From 5bc660169255453b34d0aceaa6c404f835c81611 Mon Sep 17 00:00:00 2001 From: Zane <75694352+zanesq@users.noreply.github.com> Date: Thu, 31 Jul 2025 10:45:55 -0700 Subject: [PATCH] Persist first message to local history in case of failure or cancellation (#3744) --- ui/desktop/src/hooks/useChatEngine.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ui/desktop/src/hooks/useChatEngine.ts b/ui/desktop/src/hooks/useChatEngine.ts index 512bffd0..910c81a1 100644 --- a/ui/desktop/src/hooks/useChatEngine.ts +++ b/ui/desktop/src/hooks/useChatEngine.ts @@ -264,6 +264,11 @@ export const useChatEngine = ({ // Set the text back to the input field _setInput(textValue); + // Also add to local storage history as a backup so cmd+up can retrieve it + if (enableLocalStorage && textValue.trim()) { + LocalMessageStorage.addMessage(textValue.trim()); + } + // Remove the last user message if it's the most recent one if (messages.length > 1) { setMessages(messages.slice(0, -1)); @@ -325,7 +330,7 @@ export const useChatEngine = ({ setMessages([...messages, responseMessage]); } } - }, [stop, messages, _setInput, setMessages]); + }, [stop, messages, _setInput, setMessages, enableLocalStorage]); const filteredMessages = useMemo(() => { return [...ancestorMessages, ...messages].filter((message) => message.display ?? true);