// AgentPanel.jsx — Center orchestration column import { useState } from 'react'; import { ShieldAlert, FlaskConical, Stethoscope, ListChecks, Zap, CheckCircle, Loader, Circle, ChevronDown, ChevronUp } from 'lucide-react'; const AGENTS = [ { key: 'triage', label: 'Triage Agent', icon: , desc: 'Severity classification & chief complaint' }, { key: 'contraindication', label: 'Contraindication Guardian', icon: , desc: 'Drug interactions & allergy risks' }, { key: 'labs', label: 'Lab Interpreter', icon: , desc: 'Critical lab findings & patterns' }, { key: 'differentials', label: 'Differential Diagnosis', icon: , desc: 'Top 3 differentials from evidence' }, { key: 'action_protocol', label: 'Action Protocol', icon: , desc: 'Immediate ordered steps & disposition' }, ]; const THINKING_MESSAGES = { triage: "Analyzing vitals and identifying life-threats...", contraindication: "Scanning history for high-risk medication overlaps...", labs: "Interpreting metabolic panels and blood gases...", differentials: "Cross-referencing symptoms with clinical evidence...", action_protocol: "Synthesizing final emergency stabilization steps...", }; function StatusIcon({ status }) { if (status === 'working') return
; if (status === 'complete') return ; if (status === 'error') return ; return ; } function AgentRow({ agent, status, result, expanded, onToggle }) { const cls = status === 'idle' ? 'agent-idle' : status === 'working' ? 'agent-working' : status === 'complete' ? 'agent-complete' : 'agent-error'; const hasResult = result && status === 'complete'; return (
{agent.icon}
{agent.label}
{status === 'working' ? THINKING_MESSAGES[agent.key] : agent.desc}
{hasResult && (expanded ? : )}
{hasResult && expanded && (
)}
); } function AgentResultPreview({ agentKey, result }) { const style = { fontSize: 11, color: 'var(--text-secondary)', lineHeight: 1.6 }; const tag = (text, color) => ( {text} ); if (agentKey === 'triage') return (
{tag(`ESI ${result.severity}: ${result.severity_label}`, result.severity <= 2 ? 'var(--red-critical)' : result.severity === 3 ? 'var(--amber-warning)' : 'var(--green-safe)')}

{result.chief_complaint}

{(result.time_critical_flags || []).map((f, i) =>

⚡ {f}

)} {result.agent_reasoning && (

AGENT REASONING

{result.agent_reasoning.map((r, i) =>

• {r}

)}
)}
); if (agentKey === 'contraindication') return (
{tag(result.treatment_verdict, result.treatment_verdict === 'SAFE' ? 'var(--green-safe)' : result.treatment_verdict === 'CONTRAINDICATED' ? 'var(--red-critical)' : 'var(--amber-warning)')}

{result.verdict_reason}

{(result.allergy_risks || []).slice(0, 2).map((r, i) => (

⚠ Allergy: {r.substance} → {r.risk}

))} {(result.drug_interactions || []).slice(0, 2).map((d, i) => (

💊 {d.drug_a} + {d.drug_b}: {d.interaction}

))} {result.agent_reasoning && (

AGENT REASONING

{result.agent_reasoning.map((r, i) =>

• {r}

)}
)}
); if (agentKey === 'labs') return (
{(result.critical_labs || []).map((l, i) => (

🔴 {l.name}: {l.value} — {l.significance}

))} {(result.abnormal_labs || []).map((l, i) => (

🟡 {l.name}: {l.value} — {l.significance}

))} {(result.immediate_concerns || []).slice(0, 2).map((c, i) =>

→ {c}

)} {result.agent_reasoning && (

AGENT REASONING

{result.agent_reasoning.map((r, i) =>

• {r}

)}
)}
); if (agentKey === 'differentials') return (
{(result.differentials || []).map((d, i) => (
{tag(d.likelihood, d.likelihood === 'HIGH' ? 'var(--red-critical)' : d.likelihood === 'MODERATE' ? 'var(--amber-warning)' : 'var(--text-secondary)')} {d.diagnosis} {d.must_rule_out && MUST RULE OUT}
))} {result.agent_reasoning && (

AGENT REASONING

{result.agent_reasoning.map((r, i) =>

• {r}

)}
)}
); if (agentKey === 'action_protocol') return (
{(result.immediate_actions || []).map((a, i) =>

{i + 1}. {a}

)} {result.disposition && (

Disposition → {result.disposition}

)} {result.agent_reasoning && (

AGENT REASONING

{result.agent_reasoning.map((r, i) =>

• {r}

)}
)}
); return null; } export function AgentPanel({ agentStatuses, agentResults, onRun, patient, running, focus, setFocus }) { const [expanded, setExpanded] = useState({}); const toggle = key => setExpanded(e => ({ ...e, [key]: !e[key] })); const doneCount = AGENTS.filter(a => agentStatuses[a.key] === 'complete').length; return (
Agent Orchestration {running && (
{doneCount}/5 complete )}
{!patient && (
Select a patient to run emergency analysis
)} {patient && ( <> {/* Clinical Focus Selector */}

Clinical Focus

{['General', 'Cardiac', 'Trauma', 'Respiratory', 'Neuro'].map(f => (
!running && setFocus?.(f)} style={{ padding: '4px 10px', borderRadius: 20, fontSize: 10, fontWeight: 700, cursor: 'pointer', background: focus === f ? 'var(--blue-accent)' : 'var(--bg-surface)', color: focus === f ? '#fff' : 'var(--text-secondary)', border: focus === f ? 'none' : '1px solid var(--border-subtle)', transition: 'all 0.2s' }} > {f}
))}
{/* Agent rows */} {AGENTS.map(a => ( toggle(a.key)} /> ))} {/* Run button */} {/* Collaboration Log */} {running || Object.keys(agentResults).length > 0 ? (

Collaboration Thread

{AGENTS.filter(a => agentResults[a.key] || agentStatuses[a.key] === 'working').map((a, i) => (
[{a.label}]: {agentStatuses[a.key] === 'working' ? 'Transmitting findings...' : (agentResults[a.key]?.agent_reasoning?.[0] || 'Processed record successfully.')}
))}
) : null} )}
); }