@github/copilot-sdk 1.0.0-beta.5 → 1.0.0-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -30
- package/dist/canvas.d.ts +163 -0
- package/dist/canvas.js +92 -0
- package/dist/cjs/canvas.js +119 -0
- package/dist/cjs/client.js +243 -251
- package/dist/cjs/extension.js +9 -2
- package/dist/cjs/generated/rpc.js +97 -1
- package/dist/cjs/index.js +17 -7
- package/dist/cjs/session.js +64 -90
- package/dist/cjs/types.js +36 -3
- package/dist/client.d.ts +46 -49
- package/dist/client.js +246 -252
- package/dist/extension.d.ts +3 -1
- package/dist/extension.js +10 -2
- package/dist/generated/rpc.d.ts +796 -63
- package/dist/generated/rpc.js +97 -1
- package/dist/generated/session-events.d.ts +491 -78
- package/dist/index.d.ts +4 -2
- package/dist/index.js +12 -2
- package/dist/session.d.ts +13 -210
- package/dist/session.js +63 -88
- package/dist/types.d.ts +291 -121
- package/dist/types.js +34 -2
- package/package.json +2 -2
package/dist/types.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
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
6
|
import type { SessionEvent as GeneratedSessionEvent } from "./generated/session-events.js";
|
|
6
7
|
import type { CopilotSession } from "./session.js";
|
|
7
8
|
import type { RemoteSessionMode } from "./generated/rpc.js";
|
|
9
|
+
import type { OpenCanvasInstance } from "./generated/rpc.js";
|
|
8
10
|
export type { RemoteSessionMode } from "./generated/rpc.js";
|
|
9
11
|
export type SessionEvent = GeneratedSessionEvent;
|
|
10
12
|
export type { SessionFsProvider } from "./sessionFsProvider.js";
|
|
@@ -48,80 +50,120 @@ export interface TelemetryConfig {
|
|
|
48
50
|
/** Whether to capture message content (prompts, responses). Sets OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT. */
|
|
49
51
|
captureContent?: boolean;
|
|
50
52
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
/**
|
|
54
|
+
* Configures how a {@link CopilotClient} connects to the Copilot runtime.
|
|
55
|
+
* Construct via the factory functions on {@link RuntimeConnection}.
|
|
56
|
+
*/
|
|
57
|
+
export type RuntimeConnection = StdioRuntimeConnection | TcpRuntimeConnection | UriRuntimeConnection;
|
|
58
|
+
/**
|
|
59
|
+
* Spawns a runtime child process and communicates over its stdin/stdout.
|
|
60
|
+
* This is the default if no {@link CopilotClientOptions.connection} is set.
|
|
61
|
+
*/
|
|
62
|
+
export interface StdioRuntimeConnection {
|
|
63
|
+
readonly kind: "stdio";
|
|
64
|
+
/** Path to the runtime executable. When omitted, the bundled runtime is used. */
|
|
65
|
+
readonly path?: string;
|
|
66
|
+
/** Extra command-line arguments to pass to the runtime process. */
|
|
67
|
+
readonly args?: readonly string[];
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Spawns a runtime child process that listens on a TCP socket and connects to it.
|
|
71
|
+
*/
|
|
72
|
+
export interface TcpRuntimeConnection {
|
|
73
|
+
readonly kind: "tcp";
|
|
57
74
|
/**
|
|
58
|
-
*
|
|
75
|
+
* TCP port to listen on. `0` (the default) auto-allocates a free port.
|
|
76
|
+
* If the chosen port is already in use, startup fails.
|
|
59
77
|
*/
|
|
60
|
-
|
|
78
|
+
readonly port?: number;
|
|
61
79
|
/**
|
|
62
|
-
*
|
|
63
|
-
*
|
|
80
|
+
* Optional shared secret the SDK sends to the spawned runtime to authenticate
|
|
81
|
+
* the TCP connection. When omitted, a UUID is generated automatically so the
|
|
82
|
+
* loopback listener is safe by default.
|
|
64
83
|
*/
|
|
65
|
-
|
|
84
|
+
readonly connectionToken?: string;
|
|
85
|
+
/** Path to the runtime executable. When omitted, the bundled runtime is used. */
|
|
86
|
+
readonly path?: string;
|
|
87
|
+
/** Extra command-line arguments to pass to the runtime process. */
|
|
88
|
+
readonly args?: readonly string[];
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Connects to an already-running runtime at the specified URL. The SDK does not
|
|
92
|
+
* spawn a process in this mode.
|
|
93
|
+
*/
|
|
94
|
+
export interface UriRuntimeConnection {
|
|
95
|
+
readonly kind: "uri";
|
|
66
96
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* When not set, the CLI defaults to ~/.copilot.
|
|
70
|
-
* This option is only used when the SDK spawns the CLI process; it is ignored
|
|
71
|
-
* when connecting to an external server via {@link cliUrl}.
|
|
97
|
+
* URL of the runtime to connect to. Accepts `"port"`, `"host:port"`, or a
|
|
98
|
+
* full URL (`"http://host:port"`).
|
|
72
99
|
*/
|
|
73
|
-
|
|
100
|
+
readonly url: string;
|
|
101
|
+
/** Optional shared secret to authenticate the connection. */
|
|
102
|
+
readonly connectionToken?: string;
|
|
103
|
+
}
|
|
104
|
+
/** Factory functions for constructing {@link RuntimeConnection} instances. */
|
|
105
|
+
export declare const RuntimeConnection: {
|
|
74
106
|
/**
|
|
75
|
-
*
|
|
76
|
-
*
|
|
107
|
+
* Spawn a runtime child process and communicate over its stdin/stdout.
|
|
108
|
+
* This is the default if no {@link CopilotClientOptions.connection} is set.
|
|
77
109
|
*/
|
|
78
|
-
|
|
110
|
+
readonly forStdio: (opts?: {
|
|
111
|
+
path?: string;
|
|
112
|
+
args?: readonly string[];
|
|
113
|
+
}) => StdioRuntimeConnection;
|
|
79
114
|
/**
|
|
80
|
-
*
|
|
81
|
-
* When true, communicates with CLI via stdin/stdout pipes
|
|
82
|
-
* @default true
|
|
115
|
+
* Spawn a runtime child process that listens on a TCP socket and connect to it.
|
|
83
116
|
*/
|
|
84
|
-
|
|
117
|
+
readonly forTcp: (opts?: {
|
|
118
|
+
port?: number;
|
|
119
|
+
connectionToken?: string;
|
|
120
|
+
path?: string;
|
|
121
|
+
args?: readonly string[];
|
|
122
|
+
}) => TcpRuntimeConnection;
|
|
85
123
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
* with useStdio: true.
|
|
124
|
+
* Connect to an already-running runtime at the given URL. The SDK does not
|
|
125
|
+
* spawn a process in this mode.
|
|
89
126
|
*/
|
|
90
|
-
|
|
127
|
+
readonly forUri: (url: string, opts?: {
|
|
128
|
+
connectionToken?: string;
|
|
129
|
+
}) => UriRuntimeConnection;
|
|
130
|
+
};
|
|
131
|
+
export interface CopilotClientOptions {
|
|
91
132
|
/**
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
* Format: "host:port" or "http://host:port" or just "port" (defaults to localhost)
|
|
95
|
-
* Examples: "localhost:8080", "http://127.0.0.1:9000", "8080"
|
|
96
|
-
* Mutually exclusive with cliPath, useStdio
|
|
133
|
+
* How to connect to the Copilot runtime. When omitted, defaults to
|
|
134
|
+
* {@link RuntimeConnection.forStdio} with the bundled runtime.
|
|
97
135
|
*/
|
|
98
|
-
|
|
136
|
+
connection?: RuntimeConnection;
|
|
99
137
|
/**
|
|
100
|
-
*
|
|
138
|
+
* Working directory for the runtime process.
|
|
139
|
+
* If not set, inherits the current process's working directory.
|
|
101
140
|
*/
|
|
102
|
-
|
|
141
|
+
workingDirectory?: string;
|
|
103
142
|
/**
|
|
104
|
-
*
|
|
105
|
-
*
|
|
143
|
+
* Base directory for Copilot data (session state, config, etc.).
|
|
144
|
+
* Sets the COPILOT_HOME environment variable on the spawned runtime.
|
|
145
|
+
* When not set, the runtime defaults to ~/.copilot.
|
|
146
|
+
* Ignored when connecting to an existing runtime via {@link RuntimeConnection.forUri}.
|
|
106
147
|
*/
|
|
107
|
-
|
|
148
|
+
baseDirectory?: string;
|
|
108
149
|
/**
|
|
109
|
-
*
|
|
150
|
+
* Log level for the Copilot runtime. When omitted, the runtime uses its
|
|
151
|
+
* own default (currently `"info"`).
|
|
110
152
|
*/
|
|
111
|
-
|
|
153
|
+
logLevel?: "none" | "error" | "warning" | "info" | "debug" | "all";
|
|
112
154
|
/**
|
|
113
|
-
* Environment variables to pass to the
|
|
155
|
+
* Environment variables to pass to the runtime process. If not set, inherits process.env.
|
|
114
156
|
*/
|
|
115
157
|
env?: Record<string, string | undefined>;
|
|
116
158
|
/**
|
|
117
159
|
* GitHub token to use for authentication.
|
|
118
|
-
* When provided, the token is passed to the
|
|
160
|
+
* When provided, the token is passed to the runtime via environment variable.
|
|
119
161
|
* This takes priority over other authentication methods.
|
|
120
162
|
*/
|
|
121
163
|
gitHubToken?: string;
|
|
122
164
|
/**
|
|
123
165
|
* Whether to use the logged-in user for authentication.
|
|
124
|
-
* When true, the
|
|
166
|
+
* When true, the runtime will attempt to use stored OAuth tokens or gh CLI auth.
|
|
125
167
|
* When false, only explicit tokens (gitHubToken or environment variables) are used.
|
|
126
168
|
* @default true (but defaults to false when gitHubToken is provided)
|
|
127
169
|
*/
|
|
@@ -129,14 +171,14 @@ export interface CopilotClientOptions {
|
|
|
129
171
|
/**
|
|
130
172
|
* Custom handler for listing available models.
|
|
131
173
|
* When provided, client.listModels() calls this handler instead of
|
|
132
|
-
* querying the
|
|
174
|
+
* querying the runtime. Useful in BYOK mode to return models
|
|
133
175
|
* available from your custom provider.
|
|
134
176
|
*/
|
|
135
177
|
onListModels?: () => Promise<ModelInfo[]> | ModelInfo[];
|
|
136
178
|
/**
|
|
137
|
-
* OpenTelemetry configuration for the
|
|
179
|
+
* OpenTelemetry configuration for the runtime process.
|
|
138
180
|
* When provided, the corresponding OTel environment variables are set
|
|
139
|
-
* on the spawned
|
|
181
|
+
* on the spawned runtime.
|
|
140
182
|
*/
|
|
141
183
|
telemetry?: TelemetryConfig;
|
|
142
184
|
/**
|
|
@@ -175,27 +217,18 @@ export interface CopilotClientOptions {
|
|
|
175
217
|
* Server-wide idle timeout for sessions in seconds.
|
|
176
218
|
* Sessions without activity for this duration are automatically cleaned up.
|
|
177
219
|
* Set to 0 or omit to disable (sessions live indefinitely).
|
|
178
|
-
*
|
|
179
|
-
* when connecting to an external server via {@link cliUrl}.
|
|
220
|
+
* Ignored when connecting to an existing runtime via {@link RuntimeConnection.forUri}.
|
|
180
221
|
* @default undefined (disabled)
|
|
181
222
|
*/
|
|
182
223
|
sessionIdleTimeoutSeconds?: number;
|
|
183
|
-
/**
|
|
184
|
-
* Connection token for the headless CLI server (TCP only). When the SDK
|
|
185
|
-
* spawns its own CLI in TCP mode and this is omitted, a UUID is generated
|
|
186
|
-
* automatically so the loopback listener is safe by default. Rejected with
|
|
187
|
-
* `useStdio: true` (stdio is pre-authenticated by transport).
|
|
188
|
-
*/
|
|
189
|
-
tcpConnectionToken?: string;
|
|
190
224
|
/**
|
|
191
225
|
* Enable remote session support (Mission Control integration).
|
|
192
226
|
* When true, sessions in a GitHub repository working directory are
|
|
193
227
|
* accessible from GitHub web and mobile.
|
|
194
|
-
*
|
|
195
|
-
* when connecting to an external server via {@link cliUrl}.
|
|
228
|
+
* Ignored when connecting to an existing runtime via {@link RuntimeConnection.forUri}.
|
|
196
229
|
* @default false
|
|
197
230
|
*/
|
|
198
|
-
|
|
231
|
+
enableRemoteSessions?: boolean;
|
|
199
232
|
}
|
|
200
233
|
/**
|
|
201
234
|
* Configuration for creating a session
|
|
@@ -207,13 +240,14 @@ export type ToolBinaryResult = {
|
|
|
207
240
|
type: "image" | "resource";
|
|
208
241
|
description?: string;
|
|
209
242
|
};
|
|
243
|
+
export type ToolTelemetry = Record<string, Record<string, unknown> | undefined>;
|
|
210
244
|
export type ToolResultObject = {
|
|
211
245
|
textResultForLlm: string;
|
|
212
246
|
binaryResultsForLlm?: ToolBinaryResult[];
|
|
213
247
|
resultType: ToolResultType;
|
|
214
248
|
error?: string;
|
|
215
249
|
sessionLog?: string;
|
|
216
|
-
toolTelemetry?:
|
|
250
|
+
toolTelemetry?: ToolTelemetry;
|
|
217
251
|
};
|
|
218
252
|
export type ToolResult = string | ToolResultObject;
|
|
219
253
|
/**
|
|
@@ -357,6 +391,8 @@ export interface SessionCapabilities {
|
|
|
357
391
|
ui?: {
|
|
358
392
|
/** Whether the host supports interactive elicitation dialogs. */
|
|
359
393
|
elicitation?: boolean;
|
|
394
|
+
/** Whether the host supports canvas rendering. */
|
|
395
|
+
canvases?: boolean;
|
|
360
396
|
};
|
|
361
397
|
}
|
|
362
398
|
/**
|
|
@@ -481,7 +517,7 @@ export type ElicitationHandler = (context: ElicitationContext) => Promise<Elicit
|
|
|
481
517
|
/**
|
|
482
518
|
* Options for the `input()` convenience method.
|
|
483
519
|
*/
|
|
484
|
-
export interface
|
|
520
|
+
export interface UiInputOptions {
|
|
485
521
|
/** Title label for the input field. */
|
|
486
522
|
title?: string;
|
|
487
523
|
/** Descriptive text shown below the field. */
|
|
@@ -522,7 +558,7 @@ export interface SessionUiApi {
|
|
|
522
558
|
* Returns the entered text, or `null` if the user declines/cancels.
|
|
523
559
|
* @throws Error if the host does not support elicitation.
|
|
524
560
|
*/
|
|
525
|
-
input(message: string, options?:
|
|
561
|
+
input(message: string, options?: UiInputOptions): Promise<string | null>;
|
|
526
562
|
}
|
|
527
563
|
export interface ToolCallRequestPayload {
|
|
528
564
|
sessionId: string;
|
|
@@ -534,12 +570,12 @@ export interface ToolCallResponsePayload {
|
|
|
534
570
|
result: ToolResult;
|
|
535
571
|
}
|
|
536
572
|
/**
|
|
537
|
-
* Known system
|
|
573
|
+
* Known system message section identifiers for the "customize" mode.
|
|
538
574
|
* Each section corresponds to a distinct part of the system prompt.
|
|
539
575
|
*/
|
|
540
|
-
export type
|
|
576
|
+
export type SystemMessageSection = "identity" | "tone" | "tool_efficiency" | "environment_context" | "code_change_rules" | "guidelines" | "safety" | "tool_instructions" | "custom_instructions" | "runtime_instructions" | "last_instructions";
|
|
541
577
|
/** Section metadata for documentation and tooling. */
|
|
542
|
-
export declare const
|
|
578
|
+
export declare const SYSTEM_MESSAGE_SECTIONS: Record<SystemMessageSection, {
|
|
543
579
|
description: string;
|
|
544
580
|
}>;
|
|
545
581
|
/**
|
|
@@ -557,7 +593,7 @@ export type SectionTransformFn = (currentContent: string) => string | Promise<st
|
|
|
557
593
|
*/
|
|
558
594
|
export type SectionOverrideAction = "replace" | "remove" | "append" | "prepend" | SectionTransformFn;
|
|
559
595
|
/**
|
|
560
|
-
* Override operation for a single system
|
|
596
|
+
* Override operation for a single system message section.
|
|
561
597
|
*/
|
|
562
598
|
export interface SectionOverride {
|
|
563
599
|
/**
|
|
@@ -606,7 +642,7 @@ export interface SystemMessageCustomizeConfig {
|
|
|
606
642
|
* Unknown section IDs gracefully fall back: content-bearing overrides are appended
|
|
607
643
|
* to additional instructions, and "remove" on unknown sections is a silent no-op.
|
|
608
644
|
*/
|
|
609
|
-
sections?: Partial<Record<
|
|
645
|
+
sections?: Partial<Record<SystemMessageSection, SectionOverride>>;
|
|
610
646
|
/**
|
|
611
647
|
* Additional content appended after all sections.
|
|
612
648
|
* Equivalent to append mode's content field — provided for convenience.
|
|
@@ -621,13 +657,20 @@ export interface SystemMessageCustomizeConfig {
|
|
|
621
657
|
*/
|
|
622
658
|
export type SystemMessageConfig = SystemMessageAppendConfig | SystemMessageReplaceConfig | SystemMessageCustomizeConfig;
|
|
623
659
|
/**
|
|
624
|
-
* Permission request types from the server
|
|
660
|
+
* Permission request types from the server. This is the generated
|
|
661
|
+
* discriminated union from the runtime schema — switch on `kind` to
|
|
662
|
+
* access the variant-specific fields (e.g. shell `commands`, write
|
|
663
|
+
* `fileName`/`diff`, mcp `toolName`/`args`).
|
|
625
664
|
*/
|
|
626
|
-
export
|
|
627
|
-
|
|
628
|
-
toolCallId?: string;
|
|
629
|
-
}
|
|
665
|
+
export type { PermissionRequest } from "./generated/session-events.js";
|
|
666
|
+
import type { PermissionRequest } from "./generated/session-events.js";
|
|
630
667
|
import type { PermissionDecisionRequest } from "./generated/rpc.js";
|
|
668
|
+
/**
|
|
669
|
+
* Permission decision result returned from a {@link PermissionHandler}.
|
|
670
|
+
* The discriminated `kind` field selects the decision. Variant-specific
|
|
671
|
+
* fields (e.g. `feedback` on `{ kind: "reject" }`) come from the generated
|
|
672
|
+
* `PermissionDecisionRequest["result"]` union.
|
|
673
|
+
*/
|
|
631
674
|
export type PermissionRequestResult = PermissionDecisionRequest["result"] | {
|
|
632
675
|
kind: "no-result";
|
|
633
676
|
};
|
|
@@ -729,8 +772,9 @@ export interface BaseHookInput {
|
|
|
729
772
|
/** The runtime session ID of the session that triggered the hook.
|
|
730
773
|
* For sub-agent hooks this differs from `invocation.sessionId`. */
|
|
731
774
|
sessionId: string;
|
|
732
|
-
|
|
733
|
-
|
|
775
|
+
/** Time at which the hook event was emitted by the runtime. */
|
|
776
|
+
timestamp: Date;
|
|
777
|
+
workingDirectory: string;
|
|
734
778
|
}
|
|
735
779
|
/**
|
|
736
780
|
* Input for pre-tool-use hook
|
|
@@ -755,6 +799,34 @@ export interface PreToolUseHookOutput {
|
|
|
755
799
|
export type PreToolUseHandler = (input: PreToolUseHookInput, invocation: {
|
|
756
800
|
sessionId: string;
|
|
757
801
|
}) => Promise<PreToolUseHookOutput | void> | PreToolUseHookOutput | void;
|
|
802
|
+
/**
|
|
803
|
+
* Input for pre-MCP-tool-call hook
|
|
804
|
+
*/
|
|
805
|
+
export interface PreMcpToolCallHookInput extends BaseHookInput {
|
|
806
|
+
toolCallId?: string;
|
|
807
|
+
serverName: string;
|
|
808
|
+
toolName: string;
|
|
809
|
+
arguments: unknown;
|
|
810
|
+
_meta?: Record<string, unknown>;
|
|
811
|
+
}
|
|
812
|
+
/**
|
|
813
|
+
* Output for pre-MCP-tool-call hook
|
|
814
|
+
*/
|
|
815
|
+
export interface PreMcpToolCallHookOutput {
|
|
816
|
+
/**
|
|
817
|
+
* Hook-controlled metadata to use for the outgoing MCP request.
|
|
818
|
+
* - undefined/absent: preserve the current request `_meta`
|
|
819
|
+
* - object: use this object as request `_meta`
|
|
820
|
+
* - null: omit `_meta`
|
|
821
|
+
*/
|
|
822
|
+
metaToUse?: Record<string, unknown> | null;
|
|
823
|
+
}
|
|
824
|
+
/**
|
|
825
|
+
* Handler for pre-MCP-tool-call hook
|
|
826
|
+
*/
|
|
827
|
+
export type PreMcpToolCallHandler = (input: PreMcpToolCallHookInput, invocation: {
|
|
828
|
+
sessionId: string;
|
|
829
|
+
}) => Promise<PreMcpToolCallHookOutput | void> | PreMcpToolCallHookOutput | void;
|
|
758
830
|
/**
|
|
759
831
|
* Input for post-tool-use hook
|
|
760
832
|
*/
|
|
@@ -870,6 +942,10 @@ export interface SessionHooks {
|
|
|
870
942
|
* Called before a tool is executed
|
|
871
943
|
*/
|
|
872
944
|
onPreToolUse?: PreToolUseHandler;
|
|
945
|
+
/**
|
|
946
|
+
* Called before an MCP tool is called
|
|
947
|
+
*/
|
|
948
|
+
onPreMcpToolCall?: PreMcpToolCallHandler;
|
|
873
949
|
/**
|
|
874
950
|
* Called after a tool is executed
|
|
875
951
|
*/
|
|
@@ -896,9 +972,11 @@ export interface SessionHooks {
|
|
|
896
972
|
*/
|
|
897
973
|
interface MCPServerConfigBase {
|
|
898
974
|
/**
|
|
899
|
-
* List of tools to include from this server.
|
|
975
|
+
* List of tools to include from this server.
|
|
976
|
+
* `undefined` (the default) or `["*"]` means include all tools.
|
|
977
|
+
* `[]` means include none.
|
|
900
978
|
*/
|
|
901
|
-
tools
|
|
979
|
+
tools?: string[];
|
|
902
980
|
/**
|
|
903
981
|
* Indicates the server type: "stdio" for local/subprocess servers, "http"/"sse" for remote servers.
|
|
904
982
|
* If not specified, defaults to "stdio".
|
|
@@ -920,7 +998,10 @@ export interface MCPStdioServerConfig extends MCPServerConfigBase {
|
|
|
920
998
|
* Environment variables to pass to the server.
|
|
921
999
|
*/
|
|
922
1000
|
env?: Record<string, string>;
|
|
923
|
-
|
|
1001
|
+
/**
|
|
1002
|
+
* Working directory for the server process.
|
|
1003
|
+
*/
|
|
1004
|
+
workingDirectory?: string;
|
|
924
1005
|
}
|
|
925
1006
|
/**
|
|
926
1007
|
* Configuration for a remote MCP server (HTTP or SSE).
|
|
@@ -1031,12 +1112,21 @@ export interface InfiniteSessionConfig {
|
|
|
1031
1112
|
* Valid reasoning effort levels for models that support it.
|
|
1032
1113
|
*/
|
|
1033
1114
|
export type ReasoningEffort = "low" | "medium" | "high" | "xhigh";
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1115
|
+
/**
|
|
1116
|
+
* Stable extension identity for session participants that provide canvases.
|
|
1117
|
+
*/
|
|
1118
|
+
export interface ExtensionInfo {
|
|
1119
|
+
/** Extension namespace/source, e.g. "github-app". */
|
|
1120
|
+
source: string;
|
|
1121
|
+
/** Stable provider name within the source namespace. */
|
|
1122
|
+
name: string;
|
|
1123
|
+
}
|
|
1124
|
+
/**
|
|
1125
|
+
* Shared configuration fields used by both {@link SessionConfig} (for
|
|
1126
|
+
* creating a new session) and {@link ResumeSessionConfig} (for resuming
|
|
1127
|
+
* an existing one).
|
|
1128
|
+
*/
|
|
1129
|
+
export interface SessionConfigBase {
|
|
1040
1130
|
/**
|
|
1041
1131
|
* Client name to identify the application using the SDK.
|
|
1042
1132
|
* Included in the User-Agent header for API requests.
|
|
@@ -1076,6 +1166,34 @@ export interface SessionConfig {
|
|
|
1076
1166
|
* and must be resolved by the consumer via pending external tool request RPCs.
|
|
1077
1167
|
*/
|
|
1078
1168
|
tools?: Tool<any>[];
|
|
1169
|
+
/**
|
|
1170
|
+
* Canvases contributed by this session participant. The declaring
|
|
1171
|
+
* connection becomes the live provider for `canvas.open|focus|close|reload`
|
|
1172
|
+
* and `canvas.action.invoke` dispatches targeting each canvas's `id` for
|
|
1173
|
+
* the lifetime of the connection. Re-declaring the same id on resume
|
|
1174
|
+
* replaces the prior declaration.
|
|
1175
|
+
*/
|
|
1176
|
+
canvases?: Canvas[];
|
|
1177
|
+
/**
|
|
1178
|
+
* Renderer-side opt-in: when true, the runtime surfaces canvas agent tools
|
|
1179
|
+
* (`list_canvas_capabilities`, `open_canvas`, `invoke_canvas_action`) to
|
|
1180
|
+
* the model for this connection. Default off so SDK callers that cannot
|
|
1181
|
+
* display canvases stay clean.
|
|
1182
|
+
*/
|
|
1183
|
+
requestCanvasRenderer?: boolean;
|
|
1184
|
+
/**
|
|
1185
|
+
* Extension surface opt-in: when true, the runtime wires extension
|
|
1186
|
+
* management tools and per-extension tool dispatch onto the session for
|
|
1187
|
+
* this connection. Default off so callers that do not expose extensions
|
|
1188
|
+
* stay clean.
|
|
1189
|
+
*/
|
|
1190
|
+
requestExtensions?: boolean;
|
|
1191
|
+
/**
|
|
1192
|
+
* Stable extension identity for canvas providers on this connection. When
|
|
1193
|
+
* set, the runtime uses `${source}:${name}` as the agent-facing extension
|
|
1194
|
+
* id instead of a reconnect-specific connection id.
|
|
1195
|
+
*/
|
|
1196
|
+
extensionInfo?: ExtensionInfo;
|
|
1079
1197
|
/**
|
|
1080
1198
|
* Slash commands registered for this session.
|
|
1081
1199
|
* When the CLI has a TUI, each command appears as `/name` for the user to invoke.
|
|
@@ -1132,12 +1250,12 @@ export interface SessionConfig {
|
|
|
1132
1250
|
* Handler for exit-plan-mode requests from the agent.
|
|
1133
1251
|
* When provided, enables `exitPlanMode.request` callbacks.
|
|
1134
1252
|
*/
|
|
1135
|
-
|
|
1253
|
+
onExitPlanModeRequest?: ExitPlanModeHandler;
|
|
1136
1254
|
/**
|
|
1137
1255
|
* Handler for auto-mode-switch requests from the agent.
|
|
1138
1256
|
* When provided, enables `autoModeSwitch.request` callbacks.
|
|
1139
1257
|
*/
|
|
1140
|
-
|
|
1258
|
+
onAutoModeSwitchRequest?: AutoModeSwitchHandler;
|
|
1141
1259
|
/**
|
|
1142
1260
|
* Hook handlers for intercepting session lifecycle events.
|
|
1143
1261
|
* When provided, enables hooks callback allowing custom logic at various points.
|
|
@@ -1148,6 +1266,13 @@ export interface SessionConfig {
|
|
|
1148
1266
|
* Tool operations will be relative to this directory.
|
|
1149
1267
|
*/
|
|
1150
1268
|
workingDirectory?: string;
|
|
1269
|
+
/**
|
|
1270
|
+
* Enable streaming of assistant message and reasoning chunks.
|
|
1271
|
+
* When true, ephemeral assistant.message_delta and assistant.reasoning_delta
|
|
1272
|
+
* events are sent as the response is generated. Clients should accumulate
|
|
1273
|
+
* deltaContent values to build the full response.
|
|
1274
|
+
* @default false
|
|
1275
|
+
*/
|
|
1151
1276
|
streaming?: boolean;
|
|
1152
1277
|
/**
|
|
1153
1278
|
* Include sub-agent streaming events in the event stream. When true, streaming
|
|
@@ -1217,11 +1342,6 @@ export interface SessionConfig {
|
|
|
1217
1342
|
* - `"on"` — export to GitHub AND enable remote steering
|
|
1218
1343
|
*/
|
|
1219
1344
|
remoteSession?: RemoteSessionMode;
|
|
1220
|
-
/**
|
|
1221
|
-
* Creates a remote session in the cloud instead of a local session.
|
|
1222
|
-
* The optional repository is associated with the cloud session.
|
|
1223
|
-
*/
|
|
1224
|
-
cloud?: CloudSessionOptions;
|
|
1225
1345
|
/**
|
|
1226
1346
|
* Optional event handler that is registered on the session before the
|
|
1227
1347
|
* session.create RPC is issued. This guarantees that early events emitted
|
|
@@ -1236,18 +1356,33 @@ export interface SessionConfig {
|
|
|
1236
1356
|
* Supplies a handler for session filesystem operations. This takes effect
|
|
1237
1357
|
* only if {@link CopilotClientOptions.sessionFs} is configured.
|
|
1238
1358
|
*/
|
|
1239
|
-
|
|
1359
|
+
createSessionFsProvider?: (session: CopilotSession) => SessionFsProvider;
|
|
1240
1360
|
}
|
|
1241
1361
|
/**
|
|
1242
|
-
* Configuration for
|
|
1362
|
+
* Configuration for creating a new session via {@link CopilotClient.createSession}.
|
|
1243
1363
|
*/
|
|
1244
|
-
export
|
|
1364
|
+
export interface SessionConfig extends SessionConfigBase {
|
|
1365
|
+
/**
|
|
1366
|
+
* Optional custom session ID. If not provided, the server generates one.
|
|
1367
|
+
*/
|
|
1368
|
+
sessionId?: string;
|
|
1369
|
+
/**
|
|
1370
|
+
* Creates a remote session in the cloud instead of a local session.
|
|
1371
|
+
* The optional repository is associated with the cloud session.
|
|
1372
|
+
*/
|
|
1373
|
+
cloud?: CloudSessionOptions;
|
|
1374
|
+
}
|
|
1375
|
+
/**
|
|
1376
|
+
* Configuration for resuming an existing session via
|
|
1377
|
+
* {@link CopilotClient.resumeSession}.
|
|
1378
|
+
*/
|
|
1379
|
+
export interface ResumeSessionConfig extends SessionConfigBase {
|
|
1245
1380
|
/**
|
|
1246
1381
|
* When true, skips emitting the session.resume event.
|
|
1247
1382
|
* Useful for reconnecting to a session without triggering resume-related side effects.
|
|
1248
1383
|
* @default false
|
|
1249
1384
|
*/
|
|
1250
|
-
|
|
1385
|
+
suppressResumeEvent?: boolean;
|
|
1251
1386
|
/**
|
|
1252
1387
|
* When true, the runtime continues any tool calls or permission prompts that were
|
|
1253
1388
|
* still pending when the session was last suspended. When false (the default), the
|
|
@@ -1260,7 +1395,13 @@ export type ResumeSessionConfig = Pick<SessionConfig, "clientName" | "model" | "
|
|
|
1260
1395
|
* @default false
|
|
1261
1396
|
*/
|
|
1262
1397
|
continuePendingWork?: boolean;
|
|
1263
|
-
|
|
1398
|
+
/**
|
|
1399
|
+
* Snapshot of canvases that were already open when the session was suspended.
|
|
1400
|
+
* When provided on resume, the runtime can rehydrate canvas state so consumers
|
|
1401
|
+
* do not need to re-open canvases that were active before the previous shutdown.
|
|
1402
|
+
*/
|
|
1403
|
+
openCanvases?: OpenCanvasInstance[];
|
|
1404
|
+
}
|
|
1264
1405
|
/**
|
|
1265
1406
|
* Configuration for a custom API provider.
|
|
1266
1407
|
*/
|
|
@@ -1320,7 +1461,7 @@ export interface ProviderConfig {
|
|
|
1320
1461
|
* prompt (system message, history, tool definitions, user message) would
|
|
1321
1462
|
* exceed this limit.
|
|
1322
1463
|
*/
|
|
1323
|
-
|
|
1464
|
+
maxPromptTokens?: number;
|
|
1324
1465
|
/**
|
|
1325
1466
|
* Overrides the resolved model's default max output tokens. When hit, the
|
|
1326
1467
|
* model stops generating and returns a truncated response.
|
|
@@ -1396,16 +1537,12 @@ export type TypedSessionEventHandler<T extends SessionEventType> = (event: Sessi
|
|
|
1396
1537
|
* Event handler callback type (for all events)
|
|
1397
1538
|
*/
|
|
1398
1539
|
export type SessionEventHandler = (event: SessionEvent) => void;
|
|
1399
|
-
/**
|
|
1400
|
-
* Connection state
|
|
1401
|
-
*/
|
|
1402
|
-
export type ConnectionState = "disconnected" | "connecting" | "connected" | "error";
|
|
1403
1540
|
/**
|
|
1404
1541
|
* Working directory context for a session
|
|
1405
1542
|
*/
|
|
1406
1543
|
export interface SessionContext {
|
|
1407
1544
|
/** Working directory where the session was created */
|
|
1408
|
-
|
|
1545
|
+
workingDirectory: string;
|
|
1409
1546
|
/** Git repository root (if in a git repo) */
|
|
1410
1547
|
gitRoot?: string;
|
|
1411
1548
|
/** GitHub repository in "owner/repo" format */
|
|
@@ -1448,8 +1585,8 @@ export interface SessionFsConfig {
|
|
|
1448
1585
|
* Filter options for listing sessions
|
|
1449
1586
|
*/
|
|
1450
1587
|
export interface SessionListFilter {
|
|
1451
|
-
/** Filter by exact
|
|
1452
|
-
|
|
1588
|
+
/** Filter by exact working directory match */
|
|
1589
|
+
workingDirectory?: string;
|
|
1453
1590
|
/** Filter by git root */
|
|
1454
1591
|
gitRoot?: string;
|
|
1455
1592
|
/** Filter by repository (owner/repo format) */
|
|
@@ -1466,7 +1603,7 @@ export interface SessionMetadata {
|
|
|
1466
1603
|
modifiedTime: Date;
|
|
1467
1604
|
summary?: string;
|
|
1468
1605
|
isRemote: boolean;
|
|
1469
|
-
/** Working directory context (
|
|
1606
|
+
/** Working directory context (working directory, git info) from session creation */
|
|
1470
1607
|
context?: SessionContext;
|
|
1471
1608
|
}
|
|
1472
1609
|
/**
|
|
@@ -1551,35 +1688,68 @@ export interface ModelInfo {
|
|
|
1551
1688
|
defaultReasoningEffort?: ReasoningEffort;
|
|
1552
1689
|
}
|
|
1553
1690
|
/**
|
|
1554
|
-
* Types of session lifecycle events
|
|
1691
|
+
* Types of session lifecycle events.
|
|
1555
1692
|
*/
|
|
1556
1693
|
export type SessionLifecycleEventType = "session.created" | "session.deleted" | "session.updated" | "session.foreground" | "session.background";
|
|
1557
1694
|
/**
|
|
1558
|
-
*
|
|
1559
|
-
*
|
|
1695
|
+
* Metadata payload for session lifecycle events. Not present on
|
|
1696
|
+
* `session.deleted` events.
|
|
1560
1697
|
*/
|
|
1561
|
-
export interface
|
|
1562
|
-
/**
|
|
1563
|
-
|
|
1564
|
-
/**
|
|
1698
|
+
export interface SessionLifecycleEventMetadata {
|
|
1699
|
+
/** Time the session was created. */
|
|
1700
|
+
startTime: Date;
|
|
1701
|
+
/** Time the session was last modified. */
|
|
1702
|
+
modifiedTime: Date;
|
|
1703
|
+
/** Human-readable summary of the session, if available. */
|
|
1704
|
+
summary?: string;
|
|
1705
|
+
}
|
|
1706
|
+
/** Base shape shared by every lifecycle event variant. */
|
|
1707
|
+
interface SessionLifecycleEventBase {
|
|
1708
|
+
/** ID of the session this event relates to. */
|
|
1565
1709
|
sessionId: string;
|
|
1566
|
-
/** Session metadata (not included for deleted
|
|
1567
|
-
metadata?:
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1710
|
+
/** Session metadata (not included for `session.deleted`). */
|
|
1711
|
+
metadata?: SessionLifecycleEventMetadata;
|
|
1712
|
+
}
|
|
1713
|
+
/** Emitted when a new session is created. */
|
|
1714
|
+
export interface SessionCreatedEvent extends SessionLifecycleEventBase {
|
|
1715
|
+
type: "session.created";
|
|
1716
|
+
metadata: SessionLifecycleEventMetadata;
|
|
1572
1717
|
}
|
|
1718
|
+
/** Emitted when a session is deleted. The metadata field is omitted. */
|
|
1719
|
+
export interface SessionDeletedEvent extends SessionLifecycleEventBase {
|
|
1720
|
+
type: "session.deleted";
|
|
1721
|
+
metadata?: undefined;
|
|
1722
|
+
}
|
|
1723
|
+
/** Emitted when a session's metadata is updated. */
|
|
1724
|
+
export interface SessionUpdatedEvent extends SessionLifecycleEventBase {
|
|
1725
|
+
type: "session.updated";
|
|
1726
|
+
metadata: SessionLifecycleEventMetadata;
|
|
1727
|
+
}
|
|
1728
|
+
/** Emitted when a session is brought to the foreground (TUI+server mode). */
|
|
1729
|
+
export interface SessionForegroundEvent extends SessionLifecycleEventBase {
|
|
1730
|
+
type: "session.foreground";
|
|
1731
|
+
metadata: SessionLifecycleEventMetadata;
|
|
1732
|
+
}
|
|
1733
|
+
/** Emitted when a session is moved to the background (TUI+server mode). */
|
|
1734
|
+
export interface SessionBackgroundEvent extends SessionLifecycleEventBase {
|
|
1735
|
+
type: "session.background";
|
|
1736
|
+
metadata: SessionLifecycleEventMetadata;
|
|
1737
|
+
}
|
|
1738
|
+
/**
|
|
1739
|
+
* Discriminated union of all session lifecycle events emitted in TUI+server mode.
|
|
1740
|
+
* Switch on `type` to access the variant-specific metadata.
|
|
1741
|
+
*/
|
|
1742
|
+
export type SessionLifecycleEvent = SessionCreatedEvent | SessionDeletedEvent | SessionUpdatedEvent | SessionForegroundEvent | SessionBackgroundEvent;
|
|
1573
1743
|
/**
|
|
1574
|
-
* Handler for session lifecycle events
|
|
1744
|
+
* Handler for session lifecycle events.
|
|
1575
1745
|
*/
|
|
1576
1746
|
export type SessionLifecycleHandler = (event: SessionLifecycleEvent) => void;
|
|
1577
1747
|
/**
|
|
1578
|
-
* Typed handler for specific session lifecycle event types
|
|
1748
|
+
* Typed handler for specific session lifecycle event types.
|
|
1579
1749
|
*/
|
|
1580
|
-
export type TypedSessionLifecycleHandler<K extends SessionLifecycleEventType> = (event: SessionLifecycleEvent
|
|
1750
|
+
export type TypedSessionLifecycleHandler<K extends SessionLifecycleEventType> = (event: Extract<SessionLifecycleEvent, {
|
|
1581
1751
|
type: K;
|
|
1582
|
-
}) => void;
|
|
1752
|
+
}>) => void;
|
|
1583
1753
|
/**
|
|
1584
1754
|
* Information about the foreground session in TUI+server mode
|
|
1585
1755
|
*/
|