-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add Delete chat message action to the Obsidian Plugin #1076
base: master
Are you sure you want to change the base?
Conversation
const conversationId = chatBodyEl.dataset.conversationId; | ||
|
||
// Get the turn_id from the message's data-meta attribute | ||
const turnId = messageEl.getAttribute("data-meta"); |
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.
Hey @samhoooo ! This data field doesn't actually contain the turnId
field that you need, so it just results in no change in the backend for the chat history. The turnId
isn't currently being stored in the rendered message element. You would need to add some additional handling to store that, both in the streamed messages and in the chat history messages.
For streamed messages, you can update processMessageChunk
and store the data in chatMessageState
. The chunk.type
in that case would be metadata
. Then include it in the message element, similar to how data-meta
is stored. I think finalizeChatBodyResponse
would be a good place to add the data to the element.
You can give it the attribute name data-turnId
and set the value to the incoming turnId
.
For messages loaded from history, it would be similar, except you'd add the turnId
field to renderMessageWithReferences
. Just update the logic in the renderMessage
function to include the turnId
as well.
Then finally, in this deleteMesage
function, you'll getAttribute("data-turnId")
, instead of data-meta
.
Does that make sense? Let me know if you need help with any of it. Thanks for opening the PR.
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 @sabaimran! Really appreciate your detailed explaination.
I have updated the PR to include the turnId
handling as described, covered both streamed and messages loaded from history. I have also tested with my own account, delete some messages from Obsidian, and able to see chat history is updated on web.
Let me know if there is anything else I should watch out, thanks again for your guidance.
Closes #1020
Add Delete chat message action to the Obsidian Plugin
Description
The Khoj API supports deleting specific chat messages. The web app already uses that. But the Khoj Obsidian plugin doesn't use it yet.
This feature should
Add a Delete message button to each chat message footer in the Obsidian plugin's chat view
Clicking it should
Call the Khoj server API to delete the Khoj or user message
Refresh the Khoj Obsidian UI with the conversation turn (= Khoj + associated user message) deleted
Changes
Technical Details
deleteMessage
method to handle message deletion logic/api/chat/conversation/message
trash-2
)isSystemMessage
torenderMessage
methodTesting
Screensort
Happy path:
Screen.Recording.2025-01-11.at.17.54.29.mov
Setup hint cannot be deleted: