ai-account-switch 1.5.0 → 1.5.2
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 +182 -0
- package/README_ZH.md +161 -1
- package/WINDOWS_INSTALLER.md +291 -0
- package/installer/README.md +83 -0
- package/installer/windows/ais-icon.svg +85 -0
- package/installer/windows/ais-setup.iss +114 -0
- package/installer/windows/build-installer.md +182 -0
- package/package.json +5 -2
- package/src/commands.js +212 -9
- package/src/config.js +108 -3
package/README.md
CHANGED
|
@@ -211,7 +211,14 @@ npm link
|
|
|
211
211
|
| `ais info` | - | Show current project's account info |
|
|
212
212
|
| `ais current` | - | Show current account name |
|
|
213
213
|
| `ais remove [name]` | `rm` | Remove an account |
|
|
214
|
+
| `ais model list` | `ls` | List all model groups for current account |
|
|
215
|
+
| `ais model add [name]` | - | Add a new model group |
|
|
216
|
+
| `ais model use <name>` | - | Switch to a different model group |
|
|
217
|
+
| `ais model remove [name]` | `rm` | Remove a model group |
|
|
218
|
+
| `ais model show [name]` | - | Show model group configuration |
|
|
219
|
+
| `ais ui` | - | Start web-based UI manager |
|
|
214
220
|
| `ais paths` | - | Show configuration file paths |
|
|
221
|
+
| `ais doctor` | - | Diagnose configuration issues |
|
|
215
222
|
| `ais export <name>` | - | Export account as JSON |
|
|
216
223
|
| `ais help` | - | Display help information |
|
|
217
224
|
| `ais --version` | - | Show version number |
|
|
@@ -358,6 +365,118 @@ When you run `ais use`, the tool automatically creates `.claude/settings.local.j
|
|
|
358
365
|
|
|
359
366
|
This ensures Claude Code CLI automatically uses the correct account for your project.
|
|
360
367
|
|
|
368
|
+
### Codex Integration
|
|
369
|
+
|
|
370
|
+
When you add a **Codex** type account and run `ais use`, the tool automatically creates a profile in `~/.codex/config.toml` and a `.codex-profile` file in your project directory.
|
|
371
|
+
|
|
372
|
+
#### Adding a Codex Account
|
|
373
|
+
|
|
374
|
+
When adding a Codex account, you'll see helpful configuration tips:
|
|
375
|
+
|
|
376
|
+
```bash
|
|
377
|
+
ais add my-codex-account
|
|
378
|
+
|
|
379
|
+
? Select account type: Codex
|
|
380
|
+
|
|
381
|
+
📝 Codex Configuration Tips:
|
|
382
|
+
• API URL should include the full path (e.g., https://api.example.com/v1)
|
|
383
|
+
• AIS will automatically add /v1 if missing
|
|
384
|
+
• Codex uses OpenAI-compatible API format
|
|
385
|
+
|
|
386
|
+
? Enter API Key: sk-xxx...
|
|
387
|
+
? Enter API URL (e.g., https://api.example.com or https://api.example.com/v1): https://zone.veloera.org
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
**Important Notes:**
|
|
391
|
+
- AIS automatically adds `/v1` to the API URL if it's missing
|
|
392
|
+
- The configuration uses `wire_api = "chat"` (OpenAI-compatible format)
|
|
393
|
+
- This prevents common issues like Cloudflare 400 errors
|
|
394
|
+
|
|
395
|
+
#### Using Codex with Your Project
|
|
396
|
+
|
|
397
|
+
After running `ais use` with a Codex account:
|
|
398
|
+
|
|
399
|
+
```bash
|
|
400
|
+
cd ~/my-project
|
|
401
|
+
ais use my-codex-account
|
|
402
|
+
|
|
403
|
+
# Output:
|
|
404
|
+
# ✓ Switched to account 'my-codex-account' for current project.
|
|
405
|
+
# ✓ Codex profile created: ais_my-project
|
|
406
|
+
# Use: codex --profile ais_my-project [prompt]
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
The tool creates:
|
|
410
|
+
1. **Global Profile**: `~/.codex/config.toml` with your account configuration
|
|
411
|
+
2. **Project Reference**: `.codex-profile` containing the profile name
|
|
412
|
+
|
|
413
|
+
#### Running Codex
|
|
414
|
+
|
|
415
|
+
Use Codex with the generated profile:
|
|
416
|
+
|
|
417
|
+
```bash
|
|
418
|
+
# In your project directory
|
|
419
|
+
codex --profile ais_my-project "your prompt here"
|
|
420
|
+
|
|
421
|
+
# Or use the profile name from .codex-profile
|
|
422
|
+
codex --profile $(cat .codex-profile) "your prompt"
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
#### Codex Configuration Structure
|
|
426
|
+
|
|
427
|
+
The generated configuration in `~/.codex/config.toml`:
|
|
428
|
+
|
|
429
|
+
```toml
|
|
430
|
+
# AIS Profile for project: /path/to/your/project
|
|
431
|
+
[profiles.ais_my-project]
|
|
432
|
+
model_provider = "ais_my-codex-account"
|
|
433
|
+
|
|
434
|
+
[model_providers.ais_my-codex-account]
|
|
435
|
+
name = "ais_my-codex-account"
|
|
436
|
+
base_url = "https://zone.veloera.org/v1"
|
|
437
|
+
wire_api = "chat"
|
|
438
|
+
http_headers = { "Authorization" = "Bearer sk-xxx..." }
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
#### Switching Between Projects
|
|
442
|
+
|
|
443
|
+
Each project can use a different Codex account:
|
|
444
|
+
|
|
445
|
+
```bash
|
|
446
|
+
# Project A
|
|
447
|
+
cd ~/project-a
|
|
448
|
+
ais use codex-account-1
|
|
449
|
+
codex --profile ais_project-a "implement feature X"
|
|
450
|
+
|
|
451
|
+
# Project B
|
|
452
|
+
cd ~/project-b
|
|
453
|
+
ais use codex-account-2
|
|
454
|
+
codex --profile ais_project-b "fix bug Y"
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
#### Troubleshooting Codex
|
|
458
|
+
|
|
459
|
+
**Error: "duplicate key" in TOML**
|
|
460
|
+
- This happens if profiles weren't cleaned up properly
|
|
461
|
+
- Solution: Run `ais use <account>` again to regenerate the configuration
|
|
462
|
+
|
|
463
|
+
**Error: "400 Bad Request" from Cloudflare**
|
|
464
|
+
- This usually means the API URL is incorrect
|
|
465
|
+
- Solution: Make sure your API URL includes `/v1` or let AIS add it automatically
|
|
466
|
+
- Run `ais use <account>` to regenerate with the correct configuration
|
|
467
|
+
|
|
468
|
+
**Check Codex Configuration**
|
|
469
|
+
```bash
|
|
470
|
+
# View your Codex profile
|
|
471
|
+
cat .codex-profile
|
|
472
|
+
|
|
473
|
+
# Check the configuration
|
|
474
|
+
grep -A 10 "$(cat .codex-profile)" ~/.codex/config.toml
|
|
475
|
+
|
|
476
|
+
# Or use the doctor command
|
|
477
|
+
ais doctor
|
|
478
|
+
```
|
|
479
|
+
|
|
361
480
|
#### Custom Environment Variables
|
|
362
481
|
|
|
363
482
|
You can add custom environment variables when creating an account. When prompted, enter them in `KEY=VALUE` format:
|
|
@@ -546,6 +665,69 @@ MIT License - feel free to use this tool in your projects!
|
|
|
546
665
|
|
|
547
666
|
## Changelog
|
|
548
667
|
|
|
668
|
+
### v1.5.1
|
|
669
|
+
- **Codex Integration Enhancements**:
|
|
670
|
+
- Added full support for Codex CLI with profile-based configuration
|
|
671
|
+
- Automatic generation of `~/.codex/config.toml` profiles for Codex accounts
|
|
672
|
+
- Project-level `.codex-profile` file for easy profile reference
|
|
673
|
+
- Smart API URL handling: automatically adds `/v1` path if missing
|
|
674
|
+
- Uses OpenAI-compatible `wire_api = "chat"` format
|
|
675
|
+
- Prevents Cloudflare 400 errors with correct configuration
|
|
676
|
+
- **Improved User Experience**:
|
|
677
|
+
- Configuration tips displayed when adding Codex accounts
|
|
678
|
+
- Usage instructions shown after account creation
|
|
679
|
+
- Enhanced `ais doctor` command with Codex configuration detection
|
|
680
|
+
- Better duplicate profile cleanup in TOML files
|
|
681
|
+
- **Bug Fixes**:
|
|
682
|
+
- Fixed duplicate profile key errors in Codex configuration
|
|
683
|
+
- Improved profile deletion regex patterns
|
|
684
|
+
- Separated Claude and Codex configuration generation logic
|
|
685
|
+
- **Documentation**:
|
|
686
|
+
- Comprehensive Codex integration guide in README
|
|
687
|
+
- Troubleshooting section for common Codex issues
|
|
688
|
+
- Examples for multi-project Codex usage
|
|
689
|
+
|
|
690
|
+
### v1.5.0
|
|
691
|
+
- **Model Groups Management System**:
|
|
692
|
+
- Refactored model configuration to use flexible Model Groups
|
|
693
|
+
- Each account can have multiple model groups with different configurations
|
|
694
|
+
- Quick switching between model groups with automatic Claude config updates
|
|
695
|
+
- **New CLI Commands**:
|
|
696
|
+
- `ais model list/ls` - List all model groups for current account
|
|
697
|
+
- `ais model add [name]` - Create a new model group
|
|
698
|
+
- `ais model use <name>` - Switch to a different model group
|
|
699
|
+
- `ais model remove/rm [name]` - Remove a model group
|
|
700
|
+
- `ais model show [name]` - Show model group configuration
|
|
701
|
+
- **Enhancements**:
|
|
702
|
+
- Enhanced account creation workflow with model group support
|
|
703
|
+
- Web UI updated with collapsible model group management
|
|
704
|
+
- Fixed model configuration not switching when changing accounts
|
|
705
|
+
- Better color consistency in CLI output
|
|
706
|
+
- DEFAULT_MODEL auto-fills other model configs when not specified
|
|
707
|
+
- **Backward Compatibility**:
|
|
708
|
+
- Maintains support for old modelConfig structure
|
|
709
|
+
- Existing accounts continue to work without migration
|
|
710
|
+
|
|
711
|
+
### v1.4.0
|
|
712
|
+
- **Added Web UI Management Interface**:
|
|
713
|
+
- Modern single-page application with dark/light theme support
|
|
714
|
+
- Bilingual support (English/Chinese), default English
|
|
715
|
+
- Visual account management: CRUD operations at a glance
|
|
716
|
+
- Import/Export functionality: batch manage account configurations
|
|
717
|
+
- Real-time search and filter accounts
|
|
718
|
+
- Custom environment variables configuration
|
|
719
|
+
- Theme follows system settings automatically
|
|
720
|
+
- iOS-style theme toggle switch
|
|
721
|
+
- **Port Optimization**:
|
|
722
|
+
- UI server uses random high ports (49152-65535)
|
|
723
|
+
- Automatic port conflict detection and retry
|
|
724
|
+
- **UI Improvements**:
|
|
725
|
+
- Fixed inconsistent button positioning in account cards
|
|
726
|
+
- Buttons now consistently fixed at card bottom
|
|
727
|
+
- **Removed Organization ID**:
|
|
728
|
+
- Simplified account configuration process
|
|
729
|
+
- Removed organization ID option from CLI and UI
|
|
730
|
+
|
|
549
731
|
### v1.3.0
|
|
550
732
|
- **Improved custom environment variables input**:
|
|
551
733
|
- One-line `KEY=VALUE` format input (e.g., `CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1`)
|
package/README_ZH.md
CHANGED
|
@@ -219,10 +219,15 @@ npm link
|
|
|
219
219
|
| `ais info` | - | 显示当前项目的账户信息 |
|
|
220
220
|
| `ais current` | - | 显示当前账户名称 |
|
|
221
221
|
| `ais remove [name]` | `rm` | 删除账户 |
|
|
222
|
+
| `ais model list` | `ls` | 列出当前账户的所有模型组 |
|
|
223
|
+
| `ais model add [name]` | - | 添加新的模型组 |
|
|
224
|
+
| `ais model use <name>` | - | 切换到不同的模型组 |
|
|
225
|
+
| `ais model remove [name]` | `rm` | 删除模型组 |
|
|
226
|
+
| `ais model show [name]` | - | 显示模型组配置 |
|
|
227
|
+
| `ais ui` | - | 启动 Web UI 管理界面 |
|
|
222
228
|
| `ais paths` | - | 显示配置文件路径 |
|
|
223
229
|
| `ais doctor` | - | 诊断 Claude Code 配置问题 |
|
|
224
230
|
| `ais export <name>` | - | 导出账户为 JSON 格式 |
|
|
225
|
-
| `ais ui` | - | 启动 Web UI 管理界面 |
|
|
226
231
|
| `ais help` | - | 显示帮助信息 |
|
|
227
232
|
| `ais --version` | - | 显示版本号 |
|
|
228
233
|
|
|
@@ -415,6 +420,118 @@ ais export my-claude-account
|
|
|
415
420
|
|
|
416
421
|
这确保 Claude Code CLI 自动使用项目的正确账户。
|
|
417
422
|
|
|
423
|
+
### Codex 集成
|
|
424
|
+
|
|
425
|
+
当你添加 **Codex** 类型账户并运行 `ais use` 时,工具会自动在 `~/.codex/config.toml` 中创建 profile,并在项目目录中创建 `.codex-profile` 文件。
|
|
426
|
+
|
|
427
|
+
#### 添加 Codex 账户
|
|
428
|
+
|
|
429
|
+
添加 Codex 账户时,你会看到有用的配置提示:
|
|
430
|
+
|
|
431
|
+
```bash
|
|
432
|
+
ais add my-codex-account
|
|
433
|
+
|
|
434
|
+
? Select account type: Codex
|
|
435
|
+
|
|
436
|
+
📝 Codex Configuration Tips:
|
|
437
|
+
• API URL should include the full path (e.g., https://api.example.com/v1)
|
|
438
|
+
• AIS will automatically add /v1 if missing
|
|
439
|
+
• Codex uses OpenAI-compatible API format
|
|
440
|
+
|
|
441
|
+
? Enter API Key: sk-xxx...
|
|
442
|
+
? Enter API URL (e.g., https://api.example.com or https://api.example.com/v1): https://zone.veloera.org
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
**重要说明:**
|
|
446
|
+
- AIS 会自动为 API URL 添加 `/v1` 路径(如果缺少)
|
|
447
|
+
- 配置使用 `wire_api = "chat"`(OpenAI 兼容格式)
|
|
448
|
+
- 这可以防止常见的 Cloudflare 400 错误
|
|
449
|
+
|
|
450
|
+
#### 在项目中使用 Codex
|
|
451
|
+
|
|
452
|
+
使用 Codex 账户运行 `ais use` 后:
|
|
453
|
+
|
|
454
|
+
```bash
|
|
455
|
+
cd ~/my-project
|
|
456
|
+
ais use my-codex-account
|
|
457
|
+
|
|
458
|
+
# 输出:
|
|
459
|
+
# ✓ Switched to account 'my-codex-account' for current project.
|
|
460
|
+
# ✓ Codex profile created: ais_my-project
|
|
461
|
+
# Use: codex --profile ais_my-project [prompt]
|
|
462
|
+
```
|
|
463
|
+
|
|
464
|
+
工具会创建:
|
|
465
|
+
1. **全局 Profile**:`~/.codex/config.toml` 包含你的账户配置
|
|
466
|
+
2. **项目引用**:`.codex-profile` 包含 profile 名称
|
|
467
|
+
|
|
468
|
+
#### 运行 Codex
|
|
469
|
+
|
|
470
|
+
使用生成的 profile 运行 Codex:
|
|
471
|
+
|
|
472
|
+
```bash
|
|
473
|
+
# 在项目目录中
|
|
474
|
+
codex --profile ais_my-project "your prompt here"
|
|
475
|
+
|
|
476
|
+
# 或使用 .codex-profile 中的 profile 名称
|
|
477
|
+
codex --profile $(cat .codex-profile) "your prompt"
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
#### Codex 配置结构
|
|
481
|
+
|
|
482
|
+
在 `~/.codex/config.toml` 中生成的配置:
|
|
483
|
+
|
|
484
|
+
```toml
|
|
485
|
+
# AIS Profile for project: /path/to/your/project
|
|
486
|
+
[profiles.ais_my-project]
|
|
487
|
+
model_provider = "ais_my-codex-account"
|
|
488
|
+
|
|
489
|
+
[model_providers.ais_my-codex-account]
|
|
490
|
+
name = "ais_my-codex-account"
|
|
491
|
+
base_url = "https://zone.veloera.org/v1"
|
|
492
|
+
wire_api = "chat"
|
|
493
|
+
http_headers = { "Authorization" = "Bearer sk-xxx..." }
|
|
494
|
+
```
|
|
495
|
+
|
|
496
|
+
#### 在不同项目间切换
|
|
497
|
+
|
|
498
|
+
每个项目可以使用不同的 Codex 账户:
|
|
499
|
+
|
|
500
|
+
```bash
|
|
501
|
+
# 项目 A
|
|
502
|
+
cd ~/project-a
|
|
503
|
+
ais use codex-account-1
|
|
504
|
+
codex --profile ais_project-a "implement feature X"
|
|
505
|
+
|
|
506
|
+
# 项目 B
|
|
507
|
+
cd ~/project-b
|
|
508
|
+
ais use codex-account-2
|
|
509
|
+
codex --profile ais_project-b "fix bug Y"
|
|
510
|
+
```
|
|
511
|
+
|
|
512
|
+
#### Codex 故障排除
|
|
513
|
+
|
|
514
|
+
**错误:"duplicate key" in TOML**
|
|
515
|
+
- 这是因为 profile 没有正确清理
|
|
516
|
+
- 解决方案:再次运行 `ais use <account>` 重新生成配置
|
|
517
|
+
|
|
518
|
+
**错误:"400 Bad Request" from Cloudflare**
|
|
519
|
+
- 这通常意味着 API URL 不正确
|
|
520
|
+
- 解决方案:确保 API URL 包含 `/v1` 或让 AIS 自动添加
|
|
521
|
+
- 运行 `ais use <account>` 使用正确的配置重新生成
|
|
522
|
+
|
|
523
|
+
**检查 Codex 配置**
|
|
524
|
+
```bash
|
|
525
|
+
# 查看你的 Codex profile
|
|
526
|
+
cat .codex-profile
|
|
527
|
+
|
|
528
|
+
# 检查配置
|
|
529
|
+
grep -A 10 "$(cat .codex-profile)" ~/.codex/config.toml
|
|
530
|
+
|
|
531
|
+
# 或使用 doctor 命令
|
|
532
|
+
ais doctor
|
|
533
|
+
```
|
|
534
|
+
|
|
418
535
|
#### 自定义环境变量
|
|
419
536
|
|
|
420
537
|
在创建账户时可以添加自定义环境变量。在提示时,使用 `KEY=VALUE` 格式输入:
|
|
@@ -625,6 +742,49 @@ MIT License - 欢迎在你的项目中使用此工具!
|
|
|
625
742
|
|
|
626
743
|
## 更新日志
|
|
627
744
|
|
|
745
|
+
### v1.5.1
|
|
746
|
+
- **Codex 集成增强**:
|
|
747
|
+
- 完整支持 Codex CLI 的 profile 配置
|
|
748
|
+
- 自动为 Codex 账户生成 `~/.codex/config.toml` profiles
|
|
749
|
+
- 项目级 `.codex-profile` 文件方便引用 profile
|
|
750
|
+
- 智能 API URL 处理:自动添加 `/v1` 路径(如果缺少)
|
|
751
|
+
- 使用 OpenAI 兼容的 `wire_api = "chat"` 格式
|
|
752
|
+
- 通过正确配置防止 Cloudflare 400 错误
|
|
753
|
+
- **用户体验改进**:
|
|
754
|
+
- 添加 Codex 账户时显示配置提示
|
|
755
|
+
- 账户创建后显示使用说明
|
|
756
|
+
- 增强 `ais doctor` 命令,支持 Codex 配置检测
|
|
757
|
+
- 改进 TOML 文件中的重复 profile 清理
|
|
758
|
+
- **Bug 修复**:
|
|
759
|
+
- 修复 Codex 配置中的重复 profile key 错误
|
|
760
|
+
- 改进 profile 删除的正则表达式模式
|
|
761
|
+
- 分离 Claude 和 Codex 配置生成逻辑
|
|
762
|
+
- **文档更新**:
|
|
763
|
+
- README 中添加全面的 Codex 集成指南
|
|
764
|
+
- 常见 Codex 问题的故障排除部分
|
|
765
|
+
- 多项目 Codex 使用示例
|
|
766
|
+
|
|
767
|
+
### v1.5.0
|
|
768
|
+
- **模型组管理系统**:
|
|
769
|
+
- 重构模型配置为灵活的模型组(Model Groups)系统
|
|
770
|
+
- 每个账户可以拥有多个不同配置的模型组
|
|
771
|
+
- 快速切换模型组,自动更新 Claude 配置
|
|
772
|
+
- **新增 CLI 命令**:
|
|
773
|
+
- `ais model list/ls` - 列出当前账户的所有模型组
|
|
774
|
+
- `ais model add [name]` - 创建新的模型组
|
|
775
|
+
- `ais model use <name>` - 切换到不同的模型组
|
|
776
|
+
- `ais model remove/rm [name]` - 删除模型组
|
|
777
|
+
- `ais model show [name]` - 显示模型组配置详情
|
|
778
|
+
- **功能增强**:
|
|
779
|
+
- 增强账户创建流程,支持模型组配置
|
|
780
|
+
- Web UI 更新,支持可折叠的模型组管理界面
|
|
781
|
+
- 修复切换账户时模型配置不更新的问题
|
|
782
|
+
- 优化 CLI 输出颜色一致性
|
|
783
|
+
- DEFAULT_MODEL 自动填充其他未设置的模型配置
|
|
784
|
+
- **向后兼容**:
|
|
785
|
+
- 保持对旧 modelConfig 结构的支持
|
|
786
|
+
- 现有账户无需迁移即可继续使用
|
|
787
|
+
|
|
628
788
|
### v1.4.0
|
|
629
789
|
- **添加 Web UI 管理界面**:
|
|
630
790
|
- 现代化单页面应用,支持深色/浅色主题
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
# Windows 安装程序优化方案
|
|
2
|
+
|
|
3
|
+
## 概述
|
|
4
|
+
|
|
5
|
+
为了提供更好的 Windows 用户体验,我们使用 **Inno Setup** 创建了一个专业的 Windows 安装程序。
|
|
6
|
+
|
|
7
|
+
## 用户体验对比
|
|
8
|
+
|
|
9
|
+
### 之前(手动安装)
|
|
10
|
+
1. 下载 `ais-win.exe`
|
|
11
|
+
2. 手动创建目录
|
|
12
|
+
3. 移动文件到目录
|
|
13
|
+
4. 手动添加到 PATH(需要打开系统设置)
|
|
14
|
+
5. 重启终端
|
|
15
|
+
6. 验证安装
|
|
16
|
+
|
|
17
|
+
### 现在(一键安装)
|
|
18
|
+
1. 下载 `ais-setup-1.5.1.exe`
|
|
19
|
+
2. 双击运行
|
|
20
|
+
3. 点击"下一步"几次
|
|
21
|
+
4. 完成!
|
|
22
|
+
|
|
23
|
+
## 安装程序特性
|
|
24
|
+
|
|
25
|
+
### ✅ 自动化功能
|
|
26
|
+
- **自动 PATH 配置**:安装时自动添加到用户 PATH
|
|
27
|
+
- **自动卸载**:完整的卸载程序,包括 PATH 清理
|
|
28
|
+
- **无需管理员权限**:安装到用户目录,普通用户即可安装
|
|
29
|
+
|
|
30
|
+
### ✅ 用户友好
|
|
31
|
+
- **现代化向导界面**:清晰的安装步骤
|
|
32
|
+
- **多语言支持**:英文和中文界面
|
|
33
|
+
- **开始菜单集成**:自动创建开始菜单项
|
|
34
|
+
- **可选桌面快捷方式**:用户可选择是否创建
|
|
35
|
+
|
|
36
|
+
### ✅ 专业性
|
|
37
|
+
- **版本管理**:显示版本号和发布信息
|
|
38
|
+
- **许可协议**:显示 MIT 许可证
|
|
39
|
+
- **卸载程序**:标准的 Windows 卸载体验
|
|
40
|
+
|
|
41
|
+
## 技术实现
|
|
42
|
+
|
|
43
|
+
### 使用的工具
|
|
44
|
+
|
|
45
|
+
**Inno Setup**
|
|
46
|
+
- 免费开源的 Windows 安装程序制作工具
|
|
47
|
+
- 被广泛使用(Node.js、VS Code 等都使用它)
|
|
48
|
+
- 支持脚本化配置
|
|
49
|
+
- 生成标准的 Windows 安装程序
|
|
50
|
+
|
|
51
|
+
### 文件结构
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
installer/
|
|
55
|
+
├── README.md # 安装程序说明
|
|
56
|
+
└── windows/
|
|
57
|
+
├── ais-setup.iss # Inno Setup 配置脚本
|
|
58
|
+
├── ais-icon.ico # 应用图标(可选)
|
|
59
|
+
└── build-installer.md # 构建说明文档
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### 自动化构建
|
|
63
|
+
|
|
64
|
+
GitHub Actions 工作流 (`.github/workflows/build-installer.yml`):
|
|
65
|
+
- 在创建新 tag 时自动触发
|
|
66
|
+
- 构建 Windows 可执行文件
|
|
67
|
+
- 使用 Inno Setup 创建安装程序
|
|
68
|
+
- 自动上传到 GitHub Releases
|
|
69
|
+
|
|
70
|
+
## 构建安装程序
|
|
71
|
+
|
|
72
|
+
### 前提条件
|
|
73
|
+
|
|
74
|
+
1. **安装 Inno Setup**
|
|
75
|
+
- 下载:https://jrsoftware.org/isdl.php
|
|
76
|
+
- 版本:6.0 或更高
|
|
77
|
+
|
|
78
|
+
2. **构建可执行文件**
|
|
79
|
+
```bash
|
|
80
|
+
npm run build:win
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### 构建方法
|
|
84
|
+
|
|
85
|
+
**方法 1:使用 npm 脚本(推荐)**
|
|
86
|
+
```bash
|
|
87
|
+
npm run build:win-installer
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
**方法 2:使用 Inno Setup GUI**
|
|
91
|
+
1. 打开 Inno Setup Compiler
|
|
92
|
+
2. 打开 `installer/windows/ais-setup.iss`
|
|
93
|
+
3. 点击 "Build" → "Compile"
|
|
94
|
+
|
|
95
|
+
**方法 3:命令行**
|
|
96
|
+
```bash
|
|
97
|
+
"C:\Program Files (x86)\Inno Setup 6\ISCC.exe" installer\windows\ais-setup.iss
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### 输出
|
|
101
|
+
|
|
102
|
+
安装程序将生成在:
|
|
103
|
+
```
|
|
104
|
+
dist/installer/ais-setup-1.5.1.exe
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## 安装程序功能详解
|
|
108
|
+
|
|
109
|
+
### 安装过程
|
|
110
|
+
|
|
111
|
+
1. **欢迎页面**
|
|
112
|
+
- 显示应用名称和版本
|
|
113
|
+
- 多语言支持
|
|
114
|
+
|
|
115
|
+
2. **许可协议**
|
|
116
|
+
- 显示 MIT 许可证
|
|
117
|
+
- 用户需要接受才能继续
|
|
118
|
+
|
|
119
|
+
3. **选择安装目录**
|
|
120
|
+
- 默认:`C:\Users\<username>\AppData\Local\Programs\AI Account Switch`
|
|
121
|
+
- 用户可以自定义
|
|
122
|
+
|
|
123
|
+
4. **选择组件**
|
|
124
|
+
- 添加到 PATH(推荐,默认选中)
|
|
125
|
+
- 创建桌面快捷方式(可选)
|
|
126
|
+
|
|
127
|
+
5. **安装**
|
|
128
|
+
- 复制文件
|
|
129
|
+
- 配置 PATH
|
|
130
|
+
- 创建快捷方式
|
|
131
|
+
|
|
132
|
+
6. **完成**
|
|
133
|
+
- 显示成功消息
|
|
134
|
+
- 提示用户可以使用 `ais` 命令
|
|
135
|
+
|
|
136
|
+
### 卸载过程
|
|
137
|
+
|
|
138
|
+
用户可以通过以下方式卸载:
|
|
139
|
+
- 开始菜单 → AI Account Switch → Uninstall
|
|
140
|
+
- Windows 设置 → 应用 → AI Account Switch → 卸载
|
|
141
|
+
|
|
142
|
+
卸载程序会:
|
|
143
|
+
- 删除所有安装的文件
|
|
144
|
+
- 从 PATH 中移除
|
|
145
|
+
- 删除开始菜单项
|
|
146
|
+
- 删除桌面快捷方式(如果有)
|
|
147
|
+
|
|
148
|
+
## PATH 配置原理
|
|
149
|
+
|
|
150
|
+
### 自动添加到 PATH
|
|
151
|
+
|
|
152
|
+
安装程序使用 Pascal 脚本自动修改用户的 PATH 环境变量:
|
|
153
|
+
|
|
154
|
+
```pascal
|
|
155
|
+
procedure EnvAddPath(Path: string);
|
|
156
|
+
var
|
|
157
|
+
Paths: string;
|
|
158
|
+
begin
|
|
159
|
+
{ 读取当前 PATH }
|
|
160
|
+
if not RegQueryStringValue(HKEY_CURRENT_USER, 'Environment', 'Path', Paths)
|
|
161
|
+
then Paths := '';
|
|
162
|
+
|
|
163
|
+
{ 检查是否已存在 }
|
|
164
|
+
if Pos(';' + Uppercase(Path) + ';', ';' + Uppercase(Paths) + ';') > 0 then exit;
|
|
165
|
+
|
|
166
|
+
{ 添加到 PATH }
|
|
167
|
+
Paths := Paths + ';'+ Path +';'
|
|
168
|
+
|
|
169
|
+
{ 写入注册表 }
|
|
170
|
+
RegWriteStringValue(HKEY_CURRENT_USER, 'Environment', 'Path', Paths);
|
|
171
|
+
end;
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### 自动从 PATH 移除
|
|
175
|
+
|
|
176
|
+
卸载时自动清理:
|
|
177
|
+
|
|
178
|
+
```pascal
|
|
179
|
+
procedure EnvRemovePath(Path: string);
|
|
180
|
+
var
|
|
181
|
+
Paths: string;
|
|
182
|
+
P: Integer;
|
|
183
|
+
begin
|
|
184
|
+
{ 读取当前 PATH }
|
|
185
|
+
if not RegQueryStringValue(HKEY_CURRENT_USER, 'Environment', 'Path', Paths) then
|
|
186
|
+
exit;
|
|
187
|
+
|
|
188
|
+
{ 查找并删除 }
|
|
189
|
+
P := Pos(';' + Uppercase(Path) + ';', ';' + Uppercase(Paths) + ';');
|
|
190
|
+
if P = 0 then exit;
|
|
191
|
+
|
|
192
|
+
Delete(Paths, P - 1, Length(Path) + 1);
|
|
193
|
+
|
|
194
|
+
{ 写入注册表 }
|
|
195
|
+
RegWriteStringValue(HKEY_CURRENT_USER, 'Environment', 'Path', Paths);
|
|
196
|
+
end;
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
## 自定义配置
|
|
200
|
+
|
|
201
|
+
### 修改版本号
|
|
202
|
+
|
|
203
|
+
编辑 `installer/windows/ais-setup.iss`:
|
|
204
|
+
```iss
|
|
205
|
+
#define MyAppVersion "1.5.1" ; 修改这里
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### 修改安装目录
|
|
209
|
+
|
|
210
|
+
```iss
|
|
211
|
+
DefaultDirName={autopf}\{#MyAppName} ; 当前:Program Files
|
|
212
|
+
; 或使用:
|
|
213
|
+
DefaultDirName={localappdata}\Programs\{#MyAppName} ; 用户目录
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### 添加更多文件
|
|
217
|
+
|
|
218
|
+
在 `[Files]` 部分添加:
|
|
219
|
+
```iss
|
|
220
|
+
[Files]
|
|
221
|
+
Source: "path\to\file"; DestDir: "{app}"; Flags: ignoreversion
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### 添加注册表项
|
|
225
|
+
|
|
226
|
+
在 `[Registry]` 部分添加:
|
|
227
|
+
```iss
|
|
228
|
+
[Registry]
|
|
229
|
+
Root: HKCU; Subkey: "Software\AIAccountSwitch"; ValueType: string; ValueName: "InstallPath"; ValueData: "{app}"
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
## 发布流程
|
|
233
|
+
|
|
234
|
+
### 手动发布
|
|
235
|
+
|
|
236
|
+
1. 构建安装程序:
|
|
237
|
+
```bash
|
|
238
|
+
npm run build:win-installer
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
2. 测试安装程序(在干净的 Windows 机器上)
|
|
242
|
+
|
|
243
|
+
3. 上传到 GitHub Releases
|
|
244
|
+
|
|
245
|
+
### 自动发布
|
|
246
|
+
|
|
247
|
+
1. 创建新 tag:
|
|
248
|
+
```bash
|
|
249
|
+
git tag v1.5.1
|
|
250
|
+
git push origin v1.5.1
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
2. GitHub Actions 自动:
|
|
254
|
+
- 构建可执行文件
|
|
255
|
+
- 创建安装程序
|
|
256
|
+
- 上传到 Releases
|
|
257
|
+
|
|
258
|
+
## 优势总结
|
|
259
|
+
|
|
260
|
+
| 特性 | 手动安装 | 安装程序 |
|
|
261
|
+
|------|---------|---------|
|
|
262
|
+
| 安装步骤 | 6+ 步 | 3 步 |
|
|
263
|
+
| PATH 配置 | 手动 | 自动 |
|
|
264
|
+
| 管理员权限 | 有时需要 | 不需要 |
|
|
265
|
+
| 卸载 | 手动删除 | 一键卸载 |
|
|
266
|
+
| 开始菜单 | 无 | 有 |
|
|
267
|
+
| 用户体验 | 复杂 | 简单 |
|
|
268
|
+
| 专业性 | 低 | 高 |
|
|
269
|
+
|
|
270
|
+
## 下一步
|
|
271
|
+
|
|
272
|
+
1. ✅ 创建 Inno Setup 脚本
|
|
273
|
+
2. ✅ 添加 GitHub Actions 工作流
|
|
274
|
+
3. ✅ 更新 package.json 脚本
|
|
275
|
+
4. ⏳ 创建应用图标(可选但推荐)
|
|
276
|
+
5. ⏳ 在 Windows 机器上测试
|
|
277
|
+
6. ⏳ 更新 README 安装说明
|
|
278
|
+
7. ⏳ 发布新版本
|
|
279
|
+
|
|
280
|
+
## 参考资源
|
|
281
|
+
|
|
282
|
+
- [Inno Setup 官方文档](https://jrsoftware.org/ishelp/)
|
|
283
|
+
- [Inno Setup 示例](https://jrsoftware.org/isinfo.php)
|
|
284
|
+
- [PATH 环境变量管理](https://jrsoftware.org/ishelp/index.php?topic=setup_changesenvironment)
|
|
285
|
+
|
|
286
|
+
## 支持
|
|
287
|
+
|
|
288
|
+
如有问题,请查看:
|
|
289
|
+
- `installer/windows/build-installer.md` - 详细构建说明
|
|
290
|
+
- `installer/README.md` - 安装程序概述
|
|
291
|
+
- GitHub Issues - 报告问题
|