Skip to content

Commit f73c6d9

Browse files
committed
Eliminated no-longer needed merging of API URLs w/ fail flags
1 parent 5b3702f commit f73c6d9

File tree

4 files changed

+28
-48
lines changed

4 files changed

+28
-48
lines changed

amazongpt/greasemonkey/amazongpt.user.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// @description Adds the magic of AI to Amazon shopping
44
// @author KudoAI
55
// @namespace https://kudoai.com
6-
// @version 2025.1.26.8
6+
// @version 2025.1.26.9
77
// @license MIT
88
// @icon https://amazongpt.kudoai.com/assets/images/icons/amazongpt/black-gold-teal/icon48.png?v=0fddfc7
99
// @icon64 https://amazongpt.kudoai.com/assets/images/icons/amazongpt/black-gold-teal/icon64.png?v=0fddfc7
@@ -2635,17 +2635,12 @@
26352635

26362636
const dataProcess = {
26372637

2638-
initFailFlags(api) { // escape/merge URLs w/ fail flags
2639-
const { respPatterns = {}, endpoint = apis[api].endpoints.completions, expectedOrigin } = apis[api],
2640-
escapedAPIurls = [endpoint, expectedOrigin.url].map(url => url.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'))
2641-
return new RegExp([respPatterns.fail, ...escapedAPIurls].filter(Boolean).join('|'))
2642-
},
2638+
initFailFlags(api) { return apis[api].respPatterns?.fail ? new RegExp(apis[api].respPatterns.fail) : null },
26432639

26442640
stream(resp, { caller, callerAPI }) {
26452641
if (config.streamingDisabled || !config.proxyAPIenabled) return
26462642
log.caller = `get.${caller.name}() » dataProcess.stream()`
2647-
const failFlagsAndURLs = this.initFailFlags(callerAPI),
2648-
reader = resp.response.getReader()
2643+
const reader = resp.response.getReader(), reFailFlags = this.initFailFlags(callerAPI)
26492644
let textToShow = '', isDone = false
26502645
reader.read().then(chunk => handleChunk(chunk, callerAPI))
26512646
.catch(err => log.error('Error processing stream', err.message))
@@ -2683,7 +2678,7 @@
26832678

26842679
// Show accumulated reply chunks
26852680
try {
2686-
const failMatch = failFlagsAndURLs.exec(textToShow)
2681+
const failMatch = reFailFlags?.exec(textToShow)
26872682
if (failMatch) {
26882683
log.debug('Text to show', textToShow) ; log.error('Fail flag detected', `'${failMatch[0]}'`)
26892684
if (env.browser.isChromium) clearTimeout(this.timeout) // skip handleProcessCompletion()
@@ -2721,7 +2716,7 @@
27212716
if (caller == get.reply && config.proxyAPIenabled && !config.streamingDisabled
27222717
|| caller.status == 'done') return
27232718
log.caller = `get.${caller.name}() » dataProcess.text()`
2724-
const failFlagsAndURLs = this.initFailFlags(callerAPI) ; let textToShow = ''
2719+
const reFailFlags = this.initFailFlags(callerAPI) ; let textToShow = ''
27252720
if (resp.status != 200) {
27262721
log.error('Response status', resp.status)
27272722
log.info('Response text', resp.response || resp.responseText)
@@ -2732,7 +2727,7 @@
27322727
: ['openAInotWorking', 'suggestProxy'] )
27332728
else api.tryNew(caller)
27342729
} else if (callerAPI == 'OpenAI' && resp.response) { // show response from OpenAI
2735-
const failMatch = failFlagsAndURLs.exec(resp.response)
2730+
const failMatch = reFailFlags?.exec(resp.response)
27362731
if (failMatch) { // suggest proxy
27372732
log.debug('Response text', resp.response) ; log.error('Fail flag detected', `'${failMatch[0]}'`)
27382733
appAlert('openAInotWorking', 'suggestProxy')
@@ -2769,7 +2764,7 @@
27692764
function handleProcessCompletion() {
27702765
if (caller.status != 'done') {
27712766
log.debug('Text to show', textToShow)
2772-
const failMatch = failFlagsAndURLs.exec(textToShow)
2767+
const failMatch = reFailFlags?.exec(textToShow)
27732768
if (!textToShow || failMatch) {
27742769
if (failMatch) log.error('Fail flag detected', `'${failMatch[0]}'`)
27752770
api.tryNew(caller)

bravegpt/greasemonkey/bravegpt.user.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
// @description:zu Yengeza izimpendulo ze-AI ku-Brave Search (inikwa amandla yi-GPT-4o!)
149149
// @author KudoAI
150150
// @namespace https://kudoai.com
151-
// @version 2025.1.26.8
151+
// @version 2025.1.26.9
152152
// @license MIT
153153
// @icon https://assets.bravegpt.com/images/icons/bravegpt/icon48.png?v=df624b0
154154
// @icon64 https://assets.bravegpt.com/images/icons/bravegpt/icon64.png?v=df624b0
@@ -3385,17 +3385,12 @@
33853385

33863386
const dataProcess = {
33873387

3388-
initFailFlags(api) { // escape/merge URLs w/ fail flags
3389-
const { respPatterns = {}, endpoint = apis[api].endpoints.completions, expectedOrigin } = apis[api],
3390-
escapedAPIurls = [endpoint, expectedOrigin.url].map(url => url.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'))
3391-
return new RegExp([respPatterns.fail, ...escapedAPIurls].filter(Boolean).join('|'))
3392-
},
3388+
initFailFlags(api) { return apis[api].respPatterns?.fail ? new RegExp(apis[api].respPatterns.fail) : null },
33933389

33943390
stream(resp, { caller, callerAPI }) {
33953391
if (config.streamingDisabled || !config.proxyAPIenabled) return
33963392
log.caller = `get.${caller.name}() » dataProcess.stream()`
3397-
const failFlagsAndURLs = this.initFailFlags(callerAPI),
3398-
reader = resp.response.getReader()
3393+
const reader = resp.response.getReader(), reFailFlags = this.initFailFlags(callerAPI)
33993394
let textToShow = '', isDone = false
34003395
reader.read().then(chunk => handleChunk(chunk, callerAPI))
34013396
.catch(err => log.error('Error processing stream', err.message))
@@ -3433,7 +3428,7 @@
34333428

34343429
// Show accumulated reply chunks
34353430
try {
3436-
const failMatch = failFlagsAndURLs.exec(textToShow)
3431+
const failMatch = reFailFlags?.exec(textToShow)
34373432
if (failMatch) {
34383433
log.debug('Text to show', textToShow) ; log.error('Fail flag detected', `'${failMatch[0]}'`)
34393434
if (env.browser.isChromium) clearTimeout(this.timeout) // skip handleProcessCompletion()
@@ -3471,7 +3466,7 @@
34713466
if (caller == get.reply && config.proxyAPIenabled && !config.streamingDisabled
34723467
|| caller.status == 'done') return
34733468
log.caller = `get.${caller.name}() » dataProcess.text()`
3474-
const failFlagsAndURLs = this.initFailFlags(callerAPI) ; let textToShow = ''
3469+
const reFailFlags = this.initFailFlags(callerAPI) ; let textToShow = ''
34753470
if (resp.status != 200) {
34763471
log.error('Response status', resp.status)
34773472
log.info('Response text', resp.response || resp.responseText)
@@ -3482,7 +3477,7 @@
34823477
: ['openAInotWorking', 'suggestProxy'] )
34833478
else api.tryNew(caller)
34843479
} else if (callerAPI == 'OpenAI' && resp.response) { // show response or return RQs from OpenAI
3485-
const failMatch = failFlagsAndURLs.exec(resp.response)
3480+
const failMatch = reFailFlags?.exec(resp.response)
34863481
if (failMatch) { // suggest proxy or try diff API
34873482
log.debug('Response text', resp.response) ; log.error('Fail flag detected', `'${failMatch[0]}'`)
34883483
if (caller == get.reply) appAlert('openAInotWorking', 'suggestProxy')
@@ -3520,7 +3515,7 @@
35203515
function handleProcessCompletion() {
35213516
if (caller.status != 'done') {
35223517
log.debug('Text to show', textToShow)
3523-
const failMatch = failFlagsAndURLs.exec(textToShow)
3518+
const failMatch = reFailFlags?.exec(textToShow)
35243519
if (!textToShow || failMatch) {
35253520
if (failMatch) log.error('Fail flag detected', `'${failMatch[0]}'`)
35263521
api.tryNew(caller)

duckduckgpt/greasemonkey/duckduckgpt.user.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
// @description:zu Yengeza izimpendulo ze-AI ku-DuckDuckGo (inikwa amandla yi-GPT-4o!)
149149
// @author KudoAI
150150
// @namespace https://kudoai.com
151-
// @version 2025.1.26.8
151+
// @version 2025.1.26.9
152152
// @license MIT
153153
// @icon https://assets.ddgpt.com/images/icons/duckduckgpt/icon48.png?v=06af076
154154
// @icon64 https://assets.ddgpt.com/images/icons/duckduckgpt/icon64.png?v=06af076
@@ -3269,17 +3269,12 @@
32693269

32703270
const dataProcess = {
32713271

3272-
initFailFlags(api) { // escape/merge URLs w/ fail flags
3273-
const { respPatterns = {}, endpoint = apis[api].endpoints.completions, expectedOrigin } = apis[api],
3274-
escapedAPIurls = [endpoint, expectedOrigin.url].map(url => url.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'))
3275-
return new RegExp([respPatterns.fail, ...escapedAPIurls].filter(Boolean).join('|'))
3276-
},
3272+
initFailFlags(api) { return apis[api].respPatterns?.fail ? new RegExp(apis[api].respPatterns.fail) : null },
32773273

32783274
stream(resp, { caller, callerAPI }) {
32793275
if (config.streamingDisabled || !config.proxyAPIenabled) return
32803276
log.caller = `get.${caller.name}() » dataProcess.stream()`
3281-
const failFlagsAndURLs = this.initFailFlags(callerAPI),
3282-
reader = resp.response.getReader()
3277+
const reader = resp.response.getReader(), reFailFlags = this.initFailFlags(callerAPI)
32833278
let textToShow = '', isDone = false
32843279
reader.read().then(chunk => handleChunk(chunk, callerAPI))
32853280
.catch(err => log.error('Error processing stream', err.message))
@@ -3317,7 +3312,7 @@
33173312

33183313
// Show accumulated reply chunks
33193314
try {
3320-
const failMatch = failFlagsAndURLs.exec(textToShow)
3315+
const failMatch = reFailFlags?.exec(textToShow)
33213316
if (failMatch) {
33223317
log.debug('Text to show', textToShow) ; log.error('Fail flag detected', `'${failMatch[0]}'`)
33233318
if (env.browser.isChromium) clearTimeout(this.timeout) // skip handleProcessCompletion()
@@ -3355,7 +3350,7 @@
33553350
if (caller == get.reply && config.proxyAPIenabled && !config.streamingDisabled
33563351
|| caller.status == 'done') return
33573352
log.caller = `get.${caller.name}() » dataProcess.text()`
3358-
const failFlagsAndURLs = this.initFailFlags(callerAPI) ; let textToShow = ''
3353+
const reFailFlags = this.initFailFlags(callerAPI) ; let textToShow = ''
33593354
if (resp.status != 200) {
33603355
log.error('Response status', resp.status)
33613356
log.info('Response text', resp.response || resp.responseText)
@@ -3366,7 +3361,7 @@
33663361
: ['openAInotWorking', 'suggestProxy'] )
33673362
else api.tryNew(caller)
33683363
} else if (callerAPI == 'OpenAI' && resp.response) { // show response or return RQs from OpenAI
3369-
const failMatch = failFlagsAndURLs.exec(resp.response)
3364+
const failMatch = reFailFlags?.exec(resp.response)
33703365
if (failMatch) { // suggest proxy or try diff API
33713366
log.debug('Response text', resp.response) ; log.error('Fail flag detected', `'${failMatch[0]}'`)
33723367
if (caller == get.reply) appAlert('openAInotWorking', 'suggestProxy')
@@ -3404,7 +3399,7 @@
34043399
function handleProcessCompletion() {
34053400
if (caller.status != 'done') {
34063401
log.debug('Text to show', textToShow)
3407-
const failMatch = failFlagsAndURLs.exec(textToShow)
3402+
const failMatch = reFailFlags?.exec(textToShow)
34083403
if (!textToShow || failMatch) {
34093404
if (failMatch) log.error('Fail flag detected', `'${failMatch[0]}'`)
34103405
api.tryNew(caller)

googlegpt/greasemonkey/googlegpt.user.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@
149149
// @description:zu Yengeza izimpendulo ze-AI ku-Google Search (inikwa amandla yi-Google Gemma + GPT-4o!)
150150
// @author KudoAI
151151
// @namespace https://kudoai.com
152-
// @version 2025.1.26.8
152+
// @version 2025.1.26.9
153153
// @license MIT
154154
// @icon https://assets.googlegpt.io/images/icons/googlegpt/black/icon48.png?v=59409b2
155155
// @icon64 https://assets.googlegpt.io/images/icons/googlegpt/black/icon64.png?v=59409b2
@@ -3566,17 +3566,12 @@
35663566

35673567
const dataProcess = {
35683568

3569-
initFailFlags(api) { // escape/merge URLs w/ fail flags
3570-
const { respPatterns = {}, endpoint = apis[api].endpoints.completions, expectedOrigin } = apis[api],
3571-
escapedAPIurls = [endpoint, expectedOrigin.url].map(url => url.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'))
3572-
return new RegExp([respPatterns.fail, ...escapedAPIurls].filter(Boolean).join('|'))
3573-
},
3569+
initFailFlags(api) { return apis[api].respPatterns?.fail ? new RegExp(apis[api].respPatterns.fail) : null },
35743570

35753571
stream(resp, { caller, callerAPI }) {
35763572
if (config.streamingDisabled || !config.proxyAPIenabled) return
35773573
log.caller = `get.${caller.name}() » dataProcess.stream()`
3578-
const failFlagsAndURLs = this.initFailFlags(callerAPI),
3579-
reader = resp.response.getReader()
3574+
const reader = resp.response.getReader(), reFailFlags = this.initFailFlags(callerAPI)
35803575
let textToShow = '', isDone = false
35813576
reader.read().then(chunk => handleChunk(chunk, callerAPI))
35823577
.catch(err => log.error('Error processing stream', err.message))
@@ -3614,7 +3609,7 @@
36143609

36153610
// Show accumulated reply chunks
36163611
try {
3617-
const failMatch = failFlagsAndURLs.exec(textToShow)
3612+
const failMatch = reFailFlags?.exec(textToShow)
36183613
if (failMatch) {
36193614
log.debug('Text to show', textToShow) ; log.error('Fail flag detected', `'${failMatch[0]}'`)
36203615
if (env.browser.isChromium) clearTimeout(this.timeout) // skip handleProcessCompletion()
@@ -3652,7 +3647,7 @@
36523647
if (caller == get.reply && config.proxyAPIenabled && !config.streamingDisabled
36533648
|| caller.status == 'done') return
36543649
log.caller = `get.${caller.name}() » dataProcess.text()`
3655-
const failFlagsAndURLs = this.initFailFlags(callerAPI) ; let textToShow = ''
3650+
const reFailFlags = this.initFailFlags(callerAPI) ; let textToShow = ''
36563651
if (resp.status != 200) {
36573652
log.error('Response status', resp.status)
36583653
log.info('Response text', resp.response || resp.responseText)
@@ -3663,7 +3658,7 @@
36633658
: ['openAInotWorking', 'suggestProxy'] )
36643659
else api.tryNew(caller)
36653660
} else if (callerAPI == 'OpenAI' && resp.response) { // show response or return RQs from OpenAI
3666-
const failMatch = failFlagsAndURLs.exec(resp.response)
3661+
const failMatch = reFailFlags?.exec(resp.response)
36673662
if (failMatch) { // suggest proxy or try diff API
36683663
log.debug('Response text', resp.response) ; log.error('Fail flag detected', `'${failMatch[0]}'`)
36693664
if (caller == get.reply) appAlert('openAInotWorking', 'suggestProxy')
@@ -3701,7 +3696,7 @@
37013696
function handleProcessCompletion() {
37023697
if (caller.status != 'done') {
37033698
log.debug('Text to show', textToShow)
3704-
const failMatch = failFlagsAndURLs.exec(textToShow)
3699+
const failMatch = reFailFlags?.exec(textToShow)
37053700
if (!textToShow || failMatch) {
37063701
if (failMatch) log.error('Fail flag detected', `'${failMatch[0]}'`)
37073702
api.tryNew(caller)

0 commit comments

Comments
 (0)