@join-pantheon/cli 0.33.11 → 0.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/accounts.js +229 -8
- package/dist/admin-pages.js +674 -0
- package/dist/admin-stats.js +11 -5
- package/dist/admin-ui.js +416 -0
- package/dist/board.js +17 -2
- package/dist/byte-lru.js +52 -0
- package/dist/cli.js +180 -37
- package/dist/desktop-app.js +2 -2
- package/dist/flow-stats.js +501 -0
- package/dist/home-guard.js +27 -2
- package/dist/home-safety.js +1 -0
- package/dist/ledger.js +10 -4
- package/dist/leftovers.js +178 -0
- package/dist/notice.js +1 -0
- package/dist/notifier.js +15 -3
- package/dist/open-in.js +349 -0
- package/dist/relay.js +1429 -617
- package/dist/roster-file.js +0 -6
- package/dist/store.js +36 -1
- package/dist/tray.js +16 -1
- package/dist/uri-handler.js +1 -1
- package/dist/viewer-pages.js +190 -0
- package/helper/macos/main.swift +25 -5
- package/helper/macos/menubar.swift +56 -1
- package/helper/macos/prebuilt/manifest.json +5 -5
- package/helper/macos/prebuilt/pantheon-hud +0 -0
- package/helper/macos/prebuilt/pantheon-tray +0 -0
- package/helper/windows/pantheon-tray.ps1 +26 -1
- package/package.json +1 -1
|
@@ -0,0 +1,674 @@
|
|
|
1
|
+
import { MARK, SEAL, cap, esc, head, longDay, pct, plural, rangeSeg, rangeWords, script, spark, split, stackedColumns, steps, when } from "./admin-ui.js";
|
|
2
|
+
import { dur, median, refusalWords } from "./flow-stats.js";
|
|
3
|
+
export function stateNoteHtml(n, viewer = false) {
|
|
4
|
+
if (!n)
|
|
5
|
+
return "";
|
|
6
|
+
if (n.kind === "rebuild")
|
|
7
|
+
return viewer
|
|
8
|
+
? `<p class="note">Open items are not shown right now: the team's saved record needs rebuilding, which happens by itself the next time a member connects.</p>`
|
|
9
|
+
: `<p class="note">Open items: not shown. This team's saved state needs a rebuild (it is missing, unreadable or ahead of its history); it rebuilds the next time a member connects.</p>`;
|
|
10
|
+
return viewer
|
|
11
|
+
? `<p class="note">Open items are as of ${when(n.asOf, "full")}. Newer activity appears when the team next connects.</p>`
|
|
12
|
+
: `<p class="note">Open items as of ${when(n.asOf, "full")}; newer activity (${plural(n.behind, "act")}) appears when the team next connects.</p>`;
|
|
13
|
+
}
|
|
14
|
+
export const asOfHtml = (asOf, now) => asOf && now - asOf >= 1_000 ? `as of ${when(asOf, "sec")}` : "";
|
|
15
|
+
export const NOT_SHOWN = "Not shown until this team rebuilds (the next time a member connects).";
|
|
16
|
+
function topbar(o) {
|
|
17
|
+
const t = (id, href, label, n) => `<a href="${href}"${o.tab === id ? ` aria-current="page"` : ""}>${label}${n !== undefined ? `<span class="n">${n}</span>` : ""}</a>`;
|
|
18
|
+
return `<header class="top">
|
|
19
|
+
<a class="skip" href="#main">Skip to content</a>
|
|
20
|
+
<a class="lockup" href="/admin">${MARK}<b>Pantheon</b></a>
|
|
21
|
+
${o.crumbs ? `<span class="ctx">${o.crumbs}</span>` : `<span class="ctx"><span>Relay admin</span></span>
|
|
22
|
+
<nav class="tabs" aria-label="Admin sections">${t("overview", "/admin", "Overview")}<a href="/admin#teams">Teams${o.teams !== undefined ? `<span class="n">${o.teams}</span>` : ""}</a>${t("people", "/admin?tab=people", "People", o.people)}${t("plans", "/admin?tab=plans", "Plans")}${t("security", "/admin?tab=security", "Security")}${t("audit", "/admin?tab=audit", "Audit log")}</nav>`}
|
|
23
|
+
<div class="right"><span>operator</span><button type="button" class="iconbtn" data-theme-toggle>Dark</button><a href="/admin/logout">Sign out</a></div>
|
|
24
|
+
</header>`;
|
|
25
|
+
}
|
|
26
|
+
const page = (o) => `${head({ title: o.title, description: o.description, extraCss: o.extraCss, nonce: o.nonce })}\n<body>\n${o.body}\n${script(o.nonce)}\n</body>\n</html>`;
|
|
27
|
+
const verdictChip = (v) => v === "active" ? `<span class="chip">active</span>` : v === "new" || v === "idle" ? `<span class="chip plain">${v}</span>` : `<span class="chip line">${v}</span>`;
|
|
28
|
+
export function actionForm(csrf, action, id, inner, o = {}) {
|
|
29
|
+
const conf = o.typeToConfirm !== undefined ? ` data-type-to-confirm="${esc(o.typeToConfirm)}" data-confirm="${esc(o.confirm ?? "")}"` : o.confirm ? ` data-confirm="${esc(o.confirm)}"` : "";
|
|
30
|
+
return `<form method="POST" action="/admin/action"${o.cls ? ` class="${o.cls}"` : ""}${conf}><input type="hidden" name="csrf" value="${esc(csrf)}"><input type="hidden" name="action" value="${esc(action)}"><input type="hidden" name="id" value="${esc(id)}">${inner}</form>`;
|
|
31
|
+
}
|
|
32
|
+
const menuItem = (csrf, action, id, label, o = {}) => actionForm(csrf, action, id, `${o.extra ?? ""}<button class="item${o.danger ? " danger" : ""}">${esc(label)}</button>`, o);
|
|
33
|
+
const menu = (label, items) => `<details class="menu"><summary aria-label="${esc(label)}" title="${esc(label)}">···</summary><div class="pop">${items}</div></details>`;
|
|
34
|
+
const ageMeter = (ms, scaleMs = 24 * 3_600_000, width = 72) => {
|
|
35
|
+
const p = Math.min(100, Math.max(3, Math.round((ms / scaleMs) * 100)));
|
|
36
|
+
const cls = ms >= scaleMs ? "over" : p > 10 ? "hot" : "";
|
|
37
|
+
return `<span class="meter" style="width:${width}px"><i class="${cls}" style="width:${p}%"></i></span>`;
|
|
38
|
+
};
|
|
39
|
+
const WORKER_WORDS = {
|
|
40
|
+
not_signed_in: "its agent CLI isn't signed in",
|
|
41
|
+
no_agent: "no agent CLI it can run is installed",
|
|
42
|
+
no_agent_choice: "nobody chose which agent it runs",
|
|
43
|
+
kiro_only: "only Kiro is installed, which it cannot run unattended",
|
|
44
|
+
unsandboxed_off: "it would need to run unsandboxed, which is off",
|
|
45
|
+
sandbox_unavailable: "the sandbox it needs is not available",
|
|
46
|
+
busy_turn: "its person's own session is mid-turn",
|
|
47
|
+
recently_active: "its person was active a moment ago",
|
|
48
|
+
no_signal: "it cannot tell whether its person is at the keyboard",
|
|
49
|
+
capped: "it has hit its run cap",
|
|
50
|
+
outage: "the agent's service is down",
|
|
51
|
+
awaiting_wake_approval: "it is waiting for its person to approve waking",
|
|
52
|
+
busy_elsewhere: "it is running something else",
|
|
53
|
+
pinned_kiro: "it is pinned to Kiro",
|
|
54
|
+
pinned_unsandboxed: "it is pinned to unsandboxed runs, which are off",
|
|
55
|
+
};
|
|
56
|
+
export const workerWords = (reason) => (reason ? WORKER_WORDS[reason] ?? reason.replace(/_/g, " ") : "");
|
|
57
|
+
const SIGNIN_CSS = `
|
|
58
|
+
.wrap{min-height:100dvh;display:flex;flex-direction:column}
|
|
59
|
+
.signin{flex:1;display:grid;grid-template-columns:minmax(0,1fr) minmax(0,420px);gap:clamp(28px,6vw,96px);align-items:center;max-width:1080px;width:100%;margin:0 auto;padding:40px clamp(16px,4vw,40px)}
|
|
60
|
+
.hero h1{font:400 clamp(34px,5vw,56px)/1.02 var(--display);letter-spacing:-.02em;margin:0 0 18px;max-width:13ch}
|
|
61
|
+
.hero p{font-size:15.5px;color:var(--muted);max-width:44ch;margin:0 0 12px}
|
|
62
|
+
.form{background:var(--surface);border:1.5px solid var(--text);border-radius:12px;box-shadow:0 6px 0 var(--shadow);padding:26px 26px 22px}
|
|
63
|
+
.form h2{font-size:18px;margin-bottom:6px}
|
|
64
|
+
.form p{margin:0 0 18px;color:var(--muted);font-size:13.5px}
|
|
65
|
+
.form label{display:block;font-weight:500;font-size:13.5px;margin-bottom:6px}
|
|
66
|
+
input.big{width:100%;font:400 15px var(--ui);padding:11px 12px;border-radius:8px;border:1.5px solid var(--edge);background:var(--bg);color:var(--text)}
|
|
67
|
+
input.big:focus{outline:3px solid var(--mustard);outline-offset:1px;border-color:var(--text)}
|
|
68
|
+
input.code{font:500 24px var(--ui-mono);letter-spacing:.45em;text-align:center;padding:10px 12px}
|
|
69
|
+
.cta{width:100%;margin-top:16px;font:600 15px var(--ui);padding:12px 14px;border-radius:9px;border:1.5px solid var(--ink);background:var(--coral);color:var(--ink);cursor:pointer;box-shadow:0 4px 0 var(--shadow)}
|
|
70
|
+
.cta:active{transform:translateY(2px);box-shadow:0 2px 0 var(--ink)}
|
|
71
|
+
.small{font-size:12.5px;color:var(--muted);margin:18px 0 0}
|
|
72
|
+
.small a{color:var(--text)}
|
|
73
|
+
.err{margin:12px 0 0;font-size:13.5px;color:var(--accent-text);font-weight:500}
|
|
74
|
+
.foot{padding:18px clamp(16px,4vw,40px);font-size:12.5px;color:var(--muted);display:flex;gap:12px;flex-wrap:wrap;justify-content:space-between;border-top:1px solid var(--line)}
|
|
75
|
+
.points{list-style:none;padding:0;margin:18px 0 0;display:grid;gap:8px;font-size:13.5px}
|
|
76
|
+
.points li{display:flex;gap:10px;align-items:baseline}
|
|
77
|
+
.points li::before{content:"";flex:none;width:8px;height:8px;border-radius:50%;background:var(--teal);transform:translateY(-1px)}
|
|
78
|
+
@media (max-width:820px){.signin{grid-template-columns:minmax(0,1fr);align-items:start;padding-top:28px}.hero h1{font-size:34px}.points{margin-top:12px}}
|
|
79
|
+
`;
|
|
80
|
+
export { SIGNIN_CSS };
|
|
81
|
+
export function signinShell(o) {
|
|
82
|
+
return page({
|
|
83
|
+
title: o.title, description: o.description, nonce: o.nonce, extraCss: SIGNIN_CSS,
|
|
84
|
+
body: `<div class="wrap">
|
|
85
|
+
<header class="top" style="border-bottom:0">
|
|
86
|
+
<a class="lockup" href="${esc(o.home)}">${MARK}<b>Pantheon</b></a>
|
|
87
|
+
<div class="right" style="width:auto;margin-left:auto"><button type="button" class="iconbtn" data-theme-toggle>Dark</button></div>
|
|
88
|
+
</header>
|
|
89
|
+
<main class="signin" id="main">
|
|
90
|
+
<section class="hero">${o.hero}</section>
|
|
91
|
+
${o.form}
|
|
92
|
+
</main>
|
|
93
|
+
<footer class="foot"><span>Pantheon is messaging infrastructure for AI agents.</span><span>joinpantheon.network</span></footer>
|
|
94
|
+
</div>`,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
export function renderAdminLogin(o) {
|
|
98
|
+
return signinShell({
|
|
99
|
+
title: "Pantheon relay admin", description: "Sign in to operate this Pantheon relay.", nonce: o.nonce, home: "/admin",
|
|
100
|
+
hero: `<h1>Run this relay.</h1>
|
|
101
|
+
<p>Every team on ${esc(o.host)}: hand-offs, answers, what waits on a person, and the levers to look after accounts and plans.</p>
|
|
102
|
+
<ul class="points"><li>Reading a team's messages is logged.</li><li>Each sign-in is a session of its own; signing out ends it.</li></ul>`,
|
|
103
|
+
form: `<form class="form" method="POST" action="/admin/login">
|
|
104
|
+
<h2>Sign in</h2>
|
|
105
|
+
<p>With the relay's admin token (PANTHEON_ADMIN_TOKEN).</p>
|
|
106
|
+
<label for="admin-token">Admin token</label>
|
|
107
|
+
<input class="big" id="admin-token" type="password" name="token" required autofocus autocomplete="current-password"${o.wrong ? ` aria-invalid="true" aria-describedby="login-error"` : ""}>
|
|
108
|
+
<button class="cta" type="submit">Sign in</button>
|
|
109
|
+
${o.wrong ? `<p class="err" id="login-error" role="alert">That token was not accepted. Check your admin token and try again.</p>` : ""}
|
|
110
|
+
</form>`,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
export function needsALook(d) {
|
|
114
|
+
const out = [];
|
|
115
|
+
const teamLink = (t) => `<a href="/admin/space?name=${encodeURIComponent(t)}">${esc(t)}</a>`;
|
|
116
|
+
const owed = d.teams.flatMap((t) => t.flow.open.filter((o) => !o.human && o.ageMs > 24 * 3_600_000).map((o) => ({ t, o })))
|
|
117
|
+
.sort((a, b) => b.o.ageMs - a.o.ageMs)[0];
|
|
118
|
+
if (owed) {
|
|
119
|
+
const m = owed.t.members.find((x) => x.name === owed.o.owner);
|
|
120
|
+
const who = esc(cap(owed.o.owner));
|
|
121
|
+
const seen = m?.online ? `${who} is online` : m?.lastSeen ? `${who} was last seen ${when(m.lastSeen, "full")}${m.build ? ` on ${esc(m.build)}` : ""}` : `${who} has not been seen`;
|
|
122
|
+
const wk = !m?.worker ? "No worker is connected, so nothing picks this up until they open a session." : m.worker.state === "unavailable" ? `Their worker can't take it: ${esc(workerWords(m.worker.reason))}.` : `Their worker says it is ${esc(m.worker.state)}.`;
|
|
123
|
+
out.push({ rank: 0, ic: "!", html: `<b>${who} has owed ${esc(cap(owed.o.from ?? "someone"))} ${owed.o.kind === "answer" ? "an answer" : `a ${owed.o.kind}`} for ${dur(owed.o.ageMs)}</b> in ${teamLink(owed.t.name)}.`, sub: `${seen}. ${wk}` });
|
|
124
|
+
}
|
|
125
|
+
const dec = d.teams.flatMap((t) => t.flow.waiting.map((o) => ({ t, o }))).sort((a, b) => b.o.ageMs - a.o.ageMs);
|
|
126
|
+
if (dec.length) {
|
|
127
|
+
const teams = new Set(dec.map((x) => x.t.name)).size;
|
|
128
|
+
const head_ = dec[0];
|
|
129
|
+
const rest = dec.slice(1, 3).map((x) => `${cap(x.o.owner)} in ${x.t.name} (${dur(x.o.ageMs)})`).join(", ");
|
|
130
|
+
out.push({ rank: 1, ic: SEAL, html: `<b>${plural(dec.length, "decision is", "decisions are")} waiting on a person</b>${teams > 1 ? ` across ${teams} teams` : ` in ${teamLink(head_.t.name)}`}.`, sub: esc(`Oldest: ${cap(head_.o.owner)}, in ${head_.t.name}, ${dur(head_.o.ageMs)}.${rest ? ` Then ${rest}.` : ""}`) });
|
|
131
|
+
}
|
|
132
|
+
for (const t of d.teams.filter((x) => x.verdict === "went quiet").slice(0, 2)) {
|
|
133
|
+
const open = t.flow.open.length;
|
|
134
|
+
out.push({ rank: 2, ic: "~", html: `<b>${teamLink(t.name)} went quiet.</b>`, sub: esc(`${cap(t.says)}.${open ? ` ${plural(open, "request")} still open, the oldest ${dur(t.flow.oldestOpenMs)}.` : ""}`) });
|
|
135
|
+
}
|
|
136
|
+
const down = d.teams.flatMap((t) => t.members.filter((m) => m.worker?.state === "unavailable").map((m) => ({ t, m })));
|
|
137
|
+
for (const x of down.slice(0, 2))
|
|
138
|
+
out.push({ rank: 3, ic: "×", html: `<b>${esc(cap(x.m.name))}'s worker can't take requests</b> in ${teamLink(x.t.name)}.`, sub: `${esc(cap(workerWords(x.m.worker.reason)))} (reported ${when(x.m.worker.at, "time")}).` });
|
|
139
|
+
const behind = d.teams.flatMap((t) => t.behind.map((b) => ({ ...b, team: t.name })));
|
|
140
|
+
const seenB = new Map();
|
|
141
|
+
for (const b of behind)
|
|
142
|
+
if (!seenB.has(b.member))
|
|
143
|
+
seenB.set(b.member, b);
|
|
144
|
+
if (seenB.size) {
|
|
145
|
+
const list = [...seenB.values()];
|
|
146
|
+
out.push({ rank: 4, ic: "↑", html: `<b>${plural(list.length, "person", "people")} missed a self-upgrade.</b>`, sub: esc(`${list.slice(0, 4).map((b) => `${cap(b.member)} on ${b.pkg}`).join(", ")}${list.length > 4 ? `, and ${list.length - 4} more` : ""}.`) });
|
|
147
|
+
}
|
|
148
|
+
for (const t of d.teams.filter((x) => x.verdict === "never started").slice(0, 2))
|
|
149
|
+
out.push({ rank: 5, ic: "0", html: `<b>${teamLink(t.name)} never started.</b>`, sub: esc(`${cap(t.says)}.`) });
|
|
150
|
+
return out.sort((a, b) => a.rank - b.rank).slice(0, 7);
|
|
151
|
+
}
|
|
152
|
+
export function renderOverview(d) {
|
|
153
|
+
const range = rangeWords(d.days);
|
|
154
|
+
const T = d.teams;
|
|
155
|
+
const sum = (f) => T.reduce((n, t) => n + f(t), 0);
|
|
156
|
+
const asks = sum((t) => t.flow.asks), answered = sum((t) => t.flow.answered);
|
|
157
|
+
const allAnswerMs = T.flatMap((t) => t.flow.answerMs);
|
|
158
|
+
const m = sum((t) => t.flow.messages.total), w = sum((t) => t.flow.messages.worker);
|
|
159
|
+
const cmp = T.filter((t) => t.flow.messages.prevTotal !== null);
|
|
160
|
+
const prev = cmp.reduce((n, t) => n + (t.flow.messages.prevTotal ?? 0), 0), mCmp = cmp.reduce((n, t) => n + t.flow.messages.total, 0);
|
|
161
|
+
const byDays = T.filter((t) => t.flow.messages.utcDays).length, partialTeams = T.filter((t) => t.flow.partial).length;
|
|
162
|
+
const open = sum((t) => t.flow.open.length), overDay = sum((t) => t.flow.open.filter((o) => o.ageMs > 24 * 3_600_000).length);
|
|
163
|
+
const human = sum((t) => t.flow.waiting.length);
|
|
164
|
+
const unshown = T.filter((t) => t.stateNote?.kind === "rebuild").map((t) => t.name);
|
|
165
|
+
const liveAsOf = T.filter((t) => t.live && t.asOf).map((t) => t.asOf);
|
|
166
|
+
const cachedAsOf = liveAsOf.length ? asOfHtml(Math.min(...liveAsOf), d.now) : "";
|
|
167
|
+
const h = d.health;
|
|
168
|
+
const backupStale = !h.backupAt || d.now - h.backupAt > 36 * 3_600_000;
|
|
169
|
+
const needs = needsALook(d);
|
|
170
|
+
const upH = Math.floor(h.upMs / 3_600_000);
|
|
171
|
+
const up = upH >= 24 ? `${Math.floor(upH / 24)}d ${upH % 24}h` : upH >= 1 ? `${upH}h ${Math.floor((h.upMs % 3_600_000) / 60_000)}m` : `${Math.max(0, Math.floor(h.upMs / 60_000))}m`;
|
|
172
|
+
const delta = prev && cmp.length ? Math.round(((mCmp - prev) / prev) * 100) : null;
|
|
173
|
+
const order = ["went quiet", "never started", "new", "active", "idle"];
|
|
174
|
+
const teams = [...T].sort((a, b) => (b.flow.waiting.length ? 1 : 0) - (a.flow.waiting.length ? 1 : 0)
|
|
175
|
+
|| (a.verdict === "active" ? 0 : 1) - (b.verdict === "active" ? 0 : 1)
|
|
176
|
+
|| b.flow.messages.total - a.flow.messages.total
|
|
177
|
+
|| order.indexOf(a.verdict) - order.indexOf(b.verdict) || a.name.localeCompare(b.name));
|
|
178
|
+
const teamRows = teams.map((t) => {
|
|
179
|
+
const f = t.flow, tm = f.messages.total, tw = f.messages.worker;
|
|
180
|
+
const href = `/admin/space?name=${encodeURIComponent(t.name)}`;
|
|
181
|
+
return `<tr class="link" data-href="${esc(href)}">
|
|
182
|
+
<td class="span"><a class="tname" href="${esc(href)}">${esc(t.name)}</a> ${verdictChip(t.verdict)}${t.live ? "" : ` <span class="chip plain">sleeping</span>`}<span class="sub">${esc(t.says)}</span></td>
|
|
183
|
+
<td data-l="People"><span class="num">${t.people}</span><span class="sub">${t.online ? `${t.online} online` : "nobody online"}</span></td>
|
|
184
|
+
<td data-l="Messages, 14 days">${spark(t.spark14)}<span class="sub num">${tm} ${range}</span></td>
|
|
185
|
+
<td data-l="Done by workers">${tm ? `${split(tw, tm - tw, tm, 84)}<span class="sub num">${pct(tw, tm)}% of ${tm}</span>` : `<span class="quiet">no messages</span>`}</td>
|
|
186
|
+
<td data-l="Requests answered" class="r">${f.asks ? `<span class="num">${f.answered} of ${f.asks}</span><span class="sub">${f.medianAnswerMs !== null ? `median ${dur(f.medianAnswerMs)}` : "none answered yet"}</span>` : `<span class="quiet">none asked</span>`}</td>
|
|
187
|
+
<td data-l="Open now">${t.stateNote?.kind === "rebuild" ? `<span class="quiet">not shown: needs a rebuild</span>` : f.open.length ? `<span class="num">${f.open.length} open</span><span class="sub agewrap">${ageMeter(f.oldestOpenMs ?? 0, 24 * 3_600_000, 48)}oldest ${dur(f.oldestOpenMs)}</span>` : `<span class="quiet">nothing open</span>`}</td>
|
|
188
|
+
<td data-l="Waiting on a person" class="r">${t.stateNote?.kind === "rebuild" ? `<span class="quiet" title="not shown until this team rebuilds">–</span>` : f.waiting.length ? `${SEAL} <span class="num">${f.waiting.length}</span>` : `<span class="quiet">0</span>`}</td>
|
|
189
|
+
<td data-l="Owner" class="hide-s">${t.owner ? `<span class="mono">${esc(t.owner)}</span>` : `<span class="quiet">no owner on record</span>`}<span class="sub">${esc(t.plan ?? "no plan")}${t.behind.length ? ` · ${t.behind.length} behind` : ""}</span></td>
|
|
190
|
+
</tr>`;
|
|
191
|
+
}).join("");
|
|
192
|
+
const unreadRows = (d.unreadable ?? []).map((u) => {
|
|
193
|
+
const href = `/admin/space?name=${encodeURIComponent(u.name)}`;
|
|
194
|
+
return `<tr class="link" data-href="${esc(href)}"><td class="span"><a class="tname" href="${esc(href)}">${esc(u.name)}</a> <span class="chip line">can't be read</span><span class="sub">history can't be read right now (<span class="mono">${esc(u.code)}</span>)</span></td><td colspan="7" class="quiet">not counted in any number on this page</td></tr>`;
|
|
195
|
+
}).join("");
|
|
196
|
+
const bTotal = d.builds.reduce((n, b) => n + b.n, 0);
|
|
197
|
+
const buildChip = (k) => k === "current" ? `<span class="chip">current</span>` : k === "missed" ? `<span class="chip line">missed upgrade</span>` : k === "upgrading" ? `<span class="chip plain">upgrading</span>` : `<span class="chip plain">newer</span>`;
|
|
198
|
+
const buildRows = d.builds.map((b) => `<tr><td><span class="mono">${esc(b.version)}</span> ${buildChip(b.kind)}</td><td class="r num">${b.n}</td><td style="width:45%"><svg width="100%" height="10" viewBox="0 0 100 10" preserveAspectRatio="none" aria-hidden="true"><rect width="100" height="10" rx="3" fill="var(--surface-2)"/><rect width="${bTotal ? ((b.n / bTotal) * 100).toFixed(1) : 0}" height="10" rx="3" fill="${b.kind === "current" ? "var(--teal)" : "var(--quiet)"}"/></svg></td></tr>`).join("");
|
|
199
|
+
const refTotal = d.refusals.reduce((n, r) => n + r.n, 0);
|
|
200
|
+
const refRows = d.refusals.map((r) => `<tr><td><span class="mono">${esc(r.code)}</span><span class="sub">${esc(refusalWords(r.code))}</span></td><td class="r num">${r.n}</td></tr>`).join("");
|
|
201
|
+
const peopleRows = d.accounts.top.map((a) => `<tr><td class="span"><span class="who">${esc(a.username)}</span>${a.status === "suspended" ? ` <span class="chip line">suspended</span>` : ""}<span class="sub">${esc(a.email)}</span></td><td data-l="Teams">${a.teams.length ? a.teams.map(esc).join(", ") : `<span class="quiet">none</span>`}</td><td data-l="Plan">${esc(a.plan)}</td><td data-l="Devices" class="r num">${a.devices}</td><td data-l="Last seen">${when(a.lastSeen, "time")}</td></tr>`).join("");
|
|
202
|
+
const auditRows = d.audit.latest.map(auditRow).join("");
|
|
203
|
+
const busiest = d.series30.reduce((b, x) => (!b || x.worker + x.person > b.worker + b.person ? x : b), null);
|
|
204
|
+
const s7 = d.series30.slice(-7);
|
|
205
|
+
const w7 = s7.reduce((n, x) => n + x.worker, 0), p7 = s7.reduce((n, x) => n + x.person, 0);
|
|
206
|
+
return page({
|
|
207
|
+
title: "Pantheon relay admin", description: "Operator overview of every team on the relay: hand-offs, answers, open requests, decisions waiting on a person.", nonce: d.nonce,
|
|
208
|
+
body: `${topbar({ tab: "overview", teams: T.length, people: d.accounts.total })}
|
|
209
|
+
<main id="main">
|
|
210
|
+
${d.done ? `<div class="flash" role="status">${esc(d.done)}</div>` : ""}
|
|
211
|
+
<div class="health" aria-label="Relay health">
|
|
212
|
+
<span><span class="dot"></span>Relay <b>${esc(h.version)}</b>, up ${up}${h.hold ? ` · upgrades held at <b>${esc(h.hold)}</b>` : ""}</span>
|
|
213
|
+
${h.loopP99 !== null ? `<span>Loop delay p99 <b>${Math.round(h.loopP99)} ms</b></span>` : ""}
|
|
214
|
+
<span>${h.storage ? `<span class="dot bad"></span>Disk <b>failing: ${esc(h.storage)}</b>` : `Disk <b>writing normally</b>`}</span>
|
|
215
|
+
<span>Teams <b>${h.teams}</b> of ${h.maxTeams}</span>
|
|
216
|
+
<span>Codes emailed <b>${h.codesHour}</b> of ${h.codesCap} this hour</span>
|
|
217
|
+
<span>${backupStale ? `<span class="dot amber"></span>` : ""}Off-host backup <b>${h.backupAt ? `${dur(d.now - h.backupAt)} ago` : "never"}</b> · <a href="/admin/backup">download one</a></span>
|
|
218
|
+
</div>
|
|
219
|
+
|
|
220
|
+
<div class="sechead" style="margin-top:22px">
|
|
221
|
+
<h1>${d.days === 1 ? "The last 24 hours" : `The last ${d.days} days`} across ${plural(T.length, "team")}</h1>
|
|
222
|
+
<div class="end">${rangeSeg((n) => `/admin?range=${n}`, d.days)}</div>
|
|
223
|
+
</div>
|
|
224
|
+
|
|
225
|
+
<div class="tiles">
|
|
226
|
+
<div class="tile"><div class="l">Requests handed off</div><div class="v">${asks}</div><div class="d">asks from one agent to another</div></div>
|
|
227
|
+
<div class="tile"><div class="l">Answered</div><div class="v">${answered}${asks ? `<small>${pct(answered, asks)}%</small>` : ""}</div><div class="d">${allAnswerMs.length ? `median ${dur(median(allAnswerMs))} to answer` : "nothing answered yet"}</div></div>
|
|
228
|
+
<div class="tile"><div class="l">Messages</div><div class="v">${m}${delta !== null ? `<span class="delta">${delta >= 0 ? "+" : ""}${delta}%</span>` : ""}</div><div class="d">${delta !== null ? `vs ${prev} the ${d.days === 1 ? "24 hours" : `${d.days} days`} before${cmp.length < T.length ? ` (${cmp.length} of ${plural(T.length, "team")} with whole history)` : ""}` : `${range}`}</div></div>
|
|
229
|
+
<div class="tile"><div class="l">Done by workers</div>${m ? `<div class="v">${pct(w, m)}%</div><div class="d">${w} of ${m} sent by a person's worker (an unattended agent)</div>` : `<div class="v">none yet</div><div class="d">no messages ${range}</div>`}</div>
|
|
230
|
+
<div class="tile"><div class="l">Open right now</div><div class="v">${open}</div><div class="d">${overDay ? `${overDay} older than a day` : open ? "none older than a day" : "nothing owed"}${unshown.length ? `; ${plural(unshown.length, "team")} not shown` : ""}</div></div>
|
|
231
|
+
<div class="tile call"><div class="l">${SEAL} Waiting on a person</div><div class="v">${human}</div><div class="d">decisions only a person can make${unshown.length ? `; ${plural(unshown.length, "team")} not shown` : ""}</div></div>
|
|
232
|
+
</div>
|
|
233
|
+
${d.unreadable?.length ? `<p class="note">${d.unreadable.map((u) => `${esc(u.name)} (<span class="mono">${esc(u.code)}</span>)`).join(", ")}: history can't be read right now, so ${d.unreadable.length === 1 ? "it is" : "they are"} not counted here.</p>` : ""}
|
|
234
|
+
${cachedAsOf ? `<p class="note">Open items of live teams ${cachedAsOf}; they refresh every 15 seconds.</p>` : ""}
|
|
235
|
+
|
|
236
|
+
${(() => {
|
|
237
|
+
const rb = T.filter((t) => t.stateNote?.kind === "rebuild").map((t) => t.name), st = T.filter((t) => t.stateNote?.kind === "stale").map((t) => t.name);
|
|
238
|
+
if (!rb.length && !st.length)
|
|
239
|
+
return "";
|
|
240
|
+
const parts = [rb.length ? `${rb.map(esc).join(", ")}: saved state needs a rebuild, so open items are not counted` : "", st.length ? `${st.map(esc).join(", ")}: open items as of the last save` : ""].filter(Boolean);
|
|
241
|
+
return `<p class="note">${parts.join("; ")}. Each catches up the next time a member connects.</p>`;
|
|
242
|
+
})()}
|
|
243
|
+
${partialTeams ? `<p class="note">Partial: for ${plural(partialTeams, "team")}, older history inside this range was compacted (old acts of closed goals are dropped), so their asks, answers and hand-offs count only from the newest act dropped.${byDays ? ` Their messages are counted from the daily counts instead, by UTC day.` : ""}</p>` : ""}
|
|
244
|
+
<div class="grid2 sec">
|
|
245
|
+
<section class="card pad" aria-labelledby="h-daily">
|
|
246
|
+
<div class="sechead" style="margin-bottom:4px"><h2 id="h-daily">Messages per day</h2><p>last 30 UTC days, every team</p></div>
|
|
247
|
+
${stackedColumns({ days: d.series30, height: 230, label: `Messages per day for the last 30 days, split by worker and person. The last 7 days: ${w7 + p7}, ${w7} by workers.` })}
|
|
248
|
+
<div class="row" style="gap:22px;margin-top:14px;padding-top:12px;border-top:1px solid var(--line);font-size:13px"><span class="muted">Last 7 UTC days</span><span><b class="num">${w7}</b> <span class="muted">by workers</span></span><span><b class="num">${p7}</b> <span class="muted">by people</span></span>${busiest && busiest.worker + busiest.person ? `<span><span class="muted">busiest day</span> <b>${longDay(busiest.ts)} (UTC)</b> <span class="muted num">(${busiest.worker + busiest.person})</span></span>` : ""}</div>
|
|
249
|
+
</section>
|
|
250
|
+
<section class="card" aria-labelledby="h-needs">
|
|
251
|
+
<div class="sechead cardhead" style="margin-bottom:6px"><h2 id="h-needs">Needs a look</h2><p>${needs.length ? `${plural(needs.length, "thing")}, most urgent first` : "all clear"}</p></div>
|
|
252
|
+
<ul class="list">${needs.length ? needs.map((n) => `<li><span class="ic" aria-hidden="true">${n.ic}</span><div class="t">${n.html}<span class="sub">${n.sub}</span></div></li>`).join("") : `<li class="none"><div class="t">${unshown.length ? `Nothing else needs a look. Open items and decisions of ${plural(unshown.length, "team")} are not shown until ${unshown.length === 1 ? "it rebuilds" : "they rebuild"} (${unshown.slice(0, 3).map(esc).join(", ")}${unshown.length > 3 ? ", …" : ""}).` : "Nothing needs a look right now: no answer owed for over a day, no decision waiting, no team gone quiet."}</div></li>`}</ul>
|
|
253
|
+
</section>
|
|
254
|
+
</div>
|
|
255
|
+
|
|
256
|
+
${d.leftovers?.length ? `<section class="sec" id="leftovers" aria-labelledby="h-leftovers">
|
|
257
|
+
<div class="sechead"><h2 id="h-leftovers">Leftover files of deleted teams</h2><p>nothing is removed by itself: their invites admit nobody until you decide</p></div>
|
|
258
|
+
<div class="card"><table><thead><tr><th>Files</th><th>State</th><th>Why</th><th class="r">Action</th></tr></thead><tbody>${d.leftovers.map((l) => `<tr>
|
|
259
|
+
<td class="span"><span class="mono">${esc(l.stem)}</span></td>
|
|
260
|
+
<td data-l="State">${l.state === "covered" ? `<span class="chip line">covered</span><span class="sub">the deleted team's own files: never opened</span>` : `<span class="chip plain">unsure</span><span class="sub">its members still get in</span>`}</td>
|
|
261
|
+
<td data-l="Why">Leftover files of deleted team ${esc(l.stem)} (${esc(l.state)}${l.state === "unsure" ? ` — ${esc(l.why)}` : `: ${esc(l.why)}`})</td>
|
|
262
|
+
<td class="r">${actionForm(d.csrf, "quarantine_leftover", l.stem, `<label class="sub" for="q-${esc(l.stem)}">Type ${esc(l.stem)} to confirm</label><input class="field mono" id="q-${esc(l.stem)}" name="confirm" required autocomplete="off" spellcheck="false" placeholder="${esc(l.stem)}" aria-label="Type ${esc(l.stem)} to confirm"> <button class="btn">Move to quarantine</button>`, { cls: "filters" })}</td>
|
|
263
|
+
</tr>`).join("")}</tbody></table></div>
|
|
264
|
+
</section>` : ""}
|
|
265
|
+
<section class="sec" id="teams" aria-labelledby="h-teams">
|
|
266
|
+
<div class="sechead"><h2 id="h-teams">Teams</h2><p>what needs a call first, then the busiest</p><div class="end"><input type="search" class="field" placeholder="Filter teams" aria-label="Filter teams" data-filter="t-teams" style="width:200px"></div></div>
|
|
267
|
+
<div class="card"><table class="rt" id="t-teams">
|
|
268
|
+
<thead><tr><th>Team</th><th>People</th><th>Messages, 14 days</th><th>Done by workers</th><th class="r">Requests answered</th><th>Open now</th><th class="r">Waiting on a person</th><th>Owner</th></tr></thead>
|
|
269
|
+
<tbody>${teamRows}${unreadRows}${teamRows || unreadRows ? "" : `<tr><td colspan="8" class="empty">No teams on this relay yet.</td></tr>`}</tbody>
|
|
270
|
+
</table></div>
|
|
271
|
+
<p class="note">Verdicts are the weekly report's rules (active, went quiet, new, never started, idle). "Requests answered" pairs each ask with the answer that names it, over what each team's ledger still holds. Sleeping teams are read from disk and not woken.</p>
|
|
272
|
+
</section>
|
|
273
|
+
|
|
274
|
+
<div class="grid2 even sec">
|
|
275
|
+
<section class="card" aria-labelledby="h-builds">
|
|
276
|
+
<div class="sechead cardhead"><h2 id="h-builds">Builds in use</h2><p>${plural(bTotal, "member")}, by the build each was last seen on</p></div>
|
|
277
|
+
<table><tbody>${buildRows || `<tr><td class="empty">No member has connected yet.</td></tr>`}</tbody></table>
|
|
278
|
+
</section>
|
|
279
|
+
<section class="card" aria-labelledby="h-ref">
|
|
280
|
+
<div class="sechead cardhead"><h2 id="h-ref">Refused by the relay</h2><p>${refTotal} ${range}, by reason</p></div>
|
|
281
|
+
<table><tbody>${refRows || `<tr><td class="empty">Nothing refused ${range}.</td></tr>`}</tbody></table>
|
|
282
|
+
</section>
|
|
283
|
+
</div>
|
|
284
|
+
|
|
285
|
+
<section class="sec" id="people" aria-labelledby="h-people">
|
|
286
|
+
<div class="sechead"><h2 id="h-people">People</h2><p>${plural(d.accounts.total, "account")}, ${d.accounts.paid} on a paid plan · plan, limits, suspend and block are under each row's menu on the People page</p><div class="end"><a href="/admin/export?table=accounts&format=csv">Export accounts</a></div></div>
|
|
287
|
+
<div class="card"><table class="rt">
|
|
288
|
+
<thead><tr><th>Account</th><th>Teams</th><th>Plan</th><th class="r">Devices</th><th>Last seen</th></tr></thead>
|
|
289
|
+
<tbody>${peopleRows || `<tr><td colspan="5" class="empty">No accounts yet.</td></tr>`}</tbody>
|
|
290
|
+
</table></div>
|
|
291
|
+
${d.accounts.total > d.accounts.top.length ? `<p class="note"><a href="/admin?tab=people">Show all ${d.accounts.total}</a></p>` : ""}
|
|
292
|
+
</section>
|
|
293
|
+
|
|
294
|
+
<section class="sec" id="audit" aria-labelledby="h-audit">
|
|
295
|
+
<div class="sechead"><h2 id="h-audit">Audit log</h2><p>latest ${d.audit.latest.length} of ${d.audit.total.toLocaleString("en")} · every operator and viewer read is here</p><div class="end"><a href="/admin?tab=audit">Open the log</a><a href="/admin/export?table=audit&format=csv">Export CSV</a></div></div>
|
|
296
|
+
<div class="card"><table class="rt">
|
|
297
|
+
<thead><tr><th>Time</th><th>Event</th><th>Team</th><th>Who</th><th>Detail</th></tr></thead>
|
|
298
|
+
<tbody>${auditRows || `<tr><td colspan="5" class="empty">Nothing yet.</td></tr>`}</tbody>
|
|
299
|
+
</table></div>
|
|
300
|
+
<p class="note">Weekly report: <a href="/admin/report">as text</a> · <a href="/admin/report?format=json">JSON</a> · <a href="/admin/report?format=usage">daily usage</a>. Times are shown in your browser's time zone.</p>
|
|
301
|
+
</section>
|
|
302
|
+
</main>`,
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
const auditRow = (a) => `<tr><td data-l="Time" class="num">${when(a.ts, "time")}</td><td data-l="Event"><span class="mono">${esc(a.event)}</span></td><td data-l="Team">${a.space ? esc(a.space) : `<span class="quiet">relay</span>`}</td><td data-l="Who">${esc(a.who)}</td><td data-l="Detail" class="muted wrapc">${esc(a.detail ?? "")}</td></tr>`;
|
|
306
|
+
export function renderPeople(o) {
|
|
307
|
+
const rows = o.accounts.map((a) => {
|
|
308
|
+
const planForm = actionForm(o.csrf, "set_plan", a.id, `<label class="h" for="plan-${esc(a.id)}">Plan</label><select class="field" id="plan-${esc(a.id)}" name="plan">${o.plans.map((p) => `<option value="${esc(p)}"${p === a.plan ? " selected" : ""}>${esc(p)}</option>`).join("")}</select><button class="btn">Set plan</button>`, { confirm: `Move ${a.username} to the chosen plan? It applies from their next team, invite or admit.` });
|
|
309
|
+
const limits = actionForm(o.csrf, "set_limits", a.id, `<span class="h" style="width:100%">Custom limits${a.custom ? " (set)" : ""}</span><label class="h">teams <input class="field" type="number" name="spaces" min="0" value="${a.limits.spaces}" aria-label="Teams ${esc(a.username)} may create"></label><label class="h">people <input class="field" type="number" name="members" min="1" value="${a.limits.members}" aria-label="People per team for ${esc(a.username)}"></label><label class="h"><input type="checkbox" name="wake" value="on"${a.limits.wake ? " checked" : ""}> workers</label><button class="btn">Save</button>${a.custom ? `<button class="btn" name="clear" value="1">Back to ${esc(a.plan)}</button>` : ""}`);
|
|
310
|
+
const items = `${planForm}<hr>${limits}<hr>${a.status === "suspended" ? menuItem(o.csrf, "reinstate", a.id, "Reinstate") : menuItem(o.csrf, "suspend", a.id, "Suspend and sign out everywhere", { danger: true, confirm: `Suspend ${a.username}? They are signed out everywhere and refused until reinstated.` })}${menuItem(o.csrf, "block", a.email, "Block this email", { danger: true, confirm: `Block ${a.email} from signing up or in?` })}`;
|
|
311
|
+
return `<tr><td class="span"><span class="who">${esc(a.username)}</span> ${a.status === "suspended" ? `<span class="chip line" data-status="suspended">suspended</span>` : ""}<span class="sub">${esc(a.email)}</span></td>
|
|
312
|
+
<td data-l="Teams">${a.teams.length ? a.teams.map(esc).join(", ") : `<span class="quiet">none</span>`}<span class="sub">owns ${a.owned}</span></td>
|
|
313
|
+
<td data-l="Plan"><span data-plan="${esc(a.plan)}">${esc(a.plan)}</span>${a.custom ? ` <span class="chip plain">custom</span>` : ""}<span class="sub">${esc(a.limitText)}</span></td>
|
|
314
|
+
<td data-l="Limit hits" class="r num">${a.limitHits || `<span class="quiet">0</span>`}</td>
|
|
315
|
+
<td data-l="Devices" class="r num">${a.devices}</td>
|
|
316
|
+
<td data-l="Last seen">${when(a.lastSeen, "full")}<span class="sub">joined ${when(a.created, "date")}</span></td>
|
|
317
|
+
<td class="r menu-s">${menu(`Actions for ${a.username}: plan, limits, suspend, block`, items)}</td></tr>`;
|
|
318
|
+
}).join("");
|
|
319
|
+
return page({
|
|
320
|
+
title: "People · Pantheon relay admin", description: "Every account on the relay, with its plan, limits and levers.", nonce: o.nonce,
|
|
321
|
+
body: `${topbar({ tab: "people", teams: o.teams, people: o.accounts.length })}
|
|
322
|
+
<main id="main">
|
|
323
|
+
${o.done ? `<div class="flash" role="status">${esc(o.done)}</div>` : ""}
|
|
324
|
+
<section class="sec" aria-labelledby="h-people" style="margin-top:24px">
|
|
325
|
+
<div class="sechead"><h1 id="h-people">People</h1><p>${plural(o.accounts.length, "account")} · plan, limits, suspend and block are under each row's menu</p><div class="end"><input type="search" class="field" placeholder="Filter people" aria-label="Filter people" data-filter="t-accounts" style="width:200px"><a href="/admin/export?table=accounts&format=csv">Export CSV</a><a href="/admin/export?table=accounts&format=json">JSON</a></div></div>
|
|
326
|
+
<div class="card"><table class="rt" id="t-accounts">
|
|
327
|
+
<thead><tr><th>Account</th><th>Teams</th><th>Plan</th><th class="r">Limit hits</th><th class="r">Devices</th><th>Last seen</th><th></th></tr></thead>
|
|
328
|
+
<tbody>${rows || `<tr><td colspan="7" class="empty">No accounts yet.</td></tr>`}</tbody>
|
|
329
|
+
</table></div>
|
|
330
|
+
<p class="note">Suspending signs the account out everywhere and refuses its handshakes until reinstated; its messages stay in the ledgers. A plan or limits change applies from the account's next team, invite or admit. Limit hits count the times the relay refused them for a plan limit.</p>
|
|
331
|
+
</section>
|
|
332
|
+
</main>`,
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
export function renderPlans(o) {
|
|
336
|
+
const rows = o.plans.map((p) => {
|
|
337
|
+
const fid = `plan-${p.name}`;
|
|
338
|
+
return `<tr><td class="span"><b class="mono">${esc(p.name)}</b><span class="sub">${plural(p.accounts, "account")}</span>${actionForm(o.csrf, "set_plan_limits", p.name, "", { cls: "inl" }).replace("<form ", `<form id="${esc(fid)}" `)}</td>
|
|
339
|
+
<td data-l="Teams each"><input form="${esc(fid)}" class="field" type="number" name="spaces" min="0" value="${p.spaces}" aria-label="Teams each account on ${esc(p.name)} may create"></td>
|
|
340
|
+
<td data-l="People per team"><input form="${esc(fid)}" class="field" type="number" name="members" min="1" value="${p.members}" aria-label="People per team on ${esc(p.name)}"></td>
|
|
341
|
+
<td data-l="Open invite links"><input form="${esc(fid)}" class="field" type="number" name="invites" min="0" value="${p.invites}" aria-label="Open invite links per team on ${esc(p.name)}"></td>
|
|
342
|
+
<td data-l="Unattended workers"><label><input form="${esc(fid)}" type="checkbox" name="wake" value="on"${p.wake ? " checked" : ""}> allowed</label></td>
|
|
343
|
+
<td class="r menu-s"><button form="${esc(fid)}" class="btn">Save</button> ${p.name === "free" ? "" : menu(`More for the ${p.name} plan`, menuItem(o.csrf, "delete_plan", p.name, `Remove the ${p.name} plan`, { danger: true, confirm: `Remove the plan "${p.name}"?` }))}</td></tr>`;
|
|
344
|
+
}).join("");
|
|
345
|
+
const add = `<tr><td class="span">${actionForm(o.csrf, "set_plan_limits", "", "", { cls: "inl" }).replace("<form ", `<form id="plan-new" `).replace(`<input type="hidden" name="id" value="">`, "")}<input form="plan-new" class="field" type="text" name="id" aria-label="New plan name" placeholder="new plan name" pattern="[a-z][a-z0-9_-]{0,23}" required style="width:150px"></td>
|
|
346
|
+
<td data-l="Teams each"><input form="plan-new" class="field" type="number" name="spaces" min="0" value="3" aria-label="Teams each"></td>
|
|
347
|
+
<td data-l="People per team"><input form="plan-new" class="field" type="number" name="members" min="1" value="5" aria-label="People per team"></td>
|
|
348
|
+
<td data-l="Open invite links"><input form="plan-new" class="field" type="number" name="invites" min="0" value="5" aria-label="Open invite links"></td>
|
|
349
|
+
<td data-l="Unattended workers"><label><input form="plan-new" type="checkbox" name="wake" value="on" checked> allowed</label></td>
|
|
350
|
+
<td class="r menu-s"><button form="plan-new" class="btn">Add plan</button></td></tr>`;
|
|
351
|
+
return page({
|
|
352
|
+
title: "Plans · Pantheon relay admin", description: "The limits the relay enforces, per plan.", nonce: o.nonce,
|
|
353
|
+
body: `${topbar({ tab: "plans", teams: o.teams, people: o.people })}
|
|
354
|
+
<main id="main">
|
|
355
|
+
${o.done ? `<div class="flash" role="status">${esc(o.done)}</div>` : ""}
|
|
356
|
+
<section class="sec" aria-labelledby="h-plans" style="margin-top:24px">
|
|
357
|
+
<div class="sechead"><h1 id="h-plans">Plans</h1><p>limits the relay enforces · the owner's plan governs a team</p></div>
|
|
358
|
+
<div class="card"><table class="rt" id="t-plans">
|
|
359
|
+
<thead><tr><th>Plan</th><th>Teams each</th><th>People per team</th><th>Open invite links</th><th>Unattended workers</th><th></th></tr></thead>
|
|
360
|
+
<tbody>${rows}${add}</tbody>
|
|
361
|
+
</table></div>
|
|
362
|
+
<p class="note">Edits apply at once to the next create, invite or admit of every account on that plan. Unused invites count toward people per team. Every change is audited.</p>
|
|
363
|
+
</section>
|
|
364
|
+
</main>`,
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
export function renderSecurity(o) {
|
|
368
|
+
const stale = (s) => o.now - s.lastSeen > 15 * 60_000;
|
|
369
|
+
const sess = o.sessions.map((s) => `<tr><td class="span"><span class="who">${esc(s.username)}</span><span class="sub">${esc(s.device)}</span></td><td data-l="Kind">${s.role ? `<span class="chip plain">${esc(s.role)}</span>` : `<span class="quiet">unknown</span>`}</td><td data-l="Team">${esc(s.space) || `<span class="quiet">none</span>`}</td><td data-l="Address" class="mono">${esc(s.ip)}</td><td data-l="Since">${when(s.created, "full")}</td><td data-l="Last heartbeat">${when(s.lastSeen, "full")}${stale(s) ? ` <span class="chip line" title="no heartbeat for 15+ minutes">stale</span>` : ""}</td><td class="r menu-s">${menu(`Actions for this connection of ${s.username}`, `<span class="h mono">${esc(s.id)}</span>${menuItem(o.csrf, "revoke_session", s.id, "Sign out this connection", { danger: true, confirm: `Sign out this connection of ${s.username}?` })}${menuItem(o.csrf, "revoke_device", s.deviceId, "Remove this device", { danger: true, confirm: `Remove the device "${s.device}" from ${s.username}'s account? Every session on it ends.` })}`)}</td></tr>`).join("");
|
|
370
|
+
const blocks = o.blocks.map((b) => `<tr><td class="span"><span class="mono">${esc(b.pattern)}</span><span class="sub">${esc(b.kind)} · since ${when(b.created_at, "date")}</span></td><td class="r">${actionForm(o.csrf, "unblock", b.pattern, `<button class="btn">Unblock</button>`)}</td></tr>`).join("");
|
|
371
|
+
const codes = o.codes.map((v) => `<tr><td class="span">${esc(v.email)}</td><td data-l="For">${esc(v.purpose)}</td><td data-l="Asked">${when(v.created_at, "full")}</td><td data-l="Wrong tries" class="r num">${v.attempts}</td><td data-l="State">${v.expires_at < o.now ? `<span class="chip plain">expired</span>` : `<span class="chip">pending</span>`}</td></tr>`).join("");
|
|
372
|
+
return page({
|
|
373
|
+
title: "Security · Pantheon relay admin", description: "Live connections, blocked addresses, verification codes and backups.", nonce: o.nonce,
|
|
374
|
+
body: `${topbar({ tab: "security", teams: o.teams, people: o.people })}
|
|
375
|
+
<main id="main">
|
|
376
|
+
${o.done ? `<div class="flash" role="status">${esc(o.done)}</div>` : ""}
|
|
377
|
+
<section class="sec" aria-labelledby="h-conn" style="margin-top:24px">
|
|
378
|
+
<div class="sechead"><h1 id="h-conn">Live connections</h1><p>${o.sessions.length} open · ${plural(o.endedToday, "connection")} came and went in the last 24 hours</p><div class="end"><input type="search" class="field" placeholder="Filter connections" aria-label="Filter connections" data-filter="t-sessions" style="width:200px"><a href="/admin/export?table=sessions&format=csv">Export CSV</a></div></div>
|
|
379
|
+
<div class="card"><table class="rt" id="t-sessions">
|
|
380
|
+
<thead><tr><th>Account</th><th>Kind</th><th>Team</th><th>Address</th><th>Since</th><th>Last heartbeat</th><th></th></tr></thead>
|
|
381
|
+
<tbody>${sess || `<tr><td colspan="7" class="empty">No open connections right now.</td></tr>`}</tbody>
|
|
382
|
+
</table></div>
|
|
383
|
+
<p class="note">One row per open connection: an agent window, a worker, a menu bar or a CLI command while it runs. A sign-in is not a connection. Stale means no heartbeat for 15 minutes on a socket that has not closed, usually a machine that went to sleep.</p>
|
|
384
|
+
</section>
|
|
385
|
+
|
|
386
|
+
<div class="grid2 even sec">
|
|
387
|
+
<section aria-labelledby="h-blocks">
|
|
388
|
+
<div class="sechead"><h2 id="h-blocks">Blocked emails and domains</h2><p>${o.blocks.length}</p></div>
|
|
389
|
+
<div class="card"><table class="rt"><tbody>${blocks || `<tr><td class="empty">Nothing blocked.</td></tr>`}</tbody></table></div>
|
|
390
|
+
${actionForm(o.csrf, "block", "", `<label>Email or domain<input class="field" type="text" name="id" aria-label="Email or domain to block" placeholder="someone@spam.example or spam.example" required style="width:280px"></label><button class="btn">Block</button>`, { cls: "filters" }).replace(`<input type="hidden" name="id" value="">`, "").replace(`class="filters"`, `class="filters" style="margin-top:12px"`)}
|
|
391
|
+
<p class="note">A blocked email or domain cannot sign up or sign in. Existing accounts are not touched; suspend those on the People page.</p>
|
|
392
|
+
</section>
|
|
393
|
+
<section aria-labelledby="h-backup">
|
|
394
|
+
<div class="sechead"><h2 id="h-backup">Backups and reports</h2></div>
|
|
395
|
+
<div class="card pad">
|
|
396
|
+
<p style="margin:0 0 8px">Off-host backup: <b>${o.backupAt ? `${dur(o.now - o.backupAt)} ago` : "never"}</b>. ${plural(o.snapshots, "accounts snapshot")} on the relay's own disk.</p>
|
|
397
|
+
<p style="margin:0" class="row"><a class="iconbtn" href="/admin/backup">Download a backup</a><a href="/admin/export?table=audit&format=csv">Audit CSV</a><a href="/admin/export?table=devices&format=json">Devices JSON</a><a href="/admin/report">Weekly report</a></p>
|
|
398
|
+
</div>
|
|
399
|
+
</section>
|
|
400
|
+
</div>
|
|
401
|
+
|
|
402
|
+
<section class="sec" aria-labelledby="h-codes">
|
|
403
|
+
<div class="sechead"><h2 id="h-codes">Recent verification codes</h2><p>support: "I never got my code"</p></div>
|
|
404
|
+
<div class="card"><table class="rt" id="t-verifs">
|
|
405
|
+
<thead><tr><th>Email</th><th>For</th><th>Asked</th><th class="r">Wrong tries</th><th>State</th></tr></thead>
|
|
406
|
+
<tbody>${codes || `<tr><td colspan="5" class="empty">No codes pending.</td></tr>`}</tbody>
|
|
407
|
+
</table></div>
|
|
408
|
+
<p class="note">A row means the relay made a code and handed it to the email provider. No row means the request never reached the relay. Codes themselves are never stored.</p>
|
|
409
|
+
</section>
|
|
410
|
+
</main>`,
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
export function renderAudit(o) {
|
|
414
|
+
return page({
|
|
415
|
+
title: "Audit log · Pantheon relay admin", description: "Every security and operator event on the relay.", nonce: o.nonce,
|
|
416
|
+
body: `${topbar({ tab: "audit", teams: o.teams, people: o.people })}
|
|
417
|
+
<main id="main">
|
|
418
|
+
<section class="sec" aria-labelledby="h-audit" style="margin-top:24px">
|
|
419
|
+
<div class="sechead"><h1 id="h-audit">Audit log</h1><p>latest ${o.rows.length} of ${o.total.toLocaleString("en")} · every operator and viewer read is here</p><div class="end"><input type="search" class="field" placeholder="Filter the log" aria-label="Filter the audit log" data-filter="t-audit" style="width:220px"><a href="/admin/export?table=audit&format=csv">Export CSV</a></div></div>
|
|
420
|
+
<div class="card"><table class="rt" id="t-audit">
|
|
421
|
+
<thead><tr><th>Time</th><th>Event</th><th>Team</th><th>Who</th><th>Detail</th></tr></thead>
|
|
422
|
+
<tbody>${o.rows.map(auditRow).join("") || `<tr><td colspan="5" class="empty">Nothing yet.</td></tr>`}</tbody>
|
|
423
|
+
</table></div>
|
|
424
|
+
</section>
|
|
425
|
+
</main>`,
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
const KIND_LABEL = { answer: "Answer", accept: "Accept", revise: "Revise", decision: "Decision", deliver: "Deliver" };
|
|
429
|
+
export function rightNow(o, m, now) {
|
|
430
|
+
void now;
|
|
431
|
+
const who = esc(cap(o.owner));
|
|
432
|
+
const seen = (m?.lastSeen ? `; last seen ${when(m.lastSeen, "time")}` : "");
|
|
433
|
+
if (o.claimed)
|
|
434
|
+
return o.claimed.by === "worker" ? `${who}'s worker is working on it now (started ${when(o.claimed.at, "time")})` : `Claimed by ${who}'s agent window ${when(o.claimed.at, "time")}`;
|
|
435
|
+
if (!m)
|
|
436
|
+
return `${who} is not on this team any more`;
|
|
437
|
+
if (o.human)
|
|
438
|
+
return m.online ? `${who} is online${m.windows ? "" : " in a worker only"}` : `${who} is offline${seen}`;
|
|
439
|
+
if (m.worker?.state === "holding")
|
|
440
|
+
return `${who}'s worker is holding: ${esc(workerWords(m.worker.reason) || "it says it will wait")}`;
|
|
441
|
+
if (m.worker?.state === "unavailable")
|
|
442
|
+
return `${who}'s worker can't take it: ${esc(workerWords(m.worker.reason))}`;
|
|
443
|
+
if (m.worker?.state === "running")
|
|
444
|
+
return `${who}'s worker is busy with something else`;
|
|
445
|
+
if (m.online && !m.windows && m.worker)
|
|
446
|
+
return `${who}'s worker is ${esc(m.worker.state)} and has not taken it yet`;
|
|
447
|
+
if (m.online)
|
|
448
|
+
return m.busy ? `${who}'s session is mid-turn; it reaches the agent after this turn` : `Delivered to ${who}'s session, not picked up yet`;
|
|
449
|
+
return `${who} is offline${seen}${m.worker ? "" : ", with no worker connected"}`;
|
|
450
|
+
}
|
|
451
|
+
export function stepSubs(t) {
|
|
452
|
+
let prev = null;
|
|
453
|
+
return t.steps.map((s) => {
|
|
454
|
+
let sub = "", subText = "";
|
|
455
|
+
if (s.at !== null) {
|
|
456
|
+
if (prev === null) {
|
|
457
|
+
sub = when(s.at, "time");
|
|
458
|
+
subText = "";
|
|
459
|
+
}
|
|
460
|
+
else {
|
|
461
|
+
sub = subText = `+${dur(s.at - prev)}`;
|
|
462
|
+
}
|
|
463
|
+
prev = s.at;
|
|
464
|
+
}
|
|
465
|
+
return { label: s.label, sub, subText, state: s.state };
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
export function threadOutcome(t, viewer = false) {
|
|
469
|
+
const to = cap(t.to), from = cap(t.from);
|
|
470
|
+
const chip = t.outcome === "delivered" ? `<span class="chip">delivered</span>` : t.outcome === "answered" || t.outcome === "decided" ? `<span class="chip">${t.outcome}</span>`
|
|
471
|
+
: t.outcome === "person" ? `<span class="chip line">${SEAL} ${viewer ? `needs ${esc(to)}` : `waiting on ${esc(to)}`}</span>` : t.outcome === "working" ? `<span class="chip plain">being answered</span>`
|
|
472
|
+
: t.outcome === "closed" ? `<span class="chip plain">goal closed</span>` : t.outcome === "withdrawn" ? `<span class="chip plain">withdrawn</span>` : `<span class="chip line">${viewer ? "not picked up yet" : "not picked up"}</span>`;
|
|
473
|
+
const role = t.by && t.kind === "ask" ? `<span class="role ${t.by === "worker" ? "w" : "p"}">${t.by === "worker" ? `${viewer ? "picked up by " : ""}${esc(to)}'s worker` : `${viewer ? "answered by " : ""}${esc(to)} in person`}${viewer && t.pickupMs !== null ? ` in ${dur(t.pickupMs)}` : ""}</span>` : "";
|
|
474
|
+
let text = "";
|
|
475
|
+
const owes = t.stillOwed.length ? ` · ${t.stillOwed.map(cap).join(" and ")} still ${t.stillOwed.length === 1 ? "owes" : "owe"} an answer` : "";
|
|
476
|
+
const who = t.answeredBy.length && t.answeredBy.join() !== t.to ? t.answeredBy.map(cap).join(" and ") : to;
|
|
477
|
+
const later = t.answerRetracted ? " (later retracted)" : "";
|
|
478
|
+
if (t.outcome === "delivered")
|
|
479
|
+
text = `Delivered by ${who} in ${dur(t.doneMs)}${later}${owes}${t.goalClosed ? " · goal closed" : ""}`;
|
|
480
|
+
else if (t.outcome === "answered")
|
|
481
|
+
text = `Answered by ${who}${t.by === "person" ? " in person" : t.by === "worker" ? " through their worker" : ""} in ${dur(t.doneMs)}${later}${owes}${t.goalClosed ? " · goal closed" : ""}`;
|
|
482
|
+
else if (t.outcome === "withdrawn")
|
|
483
|
+
text = `${to} asked to be released and ${from} agreed: withdrawn`;
|
|
484
|
+
else if (t.outcome === "decided")
|
|
485
|
+
text = `${to} decided in ${dur(t.doneMs)}`;
|
|
486
|
+
else if (t.outcome === "person")
|
|
487
|
+
text = t.from === t.to ? `Escalated by ${from} ${dur(t.waitingMs)} ago · a decision only ${to} can make` : `${from}'s agent asked ${to} to decide ${dur(t.waitingMs)} ago · a decision only ${to} can make`;
|
|
488
|
+
else if (t.outcome === "working")
|
|
489
|
+
text = t.pickupMs !== null ? `${to}${t.by === "worker" ? "'s worker" : ""} picked it up after ${dur(t.pickupMs)} and is on it` : `${to} is on it`;
|
|
490
|
+
else if (t.outcome === "closed")
|
|
491
|
+
text = "The goal closed before it was answered";
|
|
492
|
+
else
|
|
493
|
+
text = `Not picked up for ${dur(t.waitingMs)}`;
|
|
494
|
+
return { chip, role, text };
|
|
495
|
+
}
|
|
496
|
+
export function renderTeamUnreadable(o) {
|
|
497
|
+
return page({
|
|
498
|
+
title: `${o.name} · Pantheon relay admin`, description: "This team's history can't be read right now.", nonce: o.nonce,
|
|
499
|
+
body: `${topbar({ crumbs: `<a href="/admin">Relay admin</a><span class="sep">/</span><a href="/admin#teams">Teams</a><span class="sep">/</span><b style="color:var(--text)">${esc(o.name)}</b>` })}
|
|
500
|
+
<main id="main">
|
|
501
|
+
<div class="sechead" style="margin-top:24px"><h1>${esc(o.name)}</h1> <span class="chip line">can't be read</span></div>
|
|
502
|
+
<div class="flash" role="alert">This team's history can't be read right now (<span class="mono">${esc(o.code)}</span>). Nothing on this page is shown as zero instead: reload once the disk answers again. If it persists, check the relay's data volume.</div>
|
|
503
|
+
</main>`,
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
export function renderTeam(d) {
|
|
507
|
+
const f = d.flow, range = rangeWords(d.days);
|
|
508
|
+
const enc = encodeURIComponent(d.name);
|
|
509
|
+
const memberOf = new Map(d.members.map((m) => [m.name, m]));
|
|
510
|
+
const admitted = d.members.filter((m) => m.admitted);
|
|
511
|
+
const waitingText = f.waiting.slice(0, 2).map((w) => `${cap(w.owner)} ${dur(w.ageMs)}`).join(" · ");
|
|
512
|
+
const OPEN_CAP = 100;
|
|
513
|
+
const openShown = d.allOpen ? f.open : f.open.slice(0, OPEN_CAP);
|
|
514
|
+
const openRows = openShown.map((o) => {
|
|
515
|
+
const how = o.human ? "decides" : o.kind === "deliver" ? "owes a delivery" : o.from ? `owes ${esc(cap(o.from))}` : "owes it";
|
|
516
|
+
return `<tr>
|
|
517
|
+
<td class="span">${o.human ? `${SEAL} ` : ""}<span class="chip plain mono">${KIND_LABEL[o.kind]}</span> <b class="who">${esc(cap(o.owner))}</b> <span class="muted">${how}</span><span class="sub wrapc">${esc(d.gist(o.ref))}</span></td>
|
|
518
|
+
<td data-l="Goal">${o.goalTitle ? esc(o.goalTitle) : `<span class="quiet">no goal</span>`}</td>
|
|
519
|
+
<td data-l="Waiting" class="agewrap">${ageMeter(o.ageMs)}<span class="num">${dur(o.ageMs)}</span></td>
|
|
520
|
+
<td data-l="Right now" class="span">${rightNow(o, memberOf.get(o.owner), d.now)}</td>
|
|
521
|
+
</tr>`;
|
|
522
|
+
}).join("");
|
|
523
|
+
const handoffRows = f.threads.map((t) => {
|
|
524
|
+
const oc = threadOutcome(t);
|
|
525
|
+
const gist = d.gist(t.root);
|
|
526
|
+
return `<li><span class="ic" aria-hidden="true">→</span><div class="t">
|
|
527
|
+
<div class="row" style="gap:8px"><b>${t.kind === "decision" && t.from === t.to ? `${esc(cap(t.from))} escalated` : `${esc(cap(t.from))} → ${esc(cap(t.to))}`}</b> ${oc.chip} ${oc.role}</div>
|
|
528
|
+
<span class="sub wrapc">${esc(gist)}${t.goalTitle ? ` <span class="quiet">· in ${esc(t.goalTitle)}</span>` : ""}</span>
|
|
529
|
+
${steps(stepSubs(t))}
|
|
530
|
+
<span class="sub">${esc(oc.text)}</span></div></li>`;
|
|
531
|
+
}).join("");
|
|
532
|
+
const carriedRows = f.carried.map((c) => `<tr><td class="span"><b class="who">${esc(cap(c.who))}</b><span class="sub">${esc(c.agent)}</span></td><td data-l="Asked" class="r num">${c.asked}</td><td data-l="Answered by">${split(c.byWorker, c.byPerson, c.asked, 110)}<span class="sub num">${c.byWorker} worker · ${c.byPerson} in person</span></td><td data-l="Median" class="r num">${c.medianMs !== null ? dur(c.medianMs) : `<span class="quiet">none</span>`}</td><td data-l="Open" class="r num">${c.open || `<span class="quiet">0</span>`}</td></tr>`).join("");
|
|
533
|
+
const memberRows = d.members.map((m) => {
|
|
534
|
+
const chips = [m.windows ? `<span class="chip plain">window · ${m.busy ? "busy" : m.busy === false ? "idle" : "open"}</span>` : "", m.worker ? `<span class="chip ${m.worker.state === "running" ? "" : m.worker.state === "unavailable" ? "line" : "plain"}">worker · ${esc(m.worker.state)}</span>` : ""].filter(Boolean).join(" ")
|
|
535
|
+
|| (m.online ? `<span class="chip plain">connected</span>` : `<span class="quiet">offline</span>`);
|
|
536
|
+
return `<tr><td class="span"><b class="who">${esc(cap(m.name))}</b>${m.founder ? ` <span class="chip plain">founder</span>` : ""}${m.admitted ? "" : ` <span class="chip line">waiting to be admitted</span>`}<span class="sub">${esc(m.agent || "agent unknown")}${m.mayWake ? "" : " · may not wake workers"}</span></td><td data-l="Connected now" class="span">${chips}${m.worker?.state === "unavailable" || m.worker?.state === "holding" ? `<span class="sub">${esc(workerWords(m.worker.reason))}</span>` : ""}</td><td data-l="Build">${m.build ? `<span class="mono">${esc(m.build)}</span><span class="sub">${m.behind ? "missed the self-upgrade" : "current"}</span>` : `<span class="quiet">unknown</span>`}</td><td data-l="Last seen">${m.online ? "now" : when(m.lastSeen, "full")}</td><td data-l="Delivered, not yet seen" class="r num">${m.unseen === null ? `<span class="quiet">no hooks</span>` : m.unseen ? m.unseen : `<span class="quiet">0</span>`}</td></tr>`;
|
|
537
|
+
}).join("");
|
|
538
|
+
const goalRows = f.goals.map((g) => `<tr><td class="span"><b>${esc(g.title)}</b>${g.worklist ? ` <span class="chip plain">worklist</span>` : ""}<span class="sub">${g.why ? esc(g.why) : g.closedAt ? `closed ${when(g.closedAt, "full")}` : ""}</span></td>
|
|
539
|
+
<td data-l="State">${g.state === "OPEN" ? `<span class="chip">open</span>` : g.state === "CLOSED" ? `<span class="chip plain">closed</span>` : g.state === "STALLED" ? `<span class="chip line">${SEAL} out of acts</span>` : `<span class="chip line">${SEAL} blocked</span>`}</td>
|
|
540
|
+
<td data-l="Acts used"><span class="meter"><i style="width:${Math.min(100, pct(g.acts, g.budget))}%"></i></span><span class="num">${g.acts} / ${g.budget}</span></td>
|
|
541
|
+
<td data-l="Deadline">${g.deadline ? `${when(g.deadline, "full")}${g.overdueMs !== null ? ` <span class="chip line">overdue ${dur(g.overdueMs)}</span>` : ""}` : `<span class="quiet">none</span>`}</td>
|
|
542
|
+
<td data-l="Open items" class="r num">${g.open || `<span class="quiet">0</span>`}</td></tr>`).join("");
|
|
543
|
+
const q = d.feed.q;
|
|
544
|
+
const feedLink = (extra) => {
|
|
545
|
+
const p = new URLSearchParams({ name: d.name });
|
|
546
|
+
if (d.days !== 7)
|
|
547
|
+
p.set("range", String(d.days));
|
|
548
|
+
for (const [k, v] of Object.entries({ act: q.act, member: q.member, goal: q.goal, q: q.q, presence: q.presence ? "1" : "", before: q.before, ...extra }))
|
|
549
|
+
if (v !== undefined && String(v) !== "")
|
|
550
|
+
p.set(k, String(v));
|
|
551
|
+
return `/admin/space?${p.toString()}`;
|
|
552
|
+
};
|
|
553
|
+
const feedRows = d.feed.rows.map((r) => {
|
|
554
|
+
const open = d.feed.read?.id === r.id;
|
|
555
|
+
const row = `<tr id="m-${esc(r.id)}"><td data-l="#" class="num muted">#${r.seq}</td><td data-l="When" class="num">${when(r.ts, "time")}</td><td data-l="From → to"><b class="who">${esc(r.from)}</b> → ${r.to?.length ? r.to.map(esc).join(", ") : "everyone"}<span class="sub">${r.from === "pantheon" ? `<span class="role">the relay</span>` : `<span class="role ${r.role === "worker" ? "w" : "p"}">${r.role === "worker" ? "worker" : r.role === "cli" ? "command line" : "window"}</span>`}</span></td><td data-l="Act"><span class="chip plain mono" data-act="${esc(r.act)}">${esc(r.act)}</span></td><td data-l="Summary" class="span wrapc">${esc(r.gist) || `<span class="quiet">(empty message)</span>`}${r.goalTitle ? `<span class="sub">in <a href="${esc(feedLink({ goal: r.goal ?? "", before: undefined, read: undefined }))}">${esc(r.goalTitle)}</a></span>` : ""}</td><td class="r hide-s">${open ? `<a class="more" href="${esc(feedLink({}))}#m-${esc(r.id)}">Show less</a>` : `<a class="more" href="${esc(feedLink({ read: r.id }))}#m-${esc(r.id)}">Read in full</a>`}</td></tr>`;
|
|
556
|
+
const full = open && d.feed.read ? `<tr class="detail"><td colspan="6" class="span"><div class="fullbody">${esc(d.feed.read.body) || `<span class="quiet">(empty message)</span>`}</div><div class="kv">${d.feed.read.kv.map(([k, v]) => `<span>${esc(k)}</span><b class="mono wrapc">${esc(v)}</b>`).join("")}</div><p class="note">Opening this message was logged.</p></td></tr>` : "";
|
|
557
|
+
return row + full;
|
|
558
|
+
}).join("");
|
|
559
|
+
const refRows = d.refusals.inRange.map((r) => `<tr><td><span class="mono">${esc(r.code)}</span><span class="sub">${esc(cap(r.last.member))} · ${esc(refusalWords(r.code))} · ${when(r.last.ts, "full")}</span></td><td class="r num">${r.n}</td></tr>`).join("");
|
|
560
|
+
const liveViewers = (d.viewers ?? []).filter((v) => !v.revokedAt && v.expiresAt > d.now);
|
|
561
|
+
const viewerRows = (d.viewers ?? []).map((v) => {
|
|
562
|
+
const ended = v.revokedAt ? `revoked ${when(v.revokedAt, "date")}${v.revokedBy ? ` by ${esc(v.revokedBy)}` : ""}` : v.expiresAt <= d.now ? `expired ${when(v.expiresAt, "date")}` : null;
|
|
563
|
+
return `<tr><td><b class="who wrapc">${esc(v.email)}</b><span class="sub">granted by ${esc(v.grantedBy)} ${when(v.grantedAt, "date")} · ${ended ?? `expires ${when(v.expiresAt, "date")}`} · ${v.lastView ? `last view ${when(v.lastView, "full")}` : "never opened"}</span></td><td class="r">${ended ? `<span class="chip plain">${v.revokedAt ? "revoked" : "expired"}</span>` : actionForm(d.csrf, "revoke_viewer", v.id, `<input type="hidden" name="space" value="${esc(d.name)}"><button class="iconbtn">Revoke</button>`, { confirm: `End ${v.email}'s access to ${d.name} now? The team is told.` })}</td></tr>`;
|
|
564
|
+
}).join("");
|
|
565
|
+
const grantForm = actionForm(d.csrf, "grant_viewer", d.name, `<label>Email<input class="field" type="email" name="email" required placeholder="name@company.com" aria-label="Viewer's email" style="width:220px"></label><label>Days<input class="field" type="number" name="days" min="1" max="365" value="90" aria-label="Days of access"></label><button class="btn">Add viewer</button>`, { cls: "filters", confirm: `Give read-only access to ${d.name}? The team is told in a note.` });
|
|
566
|
+
return page({
|
|
567
|
+
title: `${d.name} · Pantheon relay admin`, description: "Operator view of one team: open requests, hand-offs, who carries the work, members and their builds.", nonce: d.nonce,
|
|
568
|
+
body: `${topbar({ crumbs: `<a href="/admin">Relay admin</a><span class="sep">/</span><a href="/admin#teams">Teams</a><span class="sep">/</span><b style="color:var(--text)">${esc(d.name)}</b>` })}
|
|
569
|
+
<main id="main">
|
|
570
|
+
${d.done ? `<div class="flash" role="status">${esc(d.done)}</div>` : ""}
|
|
571
|
+
<div class="sechead" style="margin-top:24px;margin-bottom:4px">
|
|
572
|
+
<h1>${esc(d.name)}</h1>${verdictChip(d.verdict)}${d.live ? "" : ` <span class="chip plain">sleeping</span>`}
|
|
573
|
+
<p>${d.owner ? `owner <span class="mono">${esc(d.owner)}</span> · ` : ""}${d.plan ? `${esc(d.plan)} plan · ` : ""}${admitted.length}${d.peopleLimit !== null ? ` of ${d.peopleLimit}` : ""} people${d.id ? ` · team id <span class="mono">${esc(d.id)}</span>` : ""}${d.createdAt ? ` · since ${when(d.createdAt, "date")}` : ""}</p>
|
|
574
|
+
<div class="end">${rangeSeg((n) => `/admin/space?name=${enc}&range=${n}`, d.days)}</div>
|
|
575
|
+
</div>
|
|
576
|
+
<nav class="tabs" aria-label="Team sections" style="margin-top:10px;border-bottom:1px solid var(--line)">
|
|
577
|
+
<a href="#open" aria-current="page">Work</a><a href="#people">People</a><a href="#goals">Goals</a><a href="#conversation">Messages</a>${d.viewers ? `<a href="#viewers">Viewers<span class="n">${liveViewers.length}</span></a>` : ""}<a href="#settings">Invites and settings</a>
|
|
578
|
+
</nav>
|
|
579
|
+
|
|
580
|
+
<div class="tiles">
|
|
581
|
+
<div class="tile"><div class="l">Requests handed off</div><div class="v">${f.asks}${f.partial ? `<small>partial</small>` : ""}</div><div class="d">${f.partial ? `since ${when(f.historyFrom, "full")}` : range.replace(/^in /, "")}</div></div>
|
|
582
|
+
<div class="tile"><div class="l">Answered</div><div class="v">${f.answered}${f.asks ? `<small>${pct(f.answered, f.asks)}%</small>` : ""}</div><div class="d">${f.medianAnswerMs !== null ? `median ${dur(f.medianAnswerMs)}${f.medianWorkerMs !== null ? ` · worker ${dur(f.medianWorkerMs)}` : ""}${f.medianPersonMs !== null ? `, person ${dur(f.medianPersonMs)}` : ""}` : "nothing answered yet"}</div></div>
|
|
583
|
+
<div class="tile"><div class="l">Answered by a worker</div>${f.answered ? `<div class="v">${pct(f.answeredByWorker, f.answered)}%</div><div class="d">${f.answeredByWorker} of ${plural(f.answered, "answer")} came from a person's worker${f.medianPickupMs !== null ? ` · picked up in ${dur(f.medianPickupMs)}` : ""}</div>` : `<div class="v">none yet</div><div class="d">nothing answered ${range}</div>`}</div>
|
|
584
|
+
<div class="tile"><div class="l">Delivered</div><div class="v">${f.delivered}</div><div class="d">each naming a branch and commit</div></div>
|
|
585
|
+
${d.stateNote?.kind === "rebuild" ? `<div class="tile"><div class="l">Open right now</div><div class="v">not shown</div><div class="d">saved state needs a rebuild</div></div>
|
|
586
|
+
<div class="tile call"><div class="l">${SEAL} Waiting on a person</div><div class="v">not shown</div><div class="d">rebuilds when a member connects</div></div>` : `<div class="tile"><div class="l">Open right now</div><div class="v">${f.open.length}</div><div class="d">${f.open.length ? `oldest ${dur(f.oldestOpenMs)}` : "nothing owed"}${d.live && asOfHtml(d.asOf, d.now) ? ` · ${asOfHtml(d.asOf, d.now)}` : ""}</div></div>
|
|
587
|
+
<div class="tile call"><div class="l">${SEAL} Waiting on a person</div><div class="v">${f.waiting.length}</div><div class="d">${waitingText || "no decision waiting"}</div></div>`}
|
|
588
|
+
</div>
|
|
589
|
+
|
|
590
|
+
${f.historyFrom ? `<p class="note">Partial: counts start ${when(f.historyFrom, "full")}. Older history in this range was compacted (old acts of closed goals are dropped), so asks, answers and hand-offs before then are not counted.</p>` : ""}
|
|
591
|
+
${stateNoteHtml(d.stateNote)}
|
|
592
|
+
<section class="sec" id="open" aria-labelledby="h-open">
|
|
593
|
+
<div class="sechead"><h2 id="h-open">Open right now</h2><p>everything someone owes, oldest first, and what their machine says about it</p></div>
|
|
594
|
+
<div class="card"><table class="rt">
|
|
595
|
+
<thead><tr><th>Owed</th><th>Goal</th><th>Waiting</th><th>Right now</th></tr></thead>
|
|
596
|
+
<tbody>${openRows || `<tr><td colspan="4" class="empty">${d.stateNote?.kind === "rebuild" ? NOT_SHOWN : "Nothing is owed right now."}</td></tr>`}</tbody>
|
|
597
|
+
</table></div>
|
|
598
|
+
${f.open.length > openShown.length ? `<p class="note">The oldest ${openShown.length} of ${f.open.length} are shown, and ${f.open.length - openShown.length} more. <a href="/admin/space?name=${enc}${d.days !== 7 ? `&range=${d.days}` : ""}&open=all#open">Show all ${f.open.length}</a> (a long page).</p>` : ""}
|
|
599
|
+
</section>
|
|
600
|
+
|
|
601
|
+
<div class="grid2 sec">
|
|
602
|
+
<section class="card" aria-labelledby="h-hand">
|
|
603
|
+
<div class="sechead cardhead" style="margin-bottom:4px"><h2 id="h-hand">Recent hand-offs</h2><p>newest first</p></div>
|
|
604
|
+
<ul class="list">${handoffRows || `<li class="none"><div class="t">No hand-offs ${range}.</div></li>`}</ul>
|
|
605
|
+
</section>
|
|
606
|
+
<div class="stack">
|
|
607
|
+
<section class="card pad" aria-labelledby="h-daily">
|
|
608
|
+
<div class="sechead" style="margin-bottom:4px"><h2 id="h-daily">Messages per day</h2><p>the last 14 UTC days</p></div>
|
|
609
|
+
${stackedColumns({ days: d.series14, width: 520, height: 170, step: 3, label: `Messages per day for 14 days. ${f.messages.total} ${range}, ${f.messages.worker} by workers.` })}
|
|
610
|
+
</section>
|
|
611
|
+
<section class="card" aria-labelledby="h-carry">
|
|
612
|
+
<div class="sechead cardhead" style="margin-bottom:0"><h2 id="h-carry">Who was asked, and who answered</h2></div>
|
|
613
|
+
<table class="rt"><thead><tr><th>Asked of</th><th class="r">Asked</th><th>Answered by</th><th class="r">Median</th><th class="r">Open</th></tr></thead><tbody>${carriedRows || `<tr><td colspan="5" class="empty">Nobody was asked anything ${range}.</td></tr>`}</tbody></table>
|
|
614
|
+
</section>
|
|
615
|
+
</div>
|
|
616
|
+
</div>
|
|
617
|
+
|
|
618
|
+
<section class="sec" id="people" aria-labelledby="h-people">
|
|
619
|
+
<div class="sechead"><h2 id="h-people">People</h2><p>${admitted.length} admitted · ${plural(d.pending, "waiting to be admitted", "waiting to be admitted")} · ${plural(d.invites.length, "unused invite")}</p></div>
|
|
620
|
+
<div class="card"><table class="rt">
|
|
621
|
+
<thead><tr><th>Member</th><th>Connected now</th><th>Build</th><th>Last seen</th><th class="r">Delivered, not yet seen</th></tr></thead>
|
|
622
|
+
<tbody>${memberRows || `<tr><td colspan="5" class="empty">Nobody yet.</td></tr>`}</tbody>
|
|
623
|
+
</table></div>
|
|
624
|
+
<p class="note">"Delivered, not yet seen" counts acts the relay pushed to a member's machine that their wake-up hook has not reported reaching an agent, for example because the agent is mid-turn.</p>
|
|
625
|
+
</section>
|
|
626
|
+
|
|
627
|
+
<section class="sec" id="goals" aria-labelledby="h-goals">
|
|
628
|
+
<div class="sechead"><h2 id="h-goals">Goals</h2><p>${d.stateNote?.kind === "rebuild" ? "not shown until this team rebuilds" : `${f.goals.filter((g) => g.state !== "CLOSED").length} open · ${f.goals.filter((g) => g.state === "CLOSED").length} closed ${range}`}</p></div>
|
|
629
|
+
<div class="card"><table class="rt">
|
|
630
|
+
<thead><tr><th>Goal</th><th>State</th><th>Acts used</th><th>Deadline</th><th class="r">Open items</th></tr></thead>
|
|
631
|
+
<tbody>${goalRows || `<tr><td colspan="5" class="empty">${d.stateNote?.kind === "rebuild" ? NOT_SHOWN : "No goals."}</td></tr>`}</tbody>
|
|
632
|
+
</table></div>
|
|
633
|
+
</section>
|
|
634
|
+
|
|
635
|
+
<div class="grid2 sec">
|
|
636
|
+
<section id="conversation" aria-labelledby="h-msg">
|
|
637
|
+
<div class="sechead"><h2 id="h-msg">Messages</h2><p>one-line summaries, newest first · opening a full message is logged</p></div>
|
|
638
|
+
<form class="filters" method="GET" action="/admin/space"><input type="hidden" name="name" value="${esc(d.name)}">${d.days !== 7 ? `<input type="hidden" name="range" value="${d.days}">` : ""}
|
|
639
|
+
<label>Type<select class="field" name="act"><option value="">All types</option>${d.feed.acts.map((x) => `<option value="${x}"${q.act === x ? " selected" : ""}>${x}</option>`).join("")}</select></label>
|
|
640
|
+
<label>Member<input class="field" type="text" name="member" placeholder="Anyone" value="${esc(q.member)}" size="10"></label>
|
|
641
|
+
<label>Words<input class="field" type="search" name="q" placeholder="Find words" value="${esc(q.q)}" size="16"></label>
|
|
642
|
+
<label class="chk"><input type="checkbox" name="presence" value="1"${q.presence ? " checked" : ""}> arrivals and departures</label>
|
|
643
|
+
${q.goal ? `<input type="hidden" name="goal" value="${esc(q.goal)}">` : ""}
|
|
644
|
+
<button class="btn">Apply</button>${d.feed.filtered ? `<a href="/admin/space?name=${enc}">Clear filters</a>` : ""}
|
|
645
|
+
</form>
|
|
646
|
+
<div class="card"><table class="rt" id="t-messages">
|
|
647
|
+
<thead><tr><th>#</th><th>When</th><th>From → to</th><th>Act</th><th>Summary</th><th></th></tr></thead>
|
|
648
|
+
<tbody>${feedRows || `<tr><td colspan="6" class="empty">${d.feed.filtered ? "No messages match these filters. Try other words, or clear the filters." : "No messages yet. They appear here when this team's agents start working together."}</td></tr>`}</tbody>
|
|
649
|
+
</table></div>
|
|
650
|
+
<p class="note">${q.before ? `<a href="${esc(feedLink({ before: undefined }))}">Latest messages</a> · ` : ""}${d.feed.next !== null ? `<a href="${esc(feedLink({ before: d.feed.next }))}">Older messages</a> · ` : ""}${d.retained.toLocaleString("en")} acts retained: the most recent 5,000 plus everything in an open goal.</p>
|
|
651
|
+
</section>
|
|
652
|
+
<section aria-labelledby="h-ref">
|
|
653
|
+
<div class="sechead"><h2 id="h-ref">Refused by the relay</h2><p>${d.refusals.inRange.reduce((n, r) => n + r.n, 0)} ${range} · ${d.refusals.total} all time</p></div>
|
|
654
|
+
<div class="card"><table><tbody>${refRows || `<tr><td class="empty">Nothing refused ${range}.</td></tr>`}</tbody></table></div>
|
|
655
|
+
${d.viewers ? `<div class="sechead" style="margin-top:22px" id="viewers"><h2>Read-only viewers</h2><p>people who can see this team's flow, never its messages</p></div>
|
|
656
|
+
<div class="card"><table><tbody>${viewerRows || `<tr><td class="empty">Nobody has read-only access.</td></tr>`}</tbody></table></div>
|
|
657
|
+
<div style="margin-top:12px">${grantForm}</div>
|
|
658
|
+
<p class="note">A viewer signs in at /view with a code emailed to them and sees who handed work to whom, when, and what waits on whom. Never message text, code, files, branches or commits. Access ends on the date set (90 days unless you say, 365 at most), or at once when revoked. Every grant and revoke posts a note in the team, and every visit is in the audit log.</p>` : ""}
|
|
659
|
+
</section>
|
|
660
|
+
</div>
|
|
661
|
+
|
|
662
|
+
<section class="sec" id="settings" aria-labelledby="h-set">
|
|
663
|
+
<div class="sechead"><h2 id="h-set">Invites and settings</h2></div>
|
|
664
|
+
<div class="card">${d.invites.length ? `<table class="rt"><thead><tr><th>Invite</th><th>Minted by</th><th>Expires</th><th>May wake</th><th></th></tr></thead><tbody>${d.invites.map((i) => `<tr><td data-l="Invite" class="mono">…${esc(i.tail)}</td><td data-l="Minted by" class="mono">${esc(i.by)}</td><td data-l="Expires">${when(i.expires, "full")}</td><td data-l="May wake">${i.mayWake ? "yes" : "no"}</td><td class="r menu-s">${actionForm(d.csrf, "revoke_invite", d.name, `<input type="hidden" name="token" value="${esc(i.tail)}"><button class="btn">Revoke</button>`, { confirm: "Revoke this invite? The link stops working at once." })}</td></tr>`).join("")}</tbody></table>` : ""}
|
|
665
|
+
<div class="card pad" style="display:flex;gap:24px;flex-wrap:wrap;align-items:center;border:0;box-shadow:none;background:transparent">
|
|
666
|
+
<span>Open invites <b>${d.invites.length}</b> <span class="muted">(${d.invites.length} unused)</span></span><span>Repos <b>${d.repos.length}</b>${d.repos.length ? ` <span class="muted">(${d.repos.slice(0, 3).map((r) => esc(r.origin ?? r.fingerprint)).join(", ")}${d.repos.length > 3 ? ", …" : ""})</span>` : ""}</span>
|
|
667
|
+
<span class="muted">Deleting a team disconnects every member and cannot be undone.</span>
|
|
668
|
+
<span style="margin-left:auto">${actionForm(d.csrf, "delete_space", d.name, `<input type="hidden" name="confirm" value=""><button class="iconbtn">Delete team…</button>`, { typeToConfirm: d.name, confirm: `Delete the team "${d.name}" and disconnect its members? Type its name to confirm.` })}</span>
|
|
669
|
+
</div></div>
|
|
670
|
+
</section>
|
|
671
|
+
</main>`,
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
//# sourceMappingURL=admin-pages.js.map
|