33from collections .abc import AsyncIterable , AsyncIterator
44from typing import Any
55
6- from google .protobuf .json_format import MessageToDict , Parse
6+ from google .protobuf .json_format import MessageToDict , MessageToJson , Parse
77from starlette .requests import Request
88
99from a2a .grpc import a2a_pb2
@@ -86,7 +86,7 @@ async def on_message_send_stream(
8686 self ,
8787 request : Request ,
8888 context : ServerCallContext ,
89- ) -> AsyncIterator [dict [ str , Any ] ]:
89+ ) -> AsyncIterator [str ]:
9090 """Handles the 'message/stream' REST method.
9191
9292 Yields response objects as they are produced by the underlying handler's stream.
@@ -96,7 +96,7 @@ async def on_message_send_stream(
9696 context: Context provided by the server.
9797
9898 Yields:
99- `dict` objects containing streaming events
99+ JSON serialized objects containing streaming events
100100 (Task, Message, TaskStatusUpdateEvent, TaskArtifactUpdateEvent) as JSON
101101 """
102102 body = await request .body ()
@@ -110,7 +110,7 @@ async def on_message_send_stream(
110110 a2a_request , context
111111 ):
112112 response = proto_utils .ToProto .stream_response (event )
113- yield MessageToDict (response )
113+ yield MessageToJson (response )
114114
115115 async def on_cancel_task (
116116 self ,
@@ -142,7 +142,7 @@ async def on_resubscribe_to_task(
142142 self ,
143143 request : Request ,
144144 context : ServerCallContext ,
145- ) -> AsyncIterable [dict [ str , Any ] ]:
145+ ) -> AsyncIterable [str ]:
146146 """Handles the 'tasks/resubscribe' REST method.
147147
148148 Yields response objects as they are produced by the underlying handler's stream.
@@ -152,13 +152,13 @@ async def on_resubscribe_to_task(
152152 context: Context provided by the server.
153153
154154 Yields:
155- `dict` containing streaming events
155+ JSON serialized objects containing streaming events
156156 """
157157 task_id = request .path_params ['id' ]
158158 async for event in self .request_handler .on_resubscribe_to_task (
159159 TaskIdParams (id = task_id ), context
160160 ):
161- yield ( MessageToDict ( proto_utils .ToProto .stream_response (event ) ))
161+ yield MessageToJson ( proto_utils .ToProto .stream_response (event ))
162162
163163 async def get_push_notification (
164164 self ,
@@ -262,7 +262,7 @@ async def list_push_notifications(
262262 self ,
263263 request : Request ,
264264 context : ServerCallContext ,
265- ) -> list [ dict [str , Any ] ]:
265+ ) -> dict [str , Any ]:
266266 """Handles the 'tasks/pushNotificationConfig/list' REST method.
267267
268268 This method is currently not implemented.
@@ -283,7 +283,7 @@ async def list_tasks(
283283 self ,
284284 request : Request ,
285285 context : ServerCallContext ,
286- ) -> list [ dict [str , Any ] ]:
286+ ) -> dict [str , Any ]:
287287 """Handles the 'tasks/list' REST method.
288288
289289 This method is currently not implemented.
0 commit comments