@@ -18,6 +18,9 @@ router = self.serverapp.web_app.settings.get("jupyter-ai", {}).get("router")
1818def on_new_chat (room_id : str , ychat : YChat):
1919 print (f " New chat connected: { room_id} " )
2020
21+ def on_chat_reset (room_id : str , new_ychat : YChat):
22+ print (f " Chat document reset: { room_id} " )
23+
2124def on_slash_command (room_id : str , command : str , message : Message):
2225 print (f " Slash command ' { command} ' in { room_id} : { message.body} " )
2326
@@ -26,6 +29,7 @@ def on_regular_message(room_id: str, message: Message):
2629
2730# Register the callbacks
2831router.observe_chat_init(on_new_chat)
32+ router.observe_chat_reset(on_chat_reset) # Called when .chat file is modified directly
2933router.observe_slash_cmd_msg(" room-id" , " help" , on_slash_command) # Only /help commands
3034router.observe_chat_msg(" room-id" , on_regular_message)
3135```
@@ -40,6 +44,7 @@ router.observe_chat_msg("room-id", on_regular_message)
4044### Available Methods
4145
4246- ` observe_chat_init(callback) ` - Called when new chat sessions are initialized with ` (room_id, ychat) `
47+ - ` observe_chat_reset(callback) ` - Called when a YChat document is reset (requires ` jupyter_server_documents ` ) with ` (room_id, new_ychat) `
4348- ` observe_slash_cmd_msg(room_id, command_pattern, callback) ` - Called for specific slash commands matching the pattern in a specific room
4449- ` observe_chat_msg(room_id, callback) ` - Called for regular (non-slash) messages in a specific room
4550
0 commit comments