Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ nb-configuration.xml
/.quarkus/cli/plugins/
# TLS Certificates
.certs/
nbproject/

15 changes: 15 additions & 0 deletions spec-grpc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@
<artifactId>javax.annotation-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
100 changes: 66 additions & 34 deletions spec-grpc/src/main/java/io/a2a/grpc/utils/ProtoUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.a2a.grpc.utils;


import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -61,6 +62,7 @@
* Utility class to convert between GRPC and Spec objects.
*/
public class ProtoUtils {

public static class ToProto {

public static io.a2a.grpc.AgentCard agentCard(AgentCard agentCard) {
Expand Down Expand Up @@ -143,8 +145,12 @@ public static io.a2a.grpc.Task task(Task task) {
public static io.a2a.grpc.Message message(Message message) {
io.a2a.grpc.Message.Builder builder = io.a2a.grpc.Message.newBuilder();
builder.setMessageId(message.getMessageId());
builder.setContextId(message.getContextId());
builder.setTaskId(message.getTaskId());
if (message.getContextId() != null) {
builder.setContextId(message.getContextId());
}
if (message.getTaskId() != null) {
builder.setTaskId(message.getTaskId());
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the corresponding message method in FromProto will need to be updated so the value is only set if non empty.

builder.setRole(role(message.getRole()));
if (message.getParts() != null) {
builder.addAllContent(message.getParts().stream().map(ToProto::part).collect(Collectors.toList()));
Expand All @@ -171,7 +177,7 @@ private static io.a2a.grpc.PushNotificationConfig pushNotificationConfig(PushNot
if (config.authentication() != null) {
builder.setAuthentication(authenticationInfo(config.authentication()));
}
if (config.id() != null) {
if (config.id() != null) {
builder.setId(config.id());
}
return builder.build();
Expand All @@ -182,8 +188,12 @@ public static io.a2a.grpc.TaskArtifactUpdateEvent taskArtifactUpdateEvent(TaskAr
builder.setTaskId(event.getTaskId());
builder.setContextId(event.getContextId());
builder.setArtifact(artifact(event.getArtifact()));
builder.setAppend(event.isAppend() == null ? false : event.isAppend());
builder.setLastChunk(event.isLastChunk() == null ? false : event.isLastChunk());
if (event.isAppend() != null) {
builder.setAppend(event.isAppend());
}
if (event.isLastChunk() != null) {
builder.setLastChunk(event.isLastChunk());
}
if (event.getMetadata() != null) {
builder.setMetadata(struct(event.getMetadata()));
}
Expand Down Expand Up @@ -258,8 +268,10 @@ private static io.a2a.grpc.Role role(Message.Role role) {
return io.a2a.grpc.Role.ROLE_UNSPECIFIED;
}
return switch (role) {
case USER -> io.a2a.grpc.Role.ROLE_USER;
case AGENT -> io.a2a.grpc.Role.ROLE_AGENT;
case USER ->
io.a2a.grpc.Role.ROLE_USER;
case AGENT ->
io.a2a.grpc.Role.ROLE_AGENT;
};
}

Expand All @@ -283,15 +295,24 @@ private static io.a2a.grpc.TaskState taskState(TaskState taskState) {
return io.a2a.grpc.TaskState.TASK_STATE_UNSPECIFIED;
}
return switch (taskState) {
case SUBMITTED -> io.a2a.grpc.TaskState.TASK_STATE_SUBMITTED;
case WORKING -> io.a2a.grpc.TaskState.TASK_STATE_WORKING;
case INPUT_REQUIRED -> io.a2a.grpc.TaskState.TASK_STATE_INPUT_REQUIRED;
case AUTH_REQUIRED -> io.a2a.grpc.TaskState.TASK_STATE_AUTH_REQUIRED;
case COMPLETED -> io.a2a.grpc.TaskState.TASK_STATE_COMPLETED;
case CANCELED -> io.a2a.grpc.TaskState.TASK_STATE_CANCELLED;
case FAILED -> io.a2a.grpc.TaskState.TASK_STATE_FAILED;
case REJECTED -> io.a2a.grpc.TaskState.TASK_STATE_REJECTED;
default -> io.a2a.grpc.TaskState.TASK_STATE_UNSPECIFIED;
case SUBMITTED ->
io.a2a.grpc.TaskState.TASK_STATE_SUBMITTED;
case WORKING ->
io.a2a.grpc.TaskState.TASK_STATE_WORKING;
case INPUT_REQUIRED ->
io.a2a.grpc.TaskState.TASK_STATE_INPUT_REQUIRED;
case AUTH_REQUIRED ->
io.a2a.grpc.TaskState.TASK_STATE_AUTH_REQUIRED;
case COMPLETED ->
io.a2a.grpc.TaskState.TASK_STATE_COMPLETED;
case CANCELED ->
io.a2a.grpc.TaskState.TASK_STATE_CANCELLED;
case FAILED ->
io.a2a.grpc.TaskState.TASK_STATE_FAILED;
case REJECTED ->
io.a2a.grpc.TaskState.TASK_STATE_REJECTED;
default ->
io.a2a.grpc.TaskState.TASK_STATE_UNSPECIFIED;
};
}

Expand Down Expand Up @@ -596,7 +617,6 @@ public static io.a2a.grpc.SendMessageResponse taskOrMessage(EventKind eventKind)
}
}


}

public static class FromProto {
Expand Down Expand Up @@ -734,8 +754,8 @@ public static Message message(io.a2a.grpc.Message message) {
return new Message(
role(message.getRole()),
message.getContentList().stream().map(item -> part(item)).collect(Collectors.toList()),
message.getMessageId(),
message.getContextId(),
message.getMessageId().isEmpty() ? null : message.getMessageId(),
message.getContextId().isEmpty() ? null : message.getContextId(),
message.getTaskId(),
null, // referenceTaskIds is not in grpc message
struct(message.getMetadata())
Expand Down Expand Up @@ -814,9 +834,12 @@ private static Message.Role role(io.a2a.grpc.Role role) {
return null;
}
return switch (role) {
case ROLE_USER -> Message.Role.USER;
case ROLE_AGENT -> Message.Role.AGENT;
default -> null;
case ROLE_USER ->
Message.Role.USER;
case ROLE_AGENT ->
Message.Role.AGENT;
default ->
null;
};
}

Expand All @@ -825,16 +848,26 @@ private static TaskState taskState(io.a2a.grpc.TaskState taskState) {
return null;
}
return switch (taskState) {
case TASK_STATE_SUBMITTED -> TaskState.SUBMITTED;
case TASK_STATE_WORKING -> TaskState.WORKING;
case TASK_STATE_INPUT_REQUIRED -> TaskState.INPUT_REQUIRED;
case TASK_STATE_AUTH_REQUIRED -> TaskState.AUTH_REQUIRED;
case TASK_STATE_COMPLETED -> TaskState.COMPLETED;
case TASK_STATE_CANCELLED -> TaskState.CANCELED;
case TASK_STATE_FAILED -> TaskState.FAILED;
case TASK_STATE_REJECTED -> TaskState.REJECTED;
case TASK_STATE_UNSPECIFIED -> null;
case UNRECOGNIZED -> null;
case TASK_STATE_SUBMITTED ->
TaskState.SUBMITTED;
case TASK_STATE_WORKING ->
TaskState.WORKING;
case TASK_STATE_INPUT_REQUIRED ->
TaskState.INPUT_REQUIRED;
case TASK_STATE_AUTH_REQUIRED ->
TaskState.AUTH_REQUIRED;
case TASK_STATE_COMPLETED ->
TaskState.COMPLETED;
case TASK_STATE_CANCELLED ->
TaskState.CANCELED;
case TASK_STATE_FAILED ->
TaskState.FAILED;
case TASK_STATE_REJECTED ->
TaskState.REJECTED;
case TASK_STATE_UNSPECIFIED ->
null;
case UNRECOGNIZED ->
null;
};
}

Expand Down Expand Up @@ -867,5 +900,4 @@ private static Object value(Value value) {
}
}


}
}
Loading