yymaxapi 1.0.15 → 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 +34 -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()) {
@@ -2489,12 +2507,15 @@ async function restartGateway() {
2489
2507
  // 如果 Gateway 在 WSL 里,优先用 wsl -- 重启
2490
2508
  if (gwEnv === 'wsl') {
2491
2509
  console.log(chalk.gray(' [检测] Gateway 运行在 WSL 中'));
2510
+ const wslCli = getWslCliBinary();
2492
2511
  return new Promise((resolve) => {
2493
- const wslCmds = [
2494
- 'wsl -- bash -lc "openclaw gateway restart"',
2495
- 'wsl -- bash -lc "clawdbot gateway restart"',
2496
- 'wsl -- bash -lc "moltbot gateway restart"',
2497
- ];
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
+ ];
2498
2519
  let tried = 0;
2499
2520
  const tryNext = () => {
2500
2521
  if (tried >= wslCmds.length) {
@@ -2670,8 +2691,14 @@ function testGatewayViaAgent(model) {
2670
2691
 
2671
2692
  if (gwEnv === 'wsl') {
2672
2693
  // Gateway 在 WSL 中,agent 也要在 WSL 中执行
2673
- 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`;
2674
- 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
+ }
2675
2702
  execOpts = { timeout: 120000 };
2676
2703
  } else {
2677
2704
  const { cliBinary, nodeMajor } = getCliMeta();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yymaxapi",
3
- "version": "1.0.15",
3
+ "version": "1.0.16",
4
4
  "description": "跨平台 OpenClaw/Clawdbot 配置管理工具 - 管理中转地址、模型切换、API Keys、测速优化",
5
5
  "main": "bin/yymaxapi.js",
6
6
  "bin": {