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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # ai
2
2
 
3
+ ## 5.0.269
4
+
5
+ ### Patch Changes
6
+
7
+ - 11f5cda: Preserve provider metadata on corresponding `smoothStream` chunks without carrying it into subsequent metadata-free deltas.
8
+
3
9
  ## 5.0.268
4
10
 
5
11
  ### Patch Changes
package/dist/index.js CHANGED
@@ -816,7 +816,7 @@ function detectMediaType({
816
816
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
817
817
 
818
818
  // src/version.ts
819
- var VERSION = true ? "5.0.268" : "0.0.0-test";
819
+ var VERSION = true ? "5.0.269" : "0.0.0-test";
820
820
 
821
821
  // src/util/download/download.ts
822
822
  var download = async ({
@@ -8810,28 +8810,51 @@ function smoothStream({
8810
8810
  return () => {
8811
8811
  let buffer = "";
8812
8812
  let id = "";
8813
+ let providerMetadata;
8814
+ function flushBuffer(controller) {
8815
+ if (buffer.length > 0 || providerMetadata != null) {
8816
+ controller.enqueue({
8817
+ type: "text-delta",
8818
+ text: buffer,
8819
+ id,
8820
+ ...providerMetadata != null ? { providerMetadata } : {}
8821
+ });
8822
+ buffer = "";
8823
+ providerMetadata = void 0;
8824
+ }
8825
+ }
8813
8826
  return new TransformStream({
8814
8827
  async transform(chunk, controller) {
8815
8828
  if (chunk.type !== "text-delta") {
8816
- if (buffer.length > 0) {
8817
- controller.enqueue({ type: "text-delta", text: buffer, id });
8818
- buffer = "";
8819
- }
8829
+ flushBuffer(controller);
8830
+ controller.enqueue(chunk);
8831
+ return;
8832
+ }
8833
+ if (chunk.text.length === 0 && chunk.providerMetadata != null) {
8834
+ flushBuffer(controller);
8820
8835
  controller.enqueue(chunk);
8821
8836
  return;
8822
8837
  }
8823
- if (chunk.id !== id && buffer.length > 0) {
8824
- controller.enqueue({ type: "text-delta", text: buffer, id });
8825
- buffer = "";
8838
+ if (buffer.length > 0 && (chunk.id !== id || providerMetadata != null || chunk.providerMetadata != null)) {
8839
+ flushBuffer(controller);
8826
8840
  }
8827
8841
  buffer += chunk.text;
8828
8842
  id = chunk.id;
8843
+ providerMetadata = chunk.providerMetadata;
8829
8844
  let match;
8830
8845
  while ((match = detectChunk(buffer)) != null) {
8831
- controller.enqueue({ type: "text-delta", text: match, id });
8846
+ controller.enqueue({
8847
+ type: "text-delta",
8848
+ text: match,
8849
+ id,
8850
+ ...providerMetadata != null ? { providerMetadata } : {}
8851
+ });
8832
8852
  buffer = buffer.slice(match.length);
8833
8853
  await delay2(isDocumentHidden() ? null : delayInMs);
8834
8854
  }
8855
+ if (buffer.length === 0) {
8856
+ providerMetadata = void 0;
8857
+ }
8835
8858
  }
8836
8859
  });
8837
8860
  };