diff --git a/app/main.py b/app/main.py
index 4d30fff..36a65c8 100644
--- a/app/main.py
+++ b/app/main.py
@@ -139,6 +139,22 @@ async def api_metrics(request: Request, days: int = 730):
return JSONResponse({"error": e.detail}, status_code=e.status_code)
+@app.get("/api/money-series")
+async def api_money_series(request: Request):
+ """Revenue / token spend / OC balance series (portal /admin/money-series).
+
+ The portal owns this data and caches it hourly (the OC queries are slow);
+ the panel only reads it. The full history comes back in one payload — the
+ period and spend-mode toggles slice client-side and never refetch.
+ """
+ if not is_admin(request):
+ return JSONResponse({"error": "forbidden"}, status_code=403)
+ try:
+ return await portal_get("/admin/money-series")
+ except HTTPException as e:
+ return JSONResponse({"error": e.detail}, status_code=e.status_code)
+
+
@app.post("/api/set-balance")
async def api_set_balance(request: Request):
if not is_admin(request):
@@ -291,6 +307,13 @@ PAGE_HTML = """
.chart-tip .tip-row { display: flex; justify-content: space-between; gap: 14px; }
.chart-tip .tip-row span { color: var(--muted); }
.chart-tip .tip-row b { color: var(--ink); font-variant-numeric: tabular-nums; }
+ /* Money chart: legend keys + the honest-data caption. The caption is a
+ deliberate exception to the no-caption rule for the Trends charts: the
+ operator asked for the data-history limits to be stated IN this chart. */
+ .money-legend { display: inline-flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); font-weight: 600; }
+ .money-legend .key { display: inline-flex; align-items: center; gap: 5px; }
+ .money-legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
+ .money-caption { color: var(--muted); font-size: 11px; margin: 8px 0 0; }
@media (max-width: 600px) { .trend-controls { gap: 10px; } .trend-card { padding: 12px 10px; } }
.num { font-variant-numeric: tabular-nums; }
.remaining-col { font-weight: 700; color: var(--green-deep); background: #eaf3ea; }
@@ -345,6 +368,7 @@ PAGE_HTML = """
+
@@ -401,6 +425,30 @@ PAGE_HTML = """
+
+
+
+ Period
+
+
+
+
+
+ Token spend
+
+
+
+
+
+
+ Revenue, spend and balance
+
+
+
Loading
+
+
+
+
Agents
Bot and sandbox accounts. Not members — excluded from member counts; their usage is a collective expense.
@@ -758,6 +806,204 @@ function renderTrends() {
host.innerHTML = parts.join("");
}
+// ---- Money: revenue / token spend / OC balance over time ----
+// Three series with different provenance, from the portal's
+// /admin/money-series (hourly-cached server-side; the OC queries are slow).
+// One fetch at full range; the period and spend-mode toggles re-render
+// client-side. The balance series exists only from the daily-snapshot
+// deployment date onward (the OC API exposes just the CURRENT balance), so
+// it renders as a gap before that and the caption says so — never a zero.
+let moneyData = null;
+let moneyLoaded = false;
+let moneyPeriod = 90; // 0 = all time
+let moneySpendMode = "cum"; // "cum" = cumulative lines | "daily" = daily bars
+const MONEY_COLORS = { revenue: "var(--green-deep)", spend: "#4a6a8a", balance: "#a97a2a" };
+
+async function loadMoney() {
+ if (moneyLoaded) { renderMoney(); return; }
+ const host = $("money-body");
+ try {
+ const r = await fetch("/api/money-series");
+ if (r.status === 403) { host.innerHTML = "
Forbidden
"; return; }
+ const d = await r.json();
+ if (d.error) { host.innerHTML = "