feat: support batch todo updates
This commit is contained in:
parent
b81e14b314
commit
9ded11de7a
@ -1721,14 +1721,21 @@ class MainTerminal:
|
|||||||
"type": "function",
|
"type": "function",
|
||||||
"function": {
|
"function": {
|
||||||
"name": "todo_update_task",
|
"name": "todo_update_task",
|
||||||
"description": "勾选或取消指定任务;全部勾选时提示所有任务已完成。",
|
"description": "批量勾选或取消任务(支持单个或多个任务);全部勾选时提示所有任务已完成。",
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": self._inject_intent({
|
"properties": self._inject_intent({
|
||||||
"task_index": {"type": "integer", "description": "任务序号(1-8)"},
|
"task_index": {"type": "integer", "description": "任务序号(1-8),兼容旧参数"},
|
||||||
|
"task_indices": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {"type": "integer"},
|
||||||
|
"minItems": 1,
|
||||||
|
"maxItems": 8,
|
||||||
|
"description": "要更新的任务序号列表(1-8),可一次勾选多个"
|
||||||
|
},
|
||||||
"completed": {"type": "boolean", "description": "true=打勾,false=取消"}
|
"completed": {"type": "boolean", "description": "true=打勾,false=取消"}
|
||||||
}),
|
}),
|
||||||
"required": ["task_index", "completed"]
|
"required": ["completed"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -2349,8 +2356,11 @@ class MainTerminal:
|
|||||||
)
|
)
|
||||||
|
|
||||||
elif tool_name == "todo_update_task":
|
elif tool_name == "todo_update_task":
|
||||||
|
task_indices = arguments.get("task_indices")
|
||||||
|
if task_indices is None:
|
||||||
|
task_indices = arguments.get("task_index")
|
||||||
result = self.todo_manager.update_task_status(
|
result = self.todo_manager.update_task_status(
|
||||||
task_index=arguments.get("task_index"),
|
task_indices=task_indices,
|
||||||
completed=arguments.get("completed", True)
|
completed=arguments.get("completed", True)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -109,20 +109,43 @@ class TodoManager:
|
|||||||
"todo_list": todo
|
"todo_list": todo
|
||||||
}
|
}
|
||||||
|
|
||||||
def update_task_status(self, task_index: int, completed: bool) -> Dict[str, Any]:
|
def update_task_status(self, task_indices: Any, completed: bool) -> Dict[str, Any]:
|
||||||
todo = self._get_current()
|
todo = self._get_current()
|
||||||
if not todo:
|
if not todo:
|
||||||
return {"success": False, "error": "当前没有待办列表,请先创建。"}
|
return {"success": False, "error": "当前没有待办列表,请先创建。"}
|
||||||
if todo.get("status") in {"completed", "closed"}:
|
if todo.get("status") in {"completed", "closed"}:
|
||||||
return {"success": False, "error": "待办列表已结束,无法继续修改。"}
|
return {"success": False, "error": "待办列表已结束,无法继续修改。"}
|
||||||
|
|
||||||
if not isinstance(task_index, int):
|
# 兼容单个/多个序号
|
||||||
return {"success": False, "error": "task_index 必须是数字。"}
|
if isinstance(task_indices, int):
|
||||||
if task_index < 1 or task_index > len(todo["tasks"]):
|
indices = [task_indices]
|
||||||
return {"success": False, "error": f"task_index 超出范围(1-{len(todo['tasks'])})。"}
|
elif isinstance(task_indices, list):
|
||||||
|
indices = []
|
||||||
|
for idx in task_indices:
|
||||||
|
if isinstance(idx, int):
|
||||||
|
indices.append(idx)
|
||||||
|
else:
|
||||||
|
return {"success": False, "error": "task_index 或 task_indices 必须是数字或数字数组。"}
|
||||||
|
|
||||||
|
if not indices:
|
||||||
|
return {"success": False, "error": "请提供至少一个任务序号。"}
|
||||||
|
|
||||||
|
valid_max = len(todo["tasks"])
|
||||||
|
invalid = [i for i in indices if i < 1 or i > valid_max]
|
||||||
|
if invalid:
|
||||||
|
return {"success": False, "error": f"任务序号超出范围(1-{valid_max}):{invalid}"}
|
||||||
|
|
||||||
|
# 去重保持顺序
|
||||||
|
seen = set()
|
||||||
|
normalized = []
|
||||||
|
for i in indices:
|
||||||
|
if i not in seen:
|
||||||
|
seen.add(i)
|
||||||
|
normalized.append(i)
|
||||||
|
|
||||||
task = todo["tasks"][task_index - 1]
|
|
||||||
new_status = "done" if completed else "pending"
|
new_status = "done" if completed else "pending"
|
||||||
|
for task_index in normalized:
|
||||||
|
task = todo["tasks"][task_index - 1]
|
||||||
task["status"] = new_status
|
task["status"] = new_status
|
||||||
|
|
||||||
self._save(todo)
|
self._save(todo)
|
||||||
@ -133,9 +156,14 @@ class TodoManager:
|
|||||||
"message": "所有任务已完成。",
|
"message": "所有任务已完成。",
|
||||||
"todo_list": todo
|
"todo_list": todo
|
||||||
}
|
}
|
||||||
|
if len(normalized) == 1:
|
||||||
|
msg = f"任务 {normalized[0]}{'完成' if completed else '取消完成'}。"
|
||||||
|
else:
|
||||||
|
joined = ", ".join(str(i) for i in normalized)
|
||||||
|
msg = f"任务 {joined}{'全部完成' if completed else '已取消完成'}。"
|
||||||
return {
|
return {
|
||||||
"success": True,
|
"success": True,
|
||||||
"message": f"任务 {task_index}{'完成' if completed else '取消完成'}。",
|
"message": msg,
|
||||||
"todo_list": todo
|
"todo_list": todo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user