- Add ExtractedBlock, ExtractionEnvelope, and StagedDocument data models in types.py - Define ingestion repository, file store, vision, and extraction ports in ports.py - Extend IngestionSettings with limits, policies, vision, and embedding configuration - Update database compatibility verification to support worker and review schema revisions - Add PyMuPDF, Pillow, defusedxml, and tiktoken dependencies to pyproject.toml
77 lines
2.7 KiB
Python
77 lines
2.7 KiB
Python
"""Provider-neutral ports; publication arrives in a later phase."""
|
|
from typing import Mapping, Protocol, Sequence
|
|
from uuid import UUID
|
|
|
|
from .types import EmbeddingProfile, ExtractedBlock, ExtractionEnvelope
|
|
|
|
|
|
class FileStore(Protocol):
|
|
def put(self, content: bytes) -> str:
|
|
"""Create a new immutable original under a generated key; never overwrite."""
|
|
...
|
|
|
|
def read(self, storage_key: str) -> bytes: ...
|
|
|
|
def inventory(self) -> Mapping[str, Sequence[str]]:
|
|
"""Report originals, temporary_files and unexpected_entries; never delete."""
|
|
...
|
|
|
|
def discard_unused(self, storage_key: str) -> None:
|
|
"""Delete this request's candidate only after a confirmed unused outcome.
|
|
|
|
Ambiguous commit outcomes must retain it for report-only reconciliation.
|
|
"""
|
|
...
|
|
|
|
|
|
class EmbeddingProvider(Protocol):
|
|
@property
|
|
def profile(self) -> EmbeddingProfile: ...
|
|
|
|
@property
|
|
def request_policy(self) -> Mapping[str, object]:
|
|
"""Secret-free, endpoint-specific frozen request limits and capabilities."""
|
|
...
|
|
|
|
def embed(self, texts: Sequence[str]) -> Sequence[Sequence[float]]:
|
|
"""One validated batch, input order restored; no internal retries."""
|
|
...
|
|
|
|
|
|
class DocumentRepository(Protocol):
|
|
def get_document(
|
|
self, organization_id: UUID, document_id: UUID
|
|
) -> Mapping[str, object] | None: ...
|
|
|
|
def get_enabled_administrator(self, user_id: UUID) -> Mapping[str, object] | None:
|
|
"""Resolve scope from a trusted operator's persisted administrator identity."""
|
|
...
|
|
|
|
|
|
class ExtractionProvider(Protocol):
|
|
def extract(self, *, document_id: UUID, title: str, original_sha256: str,
|
|
content: bytes, mime_type: str, processing_profile: Mapping[str, object]) -> ExtractionEnvelope:
|
|
"""Faithful ordered evidence; no native responses escape."""
|
|
...
|
|
|
|
|
|
class VisionProvider(Protocol):
|
|
def transcribe(self, image: bytes, *, page: int | None, section: str | None,
|
|
processing_profile: Mapping[str, object]) -> Sequence[ExtractedBlock]: ...
|
|
|
|
|
|
class IntakeRepository(Protocol):
|
|
def lookup(self, settings, administrator_id: UUID, request_id: UUID):
|
|
"""Short transaction: embedding compatibility, locked admin, scoped key."""
|
|
...
|
|
|
|
def replay(self, org: UUID, administrator_id: UUID, previous, submitted_hash: str): ...
|
|
|
|
def create(self, settings, prepared, key: str, administrator_id: UUID, request_id: UUID, expected_org: UUID):
|
|
"""Locked admin + scoped uniqueness + atomic document/job/audit; returns after commit."""
|
|
...
|
|
|
|
def status(self, administrator_id: UUID, document_id: UUID): ...
|
|
|
|
def original_references(self): ...
|