openclawapi 1.3.1 → 1.3.3
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 +31 -3
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -184,13 +184,13 @@ async function main() {
|
|
|
184
184
|
type: 'list',
|
|
185
185
|
name: 'action',
|
|
186
186
|
message: '请选择操作:',
|
|
187
|
+
pageSize: 10,
|
|
188
|
+
loop: false,
|
|
187
189
|
choices: [
|
|
188
190
|
{ name: '🔵 选择 Claude 节点', value: 'select_claude' },
|
|
189
191
|
{ name: '🟢 选择 Codex 节点', value: 'select_codex' },
|
|
190
|
-
new inquirer.Separator(),
|
|
191
192
|
{ name: '⚡ 激活 Claude', value: 'activate_claude' },
|
|
192
193
|
{ name: '⚡ 激活 Codex', value: 'activate_codex' },
|
|
193
|
-
new inquirer.Separator(),
|
|
194
194
|
{ name: '📋 查看当前配置', value: 'view_config' },
|
|
195
195
|
{ name: '🔄 恢复默认配置', value: 'restore' },
|
|
196
196
|
{ name: '❌ 退出', value: 'exit' }
|
|
@@ -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
|
-
|
|
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
|
// ============ 查看配置 ============
|