Sprint 1-3 Completed (Backend + Frontend): Backend (Sprint 1-2): - Implement 5-layer Agent framework (Query->Planner->Executor->Tools->Reflection) - Create agent_schema with 6 tables (agent_definitions, stages, prompts, sessions, traces, reflexion_rules) - Create protocol_schema with 2 tables (protocol_contexts, protocol_generations) - Implement Protocol Agent core services (Orchestrator, ContextService, PromptBuilder) - Integrate LLM service adapter (DeepSeek/Qwen/GPT-5/Claude) - 6 API endpoints with full authentication - 10/10 API tests passed Frontend (Sprint 3): - Add Protocol Agent entry in AgentHub (indigo theme card) - Implement ProtocolAgentPage with 3-column layout - Collapsible sidebar (Gemini style, 48px <-> 280px) - StatePanel with 5 stage cards (scientific_question, pico, study_design, sample_size, endpoints) - ChatArea with sync button and action cards integration - 100% prototype design restoration (608 lines CSS) - Detailed endpoints structure: baseline, exposure, outcomes, confounders Features: - 5-stage dialogue flow for research protocol design - Conversation-driven interaction with sync-to-protocol button - Real-time context state management - One-click protocol generation button (UI ready, backend pending) Database: - agent_schema: 6 tables for reusable Agent framework - protocol_schema: 2 tables for Protocol Agent - Seed data: 1 agent + 5 stages + 9 prompts + 4 reflexion rules Code Stats: - Backend: 13 files, 4338 lines - Frontend: 14 files, 2071 lines - Total: 27 files, 6409 lines Status: MVP core functionality completed, pending frontend-backend integration testing Next: Sprint 4 - One-click protocol generation + Word export
135 lines
3.6 KiB
TypeScript
135 lines
3.6 KiB
TypeScript
/**
|
|
* Prompt管理系统初始化脚本
|
|
*
|
|
* 功能:
|
|
* 1. 创建 capability_schema
|
|
* 2. 添加 prompt:* 权限
|
|
* 3. 更新角色权限分配
|
|
*/
|
|
|
|
import { PrismaClient } from '@prisma/client';
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
async function main() {
|
|
console.log('🚀 开始初始化 Prompt 管理系统...\n');
|
|
|
|
// 1. 创建 capability_schema
|
|
console.log('📁 Step 1: 创建 capability_schema...');
|
|
try {
|
|
await prisma.$executeRaw`CREATE SCHEMA IF NOT EXISTS capability_schema`;
|
|
console.log(' ✅ capability_schema 创建成功\n');
|
|
} catch (error) {
|
|
console.log(' ⚠️ capability_schema 可能已存在\n');
|
|
}
|
|
|
|
// 2. 添加 prompt:* 权限
|
|
console.log('🔐 Step 2: 添加 prompt:* 权限...');
|
|
|
|
const promptPermissions = [
|
|
{ code: 'prompt:view', name: '查看Prompt', description: '查看Prompt模板列表和详情', module: 'admin' },
|
|
{ code: 'prompt:edit', name: '编辑Prompt', description: '创建和修改Prompt草稿', module: 'admin' },
|
|
{ code: 'prompt:debug', name: '调试Prompt', description: '开启调试模式,在生产环境测试草稿', module: 'admin' },
|
|
{ code: 'prompt:publish', name: '发布Prompt', description: '将草稿发布为正式版', module: 'admin' },
|
|
];
|
|
|
|
for (const perm of promptPermissions) {
|
|
try {
|
|
await prisma.permissions.upsert({
|
|
where: { code: perm.code },
|
|
update: { name: perm.name, description: perm.description, module: perm.module },
|
|
create: perm,
|
|
});
|
|
console.log(` ✅ ${perm.code}`);
|
|
} catch (error) {
|
|
console.log(` ⚠️ ${perm.code} 添加失败:`, error);
|
|
}
|
|
}
|
|
console.log('');
|
|
|
|
// 3. 获取权限ID
|
|
console.log('🔗 Step 3: 更新角色权限分配...');
|
|
|
|
const permissions = await prisma.permissions.findMany({
|
|
where: { code: { startsWith: 'prompt:' } },
|
|
});
|
|
|
|
const permissionMap = new Map(permissions.map(p => [p.code, p.id]));
|
|
|
|
// SUPER_ADMIN: 全部权限
|
|
const superAdminPermissions = ['prompt:view', 'prompt:edit', 'prompt:debug', 'prompt:publish'];
|
|
for (const permCode of superAdminPermissions) {
|
|
const permId = permissionMap.get(permCode);
|
|
if (permId) {
|
|
try {
|
|
await prisma.role_permissions.upsert({
|
|
where: {
|
|
role_permission_id: { role: 'SUPER_ADMIN', permission_id: permId },
|
|
},
|
|
update: {},
|
|
create: { role: 'SUPER_ADMIN', permission_id: permId },
|
|
});
|
|
} catch (error) {
|
|
// 可能已存在
|
|
}
|
|
}
|
|
}
|
|
console.log(' ✅ SUPER_ADMIN: prompt:view, prompt:edit, prompt:debug, prompt:publish');
|
|
|
|
// PROMPT_ENGINEER: 无 publish 权限
|
|
const promptEngineerPermissions = ['prompt:view', 'prompt:edit', 'prompt:debug'];
|
|
for (const permCode of promptEngineerPermissions) {
|
|
const permId = permissionMap.get(permCode);
|
|
if (permId) {
|
|
try {
|
|
await prisma.role_permissions.upsert({
|
|
where: {
|
|
role_permission_id: { role: 'PROMPT_ENGINEER', permission_id: permId },
|
|
},
|
|
update: {},
|
|
create: { role: 'PROMPT_ENGINEER', permission_id: permId },
|
|
});
|
|
} catch (error) {
|
|
// 可能已存在
|
|
}
|
|
}
|
|
}
|
|
console.log(' ✅ PROMPT_ENGINEER: prompt:view, prompt:edit, prompt:debug (无publish)');
|
|
console.log('');
|
|
|
|
// 4. 验证
|
|
console.log('✅ Prompt 管理系统初始化完成!\n');
|
|
|
|
const allPermissions = await prisma.permissions.findMany({
|
|
where: { code: { startsWith: 'prompt:' } },
|
|
});
|
|
console.log('📋 已添加的权限:');
|
|
allPermissions.forEach(p => console.log(` - ${p.code}: ${p.name}`));
|
|
}
|
|
|
|
main()
|
|
.catch(console.error)
|
|
.finally(() => prisma.$disconnect());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|