Class: Legion::Extensions::Llm::Inventory::Identity::InstanceKey

Inherits:
Data
  • Object
show all
Defined in:
lib/legion/extensions/llm/inventory/identity.rb

Overview

A mandatory, immutable provider_family + instance_id pair. Provider family alone is never executable; two instances of the same provider are independent targets. See section 8.1.

instance_id is the operator's CONFIG NAME — the identity the router keys settings lookups (instances.) by. physical_id is an optional SECONDARY field carrying the physical/derived id (e.g. "host:port" or "host:port/ak:") preserved for dedup and diagnostics. It is NOT identity: it never participates in equality, hashing, or registry-scope identity, so two config names pointing at the same endpoint stay distinct instances.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(provider_family:, instance_id:, physical_id: nil) ⇒ InstanceKey

Returns a new instance of InstanceKey.



113
114
115
116
117
118
119
120
121
122
123
# File 'lib/legion/extensions/llm/inventory/identity.rb', line 113

def initialize(provider_family:, instance_id:, physical_id: nil)
  family = Identity.normalize_text(value: provider_family, field: :provider_family).downcase
  raise Errors::ValidationError, 'provider_family must match /\A[a-z][a-z0-9_]*\z/' unless family.match?(/\A[a-z][a-z0-9_]*\z/)

  instance = Identity.normalize_text(value: instance_id, field: :instance_id)
  raise Errors::ValidationError, 'instance_id must not be the reserved value "default"' if instance == 'default'

  physical = physical_id.nil? ? nil : Identity.normalize_text(value: physical_id, field: :physical_id)

  super(provider_family: family.to_sym, instance_id: instance, physical_id: physical)
end

Instance Attribute Details

#instance_idObject (readonly)

Returns the value of attribute instance_id

Returns:

  • (Object)

    the current value of instance_id



112
113
114
# File 'lib/legion/extensions/llm/inventory/identity.rb', line 112

def instance_id
  @instance_id
end

#physical_idObject (readonly)

Returns the value of attribute physical_id

Returns:

  • (Object)

    the current value of physical_id



112
113
114
# File 'lib/legion/extensions/llm/inventory/identity.rb', line 112

def physical_id
  @physical_id
end

#provider_familyObject (readonly)

Returns the value of attribute provider_family

Returns:

  • (Object)

    the current value of provider_family



112
113
114
# File 'lib/legion/extensions/llm/inventory/identity.rb', line 112

def provider_family
  @provider_family
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?

Identity is exactly (provider_family, instance_id). The secondary physical_id never affects equality, hashing, or registry-scope identity.



128
129
130
# File 'lib/legion/extensions/llm/inventory/identity.rb', line 128

def ==(other)
  other.is_a?(self.class) && other.provider_family == provider_family && other.instance_id == instance_id
end

#hashObject



133
134
135
# File 'lib/legion/extensions/llm/inventory/identity.rb', line 133

def hash
  [self.class, provider_family, instance_id].hash
end