From f73c6d90a623e32dffb1b808fc787b60bb383ce9 Mon Sep 17 00:00:00 2001 From: "adamlui@protonmail.com" Date: Sun, 26 Jan 2025 08:21:00 -0800 Subject: [PATCH] Eliminated no-longer needed merging of API URLs w/ fail flags --- amazongpt/greasemonkey/amazongpt.user.js | 19 +++++++------------ bravegpt/greasemonkey/bravegpt.user.js | 19 +++++++------------ duckduckgpt/greasemonkey/duckduckgpt.user.js | 19 +++++++------------ googlegpt/greasemonkey/googlegpt.user.js | 19 +++++++------------ 4 files changed, 28 insertions(+), 48 deletions(-) diff --git a/amazongpt/greasemonkey/amazongpt.user.js b/amazongpt/greasemonkey/amazongpt.user.js index 2bbaff7bb..b7a330988 100644 --- a/amazongpt/greasemonkey/amazongpt.user.js +++ b/amazongpt/greasemonkey/amazongpt.user.js @@ -3,7 +3,7 @@ // @description Adds the magic of AI to Amazon shopping // @author KudoAI // @namespace https://kudoai.com -// @version 2025.1.26.8 +// @version 2025.1.26.9 // @license MIT // @icon https://amazongpt.kudoai.com/assets/images/icons/amazongpt/black-gold-teal/icon48.png?v=0fddfc7 // @icon64 https://amazongpt.kudoai.com/assets/images/icons/amazongpt/black-gold-teal/icon64.png?v=0fddfc7 @@ -2635,17 +2635,12 @@ const dataProcess = { - initFailFlags(api) { // escape/merge URLs w/ fail flags - const { respPatterns = {}, endpoint = apis[api].endpoints.completions, expectedOrigin } = apis[api], - escapedAPIurls = [endpoint, expectedOrigin.url].map(url => url.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')) - return new RegExp([respPatterns.fail, ...escapedAPIurls].filter(Boolean).join('|')) - }, + initFailFlags(api) { return apis[api].respPatterns?.fail ? new RegExp(apis[api].respPatterns.fail) : null }, stream(resp, { caller, callerAPI }) { if (config.streamingDisabled || !config.proxyAPIenabled) return log.caller = `get.${caller.name}() » dataProcess.stream()` - const failFlagsAndURLs = this.initFailFlags(callerAPI), - reader = resp.response.getReader() + const reader = resp.response.getReader(), reFailFlags = this.initFailFlags(callerAPI) let textToShow = '', isDone = false reader.read().then(chunk => handleChunk(chunk, callerAPI)) .catch(err => log.error('Error processing stream', err.message)) @@ -2683,7 +2678,7 @@ // Show accumulated reply chunks try { - const failMatch = failFlagsAndURLs.exec(textToShow) + const failMatch = reFailFlags?.exec(textToShow) if (failMatch) { log.debug('Text to show', textToShow) ; log.error('Fail flag detected', `'${failMatch[0]}'`) if (env.browser.isChromium) clearTimeout(this.timeout) // skip handleProcessCompletion() @@ -2721,7 +2716,7 @@ if (caller == get.reply && config.proxyAPIenabled && !config.streamingDisabled || caller.status == 'done') return log.caller = `get.${caller.name}() » dataProcess.text()` - const failFlagsAndURLs = this.initFailFlags(callerAPI) ; let textToShow = '' + const reFailFlags = this.initFailFlags(callerAPI) ; let textToShow = '' if (resp.status != 200) { log.error('Response status', resp.status) log.info('Response text', resp.response || resp.responseText) @@ -2732,7 +2727,7 @@ : ['openAInotWorking', 'suggestProxy'] ) else api.tryNew(caller) } else if (callerAPI == 'OpenAI' && resp.response) { // show response from OpenAI - const failMatch = failFlagsAndURLs.exec(resp.response) + const failMatch = reFailFlags?.exec(resp.response) if (failMatch) { // suggest proxy log.debug('Response text', resp.response) ; log.error('Fail flag detected', `'${failMatch[0]}'`) appAlert('openAInotWorking', 'suggestProxy') @@ -2769,7 +2764,7 @@ function handleProcessCompletion() { if (caller.status != 'done') { log.debug('Text to show', textToShow) - const failMatch = failFlagsAndURLs.exec(textToShow) + const failMatch = reFailFlags?.exec(textToShow) if (!textToShow || failMatch) { if (failMatch) log.error('Fail flag detected', `'${failMatch[0]}'`) api.tryNew(caller) diff --git a/bravegpt/greasemonkey/bravegpt.user.js b/bravegpt/greasemonkey/bravegpt.user.js index c69e44eae..9fdebc84e 100644 --- a/bravegpt/greasemonkey/bravegpt.user.js +++ b/bravegpt/greasemonkey/bravegpt.user.js @@ -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.26.8 +// @version 2025.1.26.9 // @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 @@ -3385,17 +3385,12 @@ const dataProcess = { - initFailFlags(api) { // escape/merge URLs w/ fail flags - const { respPatterns = {}, endpoint = apis[api].endpoints.completions, expectedOrigin } = apis[api], - escapedAPIurls = [endpoint, expectedOrigin.url].map(url => url.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')) - return new RegExp([respPatterns.fail, ...escapedAPIurls].filter(Boolean).join('|')) - }, + initFailFlags(api) { return apis[api].respPatterns?.fail ? new RegExp(apis[api].respPatterns.fail) : null }, stream(resp, { caller, callerAPI }) { if (config.streamingDisabled || !config.proxyAPIenabled) return log.caller = `get.${caller.name}() » dataProcess.stream()` - const failFlagsAndURLs = this.initFailFlags(callerAPI), - reader = resp.response.getReader() + const reader = resp.response.getReader(), reFailFlags = this.initFailFlags(callerAPI) let textToShow = '', isDone = false reader.read().then(chunk => handleChunk(chunk, callerAPI)) .catch(err => log.error('Error processing stream', err.message)) @@ -3433,7 +3428,7 @@ // Show accumulated reply chunks try { - const failMatch = failFlagsAndURLs.exec(textToShow) + const failMatch = reFailFlags?.exec(textToShow) if (failMatch) { log.debug('Text to show', textToShow) ; log.error('Fail flag detected', `'${failMatch[0]}'`) if (env.browser.isChromium) clearTimeout(this.timeout) // skip handleProcessCompletion() @@ -3471,7 +3466,7 @@ if (caller == get.reply && config.proxyAPIenabled && !config.streamingDisabled || caller.status == 'done') return log.caller = `get.${caller.name}() » dataProcess.text()` - const failFlagsAndURLs = this.initFailFlags(callerAPI) ; let textToShow = '' + const reFailFlags = this.initFailFlags(callerAPI) ; let textToShow = '' if (resp.status != 200) { log.error('Response status', resp.status) log.info('Response text', resp.response || resp.responseText) @@ -3482,7 +3477,7 @@ : ['openAInotWorking', 'suggestProxy'] ) else api.tryNew(caller) } else if (callerAPI == 'OpenAI' && resp.response) { // show response or return RQs from OpenAI - const failMatch = failFlagsAndURLs.exec(resp.response) + const failMatch = reFailFlags?.exec(resp.response) if (failMatch) { // suggest proxy or try diff API log.debug('Response text', resp.response) ; log.error('Fail flag detected', `'${failMatch[0]}'`) if (caller == get.reply) appAlert('openAInotWorking', 'suggestProxy') @@ -3520,7 +3515,7 @@ function handleProcessCompletion() { if (caller.status != 'done') { log.debug('Text to show', textToShow) - const failMatch = failFlagsAndURLs.exec(textToShow) + const failMatch = reFailFlags?.exec(textToShow) if (!textToShow || failMatch) { if (failMatch) log.error('Fail flag detected', `'${failMatch[0]}'`) api.tryNew(caller) diff --git a/duckduckgpt/greasemonkey/duckduckgpt.user.js b/duckduckgpt/greasemonkey/duckduckgpt.user.js index a8822bc27..89c011fd4 100644 --- a/duckduckgpt/greasemonkey/duckduckgpt.user.js +++ b/duckduckgpt/greasemonkey/duckduckgpt.user.js @@ -148,7 +148,7 @@ // @description:zu Yengeza izimpendulo ze-AI ku-DuckDuckGo (inikwa amandla yi-GPT-4o!) // @author KudoAI // @namespace https://kudoai.com -// @version 2025.1.26.8 +// @version 2025.1.26.9 // @license MIT // @icon https://assets.ddgpt.com/images/icons/duckduckgpt/icon48.png?v=06af076 // @icon64 https://assets.ddgpt.com/images/icons/duckduckgpt/icon64.png?v=06af076 @@ -3269,17 +3269,12 @@ const dataProcess = { - initFailFlags(api) { // escape/merge URLs w/ fail flags - const { respPatterns = {}, endpoint = apis[api].endpoints.completions, expectedOrigin } = apis[api], - escapedAPIurls = [endpoint, expectedOrigin.url].map(url => url.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')) - return new RegExp([respPatterns.fail, ...escapedAPIurls].filter(Boolean).join('|')) - }, + initFailFlags(api) { return apis[api].respPatterns?.fail ? new RegExp(apis[api].respPatterns.fail) : null }, stream(resp, { caller, callerAPI }) { if (config.streamingDisabled || !config.proxyAPIenabled) return log.caller = `get.${caller.name}() » dataProcess.stream()` - const failFlagsAndURLs = this.initFailFlags(callerAPI), - reader = resp.response.getReader() + const reader = resp.response.getReader(), reFailFlags = this.initFailFlags(callerAPI) let textToShow = '', isDone = false reader.read().then(chunk => handleChunk(chunk, callerAPI)) .catch(err => log.error('Error processing stream', err.message)) @@ -3317,7 +3312,7 @@ // Show accumulated reply chunks try { - const failMatch = failFlagsAndURLs.exec(textToShow) + const failMatch = reFailFlags?.exec(textToShow) if (failMatch) { log.debug('Text to show', textToShow) ; log.error('Fail flag detected', `'${failMatch[0]}'`) if (env.browser.isChromium) clearTimeout(this.timeout) // skip handleProcessCompletion() @@ -3355,7 +3350,7 @@ if (caller == get.reply && config.proxyAPIenabled && !config.streamingDisabled || caller.status == 'done') return log.caller = `get.${caller.name}() » dataProcess.text()` - const failFlagsAndURLs = this.initFailFlags(callerAPI) ; let textToShow = '' + const reFailFlags = this.initFailFlags(callerAPI) ; let textToShow = '' if (resp.status != 200) { log.error('Response status', resp.status) log.info('Response text', resp.response || resp.responseText) @@ -3366,7 +3361,7 @@ : ['openAInotWorking', 'suggestProxy'] ) else api.tryNew(caller) } else if (callerAPI == 'OpenAI' && resp.response) { // show response or return RQs from OpenAI - const failMatch = failFlagsAndURLs.exec(resp.response) + const failMatch = reFailFlags?.exec(resp.response) if (failMatch) { // suggest proxy or try diff API log.debug('Response text', resp.response) ; log.error('Fail flag detected', `'${failMatch[0]}'`) if (caller == get.reply) appAlert('openAInotWorking', 'suggestProxy') @@ -3404,7 +3399,7 @@ function handleProcessCompletion() { if (caller.status != 'done') { log.debug('Text to show', textToShow) - const failMatch = failFlagsAndURLs.exec(textToShow) + const failMatch = reFailFlags?.exec(textToShow) if (!textToShow || failMatch) { if (failMatch) log.error('Fail flag detected', `'${failMatch[0]}'`) api.tryNew(caller) diff --git a/googlegpt/greasemonkey/googlegpt.user.js b/googlegpt/greasemonkey/googlegpt.user.js index 3b9115f0f..4261be74c 100644 --- a/googlegpt/greasemonkey/googlegpt.user.js +++ b/googlegpt/greasemonkey/googlegpt.user.js @@ -149,7 +149,7 @@ // @description:zu Yengeza izimpendulo ze-AI ku-Google Search (inikwa amandla yi-Google Gemma + GPT-4o!) // @author KudoAI // @namespace https://kudoai.com -// @version 2025.1.26.8 +// @version 2025.1.26.9 // @license MIT // @icon https://assets.googlegpt.io/images/icons/googlegpt/black/icon48.png?v=59409b2 // @icon64 https://assets.googlegpt.io/images/icons/googlegpt/black/icon64.png?v=59409b2 @@ -3566,17 +3566,12 @@ const dataProcess = { - initFailFlags(api) { // escape/merge URLs w/ fail flags - const { respPatterns = {}, endpoint = apis[api].endpoints.completions, expectedOrigin } = apis[api], - escapedAPIurls = [endpoint, expectedOrigin.url].map(url => url.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')) - return new RegExp([respPatterns.fail, ...escapedAPIurls].filter(Boolean).join('|')) - }, + initFailFlags(api) { return apis[api].respPatterns?.fail ? new RegExp(apis[api].respPatterns.fail) : null }, stream(resp, { caller, callerAPI }) { if (config.streamingDisabled || !config.proxyAPIenabled) return log.caller = `get.${caller.name}() » dataProcess.stream()` - const failFlagsAndURLs = this.initFailFlags(callerAPI), - reader = resp.response.getReader() + const reader = resp.response.getReader(), reFailFlags = this.initFailFlags(callerAPI) let textToShow = '', isDone = false reader.read().then(chunk => handleChunk(chunk, callerAPI)) .catch(err => log.error('Error processing stream', err.message)) @@ -3614,7 +3609,7 @@ // Show accumulated reply chunks try { - const failMatch = failFlagsAndURLs.exec(textToShow) + const failMatch = reFailFlags?.exec(textToShow) if (failMatch) { log.debug('Text to show', textToShow) ; log.error('Fail flag detected', `'${failMatch[0]}'`) if (env.browser.isChromium) clearTimeout(this.timeout) // skip handleProcessCompletion() @@ -3652,7 +3647,7 @@ if (caller == get.reply && config.proxyAPIenabled && !config.streamingDisabled || caller.status == 'done') return log.caller = `get.${caller.name}() » dataProcess.text()` - const failFlagsAndURLs = this.initFailFlags(callerAPI) ; let textToShow = '' + const reFailFlags = this.initFailFlags(callerAPI) ; let textToShow = '' if (resp.status != 200) { log.error('Response status', resp.status) log.info('Response text', resp.response || resp.responseText) @@ -3663,7 +3658,7 @@ : ['openAInotWorking', 'suggestProxy'] ) else api.tryNew(caller) } else if (callerAPI == 'OpenAI' && resp.response) { // show response or return RQs from OpenAI - const failMatch = failFlagsAndURLs.exec(resp.response) + const failMatch = reFailFlags?.exec(resp.response) if (failMatch) { // suggest proxy or try diff API log.debug('Response text', resp.response) ; log.error('Fail flag detected', `'${failMatch[0]}'`) if (caller == get.reply) appAlert('openAInotWorking', 'suggestProxy') @@ -3701,7 +3696,7 @@ function handleProcessCompletion() { if (caller.status != 'done') { log.debug('Text to show', textToShow) - const failMatch = failFlagsAndURLs.exec(textToShow) + const failMatch = reFailFlags?.exec(textToShow) if (!textToShow || failMatch) { if (failMatch) log.error('Fail flag detected', `'${failMatch[0]}'`) api.tryNew(caller)