aclientp 0.1.0__py3-none-any.whl

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.
Files changed (112) hide show
  1. aclientp/__init__.py +293 -0
  2. aclientp/__main__.py +10 -0
  3. aclientp/_mime.py +51 -0
  4. aclientp/_tracing.py +26 -0
  5. aclientp/agent/__init__.py +7 -0
  6. aclientp/agent/acp_agent_api.py +225 -0
  7. aclientp/agent/acp_requests.py +279 -0
  8. aclientp/agent/connection.py +350 -0
  9. aclientp/agent/implementations/__init__.py +6 -0
  10. aclientp/agent/implementations/debug_server/__init__.py +1 -0
  11. aclientp/agent/implementations/debug_server/cli.py +79 -0
  12. aclientp/agent/implementations/debug_server/debug.html +229 -0
  13. aclientp/agent/implementations/debug_server/debug_server.py +312 -0
  14. aclientp/agent/implementations/debug_server/mock_agent.py +177 -0
  15. aclientp/agent/implementations/debug_server/models.py +54 -0
  16. aclientp/agent/implementations/testing.py +104 -0
  17. aclientp/agent/notifications.py +512 -0
  18. aclientp/agent/protocol.py +150 -0
  19. aclientp/bridge/README.md +175 -0
  20. aclientp/bridge/__init__.py +7 -0
  21. aclientp/bridge/__main__.py +132 -0
  22. aclientp/bridge/bridge.py +162 -0
  23. aclientp/bridge/py.typed +0 -0
  24. aclientp/bridge/settings.py +15 -0
  25. aclientp/bridge/ws_server.py +157 -0
  26. aclientp/bridge/ws_server_cli.py +89 -0
  27. aclientp/client/__init__.py +7 -0
  28. aclientp/client/connection.py +341 -0
  29. aclientp/client/implementations/__init__.py +7 -0
  30. aclientp/client/implementations/default_client.py +198 -0
  31. aclientp/client/implementations/headless_client.py +274 -0
  32. aclientp/client/implementations/noop_client.py +122 -0
  33. aclientp/client/protocol.py +93 -0
  34. aclientp/connection.py +494 -0
  35. aclientp/exceptions.py +78 -0
  36. aclientp/filesystem.py +567 -0
  37. aclientp/py.typed +0 -0
  38. aclientp/registry/__init__.py +29 -0
  39. aclientp/registry/archive.py +61 -0
  40. aclientp/registry/fetch.py +72 -0
  41. aclientp/registry/model.py +150 -0
  42. aclientp/registry/prepare.py +90 -0
  43. aclientp/router.py +116 -0
  44. aclientp/schema/__init__.py +591 -0
  45. aclientp/schema/agent_plan.py +68 -0
  46. aclientp/schema/agent_requests.py +130 -0
  47. aclientp/schema/agent_responses.py +339 -0
  48. aclientp/schema/base.py +39 -0
  49. aclientp/schema/capabilities.py +448 -0
  50. aclientp/schema/client_requests.py +442 -0
  51. aclientp/schema/client_responses.py +100 -0
  52. aclientp/schema/common.py +177 -0
  53. aclientp/schema/config_options.py +184 -0
  54. aclientp/schema/content_blocks.py +186 -0
  55. aclientp/schema/cursors.py +144 -0
  56. aclientp/schema/elicitation.py +406 -0
  57. aclientp/schema/field_meta.py +598 -0
  58. aclientp/schema/mcp.py +173 -0
  59. aclientp/schema/messages.py +196 -0
  60. aclientp/schema/notifications.py +112 -0
  61. aclientp/schema/protocol_stuff.md +3 -0
  62. aclientp/schema/providers.py +89 -0
  63. aclientp/schema/proxy.py +49 -0
  64. aclientp/schema/session_state.py +72 -0
  65. aclientp/schema/session_updates.py +778 -0
  66. aclientp/schema/slash_commands.py +51 -0
  67. aclientp/schema/terminal.py +15 -0
  68. aclientp/schema/tool_call.py +373 -0
  69. aclientp/schema/v2/__init__.py +774 -0
  70. aclientp/schema/v2/auth.py +160 -0
  71. aclientp/schema/v2/base.py +99 -0
  72. aclientp/schema/v2/capabilities.py +280 -0
  73. aclientp/schema/v2/commands.py +89 -0
  74. aclientp/schema/v2/common.py +252 -0
  75. aclientp/schema/v2/config_options.py +218 -0
  76. aclientp/schema/v2/content.py +169 -0
  77. aclientp/schema/v2/cursors.py +148 -0
  78. aclientp/schema/v2/elicitation.py +345 -0
  79. aclientp/schema/v2/initialize.py +43 -0
  80. aclientp/schema/v2/mcp.py +154 -0
  81. aclientp/schema/v2/messages.py +119 -0
  82. aclientp/schema/v2/permissions.py +142 -0
  83. aclientp/schema/v2/plans.py +95 -0
  84. aclientp/schema/v2/prompt.py +179 -0
  85. aclientp/schema/v2/protocol.py +342 -0
  86. aclientp/schema/v2/providers.py +86 -0
  87. aclientp/schema/v2/session_updates.py +316 -0
  88. aclientp/schema/v2/sessions.py +353 -0
  89. aclientp/schema/v2/subagents.py +61 -0
  90. aclientp/schema/v2/terminals.py +139 -0
  91. aclientp/schema/v2/tool_calls.py +304 -0
  92. aclientp/schema_reference.py +1060 -0
  93. aclientp/stdio.py +261 -0
  94. aclientp/task/__init__.py +59 -0
  95. aclientp/task/debug.py +187 -0
  96. aclientp/task/dispatcher.py +107 -0
  97. aclientp/task/queue.py +69 -0
  98. aclientp/task/sender.py +166 -0
  99. aclientp/task/state.py +91 -0
  100. aclientp/task/supervisor.py +98 -0
  101. aclientp/terminal_handle.py +30 -0
  102. aclientp/tool_call_reporter.py +193 -0
  103. aclientp/tool_call_state.py +175 -0
  104. aclientp/transports.py +445 -0
  105. aclientp/v2/__init__.py +1 -0
  106. aclientp/v2/agent.py +448 -0
  107. aclientp/v2/client.py +356 -0
  108. aclientp-0.1.0.dist-info/METADATA +178 -0
  109. aclientp-0.1.0.dist-info/RECORD +112 -0
  110. aclientp-0.1.0.dist-info/WHEEL +4 -0
  111. aclientp-0.1.0.dist-info/entry_points.txt +10 -0
  112. aclientp-0.1.0.dist-info/licenses/LICENSE +22 -0
aclientp/__init__.py ADDED
@@ -0,0 +1,293 @@
1
+ """Agent Client protocol (ACP) implementation."""
2
+
3
+ # Last synced commit from https://github.com/agentclientprotocol/agent-client-protocol
4
+ SPEC_SYNCED_COMMIT = "4aab69b4e6bcb53965ff5b1141d2f04a62a25c6c"
5
+
6
+ from aclientp.client import DefaultACPClient, HeadlessACPClient, NoOpClient, ClientSideConnection
7
+ from aclientp.agent import AgentSideConnection
8
+ from aclientp.agent.protocol import Agent
9
+ from aclientp.client.protocol import Client
10
+ from aclientp.terminal_handle import TerminalHandle
11
+ from aclientp.tool_call_state import ToolCallState
12
+ from aclientp.schema import (
13
+ ArchiveSessionRequest,
14
+ ArchiveSessionResponse,
15
+ AuthStatusRequest,
16
+ AuthStatusResponse,
17
+ AuthStatusUpdateNotification,
18
+ CancelRequestNotification,
19
+ DeleteSessionRequest,
20
+ DeleteSessionResponse,
21
+ ForkSessionRequest,
22
+ ForkSessionResponse,
23
+ ListSessionsRequest,
24
+ ListSessionsResponse,
25
+ MessageMcpNotification,
26
+ MessageMcpRequest,
27
+ MessageMcpResponse,
28
+ ResumeSessionRequest,
29
+ ResumeSessionResponse,
30
+ SessionOptionsRequest,
31
+ SessionOptionsResponse,
32
+ SessionStatusRequest,
33
+ SessionStatusResponse,
34
+ SetSessionConfigOptionRequest,
35
+ SetSessionConfigOptionResponse,
36
+ SetSessionTitleRequest,
37
+ SetSessionTitleResponse,
38
+ SystemPrompt,
39
+ UnarchiveSessionRequest,
40
+ UnarchiveSessionResponse,
41
+ AgentAuthCapabilities,
42
+ AuthCapabilities,
43
+ AuthMethod,
44
+ AuthMethodAgent,
45
+ AuthMethodTerminal,
46
+ AuthenticateRequest,
47
+ AuthenticateResponse,
48
+ BooleanPropertySchema,
49
+ CancelNotification,
50
+ CreateTerminalRequest,
51
+ ClientCapabilities,
52
+ ElicitationCapabilities,
53
+ ElicitationCompleteNotification,
54
+ ElicitationContentValue,
55
+ ElicitationFormCapabilities,
56
+ ElicitationPropertySchema,
57
+ ElicitationRequest,
58
+ ElicitationResponse,
59
+ ElicitationSchema,
60
+ ElicitationUrlCapabilities,
61
+ EnumOption,
62
+ SessionMode,
63
+ FileSystemCapabilities,
64
+ AgentMessageChunk,
65
+ UserMessageChunk,
66
+ TextContentBlock,
67
+ SessionModeState,
68
+ Implementation,
69
+ ToolCallLocation,
70
+ EnvVariable,
71
+ StdioMcpServer,
72
+ SseMcpServer,
73
+ HttpMcpServer,
74
+ CreateTerminalResponse,
75
+ InitializeRequest,
76
+ IntegerPropertySchema,
77
+ LogoutCapabilities,
78
+ LogoutRequest,
79
+ LogoutResponse,
80
+ PlanEntryPriority,
81
+ PlanEntryStatus,
82
+ InitializeResponse,
83
+ KillTerminalRequest,
84
+ KillTerminalResponse,
85
+ LoadSessionRequest,
86
+ LoadSessionResponse,
87
+ MultiSelectItems,
88
+ MultiSelectPropertySchema,
89
+ NumberPropertySchema,
90
+ AllowedOutcome,
91
+ DeniedOutcome,
92
+ NewSessionRequest,
93
+ NewSessionResponse,
94
+ PromptRequest,
95
+ PromptResponse,
96
+ ReadTextFileRequest,
97
+ ReadTextFileResponse,
98
+ ReleaseTerminalRequest,
99
+ ReleaseTerminalResponse,
100
+ RequestPermissionRequest,
101
+ RequestPermissionResponse,
102
+ StringFormatLiteral,
103
+ StringPropertySchema,
104
+ SessionNotification,
105
+ CloseSessionRequest,
106
+ CloseSessionResponse,
107
+ SetSessionModeRequest,
108
+ SetSessionModeResponse,
109
+ TerminalOutputRequest,
110
+ TerminalOutputResponse,
111
+ WaitForTerminalExitRequest,
112
+ WaitForTerminalExitResponse,
113
+ WriteTextFileRequest,
114
+ WriteTextFileResponse,
115
+ TitledMultiSelectItems,
116
+ UntitledMultiSelectItems,
117
+ PermissionOption,
118
+ PROTOCOL_VERSION,
119
+ AgentMethod,
120
+ ClientMethod,
121
+ Annotations,
122
+ AvailableCommand,
123
+ PlanEntry,
124
+ ToolCallContent,
125
+ ToolCallKind,
126
+ ToolCallStatus,
127
+ ToolCallUpdate,
128
+ )
129
+ from aclientp.stdio import stdio_streams, run_agent, connect_to_agent
130
+ from aclientp.transports import (
131
+ serve,
132
+ StdioTransport,
133
+ WebSocketTransport,
134
+ StreamTransport,
135
+ Transport,
136
+ )
137
+ from aclientp.exceptions import RequestError
138
+ from aclientp.agent import acp_requests, notifications
139
+
140
+ __version__ = "0.0.1"
141
+
142
+ __all__ = [ # noqa: RUF022
143
+ # bridge
144
+ # Temporary re-export these
145
+ "acp_requests",
146
+ "notifications",
147
+ # client implementations
148
+ "DefaultACPClient",
149
+ "HeadlessACPClient",
150
+ "NoOpClient",
151
+ # constants
152
+ "PROTOCOL_VERSION",
153
+ # literal types
154
+ "AgentMethod",
155
+ "ClientMethod",
156
+ # auth
157
+ "AgentAuthCapabilities",
158
+ "AuthCapabilities",
159
+ "LogoutCapabilities",
160
+ "LogoutRequest",
161
+ "LogoutResponse",
162
+ "AuthMethod",
163
+ "AuthMethodAgent",
164
+ "AuthMethodTerminal",
165
+ # types
166
+ "Annotations",
167
+ "AvailableCommand",
168
+ "PlanEntry",
169
+ "AllowedOutcome",
170
+ "ToolCallUpdate",
171
+ "DeniedOutcome",
172
+ "ToolCallContent",
173
+ "PermissionOption",
174
+ "ToolCallKind",
175
+ "PlanEntryPriority",
176
+ "PlanEntryStatus",
177
+ "ToolCallStatus",
178
+ "InitializeRequest",
179
+ "ToolCallLocation",
180
+ "InitializeResponse",
181
+ "EnvVariable",
182
+ "HttpMcpServer",
183
+ "StdioMcpServer",
184
+ "SseMcpServer",
185
+ "NewSessionRequest",
186
+ "AgentMessageChunk",
187
+ "UserMessageChunk",
188
+ "TextContentBlock",
189
+ "NewSessionResponse",
190
+ "LoadSessionRequest",
191
+ "LoadSessionResponse",
192
+ "AuthenticateRequest",
193
+ "AuthenticateResponse",
194
+ # elicitation
195
+ "BooleanPropertySchema",
196
+ "ElicitationCapabilities",
197
+ "ElicitationCompleteNotification",
198
+ "ElicitationContentValue",
199
+ "ElicitationFormCapabilities",
200
+ "ElicitationPropertySchema",
201
+ "ElicitationRequest",
202
+ "ElicitationResponse",
203
+ "ElicitationSchema",
204
+ "ElicitationUrlCapabilities",
205
+ "EnumOption",
206
+ "IntegerPropertySchema",
207
+ "MultiSelectItems",
208
+ "MultiSelectPropertySchema",
209
+ "NumberPropertySchema",
210
+ "StringFormatLiteral",
211
+ "StringPropertySchema",
212
+ "TitledMultiSelectItems",
213
+ "UntitledMultiSelectItems",
214
+ "PromptRequest",
215
+ "ClientCapabilities",
216
+ "SessionModeState",
217
+ "SessionMode",
218
+ "Implementation",
219
+ "PromptResponse",
220
+ "WriteTextFileRequest",
221
+ "WriteTextFileResponse",
222
+ "ReadTextFileRequest",
223
+ "ReadTextFileResponse",
224
+ "RequestPermissionRequest",
225
+ "RequestPermissionResponse",
226
+ "CancelNotification",
227
+ "SessionNotification",
228
+ "SetSessionModeRequest",
229
+ "SetSessionModeResponse",
230
+ # session lifecycle
231
+ "ArchiveSessionRequest",
232
+ "ArchiveSessionResponse",
233
+ "AuthStatusRequest",
234
+ "AuthStatusResponse",
235
+ "AuthStatusUpdateNotification",
236
+ "CancelRequestNotification",
237
+ "DeleteSessionRequest",
238
+ "DeleteSessionResponse",
239
+ "ForkSessionRequest",
240
+ "ForkSessionResponse",
241
+ "ListSessionsRequest",
242
+ "ListSessionsResponse",
243
+ "MessageMcpNotification",
244
+ "MessageMcpRequest",
245
+ "MessageMcpResponse",
246
+ "ResumeSessionRequest",
247
+ "ResumeSessionResponse",
248
+ "SessionOptionsRequest",
249
+ "SessionOptionsResponse",
250
+ "SessionStatusRequest",
251
+ "SessionStatusResponse",
252
+ "SetSessionConfigOptionRequest",
253
+ "SetSessionConfigOptionResponse",
254
+ "SetSessionTitleRequest",
255
+ "SetSessionTitleResponse",
256
+ "SystemPrompt",
257
+ "UnarchiveSessionRequest",
258
+ "UnarchiveSessionResponse",
259
+ "CloseSessionRequest",
260
+ "CloseSessionResponse",
261
+ # terminal types
262
+ "CreateTerminalRequest",
263
+ "CreateTerminalResponse",
264
+ "TerminalOutputRequest",
265
+ "TerminalOutputResponse",
266
+ "WaitForTerminalExitRequest",
267
+ "WaitForTerminalExitResponse",
268
+ "KillTerminalRequest",
269
+ "KillTerminalResponse",
270
+ "ReleaseTerminalRequest",
271
+ "ReleaseTerminalResponse",
272
+ # core
273
+ "AgentSideConnection",
274
+ "ClientSideConnection",
275
+ "RequestError",
276
+ "Agent",
277
+ "Client",
278
+ "TerminalHandle",
279
+ "ToolCallState",
280
+ # connection helpers (recommended)
281
+ "run_agent",
282
+ "connect_to_agent",
283
+ # split protocols
284
+ "FileSystemCapabilities",
285
+ # stdio helper
286
+ "stdio_streams",
287
+ # transport
288
+ "serve",
289
+ "StdioTransport",
290
+ "WebSocketTransport",
291
+ "StreamTransport",
292
+ "Transport",
293
+ ]
aclientp/__main__.py ADDED
@@ -0,0 +1,10 @@
1
+ """ACP package main entry point.
2
+
3
+ Allows running the ACP debug server with:
4
+ python -m aclientp
5
+ """
6
+
7
+ if __name__ == "__main__":
8
+ from aclientp.agent.implementations.debug_server.cli import main
9
+
10
+ main()
aclientp/_mime.py ADDED
@@ -0,0 +1,51 @@
1
+ """MIME helpers for the ACP filesystem: decide between text and binary reads."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import mimetypes
6
+
7
+
8
+ # A table that does not read the system's mime.types files: those map common source
9
+ # files to non-text types (``.yaml`` -> ``application/yaml``, ``.rs`` ->
10
+ # ``application/rls-services+xml``), and their content differs between machines.
11
+ _MIME_TYPES = mimetypes.MimeTypes()
12
+ _MIME_TYPES.add_type("text/markdown", ".md")
13
+ _MIME_TYPES.add_type("text/markdown", ".mdx")
14
+ _MIME_TYPES.add_type("image/webp", ".webp")
15
+
16
+ BINARY_MIME_PREFIXES = (
17
+ "image/",
18
+ "audio/",
19
+ "video/",
20
+ "font/",
21
+ "application/octet-stream",
22
+ "application/zip",
23
+ "application/gzip",
24
+ "application/x-tar",
25
+ "application/x-7z-compressed",
26
+ "application/x-bzip2",
27
+ "application/x-xz",
28
+ "application/pdf",
29
+ "application/x-executable",
30
+ "application/x-sharedlib",
31
+ "application/vnd.openxmlformats-officedocument.",
32
+ "application/vnd.oasis.opendocument.",
33
+ "application/msword",
34
+ "application/vnd.ms-",
35
+ )
36
+ """MIME type prefixes of content that is definitely binary."""
37
+
38
+
39
+ def guess_type(path: str) -> str | None:
40
+ """Guess the MIME type of a path from its extension; ``None`` if unknown."""
41
+ mime_type, _ = _MIME_TYPES.guess_type(path)
42
+ return mime_type
43
+
44
+
45
+ def is_binary_mime(mime_type: str | None) -> bool:
46
+ """Whether content of this MIME type is definitely binary.
47
+
48
+ Unknown types count as text, so source files without a registered type are read
49
+ with ``fs/read_text_file``.
50
+ """
51
+ return mime_type is not None and mime_type.startswith(BINARY_MIME_PREFIXES)
aclientp/_tracing.py ADDED
@@ -0,0 +1,26 @@
1
+ """Optional tracing: spans via logfire when it is installed, no-ops otherwise."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import importlib.util
6
+ from typing import TYPE_CHECKING
7
+
8
+
9
+ if TYPE_CHECKING:
10
+ from collections.abc import Callable
11
+
12
+
13
+ def instrument[**P, R](message: str) -> Callable[[Callable[P, R]], Callable[P, R]]:
14
+ """Trace calls of the decorated function with ``logfire.instrument`` if available.
15
+
16
+ Install the ``tracing`` extra (``aclientp[tracing]``) to get spans.
17
+ """
18
+ if importlib.util.find_spec("logfire") is None:
19
+
20
+ def passthrough(func: Callable[P, R]) -> Callable[P, R]:
21
+ return func
22
+
23
+ return passthrough
24
+ import logfire
25
+
26
+ return logfire.instrument(message)
@@ -0,0 +1,7 @@
1
+ """Agent (Server) ACP Connection."""
2
+
3
+ from aclientp.agent.acp_agent_api import ACPAgentAPI
4
+ from aclientp.agent.connection import AgentSideConnection
5
+ from aclientp.agent.protocol import Agent
6
+
7
+ __all__ = ["ACPAgentAPI", "Agent", "AgentSideConnection"]
@@ -0,0 +1,225 @@
1
+ """ACP Agent API for simplified client-to-agent interactions."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from pathlib import Path
6
+ from typing import TYPE_CHECKING, Any
7
+
8
+ from aclientp.schema import (
9
+ AuthenticateRequest,
10
+ CancelNotification,
11
+ ForkSessionRequest,
12
+ InitializeRequest,
13
+ ListSessionsRequest,
14
+ LoadSessionRequest,
15
+ LogoutRequest,
16
+ NewSessionRequest,
17
+ PromptRequest,
18
+ ResumeSessionRequest,
19
+ SetSessionConfigOptionRequest,
20
+ SetSessionModeRequest,
21
+ )
22
+
23
+
24
+ if TYPE_CHECKING:
25
+ from collections.abc import Sequence
26
+
27
+ from aclientp.agent.protocol import Agent
28
+ from aclientp.schema import (
29
+ AuthenticateResponse,
30
+ ContentBlock,
31
+ ForkSessionResponse,
32
+ InitializeResponse,
33
+ ListSessionsResponse,
34
+ LoadSessionResponse,
35
+ LogoutResponse,
36
+ NewSessionResponse,
37
+ PromptResponse,
38
+ ResumeSessionResponse,
39
+ SetSessionConfigOptionResponse,
40
+ SetSessionModeResponse,
41
+ )
42
+ from aclientp.schema.mcp import McpServer
43
+
44
+
45
+ class ACPAgentAPI:
46
+ """Thin wrapper for client-to-agent ACP interactions.
47
+
48
+ Avoids manual instantiation of request/notification objects.
49
+ """
50
+
51
+ def __init__(self, connection: Agent) -> None:
52
+ """Initialize agent API helper.
53
+
54
+ Args:
55
+ connection: The Agent protocol connection (e.g., ClientSideConnection)
56
+ """
57
+ self.connection = connection
58
+
59
+ async def initialize(
60
+ self,
61
+ *,
62
+ title: str,
63
+ version: str,
64
+ name: str,
65
+ protocol_version: int = 1,
66
+ terminal: bool = True,
67
+ read_text_file: bool = True,
68
+ write_text_file: bool = True,
69
+ terminal_auth: bool = False,
70
+ metadata: dict[str, Any] | None = None,
71
+ ) -> InitializeResponse:
72
+ """Initialize the ACP connection."""
73
+ request = InitializeRequest.create(
74
+ title=title,
75
+ version=version,
76
+ name=name,
77
+ protocol_version=protocol_version,
78
+ terminal=terminal,
79
+ read_text_file=read_text_file,
80
+ write_text_file=write_text_file,
81
+ terminal_auth=terminal_auth,
82
+ metadata=metadata,
83
+ )
84
+ return await self.connection.initialize(request)
85
+
86
+ async def new_session(
87
+ self,
88
+ cwd: str | None = None,
89
+ mcp_servers: Sequence[McpServer] | None = None,
90
+ metadata: dict[str, Any] | None = None,
91
+ ) -> NewSessionResponse:
92
+ """Create a new ACP session."""
93
+ request = NewSessionRequest(
94
+ cwd=cwd or str(Path.cwd()),
95
+ mcp_servers=list(mcp_servers or []),
96
+ field_meta=metadata,
97
+ )
98
+ return await self.connection.new_session(request)
99
+
100
+ async def load_session(
101
+ self,
102
+ session_id: str,
103
+ cwd: str,
104
+ mcp_servers: Sequence[McpServer] | None = None,
105
+ metadata: dict[str, Any] | None = None,
106
+ ) -> LoadSessionResponse:
107
+ """Load an existing session."""
108
+ request = LoadSessionRequest(
109
+ session_id=session_id,
110
+ cwd=cwd,
111
+ mcp_servers=list(mcp_servers or []),
112
+ field_meta=metadata,
113
+ )
114
+ return await self.connection.load_session(request)
115
+
116
+ async def list_sessions(
117
+ self,
118
+ cwd: str | None = None,
119
+ cursor: str | None = None,
120
+ metadata: dict[str, Any] | None = None,
121
+ ) -> ListSessionsResponse:
122
+ """List available sessions."""
123
+ request = ListSessionsRequest(cwd=cwd, cursor=cursor, field_meta=metadata)
124
+ return await self.connection.list_sessions(request)
125
+
126
+ async def fork_session(
127
+ self,
128
+ session_id: str,
129
+ cwd: str,
130
+ mcp_servers: Sequence[McpServer] | None = None,
131
+ metadata: dict[str, Any] | None = None,
132
+ ) -> ForkSessionResponse:
133
+ """Fork an existing session."""
134
+ request = ForkSessionRequest(
135
+ session_id=session_id,
136
+ cwd=cwd,
137
+ mcp_servers=list(mcp_servers) if mcp_servers else [],
138
+ field_meta=metadata,
139
+ )
140
+ return await self.connection.fork_session(request)
141
+
142
+ async def resume_session(
143
+ self,
144
+ session_id: str,
145
+ cwd: str,
146
+ mcp_servers: Sequence[McpServer] | None = None,
147
+ metadata: dict[str, Any] | None = None,
148
+ ) -> ResumeSessionResponse:
149
+ """Resume a paused session."""
150
+ servers = list(mcp_servers) if mcp_servers else []
151
+ request = ResumeSessionRequest(
152
+ session_id=session_id,
153
+ cwd=cwd,
154
+ mcp_servers=servers,
155
+ field_meta=metadata,
156
+ )
157
+ return await self.connection.resume_session(request)
158
+
159
+ async def prompt(
160
+ self,
161
+ session_id: str,
162
+ prompt: Sequence[ContentBlock],
163
+ metadata: dict[str, Any] | None = None,
164
+ ) -> PromptResponse:
165
+ """Send a prompt to the agent."""
166
+ request = PromptRequest(
167
+ session_id=session_id,
168
+ prompt=list(prompt),
169
+ field_meta=metadata,
170
+ )
171
+ return await self.connection.prompt(request)
172
+
173
+ async def cancel(self, session_id: str) -> None:
174
+ """Cancel the current operation in a session."""
175
+ notification = CancelNotification(session_id=session_id)
176
+ await self.connection.cancel(notification)
177
+
178
+ async def set_session_mode(
179
+ self,
180
+ session_id: str,
181
+ mode_id: str,
182
+ ) -> SetSessionModeResponse | None:
183
+ """Set the session mode."""
184
+ request = SetSessionModeRequest(session_id=session_id, mode_id=mode_id)
185
+ return await self.connection.set_session_mode(request)
186
+
187
+ async def set_session_config_option(
188
+ self,
189
+ session_id: str,
190
+ config_id: str,
191
+ value: str | bool,
192
+ ) -> SetSessionConfigOptionResponse | None:
193
+ """Set a session configuration option.
194
+
195
+ Args:
196
+ session_id: The session ID.
197
+ config_id: The config option ID.
198
+ value: String value ID for select options, or bool for boolean options.
199
+ """
200
+ type_field = "boolean" if isinstance(value, bool) else None
201
+ req = SetSessionConfigOptionRequest(
202
+ session_id=session_id, config_id=config_id, value=value, type=type_field
203
+ )
204
+ return await self.connection.set_session_config_option(req)
205
+
206
+ async def authenticate(
207
+ self,
208
+ method_id: str,
209
+ ) -> AuthenticateResponse | None:
210
+ """Authenticate with the agent."""
211
+ request = AuthenticateRequest(method_id=method_id)
212
+ return await self.connection.authenticate(request)
213
+
214
+ async def logout(self) -> LogoutResponse | None:
215
+ """Log out of the current authenticated state."""
216
+ request = LogoutRequest()
217
+ return await self.connection.logout(request)
218
+
219
+ async def ext_method(self, method: str, params: dict[str, Any]) -> dict[str, Any]:
220
+ """Call an extension method on the agent."""
221
+ return await self.connection.ext_method(method, params)
222
+
223
+ async def ext_notification(self, method: str, params: dict[str, Any]) -> None:
224
+ """Send an extension notification to the agent."""
225
+ await self.connection.ext_notification(method, params)