Class: Ace::Support::Models::Atoms::ProviderConfigReader
- Inherits:
-
Object
- Object
- Ace::Support::Models::Atoms::ProviderConfigReader
- Defined in:
- lib/ace/support/models/atoms/provider_config_reader.rb
Overview
Reads provider configuration files with cascade support:
-
Project: .ace/llm/providers/
-
User: ~/.ace/llm/providers/
-
Gem: ace-llm/.ace-defaults/llm/providers/ (single source of truth)
Class Method Summary collapse
-
.config_directories(config_dir: nil) ⇒ Array<String>
Find all provider config directories in cascade order.
-
.extract_last_synced(config) ⇒ Date?
Extract last_synced date from config.
-
.extract_models(config) ⇒ Array<String>
Extract models list from a provider config.
-
.extract_models_dev_id(config) ⇒ String
Extract models.dev provider ID from config Falls back to provider name if not specified.
-
.read_all(config_dir: nil) ⇒ Hash<String, Hash>
Read all provider configs from cascade.
-
.read_directory(dir) ⇒ Hash<String, Hash>
Read provider configs from a specific directory.
-
.read_file(path) ⇒ Hash?
Read a single provider config file.
-
.writable_config_directory(config_dir: nil) ⇒ String?
Find the first writable config directory.
Class Method Details
.config_directories(config_dir: nil) ⇒ Array<String>
Find all provider config directories in cascade order
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ace/support/models/atoms/provider_config_reader.rb', line 20 def config_directories(config_dir: nil) dirs = [] if config_dir dirs << config_dir if Dir.exist?(config_dir) else # Project-level config project_dir = project_config_dir dirs << project_dir if project_dir && Dir.exist?(project_dir) # User-level config user_dir = user_config_dir dirs << user_dir if user_dir && Dir.exist?(user_dir) # Gem-level config (ace-llm/providers/) gem_dir = gem_config_dir dirs << gem_dir if gem_dir && Dir.exist?(gem_dir) end dirs end |
.extract_last_synced(config) ⇒ Date?
Extract last_synced date from config
125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/ace/support/models/atoms/provider_config_reader.rb', line 125 def extract_last_synced(config) value = config["last_synced"] return nil unless value case value when Date value when String Date.parse(value) end rescue ArgumentError nil end |
.extract_models(config) ⇒ Array<String>
Extract models list from a provider config
100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/ace/support/models/atoms/provider_config_reader.rb', line 100 def extract_models(config) models = config["models"] return [] unless models case models when Array models when Hash models.keys else [] end end |
.extract_models_dev_id(config) ⇒ String
Extract models.dev provider ID from config Falls back to provider name if not specified
118 119 120 |
# File 'lib/ace/support/models/atoms/provider_config_reader.rb', line 118 def extract_models_dev_id(config) config["models_dev_id"] || config["name"] end |
.read_all(config_dir: nil) ⇒ Hash<String, Hash>
Read all provider configs from cascade
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/ace/support/models/atoms/provider_config_reader.rb', line 53 def read_all(config_dir: nil) configs = {} # Read from all directories (later wins for same provider) config_directories(config_dir: config_dir).reverse_each do |dir| read_directory(dir).each do |name, config| configs[name] = config end end configs end |
.read_directory(dir) ⇒ Hash<String, Hash>
Read provider configs from a specific directory
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/ace/support/models/atoms/provider_config_reader.rb', line 69 def read_directory(dir) configs = {} Dir.glob(File.join(dir, "*.yml")).each do |file| name = File.basename(file, ".yml") next if name == "template" || name.end_with?(".example") config = read_file(file) configs[name] = config.merge("_source_file" => file) if config end configs end |
.read_file(path) ⇒ Hash?
Read a single provider config file
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/ace/support/models/atoms/provider_config_reader.rb', line 86 def read_file(path) return nil unless File.exist?(path) content = File.read(path) YAML.safe_load(content, permitted_classes: [Symbol, Date]) rescue Errno::EACCES => e raise CacheError, "Permission denied reading #{path}: #{e.}" rescue Psych::SyntaxError => e raise ConfigError, "Invalid YAML in #{path}: #{e.}" end |
.writable_config_directory(config_dir: nil) ⇒ String?
Find the first writable config directory
45 46 47 48 |
# File 'lib/ace/support/models/atoms/provider_config_reader.rb', line 45 def writable_config_directory(config_dir: nil) dirs = config_directories(config_dir: config_dir) dirs.find { |dir| writable?(dir) } end |