44
55from collections .abc import AsyncGenerator
66from typing import Any , NoReturn
7+ from urllib .parse import quote
78
89import httpx
910
5859}
5960
6061
62+ def _quote_id (value : str ) -> str :
63+ """Percent-encodes an id so it stays a single URL path segment."""
64+ return quote (value , safe = '' )
65+
66+
6167@trace_class (kind = SpanKind .CLIENT )
6268class CompatRestTransport (ClientTransport ):
6369 """A backward compatible REST transport for A2A v0.3."""
@@ -101,7 +107,7 @@ async def send_message(
101107 'POST' ,
102108 '/v1/message:send' ,
103109 context = context ,
104- json = MessageToDict (req_proto , preserving_proto_field_name = True ),
110+ json = MessageToDict (req_proto ),
105111 )
106112
107113 resp_proto = ParseDict (
@@ -146,7 +152,7 @@ async def send_message_streaming(
146152 'POST' ,
147153 '/v1/message:stream' ,
148154 context = context ,
149- json = MessageToDict (req_proto , preserving_proto_field_name = True ),
155+ json = MessageToDict (req_proto ),
150156 ):
151157 yield event
152158
@@ -163,7 +169,7 @@ async def get_task(
163169
164170 response_data = await self ._execute_request (
165171 'GET' ,
166- f'/v1/tasks/{ request .id } ' ,
172+ f'/v1/tasks/{ _quote_id ( request .id ) } ' ,
167173 context = context ,
168174 params = params ,
169175 )
@@ -192,7 +198,7 @@ async def cancel_task(
192198 """Requests the agent to cancel a specific task."""
193199 response_data = await self ._execute_request (
194200 'POST' ,
195- f'/v1/tasks/{ request .id } :cancel' ,
201+ f'/v1/tasks/{ _quote_id ( request .id ) } :cancel' ,
196202 context = context ,
197203 )
198204 resp_proto = ParseDict (
@@ -221,9 +227,9 @@ async def create_task_push_notification_config(
221227 )
222228 response_data = await self ._execute_request (
223229 'POST' ,
224- f'/v1/tasks/{ request .task_id } /pushNotificationConfigs' ,
230+ f'/v1/tasks/{ _quote_id ( request .task_id ) } /pushNotificationConfigs' ,
225231 context = context ,
226- json = MessageToDict (req_proto , preserving_proto_field_name = True ),
232+ json = MessageToDict (req_proto ),
227233 )
228234 resp_proto = ParseDict (
229235 response_data ,
@@ -243,7 +249,8 @@ async def get_task_push_notification_config(
243249 """Retrieves the push notification configuration for a specific task."""
244250 response_data = await self ._execute_request (
245251 'GET' ,
246- f'/v1/tasks/{ request .task_id } /pushNotificationConfigs/{ request .id } ' ,
252+ f'/v1/tasks/{ _quote_id (request .task_id )} '
253+ f'/pushNotificationConfigs/{ _quote_id (request .id )} ' ,
247254 context = context ,
248255 )
249256 resp_proto = ParseDict (
@@ -264,7 +271,7 @@ async def list_task_push_notification_configs(
264271 """Lists push notification configurations for a specific task."""
265272 response_data = await self ._execute_request (
266273 'GET' ,
267- f'/v1/tasks/{ request .task_id } /pushNotificationConfigs' ,
274+ f'/v1/tasks/{ _quote_id ( request .task_id ) } /pushNotificationConfigs' ,
268275 context = context ,
269276 )
270277 resp_proto = ParseDict (
@@ -285,8 +292,10 @@ async def delete_task_push_notification_config(
285292 context : ClientCallContext | None = None ,
286293 ) -> None :
287294 """Deletes the push notification configuration for a specific task."""
288- raise NotImplementedError (
289- 'delete_task_push_notification_config not supported in v0.3 REST'
295+ await self ._execute_request (
296+ 'DELETE' ,
297+ f'/v1/tasks/{ request .task_id } /pushNotificationConfigs/{ request .id } ' ,
298+ context = context ,
290299 )
291300
292301 async def subscribe (
@@ -308,7 +317,7 @@ async def subscribe(
308317 try :
309318 async for event in self ._send_stream_request (
310319 subscribe_method ,
311- f'/v1/tasks/{ request .id } :subscribe' ,
320+ f'/v1/tasks/{ _quote_id ( request .id ) } :subscribe' ,
312321 context = context ,
313322 ):
314323 yield event
0 commit comments