openclawapi 1.3.1 → 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 +29 -1
  2. package/package.json +1 -1
package/cli.js CHANGED
@@ -337,6 +337,20 @@ async function activate(paths, type) {
337
337
  const currentModelId = provider.models?.[0]?.id || models[0].id;
338
338
  const modelConfig = models.find(m => m.id === currentModelId) || models[0];
339
339
 
340
+ // 输入 API Key
341
+ const currentKey = provider.apiKey;
342
+ const { apiKey } = await inquirer.prompt([{
343
+ type: 'password',
344
+ name: 'apiKey',
345
+ message: `请输入 ${typeLabel} API Key:`,
346
+ mask: '*',
347
+ default: currentKey || '',
348
+ validate: input => input.trim() !== '' || 'API Key 不能为空'
349
+ }]);
350
+
351
+ // 保存 API Key
352
+ config.models.providers[apiConfig.providerName].apiKey = apiKey.trim();
353
+
340
354
  // 设置为主模型
341
355
  const modelKey = `${apiConfig.providerName}/${modelConfig.id}`;
342
356
  config.agents.defaults.model.primary = modelKey;
@@ -344,9 +358,23 @@ async function activate(paths, type) {
344
358
 
345
359
  writeConfig(paths.openclawConfig, config);
346
360
 
347
- console.log(chalk.green(`✅ 已激活 ${typeLabel}`));
361
+ // 同时写入 auth-profiles
362
+ const authDir = path.dirname(paths.authProfiles);
363
+ if (!fs.existsSync(authDir)) {
364
+ fs.mkdirSync(authDir, { recursive: true });
365
+ }
366
+
367
+ let authProfiles = {};
368
+ if (fs.existsSync(paths.authProfiles)) {
369
+ try { authProfiles = JSON.parse(fs.readFileSync(paths.authProfiles, 'utf8')); } catch {}
370
+ }
371
+ authProfiles[`${apiConfig.providerName}:default`] = { apiKey: apiKey.trim() };
372
+ fs.writeFileSync(paths.authProfiles, JSON.stringify(authProfiles, null, 2), 'utf8');
373
+
374
+ console.log(chalk.green(`\n✅ 已激活 ${typeLabel}`));
348
375
  console.log(chalk.cyan(` 节点: ${provider.baseUrl}`));
349
376
  console.log(chalk.gray(` 模型: ${modelConfig.name}`));
377
+ console.log(chalk.gray(` API Key: 已设置`));
350
378
  }
351
379
 
352
380
  // ============ 查看配置 ============
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openclawapi",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "description": "跨平台 OpenClaw/Clawdbot 配置管理工具 - 管理中转地址、模型切换、API Keys、测速优化",
5
5
  "main": "cli.js",
6
6
  "bin": {