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/dist/index.mjs CHANGED
@@ -4714,13 +4714,23 @@ function createOutputTransformStream(output) {
4714
4714
  let text2 = "";
4715
4715
  let textChunk = "";
4716
4716
  let lastPublishedJson = "";
4717
+ function publishTextChunk({
4718
+ controller,
4719
+ partialOutput = void 0
4720
+ }) {
4721
+ controller.enqueue({
4722
+ part: { type: "text-delta", textDelta: textChunk },
4723
+ partialOutput
4724
+ });
4725
+ textChunk = "";
4726
+ }
4717
4727
  return new TransformStream({
4718
4728
  transform(chunk, controller) {
4729
+ if (chunk.type === "step-finish") {
4730
+ publishTextChunk({ controller });
4731
+ }
4719
4732
  if (chunk.type !== "text-delta") {
4720
- controller.enqueue({
4721
- part: chunk,
4722
- partialOutput: void 0
4723
- });
4733
+ controller.enqueue({ part: chunk, partialOutput: void 0 });
4724
4734
  return;
4725
4735
  }
4726
4736
  text2 += chunk.textDelta;
@@ -4729,27 +4739,14 @@ function createOutputTransformStream(output) {
4729
4739
  if (result != null) {
4730
4740
  const currentJson = JSON.stringify(result.partial);
4731
4741
  if (currentJson !== lastPublishedJson) {
4732
- controller.enqueue({
4733
- part: {
4734
- type: "text-delta",
4735
- textDelta: textChunk
4736
- },
4737
- partialOutput: result.partial
4738
- });
4742
+ publishTextChunk({ controller, partialOutput: result.partial });
4739
4743
  lastPublishedJson = currentJson;
4740
- textChunk = "";
4741
4744
  }
4742
4745
  }
4743
4746
  },
4744
4747
  flush(controller) {
4745
4748
  if (textChunk.length > 0) {
4746
- controller.enqueue({
4747
- part: {
4748
- type: "text-delta",
4749
- textDelta: textChunk
4750
- },
4751
- partialOutput: void 0
4752
- });
4749
+ publishTextChunk({ controller });
4753
4750
  }
4754
4751
  }
4755
4752
  });