@@ -1,4 +1,5 @@
|
||||
import logging
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
@@ -23,10 +24,22 @@ from agents import load_all_agents # noqa: E402
|
||||
|
||||
load_all_agents()
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Lifespan
|
||||
# ---------------------------------------------------------------------------
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
from bot.discord_bot import start_in_background # noqa: E402
|
||||
|
||||
start_in_background()
|
||||
|
||||
yield
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# App
|
||||
# ---------------------------------------------------------------------------
|
||||
app = FastAPI()
|
||||
app = FastAPI(lifespan=lifespan)
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
@@ -47,14 +60,4 @@ app.state.agent_graphs: dict = {}
|
||||
# ---------------------------------------------------------------------------
|
||||
# Routers
|
||||
# ---------------------------------------------------------------------------
|
||||
app.include_router(v1_router, prefix="/v1")
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Discord bot — launched once on app startup (not at import time, which
|
||||
# would double-fire under uvicorn --reload).
|
||||
# ---------------------------------------------------------------------------
|
||||
@app.on_event("startup")
|
||||
async def _start_discord_bot() -> None:
|
||||
from bot.discord_bot import start_in_background # noqa: E402
|
||||
|
||||
start_in_background()
|
||||
app.include_router(v1_router, prefix="/v1")
|
||||
Reference in New Issue
Block a user