Skip to content

Commit 5ba961e

Browse files
committed
wip
1 parent 6a23a42 commit 5ba961e

20 files changed

Lines changed: 177 additions & 1574 deletions

src/a2a/compat/v0_3/jsonrpc_adapter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
if TYPE_CHECKING:
1111
from starlette.requests import Request
1212

13-
from a2a.server.routes.jsonrpc_dispatcher import CallContextBuilder
1413
from a2a.server.request_handlers.request_handler import RequestHandler
14+
from a2a.server.routes.jsonrpc_dispatcher import CallContextBuilder
1515
from a2a.types.a2a_pb2 import AgentCard
1616

1717
_package_starlette_installed = True

src/a2a/compat/v0_3/rest_adapter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@
3333

3434
from a2a.compat.v0_3 import conversions
3535
from a2a.compat.v0_3.rest_handler import REST03Handler
36+
from a2a.server.context import ServerCallContext
3637
from a2a.server.routes.jsonrpc_dispatcher import (
3738
CallContextBuilder,
3839
DefaultCallContextBuilder,
3940
)
40-
from a2a.server.context import ServerCallContext
4141
from a2a.utils.error_handlers import (
4242
rest_error_handler,
4343
rest_stream_error_handler,

src/a2a/server/routes/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
"""A2A Server Routes."""
22

3-
from a2a.server.routes.agent_card_route import AgentCardRoute
3+
from a2a.server.routes.agent_card_route import AgentCardRoutes
44
from a2a.server.routes.jsonrpc_dispatcher import (
55
CallContextBuilder,
66
DefaultCallContextBuilder,
77
StarletteUserProxy,
88
)
9-
from a2a.server.routes.jsonrpc_route import JsonRpcRoute
9+
from a2a.server.routes.jsonrpc_route import JsonRpcRoutes
1010
from a2a.server.routes.rest_routes import RestRoutes
1111

1212

src/a2a/server/routes/agent_card_route.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
logger = logging.getLogger(__name__)
3737

3838

39-
class AgentCardRoute:
39+
class AgentCardRoutes:
4040
"""Provides the Starlette Route for the A2A protocol agent card endpoint."""
4141

4242
def __init__(
@@ -75,9 +75,11 @@ async def get_agent_card(request: Request) -> Response:
7575
)
7676
return JSONResponse(agent_card_to_dict(card_to_serve))
7777

78-
self.route = Route(
79-
path=card_url,
80-
endpoint=get_agent_card,
81-
methods=['GET'],
82-
middleware=middleware,
83-
)
78+
self.routes = [
79+
Route(
80+
path=card_url,
81+
endpoint=get_agent_card,
82+
methods=['GET'],
83+
middleware=middleware,
84+
)
85+
]

src/a2a/server/routes/jsonrpc_dispatcher.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,9 @@ async def handle_requests(self, request: Request) -> Response: # noqa: PLR0911,
417417
call_context.state['method'] = method
418418
call_context.state['request_id'] = request_id
419419

420-
handler_result: AsyncGenerator[dict[str, Any], None] | dict[str, Any]
420+
handler_result: (
421+
AsyncGenerator[dict[str, Any], None] | dict[str, Any]
422+
)
421423
# Route streaming requests by method name
422424
if method in ('SendStreamingMessage', 'SubscribeToTask'):
423425
handler_result = await self._process_streaming_request(

src/a2a/server/routes/jsonrpc_route.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
logger = logging.getLogger(__name__)
3636

3737

38-
class JsonRpcRoute:
38+
class JsonRpcRoutes:
3939
"""Provides the Starlette Route for the A2A protocol JSON-RPC endpoint.
4040
4141
Handles incoming JSON-RPC requests, routes them to the appropriate
@@ -96,9 +96,11 @@ def __init__( # noqa: PLR0913
9696
enable_v0_3_compat=enable_v0_3_compat,
9797
)
9898

99-
self.route = Route(
100-
path=rpc_url,
101-
endpoint=self.dispatcher.handle_requests,
102-
methods=['POST'],
103-
middleware=middleware,
104-
)
99+
self.routes = [
100+
Route(
101+
path=rpc_url,
102+
endpoint=self.dispatcher.handle_requests,
103+
methods=['POST'],
104+
middleware=middleware,
105+
)
106+
]

src/a2a/server/routes/rest_routes.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ def __init__( # noqa: PLR0913
135135
context_builder=context_builder,
136136
)
137137

138-
139138
self._setup_routes(rpc_url)
140139

141140
def _build_call_context(self, request: Request) -> ServerCallContext:

tck/sut_agent.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
DefaultRequestHandler,
2222
)
2323
from a2a.server.request_handlers.grpc_handler import GrpcHandler
24-
from a2a.server.routes import AgentCardRoute, JsonRpcRoute, RestRoutes
24+
from a2a.server.routes import AgentCardRoutes, JsonRpcRoutes, RestRoutes
2525
from a2a.server.tasks.inmemory_task_store import InMemoryTaskStore
2626
from a2a.server.tasks.task_store import TaskStore
2727
from a2a.types import (
@@ -194,30 +194,30 @@ def serve(task_store: TaskStore) -> None:
194194
task_store=task_store,
195195
)
196196

197-
main_app = Starlette()
198-
199197
# Agent Card
200-
agent_card_router = AgentCardRoute(
198+
agent_card_routes = AgentCardRoutes(
201199
agent_card=agent_card,
202200
card_url=AGENT_CARD_URL,
203201
)
204-
main_app.routes.append(agent_card_router.route)
205-
206202
# JSONRPC
207-
jsonrpc_router = JsonRpcRoute(
203+
jsonrpc_routes = JsonRpcRoutes(
208204
agent_card=agent_card,
209205
request_handler=request_handler,
210206
rpc_url=JSONRPC_URL,
211207
)
212-
main_app.routes.append(jsonrpc_router.route)
213-
214208
# REST
215-
rest_router = RestRoutes(
209+
rest_routes = RestRoutes(
216210
agent_card=agent_card,
217211
request_handler=request_handler,
218212
rpc_url=REST_URL,
219213
)
220-
main_app.routes.extend(rest_router.routes)
214+
215+
routes = [
216+
*agent_card_routes.routes,
217+
*jsonrpc_routes.routes,
218+
*rest_routes.routes,
219+
]
220+
main_app = Starlette(routes=routes)
221221

222222
config = uvicorn.Config(
223223
main_app, host='127.0.0.1', port=http_port, log_level='info'

tests/compat/v0_3/test_jsonrpc_app_compat.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
import pytest
77
from starlette.testclient import TestClient
88

9-
from a2a.server.apps.jsonrpc.starlette_app import A2AStarletteApplication
9+
from starlette.applications import Starlette
10+
from a2a.server.routes import JsonRpcRoutes
1011
from a2a.server.request_handlers.request_handler import RequestHandler
1112
from a2a.types.a2a_pb2 import (
1213
AgentCard,
@@ -50,16 +51,18 @@ def test_app(mock_handler):
5051
mock_agent_card.capabilities.streaming = False
5152
mock_agent_card.capabilities.push_notifications = True
5253
mock_agent_card.capabilities.extended_agent_card = True
53-
return A2AStarletteApplication(
54+
router = JsonRpcRoutes(
5455
agent_card=mock_agent_card,
55-
http_handler=mock_handler,
56+
request_handler=mock_handler,
5657
enable_v0_3_compat=True,
58+
rpc_url='/',
5759
)
60+
return Starlette(routes=router.routes)
5861

5962

6063
@pytest.fixture
6164
def client(test_app):
62-
return TestClient(test_app.build())
65+
return TestClient(test_app)
6366

6467

6568
def test_send_message_v03_compat(

tests/compat/v0_3/test_rest_fastapi_app_compat.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
from google.protobuf import json_format
1010
from httpx import ASGITransport, AsyncClient
1111

12-
from a2a.server.apps.rest.fastapi_app import A2ARESTFastAPIApplication
12+
from starlette.applications import Starlette
13+
from a2a.server.routes import RestRoutes
1314
from a2a.server.request_handlers.request_handler import RequestHandler
1415
from a2a.types.a2a_pb2 import (
1516
AgentCard,
@@ -50,17 +51,19 @@ async def request_handler() -> RequestHandler:
5051
async def app(
5152
agent_card: AgentCard,
5253
request_handler: RequestHandler,
53-
) -> FastAPI:
54-
"""Builds the FastAPI application for testing."""
55-
return A2ARESTFastAPIApplication(
56-
agent_card,
57-
request_handler,
54+
) -> Starlette:
55+
"""Builds the Starlette application for testing."""
56+
rest_routes = RestRoutes(
57+
agent_card=agent_card,
58+
request_handler=request_handler,
5859
enable_v0_3_compat=True,
59-
).build(agent_card_url='/well-known/agent.json', rpc_url='')
60+
rpc_url='',
61+
)
62+
return Starlette(routes=rest_routes.routes)
6063

6164

6265
@pytest.fixture
63-
async def client(app: FastAPI) -> AsyncClient:
66+
async def client(app: Starlette) -> AsyncClient:
6467
return AsyncClient(
6568
transport=ASGITransport(app=app), base_url='http://testapp'
6669
)

0 commit comments

Comments
 (0)