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.
- package/LICENSE +14 -14
- package/README.md +906 -906
- package/bin/qwenproxy.js +5 -1
- package/package.json +77 -78
- package/src/api/error-classifier.ts +159 -159
- package/src/api/error-helpers.ts +118 -118
- package/src/api/models.ts +261 -261
- package/src/api/server.ts +860 -859
- package/src/cache/memory-cache.ts +385 -385
- package/src/clean-cache.ts +204 -204
- package/src/core/account-concurrency.ts +671 -671
- package/src/core/account-manager.ts +301 -297
- package/src/core/account-priority.ts +163 -163
- package/src/core/accounts.ts +186 -186
- package/src/core/config.ts +383 -383
- package/src/core/crypto-utils.ts +79 -79
- package/src/core/database.ts +276 -276
- package/src/core/errors.ts +118 -118
- package/src/core/logger.ts +269 -269
- package/src/core/memory-usage.ts +84 -84
- package/src/core/metrics.ts +291 -291
- package/src/core/model-alias.ts +77 -77
- package/src/core/model-registry.ts +544 -544
- package/src/core/mutex.ts +119 -119
- package/src/core/paths.ts +199 -199
- package/src/core/prompt-limits.ts +214 -214
- package/src/core/reasoning-effort.ts +102 -102
- package/src/core/stream-registry.ts +96 -96
- package/src/core/waf-isolation.ts +117 -117
- package/src/core/watchdog.ts +195 -195
- package/src/delete-chats.ts +23 -23
- package/src/index.ts +65 -64
- package/src/login.ts +147 -147
- package/src/reset-cooldowns.ts +11 -11
- package/src/routes/anthropic/index.ts +355 -355
- package/src/routes/anthropic/translate.ts +522 -522
- package/src/routes/anthropic/types.ts +154 -154
- package/src/routes/anthropic/validation.ts +144 -144
- package/src/routes/chat/account.ts +1817 -1817
- package/src/routes/chat/context.ts +241 -241
- package/src/routes/chat/errors.ts +85 -85
- package/src/routes/chat/helpers.ts +268 -268
- package/src/routes/chat/index.ts +618 -618
- package/src/routes/chat/media.ts +285 -285
- package/src/routes/chat/retry-policy.ts +754 -754
- package/src/routes/chat/stop.ts +98 -98
- package/src/routes/chat/streaming.ts +2710 -2710
- package/src/routes/chat/validation.ts +526 -526
- package/src/routes/chat.ts +2 -2
- package/src/routes/completions.ts +290 -290
- package/src/routes/images.ts +139 -139
- package/src/routes/responses/adapter.ts +503 -503
- package/src/routes/responses/index.ts +405 -405
- package/src/routes/responses/state.ts +230 -230
- package/src/routes/responses/streaming.ts +528 -528
- package/src/routes/responses/types.ts +285 -285
- package/src/routes/responses/validation.ts +202 -202
- package/src/routes/upload.ts +731 -731
- package/src/routes/videos.ts +214 -214
- package/src/services/auth-playwright.ts +173 -173
- package/src/services/captcha-coordinator.ts +161 -161
- package/src/services/captcha-solver.ts +553 -553
- package/src/services/chat-cleanup.ts +80 -80
- package/src/services/context-meter.ts +317 -317
- package/src/services/fingerprint.ts +242 -242
- package/src/services/human-behavior.ts +173 -173
- package/src/services/media-generation.ts +1748 -1748
- package/src/services/playwright.ts +2878 -2800
- package/src/services/qwen-chat-pool.ts +345 -345
- package/src/services/qwen-errors.ts +133 -133
- package/src/services/qwen-headers.ts +79 -79
- package/src/services/qwen-thread-state.ts +393 -393
- package/src/services/qwen-url.ts +19 -19
- package/src/services/qwen.ts +3126 -3126
- package/src/services/session-keeper.ts +88 -88
- package/src/services/token-estimation-metrics.ts +118 -118
- package/src/sync/claude-code.ts +75 -75
- package/src/sync/codex.ts +123 -123
- package/src/sync/index.ts +362 -362
- package/src/sync/omp.ts +105 -105
- package/src/sync/opencode.ts +214 -214
- package/src/sync/types.ts +53 -53
- package/src/sync/utils.ts +27 -27
- package/src/sync-clients.ts +189 -189
- package/src/tools/instructions.ts +137 -137
- package/src/tools/manifest.ts +81 -81
- package/src/tools/parser.ts +2989 -2989
- package/src/tools/toolcall-tags.ts +142 -142
- package/src/tui/app.ts +259 -264
- package/src/tui/index.ts +61 -61
- package/src/tui/markdown.ts +258 -258
- package/src/tui/proxy-client.ts +331 -326
- package/src/tui/screen.ts +294 -278
- package/src/tui/server-manager.ts +270 -270
- package/src/tui/theme.ts +432 -432
- package/src/tui/types.ts +33 -33
- package/src/tui/views/accounts-view.ts +656 -656
- package/src/tui/views/chat-view.ts +1018 -823
- package/src/tui/views/logs-view.ts +479 -413
- package/src/tui/views/status-view.ts +204 -204
- package/src/tui/views/storage-view.ts +304 -291
- package/src/tui/views/sync-view.ts +409 -409
- package/src/types/ali-oss.d.ts +32 -32
- package/src/update-cli.ts +121 -0
- package/src/utils/context-truncation.ts +84 -84
- package/src/utils/json.ts +380 -380
- package/src/utils/session-id.ts +37 -37
- package/src/utils/tool-call-guard.ts +84 -84
- package/src/utils/types.ts +109 -109
package/src/login.ts
CHANGED
|
@@ -1,147 +1,147 @@
|
|
|
1
|
-
import {
|
|
2
|
-
addAccount,
|
|
3
|
-
removeAccount,
|
|
4
|
-
listAccounts,
|
|
5
|
-
type QwenAccount,
|
|
6
|
-
} from "./core/accounts.ts";
|
|
7
|
-
|
|
8
|
-
import { maskEmail } from "./core/logger.ts";
|
|
9
|
-
import * as readline from "readline";
|
|
10
|
-
import * as dotenv from "dotenv";
|
|
11
|
-
|
|
12
|
-
dotenv.config();
|
|
13
|
-
|
|
14
|
-
const rl = readline.createInterface({
|
|
15
|
-
input: process.stdin,
|
|
16
|
-
output: process.stdout,
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
function askQuestion(query: string): Promise<string> {
|
|
20
|
-
return new Promise((resolve) => {
|
|
21
|
-
rl.question(query, (answer) => {
|
|
22
|
-
resolve(answer.trim());
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function clear() {
|
|
28
|
-
process.stdout.write("\x1Bc");
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
async function showMenu() {
|
|
32
|
-
while (true) {
|
|
33
|
-
const accounts = listAccounts();
|
|
34
|
-
clear();
|
|
35
|
-
console.log("=== QwenProxy Account Manager ===\n");
|
|
36
|
-
console.log("Auth mode: Playwright (validated on server start)\n");
|
|
37
|
-
|
|
38
|
-
if (accounts.length > 0) {
|
|
39
|
-
console.log(`Configured accounts (${accounts.length}):\n`);
|
|
40
|
-
for (let i = 0; i < accounts.length; i++) {
|
|
41
|
-
console.log(
|
|
42
|
-
` [${i + 1}] ${accounts[i].email} (ID: ${accounts[i].id})`,
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
} else {
|
|
46
|
-
console.log("No accounts configured yet.\n");
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
console.log("\nOptions:");
|
|
50
|
-
console.log(" [A] Add account");
|
|
51
|
-
if (accounts.length > 0) {
|
|
52
|
-
console.log(" [R] Remove an account");
|
|
53
|
-
}
|
|
54
|
-
console.log(" [Q] Quit\n");
|
|
55
|
-
|
|
56
|
-
const choice = (await askQuestion("Select an option: ")).toUpperCase();
|
|
57
|
-
|
|
58
|
-
if (choice === "Q") {
|
|
59
|
-
rl.close();
|
|
60
|
-
process.exit(0);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (choice === "A") {
|
|
64
|
-
await addAccountFlow();
|
|
65
|
-
continue;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (choice === "R" && accounts.length > 0) {
|
|
69
|
-
await removeAccountFlow();
|
|
70
|
-
continue;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
async function addAccountFlow() {
|
|
76
|
-
clear();
|
|
77
|
-
console.log("=== Add New Account ===\n");
|
|
78
|
-
const email = await askQuestion("Email: ");
|
|
79
|
-
if (!email) {
|
|
80
|
-
console.log("Email is required.");
|
|
81
|
-
await askQuestion("Press Enter to continue...");
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const password = await askQuestion("Password: ");
|
|
86
|
-
if (!password) {
|
|
87
|
-
console.log("Password is required.");
|
|
88
|
-
await askQuestion("Press Enter to continue...");
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
let account: QwenAccount | null = null;
|
|
93
|
-
try {
|
|
94
|
-
account = addAccount(email, password);
|
|
95
|
-
console.log(`Account added: ${maskEmail(account.email)} (${account.id})`);
|
|
96
|
-
console.log("Credentials will be validated by Playwright on server start.");
|
|
97
|
-
} catch (err: any) {
|
|
98
|
-
if (account) removeAccount(account.id);
|
|
99
|
-
console.log(`\nError: ${err.message}`);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
await askQuestion("Press Enter to continue...");
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
async function removeAccountFlow() {
|
|
106
|
-
const accounts = listAccounts();
|
|
107
|
-
if (accounts.length === 0) return;
|
|
108
|
-
|
|
109
|
-
clear();
|
|
110
|
-
console.log("=== Remove Account ===\n");
|
|
111
|
-
|
|
112
|
-
for (let i = 0; i < accounts.length; i++) {
|
|
113
|
-
console.log(
|
|
114
|
-
` [${i + 1}] ${maskEmail(accounts[i].email)} (ID: ${accounts[i].id})`,
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
const input = await askQuestion(
|
|
119
|
-
"\nSelect account number to remove (or 0 to cancel): ",
|
|
120
|
-
);
|
|
121
|
-
const idx = parseInt(input) - 1;
|
|
122
|
-
|
|
123
|
-
if (isNaN(idx) || idx < 0 || idx >= accounts.length) {
|
|
124
|
-
console.log(input !== "0" ? "Invalid selection." : "Cancelled.");
|
|
125
|
-
await askQuestion("Press Enter to continue...");
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const account = accounts[idx];
|
|
130
|
-
const confirm = await askQuestion(`\nRemove ${account.email}? (y/N): `);
|
|
131
|
-
if (confirm.toLowerCase() === "y") {
|
|
132
|
-
if (removeAccount(account.id)) {
|
|
133
|
-
console.log(`Account ${maskEmail(account.email)} removed.`);
|
|
134
|
-
} else {
|
|
135
|
-
console.log("Failed to remove account.");
|
|
136
|
-
}
|
|
137
|
-
} else {
|
|
138
|
-
console.log("Cancelled.");
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
await askQuestion("Press Enter to continue...");
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
showMenu().catch((err) => {
|
|
145
|
-
console.error(err);
|
|
146
|
-
process.exit(1);
|
|
147
|
-
});
|
|
1
|
+
import {
|
|
2
|
+
addAccount,
|
|
3
|
+
removeAccount,
|
|
4
|
+
listAccounts,
|
|
5
|
+
type QwenAccount,
|
|
6
|
+
} from "./core/accounts.ts";
|
|
7
|
+
|
|
8
|
+
import { maskEmail } from "./core/logger.ts";
|
|
9
|
+
import * as readline from "readline";
|
|
10
|
+
import * as dotenv from "dotenv";
|
|
11
|
+
|
|
12
|
+
dotenv.config();
|
|
13
|
+
|
|
14
|
+
const rl = readline.createInterface({
|
|
15
|
+
input: process.stdin,
|
|
16
|
+
output: process.stdout,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
function askQuestion(query: string): Promise<string> {
|
|
20
|
+
return new Promise((resolve) => {
|
|
21
|
+
rl.question(query, (answer) => {
|
|
22
|
+
resolve(answer.trim());
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function clear() {
|
|
28
|
+
process.stdout.write("\x1Bc");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async function showMenu() {
|
|
32
|
+
while (true) {
|
|
33
|
+
const accounts = listAccounts();
|
|
34
|
+
clear();
|
|
35
|
+
console.log("=== QwenProxy Account Manager ===\n");
|
|
36
|
+
console.log("Auth mode: Playwright (validated on server start)\n");
|
|
37
|
+
|
|
38
|
+
if (accounts.length > 0) {
|
|
39
|
+
console.log(`Configured accounts (${accounts.length}):\n`);
|
|
40
|
+
for (let i = 0; i < accounts.length; i++) {
|
|
41
|
+
console.log(
|
|
42
|
+
` [${i + 1}] ${accounts[i].email} (ID: ${accounts[i].id})`,
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
} else {
|
|
46
|
+
console.log("No accounts configured yet.\n");
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
console.log("\nOptions:");
|
|
50
|
+
console.log(" [A] Add account");
|
|
51
|
+
if (accounts.length > 0) {
|
|
52
|
+
console.log(" [R] Remove an account");
|
|
53
|
+
}
|
|
54
|
+
console.log(" [Q] Quit\n");
|
|
55
|
+
|
|
56
|
+
const choice = (await askQuestion("Select an option: ")).toUpperCase();
|
|
57
|
+
|
|
58
|
+
if (choice === "Q") {
|
|
59
|
+
rl.close();
|
|
60
|
+
process.exit(0);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (choice === "A") {
|
|
64
|
+
await addAccountFlow();
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (choice === "R" && accounts.length > 0) {
|
|
69
|
+
await removeAccountFlow();
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async function addAccountFlow() {
|
|
76
|
+
clear();
|
|
77
|
+
console.log("=== Add New Account ===\n");
|
|
78
|
+
const email = await askQuestion("Email: ");
|
|
79
|
+
if (!email) {
|
|
80
|
+
console.log("Email is required.");
|
|
81
|
+
await askQuestion("Press Enter to continue...");
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const password = await askQuestion("Password: ");
|
|
86
|
+
if (!password) {
|
|
87
|
+
console.log("Password is required.");
|
|
88
|
+
await askQuestion("Press Enter to continue...");
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
let account: QwenAccount | null = null;
|
|
93
|
+
try {
|
|
94
|
+
account = addAccount(email, password);
|
|
95
|
+
console.log(`Account added: ${maskEmail(account.email)} (${account.id})`);
|
|
96
|
+
console.log("Credentials will be validated by Playwright on server start.");
|
|
97
|
+
} catch (err: any) {
|
|
98
|
+
if (account) removeAccount(account.id);
|
|
99
|
+
console.log(`\nError: ${err.message}`);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
await askQuestion("Press Enter to continue...");
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
async function removeAccountFlow() {
|
|
106
|
+
const accounts = listAccounts();
|
|
107
|
+
if (accounts.length === 0) return;
|
|
108
|
+
|
|
109
|
+
clear();
|
|
110
|
+
console.log("=== Remove Account ===\n");
|
|
111
|
+
|
|
112
|
+
for (let i = 0; i < accounts.length; i++) {
|
|
113
|
+
console.log(
|
|
114
|
+
` [${i + 1}] ${maskEmail(accounts[i].email)} (ID: ${accounts[i].id})`,
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const input = await askQuestion(
|
|
119
|
+
"\nSelect account number to remove (or 0 to cancel): ",
|
|
120
|
+
);
|
|
121
|
+
const idx = parseInt(input) - 1;
|
|
122
|
+
|
|
123
|
+
if (isNaN(idx) || idx < 0 || idx >= accounts.length) {
|
|
124
|
+
console.log(input !== "0" ? "Invalid selection." : "Cancelled.");
|
|
125
|
+
await askQuestion("Press Enter to continue...");
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const account = accounts[idx];
|
|
130
|
+
const confirm = await askQuestion(`\nRemove ${account.email}? (y/N): `);
|
|
131
|
+
if (confirm.toLowerCase() === "y") {
|
|
132
|
+
if (removeAccount(account.id)) {
|
|
133
|
+
console.log(`Account ${maskEmail(account.email)} removed.`);
|
|
134
|
+
} else {
|
|
135
|
+
console.log("Failed to remove account.");
|
|
136
|
+
}
|
|
137
|
+
} else {
|
|
138
|
+
console.log("Cancelled.");
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
await askQuestion("Press Enter to continue...");
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
showMenu().catch((err) => {
|
|
145
|
+
console.error(err);
|
|
146
|
+
process.exit(1);
|
|
147
|
+
});
|
package/src/reset-cooldowns.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { clearAllAccountCooldowns } from "./core/account-manager.ts";
|
|
2
|
-
import { loadAccounts } from "./core/accounts.ts";
|
|
3
|
-
|
|
4
|
-
function main() {
|
|
5
|
-
const accounts = loadAccounts();
|
|
6
|
-
console.log(`🔍 Checking cooldowns for ${accounts.length} configured account(s)...`);
|
|
7
|
-
const cleared = clearAllAccountCooldowns();
|
|
8
|
-
console.log(`✅ Cooldowns reset successfully: ${cleared} account(s) cleared.`);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
main();
|
|
1
|
+
import { clearAllAccountCooldowns } from "./core/account-manager.ts";
|
|
2
|
+
import { loadAccounts } from "./core/accounts.ts";
|
|
3
|
+
|
|
4
|
+
function main() {
|
|
5
|
+
const accounts = loadAccounts();
|
|
6
|
+
console.log(`🔍 Checking cooldowns for ${accounts.length} configured account(s)...`);
|
|
7
|
+
const cleared = clearAllAccountCooldowns();
|
|
8
|
+
console.log(`✅ Cooldowns reset successfully: ${cleared} account(s) cleared.`);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
main();
|