@github/copilot-sdk 0.1.31-unstable.0 → 0.1.31
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 +14 -3
- package/dist/client.d.ts +10 -4
- package/dist/client.js +12 -6
- package/dist/generated/rpc.d.ts +21 -3
- package/dist/session.d.ts +29 -12
- package/dist/session.js +52 -18
- package/dist/types.d.ts +2 -4
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -52,10 +52,17 @@ await session.send({ prompt: "What is 2+2?" });
|
|
|
52
52
|
await done;
|
|
53
53
|
|
|
54
54
|
// Clean up
|
|
55
|
-
await session.
|
|
55
|
+
await session.disconnect();
|
|
56
56
|
await client.stop();
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
+
Sessions also support `Symbol.asyncDispose` for use with [`await using`](https://github.com/tc39/proposal-explicit-resource-management) (TypeScript 5.2+/Node.js 18.0+):
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
await using session = await client.createSession({ model: "gpt-5" });
|
|
63
|
+
// session is automatically disconnected when leaving scope
|
|
64
|
+
```
|
|
65
|
+
|
|
59
66
|
## API Reference
|
|
60
67
|
|
|
61
68
|
### CopilotClient
|
|
@@ -265,9 +272,13 @@ Abort the currently processing message in this session.
|
|
|
265
272
|
|
|
266
273
|
Get all events/messages from this session.
|
|
267
274
|
|
|
268
|
-
##### `
|
|
275
|
+
##### `disconnect(): Promise<void>`
|
|
276
|
+
|
|
277
|
+
Disconnect the session and free resources. Session data on disk is preserved for later resumption.
|
|
278
|
+
|
|
279
|
+
##### `destroy(): Promise<void>` *(deprecated)*
|
|
269
280
|
|
|
270
|
-
|
|
281
|
+
Deprecated — use `disconnect()` instead.
|
|
271
282
|
|
|
272
283
|
---
|
|
273
284
|
|
package/dist/client.d.ts
CHANGED
|
@@ -74,10 +74,14 @@ export declare class CopilotClient {
|
|
|
74
74
|
* Stops the CLI server and closes all active sessions.
|
|
75
75
|
*
|
|
76
76
|
* This method performs graceful cleanup:
|
|
77
|
-
* 1.
|
|
77
|
+
* 1. Closes all active sessions (releases in-memory resources)
|
|
78
78
|
* 2. Closes the JSON-RPC connection
|
|
79
79
|
* 3. Terminates the CLI server process (if spawned by this client)
|
|
80
80
|
*
|
|
81
|
+
* Note: session data on disk is preserved, so sessions can be resumed later.
|
|
82
|
+
* To permanently remove session data before stopping, call
|
|
83
|
+
* {@link deleteSession} for each session first.
|
|
84
|
+
*
|
|
81
85
|
* @returns A promise that resolves with an array of errors encountered during cleanup.
|
|
82
86
|
* An empty array indicates all cleanup succeeded.
|
|
83
87
|
*
|
|
@@ -242,10 +246,12 @@ export declare class CopilotClient {
|
|
|
242
246
|
*/
|
|
243
247
|
getLastSessionId(): Promise<string | undefined>;
|
|
244
248
|
/**
|
|
245
|
-
*
|
|
249
|
+
* Permanently deletes a session and all its data from disk, including
|
|
250
|
+
* conversation history, planning state, and artifacts.
|
|
246
251
|
*
|
|
247
|
-
*
|
|
248
|
-
*
|
|
252
|
+
* Unlike {@link CopilotSession.disconnect}, which only releases in-memory
|
|
253
|
+
* resources and preserves session data for later resumption, this method
|
|
254
|
+
* is irreversible. The session cannot be resumed after deletion.
|
|
249
255
|
*
|
|
250
256
|
* @param sessionId - The ID of the session to delete
|
|
251
257
|
* @returns A promise that resolves when the session is deleted
|
package/dist/client.js
CHANGED
|
@@ -188,10 +188,14 @@ class CopilotClient {
|
|
|
188
188
|
* Stops the CLI server and closes all active sessions.
|
|
189
189
|
*
|
|
190
190
|
* This method performs graceful cleanup:
|
|
191
|
-
* 1.
|
|
191
|
+
* 1. Closes all active sessions (releases in-memory resources)
|
|
192
192
|
* 2. Closes the JSON-RPC connection
|
|
193
193
|
* 3. Terminates the CLI server process (if spawned by this client)
|
|
194
194
|
*
|
|
195
|
+
* Note: session data on disk is preserved, so sessions can be resumed later.
|
|
196
|
+
* To permanently remove session data before stopping, call
|
|
197
|
+
* {@link deleteSession} for each session first.
|
|
198
|
+
*
|
|
195
199
|
* @returns A promise that resolves with an array of errors encountered during cleanup.
|
|
196
200
|
* An empty array indicates all cleanup succeeded.
|
|
197
201
|
*
|
|
@@ -210,7 +214,7 @@ class CopilotClient {
|
|
|
210
214
|
let lastError = null;
|
|
211
215
|
for (let attempt = 1; attempt <= 3; attempt++) {
|
|
212
216
|
try {
|
|
213
|
-
await session.
|
|
217
|
+
await session.disconnect();
|
|
214
218
|
lastError = null;
|
|
215
219
|
break;
|
|
216
220
|
} catch (error) {
|
|
@@ -224,7 +228,7 @@ class CopilotClient {
|
|
|
224
228
|
if (lastError) {
|
|
225
229
|
errors.push(
|
|
226
230
|
new Error(
|
|
227
|
-
`Failed to
|
|
231
|
+
`Failed to disconnect session ${sessionId} after 3 attempts: ${lastError.message}`
|
|
228
232
|
)
|
|
229
233
|
);
|
|
230
234
|
}
|
|
@@ -625,10 +629,12 @@ class CopilotClient {
|
|
|
625
629
|
return response.sessionId;
|
|
626
630
|
}
|
|
627
631
|
/**
|
|
628
|
-
*
|
|
632
|
+
* Permanently deletes a session and all its data from disk, including
|
|
633
|
+
* conversation history, planning state, and artifacts.
|
|
629
634
|
*
|
|
630
|
-
*
|
|
631
|
-
*
|
|
635
|
+
* Unlike {@link CopilotSession.disconnect}, which only releases in-memory
|
|
636
|
+
* resources and preserves session data for later resumption, this method
|
|
637
|
+
* is irreversible. The session cannot be resumed after deletion.
|
|
632
638
|
*
|
|
633
639
|
* @param sessionId - The ID of the session to delete
|
|
634
640
|
* @returns A promise that resolves when the session is deleted
|
package/dist/generated/rpc.d.ts
CHANGED
|
@@ -407,7 +407,14 @@ export interface SessionToolsHandlePendingToolCallParams {
|
|
|
407
407
|
*/
|
|
408
408
|
sessionId: string;
|
|
409
409
|
requestId: string;
|
|
410
|
-
result?: string
|
|
410
|
+
result?: string | {
|
|
411
|
+
textResultForLlm: string;
|
|
412
|
+
resultType?: string;
|
|
413
|
+
error?: string;
|
|
414
|
+
toolTelemetry?: {
|
|
415
|
+
[k: string]: unknown;
|
|
416
|
+
};
|
|
417
|
+
};
|
|
411
418
|
error?: string;
|
|
412
419
|
}
|
|
413
420
|
export interface SessionPermissionsHandlePendingPermissionRequestResult {
|
|
@@ -420,8 +427,19 @@ export interface SessionPermissionsHandlePendingPermissionRequestParams {
|
|
|
420
427
|
sessionId: string;
|
|
421
428
|
requestId: string;
|
|
422
429
|
result: {
|
|
423
|
-
kind: "approved"
|
|
424
|
-
|
|
430
|
+
kind: "approved";
|
|
431
|
+
} | {
|
|
432
|
+
kind: "denied-by-rules";
|
|
433
|
+
rules: unknown[];
|
|
434
|
+
} | {
|
|
435
|
+
kind: "denied-no-approval-rule-and-could-not-request-from-user";
|
|
436
|
+
} | {
|
|
437
|
+
kind: "denied-interactively-by-user";
|
|
438
|
+
feedback?: string;
|
|
439
|
+
} | {
|
|
440
|
+
kind: "denied-by-content-exclusion-policy";
|
|
441
|
+
path: string;
|
|
442
|
+
message: string;
|
|
425
443
|
};
|
|
426
444
|
}
|
|
427
445
|
/** Create typed server-scoped RPC methods (no session required). */
|
package/dist/session.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export type AssistantMessageEvent = Extract<SessionEvent, {
|
|
|
31
31
|
* await session.sendAndWait({ prompt: "Hello, world!" });
|
|
32
32
|
*
|
|
33
33
|
* // Clean up
|
|
34
|
-
* await session.
|
|
34
|
+
* await session.disconnect();
|
|
35
35
|
* ```
|
|
36
36
|
*/
|
|
37
37
|
export declare class CopilotSession {
|
|
@@ -72,7 +72,7 @@ export declare class CopilotSession {
|
|
|
72
72
|
*
|
|
73
73
|
* @param options - The message options including the prompt and optional attachments
|
|
74
74
|
* @returns A promise that resolves with the message ID of the response
|
|
75
|
-
* @throws Error if the session has been
|
|
75
|
+
* @throws Error if the session has been disconnected or the connection fails
|
|
76
76
|
*
|
|
77
77
|
* @example
|
|
78
78
|
* ```typescript
|
|
@@ -97,7 +97,7 @@ export declare class CopilotSession {
|
|
|
97
97
|
* @returns A promise that resolves with the final assistant message when the session becomes idle,
|
|
98
98
|
* or undefined if no assistant message was received
|
|
99
99
|
* @throws Error if the timeout is reached before the session becomes idle
|
|
100
|
-
* @throws Error if the session has been
|
|
100
|
+
* @throws Error if the session has been disconnected or the connection fails
|
|
101
101
|
*
|
|
102
102
|
* @example
|
|
103
103
|
* ```typescript
|
|
@@ -250,7 +250,7 @@ export declare class CopilotSession {
|
|
|
250
250
|
* assistant responses, tool executions, and other session events.
|
|
251
251
|
*
|
|
252
252
|
* @returns A promise that resolves with an array of all session events
|
|
253
|
-
* @throws Error if the session has been
|
|
253
|
+
* @throws Error if the session has been disconnected or the connection fails
|
|
254
254
|
*
|
|
255
255
|
* @example
|
|
256
256
|
* ```typescript
|
|
@@ -264,22 +264,39 @@ export declare class CopilotSession {
|
|
|
264
264
|
*/
|
|
265
265
|
getMessages(): Promise<SessionEvent[]>;
|
|
266
266
|
/**
|
|
267
|
-
*
|
|
267
|
+
* Disconnects this session and releases all in-memory resources (event handlers,
|
|
268
|
+
* tool handlers, permission handlers).
|
|
268
269
|
*
|
|
269
|
-
*
|
|
270
|
-
*
|
|
271
|
-
*
|
|
270
|
+
* Session state on disk (conversation history, planning state, artifacts) is
|
|
271
|
+
* preserved, so the conversation can be resumed later by calling
|
|
272
|
+
* {@link CopilotClient.resumeSession} with the session ID. To permanently
|
|
273
|
+
* remove all session data including files on disk, use
|
|
274
|
+
* {@link CopilotClient.deleteSession} instead.
|
|
272
275
|
*
|
|
273
|
-
*
|
|
276
|
+
* After calling this method, the session object can no longer be used.
|
|
277
|
+
*
|
|
278
|
+
* @returns A promise that resolves when the session is disconnected
|
|
274
279
|
* @throws Error if the connection fails
|
|
275
280
|
*
|
|
276
281
|
* @example
|
|
277
282
|
* ```typescript
|
|
278
|
-
* // Clean up when done
|
|
279
|
-
* await session.
|
|
283
|
+
* // Clean up when done — session can still be resumed later
|
|
284
|
+
* await session.disconnect();
|
|
280
285
|
* ```
|
|
281
286
|
*/
|
|
287
|
+
disconnect(): Promise<void>;
|
|
288
|
+
/**
|
|
289
|
+
* @deprecated Use {@link disconnect} instead. This method will be removed in a future release.
|
|
290
|
+
*
|
|
291
|
+
* Disconnects this session and releases all in-memory resources.
|
|
292
|
+
* Session data on disk is preserved for later resumption.
|
|
293
|
+
*
|
|
294
|
+
* @returns A promise that resolves when the session is disconnected
|
|
295
|
+
* @throws Error if the connection fails
|
|
296
|
+
*/
|
|
282
297
|
destroy(): Promise<void>;
|
|
298
|
+
/** Enables `await using session = ...` syntax for automatic cleanup. */
|
|
299
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
283
300
|
/**
|
|
284
301
|
* Aborts the currently processing message in this session.
|
|
285
302
|
*
|
|
@@ -287,7 +304,7 @@ export declare class CopilotSession {
|
|
|
287
304
|
* and can continue to be used for new messages.
|
|
288
305
|
*
|
|
289
306
|
* @returns A promise that resolves when the abort request is acknowledged
|
|
290
|
-
* @throws Error if the session has been
|
|
307
|
+
* @throws Error if the session has been disconnected or the connection fails
|
|
291
308
|
*
|
|
292
309
|
* @example
|
|
293
310
|
* ```typescript
|
package/dist/session.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ConnectionError, ResponseError } from "vscode-jsonrpc/node";
|
|
1
2
|
import { createSessionRpc } from "./generated/rpc.js";
|
|
2
3
|
class CopilotSession {
|
|
3
4
|
/**
|
|
@@ -45,7 +46,7 @@ class CopilotSession {
|
|
|
45
46
|
*
|
|
46
47
|
* @param options - The message options including the prompt and optional attachments
|
|
47
48
|
* @returns A promise that resolves with the message ID of the response
|
|
48
|
-
* @throws Error if the session has been
|
|
49
|
+
* @throws Error if the session has been disconnected or the connection fails
|
|
49
50
|
*
|
|
50
51
|
* @example
|
|
51
52
|
* ```typescript
|
|
@@ -78,7 +79,7 @@ class CopilotSession {
|
|
|
78
79
|
* @returns A promise that resolves with the final assistant message when the session becomes idle,
|
|
79
80
|
* or undefined if no assistant message was received
|
|
80
81
|
* @throws Error if the timeout is reached before the session becomes idle
|
|
81
|
-
* @throws Error if the session has been
|
|
82
|
+
* @throws Error if the session has been disconnected or the connection fails
|
|
82
83
|
*
|
|
83
84
|
* @example
|
|
84
85
|
* ```typescript
|
|
@@ -220,7 +221,13 @@ class CopilotSession {
|
|
|
220
221
|
await this.rpc.tools.handlePendingToolCall({ requestId, result });
|
|
221
222
|
} catch (error) {
|
|
222
223
|
const message = error instanceof Error ? error.message : String(error);
|
|
223
|
-
|
|
224
|
+
try {
|
|
225
|
+
await this.rpc.tools.handlePendingToolCall({ requestId, error: message });
|
|
226
|
+
} catch (rpcError) {
|
|
227
|
+
if (!(rpcError instanceof ConnectionError || rpcError instanceof ResponseError)) {
|
|
228
|
+
throw rpcError;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
224
231
|
}
|
|
225
232
|
}
|
|
226
233
|
/**
|
|
@@ -234,12 +241,18 @@ class CopilotSession {
|
|
|
234
241
|
});
|
|
235
242
|
await this.rpc.permissions.handlePendingPermissionRequest({ requestId, result });
|
|
236
243
|
} catch (_error) {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
244
|
+
try {
|
|
245
|
+
await this.rpc.permissions.handlePendingPermissionRequest({
|
|
246
|
+
requestId,
|
|
247
|
+
result: {
|
|
248
|
+
kind: "denied-no-approval-rule-and-could-not-request-from-user"
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
} catch (rpcError) {
|
|
252
|
+
if (!(rpcError instanceof ConnectionError || rpcError instanceof ResponseError)) {
|
|
253
|
+
throw rpcError;
|
|
241
254
|
}
|
|
242
|
-
}
|
|
255
|
+
}
|
|
243
256
|
}
|
|
244
257
|
}
|
|
245
258
|
/**
|
|
@@ -364,7 +377,7 @@ class CopilotSession {
|
|
|
364
377
|
* assistant responses, tool executions, and other session events.
|
|
365
378
|
*
|
|
366
379
|
* @returns A promise that resolves with an array of all session events
|
|
367
|
-
* @throws Error if the session has been
|
|
380
|
+
* @throws Error if the session has been disconnected or the connection fails
|
|
368
381
|
*
|
|
369
382
|
* @example
|
|
370
383
|
* ```typescript
|
|
@@ -383,22 +396,27 @@ class CopilotSession {
|
|
|
383
396
|
return response.events;
|
|
384
397
|
}
|
|
385
398
|
/**
|
|
386
|
-
*
|
|
399
|
+
* Disconnects this session and releases all in-memory resources (event handlers,
|
|
400
|
+
* tool handlers, permission handlers).
|
|
387
401
|
*
|
|
388
|
-
*
|
|
389
|
-
*
|
|
390
|
-
*
|
|
402
|
+
* Session state on disk (conversation history, planning state, artifacts) is
|
|
403
|
+
* preserved, so the conversation can be resumed later by calling
|
|
404
|
+
* {@link CopilotClient.resumeSession} with the session ID. To permanently
|
|
405
|
+
* remove all session data including files on disk, use
|
|
406
|
+
* {@link CopilotClient.deleteSession} instead.
|
|
391
407
|
*
|
|
392
|
-
*
|
|
408
|
+
* After calling this method, the session object can no longer be used.
|
|
409
|
+
*
|
|
410
|
+
* @returns A promise that resolves when the session is disconnected
|
|
393
411
|
* @throws Error if the connection fails
|
|
394
412
|
*
|
|
395
413
|
* @example
|
|
396
414
|
* ```typescript
|
|
397
|
-
* // Clean up when done
|
|
398
|
-
* await session.
|
|
415
|
+
* // Clean up when done — session can still be resumed later
|
|
416
|
+
* await session.disconnect();
|
|
399
417
|
* ```
|
|
400
418
|
*/
|
|
401
|
-
async
|
|
419
|
+
async disconnect() {
|
|
402
420
|
await this.connection.sendRequest("session.destroy", {
|
|
403
421
|
sessionId: this.sessionId
|
|
404
422
|
});
|
|
@@ -407,6 +425,22 @@ class CopilotSession {
|
|
|
407
425
|
this.toolHandlers.clear();
|
|
408
426
|
this.permissionHandler = void 0;
|
|
409
427
|
}
|
|
428
|
+
/**
|
|
429
|
+
* @deprecated Use {@link disconnect} instead. This method will be removed in a future release.
|
|
430
|
+
*
|
|
431
|
+
* Disconnects this session and releases all in-memory resources.
|
|
432
|
+
* Session data on disk is preserved for later resumption.
|
|
433
|
+
*
|
|
434
|
+
* @returns A promise that resolves when the session is disconnected
|
|
435
|
+
* @throws Error if the connection fails
|
|
436
|
+
*/
|
|
437
|
+
async destroy() {
|
|
438
|
+
return this.disconnect();
|
|
439
|
+
}
|
|
440
|
+
/** Enables `await using session = ...` syntax for automatic cleanup. */
|
|
441
|
+
async [Symbol.asyncDispose]() {
|
|
442
|
+
return this.disconnect();
|
|
443
|
+
}
|
|
410
444
|
/**
|
|
411
445
|
* Aborts the currently processing message in this session.
|
|
412
446
|
*
|
|
@@ -414,7 +448,7 @@ class CopilotSession {
|
|
|
414
448
|
* and can continue to be used for new messages.
|
|
415
449
|
*
|
|
416
450
|
* @returns A promise that resolves when the abort request is acknowledged
|
|
417
|
-
* @throws Error if the session has been
|
|
451
|
+
* @throws Error if the session has been disconnected or the connection fails
|
|
418
452
|
*
|
|
419
453
|
* @example
|
|
420
454
|
* ```typescript
|
package/dist/types.d.ts
CHANGED
|
@@ -185,10 +185,8 @@ export interface PermissionRequest {
|
|
|
185
185
|
toolCallId?: string;
|
|
186
186
|
[key: string]: unknown;
|
|
187
187
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
rules?: unknown[];
|
|
191
|
-
}
|
|
188
|
+
import type { SessionPermissionsHandlePendingPermissionRequestParams } from "./generated/rpc.js";
|
|
189
|
+
export type PermissionRequestResult = SessionPermissionsHandlePendingPermissionRequestParams["result"];
|
|
192
190
|
export type PermissionHandler = (request: PermissionRequest, invocation: {
|
|
193
191
|
sessionId: string;
|
|
194
192
|
}) => Promise<PermissionRequestResult> | PermissionRequestResult;
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"type": "git",
|
|
5
5
|
"url": "https://github.com/github/copilot-sdk.git"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.1.31
|
|
7
|
+
"version": "0.1.31",
|
|
8
8
|
"description": "TypeScript SDK for programmatic control of GitHub Copilot CLI via JSON-RPC",
|
|
9
9
|
"main": "./dist/index.js",
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"author": "GitHub",
|
|
45
45
|
"license": "MIT",
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@github/copilot": "^
|
|
47
|
+
"@github/copilot": "^1.0.2",
|
|
48
48
|
"vscode-jsonrpc": "^8.2.1",
|
|
49
49
|
"zod": "^4.3.6"
|
|
50
50
|
},
|