Files
aios/active-runtime/app/search_audit_store.py
T

28 lines
828 B
Python

"""Audit storage for Search Gateway executions."""
from __future__ import annotations
import json
from pathlib import Path
from typing import Any
class SearchAuditStore:
def __init__(self, root: str = "runtime/search-gateway/audit"):
self.root = Path(root)
self.root.mkdir(parents=True, exist_ok=True)
def append(self, record: dict[str, Any]) -> str:
path = self.root / f"{record.get('request_id', 'search')}.json"
path.write_text(json.dumps(record, ensure_ascii=False, indent=2), encoding="utf-8")
return str(path)
def list_recent(self) -> list[dict[str, Any]]:
result = []
for path in sorted(self.root.glob("*.json")):
result.append(json.loads(path.read_text(encoding="utf-8")))
return result[-50:]
__all__ = ["SearchAuditStore"]