@github/copilot-sdk-darwin-arm64 0.0.1 → 1.0.13-preview.6
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/animations/app-install-nudge.json.gz +0 -0
- package/animations/banner.json.gz +0 -0
- package/builtin/customize-cloud-agent/SKILL.md +254 -0
- package/builtin/discover-resources/SKILL.md +35 -0
- package/builtin/github-pr-media/SKILL.md +108 -0
- package/builtin-skills/customize-cloud-agent/SKILL.md +254 -0
- package/builtin-skills/discover-resources/SKILL.md +35 -0
- package/builtin-skills/github-pr-media/SKILL.md +108 -0
- package/copilot-sdk/canvas.d.ts +126 -0
- package/copilot-sdk/client.d.ts +478 -0
- package/copilot-sdk/copilotRequestHandler.d.ts +85 -0
- package/copilot-sdk/docs/agent-author.md +295 -0
- package/copilot-sdk/docs/examples.md +682 -0
- package/copilot-sdk/docs/extensions.md +81 -0
- package/copilot-sdk/docs/factories.md +279 -0
- package/copilot-sdk/docs/factory-patterns.md +194 -0
- package/copilot-sdk/extension.d.ts +59 -0
- package/copilot-sdk/extension.js +11399 -0
- package/copilot-sdk/factory.d.ts +301 -0
- package/copilot-sdk/ffiRuntimeHost.d.ts +35 -0
- package/copilot-sdk/generated/rpc.d.ts +24623 -0
- package/copilot-sdk/generated/session-events.d.ts +11117 -0
- package/copilot-sdk/index.d.ts +15 -0
- package/copilot-sdk/index.js +11540 -0
- package/copilot-sdk/runtimeArtifacts.d.ts +6 -0
- package/copilot-sdk/sdkProtocolVersion.d.ts +10 -0
- package/copilot-sdk/session.d.ts +331 -0
- package/copilot-sdk/sessionFsProvider.d.ts +107 -0
- package/copilot-sdk/telemetry.d.ts +14 -0
- package/copilot-sdk/toolSet.d.ts +75 -0
- package/copilot-sdk/types.d.ts +2974 -0
- package/definitions/code-review.agent.yaml +94 -0
- package/definitions/explore.agent.yaml +75 -0
- package/definitions/rem-agent.agent.yaml +22 -0
- package/definitions/research.agent.yaml +111 -0
- package/definitions/rubber-duck.agent.yaml +67 -0
- package/definitions/security-review.agent.yaml +261 -0
- package/definitions/sidekick/cloud-session-search.yaml +37 -0
- package/definitions/sidekick/github-context-memory.yaml +46 -0
- package/definitions/sidekick/github-context.yaml +44 -0
- package/definitions/sidekick/session-search.yaml +37 -0
- package/definitions/sidekick/subconscious-agent.yaml +60 -0
- package/definitions/sidekick/test-sidekick-context-changed.yaml +24 -0
- package/definitions/sidekick/test-sidekick-persistent.yaml +23 -0
- package/definitions/sidekick/test-sidekick-restart.yaml +23 -0
- package/definitions/sidekick/test-sidekick-trigger-once.yaml +22 -0
- package/definitions/task.agent.yaml +44 -0
- package/package.json +14 -11
- package/plugins/computer-use/.mcp.json +10 -0
- package/plugins/computer-use/.plugin/plugin.json +6 -0
- package/plugins/computer-use/.release-target +1 -0
- package/plugins/computer-use/Copilot Computer Use.app/Contents/CodeResources +0 -0
- package/plugins/computer-use/Copilot Computer Use.app/Contents/Info.plist +38 -0
- package/plugins/computer-use/Copilot Computer Use.app/Contents/MacOS/Copilot Computer Use +0 -0
- package/plugins/computer-use/Copilot Computer Use.app/Contents/PkgInfo +1 -0
- package/plugins/computer-use/Copilot Computer Use.app/Contents/Resources/Assets.car +0 -0
- package/plugins/computer-use/Copilot Computer Use.app/Contents/Resources/icon.icns +0 -0
- package/plugins/computer-use/Copilot Computer Use.app/Contents/_CodeSignature/CodeResources +139 -0
- package/plugins/computer-use/computer-use-mcp +0 -0
- package/prebuilds/darwin-arm64/copilot-runtime +0 -0
- package/prebuilds/darwin-arm64/runtime.node +0 -0
- package/preloads/extension_bootstrap.mjs +68 -0
- package/preloads/extension_sdk_resolver.mjs +34 -0
- package/ripgrep/bin/darwin-arm64/rg +0 -0
- package/schemas/api.schema.json +41931 -0
- package/schemas/session-events.schema.json +20937 -0
- package/sdk/index.js +1489 -0
- package/tgrep/bin/darwin-arm64/tgrep +0 -0
- package/README.md +0 -3
|
@@ -0,0 +1,2974 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for the Copilot SDK
|
|
3
|
+
*/
|
|
4
|
+
import type { Canvas } from "./canvas.js";
|
|
5
|
+
import type { SessionFsProvider } from "./sessionFsProvider.js";
|
|
6
|
+
import type { CopilotRequestHandler } from "./copilotRequestHandler.js";
|
|
7
|
+
import type { PermissionRequest as GeneratedPermissionRequest, PermissionRequestedData as GeneratedPermissionRequestedData, PermissionRequestedEvent as GeneratedPermissionRequestedEvent, ReasoningSummary, SessionLimitsConfig, SessionEvent as GeneratedSessionEvent } from "./generated/session-events.js";
|
|
8
|
+
import type { CopilotSession } from "./session.js";
|
|
9
|
+
import type { FactoryJsonSchema, JsonValue } from "./factory.js";
|
|
10
|
+
import type { GitHubTokenAcquireRequest, GitHubTokenAcquireResult, GitHubTelemetryNotification, ModelBillingTokenPrices, OpenCanvasInstance, RemoteSessionMode, CurrentToolMetadata } from "./generated/rpc.js";
|
|
11
|
+
import type { ToolSet } from "./toolSet.js";
|
|
12
|
+
export type { RemoteSessionMode } from "./generated/rpc.js";
|
|
13
|
+
export type { CurrentToolMetadata } from "./generated/rpc.js";
|
|
14
|
+
export type { GitHubTokenAcquireReason, GitHubTokenAcquireResult, GitHubTelemetryNotification, GitHubTelemetryEvent, GitHubTelemetryClientInfo, } from "./generated/rpc.js";
|
|
15
|
+
/**
|
|
16
|
+
* Arguments passed to a session's {@link GitHubTokenProvider}.
|
|
17
|
+
*
|
|
18
|
+
* The callback registration identifier is intentionally kept inside the SDK.
|
|
19
|
+
*/
|
|
20
|
+
export type GitHubTokenProviderArgs = Pick<GitHubTokenAcquireRequest, "host" | "sessionId" | "reason">;
|
|
21
|
+
/** Tagged token or cancellation returned by a {@link GitHubTokenProvider}. */
|
|
22
|
+
export type GitHubTokenProviderResult = GitHubTokenAcquireResult;
|
|
23
|
+
/**
|
|
24
|
+
* Acquires a GitHub token for one session.
|
|
25
|
+
*
|
|
26
|
+
* A token result must include `expiresIn`: the positive number of seconds of
|
|
27
|
+
* remaining lifetime when the callback completes. Production GitHub tokens
|
|
28
|
+
* typically last eight hours. Initial cancellation, callback errors, and
|
|
29
|
+
* invalid token responses reject session creation or resume instead of falling
|
|
30
|
+
* back to ambient authentication.
|
|
31
|
+
*/
|
|
32
|
+
export type GitHubTokenProvider = (args: GitHubTokenProviderArgs) => GitHubTokenProviderResult | Promise<GitHubTokenProviderResult>;
|
|
33
|
+
export type { ModelBillingTokenPrices, ModelBillingTokenPricesLongContext, } from "./generated/rpc.js";
|
|
34
|
+
export type SessionEvent = Exclude<GeneratedSessionEvent, {
|
|
35
|
+
type: "permission.requested";
|
|
36
|
+
}> | PermissionRequestedEvent;
|
|
37
|
+
export type { ReasoningSummary } from "./generated/session-events.js";
|
|
38
|
+
export type { SessionFsProvider } from "./sessionFsProvider.js";
|
|
39
|
+
export { createSessionFsAdapter } from "./sessionFsProvider.js";
|
|
40
|
+
export type { SessionFsFileInfo } from "./sessionFsProvider.js";
|
|
41
|
+
export type { SessionFsSqliteQueryResult } from "./sessionFsProvider.js";
|
|
42
|
+
export type { SessionFsSqliteQueryType } from "./sessionFsProvider.js";
|
|
43
|
+
export type { SessionFsSqliteProvider } from "./sessionFsProvider.js";
|
|
44
|
+
export type { SessionFsSqliteStatement } from "./sessionFsProvider.js";
|
|
45
|
+
export type { SessionFsSqliteTransactionErrorClass } from "./sessionFsProvider.js";
|
|
46
|
+
export { SessionFsSqliteTransactionFailure } from "./sessionFsProvider.js";
|
|
47
|
+
export type { LlmInferenceHeaders } from "./generated/rpc.js";
|
|
48
|
+
export type { PermissionDecisionContext, PermissionDecisionOutcome, PermissionDecisionSource, PermissionDecisionSurface, PermissionResponseCapability, } from "./generated/rpc.js";
|
|
49
|
+
export type { CopilotRequestContext } from "./copilotRequestHandler.js";
|
|
50
|
+
export { CopilotRequestHandler, CopilotWebSocketHandler, CopilotWebSocketCloseStatus, CopilotWebSocketForwarder, } from "./copilotRequestHandler.js";
|
|
51
|
+
/**
|
|
52
|
+
* Options for creating a CopilotClient
|
|
53
|
+
*/
|
|
54
|
+
/**
|
|
55
|
+
* W3C Trace Context headers used for distributed trace propagation.
|
|
56
|
+
*/
|
|
57
|
+
export interface TraceContext {
|
|
58
|
+
traceparent?: string;
|
|
59
|
+
tracestate?: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Callback that returns the current W3C Trace Context.
|
|
63
|
+
* Wire this up to your OpenTelemetry (or other tracing) SDK to enable
|
|
64
|
+
* distributed trace propagation between your app and the Copilot CLI.
|
|
65
|
+
*/
|
|
66
|
+
export type TraceContextProvider = () => TraceContext | Promise<TraceContext>;
|
|
67
|
+
/**
|
|
68
|
+
* Configuration for OpenTelemetry instrumentation.
|
|
69
|
+
*
|
|
70
|
+
* When provided via {@link CopilotClientOptions.telemetry}, the SDK sets
|
|
71
|
+
* the corresponding environment variables on the spawned CLI process so
|
|
72
|
+
* that the CLI's built-in OTel exporter is configured automatically.
|
|
73
|
+
*/
|
|
74
|
+
export interface TelemetryConfig {
|
|
75
|
+
/** OTLP HTTP endpoint URL for trace/metric export. Sets OTEL_EXPORTER_OTLP_ENDPOINT. */
|
|
76
|
+
otlpEndpoint?: string;
|
|
77
|
+
/** OTLP HTTP protocol for all signals. Sets OTEL_EXPORTER_OTLP_PROTOCOL. */
|
|
78
|
+
otlpProtocol?: "http/json" | "http/protobuf";
|
|
79
|
+
/** File path for JSON-lines trace output. Sets COPILOT_OTEL_FILE_EXPORTER_PATH. */
|
|
80
|
+
filePath?: string;
|
|
81
|
+
/** Exporter backend type: "otlp-http" or "file". Sets COPILOT_OTEL_EXPORTER_TYPE. */
|
|
82
|
+
exporterType?: string;
|
|
83
|
+
/** Instrumentation scope name. Sets COPILOT_OTEL_SOURCE_NAME. */
|
|
84
|
+
sourceName?: string;
|
|
85
|
+
/** Whether to capture message content (prompts, responses). Sets OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT. */
|
|
86
|
+
captureContent?: boolean;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Configures how a {@link CopilotClient} connects to the Copilot runtime.
|
|
90
|
+
* Construct via the factory functions on {@link RuntimeConnection}.
|
|
91
|
+
*/
|
|
92
|
+
export type RuntimeConnection = StdioRuntimeConnection | InProcessRuntimeConnection | TcpRuntimeConnection | UriRuntimeConnection;
|
|
93
|
+
/**
|
|
94
|
+
* Shared shape for the transports that spawn a runtime **child process**
|
|
95
|
+
* ({@link StdioRuntimeConnection} and {@link TcpRuntimeConnection}).
|
|
96
|
+
*/
|
|
97
|
+
export interface ChildProcessRuntimeConnection {
|
|
98
|
+
/** Path to the runtime executable. When omitted, the bundled runtime is used. */
|
|
99
|
+
readonly path?: string;
|
|
100
|
+
/** Extra command-line arguments to pass to the runtime process. */
|
|
101
|
+
readonly args?: readonly string[];
|
|
102
|
+
/**
|
|
103
|
+
* Environment variables for the spawned runtime child process, replacing the
|
|
104
|
+
* inherited environment. Cannot be combined with
|
|
105
|
+
* {@link CopilotClientOptions.env}; setting both throws when the client is
|
|
106
|
+
* constructed. When omitted, the client-level env (or `process.env`) is used.
|
|
107
|
+
*/
|
|
108
|
+
readonly env?: Record<string, string>;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Spawns a runtime child process and communicates over its stdin/stdout.
|
|
112
|
+
* This is the default if no {@link CopilotClientOptions.connection} is set.
|
|
113
|
+
*/
|
|
114
|
+
export interface StdioRuntimeConnection extends ChildProcessRuntimeConnection {
|
|
115
|
+
readonly kind: "stdio";
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Hosts the runtime in-process by loading the native runtime library and speaking
|
|
119
|
+
* JSON-RPC over its C ABI (FFI), instead of spawning a runtime child process. The
|
|
120
|
+
* native host spawns the CLI worker itself. Construct via
|
|
121
|
+
* {@link RuntimeConnection.forInProcess}.
|
|
122
|
+
*
|
|
123
|
+
* @experimental The in-process (FFI) transport is experimental and its behavior may
|
|
124
|
+
* change. Per-client options that are lowered to environment variables — including
|
|
125
|
+
* {@link CopilotClientOptions.env}, {@link CopilotClientOptions.telemetry},
|
|
126
|
+
* {@link CopilotClientOptions.gitHubToken}, and
|
|
127
|
+
* {@link CopilotClientOptions.baseDirectory} — are **not** honored with this
|
|
128
|
+
* transport, because the native runtime loads into the shared host process and its
|
|
129
|
+
* worker inherits that process's ambient environment. To configure the in-process
|
|
130
|
+
* runtime, set the corresponding environment variables on the host process before
|
|
131
|
+
* constructing the client. See https://github.com/github/copilot-sdk/issues/1934.
|
|
132
|
+
*/
|
|
133
|
+
export interface InProcessRuntimeConnection {
|
|
134
|
+
readonly kind: "inprocess";
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Spawns a runtime child process that listens on a TCP socket and connects to it.
|
|
138
|
+
*/
|
|
139
|
+
export interface TcpRuntimeConnection extends ChildProcessRuntimeConnection {
|
|
140
|
+
readonly kind: "tcp";
|
|
141
|
+
/**
|
|
142
|
+
* TCP port to listen on. `0` (the default) auto-allocates a free port.
|
|
143
|
+
* If the chosen port is already in use, startup fails.
|
|
144
|
+
*/
|
|
145
|
+
readonly port?: number;
|
|
146
|
+
/**
|
|
147
|
+
* Optional shared secret the SDK sends to the spawned runtime to authenticate
|
|
148
|
+
* the TCP connection. When omitted, a UUID is generated automatically so the
|
|
149
|
+
* loopback listener is safe by default.
|
|
150
|
+
*/
|
|
151
|
+
readonly connectionToken?: string;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Connects to an already-running runtime at the specified URL. The SDK does not
|
|
155
|
+
* spawn a process in this mode.
|
|
156
|
+
*/
|
|
157
|
+
export interface UriRuntimeConnection {
|
|
158
|
+
readonly kind: "uri";
|
|
159
|
+
/**
|
|
160
|
+
* URL of the runtime to connect to. Accepts `"port"`, `"host:port"`, or a
|
|
161
|
+
* full URL (`"http://host:port"`).
|
|
162
|
+
*/
|
|
163
|
+
readonly url: string;
|
|
164
|
+
/** Optional shared secret to authenticate the connection. */
|
|
165
|
+
readonly connectionToken?: string;
|
|
166
|
+
}
|
|
167
|
+
/** Factory functions for constructing {@link RuntimeConnection} instances. */
|
|
168
|
+
export declare const RuntimeConnection: {
|
|
169
|
+
/**
|
|
170
|
+
* Spawn a runtime child process and communicate over its stdin/stdout.
|
|
171
|
+
* This is the default if no {@link CopilotClientOptions.connection} is set.
|
|
172
|
+
*/
|
|
173
|
+
readonly forStdio: (opts?: {
|
|
174
|
+
path?: string;
|
|
175
|
+
args?: readonly string[];
|
|
176
|
+
env?: Record<string, string>;
|
|
177
|
+
}) => StdioRuntimeConnection;
|
|
178
|
+
/**
|
|
179
|
+
* Spawn a runtime child process that listens on a TCP socket and connect to it.
|
|
180
|
+
*/
|
|
181
|
+
readonly forTcp: (opts?: {
|
|
182
|
+
port?: number;
|
|
183
|
+
connectionToken?: string;
|
|
184
|
+
path?: string;
|
|
185
|
+
args?: readonly string[];
|
|
186
|
+
env?: Record<string, string>;
|
|
187
|
+
}) => TcpRuntimeConnection;
|
|
188
|
+
/**
|
|
189
|
+
* Connect to an already-running runtime at the given URL. The SDK does not
|
|
190
|
+
* spawn a process in this mode.
|
|
191
|
+
*/
|
|
192
|
+
readonly forUri: (url: string, opts?: {
|
|
193
|
+
connectionToken?: string;
|
|
194
|
+
}) => UriRuntimeConnection;
|
|
195
|
+
/**
|
|
196
|
+
* Host the runtime in-process over the native runtime library's C ABI (FFI).
|
|
197
|
+
*
|
|
198
|
+
* @experimental Per-client options lowered to environment variables (`env`,
|
|
199
|
+
* `telemetry`, `gitHubToken`, `baseDirectory`) are **not** honored in-process;
|
|
200
|
+
* the worker inherits the host process's ambient environment. Set the
|
|
201
|
+
* corresponding environment variables on the host process instead. See
|
|
202
|
+
* https://github.com/github/copilot-sdk/issues/1934.
|
|
203
|
+
*/
|
|
204
|
+
readonly forInProcess: () => InProcessRuntimeConnection;
|
|
205
|
+
};
|
|
206
|
+
/**
|
|
207
|
+
* Controls SDK defaults for ambient features.
|
|
208
|
+
*
|
|
209
|
+
* - `"copilot-cli"` (default): Defaults equivalent to Copilot CLI. Useful when
|
|
210
|
+
* building a coding agent that shares sessions with Copilot CLI. Do not use
|
|
211
|
+
* this mode for server-based multi-user applications — the default coding
|
|
212
|
+
* agent has tools and capabilities that operate across sessions and can
|
|
213
|
+
* access the host OS environment.
|
|
214
|
+
* - `"empty"`: Disables optional features by default. The app must explicitly
|
|
215
|
+
* opt into anything it needs. Required for any scenario where CLI-like
|
|
216
|
+
* ambient behavior is unsafe (e.g. multi-user servers).
|
|
217
|
+
*/
|
|
218
|
+
export type CopilotClientMode = "empty" | "copilot-cli";
|
|
219
|
+
export interface CopilotClientOptions {
|
|
220
|
+
/**
|
|
221
|
+
* How to connect to the Copilot runtime. When omitted, defaults to
|
|
222
|
+
* {@link RuntimeConnection.forStdio} with the bundled runtime.
|
|
223
|
+
*/
|
|
224
|
+
connection?: RuntimeConnection;
|
|
225
|
+
/**
|
|
226
|
+
* Selects the SDK defaulting strategy. See {@link CopilotClientMode}.
|
|
227
|
+
*
|
|
228
|
+
* When set to `"empty"`, the SDK validates that the app has supplied the
|
|
229
|
+
* required configuration ({@link CopilotClientOptions.baseDirectory} or
|
|
230
|
+
* {@link CopilotClientOptions.sessionFs}, plus
|
|
231
|
+
* {@link SessionConfigBase.availableTools} on each session) and translates
|
|
232
|
+
* session creation requests into runtime options that flip tool filter
|
|
233
|
+
* precedence to deny-wins so exclusions are expressible.
|
|
234
|
+
*
|
|
235
|
+
* @default "copilot-cli"
|
|
236
|
+
*/
|
|
237
|
+
mode?: CopilotClientMode;
|
|
238
|
+
/**
|
|
239
|
+
* Working directory for the runtime process.
|
|
240
|
+
* If not set, inherits the current process's working directory.
|
|
241
|
+
*/
|
|
242
|
+
workingDirectory?: string;
|
|
243
|
+
/**
|
|
244
|
+
* Base directory for Copilot data (session state, config, etc.).
|
|
245
|
+
* Sets the COPILOT_HOME environment variable on the spawned runtime.
|
|
246
|
+
* When not set, the runtime defaults to ~/.copilot.
|
|
247
|
+
* Ignored when connecting to an existing runtime via {@link RuntimeConnection.forUri}.
|
|
248
|
+
*/
|
|
249
|
+
baseDirectory?: string;
|
|
250
|
+
/**
|
|
251
|
+
* Absolute paths to trusted plugin directories bundled by the host.
|
|
252
|
+
* When non-empty, the complete set is registered with the runtime during
|
|
253
|
+
* startup before any sessions can be created.
|
|
254
|
+
*/
|
|
255
|
+
builtinPluginDirectories?: readonly string[];
|
|
256
|
+
/**
|
|
257
|
+
* Log level for the Copilot runtime. When omitted, the runtime uses its
|
|
258
|
+
* own default (currently `"info"`).
|
|
259
|
+
*/
|
|
260
|
+
logLevel?: "none" | "error" | "warning" | "info" | "debug" | "all";
|
|
261
|
+
/**
|
|
262
|
+
* Environment variables to pass to the runtime process. If not set, inherits process.env.
|
|
263
|
+
*/
|
|
264
|
+
env?: Record<string, string | undefined>;
|
|
265
|
+
/**
|
|
266
|
+
* GitHub token to use for authentication.
|
|
267
|
+
* When provided, the token is passed to the runtime via environment variable.
|
|
268
|
+
* This takes priority over other authentication methods.
|
|
269
|
+
*/
|
|
270
|
+
gitHubToken?: string;
|
|
271
|
+
/**
|
|
272
|
+
* Whether to use the logged-in user for authentication.
|
|
273
|
+
* When true, the runtime will attempt to use stored OAuth tokens or gh CLI auth.
|
|
274
|
+
* When false, only explicit tokens (gitHubToken or environment variables) are used.
|
|
275
|
+
* @default true (but defaults to false when gitHubToken is provided)
|
|
276
|
+
*/
|
|
277
|
+
useLoggedInUser?: boolean;
|
|
278
|
+
/**
|
|
279
|
+
* Custom handler for listing available models.
|
|
280
|
+
* When provided, client.listModels() calls this handler instead of
|
|
281
|
+
* querying the runtime. Useful in BYOK mode to return models
|
|
282
|
+
* available from your custom provider.
|
|
283
|
+
*/
|
|
284
|
+
onListModels?: () => Promise<ModelInfo[]> | ModelInfo[];
|
|
285
|
+
/**
|
|
286
|
+
* OpenTelemetry configuration for the runtime process.
|
|
287
|
+
* When provided, the corresponding OTel environment variables are set
|
|
288
|
+
* on the spawned runtime.
|
|
289
|
+
*/
|
|
290
|
+
telemetry?: TelemetryConfig;
|
|
291
|
+
/**
|
|
292
|
+
* Advanced: callback that returns the current W3C Trace Context for distributed
|
|
293
|
+
* trace propagation. Most users do not need this — the {@link telemetry} config
|
|
294
|
+
* alone is sufficient to collect traces from the CLI.
|
|
295
|
+
*
|
|
296
|
+
* This callback is only useful when your application creates its own
|
|
297
|
+
* OpenTelemetry spans and you want them to appear in the **same** distributed
|
|
298
|
+
* trace as the CLI's spans. The SDK calls this before `session.create`,
|
|
299
|
+
* `session.resume`, and `session.send` RPCs to inject `traceparent`/`tracestate`
|
|
300
|
+
* into the request.
|
|
301
|
+
*
|
|
302
|
+
* @example
|
|
303
|
+
* ```typescript
|
|
304
|
+
* import { propagation, context } from "@opentelemetry/api";
|
|
305
|
+
*
|
|
306
|
+
* const client = new CopilotClient({
|
|
307
|
+
* onGetTraceContext: () => {
|
|
308
|
+
* const carrier: Record<string, string> = {};
|
|
309
|
+
* propagation.inject(context.active(), carrier);
|
|
310
|
+
* return carrier;
|
|
311
|
+
* },
|
|
312
|
+
* });
|
|
313
|
+
* ```
|
|
314
|
+
*/
|
|
315
|
+
onGetTraceContext?: TraceContextProvider;
|
|
316
|
+
/**
|
|
317
|
+
* Custom session filesystem provider.
|
|
318
|
+
* When provided, the client registers as the session filesystem provider
|
|
319
|
+
* on connection, routing all session-scoped file I/O through these callbacks
|
|
320
|
+
* instead of the server's default local filesystem storage.
|
|
321
|
+
*/
|
|
322
|
+
sessionFs?: SessionFsConfig;
|
|
323
|
+
/**
|
|
324
|
+
* Custom handler for outbound model-layer requests (experimental).
|
|
325
|
+
*
|
|
326
|
+
* When provided, the client registers as the runtime's request handler
|
|
327
|
+
* on connection: every outbound model-layer request the runtime would
|
|
328
|
+
* otherwise have issued itself — plain HTTP, streaming SSE, and
|
|
329
|
+
* WebSocket — is dispatched back to the handler over JSON-RPC. The
|
|
330
|
+
* handler returns the response verbatim, exactly as if the runtime had
|
|
331
|
+
* issued the request itself.
|
|
332
|
+
*
|
|
333
|
+
* Subclass {@link CopilotRequestHandler} and override the hooks you need;
|
|
334
|
+
* an instance that overrides nothing is a transparent pass-through.
|
|
335
|
+
*
|
|
336
|
+
* v1 notes:
|
|
337
|
+
* - HTTP (buffered and streaming SSE) and WebSocket transports are all
|
|
338
|
+
* intercepted. The handler receives a `transport` discriminator on the
|
|
339
|
+
* {@link CopilotRequestContext} for both.
|
|
340
|
+
* - The handler is set process-globally on the runtime; the same
|
|
341
|
+
* handler is invoked for every session created on this client.
|
|
342
|
+
*
|
|
343
|
+
* @experimental
|
|
344
|
+
*/
|
|
345
|
+
requestHandler?: CopilotRequestHandler;
|
|
346
|
+
/**
|
|
347
|
+
* Experimental. Receives GitHub telemetry events the runtime forwards to
|
|
348
|
+
* this connection. When set, the client opts each session it creates or
|
|
349
|
+
* resumes into telemetry forwarding and dispatches each
|
|
350
|
+
* `gitHubTelemetry.event` notification to this connection-global handler;
|
|
351
|
+
* each {@link GitHubTelemetryNotification} carries its originating
|
|
352
|
+
* `sessionId`.
|
|
353
|
+
*
|
|
354
|
+
* @experimental
|
|
355
|
+
*/
|
|
356
|
+
onGitHubTelemetry?: (notification: GitHubTelemetryNotification) => void | Promise<void>;
|
|
357
|
+
/**
|
|
358
|
+
* Server-wide idle timeout for sessions in seconds.
|
|
359
|
+
* Sessions without activity for this duration are automatically cleaned up.
|
|
360
|
+
* Set to 0 or omit to disable (sessions live indefinitely).
|
|
361
|
+
* Ignored when connecting to an existing runtime via {@link RuntimeConnection.forUri}.
|
|
362
|
+
* @default undefined (disabled)
|
|
363
|
+
*/
|
|
364
|
+
sessionIdleTimeoutSeconds?: number;
|
|
365
|
+
/**
|
|
366
|
+
* Enable remote session support (Mission Control integration).
|
|
367
|
+
* When true, sessions in a GitHub repository working directory are
|
|
368
|
+
* accessible from GitHub web and mobile.
|
|
369
|
+
* Ignored when connecting to an existing runtime via {@link RuntimeConnection.forUri}.
|
|
370
|
+
* @default false
|
|
371
|
+
*/
|
|
372
|
+
enableRemoteSessions?: boolean;
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Configuration for creating a session
|
|
376
|
+
*/
|
|
377
|
+
export type ToolResultType = "success" | "failure" | "rejected" | "denied" | "timeout";
|
|
378
|
+
export type ToolBinaryResult = {
|
|
379
|
+
data: string;
|
|
380
|
+
mimeType: string;
|
|
381
|
+
type: "image" | "resource";
|
|
382
|
+
description?: string;
|
|
383
|
+
};
|
|
384
|
+
export type ToolTelemetry = Record<string, Record<string, JsonValue> | undefined>;
|
|
385
|
+
export type ToolResultObject = {
|
|
386
|
+
textResultForLlm: string;
|
|
387
|
+
binaryResultsForLlm?: ToolBinaryResult[];
|
|
388
|
+
resultType: ToolResultType;
|
|
389
|
+
error?: string;
|
|
390
|
+
sessionLog?: string;
|
|
391
|
+
toolTelemetry?: ToolTelemetry;
|
|
392
|
+
/**
|
|
393
|
+
* Names of tools returned by a tool-search tool.
|
|
394
|
+
*/
|
|
395
|
+
toolReferences?: string[];
|
|
396
|
+
};
|
|
397
|
+
export type ToolResult = string | ToolResultObject;
|
|
398
|
+
/**
|
|
399
|
+
* GitHub repository metadata to associate with a cloud session.
|
|
400
|
+
*/
|
|
401
|
+
export interface CloudSessionRepository {
|
|
402
|
+
owner: string;
|
|
403
|
+
name: string;
|
|
404
|
+
branch?: string;
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Options for creating a remote session in the cloud.
|
|
408
|
+
*/
|
|
409
|
+
export interface CloudSessionOptions {
|
|
410
|
+
repository?: CloudSessionRepository;
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Content block types within an MCP CallToolResult.
|
|
414
|
+
*/
|
|
415
|
+
type McpCallToolResultTextContent = {
|
|
416
|
+
type: "text";
|
|
417
|
+
text: string;
|
|
418
|
+
};
|
|
419
|
+
type McpCallToolResultImageContent = {
|
|
420
|
+
type: "image";
|
|
421
|
+
data: string;
|
|
422
|
+
mimeType: string;
|
|
423
|
+
};
|
|
424
|
+
type McpCallToolResultResourceContent = {
|
|
425
|
+
type: "resource";
|
|
426
|
+
resource: {
|
|
427
|
+
uri: string;
|
|
428
|
+
mimeType?: string;
|
|
429
|
+
text?: string;
|
|
430
|
+
blob?: string;
|
|
431
|
+
};
|
|
432
|
+
};
|
|
433
|
+
type McpCallToolResultContent = McpCallToolResultTextContent | McpCallToolResultImageContent | McpCallToolResultResourceContent;
|
|
434
|
+
/**
|
|
435
|
+
* MCP-compatible CallToolResult type. Can be passed to
|
|
436
|
+
* {@link convertMcpCallToolResult} to produce a {@link ToolResultObject}.
|
|
437
|
+
*/
|
|
438
|
+
type McpCallToolResult = {
|
|
439
|
+
content: McpCallToolResultContent[];
|
|
440
|
+
isError?: boolean;
|
|
441
|
+
};
|
|
442
|
+
/**
|
|
443
|
+
* Converts an MCP CallToolResult into the SDK's ToolResultObject format.
|
|
444
|
+
*/
|
|
445
|
+
export declare function convertMcpCallToolResult(callResult: McpCallToolResult): ToolResultObject;
|
|
446
|
+
export interface ToolInvocation {
|
|
447
|
+
sessionId: string;
|
|
448
|
+
toolCallId: string;
|
|
449
|
+
toolName: string;
|
|
450
|
+
arguments: unknown;
|
|
451
|
+
/**
|
|
452
|
+
* Snapshot of the session's currently initialized tools. Populated by the
|
|
453
|
+
* SDK only when this invocation targets the built-in tool-search tool
|
|
454
|
+
* (`tool_search_tool`), so a tool-search override can rank/filter the live
|
|
455
|
+
* catalog — including MCP tools configured in settings — without issuing its
|
|
456
|
+
* own RPC. `undefined` for every other tool invocation.
|
|
457
|
+
*/
|
|
458
|
+
availableTools?: CurrentToolMetadata[];
|
|
459
|
+
/** W3C Trace Context traceparent from the CLI's execute_tool span. */
|
|
460
|
+
traceparent?: string;
|
|
461
|
+
/** W3C Trace Context tracestate from the CLI's execute_tool span. */
|
|
462
|
+
tracestate?: string;
|
|
463
|
+
}
|
|
464
|
+
export type ToolHandler<TArgs = unknown> = (args: TArgs, invocation: ToolInvocation) => Promise<unknown> | unknown;
|
|
465
|
+
/**
|
|
466
|
+
* Zod-like schema interface for type inference.
|
|
467
|
+
* Any object with `toJSONSchema()` method is treated as a Zod schema.
|
|
468
|
+
*/
|
|
469
|
+
export interface ZodSchema<T = unknown> {
|
|
470
|
+
_output: T;
|
|
471
|
+
toJSONSchema(): Record<string, unknown>;
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Tool definition. Parameters can be either:
|
|
475
|
+
* - A Zod schema (provides type inference for handler)
|
|
476
|
+
* - A raw JSON schema object
|
|
477
|
+
* - Omitted (no parameters)
|
|
478
|
+
*
|
|
479
|
+
* If `handler` is omitted, the SDK exposes the declaration but does not
|
|
480
|
+
* automatically invoke the tool. Consumers can resolve tool calls by observing
|
|
481
|
+
* external tool request events and calling the pending-tool RPC.
|
|
482
|
+
*/
|
|
483
|
+
export interface Tool<TArgs = unknown> {
|
|
484
|
+
name: string;
|
|
485
|
+
description?: string;
|
|
486
|
+
parameters?: ZodSchema<TArgs> | Record<string, unknown>;
|
|
487
|
+
handler?: ToolHandler<TArgs>;
|
|
488
|
+
/**
|
|
489
|
+
* When true, explicitly indicates this tool is intended to override a built-in tool
|
|
490
|
+
* of the same name. If not set and the name clashes with a built-in tool, the runtime
|
|
491
|
+
* will return an error.
|
|
492
|
+
*/
|
|
493
|
+
overridesBuiltInTool?: boolean;
|
|
494
|
+
/**
|
|
495
|
+
* When true, the tool can execute without a permission prompt.
|
|
496
|
+
*/
|
|
497
|
+
skipPermission?: boolean;
|
|
498
|
+
/**
|
|
499
|
+
* Controls whether the tool may be deferred (loaded lazily via tool search)
|
|
500
|
+
* rather than always pre-loaded. When `"auto"`, the tool can be deferred and
|
|
501
|
+
* surfaced through tool search. When `"never"`, the tool is always pre-loaded.
|
|
502
|
+
* Optional; defaults to `"auto"`.
|
|
503
|
+
*/
|
|
504
|
+
defer?: "auto" | "never";
|
|
505
|
+
/**
|
|
506
|
+
* Opaque, host-defined metadata associated with the tool definition.
|
|
507
|
+
*
|
|
508
|
+
* Keys are namespaced and are not part of the stable public API. Values are
|
|
509
|
+
* not interpreted and may be recognized to inform host-specific behavior.
|
|
510
|
+
* Unknown keys are preserved and round-tripped untouched.
|
|
511
|
+
*/
|
|
512
|
+
metadata?: Record<string, unknown>;
|
|
513
|
+
/**
|
|
514
|
+
* When true, a successful call to this tool ends the agent turn: the runtime's
|
|
515
|
+
* tool phase halts instead of feeding the tool result back to the model for
|
|
516
|
+
* another round. A failed call (for example input validation) leaves the loop
|
|
517
|
+
* running so the model can read the error and retry.
|
|
518
|
+
*
|
|
519
|
+
* Use this for tools whose whole purpose is to terminate the turn, such as a
|
|
520
|
+
* context clear that replaces the conversation the model would otherwise
|
|
521
|
+
* continue from.
|
|
522
|
+
*/
|
|
523
|
+
isTerminal?: boolean;
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* Helper to define a tool with Zod schema and get type inference for the handler.
|
|
527
|
+
* Without this helper, TypeScript cannot infer handler argument types from Zod schemas.
|
|
528
|
+
*/
|
|
529
|
+
export declare function defineTool<T = unknown>(name: string, config: {
|
|
530
|
+
description?: string;
|
|
531
|
+
parameters?: ZodSchema<T> | Record<string, unknown>;
|
|
532
|
+
handler?: ToolHandler<T>;
|
|
533
|
+
overridesBuiltInTool?: boolean;
|
|
534
|
+
skipPermission?: boolean;
|
|
535
|
+
defer?: "auto" | "never";
|
|
536
|
+
metadata?: Record<string, unknown>;
|
|
537
|
+
isTerminal?: boolean;
|
|
538
|
+
}): Tool<T>;
|
|
539
|
+
/**
|
|
540
|
+
* SDK-supplied override for the runtime's built-in tool-search behavior.
|
|
541
|
+
*
|
|
542
|
+
* Tool search lets the model discover tools on demand instead of loading every
|
|
543
|
+
* tool definition up front. When the total tool count exceeds the deferral
|
|
544
|
+
* threshold, MCP and external tools are marked as deferred and surfaced through
|
|
545
|
+
* the built-in `tool_search_tool`.
|
|
546
|
+
*
|
|
547
|
+
* To override the tool-search tool's model-facing definition and/or its
|
|
548
|
+
* execution, register a {@link Tool} named `tool_search_tool` with
|
|
549
|
+
* `overridesBuiltInTool: true`. To customize the in-prompt tool-search
|
|
550
|
+
* guidance, use the `tool_instructions` section of {@link SystemMessageConfig}
|
|
551
|
+
* in `"customize"` mode.
|
|
552
|
+
*/
|
|
553
|
+
export interface ToolSearchConfig {
|
|
554
|
+
/**
|
|
555
|
+
* Toggle to enable/disable tool search. When disabled, all tools are pre-loaded
|
|
556
|
+
* and the model's active tool set is not deferred.
|
|
557
|
+
*/
|
|
558
|
+
enabled?: boolean;
|
|
559
|
+
/**
|
|
560
|
+
* Overrides the total tool count at which MCP and external tools are
|
|
561
|
+
* automatically deferred behind tool search. Defaults to the built-in
|
|
562
|
+
* threshold (30) when omitted.
|
|
563
|
+
*/
|
|
564
|
+
deferThreshold?: number;
|
|
565
|
+
}
|
|
566
|
+
/**
|
|
567
|
+
* Context passed to a command handler when a command is executed.
|
|
568
|
+
*/
|
|
569
|
+
export interface CommandContext {
|
|
570
|
+
/** Session ID where the command was invoked */
|
|
571
|
+
sessionId: string;
|
|
572
|
+
/** The full command text (e.g. "/deploy production") */
|
|
573
|
+
command: string;
|
|
574
|
+
/** Command name without leading / */
|
|
575
|
+
commandName: string;
|
|
576
|
+
/** Raw argument string after the command name */
|
|
577
|
+
args: string;
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* Handler invoked when a registered command is executed by a user.
|
|
581
|
+
*/
|
|
582
|
+
export type CommandHandler = (context: CommandContext) => Promise<void> | void;
|
|
583
|
+
/**
|
|
584
|
+
* Definition of a slash command registered with the session.
|
|
585
|
+
* When the CLI is running with a TUI, registered commands appear as
|
|
586
|
+
* `/commandName` for the user to invoke.
|
|
587
|
+
*/
|
|
588
|
+
export interface CommandDefinition {
|
|
589
|
+
/** Command name (without leading /). */
|
|
590
|
+
name: string;
|
|
591
|
+
/** Human-readable description shown in command completion UI. */
|
|
592
|
+
description?: string;
|
|
593
|
+
/** Handler invoked when the command is executed. */
|
|
594
|
+
handler: CommandHandler;
|
|
595
|
+
}
|
|
596
|
+
/**
|
|
597
|
+
* Capabilities reported by the CLI host for this session.
|
|
598
|
+
*/
|
|
599
|
+
export interface SessionCapabilities {
|
|
600
|
+
ui?: {
|
|
601
|
+
/** Whether the host supports interactive elicitation dialogs. */
|
|
602
|
+
elicitation?: boolean;
|
|
603
|
+
/**
|
|
604
|
+
* Whether the runtime has accepted the session's MCP Apps (SEP-1865)
|
|
605
|
+
* opt-in. `true` when the consumer set `enableMcpApps: true` on
|
|
606
|
+
* create/resume **and** the runtime's `MCP_APPS` feature flag (or
|
|
607
|
+
* `COPILOT_MCP_APPS=true` env override) is on. Otherwise absent or
|
|
608
|
+
* `false`, indicating the runtime silently dropped the opt-in.
|
|
609
|
+
*
|
|
610
|
+
* @experimental This property is part of an experimental wire-protocol surface
|
|
611
|
+
* (SEP-1865) and may change or be removed in a future release.
|
|
612
|
+
*/
|
|
613
|
+
mcpApps?: boolean;
|
|
614
|
+
/** Whether the host supports canvas rendering. */
|
|
615
|
+
canvases?: boolean;
|
|
616
|
+
};
|
|
617
|
+
}
|
|
618
|
+
/**
|
|
619
|
+
* A single field in an elicitation schema — matches the MCP SDK's
|
|
620
|
+
* `PrimitiveSchemaDefinition` union.
|
|
621
|
+
*/
|
|
622
|
+
export type ElicitationSchemaField = {
|
|
623
|
+
type: "string";
|
|
624
|
+
title?: string;
|
|
625
|
+
description?: string;
|
|
626
|
+
enum: string[];
|
|
627
|
+
enumNames?: string[];
|
|
628
|
+
default?: string;
|
|
629
|
+
} | {
|
|
630
|
+
type: "string";
|
|
631
|
+
title?: string;
|
|
632
|
+
description?: string;
|
|
633
|
+
oneOf: {
|
|
634
|
+
const: string;
|
|
635
|
+
title: string;
|
|
636
|
+
}[];
|
|
637
|
+
default?: string;
|
|
638
|
+
} | {
|
|
639
|
+
type: "array";
|
|
640
|
+
title?: string;
|
|
641
|
+
description?: string;
|
|
642
|
+
minItems?: number;
|
|
643
|
+
maxItems?: number;
|
|
644
|
+
items: {
|
|
645
|
+
type: "string";
|
|
646
|
+
enum: string[];
|
|
647
|
+
};
|
|
648
|
+
default?: string[];
|
|
649
|
+
} | {
|
|
650
|
+
type: "array";
|
|
651
|
+
title?: string;
|
|
652
|
+
description?: string;
|
|
653
|
+
minItems?: number;
|
|
654
|
+
maxItems?: number;
|
|
655
|
+
items: {
|
|
656
|
+
anyOf: {
|
|
657
|
+
const: string;
|
|
658
|
+
title: string;
|
|
659
|
+
}[];
|
|
660
|
+
};
|
|
661
|
+
default?: string[];
|
|
662
|
+
} | {
|
|
663
|
+
type: "boolean";
|
|
664
|
+
title?: string;
|
|
665
|
+
description?: string;
|
|
666
|
+
default?: boolean;
|
|
667
|
+
} | {
|
|
668
|
+
type: "string";
|
|
669
|
+
title?: string;
|
|
670
|
+
description?: string;
|
|
671
|
+
minLength?: number;
|
|
672
|
+
maxLength?: number;
|
|
673
|
+
format?: "email" | "uri" | "date" | "date-time";
|
|
674
|
+
default?: string;
|
|
675
|
+
} | {
|
|
676
|
+
type: "number" | "integer";
|
|
677
|
+
title?: string;
|
|
678
|
+
description?: string;
|
|
679
|
+
minimum?: number;
|
|
680
|
+
maximum?: number;
|
|
681
|
+
default?: number;
|
|
682
|
+
};
|
|
683
|
+
/**
|
|
684
|
+
* Schema describing the form fields for an elicitation request.
|
|
685
|
+
*/
|
|
686
|
+
export interface ElicitationSchema {
|
|
687
|
+
type: "object";
|
|
688
|
+
properties: Record<string, ElicitationSchemaField>;
|
|
689
|
+
required?: string[];
|
|
690
|
+
}
|
|
691
|
+
/**
|
|
692
|
+
* Primitive field value in an elicitation result.
|
|
693
|
+
* Matches MCP SDK's `ElicitResult.content` value type.
|
|
694
|
+
*/
|
|
695
|
+
export type ElicitationFieldValue = string | number | boolean | string[];
|
|
696
|
+
/**
|
|
697
|
+
* Result returned from an elicitation request.
|
|
698
|
+
*/
|
|
699
|
+
export interface ElicitationResult {
|
|
700
|
+
/** User action: "accept" (submitted), "decline" (rejected), or "cancel" (dismissed). */
|
|
701
|
+
action: "accept" | "decline" | "cancel";
|
|
702
|
+
/** Form values submitted by the user (present when action is "accept"). */
|
|
703
|
+
content?: Record<string, ElicitationFieldValue>;
|
|
704
|
+
}
|
|
705
|
+
/**
|
|
706
|
+
* Parameters for a raw elicitation request.
|
|
707
|
+
*/
|
|
708
|
+
export interface ElicitationParams {
|
|
709
|
+
/** Message describing what information is needed from the user. */
|
|
710
|
+
message: string;
|
|
711
|
+
/** JSON Schema describing the form fields to present. */
|
|
712
|
+
requestedSchema: ElicitationSchema;
|
|
713
|
+
}
|
|
714
|
+
/**
|
|
715
|
+
* Context for an elicitation handler invocation, combining the request data
|
|
716
|
+
* with session context. Mirrors the single-argument pattern of {@link CommandContext}.
|
|
717
|
+
*/
|
|
718
|
+
export interface ElicitationContext {
|
|
719
|
+
/** Identifier of the session that triggered the elicitation request. */
|
|
720
|
+
sessionId: string;
|
|
721
|
+
/** Message describing what information is needed from the user. */
|
|
722
|
+
message: string;
|
|
723
|
+
/** JSON Schema describing the form fields to present. */
|
|
724
|
+
requestedSchema?: ElicitationSchema;
|
|
725
|
+
/** Elicitation mode: "form" for structured input, "url" for browser redirect. */
|
|
726
|
+
mode?: "form" | "url";
|
|
727
|
+
/** The source that initiated the request (e.g. MCP server name). */
|
|
728
|
+
elicitationSource?: string;
|
|
729
|
+
/** URL to open in the user's browser (url mode only). */
|
|
730
|
+
url?: string;
|
|
731
|
+
}
|
|
732
|
+
/**
|
|
733
|
+
* Handler invoked when the server dispatches an elicitation request to this client.
|
|
734
|
+
* Return an {@link ElicitationResult} with the user's response.
|
|
735
|
+
*/
|
|
736
|
+
export type ElicitationHandler = (context: ElicitationContext) => Promise<ElicitationResult> | ElicitationResult;
|
|
737
|
+
/**
|
|
738
|
+
* Options for the `input()` convenience method.
|
|
739
|
+
*/
|
|
740
|
+
export interface UiInputOptions {
|
|
741
|
+
/** Title label for the input field. */
|
|
742
|
+
title?: string;
|
|
743
|
+
/** Descriptive text shown below the field. */
|
|
744
|
+
description?: string;
|
|
745
|
+
/** Minimum character length. */
|
|
746
|
+
minLength?: number;
|
|
747
|
+
/** Maximum character length. */
|
|
748
|
+
maxLength?: number;
|
|
749
|
+
/** Semantic format hint. */
|
|
750
|
+
format?: "email" | "uri" | "date" | "date-time";
|
|
751
|
+
/** Default value pre-populated in the field. */
|
|
752
|
+
default?: string;
|
|
753
|
+
}
|
|
754
|
+
/**
|
|
755
|
+
* The `session.ui` API object providing interactive UI methods.
|
|
756
|
+
* Only usable when the CLI host supports elicitation.
|
|
757
|
+
*/
|
|
758
|
+
export interface SessionUiApi {
|
|
759
|
+
/**
|
|
760
|
+
* Shows a generic elicitation dialog with a custom schema.
|
|
761
|
+
* @throws Error if the host does not support elicitation.
|
|
762
|
+
*/
|
|
763
|
+
elicitation(params: ElicitationParams): Promise<ElicitationResult>;
|
|
764
|
+
/**
|
|
765
|
+
* Shows a confirmation dialog and returns the user's boolean answer.
|
|
766
|
+
* Returns `false` if the user declines or cancels.
|
|
767
|
+
* @throws Error if the host does not support elicitation.
|
|
768
|
+
*/
|
|
769
|
+
confirm(message: string): Promise<boolean>;
|
|
770
|
+
/**
|
|
771
|
+
* Shows a selection dialog with the given options.
|
|
772
|
+
* Returns the selected value, or `null` if the user declines/cancels.
|
|
773
|
+
* @throws Error if the host does not support elicitation.
|
|
774
|
+
*/
|
|
775
|
+
select(message: string, options: string[]): Promise<string | null>;
|
|
776
|
+
/**
|
|
777
|
+
* Shows a text input dialog.
|
|
778
|
+
* Returns the entered text, or `null` if the user declines/cancels.
|
|
779
|
+
* @throws Error if the host does not support elicitation.
|
|
780
|
+
*/
|
|
781
|
+
input(message: string, options?: UiInputOptions): Promise<string | null>;
|
|
782
|
+
}
|
|
783
|
+
export interface ToolCallRequestPayload {
|
|
784
|
+
sessionId: string;
|
|
785
|
+
toolCallId: string;
|
|
786
|
+
toolName: string;
|
|
787
|
+
arguments: unknown;
|
|
788
|
+
}
|
|
789
|
+
export interface ToolCallResponsePayload {
|
|
790
|
+
result: ToolResult;
|
|
791
|
+
}
|
|
792
|
+
/**
|
|
793
|
+
* Known system message section identifiers for the "customize" mode.
|
|
794
|
+
* Each section corresponds to a distinct part of the system prompt.
|
|
795
|
+
*/
|
|
796
|
+
export type SystemMessageSection = "preamble" | "identity" | "tone" | "tool_efficiency" | "environment_context" | "code_change_rules" | "guidelines" | "safety" | "tool_instructions" | "custom_instructions" | "runtime_instructions" | "last_instructions";
|
|
797
|
+
/** Section metadata for documentation and tooling. */
|
|
798
|
+
export declare const SYSTEM_MESSAGE_SECTIONS: Record<SystemMessageSection, {
|
|
799
|
+
description: string;
|
|
800
|
+
}>;
|
|
801
|
+
/**
|
|
802
|
+
* Transform callback for a single section: receives current content, returns new content.
|
|
803
|
+
*/
|
|
804
|
+
export type SectionTransformFn = (currentContent: string) => string | Promise<string>;
|
|
805
|
+
/**
|
|
806
|
+
* Override action: a string literal for static overrides, or a callback for transforms.
|
|
807
|
+
*
|
|
808
|
+
* - `"replace"`: Replace section content entirely
|
|
809
|
+
* - `"remove"`: Remove the section
|
|
810
|
+
* - `"append"`: Append to existing section content
|
|
811
|
+
* - `"prepend"`: Prepend to existing section content
|
|
812
|
+
* - `"preserve"`: No-op marker that opts an individually-addressable section out of a
|
|
813
|
+
* group-level `"remove"` (e.g. keep `tone` when removing the `identity` group)
|
|
814
|
+
* - `function`: Transform callback — receives current section content, returns new content
|
|
815
|
+
*/
|
|
816
|
+
export type SectionOverrideAction = "replace" | "remove" | "append" | "prepend" | "preserve" | SectionTransformFn;
|
|
817
|
+
/**
|
|
818
|
+
* Override operation for a single system message section.
|
|
819
|
+
*/
|
|
820
|
+
export interface SectionOverride {
|
|
821
|
+
/**
|
|
822
|
+
* The operation to perform on this section.
|
|
823
|
+
* Can be a string action or a transform callback function.
|
|
824
|
+
*/
|
|
825
|
+
action: SectionOverrideAction;
|
|
826
|
+
/**
|
|
827
|
+
* Content for the override. Optional for all actions.
|
|
828
|
+
* - For replace, omitting content replaces with an empty string.
|
|
829
|
+
* - For append/prepend, content is added before/after the existing section.
|
|
830
|
+
* - Ignored for the remove action.
|
|
831
|
+
*/
|
|
832
|
+
content?: string;
|
|
833
|
+
}
|
|
834
|
+
/**
|
|
835
|
+
* Append mode: Use CLI foundation with optional appended content (default).
|
|
836
|
+
*/
|
|
837
|
+
export interface SystemMessageAppendConfig {
|
|
838
|
+
mode?: "append";
|
|
839
|
+
/**
|
|
840
|
+
* Additional instructions appended after SDK-managed sections.
|
|
841
|
+
*/
|
|
842
|
+
content?: string;
|
|
843
|
+
}
|
|
844
|
+
/**
|
|
845
|
+
* Replace mode: Use caller-provided system message entirely.
|
|
846
|
+
* Removes all SDK guardrails including security restrictions.
|
|
847
|
+
*/
|
|
848
|
+
export interface SystemMessageReplaceConfig {
|
|
849
|
+
mode: "replace";
|
|
850
|
+
/**
|
|
851
|
+
* Complete system message content.
|
|
852
|
+
* Replaces the entire SDK-managed system message.
|
|
853
|
+
*/
|
|
854
|
+
content: string;
|
|
855
|
+
}
|
|
856
|
+
/**
|
|
857
|
+
* Customize mode: Override individual sections of the system prompt.
|
|
858
|
+
* Keeps the SDK-managed prompt structure while allowing targeted modifications.
|
|
859
|
+
*/
|
|
860
|
+
export interface SystemMessageCustomizeConfig {
|
|
861
|
+
mode: "customize";
|
|
862
|
+
/**
|
|
863
|
+
* Override specific sections of the system prompt by section ID.
|
|
864
|
+
* Unknown section IDs gracefully fall back: content-bearing overrides are appended
|
|
865
|
+
* to additional instructions, and "remove" on unknown sections is a silent no-op.
|
|
866
|
+
*/
|
|
867
|
+
sections?: Partial<Record<SystemMessageSection, SectionOverride>>;
|
|
868
|
+
/**
|
|
869
|
+
* Additional content appended after all sections.
|
|
870
|
+
* Equivalent to append mode's content field — provided for convenience.
|
|
871
|
+
*/
|
|
872
|
+
content?: string;
|
|
873
|
+
}
|
|
874
|
+
/**
|
|
875
|
+
* System message configuration for session creation.
|
|
876
|
+
* - Append mode (default): SDK foundation + optional custom content
|
|
877
|
+
* - Replace mode: Full control, caller provides entire system message
|
|
878
|
+
* - Customize mode: Section-level overrides with graceful fallback
|
|
879
|
+
*/
|
|
880
|
+
export type SystemMessageConfig = SystemMessageAppendConfig | SystemMessageReplaceConfig | SystemMessageCustomizeConfig;
|
|
881
|
+
import type { PermissionDecisionRequest, PermissionDecisionContext } from "./generated/rpc.js";
|
|
882
|
+
/**
|
|
883
|
+
* Permission request types from the server. This is the generated
|
|
884
|
+
* discriminated union from the runtime schema — switch on `kind` to
|
|
885
|
+
* access the variant-specific fields (e.g. shell `commands`, write
|
|
886
|
+
* `fileName`/`diff`, mcp `toolName`/`args`).
|
|
887
|
+
*
|
|
888
|
+
* `managedApprovalRequired` indicates that managed policy requires an explicit
|
|
889
|
+
* user decision. Hosts should bypass automatic approval and present their
|
|
890
|
+
* normal confirmation UI. The runtime currently emits it for managed Shell,
|
|
891
|
+
* Read, Edit, and Domain selector asks.
|
|
892
|
+
*/
|
|
893
|
+
export type PermissionRequest = GeneratedPermissionRequest & {
|
|
894
|
+
readonly managedApprovalRequired?: boolean;
|
|
895
|
+
};
|
|
896
|
+
export type PermissionRequestedData = Omit<GeneratedPermissionRequestedData, "permissionRequest"> & {
|
|
897
|
+
permissionRequest: PermissionRequest;
|
|
898
|
+
};
|
|
899
|
+
export type PermissionRequestedEvent = Omit<GeneratedPermissionRequestedEvent, "data"> & {
|
|
900
|
+
data: PermissionRequestedData;
|
|
901
|
+
};
|
|
902
|
+
/**
|
|
903
|
+
* Permission decision result returned from a {@link PermissionHandler}.
|
|
904
|
+
* The discriminated `kind` field selects the decision. Variant-specific
|
|
905
|
+
* fields (e.g. `feedback` on `{ kind: "reject" }`) come from the generated
|
|
906
|
+
* `PermissionDecisionRequest["result"]` union.
|
|
907
|
+
*/
|
|
908
|
+
export type PermissionRequestResult = PermissionDecisionRequest["result"] | {
|
|
909
|
+
kind: "no-result";
|
|
910
|
+
};
|
|
911
|
+
/**
|
|
912
|
+
* A {@link PermissionRequestResult} annotated with the
|
|
913
|
+
* {@link PermissionDecisionContext} describing how and where the decision was
|
|
914
|
+
* reached. The context is informational only — it never changes permission
|
|
915
|
+
* behavior. Supplying it lets the runtime attribute auto-approval telemetry to
|
|
916
|
+
* the responding surface.
|
|
917
|
+
*/
|
|
918
|
+
export interface AttributedPermissionResult {
|
|
919
|
+
kind: "attributed";
|
|
920
|
+
result: PermissionRequestResult;
|
|
921
|
+
decisionContext: PermissionDecisionContext;
|
|
922
|
+
}
|
|
923
|
+
/**
|
|
924
|
+
* Narrows a {@link PermissionHandler} return value to an attributed result.
|
|
925
|
+
*/
|
|
926
|
+
export declare function isAttributedPermissionResult(result: PermissionRequestResult | AttributedPermissionResult): result is AttributedPermissionResult;
|
|
927
|
+
/**
|
|
928
|
+
* Pair a permission decision with the context describing how and where it was
|
|
929
|
+
* made, so the runtime can attribute auto-approval telemetry.
|
|
930
|
+
*
|
|
931
|
+
* Passing an already-attributed result replaces the previous context rather
|
|
932
|
+
* than nesting it. The context is informational only and never changes
|
|
933
|
+
* permission behavior.
|
|
934
|
+
*/
|
|
935
|
+
export declare function createAttributedPermissionResult(result: PermissionRequestResult | AttributedPermissionResult, decisionContext: PermissionDecisionContext): AttributedPermissionResult;
|
|
936
|
+
export type PermissionHandler = (request: PermissionRequest, invocation: {
|
|
937
|
+
sessionId: string;
|
|
938
|
+
managedSettingsEnabled?: boolean;
|
|
939
|
+
}) => Promise<PermissionRequestResult | AttributedPermissionResult> | PermissionRequestResult | AttributedPermissionResult;
|
|
940
|
+
/**
|
|
941
|
+
* Approves permission requests when managed settings are disabled.
|
|
942
|
+
*/
|
|
943
|
+
export declare const approveAll: PermissionHandler;
|
|
944
|
+
export declare const defaultJoinSessionPermissionHandler: PermissionHandler;
|
|
945
|
+
/**
|
|
946
|
+
* Legacy question-and-answer request from the `ask_user` tool.
|
|
947
|
+
*/
|
|
948
|
+
export interface UserInputRequest {
|
|
949
|
+
/**
|
|
950
|
+
* The question to ask the user
|
|
951
|
+
*/
|
|
952
|
+
question: string;
|
|
953
|
+
/**
|
|
954
|
+
* Optional choices for multiple choice questions
|
|
955
|
+
*/
|
|
956
|
+
choices?: string[];
|
|
957
|
+
/**
|
|
958
|
+
* Whether to allow freeform text input in addition to choices
|
|
959
|
+
* @default true
|
|
960
|
+
*/
|
|
961
|
+
allowFreeform?: boolean;
|
|
962
|
+
}
|
|
963
|
+
/**
|
|
964
|
+
* Response to a user input request
|
|
965
|
+
*/
|
|
966
|
+
export interface UserInputResponse {
|
|
967
|
+
/**
|
|
968
|
+
* The user's answer
|
|
969
|
+
*/
|
|
970
|
+
answer: string;
|
|
971
|
+
/**
|
|
972
|
+
* Whether the answer was freeform (not from choices)
|
|
973
|
+
*/
|
|
974
|
+
wasFreeform: boolean;
|
|
975
|
+
}
|
|
976
|
+
/**
|
|
977
|
+
* Handler for user input requests from the agent
|
|
978
|
+
*/
|
|
979
|
+
export type UserInputHandler = (request: UserInputRequest, invocation: {
|
|
980
|
+
sessionId: string;
|
|
981
|
+
}) => Promise<UserInputResponse> | UserInputResponse;
|
|
982
|
+
/**
|
|
983
|
+
* Request to exit plan mode and continue with a selected action.
|
|
984
|
+
*/
|
|
985
|
+
export interface ExitPlanModeRequest {
|
|
986
|
+
/** Summary of the plan or proposed next step. */
|
|
987
|
+
summary: string;
|
|
988
|
+
/** Full plan content, when available. */
|
|
989
|
+
planContent?: string;
|
|
990
|
+
/** Available actions the user can select. */
|
|
991
|
+
actions: string[];
|
|
992
|
+
/** The action recommended by the runtime. */
|
|
993
|
+
recommendedAction: string;
|
|
994
|
+
}
|
|
995
|
+
/**
|
|
996
|
+
* Response to an exit-plan-mode request.
|
|
997
|
+
*/
|
|
998
|
+
export interface ExitPlanModeResult {
|
|
999
|
+
/** Whether the user approved exiting plan mode. */
|
|
1000
|
+
approved: boolean;
|
|
1001
|
+
/** Selected action, if the user chose one. */
|
|
1002
|
+
selectedAction?: string;
|
|
1003
|
+
/** Optional feedback provided by the user. */
|
|
1004
|
+
feedback?: string;
|
|
1005
|
+
}
|
|
1006
|
+
/**
|
|
1007
|
+
* Handler for exit-plan-mode requests from the agent.
|
|
1008
|
+
*/
|
|
1009
|
+
export type ExitPlanModeHandler = (request: ExitPlanModeRequest, invocation: {
|
|
1010
|
+
sessionId: string;
|
|
1011
|
+
}) => Promise<ExitPlanModeResult> | ExitPlanModeResult;
|
|
1012
|
+
/**
|
|
1013
|
+
* Request to switch to auto mode after an eligible rate limit.
|
|
1014
|
+
*/
|
|
1015
|
+
export interface AutoModeSwitchRequest {
|
|
1016
|
+
/** The rate-limit error code that triggered the request. */
|
|
1017
|
+
errorCode?: string;
|
|
1018
|
+
/** Seconds until the rate limit resets, when known. */
|
|
1019
|
+
retryAfterSeconds?: number;
|
|
1020
|
+
}
|
|
1021
|
+
/**
|
|
1022
|
+
* Response to an auto-mode-switch request.
|
|
1023
|
+
*/
|
|
1024
|
+
export type AutoModeSwitchResponse = "yes" | "yes_always" | "no";
|
|
1025
|
+
/**
|
|
1026
|
+
* Handler for auto-mode-switch requests from the agent.
|
|
1027
|
+
*/
|
|
1028
|
+
export type AutoModeSwitchHandler = (request: AutoModeSwitchRequest, invocation: {
|
|
1029
|
+
sessionId: string;
|
|
1030
|
+
}) => Promise<AutoModeSwitchResponse> | AutoModeSwitchResponse;
|
|
1031
|
+
/**
|
|
1032
|
+
* Base interface for all hook inputs
|
|
1033
|
+
*/
|
|
1034
|
+
export interface BaseHookInput {
|
|
1035
|
+
/** The runtime session ID of the session that triggered the hook.
|
|
1036
|
+
* For sub-agent hooks this differs from `invocation.sessionId`. */
|
|
1037
|
+
sessionId: string;
|
|
1038
|
+
/** Time at which the hook event was emitted by the runtime. */
|
|
1039
|
+
timestamp: Date;
|
|
1040
|
+
workingDirectory: string;
|
|
1041
|
+
}
|
|
1042
|
+
/**
|
|
1043
|
+
* Input for pre-tool-use hook
|
|
1044
|
+
*/
|
|
1045
|
+
export interface PreToolUseHookInput extends BaseHookInput {
|
|
1046
|
+
toolName: string;
|
|
1047
|
+
toolArgs: unknown;
|
|
1048
|
+
}
|
|
1049
|
+
/**
|
|
1050
|
+
* Output for pre-tool-use hook
|
|
1051
|
+
*/
|
|
1052
|
+
export interface PreToolUseHookOutput {
|
|
1053
|
+
permissionDecision?: "allow" | "deny" | "ask";
|
|
1054
|
+
permissionDecisionReason?: string;
|
|
1055
|
+
modifiedArgs?: unknown;
|
|
1056
|
+
additionalContext?: string;
|
|
1057
|
+
suppressOutput?: boolean;
|
|
1058
|
+
}
|
|
1059
|
+
/**
|
|
1060
|
+
* Handler for pre-tool-use hook
|
|
1061
|
+
*/
|
|
1062
|
+
export type PreToolUseHandler = (input: PreToolUseHookInput, invocation: {
|
|
1063
|
+
sessionId: string;
|
|
1064
|
+
}) => Promise<PreToolUseHookOutput | void> | PreToolUseHookOutput | void;
|
|
1065
|
+
/**
|
|
1066
|
+
* Input for pre-MCP-tool-call hook
|
|
1067
|
+
*/
|
|
1068
|
+
export interface PreMcpToolCallHookInput extends BaseHookInput {
|
|
1069
|
+
toolCallId?: string;
|
|
1070
|
+
serverName: string;
|
|
1071
|
+
toolName: string;
|
|
1072
|
+
arguments: unknown;
|
|
1073
|
+
_meta?: Record<string, unknown>;
|
|
1074
|
+
}
|
|
1075
|
+
/**
|
|
1076
|
+
* Output for pre-MCP-tool-call hook
|
|
1077
|
+
*/
|
|
1078
|
+
export interface PreMcpToolCallHookOutput {
|
|
1079
|
+
/**
|
|
1080
|
+
* Hook-controlled metadata to use for the outgoing MCP request.
|
|
1081
|
+
* - undefined/absent: preserve the current request `_meta`
|
|
1082
|
+
* - object: use this object as request `_meta`
|
|
1083
|
+
* - null: omit `_meta`
|
|
1084
|
+
*/
|
|
1085
|
+
metaToUse?: Record<string, unknown> | null;
|
|
1086
|
+
}
|
|
1087
|
+
/**
|
|
1088
|
+
* Handler for pre-MCP-tool-call hook
|
|
1089
|
+
*/
|
|
1090
|
+
export type PreMcpToolCallHandler = (input: PreMcpToolCallHookInput, invocation: {
|
|
1091
|
+
sessionId: string;
|
|
1092
|
+
}) => Promise<PreMcpToolCallHookOutput | void> | PreMcpToolCallHookOutput | void;
|
|
1093
|
+
/**
|
|
1094
|
+
* Input for post-tool-use hook
|
|
1095
|
+
*/
|
|
1096
|
+
export interface PostToolUseHookInput extends BaseHookInput {
|
|
1097
|
+
toolName: string;
|
|
1098
|
+
toolArgs: unknown;
|
|
1099
|
+
toolResult: ToolResultObject;
|
|
1100
|
+
}
|
|
1101
|
+
/**
|
|
1102
|
+
* Output for post-tool-use hook
|
|
1103
|
+
*/
|
|
1104
|
+
export interface PostToolUseHookOutput {
|
|
1105
|
+
modifiedResult?: ToolResultObject;
|
|
1106
|
+
additionalContext?: string;
|
|
1107
|
+
suppressOutput?: boolean;
|
|
1108
|
+
}
|
|
1109
|
+
/**
|
|
1110
|
+
* Handler for post-tool-use hook
|
|
1111
|
+
*/
|
|
1112
|
+
export type PostToolUseHandler = (input: PostToolUseHookInput, invocation: {
|
|
1113
|
+
sessionId: string;
|
|
1114
|
+
}) => Promise<PostToolUseHookOutput | void> | PostToolUseHookOutput | void;
|
|
1115
|
+
/**
|
|
1116
|
+
* Input for post-tool-use-failure hook.
|
|
1117
|
+
*
|
|
1118
|
+
* Dispatched after a tool execution whose `resultType` is `"failure"`.
|
|
1119
|
+
* The input differs from {@link PostToolUseHookInput}: the host CLI does not
|
|
1120
|
+
* forward the full `ToolResultObject` to failure hooks — only `error`, the
|
|
1121
|
+
* stringified failure message extracted from the tool's result, is provided.
|
|
1122
|
+
*/
|
|
1123
|
+
export interface PostToolUseFailureHookInput extends BaseHookInput {
|
|
1124
|
+
toolName: string;
|
|
1125
|
+
toolArgs: unknown;
|
|
1126
|
+
/**
|
|
1127
|
+
* Failure message from the tool's result (the `error` field of the
|
|
1128
|
+
* underlying `ToolResultObject`, falling back to its text/log fields).
|
|
1129
|
+
*/
|
|
1130
|
+
error: string;
|
|
1131
|
+
}
|
|
1132
|
+
/**
|
|
1133
|
+
* Output for post-tool-use-failure hook.
|
|
1134
|
+
*
|
|
1135
|
+
* Only `additionalContext` is consumed by the host CLI — it is appended as
|
|
1136
|
+
* hidden guidance to the model alongside the failed tool result. Other fields
|
|
1137
|
+
* such as `modifiedResult` or `suppressOutput` are not honored for failure
|
|
1138
|
+
* hooks (see {@link PostToolUseHookOutput} for the success-only hook).
|
|
1139
|
+
*/
|
|
1140
|
+
export interface PostToolUseFailureHookOutput {
|
|
1141
|
+
additionalContext?: string;
|
|
1142
|
+
}
|
|
1143
|
+
/**
|
|
1144
|
+
* Handler for post-tool-use-failure hook.
|
|
1145
|
+
*
|
|
1146
|
+
* Fires after a tool execution whose result was `"failure"`. `onPostToolUse`
|
|
1147
|
+
* only fires for successful results, so register this handler to observe or
|
|
1148
|
+
* react to failed tool outcomes.
|
|
1149
|
+
*
|
|
1150
|
+
* Note: `"rejected"`, `"denied"`, and `"timeout"` results do not currently
|
|
1151
|
+
* trigger this hook either — only `"failure"` does.
|
|
1152
|
+
*/
|
|
1153
|
+
export type PostToolUseFailureHandler = (input: PostToolUseFailureHookInput, invocation: {
|
|
1154
|
+
sessionId: string;
|
|
1155
|
+
}) => Promise<PostToolUseFailureHookOutput | void> | PostToolUseFailureHookOutput | void;
|
|
1156
|
+
/**
|
|
1157
|
+
* Input for user-prompt-submitted hook
|
|
1158
|
+
*/
|
|
1159
|
+
export interface UserPromptSubmittedHookInput extends BaseHookInput {
|
|
1160
|
+
prompt: string;
|
|
1161
|
+
}
|
|
1162
|
+
/**
|
|
1163
|
+
* Output for user-prompt-submitted hook
|
|
1164
|
+
*/
|
|
1165
|
+
export interface UserPromptSubmittedHookOutput {
|
|
1166
|
+
modifiedPrompt?: string;
|
|
1167
|
+
additionalContext?: string;
|
|
1168
|
+
suppressOutput?: boolean;
|
|
1169
|
+
}
|
|
1170
|
+
/**
|
|
1171
|
+
* Handler for user-prompt-submitted hook
|
|
1172
|
+
*/
|
|
1173
|
+
export type UserPromptSubmittedHandler = (input: UserPromptSubmittedHookInput, invocation: {
|
|
1174
|
+
sessionId: string;
|
|
1175
|
+
}) => Promise<UserPromptSubmittedHookOutput | void> | UserPromptSubmittedHookOutput | void;
|
|
1176
|
+
/**
|
|
1177
|
+
* Input for the user-prompt-transformed hook.
|
|
1178
|
+
*
|
|
1179
|
+
* This hook runs after the runtime has transformed the submitted prompt with
|
|
1180
|
+
* generated context, but before it is persisted to session history or sent to
|
|
1181
|
+
* the model.
|
|
1182
|
+
*/
|
|
1183
|
+
export interface UserPromptTransformedHookInput extends BaseHookInput {
|
|
1184
|
+
prompt: string;
|
|
1185
|
+
transformedPrompt: string;
|
|
1186
|
+
}
|
|
1187
|
+
/**
|
|
1188
|
+
* Output for the user-prompt-transformed hook.
|
|
1189
|
+
*/
|
|
1190
|
+
export interface UserPromptTransformedHookOutput {
|
|
1191
|
+
modifiedTransformedPrompt?: string;
|
|
1192
|
+
}
|
|
1193
|
+
/**
|
|
1194
|
+
* Handler for the user-prompt-transformed hook.
|
|
1195
|
+
*/
|
|
1196
|
+
export type UserPromptTransformedHandler = (input: UserPromptTransformedHookInput, invocation: {
|
|
1197
|
+
sessionId: string;
|
|
1198
|
+
}) => Promise<UserPromptTransformedHookOutput | void> | UserPromptTransformedHookOutput | void;
|
|
1199
|
+
/**
|
|
1200
|
+
* Input for session-start hook
|
|
1201
|
+
*/
|
|
1202
|
+
export interface SessionStartHookInput extends BaseHookInput {
|
|
1203
|
+
source: "startup" | "resume" | "new";
|
|
1204
|
+
initialPrompt?: string;
|
|
1205
|
+
}
|
|
1206
|
+
/**
|
|
1207
|
+
* Output for session-start hook
|
|
1208
|
+
*/
|
|
1209
|
+
export interface SessionStartHookOutput {
|
|
1210
|
+
additionalContext?: string;
|
|
1211
|
+
modifiedConfig?: Record<string, unknown>;
|
|
1212
|
+
}
|
|
1213
|
+
/**
|
|
1214
|
+
* Handler for session-start hook
|
|
1215
|
+
*/
|
|
1216
|
+
export type SessionStartHandler = (input: SessionStartHookInput, invocation: {
|
|
1217
|
+
sessionId: string;
|
|
1218
|
+
}) => Promise<SessionStartHookOutput | void> | SessionStartHookOutput | void;
|
|
1219
|
+
/**
|
|
1220
|
+
* Input for session-end hook
|
|
1221
|
+
*/
|
|
1222
|
+
export interface SessionEndHookInput extends BaseHookInput {
|
|
1223
|
+
reason: "complete" | "error" | "abort" | "timeout" | "user_exit";
|
|
1224
|
+
finalMessage?: string;
|
|
1225
|
+
error?: string;
|
|
1226
|
+
}
|
|
1227
|
+
/**
|
|
1228
|
+
* Output for session-end hook
|
|
1229
|
+
*/
|
|
1230
|
+
export interface SessionEndHookOutput {
|
|
1231
|
+
suppressOutput?: boolean;
|
|
1232
|
+
cleanupActions?: string[];
|
|
1233
|
+
sessionSummary?: string;
|
|
1234
|
+
}
|
|
1235
|
+
/**
|
|
1236
|
+
* Handler for session-end hook
|
|
1237
|
+
*/
|
|
1238
|
+
export type SessionEndHandler = (input: SessionEndHookInput, invocation: {
|
|
1239
|
+
sessionId: string;
|
|
1240
|
+
}) => Promise<SessionEndHookOutput | void> | SessionEndHookOutput | void;
|
|
1241
|
+
/**
|
|
1242
|
+
* Input for error-occurred hook
|
|
1243
|
+
*/
|
|
1244
|
+
export interface ErrorOccurredHookInput extends BaseHookInput {
|
|
1245
|
+
error: string;
|
|
1246
|
+
errorContext: "model_call" | "tool_execution" | "system" | "user_input";
|
|
1247
|
+
recoverable: boolean;
|
|
1248
|
+
}
|
|
1249
|
+
/**
|
|
1250
|
+
* Output for error-occurred hook
|
|
1251
|
+
*/
|
|
1252
|
+
export interface ErrorOccurredHookOutput {
|
|
1253
|
+
suppressOutput?: boolean;
|
|
1254
|
+
errorHandling?: "retry" | "skip" | "abort";
|
|
1255
|
+
retryCount?: number;
|
|
1256
|
+
userNotification?: string;
|
|
1257
|
+
}
|
|
1258
|
+
/**
|
|
1259
|
+
* Handler for error-occurred hook
|
|
1260
|
+
*/
|
|
1261
|
+
export type ErrorOccurredHandler = (input: ErrorOccurredHookInput, invocation: {
|
|
1262
|
+
sessionId: string;
|
|
1263
|
+
}) => Promise<ErrorOccurredHookOutput | void> | ErrorOccurredHookOutput | void;
|
|
1264
|
+
/**
|
|
1265
|
+
* Input for the agent-stop hook.
|
|
1266
|
+
*
|
|
1267
|
+
* Fires for the top-level (main) agent when it reaches a natural terminal stop
|
|
1268
|
+
* — i.e. the agent has gone idle without a pending non-terminal tool call and
|
|
1269
|
+
* was not aborted or blocked by a rejected tool. (For sub-agents, the runtime
|
|
1270
|
+
* fires a separate sub-agent stop lifecycle.)
|
|
1271
|
+
*/
|
|
1272
|
+
export interface AgentStopHookInput extends BaseHookInput {
|
|
1273
|
+
/** Why the agent stopped (for example, `"end_turn"`). */
|
|
1274
|
+
stopReason?: string;
|
|
1275
|
+
/** Path to the on-disk session transcript, when available. */
|
|
1276
|
+
transcriptPath?: string;
|
|
1277
|
+
/**
|
|
1278
|
+
* True when this stop is a re-entry triggered by a previous agent-stop
|
|
1279
|
+
* `block` decision (Claude-compatible `stop_hook_active` semantics). Lets a
|
|
1280
|
+
* handler avoid blocking indefinitely.
|
|
1281
|
+
*/
|
|
1282
|
+
stopHookActive?: boolean;
|
|
1283
|
+
}
|
|
1284
|
+
/**
|
|
1285
|
+
* Output for the agent-stop hook.
|
|
1286
|
+
*
|
|
1287
|
+
* Return `{ decision: "block", reason }` to keep the agent running: the
|
|
1288
|
+
* `reason` is enqueued as a follow-up user message so the agent continues
|
|
1289
|
+
* working (for example, to remediate findings surfaced by the hook). The
|
|
1290
|
+
* runtime caps consecutive blocks to prevent runaway loops. Returning nothing
|
|
1291
|
+
* (or omitting `decision`) lets the agent stop normally.
|
|
1292
|
+
*/
|
|
1293
|
+
export interface AgentStopHookOutput {
|
|
1294
|
+
decision?: "block";
|
|
1295
|
+
reason?: string;
|
|
1296
|
+
}
|
|
1297
|
+
/**
|
|
1298
|
+
* Handler for the agent-stop hook.
|
|
1299
|
+
*/
|
|
1300
|
+
export type AgentStopHandler = (input: AgentStopHookInput, invocation: {
|
|
1301
|
+
sessionId: string;
|
|
1302
|
+
}) => Promise<AgentStopHookOutput | void> | AgentStopHookOutput | void;
|
|
1303
|
+
/**
|
|
1304
|
+
* Configuration for session hooks
|
|
1305
|
+
*/
|
|
1306
|
+
export interface SessionHooks {
|
|
1307
|
+
/**
|
|
1308
|
+
* Called before a tool is executed
|
|
1309
|
+
*/
|
|
1310
|
+
onPreToolUse?: PreToolUseHandler;
|
|
1311
|
+
/**
|
|
1312
|
+
* Called before an MCP tool is called
|
|
1313
|
+
*/
|
|
1314
|
+
onPreMcpToolCall?: PreMcpToolCallHandler;
|
|
1315
|
+
/**
|
|
1316
|
+
* Called after a tool is executed with a successful result.
|
|
1317
|
+
*
|
|
1318
|
+
* For failed tool executions, register {@link onPostToolUseFailure} instead;
|
|
1319
|
+
* this handler does not fire for non-success results.
|
|
1320
|
+
*/
|
|
1321
|
+
onPostToolUse?: PostToolUseHandler;
|
|
1322
|
+
/**
|
|
1323
|
+
* Called after a tool execution whose result was `"failure"`.
|
|
1324
|
+
*
|
|
1325
|
+
* Register this handler alongside {@link onPostToolUse} to observe failed
|
|
1326
|
+
* tool calls — `onPostToolUse` only fires for successful results, so
|
|
1327
|
+
* without this hook failed tool calls are invisible to extensions.
|
|
1328
|
+
*/
|
|
1329
|
+
onPostToolUseFailure?: PostToolUseFailureHandler;
|
|
1330
|
+
/**
|
|
1331
|
+
* Called when the user submits a prompt
|
|
1332
|
+
*/
|
|
1333
|
+
onUserPromptSubmitted?: UserPromptSubmittedHandler;
|
|
1334
|
+
/**
|
|
1335
|
+
* Called after the runtime transforms a submitted prompt and before it is stored.
|
|
1336
|
+
*/
|
|
1337
|
+
onUserPromptTransformed?: UserPromptTransformedHandler;
|
|
1338
|
+
/**
|
|
1339
|
+
* Called when a session starts
|
|
1340
|
+
*/
|
|
1341
|
+
onSessionStart?: SessionStartHandler;
|
|
1342
|
+
/**
|
|
1343
|
+
* Called when a session ends
|
|
1344
|
+
*/
|
|
1345
|
+
onSessionEnd?: SessionEndHandler;
|
|
1346
|
+
/**
|
|
1347
|
+
* Called when an error occurs
|
|
1348
|
+
*/
|
|
1349
|
+
onErrorOccurred?: ErrorOccurredHandler;
|
|
1350
|
+
/**
|
|
1351
|
+
* Called when the top-level agent reaches a natural terminal stop (it went
|
|
1352
|
+
* idle without pending work and was not aborted). Return
|
|
1353
|
+
* `{ decision: "block", reason }` to keep the agent running with `reason`
|
|
1354
|
+
* enqueued as a follow-up message — for example, to have the agent
|
|
1355
|
+
* remediate findings the handler surfaced. Returning nothing lets the
|
|
1356
|
+
* agent stop.
|
|
1357
|
+
*/
|
|
1358
|
+
onAgentStop?: AgentStopHandler;
|
|
1359
|
+
}
|
|
1360
|
+
/**
|
|
1361
|
+
* Base interface for MCP server configuration.
|
|
1362
|
+
*/
|
|
1363
|
+
interface MCPServerConfigBase {
|
|
1364
|
+
/**
|
|
1365
|
+
* List of tools to include from this server.
|
|
1366
|
+
* `undefined` (the default) or `["*"]` means include all tools.
|
|
1367
|
+
* `[]` means include none.
|
|
1368
|
+
*/
|
|
1369
|
+
tools?: string[];
|
|
1370
|
+
/**
|
|
1371
|
+
* Indicates the server type: "stdio" for local/subprocess servers, "http"/"sse" for remote servers.
|
|
1372
|
+
* If not specified, defaults to "stdio".
|
|
1373
|
+
*/
|
|
1374
|
+
type?: string;
|
|
1375
|
+
/**
|
|
1376
|
+
* Optional timeout in milliseconds for tool calls to this server.
|
|
1377
|
+
*/
|
|
1378
|
+
timeout?: number;
|
|
1379
|
+
}
|
|
1380
|
+
/**
|
|
1381
|
+
* Configuration for a local/stdio MCP server.
|
|
1382
|
+
*/
|
|
1383
|
+
export interface MCPStdioServerConfig extends MCPServerConfigBase {
|
|
1384
|
+
type?: "local" | "stdio";
|
|
1385
|
+
command: string;
|
|
1386
|
+
args?: string[];
|
|
1387
|
+
/**
|
|
1388
|
+
* Environment variables to pass to the server.
|
|
1389
|
+
*/
|
|
1390
|
+
env?: Record<string, string>;
|
|
1391
|
+
/**
|
|
1392
|
+
* Working directory for the server process.
|
|
1393
|
+
*/
|
|
1394
|
+
workingDirectory?: string;
|
|
1395
|
+
}
|
|
1396
|
+
/**
|
|
1397
|
+
* Configuration for a remote MCP server (HTTP or SSE).
|
|
1398
|
+
*/
|
|
1399
|
+
export interface MCPHTTPServerConfig extends MCPServerConfigBase {
|
|
1400
|
+
type: "http" | "sse";
|
|
1401
|
+
/**
|
|
1402
|
+
* URL of the remote server.
|
|
1403
|
+
*/
|
|
1404
|
+
url: string;
|
|
1405
|
+
/**
|
|
1406
|
+
* Optional HTTP headers to include in requests.
|
|
1407
|
+
*/
|
|
1408
|
+
headers?: Record<string, string>;
|
|
1409
|
+
}
|
|
1410
|
+
/**
|
|
1411
|
+
* Union type for MCP server configurations.
|
|
1412
|
+
*/
|
|
1413
|
+
export type MCPServerConfig = MCPStdioServerConfig | MCPHTTPServerConfig;
|
|
1414
|
+
/**
|
|
1415
|
+
* Configuration for a custom agent.
|
|
1416
|
+
*/
|
|
1417
|
+
export interface CustomAgentConfig {
|
|
1418
|
+
/**
|
|
1419
|
+
* Unique name of the custom agent.
|
|
1420
|
+
*/
|
|
1421
|
+
name: string;
|
|
1422
|
+
/**
|
|
1423
|
+
* Display name for UI purposes.
|
|
1424
|
+
*/
|
|
1425
|
+
displayName?: string;
|
|
1426
|
+
/**
|
|
1427
|
+
* Description of what the agent does.
|
|
1428
|
+
*/
|
|
1429
|
+
description?: string;
|
|
1430
|
+
/**
|
|
1431
|
+
* List of tool names the agent can use.
|
|
1432
|
+
* Use null or undefined for all tools.
|
|
1433
|
+
*/
|
|
1434
|
+
tools?: string[] | null;
|
|
1435
|
+
/**
|
|
1436
|
+
* The prompt content for the agent.
|
|
1437
|
+
*/
|
|
1438
|
+
prompt: string;
|
|
1439
|
+
/**
|
|
1440
|
+
* MCP servers specific to this agent.
|
|
1441
|
+
*/
|
|
1442
|
+
mcpServers?: Record<string, MCPServerConfig>;
|
|
1443
|
+
/**
|
|
1444
|
+
* Whether the agent should be available for model inference.
|
|
1445
|
+
* @default true
|
|
1446
|
+
*/
|
|
1447
|
+
infer?: boolean;
|
|
1448
|
+
/**
|
|
1449
|
+
* List of skill names to preload into this agent's context.
|
|
1450
|
+
* When set, the full content of each listed skill is eagerly injected into
|
|
1451
|
+
* the agent's context at startup. Skills are resolved by name from the
|
|
1452
|
+
* session's configured skill directories (`skillDirectories`).
|
|
1453
|
+
* When omitted, no skills are injected (opt-in model).
|
|
1454
|
+
*/
|
|
1455
|
+
skills?: string[];
|
|
1456
|
+
/**
|
|
1457
|
+
* Model identifier for this agent (e.g. "claude-haiku-4.5").
|
|
1458
|
+
* When set, the runtime will attempt to use this model for the agent,
|
|
1459
|
+
* falling back to the parent session model if unavailable.
|
|
1460
|
+
*/
|
|
1461
|
+
model?: string;
|
|
1462
|
+
/**
|
|
1463
|
+
* Reasoning effort level for this agent's model.
|
|
1464
|
+
* When omitted, the runtime resolves the effort from model configuration,
|
|
1465
|
+
* then inherits the parent effort only if this agent uses the same model.
|
|
1466
|
+
*/
|
|
1467
|
+
reasoningEffort?: ReasoningEffort;
|
|
1468
|
+
}
|
|
1469
|
+
/**
|
|
1470
|
+
* Configuration for the default agent (the built-in agent that handles
|
|
1471
|
+
* turns when no custom agent is selected).
|
|
1472
|
+
* Use this to control tool visibility for the default agent independently of custom sub-agents.
|
|
1473
|
+
*/
|
|
1474
|
+
export interface DefaultAgentConfig {
|
|
1475
|
+
/**
|
|
1476
|
+
* List of tool names to exclude from the default agent.
|
|
1477
|
+
* These tools remain available to custom sub-agents that reference them in their `tools` array.
|
|
1478
|
+
* Use this to register tools that should only be accessed via delegation to sub-agents,
|
|
1479
|
+
* keeping the default agent's context clean.
|
|
1480
|
+
*/
|
|
1481
|
+
excludedTools?: string[];
|
|
1482
|
+
}
|
|
1483
|
+
/**
|
|
1484
|
+
* Configuration for infinite sessions with automatic context compaction and workspace persistence.
|
|
1485
|
+
* When enabled, sessions automatically manage context window limits through background compaction
|
|
1486
|
+
* and persist state to a workspace directory.
|
|
1487
|
+
*/
|
|
1488
|
+
export interface InfiniteSessionConfig {
|
|
1489
|
+
/**
|
|
1490
|
+
* Whether infinite sessions are enabled.
|
|
1491
|
+
* @default true
|
|
1492
|
+
*/
|
|
1493
|
+
enabled?: boolean;
|
|
1494
|
+
/**
|
|
1495
|
+
* Context utilization threshold (0.0-1.0) at which background compaction starts.
|
|
1496
|
+
* Compaction runs asynchronously, allowing the session to continue processing.
|
|
1497
|
+
* @default 0.80
|
|
1498
|
+
*/
|
|
1499
|
+
backgroundCompactionThreshold?: number;
|
|
1500
|
+
/**
|
|
1501
|
+
* Context utilization threshold (0.0-1.0) at which the session blocks until compaction completes.
|
|
1502
|
+
* This prevents context overflow when compaction hasn't finished in time.
|
|
1503
|
+
* @default 0.95
|
|
1504
|
+
*/
|
|
1505
|
+
bufferExhaustionThreshold?: number;
|
|
1506
|
+
}
|
|
1507
|
+
/**
|
|
1508
|
+
* Configuration for the memory feature, which lets the agent persist and recall
|
|
1509
|
+
* information across turns.
|
|
1510
|
+
*/
|
|
1511
|
+
export interface MemoryConfiguration {
|
|
1512
|
+
/**
|
|
1513
|
+
* Whether the memory feature is enabled for this session.
|
|
1514
|
+
*/
|
|
1515
|
+
enabled: boolean;
|
|
1516
|
+
}
|
|
1517
|
+
/**
|
|
1518
|
+
* Configuration for handling large tool outputs.
|
|
1519
|
+
*
|
|
1520
|
+
* When a tool produces output exceeding the configured size, the output is
|
|
1521
|
+
* written to a temp file and a reference is returned to the model instead of
|
|
1522
|
+
* the full payload.
|
|
1523
|
+
*/
|
|
1524
|
+
export interface LargeToolOutputConfig {
|
|
1525
|
+
/**
|
|
1526
|
+
* Whether large output handling is enabled.
|
|
1527
|
+
* @default true
|
|
1528
|
+
*/
|
|
1529
|
+
enabled?: boolean;
|
|
1530
|
+
/**
|
|
1531
|
+
* Maximum size in bytes before output is written to a temp file.
|
|
1532
|
+
* @default 51200
|
|
1533
|
+
*/
|
|
1534
|
+
maxSizeBytes?: number;
|
|
1535
|
+
/**
|
|
1536
|
+
* Directory to write temp files to. Defaults to the OS temp directory.
|
|
1537
|
+
*/
|
|
1538
|
+
outputDirectory?: string;
|
|
1539
|
+
}
|
|
1540
|
+
/**
|
|
1541
|
+
* Valid reasoning effort levels for models that support it.
|
|
1542
|
+
*/
|
|
1543
|
+
export type ReasoningEffort = "low" | "medium" | "high" | "xhigh" | "max";
|
|
1544
|
+
/**
|
|
1545
|
+
* Context window tier for the session. "long_context" pins the session to the
|
|
1546
|
+
* long-context tier when the selected model supports it.
|
|
1547
|
+
*/
|
|
1548
|
+
export type ContextTier = "default" | "long_context";
|
|
1549
|
+
/** Parsed parameters from an MCP server's WWW-Authenticate response. */
|
|
1550
|
+
export interface McpAuthWwwAuthenticateParams {
|
|
1551
|
+
/** Parsed resource_metadata URL used for protected-resource metadata discovery, if present. */
|
|
1552
|
+
resourceMetadataUrl?: string;
|
|
1553
|
+
/** Parsed OAuth scope, if present. */
|
|
1554
|
+
scope?: string;
|
|
1555
|
+
/** Parsed OAuth error, if present. */
|
|
1556
|
+
error?: string;
|
|
1557
|
+
}
|
|
1558
|
+
/** Static OAuth client configuration supplied by the MCP server, if available. */
|
|
1559
|
+
export interface McpAuthStaticClientConfig {
|
|
1560
|
+
/** OAuth client ID for the server. */
|
|
1561
|
+
clientId: string;
|
|
1562
|
+
/** Optional OAuth client secret for confidential static clients. */
|
|
1563
|
+
clientSecret?: string;
|
|
1564
|
+
/** Optional non-default OAuth grant type. */
|
|
1565
|
+
grantType?: "client_credentials";
|
|
1566
|
+
/** Whether this is a public OAuth client. */
|
|
1567
|
+
publicClient?: boolean;
|
|
1568
|
+
}
|
|
1569
|
+
/** MCP OAuth request that the SDK host can satisfy with a host-acquired token. */
|
|
1570
|
+
export interface McpAuthRequest {
|
|
1571
|
+
/** Unique request identifier used by the SDK when responding. */
|
|
1572
|
+
requestId: string;
|
|
1573
|
+
/** Display name of the MCP server that requires OAuth. */
|
|
1574
|
+
serverName: string;
|
|
1575
|
+
/** URL of the MCP server that requires OAuth. */
|
|
1576
|
+
serverUrl: string;
|
|
1577
|
+
/** Why the runtime is requesting host-provided OAuth credentials. */
|
|
1578
|
+
reason: "initial" | "refresh" | "reauth" | "upscope";
|
|
1579
|
+
/** Parsed WWW-Authenticate parameters from the MCP server. */
|
|
1580
|
+
wwwAuthenticateParams?: McpAuthWwwAuthenticateParams;
|
|
1581
|
+
/** Raw RFC 9728 protected-resource metadata JSON fetched by the runtime, if available. */
|
|
1582
|
+
resourceMetadata?: string;
|
|
1583
|
+
/** Static OAuth client configuration, if the server specifies one. */
|
|
1584
|
+
staticClientConfig?: McpAuthStaticClientConfig;
|
|
1585
|
+
}
|
|
1586
|
+
/** Host-provided OAuth token data for a pending MCP OAuth request. */
|
|
1587
|
+
export interface McpAuthToken {
|
|
1588
|
+
/** Access token acquired by the SDK host. */
|
|
1589
|
+
accessToken: string;
|
|
1590
|
+
/** OAuth token type. Defaults to Bearer when omitted. */
|
|
1591
|
+
tokenType?: string;
|
|
1592
|
+
/** Token lifetime in seconds, if known. */
|
|
1593
|
+
expiresIn?: number;
|
|
1594
|
+
}
|
|
1595
|
+
/**
|
|
1596
|
+
* Result returned by an MCP auth request handler.
|
|
1597
|
+
*
|
|
1598
|
+
* Return `null`/`undefined` or `{ kind: "cancelled" }` to cancel the pending
|
|
1599
|
+
* OAuth request. Return `{ kind: "token", ... }` to provide host-acquired
|
|
1600
|
+
* OAuth token data.
|
|
1601
|
+
*/
|
|
1602
|
+
export type McpAuthResult = ({
|
|
1603
|
+
kind: "token";
|
|
1604
|
+
} & McpAuthToken) | {
|
|
1605
|
+
kind: "cancelled";
|
|
1606
|
+
};
|
|
1607
|
+
/** Callback invoked when an MCP server requires OAuth and the SDK host opted in. */
|
|
1608
|
+
export type McpAuthHandler = (request: McpAuthRequest, context: {
|
|
1609
|
+
sessionId: string;
|
|
1610
|
+
}) => McpAuthResult | McpAuthToken | null | undefined | Promise<McpAuthResult | McpAuthToken | null | undefined>;
|
|
1611
|
+
/**
|
|
1612
|
+
* Stable extension identity for session participants that provide canvases.
|
|
1613
|
+
*/
|
|
1614
|
+
export interface ExtensionInfo {
|
|
1615
|
+
/** Extension namespace/source, e.g. "github-app". */
|
|
1616
|
+
source: string;
|
|
1617
|
+
/** Stable provider name within the source namespace. */
|
|
1618
|
+
name: string;
|
|
1619
|
+
}
|
|
1620
|
+
/**
|
|
1621
|
+
* Stable identity for a host/SDK connection that supplies built-in canvases.
|
|
1622
|
+
*
|
|
1623
|
+
* When set on session create or resume, the runtime uses {@link id} verbatim
|
|
1624
|
+
* as the agent-facing canvas extension id, so canvases declared on a control
|
|
1625
|
+
* connection survive stdio reconnect and CLI process restart instead of being
|
|
1626
|
+
* re-keyed to a per-connection id. The id is opaque to the runtime; a
|
|
1627
|
+
* per-window-stable value such as `app:builtin:<windowId>` is recommended. An
|
|
1628
|
+
* id beginning with `connection:` is reserved and ignored by the runtime.
|
|
1629
|
+
*/
|
|
1630
|
+
export interface CanvasProviderIdentity {
|
|
1631
|
+
/** Opaque, stable provider id used verbatim as the canvas extension id. */
|
|
1632
|
+
id: string;
|
|
1633
|
+
/** Optional display name surfaced as the canvas extension name. */
|
|
1634
|
+
name?: string;
|
|
1635
|
+
}
|
|
1636
|
+
/**
|
|
1637
|
+
* Static resource ceilings declared by a factory before it runs.
|
|
1638
|
+
*
|
|
1639
|
+
* @experimental Part of the experimental Agent Factories surface and may
|
|
1640
|
+
* change or be removed in future SDK or CLI releases.
|
|
1641
|
+
*/
|
|
1642
|
+
export interface FactoryLimits {
|
|
1643
|
+
/** Maximum number of factory subagents that may run concurrently. Must be positive when present. */
|
|
1644
|
+
maxConcurrentSubagents?: number;
|
|
1645
|
+
/** Maximum total number of factory subagents that may be spawned. Must be positive when present. */
|
|
1646
|
+
maxTotalSubagents?: number;
|
|
1647
|
+
/** Maximum AI credits consumed by factory subagents and descendants. This post-paid ceiling is soft. */
|
|
1648
|
+
maxAiCredits?: number;
|
|
1649
|
+
/**
|
|
1650
|
+
* Maximum accumulated active-execution time, in seconds. Active execution includes the entire extension body,
|
|
1651
|
+
* subprocess waits, queued-agent waits, and sleeps. The limit is armed from the remaining headroom when a run
|
|
1652
|
+
* resumes; time between attempts is not counted. Must be finite and positive when present.
|
|
1653
|
+
*/
|
|
1654
|
+
timeoutSeconds?: number;
|
|
1655
|
+
}
|
|
1656
|
+
/**
|
|
1657
|
+
* Registration metadata for an extension-authored factory.
|
|
1658
|
+
*
|
|
1659
|
+
* @experimental Part of the experimental Agent Factories surface and may
|
|
1660
|
+
* change or be removed in future SDK or CLI releases.
|
|
1661
|
+
*/
|
|
1662
|
+
export interface FactoryMeta {
|
|
1663
|
+
/** Stable factory name used for invocation. */
|
|
1664
|
+
name: string;
|
|
1665
|
+
/** Human-readable factory description. */
|
|
1666
|
+
description: string;
|
|
1667
|
+
/** Display metadata for the progress phases the factory may report. */
|
|
1668
|
+
phases: Array<{
|
|
1669
|
+
title: string;
|
|
1670
|
+
detail?: string;
|
|
1671
|
+
}>;
|
|
1672
|
+
/**
|
|
1673
|
+
* Optional declared shape of the arguments this factory expects as `ctx.args`.
|
|
1674
|
+
*
|
|
1675
|
+
* Declaring one is strongly recommended for any factory that reads `ctx.args`.
|
|
1676
|
+
* When the model invokes the factory through the `run_factory` tool, the CLI
|
|
1677
|
+
* validates `args` against this declaration **before** the run starts, so a
|
|
1678
|
+
* malformed call is rejected with a correction hint and retried without ever
|
|
1679
|
+
* creating a run row, prompting the user for permission, or spending credits. A
|
|
1680
|
+
* factory that declares nothing is never validated: a malformed call starts,
|
|
1681
|
+
* takes an approval, spends credits, and then fails inside the factory body.
|
|
1682
|
+
* `factories_manage` with `operation: "inspect"` reports the declared shape so an
|
|
1683
|
+
* agent can read it before invoking.
|
|
1684
|
+
*
|
|
1685
|
+
* This covers the model's `run_factory` path only. `session.factory.run(...)` is
|
|
1686
|
+
* not validated against the declaration, so a factory should still check
|
|
1687
|
+
* `ctx.args` rather than assume the declared shape held.
|
|
1688
|
+
*
|
|
1689
|
+
* Enforcement covers structure — types, required properties, and enum/const
|
|
1690
|
+
* values. Finer constraints such as `minLength`, `pattern`, and
|
|
1691
|
+
* `additionalProperties` are recorded in the declaration but not enforced. See
|
|
1692
|
+
* {@link FactoryJsonSchema} for the accepted subset. A declaration outside that
|
|
1693
|
+
* subset is rejected at registration.
|
|
1694
|
+
*/
|
|
1695
|
+
argsSchema?: FactoryJsonSchema;
|
|
1696
|
+
/** Optional resource ceilings presented to the user before execution. */
|
|
1697
|
+
limits?: FactoryLimits;
|
|
1698
|
+
}
|
|
1699
|
+
/**
|
|
1700
|
+
* Provider-scoped options for the Copilot API (CAPI).
|
|
1701
|
+
*
|
|
1702
|
+
* These settings apply to the built-in Copilot API provider only. They live
|
|
1703
|
+
* under their own namespace because a single session can host multiple
|
|
1704
|
+
* providers (CAPI alongside BYOK via {@link ProviderConfig}), so transport and
|
|
1705
|
+
* provider-level choices are conceptually per-provider rather than global.
|
|
1706
|
+
*/
|
|
1707
|
+
export interface CapiSessionOptions {
|
|
1708
|
+
/**
|
|
1709
|
+
* Whether to use the WebSocket transport for the CAPI Responses API.
|
|
1710
|
+
*
|
|
1711
|
+
* WebSocket transport is enabled by default whenever the selected model
|
|
1712
|
+
* advertises the `ws:/responses` endpoint. Set this to `false` to fall back
|
|
1713
|
+
* to the HTTP Responses transport instead — useful for users behind proxies
|
|
1714
|
+
* where WebSocket connections fail.
|
|
1715
|
+
*
|
|
1716
|
+
* Setting this to `false` is equivalent to setting the
|
|
1717
|
+
* `COPILOT_CLI_DISABLE_WEBSOCKET_RESPONSES` environment variable.
|
|
1718
|
+
*
|
|
1719
|
+
* @default true
|
|
1720
|
+
*/
|
|
1721
|
+
enableWebSocketResponses?: boolean;
|
|
1722
|
+
}
|
|
1723
|
+
/**
|
|
1724
|
+
* A single ExP (Experiment Platform) flag value. ExP assignments resolve to a
|
|
1725
|
+
* string, number, boolean, or `null`.
|
|
1726
|
+
*/
|
|
1727
|
+
export type ExpFlagValue = string | number | boolean | null;
|
|
1728
|
+
/**
|
|
1729
|
+
* A single configuration entry in a {@link CopilotExpAssignmentResponse}. Each
|
|
1730
|
+
* entry carries an identifier and a bag of typed parameter values.
|
|
1731
|
+
*/
|
|
1732
|
+
export interface ExpConfigEntry {
|
|
1733
|
+
/** Identifier of the configuration entry. */
|
|
1734
|
+
Id: string;
|
|
1735
|
+
/** Parameter values keyed by parameter name. */
|
|
1736
|
+
Parameters: Record<string, ExpFlagValue>;
|
|
1737
|
+
}
|
|
1738
|
+
/**
|
|
1739
|
+
* ExP ("flight") assignment data, in the same JSON shape the Copilot CLI
|
|
1740
|
+
* fetches from the experimentation service. Field names are PascalCase to match
|
|
1741
|
+
* the on-the-wire contract consumed by the runtime.
|
|
1742
|
+
*/
|
|
1743
|
+
export interface CopilotExpAssignmentResponse {
|
|
1744
|
+
/** Enabled feature names. */
|
|
1745
|
+
Features: string[];
|
|
1746
|
+
/** Assigned flights keyed by flight name. */
|
|
1747
|
+
Flights: Record<string, string>;
|
|
1748
|
+
/** Configuration entries carrying typed parameter values. */
|
|
1749
|
+
Configs: ExpConfigEntry[];
|
|
1750
|
+
/** Opaque parameter-group payload passed through untouched. */
|
|
1751
|
+
ParameterGroups?: unknown;
|
|
1752
|
+
/** Version of the flighting configuration. */
|
|
1753
|
+
FlightingVersion?: number;
|
|
1754
|
+
/** Impression identifier for the assignment. */
|
|
1755
|
+
ImpressionId?: string;
|
|
1756
|
+
/** Assignment context string forwarded to CAPI and telemetry. */
|
|
1757
|
+
AssignmentContext: string;
|
|
1758
|
+
}
|
|
1759
|
+
/**
|
|
1760
|
+
* Configuration for the built-in GitHub MCP server.
|
|
1761
|
+
*
|
|
1762
|
+
* `disableFormDeferral` only applies to the built-in GitHub MCP server and
|
|
1763
|
+
* only has an effect when MCP Apps and form-backed GitHub tools are enabled.
|
|
1764
|
+
*/
|
|
1765
|
+
export interface GitHubMcpToolConfig {
|
|
1766
|
+
enableAllTools?: boolean;
|
|
1767
|
+
additionalToolsets?: string[];
|
|
1768
|
+
additionalTools?: string[];
|
|
1769
|
+
enableInsidersMode?: boolean;
|
|
1770
|
+
disableFormDeferral?: boolean;
|
|
1771
|
+
}
|
|
1772
|
+
/** Well-known managed bypass-permissions policies. */
|
|
1773
|
+
export declare const DisableBypassPermissionsModes: {
|
|
1774
|
+
/** Turn off bypass-permissions mode entirely. */
|
|
1775
|
+
readonly Disable: "disable";
|
|
1776
|
+
/** Permit automatic bypass but block full allow-all. */
|
|
1777
|
+
readonly AllowAutoOnly: "allow-auto-only";
|
|
1778
|
+
};
|
|
1779
|
+
/**
|
|
1780
|
+
* Permissions-only managed policy injected by the host via
|
|
1781
|
+
* {@link SessionConfigBase.managedSettings}.
|
|
1782
|
+
*
|
|
1783
|
+
* Rule strings use the same vocabulary the runtime accepts for fetched managed
|
|
1784
|
+
* policy (e.g. `"Read(**)"`, `"Shell(git push *)"`); malformed rules are
|
|
1785
|
+
* rejected at session creation.
|
|
1786
|
+
*/
|
|
1787
|
+
export interface ManagedSettingsPermissions {
|
|
1788
|
+
/**
|
|
1789
|
+
* Restricts bypass-permissions mode for the session. See
|
|
1790
|
+
* {@link DisableBypassPermissionsModes} for well-known values. Unknown
|
|
1791
|
+
* values are forwarded so newer runtime policies fail closed.
|
|
1792
|
+
*/
|
|
1793
|
+
disableBypassPermissionsMode?: string;
|
|
1794
|
+
/** Operations that must always be denied. Unioned across managed layers. */
|
|
1795
|
+
deny?: string[];
|
|
1796
|
+
/**
|
|
1797
|
+
* Operations that must prompt for approval. Unioned across managed layers.
|
|
1798
|
+
*/
|
|
1799
|
+
ask?: string[];
|
|
1800
|
+
/**
|
|
1801
|
+
* Operations permitted without prompting. Every declared `allow` list
|
|
1802
|
+
* (across managed layers) must admit an operation for it to be allowed.
|
|
1803
|
+
*/
|
|
1804
|
+
allow?: string[];
|
|
1805
|
+
}
|
|
1806
|
+
/**
|
|
1807
|
+
* Host-injected enterprise managed settings. The first supported contract is
|
|
1808
|
+
* permissions-only; unknown sibling keys are rejected by the runtime.
|
|
1809
|
+
*
|
|
1810
|
+
* @see {@link SessionConfigBase.managedSettings}
|
|
1811
|
+
*/
|
|
1812
|
+
export interface ManagedSettings {
|
|
1813
|
+
/** Managed permission policy for the session. */
|
|
1814
|
+
permissions?: ManagedSettingsPermissions;
|
|
1815
|
+
}
|
|
1816
|
+
/** Selects the model-facing shape of the built-in `ask_user` tool. */
|
|
1817
|
+
export type AskUserVariant = "legacy" | "elicitation";
|
|
1818
|
+
/**
|
|
1819
|
+
* Shared configuration fields used by both {@link SessionConfig} (for
|
|
1820
|
+
* creating a new session) and {@link ResumeSessionConfig} (for resuming
|
|
1821
|
+
* an existing one).
|
|
1822
|
+
*/
|
|
1823
|
+
export interface SessionConfigBase {
|
|
1824
|
+
/**
|
|
1825
|
+
* Client name to identify the application using the SDK.
|
|
1826
|
+
* Included in the User-Agent header for API requests.
|
|
1827
|
+
*/
|
|
1828
|
+
clientName?: string;
|
|
1829
|
+
/**
|
|
1830
|
+
* Model to use for this session
|
|
1831
|
+
*/
|
|
1832
|
+
model?: string;
|
|
1833
|
+
/**
|
|
1834
|
+
* Reasoning effort level for models that support it.
|
|
1835
|
+
* Only valid for models where capabilities.supports.reasoningEffort is true.
|
|
1836
|
+
* Use client.listModels() to check supported values for each model.
|
|
1837
|
+
*/
|
|
1838
|
+
reasoningEffort?: ReasoningEffort;
|
|
1839
|
+
/**
|
|
1840
|
+
* Reasoning summary mode for models that support configurable reasoning summaries.
|
|
1841
|
+
* Use "none" to suppress summary output regardless of whether reasoning is enabled.
|
|
1842
|
+
*/
|
|
1843
|
+
reasoningSummary?: ReasoningSummary;
|
|
1844
|
+
/**
|
|
1845
|
+
* Controls whether the session enables experimental features.
|
|
1846
|
+
* Defaults to `false` in `"empty"` mode; otherwise the runtime decides when unset.
|
|
1847
|
+
*/
|
|
1848
|
+
enableExperimentalMode?: boolean;
|
|
1849
|
+
/**
|
|
1850
|
+
* Context window tier for models that support it. Use "long_context" to pin
|
|
1851
|
+
* the session to the long-context tier; omit or use "default" otherwise.
|
|
1852
|
+
*/
|
|
1853
|
+
contextTier?: ContextTier;
|
|
1854
|
+
/** Per-property overrides for model capabilities, deep-merged over runtime defaults. */
|
|
1855
|
+
modelCapabilities?: ModelCapabilitiesOverride;
|
|
1856
|
+
/**
|
|
1857
|
+
* Configuration for handling large tool outputs. When a tool produces
|
|
1858
|
+
* output exceeding the configured size, the output is written to a temp
|
|
1859
|
+
* file and a reference is returned to the model instead of the full
|
|
1860
|
+
* payload.
|
|
1861
|
+
*/
|
|
1862
|
+
largeOutput?: LargeToolOutputConfig;
|
|
1863
|
+
/**
|
|
1864
|
+
* Override the default configuration directory location.
|
|
1865
|
+
* When specified, the session will use this directory for storing config and state.
|
|
1866
|
+
*/
|
|
1867
|
+
configDirectory?: string;
|
|
1868
|
+
/**
|
|
1869
|
+
* Enables runtime discovery of supported configuration. Explicitly supplied
|
|
1870
|
+
* configuration takes precedence over discovered values.
|
|
1871
|
+
*
|
|
1872
|
+
* @default false
|
|
1873
|
+
*/
|
|
1874
|
+
enableConfigDiscovery?: boolean;
|
|
1875
|
+
/**
|
|
1876
|
+
* Tools exposed to the CLI server. Tools without a handler are declaration-only
|
|
1877
|
+
* and must be resolved by the consumer via pending external tool request RPCs.
|
|
1878
|
+
*/
|
|
1879
|
+
tools?: Tool<any>[];
|
|
1880
|
+
/**
|
|
1881
|
+
* Canvases contributed by this session participant. The declaring
|
|
1882
|
+
* connection becomes the live provider for `canvas.open|focus|close|reload`
|
|
1883
|
+
* and `canvas.action.invoke` dispatches targeting each canvas's `id` for
|
|
1884
|
+
* the lifetime of the connection. Re-declaring the same id on resume
|
|
1885
|
+
* replaces the prior declaration.
|
|
1886
|
+
*/
|
|
1887
|
+
canvases?: Canvas[];
|
|
1888
|
+
/**
|
|
1889
|
+
* Renderer-side opt-in: when true, the runtime surfaces canvas agent tools
|
|
1890
|
+
* (`list_canvas_capabilities`, `open_canvas`, `invoke_canvas_action`) to
|
|
1891
|
+
* the model for this connection. Default off so SDK callers that cannot
|
|
1892
|
+
* display canvases stay clean.
|
|
1893
|
+
*/
|
|
1894
|
+
requestCanvasRenderer?: boolean;
|
|
1895
|
+
/**
|
|
1896
|
+
* Extension surface opt-in: when true, the runtime wires extension
|
|
1897
|
+
* management tools and per-extension tool dispatch onto the session for
|
|
1898
|
+
* this connection. Default off so callers that do not expose extensions
|
|
1899
|
+
* stay clean.
|
|
1900
|
+
*/
|
|
1901
|
+
requestExtensions?: boolean;
|
|
1902
|
+
/**
|
|
1903
|
+
* Optional override path to a `copilot-sdk/` folder to inject into
|
|
1904
|
+
* extension subprocesses for this session in place of the bundled SDK.
|
|
1905
|
+
* When unset or invalid (missing folder or missing `index.js` /
|
|
1906
|
+
* `extension.js`), the runtime falls back to the bundled SDK without
|
|
1907
|
+
* throwing. Takes precedence over any server-level default.
|
|
1908
|
+
*
|
|
1909
|
+
* Only honored on session create and resume — extensions joining via
|
|
1910
|
+
* `joinSession` cannot override the SDK path, because the extension
|
|
1911
|
+
* subprocess has already been forked by the host with the SDK the host
|
|
1912
|
+
* chose. `JoinSessionConfig` omits this field for that reason.
|
|
1913
|
+
*/
|
|
1914
|
+
extensionSdkPath?: string;
|
|
1915
|
+
/**
|
|
1916
|
+
* Stable extension identity for canvas providers on this connection. When
|
|
1917
|
+
* set, the runtime uses `${source}:${name}` as the agent-facing extension
|
|
1918
|
+
* id instead of a reconnect-specific connection id.
|
|
1919
|
+
*/
|
|
1920
|
+
extensionInfo?: ExtensionInfo;
|
|
1921
|
+
/**
|
|
1922
|
+
* Stable identity for a host/SDK connection that supplies built-in
|
|
1923
|
+
* canvases. When set, the runtime uses `id` verbatim as the agent-facing
|
|
1924
|
+
* canvas extension id, so canvases declared on a control connection survive
|
|
1925
|
+
* reconnect and CLI restart. Honored on session create and resume.
|
|
1926
|
+
*/
|
|
1927
|
+
canvasProvider?: CanvasProviderIdentity;
|
|
1928
|
+
/**
|
|
1929
|
+
* Slash commands registered for this session.
|
|
1930
|
+
* When the CLI has a TUI, each command appears as `/name` for the user to invoke.
|
|
1931
|
+
* The handler is called when the user executes the command.
|
|
1932
|
+
*/
|
|
1933
|
+
commands?: CommandDefinition[];
|
|
1934
|
+
/**
|
|
1935
|
+
* System message configuration
|
|
1936
|
+
* Controls how the system prompt is constructed
|
|
1937
|
+
*/
|
|
1938
|
+
systemMessage?: SystemMessageConfig;
|
|
1939
|
+
/**
|
|
1940
|
+
* Override for the runtime's built-in tool-search behavior.
|
|
1941
|
+
*
|
|
1942
|
+
* To also override the tool-search tool's implementation, register a
|
|
1943
|
+
* {@link Tool} named `tool_search_tool` with `overridesBuiltInTool: true` in
|
|
1944
|
+
* {@link SessionConfigBase.tools}.
|
|
1945
|
+
*/
|
|
1946
|
+
toolSearch?: ToolSearchConfig;
|
|
1947
|
+
/**
|
|
1948
|
+
* List of tool names to allow. When specified, only these tools will be available.
|
|
1949
|
+
*
|
|
1950
|
+
* Supports source-qualified filter patterns (`builtin:*`, `builtin:<name>`,
|
|
1951
|
+
* `mcp:*`, `mcp:<name>`, `custom:*`, `custom:<name>`) as well as the bare
|
|
1952
|
+
* name form (exact match across any source). Build this list with
|
|
1953
|
+
* {@link ToolSet} for type safety and readable intent.
|
|
1954
|
+
*
|
|
1955
|
+
* Composes with {@link excludedTools}: a tool is enabled when it matches
|
|
1956
|
+
* `availableTools` (or `availableTools` is unset) AND it does not match
|
|
1957
|
+
* `excludedTools`. This lets you express "everything matching X except Y".
|
|
1958
|
+
*/
|
|
1959
|
+
availableTools?: string[] | ToolSet;
|
|
1960
|
+
/**
|
|
1961
|
+
* List of tool names to disable. Supports the same pattern syntax as
|
|
1962
|
+
* {@link availableTools}.
|
|
1963
|
+
*
|
|
1964
|
+
* Always takes precedence over {@link availableTools}: a tool listed here
|
|
1965
|
+
* is disabled even if it also matches `availableTools`.
|
|
1966
|
+
*/
|
|
1967
|
+
excludedTools?: string[] | ToolSet;
|
|
1968
|
+
/**
|
|
1969
|
+
* Names of built-in agents to exclude from the session. Excluded built-in
|
|
1970
|
+
* agents are hidden from discovery and cannot be selected or invoked unless
|
|
1971
|
+
* a custom agent with the same name is configured.
|
|
1972
|
+
*/
|
|
1973
|
+
excludedBuiltinAgents?: string[];
|
|
1974
|
+
/**
|
|
1975
|
+
* Built-in skill names to include in the session. In `mode: "empty"`,
|
|
1976
|
+
* omitting this option excludes all runtime-bundled skills; specifying names
|
|
1977
|
+
* opts those built-ins back in. Skills from other sources remain eligible.
|
|
1978
|
+
*/
|
|
1979
|
+
includedBuiltinSkills?: string[];
|
|
1980
|
+
/**
|
|
1981
|
+
* Custom provider configuration (BYOK - Bring Your Own Key).
|
|
1982
|
+
* When specified, uses the provided API endpoint instead of the Copilot API.
|
|
1983
|
+
*/
|
|
1984
|
+
provider?: ProviderConfig;
|
|
1985
|
+
/**
|
|
1986
|
+
* Provider-scoped options for the built-in Copilot API (CAPI), such as
|
|
1987
|
+
* opting out of the WebSocket Responses transport. See
|
|
1988
|
+
* {@link CapiSessionOptions}.
|
|
1989
|
+
*/
|
|
1990
|
+
capi?: CapiSessionOptions;
|
|
1991
|
+
/**
|
|
1992
|
+
* Named BYOK provider connections (transport + credentials), referenced by
|
|
1993
|
+
* {@link models} entries via {@link NamedProviderConfig.name}.
|
|
1994
|
+
*
|
|
1995
|
+
* Unlike the singular {@link provider} — which makes the entire session BYOK
|
|
1996
|
+
* and bypasses Copilot API authentication — named providers are **additive**:
|
|
1997
|
+
* they coexist with Copilot API auth so models from CAPI and one or more BYOK
|
|
1998
|
+
* providers can be mixed within a single session and across sub-agents.
|
|
1999
|
+
* Combining `providers`/`models` with {@link provider} is rejected.
|
|
2000
|
+
*
|
|
2001
|
+
* @experimental This is part of an experimental multi-provider BYOK surface
|
|
2002
|
+
* and may change or be removed in future SDK or CLI releases.
|
|
2003
|
+
*/
|
|
2004
|
+
providers?: NamedProviderConfig[];
|
|
2005
|
+
/**
|
|
2006
|
+
* BYOK model definitions added to the session's selectable model list, each
|
|
2007
|
+
* referencing a `providers[].name`. Each model surfaces under the
|
|
2008
|
+
* provider-qualified selection id `providerName/id`, so BYOK ids never collide
|
|
2009
|
+
* with — and cannot shadow — bare CAPI ids; duplicate selection ids are rejected.
|
|
2010
|
+
*
|
|
2011
|
+
* @experimental This is part of an experimental multi-provider BYOK surface
|
|
2012
|
+
* and may change or be removed in future SDK or CLI releases.
|
|
2013
|
+
*/
|
|
2014
|
+
models?: ProviderModelConfig[];
|
|
2015
|
+
/**
|
|
2016
|
+
* Enables or disables internal session telemetry for this session.
|
|
2017
|
+
* When `false`, disables session telemetry. When omitted (the default) or `true`,
|
|
2018
|
+
* telemetry is enabled for GitHub-authenticated sessions.
|
|
2019
|
+
* When a custom {@link provider} (BYOK) is configured, session telemetry is always
|
|
2020
|
+
* disabled regardless of this setting.
|
|
2021
|
+
* This is independent of the OpenTelemetry configuration in {@link CopilotClientOptions.telemetry}.
|
|
2022
|
+
*/
|
|
2023
|
+
enableSessionTelemetry?: boolean;
|
|
2024
|
+
/**
|
|
2025
|
+
* Enables native model citations for supported providers.
|
|
2026
|
+
*
|
|
2027
|
+
* @experimental
|
|
2028
|
+
*/
|
|
2029
|
+
enableCitations?: boolean;
|
|
2030
|
+
/**
|
|
2031
|
+
* Opt in to capturing file changes for session rewind and cumulative session
|
|
2032
|
+
* diff. On create, capture starts with the first turn. On resume, this can
|
|
2033
|
+
* enable tracking only when the session still has a valid baseline; it cannot
|
|
2034
|
+
* reconstruct changes from earlier untracked turns.
|
|
2035
|
+
*/
|
|
2036
|
+
enableFileChangeTracking?: boolean;
|
|
2037
|
+
/**
|
|
2038
|
+
* Limits applied to this session's current accounting window.
|
|
2039
|
+
*
|
|
2040
|
+
* @experimental
|
|
2041
|
+
*/
|
|
2042
|
+
sessionLimits?: SessionLimitsConfig;
|
|
2043
|
+
/**
|
|
2044
|
+
* When true, the runtime skips loading custom-instruction sources
|
|
2045
|
+
* (e.g. `.github/copilot-instructions.md`, `AGENTS.md`, `CLAUDE.md`).
|
|
2046
|
+
*
|
|
2047
|
+
* Defaults to `false` (custom instructions are loaded). Under
|
|
2048
|
+
* {@link CopilotClientOptions.mode} = `"empty"`, defaults to `true`; apps
|
|
2049
|
+
* can pass `false` here to opt back in.
|
|
2050
|
+
*/
|
|
2051
|
+
skipCustomInstructions?: boolean;
|
|
2052
|
+
/**
|
|
2053
|
+
* When true, custom agents default to local-only execution and are not
|
|
2054
|
+
* dispatched to remote workers.
|
|
2055
|
+
*
|
|
2056
|
+
* Defaults to `false`. Under {@link CopilotClientOptions.mode} = `"empty"`,
|
|
2057
|
+
* defaults to `true`; apps can pass `false` here to opt back in.
|
|
2058
|
+
*/
|
|
2059
|
+
customAgentsLocalOnly?: boolean;
|
|
2060
|
+
/**
|
|
2061
|
+
* When true, the runtime instructs the agent to include a `Co-authored-by`
|
|
2062
|
+
* trailer in commit messages it composes.
|
|
2063
|
+
*
|
|
2064
|
+
* Defaults to `true`. Under {@link CopilotClientOptions.mode} = `"empty"`,
|
|
2065
|
+
* defaults to `false`; apps can pass `true` here to opt back in.
|
|
2066
|
+
*/
|
|
2067
|
+
coauthorEnabled?: boolean;
|
|
2068
|
+
/**
|
|
2069
|
+
* When true, the `manage_schedule` tool is exposed to the agent.
|
|
2070
|
+
*
|
|
2071
|
+
* Defaults to whatever the runtime exposes (typically gated to staff
|
|
2072
|
+
* users). Under {@link CopilotClientOptions.mode} = `"empty"`, defaults to
|
|
2073
|
+
* `false`; apps can pass `true` here to opt back in.
|
|
2074
|
+
*/
|
|
2075
|
+
manageScheduleEnabled?: boolean;
|
|
2076
|
+
/**
|
|
2077
|
+
* Optional handler for permission requests from the server.
|
|
2078
|
+
* When omitted, permission requests are surfaced as events and left pending for
|
|
2079
|
+
* the consumer to resolve via the pending permission RPC.
|
|
2080
|
+
*/
|
|
2081
|
+
onPermissionRequest?: PermissionHandler;
|
|
2082
|
+
/**
|
|
2083
|
+
* Optional handler for MCP OAuth requests from MCP servers.
|
|
2084
|
+
* When provided, the SDK can satisfy MCP server OAuth requests with
|
|
2085
|
+
* host-provided token data or cancellation.
|
|
2086
|
+
*/
|
|
2087
|
+
onMcpAuthRequest?: McpAuthHandler;
|
|
2088
|
+
/**
|
|
2089
|
+
* Handler for user input requests from the agent.
|
|
2090
|
+
* When provided with the default `legacy` {@link AskUserVariant}, enables the
|
|
2091
|
+
* question-and-answer form of the `ask_user` tool.
|
|
2092
|
+
*/
|
|
2093
|
+
onUserInputRequest?: UserInputHandler;
|
|
2094
|
+
/**
|
|
2095
|
+
* Selects the model-facing shape of the built-in `ask_user` tool.
|
|
2096
|
+
*
|
|
2097
|
+
* The default is `"legacy"`. To use `"elicitation"`, also provide
|
|
2098
|
+
* {@link onElicitationRequest} so the host can answer structured forms.
|
|
2099
|
+
* The runtime resolves this option when it creates or cold-resumes the session.
|
|
2100
|
+
*/
|
|
2101
|
+
askUserVariant?: AskUserVariant;
|
|
2102
|
+
/**
|
|
2103
|
+
* Handler for elicitation requests from the agent.
|
|
2104
|
+
* When provided, the server calls back to this client for form-based UI dialogs.
|
|
2105
|
+
* Also enables the `elicitation` capability on the session.
|
|
2106
|
+
*/
|
|
2107
|
+
onElicitationRequest?: ElicitationHandler;
|
|
2108
|
+
/**
|
|
2109
|
+
* Enable MCP Apps (SEP-1865) UI passthrough on this session.
|
|
2110
|
+
*
|
|
2111
|
+
* When `true` **and** the runtime has MCP Apps enabled (via the
|
|
2112
|
+
* `MCP_APPS` feature flag or `COPILOT_MCP_APPS=true` environment
|
|
2113
|
+
* override), the runtime adds the `mcp-apps` capability to the session,
|
|
2114
|
+
* which causes it to advertise the `extensions.io.modelcontextprotocol/ui`
|
|
2115
|
+
* extension to MCP servers (so they expose `_meta.ui.resourceUri` on
|
|
2116
|
+
* tools) and to expose the `session.rpc.mcp.apps.{listTools,callTool,
|
|
2117
|
+
* readResource,setHostContext,getHostContext,diagnose}` JSON-RPC methods.
|
|
2118
|
+
*
|
|
2119
|
+
* If the runtime gate is off, the opt-in is silently dropped server-side
|
|
2120
|
+
* (the runtime logs a warning); the session is created normally but the
|
|
2121
|
+
* MCP Apps surface is unavailable. Inspect the runtime's
|
|
2122
|
+
* `capabilities.ui.mcpApps` on the create/resume response to detect this.
|
|
2123
|
+
*
|
|
2124
|
+
* SDK consumers MUST set this to `true` only when they have an iframe
|
|
2125
|
+
* renderer that can display `ui://` MCP App bundles. Setting it without a
|
|
2126
|
+
* renderer will cause MCP servers to register UI-enabled tool variants
|
|
2127
|
+
* the consumer cannot display.
|
|
2128
|
+
*
|
|
2129
|
+
* @experimental This option is part of an experimental wire-protocol surface
|
|
2130
|
+
* (SEP-1865) and may change or be removed in a future release.
|
|
2131
|
+
*
|
|
2132
|
+
* @default false
|
|
2133
|
+
*/
|
|
2134
|
+
enableMcpApps?: boolean;
|
|
2135
|
+
/**
|
|
2136
|
+
* Configuration for the built-in GitHub MCP server.
|
|
2137
|
+
*
|
|
2138
|
+
* `disableFormDeferral` only applies to the built-in GitHub MCP server and
|
|
2139
|
+
* only has an effect when MCP Apps and form-backed GitHub tools are enabled.
|
|
2140
|
+
*/
|
|
2141
|
+
githubMcpToolConfig?: GitHubMcpToolConfig;
|
|
2142
|
+
/**
|
|
2143
|
+
* Handler for exit-plan-mode requests from the agent.
|
|
2144
|
+
* When provided, enables `exitPlanMode.request` callbacks.
|
|
2145
|
+
*/
|
|
2146
|
+
onExitPlanModeRequest?: ExitPlanModeHandler;
|
|
2147
|
+
/**
|
|
2148
|
+
* Handler for auto-mode-switch requests from the agent.
|
|
2149
|
+
* When provided, enables `autoModeSwitch.request` callbacks.
|
|
2150
|
+
*/
|
|
2151
|
+
onAutoModeSwitchRequest?: AutoModeSwitchHandler;
|
|
2152
|
+
/**
|
|
2153
|
+
* Hook handlers for intercepting session lifecycle events.
|
|
2154
|
+
* When provided, enables hooks callback allowing custom logic at various points.
|
|
2155
|
+
*/
|
|
2156
|
+
hooks?: SessionHooks;
|
|
2157
|
+
/**
|
|
2158
|
+
* Working directory for the session.
|
|
2159
|
+
* Tool operations will be relative to this directory.
|
|
2160
|
+
*/
|
|
2161
|
+
workingDirectory?: string;
|
|
2162
|
+
/**
|
|
2163
|
+
* Additional directories the agent may access beyond the working directory.
|
|
2164
|
+
* Relative paths are resolved against the session's working directory.
|
|
2165
|
+
* Re-supply these directories when resuming a session.
|
|
2166
|
+
*/
|
|
2167
|
+
additionalDirectories?: string[];
|
|
2168
|
+
/**
|
|
2169
|
+
* Enable streaming of assistant message and reasoning chunks.
|
|
2170
|
+
* When true, ephemeral assistant.message_delta and assistant.reasoning_delta
|
|
2171
|
+
* events are sent as the response is generated. Clients should accumulate
|
|
2172
|
+
* deltaContent values to build the full response.
|
|
2173
|
+
* @default false
|
|
2174
|
+
*/
|
|
2175
|
+
streaming?: boolean;
|
|
2176
|
+
/**
|
|
2177
|
+
* Include sub-agent streaming events in the event stream. When true, streaming
|
|
2178
|
+
* delta events from sub-agents (e.g., `assistant.message_delta`,
|
|
2179
|
+
* `assistant.reasoning_delta`, `assistant.streaming_delta` with `agentId` set)
|
|
2180
|
+
* are forwarded to this connection. When false, only non-streaming sub-agent
|
|
2181
|
+
* events and `subagent.*` lifecycle events are forwarded; streaming deltas from
|
|
2182
|
+
* sub-agents are suppressed.
|
|
2183
|
+
* @default true
|
|
2184
|
+
*/
|
|
2185
|
+
includeSubAgentStreamingEvents?: boolean;
|
|
2186
|
+
/**
|
|
2187
|
+
* Controls how MCP OAuth tokens are stored for this session.
|
|
2188
|
+
* - `"persistent"` — tokens are stored in the OS keychain (shared across sessions)
|
|
2189
|
+
* - `"in-memory"` — tokens are stored in memory and discarded when the session ends
|
|
2190
|
+
*
|
|
2191
|
+
* @default "in-memory"
|
|
2192
|
+
*/
|
|
2193
|
+
mcpOAuthTokenStorage?: "persistent" | "in-memory";
|
|
2194
|
+
/**
|
|
2195
|
+
* MCP server configurations for the session.
|
|
2196
|
+
* Keys are server names, values are server configurations.
|
|
2197
|
+
*/
|
|
2198
|
+
mcpServers?: Record<string, MCPServerConfig>;
|
|
2199
|
+
/**
|
|
2200
|
+
* Custom agent configurations for the session.
|
|
2201
|
+
*/
|
|
2202
|
+
customAgents?: CustomAgentConfig[];
|
|
2203
|
+
/**
|
|
2204
|
+
* Configuration for the default agent (the built-in agent that handles
|
|
2205
|
+
* turns when no custom agent is selected).
|
|
2206
|
+
* Use `excludedTools` to hide specific tools from the default agent while keeping
|
|
2207
|
+
* them available to custom sub-agents.
|
|
2208
|
+
*/
|
|
2209
|
+
defaultAgent?: DefaultAgentConfig;
|
|
2210
|
+
/**
|
|
2211
|
+
* Name of the custom agent to activate when the session starts.
|
|
2212
|
+
* Must match the `name` of one of the agents in `customAgents`.
|
|
2213
|
+
* Equivalent to calling `session.rpc.agent.select({ name })` after creation.
|
|
2214
|
+
*/
|
|
2215
|
+
agent?: string;
|
|
2216
|
+
/**
|
|
2217
|
+
* Directories to load skills from.
|
|
2218
|
+
*/
|
|
2219
|
+
skillDirectories?: string[];
|
|
2220
|
+
/**
|
|
2221
|
+
* Local filesystem paths to Open Plugins-format directories
|
|
2222
|
+
* (https://open-plugins.com/) to load for this session.
|
|
2223
|
+
*
|
|
2224
|
+
* Relative paths resolve against `workingDirectory` (or the runtime cwd if
|
|
2225
|
+
* unset); absolute paths are recommended. Invalid entries are logged and
|
|
2226
|
+
* skipped.
|
|
2227
|
+
*
|
|
2228
|
+
* Treated as an explicit opt-in: plugin agents and rules load even when
|
|
2229
|
+
* {@link SessionConfigBase.enableConfigDiscovery} is false. Loaded assets
|
|
2230
|
+
* slot between project (cwd) sources and personal/home sources in the
|
|
2231
|
+
* session-wide precedence order.
|
|
2232
|
+
*/
|
|
2233
|
+
pluginDirectories?: string[];
|
|
2234
|
+
/**
|
|
2235
|
+
* Additional directories to search for custom instruction files.
|
|
2236
|
+
*/
|
|
2237
|
+
instructionDirectories?: string[];
|
|
2238
|
+
/**
|
|
2239
|
+
* List of skill names to disable.
|
|
2240
|
+
*/
|
|
2241
|
+
disabledSkills?: string[];
|
|
2242
|
+
/**
|
|
2243
|
+
* Exact MCP server names to disable for this session. Disabled servers are not
|
|
2244
|
+
* started or authenticated when creating or cold-resuming a session. Supplying
|
|
2245
|
+
* this on a resident resume cannot stop servers that are already running.
|
|
2246
|
+
*/
|
|
2247
|
+
disabledMcpServers?: string[];
|
|
2248
|
+
/**
|
|
2249
|
+
* Infinite session configuration for persistent workspaces and automatic compaction.
|
|
2250
|
+
* When enabled (default), sessions automatically manage context limits and persist state.
|
|
2251
|
+
* Set to `{ enabled: false }` to disable.
|
|
2252
|
+
*/
|
|
2253
|
+
infiniteSessions?: InfiniteSessionConfig;
|
|
2254
|
+
/**
|
|
2255
|
+
* Memory configuration for the session. When omitted, the runtime default applies.
|
|
2256
|
+
*/
|
|
2257
|
+
memory?: MemoryConfiguration;
|
|
2258
|
+
/**
|
|
2259
|
+
* GitHub token for per-session authentication.
|
|
2260
|
+
* When provided, the runtime resolves this token into a full GitHub identity
|
|
2261
|
+
* (login, Copilot plan, endpoints) and stores it on the session. This enables
|
|
2262
|
+
* multitenancy — different sessions can have different GitHub identities.
|
|
2263
|
+
*
|
|
2264
|
+
* This is independent of the client-level `gitHubToken` in {@link CopilotClientOptions},
|
|
2265
|
+
* which authenticates the CLI process itself. The session-level token determines
|
|
2266
|
+
* the identity used for content exclusion, model routing, and quota checks.
|
|
2267
|
+
*/
|
|
2268
|
+
gitHubToken?: string;
|
|
2269
|
+
/**
|
|
2270
|
+
* Acquires short-lived GitHub credentials for this session on demand.
|
|
2271
|
+
*
|
|
2272
|
+
* Mutually exclusive with {@link SessionConfigBase.gitHubToken}. The
|
|
2273
|
+
* callback receives the effective GitHub host, the session ID when known,
|
|
2274
|
+
* and whether this is the initial acquisition or a refresh. Its opaque
|
|
2275
|
+
* registration ID remains internal to the SDK.
|
|
2276
|
+
*/
|
|
2277
|
+
gitHubTokenProvider?: GitHubTokenProvider;
|
|
2278
|
+
/**
|
|
2279
|
+
* Opt-in: when true, the runtime self-fetches enterprise managed settings
|
|
2280
|
+
* (bypass-permissions policy) at session bootstrap using the session's
|
|
2281
|
+
* `gitHubToken`. Requires {@link SessionConfigBase.gitHubToken} to be set;
|
|
2282
|
+
* if omitted, the runtime is expected to reject session creation (fail-closed).
|
|
2283
|
+
*/
|
|
2284
|
+
enableManagedSettings?: boolean;
|
|
2285
|
+
/**
|
|
2286
|
+
* Host-injected enterprise managed settings for this session.
|
|
2287
|
+
*
|
|
2288
|
+
* Unlike {@link SessionConfigBase.enableManagedSettings} — which asks the
|
|
2289
|
+
* runtime to *self-fetch* account/org and device policy — this field lets
|
|
2290
|
+
* the host supply the managed policy directly. The runtime validates it
|
|
2291
|
+
* with the same managed-permission parser it uses for fetched policy and
|
|
2292
|
+
* composes it restrictively with any self-fetched (server) and
|
|
2293
|
+
* device-managed (MDM) layers: `deny`/`ask` rules are unioned, every
|
|
2294
|
+
* declared `allow` list must admit an operation, and bypass-mode
|
|
2295
|
+
* restrictions are composed fail-closed.
|
|
2296
|
+
*
|
|
2297
|
+
* This is startup-only. It is **not** persisted: it must be re-supplied on
|
|
2298
|
+
* {@link CopilotClient.resumeSession | resume}, where it replaces the prior
|
|
2299
|
+
* injected layer (omitting it clears the layer, so warm and cold resume
|
|
2300
|
+
* behave identically). It may be combined with `enableManagedSettings`;
|
|
2301
|
+
* when both are supplied the injected, server, and device restrictions all
|
|
2302
|
+
* apply.
|
|
2303
|
+
*
|
|
2304
|
+
* Requires a Copilot runtime whose RPC schema includes `managedSettings`.
|
|
2305
|
+
* Older runtimes may ignore this additive field, so hosts must not rely on
|
|
2306
|
+
* injected policy until they ship a compatible runtime.
|
|
2307
|
+
*/
|
|
2308
|
+
managedSettings?: ManagedSettings;
|
|
2309
|
+
/**
|
|
2310
|
+
* When true, skips embedding-based retrieval for this session.
|
|
2311
|
+
* Use in multitenant deployments to prevent cross-session information leakage
|
|
2312
|
+
* through the shared embedding cache.
|
|
2313
|
+
*/
|
|
2314
|
+
skipEmbeddingRetrieval?: boolean;
|
|
2315
|
+
/**
|
|
2316
|
+
* Controls how the embedding cache is stored for this session.
|
|
2317
|
+
* - `"persistent"`: Embeddings are cached on disk and shared across sessions/restarts.
|
|
2318
|
+
* - `"in-memory"`: Embeddings are cached in memory only and discarded when the session ends.
|
|
2319
|
+
*/
|
|
2320
|
+
embeddingCacheStorage?: "persistent" | "in-memory";
|
|
2321
|
+
/**
|
|
2322
|
+
* Organization-level custom instructions to include in the system prompt.
|
|
2323
|
+
* Allows hosts to inject organization-specific guidance without relying on
|
|
2324
|
+
* filesystem-based instruction discovery.
|
|
2325
|
+
*/
|
|
2326
|
+
organizationCustomInstructions?: string;
|
|
2327
|
+
/**
|
|
2328
|
+
* When true, enables on-demand discovery of instruction files (AGENTS.md,
|
|
2329
|
+
* .github/copilot-instructions.md, etc.) after successful file views.
|
|
2330
|
+
*/
|
|
2331
|
+
enableOnDemandInstructionDiscovery?: boolean;
|
|
2332
|
+
/**
|
|
2333
|
+
* When true, enables loading of file-based hooks from `.github/hooks/`.
|
|
2334
|
+
* This is separate from the `hooks` callback parameter which gates SDK
|
|
2335
|
+
* hook event registration.
|
|
2336
|
+
*/
|
|
2337
|
+
enableFileHooks?: boolean;
|
|
2338
|
+
/**
|
|
2339
|
+
* When true, enables git operations on the host filesystem (branch detection,
|
|
2340
|
+
* file status, commit history). When false, no git context is surfaced in
|
|
2341
|
+
* the system prompt.
|
|
2342
|
+
*/
|
|
2343
|
+
enableHostGitOperations?: boolean;
|
|
2344
|
+
/**
|
|
2345
|
+
* When true, enables the cross-session store for search and retrieval
|
|
2346
|
+
* across sessions. When false, session content is not written to or
|
|
2347
|
+
* read from the shared session store.
|
|
2348
|
+
*/
|
|
2349
|
+
enableSessionStore?: boolean;
|
|
2350
|
+
/**
|
|
2351
|
+
* When true, enables skill loading (including builtin skills and discovered
|
|
2352
|
+
* skill directories). When false, no skills are loaded regardless of
|
|
2353
|
+
* `skillDirectories` or `enableConfigDiscovery` settings.
|
|
2354
|
+
*/
|
|
2355
|
+
enableSkills?: boolean;
|
|
2356
|
+
/**
|
|
2357
|
+
* Per-session remote behavior control:
|
|
2358
|
+
* - `"off"` — local only, no remote export (default)
|
|
2359
|
+
* - `"export"` — export session events to GitHub without enabling remote steering
|
|
2360
|
+
* - `"on"` — export to GitHub AND enable remote steering
|
|
2361
|
+
*/
|
|
2362
|
+
remoteSession?: RemoteSessionMode;
|
|
2363
|
+
/**
|
|
2364
|
+
* Optional event handler that is registered on the session before the
|
|
2365
|
+
* session.create RPC is issued. This guarantees that early events emitted
|
|
2366
|
+
* by the CLI during session creation (e.g. session.start) are delivered to
|
|
2367
|
+
* the handler.
|
|
2368
|
+
*
|
|
2369
|
+
* Equivalent to calling `session.on(handler)` immediately after creation,
|
|
2370
|
+
* but executes earlier in the lifecycle so no events are missed.
|
|
2371
|
+
*/
|
|
2372
|
+
onEvent?: SessionEventHandler;
|
|
2373
|
+
/**
|
|
2374
|
+
* Supplies a handler for session filesystem operations. This takes effect
|
|
2375
|
+
* only if {@link CopilotClientOptions.sessionFs} is configured.
|
|
2376
|
+
*/
|
|
2377
|
+
createSessionFsProvider?: (session: CopilotSession) => SessionFsProvider;
|
|
2378
|
+
}
|
|
2379
|
+
/**
|
|
2380
|
+
* Configuration for creating a new session via {@link CopilotClient.createSession}.
|
|
2381
|
+
*/
|
|
2382
|
+
export interface SessionConfig extends SessionConfigBase {
|
|
2383
|
+
/**
|
|
2384
|
+
* Optional custom session ID. If not provided, the server generates one.
|
|
2385
|
+
*/
|
|
2386
|
+
sessionId?: string;
|
|
2387
|
+
/**
|
|
2388
|
+
* Creates a remote session in the cloud instead of a local session.
|
|
2389
|
+
* The optional repository is associated with the cloud session.
|
|
2390
|
+
*/
|
|
2391
|
+
cloud?: CloudSessionOptions;
|
|
2392
|
+
}
|
|
2393
|
+
/**
|
|
2394
|
+
* Configuration for resuming an existing session via
|
|
2395
|
+
* {@link CopilotClient.resumeSession}.
|
|
2396
|
+
*/
|
|
2397
|
+
export interface ResumeSessionConfig extends SessionConfigBase {
|
|
2398
|
+
/**
|
|
2399
|
+
* When true, skips emitting the session.resume event.
|
|
2400
|
+
* Useful for reconnecting to a session without triggering resume-related side effects.
|
|
2401
|
+
* @default false
|
|
2402
|
+
*/
|
|
2403
|
+
suppressResumeEvent?: boolean;
|
|
2404
|
+
/**
|
|
2405
|
+
* When true, the runtime continues any tool calls or permission prompts that were
|
|
2406
|
+
* still pending when the session was last suspended. When false (the default), the
|
|
2407
|
+
* runtime treats pending work as interrupted on resume.
|
|
2408
|
+
*
|
|
2409
|
+
* For permission requests, the runtime re-emits `permission.requested` so the
|
|
2410
|
+
* registered `onPermissionRequest` handler can re-prompt; for external tool calls,
|
|
2411
|
+
* the consumer is expected to supply the result via the corresponding low-level
|
|
2412
|
+
* RPC method.
|
|
2413
|
+
* @default false
|
|
2414
|
+
*/
|
|
2415
|
+
continuePendingWork?: boolean;
|
|
2416
|
+
/**
|
|
2417
|
+
* Snapshot of canvases that were already open when the session was suspended.
|
|
2418
|
+
* When provided on resume, the runtime can rehydrate canvas state so consumers
|
|
2419
|
+
* do not need to re-open canvases that were active before the previous shutdown.
|
|
2420
|
+
*/
|
|
2421
|
+
openCanvases?: OpenCanvasInstance[];
|
|
2422
|
+
}
|
|
2423
|
+
/**
|
|
2424
|
+
* Arguments passed to a {@link BearerTokenProvider} callback when the runtime needs a
|
|
2425
|
+
* fresh bearer token for a BYOK provider.
|
|
2426
|
+
*
|
|
2427
|
+
* @experimental Part of the experimental managed-identity / bearer-token-provider
|
|
2428
|
+
* surface and may change or be removed in future SDK or CLI releases.
|
|
2429
|
+
*/
|
|
2430
|
+
export interface ProviderTokenArgs {
|
|
2431
|
+
/**
|
|
2432
|
+
* Name of the BYOK provider needing a token. For the singular, whole-session
|
|
2433
|
+
* {@link ProviderConfig} this is the implicit provider name (`"default"`); for
|
|
2434
|
+
* {@link NamedProviderConfig} entries it is {@link NamedProviderConfig.name}.
|
|
2435
|
+
*
|
|
2436
|
+
* The callback closes over its own token scope/audience; the runtime is
|
|
2437
|
+
* provider-agnostic and forwards only the provider name.
|
|
2438
|
+
*/
|
|
2439
|
+
readonly providerName: string;
|
|
2440
|
+
/**
|
|
2441
|
+
* Id of the session that triggered this token request. A client-level shared
|
|
2442
|
+
* callback registered for many sessions can use this to resolve the owning
|
|
2443
|
+
* session (e.g. via the client's session lookup) to scope token acquisition
|
|
2444
|
+
* or caching per session.
|
|
2445
|
+
*/
|
|
2446
|
+
readonly sessionId: string;
|
|
2447
|
+
}
|
|
2448
|
+
/**
|
|
2449
|
+
* Per-provider callback that resolves a bearer token on demand, returning the
|
|
2450
|
+
* raw token string (without the `Bearer ` prefix). The Copilot SDK itself takes
|
|
2451
|
+
* no Azure dependency: the consumer supplies this callback backed by their own
|
|
2452
|
+
* identity library (for example `@azure/identity`'s
|
|
2453
|
+
* `DefaultAzureCredential.getToken(scope)`), and the runtime calls it once before
|
|
2454
|
+
* each outbound model request. The runtime does no caching of its own, so the
|
|
2455
|
+
* callback (or the identity library it wraps) owns token caching and refresh.
|
|
2456
|
+
*
|
|
2457
|
+
* @experimental Part of the experimental managed-identity / bearer-token-provider
|
|
2458
|
+
* surface and may change or be removed in future SDK or CLI releases.
|
|
2459
|
+
*/
|
|
2460
|
+
export type BearerTokenProvider = (args: ProviderTokenArgs) => Promise<string>;
|
|
2461
|
+
/**
|
|
2462
|
+
* Configuration for a custom API provider.
|
|
2463
|
+
*/
|
|
2464
|
+
export interface ProviderConfig {
|
|
2465
|
+
/**
|
|
2466
|
+
* Provider type. Defaults to "openai" for generic OpenAI-compatible APIs.
|
|
2467
|
+
*/
|
|
2468
|
+
type?: "openai" | "azure" | "anthropic";
|
|
2469
|
+
/**
|
|
2470
|
+
* API format (openai/azure only). Defaults to "completions".
|
|
2471
|
+
*/
|
|
2472
|
+
wireApi?: "completions" | "responses";
|
|
2473
|
+
/**
|
|
2474
|
+
* Transport for OpenAI Responses requests. Defaults to "http".
|
|
2475
|
+
*
|
|
2476
|
+
* Set to "websockets" to deliver Responses API requests over a persistent
|
|
2477
|
+
* WebSocket connection instead of HTTP. Useful for long-running,
|
|
2478
|
+
* tool-call-heavy sessions that benefit from incremental
|
|
2479
|
+
* `previous_response_id` continuations. Applies to OpenAI-compatible
|
|
2480
|
+
* providers using `wireApi: "responses"`.
|
|
2481
|
+
*/
|
|
2482
|
+
transport?: "http" | "websockets";
|
|
2483
|
+
/**
|
|
2484
|
+
* API endpoint URL
|
|
2485
|
+
*/
|
|
2486
|
+
baseUrl: string;
|
|
2487
|
+
/**
|
|
2488
|
+
* API key. Optional for local providers like Ollama.
|
|
2489
|
+
*/
|
|
2490
|
+
apiKey?: string;
|
|
2491
|
+
/**
|
|
2492
|
+
* Bearer token for authentication. Sets the Authorization header directly.
|
|
2493
|
+
* Use this for services requiring bearer token auth instead of API key.
|
|
2494
|
+
* Takes precedence over apiKey when both are set.
|
|
2495
|
+
*/
|
|
2496
|
+
bearerToken?: string;
|
|
2497
|
+
/**
|
|
2498
|
+
* Per-request bearer-token provider for managed-identity / on-demand auth.
|
|
2499
|
+
* When set, the SDK keeps this function client-side (it is never serialized)
|
|
2500
|
+
* and the runtime calls back into this client to acquire a token before each
|
|
2501
|
+
* outbound request. The runtime does no caching of its own, so the callback
|
|
2502
|
+
* owns token caching and refresh. When set alongside {@link apiKey} /
|
|
2503
|
+
* {@link bearerToken}, this callback takes precedence: the runtime applies
|
|
2504
|
+
* the token it returns as the `Authorization: Bearer` header for each
|
|
2505
|
+
* request and does not send the static credential.
|
|
2506
|
+
*
|
|
2507
|
+
* @experimental
|
|
2508
|
+
*/
|
|
2509
|
+
bearerTokenProvider?: BearerTokenProvider;
|
|
2510
|
+
/**
|
|
2511
|
+
* Azure-specific options
|
|
2512
|
+
*/
|
|
2513
|
+
azure?: {
|
|
2514
|
+
/**
|
|
2515
|
+
* API version. When omitted, the runtime uses the GA versionless v1 route.
|
|
2516
|
+
*/
|
|
2517
|
+
apiVersion?: string;
|
|
2518
|
+
};
|
|
2519
|
+
/**
|
|
2520
|
+
* Custom HTTP headers to include in outbound provider requests.
|
|
2521
|
+
*/
|
|
2522
|
+
headers?: Record<string, string>;
|
|
2523
|
+
/**
|
|
2524
|
+
* Well-known model name used by the runtime to look up agent configuration
|
|
2525
|
+
* (tools, prompts, reasoning behavior) and default token limits. Also used
|
|
2526
|
+
* as the wire model when {@link wireModel} is not set.
|
|
2527
|
+
* Falls back to {@link SessionConfig.model}.
|
|
2528
|
+
*/
|
|
2529
|
+
modelId?: string;
|
|
2530
|
+
/**
|
|
2531
|
+
* Model name sent to the provider API for inference. Use this when the
|
|
2532
|
+
* provider's model name (e.g. an Azure deployment name or a custom
|
|
2533
|
+
* fine-tune name) differs from {@link modelId}.
|
|
2534
|
+
* Falls back to {@link modelId}, then {@link SessionConfig.model}.
|
|
2535
|
+
*/
|
|
2536
|
+
wireModel?: string;
|
|
2537
|
+
/**
|
|
2538
|
+
* Overrides the resolved model's default max prompt tokens. The runtime
|
|
2539
|
+
* triggers conversation compaction before sending a request when the
|
|
2540
|
+
* prompt (system message, history, tool definitions, user message) would
|
|
2541
|
+
* exceed this limit.
|
|
2542
|
+
*/
|
|
2543
|
+
maxPromptTokens?: number;
|
|
2544
|
+
/**
|
|
2545
|
+
* Overrides the resolved model's default max output tokens. When hit, the
|
|
2546
|
+
* model stops generating and returns a truncated response.
|
|
2547
|
+
*/
|
|
2548
|
+
maxOutputTokens?: number;
|
|
2549
|
+
}
|
|
2550
|
+
/**
|
|
2551
|
+
* A named BYOK provider connection (transport + credentials only), referenced by
|
|
2552
|
+
* {@link ProviderModelConfig} entries via {@link NamedProviderConfig.name}.
|
|
2553
|
+
*
|
|
2554
|
+
* Unlike the singular, whole-session {@link ProviderConfig} — which bypasses
|
|
2555
|
+
* Copilot API authentication — named providers are **additive** and coexist with
|
|
2556
|
+
* Copilot API auth, so CAPI and BYOK models can be mixed within one session and
|
|
2557
|
+
* across sub-agents. See {@link SessionConfigBase.providers}.
|
|
2558
|
+
*
|
|
2559
|
+
* @experimental This type is part of an experimental multi-provider BYOK surface
|
|
2560
|
+
* and may change or be removed in future SDK or CLI releases.
|
|
2561
|
+
*/
|
|
2562
|
+
export interface NamedProviderConfig {
|
|
2563
|
+
/**
|
|
2564
|
+
* Stable identifier referenced by {@link ProviderModelConfig.provider}.
|
|
2565
|
+
* Must not contain `/`.
|
|
2566
|
+
*/
|
|
2567
|
+
name: string;
|
|
2568
|
+
/**
|
|
2569
|
+
* Provider type. Defaults to "openai" for generic OpenAI-compatible APIs.
|
|
2570
|
+
*/
|
|
2571
|
+
type?: "openai" | "azure" | "anthropic";
|
|
2572
|
+
/**
|
|
2573
|
+
* Wire API format (openai/azure only). Defaults to "completions".
|
|
2574
|
+
*/
|
|
2575
|
+
wireApi?: "completions" | "responses";
|
|
2576
|
+
/**
|
|
2577
|
+
* API endpoint URL.
|
|
2578
|
+
*/
|
|
2579
|
+
baseUrl: string;
|
|
2580
|
+
/**
|
|
2581
|
+
* API key. Optional for local providers like Ollama.
|
|
2582
|
+
*/
|
|
2583
|
+
apiKey?: string;
|
|
2584
|
+
/**
|
|
2585
|
+
* Bearer token for authentication. Sets the Authorization header directly.
|
|
2586
|
+
* Takes precedence over {@link apiKey} when both are set.
|
|
2587
|
+
*/
|
|
2588
|
+
bearerToken?: string;
|
|
2589
|
+
/**
|
|
2590
|
+
* Per-request bearer-token provider for managed-identity / on-demand auth.
|
|
2591
|
+
* When set, the SDK keeps this function client-side (it is never serialized)
|
|
2592
|
+
* and the runtime calls back into this client to acquire a token before each
|
|
2593
|
+
* outbound request. The runtime does no caching of its own, so the callback
|
|
2594
|
+
* owns token caching and refresh. When set alongside {@link apiKey} /
|
|
2595
|
+
* {@link bearerToken}, this callback takes precedence: the runtime applies
|
|
2596
|
+
* the token it returns as the `Authorization: Bearer` header for each
|
|
2597
|
+
* request and does not send the static credential.
|
|
2598
|
+
*
|
|
2599
|
+
* @experimental
|
|
2600
|
+
*/
|
|
2601
|
+
bearerTokenProvider?: BearerTokenProvider;
|
|
2602
|
+
/**
|
|
2603
|
+
* Azure-specific options.
|
|
2604
|
+
*/
|
|
2605
|
+
azure?: {
|
|
2606
|
+
/**
|
|
2607
|
+
* API version. When set, uses the versioned deployment route. When
|
|
2608
|
+
* omitted, uses the GA versionless v1 route.
|
|
2609
|
+
*/
|
|
2610
|
+
apiVersion?: string;
|
|
2611
|
+
};
|
|
2612
|
+
/**
|
|
2613
|
+
* Custom HTTP headers to include in all outbound requests to the provider.
|
|
2614
|
+
*/
|
|
2615
|
+
headers?: Record<string, string>;
|
|
2616
|
+
}
|
|
2617
|
+
/**
|
|
2618
|
+
* A BYOK model definition that references a {@link NamedProviderConfig} by name
|
|
2619
|
+
* and is added to the session's selectable model list.
|
|
2620
|
+
*
|
|
2621
|
+
* Each model has three identities:
|
|
2622
|
+
* - {@link id}: the provider-local model id, unique within its provider. The
|
|
2623
|
+
* session-wide selection id (shown in the model list and passed to model
|
|
2624
|
+
* switching) is the provider-qualified `provider/id`.
|
|
2625
|
+
* - {@link modelId}: the well-known behavior base model used for
|
|
2626
|
+
* capability/config lookup. Defaults to {@link id}.
|
|
2627
|
+
* - {@link wireModel}: the model name actually sent to the provider API for
|
|
2628
|
+
* inference. Defaults to {@link id}.
|
|
2629
|
+
*
|
|
2630
|
+
* @experimental This type is part of an experimental multi-provider BYOK surface
|
|
2631
|
+
* and may change or be removed in future SDK or CLI releases.
|
|
2632
|
+
*/
|
|
2633
|
+
export interface ProviderModelConfig {
|
|
2634
|
+
/**
|
|
2635
|
+
* Provider-local model id, unique within its provider. The session-wide
|
|
2636
|
+
* selection id is the provider-qualified `provider/id`.
|
|
2637
|
+
*/
|
|
2638
|
+
id: string;
|
|
2639
|
+
/**
|
|
2640
|
+
* Name of the {@link NamedProviderConfig} that serves this model.
|
|
2641
|
+
*/
|
|
2642
|
+
provider: string;
|
|
2643
|
+
/**
|
|
2644
|
+
* The model name sent to the provider API for inference. Defaults to {@link id}.
|
|
2645
|
+
*/
|
|
2646
|
+
wireModel?: string;
|
|
2647
|
+
/**
|
|
2648
|
+
* Well-known base model id used for behavior/capability/config lookup.
|
|
2649
|
+
* Defaults to {@link id}.
|
|
2650
|
+
*/
|
|
2651
|
+
modelId?: string;
|
|
2652
|
+
/**
|
|
2653
|
+
* Display name for model pickers. Defaults to the provider-qualified
|
|
2654
|
+
* selection id (`provider/id`).
|
|
2655
|
+
*/
|
|
2656
|
+
name?: string;
|
|
2657
|
+
/**
|
|
2658
|
+
* Maximum prompt/input tokens for the model.
|
|
2659
|
+
*/
|
|
2660
|
+
maxPromptTokens?: number;
|
|
2661
|
+
/**
|
|
2662
|
+
* Maximum context window tokens for the model.
|
|
2663
|
+
*/
|
|
2664
|
+
maxContextWindowTokens?: number;
|
|
2665
|
+
/**
|
|
2666
|
+
* Maximum output tokens for the model.
|
|
2667
|
+
*/
|
|
2668
|
+
maxOutputTokens?: number;
|
|
2669
|
+
/**
|
|
2670
|
+
* Optional capability overrides (vision, tool_calls, reasoning, etc.) for
|
|
2671
|
+
* the synthesized model.
|
|
2672
|
+
*/
|
|
2673
|
+
capabilities?: ModelCapabilitiesOverride;
|
|
2674
|
+
}
|
|
2675
|
+
export interface MessageOptions {
|
|
2676
|
+
/**
|
|
2677
|
+
* The prompt/message to send
|
|
2678
|
+
*/
|
|
2679
|
+
prompt: string;
|
|
2680
|
+
/**
|
|
2681
|
+
* File, directory, selection, or blob attachments
|
|
2682
|
+
*/
|
|
2683
|
+
attachments?: Array<{
|
|
2684
|
+
type: "file";
|
|
2685
|
+
path: string;
|
|
2686
|
+
displayName?: string;
|
|
2687
|
+
} | {
|
|
2688
|
+
type: "directory";
|
|
2689
|
+
path: string;
|
|
2690
|
+
displayName?: string;
|
|
2691
|
+
} | {
|
|
2692
|
+
type: "selection";
|
|
2693
|
+
filePath: string;
|
|
2694
|
+
displayName: string;
|
|
2695
|
+
selection?: {
|
|
2696
|
+
start: {
|
|
2697
|
+
line: number;
|
|
2698
|
+
character: number;
|
|
2699
|
+
};
|
|
2700
|
+
end: {
|
|
2701
|
+
line: number;
|
|
2702
|
+
character: number;
|
|
2703
|
+
};
|
|
2704
|
+
};
|
|
2705
|
+
text?: string;
|
|
2706
|
+
} | {
|
|
2707
|
+
type: "blob";
|
|
2708
|
+
data: string;
|
|
2709
|
+
mimeType: string;
|
|
2710
|
+
displayName?: string;
|
|
2711
|
+
}>;
|
|
2712
|
+
/**
|
|
2713
|
+
* Message delivery mode
|
|
2714
|
+
* - "enqueue": Add to queue (default)
|
|
2715
|
+
* - "immediate": Send immediately
|
|
2716
|
+
*/
|
|
2717
|
+
mode?: "enqueue" | "immediate";
|
|
2718
|
+
/**
|
|
2719
|
+
* The UI mode the agent was in when this message was sent (for example "plan" or "autopilot").
|
|
2720
|
+
* Defaults to the session's current mode when unset.
|
|
2721
|
+
*/
|
|
2722
|
+
agentMode?: "interactive" | "plan" | "autopilot" | "shell";
|
|
2723
|
+
/**
|
|
2724
|
+
* Custom HTTP headers to include in outbound model requests for this turn.
|
|
2725
|
+
*/
|
|
2726
|
+
requestHeaders?: Record<string, string>;
|
|
2727
|
+
/**
|
|
2728
|
+
* If provided, this is shown in the timeline instead of `prompt`.
|
|
2729
|
+
*/
|
|
2730
|
+
displayPrompt?: string;
|
|
2731
|
+
}
|
|
2732
|
+
/**
|
|
2733
|
+
* All possible event type strings from SessionEvent
|
|
2734
|
+
*/
|
|
2735
|
+
export type SessionEventType = SessionEvent["type"];
|
|
2736
|
+
/**
|
|
2737
|
+
* Extract the specific event payload for a given event type
|
|
2738
|
+
*/
|
|
2739
|
+
export type SessionEventPayload<T extends SessionEventType> = Extract<SessionEvent, {
|
|
2740
|
+
type: T;
|
|
2741
|
+
}>;
|
|
2742
|
+
/**
|
|
2743
|
+
* Event handler for a specific event type
|
|
2744
|
+
*/
|
|
2745
|
+
export type TypedSessionEventHandler<T extends SessionEventType> = (event: SessionEventPayload<T>) => void;
|
|
2746
|
+
/**
|
|
2747
|
+
* Event handler callback type (for all events)
|
|
2748
|
+
*/
|
|
2749
|
+
export type SessionEventHandler = (event: SessionEvent) => void;
|
|
2750
|
+
/**
|
|
2751
|
+
* Working directory context for a session
|
|
2752
|
+
*/
|
|
2753
|
+
export interface SessionContext {
|
|
2754
|
+
/** Working directory where the session was created */
|
|
2755
|
+
workingDirectory: string;
|
|
2756
|
+
/** Git repository root (if in a git repo) */
|
|
2757
|
+
gitRoot?: string;
|
|
2758
|
+
/** GitHub repository in "owner/repo" format */
|
|
2759
|
+
repository?: string;
|
|
2760
|
+
/** Current git branch */
|
|
2761
|
+
branch?: string;
|
|
2762
|
+
}
|
|
2763
|
+
/**
|
|
2764
|
+
* Configuration for a custom session filesystem provider.
|
|
2765
|
+
*/
|
|
2766
|
+
export interface SessionFsConfig {
|
|
2767
|
+
/**
|
|
2768
|
+
* Initial working directory for sessions (user's project directory).
|
|
2769
|
+
*/
|
|
2770
|
+
initialCwd: string;
|
|
2771
|
+
/**
|
|
2772
|
+
* Path within each session's SessionFs where the runtime stores
|
|
2773
|
+
* session-scoped files (events, workspace, checkpoints, etc.).
|
|
2774
|
+
*/
|
|
2775
|
+
sessionStatePath: string;
|
|
2776
|
+
/**
|
|
2777
|
+
* Path conventions used by this filesystem provider.
|
|
2778
|
+
*/
|
|
2779
|
+
conventions: "windows" | "posix";
|
|
2780
|
+
/**
|
|
2781
|
+
* Optional capabilities declared by this provider.
|
|
2782
|
+
* The runtime uses these to determine which features are available.
|
|
2783
|
+
*/
|
|
2784
|
+
capabilities?: {
|
|
2785
|
+
/**
|
|
2786
|
+
* Whether this provider supports SQLite query/exists operations.
|
|
2787
|
+
* When false or omitted, the runtime will not offer SQL tools or
|
|
2788
|
+
* todo tracking for sessions using this provider.
|
|
2789
|
+
* @default false
|
|
2790
|
+
*/
|
|
2791
|
+
sqlite?: boolean;
|
|
2792
|
+
};
|
|
2793
|
+
}
|
|
2794
|
+
/**
|
|
2795
|
+
* Filter options for listing sessions
|
|
2796
|
+
*/
|
|
2797
|
+
export interface SessionListFilter {
|
|
2798
|
+
/** Filter by exact working directory match */
|
|
2799
|
+
workingDirectory?: string;
|
|
2800
|
+
/** Filter by git root */
|
|
2801
|
+
gitRoot?: string;
|
|
2802
|
+
/** Filter by repository (owner/repo format) */
|
|
2803
|
+
repository?: string;
|
|
2804
|
+
/** Filter by branch */
|
|
2805
|
+
branch?: string;
|
|
2806
|
+
}
|
|
2807
|
+
/**
|
|
2808
|
+
* Metadata about a session
|
|
2809
|
+
*/
|
|
2810
|
+
export interface SessionMetadata {
|
|
2811
|
+
sessionId: string;
|
|
2812
|
+
startTime: Date;
|
|
2813
|
+
modifiedTime: Date;
|
|
2814
|
+
summary?: string;
|
|
2815
|
+
isRemote: boolean;
|
|
2816
|
+
/** Working directory context (working directory, git info) from session creation */
|
|
2817
|
+
context?: SessionContext;
|
|
2818
|
+
}
|
|
2819
|
+
/**
|
|
2820
|
+
* Response from status.get
|
|
2821
|
+
*/
|
|
2822
|
+
export interface GetStatusResponse {
|
|
2823
|
+
/** Package version (e.g., "1.0.0") */
|
|
2824
|
+
version: string;
|
|
2825
|
+
/** Protocol version for SDK compatibility */
|
|
2826
|
+
protocolVersion: number;
|
|
2827
|
+
}
|
|
2828
|
+
/**
|
|
2829
|
+
* Response from auth.getStatus
|
|
2830
|
+
*/
|
|
2831
|
+
export interface GetAuthStatusResponse {
|
|
2832
|
+
/** Whether the user is authenticated */
|
|
2833
|
+
isAuthenticated: boolean;
|
|
2834
|
+
/** Authentication type */
|
|
2835
|
+
authType?: "user" | "env" | "gh-cli" | "hmac" | "api-key" | "token";
|
|
2836
|
+
/** GitHub host URL */
|
|
2837
|
+
host?: string;
|
|
2838
|
+
/** User login name */
|
|
2839
|
+
login?: string;
|
|
2840
|
+
/** Human-readable status message */
|
|
2841
|
+
statusMessage?: string;
|
|
2842
|
+
}
|
|
2843
|
+
/**
|
|
2844
|
+
* Model capabilities and limits
|
|
2845
|
+
*/
|
|
2846
|
+
export interface ModelCapabilities {
|
|
2847
|
+
supports: {
|
|
2848
|
+
vision: boolean;
|
|
2849
|
+
/** Whether this model supports reasoning effort configuration */
|
|
2850
|
+
reasoningEffort: boolean;
|
|
2851
|
+
};
|
|
2852
|
+
limits: {
|
|
2853
|
+
max_prompt_tokens?: number;
|
|
2854
|
+
max_context_window_tokens: number;
|
|
2855
|
+
vision?: {
|
|
2856
|
+
supported_media_types: string[];
|
|
2857
|
+
max_prompt_images: number;
|
|
2858
|
+
max_prompt_image_size: number;
|
|
2859
|
+
};
|
|
2860
|
+
};
|
|
2861
|
+
}
|
|
2862
|
+
/** Recursively makes all properties optional, preserving arrays as-is. */
|
|
2863
|
+
type DeepPartial<T> = T extends readonly (infer U)[] ? DeepPartial<U>[] : T extends object ? {
|
|
2864
|
+
[K in keyof T]?: DeepPartial<T[K]>;
|
|
2865
|
+
} : T;
|
|
2866
|
+
/** Deep-partial override for model capabilities — every property at any depth is optional. */
|
|
2867
|
+
export type ModelCapabilitiesOverride = DeepPartial<ModelCapabilities>;
|
|
2868
|
+
/**
|
|
2869
|
+
* Model policy state
|
|
2870
|
+
*/
|
|
2871
|
+
export interface ModelPolicy {
|
|
2872
|
+
state: "enabled" | "disabled" | "unconfigured";
|
|
2873
|
+
terms: string;
|
|
2874
|
+
}
|
|
2875
|
+
/**
|
|
2876
|
+
* Model billing information
|
|
2877
|
+
*/
|
|
2878
|
+
export interface ModelBilling {
|
|
2879
|
+
/** Billing cost multiplier relative to the base rate */
|
|
2880
|
+
multiplier?: number;
|
|
2881
|
+
/** Token-level pricing information for this model */
|
|
2882
|
+
tokenPrices?: ModelBillingTokenPrices;
|
|
2883
|
+
}
|
|
2884
|
+
/**
|
|
2885
|
+
* Information about an available model
|
|
2886
|
+
*/
|
|
2887
|
+
export interface ModelInfo {
|
|
2888
|
+
/** Model identifier (e.g., "claude-sonnet-4.5") */
|
|
2889
|
+
id: string;
|
|
2890
|
+
/** Display name */
|
|
2891
|
+
name: string;
|
|
2892
|
+
/** Model capabilities and limits */
|
|
2893
|
+
capabilities: ModelCapabilities;
|
|
2894
|
+
/** Policy state */
|
|
2895
|
+
policy?: ModelPolicy;
|
|
2896
|
+
/** Billing information */
|
|
2897
|
+
billing?: ModelBilling;
|
|
2898
|
+
/** Supported reasoning effort levels (only present if model supports reasoning effort) */
|
|
2899
|
+
supportedReasoningEfforts?: ReasoningEffort[];
|
|
2900
|
+
/** Default reasoning effort level (only present if model supports reasoning effort) */
|
|
2901
|
+
defaultReasoningEffort?: ReasoningEffort;
|
|
2902
|
+
}
|
|
2903
|
+
/**
|
|
2904
|
+
* Types of session lifecycle events.
|
|
2905
|
+
*/
|
|
2906
|
+
export type SessionLifecycleEventType = "session.created" | "session.deleted" | "session.updated" | "session.foreground" | "session.background";
|
|
2907
|
+
/**
|
|
2908
|
+
* Metadata payload for session lifecycle events. Not present on
|
|
2909
|
+
* `session.deleted` events.
|
|
2910
|
+
*/
|
|
2911
|
+
export interface SessionLifecycleEventMetadata {
|
|
2912
|
+
/** Time the session was created. */
|
|
2913
|
+
startTime: Date;
|
|
2914
|
+
/** Time the session was last modified. */
|
|
2915
|
+
modifiedTime: Date;
|
|
2916
|
+
/** Human-readable summary of the session, if available. */
|
|
2917
|
+
summary?: string;
|
|
2918
|
+
}
|
|
2919
|
+
/** Base shape shared by every lifecycle event variant. */
|
|
2920
|
+
interface SessionLifecycleEventBase {
|
|
2921
|
+
/** ID of the session this event relates to. */
|
|
2922
|
+
sessionId: string;
|
|
2923
|
+
/** Session metadata (not included for `session.deleted`). */
|
|
2924
|
+
metadata?: SessionLifecycleEventMetadata;
|
|
2925
|
+
}
|
|
2926
|
+
/** Emitted when a new session is created. */
|
|
2927
|
+
export interface SessionCreatedEvent extends SessionLifecycleEventBase {
|
|
2928
|
+
type: "session.created";
|
|
2929
|
+
metadata: SessionLifecycleEventMetadata;
|
|
2930
|
+
}
|
|
2931
|
+
/** Emitted when a session is deleted. The metadata field is omitted. */
|
|
2932
|
+
export interface SessionDeletedEvent extends SessionLifecycleEventBase {
|
|
2933
|
+
type: "session.deleted";
|
|
2934
|
+
metadata?: undefined;
|
|
2935
|
+
}
|
|
2936
|
+
/** Emitted when a session's metadata is updated. */
|
|
2937
|
+
export interface SessionUpdatedEvent extends SessionLifecycleEventBase {
|
|
2938
|
+
type: "session.updated";
|
|
2939
|
+
metadata: SessionLifecycleEventMetadata;
|
|
2940
|
+
}
|
|
2941
|
+
/** Emitted when a session is brought to the foreground (TUI+server mode). */
|
|
2942
|
+
export interface SessionForegroundEvent extends SessionLifecycleEventBase {
|
|
2943
|
+
type: "session.foreground";
|
|
2944
|
+
metadata: SessionLifecycleEventMetadata;
|
|
2945
|
+
}
|
|
2946
|
+
/** Emitted when a session is moved to the background (TUI+server mode). */
|
|
2947
|
+
export interface SessionBackgroundEvent extends SessionLifecycleEventBase {
|
|
2948
|
+
type: "session.background";
|
|
2949
|
+
metadata: SessionLifecycleEventMetadata;
|
|
2950
|
+
}
|
|
2951
|
+
/**
|
|
2952
|
+
* Discriminated union of all session lifecycle events emitted in TUI+server mode.
|
|
2953
|
+
* Switch on `type` to access the variant-specific metadata.
|
|
2954
|
+
*/
|
|
2955
|
+
export type SessionLifecycleEvent = SessionCreatedEvent | SessionDeletedEvent | SessionUpdatedEvent | SessionForegroundEvent | SessionBackgroundEvent;
|
|
2956
|
+
/**
|
|
2957
|
+
* Handler for session lifecycle events.
|
|
2958
|
+
*/
|
|
2959
|
+
export type SessionLifecycleHandler = (event: SessionLifecycleEvent) => void;
|
|
2960
|
+
/**
|
|
2961
|
+
* Typed handler for specific session lifecycle event types.
|
|
2962
|
+
*/
|
|
2963
|
+
export type TypedSessionLifecycleHandler<K extends SessionLifecycleEventType> = (event: Extract<SessionLifecycleEvent, {
|
|
2964
|
+
type: K;
|
|
2965
|
+
}>) => void;
|
|
2966
|
+
/**
|
|
2967
|
+
* Information about the foreground session in TUI+server mode
|
|
2968
|
+
*/
|
|
2969
|
+
export interface ForegroundSessionInfo {
|
|
2970
|
+
/** ID of the foreground session, or undefined if none */
|
|
2971
|
+
sessionId?: string;
|
|
2972
|
+
/** Workspace path of the foreground session */
|
|
2973
|
+
workspacePath?: string;
|
|
2974
|
+
}
|