feat: todos (#2184)

This commit is contained in:
yetone
2025-06-15 15:10:07 +08:00
committed by GitHub
parent fdf4716ec0
commit ad05a802f9
13 changed files with 538 additions and 71 deletions

View File

@@ -0,0 +1,81 @@
local Base = require("avante.llm_tools.base")
---@class AvanteLLMTool
local M = setmetatable({}, Base)
M.name = "add_todos"
M.description = "Add TODOs to the current task"
---@type AvanteLLMToolParam
M.param = {
type = "table",
fields = {
{
name = "todos",
description = "The TODOs to add",
type = "array",
items = {
name = "items",
type = "object",
fields = {
{
name = "id",
description = "The ID of the TODO",
type = "string",
},
{
name = "content",
description = "The content of the TODO",
type = "string",
},
{
name = "status",
description = "The status of the TODO",
type = "string",
choices = { "todo", "doing", "done", "cancelled" },
},
{
name = "priority",
description = "The priority of the TODO",
type = "string",
choices = { "low", "medium", "high" },
},
},
},
},
},
}
---@type AvanteLLMToolReturn[]
M.returns = {
{
name = "success",
description = "Whether the TODOs were added successfully",
type = "boolean",
},
{
name = "error",
description = "Error message if the TODOs could not be updated",
type = "string",
optional = true,
},
}
M.on_render = function() return {} end
---@type AvanteLLMToolFunc<{ todos: avante.TODO[] }>
function M.func(opts, on_log, on_complete, session_ctx)
local sidebar = require("avante").get()
if not sidebar then return false, "Avante sidebar not found" end
local todos = opts.todos
if not todos or #todos == 0 then return false, "No todos provided" end
sidebar:update_todos(todos)
if on_complete then
on_complete(true, nil)
return nil, nil
end
return true, nil
end
return M

View File

@@ -762,6 +762,8 @@ M._tools = {
require("avante.llm_tools.ls"),
require("avante.llm_tools.grep"),
require("avante.llm_tools.delete_tool_use_messages"),
require("avante.llm_tools.add_todos"),
require("avante.llm_tools.update_todo_status"),
{
name = "read_file_toplevel_symbols",
description = "Read the top-level symbols of a file in current project scope",

View File

@@ -0,0 +1,65 @@
local Base = require("avante.llm_tools.base")
---@class AvanteLLMTool
local M = setmetatable({}, Base)
M.name = "update_todo_status"
M.description = "Update the status of TODO"
---@type AvanteLLMToolParam
M.param = {
type = "table",
fields = {
{
name = "id",
description = "The ID of the TODO to update",
type = "string",
},
{
name = "status",
description = "The status of the TODO to update",
type = "string",
choices = { "todo", "doing", "done", "cancelled" },
},
},
}
---@type AvanteLLMToolReturn[]
M.returns = {
{
name = "success",
description = "Whether the TODO was updated successfully",
type = "boolean",
},
{
name = "error",
description = "Error message if the TODOs could not be updated",
type = "string",
optional = true,
},
}
M.on_render = function() return {} end
---@type AvanteLLMToolFunc<{ id: string, status: string }>
function M.func(opts, on_log, on_complete, session_ctx)
local sidebar = require("avante").get()
if not sidebar then return false, "Avante sidebar not found" end
local todos = sidebar.chat_history.todos
if not todos or #todos == 0 then return false, "No todos found" end
for _, todo in ipairs(todos) do
if todo.id == opts.id then
todo.status = opts.status
break
end
end
sidebar:update_todos(todos)
if on_complete then
on_complete(true, nil)
return nil, nil
end
return true, nil
end
return M