ai 4.3.1 → 4.3.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 +6 -0
- package/dist/index.d.mts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +28 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +28 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
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
@@ -4754,6 +4754,25 @@ function asArray(value) {
|
|
4754
4754
|
return value === void 0 ? [] : Array.isArray(value) ? value : [value];
|
4755
4755
|
}
|
4756
4756
|
|
4757
|
+
// util/consume-stream.ts
|
4758
|
+
async function consumeStream({
|
4759
|
+
stream,
|
4760
|
+
onError
|
4761
|
+
}) {
|
4762
|
+
const reader = stream.getReader();
|
4763
|
+
try {
|
4764
|
+
while (true) {
|
4765
|
+
const { done } = await reader.read();
|
4766
|
+
if (done)
|
4767
|
+
break;
|
4768
|
+
}
|
4769
|
+
} catch (error) {
|
4770
|
+
onError == null ? void 0 : onError(error);
|
4771
|
+
} finally {
|
4772
|
+
reader.releaseLock();
|
4773
|
+
}
|
4774
|
+
}
|
4775
|
+
|
4757
4776
|
// core/util/merge-streams.ts
|
4758
4777
|
function mergeStreams(stream1, stream2) {
|
4759
4778
|
const reader1 = stream1.getReader();
|
@@ -5995,9 +6014,15 @@ var DefaultStreamTextResult = class {
|
|
5995
6014
|
)
|
5996
6015
|
);
|
5997
6016
|
}
|
5998
|
-
async consumeStream() {
|
5999
|
-
|
6000
|
-
|
6017
|
+
async consumeStream(options) {
|
6018
|
+
var _a17;
|
6019
|
+
try {
|
6020
|
+
await consumeStream({
|
6021
|
+
stream: this.fullStream,
|
6022
|
+
onError: options == null ? void 0 : options.onError
|
6023
|
+
});
|
6024
|
+
} catch (error) {
|
6025
|
+
(_a17 = options == null ? void 0 : options.onError) == null ? void 0 : _a17.call(options, error);
|
6001
6026
|
}
|
6002
6027
|
}
|
6003
6028
|
get experimental_partialOutputStream() {
|