openclawapi 1.3.0 → 1.3.2

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.
Files changed (2) hide show
  1. package/cli.js +15 -61
  2. 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;
@@ -342,64 +337,24 @@ async function activate(paths, type) {
342
337
  const currentModelId = provider.models?.[0]?.id || models[0].id;
343
338
  const modelConfig = models.find(m => m.id === currentModelId) || models[0];
344
339
 
345
- // 设置为主模型
346
- const modelKey = `${apiConfig.providerName}/${modelConfig.id}`;
347
- config.agents.defaults.model.primary = modelKey;
348
- config.agents.defaults.model.fallbacks = [];
349
-
350
- writeConfig(paths.openclawConfig, config);
351
-
352
- console.log(chalk.green(`✅ 已激活 ${typeLabel}`));
353
- console.log(chalk.cyan(` 节点: ${provider.baseUrl}`));
354
- console.log(chalk.gray(` 模型: ${modelConfig.name}`));
355
- }
356
-
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
-
340
+ // 输入 API Key
341
+ const currentKey = provider.apiKey;
386
342
  const { apiKey } = await inquirer.prompt([{
387
343
  type: 'password',
388
344
  name: 'apiKey',
389
- message: '请输入 API Key:',
345
+ message: `请输入 ${typeLabel} API Key:`,
390
346
  mask: '*',
347
+ default: currentKey || '',
391
348
  validate: input => input.trim() !== '' || 'API Key 不能为空'
392
349
  }]);
393
350
 
394
- const providers = [];
395
- if (target === 'claude' || target === 'both') providers.push('yunyi-claude');
396
- if (target === 'codex' || target === 'both') providers.push('yunyi-codex');
351
+ // 保存 API Key
352
+ config.models.providers[apiConfig.providerName].apiKey = apiKey.trim();
397
353
 
398
- providers.forEach(providerName => {
399
- if (config.models.providers[providerName]) {
400
- config.models.providers[providerName].apiKey = apiKey.trim();
401
- }
402
- });
354
+ // 设置为主模型
355
+ const modelKey = `${apiConfig.providerName}/${modelConfig.id}`;
356
+ config.agents.defaults.model.primary = modelKey;
357
+ config.agents.defaults.model.fallbacks = [];
403
358
 
404
359
  writeConfig(paths.openclawConfig, config);
405
360
 
@@ -413,14 +368,13 @@ async function setApiKey(paths) {
413
368
  if (fs.existsSync(paths.authProfiles)) {
414
369
  try { authProfiles = JSON.parse(fs.readFileSync(paths.authProfiles, 'utf8')); } catch {}
415
370
  }
416
-
417
- providers.forEach(providerName => {
418
- authProfiles[`${providerName}:default`] = { apiKey: apiKey.trim() };
419
- });
420
-
371
+ authProfiles[`${apiConfig.providerName}:default`] = { apiKey: apiKey.trim() };
421
372
  fs.writeFileSync(paths.authProfiles, JSON.stringify(authProfiles, null, 2), 'utf8');
422
373
 
423
- console.log(chalk.green('\n✅ API Key 已保存'));
374
+ console.log(chalk.green(`\n✅ 已激活 ${typeLabel}`));
375
+ console.log(chalk.cyan(` 节点: ${provider.baseUrl}`));
376
+ console.log(chalk.gray(` 模型: ${modelConfig.name}`));
377
+ console.log(chalk.gray(` API Key: 已设置`));
424
378
  }
425
379
 
426
380
  // ============ 查看配置 ============
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openclawapi",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "description": "跨平台 OpenClaw/Clawdbot 配置管理工具 - 管理中转地址、模型切换、API Keys、测速优化",
5
5
  "main": "cli.js",
6
6
  "bin": {