from collections.abc import Iterator from contextlib import contextmanager from contextvars import ContextVar _CURRENT_INBOUND_EVENT_KEY: ContextVar[str | None] = ContextVar( "current_feishu_inbound_event_key", default=None, ) @contextmanager def bind_inbound_event(event_key: str) -> Iterator[None]: """Expose the current inbox key to privacy-cleanup hooks.""" token = _CURRENT_INBOUND_EVENT_KEY.set(event_key) try: yield finally: _CURRENT_INBOUND_EVENT_KEY.reset(token) def current_inbound_event_key() -> str | None: return _CURRENT_INBOUND_EVENT_KEY.get()