Hub 2.0 step 6: AI cap and markup per church

The cap and markup move from the licence to the customer (migrated), use
is counted over all the church's installs under one lock per church, and
the licence token carries the church's cap. Settings → AI shows product.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-05 08:55:43 +02:00
co-authored by Claude Opus 5.5
parent 6e51780103
commit 59e6b9f03c
11 changed files with 138 additions and 72 deletions
@@ -17,7 +17,7 @@ type Detail = {
adminContact: { name?: string; email?: string } | null; server: { node?: string; postgres?: string; os?: string } | null;
features: Record<string, unknown> | null; registeredAt: string; lastHeartbeatAt: string | null; releasedAt: string | null;
health: Health | null; stats: Stats | null;
customer: { id: string; name: string };
customer: { id: string; name: string; aiMonthlyCapCents: number; aiMarkupPercent: number | null };
licence: (Licence & { tokenPreview: { status: string; validUntil: string; licenceExpiresAt: string | null } }) | null;
summary: InstallSummary;
events: InstallEvent[];
@@ -137,8 +137,8 @@ export default function InstallPage() {
v={<>{tier.name} · {tierPrice(tier)}{d.licence.plan !== tier.name && d.licence.plan !== "Trial" && <span className="ml-1 text-amber-700">(plan is {d.licence.plan})</span>}</>}
/>
)}
<Row k="AI cap" v={d.licence.aiMonthlyCapCents ? `${rand(d.licence.aiMonthlyCapCents)} / month` : "off"} />
<Row k="AI markup" v={d.licence.aiMarkupPercent == null ? "default" : `${d.licence.aiMarkupPercent}%`} />
<Row k="AI cap (church)" v={d.customer.aiMonthlyCapCents ? `${rand(d.customer.aiMonthlyCapCents)} / month` : "off"} />
<Row k="AI markup" v={d.customer.aiMarkupPercent == null ? "default" : `${d.customer.aiMarkupPercent}%`} />
<Link href={`/customers/${d.customer.id}`} className="mt-3 inline-block text-sm text-indigo-600 hover:underline">Change the licence →</Link>
</>
) : <p className="text-sm text-slate-500">No licence (released).</p>}
@@ -162,7 +162,7 @@ export default function InstallPage() {
<div className="card mt-6">
<h2 className="mb-2 font-semibold">AI</h2>
{!d.ai.status.enabled && d.ai.months.length === 0 ? (
<p className="text-sm text-slate-500">Off for this site{d.licence?.aiMonthlyCapCents ? " (AI isn't set up in Settings → AI, or the licence isn't active)" : " (cap R0)"}.</p>
<p className="text-sm text-slate-500">Off for this site{d.customer.aiMonthlyCapCents ? " (AI isn't set up in Settings → AI, or the licence isn't active)" : " (cap R0)"}.</p>
) : (
<>
<Row k="This month (charged)" v={`${randFine(d.ai.status.usedCents)} of ${rand(d.ai.status.capCents)} (${d.ai.status.usedPercent}%)${d.ai.status.capReached ? " — used up" : ""}`} />