Add branching conversations through an edit message option - #310
Open
Yahiewi wants to merge 9 commits into
Open
Conversation
Contributor
Author
|
I'm thinking about how we can undo the code changes when editing a message, or maybe give the user the option to undo the the code changes. However, I'm still not quite sure how to do this or if this is doable. The main challenge I think is implementing this in a collaborative context: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR closes issue #288 by adding an option to edit previously sent user messages which creates a branch or multiple branches if that message was edited more than once.
This uses
updateMessagefrom @jupyter/chat.Code changes:
src/components/edit-message-button.tsx and src/index.ts:
createEditMessageSection: MessageFooterSectionin a newmessageFooterRegistry(from @jupyter/chat). It has aBranchNavigationcomponent which shows the branch navigation arrows on edited user messages. It also shows a counter for the branches (for example 2/3). It also preserves scroll position so when editing a message, the conversation isn't scrolled to end.src/agent.ts:
historygetters and setters as well as atruncateHistory(n)function (which keeps the firstnturns (user message and response) in the history) in theAgentManagerclass.EDIT: Since a
setHistoryfunction was also defined in PR Save and restore chat #303, I renamed the setHistory function defined here torestoreHistory. Although I think it makes more sense to switch the names since the function defined in this PR is a simple setter.src/chat-model.ts:
_branchPointsprivate field inAIChatModelclass of typeMap<string,{ branches: AIChatModel.IBranchSnapshot[]; currentIndex: number }which maps to every edited messagemessageIdan array of branches and the currently active branch index.clearMessagesmethod now also clears the branch points.editMessage,switchBranch,updateMessage(which is called by @jupyter/chat's native edit UI and basically calls editMessage),getBranchInfo, a new private_snapshotFrommethod and refactored out a_createErrorMessagemethod that's used ineditMessageandsendMessage.AIChatModelnamespace, added anIBranchSnapshotinterface.Demo:
Screencast.from.2026-04-07.14-27-32.mp4