feat: Implement the spec updates for v0.3.0 (#212) · anFatum/a2a-java@198504b · GitHub
Skip to content

Commit 198504b

Browse files
authored
feat: Implement the spec updates for v0.3.0 (a2aproject#212)
# Description This PR introduces some new spec classes and updates some existing ones based off the updates in the [v0.3.0 spec](https://github.com/a2aproject/A2A/releases/tag/v0.3.0). Note that the TCK job will fail until the v0.3.0 TCK is available. - [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 a2aproject#209 🦕
1 parent 77b0c7b commit 198504b

109 files changed

Lines changed: 4555 additions & 485 deletions

File tree

Some content is hidden

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

.github/workflows/run-tck.yml

Lines changed: 2 additions & 2 deletions

client/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>io.github.a2asdk</groupId>
99
<artifactId>a2a-java-sdk-parent</artifactId>
10-
<version>0.2.6.Beta1-SNAPSHOT</version>
10+
<version>0.3.0.Beta1-SNAPSHOT</version>
1111
</parent>
1212
<artifactId>a2a-java-sdk-client</artifactId>
1313

client/src/main/java/io/a2a/A2A.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public static AgentCard getAgentCard(A2AHttpClient httpClient, String agentUrl)
101101
*
102102
* @param agentUrl the base URL for the agent whose agent card we want to retrieve
103103
* @param relativeCardPath optional path to the agent card endpoint relative to the base
104-
* agent URL, defaults to ".well-known/agent.json"
104+
* agent URL, defaults to ".well-known/agent-card.json"
105105
* @param authHeaders the HTTP authentication headers to use
106106
* @return the agent card
107107
* @throws A2AClientError If an HTTP error occurs fetching the card
@@ -117,7 +117,7 @@ public static AgentCard getAgentCard(String agentUrl, String relativeCardPath, M
117117
* @param httpClient the http client to use
118118
* @param agentUrl the base URL for the agent whose agent card we want to retrieve
119119
* @param relativeCardPath optional path to the agent card endpoint relative to the base
120-
* agent URL, defaults to ".well-known/agent.json"
120+
* agent URL, defaults to ".well-known/agent-card.json"
121121
* @param authHeaders the HTTP authentication headers to use
122122
* @return the agent card
123123
* @throws A2AClientError If an HTTP error occurs fetching the card

client/src/main/java/io/a2a/client/A2ACardResolver.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class A2ACardResolver {
2020
private final String url;
2121
private final Map<String, String> authHeaders;
2222

23-
private static final String DEFAULT_AGENT_CARD_PATH = "/.well-known/agent.json";
23+
private static final String DEFAULT_AGENT_CARD_PATH = "/.well-known/agent-card.json";
2424

2525
private static final TypeReference<AgentCard> AGENT_CARD_TYPE_REFERENCE = new TypeReference<>() {};
2626

@@ -37,7 +37,7 @@ public A2ACardResolver(A2AHttpClient httpClient, String baseUrl) throws A2AClien
3737
* @param httpClient the http client to use
3838
* @param baseUrl the base URL for the agent whose agent card we want to retrieve
3939
* @param agentCardPath optional path to the agent card endpoint relative to the base
40-
* agent URL, defaults to ".well-known/agent.json"
40+
* agent URL, defaults to ".well-known/agent-card.json"
4141
* @throws A2AClientError if the URL for the agent is invalid
4242
*/
4343
public A2ACardResolver(A2AHttpClient httpClient, String baseUrl, String agentCardPath) throws A2AClientError {
@@ -48,7 +48,7 @@ public A2ACardResolver(A2AHttpClient httpClient, String baseUrl, String agentCar
4848
* @param httpClient the http client to use
4949
* @param baseUrl the base URL for the agent whose agent card we want to retrieve
5050
* @param agentCardPath optional path to the agent card endpoint relative to the base
51-
* agent URL, defaults to ".well-known/agent.json"
51+
* agent URL, defaults to ".well-known/agent-card.json"
5252
* @param authHeaders the HTTP authentication headers to use. May be {@code null}
5353
* @throws A2AClientError if the URL for the agent is invalid
5454
*/

client/src/main/java/io/a2a/client/A2AClient.java

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import io.a2a.spec.DeleteTaskPushNotificationConfigParams;
2525
import io.a2a.spec.DeleteTaskPushNotificationConfigRequest;
2626
import io.a2a.spec.DeleteTaskPushNotificationConfigResponse;
27+
import io.a2a.spec.GetAuthenticatedExtendedCardRequest;
28+
import io.a2a.spec.GetAuthenticatedExtendedCardResponse;
2729
import io.a2a.spec.GetTaskPushNotificationConfigParams;
2830
import io.a2a.spec.GetTaskPushNotificationConfigRequest;
2931
import io.a2a.spec.GetTaskPushNotificationConfigResponse;
@@ -61,6 +63,7 @@ public class A2AClient {
6163
private static final TypeReference<SetTaskPushNotificationConfigResponse> SET_TASK_PUSH_NOTIFICATION_CONFIG_RESPONSE_REFERENCE = new TypeReference<>() {};
6264
private static final TypeReference<ListTaskPushNotificationConfigResponse> LIST_TASK_PUSH_NOTIFICATION_CONFIG_RESPONSE_REFERENCE = new TypeReference<>() {};
6365
private static final TypeReference<DeleteTaskPushNotificationConfigResponse> DELETE_TASK_PUSH_NOTIFICATION_CONFIG_RESPONSE_REFERENCE = new TypeReference<>() {};
66+
private static final TypeReference<GetAuthenticatedExtendedCardResponse> GET_AUTHENTICATED_EXTENDED_CARD_RESPONSE_REFERENCE = new TypeReference<>() {};
6467
private final A2AHttpClient httpClient;
6568
private final String agentUrl;
6669
private AgentCard agentCard;
@@ -632,8 +635,51 @@ public void resubscribeToTask(String requestId, TaskIdParams taskIdParams, Consu
632635
}
633636
}
634637

638+
/**
639+
* Retrieve the authenticated extended agent card.
640+
*
641+
* @param authHeaders the HTTP authentication headers to use
642+
* @return the response
643+
* @throws A2AServerException if retrieving the authenticated extended agent card fails for any reason
644+
*/
645+
public GetAuthenticatedExtendedCardResponse getAuthenticatedExtendedCard(Map<String, String> authHeaders) throws A2AServerException {
646+
return getAuthenticatedExtendedCard(null, authHeaders);
647+
}
648+
649+
/**
650+
* Retrieve the authenticated extended agent card.
651+
*
652+
* @param requestId the request ID to use
653+
* @param authHeaders the HTTP authentication headers to use
654+
* @return the response
655+
* @throws A2AServerException if retrieving the authenticated extended agent card fails for any reason
656+
*/
657+
public GetAuthenticatedExtendedCardResponse getAuthenticatedExtendedCard(String requestId,
658+
Map<String, String> authHeaders) throws A2AServerException {
659+
GetAuthenticatedExtendedCardRequest.Builder requestBuilder = new GetAuthenticatedExtendedCardRequest.Builder()
660+
.jsonrpc(JSONRPCMessage.JSONRPC_VERSION)
661+
.method(GetAuthenticatedExtendedCardRequest.METHOD);
662+
663+
if (requestId != null) {
664+
requestBuilder.id(requestId);
665+
}
666+
667+
GetAuthenticatedExtendedCardRequest request = requestBuilder.build();
668+
669+
try {
670+
String httpResponseBody = sendPostRequest(request, authHeaders);
671+
return unmarshalResponse(httpResponseBody, GET_AUTHENTICATED_EXTENDED_CARD_RESPONSE_REFERENCE);
672+
} catch (IOException | InterruptedException e) {
673+
throw new A2AServerException("Failed to get authenticated extended agent card: " + e, e);
674+
}
675+
}
676+
635677
private String sendPostRequest(Object value) throws IOException, InterruptedException {
636-
A2AHttpClient.PostBuilder builder = createPostBuilder(value);
678+
return sendPostRequest(value, null);
679+
}
680+
681+
private String sendPostRequest(Object value, Map<String, String> authHeaders) throws IOException, InterruptedException {
682+
A2AHttpClient.PostBuilder builder = createPostBuilder(value, authHeaders);
637683
A2AHttpResponse response = builder.post();
638684
if (!response.success()) {
639685
throw new IOException("Request failed " + response.status());
@@ -642,11 +688,20 @@ private String sendPostRequest(Object value) throws IOException, InterruptedExce
642688
}
643689

644690
private A2AHttpClient.PostBuilder createPostBuilder(Object value) throws JsonProcessingException {
645-
return httpClient.createPost()
691+
return createPostBuilder(value, null);
692+
}
693+
694+
private A2AHttpClient.PostBuilder createPostBuilder(Object value, Map<String, String> authHeaders) throws JsonProcessingException {
695+
A2AHttpClient.PostBuilder builder = httpClient.createPost()
646696
.url(agentUrl)
647697
.addHeader("Content-Type", "application/json")
648698
.body(Utils.OBJECT_MAPPER.writeValueAsString(value));
649-
699+
if (authHeaders != null) {
700+
for (Map.Entry<String, String> entry : authHeaders.entrySet()) {
701+
builder.addHeader(entry.getKey(), entry.getValue());
702+
}
703+
}
704+
return builder;
650705
}
651706

652707
private <T extends JSONRPCResponse> T unmarshalResponse(String response, TypeReference<T> typeReference)

client/src/test/java/io/a2a/client/A2ACardResolverTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
public class A2ACardResolverTest {
2222

23-
private static final String AGENT_CARD_PATH = "/.well-known/agent.json";
23+
private static final String AGENT_CARD_PATH = "/.well-known/agent-card.json";
2424
private static final TypeReference<AgentCard> AGENT_CARD_TYPE_REFERENCE = new TypeReference<>() {};
2525

2626
@Test

client/src/test/java/io/a2a/client/A2AClientTest.java

Lines changed: 32 additions & 7 deletions

0 commit comments

Comments
 (0)