qwenproxy-cli 1.6.1 → 1.6.3

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.
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Upstream Qwen overload response detector.
3
+ *
4
+ * When Qwen Web servers are overloaded, the model sometimes generates
5
+ * an in-band plain text apology (HTTP 200 SSE) instead of a structured error:
6
+ * - "Estamos com alta demanda no momento. Tente novamente mais tarde."
7
+ * - "We are experiencing high demand right now."
8
+ * - "The server is busy, please try again later."
9
+ *
10
+ * Detecting these in-band messages before emitting output to the client allows
11
+ * QwenProxy to quarantine the overloaded account and auto-retry on another
12
+ * account transparently, so coding agents (Claude Code, OpenCode, Codex)
13
+ * never receive plain text error apologies as assistant responses.
14
+ */
15
+
16
+ const OVERLOAD_PATTERNS = [
17
+ /high\s+demand/i,
18
+ /problem\s+connecting/i,
19
+ /try\s+again\s+later/i,
20
+ /temporarily\s+unavailable/i,
21
+ /service\s+(is\s+)?overloaded/i,
22
+ /too\s+many\s+requests/i,
23
+ /server\s+is\s+busy/i,
24
+ /experiencing\s+high\s+(traffic|volume|load)/i,
25
+ /unable\s+to\s+connect/i,
26
+ /connection\s+(problem|error|issue)/i,
27
+ /alta\s+demanda/i,
28
+ /problema\s+de\s+conex/i,
29
+ /tente\s+novamente\s+mais\s+tarde/i,
30
+ /servidor\s+ocupado/i,
31
+ /indispon[íi]vel\s+no\s+momento/i,
32
+ /servi[çc]o\s+est[áa]\s+com\s+alta\s+demanda/i,
33
+ ];
34
+
35
+ export const OVERLOAD_COOLDOWN_MS = 5 * 60 * 1000; // 5 minutes
36
+
37
+ export function isOverloadMessage(content: string | null | undefined): boolean {
38
+ if (!content) return false;
39
+ const text = content.trim();
40
+
41
+ // Overload apologies are always short (typically 20-150 characters)
42
+ if (!text || text.length > 500) return false;
43
+
44
+ // Never match legitimate code blocks, markdown structures or tool calls
45
+ if (
46
+ text.includes("```") ||
47
+ text.includes("<tool_call") ||
48
+ text.includes("<qpx_call") ||
49
+ text.includes("</")
50
+ ) {
51
+ return false;
52
+ }
53
+
54
+ return OVERLOAD_PATTERNS.some((pattern) => pattern.test(text));
55
+ }