ai 7.0.135 → 7.0.137

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,19 @@
1
1
  # ai
2
2
 
3
+ ## 7.0.137
4
+
5
+ ### Patch Changes
6
+
7
+ - e27cc64: fix(ai): discard unrelated message state when reading resumed streams
8
+
9
+ ## 7.0.136
10
+
11
+ ### Patch Changes
12
+
13
+ - 7b5497c: Fix streaming output timeouts: stop `chunkMs` and `firstChunkMs` when the model response ends, so long-running local tools do not trigger model output timeouts. Give each retry fresh output timeout budgets. `stepMs` continues to cover the complete step, including local tools.
14
+ - Updated dependencies [e280aa1]
15
+ - @ai-sdk/gateway@4.0.110
16
+
3
17
  ## 7.0.135
4
18
 
5
19
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -749,9 +749,9 @@ type LanguageModelCallOptions = {
749
749
  * Timeout configuration for API calls. Can be specified as:
750
750
  * - A number representing milliseconds
751
751
  * - An object with `totalMs` property for the total timeout in milliseconds
752
- * - An object with `stepMs` property for the timeout of each step in milliseconds
752
+ * - An object with `stepMs` property for the timeout of each complete step, including model generation, retries, and local tool execution, in milliseconds
753
753
  * - An object with `firstChunkMs` property for the timeout until the first content chunk of each step (streaming only)
754
- * - An object with `chunkMs` property for the timeout between content chunks (streaming only)
754
+ * - An object with `chunkMs` property for the timeout between meaningful model output chunks, starting with the first output and ending when the model response ends (streaming only)
755
755
  * - An object with `toolMs` property for the default timeout for all tool executions
756
756
  * - An object with `tools` property for per-tool timeout overrides using `{toolName}Ms` keys
757
757
  */
package/dist/index.js CHANGED
@@ -1174,7 +1174,7 @@ function cloneValue(value) {
1174
1174
  }
1175
1175
  //#endregion
1176
1176
  //#region src/version.ts
1177
- const VERSION = "7.0.135";
1177
+ const VERSION = "7.0.137";
1178
1178
  //#endregion
1179
1179
  //#region src/util/download/download.ts
1180
1180
  /**
@@ -9511,6 +9511,7 @@ var DefaultStreamTextResult = class {
9511
9511
  let chunkTimeoutId = void 0;
9512
9512
  function resetChunkTimeout() {
9513
9513
  if (chunkTimeoutId != null) clearTimeout(chunkTimeoutId);
9514
+ if (abortSignal?.aborted) return;
9514
9515
  chunkTimeoutId = setAbortTimeout({
9515
9516
  abortController: chunkAbortController,
9516
9517
  label: "Chunk",
@@ -9523,13 +9524,16 @@ var DefaultStreamTextResult = class {
9523
9524
  chunkTimeoutId = void 0;
9524
9525
  }
9525
9526
  }
9527
+ function clearModelOutputTimeouts() {
9528
+ clearFirstChunkTimeout();
9529
+ clearChunkTimeout();
9530
+ }
9526
9531
  function clearStepTimeout() {
9527
9532
  if (stepTimeoutId != null) clearTimeout(stepTimeoutId);
9528
9533
  }
9529
9534
  function clearStepTimeouts() {
9530
9535
  clearStepTimeout();
9531
- clearFirstChunkTimeout();
9532
- clearChunkTimeout();
9536
+ clearModelOutputTimeouts();
9533
9537
  }
9534
9538
  function cleanupStepTimeouts() {
9535
9539
  abortSignal?.removeEventListener("abort", cleanupStepTimeouts);
@@ -9664,7 +9668,6 @@ var DefaultStreamTextResult = class {
9664
9668
  let automaticStreamRetryCount = 0;
9665
9669
  let callbackStreamRetryCount = 0;
9666
9670
  let bufferedAttemptParts = [];
9667
- const outputChunksHandledBeforeBuffering = /* @__PURE__ */ new WeakSet();
9668
9671
  const openTextParts = /* @__PURE__ */ new Set();
9669
9672
  const openReasoningParts = /* @__PURE__ */ new Set();
9670
9673
  let enqueueStreamRetryAttemptBoundary = false;
@@ -9703,28 +9706,36 @@ var DefaultStreamTextResult = class {
9703
9706
  openReasoningParts.clear();
9704
9707
  };
9705
9708
  while (true) {
9706
- const { done, value } = await languageModelStreamReader.read();
9709
+ let result;
9710
+ try {
9711
+ result = await languageModelStreamReader.read();
9712
+ } catch (error) {
9713
+ clearModelOutputTimeouts();
9714
+ throw error;
9715
+ }
9716
+ const { done, value } = result;
9707
9717
  if (enqueueStreamRetryAttemptBoundary) {
9708
9718
  controller.enqueue(createStreamRetryAttemptBoundaryPart({ warnings: !done && value.type === "model-call-start" ? value.warnings : [] }));
9709
9719
  enqueueStreamRetryAttemptBoundary = false;
9710
9720
  }
9711
9721
  if (done) {
9722
+ clearModelOutputTimeouts();
9712
9723
  flushBufferedAttemptParts();
9713
9724
  controller.close();
9714
9725
  return;
9715
9726
  }
9716
9727
  const isToolPart = value.type === "tool-input-start" || value.type === "tool-input-delta" || value.type === "tool-input-end" || value.type === "tool-call" || value.type === "tool-approval-request" || value.type === "tool-approval-response" || value.type === "tool-result" || value.type === "tool-error";
9717
9728
  if (value.type === "model-call-end") {
9729
+ clearModelOutputTimeouts();
9718
9730
  flushBufferedAttemptParts();
9719
9731
  enqueueAttemptPart(value);
9720
9732
  return;
9721
9733
  }
9734
+ if (isOutputChunk(value)) {
9735
+ clearFirstChunkTimeout();
9736
+ resetChunkTimeout();
9737
+ }
9722
9738
  if (shouldBufferToolParts && value.type !== "error" && (isToolPart || bufferedAttemptParts.length > 0)) {
9723
- if (isOutputChunk(value)) {
9724
- clearFirstChunkTimeout();
9725
- resetChunkTimeout();
9726
- outputChunksHandledBeforeBuffering.add(value);
9727
- }
9728
9739
  bufferedAttemptParts.push(value);
9729
9740
  continue;
9730
9741
  }
@@ -9732,6 +9743,7 @@ var DefaultStreamTextResult = class {
9732
9743
  enqueueAttemptPart(value);
9733
9744
  return;
9734
9745
  }
9746
+ clearModelOutputTimeouts();
9735
9747
  await notify({
9736
9748
  event: { chunk: value },
9737
9749
  callbacks: onChunk
@@ -9769,10 +9781,12 @@ var DefaultStreamTextResult = class {
9769
9781
  request = retryLanguageModelCall.request;
9770
9782
  response = retryLanguageModelCall.response;
9771
9783
  languageModelStreamReader = retryLanguageModelCall.stream.getReader();
9784
+ startFirstChunkTimeout();
9772
9785
  enqueueStreamRetryAttemptBoundary = true;
9773
9786
  }
9774
9787
  },
9775
9788
  cancel(reason) {
9789
+ clearModelOutputTimeouts();
9776
9790
  return languageModelStreamReader.cancel(reason);
9777
9791
  }
9778
9792
  });
@@ -9875,12 +9889,7 @@ var DefaultStreamTextResult = class {
9875
9889
  });
9876
9890
  }
9877
9891
  const chunkType = chunk.type;
9878
- if (isOutputChunk(chunk)) {
9879
- const timeoutHandledBeforeBuffering = outputChunksHandledBeforeBuffering.has(chunk);
9880
- if (!hasReceivedOutputChunk && !timeoutHandledBeforeBuffering) clearFirstChunkTimeout();
9881
- hasReceivedOutputChunk = true;
9882
- if (!timeoutHandledBeforeBuffering) resetChunkTimeout();
9883
- }
9892
+ if (isOutputChunk(chunk)) hasReceivedOutputChunk = true;
9884
9893
  switch (chunkType) {
9885
9894
  case "file":
9886
9895
  case "custom":
@@ -10645,6 +10654,7 @@ function readUIMessageStream({ message, stream, onError, terminateOnError = fals
10645
10654
  consumeStream({
10646
10655
  stream: processUIMessageStream({
10647
10656
  stream,
10657
+ resetStateOnMessageIdChange: true,
10648
10658
  runUpdateMessageJob(job) {
10649
10659
  return job({
10650
10660
  state,