@langchain/langgraph-sdk 1.3.1 → 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 -281
- 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 -1219
- package/dist/client.cjs.map +0 -1
- package/dist/client.d.cts +0 -803
- package/dist/client.d.cts.map +0 -1
- package/dist/client.d.ts +0 -803
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js +0 -1212
- 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/error.cjs +0 -17
- package/dist/utils/error.cjs.map +0 -1
- package/dist/utils/error.js +0 -16
- package/dist/utils/error.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 -176
- package/dist/utils/stream.cjs.map +0 -1
- package/dist/utils/stream.js +0 -175
- package/dist/utils/stream.js.map +0 -1
package/dist/utils/stream.js
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import { isNetworkError } from "./error.js";
|
|
2
|
-
|
|
3
|
-
//#region src/utils/stream.ts
|
|
4
|
-
/**
|
|
5
|
-
* Error thrown when maximum reconnection attempts are exceeded.
|
|
6
|
-
*/
|
|
7
|
-
var MaxReconnectAttemptsError = class extends Error {
|
|
8
|
-
constructor(maxAttempts, cause) {
|
|
9
|
-
super(`Exceeded maximum SSE reconnection attempts (${maxAttempts})`);
|
|
10
|
-
this.name = "MaxReconnectAttemptsError";
|
|
11
|
-
this.cause = cause;
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Stream with automatic retry logic for SSE connections.
|
|
16
|
-
* Implements reconnection behavior similar to the Python SDK.
|
|
17
|
-
*
|
|
18
|
-
* @param makeRequest Function to make requests. When `params` is undefined/empty, it's the initial request.
|
|
19
|
-
* When `params.lastEventId` is provided, it's a reconnection request.
|
|
20
|
-
* @param options Configuration options
|
|
21
|
-
* @returns AsyncGenerator yielding stream events
|
|
22
|
-
*/
|
|
23
|
-
async function* streamWithRetry(makeRequest, options = {}) {
|
|
24
|
-
const maxRetries = options.maxRetries ?? 5;
|
|
25
|
-
let attempt = 0;
|
|
26
|
-
let lastEventId;
|
|
27
|
-
let reconnectPath;
|
|
28
|
-
while (true) {
|
|
29
|
-
let shouldRetry = false;
|
|
30
|
-
let lastError;
|
|
31
|
-
let reader;
|
|
32
|
-
try {
|
|
33
|
-
if (options.signal?.aborted) return;
|
|
34
|
-
const { response, stream } = await makeRequest(lastEventId ? {
|
|
35
|
-
lastEventId,
|
|
36
|
-
reconnectPath
|
|
37
|
-
} : void 0);
|
|
38
|
-
const locationHeader = response.headers.get("location");
|
|
39
|
-
if (locationHeader) reconnectPath = locationHeader;
|
|
40
|
-
const contentType = response.headers.get("content-type")?.split(";")[0];
|
|
41
|
-
if (contentType && !contentType.includes("text/event-stream")) throw new Error(`Expected response header Content-Type to contain 'text/event-stream', got '${contentType}'`);
|
|
42
|
-
reader = stream.getReader();
|
|
43
|
-
try {
|
|
44
|
-
while (true) {
|
|
45
|
-
if (options.signal?.aborted) {
|
|
46
|
-
await reader.cancel();
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
const { done, value } = await reader.read();
|
|
50
|
-
if (done) break;
|
|
51
|
-
if (value.id) lastEventId = value.id;
|
|
52
|
-
yield value;
|
|
53
|
-
}
|
|
54
|
-
break;
|
|
55
|
-
} catch (error) {
|
|
56
|
-
if (lastEventId && reconnectPath && !options.signal?.aborted) shouldRetry = true;
|
|
57
|
-
else throw error;
|
|
58
|
-
} finally {
|
|
59
|
-
if (reader) try {
|
|
60
|
-
reader.releaseLock();
|
|
61
|
-
} catch {}
|
|
62
|
-
}
|
|
63
|
-
} catch (error) {
|
|
64
|
-
lastError = error;
|
|
65
|
-
if (isNetworkError(error) && lastEventId && reconnectPath && !options.signal?.aborted) shouldRetry = true;
|
|
66
|
-
else throw error;
|
|
67
|
-
}
|
|
68
|
-
if (shouldRetry) {
|
|
69
|
-
attempt += 1;
|
|
70
|
-
if (attempt > maxRetries) throw new MaxReconnectAttemptsError(maxRetries, lastError);
|
|
71
|
-
options.onReconnect?.({
|
|
72
|
-
attempt,
|
|
73
|
-
lastEventId,
|
|
74
|
-
cause: lastError
|
|
75
|
-
});
|
|
76
|
-
const baseDelay = Math.min(1e3 * 2 ** (attempt - 1), 5e3);
|
|
77
|
-
const jitter = Math.random() * 1e3;
|
|
78
|
-
const delay = baseDelay + jitter;
|
|
79
|
-
await new Promise((resolve) => {
|
|
80
|
-
setTimeout(resolve, delay);
|
|
81
|
-
});
|
|
82
|
-
continue;
|
|
83
|
-
}
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
var IterableReadableStream = class IterableReadableStream extends ReadableStream {
|
|
88
|
-
reader;
|
|
89
|
-
ensureReader() {
|
|
90
|
-
if (!this.reader) this.reader = this.getReader();
|
|
91
|
-
}
|
|
92
|
-
async next() {
|
|
93
|
-
this.ensureReader();
|
|
94
|
-
try {
|
|
95
|
-
const result = await this.reader.read();
|
|
96
|
-
if (result.done) {
|
|
97
|
-
this.reader.releaseLock();
|
|
98
|
-
return {
|
|
99
|
-
done: true,
|
|
100
|
-
value: void 0
|
|
101
|
-
};
|
|
102
|
-
} else return {
|
|
103
|
-
done: false,
|
|
104
|
-
value: result.value
|
|
105
|
-
};
|
|
106
|
-
} catch (e) {
|
|
107
|
-
this.reader.releaseLock();
|
|
108
|
-
throw e;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
async return() {
|
|
112
|
-
this.ensureReader();
|
|
113
|
-
if (this.locked) {
|
|
114
|
-
const cancelPromise = this.reader.cancel();
|
|
115
|
-
this.reader.releaseLock();
|
|
116
|
-
await cancelPromise;
|
|
117
|
-
}
|
|
118
|
-
return {
|
|
119
|
-
done: true,
|
|
120
|
-
value: void 0
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
async throw(e) {
|
|
124
|
-
this.ensureReader();
|
|
125
|
-
if (this.locked) {
|
|
126
|
-
const cancelPromise = this.reader.cancel();
|
|
127
|
-
this.reader.releaseLock();
|
|
128
|
-
await cancelPromise;
|
|
129
|
-
}
|
|
130
|
-
throw e;
|
|
131
|
-
}
|
|
132
|
-
async [Symbol.asyncDispose]() {
|
|
133
|
-
await this.return();
|
|
134
|
-
}
|
|
135
|
-
[Symbol.asyncIterator]() {
|
|
136
|
-
return this;
|
|
137
|
-
}
|
|
138
|
-
static fromReadableStream(stream) {
|
|
139
|
-
const reader = stream.getReader();
|
|
140
|
-
return new IterableReadableStream({
|
|
141
|
-
start(controller) {
|
|
142
|
-
return pump();
|
|
143
|
-
function pump() {
|
|
144
|
-
return reader.read().then(({ done, value }) => {
|
|
145
|
-
if (done) {
|
|
146
|
-
controller.close();
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
controller.enqueue(value);
|
|
150
|
-
return pump();
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
},
|
|
154
|
-
cancel() {
|
|
155
|
-
reader.releaseLock();
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
static fromAsyncGenerator(generator) {
|
|
160
|
-
return new IterableReadableStream({
|
|
161
|
-
async pull(controller) {
|
|
162
|
-
const { value, done } = await generator.next();
|
|
163
|
-
if (done) controller.close();
|
|
164
|
-
controller.enqueue(value);
|
|
165
|
-
},
|
|
166
|
-
async cancel(reason) {
|
|
167
|
-
await generator.return(reason);
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
//#endregion
|
|
174
|
-
export { IterableReadableStream, streamWithRetry };
|
|
175
|
-
//# sourceMappingURL=stream.js.map
|
package/dist/utils/stream.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stream.js","names":["lastEventId: string | undefined","reconnectPath: string | undefined","lastError: unknown","reader: ReadableStreamDefaultReader<T> | undefined"],"sources":["../../src/utils/stream.ts"],"sourcesContent":["import { isNetworkError } from \"./error.js\";\n\n// in this case don't quite match.\ntype IterableReadableStreamInterface<T> = ReadableStream<T> & AsyncIterable<T>;\n\n/**\n * Options for streaming with automatic retry logic.\n */\nexport interface StreamWithRetryOptions {\n /**\n * Maximum number of reconnection attempts. Default is 5.\n */\n maxRetries?: number;\n\n /**\n * AbortSignal to cancel the stream.\n */\n signal?: AbortSignal;\n\n /**\n * Callback invoked when a reconnection attempt is made.\n */\n onReconnect?: (options: {\n attempt: number;\n lastEventId?: string;\n cause: unknown;\n }) => void;\n}\n\n/**\n * Parameters for making a stream request\n */\nexport interface StreamRequestParams {\n /**\n * If provided, this is a reconnection request with the last event ID\n */\n lastEventId?: string;\n\n /**\n * Optional reconnection path from the Location header\n */\n reconnectPath?: string;\n}\n\n/**\n * Error thrown when maximum reconnection attempts are exceeded.\n */\nexport class MaxReconnectAttemptsError extends Error {\n constructor(maxAttempts: number, cause: unknown) {\n super(`Exceeded maximum SSE reconnection attempts (${maxAttempts})`);\n this.name = \"MaxReconnectAttemptsError\";\n this.cause = cause;\n }\n}\n\n/**\n * Stream with automatic retry logic for SSE connections.\n * Implements reconnection behavior similar to the Python SDK.\n *\n * @param makeRequest Function to make requests. When `params` is undefined/empty, it's the initial request.\n * When `params.lastEventId` is provided, it's a reconnection request.\n * @param options Configuration options\n * @returns AsyncGenerator yielding stream events\n */\nexport async function* streamWithRetry<T extends { id?: string }>(\n makeRequest: (params?: StreamRequestParams) => Promise<{\n response: Response;\n stream: ReadableStream<T>;\n }>,\n options: StreamWithRetryOptions = {}\n): AsyncGenerator<T> {\n const maxRetries = options.maxRetries ?? 5;\n let attempt = 0;\n let lastEventId: string | undefined;\n let reconnectPath: string | undefined;\n\n while (true) {\n let shouldRetry = false;\n let lastError: unknown;\n let reader: ReadableStreamDefaultReader<T> | undefined;\n\n try {\n // Check if aborted before making request\n if (options.signal?.aborted) return;\n\n // Make request - initial if no lastEventId, reconnect otherwise\n const { response, stream } = await makeRequest(\n lastEventId ? { lastEventId, reconnectPath } : undefined\n );\n\n // Check for Location header (server-provided reconnection path)\n const locationHeader = response.headers.get(\"location\");\n if (locationHeader) {\n reconnectPath = locationHeader;\n }\n\n // Verify content type\n const contentType = response.headers.get(\"content-type\")?.split(\";\")[0];\n if (contentType && !contentType.includes(\"text/event-stream\")) {\n throw new Error(\n `Expected response header Content-Type to contain 'text/event-stream', got '${contentType}'`\n );\n }\n\n reader = stream.getReader();\n\n try {\n while (true) {\n // Check abort signal before each read\n if (options.signal?.aborted) {\n await reader.cancel();\n return;\n }\n\n const { done, value } = await reader.read();\n\n if (done) {\n // Stream completed successfully\n break;\n }\n\n // Track last event ID for reconnection\n if (value.id) {\n lastEventId = value.id;\n }\n\n yield value;\n }\n\n // Stream completed successfully, exit retry loop\n break;\n } catch (error) {\n // Error during streaming - attempt reconnect if we have lastEventId and a location header\n if (lastEventId && reconnectPath && !options.signal?.aborted) {\n shouldRetry = true;\n } else {\n throw error;\n }\n } finally {\n if (reader) {\n try {\n reader.releaseLock();\n } catch {\n // Ignore errors when releasing lock\n }\n }\n }\n } catch (error) {\n lastError = error;\n\n // Only retry if we have reconnection capability and it's a network error\n if (\n isNetworkError(error) &&\n lastEventId &&\n reconnectPath &&\n !options.signal?.aborted\n ) {\n shouldRetry = true;\n } else {\n throw error;\n }\n }\n\n if (shouldRetry) {\n attempt += 1;\n if (attempt > maxRetries) {\n throw new MaxReconnectAttemptsError(maxRetries, lastError);\n }\n\n // Notify about reconnection attempt\n options.onReconnect?.({ attempt, lastEventId, cause: lastError });\n\n // Exponential backoff with jitter: min(1000 * 2^attempt, 5000) + random jitter\n const baseDelay = Math.min(1000 * 2 ** (attempt - 1), 5000);\n const jitter = Math.random() * 1000;\n const delay = baseDelay + jitter;\n\n await new Promise((resolve) => {\n setTimeout(resolve, delay);\n });\n\n continue;\n }\n\n // Successfully completed\n break;\n }\n}\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":";;;;;;AA+CA,IAAa,4BAAb,cAA+C,MAAM;CACnD,YAAY,aAAqB,OAAgB;AAC/C,QAAM,+CAA+C,YAAY;AACjE,OAAK,OAAO;AACZ,OAAK,QAAQ;;;;;;;;;;;;AAajB,gBAAuB,gBACrB,aAIA,UAAkC,IACf;CACnB,MAAM,aAAa,QAAQ,cAAc;CACzC,IAAI,UAAU;CACd,IAAIA;CACJ,IAAIC;AAEJ,QAAO,MAAM;EACX,IAAI,cAAc;EAClB,IAAIC;EACJ,IAAIC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