Skip to content

Commit 6cd55ab

Browse files
committed
added a is_done flag to make sure the full message is sent before mentioning personas
1 parent 308ded9 commit 6cd55ab

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

python/jupyterlab-chat/jupyterlab_chat/tests/test_ychat.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def test_update_message_includes_mentions():
182182

183183
# Update the message to mention a different user
184184
msg.body = f"@{USER3.mention_name} Goodbye!"
185-
chat.update_message(msg)
185+
chat.update_message(msg, is_done=True)
186186
updated_msg = chat.get_message(msg_id)
187187
assert updated_msg
188188
assert set(updated_msg.mentions) == set([USER3.username])
@@ -203,7 +203,7 @@ def test_update_message_append_includes_mentions():
203203

204204
# Append content with another mention
205205
msg.body = f" and @{USER3.mention_name}!"
206-
chat.update_message(msg, append=True)
206+
chat.update_message(msg, append=True, is_done=True)
207207
updated_msg = chat.get_message(msg_id)
208208
assert updated_msg
209209
# Should now mention both users
@@ -224,7 +224,7 @@ def test_update_message_append_no_duplicate_mentions():
224224

225225
# Append content that mentions the same user again
226226
msg.body = f" @{USER2.mention_name} again!"
227-
chat.update_message(msg, append=True)
227+
chat.update_message(msg, append=True, is_done=True)
228228
updated_msg = chat.get_message(msg_id)
229229
assert updated_msg
230230
# Should only have one mention despite appearing twice

python/jupyterlab-chat/jupyterlab_chat/ychat.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,11 @@ def add_message(self, new_message: NewMessage) -> str:
162162

163163
return uid
164164

165-
def update_message(self, message: Message, append: bool = False):
165+
def update_message(self, message: Message, append: bool = False, is_done: bool = False):
166166
"""
167167
Update a message of the document.
168-
If append is True, the content will be append to the previous content.
168+
If append is True, the content will be appended to the previous content.
169+
If is_done is True, mentions will be extracted and notifications triggered (use for streaming completion).
169170
"""
170171
with self._ydoc.transaction():
171172
index = self._indexes_by_id[message.id]
@@ -175,7 +176,8 @@ def update_message(self, message: Message, append: bool = False):
175176
message.body = initial_message["body"] + message.body # type:ignore[index]
176177

177178
# Extract and update mentions from the message body
178-
message.mentions = self._extract_mentions(message.body)
179+
if is_done:
180+
message.mentions = self._extract_mentions(message.body)
179181

180182
self._ymessages[index] = asdict(message, dict_factory=message_asdict_factory)
181183

0 commit comments

Comments
 (0)