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:
@@ -1,5 +1,5 @@
|
||||
local Base = require("avante.llm_tools.base")
|
||||
local Utils = require("avante.utils")
|
||||
local History = require("avante.history")
|
||||
|
||||
---@class AvanteLLMTool
|
||||
local M = setmetatable({}, Base)
|
||||
@@ -43,10 +43,10 @@ M.returns = {
|
||||
function M.func(input, opts)
|
||||
local sidebar = require("avante").get()
|
||||
if not sidebar then return false, "Avante sidebar not found" end
|
||||
local history_messages = Utils.get_history_messages(sidebar.chat_history)
|
||||
local history_messages = History.get_history_messages(sidebar.chat_history)
|
||||
local the_deleted_message_uuids = {}
|
||||
for _, msg in ipairs(history_messages) do
|
||||
if Utils.is_tool_use_message(msg) then
|
||||
if History.Helpers.is_tool_use_message(msg) then
|
||||
local content = msg.message.content
|
||||
if type(content) == "table" then
|
||||
for _, item in ipairs(content) do
|
||||
|
||||
@@ -2,7 +2,7 @@ local Providers = require("avante.providers")
|
||||
local Config = require("avante.config")
|
||||
local Utils = require("avante.utils")
|
||||
local Base = require("avante.llm_tools.base")
|
||||
local HistoryMessage = require("avante.history_message")
|
||||
local History = require("avante.history")
|
||||
local Line = require("avante.ui.line")
|
||||
local Highlights = require("avante.highlights")
|
||||
|
||||
@@ -94,7 +94,7 @@ function M.on_render(input, opts)
|
||||
local content = msg.message.content
|
||||
local summary
|
||||
if type(content) == "table" and #content > 0 and content[1].type == "tool_use" then
|
||||
local tool_result_message = Utils.get_tool_result_message(msg, messages)
|
||||
local tool_result_message = History.Helpers.get_tool_result_message(msg, messages)
|
||||
if tool_result_message then
|
||||
local tool_name = msg.message.content[1].name
|
||||
if tool_name == "ls" then
|
||||
@@ -267,7 +267,7 @@ When you're done, provide a clear and concise summary of what you found.]]):gsub
|
||||
.. elapsed_time
|
||||
.. "s)"
|
||||
if session_ctx.on_messages_add then
|
||||
local message = HistoryMessage:new({
|
||||
local message = History.Message:new({
|
||||
role = "assistant",
|
||||
content = "\n\n" .. summary,
|
||||
}, {
|
||||
|
||||
Reference in New Issue
Block a user