function read()

in static/js/chat.js [295:328]


         function read() {
           return reader.read().then(({ value, done }) => {
             if (done) return;
             let chunk = new TextDecoder().decode(value, { stream: true });
             
             // Check if the first 36 characters form a valid UUID.
             if (chunk.length >= 37) {
               let possibleId = chunk.substring(0, 36);
               // Simple regex for UUID validation.
               const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
               if (uuidRegex.test(possibleId)) {
                 // Store/update the conversationId and remove it from the chunk.
                 conversationId = possibleId;
                 console.log("Conversation ID: [", conversationId, "]");
                 chunk = chunk.substring(37);
               }
             }
             
             assistantReply += chunk;
             displaySentence += chunk;
             spokenSentence += chunk;
             
             if (chunk.trim() === "" || chunk.trim() === "\n") {
               console.log("Speak Chunk: [", spokenSentence.trim(), "]");
               speak(spokenSentence.trim());
               spokenSentence = "";
             }
             
             chatHistoryTextArea.innerHTML += displaySentence;
             chatHistoryTextArea.scrollTop = chatHistoryTextArea.scrollHeight;
             displaySentence = "";
             return read();
           });
         }