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:
@@ -46,14 +46,16 @@ function M.func(input, opts)
|
|||||||
local history_messages = History.get_history_messages(sidebar.chat_history)
|
local history_messages = History.get_history_messages(sidebar.chat_history)
|
||||||
local the_deleted_message_uuids = {}
|
local the_deleted_message_uuids = {}
|
||||||
for _, msg in ipairs(history_messages) do
|
for _, msg in ipairs(history_messages) do
|
||||||
if History.Helpers.is_tool_use_message(msg) then
|
local use = History.Helpers.get_tool_use_data(msg)
|
||||||
local content = msg.message.content
|
if use then
|
||||||
if type(content) == "table" then
|
if use.id == input.tool_use_id then table.insert(the_deleted_message_uuids, msg.uuid) end
|
||||||
for _, item in ipairs(content) do
|
goto continue
|
||||||
if item.id == input.tool_use_id then table.insert(the_deleted_message_uuids, msg.uuid) end
|
|
||||||
end
|
|
||||||
end
|
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
|
end
|
||||||
|
::continue::
|
||||||
end
|
end
|
||||||
sidebar:delete_history_messages(the_deleted_message_uuids)
|
sidebar:delete_history_messages(the_deleted_message_uuids)
|
||||||
return true, nil
|
return true, nil
|
||||||
|
|||||||
Reference in New Issue
Block a user