arnavzz
feat: add interactive landing page with live debug arena
b450c0e
Raw
History Blame Contribute Delete
1.73 kB
from pathlib import Path
from fastapi import FastAPI, HTTPException
from fastapi.responses import HTMLResponse
from ..models import (
DebugState,
ResetRequest,
ResetResponse,
StepRequest,
StepResponse,
)
from .environment import CodeDebugEnvironment
app = FastAPI(
title="Code Debug OpenEnv",
description="An OpenEnv environment where an AI agent debugs broken Python code.",
version="1.0.0",
)
env = CodeDebugEnvironment()
_STATIC_DIR = Path(__file__).parent.parent / "static"
_INDEX_HTML = (_STATIC_DIR / "index.html").read_text(encoding="utf-8")
@app.get("/", response_class=HTMLResponse)
async def landing():
return _INDEX_HTML
@app.get("/health")
async def health():
return {"status": "healthy", "tasks_loaded": len(env.tasks)}
@app.get("/tasks")
async def list_tasks():
return env.list_tasks()
@app.post("/reset", response_model=ResetResponse)
async def reset(req: ResetRequest = None):
if req is None:
req = ResetRequest()
try:
return env.reset(task_id=req.task_id, seed=req.seed)
except KeyError as e:
raise HTTPException(status_code=404, detail=str(e))
@app.post("/step/{episode_id}", response_model=StepResponse)
async def step(episode_id: str, req: StepRequest):
try:
return env.step(episode_id, req.action.code)
except KeyError as e:
raise HTTPException(status_code=404, detail=str(e))
except ValueError as e:
raise HTTPException(status_code=400, detail=str(e))
@app.get("/state/{episode_id}", response_model=DebugState)
async def state(episode_id: str):
try:
return env.state(episode_id)
except KeyError as e:
raise HTTPException(status_code=404, detail=str(e))