"""A per-request id, kept in a ContextVar — the same shape as py-09's `request_scope`, now
scoped to one asyncio task per HTTP request instead of one thread per CLI call."""

from collections.abc import Iterator
from contextlib import contextmanager
from contextvars import ContextVar  # noqa: F401  — the storage the TODO below asks for

# TODO: the request id's storage. It must hold ONE value per asyncio task — two requests in
# flight on the same event loop must never see each other's id. Outside any request, reading
# it gives "-".


@contextmanager
def request_scope(request_id: str) -> Iterator[None]:
    """Everything that runs inside this with-block — however many `await`s deep, including a
    StreamingResponse's body as it sends — reads `current_request_id()` as `request_id`.
    Restores the previous value on exit, even when the block raises.
    """
    ...


def current_request_id() -> str:
    """The id of the request this asyncio task is serving, or "-" outside any request."""
    ...
