refactor(message): add helper to update contents of simple text message

Add update_content() helper so code outside of history module does not
need to know details of the message structure.
This commit is contained in:
Dmitry Torokhov
2025-07-17 22:28:18 -07:00
committed by yetone
parent e82b159f65
commit 394e4d79eb
2 changed files with 8 additions and 1 deletions

View File

@@ -53,4 +53,11 @@ function M:new_assistant_synthetic(item) return M:new_synthetic("assistant", ite
---@return avante.HistoryMessage
function M:new_user_synthetic(item) return M:new_synthetic("user", item) end
---Updates content of a message as long as it is a simple text (or empty).
---@param new_content string
function M:update_content(new_content)
assert(type(self.message.content) == "string", "can only update content of simple string messages")
self.message.content = new_content
end
return M

View File

@@ -979,7 +979,7 @@ function M._stream(opts)
opts.on_chunk(prefix .. "\n" .. msg_content .. "\n")
end
if opts.on_messages_add and message then
message.message.content = "\n\n" .. msg_content
message:update_content("\n\n" .. msg_content)
opts.on_messages_add({ message })
end