"use client";
import clsx from "clsx";
import { BarChart3, Compass, FileStack, GitBranch, GitCompareArrows, History, LayoutDashboard, ListChecks, Menu,
MessageSquare, RotateCcw, ScrollText, Search, X } from "lucide-react";
import Link from "next/link";
import { usePathname, useRouter } from "next/navigation";
import { useEffect, useRef, useState } from "react";
import { api, getSession, resetSession } from "@/lib/api";
import { Button, DocProvider, type TileTone } from "./ui";
import SignIn from "./SignIn";
type NavItem = { href: string; label: string; icon: typeof LayoutDashboard };
const NAV: { label: string | null; items: NavItem[] }[] = [
{ label: "Operate", items: [
{ href: "/", label: "Control room", icon: LayoutDashboard },
{ href: "/impact/", label: "Change impact", icon: GitCompareArrows },
{ href: "/qualify/", label: "Tenders", icon: ScrollText },
{ href: "/live/", label: "Live documents", icon: FileStack },
{ href: "/decisions/", label: "Decisions", icon: GitBranch },
{ href: "/actions/", label: "Actions", icon: ListChecks },
] },
{ label: "Knowledge", items: [
{ href: "/memory/", label: "Memory", icon: History },
{ href: "/ask/", label: "Ask", icon: MessageSquare },
{ href: "/explore/", label: "Explore", icon: Compass },
] },
{ label: "Evaluate", items: [
{ href: "/benchmark/", label: "Benchmark", icon: BarChart3 },
] },
];
type Health = { ok?: boolean; llm?: string[]; replay?: boolean; tools?: number } | null;
function Wordmark() {
return (
B
BidBrain
on FalkorDB
);
}
function NavList({ isActive, onNavigate }: { isActive: (href: string) => boolean; onNavigate?: () => void }) {
return (
);
}
function StatusBlock({ health, sid }: { health: Health; sid: string }) {
const model = health?.llm?.length ? String(health.llm[0]).split(":").slice(1).join(":").replace(/^.*\//, "") : null;
const db = health === null ? "checking" : health.ok ? "online" : "offline";
return (
FalkorDB {db}
LLM
{model || (health?.replay ? "recorded answers" : health ? "none" : "checking")}
Your graph
{sid ? `session_${sid.replace(/^session_/, "")}` : "connecting…"}
);
}
export default function Shell({ children }: { children: React.ReactNode }) {
const path = usePathname();
const router = useRouter();
const [sid, setSid] = useState("");
const [health, setHealth] = useState(null);
const [q, setQ] = useState("");
const [drawer, setDrawer] = useState(false);
const [resetting, setResetting] = useState(false);
const drawerRef = useRef(null);
const menuBtn = useRef(null);
useEffect(() => {
getSession().then(setSid).catch(() => {});
const check = () => api("/api/health").then(setHealth).catch(() => setHealth({ ok: false }));
check();
const t = setInterval(check, 60_000);
return () => clearInterval(t);
}, []);
// the drawer closes on navigation and on Escape, and returns focus to the menu button
// eslint-disable-next-line react-hooks/set-state-in-effect -- route change is an external event
useEffect(() => { setDrawer(false); }, [path]);
useEffect(() => {
if (!drawer) return;
const btn = menuBtn.current;
drawerRef.current?.querySelector("a, button, input")?.focus();
const onKey = (e: KeyboardEvent) => e.key === "Escape" && setDrawer(false);
window.addEventListener("keydown", onKey);
const overflow = document.body.style.overflow;
document.body.style.overflow = "hidden";
return () => { window.removeEventListener("keydown", onKey); document.body.style.overflow = overflow; btn?.focus(); };
}, [drawer]);
const isActive = (href: string) => (href === "/" ? path === "/" : !!path?.startsWith(href.replace(/\/$/, "")));
async function reset() {
setResetting(true);
try { setSid(await resetSession()); location.reload(); } catch { setResetting(false); }
}
const search = (
);
return (
Skip to content
{/* desktop sidebar */}
{/* mobile drawer */}
{drawer && (
setDrawer(false)} aria-hidden />
{search}
setDrawer(false)} />
)}
);
}
/** Page title row. `icon`/`tone`/`eyebrow` are accepted for compatibility and not drawn (titles carry no icons). */
export function PageHeader({ title, subtitle, meta, actions, children }:
{ title: string; subtitle?: React.ReactNode; meta?: React.ReactNode; actions?: React.ReactNode; children?: React.ReactNode;
eyebrow?: string; icon?: React.ReactNode; tone?: TileTone }) {
return (
{title}
{(subtitle || children) &&
{subtitle || children}
}
{meta &&
{meta}
}
{actions &&
{actions}
}
);
}