Files
Agents/main.py
T
TimHoogervorst f21676eafd
Build and Push Agent API / build (push) Successful in 4s
removed bunch of old code, added /init bunch of cleanups
2026-05-25 18:07:01 +02:00

61 lines
2.0 KiB
Python

import logging
from contextlib import asynccontextmanager
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from gateway.v1.auth import router as auth_router
from gateway.jellystat.api import router as jellystat_router
# ---------------------------------------------------------------------------
# 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 gateway.auth.jellyfin # noqa: E402 — self-registers JellyfinAuth
# ---------------------------------------------------------------------------
# Lifespan
# ---------------------------------------------------------------------------
@asynccontextmanager
async def lifespan(app: FastAPI):
from gateway.discord.bot import start_in_background # noqa: E402
from gateway.jellystat.db import init_pool, close_pool # noqa: E402
await init_pool(app)
start_in_background()
yield
await close_pool(app)
# ---------------------------------------------------------------------------
# App
# ---------------------------------------------------------------------------
app = FastAPI(lifespan=lifespan)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# ---------------------------------------------------------------------------
# Routers
# ---------------------------------------------------------------------------
app.include_router(auth_router)
app.include_router(jellystat_router)