@pikecode/api-key-manager 2.0.0 → 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 +444 -151
- package/bin/akm.js +340 -11
- package/package.json +29 -12
- package/src/CommandRegistry.js +58 -3
- package/src/commands/BaseCommand.js +68 -1
- package/src/commands/add/prompts.js +280 -0
- package/src/commands/add/providerSaver.js +74 -0
- package/src/commands/add/summaryPrinter.js +29 -0
- package/src/commands/add.js +54 -439
- package/src/commands/backup.js +396 -0
- package/src/commands/batch.js +313 -0
- package/src/commands/benchmark.js +323 -0
- package/src/commands/claude-clean.js +253 -0
- package/src/commands/clone.js +265 -0
- package/src/commands/current.js +89 -41
- package/src/commands/edit.js +3 -207
- package/src/commands/health.js +264 -0
- package/src/commands/list.js +120 -35
- package/src/commands/mcp.js +467 -0
- package/src/commands/remove.js +89 -26
- package/src/commands/stats.js +281 -0
- package/src/commands/switch/claude-settings-compatibility.js +113 -0
- package/src/commands/switch/launch-args-helper.js +84 -0
- package/src/commands/switch/provider-choices-helper.js +72 -0
- package/src/commands/switch/provider-details-helper.js +46 -0
- package/src/commands/switch/provider-edit-questions-helper.js +124 -0
- package/src/commands/switch/provider-launcher.js +20 -0
- package/src/commands/switch/provider-manager.js +214 -0
- package/src/commands/switch/status-helper.js +124 -0
- package/src/commands/switch/ui-screen-renderer.js +77 -0
- package/src/commands/switch.js +471 -958
- package/src/commands/validate.js +310 -0
- package/src/config.js +541 -55
- package/src/constants/index.js +234 -0
- package/src/constants/ui.js +108 -0
- package/src/index.js +11 -4
- package/src/navigation/EscNavigationManager.js +5 -5
- package/src/utils/atomic-file.js +47 -0
- package/src/utils/claude-settings.js +4 -4
- package/src/utils/codex-files.js +418 -0
- package/src/utils/codex-launcher.js +104 -0
- package/src/utils/concurrency.js +30 -0
- package/src/utils/config-opener.js +22 -2
- package/src/utils/env-launcher.js +50 -44
- package/src/utils/env-utils.js +52 -0
- package/src/utils/error-handler.js +27 -28
- package/src/utils/health-checker.js +350 -0
- package/src/utils/import-validator.js +210 -0
- package/src/utils/inquirer-setup.js +11 -0
- package/src/utils/launch-args.js +155 -0
- package/src/utils/logger.js +0 -1
- package/src/utils/provider-status-checker.js +211 -64
- package/src/utils/secrets.js +22 -0
- package/src/utils/shell-snippets.js +32 -0
- package/src/utils/terminal-format.js +22 -4
- package/src/utils/ui-helper.js +96 -86
- package/src/utils/update-checker.js +41 -12
- package/src/utils/validator.js +115 -88
- package/bin/cc.js +0 -101
- package/src/utils/storage.js +0 -55
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Health Check Command
|
|
3
|
+
* 配置健康检查和告警
|
|
4
|
+
* @module commands/health
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const chalk = require('chalk');
|
|
8
|
+
const { configManager } = require('../config');
|
|
9
|
+
const { Logger } = require('../utils/logger');
|
|
10
|
+
const { HealthChecker } = require('../utils/health-checker');
|
|
11
|
+
const { mapWithConcurrency } = require('../utils/concurrency');
|
|
12
|
+
const { UIHelper } = require('../utils/ui-helper');
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 显示单个供应商的健康检查
|
|
16
|
+
* @param {string} providerName - 供应商名称或别名
|
|
17
|
+
* @param {Object} options - 选项
|
|
18
|
+
*/
|
|
19
|
+
async function showProviderHealth(providerName, options = {}) {
|
|
20
|
+
try {
|
|
21
|
+
await configManager.ensureLoaded();
|
|
22
|
+
|
|
23
|
+
// 支持别名查找
|
|
24
|
+
let provider = configManager.getProvider(providerName);
|
|
25
|
+
if (!provider) {
|
|
26
|
+
provider = configManager.getProviderByNameOrAlias(providerName);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (!provider) {
|
|
30
|
+
Logger.error(`供应商 '${providerName}' 不存在`);
|
|
31
|
+
Logger.info('使用 "akm list" 查看所有已配置的供应商');
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
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
|
+
}
|
|
40
|
+
|
|
41
|
+
const checker = new HealthChecker();
|
|
42
|
+
const loadingInterval = options.json ? null : UIHelper.createLoadingAnimation('检查中...');
|
|
43
|
+
|
|
44
|
+
try {
|
|
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
|
+
}
|
|
57
|
+
|
|
58
|
+
console.log(checker.formatHealthReport(results));
|
|
59
|
+
console.log();
|
|
60
|
+
|
|
61
|
+
// 如果有问题,显示建议
|
|
62
|
+
if (results.overallStatus === 'error' || results.overallStatus === 'warning') {
|
|
63
|
+
console.log(chalk.yellow('💡 建议操作:'));
|
|
64
|
+
|
|
65
|
+
if (
|
|
66
|
+
results.checks.tokenExpiry?.status === 'expired' ||
|
|
67
|
+
results.checks.tokenExpiry?.status === 'critical'
|
|
68
|
+
) {
|
|
69
|
+
console.log(chalk.yellow(' • 使用 "akm edit" 更新 Token'));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (
|
|
73
|
+
results.checks.quota?.status === 'exceeded' ||
|
|
74
|
+
results.checks.quota?.status === 'critical'
|
|
75
|
+
) {
|
|
76
|
+
console.log(chalk.yellow(' • 检查 API 配额使用情况'));
|
|
77
|
+
console.log(chalk.yellow(' • 考虑升级套餐或添加新的供应商'));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (results.checks.connectivity?.status === 'offline') {
|
|
81
|
+
console.log(chalk.yellow(' • 检查网络连接'));
|
|
82
|
+
console.log(chalk.yellow(' • 验证 Token 是否正确'));
|
|
83
|
+
console.log(chalk.yellow(' • 使用 "akm validate" 进行详细诊断'));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (results.checks.lastUsed?.status === 'stale') {
|
|
87
|
+
console.log(chalk.yellow(' • 考虑删除长期未使用的配置'));
|
|
88
|
+
console.log(chalk.yellow(' • 或运行一次验证确保仍然可用'));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
console.log();
|
|
92
|
+
}
|
|
93
|
+
} catch (error) {
|
|
94
|
+
if (loadingInterval) {
|
|
95
|
+
UIHelper.clearLoadingAnimation(loadingInterval);
|
|
96
|
+
}
|
|
97
|
+
Logger.error(`健康检查失败: ${error.message}`);
|
|
98
|
+
}
|
|
99
|
+
} catch (error) {
|
|
100
|
+
Logger.error(`健康检查执行失败: ${error.message}`);
|
|
101
|
+
throw error;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* 显示所有供应商的健康检查
|
|
107
|
+
* @param {Object} options - 选项
|
|
108
|
+
*/
|
|
109
|
+
async function showAllHealth(options = {}) {
|
|
110
|
+
try {
|
|
111
|
+
await configManager.ensureLoaded();
|
|
112
|
+
let providers = configManager.listProviders();
|
|
113
|
+
|
|
114
|
+
// 应用过滤器
|
|
115
|
+
if (options.filter === 'codex') {
|
|
116
|
+
providers = providers.filter(p => p.ideName === 'codex');
|
|
117
|
+
} else if (options.filter === 'claude') {
|
|
118
|
+
providers = providers.filter(p => p.ideName !== 'codex');
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (providers.length === 0) {
|
|
122
|
+
if (options.filter) {
|
|
123
|
+
const filterName = options.filter === 'codex' ? 'Codex CLI' : 'Claude Code';
|
|
124
|
+
Logger.warning(`暂无 ${filterName} 供应商配置`);
|
|
125
|
+
} else {
|
|
126
|
+
Logger.warning('暂无配置的供应商');
|
|
127
|
+
}
|
|
128
|
+
Logger.info('请使用 "akm add" 添加供应商配置');
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
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
|
+
}
|
|
143
|
+
|
|
144
|
+
const checker = new HealthChecker();
|
|
145
|
+
const allResults = [];
|
|
146
|
+
let completedCount = 0;
|
|
147
|
+
const total = providers.length;
|
|
148
|
+
|
|
149
|
+
// 创建进度显示
|
|
150
|
+
const progressInterval = options.json
|
|
151
|
+
? null
|
|
152
|
+
: setInterval(() => {
|
|
153
|
+
process.stdout.write(`\r检查中... ${completedCount}/${total}`);
|
|
154
|
+
}, 100);
|
|
155
|
+
|
|
156
|
+
try {
|
|
157
|
+
// 并行检查所有供应商
|
|
158
|
+
const results = await mapWithConcurrency(providers, 4, async provider => {
|
|
159
|
+
const providerResults = await checker.performHealthCheck(provider, {
|
|
160
|
+
checkConnectivity: options.connectivity === true || options.checkConnectivity === true
|
|
161
|
+
});
|
|
162
|
+
completedCount++;
|
|
163
|
+
return providerResults;
|
|
164
|
+
});
|
|
165
|
+
if (progressInterval) {
|
|
166
|
+
clearInterval(progressInterval);
|
|
167
|
+
process.stdout.write('\r' + ' '.repeat(50) + '\r'); // 清除进度显示
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
allResults.push(...results);
|
|
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
|
+
|
|
186
|
+
// 显示结果
|
|
187
|
+
const currentProvider = configManager.getCurrentProvider();
|
|
188
|
+
|
|
189
|
+
results.forEach((result, index) => {
|
|
190
|
+
const provider = providers[index];
|
|
191
|
+
const isCurrent = provider.name === currentProvider?.name;
|
|
192
|
+
console.log(checker.formatHealthReport(result));
|
|
193
|
+
if (isCurrent) {
|
|
194
|
+
console.log(chalk.green(' (当前活跃)'));
|
|
195
|
+
}
|
|
196
|
+
console.log();
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
// 显示统计
|
|
200
|
+
const errorCount = allResults.filter(r => r.overallStatus === 'error').length;
|
|
201
|
+
const warningCount = allResults.filter(r => r.overallStatus === 'warning').length;
|
|
202
|
+
const okCount = allResults.filter(
|
|
203
|
+
r => r.overallStatus === 'ok' || r.overallStatus === 'info'
|
|
204
|
+
).length;
|
|
205
|
+
|
|
206
|
+
console.log(chalk.gray('═'.repeat(60)));
|
|
207
|
+
console.log(chalk.blue('📊 健康统计:'));
|
|
208
|
+
console.log(` 总计: ${total} 个供应商`);
|
|
209
|
+
console.log(` ${chalk.green('✓')} 健康: ${okCount}`);
|
|
210
|
+
console.log(` ${chalk.yellow('⚠')} 警告: ${warningCount}`);
|
|
211
|
+
console.log(` ${chalk.red('✗')} 错误: ${errorCount}`);
|
|
212
|
+
|
|
213
|
+
// 显示需要关注的问题
|
|
214
|
+
if (errorCount > 0 || warningCount > 0) {
|
|
215
|
+
console.log();
|
|
216
|
+
console.log(chalk.yellow('⚠️ 发现需要关注的问题:'));
|
|
217
|
+
|
|
218
|
+
allResults.forEach(result => {
|
|
219
|
+
const hasIssue = result.overallStatus === 'error' || result.overallStatus === 'warning';
|
|
220
|
+
if (hasIssue) {
|
|
221
|
+
const issues = Object.entries(result.checks)
|
|
222
|
+
.filter(([_, check]) => check.level === 'error' || check.level === 'warning')
|
|
223
|
+
.map(([name, check]) => `${checker._getCheckLabel(name)}: ${check.message}`);
|
|
224
|
+
|
|
225
|
+
if (issues.length > 0) {
|
|
226
|
+
console.log(chalk.yellow(` • ${result.displayName}:`));
|
|
227
|
+
issues.forEach(issue => {
|
|
228
|
+
console.log(chalk.yellow(` - ${issue}`));
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
} catch (error) {
|
|
235
|
+
if (progressInterval) {
|
|
236
|
+
clearInterval(progressInterval);
|
|
237
|
+
}
|
|
238
|
+
Logger.error(`批量健康检查失败: ${error.message}`);
|
|
239
|
+
}
|
|
240
|
+
} catch (error) {
|
|
241
|
+
Logger.error(`健康检查执行失败: ${error.message}`);
|
|
242
|
+
throw error;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* 健康检查命令
|
|
248
|
+
* @param {string|null} providerName - 供应商名称
|
|
249
|
+
* @param {Object} options - 选项
|
|
250
|
+
*/
|
|
251
|
+
async function healthCommand(providerName, options = {}) {
|
|
252
|
+
try {
|
|
253
|
+
if (providerName) {
|
|
254
|
+
await showProviderHealth(providerName, options);
|
|
255
|
+
} else {
|
|
256
|
+
await showAllHealth(options);
|
|
257
|
+
}
|
|
258
|
+
} catch (error) {
|
|
259
|
+
Logger.error(`健康检查失败: ${error.message}`);
|
|
260
|
+
throw error;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
module.exports = { healthCommand };
|
package/src/commands/list.js
CHANGED
|
@@ -1,58 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider Lister Command
|
|
3
|
+
* 列出和显示所有配置的供应商
|
|
4
|
+
* @module commands/list
|
|
5
|
+
*/
|
|
6
|
+
|
|
1
7
|
const chalk = require('chalk');
|
|
2
|
-
const {
|
|
8
|
+
const { configManager } = require('../config');
|
|
3
9
|
const { Logger } = require('../utils/logger');
|
|
4
10
|
const { ProviderStatusChecker } = require('../utils/provider-status-checker');
|
|
11
|
+
const { AUTH_MODE_DISPLAY } = require('../constants');
|
|
5
12
|
|
|
13
|
+
/**
|
|
14
|
+
* 供应商列表显示类
|
|
15
|
+
* 用于列出、过滤和显示所有配置的 API 供应商
|
|
16
|
+
*/
|
|
6
17
|
class ProviderLister {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
18
|
+
/**
|
|
19
|
+
* 创建供应商列表显示器实例
|
|
20
|
+
*/
|
|
21
|
+
constructor(manager = configManager, statusChecker = new ProviderStatusChecker()) {
|
|
22
|
+
this.configManager = manager;
|
|
23
|
+
this.statusChecker = statusChecker;
|
|
10
24
|
}
|
|
11
25
|
|
|
12
|
-
|
|
26
|
+
/**
|
|
27
|
+
* 列出供应商配置
|
|
28
|
+
* @param {string|null} filter - 过滤器 ('codex', 'claude', 或 null 表示全部)
|
|
29
|
+
* @param {Object} options - 显示选项
|
|
30
|
+
* @param {boolean} [options.checkStatus=false] - 是否检测在线状态
|
|
31
|
+
* @returns {Promise<void>}
|
|
32
|
+
*/
|
|
33
|
+
async list(filter = null, options = {}) {
|
|
13
34
|
try {
|
|
35
|
+
const checkStatus = options.checkStatus === true;
|
|
14
36
|
await this.configManager.ensureLoaded();
|
|
15
|
-
|
|
37
|
+
let providers = this.configManager.listProviders();
|
|
16
38
|
const currentProvider = this.configManager.getCurrentProvider();
|
|
17
|
-
|
|
39
|
+
|
|
40
|
+
// 应用过滤器
|
|
41
|
+
if (filter === 'codex') {
|
|
42
|
+
providers = providers.filter(p => p.ideName === 'codex');
|
|
43
|
+
} else if (filter === 'claude') {
|
|
44
|
+
providers = providers.filter(p => p.ideName !== 'codex');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const statusMap = checkStatus ? await this.statusChecker.checkAll(providers) : {};
|
|
18
48
|
|
|
19
49
|
if (providers.length === 0) {
|
|
20
|
-
|
|
50
|
+
if (filter) {
|
|
51
|
+
const filterName = filter === 'codex' ? 'Codex CLI' : 'Claude Code';
|
|
52
|
+
Logger.warning(`暂无 ${filterName} 供应商配置`);
|
|
53
|
+
} else {
|
|
54
|
+
Logger.warning('暂无配置的供应商');
|
|
55
|
+
}
|
|
21
56
|
Logger.info('请使用 "akm add" 添加供应商配置');
|
|
22
57
|
return;
|
|
23
58
|
}
|
|
24
59
|
|
|
25
|
-
|
|
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)' : '';
|
|
77
|
+
console.log(chalk.blue(`\n📋 供应商列表${titleSuffix}:`));
|
|
26
78
|
console.log(chalk.gray('═'.repeat(60)));
|
|
27
79
|
|
|
28
80
|
providers.forEach((provider, index) => {
|
|
29
81
|
const isCurrent = provider.name === currentProvider?.name;
|
|
30
82
|
const status = isCurrent ? '✅' : '🔹';
|
|
31
|
-
const availability = statusMap[provider.name] || { state: 'unknown', label: '未知', latency: null };
|
|
32
|
-
const availabilityIcon = this._iconForState(availability.state);
|
|
33
|
-
const availabilityText = this._formatAvailability(availability);
|
|
34
83
|
const nameColor = isCurrent ? chalk.green : chalk.white;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
84
|
+
|
|
85
|
+
// IDE 类型标签
|
|
86
|
+
const ideTag =
|
|
87
|
+
provider.ideName === 'codex' ? chalk.cyan('[Codex]') : chalk.magenta('[Claude]');
|
|
88
|
+
|
|
89
|
+
// 如果有别名,显示别名
|
|
90
|
+
const aliasText = provider.alias ? chalk.yellow(` [别名: ${provider.alias}]`) : '';
|
|
91
|
+
|
|
92
|
+
if (checkStatus) {
|
|
93
|
+
const availability = statusMap[provider.name] || {
|
|
94
|
+
state: 'unknown',
|
|
95
|
+
label: '未知',
|
|
96
|
+
latency: null
|
|
97
|
+
};
|
|
98
|
+
const availabilityIcon = this._iconForState(availability.state);
|
|
99
|
+
const availabilityText = this._formatAvailability(availability);
|
|
100
|
+
console.log(
|
|
101
|
+
`${status} ${availabilityIcon} ${ideTag} ${nameColor(provider.name)} (${provider.displayName})${aliasText} - ${availabilityText}`
|
|
102
|
+
);
|
|
103
|
+
} else {
|
|
104
|
+
console.log(
|
|
105
|
+
`${status} ${ideTag} ${nameColor(provider.name)} (${provider.displayName})${aliasText}`
|
|
106
|
+
);
|
|
50
107
|
}
|
|
51
108
|
|
|
52
|
-
if (provider.
|
|
53
|
-
console.log(chalk.gray(
|
|
109
|
+
if (provider.ideName === 'codex') {
|
|
110
|
+
console.log(chalk.gray(' IDE: Codex CLI'));
|
|
111
|
+
if (provider.baseUrl) {
|
|
112
|
+
console.log(chalk.gray(` OPENAI_BASE_URL: ${provider.baseUrl}`));
|
|
113
|
+
}
|
|
114
|
+
if (provider.authToken) {
|
|
115
|
+
console.log(chalk.gray(` OPENAI_API_KEY: ${provider.authToken}`));
|
|
116
|
+
}
|
|
117
|
+
} else {
|
|
118
|
+
// 显示认证模式
|
|
119
|
+
console.log(
|
|
120
|
+
chalk.gray(` 认证模式: ${AUTH_MODE_DISPLAY[provider.authMode] || provider.authMode}`)
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
// 根据不同模式显示对应的环境变量名称
|
|
124
|
+
if (provider.authMode === 'auth_token') {
|
|
125
|
+
if (provider.baseUrl) {
|
|
126
|
+
console.log(chalk.gray(` ANTHROPIC_BASE_URL: ${provider.baseUrl}`));
|
|
127
|
+
}
|
|
128
|
+
if (provider.authToken) {
|
|
129
|
+
console.log(chalk.gray(` ANTHROPIC_AUTH_TOKEN: ${provider.authToken}`));
|
|
130
|
+
}
|
|
131
|
+
} else {
|
|
132
|
+
// API Key 模式(默认)
|
|
133
|
+
if (provider.baseUrl) {
|
|
134
|
+
console.log(chalk.gray(` ANTHROPIC_BASE_URL: ${provider.baseUrl}`));
|
|
135
|
+
}
|
|
136
|
+
if (provider.authToken) {
|
|
137
|
+
console.log(chalk.gray(` ANTHROPIC_API_KEY: ${provider.authToken}`));
|
|
138
|
+
}
|
|
139
|
+
}
|
|
54
140
|
}
|
|
55
|
-
|
|
141
|
+
|
|
56
142
|
if (provider.launchArgs && provider.launchArgs.length > 0) {
|
|
57
143
|
console.log(chalk.gray(` 启动参数: ${provider.launchArgs.join(' ')}`));
|
|
58
144
|
}
|
|
@@ -62,14 +148,14 @@ class ProviderLister {
|
|
|
62
148
|
}
|
|
63
149
|
console.log(chalk.gray(` 创建时间: ${new Date(provider.createdAt).toLocaleString()}`));
|
|
64
150
|
console.log(chalk.gray(` 最后使用: ${new Date(provider.lastUsed).toLocaleString()}`));
|
|
65
|
-
|
|
151
|
+
|
|
66
152
|
if (index < providers.length - 1) {
|
|
67
153
|
console.log(chalk.gray('─'.repeat(60)));
|
|
68
154
|
}
|
|
69
155
|
});
|
|
70
156
|
|
|
71
157
|
console.log(chalk.gray('═'.repeat(60)));
|
|
72
|
-
|
|
158
|
+
|
|
73
159
|
if (currentProvider) {
|
|
74
160
|
console.log(chalk.green(`\n当前供应商: ${currentProvider.displayName}`));
|
|
75
161
|
} else {
|
|
@@ -77,7 +163,6 @@ class ProviderLister {
|
|
|
77
163
|
}
|
|
78
164
|
|
|
79
165
|
console.log(chalk.blue(`\n总计: ${providers.length} 个供应商`));
|
|
80
|
-
|
|
81
166
|
} catch (error) {
|
|
82
167
|
Logger.error(`获取供应商列表失败: ${error.message}`);
|
|
83
168
|
throw error;
|
|
@@ -114,9 +199,9 @@ class ProviderLister {
|
|
|
114
199
|
}
|
|
115
200
|
}
|
|
116
201
|
|
|
117
|
-
async function listCommand() {
|
|
202
|
+
async function listCommand(filter = null, options = {}) {
|
|
118
203
|
const lister = new ProviderLister();
|
|
119
|
-
await lister.list();
|
|
204
|
+
await lister.list(filter, options);
|
|
120
205
|
}
|
|
121
206
|
|
|
122
207
|
module.exports = { listCommand, ProviderLister };
|