fix: cancel error (#1965)
This commit is contained in:
@@ -699,7 +699,16 @@ function M._stream(opts)
|
||||
-- Special handling for cancellation signal from tools
|
||||
if error == LLMToolHelpers.CANCEL_TOKEN then
|
||||
Utils.debug("Tool execution was cancelled by user")
|
||||
opts.on_chunk("\n*[Request cancelled by user during tool execution.]*\n")
|
||||
if opts.on_chunk then opts.on_chunk("\n*[Request cancelled by user during tool execution.]*\n") end
|
||||
if opts.on_messages_add then
|
||||
local message = HistoryMessage:new({
|
||||
role = "assistant",
|
||||
content = "\n*[Request cancelled by user during tool execution.]*\n",
|
||||
}, {
|
||||
just_for_display = true,
|
||||
})
|
||||
opts.on_messages_add({ message })
|
||||
end
|
||||
return opts.on_stop({ reason = "cancelled" })
|
||||
end
|
||||
|
||||
@@ -725,8 +734,10 @@ function M._stream(opts)
|
||||
if opts.on_chunk then opts.on_chunk("\n*[Request cancelled by user.]*\n") end
|
||||
if opts.on_messages_add then
|
||||
local message = HistoryMessage:new({
|
||||
role = "user",
|
||||
content = "[Request cancelled by user.]",
|
||||
role = "assistant",
|
||||
content = "\n*[Request cancelled by user.]*\n",
|
||||
}, {
|
||||
just_for_display = true,
|
||||
})
|
||||
opts.on_messages_add({ message })
|
||||
end
|
||||
|
||||
@@ -1148,6 +1148,7 @@ function M.process_tool_use(tools, tool_use, on_log, on_complete, session_ctx)
|
||||
cancel_timer:stop()
|
||||
cancel_timer:close()
|
||||
end
|
||||
Helpers.is_cancelled = false
|
||||
on_complete(nil, Helpers.CANCEL_TOKEN)
|
||||
end
|
||||
end)
|
||||
@@ -1191,6 +1192,7 @@ function M.process_tool_use(tools, tool_use, on_log, on_complete, session_ctx)
|
||||
end, function(result, err)
|
||||
-- Check for cancellation before completing
|
||||
if Helpers.is_cancelled then
|
||||
Helpers.is_cancelled = false
|
||||
if on_complete then on_complete(nil, Helpers.CANCEL_TOKEN) end
|
||||
return
|
||||
end
|
||||
|
||||
@@ -1513,9 +1513,8 @@ end
|
||||
---@param messages avante.HistoryMessage[]
|
||||
---@return avante.ui.Line[]
|
||||
function M.message_to_lines(message, messages)
|
||||
local Line = require("avante.ui.line")
|
||||
local content = message.message.content
|
||||
if type(content) == "string" then return { Line:new({ { content } }) } end
|
||||
if type(content) == "string" then return M.text_to_lines(content) end
|
||||
if vim.islist(content) then
|
||||
local lines = {}
|
||||
for _, item in ipairs(content) do
|
||||
|
||||
Reference in New Issue
Block a user