@fangyb/ahchat-bridge 0.1.24 → 0.1.25

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 (3) hide show
  1. package/dist/cli.cjs +137 -9
  2. package/dist/index.js +132 -4
  3. package/package.json +1 -1
package/dist/cli.cjs CHANGED
@@ -27107,8 +27107,8 @@ function getReadableStream(readStream) {
27107
27107
  if (typeof Readable2.toWeb === "function") {
27108
27108
  return Readable2.toWeb(readStream);
27109
27109
  }
27110
- const require2 = process.getBuiltinModule("module").createRequire(importMetaUrl);
27111
- const polyfill = require2("node-readable-to-web-readable-stream");
27110
+ const require3 = process.getBuiltinModule("module").createRequire(importMetaUrl);
27111
+ const polyfill = require3("node-readable-to-web-readable-stream");
27112
27112
  return polyfill.makeDefaultReadableStreamFromNodeReadable(readStream);
27113
27113
  }
27114
27114
  function getNetworkStream(url2) {
@@ -35773,8 +35773,8 @@ var init_pdf = __esm({
35773
35773
  };
35774
35774
  NodeCanvasFactory = class extends BaseCanvasFactory {
35775
35775
  _createCanvas(width, height) {
35776
- const require2 = process.getBuiltinModule("module").createRequire(importMetaUrl);
35777
- const canvas = require2("@napi-rs/canvas");
35776
+ const require3 = process.getBuiltinModule("module").createRequire(importMetaUrl);
35777
+ const canvas = require3("@napi-rs/canvas");
35778
35778
  return canvas.createCanvas(width, height);
35779
35779
  }
35780
35780
  };
@@ -60030,6 +60030,7 @@ function ensureDir(dirPath) {
60030
60030
  // src/claudeRuntime.ts
60031
60031
  init_cjs_shims();
60032
60032
  var import_node_fs3 = require("fs");
60033
+ var import_node_module = require("module");
60033
60034
  var import_node_path5 = __toESM(require("path"), 1);
60034
60035
 
60035
60036
  // src/logger.ts
@@ -61536,6 +61537,7 @@ function normalizeBridgeServerUrls(rawUrl) {
61536
61537
 
61537
61538
  // src/claudeRuntime.ts
61538
61539
  var logger = createModuleLogger("bridge.claudeRuntime");
61540
+ var require2 = (0, import_node_module.createRequire)(importMetaUrl);
61539
61541
  var EXPLICIT_CLAUDE_EXECUTABLE_ENV = "AHCHAT_CLAUDE_EXECUTABLE";
61540
61542
  var BUNDLED_CLAUDE_PATH_ENV = "AHCHAT_BUNDLED_CLAUDE_PATH";
61541
61543
  function normalizePath(value) {
@@ -61585,6 +61587,118 @@ function validateCandidate(source, candidatePath) {
61585
61587
  version: version3
61586
61588
  };
61587
61589
  }
61590
+ function getSdkRuntimeTargets() {
61591
+ const binaryName = process.platform === "win32" ? "claude.exe" : "claude";
61592
+ const targetPrefix = "@anthropic-ai/claude-agent-sdk";
61593
+ if (process.platform === "darwin") {
61594
+ if (process.arch === "arm64" || process.arch === "x64") {
61595
+ return [{ packageName: `${targetPrefix}-darwin-${process.arch}`, binaryName }];
61596
+ }
61597
+ return [];
61598
+ }
61599
+ if (process.platform === "win32") {
61600
+ if (process.arch === "arm64" || process.arch === "x64") {
61601
+ return [{ packageName: `${targetPrefix}-win32-${process.arch}`, binaryName }];
61602
+ }
61603
+ return [];
61604
+ }
61605
+ if (process.platform === "linux") {
61606
+ if (process.arch === "arm64" || process.arch === "x64") {
61607
+ return [
61608
+ { packageName: `${targetPrefix}-linux-${process.arch}`, binaryName },
61609
+ { packageName: `${targetPrefix}-linux-${process.arch}-musl`, binaryName }
61610
+ ];
61611
+ }
61612
+ }
61613
+ return [];
61614
+ }
61615
+ function safeResolve(specifier, paths) {
61616
+ try {
61617
+ return require2.resolve(specifier, paths ? { paths } : void 0);
61618
+ } catch {
61619
+ return void 0;
61620
+ }
61621
+ }
61622
+ function resolveClaudeAgentSdkDir() {
61623
+ const sdkEntry = safeResolve("@anthropic-ai/claude-agent-sdk");
61624
+ if (!sdkEntry) return void 0;
61625
+ try {
61626
+ return import_node_path5.default.dirname((0, import_node_fs3.realpathSync)(sdkEntry));
61627
+ } catch {
61628
+ return import_node_path5.default.dirname(sdkEntry);
61629
+ }
61630
+ }
61631
+ function findPnpmStoreDir(fromDir) {
61632
+ let current = fromDir;
61633
+ while (current !== import_node_path5.default.dirname(current)) {
61634
+ if (import_node_path5.default.basename(current) === ".pnpm") return current;
61635
+ current = import_node_path5.default.dirname(current);
61636
+ }
61637
+ return void 0;
61638
+ }
61639
+ function resolvePnpmRuntimeBinary(sdkDir, target) {
61640
+ const pnpmStoreDir = findPnpmStoreDir(sdkDir);
61641
+ if (!pnpmStoreDir) return void 0;
61642
+ const encodedName = target.packageName.replace("/", "+");
61643
+ let entries;
61644
+ try {
61645
+ entries = (0, import_node_fs3.readdirSync)(pnpmStoreDir);
61646
+ } catch {
61647
+ return void 0;
61648
+ }
61649
+ for (const entry of entries) {
61650
+ if (!entry.startsWith(`${encodedName}@`)) continue;
61651
+ const candidate = import_node_path5.default.join(
61652
+ pnpmStoreDir,
61653
+ entry,
61654
+ "node_modules",
61655
+ ...target.packageName.split("/"),
61656
+ target.binaryName
61657
+ );
61658
+ if ((0, import_node_fs3.existsSync)(candidate)) return candidate;
61659
+ }
61660
+ return void 0;
61661
+ }
61662
+ function resolveSdkRuntimeBinary(target) {
61663
+ const directPath = safeResolve(`${target.packageName}/${target.binaryName}`);
61664
+ if (directPath && (0, import_node_fs3.existsSync)(directPath)) return directPath;
61665
+ const sdkDir = resolveClaudeAgentSdkDir();
61666
+ if (!sdkDir) return void 0;
61667
+ const scopedPackageName = target.packageName.split("/")[1] ?? target.packageName;
61668
+ const candidates = [
61669
+ safeResolve(`${target.packageName}/${target.binaryName}`, [sdkDir]),
61670
+ import_node_path5.default.join(sdkDir, "..", scopedPackageName, target.binaryName),
61671
+ import_node_path5.default.join(sdkDir, "node_modules", ...target.packageName.split("/"), target.binaryName),
61672
+ resolvePnpmRuntimeBinary(sdkDir, target)
61673
+ ].filter((candidate) => Boolean(candidate));
61674
+ return candidates.find((candidate) => (0, import_node_fs3.existsSync)(candidate));
61675
+ }
61676
+ function resolveSdkBundledAttempts() {
61677
+ const targets = getSdkRuntimeTargets();
61678
+ if (targets.length === 0) {
61679
+ return [{
61680
+ source: "sdk-bundled",
61681
+ ok: false,
61682
+ error: `unsupported platform for Claude Agent SDK runtime: ${process.platform}-${process.arch}`
61683
+ }];
61684
+ }
61685
+ const attempts = [];
61686
+ for (const target of targets) {
61687
+ const binaryPath = resolveSdkRuntimeBinary(target);
61688
+ if (!binaryPath) {
61689
+ attempts.push({
61690
+ source: "sdk-bundled",
61691
+ ok: false,
61692
+ error: `optional runtime package ${target.packageName} is not installed`
61693
+ });
61694
+ continue;
61695
+ }
61696
+ const attempt = validateCandidate("sdk-bundled", binaryPath);
61697
+ attempts.push(attempt);
61698
+ if (attempt.ok) break;
61699
+ }
61700
+ return attempts;
61701
+ }
61588
61702
  function resolvePathCandidate() {
61589
61703
  const resolved = resolveCommand(["claude", "anthropic-cli"]);
61590
61704
  if (!resolved) return void 0;
@@ -61592,12 +61706,13 @@ function resolvePathCandidate() {
61592
61706
  }
61593
61707
  function buildMissingError(attempts) {
61594
61708
  if (attempts.length === 0) {
61595
- return "Claude runtime not found. Install Claude Code manually or use the bundled desktop runtime.";
61709
+ return "Claude runtime not found. Reinstall @fangyb/ahchat-bridge with npm optional dependencies, install Claude Code manually, or use the bundled desktop runtime.";
61596
61710
  }
61597
- return attempts.map((attempt) => {
61711
+ const attemptDetails = attempts.map((attempt) => {
61598
61712
  const pathSuffix = attempt.path ? ` at ${attempt.path}` : "";
61599
61713
  return `${attempt.source}${pathSuffix}: ${attempt.error ?? "unavailable"}`;
61600
61714
  }).join("; ");
61715
+ return `Claude runtime not found. ${attemptDetails}. Reinstall @fangyb/ahchat-bridge with npm optional dependencies, set AHCHAT_CLAUDE_EXECUTABLE, install Claude Code manually, or use the bundled desktop runtime.`;
61601
61716
  }
61602
61717
  function resolveClaudeRuntime(env2 = process.env) {
61603
61718
  const attempts = [];
@@ -61635,6 +61750,19 @@ function resolveClaudeRuntime(env2 = process.env) {
61635
61750
  };
61636
61751
  }
61637
61752
  }
61753
+ const sdkAttempts = resolveSdkBundledAttempts();
61754
+ for (const attempt of sdkAttempts) {
61755
+ attempts.push(attempt);
61756
+ if (attempt.ok) {
61757
+ return {
61758
+ ok: true,
61759
+ source: "sdk-bundled",
61760
+ path: attempt.path,
61761
+ version: attempt.version,
61762
+ attempts
61763
+ };
61764
+ }
61765
+ }
61638
61766
  const pathAttempt = resolvePathCandidate();
61639
61767
  if (pathAttempt) {
61640
61768
  attempts.push(pathAttempt);
@@ -86548,7 +86676,7 @@ Claude runtime is unavailable.
86548
86676
 
86549
86677
  ${claudeRuntime.error ?? "Install Claude Code manually or use the bundled desktop runtime."}
86550
86678
 
86551
- Set AHCHAT_CLAUDE_EXECUTABLE to a valid Claude Code binary path, install Claude Code, or use AHChat Desktop with its bundled runtime.
86679
+ Reinstall @fangyb/ahchat-bridge with npm optional dependencies, set AHCHAT_CLAUDE_EXECUTABLE to a valid Claude Code binary path, install Claude Code, or use AHChat Desktop with its bundled runtime.
86552
86680
  `
86553
86681
  );
86554
86682
  process.exit(1);
@@ -87412,7 +87540,7 @@ Install Node.js ${MIN_NODE_MAJOR}+ first, then rerun the bridge command.`);
87412
87540
  lines.push("\nNode is installed, but npm/npx is not available on PATH. Reinstall Node.js or fix PATH.");
87413
87541
  } else if (!claudeRuntime.ok) {
87414
87542
  lines.push(
87415
- "\nClaude runtime is missing. Install Claude Code manually, set AHCHAT_CLAUDE_EXECUTABLE, or use AHChat Desktop with its bundled runtime."
87543
+ "\nClaude runtime is missing. Reinstall @fangyb/ahchat-bridge with npm optional dependencies, set AHCHAT_CLAUDE_EXECUTABLE, install Claude Code manually, or use AHChat Desktop with its bundled runtime."
87416
87544
  );
87417
87545
  }
87418
87546
  process.stdout.write(`${lines.join("\n")}
@@ -87434,7 +87562,7 @@ cli.command("run", "Start the bridge and connect to server").option("--server-ur
87434
87562
  process.exit(1);
87435
87563
  });
87436
87564
  });
87437
- cli.command("doctor", "Check Node, npm, Claude CLI, PATH, and bridge launch options").option("--server-url <url>", "WebSocket URL of the AHChat server").option("--token <token>", "Auth token for server registration").option("--user <slug>", "User data-dir slug; derives ~/.ahchat/users/<slug>").option("--data-dir <dir>", "Data directory (default: ~/.ahchat)").option("--json", "Print machine-readable JSON").action((args) => {
87565
+ cli.command("doctor", "Check Node, npm, Claude runtime, PATH, and bridge launch options").option("--server-url <url>", "WebSocket URL of the AHChat server").option("--token <token>", "Auth token for server registration").option("--user <slug>", "User data-dir slug; derives ~/.ahchat/users/<slug>").option("--data-dir <dir>", "Data directory (default: ~/.ahchat)").option("--json", "Print machine-readable JSON").action((args) => {
87438
87566
  doctor(args);
87439
87567
  });
87440
87568
  cli.command("launch", "Launch bridge from ahchat:// URL (called by OS)").option("--url <url>", "ahchat:// URL with server and token params").action((args) => {
package/dist/index.js CHANGED
@@ -29480,9 +29480,11 @@ var SessionStore = class {
29480
29480
  };
29481
29481
 
29482
29482
  // src/claudeRuntime.ts
29483
- import { accessSync as accessSync2, constants as constants3, existsSync as existsSync2 } from "fs";
29483
+ import { accessSync as accessSync2, constants as constants3, existsSync as existsSync2, readdirSync as readdirSync2, realpathSync } from "fs";
29484
+ import { createRequire } from "module";
29484
29485
  import path18 from "path";
29485
29486
  var logger25 = createModuleLogger("bridge.claudeRuntime");
29487
+ var require2 = createRequire(import.meta.url);
29486
29488
  var EXPLICIT_CLAUDE_EXECUTABLE_ENV = "AHCHAT_CLAUDE_EXECUTABLE";
29487
29489
  var BUNDLED_CLAUDE_PATH_ENV = "AHCHAT_BUNDLED_CLAUDE_PATH";
29488
29490
  function normalizePath(value) {
@@ -29532,6 +29534,118 @@ function validateCandidate(source, candidatePath) {
29532
29534
  version: version2
29533
29535
  };
29534
29536
  }
29537
+ function getSdkRuntimeTargets() {
29538
+ const binaryName = process.platform === "win32" ? "claude.exe" : "claude";
29539
+ const targetPrefix = "@anthropic-ai/claude-agent-sdk";
29540
+ if (process.platform === "darwin") {
29541
+ if (process.arch === "arm64" || process.arch === "x64") {
29542
+ return [{ packageName: `${targetPrefix}-darwin-${process.arch}`, binaryName }];
29543
+ }
29544
+ return [];
29545
+ }
29546
+ if (process.platform === "win32") {
29547
+ if (process.arch === "arm64" || process.arch === "x64") {
29548
+ return [{ packageName: `${targetPrefix}-win32-${process.arch}`, binaryName }];
29549
+ }
29550
+ return [];
29551
+ }
29552
+ if (process.platform === "linux") {
29553
+ if (process.arch === "arm64" || process.arch === "x64") {
29554
+ return [
29555
+ { packageName: `${targetPrefix}-linux-${process.arch}`, binaryName },
29556
+ { packageName: `${targetPrefix}-linux-${process.arch}-musl`, binaryName }
29557
+ ];
29558
+ }
29559
+ }
29560
+ return [];
29561
+ }
29562
+ function safeResolve(specifier, paths) {
29563
+ try {
29564
+ return require2.resolve(specifier, paths ? { paths } : void 0);
29565
+ } catch {
29566
+ return void 0;
29567
+ }
29568
+ }
29569
+ function resolveClaudeAgentSdkDir() {
29570
+ const sdkEntry = safeResolve("@anthropic-ai/claude-agent-sdk");
29571
+ if (!sdkEntry) return void 0;
29572
+ try {
29573
+ return path18.dirname(realpathSync(sdkEntry));
29574
+ } catch {
29575
+ return path18.dirname(sdkEntry);
29576
+ }
29577
+ }
29578
+ function findPnpmStoreDir(fromDir) {
29579
+ let current = fromDir;
29580
+ while (current !== path18.dirname(current)) {
29581
+ if (path18.basename(current) === ".pnpm") return current;
29582
+ current = path18.dirname(current);
29583
+ }
29584
+ return void 0;
29585
+ }
29586
+ function resolvePnpmRuntimeBinary(sdkDir, target) {
29587
+ const pnpmStoreDir = findPnpmStoreDir(sdkDir);
29588
+ if (!pnpmStoreDir) return void 0;
29589
+ const encodedName = target.packageName.replace("/", "+");
29590
+ let entries;
29591
+ try {
29592
+ entries = readdirSync2(pnpmStoreDir);
29593
+ } catch {
29594
+ return void 0;
29595
+ }
29596
+ for (const entry of entries) {
29597
+ if (!entry.startsWith(`${encodedName}@`)) continue;
29598
+ const candidate = path18.join(
29599
+ pnpmStoreDir,
29600
+ entry,
29601
+ "node_modules",
29602
+ ...target.packageName.split("/"),
29603
+ target.binaryName
29604
+ );
29605
+ if (existsSync2(candidate)) return candidate;
29606
+ }
29607
+ return void 0;
29608
+ }
29609
+ function resolveSdkRuntimeBinary(target) {
29610
+ const directPath = safeResolve(`${target.packageName}/${target.binaryName}`);
29611
+ if (directPath && existsSync2(directPath)) return directPath;
29612
+ const sdkDir = resolveClaudeAgentSdkDir();
29613
+ if (!sdkDir) return void 0;
29614
+ const scopedPackageName = target.packageName.split("/")[1] ?? target.packageName;
29615
+ const candidates = [
29616
+ safeResolve(`${target.packageName}/${target.binaryName}`, [sdkDir]),
29617
+ path18.join(sdkDir, "..", scopedPackageName, target.binaryName),
29618
+ path18.join(sdkDir, "node_modules", ...target.packageName.split("/"), target.binaryName),
29619
+ resolvePnpmRuntimeBinary(sdkDir, target)
29620
+ ].filter((candidate) => Boolean(candidate));
29621
+ return candidates.find((candidate) => existsSync2(candidate));
29622
+ }
29623
+ function resolveSdkBundledAttempts() {
29624
+ const targets = getSdkRuntimeTargets();
29625
+ if (targets.length === 0) {
29626
+ return [{
29627
+ source: "sdk-bundled",
29628
+ ok: false,
29629
+ error: `unsupported platform for Claude Agent SDK runtime: ${process.platform}-${process.arch}`
29630
+ }];
29631
+ }
29632
+ const attempts = [];
29633
+ for (const target of targets) {
29634
+ const binaryPath = resolveSdkRuntimeBinary(target);
29635
+ if (!binaryPath) {
29636
+ attempts.push({
29637
+ source: "sdk-bundled",
29638
+ ok: false,
29639
+ error: `optional runtime package ${target.packageName} is not installed`
29640
+ });
29641
+ continue;
29642
+ }
29643
+ const attempt = validateCandidate("sdk-bundled", binaryPath);
29644
+ attempts.push(attempt);
29645
+ if (attempt.ok) break;
29646
+ }
29647
+ return attempts;
29648
+ }
29535
29649
  function resolvePathCandidate() {
29536
29650
  const resolved = resolveCommand(["claude", "anthropic-cli"]);
29537
29651
  if (!resolved) return void 0;
@@ -29539,12 +29653,13 @@ function resolvePathCandidate() {
29539
29653
  }
29540
29654
  function buildMissingError(attempts) {
29541
29655
  if (attempts.length === 0) {
29542
- return "Claude runtime not found. Install Claude Code manually or use the bundled desktop runtime.";
29656
+ return "Claude runtime not found. Reinstall @fangyb/ahchat-bridge with npm optional dependencies, install Claude Code manually, or use the bundled desktop runtime.";
29543
29657
  }
29544
- return attempts.map((attempt) => {
29658
+ const attemptDetails = attempts.map((attempt) => {
29545
29659
  const pathSuffix = attempt.path ? ` at ${attempt.path}` : "";
29546
29660
  return `${attempt.source}${pathSuffix}: ${attempt.error ?? "unavailable"}`;
29547
29661
  }).join("; ");
29662
+ return `Claude runtime not found. ${attemptDetails}. Reinstall @fangyb/ahchat-bridge with npm optional dependencies, set AHCHAT_CLAUDE_EXECUTABLE, install Claude Code manually, or use the bundled desktop runtime.`;
29548
29663
  }
29549
29664
  function resolveClaudeRuntime(env2 = process.env) {
29550
29665
  const attempts = [];
@@ -29582,6 +29697,19 @@ function resolveClaudeRuntime(env2 = process.env) {
29582
29697
  };
29583
29698
  }
29584
29699
  }
29700
+ const sdkAttempts = resolveSdkBundledAttempts();
29701
+ for (const attempt of sdkAttempts) {
29702
+ attempts.push(attempt);
29703
+ if (attempt.ok) {
29704
+ return {
29705
+ ok: true,
29706
+ source: "sdk-bundled",
29707
+ path: attempt.path,
29708
+ version: attempt.version,
29709
+ attempts
29710
+ };
29711
+ }
29712
+ }
29585
29713
  const pathAttempt = resolvePathCandidate();
29586
29714
  if (pathAttempt) {
29587
29715
  attempts.push(pathAttempt);
@@ -30014,7 +30142,7 @@ Claude runtime is unavailable.
30014
30142
 
30015
30143
  ${claudeRuntime.error ?? "Install Claude Code manually or use the bundled desktop runtime."}
30016
30144
 
30017
- Set AHCHAT_CLAUDE_EXECUTABLE to a valid Claude Code binary path, install Claude Code, or use AHChat Desktop with its bundled runtime.
30145
+ Reinstall @fangyb/ahchat-bridge with npm optional dependencies, set AHCHAT_CLAUDE_EXECUTABLE to a valid Claude Code binary path, install Claude Code, or use AHChat Desktop with its bundled runtime.
30018
30146
  `
30019
30147
  );
30020
30148
  process.exit(1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fangyb/ahchat-bridge",
3
- "version": "0.1.24",
3
+ "version": "0.1.25",
4
4
  "files": [
5
5
  "dist"
6
6
  ],