@github/copilot-sdk 1.0.13-preview.2 → 1.0.13-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/dist/client.d.ts CHANGED
@@ -33,6 +33,7 @@ export declare class CopilotClient {
33
33
  private _rpc;
34
34
  private _internalRpc;
35
35
  private processExitPromise;
36
+ private processTransportError;
36
37
  private negotiatedProtocolVersion;
37
38
  /** Connection-level session filesystem config, set via constructor option. */
38
39
  private sessionFsConfig;
@@ -452,17 +453,6 @@ export declare class CopilotClient {
452
453
  * reusing the same `vscode-jsonrpc` framing as the stdio transport.
453
454
  */
454
455
  private connectViaFfi;
455
- /**
456
- * Resolves the CLI entrypoint used for in-process FFI hosting: `COPILOT_CLI_PATH`
457
- * when set, otherwise the bundled platform-package entrypoint.
458
- */
459
- private resolveCliPathForFfi;
460
- /**
461
- * Returns the napi prebuilds folder name for the current host — the
462
- * `<node-platform>-<arch>` convention (e.g. `win32-x64`, `darwin-arm64`,
463
- * `linux-x64`, `linuxmusl-x64`) under which the runtime ships
464
- * `prebuilds/<folder>/runtime.node`.
465
- */
466
456
  private static getNapiPrebuildsFolder;
467
457
  private static isMusl;
468
458
  /**
package/dist/client.js CHANGED
@@ -3,7 +3,7 @@ import { randomUUID } from "node:crypto";
3
3
  import { existsSync } from "node:fs";
4
4
  import { createRequire } from "node:module";
5
5
  import { Socket } from "node:net";
6
- import { dirname, isAbsolute, join } from "node:path";
6
+ import { dirname, isAbsolute, join, resolve } from "node:path";
7
7
  import { fileURLToPath } from "node:url";
8
8
  import {
9
9
  createMessageConnection,
@@ -20,6 +20,7 @@ import {
20
20
  } from "./generated/rpc.js";
21
21
  import { getSdkProtocolVersion } from "./sdkProtocolVersion.js";
22
22
  import { CopilotSession } from "./session.js";
23
+ import { materializeRuntimeBundle } from "./runtimeArtifacts.js";
23
24
  import { createSessionFsAdapter } from "./sessionFsProvider.js";
24
25
  import { createCopilotRequestAdapter } from "./copilotRequestHandler.js";
25
26
  import { getTraceContext } from "./telemetry.js";
@@ -49,7 +50,7 @@ async function waitForChildExit(child, timeoutMs) {
49
50
  if (child.exitCode != null || child.signalCode != null) {
50
51
  return true;
51
52
  }
52
- return new Promise((resolve) => {
53
+ return new Promise((resolve2) => {
53
54
  let timeout;
54
55
  let settled = false;
55
56
  const onExit = () => {
@@ -58,7 +59,7 @@ async function waitForChildExit(child, timeoutMs) {
58
59
  }
59
60
  settled = true;
60
61
  clearTimeout(timeout);
61
- resolve(true);
62
+ resolve2(true);
62
63
  };
63
64
  timeout = setTimeout(() => {
64
65
  if (settled) {
@@ -66,7 +67,7 @@ async function waitForChildExit(child, timeoutMs) {
66
67
  }
67
68
  settled = true;
68
69
  child.off("exit", onExit);
69
- resolve(false);
70
+ resolve2(false);
70
71
  }, timeoutMs);
71
72
  child.once("exit", onExit);
72
73
  if (child.exitCode != null || child.signalCode != null) {
@@ -189,14 +190,17 @@ function getCliPlatformPackageNames() {
189
190
  const variants = process.platform === "linux" ? ["linux", "linuxmusl"] : [process.platform];
190
191
  return variants.map((variant) => `@github/copilot-${variant}-${arch}`);
191
192
  }
192
- function getBundledCliPath() {
193
+ function getBundledCliPackage() {
193
194
  const packageNames = getCliPlatformPackageNames();
194
195
  if (typeof import.meta.resolve === "function") {
195
196
  for (const packageName of packageNames) {
196
197
  try {
197
198
  const packageEntryUrl = import.meta.resolve(packageName);
198
199
  const packageEntryPath = fileURLToPath(packageEntryUrl);
199
- return join(dirname(packageEntryPath), "index.js");
200
+ return {
201
+ root: dirname(packageEntryPath),
202
+ platform: packageName.slice("@github/copilot-".length)
203
+ };
200
204
  } catch {
201
205
  }
202
206
  }
@@ -208,9 +212,13 @@ function getBundledCliPath() {
208
212
  const searchPaths = req.resolve.paths("@github/copilot") ?? [];
209
213
  for (const base of searchPaths) {
210
214
  for (const packageName of packageNames) {
211
- const candidate = join(base, ...packageName.split("/"), "index.js");
215
+ const root = join(base, ...packageName.split("/"));
216
+ const candidate = join(root, "index.js");
212
217
  if (existsSync(candidate)) {
213
- return candidate;
218
+ return {
219
+ root,
220
+ platform: packageName.slice("@github/copilot-".length)
221
+ };
214
222
  }
215
223
  }
216
224
  }
@@ -218,6 +226,13 @@ function getBundledCliPath() {
218
226
  `Could not find a @github/copilot platform package (tried ${packageNames.join(", ")}). Searched ${searchPaths.length} paths. Ensure @github/copilot is installed, or pass cliPath/cliUrl to CopilotClient.`
219
227
  );
220
228
  }
229
+ function getBundledRuntimePath() {
230
+ const bundled = getBundledCliPackage();
231
+ return materializeRuntimeBundle({
232
+ packageRoot: bundled.root,
233
+ platform: bundled.platform
234
+ });
235
+ }
221
236
  class TeardownResilientStreamMessageWriter extends StreamMessageWriter {
222
237
  suppressWriteErrors = false;
223
238
  async write(msg) {
@@ -264,6 +279,7 @@ class CopilotClient {
264
279
  _internalRpc = null;
265
280
  processExitPromise = null;
266
281
  // Rejects when CLI process exits
282
+ processTransportError = null;
267
283
  negotiatedProtocolVersion = null;
268
284
  /** Connection-level session filesystem config, set via constructor option. */
269
285
  sessionFsConfig = null;
@@ -430,7 +446,14 @@ class CopilotClient {
430
446
  const connEnv = conn.kind === "stdio" || conn.kind === "tcp" ? conn.env : void 0;
431
447
  const effectiveEnv = connEnv ?? options.env ?? process.env;
432
448
  this.resolvedEnv = effectiveEnv;
433
- this.resolvedCliPath = conn.kind === "stdio" || conn.kind === "tcp" ? conn.path ?? effectiveEnv.COPILOT_CLI_PATH ?? getBundledCliPath() : void 0;
449
+ if (conn.kind === "stdio" || conn.kind === "tcp") {
450
+ const explicitCliPath = conn.path ?? effectiveEnv.COPILOT_CLI_PATH;
451
+ if (explicitCliPath) {
452
+ this.resolvedCliPath = explicitCliPath;
453
+ } else {
454
+ this.resolvedCliPath = getBundledRuntimePath();
455
+ }
456
+ }
434
457
  const connArgs = conn.kind === "stdio" || conn.kind === "tcp" ? conn.args ?? [] : [];
435
458
  this.connectionExtraArgs = [...connArgs];
436
459
  this.options = {
@@ -598,6 +621,8 @@ class CopilotClient {
598
621
  if (this.state === "connected") {
599
622
  return;
600
623
  }
624
+ this.forceStopping = false;
625
+ this.processTransportError = null;
601
626
  this.state = "connecting";
602
627
  try {
603
628
  if (this.connectionConfig.kind === "inprocess") {
@@ -630,8 +655,10 @@ class CopilotClient {
630
655
  }
631
656
  this.state = "connected";
632
657
  } catch (error) {
658
+ const startupError = this.processTransportError ?? error;
659
+ await this.forceStop();
633
660
  this.state = "error";
634
- throw error;
661
+ throw startupError;
635
662
  }
636
663
  }
637
664
  /**
@@ -676,7 +703,7 @@ class CopilotClient {
676
703
  lastError = error instanceof Error ? error : new Error(String(error));
677
704
  if (attempt < 3) {
678
705
  const delay = 100 * Math.pow(2, attempt - 1);
679
- await new Promise((resolve) => setTimeout(resolve, delay));
706
+ await new Promise((resolve2) => setTimeout(resolve2, delay));
680
707
  }
681
708
  }
682
709
  }
@@ -743,8 +770,8 @@ class CopilotClient {
743
770
  this.socket = null;
744
771
  try {
745
772
  if (!socket.destroyed) {
746
- await new Promise((resolve) => {
747
- socket.once("close", () => resolve());
773
+ await new Promise((resolve2) => {
774
+ socket.once("close", () => resolve2());
748
775
  socket.end();
749
776
  });
750
777
  }
@@ -1185,6 +1212,7 @@ class CopilotClient {
1185
1212
  requestPermission: !!config.onPermissionRequest,
1186
1213
  requestUserInput: !!config.onUserInputRequest,
1187
1214
  requestElicitation: !!config.onElicitationRequest,
1215
+ askUserVariant: config.askUserVariant,
1188
1216
  ...config.enableMcpApps ? { requestMcpApps: true } : {},
1189
1217
  ...config.githubMcpToolConfig != null ? { githubMcpToolConfig: config.githubMcpToolConfig } : {},
1190
1218
  requestExitPlanMode: !!config.onExitPlanModeRequest,
@@ -1417,6 +1445,7 @@ class CopilotClient {
1417
1445
  requestPermission: config.onPermissionRequest !== defaultJoinSessionPermissionHandler,
1418
1446
  requestUserInput: !!config.onUserInputRequest,
1419
1447
  requestElicitation: !!config.onElicitationRequest,
1448
+ askUserVariant: config.askUserVariant,
1420
1449
  ...config.enableMcpApps ? { requestMcpApps: true } : {},
1421
1450
  ...config.githubMcpToolConfig != null ? { githubMcpToolConfig: config.githubMcpToolConfig } : {},
1422
1451
  requestExitPlanMode: !!config.onExitPlanModeRequest,
@@ -1548,8 +1577,8 @@ class CopilotClient {
1548
1577
  async listModels() {
1549
1578
  await this.modelsCacheLock;
1550
1579
  let resolveLock;
1551
- this.modelsCacheLock = new Promise((resolve) => {
1552
- resolveLock = resolve;
1580
+ this.modelsCacheLock = new Promise((resolve2) => {
1581
+ resolveLock = resolve2;
1553
1582
  });
1554
1583
  try {
1555
1584
  if (this.modelsCache !== null) {
@@ -1865,7 +1894,7 @@ class CopilotClient {
1865
1894
  * Start the CLI server process
1866
1895
  */
1867
1896
  async startCLIServer() {
1868
- return new Promise((resolve, reject) => {
1897
+ return new Promise((resolve2, reject) => {
1869
1898
  this.stderrBuffer = "";
1870
1899
  const args = [...this.connectionExtraArgs, "--headless", "--no-auto-update"];
1871
1900
  if (this.options.logLevel) {
@@ -1926,7 +1955,7 @@ class CopilotClient {
1926
1955
  let resolved = false;
1927
1956
  if (this.connectionConfig.kind === "stdio") {
1928
1957
  resolved = true;
1929
- resolve();
1958
+ resolve2();
1930
1959
  } else {
1931
1960
  this.cliProcess.stdout?.on("data", (data) => {
1932
1961
  stdout += data.toString();
@@ -1934,7 +1963,7 @@ class CopilotClient {
1934
1963
  if (match && !resolved) {
1935
1964
  this.runtimePort = parseInt(match[1], 10);
1936
1965
  resolved = true;
1937
- resolve();
1966
+ resolve2();
1938
1967
  }
1939
1968
  });
1940
1969
  }
@@ -1966,26 +1995,27 @@ stderr: ${stderrOutput}`
1966
1995
  });
1967
1996
  this.processExitPromise = new Promise((_, rejectProcessExit) => {
1968
1997
  this.cliProcess.on("exit", (code) => {
1969
- setTimeout(() => {
1970
- const stderrOutput = this.stderrBuffer.trim();
1971
- if (stderrOutput) {
1972
- rejectProcessExit(
1973
- new Error(
1974
- `CLI server exited with code ${code}
1998
+ if (this.messageWriter) {
1999
+ this.messageWriter.suppressWriteErrors = true;
2000
+ }
2001
+ const stderrOutput = this.stderrBuffer.trim();
2002
+ if (stderrOutput) {
2003
+ rejectProcessExit(
2004
+ new Error(
2005
+ `CLI server exited with code ${code}
1975
2006
  stderr: ${stderrOutput}`
1976
- )
1977
- );
1978
- } else {
1979
- rejectProcessExit(
1980
- new Error(`CLI server exited unexpectedly with code ${code}`)
1981
- );
1982
- }
1983
- }, 50);
2007
+ )
2008
+ );
2009
+ } else {
2010
+ rejectProcessExit(
2011
+ new Error(`CLI server exited unexpectedly with code ${code}`)
2012
+ );
2013
+ }
1984
2014
  });
1985
2015
  });
1986
2016
  this.processExitPromise.catch(() => {
1987
2017
  });
1988
- this.cliProcess.on("exit", (code) => {
2018
+ this.cliProcess.on("close", (code) => {
1989
2019
  if (!resolved) {
1990
2020
  resolved = true;
1991
2021
  const stderrOutput = this.stderrBuffer.trim();
@@ -2027,7 +2057,13 @@ stderr: ${stderrOutput}`
2027
2057
  }
2028
2058
  /** Starts the in-process FFI runtime with SDK-managed typed options. */
2029
2059
  async startInProcessFfi() {
2030
- const entrypoint = this.resolveCliPathForFfi();
2060
+ const explicitEntrypoint = this.resolvedEnv.COPILOT_CLI_PATH;
2061
+ const runtimeLibrary = explicitEntrypoint ? join(
2062
+ dirname(resolve(explicitEntrypoint)),
2063
+ "prebuilds",
2064
+ CopilotClient.getNapiPrebuildsFolder(explicitEntrypoint),
2065
+ "runtime.node"
2066
+ ) : join(dirname(getBundledRuntimePath()), "runtime.node");
2031
2067
  const { FfiRuntimeHost } = await import("./ffiRuntimeHost.js");
2032
2068
  const environment = {};
2033
2069
  if (this.options.gitHubToken) {
@@ -2055,12 +2091,7 @@ stderr: ${stderrOutput}`
2055
2091
  if (this.options.enableRemoteSessions) {
2056
2092
  args.push("--remote");
2057
2093
  }
2058
- const host = FfiRuntimeHost.create(
2059
- entrypoint,
2060
- CopilotClient.getNapiPrebuildsFolder(entrypoint),
2061
- environment,
2062
- args
2063
- );
2094
+ const host = FfiRuntimeHost.create(runtimeLibrary, explicitEntrypoint, environment, args);
2064
2095
  this.ffiHost = host;
2065
2096
  await host.start();
2066
2097
  }
@@ -2080,19 +2111,6 @@ stderr: ${stderrOutput}`
2080
2111
  this.attachConnectionHandlers();
2081
2112
  this.connection.listen();
2082
2113
  }
2083
- /**
2084
- * Resolves the CLI entrypoint used for in-process FFI hosting: `COPILOT_CLI_PATH`
2085
- * when set, otherwise the bundled platform-package entrypoint.
2086
- */
2087
- resolveCliPathForFfi() {
2088
- return this.resolvedEnv.COPILOT_CLI_PATH ?? getBundledCliPath();
2089
- }
2090
- /**
2091
- * Returns the napi prebuilds folder name for the current host — the
2092
- * `<node-platform>-<arch>` convention (e.g. `win32-x64`, `darwin-arm64`,
2093
- * `linux-x64`, `linuxmusl-x64`) under which the runtime ships
2094
- * `prebuilds/<folder>/runtime.node`.
2095
- */
2096
2114
  static getNapiPrebuildsFolder(entrypoint) {
2097
2115
  const arch = process.arch;
2098
2116
  if (arch !== "x64" && arch !== "arm64") {
@@ -2128,6 +2146,11 @@ stderr: ${stderrOutput}`
2128
2146
  }
2129
2147
  this.state = "error";
2130
2148
  const reason = err instanceof Error ? err.stack ?? err.message : String(err);
2149
+ const stderrOutput = this.stderrBuffer.trim();
2150
+ this.processTransportError = new Error(
2151
+ `CLI server connection failed: ${reason}${stderrOutput ? `
2152
+ stderr: ${stderrOutput}` : ""}`
2153
+ );
2131
2154
  this.logDebug(`stdin pipe error: ${reason}`);
2132
2155
  try {
2133
2156
  this.connection?.dispose();
@@ -2164,7 +2187,7 @@ stderr: ${stderrOutput}`
2164
2187
  if (!this.runtimePort) {
2165
2188
  throw new Error("Server port not available");
2166
2189
  }
2167
- return new Promise((resolve, reject) => {
2190
+ return new Promise((resolve2, reject) => {
2168
2191
  this.socket = new Socket();
2169
2192
  const connectionTimeout = setTimeout(() => {
2170
2193
  this.socket?.destroy();
@@ -2179,7 +2202,7 @@ stderr: ${stderrOutput}`
2179
2202
  );
2180
2203
  this.attachConnectionHandlers();
2181
2204
  this.connection.listen();
2182
- resolve();
2205
+ resolve2();
2183
2206
  });
2184
2207
  this.socket.on("error", (error) => {
2185
2208
  clearTimeout(connectionTimeout);
@@ -42,7 +42,7 @@ export type JoinSessionConfig = Omit<ResumeSessionConfig, "onPermissionRequest"
42
42
  factories?: FactoryHandle[];
43
43
  };
44
44
  export type { ExtensionInfo, FactoryLimits, FactoryMeta } from "./types.js";
45
- export { defineFactory, FactoryResumeError, isFactoryRunTerminal, type RunOptions, type ResumeOptions, type FactoryResumeErrorCode, type SessionFactoryApi, type FactoryAgentOptions, type FactoryContext, type FactoryDefinition, type FactoryHandle, type FactoryJsonSchema, type JsonValue, type FactoryPipelineStage, type FactoryStepOptions, type FactoryRunResult, type FactoryRunStatus, type FactoryRunSummary, type FactoryRunDetail, type FactoryProgressPage, type FactoryProgressLine, type FactoryPhaseObservation, type FactoryPhaseStatus, type FactoryAgentSummary, } from "./factory.js";
45
+ export { defineFactory, FactoryResumeError, isFactoryRunTerminal, type RunOptions, type ResumeOptions, type FactoryResumeErrorCode, type SessionFactoryApi, type FactoryAgentOptions, type FactoryContext, type FactoryDefinition, type FactoryHandle, type FactoryJsonSchema, type JsonValue, type FactoryPipelineStage, type FactoryStepOptions, type FactoryRunResult, type FactoryRunStatus, type FactoryRunSummary, type FactoryListRunsOptions, type FactoryRunsPage, type FactoryRunDetail, type FactoryProgressPage, type FactoryProgressLine, type FactoryPhaseObservation, type FactoryPhaseStatus, type FactoryAgentSummary, } from "./factory.js";
46
46
  /**
47
47
  * Joins the current foreground session.
48
48
  *
package/dist/factory.d.ts CHANGED
@@ -1,9 +1,23 @@
1
- import type { FactoryGetRunProgressRequest, FactoryProgressPage, FactoryRunDetail, FactoryRunResult, FactoryRunStatus, FactoryRunSummary } from "./generated/rpc.js";
1
+ import type { FactoryGetRunProgressRequest, FactoryListRunsRequest, FactoryListRunsResult, FactoryProgressPage, FactoryRunDetail, FactoryRunResult, FactoryRunStatus, FactoryRunSummary } from "./generated/rpc.js";
2
2
  import type { ContextTier } from "./generated/session-events.js";
3
3
  import type { CopilotSession } from "./session.js";
4
4
  import type { FactoryLimits, FactoryMeta } from "./types.js";
5
5
  export type { FactoryRunResult };
6
6
  export type { FactoryAgentSummary, FactoryPhaseStatus, FactoryPhaseObservation, FactoryProgressLine, FactoryProgressPage, FactoryRunDetail, FactoryRunStatus, FactoryRunSummary, } from "./generated/rpc.js";
7
+ /**
8
+ * Options for paging durable factory runs.
9
+ *
10
+ * @experimental Part of the experimental Agent Factories surface and may
11
+ * change or be removed in future SDK or CLI releases.
12
+ */
13
+ export type FactoryListRunsOptions = FactoryListRunsRequest;
14
+ /**
15
+ * A page of durable factory runs and its paging metadata.
16
+ *
17
+ * @experimental Part of the experimental Agent Factories surface and may
18
+ * change or be removed in future SDK or CLI releases.
19
+ */
20
+ export type FactoryRunsPage = FactoryListRunsResult;
7
21
  /**
8
22
  * Whether a factory run status is terminal.
9
23
  *
@@ -165,6 +179,10 @@ export interface RunOptions<TArgs extends JsonValue = JsonValue> {
165
179
  args?: TArgs;
166
180
  /** Optional per-invocation resource ceiling overrides. */
167
181
  limits?: FactoryLimits;
182
+ /** Whether to notify the originating session when the factory completes. */
183
+ notifyOnComplete?: boolean;
184
+ /** Whether to emit factory phase names to the session transcript. */
185
+ logPhaseNames?: boolean;
168
186
  /**
169
187
  * Prior run whose persisted identity, arguments, journal, and accounting should be resumed.
170
188
  *
@@ -181,6 +199,10 @@ export interface RunOptions<TArgs extends JsonValue = JsonValue> {
181
199
  export interface ResumeOptions {
182
200
  /** Optional per-invocation resource ceiling overrides. */
183
201
  limits?: FactoryLimits;
202
+ /** Whether to notify the originating session when the factory completes. */
203
+ notifyOnComplete?: boolean;
204
+ /** Whether to emit factory phase names to the session transcript. */
205
+ logPhaseNames?: boolean;
184
206
  }
185
207
  /**
186
208
  * Machine-readable pre-execution factory resume failure.
@@ -239,8 +261,20 @@ export interface SessionFactoryApi {
239
261
  }): Promise<FactoryRunResult>;
240
262
  /**
241
263
  * List the newest default page of this session's durable factory runs.
264
+ *
265
+ * This backwards-compatible overload returns only the runs array. Pass
266
+ * paging options to receive the full page, including its cursors and
267
+ * truncation metadata.
242
268
  */
243
269
  listRuns(): Promise<FactoryRunSummary[]>;
270
+ /**
271
+ * Page this session's durable factory runs.
272
+ *
273
+ * `afterSeq` and `beforeSeq` are exclusive cursors. The result includes
274
+ * `oldestSeq`, `newestSeq`, `hasMoreNewer`, and `omittedOlder` so callers
275
+ * can continue paging without using the raw RPC client.
276
+ */
277
+ listRuns(options: FactoryListRunsOptions): Promise<FactoryRunsPage>;
244
278
  /** Read durable phases, direct agents, and the latest progress tail for a run. */
245
279
  getRunDetail(runId: string): Promise<FactoryRunDetail>;
246
280
  /** Page durable progress forward, backward, or from the latest tail. */
@@ -16,16 +16,10 @@ export declare class FfiRuntimeHost {
16
16
  readonly sendStream: Writable;
17
17
  private constructor();
18
18
  /**
19
- * Resolves the cdylib next to the given CLI entrypoint and prepares the FFI host.
20
- * The cdylib is resolved as `prebuilds/<prebuildsFolder>/runtime.node` relative to
21
- * the entrypoint directory (the napi-rs `<node-platform>-<arch>` layout, e.g.
22
- * `linux-x64`). Throws if it cannot be found.
23
- */
24
- static create(cliEntrypoint: string, prebuildsFolder: string, environment: Record<string, string | undefined> | undefined, args: readonly string[]): FfiRuntimeHost;
25
- /**
26
- * Starts the in-process runtime: spawns the CLI worker via the native host,
27
- * waits for readiness, and opens the FFI JSON-RPC connection.
19
+ * Loads the runtime cdylib at the given path and prepares the FFI host.
28
20
  */
21
+ static create(libraryPath: string, cliEntrypoint: string | undefined, environment: Record<string, string | undefined> | undefined, args: readonly string[]): FfiRuntimeHost;
22
+ /** Starts the in-process Rust runtime and opens the FFI JSON-RPC connection. */
29
23
  start(): Promise<void>;
30
24
  private writeFrame;
31
25
  /**
@@ -1,6 +1,6 @@
1
1
  import { existsSync } from "node:fs";
2
2
  import koffi from "koffi";
3
- import { dirname, join, resolve } from "node:path";
3
+ import { resolve } from "node:path";
4
4
  import { PassThrough, Writable } from "node:stream";
5
5
  const SYMBOL_PREFIX = "copilot_runtime_";
6
6
  const KEEP_ALIVE_INTERVAL_MS = 1 << 30;
@@ -52,7 +52,7 @@ function loadLibrary(libraryPath) {
52
52
  return loadedLibrary;
53
53
  }
54
54
  function buildArgvJson(cliEntrypoint, args) {
55
- const argv = cliEntrypoint.toLowerCase().endsWith(".js") ? ["node", cliEntrypoint, "--embedded-host", "--no-auto-update"] : [cliEntrypoint, "--embedded-host", "--no-auto-update"];
55
+ const argv = cliEntrypoint ? cliEntrypoint.toLowerCase().endsWith(".js") ? ["node", cliEntrypoint, "--embedded-host", "--no-auto-update"] : [cliEntrypoint, "--embedded-host", "--no-auto-update"] : [];
56
56
  argv.push(...args);
57
57
  return Buffer.from(JSON.stringify(argv), "utf8");
58
58
  }
@@ -107,24 +107,21 @@ class FfiRuntimeHost {
107
107
  /** The stream JSON-RPC writes client→server frames to. */
108
108
  sendStream;
109
109
  /**
110
- * Resolves the cdylib next to the given CLI entrypoint and prepares the FFI host.
111
- * The cdylib is resolved as `prebuilds/<prebuildsFolder>/runtime.node` relative to
112
- * the entrypoint directory (the napi-rs `<node-platform>-<arch>` layout, e.g.
113
- * `linux-x64`). Throws if it cannot be found.
110
+ * Loads the runtime cdylib at the given path and prepares the FFI host.
114
111
  */
115
- static create(cliEntrypoint, prebuildsFolder, environment, args) {
116
- const fullEntrypoint = resolve(cliEntrypoint);
117
- const distDir = dirname(fullEntrypoint);
118
- const libraryPath = join(distDir, "prebuilds", prebuildsFolder, "runtime.node");
119
- if (!existsSync(libraryPath)) {
120
- throw new Error(`FFI runtime library not found. Looked for '${libraryPath}'.`);
112
+ static create(libraryPath, cliEntrypoint, environment, args) {
113
+ const fullLibraryPath = resolve(libraryPath);
114
+ if (!existsSync(fullLibraryPath)) {
115
+ throw new Error(`FFI runtime library not found at '${fullLibraryPath}'.`);
121
116
  }
122
- return new FfiRuntimeHost(libraryPath, fullEntrypoint, environment, args);
117
+ return new FfiRuntimeHost(
118
+ fullLibraryPath,
119
+ cliEntrypoint ? resolve(cliEntrypoint) : void 0,
120
+ environment,
121
+ args
122
+ );
123
123
  }
124
- /**
125
- * Starts the in-process runtime: spawns the CLI worker via the native host,
126
- * waits for readiness, and opens the FFI JSON-RPC connection.
127
- */
124
+ /** Starts the in-process Rust runtime and opens the FFI JSON-RPC connection. */
128
125
  async start() {
129
126
  const argvJson = buildArgvJson(this.cliEntrypoint, this.args);
130
127
  const envJson = buildEnvJson(this.environment);
@@ -144,9 +141,7 @@ class FfiRuntimeHost {
144
141
  );
145
142
  });
146
143
  if (!this.serverId) {
147
- throw new Error(
148
- `copilot_runtime_host_start failed (library '${this.libraryPath}', entrypoint '${this.cliEntrypoint}').`
149
- );
144
+ throw new Error(`copilot_runtime_host_start failed (library '${this.libraryPath}').`);
150
145
  }
151
146
  this.outboundCallback = koffi.register(
152
147
  (_userData, bytesPtr, bytesLen) => this.feedInbound(bytesPtr, bytesLen),
@@ -3,7 +3,7 @@
3
3
  * Generated from: api.schema.json
4
4
  */
5
5
  import type { MessageConnection } from "vscode-jsonrpc/node.js";
6
- import type { AbortReason, Attachment, ContextTier, EmbeddedBlobResourceContents, EmbeddedTextResourceContents, McpOauthHttpResponse, McpOauthWWWAuthenticateParams, McpServerSource, McpServerStatus, ModelChangeSource, PermissionMode, PermissionPromptRequest, PermissionRule, ReasoningSummary, SessionEvent, SessionLimitsConfig, SessionMode, ShutdownType, SkillSource, TaskCompleteData, TaskCompletionOutcome, UserToolSessionApproval, Verbosity } from "./session-events.js";
6
+ import type { AbortReason, Attachment, AutoTier, ContextTier, EmbeddedBlobResourceContents, EmbeddedTextResourceContents, McpOauthHttpResponse, McpOauthWWWAuthenticateParams, McpServerSource, McpServerStatus, ModelChangeSource, PermissionMode, PermissionPromptRequest, PermissionRule, ReasoningSummary, SessionEvent, SessionLimitsConfig, SessionMode, ShutdownType, SkillSource, TaskCompleteData, TaskCompletionOutcome, UserToolSessionApproval, Verbosity } from "./session-events.js";
7
7
  /** A value that can be represented losslessly on the SDK JSON wire. */
8
8
  export type JsonValue = null | boolean | number | string | JsonValue[] | {
9
9
  [key: string]: JsonValue;
@@ -5180,6 +5180,7 @@ export interface CanvasProviderUnregisterRequest {
5180
5180
  */
5181
5181
  /** @experimental */
5182
5182
  export interface CapiSessionOptions {
5183
+ autoTier?: AutoTier;
5183
5184
  /**
5184
5185
  * Whether to use WebSocket transport for the CAPI Responses API. Enabled by default when the model advertises `ws:/responses` support; set to `false` to force the HTTP Responses transport in environments where WebSockets are blocked (e.g. behind a proxy). Setting this to `false` is equivalent to the `COPILOT_CLI_DISABLE_WEBSOCKET_RESPONSES` environment variable.
5185
5186
  */
@@ -6463,6 +6464,10 @@ export interface EnqueueCommandParams {
6463
6464
  * Slash-prefixed command string to enqueue, e.g. '/compact' or '/model gpt-4'. Queued FIFO with any in-flight items; if the session is idle, processing kicks off immediately.
6464
6465
  */
6465
6466
  command: string;
6467
+ /**
6468
+ * Optional user-facing text for the queue row. The command string is shown when omitted.
6469
+ */
6470
+ displayText?: string | null;
6466
6471
  }
6467
6472
  /**
6468
6473
  * Indicates whether the command was accepted into the local execution queue.
@@ -15877,6 +15882,27 @@ export interface SandboxConfigAuth {
15877
15882
  */
15878
15883
  gh?: boolean;
15879
15884
  }
15885
+ /**
15886
+ * Managed sandbox enforcement state for a session.
15887
+ *
15888
+ * This interface was referenced by `_RpcSchemaRoot`'s JSON-Schema
15889
+ * via the `definition` "SandboxEnforcementStatus".
15890
+ */
15891
+ /** @experimental */
15892
+ export interface SandboxEnforcementStatus {
15893
+ /**
15894
+ * Whether the effective managed policy requires an available sandbox backend.
15895
+ */
15896
+ required: boolean;
15897
+ /**
15898
+ * Whether an enforcement failure has permanently blocked the session.
15899
+ */
15900
+ blocked: boolean;
15901
+ /**
15902
+ * The first sandbox enforcement failure that blocked the session.
15903
+ */
15904
+ reason?: string;
15905
+ }
15880
15906
  /**
15881
15907
  * Register an absolute-time scheduled prompt.
15882
15908
  *
@@ -22160,7 +22186,7 @@ export declare function createServerRpc(connection: MessageConnection): {
22160
22186
  disable: (params: DiscoveredExtensionsDisableRequest) => Promise<void>;
22161
22187
  };
22162
22188
  /**
22163
- * Registers the calling SDK client as the per-entrypoint extension launch provider. Call before creating any sessions. When omitted, the runtime temporarily falls back to its built-in Node launcher for backward compatibility.
22189
+ * Registers the calling SDK client as the per-entrypoint extension launch provider. Call before creating any sessions. When omitted, the runtime uses its built-in extension launcher.
22164
22190
  *
22165
22191
  * @experimental
22166
22192
  */
@@ -22655,6 +22681,15 @@ export declare function createSessionRpc(connection: MessageConnection, sessionI
22655
22681
  * @experimental
22656
22682
  */
22657
22683
  sendMessages: (params: SendMessagesRequest) => Promise<SendMessagesResult>;
22684
+ /** @experimental */
22685
+ sandbox: {
22686
+ /**
22687
+ * Returns whether managed policy requires sandbox enforcement and whether an enforcement failure has permanently blocked the session.
22688
+ *
22689
+ * @returns Managed sandbox enforcement state for a session.
22690
+ */
22691
+ getEnforcementStatus: () => Promise<SandboxEnforcementStatus>;
22692
+ };
22658
22693
  /**
22659
22694
  * Aborts the current agent turn.
22660
22695
  *
@@ -172,7 +172,7 @@ function createServerRpc(connection) {
172
172
  disable: async (params) => connection.sendRequest("extensions.disable", params)
173
173
  },
174
174
  /**
175
- * Registers the calling SDK client as the per-entrypoint extension launch provider. Call before creating any sessions. When omitted, the runtime temporarily falls back to its built-in Node launcher for backward compatibility.
175
+ * Registers the calling SDK client as the per-entrypoint extension launch provider. Call before creating any sessions. When omitted, the runtime uses its built-in extension launcher.
176
176
  *
177
177
  * @experimental
178
178
  */
@@ -745,6 +745,15 @@ function createSessionRpc(connection, sessionId) {
745
745
  * @experimental
746
746
  */
747
747
  sendMessages: async (params) => connection.sendRequest("session.sendMessages", { sessionId, ...params }),
748
+ /** @experimental */
749
+ sandbox: {
750
+ /**
751
+ * Returns whether managed policy requires sandbox enforcement and whether an enforcement failure has permanently blocked the session.
752
+ *
753
+ * @returns Managed sandbox enforcement state for a session.
754
+ */
755
+ getEnforcementStatus: async () => connection.sendRequest("session.sandbox.getEnforcementStatus", { sessionId })
756
+ },
748
757
  /**
749
758
  * Aborts the current agent turn.
750
759
  *