11package io .a2a .client ;
22
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- 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-
153import java .io .IOException ;
164import java .util .Map ;
175import java .util .concurrent .CompletableFuture ;
2412import io .a2a .http .A2AHttpClient ;
2513import io .a2a .http .A2AHttpResponse ;
2614import io .a2a .http .JdkA2AHttpClient ;
27- import io .a2a .spec . A2A ;
15+ import io .a2a .A2A ;
2816import io .a2a .spec .A2AClientError ;
2917import io .a2a .spec .A2AClientJSONError ;
3018import io .a2a .spec .A2AServerException ;
3624import io .a2a .spec .GetTaskRequest ;
3725import io .a2a .spec .GetTaskResponse ;
3826import io .a2a .spec .JSONRPCError ;
27+ import io .a2a .spec .JSONRPCMessage ;
3928import io .a2a .spec .JSONRPCResponse ;
4029import io .a2a .spec .MessageSendParams ;
4130import io .a2a .spec .PushNotificationConfig ;
4938import io .a2a .spec .TaskPushNotificationConfig ;
5039import io .a2a .spec .TaskQueryParams ;
5140import io .a2a .spec .TaskResubscriptionRequest ;
41+ import io .a2a .util .Assert ;
42+ import io .a2a .util .Utils ;
5243
5344/**
5445 * An A2A client.
@@ -71,7 +62,7 @@ public class A2AClient {
7162 * @param agentCard the agent card for the A2A server this client will be communicating with
7263 */
7364 public A2AClient (AgentCard agentCard ) {
74- checkNotNullParam ("agentCard" , agentCard );
65+ Assert . checkNotNullParam ("agentCard" , agentCard );
7566 this .agentCard = agentCard ;
7667 this .agentUrl = agentCard .url ();
7768 this .httpClient = new JdkA2AHttpClient ();
@@ -83,7 +74,7 @@ public A2AClient(AgentCard agentCard) {
8374 * @param agentUrl the URL for the A2A server this client will be communicating with
8475 */
8576 public A2AClient (String agentUrl ) {
86- checkNotNullParam ("agentUrl" , agentUrl );
77+ Assert . checkNotNullParam ("agentUrl" , agentUrl );
8778 this .agentUrl = agentUrl ;
8879 this .httpClient = new JdkA2AHttpClient ();
8980 }
@@ -158,8 +149,8 @@ public SendMessageResponse sendMessage(MessageSendParams messageSendParams) thro
158149 */
159150 public SendMessageResponse sendMessage (String requestId , MessageSendParams messageSendParams ) throws A2AServerException {
160151 SendMessageRequest .Builder sendMessageRequestBuilder = new SendMessageRequest .Builder ()
161- .jsonrpc (JSONRPC_VERSION )
162- .method (SEND_MESSAGE_METHOD )
152+ .jsonrpc (JSONRPCMessage . JSONRPC_VERSION )
153+ .method (SendMessageRequest . SEND_MESSAGE_METHOD )
163154 .params (messageSendParams );
164155
165156 if (requestId != null ) {
@@ -210,8 +201,8 @@ public GetTaskResponse getTask(TaskQueryParams taskQueryParams) throws A2AServer
210201 */
211202 public GetTaskResponse getTask (String requestId , TaskQueryParams taskQueryParams ) throws A2AServerException {
212203 GetTaskRequest .Builder getTaskRequestBuilder = new GetTaskRequest .Builder ()
213- .jsonrpc (JSONRPC_VERSION )
214- .method (GET_TASK_METHOD )
204+ .jsonrpc (JSONRPCMessage . JSONRPC_VERSION )
205+ .method (GetTaskRequest . GET_TASK_METHOD )
215206 .params (taskQueryParams );
216207
217208 if (requestId != null ) {
@@ -260,8 +251,8 @@ public CancelTaskResponse cancelTask(TaskIdParams taskIdParams) throws A2AServer
260251 */
261252 public CancelTaskResponse cancelTask (String requestId , TaskIdParams taskIdParams ) throws A2AServerException {
262253 CancelTaskRequest .Builder cancelTaskRequestBuilder = new CancelTaskRequest .Builder ()
263- .jsonrpc (JSONRPC_VERSION )
264- .method (CANCEL_TASK_METHOD )
254+ .jsonrpc (JSONRPCMessage . JSONRPC_VERSION )
255+ .method (CancelTaskRequest . CANCEL_TASK_METHOD )
265256 .params (taskIdParams );
266257
267258 if (requestId != null ) {
@@ -310,8 +301,8 @@ public GetTaskPushNotificationConfigResponse getTaskPushNotificationConfig(TaskI
310301 */
311302 public GetTaskPushNotificationConfigResponse getTaskPushNotificationConfig (String requestId , TaskIdParams taskIdParams ) throws A2AServerException {
312303 GetTaskPushNotificationConfigRequest .Builder getTaskPushNotificationRequestBuilder = new GetTaskPushNotificationConfigRequest .Builder ()
313- .jsonrpc (JSONRPC_VERSION )
314- .method (GET_TASK_PUSH_NOTIFICATION_CONFIG_METHOD )
304+ .jsonrpc (JSONRPCMessage . JSONRPC_VERSION )
305+ .method (GetTaskPushNotificationConfigRequest . GET_TASK_PUSH_NOTIFICATION_CONFIG_METHOD )
315306 .params (taskIdParams );
316307
317308 if (requestId != null ) {
@@ -353,8 +344,8 @@ public SetTaskPushNotificationConfigResponse setTaskPushNotificationConfig(Strin
353344 public SetTaskPushNotificationConfigResponse setTaskPushNotificationConfig (String requestId , String taskId ,
354345 PushNotificationConfig pushNotificationConfig ) throws A2AServerException {
355346 SetTaskPushNotificationConfigRequest .Builder setTaskPushNotificationRequestBuilder = new SetTaskPushNotificationConfigRequest .Builder ()
356- .jsonrpc (JSONRPC_VERSION )
357- .method (SET_TASK_PUSH_NOTIFICATION_CONFIG_METHOD )
347+ .jsonrpc (JSONRPCMessage . JSONRPC_VERSION )
348+ .method (SetTaskPushNotificationConfigRequest . SET_TASK_PUSH_NOTIFICATION_CONFIG_METHOD )
358349 .params (new TaskPushNotificationConfig (taskId , pushNotificationConfig ));
359350
360351 if (requestId != null ) {
@@ -397,14 +388,14 @@ public void sendStreamingMessage(MessageSendParams messageSendParams, Consumer<S
397388 */
398389 public void sendStreamingMessage (String requestId , MessageSendParams messageSendParams , Consumer <StreamingEventKind > eventHandler ,
399390 Consumer <JSONRPCError > errorHandler , Runnable failureHandler ) throws A2AServerException {
400- checkNotNullParam ("messageSendParams" , messageSendParams );
401- checkNotNullParam ("eventHandler" , eventHandler );
402- checkNotNullParam ("errorHandler" , errorHandler );
403- checkNotNullParam ("failureHandler" , failureHandler );
391+ Assert . checkNotNullParam ("messageSendParams" , messageSendParams );
392+ Assert . checkNotNullParam ("eventHandler" , eventHandler );
393+ Assert . checkNotNullParam ("errorHandler" , errorHandler );
394+ Assert . checkNotNullParam ("failureHandler" , failureHandler );
404395
405396 SendStreamingMessageRequest .Builder sendStreamingMessageRequestBuilder = new SendStreamingMessageRequest .Builder ()
406- .jsonrpc (JSONRPC_VERSION )
407- .method (SEND_STREAMING_MESSAGE_METHOD )
397+ .jsonrpc (JSONRPCMessage . JSONRPC_VERSION )
398+ .method (SendStreamingMessageRequest . SEND_STREAMING_MESSAGE_METHOD )
408399 .params (messageSendParams );
409400
410401 if (requestId != null ) {
@@ -456,14 +447,14 @@ public void resubscribeToTask(TaskIdParams taskIdParams, Consumer<StreamingEvent
456447 */
457448 public void resubscribeToTask (String requestId , TaskIdParams taskIdParams , Consumer <StreamingEventKind > eventHandler ,
458449 Consumer <JSONRPCError > errorHandler , Runnable failureHandler ) throws A2AServerException {
459- checkNotNullParam ("taskIdParams" , taskIdParams );
460- checkNotNullParam ("eventHandler" , eventHandler );
461- checkNotNullParam ("errorHandler" , errorHandler );
462- checkNotNullParam ("failureHandler" , failureHandler );
450+ Assert . checkNotNullParam ("taskIdParams" , taskIdParams );
451+ Assert . checkNotNullParam ("eventHandler" , eventHandler );
452+ Assert . checkNotNullParam ("errorHandler" , errorHandler );
453+ Assert . checkNotNullParam ("failureHandler" , failureHandler );
463454
464455 TaskResubscriptionRequest .Builder taskResubscriptionRequestBuilder = new TaskResubscriptionRequest .Builder ()
465- .jsonrpc (JSONRPC_VERSION )
466- .method (SEND_TASK_RESUBSCRIPTION_METHOD )
456+ .jsonrpc (JSONRPCMessage . JSONRPC_VERSION )
457+ .method (TaskResubscriptionRequest . SEND_TASK_RESUBSCRIPTION_METHOD )
467458 .params (taskIdParams );
468459
469460 if (requestId != null ) {
@@ -502,13 +493,13 @@ private A2AHttpClient.PostBuilder createPostBuilder(Object value) throws JsonPro
502493 return httpClient .createPost ()
503494 .url (agentUrl )
504495 .addHeader ("Content-Type" , "application/json" )
505- .body (OBJECT_MAPPER .writeValueAsString (value ));
496+ .body (Utils . OBJECT_MAPPER .writeValueAsString (value ));
506497
507498 }
508499
509500 private <T extends JSONRPCResponse > T unmarshalResponse (String response , TypeReference <T > typeReference )
510501 throws A2AServerException , JsonProcessingException {
511- T value = unmarshalFrom (response , typeReference );
502+ T value = Utils . unmarshalFrom (response , typeReference );
512503 JSONRPCError error = value .getError ();
513504 if (error != null ) {
514505 throw new A2AServerException (error .getMessage () + (error .getData () != null ? ": " + error .getData () : "" ));
0 commit comments