import React, { useState, useMemo } from 'react'; import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer, ReferenceLine } from 'recharts'; import { simulate } from '../api/client'; import type { SimResult, TaskInfo } from '../types'; import { Zap } from 'lucide-react'; import { CommsInterceptTerminal } from './CommsInterceptTerminal'; interface Props { tasks: TaskInfo[]; } const ACTION_LABELS: Record = { 'deploy_team': 'Dispatch Rescue (Ground)', 'send_supplies': 'Route Supply Convoy', 'airlift': 'Call Emergency Airlift', 'wait': 'Wait Penalty Applied' }; const ACTION_COLORS: Record = { 'deploy_team': 'bg-blue-600/90 text-blue-100', 'send_supplies': 'bg-orange-500/90 text-orange-100', 'airlift': 'bg-cyan-600/90 text-cyan-100', 'wait': 'bg-red-800/90 text-red-100' }; const SectionHeader = ({ title, subtitle }: { title: string, subtitle?: string }) => (

{title}

{subtitle &&

{subtitle}

}
); function ZoneContentionMatrix({ data }: { data: { zones: string[], matrix: (number | null)[][] } }) { const { zones, matrix } = data; if (!zones.length) return
Run simulation to process matrix.
; return (
{/* Header Row */}
{zones.map(z =>
{z}
)}
{/* Body Rows */} {zones.map((z1, rIdx) => (
{z1}
{zones.map((z2, cIdx) => { const val = matrix[rIdx][cIdx]; let bg = "bg-[#111318]"; let text = ""; let shadow = ""; if (val === null) text = "•"; else if (val >= 50) { bg = "bg-red-600"; text = `${val}%`; shadow = "shadow-[0_0_15px_rgba(220,38,38,0.7)] z-10 scale-105"; } else if (val >= 25) { bg = "bg-orange-600"; text = `${val}%`; shadow = "shadow-[0_0_10px_rgba(234,88,12,0.4)] z-10 scale-105"; } else if (val >= 10) { bg = "bg-yellow-600/80"; text = `${val}%`; } else if (val > 0) { text = `${val}%`; } else { text = "0%"; } return (
{text}
); })}
))}
); } function SmallChart({ data, dataKey, color, title, criticalAt }: any) { if (!data.length) return
Awaiting data
; return (
{title}
); } function ResourceHistory({ data }: { data: any[] }) { return (
); } function AgentNetworkRadar({ result }: { result: SimResult | null }) { // Try to find PyTorch scores from the most critical step const lastStep = result?.steps[result.steps.length - 1]; const scores = lastStep?.reasoning?.pytorch_scores || []; const topScores = [...scores].sort((a, b) => b.score - a.score).slice(0, 4); if (!result || !topScores.length) { return
Run simulation with PyTorch AI agent for radar telemetry.
} const sortedZones = topScores.map(t => ({ zone: t.zone_id, score: Math.round(t.score * 100) })); const positions = [ { top: '12%', left: '50%', transform: '-translate-x-1/2', bg: 'bg-red-600', shadow: 'shadow-[0_0_20px_rgba(220,38,38,0.6)]' }, { top: '50%', right: '12%', transform: '-translate-y-1/2', bg: 'bg-orange-500', shadow: 'shadow-[0_0_15px_rgba(249,115,22,0.5)]' }, { bottom: '12%', left: '50%', transform: '-translate-x-1/2', bg: 'bg-indigo-600', shadow: 'shadow-[0_0_15px_rgba(79,70,229,0.5)]' }, { top: '50%', left: '16%', transform: '-translate-y-1/2', bg: 'bg-emerald-600', shadow: '' }, ]; return (
{/* Background circles */}
{sortedZones[0] && } {sortedZones[1] && } {sortedZones[2] && } {sortedZones[3] && } {/* Nodes */} {sortedZones.map((z, i) => (
{z.zone}
Node {z.zone}
{z.score}%
))}
HQ

Attention Rank

{sortedZones.map((z, i) => (
{i+1}. Zone {z.zone}{z.score}%
))}

Network Rationale

Live API data extraction successful. Neural ranking algorithm evaluates {sortedZones[0]?.zone} as critical failure vector. Deep routing protocols initiated.

Engine: {result.agent} pipeline
); } function StrategyHeatmap({ displayData, mode, setMode }: any) { const { actions, zones, matrix } = displayData; if (!zones?.length) return
Run simulation to populate heatmap.
; return (
{mode === 'type' ? ( {zones.map((z: string) => )} {actions.map((actionKey: string, rIdx: number) => { const rowTotal = matrix[rIdx].reduce((a:number,b:number)=>a+b, 0); if (rowTotal === 0) return null; // hide unused actions return ( {zones.map((z: string, cIdx: number) => { const val = matrix[rIdx][cIdx]; const colorClass = val > 0 ? (ACTION_COLORS[actionKey] || 'bg-zinc-700 text-white') : 'bg-[#18181b] text-transparent'; return ( ) })} )})}
Enacted Strategy
{z}
{ACTION_LABELS[actionKey] || actionKey}
0 ? 'shadow-sm' : ''}`}> {val > 0 ? val : ''}
) : ( {actions.map((a: string) => { const colTotal = matrix[actions.indexOf(a)].reduce((acc:number,v:number)=>acc+v,0); if (colTotal === 0) return null; return })} {zones.map((z: string, cIdx: number) => ( {actions.map((actionKey: string, rIdx: number) => { const colTotal = matrix[rIdx].reduce((acc:number,v:number)=>acc+v,0); if (colTotal === 0) return null; const val = matrix[rIdx][cIdx]; const colorClass = val > 0 ? (ACTION_COLORS[actionKey] || 'bg-zinc-700 text-white') : 'bg-[#18181b] text-transparent'; return ( ) })} ))}
Node Focus{ACTION_LABELS[a]?.split(' ')[0] || a}
Zone {z}
{val > 0 ? val : ''}
)}
); } export function CommandCenterTab({ tasks }: Props) { const [selectedTask, setSelectedTask] = useState(() => tasks[1]?.task_id ?? tasks[0]?.task_id ?? 'task_2'); const [selectedAgent, setSelectedAgent] = useState<'ai_4stage' | 'greedy' | 'random'>('greedy'); // default greedy so it works instantly without key const [result, setResult] = useState(null); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const [heatmapMode, setHeatmapMode] = useState<'type' | 'spread'>('type'); const runSimulation = async () => { setLoading(true); setError(null); try { const r = await simulate(selectedTask, selectedAgent); setResult(r); } catch(e: any) { setError(e.message || String(e)); } finally { setLoading(false); } }; // Math Pipelines const tsData = useMemo(() => { if (!result) return []; return result.steps.map((step, i) => { const obs = step.observation; if (!obs) return { step: i, unattended: 0, supply_gap: 0, severity: 0, logistics: 0 }; const unattended = obs.zones.reduce((sum, z) => sum + z.casualties_remaining, 0); const supplyGap = obs.zones.reduce((sum, z) => sum + z.supply_gap, 0); const maxSeverity = obs.zones.reduce((max, z) => Math.max(max, z.severity), 0) * 100; const logistics = (obs.zones.filter(z => z.sos_active || z.road_blocked).length / Math.max(1, obs.zones.length)) * 100; return { step: i, unattended, supply_gap: supplyGap, severity: maxSeverity, logistics }; }); }, [result]); const contentionData = useMemo(() => { if (!result || result.steps.length < 2) return { zones: [], matrix: [] }; const zonesSet = new Set(); result.steps.forEach(s => s.observation?.zones.forEach(z => zonesSet.add(z.zone_id))); const zones = Array.from(zonesSet).sort(); const matrix = zones.map(z1 => zones.map(z2 => z1 === z2 ? null : 0 as number | null)); for (let i = 1; i < result.steps.length; i++) { const prevObs = result.steps[i-1].observation; const currObs = result.steps[i].observation; if (!prevObs || !currObs) continue; const severityDiff = zones.map(zId => { const pv = prevObs.zones.find(z => z.zone_id === zId)?.severity || 0; const cv = currObs.zones.find(z => z.zone_id === zId)?.severity || 0; return cv - pv; }); zones.forEach((z1, rIdx) => { zones.forEach((z2, cIdx) => { if (rIdx === cIdx) return; if (severityDiff[rIdx] > 0.05 && severityDiff[cIdx] > 0.05) { matrix[rIdx][cIdx]! += 25; } else if (severityDiff[rIdx] > 0 && severityDiff[cIdx] > 0) { matrix[rIdx][cIdx]! += 10; } }); }); } zones.forEach((z1, rIdx) => { zones.forEach((z2, cIdx) => { if (matrix[rIdx][cIdx] !== null) { matrix[rIdx][cIdx] = Math.min(100, matrix[rIdx][cIdx]!); } }); }); return { zones, matrix }; }, [result]); const heatmapData = useMemo(() => { if (!result) return { actions: [], zones: [], matrix: [] }; const zonesSet = new Set(); result.steps.forEach(s => s.observation?.zones.forEach(z => zonesSet.add(z.zone_id))); const zones = Array.from(zonesSet).sort(); const actionTypes = ['deploy_team', 'send_supplies', 'airlift', 'wait']; const matrix = actionTypes.map(() => zones.map(() => 0)); result.steps.forEach(s => { const a = s.action; if (!a) return; const targetZone = a.to_zone || a.from_zone; // some actions only have from_zone or to_zone. const target = targetZone || (a as any).zone // fallback if (!target) return; const actName = actionTypes.find(type => typeof a.action === 'string' && a.action.includes(type)) || a.action; let rIdx = actionTypes.indexOf(actName); if (rIdx === -1) { actionTypes.push(actName); matrix.push(zones.map(() => 0)); rIdx = actionTypes.length - 1; } const cIdx = zones.indexOf(target); if (rIdx >= 0 && cIdx >= 0) { matrix[rIdx][cIdx] += 1; } }); return { actions: actionTypes, zones, matrix }; }, [result]); return (
{/* API Controls */}
{error && (
ERROR STREAM: {error}
)} {/* Dashboard Grids */}
{result && (
)}
); }