SDK
Caps and journal
The two things that limit spending and prevent paying twice.
Caps
interface CapsPolicy {
perRequestBase: bigint;
dailyBase: bigint; // rolling 24 hours
totalBase: bigint;
perOriginDailyBase?: Record<string, bigint>; // exact origins only, no wildcards
} resolveCaps(env, stored) takes each of the three main caps from the environment first, then from caps.json. If any is
missing it throws: no caps means no payment. All must be above zero, with per-request ≤ daily ≤ total.
Journal
openJournal({ path, caps }) is a SQLite file (or ":memory:"). It checks the caps and reserves a payment in one
transaction, so two processes sharing a file cannot both spend the same room under a cap.
| Status | Meaning | Counts against caps |
|---|---|---|
reserved | Room taken, nothing signed yet | Yes |
submitted | Signed and sent, or about to be. Outcome not known | Yes |
served | Paid and answered | Yes |
rejected | Money may have moved and the call was refused. A refund case | Yes |
released | Cancelled before signing. Nothing was sent | No |
const unresolved = journal.history({ status: "submitted" }); history filters by origin, since and status, newest first.
Keep it
The journal is what stops a restart from paying again. Keep it on persistent disk. A ":memory:" journal forgets
everything when the process ends.