Spaces:
Sleeping
Sleeping
File size: 1,158 Bytes
2e818da | 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 | from fastapi import APIRouter
from pydantic import BaseModel
from app.agents.tutor_agent import TutorAgent
from app.agents.shell_visual_engine import ShellVisualEngine
router = APIRouter(prefix="/sandbox", tags=["sandbox"])
_tutor: TutorAgent | None = None
_shell: ShellVisualEngine | None = None
def _get_tutor() -> TutorAgent:
global _tutor
if _tutor is None:
_tutor = TutorAgent()
return _tutor
def _get_shell() -> ShellVisualEngine:
global _shell
if _shell is None:
_shell = ShellVisualEngine()
return _shell
class RepairRequest(BaseModel):
original_html: str
error_message: str
node_id: str = ""
animation_type: str = "canvas"
@router.post("/repair")
def repair_visual(req: RepairRequest):
if req.animation_type in ("3d", "2d_anim"):
shell_visual = _get_shell().repair_setup_code(
req.original_html, req.animation_type, req.error_message
)
if shell_visual is not None:
return {"visual": shell_visual.model_dump()}
visual = _get_tutor().repair_visual(req.original_html, req.error_message)
return {"visual": visual.model_dump()}
|