Class: A2A::Types::Part

Inherits:
BaseModel show all
Defined in:
lib/a2a/types/part.rb

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.

Direct Known Subclasses

DataPart, FilePart, TextPart

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#kindObject (readonly)

Returns the value of attribute kind.



12
13
14
# File 'lib/a2a/types/part.rb', line 12

def kind
  @kind
end

#metadataObject (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)

Parameters:

  • The hash representation

Returns:

  • The appropriate part subclass instance



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