import { useState } from "react"; import { generateSynthesis } from "../api/protocols"; import type { SynthesisResult } from "../types"; interface SynthesisPanelProps { protocolId: string; initialSynthesis: SynthesisResult | null; } // Only matches real evidence-ID citations (e.g. [pubmed-12345], // [europepmc-98765]) - deliberately NOT a bare [a-zA-Z0-9_-]+ pattern, since // the model sometimes brackets abbreviations (e.g. "[ALT]") when it isn't // citing anything; matching only known source prefixes avoids styling // those as if they were real citations. const BOLD_PATTERN = /(\*\*(.+?)\*\*)|(\[((?:pubmed|europepmc)-[a-zA-Z0-9._-]+)\])/g; function renderInline(text: string) { const nodes: React.ReactNode[] = []; let lastIndex = 0; let key = 0; for (const match of text.matchAll(BOLD_PATTERN)) { const index = match.index ?? 0; if (index > lastIndex) nodes.push(text.slice(lastIndex, index)); const [full, boldFull, boldText, , citationId] = match; if (boldFull) { nodes.push({boldText}); } else if (citationId) { nodes.push( {citationId} ); } lastIndex = index + full.length; } if (lastIndex < text.length) nodes.push(text.slice(lastIndex)); return nodes; } function renderSynthesisBody(text: string) { const lines = text.split("\n"); const blocks: React.ReactNode[] = []; let listBuffer: string[] = []; let blockKey = 0; const flushList = () => { if (listBuffer.length === 0) return; blocks.push(
{renderInline(line)}
); } } flushList(); return blocks; } export function SynthesisPanel({ protocolId, initialSynthesis }: SynthesisPanelProps) { const [synthesis, setSynthesis] = useStateGenerated {new Date(synthesis.generated_at).toLocaleString()}
> ) : ( !error && (No synthesis generated yet. This step uses an LLM to draft prose from the evidence table above — requires GROQ_API_KEY set in the backend's .env.
) )}