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()}