incognitolm commited on
Commit
8a7fbbb
Β·
verified Β·
1 Parent(s): a5154d0

Update public/js/chat.js

Browse files
Files changed (1) hide show
  1. public/js/chat.js +27 -3
public/js/chat.js CHANGED
@@ -11,6 +11,9 @@ let isStreaming = false;
11
  let streamingBubble = null;
12
  let streamingText = '';
13
  let autoScroll = true;
 
 
 
14
 
15
  export function setActiveSession(id) { activeSessionId = id; }
16
  export function getIsStreaming() { return isStreaming; }
@@ -324,7 +327,7 @@ function makeBtn(label, cls) {
324
  // ── Streaming ─────────────────────────────────────────────────────────────
325
 
326
  function onChatStart() {
327
- isStreaming = true; streamingText = '';
328
  showChat();
329
  const box = document.getElementById('chat-messages'); if (!box) return;
330
  streamingBubble = document.createElement('div');
@@ -357,7 +360,18 @@ function onChatDone(msg) {
357
  streamingBubble?.classList.remove('msg-generating');
358
  streamingBubble = null; streamingText = '';
359
  updateSendBtn(false);
360
- if (msg.history) renderHistory(msg.history);
 
 
 
 
 
 
 
 
 
 
 
361
  }
362
 
363
  function onChatAborted(msg) {
@@ -371,7 +385,15 @@ function onChatAborted(msg) {
371
  streamingBubble = null;
372
  }
373
  updateSendBtn(false);
374
- if (msg.history) renderHistory(msg.history);
 
 
 
 
 
 
 
 
375
  }
376
 
377
  function onChatError(err) {
@@ -409,6 +431,8 @@ function handleLiveToolCall(call) {
409
 
410
  function appendAsset(asset) {
411
  const box = document.getElementById('chat-messages'); if (!box) return;
 
 
412
  appendMediaMsg(box, asset.role, asset.content);
413
  if (autoScroll) box.scrollTop = box.scrollHeight;
414
  }
 
11
  let streamingBubble = null;
12
  let streamingText = '';
13
  let autoScroll = true;
14
+ // Assets (images/video/audio) received during the current stream.
15
+ // Stored here so they can be re-injected after renderHistory() wipes the DOM.
16
+ let pendingAssets = [];
17
 
18
  export function setActiveSession(id) { activeSessionId = id; }
19
  export function getIsStreaming() { return isStreaming; }
 
327
  // ── Streaming ─────────────────────────────────────────────────────────────
328
 
329
  function onChatStart() {
330
+ isStreaming = true; streamingText = ''; pendingAssets = [];
331
  showChat();
332
  const box = document.getElementById('chat-messages'); if (!box) return;
333
  streamingBubble = document.createElement('div');
 
360
  streamingBubble?.classList.remove('msg-generating');
361
  streamingBubble = null; streamingText = '';
362
  updateSendBtn(false);
363
+ if (msg.history) {
364
+ renderHistory(msg.history);
365
+ // Re-inject any assets that arrived during the stream (they are not in history)
366
+ if (pendingAssets.length > 0) {
367
+ const box = document.getElementById('chat-messages');
368
+ if (box) {
369
+ pendingAssets.forEach(asset => appendMediaMsg(box, asset.role, asset.content));
370
+ if (autoScroll) box.scrollTop = box.scrollHeight;
371
+ }
372
+ pendingAssets = [];
373
+ }
374
+ }
375
  }
376
 
377
  function onChatAborted(msg) {
 
385
  streamingBubble = null;
386
  }
387
  updateSendBtn(false);
388
+ // Re-inject assets even on abort
389
+ if (msg.history) {
390
+ renderHistory(msg.history);
391
+ if (pendingAssets.length > 0) {
392
+ const box = document.getElementById('chat-messages');
393
+ if (box) pendingAssets.forEach(asset => appendMediaMsg(box, asset.role, asset.content));
394
+ }
395
+ }
396
+ pendingAssets = [];
397
  }
398
 
399
  function onChatError(err) {
 
431
 
432
  function appendAsset(asset) {
433
  const box = document.getElementById('chat-messages'); if (!box) return;
434
+ // Store so we can re-inject after renderHistory() wipes the DOM on chat:done
435
+ pendingAssets.push(asset);
436
  appendMediaMsg(box, asset.role, asset.content);
437
  if (autoScroll) box.scrollTop = box.scrollHeight;
438
  }