Skip to content

Commit 67c8163

Browse files
committed
Starting updating the server side
Signed-off-by: Emmanuel Hugonnet <[email protected]>
1 parent 10d7b86 commit 67c8163

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
@@ -13,6 +13,7 @@
1313
import com.google.protobuf.ByteString;
1414
import com.google.protobuf.Struct;
1515
import com.google.protobuf.Value;
16+
import io.a2a.grpc.ListTaskPushNotificationConfigResponse;
1617

1718
import io.a2a.grpc.StreamResponse;
1819
import io.a2a.spec.APIKeySecurityScheme;
@@ -530,6 +531,15 @@ private static io.a2a.grpc.AuthorizationCodeOAuthFlow authorizationCodeOAuthFlow
530531
return builder.build();
531532
}
532533

534+
public static io.a2a.grpc.ListTaskPushNotificationConfigResponse listTaskPushNotificationConfigResponse(List<TaskPushNotificationConfig> configs) {
535+
List<io.a2a.grpc.TaskPushNotificationConfig> confs = new ArrayList<>(configs.size());
536+
ListTaskPushNotificationConfigResponse.Builder response = ListTaskPushNotificationConfigResponse.newBuilder();
537+
for(TaskPushNotificationConfig config: configs) {
538+
confs.add(taskPushNotificationConfig(config));
539+
}
540+
return io.a2a.grpc.ListTaskPushNotificationConfigResponse.newBuilder().addAllConfigs(confs).build();
541+
}
542+
533543
private static io.a2a.grpc.ClientCredentialsOAuthFlow clientCredentialsOAuthFlow(ClientCredentialsOAuthFlow clientCredentialsOAuthFlow) {
534544
io.a2a.grpc.ClientCredentialsOAuthFlow.Builder builder = io.a2a.grpc.ClientCredentialsOAuthFlow.newBuilder();
535545
if (clientCredentialsOAuthFlow.refreshUrl() != null) {
@@ -699,17 +709,31 @@ public static MessageSendParams messageSendParams(io.a2a.grpc.SendMessageRequest
699709
}
700710

701711
public static TaskPushNotificationConfig taskPushNotificationConfig(io.a2a.grpc.CreateTaskPushNotificationConfigRequestOrBuilder request) {
702-
return taskPushNotificationConfig(request.getConfig());
712+
return taskPushNotificationConfig(request.getConfig(), true);
703713
}
704714

705715
public static TaskPushNotificationConfig taskPushNotificationConfig(io.a2a.grpc.TaskPushNotificationConfigOrBuilder config) {
716+
return taskPushNotificationConfig(config, false);
717+
}
718+
719+
private static TaskPushNotificationConfig taskPushNotificationConfig(io.a2a.grpc.TaskPushNotificationConfigOrBuilder config, boolean create) {
706720
String name = config.getName(); // "tasks/{id}/pushNotificationConfigs/{push_id}"
707721
String[] parts = name.split("/");
708-
if (parts.length < 4) {
709-
throw new IllegalArgumentException("Invalid name format for TaskPushNotificationConfig: " + name);
722+
String configId = "";
723+
if (create) {
724+
if (parts.length < 3) {
725+
throw new IllegalArgumentException("Invalid name format for TaskPushNotificationConfig: " + name);
726+
}
727+
if (parts.length == 4) {
728+
configId = parts[3];
729+
}
730+
} else {
731+
if (parts.length < 4) {
732+
throw new IllegalArgumentException("Invalid name format for TaskPushNotificationConfig: " + name);
733+
}
734+
configId = parts[3];
710735
}
711736
String taskId = parts[1];
712-
String configId = parts[3];
713737
PushNotificationConfig pnc = pushNotification(config.getPushNotificationConfig(), configId);
714738
return new TaskPushNotificationConfig(taskId, pnc);
715739
}
@@ -730,13 +754,12 @@ public static TaskIdParams taskIdParams(io.a2a.grpc.TaskSubscriptionRequestOrBui
730754
String id = name.substring(name.lastIndexOf('/') + 1);
731755
return new TaskIdParams(id);
732756
}
733-
734-
757+
735758
public static List<TaskPushNotificationConfig> listTaskPushNotificationConfigParams(io.a2a.grpc.ListTaskPushNotificationConfigResponseOrBuilder response) {
736759
List<io.a2a.grpc.TaskPushNotificationConfig> configs = response.getConfigsList();
737760
List<TaskPushNotificationConfig> result = new ArrayList<>(configs.size());
738761
for(io.a2a.grpc.TaskPushNotificationConfig config : configs) {
739-
result.add(taskPushNotificationConfig(config));
762+
result.add(taskPushNotificationConfig(config, false));
740763
}
741764
return result;
742765
}

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)