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
+4 -3
View File
@@ -27,8 +27,6 @@ export type Licence = {
status: LicenceStatus;
expiresAt: string | null;
graceDays: number;
aiMonthlyCapCents: number;
aiMarkupPercent: number | null;
notes: string | null;
createdAt: string;
install?: { id: string; name: string; url: string; lastHeartbeatAt: string | null } | null;
@@ -42,6 +40,9 @@ export type Customer = {
phone: string | null;
notes: string | null;
createdAt: string;
/** Hub 2.0: the church's AI allowance, shared by all its installs. */
aiMonthlyCapCents: number;
aiMarkupPercent: number | null;
licences: Licence[];
installs: { id: string; product: Product; url: string; name?: string; lastHeartbeatAt: string | null; releasedAt?: string | null; version?: string | null }[];
};
@@ -75,7 +76,7 @@ export type InstallEvent = { id: string; type: string; level: Problem["level"];
export type AiStatus = { enabled: boolean; capReached: boolean; capCents: number; usedCents: number; usedPercent: number; renewsOn: string };
export type AiMonth = { month: string; calls: number; inputTokens: number; outputTokens: number; realCents: number; chargedCents: number; profitCents: number };
export type AiHelperUse = { helper: string; calls: number; chargedCents: number };
export type AiInstallUse = { installId: string; name: string; url: string; capCents: number; calls: number; realCents: number; chargedCents: number; profitCents: number };
export type AiInstallUse = { installId: string; name: string; url: string; product: Product; customer: { id: string; name: string } | null; capCents: number; calls: number; realCents: number; chargedCents: number; profitCents: number };
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 };