1
0

fix: restore real-time chat responses via WebSocket (#98)

The chat WebSocket return path was broken by two bugs that prevented
Timmy's responses from appearing in the live chat feed:

1. Frontend checked msg.type instead of msg.event for 'timmy_response'
   events — the WSEvent dataclass uses 'event' as the field name.
2. Frontend accessed msg.response instead of msg.data.response — the
   response payload is nested in the data field.

Additional fixes:
- Queue acknowledgment ("Message queued...") no longer logged as an
  agent message in chat history; the real response is logged by the
  task processor when it completes, eliminating duplicate messages.
- Chat message template now carries data-task-id so the WS handler
  can find and replace the placeholder with the actual response.
- appendMessage() uses DOM APIs (textContent) instead of innerHTML
  for safer content insertion before markdown rendering.
- Fixed chat_message.html script targeting when queue-status div is
  present between the agent message and the inline script.

https://claude.ai/code/session_011cJfexqBBuGhSRQU8qwKcR

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Alexander Whitestone
2026-02-28 20:22:47 -05:00
committed by GitHub
parent d4acaefee9
commit 2e92838033
5 changed files with 68 additions and 19 deletions

View File

@@ -3,7 +3,7 @@
<div class="msg-body">{{ user_message | e }}</div>
</div>
{% if response %}
<div class="chat-message agent">
<div class="chat-message agent"{% if task_id %} data-task-id="{{ task_id }}"{% endif %}>
<div class="msg-meta">TIMMY // {{ timestamp }}</div>
<div class="msg-body timmy-md">{{ response | e }}</div>
</div>
@@ -14,7 +14,11 @@
{% endif %}
<script>
(function() {
var el = document.currentScript.previousElementSibling.querySelector('.timmy-md');
var script = document.currentScript;
var prev = script.previousElementSibling;
// Skip queue-status div to find the agent message div
if (prev && prev.classList.contains('queue-status')) prev = prev.previousElementSibling;
var el = prev ? prev.querySelector('.timmy-md') : null;
if (el && typeof marked !== 'undefined' && typeof DOMPurify !== 'undefined') {
el.innerHTML = DOMPurify.sanitize(marked.parse(el.textContent));
if (typeof hljs !== 'undefined') {