@github/copilot-sdk 1.0.0-beta.2 → 1.0.0-beta.3
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 -1
- package/dist/cjs/client.js +55 -0
- package/dist/cjs/session.js +44 -0
- package/dist/cjs/types.js +2 -1
- package/dist/client.d.ts +2 -0
- package/dist/client.js +55 -0
- package/dist/generated/session-events.d.ts +9 -4
- package/dist/index.d.ts +1 -1
- package/dist/session.d.ts +27 -1
- package/dist/session.js +44 -0
- package/dist/sessionFsProvider.d.ts +1 -1
- package/dist/types.d.ts +69 -1
- package/dist/types.js +2 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -38,7 +38,7 @@ const session = await client.createSession({
|
|
|
38
38
|
onPermissionRequest: approveAll,
|
|
39
39
|
});
|
|
40
40
|
|
|
41
|
-
// Wait for response using typed event handlers
|
|
41
|
+
// Wait for the response using typed event handlers
|
|
42
42
|
const done = new Promise<void>((resolve) => {
|
|
43
43
|
session.on("assistant.message", (event) => {
|
|
44
44
|
console.log(event.data.content);
|
package/dist/cjs/client.js
CHANGED
|
@@ -530,6 +530,12 @@ class CopilotClient {
|
|
|
530
530
|
if (config.onElicitationRequest) {
|
|
531
531
|
session.registerElicitationHandler(config.onElicitationRequest);
|
|
532
532
|
}
|
|
533
|
+
if (config.onExitPlanMode) {
|
|
534
|
+
session.registerExitPlanModeHandler(config.onExitPlanMode);
|
|
535
|
+
}
|
|
536
|
+
if (config.onAutoModeSwitch) {
|
|
537
|
+
session.registerAutoModeSwitchHandler(config.onAutoModeSwitch);
|
|
538
|
+
}
|
|
533
539
|
if (config.hooks) {
|
|
534
540
|
session.registerHooks(config.hooks);
|
|
535
541
|
}
|
|
@@ -576,10 +582,13 @@ class CopilotClient {
|
|
|
576
582
|
availableTools: config.availableTools,
|
|
577
583
|
excludedTools: config.excludedTools,
|
|
578
584
|
provider: config.provider ? toWireProviderConfig(config.provider) : void 0,
|
|
585
|
+
enableSessionTelemetry: config.enableSessionTelemetry,
|
|
579
586
|
modelCapabilities: config.modelCapabilities,
|
|
580
587
|
requestPermission: true,
|
|
581
588
|
requestUserInput: !!config.onUserInputRequest,
|
|
582
589
|
requestElicitation: !!config.onElicitationRequest,
|
|
590
|
+
requestExitPlanMode: !!config.onExitPlanMode,
|
|
591
|
+
requestAutoModeSwitch: !!config.onAutoModeSwitch,
|
|
583
592
|
hooks: !!(config.hooks && Object.values(config.hooks).some(Boolean)),
|
|
584
593
|
workingDirectory: config.workingDirectory,
|
|
585
594
|
streaming: config.streaming,
|
|
@@ -658,6 +667,12 @@ class CopilotClient {
|
|
|
658
667
|
if (config.onElicitationRequest) {
|
|
659
668
|
session.registerElicitationHandler(config.onElicitationRequest);
|
|
660
669
|
}
|
|
670
|
+
if (config.onExitPlanMode) {
|
|
671
|
+
session.registerExitPlanModeHandler(config.onExitPlanMode);
|
|
672
|
+
}
|
|
673
|
+
if (config.onAutoModeSwitch) {
|
|
674
|
+
session.registerAutoModeSwitchHandler(config.onAutoModeSwitch);
|
|
675
|
+
}
|
|
661
676
|
if (config.hooks) {
|
|
662
677
|
session.registerHooks(config.hooks);
|
|
663
678
|
}
|
|
@@ -692,6 +707,7 @@ class CopilotClient {
|
|
|
692
707
|
systemMessage: wireSystemMessage,
|
|
693
708
|
availableTools: config.availableTools,
|
|
694
709
|
excludedTools: config.excludedTools,
|
|
710
|
+
enableSessionTelemetry: config.enableSessionTelemetry,
|
|
695
711
|
tools: config.tools?.map((tool) => ({
|
|
696
712
|
name: tool.name,
|
|
697
713
|
description: tool.description,
|
|
@@ -708,6 +724,8 @@ class CopilotClient {
|
|
|
708
724
|
requestPermission: config.onPermissionRequest !== import_types.defaultJoinSessionPermissionHandler,
|
|
709
725
|
requestUserInput: !!config.onUserInputRequest,
|
|
710
726
|
requestElicitation: !!config.onElicitationRequest,
|
|
727
|
+
requestExitPlanMode: !!config.onExitPlanMode,
|
|
728
|
+
requestAutoModeSwitch: !!config.onAutoModeSwitch,
|
|
711
729
|
hooks: !!(config.hooks && Object.values(config.hooks).some(Boolean)),
|
|
712
730
|
workingDirectory: config.workingDirectory,
|
|
713
731
|
configDir: config.configDir,
|
|
@@ -1332,6 +1350,14 @@ stderr: ${stderrOutput}`
|
|
|
1332
1350
|
"userInput.request",
|
|
1333
1351
|
async (params) => await this.handleUserInputRequest(params)
|
|
1334
1352
|
);
|
|
1353
|
+
this.connection.onRequest(
|
|
1354
|
+
"exitPlanMode.request",
|
|
1355
|
+
async (params) => await this.handleExitPlanModeRequest(params)
|
|
1356
|
+
);
|
|
1357
|
+
this.connection.onRequest(
|
|
1358
|
+
"autoModeSwitch.request",
|
|
1359
|
+
async (params) => await this.handleAutoModeSwitchRequest(params)
|
|
1360
|
+
);
|
|
1335
1361
|
this.connection.onRequest(
|
|
1336
1362
|
"hooks.invoke",
|
|
1337
1363
|
async (params) => await this.handleHooksInvoke(params)
|
|
@@ -1398,6 +1424,35 @@ stderr: ${stderrOutput}`
|
|
|
1398
1424
|
});
|
|
1399
1425
|
return result;
|
|
1400
1426
|
}
|
|
1427
|
+
async handleExitPlanModeRequest(params) {
|
|
1428
|
+
if (!params || typeof params.sessionId !== "string" || typeof params.summary !== "string" || !Array.isArray(params.actions) || typeof params.recommendedAction !== "string") {
|
|
1429
|
+
throw new Error("Invalid exit plan mode request payload");
|
|
1430
|
+
}
|
|
1431
|
+
const session = this.sessions.get(params.sessionId);
|
|
1432
|
+
if (!session) {
|
|
1433
|
+
throw new Error(`Session not found: ${params.sessionId}`);
|
|
1434
|
+
}
|
|
1435
|
+
return await session._handleExitPlanModeRequest({
|
|
1436
|
+
summary: params.summary,
|
|
1437
|
+
planContent: params.planContent,
|
|
1438
|
+
actions: params.actions,
|
|
1439
|
+
recommendedAction: params.recommendedAction
|
|
1440
|
+
});
|
|
1441
|
+
}
|
|
1442
|
+
async handleAutoModeSwitchRequest(params) {
|
|
1443
|
+
if (!params || typeof params.sessionId !== "string") {
|
|
1444
|
+
throw new Error("Invalid auto mode switch request payload");
|
|
1445
|
+
}
|
|
1446
|
+
const session = this.sessions.get(params.sessionId);
|
|
1447
|
+
if (!session) {
|
|
1448
|
+
throw new Error(`Session not found: ${params.sessionId}`);
|
|
1449
|
+
}
|
|
1450
|
+
const response = await session._handleAutoModeSwitchRequest({
|
|
1451
|
+
errorCode: params.errorCode,
|
|
1452
|
+
retryAfterSeconds: params.retryAfterSeconds
|
|
1453
|
+
});
|
|
1454
|
+
return { response };
|
|
1455
|
+
}
|
|
1401
1456
|
async handleHooksInvoke(params) {
|
|
1402
1457
|
if (!params || typeof params.sessionId !== "string" || typeof params.hookType !== "string") {
|
|
1403
1458
|
throw new Error("Invalid hooks invoke payload");
|
package/dist/cjs/session.js
CHANGED
|
@@ -49,6 +49,8 @@ class CopilotSession {
|
|
|
49
49
|
permissionHandler;
|
|
50
50
|
userInputHandler;
|
|
51
51
|
elicitationHandler;
|
|
52
|
+
exitPlanModeHandler;
|
|
53
|
+
autoModeSwitchHandler;
|
|
52
54
|
hooks;
|
|
53
55
|
transformCallbacks;
|
|
54
56
|
_rpc = null;
|
|
@@ -444,6 +446,24 @@ class CopilotSession {
|
|
|
444
446
|
registerElicitationHandler(handler) {
|
|
445
447
|
this.elicitationHandler = handler;
|
|
446
448
|
}
|
|
449
|
+
/**
|
|
450
|
+
* Registers the exit-plan-mode handler for this session.
|
|
451
|
+
*
|
|
452
|
+
* @param handler - The handler to invoke when the server dispatches an exit-plan-mode request
|
|
453
|
+
* @internal This method is typically called internally when creating/resuming a session.
|
|
454
|
+
*/
|
|
455
|
+
registerExitPlanModeHandler(handler) {
|
|
456
|
+
this.exitPlanModeHandler = handler;
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Registers the auto-mode-switch handler for this session.
|
|
460
|
+
*
|
|
461
|
+
* @param handler - The handler to invoke when the server dispatches an auto-mode-switch request
|
|
462
|
+
* @internal This method is typically called internally when creating/resuming a session.
|
|
463
|
+
*/
|
|
464
|
+
registerAutoModeSwitchHandler(handler) {
|
|
465
|
+
this.autoModeSwitchHandler = handler;
|
|
466
|
+
}
|
|
447
467
|
/**
|
|
448
468
|
* Handles an elicitation.requested broadcast event.
|
|
449
469
|
* Invokes the registered handler and responds via handlePendingElicitation RPC.
|
|
@@ -469,6 +489,26 @@ class CopilotSession {
|
|
|
469
489
|
}
|
|
470
490
|
}
|
|
471
491
|
}
|
|
492
|
+
/**
|
|
493
|
+
* Handles an exitPlanMode.request callback from the runtime.
|
|
494
|
+
* @internal
|
|
495
|
+
*/
|
|
496
|
+
async _handleExitPlanModeRequest(request) {
|
|
497
|
+
if (!this.exitPlanModeHandler) {
|
|
498
|
+
return { approved: true };
|
|
499
|
+
}
|
|
500
|
+
return await this.exitPlanModeHandler(request, { sessionId: this.sessionId });
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* Handles an autoModeSwitch.request callback from the runtime.
|
|
504
|
+
* @internal
|
|
505
|
+
*/
|
|
506
|
+
async _handleAutoModeSwitchRequest(request) {
|
|
507
|
+
if (!this.autoModeSwitchHandler) {
|
|
508
|
+
return "no";
|
|
509
|
+
}
|
|
510
|
+
return await this.autoModeSwitchHandler(request, { sessionId: this.sessionId });
|
|
511
|
+
}
|
|
472
512
|
/**
|
|
473
513
|
* Sets the host capabilities for this session.
|
|
474
514
|
*
|
|
@@ -749,6 +789,10 @@ class CopilotSession {
|
|
|
749
789
|
this.typedEventHandlers.clear();
|
|
750
790
|
this.toolHandlers.clear();
|
|
751
791
|
this.permissionHandler = void 0;
|
|
792
|
+
this.userInputHandler = void 0;
|
|
793
|
+
this.elicitationHandler = void 0;
|
|
794
|
+
this.exitPlanModeHandler = void 0;
|
|
795
|
+
this.autoModeSwitchHandler = void 0;
|
|
752
796
|
}
|
|
753
797
|
/**
|
|
754
798
|
* @deprecated Use {@link disconnect} instead. This method will be removed in a future release.
|
package/dist/cjs/types.js
CHANGED
|
@@ -51,9 +51,10 @@ function convertMcpCallToolResult(callResult) {
|
|
|
51
51
|
textParts.push(block.resource.text);
|
|
52
52
|
}
|
|
53
53
|
if (block.resource?.blob) {
|
|
54
|
+
const mimeType = block.resource.mimeType;
|
|
54
55
|
binaryResults.push({
|
|
55
56
|
data: block.resource.blob,
|
|
56
|
-
mimeType:
|
|
57
|
+
mimeType: typeof mimeType === "string" && mimeType ? mimeType : "application/octet-stream",
|
|
57
58
|
type: "resource",
|
|
58
59
|
description: block.resource.uri
|
|
59
60
|
});
|
package/dist/client.d.ts
CHANGED
|
@@ -455,6 +455,8 @@ export declare class CopilotClient {
|
|
|
455
455
|
private handleSessionEventNotification;
|
|
456
456
|
private handleSessionLifecycleNotification;
|
|
457
457
|
private handleUserInputRequest;
|
|
458
|
+
private handleExitPlanModeRequest;
|
|
459
|
+
private handleAutoModeSwitchRequest;
|
|
458
460
|
private handleHooksInvoke;
|
|
459
461
|
private handleSystemMessageTransform;
|
|
460
462
|
/**
|
package/dist/client.js
CHANGED
|
@@ -516,6 +516,12 @@ class CopilotClient {
|
|
|
516
516
|
if (config.onElicitationRequest) {
|
|
517
517
|
session.registerElicitationHandler(config.onElicitationRequest);
|
|
518
518
|
}
|
|
519
|
+
if (config.onExitPlanMode) {
|
|
520
|
+
session.registerExitPlanModeHandler(config.onExitPlanMode);
|
|
521
|
+
}
|
|
522
|
+
if (config.onAutoModeSwitch) {
|
|
523
|
+
session.registerAutoModeSwitchHandler(config.onAutoModeSwitch);
|
|
524
|
+
}
|
|
519
525
|
if (config.hooks) {
|
|
520
526
|
session.registerHooks(config.hooks);
|
|
521
527
|
}
|
|
@@ -562,10 +568,13 @@ class CopilotClient {
|
|
|
562
568
|
availableTools: config.availableTools,
|
|
563
569
|
excludedTools: config.excludedTools,
|
|
564
570
|
provider: config.provider ? toWireProviderConfig(config.provider) : void 0,
|
|
571
|
+
enableSessionTelemetry: config.enableSessionTelemetry,
|
|
565
572
|
modelCapabilities: config.modelCapabilities,
|
|
566
573
|
requestPermission: true,
|
|
567
574
|
requestUserInput: !!config.onUserInputRequest,
|
|
568
575
|
requestElicitation: !!config.onElicitationRequest,
|
|
576
|
+
requestExitPlanMode: !!config.onExitPlanMode,
|
|
577
|
+
requestAutoModeSwitch: !!config.onAutoModeSwitch,
|
|
569
578
|
hooks: !!(config.hooks && Object.values(config.hooks).some(Boolean)),
|
|
570
579
|
workingDirectory: config.workingDirectory,
|
|
571
580
|
streaming: config.streaming,
|
|
@@ -644,6 +653,12 @@ class CopilotClient {
|
|
|
644
653
|
if (config.onElicitationRequest) {
|
|
645
654
|
session.registerElicitationHandler(config.onElicitationRequest);
|
|
646
655
|
}
|
|
656
|
+
if (config.onExitPlanMode) {
|
|
657
|
+
session.registerExitPlanModeHandler(config.onExitPlanMode);
|
|
658
|
+
}
|
|
659
|
+
if (config.onAutoModeSwitch) {
|
|
660
|
+
session.registerAutoModeSwitchHandler(config.onAutoModeSwitch);
|
|
661
|
+
}
|
|
647
662
|
if (config.hooks) {
|
|
648
663
|
session.registerHooks(config.hooks);
|
|
649
664
|
}
|
|
@@ -678,6 +693,7 @@ class CopilotClient {
|
|
|
678
693
|
systemMessage: wireSystemMessage,
|
|
679
694
|
availableTools: config.availableTools,
|
|
680
695
|
excludedTools: config.excludedTools,
|
|
696
|
+
enableSessionTelemetry: config.enableSessionTelemetry,
|
|
681
697
|
tools: config.tools?.map((tool) => ({
|
|
682
698
|
name: tool.name,
|
|
683
699
|
description: tool.description,
|
|
@@ -694,6 +710,8 @@ class CopilotClient {
|
|
|
694
710
|
requestPermission: config.onPermissionRequest !== defaultJoinSessionPermissionHandler,
|
|
695
711
|
requestUserInput: !!config.onUserInputRequest,
|
|
696
712
|
requestElicitation: !!config.onElicitationRequest,
|
|
713
|
+
requestExitPlanMode: !!config.onExitPlanMode,
|
|
714
|
+
requestAutoModeSwitch: !!config.onAutoModeSwitch,
|
|
697
715
|
hooks: !!(config.hooks && Object.values(config.hooks).some(Boolean)),
|
|
698
716
|
workingDirectory: config.workingDirectory,
|
|
699
717
|
configDir: config.configDir,
|
|
@@ -1318,6 +1336,14 @@ stderr: ${stderrOutput}`
|
|
|
1318
1336
|
"userInput.request",
|
|
1319
1337
|
async (params) => await this.handleUserInputRequest(params)
|
|
1320
1338
|
);
|
|
1339
|
+
this.connection.onRequest(
|
|
1340
|
+
"exitPlanMode.request",
|
|
1341
|
+
async (params) => await this.handleExitPlanModeRequest(params)
|
|
1342
|
+
);
|
|
1343
|
+
this.connection.onRequest(
|
|
1344
|
+
"autoModeSwitch.request",
|
|
1345
|
+
async (params) => await this.handleAutoModeSwitchRequest(params)
|
|
1346
|
+
);
|
|
1321
1347
|
this.connection.onRequest(
|
|
1322
1348
|
"hooks.invoke",
|
|
1323
1349
|
async (params) => await this.handleHooksInvoke(params)
|
|
@@ -1384,6 +1410,35 @@ stderr: ${stderrOutput}`
|
|
|
1384
1410
|
});
|
|
1385
1411
|
return result;
|
|
1386
1412
|
}
|
|
1413
|
+
async handleExitPlanModeRequest(params) {
|
|
1414
|
+
if (!params || typeof params.sessionId !== "string" || typeof params.summary !== "string" || !Array.isArray(params.actions) || typeof params.recommendedAction !== "string") {
|
|
1415
|
+
throw new Error("Invalid exit plan mode request payload");
|
|
1416
|
+
}
|
|
1417
|
+
const session = this.sessions.get(params.sessionId);
|
|
1418
|
+
if (!session) {
|
|
1419
|
+
throw new Error(`Session not found: ${params.sessionId}`);
|
|
1420
|
+
}
|
|
1421
|
+
return await session._handleExitPlanModeRequest({
|
|
1422
|
+
summary: params.summary,
|
|
1423
|
+
planContent: params.planContent,
|
|
1424
|
+
actions: params.actions,
|
|
1425
|
+
recommendedAction: params.recommendedAction
|
|
1426
|
+
});
|
|
1427
|
+
}
|
|
1428
|
+
async handleAutoModeSwitchRequest(params) {
|
|
1429
|
+
if (!params || typeof params.sessionId !== "string") {
|
|
1430
|
+
throw new Error("Invalid auto mode switch request payload");
|
|
1431
|
+
}
|
|
1432
|
+
const session = this.sessions.get(params.sessionId);
|
|
1433
|
+
if (!session) {
|
|
1434
|
+
throw new Error(`Session not found: ${params.sessionId}`);
|
|
1435
|
+
}
|
|
1436
|
+
const response = await session._handleAutoModeSwitchRequest({
|
|
1437
|
+
errorCode: params.errorCode,
|
|
1438
|
+
retryAfterSeconds: params.retryAfterSeconds
|
|
1439
|
+
});
|
|
1440
|
+
return { response };
|
|
1441
|
+
}
|
|
1387
1442
|
async handleHooksInvoke(params) {
|
|
1388
1443
|
if (!params || typeof params.sessionId !== "string" || typeof params.hookType !== "string") {
|
|
1389
1444
|
throw new Error("Invalid hooks invoke payload");
|
|
@@ -43,6 +43,10 @@ export type AssistantMessageToolRequestType = "function" | "custom";
|
|
|
43
43
|
* Where the failed model call originated
|
|
44
44
|
*/
|
|
45
45
|
export type ModelCallFailureSource = "top_level" | "subagent" | "mcp_sampling";
|
|
46
|
+
/**
|
|
47
|
+
* Finite reason code describing why the current turn was aborted
|
|
48
|
+
*/
|
|
49
|
+
export type AbortReason = "user_initiated" | "remote_command" | "user_abort";
|
|
46
50
|
/**
|
|
47
51
|
* A content block within a tool result, which may be text, terminal output, image, audio, or a resource
|
|
48
52
|
*/
|
|
@@ -2255,10 +2259,7 @@ export interface AbortEvent {
|
|
|
2255
2259
|
* Turn abort information including the reason for termination
|
|
2256
2260
|
*/
|
|
2257
2261
|
export interface AbortData {
|
|
2258
|
-
|
|
2259
|
-
* Reason the current turn was aborted (e.g., "user initiated")
|
|
2260
|
-
*/
|
|
2261
|
-
reason: string;
|
|
2262
|
+
reason: AbortReason;
|
|
2262
2263
|
}
|
|
2263
2264
|
export interface ToolUserRequestedEvent {
|
|
2264
2265
|
/**
|
|
@@ -2785,6 +2786,10 @@ export interface SubagentStartedData {
|
|
|
2785
2786
|
* Internal name of the sub-agent
|
|
2786
2787
|
*/
|
|
2787
2788
|
agentName: string;
|
|
2789
|
+
/**
|
|
2790
|
+
* Model the sub-agent will run with, when known at start. Surfaced in the timeline for auto-selected sub-agents (e.g. rubber-duck).
|
|
2791
|
+
*/
|
|
2792
|
+
model?: string;
|
|
2788
2793
|
/**
|
|
2789
2794
|
* Tool call ID of the parent tool invocation that spawned this sub-agent
|
|
2790
2795
|
*/
|
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, approveAll, convertMcpCallToolResult, createSessionFsAdapter, SYSTEM_PROMPT_SECTIONS, } from "./types.js";
|
|
9
|
-
export type { CommandContext, CommandDefinition, CommandHandler, ConnectionState, CopilotClientOptions, CustomAgentConfig, ElicitationFieldValue, ElicitationHandler, ElicitationParams, ElicitationContext, ElicitationResult, ElicitationSchema, ElicitationSchemaField, ForegroundSessionInfo, GetAuthStatusResponse, GetStatusResponse, InfiniteSessionConfig, InputOptions, MCPStdioServerConfig, MCPHTTPServerConfig, MCPServerConfig, DefaultAgentConfig, MessageOptions, ModelBilling, ModelCapabilities, ModelCapabilitiesOverride, ModelInfo, ModelPolicy, PermissionHandler, PermissionRequest, PermissionRequestResult, ProviderConfig, ResumeSessionConfig, SectionOverride, SectionOverrideAction, SectionTransformFn, SessionCapabilities, SessionConfig, SessionEvent, SessionEventHandler, SessionEventPayload, SessionEventType, SessionLifecycleEvent, SessionLifecycleEventType, SessionLifecycleHandler, SessionContext, SessionListFilter, SessionMetadata, SessionUiApi, SessionFsConfig, SessionFsProvider, SessionFsFileInfo, SystemMessageAppendConfig, SystemMessageConfig, SystemMessageCustomizeConfig, SystemMessageReplaceConfig, SystemPromptSection, TelemetryConfig, TraceContext, TraceContextProvider, Tool, ToolHandler, ToolInvocation, ToolResultObject, TypedSessionEventHandler, TypedSessionLifecycleHandler, ZodSchema, } from "./types.js";
|
|
9
|
+
export type { CommandContext, CommandDefinition, CommandHandler, AutoModeSwitchHandler, AutoModeSwitchRequest, AutoModeSwitchResponse, ConnectionState, CopilotClientOptions, CustomAgentConfig, ElicitationFieldValue, ElicitationHandler, ElicitationParams, ElicitationContext, ElicitationResult, ElicitationSchema, ElicitationSchemaField, ExitPlanModeHandler, ExitPlanModeRequest, ExitPlanModeResult, ForegroundSessionInfo, GetAuthStatusResponse, GetStatusResponse, InfiniteSessionConfig, InputOptions, MCPStdioServerConfig, MCPHTTPServerConfig, MCPServerConfig, DefaultAgentConfig, MessageOptions, ModelBilling, ModelCapabilities, ModelCapabilitiesOverride, ModelInfo, ModelPolicy, PermissionHandler, PermissionRequest, PermissionRequestResult, ProviderConfig, ResumeSessionConfig, SectionOverride, SectionOverrideAction, SectionTransformFn, SessionCapabilities, SessionConfig, SessionEvent, SessionEventHandler, SessionEventPayload, SessionEventType, SessionLifecycleEvent, SessionLifecycleEventType, SessionLifecycleHandler, SessionContext, SessionListFilter, SessionMetadata, SessionUiApi, SessionFsConfig, SessionFsProvider, SessionFsFileInfo, SystemMessageAppendConfig, SystemMessageConfig, SystemMessageCustomizeConfig, SystemMessageReplaceConfig, SystemPromptSection, TelemetryConfig, TraceContext, TraceContextProvider, Tool, ToolHandler, ToolInvocation, ToolResultObject, TypedSessionEventHandler, TypedSessionLifecycleHandler, ZodSchema, } from "./types.js";
|
package/dist/session.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import type { MessageConnection } from "vscode-jsonrpc/node.js";
|
|
6
6
|
import { createSessionRpc } from "./generated/rpc.js";
|
|
7
7
|
import type { ClientSessionApiHandlers } from "./generated/rpc.js";
|
|
8
|
-
import type { CommandHandler, ElicitationHandler, ElicitationContext, MessageOptions, PermissionHandler, PermissionRequestResult, ReasoningEffort, ModelCapabilitiesOverride, SectionTransformFn, SessionCapabilities, SessionEvent, SessionEventHandler, SessionEventType, SessionHooks, SessionUiApi, Tool, ToolHandler, TraceContextProvider, TypedSessionEventHandler, UserInputHandler, UserInputResponse } from "./types.js";
|
|
8
|
+
import type { CommandHandler, AutoModeSwitchHandler, AutoModeSwitchRequest, AutoModeSwitchResponse, ElicitationHandler, ElicitationContext, ExitPlanModeHandler, ExitPlanModeRequest, ExitPlanModeResult, MessageOptions, PermissionHandler, PermissionRequestResult, ReasoningEffort, ModelCapabilitiesOverride, SectionTransformFn, SessionCapabilities, SessionEvent, SessionEventHandler, SessionEventType, SessionHooks, SessionUiApi, Tool, ToolHandler, TraceContextProvider, TypedSessionEventHandler, UserInputHandler, UserInputResponse } from "./types.js";
|
|
9
9
|
export declare const NO_RESULT_PERMISSION_V2_ERROR = "Permission handlers cannot return 'no-result' when connected to a protocol v2 server.";
|
|
10
10
|
/** Assistant message event - the final response from the assistant. */
|
|
11
11
|
export type AssistantMessageEvent = Extract<SessionEvent, {
|
|
@@ -47,6 +47,8 @@ export declare class CopilotSession {
|
|
|
47
47
|
private permissionHandler?;
|
|
48
48
|
private userInputHandler?;
|
|
49
49
|
private elicitationHandler?;
|
|
50
|
+
private exitPlanModeHandler?;
|
|
51
|
+
private autoModeSwitchHandler?;
|
|
50
52
|
private hooks?;
|
|
51
53
|
private transformCallbacks?;
|
|
52
54
|
private _rpc;
|
|
@@ -246,12 +248,36 @@ export declare class CopilotSession {
|
|
|
246
248
|
* @internal This method is typically called internally when creating/resuming a session.
|
|
247
249
|
*/
|
|
248
250
|
registerElicitationHandler(handler?: ElicitationHandler): void;
|
|
251
|
+
/**
|
|
252
|
+
* Registers the exit-plan-mode handler for this session.
|
|
253
|
+
*
|
|
254
|
+
* @param handler - The handler to invoke when the server dispatches an exit-plan-mode request
|
|
255
|
+
* @internal This method is typically called internally when creating/resuming a session.
|
|
256
|
+
*/
|
|
257
|
+
registerExitPlanModeHandler(handler?: ExitPlanModeHandler): void;
|
|
258
|
+
/**
|
|
259
|
+
* Registers the auto-mode-switch handler for this session.
|
|
260
|
+
*
|
|
261
|
+
* @param handler - The handler to invoke when the server dispatches an auto-mode-switch request
|
|
262
|
+
* @internal This method is typically called internally when creating/resuming a session.
|
|
263
|
+
*/
|
|
264
|
+
registerAutoModeSwitchHandler(handler?: AutoModeSwitchHandler): void;
|
|
249
265
|
/**
|
|
250
266
|
* Handles an elicitation.requested broadcast event.
|
|
251
267
|
* Invokes the registered handler and responds via handlePendingElicitation RPC.
|
|
252
268
|
* @internal
|
|
253
269
|
*/
|
|
254
270
|
_handleElicitationRequest(context: ElicitationContext, requestId: string): Promise<void>;
|
|
271
|
+
/**
|
|
272
|
+
* Handles an exitPlanMode.request callback from the runtime.
|
|
273
|
+
* @internal
|
|
274
|
+
*/
|
|
275
|
+
_handleExitPlanModeRequest(request: ExitPlanModeRequest): Promise<ExitPlanModeResult>;
|
|
276
|
+
/**
|
|
277
|
+
* Handles an autoModeSwitch.request callback from the runtime.
|
|
278
|
+
* @internal
|
|
279
|
+
*/
|
|
280
|
+
_handleAutoModeSwitchRequest(request: AutoModeSwitchRequest): Promise<AutoModeSwitchResponse>;
|
|
255
281
|
/**
|
|
256
282
|
* Sets the host capabilities for this session.
|
|
257
283
|
*
|
package/dist/session.js
CHANGED
|
@@ -25,6 +25,8 @@ class CopilotSession {
|
|
|
25
25
|
permissionHandler;
|
|
26
26
|
userInputHandler;
|
|
27
27
|
elicitationHandler;
|
|
28
|
+
exitPlanModeHandler;
|
|
29
|
+
autoModeSwitchHandler;
|
|
28
30
|
hooks;
|
|
29
31
|
transformCallbacks;
|
|
30
32
|
_rpc = null;
|
|
@@ -420,6 +422,24 @@ class CopilotSession {
|
|
|
420
422
|
registerElicitationHandler(handler) {
|
|
421
423
|
this.elicitationHandler = handler;
|
|
422
424
|
}
|
|
425
|
+
/**
|
|
426
|
+
* Registers the exit-plan-mode handler for this session.
|
|
427
|
+
*
|
|
428
|
+
* @param handler - The handler to invoke when the server dispatches an exit-plan-mode request
|
|
429
|
+
* @internal This method is typically called internally when creating/resuming a session.
|
|
430
|
+
*/
|
|
431
|
+
registerExitPlanModeHandler(handler) {
|
|
432
|
+
this.exitPlanModeHandler = handler;
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Registers the auto-mode-switch handler for this session.
|
|
436
|
+
*
|
|
437
|
+
* @param handler - The handler to invoke when the server dispatches an auto-mode-switch request
|
|
438
|
+
* @internal This method is typically called internally when creating/resuming a session.
|
|
439
|
+
*/
|
|
440
|
+
registerAutoModeSwitchHandler(handler) {
|
|
441
|
+
this.autoModeSwitchHandler = handler;
|
|
442
|
+
}
|
|
423
443
|
/**
|
|
424
444
|
* Handles an elicitation.requested broadcast event.
|
|
425
445
|
* Invokes the registered handler and responds via handlePendingElicitation RPC.
|
|
@@ -445,6 +465,26 @@ class CopilotSession {
|
|
|
445
465
|
}
|
|
446
466
|
}
|
|
447
467
|
}
|
|
468
|
+
/**
|
|
469
|
+
* Handles an exitPlanMode.request callback from the runtime.
|
|
470
|
+
* @internal
|
|
471
|
+
*/
|
|
472
|
+
async _handleExitPlanModeRequest(request) {
|
|
473
|
+
if (!this.exitPlanModeHandler) {
|
|
474
|
+
return { approved: true };
|
|
475
|
+
}
|
|
476
|
+
return await this.exitPlanModeHandler(request, { sessionId: this.sessionId });
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* Handles an autoModeSwitch.request callback from the runtime.
|
|
480
|
+
* @internal
|
|
481
|
+
*/
|
|
482
|
+
async _handleAutoModeSwitchRequest(request) {
|
|
483
|
+
if (!this.autoModeSwitchHandler) {
|
|
484
|
+
return "no";
|
|
485
|
+
}
|
|
486
|
+
return await this.autoModeSwitchHandler(request, { sessionId: this.sessionId });
|
|
487
|
+
}
|
|
448
488
|
/**
|
|
449
489
|
* Sets the host capabilities for this session.
|
|
450
490
|
*
|
|
@@ -725,6 +765,10 @@ class CopilotSession {
|
|
|
725
765
|
this.typedEventHandlers.clear();
|
|
726
766
|
this.toolHandlers.clear();
|
|
727
767
|
this.permissionHandler = void 0;
|
|
768
|
+
this.userInputHandler = void 0;
|
|
769
|
+
this.elicitationHandler = void 0;
|
|
770
|
+
this.exitPlanModeHandler = void 0;
|
|
771
|
+
this.autoModeSwitchHandler = void 0;
|
|
728
772
|
}
|
|
729
773
|
/**
|
|
730
774
|
* @deprecated Use {@link disconnect} instead. This method will be removed in a future release.
|
|
@@ -6,7 +6,7 @@ import type { SessionFsHandler, SessionFsStatResult, SessionFsReaddirWithTypesEn
|
|
|
6
6
|
*/
|
|
7
7
|
export type SessionFsFileInfo = Omit<SessionFsStatResult, "error">;
|
|
8
8
|
/**
|
|
9
|
-
* Interface for session filesystem providers.
|
|
9
|
+
* Interface for session filesystem providers. Implementers use idiomatic
|
|
10
10
|
* TypeScript patterns: throw on error, return values directly. Use
|
|
11
11
|
* {@link createSessionFsAdapter} to convert a provider into the
|
|
12
12
|
* {@link SessionFsHandler} expected by the SDK.
|
package/dist/types.d.ts
CHANGED
|
@@ -650,6 +650,55 @@ export interface UserInputResponse {
|
|
|
650
650
|
export type UserInputHandler = (request: UserInputRequest, invocation: {
|
|
651
651
|
sessionId: string;
|
|
652
652
|
}) => Promise<UserInputResponse> | UserInputResponse;
|
|
653
|
+
/**
|
|
654
|
+
* Request to exit plan mode and continue with a selected action.
|
|
655
|
+
*/
|
|
656
|
+
export interface ExitPlanModeRequest {
|
|
657
|
+
/** Summary of the plan or proposed next step. */
|
|
658
|
+
summary: string;
|
|
659
|
+
/** Full plan content, when available. */
|
|
660
|
+
planContent?: string;
|
|
661
|
+
/** Available actions the user can select. */
|
|
662
|
+
actions: string[];
|
|
663
|
+
/** The action recommended by the runtime. */
|
|
664
|
+
recommendedAction: string;
|
|
665
|
+
}
|
|
666
|
+
/**
|
|
667
|
+
* Response to an exit-plan-mode request.
|
|
668
|
+
*/
|
|
669
|
+
export interface ExitPlanModeResult {
|
|
670
|
+
/** Whether the user approved exiting plan mode. */
|
|
671
|
+
approved: boolean;
|
|
672
|
+
/** Selected action, if the user chose one. */
|
|
673
|
+
selectedAction?: string;
|
|
674
|
+
/** Optional feedback provided by the user. */
|
|
675
|
+
feedback?: string;
|
|
676
|
+
}
|
|
677
|
+
/**
|
|
678
|
+
* Handler for exit-plan-mode requests from the agent.
|
|
679
|
+
*/
|
|
680
|
+
export type ExitPlanModeHandler = (request: ExitPlanModeRequest, invocation: {
|
|
681
|
+
sessionId: string;
|
|
682
|
+
}) => Promise<ExitPlanModeResult> | ExitPlanModeResult;
|
|
683
|
+
/**
|
|
684
|
+
* Request to switch to auto mode after an eligible rate limit.
|
|
685
|
+
*/
|
|
686
|
+
export interface AutoModeSwitchRequest {
|
|
687
|
+
/** The rate-limit error code that triggered the request. */
|
|
688
|
+
errorCode?: string;
|
|
689
|
+
/** Seconds until the rate limit resets, when known. */
|
|
690
|
+
retryAfterSeconds?: number;
|
|
691
|
+
}
|
|
692
|
+
/**
|
|
693
|
+
* Response to an auto-mode-switch request.
|
|
694
|
+
*/
|
|
695
|
+
export type AutoModeSwitchResponse = "yes" | "yes_always" | "no";
|
|
696
|
+
/**
|
|
697
|
+
* Handler for auto-mode-switch requests from the agent.
|
|
698
|
+
*/
|
|
699
|
+
export type AutoModeSwitchHandler = (request: AutoModeSwitchRequest, invocation: {
|
|
700
|
+
sessionId: string;
|
|
701
|
+
}) => Promise<AutoModeSwitchResponse> | AutoModeSwitchResponse;
|
|
653
702
|
/**
|
|
654
703
|
* Base interface for all hook inputs
|
|
655
704
|
*/
|
|
@@ -1020,6 +1069,15 @@ export interface SessionConfig {
|
|
|
1020
1069
|
* When specified, uses the provided API endpoint instead of the Copilot API.
|
|
1021
1070
|
*/
|
|
1022
1071
|
provider?: ProviderConfig;
|
|
1072
|
+
/**
|
|
1073
|
+
* Enables or disables internal session telemetry for this session.
|
|
1074
|
+
* When `false`, disables session telemetry. When omitted (the default) or `true`,
|
|
1075
|
+
* telemetry is enabled for GitHub-authenticated sessions.
|
|
1076
|
+
* When a custom {@link provider} (BYOK) is configured, session telemetry is always
|
|
1077
|
+
* disabled regardless of this setting.
|
|
1078
|
+
* This is independent of the OpenTelemetry configuration in {@link CopilotClientOptions.telemetry}.
|
|
1079
|
+
*/
|
|
1080
|
+
enableSessionTelemetry?: boolean;
|
|
1023
1081
|
/**
|
|
1024
1082
|
* Handler for permission requests from the server.
|
|
1025
1083
|
* When provided, the server will call this handler to request permission for operations.
|
|
@@ -1036,6 +1094,16 @@ export interface SessionConfig {
|
|
|
1036
1094
|
* Also enables the `elicitation` capability on the session.
|
|
1037
1095
|
*/
|
|
1038
1096
|
onElicitationRequest?: ElicitationHandler;
|
|
1097
|
+
/**
|
|
1098
|
+
* Handler for exit-plan-mode requests from the agent.
|
|
1099
|
+
* When provided, enables `exitPlanMode.request` callbacks.
|
|
1100
|
+
*/
|
|
1101
|
+
onExitPlanMode?: ExitPlanModeHandler;
|
|
1102
|
+
/**
|
|
1103
|
+
* Handler for auto-mode-switch requests from the agent.
|
|
1104
|
+
* When provided, enables `autoModeSwitch.request` callbacks.
|
|
1105
|
+
*/
|
|
1106
|
+
onAutoModeSwitch?: AutoModeSwitchHandler;
|
|
1039
1107
|
/**
|
|
1040
1108
|
* Hook handlers for intercepting session lifecycle events.
|
|
1041
1109
|
* When provided, enables hooks callback allowing custom logic at various points.
|
|
@@ -1127,7 +1195,7 @@ export interface SessionConfig {
|
|
|
1127
1195
|
/**
|
|
1128
1196
|
* Configuration for resuming a session
|
|
1129
1197
|
*/
|
|
1130
|
-
export type ResumeSessionConfig = Pick<SessionConfig, "clientName" | "model" | "tools" | "commands" | "systemMessage" | "availableTools" | "excludedTools" | "provider" | "modelCapabilities" | "streaming" | "includeSubAgentStreamingEvents" | "reasoningEffort" | "onPermissionRequest" | "onUserInputRequest" | "onElicitationRequest" | "hooks" | "workingDirectory" | "configDir" | "enableConfigDiscovery" | "mcpServers" | "customAgents" | "defaultAgent" | "agent" | "skillDirectories" | "instructionDirectories" | "disabledSkills" | "infiniteSessions" | "gitHubToken" | "onEvent" | "createSessionFsHandler"> & {
|
|
1198
|
+
export type ResumeSessionConfig = Pick<SessionConfig, "clientName" | "model" | "tools" | "commands" | "systemMessage" | "availableTools" | "excludedTools" | "provider" | "enableSessionTelemetry" | "modelCapabilities" | "streaming" | "includeSubAgentStreamingEvents" | "reasoningEffort" | "onPermissionRequest" | "onUserInputRequest" | "onElicitationRequest" | "onExitPlanMode" | "onAutoModeSwitch" | "hooks" | "workingDirectory" | "configDir" | "enableConfigDiscovery" | "mcpServers" | "customAgents" | "defaultAgent" | "agent" | "skillDirectories" | "instructionDirectories" | "disabledSkills" | "infiniteSessions" | "gitHubToken" | "onEvent" | "createSessionFsHandler"> & {
|
|
1131
1199
|
/**
|
|
1132
1200
|
* When true, skips emitting the session.resume event.
|
|
1133
1201
|
* Useful for reconnecting to a session without triggering resume-related side effects.
|
package/dist/types.js
CHANGED
|
@@ -23,9 +23,10 @@ function convertMcpCallToolResult(callResult) {
|
|
|
23
23
|
textParts.push(block.resource.text);
|
|
24
24
|
}
|
|
25
25
|
if (block.resource?.blob) {
|
|
26
|
+
const mimeType = block.resource.mimeType;
|
|
26
27
|
binaryResults.push({
|
|
27
28
|
data: block.resource.blob,
|
|
28
|
-
mimeType:
|
|
29
|
+
mimeType: typeof mimeType === "string" && mimeType ? mimeType : "application/octet-stream",
|
|
29
30
|
type: "resource",
|
|
30
31
|
description: block.resource.uri
|
|
31
32
|
});
|
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": "1.0.0-beta.
|
|
7
|
+
"version": "1.0.0-beta.3",
|
|
8
8
|
"description": "TypeScript SDK for programmatic control of GitHub Copilot CLI via JSON-RPC",
|
|
9
9
|
"main": "./dist/cjs/index.js",
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"author": "GitHub",
|
|
57
57
|
"license": "MIT",
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@github/copilot": "^1.0.
|
|
59
|
+
"@github/copilot": "^1.0.44-2",
|
|
60
60
|
"vscode-jsonrpc": "^8.2.1",
|
|
61
61
|
"zod": "^4.3.6"
|
|
62
62
|
},
|