@pikecode/api-key-manager 1.2.0 → 1.3.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/bin/akm.js +0 -0
- package/package.json +1 -1
- package/src/commands/BaseCommand.js +1 -1
- package/src/commands/add/prompts.js +2 -13
- package/src/commands/add.js +1 -33
- package/src/commands/backup.js +0 -1
- package/src/commands/batch.js +65 -66
- package/src/commands/benchmark.js +0 -21
- package/src/commands/current.js +1 -1
- package/src/commands/edit.js +0 -1
- package/src/commands/health.js +0 -2
- package/src/commands/list.js +1 -1
- package/src/commands/remove.js +0 -1
- package/src/commands/stats.js +1 -2
- package/src/commands/switch/claude-settings-compatibility.js +113 -0
- package/src/commands/switch/provider-choices-helper.js +71 -0
- package/src/commands/switch/provider-details-helper.js +46 -0
- package/src/commands/switch/provider-edit-questions-helper.js +102 -0
- package/src/commands/switch/provider-launcher.js +20 -0
- package/src/commands/switch.js +110 -452
- package/src/commands/validate.js +17 -17
- package/src/config.js +28 -0
- package/src/navigation/EscNavigationManager.js +5 -5
- package/src/utils/codex-launcher.js +3 -0
- package/src/utils/env-utils.js +2 -2
- package/src/utils/error-handler.js +0 -1
- package/src/utils/health-checker.js +34 -34
- package/src/utils/logger.js +0 -1
- package/src/utils/provider-status-checker.js +10 -41
- package/src/utils/update-checker.js +6 -1
- package/src/utils/validator.js +1 -1
- package/src/commands/add/codexImporter.js +0 -48
package/bin/akm.js
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -32,17 +32,6 @@ async function promptProviderInfo(adder) {
|
|
|
32
32
|
default: adder.presetIdeName || 'claude',
|
|
33
33
|
when: () => !adder.presetIdeName
|
|
34
34
|
},
|
|
35
|
-
{
|
|
36
|
-
type: 'list',
|
|
37
|
-
name: 'importFromExisting',
|
|
38
|
-
message: UI_MESSAGES.IMPORT_FROM_CODEX,
|
|
39
|
-
choices: [
|
|
40
|
-
{ name: UI_MESSAGES.IMPORT_FROM_CODEX_EXISTING, value: 'import' },
|
|
41
|
-
{ name: UI_MESSAGES.IMPORT_FROM_CODEX_MANUAL, value: 'manual' }
|
|
42
|
-
],
|
|
43
|
-
default: 'import',
|
|
44
|
-
when: (answers) => (answers.ideName || adder.presetIdeName) === 'codex'
|
|
45
|
-
},
|
|
46
35
|
{
|
|
47
36
|
type: 'input',
|
|
48
37
|
name: 'name',
|
|
@@ -98,7 +87,7 @@ async function promptProviderInfo(adder) {
|
|
|
98
87
|
const err = validator.validateUrl(input);
|
|
99
88
|
return err || true;
|
|
100
89
|
},
|
|
101
|
-
when: (answers) => (answers.ideName || adder.presetIdeName) === 'codex'
|
|
90
|
+
when: (answers) => (answers.ideName || adder.presetIdeName) === 'codex'
|
|
102
91
|
},
|
|
103
92
|
{
|
|
104
93
|
type: 'input',
|
|
@@ -109,7 +98,7 @@ async function promptProviderInfo(adder) {
|
|
|
109
98
|
const err = validator.validateToken(input);
|
|
110
99
|
return err || true;
|
|
111
100
|
},
|
|
112
|
-
when: (answers) => (answers.ideName || adder.presetIdeName) === 'codex'
|
|
101
|
+
when: (answers) => (answers.ideName || adder.presetIdeName) === 'codex'
|
|
113
102
|
},
|
|
114
103
|
{
|
|
115
104
|
type: 'confirm',
|
package/src/commands/add.js
CHANGED
|
@@ -4,17 +4,12 @@
|
|
|
4
4
|
* @module commands/add
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
const inquirer = require('inquirer');
|
|
8
|
-
const chalk = require('chalk');
|
|
9
7
|
const { configManager } = require('../config');
|
|
10
|
-
const { validator } = require('../utils/validator');
|
|
11
8
|
const { Logger } = require('../utils/logger');
|
|
12
9
|
const { UIHelper } = require('../utils/ui-helper');
|
|
13
10
|
const { BaseCommand } = require('./BaseCommand');
|
|
14
|
-
const { promptProviderInfo,
|
|
15
|
-
const { importCodexConfig } = require('./add/codexImporter');
|
|
11
|
+
const { promptProviderInfo, promptCodexLaunchArgs } = require('./add/prompts');
|
|
16
12
|
const { saveProvider } = require('./add/providerSaver');
|
|
17
|
-
const { printProviderSummary } = require('./add/summaryPrinter');
|
|
18
13
|
|
|
19
14
|
/**
|
|
20
15
|
* 供应商添加器类
|
|
@@ -73,33 +68,6 @@ class ProviderAdder extends BaseCommand {
|
|
|
73
68
|
answers.authMode = 'openai_api_key';
|
|
74
69
|
answers.codexFiles = null;
|
|
75
70
|
|
|
76
|
-
// 从现有配置导入
|
|
77
|
-
if (answers.importFromExisting === 'import') {
|
|
78
|
-
const importedConfig = await importCodexConfig();
|
|
79
|
-
if (importedConfig) {
|
|
80
|
-
answers.authToken = importedConfig.apiKey;
|
|
81
|
-
answers.baseUrl = importedConfig.baseUrl;
|
|
82
|
-
} else {
|
|
83
|
-
Logger.warning('未能导入现有配置,请手动输入');
|
|
84
|
-
const manualAnswers = await this.prompt([
|
|
85
|
-
{
|
|
86
|
-
type: 'input',
|
|
87
|
-
name: 'baseUrl',
|
|
88
|
-
message: '请输入 OpenAI API 基础URL (如使用官方API可留空):',
|
|
89
|
-
default: ''
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
type: 'input',
|
|
93
|
-
name: 'authToken',
|
|
94
|
-
message: '请输入 OpenAI API Key (OPENAI_API_KEY):',
|
|
95
|
-
validate: (input) => input ? true : 'API Key 不能为空'
|
|
96
|
-
}
|
|
97
|
-
]);
|
|
98
|
-
answers.authToken = manualAnswers.authToken;
|
|
99
|
-
answers.baseUrl = manualAnswers.baseUrl;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
71
|
// Codex 启动参数配置
|
|
104
72
|
if (answers.configureCodexLaunchArgs) {
|
|
105
73
|
answers.launchArgs = await promptCodexLaunchArgs(this);
|
package/src/commands/backup.js
CHANGED
package/src/commands/batch.js
CHANGED
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
const chalk = require('chalk');
|
|
8
8
|
const { configManager } = require('../config');
|
|
9
9
|
const { Logger } = require('../utils/logger');
|
|
10
|
-
const { UIHelper } = require('../utils/ui-helper');
|
|
11
10
|
const inquirer = require('inquirer');
|
|
12
11
|
|
|
13
12
|
/**
|
|
@@ -31,7 +30,7 @@ async function batchUpdate(options = {}) {
|
|
|
31
30
|
return;
|
|
32
31
|
}
|
|
33
32
|
|
|
34
|
-
console.log(chalk.blue(
|
|
33
|
+
console.log(chalk.blue('\n📦 批量更新供应商配置'));
|
|
35
34
|
console.log(chalk.gray('═'.repeat(60)));
|
|
36
35
|
console.log();
|
|
37
36
|
|
|
@@ -67,62 +66,62 @@ async function batchUpdate(options = {}) {
|
|
|
67
66
|
for (const field of fields) {
|
|
68
67
|
let answer;
|
|
69
68
|
switch (field) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
return true;
|
|
69
|
+
case 'baseUrl':
|
|
70
|
+
answer = await inquirer.prompt([
|
|
71
|
+
{
|
|
72
|
+
type: 'input',
|
|
73
|
+
name: 'value',
|
|
74
|
+
message: '输入新的 Base URL (留空表示清除):',
|
|
75
|
+
validate: (input) => {
|
|
76
|
+
if (input && !input.startsWith('http://') && !input.startsWith('https://')) {
|
|
77
|
+
return 'Base URL 必须以 http:// 或 https:// 开头';
|
|
81
78
|
}
|
|
79
|
+
return true;
|
|
82
80
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
return true;
|
|
81
|
+
}
|
|
82
|
+
]);
|
|
83
|
+
updates.baseUrl = answer.value || null;
|
|
84
|
+
break;
|
|
85
|
+
|
|
86
|
+
case 'tokenExpiry':
|
|
87
|
+
answer = await inquirer.prompt([
|
|
88
|
+
{
|
|
89
|
+
type: 'input',
|
|
90
|
+
name: 'value',
|
|
91
|
+
message: '输入 Token 过期时间 (YYYY-MM-DD 格式, 留空表示清除):',
|
|
92
|
+
validate: (input) => {
|
|
93
|
+
if (input && !/^\d{4}-\d{2}-\d{2}$/.test(input)) {
|
|
94
|
+
return '请使用 YYYY-MM-DD 格式';
|
|
98
95
|
}
|
|
96
|
+
return true;
|
|
99
97
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
98
|
+
}
|
|
99
|
+
]);
|
|
100
|
+
updates.tokenExpiry = answer.value ? new Date(answer.value).toISOString() : null;
|
|
101
|
+
break;
|
|
102
|
+
|
|
103
|
+
case 'quotaLimit':
|
|
104
|
+
answer = await inquirer.prompt([
|
|
105
|
+
{
|
|
106
|
+
type: 'number',
|
|
107
|
+
name: 'value',
|
|
108
|
+
message: '输入配额限制 (数字, 0 表示清除):',
|
|
109
|
+
default: 0
|
|
110
|
+
}
|
|
111
|
+
]);
|
|
112
|
+
updates.quota = answer.value > 0 ? { limit: answer.value } : null;
|
|
113
|
+
break;
|
|
114
|
+
|
|
115
|
+
case 'launchArgs':
|
|
116
|
+
answer = await inquirer.prompt([
|
|
117
|
+
{
|
|
118
|
+
type: 'input',
|
|
119
|
+
name: 'value',
|
|
120
|
+
message: '输入启动参数 (空格分隔, 留空表示清除):'
|
|
121
|
+
}
|
|
122
|
+
]);
|
|
123
|
+
updates.launchArgs = answer.value ? answer.value.split(/\s+/).filter(Boolean) : [];
|
|
124
|
+
break;
|
|
126
125
|
}
|
|
127
126
|
}
|
|
128
127
|
|
|
@@ -218,7 +217,7 @@ async function batchDelete(options = {}) {
|
|
|
218
217
|
return;
|
|
219
218
|
}
|
|
220
219
|
|
|
221
|
-
console.log(chalk.blue(
|
|
220
|
+
console.log(chalk.blue('\n🗑️ 批量删除供应商'));
|
|
222
221
|
console.log(chalk.gray('═'.repeat(60)));
|
|
223
222
|
console.log();
|
|
224
223
|
|
|
@@ -247,11 +246,11 @@ async function batchDelete(options = {}) {
|
|
|
247
246
|
}
|
|
248
247
|
|
|
249
248
|
// 再次确认
|
|
250
|
-
|
|
249
|
+
await inquirer.prompt([
|
|
251
250
|
{
|
|
252
251
|
type: 'input',
|
|
253
252
|
name: 'confirmAgain',
|
|
254
|
-
message:
|
|
253
|
+
message: '请输入 "DELETE" 以确认删除:',
|
|
255
254
|
validate: (input) => {
|
|
256
255
|
if (input !== 'DELETE') {
|
|
257
256
|
return '请输入 "DELETE" 以确认';
|
|
@@ -295,15 +294,15 @@ async function batchDelete(options = {}) {
|
|
|
295
294
|
async function batchCommand(operation, options = {}) {
|
|
296
295
|
try {
|
|
297
296
|
switch (operation) {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
297
|
+
case 'update':
|
|
298
|
+
await batchUpdate(options);
|
|
299
|
+
break;
|
|
300
|
+
case 'delete':
|
|
301
|
+
await batchDelete(options);
|
|
302
|
+
break;
|
|
303
|
+
default:
|
|
304
|
+
Logger.error(`未知的批量操作: ${operation}`);
|
|
305
|
+
Logger.info('支持的操作: update, delete');
|
|
307
306
|
}
|
|
308
307
|
} catch (error) {
|
|
309
308
|
Logger.error(`批量操作失败: ${error.message}`);
|
|
@@ -11,7 +11,6 @@ const os = require('os');
|
|
|
11
11
|
const { configManager } = require('../config');
|
|
12
12
|
const { Logger } = require('../utils/logger');
|
|
13
13
|
const { ProviderStatusChecker } = require('../utils/provider-status-checker');
|
|
14
|
-
const { UIHelper } = require('../utils/ui-helper');
|
|
15
14
|
|
|
16
15
|
/**
|
|
17
16
|
* 性能测试器
|
|
@@ -290,29 +289,12 @@ async function benchmarkCommand(options = {}) {
|
|
|
290
289
|
|
|
291
290
|
const runner = new BenchmarkRunner();
|
|
292
291
|
|
|
293
|
-
let completedCount = 0;
|
|
294
|
-
const total = providers.length * rounds;
|
|
295
|
-
|
|
296
|
-
// 创建进度显示(仅在串行模式)
|
|
297
|
-
let progressInterval;
|
|
298
|
-
if (!parallel) {
|
|
299
|
-
progressInterval = setInterval(() => {
|
|
300
|
-
const percent = Math.round((completedCount / total) * 100);
|
|
301
|
-
process.stdout.write(`\r测试中... ${completedCount}/${total} (${percent}%)`);
|
|
302
|
-
}, 100);
|
|
303
|
-
}
|
|
304
|
-
|
|
305
292
|
try {
|
|
306
293
|
const results = await runner.runBenchmark(providers, {
|
|
307
294
|
rounds,
|
|
308
295
|
parallel
|
|
309
296
|
});
|
|
310
297
|
|
|
311
|
-
if (progressInterval) {
|
|
312
|
-
clearInterval(progressInterval);
|
|
313
|
-
process.stdout.write('\r' + ' '.repeat(50) + '\r');
|
|
314
|
-
}
|
|
315
|
-
|
|
316
298
|
// 显示结果
|
|
317
299
|
runner.displayResults(results);
|
|
318
300
|
|
|
@@ -329,9 +311,6 @@ async function benchmarkCommand(options = {}) {
|
|
|
329
311
|
}
|
|
330
312
|
|
|
331
313
|
} catch (error) {
|
|
332
|
-
if (progressInterval) {
|
|
333
|
-
clearInterval(progressInterval);
|
|
334
|
-
}
|
|
335
314
|
Logger.error(`性能测试失败: ${error.message}`);
|
|
336
315
|
}
|
|
337
316
|
|
package/src/commands/current.js
CHANGED
|
@@ -8,7 +8,7 @@ const chalk = require('chalk');
|
|
|
8
8
|
const { configManager } = require('../config');
|
|
9
9
|
const { Logger } = require('../utils/logger');
|
|
10
10
|
const { maybeMaskToken } = require('../utils/secrets');
|
|
11
|
-
const { AUTH_MODE_DISPLAY
|
|
11
|
+
const { AUTH_MODE_DISPLAY } = require('../constants');
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* 当前配置显示类
|
package/src/commands/edit.js
CHANGED
|
@@ -11,7 +11,6 @@ const { validator } = require('../utils/validator');
|
|
|
11
11
|
const { Logger } = require('../utils/logger');
|
|
12
12
|
const { UIHelper } = require('../utils/ui-helper');
|
|
13
13
|
const { BaseCommand } = require('./BaseCommand');
|
|
14
|
-
const { AUTH_MODE_DISPLAY, IDE_NAMES } = require('../constants');
|
|
15
14
|
|
|
16
15
|
/**
|
|
17
16
|
* 供应商编辑器类
|
package/src/commands/health.js
CHANGED
|
@@ -147,8 +147,6 @@ async function showAllHealth(options = {}) {
|
|
|
147
147
|
results.forEach((result, index) => {
|
|
148
148
|
const provider = providers[index];
|
|
149
149
|
const isCurrent = provider.name === currentProvider?.name;
|
|
150
|
-
const statusIcon = isCurrent ? '✅' : '🔹';
|
|
151
|
-
|
|
152
150
|
console.log(checker.formatHealthReport(result));
|
|
153
151
|
if (isCurrent) {
|
|
154
152
|
console.log(chalk.green(' (当前活跃)'));
|
package/src/commands/list.js
CHANGED
|
@@ -9,7 +9,7 @@ const { configManager } = require('../config');
|
|
|
9
9
|
const { Logger } = require('../utils/logger');
|
|
10
10
|
const { ProviderStatusChecker } = require('../utils/provider-status-checker');
|
|
11
11
|
const { maybeMaskToken } = require('../utils/secrets');
|
|
12
|
-
const { AUTH_MODE_DISPLAY
|
|
12
|
+
const { AUTH_MODE_DISPLAY } = require('../constants');
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* 供应商列表显示类
|
package/src/commands/remove.js
CHANGED
package/src/commands/stats.js
CHANGED
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
const chalk = require('chalk');
|
|
8
8
|
const { configManager } = require('../config');
|
|
9
9
|
const { Logger } = require('../utils/logger');
|
|
10
|
-
const { UIHelper } = require('../utils/ui-helper');
|
|
11
10
|
|
|
12
11
|
/**
|
|
13
12
|
* 格式化时长
|
|
@@ -171,7 +170,7 @@ async function showAllStats(options = {}) {
|
|
|
171
170
|
const currentProvider = configManager.getCurrentProvider();
|
|
172
171
|
|
|
173
172
|
// 显示表格
|
|
174
|
-
allStats.forEach((stats
|
|
173
|
+
allStats.forEach((stats) => {
|
|
175
174
|
const provider = configManager.getProvider(stats.name);
|
|
176
175
|
const isCurrent = provider.name === currentProvider?.name;
|
|
177
176
|
const statusIcon = isCurrent ? '✅' : '🔹';
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const { Logger } = require('../../utils/logger');
|
|
3
|
+
const { UIHelper } = require('../../utils/ui-helper');
|
|
4
|
+
const {
|
|
5
|
+
findSettingsConflict,
|
|
6
|
+
backupSettingsFile,
|
|
7
|
+
clearConflictKeys,
|
|
8
|
+
saveSettingsFile
|
|
9
|
+
} = require('../../utils/claude-settings');
|
|
10
|
+
|
|
11
|
+
async function ensureClaudeSettingsCompatibility(command, provider) {
|
|
12
|
+
const conflict = await findSettingsConflict();
|
|
13
|
+
if (!conflict) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const keyList = conflict.keys.map((key) => `• ${key}`).join('\n');
|
|
18
|
+
const backupDir = path.dirname(conflict.filePath);
|
|
19
|
+
|
|
20
|
+
command.clearScreen();
|
|
21
|
+
console.log(UIHelper.createTitle('检测到环境变量冲突', UIHelper.icons.warning));
|
|
22
|
+
console.log();
|
|
23
|
+
console.log(UIHelper.createCard('冲突文件', conflict.filePath, UIHelper.icons.info));
|
|
24
|
+
console.log();
|
|
25
|
+
console.log(UIHelper.createCard('备份目录', `${backupDir}\n备份文件将命名为 settings.backup-YYYYMMDD_HHmmss.json`, UIHelper.icons.info));
|
|
26
|
+
console.log();
|
|
27
|
+
console.log(UIHelper.createCard('可能覆盖的变量', keyList, UIHelper.icons.warning));
|
|
28
|
+
console.log();
|
|
29
|
+
console.log(UIHelper.createTooltip('Claude 会优先读取该设置文件中的 env 配置,可能覆盖本次为供应商设置的变量。'));
|
|
30
|
+
console.log();
|
|
31
|
+
|
|
32
|
+
let answer;
|
|
33
|
+
try {
|
|
34
|
+
answer = await command.prompt([
|
|
35
|
+
{
|
|
36
|
+
type: 'list',
|
|
37
|
+
name: 'action',
|
|
38
|
+
message: `在 ${conflict.filePath} 中发现 env 配置会覆盖供应商 '${provider.displayName || provider.name}' 的变量,选择处理方式:`,
|
|
39
|
+
choices: [
|
|
40
|
+
{ name: '🔧 备份并清空这些变量', value: 'fix' },
|
|
41
|
+
{ name: '⚠️ 忽略并继续(可能导致切换失败)', value: 'ignore' },
|
|
42
|
+
{ name: '❌ 取消启动', value: 'cancel' }
|
|
43
|
+
],
|
|
44
|
+
default: 'fix'
|
|
45
|
+
}
|
|
46
|
+
]);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
if (command.isEscCancelled(error)) {
|
|
49
|
+
Logger.info('已取消启动');
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (answer.action === 'fix') {
|
|
56
|
+
return await fixSettingsConflict(command, conflict, backupDir);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (answer.action === 'ignore') {
|
|
60
|
+
Logger.warning(`已忽略 ${conflict.filePath} 中的冲突,Claude 可能仍会使用该文件里的旧变量。`);
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
Logger.info('已取消启动');
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function fixSettingsConflict(command, conflict, backupDir) {
|
|
69
|
+
let confirmBackup;
|
|
70
|
+
try {
|
|
71
|
+
confirmBackup = await command.prompt([
|
|
72
|
+
{
|
|
73
|
+
type: 'confirm',
|
|
74
|
+
name: 'confirmed',
|
|
75
|
+
message: `将在 ${backupDir} 中创建备份文件 (settings.backup-YYYYMMDD_HHmmss.json),并清空冲突变量。是否继续?`,
|
|
76
|
+
default: true
|
|
77
|
+
}
|
|
78
|
+
]);
|
|
79
|
+
} catch (error) {
|
|
80
|
+
if (command.isEscCancelled(error)) {
|
|
81
|
+
Logger.info('已取消启动');
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
throw error;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (!confirmBackup.confirmed) {
|
|
88
|
+
Logger.info('已取消启动');
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
try {
|
|
93
|
+
const backupPath = await backupSettingsFile(conflict.filePath);
|
|
94
|
+
const updatedSettings = clearConflictKeys(
|
|
95
|
+
{
|
|
96
|
+
...conflict.settings,
|
|
97
|
+
env: conflict.settings.env ? { ...conflict.settings.env } : undefined
|
|
98
|
+
},
|
|
99
|
+
conflict.keys
|
|
100
|
+
);
|
|
101
|
+
await saveSettingsFile(conflict.filePath, updatedSettings);
|
|
102
|
+
Logger.success(`已将 ${conflict.filePath} 备份至 '${backupPath}' 并清空冲突变量。`);
|
|
103
|
+
} catch (error) {
|
|
104
|
+
throw new Error(`清理 Claude 设置文件失败: ${error.message}`);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
module.exports = {
|
|
111
|
+
ensureClaudeSettingsCompatibility,
|
|
112
|
+
fixSettingsConflict
|
|
113
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
class ProviderChoicesHelper {
|
|
2
|
+
static buildProviderChoices(providers, options = {}) {
|
|
3
|
+
const {
|
|
4
|
+
includeActions = false,
|
|
5
|
+
statusMap = {},
|
|
6
|
+
UIHelper,
|
|
7
|
+
StatusHelper,
|
|
8
|
+
chalk,
|
|
9
|
+
Separator,
|
|
10
|
+
icons = UIHelper?.icons || {}
|
|
11
|
+
} = options;
|
|
12
|
+
|
|
13
|
+
const lastUsedProvider = this.findLastUsedProvider(providers);
|
|
14
|
+
const choices = providers.map(provider => this.buildProviderChoice(provider, {
|
|
15
|
+
lastUsedProvider,
|
|
16
|
+
statusMap,
|
|
17
|
+
UIHelper,
|
|
18
|
+
StatusHelper,
|
|
19
|
+
chalk
|
|
20
|
+
}));
|
|
21
|
+
|
|
22
|
+
if (includeActions) {
|
|
23
|
+
choices.push(
|
|
24
|
+
new Separator(),
|
|
25
|
+
{ name: `${icons.back} 返回供应商选择`, value: 'back' },
|
|
26
|
+
{ name: `${icons.error} 退出`, value: 'exit' }
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return choices;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static buildProviderChoice(provider, options = {}) {
|
|
34
|
+
const {
|
|
35
|
+
lastUsedProvider,
|
|
36
|
+
statusMap = {},
|
|
37
|
+
UIHelper,
|
|
38
|
+
StatusHelper,
|
|
39
|
+
chalk
|
|
40
|
+
} = options;
|
|
41
|
+
const isLastUsed = lastUsedProvider && lastUsedProvider.name === provider.name;
|
|
42
|
+
const availability = statusMap[provider.name];
|
|
43
|
+
const icon = StatusHelper.getIconForState(availability?.state);
|
|
44
|
+
const statusText = StatusHelper.formatAvailability(availability);
|
|
45
|
+
const statusLabel = chalk.gray('-') + ' ' + statusText;
|
|
46
|
+
const ideTag = provider.ideName === 'codex'
|
|
47
|
+
? chalk.cyan('[Codex]')
|
|
48
|
+
: chalk.magenta('[Claude]');
|
|
49
|
+
const lastUsedLabel = isLastUsed ? UIHelper.colors.muted(' --- 上次使用') : '';
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
name: `${icon} ${ideTag} ${UIHelper.formatProvider(provider)}${lastUsedLabel} ${statusLabel}`,
|
|
53
|
+
value: provider.name,
|
|
54
|
+
short: provider.name
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
static findLastUsedProvider(providers) {
|
|
59
|
+
return providers.reduce((latest, current) => {
|
|
60
|
+
if (!current || !current.lastUsed) {
|
|
61
|
+
return latest;
|
|
62
|
+
}
|
|
63
|
+
if (!latest || !latest.lastUsed) {
|
|
64
|
+
return current;
|
|
65
|
+
}
|
|
66
|
+
return new Date(current.lastUsed) > new Date(latest.lastUsed) ? current : latest;
|
|
67
|
+
}, null);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
module.exports = { ProviderChoicesHelper };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
class ProviderDetailsHelper {
|
|
2
|
+
static buildDetailsRows(provider, options = {}) {
|
|
3
|
+
const {
|
|
4
|
+
authModeDisplay = {},
|
|
5
|
+
baseUrl,
|
|
6
|
+
formatTime
|
|
7
|
+
} = options;
|
|
8
|
+
|
|
9
|
+
const baseUrlDisplay = provider.baseUrl
|
|
10
|
+
|| (provider.authMode === 'auth_token'
|
|
11
|
+
? baseUrl.OFFICIAL_DEFAULT
|
|
12
|
+
: '⚠️ 未设置');
|
|
13
|
+
|
|
14
|
+
return [
|
|
15
|
+
['供应商名称', provider.name],
|
|
16
|
+
['显示名称', provider.displayName],
|
|
17
|
+
['认证模式', authModeDisplay[provider.authMode] || provider.authMode],
|
|
18
|
+
['基础URL', baseUrlDisplay],
|
|
19
|
+
['认证令牌', provider.authToken || '未设置'],
|
|
20
|
+
['主模型', provider.models?.primary || '未设置'],
|
|
21
|
+
['快速模型', provider.models?.smallFast || '未设置'],
|
|
22
|
+
['创建时间', formatTime(provider.createdAt)],
|
|
23
|
+
['最后使用', formatTime(provider.lastUsed)],
|
|
24
|
+
['当前状态', provider.current ? '✅ 使用中' : '⚫ 未使用'],
|
|
25
|
+
['使用次数', provider.usageCount || 0]
|
|
26
|
+
];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
static buildActionChoices(icons) {
|
|
30
|
+
return [
|
|
31
|
+
{ name: `${icons.launch} 立即启动`, value: 'launch' },
|
|
32
|
+
{ name: `${icons.edit} 编辑供应商`, value: 'edit' },
|
|
33
|
+
{ name: `${icons.delete} 删除供应商`, value: 'remove' },
|
|
34
|
+
{ name: `${icons.back} 返回管理列表`, value: 'back' }
|
|
35
|
+
];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static formatLaunchArgs(provider) {
|
|
39
|
+
if (!provider.launchArgs || provider.launchArgs.length === 0) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
return provider.launchArgs.join(', ');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
module.exports = { ProviderDetailsHelper };
|