forked from github/copilot-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.py
More file actions
361 lines (255 loc) · 10.9 KB
/
types.py
File metadata and controls
361 lines (255 loc) · 10.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
"""
Type definitions for the Copilot SDK
"""
from __future__ import annotations
from dataclasses import dataclass
from typing import Any, Awaitable, Callable, Dict, List, Literal, TypedDict, Union
from typing_extensions import NotRequired
# Import generated SessionEvent types
from .generated.session_events import SessionEvent
# SessionEvent is now imported from generated types
# It provides proper type discrimination for all event types
# Connection state
ConnectionState = Literal["disconnected", "connecting", "connected", "error"]
# Log level type
LogLevel = Literal["none", "error", "warning", "info", "debug", "all"]
# Attachment type
class Attachment(TypedDict):
type: Literal["file", "directory"]
path: str
displayName: NotRequired[str]
# Options for creating a CopilotClient
class CopilotClientOptions(TypedDict, total=False):
"""Options for creating a CopilotClient"""
cli_path: str # Path to the Copilot CLI executable (default: "copilot")
# Working directory for the CLI process (default: current process's cwd)
cwd: str
port: int # Port for the CLI server (TCP mode only, default: 0)
use_stdio: bool # Use stdio transport instead of TCP (default: True)
cli_url: str # URL of an existing Copilot CLI server to connect to over TCP
# Format: "host:port" or "http://host:port" or just "port" (defaults to localhost)
# Examples: "localhost:8080", "http://127.0.0.1:9000", "8080"
# Mutually exclusive with cli_path, use_stdio
log_level: LogLevel # Log level
auto_start: bool # Auto-start the CLI server on first use (default: True)
# Auto-restart the CLI server if it crashes (default: True)
auto_restart: bool
env: Dict[str, str] # Environment variables for the CLI process
ToolResultType = Literal["success", "failure", "rejected", "denied"]
class ToolBinaryResult(TypedDict, total=False):
data: str
mimeType: str
type: str
description: str
class ToolResult(TypedDict, total=False):
"""Result of a tool invocation."""
textResultForLlm: str
binaryResultsForLlm: List[ToolBinaryResult]
resultType: ToolResultType
error: str
sessionLog: str
toolTelemetry: Dict[str, Any]
class ToolInvocation(TypedDict):
session_id: str
tool_call_id: str
tool_name: str
arguments: Any
ToolHandler = Callable[[ToolInvocation], Union[ToolResult, Awaitable[ToolResult]]]
@dataclass
class Tool:
name: str
description: str
handler: ToolHandler
parameters: Dict[str, Any] | None = None
# System message configuration (discriminated union)
# Use SystemMessageAppendConfig for default behavior, SystemMessageReplaceConfig for full control
class SystemMessageAppendConfig(TypedDict, total=False):
"""
Append mode: Use CLI foundation with optional appended content.
"""
mode: NotRequired[Literal["append"]]
content: NotRequired[str]
class SystemMessageReplaceConfig(TypedDict):
"""
Replace mode: Use caller-provided system message entirely.
Removes all SDK guardrails including security restrictions.
"""
mode: Literal["replace"]
content: str
# Union type - use one or the other
SystemMessageConfig = Union[SystemMessageAppendConfig, SystemMessageReplaceConfig]
# Permission request types
class PermissionRequest(TypedDict, total=False):
"""Permission request from the server"""
kind: Literal["shell", "write", "mcp", "read", "url"]
toolCallId: str
# Additional fields vary by kind
class PermissionRequestResult(TypedDict, total=False):
"""Result of a permission request"""
kind: Literal[
"approved",
"denied-by-rules",
"denied-no-approval-rule-and-could-not-request-from-user",
"denied-interactively-by-user",
]
rules: List[Any]
PermissionHandler = Callable[
[PermissionRequest, Dict[str, str]],
Union[PermissionRequestResult, Awaitable[PermissionRequestResult]],
]
# ============================================================================
# MCP Server Configuration Types
# ============================================================================
class MCPLocalServerConfig(TypedDict, total=False):
"""Configuration for a local/stdio MCP server."""
tools: List[str] # List of tools to include. [] means none. "*" means all.
type: NotRequired[Literal["local", "stdio"]] # Server type
timeout: NotRequired[int] # Timeout in milliseconds
command: str # Command to run
args: List[str] # Command arguments
env: NotRequired[Dict[str, str]] # Environment variables
cwd: NotRequired[str] # Working directory
class MCPRemoteServerConfig(TypedDict, total=False):
"""Configuration for a remote MCP server (HTTP or SSE)."""
tools: List[str] # List of tools to include. [] means none. "*" means all.
type: Literal["http", "sse"] # Server type
timeout: NotRequired[int] # Timeout in milliseconds
url: str # URL of the remote server
headers: NotRequired[Dict[str, str]] # HTTP headers
MCPServerConfig = Union[MCPLocalServerConfig, MCPRemoteServerConfig]
# ============================================================================
# Custom Agent Configuration Types
# ============================================================================
class CustomAgentConfig(TypedDict, total=False):
"""Configuration for a custom agent."""
name: str # Unique name of the custom agent
display_name: NotRequired[str] # Display name for UI purposes
description: NotRequired[str] # Description of what the agent does
# List of tool names the agent can use
tools: NotRequired[List[str] | None]
prompt: str # The prompt content for the agent
# MCP servers specific to agent
mcp_servers: NotRequired[Dict[str, MCPServerConfig]]
infer: NotRequired[bool] # Whether agent is available for model inference
# Configuration for creating a session
class SessionConfig(TypedDict, total=False):
"""Configuration for creating a session"""
session_id: str # Optional custom session ID
model: Literal["gpt-5", "claude-sonnet-4", "claude-sonnet-4.5", "claude-haiku-4.5"]
tools: List[Tool]
system_message: SystemMessageConfig # System message configuration
# List of tool names to allow (takes precedence over excluded_tools)
available_tools: list[str]
# List of tool names to disable (ignored if available_tools is set)
excluded_tools: list[str]
# Handler for permission requests from the server
on_permission_request: PermissionHandler
# Custom provider configuration (BYOK - Bring Your Own Key)
provider: ProviderConfig
# Enable streaming of assistant message and reasoning chunks
# When True, assistant.message_delta and assistant.reasoning_delta events
# with delta_content are sent as the response is generated
streaming: bool
# MCP server configurations for the session
mcp_servers: Dict[str, MCPServerConfig]
# Custom agent configurations for the session
custom_agents: List[CustomAgentConfig]
# Override the default configuration directory location.
# When specified, the session will use this directory for storing config and state.
config_dir: str
# Directories to load skills from
skill_directories: List[str]
# List of skill names to disable
disabled_skills: List[str]
# Azure-specific provider options
class AzureProviderOptions(TypedDict, total=False):
"""Azure-specific provider configuration"""
api_version: str # Azure API version. Defaults to "2024-10-21".
# Configuration for a custom API provider
class ProviderConfig(TypedDict, total=False):
"""Configuration for a custom API provider"""
type: Literal["openai", "azure", "anthropic"]
wire_api: Literal["completions", "responses"]
base_url: str
api_key: str
# Bearer token for authentication. Sets the Authorization header directly.
# Use this for services requiring bearer token auth instead of API key.
# Takes precedence over api_key when both are set.
bearer_token: str
azure: AzureProviderOptions # Azure-specific options
# Configuration for resuming a session
class ResumeSessionConfig(TypedDict, total=False):
"""Configuration for resuming a session"""
tools: List[Tool]
provider: ProviderConfig
on_permission_request: PermissionHandler
# Enable streaming of assistant message chunks
streaming: bool
# MCP server configurations for the session
mcp_servers: Dict[str, MCPServerConfig]
# Custom agent configurations for the session
custom_agents: List[CustomAgentConfig]
# Directories to load skills from
skill_directories: List[str]
# List of skill names to disable
disabled_skills: List[str]
# Options for sending a message to a session
class MessageOptions(TypedDict):
"""Options for sending a message to a session"""
prompt: str # The prompt/message to send
# Optional file/directory attachments
attachments: NotRequired[List[Attachment]]
# Message processing mode
mode: NotRequired[Literal["enqueue", "immediate"]]
# Event handler type
SessionEventHandler = Callable[[SessionEvent], None]
# Response from status.get
class GetStatusResponse(TypedDict):
"""Response from status.get"""
version: str # Package version (e.g., "1.0.0")
protocolVersion: int # Protocol version for SDK compatibility
# Response from auth.getStatus
class GetAuthStatusResponse(TypedDict):
"""Response from auth.getStatus"""
isAuthenticated: bool # Whether the user is authenticated
authType: NotRequired[
Literal["user", "env", "gh-cli", "hmac", "api-key", "token"]
] # Authentication type
host: NotRequired[str] # GitHub host URL
login: NotRequired[str] # User login name
statusMessage: NotRequired[str] # Human-readable status message
# Model capabilities
class ModelVisionLimits(TypedDict, total=False):
"""Vision-specific limits"""
supported_media_types: List[str]
max_prompt_images: int
max_prompt_image_size: int
class ModelLimits(TypedDict, total=False):
"""Model limits"""
max_prompt_tokens: int
max_context_window_tokens: int
vision: ModelVisionLimits
class ModelSupports(TypedDict):
"""Model support flags"""
vision: bool
class ModelCapabilities(TypedDict):
"""Model capabilities and limits"""
supports: ModelSupports
limits: ModelLimits
class ModelPolicy(TypedDict):
"""Model policy state"""
state: Literal["enabled", "disabled", "unconfigured"]
terms: str
class ModelBilling(TypedDict):
"""Model billing information"""
multiplier: float
class ModelInfo(TypedDict):
"""Information about an available model"""
id: str # Model identifier (e.g., "claude-sonnet-4.5")
name: str # Display name
capabilities: ModelCapabilities # Model capabilities and limits
policy: NotRequired[ModelPolicy] # Policy state
billing: NotRequired[ModelBilling] # Billing information
class GetModelsResponse(TypedDict):
"""Response from models.list"""
models: List[ModelInfo]