Class: A2A::Types::DataPart

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

Overview

Represents a data part in a message

Instance Attribute Summary collapse

Attributes inherited from Part

#kind, #metadata

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(data:, metadata: nil) ⇒ DataPart

Initialize a new data part

Parameters:

  • The data content (any JSON-serializable object)

  • (defaults to: nil)

    Additional metadata



151
152
153
154
# File 'lib/a2a/types/part.rb', line 151

def initialize(data:, metadata: nil)
  @data = data
  super(kind: PART_KIND_DATA, metadata: )
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



144
145
146
# File 'lib/a2a/types/part.rb', line 144

def data
  @data
end

Class Method Details

.from_h(hash) ⇒ DataPart

Create a DataPart from a hash

Parameters:

  • The hash representation

Returns:

  • The new instance



161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/a2a/types/part.rb', line 161

def self.from_h(hash)
  return hash if hash.is_a?(DataPart)
  return nil if hash.nil?

  # Convert string keys to symbols and snake_case camelCase keys
  normalized_hash = {}
  hash.each do |key, value|
    snake_key = BaseModel.underscore(key.to_s).to_sym
    normalized_hash[snake_key] = value unless snake_key == :kind
  end

  new(**normalized_hash)
end

Instance Method Details

#validate!Object (private)



177
178
179
180
# File 'lib/a2a/types/part.rb', line 177

def validate!
  super
  validate_required(:data)
end