263 lines
14 KiB
HTML
263 lines
14 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
<meta name="robots" content="noindex" />
|
|
<title>Abacus Operator Console</title>
|
|
<style>
|
|
:root {
|
|
--bg: #0f1117; --panel: #181b24; --border: #262b38; --fg: #e6e8ee;
|
|
--muted: #8b91a1; --accent: #6ea8fe; --danger: #f2668b; --ok: #55c98a;
|
|
--row: #1e222d;
|
|
}
|
|
* { box-sizing: border-box; }
|
|
body {
|
|
margin: 0; background: var(--bg); color: var(--fg);
|
|
font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
}
|
|
header {
|
|
display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
|
|
padding: 14px 20px; background: var(--panel); border-bottom: 1px solid var(--border);
|
|
position: sticky; top: 0; z-index: 10;
|
|
}
|
|
header h1 { font-size: 16px; margin: 0; font-weight: 600; letter-spacing: .3px; }
|
|
header .spacer { flex: 1; }
|
|
input, button {
|
|
font: inherit; color: var(--fg); background: var(--row);
|
|
border: 1px solid var(--border); border-radius: 6px; padding: 7px 10px;
|
|
}
|
|
input { min-width: 280px; }
|
|
button { cursor: pointer; }
|
|
button.primary { background: var(--accent); color: #0b1020; border-color: var(--accent); font-weight: 600; }
|
|
button:hover { filter: brightness(1.08); }
|
|
#status { font-size: 12px; color: var(--muted); }
|
|
#status.err { color: var(--danger); }
|
|
#status.ok { color: var(--ok); }
|
|
main { padding: 20px; max-width: 900px; }
|
|
.note {
|
|
background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
|
|
padding: 14px 16px; margin-bottom: 18px; color: var(--muted); font-size: 13px;
|
|
}
|
|
.note b { color: var(--fg); }
|
|
.lookup { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
|
|
.card {
|
|
background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
|
|
overflow: auto;
|
|
}
|
|
table { width: 100%; border-collapse: collapse; }
|
|
th, td {
|
|
text-align: left; padding: 9px 14px; border-bottom: 1px solid var(--border);
|
|
font-variant-numeric: tabular-nums; vertical-align: top;
|
|
}
|
|
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; width: 220px; }
|
|
td.mono, th.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; word-break: break-all; }
|
|
.badge {
|
|
display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 12px;
|
|
background: var(--row); border: 1px solid var(--border);
|
|
}
|
|
.section-title { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; margin: 22px 0 8px; }
|
|
.empty, .loading { padding: 28px; color: var(--muted); text-align: center; }
|
|
.gate { max-width: 480px; margin: 60px auto; text-align: center; }
|
|
.gate p { color: var(--muted); }
|
|
code { background: var(--row); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
|
|
main { max-width: 1200px; }
|
|
nav { display: flex; gap: 4px; }
|
|
nav button { background: transparent; border-color: transparent; color: var(--muted); }
|
|
nav button.active { color: var(--fg); background: var(--row); border-color: var(--border); }
|
|
th.col { width: auto; }
|
|
td.num { text-align: right; }
|
|
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 18px; }
|
|
.tile { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; }
|
|
.tile .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
|
|
.tile .value { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 4px; }
|
|
.badge.captured { color: var(--ok); } .badge.released { color: var(--muted); }
|
|
.hidden { display: none !important; }
|
|
.error { padding: 24px; color: var(--danger); text-align: center; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<header>
|
|
<h1>Abacus Operator Console</h1>
|
|
<nav id="tabs" class="hidden">
|
|
<button data-tab="agents" class="active">Agents</button>
|
|
<button data-tab="holds">Open holds</button>
|
|
<button data-tab="receipts">Receipts</button>
|
|
<button data-tab="lookup">Lookup</button>
|
|
</nav>
|
|
<div class="spacer"></div>
|
|
<input id="key" type="password" placeholder="X-API-Key (ABACUS_ADMIN_API_KEY)" autocomplete="off" />
|
|
<button id="connect" class="primary">Connect</button>
|
|
<button id="logout" class="hidden">Sign out</button>
|
|
<span id="status">Not connected</span>
|
|
</header>
|
|
|
|
<div id="gate" class="gate">
|
|
<p>Enter the Abacus <b>operator</b> key (<code>ABACUS_ADMIN_API_KEY</code>). It is separate
|
|
from the agents' ingress key, which cannot read fleet-wide spend. The key stays in this
|
|
tab's session storage and is sent as <code>X-API-Key</code> to the operator API.</p>
|
|
</div>
|
|
|
|
<main id="app" class="hidden">
|
|
<section id="tab-agents">
|
|
<div class="lookup"><button id="refresh-agents">Refresh</button></div>
|
|
<div class="grid" id="tiles"></div>
|
|
<div class="card" id="agents"></div>
|
|
</section>
|
|
<section id="tab-holds" class="hidden">
|
|
<div class="lookup"><button id="refresh-holds">Refresh</button></div>
|
|
<div class="card" id="holds"></div>
|
|
</section>
|
|
<section id="tab-receipts" class="hidden">
|
|
<div class="lookup">
|
|
<input id="receipt-agent" placeholder="Filter by agent_id" />
|
|
<button id="refresh-receipts">Apply</button>
|
|
</div>
|
|
<div class="card" id="receipts"></div>
|
|
</section>
|
|
<section id="tab-lookup" class="hidden">
|
|
<div class="lookup">
|
|
<input id="request_id" placeholder="request_id" autocomplete="off" />
|
|
<button id="lookup" class="primary">Look up receipt</button>
|
|
</div>
|
|
<div id="view" class="card"><div class="empty">Enter a request_id to view its receipt.</div></div>
|
|
</section>
|
|
</main>
|
|
|
|
<script>
|
|
"use strict";
|
|
(function () {
|
|
const KEY_STORE = "abacus_operator_key";
|
|
const $ = (id) => document.getElementById(id);
|
|
const setStatus = (m, k) => { $("status").textContent = m; $("status").className = k || ""; };
|
|
const getKey = () => sessionStorage.getItem(KEY_STORE) || "";
|
|
const setKey = (k) => (k ? sessionStorage.setItem(KEY_STORE, k) : sessionStorage.removeItem(KEY_STORE));
|
|
const usd = (m) => (m === null || m === undefined ? "-" : (Number(m) / 1e6).toLocaleString(undefined, { style: "currency", currency: "USD", minimumFractionDigits: 2, maximumFractionDigits: 6 }));
|
|
const when = (ms) => (ms ? new Date(Number(ms)).toLocaleString() : "-");
|
|
const el = (tag, props, ...kids) => {
|
|
const n = document.createElement(tag);
|
|
if (props) for (const [k, v] of Object.entries(props)) n.setAttribute(k, v);
|
|
for (const k of kids) n.append(k instanceof Node ? k : document.createTextNode(k === null || k === undefined ? "-" : String(k)));
|
|
return n;
|
|
};
|
|
const badge = (t) => el("span", { class: "badge " + String(t) }, t);
|
|
const table = (heads, rows) => {
|
|
const t = el("table", null, el("thead", null, el("tr", null, ...heads.map((h) => el("th", { class: "col" }, h)))));
|
|
const b = el("tbody"); rows.forEach((r) => b.append(r)); t.append(b); return t;
|
|
};
|
|
const show = (node, cls, text) => node.replaceChildren(el("div", { class: cls }, text));
|
|
|
|
async function api(path) {
|
|
const res = await fetch(path, { headers: { "X-API-Key": getKey(), Accept: "application/json" } });
|
|
let body = null; try { body = await res.json(); } catch (_) {}
|
|
if (res.status === 401) { logout(); throw new Error("Operator key rejected"); }
|
|
if (!res.ok) throw new Error(body && body.error ? body.error.message : "HTTP " + res.status);
|
|
return body && Object.prototype.hasOwnProperty.call(body, "data") ? body.data : body;
|
|
}
|
|
|
|
async function loadAgents() {
|
|
show($("agents"), "loading", "Loading agents...");
|
|
try {
|
|
const o = await api("/v1/admin/overview");
|
|
const tile = (l, v) => el("div", { class: "tile" }, el("div", { class: "label" }, l), el("div", { class: "value" }, v));
|
|
const captured = o.agents.reduce((a, r) => a + r.recent_captured_micros, 0);
|
|
const reserved = o.agents.reduce((a, r) => a + r.reserved_micros, 0);
|
|
$("tiles").replaceChildren(tile("Agents", o.agents.length), tile("Open holds", o.open_holds_total),
|
|
tile("Reserved in flight", usd(reserved)), tile("Recent captured spend", usd(captured)));
|
|
if (!o.agents.length) { show($("agents"), "empty", "No agents configured."); return; }
|
|
$("agents").replaceChildren(table(["Agent", "Funding", "Per-request cap", "Allowance remaining", "Open holds", "Reserved", "Recent requests", "Recent spend", "Released"],
|
|
o.agents.map((a) => el("tr", null,
|
|
el("td", { class: "mono" }, a.agent_id), el("td", null, a.funding_path),
|
|
el("td", { class: "num" }, a.per_request_max_micros === null ? "none" : usd(a.per_request_max_micros)),
|
|
el("td", { class: "num" }, a.allowance ? (a.allowance.error ? "unavailable" : usd(a.allowance.remaining_micros) + " of " + usd(a.allowance.limit_micros)) : "n/a"),
|
|
el("td", { class: "num" }, a.open_holds), el("td", { class: "num" }, usd(a.reserved_micros)),
|
|
el("td", { class: "num" }, a.recent_requests), el("td", { class: "num" }, usd(a.recent_captured_micros)),
|
|
el("td", { class: "num" }, a.recent_released)))));
|
|
setStatus("Connected", "ok");
|
|
} catch (e) { show($("agents"), "error", e.message); setStatus(e.message, "err"); }
|
|
}
|
|
|
|
async function loadHolds() {
|
|
show($("holds"), "loading", "Loading holds...");
|
|
try {
|
|
const h = await api("/v1/admin/holds");
|
|
if (!h.items.length) { show($("holds"), "empty", "No open holds. Every reservation has settled."); return; }
|
|
$("holds").replaceChildren(table(["Opened", "Hold", "Agent", "Request", "Reserved", "Deadline"],
|
|
h.items.map((r) => el("tr", null, el("td", null, when(r.created_at_ms)), el("td", { class: "mono" }, r.hold_id),
|
|
el("td", { class: "mono" }, r.receipt_context ? r.receipt_context.agent_id : "untracked"),
|
|
el("td", { class: "mono" }, r.receipt_context ? r.receipt_context.request_id : "-"),
|
|
el("td", { class: "num" }, usd(r.reserved_micros)), el("td", null, when(r.deadline_ms))))));
|
|
} catch (e) { show($("holds"), "error", e.message); }
|
|
}
|
|
|
|
async function loadReceipts() {
|
|
show($("receipts"), "loading", "Loading receipts...");
|
|
const q = new URLSearchParams({ limit: "200" });
|
|
if ($("receipt-agent").value.trim()) q.set("agent_id", $("receipt-agent").value.trim());
|
|
try {
|
|
const r = await api("/v1/admin/receipts?" + q);
|
|
if (!r.items.length) { show($("receipts"), "empty", "No receipts yet."); return; }
|
|
$("receipts").replaceChildren(table(["Request", "Agent", "Outcome", "Reserved", "Captured", "Balance after", "Seq"],
|
|
r.items.map((x) => {
|
|
const tr = el("tr", null, el("td", { class: "mono" }, x.request_id), el("td", { class: "mono" }, x.agent_id),
|
|
el("td", null, badge(x.outcome)), el("td", { class: "num" }, usd(x.reserved_micros)), el("td", { class: "num" }, usd(x.captured_micros)),
|
|
el("td", { class: "num" }, usd(x.balance_after_micros)), el("td", { class: "num" }, x.settlement_seq));
|
|
tr.style.cursor = "pointer";
|
|
tr.onclick = () => { $("request_id").value = x.request_id; showTab("lookup"); lookup(); };
|
|
return tr;
|
|
})));
|
|
} catch (e) { show($("receipts"), "error", e.message); }
|
|
}
|
|
|
|
async function lookup() {
|
|
const id = $("request_id").value.trim();
|
|
if (!id) { setStatus("Enter a request_id.", "err"); return; }
|
|
show($("view"), "loading", "Loading...");
|
|
try {
|
|
const r = await api("/v1/receipts/" + encodeURIComponent(id));
|
|
const p = r.settlement_proof || {};
|
|
const row = (l, v) => el("tr", null, el("th", null, l), el("td", { class: "mono" }, v));
|
|
$("view").replaceChildren(el("table", null, el("tbody", null,
|
|
row("Request ID", r.request_id), row("Outcome", r.outcome), row("Agent ID", r.agent_id), row("Run ID", r.run_id),
|
|
row("Budget ID", r.budget_id), row("Payer account", r.payer_account), row("Hold ID", r.hold_id),
|
|
row("Reserved", usd(r.reserved_micros)), row("Captured", usd(r.captured_micros)), row("Balance after", usd(r.balance_after_micros)),
|
|
row("Settlement seq", r.settlement_seq), row("Proof operation", p.operation), row("Proof sequence", p.sequence),
|
|
row("Receipt hash", p.receipt_hash), row("Signature", p.signature))));
|
|
} catch (e) { show($("view"), "error", e.message); }
|
|
}
|
|
|
|
function showTab(name) {
|
|
document.querySelectorAll("#tabs button").forEach((b) => b.classList.toggle("active", b.dataset.tab === name));
|
|
["agents", "holds", "receipts", "lookup"].forEach((t) => $("tab-" + t).classList.toggle("hidden", t !== name));
|
|
if (name === "agents") loadAgents();
|
|
if (name === "holds") loadHolds();
|
|
if (name === "receipts") loadReceipts();
|
|
}
|
|
function logout() {
|
|
setKey(""); setStatus("Not connected");
|
|
$("app").classList.add("hidden"); $("tabs").classList.add("hidden"); $("gate").classList.remove("hidden");
|
|
$("logout").classList.add("hidden"); $("connect").classList.remove("hidden"); $("key").classList.remove("hidden");
|
|
}
|
|
function connect() {
|
|
const k = $("key").value.trim() || getKey();
|
|
if (!k) { setStatus("Enter the operator key.", "err"); return; }
|
|
setKey(k); $("key").value = "";
|
|
$("gate").classList.add("hidden"); $("app").classList.remove("hidden"); $("tabs").classList.remove("hidden");
|
|
$("logout").classList.remove("hidden"); $("connect").classList.add("hidden"); $("key").classList.add("hidden");
|
|
showTab("agents");
|
|
}
|
|
$("connect").onclick = connect;
|
|
$("key").addEventListener("keydown", (e) => { if (e.key === "Enter") connect(); });
|
|
$("logout").onclick = logout;
|
|
document.querySelectorAll("#tabs button").forEach((b) => (b.onclick = () => showTab(b.dataset.tab)));
|
|
$("refresh-agents").onclick = loadAgents;
|
|
$("refresh-holds").onclick = loadHolds;
|
|
$("refresh-receipts").onclick = loadReceipts;
|
|
$("lookup").onclick = lookup;
|
|
$("request_id").addEventListener("keydown", (e) => { if (e.key === "Enter") lookup(); });
|
|
if (getKey()) connect();
|
|
})();
|
|
</script>
|
|
</body>
|
|
</html>
|