copilot-sdk-supercharged 1.0.0
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.
- package/README.md +652 -0
- package/dist/client.d.ts +378 -0
- package/dist/client.js +1034 -0
- package/dist/generated/session-events.d.ts +536 -0
- package/dist/generated/session-events.js +0 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +8 -0
- package/dist/sdkProtocolVersion.d.ts +10 -0
- package/dist/sdkProtocolVersion.js +8 -0
- package/dist/session.d.ts +288 -0
- package/dist/session.js +378 -0
- package/dist/types.d.ts +822 -0
- package/dist/types.js +6 -0
- package/package.json +75 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,822 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for the Copilot SDK
|
|
3
|
+
*/
|
|
4
|
+
import type { SessionEvent as GeneratedSessionEvent } from "./generated/session-events.js";
|
|
5
|
+
export type SessionEvent = GeneratedSessionEvent;
|
|
6
|
+
/**
|
|
7
|
+
* Options for creating a CopilotClient
|
|
8
|
+
*/
|
|
9
|
+
export interface CopilotClientOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Path to the CLI executable or JavaScript entry point.
|
|
12
|
+
* If not specified, uses the bundled CLI from the @github/copilot package.
|
|
13
|
+
*/
|
|
14
|
+
cliPath?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Extra arguments to pass to the CLI executable (inserted before SDK-managed args)
|
|
17
|
+
*/
|
|
18
|
+
cliArgs?: string[];
|
|
19
|
+
/**
|
|
20
|
+
* Working directory for the CLI process
|
|
21
|
+
* If not set, inherits the current process's working directory
|
|
22
|
+
*/
|
|
23
|
+
cwd?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Port for the CLI server (TCP mode only)
|
|
26
|
+
* @default 0 (random available port)
|
|
27
|
+
*/
|
|
28
|
+
port?: number;
|
|
29
|
+
/**
|
|
30
|
+
* Use stdio transport instead of TCP
|
|
31
|
+
* When true, communicates with CLI via stdin/stdout pipes
|
|
32
|
+
* @default true
|
|
33
|
+
*/
|
|
34
|
+
useStdio?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* URL of an existing Copilot CLI server to connect to over TCP
|
|
37
|
+
* When provided, the client will not spawn a CLI process
|
|
38
|
+
* Format: "host:port" or "http://host:port" or just "port" (defaults to localhost)
|
|
39
|
+
* Examples: "localhost:8080", "http://127.0.0.1:9000", "8080"
|
|
40
|
+
* Mutually exclusive with cliPath, useStdio
|
|
41
|
+
*/
|
|
42
|
+
cliUrl?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Log level for the CLI server
|
|
45
|
+
*/
|
|
46
|
+
logLevel?: "none" | "error" | "warning" | "info" | "debug" | "all";
|
|
47
|
+
/**
|
|
48
|
+
* Auto-start the CLI server on first use
|
|
49
|
+
* @default true
|
|
50
|
+
*/
|
|
51
|
+
autoStart?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Auto-restart the CLI server if it crashes
|
|
54
|
+
* @default true
|
|
55
|
+
*/
|
|
56
|
+
autoRestart?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Environment variables to pass to the CLI process. If not set, inherits process.env.
|
|
59
|
+
*/
|
|
60
|
+
env?: Record<string, string | undefined>;
|
|
61
|
+
/**
|
|
62
|
+
* GitHub token to use for authentication.
|
|
63
|
+
* When provided, the token is passed to the CLI server via environment variable.
|
|
64
|
+
* This takes priority over other authentication methods.
|
|
65
|
+
*/
|
|
66
|
+
githubToken?: string;
|
|
67
|
+
/**
|
|
68
|
+
* Whether to use the logged-in user for authentication.
|
|
69
|
+
* When true, the CLI server will attempt to use stored OAuth tokens or gh CLI auth.
|
|
70
|
+
* When false, only explicit tokens (githubToken or environment variables) are used.
|
|
71
|
+
* @default true (but defaults to false when githubToken is provided)
|
|
72
|
+
*/
|
|
73
|
+
useLoggedInUser?: boolean;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Configuration for creating a session
|
|
77
|
+
*/
|
|
78
|
+
export type ToolResultType = "success" | "failure" | "rejected" | "denied";
|
|
79
|
+
export type ToolBinaryResult = {
|
|
80
|
+
data: string;
|
|
81
|
+
mimeType: string;
|
|
82
|
+
type: string;
|
|
83
|
+
description?: string;
|
|
84
|
+
};
|
|
85
|
+
export type ToolResultObject = {
|
|
86
|
+
textResultForLlm: string;
|
|
87
|
+
binaryResultsForLlm?: ToolBinaryResult[];
|
|
88
|
+
resultType: ToolResultType;
|
|
89
|
+
error?: string;
|
|
90
|
+
sessionLog?: string;
|
|
91
|
+
toolTelemetry?: Record<string, unknown>;
|
|
92
|
+
};
|
|
93
|
+
export type ToolResult = string | ToolResultObject;
|
|
94
|
+
export interface ToolInvocation {
|
|
95
|
+
sessionId: string;
|
|
96
|
+
toolCallId: string;
|
|
97
|
+
toolName: string;
|
|
98
|
+
arguments: unknown;
|
|
99
|
+
}
|
|
100
|
+
export type ToolHandler<TArgs = unknown> = (args: TArgs, invocation: ToolInvocation) => Promise<unknown> | unknown;
|
|
101
|
+
/**
|
|
102
|
+
* Zod-like schema interface for type inference.
|
|
103
|
+
* Any object with `toJSONSchema()` method is treated as a Zod schema.
|
|
104
|
+
*/
|
|
105
|
+
export interface ZodSchema<T = unknown> {
|
|
106
|
+
_output: T;
|
|
107
|
+
toJSONSchema(): Record<string, unknown>;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Tool definition. Parameters can be either:
|
|
111
|
+
* - A Zod schema (provides type inference for handler)
|
|
112
|
+
* - A raw JSON schema object
|
|
113
|
+
* - Omitted (no parameters)
|
|
114
|
+
*/
|
|
115
|
+
export interface Tool<TArgs = unknown> {
|
|
116
|
+
name: string;
|
|
117
|
+
description?: string;
|
|
118
|
+
parameters?: ZodSchema<TArgs> | Record<string, unknown>;
|
|
119
|
+
handler: ToolHandler<TArgs>;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Helper to define a tool with Zod schema and get type inference for the handler.
|
|
123
|
+
* Without this helper, TypeScript cannot infer handler argument types from Zod schemas.
|
|
124
|
+
*/
|
|
125
|
+
export declare function defineTool<T = unknown>(name: string, config: {
|
|
126
|
+
description?: string;
|
|
127
|
+
parameters?: ZodSchema<T> | Record<string, unknown>;
|
|
128
|
+
handler: ToolHandler<T>;
|
|
129
|
+
}): Tool<T>;
|
|
130
|
+
export interface ToolCallRequestPayload {
|
|
131
|
+
sessionId: string;
|
|
132
|
+
toolCallId: string;
|
|
133
|
+
toolName: string;
|
|
134
|
+
arguments: unknown;
|
|
135
|
+
}
|
|
136
|
+
export interface ToolCallResponsePayload {
|
|
137
|
+
result: ToolResult;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Append mode: Use CLI foundation with optional appended content (default).
|
|
141
|
+
*/
|
|
142
|
+
export interface SystemMessageAppendConfig {
|
|
143
|
+
mode?: "append";
|
|
144
|
+
/**
|
|
145
|
+
* Additional instructions appended after SDK-managed sections.
|
|
146
|
+
*/
|
|
147
|
+
content?: string;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Replace mode: Use caller-provided system message entirely.
|
|
151
|
+
* Removes all SDK guardrails including security restrictions.
|
|
152
|
+
*/
|
|
153
|
+
export interface SystemMessageReplaceConfig {
|
|
154
|
+
mode: "replace";
|
|
155
|
+
/**
|
|
156
|
+
* Complete system message content.
|
|
157
|
+
* Replaces the entire SDK-managed system message.
|
|
158
|
+
*/
|
|
159
|
+
content: string;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* System message configuration for session creation.
|
|
163
|
+
* - Append mode (default): SDK foundation + optional custom content
|
|
164
|
+
* - Replace mode: Full control, caller provides entire system message
|
|
165
|
+
*/
|
|
166
|
+
export type SystemMessageConfig = SystemMessageAppendConfig | SystemMessageReplaceConfig;
|
|
167
|
+
/**
|
|
168
|
+
* Permission request types from the server
|
|
169
|
+
*/
|
|
170
|
+
export interface PermissionRequest {
|
|
171
|
+
kind: "shell" | "write" | "mcp" | "read" | "url";
|
|
172
|
+
toolCallId?: string;
|
|
173
|
+
[key: string]: unknown;
|
|
174
|
+
}
|
|
175
|
+
export interface PermissionRequestResult {
|
|
176
|
+
kind: "approved" | "denied-by-rules" | "denied-no-approval-rule-and-could-not-request-from-user" | "denied-interactively-by-user";
|
|
177
|
+
rules?: unknown[];
|
|
178
|
+
}
|
|
179
|
+
export type PermissionHandler = (request: PermissionRequest, invocation: {
|
|
180
|
+
sessionId: string;
|
|
181
|
+
}) => Promise<PermissionRequestResult> | PermissionRequestResult;
|
|
182
|
+
/**
|
|
183
|
+
* Request for user input from the agent (enables ask_user tool)
|
|
184
|
+
*/
|
|
185
|
+
export interface UserInputRequest {
|
|
186
|
+
/**
|
|
187
|
+
* The question to ask the user
|
|
188
|
+
*/
|
|
189
|
+
question: string;
|
|
190
|
+
/**
|
|
191
|
+
* Optional choices for multiple choice questions
|
|
192
|
+
*/
|
|
193
|
+
choices?: string[];
|
|
194
|
+
/**
|
|
195
|
+
* Whether to allow freeform text input in addition to choices
|
|
196
|
+
* @default true
|
|
197
|
+
*/
|
|
198
|
+
allowFreeform?: boolean;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Response to a user input request
|
|
202
|
+
*/
|
|
203
|
+
export interface UserInputResponse {
|
|
204
|
+
/**
|
|
205
|
+
* The user's answer
|
|
206
|
+
*/
|
|
207
|
+
answer: string;
|
|
208
|
+
/**
|
|
209
|
+
* Whether the answer was freeform (not from choices)
|
|
210
|
+
*/
|
|
211
|
+
wasFreeform: boolean;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Handler for user input requests from the agent
|
|
215
|
+
*/
|
|
216
|
+
export type UserInputHandler = (request: UserInputRequest, invocation: {
|
|
217
|
+
sessionId: string;
|
|
218
|
+
}) => Promise<UserInputResponse> | UserInputResponse;
|
|
219
|
+
/**
|
|
220
|
+
* Base interface for all hook inputs
|
|
221
|
+
*/
|
|
222
|
+
export interface BaseHookInput {
|
|
223
|
+
timestamp: number;
|
|
224
|
+
cwd: string;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Input for pre-tool-use hook
|
|
228
|
+
*/
|
|
229
|
+
export interface PreToolUseHookInput extends BaseHookInput {
|
|
230
|
+
toolName: string;
|
|
231
|
+
toolArgs: unknown;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Output for pre-tool-use hook
|
|
235
|
+
*/
|
|
236
|
+
export interface PreToolUseHookOutput {
|
|
237
|
+
permissionDecision?: "allow" | "deny" | "ask";
|
|
238
|
+
permissionDecisionReason?: string;
|
|
239
|
+
modifiedArgs?: unknown;
|
|
240
|
+
additionalContext?: string;
|
|
241
|
+
suppressOutput?: boolean;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Handler for pre-tool-use hook
|
|
245
|
+
*/
|
|
246
|
+
export type PreToolUseHandler = (input: PreToolUseHookInput, invocation: {
|
|
247
|
+
sessionId: string;
|
|
248
|
+
}) => Promise<PreToolUseHookOutput | void> | PreToolUseHookOutput | void;
|
|
249
|
+
/**
|
|
250
|
+
* Input for post-tool-use hook
|
|
251
|
+
*/
|
|
252
|
+
export interface PostToolUseHookInput extends BaseHookInput {
|
|
253
|
+
toolName: string;
|
|
254
|
+
toolArgs: unknown;
|
|
255
|
+
toolResult: ToolResultObject;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Output for post-tool-use hook
|
|
259
|
+
*/
|
|
260
|
+
export interface PostToolUseHookOutput {
|
|
261
|
+
modifiedResult?: ToolResultObject;
|
|
262
|
+
additionalContext?: string;
|
|
263
|
+
suppressOutput?: boolean;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Handler for post-tool-use hook
|
|
267
|
+
*/
|
|
268
|
+
export type PostToolUseHandler = (input: PostToolUseHookInput, invocation: {
|
|
269
|
+
sessionId: string;
|
|
270
|
+
}) => Promise<PostToolUseHookOutput | void> | PostToolUseHookOutput | void;
|
|
271
|
+
/**
|
|
272
|
+
* Input for user-prompt-submitted hook
|
|
273
|
+
*/
|
|
274
|
+
export interface UserPromptSubmittedHookInput extends BaseHookInput {
|
|
275
|
+
prompt: string;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Output for user-prompt-submitted hook
|
|
279
|
+
*/
|
|
280
|
+
export interface UserPromptSubmittedHookOutput {
|
|
281
|
+
modifiedPrompt?: string;
|
|
282
|
+
additionalContext?: string;
|
|
283
|
+
suppressOutput?: boolean;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Handler for user-prompt-submitted hook
|
|
287
|
+
*/
|
|
288
|
+
export type UserPromptSubmittedHandler = (input: UserPromptSubmittedHookInput, invocation: {
|
|
289
|
+
sessionId: string;
|
|
290
|
+
}) => Promise<UserPromptSubmittedHookOutput | void> | UserPromptSubmittedHookOutput | void;
|
|
291
|
+
/**
|
|
292
|
+
* Input for session-start hook
|
|
293
|
+
*/
|
|
294
|
+
export interface SessionStartHookInput extends BaseHookInput {
|
|
295
|
+
source: "startup" | "resume" | "new";
|
|
296
|
+
initialPrompt?: string;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Output for session-start hook
|
|
300
|
+
*/
|
|
301
|
+
export interface SessionStartHookOutput {
|
|
302
|
+
additionalContext?: string;
|
|
303
|
+
modifiedConfig?: Record<string, unknown>;
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Handler for session-start hook
|
|
307
|
+
*/
|
|
308
|
+
export type SessionStartHandler = (input: SessionStartHookInput, invocation: {
|
|
309
|
+
sessionId: string;
|
|
310
|
+
}) => Promise<SessionStartHookOutput | void> | SessionStartHookOutput | void;
|
|
311
|
+
/**
|
|
312
|
+
* Input for session-end hook
|
|
313
|
+
*/
|
|
314
|
+
export interface SessionEndHookInput extends BaseHookInput {
|
|
315
|
+
reason: "complete" | "error" | "abort" | "timeout" | "user_exit";
|
|
316
|
+
finalMessage?: string;
|
|
317
|
+
error?: string;
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Output for session-end hook
|
|
321
|
+
*/
|
|
322
|
+
export interface SessionEndHookOutput {
|
|
323
|
+
suppressOutput?: boolean;
|
|
324
|
+
cleanupActions?: string[];
|
|
325
|
+
sessionSummary?: string;
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Handler for session-end hook
|
|
329
|
+
*/
|
|
330
|
+
export type SessionEndHandler = (input: SessionEndHookInput, invocation: {
|
|
331
|
+
sessionId: string;
|
|
332
|
+
}) => Promise<SessionEndHookOutput | void> | SessionEndHookOutput | void;
|
|
333
|
+
/**
|
|
334
|
+
* Input for error-occurred hook
|
|
335
|
+
*/
|
|
336
|
+
export interface ErrorOccurredHookInput extends BaseHookInput {
|
|
337
|
+
error: string;
|
|
338
|
+
errorContext: "model_call" | "tool_execution" | "system" | "user_input";
|
|
339
|
+
recoverable: boolean;
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Output for error-occurred hook
|
|
343
|
+
*/
|
|
344
|
+
export interface ErrorOccurredHookOutput {
|
|
345
|
+
suppressOutput?: boolean;
|
|
346
|
+
errorHandling?: "retry" | "skip" | "abort";
|
|
347
|
+
retryCount?: number;
|
|
348
|
+
userNotification?: string;
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Handler for error-occurred hook
|
|
352
|
+
*/
|
|
353
|
+
export type ErrorOccurredHandler = (input: ErrorOccurredHookInput, invocation: {
|
|
354
|
+
sessionId: string;
|
|
355
|
+
}) => Promise<ErrorOccurredHookOutput | void> | ErrorOccurredHookOutput | void;
|
|
356
|
+
/**
|
|
357
|
+
* Configuration for session hooks
|
|
358
|
+
*/
|
|
359
|
+
export interface SessionHooks {
|
|
360
|
+
/**
|
|
361
|
+
* Called before a tool is executed
|
|
362
|
+
*/
|
|
363
|
+
onPreToolUse?: PreToolUseHandler;
|
|
364
|
+
/**
|
|
365
|
+
* Called after a tool is executed
|
|
366
|
+
*/
|
|
367
|
+
onPostToolUse?: PostToolUseHandler;
|
|
368
|
+
/**
|
|
369
|
+
* Called when the user submits a prompt
|
|
370
|
+
*/
|
|
371
|
+
onUserPromptSubmitted?: UserPromptSubmittedHandler;
|
|
372
|
+
/**
|
|
373
|
+
* Called when a session starts
|
|
374
|
+
*/
|
|
375
|
+
onSessionStart?: SessionStartHandler;
|
|
376
|
+
/**
|
|
377
|
+
* Called when a session ends
|
|
378
|
+
*/
|
|
379
|
+
onSessionEnd?: SessionEndHandler;
|
|
380
|
+
/**
|
|
381
|
+
* Called when an error occurs
|
|
382
|
+
*/
|
|
383
|
+
onErrorOccurred?: ErrorOccurredHandler;
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Base interface for MCP server configuration.
|
|
387
|
+
*/
|
|
388
|
+
interface MCPServerConfigBase {
|
|
389
|
+
/**
|
|
390
|
+
* List of tools to include from this server. [] means none. "*" means all.
|
|
391
|
+
*/
|
|
392
|
+
tools: string[];
|
|
393
|
+
/**
|
|
394
|
+
* Indicates "remote" or "local" server type.
|
|
395
|
+
* If not specified, defaults to "local".
|
|
396
|
+
*/
|
|
397
|
+
type?: string;
|
|
398
|
+
/**
|
|
399
|
+
* Optional timeout in milliseconds for tool calls to this server.
|
|
400
|
+
*/
|
|
401
|
+
timeout?: number;
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Configuration for a local/stdio MCP server.
|
|
405
|
+
*/
|
|
406
|
+
export interface MCPLocalServerConfig extends MCPServerConfigBase {
|
|
407
|
+
type?: "local" | "stdio";
|
|
408
|
+
command: string;
|
|
409
|
+
args: string[];
|
|
410
|
+
/**
|
|
411
|
+
* Environment variables to pass to the server.
|
|
412
|
+
*/
|
|
413
|
+
env?: Record<string, string>;
|
|
414
|
+
cwd?: string;
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* Configuration for a remote MCP server (HTTP or SSE).
|
|
418
|
+
*/
|
|
419
|
+
export interface MCPRemoteServerConfig extends MCPServerConfigBase {
|
|
420
|
+
type: "http" | "sse";
|
|
421
|
+
/**
|
|
422
|
+
* URL of the remote server.
|
|
423
|
+
*/
|
|
424
|
+
url: string;
|
|
425
|
+
/**
|
|
426
|
+
* Optional HTTP headers to include in requests.
|
|
427
|
+
*/
|
|
428
|
+
headers?: Record<string, string>;
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Union type for MCP server configurations.
|
|
432
|
+
*/
|
|
433
|
+
export type MCPServerConfig = MCPLocalServerConfig | MCPRemoteServerConfig;
|
|
434
|
+
/**
|
|
435
|
+
* Configuration for a custom agent.
|
|
436
|
+
*/
|
|
437
|
+
export interface CustomAgentConfig {
|
|
438
|
+
/**
|
|
439
|
+
* Unique name of the custom agent.
|
|
440
|
+
*/
|
|
441
|
+
name: string;
|
|
442
|
+
/**
|
|
443
|
+
* Display name for UI purposes.
|
|
444
|
+
*/
|
|
445
|
+
displayName?: string;
|
|
446
|
+
/**
|
|
447
|
+
* Description of what the agent does.
|
|
448
|
+
*/
|
|
449
|
+
description?: string;
|
|
450
|
+
/**
|
|
451
|
+
* List of tool names the agent can use.
|
|
452
|
+
* Use null or undefined for all tools.
|
|
453
|
+
*/
|
|
454
|
+
tools?: string[] | null;
|
|
455
|
+
/**
|
|
456
|
+
* The prompt content for the agent.
|
|
457
|
+
*/
|
|
458
|
+
prompt: string;
|
|
459
|
+
/**
|
|
460
|
+
* MCP servers specific to this agent.
|
|
461
|
+
*/
|
|
462
|
+
mcpServers?: Record<string, MCPServerConfig>;
|
|
463
|
+
/**
|
|
464
|
+
* Whether the agent should be available for model inference.
|
|
465
|
+
* @default true
|
|
466
|
+
*/
|
|
467
|
+
infer?: boolean;
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* Configuration for infinite sessions with automatic context compaction and workspace persistence.
|
|
471
|
+
* When enabled, sessions automatically manage context window limits through background compaction
|
|
472
|
+
* and persist state to a workspace directory.
|
|
473
|
+
*/
|
|
474
|
+
export interface InfiniteSessionConfig {
|
|
475
|
+
/**
|
|
476
|
+
* Whether infinite sessions are enabled.
|
|
477
|
+
* @default true
|
|
478
|
+
*/
|
|
479
|
+
enabled?: boolean;
|
|
480
|
+
/**
|
|
481
|
+
* Context utilization threshold (0.0-1.0) at which background compaction starts.
|
|
482
|
+
* Compaction runs asynchronously, allowing the session to continue processing.
|
|
483
|
+
* @default 0.80
|
|
484
|
+
*/
|
|
485
|
+
backgroundCompactionThreshold?: number;
|
|
486
|
+
/**
|
|
487
|
+
* Context utilization threshold (0.0-1.0) at which the session blocks until compaction completes.
|
|
488
|
+
* This prevents context overflow when compaction hasn't finished in time.
|
|
489
|
+
* @default 0.95
|
|
490
|
+
*/
|
|
491
|
+
bufferExhaustionThreshold?: number;
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* Valid reasoning effort levels for models that support it.
|
|
495
|
+
*/
|
|
496
|
+
export type ReasoningEffort = "low" | "medium" | "high" | "xhigh";
|
|
497
|
+
export interface SessionConfig {
|
|
498
|
+
/**
|
|
499
|
+
* Optional custom session ID
|
|
500
|
+
* If not provided, server will generate one
|
|
501
|
+
*/
|
|
502
|
+
sessionId?: string;
|
|
503
|
+
/**
|
|
504
|
+
* Model to use for this session
|
|
505
|
+
*/
|
|
506
|
+
model?: string;
|
|
507
|
+
/**
|
|
508
|
+
* Reasoning effort level for models that support it.
|
|
509
|
+
* Only valid for models where capabilities.supports.reasoningEffort is true.
|
|
510
|
+
* Use client.listModels() to check supported values for each model.
|
|
511
|
+
*/
|
|
512
|
+
reasoningEffort?: ReasoningEffort;
|
|
513
|
+
/**
|
|
514
|
+
* Override the default configuration directory location.
|
|
515
|
+
* When specified, the session will use this directory for storing config and state.
|
|
516
|
+
*/
|
|
517
|
+
configDir?: string;
|
|
518
|
+
/**
|
|
519
|
+
* Tools exposed to the CLI server
|
|
520
|
+
*/
|
|
521
|
+
tools?: Tool<any>[];
|
|
522
|
+
/**
|
|
523
|
+
* System message configuration
|
|
524
|
+
* Controls how the system prompt is constructed
|
|
525
|
+
*/
|
|
526
|
+
systemMessage?: SystemMessageConfig;
|
|
527
|
+
/**
|
|
528
|
+
* List of tool names to allow. When specified, only these tools will be available.
|
|
529
|
+
* Takes precedence over excludedTools.
|
|
530
|
+
*/
|
|
531
|
+
availableTools?: string[];
|
|
532
|
+
/**
|
|
533
|
+
* List of tool names to disable. All other tools remain available.
|
|
534
|
+
* Ignored if availableTools is specified.
|
|
535
|
+
*/
|
|
536
|
+
excludedTools?: string[];
|
|
537
|
+
/**
|
|
538
|
+
* Custom provider configuration (BYOK - Bring Your Own Key).
|
|
539
|
+
* When specified, uses the provided API endpoint instead of the Copilot API.
|
|
540
|
+
*/
|
|
541
|
+
provider?: ProviderConfig;
|
|
542
|
+
/**
|
|
543
|
+
* Handler for permission requests from the server.
|
|
544
|
+
* When provided, the server will call this handler to request permission for operations.
|
|
545
|
+
*/
|
|
546
|
+
onPermissionRequest?: PermissionHandler;
|
|
547
|
+
/**
|
|
548
|
+
* Handler for user input requests from the agent.
|
|
549
|
+
* When provided, enables the ask_user tool allowing the agent to ask questions.
|
|
550
|
+
*/
|
|
551
|
+
onUserInputRequest?: UserInputHandler;
|
|
552
|
+
/**
|
|
553
|
+
* Hook handlers for intercepting session lifecycle events.
|
|
554
|
+
* When provided, enables hooks callback allowing custom logic at various points.
|
|
555
|
+
*/
|
|
556
|
+
hooks?: SessionHooks;
|
|
557
|
+
/**
|
|
558
|
+
* Working directory for the session.
|
|
559
|
+
* Tool operations will be relative to this directory.
|
|
560
|
+
*/
|
|
561
|
+
workingDirectory?: string;
|
|
562
|
+
streaming?: boolean;
|
|
563
|
+
/**
|
|
564
|
+
* MCP server configurations for the session.
|
|
565
|
+
* Keys are server names, values are server configurations.
|
|
566
|
+
*/
|
|
567
|
+
mcpServers?: Record<string, MCPServerConfig>;
|
|
568
|
+
/**
|
|
569
|
+
* Custom agent configurations for the session.
|
|
570
|
+
*/
|
|
571
|
+
customAgents?: CustomAgentConfig[];
|
|
572
|
+
/**
|
|
573
|
+
* Directories to load skills from.
|
|
574
|
+
*/
|
|
575
|
+
skillDirectories?: string[];
|
|
576
|
+
/**
|
|
577
|
+
* List of skill names to disable.
|
|
578
|
+
*/
|
|
579
|
+
disabledSkills?: string[];
|
|
580
|
+
/**
|
|
581
|
+
* Infinite session configuration for persistent workspaces and automatic compaction.
|
|
582
|
+
* When enabled (default), sessions automatically manage context limits and persist state.
|
|
583
|
+
* Set to `{ enabled: false }` to disable.
|
|
584
|
+
*/
|
|
585
|
+
infiniteSessions?: InfiniteSessionConfig;
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* Configuration for resuming a session
|
|
589
|
+
*/
|
|
590
|
+
export type ResumeSessionConfig = Pick<SessionConfig, "model" | "tools" | "systemMessage" | "availableTools" | "excludedTools" | "provider" | "streaming" | "reasoningEffort" | "onPermissionRequest" | "onUserInputRequest" | "hooks" | "workingDirectory" | "configDir" | "mcpServers" | "customAgents" | "skillDirectories" | "disabledSkills" | "infiniteSessions"> & {
|
|
591
|
+
/**
|
|
592
|
+
* When true, skips emitting the session.resume event.
|
|
593
|
+
* Useful for reconnecting to a session without triggering resume-related side effects.
|
|
594
|
+
* @default false
|
|
595
|
+
*/
|
|
596
|
+
disableResume?: boolean;
|
|
597
|
+
};
|
|
598
|
+
/**
|
|
599
|
+
* Configuration for a custom API provider.
|
|
600
|
+
*/
|
|
601
|
+
export interface ProviderConfig {
|
|
602
|
+
/**
|
|
603
|
+
* Provider type. Defaults to "openai" for generic OpenAI-compatible APIs.
|
|
604
|
+
*/
|
|
605
|
+
type?: "openai" | "azure" | "anthropic";
|
|
606
|
+
/**
|
|
607
|
+
* API format (openai/azure only). Defaults to "completions".
|
|
608
|
+
*/
|
|
609
|
+
wireApi?: "completions" | "responses";
|
|
610
|
+
/**
|
|
611
|
+
* API endpoint URL
|
|
612
|
+
*/
|
|
613
|
+
baseUrl: string;
|
|
614
|
+
/**
|
|
615
|
+
* API key. Optional for local providers like Ollama.
|
|
616
|
+
*/
|
|
617
|
+
apiKey?: string;
|
|
618
|
+
/**
|
|
619
|
+
* Bearer token for authentication. Sets the Authorization header directly.
|
|
620
|
+
* Use this for services requiring bearer token auth instead of API key.
|
|
621
|
+
* Takes precedence over apiKey when both are set.
|
|
622
|
+
*/
|
|
623
|
+
bearerToken?: string;
|
|
624
|
+
/**
|
|
625
|
+
* Azure-specific options
|
|
626
|
+
*/
|
|
627
|
+
azure?: {
|
|
628
|
+
/**
|
|
629
|
+
* API version. Defaults to "2024-10-21".
|
|
630
|
+
*/
|
|
631
|
+
apiVersion?: string;
|
|
632
|
+
};
|
|
633
|
+
}
|
|
634
|
+
/**
|
|
635
|
+
* Options for sending a message to a session
|
|
636
|
+
*/
|
|
637
|
+
export interface MessageOptions {
|
|
638
|
+
/**
|
|
639
|
+
* The prompt/message to send
|
|
640
|
+
*/
|
|
641
|
+
prompt: string;
|
|
642
|
+
/**
|
|
643
|
+
* File, directory, or selection attachments
|
|
644
|
+
*/
|
|
645
|
+
attachments?: Array<{
|
|
646
|
+
type: "file";
|
|
647
|
+
path: string;
|
|
648
|
+
displayName?: string;
|
|
649
|
+
} | {
|
|
650
|
+
type: "directory";
|
|
651
|
+
path: string;
|
|
652
|
+
displayName?: string;
|
|
653
|
+
} | {
|
|
654
|
+
type: "selection";
|
|
655
|
+
filePath: string;
|
|
656
|
+
displayName: string;
|
|
657
|
+
selection?: {
|
|
658
|
+
start: {
|
|
659
|
+
line: number;
|
|
660
|
+
character: number;
|
|
661
|
+
};
|
|
662
|
+
end: {
|
|
663
|
+
line: number;
|
|
664
|
+
character: number;
|
|
665
|
+
};
|
|
666
|
+
};
|
|
667
|
+
text?: string;
|
|
668
|
+
}>;
|
|
669
|
+
/**
|
|
670
|
+
* Message delivery mode
|
|
671
|
+
* - "enqueue": Add to queue (default)
|
|
672
|
+
* - "immediate": Send immediately
|
|
673
|
+
*/
|
|
674
|
+
mode?: "enqueue" | "immediate";
|
|
675
|
+
}
|
|
676
|
+
/**
|
|
677
|
+
* All possible event type strings from SessionEvent
|
|
678
|
+
*/
|
|
679
|
+
export type SessionEventType = SessionEvent["type"];
|
|
680
|
+
/**
|
|
681
|
+
* Extract the specific event payload for a given event type
|
|
682
|
+
*/
|
|
683
|
+
export type SessionEventPayload<T extends SessionEventType> = Extract<SessionEvent, {
|
|
684
|
+
type: T;
|
|
685
|
+
}>;
|
|
686
|
+
/**
|
|
687
|
+
* Event handler for a specific event type
|
|
688
|
+
*/
|
|
689
|
+
export type TypedSessionEventHandler<T extends SessionEventType> = (event: SessionEventPayload<T>) => void;
|
|
690
|
+
/**
|
|
691
|
+
* Event handler callback type (for all events)
|
|
692
|
+
*/
|
|
693
|
+
export type SessionEventHandler = (event: SessionEvent) => void;
|
|
694
|
+
/**
|
|
695
|
+
* Connection state
|
|
696
|
+
*/
|
|
697
|
+
export type ConnectionState = "disconnected" | "connecting" | "connected" | "error";
|
|
698
|
+
/**
|
|
699
|
+
* Metadata about a session
|
|
700
|
+
*/
|
|
701
|
+
export interface SessionMetadata {
|
|
702
|
+
sessionId: string;
|
|
703
|
+
startTime: Date;
|
|
704
|
+
modifiedTime: Date;
|
|
705
|
+
summary?: string;
|
|
706
|
+
isRemote: boolean;
|
|
707
|
+
}
|
|
708
|
+
/**
|
|
709
|
+
* Response from status.get
|
|
710
|
+
*/
|
|
711
|
+
export interface GetStatusResponse {
|
|
712
|
+
/** Package version (e.g., "1.0.0") */
|
|
713
|
+
version: string;
|
|
714
|
+
/** Protocol version for SDK compatibility */
|
|
715
|
+
protocolVersion: number;
|
|
716
|
+
}
|
|
717
|
+
/**
|
|
718
|
+
* Response from auth.getStatus
|
|
719
|
+
*/
|
|
720
|
+
export interface GetAuthStatusResponse {
|
|
721
|
+
/** Whether the user is authenticated */
|
|
722
|
+
isAuthenticated: boolean;
|
|
723
|
+
/** Authentication type */
|
|
724
|
+
authType?: "user" | "env" | "gh-cli" | "hmac" | "api-key" | "token";
|
|
725
|
+
/** GitHub host URL */
|
|
726
|
+
host?: string;
|
|
727
|
+
/** User login name */
|
|
728
|
+
login?: string;
|
|
729
|
+
/** Human-readable status message */
|
|
730
|
+
statusMessage?: string;
|
|
731
|
+
}
|
|
732
|
+
/**
|
|
733
|
+
* Model capabilities and limits
|
|
734
|
+
*/
|
|
735
|
+
export interface ModelCapabilities {
|
|
736
|
+
supports: {
|
|
737
|
+
vision: boolean;
|
|
738
|
+
/** Whether this model supports reasoning effort configuration */
|
|
739
|
+
reasoningEffort: boolean;
|
|
740
|
+
};
|
|
741
|
+
limits: {
|
|
742
|
+
max_prompt_tokens?: number;
|
|
743
|
+
max_context_window_tokens: number;
|
|
744
|
+
vision?: {
|
|
745
|
+
supported_media_types: string[];
|
|
746
|
+
max_prompt_images: number;
|
|
747
|
+
max_prompt_image_size: number;
|
|
748
|
+
};
|
|
749
|
+
};
|
|
750
|
+
}
|
|
751
|
+
/**
|
|
752
|
+
* Model policy state
|
|
753
|
+
*/
|
|
754
|
+
export interface ModelPolicy {
|
|
755
|
+
state: "enabled" | "disabled" | "unconfigured";
|
|
756
|
+
terms: string;
|
|
757
|
+
}
|
|
758
|
+
/**
|
|
759
|
+
* Model billing information
|
|
760
|
+
*/
|
|
761
|
+
export interface ModelBilling {
|
|
762
|
+
multiplier: number;
|
|
763
|
+
}
|
|
764
|
+
/**
|
|
765
|
+
* Information about an available model
|
|
766
|
+
*/
|
|
767
|
+
export interface ModelInfo {
|
|
768
|
+
/** Model identifier (e.g., "claude-sonnet-4.5") */
|
|
769
|
+
id: string;
|
|
770
|
+
/** Display name */
|
|
771
|
+
name: string;
|
|
772
|
+
/** Model capabilities and limits */
|
|
773
|
+
capabilities: ModelCapabilities;
|
|
774
|
+
/** Policy state */
|
|
775
|
+
policy?: ModelPolicy;
|
|
776
|
+
/** Billing information */
|
|
777
|
+
billing?: ModelBilling;
|
|
778
|
+
/** Supported reasoning effort levels (only present if model supports reasoning effort) */
|
|
779
|
+
supportedReasoningEfforts?: ReasoningEffort[];
|
|
780
|
+
/** Default reasoning effort level (only present if model supports reasoning effort) */
|
|
781
|
+
defaultReasoningEffort?: ReasoningEffort;
|
|
782
|
+
}
|
|
783
|
+
/**
|
|
784
|
+
* Types of session lifecycle events
|
|
785
|
+
*/
|
|
786
|
+
export type SessionLifecycleEventType = "session.created" | "session.deleted" | "session.updated" | "session.foreground" | "session.background";
|
|
787
|
+
/**
|
|
788
|
+
* Session lifecycle event notification
|
|
789
|
+
* Sent when sessions are created, deleted, updated, or change foreground/background state
|
|
790
|
+
*/
|
|
791
|
+
export interface SessionLifecycleEvent {
|
|
792
|
+
/** Type of lifecycle event */
|
|
793
|
+
type: SessionLifecycleEventType;
|
|
794
|
+
/** ID of the session this event relates to */
|
|
795
|
+
sessionId: string;
|
|
796
|
+
/** Session metadata (not included for deleted sessions) */
|
|
797
|
+
metadata?: {
|
|
798
|
+
startTime: string;
|
|
799
|
+
modifiedTime: string;
|
|
800
|
+
summary?: string;
|
|
801
|
+
};
|
|
802
|
+
}
|
|
803
|
+
/**
|
|
804
|
+
* Handler for session lifecycle events
|
|
805
|
+
*/
|
|
806
|
+
export type SessionLifecycleHandler = (event: SessionLifecycleEvent) => void;
|
|
807
|
+
/**
|
|
808
|
+
* Typed handler for specific session lifecycle event types
|
|
809
|
+
*/
|
|
810
|
+
export type TypedSessionLifecycleHandler<K extends SessionLifecycleEventType> = (event: SessionLifecycleEvent & {
|
|
811
|
+
type: K;
|
|
812
|
+
}) => void;
|
|
813
|
+
/**
|
|
814
|
+
* Information about the foreground session in TUI+server mode
|
|
815
|
+
*/
|
|
816
|
+
export interface ForegroundSessionInfo {
|
|
817
|
+
/** ID of the foreground session, or undefined if none */
|
|
818
|
+
sessionId?: string;
|
|
819
|
+
/** Workspace path of the foreground session */
|
|
820
|
+
workspacePath?: string;
|
|
821
|
+
}
|
|
822
|
+
export {};
|