052591281d
- Complete agent system with planning and execution - Bridge API with FastAPI server - WhatsApp-style mobile dashboard - Enhanced web search with query improvement - Security guards and policy checks - Comprehensive documentation
31 lines
942 B
Python
31 lines
942 B
Python
"""Persist and load run state to/from bridge/runs/<run_id>/state.json."""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
|
|
class StateStore:
|
|
"""Read/write run state as JSON under runs/<run_id>/state.json."""
|
|
|
|
def __init__(self, runs_dir: Path) -> None:
|
|
self._runs_dir = runs_dir
|
|
|
|
def _path(self, run_id: str) -> Path:
|
|
return self._runs_dir / run_id / "state.json"
|
|
|
|
def save(self, run_id: str, state: dict[str, Any]) -> None:
|
|
p = self._path(run_id)
|
|
p.parent.mkdir(parents=True, exist_ok=True)
|
|
p.write_text(json.dumps(state, indent=2), encoding="utf-8")
|
|
|
|
def load(self, run_id: str) -> dict[str, Any] | None:
|
|
p = self._path(run_id)
|
|
if not p.exists():
|
|
return None
|
|
return json.loads(p.read_text(encoding="utf-8"))
|
|
|
|
def exists(self, run_id: str) -> bool:
|
|
return self._path(run_id).exists()
|