dashboard: the panel's button shape, the server's spend figure, and keys as a chart
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/push/woodpecker Pipeline was successful
* Chart buttons take the admin panel's look: bordered, 8px radius, green-mid when
active (was a borderless segmented control). One design across both apps.
* "co-op spend, all time" now reads the portal's figure from /api/metrics instead
of summing the chart series in the browser. The second card ("of which the
co-op's own accounts") is gone: it was that same client-side sum, and the
portal's own breakdown is a panel-side notion I will not fake here.
* The API keys are a chart: one bar row per key — the chat key included, so the
built-in key's usage is comparable rather than a footnote — with a Spend /
Requests toggle. Revoke stays on each real key's row.
This commit is contained in:
1 parent
6e044c0f05
commit
b37b9549e4
1 file changed
+90
-50
+90
-50
@@ -579,12 +579,14 @@ PAGE_HTML = """<!DOCTYPE html>
|
||||
|
||||
.usage-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
|
||||
.usage-header h2 { margin-bottom: 0; }
|
||||
.mode-switch { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
|
||||
/* Same button shape as the admin panel's range buttons — border, 8px radius,
|
||||
green-mid when active — so the two apps' charts read as one design. */
|
||||
.mode-switch { display: inline-flex; gap: 6px; }
|
||||
.mode-btn {
|
||||
font-family: inherit; cursor: pointer; border: none; background: #fff; color: var(--muted);
|
||||
font-size: 12px; font-weight: 600; padding: 6px 12px; border-radius: 0;
|
||||
font-family: inherit; cursor: pointer; border: 1px solid var(--border); background: #fff;
|
||||
color: var(--muted); font-size: 12px; font-weight: 600; padding: 5px 12px; border-radius: 8px;
|
||||
}
|
||||
.mode-btn.active { background: var(--green-deep); color: #fff; }
|
||||
.mode-btn.active { background: var(--green-mid); color: #fff; border-color: var(--green-mid); }
|
||||
.docs-link { display: inline-block; margin-top: 14px; color: var(--green-deep); font-size: 13px; font-weight: 600; text-decoration: none; }
|
||||
.docs-link:hover { text-decoration: underline; }
|
||||
|
||||
@@ -622,6 +624,18 @@ PAGE_HTML = """<!DOCTYPE html>
|
||||
.board-fill { height: 100%; background: var(--green-mid); border-radius: 4px; }
|
||||
.board-sub { color: var(--muted); font-size: 11px; margin-top: 4px; }
|
||||
.keys { margin-top: 8px; }
|
||||
.key-controls { display: flex; align-items: center; gap: 6px; margin: 10px 0 6px; }
|
||||
/* One row per key: label, bar, value. The chat key is a row like any other,
|
||||
so the built-in key's usage is comparable instead of a footnote. */
|
||||
.key-bar-row {
|
||||
display: grid; grid-template-columns: minmax(110px, 1.4fr) 2.6fr auto auto;
|
||||
gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border);
|
||||
}
|
||||
.key-bar-row:last-child { border-bottom: none; }
|
||||
.key-bar-label { min-width: 0; }
|
||||
.key-bar-track { background: #eef0ea; border-radius: 6px; height: 14px; overflow: hidden; }
|
||||
.key-bar-fill { background: var(--green-mid); height: 100%; border-radius: 6px; }
|
||||
.key-bar-val { font-weight: 600; font-size: 12px; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
|
||||
.key-row {
|
||||
display: flex; align-items: center; justify-content: space-between; gap: 12px;
|
||||
padding: 14px 0; border-bottom: 1px solid var(--border);
|
||||
@@ -841,7 +855,6 @@ PAGE_HTML = """<!DOCTYPE html>
|
||||
</div>
|
||||
<div class="coop-stats">
|
||||
<div class="stat"><div class="num" id="coop-total">—</div><div class="lbl">co-op spend, all time</div></div>
|
||||
<div class="stat"><div class="num" id="coop-own">—</div><div class="lbl">of which the co-op's own accounts</div></div>
|
||||
</div>
|
||||
<div class="coop-trend-controls">
|
||||
<span class="trend-group" id="trend-metrics">
|
||||
@@ -875,8 +888,12 @@ PAGE_HTML = """<!DOCTYPE html>
|
||||
<div class="card" id="keys-card">
|
||||
<h2>API keys</h2>
|
||||
<p class="hint">Keys let you use the co-op's AI from your own tools. They draw from the same balance as chat.</p>
|
||||
<div class="key-controls">
|
||||
<span class="board-note" style="margin:0;">Show</span>
|
||||
<button class="mode-btn active" id="km-spend" onclick="setKeyMetric('spend')">Spend</button>
|
||||
<button class="mode-btn" id="km-requests" onclick="setKeyMetric('requests')">Requests</button>
|
||||
</div>
|
||||
<div class="keys" id="keys"><div class="empty">No API keys yet.</div></div>
|
||||
<div class="key-chat" id="key-chat"></div>
|
||||
<div class="new-key">
|
||||
<input id="new-name" type="text" placeholder="Key name (e.g. my-script)" maxlength="64" />
|
||||
<button class="primary" id="create-btn" onclick="createKey()">Create key</button>
|
||||
@@ -1343,6 +1360,7 @@ function renderModels(models) {
|
||||
// through the broker as aggregate, non-personal numbers. Fetched once at the
|
||||
// widest range; the toggles re-render client-side without refetching.
|
||||
let trendsData = null;
|
||||
let metricsTotals = null; // the co-op's all-time spend, from /api/metrics
|
||||
let trendMetric = "members"; // members | requests | spend
|
||||
let trendDays = 90; // 0 = all time
|
||||
|
||||
@@ -1427,6 +1445,9 @@ async function loadMetrics() {
|
||||
const d = await r.json();
|
||||
if (d.error) { host.innerHTML = "<div class=empty>" + d.error + "</div>"; return; }
|
||||
trendsData = d.series || [];
|
||||
// The co-op's all-time spend, straight from the portal (see the panel: it
|
||||
// and this page now read the same helper, so they cannot disagree).
|
||||
metricsTotals = d.totals || null;
|
||||
renderCoopTotals();
|
||||
renderTrends();
|
||||
} catch (e) {
|
||||
@@ -1439,13 +1460,18 @@ async function loadMetrics() {
|
||||
// it (NULL where a day was not measured, so it is skipped rather than counted
|
||||
// as zero). Both summed over the widest range the series carries (all time).
|
||||
function renderCoopTotals() {
|
||||
let total = 0, own = 0;
|
||||
(trendsData || []).forEach(row => {
|
||||
if (typeof row.spend_usd === "number") total += row.spend_usd;
|
||||
if (typeof row.operator_spend_usd === "number") own += row.operator_spend_usd;
|
||||
});
|
||||
$("coop-total").textContent = fmtMoney(total);
|
||||
$("coop-own").textContent = fmtMoney(own);
|
||||
// The server's figure, not a sum of whatever rows this page happens to hold:
|
||||
// the same number the admin panel shows. Summing the series in the browser
|
||||
// gave $900.51 where the portal's own all-time spend was $941.37 (2026-11-13).
|
||||
const el = $("coop-total");
|
||||
const t = (metricsTotals && typeof metricsTotals.spend_all_time === "number")
|
||||
? metricsTotals.spend_all_time : null;
|
||||
if (t === null) {
|
||||
// Never invent a number here. If the server did not send one, say so.
|
||||
el.textContent = "—";
|
||||
return;
|
||||
}
|
||||
el.textContent = fmtMoney(t);
|
||||
}
|
||||
|
||||
function setTrendMetric(m) {
|
||||
@@ -1638,47 +1664,61 @@ function renderBoard(models) {
|
||||
}).join('');
|
||||
}
|
||||
|
||||
function renderKeys(keys, keySpend) {
|
||||
const el = $('keys');
|
||||
// Spend rows come from the portal, keyed by the member's key name; the chat
|
||||
// key is carried separately (is_chat) and rendered on its own line.
|
||||
const spendFor = {};
|
||||
(keySpend || []).forEach(s => { if (!s.is_chat) spendFor[s.name] = s; });
|
||||
if (!keys.length) {
|
||||
el.innerHTML = '<div class="empty">No API keys yet. Create one below.</div>';
|
||||
renderChatSpend(keySpend);
|
||||
return;
|
||||
}
|
||||
el.innerHTML = keys.map(k => {
|
||||
const fp = k.fingerprint || '';
|
||||
const created = k.created_at ? ' · created ' + k.created_at.slice(0,10) : '';
|
||||
const s = spendFor[k.name];
|
||||
// Secondary detail: this key's all-time spend (server-side, from the spend
|
||||
// logs — LiteLLM's own per-key counter is period-only).
|
||||
const spent = ' · ' + fmtMoney(s ? s.spend : 0) + ' spent';
|
||||
return '<div class="key-row">' +
|
||||
'<div><div class="key-name">' + escapeHtml(k.name) + '</div>' +
|
||||
'<div class="key-meta">' + escapeHtml(created) +
|
||||
(fp ? ' · ends …' + escapeHtml(fp) : '') + escapeHtml(spent) + '</div>' +
|
||||
'</div>' +
|
||||
'<button class="ghost" data-name="' + escapeHtml(k.name) + '" onclick="revokeKey(this.dataset.name)">Revoke</button>' +
|
||||
'</div>';
|
||||
}).join('');
|
||||
renderChatSpend(keySpend);
|
||||
// A key's usage is easier to compare as bars than as a sentence: same numbers,
|
||||
// relative lengths. Spend or requests, one row per key, the chat key included.
|
||||
let keyRowsData = { keys: [], spend: [] };
|
||||
let keyMetric = "spend";
|
||||
|
||||
function setKeyMetric(m) {
|
||||
keyMetric = m;
|
||||
const sp = document.getElementById("km-spend"), rq = document.getElementById("km-requests");
|
||||
if (sp) sp.className = "mode-btn" + (m === "spend" ? " active" : "");
|
||||
if (rq) rq.className = "mode-btn" + (m === "requests" ? " active" : "");
|
||||
renderKeys(keyRowsData.keys, keyRowsData.spend);
|
||||
}
|
||||
|
||||
function renderChatSpend(keySpend) {
|
||||
const el = $('key-chat');
|
||||
if (!el) return;
|
||||
const chat = (keySpend || []).find(s => s.is_chat);
|
||||
if (!chat) { el.innerHTML = ''; return; }
|
||||
// The built-in chat key is not one of the member's API keys, so its spend is
|
||||
// shown on its own line rather than mixed into the list above.
|
||||
el.innerHTML = '<span class="key-chat-name">Chat (built-in)</span> · ' +
|
||||
'<span class="key-chat-num">' + fmtMoney(chat.spend) + '</span> spent' +
|
||||
(chat.requests ? ' · ' + chat.requests.toLocaleString() + ' requests' : '');
|
||||
function renderKeys(keys, keySpend) {
|
||||
const el = $('keys');
|
||||
keys = keys || []; keySpend = keySpend || [];
|
||||
keyRowsData = { keys: keys, spend: keySpend };
|
||||
const rows = keys.map(k => {
|
||||
const s = keySpend.find(x => !x.is_chat && x.name === k.name) || {};
|
||||
return {
|
||||
name: k.name, chat: false,
|
||||
meta: (k.created_at ? 'created ' + k.created_at.slice(0, 10) : '') +
|
||||
(k.fingerprint ? ' · ends …' + k.fingerprint : ''),
|
||||
spend: Number(s.spend) || 0, requests: Number(s.requests) || 0
|
||||
};
|
||||
});
|
||||
const chat = keySpend.find(x => x.is_chat);
|
||||
if (chat) {
|
||||
rows.push({ name: 'Chat (built-in)', chat: true, meta: 'the key the chat app uses',
|
||||
spend: Number(chat.spend) || 0, requests: Number(chat.requests) || 0 });
|
||||
}
|
||||
if (!rows.length) {
|
||||
el.innerHTML = '<div class="empty">No API keys yet. Create one below.</div>';
|
||||
return;
|
||||
}
|
||||
rows.sort((a, b) => (b[keyMetric] || 0) - (a[keyMetric] || 0));
|
||||
const max = Math.max.apply(null, rows.map(r => r[keyMetric] || 0));
|
||||
el.innerHTML = rows.map(r => {
|
||||
const v = r[keyMetric] || 0;
|
||||
const pct = max > 0 ? Math.round((v / max) * 100) : 0;
|
||||
const shown = keyMetric === "spend" ? fmtMoney(v) : v.toLocaleString() + ' requests';
|
||||
return '<div class="key-bar-row">' +
|
||||
'<div class="key-bar-label"><div class="key-name">' + escapeHtml(r.name) + '</div>' +
|
||||
'<div class="key-meta">' + escapeHtml(r.meta) + '</div></div>' +
|
||||
'<div class="key-bar-track" role="img" aria-label="' + escapeHtml(shown) + '">' +
|
||||
'<div class="key-bar-fill" style="width:' + pct + '%"></div></div>' +
|
||||
'<div class="key-bar-val">' + escapeHtml(shown) + '</div>' +
|
||||
(r.chat ? '<span></span>'
|
||||
: '<button class="ghost" data-name="' + escapeHtml(r.name) + '" onclick="revokeKey(this.dataset.name)">Revoke</button>') +
|
||||
'</div>';
|
||||
}).join('');
|
||||
}
|
||||
|
||||
|
||||
|
||||
function escapeHtml(s) {
|
||||
return String(s).replace(/[&<>"']/g, c => ({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user