diff --git a/lua/avante/history_message.lua b/lua/avante/history_message.lua index 9c630c2..e9e1340 100644 --- a/lua/avante/history_message.lua +++ b/lua/avante/history_message.lua @@ -5,7 +5,7 @@ local M = {} M.__index = M ---@param message AvanteLLMMessage ----@param opts? {is_user_submission?: boolean, visible?: boolean, displayed_content?: string, state?: avante.HistoryMessageState, uuid?: string, selected_filepaths?: string[], selected_code?: AvanteSelectedCode, just_for_display?: boolean} +---@param opts? {is_user_submission?: boolean, visible?: boolean, displayed_content?: string, state?: avante.HistoryMessageState, uuid?: string, selected_filepaths?: string[], selected_code?: AvanteSelectedCode, just_for_display?: boolean, is_dummy?: boolean} ---@return avante.HistoryMessage function M:new(message, opts) opts = opts or {} @@ -22,6 +22,7 @@ function M:new(message, opts) if opts.selected_filepaths ~= nil then obj.selected_filepaths = opts.selected_filepaths end if opts.selected_code ~= nil then obj.selected_code = opts.selected_code end if opts.just_for_display ~= nil then obj.just_for_display = opts.just_for_display end + if opts.is_dummy ~= nil then obj.is_dummy = opts.is_dummy end return obj end diff --git a/lua/avante/llm.lua b/lua/avante/llm.lua index b25f7c7..7190cb3 100644 --- a/lua/avante/llm.lua +++ b/lua/avante/llm.lua @@ -166,6 +166,8 @@ function M.generate_prompts(opts) HistoryMessage:new({ role = "assistant", content = string.format("Viewing file %s to get the latest content", path), + }, { + is_dummy = true, }), HistoryMessage:new({ role = "assistant", @@ -179,6 +181,8 @@ function M.generate_prompts(opts) }, }, }, + }, { + is_dummy = true, }), HistoryMessage:new({ role = "user", @@ -190,6 +194,8 @@ function M.generate_prompts(opts) is_error = false, }, }, + }, { + is_dummy = true, }), }) end @@ -365,6 +371,11 @@ function M.generate_prompts(opts) dropped_history_messages = vim.list_slice(cleaned_history_messages, 1, #cleaned_history_messages - #retained_history_messages) + dropped_history_messages = vim + .iter(dropped_history_messages) + :filter(function(msg) return msg.is_dummy ~= true end) + :totable() + -- prepend the history messages to the messages table vim.iter(retained_history_messages):each(function(msg) table.insert(final_history_messages, msg) end) end diff --git a/lua/avante/types.lua b/lua/avante/types.lua index 2135a77..8d29a4a 100644 --- a/lua/avante/types.lua +++ b/lua/avante/types.lua @@ -101,6 +101,7 @@ vim.g.avante_login = vim.g.avante_login ---@field selected_filepaths string[] | nil ---@field tool_use_logs string[] | nil ---@field just_for_display boolean | nil +---@field is_dummy boolean | nil --- ---@class AvanteLLMToolResult ---@field tool_name string