composite_runtime.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. from __future__ import annotations
  2. from pathlib import Path
  3. from typing import Any
  4. from content_agent.interfaces import RuntimeStore
  5. class CompositeRuntimeStore:
  6. def __init__(self, primary: RuntimeStore, export: RuntimeStore) -> None:
  7. self.primary = primary
  8. self.export = export
  9. def prepare_run(self, run_id: str) -> Path:
  10. self.primary.prepare_run(run_id)
  11. return self.export.prepare_run(run_id)
  12. def run_dir(self, run_id: str) -> Path:
  13. return self.export.run_dir(run_id)
  14. def write_json(self, run_id: str, filename: str, data: dict[str, Any]) -> Path:
  15. self.primary.write_json(run_id, filename, data)
  16. return self.export.write_json(run_id, filename, data)
  17. def update_json(self, run_id: str, filename: str, data: dict[str, Any]) -> Path:
  18. self.primary.update_json(run_id, filename, data)
  19. return self.export.update_json(run_id, filename, data)
  20. def append_jsonl(self, run_id: str, filename: str, rows: list[dict[str, Any]]) -> Path:
  21. self.primary.append_jsonl(run_id, filename, rows)
  22. return self.export.append_jsonl(run_id, filename, rows)
  23. def read_json(self, run_id: str, filename: str) -> dict[str, Any]:
  24. try:
  25. return self.primary.read_json(run_id, filename)
  26. except Exception:
  27. return self.export.read_json(run_id, filename)
  28. def read_jsonl(self, run_id: str, filename: str) -> list[dict[str, Any]]:
  29. try:
  30. return self.primary.read_jsonl(run_id, filename)
  31. except Exception:
  32. return self.export.read_jsonl(run_id, filename)
  33. def file_status(self, run_id: str) -> dict[str, bool]:
  34. try:
  35. return self.primary.file_status(run_id)
  36. except Exception:
  37. return self.export.file_status(run_id)
  38. def create_run_record(self, record: dict[str, Any]) -> None:
  39. self.primary.create_run_record(record)
  40. self.export.create_run_record(record)
  41. def update_run_record(self, run_id: str, updates: dict[str, Any]) -> None:
  42. self.primary.update_run_record(run_id, updates)
  43. self.export.update_run_record(run_id, updates)
  44. def record_policy_run(self, record: dict[str, Any]) -> None:
  45. self.primary.record_policy_run(record)
  46. self.export.record_policy_run(record)
  47. def append_run_event_records(
  48. self,
  49. run_id: str,
  50. policy_run_id: str,
  51. rows: list[dict[str, Any]],
  52. ) -> None:
  53. self.primary.append_run_event_records(run_id, policy_run_id, rows)
  54. self.export.append_run_event_records(run_id, policy_run_id, rows)
  55. def write_publish_jobs(
  56. self,
  57. run_id: str,
  58. policy_run_id: str,
  59. rows: list[dict[str, Any]],
  60. ) -> None:
  61. self.primary.write_publish_jobs(run_id, policy_run_id, rows)
  62. self.export.write_publish_jobs(run_id, policy_run_id, rows)
  63. def write_author_assets(self, rows: list[dict[str, Any]]) -> None:
  64. self.primary.write_author_assets(rows)
  65. self.export.write_author_assets(rows)
  66. def write_author_asset_roles(self, rows: list[dict[str, Any]]) -> None:
  67. self.primary.write_author_asset_roles(rows)
  68. self.export.write_author_asset_roles(rows)
  69. def write_search_clue_assets(self, rows: list[dict[str, Any]]) -> None:
  70. self.primary.write_search_clue_assets(rows)
  71. self.export.write_search_clue_assets(rows)
  72. def write_search_clue_asset_evidence(self, rows: list[dict[str, Any]]) -> None:
  73. self.primary.write_search_clue_asset_evidence(rows)
  74. self.export.write_search_clue_asset_evidence(rows)
  75. def read_performance_feedback(
  76. self,
  77. run_id: str,
  78. policy_run_id: str,
  79. ) -> list[dict[str, Any]]:
  80. return self.primary.read_performance_feedback(run_id, policy_run_id)