/** * Budget tracker — daily LLM spend enforcement. * * Backed by the budget_spend table (day TEXT PRIMARY KEY, usd_total REAL, calls INTEGER). * All DB ops are synchronous (better-sqlite3). */ import type { DB } from '../storage/db.js'; export declare class BudgetExceeded extends Error { readonly dayTotal: number; readonly cap: number; readonly estimateUsd: number; constructor(dayTotal: number, cap: number, estimateUsd: number); } export interface DaySpend { day: string; usd_total: number; calls: number; } export declare class BudgetTracker { private readonly db; constructor(db: DB); /** Return today's spend row (or a zeroed row if none exists yet). */ today(): DaySpend; /** * Add usd to today's running total and increment call count. * Uses INSERT OR REPLACE so the first call creates the row. */ record(usd: number): void; /** * Return true if today's spend + estimateUsd would remain within capUsd. * Does NOT record spend — call record() after a successful LLM call. */ canSpend(estimateUsd: number, capUsd: number): boolean; /** * Assert that we can spend estimateUsd against capUsd. * Throws BudgetExceeded if over cap. */ assertCanSpend(estimateUsd: number, capUsd: number): void; /** * Reset today's row to zero (user-initiated override). * Logs to stdout for audit trail. */ resetToday(): void; /** * Estimate LLM cost for a call given prompt character count. * Uses: input_tokens ≈ chars/4, fixed 500 output tokens. * Returns USD (0 if this is an Ollama call — caller should pass 0). */ static estimateUsd(promptChars: number, costPerInputToken: number, costPerOutputToken: number): number; /** * Month totals: sum up all days in the current calendar month (YYYY-MM prefix). */ monthTotal(): { usd_total: number; calls: number; month: string; }; }