agent-client-protocol 1.0.0rc2__tar.gz → 1.0.0rc3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/PKG-INFO +1 -1
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/pyproject.toml +1 -1
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/scripts/gen_meta.py +2 -1
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/scripts/gen_schema.py +2 -1
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/_transport.py +4 -1
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/agent/connection.py +4 -4
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/connection.py +76 -14
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/contrib/permissions.py +5 -2
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/exceptions.py +4 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/experimental/negotiation.py +3 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/experimental/v2/agent.py +2 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/http/asgi.py +5 -1
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/http/client.py +4 -3
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/http/protocol.py +7 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/http/server.py +16 -6
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/interfaces.py +2 -4
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/stdio.py +1 -1
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/transports.py +2 -8
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/ws/server.py +13 -2
- agent_client_protocol-1.0.0rc3/tests/contrib/test_contrib_permissions.py +118 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/http/test_loopback.py +40 -0
- agent_client_protocol-1.0.0rc3/tests/http/test_v2_loopback.py +226 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/http/test_websocket.py +26 -0
- agent_client_protocol-1.0.0rc3/tests/real_user/test_stdio_shutdown.py +69 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/test_connection_recovery.py +28 -0
- agent_client_protocol-1.0.0rc3/tests/test_request_cancellation.py +459 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/test_unstable.py +13 -1
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/test_v2_runtime.py +67 -0
- agent_client_protocol-1.0.0rc2/tests/contrib/test_contrib_permissions.py +0 -64
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/LICENSE +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/README.md +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/examples/agent.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/examples/client.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/examples/duet.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/examples/echo_agent.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/examples/gemini.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/examples/http_client.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/examples/http_server.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/examples/ws_client.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/scripts/__init__.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/scripts/_schema_semantics.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/scripts/gen_all.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/scripts/gen_schema_v1.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/scripts/gen_schema_v2.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/scripts/gen_signature.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/__init__.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/_cookies.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/_deserialize.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/_protocol_adapters.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/_schema_base.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/_sse.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/agent/__init__.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/agent/router.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/client/__init__.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/client/connection.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/client/router.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/contrib/__init__.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/contrib/session_state.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/contrib/tool_calls.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/core.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/experimental/__init__.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/experimental/v2/__init__.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/experimental/v2/_connection.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/experimental/v2/_initialization.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/experimental/v2/_methods.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/experimental/v2/_params.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/experimental/v2/_router.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/experimental/v2/_schema_base.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/experimental/v2/client.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/experimental/v2/interfaces.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/experimental/v2/meta.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/experimental/v2/schema.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/http/__init__.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/meta.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/py.typed +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/router.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/schema.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/task/__init__.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/task/sender.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/task/supervisor.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/telemetry.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/utils.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/ws/__init__.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/ws/client.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/conftest.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/contrib/test_contrib_session_state.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/contrib/test_contrib_tool_calls.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/golden/cancel_notification.json +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/golden/content_audio.json +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/golden/content_image.json +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/golden/content_resource_blob.json +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/golden/content_resource_link.json +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/golden/content_resource_text.json +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/golden/content_text.json +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/golden/fs_read_text_file_request.json +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/golden/fs_read_text_file_response.json +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/golden/fs_write_text_file_request.json +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/golden/initialize_request.json +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/golden/initialize_response.json +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/golden/new_session_request.json +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/golden/new_session_response.json +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/golden/permission_outcome_cancelled.json +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/golden/permission_outcome_selected.json +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/golden/prompt_request.json +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/golden/request_permission_request.json +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/golden/request_permission_response_selected.json +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/golden/session_update_agent_message_chunk.json +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/golden/session_update_agent_thought_chunk.json +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/golden/session_update_compaction_summary_chunk.json +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/golden/session_update_compaction_update.json +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/golden/session_update_config_option_update.json +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/golden/session_update_plan.json +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/golden/session_update_tool_call.json +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/golden/session_update_tool_call_edit.json +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/golden/session_update_tool_call_locations_rawinput.json +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/golden/session_update_tool_call_read.json +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/golden/session_update_tool_call_update_content.json +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/golden/session_update_tool_call_update_more_fields.json +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/golden/session_update_user_message_chunk.json +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/golden/set_session_config_option_request.json +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/golden/set_session_config_option_response.json +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/golden/tool_content_content_text.json +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/golden/tool_content_diff.json +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/golden/tool_content_diff_no_old.json +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/golden/tool_content_terminal.json +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/http/conftest.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/http/test_asgi.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/http/test_cookies.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/http/test_fixes.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/http/test_http_client.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/http/test_http_server.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/http/test_protocol.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/http/test_sse.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/http/test_ws_cookies.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/real_user/__init__.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/real_user/test_cancel_prompt_flow.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/real_user/test_mcp_servers_optional.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/real_user/test_permission_flow.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/real_user/test_stdio_limits.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/test_compatibility.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/test_core.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/test_deserialize.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/test_elicitation_catchall.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/test_gemini_example.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/test_gen_all.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/test_golden.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/test_param_model.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/test_protocol_method_coverage.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/test_protocol_negotiation.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/test_protocol_router.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/test_request_error_logging.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/test_rpc.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/test_utils.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/test_v2_routing.py +0 -0
- {agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/tests/test_v2_schema.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: agent-client-protocol
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.0rc3
|
|
4
4
|
Summary: A Python implement of Agent Client Protocol (ACP, by Zed Industries)
|
|
5
5
|
Keywords: python
|
|
6
6
|
Author-Email: Chojan Shang <psiace@apache.org>, Frost Ming <me@frostming.com>
|
|
@@ -56,7 +56,7 @@ def render_meta(*, protocol_version: int = 1) -> str:
|
|
|
56
56
|
client_methods = data.get("clientMethods", {})
|
|
57
57
|
protocol_methods = data.get("protocolMethods")
|
|
58
58
|
version = data.get("version", 1)
|
|
59
|
-
header_lines = [f"# Generated from {meta_json.relative_to(ROOT)}. Do not edit by hand."]
|
|
59
|
+
header_lines = [f"# Generated from {meta_json.relative_to(ROOT).as_posix()}. Do not edit by hand."]
|
|
60
60
|
if version_file.exists():
|
|
61
61
|
ref = version_file.read_text("utf-8").strip()
|
|
62
62
|
if ref:
|
|
@@ -74,6 +74,7 @@ def render_meta(*, protocol_version: int = 1) -> str:
|
|
|
74
74
|
[sys.executable, "-m", "ruff", "format", "--stdin-filename", str(out_py), "-"],
|
|
75
75
|
input=source,
|
|
76
76
|
text=True,
|
|
77
|
+
encoding="utf-8",
|
|
77
78
|
capture_output=True,
|
|
78
79
|
check=False,
|
|
79
80
|
cwd=ROOT,
|
|
@@ -176,7 +176,7 @@ def _deserialize_field_specs(definition: dict[str, Any]) -> tuple[list[str], lis
|
|
|
176
176
|
|
|
177
177
|
|
|
178
178
|
def _build_header(schema_json: Path, version_file: Path) -> str:
|
|
179
|
-
lines = [f"# Generated from {schema_json.relative_to(ROOT)}. Do not edit by hand."]
|
|
179
|
+
lines = [f"# Generated from {schema_json.relative_to(ROOT).as_posix()}. Do not edit by hand."]
|
|
180
180
|
if version_file.exists() and (ref := version_file.read_text(encoding="utf-8").strip()):
|
|
181
181
|
lines.append(f"# Schema ref: {ref}")
|
|
182
182
|
return "\n".join(lines)
|
|
@@ -192,6 +192,7 @@ def _format_python(source: str, schema_out: Path) -> str:
|
|
|
192
192
|
[sys.executable, "-m", "ruff", *arguments, "--stdin-filename", str(schema_out), "-"],
|
|
193
193
|
input=source,
|
|
194
194
|
text=True,
|
|
195
|
+
encoding="utf-8",
|
|
195
196
|
capture_output=True,
|
|
196
197
|
check=False,
|
|
197
198
|
cwd=ROOT,
|
|
@@ -79,10 +79,13 @@ class NdjsonTransport:
|
|
|
79
79
|
if not line:
|
|
80
80
|
continue
|
|
81
81
|
try:
|
|
82
|
-
message
|
|
82
|
+
message = json.loads(line)
|
|
83
83
|
except Exception:
|
|
84
84
|
logging.exception("Error parsing JSON-RPC message")
|
|
85
85
|
continue
|
|
86
|
+
if not isinstance(message, dict):
|
|
87
|
+
logging.warning("Ignoring non-object JSON-RPC message")
|
|
88
|
+
continue
|
|
86
89
|
return message
|
|
87
90
|
|
|
88
91
|
async def close(self) -> None:
|
{agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/agent/connection.py
RENAMED
|
@@ -8,7 +8,7 @@ from pydantic import TypeAdapter
|
|
|
8
8
|
|
|
9
9
|
from .._transport import Transport
|
|
10
10
|
from ..connection import Connection, MethodHandler
|
|
11
|
-
from ..interfaces import Agent
|
|
11
|
+
from ..interfaces import Agent
|
|
12
12
|
from ..meta import CLIENT_METHODS
|
|
13
13
|
from ..schema import (
|
|
14
14
|
AcceptElicitationResponse,
|
|
@@ -95,7 +95,7 @@ class AgentSideConnection:
|
|
|
95
95
|
|
|
96
96
|
def __init__(
|
|
97
97
|
self,
|
|
98
|
-
to_agent: Callable[[
|
|
98
|
+
to_agent: Callable[[AgentSideConnection], Agent] | Agent,
|
|
99
99
|
input_stream: Any,
|
|
100
100
|
output_stream: Any = None,
|
|
101
101
|
listening: bool = True,
|
|
@@ -119,7 +119,7 @@ class AgentSideConnection:
|
|
|
119
119
|
@classmethod
|
|
120
120
|
def attach(
|
|
121
121
|
cls,
|
|
122
|
-
to_agent: Callable[[
|
|
122
|
+
to_agent: Callable[[AgentSideConnection], Agent] | Agent,
|
|
123
123
|
connection: Connection,
|
|
124
124
|
*,
|
|
125
125
|
use_unstable_protocol: bool = False,
|
|
@@ -133,7 +133,7 @@ class AgentSideConnection:
|
|
|
133
133
|
|
|
134
134
|
def _prepare(
|
|
135
135
|
self,
|
|
136
|
-
to_agent: Callable[[
|
|
136
|
+
to_agent: Callable[[AgentSideConnection], Agent] | Agent,
|
|
137
137
|
*,
|
|
138
138
|
use_unstable_protocol: bool,
|
|
139
139
|
) -> tuple[Agent, MethodHandler]:
|
|
@@ -14,6 +14,7 @@ from pydantic import BaseModel, ValidationError
|
|
|
14
14
|
|
|
15
15
|
from ._transport import NdjsonTransport, Transport
|
|
16
16
|
from .exceptions import RequestError
|
|
17
|
+
from .meta import PROTOCOL_METHODS
|
|
17
18
|
from .task import MessageSender, TaskSupervisor
|
|
18
19
|
from .telemetry import span_context
|
|
19
20
|
|
|
@@ -37,6 +38,13 @@ class StreamEvent:
|
|
|
37
38
|
|
|
38
39
|
StreamObserver = Callable[[StreamEvent], Awaitable[None] | None]
|
|
39
40
|
|
|
41
|
+
_CANCEL_REQUEST_METHOD = PROTOCOL_METHODS["cancel_request"]
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _is_request_id(value: Any) -> bool:
|
|
45
|
+
"""Whether ``value`` is a JSON-RPC ``RequestId``: ``null``, an integer or a string."""
|
|
46
|
+
return value is None or isinstance(value, str) or (isinstance(value, int) and not isinstance(value, bool))
|
|
47
|
+
|
|
40
48
|
|
|
41
49
|
class Connection:
|
|
42
50
|
"""Minimal JSON-RPC 2.0 connection over newline-delimited JSON frames."""
|
|
@@ -54,6 +62,7 @@ class Connection:
|
|
|
54
62
|
self._handler = handler
|
|
55
63
|
self._next_request_id = 0
|
|
56
64
|
self._pending: dict[int, asyncio.Future[Any]] = {}
|
|
65
|
+
self._incoming: dict[Any, asyncio.Task[Any]] = {}
|
|
57
66
|
self._tasks = TaskSupervisor(source="acp.Connection")
|
|
58
67
|
self._tasks.add_error_handler(self._on_task_error)
|
|
59
68
|
self._closed = False
|
|
@@ -117,16 +126,14 @@ class Connection:
|
|
|
117
126
|
payload = {"jsonrpc": "2.0", "id": request_id, "method": method, "params": params}
|
|
118
127
|
try:
|
|
119
128
|
await self._transport.send(payload)
|
|
120
|
-
|
|
121
|
-
self._pending.pop(request_id, None)
|
|
122
|
-
future.cancel()
|
|
123
|
-
raise
|
|
124
|
-
self._notify_observers(StreamDirection.OUTGOING, payload)
|
|
125
|
-
try:
|
|
129
|
+
self._notify_observers(StreamDirection.OUTGOING, payload)
|
|
126
130
|
return await future
|
|
127
|
-
except
|
|
128
|
-
self._pending.pop(request_id, None)
|
|
131
|
+
except BaseException as exc:
|
|
132
|
+
still_pending = self._pending.pop(request_id, None) is not None
|
|
129
133
|
future.cancel()
|
|
134
|
+
if isinstance(exc, asyncio.CancelledError) and still_pending:
|
|
135
|
+
# The request may already be on the wire; ask the peer to stop working on it.
|
|
136
|
+
self._send_cancel_request(request_id)
|
|
130
137
|
raise
|
|
131
138
|
|
|
132
139
|
async def send_notification(self, method: str, params: JsonValue | None = None) -> None:
|
|
@@ -152,13 +159,20 @@ class Connection:
|
|
|
152
159
|
def _process_message(self, message: dict[str, Any]) -> None:
|
|
153
160
|
method = message.get("method")
|
|
154
161
|
has_id = "id" in message
|
|
162
|
+
if method == _CANCEL_REQUEST_METHOD and not has_id:
|
|
163
|
+
self._cancel_incoming(message.get("params"))
|
|
164
|
+
return
|
|
155
165
|
if method is not None: # this is a request or notification
|
|
156
166
|
# {"jsonrpc": "2.0", "id": 1, "method": "foo", "params": {...}} # request
|
|
157
167
|
# {"jsonrpc": "2.0", "method": "foo", "params: {...}} # notification
|
|
158
|
-
|
|
159
|
-
self.
|
|
160
|
-
|
|
161
|
-
|
|
168
|
+
if not has_id:
|
|
169
|
+
self._tasks.create(self._run_notification(message), name="acp.Connection.notification")
|
|
170
|
+
return
|
|
171
|
+
# The handler gets its own task so ``$/cancel_request`` can cancel it, even before it
|
|
172
|
+
# starts, without also cancelling delivery of the response the peer still expects.
|
|
173
|
+
handler = self._tasks.create(self._execute_request(message), name="acp.Connection.request")
|
|
174
|
+
self._track_incoming(message["id"], handler)
|
|
175
|
+
self._tasks.create(self._run_request(message, handler), name="acp.Connection.response")
|
|
162
176
|
return
|
|
163
177
|
if has_id: # this is a response, {"id", "result" | "error"}
|
|
164
178
|
self._handle_response(message)
|
|
@@ -184,8 +198,56 @@ class Connection:
|
|
|
184
198
|
def _on_observer_error(self, task: asyncio.Task[Any], exc: BaseException) -> None:
|
|
185
199
|
logging.exception("Stream observer coroutine failed", exc_info=exc)
|
|
186
200
|
|
|
187
|
-
|
|
188
|
-
|
|
201
|
+
def _track_incoming(self, request_id: Any, task: asyncio.Task[Any]) -> None:
|
|
202
|
+
# A ``$/cancel_request`` can only name a valid request id, and Python would alias an invalid
|
|
203
|
+
# one such as ``true`` or ``1.0`` with the integer ``1``.
|
|
204
|
+
if not _is_request_id(request_id):
|
|
205
|
+
return
|
|
206
|
+
self._incoming[request_id] = task
|
|
207
|
+
|
|
208
|
+
def _forget(done: asyncio.Task[Any]) -> None:
|
|
209
|
+
if self._incoming.get(request_id) is done:
|
|
210
|
+
del self._incoming[request_id]
|
|
211
|
+
|
|
212
|
+
task.add_done_callback(_forget)
|
|
213
|
+
|
|
214
|
+
def _cancel_incoming(self, params: Any) -> None:
|
|
215
|
+
# ``requestId`` is required and may be ``null``, so a missing one must not match a ``null`` id.
|
|
216
|
+
if not isinstance(params, dict) or "requestId" not in params:
|
|
217
|
+
return
|
|
218
|
+
request_id = params["requestId"]
|
|
219
|
+
if not _is_request_id(request_id):
|
|
220
|
+
return
|
|
221
|
+
# Unknown or already finished requests are ignored, as the protocol allows.
|
|
222
|
+
task = self._incoming.get(request_id)
|
|
223
|
+
if task is not None:
|
|
224
|
+
task.cancel()
|
|
225
|
+
|
|
226
|
+
def _send_cancel_request(self, request_id: int) -> None:
|
|
227
|
+
if self._closed or self._disconnected:
|
|
228
|
+
return
|
|
229
|
+
self._tasks.create(
|
|
230
|
+
self.send_notification(_CANCEL_REQUEST_METHOD, {"requestId": request_id}),
|
|
231
|
+
name="acp.Connection.cancel_request",
|
|
232
|
+
on_error=self._on_cancel_request_error,
|
|
233
|
+
)
|
|
234
|
+
|
|
235
|
+
def _on_cancel_request_error(self, task: asyncio.Task[Any], exc: BaseException) -> None:
|
|
236
|
+
logging.debug("Failed to send %s", _CANCEL_REQUEST_METHOD, exc_info=exc)
|
|
237
|
+
|
|
238
|
+
async def _run_request(
|
|
239
|
+
self, message: dict[str, Any], handler: asyncio.Future[dict[str, Any]] | None = None
|
|
240
|
+
) -> None:
|
|
241
|
+
if handler is None:
|
|
242
|
+
handler = self._tasks.create(self._execute_request(message), name="acp.Connection.request")
|
|
243
|
+
# Unlike ``await handler``, ``asyncio.wait`` does not re-raise the handler's cancellation, and
|
|
244
|
+
# ``$/cancel_request`` only targets the handler, so only ``close()`` can abandon the response.
|
|
245
|
+
await asyncio.wait({handler})
|
|
246
|
+
if handler.cancelled():
|
|
247
|
+
# Cancelled by ``$/cancel_request`` or from inside the handler.
|
|
248
|
+
payload = {"jsonrpc": "2.0", "id": message["id"], "error": RequestError.request_cancelled().to_error_obj()}
|
|
249
|
+
else:
|
|
250
|
+
payload = handler.result()
|
|
189
251
|
await self._transport.send(payload)
|
|
190
252
|
self._notify_observers(StreamDirection.OUTGOING, payload)
|
|
191
253
|
|
{agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/contrib/permissions.py
RENAMED
|
@@ -56,7 +56,8 @@ class PermissionBroker:
|
|
|
56
56
|
self._requester = requester
|
|
57
57
|
self._tracker = tracker
|
|
58
58
|
self._default_options = tuple(
|
|
59
|
-
option.model_copy(deep=True)
|
|
59
|
+
option.model_copy(deep=True)
|
|
60
|
+
for option in (default_permission_options() if default_options is None else default_options)
|
|
60
61
|
)
|
|
61
62
|
|
|
62
63
|
async def request_for(
|
|
@@ -84,7 +85,9 @@ class PermissionBroker:
|
|
|
84
85
|
existing.append(ContentToolCallContent(content=TextContentBlock(text=description)))
|
|
85
86
|
tool_call.content = existing
|
|
86
87
|
|
|
87
|
-
option_set = tuple(
|
|
88
|
+
option_set = tuple(
|
|
89
|
+
option.model_copy(deep=True) for option in (self._default_options if options is None else options)
|
|
90
|
+
)
|
|
88
91
|
if not option_set:
|
|
89
92
|
raise MissingPermissionOptionsError()
|
|
90
93
|
|
|
@@ -42,5 +42,9 @@ class RequestError(Exception):
|
|
|
42
42
|
data = {"uri": uri} if uri is not None else None
|
|
43
43
|
return cls(-32002, "Resource not found", data)
|
|
44
44
|
|
|
45
|
+
@classmethod
|
|
46
|
+
def request_cancelled(cls, data: dict[str, Any] | None = None) -> RequestError:
|
|
47
|
+
return cls(-32800, "Request cancelled", data)
|
|
48
|
+
|
|
45
49
|
def to_error_obj(self) -> dict[str, Any]:
|
|
46
50
|
return {"code": self.code, "message": str(self), "data": self.data}
|
{agent_client_protocol-1.0.0rc2 → agent_client_protocol-1.0.0rc3}/src/acp/experimental/v2/agent.py
RENAMED
|
@@ -84,6 +84,8 @@ class AgentSideConnection:
|
|
|
84
84
|
self._state = InitializationState()
|
|
85
85
|
self._conn = connection
|
|
86
86
|
agent = agent_factory(self)
|
|
87
|
+
if on_connect := getattr(agent, "on_connect", None):
|
|
88
|
+
on_connect(self)
|
|
87
89
|
router = _AgentRouter(agent, self._state)
|
|
88
90
|
return self, router
|
|
89
91
|
|
|
@@ -10,6 +10,7 @@ import json
|
|
|
10
10
|
from collections.abc import AsyncIterator
|
|
11
11
|
from contextlib import asynccontextmanager
|
|
12
12
|
from functools import partial
|
|
13
|
+
from typing import TYPE_CHECKING
|
|
13
14
|
|
|
14
15
|
from starlette.applications import Starlette
|
|
15
16
|
from starlette.requests import Request
|
|
@@ -21,10 +22,13 @@ from ..ws.server import handle_websocket
|
|
|
21
22
|
from .protocol import ACP_ENDPOINT_PATH, CONNECTION_ID_HEADER, CONTENT_TYPE_SSE, SESSION_ID_HEADER
|
|
22
23
|
from .server import AcpServer, AgentFactory
|
|
23
24
|
|
|
25
|
+
if TYPE_CHECKING:
|
|
26
|
+
from ..experimental.negotiation import AgentProtocolRouter
|
|
27
|
+
|
|
24
28
|
__all__ = ["create_asgi_app"]
|
|
25
29
|
|
|
26
30
|
|
|
27
|
-
def create_asgi_app(agent_factory: AgentFactory, *, path: str = ACP_ENDPOINT_PATH) -> Starlette:
|
|
31
|
+
def create_asgi_app(agent_factory: AgentFactory | AgentProtocolRouter, *, path: str = ACP_ENDPOINT_PATH) -> Starlette:
|
|
28
32
|
"""Create a Starlette app with one agent instance per connection.
|
|
29
33
|
|
|
30
34
|
The app handles POST/GET/DELETE and WebSocket at ``path`` (default: /acp).
|
|
@@ -28,7 +28,7 @@ from .protocol import (
|
|
|
28
28
|
CONNECTION_ID_HEADER,
|
|
29
29
|
CONTENT_TYPE_JSON,
|
|
30
30
|
CONTENT_TYPE_SSE,
|
|
31
|
-
|
|
31
|
+
SESSION_ATTACH_METHODS,
|
|
32
32
|
SESSION_ID_HEADER,
|
|
33
33
|
is_initialize_request,
|
|
34
34
|
is_response_message,
|
|
@@ -81,6 +81,7 @@ class _HttpStreamTransport:
|
|
|
81
81
|
self._inbox: asyncio.Queue[Any] = asyncio.Queue()
|
|
82
82
|
self._stream_tasks: set[asyncio.Task[None]] = set()
|
|
83
83
|
self._session_streams: set[str] = set()
|
|
84
|
+
# Pending session/load and session/resume requests, keyed by request id.
|
|
84
85
|
self._pending_loads: dict[str, str] = {}
|
|
85
86
|
|
|
86
87
|
# -- Transport protocol -------------------------------------------------
|
|
@@ -93,7 +94,7 @@ class _HttpStreamTransport:
|
|
|
93
94
|
return
|
|
94
95
|
key = message_id_key(message.get("id"))
|
|
95
96
|
session_id = session_id_from_message(message)
|
|
96
|
-
if message.get("method")
|
|
97
|
+
if message.get("method") in SESSION_ATTACH_METHODS and key is not None and session_id is not None:
|
|
97
98
|
self._pending_loads[key] = session_id
|
|
98
99
|
try:
|
|
99
100
|
await self._send_post(message)
|
|
@@ -215,7 +216,7 @@ class _HttpStreamTransport:
|
|
|
215
216
|
self._inbox.put_nowait(_EOF)
|
|
216
217
|
|
|
217
218
|
def _handle_incoming(self, message: dict[str, Any]) -> None:
|
|
218
|
-
# Load responses may
|
|
219
|
+
# Load and resume responses may omit sessionId; the ID is in the request.
|
|
219
220
|
if is_response_message(message):
|
|
220
221
|
key = message_id_key(message.get("id"))
|
|
221
222
|
loaded = self._pending_loads.pop(key, None) if key is not None else None
|
|
@@ -18,6 +18,8 @@ __all__ = [
|
|
|
18
18
|
"CONTENT_TYPE_SSE",
|
|
19
19
|
"INITIALIZE_METHOD",
|
|
20
20
|
"LOAD_SESSION_METHOD",
|
|
21
|
+
"RESUME_SESSION_METHOD",
|
|
22
|
+
"SESSION_ATTACH_METHODS",
|
|
21
23
|
"SESSION_ID_HEADER",
|
|
22
24
|
"is_initialize_request",
|
|
23
25
|
"is_response_message",
|
|
@@ -41,6 +43,11 @@ ACP_ENDPOINT_PATH = "/acp"
|
|
|
41
43
|
|
|
42
44
|
INITIALIZE_METHOD = AGENT_METHODS["initialize"]
|
|
43
45
|
LOAD_SESSION_METHOD = AGENT_METHODS["session_load"]
|
|
46
|
+
RESUME_SESSION_METHOD = AGENT_METHODS["session_resume"]
|
|
47
|
+
|
|
48
|
+
# Methods that attach the ``sessionId`` given in their request. Their responses
|
|
49
|
+
# need not echo the ID, so both peers take it from the request.
|
|
50
|
+
SESSION_ATTACH_METHODS = frozenset({LOAD_SESSION_METHOD, RESUME_SESSION_METHOD})
|
|
44
51
|
|
|
45
52
|
# Agent methods that operate on an *already-established* session and therefore
|
|
46
53
|
# require the ``Acp-Session-Id`` header on POST + session-scoped routing of their
|
|
@@ -33,7 +33,7 @@ from .._sse import serialize_sse_event, serialize_sse_keepalive
|
|
|
33
33
|
from ..agent.connection import AgentSideConnection
|
|
34
34
|
from .protocol import (
|
|
35
35
|
CONNECTION_ID_HEADER,
|
|
36
|
-
|
|
36
|
+
SESSION_ATTACH_METHODS,
|
|
37
37
|
is_initialize_request,
|
|
38
38
|
is_response_message,
|
|
39
39
|
message_id_key,
|
|
@@ -45,6 +45,7 @@ from .protocol import (
|
|
|
45
45
|
if TYPE_CHECKING:
|
|
46
46
|
from collections.abc import AsyncGenerator
|
|
47
47
|
|
|
48
|
+
from ..experimental.negotiation import AgentProtocolConnection, AgentProtocolRouter
|
|
48
49
|
from ..interfaces import Agent
|
|
49
50
|
|
|
50
51
|
__all__ = [
|
|
@@ -139,6 +140,7 @@ class _HttpTransport:
|
|
|
139
140
|
self.connection_stream = OutboundStream()
|
|
140
141
|
self.session_streams: dict[str, OutboundStream] = {}
|
|
141
142
|
self._pending_routes: dict[str, str] = {}
|
|
143
|
+
# Pending session/load and session/resume requests, keyed by request id.
|
|
142
144
|
self._pending_loads: dict[str, str] = {}
|
|
143
145
|
self._provisional_sessions: set[str] = set()
|
|
144
146
|
|
|
@@ -155,7 +157,7 @@ class _HttpTransport:
|
|
|
155
157
|
self.initialize_response.set_result(message)
|
|
156
158
|
return
|
|
157
159
|
session_id = self._route_response(message, key)
|
|
158
|
-
# Replay and load responses share the connection stream, including on
|
|
160
|
+
# Replay and load/resume responses share the connection stream, including on
|
|
159
161
|
# reload. This preserves replay order and never waits for a session GET.
|
|
160
162
|
if session_id in self._pending_loads.values():
|
|
161
163
|
session_id = None
|
|
@@ -191,7 +193,7 @@ class _HttpTransport:
|
|
|
191
193
|
session_id = session_id_from_params(message.get("params"))
|
|
192
194
|
key = message_id_key(message["id"])
|
|
193
195
|
if session_id is not None and key is not None:
|
|
194
|
-
if message["method"]
|
|
196
|
+
if message["method"] in SESSION_ATTACH_METHODS:
|
|
195
197
|
self._pending_loads[key] = session_id
|
|
196
198
|
if session_id not in self.session_streams:
|
|
197
199
|
# Allow clients to open a GET as soon as replay starts.
|
|
@@ -223,9 +225,17 @@ class AcpServer:
|
|
|
223
225
|
``AgentSideConnection`` to produce a per-connection ``Agent``.
|
|
224
226
|
"""
|
|
225
227
|
|
|
226
|
-
def __init__(self, agent_factory: AgentFactory) -> None:
|
|
228
|
+
def __init__(self, agent_factory: AgentFactory | AgentProtocolRouter) -> None:
|
|
227
229
|
self.agent_factory = agent_factory
|
|
228
|
-
self._connections: dict[str, tuple[AgentSideConnection, _HttpTransport]] = {}
|
|
230
|
+
self._connections: dict[str, tuple[AgentSideConnection | AgentProtocolConnection, _HttpTransport]] = {}
|
|
231
|
+
|
|
232
|
+
def _connect(self, transport: _HttpTransport) -> AgentSideConnection | AgentProtocolConnection:
|
|
233
|
+
"""Bind one agent (v1) or protocol router (v1/v2) to a transport."""
|
|
234
|
+
from ..experimental.negotiation import AgentProtocolRouter
|
|
235
|
+
|
|
236
|
+
if isinstance(self.agent_factory, AgentProtocolRouter):
|
|
237
|
+
return self.agent_factory.connect(transport)
|
|
238
|
+
return AgentSideConnection(self.agent_factory, transport)
|
|
229
239
|
|
|
230
240
|
# -- POST ---------------------------------------------------------------
|
|
231
241
|
|
|
@@ -267,7 +277,7 @@ class AcpServer:
|
|
|
267
277
|
async def _handle_initialize(self, message: dict[str, Any]) -> Response:
|
|
268
278
|
connection_id = uuid.uuid4().hex
|
|
269
279
|
transport = _HttpTransport(message.get("id"))
|
|
270
|
-
conn =
|
|
280
|
+
conn = self._connect(transport)
|
|
271
281
|
self._connections[connection_id] = (conn, transport)
|
|
272
282
|
# Deliver initialize to the agent and await its response so we can return
|
|
273
283
|
# the 200 body synchronously (initialize is the one blocking POST). If the
|
|
@@ -445,7 +445,7 @@ class Agent(Protocol):
|
|
|
445
445
|
**kwargs: Any,
|
|
446
446
|
) -> ForkSessionResponse: ...
|
|
447
447
|
|
|
448
|
-
@param_model(ResumeSessionRequest, method=AGENT_METHODS["session_resume"]
|
|
448
|
+
@param_model(ResumeSessionRequest, method=AGENT_METHODS["session_resume"])
|
|
449
449
|
async def resume_session(
|
|
450
450
|
self,
|
|
451
451
|
session_id: str,
|
|
@@ -455,9 +455,7 @@ class Agent(Protocol):
|
|
|
455
455
|
**kwargs: Any,
|
|
456
456
|
) -> ResumeSessionResponse: ...
|
|
457
457
|
|
|
458
|
-
@param_model(
|
|
459
|
-
CloseSessionRequest, method=AGENT_METHODS["session_close"], unstable=True, adapt_result=normalize_result
|
|
460
|
-
)
|
|
458
|
+
@param_model(CloseSessionRequest, method=AGENT_METHODS["session_close"], adapt_result=normalize_result)
|
|
461
459
|
async def close_session(self, session_id: str, **kwargs: Any) -> CloseSessionResponse | None: ...
|
|
462
460
|
|
|
463
461
|
@param_model(CancelNotification, method=AGENT_METHODS["session_cancel"], kind="notification")
|
|
@@ -185,7 +185,7 @@ async def spawn_agent_process(
|
|
|
185
185
|
|
|
186
186
|
@asynccontextmanager
|
|
187
187
|
async def spawn_client_process(
|
|
188
|
-
to_agent: Callable[[
|
|
188
|
+
to_agent: Callable[[AgentSideConnection], Agent] | Agent,
|
|
189
189
|
command: str,
|
|
190
190
|
*args: str,
|
|
191
191
|
env: Mapping[str, str] | None = None,
|
|
@@ -58,6 +58,7 @@ async def spawn_stdio_transport(
|
|
|
58
58
|
|
|
59
59
|
This mirrors the defensive shutdown behaviour used by the MCP Python SDK:
|
|
60
60
|
close stdin first, wait for graceful exit, then escalate to terminate/kill.
|
|
61
|
+
Stdin closure uses the same timeout as the waits before terminate/kill.
|
|
61
62
|
"""
|
|
62
63
|
merged_env = dict(default_environment())
|
|
63
64
|
if env:
|
|
@@ -96,16 +97,9 @@ async def spawn_stdio_transport(
|
|
|
96
97
|
finally:
|
|
97
98
|
# Attempt graceful stdin shutdown first
|
|
98
99
|
if process.stdin is not None:
|
|
99
|
-
try:
|
|
100
|
-
process.stdin.write_eof()
|
|
101
|
-
except (AttributeError, OSError, RuntimeError):
|
|
102
|
-
process.stdin.close()
|
|
103
|
-
with contextlib.suppress(Exception):
|
|
104
|
-
await process.stdin.drain()
|
|
105
100
|
with contextlib.suppress(Exception):
|
|
106
101
|
process.stdin.close()
|
|
107
|
-
|
|
108
|
-
await process.stdin.wait_closed()
|
|
102
|
+
await asyncio.wait_for(process.stdin.wait_closed(), timeout=shutdown_timeout)
|
|
109
103
|
|
|
110
104
|
try:
|
|
111
105
|
await asyncio.wait_for(process.wait(), timeout=shutdown_timeout)
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import json
|
|
6
|
+
import logging
|
|
6
7
|
import uuid
|
|
7
8
|
from typing import TYPE_CHECKING, Any
|
|
8
9
|
|
|
@@ -12,6 +13,7 @@ from ..agent.connection import AgentSideConnection
|
|
|
12
13
|
from ..http.protocol import CONNECTION_ID_HEADER
|
|
13
14
|
|
|
14
15
|
if TYPE_CHECKING:
|
|
16
|
+
from ..experimental.negotiation import AgentProtocolRouter
|
|
15
17
|
from ..http.server import AgentFactory
|
|
16
18
|
|
|
17
19
|
__all__ = ["handle_websocket"]
|
|
@@ -22,6 +24,7 @@ class _WebSocketTransport:
|
|
|
22
24
|
|
|
23
25
|
def __init__(self, websocket: WebSocket) -> None:
|
|
24
26
|
self._ws = websocket
|
|
27
|
+
self._warned_binary = False
|
|
25
28
|
|
|
26
29
|
async def send(self, message: dict[str, Any]) -> None:
|
|
27
30
|
if self._ws.client_state == WebSocketState.DISCONNECTED:
|
|
@@ -34,6 +37,9 @@ class _WebSocketTransport:
|
|
|
34
37
|
if event["type"] == "websocket.disconnect":
|
|
35
38
|
return None
|
|
36
39
|
if event.get("text") is None:
|
|
40
|
+
if event.get("bytes") is not None and not self._warned_binary:
|
|
41
|
+
self._warned_binary = True
|
|
42
|
+
logging.warning("Ignoring binary WebSocket frame; ACP messages must be sent as text frames")
|
|
37
43
|
continue
|
|
38
44
|
try:
|
|
39
45
|
message = json.loads(event["text"])
|
|
@@ -48,11 +54,16 @@ class _WebSocketTransport:
|
|
|
48
54
|
await self._ws.close()
|
|
49
55
|
|
|
50
56
|
|
|
51
|
-
async def handle_websocket(agent_factory: AgentFactory, websocket: WebSocket) -> None:
|
|
57
|
+
async def handle_websocket(agent_factory: AgentFactory | AgentProtocolRouter, websocket: WebSocket) -> None:
|
|
52
58
|
"""Run one agent for the lifetime of the socket; disconnect cancels its work."""
|
|
53
59
|
await websocket.accept(headers=[(CONNECTION_ID_HEADER.lower().encode(), uuid.uuid4().hex.encode())])
|
|
54
60
|
transport = _WebSocketTransport(websocket)
|
|
55
|
-
|
|
61
|
+
from ..experimental.negotiation import AgentProtocolRouter
|
|
62
|
+
|
|
63
|
+
if isinstance(agent_factory, AgentProtocolRouter):
|
|
64
|
+
conn = agent_factory.connect(transport, listening=False)
|
|
65
|
+
else:
|
|
66
|
+
conn = AgentSideConnection(agent_factory, transport, listening=False)
|
|
56
67
|
try:
|
|
57
68
|
await conn.listen()
|
|
58
69
|
finally:
|