76 lines
2.0 KiB
Python
76 lines
2.0 KiB
Python
|
|
"""
|
||
|
|
Swarm Command Center - FastAPI 主入口
|
||
|
|
多智能体协作系统的协调层后端服务
|
||
|
|
"""
|
||
|
|
|
||
|
|
from fastapi import FastAPI
|
||
|
|
from fastapi.middleware.cors import CORSMiddleware
|
||
|
|
import uvicorn
|
||
|
|
|
||
|
|
from app.routers import agents, locks, meetings, heartbeats, workflows, resources, roles, humans
|
||
|
|
from app.routers import agents_control, websocket
|
||
|
|
|
||
|
|
# 创建 FastAPI 应用实例
|
||
|
|
app = FastAPI(
|
||
|
|
title="Swarm Command Center API",
|
||
|
|
description="多智能体协作系统的协调层后端服务",
|
||
|
|
version="0.1.0",
|
||
|
|
)
|
||
|
|
|
||
|
|
# 配置 CORS - 允许前端访问
|
||
|
|
app.add_middleware(
|
||
|
|
CORSMiddleware,
|
||
|
|
allow_origins=["http://localhost:3000", "http://127.0.0.1:3000"],
|
||
|
|
allow_credentials=True,
|
||
|
|
allow_methods=["*"],
|
||
|
|
allow_headers=["*"],
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
# 基础健康检查端点
|
||
|
|
@app.get("/")
|
||
|
|
async def root():
|
||
|
|
"""健康检查端点"""
|
||
|
|
return {"status": "ok", "service": "Swarm Command Center"}
|
||
|
|
|
||
|
|
|
||
|
|
@app.get("/health")
|
||
|
|
@app.get("/api/health")
|
||
|
|
async def health():
|
||
|
|
"""详细健康检查"""
|
||
|
|
return {
|
||
|
|
"status": "healthy",
|
||
|
|
"version": "0.1.0",
|
||
|
|
"services": {
|
||
|
|
"api": "ok",
|
||
|
|
"storage": "ok",
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
# 注册 API 路由
|
||
|
|
app.include_router(agents.router, prefix="/api/agents", tags=["agents"])
|
||
|
|
app.include_router(agents_control.router, tags=["agents-control"])
|
||
|
|
app.include_router(locks.router, prefix="/api/locks", tags=["locks"])
|
||
|
|
app.include_router(meetings.router, prefix="/api/meetings", tags=["meetings"])
|
||
|
|
app.include_router(heartbeats.router, prefix="/api/heartbeats", tags=["heartbeats"])
|
||
|
|
app.include_router(workflows.router, prefix="/api/workflows", tags=["workflows"])
|
||
|
|
app.include_router(resources.router, prefix="/api", tags=["resources"])
|
||
|
|
app.include_router(roles.router, prefix="/api/roles", tags=["roles"])
|
||
|
|
app.include_router(humans.router, prefix="/api/humans", tags=["humans"])
|
||
|
|
app.include_router(websocket.router, tags=["websocket"])
|
||
|
|
|
||
|
|
|
||
|
|
def main():
|
||
|
|
"""启动开发服务器"""
|
||
|
|
uvicorn.run(
|
||
|
|
"app.main:app",
|
||
|
|
host="0.0.0.0",
|
||
|
|
port=8000,
|
||
|
|
reload=True,
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
main()
|