@github/copilot-sdk 1.0.0-beta.1 → 1.0.0-beta.11

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,80 +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
- * Base directory for Copilot data (session state, config, etc.).
63
- * Sets the COPILOT_HOME environment variable on the spawned CLI process.
64
- * When not set, the CLI defaults to ~/.copilot.
65
- * This option is only used when the SDK spawns the CLI process; it is ignored
66
- * when connecting to an external server via {@link cliUrl}.
109
+ * Spawn a runtime child process and communicate over its stdin/stdout.
110
+ * This is the default if no {@link CopilotClientOptions.connection} is set.
67
111
  */
68
- copilotHome?: string;
112
+ readonly forStdio: (opts?: {
113
+ path?: string;
114
+ args?: readonly string[];
115
+ }) => StdioRuntimeConnection;
69
116
  /**
70
- * Port for the CLI server (TCP mode only)
71
- * @default 0 (random available port)
117
+ * Spawn a runtime child process that listens on a TCP socket and connect to it.
72
118
  */
73
- port?: number;
119
+ readonly forTcp: (opts?: {
120
+ port?: number;
121
+ connectionToken?: string;
122
+ path?: string;
123
+ args?: readonly string[];
124
+ }) => TcpRuntimeConnection;
74
125
  /**
75
- * Use stdio transport instead of TCP
76
- * When true, communicates with CLI via stdin/stdout pipes
77
- * @default true
126
+ * Connect to an already-running runtime at the given URL. The SDK does not
127
+ * spawn a process in this mode.
78
128
  */
79
- useStdio?: 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 {
80
147
  /**
81
- * When true, indicates the SDK is running as a child process of the Copilot CLI server, and should
82
- * use its own stdio for communicating with the existing parent process. Can only be used in combination
83
- * with useStdio: true.
148
+ * How to connect to the Copilot runtime. When omitted, defaults to
149
+ * {@link RuntimeConnection.forStdio} with the bundled runtime.
84
150
  */
85
- isChildProcess?: boolean;
151
+ connection?: RuntimeConnection;
86
152
  /**
87
- * URL of an existing Copilot CLI server to connect to over TCP
88
- * When provided, the client will not spawn a CLI process
89
- * Format: "host:port" or "http://host:port" or just "port" (defaults to localhost)
90
- * Examples: "localhost:8080", "http://127.0.0.1:9000", "8080"
91
- * Mutually exclusive with cliPath, useStdio
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"
92
163
  */
93
- cliUrl?: string;
164
+ mode?: CopilotClientMode;
94
165
  /**
95
- * Log level for the CLI server
166
+ * Working directory for the runtime process.
167
+ * If not set, inherits the current process's working directory.
96
168
  */
97
- logLevel?: "none" | "error" | "warning" | "info" | "debug" | "all";
169
+ workingDirectory?: string;
98
170
  /**
99
- * Auto-start the CLI server on first use
100
- * @default true
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}.
101
175
  */
102
- autoStart?: boolean;
176
+ baseDirectory?: string;
103
177
  /**
104
- * @deprecated This option has no effect and will be removed in a future release.
178
+ * Log level for the Copilot runtime. When omitted, the runtime uses its
179
+ * own default (currently `"info"`).
105
180
  */
106
- autoRestart?: boolean;
181
+ logLevel?: "none" | "error" | "warning" | "info" | "debug" | "all";
107
182
  /**
108
- * Environment variables to pass to the CLI process. If not set, inherits process.env.
183
+ * Environment variables to pass to the runtime process. If not set, inherits process.env.
109
184
  */
110
185
  env?: Record<string, string | undefined>;
111
186
  /**
112
187
  * GitHub token to use for authentication.
113
- * 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.
114
189
  * This takes priority over other authentication methods.
115
190
  */
116
191
  gitHubToken?: string;
117
192
  /**
118
193
  * Whether to use the logged-in user for authentication.
119
- * 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.
120
195
  * When false, only explicit tokens (gitHubToken or environment variables) are used.
121
196
  * @default true (but defaults to false when gitHubToken is provided)
122
197
  */
@@ -124,14 +199,14 @@ export interface CopilotClientOptions {
124
199
  /**
125
200
  * Custom handler for listing available models.
126
201
  * When provided, client.listModels() calls this handler instead of
127
- * querying the CLI server. Useful in BYOK mode to return models
202
+ * querying the runtime. Useful in BYOK mode to return models
128
203
  * available from your custom provider.
129
204
  */
130
205
  onListModels?: () => Promise<ModelInfo[]> | ModelInfo[];
131
206
  /**
132
- * OpenTelemetry configuration for the CLI process.
207
+ * OpenTelemetry configuration for the runtime process.
133
208
  * When provided, the corresponding OTel environment variables are set
134
- * on the spawned CLI server.
209
+ * on the spawned runtime.
135
210
  */
136
211
  telemetry?: TelemetryConfig;
137
212
  /**
@@ -170,18 +245,18 @@ export interface CopilotClientOptions {
170
245
  * Server-wide idle timeout for sessions in seconds.
171
246
  * Sessions without activity for this duration are automatically cleaned up.
172
247
  * Set to 0 or omit to disable (sessions live indefinitely).
173
- * This option is only used when the SDK spawns the CLI process; it is ignored
174
- * when connecting to an external server via {@link cliUrl}.
248
+ * Ignored when connecting to an existing runtime via {@link RuntimeConnection.forUri}.
175
249
  * @default undefined (disabled)
176
250
  */
177
251
  sessionIdleTimeoutSeconds?: number;
178
252
  /**
179
- * Connection token for the headless CLI server (TCP only). When the SDK
180
- * spawns its own CLI in TCP mode and this is omitted, a UUID is generated
181
- * automatically so the loopback listener is safe by default. Rejected with
182
- * `useStdio: true` (stdio is pre-authenticated by transport).
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
183
258
  */
184
- tcpConnectionToken?: string;
259
+ enableRemoteSessions?: boolean;
185
260
  }
186
261
  /**
187
262
  * Configuration for creating a session
@@ -190,18 +265,33 @@ export type ToolResultType = "success" | "failure" | "rejected" | "denied" | "ti
190
265
  export type ToolBinaryResult = {
191
266
  data: string;
192
267
  mimeType: string;
193
- type: string;
268
+ type: "image" | "resource";
194
269
  description?: string;
195
270
  };
271
+ export type ToolTelemetry = Record<string, Record<string, unknown> | undefined>;
196
272
  export type ToolResultObject = {
197
273
  textResultForLlm: string;
198
274
  binaryResultsForLlm?: ToolBinaryResult[];
199
275
  resultType: ToolResultType;
200
276
  error?: string;
201
277
  sessionLog?: string;
202
- toolTelemetry?: Record<string, unknown>;
278
+ toolTelemetry?: ToolTelemetry;
203
279
  };
204
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
+ }
205
295
  /**
206
296
  * Content block types within an MCP CallToolResult.
207
297
  */
@@ -260,12 +350,16 @@ export interface ZodSchema<T = unknown> {
260
350
  * - A Zod schema (provides type inference for handler)
261
351
  * - A raw JSON schema object
262
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.
263
357
  */
264
358
  export interface Tool<TArgs = unknown> {
265
359
  name: string;
266
360
  description?: string;
267
361
  parameters?: ZodSchema<TArgs> | Record<string, unknown>;
268
- handler: ToolHandler<TArgs>;
362
+ handler?: ToolHandler<TArgs>;
269
363
  /**
270
364
  * When true, explicitly indicates this tool is intended to override a built-in tool
271
365
  * of the same name. If not set and the name clashes with a built-in tool, the runtime
@@ -284,7 +378,7 @@ export interface Tool<TArgs = unknown> {
284
378
  export declare function defineTool<T = unknown>(name: string, config: {
285
379
  description?: string;
286
380
  parameters?: ZodSchema<T> | Record<string, unknown>;
287
- handler: ToolHandler<T>;
381
+ handler?: ToolHandler<T>;
288
382
  overridesBuiltInTool?: boolean;
289
383
  skipPermission?: boolean;
290
384
  }): Tool<T>;
@@ -325,6 +419,19 @@ export interface SessionCapabilities {
325
419
  ui?: {
326
420
  /** Whether the host supports interactive elicitation dialogs. */
327
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;
328
435
  };
329
436
  }
330
437
  /**
@@ -449,7 +556,7 @@ export type ElicitationHandler = (context: ElicitationContext) => Promise<Elicit
449
556
  /**
450
557
  * Options for the `input()` convenience method.
451
558
  */
452
- export interface InputOptions {
559
+ export interface UiInputOptions {
453
560
  /** Title label for the input field. */
454
561
  title?: string;
455
562
  /** Descriptive text shown below the field. */
@@ -490,7 +597,7 @@ export interface SessionUiApi {
490
597
  * Returns the entered text, or `null` if the user declines/cancels.
491
598
  * @throws Error if the host does not support elicitation.
492
599
  */
493
- input(message: string, options?: InputOptions): Promise<string | null>;
600
+ input(message: string, options?: UiInputOptions): Promise<string | null>;
494
601
  }
495
602
  export interface ToolCallRequestPayload {
496
603
  sessionId: string;
@@ -502,12 +609,12 @@ export interface ToolCallResponsePayload {
502
609
  result: ToolResult;
503
610
  }
504
611
  /**
505
- * Known system prompt section identifiers for the "customize" mode.
612
+ * Known system message section identifiers for the "customize" mode.
506
613
  * Each section corresponds to a distinct part of the system prompt.
507
614
  */
508
- 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";
509
616
  /** Section metadata for documentation and tooling. */
510
- export declare const SYSTEM_PROMPT_SECTIONS: Record<SystemPromptSection, {
617
+ export declare const SYSTEM_MESSAGE_SECTIONS: Record<SystemMessageSection, {
511
618
  description: string;
512
619
  }>;
513
620
  /**
@@ -525,7 +632,7 @@ export type SectionTransformFn = (currentContent: string) => string | Promise<st
525
632
  */
526
633
  export type SectionOverrideAction = "replace" | "remove" | "append" | "prepend" | SectionTransformFn;
527
634
  /**
528
- * Override operation for a single system prompt section.
635
+ * Override operation for a single system message section.
529
636
  */
530
637
  export interface SectionOverride {
531
638
  /**
@@ -574,7 +681,7 @@ export interface SystemMessageCustomizeConfig {
574
681
  * Unknown section IDs gracefully fall back: content-bearing overrides are appended
575
682
  * to additional instructions, and "remove" on unknown sections is a silent no-op.
576
683
  */
577
- sections?: Partial<Record<SystemPromptSection, SectionOverride>>;
684
+ sections?: Partial<Record<SystemMessageSection, SectionOverride>>;
578
685
  /**
579
686
  * Additional content appended after all sections.
580
687
  * Equivalent to append mode's content field — provided for convenience.
@@ -589,13 +696,20 @@ export interface SystemMessageCustomizeConfig {
589
696
  */
590
697
  export type SystemMessageConfig = SystemMessageAppendConfig | SystemMessageReplaceConfig | SystemMessageCustomizeConfig;
591
698
  /**
592
- * 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`).
593
703
  */
594
- export interface PermissionRequest {
595
- kind: "shell" | "write" | "mcp" | "read" | "url" | "custom-tool" | "memory" | "hook";
596
- toolCallId?: string;
597
- }
704
+ export type { PermissionRequest } from "./generated/session-events.js";
705
+ import type { PermissionRequest } from "./generated/session-events.js";
598
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
+ */
599
713
  export type PermissionRequestResult = PermissionDecisionRequest["result"] | {
600
714
  kind: "no-result";
601
715
  };
@@ -641,12 +755,65 @@ export interface UserInputResponse {
641
755
  export type UserInputHandler = (request: UserInputRequest, invocation: {
642
756
  sessionId: string;
643
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;
644
807
  /**
645
808
  * Base interface for all hook inputs
646
809
  */
647
810
  export interface BaseHookInput {
648
- timestamp: number;
649
- 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;
650
817
  }
651
818
  /**
652
819
  * Input for pre-tool-use hook
@@ -671,6 +838,34 @@ export interface PreToolUseHookOutput {
671
838
  export type PreToolUseHandler = (input: PreToolUseHookInput, invocation: {
672
839
  sessionId: string;
673
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;
674
869
  /**
675
870
  * Input for post-tool-use hook
676
871
  */
@@ -693,6 +888,47 @@ export interface PostToolUseHookOutput {
693
888
  export type PostToolUseHandler = (input: PostToolUseHookInput, invocation: {
694
889
  sessionId: string;
695
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;
696
932
  /**
697
933
  * Input for user-prompt-submitted hook
698
934
  */
@@ -787,9 +1023,24 @@ export interface SessionHooks {
787
1023
  */
788
1024
  onPreToolUse?: PreToolUseHandler;
789
1025
  /**
790
- * 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.
791
1034
  */
792
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;
793
1044
  /**
794
1045
  * Called when the user submits a prompt
795
1046
  */
@@ -812,9 +1063,11 @@ export interface SessionHooks {
812
1063
  */
813
1064
  interface MCPServerConfigBase {
814
1065
  /**
815
- * 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.
816
1069
  */
817
- tools: string[];
1070
+ tools?: string[];
818
1071
  /**
819
1072
  * Indicates the server type: "stdio" for local/subprocess servers, "http"/"sse" for remote servers.
820
1073
  * If not specified, defaults to "stdio".
@@ -831,12 +1084,15 @@ interface MCPServerConfigBase {
831
1084
  export interface MCPStdioServerConfig extends MCPServerConfigBase {
832
1085
  type?: "local" | "stdio";
833
1086
  command: string;
834
- args: string[];
1087
+ args?: string[];
835
1088
  /**
836
1089
  * Environment variables to pass to the server.
837
1090
  */
838
1091
  env?: Record<string, string>;
839
- cwd?: string;
1092
+ /**
1093
+ * Working directory for the server process.
1094
+ */
1095
+ workingDirectory?: string;
840
1096
  }
841
1097
  /**
842
1098
  * Configuration for a remote MCP server (HTTP or SSE).
@@ -898,6 +1154,12 @@ export interface CustomAgentConfig {
898
1154
  * When omitted, no skills are injected (opt-in model).
899
1155
  */
900
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;
901
1163
  }
902
1164
  /**
903
1165
  * Configuration for the default agent (the built-in agent that handles
@@ -938,15 +1200,52 @@ export interface InfiniteSessionConfig {
938
1200
  bufferExhaustionThreshold?: number;
939
1201
  }
940
1202
  /**
941
- * 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.
942
1208
  */
943
- export type ReasoningEffort = "low" | "medium" | "high" | "xhigh";
944
- export interface SessionConfig {
1209
+ export interface LargeToolOutputConfig {
945
1210
  /**
946
- * Optional custom session ID
947
- * If not provided, server will generate one
1211
+ * Whether large output handling is enabled.
1212
+ * @default true
948
1213
  */
949
- 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
+ * Context window tier for the session. "long_context" pins the session to the
1231
+ * long-context tier when the selected model supports it.
1232
+ */
1233
+ export type ContextTier = "default" | "long_context";
1234
+ /**
1235
+ * Stable extension identity for session participants that provide canvases.
1236
+ */
1237
+ export interface ExtensionInfo {
1238
+ /** Extension namespace/source, e.g. "github-app". */
1239
+ source: string;
1240
+ /** Stable provider name within the source namespace. */
1241
+ name: string;
1242
+ }
1243
+ /**
1244
+ * Shared configuration fields used by both {@link SessionConfig} (for
1245
+ * creating a new session) and {@link ResumeSessionConfig} (for resuming
1246
+ * an existing one).
1247
+ */
1248
+ export interface SessionConfigBase {
950
1249
  /**
951
1250
  * Client name to identify the application using the SDK.
952
1251
  * Included in the User-Agent header for API requests.
@@ -962,13 +1261,30 @@ export interface SessionConfig {
962
1261
  * Use client.listModels() to check supported values for each model.
963
1262
  */
964
1263
  reasoningEffort?: ReasoningEffort;
1264
+ /**
1265
+ * Reasoning summary mode for models that support configurable reasoning summaries.
1266
+ * Use "none" to suppress summary output regardless of whether reasoning is enabled.
1267
+ */
1268
+ reasoningSummary?: ReasoningSummary;
1269
+ /**
1270
+ * Context window tier for models that support it. Use "long_context" to pin
1271
+ * the session to the long-context tier; omit or use "default" otherwise.
1272
+ */
1273
+ contextTier?: ContextTier;
965
1274
  /** Per-property overrides for model capabilities, deep-merged over runtime defaults. */
966
1275
  modelCapabilities?: ModelCapabilitiesOverride;
1276
+ /**
1277
+ * Configuration for handling large tool outputs. When a tool produces
1278
+ * output exceeding the configured size, the output is written to a temp
1279
+ * file and a reference is returned to the model instead of the full
1280
+ * payload.
1281
+ */
1282
+ largeOutput?: LargeToolOutputConfig;
967
1283
  /**
968
1284
  * Override the default configuration directory location.
969
1285
  * When specified, the session will use this directory for storing config and state.
970
1286
  */
971
- configDir?: string;
1287
+ configDirectory?: string;
972
1288
  /**
973
1289
  * When true, automatically discovers MCP server configurations (e.g. `.mcp.json`,
974
1290
  * `.vscode/mcp.json`) and skill directories from the working directory and merges
@@ -982,9 +1298,51 @@ export interface SessionConfig {
982
1298
  */
983
1299
  enableConfigDiscovery?: boolean;
984
1300
  /**
985
- * Tools exposed to the CLI server
1301
+ * Tools exposed to the CLI server. Tools without a handler are declaration-only
1302
+ * and must be resolved by the consumer via pending external tool request RPCs.
986
1303
  */
987
1304
  tools?: Tool<any>[];
1305
+ /**
1306
+ * Canvases contributed by this session participant. The declaring
1307
+ * connection becomes the live provider for `canvas.open|focus|close|reload`
1308
+ * and `canvas.action.invoke` dispatches targeting each canvas's `id` for
1309
+ * the lifetime of the connection. Re-declaring the same id on resume
1310
+ * replaces the prior declaration.
1311
+ */
1312
+ canvases?: Canvas[];
1313
+ /**
1314
+ * Renderer-side opt-in: when true, the runtime surfaces canvas agent tools
1315
+ * (`list_canvas_capabilities`, `open_canvas`, `invoke_canvas_action`) to
1316
+ * the model for this connection. Default off so SDK callers that cannot
1317
+ * display canvases stay clean.
1318
+ */
1319
+ requestCanvasRenderer?: boolean;
1320
+ /**
1321
+ * Extension surface opt-in: when true, the runtime wires extension
1322
+ * management tools and per-extension tool dispatch onto the session for
1323
+ * this connection. Default off so callers that do not expose extensions
1324
+ * stay clean.
1325
+ */
1326
+ requestExtensions?: boolean;
1327
+ /**
1328
+ * Optional override path to a `copilot-sdk/` folder to inject into
1329
+ * extension subprocesses for this session in place of the bundled SDK.
1330
+ * When unset or invalid (missing folder or missing `index.js` /
1331
+ * `extension.js`), the runtime falls back to the bundled SDK without
1332
+ * throwing. Takes precedence over any server-level default.
1333
+ *
1334
+ * Only honored on session create and resume — extensions joining via
1335
+ * `joinSession` cannot override the SDK path, because the extension
1336
+ * subprocess has already been forked by the host with the SDK the host
1337
+ * chose. `JoinSessionConfig` omits this field for that reason.
1338
+ */
1339
+ extensionSdkPath?: string;
1340
+ /**
1341
+ * Stable extension identity for canvas providers on this connection. When
1342
+ * set, the runtime uses `${source}:${name}` as the agent-facing extension
1343
+ * id instead of a reconnect-specific connection id.
1344
+ */
1345
+ extensionInfo?: ExtensionInfo;
988
1346
  /**
989
1347
  * Slash commands registered for this session.
990
1348
  * When the CLI has a TUI, each command appears as `/name` for the user to invoke.
@@ -998,24 +1356,78 @@ export interface SessionConfig {
998
1356
  systemMessage?: SystemMessageConfig;
999
1357
  /**
1000
1358
  * List of tool names to allow. When specified, only these tools will be available.
1001
- * Takes precedence over excludedTools.
1359
+ *
1360
+ * Supports source-qualified filter patterns (`builtin:*`, `builtin:<name>`,
1361
+ * `mcp:*`, `mcp:<name>`, `custom:*`, `custom:<name>`) as well as the bare
1362
+ * name form (exact match across any source). Build this list with
1363
+ * {@link ToolSet} for type safety and readable intent.
1364
+ *
1365
+ * Composes with {@link excludedTools}: a tool is enabled when it matches
1366
+ * `availableTools` (or `availableTools` is unset) AND it does not match
1367
+ * `excludedTools`. This lets you express "everything matching X except Y".
1002
1368
  */
1003
- availableTools?: string[];
1369
+ availableTools?: string[] | ToolSet;
1004
1370
  /**
1005
- * List of tool names to disable. All other tools remain available.
1006
- * Ignored if availableTools is specified.
1371
+ * List of tool names to disable. Supports the same pattern syntax as
1372
+ * {@link availableTools}.
1373
+ *
1374
+ * Always takes precedence over {@link availableTools}: a tool listed here
1375
+ * is disabled even if it also matches `availableTools`.
1007
1376
  */
1008
- excludedTools?: string[];
1377
+ excludedTools?: string[] | ToolSet;
1009
1378
  /**
1010
1379
  * Custom provider configuration (BYOK - Bring Your Own Key).
1011
1380
  * When specified, uses the provided API endpoint instead of the Copilot API.
1012
1381
  */
1013
1382
  provider?: ProviderConfig;
1014
1383
  /**
1015
- * Handler for permission requests from the server.
1016
- * When provided, the server will call this handler to request permission for operations.
1384
+ * Enables or disables internal session telemetry for this session.
1385
+ * When `false`, disables session telemetry. When omitted (the default) or `true`,
1386
+ * telemetry is enabled for GitHub-authenticated sessions.
1387
+ * When a custom {@link provider} (BYOK) is configured, session telemetry is always
1388
+ * disabled regardless of this setting.
1389
+ * This is independent of the OpenTelemetry configuration in {@link CopilotClientOptions.telemetry}.
1017
1390
  */
1018
- onPermissionRequest: PermissionHandler;
1391
+ enableSessionTelemetry?: boolean;
1392
+ /**
1393
+ * When true, the runtime skips loading custom-instruction sources
1394
+ * (e.g. `.github/copilot-instructions.md`, `AGENTS.md`, `CLAUDE.md`).
1395
+ *
1396
+ * Defaults to `false` (custom instructions are loaded). Under
1397
+ * {@link CopilotClientOptions.mode} = `"empty"`, defaults to `true`; apps
1398
+ * can pass `false` here to opt back in.
1399
+ */
1400
+ skipCustomInstructions?: boolean;
1401
+ /**
1402
+ * When true, custom agents default to local-only execution and are not
1403
+ * dispatched to remote workers.
1404
+ *
1405
+ * Defaults to `false`. Under {@link CopilotClientOptions.mode} = `"empty"`,
1406
+ * defaults to `true`; apps can pass `false` here to opt back in.
1407
+ */
1408
+ customAgentsLocalOnly?: boolean;
1409
+ /**
1410
+ * When true, the runtime instructs the agent to include a `Co-authored-by`
1411
+ * trailer in commit messages it composes.
1412
+ *
1413
+ * Defaults to `true`. Under {@link CopilotClientOptions.mode} = `"empty"`,
1414
+ * defaults to `false`; apps can pass `true` here to opt back in.
1415
+ */
1416
+ coauthorEnabled?: boolean;
1417
+ /**
1418
+ * When true, the `manage_schedule` tool is exposed to the agent.
1419
+ *
1420
+ * Defaults to whatever the runtime exposes (typically gated to staff
1421
+ * users). Under {@link CopilotClientOptions.mode} = `"empty"`, defaults to
1422
+ * `false`; apps can pass `true` here to opt back in.
1423
+ */
1424
+ manageScheduleEnabled?: boolean;
1425
+ /**
1426
+ * Optional handler for permission requests from the server.
1427
+ * When omitted, permission requests are surfaced as events and left pending for
1428
+ * the consumer to resolve via the pending permission RPC.
1429
+ */
1430
+ onPermissionRequest?: PermissionHandler;
1019
1431
  /**
1020
1432
  * Handler for user input requests from the agent.
1021
1433
  * When provided, enables the ask_user tool allowing the agent to ask questions.
@@ -1027,6 +1439,43 @@ export interface SessionConfig {
1027
1439
  * Also enables the `elicitation` capability on the session.
1028
1440
  */
1029
1441
  onElicitationRequest?: ElicitationHandler;
1442
+ /**
1443
+ * Enable MCP Apps (SEP-1865) UI passthrough on this session.
1444
+ *
1445
+ * When `true` **and** the runtime has MCP Apps enabled (via the
1446
+ * `MCP_APPS` feature flag or `COPILOT_MCP_APPS=true` environment
1447
+ * override), the runtime adds the `mcp-apps` capability to the session,
1448
+ * which causes it to advertise the `extensions.io.modelcontextprotocol/ui`
1449
+ * extension to MCP servers (so they expose `_meta.ui.resourceUri` on
1450
+ * tools) and to expose the `session.rpc.mcp.apps.{listTools,callTool,
1451
+ * readResource,setHostContext,getHostContext,diagnose}` JSON-RPC methods.
1452
+ *
1453
+ * If the runtime gate is off, the opt-in is silently dropped server-side
1454
+ * (the runtime logs a warning); the session is created normally but the
1455
+ * MCP Apps surface is unavailable. Inspect the runtime's
1456
+ * `capabilities.ui.mcpApps` on the create/resume response to detect this.
1457
+ *
1458
+ * SDK consumers MUST set this to `true` only when they have an iframe
1459
+ * renderer that can display `ui://` MCP App bundles. Setting it without a
1460
+ * renderer will cause MCP servers to register UI-enabled tool variants
1461
+ * the consumer cannot display.
1462
+ *
1463
+ * @experimental This option is part of an experimental wire-protocol surface
1464
+ * (SEP-1865) and may change or be removed in a future release.
1465
+ *
1466
+ * @default false
1467
+ */
1468
+ enableMcpApps?: boolean;
1469
+ /**
1470
+ * Handler for exit-plan-mode requests from the agent.
1471
+ * When provided, enables `exitPlanMode.request` callbacks.
1472
+ */
1473
+ onExitPlanModeRequest?: ExitPlanModeHandler;
1474
+ /**
1475
+ * Handler for auto-mode-switch requests from the agent.
1476
+ * When provided, enables `autoModeSwitch.request` callbacks.
1477
+ */
1478
+ onAutoModeSwitchRequest?: AutoModeSwitchHandler;
1030
1479
  /**
1031
1480
  * Hook handlers for intercepting session lifecycle events.
1032
1481
  * When provided, enables hooks callback allowing custom logic at various points.
@@ -1037,6 +1486,13 @@ export interface SessionConfig {
1037
1486
  * Tool operations will be relative to this directory.
1038
1487
  */
1039
1488
  workingDirectory?: string;
1489
+ /**
1490
+ * Enable streaming of assistant message and reasoning chunks.
1491
+ * When true, ephemeral assistant.message_delta and assistant.reasoning_delta
1492
+ * events are sent as the response is generated. Clients should accumulate
1493
+ * deltaContent values to build the full response.
1494
+ * @default false
1495
+ */
1040
1496
  streaming?: boolean;
1041
1497
  /**
1042
1498
  * Include sub-agent streaming events in the event stream. When true, streaming
@@ -1048,6 +1504,14 @@ export interface SessionConfig {
1048
1504
  * @default true
1049
1505
  */
1050
1506
  includeSubAgentStreamingEvents?: boolean;
1507
+ /**
1508
+ * Controls how MCP OAuth tokens are stored for this session.
1509
+ * - `"persistent"` — tokens are stored in the OS keychain (shared across sessions)
1510
+ * - `"in-memory"` — tokens are stored in memory and discarded when the session ends
1511
+ *
1512
+ * @default "in-memory"
1513
+ */
1514
+ mcpOAuthTokenStorage?: "persistent" | "in-memory";
1051
1515
  /**
1052
1516
  * MCP server configurations for the session.
1053
1517
  * Keys are server names, values are server configurations.
@@ -1074,6 +1538,20 @@ export interface SessionConfig {
1074
1538
  * Directories to load skills from.
1075
1539
  */
1076
1540
  skillDirectories?: string[];
1541
+ /**
1542
+ * Local filesystem paths to Open Plugins-format directories
1543
+ * (https://open-plugins.com/) to load for this session.
1544
+ *
1545
+ * Relative paths resolve against `workingDirectory` (or the runtime cwd if
1546
+ * unset); absolute paths are recommended. Invalid entries are logged and
1547
+ * skipped.
1548
+ *
1549
+ * Treated as an explicit opt-in: plugin agents and rules load even when
1550
+ * {@link SessionConfigBase.enableConfigDiscovery} is false. Loaded assets
1551
+ * slot between project (cwd) sources and personal/home sources in the
1552
+ * session-wide precedence order.
1553
+ */
1554
+ pluginDirectories?: string[];
1077
1555
  /**
1078
1556
  * Additional directories to search for custom instruction files.
1079
1557
  */
@@ -1099,6 +1577,60 @@ export interface SessionConfig {
1099
1577
  * the identity used for content exclusion, model routing, and quota checks.
1100
1578
  */
1101
1579
  gitHubToken?: string;
1580
+ /**
1581
+ * When true, skips embedding-based retrieval for this session.
1582
+ * Use in multitenant deployments to prevent cross-session information leakage
1583
+ * through the shared embedding cache.
1584
+ */
1585
+ skipEmbeddingRetrieval?: boolean;
1586
+ /**
1587
+ * Controls how the embedding cache is stored for this session.
1588
+ * - `"persistent"`: Embeddings are cached on disk and shared across sessions/restarts.
1589
+ * - `"in-memory"`: Embeddings are cached in memory only and discarded when the session ends.
1590
+ */
1591
+ embeddingCacheStorage?: "persistent" | "in-memory";
1592
+ /**
1593
+ * Organization-level custom instructions to include in the system prompt.
1594
+ * Allows hosts to inject organization-specific guidance without relying on
1595
+ * filesystem-based instruction discovery.
1596
+ */
1597
+ organizationCustomInstructions?: string;
1598
+ /**
1599
+ * When true, enables on-demand discovery of instruction files (AGENTS.md,
1600
+ * .github/copilot-instructions.md, etc.) after successful file views.
1601
+ */
1602
+ enableOnDemandInstructionDiscovery?: boolean;
1603
+ /**
1604
+ * When true, enables loading of file-based hooks from `.github/hooks/`.
1605
+ * This is separate from the `hooks` callback parameter which gates SDK
1606
+ * hook event registration.
1607
+ */
1608
+ enableFileHooks?: boolean;
1609
+ /**
1610
+ * When true, enables git operations on the host filesystem (branch detection,
1611
+ * file status, commit history). When false, no git context is surfaced in
1612
+ * the system prompt.
1613
+ */
1614
+ enableHostGitOperations?: boolean;
1615
+ /**
1616
+ * When true, enables the cross-session store for search and retrieval
1617
+ * across sessions. When false, session content is not written to or
1618
+ * read from the shared session store.
1619
+ */
1620
+ enableSessionStore?: boolean;
1621
+ /**
1622
+ * When true, enables skill loading (including builtin skills and discovered
1623
+ * skill directories). When false, no skills are loaded regardless of
1624
+ * `skillDirectories` or `enableConfigDiscovery` settings.
1625
+ */
1626
+ enableSkills?: boolean;
1627
+ /**
1628
+ * Per-session remote behavior control:
1629
+ * - `"off"` — local only, no remote export (default)
1630
+ * - `"export"` — export session events to GitHub without enabling remote steering
1631
+ * - `"on"` — export to GitHub AND enable remote steering
1632
+ */
1633
+ remoteSession?: RemoteSessionMode;
1102
1634
  /**
1103
1635
  * Optional event handler that is registered on the session before the
1104
1636
  * session.create RPC is issued. This guarantees that early events emitted
@@ -1113,18 +1645,33 @@ export interface SessionConfig {
1113
1645
  * Supplies a handler for session filesystem operations. This takes effect
1114
1646
  * only if {@link CopilotClientOptions.sessionFs} is configured.
1115
1647
  */
1116
- createSessionFsHandler?: (session: CopilotSession) => SessionFsProvider;
1648
+ createSessionFsProvider?: (session: CopilotSession) => SessionFsProvider;
1117
1649
  }
1118
1650
  /**
1119
- * Configuration for resuming a session
1651
+ * Configuration for creating a new session via {@link CopilotClient.createSession}.
1120
1652
  */
1121
- 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" | "instructionDirectories" | "disabledSkills" | "infiniteSessions" | "gitHubToken" | "onEvent" | "createSessionFsHandler"> & {
1653
+ export interface SessionConfig extends SessionConfigBase {
1654
+ /**
1655
+ * Optional custom session ID. If not provided, the server generates one.
1656
+ */
1657
+ sessionId?: string;
1658
+ /**
1659
+ * Creates a remote session in the cloud instead of a local session.
1660
+ * The optional repository is associated with the cloud session.
1661
+ */
1662
+ cloud?: CloudSessionOptions;
1663
+ }
1664
+ /**
1665
+ * Configuration for resuming an existing session via
1666
+ * {@link CopilotClient.resumeSession}.
1667
+ */
1668
+ export interface ResumeSessionConfig extends SessionConfigBase {
1122
1669
  /**
1123
1670
  * When true, skips emitting the session.resume event.
1124
1671
  * Useful for reconnecting to a session without triggering resume-related side effects.
1125
1672
  * @default false
1126
1673
  */
1127
- disableResume?: boolean;
1674
+ suppressResumeEvent?: boolean;
1128
1675
  /**
1129
1676
  * When true, the runtime continues any tool calls or permission prompts that were
1130
1677
  * still pending when the session was last suspended. When false (the default), the
@@ -1137,7 +1684,13 @@ export type ResumeSessionConfig = Pick<SessionConfig, "clientName" | "model" | "
1137
1684
  * @default false
1138
1685
  */
1139
1686
  continuePendingWork?: boolean;
1140
- };
1687
+ /**
1688
+ * Snapshot of canvases that were already open when the session was suspended.
1689
+ * When provided on resume, the runtime can rehydrate canvas state so consumers
1690
+ * do not need to re-open canvases that were active before the previous shutdown.
1691
+ */
1692
+ openCanvases?: OpenCanvasInstance[];
1693
+ }
1141
1694
  /**
1142
1695
  * Configuration for a custom API provider.
1143
1696
  */
@@ -1177,6 +1730,32 @@ export interface ProviderConfig {
1177
1730
  * Custom HTTP headers to include in outbound provider requests.
1178
1731
  */
1179
1732
  headers?: Record<string, string>;
1733
+ /**
1734
+ * Well-known model name used by the runtime to look up agent configuration
1735
+ * (tools, prompts, reasoning behavior) and default token limits. Also used
1736
+ * as the wire model when {@link wireModel} is not set.
1737
+ * Falls back to {@link SessionConfig.model}.
1738
+ */
1739
+ modelId?: string;
1740
+ /**
1741
+ * Model name sent to the provider API for inference. Use this when the
1742
+ * provider's model name (e.g. an Azure deployment name or a custom
1743
+ * fine-tune name) differs from {@link modelId}.
1744
+ * Falls back to {@link modelId}, then {@link SessionConfig.model}.
1745
+ */
1746
+ wireModel?: string;
1747
+ /**
1748
+ * Overrides the resolved model's default max prompt tokens. The runtime
1749
+ * triggers conversation compaction before sending a request when the
1750
+ * prompt (system message, history, tool definitions, user message) would
1751
+ * exceed this limit.
1752
+ */
1753
+ maxPromptTokens?: number;
1754
+ /**
1755
+ * Overrides the resolved model's default max output tokens. When hit, the
1756
+ * model stops generating and returns a truncated response.
1757
+ */
1758
+ maxOutputTokens?: number;
1180
1759
  }
1181
1760
  /**
1182
1761
  * Options for sending a message to a session
@@ -1224,10 +1803,19 @@ export interface MessageOptions {
1224
1803
  * - "immediate": Send immediately
1225
1804
  */
1226
1805
  mode?: "enqueue" | "immediate";
1806
+ /**
1807
+ * The UI mode the agent was in when this message was sent (for example "plan" or "autopilot").
1808
+ * Defaults to the session's current mode when unset.
1809
+ */
1810
+ agentMode?: "interactive" | "plan" | "autopilot" | "shell";
1227
1811
  /**
1228
1812
  * Custom HTTP headers to include in outbound model requests for this turn.
1229
1813
  */
1230
1814
  requestHeaders?: Record<string, string>;
1815
+ /**
1816
+ * If provided, this is shown in the timeline instead of `prompt`.
1817
+ */
1818
+ displayPrompt?: string;
1231
1819
  }
1232
1820
  /**
1233
1821
  * All possible event type strings from SessionEvent
@@ -1247,16 +1835,12 @@ export type TypedSessionEventHandler<T extends SessionEventType> = (event: Sessi
1247
1835
  * Event handler callback type (for all events)
1248
1836
  */
1249
1837
  export type SessionEventHandler = (event: SessionEvent) => void;
1250
- /**
1251
- * Connection state
1252
- */
1253
- export type ConnectionState = "disconnected" | "connecting" | "connected" | "error";
1254
1838
  /**
1255
1839
  * Working directory context for a session
1256
1840
  */
1257
1841
  export interface SessionContext {
1258
1842
  /** Working directory where the session was created */
1259
- cwd: string;
1843
+ workingDirectory: string;
1260
1844
  /** Git repository root (if in a git repo) */
1261
1845
  gitRoot?: string;
1262
1846
  /** GitHub repository in "owner/repo" format */
@@ -1281,13 +1865,26 @@ export interface SessionFsConfig {
1281
1865
  * Path conventions used by this filesystem provider.
1282
1866
  */
1283
1867
  conventions: "windows" | "posix";
1868
+ /**
1869
+ * Optional capabilities declared by this provider.
1870
+ * The runtime uses these to determine which features are available.
1871
+ */
1872
+ capabilities?: {
1873
+ /**
1874
+ * Whether this provider supports SQLite query/exists operations.
1875
+ * When false or omitted, the runtime will not offer SQL tools or
1876
+ * todo tracking for sessions using this provider.
1877
+ * @default false
1878
+ */
1879
+ sqlite?: boolean;
1880
+ };
1284
1881
  }
1285
1882
  /**
1286
1883
  * Filter options for listing sessions
1287
1884
  */
1288
1885
  export interface SessionListFilter {
1289
- /** Filter by exact cwd match */
1290
- cwd?: string;
1886
+ /** Filter by exact working directory match */
1887
+ workingDirectory?: string;
1291
1888
  /** Filter by git root */
1292
1889
  gitRoot?: string;
1293
1890
  /** Filter by repository (owner/repo format) */
@@ -1304,7 +1901,7 @@ export interface SessionMetadata {
1304
1901
  modifiedTime: Date;
1305
1902
  summary?: string;
1306
1903
  isRemote: boolean;
1307
- /** Working directory context (cwd, git info) from session creation */
1904
+ /** Working directory context (working directory, git info) from session creation */
1308
1905
  context?: SessionContext;
1309
1906
  }
1310
1907
  /**
@@ -1367,7 +1964,7 @@ export interface ModelPolicy {
1367
1964
  * Model billing information
1368
1965
  */
1369
1966
  export interface ModelBilling {
1370
- multiplier: number;
1967
+ multiplier?: number;
1371
1968
  }
1372
1969
  /**
1373
1970
  * Information about an available model
@@ -1389,35 +1986,68 @@ export interface ModelInfo {
1389
1986
  defaultReasoningEffort?: ReasoningEffort;
1390
1987
  }
1391
1988
  /**
1392
- * Types of session lifecycle events
1989
+ * Types of session lifecycle events.
1393
1990
  */
1394
1991
  export type SessionLifecycleEventType = "session.created" | "session.deleted" | "session.updated" | "session.foreground" | "session.background";
1395
1992
  /**
1396
- * Session lifecycle event notification
1397
- * Sent when sessions are created, deleted, updated, or change foreground/background state
1993
+ * Metadata payload for session lifecycle events. Not present on
1994
+ * `session.deleted` events.
1398
1995
  */
1399
- export interface SessionLifecycleEvent {
1400
- /** Type of lifecycle event */
1401
- type: SessionLifecycleEventType;
1402
- /** ID of the session this event relates to */
1996
+ export interface SessionLifecycleEventMetadata {
1997
+ /** Time the session was created. */
1998
+ startTime: Date;
1999
+ /** Time the session was last modified. */
2000
+ modifiedTime: Date;
2001
+ /** Human-readable summary of the session, if available. */
2002
+ summary?: string;
2003
+ }
2004
+ /** Base shape shared by every lifecycle event variant. */
2005
+ interface SessionLifecycleEventBase {
2006
+ /** ID of the session this event relates to. */
1403
2007
  sessionId: string;
1404
- /** Session metadata (not included for deleted sessions) */
1405
- metadata?: {
1406
- startTime: string;
1407
- modifiedTime: string;
1408
- summary?: string;
1409
- };
2008
+ /** Session metadata (not included for `session.deleted`). */
2009
+ metadata?: SessionLifecycleEventMetadata;
1410
2010
  }
2011
+ /** Emitted when a new session is created. */
2012
+ export interface SessionCreatedEvent extends SessionLifecycleEventBase {
2013
+ type: "session.created";
2014
+ metadata: SessionLifecycleEventMetadata;
2015
+ }
2016
+ /** Emitted when a session is deleted. The metadata field is omitted. */
2017
+ export interface SessionDeletedEvent extends SessionLifecycleEventBase {
2018
+ type: "session.deleted";
2019
+ metadata?: undefined;
2020
+ }
2021
+ /** Emitted when a session's metadata is updated. */
2022
+ export interface SessionUpdatedEvent extends SessionLifecycleEventBase {
2023
+ type: "session.updated";
2024
+ metadata: SessionLifecycleEventMetadata;
2025
+ }
2026
+ /** Emitted when a session is brought to the foreground (TUI+server mode). */
2027
+ export interface SessionForegroundEvent extends SessionLifecycleEventBase {
2028
+ type: "session.foreground";
2029
+ metadata: SessionLifecycleEventMetadata;
2030
+ }
2031
+ /** Emitted when a session is moved to the background (TUI+server mode). */
2032
+ export interface SessionBackgroundEvent extends SessionLifecycleEventBase {
2033
+ type: "session.background";
2034
+ metadata: SessionLifecycleEventMetadata;
2035
+ }
2036
+ /**
2037
+ * Discriminated union of all session lifecycle events emitted in TUI+server mode.
2038
+ * Switch on `type` to access the variant-specific metadata.
2039
+ */
2040
+ export type SessionLifecycleEvent = SessionCreatedEvent | SessionDeletedEvent | SessionUpdatedEvent | SessionForegroundEvent | SessionBackgroundEvent;
1411
2041
  /**
1412
- * Handler for session lifecycle events
2042
+ * Handler for session lifecycle events.
1413
2043
  */
1414
2044
  export type SessionLifecycleHandler = (event: SessionLifecycleEvent) => void;
1415
2045
  /**
1416
- * Typed handler for specific session lifecycle event types
2046
+ * Typed handler for specific session lifecycle event types.
1417
2047
  */
1418
- export type TypedSessionLifecycleHandler<K extends SessionLifecycleEventType> = (event: SessionLifecycleEvent & {
2048
+ export type TypedSessionLifecycleHandler<K extends SessionLifecycleEventType> = (event: Extract<SessionLifecycleEvent, {
1419
2049
  type: K;
1420
- }) => void;
2050
+ }>) => void;
1421
2051
  /**
1422
2052
  * Information about the foreground session in TUI+server mode
1423
2053
  */