Source code for cadrumo.application.ledger.llm_diagnostics_ports
"""Application-owned read capabilities for ledger LLM diagnostics.The diagnostics projection aggregates two existing stores, but it does not owneither store's persistence details. The application boundary therefore namesonly the accounting facts it needs and lets an executable composition roottranslate concrete records and failures before they cross inward."""from__future__importannotationsfromcollections.abcimportSequencefromdataclassesimportdataclassfromdatetimeimportdatefromdecimalimportDecimalfromtypingimportProtocolfrom...core.errors.hierarchyimportCadrumoErrorfrom...domain.transactions.modelsimportTransaction
[docs]@dataclass(frozen=True,slots=True)classLlmUsageDiagnosticRecord:"""Accounting-only usage fact supplied by an outer reader. Response text, request identifiers, and other transport/storage fields are intentionally absent: the diagnostics use case has no reason to receive them, and the DTO keeps that boundary explicit. """provider:strinput_tokens:intoutput_tokens:intcost_estimate_usd:Decimal|Nonecache_hit:bool
[docs]classLlmUsageDiagnosticsReader(Protocol):"""Read usage accounting facts within an inclusive date window."""
[docs]defload_records(self,*,since:date|None,until:date|None,)->Sequence[LlmUsageDiagnosticRecord]:"""Return translated usage facts for the requested window."""...
[docs]classLlmTransactionDiagnosticsReader(Protocol):"""Read the domain transaction facts used for confidence diagnostics."""
[docs]defload_transactions(self)->Sequence[Transaction]:"""Return all transactions in the explicitly composed bucket."""...
[docs]classLlmDiagnosticsReadError(CadrumoError):"""A usage or transaction diagnostics read failed at the outer boundary."""
[docs]@dataclass(frozen=True,slots=True)classLlmDiagnosticsPorts:"""Required read capabilities for one ledger LLM diagnostics report."""usage_reader:LlmUsageDiagnosticsReadertransaction_reader:LlmTransactionDiagnosticsReader