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.
- package/bin/mslxdff.js +4 -4
- package/package.json +1 -1
- 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/auto-race.js +1 -1
- package/src/chat-pipeline/index.js +123 -123
- package/src/chat-pipeline/policy.js +76 -76
- package/src/chat-pipeline/serial-trial.js +210 -210
- 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 +124 -124
- package/src/cli/commands/provider/models.js +139 -139
- package/src/cli/commands/provider/qwenwork-login.js +119 -119
- package/src/cli/commands/stats.js +20 -5
- package/src/cli/commands/sync.js +232 -232
- package/src/cli/provider-row.js +2 -2
- package/src/cli/status.js +279 -279
- package/src/daemon.js +96 -96
- 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/cline/auth.js +228 -228
- package/src/providers/cline/chat.js +307 -307
- package/src/providers/cline.js +2 -2
- package/src/providers/keyring.js +60 -60
- package/src/providers/qoder/chat.js +183 -183
- package/src/providers/qoder/index.js +230 -230
- package/src/providers/qoder/sse.js +103 -103
- 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 +142 -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/registry.js +66 -66
- package/src/providers/workbuddy/chat.js +248 -248
- package/src/providers/workbuddy/reshape.js +152 -152
- package/src/providers/workbuddy.js +2 -2
- package/src/providers/zcode/chat.js +11 -10
- package/src/providers/zcode/const.js +1 -1
- package/src/providers/zcode/context-shape.js +162 -0
- package/src/providers/zcode/headers.js +38 -0
- package/src/reasoning.js +32 -32
- package/src/routes/chat/broadband-handler.js +3 -2
- package/src/routes/chat/gateway.js +46 -46
- package/src/routes/chat/hedge-handler.js +3 -0
- package/src/routes/chat/local-handler.js +2 -0
- package/src/routes/chat/peer-handler.js +2 -0
- package/src/routes/chat/relay-pipeline.js +264 -250
- package/src/routes/chat/via-route-handler.js +146 -144
- package/src/routes/hedge.js +255 -255
- package/src/routes/models-route.js +167 -167
- package/src/routes/peers.js +273 -273
- package/src/routes/stream-scan.js +86 -0
- package/src/routes/stream.js +393 -438
- package/src/runtime/bootstrap.js +45 -45
- package/src/runtime/provider-gate.js +33 -33
- package/src/runtime/providers-setup.js +165 -165
- package/src/server.js +64 -64
- package/src/state/schemas/allowlist.js +92 -92
- package/src/sync-opencode.js +280 -280
- 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-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.js +289 -289
- package/src/usage/record.js +8 -1
- package/src/usage/report.js +39 -2
- package/docs/cli_help_mini.md +0 -133
|
@@ -1,152 +1,152 @@
|
|
|
1
|
-
// workbuddy 流式 reasoning_content 整形:上游思考模型(如 glm-5.3-flash)把思考过程一词一 chunk
|
|
2
|
-
// 地放进 delta.reasoning_content,客户端会把每个增量渲染成独立 "- Thought" 条目。
|
|
3
|
-
// 旧版:连续 reasoning 增量缓冲到首个 content/finish 才一次性 flush → 思考期 10~30s 界面完全无变化(用户看到 workbuddy 后台流量走但 opencode 界面卡住)
|
|
4
|
-
// 新版:增量聚合 + 阈值分片:缓冲 reasoning,达到 REASONING_CHUNK_SIZE(默认 100 字符)即分片 flush,
|
|
5
|
-
// 期间仅首个 role 帧透传保持 TTFB,其余纯 reasoning 空帧吞掉(之前会透传 800+ 空 role 帧);
|
|
6
|
-
// 尾段不足阈值的在 content/finish/流结束时兜底 flush。恒空 reasoning(deepseek-v4-flash)零改写。
|
|
7
|
-
// 仅包 workbuddy 出口的 SSE 响应,不影响其他供应商与全局聚合器。
|
|
8
|
-
|
|
9
|
-
const REASONING_CHUNK_SIZE = 150;
|
|
10
|
-
|
|
11
|
-
export function reshapeWorkbuddySse(res) {
|
|
12
|
-
try {
|
|
13
|
-
const ct = res.headers?.get?.("content-type") || "";
|
|
14
|
-
if (res.status !== 200 || !ct.includes("text/event-stream") || !res.body) return res;
|
|
15
|
-
} catch { return res; }
|
|
16
|
-
|
|
17
|
-
const reader = res.body.getReader();
|
|
18
|
-
const decoder = new TextDecoder();
|
|
19
|
-
const encoder = new TextEncoder();
|
|
20
|
-
let buf = "";
|
|
21
|
-
let reasoningBuf = "";
|
|
22
|
-
let lastMeta = null;
|
|
23
|
-
let closed = false;
|
|
24
|
-
let hasSentRole = false;
|
|
25
|
-
let lastFlushAt = Date.now();
|
|
26
|
-
|
|
27
|
-
function flushReasoningInto(out) {
|
|
28
|
-
if (!reasoningBuf) return;
|
|
29
|
-
const meta = lastMeta || {};
|
|
30
|
-
out.push(`data: ${JSON.stringify({
|
|
31
|
-
id: meta.id || "chatcmpl-workbuddy-reshape",
|
|
32
|
-
object: meta.object || "chat.completion.chunk",
|
|
33
|
-
created: meta.created || Math.floor(Date.now() / 1000),
|
|
34
|
-
model: meta.model || "",
|
|
35
|
-
choices: [{ index: 0, delta: { reasoning_content: reasoningBuf }, finish_reason: null }],
|
|
36
|
-
})}\n\n`);
|
|
37
|
-
reasoningBuf = "";
|
|
38
|
-
lastFlushAt = Date.now();
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
let blankStreak = false;
|
|
42
|
-
// 处理一段完整行文本(以 \n 结尾),产出的行/帧推进 out(连续空行合并为单个事件分隔)
|
|
43
|
-
function processInto(text, out) {
|
|
44
|
-
for (const line of text.split("\n")) {
|
|
45
|
-
if (!line) { if (!blankStreak) out.push("\n"); blankStreak = true; continue; }
|
|
46
|
-
blankStreak = false;
|
|
47
|
-
if (!line.startsWith("data:")) { out.push(line + "\n"); continue; }
|
|
48
|
-
const payload = line.slice(5).trim();
|
|
49
|
-
if (!payload || payload === "[DONE]") { out.push(line + "\n"); continue; }
|
|
50
|
-
let obj;
|
|
51
|
-
try { obj = JSON.parse(payload); } catch { out.push(line + "\n"); continue; }
|
|
52
|
-
const ch = obj.choices?.[0];
|
|
53
|
-
if (ch && typeof ch === "object") {
|
|
54
|
-
if (obj.id) lastMeta = { id: obj.id, model: obj.model, object: obj.object, created: obj.created };
|
|
55
|
-
const d = ch.delta && typeof ch.delta === "object" ? ch.delta : null;
|
|
56
|
-
const rc = d ? d.reasoning_content : undefined;
|
|
57
|
-
if (typeof rc === "string" && rc) {
|
|
58
|
-
reasoningBuf += rc;
|
|
59
|
-
d.reasoning_content = "";
|
|
60
|
-
const isBoundary = (typeof d.content === "string" && d.content) || !!ch.finish_reason;
|
|
61
|
-
// 首个 reasoning 帧的 role 透传一次,保 TTFB;后续纯 reasoning 的 role 重复帧直接吞掉
|
|
62
|
-
if (!hasSentRole && d.role !== undefined) {
|
|
63
|
-
hasSentRole = true;
|
|
64
|
-
const rm = lastMeta || obj;
|
|
65
|
-
out.push(`data: ${JSON.stringify({
|
|
66
|
-
id: rm.id || obj.id || "chatcmpl-workbuddy-reshape",
|
|
67
|
-
object: rm.object || obj.object || "chat.completion.chunk",
|
|
68
|
-
created: rm.created || obj.created || Math.floor(Date.now() / 1000),
|
|
69
|
-
model: rm.model || obj.model || "",
|
|
70
|
-
choices: [{ index: 0, delta: { role: d.role }, finish_reason: null }],
|
|
71
|
-
})}\n\n`);
|
|
72
|
-
} else if (d.role !== undefined) {
|
|
73
|
-
// 后续重复 role 帧不再透传,避免 800+ 空帧洪泛
|
|
74
|
-
// 标记已发送过,避免后续非 reasoning 帧再误判为首次
|
|
75
|
-
hasSentRole = true;
|
|
76
|
-
}
|
|
77
|
-
// 阈值分片:攒够 100 字符即向前吐一块,期间界面可见增量而非全程静默
|
|
78
|
-
// 时间阈值:若距上次 flush 已超 700ms 且已攒 20+ 字符,也吐一块(避免小尾巴长时间不更新)
|
|
79
|
-
const now = Date.now();
|
|
80
|
-
const shouldChunk = reasoningBuf.length >= REASONING_CHUNK_SIZE
|
|
81
|
-
|| (reasoningBuf.length >= 50 && now - lastFlushAt > 1500);
|
|
82
|
-
if (shouldChunk) flushReasoningInto(out);
|
|
83
|
-
if (isBoundary) {
|
|
84
|
-
// 兜底:content/finish 前把剩余思考一次性吐出,再透传本帧
|
|
85
|
-
flushReasoningInto(out);
|
|
86
|
-
const hasPassthrough = isBoundary || (Array.isArray(d.tool_calls) && d.tool_calls.length);
|
|
87
|
-
if (hasPassthrough) out.push(`data: ${JSON.stringify(obj)}\n\n`);
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
// 纯 reasoning 碎片帧已缓冲/或已分片吐出,原空帧吞掉
|
|
91
|
-
continue;
|
|
92
|
-
}
|
|
93
|
-
// 非 reasoning 帧:若有 content/finish 先兜底 flush
|
|
94
|
-
if ((typeof d?.content === "string" && d.content) || ch.finish_reason) flushReasoningInto(out);
|
|
95
|
-
if (!hasSentRole && d?.role !== undefined) {
|
|
96
|
-
hasSentRole = true;
|
|
97
|
-
} else if (hasSentRole && d?.role !== undefined) {
|
|
98
|
-
// 去重:首个 role 后续重复 role 去掉,避免下游每帧都带 role
|
|
99
|
-
try { const clone = JSON.parse(payload); delete clone.choices[0].delta.role; out.push(`data: ${JSON.stringify(clone)}\n\n`); continue; } catch { /* fallback透传 */ }
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
out.push(line + "\n");
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const body = new ReadableStream({
|
|
107
|
-
async pull(controller) {
|
|
108
|
-
if (closed) { try { controller.close(); } catch {} return; }
|
|
109
|
-
try {
|
|
110
|
-
// 循环读源,直到"有输出 / 流结束 / 出错"才返回。
|
|
111
|
-
// WHATWG 流规范:pull 的 promise 解析后若未 enqueue,规范不会再自动调度 pull
|
|
112
|
-
// (仅当解析期间有新读请求触发 pullAgain 才重调)——消费者只挂一个待处理 read 时,
|
|
113
|
-
// 任何一次"只吞帧不出数据"的拉取都会让整流永久停摆。workbuddy 思考流按帧到达
|
|
114
|
-
// (role 帧后每个 reasoning 碎片都不足 150 字符阈值)时必现,即"首帧后卡死"根因。
|
|
115
|
-
for (;;) {
|
|
116
|
-
const { done, value } = await reader.read();
|
|
117
|
-
if (done) {
|
|
118
|
-
closed = true;
|
|
119
|
-
const out = [];
|
|
120
|
-
if (buf) { processInto(buf + "\n", out); buf = ""; }
|
|
121
|
-
flushReasoningInto(out);
|
|
122
|
-
if (out.length) controller.enqueue(encoder.encode(out.join("")));
|
|
123
|
-
controller.close();
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
buf += decoder.decode(value, { stream: true });
|
|
127
|
-
const idx = buf.lastIndexOf("\n");
|
|
128
|
-
if (idx < 0) continue;
|
|
129
|
-
const complete = buf.slice(0, idx + 1);
|
|
130
|
-
buf = buf.slice(idx + 1);
|
|
131
|
-
const out = [];
|
|
132
|
-
processInto(complete, out);
|
|
133
|
-
if (out.length) { controller.enqueue(encoder.encode(out.join(""))); return; }
|
|
134
|
-
}
|
|
135
|
-
} catch {
|
|
136
|
-
closed = true;
|
|
137
|
-
try { controller.close(); } catch {}
|
|
138
|
-
}
|
|
139
|
-
},
|
|
140
|
-
cancel() {
|
|
141
|
-
closed = true;
|
|
142
|
-
try {
|
|
143
|
-
const p = reader.cancel();
|
|
144
|
-
if (p && typeof p.catch === "function") p.catch(() => {});
|
|
145
|
-
} catch {}
|
|
146
|
-
},
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
const out = new Response(body, { status: res.status, statusText: res.statusText, headers: res.headers });
|
|
150
|
-
try { out._t = res._t; } catch {}
|
|
151
|
-
return out;
|
|
152
|
-
}
|
|
1
|
+
// workbuddy 流式 reasoning_content 整形:上游思考模型(如 glm-5.3-flash)把思考过程一词一 chunk
|
|
2
|
+
// 地放进 delta.reasoning_content,客户端会把每个增量渲染成独立 "- Thought" 条目。
|
|
3
|
+
// 旧版:连续 reasoning 增量缓冲到首个 content/finish 才一次性 flush → 思考期 10~30s 界面完全无变化(用户看到 workbuddy 后台流量走但 opencode 界面卡住)
|
|
4
|
+
// 新版:增量聚合 + 阈值分片:缓冲 reasoning,达到 REASONING_CHUNK_SIZE(默认 100 字符)即分片 flush,
|
|
5
|
+
// 期间仅首个 role 帧透传保持 TTFB,其余纯 reasoning 空帧吞掉(之前会透传 800+ 空 role 帧);
|
|
6
|
+
// 尾段不足阈值的在 content/finish/流结束时兜底 flush。恒空 reasoning(deepseek-v4-flash)零改写。
|
|
7
|
+
// 仅包 workbuddy 出口的 SSE 响应,不影响其他供应商与全局聚合器。
|
|
8
|
+
|
|
9
|
+
const REASONING_CHUNK_SIZE = 150;
|
|
10
|
+
|
|
11
|
+
export function reshapeWorkbuddySse(res) {
|
|
12
|
+
try {
|
|
13
|
+
const ct = res.headers?.get?.("content-type") || "";
|
|
14
|
+
if (res.status !== 200 || !ct.includes("text/event-stream") || !res.body) return res;
|
|
15
|
+
} catch { return res; }
|
|
16
|
+
|
|
17
|
+
const reader = res.body.getReader();
|
|
18
|
+
const decoder = new TextDecoder();
|
|
19
|
+
const encoder = new TextEncoder();
|
|
20
|
+
let buf = "";
|
|
21
|
+
let reasoningBuf = "";
|
|
22
|
+
let lastMeta = null;
|
|
23
|
+
let closed = false;
|
|
24
|
+
let hasSentRole = false;
|
|
25
|
+
let lastFlushAt = Date.now();
|
|
26
|
+
|
|
27
|
+
function flushReasoningInto(out) {
|
|
28
|
+
if (!reasoningBuf) return;
|
|
29
|
+
const meta = lastMeta || {};
|
|
30
|
+
out.push(`data: ${JSON.stringify({
|
|
31
|
+
id: meta.id || "chatcmpl-workbuddy-reshape",
|
|
32
|
+
object: meta.object || "chat.completion.chunk",
|
|
33
|
+
created: meta.created || Math.floor(Date.now() / 1000),
|
|
34
|
+
model: meta.model || "",
|
|
35
|
+
choices: [{ index: 0, delta: { reasoning_content: reasoningBuf }, finish_reason: null }],
|
|
36
|
+
})}\n\n`);
|
|
37
|
+
reasoningBuf = "";
|
|
38
|
+
lastFlushAt = Date.now();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
let blankStreak = false;
|
|
42
|
+
// 处理一段完整行文本(以 \n 结尾),产出的行/帧推进 out(连续空行合并为单个事件分隔)
|
|
43
|
+
function processInto(text, out) {
|
|
44
|
+
for (const line of text.split("\n")) {
|
|
45
|
+
if (!line) { if (!blankStreak) out.push("\n"); blankStreak = true; continue; }
|
|
46
|
+
blankStreak = false;
|
|
47
|
+
if (!line.startsWith("data:")) { out.push(line + "\n"); continue; }
|
|
48
|
+
const payload = line.slice(5).trim();
|
|
49
|
+
if (!payload || payload === "[DONE]") { out.push(line + "\n"); continue; }
|
|
50
|
+
let obj;
|
|
51
|
+
try { obj = JSON.parse(payload); } catch { out.push(line + "\n"); continue; }
|
|
52
|
+
const ch = obj.choices?.[0];
|
|
53
|
+
if (ch && typeof ch === "object") {
|
|
54
|
+
if (obj.id) lastMeta = { id: obj.id, model: obj.model, object: obj.object, created: obj.created };
|
|
55
|
+
const d = ch.delta && typeof ch.delta === "object" ? ch.delta : null;
|
|
56
|
+
const rc = d ? d.reasoning_content : undefined;
|
|
57
|
+
if (typeof rc === "string" && rc) {
|
|
58
|
+
reasoningBuf += rc;
|
|
59
|
+
d.reasoning_content = "";
|
|
60
|
+
const isBoundary = (typeof d.content === "string" && d.content) || !!ch.finish_reason;
|
|
61
|
+
// 首个 reasoning 帧的 role 透传一次,保 TTFB;后续纯 reasoning 的 role 重复帧直接吞掉
|
|
62
|
+
if (!hasSentRole && d.role !== undefined) {
|
|
63
|
+
hasSentRole = true;
|
|
64
|
+
const rm = lastMeta || obj;
|
|
65
|
+
out.push(`data: ${JSON.stringify({
|
|
66
|
+
id: rm.id || obj.id || "chatcmpl-workbuddy-reshape",
|
|
67
|
+
object: rm.object || obj.object || "chat.completion.chunk",
|
|
68
|
+
created: rm.created || obj.created || Math.floor(Date.now() / 1000),
|
|
69
|
+
model: rm.model || obj.model || "",
|
|
70
|
+
choices: [{ index: 0, delta: { role: d.role }, finish_reason: null }],
|
|
71
|
+
})}\n\n`);
|
|
72
|
+
} else if (d.role !== undefined) {
|
|
73
|
+
// 后续重复 role 帧不再透传,避免 800+ 空帧洪泛
|
|
74
|
+
// 标记已发送过,避免后续非 reasoning 帧再误判为首次
|
|
75
|
+
hasSentRole = true;
|
|
76
|
+
}
|
|
77
|
+
// 阈值分片:攒够 100 字符即向前吐一块,期间界面可见增量而非全程静默
|
|
78
|
+
// 时间阈值:若距上次 flush 已超 700ms 且已攒 20+ 字符,也吐一块(避免小尾巴长时间不更新)
|
|
79
|
+
const now = Date.now();
|
|
80
|
+
const shouldChunk = reasoningBuf.length >= REASONING_CHUNK_SIZE
|
|
81
|
+
|| (reasoningBuf.length >= 50 && now - lastFlushAt > 1500);
|
|
82
|
+
if (shouldChunk) flushReasoningInto(out);
|
|
83
|
+
if (isBoundary) {
|
|
84
|
+
// 兜底:content/finish 前把剩余思考一次性吐出,再透传本帧
|
|
85
|
+
flushReasoningInto(out);
|
|
86
|
+
const hasPassthrough = isBoundary || (Array.isArray(d.tool_calls) && d.tool_calls.length);
|
|
87
|
+
if (hasPassthrough) out.push(`data: ${JSON.stringify(obj)}\n\n`);
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
// 纯 reasoning 碎片帧已缓冲/或已分片吐出,原空帧吞掉
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
// 非 reasoning 帧:若有 content/finish 先兜底 flush
|
|
94
|
+
if ((typeof d?.content === "string" && d.content) || ch.finish_reason) flushReasoningInto(out);
|
|
95
|
+
if (!hasSentRole && d?.role !== undefined) {
|
|
96
|
+
hasSentRole = true;
|
|
97
|
+
} else if (hasSentRole && d?.role !== undefined) {
|
|
98
|
+
// 去重:首个 role 后续重复 role 去掉,避免下游每帧都带 role
|
|
99
|
+
try { const clone = JSON.parse(payload); delete clone.choices[0].delta.role; out.push(`data: ${JSON.stringify(clone)}\n\n`); continue; } catch { /* fallback透传 */ }
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
out.push(line + "\n");
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const body = new ReadableStream({
|
|
107
|
+
async pull(controller) {
|
|
108
|
+
if (closed) { try { controller.close(); } catch {} return; }
|
|
109
|
+
try {
|
|
110
|
+
// 循环读源,直到"有输出 / 流结束 / 出错"才返回。
|
|
111
|
+
// WHATWG 流规范:pull 的 promise 解析后若未 enqueue,规范不会再自动调度 pull
|
|
112
|
+
// (仅当解析期间有新读请求触发 pullAgain 才重调)——消费者只挂一个待处理 read 时,
|
|
113
|
+
// 任何一次"只吞帧不出数据"的拉取都会让整流永久停摆。workbuddy 思考流按帧到达
|
|
114
|
+
// (role 帧后每个 reasoning 碎片都不足 150 字符阈值)时必现,即"首帧后卡死"根因。
|
|
115
|
+
for (;;) {
|
|
116
|
+
const { done, value } = await reader.read();
|
|
117
|
+
if (done) {
|
|
118
|
+
closed = true;
|
|
119
|
+
const out = [];
|
|
120
|
+
if (buf) { processInto(buf + "\n", out); buf = ""; }
|
|
121
|
+
flushReasoningInto(out);
|
|
122
|
+
if (out.length) controller.enqueue(encoder.encode(out.join("")));
|
|
123
|
+
controller.close();
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
buf += decoder.decode(value, { stream: true });
|
|
127
|
+
const idx = buf.lastIndexOf("\n");
|
|
128
|
+
if (idx < 0) continue;
|
|
129
|
+
const complete = buf.slice(0, idx + 1);
|
|
130
|
+
buf = buf.slice(idx + 1);
|
|
131
|
+
const out = [];
|
|
132
|
+
processInto(complete, out);
|
|
133
|
+
if (out.length) { controller.enqueue(encoder.encode(out.join(""))); return; }
|
|
134
|
+
}
|
|
135
|
+
} catch {
|
|
136
|
+
closed = true;
|
|
137
|
+
try { controller.close(); } catch {}
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
cancel() {
|
|
141
|
+
closed = true;
|
|
142
|
+
try {
|
|
143
|
+
const p = reader.cancel();
|
|
144
|
+
if (p && typeof p.catch === "function") p.catch(() => {});
|
|
145
|
+
} catch {}
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
const out = new Response(body, { status: res.status, statusText: res.statusText, headers: res.headers });
|
|
150
|
+
try { out._t = res._t; } catch {}
|
|
151
|
+
return out;
|
|
152
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
// Shim — 保持历史导入路径兼容,真实实现下沉至 ./workbuddy/ 深模块
|
|
2
|
-
export * from "./workbuddy/index.js";
|
|
1
|
+
// Shim — 保持历史导入路径兼容,真实实现下沉至 ./workbuddy/ 深模块
|
|
2
|
+
export * from "./workbuddy/index.js";
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
// 失败响应带 x-mslxdff-zcode-kind 标记,供 provider 工厂决定冷却策略。
|
|
3
3
|
import { timeoutSignal } from "../../compat.js";
|
|
4
4
|
import { ZCODE_MESSAGES_URL, canonicalZcodeModel, zcodeErrorKind } from "./const.js";
|
|
5
|
-
import {
|
|
5
|
+
import { shapeZcodeWireRequest } from "./context-shape.js";
|
|
6
|
+
import { buildZcodeModelHeaders } from "./headers.js";
|
|
6
7
|
import { aggregateAnthropicToOpenAi, anthropicToOpenAiStream } from "./sse.js";
|
|
7
8
|
|
|
8
9
|
const DEFAULT_MAX_TOKENS = 4096;
|
|
@@ -97,7 +98,7 @@ const ERROR_MAP = {
|
|
|
97
98
|
auth: { status: 401, type: "auth_error", text: (f) => `zcode: 登录已失效(code ${f.code || 1006})。请运行 mslxdff -provider zcode login 重新登录` },
|
|
98
99
|
quota: { status: 429, type: "quota_exhausted", text: () => "zcode: 免费额度已用完(按日重置),请明日再试或添加账号" },
|
|
99
100
|
rate_limit: { status: 429, type: "all_cooling", text: () => "zcode: 上游限流(账号冷却中),请稍后重试" },
|
|
100
|
-
security: { status: 403, type: "security_reject", text: (f) => `zcode: 安全校验拒绝(code ${f.code || 3007})${f.message ? `:${f.message}` : ""} ·
|
|
101
|
+
security: { status: 403, type: "security_reject", text: (f) => `zcode: 安全校验拒绝(code ${f.code || 3007})${f.message ? `:${f.message}` : ""} · v3.14.4 起模型请求已免验证码(仅 claim 通道仍需要),偶发请重试,见 docs/adr/0038` },
|
|
101
102
|
param: { status: 400, type: "invalid_request", text: (f) => `zcode: 请求参数被上游拒绝(code ${f.code})${f.message ? `:${f.message}` : ""}` },
|
|
102
103
|
server: { status: 502, type: "upstream_error", text: (f) => `zcode: 上游服务异常${f.code ? `(code ${f.code})` : ""}${f.message ? `:${f.message}` : ""}` },
|
|
103
104
|
network: { status: 502, type: "upstream_error", text: (f) => `zcode: 网络错误 ${f.message || ""}`.trim() },
|
|
@@ -115,21 +116,21 @@ export function zcodeErrorResponse(fail = {}) {
|
|
|
115
116
|
});
|
|
116
117
|
}
|
|
117
118
|
|
|
118
|
-
export async function forwardZcodeChat({ body, token, deviceMid, fetchImpl, version, timeoutMs = 120_000 } = {}) {
|
|
119
|
+
export async function forwardZcodeChat({ body, token, deviceMid, fetchImpl, version, timeoutMs = 120_000, provider = "zai" } = {}) {
|
|
119
120
|
const anthropicBody = toAnthropicRequest(body);
|
|
120
|
-
const modelId = anthropicBody.model;
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
121
|
+
const modelId = anthropicBody.model; // 响应回显用 canonical id;出站另行归一
|
|
122
|
+
// 官方线形:小写模型 + system 身份块 + currentDate 前缀(缺任一 → 上游 3012)。
|
|
123
|
+
// deviceMid 入参保留签名兼容,但模型请求出站不带(官方 CLI 模型请求不带该头,实测)。
|
|
124
|
+
const wireBody = shapeZcodeWireRequest(anthropicBody, { provider });
|
|
125
|
+
const headers = { "content-type": "application/json", ...buildZcodeModelHeaders({ token, version }) };
|
|
126
|
+
void deviceMid;
|
|
126
127
|
|
|
127
128
|
let res;
|
|
128
129
|
try {
|
|
129
130
|
res = await fetchImpl(ZCODE_MESSAGES_URL, {
|
|
130
131
|
method: "POST",
|
|
131
132
|
headers,
|
|
132
|
-
body: JSON.stringify(
|
|
133
|
+
body: JSON.stringify(wireBody),
|
|
133
134
|
signal: timeoutSignal(timeoutMs),
|
|
134
135
|
});
|
|
135
136
|
} catch (e) {
|
|
@@ -8,7 +8,7 @@ export const ZCODE_MESSAGES_URL = `${ZCODE_ORIGIN}/api/v1/zcode-plan/anthropic/v
|
|
|
8
8
|
export const zcodeBalanceUrl = (appVersion) =>
|
|
9
9
|
`${ZCODE_ORIGIN}/api/v1/zcode-plan/billing/balance?app_version=${encodeURIComponent(String(appVersion || ""))}`;
|
|
10
10
|
|
|
11
|
-
export const ZCODE_DEFAULT_APP_VERSION = "3.
|
|
11
|
+
export const ZCODE_DEFAULT_APP_VERSION = "3.14.4";
|
|
12
12
|
export const ZCODE_RELEASE_CHANNEL = "stable";
|
|
13
13
|
|
|
14
14
|
export function zcodeAppVersion(env = process.env) {
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
// zcode 出站请求的「官方线形」组装:system 身份块 + 首 user 消息的 currentDate 上下文前缀。
|
|
2
|
+
// 上游 zcode-plan 通道对请求做内容检查:system 缺官方身份块 → 业务码 3012(HTTP 405)。
|
|
3
|
+
// 本文案逐段移植自官方开源仓库 zai-org/ZCode(apps/zcode-cli/packages/core/src/context/):
|
|
4
|
+
// sections/cli-prefix.ts / sections/identity.ts / dynamic-sections.ts / sections/env-info.ts /
|
|
5
|
+
// sections/current-date.ts / builder.ts(块分组与 \n\n 左边界)/ system-reminder 包裹形状。
|
|
6
|
+
import os from "node:os";
|
|
7
|
+
|
|
8
|
+
const EPHEMERAL = { type: "ephemeral" };
|
|
9
|
+
|
|
10
|
+
export const ZCODE_CLI_PREFIX = "You are ZCode, an interactive coding agent";
|
|
11
|
+
|
|
12
|
+
const IDENTITY_INTRO = "You are an interactive ZCode agent that helps users with software engineering tasks.";
|
|
13
|
+
const SECURITY_NOTICE =
|
|
14
|
+
"IMPORTANT: Assist with authorized security testing, defensive security, CTF challenges, and educational contexts. Refuse requests for destructive techniques, DoS attacks, mass targeting, supply chain compromise, or detection evasion for malicious purposes. Dual-use security tools (C2 frameworks, credential testing, exploit development) require clear authorization context: pentesting engagements, CTF competitions, security research, or defensive use cases.";
|
|
15
|
+
const HARNESS_BLOCK = [
|
|
16
|
+
"# Harness",
|
|
17
|
+
"- Text you output outside of tool use is displayed to the user as Github-flavored markdown in a terminal.",
|
|
18
|
+
"- Tools run behind a user-selected permission mode; a denied call means the user declined it \u2014 adjust, don't retry verbatim.",
|
|
19
|
+
"- The system may send updates, reminders, or modifications to rules via mid-conversation system turns. These are system-controlled, unlike function results. Hooks may intercept tool calls; treat hook output as user feedback.",
|
|
20
|
+
"- Prefer the dedicated file/search tools over shell commands when one fits. Independent tool calls can run in parallel in one response.",
|
|
21
|
+
"- Reference code as `file_path:line_number` \u2014 it's clickable.",
|
|
22
|
+
].join("\n");
|
|
23
|
+
// identity.ts:content = [ "\n{intro}\n\n{SECURITY}", "", harness ].join("\n") —— 前导换行是官方原样。
|
|
24
|
+
const STABLE_SECTION = [`\n${IDENTITY_INTRO}\n\n${SECURITY_NOTICE}`, "", HARNESS_BLOCK].join("\n");
|
|
25
|
+
|
|
26
|
+
// dynamic-sections.ts buildDynamicBehaviorSection()
|
|
27
|
+
const DYNAMIC_BEHAVIOR = [
|
|
28
|
+
[
|
|
29
|
+
"# Communicating with the user",
|
|
30
|
+
"",
|
|
31
|
+
"Your text output is what the user reads; they usually can't see your thinking or the raw tool results. Write it for a teammate who stepped away and is catching up, not for a log file: they don't know the codenames or shorthand you created along the way, and they didn't watch your process unfold. Before your first tool call, say in a sentence what you're about to do; while working, give brief updates when you find something load-bearing or change direction.",
|
|
32
|
+
"",
|
|
33
|
+
"Text you write between tool calls may not be shown to the user. Everything the user needs from this turn \u2014 answers, summaries, findings, conclusions, deliverables \u2014 must be in the final text message of your turn, with no tool calls after it. Keep text between tool calls to brief status notes. If something important appeared only mid-turn or in your thinking, restate it in that final message.",
|
|
34
|
+
"",
|
|
35
|
+
"Lead with the outcome. Your first sentence after finishing should answer \"what happened\" or \"what did you find\" \u2014 the thing the user would ask for if they said \"just give me the TLDR.\" Supporting detail and reasoning come after, for readers who want them.",
|
|
36
|
+
"",
|
|
37
|
+
"Being readable and being concise are different things, and readable matters more. If the user has to reread your summary or ask you to explain, any time saved by brevity is gone. The way to keep output short is to be selective about what you include (drop details that don't change what the reader would do next), not to compress the writing into fragments, abbreviations, arrow chains like `A \u2192 B \u2192 fails`, or jargon. What you do include, write in complete sentences with the technical terms spelled out. Don't make the reader cross-reference labels or numbering you invented earlier; say what you mean in place.",
|
|
38
|
+
"",
|
|
39
|
+
"Match the response to the question: a simple question gets a direct answer in prose, not headers and sections. Use tables only for short enumerable facts, with explanations in the surrounding prose rather than the cells. Calibrate to the user \u2014 a bit tighter for an expert, more explanatory for someone newer.",
|
|
40
|
+
].join("\n"),
|
|
41
|
+
"",
|
|
42
|
+
"Write code that reads like the surrounding code: match its comment density, naming, and idiom.",
|
|
43
|
+
"Only write a code comment to state a constraint the code itself can't show \u2014 never to say where it came from, what the next line does, or why your change is correct; that's you talking to the reviewer, not the next reader, and it's noise the moment the PR merges.",
|
|
44
|
+
"",
|
|
45
|
+
"For actions that are hard to reverse or outward-facing, confirm first unless durably authorized or explicitly told to proceed without asking; approval in one context doesn't extend to the next. Sending content to an external service publishes it; it may be cached or indexed even if later deleted. Before deleting or overwriting, look at the target \u2014 if what you find contradicts how it was described, or you didn't create it, surface that instead of proceeding. Report outcomes faithfully: if tests fail, say so with the output; if a step was skipped, say that; when something is done and verified, state it plainly without hedging.",
|
|
46
|
+
].join("\n");
|
|
47
|
+
|
|
48
|
+
// dynamic-sections.ts buildContextManagementSection()
|
|
49
|
+
const CONTEXT_MANAGEMENT = [
|
|
50
|
+
["# Context management", "When the conversation grows long, some or all of the current context is summarized; the summary, along with any remaining unsummarized context, is provided in the next context window so work can continue \u2014 you don't need to wrap up early or hand off mid-task."].join("\n"),
|
|
51
|
+
"",
|
|
52
|
+
"When you have enough information to act, act. Do not re-derive facts already established in the conversation, re-litigate a decision the user has already made, or narrate options you will not pursue. If you are weighing a choice, give a recommendation, not an exhaustive survey",
|
|
53
|
+
"",
|
|
54
|
+
"You are operating autonomously. The user is not watching in real time and cannot answer questions mid-task, so asking 'Want me to\u2026?' or 'Shall I\u2026?' will block the work. For reversible actions that follow from the original request, proceed without asking. Stop only for destructive actions or genuine scope changes the user must decide. Offering follow-ups after the task is done is fine; asking permission before doing the work is not.",
|
|
55
|
+
"",
|
|
56
|
+
"Exception: when the user is describing a problem, asking a question, or thinking out loud rather than requesting a change, the deliverable is your assessment. Report your findings and stop. Don't apply a fix until they ask for one.",
|
|
57
|
+
"",
|
|
58
|
+
"Before ending your turn, check your last paragraph. If it is a plan, an analysis, a question, a list of next steps, or a promise about work you have not done ('I'll\u2026', 'let me know when\u2026'), do that work now with tool calls. That includes retrying after errors and gathering missing information yourself. Do not stop because the context or session is long. End your turn only when the task is complete or you are blocked on input only the user can provide.",
|
|
59
|
+
"",
|
|
60
|
+
"Before running a command that changes system state \u2014 restarts, deletes, config edits \u2014 check that the evidence actually supports that specific action. A signal that pattern-matches to a known failure may have a different cause.",
|
|
61
|
+
].join("\n");
|
|
62
|
+
|
|
63
|
+
// builder.ts buildContextMetaUserBody() 的 intro/outro(current-date.ts 的正文夹在中间)
|
|
64
|
+
const CONTEXT_INTRO = "As you answer the user's questions, you can use the following context:";
|
|
65
|
+
const CONTEXT_OUTRO = " IMPORTANT: this context may or may not be relevant to your tasks. You should not respond to this context unless it is highly relevant to your task.";
|
|
66
|
+
const REMINDER_OPEN = "<system-reminder>";
|
|
67
|
+
const REMINDER_CLOSE = "</system-reminder>";
|
|
68
|
+
|
|
69
|
+
function localIsoDate(d = new Date()) {
|
|
70
|
+
const p = (n) => String(n).padStart(2, "0");
|
|
71
|
+
return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())}`;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function normalizeCallerSystem(system) {
|
|
75
|
+
const out = [];
|
|
76
|
+
if (typeof system === "string") {
|
|
77
|
+
if (system.trim()) out.push({ type: "text", text: system });
|
|
78
|
+
} else if (Array.isArray(system)) {
|
|
79
|
+
for (const item of system) {
|
|
80
|
+
if (typeof item === "string") {
|
|
81
|
+
if (item.trim()) out.push({ type: "text", text: item });
|
|
82
|
+
} else if (item && typeof item === "object" && item.type === "text" && typeof item.text === "string" && item.text.trim()) {
|
|
83
|
+
out.push({ type: "text", text: item.text });
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return out;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// env-info.ts buildEnvInfoContent():CLI 无 git 上下文的固定形态
|
|
91
|
+
function buildEnvironmentSection({ cwd, model, provider, platform, shell, osVersion }) {
|
|
92
|
+
const lines = [
|
|
93
|
+
"# Environment",
|
|
94
|
+
"You have been invoked in the following environment:",
|
|
95
|
+
`- Primary working directory: ${cwd}`,
|
|
96
|
+
"- Is a git repository: no",
|
|
97
|
+
`- Platform: ${platform}`,
|
|
98
|
+
`- Shell: ${shell}`,
|
|
99
|
+
`- OS Version: ${osVersion}`,
|
|
100
|
+
];
|
|
101
|
+
if (model) lines.push(`- You are powered by the model named ${provider}-api/${model}.`);
|
|
102
|
+
return lines.join("\n");
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* 官方式 system 块数组:cliPrefix / stable / dynamic(\n\n 左边界)三块均带 ephemeral,
|
|
107
|
+
* 调用方原 system 追加在末尾(不进官方缓存块)。
|
|
108
|
+
*/
|
|
109
|
+
export function buildZcodeSystemBlocks({ system, model, provider = "zai", cwd = process.cwd(), now = new Date(), platform, shell, osVersion } = {}) {
|
|
110
|
+
const env = buildEnvironmentSection({
|
|
111
|
+
cwd,
|
|
112
|
+
model,
|
|
113
|
+
provider,
|
|
114
|
+
platform: platform || process.platform,
|
|
115
|
+
shell: shell || (process.platform === "win32" ? "cmd" : (process.env.SHELL || "sh")),
|
|
116
|
+
osVersion: osVersion || os.release(),
|
|
117
|
+
});
|
|
118
|
+
const dynamic = [DYNAMIC_BEHAVIOR, env, CONTEXT_MANAGEMENT].join("\n\n");
|
|
119
|
+
const official = [
|
|
120
|
+
{ type: "text", text: ZCODE_CLI_PREFIX, cache_control: { ...EPHEMERAL } },
|
|
121
|
+
{ type: "text", text: STABLE_SECTION, cache_control: { ...EPHEMERAL } },
|
|
122
|
+
// builder.ts:270-271:Main Agent 的 dynamic system block 自带 \n\n 左边界
|
|
123
|
+
{ type: "text", text: `\n\n${dynamic}`, cache_control: { ...EPHEMERAL } },
|
|
124
|
+
];
|
|
125
|
+
return [...official, ...normalizeCallerSystem(system)];
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** 首 user 消息的 currentDate 上下文块(builder.ts meta_user → system-reminder 包裹)。 */
|
|
129
|
+
export function buildZcodeContextPrefixBlock(now = new Date()) {
|
|
130
|
+
const body = [
|
|
131
|
+
CONTEXT_INTRO,
|
|
132
|
+
`# currentDate\nToday's date is ${localIsoDate(now)}.`,
|
|
133
|
+
"",
|
|
134
|
+
CONTEXT_OUTRO,
|
|
135
|
+
].join("\n");
|
|
136
|
+
return { type: "text", text: `${REMINDER_OPEN}\n${body}\n${REMINDER_CLOSE}` };
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** 把上下文前缀挂到首个 user 消息 content 最前(字符串 content 升格为块数组;已挂则不动)。 */
|
|
140
|
+
export function attachZcodeContextPrefix(messages, now = new Date()) {
|
|
141
|
+
if (!Array.isArray(messages) || messages.length === 0) return messages;
|
|
142
|
+
const first = messages[0];
|
|
143
|
+
if (!first || first.role !== "user") return messages;
|
|
144
|
+
const content = Array.isArray(first.content)
|
|
145
|
+
? first.content
|
|
146
|
+
: [{ type: "text", text: String(first.content ?? "") }];
|
|
147
|
+
if (content.some((c) => c?.type === "text" && typeof c.text === "string" && c.text.startsWith(REMINDER_OPEN))) {
|
|
148
|
+
return messages;
|
|
149
|
+
}
|
|
150
|
+
return [{ ...first, content: [buildZcodeContextPrefixBlock(now), ...content] }, ...messages.slice(1)];
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** 内部 Anthropic 请求 → 官方出站线形:小写模型名 + 身份 system 块 + currentDate 前缀,其余透传。 */
|
|
154
|
+
export function shapeZcodeWireRequest(req = {}, { cwd, provider = "zai", now = new Date() } = {}) {
|
|
155
|
+
const model = typeof req.model === "string" ? req.model.toLowerCase() : req.model;
|
|
156
|
+
return {
|
|
157
|
+
...req,
|
|
158
|
+
model,
|
|
159
|
+
system: buildZcodeSystemBlocks({ system: req.system, model, provider, cwd, now }),
|
|
160
|
+
messages: attachZcodeContextPrefix(req.messages, now),
|
|
161
|
+
};
|
|
162
|
+
}
|
|
@@ -53,3 +53,41 @@ export function buildZcodeHeaders(opts = {}) {
|
|
|
53
53
|
if (token) headers["Authorization"] = `Bearer ${token}`;
|
|
54
54
|
return headers;
|
|
55
55
|
}
|
|
56
|
+
|
|
57
|
+
// 模型请求专用形态(zcode-plan 通道):与官方 CLI 出站同形 —— 双鉴权头、ai-sdk UA、
|
|
58
|
+
// x-title=cli、production 渠道、anthropic-version、gzip;**不带** X-Device-Mid,
|
|
59
|
+
// **不带** 验证码头(v3.14.4 起模型请求免校验,client/configs captcha.skip_model_request=true)。
|
|
60
|
+
export function buildZcodeModelHeaders(opts = {}) {
|
|
61
|
+
const ver = normalizeHeaderValue(opts.version) ?? zcodeAppVersion();
|
|
62
|
+
const platform = normalizeHeaderValue(opts.platform) ?? process.platform;
|
|
63
|
+
const arch = normalizeHeaderValue(opts.arch) ?? process.arch;
|
|
64
|
+
const intl = (() => { try { return Intl.DateTimeFormat().resolvedOptions() || {}; } catch { return {}; } })();
|
|
65
|
+
const language = normalizeHeaderValue(opts.lang) ?? normalizeHeaderValue(intl.locale) ?? "unknown";
|
|
66
|
+
const timeZone = normalizeHeaderValue(opts.tz) ?? normalizeHeaderValue(intl.timeZone) ?? "unknown";
|
|
67
|
+
const osVersion = "osVersion" in opts ? normalizeHeaderValue(opts.osVersion) : normalizeHeaderValue(os.release());
|
|
68
|
+
const token = normalizeHeaderValue(opts.token);
|
|
69
|
+
const headers = {
|
|
70
|
+
"accept-encoding": "gzip",
|
|
71
|
+
"anthropic-version": "2023-06-01",
|
|
72
|
+
"authorization": token ? `Bearer ${token}` : undefined,
|
|
73
|
+
"http-referer": ZCODE_ORIGIN,
|
|
74
|
+
"user-agent": `ZCode/${ver} ai-sdk/anthropic/3.0.81`,
|
|
75
|
+
"x-api-key": token,
|
|
76
|
+
"x-client-language": language,
|
|
77
|
+
"x-client-timezone": timeZone,
|
|
78
|
+
"x-os-category": osCategory(platform),
|
|
79
|
+
"x-platform": `${platform}-${arch}`,
|
|
80
|
+
"x-release-channel": "production",
|
|
81
|
+
"x-request-id": normalizeHeaderValue(opts.requestId) ?? uuid(),
|
|
82
|
+
"x-title": "Z Code@cli",
|
|
83
|
+
"x-zcode-agent": "glm",
|
|
84
|
+
"x-zcode-app-version": ver,
|
|
85
|
+
"x-zcode-session-type": "main",
|
|
86
|
+
"x-zcode-trace-id": normalizeHeaderValue(opts.traceId) ?? uuid(),
|
|
87
|
+
};
|
|
88
|
+
if (osVersion) headers["x-os-version"] = osVersion;
|
|
89
|
+
for (const k of Object.keys(headers)) {
|
|
90
|
+
if (headers[k] === undefined) delete headers[k];
|
|
91
|
+
}
|
|
92
|
+
return headers;
|
|
93
|
+
}
|