Class: AgentCliRuntime::Route

Inherits:
Data
  • Object
show all
Defined in:
lib/agent_cli_runtime/values.rb

Constant Summary collapse

ROUTE_PATTERN =
/\A(?<provider>[a-zA-Z0-9][a-zA-Z0-9._-]*)\/(?<model>[^\s\/][^\s]*)\z/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(provider:, model:) ⇒ Route

Returns a new instance of Route.



210
211
212
213
214
215
216
217
218
219
220
# File 'lib/agent_cli_runtime/values.rb', line 210

def initialize(provider:, model:)
  normalized_provider = Immutable.string(provider)
  normalized_model = Immutable.string(model)
  route = "#{normalized_provider}/#{normalized_model}"
  unless ROUTE_PATTERN.match?(route) && !normalized_model.include?("\0")
    raise ArgumentError,
          "OpenCode route must be a full provider/model value"
  end

  super(provider: normalized_provider, model: normalized_model)
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model

Returns:

  • (Object)

    the current value of model



207
208
209
# File 'lib/agent_cli_runtime/values.rb', line 207

def model
  @model
end

#providerObject (readonly)

Returns the value of attribute provider

Returns:

  • (Object)

    the current value of provider



207
208
209
# File 'lib/agent_cli_runtime/values.rb', line 207

def provider
  @provider
end

Class Method Details

.parse(value) ⇒ Object



222
223
224
225
226
227
228
229
230
# File 'lib/agent_cli_runtime/values.rb', line 222

def self.parse(value)
  match = ROUTE_PATTERN.match(value.to_s)
  unless match
    raise ArgumentError,
          "OpenCode route must be a full provider/model value"
  end

  new(provider: match[:provider], model: match[:model])
end

Instance Method Details

#to_sObject



232
233
234
# File 'lib/agent_cli_runtime/values.rb', line 232

def to_s
  "#{provider}/#{model}"
end