"use client"; import { useTranslations } from "next-intl"; import { useState, useEffect } from "react"; import { Card } from "@/shared/components"; export default function BudgetTelemetryCards() { const t = useTranslations("usage"); const [telemetry, setTelemetry] = useState(null); const [cache, setCache] = useState(null); const [policies, setPolicies] = useState(null); useEffect(() => { Promise.allSettled([ fetch("/api/telemetry/summary").then((r) => r.json()), fetch("/api/cache/stats").then((r) => r.json()), fetch("/api/policies").then((r) => r.json()), ]).then(([t, c, p]) => { if (t.status === "fulfilled") setTelemetry(t.value); if (c.status === "fulfilled") setCache(c.value); if (p.status === "fulfilled") setPolicies(p.value); }); }, []); const fmt = (ms) => (ms != null ? `${Math.round(ms)}ms` : "—"); return (
{/* Latency Card */}

speed {t("latency")}

{telemetry ? (
{t("latencyP50")} {fmt(telemetry.p50)}
{t("latencyP95")} {fmt(telemetry.p95)}
{t("latencyP99")} {fmt(telemetry.p99)}
{t("totalRequests")} {telemetry.totalRequests ?? 0}
{t("activeSessions")} {telemetry.sessions?.activeCount ?? 0}
{t("quotaAlerts")} {telemetry.quotaMonitor?.alerting ?? 0}
) : (

{t("noDataYet")}

)}
{/* Cache Card */}

cached {t("promptCache")}

{cache ? (
{t("entries")} {cache.size}/{cache.maxSize}
{t("hitRate")} {cache.hitRate?.toFixed(1) ?? 0}%
{t("hitsMisses")} {cache.hits ?? 0} / {cache.misses ?? 0}
) : (

{t("noDataYet")}

)}
{/* System Health Card */}

monitor_heart {t("systemHealth")}

{policies ? (
{t("circuitBreakers")} {t("activeCount", { count: policies.circuitBreakers?.length ?? 0 })}
{t("lockedIPs")} {policies.lockedIdentifiers?.length ?? 0}
{policies.circuitBreakers?.some((cb) => cb.state === "OPEN") && (
{t("openCircuitBreakersDetected")}
)}
) : (

{t("noDataYet")}

)}
); }