ai 7.0.91 → 7.0.92

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,16 @@
1
1
  # ai
2
2
 
3
+ ## 7.0.92
4
+
5
+ ### Patch Changes
6
+
7
+ - a51cc94: fix(ai): preserve provider metadata from empty smooth stream deltas
8
+ - d1904d3: fix(ai): surface fallback errors for empty HTTP response bodies
9
+ - 84e5a79: fix(ai): skip `smoothStream` delays while the document is hidden
10
+ - a8e8ad0: fix(ai): expose call ID and abort reason in streamText onAbort callbacks
11
+ - Updated dependencies [a7e324b]
12
+ - @ai-sdk/gateway@4.0.74
13
+
3
14
  ## 7.0.91
4
15
 
5
16
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -3401,12 +3401,7 @@ type StreamTextOnEndCallback<TOOLS extends ToolSet = ToolSet, RUNTIME_CONTEXT ex
3401
3401
  *
3402
3402
  * @param event - The event that is passed to the callback.
3403
3403
  */
3404
- type StreamTextOnAbortCallback<TOOLS extends ToolSet, RUNTIME_CONTEXT extends Context> = Callback<{
3405
- /**
3406
- * Details for all previously finished steps.
3407
- */
3408
- readonly steps: StepResult<TOOLS, RUNTIME_CONTEXT>[];
3409
- }>;
3404
+ type StreamTextOnAbortCallback<TOOLS extends ToolSet, RUNTIME_CONTEXT extends Context> = Callback<GenerateTextAbortEvent<TOOLS, RUNTIME_CONTEXT>>;
3410
3405
  /**
3411
3406
  * Generate a text and call tools for a given prompt using a language model.
3412
3407
  *
@@ -4079,7 +4074,7 @@ type GenerateTextEndEvent<TOOLS extends ToolSet = ToolSet, RUNTIME_CONTEXT exten
4079
4074
  readonly finalStep: StepResult<TOOLS, RUNTIME_CONTEXT>;
4080
4075
  };
4081
4076
  /**
4082
- * Event passed to the telemetry `onAbort` callback.
4077
+ * Event passed to an `onAbort` callback for text generation.
4083
4078
  *
4084
4079
  * Called when a streaming text generation operation is aborted before it
4085
4080
  * completes.
@@ -7262,7 +7257,7 @@ type ChunkDetector = (buffer: string) => string | undefined | null;
7262
7257
  /**
7263
7258
  * Smooths text and reasoning streaming output.
7264
7259
  *
7265
- * @param delayInMs - The delay in milliseconds between each chunk. Defaults to 10ms. Can be set to `null` to skip the delay.
7260
+ * @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.
7266
7261
  * @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 that does not match the empty string for custom chunking, provide an Intl.Segmenter for locale-aware word segmentation (recommended for CJK languages), or provide a custom ChunkDetector function.
7267
7262
  *
7268
7263
  * @returns A transform stream that smooths text streaming output.
package/dist/index.js CHANGED
@@ -1176,7 +1176,7 @@ import {
1176
1176
  } from "@ai-sdk/provider-utils";
1177
1177
 
1178
1178
  // src/version.ts
1179
- var VERSION = true ? "7.0.91" : "0.0.0-test";
1179
+ var VERSION = true ? "7.0.92" : "0.0.0-test";
1180
1180
 
1181
1181
  // src/util/download/download.ts
1182
1182
  var download = async ({
@@ -15094,6 +15094,9 @@ var CHUNKING_REGEXPS = {
15094
15094
  word: /\S+\s+/m,
15095
15095
  line: /\n+/m
15096
15096
  };
15097
+ function isDocumentHidden() {
15098
+ return typeof document !== "undefined" && document.visibilityState === "hidden";
15099
+ }
15097
15100
  function smoothStream({
15098
15101
  delayInMs = 10,
15099
15102
  chunking = "word",
@@ -15156,7 +15159,7 @@ function smoothStream({
15156
15159
  let type = void 0;
15157
15160
  let providerMetadata = void 0;
15158
15161
  function flushBuffer(controller) {
15159
- if (buffer.length > 0 && type !== void 0) {
15162
+ if (type !== void 0 && (buffer.length > 0 || providerMetadata != null)) {
15160
15163
  controller.enqueue({
15161
15164
  type,
15162
15165
  text: buffer,
@@ -15174,7 +15177,7 @@ function smoothStream({
15174
15177
  controller.enqueue(chunk);
15175
15178
  return;
15176
15179
  }
15177
- if ((chunk.type !== type || chunk.id !== id) && buffer.length > 0) {
15180
+ if ((chunk.type !== type || chunk.id !== id) && (buffer.length > 0 || providerMetadata != null)) {
15178
15181
  flushBuffer(controller);
15179
15182
  }
15180
15183
  buffer += chunk.text;
@@ -15187,7 +15190,7 @@ function smoothStream({
15187
15190
  while ((match = detectChunk(buffer)) != null) {
15188
15191
  controller.enqueue({ type, text: match, id });
15189
15192
  buffer = buffer.slice(match.length);
15190
- await delay(delayInMs);
15193
+ await delay(isDocumentHidden() ? null : delayInMs);
15191
15194
  }
15192
15195
  }
15193
15196
  });
@@ -18463,7 +18466,6 @@ async function callCompletionApi({
18463
18466
  onError,
18464
18467
  fetch: fetch2 = getOriginalFetch()
18465
18468
  }) {
18466
- var _a25;
18467
18469
  try {
18468
18470
  setLoading(true);
18469
18471
  setError(void 0);
@@ -18491,7 +18493,7 @@ async function callCompletionApi({
18491
18493
  });
18492
18494
  if (!response.ok) {
18493
18495
  throw new Error(
18494
- (_a25 = await response.text()) != null ? _a25 : "Failed to fetch the chat response."
18496
+ await response.text() || "Failed to fetch the chat response."
18495
18497
  );
18496
18498
  }
18497
18499
  if (!response.body) {
@@ -18627,7 +18629,7 @@ var HttpChatTransport = class {
18627
18629
  abortSignal,
18628
18630
  ...options
18629
18631
  }) {
18630
- var _a25, _b25, _c, _d, _e;
18632
+ var _a25, _b25, _c, _d;
18631
18633
  const resolvedBody = await resolve2(this.body);
18632
18634
  const resolvedHeaders = await resolve2(this.headers);
18633
18635
  const resolvedCredentials = await resolve2(this.credentials);
@@ -18670,7 +18672,7 @@ var HttpChatTransport = class {
18670
18672
  });
18671
18673
  if (!response.ok) {
18672
18674
  throw new Error(
18673
- (_e = await response.text()) != null ? _e : "Failed to fetch the chat response."
18675
+ await response.text() || "Failed to fetch the chat response."
18674
18676
  );
18675
18677
  }
18676
18678
  if (!response.body) {
@@ -18679,7 +18681,7 @@ var HttpChatTransport = class {
18679
18681
  return this.processResponseStream(response.body);
18680
18682
  }
18681
18683
  async reconnectToStream(options) {
18682
- var _a25, _b25, _c, _d, _e;
18684
+ var _a25, _b25, _c, _d;
18683
18685
  const resolvedBody = await resolve2(this.body);
18684
18686
  const resolvedHeaders = await resolve2(this.headers);
18685
18687
  const resolvedCredentials = await resolve2(this.credentials);
@@ -18710,7 +18712,7 @@ var HttpChatTransport = class {
18710
18712
  }
18711
18713
  if (!response.ok) {
18712
18714
  throw new Error(
18713
- (_e = await response.text()) != null ? _e : "Failed to fetch the chat response."
18715
+ await response.text() || "Failed to fetch the chat response."
18714
18716
  );
18715
18717
  }
18716
18718
  if (!response.body) {