@github/copilot-sdk 1.0.18-preview.3 → 1.0.18-preview.5

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/dist/host.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { HostExitedNotification, HostPublishSessionResult, HostLocalServerOptions, HostGitHubEnvironmentOptions } from "./generated/rpc.js";
1
+ import type { HostExitedNotification, HostPublishSessionResult, HostListSessionsResult, HostLocalServerOptions, HostGitHubEnvironmentOptions } from "./generated/rpc.js";
2
2
  import type { CopilotSession } from "./session.js";
3
3
  import type { SessionConfig, ResumeSessionConfig } from "./types.js";
4
4
  /** Host-selected defaults for a fresh application-owned session. @experimental */
@@ -30,6 +30,8 @@ export type AhpHostExit = HostExitedNotification;
30
30
  * @experimental
31
31
  */
32
32
  export interface AhpHostOptions {
33
+ /** Stable catalog identity; must agree with githubEnvironment.computeId when both are supplied. */
34
+ computeId?: string;
33
35
  /** Enable a local WebSocket listener; an empty object selects loopback defaults. */
34
36
  localServer?: HostLocalServerOptions;
35
37
  /** Register a Mission Control environment and enable remote WPS connections. */
@@ -43,7 +45,7 @@ export interface AhpHostOptions {
43
45
  */
44
46
  createSession?: (request: AhpSessionCreateRequest) => Promise<CopilotSession>;
45
47
  /**
46
- * Resume a durable session previously created by an application factory.
48
+ * Resume a durable application-owned session, including a previously published session.
47
49
  * Return the original object from this client's resumeSession, or an existing
48
50
  * attached original without reconfiguring it. Published resident sessions
49
51
  * attach directly and never invoke this callback.
@@ -62,13 +64,14 @@ export interface AhpHostOptions {
62
64
  * the owning client also stops the host; reconnecting does not reclaim it.
63
65
  * Stopping a host does not delete its underlying sessions.
64
66
  * Its durable AHP catalog is shared by successive hosts in the runtime's
65
- * effective Copilot home; a concurrent host for that catalog is rejected.
67
+ * effective Copilot home and compute identity; a concurrent host for that catalog is rejected.
66
68
  *
67
69
  * @experimental
68
70
  */
69
71
  export declare class AhpHost {
70
72
  private readonly disposeHost;
71
73
  private readonly publishHostSession;
74
+ private readonly listHostSessions;
72
75
  readonly hostId: string;
73
76
  /** Local WebSocket URL. Absent when only the GitHub environment is enabled. */
74
77
  readonly url: string | undefined;
@@ -80,7 +83,9 @@ export declare class AhpHost {
80
83
  readonly pid: number | undefined;
81
84
  /** Ask the runtime to stop the listener and await its cleanup, on every call. */
82
85
  dispose(): Promise<void>;
83
- /** Publish an existing session attached to this client, until this listener stops. */
86
+ /** Publish an attached application session into the durable compute-scoped host catalog. */
84
87
  publishSession(sessionId: string): Promise<HostPublishSessionResult>;
88
+ /** List all live and dormant catalog sessions advertised by this host. */
89
+ listSessions(): Promise<HostListSessionsResult>;
85
90
  [Symbol.asyncDispose](): Promise<void>;
86
91
  }
package/dist/host.js CHANGED
@@ -1,8 +1,9 @@
1
1
  class AhpHost {
2
2
  /** @internal */
3
- constructor(info, disposeHost, publishHostSession) {
3
+ constructor(info, disposeHost, publishHostSession, listHostSessions) {
4
4
  this.disposeHost = disposeHost;
5
5
  this.publishHostSession = publishHostSession;
6
+ this.listHostSessions = listHostSessions;
6
7
  this.hostId = info.hostId;
7
8
  this.url = info.url;
8
9
  this.environmentId = info.environmentId;
@@ -11,6 +12,7 @@ class AhpHost {
11
12
  }
12
13
  disposeHost;
13
14
  publishHostSession;
15
+ listHostSessions;
14
16
  hostId;
15
17
  /** Local WebSocket URL. Absent when only the GitHub environment is enabled. */
16
18
  url;
@@ -24,10 +26,14 @@ class AhpHost {
24
26
  dispose() {
25
27
  return this.disposeHost();
26
28
  }
27
- /** Publish an existing session attached to this client, until this listener stops. */
29
+ /** Publish an attached application session into the durable compute-scoped host catalog. */
28
30
  publishSession(sessionId) {
29
31
  return this.publishHostSession(sessionId);
30
32
  }
33
+ /** List all live and dormant catalog sessions advertised by this host. */
34
+ listSessions() {
35
+ return this.listHostSessions();
36
+ }
31
37
  async [Symbol.asyncDispose]() {
32
38
  await this.dispose();
33
39
  }
package/dist/session.d.ts CHANGED
@@ -69,6 +69,7 @@ export declare class CopilotSession {
69
69
  private _capabilities;
70
70
  private openCanvasInstances;
71
71
  private disconnected;
72
+ private readonly pendingResponseWaits;
72
73
  private readonly pendingStructuredWaits;
73
74
  private disconnecting;
74
75
  private onDisconnected?;
@@ -173,6 +174,7 @@ export declare class CopilotSession {
173
174
  sendAndWait<TResult>(options: MessageOptions | string, responseSchema: ResponseSchema<TResult>, timeout?: number): Promise<TResult>;
174
175
  sendAndWait(options: MessageOptions, timeout?: number): Promise<AssistantMessageEvent | undefined>;
175
176
  private sendAndWaitForStructuredMessage;
177
+ private assertConnected;
176
178
  /**
177
179
  * Subscribes to events from this session.
178
180
  *
@@ -399,6 +401,7 @@ export declare class CopilotSession {
399
401
  * replace tools while the session is idle.
400
402
  *
401
403
  * @param tools - The complete set of tools this client supplies
404
+ * @throws Error if the session disconnects before the replacement is applied
402
405
  *
403
406
  * @experimental Wraps the experimental `session.tools.set` RPC and may change
404
407
  * or be removed in a future release.
package/dist/session.js CHANGED
@@ -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?.clear();
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)) {
@@ -771,7 +797,8 @@ class CopilotSession {
771
797
  args,
772
798
  handler,
773
799
  traceparent,
774
- tracestate
800
+ tracestate,
801
+ event.agentId || void 0
775
802
  );
776
803
  }
777
804
  } else if (event.type === "external_tool.completed") {
@@ -862,7 +889,7 @@ class CopilotSession {
862
889
  * Executes a tool handler and sends the result back via RPC.
863
890
  * @internal
864
891
  */
865
- async _executeToolAndRespond(requestId, toolName, toolCallId, args, handler, traceparent, tracestate) {
892
+ async _executeToolAndRespond(requestId, toolName, toolCallId, args, handler, traceparent, tracestate, agentId) {
866
893
  const controller = new AbortController();
867
894
  if (this.disconnected || this.pendingExternalTools.has(requestId)) {
868
895
  return;
@@ -900,7 +927,9 @@ class CopilotSession {
900
927
  availableTools,
901
928
  traceparent,
902
929
  tracestate,
903
- signal: controller.signal
930
+ signal: controller.signal,
931
+ agentId,
932
+ requestId
904
933
  });
905
934
  let result;
906
935
  if (rawResult == null) {
@@ -1061,6 +1090,7 @@ class CopilotSession {
1061
1090
  * @internal This method is typically called internally when creating a session with tools.
1062
1091
  */
1063
1092
  registerTools(tools) {
1093
+ this.assertConnected();
1064
1094
  this.toolHandlers.clear();
1065
1095
  if (!tools) {
1066
1096
  return;
@@ -1101,6 +1131,7 @@ class CopilotSession {
1101
1131
  * @internal Called by the SDK when creating/resuming a session with `canvases`.
1102
1132
  */
1103
1133
  registerCanvases(canvases) {
1134
+ this.assertConnected();
1104
1135
  this.canvases.clear();
1105
1136
  if (!canvases || canvases.length === 0) {
1106
1137
  delete this.clientSessionApis.canvas;
@@ -1156,6 +1187,7 @@ class CopilotSession {
1156
1187
  * @internal Called by the SDK when an extension joins a session.
1157
1188
  */
1158
1189
  registerWorkflows(workflows) {
1190
+ this.assertConnected();
1159
1191
  this.workflows.clear();
1160
1192
  if (!workflows || workflows.length === 0) {
1161
1193
  delete this.clientSessionApis.workflow;
@@ -1348,6 +1380,7 @@ class CopilotSession {
1348
1380
  * @internal This method is called internally when creating/resuming a session.
1349
1381
  */
1350
1382
  registerBearerTokenProviders(providers) {
1383
+ this.assertConnected();
1351
1384
  this.bearerTokenProviders.clear();
1352
1385
  if (!providers || providers.size === 0) {
1353
1386
  delete this.clientSessionApis.providerToken;
@@ -1359,6 +1392,7 @@ class CopilotSession {
1359
1392
  const self = this;
1360
1393
  this.clientSessionApis.providerToken = {
1361
1394
  async getToken(params) {
1395
+ self.assertConnected();
1362
1396
  const callback = self.bearerTokenProviders.get(params.providerName);
1363
1397
  if (!callback) {
1364
1398
  throw new Error(
@@ -1380,6 +1414,7 @@ class CopilotSession {
1380
1414
  * @internal This method is typically called internally when creating/resuming a session.
1381
1415
  */
1382
1416
  registerCommands(commands) {
1417
+ this.assertConnected();
1383
1418
  this.commandHandlers.clear();
1384
1419
  if (!commands) {
1385
1420
  return;
@@ -1395,6 +1430,7 @@ class CopilotSession {
1395
1430
  * @internal This method is typically called internally when creating/resuming a session.
1396
1431
  */
1397
1432
  registerElicitationHandler(handler) {
1433
+ this.assertConnected();
1398
1434
  this.elicitationHandler = handler;
1399
1435
  }
1400
1436
  /**
@@ -1404,6 +1440,7 @@ class CopilotSession {
1404
1440
  * @internal This method is typically called internally when creating/resuming a session.
1405
1441
  */
1406
1442
  registerExitPlanModeHandler(handler) {
1443
+ this.assertConnected();
1407
1444
  this.exitPlanModeHandler = handler;
1408
1445
  }
1409
1446
  /**
@@ -1413,6 +1450,7 @@ class CopilotSession {
1413
1450
  * @internal This method is typically called internally when creating/resuming a session.
1414
1451
  */
1415
1452
  registerAutoModeSwitchHandler(handler) {
1453
+ this.assertConnected();
1416
1454
  this.autoModeSwitchHandler = handler;
1417
1455
  }
1418
1456
  /**
@@ -1451,6 +1489,7 @@ class CopilotSession {
1451
1489
  * @internal
1452
1490
  */
1453
1491
  async _handleExitPlanModeRequest(request) {
1492
+ this.assertConnected();
1454
1493
  if (!this.exitPlanModeHandler) {
1455
1494
  return { approved: true };
1456
1495
  }
@@ -1461,6 +1500,7 @@ class CopilotSession {
1461
1500
  * @internal
1462
1501
  */
1463
1502
  async _handleAutoModeSwitchRequest(request) {
1503
+ this.assertConnected();
1464
1504
  if (!this.autoModeSwitchHandler) {
1465
1505
  return "no";
1466
1506
  }
@@ -1572,6 +1612,7 @@ class CopilotSession {
1572
1612
  * @internal This method is typically called internally when creating a session.
1573
1613
  */
1574
1614
  registerPermissionHandler(handler) {
1615
+ this.assertConnected();
1575
1616
  this.permissionHandler = handler;
1576
1617
  }
1577
1618
  /**
@@ -1584,6 +1625,7 @@ class CopilotSession {
1584
1625
  * @internal This method is typically called internally when creating a session.
1585
1626
  */
1586
1627
  registerUserInputHandler(handler) {
1628
+ this.assertConnected();
1587
1629
  this.userInputHandler = handler;
1588
1630
  }
1589
1631
  /**
@@ -1593,6 +1635,7 @@ class CopilotSession {
1593
1635
  * @internal This method is typically called internally when creating a session.
1594
1636
  */
1595
1637
  registerSkillProvider(provider) {
1638
+ this.assertConnected();
1596
1639
  this.skillProvider = provider;
1597
1640
  }
1598
1641
  /**
@@ -1618,6 +1661,7 @@ class CopilotSession {
1618
1661
  }));
1619
1662
  }
1620
1663
  requireSkillProvider() {
1664
+ this.assertConnected();
1621
1665
  if (!this.skillProvider) {
1622
1666
  throw new Error(`No skill provider for session: ${this.sessionId}`);
1623
1667
  }
@@ -1658,6 +1702,7 @@ class CopilotSession {
1658
1702
  * @internal This method is typically called internally when creating a session.
1659
1703
  */
1660
1704
  registerHooks(hooks) {
1705
+ this.assertConnected();
1661
1706
  this.hooks = hooks;
1662
1707
  }
1663
1708
  /**
@@ -1667,6 +1712,7 @@ class CopilotSession {
1667
1712
  * @internal This method is typically called internally when creating a session.
1668
1713
  */
1669
1714
  registerTransformCallbacks(callbacks) {
1715
+ this.assertConnected();
1670
1716
  this.transformCallbacks = callbacks;
1671
1717
  }
1672
1718
  /**
@@ -1678,6 +1724,7 @@ class CopilotSession {
1678
1724
  * @internal This method is for internal use by the SDK.
1679
1725
  */
1680
1726
  async _handleSystemMessageTransform(sections) {
1727
+ this.assertConnected();
1681
1728
  const result = {};
1682
1729
  for (const [sectionId, { content }] of Object.entries(sections)) {
1683
1730
  const callback = this.transformCallbacks?.get(sectionId);
@@ -1702,6 +1749,7 @@ class CopilotSession {
1702
1749
  * @internal This method is for internal use by the SDK.
1703
1750
  */
1704
1751
  async _handleUserInputRequest(request) {
1752
+ this.assertConnected();
1705
1753
  if (!this.userInputHandler) {
1706
1754
  throw new Error("User input requested but no handler registered");
1707
1755
  }
@@ -1723,6 +1771,7 @@ class CopilotSession {
1723
1771
  * @internal This method is for internal use by the SDK.
1724
1772
  */
1725
1773
  async _handleHooksInvoke(hookType, input) {
1774
+ this.assertConnected();
1726
1775
  if (!this.hooks) {
1727
1776
  return void 0;
1728
1777
  }
@@ -1929,6 +1978,7 @@ class CopilotSession {
1929
1978
  * replace tools while the session is idle.
1930
1979
  *
1931
1980
  * @param tools - The complete set of tools this client supplies
1981
+ * @throws Error if the session disconnects before the replacement is applied
1932
1982
  *
1933
1983
  * @experimental Wraps the experimental `session.tools.set` RPC and may change
1934
1984
  * or be removed in a future release.
@@ -1945,8 +1995,10 @@ class CopilotSession {
1945
1995
  * ```
1946
1996
  */
1947
1997
  async setTools(tools) {
1998
+ this.assertConnected();
1948
1999
  const definitions = tools.map(toToolDefinition);
1949
2000
  const replacement = this.setToolsQueue.then(async () => {
2001
+ this.assertConnected();
1950
2002
  await this.rpc.tools.set({ tools: definitions });
1951
2003
  this.registerTools(tools);
1952
2004
  });
package/dist/types.d.ts CHANGED
@@ -522,6 +522,24 @@ export interface ToolInvocation {
522
522
  tracestate?: string;
523
523
  /** Aborted when the runtime completes this request or the session disconnects. */
524
524
  signal?: AbortSignal;
525
+ /**
526
+ * Sub-agent instance that issued this call (the `agentId` of its session
527
+ * events). `undefined` for a root-agent call, and for every call when the
528
+ * runtime does not attribute sub-agent tool calls.
529
+ *
530
+ * @experimental
531
+ */
532
+ agentId?: string;
533
+ /**
534
+ * Runtime request id of this call: the key
535
+ * `session.tools.handlePendingToolCall` and `session.tools.listPendingRequests`
536
+ * use. A root-agent call stays answerable after the session is resumed with
537
+ * pending work continued; a sub-agent's call can be answered only while that
538
+ * sub-agent is still running.
539
+ *
540
+ * @experimental
541
+ */
542
+ requestId?: string;
525
543
  }
526
544
  export type ToolHandler<TArgs = unknown> = (args: TArgs, invocation: ToolInvocation) => Promise<unknown> | unknown;
527
545
  /**
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.3",
9
- "copilotCliVersion": "1.0.94-3",
8
+ "version": "1.0.18-preview.5",
9
+ "copilotCliVersion": "1.0.94-5",
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",
@@ -81,6 +81,7 @@
81
81
  "esbuild": "^0.28.1",
82
82
  "eslint": "^9.0.0",
83
83
  "glob": "^13.0.1",
84
+ "hpke-js": "^1.8.0",
84
85
  "json-schema": "^0.4.0",
85
86
  "json-schema-to-typescript": "^15.0.4",
86
87
  "prettier": "^3.8.1",
@@ -103,18 +104,18 @@
103
104
  "README.md"
104
105
  ],
105
106
  "copilotRuntime": {
106
- "sourceSha": "d8cd60bc89ed3ae60cc37d7877021ac49bd52492",
107
- "version": "1.0.94-3",
107
+ "sourceSha": "fdeb5949944ebccf3bb4dda8552a21aa1a09b6f6",
108
+ "version": "1.0.94-5",
108
109
  "visibility": "public"
109
110
  },
110
111
  "optionalDependencies": {
111
- "@github/copilot-sdk-darwin-arm64": "1.0.18-preview.3",
112
- "@github/copilot-sdk-darwin-x64": "1.0.18-preview.3",
113
- "@github/copilot-sdk-linux-arm64": "1.0.18-preview.3",
114
- "@github/copilot-sdk-linux-x64": "1.0.18-preview.3",
115
- "@github/copilot-sdk-linuxmusl-arm64": "1.0.18-preview.3",
116
- "@github/copilot-sdk-linuxmusl-x64": "1.0.18-preview.3",
117
- "@github/copilot-sdk-win32-arm64": "1.0.18-preview.3",
118
- "@github/copilot-sdk-win32-x64": "1.0.18-preview.3"
112
+ "@github/copilot-sdk-darwin-arm64": "1.0.18-preview.5",
113
+ "@github/copilot-sdk-darwin-x64": "1.0.18-preview.5",
114
+ "@github/copilot-sdk-linux-arm64": "1.0.18-preview.5",
115
+ "@github/copilot-sdk-linux-x64": "1.0.18-preview.5",
116
+ "@github/copilot-sdk-linuxmusl-arm64": "1.0.18-preview.5",
117
+ "@github/copilot-sdk-linuxmusl-x64": "1.0.18-preview.5",
118
+ "@github/copilot-sdk-win32-arm64": "1.0.18-preview.5",
119
+ "@github/copilot-sdk-win32-x64": "1.0.18-preview.5"
119
120
  }
120
121
  }