-
Notifications
You must be signed in to change notification settings - Fork 123
fix: Add missing extensions to Artifact and Message #409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -34,17 +34,18 @@ public final class Message implements EventKind, StreamingEventKind { | |||||
| private final Map<String, Object> metadata; | ||||||
| private final String kind; | ||||||
| private final List<String> referenceTaskIds; | ||||||
| private final List<String> extensions; | ||||||
|
|
||||||
| public Message(Role role, List<Part<?>> parts, String messageId, String contextId, String taskId, | ||||||
| List<String> referenceTaskIds, Map<String, Object> metadata) { | ||||||
| this(role, parts, messageId, contextId, taskId, referenceTaskIds, metadata, MESSAGE); | ||||||
| List<String> referenceTaskIds, Map<String, Object> metadata, List<String> extensions) { | ||||||
| this(role, parts, messageId, contextId, taskId, referenceTaskIds, metadata, extensions, MESSAGE); | ||||||
| } | ||||||
|
|
||||||
| @JsonCreator | ||||||
| public Message(@JsonProperty("role") Role role, @JsonProperty("parts") List<Part<?>> parts, | ||||||
| @JsonProperty("messageId") String messageId, @JsonProperty("contextId") String contextId, | ||||||
| @JsonProperty("taskId") String taskId, @JsonProperty("referenceTaskIds") List<String> referenceTaskIds, | ||||||
| @JsonProperty("metadata") Map<String, Object> metadata, | ||||||
| @JsonProperty("metadata") Map<String, Object> metadata, @JsonProperty("extensions") List<String> extensions, | ||||||
| @JsonProperty("kind") String kind) { | ||||||
| Assert.checkNotNullParam("kind", kind); | ||||||
| Assert.checkNotNullParam("parts", parts); | ||||||
|
|
@@ -63,6 +64,7 @@ public Message(@JsonProperty("role") Role role, @JsonProperty("parts") List<Part | |||||
| this.taskId = taskId; | ||||||
| this.referenceTaskIds = referenceTaskIds; | ||||||
| this.metadata = metadata; | ||||||
| this.extensions = extensions; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The For completeness, you might consider applying the same pattern to other collection fields like
Suggested change
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||||||
| this.kind = kind; | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -102,6 +104,10 @@ public List<String> getReferenceTaskIds() { | |||||
| return referenceTaskIds; | ||||||
| } | ||||||
|
|
||||||
| public List<String> getExtensions() { | ||||||
| return extensions; | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| public String getKind() { | ||||||
| return kind; | ||||||
|
|
@@ -132,6 +138,7 @@ public static class Builder { | |||||
| private String taskId; | ||||||
| private List<String> referenceTaskIds; | ||||||
| private Map<String, Object> metadata; | ||||||
| private List<String> extensions; | ||||||
|
|
||||||
| public Builder() { | ||||||
| } | ||||||
|
|
@@ -144,6 +151,7 @@ public Builder(Message message) { | |||||
| taskId = message.taskId; | ||||||
| referenceTaskIds = message.referenceTaskIds; | ||||||
| metadata = message.metadata; | ||||||
| extensions = message.extensions; | ||||||
| } | ||||||
|
|
||||||
| public Builder role(Role role) { | ||||||
|
|
@@ -186,9 +194,14 @@ public Builder metadata(Map<String, Object> metadata) { | |||||
| return this; | ||||||
| } | ||||||
|
|
||||||
| public Builder extensions(List<String> extensions) { | ||||||
| this.extensions = (extensions == null) ? null : List.copyOf(extensions); | ||||||
| return this; | ||||||
| } | ||||||
|
|
||||||
| public Message build() { | ||||||
| return new Message(role, parts, messageId == null ? UUID.randomUUID().toString() : messageId, | ||||||
| contextId, taskId, referenceTaskIds, metadata); | ||||||
| contextId, taskId, referenceTaskIds, metadata, extensions); | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To ensure the immutability of the
Artifactrecord, it's a good practice to create a defensive copy of theextensionslist. Assigning the list directly allows theArtifact's internal state to be modified from outside if a mutable list is passed to the builder. This would violate the immutability contract of a record.I noticed that the
parts(Part<?>... parts)method correctly usesList.of()to create an immutable list. This newextensionsmethod should follow a similar robust pattern.For consistency and robustness, you might also consider applying this to other collection-based builder methods like
parts(List<Part<?>> parts)andmetadata(Map<String, Object> metadata).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed