feat: manual compact instead of automatic compact (#1996)
This commit is contained in:
@@ -46,6 +46,7 @@ local Highlights = {
|
||||
AVANTE_STATE_SPINNER_SUCCEEDED = { name = "AvanteStateSpinnerSucceeded", fg = "#1e222a", bg = "#98c379" },
|
||||
AVANTE_STATE_SPINNER_SEARCHING = { name = "AvanteStateSpinnerSearching", fg = "#1e222a", bg = "#c678dd" },
|
||||
AVANTE_STATE_SPINNER_THINKING = { name = "AvanteStateSpinnerThinking", fg = "#1e222a", bg = "#c678dd" },
|
||||
AVANTE_STATE_SPINNER_COMPACTING = { name = "AvanteStateSpinnerCompacting", fg = "#1e222a", bg = "#c678dd" },
|
||||
}
|
||||
|
||||
Highlights.conflict = {
|
||||
|
||||
@@ -1849,7 +1849,15 @@ function Sidebar:render_state()
|
||||
if self.current_state == "succeeded" then hl = "AvanteStateSpinnerSucceeded" end
|
||||
if self.current_state == "searching" then hl = "AvanteStateSpinnerSearching" end
|
||||
if self.current_state == "thinking" then hl = "AvanteStateSpinnerThinking" end
|
||||
if self.current_state ~= "generating" and self.current_state ~= "tool calling" then spinner_char = "" end
|
||||
if self.current_state == "compacting" then hl = "AvanteStateSpinnerCompacting" end
|
||||
if
|
||||
self.current_state ~= "generating"
|
||||
and self.current_state ~= "tool calling"
|
||||
and self.current_state ~= "thinking"
|
||||
and self.current_state ~= "compacting"
|
||||
then
|
||||
spinner_char = ""
|
||||
end
|
||||
local virt_line
|
||||
if spinner_char == "" then
|
||||
virt_line = " " .. self.current_state .. " "
|
||||
@@ -1872,6 +1880,27 @@ function Sidebar:render_state()
|
||||
self.state_timer = vim.defer_fn(function() self:render_state() end, 160)
|
||||
end
|
||||
|
||||
function Sidebar:compact_history_messages(args, cb)
|
||||
local history_memory = self.chat_history.memory
|
||||
local messages = Utils.get_history_messages(self.chat_history)
|
||||
self.current_state = "compacting"
|
||||
self:render_state()
|
||||
self:update_content(
|
||||
"compacting history messsages",
|
||||
{ focus = false, scroll = true, callback = function() self:focus_input() end }
|
||||
)
|
||||
Llm.summarize_memory(history_memory and history_memory.content, messages, function(memory)
|
||||
if memory then
|
||||
self.chat_history.memory = memory
|
||||
Path.history.save(self.code.bufnr, self.chat_history)
|
||||
end
|
||||
self:update_content("compacted!", { focus = false, scroll = true, callback = function() self:focus_input() end })
|
||||
self.current_state = "compacted"
|
||||
self:clear_state()
|
||||
if cb then cb(args) end
|
||||
end)
|
||||
end
|
||||
|
||||
function Sidebar:new_chat(args, cb)
|
||||
local history = Path.history.new(self.code.bufnr)
|
||||
Path.history.save(self.code.bufnr, history)
|
||||
@@ -2204,6 +2233,7 @@ function Sidebar:get_generate_prompts_options(request, cb)
|
||||
history_messages = history_messages,
|
||||
code_lang = filetype,
|
||||
selected_code = selected_code,
|
||||
disable_compact_history_messages = true,
|
||||
-- instructions = request,
|
||||
tools = tools,
|
||||
}
|
||||
|
||||
@@ -359,7 +359,7 @@ vim.g.avante_login = vim.g.avante_login
|
||||
---@alias AvanteLLMMemorySummarizeCallback fun(pending_compaction_history_messages: avante.HistoryMessage[]): nil
|
||||
---
|
||||
---@alias AvanteLLMToolUseState "generating" | "generated" | "running" | "succeeded" | "failed"
|
||||
---@alias avante.GenerateState "generating" | "tool calling" | "failed" | "succeeded" | "cancelled" | "searching" | "thinking"
|
||||
---@alias avante.GenerateState "generating" | "tool calling" | "failed" | "succeeded" | "cancelled" | "searching" | "thinking" | "compacting" | "compacted"
|
||||
---
|
||||
---@class AvanteLLMStreamOptions: AvanteGeneratePromptsOptions
|
||||
---@field on_start AvanteLLMStartCallback
|
||||
|
||||
@@ -1312,6 +1312,7 @@ function M.get_commands()
|
||||
{ description = "Show help message", name = "help" },
|
||||
{ description = "Clear chat history", name = "clear" },
|
||||
{ description = "New chat", name = "new" },
|
||||
{ description = "Compact history messages to save tokens", name = "compact" },
|
||||
{
|
||||
shorthelp = "Ask a question about specific lines",
|
||||
description = "/lines <start>-<end> <question>",
|
||||
@@ -1329,6 +1330,7 @@ function M.get_commands()
|
||||
end,
|
||||
clear = function(sidebar, args, cb) sidebar:clear_history(args, cb) end,
|
||||
new = function(sidebar, args, cb) sidebar:new_chat(args, cb) end,
|
||||
compact = function(sidebar, args, cb) sidebar:compact_history_messages(args, cb) end,
|
||||
lines = function(_, args, cb)
|
||||
if cb then cb(args) end
|
||||
end,
|
||||
|
||||
Reference in New Issue
Block a user