ai 5.0.0-canary.1 → 5.0.0-canary.2

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.0-canary.2
4
+
5
+ ### Patch Changes
6
+
7
+ - bd398e4: fix (core): improve error handling in streamText's consumeStream method
8
+
3
9
  ## 5.0.0-canary.1
4
10
 
5
11
  ### Minor Changes
package/dist/index.d.mts CHANGED
@@ -2539,6 +2539,9 @@ type DataStreamOptions = {
2539
2539
  */
2540
2540
  experimental_sendStart?: boolean;
2541
2541
  };
2542
+ type ConsumeStreamOptions = {
2543
+ onError?: (error: unknown) => void;
2544
+ };
2542
2545
  /**
2543
2546
  A result object for accessing different stream types and additional information.
2544
2547
  */
@@ -2659,8 +2662,10 @@ interface StreamTextResult<TOOLS extends ToolSet, PARTIAL_OUTPUT> {
2659
2662
  This is useful to force the stream to finish.
2660
2663
  It effectively removes the backpressure and allows the stream to finish,
2661
2664
  triggering the `onFinish` callback and the promise resolution.
2665
+
2666
+ If an error occurs, it is passed to the optional `onError` callback.
2662
2667
  */
2663
- consumeStream(): Promise<void>;
2668
+ consumeStream(options?: ConsumeStreamOptions): Promise<void>;
2664
2669
  /**
2665
2670
  Converts the result to a data stream.
2666
2671
 
package/dist/index.d.ts CHANGED
@@ -2539,6 +2539,9 @@ type DataStreamOptions = {
2539
2539
  */
2540
2540
  experimental_sendStart?: boolean;
2541
2541
  };
2542
+ type ConsumeStreamOptions = {
2543
+ onError?: (error: unknown) => void;
2544
+ };
2542
2545
  /**
2543
2546
  A result object for accessing different stream types and additional information.
2544
2547
  */
@@ -2659,8 +2662,10 @@ interface StreamTextResult<TOOLS extends ToolSet, PARTIAL_OUTPUT> {
2659
2662
  This is useful to force the stream to finish.
2660
2663
  It effectively removes the backpressure and allows the stream to finish,
2661
2664
  triggering the `onFinish` callback and the promise resolution.
2665
+
2666
+ If an error occurs, it is passed to the optional `onError` callback.
2662
2667
  */
2663
- consumeStream(): Promise<void>;
2668
+ consumeStream(options?: ConsumeStreamOptions): Promise<void>;
2664
2669
  /**
2665
2670
  Converts the result to a data stream.
2666
2671
 
package/dist/index.js CHANGED
@@ -4751,6 +4751,25 @@ function asArray(value) {
4751
4751
  return value === void 0 ? [] : Array.isArray(value) ? value : [value];
4752
4752
  }
4753
4753
 
4754
+ // util/consume-stream.ts
4755
+ async function consumeStream({
4756
+ stream,
4757
+ onError
4758
+ }) {
4759
+ const reader = stream.getReader();
4760
+ try {
4761
+ while (true) {
4762
+ const { done } = await reader.read();
4763
+ if (done)
4764
+ break;
4765
+ }
4766
+ } catch (error) {
4767
+ onError == null ? void 0 : onError(error);
4768
+ } finally {
4769
+ reader.releaseLock();
4770
+ }
4771
+ }
4772
+
4754
4773
  // core/util/merge-streams.ts
4755
4774
  function mergeStreams(stream1, stream2) {
4756
4775
  const reader1 = stream1.getReader();
@@ -5992,9 +6011,15 @@ var DefaultStreamTextResult = class {
5992
6011
  )
5993
6012
  );
5994
6013
  }
5995
- async consumeStream() {
5996
- const stream = this.fullStream;
5997
- for await (const part of stream) {
6014
+ async consumeStream(options) {
6015
+ var _a17;
6016
+ try {
6017
+ await consumeStream({
6018
+ stream: this.fullStream,
6019
+ onError: options == null ? void 0 : options.onError
6020
+ });
6021
+ } catch (error) {
6022
+ (_a17 = options == null ? void 0 : options.onError) == null ? void 0 : _a17.call(options, error);
5998
6023
  }
5999
6024
  }
6000
6025
  get experimental_partialOutputStream() {