fix(compat): filter out non value and not user message (#818)

Co-authored-by: Aaron Pham <Aaronpham0103@gmail.com>
Co-authored-by: Aaron Pham <contact@aarnphm.xyz>
This commit is contained in:
insects 2024-11-07 18:38:56 +08:00 committed by GitHub
parent ec9b00db8b
commit ecaf850859
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -42,11 +42,14 @@ M.role_map = {
M.get_user_message = function(opts)
vim.deprecate("get_user_message", "parse_messages", "0.1.0", "avante.nvim")
return table.concat(
vim.iter(opts.messages):filter(function(_, value) return value.role == "user" end):fold({}, function(acc, value)
acc = vim.list_extend({}, acc)
acc = vim.list_extend(acc, { value.content })
return acc
end),
vim
.iter(opts.messages)
:filter(function(_, value) return value == nil or value.role ~= "user" end)
:fold({}, function(acc, value)
acc = vim.list_extend({}, acc)
acc = vim.list_extend(acc, { value.content })
return acc
end),
"\n"
)
end