@github/copilot-sdk 1.0.13-preview.3 → 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.
- package/README.md +26 -9
- package/dist/cjs/cliVersion.js +31 -0
- package/dist/cjs/client.js +99 -91
- package/dist/cjs/ffiRuntimeHost.js +14 -19
- package/dist/cjs/generated/rpc.js +19 -0
- package/dist/cjs/runtimeArtifacts.js +254 -0
- package/dist/cliVersion.d.ts +2 -0
- package/dist/cliVersion.js +6 -0
- package/dist/client.d.ts +2 -12
- package/dist/client.js +101 -92
- package/dist/ffiRuntimeHost.d.ts +3 -9
- package/dist/ffiRuntimeHost.js +15 -20
- package/dist/generated/rpc.d.ts +267 -7
- package/dist/generated/rpc.js +19 -0
- package/dist/generated/session-events.d.ts +322 -35
- package/dist/index.d.ts +1 -1
- package/dist/runtimeArtifacts.d.ts +18 -0
- package/dist/runtimeArtifacts.js +232 -0
- package/dist/types.d.ts +53 -2
- package/package.json +103 -88
|
@@ -0,0 +1,254 @@
|
|
|
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 runtimeArtifacts_exports = {};
|
|
20
|
+
__export(runtimeArtifacts_exports, {
|
|
21
|
+
RUNTIME_PLATFORMS: () => RUNTIME_PLATFORMS,
|
|
22
|
+
defaultRuntimeCacheRoot: () => defaultRuntimeCacheRoot,
|
|
23
|
+
ensureRuntimeBundle: () => ensureRuntimeBundle,
|
|
24
|
+
getRuntimePackageName: () => getRuntimePackageName,
|
|
25
|
+
getRuntimePlatform: () => getRuntimePlatform,
|
|
26
|
+
getRuntimeReleaseAssetName: () => getRuntimeReleaseAssetName,
|
|
27
|
+
materializeRuntimeBundle: () => materializeRuntimeBundle,
|
|
28
|
+
resolvePackageRoot: () => resolvePackageRoot,
|
|
29
|
+
validateFile: () => validateFile
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(runtimeArtifacts_exports);
|
|
32
|
+
var import_node_fs = require("node:fs");
|
|
33
|
+
var import_node_crypto = require("node:crypto");
|
|
34
|
+
var import_node_module = require("node:module");
|
|
35
|
+
var import_node_os = require("node:os");
|
|
36
|
+
var import_node_path = require("node:path");
|
|
37
|
+
var import_cliVersion = require("./cliVersion.js");
|
|
38
|
+
const import_meta = {};
|
|
39
|
+
const require2 = (0, import_node_module.createRequire)(typeof __filename === "string" ? __filename : import_meta.url);
|
|
40
|
+
const RUNTIME_PLATFORMS = [
|
|
41
|
+
"darwin-arm64",
|
|
42
|
+
"darwin-x64",
|
|
43
|
+
"linux-arm64",
|
|
44
|
+
"linux-x64",
|
|
45
|
+
"linuxmusl-arm64",
|
|
46
|
+
"linuxmusl-x64",
|
|
47
|
+
"win32-arm64",
|
|
48
|
+
"win32-x64"
|
|
49
|
+
];
|
|
50
|
+
const EXCLUDED_TOP_LEVEL = /* @__PURE__ */ new Set([
|
|
51
|
+
"app.js",
|
|
52
|
+
"assets",
|
|
53
|
+
"changelog.json",
|
|
54
|
+
"copilot",
|
|
55
|
+
"copilot.exe",
|
|
56
|
+
"foundry-local-sdk",
|
|
57
|
+
"index.js",
|
|
58
|
+
"LICENSE.md",
|
|
59
|
+
"napi-oop-runtime",
|
|
60
|
+
"npm-loader.js",
|
|
61
|
+
"package.json",
|
|
62
|
+
"pvrecorder",
|
|
63
|
+
"queries",
|
|
64
|
+
"README.md",
|
|
65
|
+
"sea-loader.js",
|
|
66
|
+
"webview"
|
|
67
|
+
]);
|
|
68
|
+
function validateFile(path, label) {
|
|
69
|
+
if (!(0, import_node_fs.existsSync)(path)) {
|
|
70
|
+
throw new Error(`${label} not found at ${path}.`);
|
|
71
|
+
}
|
|
72
|
+
if ((0, import_node_fs.statSync)(path).size === 0) {
|
|
73
|
+
throw new Error(`${label} at ${path} is empty.`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function validateRuntimeBundle(wrapper, runtimeNode) {
|
|
77
|
+
validateFile(wrapper, "Copilot runtime wrapper");
|
|
78
|
+
validateFile(runtimeNode, "Copilot runtime.node");
|
|
79
|
+
}
|
|
80
|
+
function isExcluded(relativePath) {
|
|
81
|
+
const parts = relativePath.split(import_node_path.sep);
|
|
82
|
+
const topLevel = parts[0];
|
|
83
|
+
const fileName = parts.at(-1) ?? "";
|
|
84
|
+
return EXCLUDED_TOP_LEVEL.has(topLevel) || /^tree-sitter.*\.wasm$/.test(topLevel) || /^voice-.*\.js$/.test(topLevel) || fileName === "cli-native.node" || parts.includes("mediaremote-adapter") || fileName.startsWith("copilot-runtime-bin");
|
|
85
|
+
}
|
|
86
|
+
function collectRuntimeAssets(sources) {
|
|
87
|
+
const assets = [];
|
|
88
|
+
const visit = (directory) => {
|
|
89
|
+
for (const entry of (0, import_node_fs.readdirSync)(directory, { withFileTypes: true })) {
|
|
90
|
+
const source = (0, import_node_path.join)(directory, entry.name);
|
|
91
|
+
const sourceRelative = (0, import_node_path.relative)(sources.packageRoot, source);
|
|
92
|
+
if (isExcluded(sourceRelative)) {
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if (entry.isDirectory()) {
|
|
96
|
+
visit(source);
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (!entry.isFile() && !entry.isSymbolicLink()) {
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
const parts = sourceRelative.split(import_node_path.sep);
|
|
103
|
+
if (parts[0] === "prebuilds") {
|
|
104
|
+
if (parts[1] !== sources.platform || parts.length < 3) {
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
assets.push({ source, relativePath: sourceRelative });
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
visit(sources.packageRoot);
|
|
112
|
+
return assets.sort((left, right) => left.relativePath.localeCompare(right.relativePath));
|
|
113
|
+
}
|
|
114
|
+
function sourceFingerprint(assets) {
|
|
115
|
+
const hash = (0, import_node_crypto.createHash)("sha256");
|
|
116
|
+
for (const asset of assets) {
|
|
117
|
+
const stat = (0, import_node_fs.lstatSync)(asset.source);
|
|
118
|
+
hash.update(asset.relativePath).update("\0");
|
|
119
|
+
hash.update(`${stat.size}:${stat.mtimeMs}`).update("\0");
|
|
120
|
+
}
|
|
121
|
+
return hash.digest("hex").slice(0, 20);
|
|
122
|
+
}
|
|
123
|
+
function makeExecutable(path) {
|
|
124
|
+
if (process.platform === "win32") {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const mode = (0, import_node_fs.statSync)(path).mode;
|
|
128
|
+
if ((mode & 73) === 0) {
|
|
129
|
+
(0, import_node_fs.chmodSync)(path, mode | 73);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function defaultRuntimeCacheRoot(platform = process.platform, home = (0, import_node_os.homedir)(), environment = process.env) {
|
|
133
|
+
const cacheDirectory = platform === "win32" ? environment.LOCALAPPDATA ?? (0, import_node_path.join)(home, "AppData", "Local") : platform === "darwin" ? (0, import_node_path.join)(home, "Library", "Caches") : environment.XDG_CACHE_HOME ?? (0, import_node_path.join)(home, ".cache");
|
|
134
|
+
return (0, import_node_path.join)(cacheDirectory, "github-copilot-sdk", "runtime");
|
|
135
|
+
}
|
|
136
|
+
function materializeRuntimeBundle(sources, cacheRoot = defaultRuntimeCacheRoot(), cacheKey = `${sources.platform}-${sourceFingerprint(collectRuntimeAssets(sources))}`) {
|
|
137
|
+
const assets = collectRuntimeAssets(sources);
|
|
138
|
+
const wrapperName = sources.platform.startsWith("win32") ? "copilot-runtime.exe" : "copilot-runtime";
|
|
139
|
+
const prebuildDir = (0, import_node_path.join)("prebuilds", sources.platform);
|
|
140
|
+
const wrapperRelative = (0, import_node_path.join)(prebuildDir, wrapperName);
|
|
141
|
+
const runtimeNodeRelative = (0, import_node_path.join)(prebuildDir, "runtime.node");
|
|
142
|
+
const sourceWrapper = assets.find((asset) => asset.relativePath === wrapperRelative)?.source;
|
|
143
|
+
const sourceRuntimeNode = assets.find(
|
|
144
|
+
(asset) => asset.relativePath === runtimeNodeRelative
|
|
145
|
+
)?.source;
|
|
146
|
+
validateRuntimeBundle(sourceWrapper ?? "", sourceRuntimeNode ?? "");
|
|
147
|
+
const installDir = (0, import_node_path.join)(cacheRoot, cacheKey);
|
|
148
|
+
const installedWrapper = (0, import_node_path.join)(installDir, wrapperRelative);
|
|
149
|
+
const installedRuntimeNode = (0, import_node_path.join)(installDir, runtimeNodeRelative);
|
|
150
|
+
if ((0, import_node_fs.existsSync)(installDir)) {
|
|
151
|
+
validateRuntimeBundle(installedWrapper, installedRuntimeNode);
|
|
152
|
+
makeExecutable(installedWrapper);
|
|
153
|
+
return installedWrapper;
|
|
154
|
+
}
|
|
155
|
+
(0, import_node_fs.mkdirSync)(cacheRoot, { recursive: true });
|
|
156
|
+
const stagingDir = (0, import_node_fs.mkdtempSync)((0, import_node_path.join)(cacheRoot, ".runtime-"));
|
|
157
|
+
try {
|
|
158
|
+
for (const asset of assets) {
|
|
159
|
+
const destination = (0, import_node_path.join)(stagingDir, asset.relativePath);
|
|
160
|
+
(0, import_node_fs.mkdirSync)((0, import_node_path.dirname)(destination), { recursive: true });
|
|
161
|
+
(0, import_node_fs.copyFileSync)(asset.source, destination);
|
|
162
|
+
}
|
|
163
|
+
const stagedWrapper = (0, import_node_path.join)(stagingDir, wrapperRelative);
|
|
164
|
+
makeExecutable(stagedWrapper);
|
|
165
|
+
(0, import_node_fs.renameSync)(stagingDir, installDir);
|
|
166
|
+
} catch (error) {
|
|
167
|
+
if (!(0, import_node_fs.existsSync)(installDir)) {
|
|
168
|
+
throw error;
|
|
169
|
+
}
|
|
170
|
+
validateRuntimeBundle(installedWrapper, installedRuntimeNode);
|
|
171
|
+
} finally {
|
|
172
|
+
(0, import_node_fs.rmSync)(stagingDir, { recursive: true, force: true });
|
|
173
|
+
}
|
|
174
|
+
return installedWrapper;
|
|
175
|
+
}
|
|
176
|
+
function isMusl() {
|
|
177
|
+
if (process.platform !== "linux") {
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
const report = process.report?.getReport();
|
|
181
|
+
return report?.header?.glibcVersionRuntime === void 0;
|
|
182
|
+
}
|
|
183
|
+
function getRuntimePlatform(platform = process.platform, arch = process.arch, musl = isMusl()) {
|
|
184
|
+
if (arch !== "x64" && arch !== "arm64") {
|
|
185
|
+
throw new Error(`Unsupported Copilot CLI architecture: ${arch}.`);
|
|
186
|
+
}
|
|
187
|
+
if (platform === "linux") {
|
|
188
|
+
return `${musl ? "linuxmusl" : "linux"}-${arch}`;
|
|
189
|
+
}
|
|
190
|
+
if (platform === "darwin" || platform === "win32") {
|
|
191
|
+
return `${platform}-${arch}`;
|
|
192
|
+
}
|
|
193
|
+
throw new Error(`Unsupported Copilot CLI platform: ${platform}-${arch}.`);
|
|
194
|
+
}
|
|
195
|
+
function getRuntimeReleaseAssetName(version, platform) {
|
|
196
|
+
return `github-copilot-${version}-${platform}.tgz`;
|
|
197
|
+
}
|
|
198
|
+
function getRuntimePackageName(platform) {
|
|
199
|
+
return `@github/copilot-sdk-${platform}`;
|
|
200
|
+
}
|
|
201
|
+
function resolvePackageRoot(packageName, searchPaths = require2.resolve.paths(packageName) ?? []) {
|
|
202
|
+
return searchPaths.map((base) => (0, import_node_path.join)(base, ...packageName.split("/"))).find((candidate) => (0, import_node_fs.existsSync)((0, import_node_path.join)(candidate, "package.json")));
|
|
203
|
+
}
|
|
204
|
+
async function ensureRuntimeBundle(version, options = {}) {
|
|
205
|
+
const platform = options.platform ?? getRuntimePlatform();
|
|
206
|
+
if (import_cliVersion.COPILOT_CLI_USE_NPM_PACKAGE) {
|
|
207
|
+
const packageName2 = `@github/copilot-${platform}`;
|
|
208
|
+
const packageRoot2 = resolvePackageRoot(packageName2, options.packageSearchPaths);
|
|
209
|
+
if (!packageRoot2) {
|
|
210
|
+
throw new Error(`Could not resolve ${packageName2} for Copilot CLI ${version}.`);
|
|
211
|
+
}
|
|
212
|
+
validateFile(
|
|
213
|
+
(0, import_node_path.join)(packageRoot2, "prebuilds", platform, "runtime.node"),
|
|
214
|
+
"Copilot runtime.node"
|
|
215
|
+
);
|
|
216
|
+
return materializeRuntimeBundle(
|
|
217
|
+
{ packageRoot: packageRoot2, platform },
|
|
218
|
+
options.cacheRoot,
|
|
219
|
+
`${version}-${platform}`
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
const packageName = getRuntimePackageName(platform);
|
|
223
|
+
const packageRoot = resolvePackageRoot(packageName, options.packageSearchPaths);
|
|
224
|
+
if (!packageRoot) {
|
|
225
|
+
throw new Error(
|
|
226
|
+
`Could not resolve ${packageName}. Reinstall @github/copilot-sdk so its platform package is installed.`
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
const wrapperName = platform.startsWith("win32") ? "copilot-runtime.exe" : "copilot-runtime";
|
|
230
|
+
const prebuildDir = (0, import_node_path.join)(packageRoot, "prebuilds", platform);
|
|
231
|
+
const wrapper = (0, import_node_path.join)(prebuildDir, wrapperName);
|
|
232
|
+
try {
|
|
233
|
+
validateRuntimeBundle(wrapper, (0, import_node_path.join)(prebuildDir, "runtime.node"));
|
|
234
|
+
} catch (error) {
|
|
235
|
+
throw new Error(
|
|
236
|
+
`${packageName} is missing required Copilot CLI runtime files. Reinstall @github/copilot-sdk.`,
|
|
237
|
+
{ cause: error }
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
makeExecutable(wrapper);
|
|
241
|
+
return wrapper;
|
|
242
|
+
}
|
|
243
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
244
|
+
0 && (module.exports = {
|
|
245
|
+
RUNTIME_PLATFORMS,
|
|
246
|
+
defaultRuntimeCacheRoot,
|
|
247
|
+
ensureRuntimeBundle,
|
|
248
|
+
getRuntimePackageName,
|
|
249
|
+
getRuntimePlatform,
|
|
250
|
+
getRuntimeReleaseAssetName,
|
|
251
|
+
materializeRuntimeBundle,
|
|
252
|
+
resolvePackageRoot,
|
|
253
|
+
validateFile
|
|
254
|
+
});
|
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;
|
|
@@ -91,7 +92,7 @@ export declare class CopilotClient {
|
|
|
91
92
|
private connectionExtraArgs;
|
|
92
93
|
/**
|
|
93
94
|
* Parse CLI URL into host and port
|
|
94
|
-
* Supports formats: "host:port", "http://host:port", "https://host:port", or just "port"
|
|
95
|
+
* Supports formats: "host:port", "[ipv6]:port", "http://host:port", "https://host:port", or just "port"
|
|
95
96
|
*/
|
|
96
97
|
private parseCliUrl;
|
|
97
98
|
private validateSessionFsConfig;
|
|
@@ -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
|
/**
|