openclawapi 1.3.8 → 1.3.10
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/cli.js +75 -5
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -433,7 +433,20 @@ async function testConnection(paths) {
|
|
|
433
433
|
console.log(chalk.green(`\n✅ ${typeLabel} API 连接成功!`));
|
|
434
434
|
console.log(chalk.cyan(` 响应时间: ${latency}ms`));
|
|
435
435
|
console.log(chalk.yellow(` 模型回复: ${result.message}`));
|
|
436
|
-
|
|
436
|
+
|
|
437
|
+
// 询问是否重启 gateway
|
|
438
|
+
const { restart } = await inquirer.prompt([{
|
|
439
|
+
type: 'confirm',
|
|
440
|
+
name: 'restart',
|
|
441
|
+
message: '是否重启 OpenClaw Gateway 使配置生效?',
|
|
442
|
+
default: true
|
|
443
|
+
}]);
|
|
444
|
+
|
|
445
|
+
if (restart) {
|
|
446
|
+
await restartGateway();
|
|
447
|
+
} else {
|
|
448
|
+
console.log(chalk.gray(`\n💡 稍后可手动运行: openclaw gateway restart`));
|
|
449
|
+
}
|
|
437
450
|
} else {
|
|
438
451
|
console.log(chalk.red(`\n❌ ${typeLabel} API 连接失败`));
|
|
439
452
|
console.log(chalk.red(` 错误: ${result.error}`));
|
|
@@ -446,7 +459,20 @@ async function testConnection(paths) {
|
|
|
446
459
|
console.log(chalk.green(`\n✅ ${typeLabel} API 连接成功!`));
|
|
447
460
|
console.log(chalk.cyan(` 响应时间: ${latency}ms`));
|
|
448
461
|
console.log(chalk.yellow(` 模型回复: ${result.message}`));
|
|
449
|
-
|
|
462
|
+
|
|
463
|
+
// 询问是否重启 gateway
|
|
464
|
+
const { restart } = await inquirer.prompt([{
|
|
465
|
+
type: 'confirm',
|
|
466
|
+
name: 'restart',
|
|
467
|
+
message: '是否重启 OpenClaw Gateway 使配置生效?',
|
|
468
|
+
default: true
|
|
469
|
+
}]);
|
|
470
|
+
|
|
471
|
+
if (restart) {
|
|
472
|
+
await restartGateway();
|
|
473
|
+
} else {
|
|
474
|
+
console.log(chalk.gray(`\n💡 稍后可手动运行: openclaw gateway restart`));
|
|
475
|
+
}
|
|
450
476
|
} else {
|
|
451
477
|
console.log(chalk.red(`\n❌ ${typeLabel} API 连接失败`));
|
|
452
478
|
console.log(chalk.red(` 错误: ${result.error}`));
|
|
@@ -457,6 +483,50 @@ async function testConnection(paths) {
|
|
|
457
483
|
}
|
|
458
484
|
}
|
|
459
485
|
|
|
486
|
+
// ============ 重启 Gateway ============
|
|
487
|
+
async function restartGateway() {
|
|
488
|
+
console.log(chalk.cyan('\n🔄 正在重启 OpenClaw Gateway...'));
|
|
489
|
+
|
|
490
|
+
const { exec } = require('child_process');
|
|
491
|
+
|
|
492
|
+
// 尝试多种命令
|
|
493
|
+
const commands = [
|
|
494
|
+
'openclaw gateway restart',
|
|
495
|
+
'clawdbot gateway restart',
|
|
496
|
+
'npx openclaw gateway restart',
|
|
497
|
+
'npx clawdbot gateway restart'
|
|
498
|
+
];
|
|
499
|
+
|
|
500
|
+
return new Promise((resolve) => {
|
|
501
|
+
let tried = 0;
|
|
502
|
+
|
|
503
|
+
const tryNext = () => {
|
|
504
|
+
if (tried >= commands.length) {
|
|
505
|
+
console.log(chalk.red(`❌ 重启失败: 找不到 openclaw/clawdbot 命令`));
|
|
506
|
+
console.log(chalk.gray(` 请手动运行: openclaw gateway restart`));
|
|
507
|
+
console.log(chalk.gray(` 或: clawdbot gateway restart`));
|
|
508
|
+
resolve();
|
|
509
|
+
return;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
const cmd = commands[tried];
|
|
513
|
+
tried++;
|
|
514
|
+
|
|
515
|
+
exec(cmd, { timeout: 30000 }, (error) => {
|
|
516
|
+
if (error) {
|
|
517
|
+
tryNext();
|
|
518
|
+
} else {
|
|
519
|
+
console.log(chalk.green(`✅ Gateway 已重启`));
|
|
520
|
+
console.log(chalk.gray(` 现在可以在 Web/Telegram/Discord 等渠道测试对话了`));
|
|
521
|
+
resolve();
|
|
522
|
+
}
|
|
523
|
+
});
|
|
524
|
+
};
|
|
525
|
+
|
|
526
|
+
tryNext();
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
|
|
460
530
|
// Claude API 测试
|
|
461
531
|
function testClaudeApi(baseUrl, apiKey, model) {
|
|
462
532
|
return new Promise((resolve) => {
|
|
@@ -465,8 +535,8 @@ function testClaudeApi(baseUrl, apiKey, model) {
|
|
|
465
535
|
|
|
466
536
|
const postData = JSON.stringify({
|
|
467
537
|
model: model || 'claude-sonnet-4-5',
|
|
468
|
-
max_tokens:
|
|
469
|
-
messages: [{ role: 'user', content: '
|
|
538
|
+
max_tokens: 150,
|
|
539
|
+
messages: [{ role: 'user', content: '你是哪个模型?请用一句话回答你的模型名称和版本。' }]
|
|
470
540
|
});
|
|
471
541
|
|
|
472
542
|
const options = {
|
|
@@ -525,7 +595,7 @@ function testCodexApi(baseUrl, apiKey, model) {
|
|
|
525
595
|
|
|
526
596
|
const postData = JSON.stringify({
|
|
527
597
|
model: model || 'gpt-5.2',
|
|
528
|
-
input: '
|
|
598
|
+
input: '你是哪个模型?请用一句话回答你的模型名称和版本。'
|
|
529
599
|
});
|
|
530
600
|
|
|
531
601
|
const options = {
|