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.
@@ -14,6 +14,25 @@ var __export = (target, all) => {
14
14
  };
15
15
 
16
16
  // src/core/paths.ts
17
+ var paths_exports = {};
18
+ __export(paths_exports, {
19
+ ensureDataDirs: () => ensureDataDirs,
20
+ getAccountPriorityPath: () => getAccountPriorityPath,
21
+ getAccountProfilePath: () => getAccountProfilePath,
22
+ getDataDir: () => getDataDir,
23
+ getDbDir: () => getDbDir,
24
+ getDbPath: () => getDbPath,
25
+ getEncryptionKeyPath: () => getEncryptionKeyPath,
26
+ getEnvFilePath: () => getEnvFilePath,
27
+ getLogsDir: () => getLogsDir,
28
+ getOsGlobalDataDir: () => getOsGlobalDataDir,
29
+ getProfilesDir: () => getProfilesDir,
30
+ getServerLogFilePath: () => getServerLogFilePath,
31
+ getSyncStatePath: () => getSyncStatePath,
32
+ getTuiSettingsPath: () => getTuiSettingsPath,
33
+ isRunningUnderNodeTest: () => isRunningUnderNodeTest,
34
+ resolveDataDir: () => resolveDataDir
35
+ });
17
36
  import fs from "node:fs";
18
37
  import path from "node:path";
19
38
  import os from "node:os";
@@ -78,6 +97,12 @@ function getAccountProfilePath(accountId, customDataDir) {
78
97
  function getAccountPriorityPath(customDataDir) {
79
98
  return path.join(customDataDir || getDataDir(), "account-priority.json");
80
99
  }
100
+ function getSyncStatePath(customDataDir) {
101
+ return path.join(customDataDir || getDataDir(), "sync-state.json");
102
+ }
103
+ function getTuiSettingsPath(customDataDir) {
104
+ return path.join(customDataDir || getDataDir(), "tui-settings.json");
105
+ }
81
106
  function getEnvFilePath(customDataDir) {
82
107
  if (isRunningUnderNodeTest()) {
83
108
  return path.join(customDataDir || getDataDir(), ".env");
@@ -88,6 +113,26 @@ function getEnvFilePath(customDataDir) {
88
113
  }
89
114
  return path.join(customDataDir || getDataDir(), ".env");
90
115
  }
116
+ function getLogsDir(customDataDir) {
117
+ return path.join(customDataDir || getDataDir(), "logs");
118
+ }
119
+ function getServerLogFilePath(customDataDir) {
120
+ return path.join(getLogsDir(customDataDir), "server.log");
121
+ }
122
+ function ensureDataDirs(targetDataDir) {
123
+ const root = targetDataDir || getDataDir();
124
+ const dbDir = getDbDir(root);
125
+ const profilesDir = getProfilesDir(root);
126
+ const logsDir = getLogsDir(root);
127
+ try {
128
+ if (!fs.existsSync(root)) fs.mkdirSync(root, { recursive: true });
129
+ if (!fs.existsSync(dbDir)) fs.mkdirSync(dbDir, { recursive: true });
130
+ if (!fs.existsSync(profilesDir)) fs.mkdirSync(profilesDir, { recursive: true });
131
+ if (!fs.existsSync(logsDir)) fs.mkdirSync(logsDir, { recursive: true });
132
+ } catch (err) {
133
+ console.error(`[Paths] Error ensuring data directories at ${root}:`, err?.message || String(err));
134
+ }
135
+ }
91
136
  var init_paths = __esm({
92
137
  "src/core/paths.ts"() {
93
138
  "use strict";
@@ -781,7 +826,7 @@ function addAccountsBatch(entries) {
781
826
  }
782
827
  return { added, skipped, invalid };
783
828
  }
784
- function addAccount(email, password, id) {
829
+ function addAccount(email, password = "", id) {
785
830
  if (!email || typeof email !== "string" || email.trim().length === 0) {
786
831
  throw new Error("Email is required");
787
832
  }
@@ -2963,6 +3008,10 @@ async function clearVisibleChallenge(page) {
2963
3008
  "button[aria-label*='Close' i]",
2964
3009
  "button[aria-label*='Fechar' i]",
2965
3010
  ".index-module__whats-new-modal-close",
3011
+ ".age-confirmation-modal button",
3012
+ ".age-confirmation-modal .qwen-chat-v2-btn-black",
3013
+ "button:has-text('Continuar')",
3014
+ "button:has-text('Continue')",
2966
3015
  "button:has-text('Cancel')",
2967
3016
  "button:has-text('Cancelar')",
2968
3017
  "button:has-text('I understand')",
@@ -4466,7 +4515,24 @@ async function refreshAccountToken(accountId) {
4466
4515
  return { success: false, error: "Could not refresh or re-authenticate token" };
4467
4516
  }
4468
4517
  async function captureQwenHeaders(accountId, pageOverride, timeoutMs = config.timeouts.headers, triggerGraceMs = HEADER_CAPTURE_TRIGGER_GRACE_MS) {
4469
- const page = pageOverride ?? accountPages.get(accountId);
4518
+ let page = pageOverride ?? accountPages.get(accountId);
4519
+ if (!page || page.isClosed()) {
4520
+ const { isRunningUnderNodeTest: isRunningUnderNodeTest3 } = await Promise.resolve().then(() => (init_paths(), paths_exports));
4521
+ if (!isRunningUnderNodeTest3()) {
4522
+ const { getAccountCredentials: getAccountCredentials2 } = await Promise.resolve().then(() => (init_accounts(), accounts_exports));
4523
+ const creds = getAccountCredentials2(accountId);
4524
+ if (creds) {
4525
+ await initPlaywrightForAccount(
4526
+ creds,
4527
+ config.playwright.headless,
4528
+ config.playwright.browser,
4529
+ { skipHeaderCapture: true }
4530
+ ).catch(() => {
4531
+ });
4532
+ page = accountPages.get(accountId);
4533
+ }
4534
+ }
4535
+ }
4470
4536
  if (!page || page.isClosed()) {
4471
4537
  throw new Error(`Playwright page unavailable for header capture: ${accountId}`);
4472
4538
  }
@@ -5167,8 +5233,10 @@ async function evictIdlePlaywrightContextsToLimit() {
5167
5233
  if (accountPages.size <= max) return 0;
5168
5234
  const candidates = priorityOrderForEviction(
5169
5235
  Array.from(accountPages.keys()).filter((accountId) => {
5236
+ if (isAccountServingStream(accountId)) return false;
5237
+ if (isAccountRecentlyActive(accountId, 3e4)) return false;
5170
5238
  const mutex = accountMutexes.get(accountId);
5171
- return mutex?.isIdle() && !isAccountServingStream(accountId);
5239
+ return mutex?.isIdle();
5172
5240
  })
5173
5241
  ).map((accountId) => ({
5174
5242
  accountId,
@@ -5281,6 +5349,10 @@ async function closePlaywrightForAccount(accountId) {
5281
5349
  release();
5282
5350
  }
5283
5351
  }
5352
+ function isAccountRecentlyActive(accountId, maxIdleMs = 3e5) {
5353
+ const last = lastAccountActivity.get(accountId) ?? 0;
5354
+ return last > 0 && Date.now() - last < maxIdleMs;
5355
+ }
5284
5356
  var requireLocal, contextInitHooks, ACCOUNT_MUTEX_MAX_HOLD_MS, accountMutexes, accountContexts, accountPages, inFlightAccountInits, headerCaches, HEADER_CACHE_TTL, COOKIE_CACHE_TTL, cookieCaches, lastAccountActivity, lastKeepAliveNavigation, lastProactiveTokenRefresh, profileResetQueue, profileResetChain, closingAllPlaywright, sleep2, HEADER_CAPTURE_SETTLE_MS, PLAYWRIGHT_MUTEX_WAIT_MS, ACCOUNT_PAGE_OPERATION_TIMEOUT_MS, SESSION_PROBE_NAVIGATION_TIMEOUT_MS, HEADER_CAPTURE_TRIGGER_GRACE_MS, FIRST_TRIGGER_GRACE_MS, HEADER_CAPTURE_TRIGGER_ATTEMPTS, CHAT_INPUT_APPEAR_TIMEOUT_MS, CHAT_INPUT_ACTION_TIMEOUT_MS, PROFILE_RESET_TIMEOUT_MS;
5285
5357
  var init_playwright = __esm({
5286
5358
  "src/services/playwright.ts"() {
@@ -5322,8 +5394,8 @@ var init_playwright = __esm({
5322
5394
  PLAYWRIGHT_MUTEX_WAIT_MS = 6e4;
5323
5395
  ACCOUNT_PAGE_OPERATION_TIMEOUT_MS = config.timeouts.page;
5324
5396
  SESSION_PROBE_NAVIGATION_TIMEOUT_MS = 15e3;
5325
- HEADER_CAPTURE_TRIGGER_GRACE_MS = 15e3;
5326
- FIRST_TRIGGER_GRACE_MS = 8e3;
5397
+ HEADER_CAPTURE_TRIGGER_GRACE_MS = 2e4;
5398
+ FIRST_TRIGGER_GRACE_MS = 12e3;
5327
5399
  HEADER_CAPTURE_TRIGGER_ATTEMPTS = 3;
5328
5400
  CHAT_INPUT_APPEAR_TIMEOUT_MS = 15e3;
5329
5401
  CHAT_INPUT_ACTION_TIMEOUT_MS = 1e4;