from __future__ import annotations from fastapi import FastAPI, HTTPException from fastapi.middleware.cors import CORSMiddleware from .contracts import ENUM_CATALOG, SCHEMA_CATALOG from .fake_data import GRAPH, RUN_ID, node_detail from .models import NodeDetail, RunGraph, RunSummary app = FastAPI(title="Script Build Mission Control", version="1.0.0") app.add_middleware( CORSMiddleware, allow_origins=["http://127.0.0.1:3008", "http://localhost:3008"], allow_methods=["GET"], allow_headers=["*"], ) @app.get("/api/health") def health() -> dict[str, str]: return {"status": "ok", "data_mode": "fake", "schema_version": GRAPH.schema_version} @app.get("/api/runs", response_model=list[RunSummary]) def runs() -> list[RunSummary]: return [GRAPH.run] @app.get("/api/runs/{script_build_id}/graph", response_model=RunGraph) def graph(script_build_id: int) -> RunGraph: if script_build_id != RUN_ID: raise HTTPException(status_code=404, detail="Fake run not found") return GRAPH @app.get("/api/runs/{script_build_id}/nodes/{node_id:path}", response_model=NodeDetail) def detail(script_build_id: int, node_id: str) -> NodeDetail: if script_build_id != RUN_ID: raise HTTPException(status_code=404, detail="Fake run not found") value = node_detail(node_id) if value is None: raise HTTPException(status_code=404, detail="Fake node not found") return value @app.get("/api/schema-catalog") def schema_catalog() -> dict[str, object]: return { "data_mode": "fake", "schemas": {key: list(value) for key, value in SCHEMA_CATALOG.items()}, "enums": {key: list(value) for key, value in ENUM_CATALOG.items()}, }