fix: handle user-declined tool executions separately from errors (#2258)
This commit is contained in:
@@ -682,6 +682,7 @@ function M._stream(opts)
|
||||
tool_use_id = tool_result.tool_use_id,
|
||||
content = tool_result.content,
|
||||
is_error = tool_result.is_error,
|
||||
is_user_declined = tool_result.is_user_declined,
|
||||
},
|
||||
},
|
||||
})
|
||||
@@ -726,10 +727,12 @@ function M._stream(opts)
|
||||
return opts.on_stop({ reason = "cancelled" })
|
||||
end
|
||||
|
||||
local is_user_declined = error and error:match("^User declined")
|
||||
local tool_result = {
|
||||
tool_use_id = partial_tool_use.id,
|
||||
content = error ~= nil and error or result,
|
||||
is_error = error ~= nil,
|
||||
is_error = error ~= nil, -- Keep this as error to prevent processing as success
|
||||
is_user_declined = is_user_declined ~= nil,
|
||||
}
|
||||
table.insert(tool_results, tool_result)
|
||||
return handle_next_tool_use(partial_tool_use_list, tool_use_index + 1, tool_results)
|
||||
|
||||
@@ -2195,11 +2195,20 @@ function Sidebar:get_history_messages_for_api(opts)
|
||||
local tool_use_message = Utils.get_tool_use_message(message, history_messages0)
|
||||
local is_edit_func_call, _, _, path = Utils.is_edit_func_call_message(tool_use_message)
|
||||
|
||||
if is_edit_func_call and message.message.content[1].is_error then
|
||||
failed_edit_tool_ids[message.message.content[1].tool_use_id] = true
|
||||
local tool_result = message.message.content[1]
|
||||
|
||||
-- Only track as failed if it's an error AND not user-declined
|
||||
if is_edit_func_call and tool_result.is_error and not tool_result.is_user_declined then
|
||||
failed_edit_tool_ids[tool_result.tool_use_id] = true
|
||||
end
|
||||
|
||||
if is_edit_func_call and path and not message.message.content[1].is_error then
|
||||
-- Only track as successful modification if not an error AND not user-declined
|
||||
if
|
||||
is_edit_func_call
|
||||
and path
|
||||
and not message.message.content[1].is_error
|
||||
and not message.message.content[1].is_user_declined
|
||||
then
|
||||
local uniformed_path = Utils.uniform_path(path)
|
||||
last_modified_files[uniformed_path] = idx
|
||||
end
|
||||
@@ -2260,6 +2269,7 @@ function Sidebar:get_history_messages_for_api(opts)
|
||||
tool_use_id = view_tool_use_id,
|
||||
content = view_result,
|
||||
is_error = view_error ~= nil,
|
||||
is_user_declined = false,
|
||||
},
|
||||
},
|
||||
}, {
|
||||
@@ -2299,6 +2309,7 @@ function Sidebar:get_history_messages_for_api(opts)
|
||||
tool_use_id = get_diagnostics_tool_use_id,
|
||||
content = vim.json.encode(diagnostics),
|
||||
is_error = false,
|
||||
is_user_declined = false,
|
||||
},
|
||||
},
|
||||
}, {
|
||||
|
||||
@@ -116,6 +116,7 @@ vim.g.avante_login = vim.g.avante_login
|
||||
---@field tool_use_id string
|
||||
---@field content string
|
||||
---@field is_error? boolean
|
||||
---@field is_user_declined? boolean
|
||||
---
|
||||
---@class AvantePromptOptions: table<[string], string>
|
||||
---@field system_prompt string
|
||||
|
||||
Reference in New Issue
Block a user