Class: Legion::Extensions::Llm::Routing::RegistryEvent

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/llm/routing/registry_event.rb

Overview

Serializable provider-neutral envelope for future llm.registry publishing.

Constant Summary collapse

EVENT_TYPES =
%i[
  offering_available
  offering_unavailable
  offering_degraded
  offering_heartbeat
].freeze
SENSITIVE_KEYS =
%i[
  access_key
  api_key
  authorization
  bearer
  client_secret
  credential
  credentials
  endpoint
  endpoint_url
  password
  path
  private_key
  prompt
  reply_to
  secret
  secrets
  token
  url
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event_type:, offering:, **attributes) ⇒ RegistryEvent

Returns a new instance of RegistryEvent.



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/legion/extensions/llm/routing/registry_event.rb', line 56

def initialize(event_type:, offering:, **attributes)
  @event_id = normalize_event_id(attributes.fetch(:event_id, SecureRandom.uuid))
  @event_type = normalize_event_type(event_type)
  @occurred_at = normalize_time(attributes.fetch(:occurred_at, Time.now.utc))
  @offering = normalize_offering(offering)
  @runtime = sanitize_optional_hash(attributes[:runtime], :runtime)
  @capacity = sanitize_optional_hash(attributes[:capacity], :capacity)
  @health = sanitize_optional_hash(attributes[:health], :health)
  @lane = sanitize_optional_value(attributes[:lane], :lane)
  @metadata = sanitize_optional_hash(attributes[:metadata], :metadata)
end

Instance Attribute Details

#capacityObject (readonly)

Returns the value of attribute capacity.



36
37
38
# File 'lib/legion/extensions/llm/routing/registry_event.rb', line 36

def capacity
  @capacity
end

#event_idObject (readonly)

Returns the value of attribute event_id.



36
37
38
# File 'lib/legion/extensions/llm/routing/registry_event.rb', line 36

def event_id
  @event_id
end

#event_typeObject (readonly)

Returns the value of attribute event_type.



36
37
38
# File 'lib/legion/extensions/llm/routing/registry_event.rb', line 36

def event_type
  @event_type
end

#healthObject (readonly)

Returns the value of attribute health.



36
37
38
# File 'lib/legion/extensions/llm/routing/registry_event.rb', line 36

def health
  @health
end

#laneObject (readonly)

Returns the value of attribute lane.



36
37
38
# File 'lib/legion/extensions/llm/routing/registry_event.rb', line 36

def lane
  @lane
end

#metadataObject (readonly)

Returns the value of attribute metadata.



36
37
38
# File 'lib/legion/extensions/llm/routing/registry_event.rb', line 36

def 
  @metadata
end

#occurred_atObject (readonly)

Returns the value of attribute occurred_at.



36
37
38
# File 'lib/legion/extensions/llm/routing/registry_event.rb', line 36

def occurred_at
  @occurred_at
end

#offeringObject (readonly)

Returns the value of attribute offering.



36
37
38
# File 'lib/legion/extensions/llm/routing/registry_event.rb', line 36

def offering
  @offering
end

#runtimeObject (readonly)

Returns the value of attribute runtime.



36
37
38
# File 'lib/legion/extensions/llm/routing/registry_event.rb', line 36

def runtime
  @runtime
end

Class Method Details

.available(offering, **attributes) ⇒ Object



39
40
41
# File 'lib/legion/extensions/llm/routing/registry_event.rb', line 39

def available(offering, **attributes)
  new(event_type: :offering_available, offering:, **attributes)
end

.degraded(offering, **attributes) ⇒ Object



47
48
49
# File 'lib/legion/extensions/llm/routing/registry_event.rb', line 47

def degraded(offering, **attributes)
  new(event_type: :offering_degraded, offering:, **attributes)
end

.heartbeat(offering, **attributes) ⇒ Object



51
52
53
# File 'lib/legion/extensions/llm/routing/registry_event.rb', line 51

def heartbeat(offering, **attributes)
  new(event_type: :offering_heartbeat, offering:, **attributes)
end

.unavailable(offering, **attributes) ⇒ Object



43
44
45
# File 'lib/legion/extensions/llm/routing/registry_event.rb', line 43

def unavailable(offering, **attributes)
  new(event_type: :offering_unavailable, offering:, **attributes)
end

Instance Method Details

#to_hObject



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/legion/extensions/llm/routing/registry_event.rb', line 68

def to_h
  {
    event_id: event_id,
    event_type: event_type,
    occurred_at: occurred_at.utc.iso8601(6),
    offering: sanitized_offering_hash,
    runtime: runtime,
    capacity: capacity,
    health: health,
    lane: lane,
    metadata: 
  }.compact
end