fix: sanitize loaded chat history

Ensure that chat history loaded from a file has resemblance of correct
data. Namely title and timestamp are present and are strings, and
entires, messages, and todos are lists. In case of inconsistencies
replace with empty/default data.

This should help with #2584.

More changes are needed to sanitize individual entries.
This commit is contained in:
Dmitry Torokhov
2025-08-06 22:06:30 -07:00
parent b08dc79088
commit d0f0580d64
4 changed files with 36 additions and 25 deletions

View File

@@ -48,7 +48,7 @@ function M.func(input, opts)
local sidebar = require("avante").get()
if not sidebar then return false, "Avante sidebar not found" end
local todos = sidebar.chat_history.todos
if not todos or #todos == 0 then return false, "No todos found" end
if #todos == 0 then return false, "No todos found" end
for _, todo in ipairs(todos) do
if tostring(todo.id) == tostring(input.id) then
todo.status = input.status