refactor(history): change HistoryMessage:new() to accept role and item

Change the constructor to accept role and a single content item instead
of raw AvanteLLMMessage instance. This will help when we will start
changing message.content from being a string or a list of tables to just
a string or a single table.
This commit is contained in:
Dmitry Torokhov
2025-07-18 15:08:19 -07:00
committed by yetone
parent 2d9f8fd252
commit aa606b6147
9 changed files with 171 additions and 252 deletions

View File

@@ -135,27 +135,24 @@ function M:is_disable_stream() return false end
---@param tool_calls avante.OllamaToolCall[]
---@param opts AvanteLLMStreamOptions
function M:add_tool_use_messages(tool_calls, opts)
local msgs = {}
for _, tool_call in ipairs(tool_calls) do
local id = Utils.uuid()
local func = tool_call["function"]
local msg = HistoryMessage:new({
role = "assistant",
content = {
{
type = "tool_use",
name = func.name,
id = id,
input = func.arguments,
},
},
}, {
state = "generated",
uuid = id,
})
table.insert(msgs, msg)
if opts.on_messages_add then
local msgs = {}
for _, tool_call in ipairs(tool_calls) do
local id = Utils.uuid()
local func = tool_call["function"]
local msg = HistoryMessage:new("assistant", {
type = "tool_use",
name = func.name,
id = id,
input = func.arguments,
}, {
state = "generated",
uuid = id,
})
table.insert(msgs, msg)
end
opts.on_messages_add(msgs)
end
if opts.on_messages_add then opts.on_messages_add(msgs) end
end
function M:parse_stream_data(ctx, data, opts)