mslxdff 0.1.115 → 0.1.117
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
CHANGED
|
@@ -35,6 +35,19 @@ function withUidHeader(res, uid) {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
// 400 判型需读 body 文本;读过的 Response body 不可再读(下游转发报 "Body is unusable"),
|
|
39
|
+
// 用文本重建一个等价响应(去掉 content-length 防长度不符)。
|
|
40
|
+
function rewrapBody(res, txt) {
|
|
41
|
+
try { console.error(`[workbuddy] upstream ${res.status} body: ${String(txt).slice(0, 300)}`); } catch {}
|
|
42
|
+
try {
|
|
43
|
+
const h = new Headers(res.headers);
|
|
44
|
+
h.delete("content-length");
|
|
45
|
+
const r = new Response(txt, { status: res.status, statusText: res.statusText, headers: h });
|
|
46
|
+
try { r._t = res._t; } catch {}
|
|
47
|
+
return r;
|
|
48
|
+
} catch { return res; }
|
|
49
|
+
}
|
|
50
|
+
|
|
38
51
|
function nowMs(clock) { return typeof performance !== "undefined" && performance.now ? performance.now() : clock(); }
|
|
39
52
|
|
|
40
53
|
function errRes(status, msg, reason, uid, t0, clock) {
|
|
@@ -109,7 +122,7 @@ export function createChatService({
|
|
|
109
122
|
if (res.status < 400) return reshapeWorkbuddySse(res);
|
|
110
123
|
let txt = "";
|
|
111
124
|
try { txt = await res.text(); } catch {}
|
|
112
|
-
if (!isAuthError(res.status, txt)) return res;
|
|
125
|
+
if (!isAuthError(res.status, txt)) return rewrapBody(res, txt);
|
|
113
126
|
const newKey = await authService?.refreshTokenFor?.(key, auth);
|
|
114
127
|
if (!newKey) throw failErr(`workbuddy refresh failed for ${auth?.uid || ""}: ${txt.slice(0, 120)}`, _t0(), clock);
|
|
115
128
|
const auth2 = authForKey(newKey);
|
|
@@ -118,6 +131,7 @@ export function createChatService({
|
|
|
118
131
|
catch (e2) { throw e2; }
|
|
119
132
|
let stillTxt = "";
|
|
120
133
|
if (res2.status >= 400) { try { stillTxt = await res2.text(); } catch {} }
|
|
134
|
+
if (stillTxt) res2 = rewrapBody(res2, stillTxt);
|
|
121
135
|
const stillAuth = isAuthError(res2.status, stillTxt);
|
|
122
136
|
const uid2 = auth2.uid || auth.uid;
|
|
123
137
|
res2 = withUidHeader(res2, uid2);
|
|
@@ -203,6 +217,7 @@ export function createChatService({
|
|
|
203
217
|
lastErr = failErr(`workbuddy insufficient for ${uid}: ${txt.slice(0, 120)}`, t0, clock);
|
|
204
218
|
continue;
|
|
205
219
|
}
|
|
220
|
+
res = rewrapBody(res, txt);
|
|
206
221
|
}
|
|
207
222
|
if (res.status === 401 || res.status === 403 || res.status === 429 || res.status >= 500) try { activeRing.onError(key); } catch {}
|
|
208
223
|
res = withUidHeader(res, uid);
|
|
@@ -43,7 +43,8 @@ export function responsesToChatBody(req = {}) {
|
|
|
43
43
|
}
|
|
44
44
|
continue;
|
|
45
45
|
}
|
|
46
|
-
|
|
46
|
+
// responses 规范:message item 的 type 可省(AI SDK/opencode 就不发)→ 有 role 即按 message 处理
|
|
47
|
+
if (it.type === "message" || (!it.type && it.role)) {
|
|
47
48
|
const msg = { role: it.role || "user", content: inputTextOf(it.content) };
|
|
48
49
|
if (pendingReasoning.length && msg.role === "assistant") { msg.reasoning_items = pendingReasoning; pendingReasoning = []; }
|
|
49
50
|
messages.push(msg);
|
|
@@ -112,6 +112,15 @@ export async function responsesHandler(ctx) {
|
|
|
112
112
|
inputKinds: Array.isArray(body?.input) ? [...new Set(body.input.map((i) => i?.type))] : null,
|
|
113
113
|
tools: Array.isArray(body?.tools) ? body.tools.length : 0,
|
|
114
114
|
instructionsLen: String(body?.instructions || "").length,
|
|
115
|
+
// 文本丢失定位:各 message item 的 content 形状(part 类型 + 文本长度 + 头部)
|
|
116
|
+
contentShapes: Array.isArray(body?.input)
|
|
117
|
+
? body.input.filter((i) => i && (i.type === "message" || i.role)).map((m) => ({
|
|
118
|
+
type: m.type ?? "(无type)", role: m.role,
|
|
119
|
+
cType: Array.isArray(m.content) ? "array" : typeof m.content,
|
|
120
|
+
parts: Array.isArray(m.content) ? m.content.map((p) => `${p?.type ?? "?"}:${typeof p?.text === "string" ? p.text.length : "-"}`).slice(0, 6) : null,
|
|
121
|
+
textHead: typeof m.content === "string" ? m.content.slice(0, 50) : null,
|
|
122
|
+
})).slice(0, 10)
|
|
123
|
+
: null,
|
|
115
124
|
}));
|
|
116
125
|
let chatBody;
|
|
117
126
|
try {
|