qwenproxy-cli 1.4.3 → 1.4.8
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/dist/clean-cache.js +205 -75
- package/dist/delete-chats.js +397 -93
- package/dist/index.js +399 -95
- package/dist/login.js +345 -83
- package/dist/reset-cooldowns.js +205 -75
- package/package.json +1 -1
- package/src/core/database.ts +10 -5
- package/src/core/version.ts +1 -1
- package/src/routes/chat/retry-policy.ts +4 -3
- package/src/services/playwright.ts +408 -83
- package/src/services/qwen-chat-pool.ts +9 -0
- package/src/services/qwen.ts +43 -10
package/src/services/qwen.ts
CHANGED
|
@@ -929,16 +929,28 @@ export async function requestQwenTextInBrowser(
|
|
|
929
929
|
// If 401 Unauthorized in browser, try silent in-page token refresh before giving up
|
|
930
930
|
if (response.status === 401) {
|
|
931
931
|
try {
|
|
932
|
-
const
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
932
|
+
const rTok = localStorage.getItem("refresh_token");
|
|
933
|
+
if (rTok) {
|
|
934
|
+
const refreshRes = await fetch("https://auth.qwen.ai/api/v2/auths/refresh", {
|
|
935
|
+
method: "GET",
|
|
936
|
+
credentials: "include",
|
|
937
|
+
headers: {
|
|
938
|
+
accept: "application/json, text/plain, */*",
|
|
939
|
+
source: "web",
|
|
940
|
+
version: "0.3.11",
|
|
941
|
+
"x-request-origin": "https://chat.qwen.ai",
|
|
942
|
+
timezone: new Date().toString().split(" (")[0],
|
|
943
|
+
authorization: `Bearer ${rTok}`,
|
|
944
|
+
},
|
|
945
|
+
signal: AbortSignal.timeout(5000),
|
|
946
|
+
});
|
|
938
947
|
const refreshJson: any = await refreshRes.json().catch(() => null);
|
|
939
|
-
|
|
940
|
-
|
|
948
|
+
const freshTok = refreshJson?.data?.access_token || refreshJson?.data?.token;
|
|
949
|
+
const nextRTok = refreshJson?.data?.refresh_token;
|
|
950
|
+
if (refreshJson?.success === true && freshTok) {
|
|
941
951
|
localStorage.setItem("token", freshTok);
|
|
952
|
+
localStorage.setItem("access_token", freshTok);
|
|
953
|
+
if (nextRTok) localStorage.setItem("refresh_token", nextRTok);
|
|
942
954
|
document.cookie = `token=${encodeURIComponent(freshTok)}; path=/; domain=.qwen.ai; max-age=31536000`;
|
|
943
955
|
if (headers["authorization"] || headers["Authorization"]) {
|
|
944
956
|
headers["authorization"] = `Bearer ${freshTok}`;
|
|
@@ -979,7 +991,7 @@ export async function requestQwenTextInBrowser(
|
|
|
979
991
|
// Settings and personalization requests run as same-origin in-browser fetch
|
|
980
992
|
// with appropriate Referer, keeping the page on the stable chat UI without
|
|
981
993
|
// expensive page.goto navigations that can time out under load.
|
|
982
|
-
|
|
994
|
+
let response = await withQwenBrowserPage<BrowserTextResponse>(
|
|
983
995
|
accountId,
|
|
984
996
|
evaluateRequest,
|
|
985
997
|
undefined,
|
|
@@ -987,6 +999,23 @@ export async function requestQwenTextInBrowser(
|
|
|
987
999
|
recoverOnTimeout,
|
|
988
1000
|
);
|
|
989
1001
|
|
|
1002
|
+
// If evaluateRequest still received 401, trigger outer token refresh and retry once
|
|
1003
|
+
if (response.status === 401 && accountId) {
|
|
1004
|
+
try {
|
|
1005
|
+
const { refreshAccountToken } = await import("./playwright.ts");
|
|
1006
|
+
const refreshed = await refreshAccountToken(accountId);
|
|
1007
|
+
if (refreshed.success) {
|
|
1008
|
+
response = await withQwenBrowserPage<BrowserTextResponse>(
|
|
1009
|
+
accountId,
|
|
1010
|
+
evaluateRequest,
|
|
1011
|
+
undefined,
|
|
1012
|
+
options.timeoutMs,
|
|
1013
|
+
recoverOnTimeout,
|
|
1014
|
+
);
|
|
1015
|
+
}
|
|
1016
|
+
} catch {}
|
|
1017
|
+
}
|
|
1018
|
+
|
|
990
1019
|
return new Response(response.raw, {
|
|
991
1020
|
status: response.status,
|
|
992
1021
|
headers: response.contentType
|
|
@@ -1714,7 +1743,11 @@ export async function syncQwenRequestPersonalization(
|
|
|
1714
1743
|
);
|
|
1715
1744
|
try {
|
|
1716
1745
|
currentSettings = null;
|
|
1717
|
-
const {
|
|
1746
|
+
const { refreshAccountToken } = await import("./playwright.ts");
|
|
1747
|
+
if (accountId) {
|
|
1748
|
+
await refreshAccountToken(accountId);
|
|
1749
|
+
}
|
|
1750
|
+
const { headers: freshHeaders } = await getQwenHeaders(false, accountId);
|
|
1718
1751
|
requestHeaders = buildCapturedQwenHeaders(freshHeaders, {
|
|
1719
1752
|
referer: qwenUrl("/settings/personalization"),
|
|
1720
1753
|
});
|