@pikecode/api-key-manager 1.3.91 → 2.0.1
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/README.md +79 -52
- package/bin/akm.js +47 -30
- package/package.json +13 -8
- package/src/CommandRegistry.js +2 -2
- package/src/commands/add/prompts.js +200 -171
- package/src/commands/add/providerSaver.js +6 -7
- package/src/commands/add.js +6 -2
- package/src/commands/backup.js +99 -45
- package/src/commands/current.js +41 -20
- package/src/commands/edit.js +3 -289
- package/src/commands/health.js +75 -31
- package/src/commands/list.js +39 -19
- package/src/commands/remove.js +2 -2
- package/src/commands/switch/provider-edit-questions-helper.js +29 -7
- package/src/commands/switch/provider-manager.js +39 -40
- package/src/commands/switch.js +9 -8
- package/src/config.js +68 -45
- package/src/index.js +1 -1
- package/src/utils/atomic-file.js +47 -0
- package/src/utils/claude-settings.js +4 -3
- package/src/utils/codex-files.js +227 -38
- package/src/utils/codex-launcher.js +16 -8
- package/src/utils/concurrency.js +30 -0
- package/src/utils/env-launcher.js +17 -1
- package/src/utils/import-validator.js +210 -0
- package/src/utils/launch-args.js +60 -1
- package/src/utils/provider-status-checker.js +49 -24
- package/src/utils/shell-snippets.js +32 -0
- package/src/utils/terminal-format.js +22 -4
- package/src/utils/ui-helper.js +0 -1
- package/src/utils/update-checker.js +3 -3
- package/src/utils/validator.js +81 -10
package/src/commands/edit.js
CHANGED
|
@@ -1,290 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* 编辑现有供应商配置
|
|
4
|
-
* @module commands/edit
|
|
5
|
-
*/
|
|
1
|
+
// 兼容旧的模块导入路径,编辑逻辑统一由 switch/ProviderManager 维护。
|
|
2
|
+
const { editCommand } = require('./switch');
|
|
6
3
|
|
|
7
|
-
|
|
8
|
-
const chalk = require('chalk');
|
|
9
|
-
const { configManager } = require('../config');
|
|
10
|
-
const { validator } = require('../utils/validator');
|
|
11
|
-
const { Logger } = require('../utils/logger');
|
|
12
|
-
const { UIHelper } = require('../utils/ui-helper');
|
|
13
|
-
const { BaseCommand } = require('./BaseCommand');
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* 供应商编辑器类
|
|
17
|
-
* 用于交互式编辑现有的 API 供应商配置
|
|
18
|
-
* @extends BaseCommand
|
|
19
|
-
*/
|
|
20
|
-
class ProviderEditor extends BaseCommand {
|
|
21
|
-
/**
|
|
22
|
-
* 创建供应商编辑器实例
|
|
23
|
-
*/
|
|
24
|
-
constructor() {
|
|
25
|
-
super();
|
|
26
|
-
this.configManager = configManager;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* 执行交互式编辑供应商流程
|
|
31
|
-
* @param {string} [providerName] - 要编辑的供应商名称,如果不提供则让用户选择
|
|
32
|
-
* @returns {Promise<void>}
|
|
33
|
-
*/
|
|
34
|
-
async interactive(providerName) {
|
|
35
|
-
await this.configManager.load();
|
|
36
|
-
const providers = this.configManager.listProviders();
|
|
37
|
-
|
|
38
|
-
if (providers.length === 0) {
|
|
39
|
-
Logger.warning('没有可编辑的供应商配置。请先添加一个。');
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
let providerToEdit;
|
|
44
|
-
if (providerName) {
|
|
45
|
-
providerToEdit = this.configManager.getProvider(providerName);
|
|
46
|
-
if (!providerToEdit) {
|
|
47
|
-
Logger.error(`供应商 '${providerName}' 不存在。`);
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
} else {
|
|
51
|
-
let selection;
|
|
52
|
-
try {
|
|
53
|
-
selection = await this.prompt([
|
|
54
|
-
{
|
|
55
|
-
type: 'list',
|
|
56
|
-
name: 'selectedProviderName',
|
|
57
|
-
message: '请选择要编辑的供应商:',
|
|
58
|
-
choices: [
|
|
59
|
-
...providers.map(p => ({ name: p.displayName || p.name, value: p.name })),
|
|
60
|
-
new inquirer.Separator(),
|
|
61
|
-
{ name: '取消', value: null }
|
|
62
|
-
]
|
|
63
|
-
}
|
|
64
|
-
]);
|
|
65
|
-
} catch (error) {
|
|
66
|
-
if (this.isEscCancelled(error)) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
throw error;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const { selectedProviderName } = selection;
|
|
73
|
-
|
|
74
|
-
if (!selectedProviderName) {
|
|
75
|
-
Logger.info('操作已取消。');
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
providerToEdit = this.configManager.getProvider(selectedProviderName);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
console.log(UIHelper.createTitle(`编辑供应商: ${providerToEdit.displayName}`, UIHelper.icons.edit));
|
|
82
|
-
console.log();
|
|
83
|
-
console.log(UIHelper.createTooltip('请更新供应商配置信息。按 Enter 键接受默认值。'));
|
|
84
|
-
console.log();
|
|
85
|
-
|
|
86
|
-
const isCodex = providerToEdit.ideName === 'codex';
|
|
87
|
-
|
|
88
|
-
const escListener = this.createESCListener(() => {
|
|
89
|
-
Logger.info('取消编辑供应商。');
|
|
90
|
-
const { registry } = require('../CommandRegistry');
|
|
91
|
-
registry.executeCommand('switch');
|
|
92
|
-
}, '取消编辑');
|
|
93
|
-
|
|
94
|
-
try {
|
|
95
|
-
let answers;
|
|
96
|
-
try {
|
|
97
|
-
const questions = [
|
|
98
|
-
{
|
|
99
|
-
type: 'input',
|
|
100
|
-
name: 'displayName',
|
|
101
|
-
message: '供应商名称:',
|
|
102
|
-
default: providerToEdit.displayName,
|
|
103
|
-
validate: (input) => validator.validateDisplayName(input) || true
|
|
104
|
-
}
|
|
105
|
-
];
|
|
106
|
-
|
|
107
|
-
if (isCodex) {
|
|
108
|
-
const existingLaunchArgs = Array.isArray(providerToEdit.launchArgs) ? providerToEdit.launchArgs : [];
|
|
109
|
-
const { getCodexLaunchArgs, checkExclusiveArgs } = require('../utils/launch-args');
|
|
110
|
-
const codexArgs = getCodexLaunchArgs();
|
|
111
|
-
|
|
112
|
-
const knownCodexArgNames = new Set(codexArgs.map(arg => arg.name));
|
|
113
|
-
const customCodexArgs = existingLaunchArgs
|
|
114
|
-
.filter(arg => typeof arg === 'string' && !knownCodexArgNames.has(arg));
|
|
115
|
-
|
|
116
|
-
questions.push(
|
|
117
|
-
{
|
|
118
|
-
type: 'input',
|
|
119
|
-
name: 'baseUrl',
|
|
120
|
-
message: 'OpenAI API 基础URL (留空使用官方API):',
|
|
121
|
-
default: providerToEdit.baseUrl || '',
|
|
122
|
-
validate: (input) => {
|
|
123
|
-
if (!input) return true;
|
|
124
|
-
return validator.validateUrl(input) || true;
|
|
125
|
-
}
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
type: 'input',
|
|
129
|
-
name: 'authToken',
|
|
130
|
-
message: 'OpenAI API Key (OPENAI_API_KEY):',
|
|
131
|
-
default: providerToEdit.authToken,
|
|
132
|
-
validate: (input) => {
|
|
133
|
-
if (!input) return 'API Key 不能为空';
|
|
134
|
-
return validator.validateToken(input) || true;
|
|
135
|
-
}
|
|
136
|
-
},
|
|
137
|
-
{
|
|
138
|
-
type: 'checkbox',
|
|
139
|
-
name: 'launchArgs',
|
|
140
|
-
message: 'Codex 启动参数:',
|
|
141
|
-
choices: [
|
|
142
|
-
...codexArgs.map(arg => ({
|
|
143
|
-
name: `${arg.label} (${arg.name})${arg.description ? ' - ' + arg.description : ''}`,
|
|
144
|
-
value: arg.name,
|
|
145
|
-
checked: existingLaunchArgs.includes(arg.name)
|
|
146
|
-
})),
|
|
147
|
-
...customCodexArgs.map(arg => ({
|
|
148
|
-
name: `${arg} ${chalk.gray('(自定义参数)')}`,
|
|
149
|
-
value: arg,
|
|
150
|
-
checked: true
|
|
151
|
-
}))
|
|
152
|
-
],
|
|
153
|
-
validate: (selected) => {
|
|
154
|
-
const conflictError = checkExclusiveArgs(selected, codexArgs);
|
|
155
|
-
if (conflictError) {
|
|
156
|
-
return conflictError;
|
|
157
|
-
}
|
|
158
|
-
return true;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
);
|
|
162
|
-
} else {
|
|
163
|
-
questions.push(
|
|
164
|
-
{
|
|
165
|
-
type: 'list',
|
|
166
|
-
name: 'authMode',
|
|
167
|
-
message: '认证模式:',
|
|
168
|
-
choices: [
|
|
169
|
-
{ name: '🔑 ANTHROPIC_API_KEY - 大多数第三方代理使用', value: 'api_key' },
|
|
170
|
-
{ name: '🔐 ANTHROPIC_AUTH_TOKEN - 部分服务商使用', value: 'auth_token' }
|
|
171
|
-
],
|
|
172
|
-
default: providerToEdit.authMode
|
|
173
|
-
},
|
|
174
|
-
{
|
|
175
|
-
type: 'input',
|
|
176
|
-
name: 'baseUrl',
|
|
177
|
-
message: 'API 基础URL (ANTHROPIC_BASE_URL):',
|
|
178
|
-
default: providerToEdit.baseUrl || '',
|
|
179
|
-
validate: (input) => {
|
|
180
|
-
if (!input) return 'API 基础URL不能为空';
|
|
181
|
-
return validator.validateUrl(input) || true;
|
|
182
|
-
}
|
|
183
|
-
},
|
|
184
|
-
{
|
|
185
|
-
type: 'input',
|
|
186
|
-
name: 'authToken',
|
|
187
|
-
message: (answers) => {
|
|
188
|
-
const envVar = answers.authMode === 'auth_token' ? 'ANTHROPIC_AUTH_TOKEN' : 'ANTHROPIC_API_KEY';
|
|
189
|
-
return `Token (${envVar}):`;
|
|
190
|
-
},
|
|
191
|
-
default: providerToEdit.authToken,
|
|
192
|
-
validate: (input) => validator.validateToken(input) || true
|
|
193
|
-
},
|
|
194
|
-
{
|
|
195
|
-
type: 'checkbox',
|
|
196
|
-
name: 'launchArgs',
|
|
197
|
-
message: '启动参数:',
|
|
198
|
-
choices: validator.getAvailableLaunchArgs().map(arg => ({
|
|
199
|
-
name: `${arg.label || arg.name} (${arg.name})${arg.description ? ' - ' + arg.description : ''}`,
|
|
200
|
-
value: arg.name,
|
|
201
|
-
checked: providerToEdit.launchArgs && providerToEdit.launchArgs.includes(arg.name)
|
|
202
|
-
}))
|
|
203
|
-
}
|
|
204
|
-
);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
answers = await this.prompt(questions);
|
|
208
|
-
} catch (error) {
|
|
209
|
-
this.removeESCListener(escListener);
|
|
210
|
-
if (this.isEscCancelled(error)) {
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
throw error;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
this.removeESCListener(escListener);
|
|
217
|
-
|
|
218
|
-
await this.saveProvider(providerToEdit.name, answers);
|
|
219
|
-
|
|
220
|
-
} catch (error) {
|
|
221
|
-
this.removeESCListener(escListener);
|
|
222
|
-
if (this.isEscCancelled(error)) {
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
throw error;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
async saveProvider(name, answers) {
|
|
230
|
-
try {
|
|
231
|
-
const existingProvider = this.configManager.getProvider(name);
|
|
232
|
-
const ideName = existingProvider?.ideName || 'claude';
|
|
233
|
-
|
|
234
|
-
if (ideName === 'codex') {
|
|
235
|
-
await this.configManager.addProvider(name, {
|
|
236
|
-
displayName: answers.displayName,
|
|
237
|
-
ideName: 'codex',
|
|
238
|
-
baseUrl: answers.baseUrl || null,
|
|
239
|
-
authToken: answers.authToken,
|
|
240
|
-
launchArgs: answers.launchArgs,
|
|
241
|
-
setAsDefault: false
|
|
242
|
-
});
|
|
243
|
-
} else {
|
|
244
|
-
// Re-use addProvider which can overwrite existing providers
|
|
245
|
-
await this.configManager.addProvider(name, {
|
|
246
|
-
displayName: answers.displayName,
|
|
247
|
-
ideName,
|
|
248
|
-
baseUrl: answers.baseUrl,
|
|
249
|
-
authToken: answers.authToken,
|
|
250
|
-
authMode: answers.authMode,
|
|
251
|
-
launchArgs: answers.launchArgs,
|
|
252
|
-
// Retain original model settings unless we add editing for them
|
|
253
|
-
primaryModel: existingProvider.models?.primary || null,
|
|
254
|
-
smallFastModel: existingProvider.models?.smallFast || null,
|
|
255
|
-
setAsDefault: false // Don't change default status on edit
|
|
256
|
-
});
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
Logger.success(`供应商 '${answers.displayName}' 更新成功!`);
|
|
260
|
-
|
|
261
|
-
console.log(chalk.green('\n🎉 供应商编辑完成!正在返回主界面...'));
|
|
262
|
-
await new Promise(resolve => setTimeout(resolve, 1500));
|
|
263
|
-
|
|
264
|
-
const { registry } = require('../CommandRegistry');
|
|
265
|
-
return await registry.executeCommand('switch');
|
|
266
|
-
|
|
267
|
-
} catch (error) {
|
|
268
|
-
if (this.isEscCancelled(error)) {
|
|
269
|
-
return;
|
|
270
|
-
}
|
|
271
|
-
Logger.error(`更新供应商失败: ${error.message}`);
|
|
272
|
-
throw error;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
async function editCommand(providerName) {
|
|
278
|
-
const editor = new ProviderEditor();
|
|
279
|
-
try {
|
|
280
|
-
await editor.interactive(providerName);
|
|
281
|
-
} catch (error) {
|
|
282
|
-
if (!editor.isEscCancelled(error)) {
|
|
283
|
-
Logger.error(`编辑供应商失败: ${error.message}`);
|
|
284
|
-
}
|
|
285
|
-
} finally {
|
|
286
|
-
editor.destroy();
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
module.exports = { editCommand, ProviderEditor };
|
|
4
|
+
module.exports = { editCommand };
|
package/src/commands/health.js
CHANGED
|
@@ -8,6 +8,7 @@ const chalk = require('chalk');
|
|
|
8
8
|
const { configManager } = require('../config');
|
|
9
9
|
const { Logger } = require('../utils/logger');
|
|
10
10
|
const { HealthChecker } = require('../utils/health-checker');
|
|
11
|
+
const { mapWithConcurrency } = require('../utils/concurrency');
|
|
11
12
|
const { UIHelper } = require('../utils/ui-helper');
|
|
12
13
|
|
|
13
14
|
/**
|
|
@@ -31,16 +32,28 @@ async function showProviderHealth(providerName, options = {}) {
|
|
|
31
32
|
return;
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
if (!options.json) {
|
|
36
|
+
console.log(chalk.blue(`\n🏥 健康检查: ${provider.displayName} (${provider.name})`));
|
|
37
|
+
console.log(chalk.gray('═'.repeat(60)));
|
|
38
|
+
console.log();
|
|
39
|
+
}
|
|
37
40
|
|
|
38
41
|
const checker = new HealthChecker();
|
|
39
|
-
const loadingInterval = UIHelper.createLoadingAnimation('检查中...');
|
|
42
|
+
const loadingInterval = options.json ? null : UIHelper.createLoadingAnimation('检查中...');
|
|
40
43
|
|
|
41
44
|
try {
|
|
42
|
-
const results = await checker.performHealthCheck(provider,
|
|
43
|
-
|
|
45
|
+
const results = await checker.performHealthCheck(provider, {
|
|
46
|
+
...options,
|
|
47
|
+
checkConnectivity: options.connectivity === true || options.checkConnectivity === true
|
|
48
|
+
});
|
|
49
|
+
if (loadingInterval) {
|
|
50
|
+
UIHelper.clearLoadingAnimation(loadingInterval);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (options.json) {
|
|
54
|
+
console.log(JSON.stringify(results, null, 2));
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
44
57
|
|
|
45
58
|
console.log(checker.formatHealthReport(results));
|
|
46
59
|
console.log();
|
|
@@ -49,11 +62,17 @@ async function showProviderHealth(providerName, options = {}) {
|
|
|
49
62
|
if (results.overallStatus === 'error' || results.overallStatus === 'warning') {
|
|
50
63
|
console.log(chalk.yellow('💡 建议操作:'));
|
|
51
64
|
|
|
52
|
-
if (
|
|
65
|
+
if (
|
|
66
|
+
results.checks.tokenExpiry?.status === 'expired' ||
|
|
67
|
+
results.checks.tokenExpiry?.status === 'critical'
|
|
68
|
+
) {
|
|
53
69
|
console.log(chalk.yellow(' • 使用 "akm edit" 更新 Token'));
|
|
54
70
|
}
|
|
55
71
|
|
|
56
|
-
if (
|
|
72
|
+
if (
|
|
73
|
+
results.checks.quota?.status === 'exceeded' ||
|
|
74
|
+
results.checks.quota?.status === 'critical'
|
|
75
|
+
) {
|
|
57
76
|
console.log(chalk.yellow(' • 检查 API 配额使用情况'));
|
|
58
77
|
console.log(chalk.yellow(' • 考虑升级套餐或添加新的供应商'));
|
|
59
78
|
}
|
|
@@ -71,12 +90,12 @@ async function showProviderHealth(providerName, options = {}) {
|
|
|
71
90
|
|
|
72
91
|
console.log();
|
|
73
92
|
}
|
|
74
|
-
|
|
75
93
|
} catch (error) {
|
|
76
|
-
|
|
94
|
+
if (loadingInterval) {
|
|
95
|
+
UIHelper.clearLoadingAnimation(loadingInterval);
|
|
96
|
+
}
|
|
77
97
|
Logger.error(`健康检查失败: ${error.message}`);
|
|
78
98
|
}
|
|
79
|
-
|
|
80
99
|
} catch (error) {
|
|
81
100
|
Logger.error(`健康检查执行失败: ${error.message}`);
|
|
82
101
|
throw error;
|
|
@@ -110,10 +129,17 @@ async function showAllHealth(options = {}) {
|
|
|
110
129
|
return;
|
|
111
130
|
}
|
|
112
131
|
|
|
113
|
-
const titleSuffix =
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
132
|
+
const titleSuffix =
|
|
133
|
+
options.filter === 'codex'
|
|
134
|
+
? ' (Codex CLI)'
|
|
135
|
+
: options.filter === 'claude'
|
|
136
|
+
? ' (Claude Code)'
|
|
137
|
+
: '';
|
|
138
|
+
if (!options.json) {
|
|
139
|
+
console.log(chalk.blue(`\n🏥 健康检查${titleSuffix}`));
|
|
140
|
+
console.log(chalk.gray('═'.repeat(60)));
|
|
141
|
+
console.log();
|
|
142
|
+
}
|
|
117
143
|
|
|
118
144
|
const checker = new HealthChecker();
|
|
119
145
|
const allResults = [];
|
|
@@ -121,26 +147,42 @@ async function showAllHealth(options = {}) {
|
|
|
121
147
|
const total = providers.length;
|
|
122
148
|
|
|
123
149
|
// 创建进度显示
|
|
124
|
-
const progressInterval =
|
|
125
|
-
|
|
126
|
-
|
|
150
|
+
const progressInterval = options.json
|
|
151
|
+
? null
|
|
152
|
+
: setInterval(() => {
|
|
153
|
+
process.stdout.write(`\r检查中... ${completedCount}/${total}`);
|
|
154
|
+
}, 100);
|
|
127
155
|
|
|
128
156
|
try {
|
|
129
157
|
// 并行检查所有供应商
|
|
130
|
-
const
|
|
131
|
-
const
|
|
132
|
-
checkConnectivity: options.connectivity
|
|
158
|
+
const results = await mapWithConcurrency(providers, 4, async provider => {
|
|
159
|
+
const providerResults = await checker.performHealthCheck(provider, {
|
|
160
|
+
checkConnectivity: options.connectivity === true || options.checkConnectivity === true
|
|
133
161
|
});
|
|
134
162
|
completedCount++;
|
|
135
|
-
return
|
|
163
|
+
return providerResults;
|
|
136
164
|
});
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
165
|
+
if (progressInterval) {
|
|
166
|
+
clearInterval(progressInterval);
|
|
167
|
+
process.stdout.write('\r' + ' '.repeat(50) + '\r'); // 清除进度显示
|
|
168
|
+
}
|
|
141
169
|
|
|
142
170
|
allResults.push(...results);
|
|
143
171
|
|
|
172
|
+
if (options.json) {
|
|
173
|
+
console.log(
|
|
174
|
+
JSON.stringify(
|
|
175
|
+
{
|
|
176
|
+
currentProvider: configManager.getCurrentProvider()?.name || null,
|
|
177
|
+
results
|
|
178
|
+
},
|
|
179
|
+
null,
|
|
180
|
+
2
|
|
181
|
+
)
|
|
182
|
+
);
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
|
|
144
186
|
// 显示结果
|
|
145
187
|
const currentProvider = configManager.getCurrentProvider();
|
|
146
188
|
|
|
@@ -157,7 +199,9 @@ async function showAllHealth(options = {}) {
|
|
|
157
199
|
// 显示统计
|
|
158
200
|
const errorCount = allResults.filter(r => r.overallStatus === 'error').length;
|
|
159
201
|
const warningCount = allResults.filter(r => r.overallStatus === 'warning').length;
|
|
160
|
-
const okCount = allResults.filter(
|
|
202
|
+
const okCount = allResults.filter(
|
|
203
|
+
r => r.overallStatus === 'ok' || r.overallStatus === 'info'
|
|
204
|
+
).length;
|
|
161
205
|
|
|
162
206
|
console.log(chalk.gray('═'.repeat(60)));
|
|
163
207
|
console.log(chalk.blue('📊 健康统计:'));
|
|
@@ -171,7 +215,7 @@ async function showAllHealth(options = {}) {
|
|
|
171
215
|
console.log();
|
|
172
216
|
console.log(chalk.yellow('⚠️ 发现需要关注的问题:'));
|
|
173
217
|
|
|
174
|
-
allResults.forEach(
|
|
218
|
+
allResults.forEach(result => {
|
|
175
219
|
const hasIssue = result.overallStatus === 'error' || result.overallStatus === 'warning';
|
|
176
220
|
if (hasIssue) {
|
|
177
221
|
const issues = Object.entries(result.checks)
|
|
@@ -187,12 +231,12 @@ async function showAllHealth(options = {}) {
|
|
|
187
231
|
}
|
|
188
232
|
});
|
|
189
233
|
}
|
|
190
|
-
|
|
191
234
|
} catch (error) {
|
|
192
|
-
|
|
235
|
+
if (progressInterval) {
|
|
236
|
+
clearInterval(progressInterval);
|
|
237
|
+
}
|
|
193
238
|
Logger.error(`批量健康检查失败: ${error.message}`);
|
|
194
239
|
}
|
|
195
|
-
|
|
196
240
|
} catch (error) {
|
|
197
241
|
Logger.error(`健康检查执行失败: ${error.message}`);
|
|
198
242
|
throw error;
|
package/src/commands/list.js
CHANGED
|
@@ -8,7 +8,6 @@ const chalk = require('chalk');
|
|
|
8
8
|
const { configManager } = require('../config');
|
|
9
9
|
const { Logger } = require('../utils/logger');
|
|
10
10
|
const { ProviderStatusChecker } = require('../utils/provider-status-checker');
|
|
11
|
-
const { maybeMaskToken } = require('../utils/secrets');
|
|
12
11
|
const { AUTH_MODE_DISPLAY } = require('../constants');
|
|
13
12
|
|
|
14
13
|
/**
|
|
@@ -19,23 +18,20 @@ class ProviderLister {
|
|
|
19
18
|
/**
|
|
20
19
|
* 创建供应商列表显示器实例
|
|
21
20
|
*/
|
|
22
|
-
constructor() {
|
|
23
|
-
this.configManager =
|
|
24
|
-
this.statusChecker =
|
|
21
|
+
constructor(manager = configManager, statusChecker = new ProviderStatusChecker()) {
|
|
22
|
+
this.configManager = manager;
|
|
23
|
+
this.statusChecker = statusChecker;
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
/**
|
|
28
27
|
* 列出供应商配置
|
|
29
28
|
* @param {string|null} filter - 过滤器 ('codex', 'claude', 或 null 表示全部)
|
|
30
29
|
* @param {Object} options - 显示选项
|
|
31
|
-
* @param {boolean} [options.showToken=true] - 是否显示完整 token
|
|
32
30
|
* @param {boolean} [options.checkStatus=false] - 是否检测在线状态
|
|
33
31
|
* @returns {Promise<void>}
|
|
34
32
|
*/
|
|
35
33
|
async list(filter = null, options = {}) {
|
|
36
34
|
try {
|
|
37
|
-
// 默认显示完整 token,不再加密
|
|
38
|
-
const showToken = options.showToken !== false;
|
|
39
35
|
const checkStatus = options.checkStatus === true;
|
|
40
36
|
await this.configManager.ensureLoaded();
|
|
41
37
|
let providers = this.configManager.listProviders();
|
|
@@ -61,7 +57,23 @@ class ProviderLister {
|
|
|
61
57
|
return;
|
|
62
58
|
}
|
|
63
59
|
|
|
64
|
-
|
|
60
|
+
if (options.json) {
|
|
61
|
+
console.log(
|
|
62
|
+
JSON.stringify(
|
|
63
|
+
{
|
|
64
|
+
currentProvider: currentProvider?.name || null,
|
|
65
|
+
providers,
|
|
66
|
+
status: checkStatus ? statusMap : undefined
|
|
67
|
+
},
|
|
68
|
+
null,
|
|
69
|
+
2
|
|
70
|
+
)
|
|
71
|
+
);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const titleSuffix =
|
|
76
|
+
filter === 'codex' ? ' (Codex CLI)' : filter === 'claude' ? ' (Claude Code)' : '';
|
|
65
77
|
console.log(chalk.blue(`\n📋 供应商列表${titleSuffix}:`));
|
|
66
78
|
console.log(chalk.gray('═'.repeat(60)));
|
|
67
79
|
|
|
@@ -71,20 +83,27 @@ class ProviderLister {
|
|
|
71
83
|
const nameColor = isCurrent ? chalk.green : chalk.white;
|
|
72
84
|
|
|
73
85
|
// IDE 类型标签
|
|
74
|
-
const ideTag =
|
|
75
|
-
? chalk.cyan('[Codex]')
|
|
76
|
-
: chalk.magenta('[Claude]');
|
|
86
|
+
const ideTag =
|
|
87
|
+
provider.ideName === 'codex' ? chalk.cyan('[Codex]') : chalk.magenta('[Claude]');
|
|
77
88
|
|
|
78
89
|
// 如果有别名,显示别名
|
|
79
90
|
const aliasText = provider.alias ? chalk.yellow(` [别名: ${provider.alias}]`) : '';
|
|
80
91
|
|
|
81
92
|
if (checkStatus) {
|
|
82
|
-
const availability = statusMap[provider.name] || {
|
|
93
|
+
const availability = statusMap[provider.name] || {
|
|
94
|
+
state: 'unknown',
|
|
95
|
+
label: '未知',
|
|
96
|
+
latency: null
|
|
97
|
+
};
|
|
83
98
|
const availabilityIcon = this._iconForState(availability.state);
|
|
84
99
|
const availabilityText = this._formatAvailability(availability);
|
|
85
|
-
console.log(
|
|
100
|
+
console.log(
|
|
101
|
+
`${status} ${availabilityIcon} ${ideTag} ${nameColor(provider.name)} (${provider.displayName})${aliasText} - ${availabilityText}`
|
|
102
|
+
);
|
|
86
103
|
} else {
|
|
87
|
-
console.log(
|
|
104
|
+
console.log(
|
|
105
|
+
`${status} ${ideTag} ${nameColor(provider.name)} (${provider.displayName})${aliasText}`
|
|
106
|
+
);
|
|
88
107
|
}
|
|
89
108
|
|
|
90
109
|
if (provider.ideName === 'codex') {
|
|
@@ -93,11 +112,13 @@ class ProviderLister {
|
|
|
93
112
|
console.log(chalk.gray(` OPENAI_BASE_URL: ${provider.baseUrl}`));
|
|
94
113
|
}
|
|
95
114
|
if (provider.authToken) {
|
|
96
|
-
console.log(chalk.gray(` OPENAI_API_KEY: ${
|
|
115
|
+
console.log(chalk.gray(` OPENAI_API_KEY: ${provider.authToken}`));
|
|
97
116
|
}
|
|
98
117
|
} else {
|
|
99
118
|
// 显示认证模式
|
|
100
|
-
console.log(
|
|
119
|
+
console.log(
|
|
120
|
+
chalk.gray(` 认证模式: ${AUTH_MODE_DISPLAY[provider.authMode] || provider.authMode}`)
|
|
121
|
+
);
|
|
101
122
|
|
|
102
123
|
// 根据不同模式显示对应的环境变量名称
|
|
103
124
|
if (provider.authMode === 'auth_token') {
|
|
@@ -105,7 +126,7 @@ class ProviderLister {
|
|
|
105
126
|
console.log(chalk.gray(` ANTHROPIC_BASE_URL: ${provider.baseUrl}`));
|
|
106
127
|
}
|
|
107
128
|
if (provider.authToken) {
|
|
108
|
-
console.log(chalk.gray(` ANTHROPIC_AUTH_TOKEN: ${
|
|
129
|
+
console.log(chalk.gray(` ANTHROPIC_AUTH_TOKEN: ${provider.authToken}`));
|
|
109
130
|
}
|
|
110
131
|
} else {
|
|
111
132
|
// API Key 模式(默认)
|
|
@@ -113,7 +134,7 @@ class ProviderLister {
|
|
|
113
134
|
console.log(chalk.gray(` ANTHROPIC_BASE_URL: ${provider.baseUrl}`));
|
|
114
135
|
}
|
|
115
136
|
if (provider.authToken) {
|
|
116
|
-
console.log(chalk.gray(` ANTHROPIC_API_KEY: ${
|
|
137
|
+
console.log(chalk.gray(` ANTHROPIC_API_KEY: ${provider.authToken}`));
|
|
117
138
|
}
|
|
118
139
|
}
|
|
119
140
|
}
|
|
@@ -142,7 +163,6 @@ class ProviderLister {
|
|
|
142
163
|
}
|
|
143
164
|
|
|
144
165
|
console.log(chalk.blue(`\n总计: ${providers.length} 个供应商`));
|
|
145
|
-
|
|
146
166
|
} catch (error) {
|
|
147
167
|
Logger.error(`获取供应商列表失败: ${error.message}`);
|
|
148
168
|
throw error;
|
package/src/commands/remove.js
CHANGED
|
@@ -99,11 +99,11 @@ class ProviderRemover extends BaseCommand {
|
|
|
99
99
|
}));
|
|
100
100
|
|
|
101
101
|
// 设置 ESC 键监听
|
|
102
|
-
const escListener = this.createESCListener(() => {
|
|
102
|
+
const escListener = this.createESCListener(async () => {
|
|
103
103
|
Logger.info('取消删除供应商');
|
|
104
104
|
// 使用CommandRegistry避免循环引用
|
|
105
105
|
const { registry } = require('../CommandRegistry');
|
|
106
|
-
registry.executeCommand('switch');
|
|
106
|
+
await registry.executeCommand('switch');
|
|
107
107
|
}, '取消删除');
|
|
108
108
|
|
|
109
109
|
try {
|