Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/a2a/server/request_handlers/default_request_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def __init__( # noqa: PLR0913
async def on_get_task(
self,
params: GetTaskRequest,
context: ServerCallContext | None = None,
context: ServerCallContext,
) -> Task | None:
"""Default handler for 'tasks/get'."""
validate_history_length(params)
Expand All @@ -138,7 +138,7 @@ async def on_get_task(
async def on_list_tasks(
self,
params: ListTasksRequest,
context: ServerCallContext | None = None,
context: ServerCallContext,
) -> ListTasksResponse:
"""Default handler for 'tasks/list'."""
validate_history_length(params)
Expand All @@ -159,7 +159,7 @@ async def on_list_tasks(
async def on_cancel_task(
self,
params: CancelTaskRequest,
context: ServerCallContext | None = None,
context: ServerCallContext,
) -> Task | None:
"""Default handler for 'tasks/cancel'.

Expand Down Expand Up @@ -231,7 +231,7 @@ async def _run_event_stream(
async def _setup_message_execution(
self,
params: SendMessageRequest,
context: ServerCallContext | None,
context: ServerCallContext,
) -> tuple[TaskManager, str, EventQueue, ResultAggregator, asyncio.Task]:
"""Common setup logic for both streaming and non-streaming message handling.

Expand Down Expand Up @@ -322,7 +322,7 @@ async def _send_push_notification_if_needed(
async def on_message_send(
self,
params: SendMessageRequest,
context: ServerCallContext | None = None,
context: ServerCallContext,
) -> Message | Task:
"""Default handler for 'message/send' interface (non-streaming).

Expand Down Expand Up @@ -388,7 +388,7 @@ async def push_notification_callback(event: Event) -> None:
async def on_message_send_stream(
self,
params: SendMessageRequest,
context: ServerCallContext | None = None,
context: ServerCallContext,
) -> AsyncGenerator[Event]:
"""Default handler for 'message/stream' (streaming).

Expand Down Expand Up @@ -476,7 +476,7 @@ async def _cleanup_producer(
async def on_create_task_push_notification_config(
self,
params: CreateTaskPushNotificationConfigRequest,
context: ServerCallContext | None = None,
context: ServerCallContext,
) -> TaskPushNotificationConfig:
"""Default handler for 'tasks/pushNotificationConfig/create'.

Expand Down Expand Up @@ -504,7 +504,7 @@ async def on_create_task_push_notification_config(
async def on_get_task_push_notification_config(
self,
params: GetTaskPushNotificationConfigRequest,
context: ServerCallContext | None = None,
context: ServerCallContext,
) -> TaskPushNotificationConfig:
"""Default handler for 'tasks/pushNotificationConfig/get'.

Expand Down Expand Up @@ -538,7 +538,7 @@ async def on_get_task_push_notification_config(
async def on_subscribe_to_task(
self,
params: SubscribeToTaskRequest,
context: ServerCallContext | None = None,
context: ServerCallContext,
) -> AsyncGenerator[Event, None]:
"""Default handler for 'SubscribeToTask'.

Expand Down Expand Up @@ -580,7 +580,7 @@ async def on_subscribe_to_task(
async def on_list_task_push_notification_configs(
self,
params: ListTaskPushNotificationConfigsRequest,
context: ServerCallContext | None = None,
context: ServerCallContext,
) -> ListTaskPushNotificationConfigsResponse:
"""Default handler for 'ListTaskPushNotificationConfigs'.

Expand Down Expand Up @@ -611,7 +611,7 @@ async def on_list_task_push_notification_configs(
async def on_delete_task_push_notification_config(
self,
params: DeleteTaskPushNotificationConfigRequest,
context: ServerCallContext | None = None,
context: ServerCallContext,
) -> None:
"""Default handler for 'tasks/pushNotificationConfig/delete'.

Expand Down
22 changes: 11 additions & 11 deletions src/a2a/server/request_handlers/jsonrpc_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
async def on_message_send(
self,
request: SendMessageRequest,
context: ServerCallContext | None = None,
context: ServerCallContext,
) -> dict[str, Any]:
"""Handles the 'message/send' JSON-RPC method.

Expand Down Expand Up @@ -174,7 +174,7 @@
async def on_message_send_stream(
self,
request: SendMessageRequest,
context: ServerCallContext | None = None,
context: ServerCallContext,
) -> AsyncIterable[dict[str, Any]]:
"""Handles the 'message/stream' JSON-RPC method.

Expand All @@ -188,27 +188,27 @@
Dict representations of JSON-RPC responses containing streaming events.
"""
try:
async for event in self.request_handler.on_message_send_stream(
request, context
):
# Wrap the event in StreamResponse for consistent client parsing
stream_response = proto_utils.to_stream_response(event)
result = MessageToDict(
stream_response, preserving_proto_field_name=False
)
yield _build_success_response(
self._get_request_id(context), result
)
except A2AError as e:
yield _build_error_response(
self._get_request_id(context),
e,
)

async def on_cancel_task(

Check notice on line 208 in src/a2a/server/request_handlers/jsonrpc_handler.py

View workflow job for this annotation

GitHub Actions / Lint Code Base

Copy/pasted code

see src/a2a/server/request_handlers/jsonrpc_handler.py (251-268)
self,
request: CancelTaskRequest,
context: ServerCallContext | None = None,
context: ServerCallContext,
) -> dict[str, Any]:
"""Handles the 'tasks/cancel' JSON-RPC method.

Expand All @@ -234,7 +234,7 @@
async def on_subscribe_to_task(
self,
request: SubscribeToTaskRequest,
context: ServerCallContext | None = None,
context: ServerCallContext,
) -> AsyncIterable[dict[str, Any]]:
"""Handles the 'SubscribeToTask' JSON-RPC method.

Expand All @@ -248,27 +248,27 @@
Dict representations of JSON-RPC responses containing streaming events.
"""
try:
async for event in self.request_handler.on_subscribe_to_task(
request, context
):
# Wrap the event in StreamResponse for consistent client parsing
stream_response = proto_utils.to_stream_response(event)
result = MessageToDict(
stream_response, preserving_proto_field_name=False
)
yield _build_success_response(
self._get_request_id(context), result
)
except A2AError as e:
yield _build_error_response(
self._get_request_id(context),
e,
)

async def get_push_notification_config(

Check notice on line 268 in src/a2a/server/request_handlers/jsonrpc_handler.py

View workflow job for this annotation

GitHub Actions / Lint Code Base

Copy/pasted code

see src/a2a/server/request_handlers/jsonrpc_handler.py (191-208)
self,
request: GetTaskPushNotificationConfigRequest,
context: ServerCallContext | None = None,
context: ServerCallContext,
) -> dict[str, Any]:
"""Handles the 'tasks/pushNotificationConfig/get' JSON-RPC method.

Expand Down Expand Up @@ -298,7 +298,7 @@
async def set_push_notification_config(
self,
request: CreateTaskPushNotificationConfigRequest,
context: ServerCallContext | None = None,
context: ServerCallContext,
) -> dict[str, Any]:
"""Handles the 'tasks/pushNotificationConfig/set' JSON-RPC method.

Expand Down Expand Up @@ -331,7 +331,7 @@
async def on_get_task(
self,
request: GetTaskRequest,
context: ServerCallContext | None = None,
context: ServerCallContext,
) -> dict[str, Any]:
"""Handles the 'tasks/get' JSON-RPC method.

Expand All @@ -357,7 +357,7 @@
async def list_tasks(
self,
request: ListTasksRequest,
context: ServerCallContext | None = None,
context: ServerCallContext,
) -> dict[str, Any]:
"""Handles the 'tasks/list' JSON-RPC method.

Expand All @@ -381,7 +381,7 @@
async def list_push_notification_configs(
self,
request: ListTaskPushNotificationConfigsRequest,
context: ServerCallContext | None = None,
context: ServerCallContext,
) -> dict[str, Any]:
"""Handles the 'ListTaskPushNotificationConfigs' JSON-RPC method.

Expand All @@ -406,7 +406,7 @@
async def delete_push_notification_config(
self,
request: DeleteTaskPushNotificationConfigRequest,
context: ServerCallContext | None = None,
context: ServerCallContext,
) -> dict[str, Any]:
"""Handles the 'tasks/pushNotificationConfig/delete' JSON-RPC method.

Expand All @@ -429,7 +429,7 @@
async def get_authenticated_extended_card(
self,
request: GetExtendedAgentCardRequest,
context: ServerCallContext | None = None,
context: ServerCallContext,
) -> dict[str, Any]:
"""Handles the 'agent/authenticatedExtendedCard' JSON-RPC method.

Expand Down
20 changes: 10 additions & 10 deletions src/a2a/server/request_handlers/request_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class RequestHandler(ABC):
async def on_get_task(
self,
params: GetTaskRequest,
context: ServerCallContext | None = None,
context: ServerCallContext,
) -> Task | None:
"""Handles the 'tasks/get' method.

Expand All @@ -49,7 +49,7 @@ async def on_get_task(

@abstractmethod
async def on_list_tasks(
self, params: ListTasksRequest, context: ServerCallContext | None = None
self, params: ListTasksRequest, context: ServerCallContext
) -> ListTasksResponse:
"""Handles the tasks/list method.

Expand All @@ -68,7 +68,7 @@ async def on_list_tasks(
async def on_cancel_task(
self,
params: CancelTaskRequest,
context: ServerCallContext | None = None,
context: ServerCallContext,
) -> Task | None:
"""Handles the 'tasks/cancel' method.

Expand All @@ -86,7 +86,7 @@ async def on_cancel_task(
async def on_message_send(
self,
params: SendMessageRequest,
context: ServerCallContext | None = None,
context: ServerCallContext,
) -> Task | Message:
"""Handles the 'message/send' method (non-streaming).

Expand All @@ -105,7 +105,7 @@ async def on_message_send(
async def on_message_send_stream(
self,
params: SendMessageRequest,
context: ServerCallContext | None = None,
context: ServerCallContext,
) -> AsyncGenerator[Event]:
"""Handles the 'message/stream' method (streaming).

Expand All @@ -129,7 +129,7 @@ async def on_message_send_stream(
async def on_create_task_push_notification_config(
self,
params: CreateTaskPushNotificationConfigRequest,
context: ServerCallContext | None = None,
context: ServerCallContext,
) -> TaskPushNotificationConfig:
"""Handles the 'tasks/pushNotificationConfig/create' method.

Expand All @@ -147,7 +147,7 @@ async def on_create_task_push_notification_config(
async def on_get_task_push_notification_config(
self,
params: GetTaskPushNotificationConfigRequest,
context: ServerCallContext | None = None,
context: ServerCallContext,
) -> TaskPushNotificationConfig:
"""Handles the 'tasks/pushNotificationConfig/get' method.

Expand All @@ -165,7 +165,7 @@ async def on_get_task_push_notification_config(
async def on_subscribe_to_task(
self,
params: SubscribeToTaskRequest,
context: ServerCallContext | None = None,
context: ServerCallContext,
) -> AsyncGenerator[Event]:
"""Handles the 'SubscribeToTask' method.

Expand All @@ -188,7 +188,7 @@ async def on_subscribe_to_task(
async def on_list_task_push_notification_configs(
self,
params: ListTaskPushNotificationConfigsRequest,
context: ServerCallContext | None = None,
context: ServerCallContext,
) -> ListTaskPushNotificationConfigsResponse:
"""Handles the 'ListTaskPushNotificationConfigs' method.

Expand All @@ -206,7 +206,7 @@ async def on_list_task_push_notification_configs(
async def on_delete_task_push_notification_config(
self,
params: DeleteTaskPushNotificationConfigRequest,
context: ServerCallContext | None = None,
context: ServerCallContext,
) -> None:
"""Handles the 'tasks/pushNotificationConfig/delete' method.

Expand Down
Loading
Loading