import { lazy, Suspense, useState } from "react";
import {
Activity,
ChevronLeft,
Compass,
Database,
FlaskConical,
GitCompare,
LayoutDashboard,
ListChecks,
Loader2,
Maximize2,
PanelRightClose,
PanelRightOpen,
Sliders,
Stethoscope,
X,
} from "lucide-react";
import { useShallow } from "zustand/react/shallow";
import {
useOstraStore,
type Page,
type XRayTab,
} from "../../store/useOstraStore";
import type { DiagnosticLens } from "../../types/ostra";
import { DocInspectorDrawer } from "../atlas/DocInspectorDrawer";
import { HelpInfo } from "../common/HelpInfo";
import { OverviewPage } from "../overview/OverviewPage";
import { DiagnosisAndResultsView } from "../xray/DiagnosisAndResultsView";
import { QueryBarAnatomy } from "../xray/QueryBarAnatomy";
import { CorpusHealthBar } from "./CorpusHealthBar";
// Code-split heavy views (especially Deck.gl WebGL Atlas, Labs, Compare, and Modals)
// so initial HTML + Query Bar + results paint immediately without blocking the main thread.
const AtlasPage = lazy(() =>
import("../atlas/AtlasPage").then((m) => ({ default: m.AtlasPage }))
);
const EmbeddingAtlasCanvas = lazy(() =>
import("../atlas/EmbeddingAtlasCanvas").then((m) => ({
default: m.EmbeddingAtlasCanvas,
}))
);
const CompareRunsPage = lazy(() =>
import("../compare/CompareRunsPage").then((m) => ({
default: m.CompareRunsPage,
}))
);
const LabsPage = lazy(() =>
import("../suite/LabsPage").then((m) => ({ default: m.LabsPage }))
);
const SampleSuitePanel = lazy(() =>
import("../suite/SampleSuitePanel").then((m) => ({
default: m.SampleSuitePanel,
}))
);
const ForensicDiffPanel = lazy(() =>
import("../xray/ForensicDiffPanel").then((m) => ({
default: m.ForensicDiffPanel,
}))
);
const QuadrantAndCliffView = lazy(() =>
import("../xray/QuadrantAndCliffView").then((m) => ({
default: m.QuadrantAndCliffView,
}))
);
const HybridMixingBoard = lazy(() =>
import("../tuners/HybridMixingBoard").then((m) => ({
default: m.HybridMixingBoard,
}))
);
const DatasetWizardModal = lazy(() =>
import("../ingest/DatasetWizardModal").then((m) => ({
default: m.DatasetWizardModal,
}))
);
const ExportRecipeModal = lazy(() =>
import("../suite/ExportRecipeModal").then((m) => ({
default: m.ExportRecipeModal,
}))
);
function LazyViewFallback({ label = "Loading view…" }: { label?: string }) {
return (
{label}
);
}
const XRAY_TABS: { id: XRayTab; label: string; icon: React.ReactNode }[] = [
{
id: "diagnosis",
label: "Diagnosis & Results",
icon: ,
},
{
id: "forensic",
label: "Forensic Diff (A vs B)",
icon: ,
},
{
id: "cliff",
label: "Confidence & Abstention",
icon: ,
},
];
const SPLIT_MAP_LENSES: { id: DiagnosticLens; label: string }[] = [
{ id: "clusters", label: "Clusters" },
{ id: "hubness", label: "Hubs" },
{ id: "antihubs", label: "Hidden" },
{ id: "truncation", label: "Cut-Off" },
{ id: "purity", label: "Purity" },
];
const NAV_ITEMS: {
id: Page;
label: string;
subtitle: string;
icon: React.ReactNode;
}[] = [
{
id: "debug",
label: "Debug & Map",
subtitle: "Live X-ray + 2D Atlas",
icon: ,
},
{
id: "overview",
label: "Overview",
subtitle: "Health & next step",
icon: ,
},
{
id: "suite",
label: "Eval Suite",
subtitle: "Questions, triage & gate",
icon: ,
},
{
id: "optimize",
label: "Optimize",
subtitle: "Verified fix labs",
icon: ,
},
{
id: "atlas",
label: "Full Atlas",
subtitle: "2D map & facets",
icon: ,
},
{
id: "compare",
label: "Compare",
subtitle: "Model & run bakeoff",
icon: ,
},
];
export function WorkbenchShell() {
const {
activeRun,
runs,
loadingRun,
page,
lab,
xrayTab,
sidebarCollapsed,
setSidebarCollapsed,
mixingDrawerOpen,
setMixingDrawerOpen,
openOverview,
setXRayTab,
openSuite,
openLab,
openAtlas,
openCompare,
setWizardOpen,
wizardOpen,
exportModalOpen,
activeLens,
setActiveLens,
atlasBinary,
loadingAtlas,
suiteItems,
baselineCheck,
facets,
} = useOstraStore(
useShallow((s) => ({
activeRun: s.activeRun,
runs: s.runs,
loadingRun: s.loadingRun,
page: s.page,
lab: s.lab,
xrayTab: s.xrayTab,
sidebarCollapsed: s.sidebarCollapsed,
setSidebarCollapsed: s.setSidebarCollapsed,
mixingDrawerOpen: s.mixingDrawerOpen,
setMixingDrawerOpen: s.setMixingDrawerOpen,
openOverview: s.openOverview,
setXRayTab: s.setXRayTab,
openSuite: s.openSuite,
openLab: s.openLab,
openAtlas: s.openAtlas,
openCompare: s.openCompare,
setWizardOpen: s.setWizardOpen,
wizardOpen: s.wizardOpen,
exportModalOpen: s.exportModalOpen,
activeLens: s.activeLens,
setActiveLens: s.setActiveLens,
atlasBinary: s.atlasBinary,
loadingAtlas: s.loadingAtlas,
suiteItems: s.suiteItems,
baselineCheck: s.baselineCheck,
facets: s.facets,
}))
);
const [splitMapVisible, setSplitMapVisible] = useState(true);
const navigate = (target: Page) => {
if (target === "overview") openOverview();
else if (target === "debug") setXRayTab(xrayTab);
else if (target === "suite") openSuite();
else if (target === "optimize") openLab(lab);
else if (target === "atlas") openAtlas();
else openCompare();
};
return (
{loadingRun ? (
Loading binary Atlas & sparse BM25 index…
) : !activeRun ? (
Ostra Workbench
Visual Debugger for Embedding & Hybrid Search
Select any public Hugging Face text dataset & embedding model,
diagnose why vector or hybrid search fails, optimize fusion and
reranking against an eval suite, and export verified configs.
setWizardOpen(true)}
className="paper-btn-ink px-4 py-2 text-xs font-semibold cursor-pointer inline-flex items-center gap-1.5"
>
Select Hugging Face Dataset →
) : (
{/* Primary Collapsible Left Navigation Sidebar (fully collapses to reclaim 100% width) */}
{!sidebarCollapsed && (
{NAV_ITEMS.map((item) => {
const active = page === item.id;
const badge =
item.id === "suite" && suiteItems.length > 0
? {
text: String(suiteItems.length),
tone:
baselineCheck?.verdict === "FAIL_REGRESSION"
? "bg-red-600 text-white"
: "bg-[#0f172a] text-white",
}
: item.id === "atlas" && facets?.selection_active
? {
text: String(facets.filtered_count),
tone: "bg-sky-600 text-white",
}
: item.id === "compare" && runs.length >= 2
? {
text: String(runs.length),
tone: "bg-[#e8edf3] text-[#0f172a] border border-[#0f172a]",
}
: null;
return (
navigate(item.id)}
className={`relative flex items-center justify-between px-2.5 py-2 border-[1.5px] cursor-pointer transition-colors text-left ${
active
? "bg-white border-[#0f172a] text-[#0f172a] shadow-[2px_2px_0_rgba(15,23,42,0.18)]"
: "border-transparent text-[#475569] hover:bg-white/80 hover:border-[#94a3b8] hover:text-[#0f172a]"
}`}
>
{item.icon}
{item.label}
{item.subtitle}
{badge && (
{badge.text}
)}
);
})}
setSidebarCollapsed(true)}
title="Collapse navigation sidebar"
className="w-full py-1 px-2 bg-white hover:bg-[#e8edf3] border border-[#94a3b8] hover:border-[#0f172a] text-[#475569] hover:text-[#0f172a] font-mono text-[10px] inline-flex items-center justify-center gap-1 cursor-pointer"
>
Collapse Sidebar
)}
{/* Main Full-Width Page Canvas */}
{page === "overview" && }
{page === "debug" && (
{/* X-Ray View Tabs (Clean 3-tab Folder Strip) */}
{XRAY_TABS.map((t) => (
setXRayTab(t.id)}
className={`inline-flex items-center gap-1.5 px-2.5 py-1.5 font-mono text-[11px] whitespace-nowrap shrink-0 transition-colors cursor-pointer border-[1.5px] -mb-[1.5px] ${
xrayTab === t.id
? "bg-[#f7f8fa] text-[#0f172a] border-[#0f172a] border-b-[#f7f8fa] font-semibold"
: "bg-[#e8edf3] text-[#475569] border-[#94a3b8] border-b-[#0f172a] hover:text-[#0f172a] hover:bg-white/70"
}`}
>
{t.icon}
{t.label}
))}
setSplitMapVisible((v) => !v)}
className={`h-6 px-2 text-[10px] font-mono font-semibold whitespace-nowrap inline-flex items-center gap-1 border cursor-pointer transition-colors ${
splitMapVisible
? "bg-[#0f172a] text-white border-[#0f172a]"
: "bg-white text-[#0f172a] border-[#0f172a] hover:bg-sky-50"
}`}
title={
splitMapVisible
? "Hide live 2D Map split pane"
: "Show live 2D Map alongside Debug results"
}
>
{splitMapVisible ? (
<>
Hide 2D Map
>
) : (
<>
Show 2D Map
>
)}
openAtlas(activeLens)}
className="paper-btn h-6 px-2 text-[10px] font-semibold whitespace-nowrap inline-flex items-center gap-1 cursor-pointer"
title="Expand 2D Corpus Atlas with full Facets & Cross-Filter sidebar"
>
Full Map & Facets
{/* Immersive Split Home Workspace: Debug X-Ray (Left 60%) + Live 2D Corpus Map (Right 40% of screen) */}
{xrayTab === "diagnosis" && }
{xrayTab === "forensic" && (
}>
)}
{xrayTab === "cliff" && (
}>
)}
{splitMapVisible && (
2D Map
{SPLIT_MAP_LENSES.map((l) => (
setActiveLens(l.id)}
className={`px-1.5 py-0.5 font-mono text-[10px] whitespace-nowrap border cursor-pointer transition-colors ${
activeLens === l.id
? "bg-[#0f172a] text-white border-[#0f172a] font-semibold"
: "bg-white text-[#475569] border-[#cbd5e1] hover:border-[#0f172a] hover:text-[#0f172a]"
}`}
>
{l.label}
))}
{loadingAtlas && !atlasBinary ? (
) : (
}>
)}
)}
)}
{page === "suite" && (
}>
)}
{page === "optimize" && (
}>
)}
{page === "atlas" && (
}>
)}
{page === "compare" && (
}>
)}
{/* Optional On-Demand Right Drawer: Live Engine Controls (collapsed by default!) */}
{mixingDrawerOpen && (
Engine Controls
setMixingDrawerOpen(false)}
title="Close Engine Controls drawer"
className="p-1 bg-white hover:bg-[#e8edf3] border border-[#0f172a] text-[#0f172a] cursor-pointer"
>
}>
)}
)}
{/* Modals (mounted strictly on demand) */}
{wizardOpen && (
)}
{exportModalOpen && (
)}
);
}