User-configurable settings routes.
Split out of the former flat routes.py; behaviour is unchanged.
get_settings
Return user-configurable settings.
Source code in memory/dashboard/backend/routes/settings.py
| @router.get("/settings")
def get_settings():
"""Return user-configurable settings."""
settings: dict = {"session_gap_seconds": 1800, "session_drift_threshold": 0.4}
if _CONFIG_FILE.exists():
try:
import yaml
config = yaml.safe_load(_CONFIG_FILE.read_text(encoding="utf-8")) or {}
if "session_gap_seconds" in config:
settings["session_gap_seconds"] = float(config["session_gap_seconds"])
if "session_drift_threshold" in config:
settings["session_drift_threshold"] = float(config["session_drift_threshold"])
except Exception:
pass
return settings
|
update_settings
update_settings(body: SettingsUpdate)
Update user-configurable settings in .memory/config.yaml.
Source code in memory/dashboard/backend/routes/settings.py
| @router.put("/settings")
def update_settings(body: SettingsUpdate):
"""Update user-configurable settings in .memory/config.yaml."""
import yaml
config: dict = {}
if _CONFIG_FILE.exists():
try:
config = yaml.safe_load(_CONFIG_FILE.read_text(encoding="utf-8")) or {}
except Exception:
config = {}
if body.session_gap_seconds is not None:
if body.session_gap_seconds < 60:
raise HTTPException(status_code=400, detail="session_gap_seconds must be at least 60")
config["session_gap_seconds"] = body.session_gap_seconds
if body.session_drift_threshold is not None:
if not (0.0 <= body.session_drift_threshold < 1.0):
raise HTTPException(status_code=400, detail="session_drift_threshold must be between 0 and 1")
config["session_drift_threshold"] = body.session_drift_threshold
_CONFIG_FILE.parent.mkdir(parents=True, exist_ok=True)
_CONFIG_FILE.write_text(yaml.dump(config, default_flow_style=False), encoding="utf-8")
return {
"status": "updated",
"settings": {
"session_gap_seconds": config.get("session_gap_seconds", 1800),
"session_drift_threshold": config.get("session_drift_threshold", 0.4),
},
}
|