mirror of
https://github.com/Sea-Haven-Industries/open-swe.git
synced 2026-09-30 11:33:14 +00:00
58 lines
2 KiB
Python
58 lines
2 KiB
Python
|
|
"""FastAPI application composition."""
|
||
|
|
|
||
|
|
import os
|
||
|
|
from collections.abc import AsyncIterator
|
||
|
|
from contextlib import asynccontextmanager
|
||
|
|
|
||
|
|
from fastapi import FastAPI
|
||
|
|
from fastapi.middleware.cors import CORSMiddleware
|
||
|
|
|
||
|
|
from ..dashboard import router as dashboard_router
|
||
|
|
from ..dashboard.plan_api import plan_router
|
||
|
|
from ..dashboard.workflow_approval_api import workflow_approval_router
|
||
|
|
from ..webhooks.confluence_routes import router as confluence_webhook_router
|
||
|
|
from ..webhooks.github_routes import router as github_webhook_router
|
||
|
|
from ..webhooks.jira_routes import router as jira_webhook_router
|
||
|
|
from ..webhooks.linear_routes import router as linear_webhook_router
|
||
|
|
from ..webhooks.slack_routes import router as slack_webhook_router
|
||
|
|
from .health import router as health_router
|
||
|
|
|
||
|
|
|
||
|
|
@asynccontextmanager
|
||
|
|
async def lifespan(_app: FastAPI) -> AsyncIterator[None]:
|
||
|
|
from ..utils.model import validate_local_dev_llm_config
|
||
|
|
from ..utils.sandbox import validate_sandbox_startup_config
|
||
|
|
|
||
|
|
validate_sandbox_startup_config()
|
||
|
|
validate_local_dev_llm_config()
|
||
|
|
yield
|
||
|
|
|
||
|
|
|
||
|
|
app = FastAPI(lifespan=lifespan)
|
||
|
|
|
||
|
|
DASHBOARD_ALLOWED_ORIGINS: list[str] = [
|
||
|
|
o.strip() for o in os.environ.get("DASHBOARD_ALLOWED_ORIGINS", "").split(",") if o.strip()
|
||
|
|
]
|
||
|
|
if DASHBOARD_ALLOWED_ORIGINS:
|
||
|
|
if "*" in DASHBOARD_ALLOWED_ORIGINS:
|
||
|
|
raise RuntimeError(
|
||
|
|
"DASHBOARD_ALLOWED_ORIGINS must not include '*' when allow_credentials=True"
|
||
|
|
)
|
||
|
|
app.add_middleware(
|
||
|
|
CORSMiddleware,
|
||
|
|
allow_origins=DASHBOARD_ALLOWED_ORIGINS,
|
||
|
|
allow_credentials=True,
|
||
|
|
allow_methods=["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"],
|
||
|
|
allow_headers=["*"],
|
||
|
|
)
|
||
|
|
|
||
|
|
app.include_router(dashboard_router)
|
||
|
|
app.include_router(plan_router)
|
||
|
|
app.include_router(workflow_approval_router)
|
||
|
|
app.include_router(linear_webhook_router)
|
||
|
|
app.include_router(jira_webhook_router)
|
||
|
|
app.include_router(confluence_webhook_router)
|
||
|
|
app.include_router(slack_webhook_router)
|
||
|
|
app.include_router(health_router)
|
||
|
|
app.include_router(github_webhook_router)
|