Source code for cadrumo.adapters.outbound.aeat.operator_progress
"""Lightweight operator-progress channel shared by AEAT operations and frontends.Keeping this ContextVar outside the concrete auth implementations lets CLImetadata and local configuration commands start without browser-auth settings.The CLI installs a stderr sink for headless operation; a full-screen frontendmay replace it within its worker context so progress stays inside the TUI."""from__future__importannotationsfromcollections.abcimportCallable,GeneratorfromcontextlibimportcontextmanagerfromcontextvarsimportContextVarfrom....core.operator_progressimportOperatorProgress_OPERATOR_PROGRESS_SINK:ContextVar[Callable[[OperatorProgress],None]|None]=ContextVar("_aeat_auth_operator_progress_sink",default=None,)"""Active operator progress sink for the current context, or ``None`` when unset."""
[docs]@contextmanagerdefoperator_progress_sink(sink:Callable[[OperatorProgress],None])->Generator[None]:"""Route operator progress to ``sink`` within this context."""token=_OPERATOR_PROGRESS_SINK.set(sink)try:yieldfinally:_OPERATOR_PROGRESS_SINK.reset(token)
[docs]defemit_operator_progress(progress:OperatorProgress)->None:"""Send an already-redacted operator progress update when a sink is armed."""sink=_OPERATOR_PROGRESS_SINK.get()ifsinkisnotNone:sink(progress)