Fixed mayber #3

Merged
TySS-Dev merged 26 commits from testing into main 2026-05-19 06:01:41 -04:00
Showing only changes of commit 23ecac6afa - Show all commits
+24 -13
View File
@@ -876,8 +876,18 @@ FRONTEND_JS_TEMPLATE = r"""
}; };
const box = document.getElementById('sxng-stream-box'); const box = document.getElementById('sxng-stream-box');
const data = document.getElementById('sxng-stream-data'); const data = document.getElementById('sxng-stream-data');
const wrapper = box.closest('.answer');
if (wrapper) wrapper.style.display = 'none'; // Hide native SearXNG answer entries that are siblings of our box
setTimeout(() => {
const parent = box ? box.parentElement : null;
if (parent) {
Array.from(parent.children).forEach(el => {
if (el !== box && el.classList.contains('answer')) {
el.style.display = 'none';
}
});
}
}, 0);
let restored = false; let restored = false;
let isStreaming = false; let isStreaming = false;
@@ -947,7 +957,6 @@ FRONTEND_JS_TEMPLATE = r"""
isStreaming = true; isStreaming = true;
try { try {
const ctx = auxContext || conversation.originalContext; const ctx = auxContext || conversation.originalContext;
if (wrapper) wrapper.style.display = '';
box.style.display = 'block'; box.style.display = 'block';
const controller = new AbortController(); const controller = new AbortController();
@@ -1002,6 +1011,11 @@ FRONTEND_JS_TEMPLATE = r"""
data.appendChild(cursor); data.appendChild(cursor);
} }
const streamContainer = document.createElement('div');
streamContainer.className = 'sxng-stream-container';
if (cursor) cursor.before(streamContainer);
else data.appendChild(streamContainer);
let buffer = ''; let buffer = '';
let fullText = ''; let fullText = '';
const flushBuffer = (force = false) => { const flushBuffer = (force = false) => {
@@ -1009,8 +1023,7 @@ FRONTEND_JS_TEMPLATE = r"""
if (force) { if (force) {
const fragment = renderCitations(buffer, urls); const fragment = renderCitations(buffer, urls);
if (cursor) cursor.before(fragment); streamContainer.appendChild(fragment);
else data.appendChild(fragment);
buffer = ''; buffer = '';
return; return;
} }
@@ -1025,12 +1038,12 @@ FRONTEND_JS_TEMPLATE = r"""
const s = document.createElement('span'); const s = document.createElement('span');
s.className = 'sxng-chunk'; s.className = 'sxng-chunk';
s.textContent = preText; s.textContent = preText;
cursor.before(s); streamContainer.appendChild(s);
} }
const citationText = match[0]; const citationText = match[0];
const fragment = renderCitations(citationText, urls); const fragment = renderCitations(citationText, urls);
cursor.before(fragment); streamContainer.appendChild(fragment);
buffer = buffer.substring(match.index + match[0].length); buffer = buffer.substring(match.index + match[0].length);
} }
@@ -1041,7 +1054,7 @@ FRONTEND_JS_TEMPLATE = r"""
const s = document.createElement('span'); const s = document.createElement('span');
s.className = 'sxng-chunk'; s.className = 'sxng-chunk';
s.textContent = buffer; s.textContent = buffer;
cursor.before(s); streamContainer.appendChild(s);
buffer = ''; buffer = '';
} }
} else { } else {
@@ -1050,7 +1063,7 @@ FRONTEND_JS_TEMPLATE = r"""
const s = document.createElement('span'); const s = document.createElement('span');
s.className = 'sxng-chunk'; s.className = 'sxng-chunk';
s.textContent = safeChunk; s.textContent = safeChunk;
cursor.before(s); streamContainer.appendChild(s);
} }
buffer = buffer.substring(openIdx); buffer = buffer.substring(openIdx);
@@ -1058,7 +1071,7 @@ FRONTEND_JS_TEMPLATE = r"""
const s = document.createElement('span'); const s = document.createElement('span');
s.className = 'sxng-chunk'; s.className = 'sxng-chunk';
s.textContent = buffer[0]; s.textContent = buffer[0];
cursor.before(s); streamContainer.appendChild(s);
buffer = buffer.substring(1); buffer = buffer.substring(1);
} }
} }
@@ -1120,11 +1133,9 @@ FRONTEND_JS_TEMPLATE = r"""
} }
} }
streamContainer.remove();
if (cursor) cursor.remove(); if (cursor) cursor.remove();
// Remove only the streamed chunk spans added during this stream
Array.from(data.querySelectorAll('.sxng-chunk')).forEach(node => node.remove());
const rendered = parseMarkdown(fullText.trim()); const rendered = parseMarkdown(fullText.trim());
const mdDiv = document.createElement('div'); const mdDiv = document.createElement('div');
mdDiv.className = 'sxng-md-content'; mdDiv.className = 'sxng-md-content';