refactor(history): start moving history-related code into avante/history

The utils module has grown too big and contains unrelated functionality.
Start moving code related to managing history messages comprising chat
history into lua/avante/history module to keep the code more manageable.
This commit is contained in:
Dmitry Torokhov
2025-07-08 15:57:05 -07:00
committed by yetone
parent 85a9fcef95
commit 34907fc1cd
14 changed files with 448 additions and 421 deletions

View File

@@ -53,10 +53,11 @@ function History.list(bufnr)
--- sort by timestamp
--- sort by latest_filename
table.sort(res, function(a, b)
local H = require("avante.history")
if a.filename == latest_filename then return true end
if b.filename == latest_filename then return false end
local a_messages = Utils.get_history_messages(a)
local b_messages = Utils.get_history_messages(b)
local a_messages = H.get_history_messages(a)
local b_messages = H.get_history_messages(b)
local timestamp_a = #a_messages > 0 and a_messages[#a_messages].timestamp or a.timestamp
local timestamp_b = #b_messages > 0 and b_messages[#b_messages].timestamp or b.timestamp
return timestamp_a > timestamp_b