mslxdff 0.1.161 → 0.1.163

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 (116) hide show
  1. package/bin/mslxdff.js +4 -4
  2. package/package.json +1 -1
  3. package/src/auto.js +254 -254
  4. package/src/bench/cline-bench.js +42 -42
  5. package/src/bench/probe.js +70 -70
  6. package/src/bench/report.js +162 -162
  7. package/src/bench/runner.js +77 -77
  8. package/src/bench/via-probe.js +124 -124
  9. package/src/bench/via-routes.js +87 -87
  10. package/src/bench/workbuddy-bench.js +54 -54
  11. package/src/chat/engine.js +160 -160
  12. package/src/chat/gateway.js +163 -163
  13. package/src/chat/orchestrator.js +234 -234
  14. package/src/chat/prompt.js +70 -70
  15. package/src/chat/repl.js +88 -88
  16. package/src/chat/terminal.js +135 -135
  17. package/src/chat/tools.js +306 -306
  18. package/src/chat-pipeline/index.js +127 -126
  19. package/src/chat-pipeline/policy.js +76 -76
  20. package/src/cli/commands/group.js +249 -249
  21. package/src/cli/commands/model/picks.js +50 -50
  22. package/src/cli/commands/provider/bench-via.js +247 -247
  23. package/src/cli/commands/provider/bench.js +141 -141
  24. package/src/cli/commands/provider/index.js +126 -126
  25. package/src/cli/commands/provider/models.js +142 -142
  26. package/src/cli/commands/provider/qwenwork-login.js +119 -119
  27. package/src/cli/commands/stats.js +21 -9
  28. package/src/cli/commands/sync.js +232 -232
  29. package/src/cli/format.js +1 -0
  30. package/src/cli/help.js +1 -1
  31. package/src/cli/status.js +279 -279
  32. package/src/daemon.js +101 -101
  33. package/src/model-capabilities/enrich.js +86 -86
  34. package/src/model-capabilities/index.js +183 -183
  35. package/src/model-capabilities/parse.js +70 -70
  36. package/src/model-trace.js +4 -3
  37. package/src/models.js +225 -225
  38. package/src/providers/cline/auth.js +228 -228
  39. package/src/providers/cline/chat.js +307 -307
  40. package/src/providers/cline.js +2 -2
  41. package/src/providers/dispatcher.js +26 -14
  42. package/src/providers/globalqwenwork/cosy.js +123 -123
  43. package/src/providers/globalqwenwork/crypto.js +218 -218
  44. package/src/providers/globalqwenwork/http.js +20 -20
  45. package/src/providers/globalqwenwork/rsa.js +54 -54
  46. package/src/providers/globalqwenwork/sse.js +268 -268
  47. package/src/providers/globalqwenwork/stream.js +130 -130
  48. package/src/providers/globalqwenwork/upstream.js +122 -122
  49. package/src/providers/globalworkbuddy/account-store.js +198 -0
  50. package/src/providers/globalworkbuddy/auth.js +97 -0
  51. package/src/providers/globalworkbuddy/catalog.js +138 -0
  52. package/src/providers/globalworkbuddy/constants.js +73 -0
  53. package/src/providers/globalworkbuddy/device-auth.js +120 -0
  54. package/src/providers/globalworkbuddy/errors.js +98 -0
  55. package/src/providers/globalworkbuddy/headers.js +89 -0
  56. package/src/providers/globalworkbuddy/models.js +96 -0
  57. package/src/providers/globalworkbuddy/payload.js +80 -0
  58. package/src/providers/keyring.js +60 -60
  59. package/src/providers/qoder/aggregate.js +12 -3
  60. package/src/providers/qoder/chat.js +200 -183
  61. package/src/providers/qoder/index.js +249 -230
  62. package/src/providers/qoder/models.js +7 -3
  63. package/src/providers/qoder/payload.js +7 -1
  64. package/src/providers/qoder/request.js +2 -1
  65. package/src/providers/qoder/sse.js +145 -103
  66. package/src/providers/qoder/stream.js +16 -4
  67. package/src/providers/qwenwork/account-store.js +133 -133
  68. package/src/providers/qwenwork/constants.js +67 -67
  69. package/src/providers/qwenwork/cosy.js +120 -120
  70. package/src/providers/qwenwork/crypto.js +218 -218
  71. package/src/providers/qwenwork/http.js +20 -20
  72. package/src/providers/qwenwork/index.js +327 -327
  73. package/src/providers/qwenwork/payload.js +142 -142
  74. package/src/providers/qwenwork/rsa.js +54 -54
  75. package/src/providers/qwenwork/sse.js +268 -268
  76. package/src/providers/qwenwork/stream.js +130 -130
  77. package/src/providers/qwenwork/upstream.js +120 -120
  78. package/src/providers/qwenwork.js +1 -1
  79. package/src/providers/registry.js +74 -74
  80. package/src/providers/workbuddy/chat.js +248 -248
  81. package/src/providers/workbuddy/reshape.js +152 -152
  82. package/src/providers/workbuddy.js +2 -2
  83. package/src/reasoning.js +32 -32
  84. package/src/routes/chat/exhausted-handler.js +13 -2
  85. package/src/routes/chat/gateway.js +46 -46
  86. package/src/routes/chat/relay-pipeline.js +292 -276
  87. package/src/routes/chat/via-route-handler.js +146 -146
  88. package/src/routes/hedge.js +255 -255
  89. package/src/routes/models-route.js +167 -167
  90. package/src/routes/peers.js +273 -273
  91. package/src/routes/stream-scan.js +22 -5
  92. package/src/routes/stream.js +385 -386
  93. package/src/runtime/bootstrap.js +45 -45
  94. package/src/runtime/provider-gate.js +34 -34
  95. package/src/runtime/providers-setup.js +165 -165
  96. package/src/runtime/server-lifecycle.js +5 -6
  97. package/src/server.js +69 -64
  98. package/src/state/schemas/allowlist.js +92 -92
  99. package/src/sync-opencode.js +280 -280
  100. package/src/talk-full-redact.js +129 -0
  101. package/src/talk-full.js +130 -0
  102. package/src/talk-log.js +42 -15
  103. package/src/transport/index.js +244 -244
  104. package/src/transport/pool.js +56 -56
  105. package/src/transport/retry.js +24 -24
  106. package/src/transport/sse.js +93 -93
  107. package/src/upstream-engine/sdk/responses.js +5 -0
  108. package/src/upstream-probe/display.js +52 -52
  109. package/src/upstream-probe/probe.js +49 -49
  110. package/src/upstream-probe/rotate.js +110 -110
  111. package/src/upstream-probe/start.js +45 -45
  112. package/src/upstream.js +289 -289
  113. package/src/usage/report.js +14 -8
  114. package/docs/cli_help_mini.md +0 -135
  115. package/src/providers/AGENTS.md +0 -46
  116. package/src/routes/AGENTS.md +0 -37
@@ -1,6 +1,14 @@
1
- import { appendEvent } from "../logs.js";
2
- import { splitModelId, DEFAULT_PROVIDER, joinModelId } from "./model-id.js";
3
- import { isModelAllowed as stateIsAllowed, loadProviderAllowedModels as stateLoadAllowed, loadProviderAllowAnyModels as stateLoadAllowAny } from "../state.js";
1
+ import { appendEvent } from "../logs.js";
2
+ import { splitModelId, DEFAULT_PROVIDER, joinModelId } from "./model-id.js";
3
+ import { isModelAllowed as stateIsAllowed, loadProviderAllowedModels as stateLoadAllowed, loadProviderAllowAnyModels as stateLoadAllowAny } from "../state.js";
4
+ // 定制预热名单:registry customProviders 8 家 + 默认 opencode;openrouter/自配 generic 不预热(按需自拉)
5
+ const CUSTOM_PREHEAT_IDS = new Set(["opencode", "workbuddy", "traework", "cline", "codearts", "qoder", "globalqwenwork", "qwenwork", "zcode"]);
6
+ function isPreheatDisabled() {
7
+ const raw = process.env.MSLXDFF_PREHEAT;
8
+ if (raw === undefined || raw === null || raw === "") return false;
9
+ const s = String(raw).trim().toLowerCase();
10
+ return s === "0" || s === "off" || s === "false" || s === "no" || s === "disable" || s === "disabled";
11
+ }
4
12
 
5
13
  // 多供应商 dispatcher:把多个 Provider 聚合成一个 `upstream` 形状(chat/preheat/close),
6
14
  // 按 body.model 的前缀路由到对应供应商,转发上游前剥掉前缀只发原始 id。
@@ -111,18 +119,22 @@ export function createProviderDispatcher(providers = [], opts = {}) {
111
119
  return out;
112
120
  }
113
121
 
114
- // 只预热默认供应商(opencode):连接池与模型缓存预热是其主链路收益;
115
- // 其他供应商按需在首次请求时自拉(10min 缓存)。不再逐家预热,避免 daemon 每次启动
116
- // 对所有上游各发一次 GET;MSLXDFF_PREHEAT=0 的关闭由唯一被调的 opencode preheat 自行尊重。
117
- // 见 .agents/notes/implemented/simplification/2026-09-16-preheat-opencode-only.md
122
+ // 预热定制供应商 + 默认供应商(opencode):registry 名单 8 家 + opencode 共 9 家并发各打一次;
123
+ // openrouter/用户自配 generic 不在此列(按需首次请求自拉)。单家失败静默,不拖累启动。
118
124
  async function preheat() {
119
- const p = byId.get(DEFAULT_PROVIDER);
120
- if (!p || typeof p.preheat !== "function") return { ok: false, skipped: true };
121
- try {
122
- return await p.preheat();
123
- } catch {
124
- return { ok: false, error: "preheat failed" };
125
- }
125
+ if (isPreheatDisabled()) return { ok: true, skipped: true };
126
+ const targets = providers.filter((p) => p && typeof p.preheat === "function" && CUSTOM_PREHEAT_IDS.has(p.id));
127
+ if (!targets.length) return { ok: false, skipped: true };
128
+ const settled = await Promise.all(targets.map(async (p) => {
129
+ try {
130
+ const r = await p.preheat();
131
+ return { id: p.id, ...(r && typeof r === "object" ? r : { ok: false }) };
132
+ } catch {
133
+ return { id: p.id, ok: false, error: "preheat failed" };
134
+ }
135
+ }));
136
+ const okCount = settled.filter((r) => r && r.ok).length;
137
+ return { ok: okCount > 0, results: settled, okCount, total: settled.length };
126
138
  }
127
139
 
128
140
  async function close() {
@@ -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