Repository navigation
Expand file tree
/
Copy pathArtifactUtils.java
More file actions
108 lines (98 loc) · 3.78 KB
/
Copy pathArtifactUtils.java
File metadata and controls
108 lines (98 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package io.a2a.server.util;
import java.util.List;
import java.util.UUID;
import io.a2a.spec.Artifact;
import io.a2a.spec.DataPart;
import io.a2a.spec.Part;
import io.a2a.spec.TextPart;
import org.jspecify.annotations.Nullable;
/**
* Utility functions for creating A2A Artifact objects.
*/
public final class ArtifactUtils {
private ArtifactUtils() {
// Utility class - prevent instantiation
}
/**
* Creates a new Artifact object.
*
* @param name The human-readable name of the artifact.
* @param parts The list of {@code Part} objects forming the artifact's content.
* @param description An optional description of the artifact.
* @return A new {@code Artifact} object with a generated artifact_id.
*/
public static Artifact newArtifact(String name, List<Part<?>> parts, @Nullable String description) {
return new Artifact(
UUID.randomUUID().toString(),
name,
description,
parts,
null,
null
);
}
/**
* Creates a new Artifact object with empty description.
*
* @param name The human-readable name of the artifact.
* @param parts The list of {@code Part} objects forming the artifact's content.
* @return A new {@code Artifact} object with a generated artifact_id.
*/
public static Artifact newArtifact(String name, List<Part<?>> parts) {
return newArtifact(name, parts, null);
}
/**
* Creates a new Artifact object containing only a single TextPart.
*
* @param name The human-readable name of the artifact.
* @param text The text content of the artifact.
* @param description An optional description of the artifact.
* @return A new {@code Artifact} object with a generated artifact_id.
*/
public static Artifact newTextArtifact(String name, String text, @Nullable String description) {
return newArtifact(
name,
List.of(new TextPart(text)),
description
);
}
/**
* Creates a new Artifact object containing only a single TextPart with empty description.
*
* @param name The human-readable name of the artifact.
* @param text The text content of the artifact.
* @return A new {@code Artifact} object with a generated artifact_id.
*/
public static Artifact newTextArtifact(String name, String text) {
return newTextArtifact(name, text, null);
}
/**
* Creates a new Artifact object containing only a single DataPart.
* <p>
* Supports any JSON value type: objects (Map), arrays (List), primitives (String, Number, Boolean), or null.
*
* @param name The human-readable name of the artifact.
* @param data The structured data content of the artifact (JSON object, array, primitive, or null).
* @param description An optional description of the artifact.
* @return A new {@code Artifact} object with a generated artifact_id.
*/
public static Artifact newDataArtifact(String name, Object data, @Nullable String description) {
return newArtifact(
name,
List.of(new DataPart(data)),
description
);
}
/**
* Creates a new Artifact object containing only a single DataPart with empty description.
* <p>
* Supports any JSON value type: objects (Map), arrays (List), primitives (String, Number, Boolean), or null.
*
* @param name The human-readable name of the artifact.
* @param data The structured data content of the artifact (JSON object, array, primitive, or null).
* @return A new {@code Artifact} object with a generated artifact_id.
*/
public static Artifact newDataArtifact(String name, Object data) {
return newDataArtifact(name, data, null);
}
}