Class: A2A::Types::Artifact
- Defined in:
- lib/a2a/types/artifact.rb
Instance Attribute Summary collapse
-
#artifact_id ⇒ Object
readonly
Returns the value of attribute artifact_id.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#extensions ⇒ Object
readonly
Returns the value of attribute extensions.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parts ⇒ Object
readonly
Returns the value of attribute parts.
Instance Method Summary collapse
-
#add_part(part) ⇒ Object
Add a part to the artifact.
-
#data_parts ⇒ Array<DataPart>
Get all data parts from the artifact.
-
#file_parts ⇒ Array<FilePart>
Get all file parts from the artifact.
-
#has_content? ⇒ Boolean
Check if the artifact has any content.
-
#initialize(artifact_id:, parts:, name: nil, description: nil, metadata: nil, extensions: nil) ⇒ Artifact
constructor
Initialize a new artifact.
-
#text_content ⇒ String
Get all text content from the artifact.
-
#total_file_size ⇒ Integer
Get the total size of all file parts.
- #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(artifact_id:, parts:, name: nil, description: nil, metadata: nil, extensions: nil) ⇒ Artifact
Initialize a new artifact
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_id ⇒ Object (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 |
#description ⇒ Object (readonly)
Returns the value of attribute description.
12 13 14 |
# File 'lib/a2a/types/artifact.rb', line 12 def description @description end |
#extensions ⇒ Object (readonly)
Returns the value of attribute extensions.
12 13 14 |
# File 'lib/a2a/types/artifact.rb', line 12 def extensions @extensions end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
12 13 14 |
# File 'lib/a2a/types/artifact.rb', line 12 def end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/a2a/types/artifact.rb', line 12 def name @name end |
#parts ⇒ Object (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
64 65 66 |
# File 'lib/a2a/types/artifact.rb', line 64 def add_part(part) @parts << part end |
#data_parts ⇒ Array<DataPart>
Get all data parts from the artifact
56 57 58 |
# File 'lib/a2a/types/artifact.rb', line 56 def data_parts @parts.select { |p| p.is_a?(DataPart) } end |
#file_parts ⇒ Array<FilePart>
Get all file parts from the artifact
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
72 73 74 |
# File 'lib/a2a/types/artifact.rb', line 72 def has_content? !@parts.empty? end |
#text_content ⇒ String
Get all text content from the artifact
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_size ⇒ Integer
Get the total size of all file parts
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)
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 |