ai 6.0.62 → 6.0.63

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,11 @@
1
1
  # ai
2
2
 
3
+ ## 6.0.63
4
+
5
+ ### Patch Changes
6
+
7
+ - be95579: fix(ui): respect `Promise<false>` when returned by `sendAutomaticallyWhen`
8
+
3
9
  ## 6.0.62
4
10
 
5
11
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -3433,6 +3433,7 @@ declare abstract class AbstractChat<UI_MESSAGE extends UIMessage> {
3433
3433
  * Abort the current request immediately, keep the generated tokens if any.
3434
3434
  */
3435
3435
  stop: () => Promise<void>;
3436
+ private shouldSendAutomatically;
3436
3437
  private makeRequest;
3437
3438
  }
3438
3439
 
package/dist/index.d.ts CHANGED
@@ -3433,6 +3433,7 @@ declare abstract class AbstractChat<UI_MESSAGE extends UIMessage> {
3433
3433
  * Abort the current request immediately, keep the generated tokens if any.
3434
3434
  */
3435
3435
  stop: () => Promise<void>;
3436
+ private shouldSendAutomatically;
3436
3437
  private makeRequest;
3437
3438
  }
3438
3439
 
package/dist/index.js CHANGED
@@ -1104,7 +1104,7 @@ var import_provider_utils3 = require("@ai-sdk/provider-utils");
1104
1104
  var import_provider_utils4 = require("@ai-sdk/provider-utils");
1105
1105
 
1106
1106
  // src/version.ts
1107
- var VERSION = true ? "6.0.62" : "0.0.0-test";
1107
+ var VERSION = true ? "6.0.63" : "0.0.0-test";
1108
1108
 
1109
1109
  // src/util/download/download.ts
1110
1110
  var download = async ({ url }) => {
@@ -12190,7 +12190,6 @@ var AbstractChat = class {
12190
12190
  approved,
12191
12191
  reason
12192
12192
  }) => this.jobExecutor.run(async () => {
12193
- var _a20, _b;
12194
12193
  const messages = this.state.messages;
12195
12194
  const lastMessage = messages[messages.length - 1];
12196
12195
  const updatePart = (part) => isToolUIPart(part) && part.state === "approval-requested" && part.approval.id === id ? {
@@ -12205,10 +12204,15 @@ var AbstractChat = class {
12205
12204
  if (this.activeResponse) {
12206
12205
  this.activeResponse.state.message.parts = this.activeResponse.state.message.parts.map(updatePart);
12207
12206
  }
12208
- if (this.status !== "streaming" && this.status !== "submitted" && ((_a20 = this.sendAutomaticallyWhen) == null ? void 0 : _a20.call(this, { messages: this.state.messages }))) {
12209
- this.makeRequest({
12210
- trigger: "submit-message",
12211
- messageId: (_b = this.lastMessage) == null ? void 0 : _b.id
12207
+ if (this.status !== "streaming" && this.status !== "submitted" && this.sendAutomaticallyWhen) {
12208
+ this.shouldSendAutomatically().then((shouldSend) => {
12209
+ var _a20;
12210
+ if (shouldSend) {
12211
+ this.makeRequest({
12212
+ trigger: "submit-message",
12213
+ messageId: (_a20 = this.lastMessage) == null ? void 0 : _a20.id
12214
+ });
12215
+ }
12212
12216
  });
12213
12217
  }
12214
12218
  });
@@ -12219,7 +12223,6 @@ var AbstractChat = class {
12219
12223
  output,
12220
12224
  errorText
12221
12225
  }) => this.jobExecutor.run(async () => {
12222
- var _a20, _b;
12223
12226
  const messages = this.state.messages;
12224
12227
  const lastMessage = messages[messages.length - 1];
12225
12228
  const updatePart = (part) => isToolUIPart(part) && part.toolCallId === toolCallId ? { ...part, state, output, errorText } : part;
@@ -12230,10 +12233,15 @@ var AbstractChat = class {
12230
12233
  if (this.activeResponse) {
12231
12234
  this.activeResponse.state.message.parts = this.activeResponse.state.message.parts.map(updatePart);
12232
12235
  }
12233
- if (this.status !== "streaming" && this.status !== "submitted" && ((_a20 = this.sendAutomaticallyWhen) == null ? void 0 : _a20.call(this, { messages: this.state.messages }))) {
12234
- this.makeRequest({
12235
- trigger: "submit-message",
12236
- messageId: (_b = this.lastMessage) == null ? void 0 : _b.id
12236
+ if (this.status !== "streaming" && this.status !== "submitted" && this.sendAutomaticallyWhen) {
12237
+ this.shouldSendAutomatically().then((shouldSend) => {
12238
+ var _a20;
12239
+ if (shouldSend) {
12240
+ this.makeRequest({
12241
+ trigger: "submit-message",
12242
+ messageId: (_a20 = this.lastMessage) == null ? void 0 : _a20.id
12243
+ });
12244
+ }
12237
12245
  });
12238
12246
  }
12239
12247
  });
@@ -12294,6 +12302,17 @@ var AbstractChat = class {
12294
12302
  set messages(messages) {
12295
12303
  this.state.messages = messages;
12296
12304
  }
12305
+ async shouldSendAutomatically() {
12306
+ if (!this.sendAutomaticallyWhen)
12307
+ return false;
12308
+ const result = this.sendAutomaticallyWhen({
12309
+ messages: this.state.messages
12310
+ });
12311
+ if (result && typeof result === "object" && "then" in result) {
12312
+ return await result;
12313
+ }
12314
+ return result;
12315
+ }
12297
12316
  async makeRequest({
12298
12317
  trigger,
12299
12318
  metadata,
@@ -12301,7 +12320,7 @@ var AbstractChat = class {
12301
12320
  body,
12302
12321
  messageId
12303
12322
  }) {
12304
- var _a20, _b, _c, _d;
12323
+ var _a20, _b, _c;
12305
12324
  this.setStatus({ status: "submitted", error: void 0 });
12306
12325
  const lastMessage = this.lastMessage;
12307
12326
  let isAbort = false;
@@ -12411,10 +12430,10 @@ var AbstractChat = class {
12411
12430
  }
12412
12431
  this.activeResponse = void 0;
12413
12432
  }
12414
- if (((_c = this.sendAutomaticallyWhen) == null ? void 0 : _c.call(this, { messages: this.state.messages })) && !isError) {
12433
+ if (!isError && await this.shouldSendAutomatically()) {
12415
12434
  await this.makeRequest({
12416
12435
  trigger: "submit-message",
12417
- messageId: (_d = this.lastMessage) == null ? void 0 : _d.id,
12436
+ messageId: (_c = this.lastMessage) == null ? void 0 : _c.id,
12418
12437
  metadata,
12419
12438
  headers,
12420
12439
  body