import { useCallback, useEffect, useMemo, useState } from 'react';
import AppBar from '@mui/material/AppBar';
import Box from '@mui/material/Box';
import Chip from '@mui/material/Chip';
import Drawer from '@mui/material/Drawer';
import List from '@mui/material/List';
import ListItemButton from '@mui/material/ListItemButton';
import ListItemIcon from '@mui/material/ListItemIcon';
import ListItemText from '@mui/material/ListItemText';
import ListSubheader from '@mui/material/ListSubheader';
import Toolbar from '@mui/material/Toolbar';
import Typography from '@mui/material/Typography';
import {
Gauge,
LayoutDashboard,
Database,
Tag,
Radar,
Pickaxe,
ShieldCheck,
TrendingDown,
Microscope,
Filter,
UserCheck,
Rocket,
Boxes,
ListChecks,
ScrollText,
Workflow,
Map as MapIcon,
AppWindow,
Mountain,
CircuitBoard,
Grid3x3,
GitBranch,
FileCheck2,
AlertTriangle,
Crosshair,
GitCompareArrows,
Library,
Sparkles,
LineChart,
Layers,
Shapes,
Network,
LayoutGrid,
Undo2,
RefreshCcwDot,
Scale,
ClipboardCheck,
BadgeCheck,
TrafficCone,
} from 'lucide-react';
import { LabelEvalContext, type PageId, ALL_PAGE_IDS } from './context/LabelEvalContext';
import { getOverview, useStream } from './services/labeleval';
import OverviewPage from './pages/OverviewPage';
import DatasetsPage from './pages/DatasetsPage';
import LabelGenerationPage from './pages/LabelGenerationPage';
import RareEventDashboard from './pages/RareEventDashboard';
import QualityEnginePage from './pages/QualityEnginePage';
import RegressionPage from './pages/RegressionPage';
import TriagePage from './pages/TriagePage';
import HumanReviewPage from './pages/HumanReviewPage';
import TrainingPage from './pages/TrainingPage';
import ModelsPage from './pages/ModelsPage';
import EvaluationPage from './pages/EvaluationPage';
import AuditPage from './pages/AuditPage';
import PipelineArchitecturePage from './pages/PipelineArchitecturePage';
import SSAMSafetyDashboard from './pages/SSAMSafetyDashboard';
import LegacyStudioPage from './pages/LegacyStudioPage';
import CommandCenterPage from './pages/CommandCenterPage';
import RootCauseLabPage from './pages/rca/RootCauseLabPage';
import RareMinePage from './pages/raremine/RareMinePage';
import HillClimbSection from './pages/hillclimb/HillClimbSection';
import VitisPage from './pages/vitis/VitisPage';
import OddCoveragePage from './pages/safety/OddCoveragePage';
import ReleaseGatesPage from './pages/safety/ReleaseGatesPage';
import EvidencePage from './pages/safety/EvidencePage';
import SsamConflictPage from './pages/safety/SsamConflictPage';
import CalibrationPage from './pages/safety/CalibrationPage';
import DiscrepancyPage from './pages/safety/DiscrepancyPage';
import ScenarioDbPage from './pages/safety/ScenarioDbPage';
import SemanticSearchPage from './pages/safety/SemanticSearchPage';
import SeqevalPage from './pages/engines/SeqevalPage';
import BevFusionPage from './pages/engines/BevFusionPage';
import ScenarioComposerPage from './pages/studio/ScenarioComposerPage';
import PipelineBuilderPage from './pages/studio/PipelineBuilderPage';
import MyDashboardPage from './pages/studio/MyDashboardPage';
import RetroAnalyzerPage from './pages/retro/RetroAnalyzerPage';
import ClosedLoopLabPage from './pages/nextgen/ClosedLoopLabPage';
import LaunchReadinessPage from './pages/agentic/LaunchReadinessPage';
import Studio2GovernancePage from './pages/studio2/Studio2GovernancePage';
import ProductionReadinessPage from './pages/hardening/ProductionReadinessPage';
import RotrControlCenterPage from './pages/rotr/RotrControlCenterPage';
import PageIntro from './components/help/PageIntro';
import HelpMenu from './components/help/HelpMenu';
import HelpChatbot from './components/help/HelpChatbot';
import AboutDialog, { VersionChip } from './components/help/AboutDialog';
const DRAWER_WIDTH = 230;
interface NavItem {
id: PageId;
label: string;
icon: React.ReactNode;
}
const PLATFORM_NAV: NavItem[] = [
{ id: 'command', label: 'Command Center', icon: },
{ id: 'overview', label: 'Overview', icon: },
{ id: 'datasets', label: 'Datasets', icon: },
{ id: 'label-generation', label: 'Label Generation', icon: },
{ id: 'rare-events', label: 'Rare Events', icon: },
{ id: 'raremine', label: 'Rare-Event Miner', icon: },
{ id: 'quality', label: 'Quality Engine', icon: },
{ id: 'regression', label: 'Regression', icon: },
{ id: 'rca', label: 'Root Cause Lab', icon: },
{ id: 'triage', label: 'Triage', icon: },
{ id: 'review', label: 'Human Review', icon: },
{ id: 'training', label: 'Training', icon: },
{ id: 'models', label: 'Models', icon: },
{ id: 'evaluation', label: 'Evaluation', icon: },
{ id: 'audit', label: 'Audit', icon: },
{ id: 'pipeline', label: 'Pipeline Architecture', icon: },
{ id: 'hillclimb', label: 'Hill Climbing EM', icon: },
{ id: 'vitis', label: 'Hardware Acceleration', icon: },
{ id: 'production-readiness', label: 'Production Readiness', icon: },
];
const STUDIO_NAV: NavItem[] = [
{ id: 'my-dashboard', label: 'My Dashboard', icon: },
{ id: 'scenario-composer', label: 'Scenario Composer', icon: },
{ id: 'pipeline-builder', label: 'Pipeline Builder', icon: },
];
const ENGINES_NAV: NavItem[] = [
{ id: 'seqeval', label: 'Sequential Regression', icon: },
{ id: 'bevfusion', label: 'Perception Engines', icon: },
{ id: 'closed-loop-lab', label: 'Closed-Loop Lab', icon: },
];
const SAFETY_NAV: NavItem[] = [
{ id: 'safety-odd', label: 'ODD Coverage', icon: },
{ id: 'safety-gates', label: 'Release Gates', icon: },
{ id: 'safety-evidence', label: 'Evidence Package', icon: },
{ id: 'safety-ssam', label: 'SSAM Conflicts', icon: },
{ id: 'safety-calibration', label: 'Calibration', icon: },
{ id: 'safety-discrepancy', label: 'Discrepancy Mining', icon: },
{ id: 'safety-scenarios', label: 'Scenario DB', icon: },
{ id: 'safety-search', label: 'Semantic Search', icon: },
{ id: 'retro', label: 'Retrospective Analyzer', icon: },
{ id: 'launch-readiness', label: 'Launch Readiness', icon: },
{ id: 'studio2', label: 'Studio 2.0 Governance', icon: },
{ id: 'rotr', label: 'ROTR Control Center', icon: },
];
const LEGACY_NAV: NavItem[] = [
{ id: 'ssam', label: 'SSAM Safety', icon: },
{ id: 'legacy', label: 'Legacy Studio', icon: },
];
const PAGE_TITLES: Record = {
command: 'Evaluation Command Center',
overview: 'Overview',
datasets: 'Datasets',
'label-generation': 'Label Generation',
'rare-events': 'Rare Event Detection',
raremine: 'Rare-Event Miner (Costumed Pedestrians)',
quality: 'Quality Engine',
regression: 'Regression Tracking',
rca: 'Root Cause Lab',
triage: 'Automated Triage',
review: 'Human Review (HITL)',
training: 'Training Flywheel',
models: 'Models',
evaluation: 'Evaluation Records',
audit: 'Audit & Process Units',
pipeline: 'Pipeline Architecture',
hillclimb: 'Hill Climbing EM',
vitis: 'Hardware Acceleration (Vitis Vision)',
ssam: 'SSAM Safety Dashboard',
'safety-odd': 'ODD Coverage',
'safety-gates': 'Release Gates',
'safety-evidence': 'Safety Evidence Package',
'safety-ssam': 'SSAM Conflict Analysis',
'safety-calibration': 'Sensor Calibration Validation',
'safety-discrepancy': 'Discrepancy Mining',
'safety-scenarios': 'Scenario Database',
'safety-search': 'Semantic Scenario Search',
seqeval: 'Sequential Regression Evaluation',
bevfusion: 'Perception Engines (BEV Fusion)',
'scenario-composer': 'Scenario Composer',
'pipeline-builder': 'Pipeline Builder',
'my-dashboard': 'My Dashboard',
retro: 'Retrospective Safety Analyzer',
'closed-loop-lab': 'Closed-Loop Lab',
'launch-readiness': 'Launch Readiness (Agentic Triage)',
studio2: 'Studio 2.0 Governance (Control Plane & Release)',
legacy: 'Legacy Studio',
'production-readiness': 'Production Readiness (Hardening Audit)',
rotr: 'ROTR Control Center (Right-of-the-Road)',
};
function parseHash(): { page: PageId; entityId: string | null } {
const raw = window.location.hash.replace(/^#\/?/, '');
const [pageRaw, entityRaw] = raw.split('/');
const page = (ALL_PAGE_IDS as string[]).includes(pageRaw ?? '') ? (pageRaw as PageId) : 'command';
return { page, entityId: entityRaw ? decodeURIComponent(entityRaw) : null };
}
export default function App() {
const initial = useMemo(parseHash, []);
const [page, setPage] = useState(initial.page);
const [entityId, setEntityId] = useState(initial.entityId);
const [activeDatasetId, setActiveDatasetId] = useState(null);
const [helpChatOpen, setHelpChatOpen] = useState(false);
const [aboutOpen, setAboutOpen] = useState(false);
const stream = useStream();
const navigate = useCallback((nextPage: PageId, nextEntityId?: string | null) => {
setPage(nextPage);
setEntityId(nextEntityId ?? null);
window.location.hash = nextEntityId ? `${nextPage}/${encodeURIComponent(nextEntityId)}` : nextPage;
}, []);
useEffect(() => {
const onHashChange = () => {
const parsed = parseHash();
setPage(parsed.page);
setEntityId(parsed.entityId);
};
window.addEventListener('hashchange', onHashChange);
return () => window.removeEventListener('hashchange', onHashChange);
}, []);
// Adopt the backend's active dataset once on startup so pages have context.
useEffect(() => {
getOverview()
.then((o) => {
if (o.active_dataset) {
setActiveDatasetId((current) => current ?? o.active_dataset);
}
})
.catch(() => undefined);
}, []);
const reviewCount = stream?.pipeline.review_queue_count ?? 0;
const alertsCount = stream?.alerts_count ?? 0;
const badgeFor = (id: PageId): number => {
if (id === 'review') return reviewCount;
if (id === 'overview') return alertsCount;
return 0;
};
const contextValue = useMemo(
() => ({ activeDatasetId, setActiveDatasetId, stream, page, entityId, navigate }),
[activeDatasetId, stream, page, entityId, navigate]
);
const renderNavItem = (item: NavItem) => {
const badge = badgeFor(item.id);
return (
navigate(item.id)}
sx={{
borderRadius: 1,
mx: 0.75,
my: 0.1,
py: 0.6,
'&.Mui-selected': { bgcolor: 'rgba(79,195,247,0.12)', color: '#4fc3f7' },
}}
>
{item.icon}
{badge > 0 ? (
999 ? '999+' : badge.toLocaleString()}
sx={{
height: 18,
fontSize: 10,
fontWeight: 700,
bgcolor: item.id === 'review' ? '#e65100' : '#b71c1c',
color: '#fff',
}}
/>
) : null}
);
};
const fullBleed = page === 'ssam' || page === 'legacy';
return (
t.zIndex.drawer + 1, bgcolor: '#12171d', backgroundImage: 'none' }}>
Sensorflow Studio — L4 Perception Label Evaluation
{stream?.pipeline.running ? (
) : null}
{activeDatasetId ? (
) : null}
setAboutOpen(true)} />
setHelpChatOpen(true)} />
PLATFORM
}
>
{PLATFORM_NAV.map(renderNavItem)}
STUDIO
}
>
{STUDIO_NAV.map(renderNavItem)}
ENGINES & REGRESSION
}
>
{ENGINES_NAV.map(renderNavItem)}
SAFETY & COMPLIANCE
}
>
{SAFETY_NAV.map(renderNavItem)}
LEGACY / EXISTING
}
>
{LEGACY_NAV.map(renderNavItem)}
setAboutOpen(true)} />
{fullBleed ? (
{PAGE_TITLES[page]}
{page === 'ssam' ? : }
) : (
{PAGE_TITLES[page]}
{page === 'command' ? : null}
{page === 'overview' ? : null}
{page === 'datasets' ? : null}
{page === 'label-generation' ? : null}
{page === 'rare-events' ? : null}
{page === 'raremine' ? : null}
{page === 'quality' ? : null}
{page === 'regression' ? : null}
{page === 'rca' ? : null}
{page === 'triage' ? : null}
{page === 'review' ? : null}
{page === 'training' ? : null}
{page === 'models' ? : null}
{page === 'evaluation' ? : null}
{page === 'audit' ? : null}
{page === 'pipeline' ? : null}
{page === 'hillclimb' ? : null}
{page === 'vitis' ? : null}
{page === 'safety-odd' ? : null}
{page === 'safety-gates' ? : null}
{page === 'safety-evidence' ? : null}
{page === 'safety-ssam' ? : null}
{page === 'safety-calibration' ? : null}
{page === 'safety-discrepancy' ? : null}
{page === 'safety-scenarios' ? : null}
{page === 'safety-search' ? : null}
{page === 'seqeval' ? : null}
{page === 'bevfusion' ? : null}
{page === 'scenario-composer' ? : null}
{page === 'pipeline-builder' ? : null}
{page === 'my-dashboard' ? : null}
{page === 'retro' ? : null}
{page === 'closed-loop-lab' ? : null}
{page === 'launch-readiness' ? : null}
{page === 'studio2' ? : null}
{page === 'production-readiness' ? : null}
{page === 'rotr' ? : null}
)}
setAboutOpen(false)} />
);
}