@pedrofariasx/qwenproxy 1.3.2 → 1.3.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pedrofariasx/qwenproxy",
3
- "version": "1.3.2",
3
+ "version": "1.3.3",
4
4
  "description": "Local OpenAI-compatible proxy API that routes requests to Qwen (chat.qwen.ai) via Playwright browser automation.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -16,9 +16,7 @@ function getClientHintsHeaders(): Record<string, string> {
16
16
  };
17
17
  }
18
18
 
19
- function getRandomDelay(): number {
20
- return 30 + Math.floor(Math.random() * 80);
21
- }
19
+
22
20
 
23
21
  export class RetryableQwenStreamError extends Error {
24
22
  readonly retryAfterMs: number;
@@ -85,7 +83,7 @@ const warmPool: Map<string, WarmPoolEntry[]> = new Map();
85
83
 
86
84
  const refillPromises: Map<string, Promise<void>> = new Map();
87
85
 
88
- const WARM_POOL_SIZE = 5;
86
+ const WARM_POOL_SIZE = 10;
89
87
  const WARM_POOL_TTL_MS = 10 * 60 * 1000;
90
88
 
91
89
  function cleanupStalePool(accountId: string) {
@@ -187,7 +185,7 @@ export async function getWarmedChat(accountId?: string) {
187
185
  }
188
186
  if (pool.length === 0) {
189
187
  // Retry once with short backoff if pool is still empty after first refill attempt
190
- await new Promise(r => setTimeout(r, 1000));
188
+ await new Promise(r => setTimeout(r, 200));
191
189
  if (!refillPromises.has(key)) {
192
190
  refillPromises.set(key, refillPoolForAccount(key).finally(() => refillPromises.delete(key)));
193
191
  }
@@ -489,7 +487,6 @@ export async function createQwenStream(
489
487
  const url = `https://chat.qwen.ai/api/v2/chat/completions?chat_id=${chatId}`;
490
488
  const controller = new AbortController();
491
489
  const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
492
- await sleep(getRandomDelay());
493
490
  const response = await fetch(url, {
494
491
  method: 'POST',
495
492
  headers: {
@@ -517,14 +514,13 @@ export async function createQwenStream(
517
514
  clearTimeout(timeoutId);
518
515
 
519
516
  const responseContentType = response.headers.get('content-type') || '';
520
- if (response.ok && responseContentType.includes('application/json') && response.body) {
521
- const cloned = response.clone();
522
- const peekText = await cloned.text().catch(() => '');
517
+ if (response.ok && !responseContentType.includes('text/event-stream') && response.body) {
518
+ const peekText = await response.clone().text().catch(() => '');
523
519
  if (peekText.includes('FAIL_SYS_USER_VALIDATE') || peekText.includes('_____tmd_____') || peekText.includes('RGV587_ERROR')) {
524
520
  console.warn('[Qwen] TMD challenge detected, refreshing headers and retrying...');
525
521
  try {
526
522
  const { headers: freshHeaders } = await getQwenHeaders(true, accountId);
527
- await sleep(1000 + Math.floor(Math.random() * 2000));
523
+ await sleep(500 + Math.floor(Math.random() * 1000));
528
524
  const retryController = new AbortController();
529
525
  const retryTimeoutId = setTimeout(() => retryController.abort(), timeoutMs);
530
526
  const retryResponse = await fetch(url, {