Spaces:
Sleeping
Sleeping
File size: 1,815 Bytes
f5d03aa | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | from pathlib import Path
from dotenv import load_dotenv
from fastapi import FastAPI, HTTPException
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import FileResponse
from fastapi.staticfiles import StaticFiles
from .engine import WorkflowEngine
from .models import ResumeRequest, RunResponse, StartRequest, Workflow
load_dotenv()
app = FastAPI(title="Agentic Workflow Lab", version="1.0.0")
app.add_middleware(CORSMiddleware, allow_origins=["http://localhost:5173"], allow_methods=["*"], allow_headers=["*"])
engine = WorkflowEngine()
@app.get("/api/health")
def health() -> dict[str, str]:
return {"status": "ok"}
@app.post("/api/run", response_model=RunResponse)
def run(request: StartRequest) -> RunResponse:
try:
return engine.start(request)
except Exception as exc:
raise HTTPException(status_code=400, detail=str(exc)) from exc
@app.post("/api/resume", response_model=RunResponse)
def resume(request: ResumeRequest) -> RunResponse:
try:
return engine.resume(request.run_id, request.response)
except Exception as exc:
raise HTTPException(status_code=400, detail=str(exc)) from exc
@app.post("/api/workflows/validate", response_model=Workflow)
def validate_workflow(workflow: Workflow) -> Workflow:
try:
engine._validate(workflow)
return workflow
except Exception as exc:
raise HTTPException(status_code=400, detail=str(exc)) from exc
dist = Path(__file__).resolve().parents[1] / "frontend" / "dist"
if dist.exists():
app.mount("/assets", StaticFiles(directory=dist / "assets"), name="assets")
@app.get("/{path:path}")
def spa(path: str) -> FileResponse:
requested = dist / path
return FileResponse(requested if requested.is_file() else dist / "index.html")
|