""" 人类输入 API 路由 """ from fastapi import APIRouter, HTTPException from pydantic import BaseModel from typing import List, Optional from app.services.human_input import get_human_input_service router = APIRouter() # ========== 请求/响应模型 ========== class TaskRequest(BaseModel): """任务请求""" content: str from_user: str = "user001" priority: str = "medium" title: str = "" target_files: List[str] = [] suggested_agent: str = "" urgent: bool = False class CommentRequest(BaseModel): """评论请求""" meeting_id: str content: str from_user: str = "user001" comment_type: str = "proposal" priority: str = "normal" class ParticipantRegister(BaseModel): """参与者注册""" user_id: str name: str role: str = "" avatar: str = "👤" class UserStatusUpdate(BaseModel): """用户状态更新""" status: str current_focus: str = "" # ========== API 端点 ========== @router.get("/summary") async def get_summary(): """获取人类输入服务摘要""" service = get_human_input_service() summary = await service.get_summary() return summary @router.post("/register") async def register_participant(request: ParticipantRegister): """注册人类参与者""" service = get_human_input_service() await service.register_participant( request.user_id, request.name, request.role, request.avatar ) return {"success": True, "user_id": request.user_id} @router.get("/participants") async def get_participants(): """获取所有参与者""" service = get_human_input_service() participants = await service.get_participants() return { "participants": [ { "id": p.id, "name": p.name, "role": p.role, "status": p.status, "avatar": p.avatar } for p in participants ] } @router.post("/tasks") async def add_task_request(request: TaskRequest): """提交任务请求""" service = get_human_input_service() task_id = await service.add_task_request( from_user=request.from_user, content=request.content, priority=request.priority, title=request.title, target_files=request.target_files, suggested_agent=request.suggested_agent, urgent=request.urgent ) return {"success": True, "task_id": task_id} @router.get("/tasks") async def get_pending_tasks( priority: Optional[str] = None, agent: Optional[str] = None ): """获取待处理任务""" service = get_human_input_service() tasks = await service.get_pending_tasks( priority_filter=priority, agent_filter=agent ) return { "tasks": [ { "id": t.id, "from_user": t.from_user, "timestamp": t.timestamp, "priority": t.priority, "type": t.type, "title": t.title, "content": t.content, "target_files": t.target_files, "suggested_agent": t.suggested_agent, "urgent": t.urgent, "is_urgent": t.is_urgent } for t in tasks ], "count": len(tasks) } @router.get("/tasks/urgent") async def get_urgent_tasks(): """获取紧急任务""" service = get_human_input_service() tasks = await service.get_urgent_tasks() return { "tasks": [ { "id": t.id, "from_user": t.from_user, "content": t.content, "title": t.title, "suggested_agent": t.suggested_agent } for t in tasks ], "count": len(tasks) } @router.put("/tasks/{task_id}/processing") async def mark_task_processing(task_id: str): """标记任务为处理中""" service = get_human_input_service() success = await service.mark_task_processing(task_id) if not success: raise HTTPException(status_code=404, detail="Task not found") return {"success": True} @router.put("/tasks/{task_id}/complete") async def mark_task_completed(task_id: str): """标记任务为已完成""" service = get_human_input_service() success = await service.mark_task_completed(task_id) if not success: raise HTTPException(status_code=404, detail="Task not found") return {"success": True} @router.post("/comments") async def add_meeting_comment(request: CommentRequest): """提交会议评论""" service = get_human_input_service() comment_id = await service.add_meeting_comment( from_user=request.from_user, meeting_id=request.meeting_id, content=request.content, comment_type=request.comment_type, priority=request.priority ) return {"success": True, "comment_id": comment_id} @router.get("/comments") async def get_pending_comments(meeting_id: Optional[str] = None): """获取待处理评论""" service = get_human_input_service() comments = await service.get_pending_comments(meeting_id) return { "comments": [ { "id": c.id, "from_user": c.from_user, "meeting_id": c.meeting_id, "timestamp": c.timestamp, "type": c.type, "priority": c.priority, "content": c.content } for c in comments ], "count": len(comments) } @router.put("/comments/{comment_id}/addressed") async def mark_comment_addressed(comment_id: str): """标记评论为已处理""" service = get_human_input_service() success = await service.mark_comment_addressed(comment_id) if not success: raise HTTPException(status_code=404, detail="Comment not found") return {"success": True} @router.put("/users/{user_id}/status") async def update_user_status(user_id: str, request: UserStatusUpdate): """更新用户状态""" service = get_human_input_service() success = await service.update_user_status( user_id, request.status, request.current_focus ) if not success: raise HTTPException(status_code=404, detail="User not found") return {"success": True}