Handle YChat document resets when jupyterlab_chat is installed
#161
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.
Description
This PR introduces UI handling for document resets occurring on
*.chatfiles provided byjupyterlab_chat. This may occur when an out-of-band change is made to a*.chatfile or when the YDoc history is squashed to preserve server memory (a planned feature).Demo
Screen.Recording.2025-10-16.at.5.02.09.PM.mov
Technical details
The document reset handling is implemented entirely in a single
ychatplugin. This provides a customYChatthat provides areset()method &resetSignalproperty for the Yjs Websocket provider to call & emit to when receiving a document reset close code (4xxx). This follows the strategy applied to our customYFileandYNotebookclasses.The
ychatplugin listens toresetSignalon eachYChatinstance. When a reset is detected, the plugin finds the correctChatWidgetdocument widget containing theYChatinstance which was reset, then clears its UI state before the subsequent SS1 + SS2 handshake is completed. This provides handling of chat document resets in the UI, without the need to fork the plugin providing theChatWidgetclass.ChatWidgetplugin injupyterlab_chatis 250 lines long and requires 14 other plugins.This PR adds NPM dependencies on
@jupyter/chatandjupyterlab-chat. It also adds the correct JupyterLab module federation configuration to ensure that tokens and classes imported are the same instances as the ones provided with thejupyterlab_chatpackage.jupyterlab_chatas a required dependency. The customychatplugin is only loaded ifjupyterlab_chatis installed.