|
|
@@ -3,11 +3,10 @@ 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
|
|
|
+from .models import ExecutionView, RunSummary, TaskDetail
|
|
|
+from .real_runs import RunNotFound, agent_data_root, execution_view, list_runs, task_detail
|
|
|
|
|
|
-app = FastAPI(title="Script Build Mission Control", version="1.0.0")
|
|
|
+app = FastAPI(title="Script Build Execution Observer", version="2.0.0")
|
|
|
app.add_middleware(
|
|
|
CORSMiddleware,
|
|
|
allow_origins=["http://127.0.0.1:3008", "http://localhost:3008"],
|
|
|
@@ -18,35 +17,31 @@ app.add_middleware(
|
|
|
|
|
|
@app.get("/api/health")
|
|
|
def health() -> dict[str, str]:
|
|
|
- return {"status": "ok", "data_mode": "fake", "schema_version": GRAPH.schema_version}
|
|
|
+ root = agent_data_root()
|
|
|
+ return {
|
|
|
+ "status": "ok" if root.exists() else "degraded",
|
|
|
+ "data_mode": "persisted-real-run",
|
|
|
+ "schema_version": "script-build-execution-view/v1",
|
|
|
+ "agent_data_root": str(root),
|
|
|
+ }
|
|
|
|
|
|
|
|
|
@app.get("/api/runs", response_model=list[RunSummary])
|
|
|
def runs() -> list[RunSummary]:
|
|
|
- return [GRAPH.run]
|
|
|
-
|
|
|
+ return list_runs()
|
|
|
|
|
|
-@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}/execution", response_model=ExecutionView)
|
|
|
+def execution(script_build_id: int) -> ExecutionView:
|
|
|
+ try:
|
|
|
+ return execution_view(script_build_id)
|
|
|
+ except RunNotFound as exc:
|
|
|
+ raise HTTPException(status_code=404, detail=str(exc)) from exc
|
|
|
|
|
|
-@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()},
|
|
|
- }
|
|
|
+@app.get("/api/runs/{script_build_id}/tasks/{task_id}", response_model=TaskDetail)
|
|
|
+def detail(script_build_id: int, task_id: str) -> TaskDetail:
|
|
|
+ try:
|
|
|
+ return task_detail(script_build_id, task_id)
|
|
|
+ except RunNotFound as exc:
|
|
|
+ raise HTTPException(status_code=404, detail=str(exc)) from exc
|