// Modules — LiteLLM budget viewer, model intelligence ranking, EC2 budget, shortcuts, activity. const { MoneyBig, Bar, Pill, Panel, Sparkline, BarsDaily, StatusDot, fmtInt, fmtMoney } = window.SEIS_PRIM; function DataLoading() { return
LOADING...
; } // ── §02 LITELLM BUDGETS ──────────────────────────────────────── function fmtTokens(n) { if (n >= 1_000_000) return (n / 1_000_000).toFixed(1) + "M"; if (n >= 1_000) return (n / 1_000).toFixed(1) + "K"; return n.toString(); } function ProviderBudget({ b, models }) { const tone = b.mode === "unlimited" ? "default" : (b.used / b.monthly) > 0.85 ? "danger" : (b.used / b.monthly) > 0.65 ? "warn" : "default"; const pct = b.monthly ? (b.used / b.monthly) * 100 : 0; const myModels = models.filter(m => m.bucket === b.id).sort((a, b) => b.spent - a.spent); const top = myModels[0]; return (
{b.label} {b.sub}
{b.mode === "unlimited" ? ( <> ${b.used.toFixed(4)} {b.rateLimited ? "● RATE LIMITED" : `UNLIMITED · ${(b.rateLimit || {}).currentRpm || 0}/${(b.rateLimit || {}).rpm || 240} RPM`} ) : ( <> ${b.used.toFixed(4)} / ${b.monthly.toFixed(0)} {pct.toFixed(0)}% )}
{b.mode === "unlimited" ? ( ) : ( )}
{myModels.length > 0 && ( <>
BY MODEL · SORTED BY SPEND
{myModels.map(m => { const tokens = (m.tokensIn || 0) + (m.tokensOut || 0); const share = b.mode === "unlimited" ? 0 : (m.spent / b.monthly) * 100; const topSpent = top ? top.spent : 1; return (
{m.name} {tokens > 0 && ( {fmtTokens(tokens)} TOK · {fmtTokens(m.tokensIn || 0)} IN · {fmtTokens(m.tokensOut || 0)} OUT )} ${m.spent.toFixed(4)} {b.mode !== "unlimited" && ( {share.toFixed(1)}% )}
); })}
)}
); } function LiteLLMBudget({ budgets, models, loading }) { const totalCapped = (budgets || []).filter(b => b.mode === "capped").reduce((s, b) => s + (b.monthly || 0), 0); const totalUsed = (budgets || []).reduce((s, b) => s + (b.used || 0), 0); return ( {loading && !budgets.length ? : ( <>
CAPPED TOTAL · THIS MONTH
{(budgets || []).length} PROVIDERS
+ OPEN-SOURCE TIER (UNLIMITED · RATE-LIMITED)
{(budgets || []).map(b => )}
* OPEN-SOURCE TIER IS UNLIMITED UNTIL RATE-LIMITED FOR HEAVY USE.
SESSION-MODE MODELS BILL TO SUBSCRIPTIONS — SEE §02 MODELS.
)}
); } // ── §03 MODEL INTELLIGENCE RANKING ───────────────────────────── function ModelRanking({ models, loading }) { const sorted = [...(models || [])].sort((a, b) => (b.iq || 0) - (a.iq || 0)); return ( {loading && !models.length ? : ( <> {sorted.map((m, i) => ( ))} {sorted.length === 0 && ( )}
# MODEL VENDOR SPEND MODE CALLS P95
{String(i + 1).padStart(2, "0")} {m.name} {m.vendor} ${(m.spent || 0).toFixed(4)} {(m.mode || "metered").toUpperCase()} {m.calls ? fmtInt(m.calls) : "—"} {m.p95 ? `${m.p95.toFixed(2)}s` : "—"}
NO MODEL DATA
)}
); } // ── §04 EC2 BUDGET METER ─────────────────────────────────────── function EC2Budget({ budget, loading, onLaunch }) { const monthly = budget?.monthly || 600; const used = budget?.used || 0; const daysLeft = budget?.daysLeft || 0; const free = monthly - used; const pct = (used / monthly) * 100; const tone = pct > 85 ? "danger" : pct > 65 ? "warn" : "default"; const noKey = budget?.error === "EC2_CREDENTIALS_NOT_CONFIGURED"; return (
USED · THIS MONTH
{loading && !budget ? : ( <>
{pct.toFixed(1)}% CONSUMED FREE ${free.toFixed(4)} {daysLeft}D LEFT
{noKey && (
⚠ SET EC2_AWS_ACCESS_KEY_ID IN .ENV TO ENABLE
)} )}
); } // ── ACTIVE SERVERS ───────────────────────────────────────────── function ActiveServers({ instances, loading, onOpenInstance, hasSshKey }) { const [terminating, setTerminating] = React.useState(null); const doTerminate = async (ident) => { if (!window.confirm(`Terminate ${ident}? This cannot be undone.`)) return; setTerminating(ident); try { const r = await fetch(`/api/ec2/terminate/${ident}`, { method: "POST", credentials: "include" }); if (!r.ok) { const b = await r.json().catch(() => ({})); alert(b.detail || "Terminate failed"); } } catch { alert("Network error"); } finally { setTerminating(null); } }; return ( {loading && !instances.length ? : instances.length === 0 ? (
NO RUNNING INSTANCES
) : ( {instances.map(s => ( ))}
NAME INSTANCE OWNER UPTIME SPENT STATUS
{s.name}
{s.id}
{s.instance} @{s.userHandle || s.user} {s.uptime} ${(s.cost || 0).toFixed(4)} {s.status.toUpperCase()}
)}
); } // ── EC2 LAUNCH HISTORY ───────────────────────────────────────── function EC2History({ history, loading }) { const rows = history || []; const totalActual = rows.reduce((s, r) => s + (r.costActual || 0), 0); const totalEst = rows.reduce((s, r) => s + (r.costEstimated || 0), 0); const running = rows.filter(r => r.status === "running").length; const [page, setPage] = React.useState(0); const perPage = 5; const totalPages = Math.ceil(rows.length / perPage); const showRows = rows.slice(page * perPage, (page + 1) * perPage); React.useEffect(() => { if (page >= totalPages && totalPages > 0) setPage(totalPages - 1); }, [rows.length]); const statusColor = s => s === "running" ? "var(--accent)" : s === "failed" ? "var(--accent)" : "var(--muted)"; return ( {loading && !rows.length ? : ( <>
TOTAL SPENT (ACTUAL)
${totalActual.toFixed(4)}
TOTAL ESTIMATED
${totalEst.toFixed(4)}
LAUNCHES
{rows.length}
{running > 0 && (
RUNNING NOW
{running}
)}
{showRows.length === 0 ? (
NO LAUNCHES YET
) : ( <> {showRows.map(r => ( ))}
# NAME WHO TYPE REGION / AZ HRS REQ HRS ACTUAL EST ACTUAL STATUS LAUNCHED TERM BY
{r.id} {r.nameTag || "—"} {r.instanceId &&
{r.instanceId}
}
@{r.user} {r.instanceType} {r.az || r.region} {r.hoursReq != null ? (+r.hoursReq).toFixed(4) + "h" : "—"} {r.hoursActual != null ? `${r.hoursActual.toFixed(1)}h` : "—"} {r.costEstimated != null ? `$${r.costEstimated.toFixed(4)}` : "—"} {r.costActual != null ? `$${r.costActual.toFixed(4)}` : "—"} {r.status.toUpperCase()} {r.launchedAt ? r.launchedAt.slice(0, 10) : "—"} {r.terminatedBy || "—"}
{totalPages > 1 && (
{(() => { const btns = []; const add = (i) => btns.push(); const addDots = (key) => btns.push(); if (totalPages <= 7) { for (let i = 0; i < totalPages; i++) add(i); } else { add(0); if (page > 3) addDots("l"); const start = Math.max(1, page - 1); const end = Math.min(totalPages - 2, page + 1); if (page <= 3) { for (let i = 1; i <= 4; i++) add(i); addDots("r"); } else if (page >= totalPages - 4) { addDots("l"); for (let i = totalPages - 5; i < totalPages; i++) add(i); } else { for (let i = start; i <= end; i++) add(i); if (end < totalPages - 2) addDots("r"); } add(totalPages - 1); } return btns; })()}
)} )} )}
); } // ── §05 SHORTCUTS ────────────────────────────────────────────── function Shortcuts({ shortcuts }) { return (
{(shortcuts || []).map(group => (
{group.group}
{group.items.map(it => ( e.currentTarget.style.background = "var(--bg-2)"} onMouseLeave={e => e.currentTarget.style.background = "transparent"}> {it.label} {it.hint} ))}
))}
); } // ── ACTIVITY FEED ────────────────────────────────────────────── function ActivityFeed({ activity, loading }) { return ( {loading && !activity.length ? : activity.length === 0 ? (
NO ACTIVITY YET
) : (
{activity.map((a, i) => (
{a.t} @{a.who} {a.what} {a.target}
))}
)}
); } // ── YOUR INSTANCES ────────────────────────────────────────── function YourInstances({ instances, instanceTypes, userHandle, onOpenInstance, hasSshKey }) { const [now, setNow] = React.useState(Date.now()); const [terminating, setTerminating] = React.useState(null); React.useEffect(() => { const id = setInterval(() => setNow(Date.now()), 1000); return () => clearInterval(id); }, []); const doTerminate = async (ident) => { if (!window.confirm(`Terminate ${ident}? This cannot be undone.`)) return; setTerminating(ident); try { const r = await fetch(`/api/ec2/terminate/${ident}`, { method: "POST", credentials: "include" }); if (!r.ok) { const b = await r.json().catch(() => ({})); alert(b.detail || "Terminate failed"); } } catch { alert("Network error"); } finally { setTerminating(null); } }; const my = (instances || []).filter(i => i.userHandle === userHandle && i.status === "running"); if (my.length === 0) return null; return (
EC2-007 YOUR INSTANCES ● {my.length} RUNNING
{my.map(inst => { const spec = (instanceTypes || []).find(t => t.id === inst.instance); const startedMs = inst.startedAt ? new Date(inst.startedAt).getTime() : null; const elapsedH = startedMs ? (now - startedMs) / 3600000 : 0; const hoursReq = inst.hoursReq || 0; const remaining = Math.max(0, hoursReq - elapsedH); const endsMs = startedMs ? startedMs + hoursReq * 3600000 : null; const termTime = endsMs ? new Date(endsMs).toLocaleTimeString("en-US", { hour: "2-digit", minute: "2-digit", timeZoneName: "short" }) : "—"; const costLive = inst.spotPrice ? (inst.spotPrice * elapsedH).toFixed(4) : null; const pct = hoursReq > 0 ? Math.min(100, (elapsedH / hoursReq) * 100) : 0; const tone = pct > 85 ? "danger" : pct > 65 ? "warn" : "default"; const remH = Math.floor(remaining); const remM = Math.floor((remaining - remH) * 60); const remStr = remaining < 0.017 ? "EXPIRED" : remH > 0 ? `${remH}h ${remM}m left` : `${remM}m left`; return (
{inst.name} {inst.instance}
${costLive || "—"}
{spec && ( <> {spec.vcpu} vCPU · {spec.ram} · {spec.vram} )} {!spec && {inst.instance}} {inst.spotPrice ? `@ $${inst.spotPrice.toFixed(4)}/h` : ""}
{remStr} {elapsedH.toFixed(1)}h / {hoursReq.toFixed(1)}h ENDS · {termTime}
{remaining <= 0 && (
AWAITING AUTO-TERMINATE (SWEEPS EVERY 5M)
)}
); })}
); } window.SEIS_MODULES = { LiteLLMBudget, ModelRanking, EC2Budget, ActiveServers, EC2History, Shortcuts, ActivityFeed, YourInstances };