diff --git a/src/acp/agent/connection.py b/src/acp/agent/connection.py index b0f4d9f7..c9f6d808 100644 --- a/src/acp/agent/connection.py +++ b/src/acp/agent/connection.py @@ -11,7 +11,6 @@ from ..interfaces import Agent from ..meta import CLIENT_METHODS from ..schema import ( - AcceptElicitationResponse, AgentMessageChunk, AgentPlanContentUpdate, AgentPlanRemovedUpdate, @@ -20,7 +19,6 @@ AuthAccount, AuthStatusUpdateNotification, AvailableCommandsUpdate, - CancelElicitationResponse, CompleteElicitationNotification, ConfigOptionUpdate, CreateElicitationResponse, @@ -33,7 +31,6 @@ CreateUrlRequestElicitationRequest, CreateUrlSessionElicitationRequest, CurrentModeUpdate, - DeclineElicitationResponse, ElicitationFormRequestMode, ElicitationFormSessionMode, ElicitationMode, @@ -275,9 +272,7 @@ async def kill_terminal(self, session_id: str, terminal_id: str, **kwargs: Any) KillTerminalResponse, ) - async def create_elicitation( - self, message: str, mode: ElicitationMode, **kwargs: Any - ) -> AcceptElicitationResponse | DeclineElicitationResponse | CancelElicitationResponse: + async def create_elicitation(self, message: str, mode: ElicitationMode, **kwargs: Any) -> CreateElicitationResponse: request = _create_elicitation_request(message, mode, kwargs or None) response = await self._conn.send_request(CLIENT_METHODS["elicitation_create"], serialize_params(request)) return _CREATE_ELICITATION_RESPONSE_ADAPTER.validate_python(response) diff --git a/tests/test_elicitation_catchall.py b/tests/test_elicitation_catchall.py index 7e77e61b..7c35c284 100644 --- a/tests/test_elicitation_catchall.py +++ b/tests/test_elicitation_catchall.py @@ -5,17 +5,23 @@ known values must still resolve to their specific typed variant. """ +from typing import get_type_hints + import pytest from pydantic import TypeAdapter, ValidationError +from acp import Client from acp._protocol_adapters import _mode_from_create_elicitation_request +from acp.agent.connection import AgentSideConnection from acp.exceptions import RequestError from acp.schema import ( AcceptElicitationResponse, CreateElicitationRequest, CreateElicitationResponse, CreateOtherElicitationRequest, + ElicitationFormSessionMode, ElicitationOtherPropertySchema, + ElicitationSchema, ElicitationStringPropertySchema, OtherElicitationResponse, OtherMultiSelectItems, @@ -38,6 +44,31 @@ def test_custom_elicitation_response_falls_back_to_catchall() -> None: assert parsed.model_dump(by_alias=True)["until"] == "later" +def test_elicitation_return_annotation_matches_client() -> None: + client_return = get_type_hints(Client.create_elicitation)["return"] + assert client_return == CreateElicitationResponse + assert get_type_hints(AgentSideConnection.create_elicitation)["return"] == client_return + + +@pytest.mark.asyncio +async def test_custom_elicitation_response_roundtrip(connect, client, monkeypatch: pytest.MonkeyPatch) -> None: + expected = OtherElicitationResponse.model_validate({"action": "x-snooze", "until": "later"}) + + async def create_elicitation(**kwargs) -> OtherElicitationResponse: + return expected + + monkeypatch.setattr(client, "create_elicitation", create_elicitation) + agent_conn, client_conn = connect(use_unstable_protocol=True) + async with agent_conn, client_conn: + response = await agent_conn.create_elicitation( + "Need input", + ElicitationFormSessionMode(session_id="sess", requested_schema=ElicitationSchema(properties={})), + ) + + assert isinstance(response, OtherElicitationResponse) + assert response == expected + + def test_malformed_known_variant_is_rejected_not_catchall() -> None: # A "form" request missing the required requestedSchema must fail validation rather # than silently degrade to the catch-all (restores the schema's dropped `not` clause).