Skip to content

Commit

Permalink
Added manual timeout to processStreamText() to handle missing `done…
Browse files Browse the repository at this point in the history
…` signal from `reader.read()` in Chromium browsers ↞ [auto-sync from https://github.com/adamlui/ai-web-extensionss/tree/main/bravegpt]
  • Loading branch information
kudo-sync-bot committed Jan 15, 2025
1 parent 2fd8de1 commit 1ab59f4
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions chatgpt/bravegpt/bravegpt.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
// @description:zu Yengeza izimpendulo ze-AI ku-Brave Search (inikwa amandla yi-GPT-4o!)
// @author KudoAI
// @namespace https://kudoai.com
// @version 2025.1.15.4
// @version 2025.1.15.5
// @license MIT
// @icon https://assets.bravegpt.com/images/icons/bravegpt/icon48.png?v=df624b0
// @icon64 https://assets.bravegpt.com/images/icons/bravegpt/icon64.png?v=df624b0
Expand Down Expand Up @@ -3405,9 +3405,14 @@
reader.read().then(processStreamText).catch(err => log.error('Error processing stream', err.message))

function processStreamText({ done, value }) {

// Handle stream done
if (done) { handleProcessCompletion() ; return }
let chunk = new TextDecoder('utf8').decode(new Uint8Array(value))
if (chunk.includes(apis[caller.api].watermark)) { handleProcessCompletion() ; return }
this.timeout = setTimeout(handleProcessCompletion, 500) // since reader.read() doesn't signal done in Chromium

// Process/show chunk
if (caller.api == 'MixerBox AI') { // pre-process chunks
const extractedChunks = Array.from(chunk.matchAll(/data:(.*)/g), match => match[1]
.replace(/\[SPACE\]/g, ' ').replace(/\[NEWLINE\]/g, '\n'))
Expand Down Expand Up @@ -3444,7 +3449,7 @@
}

function handleProcessCompletion() {
caller.sender = null
caller.sender = this.timeout = null
if (appDiv.querySelector('.loading')) // no text shown
api.tryNew(caller)
else { // text was shown
Expand Down

0 comments on commit 1ab59f4

Please sign in to comment.