ai 7.0.119 → 7.0.120

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,14 @@
1
1
  # ai
2
2
 
3
+ ## 7.0.120
4
+
5
+ ### Patch Changes
6
+
7
+ - b032d70: fix(ai): preserve tool metadata from tool output chunks
8
+ - e21b98b: fix(ai): continue active UI message parts when resuming after a disconnect
9
+ - Updated dependencies [e361d39]
10
+ - @ai-sdk/gateway@4.0.98
11
+
3
12
  ## 7.0.119
4
13
 
5
14
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -5816,6 +5816,7 @@ declare abstract class AbstractChat<UI_MESSAGE extends UIMessage> {
5816
5816
  private pendingApprovalMessageId;
5817
5817
  private activeResponse;
5818
5818
  private activeResumeRequest;
5819
+ private resumableStreamState;
5819
5820
  private jobExecutor;
5820
5821
  constructor({ generateId, id, transport, messageMetadataSchema, dataPartSchemas, state, onError, onToolCall, onFinish, onData, sendAutomaticallyWhen, }: Omit<ChatInit<UI_MESSAGE>, 'messages'> & {
5821
5822
  state: ChatState<UI_MESSAGE>;
package/dist/index.js CHANGED
@@ -1328,7 +1328,7 @@ import {
1328
1328
  } from "@ai-sdk/provider-utils";
1329
1329
 
1330
1330
  // src/version.ts
1331
- var VERSION = true ? "7.0.119" : "0.0.0-test";
1331
+ var VERSION = true ? "7.0.120" : "0.0.0-test";
1332
1332
 
1333
1333
  // src/util/download/download.ts
1334
1334
  var download = async ({
@@ -7979,7 +7979,7 @@ function processUIMessageStream({
7979
7979
  providerExecuted: chunk.providerExecuted,
7980
7980
  providerMetadata: chunk.providerMetadata,
7981
7981
  title: toolInvocation.title,
7982
- toolMetadata: toolInvocation.toolMetadata
7982
+ toolMetadata: chunk.toolMetadata ?? toolInvocation.toolMetadata
7983
7983
  },
7984
7984
  toolInvocation
7985
7985
  );
@@ -7995,7 +7995,7 @@ function processUIMessageStream({
7995
7995
  preliminary: chunk.preliminary,
7996
7996
  providerMetadata: chunk.providerMetadata,
7997
7997
  title: toolInvocation.title,
7998
- toolMetadata: toolInvocation.toolMetadata
7998
+ toolMetadata: chunk.toolMetadata ?? toolInvocation.toolMetadata
7999
7999
  },
8000
8000
  toolInvocation
8001
8001
  );
@@ -8016,7 +8016,7 @@ function processUIMessageStream({
8016
8016
  providerExecuted: chunk.providerExecuted,
8017
8017
  providerMetadata: chunk.providerMetadata,
8018
8018
  title: toolInvocation.title,
8019
- toolMetadata: toolInvocation.toolMetadata
8019
+ toolMetadata: chunk.toolMetadata ?? toolInvocation.toolMetadata
8020
8020
  },
8021
8021
  toolInvocation
8022
8022
  );
@@ -8032,7 +8032,7 @@ function processUIMessageStream({
8032
8032
  providerExecuted: chunk.providerExecuted,
8033
8033
  providerMetadata: chunk.providerMetadata,
8034
8034
  title: toolInvocation.title,
8035
- toolMetadata: toolInvocation.toolMetadata
8035
+ toolMetadata: chunk.toolMetadata ?? toolInvocation.toolMetadata
8036
8036
  },
8037
8037
  toolInvocation
8038
8038
  );
@@ -22007,6 +22007,7 @@ var AbstractChat = class {
22007
22007
  this.pendingMessagePreparations = /* @__PURE__ */ new Set();
22008
22008
  this.activeResponse = void 0;
22009
22009
  this.activeResumeRequest = void 0;
22010
+ this.resumableStreamState = void 0;
22010
22011
  this.jobExecutor = new SerialJobExecutor();
22011
22012
  /**
22012
22013
  * Appends or replaces a user message to the chat list. This triggers the API call to fetch
@@ -22301,6 +22302,9 @@ var AbstractChat = class {
22301
22302
  body,
22302
22303
  messageId
22303
22304
  }) {
22305
+ if (trigger !== "resume-stream") {
22306
+ this.resumableStreamState = void 0;
22307
+ }
22304
22308
  const abortController = new AbortController();
22305
22309
  const activeResumeRequest = trigger === "resume-stream" ? { abortController } : void 0;
22306
22310
  if (activeResumeRequest) {
@@ -22328,12 +22332,14 @@ var AbstractChat = class {
22328
22332
  });
22329
22333
  if (isCurrentRequest()) {
22330
22334
  this.setStatus({ status: "ready" });
22335
+ this.resumableStreamState = void 0;
22331
22336
  }
22332
22337
  clearActiveResumeRequest();
22333
22338
  return;
22334
22339
  }
22335
22340
  if (reconnect == null) {
22336
22341
  this.setStatus({ status: "ready" });
22342
+ this.resumableStreamState = void 0;
22337
22343
  clearActiveResumeRequest();
22338
22344
  return;
22339
22345
  }
@@ -22342,6 +22348,7 @@ var AbstractChat = class {
22342
22348
  if (abortController.signal.aborted || err.name === "AbortError") {
22343
22349
  if (isCurrentRequest()) {
22344
22350
  this.setStatus({ status: "ready" });
22351
+ this.resumableStreamState = void 0;
22345
22352
  }
22346
22353
  clearActiveResumeRequest();
22347
22354
  return;
@@ -22368,7 +22375,7 @@ var AbstractChat = class {
22368
22375
  let activeResponse;
22369
22376
  try {
22370
22377
  const response = {
22371
- state: createStreamingUIMessageState({
22378
+ state: trigger === "resume-stream" && this.resumableStreamState != null ? this.resumableStreamState : createStreamingUIMessageState({
22372
22379
  lastMessage: trigger === "resume-stream" || trigger === "regenerate-message" ? void 0 : this.state.snapshot(responseMessage),
22373
22380
  messageId: this.generateId()
22374
22381
  }),
@@ -22446,17 +22453,26 @@ var AbstractChat = class {
22446
22453
  if (isAbort) {
22447
22454
  if (isCurrentRequest()) {
22448
22455
  this.setStatus({ status: "ready" });
22456
+ if (this.resumableStreamState === response.state) {
22457
+ this.resumableStreamState = void 0;
22458
+ }
22449
22459
  }
22450
22460
  return null;
22451
22461
  }
22452
22462
  if (isCurrentRequest()) {
22453
22463
  this.setStatus({ status: "ready" });
22464
+ if (this.resumableStreamState === response.state) {
22465
+ this.resumableStreamState = void 0;
22466
+ }
22454
22467
  }
22455
22468
  } catch (err) {
22456
22469
  if (isAbort || err.name === "AbortError") {
22457
22470
  isAbort = true;
22458
22471
  if (isCurrentRequest()) {
22459
22472
  this.setStatus({ status: "ready" });
22473
+ if (this.resumableStreamState === activeResponse?.state) {
22474
+ this.resumableStreamState = void 0;
22475
+ }
22460
22476
  }
22461
22477
  return null;
22462
22478
  }
@@ -22467,6 +22483,11 @@ var AbstractChat = class {
22467
22483
  if (err instanceof TypeError && (err.message.toLowerCase().includes("fetch") || err.message.toLowerCase().includes("network"))) {
22468
22484
  isDisconnect = true;
22469
22485
  }
22486
+ if (isDisconnect) {
22487
+ this.resumableStreamState = activeResponse?.state;
22488
+ } else if (this.resumableStreamState === activeResponse?.state) {
22489
+ this.resumableStreamState = void 0;
22490
+ }
22470
22491
  if (this.onError && err instanceof Error) {
22471
22492
  this.onError(err);
22472
22493
  }