/** * Predictive Spend Forecaster for x402-cfo. * * Uses online linear regression on spend timestamps to forecast: * - Time until budget exhaustion (per agent or pool) * - Spend rate ($/minute, $/hour) * - Confidence interval based on spend variance * * Based on ad pacing research: optimal spend is proportional to request * rate, not linear over time. The forecaster detects whether spend is * accelerating, decelerating, or steady. * * Uses online regression (no stored history) for O(1) memory. * Sufficient statistics: n, sum_x, sum_y, sum_xy, sum_x2 * where x = time offset (seconds), y = cumulative spend. */ /** Forecast result. */ export interface SpendForecast { /** Current spend rate ($/second) */ ratePerSecond: number; /** Current spend rate ($/minute) */ ratePerMinute: number; /** Current spend rate ($/hour) */ ratePerHour: number; /** Estimated time until budget exhaustion (ms). Infinity if rate <= 0 or no budget set. */ exhaustionEtaMs: number; /** Estimated timestamp when budget will be exhausted. null if not applicable. */ exhaustionAt: Date | null; /** Spend trend: 'accelerating' | 'steady' | 'decelerating' */ trend: 'accelerating' | 'steady' | 'decelerating'; /** R² goodness-of-fit for the linear model (0-1). Higher = more predictable spend. */ confidence: number; /** Total spend so far */ totalSpent: number; /** Budget remaining. null if no budget set. */ remaining: number | null; /** Number of observations */ observations: number; } export interface ForecasterConfig { /** Total budget to forecast exhaustion against. */ budget?: number; /** Minimum observations before forecasting. Default: 3 */ minObservations?: number; } /** * Online linear regression forecaster for spend pacing. * * Tracks cumulative spend over time and fits y = mx + b where: * x = time offset from first observation (seconds) * y = cumulative spend ($) * m = spend rate ($/second) * * Detects acceleration by comparing recent rate to overall rate. */ export declare class SpendForecaster { private budget; private minObservations; private n; private sumX; private sumY; private sumXY; private sumX2; private sumY2; private firstTimestamp; private lastTimestamp; private totalSpent; private recentRates; private prevSpend; private prevTimestamp; constructor(config?: ForecasterConfig); /** * Record a spend observation. * * @param amount - Amount spent in this transaction * @param timestamp - When it occurred (ms). Default: now. */ observe(amount: number, timestamp?: number): void; /** * Get the current spend forecast. * Returns null if insufficient observations. */ forecast(now?: number): SpendForecast | null; /** Update the budget target. */ setBudget(budget: number): void; } //# sourceMappingURL=forecast.d.ts.map