Spaces:
Running
Running
File size: 2,555 Bytes
94abee9 49e1ab7 f17c49d 94abee9 f17c49d 49e1ab7 94abee9 f17c49d 49e1ab7 94abee9 f17c49d 94abee9 f17c49d 94abee9 f17c49d 94abee9 49e1ab7 94abee9 49e1ab7 94abee9 49e1ab7 94abee9 49e1ab7 94abee9 49e1ab7 94abee9 49e1ab7 b2106a4 3bed78a b2106a4 94abee9 49e1ab7 b2106a4 94abee9 f17c49d 49e1ab7 | 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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | # main.py (versión actualizada – copia-pega completa)
from fastapi import FastAPI, Request, Body
from fastapi.responses import HTMLResponse, JSONResponse
from fastapi.staticfiles import StaticFiles
from pathlib import Path
from datetime import datetime
from agents.manager import plan_mission
from agents.specialized import run_specialized_agent
from agents.registry import AGENT_REGISTRY # asegúrate de tener este archivo
app = FastAPI(title="Mission Control v2 - Docker")
# Servir frontend
templates_dir = Path("templates")
if templates_dir.exists():
app.mount("/static", StaticFiles(directory=templates_dir), name="static") # ajusta si usas /templates o /static
@app.get("/", response_class=HTMLResponse)
async def root():
index_path = templates_dir / "index.html"
if index_path.exists():
return index_path.read_text(encoding="utf-8")
return HTMLResponse(content="<h1>Mission Control v2 – Frontend no encontrado</h1>")
@app.get("/health")
async def health():
return {"status": "ok", "docker": True, "time": datetime.now().isoformat()}
@app.get("/api/agents")
async def list_agents():
return {"agents": [{"key": k, "name": v.get("name", k)} for k, v in AGENT_REGISTRY.items()]}
@app.post("/api/mission")
async def create_mission(request: Request):
data = await request.json()
task = data.get("task", "").strip()
if not task:
return JSONResponse({"error": "No task provided"}, status_code=400)
# Planificar con el manager
plan = await plan_mission(task)
# Ejecutar agentes delegados
results = []
for agent_key in plan.get("delegate", []):
result = await run_specialized_agent(agent_key, task)
results.append(result)
file_path = None
if results and results[0].get("file_path"):
file_path = results[0]["file_path"]
# Guardar en DB
from core.storage import save_mission
mission_data = {
"task": task,
"started_at": datetime.now().isoformat(), # o usa el que ya tengas
"ended_at": datetime.now().isoformat(),
"results": results, # lista de dicts
"doc_file": file_path, # path o None
"events": [] # si tienes logs de eventos, ponlos aquí
}
save_mission(mission_data) # ← ahora sí pasa un solo dict
return JSONResponse({
"success": True,
"task": task,
"plan": plan,
"results": results,
"file_path": file_path
})
print("Mission Control v2 - Docker iniciado") |