@ai-sdk/provider-utils 5.0.83 → 5.0.84
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/CHANGELOG.md +10 -0
- package/dist/index.d.ts +7 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/parse-json-event-stream.ts +18 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/provider-utils",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.84",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"@ai-sdk/provider": "4.0.39",
|
|
51
51
|
"@standard-schema/spec": "^1.1.0",
|
|
52
52
|
"@workflow/serde": "4.1.0",
|
|
53
|
-
"eventsource-parser": "^3.
|
|
53
|
+
"eventsource-parser": "^3.1.1"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@types/node": "22.19.19",
|
|
@@ -5,21 +5,38 @@ import {
|
|
|
5
5
|
import { safeParseJSON, type ParseResult } from './parse-json';
|
|
6
6
|
import type { FlexibleSchema } from './schema';
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Default maximum size of a single event: 64 * 1024 * 1024 characters.
|
|
10
|
+
*
|
|
11
|
+
* An event is buffered until it is complete, so a stream that never completes
|
|
12
|
+
* an event would grow the buffer until the process runs out of memory. With
|
|
13
|
+
* this limit, such a stream fails with an error that can be handled instead.
|
|
14
|
+
*/
|
|
15
|
+
const DEFAULT_MAX_EVENT_SIZE = 64 * 1024 * 1024;
|
|
16
|
+
|
|
8
17
|
/**
|
|
9
18
|
* Parses a JSON event stream into a stream of parsed JSON objects.
|
|
10
19
|
*/
|
|
11
20
|
export function parseJsonEventStream<T>({
|
|
12
21
|
stream,
|
|
13
22
|
schema,
|
|
23
|
+
maxEventSize = DEFAULT_MAX_EVENT_SIZE,
|
|
14
24
|
}: {
|
|
15
25
|
stream: ReadableStream<Uint8Array>;
|
|
16
26
|
schema: FlexibleSchema<T>;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Maximum size of a single event in characters. The returned stream fails
|
|
30
|
+
* with an error when an event is larger. Defaults to 64 * 1024 * 1024
|
|
31
|
+
* characters.
|
|
32
|
+
*/
|
|
33
|
+
maxEventSize?: number;
|
|
17
34
|
}): ReadableStream<ParseResult<T>> {
|
|
18
35
|
return stream
|
|
19
36
|
.pipeThrough(
|
|
20
37
|
new TextDecoderStream() as ReadableWritablePair<string, Uint8Array>,
|
|
21
38
|
)
|
|
22
|
-
.pipeThrough(new EventSourceParserStream())
|
|
39
|
+
.pipeThrough(new EventSourceParserStream({ maxBufferSize: maxEventSize }))
|
|
23
40
|
.pipeThrough(
|
|
24
41
|
new TransformStream<EventSourceMessage, ParseResult<T>>({
|
|
25
42
|
async transform({ data }, controller) {
|