Class: Aidp::Harness::ProviderConfig
- Inherits:
-
Object
- Object
- Aidp::Harness::ProviderConfig
- Includes:
- ProviderTypeChecker
- Defined in:
- lib/aidp/harness/provider_config.rb
Overview
Provider-specific configuration management
Instance Method Summary collapse
-
#api_key(options = {}) ⇒ Object
Get API key from environment or config.
-
#auth_config(options = {}) ⇒ Object
Get authentication configuration.
-
#cache_config(options = {}) ⇒ Object
Get provider-specific cache configuration.
-
#capabilities(options = {}) ⇒ Object
Get provider capabilities.
-
#circuit_breaker_config(options = {}) ⇒ Object
Get circuit breaker configuration.
-
#cmd_args(options = {}) ⇒ Object
Get provider-specific command line arguments.
-
#combined_flags(model_name = nil, options = {}) ⇒ Object
Get combined flags (default + model-specific).
-
#config(options = {}) ⇒ Object
Get complete provider configuration.
-
#configured?(options = {}) ⇒ Boolean
Check if provider is configured.
-
#cost_config(options = {}) ⇒ Object
Get cost configuration.
-
#default_endpoint(options = {}) ⇒ Object
Get default endpoint.
-
#default_flags(options = {}) ⇒ Object
Get provider default flags.
-
#default_model(options = {}) ⇒ Object
Get default model.
-
#enabled?(options = {}) ⇒ Boolean
Check if provider is enabled.
-
#endpoints(options = {}) ⇒ Object
Get endpoints configuration.
-
#env_vars(options = {}) ⇒ Object
Get provider-specific environment variables.
-
#features(options = {}) ⇒ Object
Get provider features.
-
#harness_config(options = {}) ⇒ Object
Get provider-specific harness configuration.
-
#health_check_config(options = {}) ⇒ Object
Get provider health check configuration.
-
#initialize(provider_name, config_manager = nil) ⇒ ProviderConfig
constructor
A new instance of ProviderConfig.
-
#log_config(options = {}) ⇒ Object
Get provider-specific log configuration.
-
#max_tokens(options = {}) ⇒ Object
Get provider max tokens.
-
#model_config(model_name, options = {}) ⇒ Object
Get model configuration.
-
#model_flags(model_name, options = {}) ⇒ Object
Get model-specific flags.
-
#model_weights(options = {}) ⇒ Object
Get model weights.
-
#models(options = {}) ⇒ Object
Get provider models.
-
#monitoring_config(options = {}) ⇒ Object
Get monitoring configuration.
-
#priority(options = {}) ⇒ Object
Get provider priority.
-
#rate_limit_config(options = {}) ⇒ Object
Get rate limiting configuration.
-
#reload_config ⇒ Object
Reload configuration.
-
#retry_config(options = {}) ⇒ Object
Get retry configuration.
-
#security_config(options = {}) ⇒ Object
Get provider-specific security configuration.
-
#status(options = {}) ⇒ Object
Get provider status.
-
#summary(options = {}) ⇒ Object
Get provider summary.
-
#supports_feature?(feature, options = {}) ⇒ Boolean
Check if provider supports feature.
-
#timeout(options = {}) ⇒ Object
Get provider timeout.
-
#type(options = {}) ⇒ Object
Get provider type (usage_based, subscription).
-
#usage_limit(options = {}) ⇒ UsageLimit
Get usage limits as a UsageLimit value object.
-
#usage_limits_config(options = {}) ⇒ Hash
Get usage limits configuration.
-
#usage_limits_enabled?(options = {}) ⇒ Boolean
Check if usage limits are enabled for this provider.
-
#working_directory(options = {}) ⇒ Object
Get provider-specific working directory.
Methods included from ProviderTypeChecker
#get_provider_type, #get_underlying_service, #has_underlying_service?, #passthrough_provider?, #requires_api_key?, #subscription_provider?, #usage_based_provider?
Constructor Details
#initialize(provider_name, config_manager = nil) ⇒ ProviderConfig
Returns a new instance of ProviderConfig.
13 14 15 16 17 18 19 |
# File 'lib/aidp/harness/provider_config.rb', line 13 def initialize(provider_name, config_manager = nil) @provider_name = provider_name.to_s @config_manager = config_manager || ConfigManager.new @provider_config = nil @harness_config = nil @cache_timestamp = nil end |
Instance Method Details
#api_key(options = {}) ⇒ Object
Get API key from environment or config
169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/aidp/harness/provider_config.rb', line 169 def api_key( = {}) auth_config = auth_config() # Try environment variable first if auth_config[:api_key_env] api_key = ENV[auth_config[:api_key_env]] return api_key if api_key && !api_key.empty? end # Try direct config auth_config[:api_key] end |
#auth_config(options = {}) ⇒ Object
Get authentication configuration
153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/aidp/harness/provider_config.rb', line 153 def auth_config( = {}) config = config() auth = config[:auth] || config["auth"] || {} { api_key_env: auth[:api_key_env] || auth["api_key_env"], api_key: auth[:api_key] || auth["api_key"], api_key_file: auth[:api_key_file] || auth["api_key_file"], username: auth[:username] || auth["username"], password: auth[:password] || auth["password"], token: auth[:token] || auth["token"], credentials_file: auth[:credentials_file] || auth["credentials_file"] } end |
#cache_config(options = {}) ⇒ Object
Get provider-specific cache configuration
380 381 382 383 384 385 386 387 388 389 390 |
# File 'lib/aidp/harness/provider_config.rb', line 380 def cache_config( = {}) config = config() cache_config = config[:cache] || config["cache"] || {} { enabled: cache_config[:enabled] != false, ttl: cache_config[:ttl] || 3600, max_size: cache_config[:max_size] || 100, strategy: cache_config[:strategy] || "lru" } end |
#capabilities(options = {}) ⇒ Object
Get provider capabilities
104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/aidp/harness/provider_config.rb', line 104 def capabilities( = {}) features = features() capabilities = [] capabilities << "file_upload" if features[:file_upload] capabilities << "code_generation" if features[:code_generation] capabilities << "analysis" if features[:analysis] capabilities << "vision" if features[:vision] capabilities << "streaming" if features[:streaming] capabilities << "function_calling" if features[:function_calling] capabilities << "tool_use" if features[:tool_use] capabilities end |
#circuit_breaker_config(options = {}) ⇒ Object
Get circuit breaker configuration
250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/aidp/harness/provider_config.rb', line 250 def circuit_breaker_config( = {}) config = config() cb_config = config[:circuit_breaker] || config["circuit_breaker"] || {} { enabled: cb_config[:enabled] != false, failure_threshold: cb_config[:failure_threshold] || 5, timeout: cb_config[:timeout] || 300, half_open_max_calls: cb_config[:half_open_max_calls] || 3, success_threshold: cb_config[:success_threshold] || 2 } end |
#cmd_args(options = {}) ⇒ Object
Get provider-specific command line arguments
352 353 354 355 356 |
# File 'lib/aidp/harness/provider_config.rb', line 352 def cmd_args( = {}) config = config() cmd_args = config[:cmd_args] || config["cmd_args"] || [] cmd_args.map(&:to_s) end |
#combined_flags(model_name = nil, options = {}) ⇒ Object
Get combined flags (default + model-specific)
145 146 147 148 149 150 |
# File 'lib/aidp/harness/provider_config.rb', line 145 def combined_flags(model_name = nil, = {}) base_default_flags = default_flags() model_flags_list = model_name ? model_flags(model_name, ) : [] (base_default_flags + model_flags_list).uniq end |
#config(options = {}) ⇒ Object
Get complete provider configuration
22 23 24 25 26 27 28 29 30 |
# File 'lib/aidp/harness/provider_config.rb', line 22 def config( = {}) return @provider_config if @provider_config && ![:force_reload] && cache_valid? @provider_config = @config_manager.provider_config(@provider_name, ) @harness_config = @config_manager.harness_config() @cache_timestamp = Time.now @provider_config || {} end |
#configured?(options = {}) ⇒ Boolean
Check if provider is configured
407 408 409 410 |
# File 'lib/aidp/harness/provider_config.rb', line 407 def configured?( = {}) config = config() !config.empty? end |
#cost_config(options = {}) ⇒ Object
Get cost configuration
264 265 266 267 268 269 270 271 272 273 274 |
# File 'lib/aidp/harness/provider_config.rb', line 264 def cost_config( = {}) config = config() cost = config[:cost] || config["cost"] || {} { input_cost_per_token: cost[:input_cost_per_token] || cost["input_cost_per_token"], output_cost_per_token: cost[:output_cost_per_token] || cost["output_cost_per_token"], fixed_cost_per_request: cost[:fixed_cost_per_request] || cost["fixed_cost_per_request"], currency: cost[:currency] || cost["currency"] || "USD" } end |
#default_endpoint(options = {}) ⇒ Object
Get default endpoint
197 198 199 200 |
# File 'lib/aidp/harness/provider_config.rb', line 197 def default_endpoint( = {}) endpoints_list = endpoints() endpoints_list[:default] end |
#default_flags(options = {}) ⇒ Object
Get provider default flags
132 133 134 135 136 |
# File 'lib/aidp/harness/provider_config.rb', line 132 def default_flags( = {}) config = config() flags = config[:default_flags] || config["default_flags"] || [] flags.map(&:to_s) end |
#default_model(options = {}) ⇒ Object
Get default model
54 55 56 57 |
# File 'lib/aidp/harness/provider_config.rb', line 54 def default_model( = {}) model_list = models() model_list.first end |
#enabled?(options = {}) ⇒ Boolean
Check if provider is enabled
413 414 415 416 |
# File 'lib/aidp/harness/provider_config.rb', line 413 def enabled?( = {}) harness_config = harness_config() harness_config[:enabled] != false end |
#endpoints(options = {}) ⇒ Object
Get endpoints configuration
183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/aidp/harness/provider_config.rb', line 183 def endpoints( = {}) config = config() endpoints = config[:endpoints] || config["endpoints"] || {} { default: endpoints[:default] || endpoints["default"], chat: endpoints[:chat] || endpoints["chat"], completion: endpoints[:completion] || endpoints["completion"], embedding: endpoints[:embedding] || endpoints["embedding"], vision: endpoints[:vision] || endpoints["vision"] } end |
#env_vars(options = {}) ⇒ Object
Get provider-specific environment variables
343 344 345 346 347 348 349 |
# File 'lib/aidp/harness/provider_config.rb', line 343 def env_vars( = {}) config = config() env_vars = config[:env_vars] || config["env_vars"] || {} # Convert to string keys for environment variable access env_vars.transform_keys(&:to_s) end |
#features(options = {}) ⇒ Object
Get provider features
82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/aidp/harness/provider_config.rb', line 82 def features( = {}) config = config() features = config[:features] || config["features"] || {} { file_upload: features[:file_upload] == true, code_generation: features[:code_generation] != false, analysis: features[:analysis] != false, vision: features[:vision] == true, streaming: features[:streaming] != false, function_calling: features[:function_calling] == true, tool_use: features[:tool_use] == true } end |
#harness_config(options = {}) ⇒ Object
Get provider-specific harness configuration
312 313 314 315 316 317 318 319 320 321 322 323 324 |
# File 'lib/aidp/harness/provider_config.rb', line 312 def harness_config( = {}) config = config() harness_config = config[:harness] || config["harness"] || {} { enabled: harness_config[:enabled] != false, auto_switch_on_error: harness_config[:auto_switch_on_error] != false, auto_switch_on_rate_limit: harness_config[:auto_switch_on_rate_limit] != false, priority: harness_config[:priority] || priority(), weight: harness_config[:weight] || 1, max_concurrent_requests: harness_config[:max_concurrent_requests] || 5 } end |
#health_check_config(options = {}) ⇒ Object
Get provider health check configuration
327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
# File 'lib/aidp/harness/provider_config.rb', line 327 def health_check_config( = {}) config = config() health_check = config[:health_check] || config["health_check"] || {} { enabled: health_check[:enabled] != false, interval: health_check[:interval] || 60, timeout: health_check[:timeout] || 10, failure_threshold: health_check[:failure_threshold] || 3, success_threshold: health_check[:success_threshold] || 2, check_url: health_check[:check_url] || health_check["check_url"], check_prompt: health_check[:check_prompt] || health_check["check_prompt"] } end |
#log_config(options = {}) ⇒ Object
Get provider-specific log configuration
365 366 367 368 369 370 371 372 373 374 375 376 377 |
# File 'lib/aidp/harness/provider_config.rb', line 365 def log_config( = {}) config = config() log_config = config[:log] || config["log"] || {} { enabled: log_config[:enabled] != false, level: log_config[:level] || "info", file: log_config[:file] || log_config["file"], max_size: log_config[:max_size] || 10_485_760, # 10MB max_files: log_config[:max_files] || 5, format: log_config[:format] || "json" } end |
#max_tokens(options = {}) ⇒ Object
Get provider max tokens
120 121 122 123 |
# File 'lib/aidp/harness/provider_config.rb', line 120 def max_tokens( = {}) config = config() config[:max_tokens] || config["max_tokens"] end |
#model_config(model_name, options = {}) ⇒ Object
Get model configuration
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/aidp/harness/provider_config.rb', line 67 def model_config(model_name, = {}) config = config() models_config = config[:models_config] || config["models_config"] || {} model_config = models_config[model_name.to_sym] || models_config[model_name.to_s] || {} { flags: model_config[:flags] || model_config["flags"] || [], max_tokens: model_config[:max_tokens] || model_config["max_tokens"], timeout: model_config[:timeout] || model_config["timeout"], temperature: model_config[:temperature] || model_config["temperature"], max_retries: model_config[:max_retries] || model_config["max_retries"] } end |
#model_flags(model_name, options = {}) ⇒ Object
Get model-specific flags
139 140 141 142 |
# File 'lib/aidp/harness/provider_config.rb', line 139 def model_flags(model_name, = {}) model_config = model_config(model_name, ) model_config[:flags] || [] end |
#model_weights(options = {}) ⇒ Object
Get model weights
60 61 62 63 64 |
# File 'lib/aidp/harness/provider_config.rb', line 60 def model_weights( = {}) config = config() weights = config[:model_weights] || config["model_weights"] || {} weights.transform_values { |weight| [weight.to_i, 1].max } end |
#models(options = {}) ⇒ Object
Get provider models
47 48 49 50 51 |
# File 'lib/aidp/harness/provider_config.rb', line 47 def models( = {}) config = config() models = config[:models] || config["models"] || [] models.map(&:to_s) end |
#monitoring_config(options = {}) ⇒ Object
Get monitoring configuration
203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/aidp/harness/provider_config.rb', line 203 def monitoring_config( = {}) config = config() monitoring = config[:monitoring] || config["monitoring"] || {} { enabled: monitoring[:enabled] != false, metrics_interval: monitoring[:metrics_interval] || 60, health_check_interval: monitoring[:health_check_interval] || 300, log_level: monitoring[:log_level] || "info", log_requests: monitoring[:log_requests] != false, log_responses: monitoring[:log_responses] == true } end |
#priority(options = {}) ⇒ Object
Get provider priority
41 42 43 44 |
# File 'lib/aidp/harness/provider_config.rb', line 41 def priority( = {}) config = config() config[:priority] || config["priority"] || 1 end |
#rate_limit_config(options = {}) ⇒ Object
Get rate limiting configuration
218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/aidp/harness/provider_config.rb', line 218 def rate_limit_config( = {}) config = config() rate_limit = config[:rate_limit] || config["rate_limit"] || {} { enabled: rate_limit[:enabled] != false, requests_per_minute: rate_limit[:requests_per_minute] || 60, requests_per_hour: rate_limit[:requests_per_hour] || 1000, tokens_per_minute: rate_limit[:tokens_per_minute], tokens_per_hour: rate_limit[:tokens_per_hour], burst_limit: rate_limit[:burst_limit] || 10, reset_time: rate_limit[:reset_time] || 3600 } end |
#reload_config ⇒ Object
Reload configuration
444 445 446 447 448 449 |
# File 'lib/aidp/harness/provider_config.rb', line 444 def reload_config @provider_config = nil @harness_config = nil @cache_timestamp = nil @config_manager.reload_config end |
#retry_config(options = {}) ⇒ Object
Get retry configuration
234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/aidp/harness/provider_config.rb', line 234 def retry_config( = {}) config = config() retry_config = config[:retry] || config["retry"] || {} { enabled: retry_config[:enabled] != false, max_attempts: retry_config[:max_attempts] || 3, base_delay: retry_config[:base_delay] || 1.0, max_delay: retry_config[:max_delay] || 60.0, exponential_base: retry_config[:exponential_base] || 2.0, jitter: retry_config[:jitter] != false, retry_on_rate_limit: retry_config[:retry_on_rate_limit] == true } end |
#security_config(options = {}) ⇒ Object
Get provider-specific security configuration
393 394 395 396 397 398 399 400 401 402 403 404 |
# File 'lib/aidp/harness/provider_config.rb', line 393 def security_config( = {}) config = config() security = config[:security] || config["security"] || {} { ssl_verify: security[:ssl_verify] != false, allowed_hosts: security[:allowed_hosts] || security["allowed_hosts"] || [], blocked_hosts: security[:blocked_hosts] || security["blocked_hosts"] || [], timeout: security[:timeout] || 30, max_redirects: security[:max_redirects] || 5 } end |
#status(options = {}) ⇒ Object
Get provider status
419 420 421 422 423 424 |
# File 'lib/aidp/harness/provider_config.rb', line 419 def status( = {}) return :not_configured unless configured?() return :disabled unless enabled?() :enabled end |
#summary(options = {}) ⇒ Object
Get provider summary
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 |
# File 'lib/aidp/harness/provider_config.rb', line 427 def summary( = {}) config = config() return {} if config.empty? { name: @provider_name, type: type(), priority: priority(), models: models(), features: capabilities(), status: status(), configured: configured?(), enabled: enabled?() } end |
#supports_feature?(feature, options = {}) ⇒ Boolean
Check if provider supports feature
98 99 100 101 |
# File 'lib/aidp/harness/provider_config.rb', line 98 def supports_feature?(feature, = {}) features = features() features[feature.to_sym] == true end |
#timeout(options = {}) ⇒ Object
Get provider timeout
126 127 128 129 |
# File 'lib/aidp/harness/provider_config.rb', line 126 def timeout( = {}) config = config() config[:timeout] || config["timeout"] || 300 end |
#type(options = {}) ⇒ Object
Get provider type (usage_based, subscription)
33 34 35 36 |
# File 'lib/aidp/harness/provider_config.rb', line 33 def type( = {}) config = config() config[:type] || config["type"] || "subscription" end |
#usage_limit(options = {}) ⇒ UsageLimit
Get usage limits as a UsageLimit value object
298 299 300 301 |
# File 'lib/aidp/harness/provider_config.rb', line 298 def usage_limit( = {}) config = usage_limits_config() UsageLimit.from_config(config) end |
#usage_limits_config(options = {}) ⇒ Hash
Get usage limits configuration
280 281 282 283 284 285 286 287 288 289 290 291 292 |
# File 'lib/aidp/harness/provider_config.rb', line 280 def usage_limits_config( = {}) config = config() limits = config[:usage_limits] || config["usage_limits"] || {} { enabled: limits[:enabled] == true, period: limits[:period] || limits["period"] || "monthly", reset_day: limits[:reset_day] || limits["reset_day"] || 1, max_tokens: limits[:max_tokens] || limits["max_tokens"], max_cost: limits[:max_cost] || limits["max_cost"], tier_limits: limits[:tier_limits] || limits["tier_limits"] || {} } end |
#usage_limits_enabled?(options = {}) ⇒ Boolean
Check if usage limits are enabled for this provider
307 308 309 |
# File 'lib/aidp/harness/provider_config.rb', line 307 def usage_limits_enabled?( = {}) usage_limits_config()[:enabled] end |
#working_directory(options = {}) ⇒ Object
Get provider-specific working directory
359 360 361 362 |
# File 'lib/aidp/harness/provider_config.rb', line 359 def working_directory( = {}) config = config() config[:working_directory] || config["working_directory"] || Dir.pwd end |