@@ -65,45 +65,6 @@ def __init__(
6565 self .extensions = extensions
6666 self ._needs_extended_card = agent_card .capabilities .extended_agent_card
6767
68- async def _apply_interceptors (
69- self ,
70- method_name : str ,
71- request_payload : dict [str , Any ],
72- http_kwargs : dict [str , Any ] | None ,
73- context : ClientCallContext | None ,
74- ) -> tuple [dict [str , Any ], dict [str , Any ]]:
75- final_http_kwargs = http_kwargs or {}
76- final_request_payload = request_payload
77-
78- for interceptor in self .interceptors :
79- (
80- final_request_payload ,
81- final_http_kwargs ,
82- ) = await interceptor .intercept (
83- method_name ,
84- final_request_payload ,
85- final_http_kwargs ,
86- self .agent_card ,
87- context ,
88- )
89- return final_request_payload , final_http_kwargs
90-
91- def _get_http_args (
92- self , context : ClientCallContext | None
93- ) -> dict [str , Any ] | None :
94- return context .state .get ('http_kwargs' ) if context else None
95-
96- def _handle_jsonrpc_error (self , error_dict : dict [str , Any ]) -> NoReturn :
97- """Handles JSON-RPC errors and raises the appropriate A2AError."""
98- code = error_dict .get ('code' )
99- message = error_dict .get ('message' , str (error_dict ))
100-
101- if isinstance (code , int ) and code in _JSON_RPC_ERROR_CODE_TO_A2A_ERROR :
102- raise _JSON_RPC_ERROR_CODE_TO_A2A_ERROR [code ](message )
103-
104- # Fallback to general A2AClientError
105- raise A2AClientError (f'JSON-RPC Error { code } : { message } ' )
106-
10768 async def send_message (
10869 self ,
10970 request : SendMessageRequest ,
@@ -200,28 +161,6 @@ async def send_message_streaming(
200161 except httpx .RequestError as e :
201162 raise A2AClientError (f'Network communication error: { e } ' ) from e
202163
203- async def _send_request (
204- self ,
205- rpc_request_payload : dict [str , Any ],
206- http_kwargs : dict [str , Any ] | None = None ,
207- ) -> dict [str , Any ]:
208- try :
209- response = await self .httpx_client .post (
210- self .url , json = rpc_request_payload , ** (http_kwargs or {})
211- )
212- response .raise_for_status ()
213- return response .json ()
214- except httpx .TimeoutException as e :
215- raise A2AClientError ('Client Request timed out' ) from e
216- except httpx .HTTPStatusError as e :
217- raise A2AClientError (
218- f'HTTP Error { e .response .status_code } : { e } '
219- ) from e
220- except json .JSONDecodeError as e :
221- raise A2AClientError (str (e )) from e
222- except httpx .RequestError as e :
223- raise A2AClientError (f'Network communication error: { e } ' ) from e
224-
225164 async def get_task (
226165 self ,
227166 request : GetTaskRequest ,
@@ -543,3 +482,64 @@ async def get_extended_agent_card(
543482 async def close (self ) -> None :
544483 """Closes the httpx client."""
545484 await self .httpx_client .aclose ()
485+
486+ async def _apply_interceptors (
487+ self ,
488+ method_name : str ,
489+ request_payload : dict [str , Any ],
490+ http_kwargs : dict [str , Any ] | None ,
491+ context : ClientCallContext | None ,
492+ ) -> tuple [dict [str , Any ], dict [str , Any ]]:
493+ final_http_kwargs = http_kwargs or {}
494+ final_request_payload = request_payload
495+
496+ for interceptor in self .interceptors :
497+ (
498+ final_request_payload ,
499+ final_http_kwargs ,
500+ ) = await interceptor .intercept (
501+ method_name ,
502+ final_request_payload ,
503+ final_http_kwargs ,
504+ self .agent_card ,
505+ context ,
506+ )
507+ return final_request_payload , final_http_kwargs
508+
509+ def _get_http_args (
510+ self , context : ClientCallContext | None
511+ ) -> dict [str , Any ] | None :
512+ return context .state .get ('http_kwargs' ) if context else None
513+
514+ def _handle_jsonrpc_error (self , error_dict : dict [str , Any ]) -> NoReturn :
515+ """Handles JSON-RPC errors and raises the appropriate A2AError."""
516+ code = error_dict .get ('code' )
517+ message = error_dict .get ('message' , str (error_dict ))
518+
519+ if isinstance (code , int ) and code in _JSON_RPC_ERROR_CODE_TO_A2A_ERROR :
520+ raise _JSON_RPC_ERROR_CODE_TO_A2A_ERROR [code ](message )
521+
522+ # Fallback to general A2AClientError
523+ raise A2AClientError (f'JSON-RPC Error { code } : { message } ' )
524+
525+ async def _send_request (
526+ self ,
527+ rpc_request_payload : dict [str , Any ],
528+ http_kwargs : dict [str , Any ] | None = None ,
529+ ) -> dict [str , Any ]:
530+ try :
531+ response = await self .httpx_client .post (
532+ self .url , json = rpc_request_payload , ** (http_kwargs or {})
533+ )
534+ response .raise_for_status ()
535+ return response .json ()
536+ except httpx .TimeoutException as e :
537+ raise A2AClientError ('Client Request timed out' ) from e
538+ except httpx .HTTPStatusError as e :
539+ raise A2AClientError (
540+ f'HTTP Error { e .response .status_code } : { e } '
541+ ) from e
542+ except json .JSONDecodeError as e :
543+ raise A2AClientError (str (e )) from e
544+ except httpx .RequestError as e :
545+ raise A2AClientError (f'Network communication error: { e } ' ) from e
0 commit comments