Summary: - Implement Prompt management infrastructure and core services - Build admin portal frontend with light theme - Integrate CodeMirror 6 editor for non-technical users Phase 3.5.1: Infrastructure Setup - Create capability_schema for Prompt storage - Add prompt_templates and prompt_versions tables - Add prompt:view/edit/debug/publish permissions - Migrate RVW prompts to database (RVW_EDITORIAL, RVW_METHODOLOGY) Phase 3.5.2: PromptService Core - Implement gray preview logic (DRAFT for debuggers, ACTIVE for users) - Module-level debug control (setDebugMode) - Handlebars template rendering - Variable extraction and validation (extractVariables, validateVariables) - Three-level disaster recovery (database -> cache -> hardcoded fallback) Phase 3.5.3: Management API - 8 RESTful endpoints (/api/admin/prompts/*) - Permission control (PROMPT_ENGINEER can edit, SUPER_ADMIN can publish) Phase 3.5.4: Frontend Management UI - Build admin portal architecture (AdminLayout, OrgLayout) - Add route system (/admin/*, /org/*) - Implement PromptListPage (filter, search, debug switch) - Implement PromptEditor (CodeMirror 6 simplified for clinical users) - Implement PromptEditorPage (edit, save, publish, test, version history) Technical Details: - Backend: 6 files, ~2044 lines (prompt.service.ts 596 lines) - Frontend: 9 files, ~1735 lines (PromptEditorPage.tsx 399 lines) - CodeMirror 6: Line numbers, auto-wrap, variable highlight, search, undo/redo - Chinese-friendly: 15px font, 1.8 line-height, system fonts Next Step: Phase 3.5.5 - Integrate RVW module with PromptService Tested: Backend API tests passed (8/8), Frontend pending user testing Status: Ready for Phase 3.5.5 RVW integration
194 lines
4.4 KiB
Markdown
194 lines
4.4 KiB
Markdown
# 🚀 给新AI助手的快速指南
|
||
|
||
> **更新时间:** 2026-01-11
|
||
> **当前任务:** Phase 3.5.5 - RVW 模块集成
|
||
|
||
---
|
||
|
||
## ⚡ 30秒了解当前状态
|
||
|
||
```
|
||
✅ Phase 3.5.1-3.5.4 已完成(83%)
|
||
⏳ Phase 3.5.5 待开始:改造 RVW 服务使用 PromptService
|
||
|
||
已完成:
|
||
✅ 数据库:capability_schema + prompt_templates + prompt_versions
|
||
✅ 后端:PromptService(596行)+ 8个API接口
|
||
✅ 前端:管理端架构 + Prompt列表 + 编辑器(CodeMirror 6)
|
||
✅ 测试:后端单元测试全部通过
|
||
|
||
下一步:
|
||
→ 改造 backend/src/modules/rvw/services/editorialService.ts
|
||
→ 改造 backend/src/modules/rvw/services/methodologyService.ts
|
||
→ 替换文件读取为 promptService.get()
|
||
```
|
||
|
||
---
|
||
|
||
## 📁 关键文件位置
|
||
|
||
### 核心文件(必读)
|
||
|
||
| 文件 | 说明 | 行数 |
|
||
|------|------|------|
|
||
| `backend/src/common/prompt/prompt.service.ts` | PromptService 核心逻辑 | 596 |
|
||
| `backend/src/modules/rvw/services/editorialService.ts` | RVW 稿约评估服务(待改造)| ? |
|
||
| `backend/src/modules/rvw/services/methodologyService.ts` | RVW 方法学评估服务(待改造)| ? |
|
||
| `frontend-v2/src/pages/admin/PromptEditorPage.tsx` | Prompt 编辑器页面 | 399 |
|
||
|
||
### 文档(必读)
|
||
|
||
| 文档 | 内容 |
|
||
|------|------|
|
||
| `04-开发计划/01-TODO清单(可追踪).md` | 详细任务清单(79/110 完成)|
|
||
| `04-开发计划/02-Prompt管理系统开发计划.md` | 完整开发计划 |
|
||
| `00-Phase3.5完成总结.md` | 已完成工作总结 |
|
||
|
||
---
|
||
|
||
## 🎯 Phase 3.5.5 任务详解
|
||
|
||
### 任务 1:改造 editorialService.ts
|
||
|
||
**当前实现**(文件读取)
|
||
```typescript
|
||
const PROMPT_PATH = path.join(__dirname, '../../../../prompts/review_editorial_system.txt');
|
||
const prompt = fs.readFileSync(PROMPT_PATH, 'utf-8');
|
||
```
|
||
|
||
**改造后**(PromptService)
|
||
```typescript
|
||
import { getPromptService } from '../../../common/prompt/index.js';
|
||
|
||
const promptService = getPromptService(prisma);
|
||
const { content, modelConfig } = await promptService.get('RVW_EDITORIAL', {}, userId);
|
||
```
|
||
|
||
### 任务 2:改造 methodologyService.ts
|
||
|
||
**当前实现**
|
||
```typescript
|
||
const PROMPT_PATH = path.join(__dirname, '../../../../prompts/review_methodology_system.txt');
|
||
const prompt = fs.readFileSync(PROMPT_PATH, 'utf-8');
|
||
```
|
||
|
||
**改造后**
|
||
```typescript
|
||
const { content, modelConfig } = await promptService.get('RVW_METHODOLOGY', {}, userId);
|
||
```
|
||
|
||
### 任务 3:测试验证
|
||
|
||
**测试步骤**
|
||
1. 登录 Prompt工程师(`13800000002` / `123456`)
|
||
2. 进入 `/admin/prompts`
|
||
3. 编辑 `RVW_EDITORIAL`,修改一处内容(如添加"测试")
|
||
4. 保存草稿
|
||
5. 开启调试模式,选择 RVW 模块
|
||
6. 切换到业务端 `/rvw`
|
||
7. 上传一个文档,查看审查结果是否使用了修改后的 Prompt
|
||
8. 验证普通用户仍使用旧版本
|
||
|
||
---
|
||
|
||
## 🔑 关键代码示例
|
||
|
||
### PromptService.get() 用法
|
||
|
||
```typescript
|
||
// 获取 Prompt(自动灰度)
|
||
const result = await promptService.get(
|
||
'RVW_EDITORIAL', // code
|
||
{}, // variables(RVW无变量)
|
||
{ userId: req.user.id } // 用于判断调试模式
|
||
);
|
||
|
||
// 使用渲染后的内容
|
||
const messages = [
|
||
{ role: 'system', content: result.content },
|
||
{ role: 'user', content: documentText },
|
||
];
|
||
|
||
// 使用模型配置
|
||
const llmResponse = await llm.chat(messages, {
|
||
temperature: result.modelConfig.temperature,
|
||
model: result.modelConfig.model,
|
||
});
|
||
```
|
||
|
||
### 调试模式 API
|
||
|
||
```typescript
|
||
// 开启调试(只调试 RVW)
|
||
POST /api/admin/prompts/debug
|
||
{
|
||
"modules": ["RVW"],
|
||
"enabled": true
|
||
}
|
||
|
||
// 关闭调试
|
||
POST /api/admin/prompts/debug
|
||
{
|
||
"modules": [],
|
||
"enabled": false
|
||
}
|
||
```
|
||
|
||
---
|
||
|
||
## 🛠️ 环境信息
|
||
|
||
### 数据库
|
||
|
||
```
|
||
Host: localhost
|
||
Port: 5432
|
||
Database: ai_clinical_research
|
||
User: postgres
|
||
Password: postgres123
|
||
```
|
||
|
||
### 后端服务
|
||
|
||
```
|
||
端口: 3001
|
||
启动: cd backend && npm run dev
|
||
```
|
||
|
||
### 前端服务
|
||
|
||
```
|
||
端口: 3000
|
||
启动: cd frontend-v2 && npm run dev
|
||
代理: /api -> http://localhost:3001 (已配置)
|
||
```
|
||
|
||
---
|
||
|
||
## ⚠️ 常见问题
|
||
|
||
### 1. Prisma Client 找不到 prompt_templates
|
||
|
||
**解决**:运行 `npx prisma generate`
|
||
|
||
### 2. 前端调用 API 401
|
||
|
||
**解决**:检查是否已登录,JWT Token 是否有效
|
||
|
||
### 3. CodeMirror 不显示
|
||
|
||
**解决**:检查是否安装了 `codemirror` 和 `@codemirror/*` 依赖
|
||
|
||
---
|
||
|
||
## 📞 联系信息
|
||
|
||
如有疑问,请查阅:
|
||
- 技术设计:`02-技术设计/03-Prompt管理系统快速参考.md`
|
||
- 开发规范:`../../04-开发规范/`
|
||
|
||
---
|
||
|
||
*祝开发顺利! 🚀*
|
||
|