God Mode+ v3 fix: api/routes/agents.py
Browse files1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798"""God Agent Orchestrator API Routes"""from fastapi import APIRouter, Request, HTTPExceptionfrom pydantic import BaseModelfrom typing import Optional, Dict, Anyrouter = APIRouter()class OrchestrateRequest(BaseModel):message: strsession_id: str = ""task_id: str = ""context: Dict[str, Any] = {}class SandboxExecRequest(BaseModel):command: strcwd: str = ""timeout: int = 30class FileWriteRequest(BaseModel):filename: strcontent: str@router.post("/orchestrate")async def orchestrate(req: OrchestrateRequest, request: Request):"""Route message through God Agent Orchestrator."""orchestrator = getattr(request.app.state, "orchestrator", None)if not orchestrator:raise HTTPException(500, "Orchestrator not initialized")result = await orchestrator.orchestrate(user_message=req.message,session_id=req.session_id,task_id=req.task_id,context=req.context,)return {"result": result, "session_id": req.session_id}@router.get("/status")async def agent_status(request: Request):"""Get all agent statuses."""orchestrator = getattr(request.app.state, "orchestrator", None)if not orchestrator:return {"status": "not_initialized"}return orchestrator.get_status()@router.post("/sandbox/execute")async def sandbox_execute(req: SandboxExecRequest, request: Request):"""Execute command in sandbox."""orchestrator = getattr(request.app.state, "orchestrator", None)if not orchestrator:raise HTTPException(500, "Orchestrator not initialized")sandbox = orchestrator.get_agent("sandbox")if not sandbox:raise HTTPException(503, "SandboxAgent not available")result = await sandbox.execute(req.command, cwd=req.cwd, timeout=req.timeout)return {"result": result, "command": req.command}@router.post("/sandbox/file")async def sandbox_write_file(req: FileWriteRequest, request: Request):"""Write file to sandbox workspace."""orchestrator = getattr(request.app.state, "orchestrator", None)if not orchestrator:raise HTTPException(500, "Orchestrator not initialized")sandbox = orchestrator.get_agent("sandbox")if not sandbox:raise HTTPException(503, "SandboxAgent not available")result = await sandbox.write_file(req.filename, req.content)return {"result": result, "filename": req.filename}@router.get("/sandbox/workspace")async def sandbox_workspace(request: Request):"""Get workspace info."""orchestrator = getattr(request.app.state, "orchestrator", None)if not orchestrator:raise HTTPException(500, "Orchestrator not initialized")sandbox = orchestrator.get_agent("sandbox")if not sandbox:raise HTTPException(503, "SandboxAgent not available")info = await sandbox.get_workspace_info()return info@router.get("/ai-router/stats")async def ai_router_stats(request: Request):"""Get AI router statistics."""ai_router = getattr(request.app.state, "ai_router", None)if not ai_router:return {"stats": {}}return {"stats": ai_router.get_stats()}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108"""Agents routes β sandbox, ai-router, orchestrate endpoints"""import timefrom fastapi import APIRouter, HTTPException, Requestfrom pydantic import BaseModelfrom typing import Optional, Dict, Anyrouter = APIRouter()def get_orchestrator(request: Request):return request.app.state.orchestratordef get_ai_router(request: Request):return request.app.state.ai_router# βββ Orchestrate ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββclass OrchestrateRequest(BaseModel):message: strsession_id: str = ""context: Dict[str, Any] = {}@router.post("/orchestrate", summary="Route message through God Agent Orchestrator")async def orchestrate(req: OrchestrateRequest, request: Request):orchestrator = get_orchestrator(request)result = await orchestrator.orchestrate(user_message=req.message,session_id=req.session_id,context=req.context,)return {"result": result,"session_id": req.session_id,"timestamp": time.time(),}# βββ Sandbox Execute ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββclass SandboxExecRequest(BaseModel):command: strcwd: str = ""session_id: str = ""@router.post("/sandbox/execute", summary="Execute command in sandbox")async def sandbox_execute(req: SandboxExecRequest, request: Request):orchestrator = get_orchestrator(request)sandbox = orchestrator.get_agent("sandbox")if not sandbox:raise HTTPException(status_code=503, detail="Sandbox agent not available")result = await sandbox.execute(req.command, cwd=req.cwd, session_id=req.session_id)return {"command": req.command, "result": result, "timestamp": time.time()}# βββ Sandbox File Write βββββββββββββββββββββββββββββββββββββββββββββββββββββββclass SandboxFileRequest(BaseModel):filename: strcontent: strsession_id: str = ""@router.post("/sandbox/file", summary="Write file to sandbox workspace")async def sandbox_write_file(req: SandboxFileRequest, request: Request):orchestrator = get_orchestrator(request)sandbox = orchestrator.get_agent("sandbox")if not sandbox:raise HTTPException(status_code=503, detail="Sandbox agent not available")result = await sandbox.write_file(req.filename, req.content, session_id=req.session_id)return {"filename": req.filename, "result": result, "timestamp": time.time()}# βββ Workspace Info βββββββββββββββββββββββββββββββββοΏ½οΏ½βββββββββββββββββββββββββ@router.get("/sandbox/workspace", summary="Get sandbox workspace info")async def sandbox_workspace(request: Request):orchestrator = get_orchestrator(request)sandbox = orchestrator.get_agent("sandbox")if not sandbox:raise HTTPException(status_code=503, detail="Sandbox agent not available")info = await sandbox.get_workspace_info()return info# βββ AI Router Stats βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ@router.get("/ai-router/stats", summary="Get AI Router statistics")async def ai_router_stats(request: Request):ai_router = get_ai_router(request)return {"stats": ai_router.get_stats(),"active_provider": ai_router.get_active_provider(),"timestamp": time.time(),}# βββ Agent Status βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ@router.get("/status", summary="Get all agents status")async def agents_status(request: Request):orchestrator = get_orchestrator(request)return orchestrator.get_status()
api/routes/agents.py+72-62