""" Agent Control Center — Control Plane API Часть 1: управление агентами, задачами, памятью Часть 2: Web UI """ from __future__ import annotations from pathlib import Path from fastapi import FastAPI, HTTPException, WebSocket, WebSocketDisconnect from fastapi.middleware.cors import CORSMiddleware from fastapi.staticfiles import StaticFiles from api import runs, agents, memory, skills, connectors, tasks, accounts import asyncio, json app = FastAPI( title="Agent Control Center", version="0.1.0", description="Control Plane для управления Hermes-агентами", ) app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["*"], allow_headers=["*"]) app.include_router(runs.router) app.include_router(agents.router) app.include_router(memory.router) app.include_router(skills.router) app.include_router(connectors.router) app.include_router(tasks.router) app.include_router(accounts.router) # WebSocket для real-time обновлений @app.websocket("/ws") async def websocket_endpoint(ws: WebSocket): await ws.accept() try: while True: data = await ws.receive_text() msg = json.loads(data) # Echo + broadcast agent status await ws.send_json({"type": "echo", "data": msg}) except WebSocketDisconnect: pass except Exception: pass # Web UI (доступен на /ui) static = Path(__file__).parent / "static" static.mkdir(exist_ok=True) app.mount("/ui", StaticFiles(directory=str(static), html=True), name="static") @app.get("/health") def health(): return {"status": "ok", "version": app.version}