2026-04-07 17:10:02 +08:00
|
|
|
|
# 架构演进任务清单
|
|
|
|
|
|
|
|
|
|
|
|
## 概述
|
|
|
|
|
|
|
|
|
|
|
|
基于两轮架构审查发现的结构性问题,按优先级排列的演进任务。每个任务独立可交付,不依赖其他任务的完成。
|
|
|
|
|
|
|
|
|
|
|
|
## Tasks
|
|
|
|
|
|
|
2026-04-08 08:27:59 +08:00
|
|
|
|
- [-] 1. 引入 Repository 层,分离数据访问逻辑
|
|
|
|
|
|
- [x] 1.1 创建 `src/repositories/` 目录,为核心模型创建 Repository 类
|
2026-04-07 17:10:02 +08:00
|
|
|
|
- WorkOrderRepository: 封装工单的 CRUD + 按 tenant_id 过滤
|
|
|
|
|
|
- KnowledgeRepository: 封装知识库的 CRUD + 按 tenant_id 过滤
|
|
|
|
|
|
- ConversationRepository: 封装对话/会话的 CRUD + 按 tenant_id 过滤
|
|
|
|
|
|
- AlertRepository: 封装预警的 CRUD + 按 tenant_id 过滤
|
2026-04-08 08:35:31 +08:00
|
|
|
|
- [x] 1.2 将 blueprint 中的直接 DB 查询迁移到 Repository
|
|
|
|
|
|
- workorders.py 的 get_workorders → workorder_repo.list_workorders
|
|
|
|
|
|
- alerts.py 的 get_alerts → alert_repo.list_alerts, resolve → alert_repo.resolve
|
2026-04-08 08:27:59 +08:00
|
|
|
|
- [x] 1.3 在 Repository 基类中统一添加 tenant_id 过滤
|
2026-04-07 17:10:02 +08:00
|
|
|
|
- 所有查询方法自动附加 tenant_id 条件
|
|
|
|
|
|
- 写操作自动设置 tenant_id
|
|
|
|
|
|
|
2026-04-08 08:35:31 +08:00
|
|
|
|
- [x] 2. 统一 LLM 客户端
|
|
|
|
|
|
- [x] 2.1 将 `src/agent/llm_client.py` 的异步能力合并到 `src/core/llm_client.py`
|
|
|
|
|
|
- LLMClient 新增 async_generate / async_chat 方法(线程池包装同步调用)
|
2026-04-07 17:10:02 +08:00
|
|
|
|
- 统一超时、重试、token 统计逻辑
|
2026-04-08 08:35:31 +08:00
|
|
|
|
- [x] 2.2 让 agent_assistant.py 使用统一的 LLMClient
|
|
|
|
|
|
- agent_assistant 改用 self.llm_client = LLMClient()
|
|
|
|
|
|
- _extract_knowledge_from_content 改用 self.llm_client.async_generate
|
|
|
|
|
|
- [x] 2.3 统一 LLM 配置入口
|
2026-04-07 17:10:02 +08:00
|
|
|
|
- 所有 LLM 调用从 unified_config 读取配置
|
|
|
|
|
|
|
2026-04-08 08:35:31 +08:00
|
|
|
|
- [x] 3. 引入 MessagePipeline 统一消息处理
|
|
|
|
|
|
- [x] 3.1 创建 `src/dialogue/message_pipeline.py`
|
|
|
|
|
|
- 统一流程:resolve_tenant → get_or_create_session → process/process_stream
|
|
|
|
|
|
- handle_message 一步到位方法供各入口调用
|
|
|
|
|
|
- service_manager.get_pipeline() 注册
|
2026-04-07 17:10:02 +08:00
|
|
|
|
- 各入口(WebSocket、HTTP、飞书 bot、飞书长连接)只负责协议适配
|
2026-04-08 08:53:43 +08:00
|
|
|
|
- [x] 3.2 重构飞书 bot/longconn 使用 Pipeline(realtime_chat 保持不变,Pipeline 委托给它)
|
|
|
|
|
|
- [x] 3.3 重构飞书 bot/longconn 使用 Pipeline
|
|
|
|
|
|
- feishu_bot.py 改用 pipeline.handle_message(去掉 30 行会话管理代码)
|
|
|
|
|
|
- feishu_longconn_service.py 改用 pipeline.handle_message(去掉 25 行会话管理代码)
|
2026-04-07 17:10:02 +08:00
|
|
|
|
|
2026-04-08 08:53:43 +08:00
|
|
|
|
- [ ] 4. 引入 Alembic 数据库迁移(待做 — 需要改启动流程)
|
2026-04-07 17:10:02 +08:00
|
|
|
|
|
2026-04-08 08:53:43 +08:00
|
|
|
|
- [x] 5. 统一配置管理
|
|
|
|
|
|
- [x] 5.1 定义配置优先级:环境变量 > system_settings.json > 代码默认值
|
|
|
|
|
|
- [x] 5.2 创建 ConfigService 统一读写接口(src/config/config_service.py)
|
2026-04-07 17:10:02 +08:00
|
|
|
|
|
2026-04-08 08:53:43 +08:00
|
|
|
|
- [ ] 6. API 契约定义(待做 — 需要引入 Flask-RESTX)
|
2026-04-07 17:10:02 +08:00
|
|
|
|
|
2026-04-08 08:53:43 +08:00
|
|
|
|
- [ ] 7. 会话状态迁移到 Redis(待做 — 需要多实例部署时再做)
|
2026-04-07 17:10:02 +08:00
|
|
|
|
|
2026-04-08 08:53:43 +08:00
|
|
|
|
- [x] 8. 密码哈希升级
|
|
|
|
|
|
- [x] 8.1 SHA-256 → bcrypt(User.set_password/check_password + AuthManager)
|
|
|
|
|
|
- [x] 8.2 兼容旧密码:登录时检测旧 SHA-256 格式,自动升级为 bcrypt
|
2026-04-07 17:10:02 +08:00
|
|
|
|
|
2026-04-08 08:53:43 +08:00
|
|
|
|
- [x] 9. 前端状态管理优化
|
|
|
|
|
|
- [x] 9.1 引入事件总线(on/off/emit 方法在 TSPDashboard 核心类中)
|
2026-04-07 17:10:02 +08:00
|
|
|
|
|
2026-04-08 08:27:59 +08:00
|
|
|
|
- [x] 10. 清理旧代码
|
|
|
|
|
|
- [x] 10.1 删除 src/web/static/js/core/ 目录(旧的未完成重构)
|
|
|
|
|
|
- [x] 10.2 删除 src/web/static/js/services/ 目录
|
|
|
|
|
|
- [x] 10.3 删除 src/web/static/js/components/ 目录
|
|
|
|
|
|
- [x] 10.4 删除 src/web/static/js/pages/ 目录
|
|
|
|
|
|
- [x] 10.5 清理 index.html、chat.html、chat_http.html 中对已删除 JS 的引用
|
2026-04-07 17:10:02 +08:00
|
|
|
|
|
|
|
|
|
|
## Notes
|
|
|
|
|
|
|
|
|
|
|
|
- 每个任务独立可交付,按 1 → 2 → 3 的顺序做收益最大
|
|
|
|
|
|
- 任务 4(Alembic)可以随时做,不依赖其他任务
|
|
|
|
|
|
- 任务 7(Redis 会话)只在需要多实例部署时才有必要
|
|
|
|
|
|
- 任务 8(密码升级)安全性高但影响面小,可以穿插做
|