feat: skip task

This commit is contained in:
a7m-1st 2025-10-13 03:04:55 +03:00
parent 6aeff827aa
commit f1f6d68f0d
4 changed files with 39 additions and 4 deletions

View file

@ -19,6 +19,7 @@ from app.service.task import (
ActionSupplementData,
ActionAddTaskData,
ActionRemoveTaskData,
ActionSkipTaskData,
get_or_create_task_lock,
get_task_lock,
)
@ -161,3 +162,23 @@ def remove_task(project_id: str, task_id: str):
except Exception as e:
chat_logger.error(f"Error removing task {task_id} for project_id: {project_id}: {e}")
raise UserException(code.error, f"Failed to remove task: {str(e)}")
@router.post("/chat/{project_id}/skip-task", name="skip task in workforce")
@traceroot.trace()
def skip_task(project_id: str):
"""Skip a task in the workforce"""
chat_logger.info(f"Skipping task in workforce for project_id: {project_id}")
task_lock = get_task_lock(project_id)
try:
# Queue the skip task action
skip_task_action = ActionSkipTaskData(project_id=project_id)
asyncio.run(task_lock.put_queue(skip_task_action))
chat_logger.info(f"Task skip request queued for project_id: {project_id}")
return Response(status_code=201)
except Exception as e:
chat_logger.error(f"Error skipping task for project_id: {project_id}: {e}")
raise UserException(code.error, f"Failed to skip task: {str(e)}")

View file

@ -148,6 +148,13 @@ async def step_solve(options: Chat, request: Request, task_lock: TaskLock):
"task_id": item.task_id
}
yield sse_json("remove_task", returnData)
elif item.action == Action.skip_task:
if workforce is not None and item.project_id == options.project_id:
if workforce._state.name == 'PAUSED':
# Resume paused workforce to skip the task
logger.info(f"[CHAT] Resuming paused workforce to skip task")
workforce.resume()
workforce.skip_gracefully()
elif item.action == Action.start:
if workforce is not None and workforce._state.name == 'PAUSED':
# Resume paused workforce - subtasks should already be loaded

View file

@ -39,6 +39,7 @@ class Action(str, Enum):
budget_not_enough = "budget_not_enough" # backend -> user
add_task = "add_task" # user -> backend
remove_task = "remove_task" # user -> backend
skip_task = "skip_task" # user -> backend
class ActionImproveData(BaseModel):
@ -191,6 +192,11 @@ class ActionRemoveTaskData(BaseModel):
project_id: str
class ActionSkipTaskData(BaseModel):
action: Literal[Action.skip_task] = Action.skip_task
project_id: str
ActionData = (
ActionImproveData
| ActionStartData
@ -216,6 +222,7 @@ ActionData = (
| ActionBudgetNotEnough
| ActionAddTaskData
| ActionRemoveTaskData
| ActionSkipTaskData
)

View file

@ -396,11 +396,11 @@ export default function ChatBox(): JSX.Element {
setIsPauseResumeLoading(true);
try {
// Stop the current task
await fetchPut(`/task/${projectStore.activeProjectId}/take-control`, {
action: 'stop',
// Skip the current task
await fetchPost(`/chat/${projectStore.activeProjectId}/skip-task`, {
project_id: projectStore.activeProjectId
});
// Update task status to finished
chatStore.setStatus(taskId, 'finished');
chatStore.setIsPending(taskId, false);