-
-
Notifications
You must be signed in to change notification settings - Fork 407
feat(chat): Implement autosave for chat after messages and responses #1582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(chat): Implement autosave for chat after messages and responses #1582
Conversation
Adds autosave functionality to the chat component, saving the chat after every user message and AI response if the autosave setting is enabled. Updates the autosave chat setting description for clarity.
bugbot run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR. Initially I wanted to have a separate cache for the current chat to prevent the data loss in case of a crash. This is fine too, I guess, but it's a bit too frequent, e.g. it saves both before and after an AI response, and the saving is a blocking op so it could impact performance.
cc @zeroliu wdyt?
Ah I see, that makes sense! We should remove the await to make it non-blocking. That gives us a quick solution that keeps the crash protection without the performance impact. |
Updated the Chat component to filter visible messages using sharedState.getMessages() instead of chatHistory, ensuring the latest messages are used. Also removed a redundant notice when updating an existing note.
The handleSaveAsNote function is now called without await in autosaveChat blocks.
During testing of the autosave feature, I discovered that the saved chat files were missing the last 2 messages (user message and AI response). Fixed by:
Also removed the "Chat updated..." toast notifications that appeared on every autosave, as they were becoming intrusive during regular usage. The "Chat saved..." notification for new files is preserved. |
bugbot run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ BugBot reviewed your changes and found no bugs!
Was this report helpful? Give feedback by reacting with 👍 or 👎
This is functionally fine for now but there's a significant UX issue that is - with autosave on, the user will see a notice "chat saved" on every message. We have to make it much more subtle before we introduce this change. |
I removed the "Chat updated..." toast notifications that appeared on every autosave |
Oh I see, and the "chat saved as note ..." notice only pops up at the first message and not subsequent ones. That's fine I think. Thanks for the PR, merging now and let's see what the users say 🙏 |
…1582) * feat(chat): Implement autosave for chat after messages and responses Adds autosave functionality to the chat component, saving the chat after every user message and AI response if the autosave setting is enabled. Updates the autosave chat setting description for clarity. * fix(chat): Use sharedState for visible messages in Chat Updated the Chat component to filter visible messages using sharedState.getMessages() instead of chatHistory, ensuring the latest messages are used. Also removed a redundant notice when updating an existing note. * fix(chat): Make autosave non-blocking The handleSaveAsNote function is now called without await in autosaveChat blocks. --------- Co-authored-by: Logan Yang <[email protected]>
This PR introduces a more robust autosave feature for the chat.
Previously, autosave was only triggered when creating a new chat or reloading the plugin. This could lead to data loss if the user closed Obsidian or if the plugin crashed.
The new implementation saves the chat automatically at several key moments, ensuring the conversation is always up-to-date:
This is controlled by the "Autosave Chat" setting, which has been updated to reflect the new behavior. The dependencies of the
useCallback
hooks forhandleEdit
andhandleRegenerate
have also been updated to include the new logic.I was inspired to make this change after losing several very important conversations multiple times in the same week. I was getting quite frustrated that the "Autosave Chat" setting didn't work in a way that felt logical, only saving on a new chat. I decided to fix it to create the behavior I, and likely many others, would expect, ensuring no more conversations are lost unexpectedly.