|
1 | 1 | package io.a2a.client; |
2 | 2 |
|
3 | | -import static io.a2a.spec.A2A.CANCEL_TASK_METHOD; |
4 | | -import static io.a2a.spec.A2A.GET_TASK_METHOD; |
5 | | -import static io.a2a.spec.A2A.GET_TASK_PUSH_NOTIFICATION_CONFIG_METHOD; |
6 | | -import static io.a2a.spec.A2A.JSONRPC_VERSION; |
7 | | -import static io.a2a.spec.A2A.SEND_MESSAGE_METHOD; |
8 | | -import static io.a2a.spec.A2A.SEND_STREAMING_MESSAGE_METHOD; |
9 | | -import static io.a2a.spec.A2A.SEND_TASK_RESUBSCRIPTION_METHOD; |
10 | | -import static io.a2a.spec.A2A.SET_TASK_PUSH_NOTIFICATION_CONFIG_METHOD; |
11 | 3 | import static io.a2a.util.Assert.checkNotNullParam; |
12 | | -import static io.a2a.util.Utils.OBJECT_MAPPER; |
13 | | -import static io.a2a.util.Utils.unmarshalFrom; |
14 | 4 |
|
15 | 5 | import java.io.IOException; |
16 | 6 | import java.util.Map; |
|
24 | 14 | import io.a2a.http.A2AHttpClient; |
25 | 15 | import io.a2a.http.A2AHttpResponse; |
26 | 16 | import io.a2a.http.JdkA2AHttpClient; |
27 | | -import io.a2a.spec.A2A; |
| 17 | +import io.a2a.A2A; |
28 | 18 | import io.a2a.spec.A2AClientError; |
29 | 19 | import io.a2a.spec.A2AClientJSONError; |
30 | 20 | import io.a2a.spec.A2AServerException; |
|
36 | 26 | import io.a2a.spec.GetTaskRequest; |
37 | 27 | import io.a2a.spec.GetTaskResponse; |
38 | 28 | import io.a2a.spec.JSONRPCError; |
| 29 | +import io.a2a.spec.JSONRPCMessage; |
39 | 30 | import io.a2a.spec.JSONRPCResponse; |
40 | 31 | import io.a2a.spec.MessageSendParams; |
41 | 32 | import io.a2a.spec.PushNotificationConfig; |
|
49 | 40 | import io.a2a.spec.TaskPushNotificationConfig; |
50 | 41 | import io.a2a.spec.TaskQueryParams; |
51 | 42 | import io.a2a.spec.TaskResubscriptionRequest; |
| 43 | +import io.a2a.util.Utils; |
52 | 44 |
|
53 | 45 | /** |
54 | 46 | * An A2A client. |
@@ -158,8 +150,8 @@ public SendMessageResponse sendMessage(MessageSendParams messageSendParams) thro |
158 | 150 | */ |
159 | 151 | public SendMessageResponse sendMessage(String requestId, MessageSendParams messageSendParams) throws A2AServerException { |
160 | 152 | SendMessageRequest.Builder sendMessageRequestBuilder = new SendMessageRequest.Builder() |
161 | | - .jsonrpc(JSONRPC_VERSION) |
162 | | - .method(SEND_MESSAGE_METHOD) |
| 153 | + .jsonrpc(JSONRPCMessage.JSONRPC_VERSION) |
| 154 | + .method(SendMessageRequest.METHOD) |
163 | 155 | .params(messageSendParams); |
164 | 156 |
|
165 | 157 | if (requestId != null) { |
@@ -210,8 +202,8 @@ public GetTaskResponse getTask(TaskQueryParams taskQueryParams) throws A2AServer |
210 | 202 | */ |
211 | 203 | public GetTaskResponse getTask(String requestId, TaskQueryParams taskQueryParams) throws A2AServerException { |
212 | 204 | GetTaskRequest.Builder getTaskRequestBuilder = new GetTaskRequest.Builder() |
213 | | - .jsonrpc(JSONRPC_VERSION) |
214 | | - .method(GET_TASK_METHOD) |
| 205 | + .jsonrpc(JSONRPCMessage.JSONRPC_VERSION) |
| 206 | + .method(GetTaskRequest.METHOD) |
215 | 207 | .params(taskQueryParams); |
216 | 208 |
|
217 | 209 | if (requestId != null) { |
@@ -260,8 +252,8 @@ public CancelTaskResponse cancelTask(TaskIdParams taskIdParams) throws A2AServer |
260 | 252 | */ |
261 | 253 | public CancelTaskResponse cancelTask(String requestId, TaskIdParams taskIdParams) throws A2AServerException { |
262 | 254 | CancelTaskRequest.Builder cancelTaskRequestBuilder = new CancelTaskRequest.Builder() |
263 | | - .jsonrpc(JSONRPC_VERSION) |
264 | | - .method(CANCEL_TASK_METHOD) |
| 255 | + .jsonrpc(JSONRPCMessage.JSONRPC_VERSION) |
| 256 | + .method(CancelTaskRequest.METHOD) |
265 | 257 | .params(taskIdParams); |
266 | 258 |
|
267 | 259 | if (requestId != null) { |
@@ -310,8 +302,8 @@ public GetTaskPushNotificationConfigResponse getTaskPushNotificationConfig(TaskI |
310 | 302 | */ |
311 | 303 | public GetTaskPushNotificationConfigResponse getTaskPushNotificationConfig(String requestId, TaskIdParams taskIdParams) throws A2AServerException { |
312 | 304 | GetTaskPushNotificationConfigRequest.Builder getTaskPushNotificationRequestBuilder = new GetTaskPushNotificationConfigRequest.Builder() |
313 | | - .jsonrpc(JSONRPC_VERSION) |
314 | | - .method(GET_TASK_PUSH_NOTIFICATION_CONFIG_METHOD) |
| 305 | + .jsonrpc(JSONRPCMessage.JSONRPC_VERSION) |
| 306 | + .method(GetTaskPushNotificationConfigRequest.METHOD) |
315 | 307 | .params(taskIdParams); |
316 | 308 |
|
317 | 309 | if (requestId != null) { |
@@ -353,8 +345,8 @@ public SetTaskPushNotificationConfigResponse setTaskPushNotificationConfig(Strin |
353 | 345 | public SetTaskPushNotificationConfigResponse setTaskPushNotificationConfig(String requestId, String taskId, |
354 | 346 | PushNotificationConfig pushNotificationConfig) throws A2AServerException { |
355 | 347 | SetTaskPushNotificationConfigRequest.Builder setTaskPushNotificationRequestBuilder = new SetTaskPushNotificationConfigRequest.Builder() |
356 | | - .jsonrpc(JSONRPC_VERSION) |
357 | | - .method(SET_TASK_PUSH_NOTIFICATION_CONFIG_METHOD) |
| 348 | + .jsonrpc(JSONRPCMessage.JSONRPC_VERSION) |
| 349 | + .method(SetTaskPushNotificationConfigRequest.METHOD) |
358 | 350 | .params(new TaskPushNotificationConfig(taskId, pushNotificationConfig)); |
359 | 351 |
|
360 | 352 | if (requestId != null) { |
@@ -403,8 +395,8 @@ public void sendStreamingMessage(String requestId, MessageSendParams messageSend |
403 | 395 | checkNotNullParam("failureHandler", failureHandler); |
404 | 396 |
|
405 | 397 | SendStreamingMessageRequest.Builder sendStreamingMessageRequestBuilder = new SendStreamingMessageRequest.Builder() |
406 | | - .jsonrpc(JSONRPC_VERSION) |
407 | | - .method(SEND_STREAMING_MESSAGE_METHOD) |
| 398 | + .jsonrpc(JSONRPCMessage.JSONRPC_VERSION) |
| 399 | + .method(SendStreamingMessageRequest.METHOD) |
408 | 400 | .params(messageSendParams); |
409 | 401 |
|
410 | 402 | if (requestId != null) { |
@@ -462,8 +454,8 @@ public void resubscribeToTask(String requestId, TaskIdParams taskIdParams, Consu |
462 | 454 | checkNotNullParam("failureHandler", failureHandler); |
463 | 455 |
|
464 | 456 | TaskResubscriptionRequest.Builder taskResubscriptionRequestBuilder = new TaskResubscriptionRequest.Builder() |
465 | | - .jsonrpc(JSONRPC_VERSION) |
466 | | - .method(SEND_TASK_RESUBSCRIPTION_METHOD) |
| 457 | + .jsonrpc(JSONRPCMessage.JSONRPC_VERSION) |
| 458 | + .method(TaskResubscriptionRequest.METHOD) |
467 | 459 | .params(taskIdParams); |
468 | 460 |
|
469 | 461 | if (requestId != null) { |
@@ -502,13 +494,13 @@ private A2AHttpClient.PostBuilder createPostBuilder(Object value) throws JsonPro |
502 | 494 | return httpClient.createPost() |
503 | 495 | .url(agentUrl) |
504 | 496 | .addHeader("Content-Type", "application/json") |
505 | | - .body(OBJECT_MAPPER.writeValueAsString(value)); |
| 497 | + .body(Utils.OBJECT_MAPPER.writeValueAsString(value)); |
506 | 498 |
|
507 | 499 | } |
508 | 500 |
|
509 | 501 | private <T extends JSONRPCResponse> T unmarshalResponse(String response, TypeReference<T> typeReference) |
510 | 502 | throws A2AServerException, JsonProcessingException { |
511 | | - T value = unmarshalFrom(response, typeReference); |
| 503 | + T value = Utils.unmarshalFrom(response, typeReference); |
512 | 504 | JSONRPCError error = value.getError(); |
513 | 505 | if (error != null) { |
514 | 506 | throw new A2AServerException(error.getMessage() + (error.getData() != null ? ": " + error.getData() : "")); |
|
0 commit comments