diff --git a/admin-panel-guests-harness.js b/admin-panel-guests-harness.js
new file mode 100644
index 0000000..6d4b1e8
--- /dev/null
+++ b/admin-panel-guests-harness.js
@@ -0,0 +1,133 @@
+// Harness for the admin panel's GUESTS list (gift accounts), run through the
+// skill's checker alongside the chart harness:
+// ~/.hermes/skills/research/inference-cooperative/scripts/check-page-js.sh \
+// app/main.py admin-panel-guests-harness.js
+// Exercises load() against both payload shapes — the portal's split payload
+// (guests[]) and an older payload that still tags rows account_type='gift'
+// inside members[] — and asserts the invariants that matter:
+// * guests NEVER count as members, in either shape;
+// * guests never render in the members table;
+// * the guests list shows recipient, inviter, credits remaining, expiry
+// and status, and hides entirely when there are no guests;
+// * the Members-view switch rule keeps the section's visibility handled
+// in switchView (the trap that stranded the Admin section on Models).
+// The checker evals in CommonJS (no top-level await), so the body is wrapped.
+const assert = (cond, msg) => { if (!cond) { console.error("FAIL: " + msg); process.exit(1); } };
+const count = (s, re) => (String(s).match(re) || []).length;
+const txt = (id) => String(document.getElementById(id).textContent); // stub keeps raw types; the DOM stringifies
+
+const memberRow = (email, spend) => ({
+ email, username: email.split("@")[0], active: true, activated: true,
+ account_type: "member", spend, all_time_spend: spend * 10,
+ balance: 15, credit_balance: 0, credits_remaining: 0, remaining: 15 - spend,
+});
+
+async function runLoad(overview) {
+ globalThis.fetch = async (url) => ({
+ status: 200,
+ json: async () => (String(url).indexOf("/api/overview") !== -1 ? overview : { models: [] }),
+ });
+ await load();
+}
+
+(async () => {
+// ---- Shape 1: the portal splits guests into their own list ----
+await runLoad({
+ members: [memberRow("alice@example.com", 2), memberRow("bob@example.com", 1)],
+ guests: [{
+ email: "friend@example.com", username: "friend", active: true,
+ account_type: "gift", gift_inviter: "alice@example.com",
+ credit_balance: 5, credits_remaining: 3.5,
+ gift_expires_at: "2027-01-07T02:00:00", gift_status: "active",
+ spend: 1.5, all_time_spend: 1.5,
+ }],
+ totals: { members: 2, total_spend: 4.5, total_all_time_spend: 45,
+ operator_spend: 1, operator_all_time_spend: 10 },
+});
+assert(txt("tot-members") === "2",
+ "split payload: member count is 2 (got " + txt("tot-members") + ")");
+assert(txt("tot-guests") === "1",
+ "split payload: guests count is 1");
+assert(txt("tot-spend-cycle") === "$4.50",
+ "split payload: spend total unchanged by the guests split");
+{
+ const rowsHtml = document.getElementById("rows").innerHTML;
+ assert(count(rowsHtml, /
/g) === 2, "members table holds only the 2 members");
+ assert(rowsHtml.indexOf("friend@example.com") === -1, "guest never renders in the members table");
+ const g = document.getElementById("guest-rows").innerHTML;
+ assert(count(g, /
/g) === 1, "guests list holds exactly the 1 guest");
+ assert(g.indexOf("friend@example.com") !== -1, "recipient email shown");
+ assert(g.indexOf("alice@example.com") !== -1, "inviting member shown from the ledger");
+ assert(g.indexOf("$3.50") !== -1, "credits remaining shown");
+ assert(g.indexOf("2027-01-07") !== -1, "time-box expiry date shown");
+ assert(/pill active[^>]*>active]*>expired]*>converted { console.error("FAIL: " + (e && e.stack || e)); process.exit(1); });
diff --git a/app/main.py b/app/main.py
index 92cab8a..373a33b 100644
--- a/app/main.py
+++ b/app/main.py
@@ -197,6 +197,31 @@ async def api_set_credits(request: Request):
return JSONResponse({"error": e.detail}, status_code=e.status_code)
+@app.post("/api/provision-gift")
+async def api_provision_gift(request: Request):
+ """Provision a gift account via the portal's /admin/provision-gift.
+
+ The portal enforces the abuse rules (one gift per inviter per 30 days,
+ one per recipient ever, active-member inviter) and returns a clear
+ refusal — surfaced to the operator as-is.
+ """
+ if not is_admin(request):
+ return JSONResponse({"error": "forbidden"}, status_code=403)
+ body = await request.json()
+ email = (body.get("email") or "").strip().lower()
+ name = (body.get("name") or "").strip()
+ inviter = (body.get("inviter") or body.get("inviter_email") or "").strip().lower()
+ if not email or "@" not in email:
+ return JSONResponse({"error": "A valid recipient email is required"}, status_code=400)
+ if not inviter or "@" not in inviter:
+ return JSONResponse({"error": "The inviting member's email is required"}, status_code=400)
+ try:
+ return await portal_post("/admin/provision-gift",
+ {"email": email, "name": name, "inviter": inviter})
+ except HTTPException as e:
+ return JSONResponse({"error": e.detail}, status_code=e.status_code)
+
+
# ---------------------------------------------------------------------------
# OIDC routes — authorization-code flow against Cloudron's OIDC provider.
# Active only when the `oidc` addon is configured (CLOUDRON_OIDC_* present).
@@ -290,6 +315,9 @@ PAGE_HTML = """
.pill.manual { background: #f1e8da; color: #a97a4a; }
.pill.org { background: #e7edf5; color: #4a6a8a; }
.pill.grace { background: #fdf3e3; color: #a97a2a; }
+ .pill.gift { background: #efe7f2; color: #7a5a92; }
+ #gift-group input { padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 12px; width: 170px; }
+ #gift-group input#gift-name { width: 120px; }
/* Trends tab (charts). Colours come from the same vars as the rest of the
panel; the SVG is inline so there is no chart library and no CDN. */
.trend-controls { display: flex; gap: 22px; flex-wrap: wrap; margin: 14px 0 0; }
@@ -355,6 +383,7 @@ PAGE_HTML = """
Gift accounts — access an inviting member gave to someone outside the co-op. Not members — excluded from member counts; a gift lapses on its time box or when its credits are spent.
+
+
+
+
+
Recipient
+
Invited by
+
Credits remaining
+
Expires
+
Status
+
+
+
+
+
+
+
@@ -536,7 +592,21 @@ async function load() {
// rather than left for the reader to guess.
$('tot-spend-cycle-own').textContent = fmt(d.totals.operator_spend ?? 0);
$('tot-spend-all-own').textContent = fmt(d.totals.operator_all_time_spend ?? 0);
- membersData = d.members || [];
+ // Guests: gift accounts live in their own list and never count as members.
+ // The portal splits them out (guests[]); an older payload that still tags
+ // rows account_type='gift' inside members[] is derived here, so the member
+ // count and the spend totals exclude guests in either payload shape.
+ const allRows = d.members || [];
+ const newShape = Array.isArray(d.guests);
+ guestsData = newShape ? d.guests : allRows.filter(m => (m.account_type || 'member') === 'gift');
+ membersData = newShape ? allRows : allRows.filter(m => (m.account_type || 'member') !== 'gift');
+ const gSpend = guestsData.reduce((s, m) => s + (Number(m.spend) || 0), 0);
+ const gAll = guestsData.reduce((s, m) => s + (Number(m.all_time_spend) || 0), 0);
+ const t = d.totals || {};
+ $('tot-members').textContent = newShape ? (t.members ?? membersData.length) : ((t.members ?? allRows.length) - guestsData.length);
+ $('tot-guests').textContent = guestsData.length;
+ $('tot-spend-cycle').textContent = fmt((t.total_spend ?? 0) - (newShape ? 0 : gSpend));
+ $('tot-spend-all').textContent = fmt((t.total_all_time_spend ?? t.total_spend ?? 0) - (newShape ? 0 : gAll));
adminsData = d.admins || [];
agentsData = d.agents || [];
if (currentView === 'members') renderMembers();
@@ -997,6 +1067,7 @@ function renderMoneyDaily(host, rows) {
// ---- shared state ----
let membersData = [];
+let guestsData = [];
let adminsData = [];
let agentsData = [];
let modelsData = [];
@@ -1028,6 +1099,7 @@ function switchView(view) {
$('table-models').style.display = view === 'models' ? '' : 'none';
// The Admin section is a members-view category; hide it in the Models view
// (model usage already integrates admin spend into the totals).
+ $('guests-section').style.display = view === 'members' ? '' : 'none';
$('admins-section').style.display = view === 'members' ? '' : 'none';
$('agents-section').style.display = view === 'members' ? '' : 'none';
$('trends-section').style.display = view === 'trends' ? '' : 'none';
@@ -1037,9 +1109,11 @@ function switchView(view) {
$('tab-trends').className = 'tab-btn' + (view === 'trends' ? ' active' : '');
$('tab-money').className = 'tab-btn' + (view === 'money' ? ' active' : '');
$('view-title').textContent = view === 'members' ? 'Members' : (view === 'models' ? 'Model usage' : (view === 'trends' ? 'Trends' : 'Money'));
- // Mode groups: Balance/All-time for members; Period for models.
+ // Mode groups: Balance/All-time for members; Period for models; the gift
+ // action belongs to the members view too.
$('range-group').style.display = view === 'models' ? '' : 'none';
$('member-mode-group').style.display = view === 'members' ? '' : 'none';
+ $('gift-group').style.display = view === 'members' ? '' : 'none';
// Trends renders on first visit only, so the panel's initial load stays fast.
if (view === 'trends') loadMetrics();
// Money renders on first visit only, same rule: one fetch, then the
@@ -1094,6 +1168,10 @@ function render() {
}
function renderMembers() {
+ // Datalist for the gift form's recipient/inviter fields: member emails the
+ // operator can pick from (rebuilt per render; tiny).
+ const dl = document.getElementById('member-email-list');
+ if (dl) dl.innerHTML = membersData.map(m => '').join('');
const rows = [...membersData].sort((a, b) => {
let va = a[memberSort.key], vb = b[memberSort.key];
if (memberSort.key === 'spend') { va = memberSpend(a); vb = memberSpend(b); }
@@ -1129,9 +1207,13 @@ function renderMembers() {
const creditsCell = creditsShown > 0
? fmt(creditsShown)
: '—';
- const src = m.manual
+ const src = m.account_type === 'gift'
+ ? 'gift'
+ : (m.manual
? 'manual'
- : 'OC';
+ : 'OC');
// Effective Matrix handle: dashboard-set external MXID, else the local
// @username:inference.coop identity (pending users have no username yet).
// Account cell: username on top (prominent); email + Matrix handle beneath
@@ -1164,6 +1246,29 @@ function renderMembers() {
}).join('');
clearArrows('members', memberSort);
+ // Guests — gift accounts in their own list, never in the members table or
+ // the member count. Inviter and expiry come from the portal gifts ledger.
+ const guestSection = document.getElementById('guests-section');
+ if (guestsData.length) {
+ guestSection.style.display = '';
+ $('guest-rows').innerHTML = guestsData.map(g => {
+ const top = g.username || g.email;
+ const emailLine = g.username ? '