30
30
31
31
import static io .a2a .util .Assert .checkNotNullParam ;
32
32
33
+ import org .jspecify .annotations .NonNull ;
34
+ import org .jspecify .annotations .Nullable ;
35
+
33
36
public class Client extends AbstractClient {
34
37
35
38
private final ClientConfig clientConfig ;
36
39
private final ClientTransport clientTransport ;
37
40
private AgentCard agentCard ;
38
41
39
42
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 ) {
41
44
super (consumers , streamingErrorHandler );
42
45
checkNotNullParam ("agentCard" , agentCard );
43
46
@@ -51,21 +54,21 @@ public static ClientBuilder builder(AgentCard agentCard) {
51
54
}
52
55
53
56
@ Override
54
- public void sendMessage (Message request , ClientCallContext context ) throws A2AClientException {
57
+ public void sendMessage (Message request , @ Nullable ClientCallContext context ) throws A2AClientException {
55
58
MessageSendParams messageSendParams = getMessageSendParams (request , clientConfig );
56
59
sendMessage (messageSendParams , null , null , context );
57
60
}
58
61
59
62
@ Override
60
63
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 {
62
65
MessageSendParams messageSendParams = getMessageSendParams (request , clientConfig );
63
66
sendMessage (messageSendParams , consumers , streamingErrorHandler , context );
64
67
}
65
68
66
69
@ Override
67
70
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 {
69
72
MessageSendConfiguration messageSendConfiguration = createMessageSendConfiguration (pushNotificationConfiguration );
70
73
71
74
MessageSendParams messageSendParams = new MessageSendParams .Builder ()
@@ -78,52 +81,52 @@ public void sendMessage(Message request, PushNotificationConfig pushNotification
78
81
}
79
82
80
83
@ Override
81
- public Task getTask (TaskQueryParams request , ClientCallContext context ) throws A2AClientException {
84
+ public Task getTask (TaskQueryParams request , @ Nullable ClientCallContext context ) throws A2AClientException {
82
85
return clientTransport .getTask (request , context );
83
86
}
84
87
85
88
@ Override
86
- public Task cancelTask (TaskIdParams request , ClientCallContext context ) throws A2AClientException {
89
+ public Task cancelTask (TaskIdParams request , @ Nullable ClientCallContext context ) throws A2AClientException {
87
90
return clientTransport .cancelTask (request , context );
88
91
}
89
92
90
93
@ Override
91
94
public TaskPushNotificationConfig setTaskPushNotificationConfiguration (
92
- TaskPushNotificationConfig request , ClientCallContext context ) throws A2AClientException {
95
+ TaskPushNotificationConfig request , @ Nullable ClientCallContext context ) throws A2AClientException {
93
96
return clientTransport .setTaskPushNotificationConfiguration (request , context );
94
97
}
95
98
96
99
@ Override
97
100
public TaskPushNotificationConfig getTaskPushNotificationConfiguration (
98
- GetTaskPushNotificationConfigParams request , ClientCallContext context ) throws A2AClientException {
101
+ GetTaskPushNotificationConfigParams request , @ Nullable ClientCallContext context ) throws A2AClientException {
99
102
return clientTransport .getTaskPushNotificationConfiguration (request , context );
100
103
}
101
104
102
105
@ Override
103
106
public List <TaskPushNotificationConfig > listTaskPushNotificationConfigurations (
104
- ListTaskPushNotificationConfigParams request , ClientCallContext context ) throws A2AClientException {
107
+ ListTaskPushNotificationConfigParams request , @ Nullable ClientCallContext context ) throws A2AClientException {
105
108
return clientTransport .listTaskPushNotificationConfigurations (request , context );
106
109
}
107
110
108
111
@ Override
109
112
public void deleteTaskPushNotificationConfigurations (
110
- DeleteTaskPushNotificationConfigParams request , ClientCallContext context ) throws A2AClientException {
113
+ DeleteTaskPushNotificationConfigParams request , @ Nullable ClientCallContext context ) throws A2AClientException {
111
114
clientTransport .deleteTaskPushNotificationConfigurations (request , context );
112
115
}
113
116
114
117
@ Override
115
- public void resubscribe (TaskIdParams request , ClientCallContext context ) throws A2AClientException {
118
+ public void resubscribe (TaskIdParams request , @ Nullable ClientCallContext context ) throws A2AClientException {
116
119
resubscribeToTask (request , null , null , context );
117
120
}
118
121
119
122
@ 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 {
122
125
resubscribeToTask (request , consumers , streamingErrorHandler , context );
123
126
}
124
127
125
128
@ Override
126
- public AgentCard getAgentCard (ClientCallContext context ) throws A2AClientException {
129
+ public AgentCard getAgentCard (@ Nullable ClientCallContext context ) throws A2AClientException {
127
130
agentCard = clientTransport .getAgentCard (context );
128
131
return agentCard ;
129
132
}
@@ -150,7 +153,7 @@ private ClientEvent getClientEvent(StreamingEventKind event, ClientTaskManager t
150
153
}
151
154
}
152
155
153
- private MessageSendConfiguration createMessageSendConfiguration (PushNotificationConfig pushNotificationConfig ) {
156
+ private MessageSendConfiguration createMessageSendConfiguration (@ Nullable PushNotificationConfig pushNotificationConfig ) {
154
157
return new MessageSendConfiguration .Builder ()
155
158
.acceptedOutputModes (clientConfig .getAcceptedOutputModes ())
156
159
.blocking (!clientConfig .isPolling ())
@@ -159,8 +162,8 @@ private MessageSendConfiguration createMessageSendConfiguration(PushNotification
159
162
.build ();
160
163
}
161
164
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 {
164
167
if (! clientConfig .isStreaming () || ! agentCard .capabilities ().streaming ()) {
165
168
EventKind eventKind = clientTransport .sendMessage (messageSendParams , context );
166
169
ClientEvent clientEvent ;
@@ -186,8 +189,8 @@ private void sendMessage(MessageSendParams messageSendParams, List<BiConsumer<Cl
186
189
}
187
190
}
188
191
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 {
191
194
if (! clientConfig .isStreaming () || ! agentCard .capabilities ().streaming ()) {
192
195
throw new A2AClientException ("Client and/or server does not support resubscription" );
193
196
}
@@ -204,7 +207,7 @@ private void resubscribeToTask(TaskIdParams request, List<BiConsumer<ClientEvent
204
207
clientTransport .resubscribe (request , eventHandler , overriddenErrorHandler , context );
205
208
}
206
209
207
- private Consumer <Throwable > getOverriddenErrorHandler (Consumer <Throwable > errorHandler ) {
210
+ private @ NonNull Consumer <Throwable > getOverriddenErrorHandler (@ Nullable Consumer <Throwable > errorHandler ) {
208
211
return e -> {
209
212
if (errorHandler != null ) {
210
213
errorHandler .accept (e );
@@ -216,7 +219,7 @@ private Consumer<Throwable> getOverriddenErrorHandler(Consumer<Throwable> errorH
216
219
};
217
220
}
218
221
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 ) {
220
223
if (consumers != null ) {
221
224
// use specified consumers
222
225
for (BiConsumer <ClientEvent , AgentCard > consumer : consumers ) {
0 commit comments