in static/chat.js [52:66]
eventSource.onmessage = function (event) {
const currentText = assistantMessageDiv.textContent;
const newText = event.data;
const lastChar = currentText.slice(-1);
// Check if we need to add a space (streamed chunks might be missing it)
if (/[.,!?]/.test(lastChar) && newText.charAt(0) !== " ") {
assistantMessageDiv.textContent += " " + newText;
} else {
assistantMessageDiv.textContent += newText;
}
// Scroll to the bottom of the chat container
chatContainer.scrollTop = chatContainer.scrollHeight;
};