UNPKG

framework

Version:

The (AI) Framework: turnkey, zero-config AI orchestration that wraps a coding-agent CLI (Claude Code) as a black box and takes you from an idea to a running app. Vite for AI.

53 lines 2.74 kB
import { QuotaPoller } from './quota-poller.js'; import type { Driver } from './driver/index.js'; /** A live quota gate, and the polling behind it. */ export interface ConsumptionGuard { /** * Pass as `consumptionGate` to a run. Answers from the poller's cached * readings, so it is cheap enough to ask between every turn. The label of the * window that reached the limit in force (the boundary plus its half-day * cushion, #960 Edit), or null while there is room. */ gate: () => string | null; /** The poller feeding it, exposed so a caller can read the windows off it. */ poller: QuotaPoller; /** Stop polling. Always call this when the run ends. */ stop: () => void; } /** Options for {@link startConsumptionGuard}. */ export interface StartConsumptionGuardOptions { /** The wrapped agent. Must be able to report its quota, or there's nothing to guard with. */ driver: Driver; /** The model the run is on. Brings that model's own weekly window into the gate (#879). */ model?: string; /** * The user's spend-limit offset — the #960 slider — read fresh around each gate check so * dragging it unblocks a parked run's next boundary check without a restart (#1490). It only * ever LOOSENS the gate (see the gate's comment); absent or unreadable means the default * policy, the same fallback the daemon's quota source uses. */ limitOffset?: () => number | Promise<number>; /** Clock, injectable for tests. */ now?: () => number; } /** * Wire the quota boundary up for one run (#879): poll the agent's quota, and * hand back the gate a run consults between turns. * * The boundary is derived from the account's own week, so there is nothing to * configure and nothing to remember between restarts: it is a comparison of two * numbers the agent reports, not a total we accumulate. * * Resolves `undefined` when there is nothing to guard with — the agent can't * report a quota at all (the fake driver, or a second agent that has no such * command). That is the fail-open Rom confirmed on #519: no reading means the * work carries on, with the per-run budget cap still underneath it. The gate * itself fails open for the same reason, which is the opposite of the auto-PM * gate: this one guards work the user asked for. * * The first read is deliberately not awaited. It takes ~5s (it spawns the whole * agent CLI), and making every run wait that long to *maybe* find out it has * budget would be a poor trade. It lands a moment into the run instead. */ export declare function startConsumptionGuard(opts: StartConsumptionGuardOptions): ConsumptionGuard | undefined; //# sourceMappingURL=consumption-guard.d.ts.map