ai 5.0.272 → 5.0.274

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.272" : "0.0.0-test";
730
+ var VERSION = true ? "5.0.274" : "0.0.0-test";
731
731
 
732
732
  // src/util/download/download.ts
733
733
  var download = async ({
@@ -3748,7 +3748,8 @@ function processUIMessageStream({
3748
3748
  runUpdateMessageJob,
3749
3749
  onError,
3750
3750
  onToolCall,
3751
- onData
3751
+ onData,
3752
+ resetStateOnMessageIdChange = false
3752
3753
  }) {
3753
3754
  return stream.pipeThrough(
3754
3755
  new TransformStream({
@@ -4165,6 +4166,16 @@ function processUIMessageStream({
4165
4166
  break;
4166
4167
  }
4167
4168
  case "start": {
4169
+ if (resetStateOnMessageIdChange && chunk.messageId != null && chunk.messageId !== state.message.id) {
4170
+ Object.assign(
4171
+ state,
4172
+ createStreamingUIMessageState({
4173
+ lastMessage: void 0,
4174
+ messageId: chunk.messageId
4175
+ }),
4176
+ { finishReason: void 0 }
4177
+ );
4178
+ }
4168
4179
  if (chunk.messageId != null) {
4169
4180
  state.message.id = chunk.messageId;
4170
4181
  }
@@ -6322,6 +6333,20 @@ var DefaultStreamTextResult = class {
6322
6333
  }
6323
6334
  };
6324
6335
 
6336
+ // src/util/get-own.ts
6337
+ function getOwn(obj, key) {
6338
+ return obj != null && Object.hasOwn(obj, key) ? obj[key] : void 0;
6339
+ }
6340
+
6341
+ // src/ui/unavailable-tool.ts
6342
+ function markToolPartAsUnavailable(part) {
6343
+ part.dynamic = false;
6344
+ return part;
6345
+ }
6346
+ function isToolPartFromUnavailableTool(part) {
6347
+ return part.type === "dynamic-tool" && part.dynamic === false;
6348
+ }
6349
+
6325
6350
  // src/ui/convert-to-model-messages.ts
6326
6351
  function convertToModelMessages(messages, options) {
6327
6352
  const modelMessages = [];
@@ -6333,6 +6358,25 @@ function convertToModelMessages(messages, options) {
6333
6358
  )
6334
6359
  }));
6335
6360
  }
6361
+ function createModelOutput({
6362
+ toolPart,
6363
+ toolName,
6364
+ output,
6365
+ errorMode
6366
+ }) {
6367
+ const tool2 = getOwn(options == null ? void 0 : options.tools, toolName);
6368
+ if (errorMode === "none" && tool2 == null && isToolPartFromUnavailableTool(toolPart)) {
6369
+ return {
6370
+ type: "text",
6371
+ value: "Tool output omitted because the tool is no longer available."
6372
+ };
6373
+ }
6374
+ return createToolModelOutput({
6375
+ output,
6376
+ tool: tool2,
6377
+ errorMode
6378
+ });
6379
+ }
6336
6380
  for (const message of messages) {
6337
6381
  switch (message.role) {
6338
6382
  case "system": {
@@ -6386,7 +6430,7 @@ function convertToModelMessages(messages, options) {
6386
6430
  case "assistant": {
6387
6431
  if (message.parts != null) {
6388
6432
  let processBlock2 = function() {
6389
- var _a16, _b, _c;
6433
+ var _a16, _b;
6390
6434
  if (block.length === 0) {
6391
6435
  return;
6392
6436
  }
@@ -6438,9 +6482,10 @@ function convertToModelMessages(messages, options) {
6438
6482
  type: "tool-result",
6439
6483
  toolCallId: part.toolCallId,
6440
6484
  toolName,
6441
- output: createToolModelOutput({
6485
+ output: createModelOutput({
6486
+ toolPart: part,
6487
+ toolName,
6442
6488
  output: part.state === "output-error" ? part.errorText : part.output,
6443
- tool: (_b = options == null ? void 0 : options.tools) == null ? void 0 : _b[toolName],
6444
6489
  errorMode: part.state === "output-error" ? "json" : "none"
6445
6490
  }),
6446
6491
  ...part.callProviderMetadata != null ? { providerOptions: part.callProviderMetadata } : {}
@@ -6448,7 +6493,7 @@ function convertToModelMessages(messages, options) {
6448
6493
  }
6449
6494
  }
6450
6495
  } else if (isDataUIPart(part)) {
6451
- const dataPart = (_c = options == null ? void 0 : options.convertDataPart) == null ? void 0 : _c.call(
6496
+ const dataPart = (_b = options == null ? void 0 : options.convertDataPart) == null ? void 0 : _b.call(
6452
6497
  options,
6453
6498
  part
6454
6499
  );
@@ -6471,7 +6516,6 @@ function convertToModelMessages(messages, options) {
6471
6516
  modelMessages.push({
6472
6517
  role: "tool",
6473
6518
  content: toolParts.map((toolPart) => {
6474
- var _a17;
6475
6519
  switch (toolPart.state) {
6476
6520
  case "output-error":
6477
6521
  case "output-available": {
@@ -6480,9 +6524,10 @@ function convertToModelMessages(messages, options) {
6480
6524
  type: "tool-result",
6481
6525
  toolCallId: toolPart.toolCallId,
6482
6526
  toolName,
6483
- output: createToolModelOutput({
6527
+ output: createModelOutput({
6528
+ toolPart,
6529
+ toolName,
6484
6530
  output: toolPart.state === "output-error" ? toolPart.errorText : toolPart.output,
6485
- tool: (_a17 = options == null ? void 0 : options.tools) == null ? void 0 : _a17[toolName],
6486
6531
  errorMode: toolPart.state === "output-error" ? "text" : "none"
6487
6532
  }),
6488
6533
  ...toolPart.callProviderMetadata != null ? { providerOptions: toolPart.callProviderMetadata } : {}
@@ -6677,11 +6722,6 @@ var DefaultEmbedResult = class {
6677
6722
  }
6678
6723
  };
6679
6724
 
6680
- // src/util/get-own.ts
6681
- function getOwn(obj, key) {
6682
- return obj != null && Object.hasOwn(obj, key) ? obj[key] : void 0;
6683
- }
6684
-
6685
6725
  // src/util/set-own.ts
6686
6726
  function setOwn(object2, key, value) {
6687
6727
  Object.defineProperty(object2, key, {
@@ -7961,17 +8001,24 @@ var SerialJobExecutor = class {
7961
8001
  constructor() {
7962
8002
  this.queue = [];
7963
8003
  this.isProcessing = false;
8004
+ this.idleWaiters = [];
7964
8005
  }
7965
8006
  async processQueue() {
7966
8007
  if (this.isProcessing) {
7967
8008
  return;
7968
8009
  }
7969
8010
  this.isProcessing = true;
7970
- while (this.queue.length > 0) {
7971
- await this.queue[0]();
7972
- this.queue.shift();
8011
+ try {
8012
+ while (this.queue.length > 0) {
8013
+ await this.queue[0]();
8014
+ this.queue.shift();
8015
+ }
8016
+ } finally {
8017
+ this.isProcessing = false;
8018
+ for (const resolve2 of this.idleWaiters.splice(0)) {
8019
+ resolve2();
8020
+ }
7973
8021
  }
7974
- this.isProcessing = false;
7975
8022
  }
7976
8023
  async run(job) {
7977
8024
  return new Promise((resolve2, reject) => {
@@ -7986,6 +8033,14 @@ var SerialJobExecutor = class {
7986
8033
  void this.processQueue();
7987
8034
  });
7988
8035
  }
8036
+ async waitForIdle() {
8037
+ if (!this.isProcessing && this.queue.length === 0) {
8038
+ return;
8039
+ }
8040
+ await new Promise((resolve2) => {
8041
+ this.idleWaiters.push(resolve2);
8042
+ });
8043
+ }
7989
8044
  };
7990
8045
 
7991
8046
  // src/util/simulate-readable-stream.ts
@@ -9753,7 +9808,9 @@ import {
9753
9808
  } from "@ai-sdk/provider-utils";
9754
9809
  function appendPathToUrl(url, path) {
9755
9810
  const queryOrFragmentStart = url.search(/[?#]/);
9756
- return queryOrFragmentStart === -1 ? `${url}${path}` : `${url.slice(0, queryOrFragmentStart)}${path}${url.slice(queryOrFragmentStart)}`;
9811
+ const urlPath = queryOrFragmentStart === -1 ? url : url.slice(0, queryOrFragmentStart);
9812
+ const suffix = queryOrFragmentStart === -1 ? "" : url.slice(queryOrFragmentStart);
9813
+ return `${urlPath.endsWith("/") && path.startsWith("/") ? urlPath.slice(0, -1) : urlPath}${path}${suffix}`;
9757
9814
  }
9758
9815
  var HttpChatTransport = class {
9759
9816
  constructor({
@@ -9924,6 +9981,8 @@ var AbstractChat = class {
9924
9981
  this.activeResumeRequest = void 0;
9925
9982
  this.resumableStreamState = void 0;
9926
9983
  this.jobExecutor = new SerialJobExecutor();
9984
+ this.activeStopCount = 0;
9985
+ this.stopGeneration = 0;
9927
9986
  /**
9928
9987
  * Appends or replaces a user message to the chat list. This triggers the API call to fetch
9929
9988
  * the assistant's response.
@@ -10014,6 +10073,27 @@ var AbstractChat = class {
10014
10073
  this.resumeStream = async (options = {}) => {
10015
10074
  await this.makeRequest({ trigger: "resume-stream", ...options });
10016
10075
  };
10076
+ /**
10077
+ * Resume the stream if the latest response ended with a resumable network
10078
+ * disconnect. If a response is still active, wait for it to settle first so
10079
+ * disconnects reported shortly after the caller's trigger are handled.
10080
+ *
10081
+ * @internal
10082
+ */
10083
+ this["~resumeStreamIfDisconnected"] = async ({
10084
+ shouldResume = () => true
10085
+ } = {}) => {
10086
+ const activeResponse = this.activeResponse;
10087
+ if (this.resumableStreamState == null && activeResponse != null) {
10088
+ await activeResponse.completionPromise;
10089
+ if (this.resumableStreamState !== activeResponse.state) {
10090
+ return;
10091
+ }
10092
+ }
10093
+ if (this.resumableStreamState != null && shouldResume()) {
10094
+ await this.resumeStream();
10095
+ }
10096
+ };
10017
10097
  /**
10018
10098
  * Clear the error state and set the status to ready if the chat is in an error state.
10019
10099
  */
@@ -10030,15 +10110,21 @@ var AbstractChat = class {
10030
10110
  output,
10031
10111
  errorText
10032
10112
  }) => this.jobExecutor.run(async () => {
10033
- var _a16, _b;
10034
10113
  const messages = this.state.messages;
10035
- const lastMessage = messages[messages.length - 1];
10036
- this.state.replaceMessage(messages.length - 1, {
10037
- ...lastMessage,
10038
- parts: lastMessage.parts.map(
10039
- (part) => isToolOrDynamicToolUIPart(part) && part.toolCallId === toolCallId ? { ...part, state, output, errorText } : part
10114
+ const messageIndex = messages.findIndex(
10115
+ (message) => message.parts.some(
10116
+ (part) => isToolOrDynamicToolUIPart(part) && part.toolCallId === toolCallId
10040
10117
  )
10041
- });
10118
+ );
10119
+ if (messageIndex !== -1) {
10120
+ const message = messages[messageIndex];
10121
+ this.state.replaceMessage(messageIndex, {
10122
+ ...message,
10123
+ parts: message.parts.map(
10124
+ (part) => isToolOrDynamicToolUIPart(part) && part.toolCallId === toolCallId ? { ...part, state, output, errorText } : part
10125
+ )
10126
+ });
10127
+ }
10042
10128
  if (this.activeResponse) {
10043
10129
  this.activeResponse.state.message.parts = this.activeResponse.state.message.parts.map(
10044
10130
  (part) => isToolOrDynamicToolUIPart(part) && part.toolCallId === toolCallId ? {
@@ -10049,22 +10135,41 @@ var AbstractChat = class {
10049
10135
  } : part
10050
10136
  );
10051
10137
  }
10052
- if (this.status !== "streaming" && this.status !== "submitted" && ((_a16 = this.sendAutomaticallyWhen) == null ? void 0 : _a16.call(this, { messages: this.state.messages }))) {
10053
- this.makeRequest({
10054
- trigger: "submit-message",
10055
- messageId: (_b = this.lastMessage) == null ? void 0 : _b.id
10056
- });
10138
+ if (messageIndex !== -1 && this.status !== "streaming" && this.status !== "submitted" && this.sendAutomaticallyWhen) {
10139
+ const shouldSend = await this.shouldSendAutomatically();
10140
+ if (shouldSend) {
10141
+ void this.runAutomaticRequest(
10142
+ () => this.makeRequest({
10143
+ trigger: "submit-message",
10144
+ messageId: messages[messageIndex].id
10145
+ }),
10146
+ shouldSend
10147
+ );
10148
+ }
10057
10149
  }
10058
10150
  });
10059
10151
  /** @deprecated Use addToolOutput */
10060
10152
  this.addToolResult = this.addToolOutput;
10061
10153
  /**
10062
- * Abort the current request immediately, keep the generated tokens if any.
10154
+ * Abort the current request, keep the generated tokens if any, and wait for
10155
+ * the request pipeline to finish.
10063
10156
  */
10064
10157
  this.stop = async () => {
10065
- var _a16, _b;
10066
- (_a16 = this.activeResumeRequest) == null ? void 0 : _a16.abortController.abort();
10067
- (_b = this.activeResponse) == null ? void 0 : _b.abortController.abort();
10158
+ this.activeStopCount++;
10159
+ this.stopGeneration++;
10160
+ try {
10161
+ const activeResumeRequest = this.activeResumeRequest;
10162
+ const activeResponse = this.activeResponse;
10163
+ activeResumeRequest == null ? void 0 : activeResumeRequest.abortController.abort();
10164
+ activeResponse == null ? void 0 : activeResponse.abortController.abort();
10165
+ await Promise.all([
10166
+ activeResumeRequest == null ? void 0 : activeResumeRequest.completionPromise,
10167
+ activeResponse == null ? void 0 : activeResponse.completionPromise
10168
+ ]);
10169
+ await this.jobExecutor.waitForIdle();
10170
+ } finally {
10171
+ this.activeStopCount--;
10172
+ }
10068
10173
  };
10069
10174
  this.id = id;
10070
10175
  this.transport = transport;
@@ -10110,19 +10215,53 @@ var AbstractChat = class {
10110
10215
  set messages(messages) {
10111
10216
  this.state.messages = messages;
10112
10217
  }
10113
- async makeRequest({
10218
+ async shouldSendAutomatically() {
10219
+ if (!this.sendAutomaticallyWhen)
10220
+ return false;
10221
+ const result = this.sendAutomaticallyWhen({
10222
+ messages: this.state.messages
10223
+ });
10224
+ if (result && typeof result === "object" && "then" in result) {
10225
+ return await result;
10226
+ }
10227
+ return result;
10228
+ }
10229
+ async runAutomaticRequest(request, shouldSend) {
10230
+ const stopGeneration = this.stopGeneration;
10231
+ const startedWhileStopping = this.activeStopCount > 0;
10232
+ if (!(shouldSend != null ? shouldSend : await this.shouldSendAutomatically())) {
10233
+ return;
10234
+ }
10235
+ if (startedWhileStopping || stopGeneration !== this.stopGeneration || this.activeStopCount > 0) {
10236
+ return;
10237
+ }
10238
+ await request();
10239
+ }
10240
+ async makeRequest(options) {
10241
+ const completion = createResolvablePromise();
10242
+ try {
10243
+ await this.makeRequestImpl({
10244
+ ...options,
10245
+ completionPromise: completion.promise
10246
+ });
10247
+ } finally {
10248
+ completion.resolve();
10249
+ }
10250
+ }
10251
+ async makeRequestImpl({
10114
10252
  trigger,
10115
10253
  metadata,
10116
10254
  headers,
10117
10255
  body,
10118
- messageId
10256
+ messageId,
10257
+ completionPromise
10119
10258
  }) {
10120
- var _a16, _b, _c, _d;
10259
+ var _a16, _b;
10121
10260
  if (trigger !== "resume-stream") {
10122
10261
  this.resumableStreamState = void 0;
10123
10262
  }
10124
10263
  const abortController = new AbortController();
10125
- const activeResumeRequest = trigger === "resume-stream" ? { abortController } : void 0;
10264
+ const activeResumeRequest = trigger === "resume-stream" ? { abortController, completionPromise } : void 0;
10126
10265
  if (activeResumeRequest) {
10127
10266
  (_a16 = this.activeResumeRequest) == null ? void 0 : _a16.abortController.abort();
10128
10267
  this.activeResumeRequest = activeResumeRequest;
@@ -10135,9 +10274,13 @@ var AbstractChat = class {
10135
10274
  };
10136
10275
  this.setStatus({ status: "submitted", error: void 0 });
10137
10276
  const lastMessage = this.lastMessage;
10277
+ const responseMessageIndex = trigger === "submit-message" && messageId != null ? this.state.messages.findIndex((message) => message.id === messageId) : this.state.messages.length - 1;
10278
+ const responseMessage = responseMessageIndex === -1 ? lastMessage : this.state.messages[responseMessageIndex];
10279
+ const originalResponseMessageId = responseMessage == null ? void 0 : responseMessage.id;
10138
10280
  const resumableResponseMessage = trigger === "resume-stream" && (lastMessage == null ? void 0 : lastMessage.role) === "assistant" && lastMessage.parts.some(
10139
10281
  (part) => isToolOrDynamicToolUIPart(part) && part.state === "input-streaming"
10140
10282
  ) ? this.state.snapshot(lastMessage) : void 0;
10283
+ const usesEarlierAssistantMessage = responseMessageIndex !== -1 && responseMessageIndex < this.state.messages.length - 1 && (responseMessage == null ? void 0 : responseMessage.role) === "assistant";
10141
10284
  let isAbort = false;
10142
10285
  let isDisconnect = false;
10143
10286
  let isError = false;
@@ -10145,10 +10288,11 @@ var AbstractChat = class {
10145
10288
  try {
10146
10289
  const response = {
10147
10290
  state: trigger === "resume-stream" && this.resumableStreamState != null ? this.resumableStreamState : createStreamingUIMessageState({
10148
- lastMessage: trigger === "resume-stream" ? resumableResponseMessage : this.state.snapshot(lastMessage),
10291
+ lastMessage: trigger === "resume-stream" ? resumableResponseMessage : this.state.snapshot(responseMessage),
10149
10292
  messageId: this.generateId()
10150
10293
  }),
10151
- abortController
10294
+ abortController,
10295
+ completionPromise
10152
10296
  };
10153
10297
  activeResponse = response;
10154
10298
  response.abortController.signal.addEventListener("abort", () => {
@@ -10202,19 +10346,32 @@ var AbstractChat = class {
10202
10346
  return job({
10203
10347
  state: response.state,
10204
10348
  write: ({ updateStatus = true } = {}) => {
10205
- var _a17;
10206
10349
  if (response.abortController.signal.aborted) {
10207
10350
  return;
10208
10351
  }
10209
10352
  if (updateStatus) {
10210
10353
  this.setStatus({ status: "streaming" });
10211
10354
  }
10212
- const replaceLastMessage = response.state.message.id === ((_a17 = this.lastMessage) == null ? void 0 : _a17.id);
10213
- if (replaceLastMessage) {
10355
+ const existingMessageIndex = this.state.messages.findLastIndex(
10356
+ (message) => message.id === response.state.message.id
10357
+ );
10358
+ if (existingMessageIndex !== -1) {
10214
10359
  this.state.replaceMessage(
10215
- this.state.messages.length - 1,
10360
+ existingMessageIndex,
10216
10361
  response.state.message
10217
10362
  );
10363
+ } else if (usesEarlierAssistantMessage) {
10364
+ const originalMessageIndex = this.state.messages.findLastIndex(
10365
+ (message) => message.id === originalResponseMessageId
10366
+ );
10367
+ if (originalMessageIndex !== -1) {
10368
+ this.state.replaceMessage(
10369
+ originalMessageIndex,
10370
+ response.state.message
10371
+ );
10372
+ } else {
10373
+ this.state.pushMessage(response.state.message);
10374
+ }
10218
10375
  } else {
10219
10376
  this.state.pushMessage(response.state.message);
10220
10377
  }
@@ -10300,14 +10457,19 @@ var AbstractChat = class {
10300
10457
  clearActiveResumeRequest();
10301
10458
  }
10302
10459
  }
10303
- if (((_c = this.sendAutomaticallyWhen) == null ? void 0 : _c.call(this, { messages: this.state.messages })) && !isError) {
10304
- await this.makeRequest({
10305
- trigger: "submit-message",
10306
- messageId: (_d = this.lastMessage) == null ? void 0 : _d.id,
10307
- metadata,
10308
- headers,
10309
- body
10310
- });
10460
+ if (!isAbort && !isError) {
10461
+ await this.runAutomaticRequest(
10462
+ () => {
10463
+ var _a17;
10464
+ return this.makeRequest({
10465
+ trigger: "submit-message",
10466
+ messageId: (_a17 = this.lastMessage) == null ? void 0 : _a17.id,
10467
+ metadata,
10468
+ headers,
10469
+ body
10470
+ });
10471
+ }
10472
+ );
10311
10473
  }
10312
10474
  }
10313
10475
  };
@@ -10393,20 +10555,20 @@ function asDynamicToolPart(toolPart) {
10393
10555
  ...toolPart.callProviderMetadata === void 0 ? {} : { callProviderMetadata: toolPart.callProviderMetadata }
10394
10556
  };
10395
10557
  if (toolPart.state === "output-available") {
10396
- return {
10558
+ return markToolPartAsUnavailable({
10397
10559
  ...common,
10398
10560
  state: "output-available",
10399
10561
  input: toolPart.input,
10400
10562
  output: toolPart.output,
10401
10563
  ...toolPart.preliminary === void 0 ? {} : { preliminary: toolPart.preliminary }
10402
- };
10564
+ });
10403
10565
  }
10404
- return {
10566
+ return markToolPartAsUnavailable({
10405
10567
  ...common,
10406
10568
  state: "output-error",
10407
10569
  input: toolPart.input,
10408
10570
  errorText: toolPart.errorText
10409
- };
10571
+ });
10410
10572
  }
10411
10573
  var uiMessagesSchema = lazyValidator2(
10412
10574
  () => zodSchema2(
@@ -10462,6 +10624,7 @@ var uiMessagesSchema = lazyValidator2(
10462
10624
  }),
10463
10625
  z8.object({
10464
10626
  type: z8.literal("dynamic-tool"),
10627
+ dynamic: z8.literal(false).optional(),
10465
10628
  toolName: z8.string(),
10466
10629
  toolCallId: z8.string(),
10467
10630
  state: z8.literal("input-streaming"),
@@ -10473,6 +10636,7 @@ var uiMessagesSchema = lazyValidator2(
10473
10636
  }),
10474
10637
  z8.object({
10475
10638
  type: z8.literal("dynamic-tool"),
10639
+ dynamic: z8.literal(false).optional(),
10476
10640
  toolName: z8.string(),
10477
10641
  toolCallId: z8.string(),
10478
10642
  state: z8.literal("input-available"),
@@ -10484,6 +10648,7 @@ var uiMessagesSchema = lazyValidator2(
10484
10648
  }),
10485
10649
  z8.object({
10486
10650
  type: z8.literal("dynamic-tool"),
10651
+ dynamic: z8.literal(false).optional(),
10487
10652
  toolName: z8.string(),
10488
10653
  toolCallId: z8.string(),
10489
10654
  state: z8.literal("output-available"),
@@ -10496,6 +10661,7 @@ var uiMessagesSchema = lazyValidator2(
10496
10661
  }),
10497
10662
  z8.object({
10498
10663
  type: z8.literal("dynamic-tool"),
10664
+ dynamic: z8.literal(false).optional(),
10499
10665
  toolName: z8.string(),
10500
10666
  toolCallId: z8.string(),
10501
10667
  state: z8.literal("output-error"),
@@ -10695,7 +10861,7 @@ async function safeValidateUIMessages({
10695
10861
  }
10696
10862
  const toolPart = part;
10697
10863
  const toolName = toolPart.type.slice(5);
10698
- const tool2 = tools[toolName];
10864
+ const tool2 = getOwn(tools, toolName);
10699
10865
  if (!tool2 && (toolPart.state === "output-available" || toolPart.state === "output-error")) {
10700
10866
  message.parts[partIdx] = asDynamicToolPart(toolPart);
10701
10867
  continue;
@@ -10936,6 +11102,7 @@ function readUIMessageStream({
10936
11102
  consumeStream({
10937
11103
  stream: processUIMessageStream({
10938
11104
  stream,
11105
+ resetStateOnMessageIdChange: true,
10939
11106
  runUpdateMessageJob(job) {
10940
11107
  return job({
10941
11108
  state,