AMRYB's picture
Upload 91 files
287f3d3 verified
Raw
History Blame Contribute Delete
2.06 kB
"""FastAPI application initialization and router aggregation for B2D."""
from __future__ import annotations
from contextlib import asynccontextmanager
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse
from agentic_core.llm import LLMProviderError
from agentic_core.orchestrator import DiscoveryError, OrchestrationError
from .deps import services
from .routers import artifacts, discovery, generation, health, projects
@asynccontextmanager
async def lifespan(_app: FastAPI):
yield
await services.provider.aclose()
app = FastAPI(
title="B2D — Business to Development API",
version="0.1.0",
description="Autonomous multi-agent platform converting business ideas into production blueprints.",
lifespan=lifespan,
)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_methods=["*"],
allow_headers=["*"],
)
# Custom exception handlers
@app.exception_handler(DiscoveryError)
async def discovery_error_handler(_request, exc: DiscoveryError):
return JSONResponse(
status_code=502,
content={"detail": "Discovery agent error", "error": str(exc)},
)
@app.exception_handler(OrchestrationError)
async def orchestration_error_handler(_request, exc: OrchestrationError):
return JSONResponse(
status_code=409,
content={"detail": "Orchestration error", "error": str(exc)},
)
@app.exception_handler(LLMProviderError)
async def llm_provider_error_handler(_request, exc: LLMProviderError):
return JSONResponse(
status_code=503,
content={"detail": "LLM provider error", "error": str(exc)},
)
# Include modular routers
app.include_router(health.router)
app.include_router(projects.router)
app.include_router(discovery.router)
app.include_router(generation.router)
app.include_router(artifacts.router)
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)