import React from "react"; import { Box, Text } from "ink"; import { HeaderSwr } from "../../tui-components/HeaderSwr.jsx"; import { Sparkline } from "../../tui-components/Sparkline.jsx"; import { StatusBadge } from "../../tui-components/StatusBadge.jsx"; function formatUptime(seconds) { const d = Math.floor(seconds / 86400); const h = Math.floor((seconds % 86400) / 3600); const m = Math.floor((seconds % 3600) / 60); if (d > 0) return `${d}d ${h}h`; if (h > 0) return `${h}h ${m}m`; return `${m}m`; } function OverviewContent({ data }) { const reqs = data?.requests24h ?? 0; const cost = (data?.cost24h ?? 0).toFixed(4); const uptimeSecs = data?.uptimeSeconds ?? 0; const sparkData = data?.requestsSparkline ?? []; return ( Server Uptime {formatUptime(uptimeSecs)} Requests/24h {reqs.toLocaleString()} Cost/24h ${cost} {data?.recentActivity?.length > 0 && ( Recent Activity {data.recentActivity.slice(0, 5).map((r, i) => ( {r.time} {r.status < 400 ? "✓" : "✗"} {r.path} {r.model} {r.duration}ms ))} )} ); } export default function Overview({ baseUrl, apiKey }) { const fetcher = React.useCallback(async () => { const res = await fetch(`${baseUrl}/api/monitoring/health`, { headers: apiKey ? { Authorization: `Bearer ${apiKey}` } : {}, }); return res.ok ? res.json() : null; }, [baseUrl, apiKey]); return ( } /> ); }