重构 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>
This commit is contained in:
@@ -1,48 +1,64 @@
|
||||
"""
|
||||
心跳管理 API 路由
|
||||
接入 HeartbeatService 服务,监控 Agent 活跃状态
|
||||
"""
|
||||
from fastapi import APIRouter
|
||||
from pydantic import BaseModel
|
||||
from typing import Dict
|
||||
import time
|
||||
from typing import Optional
|
||||
|
||||
from ..services.heartbeat import get_heartbeat_service
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
heartbeats_db = {}
|
||||
|
||||
|
||||
class Heartbeat(BaseModel):
|
||||
agent_id: str
|
||||
timestamp: float
|
||||
is_timeout: bool = False
|
||||
class HeartbeatUpdate(BaseModel):
|
||||
status: str = "idle"
|
||||
current_task: Optional[str] = ""
|
||||
progress: Optional[int] = 0
|
||||
|
||||
|
||||
@router.get("")
|
||||
@router.get("/")
|
||||
async def list_heartbeats():
|
||||
"""获取所有 Agent 心跳"""
|
||||
return {
|
||||
"heartbeats": {
|
||||
"claude-001": {
|
||||
"agent_id": "claude-001",
|
||||
"timestamp": time.time() - 30,
|
||||
"is_timeout": False
|
||||
},
|
||||
"kimi-001": {
|
||||
"agent_id": "kimi-001",
|
||||
"timestamp": time.time() - 60,
|
||||
"is_timeout": False
|
||||
}
|
||||
service = get_heartbeat_service()
|
||||
all_hb = await service.get_all_heartbeats()
|
||||
heartbeats = {}
|
||||
for agent_id, hb in all_hb.items():
|
||||
heartbeats[agent_id] = {
|
||||
"agent_id": hb.agent_id,
|
||||
"last_heartbeat": hb.last_heartbeat,
|
||||
"status": hb.status,
|
||||
"current_task": hb.current_task,
|
||||
"progress": hb.progress,
|
||||
"elapsed_display": hb.elapsed_display,
|
||||
"is_timeout": hb.is_timeout()
|
||||
}
|
||||
}
|
||||
return {"heartbeats": heartbeats}
|
||||
|
||||
|
||||
@router.post("/{agent_id}")
|
||||
async def update_heartbeat(agent_id: str):
|
||||
async def update_heartbeat(agent_id: str, data: HeartbeatUpdate = None):
|
||||
"""更新 Agent 心跳"""
|
||||
heartbeats_db[agent_id] = {
|
||||
"agent_id": agent_id,
|
||||
"timestamp": time.time(),
|
||||
"is_timeout": False
|
||||
}
|
||||
service = get_heartbeat_service()
|
||||
if data is None:
|
||||
data = HeartbeatUpdate()
|
||||
await service.update_heartbeat(
|
||||
agent_id=agent_id,
|
||||
status=data.status,
|
||||
current_task=data.current_task or "",
|
||||
progress=data.progress or 0
|
||||
)
|
||||
return {"success": True}
|
||||
|
||||
|
||||
@router.get("/timeouts")
|
||||
async def check_timeouts(timeout_seconds: int = 60):
|
||||
"""检查超时的 Agent"""
|
||||
service = get_heartbeat_service()
|
||||
timeout_agents = await service.check_timeout(timeout_seconds)
|
||||
return {
|
||||
"timeout_seconds": timeout_seconds,
|
||||
"timeout_agents": timeout_agents,
|
||||
"count": len(timeout_agents)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user