Spaces:
Paused
Paused
| """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 | |
| 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 | |
| async def discovery_error_handler(_request, exc: DiscoveryError): | |
| return JSONResponse( | |
| status_code=502, | |
| content={"detail": "Discovery agent error", "error": str(exc)}, | |
| ) | |
| async def orchestration_error_handler(_request, exc: OrchestrationError): | |
| return JSONResponse( | |
| status_code=409, | |
| content={"detail": "Orchestration error", "error": str(exc)}, | |
| ) | |
| 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) | |