ai 5.0.260 → 5.0.261

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,11 @@
1
1
  # ai
2
2
 
3
+ ## 5.0.261
4
+
5
+ ### Patch Changes
6
+
7
+ - 69879fe: fix(ai): prevent unhandled rejections when UI message stream reading stops early
8
+
3
9
  ## 5.0.260
4
10
 
5
11
  ### Patch Changes
package/dist/index.js CHANGED
@@ -816,7 +816,7 @@ function detectMediaType({
816
816
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
817
817
 
818
818
  // src/version.ts
819
- var VERSION = true ? "5.0.260" : "0.0.0-test";
819
+ var VERSION = true ? "5.0.261" : "0.0.0-test";
820
820
 
821
821
  // src/util/download/download.ts
822
822
  var download = async ({
@@ -10675,9 +10675,15 @@ function readUIMessageStream({
10675
10675
  var _a16;
10676
10676
  let controller;
10677
10677
  let hasErrored = false;
10678
+ let isCancelled = false;
10679
+ const abortController = new AbortController();
10678
10680
  const outputStream = new ReadableStream({
10679
10681
  start(controllerParam) {
10680
10682
  controller = controllerParam;
10683
+ },
10684
+ cancel() {
10685
+ isCancelled = true;
10686
+ abortController.abort();
10681
10687
  }
10682
10688
  });
10683
10689
  const state = createStreamingUIMessageState({
@@ -10698,15 +10704,18 @@ function readUIMessageStream({
10698
10704
  return job({
10699
10705
  state,
10700
10706
  write: () => {
10701
- controller == null ? void 0 : controller.enqueue(createUIMessageSnapshot(state.message));
10707
+ if (!isCancelled) {
10708
+ controller == null ? void 0 : controller.enqueue(createUIMessageSnapshot(state.message));
10709
+ }
10702
10710
  }
10703
10711
  });
10704
10712
  },
10705
10713
  onError: handleError
10706
10714
  }),
10707
- onError: handleError
10715
+ onError: handleError,
10716
+ abortSignal: abortController.signal
10708
10717
  }).finally(() => {
10709
- if (!hasErrored) {
10718
+ if (!hasErrored && !isCancelled) {
10710
10719
  controller == null ? void 0 : controller.close();
10711
10720
  }
10712
10721
  });