main.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. from __future__ import annotations
  2. from fastapi import FastAPI, HTTPException
  3. from fastapi.middleware.cors import CORSMiddleware
  4. from .contracts import ENUM_CATALOG, SCHEMA_CATALOG
  5. from .fake_data import GRAPH, RUN_ID, node_detail
  6. from .models import NodeDetail, RunGraph, RunSummary
  7. app = FastAPI(title="Script Build Mission Control", version="1.0.0")
  8. app.add_middleware(
  9. CORSMiddleware,
  10. allow_origins=["http://127.0.0.1:3008", "http://localhost:3008"],
  11. allow_methods=["GET"],
  12. allow_headers=["*"],
  13. )
  14. @app.get("/api/health")
  15. def health() -> dict[str, str]:
  16. return {"status": "ok", "data_mode": "fake", "schema_version": GRAPH.schema_version}
  17. @app.get("/api/runs", response_model=list[RunSummary])
  18. def runs() -> list[RunSummary]:
  19. return [GRAPH.run]
  20. @app.get("/api/runs/{script_build_id}/graph", response_model=RunGraph)
  21. def graph(script_build_id: int) -> RunGraph:
  22. if script_build_id != RUN_ID:
  23. raise HTTPException(status_code=404, detail="Fake run not found")
  24. return GRAPH
  25. @app.get("/api/runs/{script_build_id}/nodes/{node_id:path}", response_model=NodeDetail)
  26. def detail(script_build_id: int, node_id: str) -> NodeDetail:
  27. if script_build_id != RUN_ID:
  28. raise HTTPException(status_code=404, detail="Fake run not found")
  29. value = node_detail(node_id)
  30. if value is None:
  31. raise HTTPException(status_code=404, detail="Fake node not found")
  32. return value
  33. @app.get("/api/schema-catalog")
  34. def schema_catalog() -> dict[str, object]:
  35. return {
  36. "data_mode": "fake",
  37. "schemas": {key: list(value) for key, value in SCHEMA_CATALOG.items()},
  38. "enums": {key: list(value) for key, value in ENUM_CATALOG.items()},
  39. }