mslxdff 0.1.159 → 0.1.160

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 (95) 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/auto-race.js +1 -1
  19. package/src/chat-pipeline/index.js +123 -123
  20. package/src/chat-pipeline/policy.js +76 -76
  21. package/src/chat-pipeline/serial-trial.js +210 -210
  22. package/src/cli/commands/group.js +249 -249
  23. package/src/cli/commands/model/picks.js +50 -50
  24. package/src/cli/commands/provider/bench-via.js +247 -247
  25. package/src/cli/commands/provider/bench.js +141 -141
  26. package/src/cli/commands/provider/index.js +124 -124
  27. package/src/cli/commands/provider/models.js +139 -139
  28. package/src/cli/commands/provider/qwenwork-login.js +119 -119
  29. package/src/cli/commands/stats.js +20 -5
  30. package/src/cli/commands/sync.js +232 -232
  31. package/src/cli/provider-row.js +2 -2
  32. package/src/cli/status.js +279 -279
  33. package/src/daemon.js +96 -96
  34. package/src/model-capabilities/enrich.js +86 -86
  35. package/src/model-capabilities/index.js +183 -183
  36. package/src/model-capabilities/parse.js +70 -70
  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/keyring.js +60 -60
  42. package/src/providers/qoder/chat.js +183 -183
  43. package/src/providers/qoder/index.js +230 -230
  44. package/src/providers/qoder/sse.js +103 -103
  45. package/src/providers/qwenwork/account-store.js +133 -133
  46. package/src/providers/qwenwork/constants.js +67 -67
  47. package/src/providers/qwenwork/cosy.js +120 -120
  48. package/src/providers/qwenwork/crypto.js +218 -218
  49. package/src/providers/qwenwork/http.js +20 -20
  50. package/src/providers/qwenwork/index.js +327 -327
  51. package/src/providers/qwenwork/payload.js +142 -142
  52. package/src/providers/qwenwork/rsa.js +54 -54
  53. package/src/providers/qwenwork/sse.js +268 -268
  54. package/src/providers/qwenwork/stream.js +130 -130
  55. package/src/providers/qwenwork/upstream.js +120 -120
  56. package/src/providers/qwenwork.js +1 -1
  57. package/src/providers/registry.js +66 -66
  58. package/src/providers/workbuddy/chat.js +248 -248
  59. package/src/providers/workbuddy/reshape.js +152 -152
  60. package/src/providers/workbuddy.js +2 -2
  61. package/src/providers/zcode/chat.js +11 -10
  62. package/src/providers/zcode/const.js +1 -1
  63. package/src/providers/zcode/context-shape.js +162 -0
  64. package/src/providers/zcode/headers.js +38 -0
  65. package/src/reasoning.js +32 -32
  66. package/src/routes/chat/broadband-handler.js +3 -2
  67. package/src/routes/chat/gateway.js +46 -46
  68. package/src/routes/chat/hedge-handler.js +3 -0
  69. package/src/routes/chat/local-handler.js +2 -0
  70. package/src/routes/chat/peer-handler.js +2 -0
  71. package/src/routes/chat/relay-pipeline.js +264 -250
  72. package/src/routes/chat/via-route-handler.js +146 -144
  73. package/src/routes/hedge.js +255 -255
  74. package/src/routes/models-route.js +167 -167
  75. package/src/routes/peers.js +273 -273
  76. package/src/routes/stream-scan.js +86 -0
  77. package/src/routes/stream.js +393 -438
  78. package/src/runtime/bootstrap.js +45 -45
  79. package/src/runtime/provider-gate.js +33 -33
  80. package/src/runtime/providers-setup.js +165 -165
  81. package/src/server.js +64 -64
  82. package/src/state/schemas/allowlist.js +92 -92
  83. package/src/sync-opencode.js +280 -280
  84. package/src/transport/index.js +244 -244
  85. package/src/transport/pool.js +56 -56
  86. package/src/transport/retry.js +24 -24
  87. package/src/transport/sse.js +93 -93
  88. package/src/upstream-probe/display.js +52 -52
  89. package/src/upstream-probe/probe.js +49 -49
  90. package/src/upstream-probe/rotate.js +110 -110
  91. package/src/upstream-probe/start.js +45 -45
  92. package/src/upstream.js +289 -289
  93. package/src/usage/record.js +8 -1
  94. package/src/usage/report.js +39 -2
  95. package/docs/cli_help_mini.md +0 -133
package/src/reasoning.js CHANGED
@@ -1,33 +1,33 @@
1
- const PLACEHOLDER = " ";
2
-
3
- const MODEL_RULES = [
4
- { match: (m) => /^kimi-/i.test(m || ""), scope: "toolCalls" },
5
- { match: (m) => /deepseek/i.test(m || ""), scope: "all" },
6
- ];
7
-
8
- export function normalizeModel(model) {
9
- return model.startsWith("oc/") ? model.slice(3) : model;
10
- }
11
-
12
- function shouldInject(message, scope) {
13
- if (message?.role !== "assistant") return false;
14
- const rc = message.reasoning_content;
15
- if (typeof rc === "string" && rc.length > 0) return false;
16
- if (scope === "toolCalls") {
17
- return Array.isArray(message.tool_calls) && message.tool_calls.length > 0;
18
- }
19
- return true;
20
- }
21
-
22
- function applyRule(body, rule) {
23
- if (!rule || !body?.messages) return body;
24
- const messages = body.messages.map((m) =>
25
- shouldInject(m, rule.scope) ? { ...m, reasoning_content: PLACEHOLDER } : m
26
- );
27
- return { ...body, messages };
28
- }
29
-
30
- export function injectReasoningContent(model, body) {
31
- const rule = MODEL_RULES.find((r) => r.match(model));
32
- return applyRule(body, rule);
1
+ const PLACEHOLDER = " ";
2
+
3
+ const MODEL_RULES = [
4
+ { match: (m) => /^kimi-/i.test(m || ""), scope: "toolCalls" },
5
+ { match: (m) => /deepseek/i.test(m || ""), scope: "all" },
6
+ ];
7
+
8
+ export function normalizeModel(model) {
9
+ return model.startsWith("oc/") ? model.slice(3) : model;
10
+ }
11
+
12
+ function shouldInject(message, scope) {
13
+ if (message?.role !== "assistant") return false;
14
+ const rc = message.reasoning_content;
15
+ if (typeof rc === "string" && rc.length > 0) return false;
16
+ if (scope === "toolCalls") {
17
+ return Array.isArray(message.tool_calls) && message.tool_calls.length > 0;
18
+ }
19
+ return true;
20
+ }
21
+
22
+ function applyRule(body, rule) {
23
+ if (!rule || !body?.messages) return body;
24
+ const messages = body.messages.map((m) =>
25
+ shouldInject(m, rule.scope) ? { ...m, reasoning_content: PLACEHOLDER } : m
26
+ );
27
+ return { ...body, messages };
28
+ }
29
+
30
+ export function injectReasoningContent(model, body) {
31
+ const rule = MODEL_RULES.find((r) => r.match(model));
32
+ return applyRule(body, rule);
33
33
  }
@@ -21,6 +21,7 @@ export async function handleBroadbandRelay({
21
21
  evt,
22
22
  mark,
23
23
  perf0,
24
+ attemptStartMs,
24
25
  stages,
25
26
  res,
26
27
  startedAt,
@@ -48,7 +49,7 @@ export async function handleBroadbandRelay({
48
49
  });
49
50
  const isResponse = bb.result && typeof bb.result.status === "number" && typeof bb.result.headers?.get === "function";
50
51
  if (isResponse) {
51
- const r = await pipeline.execute({ res, upRes: bb.result, body, requested, actual: model, lastErr, via: "broadband", lockModel, useAuto, handlerCtx, mark, perf0, stages, startedAt });
52
+ const r = await pipeline.execute({ res, upRes: bb.result, body, requested, actual: model, lastErr, via: "broadband", lockModel, useAuto, handlerCtx, mark, perf0, attemptStartMs, stages, startedAt });
52
53
  if (!r.handled) return { handled: false, upRes: null, lastErr: r.lastErr };
53
54
  return { handled: true };
54
55
  }
@@ -62,7 +63,7 @@ export async function handleBroadbandRelay({
62
63
  text: async () => str,
63
64
  body: isSSE ? (async function* () { yield Buffer.from(str); })() : null,
64
65
  };
65
- const r = await pipeline.execute({ res, upRes: fakeRes, body, requested, actual: model, lastErr, via: "broadband-local", lockModel, useAuto, handlerCtx, mark, perf0, stages, startedAt });
66
+ const r = await pipeline.execute({ res, upRes: fakeRes, body, requested, actual: model, lastErr, via: "broadband-local", lockModel, useAuto, handlerCtx, mark, perf0, attemptStartMs, stages, startedAt });
66
67
  if (!r.handled) return { handled: false, upRes: null, lastErr: r.lastErr };
67
68
  return { handled: true };
68
69
  }
@@ -1,47 +1,47 @@
1
- import { clientIp, json, readBody, parseHops } from "../helpers.js";
2
- import { runHook } from "../../plugins.js";
3
- import { createChatPipeline } from "../../chat-pipeline/index.js";
4
-
5
- /**
6
- * ChatGateway 薄适配层:仅负责 HTTP I/O(readBody + request:received hook)→ 委托 ChatPipeline.execute
7
- * Policy/Order/AutoRace/hedge/peer/broadband 全部在 chat-pipeline 深模块内。
8
- */
9
- export function createChatGateway(deps = {}) {
10
- const pipeline = createChatPipeline(deps);
11
-
12
- async function handle({ req, res }) {
13
- let body;
14
- try {
15
- body = await readBody(req);
16
- } catch {
17
- return json(res, 400, { error: "Invalid JSON body" });
18
- }
19
- if (deps.plugins?.length) {
20
- const rc = await runHook(deps.plugins, "request:received", {
21
- ip: clientIp(req),
22
- hops: parseHops(req.headers["x-mslxdff-hops"]),
23
- headers: { "content-type": req.headers["content-type"] },
24
- body,
25
- });
26
- for (const e of rc.errors) deps.logs?.appendEvent?.({ ts: Date.now(), type: "plugin-hook-error", hook: "request:received", plugin: e.plugin, error: e.error });
27
- const respond = rc.value?.respond;
28
- if (respond && typeof respond === "object") return json(res, respond.status || 200, respond.body ?? {});
29
- }
30
- req.body = body;
31
- try {
32
- await pipeline.execute({ req, res });
33
- } catch (err) {
34
- const msg = err?.message || String(err);
35
- if (!res.headersSent) return json(res, 502, { error: msg });
36
- try { res.end(); } catch {}
37
- }
38
- }
39
-
40
- return { handle };
41
- }
42
-
43
- // 薄适配:保持原 chatHandler 签名兼容
44
- export async function chatHandler(ctx) {
45
- const gw = createChatGateway(ctx);
46
- return gw.handle(ctx);
1
+ import { clientIp, json, readBody, parseHops } from "../helpers.js";
2
+ import { runHook } from "../../plugins.js";
3
+ import { createChatPipeline } from "../../chat-pipeline/index.js";
4
+
5
+ /**
6
+ * ChatGateway 薄适配层:仅负责 HTTP I/O(readBody + request:received hook)→ 委托 ChatPipeline.execute
7
+ * Policy/Order/AutoRace/hedge/peer/broadband 全部在 chat-pipeline 深模块内。
8
+ */
9
+ export function createChatGateway(deps = {}) {
10
+ const pipeline = createChatPipeline(deps);
11
+
12
+ async function handle({ req, res }) {
13
+ let body;
14
+ try {
15
+ body = await readBody(req);
16
+ } catch {
17
+ return json(res, 400, { error: "Invalid JSON body" });
18
+ }
19
+ if (deps.plugins?.length) {
20
+ const rc = await runHook(deps.plugins, "request:received", {
21
+ ip: clientIp(req),
22
+ hops: parseHops(req.headers["x-mslxdff-hops"]),
23
+ headers: { "content-type": req.headers["content-type"] },
24
+ body,
25
+ });
26
+ for (const e of rc.errors) deps.logs?.appendEvent?.({ ts: Date.now(), type: "plugin-hook-error", hook: "request:received", plugin: e.plugin, error: e.error });
27
+ const respond = rc.value?.respond;
28
+ if (respond && typeof respond === "object") return json(res, respond.status || 200, respond.body ?? {});
29
+ }
30
+ req.body = body;
31
+ try {
32
+ await pipeline.execute({ req, res });
33
+ } catch (err) {
34
+ const msg = err?.message || String(err);
35
+ if (!res.headersSent) return json(res, 502, { error: msg });
36
+ try { res.end(); } catch {}
37
+ }
38
+ }
39
+
40
+ return { handle };
41
+ }
42
+
43
+ // 薄适配:保持原 chatHandler 签名兼容
44
+ export async function chatHandler(ctx) {
45
+ const gw = createChatGateway(ctx);
46
+ return gw.handle(ctx);
47
47
  }
@@ -22,6 +22,7 @@ export async function handleHedge({
22
22
  logError,
23
23
  mark,
24
24
  perf0,
25
+ attemptStartMs,
25
26
  stages,
26
27
  startedAt,
27
28
  plugins,
@@ -62,6 +63,7 @@ export async function handleHedge({
62
63
  handlerCtx,
63
64
  mark,
64
65
  perf0,
66
+ attemptStartMs,
65
67
  stages,
66
68
  startedAt,
67
69
  });
@@ -100,6 +102,7 @@ export async function handleHedge({
100
102
  handlerCtx: { ...handlerCtx, model: win.target },
101
103
  mark: (n) => mark(n),
102
104
  perf0,
105
+ attemptStartMs,
103
106
  stages,
104
107
  startedAt,
105
108
  });
@@ -20,6 +20,7 @@ export async function handleLocalRelay({
20
20
  logError,
21
21
  mark,
22
22
  perf0,
23
+ attemptStartMs,
23
24
  stages,
24
25
  startedAt,
25
26
  plugins,
@@ -51,6 +52,7 @@ export async function handleLocalRelay({
51
52
  handlerCtx,
52
53
  mark,
53
54
  perf0,
55
+ attemptStartMs,
54
56
  stages,
55
57
  startedAt,
56
58
  });
@@ -18,6 +18,7 @@ export async function handlePeerRelay({
18
18
  logCall,
19
19
  mark,
20
20
  perf0,
21
+ attemptStartMs,
21
22
  stages,
22
23
  startedAt,
23
24
  plugins,
@@ -70,6 +71,7 @@ export async function handlePeerRelay({
70
71
  handlerCtx: { ...handlerCtx, model: win.target },
71
72
  mark,
72
73
  perf0,
74
+ attemptStartMs,
73
75
  stages,
74
76
  startedAt,
75
77
  });