refactor: llm tool parameters (#2449)

This commit is contained in:
yetone
2025-07-15 16:40:25 +08:00
committed by GitHub
parent 0c6a8f5688
commit b8bb0fd969
25 changed files with 627 additions and 381 deletions

View File

@@ -57,27 +57,26 @@ M.returns = {
--- IMPORTANT: Using "the_content" instead of "content" is to avoid LLM streaming generating function parameters in alphabetical order, which would result in generating "path" after "content", making it impossible to achieve a stream diff view.
---@type AvanteLLMToolFunc<{ path: string, content: string, the_content?: string, streaming?: boolean, tool_use_id?: string }>
function M.func(opts, on_log, on_complete, session_ctx)
if opts.the_content ~= nil then
opts.content = opts.the_content
opts.the_content = nil
function M.func(input, opts)
if input.the_content ~= nil then
input.content = input.the_content
input.the_content = nil
end
if not on_complete then return false, "on_complete not provided" end
local abs_path = Helpers.get_abs_path(opts.path)
local abs_path = Helpers.get_abs_path(input.path)
if not Helpers.has_permission_to_access(abs_path) then return false, "No permission to access path: " .. abs_path end
if opts.content == nil then return false, "content not provided" end
if type(opts.content) ~= "string" then opts.content = vim.json.encode(opts.content) end
if input.content == nil then return false, "content not provided" end
if type(input.content) ~= "string" then input.content = vim.json.encode(input.content) end
local old_lines = Utils.read_file_from_buf_or_disk(abs_path)
local old_content = table.concat(old_lines or {}, "\n")
local str_replace = require("avante.llm_tools.str_replace")
local new_opts = {
path = opts.path,
local new_input = {
path = input.path,
old_str = old_content,
new_str = opts.content,
streaming = opts.streaming,
tool_use_id = opts.tool_use_id,
new_str = input.content,
streaming = input.streaming,
tool_use_id = input.tool_use_id,
}
return str_replace.func(new_opts, on_log, on_complete, session_ctx)
return str_replace.func(new_input, opts)
end
return M