| 274 | }) |
| 275 | |
| 276 | def _load(self) -> None: |
| 277 | data = self._storage.load() |
| 278 | if not data: |
| 279 | return |
| 280 | for key in ("per_request", "hourly", "daily", "session"): |
| 281 | val = data.get("limits", {}).get(key) |
| 282 | if val is not None: |
| 283 | setattr(self._limits, key, float(val)) |
| 284 | for r in data.get("history", []): |
| 285 | self._history.append(SpendRecord( |
| 286 | timestamp=r["timestamp"], amount=r["amount"], |
| 287 | model=r.get("model"), action=r.get("action"), |
| 288 | )) |
| 289 | self._cleanup() |
| 290 | |
| 291 | |
| 292 | def format_duration(seconds: int) -> str: |