| 252 | } |
| 253 | |
| 254 | record(amount: number, metadata?: { model?: string; action?: string }): void { |
| 255 | if (!Number.isFinite(amount) || amount < 0) { |
| 256 | throw new Error("Record amount must be a non-negative finite number"); |
| 257 | } |
| 258 | const record: SpendRecord = { |
| 259 | timestamp: this.now(), |
| 260 | amount, |
| 261 | model: metadata?.model, |
| 262 | action: metadata?.action, |
| 263 | }; |
| 264 | |
| 265 | this.history.push(record); |
| 266 | this.sessionSpent += amount; |
| 267 | this.sessionCalls += 1; |
| 268 | |
| 269 | this.cleanup(); |
| 270 | this.save(); |
| 271 | } |
| 272 | |
| 273 | private getSpendingInWindow(from: number, to: number): number { |
| 274 | return this.history |