3030
3131import static io .a2a .util .Assert .checkNotNullParam ;
3232
33+ import org .jspecify .annotations .NonNull ;
34+ import org .jspecify .annotations .Nullable ;
35+
3336public class Client extends AbstractClient {
3437
3538 private final ClientConfig clientConfig ;
3639 private final ClientTransport clientTransport ;
3740 private AgentCard agentCard ;
3841
3942 Client (AgentCard agentCard , ClientConfig clientConfig , ClientTransport clientTransport ,
40- List <BiConsumer <ClientEvent , AgentCard >> consumers , Consumer <Throwable > streamingErrorHandler ) {
43+ List <BiConsumer <ClientEvent , AgentCard >> consumers , @ Nullable Consumer <Throwable > streamingErrorHandler ) {
4144 super (consumers , streamingErrorHandler );
4245 checkNotNullParam ("agentCard" , agentCard );
4346
@@ -51,21 +54,21 @@ public static ClientBuilder builder(AgentCard agentCard) {
5154 }
5255
5356 @ Override
54- public void sendMessage (Message request , ClientCallContext context ) throws A2AClientException {
57+ public void sendMessage (Message request , @ Nullable ClientCallContext context ) throws A2AClientException {
5558 MessageSendParams messageSendParams = getMessageSendParams (request , clientConfig );
5659 sendMessage (messageSendParams , null , null , context );
5760 }
5861
5962 @ Override
6063 public void sendMessage (Message request , List <BiConsumer <ClientEvent , AgentCard >> consumers ,
61- Consumer <Throwable > streamingErrorHandler , ClientCallContext context ) throws A2AClientException {
64+ Consumer <Throwable > streamingErrorHandler , @ Nullable ClientCallContext context ) throws A2AClientException {
6265 MessageSendParams messageSendParams = getMessageSendParams (request , clientConfig );
6366 sendMessage (messageSendParams , consumers , streamingErrorHandler , context );
6467 }
6568
6669 @ Override
6770 public void sendMessage (Message request , PushNotificationConfig pushNotificationConfiguration ,
68- Map <String , Object > metatadata , ClientCallContext context ) throws A2AClientException {
71+ Map <String , Object > metatadata , @ Nullable ClientCallContext context ) throws A2AClientException {
6972 MessageSendConfiguration messageSendConfiguration = createMessageSendConfiguration (pushNotificationConfiguration );
7073
7174 MessageSendParams messageSendParams = new MessageSendParams .Builder ()
@@ -78,52 +81,52 @@ public void sendMessage(Message request, PushNotificationConfig pushNotification
7881 }
7982
8083 @ Override
81- public Task getTask (TaskQueryParams request , ClientCallContext context ) throws A2AClientException {
84+ public Task getTask (TaskQueryParams request , @ Nullable ClientCallContext context ) throws A2AClientException {
8285 return clientTransport .getTask (request , context );
8386 }
8487
8588 @ Override
86- public Task cancelTask (TaskIdParams request , ClientCallContext context ) throws A2AClientException {
89+ public Task cancelTask (TaskIdParams request , @ Nullable ClientCallContext context ) throws A2AClientException {
8790 return clientTransport .cancelTask (request , context );
8891 }
8992
9093 @ Override
9194 public TaskPushNotificationConfig setTaskPushNotificationConfiguration (
92- TaskPushNotificationConfig request , ClientCallContext context ) throws A2AClientException {
95+ TaskPushNotificationConfig request , @ Nullable ClientCallContext context ) throws A2AClientException {
9396 return clientTransport .setTaskPushNotificationConfiguration (request , context );
9497 }
9598
9699 @ Override
97100 public TaskPushNotificationConfig getTaskPushNotificationConfiguration (
98- GetTaskPushNotificationConfigParams request , ClientCallContext context ) throws A2AClientException {
101+ GetTaskPushNotificationConfigParams request , @ Nullable ClientCallContext context ) throws A2AClientException {
99102 return clientTransport .getTaskPushNotificationConfiguration (request , context );
100103 }
101104
102105 @ Override
103106 public List <TaskPushNotificationConfig > listTaskPushNotificationConfigurations (
104- ListTaskPushNotificationConfigParams request , ClientCallContext context ) throws A2AClientException {
107+ ListTaskPushNotificationConfigParams request , @ Nullable ClientCallContext context ) throws A2AClientException {
105108 return clientTransport .listTaskPushNotificationConfigurations (request , context );
106109 }
107110
108111 @ Override
109112 public void deleteTaskPushNotificationConfigurations (
110- DeleteTaskPushNotificationConfigParams request , ClientCallContext context ) throws A2AClientException {
113+ DeleteTaskPushNotificationConfigParams request , @ Nullable ClientCallContext context ) throws A2AClientException {
111114 clientTransport .deleteTaskPushNotificationConfigurations (request , context );
112115 }
113116
114117 @ Override
115- public void resubscribe (TaskIdParams request , ClientCallContext context ) throws A2AClientException {
118+ public void resubscribe (TaskIdParams request , @ Nullable ClientCallContext context ) throws A2AClientException {
116119 resubscribeToTask (request , null , null , context );
117120 }
118121
119122 @ Override
120- public void resubscribe (TaskIdParams request , List <BiConsumer <ClientEvent , AgentCard >> consumers ,
121- Consumer <Throwable > streamingErrorHandler , ClientCallContext context ) throws A2AClientException {
123+ public void resubscribe (TaskIdParams request , @ Nullable List <BiConsumer <ClientEvent , AgentCard >> consumers ,
124+ @ Nullable Consumer <Throwable > streamingErrorHandler , @ Nullable ClientCallContext context ) throws A2AClientException {
122125 resubscribeToTask (request , consumers , streamingErrorHandler , context );
123126 }
124127
125128 @ Override
126- public AgentCard getAgentCard (ClientCallContext context ) throws A2AClientException {
129+ public AgentCard getAgentCard (@ Nullable ClientCallContext context ) throws A2AClientException {
127130 agentCard = clientTransport .getAgentCard (context );
128131 return agentCard ;
129132 }
@@ -150,7 +153,7 @@ private ClientEvent getClientEvent(StreamingEventKind event, ClientTaskManager t
150153 }
151154 }
152155
153- private MessageSendConfiguration createMessageSendConfiguration (PushNotificationConfig pushNotificationConfig ) {
156+ private MessageSendConfiguration createMessageSendConfiguration (@ Nullable PushNotificationConfig pushNotificationConfig ) {
154157 return new MessageSendConfiguration .Builder ()
155158 .acceptedOutputModes (clientConfig .getAcceptedOutputModes ())
156159 .blocking (!clientConfig .isPolling ())
@@ -159,8 +162,8 @@ private MessageSendConfiguration createMessageSendConfiguration(PushNotification
159162 .build ();
160163 }
161164
162- private void sendMessage (MessageSendParams messageSendParams , List <BiConsumer <ClientEvent , AgentCard >> consumers ,
163- Consumer <Throwable > errorHandler , ClientCallContext context ) throws A2AClientException {
165+ private void sendMessage (MessageSendParams messageSendParams , @ Nullable List <BiConsumer <ClientEvent , AgentCard >> consumers ,
166+ @ Nullable Consumer <Throwable > errorHandler , @ Nullable ClientCallContext context ) throws A2AClientException {
164167 if (! clientConfig .isStreaming () || ! agentCard .capabilities ().streaming ()) {
165168 EventKind eventKind = clientTransport .sendMessage (messageSendParams , context );
166169 ClientEvent clientEvent ;
@@ -186,8 +189,8 @@ private void sendMessage(MessageSendParams messageSendParams, List<BiConsumer<Cl
186189 }
187190 }
188191
189- private void resubscribeToTask (TaskIdParams request , List <BiConsumer <ClientEvent , AgentCard >> consumers ,
190- Consumer <Throwable > errorHandler , ClientCallContext context ) throws A2AClientException {
192+ private void resubscribeToTask (TaskIdParams request , @ Nullable List <BiConsumer <ClientEvent , AgentCard >> consumers ,
193+ @ Nullable Consumer <Throwable > errorHandler , @ Nullable ClientCallContext context ) throws A2AClientException {
191194 if (! clientConfig .isStreaming () || ! agentCard .capabilities ().streaming ()) {
192195 throw new A2AClientException ("Client and/or server does not support resubscription" );
193196 }
@@ -204,7 +207,7 @@ private void resubscribeToTask(TaskIdParams request, List<BiConsumer<ClientEvent
204207 clientTransport .resubscribe (request , eventHandler , overriddenErrorHandler , context );
205208 }
206209
207- private Consumer <Throwable > getOverriddenErrorHandler (Consumer <Throwable > errorHandler ) {
210+ private @ NonNull Consumer <Throwable > getOverriddenErrorHandler (@ Nullable Consumer <Throwable > errorHandler ) {
208211 return e -> {
209212 if (errorHandler != null ) {
210213 errorHandler .accept (e );
@@ -216,7 +219,7 @@ private Consumer<Throwable> getOverriddenErrorHandler(Consumer<Throwable> errorH
216219 };
217220 }
218221
219- private void consume (ClientEvent clientEvent , AgentCard agentCard , List <BiConsumer <ClientEvent , AgentCard >> consumers ) {
222+ private void consume (ClientEvent clientEvent , AgentCard agentCard , @ Nullable List <BiConsumer <ClientEvent , AgentCard >> consumers ) {
220223 if (consumers != null ) {
221224 // use specified consumers
222225 for (BiConsumer <ClientEvent , AgentCard > consumer : consumers ) {
0 commit comments