"""FastAPI application entry point."""
import asyncio
from pathlib import Path
import structlog
from fastapi import FastAPI, Request
from fastapi.responses import FileResponse, Response
from fastapi.staticfiles import StaticFiles
from navi.api.routes import agents, health, messages, sessions
from navi.api.websocket import router as ws_router
from navi.config import settings
from debug.eval.api import router as eval_router
structlog.configure(
wrapper_class=structlog.make_filtering_bound_logger(
getattr(__import__("logging"), settings.log_level)
),
)
app = FastAPI(
title="Navi",
description="Modular agent system — REST API and WebSocket",
version="0.1.0",
)
app.include_router(health.router)
app.include_router(agents.router)
app.include_router(sessions.router)
app.include_router(messages.router)
app.include_router(ws_router)
app.include_router(eval_router)
_base = Path(__file__).parent.parent
_static_dir = _base / "old_webclient"
if _static_dir.exists():
app.mount("/static", StaticFiles(directory=str(_static_dir)), name="static")
app.mount("/assets", StaticFiles(directory=str(_base / "webclient" / "dist" / "assets")), name="assets")
app.mount("/images", StaticFiles(directory=str(_base / "webclient" / "dist" / "images")), name="images")
app.mount("/content-viewers", StaticFiles(directory=str(_base / "webclient" / "dist" / "content-viewers")), name="content_viewers")
app.mount("/content", StaticFiles(directory=str(_base / "navi" / "content")), name="content")
@app.on_event("startup")
async def _start_session_file_cleanup() -> None:
from navi.api.deps import get_session_store
from navi.session_files import cleanup_loop
asyncio.create_task(cleanup_loop(get_session_store()))
@app.middleware("http")
async def no_cache_static(request: Request, call_next) -> Response:
response = await call_next(request)
if request.url.path.startswith("/static/"):
response.headers["Cache-Control"] = "no-store"
return response
@app.get("/", include_in_schema=False)
async def index() -> FileResponse:
return FileResponse("webclient/dist/index.html", headers={"Cache-Control": "no-store"})
@app.get("/debug", include_in_schema=False)
async def debug() -> FileResponse:
return FileResponse("debug/index.html", headers={"Cache-Control": "no-store"})
@app.get("/debug/eval", include_in_schema=False)
async def debug_eval() -> FileResponse:
return FileResponse("debug/eval/index.html", headers={"Cache-Control": "no-store"})