Skip to content

Commit f79e392

Browse files
committed
chore: Re-organize sub-modules to extract the client part from the core to ease client extensibility with new implementation
1 parent e97df4c commit f79e392

File tree

131 files changed

+269
-535
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+269
-535
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ The A2A Java SDK provides a Java server implementation of the [Agent2Agent (A2A)
4242
```xml
4343
<dependency>
4444
<groupId>io.a2a.sdk</groupId>
45-
<artifactId>a2a-java-sdk-core</artifactId>
45+
<artifactId>a2a-java-sdk-client</artifactId>
4646
<version>0.2.3</version>
4747
</dependency>
4848
```

core/pom.xml renamed to client/pom.xml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,32 @@
99
<artifactId>a2a-java-sdk-parent</artifactId>
1010
<version>0.2.4-SNAPSHOT</version>
1111
</parent>
12-
<artifactId>a2a-java-sdk-core</artifactId>
12+
<artifactId>a2a-java-sdk-client</artifactId>
1313

1414
<packaging>jar</packaging>
1515

16-
<name>Java SDK A2A Core</name>
17-
<description>Java SDK for the Agent2Agent Protocol (A2A) - Core</description>
16+
<name>Java SDK A2A Client</name>
17+
<description>Java SDK for the Agent2Agent Protocol (A2A) - Client</description>
1818

1919
<dependencies>
2020
<dependency>
21-
<groupId>com.fasterxml.jackson.core</groupId>
22-
<artifactId>jackson-databind</artifactId>
21+
<groupId>io.a2a.sdk</groupId>
22+
<artifactId>a2a-java-sdk-common</artifactId>
23+
<version>${project.version}</version>
2324
</dependency>
25+
2426
<dependency>
25-
<groupId>com.fasterxml.jackson.datatype</groupId>
26-
<artifactId>jackson-datatype-jsr310</artifactId>
27+
<groupId>io.a2a.sdk</groupId>
28+
<artifactId>a2a-java-sdk-model</artifactId>
29+
<version>${project.version}</version>
2730
</dependency>
31+
2832
<dependency>
2933
<groupId>org.junit.jupiter</groupId>
3034
<artifactId>junit-jupiter-api</artifactId>
3135
<scope>test</scope>
3236
</dependency>
33-
<dependency>
34-
<groupId>org.mockito</groupId>
35-
<artifactId>mockito-core</artifactId>
36-
<scope>test</scope>
37-
</dependency>
37+
3838
<dependency>
3939
<groupId>org.mock-server</groupId>
4040
<artifactId>mockserver-netty</artifactId>
Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,19 @@
1-
package io.a2a.spec;
1+
package io.a2a;
22

33
import java.util.Collections;
44
import java.util.Map;
55

66
import io.a2a.client.A2ACardResolver;
77
import io.a2a.http.A2AHttpClient;
88
import io.a2a.http.JdkA2AHttpClient;
9+
import io.a2a.spec.*;
910

1011

1112
/**
1213
* Constants and utility methods related to the A2A protocol.
1314
*/
1415
public class A2A {
1516

16-
public static final String CANCEL_TASK_METHOD = "tasks/cancel";
17-
public static final String GET_TASK_PUSH_NOTIFICATION_CONFIG_METHOD = "tasks/pushNotificationConfig/get";
18-
public static final String GET_TASK_METHOD = "tasks/get";
19-
public static final String SET_TASK_PUSH_NOTIFICATION_CONFIG_METHOD = "tasks/pushNotificationConfig/set";
20-
public static final String SEND_TASK_RESUBSCRIPTION_METHOD = "tasks/resubscribe";
21-
public static final String SEND_STREAMING_MESSAGE_METHOD = "message/stream";
22-
public static final String SEND_MESSAGE_METHOD = "message/send";
23-
24-
public static final String JSONRPC_VERSION = "2.0";
25-
26-
2717
/**
2818
* Convert the given text to a user message.
2919
*
@@ -133,16 +123,4 @@ public static AgentCard getAgentCard(A2AHttpClient httpClient, String agentUrl,
133123
A2ACardResolver resolver = new A2ACardResolver(httpClient, agentUrl, relativeCardPath, authHeaders);
134124
return resolver.getAgentCard();
135125
}
136-
137-
protected static boolean isValidMethodName(String methodName) {
138-
return methodName != null && (methodName.equals(CANCEL_TASK_METHOD)
139-
|| methodName.equals(GET_TASK_METHOD)
140-
|| methodName.equals(GET_TASK_PUSH_NOTIFICATION_CONFIG_METHOD)
141-
|| methodName.equals(SET_TASK_PUSH_NOTIFICATION_CONFIG_METHOD)
142-
|| methodName.equals(SEND_TASK_RESUBSCRIPTION_METHOD)
143-
|| methodName.equals(SEND_MESSAGE_METHOD)
144-
|| methodName.equals(SEND_STREAMING_MESSAGE_METHOD));
145-
146-
}
147-
148126
}

core/src/main/java/io/a2a/client/A2ACardResolver.java renamed to client/src/main/java/io/a2a/client/A2ACardResolver.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package io.a2a.client;
22

3-
import static io.a2a.util.Utils.unmarshalFrom;
4-
53
import java.io.IOException;
64
import java.util.Map;
75

@@ -12,6 +10,7 @@
1210
import io.a2a.spec.A2AClientError;
1311
import io.a2a.spec.A2AClientJSONError;
1412
import io.a2a.spec.AgentCard;
13+
import io.a2a.util.Utils;
1514

1615
public class A2ACardResolver {
1716
private final A2AHttpClient httpClient;
@@ -89,7 +88,7 @@ public AgentCard getAgentCard() throws A2AClientError, A2AClientJSONError {
8988
}
9089

9190
try {
92-
return unmarshalFrom(body, AGENT_CARD_TYPE_REFERENCE);
91+
return Utils.unmarshalFrom(body, AGENT_CARD_TYPE_REFERENCE);
9392
} catch (JsonProcessingException e) {
9493
throw new A2AClientJSONError("Could not unmarshal agent card response", e);
9594
}

core/src/main/java/io/a2a/client/A2AClient.java renamed to client/src/main/java/io/a2a/client/A2AClient.java

Lines changed: 30 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
11
package 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-
153
import java.io.IOException;
164
import java.util.Map;
175
import java.util.concurrent.CompletableFuture;
@@ -24,7 +12,7 @@
2412
import io.a2a.http.A2AHttpClient;
2513
import io.a2a.http.A2AHttpResponse;
2614
import io.a2a.http.JdkA2AHttpClient;
27-
import io.a2a.spec.A2A;
15+
import io.a2a.A2A;
2816
import io.a2a.spec.A2AClientError;
2917
import io.a2a.spec.A2AClientJSONError;
3018
import io.a2a.spec.A2AServerException;
@@ -36,6 +24,7 @@
3624
import io.a2a.spec.GetTaskRequest;
3725
import io.a2a.spec.GetTaskResponse;
3826
import io.a2a.spec.JSONRPCError;
27+
import io.a2a.spec.JSONRPCMessage;
3928
import io.a2a.spec.JSONRPCResponse;
4029
import io.a2a.spec.MessageSendParams;
4130
import io.a2a.spec.PushNotificationConfig;
@@ -49,6 +38,8 @@
4938
import io.a2a.spec.TaskPushNotificationConfig;
5039
import io.a2a.spec.TaskQueryParams;
5140
import 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() : ""));

core/src/main/java/io/a2a/client/sse/SSEEventListener.java renamed to client/src/main/java/io/a2a/client/sse/SSEEventListener.java

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)