Class: AgentHarness::ProviderRuntime
- Inherits:
-
Object
- Object
- AgentHarness::ProviderRuntime
- Defined in:
- lib/agent_harness/provider_runtime.rb
Overview
Normalized runtime configuration for per-request provider overrides.
ProviderRuntime lets callers pass a single, provider-agnostic payload into send_message that each provider materializes into CLI args, env vars, or config files as needed.
Instance Attribute Summary collapse
-
#api_provider ⇒ Object
readonly
Returns the value of attribute api_provider.
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#flags ⇒ Object
readonly
Returns the value of attribute flags.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#unset_env ⇒ Object
readonly
Returns the value of attribute unset_env.
Class Method Summary collapse
-
.from_hash(hash) ⇒ ProviderRuntime
Build a ProviderRuntime from a Hash.
-
.wrap(value) ⇒ ProviderRuntime?
Coerce a value into a ProviderRuntime.
Instance Method Summary collapse
-
#empty? ⇒ Boolean
Whether any meaningful overrides are present.
-
#initialize(model: nil, base_url: nil, api_provider: nil, env: {}, flags: [], unset_env: [], metadata: {}) ⇒ ProviderRuntime
constructor
A new instance of ProviderRuntime.
Constructor Details
#initialize(model: nil, base_url: nil, api_provider: nil, env: {}, flags: [], unset_env: [], metadata: {}) ⇒ ProviderRuntime
Returns a new instance of ProviderRuntime.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/agent_harness/provider_runtime.rb', line 37 def initialize(model: nil, base_url: nil, api_provider: nil, env: {}, flags: [], unset_env: [], metadata: {}) @model = model @base_url = base_url @api_provider = api_provider env_hash = env || {} unless env_hash.is_a?(Hash) raise ArgumentError, "env must be a Hash (got #{env_hash.class})" end normalized_env = env_hash.each_with_object({}) do |(key, value), acc| string_key = key.to_s unless value.is_a?(String) raise ArgumentError, "env value for #{string_key.inspect} must be a String (got #{value.class})" end acc[string_key] = value end @env = normalized_env.freeze normalized_flags = flags || [] unless normalized_flags.is_a?(Array) raise ArgumentError, "flags must be an Array (got #{normalized_flags.class})" end normalized_flags = normalized_flags.dup normalized_flags.each_with_index do |flag, index| unless flag.is_a?(String) raise ArgumentError, "flags must be an Array of Strings; invalid element at index #{index}: #{flag.inspect} (#{flag.class})" end end @flags = normalized_flags.freeze = || {} unless .is_a?(Hash) raise ArgumentError, "metadata must be a Hash (got #{.class})" end @metadata = .dup.freeze # Unset environment variables for the request. These are variable names that # should be removed from the inherited environment before the provider # command runs. unset_array = unset_env || [] unless unset_array.is_a?(Array) raise ArgumentError, "unset_env must be an Array (got #{unset_array.class})" end normalized_unset_env = unset_array.map.with_index do |key, index| key.to_s rescue NoMethodError raise ArgumentError, "unset_env must contain values convertible to String; invalid element at index #{index}: #{key.inspect} (#{key.class})" end @unset_env = normalized_unset_env.freeze freeze end |
Instance Attribute Details
#api_provider ⇒ Object (readonly)
Returns the value of attribute api_provider.
28 29 30 |
# File 'lib/agent_harness/provider_runtime.rb', line 28 def api_provider @api_provider end |
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
28 29 30 |
# File 'lib/agent_harness/provider_runtime.rb', line 28 def base_url @base_url end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
28 29 30 |
# File 'lib/agent_harness/provider_runtime.rb', line 28 def env @env end |
#flags ⇒ Object (readonly)
Returns the value of attribute flags.
28 29 30 |
# File 'lib/agent_harness/provider_runtime.rb', line 28 def flags @flags end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
28 29 30 |
# File 'lib/agent_harness/provider_runtime.rb', line 28 def @metadata end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
28 29 30 |
# File 'lib/agent_harness/provider_runtime.rb', line 28 def model @model end |
#unset_env ⇒ Object (readonly)
Returns the value of attribute unset_env.
28 29 30 |
# File 'lib/agent_harness/provider_runtime.rb', line 28 def unset_env @unset_env end |
Class Method Details
.from_hash(hash) ⇒ ProviderRuntime
Build a ProviderRuntime from a Hash.
96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/agent_harness/provider_runtime.rb', line 96 def self.from_hash(hash) raise ArgumentError, "expected a Hash, got #{hash.class}" unless hash.is_a?(Hash) new( model: hash[:model] || hash["model"], base_url: hash[:base_url] || hash["base_url"], api_provider: hash[:api_provider] || hash["api_provider"], env: hash[:env] || hash["env"] || {}, flags: hash[:flags] || hash["flags"] || [], unset_env: hash[:unset_env] || hash["unset_env"] || [], metadata: hash[:metadata] || hash["metadata"] || {} ) end |
.wrap(value) ⇒ ProviderRuntime?
Coerce a value into a ProviderRuntime.
114 115 116 117 118 119 120 121 122 |
# File 'lib/agent_harness/provider_runtime.rb', line 114 def self.wrap(value) case value when ProviderRuntime then value when Hash then from_hash(value) when nil then nil else raise ArgumentError, "Cannot coerce #{value.class} into ProviderRuntime" end end |
Instance Method Details
#empty? ⇒ Boolean
Whether any meaningful overrides are present.
127 128 129 130 |
# File 'lib/agent_harness/provider_runtime.rb', line 127 def empty? model.nil? && base_url.nil? && api_provider.nil? && env.empty? && flags.empty? && .empty? && unset_env.empty? end |