Class: A2A::Types::Part
Overview
Base class for message parts (discriminated union)
Parts represent different types of content within a message. This is an abstract base class - use TextPart, FilePart, or DataPart.
Instance Attribute Summary collapse
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
Class Method Summary collapse
-
.from_h(hash) ⇒ Part
Create a part from a hash (factory method).
Instance Method Summary collapse
-
#initialize(kind:, metadata: nil) ⇒ Part
constructor
protected
A new instance of Part.
- #validate! ⇒ Object private
Methods inherited from BaseModel
#==, #camelize, from_json, #hash, #to_h, #to_json, underscore, #valid?, #validate_array_type, #validate_inclusion, #validate_required, #validate_type
Constructor Details
#initialize(kind:, metadata: nil) ⇒ Part (protected)
Returns a new instance of Part.
38 39 40 41 42 |
# File 'lib/a2a/types/part.rb', line 38 def initialize(kind:, metadata: nil) @kind = kind = validate! end |
Instance Attribute Details
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
12 13 14 |
# File 'lib/a2a/types/part.rb', line 12 def kind @kind end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
12 13 14 |
# File 'lib/a2a/types/part.rb', line 12 def end |
Class Method Details
.from_h(hash) ⇒ Part
Create a part from a hash (factory method)
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/a2a/types/part.rb', line 19 def self.from_h(hash) return hash if hash.is_a?(Part) # Already a Part instance return nil if hash.nil? kind = hash[:kind] || hash["kind"] case kind when PART_KIND_TEXT TextPart.from_h(hash) when PART_KIND_FILE FilePart.from_h(hash) when PART_KIND_DATA DataPart.from_h(hash) else raise ArgumentError, "Unknown part kind: #{kind}" end end |
Instance Method Details
#validate! ⇒ Object (private)
46 47 48 49 |
# File 'lib/a2a/types/part.rb', line 46 def validate! validate_required(:kind) validate_inclusion(:kind, VALID_PART_KINDS) end |