import type { Reasoning, StageName, StreamStageEvent } from '../types' interface Props { reasoning: Reasoning agent: string activeStage?: StageName | null stageEvents?: StreamStageEvent[] } function badgeClass(active: boolean): string { return active ? 'bg-blue-900/70 border-blue-500 text-blue-200 shadow-[0_0_20px_rgba(59,130,246,0.3)]' : 'bg-zinc-900 border-zinc-800 text-zinc-400' } function stageSummary(stage: StageName, reasoning: Reasoning): string { if (stage === 'pytorch') { const top = [...reasoning.pytorch_scores] .sort((a, b) => b.score - a.score) .slice(0, 3) .map((s) => `${s.zone_id}:${s.score.toFixed(2)}`) return top.length > 0 ? `Top activations → ${top.join(', ')}` : 'No zone scores yet.' } if (stage === 'triage') return reasoning.triage_summary || 'Triage analysis pending.' if (stage === 'planner') return reasoning.plan_decision || 'Planner has no decision yet.' return reasoning.action_rationale || 'Action rationale pending.' } const STAGES: Array<{ key: StageName; title: string; icon: string }> = [ { key: 'pytorch', title: 'PyTorch ZoneScorer', icon: '🧠' }, { key: 'triage', title: 'Triage Agent', icon: '🔍' }, { key: 'planner', title: 'Planner Agent', icon: '📋' }, { key: 'action', title: 'Action Agent', icon: '✅' }, ] export function AgentReasoningPanel({ reasoning, agent, activeStage = null, stageEvents = [] }: Props) { const triageDetails = reasoning.triage const planDetails = reasoning.plan const validator = reasoning.validator const durations = reasoning.stage_timings_ms return (

Agent Thinking Theater

{agent}
{STAGES.map((stage, index) => { const active = activeStage === stage.key const ev = stageEvents.find((e) => e.stage === stage.key) const durationMs = ev?.duration_ms ?? durations?.[stage.key] return (
{stage.icon} {stage.title}
{typeof durationMs === 'number' ? `${durationMs.toFixed(1)} ms` : '—'}
{ev?.summary || stageSummary(stage.key, reasoning)}
) })}
False-SOS Confidence
{Math.round((triageDetails?.confidence ?? 0.5) * 100)}% {triageDetails?.false_sos_suspects?.join(', ') || 'none'}
Planner Trade-off
{planDetails?.critical_decision || reasoning.plan_decision || 'No trade-off summary yet.'}
{planDetails?.step_plan?.length ? (
{planDetails.step_plan.slice(0, 3).map((p) => `T+${p.step_offset}:${p.action}@${p.zone ?? 'HQ'}`).join(' | ')}
) : null}
Validator Checklist
{(validator?.constraints_checked ?? ['zone_exists', 'resource_limits', 'road_access']).join(', ')}
{validator?.fallback_used ? 'Fallback heuristic used for safety.' : 'Primary plan passed validation.'}
) }