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
101 lines
3.5 KiB
TypeScript
101 lines
3.5 KiB
TypeScript
/**
|
||
* 测试 Prompt 管理 API
|
||
*
|
||
* 启动后端后运行: npx tsx scripts/test-prompt-api.ts
|
||
*/
|
||
|
||
const BASE_URL = 'http://localhost:3001/api/admin/prompts';
|
||
|
||
async function testAPI() {
|
||
console.log('🧪 测试 Prompt 管理 API...\n');
|
||
|
||
// 1. 获取列表
|
||
console.log('═══════════════════════════════════════════════════════');
|
||
console.log('📋 Test 1: GET /api/admin/prompts\n');
|
||
|
||
const listRes = await fetch(BASE_URL);
|
||
const listData = await listRes.json();
|
||
console.log(` 状态: ${listRes.status}`);
|
||
console.log(` 总数: ${listData.total}`);
|
||
console.log(` Prompts:`);
|
||
for (const p of listData.data || []) {
|
||
console.log(` - ${p.code} (${p.name}) v${p.latestVersion?.version || 0}`);
|
||
}
|
||
|
||
// 2. 获取详情
|
||
console.log('\n═══════════════════════════════════════════════════════');
|
||
console.log('📋 Test 2: GET /api/admin/prompts/RVW_EDITORIAL\n');
|
||
|
||
const detailRes = await fetch(`${BASE_URL}/RVW_EDITORIAL`);
|
||
const detailData = await detailRes.json();
|
||
console.log(` 状态: ${detailRes.status}`);
|
||
console.log(` Code: ${detailData.data?.code}`);
|
||
console.log(` Name: ${detailData.data?.name}`);
|
||
console.log(` 版本数: ${detailData.data?.versions?.length || 0}`);
|
||
|
||
// 3. 测试渲染
|
||
console.log('\n═══════════════════════════════════════════════════════');
|
||
console.log('📋 Test 3: POST /api/admin/prompts/test-render\n');
|
||
|
||
const renderRes = await fetch(`${BASE_URL}/test-render`, {
|
||
method: 'POST',
|
||
headers: { 'Content-Type': 'application/json' },
|
||
body: JSON.stringify({
|
||
content: '你好,{{name}}!请评估标题:{{title}}',
|
||
variables: { name: '张三', title: '测试标题' },
|
||
}),
|
||
});
|
||
const renderData = await renderRes.json();
|
||
console.log(` 状态: ${renderRes.status}`);
|
||
console.log(` 渲染结果: ${renderData.data?.rendered}`);
|
||
console.log(` 提取变量: [${renderData.data?.extractedVariables?.join(', ')}]`);
|
||
console.log(` 校验结果: ${renderData.data?.validation?.isValid ? '✅ 通过' : '❌ 缺少变量'}`);
|
||
|
||
// 4. 按模块筛选
|
||
console.log('\n═══════════════════════════════════════════════════════');
|
||
console.log('📋 Test 4: GET /api/admin/prompts?module=RVW\n');
|
||
|
||
const rvwRes = await fetch(`${BASE_URL}?module=RVW`);
|
||
const rvwData = await rvwRes.json();
|
||
console.log(` 状态: ${rvwRes.status}`);
|
||
console.log(` RVW模块Prompt数: ${rvwData.total}`);
|
||
for (const p of rvwData.data || []) {
|
||
console.log(` - ${p.code}`);
|
||
}
|
||
|
||
// 5. 获取调试状态(无认证,预期返回401)
|
||
console.log('\n═══════════════════════════════════════════════════════');
|
||
console.log('📋 Test 5: GET /api/admin/prompts/debug (无认证)\n');
|
||
|
||
const debugRes = await fetch(`${BASE_URL}/debug`);
|
||
const debugData = await debugRes.json();
|
||
console.log(` 状态: ${debugRes.status}`);
|
||
console.log(` 响应: ${JSON.stringify(debugData)}`);
|
||
|
||
console.log('\n✅ API 测试完成!');
|
||
}
|
||
|
||
testAPI().catch(console.error);
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|