@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/client.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createServerRpc } from "./generated/rpc.js";
|
|
2
2
|
import { CopilotSession } from "./session.js";
|
|
3
|
-
import type {
|
|
3
|
+
import type { CopilotClientOptions, GetAuthStatusResponse, GetStatusResponse, ModelInfo, ResumeSessionConfig, SessionConfig, SessionLifecycleEventType, SessionLifecycleHandler, SessionListFilter, SessionMetadata, TypedSessionLifecycleHandler } from "./types.js";
|
|
4
4
|
/**
|
|
5
5
|
* Main client for interacting with the Copilot CLI.
|
|
6
6
|
*
|
|
@@ -16,7 +16,7 @@ import type { ConnectionState, CopilotClientOptions, GetAuthStatusResponse, GetS
|
|
|
16
16
|
* const client = new CopilotClient();
|
|
17
17
|
*
|
|
18
18
|
* // Or connect to an existing server
|
|
19
|
-
* const client = new CopilotClient({
|
|
19
|
+
* const client = new CopilotClient({ connection: RuntimeConnection.forUri("localhost:3000") });
|
|
20
20
|
*
|
|
21
21
|
* // Create a session
|
|
22
22
|
* const session = await client.createSession({ onPermissionRequest: approveAll, model: "gpt-4" });
|
|
@@ -39,11 +39,17 @@ export declare class CopilotClient {
|
|
|
39
39
|
private cliProcess;
|
|
40
40
|
private connection;
|
|
41
41
|
private socket;
|
|
42
|
-
private
|
|
42
|
+
private runtimePort;
|
|
43
43
|
private actualHost;
|
|
44
44
|
private state;
|
|
45
45
|
private sessions;
|
|
46
46
|
private stderrBuffer;
|
|
47
|
+
/** Resolved connection mode chosen in the constructor. */
|
|
48
|
+
private connectionConfig;
|
|
49
|
+
/** Resolved path to the runtime executable (only used for child-process kinds). */
|
|
50
|
+
private resolvedCliPath;
|
|
51
|
+
/** Resolved environment passed to the spawned runtime. */
|
|
52
|
+
private resolvedEnv;
|
|
47
53
|
private options;
|
|
48
54
|
private isExternalServer;
|
|
49
55
|
private forceStopping;
|
|
@@ -66,33 +72,35 @@ export declare class CopilotClient {
|
|
|
66
72
|
* @throws Error if the client is not connected
|
|
67
73
|
*/
|
|
68
74
|
get rpc(): ReturnType<typeof createServerRpc>;
|
|
69
|
-
/**
|
|
70
|
-
* Internal RPC surface (e.g. handshake helpers). Not part of the public API.
|
|
71
|
-
* @internal
|
|
72
|
-
*/
|
|
73
|
-
private get internalRpc();
|
|
74
75
|
/**
|
|
75
76
|
* Creates a new CopilotClient instance.
|
|
76
77
|
*
|
|
77
78
|
* @param options - Configuration options for the client
|
|
78
|
-
* @throws Error if mutually exclusive options are provided (e.g., cliUrl with useStdio or cliPath)
|
|
79
79
|
*
|
|
80
80
|
* @example
|
|
81
81
|
* ```typescript
|
|
82
|
-
* // Default
|
|
82
|
+
* // Default: spawns the bundled runtime over stdio
|
|
83
83
|
* const client = new CopilotClient();
|
|
84
84
|
*
|
|
85
|
-
* // Connect to an existing
|
|
86
|
-
* const client = new CopilotClient({
|
|
85
|
+
* // Connect to an existing runtime
|
|
86
|
+
* const client = new CopilotClient({
|
|
87
|
+
* connection: RuntimeConnection.forUri("localhost:3000"),
|
|
88
|
+
* });
|
|
89
|
+
*
|
|
90
|
+
* // Spawn the runtime over TCP on a chosen port
|
|
91
|
+
* const client = new CopilotClient({
|
|
92
|
+
* connection: RuntimeConnection.forTcp({ port: 9001 }),
|
|
93
|
+
* });
|
|
87
94
|
*
|
|
88
|
-
* //
|
|
95
|
+
* // Use a custom runtime binary
|
|
89
96
|
* const client = new CopilotClient({
|
|
90
|
-
*
|
|
91
|
-
* logLevel: "debug"
|
|
97
|
+
* connection: RuntimeConnection.forStdio({ path: "/usr/local/bin/copilot" }),
|
|
98
|
+
* logLevel: "debug",
|
|
92
99
|
* });
|
|
93
100
|
* ```
|
|
94
101
|
*/
|
|
95
102
|
constructor(options?: CopilotClientOptions);
|
|
103
|
+
private connectionExtraArgs;
|
|
96
104
|
/**
|
|
97
105
|
* Parse CLI URL into host and port
|
|
98
106
|
* Supports formats: "host:port", "http://host:port", "https://host:port", or just "port"
|
|
@@ -106,14 +114,14 @@ export declare class CopilotClient {
|
|
|
106
114
|
* If connecting to an external server (via cliUrl), only establishes the connection.
|
|
107
115
|
* Otherwise, spawns the CLI server process and then connects.
|
|
108
116
|
*
|
|
109
|
-
* This method is called automatically
|
|
117
|
+
* This method is called automatically the first time you create or resume a session.
|
|
110
118
|
*
|
|
111
119
|
* @returns A promise that resolves when the connection is established
|
|
112
120
|
* @throws Error if the server fails to start or the connection fails
|
|
113
121
|
*
|
|
114
122
|
* @example
|
|
115
123
|
* ```typescript
|
|
116
|
-
* const client = new CopilotClient(
|
|
124
|
+
* const client = new CopilotClient();
|
|
117
125
|
* await client.start();
|
|
118
126
|
* // Now ready to create sessions
|
|
119
127
|
* ```
|
|
@@ -143,6 +151,19 @@ export declare class CopilotClient {
|
|
|
143
151
|
* ```
|
|
144
152
|
*/
|
|
145
153
|
stop(): Promise<Error[]>;
|
|
154
|
+
/**
|
|
155
|
+
* Alias for {@link stop} that lets `CopilotClient` participate in `await using`
|
|
156
|
+
* blocks for automatic cleanup.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```typescript
|
|
160
|
+
* await using client = new CopilotClient();
|
|
161
|
+
* const session = await client.createSession({ onPermissionRequest: approveAll });
|
|
162
|
+
* await session.sendAndWait("Hello");
|
|
163
|
+
* // client.stop() is called automatically when the block exits.
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
146
167
|
/**
|
|
147
168
|
* Forcefully stops the CLI server without graceful cleanup.
|
|
148
169
|
*
|
|
@@ -173,12 +194,11 @@ export declare class CopilotClient {
|
|
|
173
194
|
* Creates a new conversation session with the Copilot CLI.
|
|
174
195
|
*
|
|
175
196
|
* Sessions maintain conversation state, handle events, and manage tool execution.
|
|
176
|
-
* If the client is not connected
|
|
177
|
-
* start the connection.
|
|
197
|
+
* If the client is not connected, this method automatically starts the connection.
|
|
178
198
|
*
|
|
179
199
|
* @param config - Optional configuration for the session
|
|
180
200
|
* @returns A promise that resolves with the created session
|
|
181
|
-
* @throws Error if the client
|
|
201
|
+
* @throws Error if the client fails to start
|
|
182
202
|
*
|
|
183
203
|
* @example
|
|
184
204
|
* ```typescript
|
|
@@ -224,19 +244,6 @@ export declare class CopilotClient {
|
|
|
224
244
|
* ```
|
|
225
245
|
*/
|
|
226
246
|
resumeSession(sessionId: string, config: ResumeSessionConfig): Promise<CopilotSession>;
|
|
227
|
-
/**
|
|
228
|
-
* Gets the current connection state of the client.
|
|
229
|
-
*
|
|
230
|
-
* @returns The current connection state: "disconnected", "connecting", "connected", or "error"
|
|
231
|
-
*
|
|
232
|
-
* @example
|
|
233
|
-
* ```typescript
|
|
234
|
-
* if (client.getState() === "connected") {
|
|
235
|
-
* const session = await client.createSession({ onPermissionRequest: approveAll });
|
|
236
|
-
* }
|
|
237
|
-
* ```
|
|
238
|
-
*/
|
|
239
|
-
getState(): ConnectionState;
|
|
240
247
|
/**
|
|
241
248
|
* Sends a ping request to the server to verify connectivity.
|
|
242
249
|
*
|
|
@@ -399,7 +406,7 @@ export declare class CopilotClient {
|
|
|
399
406
|
* @example
|
|
400
407
|
* ```typescript
|
|
401
408
|
* // Listen for when a session becomes foreground in TUI
|
|
402
|
-
* const unsubscribe = client.
|
|
409
|
+
* const unsubscribe = client.onLifecycle("session.foreground", (event) => {
|
|
403
410
|
* console.log(`Session ${event.sessionId} is now displayed in TUI`);
|
|
404
411
|
* });
|
|
405
412
|
*
|
|
@@ -407,7 +414,7 @@ export declare class CopilotClient {
|
|
|
407
414
|
* unsubscribe();
|
|
408
415
|
* ```
|
|
409
416
|
*/
|
|
410
|
-
|
|
417
|
+
onLifecycle<K extends SessionLifecycleEventType>(eventType: K, handler: TypedSessionLifecycleHandler<K>): () => void;
|
|
411
418
|
/**
|
|
412
419
|
* Subscribes to all session lifecycle events.
|
|
413
420
|
*
|
|
@@ -416,7 +423,7 @@ export declare class CopilotClient {
|
|
|
416
423
|
*
|
|
417
424
|
* @example
|
|
418
425
|
* ```typescript
|
|
419
|
-
* const unsubscribe = client.
|
|
426
|
+
* const unsubscribe = client.onLifecycle((event) => {
|
|
420
427
|
* switch (event.type) {
|
|
421
428
|
* case "session.foreground":
|
|
422
429
|
* console.log(`Session ${event.sessionId} is now in foreground`);
|
|
@@ -431,7 +438,7 @@ export declare class CopilotClient {
|
|
|
431
438
|
* unsubscribe();
|
|
432
439
|
* ```
|
|
433
440
|
*/
|
|
434
|
-
|
|
441
|
+
onLifecycle(handler: SessionLifecycleHandler): () => void;
|
|
435
442
|
/**
|
|
436
443
|
* Start the CLI server process
|
|
437
444
|
*/
|
|
@@ -460,16 +467,6 @@ export declare class CopilotClient {
|
|
|
460
467
|
private handleAutoModeSwitchRequest;
|
|
461
468
|
private handleHooksInvoke;
|
|
462
469
|
private handleSystemMessageTransform;
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
* Looks up the session and tool handler, executes it, and returns the result
|
|
466
|
-
* in the v2 response format.
|
|
467
|
-
*/
|
|
468
|
-
private handleToolCallRequestV2;
|
|
469
|
-
/**
|
|
470
|
-
* Handles a v2-style permission.request RPC request from the server.
|
|
471
|
-
*/
|
|
472
|
-
private handlePermissionRequestV2;
|
|
473
|
-
private normalizeToolResultV2;
|
|
474
|
-
private isToolResultObject;
|
|
470
|
+
private handleCanvasProviderRequest;
|
|
471
|
+
private handleCanvasActionInvokeRequest;
|
|
475
472
|
}
|