yymaxapi 1.0.14 → 1.0.16

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 (2) hide show
  1. package/bin/yymaxapi.js +44 -7
  2. package/package.json +1 -1
package/bin/yymaxapi.js CHANGED
@@ -587,6 +587,24 @@ function getWslHome() {
587
587
  return _wslHomeCache;
588
588
  }
589
589
 
590
+ // 获取 WSL 内 openclaw CLI 的完整路径(缓存)
591
+ let _wslCliBinaryCache = undefined;
592
+
593
+ function getWslCliBinary() {
594
+ if (_wslCliBinaryCache !== undefined) return _wslCliBinaryCache;
595
+ for (const name of ['openclaw', 'clawdbot', 'moltbot']) {
596
+ try {
597
+ const result = execFileSync('wsl', ['bash', '-c', `which ${name} 2>/dev/null`], { encoding: 'utf8', timeout: 5000 }).trim();
598
+ if (result && result.startsWith('/')) {
599
+ _wslCliBinaryCache = result;
600
+ return _wslCliBinaryCache;
601
+ }
602
+ } catch {}
603
+ }
604
+ _wslCliBinaryCache = null;
605
+ return null;
606
+ }
607
+
590
608
  function detectGatewayEnv(port = 18789) {
591
609
  if (_gwEnvCache !== null) return _gwEnvCache;
592
610
  if (process.platform !== 'win32' || !isWslAvailable()) {
@@ -980,8 +998,16 @@ function resolveCliBinary() {
980
998
  // Validate that a found binary is a real gateway CLI, not yymaxapi itself
981
999
  function isRealCli(filePath) {
982
1000
  try {
1001
+ // Windows 上跳过 Linux 路径(WSL 路径在 Windows cmd.exe 下无法执行)
1002
+ if (process.platform === 'win32' && filePath.startsWith('/')) {
1003
+ return false;
1004
+ }
983
1005
  // Resolve symlinks to get the real target
984
1006
  const realPath = fs.realpathSync(filePath);
1007
+ // Windows 上再次检查解析后的路径
1008
+ if (process.platform === 'win32' && realPath.startsWith('/')) {
1009
+ return false;
1010
+ }
985
1011
  const baseName = path.basename(realPath).toLowerCase();
986
1012
  // Skip if it points to yymaxapi/openclawapi (our own config tool, not the gateway CLI)
987
1013
  if (baseName === 'yymaxapi' || baseName === 'yymaxapi.js' || realPath.includes('yymaxapi') || baseName === 'openclawapi' || baseName === 'openclawapi.js' || realPath.includes('openclawapi')) {
@@ -1139,6 +1165,8 @@ function findCompatibleNode(minMajor = 22) {
1139
1165
  const seen = new Set();
1140
1166
  for (const candidate of candidates) {
1141
1167
  if (!candidate || seen.has(candidate)) continue;
1168
+ // Windows 上跳过 Linux 路径(WSL 路径无法直接执行)
1169
+ if (process.platform === 'win32' && candidate.startsWith('/')) continue;
1142
1170
  seen.add(candidate);
1143
1171
  try {
1144
1172
  if (!fs.existsSync(candidate)) continue;
@@ -2479,12 +2507,15 @@ async function restartGateway() {
2479
2507
  // 如果 Gateway 在 WSL 里,优先用 wsl -- 重启
2480
2508
  if (gwEnv === 'wsl') {
2481
2509
  console.log(chalk.gray(' [检测] Gateway 运行在 WSL 中'));
2510
+ const wslCli = getWslCliBinary();
2482
2511
  return new Promise((resolve) => {
2483
- const wslCmds = [
2484
- 'wsl -- bash -lc "openclaw gateway restart"',
2485
- 'wsl -- bash -lc "clawdbot gateway restart"',
2486
- 'wsl -- bash -lc "moltbot gateway restart"',
2487
- ];
2512
+ const wslCmds = wslCli
2513
+ ? [`wsl -- bash -c "${wslCli} gateway restart"`]
2514
+ : [
2515
+ 'wsl -- bash -lc "openclaw gateway restart"',
2516
+ 'wsl -- bash -lc "clawdbot gateway restart"',
2517
+ 'wsl -- bash -lc "moltbot gateway restart"',
2518
+ ];
2488
2519
  let tried = 0;
2489
2520
  const tryNext = () => {
2490
2521
  if (tried >= wslCmds.length) {
@@ -2660,8 +2691,14 @@ function testGatewayViaAgent(model) {
2660
2691
 
2661
2692
  if (gwEnv === 'wsl') {
2662
2693
  // Gateway 在 WSL 中,agent 也要在 WSL 中执行
2663
- const agentCmd = `openclaw agent --session-id ${sessionId} --message "请回复你的模型名称" --json --timeout 120 2>/dev/null || clawdbot agent --session-id ${sessionId} --message "请回复你的模型名称" --json --timeout 120 2>/dev/null || moltbot agent --session-id ${sessionId} --message "请回复你的模型名称" --json --timeout 120`;
2664
- cmd = `wsl -- bash -lc '${agentCmd.replace(/'/g, "'\\''")}'`;
2694
+ const wslCli = getWslCliBinary();
2695
+ if (wslCli) {
2696
+ const agentCmd = `${wslCli} agent --session-id ${sessionId} --message "请回复你的模型名称" --json --timeout 120`;
2697
+ cmd = `wsl -- bash -c '${agentCmd.replace(/'/g, "'\\''")}'`;
2698
+ } else {
2699
+ const agentCmd = `openclaw agent --session-id ${sessionId} --message "请回复你的模型名称" --json --timeout 120 2>/dev/null || clawdbot agent --session-id ${sessionId} --message "请回复你的模型名称" --json --timeout 120 2>/dev/null || moltbot agent --session-id ${sessionId} --message "请回复你的模型名称" --json --timeout 120`;
2700
+ cmd = `wsl -- bash -lc '${agentCmd.replace(/'/g, "'\\''")}'`;
2701
+ }
2665
2702
  execOpts = { timeout: 120000 };
2666
2703
  } else {
2667
2704
  const { cliBinary, nodeMajor } = getCliMeta();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yymaxapi",
3
- "version": "1.0.14",
3
+ "version": "1.0.16",
4
4
  "description": "跨平台 OpenClaw/Clawdbot 配置管理工具 - 管理中转地址、模型切换、API Keys、测速优化",
5
5
  "main": "bin/yymaxapi.js",
6
6
  "bin": {