@github/copilot-sdk 0.1.20 → 0.1.21
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 +44 -8
- package/dist/client.d.ts +92 -2
- package/dist/client.js +126 -5
- package/dist/generated/session-events.d.ts +55 -2
- package/dist/index.d.ts +1 -1
- package/dist/types.d.ts +56 -1
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -86,8 +86,9 @@ Create a new conversation session.
|
|
|
86
86
|
|
|
87
87
|
**Config:**
|
|
88
88
|
|
|
89
|
-
- `sessionId?: string` - Custom session ID
|
|
89
|
+
- `sessionId?: string` - Custom session ID.
|
|
90
90
|
- `model?: string` - Model to use ("gpt-5", "claude-sonnet-4.5", etc.). **Required when using custom provider.**
|
|
91
|
+
- `reasoningEffort?: "low" | "medium" | "high" | "xhigh"` - Reasoning effort level for models that support it. Use `listModels()` to check which models support this option.
|
|
91
92
|
- `tools?: Tool[]` - Custom tools exposed to the CLI
|
|
92
93
|
- `systemMessage?: SystemMessageConfig` - System message customization (see below)
|
|
93
94
|
- `infiniteSessions?: InfiniteSessionConfig` - Configure automatic context compaction (see below)
|
|
@@ -115,6 +116,41 @@ List all available sessions.
|
|
|
115
116
|
|
|
116
117
|
Delete a session and its data from disk.
|
|
117
118
|
|
|
119
|
+
##### `getForegroundSessionId(): Promise<string | undefined>`
|
|
120
|
+
|
|
121
|
+
Get the ID of the session currently displayed in the TUI. Only available when connecting to a server running in TUI+server mode (`--ui-server`).
|
|
122
|
+
|
|
123
|
+
##### `setForegroundSessionId(sessionId: string): Promise<void>`
|
|
124
|
+
|
|
125
|
+
Request the TUI to switch to displaying the specified session. Only available in TUI+server mode.
|
|
126
|
+
|
|
127
|
+
##### `on(eventType: SessionLifecycleEventType, handler): () => void`
|
|
128
|
+
|
|
129
|
+
Subscribe to a specific session lifecycle event type. Returns an unsubscribe function.
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
const unsubscribe = client.on("session.foreground", (event) => {
|
|
133
|
+
console.log(`Session ${event.sessionId} is now in foreground`);
|
|
134
|
+
});
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
##### `on(handler: SessionLifecycleHandler): () => void`
|
|
138
|
+
|
|
139
|
+
Subscribe to all session lifecycle events. Returns an unsubscribe function.
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
const unsubscribe = client.on((event) => {
|
|
143
|
+
console.log(`${event.type}: ${event.sessionId}`);
|
|
144
|
+
});
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
**Lifecycle Event Types:**
|
|
148
|
+
- `session.created` - A new session was created
|
|
149
|
+
- `session.deleted` - A session was deleted
|
|
150
|
+
- `session.updated` - A session was updated (e.g., new messages)
|
|
151
|
+
- `session.foreground` - A session became the foreground session in TUI
|
|
152
|
+
- `session.background` - A session is no longer the foreground session
|
|
153
|
+
|
|
118
154
|
---
|
|
119
155
|
|
|
120
156
|
### CopilotSession
|
|
@@ -511,12 +547,12 @@ const session = await client.createSession({
|
|
|
511
547
|
// request.question - The question to ask
|
|
512
548
|
// request.choices - Optional array of choices for multiple choice
|
|
513
549
|
// request.allowFreeform - Whether freeform input is allowed (default: true)
|
|
514
|
-
|
|
550
|
+
|
|
515
551
|
console.log(`Agent asks: ${request.question}`);
|
|
516
552
|
if (request.choices) {
|
|
517
553
|
console.log(`Choices: ${request.choices.join(", ")}`);
|
|
518
554
|
}
|
|
519
|
-
|
|
555
|
+
|
|
520
556
|
// Return the user's response
|
|
521
557
|
return {
|
|
522
558
|
answer: "User's answer here",
|
|
@@ -544,7 +580,7 @@ const session = await client.createSession({
|
|
|
544
580
|
additionalContext: "Extra context for the model",
|
|
545
581
|
};
|
|
546
582
|
},
|
|
547
|
-
|
|
583
|
+
|
|
548
584
|
// Called after each tool execution
|
|
549
585
|
onPostToolUse: async (input, invocation) => {
|
|
550
586
|
console.log(`Tool ${input.toolName} completed`);
|
|
@@ -553,7 +589,7 @@ const session = await client.createSession({
|
|
|
553
589
|
additionalContext: "Post-execution notes",
|
|
554
590
|
};
|
|
555
591
|
},
|
|
556
|
-
|
|
592
|
+
|
|
557
593
|
// Called when user submits a prompt
|
|
558
594
|
onUserPromptSubmitted: async (input, invocation) => {
|
|
559
595
|
console.log(`User prompt: ${input.prompt}`);
|
|
@@ -561,7 +597,7 @@ const session = await client.createSession({
|
|
|
561
597
|
modifiedPrompt: input.prompt, // Optionally modify the prompt
|
|
562
598
|
};
|
|
563
599
|
},
|
|
564
|
-
|
|
600
|
+
|
|
565
601
|
// Called when session starts
|
|
566
602
|
onSessionStart: async (input, invocation) => {
|
|
567
603
|
console.log(`Session started from: ${input.source}`); // "startup", "resume", "new"
|
|
@@ -569,12 +605,12 @@ const session = await client.createSession({
|
|
|
569
605
|
additionalContext: "Session initialization context",
|
|
570
606
|
};
|
|
571
607
|
},
|
|
572
|
-
|
|
608
|
+
|
|
573
609
|
// Called when session ends
|
|
574
610
|
onSessionEnd: async (input, invocation) => {
|
|
575
611
|
console.log(`Session ended: ${input.reason}`);
|
|
576
612
|
},
|
|
577
|
-
|
|
613
|
+
|
|
578
614
|
// Called when an error occurs
|
|
579
615
|
onErrorOccurred: async (input, invocation) => {
|
|
580
616
|
console.error(`Error in ${input.errorContext}: ${input.error}`);
|
package/dist/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CopilotSession } from "./session.js";
|
|
2
|
-
import type { ConnectionState, CopilotClientOptions, GetAuthStatusResponse, GetStatusResponse, ModelInfo, ResumeSessionConfig, SessionConfig, SessionMetadata } from "./types.js";
|
|
2
|
+
import type { ConnectionState, CopilotClientOptions, GetAuthStatusResponse, GetStatusResponse, ModelInfo, ResumeSessionConfig, SessionConfig, SessionLifecycleEventType, SessionLifecycleHandler, SessionMetadata, TypedSessionLifecycleHandler } from "./types.js";
|
|
3
3
|
/**
|
|
4
4
|
* Main client for interacting with the Copilot CLI.
|
|
5
5
|
*
|
|
@@ -44,6 +44,10 @@ export declare class CopilotClient {
|
|
|
44
44
|
private options;
|
|
45
45
|
private isExternalServer;
|
|
46
46
|
private forceStopping;
|
|
47
|
+
private modelsCache;
|
|
48
|
+
private modelsCacheLock;
|
|
49
|
+
private sessionLifecycleHandlers;
|
|
50
|
+
private typedLifecycleHandlers;
|
|
47
51
|
/**
|
|
48
52
|
* Creates a new CopilotClient instance.
|
|
49
53
|
*
|
|
@@ -229,7 +233,11 @@ export declare class CopilotClient {
|
|
|
229
233
|
*/
|
|
230
234
|
getAuthStatus(): Promise<GetAuthStatusResponse>;
|
|
231
235
|
/**
|
|
232
|
-
* List available models with their metadata
|
|
236
|
+
* List available models with their metadata.
|
|
237
|
+
*
|
|
238
|
+
* Results are cached after the first successful call to avoid rate limiting.
|
|
239
|
+
* The cache is cleared when the client disconnects.
|
|
240
|
+
*
|
|
233
241
|
* @throws Error if not authenticated
|
|
234
242
|
*/
|
|
235
243
|
listModels(): Promise<ModelInfo[]>;
|
|
@@ -288,6 +296,87 @@ export declare class CopilotClient {
|
|
|
288
296
|
* ```
|
|
289
297
|
*/
|
|
290
298
|
listSessions(): Promise<SessionMetadata[]>;
|
|
299
|
+
/**
|
|
300
|
+
* Gets the foreground session ID in TUI+server mode.
|
|
301
|
+
*
|
|
302
|
+
* This returns the ID of the session currently displayed in the TUI.
|
|
303
|
+
* Only available when connecting to a server running in TUI+server mode (--ui-server).
|
|
304
|
+
*
|
|
305
|
+
* @returns A promise that resolves with the foreground session ID, or undefined if none
|
|
306
|
+
* @throws Error if the client is not connected
|
|
307
|
+
*
|
|
308
|
+
* @example
|
|
309
|
+
* ```typescript
|
|
310
|
+
* const sessionId = await client.getForegroundSessionId();
|
|
311
|
+
* if (sessionId) {
|
|
312
|
+
* console.log(`TUI is displaying session: ${sessionId}`);
|
|
313
|
+
* }
|
|
314
|
+
* ```
|
|
315
|
+
*/
|
|
316
|
+
getForegroundSessionId(): Promise<string | undefined>;
|
|
317
|
+
/**
|
|
318
|
+
* Sets the foreground session in TUI+server mode.
|
|
319
|
+
*
|
|
320
|
+
* This requests the TUI to switch to displaying the specified session.
|
|
321
|
+
* Only available when connecting to a server running in TUI+server mode (--ui-server).
|
|
322
|
+
*
|
|
323
|
+
* @param sessionId - The ID of the session to display in the TUI
|
|
324
|
+
* @returns A promise that resolves when the session is switched
|
|
325
|
+
* @throws Error if the client is not connected or if the operation fails
|
|
326
|
+
*
|
|
327
|
+
* @example
|
|
328
|
+
* ```typescript
|
|
329
|
+
* // Switch the TUI to display a specific session
|
|
330
|
+
* await client.setForegroundSessionId("session-123");
|
|
331
|
+
* ```
|
|
332
|
+
*/
|
|
333
|
+
setForegroundSessionId(sessionId: string): Promise<void>;
|
|
334
|
+
/**
|
|
335
|
+
* Subscribes to a specific session lifecycle event type.
|
|
336
|
+
*
|
|
337
|
+
* Lifecycle events are emitted when sessions are created, deleted, updated,
|
|
338
|
+
* or change foreground/background state (in TUI+server mode).
|
|
339
|
+
*
|
|
340
|
+
* @param eventType - The specific event type to listen for
|
|
341
|
+
* @param handler - A callback function that receives events of the specified type
|
|
342
|
+
* @returns A function that, when called, unsubscribes the handler
|
|
343
|
+
*
|
|
344
|
+
* @example
|
|
345
|
+
* ```typescript
|
|
346
|
+
* // Listen for when a session becomes foreground in TUI
|
|
347
|
+
* const unsubscribe = client.on("session.foreground", (event) => {
|
|
348
|
+
* console.log(`Session ${event.sessionId} is now displayed in TUI`);
|
|
349
|
+
* });
|
|
350
|
+
*
|
|
351
|
+
* // Later, to stop receiving events:
|
|
352
|
+
* unsubscribe();
|
|
353
|
+
* ```
|
|
354
|
+
*/
|
|
355
|
+
on<K extends SessionLifecycleEventType>(eventType: K, handler: TypedSessionLifecycleHandler<K>): () => void;
|
|
356
|
+
/**
|
|
357
|
+
* Subscribes to all session lifecycle events.
|
|
358
|
+
*
|
|
359
|
+
* @param handler - A callback function that receives all lifecycle events
|
|
360
|
+
* @returns A function that, when called, unsubscribes the handler
|
|
361
|
+
*
|
|
362
|
+
* @example
|
|
363
|
+
* ```typescript
|
|
364
|
+
* const unsubscribe = client.on((event) => {
|
|
365
|
+
* switch (event.type) {
|
|
366
|
+
* case "session.foreground":
|
|
367
|
+
* console.log(`Session ${event.sessionId} is now in foreground`);
|
|
368
|
+
* break;
|
|
369
|
+
* case "session.created":
|
|
370
|
+
* console.log(`New session created: ${event.sessionId}`);
|
|
371
|
+
* break;
|
|
372
|
+
* }
|
|
373
|
+
* });
|
|
374
|
+
*
|
|
375
|
+
* // Later, to stop receiving events:
|
|
376
|
+
* unsubscribe();
|
|
377
|
+
* ```
|
|
378
|
+
*/
|
|
379
|
+
on(handler: SessionLifecycleHandler): () => void;
|
|
291
380
|
/**
|
|
292
381
|
* Start the CLI server process
|
|
293
382
|
*/
|
|
@@ -306,6 +395,7 @@ export declare class CopilotClient {
|
|
|
306
395
|
private connectViaTcp;
|
|
307
396
|
private attachConnectionHandlers;
|
|
308
397
|
private handleSessionEventNotification;
|
|
398
|
+
private handleSessionLifecycleNotification;
|
|
309
399
|
private handleToolCallRequest;
|
|
310
400
|
private executeToolCall;
|
|
311
401
|
private handlePermissionRequest;
|
package/dist/client.js
CHANGED
|
@@ -28,6 +28,10 @@ class CopilotClient {
|
|
|
28
28
|
options;
|
|
29
29
|
isExternalServer = false;
|
|
30
30
|
forceStopping = false;
|
|
31
|
+
modelsCache = null;
|
|
32
|
+
modelsCacheLock = Promise.resolve();
|
|
33
|
+
sessionLifecycleHandlers = /* @__PURE__ */ new Set();
|
|
34
|
+
typedLifecycleHandlers = /* @__PURE__ */ new Map();
|
|
31
35
|
/**
|
|
32
36
|
* Creates a new CopilotClient instance.
|
|
33
37
|
*
|
|
@@ -196,6 +200,7 @@ class CopilotClient {
|
|
|
196
200
|
}
|
|
197
201
|
this.connection = null;
|
|
198
202
|
}
|
|
203
|
+
this.modelsCache = null;
|
|
199
204
|
if (this.socket) {
|
|
200
205
|
try {
|
|
201
206
|
this.socket.end();
|
|
@@ -259,6 +264,7 @@ class CopilotClient {
|
|
|
259
264
|
}
|
|
260
265
|
this.connection = null;
|
|
261
266
|
}
|
|
267
|
+
this.modelsCache = null;
|
|
262
268
|
if (this.socket) {
|
|
263
269
|
try {
|
|
264
270
|
this.socket.destroy();
|
|
@@ -315,6 +321,7 @@ class CopilotClient {
|
|
|
315
321
|
const response = await this.connection.sendRequest("session.create", {
|
|
316
322
|
model: config.model,
|
|
317
323
|
sessionId: config.sessionId,
|
|
324
|
+
reasoningEffort: config.reasoningEffort,
|
|
318
325
|
tools: config.tools?.map((tool) => ({
|
|
319
326
|
name: tool.name,
|
|
320
327
|
description: tool.description,
|
|
@@ -384,6 +391,7 @@ class CopilotClient {
|
|
|
384
391
|
}
|
|
385
392
|
const response = await this.connection.sendRequest("session.resume", {
|
|
386
393
|
sessionId,
|
|
394
|
+
reasoningEffort: config.reasoningEffort,
|
|
387
395
|
tools: config.tools?.map((tool) => ({
|
|
388
396
|
name: tool.name,
|
|
389
397
|
description: tool.description,
|
|
@@ -472,16 +480,34 @@ class CopilotClient {
|
|
|
472
480
|
return result;
|
|
473
481
|
}
|
|
474
482
|
/**
|
|
475
|
-
* List available models with their metadata
|
|
483
|
+
* List available models with their metadata.
|
|
484
|
+
*
|
|
485
|
+
* Results are cached after the first successful call to avoid rate limiting.
|
|
486
|
+
* The cache is cleared when the client disconnects.
|
|
487
|
+
*
|
|
476
488
|
* @throws Error if not authenticated
|
|
477
489
|
*/
|
|
478
490
|
async listModels() {
|
|
479
491
|
if (!this.connection) {
|
|
480
492
|
throw new Error("Client not connected");
|
|
481
493
|
}
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
494
|
+
await this.modelsCacheLock;
|
|
495
|
+
let resolveLock;
|
|
496
|
+
this.modelsCacheLock = new Promise((resolve) => {
|
|
497
|
+
resolveLock = resolve;
|
|
498
|
+
});
|
|
499
|
+
try {
|
|
500
|
+
if (this.modelsCache !== null) {
|
|
501
|
+
return [...this.modelsCache];
|
|
502
|
+
}
|
|
503
|
+
const result = await this.connection.sendRequest("models.list", {});
|
|
504
|
+
const response = result;
|
|
505
|
+
const models = response.models;
|
|
506
|
+
this.modelsCache = models;
|
|
507
|
+
return [...models];
|
|
508
|
+
} finally {
|
|
509
|
+
resolveLock();
|
|
510
|
+
}
|
|
485
511
|
}
|
|
486
512
|
/**
|
|
487
513
|
* Verify that the server's protocol version matches the SDK's expected version
|
|
@@ -583,6 +609,77 @@ class CopilotClient {
|
|
|
583
609
|
isRemote: s.isRemote
|
|
584
610
|
}));
|
|
585
611
|
}
|
|
612
|
+
/**
|
|
613
|
+
* Gets the foreground session ID in TUI+server mode.
|
|
614
|
+
*
|
|
615
|
+
* This returns the ID of the session currently displayed in the TUI.
|
|
616
|
+
* Only available when connecting to a server running in TUI+server mode (--ui-server).
|
|
617
|
+
*
|
|
618
|
+
* @returns A promise that resolves with the foreground session ID, or undefined if none
|
|
619
|
+
* @throws Error if the client is not connected
|
|
620
|
+
*
|
|
621
|
+
* @example
|
|
622
|
+
* ```typescript
|
|
623
|
+
* const sessionId = await client.getForegroundSessionId();
|
|
624
|
+
* if (sessionId) {
|
|
625
|
+
* console.log(`TUI is displaying session: ${sessionId}`);
|
|
626
|
+
* }
|
|
627
|
+
* ```
|
|
628
|
+
*/
|
|
629
|
+
async getForegroundSessionId() {
|
|
630
|
+
if (!this.connection) {
|
|
631
|
+
throw new Error("Client not connected");
|
|
632
|
+
}
|
|
633
|
+
const response = await this.connection.sendRequest("session.getForeground", {});
|
|
634
|
+
return response.sessionId;
|
|
635
|
+
}
|
|
636
|
+
/**
|
|
637
|
+
* Sets the foreground session in TUI+server mode.
|
|
638
|
+
*
|
|
639
|
+
* This requests the TUI to switch to displaying the specified session.
|
|
640
|
+
* Only available when connecting to a server running in TUI+server mode (--ui-server).
|
|
641
|
+
*
|
|
642
|
+
* @param sessionId - The ID of the session to display in the TUI
|
|
643
|
+
* @returns A promise that resolves when the session is switched
|
|
644
|
+
* @throws Error if the client is not connected or if the operation fails
|
|
645
|
+
*
|
|
646
|
+
* @example
|
|
647
|
+
* ```typescript
|
|
648
|
+
* // Switch the TUI to display a specific session
|
|
649
|
+
* await client.setForegroundSessionId("session-123");
|
|
650
|
+
* ```
|
|
651
|
+
*/
|
|
652
|
+
async setForegroundSessionId(sessionId) {
|
|
653
|
+
if (!this.connection) {
|
|
654
|
+
throw new Error("Client not connected");
|
|
655
|
+
}
|
|
656
|
+
const response = await this.connection.sendRequest("session.setForeground", { sessionId });
|
|
657
|
+
const result = response;
|
|
658
|
+
if (!result.success) {
|
|
659
|
+
throw new Error(result.error || "Failed to set foreground session");
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
on(eventTypeOrHandler, handler) {
|
|
663
|
+
if (typeof eventTypeOrHandler === "string" && handler) {
|
|
664
|
+
const eventType = eventTypeOrHandler;
|
|
665
|
+
if (!this.typedLifecycleHandlers.has(eventType)) {
|
|
666
|
+
this.typedLifecycleHandlers.set(eventType, /* @__PURE__ */ new Set());
|
|
667
|
+
}
|
|
668
|
+
const storedHandler = handler;
|
|
669
|
+
this.typedLifecycleHandlers.get(eventType).add(storedHandler);
|
|
670
|
+
return () => {
|
|
671
|
+
const handlers = this.typedLifecycleHandlers.get(eventType);
|
|
672
|
+
if (handlers) {
|
|
673
|
+
handlers.delete(storedHandler);
|
|
674
|
+
}
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
const wildcardHandler = eventTypeOrHandler;
|
|
678
|
+
this.sessionLifecycleHandlers.add(wildcardHandler);
|
|
679
|
+
return () => {
|
|
680
|
+
this.sessionLifecycleHandlers.delete(wildcardHandler);
|
|
681
|
+
};
|
|
682
|
+
}
|
|
586
683
|
/**
|
|
587
684
|
* Start the CLI server process
|
|
588
685
|
*/
|
|
@@ -590,7 +687,7 @@ class CopilotClient {
|
|
|
590
687
|
return new Promise((resolve, reject) => {
|
|
591
688
|
const args = [
|
|
592
689
|
...this.options.cliArgs,
|
|
593
|
-
"--
|
|
690
|
+
"--headless",
|
|
594
691
|
"--log-level",
|
|
595
692
|
this.options.logLevel
|
|
596
693
|
];
|
|
@@ -735,6 +832,9 @@ class CopilotClient {
|
|
|
735
832
|
this.connection.onNotification("session.event", (notification) => {
|
|
736
833
|
this.handleSessionEventNotification(notification);
|
|
737
834
|
});
|
|
835
|
+
this.connection.onNotification("session.lifecycle", (notification) => {
|
|
836
|
+
this.handleSessionLifecycleNotification(notification);
|
|
837
|
+
});
|
|
738
838
|
this.connection.onRequest(
|
|
739
839
|
"tool.call",
|
|
740
840
|
async (params) => await this.handleToolCallRequest(params)
|
|
@@ -768,6 +868,27 @@ class CopilotClient {
|
|
|
768
868
|
session._dispatchEvent(notification.event);
|
|
769
869
|
}
|
|
770
870
|
}
|
|
871
|
+
handleSessionLifecycleNotification(notification) {
|
|
872
|
+
if (typeof notification !== "object" || !notification || !("type" in notification) || typeof notification.type !== "string" || !("sessionId" in notification) || typeof notification.sessionId !== "string") {
|
|
873
|
+
return;
|
|
874
|
+
}
|
|
875
|
+
const event = notification;
|
|
876
|
+
const typedHandlers = this.typedLifecycleHandlers.get(event.type);
|
|
877
|
+
if (typedHandlers) {
|
|
878
|
+
for (const handler of typedHandlers) {
|
|
879
|
+
try {
|
|
880
|
+
handler(event);
|
|
881
|
+
} catch {
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
for (const handler of this.sessionLifecycleHandlers) {
|
|
886
|
+
try {
|
|
887
|
+
handler(event);
|
|
888
|
+
} catch {
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
}
|
|
771
892
|
async handleToolCallRequest(params) {
|
|
772
893
|
if (!params || typeof params.sessionId !== "string" || typeof params.toolCallId !== "string" || typeof params.toolName !== "string") {
|
|
773
894
|
throw new Error("Invalid tool call payload");
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Generated from: @github/copilot/session-events.schema.json
|
|
5
5
|
* Generated by: scripts/generate-session-types.ts
|
|
6
|
-
* Generated at: 2026-
|
|
6
|
+
* Generated at: 2026-02-03T20:40:49.167Z
|
|
7
7
|
*
|
|
8
8
|
* To update these types:
|
|
9
9
|
* 1. Update the schema in copilot-agent-runtime
|
|
@@ -55,6 +55,8 @@ export type SessionEvent = {
|
|
|
55
55
|
errorType: string;
|
|
56
56
|
message: string;
|
|
57
57
|
stack?: string;
|
|
58
|
+
statusCode?: number;
|
|
59
|
+
providerCallId?: string;
|
|
58
60
|
};
|
|
59
61
|
} | {
|
|
60
62
|
id: string;
|
|
@@ -127,6 +129,39 @@ export type SessionEvent = {
|
|
|
127
129
|
upToEventId: string;
|
|
128
130
|
eventsRemoved: number;
|
|
129
131
|
};
|
|
132
|
+
} | {
|
|
133
|
+
id: string;
|
|
134
|
+
timestamp: string;
|
|
135
|
+
parentId: string | null;
|
|
136
|
+
ephemeral: true;
|
|
137
|
+
type: "session.shutdown";
|
|
138
|
+
data: {
|
|
139
|
+
shutdownType: "routine" | "error";
|
|
140
|
+
errorReason?: string;
|
|
141
|
+
totalPremiumRequests: number;
|
|
142
|
+
totalApiDurationMs: number;
|
|
143
|
+
sessionStartTime: number;
|
|
144
|
+
codeChanges: {
|
|
145
|
+
linesAdded: number;
|
|
146
|
+
linesRemoved: number;
|
|
147
|
+
filesModified: string[];
|
|
148
|
+
};
|
|
149
|
+
modelMetrics: {
|
|
150
|
+
[k: string]: {
|
|
151
|
+
requests: {
|
|
152
|
+
count: number;
|
|
153
|
+
cost: number;
|
|
154
|
+
};
|
|
155
|
+
usage: {
|
|
156
|
+
inputTokens: number;
|
|
157
|
+
outputTokens: number;
|
|
158
|
+
cacheReadTokens: number;
|
|
159
|
+
cacheWriteTokens: number;
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
currentModel?: string;
|
|
164
|
+
};
|
|
130
165
|
} | {
|
|
131
166
|
id: string;
|
|
132
167
|
timestamp: string;
|
|
@@ -160,6 +195,8 @@ export type SessionEvent = {
|
|
|
160
195
|
messagesRemoved?: number;
|
|
161
196
|
tokensRemoved?: number;
|
|
162
197
|
summaryContent?: string;
|
|
198
|
+
checkpointNumber?: number;
|
|
199
|
+
checkpointPath?: string;
|
|
163
200
|
compactionTokensUsed?: {
|
|
164
201
|
input: number;
|
|
165
202
|
output: number;
|
|
@@ -261,6 +298,9 @@ export type SessionEvent = {
|
|
|
261
298
|
arguments?: unknown;
|
|
262
299
|
type?: "function" | "custom";
|
|
263
300
|
}[];
|
|
301
|
+
reasoningOpaque?: string;
|
|
302
|
+
reasoningText?: string;
|
|
303
|
+
encryptedContent?: string;
|
|
264
304
|
parentToolCallId?: string;
|
|
265
305
|
};
|
|
266
306
|
} | {
|
|
@@ -291,7 +331,7 @@ export type SessionEvent = {
|
|
|
291
331
|
ephemeral: true;
|
|
292
332
|
type: "assistant.usage";
|
|
293
333
|
data: {
|
|
294
|
-
model
|
|
334
|
+
model: string;
|
|
295
335
|
inputTokens?: number;
|
|
296
336
|
outputTokens?: number;
|
|
297
337
|
cacheReadTokens?: number;
|
|
@@ -301,6 +341,7 @@ export type SessionEvent = {
|
|
|
301
341
|
initiator?: string;
|
|
302
342
|
apiCallId?: string;
|
|
303
343
|
providerCallId?: string;
|
|
344
|
+
parentToolCallId?: string;
|
|
304
345
|
quotaSnapshots?: {
|
|
305
346
|
[k: string]: {
|
|
306
347
|
isUnlimitedEntitlement: boolean;
|
|
@@ -391,6 +432,18 @@ export type SessionEvent = {
|
|
|
391
432
|
};
|
|
392
433
|
parentToolCallId?: string;
|
|
393
434
|
};
|
|
435
|
+
} | {
|
|
436
|
+
id: string;
|
|
437
|
+
timestamp: string;
|
|
438
|
+
parentId: string | null;
|
|
439
|
+
ephemeral?: boolean;
|
|
440
|
+
type: "skill.invoked";
|
|
441
|
+
data: {
|
|
442
|
+
name: string;
|
|
443
|
+
path: string;
|
|
444
|
+
content: string;
|
|
445
|
+
allowedTools?: string[];
|
|
446
|
+
};
|
|
394
447
|
} | {
|
|
395
448
|
id: string;
|
|
396
449
|
timestamp: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
export { CopilotClient } from "./client.js";
|
|
7
7
|
export { CopilotSession, type AssistantMessageEvent } from "./session.js";
|
|
8
8
|
export { defineTool } from "./types.js";
|
|
9
|
-
export type { ConnectionState, CopilotClientOptions, CustomAgentConfig, GetAuthStatusResponse, GetStatusResponse, InfiniteSessionConfig, MCPLocalServerConfig, MCPRemoteServerConfig, MCPServerConfig, MessageOptions, ModelBilling, ModelCapabilities, ModelInfo, ModelPolicy, PermissionHandler, PermissionRequest, PermissionRequestResult, ResumeSessionConfig, SessionConfig, SessionEvent, SessionEventHandler, SessionEventPayload, SessionEventType, SessionMetadata, SystemMessageAppendConfig, SystemMessageConfig, SystemMessageReplaceConfig, Tool, ToolHandler, ToolInvocation, ToolResultObject, TypedSessionEventHandler, ZodSchema, } from "./types.js";
|
|
9
|
+
export type { ConnectionState, CopilotClientOptions, CustomAgentConfig, ForegroundSessionInfo, GetAuthStatusResponse, GetStatusResponse, InfiniteSessionConfig, MCPLocalServerConfig, MCPRemoteServerConfig, MCPServerConfig, MessageOptions, ModelBilling, ModelCapabilities, ModelInfo, ModelPolicy, PermissionHandler, PermissionRequest, PermissionRequestResult, ResumeSessionConfig, SessionConfig, SessionEvent, SessionEventHandler, SessionEventPayload, SessionEventType, SessionLifecycleEvent, SessionLifecycleEventType, SessionLifecycleHandler, SessionMetadata, SystemMessageAppendConfig, SystemMessageConfig, SystemMessageReplaceConfig, Tool, ToolHandler, ToolInvocation, ToolResultObject, TypedSessionEventHandler, TypedSessionLifecycleHandler, ZodSchema, } from "./types.js";
|
package/dist/types.d.ts
CHANGED
|
@@ -490,6 +490,10 @@ export interface InfiniteSessionConfig {
|
|
|
490
490
|
*/
|
|
491
491
|
bufferExhaustionThreshold?: number;
|
|
492
492
|
}
|
|
493
|
+
/**
|
|
494
|
+
* Valid reasoning effort levels for models that support it.
|
|
495
|
+
*/
|
|
496
|
+
export type ReasoningEffort = "low" | "medium" | "high" | "xhigh";
|
|
493
497
|
export interface SessionConfig {
|
|
494
498
|
/**
|
|
495
499
|
* Optional custom session ID
|
|
@@ -500,6 +504,12 @@ export interface SessionConfig {
|
|
|
500
504
|
* Model to use for this session
|
|
501
505
|
*/
|
|
502
506
|
model?: string;
|
|
507
|
+
/**
|
|
508
|
+
* Reasoning effort level for models that support it.
|
|
509
|
+
* Only valid for models where capabilities.supports.reasoningEffort is true.
|
|
510
|
+
* Use client.listModels() to check supported values for each model.
|
|
511
|
+
*/
|
|
512
|
+
reasoningEffort?: ReasoningEffort;
|
|
503
513
|
/**
|
|
504
514
|
* Override the default configuration directory location.
|
|
505
515
|
* When specified, the session will use this directory for storing config and state.
|
|
@@ -577,7 +587,7 @@ export interface SessionConfig {
|
|
|
577
587
|
/**
|
|
578
588
|
* Configuration for resuming a session
|
|
579
589
|
*/
|
|
580
|
-
export type ResumeSessionConfig = Pick<SessionConfig, "tools" | "provider" | "streaming" | "onPermissionRequest" | "onUserInputRequest" | "hooks" | "workingDirectory" | "mcpServers" | "customAgents" | "skillDirectories" | "disabledSkills"> & {
|
|
590
|
+
export type ResumeSessionConfig = Pick<SessionConfig, "tools" | "provider" | "streaming" | "reasoningEffort" | "onPermissionRequest" | "onUserInputRequest" | "hooks" | "workingDirectory" | "mcpServers" | "customAgents" | "skillDirectories" | "disabledSkills"> & {
|
|
581
591
|
/**
|
|
582
592
|
* When true, skips emitting the session.resume event.
|
|
583
593
|
* Useful for reconnecting to a session without triggering resume-related side effects.
|
|
@@ -706,6 +716,8 @@ export interface GetAuthStatusResponse {
|
|
|
706
716
|
export interface ModelCapabilities {
|
|
707
717
|
supports: {
|
|
708
718
|
vision: boolean;
|
|
719
|
+
/** Whether this model supports reasoning effort configuration */
|
|
720
|
+
reasoningEffort: boolean;
|
|
709
721
|
};
|
|
710
722
|
limits: {
|
|
711
723
|
max_prompt_tokens?: number;
|
|
@@ -744,5 +756,48 @@ export interface ModelInfo {
|
|
|
744
756
|
policy?: ModelPolicy;
|
|
745
757
|
/** Billing information */
|
|
746
758
|
billing?: ModelBilling;
|
|
759
|
+
/** Supported reasoning effort levels (only present if model supports reasoning effort) */
|
|
760
|
+
supportedReasoningEfforts?: ReasoningEffort[];
|
|
761
|
+
/** Default reasoning effort level (only present if model supports reasoning effort) */
|
|
762
|
+
defaultReasoningEffort?: ReasoningEffort;
|
|
763
|
+
}
|
|
764
|
+
/**
|
|
765
|
+
* Types of session lifecycle events
|
|
766
|
+
*/
|
|
767
|
+
export type SessionLifecycleEventType = "session.created" | "session.deleted" | "session.updated" | "session.foreground" | "session.background";
|
|
768
|
+
/**
|
|
769
|
+
* Session lifecycle event notification
|
|
770
|
+
* Sent when sessions are created, deleted, updated, or change foreground/background state
|
|
771
|
+
*/
|
|
772
|
+
export interface SessionLifecycleEvent {
|
|
773
|
+
/** Type of lifecycle event */
|
|
774
|
+
type: SessionLifecycleEventType;
|
|
775
|
+
/** ID of the session this event relates to */
|
|
776
|
+
sessionId: string;
|
|
777
|
+
/** Session metadata (not included for deleted sessions) */
|
|
778
|
+
metadata?: {
|
|
779
|
+
startTime: string;
|
|
780
|
+
modifiedTime: string;
|
|
781
|
+
summary?: string;
|
|
782
|
+
};
|
|
783
|
+
}
|
|
784
|
+
/**
|
|
785
|
+
* Handler for session lifecycle events
|
|
786
|
+
*/
|
|
787
|
+
export type SessionLifecycleHandler = (event: SessionLifecycleEvent) => void;
|
|
788
|
+
/**
|
|
789
|
+
* Typed handler for specific session lifecycle event types
|
|
790
|
+
*/
|
|
791
|
+
export type TypedSessionLifecycleHandler<K extends SessionLifecycleEventType> = (event: SessionLifecycleEvent & {
|
|
792
|
+
type: K;
|
|
793
|
+
}) => void;
|
|
794
|
+
/**
|
|
795
|
+
* Information about the foreground session in TUI+server mode
|
|
796
|
+
*/
|
|
797
|
+
export interface ForegroundSessionInfo {
|
|
798
|
+
/** ID of the foreground session, or undefined if none */
|
|
799
|
+
sessionId?: string;
|
|
800
|
+
/** Workspace path of the foreground session */
|
|
801
|
+
workspacePath?: string;
|
|
747
802
|
}
|
|
748
803
|
export {};
|
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.
|
|
7
|
+
"version": "0.1.21",
|
|
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",
|
|
@@ -40,15 +40,15 @@
|
|
|
40
40
|
"author": "GitHub",
|
|
41
41
|
"license": "MIT",
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@github/copilot": "^0.0.
|
|
43
|
+
"@github/copilot": "^0.0.402",
|
|
44
44
|
"vscode-jsonrpc": "^8.2.1",
|
|
45
45
|
"zod": "^4.3.5"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@types/node": "^
|
|
49
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
50
|
-
"@typescript-eslint/parser": "^8.
|
|
51
|
-
"esbuild": "^0.27.
|
|
48
|
+
"@types/node": "^25.2.0",
|
|
49
|
+
"@typescript-eslint/eslint-plugin": "^8.54.0",
|
|
50
|
+
"@typescript-eslint/parser": "^8.54.0",
|
|
51
|
+
"esbuild": "^0.27.2",
|
|
52
52
|
"eslint": "^9.0.0",
|
|
53
53
|
"glob": "^11.0.0",
|
|
54
54
|
"json-schema": "^0.4.0",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"semver": "^7.7.3",
|
|
60
60
|
"tsx": "^4.20.6",
|
|
61
61
|
"typescript": "^5.0.0",
|
|
62
|
-
"vitest": "^4.0.
|
|
62
|
+
"vitest": "^4.0.18"
|
|
63
63
|
},
|
|
64
64
|
"engines": {
|
|
65
65
|
"node": ">=18.0.0"
|