from contextvars import ContextVar
from typing import Optional, Dict, Any

_user_context: ContextVar[Optional[Dict[str, Any]]] = ContextVar("user_context", default=None)

def get_user_context() -> Optional[Dict[str, Any]]:
    return _user_context.get()

def set_user_context(user: Dict[str, Any]) -> None:
    _user_context.set(user)
