Skip to content

Commit 24cafde

Browse files
Phase F: internals cleanup + expand public API surface
Mirrors PR #1357 Phase K + 4.1 (TypeScript SDK API review). Cleanup: * Remove the deprecated `CopilotSession.destroy()` method. Only `disconnect()` remains (matches TS PR #1357 4.1). * Rename `NO_RESULT_PERMISSION_V2_ERROR` → `_NO_RESULT_PERMISSION_V2_ERROR` and `MIN_PROTOCOL_VERSION` → `_MIN_PROTOCOL_VERSION` (module-private constants; Python equivalent of TS `@internal` + `stripInternal`). Public API audit vs C# / TypeScript: * `copilot/__init__.py` now re-exports the full set of types that match the TS public surface from `nodejs/src/index.ts`. Notable additions: - Lifecycle event hierarchy: `SessionCreatedEvent`, `SessionDeletedEvent`, `SessionUpdatedEvent`, `SessionForegroundEvent`, `SessionBackgroundEvent`, `SessionLifecycleEvent`, `SessionLifecycleEventBase`, `SessionLifecycleEventMetadata`, `SessionLifecycleEventType`, `SessionLifecycleHandler` - Session metadata / context: `SessionContext`, `SessionListFilter`, `SessionMetadata` - Generated `PermissionRequest`, `SessionEvent`, `SessionEventType` ( consumers shouldn't have to reach into `copilot.generated.*`) - `PermissionHandler`, `PermissionRequestResult`, `PermissionNoResult`, `UserInputHandler`, `UserInputRequest`, `UserInputResponse` - MCP server configs: `MCPHTTPServerConfig`, `MCPServerConfig`, `MCPStdioServerConfig` - Session config: `SessionConfig`, `ResumeSessionConfig`, `SessionHooks`, `SystemMessageConfig`, `InfiniteSessionConfig` - All hook handler / input / output TypedDicts: `PreToolUseHandler` & friends across the six hook lifecycle points - Model* completion (added `ModelLimits`, `ModelSupports`, `ModelVisionLimits`, `ModelBilling`, `ModelPolicy`, `ModelCapabilities`) - `ConnectionState`, `LogLevel`, `PingResponse`, `GetStatusResponse`, `GetAuthStatusResponse`, `StopError` - `ToolResultType`, `SessionEventHandler` `__all__` is now alphabetically sorted. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 9d63384 commit 24cafde

3 files changed

Lines changed: 145 additions & 31 deletions

File tree

python/copilot/__init__.py

Lines changed: 138 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,50 @@
88
ChildProcessRuntimeConnection,
99
CloudSessionOptions,
1010
CloudSessionRepository,
11+
ConnectionState,
1112
CopilotClient,
1213
CopilotClientOptions,
14+
GetAuthStatusResponse,
15+
GetStatusResponse,
16+
LogLevel,
17+
ModelBilling,
18+
ModelCapabilities,
1319
ModelCapabilitiesOverride,
20+
ModelInfo,
21+
ModelLimits,
1422
ModelLimitsOverride,
23+
ModelPolicy,
24+
ModelSupports,
1525
ModelSupportsOverride,
26+
ModelVisionLimits,
1627
ModelVisionLimitsOverride,
28+
PingResponse,
1729
RemoteSessionMode,
1830
RuntimeConnection,
31+
SessionBackgroundEvent,
32+
SessionContext,
33+
SessionCreatedEvent,
34+
SessionDeletedEvent,
35+
SessionForegroundEvent,
36+
SessionLifecycleEvent,
37+
SessionLifecycleEventBase,
38+
SessionLifecycleEventMetadata,
39+
SessionLifecycleEventType,
40+
SessionLifecycleHandler,
41+
SessionListFilter,
42+
SessionMetadata,
43+
SessionUpdatedEvent,
1944
StdioRuntimeConnection,
45+
StopError,
2046
TcpRuntimeConnection,
2147
TelemetryConfig,
2248
UriRuntimeConnection,
2349
)
50+
from .generated.session_events import (
51+
PermissionRequest,
52+
SessionEvent,
53+
SessionEventType,
54+
)
2455
from .session import (
2556
AutoModeSwitchHandler,
2657
AutoModeSwitchRequest,
@@ -33,16 +64,52 @@
3364
ElicitationHandler,
3465
ElicitationParams,
3566
ElicitationResult,
67+
ErrorOccurredHandler,
68+
ErrorOccurredHookInput,
69+
ErrorOccurredHookOutput,
3670
ExitPlanModeHandler,
3771
ExitPlanModeRequest,
3872
ExitPlanModeResult,
73+
InfiniteSessionConfig,
3974
InputOptions,
75+
MCPHTTPServerConfig,
76+
MCPServerConfig,
77+
MCPStdioServerConfig,
78+
PermissionHandler,
79+
PermissionNoResult,
80+
PermissionRequestResult,
81+
PostToolUseHandler,
82+
PostToolUseHookInput,
83+
PostToolUseHookOutput,
84+
PreMcpToolCallHandler,
85+
PreMcpToolCallHookInput,
86+
PreMcpToolCallHookOutput,
87+
PreToolUseHandler,
88+
PreToolUseHookInput,
89+
PreToolUseHookOutput,
4090
ProviderConfig,
91+
ResumeSessionConfig,
4192
SessionCapabilities,
93+
SessionConfig,
94+
SessionEndHandler,
95+
SessionEndHookInput,
96+
SessionEndHookOutput,
97+
SessionEventHandler,
4298
SessionFsCapabilities,
4399
SessionFsConfig,
100+
SessionHooks,
101+
SessionStartHandler,
102+
SessionStartHookInput,
103+
SessionStartHookOutput,
44104
SessionUiApi,
45105
SessionUiCapabilities,
106+
SystemMessageConfig,
107+
UserInputHandler,
108+
UserInputRequest,
109+
UserInputResponse,
110+
UserPromptSubmittedHandler,
111+
UserPromptSubmittedHookInput,
112+
UserPromptSubmittedHookOutput,
46113
)
47114
from .session_fs_provider import (
48115
SessionFsFileInfo,
@@ -56,58 +123,125 @@
56123
ToolBinaryResult,
57124
ToolInvocation,
58125
ToolResult,
126+
ToolResultType,
59127
convert_mcp_call_tool_result,
60128
define_tool,
61129
)
62130

63131
__version__ = "0.1.0"
64132

65133
__all__ = [
66-
"CommandContext",
67134
"AutoModeSwitchHandler",
68135
"AutoModeSwitchRequest",
69136
"AutoModeSwitchResponse",
70137
"ChildProcessRuntimeConnection",
71-
"CommandDefinition",
72138
"CloudSessionOptions",
73139
"CloudSessionRepository",
140+
"CommandContext",
141+
"CommandDefinition",
142+
"ConnectionState",
74143
"CopilotClient",
75144
"CopilotClientOptions",
76145
"CopilotSession",
77146
"CreateSessionFsHandler",
147+
"ElicitationContext",
78148
"ElicitationHandler",
79149
"ElicitationParams",
80-
"ElicitationContext",
81150
"ElicitationResult",
151+
"ErrorOccurredHandler",
152+
"ErrorOccurredHookInput",
153+
"ErrorOccurredHookOutput",
82154
"ExitPlanModeHandler",
83155
"ExitPlanModeRequest",
84156
"ExitPlanModeResult",
157+
"GetAuthStatusResponse",
158+
"GetStatusResponse",
159+
"InfiniteSessionConfig",
85160
"InputOptions",
161+
"LogLevel",
162+
"MCPHTTPServerConfig",
163+
"MCPServerConfig",
164+
"MCPStdioServerConfig",
165+
"ModelBilling",
166+
"ModelCapabilities",
86167
"ModelCapabilitiesOverride",
168+
"ModelInfo",
169+
"ModelLimits",
87170
"ModelLimitsOverride",
171+
"ModelPolicy",
172+
"ModelSupports",
88173
"ModelSupportsOverride",
174+
"ModelVisionLimits",
89175
"ModelVisionLimitsOverride",
176+
"PermissionHandler",
177+
"PermissionNoResult",
178+
"PermissionRequest",
179+
"PermissionRequestResult",
180+
"PingResponse",
181+
"PostToolUseHandler",
182+
"PostToolUseHookInput",
183+
"PostToolUseHookOutput",
184+
"PreMcpToolCallHandler",
185+
"PreMcpToolCallHookInput",
186+
"PreMcpToolCallHookOutput",
187+
"PreToolUseHandler",
188+
"PreToolUseHookInput",
189+
"PreToolUseHookOutput",
90190
"ProviderConfig",
91191
"RemoteSessionMode",
192+
"ResumeSessionConfig",
92193
"RuntimeConnection",
194+
"SessionBackgroundEvent",
93195
"SessionCapabilities",
196+
"SessionConfig",
197+
"SessionContext",
198+
"SessionCreatedEvent",
199+
"SessionDeletedEvent",
200+
"SessionEndHandler",
201+
"SessionEndHookInput",
202+
"SessionEndHookOutput",
203+
"SessionEvent",
204+
"SessionEventHandler",
205+
"SessionEventType",
206+
"SessionForegroundEvent",
94207
"SessionFsCapabilities",
95208
"SessionFsConfig",
96209
"SessionFsFileInfo",
97210
"SessionFsProvider",
98211
"SessionFsSqliteProvider",
99212
"SessionFsSqliteQueryResult",
100-
"create_session_fs_adapter",
213+
"SessionHooks",
214+
"SessionLifecycleEvent",
215+
"SessionLifecycleEventBase",
216+
"SessionLifecycleEventMetadata",
217+
"SessionLifecycleEventType",
218+
"SessionLifecycleHandler",
219+
"SessionListFilter",
220+
"SessionMetadata",
221+
"SessionStartHandler",
222+
"SessionStartHookInput",
223+
"SessionStartHookOutput",
101224
"SessionUiApi",
102225
"SessionUiCapabilities",
226+
"SessionUpdatedEvent",
103227
"StdioRuntimeConnection",
228+
"StopError",
229+
"SystemMessageConfig",
104230
"TcpRuntimeConnection",
105231
"TelemetryConfig",
106232
"Tool",
107233
"ToolBinaryResult",
108234
"ToolInvocation",
109235
"ToolResult",
236+
"ToolResultType",
110237
"UriRuntimeConnection",
238+
"UserInputHandler",
239+
"UserInputRequest",
240+
"UserInputResponse",
241+
"UserPromptSubmittedHandler",
242+
"UserPromptSubmittedHookInput",
243+
"UserPromptSubmittedHookOutput",
111244
"convert_mcp_call_tool_result",
245+
"create_session_fs_adapter",
112246
"define_tool",
113247
]

python/copilot/client.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -979,13 +979,13 @@ def _session_lifecycle_event_from_dict(data: dict) -> SessionLifecycleEvent:
979979

980980
HandlerUnsubcribe = Callable[[], None]
981981

982-
NO_RESULT_PERMISSION_V2_ERROR = (
982+
_NO_RESULT_PERMISSION_V2_ERROR = (
983983
"Permission handlers cannot return 'no-result' when connected to a protocol v2 server."
984984
)
985985

986986
# Minimum protocol version this SDK can communicate with.
987987
# Servers reporting a version below this are rejected.
988-
MIN_PROTOCOL_VERSION = 2
988+
_MIN_PROTOCOL_VERSION = 2
989989

990990

991991
def _get_bundled_cli_path() -> str | None:
@@ -2664,15 +2664,15 @@ async def _verify_protocol_version(self) -> None:
26642664
if server_version is None:
26652665
raise RuntimeError(
26662666
"SDK protocol version mismatch: "
2667-
f"SDK supports versions {MIN_PROTOCOL_VERSION}-{max_version}"
2667+
f"SDK supports versions {_MIN_PROTOCOL_VERSION}-{max_version}"
26682668
", but server does not report a protocol version. "
26692669
"Please update your server to ensure compatibility."
26702670
)
26712671

2672-
if server_version < MIN_PROTOCOL_VERSION or server_version > max_version:
2672+
if server_version < _MIN_PROTOCOL_VERSION or server_version > max_version:
26732673
raise RuntimeError(
26742674
"SDK protocol version mismatch: "
2675-
f"SDK supports versions {MIN_PROTOCOL_VERSION}-{max_version}"
2675+
f"SDK supports versions {_MIN_PROTOCOL_VERSION}-{max_version}"
26762676
f", but server reports version {server_version}. "
26772677
"Please update your SDK or server to ensure compatibility."
26782678
)
@@ -3364,10 +3364,10 @@ async def _handle_permission_request_v2(self, params: dict) -> dict:
33643364
perm_request = _load_PermissionRequest(permission_request)
33653365
result = await session._handle_permission_request(perm_request)
33663366
if isinstance(result, PermissionNoResult):
3367-
raise ValueError(NO_RESULT_PERMISSION_V2_ERROR)
3367+
raise ValueError(_NO_RESULT_PERMISSION_V2_ERROR)
33683368
return {"result": result.to_dict()}
33693369
except ValueError as exc:
3370-
if str(exc) == NO_RESULT_PERMISSION_V2_ERROR:
3370+
if str(exc) == _NO_RESULT_PERMISSION_V2_ERROR:
33713371
raise
33723372
return {"result": PermissionDecisionUserNotAvailable().to_dict()}
33733373
except Exception: # pylint: disable=broad-except

python/copilot/session.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2338,26 +2338,6 @@ async def disconnect(self) -> None:
23382338
with self._auto_mode_switch_handler_lock:
23392339
self._auto_mode_switch_handler = None
23402340

2341-
async def destroy(self) -> None:
2342-
"""
2343-
.. deprecated::
2344-
Use :meth:`disconnect` instead. This method will be removed in a future release.
2345-
2346-
Disconnect this session and release all in-memory resources.
2347-
Session data on disk is preserved for later resumption.
2348-
2349-
Raises:
2350-
Exception: If the connection fails.
2351-
"""
2352-
import warnings
2353-
2354-
warnings.warn(
2355-
"destroy() is deprecated, use disconnect() instead",
2356-
DeprecationWarning,
2357-
stacklevel=2,
2358-
)
2359-
await self.disconnect()
2360-
23612341
async def __aenter__(self) -> CopilotSession:
23622342
"""Enable use as an async context manager."""
23632343
return self

0 commit comments

Comments
 (0)