后端: - 重构 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>
83 lines
2.1 KiB
Python
83 lines
2.1 KiB
Python
"""
|
|
文件锁 API 路由
|
|
接入 FileLockService 服务,管理文件的排他锁
|
|
"""
|
|
from fastapi import APIRouter
|
|
from pydantic import BaseModel
|
|
from typing import Optional
|
|
from dataclasses import asdict
|
|
|
|
from ..services.file_lock import get_file_lock_service
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
class LockAcquireRequest(BaseModel):
|
|
file_path: str
|
|
agent_id: str
|
|
agent_name: Optional[str] = ""
|
|
|
|
|
|
class LockReleaseRequest(BaseModel):
|
|
file_path: str
|
|
agent_id: str
|
|
|
|
|
|
@router.get("")
|
|
@router.get("/")
|
|
async def list_locks():
|
|
"""获取所有文件锁列表"""
|
|
service = get_file_lock_service()
|
|
locks = await service.get_locks()
|
|
return {
|
|
"locks": [
|
|
{
|
|
"file_path": lock.file_path,
|
|
"agent_id": lock.agent_id,
|
|
"agent_name": lock.agent_name,
|
|
"acquired_at": lock.acquired_at,
|
|
"elapsed_display": lock.elapsed_display
|
|
}
|
|
for lock in locks
|
|
]
|
|
}
|
|
|
|
|
|
@router.post("/acquire")
|
|
async def acquire_lock(request: LockAcquireRequest):
|
|
"""获取文件锁"""
|
|
service = get_file_lock_service()
|
|
success = await service.acquire_lock(
|
|
file_path=request.file_path,
|
|
agent_id=request.agent_id,
|
|
agent_name=request.agent_name or ""
|
|
)
|
|
if success:
|
|
return {"success": True, "message": "Lock acquired"}
|
|
return {"success": False, "message": "File already locked by another agent"}
|
|
|
|
|
|
@router.post("/release")
|
|
async def release_lock(request: LockReleaseRequest):
|
|
"""释放文件锁"""
|
|
service = get_file_lock_service()
|
|
success = await service.release_lock(
|
|
file_path=request.file_path,
|
|
agent_id=request.agent_id
|
|
)
|
|
if success:
|
|
return {"success": True, "message": "Lock released"}
|
|
return {"success": False, "message": "Lock not found or not owned by this agent"}
|
|
|
|
|
|
@router.get("/check")
|
|
async def check_lock(file_path: str):
|
|
"""检查文件锁定状态"""
|
|
service = get_file_lock_service()
|
|
locked_by = await service.check_locked(file_path)
|
|
return {
|
|
"file_path": file_path,
|
|
"locked": locked_by is not None,
|
|
"locked_by": locked_by
|
|
}
|