Class: AIA::Config
- Inherits:
-
MywayConfig::Base
- Object
- MywayConfig::Base
- AIA::Config
- Defined in:
- lib/aia/config.rb
Constant Summary collapse
- TO_MODEL_SPECS =
Convert array of hashes to array of ModelSpec objects
->(v) { return [] if v.nil? return v if v.is_a?(Array) && v.first.is_a?(ModelSpec) model_counts = Hash.new(0) Array(v).map do |spec| # Handle string format from CLI if spec.is_a?(String) if spec.include?('=') name, role = spec.split('=', 2) spec = { name: name.strip, role: role.strip } else spec = { name: spec.strip } end end spec = spec.transform_keys(&:to_sym) if spec.respond_to?(:transform_keys) name = spec[:name] model_counts[name] += 1 instance = model_counts[name] ModelSpec.new( name: name, role: spec[:role], instance: instance, internal_id: instance > 1 ? "#{name}##{instance}" : name ) end }
- CLI_TO_NESTED_MAP =
Mapping of flat CLI keys to their nested config locations
{ # flags section chat: [:flags, :chat], cost: [:flags, :cost], fuzzy: [:flags, :fuzzy], tokens: [:flags, :tokens], no_mcp: [:flags, :no_mcp], terse: [:flags, :terse], debug: [:flags, :debug], verbose: [:flags, :verbose], consensus: [:flags, :consensus], # llm section temperature: [:llm, :temperature], max_tokens: [:llm, :max_tokens], top_p: [:llm, :top_p], frequency_penalty: [:llm, :frequency_penalty], presence_penalty: [:llm, :presence_penalty], # prompts section prompts_dir: [:prompts, :dir], roles_prefix: [:prompts, :roles_prefix], role: [:prompts, :role], skills_dir: [:skills, :dir], skills_prefix: [:prompts, :skills_prefix], skills: [:prompts, :skills], parameter_regex: [:prompts, :parameter_regex], system_prompt: [:prompts, :system_prompt], # output section output: [:output, :file], history_file: [:output, :history_file], append: [:output, :append], markdown: [:output, :markdown], # audio section speak: [:audio, :speak], voice: [:audio, :voice], speech_model: [:audio, :speech_model], transcription_model: [:audio, :transcription_model], # image section image_size: [:image, :size], image_quality: [:image, :quality], image_style: [:image, :style], # tools section tool_paths: [:tools, :paths], allowed_tools: [:tools, :allowed], rejected_tools: [:tools, :rejected], # registry section refresh: [:registry, :refresh], }.freeze
Instance Attribute Summary collapse
-
#completion ⇒ Object
Runtime attributes (not loaded from config files).
-
#connected_mcp_servers ⇒ Object
Runtime attributes (not loaded from config files).
-
#dump_file ⇒ Object
Runtime attributes (not loaded from config files).
-
#executable_prompt_content ⇒ Object
Runtime attributes (not loaded from config files).
-
#failed_mcp_servers ⇒ Object
Runtime attributes (not loaded from config files).
-
#list_skills ⇒ Object
Runtime attributes (not loaded from config files).
-
#list_tools ⇒ Object
Runtime attributes (not loaded from config files).
-
#loaded_tools ⇒ Object
Runtime attributes (not loaded from config files).
-
#log_file_override ⇒ Object
Runtime attributes (not loaded from config files).
-
#log_level_override ⇒ Object
Runtime attributes (not loaded from config files).
-
#mcp_list ⇒ Object
Runtime attributes (not loaded from config files).
-
#prompt_id ⇒ Object
Runtime attributes (not loaded from config files).
-
#remaining_args ⇒ Object
Runtime attributes (not loaded from config files).
-
#stdin_content ⇒ Object
Runtime attributes (not loaded from config files).
-
#tool_names ⇒ Object
Runtime attributes (not loaded from config files).
Class Method Summary collapse
-
.setup(cli_overrides = {}) ⇒ Config
Setup configuration with CLI overrides.
- .validate_environment! ⇒ Object
Instance Method Summary collapse
-
#apply_overrides(overrides) ⇒ Object
Apply CLI or runtime overrides to configuration.
-
#initialize(overrides: {}) ⇒ Config
constructor
A new instance of Config.
-
#to_h ⇒ Object
Convert config to hash (for dump, etc.).
Constructor Details
#initialize(overrides: {}) ⇒ Config
Returns a new instance of Config.
201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/aia/config.rb', line 201 def initialize(overrides: {}) super() # Load extra config file AFTER base init (defaults + user config + env vars) # but BEFORE CLI overrides, so CLI flags take precedence. extra_config_path = overrides.delete(:extra_config_file) load_extra_config(extra_config_path) if extra_config_path apply_models_env_var unless overrides[:models] apply_overrides(overrides) if overrides && !overrides.empty? process_mcp_files(overrides[:mcp_files]) if overrides[:mcp_files] end |
Instance Attribute Details
#completion ⇒ Object
Runtime attributes (not loaded from config files)
58 59 60 |
# File 'lib/aia/config.rb', line 58 def completion @completion end |
#connected_mcp_servers ⇒ Object
Runtime attributes (not loaded from config files)
58 59 60 |
# File 'lib/aia/config.rb', line 58 def connected_mcp_servers @connected_mcp_servers end |
#dump_file ⇒ Object
Runtime attributes (not loaded from config files)
58 59 60 |
# File 'lib/aia/config.rb', line 58 def dump_file @dump_file end |
#executable_prompt_content ⇒ Object
Runtime attributes (not loaded from config files)
58 59 60 |
# File 'lib/aia/config.rb', line 58 def executable_prompt_content @executable_prompt_content end |
#failed_mcp_servers ⇒ Object
Runtime attributes (not loaded from config files)
58 59 60 |
# File 'lib/aia/config.rb', line 58 def failed_mcp_servers @failed_mcp_servers end |
#list_skills ⇒ Object
Runtime attributes (not loaded from config files)
58 59 60 |
# File 'lib/aia/config.rb', line 58 def list_skills @list_skills end |
#list_tools ⇒ Object
Runtime attributes (not loaded from config files)
58 59 60 |
# File 'lib/aia/config.rb', line 58 def list_tools @list_tools end |
#loaded_tools ⇒ Object
Runtime attributes (not loaded from config files)
58 59 60 |
# File 'lib/aia/config.rb', line 58 def loaded_tools @loaded_tools end |
#log_file_override ⇒ Object
Runtime attributes (not loaded from config files)
58 59 60 |
# File 'lib/aia/config.rb', line 58 def log_file_override @log_file_override end |
#log_level_override ⇒ Object
Runtime attributes (not loaded from config files)
58 59 60 |
# File 'lib/aia/config.rb', line 58 def log_level_override @log_level_override end |
#mcp_list ⇒ Object
Runtime attributes (not loaded from config files)
58 59 60 |
# File 'lib/aia/config.rb', line 58 def mcp_list @mcp_list end |
#prompt_id ⇒ Object
Runtime attributes (not loaded from config files)
58 59 60 |
# File 'lib/aia/config.rb', line 58 def prompt_id @prompt_id end |
#remaining_args ⇒ Object
Runtime attributes (not loaded from config files)
58 59 60 |
# File 'lib/aia/config.rb', line 58 def remaining_args @remaining_args end |
#stdin_content ⇒ Object
Runtime attributes (not loaded from config files)
58 59 60 |
# File 'lib/aia/config.rb', line 58 def stdin_content @stdin_content end |
#tool_names ⇒ Object
Runtime attributes (not loaded from config files)
58 59 60 |
# File 'lib/aia/config.rb', line 58 def tool_names @tool_names end |
Class Method Details
.setup(cli_overrides = {}) ⇒ Config
Setup configuration with CLI overrides
143 144 145 |
# File 'lib/aia/config.rb', line 143 def setup(cli_overrides = {}) new(overrides: cli_overrides) end |
.validate_environment! ⇒ Object
41 42 43 |
# File 'lib/aia/config.rb', line 41 def validate_environment! # no-op: AIA has no environment sections in defaults.yml end |
Instance Method Details
#apply_overrides(overrides) ⇒ Object
Apply CLI or runtime overrides to configuration
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/aia/config.rb', line 217 def apply_overrides(overrides) overrides.each do |key, value| key_sym = key.to_sym # Check if this is a flat CLI key that maps to a nested location if CLI_TO_NESTED_MAP.key?(key_sym) section, nested_key = CLI_TO_NESTED_MAP[key_sym] section_obj = send(section) section_obj.send("#{nested_key}=", value) if section_obj.respond_to?("#{nested_key}=") elsif respond_to?("#{key}=") send("#{key}=", value) elsif key.to_s.include?('__') # Handle nested keys like 'llm__temperature' parts = key.to_s.split('__') apply_nested_override(parts, value) end end end |
#to_h ⇒ Object
Convert config to hash (for dump, etc.)
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
# File 'lib/aia/config.rb', line 237 def to_h { service: service.to_h, llm: llm.to_h, models: models.map(&:to_h), prompts: prompts.to_h, roles: roles.to_h, skills: skills.to_h, output: output.to_h, audio: audio.to_h, image: image.to_h, embedding: .to_h, tools: tools.to_h, flags: flags.to_h, registry: registry.to_h, paths: paths.to_h, pipeline: pipeline, require_libs: require_libs, mcp_servers: mcp_servers, mcp_use: mcp_use, mcp_skip: mcp_skip, context_files: context_files } end |