From 394e4d79ebd58f9e1d0c5a466de043a498c07e11 Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Thu, 17 Jul 2025 22:28:18 -0700 Subject: [PATCH] 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. --- lua/avante/history/message.lua | 7 +++++++ lua/avante/llm.lua | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lua/avante/history/message.lua b/lua/avante/history/message.lua index 8a37542..ffc91b2 100644 --- a/lua/avante/history/message.lua +++ b/lua/avante/history/message.lua @@ -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 diff --git a/lua/avante/llm.lua b/lua/avante/llm.lua index c9f8481..5eb3489 100644 --- a/lua/avante/llm.lua +++ b/lua/avante/llm.lua @@ -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