3636 TaskPushNotificationConfig ,
3737)
3838from a2a .utils .errors import JSON_RPC_ERROR_CODE_MAP
39+ from a2a .utils .proto_utils import parse_lenient
3940from a2a .utils .telemetry import SpanKind , trace_class
4041
4142
@@ -82,7 +83,7 @@ async def send_message(
8283 json_rpc_response = JSONRPC20Response (** response_data )
8384 if json_rpc_response .error :
8485 raise self ._create_jsonrpc_error (json_rpc_response .error )
85- response : SendMessageResponse = json_format . ParseDict (
86+ response : SendMessageResponse = parse_lenient (
8687 json_rpc_response .result , SendMessageResponse ()
8788 )
8889 return response
@@ -123,7 +124,7 @@ async def get_task(
123124 json_rpc_response = JSONRPC20Response (** response_data )
124125 if json_rpc_response .error :
125126 raise self ._create_jsonrpc_error (json_rpc_response .error )
126- response : Task = json_format . ParseDict (json_rpc_response .result , Task ())
127+ response : Task = parse_lenient (json_rpc_response .result , Task ())
127128 return response
128129
129130 async def list_tasks (
@@ -144,7 +145,7 @@ async def list_tasks(
144145 json_rpc_response = JSONRPC20Response (** response_data )
145146 if json_rpc_response .error :
146147 raise self ._create_jsonrpc_error (json_rpc_response .error )
147- response : ListTasksResponse = json_format . ParseDict (
148+ response : ListTasksResponse = parse_lenient (
148149 json_rpc_response .result , ListTasksResponse ()
149150 )
150151 return response
@@ -167,7 +168,7 @@ async def cancel_task(
167168 json_rpc_response = JSONRPC20Response (** response_data )
168169 if json_rpc_response .error :
169170 raise self ._create_jsonrpc_error (json_rpc_response .error )
170- response : Task = json_format . ParseDict (json_rpc_response .result , Task ())
171+ response : Task = parse_lenient (json_rpc_response .result , Task ())
171172 return response
172173
173174 async def create_task_push_notification_config (
@@ -188,7 +189,7 @@ async def create_task_push_notification_config(
188189 json_rpc_response = JSONRPC20Response (** response_data )
189190 if json_rpc_response .error :
190191 raise self ._create_jsonrpc_error (json_rpc_response .error )
191- response : TaskPushNotificationConfig = json_format . ParseDict (
192+ response : TaskPushNotificationConfig = parse_lenient (
192193 json_rpc_response .result , TaskPushNotificationConfig ()
193194 )
194195 return response
@@ -211,7 +212,7 @@ async def get_task_push_notification_config(
211212 json_rpc_response = JSONRPC20Response (** response_data )
212213 if json_rpc_response .error :
213214 raise self ._create_jsonrpc_error (json_rpc_response .error )
214- response : TaskPushNotificationConfig = json_format . ParseDict (
215+ response : TaskPushNotificationConfig = parse_lenient (
215216 json_rpc_response .result , TaskPushNotificationConfig ()
216217 )
217218 return response
@@ -234,11 +235,8 @@ async def list_task_push_notification_configs(
234235 json_rpc_response = JSONRPC20Response (** response_data )
235236 if json_rpc_response .error :
236237 raise self ._create_jsonrpc_error (json_rpc_response .error )
237- response : ListTaskPushNotificationConfigsResponse = (
238- json_format .ParseDict (
239- json_rpc_response .result ,
240- ListTaskPushNotificationConfigsResponse (),
241- )
238+ response : ListTaskPushNotificationConfigsResponse = parse_lenient (
239+ json_rpc_response .result , ListTaskPushNotificationConfigsResponse ()
242240 )
243241 return response
244242
@@ -307,7 +305,7 @@ async def get_extended_agent_card(
307305 raise A2AClientError (
308306 f'Invalid response type: { type (json_rpc_response .result )} '
309307 )
310- response : AgentCard = json_format . ParseDict (
308+ response : AgentCard = parse_lenient (
311309 json_rpc_response .result , AgentCard ()
312310 )
313311
@@ -380,7 +378,7 @@ async def _send_stream_request(
380378 json_rpc_response = JSONRPC20Response .from_json (sse_data )
381379 if json_rpc_response .error :
382380 raise self ._create_jsonrpc_error (json_rpc_response .error )
383- response : StreamResponse = json_format . ParseDict (
381+ response : StreamResponse = parse_lenient (
384382 json_rpc_response .result , StreamResponse ()
385383 )
386384 yield response
0 commit comments