Skip to content

Commit 19d2401

Browse files
committed
fix: Introduce a ClientTransportConfig interface, update ClientConfig to make use of it, and remove the http-client and grpc dependencies from the client config module
1 parent a880df8 commit 19d2401

File tree

7 files changed

+79
-34
lines changed

7 files changed

+79
-34
lines changed

client/config/pom.xml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@
1818
<description>Java SDK for the Agent2Agent Protocol (A2A) - Client Configuration</description>
1919

2020
<dependencies>
21-
<dependency>
22-
<groupId>${project.groupId}</groupId>
23-
<artifactId>a2a-java-sdk-http-client</artifactId>
24-
<version>${project.version}</version>
25-
</dependency>
2621
<dependency>
2722
<groupId>${project.groupId}</groupId>
2823
<artifactId>a2a-java-sdk-spec</artifactId>
@@ -39,10 +34,6 @@
3934
<artifactId>mockserver-netty</artifactId>
4035
<scope>test</scope>
4136
</dependency>
42-
<dependency>
43-
<groupId>io.grpc</groupId>
44-
<artifactId>grpc-api</artifactId>
45-
</dependency>
4637
</dependencies>
4738

4839
</project>

client/config/src/main/java/io/a2a/client/config/ClientConfig.java

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
import java.util.List;
44
import java.util.Map;
55

6-
import io.a2a.client.http.A2AHttpClient;
76
import io.a2a.spec.PushNotificationConfig;
8-
import io.grpc.Channel;
97

108
/**
119
* Configuration for the A2A client factory.
@@ -14,23 +12,21 @@ public class ClientConfig {
1412

1513
private final Boolean streaming;
1614
private final Boolean polling;
17-
private final A2AHttpClient httpClient;
18-
private final Channel channel;
15+
private final List<ClientTransportConfig> clientTransportConfigs;
1916
private final List<String> supportedTransports;
2017
private final Boolean useClientPreference;
2118
private final List<String> acceptedOutputModes;
2219
private final PushNotificationConfig pushNotificationConfig;
2320
private final Integer historyLength;
2421
private final Map<String, Object> metadata;
2522

26-
public ClientConfig(Boolean streaming, Boolean polling, A2AHttpClient httpClient, Channel channel,
23+
public ClientConfig(Boolean streaming, Boolean polling, List<ClientTransportConfig> clientTransportConfigs,
2724
List<String> supportedTransports, Boolean useClientPreference,
2825
List<String> acceptedOutputModes, PushNotificationConfig pushNotificationConfig,
2926
Integer historyLength, Map<String, Object> metadata) {
3027
this.streaming = streaming == null ? true : streaming;
3128
this.polling = polling == null ? false : polling;
32-
this.httpClient = httpClient;
33-
this.channel = channel;
29+
this.clientTransportConfigs = clientTransportConfigs;
3430
this.supportedTransports = supportedTransports;
3531
this.useClientPreference = useClientPreference == null ? false : useClientPreference;
3632
this.acceptedOutputModes = acceptedOutputModes;
@@ -47,12 +43,8 @@ public boolean isPolling() {
4743
return polling;
4844
}
4945

50-
public A2AHttpClient getHttpClient() {
51-
return httpClient;
52-
}
53-
54-
public Channel getChannel() {
55-
return channel;
46+
public List<ClientTransportConfig> getClientTransportConfigs() {
47+
return clientTransportConfigs;
5648
}
5749

5850
public List<String> getSupportedTransports() {
@@ -82,8 +74,7 @@ public Map<String, Object> getMetadata() {
8274
public static class Builder {
8375
private Boolean streaming;
8476
private Boolean polling;
85-
private A2AHttpClient httpClient;
86-
private Channel channel;
77+
private List<ClientTransportConfig> clientTransportConfigs;
8778
private List<String> supportedTransports;
8879
private Boolean useClientPreference;
8980
private List<String> acceptedOutputModes;
@@ -101,13 +92,8 @@ public Builder setPolling(Boolean polling) {
10192
return this;
10293
}
10394

104-
public Builder setHttpClient(A2AHttpClient httpClient) {
105-
this.httpClient = httpClient;
106-
return this;
107-
}
108-
109-
public Builder setChannel(Channel channel) {
110-
this.channel = channel;
95+
public Builder setClientTransportConfigs(List<ClientTransportConfig> clientTransportConfigs) {
96+
this.clientTransportConfigs = clientTransportConfigs;
11197
return this;
11298
}
11399

@@ -142,7 +128,7 @@ public Builder setMetadata(Map<String, Object> metadata) {
142128
}
143129

144130
public ClientConfig build() {
145-
return new ClientConfig(streaming, polling, httpClient, channel,
131+
return new ClientConfig(streaming, polling, clientTransportConfigs,
146132
supportedTransports, useClientPreference, acceptedOutputModes,
147133
pushNotificationConfig, historyLength, metadata);
148134
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package io.a2a.client.config;
2+
3+
/**
4+
* Configuration for an A2A client transport.
5+
*/
6+
public interface ClientTransportConfig {
7+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package io.a2a.client.transport.grpc;
2+
3+
import io.a2a.client.config.ClientTransportConfig;
4+
import io.grpc.ManagedChannelBuilder;
5+
6+
public class GrpcTransportConfig implements ClientTransportConfig {
7+
8+
private final ManagedChannelBuilder<?> channelBuilder;
9+
10+
public GrpcTransportConfig(ManagedChannelBuilder<?> channelBuilder) {
11+
this.channelBuilder = channelBuilder;
12+
}
13+
14+
public ManagedChannelBuilder<?> getManagedChannelBuilder() {
15+
return channelBuilder;
16+
}
17+
}

client/transport/grpc/src/main/java/io/a2a/client/transport/grpc/GrpcTransportProvider.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44

55
import io.a2a.client.config.ClientCallInterceptor;
66
import io.a2a.client.config.ClientConfig;
7+
import io.a2a.client.config.ClientTransportConfig;
78
import io.a2a.client.transport.spi.ClientTransport;
89
import io.a2a.client.transport.spi.ClientTransportProvider;
910
import io.a2a.spec.AgentCard;
1011
import io.a2a.spec.TransportProtocol;
12+
import io.grpc.Channel;
13+
import io.grpc.ManagedChannelBuilder;
1114

1215
/**
1316
* Provider for gRPC transport implementation.
@@ -18,7 +21,19 @@ public class GrpcTransportProvider implements ClientTransportProvider {
1821
public ClientTransport create(ClientConfig clientConfig, AgentCard agentCard,
1922
String agentUrl, List<ClientCallInterceptor> interceptors) {
2023
// not making use of the interceptors for gRPC for now
21-
return new GrpcTransport(clientConfig.getChannel(), agentCard);
24+
ManagedChannelBuilder<?> managedChannelBuilder = null;
25+
List<ClientTransportConfig> clientTransportConfigs = clientConfig.getClientTransportConfigs();
26+
if (clientTransportConfigs != null) {
27+
for (ClientTransportConfig clientTransportConfig : clientTransportConfigs) {
28+
if (clientTransportConfig instanceof GrpcTransportConfig grpcTransportConfig) {
29+
managedChannelBuilder = grpcTransportConfig.getManagedChannelBuilder();
30+
break;
31+
}
32+
}
33+
}
34+
Channel channel = managedChannelBuilder == null ? ManagedChannelBuilder.forTarget(agentUrl).build()
35+
: managedChannelBuilder.forTarget(agentUrl).build();
36+
return new GrpcTransport(channel, agentCard);
2237
}
2338

2439
@Override
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package io.a2a.client.transport.jsonrpc;
2+
3+
import io.a2a.client.config.ClientTransportConfig;
4+
import io.a2a.client.http.A2AHttpClient;
5+
6+
public class JSONRPCTransportConfig implements ClientTransportConfig {
7+
8+
private final A2AHttpClient httpClient;
9+
10+
public JSONRPCTransportConfig(A2AHttpClient httpClient) {
11+
this.httpClient = httpClient;
12+
}
13+
14+
public A2AHttpClient getHttpClient() {
15+
return httpClient;
16+
}
17+
}

client/transport/jsonrpc/src/main/java/io/a2a/client/transport/jsonrpc/JSONRPCTransportProvider.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
import io.a2a.client.config.ClientCallInterceptor;
66
import io.a2a.client.config.ClientConfig;
7+
import io.a2a.client.config.ClientTransportConfig;
8+
import io.a2a.client.http.A2AHttpClient;
79
import io.a2a.client.transport.spi.ClientTransport;
810
import io.a2a.client.transport.spi.ClientTransportProvider;
911
import io.a2a.spec.AgentCard;
@@ -14,7 +16,17 @@ public class JSONRPCTransportProvider implements ClientTransportProvider {
1416
@Override
1517
public ClientTransport create(ClientConfig clientConfig, AgentCard agentCard,
1618
String agentUrl, List<ClientCallInterceptor> interceptors) {
17-
return new JSONRPCTransport(clientConfig.getHttpClient(), agentCard, agentUrl, interceptors);
19+
A2AHttpClient httpClient = null;
20+
List<ClientTransportConfig> clientTransportConfigs = clientConfig.getClientTransportConfigs();
21+
if (clientTransportConfigs != null) {
22+
for (ClientTransportConfig clientTransportConfig : clientTransportConfigs) {
23+
if (clientTransportConfig instanceof JSONRPCTransportConfig jsonrpcTransportConfig) {
24+
httpClient = jsonrpcTransportConfig.getHttpClient();
25+
break;
26+
}
27+
}
28+
}
29+
return new JSONRPCTransport(httpClient, agentCard, agentUrl, interceptors);
1830
}
1931

2032
@Override

0 commit comments

Comments
 (0)