You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tooling.apache.org by gs...@apache.org on 2026/10/19 07:56:31 UTC
(tooling-llmao) 03/03: admin: one page that says what is waiting, and what admins have done
This is an automated email from the ASF dual-hosted git repository.
gstein pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tooling-llmao.git
commit 99abf5ea3cb26c79e660d5a34301352666a85ca7
Author: Greg Stein <gs...@gmail.com>
AuthorDate: Mon Oct 19 02:53:39 2026 -0500
admin: one page that says what is waiting, and what admins have done
/admin was a menu with the request count as a small badge, and told
nobody what approving a request would do. It now leads with what needs
an admin, and says how much:
- Tiles for requests awaiting a decision, approvals not yet used, work
needed, and LiteLLM against the pin, each linking to its section.
- Requests are decided on the page, under a heading that gives the
count. Each says in words what approving does ("Lets carol create
one personal free-tier key, ..."). /admin/requests is gone.
- Approvals not yet used: each right to create a key that was granted
and not exercised, who approved it, and when it lapses.
- Recent work: the last 14 days, newest first, everyone or just me,
merged from the request records, the service keys' creators, each
tier's last change and the action log. One source being down thins
the list rather than failing the page.
- Tiers and Service keys as link cards. The link to the nonexistent
At the limit page is gone.
- LiteLLM is the version against the pin, read as the page loads;
per-deployment health stays on /models.
A decision is confirmed in words ("Approved: johndoe may create one
service key ... until 2026-11-02") rather than "Decision recorded.", so
a yes to the wrong thing shows at once.
Co-Authored-By: Claude Opus 5.5 <no...@anthropic.com>
---
pages.py | 209 ++++++++++++++++++++++++++++++++++-----
static/css/llmao.css | 66 +++++++++++++
templates/admin.ezt | 252 ++++++++++++++++++++++++++++++++++++-----------
templates/requests.ezt | 70 -------------
tests/test_admin.py | 88 ++++++++++++++++-
tests/test_admin_work.py | 185 ++++++++++++++++++++++++++++++++++
6 files changed, 714 insertions(+), 156 deletions(-)
diff --git a/pages.py b/pages.py
index 08ded72..1f7ec2d 100644
--- a/pages.py
+++ b/pages.py
@@ -19,6 +19,7 @@
from __future__ import annotations
+import datetime as dt
import functools
import io
import logging
@@ -39,6 +40,7 @@ from cmarkgfm.cmark import Options
from dunamai import Version
from easydict import EasyDict as edict # noqa: N813
+from llmao.access_requests import APPROVAL_TTL_DAYS
from llmao.auth import current_identity
from llmao.fleet import add_refusal, remove_refusal, snapshot_for_status
from llmao.model_status import (
@@ -60,7 +62,14 @@ from llmao.model_status import (
deployment_status,
)
from llmao.models import load_models, model_available_for, model_in_service, ux_models, vllm_recipe
-from llmao.proxy.client import PRETEND_PROJECTS, BackendUnavailableError, KeyInfo, pinned_litellm_version
+from llmao.proxy.client import (
+ PRETEND_PROJECTS,
+ TIER_FREE,
+ TIERS,
+ BackendUnavailableError,
+ KeyInfo,
+ pinned_litellm_version,
+)
from llmao.seam import AuthzError
# Replica summary order: the calm states first, the ones needing attention last.
@@ -1391,27 +1400,39 @@ async def usage_moved():
@APP.use_template(TEMPLATES / "admin.ezt")
@page(title="Admin")
async def admin_index(result):
- """One door for everything a site admin does.
+ """Everything that needs a site admin, on one page.
- The pages that only make sense together, and none of which a committer
- should have to scroll past in the nav. Models stays in the top nav.
+ What is waiting comes first and says how much is waiting: requests to
+ decide, approvals nobody has used yet, and Work needed. Then what admins
+ have done lately, then the settings pages. Each section is read on its
+ own, so one source being down leaves the rest of the page.
"""
if not result.is_site_admin:
raise AuthzError("Admin is limited to site admins.")
- # ezt's [if-any] tests truthiness but still requires the name to exist,
- # so an empty queue is None rather than 0 -- a badge reading "0" is worse
- # than no badge.
+ ident = await current_identity(APP.cfg)
+ mine = quart.request.args.get("who") == "me"
+
try:
- pending = await APP.seam.pending_requests(await current_identity(APP.cfg))
- except (AuthzError, BackendUnavailableError):
- pending = []
+ stored = await APP.backend.requests.find_all()
+ except BackendUnavailableError:
+ stored = []
+ pending = sorted((r for r in stored if r.state == "pending"), key=lambda r: r.created_at or "")
+ result.requests = _request_rows(pending)
result.pending_count = len(pending) or None
- # The page is still worth having when this cannot be read.
+ result.approvals = _open_approval_rows(stored)
+ result.approval_count = len(result.approvals) or None
+
try:
- skew = await APP.seam.work_needed(await current_identity(APP.cfg))
+ skew = await APP.seam.work_needed(ident)
except (AuthzError, BackendUnavailableError):
skew = []
result.skew = _skew_rows(skew)
+ result.skew_count = len(result.skew) or None
+
+ result.recent = await _recent_work(stored, only=ident.uid if mine else None)
+ result.recent_days = RECENT_DAYS
+ result.recent_mine = ezt.boolean(mine)
+
try:
result.litellm_running = await APP.seam.proxy_version()
except BackendUnavailableError:
@@ -1423,6 +1444,139 @@ async def admin_index(result):
return result
+# How far back Recent work reaches.
+RECENT_DAYS = 14
+
+# Bootstrap icon for each kind of recent work.
+_WORK_ICONS = {
+ "approved": "bi-check-circle",
+ "denied": "bi-x-circle",
+ "used": "bi-key",
+ "service_key": "bi-robot",
+ "tier": "bi-sliders",
+ "add_deployment": "bi-plus-circle",
+ "remove_deployment": "bi-dash-circle",
+ "approve_box": "bi-hdd-network",
+ "admin_label": "bi-flag",
+ "restrict_project": "bi-shield-lock",
+ "revoke_key": "bi-slash-circle",
+}
+
+
+def _key_ask(r) -> str:
+ """What a key request asks for, in words: 'one service key for tooling, "hadoop CI"'."""
+ want = {**r.wanted, **(r.granted or {})}
+ tier = want.get("tier") or "service"
+ kind = "personal free-tier key" if tier == TIER_FREE else f"{tier.replace('_', ' ')} key"
+ where = f" for {r.project}" if r.project else ""
+ purpose = f', "{want["purpose"]}"' if want.get("purpose") else ""
+ return f"one {kind}{where}{purpose}"
+
+
+def _approval_means(r) -> str:
+ """What saying yes to a pending request does, in words."""
+ if r.kind == "capacity":
+ return f"Sets {r.project}'s weekly allocation to {_tokens_h(r.wanted.get('token_cap') or 0)} tokens, at once."
+ return (
+ f"Lets {r.requester} create {_key_ask(r)}. Nothing is created until they do; "
+ f"they have {APPROVAL_TTL_DAYS} days."
+ )
+
+
+def _open_approval_rows(stored) -> list:
+ """Key approvals granted and not yet used: the rights still outstanding."""
+ rows = []
+ for r in stored:
+ if r.kind != "key" or not r.is_actionable():
+ continue
+ exp = r.expires_at()
+ days_left = (exp.date() - dt.datetime.now(dt.UTC).date()).days if exp else None
+ rows.append(
+ edict(
+ requester=r.requester,
+ ask=_key_ask(r),
+ decided_by=r.decided_by,
+ decided_on=(r.decided_at or "")[:10],
+ expires_h=_when_h(exp.date()) if exp else "",
+ soon=ezt.boolean(days_left is not None and days_left <= 3),
+ )
+ )
+ return sorted(rows, key=lambda row: row.expires_h)
+
+
+def _ago_h(stamp: str) -> str:
+ """'5m ago', '3h ago', '2d ago' from an ISO stamp; '' if unreadable."""
+ try:
+ at = dt.datetime.fromisoformat(stamp)
+ except (TypeError, ValueError):
+ return ""
+ if at.tzinfo is None:
+ at = at.replace(tzinfo=dt.UTC)
+ secs = max(0, int((dt.datetime.now(dt.UTC) - at).total_seconds()))
+ if secs < 3600:
+ return f"{max(1, secs // 60)}m ago"
+ if secs < 86400:
+ return f"{secs // 3600}h ago"
+ return f"{secs // 86400}d ago"
+
+
+def _work(at: str, by: str, kind: str, sentence: str) -> edict:
+ return edict(at=at or "", by=by or "", sentence=sentence, icon=_WORK_ICONS.get(kind, "bi-dot"), ago=_ago_h(at))
+
+
+async def _recent_work(stored, *, only: str | None = None) -> list:
+ """What admins did lately, newest first, from every record that keeps it.
+
+ Request decisions and approvals used come from the requests; service
+ keys from their creator on the key; tier changes from the tier; the
+ rest from the action log. Each source is read on its own, so one being
+ down thins the list rather than emptying the page.
+ """
+ since = (dt.datetime.now(dt.UTC) - dt.timedelta(days=RECENT_DAYS)).isoformat(timespec="seconds")
+ work = []
+ for r in stored:
+ what = "capacity" if r.kind == "capacity" else _key_ask(r)
+ subject = r.project if r.kind == "capacity" else r.requester
+ if r.decided_at:
+ if r.state == "denied":
+ work.append(_work(r.decided_at, r.decided_by, "denied", f"Denied {subject}'s request for {what}."))
+ elif r.kind == "capacity":
+ cap = _tokens_h((r.granted or r.wanted).get("token_cap") or 0)
+ work.append(
+ _work(r.decided_at, r.decided_by, "approved", f"Raised {r.project}'s weekly allocation to {cap}.")
+ )
+ else:
+ work.append(_work(r.decided_at, r.decided_by, "approved", f"Approved {r.requester} to create {what}."))
+ if r.consumed_at:
+ work.append(
+ _work(r.consumed_at, r.requester, "used", f"{r.requester} used their approval and created {what}.")
+ )
+ try:
+ for k in await APP.backend.keys.find(size=200):
+ if k.is_automation and k.created_by and k.created_at:
+ named = f' "{k.purpose}"' if k.purpose else ""
+ work.append(
+ _work(k.created_at, k.created_by, "service_key", f"Created {k.project}'s service key{named}.")
+ )
+ except BackendUnavailableError:
+ pass
+ for tier in TIERS:
+ try:
+ change = await APP.backend.tiers.last_change(tier)
+ except BackendUnavailableError:
+ change = None
+ if change:
+ label = "free tier" if tier == TIER_FREE else f"{tier} tier"
+ work.append(_work(change.at, change.by, "tier", f"Changed the {label}'s limits."))
+ try:
+ for a in await APP.actions.recent(RECENT_DAYS):
+ work.append(_work(a.at, a.by, a.what, a.sentence))
+ except BackendUnavailableError:
+ pass
+ work = [w for w in work if w.at >= since and (only is None or w.by == only)]
+ return sorted(work, key=lambda w: w.at, reverse=True)
+
+
def _stamp(at) -> str:
"""LiteLLM's own stamp on a memory row, to the minute."""
at = str(at or "")
@@ -1492,6 +1646,7 @@ def _request_rows(reqs) -> list:
was_adjusted=ezt.boolean(bool(r.granted) and r.granted != r.wanted),
decision_reason=r.decision_reason,
decided_by=r.decided_by,
+ means=_approval_means(r) if r.state == "pending" else "",
# The question a requester actually has: how long have I
# got to act on this.
expires_h=_when_h(exp.date()) if exp else "",
@@ -1501,17 +1656,6 @@ def _request_rows(reqs) -> list:
return out
-@APP.get("/admin/requests")
-@asfquart.auth.require
-@APP.use_template(TEMPLATES / "requests.ezt")
-@page(title="Requests")
-async def admin_requests(result):
- """Everything awaiting a decision, oldest first."""
- ident = await current_identity(APP.cfg)
- result.requests = _request_rows(await APP.seam.pending_requests(ident))
- return result
-
-
@APP.get("/admin/tiers")
@asfquart.auth.require
@APP.use_template(TEMPLATES / "tiers.ezt")
@@ -1633,17 +1777,30 @@ async def do_decide_request():
granted = None
try:
ident = await current_identity(APP.cfg)
- await APP.seam.decide_request(
+ req = await APP.seam.decide_request(
ident,
(form.get("request_id") or "").strip(),
approve=(form.get("decision") == "approve"),
reason=form.get("reason") or "",
granted=granted,
)
- await flash_success("Decision recorded.")
+ await flash_success(_decided_h(req))
except (AuthzError, BackendUnavailableError, ValueError) as e:
await flash_danger(str(e))
- return _see_other("/admin/requests")
+ return _see_other("/admin#requests")
+
+
+def _decided_h(r) -> str:
+ """What the admin just did, in words, so a yes to the wrong thing is caught at once."""
+ if r.state == "denied":
+ subject = r.project if r.kind == "capacity" else r.requester
+ return f"Denied {subject}'s request. They will see your reason."
+ if r.kind == "capacity":
+ cap = _tokens_h(r.granted.get("token_cap") or 0)
+ return f"Raised {r.project}'s weekly allocation to {cap}. It applies now."
+ exp = r.expires_at()
+ until = f" until {exp.date().isoformat()}" if exp else ""
+ return f"Approved: {r.requester} may create {_key_ask(r)}{until}."
@APP.get("/keys/other")
diff --git a/static/css/llmao.css b/static/css/llmao.css
index 3b7cbad..951bdc4 100644
--- a/static/css/llmao.css
+++ b/static/css/llmao.css
@@ -183,3 +183,69 @@ body {
display: none;
}
}
+
+/* Admin: summary tiles that say how much is waiting, and a timeline of recent work. */
+.admin-page .admin-tile,
+.admin-page .admin-link {
+ color: inherit;
+ text-decoration: none;
+ border-top: 0.25rem solid var(--bs-border-color);
+ transition: box-shadow 0.15s ease-in-out, transform 0.15s ease-in-out;
+}
+.admin-page .admin-tile:hover,
+.admin-page .admin-tile:focus-visible,
+.admin-page .admin-link:hover,
+.admin-page .admin-link:focus-visible {
+ box-shadow: var(--bs-box-shadow-sm);
+ transform: translateY(-1px);
+}
+.admin-page .admin-tile-hot {
+ border-top-color: var(--bs-danger);
+}
+.admin-page .admin-tile-hot .admin-tile-figure {
+ color: var(--bs-danger);
+}
+.admin-page .admin-tile-warm {
+ border-top-color: var(--bs-warning);
+}
+.admin-page .admin-tile-figure {
+ font-size: 2rem;
+ font-weight: 600;
+ line-height: 1.1;
+}
+.admin-page .admin-tile-figure-text {
+ font-size: 1.25rem;
+ font-family: var(--bs-font-monospace);
+ padding: 0.35rem 0;
+}
+.admin-page .admin-tile-label {
+ font-size: 0.875rem;
+ color: var(--bs-secondary-color);
+}
+.admin-page .admin-request {
+ border-left: 0.25rem solid var(--bs-danger);
+}
+.admin-page .admin-means {
+ padding: 0.5rem 0.75rem;
+ border-radius: var(--bs-border-radius-sm);
+ background-color: var(--bs-info-bg-subtle);
+ color: var(--bs-info-text-emphasis);
+}
+.admin-page .admin-timeline {
+ border-left: 2px solid var(--bs-border-color);
+ margin-left: 0.6rem;
+}
+.admin-page .admin-timeline-item {
+ display: flex;
+ gap: 0.75rem;
+ align-items: flex-start;
+ padding: 0.35rem 0 0.35rem 0;
+ margin-left: -0.6rem;
+}
+.admin-page .admin-timeline-icon {
+ flex: none;
+ width: 1.2rem;
+ text-align: center;
+ background: var(--bs-body-bg);
+ color: var(--bs-secondary-color);
+}
diff --git a/templates/admin.ezt b/templates/admin.ezt
index fdc5d3b..acf0bf2 100644
--- a/templates/admin.ezt
+++ b/templates/admin.ezt
@@ -1,21 +1,59 @@
[include "header.ezt"]
-<div class="container py-4">
+<div class="container py-4 admin-page">
<div class="mt-2">[include "flashes.ezt"]</div>
- <h1 class="h3 mb-3">Admin</h1>
- <p class="text-muted small">
- Everything that needs a site admin, in one place.
- </p>
+ <h1 class="h3 mb-1">Admin</h1>
+ <p class="text-muted small mb-3">Everything that needs a site admin, in one place.</p>
+
+ <div class="row row-cols-2 row-cols-lg-4 g-3 mb-4">
+ <div class="col">
+ <a href="#requests" class="card h-100 admin-tile[if-any pending_count] admin-tile-hot[end]">
+ <div class="card-body">
+ <div class="admin-tile-figure">[if-any pending_count][pending_count][else]0[end]</div>
+ <div class="admin-tile-label"><i class="bi bi-inbox" aria-hidden="true"></i> Awaiting your decision</div>
+ </div>
+ </a>
+ </div>
+ <div class="col">
+ <a href="#approvals" class="card h-100 admin-tile[if-any approval_count] admin-tile-warm[end]">
+ <div class="card-body">
+ <div class="admin-tile-figure">[if-any approval_count][approval_count][else]0[end]</div>
+ <div class="admin-tile-label"><i class="bi bi-key" aria-hidden="true"></i> Approvals not yet used</div>
+ </div>
+ </a>
+ </div>
+ <div class="col">
+ <a href="#work" class="card h-100 admin-tile[if-any skew_count] admin-tile-warm[end]">
+ <div class="card-body">
+ <div class="admin-tile-figure">[if-any skew_count][skew_count][else]0[end]</div>
+ <div class="admin-tile-label"><i class="bi bi-wrench-adjustable" aria-hidden="true"></i> Work needed</div>
+ </div>
+ </a>
+ </div>
+ <div class="col">
+ <a href="#litellm" class="card h-100 admin-tile[if-any litellm_matches][else] admin-tile-warm[end]">
+ <div class="card-body">
+ <div class="admin-tile-figure admin-tile-figure-text">
+ [if-any litellm_running][litellm_running][else]down[end]
+ </div>
+ <div class="admin-tile-label">
+ <i class="bi [if-any litellm_matches]bi-check-circle text-success[else]bi-exclamation-triangle[end]" aria-hidden="true"></i>
+ LiteLLM [if-any litellm_matches]matches the pin[else][if-any litellm_running]differs from the pin[else]unavailable[end][end]
+ </div>
+ </div>
+ </a>
+ </div>
+ </div>
[if-any skew]
- <div class="card border-warning mb-3">
- <div class="card-header fw-semibold">Work needed</div>
- <ul class="list-group list-group-flush">
+ <section id="work" class="mb-4">
+ <h2 class="h5 mb-2">Work needed <span class="badge text-bg-warning align-middle">[skew_count]</span></h2>
+ <div class="list-group">
[for skew]
- <li class="list-group-item small d-flex justify-content-between align-items-start">
+ <div class="list-group-item d-flex justify-content-between align-items-start">
<div>
- <span class="fw-semibold">[skew.what]</span>
- <span class="text-muted">[if-any skew.since]· since [skew.since][end]</span>
+ <div class="fw-semibold">[skew.what]</div>
+ [if-any skew.since]<div class="small text-muted">since [skew.since]</div>[end]
</div>
[if-any skew.action]
<form method="post" action="[skew.action]" class="mb-0 ms-3">
@@ -23,61 +61,165 @@
<button type="submit" class="btn btn-warning btn-sm">[skew.action_label]</button>
</form>
[end]
- </li>
+ </div>
[end]
- </ul>
- <div class="card-footer small text-muted">
- Each of these stays until it is put right.
</div>
- </div>
+ <p class="small text-muted mt-1 mb-0">Each stays until it is put right.</p>
+ </section>
[end]
- <div class="list-group">
- <a class="list-group-item list-group-item-action d-flex justify-content-between align-items-start"
- href="/admin/requests">
- <div>
- <div class="fw-semibold">Requests</div>
- <div class="small text-muted">
- Capacity bumps and key requests awaiting a decision.
+ <section id="requests" class="mb-4">
+ <h2 class="h5 mb-2">
+ [if-any pending_count]
+ [pending_count] [is pending_count "1"]request[else]requests[end] awaiting a decision
+ [else]
+ Requests
+ [end]
+ </h2>
+ [if-any requests]
+ [for requests]
+ <div class="card mb-3 admin-request">
+ <div class="card-body">
+ <div class="d-flex justify-content-between align-items-start flex-wrap gap-2">
+ <div>
+ <span class="fw-semibold">[requests.requester]</span>
+ <span class="badge text-bg-secondary ms-1">[requests.what]</span>
+ [if-any requests.project]<span class="text-muted small ms-1">[requests.project]</span>[end]
+ <div class="small text-muted">asked [requests.created_at]</div>
+ </div>
+ <div class="text-end">
+ <div class="fw-semibold font-monospace">[requests.wanted_h]</div>
+ [if-any requests.tier]<div class="small text-muted">[requests.tier] tier</div>[end]
+ </div>
+ </div>
+
+ [if-any requests.reason]
+ <p class="small mt-2 mb-0 fst-italic">“[requests.reason]”</p>
+ [end]
+
+ <div class="admin-means small mt-3">
+ <i class="bi bi-info-circle" aria-hidden="true"></i>
+ <strong>If you approve:</strong> [requests.means]
</div>
+
+ <form method="post" action="/do-decide-request" class="mt-3">
+ <input type="hidden" name="request_id" value="[requests.id]">
+ <div class="row g-2 align-items-center">
+ [if-any requests.is_capacity]
+ <div class="col-auto">
+ <input class="form-control form-control-sm" type="text"
+ name="granted_token_cap" placeholder="approve this instead"
+ aria-label="Approve a different allocation" style="width:12rem">
+ </div>
+ [end]
+ <div class="col">
+ <input class="form-control form-control-sm" type="text" name="reason"
+ placeholder="Why — required if you change the number or deny"
+ aria-label="Reason">
+ </div>
+ <div class="col-auto">
+ <button class="btn btn-success btn-sm" type="submit" name="decision" value="approve">
+ <i class="bi bi-check-lg" aria-hidden="true"></i> Approve
+ </button>
+ <button class="btn btn-outline-danger btn-sm" type="submit" name="decision" value="deny">Deny</button>
+ </div>
+ </div>
+ </form>
+ </div>
+ </div>
+ [end]
+ [else]
+ <p class="text-muted small"><i class="bi bi-check2-all text-success" aria-hidden="true"></i> Nothing waiting.</p>
+ [end]
+ </section>
+
+ <section id="approvals" class="mb-4">
+ <h2 class="h5 mb-1">Approvals not yet used</h2>
+ <p class="small text-muted mb-2">
+ Each is a right to create one key, granted and not yet exercised. It lapses on its date.
+ </p>
+ [if-any approvals]
+ <div class="list-group">
+ [for approvals]
+ <div class="list-group-item d-flex justify-content-between align-items-start flex-wrap gap-2">
+ <div>
+ <i class="bi bi-key text-secondary me-1" aria-hidden="true"></i>
+ <span class="fw-semibold">[approvals.requester]</span> may create [approvals.ask]
+ <div class="small text-muted">approved by [approvals.decided_by] on [approvals.decided_on]</div>
+ </div>
+ <span class="badge [if-any approvals.soon]text-bg-warning[else]text-bg-light border[end]">lapses [approvals.expires_h]</span>
</div>
- [if-any pending_count]
- <span class="badge text-bg-danger rounded-pill">[pending_count]</span>
[end]
- </a>
- <a class="list-group-item list-group-item-action" href="/admin/tiers">
- <div class="fw-semibold">Tiers</div>
- <div class="small text-muted">
- Allowances and rate limits per tier. Applies to every key on the tier.
+ </div>
+ [else]
+ <p class="text-muted small">None outstanding.</p>
+ [end]
+ </section>
+
+ <section id="recent" class="mb-4">
+ <div class="d-flex justify-content-between align-items-baseline flex-wrap gap-2 mb-2">
+ <h2 class="h5 mb-0">Recent work <span class="small text-muted fw-normal">last [recent_days] days</span></h2>
+ <div class="btn-group btn-group-sm" role="group" aria-label="Whose work">
+ <a href="/admin#recent" class="btn [if-any recent_mine]btn-outline-secondary[else]btn-secondary[end]">Everyone</a>
+ <a href="/admin?who=me#recent" class="btn [if-any recent_mine]btn-secondary[else]btn-outline-secondary[end]">Just me</a>
</div>
- </a>
- <a class="list-group-item list-group-item-action" href="/admin/at-limit">
- <div class="fw-semibold">At the limit</div>
- <div class="small text-muted">
- Keys at or near their allowance, oldest first.
+ </div>
+ [if-any recent]
+ <ul class="list-unstyled admin-timeline mb-0">
+ [for recent]
+ <li class="admin-timeline-item">
+ <i class="bi [recent.icon] admin-timeline-icon" aria-hidden="true"></i>
+ <div>
+ <div>[recent.sentence]</div>
+ <div class="small text-muted">[recent.by] · <span title="[recent.at] UTC">[recent.ago]</span></div>
+ </div>
+ </li>
+ [end]
+ </ul>
+ [else]
+ <p class="text-muted small">Nothing in the last [recent_days] days.</p>
+ [end]
+ </section>
+
+ <section class="mb-4">
+ <h2 class="h5 mb-2">Settings and lists</h2>
+ <div class="row row-cols-1 row-cols-md-2 g-3">
+ <div class="col">
+ <a class="card h-100 admin-link" href="/admin/tiers">
+ <div class="card-body">
+ <div class="fw-semibold"><i class="bi bi-sliders me-1" aria-hidden="true"></i> Tiers</div>
+ <div class="small text-muted">Allowances and rate limits per tier. Applies to every key on the tier.</div>
+ </div>
+ </a>
</div>
- </a>
- <a class="list-group-item list-group-item-action" href="/keys/other">
- <div class="fw-semibold">Service keys</div>
- <div class="small text-muted">
- Every key with no human at the keyboard, and when it was last used.
+ <div class="col">
+ <a class="card h-100 admin-link" href="/keys/other">
+ <div class="card-body">
+ <div class="fw-semibold"><i class="bi bi-robot me-1" aria-hidden="true"></i> Service keys</div>
+ <div class="small text-muted">Every key with no human at the keyboard, and when it was last used.</div>
+ </div>
+ </a>
</div>
- </a>
- </div>
+ </div>
+ </section>
- <div class="card mt-4">
- <div class="card-body py-2 small">
- <div class="fw-semibold">LiteLLM</div>
- [if-any litellm_running]
- [if-any litellm_matches]
- [litellm_running], matches the pin.
- [else]
- Running [litellm_running]. The pin is [litellm_expected].
- [end]
- [else]
- Unavailable.
- [end]
+ <section id="litellm">
+ <div class="card">
+ <div class="card-body py-2 small d-flex align-items-center gap-2">
+ <i class="bi bi-hdd-stack" aria-hidden="true"></i>
+ <span class="fw-semibold">LiteLLM</span>
+ [if-any litellm_running]
+ [if-any litellm_matches]
+ <span>[litellm_running], matches the pin.</span>
+ [else]
+ <span>Running [litellm_running]; the pin is [litellm_expected].</span>
+ [end]
+ [else]
+ <span>Unavailable.</span>
+ [end]
+ <span class="text-muted ms-auto">Read from LiteLLM as this page loaded. Each deployment's health is on <a href="/models">Models</a>.</span>
+ </div>
</div>
- </div>
+ </section>
</div>
[include "footer.ezt"]
diff --git a/templates/requests.ezt b/templates/requests.ezt
deleted file mode 100644
index 0100d5f..0000000
--- a/templates/requests.ezt
+++ /dev/null
@@ -1,70 +0,0 @@
-[include "header.ezt"]
-<div class="container py-4">
- <div class="mt-2">[include "flashes.ezt"]</div>
-
- <p class="small mb-2"><a href="/admin">← Admin</a></p>
- <h1 class="h3 mb-3">Requests</h1>
-
- [if-any requests]
- <p class="text-muted small">
- Capacity and key requests in one list, oldest first. Both are someone
- asking permission; both need a reason when the answer is not yes.
- </p>
-
- [for requests]
- <div class="card mb-3">
- <div class="card-body py-3">
- <div class="d-flex justify-content-between align-items-start flex-wrap gap-2">
- <div>
- <span class="fw-semibold">[requests.requester]</span>
- <span class="badge text-bg-secondary ms-1">[requests.what]</span>
- [if-any requests.project]
- <span class="text-muted small ms-1">[requests.project]</span>
- [end]
- <div class="small text-muted">asked [requests.created_at]</div>
- </div>
- <div class="text-end">
- <div class="fw-semibold font-monospace">[requests.wanted_h]</div>
- [if-any requests.tier]
- <div class="small text-muted">[requests.tier] tier</div>
- [end]
- </div>
- </div>
-
- [if-any requests.reason]
- <p class="small mt-2 mb-0 fst-italic">“[requests.reason]”</p>
- [end]
-
- <form method="post" action="/do-decide-request" class="mt-3">
- <input type="hidden" name="request_id" value="[requests.id]">
- <div class="row g-2 align-items-center">
- [if-any requests.is_capacity]
- <div class="col-auto">
- <input class="form-control form-control-sm" type="text"
- name="granted_token_cap" placeholder="approve this instead"
- aria-label="Approve a different allocation" style="width:12rem">
- </div>
- [end]
- <div class="col">
- <input class="form-control form-control-sm" type="text"
- name="reason"
- placeholder="Why — required if you change the number or deny"
- aria-label="Reason">
- </div>
- <div class="col-auto">
- <button class="btn btn-success btn-sm" type="submit"
- name="decision" value="approve">Approve</button>
- <button class="btn btn-outline-danger btn-sm" type="submit"
- name="decision" value="deny">Deny</button>
- </div>
- </div>
- </form>
- </div>
- </div>
- [end]
- [else]
- <p class="text-muted">Nothing waiting.</p>
- [end]
-
-</div>
-[include "footer.ezt"]
diff --git a/tests/test_admin.py b/tests/test_admin.py
index e9d329a..2046850 100644
--- a/tests/test_admin.py
+++ b/tests/test_admin.py
@@ -30,7 +30,7 @@ from llmao.proxy.client import LiteLLMBackend, LiteLLMTransport, pinned_litellm_
THIS_DIR = pathlib.Path(__file__).resolve().parent.parent
-def _render(*, running, expected, skew=(), flashes=(), notices=(), work=None):
+def _render(*, running, expected, skew=(), flashes=(), notices=(), work=None, requests=(), approvals=(), recent=()):
data = edict(
title="Admin",
is_site_admin=ezt.boolean(True),
@@ -49,8 +49,15 @@ def _render(*, running, expected, skew=(), flashes=(), notices=(), work=None):
work=work,
repo="https://github.com/apache/tooling-llmao",
commit="deadbeef",
- pending_count=None,
+ pending_count=len(requests) or None,
+ requests=list(requests),
+ approvals=list(approvals),
+ approval_count=len(approvals) or None,
+ recent=list(recent),
+ recent_days=14,
+ recent_mine=ezt.boolean(False),
skew=list(skew),
+ skew_count=len(skew) or None,
litellm_running=running,
litellm_expected=expected,
litellm_matches=ezt.boolean(bool(running) and running == expected),
@@ -72,7 +79,7 @@ def test_admin_drops_models_and_shows_a_version_match():
def test_admin_shows_a_version_mismatch_and_unavailable():
out = _render(running="1.0.0", expected="1.102.2")
- assert "Running 1.0.0. The pin is 1.102.2." in out
+ assert "Running 1.0.0; the pin is 1.102.2." in out
missing = _render(running=None, expected="1.102.2")
assert "Unavailable." in missing
@@ -152,8 +159,9 @@ def test_admin_shows_work_needed():
assert "limits differ from the service tier" in out
assert "since 2026-10-12 09:00 UTC" in out
assert "/do-acknowledge" not in out
- assert "<form" not in out[out.index("Work needed") : out.index("list-group-item-action")]
- assert "Work needed" not in _render(running=pin, expected=pin)
+ section = out[out.index('id="work"') : out.index('id="requests"')]
+ assert "<form" not in section
+ assert 'id="work"' not in _render(running=pin, expected=pin)
def test_work_with_a_way_to_do_it_has_a_button_that_does_it():
@@ -224,3 +232,73 @@ def test_work_needed_is_one_line_saying_where_to_go():
assert "3 things need doing." in out
assert 'href="/keys">Go to My Keys</a>' in out
assert "3 things need doing." not in _render(running=pin, expected=pin)
+
+
+def _pending(**over):
+ row = edict(
+ id="r1",
+ what="key",
+ requester="jdoe",
+ project="",
+ reason="for the hadoop CI",
+ wanted_h="hadoop CI",
+ tier="service",
+ is_capacity=ezt.boolean(False),
+ means='Lets jdoe create one service key, "hadoop CI". Nothing is created until they do; they have 14 days.',
+ created_at="2026-10-19",
+ )
+ row.update(over)
+ return row
+
+
+def test_the_count_waiting_is_said_outright_not_hidden_in_a_badge():
+ pin = pinned_litellm_version()
+ out = _render(running=pin, expected=pin, requests=[_pending(), _pending(id="r2")])
+ assert "2 requests awaiting a decision" in out
+ assert 'class="card h-100 admin-tile admin-tile-hot"' in out
+ one = _render(running=pin, expected=pin, requests=[_pending()])
+ assert "1 request awaiting a decision" in one
+ none = _render(running=pin, expected=pin)
+ assert "Nothing waiting." in none
+ assert "admin-tile-hot" not in none
+
+
+def test_each_request_says_what_approving_it_does():
+ pin = pinned_litellm_version()
+ out = _render(running=pin, expected=pin, requests=[_pending()])
+ assert "If you approve:" in out
+ assert "Lets jdoe create one service key" in out
+ assert 'name="request_id" value="r1"' in out
+
+
+def test_approvals_not_yet_used_say_who_may_do_what_until_when():
+ pin = pinned_litellm_version()
+ row = edict(
+ requester="jdoe",
+ ask='one service key, "hadoop CI"',
+ decided_by="admin1",
+ decided_on="2026-10-19",
+ expires_h="on 2026-11-02",
+ soon=ezt.boolean(False),
+ )
+ out = _render(running=pin, expected=pin, approvals=[row])
+ assert "may create one service key" in out
+ assert "approved by admin1 on 2026-10-19" in out
+ assert "lapses on 2026-11-02" in out
+ assert "None outstanding." in _render(running=pin, expected=pin)
+
+
+def test_recent_work_reads_as_sentences_with_who_and_when():
+ pin = pinned_litellm_version()
+ row = edict(
+ at="2026-10-19T14:02:11",
+ by="admin1",
+ sentence="Restricted free-tier to our own boxes.",
+ icon="bi-shield-lock",
+ ago="5m ago",
+ )
+ out = _render(running=pin, expected=pin, recent=[row])
+ assert "Restricted free-tier to our own boxes." in out
+ assert "admin1 ·" in out
+ assert "5m ago" in out
+ assert "Nothing in the last 14 days." in _render(running=pin, expected=pin)
diff --git a/tests/test_admin_work.py b/tests/test_admin_work.py
new file mode 100644
index 0000000..0329d2d
--- /dev/null
+++ b/tests/test_admin_work.py
@@ -0,0 +1,185 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""What /admin says about requests, approvals and recent work (pages.py)."""
+
+from __future__ import annotations
+
+import asyncio
+import datetime as dt
+import pathlib
+
+import asfquart
+from easydict import EasyDict as edict # noqa: N813
+
+from llmao.access_requests import KIND_CAPACITY, KIND_KEY, STATE_APPROVED, STATE_DENIED, AccessRequest
+from llmao.proxy.client import BackendUnavailableError, KeyInfo
+
+THIS_DIR = pathlib.Path(__file__).resolve().parent.parent
+
+
+def _app():
+ if asfquart.APP is None:
+ asfquart.construct(
+ "llmao", app_dir=str(THIS_DIR), cfg_file="config.yaml.example", oauth=False, force_login=False
+ )
+ import pages
+
+ return pages
+
+
+def _key(**kw):
+ base = dict(
+ kind=KIND_KEY,
+ requester="johndoe",
+ project=None,
+ reason="nightly build",
+ wanted={"purpose": "hadoop CI", "tier": "service"},
+ )
+ base.update(kw)
+ return AccessRequest.new(**base)
+
+
+def _capacity(**kw):
+ base = dict(
+ kind=KIND_CAPACITY, requester="alice", project="tooling", reason="audit", wanted={"token_cap": 40_000_000}
+ )
+ base.update(kw)
+ return AccessRequest.new(**base)
+
+
+def test_what_approving_does_is_said_plainly():
+ pages = _app()
+ assert pages._approval_means(_key()) == (
+ 'Lets johndoe create one service key, "hadoop CI". Nothing is created until they do; they have 14 days.'
+ )
+ free = _key(wanted={"purpose": "hadoop extension", "tier": "free_tier"})
+ assert "one personal free-tier key" in pages._approval_means(free)
+ assert pages._approval_means(_capacity()) == "Sets tooling's weekly allocation to 40M tokens, at once."
+
+
+def test_an_approval_not_yet_used_is_listed_until_it_is_used():
+ pages = _app()
+ granted, used, pending = _key(), _key(requester="bob"), _key(requester="carol")
+ for r in (granted, used):
+ r.decide(state=STATE_APPROVED, by="admin1")
+ used.consume()
+ rows = pages._open_approval_rows([granted, used, pending, _capacity()])
+ assert [r.requester for r in rows] == ["johndoe"]
+ assert rows[0].ask == 'one service key, "hadoop CI"'
+ assert rows[0].decided_by == "admin1"
+ assert rows[0].expires_h
+
+
+def test_a_decision_is_confirmed_in_words():
+ pages = _app()
+ r = _key()
+ r.decide(state=STATE_APPROVED, by="admin1")
+ assert pages._decided_h(r).startswith('Approved: johndoe may create one service key, "hadoop CI" until 20')
+ c = _capacity()
+ c.decide(state=STATE_APPROVED, by="admin1")
+ assert pages._decided_h(c) == "Raised tooling's weekly allocation to 40M. It applies now."
+ d = _key()
+ d.decide(state=STATE_DENIED, by="admin1", reason="use a project key")
+ assert pages._decided_h(d) == "Denied johndoe's request. They will see your reason."
+
+
+class _Keys:
+ def __init__(self, keys=(), down=False):
+ self._keys, self._down = list(keys), down
+
+ async def find(self, **_kw):
+ if self._down:
+ raise BackendUnavailableError("down")
+ return self._keys
+
+
+class _Tiers:
+ def __init__(self, changes):
+ self._changes = changes
+
+ async def last_change(self, tier):
+ return self._changes.get(tier)
+
+
+class _Actions:
+ def __init__(self, rows):
+ self._rows = rows
+
+ async def recent(self, _days):
+ return self._rows
+
+
+def _recent(monkeypatch, stored, *, keys=(), tiers=None, actions=(), keys_down=False, only=None):
+ pages = _app()
+ monkeypatch.setattr(
+ pages.APP, "backend", edict(keys=_Keys(keys, keys_down), tiers=_Tiers(tiers or {})), raising=False
+ )
+ monkeypatch.setattr(pages.APP, "actions", _Actions(list(actions)), raising=False)
+ return asyncio.run(pages._recent_work(stored, only=only))
+
+
+def _stamp(hours_ago):
+ return (dt.datetime.now(dt.UTC) - dt.timedelta(hours=hours_ago)).isoformat(timespec="seconds")
+
+
+def test_recent_work_merges_every_record_newest_first(monkeypatch):
+ approved = _key()
+ approved.decide(state=STATE_APPROVED, by="admin1")
+ approved.decided_at = _stamp(5)
+ approved.consume()
+ approved.consumed_at = _stamp(1)
+ service = KeyInfo(
+ token_id="key-1", # noqa: S106 -- an id, not a secret
+ project="tooling",
+ user=None,
+ purpose="nightly",
+ team_id="x",
+ spend=0.0,
+ max_budget=None,
+ created_at=_stamp(3),
+ last_used=None,
+ created_by="admin2",
+ )
+ action = edict(
+ at=_stamp(2), by="admin2", what="restrict_project", sentence="Restricted free-tier to our own boxes."
+ )
+ tier = {"free_tier": edict(by="admin1", at=_stamp(4))}
+ work = _recent(monkeypatch, [approved], keys=[service], tiers=tier, actions=[action])
+ assert [w.sentence for w in work] == [
+ 'johndoe used their approval and created one service key, "hadoop CI".',
+ "Restricted free-tier to our own boxes.",
+ 'Created tooling\'s service key "nightly".',
+ "Changed the free tier's limits.",
+ 'Approved johndoe to create one service key, "hadoop CI".',
+ ]
+ assert [w.by for w in work] == ["johndoe", "admin2", "admin2", "admin1", "admin1"]
+ assert work[1].icon == "bi-shield-lock"
+
+
+def test_recent_work_can_be_just_mine_and_leaves_out_the_old(monkeypatch):
+ old, mine = _key(), _key(requester="bob")
+ for r, by, ago in ((old, "admin1", 24 * 30), (mine, "admin2", 1)):
+ r.decide(state=STATE_DENIED, by=by, reason="no")
+ r.decided_at = _stamp(ago)
+ assert [w.by for w in _recent(monkeypatch, [old, mine])] == ["admin2"]
+ assert _recent(monkeypatch, [old, mine], only="admin1") == []
+
+
+def test_one_source_down_thins_the_list_rather_than_failing_the_page(monkeypatch):
+ r = _key()
+ r.decide(state=STATE_DENIED, by="admin1", reason="no")
+ assert len(_recent(monkeypatch, [r], keys_down=True)) == 1
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tooling.apache.org
For additional commands, e-mail: commits-help@tooling.apache.org