Improve ACP history message tracking (#2781)
This commit is contained in:
@@ -943,6 +943,11 @@ function M._stream_acp(opts)
|
|||||||
local last_tool_call_message = nil
|
local last_tool_call_message = nil
|
||||||
local acp_provider = Config.acp_providers[Config.provider]
|
local acp_provider = Config.acp_providers[Config.provider]
|
||||||
local prev_text_message_content = ""
|
local prev_text_message_content = ""
|
||||||
|
local history_messages = {}
|
||||||
|
local get_history_messages = function()
|
||||||
|
if opts.get_history_messages then return opts.get_history_messages() end
|
||||||
|
return history_messages
|
||||||
|
end
|
||||||
local on_messages_add = function(messages)
|
local on_messages_add = function(messages)
|
||||||
if opts.on_chunk then
|
if opts.on_chunk then
|
||||||
for _, message in ipairs(messages) do
|
for _, message in ipairs(messages) do
|
||||||
@@ -955,7 +960,21 @@ function M._stream_acp(opts)
|
|||||||
end
|
end
|
||||||
if opts.on_messages_add then
|
if opts.on_messages_add then
|
||||||
opts.on_messages_add(messages)
|
opts.on_messages_add(messages)
|
||||||
-- vim.schedule(function() vim.cmd("redraw") end)
|
else
|
||||||
|
for _, message in ipairs(messages) do
|
||||||
|
local idx = nil
|
||||||
|
for i, m in ipairs(history_messages) do
|
||||||
|
if m.uuid == message.uuid then
|
||||||
|
idx = i
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if idx ~= nil then
|
||||||
|
history_messages[idx] = message
|
||||||
|
else
|
||||||
|
table.insert(history_messages, message)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local function add_tool_call_message(update)
|
local function add_tool_call_message(update)
|
||||||
@@ -1008,8 +1027,7 @@ function M._stream_acp(opts)
|
|||||||
|
|
||||||
if update.sessionUpdate == "agent_message_chunk" then
|
if update.sessionUpdate == "agent_message_chunk" then
|
||||||
if update.content.type == "text" then
|
if update.content.type == "text" then
|
||||||
if opts.get_history_messages then
|
local messages = get_history_messages()
|
||||||
local messages = opts.get_history_messages()
|
|
||||||
local last_message = messages[#messages]
|
local last_message = messages[#messages]
|
||||||
if last_message and last_message.message.role == "assistant" then
|
if last_message and last_message.message.role == "assistant" then
|
||||||
local has_text = false
|
local has_text = false
|
||||||
@@ -1034,7 +1052,6 @@ function M._stream_acp(opts)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
local message = History.Message:new("assistant", update.content.text)
|
local message = History.Message:new("assistant", update.content.text)
|
||||||
on_messages_add({ message })
|
on_messages_add({ message })
|
||||||
end
|
end
|
||||||
@@ -1042,7 +1059,7 @@ function M._stream_acp(opts)
|
|||||||
|
|
||||||
if update.sessionUpdate == "agent_thought_chunk" then
|
if update.sessionUpdate == "agent_thought_chunk" then
|
||||||
if update.content.type == "text" then
|
if update.content.type == "text" then
|
||||||
local messages = opts.get_history_messages()
|
local messages = get_history_messages()
|
||||||
local last_message = messages[#messages]
|
local last_message = messages[#messages]
|
||||||
if last_message and last_message.message.role == "assistant" then
|
if last_message and last_message.message.role == "assistant" then
|
||||||
local is_thinking = false
|
local is_thinking = false
|
||||||
|
|||||||
Reference in New Issue
Block a user