Skip to content

Commit 08f4e20

Browse files
committed
Updating and renaming all JSON-RPC method names to the new standard.
Signed-off-by: Emmanuel Hugonnet <[email protected]>
1 parent 7247303 commit 08f4e20

26 files changed

+97
-62
lines changed

client/transport/jsonrpc/src/test/java/io/a2a/client/transport/jsonrpc/JsonMessages.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public class JsonMessages {
165165
static final String SEND_MESSAGE_TEST_REQUEST = """
166166
{
167167
"jsonrpc":"2.0",
168-
"method":"message/send",
168+
"method":"SendMessage",
169169
"params":{
170170
"message":{
171171
"messageId":"message-1234",
@@ -214,7 +214,7 @@ public class JsonMessages {
214214
static final String SEND_MESSAGE_TEST_REQUEST_WITH_MESSAGE_RESPONSE = """
215215
{
216216
"jsonrpc":"2.0",
217-
"method":"message/send",
217+
"method":"SendMessage",
218218
"params":{
219219
"message":{
220220
"messageId":"message-1234",
@@ -263,7 +263,7 @@ public class JsonMessages {
263263
static final String SEND_MESSAGE_WITH_ERROR_TEST_REQUEST = """
264264
{
265265
"jsonrpc":"2.0",
266-
"method":"message/send",
266+
"method":"SendMessage",
267267
"params":{
268268
"message":{
269269
"messageId":"message-1234",
@@ -303,7 +303,7 @@ public class JsonMessages {
303303
static final String GET_TASK_TEST_REQUEST = """
304304
{
305305
"jsonrpc":"2.0",
306-
"method":"tasks/get",
306+
"method":"GetTask",
307307
"params":{
308308
"name":"tasks/de38c76d-d54c-436c-8b9f-4c2703648d64",
309309
"historyLength":10
@@ -363,7 +363,7 @@ public class JsonMessages {
363363
static final String CANCEL_TASK_TEST_REQUEST = """
364364
{
365365
"jsonrpc":"2.0",
366-
"method":"tasks/cancel",
366+
"method":"CancelTask",
367367
"params":{
368368
"name":"tasks/de38c76d-d54c-436c-8b9f-4c2703648d64"
369369
}
@@ -389,7 +389,7 @@ public class JsonMessages {
389389
static final String GET_TASK_PUSH_NOTIFICATION_CONFIG_TEST_REQUEST = """
390390
{
391391
"jsonrpc":"2.0",
392-
"method":"tasks/pushNotificationConfig/get",
392+
"method":"GetTaskPushNotificationConfig",
393393
"params":{
394394
"name":"tasks/de38c76d-d54c-436c-8b9f-4c2703648d64/pushNotificationConfigs"
395395
}
@@ -413,7 +413,7 @@ public class JsonMessages {
413413
static final String SET_TASK_PUSH_NOTIFICATION_CONFIG_TEST_REQUEST = """
414414
{
415415
"jsonrpc":"2.0",
416-
"method":"tasks/pushNotificationConfig/set",
416+
"method":"SetTaskPushNotificationConfig",
417417
"params":{
418418
"name":"tasks/de38c76d-d54c-436c-8b9f-4c2703648d64/pushNotificationConfigs",
419419
"pushNotificationConfig":{
@@ -445,7 +445,7 @@ public class JsonMessages {
445445
static final String SEND_MESSAGE_WITH_FILE_PART_TEST_REQUEST = """
446446
{
447447
"jsonrpc":"2.0",
448-
"method":"message/send",
448+
"method":"SendMessage",
449449
"params":{
450450
"message":{
451451
"messageId":"message-1234-with-file",
@@ -509,7 +509,7 @@ public class JsonMessages {
509509
static final String SEND_MESSAGE_WITH_DATA_PART_TEST_REQUEST = """
510510
{
511511
"jsonrpc":"2.0",
512-
"method":"message/send",
512+
"method":"SendMessage",
513513
"params":{
514514
"message":{
515515
"messageId":"message-1234-with-data",
@@ -577,7 +577,7 @@ public class JsonMessages {
577577
static final String SEND_MESSAGE_WITH_MIXED_PARTS_TEST_REQUEST = """
578578
{
579579
"jsonrpc":"2.0",
580-
"method":"message/send",
580+
"method":"SendMessage",
581581
"params":{
582582
"message":{
583583
"messageId":"message-1234-with-mixed",
@@ -651,7 +651,7 @@ public class JsonMessages {
651651
static final String GET_AUTHENTICATED_EXTENDED_AGENT_CARD_REQUEST = """
652652
{
653653
"jsonrpc": "2.0",
654-
"method": "agent/getAuthenticatedExtendedCard"
654+
"method": "GetExtendedAgentCard"
655655
}
656656
""";
657657

client/transport/jsonrpc/src/test/java/io/a2a/client/transport/jsonrpc/JsonStreamingMessages.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public class JsonStreamingMessages {
108108
public static final String SEND_MESSAGE_STREAMING_TEST_REQUEST = """
109109
{
110110
"jsonrpc":"2.0",
111-
"method":"message/stream",
111+
"method":"SendStreamingMessage",
112112
"params":{
113113
"message":{
114114
"messageId":"message-1234",

client/transport/spi/src/test/java/io/a2a/client/transport/spi/interceptors/auth/AuthInterceptorTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ private void testSecurityScheme(AuthTestCase authTestCase) {
138138
ClientCallContext context = new ClientCallContext(Map.of("sessionId", authTestCase.sessionId), Map.of());
139139

140140
PayloadAndHeaders result = authInterceptor.intercept(
141-
"message/send",
141+
"SendMessage",
142142
requestPayload,
143143
headers,
144144
agentCard,
@@ -155,7 +155,7 @@ void testAuthInterceptorWithoutAgentCard() {
155155
Map<String, String> headers = Map.of("foo", "bar");
156156

157157
PayloadAndHeaders result = authInterceptor.intercept(
158-
"message/send",
158+
"SendMessage",
159159
requestPayload,
160160
headers,
161161
null, // no agent card
@@ -207,7 +207,7 @@ void testCustomInterceptor() {
207207
Map<String, String> headers = Map.of();
208208

209209
PayloadAndHeaders result = interceptor.intercept(
210-
"message/send",
210+
"SendMessage",
211211
payload,
212212
headers,
213213
null,
@@ -245,7 +245,7 @@ void testAvailableSecuritySchemeNotInAgentCardSecuritySchemes() {
245245
ClientCallContext context = new ClientCallContext(Map.of("sessionId", sessionId), Map.of());
246246

247247
PayloadAndHeaders result = authInterceptor.intercept(
248-
"message/send",
248+
"SendMessage",
249249
requestPayload,
250250
headers,
251251
agentCard,
@@ -267,7 +267,7 @@ void testNoCredentialAvailable() {
267267
ClientCallContext context = new ClientCallContext(Map.of("sessionId", "session-id"), Map.of());
268268

269269
PayloadAndHeaders result = authInterceptor.intercept(
270-
"message/send",
270+
"SendMessage",
271271
requestPayload,
272272
headers,
273273
agentCard,
@@ -298,7 +298,7 @@ void testNoAgentCardSecuritySpecified() {
298298
ClientCallContext context = new ClientCallContext(Map.of("sessionId", "session-id"), Map.of());
299299

300300
PayloadAndHeaders result = authInterceptor.intercept(
301-
"message/send",
301+
"SendMessage",
302302
requestPayload,
303303
headers,
304304
agentCard,

reference/jsonrpc/src/test/java/io/a2a/server/apps/quarkus/A2AServerRoutesTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public void testSendMessage_MethodNameSetInContext() {
9999
String jsonRpcRequest = """
100100
{
101101
"jsonrpc": "2.0",
102-
"method": "message/send",
102+
"method": "SendMessage",
103103
"params": {
104104
"message": {
105105
"role": "user",
@@ -189,7 +189,7 @@ public void testGetTask_MethodNameSetInContext() {
189189
String jsonRpcRequest = """
190190
{
191191
"jsonrpc": "2.0",
192-
"method": "tasks/get",
192+
"method": "GetTask",
193193
"params": {
194194
"id": "de38c76d-d54c-436c-8b9f-4c2703648d64",
195195
"historyLength": 10
@@ -219,7 +219,7 @@ public void testCancelTask_MethodNameSetInContext() {
219219
String jsonRpcRequest = """
220220
{
221221
"jsonrpc": "2.0",
222-
"method": "tasks/cancel",
222+
"method": "CancelTask",
223223
"params": {
224224
"id": "de38c76d-d54c-436c-8b9f-4c2703648d64",
225225
"metadata": {}
@@ -280,7 +280,7 @@ public void testSetTaskPushNotificationConfig_MethodNameSetInContext() {
280280
String jsonRpcRequest = """
281281
{
282282
"jsonrpc": "2.0",
283-
"method": "tasks/pushNotificationConfig/set",
283+
"method": "SetTaskPushNotificationConfig",
284284
"params": {
285285
"taskId": "de38c76d-d54c-436c-8b9f-4c2703648d64",
286286
"pushNotificationConfig": {
@@ -316,7 +316,7 @@ public void testGetTaskPushNotificationConfig_MethodNameSetInContext() {
316316
String jsonRpcRequest = """
317317
{
318318
"jsonrpc": "2.0",
319-
"method": "tasks/pushNotificationConfig/get",
319+
"method": "GetTaskPushNotificationConfig",
320320
"params": {
321321
"id": "de38c76d-d54c-436c-8b9f-4c2703648d64",
322322
"metadata": {}
@@ -347,7 +347,7 @@ public void testListTaskPushNotificationConfig_MethodNameSetInContext() {
347347
String jsonRpcRequest = """
348348
{
349349
"jsonrpc": "2.0",
350-
"method": "tasks/pushNotificationConfig/list",
350+
"method": "ListTaskPushNotificationConfig",
351351
"params": {
352352
"id": "de38c76d-d54c-436c-8b9f-4c2703648d64"
353353
}
@@ -377,7 +377,7 @@ public void testDeleteTaskPushNotificationConfig_MethodNameSetInContext() {
377377
String jsonRpcRequest = """
378378
{
379379
"jsonrpc": "2.0",
380-
"method": "tasks/pushNotificationConfig/delete",
380+
"method": "DeleteTaskPushNotificationConfig",
381381
"params": {
382382
"id": "de38c76d-d54c-436c-8b9f-4c2703648d64",
383383
"pushNotificationConfigId": "config-456"

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

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.a2a.grpc.utils;
22

3-
43
import com.fasterxml.jackson.core.JsonProcessingException;
54
import com.fasterxml.jackson.databind.JsonMappingException;
65
import com.google.gson.Gson;
@@ -15,6 +14,7 @@
1514
import io.a2a.grpc.StreamResponse;
1615
import io.a2a.spec.CancelTaskRequest;
1716
import io.a2a.spec.CancelTaskResponse;
17+
import io.a2a.spec.ContentTypeNotSupportedError;
1818
import io.a2a.spec.DeleteTaskPushNotificationConfigRequest;
1919
import io.a2a.spec.DeleteTaskPushNotificationConfigResponse;
2020
import io.a2a.spec.GetAuthenticatedExtendedCardRequest;
@@ -24,7 +24,10 @@
2424
import io.a2a.spec.GetTaskRequest;
2525
import io.a2a.spec.GetTaskResponse;
2626
import io.a2a.spec.IdJsonMappingException;
27+
import io.a2a.spec.InvalidAgentResponseError;
2728
import io.a2a.spec.InvalidParamsError;
29+
import io.a2a.spec.InvalidRequestError;
30+
import io.a2a.spec.JSONParseError;
2831
import io.a2a.spec.JSONRPCError;
2932
import io.a2a.spec.JSONRPCMessage;
3033
import io.a2a.spec.JSONRPCRequest;
@@ -33,13 +36,18 @@
3336
import io.a2a.spec.ListTaskPushNotificationConfigResponse;
3437
import io.a2a.spec.ListTasksRequest;
3538
import io.a2a.spec.ListTasksResponse;
39+
import io.a2a.spec.MethodNotFoundError;
3640
import io.a2a.spec.MethodNotFoundJsonMappingException;
41+
import io.a2a.spec.PushNotificationNotSupportedError;
3742
import io.a2a.spec.SendMessageRequest;
3843
import io.a2a.spec.SendMessageResponse;
3944
import io.a2a.spec.SendStreamingMessageRequest;
4045
import io.a2a.spec.SetTaskPushNotificationConfigRequest;
4146
import io.a2a.spec.SetTaskPushNotificationConfigResponse;
4247
import io.a2a.spec.SubscribeToTaskRequest;
48+
import io.a2a.spec.TaskNotCancelableError;
49+
import io.a2a.spec.TaskNotFoundError;
50+
import io.a2a.spec.UnsupportedOperationError;
4351
import java.io.IOException;
4452
import java.io.StringWriter;
4553
import java.io.Writer;
@@ -123,12 +131,12 @@ public static JSONRPCRequest<?> parseRequestBody(String body) throws JsonProcess
123131
}
124132

125133
public static StreamResponse parseResponseEvent(String body) throws JsonProcessingException {
126-
JsonElement jelement = JsonParser.parseString(body);
134+
JsonElement jelement = JsonParser.parseString(body);
127135
JsonObject jsonRpc = jelement.getAsJsonObject();
128136
String version = getAndValidateJsonrpc(jsonRpc);
129137
Object id = getAndValidateId(jsonRpc);
130138
JsonElement paramsNode = jsonRpc.get("result");
131-
if(jsonRpc.has("error")) {
139+
if (jsonRpc.has("error")) {
132140
throw processError(jsonRpc.getAsJsonObject("error"));
133141
}
134142
StreamResponse.Builder builder = StreamResponse.newBuilder();
@@ -142,7 +150,7 @@ public static JSONRPCResponse<?> parseResponseBody(String body, String method) t
142150
String version = getAndValidateJsonrpc(jsonRpc);
143151
Object id = getAndValidateId(jsonRpc);
144152
JsonElement paramsNode = jsonRpc.get("result");
145-
if(jsonRpc.has("error")) {
153+
if (jsonRpc.has("error")) {
146154
return parseError(jsonRpc.getAsJsonObject("error"), id, method);
147155
}
148156
switch (method) {
@@ -174,7 +182,7 @@ public static JSONRPCResponse<?> parseResponseBody(String body, String method) t
174182
case SendMessageRequest.METHOD -> {
175183
io.a2a.grpc.SendMessageResponse.Builder builder = io.a2a.grpc.SendMessageResponse.newBuilder();
176184
parseRequestBody(paramsNode, builder);
177-
if(builder.hasMsg()) {
185+
if (builder.hasMsg()) {
178186
return new SendMessageResponse(id, ProtoUtils.FromProto.message(builder.getMsg()));
179187
}
180188
return new SendMessageResponse(id, ProtoUtils.FromProto.task(builder.getTask()));
@@ -225,14 +233,42 @@ public static JSONRPCResponse<?> parseError(JsonObject error, Object id, String
225233
return new DeleteTaskPushNotificationConfigResponse(id, rpcError);
226234
}
227235
default ->
228-
throw new MethodNotFoundJsonMappingException("Invalid method",id);
236+
throw new MethodNotFoundJsonMappingException("Invalid method", id);
229237
}
230238
}
231239

232240
private static JSONRPCError processError(JsonObject error) {
233241
String message = error.has("message") ? error.get("message").getAsString() : null;
234242
Integer code = error.has("code") ? error.get("code").getAsInt() : null;
235243
String data = error.has("data") ? error.get("data").toString() : null;
244+
if(code != null) {
245+
switch (code) {
246+
case JSONParseError.DEFAULT_CODE:
247+
return new JSONParseError(code, message, data);
248+
case InvalidRequestError.DEFAULT_CODE:
249+
return new InvalidRequestError(code, message, data);
250+
case MethodNotFoundError.DEFAULT_CODE:
251+
return new MethodNotFoundError(code, message, data);
252+
case InvalidParamsError.DEFAULT_CODE:
253+
return new InvalidParamsError(code, message, data);
254+
case io.a2a.spec.InternalError.DEFAULT_CODE:
255+
return new io.a2a.spec.InternalError(code, message, data);
256+
case PushNotificationNotSupportedError.DEFAULT_CODE:
257+
return new PushNotificationNotSupportedError(code, message, data);
258+
case UnsupportedOperationError.DEFAULT_CODE:
259+
return new UnsupportedOperationError(code, message, data);
260+
case ContentTypeNotSupportedError.DEFAULT_CODE:
261+
return new ContentTypeNotSupportedError(code, message, data);
262+
case InvalidAgentResponseError.DEFAULT_CODE:
263+
return new InvalidAgentResponseError(code, message, data);
264+
case TaskNotCancelableError.DEFAULT_CODE:
265+
return new TaskNotCancelableError(code, message, data);
266+
case TaskNotFoundError.DEFAULT_CODE:
267+
return new TaskNotFoundError(code, message, data);
268+
default:
269+
return new JSONRPCError(code, message, data);
270+
}
271+
}
236272
return new JSONRPCError(code, message, data);
237273
}
238274

@@ -290,8 +326,7 @@ protected static Object getAndValidateId(JsonObject jsonRpc) throws JsonProcessi
290326
}
291327

292328
public static String toJsonRPCRequest(String requestId, String method, com.google.protobuf.MessageOrBuilder builder) {
293-
try (StringWriter result = new StringWriter();
294-
JsonWriter output = GSON.newJsonWriter(result)) {
329+
try (StringWriter result = new StringWriter(); JsonWriter output = GSON.newJsonWriter(result)) {
295330
output.beginObject();
296331
output.name("jsonrpc").value("2.0");
297332
String id = requestId;
@@ -314,9 +349,9 @@ public static String toJsonRPCRequest(String requestId, String method, com.googl
314349
throw new RuntimeException(ex);
315350
}
316351
}
352+
317353
public static String toJsonRPCResponse(String requestId, String method, com.google.protobuf.MessageOrBuilder builder) {
318-
try (StringWriter result = new StringWriter();
319-
JsonWriter output = GSON.newJsonWriter(result)) {
354+
try (StringWriter result = new StringWriter(); JsonWriter output = GSON.newJsonWriter(result)) {
320355
output.beginObject();
321356
output.name("jsonrpc").value("2.0");
322357
String id = requestId;

spec/src/main/java/io/a2a/spec/CancelTaskRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
@JsonIgnoreProperties(ignoreUnknown = true)
3333
public final class CancelTaskRequest extends NonStreamingJSONRPCRequest<TaskIdParams> {
3434

35-
public static final String METHOD = "tasks/cancel";
35+
public static final String METHOD = "CancelTask";
3636

3737
@JsonCreator
3838
public CancelTaskRequest(@JsonProperty("jsonrpc") String jsonrpc, @JsonProperty("id") Object id,

spec/src/main/java/io/a2a/spec/ContentTypeNotSupportedError.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
@JsonIgnoreProperties(ignoreUnknown = true)
4545
public class ContentTypeNotSupportedError extends JSONRPCError {
4646

47-
public final static Integer DEFAULT_CODE = -32005;
47+
public final static int DEFAULT_CODE = -32005;
4848

4949
@JsonCreator
5050
public ContentTypeNotSupportedError(

spec/src/main/java/io/a2a/spec/DeleteTaskPushNotificationConfigRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
@JsonIgnoreProperties(ignoreUnknown = true)
2828
public final class DeleteTaskPushNotificationConfigRequest extends NonStreamingJSONRPCRequest<DeleteTaskPushNotificationConfigParams> {
2929

30-
public static final String METHOD = "tasks/pushNotificationConfig/delete";
30+
public static final String METHOD = "DeleteTaskPushNotificationConfig";
3131

3232
@JsonCreator
3333
public DeleteTaskPushNotificationConfigRequest(@JsonProperty("jsonrpc") String jsonrpc, @JsonProperty("id") Object id,

0 commit comments

Comments
 (0)