@pikecode/api-key-manager 1.0.28 → 1.0.30

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.30",
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,29 @@ 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;
1494
+ } else {
1495
+ // 确保 Codex 配置不包含 Claude 特定字段
1496
+ provider.authMode = null;
1497
+ provider.tokenType = null;
1498
+ provider.models = null;
1473
1499
  }
1474
- provider.models.primary = answers.primaryModel || null;
1475
- provider.models.smallFast = answers.smallFastModel || null;
1500
+
1501
+ // 确保 ideName 不被改变
1502
+ provider.ideName = isCodex ? 'codex' : 'claude';
1476
1503
 
1477
1504
  await this.configManager.save();
1478
1505
  Logger.success(`供应商 '${newName}' 已更新`);
package/src/config.js CHANGED
@@ -198,24 +198,35 @@ class ConfigManager {
198
198
  async addProvider(name, providerConfig) {
199
199
  await this.ensureLoaded();
200
200
 
201
+ const isCodex = providerConfig.ideName === 'codex';
202
+
201
203
  this.config.providers[name] = {
202
204
  name,
203
205
  displayName: providerConfig.displayName || name,
204
- ideName: providerConfig.ideName || 'claude', // 历史兼容性字段
206
+ ideName: providerConfig.ideName || 'claude',
205
207
  baseUrl: providerConfig.baseUrl,
206
208
  authToken: providerConfig.authToken,
207
- authMode: providerConfig.authMode || 'api_key',
208
- tokenType: providerConfig.tokenType || 'api_key', // 仅在 authMode 为 'api_key' 时使用
209
209
  launchArgs: providerConfig.launchArgs || [],
210
- models: {
211
- primary: providerConfig.primaryModel || null,
212
- smallFast: providerConfig.smallFastModel || null
213
- },
214
210
  createdAt: new Date().toISOString(),
215
211
  lastUsed: new Date().toISOString(),
216
212
  current: false
217
213
  };
218
214
 
215
+ // Claude Code 特定字段
216
+ if (!isCodex) {
217
+ this.config.providers[name].authMode = providerConfig.authMode || 'api_key';
218
+ this.config.providers[name].tokenType = providerConfig.tokenType || 'api_key';
219
+ this.config.providers[name].models = {
220
+ primary: providerConfig.primaryModel || null,
221
+ smallFast: providerConfig.smallFastModel || null
222
+ };
223
+ } else {
224
+ // Codex 不需要这些字段,设置为 null 以保持向后兼容
225
+ this.config.providers[name].authMode = null;
226
+ this.config.providers[name].tokenType = null;
227
+ this.config.providers[name].models = null;
228
+ }
229
+
219
230
  // 如果是第一个供应商或设置为默认,则设为当前供应商
220
231
  if (Object.keys(this.config.providers).length === 1 || providerConfig.setAsDefault) {
221
232
  // 重置所有供应商的current状态