Class: A2A::Types::Artifact

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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(artifact_id:, parts:, name: nil, description: nil, metadata: nil, extensions: nil) ⇒ Artifact

Initialize a new artifact

Parameters:

  • Unique artifact identifier

  • Artifact parts

  • (defaults to: nil)

    Optional artifact name

  • (defaults to: nil)

    Optional artifact description

  • (defaults to: nil)

    Additional metadata

  • (defaults to: nil)

    Protocol extensions



23
24
25
26
27
28
29
30
31
32
# File 'lib/a2a/types/artifact.rb', line 23

def initialize(artifact_id:, parts:, name: nil, description: nil, metadata: nil, extensions: nil)
  @artifact_id = artifact_id
  @parts = parts.map { |p| p.is_a?(Part) ? p : Part.from_h(p) }
  @name = name
  @description = description
   = 
  @extensions = extensions

  validate!
end

Instance Attribute Details

#artifact_idObject (readonly)

Returns the value of attribute artifact_id.



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

def artifact_id
  @artifact_id
end

#descriptionObject (readonly)

Returns the value of attribute description.



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

def description
  @description
end

#extensionsObject (readonly)

Returns the value of attribute extensions.



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

def extensions
  @extensions
end

#metadataObject (readonly)

Returns the value of attribute metadata.



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

def 
  
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#partsObject (readonly)

Returns the value of attribute parts.



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

def parts
  @parts
end

Instance Method Details

#add_part(part) ⇒ Object

Add a part to the artifact

Parameters:

  • The part to add



64
65
66
# File 'lib/a2a/types/artifact.rb', line 64

def add_part(part)
  @parts << part
end

#data_partsArray<DataPart>

Get all data parts from the artifact

Returns:

  • All data parts



56
57
58
# File 'lib/a2a/types/artifact.rb', line 56

def data_parts
  @parts.select { |p| p.is_a?(DataPart) }
end

#file_partsArray<FilePart>

Get all file parts from the artifact

Returns:

  • All file parts



48
49
50
# File 'lib/a2a/types/artifact.rb', line 48

def file_parts
  @parts.select { |p| p.is_a?(FilePart) }
end

#has_content?Boolean

Check if the artifact has any content

Returns:

  • True if the artifact has parts



72
73
74
# File 'lib/a2a/types/artifact.rb', line 72

def has_content?
  !@parts.empty?
end

#text_contentString

Get all text content from the artifact

Returns:

  • Combined text from all text parts



38
39
40
41
42
# File 'lib/a2a/types/artifact.rb', line 38

def text_content
  @parts.select { |p| p.is_a?(TextPart) }
        .map(&:text)
        .join("\n")
end

#total_file_sizeInteger

Get the total size of all file parts

Returns:

  • Total size in bytes



80
81
82
83
84
# File 'lib/a2a/types/artifact.rb', line 80

def total_file_size
  file_parts.sum do |file_part|
    file_part.file.respond_to?(:size) ? file_part.file.size : 0
  end
end

#validate!Object (private)

Raises:



88
89
90
91
92
93
94
95
96
# File 'lib/a2a/types/artifact.rb', line 88

def validate!
  validate_required(:artifact_id, :parts)
  validate_type(:artifact_id, String)
  validate_array_type(:parts, Part)

  return unless @parts.empty?

  raise ArgumentError, "Artifact must have at least one part"
end