Skip to content

Commit 2a881cb

Browse files
brasseldkabir
andauthored
chore: Re-organize sub-modules to extract the client part from core (#149)
# Description This PR is made for better organize the different sub-modules, essentially the core one by extracing the specification (the model) from the client, in a similar way as what as been done for the server part. The goal for this split is to make it easier to provide other client implementation in a near future. Although code as been spread across new modules, it does not impact the way it is used as the same packages as been kept. Therefore, it does not impact much the main readme - [X ] Follow the [`CONTRIBUTING` Guide](../CONTRIBUTING.md). - [ X] Make your Pull Request title in the <https://www.conventionalcommits.org/> specification. - Important Prefixes for [release-please](https://github.com/googleapis/release-please): - `fix:` which represents bug fixes, and correlates to a [SemVer](https://semver.org/) patch. - `feat:` represents a new feature, and correlates to a SemVer minor. - `feat!:`, or `fix!:`, `refactor!:`, etc., which represent a breaking change (indicated by the `!`) and will result in a SemVer major. - [ X] Ensure the tests pass - [ X] Appropriate READMEs were updated (if necessary) Fixes #<issue_number_goes_here> 🦕 --------- Co-authored-by: Kabir Khan <[email protected]>
1 parent be11861 commit 2a881cb

File tree

134 files changed

+254
-480
lines changed

Some content is hidden

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

134 files changed

+254
-480
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,20 @@ The A2A Java SDK provides a Java server implementation of the [Agent2Agent (A2A)
3434
- [Add a class that creates an A2A Agent Executor](#3-add-a-class-that-creates-an-a2a-agent-executor)
3535
- [Add an A2A Java SDK Server Maven dependency to your project](#4-add-an-a2a-java-sdk-server-maven-dependency-to-your-project)
3636

37-
### 1. Add the A2A Java SDK Core Maven dependency to your project
37+
### 1. Add the A2A Java SDK Maven dependencies to your project
3838

3939
> **Note**: The A2A Java SDK isn't available yet in Maven Central but will be soon. For now, be
4040
> sure to check out the latest tag (you can see the tags [here](https://github.com/a2aproject/a2a-java/tags)), build from the tag, and reference that version below. For example, if the latest tag is `0.2.3`, you can use the following dependency.
4141
4242
```xml
4343
<dependency>
4444
<groupId>io.a2a.sdk</groupId>
45-
<artifactId>a2a-java-sdk-core</artifactId>
45+
<artifactId>a2a-java-sdk-client</artifactId>
46+
<version>0.2.3</version>
47+
</dependency>
48+
<dependency>
49+
<groupId>io.a2a.sdk</groupId>
50+
<artifactId>a2a-java-sdk-server-common</artifactId>
4651
<version>0.2.3</version>
4752
</dependency>
4853
```

client/pom.xml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0"?>
2+
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
3+
xmlns="http://maven.apache.org/POM/4.0.0"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>io.a2a.sdk</groupId>
9+
<artifactId>a2a-java-sdk-parent</artifactId>
10+
<version>0.2.4-SNAPSHOT</version>
11+
</parent>
12+
<artifactId>a2a-java-sdk-client</artifactId>
13+
14+
<packaging>jar</packaging>
15+
16+
<name>Java SDK A2A Client</name>
17+
<description>Java SDK for the Agent2Agent Protocol (A2A) - Client</description>
18+
19+
<dependencies>
20+
<dependency>
21+
<groupId>${project.groupId}</groupId>
22+
<artifactId>a2a-java-sdk-common</artifactId>
23+
<version>${project.version}</version>
24+
</dependency>
25+
26+
<dependency>
27+
<groupId>${project.groupId}</groupId>
28+
<artifactId>a2a-java-sdk-spec</artifactId>
29+
<version>${project.version}</version>
30+
</dependency>
31+
32+
<dependency>
33+
<groupId>org.junit.jupiter</groupId>
34+
<artifactId>junit-jupiter-api</artifactId>
35+
<scope>test</scope>
36+
</dependency>
37+
38+
<dependency>
39+
<groupId>org.mock-server</groupId>
40+
<artifactId>mockserver-netty</artifactId>
41+
<scope>test</scope>
42+
</dependency>
43+
</dependencies>
44+
45+
</project>
Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,23 @@
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.A2AClientError;
10+
import io.a2a.spec.A2AClientJSONError;
11+
import io.a2a.spec.AgentCard;
12+
import io.a2a.spec.Message;
13+
import io.a2a.spec.TextPart;
914

1015

1116
/**
1217
* Constants and utility methods related to the A2A protocol.
1318
*/
1419
public class A2A {
1520

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-
2721
/**
2822
* Convert the given text to a user message.
2923
*
@@ -133,16 +127,4 @@ public static AgentCard getAgentCard(A2AHttpClient httpClient, String agentUrl,
133127
A2ACardResolver resolver = new A2ACardResolver(httpClient, agentUrl, relativeCardPath, authHeaders);
134128
return resolver.getAgentCard();
135129
}
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-
148130
}

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

File renamed without changes.

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

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
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;
113
import static io.a2a.util.Assert.checkNotNullParam;
12-
import static io.a2a.util.Utils.OBJECT_MAPPER;
13-
import static io.a2a.util.Utils.unmarshalFrom;
144

155
import java.io.IOException;
166
import java.util.Map;
@@ -24,7 +14,7 @@
2414
import io.a2a.http.A2AHttpClient;
2515
import io.a2a.http.A2AHttpResponse;
2616
import io.a2a.http.JdkA2AHttpClient;
27-
import io.a2a.spec.A2A;
17+
import io.a2a.A2A;
2818
import io.a2a.spec.A2AClientError;
2919
import io.a2a.spec.A2AClientJSONError;
3020
import io.a2a.spec.A2AServerException;
@@ -36,6 +26,7 @@
3626
import io.a2a.spec.GetTaskRequest;
3727
import io.a2a.spec.GetTaskResponse;
3828
import io.a2a.spec.JSONRPCError;
29+
import io.a2a.spec.JSONRPCMessage;
3930
import io.a2a.spec.JSONRPCResponse;
4031
import io.a2a.spec.MessageSendParams;
4132
import io.a2a.spec.PushNotificationConfig;
@@ -49,6 +40,7 @@
4940
import io.a2a.spec.TaskPushNotificationConfig;
5041
import io.a2a.spec.TaskQueryParams;
5142
import io.a2a.spec.TaskResubscriptionRequest;
43+
import io.a2a.util.Utils;
5244

5345
/**
5446
* An A2A client.
@@ -158,8 +150,8 @@ public SendMessageResponse sendMessage(MessageSendParams messageSendParams) thro
158150
*/
159151
public SendMessageResponse sendMessage(String requestId, MessageSendParams messageSendParams) throws A2AServerException {
160152
SendMessageRequest.Builder sendMessageRequestBuilder = new SendMessageRequest.Builder()
161-
.jsonrpc(JSONRPC_VERSION)
162-
.method(SEND_MESSAGE_METHOD)
153+
.jsonrpc(JSONRPCMessage.JSONRPC_VERSION)
154+
.method(SendMessageRequest.METHOD)
163155
.params(messageSendParams);
164156

165157
if (requestId != null) {
@@ -210,8 +202,8 @@ public GetTaskResponse getTask(TaskQueryParams taskQueryParams) throws A2AServer
210202
*/
211203
public GetTaskResponse getTask(String requestId, TaskQueryParams taskQueryParams) throws A2AServerException {
212204
GetTaskRequest.Builder getTaskRequestBuilder = new GetTaskRequest.Builder()
213-
.jsonrpc(JSONRPC_VERSION)
214-
.method(GET_TASK_METHOD)
205+
.jsonrpc(JSONRPCMessage.JSONRPC_VERSION)
206+
.method(GetTaskRequest.METHOD)
215207
.params(taskQueryParams);
216208

217209
if (requestId != null) {
@@ -260,8 +252,8 @@ public CancelTaskResponse cancelTask(TaskIdParams taskIdParams) throws A2AServer
260252
*/
261253
public CancelTaskResponse cancelTask(String requestId, TaskIdParams taskIdParams) throws A2AServerException {
262254
CancelTaskRequest.Builder cancelTaskRequestBuilder = new CancelTaskRequest.Builder()
263-
.jsonrpc(JSONRPC_VERSION)
264-
.method(CANCEL_TASK_METHOD)
255+
.jsonrpc(JSONRPCMessage.JSONRPC_VERSION)
256+
.method(CancelTaskRequest.METHOD)
265257
.params(taskIdParams);
266258

267259
if (requestId != null) {
@@ -310,8 +302,8 @@ public GetTaskPushNotificationConfigResponse getTaskPushNotificationConfig(TaskI
310302
*/
311303
public GetTaskPushNotificationConfigResponse getTaskPushNotificationConfig(String requestId, TaskIdParams taskIdParams) throws A2AServerException {
312304
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)
315307
.params(taskIdParams);
316308

317309
if (requestId != null) {
@@ -353,8 +345,8 @@ public SetTaskPushNotificationConfigResponse setTaskPushNotificationConfig(Strin
353345
public SetTaskPushNotificationConfigResponse setTaskPushNotificationConfig(String requestId, String taskId,
354346
PushNotificationConfig pushNotificationConfig) throws A2AServerException {
355347
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)
358350
.params(new TaskPushNotificationConfig(taskId, pushNotificationConfig));
359351

360352
if (requestId != null) {
@@ -403,8 +395,8 @@ public void sendStreamingMessage(String requestId, MessageSendParams messageSend
403395
checkNotNullParam("failureHandler", failureHandler);
404396

405397
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)
408400
.params(messageSendParams);
409401

410402
if (requestId != null) {
@@ -462,8 +454,8 @@ public void resubscribeToTask(String requestId, TaskIdParams taskIdParams, Consu
462454
checkNotNullParam("failureHandler", failureHandler);
463455

464456
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)
467459
.params(taskIdParams);
468460

469461
if (requestId != null) {
@@ -502,13 +494,13 @@ private A2AHttpClient.PostBuilder createPostBuilder(Object value) throws JsonPro
502494
return httpClient.createPost()
503495
.url(agentUrl)
504496
.addHeader("Content-Type", "application/json")
505-
.body(OBJECT_MAPPER.writeValueAsString(value));
497+
.body(Utils.OBJECT_MAPPER.writeValueAsString(value));
506498

507499
}
508500

509501
private <T extends JSONRPCResponse> T unmarshalResponse(String response, TypeReference<T> typeReference)
510502
throws A2AServerException, JsonProcessingException {
511-
T value = unmarshalFrom(response, typeReference);
503+
T value = Utils.unmarshalFrom(response, typeReference);
512504
JSONRPCError error = value.getError();
513505
if (error != null) {
514506
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.

client/src/main/resources/META-INF/beans.xml

Whitespace-only changes.

0 commit comments

Comments
 (0)