67 lines
2.3 KiB
Python
67 lines
2.3 KiB
Python
import logging
|
|
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from api.v1.auth import router as auth_router
|
|
from api.v1.chat import router as v1_router
|
|
from core.config import DEEPSEEK_API_KEY, get_config
|
|
from core.llm import create_client
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Logging — tool calls will appear in the uvicorn console
|
|
# ---------------------------------------------------------------------------
|
|
logging.basicConfig(
|
|
level=logging.INFO,
|
|
format="%(asctime)s [%(name)s] %(levelname)s: %(message)s",
|
|
datefmt="%H:%M:%S",
|
|
)
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Load all agents, skills, AND auth services so they self-register at startup
|
|
# ---------------------------------------------------------------------------
|
|
from agents import load_all_agents # noqa: E402
|
|
|
|
load_all_agents()
|
|
|
|
import auth.jellyfin # noqa: E402 — self-registers JellyfinAuth
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Lifespan
|
|
# ---------------------------------------------------------------------------
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
from bot.discord_bot import start_in_background # noqa: E402
|
|
|
|
start_in_background()
|
|
|
|
yield
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# App
|
|
# ---------------------------------------------------------------------------
|
|
app = FastAPI(lifespan=lifespan)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Singletons (stored on app.state so every module can reach them via Depends)
|
|
# ---------------------------------------------------------------------------
|
|
app.state.llm_client = create_client(DEEPSEEK_API_KEY)
|
|
|
|
# Lazy-compiled LangGraph graphs — populated on first use per agent
|
|
app.state.agent_graphs: dict = {}
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Routers
|
|
# ---------------------------------------------------------------------------
|
|
app.include_router(v1_router, prefix="/v1")
|
|
app.include_router(auth_router) |