ai-account-switch 1.8.1 → 1.9.0
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 +40 -6
- package/README_EN.md +40 -6
- package/package.json +1 -1
- package/src/commands/account.js +56 -23
- package/src/config.js +79 -3
- package/src/index.js +27 -24
package/README.md
CHANGED
|
@@ -73,11 +73,11 @@ npm link
|
|
|
73
73
|
| 命令 | 别名 | 描述 |
|
|
74
74
|
|------|------|------|
|
|
75
75
|
| `ais add [name]` | - | 添加新的账户配置 |
|
|
76
|
-
| `ais list` | `ls` |
|
|
77
|
-
| `ais use [name]` | - | 为当前项目设置账户 |
|
|
76
|
+
| `ais list` | `ls` | 列出所有可用账户(含ID) |
|
|
77
|
+
| `ais use [name-or-id]` | - | 通过名称或ID为当前项目设置账户 |
|
|
78
78
|
| `ais info` | - | 显示当前项目的账户信息 |
|
|
79
79
|
| `ais current` | - | 显示当前账户名称 |
|
|
80
|
-
| `ais remove [name]` | `rm` | 删除账户 |
|
|
80
|
+
| `ais remove [name-or-id]` | `rm` | 通过名称或ID删除账户 |
|
|
81
81
|
| `ais model list` | `ls` | 列出当前账户的所有模型组 |
|
|
82
82
|
| `ais model add [name]` | - | 添加新的模型组 |
|
|
83
83
|
| `ais model use <name>` | - | 切换到不同的模型组 |
|
|
@@ -95,7 +95,7 @@ npm link
|
|
|
95
95
|
| `ais ui` | - | 启动 Web UI 管理界面 |
|
|
96
96
|
| `ais paths` | - | 显示配置文件路径 |
|
|
97
97
|
| `ais doctor` | - | 诊断 Claude Code 配置问题 |
|
|
98
|
-
| `ais export <name>` | - | 导出账户为 JSON 格式 |
|
|
98
|
+
| `ais export <name-or-id>` | - | 通过名称或ID导出账户为 JSON 格式 |
|
|
99
99
|
| `ais help` | - | 显示帮助信息 |
|
|
100
100
|
| `ais --version` | - | 显示版本号 |
|
|
101
101
|
|
|
@@ -128,7 +128,7 @@ ais add my-claude-account
|
|
|
128
128
|
|
|
129
129
|
#### 2. 列出所有账户
|
|
130
130
|
|
|
131
|
-
|
|
131
|
+
查看所有已配置的账户及其ID:
|
|
132
132
|
|
|
133
133
|
```bash
|
|
134
134
|
ais list
|
|
@@ -136,14 +136,33 @@ ais list
|
|
|
136
136
|
ais ls
|
|
137
137
|
```
|
|
138
138
|
|
|
139
|
+
输出示例:
|
|
140
|
+
```
|
|
141
|
+
📋 Available Accounts (可用账号):
|
|
142
|
+
|
|
143
|
+
● [1] my-claude-account
|
|
144
|
+
Type: Claude
|
|
145
|
+
API Key: sk-a****xyz
|
|
146
|
+
...
|
|
147
|
+
|
|
148
|
+
[2] work-codex
|
|
149
|
+
Type: Codex
|
|
150
|
+
API Key: sk-b****abc
|
|
151
|
+
...
|
|
152
|
+
```
|
|
153
|
+
|
|
139
154
|
当前项目激活的账户将用绿色圆点标记。
|
|
140
155
|
|
|
141
156
|
#### 3. 为当前项目切换账户
|
|
142
157
|
|
|
143
|
-
|
|
158
|
+
设置当前项目使用的账户(可以使用账户名或ID):
|
|
144
159
|
|
|
145
160
|
```bash
|
|
161
|
+
# 使用账户名
|
|
146
162
|
ais use my-claude-account
|
|
163
|
+
|
|
164
|
+
# 或使用ID(更快捷)
|
|
165
|
+
ais use 1
|
|
147
166
|
```
|
|
148
167
|
|
|
149
168
|
或交互式选择:
|
|
@@ -1006,6 +1025,21 @@ MIT License - 欢迎在你的项目中使用此工具!
|
|
|
1006
1025
|
|
|
1007
1026
|
## 更新日志
|
|
1008
1027
|
|
|
1028
|
+
### v1.9.0
|
|
1029
|
+
- **账号ID功能**:
|
|
1030
|
+
- 为每个账号自动分配唯一数字ID(从1开始递增)
|
|
1031
|
+
- 支持通过ID快速切换账号:`ais use 1`
|
|
1032
|
+
- 支持通过ID删除账号:`ais remove 2`
|
|
1033
|
+
- 支持通过ID导出账号:`ais export 3`
|
|
1034
|
+
- 账号列表展示格式优化:`[ID] AccountName`
|
|
1035
|
+
- ID使用黄色高亮显示,更加清晰可见
|
|
1036
|
+
- 完全向后兼容:已有账号自动分配ID
|
|
1037
|
+
- 交互式选择账号时同时显示ID和名称
|
|
1038
|
+
- **文档更新**:
|
|
1039
|
+
- 更新所有命令说明,添加ID使用示例
|
|
1040
|
+
- 中英文README同步更新
|
|
1041
|
+
- Help命令输出优化
|
|
1042
|
+
|
|
1009
1043
|
### v1.7.0
|
|
1010
1044
|
- **MCP Web UI 管理**:
|
|
1011
1045
|
- 通过 Web UI 完整管理 MCP 服务器
|
package/README_EN.md
CHANGED
|
@@ -66,11 +66,11 @@ npm link
|
|
|
66
66
|
| Command | Alias | Description |
|
|
67
67
|
|---------|-------|-------------|
|
|
68
68
|
| `ais add [name]` | - | Add a new account configuration |
|
|
69
|
-
| `ais list` | `ls` | List all available accounts |
|
|
70
|
-
| `ais use [name]` | - | Set account for current project |
|
|
69
|
+
| `ais list` | `ls` | List all available accounts with IDs |
|
|
70
|
+
| `ais use [name-or-id]` | - | Set account for current project by name or ID |
|
|
71
71
|
| `ais info` | - | Show current project's account info |
|
|
72
72
|
| `ais current` | - | Show current account name |
|
|
73
|
-
| `ais remove [name]` | `rm` | Remove an account |
|
|
73
|
+
| `ais remove [name-or-id]` | `rm` | Remove an account by name or ID |
|
|
74
74
|
| `ais model list` | `ls` | List all model groups for current account |
|
|
75
75
|
| `ais model add [name]` | - | Add a new model group |
|
|
76
76
|
| `ais model use <name>` | - | Switch to a different model group |
|
|
@@ -88,7 +88,7 @@ npm link
|
|
|
88
88
|
| `ais ui` | - | Start web-based UI manager |
|
|
89
89
|
| `ais paths` | - | Show configuration file paths |
|
|
90
90
|
| `ais doctor` | - | Diagnose configuration issues |
|
|
91
|
-
| `ais export <name>` | - | Export account as JSON |
|
|
91
|
+
| `ais export <name-or-id>` | - | Export account as JSON by name or ID |
|
|
92
92
|
| `ais help` | - | Display help information |
|
|
93
93
|
| `ais --version` | - | Show version number |
|
|
94
94
|
|
|
@@ -122,7 +122,7 @@ You'll be prompted to enter:
|
|
|
122
122
|
|
|
123
123
|
#### 2. List All Accounts
|
|
124
124
|
|
|
125
|
-
View all your configured accounts:
|
|
125
|
+
View all your configured accounts with their IDs:
|
|
126
126
|
|
|
127
127
|
```bash
|
|
128
128
|
ais list
|
|
@@ -130,14 +130,33 @@ ais list
|
|
|
130
130
|
ais ls
|
|
131
131
|
```
|
|
132
132
|
|
|
133
|
+
Example output:
|
|
134
|
+
```
|
|
135
|
+
📋 Available Accounts:
|
|
136
|
+
|
|
137
|
+
● [1] my-claude-account
|
|
138
|
+
Type: Claude
|
|
139
|
+
API Key: sk-a****xyz
|
|
140
|
+
...
|
|
141
|
+
|
|
142
|
+
[2] work-codex
|
|
143
|
+
Type: Codex
|
|
144
|
+
API Key: sk-b****abc
|
|
145
|
+
...
|
|
146
|
+
```
|
|
147
|
+
|
|
133
148
|
The active account for the current project will be marked with a green dot.
|
|
134
149
|
|
|
135
150
|
#### 3. Switch Account for Current Project
|
|
136
151
|
|
|
137
|
-
Set which account to use in your current project:
|
|
152
|
+
Set which account to use in your current project (by name or ID):
|
|
138
153
|
|
|
139
154
|
```bash
|
|
155
|
+
# Use account by name
|
|
140
156
|
ais use my-claude-account
|
|
157
|
+
|
|
158
|
+
# Or use account by ID (faster)
|
|
159
|
+
ais use 1
|
|
141
160
|
```
|
|
142
161
|
|
|
143
162
|
Or select interactively:
|
|
@@ -997,6 +1016,21 @@ MIT License - feel free to use this tool in your projects!
|
|
|
997
1016
|
|
|
998
1017
|
## Changelog
|
|
999
1018
|
|
|
1019
|
+
### v1.9.0
|
|
1020
|
+
- **Account ID Feature**:
|
|
1021
|
+
- Automatically assign unique numeric ID to each account (starting from 1)
|
|
1022
|
+
- Quick account switching by ID: `ais use 1`
|
|
1023
|
+
- Remove account by ID: `ais remove 2`
|
|
1024
|
+
- Export account by ID: `ais export 3`
|
|
1025
|
+
- Optimized account list display format: `[ID] AccountName`
|
|
1026
|
+
- ID displayed in yellow color for better visibility
|
|
1027
|
+
- Fully backward compatible: existing accounts automatically assigned IDs
|
|
1028
|
+
- Interactive selection shows both ID and name
|
|
1029
|
+
- **Documentation Updates**:
|
|
1030
|
+
- Updated all command descriptions with ID usage examples
|
|
1031
|
+
- Synchronized Chinese and English README
|
|
1032
|
+
- Optimized help command output
|
|
1033
|
+
|
|
1000
1034
|
### v1.7.0
|
|
1001
1035
|
- **MCP Web UI Management**:
|
|
1002
1036
|
- Complete MCP server management through Web UI
|
package/package.json
CHANGED
package/src/commands/account.js
CHANGED
|
@@ -623,11 +623,14 @@ function listAccounts() {
|
|
|
623
623
|
const account = accounts[name];
|
|
624
624
|
const isActive = currentProject && currentProject.name === name;
|
|
625
625
|
const marker = isActive ? chalk.green("● ") : " ";
|
|
626
|
+
|
|
627
|
+
// Display ID and name
|
|
628
|
+
const idDisplay = chalk.yellow(`[${account.id}]`);
|
|
626
629
|
const nameDisplay = isActive
|
|
627
630
|
? chalk.green.bold(name)
|
|
628
631
|
: chalk.cyan(name);
|
|
629
632
|
|
|
630
|
-
console.log(`${marker}${nameDisplay}`);
|
|
633
|
+
console.log(`${marker}${idDisplay} ${nameDisplay}`);
|
|
631
634
|
console.log(` Type: ${account.type}`);
|
|
632
635
|
console.log(` API Key: ${maskApiKey(account.apiKey)}`);
|
|
633
636
|
if (account.apiUrl) console.log(` API URL: ${account.apiUrl}`);
|
|
@@ -687,9 +690,9 @@ function listAccounts() {
|
|
|
687
690
|
/**
|
|
688
691
|
* Switch to a specific account for current project
|
|
689
692
|
*/
|
|
690
|
-
async function useAccount(
|
|
691
|
-
if (!
|
|
692
|
-
// If no name provided, show interactive selection
|
|
693
|
+
async function useAccount(nameOrId) {
|
|
694
|
+
if (!nameOrId) {
|
|
695
|
+
// If no name/ID provided, show interactive selection
|
|
693
696
|
const accounts = config.getAllAccounts();
|
|
694
697
|
const accountNames = Object.keys(accounts);
|
|
695
698
|
|
|
@@ -702,21 +705,32 @@ async function useAccount(name) {
|
|
|
702
705
|
return;
|
|
703
706
|
}
|
|
704
707
|
|
|
708
|
+
// Create choices with ID and name
|
|
709
|
+
const choices = accountNames.map(name => {
|
|
710
|
+
const account = accounts[name];
|
|
711
|
+
return {
|
|
712
|
+
name: `[${account.id}] ${name}`,
|
|
713
|
+
value: name
|
|
714
|
+
};
|
|
715
|
+
});
|
|
716
|
+
|
|
705
717
|
const answers = await inquirer.prompt([
|
|
706
718
|
{
|
|
707
719
|
type: "list",
|
|
708
720
|
name: "accountName",
|
|
709
721
|
message: "Select an account to use (请选择要使用的账号):",
|
|
710
|
-
choices:
|
|
722
|
+
choices: choices,
|
|
711
723
|
},
|
|
712
724
|
]);
|
|
713
725
|
|
|
714
|
-
|
|
726
|
+
nameOrId = answers.accountName;
|
|
715
727
|
}
|
|
716
728
|
|
|
717
|
-
|
|
729
|
+
// Find account by ID or name
|
|
730
|
+
const accountInfo = config.getAccountByIdOrName(nameOrId);
|
|
731
|
+
if (!accountInfo) {
|
|
718
732
|
console.log(
|
|
719
|
-
chalk.red(`✗ Account '${
|
|
733
|
+
chalk.red(`✗ Account '${nameOrId}' not found. (未找到账号 '${nameOrId}'。)`)
|
|
720
734
|
);
|
|
721
735
|
console.log(
|
|
722
736
|
chalk.yellow(
|
|
@@ -726,6 +740,7 @@ async function useAccount(name) {
|
|
|
726
740
|
return;
|
|
727
741
|
}
|
|
728
742
|
|
|
743
|
+
const name = accountInfo.name;
|
|
729
744
|
const success = config.setProjectAccount(name);
|
|
730
745
|
if (success) {
|
|
731
746
|
const fs = require("fs");
|
|
@@ -920,6 +935,7 @@ function showInfo() {
|
|
|
920
935
|
console.log(
|
|
921
936
|
chalk.bold("\n📌 Current Project Account Info (当前项目账号信息):\n")
|
|
922
937
|
);
|
|
938
|
+
console.log(`${chalk.cyan("Account ID:")} ${chalk.yellow(`[${projectAccount.id}]`)}`);
|
|
923
939
|
console.log(
|
|
924
940
|
`${chalk.cyan("Account Name:")} ${chalk.green.bold(
|
|
925
941
|
projectAccount.name
|
|
@@ -989,8 +1005,8 @@ function showInfo() {
|
|
|
989
1005
|
/**
|
|
990
1006
|
* Remove an account
|
|
991
1007
|
*/
|
|
992
|
-
async function removeAccount(
|
|
993
|
-
if (!
|
|
1008
|
+
async function removeAccount(nameOrId) {
|
|
1009
|
+
if (!nameOrId) {
|
|
994
1010
|
const accounts = config.getAllAccounts();
|
|
995
1011
|
const accountNames = Object.keys(accounts);
|
|
996
1012
|
|
|
@@ -999,30 +1015,43 @@ async function removeAccount(name) {
|
|
|
999
1015
|
return;
|
|
1000
1016
|
}
|
|
1001
1017
|
|
|
1018
|
+
// Create choices with ID and name
|
|
1019
|
+
const choices = accountNames.map(name => {
|
|
1020
|
+
const account = accounts[name];
|
|
1021
|
+
return {
|
|
1022
|
+
name: `[${account.id}] ${name}`,
|
|
1023
|
+
value: name
|
|
1024
|
+
};
|
|
1025
|
+
});
|
|
1026
|
+
|
|
1002
1027
|
const answers = await inquirer.prompt([
|
|
1003
1028
|
{
|
|
1004
1029
|
type: "list",
|
|
1005
1030
|
name: "accountName",
|
|
1006
1031
|
message: "Select an account to remove (请选择要删除的账号):",
|
|
1007
|
-
choices:
|
|
1032
|
+
choices: choices,
|
|
1008
1033
|
},
|
|
1009
1034
|
]);
|
|
1010
1035
|
|
|
1011
|
-
|
|
1036
|
+
nameOrId = answers.accountName;
|
|
1012
1037
|
}
|
|
1013
1038
|
|
|
1014
|
-
|
|
1039
|
+
// Find account by ID or name
|
|
1040
|
+
const accountInfo = config.getAccountByIdOrName(nameOrId);
|
|
1041
|
+
if (!accountInfo) {
|
|
1015
1042
|
console.log(
|
|
1016
|
-
chalk.red(`✗ Account '${
|
|
1043
|
+
chalk.red(`✗ Account '${nameOrId}' not found. (未找到账号 '${nameOrId}'。)`)
|
|
1017
1044
|
);
|
|
1018
1045
|
return;
|
|
1019
1046
|
}
|
|
1020
1047
|
|
|
1048
|
+
const name = accountInfo.name;
|
|
1049
|
+
|
|
1021
1050
|
const { confirm } = await inquirer.prompt([
|
|
1022
1051
|
{
|
|
1023
1052
|
type: "confirm",
|
|
1024
1053
|
name: "confirm",
|
|
1025
|
-
message: `Are you sure you want to remove account '${name}'? (确定要删除账号 '${name}' 吗?)`,
|
|
1054
|
+
message: `Are you sure you want to remove account '${name}' (ID: ${accountInfo.id})? (确定要删除账号 '${name}' (ID: ${accountInfo.id}) 吗?)`,
|
|
1026
1055
|
default: false,
|
|
1027
1056
|
},
|
|
1028
1057
|
]);
|
|
@@ -1069,30 +1098,34 @@ function showCurrent() {
|
|
|
1069
1098
|
/**
|
|
1070
1099
|
* Export account configuration
|
|
1071
1100
|
*/
|
|
1072
|
-
function exportAccount(
|
|
1073
|
-
if (!
|
|
1101
|
+
function exportAccount(nameOrId) {
|
|
1102
|
+
if (!nameOrId) {
|
|
1074
1103
|
console.log(
|
|
1075
|
-
chalk.red("Please specify an account name. (
|
|
1104
|
+
chalk.red("Please specify an account name or ID. (请指定账号名称或 ID。)")
|
|
1076
1105
|
);
|
|
1077
1106
|
console.log(
|
|
1078
1107
|
chalk.cyan(
|
|
1079
|
-
"Usage: ais export <account-name> (用法: ais export
|
|
1108
|
+
"Usage: ais export <account-name-or-id> (用法: ais export <账号名或ID>)"
|
|
1080
1109
|
)
|
|
1081
1110
|
);
|
|
1082
1111
|
return;
|
|
1083
1112
|
}
|
|
1084
1113
|
|
|
1085
|
-
|
|
1086
|
-
|
|
1114
|
+
// Find account by ID or name
|
|
1115
|
+
const accountInfo = config.getAccountByIdOrName(nameOrId);
|
|
1116
|
+
if (!accountInfo) {
|
|
1087
1117
|
console.log(
|
|
1088
|
-
chalk.red(`✗ Account '${
|
|
1118
|
+
chalk.red(`✗ Account '${nameOrId}' not found. (未找到账号 '${nameOrId}'。)`)
|
|
1089
1119
|
);
|
|
1090
1120
|
return;
|
|
1091
1121
|
}
|
|
1092
1122
|
|
|
1123
|
+
const name = accountInfo.name;
|
|
1124
|
+
const { name: _, ...account } = accountInfo; // Remove the name property from accountInfo
|
|
1125
|
+
|
|
1093
1126
|
console.log(
|
|
1094
1127
|
chalk.bold(
|
|
1095
|
-
`\n📤 Export for account '${name}' (账号 '${name}' 的导出数据):\n`
|
|
1128
|
+
`\n📤 Export for account '${name}' (ID: ${account.id}) (账号 '${name}' 的导出数据):\n`
|
|
1096
1129
|
)
|
|
1097
1130
|
);
|
|
1098
1131
|
console.log(JSON.stringify({ [name]: account }, null, 2));
|
package/src/config.js
CHANGED
|
@@ -46,8 +46,11 @@ class ConfigManager {
|
|
|
46
46
|
|
|
47
47
|
// Create global config file if it doesn't exist
|
|
48
48
|
if (!fs.existsSync(this.globalConfigFile)) {
|
|
49
|
-
this.saveGlobalConfig({ accounts: {}, mcpServers: {} });
|
|
49
|
+
this.saveGlobalConfig({ accounts: {}, mcpServers: {}, nextAccountId: 1 });
|
|
50
50
|
}
|
|
51
|
+
|
|
52
|
+
// Migrate existing accounts to have IDs
|
|
53
|
+
this.migrateAccountIds();
|
|
51
54
|
}
|
|
52
55
|
|
|
53
56
|
/**
|
|
@@ -82,9 +85,14 @@ class ConfigManager {
|
|
|
82
85
|
readGlobalConfig() {
|
|
83
86
|
try {
|
|
84
87
|
const data = fs.readFileSync(this.globalConfigFile, 'utf8');
|
|
85
|
-
|
|
88
|
+
const config = JSON.parse(data);
|
|
89
|
+
// Ensure nextAccountId exists
|
|
90
|
+
if (!config.nextAccountId) {
|
|
91
|
+
config.nextAccountId = 1;
|
|
92
|
+
}
|
|
93
|
+
return config;
|
|
86
94
|
} catch (error) {
|
|
87
|
-
return { accounts: {}, mcpServers: {} };
|
|
95
|
+
return { accounts: {}, mcpServers: {}, nextAccountId: 1 };
|
|
88
96
|
}
|
|
89
97
|
}
|
|
90
98
|
|
|
@@ -95,16 +103,84 @@ class ConfigManager {
|
|
|
95
103
|
fs.writeFileSync(this.globalConfigFile, JSON.stringify(config, null, 2), 'utf8');
|
|
96
104
|
}
|
|
97
105
|
|
|
106
|
+
/**
|
|
107
|
+
* Migrate existing accounts to have IDs
|
|
108
|
+
* This ensures backward compatibility by assigning IDs to accounts that don't have one
|
|
109
|
+
*/
|
|
110
|
+
migrateAccountIds() {
|
|
111
|
+
const config = this.readGlobalConfig();
|
|
112
|
+
let needsSave = false;
|
|
113
|
+
|
|
114
|
+
// Ensure nextAccountId exists
|
|
115
|
+
if (!config.nextAccountId) {
|
|
116
|
+
config.nextAccountId = 1;
|
|
117
|
+
needsSave = true;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Assign IDs to accounts that don't have one
|
|
121
|
+
Object.keys(config.accounts || {}).forEach(name => {
|
|
122
|
+
if (!config.accounts[name].id) {
|
|
123
|
+
config.accounts[name].id = config.nextAccountId;
|
|
124
|
+
config.nextAccountId++;
|
|
125
|
+
needsSave = true;
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
if (needsSave) {
|
|
130
|
+
this.saveGlobalConfig(config);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Get account by ID or name
|
|
136
|
+
* @param {string|number} idOrName - Account ID or name
|
|
137
|
+
* @returns {Object|null} - Account object with name property, or null if not found
|
|
138
|
+
*/
|
|
139
|
+
getAccountByIdOrName(idOrName) {
|
|
140
|
+
const accounts = this.getAllAccounts();
|
|
141
|
+
|
|
142
|
+
// Try to parse as ID (number)
|
|
143
|
+
const id = parseInt(idOrName, 10);
|
|
144
|
+
if (!isNaN(id)) {
|
|
145
|
+
// Search by ID
|
|
146
|
+
for (const [name, account] of Object.entries(accounts)) {
|
|
147
|
+
if (account.id === id) {
|
|
148
|
+
return { name, ...account };
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Search by name
|
|
154
|
+
const account = accounts[idOrName];
|
|
155
|
+
if (account) {
|
|
156
|
+
return { name: idOrName, ...account };
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
|
|
98
162
|
/**
|
|
99
163
|
* Add or update an account
|
|
100
164
|
*/
|
|
101
165
|
addAccount(name, accountData) {
|
|
102
166
|
const config = this.readGlobalConfig();
|
|
167
|
+
|
|
168
|
+
// Assign ID for new accounts
|
|
169
|
+
const isNewAccount = !config.accounts[name];
|
|
170
|
+
const accountId = isNewAccount ? config.nextAccountId : config.accounts[name].id;
|
|
171
|
+
|
|
103
172
|
config.accounts[name] = {
|
|
104
173
|
...accountData,
|
|
174
|
+
id: accountId,
|
|
105
175
|
createdAt: config.accounts[name]?.createdAt || new Date().toISOString(),
|
|
106
176
|
updatedAt: new Date().toISOString()
|
|
107
177
|
};
|
|
178
|
+
|
|
179
|
+
// Increment nextAccountId only for new accounts
|
|
180
|
+
if (isNewAccount) {
|
|
181
|
+
config.nextAccountId++;
|
|
182
|
+
}
|
|
183
|
+
|
|
108
184
|
this.saveGlobalConfig(config);
|
|
109
185
|
return true;
|
|
110
186
|
}
|
package/src/index.js
CHANGED
|
@@ -53,8 +53,8 @@ program
|
|
|
53
53
|
|
|
54
54
|
// Use account command
|
|
55
55
|
program
|
|
56
|
-
.command('use [name]')
|
|
57
|
-
.description('Set the account to use for the current project (设置当前项目使用的账号)')
|
|
56
|
+
.command('use [name-or-id]')
|
|
57
|
+
.description('Set the account to use for the current project by name or ID (通过名称或ID设置当前项目使用的账号)')
|
|
58
58
|
.action(useAccount);
|
|
59
59
|
|
|
60
60
|
// Show info command
|
|
@@ -65,9 +65,9 @@ program
|
|
|
65
65
|
|
|
66
66
|
// Remove account command
|
|
67
67
|
program
|
|
68
|
-
.command('remove [name]')
|
|
68
|
+
.command('remove [name-or-id]')
|
|
69
69
|
.alias('rm')
|
|
70
|
-
.description('Remove an account (删除账号)')
|
|
70
|
+
.description('Remove an account by name or ID (通过名称或ID删除账号)')
|
|
71
71
|
.action(removeAccount);
|
|
72
72
|
|
|
73
73
|
// Show current account command
|
|
@@ -84,8 +84,8 @@ program
|
|
|
84
84
|
|
|
85
85
|
// Export account configuration
|
|
86
86
|
program
|
|
87
|
-
.command('export <name>')
|
|
88
|
-
.description('Export account configuration as JSON (导出账号配置为 JSON)')
|
|
87
|
+
.command('export <name-or-id>')
|
|
88
|
+
.description('Export account configuration as JSON by name or ID (通过名称或ID导出账号配置为 JSON)')
|
|
89
89
|
.action(exportAccount);
|
|
90
90
|
|
|
91
91
|
// Diagnostic command
|
|
@@ -199,36 +199,39 @@ program
|
|
|
199
199
|
console.log(' ais <command> [options]\n');
|
|
200
200
|
|
|
201
201
|
console.log(chalk.bold('COMMANDS (命令):'));
|
|
202
|
-
console.log(' add [name]
|
|
203
|
-
console.log(' list, ls
|
|
204
|
-
console.log(' use [name] Set the account for current project (设置当前项目使用的账号)');
|
|
205
|
-
console.log(' info
|
|
206
|
-
console.log(' current
|
|
207
|
-
console.log(' remove, rm
|
|
208
|
-
console.log(' paths
|
|
209
|
-
console.log(' doctor
|
|
210
|
-
console.log(' export <name> Export account as JSON (导出账号为 JSON)');
|
|
211
|
-
console.log(' ui
|
|
212
|
-
console.log(' model
|
|
213
|
-
console.log(' mcp
|
|
214
|
-
console.log(' help
|
|
215
|
-
console.log(' version
|
|
202
|
+
console.log(' add [name] Add a new account configuration (with custom env vars) (添加新账号配置,支持自定义环境变量)');
|
|
203
|
+
console.log(' list, ls List all available accounts with IDs (列出所有可用账号及其ID)');
|
|
204
|
+
console.log(' use [name-or-id] Set the account for current project by name or ID (通过名称或ID设置当前项目使用的账号)');
|
|
205
|
+
console.log(' info Show current project\'s account info (显示当前项目的账号信息)');
|
|
206
|
+
console.log(' current Show current account name (显示当前账号名称)');
|
|
207
|
+
console.log(' remove, rm [name-or-id] Remove an account by name or ID (通过名称或ID删除账号)');
|
|
208
|
+
console.log(' paths Show configuration file paths (显示配置文件路径)');
|
|
209
|
+
console.log(' doctor Diagnose Claude Code configuration issues (诊断 Claude Code 配置问题)');
|
|
210
|
+
console.log(' export <name-or-id> Export account as JSON by name or ID (通过名称或ID导出账号为 JSON)');
|
|
211
|
+
console.log(' ui Start web-based account manager UI (启动基于 Web 的账号管理界面)');
|
|
212
|
+
console.log(' model Manage model groups (管理模型组)');
|
|
213
|
+
console.log(' mcp Manage MCP servers (管理 MCP 服务器)');
|
|
214
|
+
console.log(' help Display this help message (显示此帮助信息)');
|
|
215
|
+
console.log(' version Show version number (显示版本号)\n');
|
|
216
216
|
|
|
217
217
|
console.log(chalk.bold('EXAMPLES (示例):'));
|
|
218
218
|
console.log(chalk.gray(' # Add a new account interactively (交互式添加新账号)'));
|
|
219
219
|
console.log(' ais add\n');
|
|
220
220
|
console.log(chalk.gray(' # Add a new account with a name (添加带名称的新账号)'));
|
|
221
221
|
console.log(' ais add my-claude-account\n');
|
|
222
|
-
console.log(chalk.gray(' # List all accounts (
|
|
222
|
+
console.log(chalk.gray(' # List all accounts with IDs (列出所有账号及其ID)'));
|
|
223
223
|
console.log(' ais list\n');
|
|
224
|
-
console.log(chalk.gray(' # Use an account
|
|
224
|
+
console.log(chalk.gray(' # Use an account by name (通过名称使用账号)'));
|
|
225
225
|
console.log(' ais use my-claude-account\n');
|
|
226
|
+
console.log(chalk.gray(' # Use an account by ID (通过ID使用账号)'));
|
|
227
|
+
console.log(' ais use 1\n');
|
|
226
228
|
console.log(chalk.gray(' # Show current project info (显示当前项目信息)'));
|
|
227
229
|
console.log(' ais info\n');
|
|
228
230
|
console.log(chalk.gray(' # Diagnose configuration issues (诊断配置问题)'));
|
|
229
231
|
console.log(' ais doctor\n');
|
|
230
|
-
console.log(chalk.gray(' # Remove an account (删除账号)'));
|
|
231
|
-
console.log(' ais remove my-old-account
|
|
232
|
+
console.log(chalk.gray(' # Remove an account by name or ID (通过名称或ID删除账号)'));
|
|
233
|
+
console.log(' ais remove my-old-account');
|
|
234
|
+
console.log(' ais remove 2\n');
|
|
232
235
|
console.log(chalk.gray(' # Start web UI for managing accounts (启动 Web 界面管理账号)'));
|
|
233
236
|
console.log(' ais ui\n');
|
|
234
237
|
|