@github/copilot-sdk-darwin-x64 0.0.1 → 1.0.13-preview.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/animations/app-install-nudge.json.gz +0 -0
- package/animations/banner.json.gz +0 -0
- package/builtin/customize-cloud-agent/SKILL.md +254 -0
- package/builtin/discover-resources/SKILL.md +35 -0
- package/builtin/github-pr-media/SKILL.md +108 -0
- package/builtin-skills/customize-cloud-agent/SKILL.md +254 -0
- package/builtin-skills/discover-resources/SKILL.md +35 -0
- package/builtin-skills/github-pr-media/SKILL.md +108 -0
- package/copilot-sdk/canvas.d.ts +126 -0
- package/copilot-sdk/client.d.ts +478 -0
- package/copilot-sdk/copilotRequestHandler.d.ts +85 -0
- package/copilot-sdk/docs/agent-author.md +295 -0
- package/copilot-sdk/docs/examples.md +682 -0
- package/copilot-sdk/docs/extensions.md +81 -0
- package/copilot-sdk/docs/factories.md +279 -0
- package/copilot-sdk/docs/factory-patterns.md +194 -0
- package/copilot-sdk/extension.d.ts +59 -0
- package/copilot-sdk/extension.js +11399 -0
- package/copilot-sdk/factory.d.ts +301 -0
- package/copilot-sdk/ffiRuntimeHost.d.ts +35 -0
- package/copilot-sdk/generated/rpc.d.ts +24623 -0
- package/copilot-sdk/generated/session-events.d.ts +11117 -0
- package/copilot-sdk/index.d.ts +15 -0
- package/copilot-sdk/index.js +11540 -0
- package/copilot-sdk/runtimeArtifacts.d.ts +6 -0
- package/copilot-sdk/sdkProtocolVersion.d.ts +10 -0
- package/copilot-sdk/session.d.ts +331 -0
- package/copilot-sdk/sessionFsProvider.d.ts +107 -0
- package/copilot-sdk/telemetry.d.ts +14 -0
- package/copilot-sdk/toolSet.d.ts +75 -0
- package/copilot-sdk/types.d.ts +2974 -0
- package/definitions/code-review.agent.yaml +94 -0
- package/definitions/explore.agent.yaml +75 -0
- package/definitions/rem-agent.agent.yaml +22 -0
- package/definitions/research.agent.yaml +111 -0
- package/definitions/rubber-duck.agent.yaml +67 -0
- package/definitions/security-review.agent.yaml +261 -0
- package/definitions/sidekick/cloud-session-search.yaml +37 -0
- package/definitions/sidekick/github-context-memory.yaml +46 -0
- package/definitions/sidekick/github-context.yaml +44 -0
- package/definitions/sidekick/session-search.yaml +37 -0
- package/definitions/sidekick/subconscious-agent.yaml +60 -0
- package/definitions/sidekick/test-sidekick-context-changed.yaml +24 -0
- package/definitions/sidekick/test-sidekick-persistent.yaml +23 -0
- package/definitions/sidekick/test-sidekick-restart.yaml +23 -0
- package/definitions/sidekick/test-sidekick-trigger-once.yaml +22 -0
- package/definitions/task.agent.yaml +44 -0
- package/package.json +14 -11
- package/plugins/computer-use/.mcp.json +10 -0
- package/plugins/computer-use/.plugin/plugin.json +6 -0
- package/plugins/computer-use/.release-target +1 -0
- package/plugins/computer-use/Copilot Computer Use.app/Contents/CodeResources +0 -0
- package/plugins/computer-use/Copilot Computer Use.app/Contents/Info.plist +38 -0
- package/plugins/computer-use/Copilot Computer Use.app/Contents/MacOS/Copilot Computer Use +0 -0
- package/plugins/computer-use/Copilot Computer Use.app/Contents/PkgInfo +1 -0
- package/plugins/computer-use/Copilot Computer Use.app/Contents/Resources/Assets.car +0 -0
- package/plugins/computer-use/Copilot Computer Use.app/Contents/Resources/icon.icns +0 -0
- package/plugins/computer-use/Copilot Computer Use.app/Contents/_CodeSignature/CodeResources +139 -0
- package/plugins/computer-use/computer-use-mcp +0 -0
- package/prebuilds/darwin-x64/copilot-runtime +0 -0
- package/prebuilds/darwin-x64/runtime.node +0 -0
- package/preloads/extension_bootstrap.mjs +68 -0
- package/preloads/extension_sdk_resolver.mjs +34 -0
- package/ripgrep/bin/darwin-arm64/rg +0 -0
- package/ripgrep/bin/darwin-x64/rg +0 -0
- package/schemas/api.schema.json +41931 -0
- package/schemas/session-events.schema.json +20937 -0
- package/sdk/index.js +1489 -0
- package/tgrep/bin/darwin-arm64/tgrep +0 -0
- package/tgrep/bin/darwin-x64/tgrep +0 -0
- package/README.md +0 -3
|
@@ -0,0 +1,478 @@
|
|
|
1
|
+
import { createServerRpc } from "./generated/rpc.js";
|
|
2
|
+
import { CopilotSession } from "./session.js";
|
|
3
|
+
import type { CopilotClientOptions, GetAuthStatusResponse, GetStatusResponse, ModelInfo, ResumeSessionConfig, SessionConfig, SessionLifecycleEventType, SessionLifecycleHandler, SessionListFilter, SessionMetadata, TypedSessionLifecycleHandler } from "./types.js";
|
|
4
|
+
export declare class CopilotClient {
|
|
5
|
+
private cliStartTimeout;
|
|
6
|
+
private cliProcess;
|
|
7
|
+
private ffiHost;
|
|
8
|
+
private connection;
|
|
9
|
+
private messageWriter;
|
|
10
|
+
private socket;
|
|
11
|
+
private runtimePort;
|
|
12
|
+
private actualHost;
|
|
13
|
+
private state;
|
|
14
|
+
private sessions;
|
|
15
|
+
private stderrBuffer;
|
|
16
|
+
/** Resolved connection mode chosen in the constructor. */
|
|
17
|
+
private connectionConfig;
|
|
18
|
+
/** Resolved path to the runtime executable (only used for child-process kinds). */
|
|
19
|
+
private resolvedCliPath;
|
|
20
|
+
/** Resolved environment passed to the spawned runtime. */
|
|
21
|
+
private resolvedEnv;
|
|
22
|
+
private options;
|
|
23
|
+
private isExternalServer;
|
|
24
|
+
private forceStopping;
|
|
25
|
+
/** Token sent in `connect`; auto-generated when the SDK spawns its own CLI in TCP mode. */
|
|
26
|
+
private effectiveConnectionToken?;
|
|
27
|
+
private onListModels?;
|
|
28
|
+
private onGetTraceContext?;
|
|
29
|
+
private modelsCache;
|
|
30
|
+
private modelsCacheLock;
|
|
31
|
+
private sessionLifecycleHandlers;
|
|
32
|
+
private typedLifecycleHandlers;
|
|
33
|
+
private _rpc;
|
|
34
|
+
private _internalRpc;
|
|
35
|
+
private processExitPromise;
|
|
36
|
+
private processTransportError;
|
|
37
|
+
private negotiatedProtocolVersion;
|
|
38
|
+
/** Connection-level session filesystem config, set via constructor option. */
|
|
39
|
+
private sessionFsConfig;
|
|
40
|
+
private requestHandler;
|
|
41
|
+
private builtinPluginDirectories;
|
|
42
|
+
private onGitHubTelemetry?;
|
|
43
|
+
private clientGlobalHandlers;
|
|
44
|
+
private githubTokenProviders;
|
|
45
|
+
/**
|
|
46
|
+
* Typed server-scoped RPC methods.
|
|
47
|
+
* @throws Error if the client is not connected
|
|
48
|
+
*/
|
|
49
|
+
get rpc(): ReturnType<typeof createServerRpc>;
|
|
50
|
+
private logDebugTiming;
|
|
51
|
+
private logDebug;
|
|
52
|
+
/**
|
|
53
|
+
* Environment variable that overrides the transport when the caller does not set
|
|
54
|
+
* {@link CopilotClientOptions.connection}. Accepts `"inprocess"` or `"stdio"`
|
|
55
|
+
* (case-insensitive); unset preserves the default stdio transport. Any other value
|
|
56
|
+
* is an error.
|
|
57
|
+
*/
|
|
58
|
+
private static readonly DEFAULT_CONNECTION_ENV_VAR;
|
|
59
|
+
/**
|
|
60
|
+
* Resolves the default {@link RuntimeConnection} for the no-connection case,
|
|
61
|
+
* honoring {@link CopilotClient.DEFAULT_CONNECTION_ENV_VAR}.
|
|
62
|
+
*/
|
|
63
|
+
private static resolveDefaultConnection;
|
|
64
|
+
/**
|
|
65
|
+
* Creates a new CopilotClient instance.
|
|
66
|
+
*
|
|
67
|
+
* @param options - Configuration options for the client
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* // Default: spawns the bundled runtime over stdio
|
|
72
|
+
* const client = new CopilotClient();
|
|
73
|
+
*
|
|
74
|
+
* // Connect to an existing runtime
|
|
75
|
+
* const client = new CopilotClient({
|
|
76
|
+
* connection: RuntimeConnection.forUri("localhost:3000"),
|
|
77
|
+
* });
|
|
78
|
+
*
|
|
79
|
+
* // Spawn the runtime over TCP on a chosen port
|
|
80
|
+
* const client = new CopilotClient({
|
|
81
|
+
* connection: RuntimeConnection.forTcp({ port: 9001 }),
|
|
82
|
+
* });
|
|
83
|
+
*
|
|
84
|
+
* // Use a custom runtime binary
|
|
85
|
+
* const client = new CopilotClient({
|
|
86
|
+
* connection: RuntimeConnection.forStdio({ path: "/usr/local/bin/copilot" }),
|
|
87
|
+
* logLevel: "debug",
|
|
88
|
+
* });
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
constructor(options?: CopilotClientOptions);
|
|
92
|
+
private connectionExtraArgs;
|
|
93
|
+
/**
|
|
94
|
+
* Parse CLI URL into host and port
|
|
95
|
+
* Supports formats: "host:port", "http://host:port", "https://host:port", or just "port"
|
|
96
|
+
*/
|
|
97
|
+
private parseCliUrl;
|
|
98
|
+
private validateSessionFsConfig;
|
|
99
|
+
private setupSessionFs;
|
|
100
|
+
private setupClientGlobalHandlers;
|
|
101
|
+
private acquireGitHubToken;
|
|
102
|
+
private registerGitHubTokenProvider;
|
|
103
|
+
private assignGitHubTokenProvider;
|
|
104
|
+
private commitGitHubTokenProvider;
|
|
105
|
+
/**
|
|
106
|
+
* Starts the CLI server and establishes a connection.
|
|
107
|
+
*
|
|
108
|
+
* If connecting to an external server (via cliUrl), only establishes the connection.
|
|
109
|
+
* Otherwise, spawns the CLI server process and then connects.
|
|
110
|
+
*
|
|
111
|
+
* This method is called automatically the first time you create or resume a session.
|
|
112
|
+
*
|
|
113
|
+
* @returns A promise that resolves when the connection is established
|
|
114
|
+
* @throws Error if the server fails to start or the connection fails
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* const client = new CopilotClient();
|
|
119
|
+
* await client.start();
|
|
120
|
+
* // Now ready to create sessions
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
start(): Promise<void>;
|
|
124
|
+
/**
|
|
125
|
+
* Stops the CLI server and closes all active sessions.
|
|
126
|
+
*
|
|
127
|
+
* This method performs graceful cleanup:
|
|
128
|
+
* 1. Closes all active sessions (releases in-memory resources)
|
|
129
|
+
* 2. Requests runtime shutdown for SDK-owned CLI processes
|
|
130
|
+
* 3. Closes the JSON-RPC connection
|
|
131
|
+
* 4. Terminates the CLI server process (if spawned by this client)
|
|
132
|
+
*
|
|
133
|
+
* Note: session data on disk is preserved, so sessions can be resumed later.
|
|
134
|
+
* To permanently remove session data before stopping, call
|
|
135
|
+
* {@link deleteSession} for each session first.
|
|
136
|
+
*
|
|
137
|
+
* @returns A promise that resolves with an array of errors encountered during cleanup.
|
|
138
|
+
* An empty array indicates all cleanup succeeded.
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```typescript
|
|
142
|
+
* const errors = await client.stop();
|
|
143
|
+
* if (errors.length > 0) {
|
|
144
|
+
* console.error("Cleanup errors:", errors);
|
|
145
|
+
* }
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
stop(): Promise<Error[]>;
|
|
149
|
+
/**
|
|
150
|
+
* Alias for {@link stop} that lets `CopilotClient` participate in `await using`
|
|
151
|
+
* blocks for automatic cleanup.
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```typescript
|
|
155
|
+
* await using client = new CopilotClient();
|
|
156
|
+
* const session = await client.createSession({ onPermissionRequest: approveAll });
|
|
157
|
+
* await session.sendAndWait("Hello");
|
|
158
|
+
* // client.stop() is called automatically when the block exits.
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
162
|
+
/**
|
|
163
|
+
* Forcefully stops the CLI server without graceful cleanup.
|
|
164
|
+
*
|
|
165
|
+
* Use this when {@link stop} fails or takes too long. This method:
|
|
166
|
+
* - Clears all sessions immediately without destroying them
|
|
167
|
+
* - Force closes the connection
|
|
168
|
+
* - Sends SIGKILL to the CLI process (if spawned by this client)
|
|
169
|
+
*
|
|
170
|
+
* @returns A promise that resolves when the force stop is complete
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```typescript
|
|
174
|
+
* // If normal stop hangs, force stop
|
|
175
|
+
* const stopPromise = client.stop();
|
|
176
|
+
* const timeout = new Promise((_, reject) =>
|
|
177
|
+
* setTimeout(() => reject(new Error("Timeout")), 5000)
|
|
178
|
+
* );
|
|
179
|
+
*
|
|
180
|
+
* try {
|
|
181
|
+
* await Promise.race([stopPromise, timeout]);
|
|
182
|
+
* } catch {
|
|
183
|
+
* await client.forceStop();
|
|
184
|
+
* }
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
187
|
+
forceStop(): Promise<void>;
|
|
188
|
+
/** Mode-specific defaults spread under the caller's config (app values win). */
|
|
189
|
+
private configDefaultsForMode;
|
|
190
|
+
/** Mode-specific default for enableExperimentalMode. */
|
|
191
|
+
private experimentalModeForMode;
|
|
192
|
+
/**
|
|
193
|
+
* Returns the systemMessage config to use, adjusted for the current mode.
|
|
194
|
+
* In empty mode we ensure the environment_context section is removed
|
|
195
|
+
* unless the app has already taken control of it. `append` (and
|
|
196
|
+
* unspecified) mode is promoted to `customize` so we can also strip
|
|
197
|
+
* environment_context; the caller's `content` is preserved verbatim
|
|
198
|
+
* because the runtime appends it as additional instructions in both
|
|
199
|
+
* customize and append modes.
|
|
200
|
+
*/
|
|
201
|
+
private getSystemMessageConfigForMode;
|
|
202
|
+
/**
|
|
203
|
+
* Mode-specific options applied via session.options.update after create/resume.
|
|
204
|
+
*
|
|
205
|
+
* In empty mode, defaults the four overridable feature flags to safe values
|
|
206
|
+
* (caller values from `config` win). `installedPlugins=[]` is unconditional
|
|
207
|
+
* in empty mode. `includedBuiltinSkills` defaults to `[]`, but callers can
|
|
208
|
+
* explicitly allow selected runtime-bundled skills.
|
|
209
|
+
*/
|
|
210
|
+
private updateSessionOptionsForMode;
|
|
211
|
+
createSession(config: SessionConfig): Promise<CopilotSession>;
|
|
212
|
+
/**
|
|
213
|
+
* Resumes an existing conversation session by its ID.
|
|
214
|
+
*
|
|
215
|
+
* This allows you to continue a previous conversation, maintaining all
|
|
216
|
+
* conversation history. The session must have been previously created
|
|
217
|
+
* and not deleted.
|
|
218
|
+
*
|
|
219
|
+
* @param sessionId - The ID of the session to resume
|
|
220
|
+
* @param config - Optional configuration for the resumed session
|
|
221
|
+
* @returns A promise that resolves with the resumed session
|
|
222
|
+
* @throws Error if the session does not exist or the client is not connected
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* ```typescript
|
|
226
|
+
* // Resume a previous session
|
|
227
|
+
* const session = await client.resumeSession("session-123", { onPermissionRequest: approveAll });
|
|
228
|
+
*
|
|
229
|
+
* // Resume with new tools
|
|
230
|
+
* const session = await client.resumeSession("session-123", {
|
|
231
|
+
* onPermissionRequest: approveAll,
|
|
232
|
+
* tools: [myNewTool]
|
|
233
|
+
* });
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
resumeSession(sessionId: string, config: ResumeSessionConfig): Promise<CopilotSession>;
|
|
237
|
+
private resumeSessionInternal;
|
|
238
|
+
/**
|
|
239
|
+
* Sends a ping request to the server to verify connectivity.
|
|
240
|
+
*
|
|
241
|
+
* @param message - Optional message to include in the ping
|
|
242
|
+
* @returns A promise that resolves with the ping response containing the message and timestamp
|
|
243
|
+
* @throws Error if the client is not connected
|
|
244
|
+
*
|
|
245
|
+
* @example
|
|
246
|
+
* ```typescript
|
|
247
|
+
* const response = await client.ping("health check");
|
|
248
|
+
* console.log(`Server responded at ${new Date(response.timestamp)}`);
|
|
249
|
+
* ```
|
|
250
|
+
*/
|
|
251
|
+
ping(message?: string): Promise<{
|
|
252
|
+
message: string;
|
|
253
|
+
timestamp: string;
|
|
254
|
+
protocolVersion?: number;
|
|
255
|
+
}>;
|
|
256
|
+
/**
|
|
257
|
+
* Get CLI status including version and protocol information
|
|
258
|
+
*/
|
|
259
|
+
getStatus(): Promise<GetStatusResponse>;
|
|
260
|
+
/**
|
|
261
|
+
* Get current authentication status
|
|
262
|
+
*/
|
|
263
|
+
getAuthStatus(): Promise<GetAuthStatusResponse>;
|
|
264
|
+
/**
|
|
265
|
+
* List available models with their metadata.
|
|
266
|
+
*
|
|
267
|
+
* If an `onListModels` handler was provided in the client options,
|
|
268
|
+
* it is called instead of querying the CLI server.
|
|
269
|
+
*
|
|
270
|
+
* Results are cached after the first successful call to avoid rate limiting.
|
|
271
|
+
* The cache is cleared when the client disconnects.
|
|
272
|
+
*
|
|
273
|
+
* @throws Error if not connected (when no custom handler is set)
|
|
274
|
+
*/
|
|
275
|
+
listModels(): Promise<ModelInfo[]>;
|
|
276
|
+
/**
|
|
277
|
+
* Send the `connect` handshake (carrying the optional token) and verify the
|
|
278
|
+
* server's protocol version. Falls back to `ping` against legacy servers
|
|
279
|
+
* that don't implement `connect`.
|
|
280
|
+
*/
|
|
281
|
+
private verifyProtocolVersion;
|
|
282
|
+
/**
|
|
283
|
+
* Gets the ID of the most recently updated session.
|
|
284
|
+
*
|
|
285
|
+
* This is useful for resuming the last conversation when the session ID
|
|
286
|
+
* was not stored.
|
|
287
|
+
*
|
|
288
|
+
* @returns A promise that resolves with the session ID, or undefined if no sessions exist
|
|
289
|
+
* @throws Error if the client is not connected
|
|
290
|
+
*
|
|
291
|
+
* @example
|
|
292
|
+
* ```typescript
|
|
293
|
+
* const lastId = await client.getLastSessionId();
|
|
294
|
+
* if (lastId) {
|
|
295
|
+
* const session = await client.resumeSession(lastId, { onPermissionRequest: approveAll });
|
|
296
|
+
* }
|
|
297
|
+
* ```
|
|
298
|
+
*/
|
|
299
|
+
getLastSessionId(): Promise<string | undefined>;
|
|
300
|
+
/**
|
|
301
|
+
* Permanently deletes a session and all its data from disk, including
|
|
302
|
+
* conversation history, planning state, and artifacts.
|
|
303
|
+
*
|
|
304
|
+
* Unlike {@link CopilotSession.disconnect}, which only releases in-memory
|
|
305
|
+
* resources and preserves session data for later resumption, this method
|
|
306
|
+
* is irreversible. The session cannot be resumed after deletion.
|
|
307
|
+
*
|
|
308
|
+
* @param sessionId - The ID of the session to delete
|
|
309
|
+
* @returns A promise that resolves when the session is deleted
|
|
310
|
+
* @throws Error if the session does not exist or deletion fails
|
|
311
|
+
*
|
|
312
|
+
* @example
|
|
313
|
+
* ```typescript
|
|
314
|
+
* await client.deleteSession("session-123");
|
|
315
|
+
* ```
|
|
316
|
+
*/
|
|
317
|
+
deleteSession(sessionId: string): Promise<void>;
|
|
318
|
+
/**
|
|
319
|
+
* List all available sessions.
|
|
320
|
+
*
|
|
321
|
+
* @param filter - Optional filter to limit returned sessions by context fields
|
|
322
|
+
*
|
|
323
|
+
* @example
|
|
324
|
+
* // List all sessions
|
|
325
|
+
* const sessions = await client.listSessions();
|
|
326
|
+
*
|
|
327
|
+
* @example
|
|
328
|
+
* // List sessions for a specific repository
|
|
329
|
+
* const sessions = await client.listSessions({ repository: "owner/repo" });
|
|
330
|
+
*/
|
|
331
|
+
listSessions(filter?: SessionListFilter): Promise<SessionMetadata[]>;
|
|
332
|
+
/**
|
|
333
|
+
* Gets metadata for a specific session by ID.
|
|
334
|
+
*
|
|
335
|
+
* This provides an efficient O(1) lookup of a single session's metadata
|
|
336
|
+
* instead of listing all sessions. Returns undefined if the session is not found.
|
|
337
|
+
*
|
|
338
|
+
* @param sessionId - The ID of the session to look up
|
|
339
|
+
* @returns A promise that resolves with the session metadata, or undefined if not found
|
|
340
|
+
* @throws Error if the client is not connected
|
|
341
|
+
*
|
|
342
|
+
* @example
|
|
343
|
+
* ```typescript
|
|
344
|
+
* const metadata = await client.getSessionMetadata("session-123");
|
|
345
|
+
* if (metadata) {
|
|
346
|
+
* console.log(`Session started at: ${metadata.startTime}`);
|
|
347
|
+
* }
|
|
348
|
+
* ```
|
|
349
|
+
*/
|
|
350
|
+
getSessionMetadata(sessionId: string): Promise<SessionMetadata | undefined>;
|
|
351
|
+
private static toSessionMetadata;
|
|
352
|
+
/**
|
|
353
|
+
* Gets the foreground session ID in TUI+server mode.
|
|
354
|
+
*
|
|
355
|
+
* This returns the ID of the session currently displayed in the TUI.
|
|
356
|
+
* Only available when connecting to a server running in TUI+server mode (--ui-server).
|
|
357
|
+
*
|
|
358
|
+
* @returns A promise that resolves with the foreground session ID, or undefined if none
|
|
359
|
+
* @throws Error if the client is not connected
|
|
360
|
+
*
|
|
361
|
+
* @example
|
|
362
|
+
* ```typescript
|
|
363
|
+
* const sessionId = await client.getForegroundSessionId();
|
|
364
|
+
* if (sessionId) {
|
|
365
|
+
* console.log(`TUI is displaying session: ${sessionId}`);
|
|
366
|
+
* }
|
|
367
|
+
* ```
|
|
368
|
+
*/
|
|
369
|
+
getForegroundSessionId(): Promise<string | undefined>;
|
|
370
|
+
/**
|
|
371
|
+
* Sets the foreground session in TUI+server mode.
|
|
372
|
+
*
|
|
373
|
+
* This requests the TUI to switch to displaying the specified session.
|
|
374
|
+
* Only available when connecting to a server running in TUI+server mode (--ui-server).
|
|
375
|
+
*
|
|
376
|
+
* @param sessionId - The ID of the session to display in the TUI
|
|
377
|
+
* @returns A promise that resolves when the session is switched
|
|
378
|
+
* @throws Error if the client is not connected or if the operation fails
|
|
379
|
+
*
|
|
380
|
+
* @example
|
|
381
|
+
* ```typescript
|
|
382
|
+
* // Switch the TUI to display a specific session
|
|
383
|
+
* await client.setForegroundSessionId("session-123");
|
|
384
|
+
* ```
|
|
385
|
+
*/
|
|
386
|
+
setForegroundSessionId(sessionId: string): Promise<void>;
|
|
387
|
+
/**
|
|
388
|
+
* Subscribes to a specific session lifecycle event type.
|
|
389
|
+
*
|
|
390
|
+
* Lifecycle events are emitted when sessions are created, deleted, updated,
|
|
391
|
+
* or change foreground/background state (in TUI+server mode).
|
|
392
|
+
*
|
|
393
|
+
* @param eventType - The specific event type to listen for
|
|
394
|
+
* @param handler - A callback function that receives events of the specified type
|
|
395
|
+
* @returns A function that, when called, unsubscribes the handler
|
|
396
|
+
*
|
|
397
|
+
* @example
|
|
398
|
+
* ```typescript
|
|
399
|
+
* // Listen for when a session becomes foreground in TUI
|
|
400
|
+
* const unsubscribe = client.onLifecycle("session.foreground", (event) => {
|
|
401
|
+
* console.log(`Session ${event.sessionId} is now displayed in TUI`);
|
|
402
|
+
* });
|
|
403
|
+
*
|
|
404
|
+
* // Later, to stop receiving events:
|
|
405
|
+
* unsubscribe();
|
|
406
|
+
* ```
|
|
407
|
+
*/
|
|
408
|
+
onLifecycle<K extends SessionLifecycleEventType>(eventType: K, handler: TypedSessionLifecycleHandler<K>): () => void;
|
|
409
|
+
/**
|
|
410
|
+
* Subscribes to all session lifecycle events.
|
|
411
|
+
*
|
|
412
|
+
* @param handler - A callback function that receives all lifecycle events
|
|
413
|
+
* @returns A function that, when called, unsubscribes the handler
|
|
414
|
+
*
|
|
415
|
+
* @example
|
|
416
|
+
* ```typescript
|
|
417
|
+
* const unsubscribe = client.onLifecycle((event) => {
|
|
418
|
+
* switch (event.type) {
|
|
419
|
+
* case "session.foreground":
|
|
420
|
+
* console.log(`Session ${event.sessionId} is now in foreground`);
|
|
421
|
+
* break;
|
|
422
|
+
* case "session.created":
|
|
423
|
+
* console.log(`New session created: ${event.sessionId}`);
|
|
424
|
+
* break;
|
|
425
|
+
* }
|
|
426
|
+
* });
|
|
427
|
+
*
|
|
428
|
+
* // Later, to stop receiving events:
|
|
429
|
+
* unsubscribe();
|
|
430
|
+
* ```
|
|
431
|
+
*/
|
|
432
|
+
onLifecycle(handler: SessionLifecycleHandler): () => void;
|
|
433
|
+
/**
|
|
434
|
+
* Builds the environment for the spawned runtime child process (stdio/TCP): applies
|
|
435
|
+
* the auth token, connection token, `COPILOT_HOME`, keychain setting, and telemetry
|
|
436
|
+
* variables on top of the effective env. Not used by the in-process (FFI) transport,
|
|
437
|
+
* whose worker inherits the host process's ambient environment
|
|
438
|
+
* (see {@link CopilotClient.startInProcessFfi}).
|
|
439
|
+
*/
|
|
440
|
+
private buildRuntimeEnv;
|
|
441
|
+
/**
|
|
442
|
+
* Start the CLI server process
|
|
443
|
+
*/
|
|
444
|
+
private startCLIServer;
|
|
445
|
+
/**
|
|
446
|
+
* Connect to the CLI server (via socket or stdio)
|
|
447
|
+
*/
|
|
448
|
+
private connectToServer;
|
|
449
|
+
/** Starts the in-process FFI runtime with SDK-managed typed options. */
|
|
450
|
+
private startInProcessFfi;
|
|
451
|
+
/**
|
|
452
|
+
* Connect to the in-process FFI runtime host over its receive/send streams,
|
|
453
|
+
* reusing the same `vscode-jsonrpc` framing as the stdio transport.
|
|
454
|
+
*/
|
|
455
|
+
private connectViaFfi;
|
|
456
|
+
private static getNapiPrebuildsFolder;
|
|
457
|
+
private static isMusl;
|
|
458
|
+
/**
|
|
459
|
+
* Connect to child via stdio pipes
|
|
460
|
+
*/
|
|
461
|
+
private connectToChildProcessViaStdio;
|
|
462
|
+
/**
|
|
463
|
+
* Connect to parent via stdio pipes
|
|
464
|
+
*/
|
|
465
|
+
private connectToParentProcessViaStdio;
|
|
466
|
+
/**
|
|
467
|
+
* Connect to the CLI server via TCP socket
|
|
468
|
+
*/
|
|
469
|
+
private connectViaTcp;
|
|
470
|
+
private attachConnectionHandlers;
|
|
471
|
+
private handleSessionEventNotification;
|
|
472
|
+
private handleSessionLifecycleNotification;
|
|
473
|
+
private handleUserInputRequest;
|
|
474
|
+
private handleExitPlanModeRequest;
|
|
475
|
+
private handleAutoModeSwitchRequest;
|
|
476
|
+
private handleHooksInvoke;
|
|
477
|
+
private handleSystemMessageTransform;
|
|
478
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { LlmInferenceHeaders } from "./generated/rpc.js";
|
|
2
|
+
declare const kSuppressCloseOnDispose: unique symbol;
|
|
3
|
+
/**
|
|
4
|
+
* Per-request context handed to every {@link CopilotRequestHandler} hook.
|
|
5
|
+
*
|
|
6
|
+
* @experimental
|
|
7
|
+
*/
|
|
8
|
+
export interface CopilotRequestContext {
|
|
9
|
+
readonly requestId: string;
|
|
10
|
+
readonly sessionId?: string;
|
|
11
|
+
readonly agentId?: string;
|
|
12
|
+
readonly parentAgentId?: string;
|
|
13
|
+
readonly interactionType?: string;
|
|
14
|
+
readonly transport: "http" | "websocket";
|
|
15
|
+
url: string;
|
|
16
|
+
headers: LlmInferenceHeaders;
|
|
17
|
+
readonly signal: AbortSignal;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Terminal status for a callback-owned WebSocket connection.
|
|
21
|
+
*
|
|
22
|
+
* @experimental
|
|
23
|
+
*/
|
|
24
|
+
export declare class CopilotWebSocketCloseStatus {
|
|
25
|
+
readonly description?: string | undefined;
|
|
26
|
+
readonly errorCode?: string | undefined;
|
|
27
|
+
readonly error?: Error | undefined;
|
|
28
|
+
static readonly normalClosure: CopilotWebSocketCloseStatus;
|
|
29
|
+
constructor(description?: string | undefined, errorCode?: string | undefined, error?: Error | undefined);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Lower-level WebSocket handler with no upstream connection.
|
|
33
|
+
*
|
|
34
|
+
* This is the abstract base shared by all WebSocket handlers. It does not open
|
|
35
|
+
* or forward to any upstream server on its own — subclass it directly only when
|
|
36
|
+
* you want to service a fully synthetic connection yourself (e.g. answer the
|
|
37
|
+
* runtime without any real backend). For the common case of mutating and
|
|
38
|
+
* forwarding traffic to the real upstream, subclass {@link CopilotWebSocketForwarder}
|
|
39
|
+
* instead, which connects upstream and forwards by default.
|
|
40
|
+
*
|
|
41
|
+
* @experimental
|
|
42
|
+
*/
|
|
43
|
+
export declare abstract class CopilotWebSocketHandler implements AsyncDisposable {
|
|
44
|
+
#private;
|
|
45
|
+
[kSuppressCloseOnDispose]: boolean;
|
|
46
|
+
protected readonly context: CopilotRequestContext;
|
|
47
|
+
protected constructor(context: CopilotRequestContext);
|
|
48
|
+
sendResponseMessage(data: string | Uint8Array): Promise<void>;
|
|
49
|
+
close(status?: CopilotWebSocketCloseStatus): Promise<void>;
|
|
50
|
+
abstract sendRequestMessage(data: string | Uint8Array): Promise<void> | void;
|
|
51
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* WebSocket handler that connects to the real upstream and forwards traffic by
|
|
55
|
+
* default. This is the type returned by the default
|
|
56
|
+
* {@link CopilotRequestHandler.openWebSocket}.
|
|
57
|
+
*
|
|
58
|
+
* Override nothing to get full pass-through. To mutate traffic, subclass this
|
|
59
|
+
* type and override a message hook, then call `super` to keep forwarding to the
|
|
60
|
+
* upstream. (Subclassing {@link CopilotWebSocketHandler} instead would drop
|
|
61
|
+
* forwarding entirely.)
|
|
62
|
+
*
|
|
63
|
+
* @experimental
|
|
64
|
+
*/
|
|
65
|
+
export declare class CopilotWebSocketForwarder extends CopilotWebSocketHandler {
|
|
66
|
+
#private;
|
|
67
|
+
constructor(context: CopilotRequestContext);
|
|
68
|
+
sendRequestMessage(data: string | Uint8Array): void;
|
|
69
|
+
close(status?: CopilotWebSocketCloseStatus): Promise<void>;
|
|
70
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Base class for SDK consumers who want to observe or mutate the outbound
|
|
74
|
+
* model-layer requests the runtime issues (for both CAPI and BYOK providers).
|
|
75
|
+
* Subclass and override {@link sendRequest} or {@link openWebSocket}; an
|
|
76
|
+
* instance that overrides nothing is a transparent pass-through.
|
|
77
|
+
*
|
|
78
|
+
* @experimental
|
|
79
|
+
*/
|
|
80
|
+
export declare class CopilotRequestHandler {
|
|
81
|
+
#private;
|
|
82
|
+
protected sendRequest(request: Request, ctx: CopilotRequestContext): Promise<Response>;
|
|
83
|
+
protected openWebSocket(ctx: CopilotRequestContext): Promise<CopilotWebSocketHandler>;
|
|
84
|
+
}
|
|
85
|
+
export {};
|