@github/copilot-sdk 0.0.1 → 0.1.10-preview.0
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 +1 -0
- package/dist/client.d.ts +95 -0
- package/dist/client.js +551 -0
- package/dist/generated/session-events.d.ts +384 -0
- package/dist/generated/session-events.js +0 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +8 -0
- package/dist/session.d.ts +39 -0
- package/dist/session.js +83 -0
- package/dist/types.d.ts +277 -0
- package/dist/types.js +6 -0
- package/package.json +67 -2
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AUTO-GENERATED FILE - DO NOT EDIT
|
|
3
|
+
*
|
|
4
|
+
* Generated from: @github/copilot/session-events.schema.json
|
|
5
|
+
* Generated by: scripts/generate-session-types.ts
|
|
6
|
+
* Generated at: 2026-01-08T23:59:19.905Z
|
|
7
|
+
*
|
|
8
|
+
* To update these types:
|
|
9
|
+
* 1. Update the schema in copilot-agent-runtime
|
|
10
|
+
* 2. Run: npm run generate:session-types
|
|
11
|
+
*/
|
|
12
|
+
export type SessionEvent = {
|
|
13
|
+
id: string;
|
|
14
|
+
timestamp: string;
|
|
15
|
+
parentId: string | null;
|
|
16
|
+
ephemeral?: boolean;
|
|
17
|
+
type: "session.start";
|
|
18
|
+
data: {
|
|
19
|
+
sessionId: string;
|
|
20
|
+
version: number;
|
|
21
|
+
producer: string;
|
|
22
|
+
copilotVersion: string;
|
|
23
|
+
startTime: string;
|
|
24
|
+
selectedModel?: string;
|
|
25
|
+
};
|
|
26
|
+
} | {
|
|
27
|
+
id: string;
|
|
28
|
+
timestamp: string;
|
|
29
|
+
parentId: string | null;
|
|
30
|
+
ephemeral?: boolean;
|
|
31
|
+
type: "session.resume";
|
|
32
|
+
data: {
|
|
33
|
+
resumeTime: string;
|
|
34
|
+
eventCount: number;
|
|
35
|
+
};
|
|
36
|
+
} | {
|
|
37
|
+
id: string;
|
|
38
|
+
timestamp: string;
|
|
39
|
+
parentId: string | null;
|
|
40
|
+
ephemeral?: boolean;
|
|
41
|
+
type: "session.error";
|
|
42
|
+
data: {
|
|
43
|
+
errorType: string;
|
|
44
|
+
message: string;
|
|
45
|
+
stack?: string;
|
|
46
|
+
};
|
|
47
|
+
} | {
|
|
48
|
+
id: string;
|
|
49
|
+
timestamp: string;
|
|
50
|
+
parentId: string | null;
|
|
51
|
+
ephemeral: true;
|
|
52
|
+
type: "session.idle";
|
|
53
|
+
data: {};
|
|
54
|
+
} | {
|
|
55
|
+
id: string;
|
|
56
|
+
timestamp: string;
|
|
57
|
+
parentId: string | null;
|
|
58
|
+
ephemeral?: boolean;
|
|
59
|
+
type: "session.info";
|
|
60
|
+
data: {
|
|
61
|
+
infoType: string;
|
|
62
|
+
message: string;
|
|
63
|
+
};
|
|
64
|
+
} | {
|
|
65
|
+
id: string;
|
|
66
|
+
timestamp: string;
|
|
67
|
+
parentId: string | null;
|
|
68
|
+
ephemeral?: boolean;
|
|
69
|
+
type: "session.model_change";
|
|
70
|
+
data: {
|
|
71
|
+
previousModel?: string;
|
|
72
|
+
newModel: string;
|
|
73
|
+
};
|
|
74
|
+
} | {
|
|
75
|
+
id: string;
|
|
76
|
+
timestamp: string;
|
|
77
|
+
parentId: string | null;
|
|
78
|
+
ephemeral?: boolean;
|
|
79
|
+
type: "session.handoff";
|
|
80
|
+
data: {
|
|
81
|
+
handoffTime: string;
|
|
82
|
+
sourceType: "remote" | "local";
|
|
83
|
+
repository?: {
|
|
84
|
+
owner: string;
|
|
85
|
+
name: string;
|
|
86
|
+
branch?: string;
|
|
87
|
+
};
|
|
88
|
+
context?: string;
|
|
89
|
+
summary?: string;
|
|
90
|
+
remoteSessionId?: string;
|
|
91
|
+
};
|
|
92
|
+
} | {
|
|
93
|
+
id: string;
|
|
94
|
+
timestamp: string;
|
|
95
|
+
parentId: string | null;
|
|
96
|
+
ephemeral?: boolean;
|
|
97
|
+
type: "session.truncation";
|
|
98
|
+
data: {
|
|
99
|
+
tokenLimit: number;
|
|
100
|
+
preTruncationTokensInMessages: number;
|
|
101
|
+
preTruncationMessagesLength: number;
|
|
102
|
+
postTruncationTokensInMessages: number;
|
|
103
|
+
postTruncationMessagesLength: number;
|
|
104
|
+
tokensRemovedDuringTruncation: number;
|
|
105
|
+
messagesRemovedDuringTruncation: number;
|
|
106
|
+
performedBy: string;
|
|
107
|
+
};
|
|
108
|
+
} | {
|
|
109
|
+
id: string;
|
|
110
|
+
timestamp: string;
|
|
111
|
+
parentId: string | null;
|
|
112
|
+
ephemeral?: boolean;
|
|
113
|
+
type: "user.message";
|
|
114
|
+
data: {
|
|
115
|
+
content: string;
|
|
116
|
+
transformedContent?: string;
|
|
117
|
+
attachments?: {
|
|
118
|
+
type: "file" | "directory";
|
|
119
|
+
path: string;
|
|
120
|
+
displayName: string;
|
|
121
|
+
}[];
|
|
122
|
+
source?: string;
|
|
123
|
+
};
|
|
124
|
+
} | {
|
|
125
|
+
id: string;
|
|
126
|
+
timestamp: string;
|
|
127
|
+
parentId: string | null;
|
|
128
|
+
ephemeral?: boolean;
|
|
129
|
+
type: "assistant.turn_start";
|
|
130
|
+
data: {
|
|
131
|
+
turnId: string;
|
|
132
|
+
};
|
|
133
|
+
} | {
|
|
134
|
+
id: string;
|
|
135
|
+
timestamp: string;
|
|
136
|
+
parentId: string | null;
|
|
137
|
+
ephemeral: true;
|
|
138
|
+
type: "assistant.intent";
|
|
139
|
+
data: {
|
|
140
|
+
intent: string;
|
|
141
|
+
};
|
|
142
|
+
} | {
|
|
143
|
+
id: string;
|
|
144
|
+
timestamp: string;
|
|
145
|
+
parentId: string | null;
|
|
146
|
+
ephemeral?: boolean;
|
|
147
|
+
type: "assistant.reasoning";
|
|
148
|
+
data: {
|
|
149
|
+
reasoningId: string;
|
|
150
|
+
content: string;
|
|
151
|
+
chunkContent?: string;
|
|
152
|
+
};
|
|
153
|
+
} | {
|
|
154
|
+
id: string;
|
|
155
|
+
timestamp: string;
|
|
156
|
+
parentId: string | null;
|
|
157
|
+
ephemeral?: true;
|
|
158
|
+
type: "assistant.reasoning_delta";
|
|
159
|
+
data: {
|
|
160
|
+
reasoningId: string;
|
|
161
|
+
deltaContent: string;
|
|
162
|
+
};
|
|
163
|
+
} | {
|
|
164
|
+
id: string;
|
|
165
|
+
timestamp: string;
|
|
166
|
+
parentId: string | null;
|
|
167
|
+
ephemeral?: boolean;
|
|
168
|
+
type: "assistant.message";
|
|
169
|
+
data: {
|
|
170
|
+
messageId: string;
|
|
171
|
+
content: string;
|
|
172
|
+
chunkContent?: string;
|
|
173
|
+
totalResponseSizeBytes?: number;
|
|
174
|
+
toolRequests?: {
|
|
175
|
+
toolCallId: string;
|
|
176
|
+
name: string;
|
|
177
|
+
arguments?: unknown;
|
|
178
|
+
}[];
|
|
179
|
+
parentToolCallId?: string;
|
|
180
|
+
};
|
|
181
|
+
} | {
|
|
182
|
+
id: string;
|
|
183
|
+
timestamp: string;
|
|
184
|
+
parentId: string | null;
|
|
185
|
+
ephemeral?: true;
|
|
186
|
+
type: "assistant.message_delta";
|
|
187
|
+
data: {
|
|
188
|
+
messageId: string;
|
|
189
|
+
deltaContent: string;
|
|
190
|
+
totalResponseSizeBytes?: number;
|
|
191
|
+
parentToolCallId?: string;
|
|
192
|
+
};
|
|
193
|
+
} | {
|
|
194
|
+
id: string;
|
|
195
|
+
timestamp: string;
|
|
196
|
+
parentId: string | null;
|
|
197
|
+
ephemeral?: boolean;
|
|
198
|
+
type: "assistant.turn_end";
|
|
199
|
+
data: {
|
|
200
|
+
turnId: string;
|
|
201
|
+
};
|
|
202
|
+
} | {
|
|
203
|
+
id: string;
|
|
204
|
+
timestamp: string;
|
|
205
|
+
parentId: string | null;
|
|
206
|
+
ephemeral: true;
|
|
207
|
+
type: "assistant.usage";
|
|
208
|
+
data: {
|
|
209
|
+
model?: string;
|
|
210
|
+
inputTokens?: number;
|
|
211
|
+
outputTokens?: number;
|
|
212
|
+
cacheReadTokens?: number;
|
|
213
|
+
cacheWriteTokens?: number;
|
|
214
|
+
cost?: number;
|
|
215
|
+
duration?: number;
|
|
216
|
+
initiator?: string;
|
|
217
|
+
apiCallId?: string;
|
|
218
|
+
providerCallId?: string;
|
|
219
|
+
quotaSnapshots?: {
|
|
220
|
+
[k: string]: {
|
|
221
|
+
isUnlimitedEntitlement: boolean;
|
|
222
|
+
entitlementRequests: number;
|
|
223
|
+
usedRequests: number;
|
|
224
|
+
usageAllowedWithExhaustedQuota: boolean;
|
|
225
|
+
overage: number;
|
|
226
|
+
overageAllowedWithExhaustedQuota: boolean;
|
|
227
|
+
remainingPercentage: number;
|
|
228
|
+
resetDate?: string;
|
|
229
|
+
};
|
|
230
|
+
};
|
|
231
|
+
};
|
|
232
|
+
} | {
|
|
233
|
+
id: string;
|
|
234
|
+
timestamp: string;
|
|
235
|
+
parentId: string | null;
|
|
236
|
+
ephemeral?: boolean;
|
|
237
|
+
type: "abort";
|
|
238
|
+
data: {
|
|
239
|
+
reason: string;
|
|
240
|
+
};
|
|
241
|
+
} | {
|
|
242
|
+
id: string;
|
|
243
|
+
timestamp: string;
|
|
244
|
+
parentId: string | null;
|
|
245
|
+
ephemeral?: boolean;
|
|
246
|
+
type: "tool.user_requested";
|
|
247
|
+
data: {
|
|
248
|
+
toolCallId: string;
|
|
249
|
+
toolName: string;
|
|
250
|
+
arguments?: unknown;
|
|
251
|
+
};
|
|
252
|
+
} | {
|
|
253
|
+
id: string;
|
|
254
|
+
timestamp: string;
|
|
255
|
+
parentId: string | null;
|
|
256
|
+
ephemeral?: boolean;
|
|
257
|
+
type: "tool.execution_start";
|
|
258
|
+
data: {
|
|
259
|
+
toolCallId: string;
|
|
260
|
+
toolName: string;
|
|
261
|
+
arguments?: unknown;
|
|
262
|
+
parentToolCallId?: string;
|
|
263
|
+
};
|
|
264
|
+
} | {
|
|
265
|
+
id: string;
|
|
266
|
+
timestamp: string;
|
|
267
|
+
parentId: string | null;
|
|
268
|
+
ephemeral: true;
|
|
269
|
+
type: "tool.execution_partial_result";
|
|
270
|
+
data: {
|
|
271
|
+
toolCallId: string;
|
|
272
|
+
partialOutput: string;
|
|
273
|
+
};
|
|
274
|
+
} | {
|
|
275
|
+
id: string;
|
|
276
|
+
timestamp: string;
|
|
277
|
+
parentId: string | null;
|
|
278
|
+
ephemeral?: boolean;
|
|
279
|
+
type: "tool.execution_complete";
|
|
280
|
+
data: {
|
|
281
|
+
toolCallId: string;
|
|
282
|
+
success: boolean;
|
|
283
|
+
isUserRequested?: boolean;
|
|
284
|
+
result?: {
|
|
285
|
+
content: string;
|
|
286
|
+
};
|
|
287
|
+
error?: {
|
|
288
|
+
message: string;
|
|
289
|
+
code?: string;
|
|
290
|
+
};
|
|
291
|
+
toolTelemetry?: {
|
|
292
|
+
[k: string]: unknown;
|
|
293
|
+
};
|
|
294
|
+
parentToolCallId?: string;
|
|
295
|
+
};
|
|
296
|
+
} | {
|
|
297
|
+
id: string;
|
|
298
|
+
timestamp: string;
|
|
299
|
+
parentId: string | null;
|
|
300
|
+
ephemeral?: boolean;
|
|
301
|
+
type: "custom_agent.started";
|
|
302
|
+
data: {
|
|
303
|
+
toolCallId: string;
|
|
304
|
+
agentName: string;
|
|
305
|
+
agentDisplayName: string;
|
|
306
|
+
agentDescription: string;
|
|
307
|
+
};
|
|
308
|
+
} | {
|
|
309
|
+
id: string;
|
|
310
|
+
timestamp: string;
|
|
311
|
+
parentId: string | null;
|
|
312
|
+
ephemeral?: boolean;
|
|
313
|
+
type: "custom_agent.completed";
|
|
314
|
+
data: {
|
|
315
|
+
toolCallId: string;
|
|
316
|
+
agentName: string;
|
|
317
|
+
};
|
|
318
|
+
} | {
|
|
319
|
+
id: string;
|
|
320
|
+
timestamp: string;
|
|
321
|
+
parentId: string | null;
|
|
322
|
+
ephemeral?: boolean;
|
|
323
|
+
type: "custom_agent.failed";
|
|
324
|
+
data: {
|
|
325
|
+
toolCallId: string;
|
|
326
|
+
agentName: string;
|
|
327
|
+
error: string;
|
|
328
|
+
};
|
|
329
|
+
} | {
|
|
330
|
+
id: string;
|
|
331
|
+
timestamp: string;
|
|
332
|
+
parentId: string | null;
|
|
333
|
+
ephemeral?: boolean;
|
|
334
|
+
type: "custom_agent.selected";
|
|
335
|
+
data: {
|
|
336
|
+
agentName: string;
|
|
337
|
+
agentDisplayName: string;
|
|
338
|
+
tools: string[] | null;
|
|
339
|
+
};
|
|
340
|
+
} | {
|
|
341
|
+
id: string;
|
|
342
|
+
timestamp: string;
|
|
343
|
+
parentId: string | null;
|
|
344
|
+
ephemeral?: boolean;
|
|
345
|
+
type: "hook.start";
|
|
346
|
+
data: {
|
|
347
|
+
hookInvocationId: string;
|
|
348
|
+
hookType: string;
|
|
349
|
+
input?: unknown;
|
|
350
|
+
};
|
|
351
|
+
} | {
|
|
352
|
+
id: string;
|
|
353
|
+
timestamp: string;
|
|
354
|
+
parentId: string | null;
|
|
355
|
+
ephemeral?: boolean;
|
|
356
|
+
type: "hook.end";
|
|
357
|
+
data: {
|
|
358
|
+
hookInvocationId: string;
|
|
359
|
+
hookType: string;
|
|
360
|
+
output?: unknown;
|
|
361
|
+
success: boolean;
|
|
362
|
+
error?: {
|
|
363
|
+
message: string;
|
|
364
|
+
stack?: string;
|
|
365
|
+
};
|
|
366
|
+
};
|
|
367
|
+
} | {
|
|
368
|
+
id: string;
|
|
369
|
+
timestamp: string;
|
|
370
|
+
parentId: string | null;
|
|
371
|
+
ephemeral?: boolean;
|
|
372
|
+
type: "system.message";
|
|
373
|
+
data: {
|
|
374
|
+
content: string;
|
|
375
|
+
role: "system" | "developer";
|
|
376
|
+
name?: string;
|
|
377
|
+
metadata?: {
|
|
378
|
+
promptVersion?: string;
|
|
379
|
+
variables?: {
|
|
380
|
+
[k: string]: unknown;
|
|
381
|
+
};
|
|
382
|
+
};
|
|
383
|
+
};
|
|
384
|
+
};
|
|
File without changes
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copilot SDK - TypeScript/Node.js Client
|
|
3
|
+
*
|
|
4
|
+
* JSON-RPC based SDK for programmatic control of GitHub Copilot CLI
|
|
5
|
+
*/
|
|
6
|
+
export { CopilotClient } from "./client.js";
|
|
7
|
+
export { CopilotSession } from "./session.js";
|
|
8
|
+
export { defineTool } from "./types.js";
|
|
9
|
+
export type { ConnectionState, CopilotClientOptions, MessageOptions, ResumeSessionConfig, SessionConfig, SessionEvent, SessionEventHandler, SessionMetadata, SystemMessageAppendConfig, SystemMessageConfig, SystemMessageReplaceConfig, Tool, ToolHandler, ToolInvocation, ToolResultObject, ZodSchema, } from "./types.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copilot Session - represents a single conversation session with the CLI
|
|
3
|
+
*/
|
|
4
|
+
import type { MessageConnection } from "vscode-jsonrpc/node";
|
|
5
|
+
import type { MessageOptions, SessionEvent, SessionEventHandler, Tool, ToolHandler } from "./types.js";
|
|
6
|
+
export declare class CopilotSession {
|
|
7
|
+
readonly sessionId: string;
|
|
8
|
+
private connection;
|
|
9
|
+
private eventHandlers;
|
|
10
|
+
private toolHandlers;
|
|
11
|
+
constructor(sessionId: string, connection: MessageConnection);
|
|
12
|
+
/**
|
|
13
|
+
* Send a message to this session
|
|
14
|
+
*/
|
|
15
|
+
send(options: MessageOptions): Promise<string>;
|
|
16
|
+
/**
|
|
17
|
+
* Subscribe to events from this session
|
|
18
|
+
* @returns Unsubscribe function
|
|
19
|
+
*/
|
|
20
|
+
on(handler: SessionEventHandler): () => void;
|
|
21
|
+
/**
|
|
22
|
+
* Internal: dispatch an event to all handlers
|
|
23
|
+
*/
|
|
24
|
+
_dispatchEvent(event: SessionEvent): void;
|
|
25
|
+
registerTools(tools?: Tool[]): void;
|
|
26
|
+
getToolHandler(name: string): ToolHandler | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Get all events/messages from this session
|
|
29
|
+
*/
|
|
30
|
+
getMessages(): Promise<SessionEvent[]>;
|
|
31
|
+
/**
|
|
32
|
+
* Destroy this session and free resources
|
|
33
|
+
*/
|
|
34
|
+
destroy(): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Abort the currently processing message in this session
|
|
37
|
+
*/
|
|
38
|
+
abort(): Promise<void>;
|
|
39
|
+
}
|
package/dist/session.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
class CopilotSession {
|
|
2
|
+
constructor(sessionId, connection) {
|
|
3
|
+
this.sessionId = sessionId;
|
|
4
|
+
this.connection = connection;
|
|
5
|
+
}
|
|
6
|
+
eventHandlers = /* @__PURE__ */ new Set();
|
|
7
|
+
toolHandlers = /* @__PURE__ */ new Map();
|
|
8
|
+
/**
|
|
9
|
+
* Send a message to this session
|
|
10
|
+
*/
|
|
11
|
+
async send(options) {
|
|
12
|
+
const response = await this.connection.sendRequest("session.send", {
|
|
13
|
+
sessionId: this.sessionId,
|
|
14
|
+
prompt: options.prompt,
|
|
15
|
+
attachments: options.attachments,
|
|
16
|
+
mode: options.mode
|
|
17
|
+
});
|
|
18
|
+
return response.messageId;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Subscribe to events from this session
|
|
22
|
+
* @returns Unsubscribe function
|
|
23
|
+
*/
|
|
24
|
+
on(handler) {
|
|
25
|
+
this.eventHandlers.add(handler);
|
|
26
|
+
return () => {
|
|
27
|
+
this.eventHandlers.delete(handler);
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Internal: dispatch an event to all handlers
|
|
32
|
+
*/
|
|
33
|
+
_dispatchEvent(event) {
|
|
34
|
+
for (const handler of this.eventHandlers) {
|
|
35
|
+
try {
|
|
36
|
+
handler(event);
|
|
37
|
+
} catch (_error) {
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
registerTools(tools) {
|
|
42
|
+
this.toolHandlers.clear();
|
|
43
|
+
if (!tools) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
for (const tool of tools) {
|
|
47
|
+
this.toolHandlers.set(tool.name, tool.handler);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
getToolHandler(name) {
|
|
51
|
+
return this.toolHandlers.get(name);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Get all events/messages from this session
|
|
55
|
+
*/
|
|
56
|
+
async getMessages() {
|
|
57
|
+
const response = await this.connection.sendRequest("session.getMessages", {
|
|
58
|
+
sessionId: this.sessionId
|
|
59
|
+
});
|
|
60
|
+
return response.events;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Destroy this session and free resources
|
|
64
|
+
*/
|
|
65
|
+
async destroy() {
|
|
66
|
+
await this.connection.sendRequest("session.destroy", {
|
|
67
|
+
sessionId: this.sessionId
|
|
68
|
+
});
|
|
69
|
+
this.eventHandlers.clear();
|
|
70
|
+
this.toolHandlers.clear();
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Abort the currently processing message in this session
|
|
74
|
+
*/
|
|
75
|
+
async abort() {
|
|
76
|
+
await this.connection.sendRequest("session.abort", {
|
|
77
|
+
sessionId: this.sessionId
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
export {
|
|
82
|
+
CopilotSession
|
|
83
|
+
};
|