Class: A2A::Types::Message
- Defined in:
- lib/a2a/types/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.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#message_id ⇒ Object
readonly
Returns the value of attribute message_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.
Instance Method Summary collapse
-
#add_part(part) ⇒ Object
Add a part to the message.
-
#data_parts ⇒ Array<DataPart>
Get all data parts from the message.
-
#file_parts ⇒ Array<FilePart>
Get all file parts from the message.
-
#from_agent? ⇒ Boolean
Check if the message is from an agent.
-
#from_user? ⇒ Boolean
Check if the message is from a user.
-
#initialize(message_id:, role:, parts:, kind: KIND_MESSAGE, context_id: nil, task_id: nil, metadata: nil, extensions: nil, reference_task_ids: nil) ⇒ Message
constructor
Initialize a new message.
-
#text_content ⇒ String
Get all text content from the message.
- #validate! ⇒ Object private
Methods inherited from BaseModel
#==, #camelize, from_h, from_json, #hash, #to_h, #to_json, underscore, #valid?, #validate_array_type, #validate_inclusion, #validate_required, #validate_type
Constructor Details
#initialize(message_id:, role:, parts:, kind: KIND_MESSAGE, context_id: nil, task_id: nil, metadata: nil, extensions: nil, reference_task_ids: nil) ⇒ Message
Initialize a new message
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/a2a/types/message.rb', line 27 def initialize(message_id:, role:, parts:, kind: KIND_MESSAGE, context_id: nil, task_id: nil, metadata: nil, extensions: nil, reference_task_ids: nil) @message_id = @role = role @parts = parts.map { |p| p.is_a?(Part) ? p : Part.from_h(p) } @kind = kind @context_id = context_id @task_id = task_id @metadata = @extensions = extensions @reference_task_ids = reference_task_ids validate! end |
Instance Attribute Details
#context_id ⇒ Object (readonly)
Returns the value of attribute context_id.
12 13 14 |
# File 'lib/a2a/types/message.rb', line 12 def context_id @context_id end |
#extensions ⇒ Object (readonly)
Returns the value of attribute extensions.
12 13 14 |
# File 'lib/a2a/types/message.rb', line 12 def extensions @extensions end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
12 13 14 |
# File 'lib/a2a/types/message.rb', line 12 def kind @kind end |
#message_id ⇒ Object (readonly)
Returns the value of attribute message_id.
12 13 14 |
# File 'lib/a2a/types/message.rb', line 12 def @message_id end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
12 13 14 |
# File 'lib/a2a/types/message.rb', line 12 def @metadata end |
#parts ⇒ Object (readonly)
Returns the value of attribute parts.
12 13 14 |
# File 'lib/a2a/types/message.rb', line 12 def parts @parts end |
#reference_task_ids ⇒ Object (readonly)
Returns the value of attribute reference_task_ids.
12 13 14 |
# File 'lib/a2a/types/message.rb', line 12 def reference_task_ids @reference_task_ids end |
#role ⇒ Object (readonly)
Returns the value of attribute role.
12 13 14 |
# File 'lib/a2a/types/message.rb', line 12 def role @role end |
#task_id ⇒ Object (readonly)
Returns the value of attribute task_id.
12 13 14 |
# File 'lib/a2a/types/message.rb', line 12 def task_id @task_id end |
Instance Method Details
#add_part(part) ⇒ Object
Add a part to the message
72 73 74 |
# File 'lib/a2a/types/message.rb', line 72 def add_part(part) @parts << part end |
#data_parts ⇒ Array<DataPart>
Get all data parts from the message
64 65 66 |
# File 'lib/a2a/types/message.rb', line 64 def data_parts @parts.select { |p| p.is_a?(DataPart) } end |
#file_parts ⇒ Array<FilePart>
Get all file parts from the message
56 57 58 |
# File 'lib/a2a/types/message.rb', line 56 def file_parts @parts.select { |p| p.is_a?(FilePart) } end |
#from_agent? ⇒ Boolean
Check if the message is from an agent
88 89 90 |
# File 'lib/a2a/types/message.rb', line 88 def from_agent? @role == ROLE_AGENT end |
#from_user? ⇒ Boolean
Check if the message is from a user
80 81 82 |
# File 'lib/a2a/types/message.rb', line 80 def from_user? @role == ROLE_USER end |
#text_content ⇒ String
Get all text content from the message
46 47 48 49 50 |
# File 'lib/a2a/types/message.rb', line 46 def text_content @parts.select { |p| p.is_a?(TextPart) } .map(&:text) .join("\n") end |
#validate! ⇒ Object (private)
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/a2a/types/message.rb', line 94 def validate! validate_required(:message_id, :role, :parts, :kind) validate_inclusion(:role, VALID_ROLES) validate_inclusion(:kind, [KIND_MESSAGE]) validate_array_type(:parts, Part) return unless @parts.empty? raise ArgumentError, "Message must have at least one part" end |