@github/copilot-sdk 1.0.5-preview.0 → 1.0.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.
@@ -925,7 +925,8 @@ class CopilotClient {
925
925
  sessionId,
926
926
  this.connection,
927
927
  void 0,
928
- this.onGetTraceContext
928
+ this.onGetTraceContext,
929
+ { mcpAuthHandler: config.onMcpAuthRequest }
929
930
  );
930
931
  s.registerTools(config.tools);
931
932
  s.registerCanvases(config.canvases);
@@ -996,11 +997,14 @@ class CopilotClient {
996
997
  availableTools: toolFilterOptions.availableTools,
997
998
  excludedTools: toolFilterOptions.excludedTools,
998
999
  toolFilterPrecedence: toolFilterOptions.toolFilterPrecedence,
1000
+ excludedBuiltinAgents: config.excludedBuiltinAgents,
999
1001
  provider: bearerWireProvider,
1000
1002
  capi: config.capi,
1001
1003
  providers: bearerWireProviders,
1002
1004
  models: config.models,
1003
1005
  enableSessionTelemetry: config.enableSessionTelemetry,
1006
+ enableCitations: config.enableCitations,
1007
+ sessionLimits: config.sessionLimits,
1004
1008
  modelCapabilities: config.modelCapabilities,
1005
1009
  largeOutput: toWireLargeOutput(config.largeOutput),
1006
1010
  requestPermission: !!config.onPermissionRequest,
@@ -1057,6 +1061,12 @@ class CopilotClient {
1057
1061
  session = initializeSession(returnedSessionId);
1058
1062
  registeredId = returnedSessionId;
1059
1063
  }
1064
+ if (config.onMcpAuthRequest) {
1065
+ await this.connection.sendRequest("session.eventLog.registerInterest", {
1066
+ sessionId: returnedSessionId,
1067
+ eventType: "mcp.oauth_required"
1068
+ });
1069
+ }
1060
1070
  session["_workspacePath"] = workspacePath;
1061
1071
  session.setCapabilities(capabilities);
1062
1072
  await this.updateSessionOptionsForMode(session, config);
@@ -1100,7 +1110,8 @@ class CopilotClient {
1100
1110
  sessionId,
1101
1111
  this.connection,
1102
1112
  void 0,
1103
- this.onGetTraceContext
1113
+ this.onGetTraceContext,
1114
+ { mcpAuthHandler: config.onMcpAuthRequest }
1104
1115
  );
1105
1116
  session.registerTools(config.tools);
1106
1117
  session.registerCanvases(config.canvases);
@@ -1157,6 +1168,9 @@ class CopilotClient {
1157
1168
  excludedTools: toolFilterOptions.excludedTools,
1158
1169
  toolFilterPrecedence: toolFilterOptions.toolFilterPrecedence,
1159
1170
  enableSessionTelemetry: config.enableSessionTelemetry,
1171
+ excludedBuiltinAgents: config.excludedBuiltinAgents,
1172
+ enableCitations: config.enableCitations,
1173
+ sessionLimits: config.sessionLimits,
1160
1174
  tools: config.tools?.map((tool) => ({
1161
1175
  name: tool.name,
1162
1176
  description: tool.description,
@@ -1223,6 +1237,12 @@ class CopilotClient {
1223
1237
  session["_workspacePath"] = workspacePath;
1224
1238
  session.setCapabilities(capabilities);
1225
1239
  session.setOpenCanvases(openCanvases ?? []);
1240
+ if (config.onMcpAuthRequest) {
1241
+ await this.connection.sendRequest("session.eventLog.registerInterest", {
1242
+ sessionId,
1243
+ eventType: "mcp.oauth_required"
1244
+ });
1245
+ }
1226
1246
  await this.updateSessionOptionsForMode(session, config);
1227
1247
  } catch (e) {
1228
1248
  this.sessions.delete(sessionId);
@@ -34,8 +34,11 @@ function createServerRpc(connection) {
34
34
  * @param params Optional message to echo back to the caller.
35
35
  *
36
36
  * @returns Server liveness response, including the echoed message, current server timestamp, and protocol version.
37
+ *
38
+ * @experimental
37
39
  */
38
40
  ping: async (params) => connection.sendRequest("ping", params),
41
+ /** @experimental */
39
42
  models: {
40
43
  /**
41
44
  * Lists Copilot models available to the authenticated user.
@@ -46,6 +49,7 @@ function createServerRpc(connection) {
46
49
  */
47
50
  list: async (params) => connection.sendRequest("models.list", params)
48
51
  },
52
+ /** @experimental */
49
53
  tools: {
50
54
  /**
51
55
  * Lists built-in tools available for a model.
@@ -56,6 +60,7 @@ function createServerRpc(connection) {
56
60
  */
57
61
  list: async (params) => connection.sendRequest("tools.list", params)
58
62
  },
63
+ /** @experimental */
59
64
  account: {
60
65
  /**
61
66
  * Gets Copilot quota usage for the authenticated user or supplied GitHub token.
@@ -94,6 +99,7 @@ function createServerRpc(connection) {
94
99
  */
95
100
  logout: async (params) => connection.sendRequest("account.logout", params)
96
101
  },
102
+ /** @experimental */
97
103
  secrets: {
98
104
  /**
99
105
  * Registers secret values for redaction in session logs and exports. The SDK calls this to inject dynamically generated secret values (e.g., OIDC tokens).
@@ -104,7 +110,9 @@ function createServerRpc(connection) {
104
110
  */
105
111
  addFilterValues: async (params) => connection.sendRequest("secrets.addFilterValues", params)
106
112
  },
113
+ /** @experimental */
107
114
  mcp: {
115
+ /** @experimental */
108
116
  config: {
109
117
  /**
110
118
  * Lists MCP servers from user configuration.
@@ -246,7 +254,9 @@ function createServerRpc(connection) {
246
254
  refresh: async (params) => connection.sendRequest("plugins.marketplaces.refresh", params)
247
255
  }
248
256
  },
257
+ /** @experimental */
249
258
  skills: {
259
+ /** @experimental */
250
260
  config: {
251
261
  /**
252
262
  * Replaces the global list of disabled skills.
@@ -269,8 +279,6 @@ function createServerRpc(connection) {
269
279
  * @param params Optional project paths to enumerate.
270
280
  *
271
281
  * @returns Canonical locations where skills can be created so the runtime will recognize them.
272
- *
273
- * @experimental
274
282
  */
275
283
  getDiscoveryPaths: async (params) => connection.sendRequest("skills.getDiscoveryPaths", params)
276
284
  },
@@ -312,20 +320,38 @@ function createServerRpc(connection) {
312
320
  */
313
321
  getDiscoveryPaths: async (params) => connection.sendRequest("instructions.getDiscoveryPaths", params)
314
322
  },
323
+ /** @experimental */
315
324
  user: {
325
+ /** @experimental */
316
326
  settings: {
317
327
  /**
318
328
  * Drops this runtime process's in-memory user settings cache so the next settings read observes disk.
319
329
  */
320
- reload: async () => connection.sendRequest("user.settings.reload", {})
330
+ reload: async () => connection.sendRequest("user.settings.reload", {}),
331
+ /**
332
+ * Lists every known user setting (settings.json overlaid with the legacy config.json, config.json wins), each with its effective value, its default, and whether it is at the default — so settings the user has never set still appear with their default value. Does not include repository- or enterprise-managed overrides that the runtime layers on top at session time.
333
+ *
334
+ * @returns Per-key metadata for every known user setting (settings.json overlaid with the legacy config.json, config.json wins), including settings left at their default. Excludes repository- and enterprise-managed overrides.
335
+ */
336
+ get: async () => connection.sendRequest("user.settings.get", {}),
337
+ /**
338
+ * Writes one or more user settings to settings.json, replacing each provided top-level key. A key whose value is null is removed. Returns the keys whose new value is shadowed by a legacy config.json entry (config.json wins on read), which the runtime leaves in place — such writes do not take effect until the legacy value is removed.
339
+ *
340
+ * @param params Partial user settings to write to settings.json. Each top-level key is written individually, replacing the existing value; a key whose value is null is removed.
341
+ *
342
+ * @returns Outcome of writing user settings.
343
+ */
344
+ set: async (params) => connection.sendRequest("user.settings.set", params)
321
345
  }
322
346
  },
347
+ /** @experimental */
323
348
  runtime: {
324
349
  /**
325
350
  * Gracefully shuts down an SDK-owned runtime. The response is sent only after cleanup completes; callers may then terminate the owned runtime process.
326
351
  */
327
352
  shutdown: async () => connection.sendRequest("runtime.shutdown", {})
328
353
  },
354
+ /** @experimental */
329
355
  sessionFs: {
330
356
  /**
331
357
  * Registers an SDK client as the session filesystem provider.
@@ -565,6 +591,8 @@ function createInternalServerRpc(connection) {
565
591
  * @param params Optional connection token presented by the SDK client during the handshake.
566
592
  *
567
593
  * @returns Handshake result reporting the server's protocol version and package version on success.
594
+ *
595
+ * @experimental
568
596
  */
569
597
  connect: async (params) => connection.sendRequest("connect", params),
570
598
  /** @experimental */
@@ -873,6 +901,23 @@ function createSessionRpc(connection, sessionId) {
873
901
  diff: async (params) => connection.sendRequest("session.workspaces.diff", { sessionId, ...params })
874
902
  },
875
903
  /** @experimental */
904
+ completions: {
905
+ /**
906
+ * Gets the characters that should trigger host-driven completions for the session. Empty disables host-driven completions (e.g. local sessions, or a relay host that does not advertise them).
907
+ *
908
+ * @returns Characters that, when typed in the composer, should trigger a `completions.request`. Empty when the session has no host-driven completions (e.g. local sessions, or a relay host that does not advertise `completionTriggerCharacters`).
909
+ */
910
+ getTriggerCharacters: async () => connection.sendRequest("session.completions.getTriggerCharacters", { sessionId }),
911
+ /**
912
+ * Requests host-driven completion items for the current composer input. Returns an empty list when the host has no items or does not support completions.
913
+ *
914
+ * @param params Request host-driven completions for the current composer input.
915
+ *
916
+ * @returns Host-driven completion items for the current composer input. Empty when the host returns no items or does not support completions.
917
+ */
918
+ request: async (params) => connection.sendRequest("session.completions.request", { sessionId, ...params })
919
+ },
920
+ /** @experimental */
876
921
  instructions: {
877
922
  /**
878
923
  * Gets instruction sources loaded for the session.
@@ -1429,6 +1474,14 @@ function createSessionRpc(connection, sessionId) {
1429
1474
  * @returns Indicates whether the pending UI request was resolved by this call.
1430
1475
  */
1431
1476
  handlePendingAutoModeSwitch: async (params) => connection.sendRequest("session.ui.handlePendingAutoModeSwitch", { sessionId, ...params }),
1477
+ /**
1478
+ * Resolves a pending `session_limits_exhausted.requested` event with the user's selected limit action.
1479
+ *
1480
+ * @param params Request ID of a pending `session_limits_exhausted.requested` event and the user's selected limit action.
1481
+ *
1482
+ * @returns Indicates whether the pending UI request was resolved by this call.
1483
+ */
1484
+ handlePendingSessionLimitsExhausted: async (params) => connection.sendRequest("session.ui.handlePendingSessionLimitsExhausted", { sessionId, ...params }),
1432
1485
  /**
1433
1486
  * Resolves a pending `exit_plan_mode.requested` event with the user's response.
1434
1487
  *
@@ -1847,6 +1900,23 @@ function createSessionRpc(connection, sessionId) {
1847
1900
  notifySteerableChanged: async (params) => connection.sendRequest("session.remote.notifySteerableChanged", { sessionId, ...params })
1848
1901
  },
1849
1902
  /** @experimental */
1903
+ visibility: {
1904
+ /**
1905
+ * Returns the session's current Mission Control sharing status and shareable GitHub URL. Reflects whether the synced session is visible to repository readers ("repo") or restricted to its creator and collaborators ("unshared").
1906
+ *
1907
+ * @returns Current sharing status and shareable GitHub URL for a session.
1908
+ */
1909
+ get: async () => connection.sendRequest("session.visibility.get", { sessionId }),
1910
+ /**
1911
+ * Sets the session's Mission Control sharing status, controlling whether the synced session is visible to repository readers. Returns the effective status and shareable GitHub URL after the change.
1912
+ *
1913
+ * @param params Desired sharing status for the session.
1914
+ *
1915
+ * @returns Effective sharing status and shareable GitHub URL after updating session visibility.
1916
+ */
1917
+ set: async (params) => connection.sendRequest("session.visibility.set", { sessionId, ...params })
1918
+ },
1919
+ /** @experimental */
1850
1920
  schedule: {
1851
1921
  /**
1852
1922
  * Lists the session's currently active scheduled prompts.
@@ -2016,6 +2086,11 @@ function registerClientGlobalApiHandlers(connection, handlers) {
2016
2086
  if (!handler) throw new Error("No llmInference client-global handler registered");
2017
2087
  return handler.httpRequestChunk(params);
2018
2088
  });
2089
+ connection.onRequest("gitHubTelemetry.event", async (params) => {
2090
+ const handler = handlers.gitHubTelemetry;
2091
+ if (!handler) throw new Error("No gitHubTelemetry client-global handler registered");
2092
+ return handler.event(params);
2093
+ });
2019
2094
  }
2020
2095
  // Annotate the CommonJS export names for ESM import in node:
2021
2096
  0 && (module.exports = {
@@ -50,11 +50,12 @@ class CopilotSession {
50
50
  * @param traceContextProvider - Optional callback to get W3C Trace Context for outbound RPCs
51
51
  * @internal This constructor is internal. Use {@link CopilotClient.createSession} to create sessions.
52
52
  */
53
- constructor(sessionId, connection, _workspacePath, traceContextProvider) {
53
+ constructor(sessionId, connection, _workspacePath, traceContextProvider, options) {
54
54
  this.sessionId = sessionId;
55
55
  this.connection = connection;
56
56
  this._workspacePath = _workspacePath;
57
57
  this.traceContextProvider = traceContextProvider;
58
+ this.mcpAuthHandler = options?.mcpAuthHandler;
58
59
  }
59
60
  sessionId;
60
61
  connection;
@@ -66,6 +67,7 @@ class CopilotSession {
66
67
  bearerTokenProviders = /* @__PURE__ */ new Map();
67
68
  commandHandlers = /* @__PURE__ */ new Map();
68
69
  permissionHandler;
70
+ mcpAuthHandler;
69
71
  userInputHandler;
70
72
  elicitationHandler;
71
73
  exitPlanModeHandler;
@@ -277,6 +279,18 @@ class CopilotSession {
277
279
  if (this.permissionHandler) {
278
280
  void this._executePermissionAndRespond(requestId, permissionRequest);
279
281
  }
282
+ } else if (event.type === "mcp.oauth_required") {
283
+ const data = event.data;
284
+ if (!data?.requestId) {
285
+ return;
286
+ }
287
+ if (!this.mcpAuthHandler) {
288
+ console.warn(
289
+ `Received MCP OAuth request without a registered MCP auth handler. SessionId=${this.sessionId}, RequestId=${data.requestId}`
290
+ );
291
+ return;
292
+ }
293
+ void this._executeMcpAuthAndRespond(data);
280
294
  } else if (event.type === "command.execute") {
281
295
  const { requestId, commandName, command, args } = event.data;
282
296
  void this._executeCommandAndRespond(requestId, commandName, command, args);
@@ -408,6 +422,31 @@ class CopilotSession {
408
422
  }
409
423
  }
410
424
  }
425
+ /**
426
+ * Executes an MCP auth handler and sends the result back via RPC.
427
+ * @internal
428
+ */
429
+ async _executeMcpAuthAndRespond(request) {
430
+ try {
431
+ const result = await this.mcpAuthHandler(request, { sessionId: this.sessionId });
432
+ const response = result && "accessToken" in result ? { kind: "token", ...result } : { kind: "cancelled" };
433
+ await this.rpc.mcp.oauth.handlePendingRequest({
434
+ requestId: request.requestId,
435
+ result: response
436
+ });
437
+ } catch (_error) {
438
+ try {
439
+ await this.rpc.mcp.oauth.handlePendingRequest({
440
+ requestId: request.requestId,
441
+ result: { kind: "cancelled" }
442
+ });
443
+ } catch (rpcError) {
444
+ if (!(rpcError instanceof import_node.ConnectionError || rpcError instanceof import_node.ResponseError)) {
445
+ throw rpcError;
446
+ }
447
+ }
448
+ }
449
+ }
411
450
  /**
412
451
  * Executes a command handler and sends the result back via RPC.
413
452
  * @internal
package/dist/client.js CHANGED
@@ -912,7 +912,8 @@ class CopilotClient {
912
912
  sessionId,
913
913
  this.connection,
914
914
  void 0,
915
- this.onGetTraceContext
915
+ this.onGetTraceContext,
916
+ { mcpAuthHandler: config.onMcpAuthRequest }
916
917
  );
917
918
  s.registerTools(config.tools);
918
919
  s.registerCanvases(config.canvases);
@@ -983,11 +984,14 @@ class CopilotClient {
983
984
  availableTools: toolFilterOptions.availableTools,
984
985
  excludedTools: toolFilterOptions.excludedTools,
985
986
  toolFilterPrecedence: toolFilterOptions.toolFilterPrecedence,
987
+ excludedBuiltinAgents: config.excludedBuiltinAgents,
986
988
  provider: bearerWireProvider,
987
989
  capi: config.capi,
988
990
  providers: bearerWireProviders,
989
991
  models: config.models,
990
992
  enableSessionTelemetry: config.enableSessionTelemetry,
993
+ enableCitations: config.enableCitations,
994
+ sessionLimits: config.sessionLimits,
991
995
  modelCapabilities: config.modelCapabilities,
992
996
  largeOutput: toWireLargeOutput(config.largeOutput),
993
997
  requestPermission: !!config.onPermissionRequest,
@@ -1044,6 +1048,12 @@ class CopilotClient {
1044
1048
  session = initializeSession(returnedSessionId);
1045
1049
  registeredId = returnedSessionId;
1046
1050
  }
1051
+ if (config.onMcpAuthRequest) {
1052
+ await this.connection.sendRequest("session.eventLog.registerInterest", {
1053
+ sessionId: returnedSessionId,
1054
+ eventType: "mcp.oauth_required"
1055
+ });
1056
+ }
1047
1057
  session["_workspacePath"] = workspacePath;
1048
1058
  session.setCapabilities(capabilities);
1049
1059
  await this.updateSessionOptionsForMode(session, config);
@@ -1087,7 +1097,8 @@ class CopilotClient {
1087
1097
  sessionId,
1088
1098
  this.connection,
1089
1099
  void 0,
1090
- this.onGetTraceContext
1100
+ this.onGetTraceContext,
1101
+ { mcpAuthHandler: config.onMcpAuthRequest }
1091
1102
  );
1092
1103
  session.registerTools(config.tools);
1093
1104
  session.registerCanvases(config.canvases);
@@ -1144,6 +1155,9 @@ class CopilotClient {
1144
1155
  excludedTools: toolFilterOptions.excludedTools,
1145
1156
  toolFilterPrecedence: toolFilterOptions.toolFilterPrecedence,
1146
1157
  enableSessionTelemetry: config.enableSessionTelemetry,
1158
+ excludedBuiltinAgents: config.excludedBuiltinAgents,
1159
+ enableCitations: config.enableCitations,
1160
+ sessionLimits: config.sessionLimits,
1147
1161
  tools: config.tools?.map((tool) => ({
1148
1162
  name: tool.name,
1149
1163
  description: tool.description,
@@ -1210,6 +1224,12 @@ class CopilotClient {
1210
1224
  session["_workspacePath"] = workspacePath;
1211
1225
  session.setCapabilities(capabilities);
1212
1226
  session.setOpenCanvases(openCanvases ?? []);
1227
+ if (config.onMcpAuthRequest) {
1228
+ await this.connection.sendRequest("session.eventLog.registerInterest", {
1229
+ sessionId,
1230
+ eventType: "mcp.oauth_required"
1231
+ });
1232
+ }
1213
1233
  await this.updateSessionOptionsForMode(session, config);
1214
1234
  } catch (e) {
1215
1235
  this.sessions.delete(sessionId);