yymaxapi 1.0.49 → 1.0.50
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/bin/yymaxapi.js +24 -39
- package/package.json +1 -1
package/bin/yymaxapi.js
CHANGED
|
@@ -138,6 +138,10 @@ const DEFAULT_API_CONFIG = {
|
|
|
138
138
|
}
|
|
139
139
|
};
|
|
140
140
|
|
|
141
|
+
const SKIP_API_VALIDATION = false;
|
|
142
|
+
|
|
143
|
+
const SKIP_API_VALIDATION = false;
|
|
144
|
+
|
|
141
145
|
function normalizeEndpoints(raw, fallback) {
|
|
142
146
|
if (!Array.isArray(raw)) return fallback;
|
|
143
147
|
const normalized = raw
|
|
@@ -371,6 +375,9 @@ function httpGetJson(url, headers = {}, timeout = 10000) {
|
|
|
371
375
|
}
|
|
372
376
|
|
|
373
377
|
async function validateApiKey(nodeUrl, apiKey) {
|
|
378
|
+
if (SKIP_API_VALIDATION) {
|
|
379
|
+
return { valid: true, skipped: true };
|
|
380
|
+
}
|
|
374
381
|
const verifyUrl = `${nodeUrl.replace(/\/+$/, '')}/user/api/v1/me`;
|
|
375
382
|
const maxRetries = 3;
|
|
376
383
|
const spinner = ora({ text: '正在验证 API Key...', spinner: 'dots' }).start();
|
|
@@ -2782,7 +2789,7 @@ async function autoActivate(paths, args = {}) {
|
|
|
2782
2789
|
const gwToken = config.gateway?.auth?.token;
|
|
2783
2790
|
if (gwToken) {
|
|
2784
2791
|
console.log(chalk.green(`\n🌐 Web Dashboard:`));
|
|
2785
|
-
console.log(chalk.cyan(` http://
|
|
2792
|
+
console.log(chalk.cyan(` http://127.0.0.1:${gwPort}/?token=${gwToken}`));
|
|
2786
2793
|
}
|
|
2787
2794
|
|
|
2788
2795
|
// ---- 测试连接 ----
|
|
@@ -3567,7 +3574,7 @@ async function switchModel(paths) {
|
|
|
3567
3574
|
|
|
3568
3575
|
if (gwToken) {
|
|
3569
3576
|
console.log(chalk.green(`\n🌐 Web Dashboard:`));
|
|
3570
|
-
console.log(chalk.cyan(` http://
|
|
3577
|
+
console.log(chalk.cyan(` http://127.0.0.1:${gwPort}/?token=${gwToken}`));
|
|
3571
3578
|
}
|
|
3572
3579
|
}
|
|
3573
3580
|
// ============ 权限管理 (tools.profile) ============
|
|
@@ -3695,7 +3702,7 @@ async function testConnection(paths, args = {}) {
|
|
|
3695
3702
|
console.log(chalk.gray(`当前激活: ${typeLabel}`));
|
|
3696
3703
|
console.log(chalk.gray(`中转节点: ${provider.baseUrl}`));
|
|
3697
3704
|
console.log(chalk.gray(`模型: ${primary}`));
|
|
3698
|
-
console.log(chalk.gray(`Gateway: http://
|
|
3705
|
+
console.log(chalk.gray(`Gateway: http://127.0.0.1:${gatewayPort}\n`));
|
|
3699
3706
|
// 获取 Gateway token
|
|
3700
3707
|
const gatewayToken = config.gateway?.auth?.token;
|
|
3701
3708
|
if (!gatewayToken) {
|
|
@@ -3819,7 +3826,7 @@ async function testConnection(paths, args = {}) {
|
|
|
3819
3826
|
}
|
|
3820
3827
|
}
|
|
3821
3828
|
|
|
3822
|
-
console.log(chalk.gray(` 端点: http://
|
|
3829
|
+
console.log(chalk.gray(` 端点: http://127.0.0.1:${gatewayPort}/v1/responses`));
|
|
3823
3830
|
const startTime = Date.now();
|
|
3824
3831
|
let result = await testGatewayApi(gatewayPort, gatewayToken, primary);
|
|
3825
3832
|
const latency = Date.now() - startTime;
|
|
@@ -4017,15 +4024,11 @@ async function restartGatewayNative(silent = false) {
|
|
|
4017
4024
|
const gwConfig = readConfig(configPaths.openclawConfig);
|
|
4018
4025
|
const gatewayPort = gwConfig?.gateway?.port || 18789;
|
|
4019
4026
|
|
|
4020
|
-
// 策略 A
|
|
4021
|
-
// 注意:该命令通常会启动前台 daemon 不退出,超时是正常的
|
|
4027
|
+
// 策略 A:尝试 exec "gateway restart"(短超时),然后端口探测
|
|
4022
4028
|
const restartCmds = buildGatewayCommands(resolved, nodeInfo, useNode, 'restart');
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
execAttempted = true;
|
|
4027
|
-
const result = safeExec(cmd, { timeout: 8000, env });
|
|
4028
|
-
// 不管是否 "成功"(通常会超时),检查端口是否可达
|
|
4029
|
+
if (restartCmds.length > 0) {
|
|
4030
|
+
// 只尝试第一条(最精确的路径),避免逐条超时累积
|
|
4031
|
+
safeExec(restartCmds[0], { timeout: 8000, env });
|
|
4029
4032
|
if (await waitForGateway(gatewayPort, '127.0.0.1', 5000)) {
|
|
4030
4033
|
if (!silent) console.log(chalk.green(`✅ Gateway 已重启`));
|
|
4031
4034
|
return true;
|
|
@@ -4035,29 +4038,34 @@ async function restartGatewayNative(silent = false) {
|
|
|
4035
4038
|
// 策略 B:杀旧进程 → spawn 后台启动新 Gateway → 端口探测
|
|
4036
4039
|
if (!silent) console.log(chalk.gray(' 常规重启未生效,尝试杀进程后重新启动...'));
|
|
4037
4040
|
await killGatewayProcesses(gatewayPort);
|
|
4038
|
-
await new Promise(resolve => setTimeout(resolve,
|
|
4041
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
4039
4042
|
|
|
4040
4043
|
const startCmds = buildGatewayCommands(resolved, nodeInfo, useNode, 'start');
|
|
4041
4044
|
for (const cmd of startCmds) {
|
|
4042
4045
|
if (spawnDetached(cmd, env)) {
|
|
4043
|
-
if (await waitForGateway(gatewayPort, '127.0.0.1',
|
|
4046
|
+
if (await waitForGateway(gatewayPort, '127.0.0.1', 10000)) {
|
|
4044
4047
|
if (!silent) console.log(chalk.green('✅ Gateway 已重启'));
|
|
4045
4048
|
return true;
|
|
4046
4049
|
}
|
|
4050
|
+
break; // spawn 成功但端口未通,不再逐条重试
|
|
4047
4051
|
}
|
|
4048
4052
|
}
|
|
4049
4053
|
|
|
4050
4054
|
// 策略 C:用 login shell 启动(加载 nvm/fnm 等 PATH)
|
|
4051
4055
|
if (process.platform !== 'win32') {
|
|
4052
4056
|
if (!silent) console.log(chalk.gray(' 尝试通过 login shell 启动...'));
|
|
4057
|
+
let launched = false;
|
|
4053
4058
|
for (const name of ['openclaw', 'clawdbot', 'moltbot']) {
|
|
4059
|
+
if (launched) break;
|
|
4054
4060
|
for (const sh of ['/bin/zsh', '/bin/bash']) {
|
|
4055
4061
|
if (!fs.existsSync(sh)) continue;
|
|
4056
4062
|
if (spawnDetached(`${sh} -lc '${name} gateway'`, env)) {
|
|
4057
|
-
|
|
4063
|
+
launched = true;
|
|
4064
|
+
if (await waitForGateway(gatewayPort, '127.0.0.1', 10000)) {
|
|
4058
4065
|
if (!silent) console.log(chalk.green('✅ Gateway 已重启 (login shell)'));
|
|
4059
4066
|
return true;
|
|
4060
4067
|
}
|
|
4068
|
+
break;
|
|
4061
4069
|
}
|
|
4062
4070
|
}
|
|
4063
4071
|
}
|
|
@@ -4087,30 +4095,7 @@ function buildGatewayCommands(resolved, nodeInfo, useNode, action) {
|
|
|
4087
4095
|
}
|
|
4088
4096
|
|
|
4089
4097
|
const names = ['openclaw', 'clawdbot', 'moltbot'];
|
|
4090
|
-
|
|
4091
|
-
for (const name of names) commands.push(`${name} ${verb}`);
|
|
4092
|
-
if (isWslAvailable()) {
|
|
4093
|
-
const wslCli = getWslCliBinary();
|
|
4094
|
-
if (wslCli) commands.push(`wsl -- bash -lc "${wslCli} ${verb}"`);
|
|
4095
|
-
for (const name of names) commands.push(`wsl -- bash -lc "${name} ${verb}"`);
|
|
4096
|
-
}
|
|
4097
|
-
} else {
|
|
4098
|
-
for (const name of names) commands.push(`${name} ${verb}`);
|
|
4099
|
-
}
|
|
4100
|
-
|
|
4101
|
-
if (isDockerAvailable()) {
|
|
4102
|
-
const containers = findOpenclawDockerContainers();
|
|
4103
|
-
for (const c of containers) {
|
|
4104
|
-
if (c.cli === 'node') {
|
|
4105
|
-
commands.push(dockerCmd(`exec ${c.id} bash -lc "node ${c.cliPath} ${verb}"`));
|
|
4106
|
-
} else if (c.cli !== 'unknown') {
|
|
4107
|
-
commands.push(dockerCmd(`exec ${c.id} bash -lc "${c.cli} ${verb}"`));
|
|
4108
|
-
}
|
|
4109
|
-
for (const name of names) {
|
|
4110
|
-
commands.push(dockerCmd(`exec ${c.id} bash -lc "${name} ${verb}"`));
|
|
4111
|
-
}
|
|
4112
|
-
}
|
|
4113
|
-
}
|
|
4098
|
+
for (const name of names) commands.push(`${name} ${verb}`);
|
|
4114
4099
|
|
|
4115
4100
|
return [...new Set(commands)].filter(Boolean);
|
|
4116
4101
|
}
|