mslxdff 0.1.170 → 0.1.171
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/bin/mslxdff.js +3 -3
- package/docs/cli_help_mini.md +143 -0
- package/package.json +1 -1
- package/src/anthropic/count-tokens.js +39 -0
- package/src/anthropic/translate.js +20 -41
- package/src/auto.js +254 -254
- package/src/bench/cline-bench.js +42 -42
- package/src/bench/probe.js +70 -70
- package/src/bench/report.js +162 -162
- package/src/bench/runner.js +77 -77
- package/src/bench/via-probe.js +124 -124
- package/src/bench/via-routes.js +87 -87
- package/src/bench/workbuddy-bench.js +54 -54
- package/src/chat/engine.js +160 -160
- package/src/chat/gateway.js +163 -163
- package/src/chat/orchestrator.js +234 -234
- package/src/chat/prompt.js +70 -70
- package/src/chat/repl.js +88 -88
- package/src/chat/terminal.js +135 -135
- package/src/chat/tools.js +306 -306
- package/src/chat-pipeline/index.js +131 -131
- package/src/chat-pipeline/policy.js +76 -76
- package/src/cli/commands/group.js +249 -249
- package/src/cli/commands/model/picks.js +50 -50
- package/src/cli/commands/provider/bench-via.js +247 -247
- package/src/cli/commands/provider/bench.js +141 -141
- package/src/cli/commands/provider/index.js +133 -133
- package/src/cli/commands/provider/models.js +145 -145
- package/src/cli/commands/provider/qwenwork-login.js +119 -119
- package/src/cli/commands/sync.js +310 -310
- package/src/cli/status.js +279 -279
- package/src/daemon.js +112 -112
- package/src/model-capabilities/enrich.js +86 -86
- package/src/model-capabilities/index.js +183 -183
- package/src/model-capabilities/parse.js +70 -70
- package/src/models.js +225 -225
- package/src/providers/AGENTS.md +49 -0
- package/src/providers/cline/auth.js +228 -228
- package/src/providers/cline/chat.js +307 -307
- package/src/providers/cline.js +2 -2
- package/src/providers/codearts/concurrency.js +34 -0
- package/src/providers/codearts/index.js +11 -3
- package/src/providers/globalqwenwork/cosy.js +123 -123
- package/src/providers/globalqwenwork/crypto.js +218 -218
- package/src/providers/globalqwenwork/http.js +20 -20
- package/src/providers/globalqwenwork/payload.js +4 -2
- package/src/providers/globalqwenwork/rsa.js +54 -54
- package/src/providers/globalqwenwork/sse.js +268 -268
- package/src/providers/globalqwenwork/stream.js +130 -130
- package/src/providers/globalqwenwork/upstream.js +122 -122
- package/src/providers/keyring.js +60 -60
- package/src/providers/qoder/chat.js +203 -200
- package/src/providers/qoder/index.js +249 -249
- package/src/providers/qoder/sse.js +145 -145
- package/src/providers/qwenwork/account-store.js +133 -133
- package/src/providers/qwenwork/constants.js +67 -67
- package/src/providers/qwenwork/cosy.js +120 -120
- package/src/providers/qwenwork/crypto.js +218 -218
- package/src/providers/qwenwork/http.js +20 -20
- package/src/providers/qwenwork/index.js +327 -327
- package/src/providers/qwenwork/payload.js +144 -142
- package/src/providers/qwenwork/rsa.js +54 -54
- package/src/providers/qwenwork/sse.js +268 -268
- package/src/providers/qwenwork/stream.js +130 -130
- package/src/providers/qwenwork/upstream.js +120 -120
- package/src/providers/qwenwork.js +1 -1
- package/src/providers/raccoon/chat.js +10 -5
- package/src/providers/raccoon/const.js +4 -4
- package/src/providers/registry.js +79 -79
- package/src/providers/workbuddy/chat.js +248 -248
- package/src/providers/workbuddy/payload.js +16 -7
- package/src/providers/workbuddy/reshape.js +152 -152
- package/src/providers/workbuddy.js +2 -2
- package/src/providers/zcode/chat.js +7 -0
- package/src/reasoning.js +32 -32
- package/src/responses/translate.js +4 -0
- package/src/routes/AGENTS.md +37 -0
- package/src/routes/chat/exhausted-handler.js +5 -0
- package/src/routes/chat/gateway.js +46 -46
- package/src/routes/chat/relay-pipeline.js +294 -291
- package/src/routes/chat/via-route-handler.js +146 -146
- package/src/routes/hedge.js +255 -255
- package/src/routes/messages-route.js +1 -1
- package/src/routes/models-route.js +167 -167
- package/src/routes/peers.js +273 -273
- package/src/routes/stream-scan.js +47 -21
- package/src/routes/stream.js +385 -385
- package/src/runtime/bootstrap.js +50 -50
- package/src/runtime/provider-gate.js +36 -36
- package/src/runtime/providers-setup.js +165 -165
- package/src/server.js +69 -69
- package/src/state/schemas/allowlist.js +92 -92
- package/src/sync-opencode.js +280 -280
- package/src/talk-full.js +1 -0
- package/src/talk-log.js +3 -2
- package/src/thinking-effort.js +67 -0
- package/src/transport/index.js +244 -244
- package/src/transport/pool.js +56 -56
- package/src/transport/retry.js +24 -24
- package/src/transport/sse.js +93 -93
- package/src/upstream-engine/sdk/convert.js +6 -0
- package/src/upstream-probe/display.js +52 -52
- package/src/upstream-probe/probe.js +49 -49
- package/src/upstream-probe/rotate.js +110 -110
- package/src/upstream-probe/start.js +45 -45
- package/src/upstream-responses.js +5 -0
- package/src/upstream.js +289 -289
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// codearts 上游硬限并发:FIFO 排队闸,超限请求等前面的让出额度再发(该上游对并发极敏感)。
|
|
2
|
+
export function createGate({ limit = 3 } = {}) {
|
|
3
|
+
const cap = Number.isFinite(limit) && limit > 0 ? Math.floor(limit) : Infinity;
|
|
4
|
+
let active = 0;
|
|
5
|
+
const waiters = [];
|
|
6
|
+
|
|
7
|
+
function release() {
|
|
8
|
+
active--;
|
|
9
|
+
const w = waiters.shift();
|
|
10
|
+
if (w) w();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async function run(fn, onWait) {
|
|
14
|
+
if (active >= cap) {
|
|
15
|
+
const t0 = Date.now();
|
|
16
|
+
const queued = waiters.length + 1;
|
|
17
|
+
await new Promise((resolve) => waiters.push(resolve));
|
|
18
|
+
if (onWait) { try { onWait({ waitedMs: Date.now() - t0, queued, limit: cap }); } catch {} }
|
|
19
|
+
}
|
|
20
|
+
active++;
|
|
21
|
+
try {
|
|
22
|
+
return await fn();
|
|
23
|
+
} finally {
|
|
24
|
+
release();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
run,
|
|
30
|
+
stats: () => ({ active, queued: waiters.length, limit: cap }),
|
|
31
|
+
get active() { return active; },
|
|
32
|
+
get queued() { return waiters.length; },
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -4,12 +4,13 @@ import { createKeyRing } from "../keyring.js";
|
|
|
4
4
|
import { loadProviderKeys, loadProviderBaseUrl, saveProviderConfig } from "../../state.js";
|
|
5
5
|
import { getUndici, createAgent, envInt, collectApiKeysGeneric } from "../base.js";
|
|
6
6
|
import { compatFetch } from "../../compat.js";
|
|
7
|
-
import { logDir } from "../../logs.js";
|
|
7
|
+
import { logDir, appendEvent } from "../../logs.js";
|
|
8
8
|
import { join } from "node:path";
|
|
9
9
|
import { SNAP_BASE, MODELS_CACHE_TTL_MS } from "./const.js";
|
|
10
10
|
import { createAuthPool } from "./auth-pool.js";
|
|
11
11
|
import { createCatalog, discoverAccountModels } from "./models.js";
|
|
12
12
|
import { createChatService } from "./chat.js";
|
|
13
|
+
import { createGate } from "./concurrency.js";
|
|
13
14
|
|
|
14
15
|
const { UndiciFetch } = getUndici();
|
|
15
16
|
|
|
@@ -30,6 +31,7 @@ export function createCodeartsProvider({
|
|
|
30
31
|
snapBase,
|
|
31
32
|
connectTimeoutMs = envInt("MSLXDFF_CODEARTS_TIMEOUT_MS", 30_000),
|
|
32
33
|
cooldownMs = envInt("MSLXDFF_CODEARTS_COOLDOWN_MS", 30_000),
|
|
34
|
+
maxConcurrent = Number.parseInt(process.env.MSLXDFF_CODEARTS_MAX_CONCURRENT ?? "", 10) || 3,
|
|
33
35
|
autoClaim = process.env.MSLXDFF_CODEARTS_AUTO_CLAIM !== "0",
|
|
34
36
|
fetchImpl,
|
|
35
37
|
file,
|
|
@@ -59,6 +61,8 @@ export function createCodeartsProvider({
|
|
|
59
61
|
};
|
|
60
62
|
const pool = createAuthPool({ keys: allKeys, fetchImpl, stsHost, clock, saveFn });
|
|
61
63
|
const catalog = createCatalog();
|
|
64
|
+
// 该上游对并发极敏感(实测 >3 即坏号/限流);超限请求 FIFO 排队,不拒绝。
|
|
65
|
+
const gate = createGate({ limit: maxConcurrent });
|
|
62
66
|
|
|
63
67
|
let agent = null; let dispatcher = null;
|
|
64
68
|
try {
|
|
@@ -75,9 +79,12 @@ export function createCodeartsProvider({
|
|
|
75
79
|
id, baseUrl: chatSvcBase, chatPath, fetchImpl, dispatcher, authPool: pool, catalog, connectTimeoutMs, clock,
|
|
76
80
|
});
|
|
77
81
|
|
|
82
|
+
const onWait = (info) => {
|
|
83
|
+
try { appendEvent({ type: "codearts-queue", ...info }); } catch {}
|
|
84
|
+
};
|
|
78
85
|
async function chat(body, opts = {}) {
|
|
79
86
|
if (!ring.size) throw new Error("codearts: missing credential — run: mslxdff -provider codearts login");
|
|
80
|
-
return chatSvc.runChat(body, ring, opts);
|
|
87
|
+
return gate.run(() => chatSvc.runChat(body, ring, opts), onWait);
|
|
81
88
|
}
|
|
82
89
|
async function chatWithKeys(body, keys, opts = {}) {
|
|
83
90
|
const blobs = (keys || []).filter((k) => typeof k === "string" && k.trim().startsWith("{"));
|
|
@@ -85,7 +92,7 @@ export function createCodeartsProvider({
|
|
|
85
92
|
const tmpRing = createKeyRing(blobs, { cooldownMs });
|
|
86
93
|
const tmpPool = createAuthPool({ keys: blobs, fetchImpl, stsHost, clock }); // 借用凭据不写回本节点
|
|
87
94
|
const tmpSvc = createChatService({ id, baseUrl: chatSvcBase, chatPath, fetchImpl, dispatcher: null, authPool: tmpPool, catalog, connectTimeoutMs, clock });
|
|
88
|
-
return tmpSvc.runChat(body, tmpRing, opts);
|
|
95
|
+
return gate.run(() => tmpSvc.runChat(body, tmpRing, opts), onWait);
|
|
89
96
|
}
|
|
90
97
|
|
|
91
98
|
// 三路发现(主账号);结果写目录(benefit 判定按账号隔离)
|
|
@@ -155,6 +162,7 @@ export function createCodeartsProvider({
|
|
|
155
162
|
baseUrl: resolvedBase,
|
|
156
163
|
_pool: pool,
|
|
157
164
|
_catalog: catalog,
|
|
165
|
+
_gate: gate,
|
|
158
166
|
_snapshotPath: join(logDir(), "codearts-models.json"),
|
|
159
167
|
};
|
|
160
168
|
}
|
|
@@ -1,123 +1,123 @@
|
|
|
1
|
-
// cosy.js(COSY 会话 + 签名头)— vendor 自 src/providers/qwenwork/cosy.js 逐字搬;
|
|
2
|
-
// 本目录 import 全为相对路径,自动绑定本目录 constants/crypto/rsa。线上头 x-qwenwork-* 与 cn 同名,**禁止改名**(实测 .ai 接受)。
|
|
3
|
-
// 关键不变式(改动即 403):
|
|
4
|
-
// · identity/payload 都必须 key 升序紧凑 JSON(sortedCompact)
|
|
5
|
-
// · 签名 = md5(payloadB64 \n cosyKey \n date \n body \n pathSig),pathSig 去 /algo 前缀、不含 query
|
|
6
|
-
// · authorization = `Bearer COSY.${payloadB64}.${sig}`;payloadB64 是**标准 base64(带 padding)**
|
|
7
|
-
// · 同一 requestId 重放会被上游判 `code 103 Duplicate request`
|
|
8
|
-
import { uuid, b64, b64url, utf8, aesCbcEncrypt, md5 } from "./crypto.js";
|
|
9
|
-
import { rsaPkcs1Encrypt } from "./rsa.js";
|
|
10
|
-
import {
|
|
11
|
-
COSY_VERSION, IDE_VERSION, RELEASE_VERSION, BUILD, CLIENT_TYPE,
|
|
12
|
-
BUSINESS_PRODUCT, BUSINESS_TYPE, SCENE, MACHINE_OS, UA,
|
|
13
|
-
} from "./constants.js";
|
|
14
|
-
|
|
15
|
-
const cache = new Map();
|
|
16
|
-
|
|
17
|
-
function sortedCompact(obj) {
|
|
18
|
-
const keys = Object.keys(obj).sort();
|
|
19
|
-
let out = "{";
|
|
20
|
-
for (let i = 0; i < keys.length; i++) {
|
|
21
|
-
if (i > 0) out += ",";
|
|
22
|
-
out += JSON.stringify(keys[i]) + ":" + JSON.stringify(obj[keys[i]]);
|
|
23
|
-
}
|
|
24
|
-
return out + "}";
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function newSession(account) {
|
|
28
|
-
const machineID = uuid();
|
|
29
|
-
const seed = (uuid() + uuid()).slice(0, 50);
|
|
30
|
-
const machineToken = b64url(utf8(seed));
|
|
31
|
-
const machineType = uuid().replace(/-/g, "").slice(0, 18);
|
|
32
|
-
const tempKey = uuid().replace(/-/g, "").slice(0, 16);
|
|
33
|
-
|
|
34
|
-
const identity = sortedCompact({
|
|
35
|
-
uid: account.uid || "",
|
|
36
|
-
aid: account.uid || "",
|
|
37
|
-
name: account.nickname || "",
|
|
38
|
-
email: account.email || "",
|
|
39
|
-
security_oauth_token: account.accessToken,
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
return {
|
|
43
|
-
machineID,
|
|
44
|
-
machineToken,
|
|
45
|
-
machineType,
|
|
46
|
-
tempKey,
|
|
47
|
-
cosyKey: rsaPkcs1Encrypt(utf8(tempKey)),
|
|
48
|
-
info: b64(aesCbcEncrypt(utf8(identity), utf8(tempKey))),
|
|
49
|
-
accessToken: account.accessToken,
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function sessionFor(account) {
|
|
54
|
-
if (!account || !account.accessToken) throw new Error("cosy: empty access token");
|
|
55
|
-
const key = account.id || account.uid || account.accessToken.slice(0, 16);
|
|
56
|
-
const hit = cache.get(key);
|
|
57
|
-
if (hit && hit.accessToken === account.accessToken) return hit;
|
|
58
|
-
if (cache.size > 128) cache.clear();
|
|
59
|
-
const sess = newSession(account);
|
|
60
|
-
cache.set(key, sess);
|
|
61
|
-
return sess;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export function invalidateSession(account) {
|
|
65
|
-
const key = account && (account.id || account.uid);
|
|
66
|
-
if (key) cache.delete(key);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function pathSig(rawURL) {
|
|
70
|
-
const u = new URL(rawURL);
|
|
71
|
-
let p = u.pathname;
|
|
72
|
-
if (p.startsWith("/algo")) p = p.slice("/algo".length);
|
|
73
|
-
return p;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export function signHeaders(account, body, rawURL, modelKey, accept) {
|
|
77
|
-
const sess = sessionFor(account);
|
|
78
|
-
const payload = sortedCompact({
|
|
79
|
-
cosyVersion: COSY_VERSION,
|
|
80
|
-
ideVersion: IDE_VERSION,
|
|
81
|
-
info: sess.info,
|
|
82
|
-
requestId: uuid(),
|
|
83
|
-
version: "v1",
|
|
84
|
-
});
|
|
85
|
-
const payloadB64 = b64(utf8(payload));
|
|
86
|
-
const date = Math.floor(Date.now() / 1000).toString();
|
|
87
|
-
const sig = md5(`${payloadB64}\n${sess.cosyKey}\n${date}\n${body}\n${pathSig(rawURL)}`);
|
|
88
|
-
|
|
89
|
-
const headers = {
|
|
90
|
-
accept: accept || "text/event-stream",
|
|
91
|
-
"content-type": "application/json",
|
|
92
|
-
"user-agent": UA,
|
|
93
|
-
"x-request-id": uuid(),
|
|
94
|
-
"x-qwenwork-version": IDE_VERSION,
|
|
95
|
-
"x-qwenwork-release-version": RELEASE_VERSION,
|
|
96
|
-
"x-qwenwork-build": BUILD,
|
|
97
|
-
"x-qwenwork-platform": "win32",
|
|
98
|
-
"x-qwenwork-arch": "x64",
|
|
99
|
-
"x-qwenwork-channel": "stable",
|
|
100
|
-
"cosy-version": COSY_VERSION,
|
|
101
|
-
"cosy-clienttype": CLIENT_TYPE,
|
|
102
|
-
"cosy-business-product": BUSINESS_PRODUCT,
|
|
103
|
-
"cosy-business-type": BUSINESS_TYPE,
|
|
104
|
-
"cosy-scene": SCENE,
|
|
105
|
-
"cosy-machineos": MACHINE_OS,
|
|
106
|
-
"login-version": "v2",
|
|
107
|
-
authorization: `Bearer COSY.${payloadB64}.${sig}`,
|
|
108
|
-
"cosy-key": sess.cosyKey,
|
|
109
|
-
"cosy-user": account.uid || "",
|
|
110
|
-
"cosy-date": date,
|
|
111
|
-
"cosy-machineid": sess.machineID,
|
|
112
|
-
"accept-encoding": "identity",
|
|
113
|
-
connection: "keep-alive",
|
|
114
|
-
"cache-control": "no-cache",
|
|
115
|
-
};
|
|
116
|
-
if (modelKey) {
|
|
117
|
-
headers["x-model-key"] = modelKey;
|
|
118
|
-
headers["x-model-source"] = "system";
|
|
119
|
-
}
|
|
120
|
-
return headers;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// globalqwenwork 变体(国际站 gateway.qwenwork.ai):协议与 cn 逐字同构,2026-10-01 现网实测签名/请求 200 — 见 docs/adr/0041-globalqwenwork-international-provider.md
|
|
1
|
+
// cosy.js(COSY 会话 + 签名头)— vendor 自 src/providers/qwenwork/cosy.js 逐字搬;
|
|
2
|
+
// 本目录 import 全为相对路径,自动绑定本目录 constants/crypto/rsa。线上头 x-qwenwork-* 与 cn 同名,**禁止改名**(实测 .ai 接受)。
|
|
3
|
+
// 关键不变式(改动即 403):
|
|
4
|
+
// · identity/payload 都必须 key 升序紧凑 JSON(sortedCompact)
|
|
5
|
+
// · 签名 = md5(payloadB64 \n cosyKey \n date \n body \n pathSig),pathSig 去 /algo 前缀、不含 query
|
|
6
|
+
// · authorization = `Bearer COSY.${payloadB64}.${sig}`;payloadB64 是**标准 base64(带 padding)**
|
|
7
|
+
// · 同一 requestId 重放会被上游判 `code 103 Duplicate request`
|
|
8
|
+
import { uuid, b64, b64url, utf8, aesCbcEncrypt, md5 } from "./crypto.js";
|
|
9
|
+
import { rsaPkcs1Encrypt } from "./rsa.js";
|
|
10
|
+
import {
|
|
11
|
+
COSY_VERSION, IDE_VERSION, RELEASE_VERSION, BUILD, CLIENT_TYPE,
|
|
12
|
+
BUSINESS_PRODUCT, BUSINESS_TYPE, SCENE, MACHINE_OS, UA,
|
|
13
|
+
} from "./constants.js";
|
|
14
|
+
|
|
15
|
+
const cache = new Map();
|
|
16
|
+
|
|
17
|
+
function sortedCompact(obj) {
|
|
18
|
+
const keys = Object.keys(obj).sort();
|
|
19
|
+
let out = "{";
|
|
20
|
+
for (let i = 0; i < keys.length; i++) {
|
|
21
|
+
if (i > 0) out += ",";
|
|
22
|
+
out += JSON.stringify(keys[i]) + ":" + JSON.stringify(obj[keys[i]]);
|
|
23
|
+
}
|
|
24
|
+
return out + "}";
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function newSession(account) {
|
|
28
|
+
const machineID = uuid();
|
|
29
|
+
const seed = (uuid() + uuid()).slice(0, 50);
|
|
30
|
+
const machineToken = b64url(utf8(seed));
|
|
31
|
+
const machineType = uuid().replace(/-/g, "").slice(0, 18);
|
|
32
|
+
const tempKey = uuid().replace(/-/g, "").slice(0, 16);
|
|
33
|
+
|
|
34
|
+
const identity = sortedCompact({
|
|
35
|
+
uid: account.uid || "",
|
|
36
|
+
aid: account.uid || "",
|
|
37
|
+
name: account.nickname || "",
|
|
38
|
+
email: account.email || "",
|
|
39
|
+
security_oauth_token: account.accessToken,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
machineID,
|
|
44
|
+
machineToken,
|
|
45
|
+
machineType,
|
|
46
|
+
tempKey,
|
|
47
|
+
cosyKey: rsaPkcs1Encrypt(utf8(tempKey)),
|
|
48
|
+
info: b64(aesCbcEncrypt(utf8(identity), utf8(tempKey))),
|
|
49
|
+
accessToken: account.accessToken,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function sessionFor(account) {
|
|
54
|
+
if (!account || !account.accessToken) throw new Error("cosy: empty access token");
|
|
55
|
+
const key = account.id || account.uid || account.accessToken.slice(0, 16);
|
|
56
|
+
const hit = cache.get(key);
|
|
57
|
+
if (hit && hit.accessToken === account.accessToken) return hit;
|
|
58
|
+
if (cache.size > 128) cache.clear();
|
|
59
|
+
const sess = newSession(account);
|
|
60
|
+
cache.set(key, sess);
|
|
61
|
+
return sess;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function invalidateSession(account) {
|
|
65
|
+
const key = account && (account.id || account.uid);
|
|
66
|
+
if (key) cache.delete(key);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function pathSig(rawURL) {
|
|
70
|
+
const u = new URL(rawURL);
|
|
71
|
+
let p = u.pathname;
|
|
72
|
+
if (p.startsWith("/algo")) p = p.slice("/algo".length);
|
|
73
|
+
return p;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function signHeaders(account, body, rawURL, modelKey, accept) {
|
|
77
|
+
const sess = sessionFor(account);
|
|
78
|
+
const payload = sortedCompact({
|
|
79
|
+
cosyVersion: COSY_VERSION,
|
|
80
|
+
ideVersion: IDE_VERSION,
|
|
81
|
+
info: sess.info,
|
|
82
|
+
requestId: uuid(),
|
|
83
|
+
version: "v1",
|
|
84
|
+
});
|
|
85
|
+
const payloadB64 = b64(utf8(payload));
|
|
86
|
+
const date = Math.floor(Date.now() / 1000).toString();
|
|
87
|
+
const sig = md5(`${payloadB64}\n${sess.cosyKey}\n${date}\n${body}\n${pathSig(rawURL)}`);
|
|
88
|
+
|
|
89
|
+
const headers = {
|
|
90
|
+
accept: accept || "text/event-stream",
|
|
91
|
+
"content-type": "application/json",
|
|
92
|
+
"user-agent": UA,
|
|
93
|
+
"x-request-id": uuid(),
|
|
94
|
+
"x-qwenwork-version": IDE_VERSION,
|
|
95
|
+
"x-qwenwork-release-version": RELEASE_VERSION,
|
|
96
|
+
"x-qwenwork-build": BUILD,
|
|
97
|
+
"x-qwenwork-platform": "win32",
|
|
98
|
+
"x-qwenwork-arch": "x64",
|
|
99
|
+
"x-qwenwork-channel": "stable",
|
|
100
|
+
"cosy-version": COSY_VERSION,
|
|
101
|
+
"cosy-clienttype": CLIENT_TYPE,
|
|
102
|
+
"cosy-business-product": BUSINESS_PRODUCT,
|
|
103
|
+
"cosy-business-type": BUSINESS_TYPE,
|
|
104
|
+
"cosy-scene": SCENE,
|
|
105
|
+
"cosy-machineos": MACHINE_OS,
|
|
106
|
+
"login-version": "v2",
|
|
107
|
+
authorization: `Bearer COSY.${payloadB64}.${sig}`,
|
|
108
|
+
"cosy-key": sess.cosyKey,
|
|
109
|
+
"cosy-user": account.uid || "",
|
|
110
|
+
"cosy-date": date,
|
|
111
|
+
"cosy-machineid": sess.machineID,
|
|
112
|
+
"accept-encoding": "identity",
|
|
113
|
+
connection: "keep-alive",
|
|
114
|
+
"cache-control": "no-cache",
|
|
115
|
+
};
|
|
116
|
+
if (modelKey) {
|
|
117
|
+
headers["x-model-key"] = modelKey;
|
|
118
|
+
headers["x-model-source"] = "system";
|
|
119
|
+
}
|
|
120
|
+
return headers;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// globalqwenwork 变体(国际站 gateway.qwenwork.ai):协议与 cn 逐字同构,2026-10-01 现网实测签名/请求 200 — 见 docs/adr/0041-globalqwenwork-international-provider.md
|