mirror of
https://github.com/Sea-Haven-Industries/open-swe.git
synced 2026-09-30 13:53:15 +00:00
Plan step C4 (docs/upstream-sync/domain-reorg/reorg-build-plan.md, approved
decisions 1-2): split the 2,590-line agent/webapp.py monolith into
agent/webhooks/common.py (shared verify/dispatch helpers), agent/api/app.py
(composition), agent/api/health.py (/health + /webhooks/run-complete), and
per-source {github,linear,slack,jira,confluence}_routes.py. Atlassian
Connect lifecycle + descriptor routes (/connect/*) fold into
confluence_routes.py; webapp.py becomes the upstream-shaped compatibility
shim (from .api.app import app). langgraph.json http.app stays
agent.webapp:app via the shim.
Fork content, upstream layout: linear/slack route files verified
content-identical to upstream 8356eb34 and taken verbatim; github_routes is
upstream + the fork's CI auto-fix trigger wiring; jira/confluence routes are
fork-only, transformed to the same common.X / service.X module-attribute
style. All signature verification (GitHub HMAC, Slack, Linear
timestamp-freshness, verify_jira_secret + opt-in HMAC/timestamp/IP
allowlist, Connect JWT/qsh), token-attribution gating, TID-COLLIDE-01 repo
binding, _is_repo_auto_review_enabled gates, and public-repo org gate move
unchanged.
Handlers rewired from webapp.X to common.X; test monkeypatch sites across
26 files + conftest.py + e2e/harness.py retargeted to
webhook_common/handler/route modules per upstream's pattern. Residual
agent.webapp importers: only the shim, langgraph.json http.app, Makefile
uvicorn target, and docs (doc-path updates land in C7).
Gates: ruff check + format, pytest --co, full unit (1637 passed), full
Playwright E2E vs real langgraph dev (9/9), residual-importer sweep.
57 lines
2 KiB
Python
57 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)
|