Skip to content

Commit

Permalink
fix /clear during pending message
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelchia committed Aug 12, 2024
1 parent 4351ad9 commit 9436967
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/jupyter-ai/jupyter_ai/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,15 @@ def broadcast_message(self, message: Message):
"""Broadcasts message to all connected clients.
Appends message to chat history.
"""
# do not broadcast agent messages that are replying to cleared human message
if (
isinstance(message, (AgentChatMessage, AgentStreamMessage))
and message.reply_to
):
if message.reply_to not in [
m.id for m in self.chat_history if isinstance(m, HumanChatMessage)
]:
return

self.log.debug("Broadcasting message: %s to all clients...", message)
client_ids = self.root_chat_handlers.keys()
Expand Down
1 change: 1 addition & 0 deletions packages/jupyter-ai/src/chat_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export class ChatHandler implements IDisposable {
break;
case 'clear':
this._messages = [];
this._pendingMessages = [];
break;
case 'pending':
this._pendingMessages = [...this._pendingMessages, newMessage];
Expand Down

0 comments on commit 9436967

Please sign in to comment.