qwenproxy-cli 1.0.0 → 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.
Files changed (109) hide show
  1. package/LICENSE +14 -14
  2. package/README.md +906 -906
  3. package/bin/qwenproxy.js +5 -1
  4. package/package.json +77 -78
  5. package/src/api/error-classifier.ts +159 -159
  6. package/src/api/error-helpers.ts +118 -118
  7. package/src/api/models.ts +261 -261
  8. package/src/api/server.ts +860 -859
  9. package/src/cache/memory-cache.ts +385 -385
  10. package/src/clean-cache.ts +204 -204
  11. package/src/core/account-concurrency.ts +671 -671
  12. package/src/core/account-manager.ts +301 -297
  13. package/src/core/account-priority.ts +163 -163
  14. package/src/core/accounts.ts +186 -186
  15. package/src/core/config.ts +383 -383
  16. package/src/core/crypto-utils.ts +79 -79
  17. package/src/core/database.ts +276 -276
  18. package/src/core/errors.ts +118 -118
  19. package/src/core/logger.ts +269 -269
  20. package/src/core/memory-usage.ts +84 -84
  21. package/src/core/metrics.ts +291 -291
  22. package/src/core/model-alias.ts +77 -77
  23. package/src/core/model-registry.ts +544 -544
  24. package/src/core/mutex.ts +119 -119
  25. package/src/core/paths.ts +199 -199
  26. package/src/core/prompt-limits.ts +214 -214
  27. package/src/core/reasoning-effort.ts +102 -102
  28. package/src/core/stream-registry.ts +96 -96
  29. package/src/core/waf-isolation.ts +117 -117
  30. package/src/core/watchdog.ts +195 -195
  31. package/src/delete-chats.ts +23 -23
  32. package/src/index.ts +65 -64
  33. package/src/login.ts +147 -147
  34. package/src/reset-cooldowns.ts +11 -11
  35. package/src/routes/anthropic/index.ts +355 -355
  36. package/src/routes/anthropic/translate.ts +522 -522
  37. package/src/routes/anthropic/types.ts +154 -154
  38. package/src/routes/anthropic/validation.ts +144 -144
  39. package/src/routes/chat/account.ts +1817 -1817
  40. package/src/routes/chat/context.ts +241 -241
  41. package/src/routes/chat/errors.ts +85 -85
  42. package/src/routes/chat/helpers.ts +268 -268
  43. package/src/routes/chat/index.ts +618 -618
  44. package/src/routes/chat/media.ts +285 -285
  45. package/src/routes/chat/retry-policy.ts +754 -754
  46. package/src/routes/chat/stop.ts +98 -98
  47. package/src/routes/chat/streaming.ts +2710 -2710
  48. package/src/routes/chat/validation.ts +526 -526
  49. package/src/routes/chat.ts +2 -2
  50. package/src/routes/completions.ts +290 -290
  51. package/src/routes/images.ts +139 -139
  52. package/src/routes/responses/adapter.ts +503 -503
  53. package/src/routes/responses/index.ts +405 -405
  54. package/src/routes/responses/state.ts +230 -230
  55. package/src/routes/responses/streaming.ts +528 -528
  56. package/src/routes/responses/types.ts +285 -285
  57. package/src/routes/responses/validation.ts +202 -202
  58. package/src/routes/upload.ts +731 -731
  59. package/src/routes/videos.ts +214 -214
  60. package/src/services/auth-playwright.ts +173 -173
  61. package/src/services/captcha-coordinator.ts +161 -161
  62. package/src/services/captcha-solver.ts +553 -553
  63. package/src/services/chat-cleanup.ts +80 -80
  64. package/src/services/context-meter.ts +317 -317
  65. package/src/services/fingerprint.ts +242 -242
  66. package/src/services/human-behavior.ts +173 -173
  67. package/src/services/media-generation.ts +1748 -1748
  68. package/src/services/playwright.ts +2878 -2800
  69. package/src/services/qwen-chat-pool.ts +345 -345
  70. package/src/services/qwen-errors.ts +133 -133
  71. package/src/services/qwen-headers.ts +79 -79
  72. package/src/services/qwen-thread-state.ts +393 -393
  73. package/src/services/qwen-url.ts +19 -19
  74. package/src/services/qwen.ts +3126 -3126
  75. package/src/services/session-keeper.ts +88 -88
  76. package/src/services/token-estimation-metrics.ts +118 -118
  77. package/src/sync/claude-code.ts +75 -75
  78. package/src/sync/codex.ts +123 -123
  79. package/src/sync/index.ts +362 -362
  80. package/src/sync/omp.ts +105 -105
  81. package/src/sync/opencode.ts +214 -214
  82. package/src/sync/types.ts +53 -53
  83. package/src/sync/utils.ts +27 -27
  84. package/src/sync-clients.ts +189 -189
  85. package/src/tools/instructions.ts +137 -137
  86. package/src/tools/manifest.ts +81 -81
  87. package/src/tools/parser.ts +2989 -2989
  88. package/src/tools/toolcall-tags.ts +142 -142
  89. package/src/tui/app.ts +259 -264
  90. package/src/tui/index.ts +61 -61
  91. package/src/tui/markdown.ts +258 -258
  92. package/src/tui/proxy-client.ts +331 -326
  93. package/src/tui/screen.ts +294 -278
  94. package/src/tui/server-manager.ts +270 -270
  95. package/src/tui/theme.ts +432 -432
  96. package/src/tui/types.ts +33 -33
  97. package/src/tui/views/accounts-view.ts +656 -656
  98. package/src/tui/views/chat-view.ts +1018 -823
  99. package/src/tui/views/logs-view.ts +479 -413
  100. package/src/tui/views/status-view.ts +204 -204
  101. package/src/tui/views/storage-view.ts +304 -291
  102. package/src/tui/views/sync-view.ts +409 -409
  103. package/src/types/ali-oss.d.ts +32 -32
  104. package/src/update-cli.ts +121 -0
  105. package/src/utils/context-truncation.ts +84 -84
  106. package/src/utils/json.ts +380 -380
  107. package/src/utils/session-id.ts +37 -37
  108. package/src/utils/tool-call-guard.ts +84 -84
  109. package/src/utils/types.ts +109 -109
@@ -1,242 +1,242 @@
1
- function mulberry32(seed: number): () => number {
2
- return () => {
3
- seed |= 0;
4
- seed = (seed + 0x6d2b79f5) | 0;
5
- let t = Math.imul(seed ^ (seed >>> 15), 1 | seed);
6
- t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
7
- return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
8
- };
9
- }
10
-
11
- function seedFromString(value: string): number {
12
- let hash = 0;
13
- for (let i = 0; i < value.length; i++) {
14
- hash = ((hash << 5) - hash + value.charCodeAt(i)) | 0;
15
- }
16
- return hash >>> 0;
17
- }
18
-
19
- function pick<T>(rng: () => number, values: readonly T[]): T {
20
- return values[Math.floor(rng() * values.length)];
21
- }
22
-
23
- function randInt(rng: () => number, min: number, max: number): number {
24
- return Math.floor(rng() * (max - min + 1)) + min;
25
- }
26
-
27
- const CHROME_MAJOR = 149;
28
-
29
- const VIEWPORTS = [
30
- { width: 1366, height: 768 },
31
- { width: 1440, height: 900 },
32
- { width: 1536, height: 864 },
33
- { width: 1600, height: 900 },
34
- { width: 1680, height: 1050 },
35
- { width: 1920, height: 1080 },
36
- { width: 1920, height: 1200 },
37
- { width: 1280, height: 720 },
38
- { width: 1280, height: 800 },
39
- { width: 1536, height: 864 },
40
- ] as const;
41
-
42
- const WEBGL_PROFILES = [
43
- {
44
- vendor: "Google Inc. (Intel)",
45
- renderer: "ANGLE (Intel, Intel(R) UHD Graphics 630 Direct3D11 vs_5_0 ps_5_0, D3D11)",
46
- },
47
- {
48
- vendor: "Google Inc. (Intel)",
49
- renderer: "ANGLE (Intel, Intel(R) Iris(R) Xe Graphics Direct3D11 vs_5_0 ps_5_0, D3D11)",
50
- },
51
- {
52
- vendor: "Google Inc. (Intel)",
53
- renderer: "ANGLE (Intel, Intel(R) UHD Graphics 770 Direct3D11 vs_5_0 ps_5_0, D3D11)",
54
- },
55
- {
56
- vendor: "Google Inc. (NVIDIA)",
57
- renderer: "ANGLE (NVIDIA, NVIDIA GeForce RTX 3060 Direct3D11 vs_5_0 ps_5_0, D3D11)",
58
- },
59
- {
60
- vendor: "Google Inc. (NVIDIA)",
61
- renderer: "ANGLE (NVIDIA, NVIDIA GeForce RTX 3070 Direct3D11 vs_5_0 ps_5_0, D3D11)",
62
- },
63
- {
64
- vendor: "Google Inc. (NVIDIA)",
65
- renderer: "ANGLE (NVIDIA, NVIDIA GeForce RTX 3080 Direct3D11 vs_5_0 ps_5_0, D3D11)",
66
- },
67
- {
68
- vendor: "Google Inc. (NVIDIA)",
69
- renderer: "ANGLE (NVIDIA, NVIDIA GeForce RTX 4060 Direct3D11 vs_5_0 ps_5_0, D3D11)",
70
- },
71
- {
72
- vendor: "Google Inc. (NVIDIA)",
73
- renderer: "ANGLE (NVIDIA, NVIDIA GeForce RTX 4070 Direct3D11 vs_5_0 ps_5_0, D3D11)",
74
- },
75
- {
76
- vendor: "Google Inc. (NVIDIA)",
77
- renderer: "ANGLE (NVIDIA, NVIDIA GeForce GTX 1660 SUPER Direct3D11 vs_5_0 ps_5_0, D3D11)",
78
- },
79
- {
80
- vendor: "Google Inc. (AMD)",
81
- renderer: "ANGLE (AMD, AMD Radeon RX 6600 Direct3D11 vs_5_0 ps_5_0, D3D11)",
82
- },
83
- {
84
- vendor: "Google Inc. (AMD)",
85
- renderer: "ANGLE (AMD, AMD Radeon RX 7600 Direct3D11 vs_5_0 ps_5_0, D3D11)",
86
- },
87
- {
88
- vendor: "Google Inc. (AMD)",
89
- renderer: "ANGLE (AMD, AMD Radeon RX 580 Direct3D11 vs_5_0 ps_5_0, D3D11)",
90
- },
91
- ] as const;
92
-
93
- const LANGUAGE_PROFILES = [
94
- ["pt-BR", "pt", "en-US", "en"],
95
- ["pt-BR", "pt", "en-US", "en", "es"],
96
- ["pt-BR", "en-US", "en", "pt"],
97
- ["pt-BR", "pt", "en"],
98
- ["pt-BR", "pt;q=0.9", "en-US;q=0.8", "en;q=0.7"],
99
- ] as const;
100
-
101
- const HARDWARE_CONCURRENCIES = [4, 6, 8, 8, 8, 12, 16, 16, 24, 32] as const;
102
- const DEVICE_MEMORIES = [4, 8, 8, 8, 16, 16, 32] as const;
103
-
104
- const PLATFORM_VERSIONS = [
105
- { platform: "Windows", platformVersion: "14.0.0", major: "10" },
106
- { platform: "Windows", platformVersion: "15.0.0", major: "11" },
107
- { platform: "Windows", platformVersion: "14.0.0", major: "10" },
108
- { platform: "Windows", platformVersion: "15.0.0", major: "11" },
109
- ] as const;
110
-
111
- const NOT_A_BRAND_VARIANTS = [
112
- { brand: "Not/A)Brand", version: "99" },
113
- { brand: "Not)A_Brand", version: "99" },
114
- { brand: "Not/A)Brand", version: "8" },
115
- { brand: "Not?A_Brand", version: "24" },
116
- { brand: "Not/A)Brand", version: "99" },
117
- ] as const;
118
-
119
- export interface FingerprintProfile {
120
- accountId: string;
121
- seed: number;
122
- userAgent: string;
123
- appVersion: string;
124
- chromeMajor: number;
125
- chromeVersion: string;
126
- brands: Array<{ brand: string; version: string }>;
127
- fullVersionList: Array<{ brand: string; version: string }>;
128
- secChUa: string;
129
- platform: string;
130
- platformVersion: string;
131
- architecture: string;
132
- bitness: string;
133
- languages: string[];
134
- locale: string;
135
- timezoneId: string;
136
- viewport: { width: number; height: number };
137
- hardwareConcurrency: number;
138
- deviceMemory: number;
139
- webglVendor: string;
140
- webglRenderer: string;
141
- colorDepth: number;
142
- pixelDepth: number;
143
- canvasNoiseSeed: number;
144
- audioNoiseSeed: number;
145
- webglNoiseSeed: number;
146
- outerWidthOffset: number;
147
- outerHeightOffset: number;
148
- }
149
-
150
- const profileCache = new Map<string, FingerprintProfile>();
151
-
152
- // Per-account rotation salt. The seed is normally derived ONLY from the
153
- // accountId, so after a hard WAF block (captcha/TMD) the account would return
154
- // from its cooldown on the SAME device identity the WAF already flagged — the
155
- // flag re-propagates immediately. Bumping the salt (and closing the browser
156
- // context) makes the next profile a fresh device identity.
157
- const rotationSalts = new Map<string, number>();
158
-
159
- export function rotateFingerprintSeed(accountId: string): number {
160
- const next = (rotationSalts.get(accountId) ?? 0) + 1;
161
- rotationSalts.set(accountId, next);
162
- profileCache.delete(accountId);
163
- return next;
164
- }
165
-
166
- export function getFingerprintRotation(accountId: string): number {
167
- return rotationSalts.get(accountId) ?? 0;
168
- }
169
-
170
- export function getFingerprintProfile(accountId: string): FingerprintProfile {
171
- const cached = profileCache.get(accountId);
172
- if (cached) return cached;
173
-
174
- const salt = rotationSalts.get(accountId) ?? 0;
175
- const seed = seedFromString(salt === 0 ? accountId : `${accountId}#r${salt}`);
176
- const rng = mulberry32(seed);
177
- const viewport = pick(rng, VIEWPORTS);
178
- const webgl = pick(rng, WEBGL_PROFILES);
179
- const languages = [...pick(rng, LANGUAGE_PROFILES)];
180
- const hardwareConcurrency = pick(rng, HARDWARE_CONCURRENCIES);
181
- const deviceMemory = pick(rng, DEVICE_MEMORIES);
182
- const platformInfo = pick(rng, PLATFORM_VERSIONS);
183
- const notABrand = pick(rng, NOT_A_BRAND_VARIANTS);
184
-
185
- const build = randInt(rng, 7300, 7600);
186
- const patch = randInt(rng, 0, 160);
187
- const chromeVersion = `${CHROME_MAJOR}.0.${build}.${patch}`;
188
-
189
- const brands = [
190
- { brand: notABrand.brand, version: notABrand.version },
191
- { brand: "Google Chrome", version: String(CHROME_MAJOR) },
192
- { brand: "Chromium", version: String(CHROME_MAJOR) },
193
- ];
194
- const fullVersionList = [
195
- { brand: notABrand.brand, version: chromeVersion },
196
- { brand: "Google Chrome", version: chromeVersion },
197
- { brand: "Chromium", version: chromeVersion },
198
- ];
199
- const secChUa = brands
200
- .map((brand) => `"${brand.brand}";v="${brand.version}"`)
201
- .join(", ");
202
- const userAgent = `Mozilla/5.0 (Windows NT ${platformInfo.major}.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${chromeVersion} Safari/537.36`;
203
-
204
- const profile: FingerprintProfile = {
205
- accountId,
206
- seed,
207
- userAgent,
208
- appVersion: userAgent.replace("Mozilla/", ""),
209
- chromeMajor: CHROME_MAJOR,
210
- chromeVersion,
211
- brands,
212
- fullVersionList,
213
- secChUa,
214
- platform: "Win32",
215
- platformVersion: platformInfo.platformVersion,
216
- architecture: "x86",
217
- bitness: "64",
218
- languages,
219
- locale: languages[0].split(";")[0],
220
- timezoneId: "America/Sao_Paulo",
221
- viewport,
222
- hardwareConcurrency,
223
- deviceMemory,
224
- webglVendor: webgl.vendor,
225
- webglRenderer: webgl.renderer,
226
- colorDepth: 24,
227
- pixelDepth: 24,
228
- canvasNoiseSeed: randInt(rng, 1, 2147483647),
229
- audioNoiseSeed: randInt(rng, 1, 2147483647),
230
- webglNoiseSeed: randInt(rng, 1, 2147483647),
231
- outerWidthOffset: randInt(rng, 0, 20),
232
- outerHeightOffset: randInt(rng, 75, 95),
233
- };
234
-
235
- profileCache.set(accountId, profile);
236
- return profile;
237
- }
238
-
239
- export function clearFingerprintCache(accountId?: string): void {
240
- if (accountId) profileCache.delete(accountId);
241
- else profileCache.clear();
242
- }
1
+ function mulberry32(seed: number): () => number {
2
+ return () => {
3
+ seed |= 0;
4
+ seed = (seed + 0x6d2b79f5) | 0;
5
+ let t = Math.imul(seed ^ (seed >>> 15), 1 | seed);
6
+ t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
7
+ return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
8
+ };
9
+ }
10
+
11
+ function seedFromString(value: string): number {
12
+ let hash = 0;
13
+ for (let i = 0; i < value.length; i++) {
14
+ hash = ((hash << 5) - hash + value.charCodeAt(i)) | 0;
15
+ }
16
+ return hash >>> 0;
17
+ }
18
+
19
+ function pick<T>(rng: () => number, values: readonly T[]): T {
20
+ return values[Math.floor(rng() * values.length)];
21
+ }
22
+
23
+ function randInt(rng: () => number, min: number, max: number): number {
24
+ return Math.floor(rng() * (max - min + 1)) + min;
25
+ }
26
+
27
+ const CHROME_MAJOR = 149;
28
+
29
+ const VIEWPORTS = [
30
+ { width: 1366, height: 768 },
31
+ { width: 1440, height: 900 },
32
+ { width: 1536, height: 864 },
33
+ { width: 1600, height: 900 },
34
+ { width: 1680, height: 1050 },
35
+ { width: 1920, height: 1080 },
36
+ { width: 1920, height: 1200 },
37
+ { width: 1280, height: 720 },
38
+ { width: 1280, height: 800 },
39
+ { width: 1536, height: 864 },
40
+ ] as const;
41
+
42
+ const WEBGL_PROFILES = [
43
+ {
44
+ vendor: "Google Inc. (Intel)",
45
+ renderer: "ANGLE (Intel, Intel(R) UHD Graphics 630 Direct3D11 vs_5_0 ps_5_0, D3D11)",
46
+ },
47
+ {
48
+ vendor: "Google Inc. (Intel)",
49
+ renderer: "ANGLE (Intel, Intel(R) Iris(R) Xe Graphics Direct3D11 vs_5_0 ps_5_0, D3D11)",
50
+ },
51
+ {
52
+ vendor: "Google Inc. (Intel)",
53
+ renderer: "ANGLE (Intel, Intel(R) UHD Graphics 770 Direct3D11 vs_5_0 ps_5_0, D3D11)",
54
+ },
55
+ {
56
+ vendor: "Google Inc. (NVIDIA)",
57
+ renderer: "ANGLE (NVIDIA, NVIDIA GeForce RTX 3060 Direct3D11 vs_5_0 ps_5_0, D3D11)",
58
+ },
59
+ {
60
+ vendor: "Google Inc. (NVIDIA)",
61
+ renderer: "ANGLE (NVIDIA, NVIDIA GeForce RTX 3070 Direct3D11 vs_5_0 ps_5_0, D3D11)",
62
+ },
63
+ {
64
+ vendor: "Google Inc. (NVIDIA)",
65
+ renderer: "ANGLE (NVIDIA, NVIDIA GeForce RTX 3080 Direct3D11 vs_5_0 ps_5_0, D3D11)",
66
+ },
67
+ {
68
+ vendor: "Google Inc. (NVIDIA)",
69
+ renderer: "ANGLE (NVIDIA, NVIDIA GeForce RTX 4060 Direct3D11 vs_5_0 ps_5_0, D3D11)",
70
+ },
71
+ {
72
+ vendor: "Google Inc. (NVIDIA)",
73
+ renderer: "ANGLE (NVIDIA, NVIDIA GeForce RTX 4070 Direct3D11 vs_5_0 ps_5_0, D3D11)",
74
+ },
75
+ {
76
+ vendor: "Google Inc. (NVIDIA)",
77
+ renderer: "ANGLE (NVIDIA, NVIDIA GeForce GTX 1660 SUPER Direct3D11 vs_5_0 ps_5_0, D3D11)",
78
+ },
79
+ {
80
+ vendor: "Google Inc. (AMD)",
81
+ renderer: "ANGLE (AMD, AMD Radeon RX 6600 Direct3D11 vs_5_0 ps_5_0, D3D11)",
82
+ },
83
+ {
84
+ vendor: "Google Inc. (AMD)",
85
+ renderer: "ANGLE (AMD, AMD Radeon RX 7600 Direct3D11 vs_5_0 ps_5_0, D3D11)",
86
+ },
87
+ {
88
+ vendor: "Google Inc. (AMD)",
89
+ renderer: "ANGLE (AMD, AMD Radeon RX 580 Direct3D11 vs_5_0 ps_5_0, D3D11)",
90
+ },
91
+ ] as const;
92
+
93
+ const LANGUAGE_PROFILES = [
94
+ ["pt-BR", "pt", "en-US", "en"],
95
+ ["pt-BR", "pt", "en-US", "en", "es"],
96
+ ["pt-BR", "en-US", "en", "pt"],
97
+ ["pt-BR", "pt", "en"],
98
+ ["pt-BR", "pt;q=0.9", "en-US;q=0.8", "en;q=0.7"],
99
+ ] as const;
100
+
101
+ const HARDWARE_CONCURRENCIES = [4, 6, 8, 8, 8, 12, 16, 16, 24, 32] as const;
102
+ const DEVICE_MEMORIES = [4, 8, 8, 8, 16, 16, 32] as const;
103
+
104
+ const PLATFORM_VERSIONS = [
105
+ { platform: "Windows", platformVersion: "14.0.0", major: "10" },
106
+ { platform: "Windows", platformVersion: "15.0.0", major: "11" },
107
+ { platform: "Windows", platformVersion: "14.0.0", major: "10" },
108
+ { platform: "Windows", platformVersion: "15.0.0", major: "11" },
109
+ ] as const;
110
+
111
+ const NOT_A_BRAND_VARIANTS = [
112
+ { brand: "Not/A)Brand", version: "99" },
113
+ { brand: "Not)A_Brand", version: "99" },
114
+ { brand: "Not/A)Brand", version: "8" },
115
+ { brand: "Not?A_Brand", version: "24" },
116
+ { brand: "Not/A)Brand", version: "99" },
117
+ ] as const;
118
+
119
+ export interface FingerprintProfile {
120
+ accountId: string;
121
+ seed: number;
122
+ userAgent: string;
123
+ appVersion: string;
124
+ chromeMajor: number;
125
+ chromeVersion: string;
126
+ brands: Array<{ brand: string; version: string }>;
127
+ fullVersionList: Array<{ brand: string; version: string }>;
128
+ secChUa: string;
129
+ platform: string;
130
+ platformVersion: string;
131
+ architecture: string;
132
+ bitness: string;
133
+ languages: string[];
134
+ locale: string;
135
+ timezoneId: string;
136
+ viewport: { width: number; height: number };
137
+ hardwareConcurrency: number;
138
+ deviceMemory: number;
139
+ webglVendor: string;
140
+ webglRenderer: string;
141
+ colorDepth: number;
142
+ pixelDepth: number;
143
+ canvasNoiseSeed: number;
144
+ audioNoiseSeed: number;
145
+ webglNoiseSeed: number;
146
+ outerWidthOffset: number;
147
+ outerHeightOffset: number;
148
+ }
149
+
150
+ const profileCache = new Map<string, FingerprintProfile>();
151
+
152
+ // Per-account rotation salt. The seed is normally derived ONLY from the
153
+ // accountId, so after a hard WAF block (captcha/TMD) the account would return
154
+ // from its cooldown on the SAME device identity the WAF already flagged — the
155
+ // flag re-propagates immediately. Bumping the salt (and closing the browser
156
+ // context) makes the next profile a fresh device identity.
157
+ const rotationSalts = new Map<string, number>();
158
+
159
+ export function rotateFingerprintSeed(accountId: string): number {
160
+ const next = (rotationSalts.get(accountId) ?? 0) + 1;
161
+ rotationSalts.set(accountId, next);
162
+ profileCache.delete(accountId);
163
+ return next;
164
+ }
165
+
166
+ export function getFingerprintRotation(accountId: string): number {
167
+ return rotationSalts.get(accountId) ?? 0;
168
+ }
169
+
170
+ export function getFingerprintProfile(accountId: string): FingerprintProfile {
171
+ const cached = profileCache.get(accountId);
172
+ if (cached) return cached;
173
+
174
+ const salt = rotationSalts.get(accountId) ?? 0;
175
+ const seed = seedFromString(salt === 0 ? accountId : `${accountId}#r${salt}`);
176
+ const rng = mulberry32(seed);
177
+ const viewport = pick(rng, VIEWPORTS);
178
+ const webgl = pick(rng, WEBGL_PROFILES);
179
+ const languages = [...pick(rng, LANGUAGE_PROFILES)];
180
+ const hardwareConcurrency = pick(rng, HARDWARE_CONCURRENCIES);
181
+ const deviceMemory = pick(rng, DEVICE_MEMORIES);
182
+ const platformInfo = pick(rng, PLATFORM_VERSIONS);
183
+ const notABrand = pick(rng, NOT_A_BRAND_VARIANTS);
184
+
185
+ const build = randInt(rng, 7300, 7600);
186
+ const patch = randInt(rng, 0, 160);
187
+ const chromeVersion = `${CHROME_MAJOR}.0.${build}.${patch}`;
188
+
189
+ const brands = [
190
+ { brand: notABrand.brand, version: notABrand.version },
191
+ { brand: "Google Chrome", version: String(CHROME_MAJOR) },
192
+ { brand: "Chromium", version: String(CHROME_MAJOR) },
193
+ ];
194
+ const fullVersionList = [
195
+ { brand: notABrand.brand, version: chromeVersion },
196
+ { brand: "Google Chrome", version: chromeVersion },
197
+ { brand: "Chromium", version: chromeVersion },
198
+ ];
199
+ const secChUa = brands
200
+ .map((brand) => `"${brand.brand}";v="${brand.version}"`)
201
+ .join(", ");
202
+ const userAgent = `Mozilla/5.0 (Windows NT ${platformInfo.major}.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${chromeVersion} Safari/537.36`;
203
+
204
+ const profile: FingerprintProfile = {
205
+ accountId,
206
+ seed,
207
+ userAgent,
208
+ appVersion: userAgent.replace("Mozilla/", ""),
209
+ chromeMajor: CHROME_MAJOR,
210
+ chromeVersion,
211
+ brands,
212
+ fullVersionList,
213
+ secChUa,
214
+ platform: "Win32",
215
+ platformVersion: platformInfo.platformVersion,
216
+ architecture: "x86",
217
+ bitness: "64",
218
+ languages,
219
+ locale: languages[0].split(";")[0],
220
+ timezoneId: "America/Sao_Paulo",
221
+ viewport,
222
+ hardwareConcurrency,
223
+ deviceMemory,
224
+ webglVendor: webgl.vendor,
225
+ webglRenderer: webgl.renderer,
226
+ colorDepth: 24,
227
+ pixelDepth: 24,
228
+ canvasNoiseSeed: randInt(rng, 1, 2147483647),
229
+ audioNoiseSeed: randInt(rng, 1, 2147483647),
230
+ webglNoiseSeed: randInt(rng, 1, 2147483647),
231
+ outerWidthOffset: randInt(rng, 0, 20),
232
+ outerHeightOffset: randInt(rng, 75, 95),
233
+ };
234
+
235
+ profileCache.set(accountId, profile);
236
+ return profile;
237
+ }
238
+
239
+ export function clearFingerprintCache(accountId?: string): void {
240
+ if (accountId) profileCache.delete(accountId);
241
+ else profileCache.clear();
242
+ }