Module: Legion::LLM::Inventory

Extended by:
Legion::Logging::Helper
Defined in:
lib/legion/llm/inventory.rb,
lib/legion/llm/inventory/discovery.rb

Overview

SSOT read facade over the lex-llm inventory registry. The registry (Legion::Extensions::Llm::Inventory::Registry) is the single catalog: one bucket of lanes keyed by the 5-tuple id tier:provider_family:instance_id:type:model (composed only by Inventory::Identity.compose_lane_id). This module holds no store of its own — every read delegates to the registry snapshot.

Defined Under Namespace

Modules: Discovery

Class Method Summary collapse

Class Method Details

.instances(snapshot:, filters: {}) ⇒ Object

Projects frozen Array of instance data from the supplied snapshot in canonical InstanceKey order. Filters: :provider_family, :instance_id, :availability. Unknown filter keys raise ArgumentError.



44
45
46
47
48
49
50
51
52
53
# File 'lib/legion/llm/inventory.rb', line 44

def instances(snapshot:, filters: {}, **)
  validate_filter_keys!(filters)
  result = []
  snapshot.each_instance do |inst|
    next if filter_mismatch_instance?(inst, filters)

    result << project_instance(inst)
  end
  result.freeze
end

.models(snapshot:, filters: {}) ⇒ Object

Projects distinct, sorted, frozen Array of model names from the supplied snapshot's lanes. Filters: :provider_family, :instance_id, :tier, :operation. Unknown filter keys raise ArgumentError.



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/legion/llm/inventory.rb', line 58

def models(snapshot:, filters: {}, **)
  validate_filter_keys!(filters)
  result = []
  snapshot.each_lane do |lane|
    next if filter_mismatch_lane?(lane, filters)

    model = lane.model
    result << model unless result.include?(model)
  end
  result.sort.freeze
end

.providers_from(snapshot:, filters: {}) ⇒ Object

Projects distinct, frozen, sorted provider-family Strings from the supplied snapshot. Filters: :provider_family, :instance_id, :tier, :operation, :availability. Unknown filter keys raise ArgumentError.



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/legion/llm/inventory.rb', line 29

def providers_from(snapshot:, filters: {}, **)
  validate_filter_keys!(filters)
  result = []
  snapshot.each_instance do |inst|
    next if filter_mismatch_instance?(inst, filters)

    family = inst.instance_key.provider_family.to_s
    result << family unless result.include?(family)
  end
  result.sort.freeze
end

.snapshotObject

Returns the live registry snapshot (no args; generation-tagged).



22
23
24
# File 'lib/legion/llm/inventory.rb', line 22

def snapshot
  Legion::Extensions::Llm::Inventory::Registry.snapshot
end