mslxdff 0.1.111 → 0.1.112
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
|
@@ -139,7 +139,10 @@ export function reshapeWorkbuddySse(res) {
|
|
|
139
139
|
},
|
|
140
140
|
cancel() {
|
|
141
141
|
closed = true;
|
|
142
|
-
try {
|
|
142
|
+
try {
|
|
143
|
+
const p = reader.cancel();
|
|
144
|
+
if (p && typeof p.catch === "function") p.catch(() => {});
|
|
145
|
+
} catch {}
|
|
143
146
|
},
|
|
144
147
|
});
|
|
145
148
|
|
|
@@ -61,21 +61,29 @@ export function errorResponseFromSdkError(e, { marker = null } = {}) {
|
|
|
61
61
|
export function streamResponseFromParts(parts, { marker = null, clock = Date.now, t0 = clock() } = {}) {
|
|
62
62
|
const ser = createSseSerializer();
|
|
63
63
|
const enc = new TextEncoder();
|
|
64
|
+
let cancelled = false;
|
|
64
65
|
const stream = new ReadableStream({
|
|
65
66
|
async start(controller) {
|
|
66
67
|
try {
|
|
67
68
|
for await (const part of parts) {
|
|
69
|
+
if (cancelled) break;
|
|
68
70
|
const text = ser.push(part);
|
|
69
71
|
if (text) controller.enqueue(enc.encode(text));
|
|
70
72
|
}
|
|
71
73
|
} catch (e) {
|
|
72
|
-
controller.enqueue(enc.encode(`data: ${JSON.stringify({ error: { message: String(e?.message || e) } })}\n\n`));
|
|
74
|
+
try { controller.enqueue(enc.encode(`data: ${JSON.stringify({ error: { message: String(e?.message || e) } })}\n\n`)); } catch {}
|
|
73
75
|
}
|
|
74
|
-
controller.enqueue(enc.encode(ser.end()));
|
|
75
|
-
controller.close();
|
|
76
|
+
try { controller.enqueue(enc.encode(ser.end())); controller.close(); } catch {}
|
|
76
77
|
},
|
|
77
78
|
cancel() {
|
|
78
|
-
|
|
79
|
+
// 客户端断开时 parts 仍被 start 的 for-await 锁定:直接 cancel 会抛 ERR_INVALID_STATE,
|
|
80
|
+
// 且异常经内部 promise 回调逃出同步 try/catch → unhandled rejection 崩进程(v0.1.111 实测 9 次)。
|
|
81
|
+
// 修复:置标志让迭代自然收尾,并同时吞掉同步异常与 promise rejection 两条路径。
|
|
82
|
+
cancelled = true;
|
|
83
|
+
try {
|
|
84
|
+
const p = parts?.cancel?.();
|
|
85
|
+
if (p && typeof p.catch === "function") p.catch(() => {});
|
|
86
|
+
} catch {}
|
|
79
87
|
},
|
|
80
88
|
});
|
|
81
89
|
const out = new Response(stream, {
|