openclawsetup 2.4.7 → 2.4.9
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/cli.mjs +80 -5
- package/package.json +1 -1
package/bin/cli.mjs
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* npx openclawsetup --update # 更新已安装的 OpenClaw
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import { execSync, spawnSync } from 'child_process';
|
|
13
|
+
import { exec, execSync, spawnSync } from 'child_process';
|
|
14
14
|
import { existsSync, accessSync, constants as fsConstants, rmSync, readFileSync } from 'fs';
|
|
15
15
|
import { homedir, platform } from 'os';
|
|
16
16
|
import { join } from 'path';
|
|
@@ -1236,6 +1236,48 @@ async function runHealthCheck(cliName, autoFix = false) {
|
|
|
1236
1236
|
|
|
1237
1237
|
// ============ 交互式菜单 ============
|
|
1238
1238
|
|
|
1239
|
+
function testModelChat(cliName) {
|
|
1240
|
+
return new Promise((resolve) => {
|
|
1241
|
+
const cmd = `${cliName} agent --session-id openclawsetup-test --message "请用一句话回复你的模型名称" --json --timeout 60`;
|
|
1242
|
+
exec(cmd, { timeout: 65000 }, (error, stdout, stderr) => {
|
|
1243
|
+
if (error) {
|
|
1244
|
+
const errMsg = (stderr || stdout || error.message || '').trim();
|
|
1245
|
+
// 提取关键错误信息
|
|
1246
|
+
if (errMsg.includes('401')) {
|
|
1247
|
+
resolve({ success: false, error: 'API Key 无效 (401)' });
|
|
1248
|
+
} else if (errMsg.includes('403')) {
|
|
1249
|
+
resolve({ success: false, error: 'API 访问被拒绝 (403)' });
|
|
1250
|
+
} else if (errMsg.includes('timeout') || errMsg.includes('ETIMEDOUT')) {
|
|
1251
|
+
resolve({ success: false, error: '请求超时,节点可能不可达' });
|
|
1252
|
+
} else {
|
|
1253
|
+
resolve({ success: false, error: errMsg.substring(0, 200) || 'CLI 执行失败' });
|
|
1254
|
+
}
|
|
1255
|
+
return;
|
|
1256
|
+
}
|
|
1257
|
+
const output = (stdout || '').trim();
|
|
1258
|
+
const jsonStart = output.indexOf('{');
|
|
1259
|
+
const jsonEnd = output.lastIndexOf('}');
|
|
1260
|
+
if (jsonStart === -1 || jsonEnd === -1 || jsonEnd <= jsonStart) {
|
|
1261
|
+
resolve({ success: false, error: '返回格式异常' });
|
|
1262
|
+
return;
|
|
1263
|
+
}
|
|
1264
|
+
try {
|
|
1265
|
+
const parsed = JSON.parse(output.slice(jsonStart, jsonEnd + 1));
|
|
1266
|
+
const message = parsed?.result?.payloads?.[0]?.text || '';
|
|
1267
|
+
const provider = parsed?.result?.meta?.agentMeta?.provider || '';
|
|
1268
|
+
const modelId = parsed?.result?.meta?.agentMeta?.model || '';
|
|
1269
|
+
if (message || (provider && modelId)) {
|
|
1270
|
+
resolve({ success: true, message, provider, model: modelId });
|
|
1271
|
+
} else {
|
|
1272
|
+
resolve({ success: false, error: '模型未返回内容' });
|
|
1273
|
+
}
|
|
1274
|
+
} catch {
|
|
1275
|
+
resolve({ success: false, error: '返回 JSON 解析失败' });
|
|
1276
|
+
}
|
|
1277
|
+
});
|
|
1278
|
+
});
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1239
1281
|
async function showStatusInfo(cliName) {
|
|
1240
1282
|
const config = getConfigInfo();
|
|
1241
1283
|
const port = config.port || 18789;
|
|
@@ -1271,12 +1313,45 @@ async function showStatusInfo(cliName) {
|
|
|
1271
1313
|
}
|
|
1272
1314
|
|
|
1273
1315
|
// 模型配置
|
|
1316
|
+
let primaryModel = '';
|
|
1274
1317
|
if (config.raw) {
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1318
|
+
try {
|
|
1319
|
+
const json = JSON.parse(config.raw);
|
|
1320
|
+
const hasProviders = json.models?.providers && Object.keys(json.models.providers).length > 0;
|
|
1321
|
+
primaryModel = json.agents?.defaults?.model?.primary || '';
|
|
1322
|
+
if (hasProviders) {
|
|
1323
|
+
console.log(colors.green(' ✓ 已配置 AI 模型'));
|
|
1324
|
+
if (primaryModel) {
|
|
1325
|
+
console.log(colors.gray(` 主模型: ${primaryModel}`));
|
|
1326
|
+
}
|
|
1327
|
+
} else {
|
|
1328
|
+
console.log(colors.yellow(' ⚠ 未配置模型,请先选择「配置模型」'));
|
|
1329
|
+
}
|
|
1330
|
+
} catch {
|
|
1331
|
+
const hasProviders = config.raw.includes('"providers"');
|
|
1332
|
+
if (hasProviders) {
|
|
1333
|
+
console.log(colors.green(' ✓ 已配置 AI 模型'));
|
|
1334
|
+
} else {
|
|
1335
|
+
console.log(colors.yellow(' ⚠ 未配置模型,请先选择「配置模型」'));
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
|
|
1340
|
+
// 模型对话测试
|
|
1341
|
+
if (primaryModel) {
|
|
1342
|
+
console.log(colors.gray(' … 正在测试模型对话...'));
|
|
1343
|
+
const testResult = await testModelChat(cliName);
|
|
1344
|
+
if (testResult.success) {
|
|
1345
|
+
console.log(colors.green(' ✓ 模型对话正常'));
|
|
1346
|
+
if (testResult.message) {
|
|
1347
|
+
const reply = testResult.message.length > 60
|
|
1348
|
+
? testResult.message.substring(0, 60) + '...'
|
|
1349
|
+
: testResult.message;
|
|
1350
|
+
console.log(colors.gray(` 回复: ${reply}`));
|
|
1351
|
+
}
|
|
1278
1352
|
} else {
|
|
1279
|
-
console.log(colors.
|
|
1353
|
+
console.log(colors.red(` ✗ 模型对话失败: ${testResult.error}`));
|
|
1354
|
+
console.log(colors.yellow(' → 请选择「配置模型」检查 API Key 和节点配置'));
|
|
1280
1355
|
}
|
|
1281
1356
|
}
|
|
1282
1357
|
|