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.

45 lines 1.86 kB
/** * The starting total. `costUsd` is absent rather than `0`: an agent that never * prices a turn must not accumulate a total that reads as "this agent was free" * (#540). It appears as soon as one turn reports a price. */ const ZERO = { inputTokens: 0, outputTokens: 0, cacheReadTokens: 0, cacheCreationTokens: 0, turns: 0, }; /** * Accumulates per-turn {@link DriverUsage} into a running total for the whole * run and lets a budget cap gate on it (#322). * * This tracks what *this agent* spent, not where the account's subscription quota * stands — the agent reports that separately, per turn, as `DriverRateLimit` * (#517). An earlier version of this note claimed the account limit was * unreachable under subscription auth; it isn't. */ export class UsageMeter { totalsState = { ...ZERO }; /** * Fold one turn's usage into the running total. A turn that reports no price * still counts its tokens; it just leaves the cost total where it was, so an * unpriced run totals `undefined` rather than `$0` (#540). */ add(usage) { const costUsd = usage.costUsd === undefined ? this.totalsState.costUsd : (this.totalsState.costUsd ?? 0) + usage.costUsd; this.totalsState = { ...(costUsd === undefined ? {} : { costUsd }), inputTokens: this.totalsState.inputTokens + usage.inputTokens, outputTokens: this.totalsState.outputTokens + usage.outputTokens, cacheReadTokens: this.totalsState.cacheReadTokens + usage.cacheReadTokens, cacheCreationTokens: this.totalsState.cacheCreationTokens + usage.cacheCreationTokens, turns: this.totalsState.turns + 1, }; } /** A snapshot of the cumulative totals. */ totals() { return { ...this.totalsState }; } } //# sourceMappingURL=usage.js.map