@microsoft/copilot-sdk 1.0.29-unstable.42916223485.gfff36db → 2.0.0-preview.0

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.
Files changed (48) hide show
  1. package/README.md +80 -62
  2. package/dist/canvas.d.ts +4 -0
  3. package/dist/canvas.js +1 -0
  4. package/dist/cjs/canvas.js +1 -0
  5. package/dist/cjs/cliVersion.js +1 -1
  6. package/dist/cjs/client.js +294 -107
  7. package/dist/cjs/copilotRequestHandler.js +24 -1
  8. package/dist/cjs/extension.js +4 -1
  9. package/dist/cjs/generated/rpc.js +295 -16
  10. package/dist/cjs/index.js +12 -2
  11. package/dist/cjs/localModelJson.js +103 -0
  12. package/dist/cjs/providerConfiguration.js +39 -0
  13. package/dist/cjs/rpcCancellation.js +49 -0
  14. package/dist/cjs/session.js +155 -10
  15. package/dist/cjs/taskAnalyticsJson.js +47 -0
  16. package/dist/cjs/types.js +14 -3
  17. package/dist/cjs/workflow.js +145 -1
  18. package/dist/cliVersion.d.ts +1 -1
  19. package/dist/cliVersion.js +1 -1
  20. package/dist/client.d.ts +33 -14
  21. package/dist/client.js +294 -107
  22. package/dist/copilotRequestHandler.js +24 -1
  23. package/dist/extension.d.ts +12 -2
  24. package/dist/extension.js +4 -1
  25. package/dist/generated/lifecycle-diagnostics.d.ts +48 -40
  26. package/dist/generated/rpc.d.ts +3668 -500
  27. package/dist/generated/rpc.js +295 -16
  28. package/dist/generated/session-events.d.ts +358 -115
  29. package/dist/index.d.ts +9 -5
  30. package/dist/index.js +14 -2
  31. package/dist/localModelJson.d.ts +1 -0
  32. package/dist/localModelJson.js +69 -0
  33. package/dist/providerConfiguration.d.ts +3 -0
  34. package/dist/providerConfiguration.js +15 -0
  35. package/dist/rpcCancellation.d.ts +3 -0
  36. package/dist/rpcCancellation.js +25 -0
  37. package/dist/session.d.ts +64 -5
  38. package/dist/session.js +156 -10
  39. package/dist/taskAnalyticsJson.d.ts +8 -0
  40. package/dist/taskAnalyticsJson.js +12 -0
  41. package/dist/types.d.ts +223 -43
  42. package/dist/types.js +13 -3
  43. package/dist/workflow.d.ts +60 -14
  44. package/dist/workflow.js +143 -1
  45. package/docs/agent-author.md +11 -11
  46. package/docs/extensions.md +41 -2
  47. package/docs/workflows.md +52 -17
  48. package/package.json +16 -15
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var localModelJson_exports = {};
30
+ __export(localModelJson_exports, {
31
+ createLocalModelJsonCodec: () => createLocalModelJsonCodec
32
+ });
33
+ module.exports = __toCommonJS(localModelJson_exports);
34
+ var import_node = require("vscode-jsonrpc/node");
35
+ var import_taskAnalyticsJson = require("./taskAnalyticsJson.js");
36
+ function createLocalModelJsonCodec() {
37
+ const pending = /* @__PURE__ */ new Map();
38
+ const snapshots = /* @__PURE__ */ new Set([
39
+ "localModels.configure",
40
+ "localModels.inspect",
41
+ "localModels.watch"
42
+ ]);
43
+ const modelRequests = /* @__PURE__ */ new Set([
44
+ "localModels.prepare",
45
+ "localModels.setup",
46
+ "localModels.deleteModel"
47
+ ]);
48
+ return {
49
+ async encode(message) {
50
+ const method = import_node.Message.isRequest(message) ? message.method : void 0;
51
+ const rawHistory = method === "session.getMessages" && message.params?.[import_taskAnalyticsJson.rawHistoryResponse];
52
+ const analytics = method === "taskAnalytics.classifyTrajectory";
53
+ const json = method && (snapshots.has(method) || modelRequests.has(method) || rawHistory || analytics) ? await import("lossless-json") : void 0;
54
+ const text = method && (modelRequests.has(method) || analytics) && json ? json.stringify(
55
+ message,
56
+ analytics ? (_key, value) => {
57
+ const nativeJson = JSON;
58
+ return nativeJson.isRawJSON?.(value) ? json.parse(JSON.stringify(value)) : value;
59
+ } : void 0
60
+ ) : JSON.stringify(message);
61
+ if (import_node.Message.isRequest(message) && json && (snapshots.has(message.method) || message.method === "localModels.prepare" || rawHistory)) {
62
+ pending.set(message.id, { method: message.method, json });
63
+ }
64
+ return text;
65
+ },
66
+ async decode(text) {
67
+ const message = JSON.parse(text);
68
+ if (!import_node.Message.isResponse(message)) return message;
69
+ const request = pending.get(message.id);
70
+ pending.delete(message.id);
71
+ if (!request || !("result" in message)) return message;
72
+ if (request.method === "session.getMessages") {
73
+ return await (0, import_taskAnalyticsJson.parseTrajectoryJson)(text);
74
+ }
75
+ const {
76
+ method,
77
+ json: { parse, parseNumberAndBigInt }
78
+ } = request;
79
+ const precise = parse(text, void 0, (token) => {
80
+ const value = parseNumberAndBigInt(token);
81
+ return typeof value === "bigint" && Number.isSafeInteger(Number(value)) ? Number(value) : value;
82
+ });
83
+ if (method === "localModels.prepare") {
84
+ const result = message.result;
85
+ const source = precise.result;
86
+ result.metadata = source.metadata;
87
+ result.serveOptions = source.serveOptions;
88
+ } else {
89
+ const result = message.result;
90
+ const source = precise.result;
91
+ for (const [index, row] of result.state.machine.rows.entries()) {
92
+ row.descriptor.metadata = source.state.machine.rows[index].descriptor.metadata;
93
+ row.descriptor.serveOptions = source.state.machine.rows[index].descriptor.serveOptions;
94
+ }
95
+ }
96
+ return message;
97
+ }
98
+ };
99
+ }
100
+ // Annotate the CommonJS export names for ESM import in node:
101
+ 0 && (module.exports = {
102
+ createLocalModelJsonCodec
103
+ });
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var providerConfiguration_exports = {};
20
+ __export(providerConfiguration_exports, {
21
+ toSavedProviderConfiguration: () => toSavedProviderConfiguration
22
+ });
23
+ module.exports = __toCommonJS(providerConfiguration_exports);
24
+ function toSavedProviderConfiguration(provider) {
25
+ return {
26
+ name: provider.name,
27
+ type: provider.type,
28
+ wireApi: provider.wireApi,
29
+ transport: provider.transport,
30
+ baseUrl: provider.baseUrl,
31
+ localModel: provider.localModel,
32
+ azure: provider.azure,
33
+ modelProvider: provider.modelProvider
34
+ };
35
+ }
36
+ // Annotate the CommonJS export names for ESM import in node:
37
+ 0 && (module.exports = {
38
+ toSavedProviderConfiguration
39
+ });
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var rpcCancellation_exports = {};
20
+ __export(rpcCancellation_exports, {
21
+ sendCancellableRequest: () => sendCancellableRequest
22
+ });
23
+ module.exports = __toCommonJS(rpcCancellation_exports);
24
+ var import_node = require("vscode-jsonrpc/node");
25
+ async function sendCancellableRequest(connection, method, params, signal, rejectOnAbort = false) {
26
+ signal?.throwIfAborted();
27
+ if (!signal) return connection.sendRequest(method, params);
28
+ const cancellation = new import_node.CancellationTokenSource();
29
+ let rejectAbort;
30
+ const aborted = rejectOnAbort ? new Promise((_, reject) => {
31
+ rejectAbort = reject;
32
+ }) : void 0;
33
+ const abort = () => {
34
+ cancellation.cancel();
35
+ rejectAbort?.(signal.reason);
36
+ };
37
+ signal.addEventListener("abort", abort, { once: true });
38
+ try {
39
+ const request = connection.sendRequest(method, params, cancellation.token);
40
+ return await (aborted ? Promise.race([request, aborted]) : request);
41
+ } finally {
42
+ signal.removeEventListener("abort", abort);
43
+ cancellation.dispose();
44
+ }
45
+ }
46
+ // Annotate the CommonJS export names for ESM import in node:
47
+ 0 && (module.exports = {
48
+ sendCancellableRequest
49
+ });
@@ -26,11 +26,12 @@ var import_node = require("vscode-jsonrpc/node");
26
26
  var import_rpc = require("./generated/rpc.js");
27
27
  var import_canvas = require("./canvas.js");
28
28
  var import_telemetry = require("./telemetry.js");
29
+ var import_taskAnalyticsJson = require("./taskAnalyticsJson.js");
29
30
  var import_schema = require("./schema.js");
30
31
  var import_types = require("./types.js");
31
32
  var import_workflow = require("./workflow.js");
32
33
  function isWorkflowResumeErrorCode(value) {
33
- return value === "not_found" || value === "non_resumable" || value === "workflow_run_not_resumable" || value === "already_active" || value === "workflow_already_running" || value === "workflow_limits_invalid" || value === "workflow_session_disposed" || value === "workflow_storage_unavailable" || value === "workflow_storage_corrupt";
34
+ return value === "not_found" || value === "non_resumable" || value === "workflow_run_not_resumable" || value === "already_active" || value === "workflow_already_running" || value === "workflow_limits_invalid" || value === "workflow_session_disposed" || value === "workflow_storage_unavailable" || value === "workflow_storage_corrupt" || value === "workflow_role_definition_mismatch";
34
35
  }
35
36
  function copyDefinedWorkflowAgentOption(source, target, key) {
36
37
  const value = source[key];
@@ -41,6 +42,7 @@ function copyDefinedWorkflowAgentOption(source, target, key) {
41
42
  function toToolDefinition(tool) {
42
43
  return {
43
44
  name: tool.name,
45
+ title: tool.title,
44
46
  description: tool.description ?? "",
45
47
  parameters: (0, import_schema.toJsonSchema)(tool.parameters),
46
48
  overridesBuiltInTool: tool.overridesBuiltInTool,
@@ -49,6 +51,7 @@ function toToolDefinition(tool) {
49
51
  defer: tool.defer,
50
52
  metadata: tool.metadata,
51
53
  isTerminal: tool.isTerminal,
54
+ idempotent: tool.idempotent,
52
55
  namespace: tool.namespace
53
56
  };
54
57
  }
@@ -56,7 +59,7 @@ const workflowExecutionStore = new import_node_async_hooks.AsyncLocalStorage();
56
59
  function throwIfWorkflowExecutionIsActive() {
57
60
  if (workflowExecutionStore.getStore()?.active) {
58
61
  throw new Error(
59
- "workflow.run, workflow.resume, and workflow.pause are not allowed while a workflow body is running on this call path."
62
+ "workflow.start, workflow.run, workflow.resume, and workflow.pause are not allowed while a workflow body is running on this call path."
60
63
  );
61
64
  }
62
65
  }
@@ -313,6 +316,8 @@ class CopilotSession {
313
316
  permissionHandler;
314
317
  mcpAuthHandler;
315
318
  userInputHandler;
319
+ shellAuthenticationHandler;
320
+ pendingShellAuthenticationRequests = /* @__PURE__ */ new Map();
316
321
  elicitationHandler;
317
322
  exitPlanModeHandler;
318
323
  autoModeSwitchHandler;
@@ -343,10 +348,10 @@ class CopilotSession {
343
348
  * change or be removed in future SDK or CLI releases.
344
349
  */
345
350
  workflow = {
346
- run: (async (nameOrHandle, options) => {
351
+ start: (async (nameOrHandle, options) => {
347
352
  throwIfWorkflowExecutionIsActive();
348
353
  const name = typeof nameOrHandle === "string" ? nameOrHandle : (0, import_workflow.getWorkflowDefinition)(nameOrHandle).meta.name;
349
- const envelope = await this.rpc.workflow.run({
354
+ return this.rpc.workflow.run({
350
355
  name,
351
356
  args: options?.args === void 0 ? {} : options.args,
352
357
  options: {
@@ -355,6 +360,11 @@ class CopilotSession {
355
360
  logPhaseNames: options?.logPhaseNames
356
361
  }
357
362
  });
363
+ }),
364
+ run: (async (nameOrHandle, options) => {
365
+ throwIfWorkflowExecutionIsActive();
366
+ const name = typeof nameOrHandle === "string" ? nameOrHandle : (0, import_workflow.getWorkflowDefinition)(nameOrHandle).meta.name;
367
+ const envelope = await this.workflow.start(name, options);
358
368
  return this.settleWorkflowRun(envelope);
359
369
  }),
360
370
  resume: (async (runId, options) => {
@@ -953,6 +963,11 @@ class CopilotSession {
953
963
  this.permissionHandler = void 0;
954
964
  this.mcpAuthHandler = void 0;
955
965
  this.userInputHandler = void 0;
966
+ this.shellAuthenticationHandler = void 0;
967
+ for (const controller of this.pendingShellAuthenticationRequests.values()) {
968
+ controller.abort();
969
+ }
970
+ this.pendingShellAuthenticationRequests.clear();
956
971
  this.elicitationHandler = void 0;
957
972
  this.exitPlanModeHandler = void 0;
958
973
  this.autoModeSwitchHandler = void 0;
@@ -1567,6 +1582,7 @@ class CopilotSession {
1567
1582
  try {
1568
1583
  const context = {
1569
1584
  runId: params.runId,
1585
+ agents: definition.agents,
1570
1586
  args: params.args,
1571
1587
  session: self,
1572
1588
  signal: controller.signal,
@@ -1582,7 +1598,18 @@ class CopilotSession {
1582
1598
  await progress.flush();
1583
1599
  const opts = {};
1584
1600
  for (const key of import_workflow.WORKFLOW_AGENT_OPTION_KEYS) {
1585
- copyDefinedWorkflowAgentOption(options, opts, key);
1601
+ if (key === "agent") {
1602
+ if (typeof options.agent === "string") {
1603
+ opts.agent = options.agent;
1604
+ } else if (options.agent !== void 0) {
1605
+ opts.role = (0, import_workflow.getWorkflowAgentReference)(
1606
+ definition,
1607
+ options.agent
1608
+ );
1609
+ }
1610
+ } else {
1611
+ copyDefinedWorkflowAgentOption(options, opts, key);
1612
+ }
1586
1613
  }
1587
1614
  const response = await awaitWorkflowOperation(
1588
1615
  () => self.rpc.workflow.agent({
@@ -1807,7 +1834,8 @@ class CopilotSession {
1807
1834
  result: {
1808
1835
  action: result.action,
1809
1836
  ...result.content ? { content: result.content } : {}
1810
- }
1837
+ },
1838
+ ...result.decisionContext !== void 0 ? { decisionContext: result.decisionContext } : {}
1811
1839
  });
1812
1840
  } catch {
1813
1841
  try {
@@ -1966,6 +1994,17 @@ class CopilotSession {
1966
1994
  this.assertConnected();
1967
1995
  this.userInputHandler = handler;
1968
1996
  }
1997
+ /**
1998
+ * Registers the handler for passwords and other answers that shell
1999
+ * commands run by the agent ask for.
2000
+ *
2001
+ * @param handler - The shell authentication handler, or undefined to remove it
2002
+ * @internal This method is typically called internally when creating a session.
2003
+ */
2004
+ registerShellAuthenticationHandler(handler) {
2005
+ this.assertConnected();
2006
+ this.shellAuthenticationHandler = handler;
2007
+ }
1969
2008
  /**
1970
2009
  * Registers the session's skill provider.
1971
2010
  *
@@ -2172,6 +2211,54 @@ class CopilotSession {
2172
2211
  throw error;
2173
2212
  }
2174
2213
  }
2214
+ /**
2215
+ * Asks the registered handler for a secret. Any failure, a malformed answer,
2216
+ * or an abort cancels the prompt, so the program that asked fails instead
2217
+ * of receiving a wrong value. Never logs the answer.
2218
+ *
2219
+ * @param cancelled - Aborted when the runtime no longer needs the answer.
2220
+ * @internal This method is for internal use by the SDK.
2221
+ */
2222
+ async _handleShellAuthenticationRequest(request, cancelled) {
2223
+ const handler = this.shellAuthenticationHandler;
2224
+ if (!handler || cancelled.aborted || this.pendingShellAuthenticationRequests.has(request.requestId)) {
2225
+ return { action: "cancel" };
2226
+ }
2227
+ const controller = new AbortController();
2228
+ const abort = () => controller.abort();
2229
+ cancelled.addEventListener("abort", abort, { once: true });
2230
+ this.pendingShellAuthenticationRequests.set(request.requestId, controller);
2231
+ try {
2232
+ const cancellation = new Promise((resolve) => {
2233
+ controller.signal.addEventListener("abort", () => resolve(void 0), {
2234
+ once: true
2235
+ });
2236
+ });
2237
+ const result = await Promise.race([
2238
+ Promise.resolve(
2239
+ handler(request, {
2240
+ sessionId: this.sessionId,
2241
+ signal: controller.signal
2242
+ })
2243
+ ),
2244
+ cancellation
2245
+ ]);
2246
+ if (controller.signal.aborted || result?.action !== "accept" || typeof result.value !== "string") {
2247
+ return { action: "cancel" };
2248
+ }
2249
+ return { action: "accept", value: result.value };
2250
+ } catch (error) {
2251
+ console.error("Shell authentication handler failed", {
2252
+ sessionId: this.sessionId,
2253
+ requestId: request.requestId,
2254
+ errorType: errorTypeName(error)
2255
+ });
2256
+ return { action: "cancel" };
2257
+ } finally {
2258
+ cancelled.removeEventListener("abort", abort);
2259
+ this.pendingShellAuthenticationRequests.delete(request.requestId);
2260
+ }
2261
+ }
2175
2262
  /**
2176
2263
  * Handles a hooks invocation from the Copilot CLI.
2177
2264
  *
@@ -2216,6 +2303,7 @@ class CopilotSession {
2216
2303
  *
2217
2304
  * This returns the complete conversation history including user messages,
2218
2305
  * assistant responses, tool executions, and other session events.
2306
+ * Use getRawEvents for archives containing integers outside JavaScript's safe range.
2219
2307
  *
2220
2308
  * @returns A promise that resolves with an array of all session events
2221
2309
  * @throws Error if the session has been disconnected or the connection fails
@@ -2236,6 +2324,19 @@ class CopilotSession {
2236
2324
  });
2237
2325
  return response.events;
2238
2326
  }
2327
+ /**
2328
+ * Retrieves history with unsafe integers preserved as bigint values.
2329
+ * Timestamp strings, explicit nulls, and unknown fields are retained.
2330
+ * Pass the result directly to taskAnalytics.classifyTrajectory; JSON.stringify
2331
+ * does not support bigint, but that RPC's encoder does.
2332
+ */
2333
+ async getRawEvents() {
2334
+ const response = await this.connection.sendRequest(
2335
+ "session.getMessages",
2336
+ { sessionId: this.sessionId, [import_taskAnalyticsJson.rawHistoryResponse]: true }
2337
+ );
2338
+ return response.events;
2339
+ }
2239
2340
  /**
2240
2341
  * Disconnects this session and releases all in-memory resources (event handlers,
2241
2342
  * tool handlers, permission handlers).
@@ -2323,8 +2424,9 @@ class CopilotSession {
2323
2424
  * await session.setModel("gpt-5.4");
2324
2425
  * await session.setModel("claude-sonnet-4.6", { reasoningEffort: "high" });
2325
2426
  *
2326
- * // Select the Auto model and its routing preference in one call.
2327
- * await session.setModel("auto", { autoTier: "intelligence" });
2427
+ * // Select Copilot Fusion and its tier in one call, like
2428
+ * // `copilot --model fusion --fusion-tier high`.
2429
+ * await session.setModel("fusion", { fusionTier: "high" });
2328
2430
  * ```
2329
2431
  */
2330
2432
  async setModel(model, options) {
@@ -2346,6 +2448,10 @@ class CopilotSession {
2346
2448
  * Only the most recent request survives: issuing a new request replaces any
2347
2449
  * earlier one that has not yet been claimed by a turn.
2348
2450
  *
2451
+ * For Copilot Fusion, prefer {@link setFusionTier}. The `balance`,
2452
+ * `hydrafusion` and `hydrafusion-max` identifiers it replaces remain
2453
+ * accepted but are deprecated.
2454
+ *
2349
2455
  * @param autoTier - Routing preference to activate, or `null` to return to
2350
2456
  * the provider's default Auto routing
2351
2457
  * @returns The runtime's immediate acknowledgement and Auto preference snapshot
@@ -2364,6 +2470,33 @@ class CopilotSession {
2364
2470
  async setAutoTier(autoTier) {
2365
2471
  return await this.rpc.model.switchAutoTier({ autoTier });
2366
2472
  }
2473
+ /**
2474
+ * Change the Copilot Fusion tier without changing the selected model,
2475
+ * naming the tier as the CLI's `--fusion-tier` does.
2476
+ *
2477
+ * The runtime resolves the tier to the Auto routing preference it stands
2478
+ * for and then handles the request exactly like {@link setAutoTier}: it
2479
+ * takes effect on a later user turn that uses the `fusion` or `auto`
2480
+ * model. To return to the provider's default routing, call
2481
+ * `setAutoTier(null)`.
2482
+ *
2483
+ * @param fusionTier - Copilot Fusion tier to activate
2484
+ * @returns The runtime's immediate acknowledgement and Auto preference snapshot
2485
+ *
2486
+ * @experimental Part of an experimental Auto routing surface and may change
2487
+ * or be removed in a future release.
2488
+ *
2489
+ * @example
2490
+ * ```typescript
2491
+ * const result = await session.setFusionTier("max");
2492
+ * if (result.status === "pending") {
2493
+ * // Takes effect on a later turn that uses Copilot Fusion.
2494
+ * }
2495
+ * ```
2496
+ */
2497
+ async setFusionTier(fusionTier) {
2498
+ return await this.rpc.model.switchFusionTier({ fusionTier });
2499
+ }
2367
2500
  /**
2368
2501
  * Replace the tools this client supplies to the session.
2369
2502
  *
@@ -2385,8 +2518,9 @@ class CopilotSession {
2385
2518
  * The agent sees the new tools from its next model request, which can fall
2386
2519
  * within a turn in progress. A model request already in flight was made
2387
2520
  * with the previous tools, so the agent can still call a tool you removed.
2388
- * This session doesn't answer that call, and it can stay pending until the
2389
- * turn is aborted. If a running turn might still call a tool you remove,
2521
+ * If no connected client supplies a tool with that name any more, the call
2522
+ * fails with an error that tells the agent the tool is no longer available,
2523
+ * and the turn continues. If you don't want the agent to see that failure,
2390
2524
  * replace tools while the session is idle.
2391
2525
  *
2392
2526
  * @param tools - The complete set of tools this client supplies
@@ -2468,6 +2602,17 @@ function toCanvasRpcError(error) {
2468
2602
  function skillProviderFailure(operation) {
2469
2603
  return new import_node.ResponseError(import_node.ErrorCodes.InternalError, `Skill provider ${operation} failed`);
2470
2604
  }
2605
+ function errorTypeName(error) {
2606
+ if (typeof error !== "object" && typeof error !== "function" || error === null) {
2607
+ return typeof error;
2608
+ }
2609
+ try {
2610
+ const name = Object.getPrototypeOf(error)?.constructor?.name;
2611
+ return typeof name === "string" && name !== "" ? name : typeof error;
2612
+ } catch {
2613
+ return typeof error;
2614
+ }
2615
+ }
2471
2616
  function strictJsonValidationError(context, category, message, path) {
2472
2617
  return new import_node.ResponseError(import_node.ErrorCodes.InternalError, message, {
2473
2618
  code: context.code,
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var taskAnalyticsJson_exports = {};
30
+ __export(taskAnalyticsJson_exports, {
31
+ parseTrajectoryJson: () => parseTrajectoryJson,
32
+ rawHistoryResponse: () => rawHistoryResponse
33
+ });
34
+ module.exports = __toCommonJS(taskAnalyticsJson_exports);
35
+ const rawHistoryResponse = /* @__PURE__ */ Symbol("rawHistoryResponse");
36
+ async function parseTrajectoryJson(text) {
37
+ const { parse, parseNumberAndBigInt } = await import("lossless-json");
38
+ return parse(text, void 0, (token) => {
39
+ const value = parseNumberAndBigInt(token);
40
+ return typeof value === "bigint" && Number.isSafeInteger(Number(value)) ? Number(value) : value;
41
+ });
42
+ }
43
+ // Annotate the CommonJS export names for ESM import in node:
44
+ 0 && (module.exports = {
45
+ parseTrajectoryJson,
46
+ rawHistoryResponse
47
+ });
package/dist/cjs/types.js CHANGED
@@ -30,6 +30,7 @@ __export(types_exports, {
30
30
  approveAll: () => approveAll,
31
31
  convertMcpCallToolResult: () => convertMcpCallToolResult,
32
32
  createAttributedPermissionResult: () => createAttributedPermissionResult,
33
+ createAttributedResult: () => createAttributedResult,
33
34
  createSessionFsAdapter: () => import_sessionFsProvider.createSessionFsAdapter,
34
35
  defaultJoinSessionPermissionHandler: () => defaultJoinSessionPermissionHandler,
35
36
  defineTool: () => defineTool,
@@ -43,7 +44,6 @@ var import_copilotRequestHandler = require("./copilotRequestHandler.js");
43
44
  const RuntimeConnection = {
44
45
  /**
45
46
  * Spawn a runtime child process and communicate over its stdin/stdout.
46
- * This is the default if no {@link CopilotClientOptions.connection} is set.
47
47
  */
48
48
  forStdio(opts = {}) {
49
49
  return { kind: "stdio", path: opts.path, args: opts.args, env: opts.env };
@@ -71,9 +71,10 @@ const RuntimeConnection = {
71
71
  /**
72
72
  * Host the runtime in-process over the native runtime library's C ABI (FFI).
73
73
  *
74
- * @experimental Runtime configuration from `gitHubToken` and
74
+ * The default when no connection or environment override is supplied.
75
+ * Runtime configuration from `gitHubToken`, `telemetry` and
75
76
  * `baseDirectory` is scoped to this host, not the process environment.
76
- * Client-level `env`, `telemetry` and `workingDirectory` are unsupported.
77
+ * Client-level `env` and `workingDirectory` are unsupported.
77
78
  */
78
79
  forInProcess(options = {}) {
79
80
  return { kind: "inprocess", ...options };
@@ -151,6 +152,15 @@ function createAttributedPermissionResult(result, decisionContext) {
151
152
  const inner = isAttributedPermissionResult(result) ? result.result : result;
152
153
  return { kind: "attributed", result: inner, decisionContext };
153
154
  }
155
+ function createAttributedResult(result, decisionContext) {
156
+ if ("kind" in result && typeof result.kind === "string") {
157
+ return createAttributedPermissionResult(
158
+ result,
159
+ decisionContext
160
+ );
161
+ }
162
+ return { ...result, decisionContext };
163
+ }
154
164
  const approveAll = (request, invocation) => {
155
165
  if (invocation.managedSettingsEnabled) {
156
166
  throw new Error("approveAll cannot be used when managed settings are enabled");
@@ -186,6 +196,7 @@ const DisableBypassPermissionsModes = {
186
196
  approveAll,
187
197
  convertMcpCallToolResult,
188
198
  createAttributedPermissionResult,
199
+ createAttributedResult,
189
200
  createSessionFsAdapter,
190
201
  defaultJoinSessionPermissionHandler,
191
202
  defineTool,