@github/copilot-sdk 0.3.0 → 1.0.0-beta.10

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/dist/types.d.ts CHANGED
@@ -1,13 +1,22 @@
1
1
  /**
2
2
  * Type definitions for the Copilot SDK
3
3
  */
4
+ import type { Canvas } from "./canvas.js";
4
5
  import type { SessionFsProvider } from "./sessionFsProvider.js";
5
- import type { SessionEvent as GeneratedSessionEvent } from "./generated/session-events.js";
6
+ import type { ReasoningSummary, SessionEvent as GeneratedSessionEvent } from "./generated/session-events.js";
6
7
  import type { CopilotSession } from "./session.js";
8
+ import type { RemoteSessionMode } from "./generated/rpc.js";
9
+ import type { OpenCanvasInstance } from "./generated/rpc.js";
10
+ import type { ToolSet } from "./toolSet.js";
11
+ export type { RemoteSessionMode } from "./generated/rpc.js";
7
12
  export type SessionEvent = GeneratedSessionEvent;
13
+ export type { ReasoningSummary } from "./generated/session-events.js";
8
14
  export type { SessionFsProvider } from "./sessionFsProvider.js";
9
15
  export { createSessionFsAdapter } from "./sessionFsProvider.js";
10
16
  export type { SessionFsFileInfo } from "./sessionFsProvider.js";
17
+ export type { SessionFsSqliteQueryResult } from "./sessionFsProvider.js";
18
+ export type { SessionFsSqliteQueryType } from "./sessionFsProvider.js";
19
+ export type { SessionFsSqliteProvider } from "./sessionFsProvider.js";
11
20
  /**
12
21
  * Options for creating a CopilotClient
13
22
  */
@@ -43,72 +52,146 @@ export interface TelemetryConfig {
43
52
  /** Whether to capture message content (prompts, responses). Sets OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT. */
44
53
  captureContent?: boolean;
45
54
  }
46
- export interface CopilotClientOptions {
55
+ /**
56
+ * Configures how a {@link CopilotClient} connects to the Copilot runtime.
57
+ * Construct via the factory functions on {@link RuntimeConnection}.
58
+ */
59
+ export type RuntimeConnection = StdioRuntimeConnection | TcpRuntimeConnection | UriRuntimeConnection;
60
+ /**
61
+ * Spawns a runtime child process and communicates over its stdin/stdout.
62
+ * This is the default if no {@link CopilotClientOptions.connection} is set.
63
+ */
64
+ export interface StdioRuntimeConnection {
65
+ readonly kind: "stdio";
66
+ /** Path to the runtime executable. When omitted, the bundled runtime is used. */
67
+ readonly path?: string;
68
+ /** Extra command-line arguments to pass to the runtime process. */
69
+ readonly args?: readonly string[];
70
+ }
71
+ /**
72
+ * Spawns a runtime child process that listens on a TCP socket and connects to it.
73
+ */
74
+ export interface TcpRuntimeConnection {
75
+ readonly kind: "tcp";
47
76
  /**
48
- * Path to the CLI executable or JavaScript entry point.
49
- * If not specified, uses the bundled CLI from the @github/copilot package.
77
+ * TCP port to listen on. `0` (the default) auto-allocates a free port.
78
+ * If the chosen port is already in use, startup fails.
50
79
  */
51
- cliPath?: string;
80
+ readonly port?: number;
52
81
  /**
53
- * Extra arguments to pass to the CLI executable (inserted before SDK-managed args)
82
+ * Optional shared secret the SDK sends to the spawned runtime to authenticate
83
+ * the TCP connection. When omitted, a UUID is generated automatically so the
84
+ * loopback listener is safe by default.
54
85
  */
55
- cliArgs?: string[];
86
+ readonly connectionToken?: string;
87
+ /** Path to the runtime executable. When omitted, the bundled runtime is used. */
88
+ readonly path?: string;
89
+ /** Extra command-line arguments to pass to the runtime process. */
90
+ readonly args?: readonly string[];
91
+ }
92
+ /**
93
+ * Connects to an already-running runtime at the specified URL. The SDK does not
94
+ * spawn a process in this mode.
95
+ */
96
+ export interface UriRuntimeConnection {
97
+ readonly kind: "uri";
56
98
  /**
57
- * Working directory for the CLI process
58
- * If not set, inherits the current process's working directory
99
+ * URL of the runtime to connect to. Accepts `"port"`, `"host:port"`, or a
100
+ * full URL (`"http://host:port"`).
59
101
  */
60
- cwd?: string;
102
+ readonly url: string;
103
+ /** Optional shared secret to authenticate the connection. */
104
+ readonly connectionToken?: string;
105
+ }
106
+ /** Factory functions for constructing {@link RuntimeConnection} instances. */
107
+ export declare const RuntimeConnection: {
61
108
  /**
62
- * Port for the CLI server (TCP mode only)
63
- * @default 0 (random available port)
109
+ * Spawn a runtime child process and communicate over its stdin/stdout.
110
+ * This is the default if no {@link CopilotClientOptions.connection} is set.
64
111
  */
65
- port?: number;
112
+ readonly forStdio: (opts?: {
113
+ path?: string;
114
+ args?: readonly string[];
115
+ }) => StdioRuntimeConnection;
66
116
  /**
67
- * Use stdio transport instead of TCP
68
- * When true, communicates with CLI via stdin/stdout pipes
69
- * @default true
117
+ * Spawn a runtime child process that listens on a TCP socket and connect to it.
70
118
  */
71
- useStdio?: boolean;
119
+ readonly forTcp: (opts?: {
120
+ port?: number;
121
+ connectionToken?: string;
122
+ path?: string;
123
+ args?: readonly string[];
124
+ }) => TcpRuntimeConnection;
72
125
  /**
73
- * When true, indicates the SDK is running as a child process of the Copilot CLI server, and should
74
- * use its own stdio for communicating with the existing parent process. Can only be used in combination
75
- * with useStdio: true.
126
+ * Connect to an already-running runtime at the given URL. The SDK does not
127
+ * spawn a process in this mode.
76
128
  */
77
- isChildProcess?: boolean;
129
+ readonly forUri: (url: string, opts?: {
130
+ connectionToken?: string;
131
+ }) => UriRuntimeConnection;
132
+ };
133
+ /**
134
+ * Controls SDK defaults for ambient features.
135
+ *
136
+ * - `"copilot-cli"` (default): Defaults equivalent to Copilot CLI. Useful when
137
+ * building a coding agent that shares sessions with Copilot CLI. Do not use
138
+ * this mode for server-based multi-user applications — the default coding
139
+ * agent has tools and capabilities that operate across sessions and can
140
+ * access the host OS environment.
141
+ * - `"empty"`: Disables optional features by default. The app must explicitly
142
+ * opt into anything it needs. Required for any scenario where CLI-like
143
+ * ambient behavior is unsafe (e.g. multi-user servers).
144
+ */
145
+ export type CopilotClientMode = "empty" | "copilot-cli";
146
+ export interface CopilotClientOptions {
78
147
  /**
79
- * URL of an existing Copilot CLI server to connect to over TCP
80
- * When provided, the client will not spawn a CLI process
81
- * Format: "host:port" or "http://host:port" or just "port" (defaults to localhost)
82
- * Examples: "localhost:8080", "http://127.0.0.1:9000", "8080"
83
- * Mutually exclusive with cliPath, useStdio
148
+ * How to connect to the Copilot runtime. When omitted, defaults to
149
+ * {@link RuntimeConnection.forStdio} with the bundled runtime.
84
150
  */
85
- cliUrl?: string;
151
+ connection?: RuntimeConnection;
86
152
  /**
87
- * Log level for the CLI server
153
+ * Selects the SDK defaulting strategy. See {@link CopilotClientMode}.
154
+ *
155
+ * When set to `"empty"`, the SDK validates that the app has supplied the
156
+ * required configuration ({@link CopilotClientOptions.baseDirectory} or
157
+ * {@link CopilotClientOptions.sessionFs}, plus
158
+ * {@link SessionConfigBase.availableTools} on each session) and translates
159
+ * session creation requests into runtime options that flip tool filter
160
+ * precedence to deny-wins so exclusions are expressible.
161
+ *
162
+ * @default "copilot-cli"
88
163
  */
89
- logLevel?: "none" | "error" | "warning" | "info" | "debug" | "all";
164
+ mode?: CopilotClientMode;
90
165
  /**
91
- * Auto-start the CLI server on first use
92
- * @default true
166
+ * Working directory for the runtime process.
167
+ * If not set, inherits the current process's working directory.
93
168
  */
94
- autoStart?: boolean;
169
+ workingDirectory?: string;
95
170
  /**
96
- * @deprecated This option has no effect and will be removed in a future release.
171
+ * Base directory for Copilot data (session state, config, etc.).
172
+ * Sets the COPILOT_HOME environment variable on the spawned runtime.
173
+ * When not set, the runtime defaults to ~/.copilot.
174
+ * Ignored when connecting to an existing runtime via {@link RuntimeConnection.forUri}.
97
175
  */
98
- autoRestart?: boolean;
176
+ baseDirectory?: string;
99
177
  /**
100
- * Environment variables to pass to the CLI process. If not set, inherits process.env.
178
+ * Log level for the Copilot runtime. When omitted, the runtime uses its
179
+ * own default (currently `"info"`).
180
+ */
181
+ logLevel?: "none" | "error" | "warning" | "info" | "debug" | "all";
182
+ /**
183
+ * Environment variables to pass to the runtime process. If not set, inherits process.env.
101
184
  */
102
185
  env?: Record<string, string | undefined>;
103
186
  /**
104
187
  * GitHub token to use for authentication.
105
- * When provided, the token is passed to the CLI server via environment variable.
188
+ * When provided, the token is passed to the runtime via environment variable.
106
189
  * This takes priority over other authentication methods.
107
190
  */
108
191
  gitHubToken?: string;
109
192
  /**
110
193
  * Whether to use the logged-in user for authentication.
111
- * When true, the CLI server will attempt to use stored OAuth tokens or gh CLI auth.
194
+ * When true, the runtime will attempt to use stored OAuth tokens or gh CLI auth.
112
195
  * When false, only explicit tokens (gitHubToken or environment variables) are used.
113
196
  * @default true (but defaults to false when gitHubToken is provided)
114
197
  */
@@ -116,14 +199,14 @@ export interface CopilotClientOptions {
116
199
  /**
117
200
  * Custom handler for listing available models.
118
201
  * When provided, client.listModels() calls this handler instead of
119
- * querying the CLI server. Useful in BYOK mode to return models
202
+ * querying the runtime. Useful in BYOK mode to return models
120
203
  * available from your custom provider.
121
204
  */
122
205
  onListModels?: () => Promise<ModelInfo[]> | ModelInfo[];
123
206
  /**
124
- * OpenTelemetry configuration for the CLI process.
207
+ * OpenTelemetry configuration for the runtime process.
125
208
  * When provided, the corresponding OTel environment variables are set
126
- * on the spawned CLI server.
209
+ * on the spawned runtime.
127
210
  */
128
211
  telemetry?: TelemetryConfig;
129
212
  /**
@@ -162,11 +245,18 @@ export interface CopilotClientOptions {
162
245
  * Server-wide idle timeout for sessions in seconds.
163
246
  * Sessions without activity for this duration are automatically cleaned up.
164
247
  * Set to 0 or omit to disable (sessions live indefinitely).
165
- * This option is only used when the SDK spawns the CLI process; it is ignored
166
- * when connecting to an external server via {@link cliUrl}.
248
+ * Ignored when connecting to an existing runtime via {@link RuntimeConnection.forUri}.
167
249
  * @default undefined (disabled)
168
250
  */
169
251
  sessionIdleTimeoutSeconds?: number;
252
+ /**
253
+ * Enable remote session support (Mission Control integration).
254
+ * When true, sessions in a GitHub repository working directory are
255
+ * accessible from GitHub web and mobile.
256
+ * Ignored when connecting to an existing runtime via {@link RuntimeConnection.forUri}.
257
+ * @default false
258
+ */
259
+ enableRemoteSessions?: boolean;
170
260
  }
171
261
  /**
172
262
  * Configuration for creating a session
@@ -175,18 +265,33 @@ export type ToolResultType = "success" | "failure" | "rejected" | "denied" | "ti
175
265
  export type ToolBinaryResult = {
176
266
  data: string;
177
267
  mimeType: string;
178
- type: string;
268
+ type: "image" | "resource";
179
269
  description?: string;
180
270
  };
271
+ export type ToolTelemetry = Record<string, Record<string, unknown> | undefined>;
181
272
  export type ToolResultObject = {
182
273
  textResultForLlm: string;
183
274
  binaryResultsForLlm?: ToolBinaryResult[];
184
275
  resultType: ToolResultType;
185
276
  error?: string;
186
277
  sessionLog?: string;
187
- toolTelemetry?: Record<string, unknown>;
278
+ toolTelemetry?: ToolTelemetry;
188
279
  };
189
280
  export type ToolResult = string | ToolResultObject;
281
+ /**
282
+ * GitHub repository metadata to associate with a cloud session.
283
+ */
284
+ export interface CloudSessionRepository {
285
+ owner: string;
286
+ name: string;
287
+ branch?: string;
288
+ }
289
+ /**
290
+ * Options for creating a remote session in the cloud.
291
+ */
292
+ export interface CloudSessionOptions {
293
+ repository?: CloudSessionRepository;
294
+ }
190
295
  /**
191
296
  * Content block types within an MCP CallToolResult.
192
297
  */
@@ -245,12 +350,16 @@ export interface ZodSchema<T = unknown> {
245
350
  * - A Zod schema (provides type inference for handler)
246
351
  * - A raw JSON schema object
247
352
  * - Omitted (no parameters)
353
+ *
354
+ * If `handler` is omitted, the SDK exposes the declaration but does not
355
+ * automatically invoke the tool. Consumers can resolve tool calls by observing
356
+ * external tool request events and calling the pending-tool RPC.
248
357
  */
249
358
  export interface Tool<TArgs = unknown> {
250
359
  name: string;
251
360
  description?: string;
252
361
  parameters?: ZodSchema<TArgs> | Record<string, unknown>;
253
- handler: ToolHandler<TArgs>;
362
+ handler?: ToolHandler<TArgs>;
254
363
  /**
255
364
  * When true, explicitly indicates this tool is intended to override a built-in tool
256
365
  * of the same name. If not set and the name clashes with a built-in tool, the runtime
@@ -269,7 +378,7 @@ export interface Tool<TArgs = unknown> {
269
378
  export declare function defineTool<T = unknown>(name: string, config: {
270
379
  description?: string;
271
380
  parameters?: ZodSchema<T> | Record<string, unknown>;
272
- handler: ToolHandler<T>;
381
+ handler?: ToolHandler<T>;
273
382
  overridesBuiltInTool?: boolean;
274
383
  skipPermission?: boolean;
275
384
  }): Tool<T>;
@@ -310,6 +419,19 @@ export interface SessionCapabilities {
310
419
  ui?: {
311
420
  /** Whether the host supports interactive elicitation dialogs. */
312
421
  elicitation?: boolean;
422
+ /**
423
+ * Whether the runtime has accepted the session's MCP Apps (SEP-1865)
424
+ * opt-in. `true` when the consumer set `enableMcpApps: true` on
425
+ * create/resume **and** the runtime's `MCP_APPS` feature flag (or
426
+ * `COPILOT_MCP_APPS=true` env override) is on. Otherwise absent or
427
+ * `false`, indicating the runtime silently dropped the opt-in.
428
+ *
429
+ * @experimental This property is part of an experimental wire-protocol surface
430
+ * (SEP-1865) and may change or be removed in a future release.
431
+ */
432
+ mcpApps?: boolean;
433
+ /** Whether the host supports canvas rendering. */
434
+ canvases?: boolean;
313
435
  };
314
436
  }
315
437
  /**
@@ -434,7 +556,7 @@ export type ElicitationHandler = (context: ElicitationContext) => Promise<Elicit
434
556
  /**
435
557
  * Options for the `input()` convenience method.
436
558
  */
437
- export interface InputOptions {
559
+ export interface UiInputOptions {
438
560
  /** Title label for the input field. */
439
561
  title?: string;
440
562
  /** Descriptive text shown below the field. */
@@ -475,7 +597,7 @@ export interface SessionUiApi {
475
597
  * Returns the entered text, or `null` if the user declines/cancels.
476
598
  * @throws Error if the host does not support elicitation.
477
599
  */
478
- input(message: string, options?: InputOptions): Promise<string | null>;
600
+ input(message: string, options?: UiInputOptions): Promise<string | null>;
479
601
  }
480
602
  export interface ToolCallRequestPayload {
481
603
  sessionId: string;
@@ -487,12 +609,12 @@ export interface ToolCallResponsePayload {
487
609
  result: ToolResult;
488
610
  }
489
611
  /**
490
- * Known system prompt section identifiers for the "customize" mode.
612
+ * Known system message section identifiers for the "customize" mode.
491
613
  * Each section corresponds to a distinct part of the system prompt.
492
614
  */
493
- export type SystemPromptSection = "identity" | "tone" | "tool_efficiency" | "environment_context" | "code_change_rules" | "guidelines" | "safety" | "tool_instructions" | "custom_instructions" | "last_instructions";
615
+ export type SystemMessageSection = "identity" | "tone" | "tool_efficiency" | "environment_context" | "code_change_rules" | "guidelines" | "safety" | "tool_instructions" | "custom_instructions" | "runtime_instructions" | "last_instructions";
494
616
  /** Section metadata for documentation and tooling. */
495
- export declare const SYSTEM_PROMPT_SECTIONS: Record<SystemPromptSection, {
617
+ export declare const SYSTEM_MESSAGE_SECTIONS: Record<SystemMessageSection, {
496
618
  description: string;
497
619
  }>;
498
620
  /**
@@ -510,7 +632,7 @@ export type SectionTransformFn = (currentContent: string) => string | Promise<st
510
632
  */
511
633
  export type SectionOverrideAction = "replace" | "remove" | "append" | "prepend" | SectionTransformFn;
512
634
  /**
513
- * Override operation for a single system prompt section.
635
+ * Override operation for a single system message section.
514
636
  */
515
637
  export interface SectionOverride {
516
638
  /**
@@ -559,7 +681,7 @@ export interface SystemMessageCustomizeConfig {
559
681
  * Unknown section IDs gracefully fall back: content-bearing overrides are appended
560
682
  * to additional instructions, and "remove" on unknown sections is a silent no-op.
561
683
  */
562
- sections?: Partial<Record<SystemPromptSection, SectionOverride>>;
684
+ sections?: Partial<Record<SystemMessageSection, SectionOverride>>;
563
685
  /**
564
686
  * Additional content appended after all sections.
565
687
  * Equivalent to append mode's content field — provided for convenience.
@@ -574,13 +696,20 @@ export interface SystemMessageCustomizeConfig {
574
696
  */
575
697
  export type SystemMessageConfig = SystemMessageAppendConfig | SystemMessageReplaceConfig | SystemMessageCustomizeConfig;
576
698
  /**
577
- * Permission request types from the server
699
+ * Permission request types from the server. This is the generated
700
+ * discriminated union from the runtime schema — switch on `kind` to
701
+ * access the variant-specific fields (e.g. shell `commands`, write
702
+ * `fileName`/`diff`, mcp `toolName`/`args`).
578
703
  */
579
- export interface PermissionRequest {
580
- kind: "shell" | "write" | "mcp" | "read" | "url" | "custom-tool" | "memory" | "hook";
581
- toolCallId?: string;
582
- }
704
+ export type { PermissionRequest } from "./generated/session-events.js";
705
+ import type { PermissionRequest } from "./generated/session-events.js";
583
706
  import type { PermissionDecisionRequest } from "./generated/rpc.js";
707
+ /**
708
+ * Permission decision result returned from a {@link PermissionHandler}.
709
+ * The discriminated `kind` field selects the decision. Variant-specific
710
+ * fields (e.g. `feedback` on `{ kind: "reject" }`) come from the generated
711
+ * `PermissionDecisionRequest["result"]` union.
712
+ */
584
713
  export type PermissionRequestResult = PermissionDecisionRequest["result"] | {
585
714
  kind: "no-result";
586
715
  };
@@ -626,12 +755,65 @@ export interface UserInputResponse {
626
755
  export type UserInputHandler = (request: UserInputRequest, invocation: {
627
756
  sessionId: string;
628
757
  }) => Promise<UserInputResponse> | UserInputResponse;
758
+ /**
759
+ * Request to exit plan mode and continue with a selected action.
760
+ */
761
+ export interface ExitPlanModeRequest {
762
+ /** Summary of the plan or proposed next step. */
763
+ summary: string;
764
+ /** Full plan content, when available. */
765
+ planContent?: string;
766
+ /** Available actions the user can select. */
767
+ actions: string[];
768
+ /** The action recommended by the runtime. */
769
+ recommendedAction: string;
770
+ }
771
+ /**
772
+ * Response to an exit-plan-mode request.
773
+ */
774
+ export interface ExitPlanModeResult {
775
+ /** Whether the user approved exiting plan mode. */
776
+ approved: boolean;
777
+ /** Selected action, if the user chose one. */
778
+ selectedAction?: string;
779
+ /** Optional feedback provided by the user. */
780
+ feedback?: string;
781
+ }
782
+ /**
783
+ * Handler for exit-plan-mode requests from the agent.
784
+ */
785
+ export type ExitPlanModeHandler = (request: ExitPlanModeRequest, invocation: {
786
+ sessionId: string;
787
+ }) => Promise<ExitPlanModeResult> | ExitPlanModeResult;
788
+ /**
789
+ * Request to switch to auto mode after an eligible rate limit.
790
+ */
791
+ export interface AutoModeSwitchRequest {
792
+ /** The rate-limit error code that triggered the request. */
793
+ errorCode?: string;
794
+ /** Seconds until the rate limit resets, when known. */
795
+ retryAfterSeconds?: number;
796
+ }
797
+ /**
798
+ * Response to an auto-mode-switch request.
799
+ */
800
+ export type AutoModeSwitchResponse = "yes" | "yes_always" | "no";
801
+ /**
802
+ * Handler for auto-mode-switch requests from the agent.
803
+ */
804
+ export type AutoModeSwitchHandler = (request: AutoModeSwitchRequest, invocation: {
805
+ sessionId: string;
806
+ }) => Promise<AutoModeSwitchResponse> | AutoModeSwitchResponse;
629
807
  /**
630
808
  * Base interface for all hook inputs
631
809
  */
632
810
  export interface BaseHookInput {
633
- timestamp: number;
634
- cwd: string;
811
+ /** The runtime session ID of the session that triggered the hook.
812
+ * For sub-agent hooks this differs from `invocation.sessionId`. */
813
+ sessionId: string;
814
+ /** Time at which the hook event was emitted by the runtime. */
815
+ timestamp: Date;
816
+ workingDirectory: string;
635
817
  }
636
818
  /**
637
819
  * Input for pre-tool-use hook
@@ -656,6 +838,34 @@ export interface PreToolUseHookOutput {
656
838
  export type PreToolUseHandler = (input: PreToolUseHookInput, invocation: {
657
839
  sessionId: string;
658
840
  }) => Promise<PreToolUseHookOutput | void> | PreToolUseHookOutput | void;
841
+ /**
842
+ * Input for pre-MCP-tool-call hook
843
+ */
844
+ export interface PreMcpToolCallHookInput extends BaseHookInput {
845
+ toolCallId?: string;
846
+ serverName: string;
847
+ toolName: string;
848
+ arguments: unknown;
849
+ _meta?: Record<string, unknown>;
850
+ }
851
+ /**
852
+ * Output for pre-MCP-tool-call hook
853
+ */
854
+ export interface PreMcpToolCallHookOutput {
855
+ /**
856
+ * Hook-controlled metadata to use for the outgoing MCP request.
857
+ * - undefined/absent: preserve the current request `_meta`
858
+ * - object: use this object as request `_meta`
859
+ * - null: omit `_meta`
860
+ */
861
+ metaToUse?: Record<string, unknown> | null;
862
+ }
863
+ /**
864
+ * Handler for pre-MCP-tool-call hook
865
+ */
866
+ export type PreMcpToolCallHandler = (input: PreMcpToolCallHookInput, invocation: {
867
+ sessionId: string;
868
+ }) => Promise<PreMcpToolCallHookOutput | void> | PreMcpToolCallHookOutput | void;
659
869
  /**
660
870
  * Input for post-tool-use hook
661
871
  */
@@ -678,6 +888,47 @@ export interface PostToolUseHookOutput {
678
888
  export type PostToolUseHandler = (input: PostToolUseHookInput, invocation: {
679
889
  sessionId: string;
680
890
  }) => Promise<PostToolUseHookOutput | void> | PostToolUseHookOutput | void;
891
+ /**
892
+ * Input for post-tool-use-failure hook.
893
+ *
894
+ * Dispatched after a tool execution whose `resultType` is `"failure"`.
895
+ * The input differs from {@link PostToolUseHookInput}: the host CLI does not
896
+ * forward the full `ToolResultObject` to failure hooks — only `error`, the
897
+ * stringified failure message extracted from the tool's result, is provided.
898
+ */
899
+ export interface PostToolUseFailureHookInput extends BaseHookInput {
900
+ toolName: string;
901
+ toolArgs: unknown;
902
+ /**
903
+ * Failure message from the tool's result (the `error` field of the
904
+ * underlying `ToolResultObject`, falling back to its text/log fields).
905
+ */
906
+ error: string;
907
+ }
908
+ /**
909
+ * Output for post-tool-use-failure hook.
910
+ *
911
+ * Only `additionalContext` is consumed by the host CLI — it is appended as
912
+ * hidden guidance to the model alongside the failed tool result. Other fields
913
+ * such as `modifiedResult` or `suppressOutput` are not honored for failure
914
+ * hooks (see {@link PostToolUseHookOutput} for the success-only hook).
915
+ */
916
+ export interface PostToolUseFailureHookOutput {
917
+ additionalContext?: string;
918
+ }
919
+ /**
920
+ * Handler for post-tool-use-failure hook.
921
+ *
922
+ * Fires after a tool execution whose result was `"failure"`. `onPostToolUse`
923
+ * only fires for successful results, so register this handler to observe or
924
+ * react to failed tool outcomes.
925
+ *
926
+ * Note: `"rejected"`, `"denied"`, and `"timeout"` results do not currently
927
+ * trigger this hook either — only `"failure"` does.
928
+ */
929
+ export type PostToolUseFailureHandler = (input: PostToolUseFailureHookInput, invocation: {
930
+ sessionId: string;
931
+ }) => Promise<PostToolUseFailureHookOutput | void> | PostToolUseFailureHookOutput | void;
681
932
  /**
682
933
  * Input for user-prompt-submitted hook
683
934
  */
@@ -772,9 +1023,24 @@ export interface SessionHooks {
772
1023
  */
773
1024
  onPreToolUse?: PreToolUseHandler;
774
1025
  /**
775
- * Called after a tool is executed
1026
+ * Called before an MCP tool is called
1027
+ */
1028
+ onPreMcpToolCall?: PreMcpToolCallHandler;
1029
+ /**
1030
+ * Called after a tool is executed with a successful result.
1031
+ *
1032
+ * For failed tool executions, register {@link onPostToolUseFailure} instead;
1033
+ * this handler does not fire for non-success results.
776
1034
  */
777
1035
  onPostToolUse?: PostToolUseHandler;
1036
+ /**
1037
+ * Called after a tool execution whose result was `"failure"`.
1038
+ *
1039
+ * Register this handler alongside {@link onPostToolUse} to observe failed
1040
+ * tool calls — `onPostToolUse` only fires for successful results, so
1041
+ * without this hook failed tool calls are invisible to extensions.
1042
+ */
1043
+ onPostToolUseFailure?: PostToolUseFailureHandler;
778
1044
  /**
779
1045
  * Called when the user submits a prompt
780
1046
  */
@@ -797,9 +1063,11 @@ export interface SessionHooks {
797
1063
  */
798
1064
  interface MCPServerConfigBase {
799
1065
  /**
800
- * List of tools to include from this server. [] means none. "*" means all.
1066
+ * List of tools to include from this server.
1067
+ * `undefined` (the default) or `["*"]` means include all tools.
1068
+ * `[]` means include none.
801
1069
  */
802
- tools: string[];
1070
+ tools?: string[];
803
1071
  /**
804
1072
  * Indicates the server type: "stdio" for local/subprocess servers, "http"/"sse" for remote servers.
805
1073
  * If not specified, defaults to "stdio".
@@ -816,12 +1084,15 @@ interface MCPServerConfigBase {
816
1084
  export interface MCPStdioServerConfig extends MCPServerConfigBase {
817
1085
  type?: "local" | "stdio";
818
1086
  command: string;
819
- args: string[];
1087
+ args?: string[];
820
1088
  /**
821
1089
  * Environment variables to pass to the server.
822
1090
  */
823
1091
  env?: Record<string, string>;
824
- cwd?: string;
1092
+ /**
1093
+ * Working directory for the server process.
1094
+ */
1095
+ workingDirectory?: string;
825
1096
  }
826
1097
  /**
827
1098
  * Configuration for a remote MCP server (HTTP or SSE).
@@ -883,6 +1154,12 @@ export interface CustomAgentConfig {
883
1154
  * When omitted, no skills are injected (opt-in model).
884
1155
  */
885
1156
  skills?: string[];
1157
+ /**
1158
+ * Model identifier for this agent (e.g. "claude-haiku-4.5").
1159
+ * When set, the runtime will attempt to use this model for the agent,
1160
+ * falling back to the parent session model if unavailable.
1161
+ */
1162
+ model?: string;
886
1163
  }
887
1164
  /**
888
1165
  * Configuration for the default agent (the built-in agent that handles
@@ -923,15 +1200,47 @@ export interface InfiniteSessionConfig {
923
1200
  bufferExhaustionThreshold?: number;
924
1201
  }
925
1202
  /**
926
- * Valid reasoning effort levels for models that support it.
1203
+ * Configuration for handling large tool outputs.
1204
+ *
1205
+ * When a tool produces output exceeding the configured size, the output is
1206
+ * written to a temp file and a reference is returned to the model instead of
1207
+ * the full payload.
927
1208
  */
928
- export type ReasoningEffort = "low" | "medium" | "high" | "xhigh";
929
- export interface SessionConfig {
1209
+ export interface LargeToolOutputConfig {
930
1210
  /**
931
- * Optional custom session ID
932
- * If not provided, server will generate one
1211
+ * Whether large output handling is enabled.
1212
+ * @default true
933
1213
  */
934
- sessionId?: string;
1214
+ enabled?: boolean;
1215
+ /**
1216
+ * Maximum size in bytes before output is written to a temp file.
1217
+ * @default 51200
1218
+ */
1219
+ maxSizeBytes?: number;
1220
+ /**
1221
+ * Directory to write temp files to. Defaults to the OS temp directory.
1222
+ */
1223
+ outputDirectory?: string;
1224
+ }
1225
+ /**
1226
+ * Valid reasoning effort levels for models that support it.
1227
+ */
1228
+ export type ReasoningEffort = "low" | "medium" | "high" | "xhigh";
1229
+ /**
1230
+ * Stable extension identity for session participants that provide canvases.
1231
+ */
1232
+ export interface ExtensionInfo {
1233
+ /** Extension namespace/source, e.g. "github-app". */
1234
+ source: string;
1235
+ /** Stable provider name within the source namespace. */
1236
+ name: string;
1237
+ }
1238
+ /**
1239
+ * Shared configuration fields used by both {@link SessionConfig} (for
1240
+ * creating a new session) and {@link ResumeSessionConfig} (for resuming
1241
+ * an existing one).
1242
+ */
1243
+ export interface SessionConfigBase {
935
1244
  /**
936
1245
  * Client name to identify the application using the SDK.
937
1246
  * Included in the User-Agent header for API requests.
@@ -947,13 +1256,25 @@ export interface SessionConfig {
947
1256
  * Use client.listModels() to check supported values for each model.
948
1257
  */
949
1258
  reasoningEffort?: ReasoningEffort;
1259
+ /**
1260
+ * Reasoning summary mode for models that support configurable reasoning summaries.
1261
+ * Use "none" to suppress summary output regardless of whether reasoning is enabled.
1262
+ */
1263
+ reasoningSummary?: ReasoningSummary;
950
1264
  /** Per-property overrides for model capabilities, deep-merged over runtime defaults. */
951
1265
  modelCapabilities?: ModelCapabilitiesOverride;
1266
+ /**
1267
+ * Configuration for handling large tool outputs. When a tool produces
1268
+ * output exceeding the configured size, the output is written to a temp
1269
+ * file and a reference is returned to the model instead of the full
1270
+ * payload.
1271
+ */
1272
+ largeOutput?: LargeToolOutputConfig;
952
1273
  /**
953
1274
  * Override the default configuration directory location.
954
1275
  * When specified, the session will use this directory for storing config and state.
955
1276
  */
956
- configDir?: string;
1277
+ configDirectory?: string;
957
1278
  /**
958
1279
  * When true, automatically discovers MCP server configurations (e.g. `.mcp.json`,
959
1280
  * `.vscode/mcp.json`) and skill directories from the working directory and merges
@@ -967,9 +1288,38 @@ export interface SessionConfig {
967
1288
  */
968
1289
  enableConfigDiscovery?: boolean;
969
1290
  /**
970
- * Tools exposed to the CLI server
1291
+ * Tools exposed to the CLI server. Tools without a handler are declaration-only
1292
+ * and must be resolved by the consumer via pending external tool request RPCs.
971
1293
  */
972
1294
  tools?: Tool<any>[];
1295
+ /**
1296
+ * Canvases contributed by this session participant. The declaring
1297
+ * connection becomes the live provider for `canvas.open|focus|close|reload`
1298
+ * and `canvas.action.invoke` dispatches targeting each canvas's `id` for
1299
+ * the lifetime of the connection. Re-declaring the same id on resume
1300
+ * replaces the prior declaration.
1301
+ */
1302
+ canvases?: Canvas[];
1303
+ /**
1304
+ * Renderer-side opt-in: when true, the runtime surfaces canvas agent tools
1305
+ * (`list_canvas_capabilities`, `open_canvas`, `invoke_canvas_action`) to
1306
+ * the model for this connection. Default off so SDK callers that cannot
1307
+ * display canvases stay clean.
1308
+ */
1309
+ requestCanvasRenderer?: boolean;
1310
+ /**
1311
+ * Extension surface opt-in: when true, the runtime wires extension
1312
+ * management tools and per-extension tool dispatch onto the session for
1313
+ * this connection. Default off so callers that do not expose extensions
1314
+ * stay clean.
1315
+ */
1316
+ requestExtensions?: boolean;
1317
+ /**
1318
+ * Stable extension identity for canvas providers on this connection. When
1319
+ * set, the runtime uses `${source}:${name}` as the agent-facing extension
1320
+ * id instead of a reconnect-specific connection id.
1321
+ */
1322
+ extensionInfo?: ExtensionInfo;
973
1323
  /**
974
1324
  * Slash commands registered for this session.
975
1325
  * When the CLI has a TUI, each command appears as `/name` for the user to invoke.
@@ -983,24 +1333,78 @@ export interface SessionConfig {
983
1333
  systemMessage?: SystemMessageConfig;
984
1334
  /**
985
1335
  * List of tool names to allow. When specified, only these tools will be available.
986
- * Takes precedence over excludedTools.
1336
+ *
1337
+ * Supports source-qualified filter patterns (`builtin:*`, `builtin:<name>`,
1338
+ * `mcp:*`, `mcp:<name>`, `custom:*`, `custom:<name>`) as well as the bare
1339
+ * name form (exact match across any source). Build this list with
1340
+ * {@link ToolSet} for type safety and readable intent.
1341
+ *
1342
+ * Composes with {@link excludedTools}: a tool is enabled when it matches
1343
+ * `availableTools` (or `availableTools` is unset) AND it does not match
1344
+ * `excludedTools`. This lets you express "everything matching X except Y".
987
1345
  */
988
- availableTools?: string[];
1346
+ availableTools?: string[] | ToolSet;
989
1347
  /**
990
- * List of tool names to disable. All other tools remain available.
991
- * Ignored if availableTools is specified.
1348
+ * List of tool names to disable. Supports the same pattern syntax as
1349
+ * {@link availableTools}.
1350
+ *
1351
+ * Always takes precedence over {@link availableTools}: a tool listed here
1352
+ * is disabled even if it also matches `availableTools`.
992
1353
  */
993
- excludedTools?: string[];
1354
+ excludedTools?: string[] | ToolSet;
994
1355
  /**
995
1356
  * Custom provider configuration (BYOK - Bring Your Own Key).
996
1357
  * When specified, uses the provided API endpoint instead of the Copilot API.
997
1358
  */
998
1359
  provider?: ProviderConfig;
999
1360
  /**
1000
- * Handler for permission requests from the server.
1001
- * When provided, the server will call this handler to request permission for operations.
1361
+ * Enables or disables internal session telemetry for this session.
1362
+ * When `false`, disables session telemetry. When omitted (the default) or `true`,
1363
+ * telemetry is enabled for GitHub-authenticated sessions.
1364
+ * When a custom {@link provider} (BYOK) is configured, session telemetry is always
1365
+ * disabled regardless of this setting.
1366
+ * This is independent of the OpenTelemetry configuration in {@link CopilotClientOptions.telemetry}.
1367
+ */
1368
+ enableSessionTelemetry?: boolean;
1369
+ /**
1370
+ * When true, the runtime skips loading custom-instruction sources
1371
+ * (e.g. `.github/copilot-instructions.md`, `AGENTS.md`, `CLAUDE.md`).
1372
+ *
1373
+ * Defaults to `false` (custom instructions are loaded). Under
1374
+ * {@link CopilotClientOptions.mode} = `"empty"`, defaults to `true`; apps
1375
+ * can pass `false` here to opt back in.
1376
+ */
1377
+ skipCustomInstructions?: boolean;
1378
+ /**
1379
+ * When true, custom agents default to local-only execution and are not
1380
+ * dispatched to remote workers.
1381
+ *
1382
+ * Defaults to `false`. Under {@link CopilotClientOptions.mode} = `"empty"`,
1383
+ * defaults to `true`; apps can pass `false` here to opt back in.
1384
+ */
1385
+ customAgentsLocalOnly?: boolean;
1386
+ /**
1387
+ * When true, the runtime instructs the agent to include a `Co-authored-by`
1388
+ * trailer in commit messages it composes.
1389
+ *
1390
+ * Defaults to `true`. Under {@link CopilotClientOptions.mode} = `"empty"`,
1391
+ * defaults to `false`; apps can pass `true` here to opt back in.
1392
+ */
1393
+ coauthorEnabled?: boolean;
1394
+ /**
1395
+ * When true, the `manage_schedule` tool is exposed to the agent.
1396
+ *
1397
+ * Defaults to whatever the runtime exposes (typically gated to staff
1398
+ * users). Under {@link CopilotClientOptions.mode} = `"empty"`, defaults to
1399
+ * `false`; apps can pass `true` here to opt back in.
1400
+ */
1401
+ manageScheduleEnabled?: boolean;
1402
+ /**
1403
+ * Optional handler for permission requests from the server.
1404
+ * When omitted, permission requests are surfaced as events and left pending for
1405
+ * the consumer to resolve via the pending permission RPC.
1002
1406
  */
1003
- onPermissionRequest: PermissionHandler;
1407
+ onPermissionRequest?: PermissionHandler;
1004
1408
  /**
1005
1409
  * Handler for user input requests from the agent.
1006
1410
  * When provided, enables the ask_user tool allowing the agent to ask questions.
@@ -1012,6 +1416,43 @@ export interface SessionConfig {
1012
1416
  * Also enables the `elicitation` capability on the session.
1013
1417
  */
1014
1418
  onElicitationRequest?: ElicitationHandler;
1419
+ /**
1420
+ * Enable MCP Apps (SEP-1865) UI passthrough on this session.
1421
+ *
1422
+ * When `true` **and** the runtime has MCP Apps enabled (via the
1423
+ * `MCP_APPS` feature flag or `COPILOT_MCP_APPS=true` environment
1424
+ * override), the runtime adds the `mcp-apps` capability to the session,
1425
+ * which causes it to advertise the `extensions.io.modelcontextprotocol/ui`
1426
+ * extension to MCP servers (so they expose `_meta.ui.resourceUri` on
1427
+ * tools) and to expose the `session.rpc.mcp.apps.{listTools,callTool,
1428
+ * readResource,setHostContext,getHostContext,diagnose}` JSON-RPC methods.
1429
+ *
1430
+ * If the runtime gate is off, the opt-in is silently dropped server-side
1431
+ * (the runtime logs a warning); the session is created normally but the
1432
+ * MCP Apps surface is unavailable. Inspect the runtime's
1433
+ * `capabilities.ui.mcpApps` on the create/resume response to detect this.
1434
+ *
1435
+ * SDK consumers MUST set this to `true` only when they have an iframe
1436
+ * renderer that can display `ui://` MCP App bundles. Setting it without a
1437
+ * renderer will cause MCP servers to register UI-enabled tool variants
1438
+ * the consumer cannot display.
1439
+ *
1440
+ * @experimental This option is part of an experimental wire-protocol surface
1441
+ * (SEP-1865) and may change or be removed in a future release.
1442
+ *
1443
+ * @default false
1444
+ */
1445
+ enableMcpApps?: boolean;
1446
+ /**
1447
+ * Handler for exit-plan-mode requests from the agent.
1448
+ * When provided, enables `exitPlanMode.request` callbacks.
1449
+ */
1450
+ onExitPlanModeRequest?: ExitPlanModeHandler;
1451
+ /**
1452
+ * Handler for auto-mode-switch requests from the agent.
1453
+ * When provided, enables `autoModeSwitch.request` callbacks.
1454
+ */
1455
+ onAutoModeSwitchRequest?: AutoModeSwitchHandler;
1015
1456
  /**
1016
1457
  * Hook handlers for intercepting session lifecycle events.
1017
1458
  * When provided, enables hooks callback allowing custom logic at various points.
@@ -1022,6 +1463,13 @@ export interface SessionConfig {
1022
1463
  * Tool operations will be relative to this directory.
1023
1464
  */
1024
1465
  workingDirectory?: string;
1466
+ /**
1467
+ * Enable streaming of assistant message and reasoning chunks.
1468
+ * When true, ephemeral assistant.message_delta and assistant.reasoning_delta
1469
+ * events are sent as the response is generated. Clients should accumulate
1470
+ * deltaContent values to build the full response.
1471
+ * @default false
1472
+ */
1025
1473
  streaming?: boolean;
1026
1474
  /**
1027
1475
  * Include sub-agent streaming events in the event stream. When true, streaming
@@ -1033,6 +1481,14 @@ export interface SessionConfig {
1033
1481
  * @default true
1034
1482
  */
1035
1483
  includeSubAgentStreamingEvents?: boolean;
1484
+ /**
1485
+ * Controls how MCP OAuth tokens are stored for this session.
1486
+ * - `"persistent"` — tokens are stored in the OS keychain (shared across sessions)
1487
+ * - `"in-memory"` — tokens are stored in memory and discarded when the session ends
1488
+ *
1489
+ * @default "in-memory"
1490
+ */
1491
+ mcpOAuthTokenStorage?: "persistent" | "in-memory";
1036
1492
  /**
1037
1493
  * MCP server configurations for the session.
1038
1494
  * Keys are server names, values are server configurations.
@@ -1059,6 +1515,24 @@ export interface SessionConfig {
1059
1515
  * Directories to load skills from.
1060
1516
  */
1061
1517
  skillDirectories?: string[];
1518
+ /**
1519
+ * Local filesystem paths to Open Plugins-format directories
1520
+ * (https://open-plugins.com/) to load for this session.
1521
+ *
1522
+ * Relative paths resolve against `workingDirectory` (or the runtime cwd if
1523
+ * unset); absolute paths are recommended. Invalid entries are logged and
1524
+ * skipped.
1525
+ *
1526
+ * Treated as an explicit opt-in: plugin agents and rules load even when
1527
+ * {@link SessionConfigBase.enableConfigDiscovery} is false. Loaded assets
1528
+ * slot between project (cwd) sources and personal/home sources in the
1529
+ * session-wide precedence order.
1530
+ */
1531
+ pluginDirectories?: string[];
1532
+ /**
1533
+ * Additional directories to search for custom instruction files.
1534
+ */
1535
+ instructionDirectories?: string[];
1062
1536
  /**
1063
1537
  * List of skill names to disable.
1064
1538
  */
@@ -1080,6 +1554,60 @@ export interface SessionConfig {
1080
1554
  * the identity used for content exclusion, model routing, and quota checks.
1081
1555
  */
1082
1556
  gitHubToken?: string;
1557
+ /**
1558
+ * When true, skips embedding-based retrieval for this session.
1559
+ * Use in multitenant deployments to prevent cross-session information leakage
1560
+ * through the shared embedding cache.
1561
+ */
1562
+ skipEmbeddingRetrieval?: boolean;
1563
+ /**
1564
+ * Controls how the embedding cache is stored for this session.
1565
+ * - `"persistent"`: Embeddings are cached on disk and shared across sessions/restarts.
1566
+ * - `"in-memory"`: Embeddings are cached in memory only and discarded when the session ends.
1567
+ */
1568
+ embeddingCacheStorage?: "persistent" | "in-memory";
1569
+ /**
1570
+ * Organization-level custom instructions to include in the system prompt.
1571
+ * Allows hosts to inject organization-specific guidance without relying on
1572
+ * filesystem-based instruction discovery.
1573
+ */
1574
+ organizationCustomInstructions?: string;
1575
+ /**
1576
+ * When true, enables on-demand discovery of instruction files (AGENTS.md,
1577
+ * .github/copilot-instructions.md, etc.) after successful file views.
1578
+ */
1579
+ enableOnDemandInstructionDiscovery?: boolean;
1580
+ /**
1581
+ * When true, enables loading of file-based hooks from `.github/hooks/`.
1582
+ * This is separate from the `hooks` callback parameter which gates SDK
1583
+ * hook event registration.
1584
+ */
1585
+ enableFileHooks?: boolean;
1586
+ /**
1587
+ * When true, enables git operations on the host filesystem (branch detection,
1588
+ * file status, commit history). When false, no git context is surfaced in
1589
+ * the system prompt.
1590
+ */
1591
+ enableHostGitOperations?: boolean;
1592
+ /**
1593
+ * When true, enables the cross-session store for search and retrieval
1594
+ * across sessions. When false, session content is not written to or
1595
+ * read from the shared session store.
1596
+ */
1597
+ enableSessionStore?: boolean;
1598
+ /**
1599
+ * When true, enables skill loading (including builtin skills and discovered
1600
+ * skill directories). When false, no skills are loaded regardless of
1601
+ * `skillDirectories` or `enableConfigDiscovery` settings.
1602
+ */
1603
+ enableSkills?: boolean;
1604
+ /**
1605
+ * Per-session remote behavior control:
1606
+ * - `"off"` — local only, no remote export (default)
1607
+ * - `"export"` — export session events to GitHub without enabling remote steering
1608
+ * - `"on"` — export to GitHub AND enable remote steering
1609
+ */
1610
+ remoteSession?: RemoteSessionMode;
1083
1611
  /**
1084
1612
  * Optional event handler that is registered on the session before the
1085
1613
  * session.create RPC is issued. This guarantees that early events emitted
@@ -1094,19 +1622,52 @@ export interface SessionConfig {
1094
1622
  * Supplies a handler for session filesystem operations. This takes effect
1095
1623
  * only if {@link CopilotClientOptions.sessionFs} is configured.
1096
1624
  */
1097
- createSessionFsHandler?: (session: CopilotSession) => SessionFsProvider;
1625
+ createSessionFsProvider?: (session: CopilotSession) => SessionFsProvider;
1098
1626
  }
1099
1627
  /**
1100
- * Configuration for resuming a session
1628
+ * Configuration for creating a new session via {@link CopilotClient.createSession}.
1101
1629
  */
1102
- export type ResumeSessionConfig = Pick<SessionConfig, "clientName" | "model" | "tools" | "commands" | "systemMessage" | "availableTools" | "excludedTools" | "provider" | "modelCapabilities" | "streaming" | "includeSubAgentStreamingEvents" | "reasoningEffort" | "onPermissionRequest" | "onUserInputRequest" | "onElicitationRequest" | "hooks" | "workingDirectory" | "configDir" | "enableConfigDiscovery" | "mcpServers" | "customAgents" | "defaultAgent" | "agent" | "skillDirectories" | "disabledSkills" | "infiniteSessions" | "gitHubToken" | "onEvent" | "createSessionFsHandler"> & {
1630
+ export interface SessionConfig extends SessionConfigBase {
1631
+ /**
1632
+ * Optional custom session ID. If not provided, the server generates one.
1633
+ */
1634
+ sessionId?: string;
1635
+ /**
1636
+ * Creates a remote session in the cloud instead of a local session.
1637
+ * The optional repository is associated with the cloud session.
1638
+ */
1639
+ cloud?: CloudSessionOptions;
1640
+ }
1641
+ /**
1642
+ * Configuration for resuming an existing session via
1643
+ * {@link CopilotClient.resumeSession}.
1644
+ */
1645
+ export interface ResumeSessionConfig extends SessionConfigBase {
1103
1646
  /**
1104
1647
  * When true, skips emitting the session.resume event.
1105
1648
  * Useful for reconnecting to a session without triggering resume-related side effects.
1106
1649
  * @default false
1107
1650
  */
1108
- disableResume?: boolean;
1109
- };
1651
+ suppressResumeEvent?: boolean;
1652
+ /**
1653
+ * When true, the runtime continues any tool calls or permission prompts that were
1654
+ * still pending when the session was last suspended. When false (the default), the
1655
+ * runtime treats pending work as interrupted on resume.
1656
+ *
1657
+ * For permission requests, the runtime re-emits `permission.requested` so the
1658
+ * registered `onPermissionRequest` handler can re-prompt; for external tool calls,
1659
+ * the consumer is expected to supply the result via the corresponding low-level
1660
+ * RPC method.
1661
+ * @default false
1662
+ */
1663
+ continuePendingWork?: boolean;
1664
+ /**
1665
+ * Snapshot of canvases that were already open when the session was suspended.
1666
+ * When provided on resume, the runtime can rehydrate canvas state so consumers
1667
+ * do not need to re-open canvases that were active before the previous shutdown.
1668
+ */
1669
+ openCanvases?: OpenCanvasInstance[];
1670
+ }
1110
1671
  /**
1111
1672
  * Configuration for a custom API provider.
1112
1673
  */
@@ -1146,6 +1707,32 @@ export interface ProviderConfig {
1146
1707
  * Custom HTTP headers to include in outbound provider requests.
1147
1708
  */
1148
1709
  headers?: Record<string, string>;
1710
+ /**
1711
+ * Well-known model name used by the runtime to look up agent configuration
1712
+ * (tools, prompts, reasoning behavior) and default token limits. Also used
1713
+ * as the wire model when {@link wireModel} is not set.
1714
+ * Falls back to {@link SessionConfig.model}.
1715
+ */
1716
+ modelId?: string;
1717
+ /**
1718
+ * Model name sent to the provider API for inference. Use this when the
1719
+ * provider's model name (e.g. an Azure deployment name or a custom
1720
+ * fine-tune name) differs from {@link modelId}.
1721
+ * Falls back to {@link modelId}, then {@link SessionConfig.model}.
1722
+ */
1723
+ wireModel?: string;
1724
+ /**
1725
+ * Overrides the resolved model's default max prompt tokens. The runtime
1726
+ * triggers conversation compaction before sending a request when the
1727
+ * prompt (system message, history, tool definitions, user message) would
1728
+ * exceed this limit.
1729
+ */
1730
+ maxPromptTokens?: number;
1731
+ /**
1732
+ * Overrides the resolved model's default max output tokens. When hit, the
1733
+ * model stops generating and returns a truncated response.
1734
+ */
1735
+ maxOutputTokens?: number;
1149
1736
  }
1150
1737
  /**
1151
1738
  * Options for sending a message to a session
@@ -1193,10 +1780,19 @@ export interface MessageOptions {
1193
1780
  * - "immediate": Send immediately
1194
1781
  */
1195
1782
  mode?: "enqueue" | "immediate";
1783
+ /**
1784
+ * The UI mode the agent was in when this message was sent (for example "plan" or "autopilot").
1785
+ * Defaults to the session's current mode when unset.
1786
+ */
1787
+ agentMode?: "interactive" | "plan" | "autopilot" | "shell";
1196
1788
  /**
1197
1789
  * Custom HTTP headers to include in outbound model requests for this turn.
1198
1790
  */
1199
1791
  requestHeaders?: Record<string, string>;
1792
+ /**
1793
+ * If provided, this is shown in the timeline instead of `prompt`.
1794
+ */
1795
+ displayPrompt?: string;
1200
1796
  }
1201
1797
  /**
1202
1798
  * All possible event type strings from SessionEvent
@@ -1216,16 +1812,12 @@ export type TypedSessionEventHandler<T extends SessionEventType> = (event: Sessi
1216
1812
  * Event handler callback type (for all events)
1217
1813
  */
1218
1814
  export type SessionEventHandler = (event: SessionEvent) => void;
1219
- /**
1220
- * Connection state
1221
- */
1222
- export type ConnectionState = "disconnected" | "connecting" | "connected" | "error";
1223
1815
  /**
1224
1816
  * Working directory context for a session
1225
1817
  */
1226
1818
  export interface SessionContext {
1227
1819
  /** Working directory where the session was created */
1228
- cwd: string;
1820
+ workingDirectory: string;
1229
1821
  /** Git repository root (if in a git repo) */
1230
1822
  gitRoot?: string;
1231
1823
  /** GitHub repository in "owner/repo" format */
@@ -1250,13 +1842,26 @@ export interface SessionFsConfig {
1250
1842
  * Path conventions used by this filesystem provider.
1251
1843
  */
1252
1844
  conventions: "windows" | "posix";
1845
+ /**
1846
+ * Optional capabilities declared by this provider.
1847
+ * The runtime uses these to determine which features are available.
1848
+ */
1849
+ capabilities?: {
1850
+ /**
1851
+ * Whether this provider supports SQLite query/exists operations.
1852
+ * When false or omitted, the runtime will not offer SQL tools or
1853
+ * todo tracking for sessions using this provider.
1854
+ * @default false
1855
+ */
1856
+ sqlite?: boolean;
1857
+ };
1253
1858
  }
1254
1859
  /**
1255
1860
  * Filter options for listing sessions
1256
1861
  */
1257
1862
  export interface SessionListFilter {
1258
- /** Filter by exact cwd match */
1259
- cwd?: string;
1863
+ /** Filter by exact working directory match */
1864
+ workingDirectory?: string;
1260
1865
  /** Filter by git root */
1261
1866
  gitRoot?: string;
1262
1867
  /** Filter by repository (owner/repo format) */
@@ -1273,7 +1878,7 @@ export interface SessionMetadata {
1273
1878
  modifiedTime: Date;
1274
1879
  summary?: string;
1275
1880
  isRemote: boolean;
1276
- /** Working directory context (cwd, git info) from session creation */
1881
+ /** Working directory context (working directory, git info) from session creation */
1277
1882
  context?: SessionContext;
1278
1883
  }
1279
1884
  /**
@@ -1336,7 +1941,7 @@ export interface ModelPolicy {
1336
1941
  * Model billing information
1337
1942
  */
1338
1943
  export interface ModelBilling {
1339
- multiplier: number;
1944
+ multiplier?: number;
1340
1945
  }
1341
1946
  /**
1342
1947
  * Information about an available model
@@ -1358,35 +1963,68 @@ export interface ModelInfo {
1358
1963
  defaultReasoningEffort?: ReasoningEffort;
1359
1964
  }
1360
1965
  /**
1361
- * Types of session lifecycle events
1966
+ * Types of session lifecycle events.
1362
1967
  */
1363
1968
  export type SessionLifecycleEventType = "session.created" | "session.deleted" | "session.updated" | "session.foreground" | "session.background";
1364
1969
  /**
1365
- * Session lifecycle event notification
1366
- * Sent when sessions are created, deleted, updated, or change foreground/background state
1970
+ * Metadata payload for session lifecycle events. Not present on
1971
+ * `session.deleted` events.
1367
1972
  */
1368
- export interface SessionLifecycleEvent {
1369
- /** Type of lifecycle event */
1370
- type: SessionLifecycleEventType;
1371
- /** ID of the session this event relates to */
1973
+ export interface SessionLifecycleEventMetadata {
1974
+ /** Time the session was created. */
1975
+ startTime: Date;
1976
+ /** Time the session was last modified. */
1977
+ modifiedTime: Date;
1978
+ /** Human-readable summary of the session, if available. */
1979
+ summary?: string;
1980
+ }
1981
+ /** Base shape shared by every lifecycle event variant. */
1982
+ interface SessionLifecycleEventBase {
1983
+ /** ID of the session this event relates to. */
1372
1984
  sessionId: string;
1373
- /** Session metadata (not included for deleted sessions) */
1374
- metadata?: {
1375
- startTime: string;
1376
- modifiedTime: string;
1377
- summary?: string;
1378
- };
1985
+ /** Session metadata (not included for `session.deleted`). */
1986
+ metadata?: SessionLifecycleEventMetadata;
1379
1987
  }
1988
+ /** Emitted when a new session is created. */
1989
+ export interface SessionCreatedEvent extends SessionLifecycleEventBase {
1990
+ type: "session.created";
1991
+ metadata: SessionLifecycleEventMetadata;
1992
+ }
1993
+ /** Emitted when a session is deleted. The metadata field is omitted. */
1994
+ export interface SessionDeletedEvent extends SessionLifecycleEventBase {
1995
+ type: "session.deleted";
1996
+ metadata?: undefined;
1997
+ }
1998
+ /** Emitted when a session's metadata is updated. */
1999
+ export interface SessionUpdatedEvent extends SessionLifecycleEventBase {
2000
+ type: "session.updated";
2001
+ metadata: SessionLifecycleEventMetadata;
2002
+ }
2003
+ /** Emitted when a session is brought to the foreground (TUI+server mode). */
2004
+ export interface SessionForegroundEvent extends SessionLifecycleEventBase {
2005
+ type: "session.foreground";
2006
+ metadata: SessionLifecycleEventMetadata;
2007
+ }
2008
+ /** Emitted when a session is moved to the background (TUI+server mode). */
2009
+ export interface SessionBackgroundEvent extends SessionLifecycleEventBase {
2010
+ type: "session.background";
2011
+ metadata: SessionLifecycleEventMetadata;
2012
+ }
2013
+ /**
2014
+ * Discriminated union of all session lifecycle events emitted in TUI+server mode.
2015
+ * Switch on `type` to access the variant-specific metadata.
2016
+ */
2017
+ export type SessionLifecycleEvent = SessionCreatedEvent | SessionDeletedEvent | SessionUpdatedEvent | SessionForegroundEvent | SessionBackgroundEvent;
1380
2018
  /**
1381
- * Handler for session lifecycle events
2019
+ * Handler for session lifecycle events.
1382
2020
  */
1383
2021
  export type SessionLifecycleHandler = (event: SessionLifecycleEvent) => void;
1384
2022
  /**
1385
- * Typed handler for specific session lifecycle event types
2023
+ * Typed handler for specific session lifecycle event types.
1386
2024
  */
1387
- export type TypedSessionLifecycleHandler<K extends SessionLifecycleEventType> = (event: SessionLifecycleEvent & {
2025
+ export type TypedSessionLifecycleHandler<K extends SessionLifecycleEventType> = (event: Extract<SessionLifecycleEvent, {
1388
2026
  type: K;
1389
- }) => void;
2027
+ }>) => void;
1390
2028
  /**
1391
2029
  * Information about the foreground session in TUI+server mode
1392
2030
  */