Source code for cadrumo.application.ledger.invoice_draft_extraction_ports
"""Application-owned dependencies for invoice-draft extraction.The extraction use case decides *when* an evidence reader is needed. Thismodule names the capabilities it needs; outer composition chooses the concretee-invoice, LLM, and secure-storage implementations."""from__future__importannotationsfromcollections.abcimportCallablefromdataclassesimportdataclassfromtypingimportProtocolfrom...core.configimportSettingsfrom...core.config_supportimportLLMProviderfrom...core.errors.hierarchyimportCadrumoErrorfrom...core.image_media_typeimportImageMediaTypefrom...domain.iva.supply_natureimportSupplyNaturefrom.document_transcriptionimportDocumentTranscriptionfrom.evidence_inputimportEvidenceInputfrom.evidence_input_portsimportEvidenceInputPortsfrom.evidence_textlayer_portsimportEvidenceTextLayerPortsfrom.invoice_draft_recordsimportInvoiceDraftfrom.structured_invoice_portsimportStructuredInvoiceReader
[docs]classEvidenceConsentProof(Protocol):"""Minimum consent fact the use case needs to bind evidence bytes."""@propertydefevidence_content_address(self)->str:"""Return the content address covered by the consent proof."""...
[docs]@dataclass(frozen=True)classVisionImage:"""In-memory image prepared by the application for a vision reader."""base64_data:strmedia_type:ImageMediaType
[docs]classStructuredInvoiceReadError(CadrumoError):"""A structured document could not be read by the selected exact reader."""
[docs]classInvoiceDraftReaderUnavailableError(CadrumoError):"""Selected reader or its runtime was unavailable; preserve its cause."""def__init__(self,cause:Exception)->None:"""Create an unavailable-reader error while preserving its cause."""super().__init__(str(cause))self.cause=cause
[docs]@dataclass(frozen=True)classInvoiceDraftExtractionPorts:"""Concrete capabilities supplied by an outer composition root."""resolve_evidence_input:Callable[[str,str|None,str|None,Settings],EvidenceInput]evidence_input_ports:EvidenceInputPortstext_layer_ports:EvidenceTextLayerPortsparse_structured_invoice:StructuredInvoiceReaderread_text:Callable[[DocumentTranscription,Settings,LLMProvider|None,EvidenceConsentProof|None,object],InvoiceDraft]propose_supply_nature:Callable[[DocumentTranscription,Settings],SupplyNature|None]rasterise_pdf:Callable[[bytes],tuple[str,...]]transcribe_vision:Callable[[tuple[VisionImage,...],str,Settings,LLMProvider|None,EvidenceConsentProof|None],DocumentTranscription]consent_binding_error:Callable[[dict[str,object]],Exception]