import Link from "next/link"; import { cache } from "react"; import { badgeVariants } from "@/components/ui/badge"; import { askEditor, readPolicy, readToday } from "@/lib/articles/generation"; import { policyChipLabel } from "@/lib/articles/policyChip"; import { generationPolicyHref } from "@/lib/hrefs"; import { cn } from "@/lib/utils"; // THE GENERATION POLICY, as a chip (P4a-2; canvas "Create": "Policy shown as a // chip"): the policy's one line -- its preset, the API model, the day's spend // against the daily cap -- with a Meter dot, linking to where it is set // (/settings/generation, P5's page, which holds the PolicyPanel). On a // local-only EDITOR (its generation-usage answer's `localOnly`, demo epic D5) // it names the local model and says "local only", with no spend // (lib/articles/policyChip.ts); otherwise it is exactly as it always was. // // Async: the policy is the editor's (askEditor), so the frame streams this in // under a ; an editor that does not answer is said, not hidden. // Once a request: a phone renders the chip twice (the stage row's, hidden, and // the ⋯ sheet's -- PieceFrame), and the editor need not be asked twice. const policyOnce = cache(() => readPolicy()); const todayOnce = cache((daily: number) => readToday(daily)); // The editor's own word on local only; an editor that does not say is not. const localOnlyOnce = cache(async () => askEditor<{ localOnly?: unknown }>("/api/ops/generation-usage") .then((a) => a.localOnly === true) .catch(() => false), ); const usd = (v: number) => `$${v.toFixed(2)}`; const shortModel = (m: string) => m.replace(/^claude-/, ""); export function PolicyChipShell({ children, preset }: { children: React.ReactNode; preset?: string }) { return (