@ai-sdk/provider-utils 4.0.66 → 4.0.68
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 +16 -0
- package/dist/index.d.mts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +6 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/parse-json-event-stream.ts +18 -1
- package/src/schema.ts +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @ai-sdk/provider-utils
|
|
2
2
|
|
|
3
|
+
## 4.0.68
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- ca77a27: fix(provider-utils): limit the size of a single server-sent event
|
|
8
|
+
|
|
9
|
+
`parseJsonEventStream` and `createEventSourceResponseHandler` buffered an event until it was complete, without a limit. A streaming response that never completed an event could exhaust the memory and crash the process. A single event is now limited to 67,108,864 characters (64 MiB of ASCII text). A stream that exceeds the limit fails with an error and the response body is cancelled.
|
|
10
|
+
|
|
11
|
+
The limit also applies to the streams that `useChat` and `useCompletion` read. `parseJsonEventStream` has a new `maxEventSize` option to change it. The gateway video model uses it to accept a result event of up to 536,870,912 characters, because that event contains the generated videos.
|
|
12
|
+
|
|
13
|
+
## 4.0.67
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- d59eee0: Fix validation of non-Zod Standard Schema results: a result that contains `issues` is now always treated as a failure, even when it also carries a `value`. Previously a failing schema such as Valibot's through `toStandardJsonSchema()` could be reported as valid, so rejected input, including tool input, was accepted.
|
|
18
|
+
|
|
3
19
|
## 4.0.66
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -658,9 +658,15 @@ declare function normalizeHeaders(headers: HeadersInit | Record<string, string |
|
|
|
658
658
|
/**
|
|
659
659
|
* Parses a JSON event stream into a stream of parsed JSON objects.
|
|
660
660
|
*/
|
|
661
|
-
declare function parseJsonEventStream<T>({ stream, schema, }: {
|
|
661
|
+
declare function parseJsonEventStream<T>({ stream, schema, maxEventSize, }: {
|
|
662
662
|
stream: ReadableStream<Uint8Array>;
|
|
663
663
|
schema: FlexibleSchema<T>;
|
|
664
|
+
/**
|
|
665
|
+
* Maximum size of a single event in characters. The returned stream fails
|
|
666
|
+
* with an error when an event is larger. Defaults to 64 * 1024 * 1024
|
|
667
|
+
* characters.
|
|
668
|
+
*/
|
|
669
|
+
maxEventSize?: number;
|
|
664
670
|
}): ReadableStream<ParseResult<T>>;
|
|
665
671
|
|
|
666
672
|
declare function parseProviderOptions<OPTIONS>({ provider, providerOptions, schema, }: {
|
package/dist/index.d.ts
CHANGED
|
@@ -658,9 +658,15 @@ declare function normalizeHeaders(headers: HeadersInit | Record<string, string |
|
|
|
658
658
|
/**
|
|
659
659
|
* Parses a JSON event stream into a stream of parsed JSON objects.
|
|
660
660
|
*/
|
|
661
|
-
declare function parseJsonEventStream<T>({ stream, schema, }: {
|
|
661
|
+
declare function parseJsonEventStream<T>({ stream, schema, maxEventSize, }: {
|
|
662
662
|
stream: ReadableStream<Uint8Array>;
|
|
663
663
|
schema: FlexibleSchema<T>;
|
|
664
|
+
/**
|
|
665
|
+
* Maximum size of a single event in characters. The returned stream fails
|
|
666
|
+
* with an error when an event is larger. Defaults to 64 * 1024 * 1024
|
|
667
|
+
* characters.
|
|
668
|
+
*/
|
|
669
|
+
maxEventSize?: number;
|
|
664
670
|
}): ReadableStream<ParseResult<T>>;
|
|
665
671
|
|
|
666
672
|
declare function parseProviderOptions<OPTIONS>({ provider, providerOptions, schema, }: {
|
package/dist/index.js
CHANGED
|
@@ -1057,7 +1057,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
1057
1057
|
}
|
|
1058
1058
|
|
|
1059
1059
|
// src/version.ts
|
|
1060
|
-
var VERSION = true ? "4.0.
|
|
1060
|
+
var VERSION = true ? "4.0.68" : "0.0.0-test";
|
|
1061
1061
|
|
|
1062
1062
|
// src/get-from-api.ts
|
|
1063
1063
|
var getOriginalFetch = () => globalThis.fetch;
|
|
@@ -2629,7 +2629,7 @@ function standardSchema(standardSchema2) {
|
|
|
2629
2629
|
{
|
|
2630
2630
|
validate: async (value) => {
|
|
2631
2631
|
const result = await standardSchema2["~standard"].validate(value);
|
|
2632
|
-
return "value" in result ? { success: true, value: result.value } : {
|
|
2632
|
+
return result.issues === void 0 && "value" in result ? { success: true, value: result.value } : {
|
|
2633
2633
|
success: false,
|
|
2634
2634
|
error: new import_provider7.TypeValidationError({
|
|
2635
2635
|
value,
|
|
@@ -2777,11 +2777,13 @@ function isParsableJson(input) {
|
|
|
2777
2777
|
|
|
2778
2778
|
// src/parse-json-event-stream.ts
|
|
2779
2779
|
var import_stream = require("eventsource-parser/stream");
|
|
2780
|
+
var DEFAULT_MAX_EVENT_SIZE = 64 * 1024 * 1024;
|
|
2780
2781
|
function parseJsonEventStream({
|
|
2781
2782
|
stream,
|
|
2782
|
-
schema
|
|
2783
|
+
schema,
|
|
2784
|
+
maxEventSize = DEFAULT_MAX_EVENT_SIZE
|
|
2783
2785
|
}) {
|
|
2784
|
-
return stream.pipeThrough(new TextDecoderStream()).pipeThrough(new import_stream.EventSourceParserStream()).pipeThrough(
|
|
2786
|
+
return stream.pipeThrough(new TextDecoderStream()).pipeThrough(new import_stream.EventSourceParserStream({ maxBufferSize: maxEventSize })).pipeThrough(
|
|
2785
2787
|
new TransformStream({
|
|
2786
2788
|
async transform({ data }, controller) {
|
|
2787
2789
|
if (data === "[DONE]") {
|