Module: Insika::Server::A2A::Message

Defined in:
lib/insika/server/a2a/message.rb

Overview

Message parts translation: TextPart only in this slice. Tolerates kind (A2A ~v0.2+) and type (older spec) at the boundary.

Class Method Summary collapse

Class Method Details

.agent_message(text) ⇒ Object

String -> A2A Message (role agent, 1 TextPart).



21
22
23
# File 'lib/insika/server/a2a/message.rb', line 21

def self.agent_message(text)
  { role: "agent", parts: [{ kind: "text", text: text.to_s }] }
end

.text_from(a2a_message) ⇒ Object

A2A Message (Hash) -> String (concatenates the TextParts). "" if none.



10
11
12
13
14
15
16
17
18
# File 'lib/insika/server/a2a/message.rb', line 10

def self.text_from(a2a_message)
  parts = a2a_message.is_a?(Hash) ? Array(a2a_message["parts"] || a2a_message[:parts]) : []
  parts.filter_map do |part|
    next unless part.is_a?(Hash)

    kind = part["kind"] || part["type"] || part[:kind] || part[:type]
    (part["text"] || part[:text]).to_s if kind.to_s == "text"
  end.join
end