@github/copilot-sdk 0.1.13-preview.0 → 0.1.14

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.
@@ -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-01-13T00:08:20.716Z
6
+ * Generated at: 2026-01-16T00:52:51.450Z
7
7
  *
8
8
  * To update these types:
9
9
  * 1. Update the schema in copilot-agent-runtime
@@ -105,6 +105,45 @@ export type SessionEvent = {
105
105
  messagesRemovedDuringTruncation: number;
106
106
  performedBy: string;
107
107
  };
108
+ } | {
109
+ id: string;
110
+ timestamp: string;
111
+ parentId: string | null;
112
+ ephemeral: true;
113
+ type: "session.usage_info";
114
+ data: {
115
+ tokenLimit: number;
116
+ currentTokens: number;
117
+ messagesLength: number;
118
+ };
119
+ } | {
120
+ id: string;
121
+ timestamp: string;
122
+ parentId: string | null;
123
+ ephemeral?: boolean;
124
+ type: "session.compaction_start";
125
+ data: {};
126
+ } | {
127
+ id: string;
128
+ timestamp: string;
129
+ parentId: string | null;
130
+ ephemeral?: boolean;
131
+ type: "session.compaction_complete";
132
+ data: {
133
+ success: boolean;
134
+ error?: string;
135
+ preCompactionTokens?: number;
136
+ postCompactionTokens?: number;
137
+ preCompactionMessagesLength?: number;
138
+ messagesRemoved?: number;
139
+ tokensRemoved?: number;
140
+ summaryContent?: string;
141
+ compactionTokensUsed?: {
142
+ input: number;
143
+ output: number;
144
+ cachedInput: number;
145
+ };
146
+ };
108
147
  } | {
109
148
  id: string;
110
149
  timestamp: string;
@@ -155,13 +194,12 @@ export type SessionEvent = {
155
194
  data: {
156
195
  reasoningId: string;
157
196
  content: string;
158
- chunkContent?: string;
159
197
  };
160
198
  } | {
161
199
  id: string;
162
200
  timestamp: string;
163
201
  parentId: string | null;
164
- ephemeral?: true;
202
+ ephemeral: true;
165
203
  type: "assistant.reasoning_delta";
166
204
  data: {
167
205
  reasoningId: string;
@@ -176,8 +214,6 @@ export type SessionEvent = {
176
214
  data: {
177
215
  messageId: string;
178
216
  content: string;
179
- chunkContent?: string;
180
- totalResponseSizeBytes?: number;
181
217
  toolRequests?: {
182
218
  toolCallId: string;
183
219
  name: string;
@@ -189,7 +225,7 @@ export type SessionEvent = {
189
225
  id: string;
190
226
  timestamp: string;
191
227
  parentId: string | null;
192
- ephemeral?: true;
228
+ ephemeral: true;
193
229
  type: "assistant.message_delta";
194
230
  data: {
195
231
  messageId: string;
@@ -305,7 +341,7 @@ export type SessionEvent = {
305
341
  timestamp: string;
306
342
  parentId: string | null;
307
343
  ephemeral?: boolean;
308
- type: "custom_agent.started";
344
+ type: "subagent.started";
309
345
  data: {
310
346
  toolCallId: string;
311
347
  agentName: string;
@@ -317,7 +353,7 @@ export type SessionEvent = {
317
353
  timestamp: string;
318
354
  parentId: string | null;
319
355
  ephemeral?: boolean;
320
- type: "custom_agent.completed";
356
+ type: "subagent.completed";
321
357
  data: {
322
358
  toolCallId: string;
323
359
  agentName: string;
@@ -327,7 +363,7 @@ export type SessionEvent = {
327
363
  timestamp: string;
328
364
  parentId: string | null;
329
365
  ephemeral?: boolean;
330
- type: "custom_agent.failed";
366
+ type: "subagent.failed";
331
367
  data: {
332
368
  toolCallId: string;
333
369
  agentName: string;
@@ -338,7 +374,7 @@ export type SessionEvent = {
338
374
  timestamp: string;
339
375
  parentId: string | null;
340
376
  ephemeral?: boolean;
341
- type: "custom_agent.selected";
377
+ type: "subagent.selected";
342
378
  data: {
343
379
  agentName: string;
344
380
  agentDisplayName: string;
package/dist/index.d.ts CHANGED
@@ -4,6 +4,6 @@
4
4
  * JSON-RPC based SDK for programmatic control of GitHub Copilot CLI
5
5
  */
6
6
  export { CopilotClient } from "./client.js";
7
- export { CopilotSession } from "./session.js";
7
+ export { CopilotSession, type AssistantMessageEvent } from "./session.js";
8
8
  export { defineTool } from "./types.js";
9
9
  export type { ConnectionState, CopilotClientOptions, CustomAgentConfig, MCPLocalServerConfig, MCPRemoteServerConfig, MCPServerConfig, MessageOptions, PermissionHandler, PermissionRequest, PermissionRequestResult, ResumeSessionConfig, SessionConfig, SessionEvent, SessionEventHandler, SessionMetadata, SystemMessageAppendConfig, SystemMessageConfig, SystemMessageReplaceConfig, Tool, ToolHandler, ToolInvocation, ToolResultObject, ZodSchema, } from "./types.js";
package/dist/session.d.ts CHANGED
@@ -4,6 +4,10 @@
4
4
  */
5
5
  import type { MessageConnection } from "vscode-jsonrpc/node";
6
6
  import type { MessageOptions, PermissionHandler, PermissionRequestResult, SessionEvent, SessionEventHandler, Tool, ToolHandler } from "./types.js";
7
+ /** Assistant message event - the final response from the assistant. */
8
+ export type AssistantMessageEvent = Extract<SessionEvent, {
9
+ type: "assistant.message";
10
+ }>;
7
11
  /**
8
12
  * Represents a single conversation session with the Copilot CLI.
9
13
  *
@@ -16,17 +20,16 @@ import type { MessageOptions, PermissionHandler, PermissionRequestResult, Sessio
16
20
  * const session = await client.createSession({ model: "gpt-4" });
17
21
  *
18
22
  * // Subscribe to events
19
- * const unsubscribe = session.on((event) => {
23
+ * session.on((event) => {
20
24
  * if (event.type === "assistant.message") {
21
25
  * console.log(event.data.content);
22
26
  * }
23
27
  * });
24
28
  *
25
- * // Send a message
26
- * await session.send({ prompt: "Hello, world!" });
29
+ * // Send a message and wait for completion
30
+ * await session.sendAndWait({ prompt: "Hello, world!" });
27
31
  *
28
32
  * // Clean up
29
- * unsubscribe();
30
33
  * await session.destroy();
31
34
  * ```
32
35
  */
@@ -63,6 +66,30 @@ export declare class CopilotSession {
63
66
  * ```
64
67
  */
65
68
  send(options: MessageOptions): Promise<string>;
69
+ /**
70
+ * Sends a message to this session and waits until the session becomes idle.
71
+ *
72
+ * This is a convenience method that combines {@link send} with waiting for
73
+ * the `session.idle` event. Use this when you want to block until the
74
+ * assistant has finished processing the message.
75
+ *
76
+ * Events are still delivered to handlers registered via {@link on} while waiting.
77
+ *
78
+ * @param options - The message options including the prompt and optional attachments
79
+ * @param timeout - Timeout in milliseconds (default: 60000). Controls how long to wait; does not abort in-flight agent work.
80
+ * @returns A promise that resolves with the final assistant message when the session becomes idle,
81
+ * or undefined if no assistant message was received
82
+ * @throws Error if the timeout is reached before the session becomes idle
83
+ * @throws Error if the session has been destroyed or the connection fails
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * // Send and wait for completion with default 60s timeout
88
+ * const response = await session.sendAndWait({ prompt: "What is 2+2?" });
89
+ * console.log(response?.data.content); // "4"
90
+ * ```
91
+ */
92
+ sendAndWait(options: MessageOptions, timeout?: number): Promise<AssistantMessageEvent | undefined>;
66
93
  /**
67
94
  * Subscribes to events from this session.
68
95
  *
package/dist/session.js CHANGED
@@ -40,6 +40,67 @@ class CopilotSession {
40
40
  });
41
41
  return response.messageId;
42
42
  }
43
+ /**
44
+ * Sends a message to this session and waits until the session becomes idle.
45
+ *
46
+ * This is a convenience method that combines {@link send} with waiting for
47
+ * the `session.idle` event. Use this when you want to block until the
48
+ * assistant has finished processing the message.
49
+ *
50
+ * Events are still delivered to handlers registered via {@link on} while waiting.
51
+ *
52
+ * @param options - The message options including the prompt and optional attachments
53
+ * @param timeout - Timeout in milliseconds (default: 60000). Controls how long to wait; does not abort in-flight agent work.
54
+ * @returns A promise that resolves with the final assistant message when the session becomes idle,
55
+ * or undefined if no assistant message was received
56
+ * @throws Error if the timeout is reached before the session becomes idle
57
+ * @throws Error if the session has been destroyed or the connection fails
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * // Send and wait for completion with default 60s timeout
62
+ * const response = await session.sendAndWait({ prompt: "What is 2+2?" });
63
+ * console.log(response?.data.content); // "4"
64
+ * ```
65
+ */
66
+ async sendAndWait(options, timeout) {
67
+ const effectiveTimeout = timeout ?? 6e4;
68
+ let resolveIdle;
69
+ let rejectWithError;
70
+ const idlePromise = new Promise((resolve, reject) => {
71
+ resolveIdle = resolve;
72
+ rejectWithError = reject;
73
+ });
74
+ let lastAssistantMessage;
75
+ const unsubscribe = this.on((event) => {
76
+ if (event.type === "assistant.message") {
77
+ lastAssistantMessage = event;
78
+ } else if (event.type === "session.idle") {
79
+ resolveIdle();
80
+ } else if (event.type === "session.error") {
81
+ const error = new Error(event.data.message);
82
+ error.stack = event.data.stack;
83
+ rejectWithError(error);
84
+ }
85
+ });
86
+ try {
87
+ await this.send(options);
88
+ const timeoutPromise = new Promise((_, reject) => {
89
+ setTimeout(
90
+ () => reject(
91
+ new Error(
92
+ `Timeout after ${effectiveTimeout}ms waiting for session.idle`
93
+ )
94
+ ),
95
+ effectiveTimeout
96
+ );
97
+ });
98
+ await Promise.race([idlePromise, timeoutPromise]);
99
+ return lastAssistantMessage;
100
+ } finally {
101
+ unsubscribe();
102
+ }
103
+ }
43
104
  /**
44
105
  * Subscribes to events from this session.
45
106
  *
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.13-preview.0",
7
+ "version": "0.1.14",
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,7 +40,7 @@
40
40
  "author": "GitHub",
41
41
  "license": "MIT",
42
42
  "dependencies": {
43
- "@github/copilot": "^0.0.382-0",
43
+ "@github/copilot": "^0.0.384",
44
44
  "vscode-jsonrpc": "^8.2.1",
45
45
  "zod": "^4.3.5"
46
46
  },