@github/copilot-sdk 1.0.13-preview.4 → 1.0.13-preview.6

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.
@@ -1,4 +1,3 @@
1
- import { createHash } from "node:crypto";
2
1
  import {
3
2
  chmodSync,
4
3
  copyFileSync,
@@ -11,26 +10,37 @@ import {
11
10
  rmSync,
12
11
  statSync
13
12
  } from "node:fs";
13
+ import { createHash } from "node:crypto";
14
+ import { createRequire } from "node:module";
14
15
  import { homedir } from "node:os";
15
16
  import { dirname, join, relative, sep } from "node:path";
17
+ import { COPILOT_CLI_USE_NPM_PACKAGE } from "./cliVersion.js";
18
+ const require2 = createRequire(typeof __filename === "string" ? __filename : import.meta.url);
19
+ const RUNTIME_PLATFORMS = [
20
+ "darwin-arm64",
21
+ "darwin-x64",
22
+ "linux-arm64",
23
+ "linux-x64",
24
+ "linuxmusl-arm64",
25
+ "linuxmusl-x64",
26
+ "win32-arm64",
27
+ "win32-x64"
28
+ ];
16
29
  const EXCLUDED_TOP_LEVEL = /* @__PURE__ */ new Set([
17
30
  "app.js",
18
31
  "assets",
19
32
  "changelog.json",
20
33
  "copilot",
21
34
  "copilot.exe",
22
- "copilot-sdk",
23
35
  "foundry-local-sdk",
24
36
  "index.js",
25
37
  "LICENSE.md",
26
38
  "napi-oop-runtime",
27
39
  "npm-loader.js",
28
40
  "package.json",
29
- "preloads",
30
41
  "pvrecorder",
31
42
  "queries",
32
43
  "README.md",
33
- "sdk",
34
44
  "sea-loader.js",
35
45
  "webview"
36
46
  ]);
@@ -69,14 +79,12 @@ function collectRuntimeAssets(sources) {
69
79
  continue;
70
80
  }
71
81
  const parts = sourceRelative.split(sep);
72
- let relativePath = sourceRelative;
73
82
  if (parts[0] === "prebuilds") {
74
83
  if (parts[1] !== sources.platform || parts.length < 3) {
75
84
  continue;
76
85
  }
77
- relativePath = parts.slice(2).join(sep);
78
86
  }
79
- assets.push({ source, relativePath });
87
+ assets.push({ source, relativePath: sourceRelative });
80
88
  }
81
89
  };
82
90
  visit(sources.packageRoot);
@@ -104,15 +112,20 @@ function defaultRuntimeCacheRoot(platform = process.platform, home = homedir(),
104
112
  const cacheDirectory = platform === "win32" ? environment.LOCALAPPDATA ?? join(home, "AppData", "Local") : platform === "darwin" ? join(home, "Library", "Caches") : environment.XDG_CACHE_HOME ?? join(home, ".cache");
105
113
  return join(cacheDirectory, "github-copilot-sdk", "runtime");
106
114
  }
107
- function materializeRuntimeBundle(sources, cacheRoot = defaultRuntimeCacheRoot()) {
115
+ function materializeRuntimeBundle(sources, cacheRoot = defaultRuntimeCacheRoot(), cacheKey = `${sources.platform}-${sourceFingerprint(collectRuntimeAssets(sources))}`) {
108
116
  const assets = collectRuntimeAssets(sources);
109
- const wrapperName = process.platform === "win32" ? "copilot-runtime.exe" : "copilot-runtime";
110
- const sourceWrapper = assets.find((asset) => asset.relativePath === wrapperName)?.source;
111
- const sourceRuntimeNode = assets.find((asset) => asset.relativePath === "runtime.node")?.source;
117
+ const wrapperName = sources.platform.startsWith("win32") ? "copilot-runtime.exe" : "copilot-runtime";
118
+ const prebuildDir = join("prebuilds", sources.platform);
119
+ const wrapperRelative = join(prebuildDir, wrapperName);
120
+ const runtimeNodeRelative = join(prebuildDir, "runtime.node");
121
+ const sourceWrapper = assets.find((asset) => asset.relativePath === wrapperRelative)?.source;
122
+ const sourceRuntimeNode = assets.find(
123
+ (asset) => asset.relativePath === runtimeNodeRelative
124
+ )?.source;
112
125
  validateRuntimeBundle(sourceWrapper ?? "", sourceRuntimeNode ?? "");
113
- const installDir = join(cacheRoot, `${sources.platform}-${sourceFingerprint(assets)}`);
114
- const installedWrapper = join(installDir, wrapperName);
115
- const installedRuntimeNode = join(installDir, "runtime.node");
126
+ const installDir = join(cacheRoot, cacheKey);
127
+ const installedWrapper = join(installDir, wrapperRelative);
128
+ const installedRuntimeNode = join(installDir, runtimeNodeRelative);
116
129
  if (existsSync(installDir)) {
117
130
  validateRuntimeBundle(installedWrapper, installedRuntimeNode);
118
131
  makeExecutable(installedWrapper);
@@ -126,7 +139,7 @@ function materializeRuntimeBundle(sources, cacheRoot = defaultRuntimeCacheRoot()
126
139
  mkdirSync(dirname(destination), { recursive: true });
127
140
  copyFileSync(asset.source, destination);
128
141
  }
129
- const stagedWrapper = join(stagingDir, wrapperName);
142
+ const stagedWrapper = join(stagingDir, wrapperRelative);
130
143
  makeExecutable(stagedWrapper);
131
144
  renameSync(stagingDir, installDir);
132
145
  } catch (error) {
@@ -139,7 +152,81 @@ function materializeRuntimeBundle(sources, cacheRoot = defaultRuntimeCacheRoot()
139
152
  }
140
153
  return installedWrapper;
141
154
  }
155
+ function isMusl() {
156
+ if (process.platform !== "linux") {
157
+ return false;
158
+ }
159
+ const report = process.report?.getReport();
160
+ return report?.header?.glibcVersionRuntime === void 0;
161
+ }
162
+ function getRuntimePlatform(platform = process.platform, arch = process.arch, musl = isMusl()) {
163
+ if (arch !== "x64" && arch !== "arm64") {
164
+ throw new Error(`Unsupported Copilot CLI architecture: ${arch}.`);
165
+ }
166
+ if (platform === "linux") {
167
+ return `${musl ? "linuxmusl" : "linux"}-${arch}`;
168
+ }
169
+ if (platform === "darwin" || platform === "win32") {
170
+ return `${platform}-${arch}`;
171
+ }
172
+ throw new Error(`Unsupported Copilot CLI platform: ${platform}-${arch}.`);
173
+ }
174
+ function getRuntimeReleaseAssetName(version, platform) {
175
+ return `github-copilot-${version}-${platform}.tgz`;
176
+ }
177
+ function getRuntimePackageName(platform) {
178
+ return `@github/copilot-sdk-${platform}`;
179
+ }
180
+ function resolvePackageRoot(packageName, searchPaths = require2.resolve.paths(packageName) ?? []) {
181
+ return searchPaths.map((base) => join(base, ...packageName.split("/"))).find((candidate) => existsSync(join(candidate, "package.json")));
182
+ }
183
+ async function ensureRuntimeBundle(version, options = {}) {
184
+ const platform = options.platform ?? getRuntimePlatform();
185
+ if (COPILOT_CLI_USE_NPM_PACKAGE) {
186
+ const packageName2 = `@github/copilot-${platform}`;
187
+ const packageRoot2 = resolvePackageRoot(packageName2, options.packageSearchPaths);
188
+ if (!packageRoot2) {
189
+ throw new Error(`Could not resolve ${packageName2} for Copilot CLI ${version}.`);
190
+ }
191
+ validateFile(
192
+ join(packageRoot2, "prebuilds", platform, "runtime.node"),
193
+ "Copilot runtime.node"
194
+ );
195
+ return materializeRuntimeBundle(
196
+ { packageRoot: packageRoot2, platform },
197
+ options.cacheRoot,
198
+ `${version}-${platform}`
199
+ );
200
+ }
201
+ const packageName = getRuntimePackageName(platform);
202
+ const packageRoot = resolvePackageRoot(packageName, options.packageSearchPaths);
203
+ if (!packageRoot) {
204
+ throw new Error(
205
+ `Could not resolve ${packageName}. Reinstall @github/copilot-sdk so its platform package is installed.`
206
+ );
207
+ }
208
+ const wrapperName = platform.startsWith("win32") ? "copilot-runtime.exe" : "copilot-runtime";
209
+ const prebuildDir = join(packageRoot, "prebuilds", platform);
210
+ const wrapper = join(prebuildDir, wrapperName);
211
+ try {
212
+ validateRuntimeBundle(wrapper, join(prebuildDir, "runtime.node"));
213
+ } catch (error) {
214
+ throw new Error(
215
+ `${packageName} is missing required Copilot CLI runtime files. Reinstall @github/copilot-sdk.`,
216
+ { cause: error }
217
+ );
218
+ }
219
+ makeExecutable(wrapper);
220
+ return wrapper;
221
+ }
142
222
  export {
223
+ RUNTIME_PLATFORMS,
143
224
  defaultRuntimeCacheRoot,
144
- materializeRuntimeBundle
225
+ ensureRuntimeBundle,
226
+ getRuntimePackageName,
227
+ getRuntimePlatform,
228
+ getRuntimeReleaseAssetName,
229
+ materializeRuntimeBundle,
230
+ resolvePackageRoot,
231
+ validateFile
145
232
  };
package/dist/types.d.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  import type { Canvas } from "./canvas.js";
5
5
  import type { SessionFsProvider } from "./sessionFsProvider.js";
6
6
  import type { CopilotRequestHandler } from "./copilotRequestHandler.js";
7
- import type { PermissionRequest as GeneratedPermissionRequest, PermissionRequestedData as GeneratedPermissionRequestedData, PermissionRequestedEvent as GeneratedPermissionRequestedEvent, ReasoningSummary, SessionLimitsConfig, SessionEvent as GeneratedSessionEvent } from "./generated/session-events.js";
7
+ import type { AutoTier, PermissionRequest as GeneratedPermissionRequest, PermissionRequestedData as GeneratedPermissionRequestedData, PermissionRequestedEvent as GeneratedPermissionRequestedEvent, ReasoningSummary, SessionLimitsConfig, SessionEvent as GeneratedSessionEvent } from "./generated/session-events.js";
8
8
  import type { CopilotSession } from "./session.js";
9
9
  import type { FactoryJsonSchema, JsonValue } from "./factory.js";
10
10
  import type { GitHubTokenAcquireRequest, GitHubTokenAcquireResult, GitHubTelemetryNotification, ModelBillingTokenPrices, OpenCanvasInstance, RemoteSessionMode, CurrentToolMetadata } from "./generated/rpc.js";
@@ -34,7 +34,7 @@ export type { ModelBillingTokenPrices, ModelBillingTokenPricesLongContext, } fro
34
34
  export type SessionEvent = Exclude<GeneratedSessionEvent, {
35
35
  type: "permission.requested";
36
36
  }> | PermissionRequestedEvent;
37
- export type { ReasoningSummary } from "./generated/session-events.js";
37
+ export type { AutoTier, ReasoningSummary } from "./generated/session-events.js";
38
38
  export type { SessionFsProvider } from "./sessionFsProvider.js";
39
39
  export { createSessionFsAdapter } from "./sessionFsProvider.js";
40
40
  export type { SessionFsFileInfo } from "./sessionFsProvider.js";
@@ -216,6 +216,33 @@ export declare const RuntimeConnection: {
216
216
  * ambient behavior is unsafe (e.g. multi-user servers).
217
217
  */
218
218
  export type CopilotClientMode = "empty" | "copilot-cli";
219
+ /**
220
+ * Identity of the integrating application, declared once on the `server.connect`
221
+ * handshake so the telemetry the runtime emits on this connection is attributed
222
+ * to a single, consistent surface rather than to the runtime's own build.
223
+ *
224
+ * All fields are optional; omit any of them (or the whole object) to keep the
225
+ * runtime's default attribution. Version fields are ignored by the runtime
226
+ * unless they look like a version string.
227
+ */
228
+ export interface CopilotClientInfo {
229
+ /**
230
+ * Name of the application using the SDK, e.g. `"acme-developer-portal"`.
231
+ */
232
+ applicationName?: string;
233
+ /**
234
+ * Version of the application using the SDK, e.g. `"2.4.0"`.
235
+ */
236
+ applicationVersion?: string;
237
+ /**
238
+ * Optional name of a specific integration within the application, such as an extension or plugin.
239
+ */
240
+ integrationName?: string;
241
+ /**
242
+ * Optional version of the integration identified by `integrationName`.
243
+ */
244
+ integrationVersion?: string;
245
+ }
219
246
  export interface CopilotClientOptions {
220
247
  /**
221
248
  * How to connect to the Copilot runtime. When omitted, defaults to
@@ -370,6 +397,15 @@ export interface CopilotClientOptions {
370
397
  * @default false
371
398
  */
372
399
  enableRemoteSessions?: boolean;
400
+ /**
401
+ * Identity of the integrating application, forwarded to the runtime on the
402
+ * `server.connect` handshake. Declaring it lets the telemetry the runtime
403
+ * emits on this connection be attributed to a single, consistent surface
404
+ * (e.g. the application and its Copilot integration) instead of the
405
+ * runtime's own build. All fields are optional; omit it to keep the default
406
+ * attribution.
407
+ */
408
+ clientInfo?: CopilotClientInfo;
373
409
  }
374
410
  /**
375
411
  * Configuration for creating a session
@@ -1705,6 +1741,16 @@ export interface FactoryMeta {
1705
1741
  * provider-level choices are conceptually per-provider rather than global.
1706
1742
  */
1707
1743
  export interface CapiSessionOptions {
1744
+ /**
1745
+ * Routing preference used when the session model is `auto`.
1746
+ * Requires a runtime with Auto tier support and V2 Auto routing.
1747
+ *
1748
+ * When omitted on create, the runtime uses its default routing behavior.
1749
+ * The runtime persists this preference across cold resume; an explicit tier
1750
+ * on cold resume overrides the persisted value. For an already-resident
1751
+ * session, omission preserves the current tier and a different tier is rejected.
1752
+ */
1753
+ autoTier?: AutoTier;
1708
1754
  /**
1709
1755
  * Whether to use the WebSocket transport for the CAPI Responses API.
1710
1756
  *
@@ -2375,6 +2421,11 @@ export interface SessionConfigBase {
2375
2421
  * only if {@link CopilotClientOptions.sessionFs} is configured.
2376
2422
  */
2377
2423
  createSessionFsProvider?: (session: CopilotSession) => SessionFsProvider;
2424
+ /**
2425
+ * Feature-flag values resolved by the host for this session.
2426
+ * Re-supply them when resuming after a runtime restart.
2427
+ */
2428
+ featureFlags?: Record<string, boolean>;
2378
2429
  }
2379
2430
  /**
2380
2431
  * Configuration for creating a new session via {@link CopilotClient.createSession}.
package/package.json CHANGED
@@ -1,92 +1,107 @@
1
1
  {
2
- "name": "@github/copilot-sdk",
3
- "repository": {
4
- "type": "git",
5
- "url": "https://github.com/github/copilot-sdk.git"
6
- },
7
- "version": "1.0.13-preview.4",
8
- "description": "TypeScript SDK for programmatic control of GitHub Copilot CLI via JSON-RPC",
9
- "main": "./dist/cjs/index.js",
10
- "types": "./dist/index.d.ts",
11
- "exports": {
12
- ".": {
13
- "import": {
14
- "types": "./dist/index.d.ts",
15
- "default": "./dist/index.js"
16
- },
17
- "require": {
18
- "types": "./dist/index.d.ts",
19
- "default": "./dist/cjs/index.js"
20
- }
2
+ "name": "@github/copilot-sdk",
3
+ "repository": {
4
+ "type": "git",
5
+ "url": "https://github.com/github/copilot-sdk.git"
21
6
  },
22
- "./extension": {
23
- "import": {
24
- "types": "./dist/extension.d.ts",
25
- "default": "./dist/extension.js"
26
- },
27
- "require": {
28
- "types": "./dist/extension.d.ts",
29
- "default": "./dist/cjs/extension.js"
30
- }
7
+ "version": "1.0.13-preview.6",
8
+ "copilotCliVersion": "1.0.83-3",
9
+ "description": "TypeScript SDK for programmatic control of GitHub Copilot CLI via JSON-RPC",
10
+ "main": "./dist/cjs/index.js",
11
+ "types": "./dist/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "import": {
15
+ "types": "./dist/index.d.ts",
16
+ "default": "./dist/index.js"
17
+ },
18
+ "require": {
19
+ "types": "./dist/index.d.ts",
20
+ "default": "./dist/cjs/index.js"
21
+ }
22
+ },
23
+ "./extension": {
24
+ "import": {
25
+ "types": "./dist/extension.d.ts",
26
+ "default": "./dist/extension.js"
27
+ },
28
+ "require": {
29
+ "types": "./dist/extension.d.ts",
30
+ "default": "./dist/cjs/extension.js"
31
+ }
32
+ }
33
+ },
34
+ "type": "module",
35
+ "scripts": {
36
+ "clean": "rimraf --glob dist *.tgz",
37
+ "build": "tsx esbuild-copilotsdk-nodejs.ts",
38
+ "pack:release": "tsx scripts/package-sdk.ts",
39
+ "verify:release-packages": "tsx scripts/verify-release-packages.ts",
40
+ "prepare:runtime": "tsx scripts/prepare-runtime.ts",
41
+ "test": "vitest run",
42
+ "test:watch": "vitest",
43
+ "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\" --ignore-path .prettierignore",
44
+ "format:check": "prettier --check \"src/**/*.ts\" \"test/**/*.ts\" --ignore-path .prettierignore",
45
+ "lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
46
+ "lint:fix": "eslint --fix \"src/**/*.ts\" \"test/**/*.ts\"",
47
+ "typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json",
48
+ "generate": "cd ../scripts/codegen && npm run generate",
49
+ "set:cli-version": "node scripts/set-cli-version.js",
50
+ "update:protocol-version": "tsx scripts/update-protocol-version.ts",
51
+ "prepublishOnly": "npm run build",
52
+ "package": "npm run clean && npm run build && node scripts/set-version.js && npm run pack:release && npm version 0.0.0-dev --no-git-tag-version --allow-same-version"
53
+ },
54
+ "keywords": [
55
+ "github",
56
+ "copilot",
57
+ "sdk",
58
+ "jsonrpc",
59
+ "agent"
60
+ ],
61
+ "author": "GitHub",
62
+ "license": "MIT",
63
+ "dependencies": {
64
+ "koffi": "^3.1.0",
65
+ "vscode-jsonrpc": "^8.2.1",
66
+ "zod": "^4.3.6"
67
+ },
68
+ "devDependencies": {
69
+ "@platformatic/vfs": "^0.3.0",
70
+ "@types/node": "^25.2.0",
71
+ "@types/ws": "^8.18.1",
72
+ "@typescript-eslint/eslint-plugin": "^8.54.0",
73
+ "@typescript-eslint/parser": "^8.54.0",
74
+ "esbuild": "^0.28.1",
75
+ "eslint": "^9.0.0",
76
+ "glob": "^13.0.1",
77
+ "json-schema": "^0.4.0",
78
+ "json-schema-to-typescript": "^15.0.4",
79
+ "prettier": "^3.8.1",
80
+ "quicktype-core": "^23.2.6",
81
+ "rimraf": "^6.1.2",
82
+ "semver": "^7.7.3",
83
+ "tar": "^7.5.22",
84
+ "tsx": "^4.20.6",
85
+ "typescript": "^5.0.0",
86
+ "vitest": "^4.0.18",
87
+ "ws": "^8.21.0"
88
+ },
89
+ "engines": {
90
+ "node": "^20.19.0 || >=22.12.0"
91
+ },
92
+ "files": [
93
+ "dist/**/*",
94
+ "docs/**/*",
95
+ "README.md"
96
+ ],
97
+ "optionalDependencies": {
98
+ "@github/copilot-sdk-darwin-arm64": "1.0.13-preview.6",
99
+ "@github/copilot-sdk-darwin-x64": "1.0.13-preview.6",
100
+ "@github/copilot-sdk-linux-arm64": "1.0.13-preview.6",
101
+ "@github/copilot-sdk-linux-x64": "1.0.13-preview.6",
102
+ "@github/copilot-sdk-linuxmusl-arm64": "1.0.13-preview.6",
103
+ "@github/copilot-sdk-linuxmusl-x64": "1.0.13-preview.6",
104
+ "@github/copilot-sdk-win32-arm64": "1.0.13-preview.6",
105
+ "@github/copilot-sdk-win32-x64": "1.0.13-preview.6"
31
106
  }
32
- },
33
- "type": "module",
34
- "scripts": {
35
- "clean": "rimraf --glob dist *.tgz",
36
- "build": "tsx esbuild-copilotsdk-nodejs.ts",
37
- "test": "vitest run",
38
- "test:watch": "vitest",
39
- "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\" --ignore-path .prettierignore",
40
- "format:check": "prettier --check \"src/**/*.ts\" \"test/**/*.ts\" --ignore-path .prettierignore",
41
- "lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
42
- "lint:fix": "eslint --fix \"src/**/*.ts\" \"test/**/*.ts\"",
43
- "typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json",
44
- "generate": "cd ../scripts/codegen && npm run generate",
45
- "update:protocol-version": "tsx scripts/update-protocol-version.ts",
46
- "prepublishOnly": "npm run build",
47
- "package": "npm run clean && npm run build && node scripts/set-version.js && npm pack && npm version 0.0.0-dev --no-git-tag-version --allow-same-version"
48
- },
49
- "keywords": [
50
- "github",
51
- "copilot",
52
- "sdk",
53
- "jsonrpc",
54
- "agent"
55
- ],
56
- "author": "GitHub",
57
- "license": "MIT",
58
- "dependencies": {
59
- "@github/copilot": "^1.0.83-0",
60
- "koffi": "^3.1.0",
61
- "vscode-jsonrpc": "^8.2.1",
62
- "zod": "^4.3.6"
63
- },
64
- "devDependencies": {
65
- "@platformatic/vfs": "^0.3.0",
66
- "@types/node": "^25.2.0",
67
- "@types/ws": "^8.18.1",
68
- "@typescript-eslint/eslint-plugin": "^8.54.0",
69
- "@typescript-eslint/parser": "^8.54.0",
70
- "esbuild": "^0.28.1",
71
- "eslint": "^9.0.0",
72
- "glob": "^13.0.1",
73
- "json-schema": "^0.4.0",
74
- "json-schema-to-typescript": "^15.0.4",
75
- "prettier": "^3.8.1",
76
- "quicktype-core": "^23.2.6",
77
- "rimraf": "^6.1.2",
78
- "semver": "^7.7.3",
79
- "tsx": "^4.20.6",
80
- "typescript": "^5.0.0",
81
- "vitest": "^4.0.18",
82
- "ws": "^8.21.0"
83
- },
84
- "engines": {
85
- "node": "^20.19.0 || >=22.12.0"
86
- },
87
- "files": [
88
- "dist/**/*",
89
- "docs/**/*",
90
- "README.md"
91
- ]
92
107
  }