- Add app/core/deep_agent.py with Home and Floating supervisor graphs using LangGraph create_react_agent (hierarchical pattern) - Strip ChatAgent classes from all 4 agent files, keep @tool functions - Rewrite output_formatter.py for event-based (token/tool_end/mutations) stream - Update device_ws.py to use run_home_stream/run_floating_stream - Rewrite chat.py REST route to use run_home - Add update_core_memory tool to both supervisors - Add langgraph>=0.3.0 to requirements.txt - Remove orchestrator.py, execution_plan.py, agent_registry.py, plans.py - Remove PlanAction, PlanStep, ExecutionPlan, execution_mode from schemas - Update all affected tests to match new API - Remove 6 deprecated test files for deleted modules - Clean up stale docstrings referencing removed orchestrator
72 lines
2.3 KiB
Python
72 lines
2.3 KiB
Python
from contextlib import asynccontextmanager
|
|
import logging
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
logging.basicConfig(
|
|
level=logging.INFO,
|
|
format="%(asctime)s %(levelname)s %(name)s: %(message)s",
|
|
)
|
|
logging.getLogger("sqlalchemy.engine").setLevel(logging.WARNING)
|
|
logging.getLogger("sqlalchemy.pool").setLevel(logging.WARNING)
|
|
|
|
from app.api.middleware.rate_limit import TierRateLimitMiddleware
|
|
from app.api.middleware.sanitizer import SanitizerMiddleware
|
|
from app.config.settings import settings
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
# Startup: initialise DB connection pool
|
|
yield
|
|
|
|
# Shutdown: dispose SQLAlchemy connection pool
|
|
from app.db import engine
|
|
await engine.dispose()
|
|
|
|
|
|
def create_app() -> FastAPI:
|
|
app = FastAPI(
|
|
title="Adiuva Cloud API",
|
|
version="0.1.0",
|
|
docs_url="/docs" if settings.ENV == "dev" else None,
|
|
redoc_url=None,
|
|
lifespan=lifespan,
|
|
)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=settings.CORS_ORIGINS,
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
# Middleware stack (Starlette inserts at position 0, so last-added = outermost).
|
|
# Request flow: TierRateLimit → Sanitizer → CORS → Router
|
|
# Response flow: Router → CORS → Sanitizer → TierRateLimit
|
|
app.add_middleware(SanitizerMiddleware)
|
|
app.add_middleware(TierRateLimitMiddleware)
|
|
|
|
from app.api.routes import agent_setup, agents, auth, backup, billing, chat, device_ws, plugins, storage, vectors
|
|
|
|
app.include_router(auth.router, prefix="/api/v1")
|
|
app.include_router(chat.router, prefix="/api/v1")
|
|
app.include_router(storage.router, prefix="/api/v1")
|
|
app.include_router(vectors.router, prefix="/api/v1")
|
|
app.include_router(backup.router, prefix="/api/v1")
|
|
app.include_router(plugins.router, prefix="/api/v1")
|
|
app.include_router(billing.router, prefix="/api/v1")
|
|
app.include_router(agents.router, prefix="/api/v1")
|
|
app.include_router(agent_setup.router, prefix="/api/v1")
|
|
app.include_router(device_ws.router, prefix="/api/v1")
|
|
|
|
@app.get("/api/v1/health", tags=["health"])
|
|
async def health() -> dict:
|
|
return {"status": "ok", "version": app.version}
|
|
|
|
return app
|
|
|
|
|
|
app = create_app()
|