Skip to content

Commit 06905cf

Browse files
committed
Starting updating the server side
Signed-off-by: Emmanuel Hugonnet <[email protected]>
1 parent 70acabf commit 06905cf

File tree

6 files changed

+213
-166
lines changed

6 files changed

+213
-166
lines changed

client/src/main/java/io/a2a/client/transport/JSONRestTransport.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ public JSONRestTransport(A2AHttpClient httpClient, AgentCard agentCard,
6767
public EventKind sendMessage(MessageSendParams messageSendParams, ClientCallContext context) throws A2AClientException {
6868
checkNotNullParam("messageSendParams", messageSendParams);
6969
io.a2a.grpc.SendMessageRequest.Builder builder = io.a2a.grpc.SendMessageRequest.newBuilder(ProtoUtils.ToProto.sendMessageRequest(messageSendParams));
70-
PayloadAndHeaders payloadAndHeaders = applyInterceptors(io.a2a.spec.SendMessageRequest.METHOD, builder.getRequestOrBuilder(),
71-
agentCard, context);
70+
PayloadAndHeaders payloadAndHeaders = applyInterceptors(io.a2a.spec.SendMessageRequest.METHOD, builder, agentCard, context);
7271
try {
7372
String httpResponseBody = sendPostRequest(agentUrl + "/v1/message:send", payloadAndHeaders);
7473
io.a2a.grpc.SendMessageResponse.Builder responseBuilder = io.a2a.grpc.SendMessageResponse.newBuilder();

client/src/test/java/io/a2a/client/transport/JsonRestMessages.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@ public class JsonRestMessages {
88

99
static final String SEND_MESSAGE_TEST_REQUEST = """
1010
{
11-
"messageId": "message-1234",
12-
"contextId": "context-1234",
13-
"role": "ROLE_USER",
14-
"content": [{
15-
"text": "tell me a joke"
16-
}],
17-
"metadata": {
11+
"message":
12+
{
13+
"messageId": "message-1234",
14+
"contextId": "context-1234",
15+
"role": "ROLE_USER",
16+
"content": [{
17+
"text": "tell me a joke"
18+
}],
19+
"metadata": {
20+
}
1821
}
1922
}""";
2023

@@ -629,7 +632,7 @@ public class JsonRestMessages {
629632
}
630633
],
631634
"messageId": "message-1234",
632-
"contextId": "context-1234",
635+
"contextId": "context-1234"
633636
},
634637
"configuration": {
635638
"acceptedOutputModes": ["text"]

spec-grpc/src/main/java/io/a2a/grpc/utils/ProtoUtils.java

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.google.protobuf.ByteString;
1313
import com.google.protobuf.Struct;
1414
import com.google.protobuf.Value;
15+
import io.a2a.grpc.ListTaskPushNotificationConfigResponse;
1516

1617
import io.a2a.grpc.StreamResponse;
1718
import io.a2a.spec.APIKeySecurityScheme;
@@ -509,6 +510,15 @@ private static io.a2a.grpc.AuthorizationCodeOAuthFlow authorizationCodeOAuthFlow
509510
return builder.build();
510511
}
511512

513+
public static io.a2a.grpc.ListTaskPushNotificationConfigResponse listTaskPushNotificationConfigResponse(List<TaskPushNotificationConfig> configs) {
514+
List<io.a2a.grpc.TaskPushNotificationConfig> confs = new ArrayList<>(configs.size());
515+
ListTaskPushNotificationConfigResponse.Builder response = ListTaskPushNotificationConfigResponse.newBuilder();
516+
for(TaskPushNotificationConfig config: configs) {
517+
confs.add(taskPushNotificationConfig(config));
518+
}
519+
return io.a2a.grpc.ListTaskPushNotificationConfigResponse.newBuilder().addAllConfigs(confs).build();
520+
}
521+
512522
private static io.a2a.grpc.ClientCredentialsOAuthFlow clientCredentialsOAuthFlow(ClientCredentialsOAuthFlow clientCredentialsOAuthFlow) {
513523
io.a2a.grpc.ClientCredentialsOAuthFlow.Builder builder = io.a2a.grpc.ClientCredentialsOAuthFlow.newBuilder();
514524
if (clientCredentialsOAuthFlow.refreshUrl() != null) {
@@ -679,17 +689,31 @@ public static MessageSendParams messageSendParams(io.a2a.grpc.SendMessageRequest
679689
}
680690

681691
public static TaskPushNotificationConfig taskPushNotificationConfig(io.a2a.grpc.CreateTaskPushNotificationConfigRequestOrBuilder request) {
682-
return taskPushNotificationConfig(request.getConfig());
692+
return taskPushNotificationConfig(request.getConfig(), true);
683693
}
684694

685695
public static TaskPushNotificationConfig taskPushNotificationConfig(io.a2a.grpc.TaskPushNotificationConfigOrBuilder config) {
696+
return taskPushNotificationConfig(config, false);
697+
}
698+
699+
private static TaskPushNotificationConfig taskPushNotificationConfig(io.a2a.grpc.TaskPushNotificationConfigOrBuilder config, boolean create) {
686700
String name = config.getName(); // "tasks/{id}/pushNotificationConfigs/{push_id}"
687701
String[] parts = name.split("/");
688-
if (parts.length < 4) {
689-
throw new IllegalArgumentException("Invalid name format for TaskPushNotificationConfig: " + name);
702+
String configId = "";
703+
if (create) {
704+
if (parts.length < 3) {
705+
throw new IllegalArgumentException("Invalid name format for TaskPushNotificationConfig: " + name);
706+
}
707+
if (parts.length == 4) {
708+
configId = parts[3];
709+
}
710+
} else {
711+
if (parts.length < 4) {
712+
throw new IllegalArgumentException("Invalid name format for TaskPushNotificationConfig: " + name);
713+
}
714+
configId = parts[3];
690715
}
691716
String taskId = parts[1];
692-
String configId = parts[3];
693717
PushNotificationConfig pnc = pushNotification(config.getPushNotificationConfig(), configId);
694718
return new TaskPushNotificationConfig(taskId, pnc);
695719
}
@@ -710,13 +734,12 @@ public static TaskIdParams taskIdParams(io.a2a.grpc.TaskSubscriptionRequestOrBui
710734
String id = name.substring(name.lastIndexOf('/') + 1);
711735
return new TaskIdParams(id);
712736
}
713-
714-
737+
715738
public static List<TaskPushNotificationConfig> listTaskPushNotificationConfigParams(io.a2a.grpc.ListTaskPushNotificationConfigResponseOrBuilder response) {
716739
List<io.a2a.grpc.TaskPushNotificationConfig> configs = response.getConfigsList();
717740
List<TaskPushNotificationConfig> result = new ArrayList<>(configs.size());
718741
for(io.a2a.grpc.TaskPushNotificationConfig config : configs) {
719-
result.add(taskPushNotificationConfig(config));
742+
result.add(taskPushNotificationConfig(config, false));
720743
}
721744
return result;
722745
}

transport/httprest/pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@
4848
<groupId>com.fasterxml.jackson.datatype</groupId>
4949
<artifactId>jackson-datatype-jsr310</artifactId>
5050
</dependency>
51+
<dependency>
52+
<groupId>com.google.protobuf</groupId>
53+
<artifactId>protobuf-java-util</artifactId>
54+
<type>jar</type>
55+
</dependency>
56+
<dependency>
57+
<groupId>org.slf4j</groupId>
58+
<artifactId>slf4j-jdk14</artifactId>
59+
<scope>test</scope>
60+
</dependency>
5161

5262
</dependencies>
5363

0 commit comments

Comments
 (0)