@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 CHANGED
@@ -345,6 +345,11 @@ This graceful-exit timeout is separate from the shutdown RPC and post-terminatio
345
345
  ##### `forceStop(): Promise<void>`
346
346
 
347
347
  Force stop the CLI server without graceful cleanup. Use when `stop()` takes too long.
348
+ Retained sessions are disconnected locally, and pending `sendAndWait()` calls reject
349
+ without waiting for `session.idle` or their response timeout.
350
+ Retirement releases session-owned tool, hook, auth/input, provider, workflow, canvas,
351
+ and transform registrations without changing caller-owned configuration. Late
352
+ registration and callback dispatch are rejected; callbacks already admitted may finish.
348
353
 
349
354
  ##### `createSession(config?: SessionConfig): Promise<CopilotSession>`
350
355
 
@@ -22,7 +22,7 @@ __export(cliVersion_exports, {
22
22
  COPILOT_CLI_VERSION: () => COPILOT_CLI_VERSION
23
23
  });
24
24
  module.exports = __toCommonJS(cliVersion_exports);
25
- const COPILOT_CLI_VERSION = "1.0.94-2";
25
+ const COPILOT_CLI_VERSION = "1.0.94-4";
26
26
  const COPILOT_CLI_USE_NPM_PACKAGE = false;
27
27
  // Annotate the CommonJS export names for ESM import in node:
28
28
  0 && (module.exports = {
@@ -2710,6 +2710,12 @@ function createSessionRpc(connection, sessionId) {
2710
2710
  * @returns Indicates whether the external tool call result was handled successfully.
2711
2711
  */
2712
2712
  handlePendingToolCall: async (params) => connection.sendRequest("session.tools.handlePendingToolCall", { ...params, sessionId }),
2713
+ /**
2714
+ * Lists the external tool calls of the session and its sub-agents that are still waiting for session.tools.handlePendingToolCall.
2715
+ *
2716
+ * @returns External tool calls still waiting for a result.
2717
+ */
2718
+ listPendingRequests: async () => connection.sendRequest("session.tools.listPendingRequests", { sessionId }),
2713
2719
  /**
2714
2720
  * Resolves, builds, and validates the runtime tool list for the session.
2715
2721
  *
@@ -3399,6 +3405,27 @@ function createSessionRpc(connection, sessionId) {
3399
3405
  getMetrics: async () => connection.sendRequest("session.usage.getMetrics", { sessionId })
3400
3406
  },
3401
3407
  /** @experimental */
3408
+ quota: {
3409
+ /**
3410
+ * Gets the session's current quota and account projection without making a network request.
3411
+ *
3412
+ * @returns The incumbent session-owned quota and account projection.
3413
+ */
3414
+ get: async () => connection.sendRequest("session.quota.get", { sessionId }),
3415
+ /**
3416
+ * Refreshes the session's provider model catalog bypassing its cache, folds quota snapshots into session state, and returns the updated projection. Failures leave the last known quota intact.
3417
+ *
3418
+ * @returns The incumbent session-owned quota and account projection.
3419
+ */
3420
+ refresh: async () => connection.sendRequest("session.quota.refresh", { sessionId }),
3421
+ /**
3422
+ * Returns and clears the session's pending quota warnings. Reading or refreshing quota does not drain warnings.
3423
+ *
3424
+ * @returns Pending warnings returned and cleared by session.quota.takeWarnings.
3425
+ */
3426
+ takeWarnings: async () => connection.sendRequest("session.quota.takeWarnings", { sessionId })
3427
+ },
3428
+ /** @experimental */
3402
3429
  limitPrediction: {
3403
3430
  /**
3404
3431
  * Predicts an AI-credit session limit for the session's resolved model. Returns an unavailable result instead of falling back when the current model is unresolved auto.
@@ -3585,7 +3612,11 @@ function createInternalSessionRpc(connection, sessionId) {
3585
3612
  *
3586
3613
  * @returns The model identifier active on the session after the switch.
3587
3614
  */
3588
- applyStartupOverlay: async (params) => connection.sendRequest("session.model.applyStartupOverlay", { ...params, sessionId })
3615
+ applyStartupOverlay: async (params) => connection.sendRequest("session.model.applyStartupOverlay", { ...params, sessionId }),
3616
+ /**
3617
+ * Clears an unchanged startup model/provider seed before default-model resolution. Never clears a resumed or user-selected model.
3618
+ */
3619
+ clearStartupSeed: async (params) => connection.sendRequest("session.model.clearStartupSeed", { ...params, sessionId })
3589
3620
  },
3590
3621
  /** @experimental */
3591
3622
  mcp: {
@@ -3752,6 +3783,15 @@ function createInternalSessionRpc(connection, sessionId) {
3752
3783
  process: async () => connection.sendRequest("session.queue.process", { sessionId })
3753
3784
  },
3754
3785
  /** @experimental */
3786
+ usage: {
3787
+ /**
3788
+ * Internal host-only replacement of absolute code-change totals reported by a relay host.
3789
+ *
3790
+ * @param params Internal absolute code-change totals reported by the owning host.
3791
+ */
3792
+ setCodeChanges: async (params) => connection.sendRequest("session.usage.setCodeChanges", { ...params, sessionId })
3793
+ },
3794
+ /** @experimental */
3755
3795
  schedule: {
3756
3796
  /**
3757
3797
  * Hydrates the native schedule registry from persisted session events.
@@ -82,12 +82,12 @@ function isOpenCanvasInstance(value) {
82
82
  const instance = value;
83
83
  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;
84
84
  }
85
- const FACTORY_LOG_FLUSH_DELAY_MS = 10;
86
- const MAX_FACTORY_FANOUT_ITEMS = 4096;
85
+ const WORKFLOW_LOG_FLUSH_DELAY_MS = 10;
86
+ const MAX_WORKFLOW_FANOUT_ITEMS = 4096;
87
87
  function assertWorkflowFanoutSize(kind, size) {
88
- if (size > MAX_FACTORY_FANOUT_ITEMS) {
88
+ if (size > MAX_WORKFLOW_FANOUT_ITEMS) {
89
89
  throw new Error(
90
- `${kind}() accepts at most ${MAX_FACTORY_FANOUT_ITEMS} items; got ${size}.`
90
+ `${kind}() accepts at most ${MAX_WORKFLOW_FANOUT_ITEMS} items; got ${size}.`
91
91
  );
92
92
  }
93
93
  }
@@ -208,7 +208,7 @@ class WorkflowProgressBuffer {
208
208
  this.flushTimer = void 0;
209
209
  void this.flush().catch(() => {
210
210
  });
211
- }, FACTORY_LOG_FLUSH_DELAY_MS);
211
+ }, WORKFLOW_LOG_FLUSH_DELAY_MS);
212
212
  this.flushTimer.unref?.();
213
213
  }
214
214
  clearFlushTimer() {
@@ -294,6 +294,7 @@ class CopilotSession {
294
294
  _capabilities = {};
295
295
  openCanvasInstances = [];
296
296
  disconnected = false;
297
+ pendingResponseWaits = /* @__PURE__ */ new Set();
297
298
  pendingStructuredWaits = /* @__PURE__ */ new Set();
298
299
  disconnecting = false;
299
300
  onDisconnected;
@@ -570,6 +571,8 @@ class CopilotSession {
570
571
  resolveOutcome({ kind: "error", error });
571
572
  }
572
573
  });
574
+ const fail = (error) => resolveOutcome({ kind: "error", error });
575
+ this.pendingResponseWaits.add(fail);
573
576
  let timeoutId;
574
577
  try {
575
578
  await this.send(options);
@@ -593,6 +596,7 @@ class CopilotSession {
593
596
  clearTimeout(timeoutId);
594
597
  }
595
598
  unsubscribe();
599
+ this.pendingResponseWaits.delete(fail);
596
600
  }
597
601
  }
598
602
  async sendAndWaitForStructuredMessage(options, timeout) {
@@ -674,12 +678,21 @@ class CopilotSession {
674
678
  this.pendingStructuredWaits.delete(fail);
675
679
  }
676
680
  }
681
+ assertConnected() {
682
+ if (this.disconnected) {
683
+ throw new Error("Session is disconnected");
684
+ }
685
+ }
677
686
  /** @internal */
678
687
  _markDisconnected() {
679
688
  if (this.disconnected) {
680
689
  return;
681
690
  }
682
691
  this.disconnected = true;
692
+ for (const fail of this.pendingResponseWaits) {
693
+ fail(new Error("Session disconnected while waiting for a response"));
694
+ }
695
+ this.pendingResponseWaits.clear();
683
696
  for (const fail of this.pendingStructuredWaits) {
684
697
  fail(new Error("Session disconnected while waiting for a structured response"));
685
698
  }
@@ -688,16 +701,19 @@ class CopilotSession {
688
701
  controller.abort();
689
702
  }
690
703
  this.pendingExternalTools.clear();
691
- this._runOnDisconnected();
692
704
  this.eventHandlers.clear();
693
705
  this.typedEventHandlers.clear();
694
706
  this.toolHandlers.clear();
695
707
  this.permissionHandler = void 0;
708
+ this.mcpAuthHandler = void 0;
696
709
  this.userInputHandler = void 0;
697
710
  this.elicitationHandler = void 0;
698
711
  this.exitPlanModeHandler = void 0;
699
712
  this.autoModeSwitchHandler = void 0;
700
713
  this.skillProvider = void 0;
714
+ this.hooks = void 0;
715
+ this.traceContextProvider = void 0;
716
+ this.bearerTokenProviders.clear();
701
717
  this.commandHandlers.clear();
702
718
  this.canvases.clear();
703
719
  this.workflows.clear();
@@ -707,18 +723,28 @@ class CopilotSession {
707
723
  }
708
724
  }
709
725
  this.workflowAbortControllers.clear();
710
- this.transformCallbacks?.clear();
726
+ this.transformCallbacks = void 0;
727
+ delete this.clientSessionApis.providerToken;
728
+ delete this.clientSessionApis.canvas;
729
+ delete this.clientSessionApis.workflow;
730
+ delete this.clientSessionApis.sessionFs;
731
+ this._runOnDisconnected();
711
732
  }
712
733
  /** @internal */
713
734
  _runOnDisconnected() {
714
- this.onDisconnected?.();
735
+ const callback = this.onDisconnected;
715
736
  this.onDisconnected = void 0;
737
+ callback?.();
716
738
  }
717
739
  /** @internal */
718
740
  _setOnDisconnected(callback) {
741
+ this.assertConnected();
719
742
  this.onDisconnected = callback;
720
743
  }
721
744
  on(eventTypeOrHandler, handler) {
745
+ if (this.disconnected) {
746
+ throw new Error("Session is disconnected");
747
+ }
722
748
  if (typeof eventTypeOrHandler === "string" && handler) {
723
749
  const eventType = eventTypeOrHandler;
724
750
  if (!this.typedEventHandlers.has(eventType)) {
@@ -1079,6 +1105,7 @@ class CopilotSession {
1079
1105
  * @internal This method is typically called internally when creating a session with tools.
1080
1106
  */
1081
1107
  registerTools(tools) {
1108
+ this.assertConnected();
1082
1109
  this.toolHandlers.clear();
1083
1110
  if (!tools) {
1084
1111
  return;
@@ -1119,6 +1146,7 @@ class CopilotSession {
1119
1146
  * @internal Called by the SDK when creating/resuming a session with `canvases`.
1120
1147
  */
1121
1148
  registerCanvases(canvases) {
1149
+ this.assertConnected();
1122
1150
  this.canvases.clear();
1123
1151
  if (!canvases || canvases.length === 0) {
1124
1152
  delete this.clientSessionApis.canvas;
@@ -1174,6 +1202,7 @@ class CopilotSession {
1174
1202
  * @internal Called by the SDK when an extension joins a session.
1175
1203
  */
1176
1204
  registerWorkflows(workflows) {
1205
+ this.assertConnected();
1177
1206
  this.workflows.clear();
1178
1207
  if (!workflows || workflows.length === 0) {
1179
1208
  delete this.clientSessionApis.workflow;
@@ -1366,6 +1395,7 @@ class CopilotSession {
1366
1395
  * @internal This method is called internally when creating/resuming a session.
1367
1396
  */
1368
1397
  registerBearerTokenProviders(providers) {
1398
+ this.assertConnected();
1369
1399
  this.bearerTokenProviders.clear();
1370
1400
  if (!providers || providers.size === 0) {
1371
1401
  delete this.clientSessionApis.providerToken;
@@ -1377,6 +1407,7 @@ class CopilotSession {
1377
1407
  const self = this;
1378
1408
  this.clientSessionApis.providerToken = {
1379
1409
  async getToken(params) {
1410
+ self.assertConnected();
1380
1411
  const callback = self.bearerTokenProviders.get(params.providerName);
1381
1412
  if (!callback) {
1382
1413
  throw new Error(
@@ -1398,6 +1429,7 @@ class CopilotSession {
1398
1429
  * @internal This method is typically called internally when creating/resuming a session.
1399
1430
  */
1400
1431
  registerCommands(commands) {
1432
+ this.assertConnected();
1401
1433
  this.commandHandlers.clear();
1402
1434
  if (!commands) {
1403
1435
  return;
@@ -1413,6 +1445,7 @@ class CopilotSession {
1413
1445
  * @internal This method is typically called internally when creating/resuming a session.
1414
1446
  */
1415
1447
  registerElicitationHandler(handler) {
1448
+ this.assertConnected();
1416
1449
  this.elicitationHandler = handler;
1417
1450
  }
1418
1451
  /**
@@ -1422,6 +1455,7 @@ class CopilotSession {
1422
1455
  * @internal This method is typically called internally when creating/resuming a session.
1423
1456
  */
1424
1457
  registerExitPlanModeHandler(handler) {
1458
+ this.assertConnected();
1425
1459
  this.exitPlanModeHandler = handler;
1426
1460
  }
1427
1461
  /**
@@ -1431,6 +1465,7 @@ class CopilotSession {
1431
1465
  * @internal This method is typically called internally when creating/resuming a session.
1432
1466
  */
1433
1467
  registerAutoModeSwitchHandler(handler) {
1468
+ this.assertConnected();
1434
1469
  this.autoModeSwitchHandler = handler;
1435
1470
  }
1436
1471
  /**
@@ -1469,6 +1504,7 @@ class CopilotSession {
1469
1504
  * @internal
1470
1505
  */
1471
1506
  async _handleExitPlanModeRequest(request) {
1507
+ this.assertConnected();
1472
1508
  if (!this.exitPlanModeHandler) {
1473
1509
  return { approved: true };
1474
1510
  }
@@ -1479,6 +1515,7 @@ class CopilotSession {
1479
1515
  * @internal
1480
1516
  */
1481
1517
  async _handleAutoModeSwitchRequest(request) {
1518
+ this.assertConnected();
1482
1519
  if (!this.autoModeSwitchHandler) {
1483
1520
  return "no";
1484
1521
  }
@@ -1590,6 +1627,7 @@ class CopilotSession {
1590
1627
  * @internal This method is typically called internally when creating a session.
1591
1628
  */
1592
1629
  registerPermissionHandler(handler) {
1630
+ this.assertConnected();
1593
1631
  this.permissionHandler = handler;
1594
1632
  }
1595
1633
  /**
@@ -1602,6 +1640,7 @@ class CopilotSession {
1602
1640
  * @internal This method is typically called internally when creating a session.
1603
1641
  */
1604
1642
  registerUserInputHandler(handler) {
1643
+ this.assertConnected();
1605
1644
  this.userInputHandler = handler;
1606
1645
  }
1607
1646
  /**
@@ -1611,6 +1650,7 @@ class CopilotSession {
1611
1650
  * @internal This method is typically called internally when creating a session.
1612
1651
  */
1613
1652
  registerSkillProvider(provider) {
1653
+ this.assertConnected();
1614
1654
  this.skillProvider = provider;
1615
1655
  }
1616
1656
  /**
@@ -1636,6 +1676,7 @@ class CopilotSession {
1636
1676
  }));
1637
1677
  }
1638
1678
  requireSkillProvider() {
1679
+ this.assertConnected();
1639
1680
  if (!this.skillProvider) {
1640
1681
  throw new Error(`No skill provider for session: ${this.sessionId}`);
1641
1682
  }
@@ -1676,6 +1717,7 @@ class CopilotSession {
1676
1717
  * @internal This method is typically called internally when creating a session.
1677
1718
  */
1678
1719
  registerHooks(hooks) {
1720
+ this.assertConnected();
1679
1721
  this.hooks = hooks;
1680
1722
  }
1681
1723
  /**
@@ -1685,6 +1727,7 @@ class CopilotSession {
1685
1727
  * @internal This method is typically called internally when creating a session.
1686
1728
  */
1687
1729
  registerTransformCallbacks(callbacks) {
1730
+ this.assertConnected();
1688
1731
  this.transformCallbacks = callbacks;
1689
1732
  }
1690
1733
  /**
@@ -1696,6 +1739,7 @@ class CopilotSession {
1696
1739
  * @internal This method is for internal use by the SDK.
1697
1740
  */
1698
1741
  async _handleSystemMessageTransform(sections) {
1742
+ this.assertConnected();
1699
1743
  const result = {};
1700
1744
  for (const [sectionId, { content }] of Object.entries(sections)) {
1701
1745
  const callback = this.transformCallbacks?.get(sectionId);
@@ -1720,6 +1764,7 @@ class CopilotSession {
1720
1764
  * @internal This method is for internal use by the SDK.
1721
1765
  */
1722
1766
  async _handleUserInputRequest(request) {
1767
+ this.assertConnected();
1723
1768
  if (!this.userInputHandler) {
1724
1769
  throw new Error("User input requested but no handler registered");
1725
1770
  }
@@ -1741,6 +1786,7 @@ class CopilotSession {
1741
1786
  * @internal This method is for internal use by the SDK.
1742
1787
  */
1743
1788
  async _handleHooksInvoke(hookType, input) {
1789
+ this.assertConnected();
1744
1790
  if (!this.hooks) {
1745
1791
  return void 0;
1746
1792
  }
@@ -1947,6 +1993,7 @@ class CopilotSession {
1947
1993
  * replace tools while the session is idle.
1948
1994
  *
1949
1995
  * @param tools - The complete set of tools this client supplies
1996
+ * @throws Error if the session disconnects before the replacement is applied
1950
1997
  *
1951
1998
  * @experimental Wraps the experimental `session.tools.set` RPC and may change
1952
1999
  * or be removed in a future release.
@@ -1963,8 +2010,10 @@ class CopilotSession {
1963
2010
  * ```
1964
2011
  */
1965
2012
  async setTools(tools) {
2013
+ this.assertConnected();
1966
2014
  const definitions = tools.map(toToolDefinition);
1967
2015
  const replacement = this.setToolsQueue.then(async () => {
2016
+ this.assertConnected();
1968
2017
  await this.rpc.tools.set({ tools: definitions });
1969
2018
  this.registerTools(tools);
1970
2019
  });
@@ -1,2 +1,2 @@
1
- export declare const COPILOT_CLI_VERSION = "1.0.94-2";
1
+ export declare const COPILOT_CLI_VERSION = "1.0.94-4";
2
2
  export declare const COPILOT_CLI_USE_NPM_PACKAGE = false;
@@ -1,4 +1,4 @@
1
- const COPILOT_CLI_VERSION = "1.0.94-2";
1
+ const COPILOT_CLI_VERSION = "1.0.94-4";
2
2
  const COPILOT_CLI_USE_NPM_PACKAGE = false;
3
3
  export {
4
4
  COPILOT_CLI_USE_NPM_PACKAGE,