import { requireAdmin } from "@/lib/session"; import { internalApi, InternalApiError } from "@/lib/api"; import { getProviderConfigs, getProviderHealthHistory, getProviderStats, rangeStart } from "@/lib/queries/admin"; import { formatBytes, formatMs, formatNumber, formatPercent, formatUsd } from "@/lib/format"; import { PageHeader } from "@/components/ui/page-header"; import { Alert } from "@/components/ui/alert"; import { Badge, StatusBadge } from "@/components/ui/badge"; import { Stat, StatGrid } from "@/components/ui/stat"; import { Table, TableBody, TableCell, TableEmpty, TableHead, TableHeader, TableRow } from "@/components/ui/table"; import { DateCell, NetworkBadge, Panel, ProviderBadge, numCell } from "@/components/admin/primitives"; import { CircuitList, ProbeButton, ProviderConfigForm, ResetAllCircuitsButton } from "@/components/admin/provider-panel"; export const dynamic = "force-dynamic"; type ProvidersPayload = Awaited>; export default async function AdminProvidersPage() { await requireAdmin(); let live: ProvidersPayload | null = null; let apiError: string | null = null; try { live = await internalApi.providers(); } catch (e) { apiError = e instanceof InternalApiError ? `${e.code}: ${e.message}` : (e as Error).message; } const [configs, stats, history] = await Promise.all([getProviderConfigs(), getProviderStats(rangeStart("24h")), getProviderHealthHistory(50)]); const configById = new Map(configs.map((c) => [c.id, c])); const statById = new Map(stats.map((s) => [s.provider, s])); // Providers known to the API, plus any config rows the API does not report (e.g. disabled ones). const providerIds = Array.from(new Set([...(live?.providers.map((p) => p.id) ?? []), ...configs.map((c) => c.id)])); return ( <> } /> {apiError ? ( Live provider status could not be loaded ({apiError}). Configuration and database statistics are still shown; saving a config will retry the reload. ) : (

Available networks right now: {live!.available_networks.length ? live!.available_networks.map((n) => ) : none}

)}
{providerIds.length === 0 ? No providers registered. : null} {providerIds.map((id) => { const p = live?.providers.find((x) => x.id === id) ?? null; const cfg = configById.get(id) ?? null; const st = statById.get(id) ?? null; const label = cfg?.label ?? p?.label ?? id; const enabled = cfg?.enabled ?? true; return ( {label} {p ? p.configured ? configured : credentials missing : not reported by API} {enabled ? enabled : disabled} } description={p ? `Networks: ${p.networks.join(", ") || "none"}` : cfg ? `Networks (config): ${cfg.networks.join(", ")}` : undefined} bodyClassName="p-0" >
{formatUsd(st?.costPerSuccess ?? null, true)}} hint="key metric" />

Configuration

Latest health per network

{p?.health.length ? (
    {p.health.map((h) => (
  • {formatMs(h.latency_ms)} {h.detail ? ( {h.detail} ) : null}
  • ))}
) : (

No health check in the last 24 hours. Run a probe.

)}

Circuit breakers

); })}
Checked Provider Network Status Latency Success rate Detail {history.length === 0 ? ( No probes recorded yet. ) : ( history.map((h) => ( {formatMs(h.latencyMs)} {h.successRate !== null ? formatPercent(h.successRate * (h.successRate <= 1 ? 100 : 1)) : "—"} {h.detail ?? "—"} )) )}
); }