Skip to content

feat: 新增 GA Switch 多路由管理系统与 Qt 桌面前端#109

Closed
abraxas914 wants to merge 3 commits intolsdefine:mainfrom
abraxas914:feat/ga-switch-qt-frontend
Closed

feat: 新增 GA Switch 多路由管理系统与 Qt 桌面前端#109
abraxas914 wants to merge 3 commits intolsdefine:mainfrom
abraxas914:feat/ga-switch-qt-frontend

Conversation

@abraxas914
Copy link
Copy Markdown

@abraxas914 abraxas914 commented Apr 19, 2026

No description provided.

## 核心功能

### ga_switch —— 结构化路由管理后端
- 新增 `ga_switch/` 模块,提供完整的多路由管理能力
- `models.py`:Provider / Route / DiagnosticEvent 领域模型
- `store.py`:SQLite 持久化存储,支持路由配置的增删改查
- `service.py`:对外服务层,提供 get_ui_snapshot / upsert_provider / upsert_route / run_model_test / import_legacy_mykey
- `viewmodel.py`:纯 Python 视图模型层,将快照转为前端可直接消费的结构化数据
- `diagnostics.py`:诊断事件记录与分类
- `testing.py`:路由连通性测试工具

### agentmain.py —— Agent 与路由系统集成
- GeneraticAgent 持有 ga_switch 服务实例
- 新增 set_active_route() 支持按路由 ID 或索引切换
- 新增 reload_llm_config() 支持软重载(不重启进程)
- 新增 describe_llms() 返回结构化路由描述(含诊断信息)
- 支持从结构化 store 和 legacy mykey.py 两种配置源构建客户端

### llmcore.py —— 诊断能力增强
- LLMSession 新增诊断字段:last_error_kind / last_error_message / last_error_at / last_ok_at / last_status_code / last_latency_ms / last_ttfb_ms
- 新增 _record_success() / _record_error() / describe_diagnostics() 方法
- 新增 route_id / route_name / provider_id 等路由元数据字段
- 超时配置支持 connect_timeout / read_timeout 分离,并根据 stream 模式自动调整默认值

### frontends/qt_switch.py —— Qt 路由管理页面(新增)
- RouteCenterPage:完整的路由管理工作台
- 四个一级导航:总览 / 全部路由 / 模型服务 / 诊断记录
- 支持创建/编辑路由、创建/编辑模型服务、切换当前路由
- 支持连通性测试、软重载、导入 mykey
- 渐进式披露:默认显示摘要,高级设置可展开
- 全中文界面,空状态有明确操作入口

### frontends/qtapp.py —— Qt 聊天面板优化
- 新增 design_tokens.py 设计 token 系统(字体/颜色/间距/圆角)
- 统一字体栈:system-ui / Segoe UI / Microsoft YaHei(无需下载字体包)
- 统一颜色系统:全面替换紫色为蓝色主题(#3b82f6)
- 移除侧边条纹设计(border-left: 3px solid),改为全边框高亮
- 修复窗口调整大小:移除 setMask() 阻塞,QSizeGrip 现在可正常工作
- 统一圆角系统:窗口 8px / 按钮 4-6px
- 聊天页顶部路由状态条与路由页双向联动
- 悬浮按钮支持右键菜单(强制终止 Agent / 隐藏面板 / 退出)
- 标题栏新增最小化按钮

### frontends/shared_runtime.py —— 共享运行时(新增)
- 提供 get_shared_runtime(),供 Streamlit 多页面共享同一 Agent 实例

### frontends/stapp.py —— Streamlit 前端适配
- 迁移到 shared_runtime,支持与 ga_switch 联动
- 新增路由切换、状态展示、诊断信息面板

### launch.pyw —— 启动逻辑优化
- 优先探测 PySide6,可用则进入 Qt 桌面前端
- 缺少 PySide6 时自动回退到 Streamlit + pywebview

## 文档
- README.md / GETTING_STARTED.md:新增 PySide6 安装说明和 Qt 前端启动说明
- docs/GA_SWITCH_FRONTEND_HANDOFF.md:完整的前端交接文档
- docs/CC_SWITCH_UI_AUDIT.md:UI 审计参考文档

## 测试
- tests/test_ga_switch.py:31 个测试覆盖结构化配置、视图模型、payload builder、reload 等核心路径
- Add api_server.py: FastAPI server with 15 REST endpoints
- Add requirements-api.txt: API dependencies (fastapi, uvicorn)
- Add start_api_server.bat: Windows startup script
- Add API_SERVER_README.md: API documentation
- Update .gitignore: ignore api_server.pid runtime file
- Replace wildcard CORS with localhost-only origins
- Add lifespan context manager for proper resource management
- Use dependency injection pattern via Request.app.state
- Restrict CORS methods to GET/POST/PUT/DELETE only
@abraxas914
Copy link
Copy Markdown
Author

This PR is being superseded by a split backend-first resubmission.

New review path:

Reason for the split: PR109 mixed route core, GUI, launcher, and API surface into one review unit. To reduce review scope and align with the repository's review principles, the backend-only slice has been restarted in #117 and GUI work is being deferred.

@abraxas914
Copy link
Copy Markdown
Author

Closing in favor of the split resubmission path. Backend review continues in #117; GUI/API work will be proposed separately if needed.

@abraxas914 abraxas914 closed this Apr 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant