fix: when deleting tool use also delete tool result

Tool results are not useful without their "use" messages, so delete them
when deleting "use" ones.

Makes use of the new get_tool_use_data() and get_tool_result_data()
helpers.
This commit is contained in:
Dmitry Torokhov
2025-07-11 16:23:43 -07:00
committed by yetone
parent 520ca47a8f
commit 47ad90b389

View File

@@ -46,14 +46,16 @@ function M.func(input, opts)
local history_messages = History.get_history_messages(sidebar.chat_history)
local the_deleted_message_uuids = {}
for _, msg in ipairs(history_messages) do
if History.Helpers.is_tool_use_message(msg) then
local content = msg.message.content
if type(content) == "table" then
for _, item in ipairs(content) do
if item.id == input.tool_use_id then table.insert(the_deleted_message_uuids, msg.uuid) end
end
end
local use = History.Helpers.get_tool_use_data(msg)
if use then
if use.id == input.tool_use_id then table.insert(the_deleted_message_uuids, msg.uuid) end
goto continue
end
local result = History.Helpers.get_tool_result_data(msg)
if result then
if result.tool_use_id == input.tool_use_id then table.insert(the_deleted_message_uuids, msg.uuid) end
end
::continue::
end
sidebar:delete_history_messages(the_deleted_message_uuids)
return true, nil