feat(admin): Add user management and upgrade to module permission system

Features - User Management (Phase 4.1):
- Database: Add user_modules table for fine-grained module permissions
- Database: Add 4 user permissions (view/create/edit/delete) to role_permissions
- Backend: UserService (780 lines) - CRUD with tenant isolation
- Backend: UserController + UserRoutes (648 lines) - 13 API endpoints
- Backend: Batch import users from Excel
- Frontend: UserListPage (412 lines) - list/filter/search/pagination
- Frontend: UserFormPage (341 lines) - create/edit with module config
- Frontend: UserDetailPage (393 lines) - details/tenant/module management
- Frontend: 3 modal components (592 lines) - import/assign/configure
- API: GET/POST/PUT/DELETE /api/admin/users/* endpoints

Architecture Upgrade - Module Permission System:
- Backend: Add getUserModules() method in auth.service
- Backend: Login API returns modules array in user object
- Frontend: AuthContext adds hasModule() method
- Frontend: Navigation filters modules based on user.modules
- Frontend: RouteGuard checks requiredModule instead of requiredVersion
- Frontend: Remove deprecated version-based permission system
- UX: Only show accessible modules in navigation (clean UI)
- UX: Smart redirect after login (avoid 403 for regular users)

Fixes:
- Fix UTF-8 encoding corruption in ~100 docs files
- Fix pageSize type conversion in userService (String to Number)
- Fix authUser undefined error in TopNavigation
- Fix login redirect logic with role-based access check
- Update Git commit guidelines v1.2 with UTF-8 safety rules

Database Changes:
- CREATE TABLE user_modules (user_id, tenant_id, module_code, is_enabled)
- ADD UNIQUE CONSTRAINT (user_id, tenant_id, module_code)
- INSERT 4 permissions + role assignments
- UPDATE PUBLIC tenant with 8 module subscriptions

Technical:
- Backend: 5 new files (~2400 lines)
- Frontend: 10 new files (~2500 lines)
- Docs: 1 development record + 2 status updates + 1 guideline update
- Total: ~4900 lines of code

Status: User management 100% complete, module permission system operational
This commit is contained in:
2026-01-16 13:42:10 +08:00
parent 98d862dbd4
commit 66255368b7
560 changed files with 70424 additions and 52353 deletions

View File

@@ -1,161 +1,161 @@
# AIA 妯″潡 V2.1 寮€鍙戣<EFBFBD>鍒?
# AIA 模块 V2.1 开发计划
> **版本**V2.1
> **鍒涘缓鏃ユ湡**锛?026-01-11
> **璁″垝鍛ㄦ湡**锛氱害 8-11 澶?
> **绛栫暐**锛氶噸鍐欏悗绔?+ 澶嶇敤鏁版嵁搴?+ 鏂板紑鍙戝墠绔?
> **鍏宠仈PRD**锛歚01-闇€姹傚垎鏋?AIA妯″潡PRD.md`
> **鍏宠仈鍘熷瀷**锛歚01-闇€姹傚垎鏋?AI鏅鸿兘闂<E58598>V2.html`
> **创建日期**2026-01-11
> **计划周期**:约 8-11
> **策略**:重写后端 + 复用数据库 + 新开发前端
> **关联PRD**`01-需求分析/AIA模块PRD.md`
> **关联原型**`01-需求分析/AI智能问答V2.html`
---
## 馃搵 寮€鍙戠瓥鐣ユ<E990A3>杩?
## 📋 开发策略概述
### 核心决策
| 组件 | 策略 | 理由 |
|------|------|------|
| **鍚庣<EFBFBD>** | 馃敶 **閲嶅啓** | х増涓嶇<EFBFBD>鍚堜簯鍘熺敓瑙勮寖锛坈onsole.log銆佹湭浣跨敤骞冲彴鑳藉姏锛?|
| **鏁版嵁搴?* | 鉁?**澶嶇敤** | aia_schema 宸插畬鍠勶紝瀛楁<EFBFBD>婊¤冻闇€姹?|
| **鍓嶇<EFBFBD>** | 馃敶 **鏂板紑鍙?* | 澶嶇敤 shared/components/Chat 閫氱敤缁勪欢锛屽叏鏂癠I |
| **后端** | 🔴 **重写** | 旧版不符合云原生规范console.log、未使用平台能力 |
| **数据库** | ✅ **复用** | aia_schema 已完善,字段满足需求 |
| **前端** | 🔴 **新开发** | 复用 shared/components/Chat 通用组件全新UI |
### 鎶€鏈<EFBFBD><EFBFBD>鑼?
### 技术规范
| 规范 | 要求 |
|------|------|
| **鏃ュ織** | 浣跨敤 `logger` from `@/common/logging`锛堢<EFBFBD>姝?console.log锛?|
| **日志** | 使用 `logger` from `@/common/logging`(禁止 console.log |
| **存储** | 使用 `storage` from `@/common/storage` |
| **缓存** | 使用 `cache` from `@/common/cache` |
| **队列** | 使用 `jobQueue` from `@/common/jobs` |
| **Prompt** | 使用 `promptService.get()` from `@/common/prompts` |
| **代码位置** | `backend/src/modules/aia/` |
| **API<EFBFBD>** | `/api/v1/aia/*` |
| **API路由** | `/api/v2/aia/*` |
---
## 馃搳 鏁版嵁搴撶姸鎬侊紙鉁?宸插畬鎴愶級
## 📊 数据库状态(✅ 已完成)
### 琛ㄧ粨鏋勶紙3涓<EFBFBD>〃锛?
### 表结构3个表
```
aia_schema.projects 鉁?淇濈暀
aia_schema.conversations 鉁?淇濈暀
aia_schema.messages 鉁?淇濈暀 + 鏂板<E98F82>瀛楁<E7809B>
aia_schema.projects ✅ 保留
aia_schema.conversations ✅ 保留
aia_schema.messages ✅ 保留 + 新增字段
```
### 鏂板<EFBFBD>瀛楁<EFBFBD>锛?026-01-11 宸茶縼绉伙級
### 新增字段2026-01-11 已迁移)
| 琛?| 瀛楁<E7809B> | 绫诲瀷 | 璇存槑 |
| 表 | 字段 | 类型 | 说明 |
|----|------|------|------|
| messages | `thinking_content` | TEXT | 娣卞害鎬濊€冨唴瀹?`<think>...</think>` |
| messages | `attachments` | JSONB | 闄勪欢鏁扮粍锛堜笂闄?涓<>紝鍗曚釜鈮?0MB锛屾枃鏈<E69E83>30K tokens锛?|
| messages | `thinking_content` | TEXT | 深度思考内容 `<think>...</think>` |
| messages | `attachments` | JSONB | 附件数组上限5个单个≤20MB文本≤30K tokens |
### 已删除表
| 琛?| 鍘熷洜 |
| 表 | 原因 |
|----|------|
| `general_conversations` | 鍔熻兘閲嶅彔锛屼娇鐢?conversations.project_id = NULL |
| `general_conversations` | 功能重叠,使用 conversations.project_id = NULL |
| `general_messages` | 功能重叠 |
---
## 馃棑锔?寮€鍙戦樁娈?
## 🗓️ 开发阶段
### Phase 1: 鍚庣<EFBFBD>閲嶅啓锛?-4澶╋級
### Phase 1: 后端重写3-4天
#### Day 1: 模块骨架 + 核心服务
**目标**:搭建模块结构,迁移核心对话服务
**浠诲姟娓呭崟**锛?
**任务清单**
- [ ] **1.1 创建模块目录结构**
```
backend/src/modules/aia/
├── controllers/
鈹? 鈹溾攢鈹€ conversationController.ts
鈹? 鈹溾攢鈹€ agentController.ts
鈹? 鈹斺攢鈹€ projectController.ts
│ ├── conversationController.ts
│ ├── agentController.ts
│ └── projectController.ts
├── services/
鈹? 鈹溾攢鈹€ conversationService.ts
鈹? 鈹溾攢鈹€ agentService.ts
鈹? 鈹斺攢鈹€ projectService.ts
│ ├── conversationService.ts
│ ├── agentService.ts
│ └── projectService.ts
├── routes/
鈹? 鈹斺攢鈹€ index.ts
│ └── index.ts
├── types/
鈹? 鈹斺攢鈹€ index.ts
│ └── index.ts
└── index.ts
```
- [ ] **1.2 重写 conversationService**
- 浠?legacy 澶嶅埗鏍稿績閫昏緫
- 鏇挎崲 `console.log` 鈫?`logger`
- 浣跨敤 `prisma.message`锛堝凡鍦?aia_schema锛?
- legacy 复制核心逻辑
- 替换 `console.log` `logger`
- 使用 `prisma.message`(已在 aia_schema
- 添加 `thinkingContent` 处理逻辑
- 保持流式输出能力
- [ ] **1.3 重写 agentService**
- 改用 `promptService.get()` 获取 Prompt
- 缂撳瓨鏅鸿兘浣撻厤缃<EFBFBD>紙浣跨敤 `cache`锛?
- 缓存智能体配置(使用 `cache`
- [ ] **1.4 注册 v2 路由**
- 娉ㄥ唽鍒?`/api/v1/aia/*`
- 淇濇寔 legacy <EFBFBD>敱鍏煎<EFBFBD>锛堥€愭<EFBFBD>杩佺Щ锛?
- 注册到 `/api/v2/aia/*`
- 保持 legacy 路由兼容(逐步迁移)
**楠屾敹鏍囧噯**锛?
**验收标准**
- [ ] 基础对话功能可用
- [ ] 流式输出正常
- [ ] 鏃ュ織杈撳嚭鍒?logger
- [ ] 日志输出到 logger
---
#### Day 2: 娣卞害鎬濊€?+ 闄勪欢涓婁紶
#### Day 2: 深度思考 + 附件上传
**<EFBFBD>爣**锛氬疄鐜?V2.1 鏂板<E98F82>鍔熻兘
**目标**:实现 V2.1 新增功能
**浠诲姟娓呭崟**锛?
**任务清单**
- [ ] **2.1 娣卞害鎬濊€冩ā寮?*
- 妫€娴?LLM 杈撳嚭涓<E59AAD> `<think>...</think>` 鏍囩<EFBFBD>
- [ ] **2.1 深度思考模式**
- 检测 LLM 输出中的 `<think>...</think>` 标签
- 提取并存储到 `messages.thinking_content`
- 浠?`content` <EFBFBD>Щ闄?think 鏍囩<EFBFBD>
- 娴佸紡杈撳嚭鏃跺垎绂?thinking 鍜?content
- `content` 中移除 think 标签
- 流式输出时分离 thinking content
- [ ] **2.2 附件上传服务**
- 浣跨敤 `storage.upload()` 涓婁紶鍒?OSS
- 璋冪敤 Python <EFBFBD>湇鍔℃彁鍙栨枃鏈?
- Token 璁℃暟锛堜娇鐢?tiktoken锛?
- <EFBFBD>柇澶勭悊锛堣秴杩?30K tokens锛?
- 瀛樺偍闄勪欢淇℃伅鍒?`messages.attachments`
- 使用 `storage.upload()` 上传到 OSS
- 调用 Python 微服务提取文本
- Token 计数(使用 tiktoken
- 截断处理(超过 30K tokens
- 存储附件信息到 `messages.attachments`
- [ ] **2.3 闄勪欢娉ㄥ叆 LLM 涓婁笅鏂?*
- 缁勮<EFBFBD>闄勪欢鏂囨湰鍒?User Prompt
- 鎺у埗鎬?Token 闀垮害
- [ ] **2.3 附件注入 LLM 上下文**
- 组装附件文本到 User Prompt
- 控制总 Token 长度
**鎶€鏈<EFBFBD><EFBFBD>鏍?*锛?
**技术规格**
```typescript
// 附件处理配置
const ATTACHMENT_CONFIG = {
maxCount: 5, // 姣忔潯娑堟伅鏈€澶?涓<>檮浠?
maxCount: 5, // 每条消息最多5个附件
maxSizePerFile: 20 * 1024 * 1024, // 单个文件20MB
maxTokens: 30000, // 鎻愬彇鏂囨湰鏈€澶?0K tokens
maxTokens: 30000, // 提取文本最多30K tokens
supportedTypes: ['pdf', 'docx', 'txt', 'xlsx'],
};
```
**楠屾敹鏍囧噯**锛?
- [ ] 娣卞害鎬濊€冨唴瀹规<EFBFBD><EFBFBD>垎绂诲瓨鍌?
**验收标准**
- [ ] 深度思考内容正确分离存储
- [ ] 附件上传成功
- [ ] 附件文本正确注入 LLM
---
#### Day 3: 鎰忓浘璺<EFBFBD>敱 + 鐭ヨ瘑搴撻泦鎴?
#### Day 3: 意图路由 + 知识库集成
**目标**:实现全局意图路由,完善知识库引用
**浠诲姟娓呭崟**锛?
**任务清单**
- [ ] **3.1 意图路由服务**
- 新建 `intentRouterService.ts`
@@ -163,27 +163,27 @@ const ATTACHMENT_CONFIG = {
- 返回目标 Agent ID + 预填 Prompt
- 添加 500ms 防抖(前端实现)
- [ ] **3.2 瀹屽杽鐭ヨ瘑搴撻泦鎴?*
- 澶嶇敤 PKB 妯″潡鐨?RAG 妫€绱?
- 鏅鸿兘寮曠敤绯荤粺锛圼鏉ユ簮N]锛?
- 寮曠敤娓呭崟鏍煎紡鍖?
- [ ] **3.2 完善知识库集成**
- 复用 PKB 模块的 RAG 检索
- 智能引用系统([来源N]
- 引用清单格式化
- [ ] **3.3 API 端点完善**
```
POST /api/v1/aia/intent/route # 鎰忓浘璺<EFBFBD>
POST /api/v1/aia/conversations # 鍒涘缓瀵硅瘽
GET /api/v1/aia/conversations # 瀵硅瘽鍒楄〃
GET /api/v1/aia/conversations/:id # 瀵硅瘽璇︽儏
POST /api/v1/aia/conversations/:id/messages/stream # 鍙戦€佹秷鎭<EFBFBD>紙娴佸紡锛?
POST /api/v1/aia/conversations/:id/attachments # 涓婁紶闄勪欢
GET /api/v1/aia/agents # 鏅鸿兘浣撳垪琛?
GET /api/v1/aia/agents/:id # 鏅鸿兘浣撹<EFBFBD>鎯?
POST /api/v2/aia/intent/route # 意图路由
POST /api/v2/aia/conversations # 创建对话
GET /api/v2/aia/conversations # 对话列表
GET /api/v2/aia/conversations/:id # 对话详情
POST /api/v2/aia/conversations/:id/messages/stream # 发送消息(流式)
POST /api/v2/aia/conversations/:id/attachments # 上传附件
GET /api/v2/aia/agents # 智能体列表
GET /api/v2/aia/agents/:id # 智能体详情
```
**楠屾敹鏍囧噯**锛?
- [ ] 鎰忓浘璺<EFBFBD>敱姝璇嗗埆骞惰烦杞?
- [ ] 鐭ヨ瘑搴撳紩鐢ㄦ<EFBFBD><EFBFBD>樉绀?
- [ ] 鎵€鏈?API 绔<>偣鍙<E581A3>
**验收标准**
- [ ] 意图路由正确识别并跳转
- [ ] 知识库引用正确显示
- [ ] 所有 API 端点可用
---
@@ -191,23 +191,23 @@ const ATTACHMENT_CONFIG = {
**目标**:完成后端测试和文档
**浠诲姟娓呭崟**锛?
**任务清单**
- [ ] **4.1 单元测试**
- conversationService 测试
- 娣卞害鎬濊€冭В鏋愭祴璇?
- 深度思考解析测试
- 附件处理测试
- [ ] **4.2 集成测试**
- 完整对话流程
- 附件上传流程
- 鐭ヨ瘑搴撴<EFBFBD>绱㈡祦绋?
- 知识库检索流程
- [ ] **4.3 API 文档**
- 更新 REST Client 测试文件
- 编写 API 使用示例
**楠屾敹鏍囧噯**锛?
**验收标准**
- [ ] 测试覆盖核心功能
- [ ] API 文档完整
@@ -215,66 +215,66 @@ const ATTACHMENT_CONFIG = {
### Phase 2: 前端开发5-7天
#### Day 5-6: 鏅鸿兘浣撳ぇ鍘咃紙Dashboard锛?
#### Day 5-6: 智能体大厅(Dashboard
**目标**:实现首页智能体大厅
**浠诲姟娓呭崟**锛?
**任务清单**
- [ ] **5.1 创建模块目录结构**
```
frontend-v2/src/modules/aia/
├── pages/
鈹? 鈹溾攢鈹€ Dashboard.tsx # 鏅鸿兘浣撳ぇ鍘?
鈹? 鈹斺攢鈹€ Workspace.tsx # 瀵硅瘽宸ヤ綔鍙?
│ ├── Dashboard.tsx # 智能体大厅
│ └── Workspace.tsx # 对话工作台
├── components/
鈹? 鈹溾攢鈹€ AgentPipeline.tsx # 5闃舵<EFBFBD>娴佹按绾?
鈹? 鈹溾攢鈹€ AgentCard.tsx # 鏅鸿兘浣撳崱鐗?
鈹? 鈹溾攢鈹€ IntentSearch.tsx # 鎰忓浘鎼滅储妗?
鈹? 鈹溾攢鈹€ ConversationList.tsx # 鍘嗗彶浼氳瘽鍒楄〃
鈹? 鈹溾攢鈹€ ThinkingBlock.tsx # 娣卞害鎬濊€冩姌鍙犲潡
鈹? 鈹溾攢鈹€ AttachmentUpload.tsx # 闄勪欢涓婁紶
鈹? 鈹溾攢鈹€ AttachmentCard.tsx # 闄勪欢鍗$墖
鈹? 鈹斺攢鈹€ SlashCommands.tsx # <EFBFBD>嵎鎸囦护
│ ├── AgentPipeline.tsx # 5阶段流水线
│ ├── AgentCard.tsx # 智能体卡片
│ ├── IntentSearch.tsx # 意图搜索框
│ ├── ConversationList.tsx # 历史会话列表
│ ├── ThinkingBlock.tsx # 深度思考折叠块
│ ├── AttachmentUpload.tsx # 附件上传
│ ├── AttachmentCard.tsx # 附件卡片
│ └── SlashCommands.tsx # 快捷指令
├── hooks/
鈹? 鈹溾攢鈹€ useConversation.ts
鈹? 鈹溾攢鈹€ useAgents.ts
鈹? 鈹斺攢鈹€ useIntentRouter.ts
│ ├── useConversation.ts
│ ├── useAgents.ts
│ └── useIntentRouter.ts
├── api/
鈹? 鈹斺攢鈹€ index.ts
│ └── index.ts
├── types/
鈹? 鈹斺攢鈹€ index.ts
│ └── index.ts
└── index.tsx
```
- [ ] **5.2 鏅鸿兘浣撴祦姘寸嚎锛圓gentPipeline锛?*
- 5闃舵<EFBFBD>甯冨眬锛堜弗鏍艰繕鍘?V11 鍘熷瀷锛?
- 3鑹茶<EFBFBD>瑙変綋绯?
- [ ] **5.2 智能体流水线AgentPipeline**
- 5阶段布局(严格还原 V11 原型)
- 3色视觉体系
- 卡片点击跳转 Workspace
- 宸ュ叿鍗$墖璺宠浆澶栭儴妯″潡锛圖C/ST锛?
- 工具卡片跳转外部模块DC/ST
- [ ] **5.3 鎰忓浘鎼滅储妗嗭紙IntentSearch锛?*
- [ ] **5.3 意图搜索框(IntentSearch**
- 顶部大搜索框
- 500ms 防抖
- 调用意图路由 API
- 自动跳转目标 Agent
**楠屾敹鏍囧噯**锛?
- [ ] 5闃舵<EFBFBD>娴佹按绾挎<EFBFBD><EFBFBD>睍绀?
**验收标准**
- [ ] 5阶段流水线正确展示
- [ ] 意图搜索功能可用
- [ ] 涓庡師鍨嬪浘涓€鑷?
- [ ] 与原型图一致
---
#### Day 7-8: 瀵硅瘽宸ヤ綔鍙帮紙Workspace锛?
#### Day 7-8: 对话工作台(Workspace
**目标**:实现沉浸式对话界面
**浠诲姟娓呭崟**锛?
**任务清单**
- [ ] **7.1 工作台布局**
- Gemini 风格(大留白、少分割线)
- 宸︿晶渚ц竟鏍忥紙鍘嗗彶浼氳瘽锛屽彲鎶樺彔锛?
- 左侧侧边栏(历史会话,可折叠)
- 主对话区Header + 消息列表 + 输入框)
- [ ] **7.2 复用 Chat 通用组件**
@@ -283,17 +283,17 @@ const ATTACHMENT_CONFIG = {
<ChatContainer
providerConfig={{
apiEndpoint: '/api/v1/aia/conversations/:id/messages/stream',
apiEndpoint: '/api/v2/aia/conversations/:id/messages/stream',
requestFn: sendMessageWithStream,
}}
customMessageRenderer={renderAIAMessage}
/>
```
- [ ] **7.3 娣卞害鎬濊€冩姌鍙犲潡锛圱hinkingBlock锛?*
- [ ] **7.3 深度思考折叠块ThinkingBlock**
- 可折叠灰色引用块
- 生成中展开,完成后自动收起
- 鏄剧ず"宸叉繁搴︽€濊€?(鑰楁椂 Xs)"
- 显示"已深度思考 (耗时 Xs)"
- [ ] **7.4 附件上传组件**
- 支持拖拽上传
@@ -302,13 +302,13 @@ const ATTACHMENT_CONFIG = {
- 消息气泡下方附件卡片
- [ ] **7.5 历史会话列表**
- 鎸夋椂闂村垎缁勶紙浠婂ぉ銆佹槰澶┿€?澶╁墠锛?
- 妗岄潰绔<EFBFBD>浐瀹氭樉绀?
- 绉诲姩绔<EFBFBD>娊灞夋粦鍑?
- 按时间分组今天、昨天、7天前
- 桌面端固定显示
- 移动端抽屉滑出
**楠屾敹鏍囧噯**锛?
**验收标准**
- [ ] Gemini 风格 UI
- [ ] 娣卞害鎬濊€冩<EFBFBD><EFBFBD>睍绀?
- [ ] 深度思考正确展示
- [ ] 附件上传完整流程
- [ ] 历史会话切换
@@ -316,30 +316,30 @@ const ATTACHMENT_CONFIG = {
#### Day 9: Markdown 增强 + 快捷指令
**<EFBFBD>爣**锛氬<E9949B>寮哄<E5AFAE>璇濅綋楠?
**目标**:增强对话体验
**浠诲姟娓呭崟**锛?
**任务清单**
- [ ] **9.1 Markdown 渲染增强**
- KaTeX 公式渲染(医学公式)
- 表格横向滚动
- 爜鍧楄<EFBFBD>娉曢珮浜?+ 涓€閿<E282AC><E996BF>鍒?
- 代码块语法高亮 + 一键复制
- [ ] **9.2 <EFBFBD>嵎鎸囦护锛圫lashCommands锛?*
- [ ] **9.2 快捷指令SlashCommands**
- 输入 `/` 弹出菜单
- <EFBFBD>寔锛?娑﹁壊, /鎵╁啓, /缈昏瘧, /瀵煎嚭Word
- 支持:/润色, /扩写, /翻译, /导出Word
- 键盘导航
- [ ] **9.3 缁撴灉鎿嶄綔鏍?*
- Hover 鏄剧ず宸ュ叿鏍?
- 澶嶅埗锛圡arkdown 婧愮爜锛?
- [ ] **9.3 结果操作栏**
- Hover 显示工具栏
- 复制Markdown 源码)
- 重新生成
- 瀵煎嚭 Word锛堣皟鐢?RVW 瀵煎嚭鏈嶅姟锛?
- 导出 Word(调用 RVW 导出服务)
**楠屾敹鏍囧噯**锛?
**验收标准**
- [ ] 公式正确渲染
- [ ] 快捷指令可用
- [ ] 鎿嶄綔鏍忓姛鑳藉畬鏁?
- [ ] 操作栏功能完整
---
@@ -347,25 +347,25 @@ const ATTACHMENT_CONFIG = {
**目标**:响应式布局适配
**浠诲姟娓呭崟**锛?
**任务清单**
- [ ] **10.1 Dashboard 绉诲姩绔?*
- [ ] **10.1 Dashboard 移动端**
- 隐藏复杂导航
- 卡片单列流式布局
- 鏃堕棿杞存牱寮忚皟鏁?
- 时间轴样式调整
- [ ] **10.2 Workspace 绉诲姩绔?*
- 渚ц竟鏍忔敼涓烘娊灞?
- 杈撳叆妗嗛敭鐩橀€傞厤锛坰crollIntoView锛?
- 鍙戦€佹寜閽<EFBFBD><EFBFBD>缁堝彲瑙?
- [ ] **10.2 Workspace 移动端**
- 侧边栏改为抽屉
- 输入框键盘适配scrollIntoView
- 发送按钮始终可见
- [ ] **10.3 触控优化**
- 鎸夐挳 active 鎬?
- 按钮 active
- 触控区域优化
**楠屾敹鏍囧噯**锛?
**验收标准**
- [ ] md (768px) 断点响应正确
- [ ] 绉诲姩绔<EFBFBD>氦浜掓祦鐣?
- [ ] 移动端交互流畅
---
@@ -373,27 +373,27 @@ const ATTACHMENT_CONFIG = {
**目标**:完成整体测试和优化
**浠诲姟娓呭崟**锛?
**任务清单**
- [ ] **11.1 <EFBFBD>埌绔<EFBFBD>祴璇?*
- [ ] **11.1 端到端测试**
- 完整对话流程
- 附件上传流程
- 娣卞害鎬濊€冩祦绋?
- 鐭ヨ瘑搴撳紩鐢ㄦ祦绋?
- 深度思考流程
- 知识库引用流程
- [ ] **11.2 性能优化**
- TTFB < 1.5s
- 绉诲姩绔?LCP < 1s
- 移动端 LCP < 1s
- 意图搜索防抖
- [ ] **11.3 Bug 修复**
- [ ] **11.4 文档更新**
- 鏇存柊妯″潡鐘舵€佹枃妗?
- 鏇存柊绯荤粺褰撳墠鐘舵€?
- 更新模块状态文档
- 更新系统当前状态
**楠屾敹鏍囧噯**锛?
- [ ] 鎵€鏈夊姛鑳芥<EFBFBD>甯?
**验收标准**
- [ ] 所有功能正常
- [ ] 性能达标
- [ ] 文档完整
@@ -406,22 +406,22 @@ const ATTACHMENT_CONFIG = {
```
backend/src/modules/aia/
├── controllers/
鈹? 鈹溾攢鈹€ conversationController.ts # ~300琛?
鈹? 鈹溾攢鈹€ agentController.ts # ~150琛?
鈹? 鈹斺攢鈹€ projectController.ts # ~200琛?
│ ├── conversationController.ts # ~300
│ ├── agentController.ts # ~150
│ └── projectController.ts # ~200
├── services/
鈹? 鈹溾攢鈹€ conversationService.ts # ~500琛岋紙鏍稿績锛?
鈹? 鈹溾攢鈹€ agentService.ts # ~200琛?
鈹? 鈹溾攢鈹€ projectService.ts # ~150琛?
鈹? 鈹溾攢鈹€ intentRouterService.ts # ~100琛岋紙鏂帮級
鈹? 鈹斺攢鈹€ attachmentService.ts # ~200琛岋紙鏂帮級
│ ├── conversationService.ts # ~500行(核心)
│ ├── agentService.ts # ~200
│ ├── projectService.ts # ~150
│ ├── intentRouterService.ts # ~100行(新)
│ └── attachmentService.ts # ~200行(新)
├── routes/
鈹? 鈹斺攢鈹€ index.ts # ~100琛?
│ └── index.ts # ~100
├── types/
鈹? 鈹斺攢鈹€ index.ts # ~100琛?
鈹斺攢鈹€ index.ts # ~20琛?
│ └── index.ts # ~100
└── index.ts # ~20
棰勮<EFBFBD>鎬昏<EFBFBD>锛殈2000琛?
预计总计:~2000
```
### 前端新增文件
@@ -429,28 +429,28 @@ backend/src/modules/aia/
```
frontend-v2/src/modules/aia/
├── pages/
鈹? 鈹溾攢鈹€ Dashboard.tsx # ~400琛?
鈹? 鈹斺攢鈹€ Workspace.tsx # ~500琛?
│ ├── Dashboard.tsx # ~400
│ └── Workspace.tsx # ~500
├── components/
鈹? 鈹溾攢鈹€ AgentPipeline.tsx # ~300琛?
鈹? 鈹溾攢鈹€ AgentCard.tsx # ~100琛?
鈹? 鈹溾攢鈹€ IntentSearch.tsx # ~150琛?
鈹? 鈹溾攢鈹€ ConversationList.tsx # ~200琛?
鈹? 鈹溾攢鈹€ ThinkingBlock.tsx # ~100琛?
鈹? 鈹溾攢鈹€ AttachmentUpload.tsx # ~200琛?
鈹? 鈹溾攢鈹€ AttachmentCard.tsx # ~80琛?
鈹? 鈹斺攢鈹€ SlashCommands.tsx # ~150琛?
│ ├── AgentPipeline.tsx # ~300
│ ├── AgentCard.tsx # ~100
│ ├── IntentSearch.tsx # ~150
│ ├── ConversationList.tsx # ~200
│ ├── ThinkingBlock.tsx # ~100
│ ├── AttachmentUpload.tsx # ~200
│ ├── AttachmentCard.tsx # ~80
│ └── SlashCommands.tsx # ~150
├── hooks/
鈹? 鈹溾攢鈹€ useConversation.ts # ~150琛?
鈹? 鈹溾攢鈹€ useAgents.ts # ~100琛?
鈹? 鈹斺攢鈹€ useIntentRouter.ts # ~80琛?
│ ├── useConversation.ts # ~150
│ ├── useAgents.ts # ~100
│ └── useIntentRouter.ts # ~80
├── api/
鈹? 鈹斺攢鈹€ index.ts # ~200琛?
│ └── index.ts # ~200
├── types/
鈹? 鈹斺攢鈹€ index.ts # ~100琛?
鈹斺攢鈹€ index.tsx # ~50琛?
│ └── index.ts # ~100
└── index.tsx # ~50
棰勮<EFBFBD>鎬昏<EFBFBD>锛殈2900琛?
预计总计:~2900
```
---
@@ -466,8 +466,8 @@ frontend-v2/src/modules/aia/
| `cache` | `@/common/cache` | Redis/PG缓存 |
| `jobQueue` | `@/common/jobs` | 异步任务 |
| `promptService` | `@/common/prompts` | Prompt管理 |
| `LLMFactory` | `@/common/llm` | LLM閫傞厤鍣?|
| `prisma` | `@/config/database` | 鏁版嵁搴?|
| `LLMFactory` | `@/common/llm` | LLM适配器 |
| `prisma` | `@/config/database` | 数据库 |
| `ExtractionClient` | `@/clients` | 文档提取 |
| `TokenService` | `@/services` | Token计数 |
@@ -476,7 +476,7 @@ frontend-v2/src/modules/aia/
| 依赖 | 来源 | 说明 |
|------|------|------|
| `ChatContainer` | `@/shared/components/Chat` | 通用对话组件 |
| `Ant Design` | `antd` | UI缁勪欢搴?|
| `Ant Design` | `antd` | UI组件库 |
| `Ant Design X` | `@ant-design/x` | AI对话组件 |
| `KaTeX` | `katex` | 公式渲染 |
| `react-markdown` | `react-markdown` | Markdown渲染 |
@@ -487,37 +487,37 @@ frontend-v2/src/modules/aia/
| 风险 | 概率 | 影响 | 缓解措施 |
|------|------|------|---------|
| 娴佸紡杈撳嚭鍏煎<EFBFBD>鎬?| 涓?| 楂?| 澶嶇敤宸查獙璇佺殑 SSE 浠g爜 |
| 闄勪欢鎻愬彇瓒呮椂 | 涓?| 涓?| 浣跨敤 jobQueue 寮傛<EFBFBD>澶勭悊 |
| 绉诲姩绔<EFBFBD>€傞厤闂<EFBFBD><EFBFBD> | 浣?| 涓?| 鎻愬墠瑙勫垝鏂<E59E9D>偣鍜屽竷灞€ |
| Prompt悊鏈嶅姟鏈<EFBFBD>氨缁?| 浣?| 涓?| 鍙<>复鏃跺洖閫€鍒版枃浠惰<E6B5A0>鍙?|
| 流式输出兼容性 | 中 | 高 | 复用已验证的 SSE 代码 |
| 附件提取超时 | 中 | 中 | 使用 jobQueue 异步处理 |
| 移动端适配问题 | 低 | 中 | 提前规划断点和布局 |
| Prompt管理服务未就绪 | 低 | 中 | 可临时回退到文件读取 |
---
## 鉁?楠屾敹鏍囧噯
## ✅ 验收标准
### 功能验收
- [ ] 鏅鸿兘浣撳ぇ鍘呭畬鏁村睍绀?
- [ ] 智能体大厅完整展示
- [ ] 意图搜索正确路由
- [ ] 多轮对话正常
- [ ] 流式输出流畅
- [ ] 娣卞害鎬濊€冩<EFBFBD><EFBFBD>姌鍙?
- [ ] 深度思考正确折叠
- [ ] 附件上传完整
- [ ] 鐭ヨ瘑搴撳紩鐢ㄦ<EFBFBD>纭?
- [ ] 知识库引用正确
- [ ] 快捷指令可用
- [ ] 移动端适配正常
### 性能验收
- [ ] TTFB < 1.5s
- [ ] 绉诲姩绔?LCP < 1s
- [ ] 移动端 LCP < 1s
- [ ] 意图搜索响应 < 500ms
### 质量验收
- [ ] 鏃?console.log锛堜娇鐢?logger锛?
- [ ] 爜绗﹀悎浜戝師鐢熻<EFBFBD>鑼?
- [ ] console.log(使用 logger
- [ ] 代码符合云原生规范
- [ ] API 文档完整
- [ ] 单元测试覆盖核心功能
@@ -527,14 +527,13 @@ frontend-v2/src/modules/aia/
| 日期 | 版本 | 内容 |
|------|------|------|
| 2026-01-11 | V1.0 | 鍒涘缓寮€鍙戣<EFBFBD>鍒?|
| 2026-01-11 | V1.0 | 创建开发计划 |
---
**璁″垝鍒跺畾浜?*锛欰I Assistant
**瀹℃牳浜?*锛氬緟瀹?
**鎵瑰噯浜?*锛氬緟瀹?
**计划制定人**AI Assistant
**审核人**:待定
**批准人**:待定

View File

@@ -1,8 +1,8 @@
# AIA V2.1 后端 API 设计
> **版本**V2.1
> **<EFBFBD>𥕦遣<EFBFBD><EFBFBD>**嚗?026-01-11
> **<EFBFBD><EFBFBD>頝臬<EFBFBD>**嚗䫤/api/v1/aia`
> **创建日期**2026-01-11
> **基础路径**`/api/v2/aia`
---
@@ -10,23 +10,23 @@
| 方法 | 路径 | 描述 | 认证 |
|------|------|------|------|
| GET | `/agents` | <EFBFBD><EFBFBD><EFBFBD><EFBFBD>雿枏<EFBFBD>銵?| <20>?|
| GET | `/agents/:id` | <EFBFBD><EFBFBD><EFBFBD><EFBFBD>雿栞祕<EFBFBD>?| <20>?|
| POST | `/intent/route` | <EFBFBD>誩㦛頝舐眏 | <EFBFBD>?|
| GET | `/conversations` | <EFBFBD><EFBFBD>撖寡<EFBFBD><EFBFBD>𡑒” | <EFBFBD>?|
| POST | `/conversations` | <EFBFBD>𥕦遣撖寡<EFBFBD> | <EFBFBD>?|
| GET | `/conversations/:id` | <EFBFBD><EFBFBD>撖寡<EFBFBD>霂行<EFBFBD> | <EFBFBD>?|
| DELETE | `/conversations/:id` | <EFBFBD>𣳇膄撖寡<EFBFBD> | <EFBFBD>?|
| POST | `/conversations/:id/messages/stream` | <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>嚗?| <20>?|
| POST | `/conversations/:id/attachments` | 銝𠹺<EFBFBD><EFBFBD><EFBFBD> | <EFBFBD>?|
| GET | `/projects` | <EFBFBD><EFBFBD>憿寧𤌍<EFBFBD>𡑒” | <EFBFBD>?|
| GET | `/projects/:id` | <EFBFBD><EFBFBD>憿寧𤌍霂行<EFBFBD> | <EFBFBD>?|
| GET | `/agents` | 获取智能体列表 | ✅ |
| GET | `/agents/:id` | 获取智能体详情 | ✅ |
| POST | `/intent/route` | 意图路由 | |
| GET | `/conversations` | 获取对话列表 | |
| POST | `/conversations` | 创建对话 | |
| GET | `/conversations/:id` | 获取对话详情 | |
| DELETE | `/conversations/:id` | 删除对话 | |
| POST | `/conversations/:id/messages/stream` | 发送消息(流式) | ✅ |
| POST | `/conversations/:id/attachments` | 上传附件 | |
| GET | `/projects` | 获取项目列表 | |
| GET | `/projects/:id` | 获取项目详情 | |
---
## 🔐 认证
<EFBFBD><EFBFBD><EFBFBD>?API <20><><EFBFBD>銁霂瑟<E99C82>憭港葉<E6B8AF>箏蒂 JWT Token嚗?
所有 API 需要在请求头中携带 JWT Token
```
Authorization: Bearer <token>
@@ -36,21 +36,21 @@ Authorization: Bearer <token>
## 📖 API 详细定义
### 1. <EFBFBD><EFBFBD>雿梶㮾<EFBFBD>?
### 1. 智能体相关
#### 1.1 <EFBFBD><EFBFBD><EFBFBD><EFBFBD>雿枏<EFBFBD>銵?
#### 1.1 获取智能体列表
```http
GET /api/v1/aia/agents
GET /api/v2/aia/agents
```
**<EFBFBD>亥砭<EFBFBD><EFBFBD>㺭**嚗?
**查询参数**
| 参数 | 类型 | 必填 | 描述 |
|------|------|------|------|
| stage | string | <EFBFBD>?| 蝑偦<E89D91>厰𧫴畾蛛<E795BE>`design`, `data`, `analysis`, `write`, `publish` |
| stage | string | 否 | 筛选阶段:`design`, `data`, `analysis`, `write`, `publish` |
**<EFBFBD><EFBFBD>**嚗?
**响应**
```json
{
@@ -59,7 +59,7 @@ GET /api/v1/aia/agents
"agents": [
{
"id": "research-design",
"name": "蝘𤑳<EFBFBD>霈曇恣撠誩𨭌<EFBFBD>?,
"name": "科研设计小助手",
"description": "帮助您完成研究方案设计、文献检索、方法学指导",
"icon": "🔬",
"stage": "design",
@@ -70,7 +70,7 @@ GET /api/v1/aia/agents
{
"id": "dc-tool",
"name": "数据采集工具",
"description": "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>?,
"description": "跳转到数据采集模块",
"icon": "📊",
"stage": "data",
"color": "#8B5CF6",
@@ -82,20 +82,20 @@ GET /api/v1/aia/agents
}
```
#### 1.2 <EFBFBD><EFBFBD><EFBFBD><EFBFBD>雿栞祕<EFBFBD>?
#### 1.2 获取智能体详情
```http
GET /api/v1/aia/agents/:id
GET /api/v2/aia/agents/:id
```
**<EFBFBD><EFBFBD>**嚗?
**响应**
```json
{
"code": 0,
"data": {
"id": "research-design",
"name": "蝘𤑳<EFBFBD>霈曇恣撠誩𨭌<EFBFBD>?,
"name": "科研设计小助手",
"description": "帮助您完成研究方案设计、文献检索、方法学指导",
"icon": "🔬",
"stage": "design",
@@ -104,7 +104,7 @@ GET /api/v1/aia/agents/:id
"systemPrompt": "你是一个专业的医学科研设计专家...",
"welcomeMessage": "您好!我是科研设计小助手,我可以帮您:\n- 设计研究方案\n- 检索相关文献\n- 指导研究方法",
"suggestedQuestions": [
"<EFBFBD><EFBFBD><EFBFBD>CT<EFBFBD>𠉛?,
"如何设计一个RCT研究",
"帮我检索近5年糖尿病研究文献",
"什么情况下使用倾向性评分匹配?"
]
@@ -119,27 +119,27 @@ GET /api/v1/aia/agents/:id
#### 2.1 智能意图识别
```http
POST /api/v1/aia/intent/route
POST /api/v2/aia/intent/route
```
**霂瑟<EFBFBD>雿?*嚗?
**请求体**
```json
{
"query": "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>?
"query": "帮我分析一下这份数据"
}
```
**<EFBFBD><EFBFBD>**嚗?
**响应**
```json
{
"code": 0,
"data": {
"agentId": "data-analysis",
"agentName": "蝏蠘恣<EFBFBD><EFBFBD><EFBFBD>撠誩𨭌<EFBFBD>?,
"agentName": "统计分析小助手",
"confidence": 0.92,
"prefillPrompt": "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>𡠺<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>?
"prefillPrompt": "请帮我分析这份数据,包括描述性统计和相关性分析"
}
}
```
@@ -151,19 +151,19 @@ POST /api/v1/aia/intent/route
#### 3.1 获取对话列表
```http
GET /api/v1/aia/conversations
GET /api/v2/aia/conversations
```
**<EFBFBD>亥砭<EFBFBD><EFBFBD>㺭**嚗?
**查询参数**
| 参数 | 类型 | 必填 | 描述 |
|------|------|------|------|
| agentId | string | <EFBFBD>?| <20>㗇惣<E39787><EFBFBD>蝑偦<E89D91>?|
| projectId | string | <EFBFBD>?| <20>厰★<E58EB0><EFBFBD><E6A183><EFBFBD>NULL 銵函內<E587BD>𡁶鍂撖寡<E69296>嚗?|
| page | number | <EFBFBD>?| 憿萇<E686BF>嚗屸<E59A97>霈?1 |
| pageSize | number | <EFBFBD>?| 瘥誯△<E8AAAF><EFBFBD>嚗屸<E59A97>霈?20 |
| agentId | string | 否 | 按智能体筛选 |
| projectId | string | 否 | 按项目筛选NULL 表示通用对话) |
| page | number | 否 | 页码,默认 1 |
| pageSize | number | 否 | 每页数量,默认 20 |
**<EFBFBD><EFBFBD>**嚗?
**响应**
```json
{
@@ -174,10 +174,10 @@ GET /api/v1/aia/conversations
"id": "conv-001",
"title": "RCT研究设计咨询",
"agentId": "research-design",
"agentName": "蝘𤑳<EFBFBD>霈曇恣撠誩𨭌<EFBFBD>?,
"agentName": "科研设计小助手",
"projectId": null,
"messageCount": 12,
"lastMessage": "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>?..",
"lastMessage": "好的,我来帮您设计研究方案...",
"createdAt": "2026-01-11T10:00:00Z",
"updatedAt": "2026-01-11T12:30:00Z"
}
@@ -195,27 +195,27 @@ GET /api/v1/aia/conversations
#### 3.2 创建对话
```http
POST /api/v1/aia/conversations
POST /api/v2/aia/conversations
```
**霂瑟<EFBFBD>雿?*嚗?
**请求体**
```json
{
"agentId": "research-design",
"projectId": null,
"title": "<EFBFBD>?
"title": "新对话"
}
```
**<EFBFBD><EFBFBD>**嚗?
**响应**
```json
{
"code": 0,
"data": {
"id": "conv-002",
"title": "<EFBFBD>啣笆霂?,
"title": "新对话",
"agentId": "research-design",
"projectId": null,
"createdAt": "2026-01-11T14:00:00Z"
@@ -223,19 +223,19 @@ POST /api/v1/aia/conversations
}
```
#### 3.3 <EFBFBD><EFBFBD>撖寡<EFBFBD>霂行<EFBFBD><EFBFBD><EFBFBD><EFBFBD>蟮瘨<EFBFBD><EFBFBD>嚗?
#### 3.3 获取对话详情(含历史消息)
```http
GET /api/v1/aia/conversations/:id
GET /api/v2/aia/conversations/:id
```
**<EFBFBD>亥砭<EFBFBD><EFBFBD>㺭**嚗?
**查询参数**
| 参数 | 类型 | 必填 | 描述 |
|------|------|------|------|
| limit | number | <EFBFBD>?| <20><EFBFBD><E79195><EFBFBD>餈𤨩<E9A488><EFBFBD><E28AA5><EFBFBD>暺䁅恕 50 |
| limit | number | 否 | 获取最近N条消息默认 50 |
**<EFBFBD><EFBFBD>**嚗?
**响应**
```json
{
@@ -244,7 +244,7 @@ GET /api/v1/aia/conversations/:id
"id": "conv-001",
"title": "RCT研究设计咨询",
"agentId": "research-design",
"agentName": "蝘𤑳<EFBFBD>霈曇恣撠誩𨭌<EFBFBD>?,
"agentName": "科研设计小助手",
"projectId": null,
"createdAt": "2026-01-11T10:00:00Z",
"updatedAt": "2026-01-11T12:30:00Z",
@@ -260,7 +260,7 @@ GET /api/v1/aia/conversations/:id
"id": "msg-002",
"role": "assistant",
"content": "好的我来帮您设计一个糖尿病RCT研究方案...",
"thinkingContent": "<EFBFBD><EFBFBD><EFBFBD>CT<EFBFBD>𠉛<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>?<EFBFBD>𤌍<EFBFBD>?2<EFBFBD><EFBFBD><EFBFBD><EFBFBD>?3<EFBFBD><EFBFBD> 4<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 5𤩅?6<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>...",
"thinkingContent": "用户想设计RCT研究需要考虑1研究目的 2入排标准 3样本量 4随机化方法 5盲法 6结局指标...",
"model": "deepseek-v3",
"tokens": 1250,
"createdAt": "2026-01-11T10:00:30Z"
@@ -273,10 +273,10 @@ GET /api/v1/aia/conversations/:id
#### 3.4 删除对话
```http
DELETE /api/v1/aia/conversations/:id
DELETE /api/v2/aia/conversations/:id
```
**<EFBFBD><EFBFBD>**嚗?
**响应**
```json
{
@@ -289,22 +289,22 @@ DELETE /api/v1/aia/conversations/:id
---
### 4. <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>嚗?
### 4. 消息发送(流式)
#### 4.1 发送消息并获取流式响应
```http
POST /api/v1/aia/conversations/:id/messages/stream
POST /api/v2/aia/conversations/:id/messages/stream
```
**霂瑟<EFBFBD>憭?*嚗?
**请求头**
```
Content-Type: application/json
Accept: text/event-stream
```
**霂瑟<EFBFBD>雿?*嚗?
**请求体**
```json
{
@@ -314,17 +314,17 @@ Accept: text/event-stream
}
```
**<EFBFBD><EFBFBD>嚗𠄎SE <20><EFBFBD>嚗?*嚗?
**响应SSE 格式)**
```
event: thinking_start
data: {}
event: thinking_delta
data: {"content": "<EFBFBD><EFBFBD>銝𠹺<EFBFBD><EFBFBD><EFBFBD><EFBFBD>隞塚<EFBFBD><EFBFBD><EFBFBD>閬?}
data: {"content": "用户上传了数据文件,需要"}
event: thinking_delta
data: {"content": "餈𥡝<EFBFBD><EFBFBD>讛膩<EFBFBD><EFBFBD><EFBFBD><EFBFBD>?.."}
data: {"content": "进行描述性统计分析..."}
event: thinking_end
data: {"duration": 3200}
@@ -333,7 +333,7 @@ event: message_start
data: {"id": "msg-003"}
event: delta
data: {"content": "<EFBFBD>寞旿<EFBFBD><EFBFBD>隡删<EFBFBD><EFBFBD>唳旿嚗?}
data: {"content": "根据您上传的数据,"}
event: delta
data: {"content": "我来为您进行分析..."}
@@ -345,18 +345,18 @@ event: done
data: {}
```
**SSE 鈭衤辣蝐餃<EFBFBD>**嚗?
**SSE 事件类型**
| 事件 | 描述 | 数据格式 |
|------|------|---------|
| `thinking_start` | <EFBFBD>憪𧢲楛摨行<EFBFBD><EFBFBD>?| `{}` |
| `thinking_delta` | <EFBFBD><EFBFBD><EFBFBD><EFBFBD>摰寧<EFBFBD>畾?| `{"content": "..."}` |
| `thinking_end` | <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>?| `{"duration": number}` |
| `message_start` | <EFBFBD>憪讠<EFBFBD><EFBFBD>𣂼<EFBFBD>憭?| `{"id": "..."}` |
| `thinking_start` | 开始深度思考 | `{}` |
| `thinking_delta` | 思考内容片段 | `{"content": "..."}` |
| `thinking_end` | 思考结束 | `{"duration": number}` |
| `message_start` | 开始生成回复 | `{"id": "..."}` |
| `delta` | 回复内容片段 | `{"content": "..."}` |
| `message_end` | 回复结束 | `{"id": "...", "tokens": number, "model": "..."}` |
| `error` | 发生错误 | `{"code": "...", "message": "..."}` |
| `done` | <EFBFBD><EFBFBD><EFBFBD>?| `{}` |
| `done` | 流结束 | `{}` |
---
@@ -365,22 +365,22 @@ data: {}
#### 5.1 上传附件
```http
POST /api/v1/aia/conversations/:id/attachments
POST /api/v2/aia/conversations/:id/attachments
```
**霂瑟<EFBFBD>憭?*嚗?
**请求头**
```
Content-Type: multipart/form-data
```
**霂瑟<EFBFBD>雿橒<EFBFBD>FormData嚗?*嚗?
**请求体(FormData**
| 字段 | 类型 | 必填 | 描述 |
|------|------|------|------|
| file | File | <EFBFBD>?| <20><>辣嚗㇊DF/Word/TXT/Excel嚗峕<EFBFBD>憭?0MB嚗?|
| file | File | 是 | 文件PDF/Word/TXT/Excel最大20MB |
**<EFBFBD><EFBFBD>**嚗?
**响应**
```json
{
@@ -399,13 +399,13 @@ Content-Type: multipart/form-data
}
```
**<EFBFBD>躰秤<EFBFBD>?*嚗?
**错误码**
| <EFBFBD>躰秤<EFBFBD>?| <20>讛膩 |
| 错误码 | 描述 |
|--------|------|
| `ATTACHMENT_TOO_LARGE` | 文件超过 20MB |
| `ATTACHMENT_TYPE_NOT_SUPPORTED` | 不支持的文件类型 |
| `ATTACHMENT_LIMIT_EXCEEDED` | <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>銝𢠃<EFBFBD>嚗?銝迎<E98A9D> |
| `ATTACHMENT_LIMIT_EXCEEDED` | 附件数量超过上限5个 |
| `TEXT_EXTRACTION_FAILED` | 文本提取失败 |
---
@@ -415,10 +415,10 @@ Content-Type: multipart/form-data
#### 6.1 获取项目列表
```http
GET /api/v1/aia/projects
GET /api/v2/aia/projects
```
**<EFBFBD><EFBFBD>**嚗?
**响应**
```json
{
@@ -427,8 +427,8 @@ GET /api/v1/aia/projects
"projects": [
{
"id": "proj-001",
"name": "蝟硋倏<EFBFBD><EFBFBD><EFBFBD>蝛園★<EFBFBD>?,
"description": "2<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>?,
"name": "糖尿病研究项目",
"description": "2型糖尿病患者生活方式干预研究",
"conversationCount": 5,
"createdAt": "2026-01-01T10:00:00Z",
"updatedAt": "2026-01-11T12:00:00Z"
@@ -449,20 +449,20 @@ GET /api/v1/aia/projects
"code": -1,
"error": {
"code": "CONVERSATION_NOT_FOUND",
"message": "<EFBFBD><EFBFBD><EFBFBD>?
"message": "对话不存在"
}
}
```
### <EFBFBD>𡁶鍂<EFBFBD>躰秤<EFBFBD>?
### 通用错误码
| <EFBFBD>躰秤<EFBFBD>?| HTTP <EFBFBD><EFBFBD><EFBFBD><EFBFBD> | <20>讛膩 |
| 错误码 | HTTP 状态码 | 描述 |
|--------|------------|------|
| `UNAUTHORIZED` | 401 | <EFBFBD><EFBFBD><EFBFBD>?|
| `FORBIDDEN` | 403 | <EFBFBD><EFBFBD><EFBFBD>?|
| `NOT_FOUND` | 404 | <EFBFBD><EFBFBD>銝滚<EFBFBD><EFBFBD>?|
| `UNAUTHORIZED` | 401 | 未授权 |
| `FORBIDDEN` | 403 | 无权限 |
| `NOT_FOUND` | 404 | 资源不存在 |
| `VALIDATION_ERROR` | 400 | 参数验证失败 |
| `INTERNAL_ERROR` | 500 | <EFBFBD>滚𦛚<EFBFBD><EFBFBD><EFBFBD><EFBFBD>霂?|
| `INTERNAL_ERROR` | 500 | 服务器内部错误 |
| `LLM_ERROR` | 500 | LLM 调用失败 |
| `RATE_LIMITED` | 429 | 请求过于频繁 |
@@ -475,13 +475,13 @@ GET /api/v1/aia/projects
```typescript
interface Attachment {
id: string; // 附件ID
filename: string; // <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>?
filename: string; // 原始文件名
mimeType: string; // MIME 类型
size: number; // 文件大小(字节)
ossUrl: string; // OSS 存储地址
textContent?: string; // 提取的文本内容(存储时截断)
tokenCount: number; // <EFBFBD><EFBFBD>𧋦 Token <EFBFBD>?
truncated: boolean; // <EFBFBD>臬炏鋡急⏛<EFBFBD><EFBFBD><EFBFBD><EFBFBD>30K tokens嚗?
tokenCount: number; // 文本 Token
truncated: boolean; // 是否被截断(超过30K tokens
createdAt: string; // 创建时间
}
```
@@ -494,7 +494,7 @@ interface Message {
conversationId: string;
role: 'user' | 'assistant';
content: string;
thinkingContent?: string; // 瘛勗漲<EFBFBD><EFBFBD><EFBFBD><EFBFBD>摰?
thinkingContent?: string; // 深度思考内容
attachments?: Attachment[];
model?: string;
tokens?: number;
@@ -505,15 +505,15 @@ interface Message {
---
## <EFBFBD>妒 瘚贝<E7989A>蝷箔<E89DB7>嚗㇌EST Client嚗?
## 🧪 测试示例REST Client
```http
### <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>?
GET {{baseUrl}}/api/v1/aia/agents
###
GET {{baseUrl}}/api/v2/aia/agents
Authorization: Bearer {{token}}
###
POST {{baseUrl}}/api/v1/aia/intent/route
POST {{baseUrl}}/api/v2/aia/intent/route
Authorization: Bearer {{token}}
Content-Type: application/json
@@ -522,7 +522,7 @@ Content-Type: application/json
}
###
POST {{baseUrl}}/api/v1/aia/conversations
POST {{baseUrl}}/api/v2/aia/conversations
Authorization: Bearer {{token}}
Content-Type: application/json
@@ -531,8 +531,8 @@ Content-Type: application/json
"title": ""
}
### <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>?
POST {{baseUrl}}/api/v1/aia/conversations/{{conversationId}}/messages/stream
###
POST {{baseUrl}}/api/v2/aia/conversations/{{conversationId}}/messages/stream
Authorization: Bearer {{token}}
Content-Type: application/json
Accept: text/event-stream
@@ -543,7 +543,7 @@ Accept: text/event-stream
}
###
POST {{baseUrl}}/api/v1/aia/conversations/{{conversationId}}/attachments
POST {{baseUrl}}/api/v2/aia/conversations/{{conversationId}}/attachments
Authorization: Bearer {{token}}
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary
@@ -568,4 +568,3 @@ Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

View File

@@ -1,7 +1,7 @@
# AIA V2.1 前端组件设计
> **版本**V2.1
> **创建日期**�026-01-11
> **创建日期**2026-01-11
> **技术栈**React 19 + TypeScript 5 + Ant Design 6 + Ant Design X 2.1
---
@@ -11,45 +11,45 @@
```
frontend-v2/src/modules/aia/
├── pages/
� ├── Dashboard.tsx # 智能体大厅(首页�
â”? └── Workspace.tsx # 对è¯<EFBFBD>工作å<EFBFBD>?
│ ├── Dashboard.tsx # 智能体大厅(首页)
│ └── Workspace.tsx # 对话工作台
├── components/
� ├── AgentPipeline/
â”? â”? ├── index.tsx # 5阶段æµ<EFBFBD>水线容å™?
â”? â”? ├── StageColumn.tsx # å<EFBFBD>•阶段åˆ
â”? â”? └── AgentCard.tsx # 智能体å<EFBFBD>¡ç‰?
� ├── IntentSearch/
â”? â”? ├── index.tsx # æ„<EFBFBD>徿<EFBFBD>œç´¢æ¡?
� � └── SuggestionDropdown.tsx # 建议下拉�
� ├── ConversationList/
â”? â”? ├── index.tsx # 历å<EFBFBD>²ä¼šè¯<EFBFBD>列表
â”? â”? └── ConversationItem.tsx # 会è¯<EFBFBD>é¡?
� ├── MessageList/
â”? â”? ├── index.tsx # 消æ<EFBFBD>¯åˆ—表
â”? â”? ├── UserMessage.tsx # 用户消æ<EFBFBD>¯
â”? â”? ├── AssistantMessage.tsx # AIåžå¤<EFBFBD>
â”? â”? └── ThinkingBlock.tsx # 深度æ€<EFBFBD>考折å<EFBFBD> å<EFBFBD>
� ├── Attachment/
� � ├── AttachmentUpload.tsx # 附件上传
â”? â”? ├── AttachmentCard.tsx # 附件å<EFBFBD>¡ç‰‡
� � └── AttachmentPreview.tsx # 附件预览
� ├── SlashCommands/
â”? â”? └── index.tsx # å¿«æ<EFBFBD>·æŒ‡ä»¤è<EFBFBD>œå<EFBFBD>
� └── ActionBar/
â”? └── index.tsx # 结果æ“<EFBFBD>作æ ?
│ ├── AgentPipeline/
│ │ ├── index.tsx # 5阶段流水线容器
│ │ ├── StageColumn.tsx # 单阶段列
│ │ └── AgentCard.tsx # 智能体卡片
│ ├── IntentSearch/
│ │ ├── index.tsx # 意图搜索框
│ │ └── SuggestionDropdown.tsx # 建议下拉框
│ ├── ConversationList/
│ │ ├── index.tsx # 历史会话列表
│ │ └── ConversationItem.tsx # 会话项
│ ├── MessageList/
│ │ ├── index.tsx # 消息列表
│ │ ├── UserMessage.tsx # 用户消息
│ │ ├── AssistantMessage.tsx # AI回复
│ │ └── ThinkingBlock.tsx # 深度思考折叠块
│ ├── Attachment/
│ │ ├── AttachmentUpload.tsx # 附件上传
│ │ ├── AttachmentCard.tsx # 附件卡片
│ │ └── AttachmentPreview.tsx # 附件预览
│ ├── SlashCommands/
│ │ └── index.tsx # 快捷指令菜单
│ └── ActionBar/
└── index.tsx # 结果操作栏
├── hooks/
â”? ├── useConversation.ts # 对è¯<EFBFBD>管ç<EFBFBD>
â”? ├── useAgents.ts # 智能体数æ<EFBFBD>?
â”? ├── useIntentRouter.ts # æ„<EFBFBD>å¾è·¯ç”±
â”? ├── useStreamMessage.ts # æµ<EFBFBD>å¼<EFBFBD>消æ<EFBFBD>¯
� └── useAttachment.ts # 附件上传
│ ├── useConversation.ts # 对话管理
│ ├── useAgents.ts # 智能体数据
│ ├── useIntentRouter.ts # 意图路由
│ ├── useStreamMessage.ts # 流式消息
│ └── useAttachment.ts # 附件上传
├── api/
â”? └── index.ts # API å°<EFBFBD>装
│ └── index.ts # API 封装
├── types/
� └── index.ts # TypeScript 类型
│ └── index.ts # TypeScript 类型
├── styles/
â”? ├── dashboard.module.css # Dashboard æ ·å¼<EFBFBD>
â”? └── workspace.module.css # Workspace æ ·å¼<EFBFBD>
│ ├── dashboard.module.css # Dashboard 样式
│ └── workspace.module.css # Workspace 样式
└── index.tsx # 模块入口 + 路由
```
@@ -68,7 +68,7 @@ frontend-v2/src/modules/aia/
--stage-write: #F59E0B; /* 橙色 - 论文撰写 */
--stage-publish: #EF4444; /* 红色 - 成果发布 */
/* 功能�*/
/* 功能色 */
--ai-assistant: #6366F1; /* AI助手主色 */
--thinking-bg: #F3F4F6; /* 思考块背景 */
--thinking-border: #E5E7EB; /* 思考块边框 */
@@ -108,7 +108,7 @@ frontend-v2/src/modules/aia/
## 📄 页面设计
### 1. Dashboard(智能体大厅�
### 1. Dashboard(智能体大厅)
```tsx
// pages/Dashboard.tsx
@@ -119,7 +119,7 @@ import { AgentPipeline } from '../components/AgentPipeline';
export const Dashboard: React.FC = () => {
return (
<div className={styles.dashboard}>
{/* 顶部æ„<EFBFBD>徿<EFBFBD>œç´¢æ¡?*/}
{/* 顶部意图搜索框 */}
<header className={styles.header}>
<h1>AI </h1>
<p></p>
@@ -135,14 +135,14 @@ export const Dashboard: React.FC = () => {
};
```
**布局特点**�
**布局特点**
- 顶部居中大搜索框
- 5阶段æµ<EFBFBD>水线横å<EFBFBD>平铺(桌é<EFBFBD>¢ï¼? 纵å<C2B5>滚动(移动)
- Gemini 风格大留�
- 5阶段流水线横向平铺(桌面)/ 纵向滚动(移动)
- Gemini 风格大留白
---
### 2. Workspace(对è¯<EFBFBD>工作å<EFBFBD>°ï¼?
### 2. Workspace(对话工作台)
```tsx
// pages/Workspace.tsx
@@ -201,7 +201,7 @@ export const Workspace: React.FC = () => {
## 🧩 组件详细设计
### 1. AgentPipelineï¼?阶段æµ<C3A6>水线)
### 1. AgentPipeline5阶段流水线
```tsx
// components/AgentPipeline/index.tsx
@@ -238,7 +238,7 @@ export const AgentPipeline: React.FC<AgentPipelineProps> = ({ onAgentClick }) =>
};
```
**æ ·å¼<EFBFBD>特ç¹**ï¼?
**样式特点**
```css
.pipeline {
display: flex;
@@ -258,7 +258,7 @@ export const AgentPipeline: React.FC<AgentPipelineProps> = ({ onAgentClick }) =>
---
### 2. IntentSearch(æ„<EFBFBD>徿<EFBFBD>œç´¢æ¡†ï¼?
### 2. IntentSearch(意图搜索框)
```tsx
// components/IntentSearch/index.tsx
@@ -307,14 +307,14 @@ export const IntentSearch: React.FC = () => {
---
### 3. ThinkingBlock(深度æ€<EFBFBD>考折å<EFBFBD> å<EFBFBD>—ï¼?
### 3. ThinkingBlock(深度思考折叠块)
```tsx
// components/MessageList/ThinkingBlock.tsx
interface ThinkingBlockProps {
content: string;
duration?: number; // æ€<EFBFBD>考耗时(ç§ï¼?
duration?: number; // 思考耗时(秒)
isStreaming?: boolean; // 是否正在生成
}
@@ -328,7 +328,7 @@ export const ThinkingBlock: React.FC<ThinkingBlockProps> = ({
useEffect(() => {
if (!isStreaming && expanded) {
// 完æˆ<EFBFBD>å<EFBFBD>?1.5s 自动收起
// 完成后 1.5s 自动收起
const timer = setTimeout(() => setExpanded(false), 1500);
return () => clearTimeout(timer);
}
@@ -344,7 +344,7 @@ export const ThinkingBlock: React.FC<ThinkingBlockProps> = ({
{isStreaming ? <LoadingOutlined spin /> : <BulbOutlined />}
</span>
<span className={styles.title}>
{isStreaming ? '正在深度æ€<EFBFBD>è€?..' : `已深度æ€<EFBFBD>è€?(耗时 ${duration?.toFixed(1)}s)`}
{isStreaming ? '正在深度思考...' : `已深度思考 (耗时 ${duration?.toFixed(1)}s)`}
</span>
<span className={styles.expandIcon}>
{expanded ? <UpOutlined /> : <DownOutlined />}
@@ -363,7 +363,7 @@ export const ThinkingBlock: React.FC<ThinkingBlockProps> = ({
};
```
**æ ·å¼<EFBFBD>**ï¼?
**样式**
```css
.thinkingBlock {
background: var(--thinking-bg);
@@ -412,18 +412,18 @@ export const AttachmentUpload: React.FC<AttachmentUploadProps> = ({
const handleUpload = async (file: File) => {
if (attachments.length >= maxCount) {
message.error(`最多上�${maxCount} 个附件`);
message.error(`最多上传 ${maxCount} 个附件`);
return false;
}
// 文件类型校验
const allowedTypes = ['application/pdf', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'text/plain', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'];
if (!allowedTypes.includes(file.type)) {
message.error('仅支æŒ?PDFã€<C3A3>Wordã€<C3A3>TXTã€<C3A3>Excel 文件');
message.error('仅支持 PDF、Word、TXT、Excel 文件');
return false;
}
// æ‡ä»¶å¤§å°<EFBFBD>校验ï¼?0MBï¼?
// 文件大小校验20MB
if (file.size > 20 * 1024 * 1024) {
message.error('文件大小不能超过 20MB');
return false;
@@ -448,7 +448,7 @@ export const AttachmentUpload: React.FC<AttachmentUploadProps> = ({
</Button>
</Upload>
{/* 已上传附件列�*/}
{/* 已上传附件列表 */}
<div className={styles.attachmentList}>
{attachments.map(att => (
<AttachmentCard
@@ -483,10 +483,10 @@ interface SlashCommandsProps {
}
const commands: SlashCommand[] = [
{ key: 'polish', icon: 'âœ?, label: 'æ¦è²', description: 'ä¼˜åŒææœ¬è¡¨è¾¾' },
{ key: 'polish', icon: '✨', label: '润色', description: '优化文本表达' },
{ key: 'expand', icon: '📝', label: '扩写', description: '扩展内容细节' },
{ key: 'translate', icon: '🌐', label: '翻译', description: '中英互译' },
{ key: 'export', icon: 'ðŸ', label: '导åºWord', description: '导åºä¸?Word ææ¡£' },
{ key: 'export', icon: '📄', label: '导出Word', description: '导出为 Word 文档' },
];
export const SlashCommands: React.FC<SlashCommandsProps> = ({
@@ -544,7 +544,7 @@ export const SlashCommands: React.FC<SlashCommandsProps> = ({
---
### 6. ActionBar(结果æ“<EFBFBD>作æ <EFBFBD>ï¼?
### 6. ActionBar(结果操作栏)
```tsx
// components/ActionBar/index.tsx
@@ -623,7 +623,7 @@ export function useConversation(conversationId?: string): UseConversationReturn
}
}, [conversationId]);
// å<EFBFBD>é€<EFBFBD>消æ<EFBFBD>¯ï¼ˆæµ<EFBFBD>å¼<EFBFBD>ï¼?
// 发送消息(流式)
const sendMessage = async (content: string, attachmentIds?: string[]) => {
setIsLoading(true);
@@ -637,7 +637,7 @@ export function useConversation(conversationId?: string): UseConversationReturn
};
setMessages(prev => [...prev, userMessage]);
// åˆ<EFBFBD>å§åŒ?AI 消æ<CB86>¯
// 初始化 AI 消息
const aiMessage: Message = {
id: `temp-ai-${Date.now()}`,
role: 'assistant',
@@ -769,7 +769,7 @@ export function useStreamMessage() {
---
## 📱 å“<C3A5>应å¼<C3A5>设è®?
## 📱 响应式设计
### 断点策略
@@ -783,19 +783,19 @@ const breakpoints = {
};
```
### Dashboard å“<EFBFBD>应å¼?
### Dashboard 响应式
| 断点 | 布局 |
|------|------|
| `< 768px` | 流水线纵向滚动,卡片单列 |
| `â‰?768px` | æµ<EFBFBD>水线横å<EFBFBD>?5 åˆ?|
| `768px` | 流水线横向 5 列 |
### Workspace å“<EFBFBD>应å¼?
### Workspace 响应式
| 断点 | 布局 |
|------|------|
| `< 768px` | 侧边栏隐藏(抽屉滑出),输入框键盘适配 |
| `â‰?768px` | ä¾§è¾¹æ <EFBFBD>åºå®šæ˜¾ç¤?240px |
| `768px` | 侧边栏固定显示 240px |
---
@@ -883,4 +883,3 @@ export interface SlashCommand {