Files
multiAgentTry/backend/app/main.py
Claude Code 1719d1f1f9 重构 API 路由并新增工作流编排功能
后端:
- 重构 agents, heartbeats, locks, meetings, resources, roles, workflows 路由
- 新增 orchestrator 和 providers 路由
- 新增 CLI 调用器和流程编排服务
- 添加日志配置和依赖项

前端:
- 更新 AgentsPage、SettingsPage、WorkflowPage 页面
- 扩展 api.ts 新增 API 接口

其他:
- 清理测试 agent 数据文件
- 新增示例工作流和项目审计报告

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 16:36:25 +08:00

90 lines
2.6 KiB
Python

"""
Swarm Command Center - FastAPI 主入口
多智能体协作系统的协调层后端服务
"""
import logging
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import uvicorn
logging.basicConfig(level=logging.INFO, format="%(levelname)s:%(name)s: %(message)s")
from app.routers import agents, locks, meetings, heartbeats, workflows, resources, roles, humans
from app.routers import agents_control, websocket, orchestrator, providers
# 创建 FastAPI 应用实例
app = FastAPI(
title="Swarm Command Center API",
description="多智能体协作系统的协调层后端服务",
version="0.1.0",
)
# 配置 CORS - 允许前端访问
app.add_middleware(
CORSMiddleware,
allow_origins=[ # 必须具体列出,不能使用 * 当 allow_credentials=True
"http://localhost:3000",
"http://localhost:3001",
"http://127.0.0.1:3000",
"http://127.0.0.1:3001",
"http://localhost:5173",
"http://127.0.0.1:5173",
"http://localhost:8080",
],
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"])
app.include_router(orchestrator.router, prefix="/api", tags=["orchestrator"])
app.include_router(providers.router, prefix="/api", tags=["providers"])
def main():
"""启动开发服务器"""
uvicorn.run(
"app.main:app",
host="0.0.0.0",
port=8000,
reload=True,
)
if __name__ == "__main__":
main()