open-sse 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/services/accountFallback.js +16 -16
- package/utils/bypassHandler.js +8 -0
package/package.json
CHANGED
|
@@ -19,22 +19,7 @@ export function getQuotaCooldown(backoffLevel = 0) {
|
|
|
19
19
|
* @returns {{ shouldFallback: boolean, cooldownMs: number, newBackoffLevel?: number }}
|
|
20
20
|
*/
|
|
21
21
|
export function checkFallbackError(status, errorText, backoffLevel = 0) {
|
|
22
|
-
//
|
|
23
|
-
if (status === 401) {
|
|
24
|
-
return { shouldFallback: true, cooldownMs: COOLDOWN_MS.unauthorized };
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// 402/403 - Payment required / Forbidden (quota/permission)
|
|
28
|
-
if (status === 402 || status === 403) {
|
|
29
|
-
return { shouldFallback: true, cooldownMs: COOLDOWN_MS.paymentRequired };
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// 404 - Model not found (long cooldown)
|
|
33
|
-
if (status === 404) {
|
|
34
|
-
return { shouldFallback: true, cooldownMs: COOLDOWN_MS.notFound };
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// Check error message FIRST (before status codes) for specific patterns
|
|
22
|
+
// Check error message FIRST - specific patterns take priority over status codes
|
|
38
23
|
if (errorText) {
|
|
39
24
|
const lowerError = errorText.toLowerCase();
|
|
40
25
|
|
|
@@ -60,6 +45,21 @@ export function checkFallbackError(status, errorText, backoffLevel = 0) {
|
|
|
60
45
|
}
|
|
61
46
|
}
|
|
62
47
|
|
|
48
|
+
// 401 - Authentication error (token expired/invalid)
|
|
49
|
+
if (status === 401) {
|
|
50
|
+
return { shouldFallback: true, cooldownMs: COOLDOWN_MS.unauthorized };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// 402/403 - Payment required / Forbidden (quota/permission)
|
|
54
|
+
if (status === 402 || status === 403) {
|
|
55
|
+
return { shouldFallback: true, cooldownMs: COOLDOWN_MS.paymentRequired };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// 404 - Model not found (long cooldown)
|
|
59
|
+
if (status === 404) {
|
|
60
|
+
return { shouldFallback: true, cooldownMs: COOLDOWN_MS.notFound };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
63
|
// 429 - Rate limit with exponential backoff
|
|
64
64
|
if (status === 429) {
|
|
65
65
|
const newLevel = Math.min(backoffLevel + 1, BACKOFF_CONFIG.maxLevel);
|
package/utils/bypassHandler.js
CHANGED
|
@@ -32,6 +32,14 @@ export function handleBypassRequest(body, model) {
|
|
|
32
32
|
const firstText = getText(messages[0]?.content);
|
|
33
33
|
if (firstText === "Warmup") shouldBypass = true;
|
|
34
34
|
|
|
35
|
+
// Check count pattern: [{"role":"user","content":"count"}]
|
|
36
|
+
if (!shouldBypass &&
|
|
37
|
+
messages.length === 1 &&
|
|
38
|
+
messages[0]?.role === "user" &&
|
|
39
|
+
firstText === "count") {
|
|
40
|
+
shouldBypass = true;
|
|
41
|
+
}
|
|
42
|
+
|
|
35
43
|
// Check skip patterns
|
|
36
44
|
if (!shouldBypass && SKIP_PATTERNS?.length) {
|
|
37
45
|
const allText = messages.map(m => getText(m.content)).join(" ");
|