feat(aia): Integrate PromptService for 10 AI agents

Features:
- Migrate 10 agent prompts from hardcoded to database
- Add grayscale preview support (DRAFT/ACTIVE distribution)
- Implement 3-tier fallback (DB -> Cache -> Hardcoded)
- Add version management and rollback capability

Files changed:
- backend/scripts/migrate-aia-prompts.ts (new migration script)
- backend/src/common/prompt/prompt.fallbacks.ts (add AIA fallbacks)
- backend/src/modules/aia/services/agentService.ts (integrate PromptService)
- backend/src/modules/aia/services/conversationService.ts (pass userId)
- backend/src/modules/aia/types/index.ts (fix AgentStage type)

Documentation:
- docs/03-业务模块/AIA-AI智能问答/06-开发记录/2026-01-18-Prompt管理系统集成.md
- docs/02-通用能力层/00-通用能力层清单.md (add FileCard, Prompt management)
- docs/00-系统总体设计/00-系统当前状态与开发指南.md (update to v3.6)

Prompt codes:
- AIA_SCIENTIFIC_QUESTION, AIA_PICO_ANALYSIS, AIA_TOPIC_EVALUATION
- AIA_OUTCOME_DESIGN, AIA_CRF_DESIGN, AIA_SAMPLE_SIZE
- AIA_PROTOCOL_WRITING, AIA_METHODOLOGY_REVIEW
- AIA_PAPER_POLISH, AIA_PAPER_TRANSLATE

Tested: Migration script executed, all 10 prompts inserted successfully
This commit is contained in:
2026-01-18 15:48:53 +08:00
parent 66255368b7
commit 57fdc6ef00
290 changed files with 2950 additions and 106 deletions

View File

@@ -1,9 +1,10 @@
# 通用能力层清单
> **文档版本:** v2.0
> **文档版本:** v2.1
> **创建日期:** 2026-01-14
> **最后更新:** 2026-01-14
> **最后更新:** 2026-01-18
> **文档目的:** 列出所有通用能力模块,提供快速调用指南
> **本次更新:** Ant Design X FileCard 组件使用、Prompt管理 AIA 集成
---
@@ -42,6 +43,7 @@
| 能力 | 路径 | 状态 | 说明 |
|------|------|------|------|
| **Chat组件** | `shared/components/Chat/` | ✅ 🆕 | AI对话通用组件V2 |
| **FileCard组件** | `@ant-design/x` | ✅ 🆕 | 文件卡片展示(附件) |
| **认证API** | `framework/auth/api.ts` | ✅ | Token管理 |
| **API Client** | `common/api/axios.ts` | ✅ | 带认证的axios实例 |
| **通用布局** | `shared/layouts/` | ✅ | 主布局、侧边栏 |
@@ -95,7 +97,59 @@ data: [DONE]\n\n
---
### 2. Chat 通用组件(🆕 重点推荐)
### 2. Prompt 管理服务
**路径:** `backend/src/common/prompt/`
**功能:** 动态 Prompt 配置、灰度预览、版本管理
**核心特性:**
- 灰度预览DRAFT/ACTIVE 分发)
- Handlebars 模板渲染
- 变量提取与校验
- 三级容灾(数据库→缓存→兜底)
**使用方式:**
```typescript
import { getPromptService } from '../../../common/prompt';
import { prisma } from '../../../config/database';
// 获取 Prompt支持灰度预览
const promptService = getPromptService(prisma);
const { content, isDraft, version } = await promptService.get(
'AIA_SCIENTIFIC_QUESTION', // Prompt Code
{}, // 变量(如 { userName: '张三' }
{ userId } // 用于灰度判断
);
if (isDraft) {
console.log('使用 DRAFT 版本(调试模式)');
}
```
**已集成模块:**
- ✅ RVW - 稿件审查2个 Prompt
- ✅ AIA - AI智能问答10个 Prompt🆕 2026-01-18
**AIA 模块 Prompt Code 列表:**
| Prompt Code | 智能体 |
|-------------|--------|
| `AIA_SCIENTIFIC_QUESTION` | 科学问题梳理 |
| `AIA_PICO_ANALYSIS` | PICO 梳理 |
| `AIA_TOPIC_EVALUATION` | 选题评价 |
| `AIA_OUTCOME_DESIGN` | 观察指标设计 |
| `AIA_CRF_DESIGN` | 病例报告表设计 |
| `AIA_SAMPLE_SIZE` | 样本量计算 |
| `AIA_PROTOCOL_WRITING` | 临床研究方案撰写 |
| `AIA_METHODOLOGY_REVIEW` | 方法学评审智能体 |
| `AIA_PAPER_POLISH` | 论文润色 |
| `AIA_PAPER_TRANSLATE` | 论文翻译 |
---
### 3. Chat 通用组件(🆕 重点推荐)
**路径:** `frontend-v2/src/shared/components/Chat/`
@@ -137,7 +191,77 @@ import {
---
### 3. LLM 网关
### 4. Ant Design X FileCard 组件(🆕 2026-01-18
**来源:** `@ant-design/x` (Ant Design X 2.1)
**功能:** 紧凑的文件卡片展示,适用于聊天界面附件显示
**安装:**
```bash
npm install @ant-design/x
```
**使用方式:**
```tsx
import { Attachments } from '@ant-design/x';
const { FileCard } = Attachments;
// 单个文件卡片
<FileCard
item={{
uid: 'file-1',
name: '研究方案.pdf',
size: 1024000, // 字节
}}
/>
// 文件卡片列表(水平排列)
<FileCard.List
items={[
{ uid: '1', name: '方案.pdf', size: 512000 },
{ uid: '2', name: '数据.xlsx', size: 256000 },
]}
/>
```
**在聊天界面中使用:**
```tsx
// 将附件与工具栏放在同一行
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
<Button icon={<PaperClipOutlined />}></Button>
<Button icon={<BulbOutlined />}></Button>
{/* 附件列表 */}
{attachments.length > 0 && (
<FileCard.List
items={attachments.map(att => ({
uid: att.id,
name: att.filename,
size: att.size,
}))}
/>
)}
</div>
```
**样式特点:**
- 自动识别文件类型图标PDF/Word/Excel/图片等)
- 自动格式化文件大小KB/MB
- 紧凑设计,适合水平排列
- 支持删除回调
**已使用模块:**
- ✅ AIA - AI智能问答附件上传预览
**官方文档:** https://x.ant.design/components/attachments-cn
---
### 5. LLM 网关
**路径:** `backend/src/common/llm/`
@@ -769,3 +893,6 @@ await storage.upload('path/file.txt', buffer);