@github/copilot-sdk 1.0.18-preview.2 → 1.0.18-preview.4
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 +5 -0
- package/dist/cjs/cliVersion.js +1 -1
- package/dist/cjs/generated/rpc.js +41 -1
- package/dist/cjs/session.js +57 -8
- package/dist/cliVersion.d.ts +1 -1
- package/dist/cliVersion.js +1 -1
- package/dist/generated/rpc.d.ts +474 -245
- package/dist/generated/rpc.js +41 -1
- package/dist/generated/session-events.d.ts +528 -1
- package/dist/session.d.ts +3 -0
- package/dist/session.js +57 -8
- package/package.json +12 -12
package/dist/session.js
CHANGED
|
@@ -64,12 +64,12 @@ function isOpenCanvasInstance(value) {
|
|
|
64
64
|
const instance = value;
|
|
65
65
|
return typeof instance.instanceId === "string" && instance.instanceId.length > 0 && typeof instance.extensionId === "string" && instance.extensionId.length > 0 && typeof instance.canvasId === "string" && instance.canvasId.length > 0;
|
|
66
66
|
}
|
|
67
|
-
const
|
|
68
|
-
const
|
|
67
|
+
const WORKFLOW_LOG_FLUSH_DELAY_MS = 10;
|
|
68
|
+
const MAX_WORKFLOW_FANOUT_ITEMS = 4096;
|
|
69
69
|
function assertWorkflowFanoutSize(kind, size) {
|
|
70
|
-
if (size >
|
|
70
|
+
if (size > MAX_WORKFLOW_FANOUT_ITEMS) {
|
|
71
71
|
throw new Error(
|
|
72
|
-
`${kind}() accepts at most ${
|
|
72
|
+
`${kind}() accepts at most ${MAX_WORKFLOW_FANOUT_ITEMS} items; got ${size}.`
|
|
73
73
|
);
|
|
74
74
|
}
|
|
75
75
|
}
|
|
@@ -190,7 +190,7 @@ class WorkflowProgressBuffer {
|
|
|
190
190
|
this.flushTimer = void 0;
|
|
191
191
|
void this.flush().catch(() => {
|
|
192
192
|
});
|
|
193
|
-
},
|
|
193
|
+
}, WORKFLOW_LOG_FLUSH_DELAY_MS);
|
|
194
194
|
this.flushTimer.unref?.();
|
|
195
195
|
}
|
|
196
196
|
clearFlushTimer() {
|
|
@@ -276,6 +276,7 @@ class CopilotSession {
|
|
|
276
276
|
_capabilities = {};
|
|
277
277
|
openCanvasInstances = [];
|
|
278
278
|
disconnected = false;
|
|
279
|
+
pendingResponseWaits = /* @__PURE__ */ new Set();
|
|
279
280
|
pendingStructuredWaits = /* @__PURE__ */ new Set();
|
|
280
281
|
disconnecting = false;
|
|
281
282
|
onDisconnected;
|
|
@@ -552,6 +553,8 @@ class CopilotSession {
|
|
|
552
553
|
resolveOutcome({ kind: "error", error });
|
|
553
554
|
}
|
|
554
555
|
});
|
|
556
|
+
const fail = (error) => resolveOutcome({ kind: "error", error });
|
|
557
|
+
this.pendingResponseWaits.add(fail);
|
|
555
558
|
let timeoutId;
|
|
556
559
|
try {
|
|
557
560
|
await this.send(options);
|
|
@@ -575,6 +578,7 @@ class CopilotSession {
|
|
|
575
578
|
clearTimeout(timeoutId);
|
|
576
579
|
}
|
|
577
580
|
unsubscribe();
|
|
581
|
+
this.pendingResponseWaits.delete(fail);
|
|
578
582
|
}
|
|
579
583
|
}
|
|
580
584
|
async sendAndWaitForStructuredMessage(options, timeout) {
|
|
@@ -656,12 +660,21 @@ class CopilotSession {
|
|
|
656
660
|
this.pendingStructuredWaits.delete(fail);
|
|
657
661
|
}
|
|
658
662
|
}
|
|
663
|
+
assertConnected() {
|
|
664
|
+
if (this.disconnected) {
|
|
665
|
+
throw new Error("Session is disconnected");
|
|
666
|
+
}
|
|
667
|
+
}
|
|
659
668
|
/** @internal */
|
|
660
669
|
_markDisconnected() {
|
|
661
670
|
if (this.disconnected) {
|
|
662
671
|
return;
|
|
663
672
|
}
|
|
664
673
|
this.disconnected = true;
|
|
674
|
+
for (const fail of this.pendingResponseWaits) {
|
|
675
|
+
fail(new Error("Session disconnected while waiting for a response"));
|
|
676
|
+
}
|
|
677
|
+
this.pendingResponseWaits.clear();
|
|
665
678
|
for (const fail of this.pendingStructuredWaits) {
|
|
666
679
|
fail(new Error("Session disconnected while waiting for a structured response"));
|
|
667
680
|
}
|
|
@@ -670,16 +683,19 @@ class CopilotSession {
|
|
|
670
683
|
controller.abort();
|
|
671
684
|
}
|
|
672
685
|
this.pendingExternalTools.clear();
|
|
673
|
-
this._runOnDisconnected();
|
|
674
686
|
this.eventHandlers.clear();
|
|
675
687
|
this.typedEventHandlers.clear();
|
|
676
688
|
this.toolHandlers.clear();
|
|
677
689
|
this.permissionHandler = void 0;
|
|
690
|
+
this.mcpAuthHandler = void 0;
|
|
678
691
|
this.userInputHandler = void 0;
|
|
679
692
|
this.elicitationHandler = void 0;
|
|
680
693
|
this.exitPlanModeHandler = void 0;
|
|
681
694
|
this.autoModeSwitchHandler = void 0;
|
|
682
695
|
this.skillProvider = void 0;
|
|
696
|
+
this.hooks = void 0;
|
|
697
|
+
this.traceContextProvider = void 0;
|
|
698
|
+
this.bearerTokenProviders.clear();
|
|
683
699
|
this.commandHandlers.clear();
|
|
684
700
|
this.canvases.clear();
|
|
685
701
|
this.workflows.clear();
|
|
@@ -689,18 +705,28 @@ class CopilotSession {
|
|
|
689
705
|
}
|
|
690
706
|
}
|
|
691
707
|
this.workflowAbortControllers.clear();
|
|
692
|
-
this.transformCallbacks
|
|
708
|
+
this.transformCallbacks = void 0;
|
|
709
|
+
delete this.clientSessionApis.providerToken;
|
|
710
|
+
delete this.clientSessionApis.canvas;
|
|
711
|
+
delete this.clientSessionApis.workflow;
|
|
712
|
+
delete this.clientSessionApis.sessionFs;
|
|
713
|
+
this._runOnDisconnected();
|
|
693
714
|
}
|
|
694
715
|
/** @internal */
|
|
695
716
|
_runOnDisconnected() {
|
|
696
|
-
this.onDisconnected
|
|
717
|
+
const callback = this.onDisconnected;
|
|
697
718
|
this.onDisconnected = void 0;
|
|
719
|
+
callback?.();
|
|
698
720
|
}
|
|
699
721
|
/** @internal */
|
|
700
722
|
_setOnDisconnected(callback) {
|
|
723
|
+
this.assertConnected();
|
|
701
724
|
this.onDisconnected = callback;
|
|
702
725
|
}
|
|
703
726
|
on(eventTypeOrHandler, handler) {
|
|
727
|
+
if (this.disconnected) {
|
|
728
|
+
throw new Error("Session is disconnected");
|
|
729
|
+
}
|
|
704
730
|
if (typeof eventTypeOrHandler === "string" && handler) {
|
|
705
731
|
const eventType = eventTypeOrHandler;
|
|
706
732
|
if (!this.typedEventHandlers.has(eventType)) {
|
|
@@ -1061,6 +1087,7 @@ class CopilotSession {
|
|
|
1061
1087
|
* @internal This method is typically called internally when creating a session with tools.
|
|
1062
1088
|
*/
|
|
1063
1089
|
registerTools(tools) {
|
|
1090
|
+
this.assertConnected();
|
|
1064
1091
|
this.toolHandlers.clear();
|
|
1065
1092
|
if (!tools) {
|
|
1066
1093
|
return;
|
|
@@ -1101,6 +1128,7 @@ class CopilotSession {
|
|
|
1101
1128
|
* @internal Called by the SDK when creating/resuming a session with `canvases`.
|
|
1102
1129
|
*/
|
|
1103
1130
|
registerCanvases(canvases) {
|
|
1131
|
+
this.assertConnected();
|
|
1104
1132
|
this.canvases.clear();
|
|
1105
1133
|
if (!canvases || canvases.length === 0) {
|
|
1106
1134
|
delete this.clientSessionApis.canvas;
|
|
@@ -1156,6 +1184,7 @@ class CopilotSession {
|
|
|
1156
1184
|
* @internal Called by the SDK when an extension joins a session.
|
|
1157
1185
|
*/
|
|
1158
1186
|
registerWorkflows(workflows) {
|
|
1187
|
+
this.assertConnected();
|
|
1159
1188
|
this.workflows.clear();
|
|
1160
1189
|
if (!workflows || workflows.length === 0) {
|
|
1161
1190
|
delete this.clientSessionApis.workflow;
|
|
@@ -1348,6 +1377,7 @@ class CopilotSession {
|
|
|
1348
1377
|
* @internal This method is called internally when creating/resuming a session.
|
|
1349
1378
|
*/
|
|
1350
1379
|
registerBearerTokenProviders(providers) {
|
|
1380
|
+
this.assertConnected();
|
|
1351
1381
|
this.bearerTokenProviders.clear();
|
|
1352
1382
|
if (!providers || providers.size === 0) {
|
|
1353
1383
|
delete this.clientSessionApis.providerToken;
|
|
@@ -1359,6 +1389,7 @@ class CopilotSession {
|
|
|
1359
1389
|
const self = this;
|
|
1360
1390
|
this.clientSessionApis.providerToken = {
|
|
1361
1391
|
async getToken(params) {
|
|
1392
|
+
self.assertConnected();
|
|
1362
1393
|
const callback = self.bearerTokenProviders.get(params.providerName);
|
|
1363
1394
|
if (!callback) {
|
|
1364
1395
|
throw new Error(
|
|
@@ -1380,6 +1411,7 @@ class CopilotSession {
|
|
|
1380
1411
|
* @internal This method is typically called internally when creating/resuming a session.
|
|
1381
1412
|
*/
|
|
1382
1413
|
registerCommands(commands) {
|
|
1414
|
+
this.assertConnected();
|
|
1383
1415
|
this.commandHandlers.clear();
|
|
1384
1416
|
if (!commands) {
|
|
1385
1417
|
return;
|
|
@@ -1395,6 +1427,7 @@ class CopilotSession {
|
|
|
1395
1427
|
* @internal This method is typically called internally when creating/resuming a session.
|
|
1396
1428
|
*/
|
|
1397
1429
|
registerElicitationHandler(handler) {
|
|
1430
|
+
this.assertConnected();
|
|
1398
1431
|
this.elicitationHandler = handler;
|
|
1399
1432
|
}
|
|
1400
1433
|
/**
|
|
@@ -1404,6 +1437,7 @@ class CopilotSession {
|
|
|
1404
1437
|
* @internal This method is typically called internally when creating/resuming a session.
|
|
1405
1438
|
*/
|
|
1406
1439
|
registerExitPlanModeHandler(handler) {
|
|
1440
|
+
this.assertConnected();
|
|
1407
1441
|
this.exitPlanModeHandler = handler;
|
|
1408
1442
|
}
|
|
1409
1443
|
/**
|
|
@@ -1413,6 +1447,7 @@ class CopilotSession {
|
|
|
1413
1447
|
* @internal This method is typically called internally when creating/resuming a session.
|
|
1414
1448
|
*/
|
|
1415
1449
|
registerAutoModeSwitchHandler(handler) {
|
|
1450
|
+
this.assertConnected();
|
|
1416
1451
|
this.autoModeSwitchHandler = handler;
|
|
1417
1452
|
}
|
|
1418
1453
|
/**
|
|
@@ -1451,6 +1486,7 @@ class CopilotSession {
|
|
|
1451
1486
|
* @internal
|
|
1452
1487
|
*/
|
|
1453
1488
|
async _handleExitPlanModeRequest(request) {
|
|
1489
|
+
this.assertConnected();
|
|
1454
1490
|
if (!this.exitPlanModeHandler) {
|
|
1455
1491
|
return { approved: true };
|
|
1456
1492
|
}
|
|
@@ -1461,6 +1497,7 @@ class CopilotSession {
|
|
|
1461
1497
|
* @internal
|
|
1462
1498
|
*/
|
|
1463
1499
|
async _handleAutoModeSwitchRequest(request) {
|
|
1500
|
+
this.assertConnected();
|
|
1464
1501
|
if (!this.autoModeSwitchHandler) {
|
|
1465
1502
|
return "no";
|
|
1466
1503
|
}
|
|
@@ -1572,6 +1609,7 @@ class CopilotSession {
|
|
|
1572
1609
|
* @internal This method is typically called internally when creating a session.
|
|
1573
1610
|
*/
|
|
1574
1611
|
registerPermissionHandler(handler) {
|
|
1612
|
+
this.assertConnected();
|
|
1575
1613
|
this.permissionHandler = handler;
|
|
1576
1614
|
}
|
|
1577
1615
|
/**
|
|
@@ -1584,6 +1622,7 @@ class CopilotSession {
|
|
|
1584
1622
|
* @internal This method is typically called internally when creating a session.
|
|
1585
1623
|
*/
|
|
1586
1624
|
registerUserInputHandler(handler) {
|
|
1625
|
+
this.assertConnected();
|
|
1587
1626
|
this.userInputHandler = handler;
|
|
1588
1627
|
}
|
|
1589
1628
|
/**
|
|
@@ -1593,6 +1632,7 @@ class CopilotSession {
|
|
|
1593
1632
|
* @internal This method is typically called internally when creating a session.
|
|
1594
1633
|
*/
|
|
1595
1634
|
registerSkillProvider(provider) {
|
|
1635
|
+
this.assertConnected();
|
|
1596
1636
|
this.skillProvider = provider;
|
|
1597
1637
|
}
|
|
1598
1638
|
/**
|
|
@@ -1618,6 +1658,7 @@ class CopilotSession {
|
|
|
1618
1658
|
}));
|
|
1619
1659
|
}
|
|
1620
1660
|
requireSkillProvider() {
|
|
1661
|
+
this.assertConnected();
|
|
1621
1662
|
if (!this.skillProvider) {
|
|
1622
1663
|
throw new Error(`No skill provider for session: ${this.sessionId}`);
|
|
1623
1664
|
}
|
|
@@ -1658,6 +1699,7 @@ class CopilotSession {
|
|
|
1658
1699
|
* @internal This method is typically called internally when creating a session.
|
|
1659
1700
|
*/
|
|
1660
1701
|
registerHooks(hooks) {
|
|
1702
|
+
this.assertConnected();
|
|
1661
1703
|
this.hooks = hooks;
|
|
1662
1704
|
}
|
|
1663
1705
|
/**
|
|
@@ -1667,6 +1709,7 @@ class CopilotSession {
|
|
|
1667
1709
|
* @internal This method is typically called internally when creating a session.
|
|
1668
1710
|
*/
|
|
1669
1711
|
registerTransformCallbacks(callbacks) {
|
|
1712
|
+
this.assertConnected();
|
|
1670
1713
|
this.transformCallbacks = callbacks;
|
|
1671
1714
|
}
|
|
1672
1715
|
/**
|
|
@@ -1678,6 +1721,7 @@ class CopilotSession {
|
|
|
1678
1721
|
* @internal This method is for internal use by the SDK.
|
|
1679
1722
|
*/
|
|
1680
1723
|
async _handleSystemMessageTransform(sections) {
|
|
1724
|
+
this.assertConnected();
|
|
1681
1725
|
const result = {};
|
|
1682
1726
|
for (const [sectionId, { content }] of Object.entries(sections)) {
|
|
1683
1727
|
const callback = this.transformCallbacks?.get(sectionId);
|
|
@@ -1702,6 +1746,7 @@ class CopilotSession {
|
|
|
1702
1746
|
* @internal This method is for internal use by the SDK.
|
|
1703
1747
|
*/
|
|
1704
1748
|
async _handleUserInputRequest(request) {
|
|
1749
|
+
this.assertConnected();
|
|
1705
1750
|
if (!this.userInputHandler) {
|
|
1706
1751
|
throw new Error("User input requested but no handler registered");
|
|
1707
1752
|
}
|
|
@@ -1723,6 +1768,7 @@ class CopilotSession {
|
|
|
1723
1768
|
* @internal This method is for internal use by the SDK.
|
|
1724
1769
|
*/
|
|
1725
1770
|
async _handleHooksInvoke(hookType, input) {
|
|
1771
|
+
this.assertConnected();
|
|
1726
1772
|
if (!this.hooks) {
|
|
1727
1773
|
return void 0;
|
|
1728
1774
|
}
|
|
@@ -1929,6 +1975,7 @@ class CopilotSession {
|
|
|
1929
1975
|
* replace tools while the session is idle.
|
|
1930
1976
|
*
|
|
1931
1977
|
* @param tools - The complete set of tools this client supplies
|
|
1978
|
+
* @throws Error if the session disconnects before the replacement is applied
|
|
1932
1979
|
*
|
|
1933
1980
|
* @experimental Wraps the experimental `session.tools.set` RPC and may change
|
|
1934
1981
|
* or be removed in a future release.
|
|
@@ -1945,8 +1992,10 @@ class CopilotSession {
|
|
|
1945
1992
|
* ```
|
|
1946
1993
|
*/
|
|
1947
1994
|
async setTools(tools) {
|
|
1995
|
+
this.assertConnected();
|
|
1948
1996
|
const definitions = tools.map(toToolDefinition);
|
|
1949
1997
|
const replacement = this.setToolsQueue.then(async () => {
|
|
1998
|
+
this.assertConnected();
|
|
1950
1999
|
await this.rpc.tools.set({ tools: definitions });
|
|
1951
2000
|
this.registerTools(tools);
|
|
1952
2001
|
});
|
package/package.json
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
"url": "https://github.com/github/copilot-agent-runtime.git",
|
|
6
6
|
"directory": "src/sdk/nodejs"
|
|
7
7
|
},
|
|
8
|
-
"version": "1.0.18-preview.
|
|
9
|
-
"copilotCliVersion": "1.0.94-
|
|
8
|
+
"version": "1.0.18-preview.4",
|
|
9
|
+
"copilotCliVersion": "1.0.94-4",
|
|
10
10
|
"description": "TypeScript SDK for programmatic control of GitHub Copilot CLI via JSON-RPC",
|
|
11
11
|
"main": "./dist/cjs/index.js",
|
|
12
12
|
"types": "./dist/index.d.ts",
|
|
@@ -103,18 +103,18 @@
|
|
|
103
103
|
"README.md"
|
|
104
104
|
],
|
|
105
105
|
"copilotRuntime": {
|
|
106
|
-
"sourceSha": "
|
|
107
|
-
"version": "1.0.94-
|
|
106
|
+
"sourceSha": "eb9442810f652729e706715ab1093119e20876e0",
|
|
107
|
+
"version": "1.0.94-4",
|
|
108
108
|
"visibility": "public"
|
|
109
109
|
},
|
|
110
110
|
"optionalDependencies": {
|
|
111
|
-
"@github/copilot-sdk-darwin-arm64": "1.0.18-preview.
|
|
112
|
-
"@github/copilot-sdk-darwin-x64": "1.0.18-preview.
|
|
113
|
-
"@github/copilot-sdk-linux-arm64": "1.0.18-preview.
|
|
114
|
-
"@github/copilot-sdk-linux-x64": "1.0.18-preview.
|
|
115
|
-
"@github/copilot-sdk-linuxmusl-arm64": "1.0.18-preview.
|
|
116
|
-
"@github/copilot-sdk-linuxmusl-x64": "1.0.18-preview.
|
|
117
|
-
"@github/copilot-sdk-win32-arm64": "1.0.18-preview.
|
|
118
|
-
"@github/copilot-sdk-win32-x64": "1.0.18-preview.
|
|
111
|
+
"@github/copilot-sdk-darwin-arm64": "1.0.18-preview.4",
|
|
112
|
+
"@github/copilot-sdk-darwin-x64": "1.0.18-preview.4",
|
|
113
|
+
"@github/copilot-sdk-linux-arm64": "1.0.18-preview.4",
|
|
114
|
+
"@github/copilot-sdk-linux-x64": "1.0.18-preview.4",
|
|
115
|
+
"@github/copilot-sdk-linuxmusl-arm64": "1.0.18-preview.4",
|
|
116
|
+
"@github/copilot-sdk-linuxmusl-x64": "1.0.18-preview.4",
|
|
117
|
+
"@github/copilot-sdk-win32-arm64": "1.0.18-preview.4",
|
|
118
|
+
"@github/copilot-sdk-win32-x64": "1.0.18-preview.4"
|
|
119
119
|
}
|
|
120
120
|
}
|