@ai-sdk/provider-utils 4.0.67 → 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 CHANGED
@@ -1,5 +1,15 @@
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
+
3
13
  ## 4.0.67
4
14
 
5
15
  ### 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.67" : "0.0.0-test";
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;
@@ -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]") {