2525import io .a2a .spec .A2AClientError ;
2626import io .a2a .spec .A2AClientException ;
2727import io .a2a .spec .AgentCard ;
28+ import io .a2a .spec .AgentInterface ;
2829import io .a2a .spec .CancelTaskRequest ;
2930import io .a2a .spec .CancelTaskResponse ;
3031import io .a2a .spec .DeleteTaskPushNotificationConfigParams ;
6667public class JSONRPCTransport implements ClientTransport {
6768
6869 private final A2AHttpClient httpClient ;
69- private final String agentUrl ;
70+ private final AgentInterface agentInterface ;
7071 private final @ Nullable List <ClientCallInterceptor > interceptors ;
7172 private @ Nullable AgentCard agentCard ;
7273 private boolean needsExtendedCard = false ;
7374
7475 public JSONRPCTransport (String agentUrl ) {
75- this (null , null , agentUrl , null );
76+ this (null , null , new AgentInterface ( "JSONRPC" , agentUrl ), null );
7677 }
7778
7879 public JSONRPCTransport (AgentCard agentCard ) {
7980 this (null , agentCard , Utils .getFavoriteInterface (agentCard ), null );
8081 }
8182
8283 public JSONRPCTransport (@ Nullable A2AHttpClient httpClient , @ Nullable AgentCard agentCard ,
83- String agentUrl , @ Nullable List <ClientCallInterceptor > interceptors ) {
84+ AgentInterface agentInterface , @ Nullable List <ClientCallInterceptor > interceptors ) {
8485 this .httpClient = httpClient == null ? new JdkA2AHttpClient () : httpClient ;
8586 this .agentCard = agentCard ;
86- this .agentUrl = agentUrl ;
87+ this .agentInterface = agentInterface ;
8788 this .interceptors = interceptors ;
8889 this .needsExtendedCard = agentCard == null || agentCard .supportsExtendedAgentCard ();
8990 }
@@ -95,7 +96,7 @@ public EventKind sendMessage(MessageSendParams request, @Nullable ClientCallCont
9596 agentCard , context );
9697
9798 try {
98- String httpResponseBody = sendPostRequest (payloadAndHeaders , SendMessageRequest .METHOD );
99+ String httpResponseBody = sendPostRequest (Utils . buildBaseUrl ( agentInterface , request . tenant ()), payloadAndHeaders , SendMessageRequest .METHOD );
99100 SendMessageResponse response = unmarshalResponse (httpResponseBody , SendMessageRequest .METHOD );
100101 return response .getResult ();
101102 } catch (A2AClientException e ) {
@@ -117,7 +118,7 @@ public void sendMessageStreaming(MessageSendParams request, Consumer<StreamingEv
117118 SSEEventListener sseEventListener = new SSEEventListener (eventConsumer , errorConsumer );
118119
119120 try {
120- A2AHttpClient .PostBuilder builder = createPostBuilder (payloadAndHeaders , SendStreamingMessageRequest .METHOD );
121+ A2AHttpClient .PostBuilder builder = createPostBuilder (Utils . buildBaseUrl ( agentInterface , request . tenant ()), payloadAndHeaders , SendStreamingMessageRequest .METHOD );
121122 ref .set (builder .postAsyncSSE (
122123 msg -> sseEventListener .onMessage (msg , ref .get ()),
123124 throwable -> sseEventListener .onError (throwable , ref .get ()),
@@ -141,7 +142,7 @@ public Task getTask(TaskQueryParams request, @Nullable ClientCallContext context
141142 agentCard , context );
142143
143144 try {
144- String httpResponseBody = sendPostRequest (payloadAndHeaders , GetTaskRequest .METHOD );
145+ String httpResponseBody = sendPostRequest (Utils . buildBaseUrl ( agentInterface , request . tenant ()), payloadAndHeaders , GetTaskRequest .METHOD );
145146 GetTaskResponse response = unmarshalResponse (httpResponseBody , GetTaskRequest .METHOD );
146147 return response .getResult ();
147148 } catch (A2AClientException e ) {
@@ -158,7 +159,7 @@ public Task cancelTask(TaskIdParams request, @Nullable ClientCallContext context
158159 agentCard , context );
159160
160161 try {
161- String httpResponseBody = sendPostRequest (payloadAndHeaders , CancelTaskRequest .METHOD );
162+ String httpResponseBody = sendPostRequest (Utils . buildBaseUrl ( agentInterface , request . tenant ()), payloadAndHeaders , CancelTaskRequest .METHOD );
162163 CancelTaskResponse response = unmarshalResponse (httpResponseBody , CancelTaskRequest .METHOD );
163164 return response .getResult ();
164165 } catch (A2AClientException e ) {
@@ -174,7 +175,7 @@ public ListTasksResult listTasks(ListTasksParams request, @Nullable ClientCallCo
174175 PayloadAndHeaders payloadAndHeaders = applyInterceptors (ListTasksRequest .METHOD , ProtoUtils .ToProto .listTasksParams (request ),
175176 agentCard , context );
176177 try {
177- String httpResponseBody = sendPostRequest (payloadAndHeaders , ListTasksRequest .METHOD );
178+ String httpResponseBody = sendPostRequest (Utils . buildBaseUrl ( agentInterface , request . tenant ()), payloadAndHeaders , ListTasksRequest .METHOD );
178179 ListTasksResponse response = unmarshalResponse (httpResponseBody , ListTasksRequest .METHOD );
179180 return response .getResult ();
180181 } catch (IOException | InterruptedException | JsonProcessingException e ) {
@@ -190,7 +191,7 @@ public TaskPushNotificationConfig setTaskPushNotificationConfiguration(TaskPushN
190191 ProtoUtils .ToProto .setTaskPushNotificationConfigRequest (request ), agentCard , context );
191192
192193 try {
193- String httpResponseBody = sendPostRequest (payloadAndHeaders , SetTaskPushNotificationConfigRequest .METHOD );
194+ String httpResponseBody = sendPostRequest (Utils . buildBaseUrl ( agentInterface , request . tenant ()), payloadAndHeaders , SetTaskPushNotificationConfigRequest .METHOD );
194195 SetTaskPushNotificationConfigResponse response = unmarshalResponse (httpResponseBody ,
195196 SetTaskPushNotificationConfigRequest .METHOD );
196197 return response .getResult ();
@@ -209,7 +210,7 @@ public TaskPushNotificationConfig getTaskPushNotificationConfiguration(GetTaskPu
209210 ProtoUtils .ToProto .getTaskPushNotificationConfigRequest (request ), agentCard , context );
210211
211212 try {
212- String httpResponseBody = sendPostRequest (payloadAndHeaders ,GetTaskPushNotificationConfigRequest .METHOD );
213+ String httpResponseBody = sendPostRequest (Utils . buildBaseUrl ( agentInterface , request . tenant ()), payloadAndHeaders ,GetTaskPushNotificationConfigRequest .METHOD );
213214 GetTaskPushNotificationConfigResponse response = unmarshalResponse (httpResponseBody ,
214215 GetTaskPushNotificationConfigRequest .METHOD );
215216 return response .getResult ();
@@ -229,7 +230,7 @@ public List<TaskPushNotificationConfig> listTaskPushNotificationConfigurations(
229230 ProtoUtils .ToProto .listTaskPushNotificationConfigRequest (request ), agentCard , context );
230231
231232 try {
232- String httpResponseBody = sendPostRequest (payloadAndHeaders , ListTaskPushNotificationConfigRequest .METHOD );
233+ String httpResponseBody = sendPostRequest (Utils . buildBaseUrl ( agentInterface , request . tenant ()), payloadAndHeaders , ListTaskPushNotificationConfigRequest .METHOD );
233234 ListTaskPushNotificationConfigResponse response = unmarshalResponse (httpResponseBody ,
234235 ListTaskPushNotificationConfigRequest .METHOD );
235236 return response .getResult ();
@@ -248,7 +249,7 @@ public void deleteTaskPushNotificationConfigurations(DeleteTaskPushNotificationC
248249 ProtoUtils .ToProto .deleteTaskPushNotificationConfigRequest (request ), agentCard , context );
249250
250251 try {
251- String httpResponseBody = sendPostRequest (payloadAndHeaders ,DeleteTaskPushNotificationConfigRequest .METHOD );
252+ String httpResponseBody = sendPostRequest (Utils . buildBaseUrl ( agentInterface , request . tenant ()), payloadAndHeaders ,DeleteTaskPushNotificationConfigRequest .METHOD );
252253 DeleteTaskPushNotificationConfigResponse response = unmarshalResponse (httpResponseBody , DeleteTaskPushNotificationConfigRequest .METHOD );
253254 // Response validated (no error), but no result to return
254255 } catch (A2AClientException e ) {
@@ -271,7 +272,7 @@ public void resubscribe(TaskIdParams request, Consumer<StreamingEventKind> event
271272 SSEEventListener sseEventListener = new SSEEventListener (eventConsumer , errorConsumer );
272273
273274 try {
274- A2AHttpClient .PostBuilder builder = createPostBuilder (payloadAndHeaders ,SubscribeToTaskRequest .METHOD );
275+ A2AHttpClient .PostBuilder builder = createPostBuilder (Utils . buildBaseUrl ( agentInterface , request . tenant ()), payloadAndHeaders ,SubscribeToTaskRequest .METHOD );
275276 ref .set (builder .postAsyncSSE (
276277 msg -> sseEventListener .onMessage (msg , ref .get ()),
277278 throwable -> sseEventListener .onError (throwable , ref .get ()),
@@ -293,7 +294,7 @@ public AgentCard getAgentCard(@Nullable ClientCallContext context) throws A2ACli
293294 A2ACardResolver resolver ;
294295 try {
295296 if (agentCard == null ) {
296- resolver = new A2ACardResolver (httpClient , agentUrl , null , getHttpHeaders (context ));
297+ resolver = new A2ACardResolver (httpClient , agentInterface . url (), agentInterface . tenant () , null , getHttpHeaders (context ));
297298 agentCard = resolver .getAgentCard ();
298299 needsExtendedCard = agentCard .supportsExtendedAgentCard ();
299300 }
@@ -309,7 +310,7 @@ public AgentCard getAgentCard(@Nullable ClientCallContext context) throws A2ACli
309310 ProtoUtils .ToProto .extendedAgentCard (getExtendedAgentCardRequest ), agentCard , context );
310311
311312 try {
312- String httpResponseBody = sendPostRequest (payloadAndHeaders ,GetAuthenticatedExtendedCardRequest .METHOD );
313+ String httpResponseBody = sendPostRequest (Utils . buildBaseUrl ( agentInterface , "" ), payloadAndHeaders ,GetAuthenticatedExtendedCardRequest .METHOD );
313314 GetAuthenticatedExtendedCardResponse response = unmarshalResponse (httpResponseBody ,
314315 GetAuthenticatedExtendedCardRequest .METHOD );
315316 agentCard = response .getResult ();
@@ -340,18 +341,18 @@ private PayloadAndHeaders applyInterceptors(String methodName, @Nullable Object
340341 return payloadAndHeaders ;
341342 }
342343
343- private String sendPostRequest (PayloadAndHeaders payloadAndHeaders , String method ) throws IOException , InterruptedException , JsonProcessingException {
344- A2AHttpClient .PostBuilder builder = createPostBuilder (payloadAndHeaders ,method );
344+ private String sendPostRequest (String url , PayloadAndHeaders payloadAndHeaders , String method ) throws IOException , InterruptedException , JsonProcessingException {
345+ A2AHttpClient .PostBuilder builder = createPostBuilder (url , payloadAndHeaders ,method );
345346 A2AHttpResponse response = builder .post ();
346347 if (!response .success ()) {
347348 throw new IOException ("Request failed " + response .status ());
348349 }
349350 return response .body ();
350351 }
351352
352- private A2AHttpClient .PostBuilder createPostBuilder (PayloadAndHeaders payloadAndHeaders , String method ) throws JsonProcessingException {
353+ private A2AHttpClient .PostBuilder createPostBuilder (String url , PayloadAndHeaders payloadAndHeaders , String method ) throws JsonProcessingException {
353354 A2AHttpClient .PostBuilder postBuilder = httpClient .createPost ()
354- .url (agentUrl )
355+ .url (url )
355356 .addHeader ("Content-Type" , "application/json" )
356357 .body (JSONRPCUtils .toJsonRPCRequest (null , method , (MessageOrBuilder ) payloadAndHeaders .getPayload ()));
357358
0 commit comments