ai-account-switch 1.5.6 → 1.6.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 +325 -5
- package/README_ZH.md +316 -5
- package/package.json +6 -4
- package/src/commands/README.md +124 -0
- package/src/commands/account.js +997 -0
- package/src/commands/helpers.js +35 -0
- package/src/commands/index.js +53 -0
- package/src/commands/model.js +383 -0
- package/src/commands/utility.js +326 -0
- package/src/config.js +158 -7
- package/src/index.js +55 -55
- package/src/ui-server.js +494 -47
- package/src/commands.js +0 -1182
package/README_ZH.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[English](README.md) | 简体中文
|
|
4
4
|
|
|
5
|
-
一个跨平台的命令行工具,用于管理和切换不同项目的 Claude/Codex 账户配置。
|
|
5
|
+
一个跨平台的命令行工具,用于管理和切换不同项目的 Claude/Codex/Droids 账户配置。
|
|
6
6
|
|
|
7
7
|
## 特性
|
|
8
8
|
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
- 🎯 主题自动跟随系统设置
|
|
22
22
|
- **安全存储**:账户凭证仅存储在本地
|
|
23
23
|
- **交互式命令行**:所有操作都有易用的交互式提示
|
|
24
|
-
- **多种账户类型**:支持 Claude、Codex 和其他 AI 服务
|
|
24
|
+
- **多种账户类型**:支持 Claude、Codex、CCR (Claude Code Router)、Droids 和其他 AI 服务
|
|
25
25
|
|
|
26
26
|
## 安装
|
|
27
27
|
|
|
@@ -100,7 +100,7 @@ ais add my-claude-account
|
|
|
100
100
|
```
|
|
101
101
|
|
|
102
102
|
系统将提示你输入:
|
|
103
|
-
- 账户类型(Claude、Codex、其他)
|
|
103
|
+
- 账户类型(Claude、Codex、CCR、Droids、其他)
|
|
104
104
|
- API Key
|
|
105
105
|
- API URL(可选)
|
|
106
106
|
- Email(可选)
|
|
@@ -384,6 +384,265 @@ grep -A 10 "$(cat .codex-profile)" ~/.codex/config.toml
|
|
|
384
384
|
ais doctor
|
|
385
385
|
```
|
|
386
386
|
|
|
387
|
+
### CCR (Claude Code Router) 集成
|
|
388
|
+
|
|
389
|
+
[Claude Code Router](https://github.com/musistudio/claude-code-router) 是一个强大的 Claude Code 路由层,允许你无缝使用多个 AI 提供商和模型。
|
|
390
|
+
|
|
391
|
+
当你添加 **CCR** 类型账户并运行 `ais use` 时,工具会自动:
|
|
392
|
+
1. 更新 `~/.claude-code-router/config.json` 中的 Provider 和 Router 配置
|
|
393
|
+
2. 生成指向本地 CCR Router 的 `.claude/settings.local.json`
|
|
394
|
+
3. 自动重启 CCR Router 以应用更改
|
|
395
|
+
|
|
396
|
+
**前提条件:**
|
|
397
|
+
- 安装 Claude Code Router:`npm install -g @musistudio/claude-code-router`
|
|
398
|
+
- 启动 CCR Router:`ccr start`
|
|
399
|
+
|
|
400
|
+
#### 添加 CCR 账户
|
|
401
|
+
|
|
402
|
+
添加 CCR 账户时,你会看到有用的配置提示:
|
|
403
|
+
|
|
404
|
+
```bash
|
|
405
|
+
ais add my-ccr-account
|
|
406
|
+
|
|
407
|
+
? Select account type: CCR
|
|
408
|
+
|
|
409
|
+
📝 CCR Configuration Tips:
|
|
410
|
+
• CCR configuration will be stored in ~/.claude-code-router/config.json
|
|
411
|
+
• You need to provide Provider name and models
|
|
412
|
+
• Router configuration will be automatically updated
|
|
413
|
+
|
|
414
|
+
? Enter API Key: sk-xxx...
|
|
415
|
+
? Enter API URL: http://localhost:3000/v1/chat/completions
|
|
416
|
+
? Enter Provider name: Local-new-api
|
|
417
|
+
? Enter default model: gemini-2.5-flash
|
|
418
|
+
? Enter background model: gemini-2.5-flash
|
|
419
|
+
? Enter think model: gemini-2.5-pro
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
**重要说明:**
|
|
423
|
+
- 默认 API URL 是 `http://localhost:3000/v1/chat/completions`
|
|
424
|
+
- 你需要指定三个模型:default、background 和 think
|
|
425
|
+
- 模型会在 Provider 配置中自动去重
|
|
426
|
+
|
|
427
|
+
#### 在项目中使用 CCR
|
|
428
|
+
|
|
429
|
+
使用 CCR 账户运行 `ais use` 后:
|
|
430
|
+
|
|
431
|
+
```bash
|
|
432
|
+
cd ~/my-project
|
|
433
|
+
ais use my-ccr-account
|
|
434
|
+
|
|
435
|
+
# 输出:
|
|
436
|
+
# ✓ Switched to account 'my-ccr-account' for current project.
|
|
437
|
+
# 🔄 Restarting CCR Router...
|
|
438
|
+
# ✓ CCR Router restarted successfully
|
|
439
|
+
# ✓ CCR configuration updated at: ~/.claude-code-router/config.json
|
|
440
|
+
# ✓ Claude configuration generated at: .claude/settings.local.json
|
|
441
|
+
#
|
|
442
|
+
# 📖 Next Steps:
|
|
443
|
+
# Start interactive session: claude
|
|
444
|
+
# This will enter project-level interactive mode
|
|
445
|
+
# Claude Code will use CCR Router to route requests
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
工具会:
|
|
449
|
+
1. **更新 CCR 配置**:在 `~/.claude-code-router/config.json` 中添加/更新 Provider
|
|
450
|
+
2. **更新 Router**:设置 default、background 和 think 模型
|
|
451
|
+
3. **生成 Claude 配置**:创建 `.claude/settings.local.json`,`ANTHROPIC_BASE_URL` 指向 CCR Router
|
|
452
|
+
4. **重启 CCR**:自动运行 `ccr restart` 以应用更改
|
|
453
|
+
|
|
454
|
+
#### 使用 CCR 运行 Claude
|
|
455
|
+
|
|
456
|
+
启动 Claude 交互会话:
|
|
457
|
+
|
|
458
|
+
```bash
|
|
459
|
+
# 在项目目录中
|
|
460
|
+
claude
|
|
461
|
+
|
|
462
|
+
# Claude Code 会自动使用 CCR Router
|
|
463
|
+
# 请求会根据你的 CCR 配置进行路由
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
#### CCR 配置结构
|
|
467
|
+
|
|
468
|
+
在 `~/.claude-code-router/config.json` 中生成的配置:
|
|
469
|
+
|
|
470
|
+
```json
|
|
471
|
+
{
|
|
472
|
+
"PORT": 3456,
|
|
473
|
+
"Providers": [
|
|
474
|
+
{
|
|
475
|
+
"api_base_url": "http://localhost:3000/v1/chat/completions",
|
|
476
|
+
"api_key": "sk-xxx...",
|
|
477
|
+
"models": ["gemini-2.5-flash", "gemini-2.5-pro"],
|
|
478
|
+
"name": "Local-new-api"
|
|
479
|
+
}
|
|
480
|
+
],
|
|
481
|
+
"Router": {
|
|
482
|
+
"default": "Local-new-api,gemini-2.5-flash",
|
|
483
|
+
"background": "Local-new-api,gemini-2.5-flash",
|
|
484
|
+
"think": "Local-new-api,gemini-2.5-pro"
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
在 `.claude/settings.local.json` 中生成的配置:
|
|
490
|
+
|
|
491
|
+
```json
|
|
492
|
+
{
|
|
493
|
+
"env": {
|
|
494
|
+
"ANTHROPIC_AUTH_TOKEN": "your-api-key",
|
|
495
|
+
"ANTHROPIC_BASE_URL": "http://127.0.0.1:3456"
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
```
|
|
499
|
+
|
|
500
|
+
#### 在不同项目间切换
|
|
501
|
+
|
|
502
|
+
每个项目可以使用不同的 CCR 配置:
|
|
503
|
+
|
|
504
|
+
```bash
|
|
505
|
+
# 项目 A
|
|
506
|
+
cd ~/project-a
|
|
507
|
+
ais use ccr-account-1
|
|
508
|
+
claude
|
|
509
|
+
|
|
510
|
+
# 项目 B
|
|
511
|
+
cd ~/project-b
|
|
512
|
+
ais use ccr-account-2
|
|
513
|
+
claude
|
|
514
|
+
```
|
|
515
|
+
|
|
516
|
+
#### CCR 故障排除
|
|
517
|
+
|
|
518
|
+
**检查 CCR 配置**
|
|
519
|
+
```bash
|
|
520
|
+
# 查看你的 CCR 配置
|
|
521
|
+
cat ~/.claude-code-router/config.json
|
|
522
|
+
|
|
523
|
+
# 查看 Claude 配置
|
|
524
|
+
cat .claude/settings.local.json
|
|
525
|
+
|
|
526
|
+
# 或使用 doctor 命令
|
|
527
|
+
ais doctor
|
|
528
|
+
```
|
|
529
|
+
|
|
530
|
+
**CCR Router 未安装**
|
|
531
|
+
- 从 npm 安装:`npm install -g @musistudio/claude-code-router`
|
|
532
|
+
- 访问项目页面:https://github.com/musistudio/claude-code-router
|
|
533
|
+
|
|
534
|
+
**CCR Router 未重启**
|
|
535
|
+
- 确保 CCR CLI 已安装并在 PATH 中可用
|
|
536
|
+
- 如果自动重启失败,手动运行 `ccr restart`
|
|
537
|
+
- 检查 CCR Router 是否运行:`ccr status`
|
|
538
|
+
|
|
539
|
+
**Claude 未使用 CCR Router**
|
|
540
|
+
- 验证 `.claude/settings.local.json` 中的 `ANTHROPIC_BASE_URL` 指向正确的端口
|
|
541
|
+
- 检查 CCR Router 是否在配置的端口上运行
|
|
542
|
+
- 配置更改后重启 Claude Code
|
|
543
|
+
|
|
544
|
+
### Droids 集成
|
|
545
|
+
|
|
546
|
+
当你添加 **Droids** 类型账户并运行 `ais use` 时,工具会自动在项目目录中创建 `.droids/config.json` 配置文件。
|
|
547
|
+
|
|
548
|
+
#### 添加 Droids 账户
|
|
549
|
+
|
|
550
|
+
添加 Droids 账户时,你会看到有用的配置提示:
|
|
551
|
+
|
|
552
|
+
```bash
|
|
553
|
+
ais add my-droids-account
|
|
554
|
+
|
|
555
|
+
? Select account type: Droids
|
|
556
|
+
|
|
557
|
+
📝 Droids Configuration Tips:
|
|
558
|
+
• Droids configuration will be stored in .droids/config.json
|
|
559
|
+
• API URL is optional (defaults to Droids default endpoint)
|
|
560
|
+
• You can configure custom models and settings
|
|
561
|
+
|
|
562
|
+
? Enter API Key: sk-xxx...
|
|
563
|
+
? Enter API URL (optional): https://api.example.com
|
|
564
|
+
? Do you want to specify a model? (Optional) Yes
|
|
565
|
+
? Enter model name: droids-model-v1
|
|
566
|
+
```
|
|
567
|
+
|
|
568
|
+
#### 在项目中使用 Droids
|
|
569
|
+
|
|
570
|
+
使用 Droids 账户运行 `ais use` 后:
|
|
571
|
+
|
|
572
|
+
```bash
|
|
573
|
+
cd ~/my-project
|
|
574
|
+
ais use my-droids-account
|
|
575
|
+
|
|
576
|
+
# 输出:
|
|
577
|
+
# ✓ Switched to account 'my-droids-account' for current project.
|
|
578
|
+
# ✓ Droids configuration generated at: .droids/config.json
|
|
579
|
+
#
|
|
580
|
+
# 📖 Next Steps:
|
|
581
|
+
# Start interactive session: droid
|
|
582
|
+
# This will enter project-level interactive mode
|
|
583
|
+
# Droids will automatically use the configuration from .droids/config.json
|
|
584
|
+
```
|
|
585
|
+
|
|
586
|
+
工具会创建:
|
|
587
|
+
- **项目配置**:`.droids/config.json` 包含你的账户设置
|
|
588
|
+
|
|
589
|
+
#### 运行 Droids
|
|
590
|
+
|
|
591
|
+
启动 Droids 交互会话:
|
|
592
|
+
|
|
593
|
+
```bash
|
|
594
|
+
# 在项目目录中
|
|
595
|
+
droid
|
|
596
|
+
|
|
597
|
+
# Droids 会自动从 .droids/config.json 加载配置
|
|
598
|
+
```
|
|
599
|
+
|
|
600
|
+
#### Droids 配置结构
|
|
601
|
+
|
|
602
|
+
在 `.droids/config.json` 中生成的配置:
|
|
603
|
+
|
|
604
|
+
```json
|
|
605
|
+
{
|
|
606
|
+
"apiKey": "your-api-key",
|
|
607
|
+
"baseUrl": "https://api.example.com",
|
|
608
|
+
"model": "droids-model-v1",
|
|
609
|
+
"customSettings": {
|
|
610
|
+
"CUSTOM_VAR": "value"
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
```
|
|
614
|
+
|
|
615
|
+
#### 在不同项目间切换
|
|
616
|
+
|
|
617
|
+
每个项目可以使用不同的 Droids 账户:
|
|
618
|
+
|
|
619
|
+
```bash
|
|
620
|
+
# 项目 A
|
|
621
|
+
cd ~/project-a
|
|
622
|
+
ais use droids-account-1
|
|
623
|
+
droid
|
|
624
|
+
|
|
625
|
+
# 项目 B
|
|
626
|
+
cd ~/project-b
|
|
627
|
+
ais use droids-account-2
|
|
628
|
+
droid
|
|
629
|
+
```
|
|
630
|
+
|
|
631
|
+
#### Droids 故障排除
|
|
632
|
+
|
|
633
|
+
**检查 Droids 配置**
|
|
634
|
+
```bash
|
|
635
|
+
# 查看你的 Droids 配置
|
|
636
|
+
cat .droids/config.json
|
|
637
|
+
|
|
638
|
+
# 或使用 doctor 命令
|
|
639
|
+
ais doctor
|
|
640
|
+
```
|
|
641
|
+
|
|
642
|
+
**Droids CLI 未找到**
|
|
643
|
+
- 确保 Droids CLI 已安装并在 PATH 中可用
|
|
644
|
+
- 运行 `droid --version` 验证安装
|
|
645
|
+
|
|
387
646
|
#### 自定义环境变量
|
|
388
647
|
|
|
389
648
|
在创建账户时可以添加自定义环境变量。在提示时,使用 `KEY=VALUE` 格式输入:
|
|
@@ -425,6 +684,9 @@ ais add work-claude
|
|
|
425
684
|
# 添加 Codex 账户
|
|
426
685
|
ais add codex-dev
|
|
427
686
|
|
|
687
|
+
# 添加 Droids 账户
|
|
688
|
+
ais add droids-dev
|
|
689
|
+
|
|
428
690
|
# 列出所有账户
|
|
429
691
|
ais list
|
|
430
692
|
```
|
|
@@ -496,8 +758,16 @@ ais use correct-account
|
|
|
496
758
|
|
|
497
759
|
## 系统要求
|
|
498
760
|
|
|
499
|
-
- Node.js >=
|
|
500
|
-
- npm >=
|
|
761
|
+
- **Node.js**: >= 16.0.0
|
|
762
|
+
- **npm**: >= 7.0.0
|
|
763
|
+
|
|
764
|
+
**注意**: 此工具需要 Node.js 16 或更高版本(因为 commander@11.x 依赖要求)。你可以使用以下命令检查当前版本:
|
|
765
|
+
```bash
|
|
766
|
+
node --version
|
|
767
|
+
npm --version
|
|
768
|
+
```
|
|
769
|
+
|
|
770
|
+
如果需要升级 Node.js,请访问 [nodejs.org](https://nodejs.org/) 或使用版本管理器如 [nvm](https://github.com/nvm-sh/nvm)。
|
|
501
771
|
|
|
502
772
|
## 项目结构
|
|
503
773
|
|
|
@@ -594,6 +864,47 @@ MIT License - 欢迎在你的项目中使用此工具!
|
|
|
594
864
|
|
|
595
865
|
## 更新日志
|
|
596
866
|
|
|
867
|
+
### v1.6.0
|
|
868
|
+
- **CCR (Claude Code Router) 集成**:
|
|
869
|
+
- 完整支持 Claude Code Router
|
|
870
|
+
- 自动生成 `~/.claude-code-router/config.json` 配置
|
|
871
|
+
- Provider 和 Router 配置管理
|
|
872
|
+
- 配置更改后自动重启 CCR Router
|
|
873
|
+
- Claude Code 与本地 CCR Router 端点集成
|
|
874
|
+
- 支持 default、background 和 think 模型路由
|
|
875
|
+
- **Web UI 增强**:
|
|
876
|
+
- 添加账户状态检查,带颜色指示器(绿色:可用,橙色:不稳定,红色:不可用)
|
|
877
|
+
- 状态结果会保存并在页面加载时显示
|
|
878
|
+
- 实时状态检查,带"状态检查"按钮
|
|
879
|
+
- 改进账户卡片布局,状态显示在右上角
|
|
880
|
+
- 状态检查期间增强视觉反馈
|
|
881
|
+
- **配置改进**:
|
|
882
|
+
- CCR 账户自动生成 CCR 和 Claude 两种配置
|
|
883
|
+
- 从 CCR 配置动态读取端口用于 Claude 集成
|
|
884
|
+
- 更好的错误处理和用户反馈
|
|
885
|
+
|
|
886
|
+
### v1.5.7
|
|
887
|
+
- **Droids 集成**:
|
|
888
|
+
- 完整支持 Droids AI 助手
|
|
889
|
+
- 自动生成 `.droids/config.json` 配置文件
|
|
890
|
+
- Droids 账户的简单模型配置
|
|
891
|
+
- 交互会话命令:`droid`
|
|
892
|
+
- 增强 `ais doctor` 命令,支持 Droids 配置检测
|
|
893
|
+
- **UI 增强**:
|
|
894
|
+
- 添加类型筛选下拉框,快速过滤账户
|
|
895
|
+
- 按类型为账户卡片着色(Claude: 蓝色,Codex: 紫色,Droids: 绿色,Other: 橙色)
|
|
896
|
+
- 账户卡片左侧边框颜色指示器
|
|
897
|
+
- 改进视觉层次和用户体验
|
|
898
|
+
- **模型配置改进**:
|
|
899
|
+
- 为不同账户类型分离模型配置
|
|
900
|
+
- Claude: 复杂的模型组,支持多个模型设置
|
|
901
|
+
- Codex/Droids: 简单的模型字段,配置更直观
|
|
902
|
+
- 所有模型设置移至可折叠的"高级配置"区域
|
|
903
|
+
- **更好的用户指引**:
|
|
904
|
+
- 增强 `ais use` 命令,提供清晰的下一步操作说明
|
|
905
|
+
- 为每个 AI 助手提供特定类型的使用示例
|
|
906
|
+
- 交互模式提示而非一次性命令示例
|
|
907
|
+
|
|
597
908
|
### v1.5.1
|
|
598
909
|
- **Codex 集成增强**:
|
|
599
910
|
- 完整支持 Codex CLI 的 profile 配置
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai-account-switch",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "A cross-platform CLI tool to manage and switch Claude/Codex account configurations",
|
|
3
|
+
"version": "1.6.0",
|
|
4
|
+
"description": "A cross-platform CLI tool to manage and switch Claude/Codex/Droids account configurations",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": {
|
|
7
7
|
"ais": "./bin/ais.js"
|
|
@@ -14,11 +14,13 @@
|
|
|
14
14
|
"cli",
|
|
15
15
|
"claude",
|
|
16
16
|
"codex",
|
|
17
|
+
"droids",
|
|
17
18
|
"account",
|
|
18
19
|
"switch",
|
|
19
20
|
"cross-platform",
|
|
20
21
|
"claude-code",
|
|
21
|
-
"ai"
|
|
22
|
+
"ai",
|
|
23
|
+
"ai-assistant"
|
|
22
24
|
],
|
|
23
25
|
"author": "deanwanghewei@gmail.comnpm view ai-account-switch",
|
|
24
26
|
"license": "MIT",
|
|
@@ -31,7 +33,7 @@
|
|
|
31
33
|
"inquirer": "^8.2.5"
|
|
32
34
|
},
|
|
33
35
|
"engines": {
|
|
34
|
-
"node": ">=
|
|
36
|
+
"node": ">=16.0.0"
|
|
35
37
|
},
|
|
36
38
|
"repository": {
|
|
37
39
|
"type": "git",
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# Commands 模块说明
|
|
2
|
+
|
|
3
|
+
## 目录结构
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
commands/
|
|
7
|
+
├── README.md # 本文件 - 模块说明
|
|
8
|
+
├── helpers.js # ✅ 辅助函数 (maskApiKey, validateAccount)
|
|
9
|
+
├── account.js # ⏳ 账号管理命令
|
|
10
|
+
├── model.js # ⏳ 模型组管理命令
|
|
11
|
+
├── utility.js # ⏳ 工具类命令
|
|
12
|
+
└── index.js # ⏳ 统一导出接口
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## 模块职责
|
|
16
|
+
|
|
17
|
+
### helpers.js ✅
|
|
18
|
+
**辅助函数** - 所有模块共用的工具函数
|
|
19
|
+
|
|
20
|
+
- `maskApiKey(apiKey)` - API密钥遮罩显示
|
|
21
|
+
- `validateAccount(apiKey, apiUrl)` - 验证账号有效性
|
|
22
|
+
|
|
23
|
+
### account.js
|
|
24
|
+
**账号管理** - 处理账号的 CRUD 操作
|
|
25
|
+
|
|
26
|
+
- `addAccount(name, options)` - 添加新账号
|
|
27
|
+
- `listAccounts()` - 列出所有账号
|
|
28
|
+
- `useAccount(name)` - 切换到指定账号
|
|
29
|
+
- `showInfo()` - 显示当前项目账号信息
|
|
30
|
+
- `removeAccount(name)` - 删除账号
|
|
31
|
+
- `showCurrent()` - 显示当前账号名称
|
|
32
|
+
- `exportAccount(name)` - 导出账号配置
|
|
33
|
+
- `promptForModelGroup()` - 模型组配置提示(内部使用)
|
|
34
|
+
|
|
35
|
+
### model.js
|
|
36
|
+
**模型组管理** - 管理 Claude 账号的模型组配置
|
|
37
|
+
|
|
38
|
+
- `listModelGroups()` - 列出模型组
|
|
39
|
+
- `addModelGroup(name)` - 添加模型组
|
|
40
|
+
- `useModelGroup(name)` - 切换模型组
|
|
41
|
+
- `removeModelGroup(name)` - 删除模型组
|
|
42
|
+
- `showModelGroup(name)` - 显示模型组详情
|
|
43
|
+
|
|
44
|
+
### utility.js
|
|
45
|
+
**工具类命令** - 诊断和辅助功能
|
|
46
|
+
|
|
47
|
+
- `showPaths()` - 显示配置文件路径
|
|
48
|
+
- `doctor()` - 诊断配置问题
|
|
49
|
+
- `startUI()` - 启动 Web UI 管理界面
|
|
50
|
+
|
|
51
|
+
### index.js
|
|
52
|
+
**统一导出** - 导出所有命令供主程序使用
|
|
53
|
+
|
|
54
|
+
```javascript
|
|
55
|
+
module.exports = {
|
|
56
|
+
// Account commands
|
|
57
|
+
addAccount,
|
|
58
|
+
listAccounts,
|
|
59
|
+
useAccount,
|
|
60
|
+
showInfo,
|
|
61
|
+
removeAccount,
|
|
62
|
+
showCurrent,
|
|
63
|
+
exportAccount,
|
|
64
|
+
|
|
65
|
+
// Model commands
|
|
66
|
+
listModelGroups,
|
|
67
|
+
addModelGroup,
|
|
68
|
+
useModelGroup,
|
|
69
|
+
removeModelGroup,
|
|
70
|
+
showModelGroup,
|
|
71
|
+
|
|
72
|
+
// Utility commands
|
|
73
|
+
showPaths,
|
|
74
|
+
doctor,
|
|
75
|
+
startUI
|
|
76
|
+
};
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## 依赖关系
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
index.js (主入口)
|
|
83
|
+
↓
|
|
84
|
+
commands/index.js (命令导出)
|
|
85
|
+
↓
|
|
86
|
+
├─ account.js → helpers.js
|
|
87
|
+
├─ model.js → helpers.js
|
|
88
|
+
└─ utility.js → helpers.js
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## 迁移状态
|
|
92
|
+
|
|
93
|
+
✅ **重构已完成!** (2025-10-24)
|
|
94
|
+
|
|
95
|
+
- [x] helpers.js - 辅助函数模块
|
|
96
|
+
- [x] account.js - 账号管理模块
|
|
97
|
+
- [x] model.js - 模型组管理模块
|
|
98
|
+
- [x] utility.js - 工具类模块
|
|
99
|
+
- [x] index.js - 统一导出
|
|
100
|
+
- [x] 更新 src/index.js 引用 (已兼容)
|
|
101
|
+
- [x] 测试所有命令功能
|
|
102
|
+
- [x] 备份原文件 (src/commands.js → src/commands.js.bak)
|
|
103
|
+
|
|
104
|
+
## 优势
|
|
105
|
+
|
|
106
|
+
1. **模块化** - 每个文件职责单一,代码清晰
|
|
107
|
+
2. **可维护** - 修改某个功能只需关注对应模块
|
|
108
|
+
3. **可测试** - 独立模块易于编写单元测试
|
|
109
|
+
4. **可扩展** - 新增功能只需添加新模块或扩展现有模块
|
|
110
|
+
|
|
111
|
+
## 使用方式
|
|
112
|
+
|
|
113
|
+
```javascript
|
|
114
|
+
// 旧方式 (src/commands.js)
|
|
115
|
+
const { addAccount, listAccounts } = require('./commands');
|
|
116
|
+
|
|
117
|
+
// 新方式 (src/commands/index.js)
|
|
118
|
+
const { addAccount, listAccounts } = require('./commands');
|
|
119
|
+
// 或
|
|
120
|
+
const commands = require('./commands');
|
|
121
|
+
commands.addAccount();
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
接口保持不变,只是内部实现变成模块化。
|