openclawapi 1.3.0 → 1.3.1
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 +0 -74
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -191,10 +191,8 @@ async function main() {
|
|
|
191
191
|
{ name: '⚡ 激活 Claude', value: 'activate_claude' },
|
|
192
192
|
{ name: '⚡ 激活 Codex', value: 'activate_codex' },
|
|
193
193
|
new inquirer.Separator(),
|
|
194
|
-
{ name: '🔑 设置 API Key', value: 'set_apikey' },
|
|
195
194
|
{ name: '📋 查看当前配置', value: 'view_config' },
|
|
196
195
|
{ name: '🔄 恢复默认配置', value: 'restore' },
|
|
197
|
-
new inquirer.Separator(),
|
|
198
196
|
{ name: '❌ 退出', value: 'exit' }
|
|
199
197
|
]
|
|
200
198
|
}]);
|
|
@@ -215,9 +213,6 @@ async function main() {
|
|
|
215
213
|
case 'activate_codex':
|
|
216
214
|
await activate(paths, 'codex');
|
|
217
215
|
break;
|
|
218
|
-
case 'set_apikey':
|
|
219
|
-
await setApiKey(paths);
|
|
220
|
-
break;
|
|
221
216
|
case 'view_config':
|
|
222
217
|
await viewConfig(paths);
|
|
223
218
|
break;
|
|
@@ -354,75 +349,6 @@ async function activate(paths, type) {
|
|
|
354
349
|
console.log(chalk.gray(` 模型: ${modelConfig.name}`));
|
|
355
350
|
}
|
|
356
351
|
|
|
357
|
-
// ============ 设置 API Key ============
|
|
358
|
-
async function setApiKey(paths) {
|
|
359
|
-
console.log(chalk.cyan('🔑 设置 API Key\n'));
|
|
360
|
-
|
|
361
|
-
let config = readConfig(paths.openclawConfig);
|
|
362
|
-
|
|
363
|
-
// 检查已配置的节点
|
|
364
|
-
const claudeConfigured = config?.models?.providers?.['yunyi-claude'];
|
|
365
|
-
const codexConfigured = config?.models?.providers?.['yunyi-codex'];
|
|
366
|
-
|
|
367
|
-
if (!claudeConfigured && !codexConfigured) {
|
|
368
|
-
console.log(chalk.yellow('⚠️ 请先选择节点'));
|
|
369
|
-
return;
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
const choices = [];
|
|
373
|
-
if (claudeConfigured) choices.push({ name: '🔵 Claude', value: 'claude' });
|
|
374
|
-
if (codexConfigured) choices.push({ name: '🟢 Codex', value: 'codex' });
|
|
375
|
-
if (claudeConfigured && codexConfigured) {
|
|
376
|
-
choices.push({ name: '🔷 两者都设置 (相同 Key)', value: 'both' });
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
const { target } = await inquirer.prompt([{
|
|
380
|
-
type: 'list',
|
|
381
|
-
name: 'target',
|
|
382
|
-
message: '为哪个设置 API Key?',
|
|
383
|
-
choices
|
|
384
|
-
}]);
|
|
385
|
-
|
|
386
|
-
const { apiKey } = await inquirer.prompt([{
|
|
387
|
-
type: 'password',
|
|
388
|
-
name: 'apiKey',
|
|
389
|
-
message: '请输入 API Key:',
|
|
390
|
-
mask: '*',
|
|
391
|
-
validate: input => input.trim() !== '' || 'API Key 不能为空'
|
|
392
|
-
}]);
|
|
393
|
-
|
|
394
|
-
const providers = [];
|
|
395
|
-
if (target === 'claude' || target === 'both') providers.push('yunyi-claude');
|
|
396
|
-
if (target === 'codex' || target === 'both') providers.push('yunyi-codex');
|
|
397
|
-
|
|
398
|
-
providers.forEach(providerName => {
|
|
399
|
-
if (config.models.providers[providerName]) {
|
|
400
|
-
config.models.providers[providerName].apiKey = apiKey.trim();
|
|
401
|
-
}
|
|
402
|
-
});
|
|
403
|
-
|
|
404
|
-
writeConfig(paths.openclawConfig, config);
|
|
405
|
-
|
|
406
|
-
// 同时写入 auth-profiles
|
|
407
|
-
const authDir = path.dirname(paths.authProfiles);
|
|
408
|
-
if (!fs.existsSync(authDir)) {
|
|
409
|
-
fs.mkdirSync(authDir, { recursive: true });
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
let authProfiles = {};
|
|
413
|
-
if (fs.existsSync(paths.authProfiles)) {
|
|
414
|
-
try { authProfiles = JSON.parse(fs.readFileSync(paths.authProfiles, 'utf8')); } catch {}
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
providers.forEach(providerName => {
|
|
418
|
-
authProfiles[`${providerName}:default`] = { apiKey: apiKey.trim() };
|
|
419
|
-
});
|
|
420
|
-
|
|
421
|
-
fs.writeFileSync(paths.authProfiles, JSON.stringify(authProfiles, null, 2), 'utf8');
|
|
422
|
-
|
|
423
|
-
console.log(chalk.green('\n✅ API Key 已保存'));
|
|
424
|
-
}
|
|
425
|
-
|
|
426
352
|
// ============ 查看配置 ============
|
|
427
353
|
async function viewConfig(paths) {
|
|
428
354
|
console.log(chalk.cyan('📋 当前配置\n'));
|