@langchain/langgraph-sdk 1.3.0 → 1.4.4
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 +5 -5
- package/CHANGELOG.md +0 -275
- package/dist/_virtual/rolldown_runtime.cjs +0 -25
- package/dist/auth/error.cjs +0 -79
- package/dist/auth/error.cjs.map +0 -1
- package/dist/auth/error.d.cts +0 -13
- package/dist/auth/error.d.cts.map +0 -1
- package/dist/auth/error.d.ts +0 -13
- package/dist/auth/error.d.ts.map +0 -1
- package/dist/auth/error.js +0 -78
- package/dist/auth/error.js.map +0 -1
- package/dist/auth/index.cjs +0 -39
- package/dist/auth/index.cjs.map +0 -1
- package/dist/auth/index.d.cts +0 -31
- package/dist/auth/index.d.cts.map +0 -1
- package/dist/auth/index.d.ts +0 -31
- package/dist/auth/index.d.ts.map +0 -1
- package/dist/auth/index.js +0 -37
- package/dist/auth/index.js.map +0 -1
- package/dist/auth/types.d.cts +0 -294
- package/dist/auth/types.d.cts.map +0 -1
- package/dist/auth/types.d.ts +0 -294
- package/dist/auth/types.d.ts.map +0 -1
- package/dist/client.cjs +0 -1193
- package/dist/client.cjs.map +0 -1
- package/dist/client.d.cts +0 -780
- package/dist/client.d.cts.map +0 -1
- package/dist/client.d.ts +0 -780
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js +0 -1186
- package/dist/client.js.map +0 -1
- package/dist/index.cjs +0 -6
- package/dist/index.d.cts +0 -7
- package/dist/index.d.ts +0 -7
- package/dist/index.js +0 -4
- package/dist/logging/index.cjs +0 -35
- package/dist/logging/index.cjs.map +0 -1
- package/dist/logging/index.d.cts +0 -47
- package/dist/logging/index.d.cts.map +0 -1
- package/dist/logging/index.d.ts +0 -47
- package/dist/logging/index.d.ts.map +0 -1
- package/dist/logging/index.js +0 -34
- package/dist/logging/index.js.map +0 -1
- package/dist/react/index.cjs +0 -5
- package/dist/react/index.d.cts +0 -4
- package/dist/react/index.d.ts +0 -4
- package/dist/react/index.js +0 -4
- package/dist/react/stream.cjs +0 -18
- package/dist/react/stream.cjs.map +0 -1
- package/dist/react/stream.custom.cjs +0 -129
- package/dist/react/stream.custom.cjs.map +0 -1
- package/dist/react/stream.custom.d.cts +0 -39
- package/dist/react/stream.custom.d.cts.map +0 -1
- package/dist/react/stream.custom.d.ts +0 -39
- package/dist/react/stream.custom.d.ts.map +0 -1
- package/dist/react/stream.custom.js +0 -127
- package/dist/react/stream.custom.js.map +0 -1
- package/dist/react/stream.d.cts +0 -73
- package/dist/react/stream.d.cts.map +0 -1
- package/dist/react/stream.d.ts +0 -73
- package/dist/react/stream.d.ts.map +0 -1
- package/dist/react/stream.js +0 -17
- package/dist/react/stream.js.map +0 -1
- package/dist/react/stream.lgp.cjs +0 -446
- package/dist/react/stream.lgp.cjs.map +0 -1
- package/dist/react/stream.lgp.js +0 -445
- package/dist/react/stream.lgp.js.map +0 -1
- package/dist/react/thread.cjs +0 -22
- package/dist/react/thread.cjs.map +0 -1
- package/dist/react/thread.js +0 -21
- package/dist/react/thread.js.map +0 -1
- package/dist/react/types.d.cts +0 -363
- package/dist/react/types.d.cts.map +0 -1
- package/dist/react/types.d.ts +0 -363
- package/dist/react/types.d.ts.map +0 -1
- package/dist/react-ui/client.cjs +0 -137
- package/dist/react-ui/client.cjs.map +0 -1
- package/dist/react-ui/client.d.cts +0 -90
- package/dist/react-ui/client.d.cts.map +0 -1
- package/dist/react-ui/client.d.ts +0 -90
- package/dist/react-ui/client.d.ts.map +0 -1
- package/dist/react-ui/client.js +0 -134
- package/dist/react-ui/client.js.map +0 -1
- package/dist/react-ui/index.cjs +0 -14
- package/dist/react-ui/index.cjs.map +0 -1
- package/dist/react-ui/index.d.cts +0 -3
- package/dist/react-ui/index.d.ts +0 -3
- package/dist/react-ui/index.js +0 -9
- package/dist/react-ui/index.js.map +0 -1
- package/dist/react-ui/server/index.cjs +0 -5
- package/dist/react-ui/server/index.d.cts +0 -3
- package/dist/react-ui/server/index.d.ts +0 -3
- package/dist/react-ui/server/index.js +0 -4
- package/dist/react-ui/server/server.cjs +0 -57
- package/dist/react-ui/server/server.cjs.map +0 -1
- package/dist/react-ui/server/server.d.cts +0 -55
- package/dist/react-ui/server/server.d.cts.map +0 -1
- package/dist/react-ui/server/server.d.ts +0 -55
- package/dist/react-ui/server/server.d.ts.map +0 -1
- package/dist/react-ui/server/server.js +0 -56
- package/dist/react-ui/server/server.js.map +0 -1
- package/dist/react-ui/types.cjs +0 -38
- package/dist/react-ui/types.cjs.map +0 -1
- package/dist/react-ui/types.d.cts +0 -25
- package/dist/react-ui/types.d.cts.map +0 -1
- package/dist/react-ui/types.d.ts +0 -25
- package/dist/react-ui/types.d.ts.map +0 -1
- package/dist/react-ui/types.js +0 -35
- package/dist/react-ui/types.js.map +0 -1
- package/dist/schema.d.cts +0 -284
- package/dist/schema.d.cts.map +0 -1
- package/dist/schema.d.ts +0 -284
- package/dist/schema.d.ts.map +0 -1
- package/dist/singletons/fetch.cjs +0 -24
- package/dist/singletons/fetch.cjs.map +0 -1
- package/dist/singletons/fetch.d.cts +0 -14
- package/dist/singletons/fetch.d.cts.map +0 -1
- package/dist/singletons/fetch.d.ts +0 -14
- package/dist/singletons/fetch.d.ts.map +0 -1
- package/dist/singletons/fetch.js +0 -22
- package/dist/singletons/fetch.js.map +0 -1
- package/dist/types.d.cts +0 -187
- package/dist/types.d.cts.map +0 -1
- package/dist/types.d.ts +0 -187
- package/dist/types.d.ts.map +0 -1
- package/dist/types.messages.d.cts +0 -91
- package/dist/types.messages.d.cts.map +0 -1
- package/dist/types.messages.d.ts +0 -91
- package/dist/types.messages.d.ts.map +0 -1
- package/dist/types.stream.d.cts +0 -235
- package/dist/types.stream.d.cts.map +0 -1
- package/dist/types.stream.d.ts +0 -235
- package/dist/types.stream.d.ts.map +0 -1
- package/dist/ui/branching.cjs +0 -153
- package/dist/ui/branching.cjs.map +0 -1
- package/dist/ui/branching.d.cts +0 -22
- package/dist/ui/branching.d.cts.map +0 -1
- package/dist/ui/branching.d.ts +0 -22
- package/dist/ui/branching.d.ts.map +0 -1
- package/dist/ui/branching.js +0 -152
- package/dist/ui/branching.js.map +0 -1
- package/dist/ui/errors.cjs +0 -15
- package/dist/ui/errors.cjs.map +0 -1
- package/dist/ui/errors.js +0 -14
- package/dist/ui/errors.js.map +0 -1
- package/dist/ui/manager.cjs +0 -182
- package/dist/ui/manager.cjs.map +0 -1
- package/dist/ui/manager.js +0 -182
- package/dist/ui/manager.js.map +0 -1
- package/dist/ui/messages.cjs +0 -70
- package/dist/ui/messages.cjs.map +0 -1
- package/dist/ui/messages.js +0 -68
- package/dist/ui/messages.js.map +0 -1
- package/dist/ui/utils.cjs +0 -14
- package/dist/ui/utils.cjs.map +0 -1
- package/dist/ui/utils.js +0 -12
- package/dist/ui/utils.js.map +0 -1
- package/dist/utils/async_caller.cjs +0 -111
- package/dist/utils/async_caller.cjs.map +0 -1
- package/dist/utils/async_caller.d.cts +0 -53
- package/dist/utils/async_caller.d.cts.map +0 -1
- package/dist/utils/async_caller.d.ts +0 -53
- package/dist/utils/async_caller.d.ts.map +0 -1
- package/dist/utils/async_caller.js +0 -110
- package/dist/utils/async_caller.js.map +0 -1
- package/dist/utils/env.cjs +0 -13
- package/dist/utils/env.cjs.map +0 -1
- package/dist/utils/env.js +0 -12
- package/dist/utils/env.js.map +0 -1
- package/dist/utils/signals.cjs +0 -20
- package/dist/utils/signals.cjs.map +0 -1
- package/dist/utils/signals.js +0 -19
- package/dist/utils/signals.js.map +0 -1
- package/dist/utils/sse.cjs +0 -124
- package/dist/utils/sse.cjs.map +0 -1
- package/dist/utils/sse.js +0 -122
- package/dist/utils/sse.js.map +0 -1
- package/dist/utils/stream.cjs +0 -91
- package/dist/utils/stream.cjs.map +0 -1
- package/dist/utils/stream.js +0 -90
- package/dist/utils/stream.js.map +0 -1
package/dist/utils/signals.cjs
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
//#region src/utils/signals.ts
|
|
3
|
-
function mergeSignals(...signals) {
|
|
4
|
-
const nonZeroSignals = signals.filter((signal) => signal != null);
|
|
5
|
-
if (nonZeroSignals.length === 0) return void 0;
|
|
6
|
-
if (nonZeroSignals.length === 1) return nonZeroSignals[0];
|
|
7
|
-
const controller = new AbortController();
|
|
8
|
-
for (const signal of signals) {
|
|
9
|
-
if (signal?.aborted) {
|
|
10
|
-
controller.abort(signal.reason);
|
|
11
|
-
return controller.signal;
|
|
12
|
-
}
|
|
13
|
-
signal?.addEventListener("abort", () => controller.abort(signal.reason), { once: true });
|
|
14
|
-
}
|
|
15
|
-
return controller.signal;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
//#endregion
|
|
19
|
-
exports.mergeSignals = mergeSignals;
|
|
20
|
-
//# sourceMappingURL=signals.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"signals.cjs","names":[],"sources":["../../src/utils/signals.ts"],"sourcesContent":["export function mergeSignals(...signals: (AbortSignal | null | undefined)[]) {\n const nonZeroSignals = signals.filter(\n (signal): signal is AbortSignal => signal != null\n );\n\n if (nonZeroSignals.length === 0) return undefined;\n if (nonZeroSignals.length === 1) return nonZeroSignals[0];\n\n const controller = new AbortController();\n for (const signal of signals) {\n if (signal?.aborted) {\n controller.abort(signal.reason);\n return controller.signal;\n }\n\n signal?.addEventListener(\"abort\", () => controller.abort(signal.reason), {\n once: true,\n });\n }\n\n return controller.signal;\n}\n"],"mappings":";;AAAA,SAAgB,aAAa,GAAG,SAA6C;CAC3E,MAAM,iBAAiB,QAAQ,QAC5B,WAAkC,UAAU;AAG/C,KAAI,eAAe,WAAW,EAAG,QAAO;AACxC,KAAI,eAAe,WAAW,EAAG,QAAO,eAAe;CAEvD,MAAM,aAAa,IAAI;AACvB,MAAK,MAAM,UAAU,SAAS;AAC5B,MAAI,QAAQ,SAAS;AACnB,cAAW,MAAM,OAAO;AACxB,UAAO,WAAW;;AAGpB,UAAQ,iBAAiB,eAAe,WAAW,MAAM,OAAO,SAAS,EACvE,MAAM;;AAIV,QAAO,WAAW"}
|
package/dist/utils/signals.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
//#region src/utils/signals.ts
|
|
2
|
-
function mergeSignals(...signals) {
|
|
3
|
-
const nonZeroSignals = signals.filter((signal) => signal != null);
|
|
4
|
-
if (nonZeroSignals.length === 0) return void 0;
|
|
5
|
-
if (nonZeroSignals.length === 1) return nonZeroSignals[0];
|
|
6
|
-
const controller = new AbortController();
|
|
7
|
-
for (const signal of signals) {
|
|
8
|
-
if (signal?.aborted) {
|
|
9
|
-
controller.abort(signal.reason);
|
|
10
|
-
return controller.signal;
|
|
11
|
-
}
|
|
12
|
-
signal?.addEventListener("abort", () => controller.abort(signal.reason), { once: true });
|
|
13
|
-
}
|
|
14
|
-
return controller.signal;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
//#endregion
|
|
18
|
-
export { mergeSignals };
|
|
19
|
-
//# sourceMappingURL=signals.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"signals.js","names":[],"sources":["../../src/utils/signals.ts"],"sourcesContent":["export function mergeSignals(...signals: (AbortSignal | null | undefined)[]) {\n const nonZeroSignals = signals.filter(\n (signal): signal is AbortSignal => signal != null\n );\n\n if (nonZeroSignals.length === 0) return undefined;\n if (nonZeroSignals.length === 1) return nonZeroSignals[0];\n\n const controller = new AbortController();\n for (const signal of signals) {\n if (signal?.aborted) {\n controller.abort(signal.reason);\n return controller.signal;\n }\n\n signal?.addEventListener(\"abort\", () => controller.abort(signal.reason), {\n once: true,\n });\n }\n\n return controller.signal;\n}\n"],"mappings":";AAAA,SAAgB,aAAa,GAAG,SAA6C;CAC3E,MAAM,iBAAiB,QAAQ,QAC5B,WAAkC,UAAU;AAG/C,KAAI,eAAe,WAAW,EAAG,QAAO;AACxC,KAAI,eAAe,WAAW,EAAG,QAAO,eAAe;CAEvD,MAAM,aAAa,IAAI;AACvB,MAAK,MAAM,UAAU,SAAS;AAC5B,MAAI,QAAQ,SAAS;AACnB,cAAW,MAAM,OAAO;AACxB,UAAO,WAAW;;AAGpB,UAAQ,iBAAiB,eAAe,WAAW,MAAM,OAAO,SAAS,EACvE,MAAM;;AAIV,QAAO,WAAW"}
|
package/dist/utils/sse.cjs
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
//#region src/utils/sse.ts
|
|
3
|
-
const CR = "\r".charCodeAt(0);
|
|
4
|
-
const LF = "\n".charCodeAt(0);
|
|
5
|
-
const NULL = "\0".charCodeAt(0);
|
|
6
|
-
const COLON = ":".charCodeAt(0);
|
|
7
|
-
const SPACE = " ".charCodeAt(0);
|
|
8
|
-
const TRAILING_NEWLINE = [CR, LF];
|
|
9
|
-
function BytesLineDecoder() {
|
|
10
|
-
let buffer = [];
|
|
11
|
-
let trailingCr = false;
|
|
12
|
-
return new TransformStream({
|
|
13
|
-
start() {
|
|
14
|
-
buffer = [];
|
|
15
|
-
trailingCr = false;
|
|
16
|
-
},
|
|
17
|
-
transform(chunk, controller) {
|
|
18
|
-
let text = chunk;
|
|
19
|
-
if (trailingCr) {
|
|
20
|
-
text = joinArrays([[CR], text]);
|
|
21
|
-
trailingCr = false;
|
|
22
|
-
}
|
|
23
|
-
if (text.length > 0 && text.at(-1) === CR) {
|
|
24
|
-
trailingCr = true;
|
|
25
|
-
text = text.subarray(0, -1);
|
|
26
|
-
}
|
|
27
|
-
if (!text.length) return;
|
|
28
|
-
const trailingNewline = TRAILING_NEWLINE.includes(text.at(-1));
|
|
29
|
-
const lastIdx = text.length - 1;
|
|
30
|
-
const { lines } = text.reduce((acc, cur, idx) => {
|
|
31
|
-
if (acc.from > idx) return acc;
|
|
32
|
-
if (cur === CR || cur === LF) {
|
|
33
|
-
acc.lines.push(text.subarray(acc.from, idx));
|
|
34
|
-
if (cur === CR && text[idx + 1] === LF) acc.from = idx + 2;
|
|
35
|
-
else acc.from = idx + 1;
|
|
36
|
-
}
|
|
37
|
-
if (idx === lastIdx && acc.from <= lastIdx) acc.lines.push(text.subarray(acc.from));
|
|
38
|
-
return acc;
|
|
39
|
-
}, {
|
|
40
|
-
lines: [],
|
|
41
|
-
from: 0
|
|
42
|
-
});
|
|
43
|
-
if (lines.length === 1 && !trailingNewline) {
|
|
44
|
-
buffer.push(lines[0]);
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
if (buffer.length) {
|
|
48
|
-
buffer.push(lines[0]);
|
|
49
|
-
lines[0] = joinArrays(buffer);
|
|
50
|
-
buffer = [];
|
|
51
|
-
}
|
|
52
|
-
if (!trailingNewline) {
|
|
53
|
-
if (lines.length) buffer = [lines.pop()];
|
|
54
|
-
}
|
|
55
|
-
for (const line of lines) controller.enqueue(line);
|
|
56
|
-
},
|
|
57
|
-
flush(controller) {
|
|
58
|
-
if (buffer.length) controller.enqueue(joinArrays(buffer));
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
function SSEDecoder() {
|
|
63
|
-
let event = "";
|
|
64
|
-
let data = [];
|
|
65
|
-
let lastEventId = "";
|
|
66
|
-
let retry = null;
|
|
67
|
-
const decoder = new TextDecoder();
|
|
68
|
-
return new TransformStream({
|
|
69
|
-
transform(chunk, controller) {
|
|
70
|
-
if (!chunk.length) {
|
|
71
|
-
if (!event && !data.length && !lastEventId && retry == null) return;
|
|
72
|
-
const sse = {
|
|
73
|
-
id: lastEventId || void 0,
|
|
74
|
-
event,
|
|
75
|
-
data: data.length ? decodeArraysToJson(decoder, data) : null
|
|
76
|
-
};
|
|
77
|
-
event = "";
|
|
78
|
-
data = [];
|
|
79
|
-
retry = null;
|
|
80
|
-
controller.enqueue(sse);
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
if (chunk[0] === COLON) return;
|
|
84
|
-
const sepIdx = chunk.indexOf(COLON);
|
|
85
|
-
if (sepIdx === -1) return;
|
|
86
|
-
const fieldName = decoder.decode(chunk.subarray(0, sepIdx));
|
|
87
|
-
let value = chunk.subarray(sepIdx + 1);
|
|
88
|
-
if (value[0] === SPACE) value = value.subarray(1);
|
|
89
|
-
if (fieldName === "event") event = decoder.decode(value);
|
|
90
|
-
else if (fieldName === "data") data.push(value);
|
|
91
|
-
else if (fieldName === "id") {
|
|
92
|
-
if (value.indexOf(NULL) === -1) lastEventId = decoder.decode(value);
|
|
93
|
-
} else if (fieldName === "retry") {
|
|
94
|
-
const retryNum = Number.parseInt(decoder.decode(value), 10);
|
|
95
|
-
if (!Number.isNaN(retryNum)) retry = retryNum;
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
flush(controller) {
|
|
99
|
-
if (event) controller.enqueue({
|
|
100
|
-
id: lastEventId || void 0,
|
|
101
|
-
event,
|
|
102
|
-
data: data.length ? decodeArraysToJson(decoder, data) : null
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
function joinArrays(data) {
|
|
108
|
-
const totalLength = data.reduce((acc, curr) => acc + curr.length, 0);
|
|
109
|
-
const merged = new Uint8Array(totalLength);
|
|
110
|
-
let offset = 0;
|
|
111
|
-
for (const c of data) {
|
|
112
|
-
merged.set(c, offset);
|
|
113
|
-
offset += c.length;
|
|
114
|
-
}
|
|
115
|
-
return merged;
|
|
116
|
-
}
|
|
117
|
-
function decodeArraysToJson(decoder, data) {
|
|
118
|
-
return JSON.parse(decoder.decode(joinArrays(data)));
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
//#endregion
|
|
122
|
-
exports.BytesLineDecoder = BytesLineDecoder;
|
|
123
|
-
exports.SSEDecoder = SSEDecoder;
|
|
124
|
-
//# sourceMappingURL=sse.cjs.map
|
package/dist/utils/sse.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sse.cjs","names":["buffer: Uint8Array[]","data: Uint8Array[]","retry: number | null"],"sources":["../../src/utils/sse.ts"],"sourcesContent":["const CR = \"\\r\".charCodeAt(0);\nconst LF = \"\\n\".charCodeAt(0);\nconst NULL = \"\\0\".charCodeAt(0);\nconst COLON = \":\".charCodeAt(0);\nconst SPACE = \" \".charCodeAt(0);\n\nconst TRAILING_NEWLINE = [CR, LF];\n\nexport function BytesLineDecoder() {\n let buffer: Uint8Array[] = [];\n let trailingCr = false;\n\n return new TransformStream<Uint8Array, Uint8Array>({\n start() {\n buffer = [];\n trailingCr = false;\n },\n\n transform(chunk, controller) {\n // See https://docs.python.org/3/glossary.html#term-universal-newlines\n let text = chunk;\n\n // Handle trailing CR from previous chunk\n if (trailingCr) {\n text = joinArrays([[CR], text]);\n trailingCr = false;\n }\n\n // Check for trailing CR in current chunk\n if (text.length > 0 && text.at(-1) === CR) {\n trailingCr = true;\n text = text.subarray(0, -1);\n }\n\n if (!text.length) return;\n const trailingNewline = TRAILING_NEWLINE.includes(text.at(-1)!);\n\n const lastIdx = text.length - 1;\n const { lines } = text.reduce<{ lines: Uint8Array[]; from: number }>(\n (acc, cur, idx) => {\n if (acc.from > idx) return acc;\n\n if (cur === CR || cur === LF) {\n acc.lines.push(text.subarray(acc.from, idx));\n if (cur === CR && text[idx + 1] === LF) {\n acc.from = idx + 2;\n } else {\n acc.from = idx + 1;\n }\n }\n\n if (idx === lastIdx && acc.from <= lastIdx) {\n acc.lines.push(text.subarray(acc.from));\n }\n\n return acc;\n },\n { lines: [], from: 0 }\n );\n\n if (lines.length === 1 && !trailingNewline) {\n buffer.push(lines[0]);\n return;\n }\n\n if (buffer.length) {\n // Include existing buffer in first line\n buffer.push(lines[0]);\n lines[0] = joinArrays(buffer);\n buffer = [];\n }\n\n if (!trailingNewline) {\n // If the last segment is not newline terminated,\n // buffer it for the next chunk\n if (lines.length) buffer = [lines.pop()!];\n }\n\n // Enqueue complete lines\n for (const line of lines) {\n controller.enqueue(line);\n }\n },\n\n flush(controller) {\n if (buffer.length) {\n controller.enqueue(joinArrays(buffer));\n }\n },\n });\n}\n\ninterface StreamPart {\n id: string | undefined;\n event: string;\n data: unknown;\n}\n\nexport function SSEDecoder() {\n let event = \"\";\n let data: Uint8Array[] = [];\n let lastEventId = \"\";\n let retry: number | null = null;\n\n const decoder = new TextDecoder();\n\n return new TransformStream<Uint8Array, StreamPart>({\n transform(chunk, controller) {\n // Handle empty line case\n if (!chunk.length) {\n if (!event && !data.length && !lastEventId && retry == null) return;\n\n const sse = {\n id: lastEventId || undefined,\n event,\n data: data.length ? decodeArraysToJson(decoder, data) : null,\n };\n\n // NOTE: as per the SSE spec, do not reset lastEventId\n event = \"\";\n data = [];\n retry = null;\n\n controller.enqueue(sse);\n return;\n }\n\n // Ignore comments\n if (chunk[0] === COLON) return;\n\n const sepIdx = chunk.indexOf(COLON);\n if (sepIdx === -1) return;\n\n const fieldName = decoder.decode(chunk.subarray(0, sepIdx));\n let value = chunk.subarray(sepIdx + 1);\n if (value[0] === SPACE) value = value.subarray(1);\n\n if (fieldName === \"event\") {\n event = decoder.decode(value);\n } else if (fieldName === \"data\") {\n data.push(value);\n } else if (fieldName === \"id\") {\n if (value.indexOf(NULL) === -1) lastEventId = decoder.decode(value);\n } else if (fieldName === \"retry\") {\n const retryNum = Number.parseInt(decoder.decode(value), 10);\n if (!Number.isNaN(retryNum)) retry = retryNum;\n }\n },\n\n flush(controller) {\n if (event) {\n controller.enqueue({\n id: lastEventId || undefined,\n event,\n data: data.length ? decodeArraysToJson(decoder, data) : null,\n });\n }\n },\n });\n}\n\nfunction joinArrays(data: ArrayLike<number>[]) {\n const totalLength = data.reduce((acc, curr) => acc + curr.length, 0);\n const merged = new Uint8Array(totalLength);\n let offset = 0;\n for (const c of data) {\n merged.set(c, offset);\n offset += c.length;\n }\n return merged;\n}\n\nfunction decodeArraysToJson(decoder: TextDecoder, data: ArrayLike<number>[]) {\n return JSON.parse(decoder.decode(joinArrays(data)));\n}\n"],"mappings":";;AAAA,MAAM,KAAK,KAAK,WAAW;AAC3B,MAAM,KAAK,KAAK,WAAW;AAC3B,MAAM,OAAO,KAAK,WAAW;AAC7B,MAAM,Q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,MAAM;AACpB,SAAO,IAAI,GAAG;AACd,YAAU,EAAE;;AAEd,QAAO;;AAGT,SAAS,mBAAmB,SAAsB,MAA2B;AAC3E,QAAO,KAAK,MAAM,QAAQ,OAAO,WAAW"}
|
package/dist/utils/sse.js
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
//#region src/utils/sse.ts
|
|
2
|
-
const CR = "\r".charCodeAt(0);
|
|
3
|
-
const LF = "\n".charCodeAt(0);
|
|
4
|
-
const NULL = "\0".charCodeAt(0);
|
|
5
|
-
const COLON = ":".charCodeAt(0);
|
|
6
|
-
const SPACE = " ".charCodeAt(0);
|
|
7
|
-
const TRAILING_NEWLINE = [CR, LF];
|
|
8
|
-
function BytesLineDecoder() {
|
|
9
|
-
let buffer = [];
|
|
10
|
-
let trailingCr = false;
|
|
11
|
-
return new TransformStream({
|
|
12
|
-
start() {
|
|
13
|
-
buffer = [];
|
|
14
|
-
trailingCr = false;
|
|
15
|
-
},
|
|
16
|
-
transform(chunk, controller) {
|
|
17
|
-
let text = chunk;
|
|
18
|
-
if (trailingCr) {
|
|
19
|
-
text = joinArrays([[CR], text]);
|
|
20
|
-
trailingCr = false;
|
|
21
|
-
}
|
|
22
|
-
if (text.length > 0 && text.at(-1) === CR) {
|
|
23
|
-
trailingCr = true;
|
|
24
|
-
text = text.subarray(0, -1);
|
|
25
|
-
}
|
|
26
|
-
if (!text.length) return;
|
|
27
|
-
const trailingNewline = TRAILING_NEWLINE.includes(text.at(-1));
|
|
28
|
-
const lastIdx = text.length - 1;
|
|
29
|
-
const { lines } = text.reduce((acc, cur, idx) => {
|
|
30
|
-
if (acc.from > idx) return acc;
|
|
31
|
-
if (cur === CR || cur === LF) {
|
|
32
|
-
acc.lines.push(text.subarray(acc.from, idx));
|
|
33
|
-
if (cur === CR && text[idx + 1] === LF) acc.from = idx + 2;
|
|
34
|
-
else acc.from = idx + 1;
|
|
35
|
-
}
|
|
36
|
-
if (idx === lastIdx && acc.from <= lastIdx) acc.lines.push(text.subarray(acc.from));
|
|
37
|
-
return acc;
|
|
38
|
-
}, {
|
|
39
|
-
lines: [],
|
|
40
|
-
from: 0
|
|
41
|
-
});
|
|
42
|
-
if (lines.length === 1 && !trailingNewline) {
|
|
43
|
-
buffer.push(lines[0]);
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
if (buffer.length) {
|
|
47
|
-
buffer.push(lines[0]);
|
|
48
|
-
lines[0] = joinArrays(buffer);
|
|
49
|
-
buffer = [];
|
|
50
|
-
}
|
|
51
|
-
if (!trailingNewline) {
|
|
52
|
-
if (lines.length) buffer = [lines.pop()];
|
|
53
|
-
}
|
|
54
|
-
for (const line of lines) controller.enqueue(line);
|
|
55
|
-
},
|
|
56
|
-
flush(controller) {
|
|
57
|
-
if (buffer.length) controller.enqueue(joinArrays(buffer));
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
function SSEDecoder() {
|
|
62
|
-
let event = "";
|
|
63
|
-
let data = [];
|
|
64
|
-
let lastEventId = "";
|
|
65
|
-
let retry = null;
|
|
66
|
-
const decoder = new TextDecoder();
|
|
67
|
-
return new TransformStream({
|
|
68
|
-
transform(chunk, controller) {
|
|
69
|
-
if (!chunk.length) {
|
|
70
|
-
if (!event && !data.length && !lastEventId && retry == null) return;
|
|
71
|
-
const sse = {
|
|
72
|
-
id: lastEventId || void 0,
|
|
73
|
-
event,
|
|
74
|
-
data: data.length ? decodeArraysToJson(decoder, data) : null
|
|
75
|
-
};
|
|
76
|
-
event = "";
|
|
77
|
-
data = [];
|
|
78
|
-
retry = null;
|
|
79
|
-
controller.enqueue(sse);
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
if (chunk[0] === COLON) return;
|
|
83
|
-
const sepIdx = chunk.indexOf(COLON);
|
|
84
|
-
if (sepIdx === -1) return;
|
|
85
|
-
const fieldName = decoder.decode(chunk.subarray(0, sepIdx));
|
|
86
|
-
let value = chunk.subarray(sepIdx + 1);
|
|
87
|
-
if (value[0] === SPACE) value = value.subarray(1);
|
|
88
|
-
if (fieldName === "event") event = decoder.decode(value);
|
|
89
|
-
else if (fieldName === "data") data.push(value);
|
|
90
|
-
else if (fieldName === "id") {
|
|
91
|
-
if (value.indexOf(NULL) === -1) lastEventId = decoder.decode(value);
|
|
92
|
-
} else if (fieldName === "retry") {
|
|
93
|
-
const retryNum = Number.parseInt(decoder.decode(value), 10);
|
|
94
|
-
if (!Number.isNaN(retryNum)) retry = retryNum;
|
|
95
|
-
}
|
|
96
|
-
},
|
|
97
|
-
flush(controller) {
|
|
98
|
-
if (event) controller.enqueue({
|
|
99
|
-
id: lastEventId || void 0,
|
|
100
|
-
event,
|
|
101
|
-
data: data.length ? decodeArraysToJson(decoder, data) : null
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
function joinArrays(data) {
|
|
107
|
-
const totalLength = data.reduce((acc, curr) => acc + curr.length, 0);
|
|
108
|
-
const merged = new Uint8Array(totalLength);
|
|
109
|
-
let offset = 0;
|
|
110
|
-
for (const c of data) {
|
|
111
|
-
merged.set(c, offset);
|
|
112
|
-
offset += c.length;
|
|
113
|
-
}
|
|
114
|
-
return merged;
|
|
115
|
-
}
|
|
116
|
-
function decodeArraysToJson(decoder, data) {
|
|
117
|
-
return JSON.parse(decoder.decode(joinArrays(data)));
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
//#endregion
|
|
121
|
-
export { BytesLineDecoder, SSEDecoder };
|
|
122
|
-
//# sourceMappingURL=sse.js.map
|
package/dist/utils/sse.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sse.js","names":["buffer: Uint8Array[]","data: Uint8Array[]","retry: number | null"],"sources":["../../src/utils/sse.ts"],"sourcesContent":["const CR = \"\\r\".charCodeAt(0);\nconst LF = \"\\n\".charCodeAt(0);\nconst NULL = \"\\0\".charCodeAt(0);\nconst COLON = \":\".charCodeAt(0);\nconst SPACE = \" \".charCodeAt(0);\n\nconst TRAILING_NEWLINE = [CR, LF];\n\nexport function BytesLineDecoder() {\n let buffer: Uint8Array[] = [];\n let trailingCr = false;\n\n return new TransformStream<Uint8Array, Uint8Array>({\n start() {\n buffer = [];\n trailingCr = false;\n },\n\n transform(chunk, controller) {\n // See https://docs.python.org/3/glossary.html#term-universal-newlines\n let text = chunk;\n\n // Handle trailing CR from previous chunk\n if (trailingCr) {\n text = joinArrays([[CR], text]);\n trailingCr = false;\n }\n\n // Check for trailing CR in current chunk\n if (text.length > 0 && text.at(-1) === CR) {\n trailingCr = true;\n text = text.subarray(0, -1);\n }\n\n if (!text.length) return;\n const trailingNewline = TRAILING_NEWLINE.includes(text.at(-1)!);\n\n const lastIdx = text.length - 1;\n const { lines } = text.reduce<{ lines: Uint8Array[]; from: number }>(\n (acc, cur, idx) => {\n if (acc.from > idx) return acc;\n\n if (cur === CR || cur === LF) {\n acc.lines.push(text.subarray(acc.from, idx));\n if (cur === CR && text[idx + 1] === LF) {\n acc.from = idx + 2;\n } else {\n acc.from = idx + 1;\n }\n }\n\n if (idx === lastIdx && acc.from <= lastIdx) {\n acc.lines.push(text.subarray(acc.from));\n }\n\n return acc;\n },\n { lines: [], from: 0 }\n );\n\n if (lines.length === 1 && !trailingNewline) {\n buffer.push(lines[0]);\n return;\n }\n\n if (buffer.length) {\n // Include existing buffer in first line\n buffer.push(lines[0]);\n lines[0] = joinArrays(buffer);\n buffer = [];\n }\n\n if (!trailingNewline) {\n // If the last segment is not newline terminated,\n // buffer it for the next chunk\n if (lines.length) buffer = [lines.pop()!];\n }\n\n // Enqueue complete lines\n for (const line of lines) {\n controller.enqueue(line);\n }\n },\n\n flush(controller) {\n if (buffer.length) {\n controller.enqueue(joinArrays(buffer));\n }\n },\n });\n}\n\ninterface StreamPart {\n id: string | undefined;\n event: string;\n data: unknown;\n}\n\nexport function SSEDecoder() {\n let event = \"\";\n let data: Uint8Array[] = [];\n let lastEventId = \"\";\n let retry: number | null = null;\n\n const decoder = new TextDecoder();\n\n return new TransformStream<Uint8Array, StreamPart>({\n transform(chunk, controller) {\n // Handle empty line case\n if (!chunk.length) {\n if (!event && !data.length && !lastEventId && retry == null) return;\n\n const sse = {\n id: lastEventId || undefined,\n event,\n data: data.length ? decodeArraysToJson(decoder, data) : null,\n };\n\n // NOTE: as per the SSE spec, do not reset lastEventId\n event = \"\";\n data = [];\n retry = null;\n\n controller.enqueue(sse);\n return;\n }\n\n // Ignore comments\n if (chunk[0] === COLON) return;\n\n const sepIdx = chunk.indexOf(COLON);\n if (sepIdx === -1) return;\n\n const fieldName = decoder.decode(chunk.subarray(0, sepIdx));\n let value = chunk.subarray(sepIdx + 1);\n if (value[0] === SPACE) value = value.subarray(1);\n\n if (fieldName === \"event\") {\n event = decoder.decode(value);\n } else if (fieldName === \"data\") {\n data.push(value);\n } else if (fieldName === \"id\") {\n if (value.indexOf(NULL) === -1) lastEventId = decoder.decode(value);\n } else if (fieldName === \"retry\") {\n const retryNum = Number.parseInt(decoder.decode(value), 10);\n if (!Number.isNaN(retryNum)) retry = retryNum;\n }\n },\n\n flush(controller) {\n if (event) {\n controller.enqueue({\n id: lastEventId || undefined,\n event,\n data: data.length ? decodeArraysToJson(decoder, data) : null,\n });\n }\n },\n });\n}\n\nfunction joinArrays(data: ArrayLike<number>[]) {\n const totalLength = data.reduce((acc, curr) => acc + curr.length, 0);\n const merged = new Uint8Array(totalLength);\n let offset = 0;\n for (const c of data) {\n merged.set(c, offset);\n offset += c.length;\n }\n return merged;\n}\n\nfunction decodeArraysToJson(decoder: TextDecoder, data: ArrayLike<number>[]) {\n return JSON.parse(decoder.decode(joinArrays(data)));\n}\n"],"mappings":";AAAA,MAAM,KAAK,KAAK,WAAW;AAC3B,MAAM,KAAK,KAAK,WAAW;AAC3B,MAAM,OAAO,KAAK,WAAW;AAC7B,MAAM,QAAQ,IAAI,WAAW;AAC7B,MAAM,QAAQ,IAAI,WAAW;AAE7B,MAAM,mBAAmB,CAAC,IAAI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SAAsB,MAA2B;AAC3E,QAAO,KAAK,MAAM,QAAQ,OAAO,WAAW"}
|
package/dist/utils/stream.cjs
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
//#region src/utils/stream.ts
|
|
3
|
-
var IterableReadableStream = class IterableReadableStream extends ReadableStream {
|
|
4
|
-
reader;
|
|
5
|
-
ensureReader() {
|
|
6
|
-
if (!this.reader) this.reader = this.getReader();
|
|
7
|
-
}
|
|
8
|
-
async next() {
|
|
9
|
-
this.ensureReader();
|
|
10
|
-
try {
|
|
11
|
-
const result = await this.reader.read();
|
|
12
|
-
if (result.done) {
|
|
13
|
-
this.reader.releaseLock();
|
|
14
|
-
return {
|
|
15
|
-
done: true,
|
|
16
|
-
value: void 0
|
|
17
|
-
};
|
|
18
|
-
} else return {
|
|
19
|
-
done: false,
|
|
20
|
-
value: result.value
|
|
21
|
-
};
|
|
22
|
-
} catch (e) {
|
|
23
|
-
this.reader.releaseLock();
|
|
24
|
-
throw e;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
async return() {
|
|
28
|
-
this.ensureReader();
|
|
29
|
-
if (this.locked) {
|
|
30
|
-
const cancelPromise = this.reader.cancel();
|
|
31
|
-
this.reader.releaseLock();
|
|
32
|
-
await cancelPromise;
|
|
33
|
-
}
|
|
34
|
-
return {
|
|
35
|
-
done: true,
|
|
36
|
-
value: void 0
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
async throw(e) {
|
|
40
|
-
this.ensureReader();
|
|
41
|
-
if (this.locked) {
|
|
42
|
-
const cancelPromise = this.reader.cancel();
|
|
43
|
-
this.reader.releaseLock();
|
|
44
|
-
await cancelPromise;
|
|
45
|
-
}
|
|
46
|
-
throw e;
|
|
47
|
-
}
|
|
48
|
-
async [Symbol.asyncDispose]() {
|
|
49
|
-
await this.return();
|
|
50
|
-
}
|
|
51
|
-
[Symbol.asyncIterator]() {
|
|
52
|
-
return this;
|
|
53
|
-
}
|
|
54
|
-
static fromReadableStream(stream) {
|
|
55
|
-
const reader = stream.getReader();
|
|
56
|
-
return new IterableReadableStream({
|
|
57
|
-
start(controller) {
|
|
58
|
-
return pump();
|
|
59
|
-
function pump() {
|
|
60
|
-
return reader.read().then(({ done, value }) => {
|
|
61
|
-
if (done) {
|
|
62
|
-
controller.close();
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
controller.enqueue(value);
|
|
66
|
-
return pump();
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
cancel() {
|
|
71
|
-
reader.releaseLock();
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
static fromAsyncGenerator(generator) {
|
|
76
|
-
return new IterableReadableStream({
|
|
77
|
-
async pull(controller) {
|
|
78
|
-
const { value, done } = await generator.next();
|
|
79
|
-
if (done) controller.close();
|
|
80
|
-
controller.enqueue(value);
|
|
81
|
-
},
|
|
82
|
-
async cancel(reason) {
|
|
83
|
-
await generator.return(reason);
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
//#endregion
|
|
90
|
-
exports.IterableReadableStream = IterableReadableStream;
|
|
91
|
-
//# sourceMappingURL=stream.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stream.cjs","names":[],"sources":["../../src/utils/stream.ts"],"sourcesContent":["// in this case don't quite match.\ntype IterableReadableStreamInterface<T> = ReadableStream<T> & AsyncIterable<T>;\n\n/*\n * Support async iterator syntax for ReadableStreams in all environments.\n * Source: https://github.com/MattiasBuelens/web-streams-polyfill/pull/122#issuecomment-1627354490\n */\nexport class IterableReadableStream<T>\n extends ReadableStream<T>\n implements IterableReadableStreamInterface<T>\n{\n public reader: ReadableStreamDefaultReader<T>;\n\n ensureReader() {\n if (!this.reader) {\n this.reader = this.getReader();\n }\n }\n\n async next(): Promise<IteratorResult<T>> {\n this.ensureReader();\n try {\n const result = await this.reader.read();\n if (result.done) {\n this.reader.releaseLock(); // release lock when stream becomes closed\n return {\n done: true,\n value: undefined,\n };\n } else {\n return {\n done: false,\n value: result.value,\n };\n }\n } catch (e) {\n this.reader.releaseLock(); // release lock when stream becomes errored\n throw e;\n }\n }\n\n async return(): Promise<IteratorResult<T>> {\n this.ensureReader();\n // If wrapped in a Node stream, cancel is already called.\n if (this.locked) {\n const cancelPromise = this.reader.cancel(); // cancel first, but don't await yet\n this.reader.releaseLock(); // release lock first\n await cancelPromise; // now await it\n }\n return { done: true, value: undefined };\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async throw(e: any): Promise<IteratorResult<T>> {\n this.ensureReader();\n if (this.locked) {\n const cancelPromise = this.reader.cancel(); // cancel first, but don't await yet\n this.reader.releaseLock(); // release lock first\n await cancelPromise; // now await it\n }\n throw e;\n }\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore Not present in Node 18 types, required in latest Node 22\n async [Symbol.asyncDispose]() {\n await this.return();\n }\n\n [Symbol.asyncIterator]() {\n return this;\n }\n\n static fromReadableStream<T>(stream: ReadableStream<T>) {\n // From https://developer.mozilla.org/en-US/docs/Web/API/Streams_API/Using_readable_streams#reading_the_stream\n const reader = stream.getReader();\n return new IterableReadableStream<T>({\n start(controller) {\n return pump();\n function pump(): Promise<T | undefined> {\n return reader.read().then(({ done, value }) => {\n // When no more data needs to be consumed, close the stream\n if (done) {\n controller.close();\n return;\n }\n // Enqueue the next data chunk into our target stream\n controller.enqueue(value);\n return pump();\n });\n }\n },\n cancel() {\n reader.releaseLock();\n },\n });\n }\n\n static fromAsyncGenerator<T>(generator: AsyncGenerator<T>) {\n return new IterableReadableStream<T>({\n async pull(controller) {\n const { value, done } = await generator.next();\n // When no more data needs to be consumed, close the stream\n if (done) {\n controller.close();\n }\n // Fix: `else if (value)` will hang the streaming when nullish value (e.g. empty string) is pulled\n controller.enqueue(value);\n },\n async cancel(reason) {\n await generator.return(reason);\n },\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OAAO"}
|
package/dist/utils/stream.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
//#region src/utils/stream.ts
|
|
2
|
-
var IterableReadableStream = class IterableReadableStream extends ReadableStream {
|
|
3
|
-
reader;
|
|
4
|
-
ensureReader() {
|
|
5
|
-
if (!this.reader) this.reader = this.getReader();
|
|
6
|
-
}
|
|
7
|
-
async next() {
|
|
8
|
-
this.ensureReader();
|
|
9
|
-
try {
|
|
10
|
-
const result = await this.reader.read();
|
|
11
|
-
if (result.done) {
|
|
12
|
-
this.reader.releaseLock();
|
|
13
|
-
return {
|
|
14
|
-
done: true,
|
|
15
|
-
value: void 0
|
|
16
|
-
};
|
|
17
|
-
} else return {
|
|
18
|
-
done: false,
|
|
19
|
-
value: result.value
|
|
20
|
-
};
|
|
21
|
-
} catch (e) {
|
|
22
|
-
this.reader.releaseLock();
|
|
23
|
-
throw e;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
async return() {
|
|
27
|
-
this.ensureReader();
|
|
28
|
-
if (this.locked) {
|
|
29
|
-
const cancelPromise = this.reader.cancel();
|
|
30
|
-
this.reader.releaseLock();
|
|
31
|
-
await cancelPromise;
|
|
32
|
-
}
|
|
33
|
-
return {
|
|
34
|
-
done: true,
|
|
35
|
-
value: void 0
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
async throw(e) {
|
|
39
|
-
this.ensureReader();
|
|
40
|
-
if (this.locked) {
|
|
41
|
-
const cancelPromise = this.reader.cancel();
|
|
42
|
-
this.reader.releaseLock();
|
|
43
|
-
await cancelPromise;
|
|
44
|
-
}
|
|
45
|
-
throw e;
|
|
46
|
-
}
|
|
47
|
-
async [Symbol.asyncDispose]() {
|
|
48
|
-
await this.return();
|
|
49
|
-
}
|
|
50
|
-
[Symbol.asyncIterator]() {
|
|
51
|
-
return this;
|
|
52
|
-
}
|
|
53
|
-
static fromReadableStream(stream) {
|
|
54
|
-
const reader = stream.getReader();
|
|
55
|
-
return new IterableReadableStream({
|
|
56
|
-
start(controller) {
|
|
57
|
-
return pump();
|
|
58
|
-
function pump() {
|
|
59
|
-
return reader.read().then(({ done, value }) => {
|
|
60
|
-
if (done) {
|
|
61
|
-
controller.close();
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
controller.enqueue(value);
|
|
65
|
-
return pump();
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
cancel() {
|
|
70
|
-
reader.releaseLock();
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
static fromAsyncGenerator(generator) {
|
|
75
|
-
return new IterableReadableStream({
|
|
76
|
-
async pull(controller) {
|
|
77
|
-
const { value, done } = await generator.next();
|
|
78
|
-
if (done) controller.close();
|
|
79
|
-
controller.enqueue(value);
|
|
80
|
-
},
|
|
81
|
-
async cancel(reason) {
|
|
82
|
-
await generator.return(reason);
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
//#endregion
|
|
89
|
-
export { IterableReadableStream };
|
|
90
|
-
//# sourceMappingURL=stream.js.map
|
package/dist/utils/stream.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stream.js","names":[],"sources":["../../src/utils/stream.ts"],"sourcesContent":["// in this case don't quite match.\ntype IterableReadableStreamInterface<T> = ReadableStream<T> & AsyncIterable<T>;\n\n/*\n * Support async iterator syntax for ReadableStreams in all environments.\n * Source: https://github.com/MattiasBuelens/web-streams-polyfill/pull/122#issuecomment-1627354490\n */\nexport class IterableReadableStream<T>\n extends ReadableStream<T>\n implements IterableReadableStreamInterface<T>\n{\n public reader: ReadableStreamDefaultReader<T>;\n\n ensureReader() {\n if (!this.reader) {\n this.reader = this.getReader();\n }\n }\n\n async next(): Promise<IteratorResult<T>> {\n this.ensureReader();\n try {\n const result = await this.reader.read();\n if (result.done) {\n this.reader.releaseLock(); // release lock when stream becomes closed\n return {\n done: true,\n value: undefined,\n };\n } else {\n return {\n done: false,\n value: result.value,\n };\n }\n } catch (e) {\n this.reader.releaseLock(); // release lock when stream becomes errored\n throw e;\n }\n }\n\n async return(): Promise<IteratorResult<T>> {\n this.ensureReader();\n // If wrapped in a Node stream, cancel is already called.\n if (this.locked) {\n const cancelPromise = this.reader.cancel(); // cancel first, but don't await yet\n this.reader.releaseLock(); // release lock first\n await cancelPromise; // now await it\n }\n return { done: true, value: undefined };\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async throw(e: any): Promise<IteratorResult<T>> {\n this.ensureReader();\n if (this.locked) {\n const cancelPromise = this.reader.cancel(); // cancel first, but don't await yet\n this.reader.releaseLock(); // release lock first\n await cancelPromise; // now await it\n }\n throw e;\n }\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore Not present in Node 18 types, required in latest Node 22\n async [Symbol.asyncDispose]() {\n await this.return();\n }\n\n [Symbol.asyncIterator]() {\n return this;\n }\n\n static fromReadableStream<T>(stream: ReadableStream<T>) {\n // From https://developer.mozilla.org/en-US/docs/Web/API/Streams_API/Using_readable_streams#reading_the_stream\n const reader = stream.getReader();\n return new IterableReadableStream<T>({\n start(controller) {\n return pump();\n function pump(): Promise<T | undefined> {\n return reader.read().then(({ done, value }) => {\n // When no more data needs to be consumed, close the stream\n if (done) {\n controller.close();\n return;\n }\n // Enqueue the next data chunk into our target stream\n controller.enqueue(value);\n return pump();\n });\n }\n },\n cancel() {\n reader.releaseLock();\n },\n });\n }\n\n static fromAsyncGenerator<T>(generator: AsyncGenerator<T>) {\n return new IterableReadableStream<T>({\n async pull(controller) {\n const { value, done } = await generator.next();\n // When no more data needs to be consumed, close the stream\n if (done) {\n controller.close();\n }\n // Fix: `else if (value)` will hang the streaming when nullish value (e.g. empty string) is pulled\n controller.enqueue(value);\n },\n async cancel(reason) {\n await generator.return(reason);\n },\n });\n }\n}\n"],"mappings":";AAOA,IAAa,yBAAb,MAAa,+BACH,eAEV;C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