import React, { Suspense } from 'react'; import { ErrorBoundary } from './components/ErrorBoundary'; import { Routes, Route, Navigate } from 'react-router-dom'; import { Layout } from './components/Layout'; import { PageSkeleton } from './components/PageSkeleton'; import { useFeatures } from './hooks/useFeatures'; import { AuthProvider, useAuth } from './context/AuthContext'; import { Login } from './pages/Login'; // Lazy-loaded page components (named exports) const Overview = React.lazy(() => import('./pages/Overview').then(m => ({ default: m.Overview }))); const Sessions = React.lazy(() => import('./pages/Sessions').then(m => ({ default: m.Sessions }))); const Agents = React.lazy(() => import('./pages/Agents').then(m => ({ default: m.Agents }))); const SessionDetailPage = React.lazy(() => import('./pages/SessionDetail').then(m => ({ default: m.SessionDetail }))); const EventsExplorer = React.lazy(() => import('./pages/EventsExplorer').then(m => ({ default: m.EventsExplorer }))); const Analytics = React.lazy(() => import('./pages/Analytics').then(m => ({ default: m.Analytics }))); const Alerts = React.lazy(() => import('./pages/Alerts').then(m => ({ default: m.Alerts }))); const LlmAnalytics = React.lazy(() => import('./pages/LlmAnalytics').then(m => ({ default: m.LlmAnalytics }))); const Knowledge = React.lazy(() => import('./pages/Knowledge').then(m => ({ default: m.Knowledge }))); const MemoryProvenance = React.lazy(() => import('./pages/MemoryProvenance').then(m => ({ default: m.MemoryProvenance }))); const Search = React.lazy(() => import('./pages/Search').then(m => ({ default: m.Search }))); const Insights = React.lazy(() => import('./pages/Insights').then(m => ({ default: m.Insights }))); const HealthOverview = React.lazy(() => import('./pages/HealthOverview').then(m => ({ default: m.HealthOverview }))); const CostOptimization = React.lazy(() => import('./pages/CostOptimization').then(m => ({ default: m.CostOptimization }))); const SessionReplay = React.lazy(() => import('./pages/SessionReplay').then(m => ({ default: m.SessionReplay }))); const Benchmarks = React.lazy(() => import('./pages/Benchmarks').then(m => ({ default: m.Benchmarks }))); const BenchmarkNew = React.lazy(() => import('./pages/BenchmarkNew').then(m => ({ default: m.BenchmarkNew }))); const BenchmarkDetail = React.lazy(() => import('./pages/BenchmarkDetail').then(m => ({ default: m.BenchmarkDetail }))); // Lazy-loaded page components (default exports) const Settings = React.lazy(() => import('./pages/Settings')); const Guardrails = React.lazy(() => import('./pages/Guardrails')); const GuardrailList = React.lazy(() => import('./pages/GuardrailList')); const GuardrailForm = React.lazy(() => import('./pages/GuardrailForm')); const GuardrailDetail = React.lazy(() => import('./pages/GuardrailDetail')); const GuardrailActivity = React.lazy(() => import('./pages/GuardrailActivity')); const AgentNetwork = React.lazy(() => import('./pages/AgentNetwork')); const CapabilityRegistry = React.lazy(() => import('./pages/CapabilityRegistry')); const DelegationLog = React.lazy(() => import('./pages/DelegationLog')); const Prompts = React.lazy(() => import('./pages/Prompts').then(m => ({ default: m.Prompts }))); const PromptDetail = React.lazy(() => import('./pages/PromptDetail').then(m => ({ default: m.PromptDetail }))); const EvalDatasets = React.lazy(() => import('./pages/eval/datasets').then(m => ({ default: m.EvalDatasets }))); const EvalDatasetDetail = React.lazy(() => import('./pages/eval/dataset-detail').then(m => ({ default: m.EvalDatasetDetail }))); const Evaluators = React.lazy(() => import('./pages/eval/evaluators').then(m => ({ default: m.Evaluators }))); const Compliance = React.lazy(() => import('./pages/Compliance')); const BudgetConfig = React.lazy(() => import('./pages/BudgetConfig')); const AgentInsights = React.lazy(() => import('./pages/AgentInsights')); const AnnotationQueues = React.lazy(() => import('./pages/AnnotationQueues').then(m => ({ default: m.AnnotationQueues }))); const AnnotationReview = React.lazy(() => import('./pages/AnnotationReview').then(m => ({ default: m.AnnotationReview }))); const Playground = React.lazy(() => import('./pages/Playground').then(m => ({ default: m.Playground }))); const Users = React.lazy(() => import('./pages/Users').then(m => ({ default: m.Users }))); // Lazy-loaded cloud components (named exports) const TeamManagement = React.lazy(() => import('./cloud/TeamManagement').then(m => ({ default: m.TeamManagement }))); const ApiKeyManagement = React.lazy(() => import('./cloud/ApiKeyManagement').then(m => ({ default: m.ApiKeyManagement }))); const UsageDashboard = React.lazy(() => import('./cloud/UsageDashboard').then(m => ({ default: m.UsageDashboard }))); const RequireAuth = React.memo(function RequireAuth({ children }: { children: React.ReactElement }): React.ReactElement { const { user, loading, authMode } = useAuth(); if (loading) { return (
); } // When SSO is not enabled, skip auth guard if (authMode === 'api-key-only') return children; if (!user) return ; return children; }); export function App(): React.ReactElement { return ( ); } function AppRoutes(): React.ReactElement { const { lore } = useFeatures(); return ( } /> }> }>} /> }>} /> }>} /> }>} /> }>} /> }>} /> }>} /> }>} /> }>} /> }>} /> }>} /> }>} /> }>} /> }>} /> {lore && }>} />} {lore && }>} />} } /> } /> } /> }>} /> }>} /> }>} /> }>} /> }>} /> }>} /> }>} /> }>} /> } /> } /> } /> }>} /> }>} /> }>} /> }>} /> }>} /> }>} /> }>} /> }>} /> }>} /> }>} /> }>} /> }>} /> }>} /> }>} /> }>} /> }>} /> {/* Unknown in-app path → Overview, instead of a blank white screen. */} } /> ); } const LoginGuard = React.memo(function LoginGuard(): React.ReactElement { const { user, loading, authMode } = useAuth(); if (loading) { return (
); } // Already authenticated or SSO not enabled → go to dashboard if (user || authMode === 'api-key-only') return ; return ; });