ai 4.0.32 → 4.0.33

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
+ ## 4.0.33
4
+
5
+ ### Patch Changes
6
+
7
+ - 5510ee7: feat (ai/core): add stopStream option to streamText transforms
8
+
3
9
  ## 4.0.32
4
10
 
5
11
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -2134,9 +2134,13 @@ Enable streaming of tool call deltas as they are generated. Disabled by default.
2134
2134
  experimental_toolCallStreaming?: boolean;
2135
2135
  /**
2136
2136
  Optional transformation that is applied to the stream.
2137
+
2138
+ @param stopStream - A function that stops the source stream.
2139
+ @param tools - The tools that are accessible to and can be called by the model. The model needs to support calling tools.
2137
2140
  */
2138
2141
  experimental_transform?: (options: {
2139
2142
  tools: TOOLS;
2143
+ stopStream: () => void;
2140
2144
  }) => TransformStream<TextStreamPart<TOOLS>, TextStreamPart<TOOLS>>;
2141
2145
  /**
2142
2146
  Callback that is called for each chunk of the stream. The stream processing will pause until the callback promise is resolved.
package/dist/index.d.ts CHANGED
@@ -2134,9 +2134,13 @@ Enable streaming of tool call deltas as they are generated. Disabled by default.
2134
2134
  experimental_toolCallStreaming?: boolean;
2135
2135
  /**
2136
2136
  Optional transformation that is applied to the stream.
2137
+
2138
+ @param stopStream - A function that stops the source stream.
2139
+ @param tools - The tools that are accessible to and can be called by the model. The model needs to support calling tools.
2137
2140
  */
2138
2141
  experimental_transform?: (options: {
2139
2142
  tools: TOOLS;
2143
+ stopStream: () => void;
2140
2144
  }) => TransformStream<TextStreamPart<TOOLS>, TextStreamPart<TOOLS>>;
2141
2145
  /**
2142
2146
  Callback that is called for each chunk of the stream. The stream processing will pause until the callback promise is resolved.
package/dist/index.js CHANGED
@@ -2765,12 +2765,27 @@ function createStitchableStream() {
2765
2765
  innerStreamReaders.push(innerStream.getReader());
2766
2766
  waitForNewStream.resolve();
2767
2767
  },
2768
+ /**
2769
+ * Gracefully close the outer stream. This will let the inner streams
2770
+ * finish processing and then close the outer stream.
2771
+ */
2768
2772
  close: () => {
2769
2773
  isClosed = true;
2770
2774
  waitForNewStream.resolve();
2771
2775
  if (innerStreamReaders.length === 0) {
2772
2776
  controller == null ? void 0 : controller.close();
2773
2777
  }
2778
+ },
2779
+ /**
2780
+ * Immediately close the outer stream. This will cancel all inner streams
2781
+ * and close the outer stream.
2782
+ */
2783
+ terminate: () => {
2784
+ isClosed = true;
2785
+ waitForNewStream.resolve();
2786
+ innerStreamReaders.forEach((reader) => reader.cancel());
2787
+ innerStreamReaders = [];
2788
+ controller == null ? void 0 : controller.close();
2774
2789
  }
2775
2790
  };
2776
2791
  }
@@ -4455,7 +4470,7 @@ function streamText({
4455
4470
  tools,
4456
4471
  toolChoice,
4457
4472
  toolCallStreaming,
4458
- transform: transform == null ? void 0 : transform({ tools }),
4473
+ transform,
4459
4474
  activeTools,
4460
4475
  repairToolCall,
4461
4476
  maxSteps,
@@ -4729,7 +4744,14 @@ var DefaultStreamTextResult = class {
4729
4744
  this.closeStream = stitchableStream.close;
4730
4745
  let stream = stitchableStream.stream;
4731
4746
  if (transform) {
4732
- stream = stream.pipeThrough(transform);
4747
+ stream = stream.pipeThrough(
4748
+ transform({
4749
+ tools,
4750
+ stopStream() {
4751
+ stitchableStream.terminate();
4752
+ }
4753
+ })
4754
+ );
4733
4755
  }
4734
4756
  this.baseStream = stream.pipeThrough(createOutputTransformStream(output)).pipeThrough(eventProcessor);
4735
4757
  const { maxRetries, retry } = prepareRetries({