@github/copilot-sdk 0.1.19 → 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 +255 -31
- package/dist/client.d.ts +94 -2
- package/dist/client.js +198 -7
- package/dist/generated/session-events.d.ts +55 -2
- package/dist/index.d.ts +1 -1
- package/dist/session.d.ts +61 -2
- package/dist/session.js +106 -29
- package/dist/types.d.ts +309 -2
- package/package.json +7 -7
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
|
*
|
|
@@ -53,6 +57,11 @@ class CopilotClient {
|
|
|
53
57
|
if (options.cliUrl && (options.useStdio === true || options.cliPath)) {
|
|
54
58
|
throw new Error("cliUrl is mutually exclusive with useStdio and cliPath");
|
|
55
59
|
}
|
|
60
|
+
if (options.cliUrl && (options.githubToken || options.useLoggedInUser !== void 0)) {
|
|
61
|
+
throw new Error(
|
|
62
|
+
"githubToken and useLoggedInUser cannot be used with cliUrl (external server manages its own auth)"
|
|
63
|
+
);
|
|
64
|
+
}
|
|
56
65
|
if (options.cliUrl) {
|
|
57
66
|
const { host, port } = this.parseCliUrl(options.cliUrl);
|
|
58
67
|
this.actualHost = host;
|
|
@@ -70,7 +79,10 @@ class CopilotClient {
|
|
|
70
79
|
logLevel: options.logLevel || "debug",
|
|
71
80
|
autoStart: options.autoStart ?? true,
|
|
72
81
|
autoRestart: options.autoRestart ?? true,
|
|
73
|
-
env: options.env ?? process.env
|
|
82
|
+
env: options.env ?? process.env,
|
|
83
|
+
githubToken: options.githubToken,
|
|
84
|
+
// Default useLoggedInUser to false when githubToken is provided, otherwise true
|
|
85
|
+
useLoggedInUser: options.useLoggedInUser ?? (options.githubToken ? false : true)
|
|
74
86
|
};
|
|
75
87
|
}
|
|
76
88
|
/**
|
|
@@ -188,6 +200,7 @@ class CopilotClient {
|
|
|
188
200
|
}
|
|
189
201
|
this.connection = null;
|
|
190
202
|
}
|
|
203
|
+
this.modelsCache = null;
|
|
191
204
|
if (this.socket) {
|
|
192
205
|
try {
|
|
193
206
|
this.socket.end();
|
|
@@ -251,6 +264,7 @@ class CopilotClient {
|
|
|
251
264
|
}
|
|
252
265
|
this.connection = null;
|
|
253
266
|
}
|
|
267
|
+
this.modelsCache = null;
|
|
254
268
|
if (this.socket) {
|
|
255
269
|
try {
|
|
256
270
|
this.socket.destroy();
|
|
@@ -307,6 +321,7 @@ class CopilotClient {
|
|
|
307
321
|
const response = await this.connection.sendRequest("session.create", {
|
|
308
322
|
model: config.model,
|
|
309
323
|
sessionId: config.sessionId,
|
|
324
|
+
reasoningEffort: config.reasoningEffort,
|
|
310
325
|
tools: config.tools?.map((tool) => ({
|
|
311
326
|
name: tool.name,
|
|
312
327
|
description: tool.description,
|
|
@@ -317,6 +332,9 @@ class CopilotClient {
|
|
|
317
332
|
excludedTools: config.excludedTools,
|
|
318
333
|
provider: config.provider,
|
|
319
334
|
requestPermission: !!config.onPermissionRequest,
|
|
335
|
+
requestUserInput: !!config.onUserInputRequest,
|
|
336
|
+
hooks: !!(config.hooks && Object.values(config.hooks).some(Boolean)),
|
|
337
|
+
workingDirectory: config.workingDirectory,
|
|
320
338
|
streaming: config.streaming,
|
|
321
339
|
mcpServers: config.mcpServers,
|
|
322
340
|
customAgents: config.customAgents,
|
|
@@ -331,6 +349,12 @@ class CopilotClient {
|
|
|
331
349
|
if (config.onPermissionRequest) {
|
|
332
350
|
session.registerPermissionHandler(config.onPermissionRequest);
|
|
333
351
|
}
|
|
352
|
+
if (config.onUserInputRequest) {
|
|
353
|
+
session.registerUserInputHandler(config.onUserInputRequest);
|
|
354
|
+
}
|
|
355
|
+
if (config.hooks) {
|
|
356
|
+
session.registerHooks(config.hooks);
|
|
357
|
+
}
|
|
334
358
|
this.sessions.set(sessionId, session);
|
|
335
359
|
return session;
|
|
336
360
|
}
|
|
@@ -367,6 +391,7 @@ class CopilotClient {
|
|
|
367
391
|
}
|
|
368
392
|
const response = await this.connection.sendRequest("session.resume", {
|
|
369
393
|
sessionId,
|
|
394
|
+
reasoningEffort: config.reasoningEffort,
|
|
370
395
|
tools: config.tools?.map((tool) => ({
|
|
371
396
|
name: tool.name,
|
|
372
397
|
description: tool.description,
|
|
@@ -374,11 +399,15 @@ class CopilotClient {
|
|
|
374
399
|
})),
|
|
375
400
|
provider: config.provider,
|
|
376
401
|
requestPermission: !!config.onPermissionRequest,
|
|
402
|
+
requestUserInput: !!config.onUserInputRequest,
|
|
403
|
+
hooks: !!(config.hooks && Object.values(config.hooks).some(Boolean)),
|
|
404
|
+
workingDirectory: config.workingDirectory,
|
|
377
405
|
streaming: config.streaming,
|
|
378
406
|
mcpServers: config.mcpServers,
|
|
379
407
|
customAgents: config.customAgents,
|
|
380
408
|
skillDirectories: config.skillDirectories,
|
|
381
|
-
disabledSkills: config.disabledSkills
|
|
409
|
+
disabledSkills: config.disabledSkills,
|
|
410
|
+
disableResume: config.disableResume
|
|
382
411
|
});
|
|
383
412
|
const { sessionId: resumedSessionId, workspacePath } = response;
|
|
384
413
|
const session = new CopilotSession(resumedSessionId, this.connection, workspacePath);
|
|
@@ -386,6 +415,12 @@ class CopilotClient {
|
|
|
386
415
|
if (config.onPermissionRequest) {
|
|
387
416
|
session.registerPermissionHandler(config.onPermissionRequest);
|
|
388
417
|
}
|
|
418
|
+
if (config.onUserInputRequest) {
|
|
419
|
+
session.registerUserInputHandler(config.onUserInputRequest);
|
|
420
|
+
}
|
|
421
|
+
if (config.hooks) {
|
|
422
|
+
session.registerHooks(config.hooks);
|
|
423
|
+
}
|
|
389
424
|
this.sessions.set(resumedSessionId, session);
|
|
390
425
|
return session;
|
|
391
426
|
}
|
|
@@ -445,16 +480,34 @@ class CopilotClient {
|
|
|
445
480
|
return result;
|
|
446
481
|
}
|
|
447
482
|
/**
|
|
448
|
-
* 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
|
+
*
|
|
449
488
|
* @throws Error if not authenticated
|
|
450
489
|
*/
|
|
451
490
|
async listModels() {
|
|
452
491
|
if (!this.connection) {
|
|
453
492
|
throw new Error("Client not connected");
|
|
454
493
|
}
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
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
|
+
}
|
|
458
511
|
}
|
|
459
512
|
/**
|
|
460
513
|
* Verify that the server's protocol version matches the SDK's expected version
|
|
@@ -556,6 +609,77 @@ class CopilotClient {
|
|
|
556
609
|
isRemote: s.isRemote
|
|
557
610
|
}));
|
|
558
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
|
+
}
|
|
559
683
|
/**
|
|
560
684
|
* Start the CLI server process
|
|
561
685
|
*/
|
|
@@ -563,7 +687,7 @@ class CopilotClient {
|
|
|
563
687
|
return new Promise((resolve, reject) => {
|
|
564
688
|
const args = [
|
|
565
689
|
...this.options.cliArgs,
|
|
566
|
-
"--
|
|
690
|
+
"--headless",
|
|
567
691
|
"--log-level",
|
|
568
692
|
this.options.logLevel
|
|
569
693
|
];
|
|
@@ -572,8 +696,17 @@ class CopilotClient {
|
|
|
572
696
|
} else if (this.options.port > 0) {
|
|
573
697
|
args.push("--port", this.options.port.toString());
|
|
574
698
|
}
|
|
699
|
+
if (this.options.githubToken) {
|
|
700
|
+
args.push("--auth-token-env", "COPILOT_SDK_AUTH_TOKEN");
|
|
701
|
+
}
|
|
702
|
+
if (!this.options.useLoggedInUser) {
|
|
703
|
+
args.push("--no-auto-login");
|
|
704
|
+
}
|
|
575
705
|
const envWithoutNodeDebug = { ...this.options.env };
|
|
576
706
|
delete envWithoutNodeDebug.NODE_DEBUG;
|
|
707
|
+
if (this.options.githubToken) {
|
|
708
|
+
envWithoutNodeDebug.COPILOT_SDK_AUTH_TOKEN = this.options.githubToken;
|
|
709
|
+
}
|
|
577
710
|
const isJsFile = this.options.cliPath.endsWith(".js");
|
|
578
711
|
const isAbsolutePath = this.options.cliPath.startsWith("/") || /^[a-zA-Z]:/.test(this.options.cliPath);
|
|
579
712
|
let command;
|
|
@@ -699,6 +832,9 @@ class CopilotClient {
|
|
|
699
832
|
this.connection.onNotification("session.event", (notification) => {
|
|
700
833
|
this.handleSessionEventNotification(notification);
|
|
701
834
|
});
|
|
835
|
+
this.connection.onNotification("session.lifecycle", (notification) => {
|
|
836
|
+
this.handleSessionLifecycleNotification(notification);
|
|
837
|
+
});
|
|
702
838
|
this.connection.onRequest(
|
|
703
839
|
"tool.call",
|
|
704
840
|
async (params) => await this.handleToolCallRequest(params)
|
|
@@ -707,6 +843,14 @@ class CopilotClient {
|
|
|
707
843
|
"permission.request",
|
|
708
844
|
async (params) => await this.handlePermissionRequest(params)
|
|
709
845
|
);
|
|
846
|
+
this.connection.onRequest(
|
|
847
|
+
"userInput.request",
|
|
848
|
+
async (params) => await this.handleUserInputRequest(params)
|
|
849
|
+
);
|
|
850
|
+
this.connection.onRequest(
|
|
851
|
+
"hooks.invoke",
|
|
852
|
+
async (params) => await this.handleHooksInvoke(params)
|
|
853
|
+
);
|
|
710
854
|
this.connection.onClose(() => {
|
|
711
855
|
if (this.state === "connected" && this.options.autoRestart) {
|
|
712
856
|
void this.reconnect();
|
|
@@ -724,6 +868,27 @@ class CopilotClient {
|
|
|
724
868
|
session._dispatchEvent(notification.event);
|
|
725
869
|
}
|
|
726
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
|
+
}
|
|
727
892
|
async handleToolCallRequest(params) {
|
|
728
893
|
if (!params || typeof params.sessionId !== "string" || typeof params.toolCallId !== "string" || typeof params.toolName !== "string") {
|
|
729
894
|
throw new Error("Invalid tool call payload");
|
|
@@ -780,6 +945,32 @@ class CopilotClient {
|
|
|
780
945
|
};
|
|
781
946
|
}
|
|
782
947
|
}
|
|
948
|
+
async handleUserInputRequest(params) {
|
|
949
|
+
if (!params || typeof params.sessionId !== "string" || typeof params.question !== "string") {
|
|
950
|
+
throw new Error("Invalid user input request payload");
|
|
951
|
+
}
|
|
952
|
+
const session = this.sessions.get(params.sessionId);
|
|
953
|
+
if (!session) {
|
|
954
|
+
throw new Error(`Session not found: ${params.sessionId}`);
|
|
955
|
+
}
|
|
956
|
+
const result = await session._handleUserInputRequest({
|
|
957
|
+
question: params.question,
|
|
958
|
+
choices: params.choices,
|
|
959
|
+
allowFreeform: params.allowFreeform
|
|
960
|
+
});
|
|
961
|
+
return result;
|
|
962
|
+
}
|
|
963
|
+
async handleHooksInvoke(params) {
|
|
964
|
+
if (!params || typeof params.sessionId !== "string" || typeof params.hookType !== "string") {
|
|
965
|
+
throw new Error("Invalid hooks invoke payload");
|
|
966
|
+
}
|
|
967
|
+
const session = this.sessions.get(params.sessionId);
|
|
968
|
+
if (!session) {
|
|
969
|
+
throw new Error(`Session not found: ${params.sessionId}`);
|
|
970
|
+
}
|
|
971
|
+
const output = await session._handleHooksInvoke(params.hookType, params.input);
|
|
972
|
+
return { output };
|
|
973
|
+
}
|
|
783
974
|
normalizeToolResult(result) {
|
|
784
975
|
if (result === void 0 || result === null) {
|
|
785
976
|
return {
|
|
@@ -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, SessionMetadata, SystemMessageAppendConfig, SystemMessageConfig, SystemMessageReplaceConfig, Tool, ToolHandler, ToolInvocation, ToolResultObject, 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/session.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @module session
|
|
4
4
|
*/
|
|
5
5
|
import type { MessageConnection } from "vscode-jsonrpc/node";
|
|
6
|
-
import type { MessageOptions, PermissionHandler, PermissionRequestResult, SessionEvent, SessionEventHandler, Tool, ToolHandler } from "./types.js";
|
|
6
|
+
import type { MessageOptions, PermissionHandler, PermissionRequestResult, SessionEvent, SessionEventHandler, SessionEventType, SessionHooks, Tool, ToolHandler, TypedSessionEventHandler, UserInputHandler, UserInputResponse } from "./types.js";
|
|
7
7
|
/** Assistant message event - the final response from the assistant. */
|
|
8
8
|
export type AssistantMessageEvent = Extract<SessionEvent, {
|
|
9
9
|
type: "assistant.message";
|
|
@@ -38,8 +38,11 @@ export declare class CopilotSession {
|
|
|
38
38
|
private connection;
|
|
39
39
|
private readonly _workspacePath?;
|
|
40
40
|
private eventHandlers;
|
|
41
|
+
private typedEventHandlers;
|
|
41
42
|
private toolHandlers;
|
|
42
43
|
private permissionHandler?;
|
|
44
|
+
private userInputHandler?;
|
|
45
|
+
private hooks?;
|
|
43
46
|
/**
|
|
44
47
|
* Creates a new CopilotSession instance.
|
|
45
48
|
*
|
|
@@ -104,7 +107,26 @@ export declare class CopilotSession {
|
|
|
104
107
|
* Events include assistant messages, tool executions, errors, and session state changes.
|
|
105
108
|
* Multiple handlers can be registered and will all receive events.
|
|
106
109
|
*
|
|
107
|
-
* @param
|
|
110
|
+
* @param eventType - The specific event type to listen for (e.g., "assistant.message", "session.idle")
|
|
111
|
+
* @param handler - A callback function that receives events of the specified type
|
|
112
|
+
* @returns A function that, when called, unsubscribes the handler
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* // Listen for a specific event type
|
|
117
|
+
* const unsubscribe = session.on("assistant.message", (event) => {
|
|
118
|
+
* console.log("Assistant:", event.data.content);
|
|
119
|
+
* });
|
|
120
|
+
*
|
|
121
|
+
* // Later, to stop receiving events:
|
|
122
|
+
* unsubscribe();
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
on<K extends SessionEventType>(eventType: K, handler: TypedSessionEventHandler<K>): () => void;
|
|
126
|
+
/**
|
|
127
|
+
* Subscribes to all events from this session.
|
|
128
|
+
*
|
|
129
|
+
* @param handler - A callback function that receives all session events
|
|
108
130
|
* @returns A function that, when called, unsubscribes the handler
|
|
109
131
|
*
|
|
110
132
|
* @example
|
|
@@ -160,6 +182,26 @@ export declare class CopilotSession {
|
|
|
160
182
|
* @internal This method is typically called internally when creating a session.
|
|
161
183
|
*/
|
|
162
184
|
registerPermissionHandler(handler?: PermissionHandler): void;
|
|
185
|
+
/**
|
|
186
|
+
* Registers a user input handler for ask_user requests.
|
|
187
|
+
*
|
|
188
|
+
* When the agent needs input from the user (via ask_user tool),
|
|
189
|
+
* this handler is called to provide the response.
|
|
190
|
+
*
|
|
191
|
+
* @param handler - The user input handler function, or undefined to remove the handler
|
|
192
|
+
* @internal This method is typically called internally when creating a session.
|
|
193
|
+
*/
|
|
194
|
+
registerUserInputHandler(handler?: UserInputHandler): void;
|
|
195
|
+
/**
|
|
196
|
+
* Registers hook handlers for session lifecycle events.
|
|
197
|
+
*
|
|
198
|
+
* Hooks allow custom logic to be executed at various points during
|
|
199
|
+
* the session lifecycle (before/after tool use, session start/end, etc.).
|
|
200
|
+
*
|
|
201
|
+
* @param hooks - The hook handlers object, or undefined to remove all hooks
|
|
202
|
+
* @internal This method is typically called internally when creating a session.
|
|
203
|
+
*/
|
|
204
|
+
registerHooks(hooks?: SessionHooks): void;
|
|
163
205
|
/**
|
|
164
206
|
* Handles a permission request from the Copilot CLI.
|
|
165
207
|
*
|
|
@@ -168,6 +210,23 @@ export declare class CopilotSession {
|
|
|
168
210
|
* @internal This method is for internal use by the SDK.
|
|
169
211
|
*/
|
|
170
212
|
_handlePermissionRequest(request: unknown): Promise<PermissionRequestResult>;
|
|
213
|
+
/**
|
|
214
|
+
* Handles a user input request from the Copilot CLI.
|
|
215
|
+
*
|
|
216
|
+
* @param request - The user input request data from the CLI
|
|
217
|
+
* @returns A promise that resolves with the user's response
|
|
218
|
+
* @internal This method is for internal use by the SDK.
|
|
219
|
+
*/
|
|
220
|
+
_handleUserInputRequest(request: unknown): Promise<UserInputResponse>;
|
|
221
|
+
/**
|
|
222
|
+
* Handles a hooks invocation from the Copilot CLI.
|
|
223
|
+
*
|
|
224
|
+
* @param hookType - The type of hook being invoked
|
|
225
|
+
* @param input - The input data for the hook
|
|
226
|
+
* @returns A promise that resolves with the hook output, or undefined
|
|
227
|
+
* @internal This method is for internal use by the SDK.
|
|
228
|
+
*/
|
|
229
|
+
_handleHooksInvoke(hookType: string, input: unknown): Promise<unknown>;
|
|
171
230
|
/**
|
|
172
231
|
* Retrieves all events and messages from this session's history.
|
|
173
232
|
*
|