repository.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. """Repository contracts for decode-content state."""
  2. from __future__ import annotations
  3. from typing import Any, Protocol
  4. from uuid import UUID
  5. from decode_content.models import (
  6. ContractSnapshot,
  7. DecodeJob,
  8. DecodeResult,
  9. IngestRecord,
  10. KnowledgeParticle,
  11. PayloadDraft,
  12. ScopeResult,
  13. )
  14. class DecodeRepository(Protocol):
  15. """Persistence boundary for the formal single-item decode workflow."""
  16. def create_decode_job(
  17. self,
  18. *,
  19. item_id: UUID,
  20. status: str = "pending",
  21. metadata: dict[str, Any] | None = None,
  22. ) -> DecodeJob:
  23. ...
  24. def save_decode_result(
  25. self,
  26. *,
  27. item_id: UUID,
  28. decode_job_id: UUID | None = None,
  29. read_result: dict[str, Any] | None = None,
  30. gate_result: dict[str, Any] | None = None,
  31. framing_result: dict[str, Any] | None = None,
  32. status: str = "draft",
  33. ) -> DecodeResult:
  34. ...
  35. def get_decode_result_for_item(self, item_id: UUID) -> DecodeResult:
  36. ...
  37. def save_knowledge_particle(
  38. self,
  39. *,
  40. item_id: UUID,
  41. particle_type: str,
  42. title: str,
  43. decode_result_id: UUID | None = None,
  44. parent_particle_id: UUID | None = None,
  45. content: dict[str, Any] | None = None,
  46. status: str = "draft",
  47. ) -> KnowledgeParticle:
  48. ...
  49. def save_scope_result(
  50. self,
  51. *,
  52. scope_type: str,
  53. scope_value: str,
  54. particle_id: UUID | None = None,
  55. item_id: UUID | None = None,
  56. evidence: dict[str, Any] | None = None,
  57. status: str = "draft",
  58. ) -> ScopeResult:
  59. ...
  60. def save_payload_draft(
  61. self,
  62. *,
  63. payload: dict[str, Any],
  64. particle_id: UUID | None = None,
  65. item_id: UUID | None = None,
  66. review_status: str = "pending",
  67. ingest_ready: bool = False,
  68. status: str = "draft",
  69. ) -> PayloadDraft:
  70. ...
  71. def list_payload_drafts(self, item_id: UUID | None = None) -> list[PayloadDraft]:
  72. ...
  73. def save_ingest_record(
  74. self,
  75. *,
  76. payload_draft_id: UUID | None = None,
  77. target_system: str,
  78. target_id: str | None = None,
  79. status: str = "pending",
  80. response_payload: dict[str, Any] | None = None,
  81. error_message: str | None = None,
  82. ) -> IngestRecord:
  83. ...
  84. def save_contract_snapshot(
  85. self,
  86. *,
  87. contract_name: str,
  88. contract_type: str,
  89. version_label: str | None = None,
  90. content_hash: str | None = None,
  91. source_path: str | None = None,
  92. snapshot: dict[str, Any] | None = None,
  93. ) -> ContractSnapshot:
  94. ...