WIP Hub 1.6.0: AI proxy for Cross Events 2.0
Signed /installs/ai/status and /installs/ai/complete (protocol 3b): the Hub holds the Claude key, holds each call's worst case against the licence's monthly cap in a locked transaction, calls Claude Haiku 5.5 and meters real cost and charged amount (markup) in rand. Settings -> AI, licence markup override, AI use on the install page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,9 +5,9 @@ import Link from "next/link";
|
||||
import { useParams } from "next/navigation";
|
||||
import { ArrowLeft } from "lucide-react";
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import { ago, bytes, fmtDate, rand } from "@/lib/format";
|
||||
import { ago, bytes, fmtDate, rand, randFine } from "@/lib/format";
|
||||
import { usePaged } from "@/lib/paging";
|
||||
import type { Health, InstallEvent, InstallSummary, Licence, Stats } from "@/lib/types";
|
||||
import type { AiHelperUse, AiMonth, AiStatus, Health, InstallEvent, InstallSummary, Licence, Stats } from "@/lib/types";
|
||||
import { Badge, Loading, Message, PageTitle, Pager } from "@/components/ui";
|
||||
|
||||
type Detail = {
|
||||
@@ -20,6 +20,7 @@ type Detail = {
|
||||
summary: InstallSummary;
|
||||
events: InstallEvent[];
|
||||
heartbeats: { receivedAt: string; version: string | null; stats: Stats | null }[];
|
||||
ai: { status: AiStatus; months: AiMonth[]; helpers: AiHelperUse[] };
|
||||
};
|
||||
|
||||
const NO_EVENTS: InstallEvent[] = [];
|
||||
@@ -114,7 +115,8 @@ export default function InstallPage() {
|
||||
<Row k="Status" v={<Badge value={d.licence.status} />} />
|
||||
<Row k="Expires" v={d.licence.expiresAt ? fmtDate(d.licence.expiresAt, false) : "no end date"} />
|
||||
<Row k="Grace" v={`${d.licence.graceDays} days`} />
|
||||
<Row k="AI cap (2.0)" v={d.licence.aiMonthlyCapCents ? `${rand(d.licence.aiMonthlyCapCents)} / month` : "off"} />
|
||||
<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}%`} />
|
||||
<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>}
|
||||
@@ -135,6 +137,38 @@ export default function InstallPage() {
|
||||
|
||||
{msg && <div className="mt-4"><Message msg={msg} /></div>}
|
||||
|
||||
<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>
|
||||
) : (
|
||||
<>
|
||||
<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" : ""}`} />
|
||||
<Row k="Renews" v={fmtDate(d.ai.status.renewsOn, false)} />
|
||||
{d.ai.helpers.length > 0 && <Row k="By helper this month" v={d.ai.helpers.map(h => `${h.helper.replace(/_/g, " ")}: ${h.calls} (${randFine(h.chargedCents)})`).join(" · ")} />}
|
||||
{d.ai.months.length > 0 && (
|
||||
<div className="mt-3 overflow-x-auto">
|
||||
<table className="w-full text-sm">
|
||||
<thead><tr className="text-left text-xs text-slate-500"><th className="py-1">Month</th><th>Uses</th><th>Tokens in / out</th><th className="text-right">Real cost</th><th className="text-right">Charged</th><th className="text-right">Profit</th></tr></thead>
|
||||
<tbody>
|
||||
{d.ai.months.map(m => (
|
||||
<tr key={m.month} className="border-t border-slate-100">
|
||||
<td className="py-1">{m.month}</td>
|
||||
<td>{m.calls}</td>
|
||||
<td>{m.inputTokens.toLocaleString("en-ZA")} / {m.outputTokens.toLocaleString("en-ZA")}</td>
|
||||
<td className="text-right">{randFine(m.realCents)}</td>
|
||||
<td className="text-right">{randFine(m.chargedCents)}</td>
|
||||
<td className="text-right">{randFine(m.profitCents)}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="card mt-6">
|
||||
<h2 className="mb-3 font-semibold">History</h2>
|
||||
{d.events.length === 0 ? <p className="text-sm text-slate-500">Nothing yet.</p> : (
|
||||
|
||||
Reference in New Issue
Block a user