ai 4.1.31 → 4.1.32

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.1.32
4
+
5
+ ### Patch Changes
6
+
7
+ - c128ca5: fix (ai/core): fix streamText onFinish messages with structured output
8
+
3
9
  ## 4.1.31
4
10
 
5
11
  ### Patch Changes
package/dist/index.js CHANGED
@@ -4763,13 +4763,23 @@ function createOutputTransformStream(output) {
4763
4763
  let text2 = "";
4764
4764
  let textChunk = "";
4765
4765
  let lastPublishedJson = "";
4766
+ function publishTextChunk({
4767
+ controller,
4768
+ partialOutput = void 0
4769
+ }) {
4770
+ controller.enqueue({
4771
+ part: { type: "text-delta", textDelta: textChunk },
4772
+ partialOutput
4773
+ });
4774
+ textChunk = "";
4775
+ }
4766
4776
  return new TransformStream({
4767
4777
  transform(chunk, controller) {
4778
+ if (chunk.type === "step-finish") {
4779
+ publishTextChunk({ controller });
4780
+ }
4768
4781
  if (chunk.type !== "text-delta") {
4769
- controller.enqueue({
4770
- part: chunk,
4771
- partialOutput: void 0
4772
- });
4782
+ controller.enqueue({ part: chunk, partialOutput: void 0 });
4773
4783
  return;
4774
4784
  }
4775
4785
  text2 += chunk.textDelta;
@@ -4778,27 +4788,14 @@ function createOutputTransformStream(output) {
4778
4788
  if (result != null) {
4779
4789
  const currentJson = JSON.stringify(result.partial);
4780
4790
  if (currentJson !== lastPublishedJson) {
4781
- controller.enqueue({
4782
- part: {
4783
- type: "text-delta",
4784
- textDelta: textChunk
4785
- },
4786
- partialOutput: result.partial
4787
- });
4791
+ publishTextChunk({ controller, partialOutput: result.partial });
4788
4792
  lastPublishedJson = currentJson;
4789
- textChunk = "";
4790
4793
  }
4791
4794
  }
4792
4795
  },
4793
4796
  flush(controller) {
4794
4797
  if (textChunk.length > 0) {
4795
- controller.enqueue({
4796
- part: {
4797
- type: "text-delta",
4798
- textDelta: textChunk
4799
- },
4800
- partialOutput: void 0
4801
- });
4798
+ publishTextChunk({ controller });
4802
4799
  }
4803
4800
  }
4804
4801
  });