Class: A2A::Message
- Inherits:
-
Object
- Object
- A2A::Message
- Defined in:
- lib/a2a/message.rb
Instance Attribute Summary collapse
-
#context_id ⇒ Object
readonly
Returns the value of attribute context_id.
-
#extensions ⇒ Object
readonly
Returns the value of attribute extensions.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#parts ⇒ Object
readonly
Returns the value of attribute parts.
-
#reference_task_ids ⇒ Object
readonly
Returns the value of attribute reference_task_ids.
-
#role ⇒ Object
readonly
Returns the value of attribute role.
-
#task_id ⇒ Object
readonly
Returns the value of attribute task_id.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(id:, role:, parts:, **kwargs) ⇒ Message
constructor
A new instance of Message.
-
#text ⇒ Object
Returns the plain-text content of the first Parts::Text, or nil.
- #to_h ⇒ Object
Constructor Details
#initialize(id:, role:, parts:, **kwargs) ⇒ Message
Returns a new instance of Message.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/a2a/message.rb', line 9 def initialize(id:, role:, parts:, **kwargs) raise ArgumentError, "invalid role: #{role.inspect}" unless Role.valid?(role) raise ArgumentError, "parts must contain at least one element" if Array(parts).empty? @id = id @role = role @parts = parts @context_id = kwargs[:context_id] @task_id = kwargs[:task_id] @reference_task_ids = kwargs[:reference_task_ids] @extensions = kwargs[:extensions] @metadata = kwargs[:metadata] end |
Instance Attribute Details
#context_id ⇒ Object (readonly)
Returns the value of attribute context_id.
5 6 7 |
# File 'lib/a2a/message.rb', line 5 def context_id @context_id end |
#extensions ⇒ Object (readonly)
Returns the value of attribute extensions.
5 6 7 |
# File 'lib/a2a/message.rb', line 5 def extensions @extensions end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/a2a/message.rb', line 5 def id @id end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
5 6 7 |
# File 'lib/a2a/message.rb', line 5 def @metadata end |
#parts ⇒ Object (readonly)
Returns the value of attribute parts.
5 6 7 |
# File 'lib/a2a/message.rb', line 5 def parts @parts end |
#reference_task_ids ⇒ Object (readonly)
Returns the value of attribute reference_task_ids.
5 6 7 |
# File 'lib/a2a/message.rb', line 5 def reference_task_ids @reference_task_ids end |
#role ⇒ Object (readonly)
Returns the value of attribute role.
5 6 7 |
# File 'lib/a2a/message.rb', line 5 def role @role end |
#task_id ⇒ Object (readonly)
Returns the value of attribute task_id.
5 6 7 |
# File 'lib/a2a/message.rb', line 5 def task_id @task_id end |
Class Method Details
.from_h(hash) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/a2a/message.rb', line 23 def self.from_h(hash) new( id: hash.fetch("messageId"), role: hash.fetch("role"), parts: Array(hash["parts"]).map { Part.from_h(_1) }, context_id: hash["contextId"], task_id: hash["taskId"], reference_task_ids: hash["referenceTaskIds"], extensions: hash["extensions"], metadata: hash["metadata"] ) end |
Instance Method Details
#text ⇒ Object
Returns the plain-text content of the first Parts::Text, or nil.
50 51 52 |
# File 'lib/a2a/message.rb', line 50 def text parts.find { |p| p.is_a?(Part::Text) }&.text end |
#to_h ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/a2a/message.rb', line 36 def to_h { "messageId" => id, "role" => role, "parts" => parts.map(&:to_h), "contextId" => context_id, "taskId" => task_id, "metadata" => , "referenceTaskIds" => reference_task_ids, "extensions" => extensions }.compact end |