@pikecode/api-key-manager 2.0.3 → 2.0.5

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": "2.0.3",
3
+ "version": "2.0.5",
4
4
  "description": "A CLI tool for managing and switching multiple API provider configurations",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -38,6 +38,20 @@ async function promptProviderInfo(adder) {
38
38
  validate: input => {
39
39
  const err = validator.validateName(input);
40
40
  return err || true;
41
+ },
42
+ when: answers => {
43
+ // 如果选择了官方登录,直接用 "openai-official",不需要输入名称
44
+ if ((answers.ideName || adder.presetIdeName) === 'codex' && answers.authMode === 'chatgpt_login') {
45
+ return false;
46
+ }
47
+ return true;
48
+ },
49
+ default: answers => {
50
+ // 官方登录模式下返回默认名称
51
+ if ((answers.ideName || adder.presetIdeName) === 'codex' && answers.authMode === 'chatgpt_login') {
52
+ return 'openai-official';
53
+ }
54
+ return undefined;
41
55
  }
42
56
  },
43
57
  {
@@ -86,7 +100,13 @@ async function promptProviderInfo(adder) {
86
100
  { name: UI_MESSAGES.AUTH_MODE_CODEX_CHATGPT_LOGIN, value: 'chatgpt_login' }
87
101
  ],
88
102
  default: 'api_key',
89
- when: answers => (answers.ideName || adder.presetIdeName) === 'codex'
103
+ when: answers => {
104
+ const isCodex = (answers.ideName || adder.presetIdeName) === 'codex';
105
+ if (!isCodex) return false;
106
+ // 如果已经有官方配置了,就用 api_key 模式,不提示选择
107
+ const hasOfficialConfig = adder.configManager.getProvider('openai-official');
108
+ return !hasOfficialConfig;
109
+ }
90
110
  },
91
111
  {
92
112
  type: 'input',
@@ -57,7 +57,7 @@ async function saveProvider(adder, answers) {
57
57
 
58
58
  // 如果是首个 Codex 配置,自动创建官方登录配置
59
59
  if (answers.ideName === 'codex') {
60
- const existingCodexProviders = Object.values(adder.configManager.getAllProviders())
60
+ const existingCodexProviders = adder.configManager.listProviders()
61
61
  .filter(p => p.ideName === 'codex');
62
62
 
63
63
  // 只有当刚才添加的是第一个 Codex 配置,且没有官方配置时才创建
@@ -66,8 +66,17 @@ class ProviderAdder extends BaseCommand {
66
66
  }
67
67
 
68
68
  if (answers.ideName === 'codex') {
69
- // authMode 由用户在 prompts 中选择,不再强制覆盖
70
- // 支持 api_key 和 chatgpt_login 两种模式
69
+ // authMode 由用户在 prompts 中选择,没有官方配置时才提示
70
+ // 如果已有官方配置,默认为 api_key
71
+ if (!answers.authMode) {
72
+ answers.authMode = 'api_key';
73
+ }
74
+
75
+ // 官方登录模式下自动设置名称为 openai-official
76
+ if (answers.authMode === 'chatgpt_login' && !answers.name) {
77
+ answers.name = 'openai-official';
78
+ }
79
+
71
80
  answers.codexFiles = null;
72
81
 
73
82
  // Codex 启动参数配置
package/src/config.js CHANGED
@@ -383,8 +383,9 @@ class ConfigManager {
383
383
  smallFast: smallFastModel
384
384
  };
385
385
  } else {
386
- // Codex 不需要这些字段,设置为 null 以保持向后兼容
387
- newProvider.authMode = null;
386
+ // Codex 支持 authMode(api_key 或 chatgpt_login)
387
+ const authMode = providerConfig.authMode || existing?.authMode || null;
388
+ newProvider.authMode = authMode;
388
389
  newProvider.models = null;
389
390
  }
390
391
 
@@ -165,7 +165,7 @@ function validateAndNormalizeData(data, source) {
165
165
  ideName,
166
166
  authMode:
167
167
  ideName === 'codex'
168
- ? null
168
+ ? provider.authMode || null
169
169
  : provider.authMode === 'api_token'
170
170
  ? 'auth_token'
171
171
  : provider.authMode || 'api_key',