Class: Legion::LLM::Transport::Message

Inherits:
Transport::Message
  • Object
show all
Defined in:
lib/legion/llm/transport/message.rb

Constant Summary collapse

LLM_ENVELOPE_KEYS =

Keys stripped from the JSON body (in addition to base ENVELOPE_KEYS). Do NOT add keys already in ENVELOPE_KEYS (:routing_key, :reply_to, etc.). Do NOT add :request_type — metering/audit need it in the body. Do NOT add :message_context — it MUST appear in the body of all 6 messages.

%i[
  fleet_correlation_id provider model ttl
].freeze

Instance Method Summary collapse

Instance Method Details

#app_idObject



35
36
37
# File 'lib/legion/llm/transport/message.rb', line 35

def app_id
  @options[:app_id] || 'legion-llm'
end

#correlation_idObject

Fleet messages use :fleet_correlation_id to avoid collision with the base class’s :correlation_id (which falls through to :parent_id/:task_id).



31
32
33
# File 'lib/legion/llm/transport/message.rb', line 31

def correlation_id
  @options[:fleet_correlation_id] || super
end

#headersObject



39
40
41
# File 'lib/legion/llm/transport/message.rb', line 39

def headers
  super.merge(llm_headers).merge(context_headers).merge(tracing_headers)
end

#messageObject



21
22
23
# File 'lib/legion/llm/transport/message.rb', line 21

def message
  @options.except(*ENVELOPE_KEYS, *LLM_ENVELOPE_KEYS)
end

#message_contextObject



17
18
19
# File 'lib/legion/llm/transport/message.rb', line 17

def message_context
  @options[:message_context] || {}
end

#message_idObject



25
26
27
# File 'lib/legion/llm/transport/message.rb', line 25

def message_id
  @options[:message_id] || "#{message_id_prefix}_#{SecureRandom.uuid}"
end

#tracing_headersObject

Subclasses override to inject OpenTelemetry span context. Stub returns empty hash until tracing integration is implemented.



45
46
47
# File 'lib/legion/llm/transport/message.rb', line 45

def tracing_headers
  {}
end