@langchain/core 0.1.23 → 0.1.24

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.
@@ -0,0 +1,374 @@
1
+ import { Runnable } from "./base.js";
2
+ import { Document } from "../documents/index.js";
3
+ import { ChatPromptValue, StringPromptValue } from "../prompt_values.js";
4
+ import { LogStreamCallbackHandler, } from "../tracers/log_stream.js";
5
+ import { AIMessage, AIMessageChunk, ChatMessage, ChatMessageChunk, FunctionMessage, FunctionMessageChunk, HumanMessage, HumanMessageChunk, SystemMessage, SystemMessageChunk, ToolMessage, ToolMessageChunk, isBaseMessage, } from "../messages/index.js";
6
+ import { GenerationChunk, ChatGenerationChunk, RUN_KEY } from "../outputs.js";
7
+ import { getBytes, getLines, getMessages, convertEventStreamToIterableReadableDataStream, } from "../utils/event_source_parse.js";
8
+ import { IterableReadableStream } from "../utils/stream.js";
9
+ function isSuperset(set, subset) {
10
+ for (const elem of subset) {
11
+ if (!set.has(elem)) {
12
+ return false;
13
+ }
14
+ }
15
+ return true;
16
+ }
17
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
+ function revive(obj) {
19
+ if (Array.isArray(obj))
20
+ return obj.map(revive);
21
+ if (typeof obj === "object") {
22
+ // eslint-disable-next-line no-instanceof/no-instanceof
23
+ if (!obj || obj instanceof Date) {
24
+ return obj;
25
+ }
26
+ const keysArr = Object.keys(obj);
27
+ const keys = new Set(keysArr);
28
+ if (isSuperset(keys, new Set(["page_content", "metadata"]))) {
29
+ return new Document({
30
+ pageContent: obj.page_content,
31
+ metadata: obj.metadata,
32
+ });
33
+ }
34
+ if (isSuperset(keys, new Set(["content", "type", "additional_kwargs"]))) {
35
+ if (obj.type === "HumanMessage" || obj.type === "human") {
36
+ return new HumanMessage({
37
+ content: obj.content,
38
+ });
39
+ }
40
+ if (obj.type === "SystemMessage" || obj.type === "system") {
41
+ return new SystemMessage({
42
+ content: obj.content,
43
+ });
44
+ }
45
+ if (obj.type === "ChatMessage" || obj.type === "chat") {
46
+ return new ChatMessage({
47
+ content: obj.content,
48
+ role: obj.role,
49
+ });
50
+ }
51
+ if (obj.type === "FunctionMessage" || obj.type === "function") {
52
+ return new FunctionMessage({
53
+ content: obj.content,
54
+ name: obj.name,
55
+ });
56
+ }
57
+ if (obj.type === "ToolMessage" || obj.type === "tool") {
58
+ return new ToolMessage({
59
+ content: obj.content,
60
+ tool_call_id: obj.tool_call_id,
61
+ });
62
+ }
63
+ if (obj.type === "AIMessage" || obj.type === "ai") {
64
+ return new AIMessage({
65
+ content: obj.content,
66
+ });
67
+ }
68
+ if (obj.type === "HumanMessageChunk") {
69
+ return new HumanMessageChunk({
70
+ content: obj.content,
71
+ });
72
+ }
73
+ if (obj.type === "SystemMessageChunk") {
74
+ return new SystemMessageChunk({
75
+ content: obj.content,
76
+ });
77
+ }
78
+ if (obj.type === "ChatMessageChunk") {
79
+ return new ChatMessageChunk({
80
+ content: obj.content,
81
+ role: obj.role,
82
+ });
83
+ }
84
+ if (obj.type === "FunctionMessageChunk") {
85
+ return new FunctionMessageChunk({
86
+ content: obj.content,
87
+ name: obj.name,
88
+ });
89
+ }
90
+ if (obj.type === "ToolMessageChunk") {
91
+ return new ToolMessageChunk({
92
+ content: obj.content,
93
+ tool_call_id: obj.tool_call_id,
94
+ });
95
+ }
96
+ if (obj.type === "AIMessageChunk") {
97
+ return new AIMessageChunk({
98
+ content: obj.content,
99
+ });
100
+ }
101
+ }
102
+ if (isSuperset(keys, new Set(["text", "generation_info", "type"]))) {
103
+ if (obj.type === "ChatGenerationChunk") {
104
+ return new ChatGenerationChunk({
105
+ message: revive(obj.message),
106
+ text: obj.text,
107
+ generationInfo: obj.generation_info,
108
+ });
109
+ }
110
+ else if (obj.type === "ChatGeneration") {
111
+ return {
112
+ message: revive(obj.message),
113
+ text: obj.text,
114
+ generationInfo: obj.generation_info,
115
+ };
116
+ }
117
+ else if (obj.type === "GenerationChunk") {
118
+ return new GenerationChunk({
119
+ text: obj.text,
120
+ generationInfo: obj.generation_info,
121
+ });
122
+ }
123
+ else if (obj.type === "Generation") {
124
+ return {
125
+ text: obj.text,
126
+ generationInfo: obj.generation_info,
127
+ };
128
+ }
129
+ }
130
+ if (isSuperset(keys, new Set(["tool", "tool_input", "log", "type"]))) {
131
+ if (obj.type === "AgentAction") {
132
+ return {
133
+ tool: obj.tool,
134
+ toolInput: obj.tool_input,
135
+ log: obj.log,
136
+ };
137
+ }
138
+ }
139
+ if (isSuperset(keys, new Set(["return_values", "log", "type"]))) {
140
+ if (obj.type === "AgentFinish") {
141
+ return {
142
+ returnValues: obj.return_values,
143
+ log: obj.log,
144
+ };
145
+ }
146
+ }
147
+ if (isSuperset(keys, new Set(["generations", "run", "type"]))) {
148
+ if (obj.type === "LLMResult") {
149
+ return {
150
+ generations: revive(obj.generations),
151
+ llmOutput: obj.llm_output,
152
+ [RUN_KEY]: obj.run,
153
+ };
154
+ }
155
+ }
156
+ if (isSuperset(keys, new Set(["messages"]))) {
157
+ // TODO: Start checking for type: ChatPromptValue and ChatPromptValueConcrete
158
+ // when LangServe bug is fixed
159
+ return new ChatPromptValue({
160
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
161
+ messages: obj.messages.map((msg) => revive(msg)),
162
+ });
163
+ }
164
+ if (isSuperset(keys, new Set(["text"]))) {
165
+ // TODO: Start checking for type: StringPromptValue
166
+ // when LangServe bug is fixed
167
+ return new StringPromptValue(obj.text);
168
+ }
169
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
170
+ const innerRevive = (key) => [
171
+ key,
172
+ revive(obj[key]),
173
+ ];
174
+ const rtn = Object.fromEntries(keysArr.map(innerRevive));
175
+ return rtn;
176
+ }
177
+ return obj;
178
+ }
179
+ function deserialize(str) {
180
+ const obj = JSON.parse(str);
181
+ return revive(obj);
182
+ }
183
+ function removeCallbacks(options) {
184
+ const rest = { ...options };
185
+ delete rest.callbacks;
186
+ return rest;
187
+ }
188
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
189
+ function serialize(input) {
190
+ if (Array.isArray(input))
191
+ return input.map(serialize);
192
+ if (isBaseMessage(input)) {
193
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
194
+ const serializedMessage = {
195
+ content: input.content,
196
+ type: input._getType(),
197
+ additional_kwargs: input.additional_kwargs,
198
+ name: input.name,
199
+ example: false,
200
+ };
201
+ if (ToolMessage.isInstance(input)) {
202
+ serializedMessage.tool_call_id = input.tool_call_id;
203
+ }
204
+ else if (ChatMessage.isInstance(input)) {
205
+ serializedMessage.role = input.role;
206
+ }
207
+ return serializedMessage;
208
+ }
209
+ if (typeof input === "object") {
210
+ // eslint-disable-next-line no-instanceof/no-instanceof
211
+ if (!input || input instanceof Date) {
212
+ return input;
213
+ }
214
+ const keysArr = Object.keys(input);
215
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
216
+ const innerSerialize = (key) => [
217
+ key,
218
+ serialize(input[key]),
219
+ ];
220
+ const rtn = Object.fromEntries(keysArr.map(innerSerialize));
221
+ return rtn;
222
+ }
223
+ return input;
224
+ }
225
+ export class RemoteRunnable extends Runnable {
226
+ constructor(fields) {
227
+ super(fields);
228
+ Object.defineProperty(this, "url", {
229
+ enumerable: true,
230
+ configurable: true,
231
+ writable: true,
232
+ value: void 0
233
+ });
234
+ Object.defineProperty(this, "options", {
235
+ enumerable: true,
236
+ configurable: true,
237
+ writable: true,
238
+ value: void 0
239
+ });
240
+ Object.defineProperty(this, "lc_namespace", {
241
+ enumerable: true,
242
+ configurable: true,
243
+ writable: true,
244
+ value: ["langchain", "schema", "runnable", "remote"]
245
+ });
246
+ const { url, options } = fields;
247
+ this.url = url.replace(/\/$/, ""); // remove trailing slash
248
+ this.options = options;
249
+ }
250
+ async post(path, body) {
251
+ return fetch(`${this.url}${path}`, {
252
+ method: "POST",
253
+ body: JSON.stringify(serialize(body)),
254
+ headers: {
255
+ "Content-Type": "application/json",
256
+ ...this.options?.headers,
257
+ },
258
+ signal: AbortSignal.timeout(this.options?.timeout ?? 60000),
259
+ });
260
+ }
261
+ async invoke(input, options) {
262
+ const [config, kwargs] = this._separateRunnableConfigFromCallOptions(options);
263
+ const response = await this.post("/invoke", {
264
+ input,
265
+ config: removeCallbacks(config),
266
+ kwargs: kwargs ?? {},
267
+ });
268
+ return revive((await response.json()).output);
269
+ }
270
+ async _batch(inputs, options, _, batchOptions) {
271
+ if (batchOptions?.returnExceptions) {
272
+ throw new Error("returnExceptions is not supported for remote clients");
273
+ }
274
+ const configsAndKwargsArray = options?.map((opts) => this._separateRunnableConfigFromCallOptions(opts));
275
+ const [configs, kwargs] = configsAndKwargsArray?.reduce(([pc, pk], [c, k]) => [
276
+ [...pc, c],
277
+ [...pk, k],
278
+ ], [[], []]) ?? [undefined, undefined];
279
+ const response = await this.post("/batch", {
280
+ inputs,
281
+ config: (configs ?? [])
282
+ .map(removeCallbacks)
283
+ .map((config) => ({ ...config, ...batchOptions })),
284
+ kwargs,
285
+ });
286
+ const body = await response.json();
287
+ if (!body.output)
288
+ throw new Error("Invalid response from remote runnable");
289
+ return revive(body.output);
290
+ }
291
+ async batch(inputs, options, batchOptions) {
292
+ if (batchOptions?.returnExceptions) {
293
+ throw Error("returnExceptions is not supported for remote clients");
294
+ }
295
+ return this._batchWithConfig(this._batch.bind(this), inputs, options, batchOptions);
296
+ }
297
+ async stream(input, options) {
298
+ const [config, kwargs] = this._separateRunnableConfigFromCallOptions(options);
299
+ const response = await this.post("/stream", {
300
+ input,
301
+ config: removeCallbacks(config),
302
+ kwargs,
303
+ });
304
+ if (!response.ok) {
305
+ const json = await response.json();
306
+ const error = new Error(`RemoteRunnable call failed with status code ${response.status}: ${json.message}`);
307
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
308
+ error.response = response;
309
+ throw error;
310
+ }
311
+ const { body } = response;
312
+ if (!body) {
313
+ throw new Error("Could not begin remote stream. Please check the given URL and try again.");
314
+ }
315
+ const stream = new ReadableStream({
316
+ async start(controller) {
317
+ const enqueueLine = getMessages((msg) => {
318
+ if (msg.data)
319
+ controller.enqueue(deserialize(msg.data));
320
+ });
321
+ const onLine = (line, fieldLength, flush) => {
322
+ enqueueLine(line, fieldLength, flush);
323
+ if (flush)
324
+ controller.close();
325
+ };
326
+ await getBytes(body, getLines(onLine));
327
+ },
328
+ });
329
+ return IterableReadableStream.fromReadableStream(stream);
330
+ }
331
+ async *streamLog(input, options, streamOptions) {
332
+ const [config, kwargs] = this._separateRunnableConfigFromCallOptions(options);
333
+ const stream = new LogStreamCallbackHandler({
334
+ ...streamOptions,
335
+ autoClose: false,
336
+ });
337
+ const { callbacks } = config;
338
+ if (callbacks === undefined) {
339
+ config.callbacks = [stream];
340
+ }
341
+ else if (Array.isArray(callbacks)) {
342
+ config.callbacks = callbacks.concat([stream]);
343
+ }
344
+ else {
345
+ const copiedCallbacks = callbacks.copy();
346
+ copiedCallbacks.inheritableHandlers.push(stream);
347
+ config.callbacks = copiedCallbacks;
348
+ }
349
+ // The type is in camelCase but the API only accepts snake_case.
350
+ const camelCaseStreamOptions = {
351
+ include_names: streamOptions?.includeNames,
352
+ include_types: streamOptions?.includeTypes,
353
+ include_tags: streamOptions?.includeTags,
354
+ exclude_names: streamOptions?.excludeNames,
355
+ exclude_types: streamOptions?.excludeTypes,
356
+ exclude_tags: streamOptions?.excludeTags,
357
+ };
358
+ const response = await this.post("/stream_log", {
359
+ input,
360
+ config: removeCallbacks(config),
361
+ kwargs,
362
+ ...camelCaseStreamOptions,
363
+ diff: false,
364
+ });
365
+ const { body } = response;
366
+ if (!body) {
367
+ throw new Error("Could not begin remote stream log. Please check the given URL and try again.");
368
+ }
369
+ const runnableStream = convertEventStreamToIterableReadableDataStream(body);
370
+ for await (const log of runnableStream) {
371
+ yield revive(JSON.parse(log));
372
+ }
373
+ }
374
+ }
@@ -0,0 +1,226 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.convertEventStreamToIterableReadableDataStream = exports.getMessages = exports.getLines = exports.getBytes = exports.EventStreamContentType = void 0;
4
+ const stream_js_1 = require("./stream.cjs");
5
+ exports.EventStreamContentType = "text/event-stream";
6
+ function isNodeJSReadable(x) {
7
+ return x != null && typeof x === "object" && "on" in x;
8
+ }
9
+ /**
10
+ * Converts a ReadableStream into a callback pattern.
11
+ * @param stream The input ReadableStream.
12
+ * @param onChunk A function that will be called on each new byte chunk in the stream.
13
+ * @returns {Promise<void>} A promise that will be resolved when the stream closes.
14
+ */
15
+ async function getBytes(stream, onChunk) {
16
+ // stream is a Node.js Readable / PassThrough stream
17
+ // this can happen if node-fetch is polyfilled
18
+ if (isNodeJSReadable(stream)) {
19
+ return new Promise((resolve) => {
20
+ stream.on("readable", () => {
21
+ let chunk;
22
+ // eslint-disable-next-line no-constant-condition
23
+ while (true) {
24
+ chunk = stream.read();
25
+ if (chunk == null) {
26
+ onChunk(new Uint8Array(), true);
27
+ break;
28
+ }
29
+ onChunk(chunk);
30
+ }
31
+ resolve();
32
+ });
33
+ });
34
+ }
35
+ const reader = stream.getReader();
36
+ // CHANGED: Introduced a "flush" mechanism to process potential pending messages when the stream ends.
37
+ // This change is essential to ensure that we capture every last piece of information from streams,
38
+ // such as those from Azure OpenAI, which may not terminate with a blank line. Without this
39
+ // mechanism, we risk ignoring a possibly significant last message.
40
+ // See https://github.com/langchain-ai/langchainjs/issues/1299 for details.
41
+ // eslint-disable-next-line no-constant-condition
42
+ while (true) {
43
+ const result = await reader.read();
44
+ if (result.done) {
45
+ onChunk(new Uint8Array(), true);
46
+ break;
47
+ }
48
+ onChunk(result.value);
49
+ }
50
+ }
51
+ exports.getBytes = getBytes;
52
+ /**
53
+ * Parses arbitary byte chunks into EventSource line buffers.
54
+ * Each line should be of the format "field: value" and ends with \r, \n, or \r\n.
55
+ * @param onLine A function that will be called on each new EventSource line.
56
+ * @returns A function that should be called for each incoming byte chunk.
57
+ */
58
+ function getLines(onLine) {
59
+ let buffer;
60
+ let position; // current read position
61
+ let fieldLength; // length of the `field` portion of the line
62
+ let discardTrailingNewline = false;
63
+ // return a function that can process each incoming byte chunk:
64
+ return function onChunk(arr, flush) {
65
+ if (flush) {
66
+ onLine(arr, 0, true);
67
+ return;
68
+ }
69
+ if (buffer === undefined) {
70
+ buffer = arr;
71
+ position = 0;
72
+ fieldLength = -1;
73
+ }
74
+ else {
75
+ // we're still parsing the old line. Append the new bytes into buffer:
76
+ buffer = concat(buffer, arr);
77
+ }
78
+ const bufLength = buffer.length;
79
+ let lineStart = 0; // index where the current line starts
80
+ while (position < bufLength) {
81
+ if (discardTrailingNewline) {
82
+ if (buffer[position] === 10 /* ControlChars.NewLine */) {
83
+ lineStart = ++position; // skip to next char
84
+ }
85
+ discardTrailingNewline = false;
86
+ }
87
+ // start looking forward till the end of line:
88
+ let lineEnd = -1; // index of the \r or \n char
89
+ for (; position < bufLength && lineEnd === -1; ++position) {
90
+ switch (buffer[position]) {
91
+ case 58 /* ControlChars.Colon */:
92
+ if (fieldLength === -1) {
93
+ // first colon in line
94
+ fieldLength = position - lineStart;
95
+ }
96
+ break;
97
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
98
+ // @ts-ignore:7029 \r case below should fallthrough to \n:
99
+ case 13 /* ControlChars.CarriageReturn */:
100
+ discardTrailingNewline = true;
101
+ // eslint-disable-next-line no-fallthrough
102
+ case 10 /* ControlChars.NewLine */:
103
+ lineEnd = position;
104
+ break;
105
+ }
106
+ }
107
+ if (lineEnd === -1) {
108
+ // We reached the end of the buffer but the line hasn't ended.
109
+ // Wait for the next arr and then continue parsing:
110
+ break;
111
+ }
112
+ // we've reached the line end, send it out:
113
+ onLine(buffer.subarray(lineStart, lineEnd), fieldLength);
114
+ lineStart = position; // we're now on the next line
115
+ fieldLength = -1;
116
+ }
117
+ if (lineStart === bufLength) {
118
+ buffer = undefined; // we've finished reading it
119
+ }
120
+ else if (lineStart !== 0) {
121
+ // Create a new view into buffer beginning at lineStart so we don't
122
+ // need to copy over the previous lines when we get the new arr:
123
+ buffer = buffer.subarray(lineStart);
124
+ position -= lineStart;
125
+ }
126
+ };
127
+ }
128
+ exports.getLines = getLines;
129
+ /**
130
+ * Parses line buffers into EventSourceMessages.
131
+ * @param onId A function that will be called on each `id` field.
132
+ * @param onRetry A function that will be called on each `retry` field.
133
+ * @param onMessage A function that will be called on each message.
134
+ * @returns A function that should be called for each incoming line buffer.
135
+ */
136
+ function getMessages(onMessage, onId, onRetry) {
137
+ let message = newMessage();
138
+ const decoder = new TextDecoder();
139
+ // return a function that can process each incoming line buffer:
140
+ return function onLine(line, fieldLength, flush) {
141
+ if (flush) {
142
+ if (!isEmpty(message)) {
143
+ onMessage?.(message);
144
+ message = newMessage();
145
+ }
146
+ return;
147
+ }
148
+ if (line.length === 0) {
149
+ // empty line denotes end of message. Trigger the callback and start a new message:
150
+ onMessage?.(message);
151
+ message = newMessage();
152
+ }
153
+ else if (fieldLength > 0) {
154
+ // exclude comments and lines with no values
155
+ // line is of format "<field>:<value>" or "<field>: <value>"
156
+ // https://html.spec.whatwg.org/multipage/server-sent-events.html#event-stream-interpretation
157
+ const field = decoder.decode(line.subarray(0, fieldLength));
158
+ const valueOffset = fieldLength + (line[fieldLength + 1] === 32 /* ControlChars.Space */ ? 2 : 1);
159
+ const value = decoder.decode(line.subarray(valueOffset));
160
+ switch (field) {
161
+ case "data":
162
+ // if this message already has data, append the new value to the old.
163
+ // otherwise, just set to the new value:
164
+ message.data = message.data ? message.data + "\n" + value : value; // otherwise,
165
+ break;
166
+ case "event":
167
+ message.event = value;
168
+ break;
169
+ case "id":
170
+ onId?.((message.id = value));
171
+ break;
172
+ case "retry": {
173
+ const retry = parseInt(value, 10);
174
+ if (!Number.isNaN(retry)) {
175
+ // per spec, ignore non-integers
176
+ onRetry?.((message.retry = retry));
177
+ }
178
+ break;
179
+ }
180
+ }
181
+ }
182
+ };
183
+ }
184
+ exports.getMessages = getMessages;
185
+ function concat(a, b) {
186
+ const res = new Uint8Array(a.length + b.length);
187
+ res.set(a);
188
+ res.set(b, a.length);
189
+ return res;
190
+ }
191
+ function newMessage() {
192
+ // data, event, and id must be initialized to empty strings:
193
+ // https://html.spec.whatwg.org/multipage/server-sent-events.html#event-stream-interpretation
194
+ // retry should be initialized to undefined so we return a consistent shape
195
+ // to the js engine all the time: https://mathiasbynens.be/notes/shapes-ics#takeaways
196
+ return {
197
+ data: "",
198
+ event: "",
199
+ id: "",
200
+ retry: undefined,
201
+ };
202
+ }
203
+ function convertEventStreamToIterableReadableDataStream(stream) {
204
+ const dataStream = new ReadableStream({
205
+ async start(controller) {
206
+ const enqueueLine = getMessages((msg) => {
207
+ if (msg.data)
208
+ controller.enqueue(msg.data);
209
+ });
210
+ const onLine = (line, fieldLength, flush) => {
211
+ enqueueLine(line, fieldLength, flush);
212
+ if (flush)
213
+ controller.close();
214
+ };
215
+ await getBytes(stream, getLines(onLine));
216
+ },
217
+ });
218
+ return stream_js_1.IterableReadableStream.fromReadableStream(dataStream);
219
+ }
220
+ exports.convertEventStreamToIterableReadableDataStream = convertEventStreamToIterableReadableDataStream;
221
+ function isEmpty(message) {
222
+ return (message.data === "" &&
223
+ message.event === "" &&
224
+ message.id === "" &&
225
+ message.retry === undefined);
226
+ }
@@ -0,0 +1,39 @@
1
+ import { IterableReadableStream } from "./stream.js";
2
+ export declare const EventStreamContentType = "text/event-stream";
3
+ /**
4
+ * Represents a message sent in an event stream
5
+ * https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format
6
+ */
7
+ export interface EventSourceMessage {
8
+ /** The event ID to set the EventSource object's last event ID value. */
9
+ id: string;
10
+ /** A string identifying the type of event described. */
11
+ event: string;
12
+ /** The event data */
13
+ data: string;
14
+ /** The reconnection interval (in milliseconds) to wait before retrying the connection */
15
+ retry?: number;
16
+ }
17
+ /**
18
+ * Converts a ReadableStream into a callback pattern.
19
+ * @param stream The input ReadableStream.
20
+ * @param onChunk A function that will be called on each new byte chunk in the stream.
21
+ * @returns {Promise<void>} A promise that will be resolved when the stream closes.
22
+ */
23
+ export declare function getBytes(stream: ReadableStream<Uint8Array>, onChunk: (arr: Uint8Array, flush?: boolean) => void): Promise<void>;
24
+ /**
25
+ * Parses arbitary byte chunks into EventSource line buffers.
26
+ * Each line should be of the format "field: value" and ends with \r, \n, or \r\n.
27
+ * @param onLine A function that will be called on each new EventSource line.
28
+ * @returns A function that should be called for each incoming byte chunk.
29
+ */
30
+ export declare function getLines(onLine: (line: Uint8Array, fieldLength: number, flush?: boolean) => void): (arr: Uint8Array, flush?: boolean) => void;
31
+ /**
32
+ * Parses line buffers into EventSourceMessages.
33
+ * @param onId A function that will be called on each `id` field.
34
+ * @param onRetry A function that will be called on each `retry` field.
35
+ * @param onMessage A function that will be called on each message.
36
+ * @returns A function that should be called for each incoming line buffer.
37
+ */
38
+ export declare function getMessages(onMessage?: (msg: EventSourceMessage) => void, onId?: (id: string) => void, onRetry?: (retry: number) => void): (line: Uint8Array, fieldLength: number, flush?: boolean) => void;
39
+ export declare function convertEventStreamToIterableReadableDataStream(stream: ReadableStream): IterableReadableStream<any>;