import Link from "next/link"; import { requireAdmin } from "@/lib/session"; import { internalApi, InternalApiError } from "@/lib/api"; import { getEnvPresence, getFeatureFlags, getIncidents, getTableCounts } from "@/lib/queries/admin"; import { formatNumber, titleCase } from "@/lib/format"; import { PageHeader } from "@/components/ui/page-header"; import { Alert } from "@/components/ui/alert"; import { Badge, StatusBadge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Table, TableBody, TableCell, TableEmpty, TableHead, TableHeader, TableRow } from "@/components/ui/table"; import { DateCell, KV, Mono, Panel, numCell } from "@/components/admin/primitives"; import { FlagSwitch } from "@/components/admin/flag-controls"; import { NewIncidentDialog, ResolveIncidentButton } from "@/components/admin/incident-controls"; export const dynamic = "force-dynamic"; async function safe(fn: () => Promise): Promise<{ ok: true; value: T } | { ok: false; error: string }> { try { return { ok: true, value: await fn() }; } catch (e) { return { ok: false, error: e instanceof InternalApiError ? `${e.code}: ${e.message}` : (e as Error).message }; } } export default async function AdminSystemPage() { await requireAdmin(); const [health, ready, dbStats, flags, incidents] = await Promise.all([safe(() => internalApi.health()), safe(() => internalApi.ready()), safe(getTableCounts), getFeatureFlags(), getIncidents(50)]); const env = getEnvPresence(); const groups = Array.from(new Set(env.map((e) => e.group))); const openIncidents = incidents.filter((i) => !i.resolvedAt).length; return ( <> } />
{health.ok ? ( }, { label: "Version", value: health.value.version, mono: true }, { label: "Readiness", value: ready.ok ? : }, { label: "Available networks", value: ready.ok && ready.value.available_networks.length ? ready.value.available_networks.join(", ") : "none" }, { label: "Readiness checks", span: true, value: ready.ok ? ( Object.keys(ready.value.checks).length ? (
    {Object.entries(ready.value.checks).map(([k, v]) => (
  • {k}
  • ))}
) : ( no check details (degraded) ) ) : ( {ready.error} ), }, ]} /> ) : ( {health.error} )}
{dbStats.ok ? ( Table Rows {Object.entries(dbStats.value.counts).map(([t, n]) => ( {t} {formatNumber(n)} ))}
) : (
{dbStats.error}
)}
{groups.map((g) => (

{g}

    {env .filter((e) => e.group === g) .map((e) => (
  • {e.key} {e.present ? set : missing}
  • ))}
))}
Manage →} flush> Key Description Targeting Enabled {flags.length === 0 ? ( No flags. Create one. ) : ( flags.map((f) => ( {f.key} {f.description ?? "—"} {f.plans?.length ? `plans: ${f.plans.join(", ")}` : null} {f.plans?.length && f.organizationIds?.length ? " · " : null} {f.organizationIds?.length ? `${f.organizationIds.length} org(s)` : null} {!f.plans?.length && !f.organizationIds?.length ? "everyone" : null} )) )}
Status incidents {openIncidents ? {openIncidents} open : all resolved} } description="Shown on the public /status page. Write for customers; never name upstream providers." flush > Started Component Severity Title Status {incidents.length === 0 ? ( No incidents recorded. The status page shows all systems operational. ) : ( incidents.map((i) => ( {titleCase(i.component)} {i.severity}
{i.title}
{i.body ? (
{i.body}
) : null}
{i.resolvedAt ? ( resolved ) : ( open )}
)) )}
); }