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