Skip to content

Commit 30685cf

Browse files
committed
Refactor: Extract JSONRPC error models to resolve circular dependency
- Create `src/a2a/server/jsonrpc_models.py` to hold exception classes. - Remove `src/a2a/server/apps/jsonrpc/errors.py`. - Update imports across server handlers, utils, and tests. - Fix logic in DefaultRequestHandler.on_get_task_push_notification_config to handle list of configs.
1 parent c00b7b8 commit 30685cf

15 files changed

Lines changed: 41 additions & 46 deletions

src/a2a/server/apps/jsonrpc/jsonrpc_app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
HTTP_EXTENSION_HEADER,
1919
get_requested_extensions,
2020
)
21-
from a2a.server.apps.jsonrpc.errors import (
21+
from a2a.server.context import ServerCallContext
22+
from a2a.server.jsonrpc_models import (
2223
InternalError,
2324
InvalidParamsError,
2425
InvalidRequestError,
2526
JSONParseError,
2627
MethodNotFoundError,
2728
)
28-
from a2a.server.context import ServerCallContext
2929
from a2a.server.request_handlers.jsonrpc_handler import JSONRPCHandler
3030
from a2a.server.request_handlers.request_handler import RequestHandler
3131
from a2a.server.request_handlers.response_helpers import build_error_response

src/a2a/server/request_handlers/default_request_handler.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
ListTaskPushNotificationConfigRequest,
3636
ListTaskPushNotificationConfigResponse,
3737
Message,
38+
PushNotificationConfig,
3839
SendMessageRequest,
3940
SetTaskPushNotificationConfigRequest,
4041
StreamResponse,
@@ -514,23 +515,24 @@ async def on_get_task_push_notification_config(
514515
raise ServerError(error=UnsupportedOperationError())
515516

516517
task_id = _extract_task_id(params.name)
518+
config_id = _extract_config_id(params.name)
517519
task: Task | None = await self.task_store.get(task_id, context)
518520
if not task:
519521
raise ServerError(error=TaskNotFoundError())
520522

521-
push_notification_config = await self._push_config_store.get_info(
522-
task_id
523+
push_notification_configs: list[PushNotificationConfig] = (
524+
await self._push_config_store.get_info(task_id) or []
523525
)
524-
if not push_notification_config or not push_notification_config[0]:
525-
raise ServerError(
526-
error=InternalError(
527-
message='Push notification config not found'
526+
527+
for config in push_notification_configs:
528+
if config.id == config_id:
529+
return TaskPushNotificationConfig(
530+
name=params.name,
531+
push_notification_config=config,
528532
)
529-
)
530533

531-
return TaskPushNotificationConfig(
532-
name=params.name,
533-
push_notification_config=push_notification_config[0],
534+
raise ServerError(
535+
error=InternalError(message='Push notification config not found')
534536
)
535537

536538
async def on_subscribe_to_task(

src/a2a/server/request_handlers/grpc_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
HTTP_EXTENSION_HEADER,
2929
get_requested_extensions,
3030
)
31-
from a2a.server.apps.jsonrpc.errors import JSONParseError
3231
from a2a.server.context import ServerCallContext
32+
from a2a.server.jsonrpc_models import JSONParseError
3333
from a2a.server.request_handlers.request_handler import RequestHandler
3434
from a2a.types import a2a_pb2
3535
from a2a.types.a2a_pb2 import AgentCard

src/a2a/server/request_handlers/jsonrpc_handler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
from google.protobuf.json_format import MessageToDict
99
from jsonrpc.jsonrpc2 import JSONRPC20Response
1010

11-
from a2a.server.apps.jsonrpc.errors import (
11+
from a2a.server.context import ServerCallContext
12+
from a2a.server.jsonrpc_models import (
1213
InternalError as JSONRPCInternalError,
1314
)
14-
from a2a.server.apps.jsonrpc.errors import (
15+
from a2a.server.jsonrpc_models import (
1516
JSONRPCError,
1617
)
17-
from a2a.server.context import ServerCallContext
1818
from a2a.server.request_handlers.request_handler import RequestHandler
1919
from a2a.types.a2a_pb2 import (
2020
AgentCard,

src/a2a/server/request_handlers/response_helpers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
from google.protobuf.message import Message as ProtoMessage
77
from jsonrpc.jsonrpc2 import JSONRPC20Response
88

9-
from a2a.server.apps.jsonrpc.errors import (
9+
from a2a.server.jsonrpc_models import (
1010
InternalError as JSONRPCInternalError,
1111
)
12-
from a2a.server.apps.jsonrpc.errors import (
12+
from a2a.server.jsonrpc_models import (
1313
JSONRPCError,
1414
)
1515
from a2a.types.a2a_pb2 import (

src/a2a/utils/error_handlers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
Response = Any
1616

1717

18-
from a2a.server.apps.jsonrpc.errors import (
18+
from a2a.server.jsonrpc_models import (
1919
InternalError as JSONRPCInternalError,
2020
)
21-
from a2a.server.apps.jsonrpc.errors import (
21+
from a2a.server.jsonrpc_models import (
2222
JSONParseError,
2323
JSONRPCError,
2424
)

tests/server/apps/jsonrpc/test_serialization.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from starlette.testclient import TestClient
77

88
from a2a.server.apps import A2AFastAPIApplication, A2AStarletteApplication
9-
from a2a.server.apps.jsonrpc.errors import JSONParseError
9+
from a2a.server.jsonrpc_models import JSONParseError
1010
from a2a.types import (
1111
InvalidRequestError,
1212
)

tests/server/events/test_event_consumer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from a2a.server.events.event_consumer import EventConsumer, QueueClosed
99
from a2a.server.events.event_queue import EventQueue
10-
from a2a.server.apps.jsonrpc.errors import JSONRPCError
10+
from a2a.server.jsonrpc_models import JSONRPCError
1111
from a2a.types import (
1212
InternalError,
1313
)

tests/server/events/test_event_queue.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import pytest
1212

1313
from a2a.server.events.event_queue import DEFAULT_MAX_QUEUE_SIZE, EventQueue
14-
from a2a.server.apps.jsonrpc.errors import JSONRPCError
14+
from a2a.server.jsonrpc_models import JSONRPCError
1515
from a2a.types import (
1616
TaskNotFoundError,
1717
)

0 commit comments

Comments
 (0)