File size: 2,063 Bytes
287f3d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"""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)