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.
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: [], metadata: {}) ⇒ ProviderRuntime
constructor
A new instance of ProviderRuntime.
Constructor Details
#initialize(model: nil, base_url: nil, api_provider: nil, env: {}, flags: [], metadata: {}) ⇒ ProviderRuntime
Returns a new instance of ProviderRuntime.
36 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 |
# File 'lib/agent_harness/provider_runtime.rb', line 36 def initialize(model: nil, base_url: nil, api_provider: nil, env: {}, flags: [], 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 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 |
Class Method Details
.from_hash(hash) ⇒ ProviderRuntime
Build a ProviderRuntime from a Hash.
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/agent_harness/provider_runtime.rb', line 80 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"] || [], metadata: hash[:metadata] || hash["metadata"] || {} ) end |
.wrap(value) ⇒ ProviderRuntime?
Coerce a value into a ProviderRuntime.
97 98 99 100 101 102 103 104 105 |
# File 'lib/agent_harness/provider_runtime.rb', line 97 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.
110 111 112 113 |
# File 'lib/agent_harness/provider_runtime.rb', line 110 def empty? model.nil? && base_url.nil? && api_provider.nil? && env.empty? && flags.empty? && .empty? end |