@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
package/bin/cc.js
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const { program } = require('commander');
|
|
4
|
-
const chalk = require('chalk');
|
|
5
|
-
const { main } = require('../src/index');
|
|
6
|
-
const { registry } = require('../src/CommandRegistry');
|
|
7
|
-
const pkg = require('../package.json');
|
|
8
|
-
const { checkForUpdates } = require('../src/utils/update-checker');
|
|
9
|
-
|
|
10
|
-
// Set up CLI
|
|
11
|
-
program
|
|
12
|
-
.name('akm')
|
|
13
|
-
.description('API密钥管理工具 - Manage and switch multiple API provider configurations')
|
|
14
|
-
.version(pkg.version, '-v, -V, --version', '显示版本号');
|
|
15
|
-
|
|
16
|
-
// Check for updates before any command runs
|
|
17
|
-
program.hook('preAction', async () => {
|
|
18
|
-
await checkForUpdates({ packageName: pkg.name, currentVersion: pkg.version });
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
// Default command - show provider selection
|
|
22
|
-
program
|
|
23
|
-
.argument('[provider]', '直接切换到指定供应商')
|
|
24
|
-
.action(async (provider) => {
|
|
25
|
-
try {
|
|
26
|
-
await main(provider);
|
|
27
|
-
} catch (error) {
|
|
28
|
-
console.error(chalk.red('❌ 执行失败:'), error.message);
|
|
29
|
-
process.exit(1);
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
// Add command
|
|
34
|
-
program
|
|
35
|
-
.command('add')
|
|
36
|
-
.description('添加新供应商配置')
|
|
37
|
-
.action(async () => {
|
|
38
|
-
try {
|
|
39
|
-
await registry.executeCommand('add');
|
|
40
|
-
} catch (error) {
|
|
41
|
-
console.error(chalk.red('❌ 添加失败:'), error.message);
|
|
42
|
-
process.exit(1);
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
// Remove command
|
|
47
|
-
program
|
|
48
|
-
.command('remove')
|
|
49
|
-
.argument('[provider]', '要删除的供应商名称')
|
|
50
|
-
.description('删除供应商配置')
|
|
51
|
-
.action(async (provider) => {
|
|
52
|
-
try {
|
|
53
|
-
await registry.executeCommand('remove', provider);
|
|
54
|
-
} catch (error) {
|
|
55
|
-
console.error(chalk.red('❌ 删除失败:'), error.message);
|
|
56
|
-
process.exit(1);
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
// List command
|
|
61
|
-
program
|
|
62
|
-
.command('list')
|
|
63
|
-
.description('列出所有供应商')
|
|
64
|
-
.action(async () => {
|
|
65
|
-
try {
|
|
66
|
-
await registry.executeCommand('list');
|
|
67
|
-
} catch (error) {
|
|
68
|
-
console.error(chalk.red('❌ 列表失败:'), error.message);
|
|
69
|
-
process.exit(1);
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
// Current command
|
|
74
|
-
program
|
|
75
|
-
.command('current')
|
|
76
|
-
.description('显示当前配置')
|
|
77
|
-
.action(async () => {
|
|
78
|
-
try {
|
|
79
|
-
await registry.executeCommand('current');
|
|
80
|
-
} catch (error) {
|
|
81
|
-
console.error(chalk.red('❌ 获取当前配置失败:'), error.message);
|
|
82
|
-
process.exit(1);
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
// Edit command
|
|
87
|
-
program
|
|
88
|
-
.command('edit')
|
|
89
|
-
.argument('[provider]', '要编辑的供应商名称')
|
|
90
|
-
.description('编辑供应商配置')
|
|
91
|
-
.action(async (provider) => {
|
|
92
|
-
try {
|
|
93
|
-
await registry.executeCommand('edit', provider);
|
|
94
|
-
} catch (error) {
|
|
95
|
-
console.error(chalk.red('❌ 编辑失败:'), error.message);
|
|
96
|
-
process.exit(1);
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
// Parse arguments
|
|
101
|
-
program.parse();
|
package/src/utils/storage.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
const fs = require('fs-extra');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const os = require('os');
|
|
4
|
-
|
|
5
|
-
class Storage {
|
|
6
|
-
static async ensureConfigDir() {
|
|
7
|
-
const configDir = path.join(os.homedir(), '.akm-config');
|
|
8
|
-
await fs.ensureDir(configDir);
|
|
9
|
-
return configDir;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
static async readConfig() {
|
|
13
|
-
const configPath = path.join(os.homedir(), '.akm-config.json');
|
|
14
|
-
try {
|
|
15
|
-
if (await fs.pathExists(configPath)) {
|
|
16
|
-
return await fs.readJSON(configPath);
|
|
17
|
-
}
|
|
18
|
-
return null;
|
|
19
|
-
} catch (error) {
|
|
20
|
-
throw new Error(`读取配置文件失败: ${error.message}`);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
static async writeConfig(config) {
|
|
25
|
-
const configPath = path.join(os.homedir(), '.akm-config.json');
|
|
26
|
-
try {
|
|
27
|
-
await fs.writeJSON(configPath, config, { spaces: 2 });
|
|
28
|
-
return true;
|
|
29
|
-
} catch (error) {
|
|
30
|
-
throw new Error(`写入配置文件失败: ${error.message}`);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
static async backupConfig() {
|
|
35
|
-
const configPath = path.join(os.homedir(), '.akm-config.json');
|
|
36
|
-
const backupPath = path.join(os.homedir(), '.akm-config.backup.json');
|
|
37
|
-
|
|
38
|
-
if (await fs.pathExists(configPath)) {
|
|
39
|
-
await fs.copy(configPath, backupPath);
|
|
40
|
-
return backupPath;
|
|
41
|
-
}
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
static async restoreConfig(backupPath) {
|
|
46
|
-
const configPath = path.join(os.homedir(), '.akm-config.json');
|
|
47
|
-
if (await fs.pathExists(backupPath)) {
|
|
48
|
-
await fs.copy(backupPath, configPath);
|
|
49
|
-
return true;
|
|
50
|
-
}
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
module.exports = { Storage };
|