""" web/deps.py =========== Shared bot reference for FastAPI dependency injection. ``set_bot()`` is called once from ``bot.py`` before starting Uvicorn. FastAPI route handlers use ``get_bot()``, ``get_comfy()``, etc. as Depends() callables. """ from __future__ import annotations from typing import Optional _bot = None def set_bot(bot) -> None: """Store the discord.py bot instance for DI access.""" global _bot _bot = bot def get_bot(): """FastAPI dependency: return the bot instance.""" return _bot def get_comfy(): """FastAPI dependency: return the ComfyClient.""" if _bot is None: return None return getattr(_bot, "comfy", None) def get_config(): """FastAPI dependency: return the BotConfig.""" if _bot is None: return None return getattr(_bot, "config", None) def get_state_manager(): """FastAPI dependency: return the WorkflowStateManager.""" comfy = get_comfy() if comfy is None: return None return getattr(comfy, "state_manager", None) def get_workflow_manager(): """FastAPI dependency: return the WorkflowManager.""" comfy = get_comfy() if comfy is None: return None return getattr(comfy, "workflow_manager", None) def get_inspector(): """FastAPI dependency: return the WorkflowInspector.""" comfy = get_comfy() if comfy is None: return None return getattr(comfy, "inspector", None) def get_user_registry(): """FastAPI dependency: return the UserStateRegistry.""" if _bot is None: return None return getattr(_bot, "user_registry", None)