Class: SwarmSDK::Configuration::Parser
- Inherits:
-
Object
- Object
- SwarmSDK::Configuration::Parser
- Defined in:
- lib/swarm_sdk/configuration/parser.rb
Overview
Handles YAML parsing, validation, and normalization
This class is responsible for:
- Loading and parsing YAML content
- Validating configuration structure
- Normalizing data (symbolizing keys, env interpolation)
- Detecting configuration type (swarm vs workflow)
- Loading agents and nodes
- Detecting circular dependencies
After parsing, the parsed data can be translated to a Swarm/Workflow using the Translator class.
Constant Summary collapse
- ENV_VAR_WITH_DEFAULT_PATTERN =
/\$\{([^:}]+)(:=([^}]*))?\}/
Instance Attribute Summary collapse
-
#agents ⇒ Object
readonly
Returns the value of attribute agents.
-
#all_agents_config ⇒ Object
readonly
Returns the value of attribute all_agents_config.
-
#all_agents_hooks ⇒ Object
readonly
Returns the value of attribute all_agents_hooks.
-
#base_dir ⇒ Object
readonly
Returns the value of attribute base_dir.
-
#config_type ⇒ Object
readonly
Returns the value of attribute config_type.
-
#external_swarms ⇒ Object
readonly
Returns the value of attribute external_swarms.
-
#lead_agent ⇒ Object
readonly
Returns the value of attribute lead_agent.
-
#nodes ⇒ Object
readonly
Returns the value of attribute nodes.
-
#scratchpad_mode ⇒ Object
readonly
Returns the value of attribute scratchpad_mode.
-
#start_node ⇒ Object
readonly
Returns the value of attribute start_node.
-
#swarm_hooks ⇒ Object
readonly
Returns the value of attribute swarm_hooks.
-
#swarm_id ⇒ Object
readonly
Returns the value of attribute swarm_id.
-
#swarm_name ⇒ Object
readonly
Returns the value of attribute swarm_name.
Instance Method Summary collapse
- #agent_names ⇒ Object
- #connections_for(agent_name) ⇒ Object
-
#initialize(yaml_content, base_dir:, env_interpolation: nil) ⇒ Parser
constructor
Initialize parser with YAML content and options.
- #parse ⇒ Object
Constructor Details
#initialize(yaml_content, base_dir:, env_interpolation: nil) ⇒ Parser
Initialize parser with YAML content and options
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/swarm_sdk/configuration/parser.rb', line 41 def initialize(yaml_content, base_dir:, env_interpolation: nil) @yaml_content = yaml_content @base_dir = Pathname.new(base_dir). @env_interpolation = env_interpolation @config_type = nil @swarm_id = nil @swarm_name = nil @lead_agent = nil @start_node = nil @agents = {} @all_agents_config = {} @swarm_hooks = {} @all_agents_hooks = {} @external_swarms = {} @nodes = {} @scratchpad_mode = :disabled end |
Instance Attribute Details
#agents ⇒ Object (readonly)
Returns the value of attribute agents.
20 21 22 |
# File 'lib/swarm_sdk/configuration/parser.rb', line 20 def agents @agents end |
#all_agents_config ⇒ Object (readonly)
Returns the value of attribute all_agents_config.
20 21 22 |
# File 'lib/swarm_sdk/configuration/parser.rb', line 20 def all_agents_config @all_agents_config end |
#all_agents_hooks ⇒ Object (readonly)
Returns the value of attribute all_agents_hooks.
20 21 22 |
# File 'lib/swarm_sdk/configuration/parser.rb', line 20 def all_agents_hooks @all_agents_hooks end |
#base_dir ⇒ Object (readonly)
Returns the value of attribute base_dir.
94 95 96 |
# File 'lib/swarm_sdk/configuration/parser.rb', line 94 def base_dir @base_dir end |
#config_type ⇒ Object (readonly)
Returns the value of attribute config_type.
20 21 22 |
# File 'lib/swarm_sdk/configuration/parser.rb', line 20 def config_type @config_type end |
#external_swarms ⇒ Object (readonly)
Returns the value of attribute external_swarms.
20 21 22 |
# File 'lib/swarm_sdk/configuration/parser.rb', line 20 def external_swarms @external_swarms end |
#lead_agent ⇒ Object (readonly)
Returns the value of attribute lead_agent.
20 21 22 |
# File 'lib/swarm_sdk/configuration/parser.rb', line 20 def lead_agent @lead_agent end |
#nodes ⇒ Object (readonly)
Returns the value of attribute nodes.
20 21 22 |
# File 'lib/swarm_sdk/configuration/parser.rb', line 20 def nodes @nodes end |
#scratchpad_mode ⇒ Object (readonly)
Returns the value of attribute scratchpad_mode.
20 21 22 |
# File 'lib/swarm_sdk/configuration/parser.rb', line 20 def scratchpad_mode @scratchpad_mode end |
#start_node ⇒ Object (readonly)
Returns the value of attribute start_node.
20 21 22 |
# File 'lib/swarm_sdk/configuration/parser.rb', line 20 def start_node @start_node end |
#swarm_hooks ⇒ Object (readonly)
Returns the value of attribute swarm_hooks.
20 21 22 |
# File 'lib/swarm_sdk/configuration/parser.rb', line 20 def swarm_hooks @swarm_hooks end |
#swarm_id ⇒ Object (readonly)
Returns the value of attribute swarm_id.
20 21 22 |
# File 'lib/swarm_sdk/configuration/parser.rb', line 20 def swarm_id @swarm_id end |
#swarm_name ⇒ Object (readonly)
Returns the value of attribute swarm_name.
20 21 22 |
# File 'lib/swarm_sdk/configuration/parser.rb', line 20 def swarm_name @swarm_name end |
Instance Method Details
#agent_names ⇒ Object
82 83 84 |
# File 'lib/swarm_sdk/configuration/parser.rb', line 82 def agent_names @agents.keys end |
#connections_for(agent_name) ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/swarm_sdk/configuration/parser.rb', line 86 def connections_for(agent_name) agent_config = @agents[agent_name] return [] unless agent_config delegates = agent_config[:delegates_to] || [] Array(delegates).map(&:to_sym) end |
#parse ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/swarm_sdk/configuration/parser.rb', line 59 def parse @config = YAML.safe_load(@yaml_content, permitted_classes: [Symbol], aliases: true) unless @config.is_a?(Hash) raise ConfigurationError, "Invalid YAML syntax: configuration must be a Hash" end @config = Utils.symbolize_keys(@config) interpolate_env_vars!(@config) if env_interpolation_enabled? validate_version detect_and_validate_type load_common_config load_type_specific_config load_agents load_nodes if @config_type == :workflow detect_circular_dependencies self rescue Psych::SyntaxError => e raise ConfigurationError, "Invalid YAML syntax: #{e.}" end |