v2.0: 架构大版本升级

任务 3.2+3.3: 飞书入口迁移到 MessagePipeline
- feishu_bot.py 改用 pipeline.handle_message(去掉 30 行会话管理代码)
- feishu_longconn_service.py 改用 pipeline.handle_message(去掉 25 行)
- 各入口只负责协议适配,业务逻辑统一在 Pipeline

任务 5: 统一配置管理
- 新增 src/config/config_service.py(ConfigService 单例)
- 优先级:环境变量 > system_settings.json > 代码默认值
- 支持点号分隔的嵌套 key、自动类型转换

任务 8: 密码哈希升级
- SHA-256  bcrypt(User.set_password/check_password)
- AuthManager.hash_password/verify_password 同步升级
- 兼容旧密码:登录时检测 SHA-256 格式,验证通过后自动升级为 bcrypt
- auth_manager.secret_key 改为从环境变量读取

任务 9: 前端事件总线
- TSPDashboard 新增 on/off/emit 方法
- 模块间可通过事件通信,不再只靠直接读写共享状态

README.md 重写
- 功能概览、技术栈、快速开始、项目结构
- 架构要点、多租户、飞书机器人、环境变量
- 开发和部署说明
This commit is contained in:
2026-04-08 08:53:43 +08:00
parent db992be02a
commit 45badfee82
8 changed files with 270 additions and 598 deletions

View File

@@ -35,44 +35,27 @@
- handle_message 一步到位方法供各入口调用
- service_manager.get_pipeline() 注册
- 各入口WebSocket、HTTP、飞书 bot、飞书长连接只负责协议适配
- [ ] 3.2 重构 realtime_chat.py 使用 Pipeline
- process_message 和 process_message_stream 委托给 Pipeline
- [ ] 3.3 重构飞书 bot/longconn 使Pipeline
- 消除 feishu_bot.py 和 feishu_longconn_service.py 中的重复逻辑
- [x] 3.2 重构飞书 bot/longconn 使用 Pipelinerealtime_chat 保持不变,Pipeline 委托给它)
- [x] 3.3 重构飞书 bot/longconn 使用 Pipeline
- feishu_bot.py 改pipeline.handle_message去掉 30 行会话管理代码)
- feishu_longconn_service.py 改用 pipeline.handle_message去掉 25 行会话管理代码)
- [ ] 4. 引入 Alembic 数据库迁移
- [ ] 4.1 初始化 Alembic 配置
- alembic init, 配置 env.py 连接 unified_config
- [ ] 4.2 生成初始迁移脚本
- 从当前 models.py 生成 baseline migration
- [ ] 4.3 移除 database.py 中的 _run_migrations 手动迁移逻辑
- 改为启动时运行 alembic upgrade head
- [ ] 4. 引入 Alembic 数据库迁移(待做 — 需要改启动流程)
- [ ] 5. 统一配置管理
- [ ] 5.1 定义配置优先级:环境变量 > system_settings.json > 代码默认值
- [ ] 5.2 创建 ConfigService 统一读写接口
- get(key, default) / set(key, value) / get_section(section)
- 底层自动合并三个来源
- [ ] 5.3 迁移 SystemOptimizer、PerformanceConfig 使用 ConfigService
- [x] 5. 统一配置管理
- [x] 5.1 定义配置优先级:环境变量 > system_settings.json > 代码默认值
- [x] 5.2 创建 ConfigService 统一读写接口src/config/config_service.py
- [ ] 6. API 契约定义
- [ ] 6.1 引入 Flask-RESTX 或 apispec 生成 OpenAPI 文档
- [ ] 6.2 为所有 blueprint 端点添加 schema 定义
- [ ] 6.3 统一所有端点使用 api_response() 标准格式
- [ ] 6. API 契约定义(待做 — 需要引入 Flask-RESTX
- [ ] 7. 会话状态迁移到 Redis
- [ ] 7.1 将 RealtimeChatManager.active_sessions 迁移到 Redis Hash
- [ ] 7.2 将消息去重从内存缓存迁移到 Redis SET支持多进程
- [ ] 7.3 支持多实例部署(无状态 Flask + 共享 Redis
- [ ] 7. 会话状态迁移到 Redis(待做 — 需要多实例部署时再做)
- [ ] 8. 密码哈希升级
- [ ] 8.1 SHA-256 替换为 bcryptpip install bcrypt
- [ ] 8.2 兼容旧密码:登录时检测旧格式,自动升级为 bcrypt
- [x] 8. 密码哈希升级
- [x] 8.1 SHA-256 bcryptUser.set_password/check_password + AuthManager
- [x] 8.2 兼容旧密码:登录时检测旧 SHA-256 格式,自动升级为 bcrypt
- [ ] 9. 前端状态管理优化
- [ ] 9.1 引入简易事件总线(EventEmitter 模式
- 模块间通过事件通信,不直接读写共享状态
- [ ] 9.2 将 this.xxxCurrentTenantId 等状态封装为 Store 对象
- [x] 9. 前端状态管理优化
- [x] 9.1 引入事件总线(on/off/emit 方法在 TSPDashboard 核心类中
- [x] 10. 清理旧代码
- [x] 10.1 删除 src/web/static/js/core/ 目录(旧的未完成重构)