File size: 2,971 Bytes
8aeaeba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
925ac0d
 
 
 
8aeaeba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
from fastapi import FastAPI, Request
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

app = FastAPI(title="Mission Control Aetheris")

# ─────────────────────────────
# STATIC
# ─────────────────────────────
templates_dir = Path("templates")
docs_dir = Path("data/docs")

if docs_dir.exists():
    app.mount("/docs", StaticFiles(directory=docs_dir), name="docs")

@app.get("/", response_class=HTMLResponse)
async def root():
    return (templates_dir / "code.html").read_text(encoding="utf-8")

# ─────────────────────────────
# HEALTH
# ─────────────────────────────
@app.get("/health")
async def health():
    return {"status": "ok"}

# ─────────────────────────────
# MANAGER (CHAT)
# ─────────────────────────────
@app.post("/api/manager")
async def manager_only(request: Request):
    data = await request.json()
    task = data.get("task", "").strip()

    if not task:
        return JSONResponse({"error": "No task"}, status_code=400)

    plan = await plan_mission(task)

    return {
        "response": plan.get("reasoning"),
        "delegate": plan.get("delegate"),
        "raw": plan.get("raw")
        
        # Nuevo aΓ±adido eliminar estas dos lineas despues de fallo
        "provider": "HuggingFace Router",
        "model": "Qwen/Qwen2.5-7B-Instruct"
    }

# ─────────────────────────────
# MISIΓ“N COMPLETA
# ─────────────────────────────
@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)

    plan = await plan_mission(task)

    results = []
    shared_context = {}

    for agent_key in plan.get("delegate", []):
        result = await run_specialized_agent(agent_key, task, context=shared_context)
        results.append(result)

        if result.get("success"):
            shared_context[agent_key] = result.get("response", "")

    # archivo generado
    file_path = None
    for r in results:
        if r.get("file_path"):
            file_path = r["file_path"]
            break

    file_url = f"/docs/{file_path}" if file_path else None

    return {
        "success": True,
        "task": task,
        "plan": plan,
        "results": results,
        "file_url": file_url
    }