Skip to content

Commit b7df503

Browse files
authored
Merge pull request #68 from rmusser01/dev
Update chat_message.py
2 parents c94557a + b1b1ebf commit b7df503

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

tldw_chatbook/Widgets/chat_message.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,20 @@ def watch__generation_complete_internal(self, complete: bool) -> None:
173173
Watcher for the internal generation status.
174174
Updates the actions bar visibility and the continue button visibility for AI messages.
175175
"""
176+
logging.info(f"watch__generation_complete_internal called with complete={complete} for ChatMessage (ID: {self.id}, Role: {self.role})")
176177
if self.has_class("-ai"):
178+
logging.info(f"ChatMessage has -ai class")
177179
try:
178180
actions_container = self.query_one(".message-actions")
181+
logging.info(f"Found actions_container: {actions_container}")
179182
if complete:
183+
logging.info(f"Setting actions_container to visible")
180184
actions_container.remove_class("-generating")
181185
actions_container.styles.display = "block"
186+
# Force update the DOM to ensure changes are applied
187+
self.refresh()
182188
else:
189+
logging.info(f"Setting actions_container to hidden")
183190
actions_container.add_class("-generating")
184191

185192
# Separately handle the continue button in its own try...except block
@@ -193,10 +200,11 @@ def watch__generation_complete_internal(self, complete: bool) -> None:
193200

194201
except QueryError as qe:
195202
# This might happen if the query runs before the widget is fully composed or if it's being removed.
196-
logging.debug(f"ChatMessage (ID: {self.id}, Role: {self.role}): QueryError in watch__generation_complete_internal: {qe}. Widget might not be fully ready or is not an AI message with these components.")
203+
logging.warning(f"ChatMessage (ID: {self.id}, Role: {self.role}): QueryError in watch__generation_complete_internal: {qe}. Widget might not be fully ready or is not an AI message with these components.")
197204
except Exception as e:
198205
logging.error(f"Error in watch__generation_complete_internal for ChatMessage (ID: {self.id}): {e}", exc_info=True)
199206
else: # Not an AI message
207+
logging.info(f"ChatMessage does not have -ai class")
200208
try: # Ensure continue button is hidden for non-AI messages if it somehow got queried
201209
continue_button = self.query_one("#continue-response-button", Button)
202210
continue_button.display = False
@@ -216,8 +224,12 @@ def mark_generation_complete(self):
216224
Marks the AI message generation as complete.
217225
This will trigger the watcher for _generation_complete_internal to update UI.
218226
"""
227+
logging.info(f"mark_generation_complete called for ChatMessage (ID: {self.id}, Role: {self.role})")
219228
if self.has_class("-ai"):
229+
logging.info(f"Setting _generation_complete_internal to True")
220230
self._generation_complete_internal = True
231+
# Force a refresh to ensure UI updates
232+
self.refresh()
221233

222234
def on_mount(self) -> None:
223235
"""Ensure initial state of continue button and actions bar is correct after mounting."""

0 commit comments

Comments
 (0)