-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
110 lines (84 loc) · 3.88 KB
/
Copy pathserver.py
File metadata and controls
110 lines (84 loc) · 3.88 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
"""
Software Factory - FastAPI Server
API REST y WebSocket para conectar con frontend React
"""
from contextlib import asynccontextmanager
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from core.db import db_manager
from core.logger import get_logger
from fastapi.security import OAuth2PasswordBearer
from routers import auth_router, agents_router, internal_router, sessions_router, analytics_router
from routers import extra_router, skills_router, hq_router, playbook_router, memory_router, claw3d_router, schedules_router, context_router, recon_router
logger = get_logger(__name__)
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="api/auth/login")
# ===========================================
# FastAPI App & Endpoints
# ===========================================
from core.agenda_engine import start_scheduler
@asynccontextmanager
async def lifespan(app: FastAPI):
await db_manager.connect()
start_scheduler()
logger.info("TripKode Agents API con MongoDB iniciada. Scheduler activo.")
yield
await db_manager.disconnect()
app = FastAPI(title="TripKode Agents API", lifespan=lifespan)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# --- AUTH ENDPOINTS ---
app.include_router(auth_router)
# --- AGENT ENDPOINTS ---
app.include_router(agents_router)
app.include_router(internal_router)
# --- SESSION ENDPOINTS ---
app.include_router(sessions_router)
# --- ANALYTICS ENDPOINTS ---
app.include_router(analytics_router)
# --- EXTRA ENDPOINTS ---
app.include_router(extra_router)
app.include_router(skills_router)
app.include_router(hq_router)
app.include_router(playbook_router)
app.include_router(memory_router)
# --- CLAW3D ENDPOINTS ---
app.include_router(claw3d_router)
app.include_router(schedules_router)
app.include_router(context_router)
app.include_router(recon_router)
# ===========================================
# EJECUCIÓN
# ===========================================
if __name__ == "__main__":
import asyncio
import sys
import uvicorn
# Evita ruido frecuente de Proactor en Windows (WinError 10054) al cerrar sockets.
if sys.platform.startswith("win"):
try:
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) # type: ignore[attr-defined]
except Exception:
pass
print("""
╔══════════════════════════════════════════════════════════╗
║ TripKode Agents API - Iniciando ║
╠══════════════════════════════════════════════════════════╣
║ Endpoints: ║
║ • POST /api/generate - Iniciar pipeline ║
║ • GET /api/status/{id} - Estado del pipeline ║
║ • GET /api/sessions - Listar sesiones ║
║ • WS /api/ws/{session_id} - WebSocket para updates ║
║ • GET /health - Health check ║
╠══════════════════════════════════════════════════════════╣
║ Ejemplo de uso: ║
║ curl -X POST http://localhost:8000/api/generate \\ ║
║ -H "Content-Type: application/json" \\ ║
║ -d '{"prompt": "Crea una API REST para tareas"}' ║
╚══════════════════════════════════════════════════════════╝
""")
uvicorn.run(app, host="0.0.0.0", port=8000)