ai 5.0.268 → 5.0.269

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
@@ -727,7 +727,7 @@ import {
727
727
  } from "@ai-sdk/provider-utils";
728
728
 
729
729
  // src/version.ts
730
- var VERSION = true ? "5.0.268" : "0.0.0-test";
730
+ var VERSION = true ? "5.0.269" : "0.0.0-test";
731
731
 
732
732
  // src/util/download/download.ts
733
733
  var download = async ({
@@ -8771,28 +8771,51 @@ function smoothStream({
8771
8771
  return () => {
8772
8772
  let buffer = "";
8773
8773
  let id = "";
8774
+ let providerMetadata;
8775
+ function flushBuffer(controller) {
8776
+ if (buffer.length > 0 || providerMetadata != null) {
8777
+ controller.enqueue({
8778
+ type: "text-delta",
8779
+ text: buffer,
8780
+ id,
8781
+ ...providerMetadata != null ? { providerMetadata } : {}
8782
+ });
8783
+ buffer = "";
8784
+ providerMetadata = void 0;
8785
+ }
8786
+ }
8774
8787
  return new TransformStream({
8775
8788
  async transform(chunk, controller) {
8776
8789
  if (chunk.type !== "text-delta") {
8777
- if (buffer.length > 0) {
8778
- controller.enqueue({ type: "text-delta", text: buffer, id });
8779
- buffer = "";
8780
- }
8790
+ flushBuffer(controller);
8791
+ controller.enqueue(chunk);
8792
+ return;
8793
+ }
8794
+ if (chunk.text.length === 0 && chunk.providerMetadata != null) {
8795
+ flushBuffer(controller);
8781
8796
  controller.enqueue(chunk);
8782
8797
  return;
8783
8798
  }
8784
- if (chunk.id !== id && buffer.length > 0) {
8785
- controller.enqueue({ type: "text-delta", text: buffer, id });
8786
- buffer = "";
8799
+ if (buffer.length > 0 && (chunk.id !== id || providerMetadata != null || chunk.providerMetadata != null)) {
8800
+ flushBuffer(controller);
8787
8801
  }
8788
8802
  buffer += chunk.text;
8789
8803
  id = chunk.id;
8804
+ providerMetadata = chunk.providerMetadata;
8790
8805
  let match;
8791
8806
  while ((match = detectChunk(buffer)) != null) {
8792
- controller.enqueue({ type: "text-delta", text: match, id });
8807
+ controller.enqueue({
8808
+ type: "text-delta",
8809
+ text: match,
8810
+ id,
8811
+ ...providerMetadata != null ? { providerMetadata } : {}
8812
+ });
8793
8813
  buffer = buffer.slice(match.length);
8794
8814
  await delay2(isDocumentHidden() ? null : delayInMs);
8795
8815
  }
8816
+ if (buffer.length === 0) {
8817
+ providerMetadata = void 0;
8818
+ }
8796
8819
  }
8797
8820
  });
8798
8821
  };