mslxdff 0.1.162 → 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.
- package/package.json +1 -1
- package/src/chat-pipeline/index.js +3 -2
- package/src/cli/commands/stats.js +21 -9
- package/src/cli/help.js +1 -1
- package/src/providers/globalworkbuddy/account-store.js +198 -0
- package/src/providers/globalworkbuddy/auth.js +97 -0
- package/src/providers/globalworkbuddy/catalog.js +138 -0
- package/src/providers/globalworkbuddy/constants.js +73 -0
- package/src/providers/globalworkbuddy/device-auth.js +120 -0
- package/src/providers/globalworkbuddy/errors.js +98 -0
- package/src/providers/globalworkbuddy/headers.js +89 -0
- package/src/providers/globalworkbuddy/models.js +96 -0
- package/src/providers/globalworkbuddy/payload.js +80 -0
- package/src/providers/qoder/aggregate.js +12 -3
- package/src/providers/qoder/chat.js +9 -2
- package/src/providers/qoder/index.js +13 -3
- package/src/providers/qoder/models.js +7 -3
- package/src/providers/qoder/payload.js +7 -1
- package/src/providers/qoder/request.js +2 -1
- package/src/providers/qoder/sse.js +5 -1
- package/src/providers/qoder/stream.js +16 -4
- package/src/routes/chat/exhausted-handler.js +13 -2
- package/src/routes/chat/relay-pipeline.js +18 -2
- package/src/routes/stream-scan.js +22 -5
- package/src/routes/stream.js +2 -3
- package/src/server.js +5 -0
- package/src/talk-full-redact.js +129 -0
- package/src/talk-full.js +130 -0
- package/src/talk-log.js +42 -15
- package/src/upstream-engine/sdk/responses.js +5 -0
- package/src/usage/report.js +14 -8
package/src/talk-log.js
CHANGED
|
@@ -43,12 +43,14 @@ const MASKS = [
|
|
|
43
43
|
[/\b(token|accessToken|refreshToken|api[_-]?key|apiKey|secret|password|cookie|client_secret|authorization)\s*[:=]\s*[\w./+-]{12,}/gi, "$1=[已脱敏]"],
|
|
44
44
|
];
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
const CUT_MARK = "\n…[已截断]";
|
|
47
|
+
|
|
48
|
+
/** 脱敏 + 按字节封顶截断(中文 3 字节/字,逐字累加才不会超预算),并报告这一刀是否真的落下。 */
|
|
49
|
+
function maskCut(v, cap = 100000) {
|
|
48
50
|
let s = String(v ?? "");
|
|
49
51
|
for (const [re, repl] of MASKS) s = s.replace(re, repl);
|
|
50
|
-
if (Buffer.byteLength(s, "utf8") <= cap) return s;
|
|
51
|
-
const tail = Buffer.from(
|
|
52
|
+
if (Buffer.byteLength(s, "utf8") <= cap) return { text: s, capped: false };
|
|
53
|
+
const tail = Buffer.from(CUT_MARK, "utf8");
|
|
52
54
|
const budget = Math.max(0, cap - tail.length);
|
|
53
55
|
let bytes = 0, i = 0;
|
|
54
56
|
for (const ch of s) {
|
|
@@ -57,9 +59,12 @@ export function maskText(v, cap = 100000) {
|
|
|
57
59
|
bytes += n;
|
|
58
60
|
i += ch.length;
|
|
59
61
|
}
|
|
60
|
-
return s.slice(0, i) +
|
|
62
|
+
return { text: s.slice(0, i) + CUT_MARK, capped: true };
|
|
61
63
|
}
|
|
62
64
|
|
|
65
|
+
/** 脱敏 + 按字节封顶截断(对外口径与改前逐字一致;要知道是否砍过用 maskCut/pushBlock)。 */
|
|
66
|
+
export function maskText(v, cap = 100000) { return maskCut(v, cap).text; }
|
|
67
|
+
|
|
63
68
|
function textOf(content) {
|
|
64
69
|
if (typeof content === "string") return content;
|
|
65
70
|
if (Array.isArray(content)) return content.map((p) => p?.text || (p?.image_url ? `[图片 ${String(p.image_url.url).slice(0, 60)}]` : "")).filter(Boolean).join("\n");
|
|
@@ -78,26 +83,44 @@ export function lastUserQuestion(body) {
|
|
|
78
83
|
|
|
79
84
|
const CUT_IN = "----8<----", CUT_OUT = "---->8----";
|
|
80
85
|
|
|
86
|
+
// 标签行的「N 字」在字节封顶之后只是**已落盘**的字数;不带封顶标记,就会被读成「模型只说了这么多」。
|
|
81
87
|
function pushBlock(out, label, text, cap) {
|
|
82
|
-
const m =
|
|
83
|
-
if (!m.trim()) return;
|
|
84
|
-
out.push(`[${label} · ${m.length}
|
|
88
|
+
const { text: m, capped } = maskCut(text, cap);
|
|
89
|
+
if (!m.trim()) return false;
|
|
90
|
+
out.push(`[${label} · ${m.length} 字${capped ? " · 已封顶" : ""}]`, CUT_IN, m, CUT_OUT, "");
|
|
91
|
+
return capped;
|
|
85
92
|
}
|
|
86
93
|
|
|
87
|
-
|
|
88
|
-
|
|
94
|
+
// 撞捕获上限时紧跟头部行的人类可读提醒:不必先认识 truncated=1 这个键名也能一眼看出「可能不完整」。
|
|
95
|
+
const TRUNC_NOTE = "[!] 本轮已撞捕获上限(truncated=1):思考/正文后半段未落盘,内容可能不完整 —— 别当成模型的完整回答";
|
|
96
|
+
|
|
97
|
+
/** 一条对话 = 一个可读块:头部一行元信息(ts= 是环形淘汰的唯一依据),正文三段。elapsed= 取本次尝试墙钟(design D3),finish=/relayMs= 为 ADR-0046 新读数。 */
|
|
98
|
+
export function formatTalkEntry({ reqId, model, via, hops, status, stream, elapsedMs, question, thinking, answer, tools, usage, upstream, account, pick, ts, talkCapped = false, talkChars, talkCap, finishReason, relayMs } = {}) {
|
|
99
|
+
const fval = finishReason || "-"; // 缺值占位(grill Q5):「没给 finish」不得被读成 stop;字段恒在场
|
|
89
100
|
const now = Number.isFinite(ts) && ts > 0 ? ts : Date.now();
|
|
101
|
+
const trunc = talkCapped === true;
|
|
90
102
|
const head = [
|
|
91
103
|
`${MARK} ts=${now}`, `time=${fmtShanghaiYMDHMS(new Date(now))}`, `req=${reqId || "-"}`, `model=${model || "-"}`,
|
|
92
104
|
via ? `via=${via}` : "", hops != null ? `hops=${hops}` : "", `status=${status ?? "-"}`,
|
|
93
105
|
stream ? "stream=1" : "stream=0", Number.isFinite(elapsedMs) ? `elapsed=${Math.round(elapsedMs)}ms` : "",
|
|
106
|
+
// 尝试墙钟与 relay 内部计时同值时不重复打印(头行噪音克制,grill Q3);两值不同(hedge/缓冲重放)才另列 relayMs
|
|
107
|
+
Number.isFinite(relayMs) && Number.isFinite(elapsedMs) && Math.round(relayMs) !== Math.round(elapsedMs) ? `relayMs=${Math.round(relayMs)}ms` : "",
|
|
108
|
+
`finish=${fval}`,
|
|
94
109
|
usage ? `usage(prompt=${usage.prompt_tokens ?? "-"},completion=${usage.completion_tokens ?? "-"})` : "",
|
|
95
110
|
upstream ? `upstream=${upstream}` : "", account ? `account=${account}` : "", pick ? `pick=${pick}` : "",
|
|
111
|
+
// 截断读数只在真截断时出现(未截断不得新增噪音字段):cap= 上限、chars= 已捕获字符数
|
|
112
|
+
trunc ? `truncated=1 cap=${Number.isFinite(talkCap) && talkCap > 0 ? talkCap : "-"} chars=${Number.isFinite(talkChars) ? talkChars : "-"}` : "",
|
|
96
113
|
].filter(Boolean).join(" ");
|
|
97
|
-
const out = [head
|
|
114
|
+
const out = [head];
|
|
115
|
+
if (trunc) out.push(TRUNC_NOTE);
|
|
116
|
+
out.push("");
|
|
98
117
|
pushBlock(out, "我问", question, 20000);
|
|
99
118
|
pushBlock(out, "思考", thinking, 100000);
|
|
100
|
-
|
|
119
|
+
// 零正文不再静默跳块(spec「零输出轮必须可判读」/grill Q4):缺块与「正文该有却没落盘」同形,缺席必须是可读读数。
|
|
120
|
+
// 只落一行标注 + 空行(没有内容可围,不套 CUT 围栏);有真实正文的字符串照旧走 pushBlock,该段与改动前逐字节一致。
|
|
121
|
+
// 判据看 trim 不看长度(P1-B):" "/"\n" 进 pushBlock 也会被 !m.trim() 整块跳过 → 与「正文丢盘」再度同形,而「只调工具 + 吐个换行」是真实 agent 形态。
|
|
122
|
+
if (!String(answer ?? "").trim()) out.push(`[回答 · 0 字 · 本轮无正文(finish=${fval})]`, "");
|
|
123
|
+
else pushBlock(out, "回答", answer, 200000);
|
|
101
124
|
const t = tools == null || tools === "" ? "" : String(tools);
|
|
102
125
|
pushBlock(out, "工具调用", t, 20000);
|
|
103
126
|
out.push("[END]", "");
|
|
@@ -177,8 +200,10 @@ export function trimTalkLog(file, nowTs = Date.now()) {
|
|
|
177
200
|
/**
|
|
178
201
|
* relay 落盘的唯一入口:把 relay() 累积的 detail.talk(思考/正文/工具分片)拼成一条对话。
|
|
179
202
|
* 空轮(零正文零思考零工具)不占环形窗口 —— 那是 relay-pipeline 已经另行报错的场景。
|
|
203
|
+
* 桶的 capped/n/cap 必须一路传到 formatTalkEntry:撞顶的那条要能看出「后半截没了」。
|
|
204
|
+
* attemptMs(本次上游尝试墙钟)由调用点传入;未传(拿不到尝试起点)回退 out.totalMs —— 此时 elapsed 与 relayMs 同值(spec 降级 scenario)。
|
|
180
205
|
*/
|
|
181
|
-
export function recordRelayTalk({ reqId, model, via, hops, body, out, echo = {} } = {}) {
|
|
206
|
+
export function recordRelayTalk({ reqId, model, via, hops, body, out, echo = {}, attemptMs, finishReason } = {}) {
|
|
182
207
|
if (!talkLogEnabled()) return false;
|
|
183
208
|
try {
|
|
184
209
|
const talk = out?.detail?.talk;
|
|
@@ -190,9 +215,11 @@ export function recordRelayTalk({ reqId, model, via, hops, body, out, echo = {}
|
|
|
190
215
|
if (!answer && !thinking && !tools) return false;
|
|
191
216
|
const ts = Date.now();
|
|
192
217
|
const block = formatTalkEntry({
|
|
193
|
-
reqId, model, via, hops, status, stream: Boolean(body?.stream),
|
|
194
|
-
elapsedMs: out?.totalMs,
|
|
218
|
+
reqId, model, via, hops, status, stream: Boolean(body?.stream), finishReason: finishReason ?? out?.detail?.sawFinishReason,
|
|
219
|
+
elapsedMs: Number.isFinite(Number(attemptMs)) ? Number(attemptMs) : out?.totalMs, // 新口径:本次尝试墙钟优先(design D3)
|
|
220
|
+
relayMs: out?.totalMs, question: lastUserQuestion(body || {}),
|
|
195
221
|
thinking, answer, tools, usage: out?.detail?.usage, ...echo, ts,
|
|
222
|
+
talkCapped: talk?.capped === true, talkChars: talk?.n, talkCap: talk?.cap,
|
|
196
223
|
});
|
|
197
224
|
appendTalkEntry({ file: talkLogFile(model), block, atMs: ts });
|
|
198
225
|
return true;
|
|
@@ -141,6 +141,11 @@ export async function attemptOnceResponsesSdk({
|
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
143
|
if (mapped) return mapped;
|
|
144
|
+
// 非 HTTP 类错误(网络断/超时/无 statusCode)经 errorResponseFromSdkError 映射为 null:
|
|
145
|
+
// 必须 rethrow,否则 res 保持 undefined 掉到下面 res.stream,把真实网络错误伪装成
|
|
146
|
+
// "Cannot read properties of undefined" 的 TypeError 502(2026-10-07 muse-spark 实测)。
|
|
147
|
+
// 不可无条件 throw:400(encrypted) 剥态重试成功也走到这里(res 已赋值、mapped 置 null)。
|
|
148
|
+
if (res === undefined) throw e;
|
|
144
149
|
}
|
|
145
150
|
const out = streamResponseFromParts(res.stream, { marker, clock, t0, captured });
|
|
146
151
|
if (encRetry) { try { out._t.encRetry = true; } catch {} }
|
package/src/usage/report.js
CHANGED
|
@@ -118,11 +118,15 @@ function fold(acc, r) {
|
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
// 纯函数:只做过滤 + 归并,不碰磁盘。
|
|
121
|
-
export function aggregateUsage(rows, { hours = 24, now = Date.now(), model = null } = {}) {
|
|
122
|
-
const windowHours = Number.isFinite(Number(hours)) && Number(hours) > 0 ? Number(hours) : 24;
|
|
121
|
+
export function aggregateUsage(rows, { hours = 24, since: sinceOpt = null, now = Date.now(), model = null } = {}) {
|
|
123
122
|
const untilN = Number(now);
|
|
124
123
|
const until = Number.isFinite(untilN) ? untilN : Date.now();
|
|
125
|
-
|
|
124
|
+
// since(绝对窗口起点,毫秒)优先于 hours:CLI 默认窗口「今日 0 点 → 现在」靠它精确落在 0 点,不随查询时刻漂移
|
|
125
|
+
const sinceMs = sinceOpt == null ? NaN : Number(sinceOpt);
|
|
126
|
+
const hasSince = Number.isFinite(sinceMs);
|
|
127
|
+
const hoursN = Number(hours);
|
|
128
|
+
const windowHours = hasSince ? (until - sinceMs) / HOUR_MS : Number.isFinite(hoursN) && hoursN > 0 ? hoursN : 24;
|
|
129
|
+
const since = hasSince ? sinceMs : until - windowHours * HOUR_MS;
|
|
126
130
|
const byModel = new Map();
|
|
127
131
|
const sum = blank(null);
|
|
128
132
|
let scanned = 0;
|
|
@@ -156,8 +160,10 @@ export function aggregateUsage(rows, { hours = 24, now = Date.now(), model = nul
|
|
|
156
160
|
}
|
|
157
161
|
|
|
158
162
|
// 读保留期内的日文件并只留窗口内的行(保留期默认 2 天,文件数很少,全读即可)。
|
|
159
|
-
export async function readUsageRows({ dir, hours = 24, now = Date.now() } = {}) {
|
|
160
|
-
const
|
|
163
|
+
export async function readUsageRows({ dir, hours = 24, since: sinceOpt = null, now = Date.now() } = {}) {
|
|
164
|
+
const sinceMs = sinceOpt == null ? NaN : Number(sinceOpt);
|
|
165
|
+
const hoursN = Number(hours);
|
|
166
|
+
const since = Number.isFinite(sinceMs) ? sinceMs : Number(now) - (Number.isFinite(hoursN) && hoursN > 0 ? hoursN : 24) * HOUR_MS;
|
|
161
167
|
let files = [];
|
|
162
168
|
try {
|
|
163
169
|
files = (await readdir(usageDir({ dir }))).filter((f) => f.endsWith(".jsonl")).sort();
|
|
@@ -183,7 +189,7 @@ export async function readUsageRows({ dir, hours = 24, now = Date.now() } = {})
|
|
|
183
189
|
return rows;
|
|
184
190
|
}
|
|
185
191
|
|
|
186
|
-
export async function usageReport({ dir, hours = 24, now = Date.now(), model = null } = {}) {
|
|
187
|
-
const rows = await readUsageRows({ dir, hours, now });
|
|
188
|
-
return aggregateUsage(rows, { hours, now, model });
|
|
192
|
+
export async function usageReport({ dir, hours = 24, since = null, now = Date.now(), model = null } = {}) {
|
|
193
|
+
const rows = await readUsageRows({ dir, hours, since, now });
|
|
194
|
+
return aggregateUsage(rows, { hours, since, now, model });
|
|
189
195
|
}
|