Hub 2.19.0: the server agent's releases; Update agent picks one

- AgentRelease (migration 20261123150000_agent_release): the agent's releases, apart from the
  products' so licences and billing are untouched.
- Release sources can be for the Server agent; the defaults include it (monorepo agent@ tags,
  apps/agent/WHATS-NEW.md). Same sync rules as products. A saved list without it gets an
  "Add the agent's source" button on the Releases page.
- GET /api/admin/agent-releases; server summaries carry agentLatest; update-agent jobs go to a
  known agent release, the latest when none is asked for (agentTag).
- Update agent is a ReleaseSelect with the chosen version's notes; the Servers list and a server's
  page say when a newer agent is out; the Releases page shows agent releases (Server agent filter,
  Everything newest first by date).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-23 13:18:56 +02:00
co-authored by Claude Opus 5.5
parent 44fac310eb
commit 65637711c6
19 changed files with 292 additions and 50 deletions
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "events-hub-frontend",
"version": "2.18.0",
"version": "2.19.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "events-hub-frontend",
"version": "2.18.0",
"version": "2.19.0",
"dependencies": {
"lucide-react": "^0.536.0",
"next": "^15.5.24",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "events-hub-frontend",
"version": "2.18.0",
"version": "2.19.0",
"private": true,
"scripts": {
"dev": "next dev -p 3200",
+56 -13
View File
@@ -5,14 +5,18 @@ import { GitBranch, Link2, Pencil, Plus, RefreshCw, ShieldAlert, Trash2 } from "
import { api, errorText } from "@/lib/api";
import { ago, fmtDate } from "@/lib/format";
import { PRODUCTS, PRODUCT_NAMES, type Product } from "@/lib/products";
import type { Release, ReleaseSource } from "@/lib/types";
import type { AgentRelease, Release, ReleaseSource } from "@/lib/types";
import { usePaged } from "@/lib/paging";
import { Badge, FormError, Loading, Modal, ModalButtons, PageMessage, PageTitle, Pager, ReadCard, ReleaseNotes, useSubmit } from "@/components/ui";
type Msg = { type: "ok" | "err"; text: string } | null;
type Target = ReleaseSource["product"];
type Filter = Target | "all";
type Form = { product: Product; version: string; notes: string; urgent: boolean; releasedAt: string };
const today = () => new Date().toISOString().slice(0, 10);
/** Hub 2.19.0: a product's name, or "Server agent". */
const targetName = (p: Target) => (p === "agent" ? "Server agent" : PRODUCT_NAMES[p]);
const toBody = (f: Form) => ({ product: f.product, version: f.version, notes: f.notes, urgent: f.urgent, releasedAt: f.releasedAt ? `${f.releasedAt}T12:00:00+02:00` : null });
/**
@@ -96,8 +100,9 @@ function SourcesModal({ sources, tokenSet, onClose, onSaved }: { sources: Releas
<div key={i} className="grid items-end gap-2 rounded-lg border border-slate-200 p-3 sm:grid-cols-[10rem_1fr_auto]">
<div>
<label className="label" htmlFor={`src_product_${i}`}>Product</label>
<select id={`src_product_${i}`} className="input" value={r.product} onChange={e => set(i, { product: e.target.value as Product })}>
<select id={`src_product_${i}`} className="input" value={r.product} onChange={e => set(i, { product: e.target.value as Target })}>
{PRODUCTS.map(p => <option key={p} value={p}>{PRODUCT_NAMES[p]}</option>)}
<option value="agent">Server agent</option>
</select>
</div>
<div><label className="label" htmlFor={`src_repo_${i}`}>Repository</label><input id={`src_repo_${i}`} className="input" value={r.repo} onChange={e => set(i, { repo: e.target.value })} placeholder="https://c-git.crosscode.co.za/joshua/crosscode-platform" required /></div>
@@ -125,7 +130,7 @@ function SourcesModal({ sources, tokenSet, onClose, onSaved }: { sources: Releas
* Where releases come from: per product, one or more git sources (a repository, a tag prefix and a
* notes file), synced every 15 minutes. Hub 2.16.0: a read view; Edit opens the popup.
*/
function Sources({ sources, state, onSaved, setMsg }: { sources: ReleaseSource[]; state: SyncState; onSaved: () => void; setMsg: (m: Msg) => void }) {
function Sources({ sources, agentSource, state, onSaved, setMsg }: { sources: ReleaseSource[]; agentSource: ReleaseSource | null; state: SyncState; onSaved: () => void; setMsg: (m: Msg) => void }) {
const [busy, setBusy] = useState(false);
const [editing, setEditing] = useState(false);
const saved = !!state.release_sources?.trim();
@@ -141,6 +146,13 @@ function Sources({ sources, state, onSaved, setMsg }: { sources: ReleaseSource[]
onSaved();
};
// Hub 2.19.0: a saved list from before has no source for the agent; one click adds it.
const addAgent = async () => {
if (!agentSource) return;
setMsg(null);
try { await saveSources([...sources, agentSource]); await syncNow("Added the agent's source and synced"); } catch (e) { setMsg({ type: "err", text: errorText(e) }); }
};
const useDefaults = async () => {
if (!confirm("Go back to the default sources? Your list is removed.")) return;
setMsg(null);
@@ -156,6 +168,7 @@ function Sources({ sources, state, onSaved, setMsg }: { sources: ReleaseSource[]
<button type="button" className="btn-secondary px-2.5 py-1.5" disabled={busy} onClick={() => { setMsg(null); syncNow(); }}>
<RefreshCw className={`h-3.5 w-3.5 ${busy ? "animate-spin" : ""}`} /> Sync now
</button>
{saved && agentSource && !sources.some(s => s.product === "agent") && <button type="button" className="btn-secondary px-2.5 py-1.5" disabled={busy} onClick={addAgent}><Plus className="h-3.5 w-3.5" /> Add the agent&apos;s source</button>}
{saved && <button type="button" className="btn-secondary px-2.5 py-1.5" disabled={busy} onClick={useDefaults}>Use the defaults</button>}
</>}
>
@@ -169,7 +182,7 @@ function Sources({ sources, state, onSaved, setMsg }: { sources: ReleaseSource[]
<table className="w-full text-sm">
<thead className="text-left text-xs text-slate-500"><tr><th className="py-1 pr-3">Product</th><th className="pr-3">Repository</th><th className="pr-3">Tag prefix</th><th>Notes file</th></tr></thead>
<tbody>{sources.map((r, i) => (
<tr key={i} className="border-t border-slate-100"><td className="py-1.5 pr-3">{PRODUCT_NAMES[r.product]}</td><td className="break-all pr-3">{r.repo}</td><td className="pr-3 font-mono">{r.tagPrefix || "—"}</td><td className="font-mono">{r.notesPath || "—"}</td></tr>
<tr key={i} className="border-t border-slate-100"><td className="py-1.5 pr-3">{targetName(r.product)}</td><td className="break-all pr-3">{r.repo}</td><td className="pr-3 font-mono">{r.tagPrefix || "—"}</td><td className="font-mono">{r.notesPath || "—"}</td></tr>
))}</tbody>
</table>
</div>
@@ -185,24 +198,50 @@ function Sources({ sources, state, onSaved, setMsg }: { sources: ReleaseSource[]
);
}
type Item = { kind: "product"; r: Release } | { kind: "agent"; r: AgentRelease };
/** Hub 2.19.0: a release of the server agent: from git only, so no Edit or Delete. */
function AgentReleaseCard({ r }: { r: AgentRelease }) {
return (
<div className="card">
<div className="mb-2 flex flex-wrap items-center gap-2">
<h2 className="text-lg font-semibold"><span className="text-slate-500">Server agent</span> {r.version}</h2>
{r.latest && <Badge value="ok" label="Latest" />}
{r.urgent && <span className="inline-flex items-center gap-1 rounded-full bg-red-50 px-2 py-0.5 text-xs font-medium text-red-700 ring-1 ring-inset ring-red-200"><ShieldAlert className="h-3 w-3" /> Urgent</span>}
<span className="text-xs text-slate-500">{fmtDate(r.releasedAt, false)} · {r.servers} server{r.servers === 1 ? "" : "s"} on it</span>
</div>
{r.notes ? <ReleaseNotes notes={r.notes} /> : <p className="text-sm text-slate-500">No notes for this version.</p>}
</div>
);
}
/** Each product's versions and what's new in each. A product's newest is the latest version its installs are offered. */
export default function ReleasesPage() {
const [releases, setReleases] = useState<Release[] | null>(null);
const [msg, setMsg] = useState<Msg>(null);
// Hub 2.16.0: the popup that's open: a new release, or the id of the one being edited.
const [open, setOpen] = useState<"new" | string | null>(null);
const [filter, setFilter] = useState<Product | "all">("all");
const [state, setState] = useState<{ settings: SyncState; releaseSources: ReleaseSource[] } | null>(null);
const [filter, setFilter] = useState<Filter>("all");
const [state, setState] = useState<{ settings: SyncState; releaseSources: ReleaseSource[]; agentSource?: ReleaseSource } | null>(null);
// Hub 2.19.0: the server agent's releases, shown with the products'.
const [agentReleases, setAgentReleases] = useState<AgentRelease[]>([]);
const load = useCallback(() => {
api<Release[]>("/api/admin/releases").then(setReleases).catch(e => setMsg({ type: "err", text: errorText(e) }));
api<AgentRelease[]>("/api/admin/agent-releases").then(setAgentReleases).catch(() => {});
api<{ settings: SyncState; releaseSources: ReleaseSource[] }>("/api/admin/settings").then(setState).catch(() => {});
}, []);
useEffect(() => { load(); }, [load]);
const fromGit = useMemo(() => new Set((state?.releaseSources || []).map(s => s.product)), [state]);
const manual = PRODUCTS.filter(p => !fromGit.has(p));
const shown = (releases || []).filter(r => filter === "all" || r.product === filter);
// Hub 2.19.0: the products' releases and the agent's in one list; All is newest first by date.
const shown = useMemo<Item[]>(() => {
const products: Item[] = filter === "agent" ? [] : (releases || []).filter(r => filter === "all" || r.product === filter).map(r => ({ kind: "product", r }));
const agents: Item[] = filter === "all" || filter === "agent" ? agentReleases.map(r => ({ kind: "agent", r })) : [];
const all = [...products, ...agents];
return filter === "all" ? all.sort((a, b) => new Date(b.r.releasedAt).getTime() - new Date(a.r.releasedAt).getTime()) : all;
}, [releases, agentReleases, filter]);
// Hub 2.6.0: a page at a time.
const paged = usePaged(shown, filter, 15);
const editing = open && open !== "new" ? releases?.find(r => r.id === open) || null : null;
@@ -225,7 +264,7 @@ export default function ReleasesPage() {
actions={state && manual.length > 0 && <button className="btn-primary" onClick={() => setOpen("new")}><Plus className="h-4 w-4" /> Add release</button>}
/>
<PageMessage msg={msg} onClose={() => setMsg(null)} />
{state && <Sources sources={state.releaseSources} state={state.settings} onSaved={load} setMsg={setMsg} />}
{state && <Sources sources={state.releaseSources} agentSource={state.agentSource || null} state={state.settings} onSaved={load} setMsg={setMsg} />}
{open === "new" && manual.length > 0 && (
<ReleaseModal initial={{ product: manual[0], version: "", notes: "", urgent: false, releasedAt: today() }} products={manual} onClose={() => setOpen(null)} onSaved={saved} />
)}
@@ -234,16 +273,19 @@ export default function ReleasesPage() {
)}
<div className="mb-4 flex flex-wrap gap-2" role="group" aria-label="Show releases of">
{(["all", ...PRODUCTS] as const).map(p => (
{(["all", ...PRODUCTS, "agent"] as const).map(p => (
<button key={p} type="button" className={filter === p ? "btn-primary px-3 py-1 text-xs" : "btn-secondary px-3 py-1 text-xs"} aria-pressed={filter === p} onClick={() => setFilter(p)}>
{p === "all" ? "All products" : PRODUCT_NAMES[p]}
{p === "all" ? "Everything" : targetName(p)}
</button>
))}
</div>
{!releases ? <Loading /> : shown.length === 0 ? <p className="text-sm text-slate-500">No releases yet{filter === "all" ? "" : ` for ${PRODUCT_NAMES[filter]}`}.</p> : (
{!releases ? <Loading /> : shown.length === 0 ? <p className="text-sm text-slate-500">No releases yet{filter === "all" ? "" : ` for ${targetName(filter)}`}.</p> : (
<div className="space-y-4">
{paged.rows.map(r => (
{paged.rows.map(item => {
if (item.kind === "agent") return <AgentReleaseCard key={`agent-${item.r.id}`} r={item.r} />;
const r = item.r;
return (
<div key={r.id} className="card">
<div className="mb-2 flex flex-wrap items-center gap-2">
<h2 className="text-lg font-semibold"><span className="text-slate-500">{PRODUCT_NAMES[r.product]}</span> {r.version}</h2>
@@ -264,7 +306,8 @@ export default function ReleasesPage() {
</div>
<ReleaseNotes notes={r.notes} />
</div>
))}
);
})}
<div className="card p-0"><Pager {...paged} /></div>
</div>
)}
+27 -8
View File
@@ -7,8 +7,10 @@ import { Plus, Trash2, Upload } from "lucide-react";
import { api, errorText } from "@/lib/api";
import { ago, bytes, fmtDate } from "@/lib/format";
import { useServerPaged } from "@/lib/paging";
import { Field, Fields, FormError, Loading, Message, Modal, ModalButtons, PageMessage, PageTitle, Pager, ReadCard, useSubmit } from "@/components/ui";
import { PercentChart, ServersNav, StatusPill, pct, type Deployment, type Job, type ServerSummary } from "@/components/servers";
import { Field, Fields, FormError, Loading, Message, Modal, ModalButtons, PageMessage, PageTitle, Pager, ReadCard, ReleaseNotes, useSubmit } from "@/components/ui";
import { PercentChart, ServersNav, StatusPill, agentUpdate, pct, type Deployment, type Job, type ServerSummary } from "@/components/servers";
import { ReleaseSelect } from "@/components/ReleaseSelect";
import type { AgentRelease } from "@/lib/types";
import { FrpConfig, type FrpState } from "@/components/FrpConfig";
type Msg = { type: "ok" | "err"; text: string } | null;
@@ -69,17 +71,34 @@ function ConfigModal({ id, config, onClose, onSaved }: { id: string; config: Rec
);
}
/** Hub 2.17.0: Update agent in a popup; queuing it opens the job. */
/**
* Hub 2.17.0: Update agent in a popup; queuing it opens the job. 2.19.0: the version is picked from
* the agent's releases (Latest by default; the one running here can't be picked), with its notes.
*/
function UpdateAgentModal({ current, onClose, queue }: { current: string | null; onClose: () => void; queue: (version: string) => Promise<void> }) {
const [version, setVersion] = useState("");
const [releases, setReleases] = useState<AgentRelease[] | null>(null);
const { busy, error, run } = useSubmit();
useEffect(() => { api<AgentRelease[]>("/api/admin/agent-releases").then(setReleases).catch(() => setReleases([])); }, []);
const chosen = releases?.find(r => (version ? r.version === version : r.latest)) || null;
const nothingNew = !version && !!chosen && chosen.version === current;
return (
<Modal title="Update agent" onClose={onClose} dirty={version.trim() !== ""}>
<form onSubmit={e => { e.preventDefault(); run(() => queue(version.trim())); }} className="space-y-3">
<Modal title="Update agent" onClose={onClose} dirty={version !== ""} wide>
<form onSubmit={e => { e.preventDefault(); run(() => queue(version ? `agent@${version}` : "")); }} className="space-y-3">
<p className="text-sm text-slate-600">The agent here is {current || "an unknown version"}. The new version is queued as a job on this server.</p>
<div><label className="label" htmlFor="agent-version">Version</label><input id="agent-version" className="input font-mono" placeholder="agent@1.0.1" value={version} onChange={e => setVersion(e.target.value)} required /></div>
<div>
<label className="label" htmlFor="agent-version">Version</label>
{!releases ? <Loading /> : <ReleaseSelect id="agent-version" releases={releases} value={version} onChange={setVersion} current={current} currentPickable={false} />}
</div>
{chosen && (
<div className="max-h-64 overflow-y-auto rounded-lg border border-slate-200 bg-slate-50 p-3">
<div className="mb-1 text-xs font-medium text-slate-500">What&apos;s new in {chosen.version}{chosen.urgent ? " (urgent)" : ""}</div>
{chosen.notes ? <ReleaseNotes notes={chosen.notes} /> : <p className="text-sm text-slate-500">No notes for this version.</p>}
</div>
)}
{nothingNew && <p className="text-sm text-slate-500">This server already runs the latest agent.</p>}
<FormError error={error} />
<ModalButtons busy={busy} onCancel={onClose} label="Update agent" busyLabel="Queuing…" />
<ModalButtons busy={busy} onCancel={onClose} label="Update agent" busyLabel="Queuing…" disabled={nothingNew} />
</form>
</Modal>
);
@@ -116,7 +135,7 @@ export default function ServerPage() {
return (
<div className="space-y-6">
<div>
<PageTitle title={s.name} subtitle={<>{s.mode === "central" ? "Central server" : "Church server"} · {s.hostname} · agent {s.agentVersion} · last heard {ago(s.lastSeenAt)} <StatusPill status={s.busy ? "busy" : s.online ? "online" : "offline"} /></>} />
<PageTitle title={s.name} subtitle={<>{s.mode === "central" ? "Central server" : "Church server"} · {s.hostname} · agent {s.agentVersion}{agentUpdate(s) && <span className="font-medium text-amber-700"> ({agentUpdate(s)} available)</span>} · last heard {ago(s.lastSeenAt)} <StatusPill status={s.busy ? "busy" : s.online ? "online" : "offline"} /></>} />
<ServersNav active="/servers" />
<PageMessage msg={msg} onClose={() => setMsg(null)} />
</div>
+2 -2
View File
@@ -7,7 +7,7 @@ import { api, errorText } from "@/lib/api";
import { ago, bytes } from "@/lib/format";
import { usePaged } from "@/lib/paging";
import { FormError, Loading, Modal, ModalButtons, PageMessage, PageTitle, Pager, useSubmit } from "@/components/ui";
import { ServersNav, StatusPill, pct, type ServerSummary } from "@/components/servers";
import { ServersNav, StatusPill, agentUpdate, pct, type ServerSummary } from "@/components/servers";
type Msg = { type: "ok" | "err"; text: string } | null;
@@ -86,7 +86,7 @@ export default function ServersPage() {
<div className="flex items-start justify-between gap-2">
<div>
<div className="font-medium">{s.name}</div>
<div className="text-xs text-slate-500">{s.mode === "central" ? "Central server" : "Church server"} · {s.hostname || "?"} · agent {s.agentVersion || "?"}</div>
<div className="text-xs text-slate-500">{s.mode === "central" ? "Central server" : "Church server"} · {s.hostname || "?"} · agent {s.agentVersion || "?"}{agentUpdate(s) && <span className="font-medium text-amber-700"> · {agentUpdate(s)} available</span>}</div>
</div>
<StatusPill status={s.busy ? "busy" : s.online ? "online" : "offline"} />
</div>
+8
View File
@@ -2,11 +2,14 @@
import React, { useMemo, useRef, useState } from "react";
import { fmtDate } from "@/lib/format";
import { compareVersions } from "@/components/ReleaseSelect";
/** Shared pieces for the servers pages (2.1.0). */
export type ServerSummary = {
id: string; name: string; mode: "church" | "central"; hostname: string | null; agentVersion: string | null;
/** Hub 2.19.0: the newest agent release (null: none known). */
agentLatest?: string | null;
lastSeenAt: string | null; joinedAt: string; removedAt: string | null; notes: string | null; online: boolean; busy?: boolean;
ram: { totalBytes: number; availableBytes: number; usedPercent: number } | null;
cpu: { percent: number; load1: number; cores: number } | null;
@@ -173,3 +176,8 @@ export function ServersNav({ active }: { active: string }) {
</nav>
);
}
/** Hub 2.19.0: the newer agent release this server could update to, or null. */
export function agentUpdate(s: Pick<ServerSummary, "agentVersion" | "agentLatest">): string | null {
return s.agentLatest && s.agentVersion && compareVersions(s.agentLatest, s.agentVersion) > 0 ? s.agentLatest : null;
}
+4 -1
View File
@@ -86,7 +86,10 @@ export type AiInstallUse = { installId: string; name: string; url: string; produ
export type ReleaseRequirement = { product: Product; version: string };
export type Release = { id: string; product: Product; version: string; notes: string; urgent: boolean; requires: ReleaseRequirement[]; releasedAt: string; latest: boolean; installs: number };
export type ReleaseSource = { product: Product; repo: string; tagPrefix: string; notesPath: string };
/** Hub 2.19.0: a source is for a product or the server agent. */
export type ReleaseSource = { product: Product | "agent"; repo: string; tagPrefix: string; notesPath: string };
/** Hub 2.19.0: a release of the server agent (from git only), with how many servers run it. */
export type AgentRelease = { id: string; version: string; notes: string; urgent: boolean; releasedAt: string; latest: boolean; servers: number };
export type UnmetRequirement = { product: Product; version: string; current: string | null };
export type NoticeLevel = "info" | "maintenance" | "warning";