ai 6.0.274 → 6.0.276

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,24 @@
1
1
  # ai
2
2
 
3
+ ## 6.0.276
4
+
5
+ ### Patch Changes
6
+
7
+ - 760ac87: fix(ai): preserve provider metadata from empty smooth stream deltas
8
+ - 5e43974: fix(ai): skip `smoothStream` delays while the document is hidden
9
+ - Updated dependencies [13507cb]
10
+ - Updated dependencies [7782fec]
11
+ - Updated dependencies [978e084]
12
+ - Updated dependencies [d0c255c]
13
+ - @ai-sdk/gateway@3.0.188
14
+
15
+ ## 6.0.275
16
+
17
+ ### Patch Changes
18
+
19
+ - Updated dependencies [57d88f5]
20
+ - @ai-sdk/gateway@3.0.187
21
+
3
22
  ## 6.0.274
4
23
 
5
24
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1527,7 +1527,7 @@ type ChunkDetector = (buffer: string) => string | undefined | null;
1527
1527
  /**
1528
1528
  * Smooths text and reasoning streaming output.
1529
1529
  *
1530
- * @param delayInMs - The delay in milliseconds between each chunk. Defaults to 10ms. Can be set to `null` to skip the delay.
1530
+ * @param delayInMs - The delay in milliseconds between each chunk. Defaults to 10ms. Can be set to `null` to skip the delay. The delay is skipped while the document is hidden (e.g. browser background tabs), where timer throttling would otherwise stall the stream.
1531
1531
  * @param chunking - Controls how the text is chunked for streaming. Use "word" to stream word by word (default), "line" to stream line by line, provide a custom RegExp pattern for custom chunking, provide an Intl.Segmenter for locale-aware word segmentation (recommended for CJK languages), or provide a custom ChunkDetector function.
1532
1532
  *
1533
1533
  * @returns A transform stream that smooths text streaming output.
package/dist/index.d.ts CHANGED
@@ -1527,7 +1527,7 @@ type ChunkDetector = (buffer: string) => string | undefined | null;
1527
1527
  /**
1528
1528
  * Smooths text and reasoning streaming output.
1529
1529
  *
1530
- * @param delayInMs - The delay in milliseconds between each chunk. Defaults to 10ms. Can be set to `null` to skip the delay.
1530
+ * @param delayInMs - The delay in milliseconds between each chunk. Defaults to 10ms. Can be set to `null` to skip the delay. The delay is skipped while the document is hidden (e.g. browser background tabs), where timer throttling would otherwise stall the stream.
1531
1531
  * @param chunking - Controls how the text is chunked for streaming. Use "word" to stream word by word (default), "line" to stream line by line, provide a custom RegExp pattern for custom chunking, provide an Intl.Segmenter for locale-aware word segmentation (recommended for CJK languages), or provide a custom ChunkDetector function.
1532
1532
  *
1533
1533
  * @returns A transform stream that smooths text streaming output.
package/dist/index.js CHANGED
@@ -1334,7 +1334,7 @@ function detectMediaType({
1334
1334
  var import_provider_utils3 = require("@ai-sdk/provider-utils");
1335
1335
 
1336
1336
  // src/version.ts
1337
- var VERSION = true ? "6.0.274" : "0.0.0-test";
1337
+ var VERSION = true ? "6.0.276" : "0.0.0-test";
1338
1338
 
1339
1339
  // src/util/download/download.ts
1340
1340
  var download = async ({
@@ -12521,6 +12521,9 @@ var CHUNKING_REGEXPS = {
12521
12521
  word: /\S+\s+/m,
12522
12522
  line: /\n+/m
12523
12523
  };
12524
+ function isDocumentHidden() {
12525
+ return typeof document !== "undefined" && document.visibilityState === "hidden";
12526
+ }
12524
12527
  function smoothStream({
12525
12528
  delayInMs = 10,
12526
12529
  chunking = "word",
@@ -12574,7 +12577,7 @@ function smoothStream({
12574
12577
  let type = void 0;
12575
12578
  let providerMetadata = void 0;
12576
12579
  function flushBuffer(controller) {
12577
- if (buffer.length > 0 && type !== void 0) {
12580
+ if (type !== void 0 && (buffer.length > 0 || providerMetadata != null)) {
12578
12581
  controller.enqueue({
12579
12582
  type,
12580
12583
  text: buffer,
@@ -12592,7 +12595,7 @@ function smoothStream({
12592
12595
  controller.enqueue(chunk);
12593
12596
  return;
12594
12597
  }
12595
- if ((chunk.type !== type || chunk.id !== id) && buffer.length > 0) {
12598
+ if ((chunk.type !== type || chunk.id !== id) && (buffer.length > 0 || providerMetadata != null)) {
12596
12599
  flushBuffer(controller);
12597
12600
  }
12598
12601
  buffer += chunk.text;
@@ -12605,7 +12608,7 @@ function smoothStream({
12605
12608
  while ((match = detectChunk(buffer)) != null) {
12606
12609
  controller.enqueue({ type, text: match, id });
12607
12610
  buffer = buffer.slice(match.length);
12608
- await delay(delayInMs);
12611
+ await delay(isDocumentHidden() ? null : delayInMs);
12609
12612
  }
12610
12613
  }
12611
12614
  });
@@ -13797,7 +13800,7 @@ async function rerank({
13797
13800
  ...assembleOperationName({ operationId: "ai.rerank", telemetry }),
13798
13801
  ...baseTelemetryAttributes,
13799
13802
  "ai.documents": {
13800
- input: () => documents.map((document) => JSON.stringify(document))
13803
+ input: () => documents.map((document2) => JSON.stringify(document2))
13801
13804
  }
13802
13805
  }
13803
13806
  }),
@@ -13817,7 +13820,7 @@ async function rerank({
13817
13820
  ...baseTelemetryAttributes,
13818
13821
  // specific settings that only make sense on the outer level:
13819
13822
  "ai.documents": {
13820
- input: () => documents.map((document) => JSON.stringify(document))
13823
+ input: () => documents.map((document2) => JSON.stringify(document2))
13821
13824
  }
13822
13825
  }
13823
13826
  }),