@love-moon/ai-sdk 0.3.1 → 0.3.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @love-moon/ai-sdk
2
2
 
3
+ ## 0.3.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 8e1d4a8: Prefer the bundled Copilot platform executable before the JS entrypoint so Node
8
+ 20 installs do not fail with `ERR_UNKNOWN_BUILTIN_MODULE: node:sqlite`.
9
+
3
10
  ## 0.3.1
4
11
 
5
12
  ### Patch Changes
@@ -1,3 +1,10 @@
1
+ export function resolveBundledCopilotCliPath({ platform, arch, resolvePackage, resolvePackagePaths, existsSyncFn, }?: {
2
+ platform?: NodeJS.Platform | undefined;
3
+ arch?: NodeJS.Architecture | undefined;
4
+ resolvePackage?: ((packageName: any) => string) | undefined;
5
+ resolvePackagePaths?: ((packageName: any) => string[]) | undefined;
6
+ existsSyncFn?: typeof existsSync | undefined;
7
+ }): string | null;
1
8
  export class CopilotSdkSession extends EventEmitter<[never]> {
2
9
  constructor(backend: any, options?: {});
3
10
  backend: string;
@@ -190,4 +197,5 @@ export class CopilotSdkSession extends EventEmitter<[never]> {
190
197
  }>;
191
198
  close(): Promise<void>;
192
199
  }
200
+ import { existsSync } from "node:fs";
193
201
  import { EventEmitter } from "node:events";
@@ -1,5 +1,6 @@
1
1
  import { EventEmitter } from "node:events";
2
2
  import { existsSync } from "node:fs";
3
+ import { createRequire } from "node:module";
3
4
  import path from "node:path";
4
5
  import { COPILOT_SDK_VARIANT as COPILOT_PROVIDER_VARIANT } from "../built-in-backends.js";
5
6
  import { emitLog, getBoundedEnvInt, loadEnvConfig, normalizeLogger, parseCommandParts, proxyToEnv, sanitizeForLog, withoutCopilotGithubTokenEnv, } from "../shared.js";
@@ -9,6 +10,7 @@ const MAX_TURN_DEADLINE_MS = 30 * 60 * 1000;
9
10
  const DEFAULT_CLOSE_TIMEOUT_MS = 5 * 1000;
10
11
  const SDK_SEND_AND_WAIT_TIMEOUT_GRACE_MS = 5 * 1000;
11
12
  const LEGACY_COPILOT_CLI_ARGS = new Set(["--allow-all-paths", "--allow-all-tools"]);
13
+ const moduleRequire = createRequire(import.meta.url);
12
14
  function waitForever() {
13
15
  return new Promise(() => { });
14
16
  }
@@ -192,6 +194,44 @@ function unwrapEnvironmentCommand(command, args) {
192
194
  function hasOwnEnumerableKeys(value) {
193
195
  return value && typeof value === "object" && Object.keys(value).length > 0;
194
196
  }
197
+ function resolveCopilotPlatformPackageName(platform = process.platform, arch = process.arch) {
198
+ if (!["darwin", "linux", "win32"].includes(platform)) {
199
+ return null;
200
+ }
201
+ if (!["arm64", "x64"].includes(arch)) {
202
+ return null;
203
+ }
204
+ return `@github/copilot-${platform}-${arch}`;
205
+ }
206
+ function resolvePackageFileFromSearchPaths(packageName, relativePath, resolvePackagePaths, existsSyncFn) {
207
+ const searchPaths = resolvePackagePaths(packageName) || [];
208
+ const packageParts = packageName.split("/");
209
+ for (const basePath of searchPaths) {
210
+ const candidate = path.join(basePath, ...packageParts, relativePath);
211
+ if (existsSyncFn(candidate)) {
212
+ return candidate;
213
+ }
214
+ }
215
+ return null;
216
+ }
217
+ export function resolveBundledCopilotCliPath({ platform = process.platform, arch = process.arch, resolvePackage = (packageName) => moduleRequire.resolve(packageName), resolvePackagePaths = (packageName) => moduleRequire.resolve.paths(packageName) || [], existsSyncFn = existsSync, } = {}) {
218
+ const platformPackageName = resolveCopilotPlatformPackageName(platform, arch);
219
+ if (platformPackageName) {
220
+ try {
221
+ const platformExecutablePath = resolvePackage(platformPackageName);
222
+ if (platformExecutablePath && existsSyncFn(platformExecutablePath)) {
223
+ return platformExecutablePath;
224
+ }
225
+ }
226
+ catch {
227
+ // Optional platform packages may be absent when optional dependencies are disabled.
228
+ }
229
+ }
230
+ return resolvePackageFileFromSearchPaths("@github/copilot", "npm-loader.js", resolvePackagePaths, existsSyncFn);
231
+ }
232
+ function hasExplicitCopilotCliPathEnv(env) {
233
+ return typeof env?.COPILOT_CLI_PATH === "string" && env.COPILOT_CLI_PATH.trim();
234
+ }
195
235
  function resolveCopilotCliLaunch(commandLine, env = process.env) {
196
236
  const normalized = typeof commandLine === "string" ? commandLine.trim() : "";
197
237
  if (!normalized) {
@@ -395,6 +435,14 @@ function buildCopilotClientOptions(options, cwd, env) {
395
435
  clientOptions.env = hasExplicitGithubToken
396
436
  ? resolvedEnv
397
437
  : withoutCopilotGithubTokenEnv(resolvedEnv);
438
+ if (clientOptions.cliPath === undefined &&
439
+ clientOptions.cliUrl === undefined &&
440
+ !hasExplicitCopilotCliPathEnv(clientOptions.env)) {
441
+ const bundledCliPath = resolveBundledCopilotCliPath();
442
+ if (bundledCliPath) {
443
+ clientOptions.cliPath = bundledCliPath;
444
+ }
445
+ }
398
446
  if (!hasExplicitGithubToken && clientOptions.useLoggedInUser === undefined) {
399
447
  clientOptions.useLoggedInUser = true;
400
448
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@love-moon/ai-sdk",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/lovemoon-ai/conductor.git"
@@ -32,5 +32,5 @@
32
32
  "@types/node": "^22.10.2",
33
33
  "typescript": "^5.6.3"
34
34
  },
35
- "gitCommitId": "03b4582"
35
+ "gitCommitId": "519f104"
36
36
  }