@pikecode/api-key-manager 1.0.28 → 1.0.29

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pikecode/api-key-manager",
3
- "version": "1.0.28",
3
+ "version": "1.0.29",
4
4
  "description": "A CLI tool for managing and switching multiple API provider configurations",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -1325,27 +1325,32 @@ class EnvSwitcher extends BaseCommand {
1325
1325
  this.showManageMenu();
1326
1326
  }, '取消编辑');
1327
1327
 
1328
- let answers;
1329
- try {
1330
- answers = await this.prompt([
1331
- {
1332
- type: 'input',
1333
- name: 'name',
1334
- message: '请输入供应商名称 (用于命令行):',
1335
- default: provider.name,
1336
- validate: (input) => {
1337
- const error = validator.validateName(input);
1338
- if (error) return error;
1339
- return true;
1340
- }
1341
- },
1342
- {
1343
- type: 'input',
1344
- name: 'displayName',
1345
- message: '显示名称:',
1346
- default: provider.displayName,
1347
- prefillDefault: true
1348
- },
1328
+ // 根据 IDE 类型构建不同的问卷
1329
+ const isCodex = provider.ideName === 'codex';
1330
+ const questions = [
1331
+ {
1332
+ type: 'input',
1333
+ name: 'name',
1334
+ message: '请输入供应商名称 (用于命令行):',
1335
+ default: provider.name,
1336
+ validate: (input) => {
1337
+ const error = validator.validateName(input);
1338
+ if (error) return error;
1339
+ return true;
1340
+ }
1341
+ },
1342
+ {
1343
+ type: 'input',
1344
+ name: 'displayName',
1345
+ message: '显示名称:',
1346
+ default: provider.displayName,
1347
+ prefillDefault: true
1348
+ }
1349
+ ];
1350
+
1351
+ // Claude Code 特定的字段
1352
+ if (!isCodex) {
1353
+ questions.push(
1349
1354
  {
1350
1355
  type: 'list',
1351
1356
  name: 'authMode',
@@ -1368,33 +1373,6 @@ class EnvSwitcher extends BaseCommand {
1368
1373
  default: provider.tokenType || 'api_key',
1369
1374
  when: (answers) => answers.authMode === 'api_key'
1370
1375
  },
1371
- {
1372
- type: 'input',
1373
- name: 'baseUrl',
1374
- message: '基础URL:',
1375
- default: provider.baseUrl,
1376
- prefillDefault: true,
1377
- when: (answers) => answers.authMode === 'api_key' || answers.authMode === 'auth_token'
1378
- },
1379
- {
1380
- type: 'input',
1381
- name: 'authToken',
1382
- message: (answers) => {
1383
- switch (answers.authMode) {
1384
- case 'api_key':
1385
- const tokenTypeLabel = answers.tokenType === 'auth_token' ? 'ANTHROPIC_AUTH_TOKEN' : 'ANTHROPIC_API_KEY';
1386
- return `Token (${tokenTypeLabel}):`;
1387
- case 'auth_token':
1388
- return '认证令牌 (ANTHROPIC_AUTH_TOKEN):';
1389
- case 'oauth_token':
1390
- return 'OAuth令牌 (CLAUDE_CODE_OAUTH_TOKEN):';
1391
- default:
1392
- return '认证令牌:';
1393
- }
1394
- },
1395
- default: provider.authToken,
1396
- prefillDefault: true
1397
- },
1398
1376
  {
1399
1377
  type: 'input',
1400
1378
  name: 'primaryModel',
@@ -1421,7 +1399,44 @@ class EnvSwitcher extends BaseCommand {
1421
1399
  return true;
1422
1400
  }
1423
1401
  }
1424
- ]);
1402
+ );
1403
+ }
1404
+
1405
+ // 通用字段(Claude 和 Codex 都需要)
1406
+ questions.push({
1407
+ type: 'input',
1408
+ name: 'baseUrl',
1409
+ message: isCodex ? '基础URL (OPENAI_BASE_URL):' : '基础URL:',
1410
+ default: provider.baseUrl,
1411
+ prefillDefault: true
1412
+ });
1413
+
1414
+ questions.push({
1415
+ type: 'input',
1416
+ name: 'authToken',
1417
+ message: (answers) => {
1418
+ if (isCodex) {
1419
+ return 'API Key (OPENAI_API_KEY):';
1420
+ }
1421
+ switch (answers.authMode) {
1422
+ case 'api_key':
1423
+ const tokenTypeLabel = answers.tokenType === 'auth_token' ? 'ANTHROPIC_AUTH_TOKEN' : 'ANTHROPIC_API_KEY';
1424
+ return `Token (${tokenTypeLabel}):`;
1425
+ case 'auth_token':
1426
+ return '认证令牌 (ANTHROPIC_AUTH_TOKEN):';
1427
+ case 'oauth_token':
1428
+ return 'OAuth令牌 (CLAUDE_CODE_OAUTH_TOKEN):';
1429
+ default:
1430
+ return '认证令牌:';
1431
+ }
1432
+ },
1433
+ default: provider.authToken,
1434
+ prefillDefault: true
1435
+ });
1436
+
1437
+ let answers;
1438
+ try {
1439
+ answers = await this.prompt(questions);
1425
1440
  } catch (error) {
1426
1441
  this.removeESCListener(escListener);
1427
1442
  if (this.isEscCancelled(error)) {
@@ -1462,17 +1477,24 @@ class EnvSwitcher extends BaseCommand {
1462
1477
  provider.displayName = answers.displayName || newName;
1463
1478
  provider.baseUrl = answers.baseUrl;
1464
1479
  provider.authToken = answers.authToken;
1465
- provider.authMode = answers.authMode;
1466
- if (answers.tokenType) {
1467
- provider.tokenType = answers.tokenType; // 仅在 authMode 为 'api_key' 时使用
1468
- }
1469
1480
 
1470
- // 更新模型配置
1471
- if (!provider.models) {
1472
- provider.models = {};
1481
+ // Claude Code 特定的更新
1482
+ if (!isCodex) {
1483
+ provider.authMode = answers.authMode;
1484
+ if (answers.tokenType) {
1485
+ provider.tokenType = answers.tokenType; // 仅在 authMode 为 'api_key' 时使用
1486
+ }
1487
+
1488
+ // 更新模型配置
1489
+ if (!provider.models) {
1490
+ provider.models = {};
1491
+ }
1492
+ provider.models.primary = answers.primaryModel || null;
1493
+ provider.models.smallFast = answers.smallFastModel || null;
1473
1494
  }
1474
- provider.models.primary = answers.primaryModel || null;
1475
- provider.models.smallFast = answers.smallFastModel || null;
1495
+
1496
+ // 确保 ideName 不被改变
1497
+ provider.ideName = isCodex ? 'codex' : 'claude';
1476
1498
 
1477
1499
  await this.configManager.save();
1478
1500
  Logger.success(`供应商 '${newName}' 已更新`);