openclawsetup 2.4.8 → 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 +39 -40
- package/package.json +1 -1
package/bin/cli.mjs
CHANGED
|
@@ -10,9 +10,8 @@
|
|
|
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
|
-
import http from 'http';
|
|
16
15
|
import { homedir, platform } from 'os';
|
|
17
16
|
import { join } from 'path';
|
|
18
17
|
import { createInterface } from 'readline';
|
|
@@ -1237,45 +1236,45 @@ async function runHealthCheck(cliName, autoFix = false) {
|
|
|
1237
1236
|
|
|
1238
1237
|
// ============ 交互式菜单 ============
|
|
1239
1238
|
|
|
1240
|
-
function testModelChat(
|
|
1239
|
+
function testModelChat(cliName) {
|
|
1241
1240
|
return new Promise((resolve) => {
|
|
1242
|
-
const
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
'
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
let data = '';
|
|
1256
|
-
res.on('data', chunk => data += chunk);
|
|
1257
|
-
res.on('end', () => {
|
|
1258
|
-
try {
|
|
1259
|
-
const json = JSON.parse(data);
|
|
1260
|
-
const text = json.output?.[0]?.content?.[0]?.text;
|
|
1261
|
-
if (text) {
|
|
1262
|
-
resolve({ success: true, message: text });
|
|
1263
|
-
} else if (json.error) {
|
|
1264
|
-
resolve({ success: false, error: json.error.message || JSON.stringify(json.error) });
|
|
1265
|
-
} else {
|
|
1266
|
-
resolve({ success: false, error: `HTTP ${res.statusCode}: ${data.substring(0, 200)}` });
|
|
1267
|
-
}
|
|
1268
|
-
} catch {
|
|
1269
|
-
resolve({ success: false, error: `HTTP ${res.statusCode}: ${data.substring(0, 200)}` });
|
|
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 执行失败' });
|
|
1270
1254
|
}
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
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
|
+
}
|
|
1276
1277
|
});
|
|
1277
|
-
req.write(postData);
|
|
1278
|
-
req.end();
|
|
1279
1278
|
});
|
|
1280
1279
|
}
|
|
1281
1280
|
|
|
@@ -1339,9 +1338,9 @@ async function showStatusInfo(cliName) {
|
|
|
1339
1338
|
}
|
|
1340
1339
|
|
|
1341
1340
|
// 模型对话测试
|
|
1342
|
-
if (
|
|
1341
|
+
if (primaryModel) {
|
|
1343
1342
|
console.log(colors.gray(' … 正在测试模型对话...'));
|
|
1344
|
-
const testResult = await testModelChat(
|
|
1343
|
+
const testResult = await testModelChat(cliName);
|
|
1345
1344
|
if (testResult.success) {
|
|
1346
1345
|
console.log(colors.green(' ✓ 模型对话正常'));
|
|
1347
1346
|
if (testResult.message) {
|