1- import logging
2- import grpc
31import contextlib
2+ import logging
43
5- from typing import AsyncIterable
64from abc import ABC , abstractmethod
5+ from collections .abc import AsyncIterable
6+
7+ import grpc
8+
9+ import a2a .grpc .a2a_pb2_grpc as a2a_grpc
710
11+ from a2a import types
12+ from a2a .auth .user import UnauthenticatedUser
13+ from a2a .grpc import a2a_pb2
814from a2a .server .context import ServerCallContext
915from a2a .server .request_handlers .request_handler import RequestHandler
1016from a2a .types import (
1117 AgentCard ,
12- InternalError ,
13- Message ,
14- Task ,
15- TaskArtifactUpdateEvent ,
1618 TaskNotFoundError ,
17- TaskPushNotificationConfig ,
18- TaskStatusUpdateEvent ,
1919)
20- from a2a import types
21- from a2a .auth .user import User as A2AUser
22- from a2a .auth .user import UnauthenticatedUser
23- from a2a .server .context import ServerCallContext
20+ from a2a .utils import proto_utils
2421from a2a .utils .errors import ServerError
2522from a2a .utils .helpers import validate , validate_async_generator
26- from a2a .utils import proto_utils
27- import a2a .grpc .a2a_pb2 as a2a_pb2
28- import a2a .grpc .a2a_pb2_grpc as a2a_grpc
2923
3024
3125logger = logging .getLogger (__name__ )
3226
3327# For now we use a trivial wrapper on the grpc context object
3428
29+
3530class CallContextBuilder (ABC ):
3631 """A class for building ServerCallContexts using the Starlette Request."""
3732
@@ -53,7 +48,8 @@ def build(self, context: grpc.ServicerContext) -> ServerCallContext:
5348
5449class GrpcHandler (a2a_grpc .A2AServiceServicer ):
5550 """Maps incoming gRPC requests to the appropriate request handler method
56- and formats responses."""
51+ and formats responses.
52+ """
5753
5854 def __init__ (
5955 self ,
@@ -115,7 +111,7 @@ async def SendStreamingMessage(
115111 """Handles the 'StreamMessage' gRPC method.
116112
117113 Yields response objects as they are produced by the underlying handler's
118- stream.
114+ stream.
119115
120116 Args:
121117 request: The incoming `SendMessageRequest` object.
@@ -181,7 +177,7 @@ async def TaskSubscription(
181177 """Handles the 'TaskSubscription' gRPC method.
182178
183179 Yields response objects as they are produced by the underlying handler's
184- stream.
180+ stream.
185181
186182 Args:
187183 request: The incoming `TaskSubscriptionRequest` object.
@@ -193,7 +189,8 @@ async def TaskSubscription(
193189 try :
194190 server_context = self .context_builder .build (context )
195191 async for event in self .request_handler .on_resubscribe_to_task (
196- proto_utils .FromProto .task_id_params (request ), server_context ,
192+ proto_utils .FromProto .task_id_params (request ),
193+ server_context ,
197194 ):
198195 yield proto_utils .ToProto .stream_response (event )
199196 except ServerError as e :
0 commit comments