ai 7.0.78 → 7.0.82

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.
Files changed (52) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/dist/index.d.ts +103 -37
  3. package/dist/index.js +608 -422
  4. package/dist/index.js.map +1 -1
  5. package/dist/internal/index.d.ts +9 -1
  6. package/dist/internal/index.js +4 -2
  7. package/dist/internal/index.js.map +1 -1
  8. package/dist/test/index.d.ts +4 -1
  9. package/dist/test/index.js +4 -0
  10. package/dist/test/index.js.map +1 -1
  11. package/docs/02-foundations/02-providers-and-models.mdx +2 -2
  12. package/docs/03-agents/06-policy-tool-approvals.mdx +1 -1
  13. package/docs/03-agents/06-tool-approvals.mdx +6 -0
  14. package/docs/03-ai-sdk-core/15-tools-and-tool-calling.mdx +6 -4
  15. package/docs/03-ai-sdk-core/50-error-handling.mdx +17 -2
  16. package/docs/03-ai-sdk-harnesses/05-harness-adapters.mdx +4 -4
  17. package/docs/04-ai-sdk-ui/03-chatbot-tool-usage.mdx +6 -0
  18. package/docs/04-ai-sdk-ui/50-stream-protocol.mdx +2 -2
  19. package/docs/07-reference/01-ai-sdk-core/01-generate-text.mdx +1 -1
  20. package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +5 -4
  21. package/docs/07-reference/01-ai-sdk-core/06-embed-many.mdx +6 -2
  22. package/docs/07-reference/01-ai-sdk-core/16-tool-loop-agent.mdx +1 -1
  23. package/docs/07-reference/02-ai-sdk-ui/31-convert-to-model-messages.mdx +2 -2
  24. package/docs/07-reference/04-ai-sdk-workflow/03-generate-video.mdx +157 -0
  25. package/docs/07-reference/04-ai-sdk-workflow/index.mdx +6 -0
  26. package/docs/07-reference/05-ai-sdk-errors/ai-stream-provider-error.mdx +52 -0
  27. package/docs/07-reference/05-ai-sdk-errors/index.mdx +1 -0
  28. package/package.json +18 -7
  29. package/src/batch/batch-types.ts +7 -0
  30. package/src/batch/batch.ts +2 -0
  31. package/src/embed/embed-many.ts +78 -8
  32. package/src/error/index.ts +1 -0
  33. package/src/error/stream-provider-error.ts +78 -0
  34. package/src/generate-text/execute-tools-from-stream.ts +3 -0
  35. package/src/generate-text/generate-text-result.ts +2 -1
  36. package/src/generate-text/generate-text.ts +9 -2
  37. package/src/generate-text/stream-language-model-call.ts +8 -0
  38. package/src/generate-text/to-response-messages.ts +1 -0
  39. package/src/generate-text/tool-approval-configuration.ts +5 -1
  40. package/src/generate-text/tool-approval-request-output.ts +5 -0
  41. package/src/index.ts +7 -1
  42. package/src/middleware/wrap-embedding-model.ts +11 -2
  43. package/src/model/get-embedding-model-max-input-bytes-per-call.ts +15 -0
  44. package/src/prompt/content-part.ts +1 -0
  45. package/src/prompt/normalize-stream-provider-error.ts +131 -0
  46. package/src/test/mock-embedding-model-v4.ts +9 -0
  47. package/src/ui/convert-to-model-messages.ts +3 -0
  48. package/src/ui/process-ui-message-stream.ts +8 -3
  49. package/src/ui/ui-messages.ts +10 -0
  50. package/src/ui/validate-ui-messages.ts +10 -0
  51. package/src/ui-message-stream/to-ui-message-chunk.ts +1 -0
  52. package/src/ui-message-stream/ui-message-chunks.ts +2 -0
package/dist/index.js CHANGED
@@ -1,11 +1,14 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __export = (target, all) => {
3
- for (var name23 in all)
4
- __defProp(target, name23, { get: all[name23], enumerable: true });
3
+ for (var name24 in all)
4
+ __defProp(target, name24, { get: all[name24], enumerable: true });
5
5
  };
6
6
 
7
7
  // src/index.ts
8
- import { createGateway, gateway as gateway2 } from "@ai-sdk/gateway";
8
+ import {
9
+ createGateway,
10
+ gateway as gateway2
11
+ } from "@ai-sdk/gateway";
9
12
  import {
10
13
  asSchema as asSchema8,
11
14
  createIdGenerator as createIdGenerator9,
@@ -34,7 +37,7 @@ import {
34
37
 
35
38
  // src/error/index.ts
36
39
  import {
37
- AISDKError as AISDKError23,
40
+ AISDKError as AISDKError24,
38
41
  APICallError,
39
42
  EmptyResponseBodyError,
40
43
  InvalidPromptError,
@@ -413,31 +416,64 @@ var NoSuchToolError = class extends AISDKError15 {
413
416
  };
414
417
  _a15 = symbol15;
415
418
 
416
- // src/error/tool-call-repair-error.ts
417
- import { AISDKError as AISDKError16, getErrorMessage as getErrorMessage2 } from "@ai-sdk/provider";
418
- var name16 = "AI_ToolCallRepairError";
419
+ // src/error/stream-provider-error.ts
420
+ import { AISDKError as AISDKError16 } from "@ai-sdk/provider";
421
+ var name16 = "AI_StreamProviderError";
419
422
  var marker16 = `vercel.ai.error.${name16}`;
420
423
  var symbol16 = Symbol.for(marker16);
421
424
  var _a16;
422
- var ToolCallRepairError = class extends AISDKError16 {
425
+ var StreamProviderError = class extends AISDKError16 {
423
426
  constructor({
424
- cause,
425
- originalError,
426
- message = `Error repairing tool call: ${getErrorMessage2(cause)}`
427
+ message,
428
+ type,
429
+ code,
430
+ statusCode,
431
+ isRetryable = isRetryableStatusCode(statusCode),
432
+ data,
433
+ cause
427
434
  }) {
428
435
  super({ name: name16, message, cause });
429
436
  this[_a16] = true;
430
- this.originalError = originalError;
437
+ this.type = type;
438
+ this.code = code;
439
+ this.statusCode = statusCode;
440
+ this.isRetryable = isRetryable;
441
+ this.data = data;
431
442
  }
432
443
  static isInstance(error) {
433
444
  return AISDKError16.hasMarker(error, marker16);
434
445
  }
435
446
  };
436
447
  _a16 = symbol16;
448
+ function isRetryableStatusCode(statusCode) {
449
+ return statusCode != null && (statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500);
450
+ }
451
+
452
+ // src/error/tool-call-repair-error.ts
453
+ import { AISDKError as AISDKError17, getErrorMessage as getErrorMessage2 } from "@ai-sdk/provider";
454
+ var name17 = "AI_ToolCallRepairError";
455
+ var marker17 = `vercel.ai.error.${name17}`;
456
+ var symbol17 = Symbol.for(marker17);
457
+ var _a17;
458
+ var ToolCallRepairError = class extends AISDKError17 {
459
+ constructor({
460
+ cause,
461
+ originalError,
462
+ message = `Error repairing tool call: ${getErrorMessage2(cause)}`
463
+ }) {
464
+ super({ name: name17, message, cause });
465
+ this[_a17] = true;
466
+ this.originalError = originalError;
467
+ }
468
+ static isInstance(error) {
469
+ return AISDKError17.hasMarker(error, marker17);
470
+ }
471
+ };
472
+ _a17 = symbol17;
437
473
 
438
474
  // src/error/unsupported-model-version-error.ts
439
- import { AISDKError as AISDKError17 } from "@ai-sdk/provider";
440
- var UnsupportedModelVersionError = class extends AISDKError17 {
475
+ import { AISDKError as AISDKError18 } from "@ai-sdk/provider";
476
+ var UnsupportedModelVersionError = class extends AISDKError18 {
441
477
  constructor(options) {
442
478
  super({
443
479
  name: "AI_UnsupportedModelVersionError",
@@ -450,118 +486,118 @@ var UnsupportedModelVersionError = class extends AISDKError17 {
450
486
  };
451
487
 
452
488
  // src/error/ui-message-stream-error.ts
453
- import { AISDKError as AISDKError18 } from "@ai-sdk/provider";
454
- var name17 = "AI_UIMessageStreamError";
455
- var marker17 = `vercel.ai.error.${name17}`;
456
- var symbol17 = Symbol.for(marker17);
457
- var _a17;
458
- var UIMessageStreamError = class extends AISDKError18 {
489
+ import { AISDKError as AISDKError19 } from "@ai-sdk/provider";
490
+ var name18 = "AI_UIMessageStreamError";
491
+ var marker18 = `vercel.ai.error.${name18}`;
492
+ var symbol18 = Symbol.for(marker18);
493
+ var _a18;
494
+ var UIMessageStreamError = class extends AISDKError19 {
459
495
  constructor({
460
496
  chunkType,
461
497
  chunkId,
462
498
  message
463
499
  }) {
464
- super({ name: name17, message });
465
- this[_a17] = true;
500
+ super({ name: name18, message });
501
+ this[_a18] = true;
466
502
  this.chunkType = chunkType;
467
503
  this.chunkId = chunkId;
468
504
  }
469
505
  static isInstance(error) {
470
- return AISDKError18.hasMarker(error, marker17);
506
+ return AISDKError19.hasMarker(error, marker18);
471
507
  }
472
508
  };
473
- _a17 = symbol17;
509
+ _a18 = symbol18;
474
510
 
475
511
  // src/prompt/invalid-data-content-error.ts
476
- import { AISDKError as AISDKError19 } from "@ai-sdk/provider";
477
- var name18 = "AI_InvalidDataContentError";
478
- var marker18 = `vercel.ai.error.${name18}`;
479
- var symbol18 = Symbol.for(marker18);
480
- var _a18;
481
- var InvalidDataContentError = class extends AISDKError19 {
512
+ import { AISDKError as AISDKError20 } from "@ai-sdk/provider";
513
+ var name19 = "AI_InvalidDataContentError";
514
+ var marker19 = `vercel.ai.error.${name19}`;
515
+ var symbol19 = Symbol.for(marker19);
516
+ var _a19;
517
+ var InvalidDataContentError = class extends AISDKError20 {
482
518
  constructor({
483
519
  content,
484
520
  cause,
485
521
  message = `Invalid data content. Expected a base64 string, Uint8Array, ArrayBuffer, or Buffer, but got ${typeof content}.`
486
522
  }) {
487
- super({ name: name18, message, cause });
488
- this[_a18] = true;
523
+ super({ name: name19, message, cause });
524
+ this[_a19] = true;
489
525
  this.content = content;
490
526
  }
491
527
  static isInstance(error) {
492
- return AISDKError19.hasMarker(error, marker18);
528
+ return AISDKError20.hasMarker(error, marker19);
493
529
  }
494
530
  };
495
- _a18 = symbol18;
531
+ _a19 = symbol19;
496
532
 
497
533
  // src/prompt/invalid-message-role-error.ts
498
- import { AISDKError as AISDKError20 } from "@ai-sdk/provider";
499
- var name19 = "AI_InvalidMessageRoleError";
500
- var marker19 = `vercel.ai.error.${name19}`;
501
- var symbol19 = Symbol.for(marker19);
502
- var _a19;
503
- var InvalidMessageRoleError = class extends AISDKError20 {
534
+ import { AISDKError as AISDKError21 } from "@ai-sdk/provider";
535
+ var name20 = "AI_InvalidMessageRoleError";
536
+ var marker20 = `vercel.ai.error.${name20}`;
537
+ var symbol20 = Symbol.for(marker20);
538
+ var _a20;
539
+ var InvalidMessageRoleError = class extends AISDKError21 {
504
540
  constructor({
505
541
  role,
506
542
  message = `Invalid message role: '${role}'. Must be one of: "system", "user", "assistant", "tool".`
507
543
  }) {
508
- super({ name: name19, message });
509
- this[_a19] = true;
544
+ super({ name: name20, message });
545
+ this[_a20] = true;
510
546
  this.role = role;
511
547
  }
512
548
  static isInstance(error) {
513
- return AISDKError20.hasMarker(error, marker19);
549
+ return AISDKError21.hasMarker(error, marker20);
514
550
  }
515
551
  };
516
- _a19 = symbol19;
552
+ _a20 = symbol20;
517
553
 
518
554
  // src/prompt/message-conversion-error.ts
519
- import { AISDKError as AISDKError21 } from "@ai-sdk/provider";
520
- var name20 = "AI_MessageConversionError";
521
- var marker20 = `vercel.ai.error.${name20}`;
522
- var symbol20 = Symbol.for(marker20);
523
- var _a20;
524
- var MessageConversionError = class extends AISDKError21 {
555
+ import { AISDKError as AISDKError22 } from "@ai-sdk/provider";
556
+ var name21 = "AI_MessageConversionError";
557
+ var marker21 = `vercel.ai.error.${name21}`;
558
+ var symbol21 = Symbol.for(marker21);
559
+ var _a21;
560
+ var MessageConversionError = class extends AISDKError22 {
525
561
  constructor({
526
562
  originalMessage,
527
563
  message
528
564
  }) {
529
- super({ name: name20, message });
530
- this[_a20] = true;
565
+ super({ name: name21, message });
566
+ this[_a21] = true;
531
567
  this.originalMessage = originalMessage;
532
568
  }
533
569
  static isInstance(error) {
534
- return AISDKError21.hasMarker(error, marker20);
570
+ return AISDKError22.hasMarker(error, marker21);
535
571
  }
536
572
  };
537
- _a20 = symbol20;
573
+ _a21 = symbol21;
538
574
 
539
575
  // src/error/index.ts
540
576
  import { DownloadError } from "@ai-sdk/provider-utils";
541
577
 
542
578
  // src/util/retry-error.ts
543
- import { AISDKError as AISDKError22 } from "@ai-sdk/provider";
544
- var name21 = "AI_RetryError";
545
- var marker21 = `vercel.ai.error.${name21}`;
546
- var symbol21 = Symbol.for(marker21);
547
- var _a21;
548
- var RetryError = class extends AISDKError22 {
579
+ import { AISDKError as AISDKError23 } from "@ai-sdk/provider";
580
+ var name22 = "AI_RetryError";
581
+ var marker22 = `vercel.ai.error.${name22}`;
582
+ var symbol22 = Symbol.for(marker22);
583
+ var _a22;
584
+ var RetryError = class extends AISDKError23 {
549
585
  constructor({
550
586
  message,
551
587
  reason,
552
588
  errors
553
589
  }) {
554
- super({ name: name21, message });
555
- this[_a21] = true;
590
+ super({ name: name22, message });
591
+ this[_a22] = true;
556
592
  this.reason = reason;
557
593
  this.errors = errors;
558
594
  this.lastError = errors[errors.length - 1];
559
595
  }
560
596
  static isInstance(error) {
561
- return AISDKError22.hasMarker(error, marker21);
597
+ return AISDKError23.hasMarker(error, marker22);
562
598
  }
563
599
  };
564
- _a21 = symbol21;
600
+ _a22 = symbol22;
565
601
 
566
602
  // src/logger/log-warnings.ts
567
603
  function formatWarning({
@@ -981,9 +1017,9 @@ function resolveEmbeddingModel(model) {
981
1017
  return asEmbeddingModelV4(model);
982
1018
  }
983
1019
  function resolveTranscriptionModel(model) {
984
- var _a23, _b;
1020
+ var _a24, _b;
985
1021
  if (typeof model === "string") {
986
- return (_b = (_a23 = getGlobalProvider()).transcriptionModel) == null ? void 0 : _b.call(_a23, model);
1022
+ return (_b = (_a24 = getGlobalProvider()).transcriptionModel) == null ? void 0 : _b.call(_a24, model);
987
1023
  }
988
1024
  if (!["v4", "v3", "v2"].includes(model.specificationVersion)) {
989
1025
  const unsupportedModel = model;
@@ -996,9 +1032,9 @@ function resolveTranscriptionModel(model) {
996
1032
  return asTranscriptionModelV4(model);
997
1033
  }
998
1034
  function resolveSpeechTranslationModel(model) {
999
- var _a23;
1035
+ var _a24;
1000
1036
  if (typeof model === "string") {
1001
- const provider = (_a23 = globalThis.AI_SDK_DEFAULT_PROVIDER) != null ? _a23 : gateway;
1037
+ const provider = (_a24 = globalThis.AI_SDK_DEFAULT_PROVIDER) != null ? _a24 : gateway;
1002
1038
  const speechTranslationModel = provider.speechTranslationModel;
1003
1039
  if (!speechTranslationModel) {
1004
1040
  throw new Error(
@@ -1018,9 +1054,9 @@ function resolveSpeechTranslationModel(model) {
1018
1054
  return model;
1019
1055
  }
1020
1056
  function resolveSpeechModel(model) {
1021
- var _a23, _b;
1057
+ var _a24, _b;
1022
1058
  if (typeof model === "string") {
1023
- return (_b = (_a23 = getGlobalProvider()).speechModel) == null ? void 0 : _b.call(_a23, model);
1059
+ return (_b = (_a24 = getGlobalProvider()).speechModel) == null ? void 0 : _b.call(_a24, model);
1024
1060
  }
1025
1061
  if (!["v4", "v3", "v2"].includes(model.specificationVersion)) {
1026
1062
  const unsupportedModel = model;
@@ -1047,9 +1083,9 @@ function resolveImageModel(model) {
1047
1083
  return asImageModelV4(model);
1048
1084
  }
1049
1085
  function resolveVideoModel(model) {
1050
- var _a23;
1086
+ var _a24;
1051
1087
  if (typeof model === "string") {
1052
- const provider = (_a23 = globalThis.AI_SDK_DEFAULT_PROVIDER) != null ? _a23 : gateway;
1088
+ const provider = (_a24 = globalThis.AI_SDK_DEFAULT_PROVIDER) != null ? _a24 : gateway;
1053
1089
  const videoModel = provider.videoModel;
1054
1090
  if (!videoModel) {
1055
1091
  throw new Error(
@@ -1090,8 +1126,8 @@ function resolveRerankingModel(model) {
1090
1126
  return asRerankingModelV4(model);
1091
1127
  }
1092
1128
  function getGlobalProvider() {
1093
- var _a23;
1094
- const provider = (_a23 = globalThis.AI_SDK_DEFAULT_PROVIDER) != null ? _a23 : gateway;
1129
+ var _a24;
1130
+ const provider = (_a24 = globalThis.AI_SDK_DEFAULT_PROVIDER) != null ? _a24 : gateway;
1095
1131
  return asProviderV4(provider);
1096
1132
  }
1097
1133
 
@@ -1143,7 +1179,7 @@ import {
1143
1179
  } from "@ai-sdk/provider-utils";
1144
1180
 
1145
1181
  // src/version.ts
1146
- var VERSION = true ? "7.0.78" : "0.0.0-test";
1182
+ var VERSION = true ? "7.0.82" : "0.0.0-test";
1147
1183
 
1148
1184
  // src/util/download/download.ts
1149
1185
  var download = async ({
@@ -1151,7 +1187,7 @@ var download = async ({
1151
1187
  maxBytes,
1152
1188
  abortSignal
1153
1189
  }) => {
1154
- var _a23;
1190
+ var _a24;
1155
1191
  const urlText = url.toString();
1156
1192
  try {
1157
1193
  const headers = withUserAgentSuffix(
@@ -1179,7 +1215,7 @@ var download = async ({
1179
1215
  });
1180
1216
  return {
1181
1217
  data,
1182
- mediaType: (_a23 = response.headers.get("content-type")) != null ? _a23 : void 0
1218
+ mediaType: (_a24 = response.headers.get("content-type")) != null ? _a24 : void 0
1183
1219
  };
1184
1220
  } catch (error) {
1185
1221
  if (DownloadError2.isInstance(error)) {
@@ -1646,14 +1682,14 @@ function convertToLanguageModelMessage({
1646
1682
  }
1647
1683
  }
1648
1684
  function convertImagePartToFilePart(part) {
1649
- var _a23;
1685
+ var _a24;
1650
1686
  if (part.type !== "image") {
1651
1687
  return part;
1652
1688
  }
1653
1689
  return {
1654
1690
  type: "file",
1655
1691
  data: part.image,
1656
- mediaType: (_a23 = part.mediaType) != null ? _a23 : "image",
1692
+ mediaType: (_a24 = part.mediaType) != null ? _a24 : "image",
1657
1693
  providerOptions: part.providerOptions
1658
1694
  };
1659
1695
  }
@@ -1775,7 +1811,7 @@ function mapToolResultOutput({
1775
1811
  return {
1776
1812
  type: "content",
1777
1813
  value: output.value.map((item) => {
1778
- var _a23;
1814
+ var _a24;
1779
1815
  switch (item.type) {
1780
1816
  case "file": {
1781
1817
  const convertedPart = convertPartToLanguageModelPart(
@@ -1804,7 +1840,7 @@ function mapToolResultOutput({
1804
1840
  };
1805
1841
  }
1806
1842
  case "file-url": {
1807
- const mediaType = (_a23 = item.mediaType) != null ? _a23 : getMediaTypeFromUrl(item.url);
1843
+ const mediaType = (_a24 = item.mediaType) != null ? _a24 : getMediaTypeFromUrl(item.url);
1808
1844
  let message = `The "file-url" type for tool result content is deprecated. Use the "file" type with mediaType and { type: 'url', url } instead.`;
1809
1845
  if (!item.mediaType) {
1810
1846
  const inferenceSuffix = mediaType === "application/octet-stream" ? `Unable to infer media type from URL. Defaulting to 'application/octet-stream'.` : `Inferred media type '${mediaType}' from URL.`;
@@ -1958,10 +1994,10 @@ var URL_EXTENSION_TO_MEDIA_TYPE = {
1958
1994
  ogg: "audio/ogg"
1959
1995
  };
1960
1996
  function getMediaTypeFromUrl(url, fallbackMediaType = "application/octet-stream") {
1961
- var _a23;
1997
+ var _a24;
1962
1998
  try {
1963
1999
  const pathname = new URL(url).pathname;
1964
- const fileExtension = (_a23 = pathname.split(".").pop()) == null ? void 0 : _a23.toLowerCase();
2000
+ const fileExtension = (_a24 = pathname.split(".").pop()) == null ? void 0 : _a24.toLowerCase();
1965
2001
  if (fileExtension && Object.hasOwn(URL_EXTENSION_TO_MEDIA_TYPE, fileExtension)) {
1966
2002
  return URL_EXTENSION_TO_MEDIA_TYPE[fileExtension];
1967
2003
  }
@@ -2116,7 +2152,7 @@ async function prepareTools({
2116
2152
  return void 0;
2117
2153
  }
2118
2154
  const languageModelTools = [];
2119
- for (const [name23, tool2] of orderToolEntries({ tools, toolOrder })) {
2155
+ for (const [name24, tool2] of orderToolEntries({ tools, toolOrder })) {
2120
2156
  const toolType = tool2.type;
2121
2157
  switch (toolType) {
2122
2158
  case void 0:
@@ -2124,7 +2160,7 @@ async function prepareTools({
2124
2160
  case "function": {
2125
2161
  const description = resolveToolDescription({
2126
2162
  tool: tool2,
2127
- toolName: name23,
2163
+ toolName: name24,
2128
2164
  toolsContext,
2129
2165
  experimental_sandbox: sandbox
2130
2166
  });
@@ -2133,7 +2169,7 @@ async function prepareTools({
2133
2169
  const strict = tool2.strict;
2134
2170
  languageModelTools.push({
2135
2171
  type: "function",
2136
- name: name23,
2172
+ name: name24,
2137
2173
  inputSchema: await asSchema(tool2.inputSchema).jsonSchema,
2138
2174
  ...description != null ? { description } : {},
2139
2175
  ...inputExamples != null ? { inputExamples } : {},
@@ -2145,7 +2181,7 @@ async function prepareTools({
2145
2181
  case "provider": {
2146
2182
  languageModelTools.push({
2147
2183
  type: "provider",
2148
- name: name23,
2184
+ name: name24,
2149
2185
  id: tool2.id,
2150
2186
  args: tool2.args
2151
2187
  });
@@ -2167,10 +2203,10 @@ function orderToolEntries({
2167
2203
  return Object.entries(tools);
2168
2204
  }
2169
2205
  const toolEntries = Object.entries(tools);
2170
- const orderedTools = toolEntries.filter(([name23]) => toolOrder.includes(name23)).sort(
2206
+ const orderedTools = toolEntries.filter(([name24]) => toolOrder.includes(name24)).sort(
2171
2207
  ([nameA], [nameB]) => toolOrder.indexOf(nameA) - toolOrder.indexOf(nameB)
2172
2208
  );
2173
- const unorderedTools = toolEntries.filter(([name23]) => !toolOrder.includes(name23)).sort(([nameA], [nameB]) => nameA < nameB ? -1 : nameA > nameB ? 1 : 0);
2209
+ const unorderedTools = toolEntries.filter(([name24]) => !toolOrder.includes(name24)).sort(([nameA], [nameB]) => nameA < nameB ? -1 : nameA > nameB ? 1 : 0);
2174
2210
  return [...orderedTools, ...unorderedTools];
2175
2211
  }
2176
2212
  function resolveToolDescription({
@@ -2214,11 +2250,11 @@ function getChunkTimeoutMs(timeout) {
2214
2250
  return timeout.chunkMs;
2215
2251
  }
2216
2252
  function getToolTimeoutMs(timeout, toolName) {
2217
- var _a23, _b;
2253
+ var _a24, _b;
2218
2254
  if (timeout == null || typeof timeout === "number") {
2219
2255
  return void 0;
2220
2256
  }
2221
- return (_b = (_a23 = timeout.tools) == null ? void 0 : _a23[`${toolName}Ms`]) != null ? _b : timeout.toolMs;
2257
+ return (_b = (_a24 = timeout.tools) == null ? void 0 : _a24[`${toolName}Ms`]) != null ? _b : timeout.toolMs;
2222
2258
  }
2223
2259
 
2224
2260
  // src/prompt/standardize-prompt.ts
@@ -2481,7 +2517,8 @@ var toolApprovalRequestSchema = z.object(
2481
2517
  {
2482
2518
  type: z.literal("tool-approval-request"),
2483
2519
  approvalId: z.string(),
2484
- toolCallId: z.string()
2520
+ toolCallId: z.string(),
2521
+ reason: z.string().optional()
2485
2522
  }
2486
2523
  );
2487
2524
  var toolApprovalResponseSchema = z.object({
@@ -2600,14 +2637,14 @@ async function standardizePrompt({
2600
2637
 
2601
2638
  // src/prompt/wrap-gateway-error.ts
2602
2639
  import { GatewayAuthenticationError } from "@ai-sdk/gateway";
2603
- import { AISDKError as AISDKError24 } from "@ai-sdk/provider";
2640
+ import { AISDKError as AISDKError25 } from "@ai-sdk/provider";
2604
2641
  function wrapGatewayError(error) {
2605
2642
  if (!GatewayAuthenticationError.isInstance(error))
2606
2643
  return error;
2607
2644
  const isProductionEnv = (process == null ? void 0 : process.env.NODE_ENV) === "production";
2608
2645
  const moreInfoURL = "https://ai-sdk.dev/unauthenticated-ai-gateway";
2609
2646
  if (isProductionEnv) {
2610
- return new AISDKError24({
2647
+ return new AISDKError25({
2611
2648
  name: "GatewayError",
2612
2649
  message: `Unauthenticated. Configure AI_GATEWAY_API_KEY or use a provider module. Learn more: ${moreInfoURL}`
2613
2650
  });
@@ -2665,12 +2702,12 @@ function createNullLanguageModelUsage() {
2665
2702
  };
2666
2703
  }
2667
2704
  function addLanguageModelUsage(usage1, usage2) {
2668
- var _a23, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2705
+ var _a24, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2669
2706
  return {
2670
2707
  inputTokens: addTokenCounts(usage1.inputTokens, usage2.inputTokens),
2671
2708
  inputTokenDetails: {
2672
2709
  noCacheTokens: addTokenCounts(
2673
- (_a23 = usage1.inputTokenDetails) == null ? void 0 : _a23.noCacheTokens,
2710
+ (_a24 = usage1.inputTokenDetails) == null ? void 0 : _a24.noCacheTokens,
2674
2711
  (_b = usage2.inputTokenDetails) == null ? void 0 : _b.noCacheTokens
2675
2712
  ),
2676
2713
  cacheReadTokens: addTokenCounts(
@@ -2723,8 +2760,8 @@ function mergeAbortSignals(...signals) {
2723
2760
 
2724
2761
  // src/util/now.ts
2725
2762
  function now() {
2726
- var _a23, _b;
2727
- return (_b = (_a23 = globalThis == null ? void 0 : globalThis.performance) == null ? void 0 : _a23.now()) != null ? _b : Date.now();
2763
+ var _a24, _b;
2764
+ return (_b = (_a24 = globalThis == null ? void 0 : globalThis.performance) == null ? void 0 : _a24.now()) != null ? _b : Date.now();
2728
2765
  }
2729
2766
 
2730
2767
  // src/util/notify.ts
@@ -3098,7 +3135,7 @@ function filterActiveTools({
3098
3135
  return tools;
3099
3136
  }
3100
3137
  return Object.fromEntries(
3101
- Object.entries(tools).filter(([name23]) => activeTools.includes(name23))
3138
+ Object.entries(tools).filter(([name24]) => activeTools.includes(name24))
3102
3139
  );
3103
3140
  }
3104
3141
 
@@ -3535,7 +3572,7 @@ var text = () => ({
3535
3572
  });
3536
3573
  var object2 = ({
3537
3574
  schema: inputSchema,
3538
- name: name23,
3575
+ name: name24,
3539
3576
  description
3540
3577
  }) => {
3541
3578
  const schema = asSchema2(inputSchema);
@@ -3544,7 +3581,7 @@ var object2 = ({
3544
3581
  responseFormat: resolve(schema.jsonSchema).then((jsonSchema2) => ({
3545
3582
  type: "json",
3546
3583
  schema: jsonSchema2,
3547
- ...name23 != null && { name: name23 },
3584
+ ...name24 != null && { name: name24 },
3548
3585
  ...description != null && { description }
3549
3586
  })),
3550
3587
  async parseCompleteOutput({ text: text2 }, context) {
@@ -3598,7 +3635,7 @@ var object2 = ({
3598
3635
  };
3599
3636
  var array2 = ({
3600
3637
  element: inputElementSchema,
3601
- name: name23,
3638
+ name: name24,
3602
3639
  description
3603
3640
  }) => {
3604
3641
  const elementSchema = asSchema2(inputElementSchema);
@@ -3625,7 +3662,7 @@ var array2 = ({
3625
3662
  required: ["elements"],
3626
3663
  additionalProperties: false
3627
3664
  },
3628
- ...name23 != null && { name: name23 },
3665
+ ...name24 != null && { name: name24 },
3629
3666
  ...description != null && { description }
3630
3667
  };
3631
3668
  }),
@@ -3719,7 +3756,7 @@ var array2 = ({
3719
3756
  };
3720
3757
  var choice = ({
3721
3758
  options: choiceOptions,
3722
- name: name23,
3759
+ name: name24,
3723
3760
  description
3724
3761
  }) => {
3725
3762
  return {
@@ -3736,7 +3773,7 @@ var choice = ({
3736
3773
  required: ["result"],
3737
3774
  additionalProperties: false
3738
3775
  },
3739
- ...name23 != null && { name: name23 },
3776
+ ...name24 != null && { name: name24 },
3740
3777
  ...description != null && { description }
3741
3778
  }),
3742
3779
  async parseCompleteOutput({ text: text2 }, context) {
@@ -3797,14 +3834,14 @@ var choice = ({
3797
3834
  };
3798
3835
  };
3799
3836
  var json = ({
3800
- name: name23,
3837
+ name: name24,
3801
3838
  description
3802
3839
  } = {}) => {
3803
3840
  return {
3804
3841
  name: "json",
3805
3842
  responseFormat: Promise.resolve({
3806
3843
  type: "json",
3807
- ...name23 != null && { name: name23 },
3844
+ ...name24 != null && { name: name24 },
3808
3845
  ...description != null && { description }
3809
3846
  }),
3810
3847
  async parseCompleteOutput({ text: text2 }, context) {
@@ -3879,8 +3916,8 @@ async function parseToolCall({
3879
3916
  toolCall,
3880
3917
  tools,
3881
3918
  inputSchema: async ({ toolName }) => {
3882
- var _a23;
3883
- const inputSchema = (_a23 = getOwn(tools, toolName)) == null ? void 0 : _a23.inputSchema;
3919
+ var _a24;
3920
+ const inputSchema = (_a24 = getOwn(tools, toolName)) == null ? void 0 : _a24.inputSchema;
3884
3921
  return await asSchema3(inputSchema).jsonSchema;
3885
3922
  },
3886
3923
  instructions,
@@ -4004,9 +4041,9 @@ function prepareStepCallSettings({
4004
4041
  callSettings,
4005
4042
  stepSettings
4006
4043
  }) {
4007
- var _a23, _b, _c, _d, _e, _f, _g, _h, _i;
4044
+ var _a24, _b, _c, _d, _e, _f, _g, _h, _i;
4008
4045
  return prepareLanguageModelCallOptions({
4009
- maxOutputTokens: (_a23 = stepSettings == null ? void 0 : stepSettings.maxOutputTokens) != null ? _a23 : callSettings.maxOutputTokens,
4046
+ maxOutputTokens: (_a24 = stepSettings == null ? void 0 : stepSettings.maxOutputTokens) != null ? _a24 : callSettings.maxOutputTokens,
4010
4047
  temperature: (_b = stepSettings == null ? void 0 : stepSettings.temperature) != null ? _b : callSettings.temperature,
4011
4048
  topP: (_c = stepSettings == null ? void 0 : stepSettings.topP) != null ? _c : callSettings.topP,
4012
4049
  topK: (_d = stepSettings == null ? void 0 : stepSettings.topK) != null ? _d : callSettings.topK,
@@ -4138,8 +4175,8 @@ var AI_SDK_TELEMETRY_TRACING_CHANNEL = "ai:telemetry";
4138
4175
 
4139
4176
  // src/util/is-node-runtime.ts
4140
4177
  function isNodeRuntime() {
4141
- var _a23;
4142
- return typeof process !== "undefined" && ((_a23 = process.release) == null ? void 0 : _a23.name) === "node";
4178
+ var _a24;
4179
+ return typeof process !== "undefined" && ((_a24 = process.release) == null ? void 0 : _a24.name) === "node";
4143
4180
  }
4144
4181
 
4145
4182
  // src/telemetry/tracing-channel-publisher.ts
@@ -4156,18 +4193,18 @@ async function loadDiagnosticsChannel() {
4156
4193
  return diagnosticsChannelPromise;
4157
4194
  }
4158
4195
  function loadBuiltinModule(id) {
4159
- var _a23;
4196
+ var _a24;
4160
4197
  const processWithBuiltins = globalThis.process;
4161
4198
  try {
4162
- return (_a23 = processWithBuiltins == null ? void 0 : processWithBuiltins.getBuiltinModule) == null ? void 0 : _a23.call(processWithBuiltins, id);
4199
+ return (_a24 = processWithBuiltins == null ? void 0 : processWithBuiltins.getBuiltinModule) == null ? void 0 : _a24.call(processWithBuiltins, id);
4163
4200
  } catch (e) {
4164
4201
  return void 0;
4165
4202
  }
4166
4203
  }
4167
4204
  async function runWithTracingChannelSpan(message, execute) {
4168
- var _a23;
4205
+ var _a24;
4169
4206
  const diagnosticsChannel = await loadDiagnosticsChannel();
4170
- const tracingChannel = (_a23 = diagnosticsChannel == null ? void 0 : diagnosticsChannel.tracingChannel) == null ? void 0 : _a23.call(
4207
+ const tracingChannel = (_a24 = diagnosticsChannel == null ? void 0 : diagnosticsChannel.tracingChannel) == null ? void 0 : _a24.call(
4171
4208
  diagnosticsChannel,
4172
4209
  AI_SDK_TELEMETRY_TRACING_CHANNEL
4173
4210
  );
@@ -4218,7 +4255,7 @@ function openTelemetryChannelSpanContext({
4218
4255
  message,
4219
4256
  completion
4220
4257
  }) {
4221
- var _a23;
4258
+ var _a24;
4222
4259
  if (!isNodeRuntime()) {
4223
4260
  return void 0;
4224
4261
  }
@@ -4226,7 +4263,7 @@ function openTelemetryChannelSpanContext({
4226
4263
  "node:diagnostics_channel"
4227
4264
  );
4228
4265
  const asyncHooks = loadBuiltinModule("node:async_hooks");
4229
- const tracingChannel = (_a23 = diagnosticsChannel == null ? void 0 : diagnosticsChannel.tracingChannel) == null ? void 0 : _a23.call(
4266
+ const tracingChannel = (_a24 = diagnosticsChannel == null ? void 0 : diagnosticsChannel.tracingChannel) == null ? void 0 : _a24.call(
4230
4267
  diagnosticsChannel,
4231
4268
  AI_SDK_TELEMETRY_TRACING_CHANNEL
4232
4269
  );
@@ -4284,8 +4321,8 @@ function registerTelemetry(...integrations) {
4284
4321
  globalThis.AI_SDK_TELEMETRY_INTEGRATIONS.push(...integrations);
4285
4322
  }
4286
4323
  function getGlobalTelemetryIntegrations() {
4287
- var _a23;
4288
- return (_a23 = globalThis.AI_SDK_TELEMETRY_INTEGRATIONS) != null ? _a23 : [];
4324
+ var _a24;
4325
+ return (_a24 = globalThis.AI_SDK_TELEMETRY_INTEGRATIONS) != null ? _a24 : [];
4289
4326
  }
4290
4327
 
4291
4328
  // src/telemetry/create-telemetry-dispatcher.ts
@@ -4311,8 +4348,8 @@ function createTelemetryDispatcher({
4311
4348
  };
4312
4349
  const mergeTelemetryCallback = (key) => {
4313
4350
  const integrationCallbacks = integrations.map((integration) => {
4314
- var _a23;
4315
- return (_a23 = integration[key]) == null ? void 0 : _a23.bind(integration);
4351
+ var _a24;
4352
+ return (_a24 = integration[key]) == null ? void 0 : _a24.bind(integration);
4316
4353
  }).filter(Boolean).map(
4317
4354
  (callback) => (event) => callback(augmentEvent(event, telemetryMetadata))
4318
4355
  );
@@ -4322,12 +4359,12 @@ function createTelemetryDispatcher({
4322
4359
  };
4323
4360
  };
4324
4361
  const executeLanguageModelCallWrappers = integrations.map((integration) => {
4325
- var _a23;
4326
- return (_a23 = integration.executeLanguageModelCall) == null ? void 0 : _a23.bind(integration);
4362
+ var _a24;
4363
+ return (_a24 = integration.executeLanguageModelCall) == null ? void 0 : _a24.bind(integration);
4327
4364
  }).filter(Boolean);
4328
4365
  const executeToolWrappers = integrations.map((integration) => {
4329
- var _a23;
4330
- return (_a23 = integration.executeTool) == null ? void 0 : _a23.bind(integration);
4366
+ var _a24;
4367
+ return (_a24 = integration.executeTool) == null ? void 0 : _a24.bind(integration);
4331
4368
  }).filter(Boolean);
4332
4369
  return {
4333
4370
  runInTracingChannelSpan: async ({ type, event, execute }) => await runWithTracingChannelSpan(
@@ -4571,8 +4608,8 @@ function createRestrictedTelemetryDispatcher({
4571
4608
  return {
4572
4609
  ...telemetryDispatcher,
4573
4610
  onStart: (event) => {
4574
- var _a23;
4575
- return (_a23 = telemetryDispatcher.onStart) == null ? void 0 : _a23.call(telemetryDispatcher, {
4611
+ var _a24;
4612
+ return (_a24 = telemetryDispatcher.onStart) == null ? void 0 : _a24.call(telemetryDispatcher, {
4576
4613
  ...event,
4577
4614
  runtimeContext: filterIncludedContext({
4578
4615
  context: event.runtimeContext,
@@ -4585,8 +4622,8 @@ function createRestrictedTelemetryDispatcher({
4585
4622
  });
4586
4623
  },
4587
4624
  onStepStart: (event) => {
4588
- var _a23;
4589
- return (_a23 = telemetryDispatcher.onStepStart) == null ? void 0 : _a23.call(telemetryDispatcher, {
4625
+ var _a24;
4626
+ return (_a24 = telemetryDispatcher.onStepStart) == null ? void 0 : _a24.call(telemetryDispatcher, {
4590
4627
  ...event,
4591
4628
  runtimeContext: filterIncludedContext({
4592
4629
  context: event.runtimeContext,
@@ -4606,8 +4643,8 @@ function createRestrictedTelemetryDispatcher({
4606
4643
  });
4607
4644
  },
4608
4645
  onStepEnd: (event) => {
4609
- var _a23;
4610
- return (_a23 = telemetryDispatcher.onStepEnd) == null ? void 0 : _a23.call(
4646
+ var _a24;
4647
+ return (_a24 = telemetryDispatcher.onStepEnd) == null ? void 0 : _a24.call(
4611
4648
  telemetryDispatcher,
4612
4649
  restrictStepResult({
4613
4650
  step: event,
@@ -4617,8 +4654,8 @@ function createRestrictedTelemetryDispatcher({
4617
4654
  );
4618
4655
  },
4619
4656
  onStepFinish: (event) => {
4620
- var _a23;
4621
- return (_a23 = telemetryDispatcher.onStepEnd) == null ? void 0 : _a23.call(
4657
+ var _a24;
4658
+ return (_a24 = telemetryDispatcher.onStepEnd) == null ? void 0 : _a24.call(
4622
4659
  telemetryDispatcher,
4623
4660
  restrictStepResult({
4624
4661
  step: event,
@@ -4628,8 +4665,8 @@ function createRestrictedTelemetryDispatcher({
4628
4665
  );
4629
4666
  },
4630
4667
  onEnd: (event) => {
4631
- var _a23;
4632
- return (_a23 = telemetryDispatcher.onEnd) == null ? void 0 : _a23.call(
4668
+ var _a24;
4669
+ return (_a24 = telemetryDispatcher.onEnd) == null ? void 0 : _a24.call(
4633
4670
  telemetryDispatcher,
4634
4671
  ((restrictedSteps) => {
4635
4672
  return {
@@ -4657,8 +4694,8 @@ function createRestrictedTelemetryDispatcher({
4657
4694
  );
4658
4695
  },
4659
4696
  onAbort: (event) => {
4660
- var _a23;
4661
- return (_a23 = telemetryDispatcher.onAbort) == null ? void 0 : _a23.call(telemetryDispatcher, {
4697
+ var _a24;
4698
+ return (_a24 = telemetryDispatcher.onAbort) == null ? void 0 : _a24.call(telemetryDispatcher, {
4662
4699
  ...event,
4663
4700
  steps: event.steps.map(
4664
4701
  (step) => restrictStepResult({
@@ -4670,8 +4707,8 @@ function createRestrictedTelemetryDispatcher({
4670
4707
  });
4671
4708
  },
4672
4709
  onToolExecutionStart: (event) => {
4673
- var _a23;
4674
- return (_a23 = telemetryDispatcher.onToolExecutionStart) == null ? void 0 : _a23.call(telemetryDispatcher, {
4710
+ var _a24;
4711
+ return (_a24 = telemetryDispatcher.onToolExecutionStart) == null ? void 0 : _a24.call(telemetryDispatcher, {
4675
4712
  ...event,
4676
4713
  toolContext: filterToolContext({
4677
4714
  toolName: event.toolCall.toolName,
@@ -4681,8 +4718,8 @@ function createRestrictedTelemetryDispatcher({
4681
4718
  });
4682
4719
  },
4683
4720
  onToolExecutionEnd: (event) => {
4684
- var _a23;
4685
- return (_a23 = telemetryDispatcher.onToolExecutionEnd) == null ? void 0 : _a23.call(telemetryDispatcher, {
4721
+ var _a24;
4722
+ return (_a24 = telemetryDispatcher.onToolExecutionEnd) == null ? void 0 : _a24.call(telemetryDispatcher, {
4686
4723
  ...event,
4687
4724
  toolContext: filterToolContext({
4688
4725
  toolName: event.toolCall.toolName,
@@ -4703,8 +4740,8 @@ function isLoopFinished() {
4703
4740
  }
4704
4741
  function hasToolCall(...toolName) {
4705
4742
  return ({ steps }) => {
4706
- var _a23, _b, _c;
4707
- return (_c = (_b = (_a23 = steps[steps.length - 1]) == null ? void 0 : _a23.toolCalls) == null ? void 0 : _b.some(
4743
+ var _a24, _b, _c;
4744
+ return (_c = (_b = (_a24 = steps[steps.length - 1]) == null ? void 0 : _a24.toolCalls) == null ? void 0 : _b.some(
4708
4745
  (toolCall) => toolName.includes(toolCall.toolName)
4709
4746
  )) != null ? _c : false;
4710
4747
  };
@@ -4829,6 +4866,7 @@ async function toResponseMessages({
4829
4866
  type: "tool-approval-request",
4830
4867
  approvalId: part.approvalId,
4831
4868
  toolCallId: part.toolCall.toolCallId,
4869
+ ...part.reason != null ? { reason: part.reason } : {},
4832
4870
  isAutomatic: part.isAutomatic,
4833
4871
  ...part.signature != null ? { signature: part.signature } : {}
4834
4872
  });
@@ -4968,7 +5006,7 @@ function prepareToolsForToolCallers({
4968
5006
  tools,
4969
5007
  toolCallers
4970
5008
  }) {
4971
- var _a23, _b;
5009
+ var _a24, _b;
4972
5010
  if (tools == null || toolCallers == null) {
4973
5011
  return { executionTools: tools, modelTools: tools };
4974
5012
  }
@@ -5001,7 +5039,7 @@ function prepareToolsForToolCallers({
5001
5039
  )
5002
5040
  };
5003
5041
  } else {
5004
- const localTools = (_a23 = localToolsByCaller.get(callerName)) != null ? _a23 : {};
5042
+ const localTools = (_a24 = localToolsByCaller.get(callerName)) != null ? _a24 : {};
5005
5043
  localTools[toolName] = preparedTool;
5006
5044
  localToolsByCaller.set(callerName, localTools);
5007
5045
  }
@@ -5160,7 +5198,7 @@ async function validateApprovedToolApprovals({
5160
5198
  runtimeContext,
5161
5199
  toolApprovalSecret
5162
5200
  }) {
5163
- var _a23;
5201
+ var _a24;
5164
5202
  const approved = [];
5165
5203
  const denied = [];
5166
5204
  const invalid = [];
@@ -5222,7 +5260,7 @@ async function validateApprovedToolApprovals({
5222
5260
  approvalResponse: {
5223
5261
  ...approval.approvalResponse,
5224
5262
  approved: false,
5225
- reason: (_a23 = approvalStatus.reason) != null ? _a23 : approval.approvalResponse.reason
5263
+ reason: (_a24 = approvalStatus.reason) != null ? _a24 : approval.approvalResponse.reason
5226
5264
  }
5227
5265
  });
5228
5266
  } else {
@@ -5301,9 +5339,9 @@ async function generateText({
5301
5339
  onEnd = onFinish,
5302
5340
  ...settings
5303
5341
  }) {
5304
- var _a23, _b, _c, _d;
5342
+ var _a24, _b, _c, _d;
5305
5343
  include = {
5306
- requestBody: (_a23 = include == null ? void 0 : include.requestBody) != null ? _a23 : false,
5344
+ requestBody: (_a24 = include == null ? void 0 : include.requestBody) != null ? _a24 : false,
5307
5345
  requestMessages: (_b = include == null ? void 0 : include.requestMessages) != null ? _b : false,
5308
5346
  responseBody: (_c = include == null ? void 0 : include.responseBody) != null ? _c : false
5309
5347
  };
@@ -5402,7 +5440,7 @@ async function generateText({
5402
5440
  toolsContext
5403
5441
  };
5404
5442
  const executeGenerateText = async () => {
5405
- var _a24;
5443
+ var _a25;
5406
5444
  await notify({
5407
5445
  event: generateTextStartEvent,
5408
5446
  callbacks: [resolvedOnStart, telemetryDispatcher.onStart]
@@ -5548,7 +5586,7 @@ async function generateText({
5548
5586
  type: "step",
5549
5587
  event: { callId, stepNumber },
5550
5588
  execute: async () => {
5551
- var _a25, _b2, _c2, _d2, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
5589
+ var _a26, _b2, _c2, _d2, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
5552
5590
  const accumulatedResponseMessages = [
5553
5591
  ...initialResponseMessages,
5554
5592
  ...steps.flatMap((step) => step.response.messages)
@@ -5567,7 +5605,7 @@ async function generateText({
5567
5605
  toolsContext,
5568
5606
  experimental_sandbox: sandbox
5569
5607
  }));
5570
- const stepSandbox = (_a25 = prepareStepResult == null ? void 0 : prepareStepResult.experimental_sandbox) != null ? _a25 : sandbox;
5608
+ const stepSandbox = (_a26 = prepareStepResult == null ? void 0 : prepareStepResult.experimental_sandbox) != null ? _a26 : sandbox;
5571
5609
  const stepModel = resolveLanguageModel(
5572
5610
  (_b2 = prepareStepResult == null ? void 0 : prepareStepResult.model) != null ? _b2 : model
5573
5611
  );
@@ -5662,7 +5700,7 @@ async function generateText({
5662
5700
  });
5663
5701
  const executeLanguageModelCallInTelemetryContext = (_n = telemetryDispatcher.executeLanguageModelCall) != null ? _n : async ({ execute }) => await execute();
5664
5702
  currentModelResponse = await retry(async () => {
5665
- var _a26, _b3, _c3, _d3, _e2, _f2, _g2, _h2;
5703
+ var _a27, _b3, _c3, _d3, _e2, _f2, _g2, _h2;
5666
5704
  const result = await executeLanguageModelCallInTelemetryContext(
5667
5705
  {
5668
5706
  ...languageModelCallStartEvent,
@@ -5679,7 +5717,7 @@ async function generateText({
5679
5717
  }
5680
5718
  );
5681
5719
  const responseData = {
5682
- id: (_b3 = (_a26 = result.response) == null ? void 0 : _a26.id) != null ? _b3 : generateId4(),
5720
+ id: (_b3 = (_a27 = result.response) == null ? void 0 : _a27.id) != null ? _b3 : generateId4(),
5683
5721
  timestamp: (_d3 = (_c3 = result.response) == null ? void 0 : _c3.timestamp) != null ? _d3 : /* @__PURE__ */ new Date(),
5684
5722
  modelId: (_f2 = (_e2 = result.response) == null ? void 0 : _e2.modelId) != null ? _f2 : stepModel.modelId,
5685
5723
  headers: (_g2 = result.response) == null ? void 0 : _g2.headers,
@@ -5801,6 +5839,7 @@ async function generateText({
5801
5839
  type: "tool-approval-request",
5802
5840
  approvalId,
5803
5841
  toolCall,
5842
+ ...toolApprovalStatus.reason != null ? { reason: toolApprovalStatus.reason } : {},
5804
5843
  ...signature != null ? { signature } : {}
5805
5844
  };
5806
5845
  blockedToolCallIds.add(toolCall.toolCallId);
@@ -6039,8 +6078,8 @@ async function generateText({
6039
6078
  const staticToolResults = steps.flatMap((step) => step.staticToolResults);
6040
6079
  const dynamicToolResults = steps.flatMap((step) => step.dynamicToolResults);
6041
6080
  const warnings = steps.flatMap((step) => {
6042
- var _a25;
6043
- return (_a25 = step.warnings) != null ? _a25 : [];
6081
+ var _a26;
6082
+ return (_a26 = step.warnings) != null ? _a26 : [];
6044
6083
  });
6045
6084
  const onEndEvent = {
6046
6085
  callId,
@@ -6080,7 +6119,7 @@ async function generateText({
6080
6119
  callbacks: [onEnd, telemetryDispatcher.onEnd]
6081
6120
  });
6082
6121
  let resolvedOutput;
6083
- if (lastStep.finishReason === "stop") {
6122
+ if (lastStep.finishReason === "stop" || lastStep.finishReason !== "tool-calls" && lastStep.text.length > 0) {
6084
6123
  const outputSpecification = output != null ? output : text();
6085
6124
  resolvedOutput = await outputSpecification.parseCompleteOutput(
6086
6125
  { text: lastStep.text },
@@ -6098,7 +6137,7 @@ async function generateText({
6098
6137
  output: resolvedOutput
6099
6138
  });
6100
6139
  } catch (error) {
6101
- await ((_a24 = telemetryDispatcher.onError) == null ? void 0 : _a24.call(telemetryDispatcher, { callId, error }));
6140
+ await ((_a25 = telemetryDispatcher.onError) == null ? void 0 : _a25.call(telemetryDispatcher, { callId, error }));
6102
6141
  throw wrapGatewayError(error);
6103
6142
  }
6104
6143
  };
@@ -6198,8 +6237,8 @@ var DefaultGenerateTextResult = class {
6198
6237
  }
6199
6238
  get warnings() {
6200
6239
  return this.steps.flatMap((step) => {
6201
- var _a23;
6202
- return (_a23 = step.warnings) != null ? _a23 : [];
6240
+ var _a24;
6241
+ return (_a24 = step.warnings) != null ? _a24 : [];
6203
6242
  });
6204
6243
  }
6205
6244
  get providerMetadata() {
@@ -6644,6 +6683,7 @@ var uiMessageChunkSchema = lazySchema(
6644
6683
  type: z.literal("tool-approval-request"),
6645
6684
  approvalId: z.string(),
6646
6685
  toolCallId: z.string(),
6686
+ reason: z.string().optional(),
6647
6687
  isAutomatic: z.boolean().optional(),
6648
6688
  signature: z.string().optional()
6649
6689
  }),
@@ -6847,7 +6887,7 @@ function processUIMessageStream({
6847
6887
  new TransformStream({
6848
6888
  async transform(chunk, controller) {
6849
6889
  await runUpdateMessageJob(async ({ state, write }) => {
6850
- var _a23, _b, _c, _d;
6890
+ var _a24, _b, _c, _d;
6851
6891
  function getCurrentStepParts() {
6852
6892
  const parts = state.message.parts;
6853
6893
  let currentStepStartIndex = parts.length - 1;
@@ -6887,8 +6927,8 @@ function processUIMessageStream({
6887
6927
  const toolInvocations = state.message.parts.filter(isToolUIPart);
6888
6928
  const toolInvocation = toolInvocations.find(
6889
6929
  (invocation) => {
6890
- var _a24;
6891
- return ((_a24 = invocation.approval) == null ? void 0 : _a24.id) === approvalId;
6930
+ var _a25;
6931
+ return ((_a25 = invocation.approval) == null ? void 0 : _a25.id) === approvalId;
6892
6932
  }
6893
6933
  );
6894
6934
  if (toolInvocation == null) {
@@ -6901,7 +6941,7 @@ function processUIMessageStream({
6901
6941
  return toolInvocation;
6902
6942
  }
6903
6943
  function updateToolPart(options, existingPart) {
6904
- var _a24;
6944
+ var _a25;
6905
6945
  const part = existingPart != null ? existingPart : getCurrentStepParts().find(
6906
6946
  (part2) => isStaticToolUIPart(part2) && part2.toolCallId === options.toolCallId
6907
6947
  );
@@ -6920,7 +6960,7 @@ function processUIMessageStream({
6920
6960
  if (options.toolMetadata !== void 0) {
6921
6961
  anyPart.toolMetadata = options.toolMetadata;
6922
6962
  }
6923
- anyPart.providerExecuted = (_a24 = anyOptions.providerExecuted) != null ? _a24 : part.providerExecuted;
6963
+ anyPart.providerExecuted = (_a25 = anyOptions.providerExecuted) != null ? _a25 : part.providerExecuted;
6924
6964
  const providerMetadata = anyOptions.providerMetadata;
6925
6965
  if (providerMetadata != null) {
6926
6966
  if (options.state === "output-available" || options.state === "output-error") {
@@ -6949,7 +6989,7 @@ function processUIMessageStream({
6949
6989
  }
6950
6990
  }
6951
6991
  function updateDynamicToolPart(options, existingPart) {
6952
- var _a24, _b2;
6992
+ var _a25, _b2;
6953
6993
  const part = existingPart != null ? existingPart : getCurrentStepParts().find(
6954
6994
  (part2) => part2.type === "dynamic-tool" && part2.toolCallId === options.toolCallId
6955
6995
  );
@@ -6961,7 +7001,7 @@ function processUIMessageStream({
6961
7001
  anyPart.input = anyOptions.input;
6962
7002
  anyPart.output = anyOptions.output;
6963
7003
  anyPart.errorText = anyOptions.errorText;
6964
- anyPart.rawInput = (_a24 = anyOptions.rawInput) != null ? _a24 : anyPart.rawInput;
7004
+ anyPart.rawInput = (_a25 = anyOptions.rawInput) != null ? _a25 : anyPart.rawInput;
6965
7005
  anyPart.preliminary = anyOptions.preliminary;
6966
7006
  if (options.title !== void 0) {
6967
7007
  anyPart.title = options.title;
@@ -7036,7 +7076,7 @@ function processUIMessageStream({
7036
7076
  });
7037
7077
  }
7038
7078
  textPart.text += chunk.delta;
7039
- textPart.providerMetadata = (_a23 = chunk.providerMetadata) != null ? _a23 : textPart.providerMetadata;
7079
+ textPart.providerMetadata = (_a24 = chunk.providerMetadata) != null ? _a24 : textPart.providerMetadata;
7040
7080
  write();
7041
7081
  break;
7042
7082
  }
@@ -7279,6 +7319,7 @@ function processUIMessageStream({
7279
7319
  toolInvocation.state = "approval-requested";
7280
7320
  toolInvocation.approval = {
7281
7321
  id: chunk.approvalId,
7322
+ ...chunk.reason != null ? { requestReason: chunk.reason } : {},
7282
7323
  ...chunk.isAutomatic === true ? { isAutomatic: true } : {},
7283
7324
  ...chunk.signature != null ? { signature: chunk.signature } : {}
7284
7325
  };
@@ -7294,6 +7335,7 @@ function processUIMessageStream({
7294
7335
  toolInvocation.approval = {
7295
7336
  id: chunk.approvalId,
7296
7337
  approved: chunk.approved,
7338
+ ...approval.requestReason != null ? { requestReason: approval.requestReason } : {},
7297
7339
  ...chunk.reason != null ? { reason: chunk.reason } : {},
7298
7340
  ...approval.isAutomatic === true ? { isAutomatic: true } : {},
7299
7341
  ...approval.signature != null ? { signature: approval.signature } : {}
@@ -7393,8 +7435,6 @@ function processUIMessageStream({
7393
7435
  break;
7394
7436
  }
7395
7437
  case "finish-step": {
7396
- state.activeTextParts = createIdMap();
7397
- state.activeReasoningParts = createIdMap();
7398
7438
  break;
7399
7439
  }
7400
7440
  case "reset-step": {
@@ -7753,6 +7793,7 @@ function toUIMessageChunk(part, {
7753
7793
  type: "tool-approval-request",
7754
7794
  approvalId: part.approvalId,
7755
7795
  toolCallId: part.toolCall.toolCallId,
7796
+ ...part.reason != null ? { reason: part.reason } : {},
7756
7797
  ...part.isAutomatic != null ? { isAutomatic: part.isAutomatic } : {},
7757
7798
  ...part.signature != null ? { signature: part.signature } : {}
7758
7799
  };
@@ -7909,13 +7950,13 @@ function asAsyncIterableStream(stream) {
7909
7950
  const reader = this.getReader();
7910
7951
  let finished = false;
7911
7952
  async function cleanup(cancelStream) {
7912
- var _a23;
7953
+ var _a24;
7913
7954
  if (finished)
7914
7955
  return;
7915
7956
  finished = true;
7916
7957
  try {
7917
7958
  if (cancelStream) {
7918
- await ((_a23 = reader.cancel) == null ? void 0 : _a23.call(reader));
7959
+ await ((_a24 = reader.cancel) == null ? void 0 : _a24.call(reader));
7919
7960
  }
7920
7961
  } finally {
7921
7962
  try {
@@ -8033,7 +8074,7 @@ function createStitchableStream() {
8033
8074
  controller == null ? void 0 : controller.close();
8034
8075
  };
8035
8076
  const processPull = async () => {
8036
- var _a23;
8077
+ var _a24;
8037
8078
  if (isClosed && innerStreams.length === 0) {
8038
8079
  controller == null ? void 0 : controller.close();
8039
8080
  return;
@@ -8057,7 +8098,7 @@ function createStitchableStream() {
8057
8098
  controller == null ? void 0 : controller.enqueue(value);
8058
8099
  }
8059
8100
  } catch (error) {
8060
- (_a23 = currentStream.onError) == null ? void 0 : _a23.call(currentStream, error);
8101
+ (_a24 = currentStream.onError) == null ? void 0 : _a24.call(currentStream, error);
8061
8102
  controller == null ? void 0 : controller.error(error);
8062
8103
  innerStreams.shift();
8063
8104
  terminate();
@@ -8169,6 +8210,7 @@ function executeToolsFromStream({
8169
8210
  type: "tool-approval-request",
8170
8211
  approvalId,
8171
8212
  toolCall: chunk,
8213
+ ...toolApprovalStatus.reason != null ? { reason: toolApprovalStatus.reason } : {},
8172
8214
  ...signature != null ? { signature } : {}
8173
8215
  });
8174
8216
  return;
@@ -8333,6 +8375,77 @@ import {
8333
8375
  import {
8334
8376
  createIdGenerator as createIdGenerator2
8335
8377
  } from "@ai-sdk/provider-utils";
8378
+
8379
+ // src/prompt/normalize-stream-provider-error.ts
8380
+ import { AISDKError as AISDKError26 } from "@ai-sdk/provider";
8381
+ import { isProviderStreamError } from "@ai-sdk/provider-utils";
8382
+ function normalizeStreamProviderError(error) {
8383
+ var _a24, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
8384
+ if (isError(error) || AISDKError26.isInstance(error) || StreamProviderError.isInstance(error)) {
8385
+ return error;
8386
+ }
8387
+ const outer = asRecord(error);
8388
+ if (outer == null) {
8389
+ return error;
8390
+ }
8391
+ const providerStreamError = isProviderStreamError(error);
8392
+ const details = providerStreamError ? outer : (_c = (_b = asRecord((_a24 = asRecord(outer.response)) == null ? void 0 : _a24.error)) != null ? _b : asRecord(outer.error)) != null ? _c : outer;
8393
+ if (typeof details.message !== "string") {
8394
+ return error;
8395
+ }
8396
+ const type = (_d = getString(details.type)) != null ? _d : getString(outer.type);
8397
+ const code = (_e = getStringOrNumber(details.code)) != null ? _e : getStringOrNumber(outer.code);
8398
+ const explicitStatusCode = (_l = (_k = (_j = (_i = (_h = (_g = (_f = getHttpStatusCode(details.statusCode)) != null ? _f : getHttpStatusCode(outer.statusCode)) != null ? _g : getHttpStatusCode(details.status_code)) != null ? _h : getHttpStatusCode(outer.status_code)) != null ? _i : getHttpStatusCode(details.status)) != null ? _j : getHttpStatusCode(outer.status)) != null ? _k : getHttpStatusCode(details.code)) != null ? _l : getHttpStatusCode(outer.code);
8399
+ const messageMetadata = inferExactMessageMetadata(details.message);
8400
+ const statusCode = explicitStatusCode != null ? explicitStatusCode : messageMetadata == null ? void 0 : messageMetadata.statusCode;
8401
+ const explicitRetryability = (_o = (_n = (_m = getBoolean(details.isRetryable)) != null ? _m : getBoolean(outer.isRetryable)) != null ? _n : getBoolean(details.is_retryable)) != null ? _o : getBoolean(outer.is_retryable);
8402
+ return new StreamProviderError({
8403
+ message: details.message,
8404
+ type,
8405
+ code,
8406
+ statusCode,
8407
+ isRetryable: (_p = explicitRetryability != null ? explicitRetryability : messageMetadata == null ? void 0 : messageMetadata.isRetryable) != null ? _p : isRetryableStatusCode2(statusCode),
8408
+ data: providerStreamError ? error.data : error
8409
+ });
8410
+ }
8411
+ function inferExactMessageMetadata(message) {
8412
+ switch (message.trim().toLowerCase()) {
8413
+ case "overloaded":
8414
+ case "overloaded error":
8415
+ case "model overloaded":
8416
+ return { statusCode: 503, isRetryable: true };
8417
+ case "internal server error":
8418
+ return { statusCode: 500, isRetryable: true };
8419
+ case "service unavailable":
8420
+ return { statusCode: 503, isRetryable: true };
8421
+ default:
8422
+ return void 0;
8423
+ }
8424
+ }
8425
+ function isRetryableStatusCode2(statusCode) {
8426
+ return statusCode != null && (statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500);
8427
+ }
8428
+ function asRecord(value) {
8429
+ return typeof value === "object" && value != null ? value : void 0;
8430
+ }
8431
+ function isError(value) {
8432
+ return value instanceof Error || Object.prototype.toString.call(value) === "[object Error]";
8433
+ }
8434
+ function getString(value) {
8435
+ return typeof value === "string" ? value : void 0;
8436
+ }
8437
+ function getStringOrNumber(value) {
8438
+ return typeof value === "string" || typeof value === "number" ? value : void 0;
8439
+ }
8440
+ function getBoolean(value) {
8441
+ return typeof value === "boolean" ? value : void 0;
8442
+ }
8443
+ function getHttpStatusCode(value) {
8444
+ const statusCode = typeof value === "string" && /^\d{3}$/.test(value) ? Number(value) : value;
8445
+ return typeof statusCode === "number" && Number.isInteger(statusCode) && statusCode >= 400 && statusCode <= 599 ? statusCode : void 0;
8446
+ }
8447
+
8448
+ // src/generate-text/stream-language-model-call.ts
8336
8449
  var originalGenerateId2 = createIdGenerator2({
8337
8450
  prefix: "aitxt",
8338
8451
  size: 24
@@ -8486,7 +8599,7 @@ function createLanguageModelV4StreamPartToLanguageModelStreamPartTransform({
8486
8599
  const timeBetweenOutputChunksMs = [];
8487
8600
  return new TransformStream({
8488
8601
  async transform(chunk, controller) {
8489
- var _a23, _b, _c;
8602
+ var _a24, _b, _c;
8490
8603
  if (isOutputChunk(chunk)) {
8491
8604
  const outputChunkTimestampMs = now2();
8492
8605
  if (timeToFirstOutputMs == null) {
@@ -8499,6 +8612,12 @@ function createLanguageModelV4StreamPartToLanguageModelStreamPartTransform({
8499
8612
  previousOutputChunkTimestampMs = outputChunkTimestampMs;
8500
8613
  }
8501
8614
  switch (chunk.type) {
8615
+ case "error":
8616
+ controller.enqueue({
8617
+ type: "error",
8618
+ error: normalizeStreamProviderError(chunk.error)
8619
+ });
8620
+ break;
8502
8621
  case "text-start":
8503
8622
  upsertTextContentPart({
8504
8623
  content: modelCallContent,
@@ -8725,7 +8844,7 @@ function createLanguageModelV4StreamPartToLanguageModelStreamPartTransform({
8725
8844
  const tool2 = getOwn(tools, chunk.toolName);
8726
8845
  controller.enqueue({
8727
8846
  ...chunk,
8728
- dynamic: (_a23 = chunk.dynamic) != null ? _a23 : (tool2 == null ? void 0 : tool2.type) === "dynamic",
8847
+ dynamic: (_a24 = chunk.dynamic) != null ? _a24 : (tool2 == null ? void 0 : tool2.type) === "dynamic",
8729
8848
  title: tool2 == null ? void 0 : tool2.title,
8730
8849
  ...(tool2 == null ? void 0 : tool2.metadata) != null ? { toolMetadata: tool2.metadata } : {}
8731
8850
  });
@@ -8919,7 +9038,7 @@ function streamText({
8919
9038
  } = {},
8920
9039
  ...settings
8921
9040
  }) {
8922
- var _a23, _b, _c, _d;
9041
+ var _a24, _b, _c, _d;
8923
9042
  const totalTimeoutMs = getTotalTimeoutMs(timeout);
8924
9043
  const stepTimeoutMs = getStepTimeoutMs(timeout);
8925
9044
  const firstChunkTimeoutMs = getFirstChunkTimeoutMs(timeout);
@@ -8993,7 +9112,7 @@ function streamText({
8993
9112
  download: download2,
8994
9113
  // assign default values to include:
8995
9114
  include: {
8996
- requestBody: (_a23 = include == null ? void 0 : include.requestBody) != null ? _a23 : false,
9115
+ requestBody: (_a24 = include == null ? void 0 : include.requestBody) != null ? _a24 : false,
8997
9116
  requestMessages: (_b = include == null ? void 0 : include.requestMessages) != null ? _b : false,
8998
9117
  rawChunks: (_d = (_c = include == null ? void 0 : include.rawChunks) != null ? _c : includeRawChunks) != null ? _d : false
8999
9118
  }
@@ -9028,7 +9147,7 @@ function createOutputTransformStream(output) {
9028
9147
  }
9029
9148
  return new TransformStream({
9030
9149
  async transform(chunk, controller) {
9031
- var _a23;
9150
+ var _a24;
9032
9151
  if (chunk.type === "finish-step" && textChunk.length > 0) {
9033
9152
  publishTextChunk({ controller });
9034
9153
  }
@@ -9055,7 +9174,7 @@ function createOutputTransformStream(output) {
9055
9174
  }
9056
9175
  text2 += chunk.text;
9057
9176
  textChunk += chunk.text;
9058
- textProviderMetadata = (_a23 = chunk.providerMetadata) != null ? _a23 : textProviderMetadata;
9177
+ textProviderMetadata = (_a24 = chunk.providerMetadata) != null ? _a24 : textProviderMetadata;
9059
9178
  if (chunk.text.length === 0 && chunk.providerMetadata != null) {
9060
9179
  controller.enqueue({ part: chunk, partialOutput: void 0 });
9061
9180
  return;
@@ -9178,7 +9297,7 @@ var DefaultStreamTextResult = class {
9178
9297
  let recordedNoOutputError;
9179
9298
  const eventProcessor = new TransformStream({
9180
9299
  async transform(chunk, controller) {
9181
- var _a23, _b, _c, _d;
9300
+ var _a24, _b, _c, _d;
9182
9301
  controller.enqueue(chunk);
9183
9302
  const { part } = chunk;
9184
9303
  await notify({
@@ -9219,7 +9338,7 @@ var DefaultStreamTextResult = class {
9219
9338
  return;
9220
9339
  }
9221
9340
  activeText.text += part.text;
9222
- activeText.providerMetadata = (_a23 = part.providerMetadata) != null ? _a23 : activeText.providerMetadata;
9341
+ activeText.providerMetadata = (_a24 = part.providerMetadata) != null ? _a24 : activeText.providerMetadata;
9223
9342
  }
9224
9343
  if (part.type === "text-end") {
9225
9344
  const activeText = activeTextContent[part.id];
@@ -9375,8 +9494,8 @@ var DefaultStreamTextResult = class {
9375
9494
  (step) => step.dynamicToolResults
9376
9495
  );
9377
9496
  const warnings = recordedSteps.flatMap((step) => {
9378
- var _a23;
9379
- return (_a23 = step.warnings) != null ? _a23 : [];
9497
+ var _a24;
9498
+ return (_a24 = step.warnings) != null ? _a24 : [];
9380
9499
  });
9381
9500
  await notify({
9382
9501
  event: {
@@ -9499,7 +9618,7 @@ var DefaultStreamTextResult = class {
9499
9618
  const self = this;
9500
9619
  const callId = generateCallId();
9501
9620
  (async () => {
9502
- var _a23;
9621
+ var _a24;
9503
9622
  const initialPrompt = await standardizePrompt({
9504
9623
  instructions,
9505
9624
  system,
@@ -9535,14 +9654,14 @@ var DefaultStreamTextResult = class {
9535
9654
  runtimeContext,
9536
9655
  toolsContext
9537
9656
  };
9538
- const streamTextTracingChannelContext = (_a23 = telemetryDispatcher.startTracingChannelContext) == null ? void 0 : _a23.call(telemetryDispatcher, {
9657
+ const streamTextTracingChannelContext = (_a24 = telemetryDispatcher.startTracingChannelContext) == null ? void 0 : _a24.call(telemetryDispatcher, {
9539
9658
  type: "streamText",
9540
9659
  event: startEvent,
9541
9660
  completion: self._totalUsage.promise.then(() => void 0)
9542
9661
  });
9543
9662
  const runInStreamTextTracingChannelContext = (execute) => {
9544
- var _a24;
9545
- return (_a24 = streamTextTracingChannelContext == null ? void 0 : streamTextTracingChannelContext.run(execute)) != null ? _a24 : execute();
9663
+ var _a25;
9664
+ return (_a25 = streamTextTracingChannelContext == null ? void 0 : streamTextTracingChannelContext.run(execute)) != null ? _a25 : execute();
9546
9665
  };
9547
9666
  const runInTracingChannelSpanInStreamText = telemetryDispatcher.runInTracingChannelSpan == null ? void 0 : (options) => runInStreamTextTracingChannelContext(
9548
9667
  () => telemetryDispatcher.runInTracingChannelSpan(options)
@@ -9699,7 +9818,7 @@ var DefaultStreamTextResult = class {
9699
9818
  currentStep,
9700
9819
  usage
9701
9820
  }) {
9702
- var _a24, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
9821
+ var _a25, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
9703
9822
  const stepTimeoutId = setAbortTimeout({
9704
9823
  abortController: stepAbortController,
9705
9824
  label: "Step",
@@ -9758,14 +9877,14 @@ var DefaultStreamTextResult = class {
9758
9877
  });
9759
9878
  try {
9760
9879
  stepFinish = new DelayedPromise();
9761
- const stepTracingChannelContext = (_a24 = telemetryDispatcher.startTracingChannelContext) == null ? void 0 : _a24.call(telemetryDispatcher, {
9880
+ const stepTracingChannelContext = (_a25 = telemetryDispatcher.startTracingChannelContext) == null ? void 0 : _a25.call(telemetryDispatcher, {
9762
9881
  type: "step",
9763
9882
  event: { callId, stepNumber: currentStep },
9764
9883
  completion: stepFinish.promise
9765
9884
  });
9766
9885
  const runInStepTracingChannelContext = (execute) => {
9767
- var _a25;
9768
- return (_a25 = stepTracingChannelContext == null ? void 0 : stepTracingChannelContext.run(execute)) != null ? _a25 : execute();
9886
+ var _a26;
9887
+ return (_a26 = stepTracingChannelContext == null ? void 0 : stepTracingChannelContext.run(execute)) != null ? _a26 : execute();
9769
9888
  };
9770
9889
  const responseMessagesFromPreviousSteps = recordedSteps.flatMap(
9771
9890
  (step) => step.response.messages
@@ -9840,9 +9959,9 @@ var DefaultStreamTextResult = class {
9840
9959
  } = await runInStepTracingChannelContext(
9841
9960
  () => retry(
9842
9961
  async () => {
9843
- var _a25, _b2;
9962
+ var _a26, _b2;
9844
9963
  return streamLanguageModelCall({
9845
- model: (_a25 = prepareStepResult == null ? void 0 : prepareStepResult.model) != null ? _a25 : model,
9964
+ model: (_a26 = prepareStepResult == null ? void 0 : prepareStepResult.model) != null ? _a26 : model,
9846
9965
  tools: stepModelTools,
9847
9966
  toolOrder: stepToolOrder,
9848
9967
  toolChoice: (_b2 = prepareStepResult == null ? void 0 : prepareStepResult.toolChoice) != null ? _b2 : toolChoice,
@@ -9870,7 +9989,7 @@ var DefaultStreamTextResult = class {
9870
9989
  telemetryDispatcher.onLanguageModelCallEnd
9871
9990
  ),
9872
9991
  onStart: async ({ promptMessages }) => {
9873
- var _a26, _b3;
9992
+ var _a27, _b3;
9874
9993
  await notify({
9875
9994
  event: {
9876
9995
  callId,
@@ -9880,7 +9999,7 @@ var DefaultStreamTextResult = class {
9880
9999
  instructions: stepInstructions,
9881
10000
  messages: stepMessages,
9882
10001
  tools,
9883
- toolChoice: (_a26 = prepareStepResult == null ? void 0 : prepareStepResult.toolChoice) != null ? _a26 : toolChoice,
10002
+ toolChoice: (_a27 = prepareStepResult == null ? void 0 : prepareStepResult.toolChoice) != null ? _a27 : toolChoice,
9884
10003
  activeTools: (_b3 = prepareStepResult == null ? void 0 : prepareStepResult.activeTools) != null ? _b3 : activeTools,
9885
10004
  toolOrder: stepToolOrder,
9886
10005
  steps: [...recordedSteps],
@@ -9978,7 +10097,7 @@ var DefaultStreamTextResult = class {
9978
10097
  streamWithToolResults.pipeThrough(
9979
10098
  new TransformStream({
9980
10099
  async transform(chunk, controller) {
9981
- var _a25, _b2, _c2, _d2, _e2, _f2, _g2;
10100
+ var _a26, _b2, _c2, _d2, _e2, _f2, _g2;
9982
10101
  if (chunk.type === "model-call-start") {
9983
10102
  warnings = chunk.warnings;
9984
10103
  return;
@@ -10021,7 +10140,7 @@ var DefaultStreamTextResult = class {
10021
10140
  if (chunk.text.length > 0 || chunk.providerMetadata != null) {
10022
10141
  controller.enqueue({
10023
10142
  ...chunk,
10024
- id: (_a25 = textPartIds.get(chunk.id)) != null ? _a25 : chunk.id
10143
+ id: (_a26 = textPartIds.get(chunk.id)) != null ? _a26 : chunk.id
10025
10144
  });
10026
10145
  }
10027
10146
  break;
@@ -10234,8 +10353,8 @@ var DefaultStreamTextResult = class {
10234
10353
  )
10235
10354
  );
10236
10355
  })().catch(async (error) => {
10237
- var _a23;
10238
- await ((_a23 = telemetryDispatcher.onError) == null ? void 0 : _a23.call(telemetryDispatcher, { callId, error }));
10356
+ var _a24;
10357
+ await ((_a24 = telemetryDispatcher.onError) == null ? void 0 : _a24.call(telemetryDispatcher, { callId, error }));
10239
10358
  self._initialResponseMessages.reject(error);
10240
10359
  markPromiseAsHandled(self._initialResponseMessages.promise);
10241
10360
  self.addStream(
@@ -10261,8 +10380,8 @@ var DefaultStreamTextResult = class {
10261
10380
  }
10262
10381
  get warnings() {
10263
10382
  return this.steps.then((steps) => steps.flatMap((step) => {
10264
- var _a23;
10265
- return (_a23 = step.warnings) != null ? _a23 : [];
10383
+ var _a24;
10384
+ return (_a24 = step.warnings) != null ? _a24 : [];
10266
10385
  }));
10267
10386
  }
10268
10387
  get providerMetadata() {
@@ -10391,19 +10510,19 @@ var DefaultStreamTextResult = class {
10391
10510
  }
10392
10511
  }
10393
10512
  async consumeStream(options) {
10394
- var _a23;
10513
+ var _a24;
10395
10514
  try {
10396
10515
  await consumeStream({
10397
10516
  stream: this.stream,
10398
10517
  onError: (error) => {
10399
- var _a24;
10518
+ var _a25;
10400
10519
  this.rejectResultPromises(error);
10401
- (_a24 = options == null ? void 0 : options.onError) == null ? void 0 : _a24.call(options, error);
10520
+ (_a25 = options == null ? void 0 : options.onError) == null ? void 0 : _a25.call(options, error);
10402
10521
  }
10403
10522
  });
10404
10523
  } catch (error) {
10405
10524
  this.rejectResultPromises(error);
10406
- (_a23 = options == null ? void 0 : options.onError) == null ? void 0 : _a23.call(options, error);
10525
+ (_a24 = options == null ? void 0 : options.onError) == null ? void 0 : _a24.call(options, error);
10407
10526
  }
10408
10527
  }
10409
10528
  get experimental_partialOutputStream() {
@@ -10423,8 +10542,8 @@ var DefaultStreamTextResult = class {
10423
10542
  );
10424
10543
  }
10425
10544
  get elementStream() {
10426
- var _a23, _b, _c;
10427
- const transform = (_a23 = this.outputSpecification) == null ? void 0 : _a23.createElementStreamTransform();
10545
+ var _a24, _b, _c;
10546
+ const transform = (_a24 = this.outputSpecification) == null ? void 0 : _a24.createElementStreamTransform();
10428
10547
  if (transform == null) {
10429
10548
  throw new UnsupportedFunctionalityError2({
10430
10549
  functionality: `element streams in ${(_c = (_b = this.outputSpecification) == null ? void 0 : _b.name) != null ? _c : "text"} mode`
@@ -10434,8 +10553,8 @@ var DefaultStreamTextResult = class {
10434
10553
  }
10435
10554
  get output() {
10436
10555
  return this.finalStep.then((step) => {
10437
- var _a23;
10438
- const output = (_a23 = this.outputSpecification) != null ? _a23 : text();
10556
+ var _a24;
10557
+ const output = (_a24 = this.outputSpecification) != null ? _a24 : text();
10439
10558
  return output.parseCompleteOutput(
10440
10559
  { text: step.text },
10441
10560
  {
@@ -10566,7 +10685,7 @@ var ToolLoopAgent = class {
10566
10685
  return this.settings.tools;
10567
10686
  }
10568
10687
  async prepareCall(options) {
10569
- var _a23, _b, _c, _d;
10688
+ var _a24, _b, _c, _d;
10570
10689
  if (this.settings.callOptionsSchema != null && options.options !== void 0) {
10571
10690
  const validatedOptions = await validateTypes3({
10572
10691
  value: options.options,
@@ -10590,7 +10709,7 @@ var ToolLoopAgent = class {
10590
10709
  } = this.settings;
10591
10710
  const baseCallArgs = {
10592
10711
  ...settingsWithoutCallbacks,
10593
- stopWhen: (_a23 = this.settings.stopWhen) != null ? _a23 : isStepCount(20),
10712
+ stopWhen: (_a24 = this.settings.stopWhen) != null ? _a24 : isStepCount(20),
10594
10713
  ...options
10595
10714
  };
10596
10715
  const preparedCallArgs = (_d = await ((_c = (_b = this.settings).prepareCall) == null ? void 0 : _c.call(
@@ -10629,9 +10748,9 @@ var ToolLoopAgent = class {
10629
10748
  * downstream by generateText/streamText and the provider.
10630
10749
  */
10631
10750
  agentHeaders(preparedCall) {
10632
- var _a23;
10751
+ var _a24;
10633
10752
  return withUserAgentSuffix3(
10634
- (_a23 = preparedCall.headers) != null ? _a23 : {},
10753
+ (_a24 = preparedCall.headers) != null ? _a24 : {},
10635
10754
  "ai-sdk-agent/tool-loop"
10636
10755
  );
10637
10756
  }
@@ -10654,7 +10773,7 @@ var ToolLoopAgent = class {
10654
10773
  onEnd = onFinish,
10655
10774
  ...options
10656
10775
  }) {
10657
- var _a23, _b, _c;
10776
+ var _a24, _b, _c;
10658
10777
  const generate = generateText;
10659
10778
  const preparedCall = await this.prepareCall({
10660
10779
  ...options,
@@ -10665,7 +10784,7 @@ var ToolLoopAgent = class {
10665
10784
  timeout: timeout != null ? timeout : preparedCall.timeout,
10666
10785
  experimental_sandbox: sandbox,
10667
10786
  onStart: mergeCallbacks(
10668
- (_a23 = this.settings.onStart) != null ? _a23 : this.settings.experimental_onStart,
10787
+ (_a24 = this.settings.onStart) != null ? _a24 : this.settings.experimental_onStart,
10669
10788
  onStart != null ? onStart : experimental_onStart
10670
10789
  ),
10671
10790
  onStepStart: mergeCallbacks(
@@ -10712,7 +10831,7 @@ var ToolLoopAgent = class {
10712
10831
  onEnd = onFinish,
10713
10832
  ...options
10714
10833
  }) {
10715
- var _a23, _b, _c;
10834
+ var _a24, _b, _c;
10716
10835
  const stream = streamText;
10717
10836
  const preparedCall = await this.prepareCall({
10718
10837
  ...options,
@@ -10724,7 +10843,7 @@ var ToolLoopAgent = class {
10724
10843
  experimental_sandbox: sandbox,
10725
10844
  experimental_transform,
10726
10845
  onStart: mergeCallbacks(
10727
- (_a23 = this.settings.onStart) != null ? _a23 : this.settings.experimental_onStart,
10846
+ (_a24 = this.settings.onStart) != null ? _a24 : this.settings.experimental_onStart,
10728
10847
  onStart != null ? onStart : experimental_onStart
10729
10848
  ),
10730
10849
  onStepStart: mergeCallbacks(
@@ -10874,7 +10993,7 @@ function readUIMessageStream({
10874
10993
  onError,
10875
10994
  terminateOnError = false
10876
10995
  }) {
10877
- var _a23;
10996
+ var _a24;
10878
10997
  let controller;
10879
10998
  let hasErrored = false;
10880
10999
  const outputStream = new ReadableStream({
@@ -10883,7 +11002,7 @@ function readUIMessageStream({
10883
11002
  }
10884
11003
  });
10885
11004
  const state = createStreamingUIMessageState({
10886
- messageId: (_a23 = message == null ? void 0 : message.id) != null ? _a23 : "",
11005
+ messageId: (_a24 = message == null ? void 0 : message.id) != null ? _a24 : "",
10887
11006
  lastMessage: message
10888
11007
  });
10889
11008
  const handleError = (error) => {
@@ -10952,7 +11071,7 @@ async function convertToModelMessages(messages, options) {
10952
11071
  modelMessages.push({
10953
11072
  role: "user",
10954
11073
  content: message.parts.map((part) => {
10955
- var _a23;
11074
+ var _a24;
10956
11075
  if (isTextUIPart(part)) {
10957
11076
  return {
10958
11077
  type: "text",
@@ -10973,7 +11092,7 @@ async function convertToModelMessages(messages, options) {
10973
11092
  };
10974
11093
  }
10975
11094
  if (isDataUIPart(part)) {
10976
- return (_a23 = options == null ? void 0 : options.convertDataPart) == null ? void 0 : _a23.call(
11095
+ return (_a24 = options == null ? void 0 : options.convertDataPart) == null ? void 0 : _a24.call(
10977
11096
  options,
10978
11097
  part
10979
11098
  );
@@ -10986,7 +11105,7 @@ async function convertToModelMessages(messages, options) {
10986
11105
  if (message.parts != null) {
10987
11106
  let block = [];
10988
11107
  async function processBlock() {
10989
- var _a23, _b, _c, _d, _e, _f, _g;
11108
+ var _a24, _b, _c, _d, _e, _f, _g;
10990
11109
  if (block.length === 0) {
10991
11110
  return;
10992
11111
  }
@@ -11035,7 +11154,7 @@ async function convertToModelMessages(messages, options) {
11035
11154
  type: "tool-call",
11036
11155
  toolCallId: part.toolCallId,
11037
11156
  toolName,
11038
- input: part.state === "output-error" ? (_a23 = part.input) != null ? _a23 : "rawInput" in part ? part.rawInput : void 0 : part.input,
11157
+ input: part.state === "output-error" ? (_a24 = part.input) != null ? _a24 : "rawInput" in part ? part.rawInput : void 0 : part.input,
11039
11158
  providerExecuted: part.providerExecuted,
11040
11159
  ...part.callProviderMetadata != null ? { providerOptions: part.callProviderMetadata } : {}
11041
11160
  });
@@ -11045,6 +11164,7 @@ async function convertToModelMessages(messages, options) {
11045
11164
  approvalId: part.approval.id,
11046
11165
  toolCallId: part.toolCallId,
11047
11166
  isAutomatic: part.approval.isAutomatic,
11167
+ ...part.approval.requestReason != null ? { reason: part.approval.requestReason } : {},
11048
11168
  ...part.approval.signature != null ? { signature: part.approval.signature } : {}
11049
11169
  });
11050
11170
  }
@@ -11086,8 +11206,8 @@ async function convertToModelMessages(messages, options) {
11086
11206
  }
11087
11207
  const toolParts = block.filter(
11088
11208
  (part) => {
11089
- var _a24;
11090
- return isToolUIPart(part) && (part.providerExecuted !== true || ((_a24 = part.approval) == null ? void 0 : _a24.approved) != null);
11209
+ var _a25;
11210
+ return isToolUIPart(part) && (part.providerExecuted !== true || ((_a25 = part.approval) == null ? void 0 : _a25.approved) != null);
11091
11211
  }
11092
11212
  );
11093
11213
  if (toolParts.length > 0) {
@@ -11302,6 +11422,7 @@ var uiMessagesSchema = lazySchema2(
11302
11422
  approval: z.object({
11303
11423
  id: z.string(),
11304
11424
  approved: z.never().optional(),
11425
+ requestReason: z.string().optional(),
11305
11426
  reason: z.never().optional(),
11306
11427
  isAutomatic: z.boolean().optional(),
11307
11428
  signature: z.string().optional()
@@ -11321,6 +11442,7 @@ var uiMessagesSchema = lazySchema2(
11321
11442
  approval: z.object({
11322
11443
  id: z.string(),
11323
11444
  approved: z.boolean(),
11445
+ requestReason: z.string().optional(),
11324
11446
  reason: z.string().optional(),
11325
11447
  isAutomatic: z.boolean().optional(),
11326
11448
  signature: z.string().optional()
@@ -11342,6 +11464,7 @@ var uiMessagesSchema = lazySchema2(
11342
11464
  approval: z.object({
11343
11465
  id: z.string(),
11344
11466
  approved: z.literal(true),
11467
+ requestReason: z.string().optional(),
11345
11468
  reason: z.string().optional(),
11346
11469
  isAutomatic: z.boolean().optional(),
11347
11470
  signature: z.string().optional()
@@ -11363,6 +11486,7 @@ var uiMessagesSchema = lazySchema2(
11363
11486
  approval: z.object({
11364
11487
  id: z.string(),
11365
11488
  approved: z.literal(true),
11489
+ requestReason: z.string().optional(),
11366
11490
  reason: z.string().optional(),
11367
11491
  isAutomatic: z.boolean().optional(),
11368
11492
  signature: z.string().optional()
@@ -11382,6 +11506,7 @@ var uiMessagesSchema = lazySchema2(
11382
11506
  approval: z.object({
11383
11507
  id: z.string(),
11384
11508
  approved: z.literal(false),
11509
+ requestReason: z.string().optional(),
11385
11510
  reason: z.string().optional(),
11386
11511
  isAutomatic: z.boolean().optional(),
11387
11512
  signature: z.string().optional()
@@ -11424,6 +11549,7 @@ var uiMessagesSchema = lazySchema2(
11424
11549
  approval: z.object({
11425
11550
  id: z.string(),
11426
11551
  approved: z.never().optional(),
11552
+ requestReason: z.string().optional(),
11427
11553
  reason: z.never().optional(),
11428
11554
  isAutomatic: z.boolean().optional(),
11429
11555
  signature: z.string().optional()
@@ -11442,6 +11568,7 @@ var uiMessagesSchema = lazySchema2(
11442
11568
  approval: z.object({
11443
11569
  id: z.string(),
11444
11570
  approved: z.boolean(),
11571
+ requestReason: z.string().optional(),
11445
11572
  reason: z.string().optional(),
11446
11573
  isAutomatic: z.boolean().optional(),
11447
11574
  signature: z.string().optional()
@@ -11462,6 +11589,7 @@ var uiMessagesSchema = lazySchema2(
11462
11589
  approval: z.object({
11463
11590
  id: z.string(),
11464
11591
  approved: z.literal(true),
11592
+ requestReason: z.string().optional(),
11465
11593
  reason: z.string().optional(),
11466
11594
  isAutomatic: z.boolean().optional(),
11467
11595
  signature: z.string().optional()
@@ -11482,6 +11610,7 @@ var uiMessagesSchema = lazySchema2(
11482
11610
  approval: z.object({
11483
11611
  id: z.string(),
11484
11612
  approved: z.literal(true),
11613
+ requestReason: z.string().optional(),
11485
11614
  reason: z.string().optional(),
11486
11615
  isAutomatic: z.boolean().optional(),
11487
11616
  signature: z.string().optional()
@@ -11500,6 +11629,7 @@ var uiMessagesSchema = lazySchema2(
11500
11629
  approval: z.object({
11501
11630
  id: z.string(),
11502
11631
  approved: z.literal(false),
11632
+ requestReason: z.string().optional(),
11503
11633
  reason: z.string().optional(),
11504
11634
  isAutomatic: z.boolean().optional(),
11505
11635
  signature: z.string().optional()
@@ -11676,7 +11806,7 @@ async function createAgentUIStream({
11676
11806
  onStepFinish,
11677
11807
  ...uiMessageStreamOptions
11678
11808
  }) {
11679
- var _a23;
11809
+ var _a24;
11680
11810
  const validatedMessages = await validateUIMessages({
11681
11811
  messages: uiMessages,
11682
11812
  // tools are compatible; the casting is required because the context param is
@@ -11695,7 +11825,7 @@ async function createAgentUIStream({
11695
11825
  experimental_transform,
11696
11826
  onStepEnd: onStepEnd != null ? onStepEnd : onStepFinish
11697
11827
  });
11698
- const originalMessages = (_a23 = uiMessageStreamOptions.originalMessages) != null ? _a23 : validatedMessages;
11828
+ const originalMessages = (_a24 = uiMessageStreamOptions.originalMessages) != null ? _a24 : validatedMessages;
11699
11829
  return createAsyncIterableStream(
11700
11830
  toUIMessageStream({
11701
11831
  ...uiMessageStreamOptions,
@@ -11751,6 +11881,7 @@ async function startTextBatch({
11751
11881
  model: modelArg,
11752
11882
  requests,
11753
11883
  providerOptions,
11884
+ webhookUrl,
11754
11885
  abortSignal,
11755
11886
  headers,
11756
11887
  timeout
@@ -11790,7 +11921,8 @@ async function startTextBatch({
11790
11921
  requests: normalizedRequests,
11791
11922
  providerOptions,
11792
11923
  abortSignal: operationAbortSignal,
11793
- headers: headersWithUserAgent
11924
+ headers: headersWithUserAgent,
11925
+ ...webhookUrl != null && { webhookUrl }
11794
11926
  });
11795
11927
  const { batchId, warnings, ...status } = result;
11796
11928
  logWarnings({
@@ -11967,7 +12099,7 @@ function convertBatchItemResult(item) {
11967
12099
  };
11968
12100
  }
11969
12101
  function convertGenerateResult(result) {
11970
- var _a23;
12102
+ var _a24;
11971
12103
  return {
11972
12104
  text: result.content.filter(
11973
12105
  (part) => part.type === "text"
@@ -11978,7 +12110,7 @@ function convertGenerateResult(result) {
11978
12110
  ...result.response != null ? {
11979
12111
  response: {
11980
12112
  id: result.response.id,
11981
- timestamp: (_a23 = result.response.timestamp) == null ? void 0 : _a23.toISOString(),
12113
+ timestamp: (_a24 = result.response.timestamp) == null ? void 0 : _a24.toISOString(),
11982
12114
  modelId: result.response.modelId
11983
12115
  }
11984
12116
  } : {},
@@ -12010,7 +12142,7 @@ async function embed({
12010
12142
  experimental_onEnd,
12011
12143
  _internal: { generateCallId = originalGenerateCallId4 } = {}
12012
12144
  }) {
12013
- var _a23;
12145
+ var _a24;
12014
12146
  const model = resolveEmbeddingModel(modelArg);
12015
12147
  const { maxRetries, retry } = prepareRetries({
12016
12148
  maxRetries: maxRetriesArg,
@@ -12026,7 +12158,7 @@ async function embed({
12026
12158
  const telemetryDispatcher = createTelemetryDispatcher({
12027
12159
  telemetry
12028
12160
  });
12029
- const runInTracingChannelSpan = (_a23 = telemetryDispatcher.runInTracingChannelSpan) != null ? _a23 : async ({ execute }) => await execute();
12161
+ const runInTracingChannelSpan = (_a24 = telemetryDispatcher.runInTracingChannelSpan) != null ? _a24 : async ({ execute }) => await execute();
12030
12162
  const startEvent = {
12031
12163
  callId,
12032
12164
  operationId: "ai.embed",
@@ -12041,14 +12173,14 @@ async function embed({
12041
12173
  type: "embed",
12042
12174
  event: startEvent,
12043
12175
  execute: async () => {
12044
- var _a24;
12176
+ var _a25;
12045
12177
  await notify({
12046
12178
  event: startEvent,
12047
12179
  callbacks: [resolvedOnStart, telemetryDispatcher.onStart]
12048
12180
  });
12049
12181
  try {
12050
12182
  const { embedding, usage, warnings, response, providerMetadata } = await retry(async () => {
12051
- var _a25, _b;
12183
+ var _a26, _b;
12052
12184
  const embedCallId = generateCallId();
12053
12185
  await notify({
12054
12186
  event: {
@@ -12068,7 +12200,7 @@ async function embed({
12068
12200
  providerOptions
12069
12201
  });
12070
12202
  const embedding2 = modelResponse.embeddings[0];
12071
- const usage2 = (_a25 = modelResponse.usage) != null ? _a25 : { tokens: NaN };
12203
+ const usage2 = (_a26 = modelResponse.usage) != null ? _a26 : { tokens: NaN };
12072
12204
  await notify({
12073
12205
  event: {
12074
12206
  callId,
@@ -12119,7 +12251,7 @@ async function embed({
12119
12251
  response
12120
12252
  });
12121
12253
  } catch (error) {
12122
- await ((_a24 = telemetryDispatcher.onError) == null ? void 0 : _a24.call(telemetryDispatcher, { callId, error }));
12254
+ await ((_a25 = telemetryDispatcher.onError) == null ? void 0 : _a25.call(telemetryDispatcher, { callId, error }));
12123
12255
  throw error;
12124
12256
  }
12125
12257
  }
@@ -12142,6 +12274,12 @@ import {
12142
12274
  withUserAgentSuffix as withUserAgentSuffix6
12143
12275
  } from "@ai-sdk/provider-utils";
12144
12276
 
12277
+ // src/model/get-embedding-model-max-input-bytes-per-call.ts
12278
+ import { EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL } from "@ai-sdk/provider-utils";
12279
+ function getEmbeddingModelMaxInputBytesPerCall(model) {
12280
+ return model[EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL];
12281
+ }
12282
+
12145
12283
  // src/util/split-array.ts
12146
12284
  function splitArray(array3, chunkSize) {
12147
12285
  if (chunkSize <= 0) {
@@ -12175,7 +12313,7 @@ async function embedMany({
12175
12313
  experimental_onEnd,
12176
12314
  _internal: { generateCallId = originalGenerateCallId5 } = {}
12177
12315
  }) {
12178
- var _a23;
12316
+ var _a24;
12179
12317
  const model = resolveEmbeddingModel(modelArg);
12180
12318
  const { maxRetries, retry } = prepareRetries({
12181
12319
  maxRetries: maxRetriesArg,
@@ -12191,7 +12329,7 @@ async function embedMany({
12191
12329
  const telemetryDispatcher = createTelemetryDispatcher({
12192
12330
  telemetry
12193
12331
  });
12194
- const runInTracingChannelSpan = (_a23 = telemetryDispatcher.runInTracingChannelSpan) != null ? _a23 : async ({ execute }) => await execute();
12332
+ const runInTracingChannelSpan = (_a24 = telemetryDispatcher.runInTracingChannelSpan) != null ? _a24 : async ({ execute }) => await execute();
12195
12333
  const startEvent = {
12196
12334
  callId,
12197
12335
  operationId: "ai.embedMany",
@@ -12206,18 +12344,26 @@ async function embedMany({
12206
12344
  type: "embedMany",
12207
12345
  event: startEvent,
12208
12346
  execute: async () => {
12209
- var _a24, _b;
12347
+ var _a25, _b;
12210
12348
  await notify({
12211
12349
  event: startEvent,
12212
12350
  callbacks: [resolvedOnStart, telemetryDispatcher.onStart]
12213
12351
  });
12214
12352
  try {
12215
- const [maxEmbeddingsPerCall, supportsParallelCalls] = await Promise.all(
12216
- [model.maxEmbeddingsPerCall, model.supportsParallelCalls]
12217
- );
12218
- if (maxEmbeddingsPerCall == null || maxEmbeddingsPerCall === Infinity) {
12353
+ const [
12354
+ maxEmbeddingsPerCall,
12355
+ maxInputBytesPerCall,
12356
+ supportsParallelCalls
12357
+ ] = await Promise.all([
12358
+ model.maxEmbeddingsPerCall,
12359
+ getEmbeddingModelMaxInputBytesPerCall(model),
12360
+ model.supportsParallelCalls
12361
+ ]);
12362
+ const hasEmbeddingLimit = maxEmbeddingsPerCall != null && maxEmbeddingsPerCall !== Infinity;
12363
+ const hasInputByteLimit = maxInputBytesPerCall != null && maxInputBytesPerCall !== Infinity;
12364
+ if (!hasEmbeddingLimit && !hasInputByteLimit) {
12219
12365
  const { embeddings: embeddings2, usage, warnings: warnings2, response, providerMetadata: providerMetadata2 } = await retry(async () => {
12220
- var _a25, _b2;
12366
+ var _a26, _b2;
12221
12367
  const embedCallId = generateCallId();
12222
12368
  await notify({
12223
12369
  event: {
@@ -12237,7 +12383,7 @@ async function embedMany({
12237
12383
  providerOptions
12238
12384
  });
12239
12385
  const embeddings3 = modelResponse.embeddings;
12240
- const usage2 = (_a25 = modelResponse.usage) != null ? _a25 : { tokens: NaN };
12386
+ const usage2 = (_a26 = modelResponse.usage) != null ? _a26 : { tokens: NaN };
12241
12387
  await notify({
12242
12388
  event: {
12243
12389
  callId,
@@ -12288,7 +12434,11 @@ async function embedMany({
12288
12434
  responses: [response]
12289
12435
  });
12290
12436
  }
12291
- const valueChunks = splitArray(values, maxEmbeddingsPerCall);
12437
+ const valueChunks = splitByEmbeddingLimits({
12438
+ values,
12439
+ maxEmbeddingsPerCall: hasEmbeddingLimit ? maxEmbeddingsPerCall : Infinity,
12440
+ maxInputBytesPerCall: hasInputByteLimit ? maxInputBytesPerCall : Infinity
12441
+ });
12292
12442
  const embeddings = [];
12293
12443
  const warnings = [];
12294
12444
  const responses = [];
@@ -12302,7 +12452,7 @@ async function embedMany({
12302
12452
  const results = await Promise.all(
12303
12453
  parallelChunk.map((chunk) => {
12304
12454
  return retry(async () => {
12305
- var _a25, _b2;
12455
+ var _a26, _b2;
12306
12456
  const embedCallId = generateCallId();
12307
12457
  await notify({
12308
12458
  event: {
@@ -12322,7 +12472,7 @@ async function embedMany({
12322
12472
  providerOptions
12323
12473
  });
12324
12474
  const chunkEmbeddings = modelResponse.embeddings;
12325
- const usage = (_a25 = modelResponse.usage) != null ? _a25 : { tokens: NaN };
12475
+ const usage = (_a26 = modelResponse.usage) != null ? _a26 : { tokens: NaN };
12326
12476
  await notify({
12327
12477
  event: {
12328
12478
  callId,
@@ -12359,7 +12509,7 @@ async function embedMany({
12359
12509
  result.providerMetadata
12360
12510
  )) {
12361
12511
  providerMetadata[providerName] = {
12362
- ...(_a24 = providerMetadata[providerName]) != null ? _a24 : {},
12512
+ ...(_a25 = providerMetadata[providerName]) != null ? _a25 : {},
12363
12513
  ...metadata
12364
12514
  };
12365
12515
  }
@@ -12402,6 +12552,37 @@ async function embedMany({
12402
12552
  }
12403
12553
  });
12404
12554
  }
12555
+ var textEncoder = new TextEncoder();
12556
+ function splitByEmbeddingLimits({
12557
+ values,
12558
+ maxEmbeddingsPerCall,
12559
+ maxInputBytesPerCall
12560
+ }) {
12561
+ if (maxEmbeddingsPerCall <= 0) {
12562
+ throw new Error("maxEmbeddingsPerCall must be greater than 0");
12563
+ }
12564
+ if (maxInputBytesPerCall <= 0) {
12565
+ throw new Error("maxInputBytesPerCall must be greater than 0");
12566
+ }
12567
+ if (values.length === 0) {
12568
+ return [];
12569
+ }
12570
+ const chunks = [];
12571
+ let currentChunk = [];
12572
+ let currentInputBytes = 0;
12573
+ for (const value of values) {
12574
+ const inputBytes = textEncoder.encode(value).length;
12575
+ if (currentChunk.length > 0 && (currentChunk.length >= maxEmbeddingsPerCall || currentInputBytes + inputBytes > maxInputBytesPerCall)) {
12576
+ chunks.push(currentChunk);
12577
+ currentChunk = [];
12578
+ currentInputBytes = 0;
12579
+ }
12580
+ currentChunk.push(value);
12581
+ currentInputBytes += inputBytes;
12582
+ }
12583
+ chunks.push(currentChunk);
12584
+ return chunks;
12585
+ }
12405
12586
  var DefaultEmbedManyResult = class {
12406
12587
  constructor(options) {
12407
12588
  this.values = options.values;
@@ -12469,7 +12650,7 @@ async function generateImage({
12469
12650
  abortSignal,
12470
12651
  headers
12471
12652
  }) {
12472
- var _a23, _b;
12653
+ var _a24, _b;
12473
12654
  const model = resolveImageModel(modelArg);
12474
12655
  const headersWithUserAgent = withUserAgentSuffix7(
12475
12656
  headers != null ? headers : {},
@@ -12479,7 +12660,7 @@ async function generateImage({
12479
12660
  maxRetries: maxRetriesArg,
12480
12661
  abortSignal
12481
12662
  });
12482
- const maxImagesPerCallWithDefault = (_a23 = maxImagesPerCall != null ? maxImagesPerCall : await invokeModelMaxImagesPerCall(model)) != null ? _a23 : 1;
12663
+ const maxImagesPerCallWithDefault = (_a24 = maxImagesPerCall != null ? maxImagesPerCall : await invokeModelMaxImagesPerCall(model)) != null ? _a24 : 1;
12483
12664
  const callCount = Math.ceil(n / maxImagesPerCallWithDefault);
12484
12665
  const callImageCounts = Array.from({ length: callCount }, (_, i) => {
12485
12666
  if (i < callCount - 1) {
@@ -12520,13 +12701,13 @@ async function generateImage({
12520
12701
  images.push(
12521
12702
  ...result.images.map(
12522
12703
  (image) => {
12523
- var _a24;
12704
+ var _a25;
12524
12705
  return new DefaultGeneratedFile({
12525
12706
  data: image,
12526
- mediaType: (_a24 = detectMediaType2({
12707
+ mediaType: (_a25 = detectMediaType2({
12527
12708
  data: image,
12528
12709
  topLevelType: "image"
12529
- })) != null ? _a24 : "image/png"
12710
+ })) != null ? _a25 : "image/png"
12530
12711
  });
12531
12712
  }
12532
12713
  )
@@ -12749,7 +12930,7 @@ var arrayOutputStrategy = (schema) => {
12749
12930
  isFirstDelta,
12750
12931
  isFinalDelta
12751
12932
  }) {
12752
- var _a23;
12933
+ var _a24;
12753
12934
  if (!isJSONObject(value) || !isJSONArray(value.elements)) {
12754
12935
  return {
12755
12936
  success: false,
@@ -12772,7 +12953,7 @@ var arrayOutputStrategy = (schema) => {
12772
12953
  }
12773
12954
  resultArray.push(result.value);
12774
12955
  }
12775
- const publishedElementCount = (_a23 = latestObject == null ? void 0 : latestObject.length) != null ? _a23 : 0;
12956
+ const publishedElementCount = (_a24 = latestObject == null ? void 0 : latestObject.length) != null ? _a24 : 0;
12776
12957
  let textDelta = "";
12777
12958
  if (isFirstDelta) {
12778
12959
  textDelta += "[";
@@ -13116,7 +13297,7 @@ function validateObjectGenerationInput({
13116
13297
  // src/generate-object/generate-object.ts
13117
13298
  var originalGenerateId4 = createIdGenerator6({ prefix: "aiobj", size: 24 });
13118
13299
  async function generateObject(options) {
13119
- var _a23, _b, _c, _d, _e, _f, _g, _h, _i, _j;
13300
+ var _a24, _b, _c, _d, _e, _f, _g, _h, _i, _j;
13120
13301
  const {
13121
13302
  model: modelArg,
13122
13303
  output = "object",
@@ -13251,7 +13432,7 @@ async function generateObject(options) {
13251
13432
  })
13252
13433
  );
13253
13434
  const responseData = {
13254
- id: (_b = (_a23 = generateResult.response) == null ? void 0 : _a23.id) != null ? _b : generateId4(),
13435
+ id: (_b = (_a24 = generateResult.response) == null ? void 0 : _a24.id) != null ? _b : generateId4(),
13255
13436
  timestamp: (_d = (_c = generateResult.response) == null ? void 0 : _c.timestamp) != null ? _d : currentDate(),
13256
13437
  modelId: (_f = (_e = generateResult.response) == null ? void 0 : _e.modelId) != null ? _f : model.modelId,
13257
13438
  headers: (_g = generateResult.response) == null ? void 0 : _g.headers,
@@ -13349,9 +13530,9 @@ var DefaultGenerateObjectResult = class {
13349
13530
  this.reasoning = options.reasoning;
13350
13531
  }
13351
13532
  toJsonResponse(init) {
13352
- var _a23;
13533
+ var _a24;
13353
13534
  return new Response(JSON.stringify(this.object), {
13354
- status: (_a23 = init == null ? void 0 : init.status) != null ? _a23 : 200,
13535
+ status: (_a24 = init == null ? void 0 : init.status) != null ? _a24 : 200,
13355
13536
  headers: prepareHeaders(init == null ? void 0 : init.headers, {
13356
13537
  "content-type": "application/json; charset=utf-8"
13357
13538
  })
@@ -13485,8 +13666,8 @@ function simulateReadableStream({
13485
13666
  chunkDelayInMs = 0,
13486
13667
  _internal
13487
13668
  }) {
13488
- var _a23;
13489
- const delay = (_a23 = _internal == null ? void 0 : _internal.delay) != null ? _a23 : delayFunction;
13669
+ var _a24;
13670
+ const delay = (_a24 = _internal == null ? void 0 : _internal.delay) != null ? _a24 : delayFunction;
13490
13671
  let index = 0;
13491
13672
  return new ReadableStream({
13492
13673
  async pull(controller) {
@@ -13756,7 +13937,7 @@ var DefaultStreamObjectResult = class {
13756
13937
  const transformedStream = stream.pipeThrough(new TransformStream(transformer)).pipeThrough(
13757
13938
  new TransformStream({
13758
13939
  async transform(chunk, controller) {
13759
- var _a23, _b, _c;
13940
+ var _a24, _b, _c;
13760
13941
  if (typeof chunk === "object" && chunk.type === "stream-start") {
13761
13942
  warnings = chunk.warnings;
13762
13943
  return;
@@ -13800,7 +13981,7 @@ var DefaultStreamObjectResult = class {
13800
13981
  switch (chunk.type) {
13801
13982
  case "response-metadata": {
13802
13983
  fullResponse = {
13803
- id: (_a23 = chunk.id) != null ? _a23 : fullResponse.id,
13984
+ id: (_a24 = chunk.id) != null ? _a24 : fullResponse.id,
13804
13985
  timestamp: (_b = chunk.timestamp) != null ? _b : fullResponse.timestamp,
13805
13986
  modelId: (_c = chunk.modelId) != null ? _c : fullResponse.modelId
13806
13987
  };
@@ -13936,9 +14117,9 @@ var DefaultStreamObjectResult = class {
13936
14117
  }
13937
14118
  });
13938
14119
  })().catch(async (error) => {
13939
- var _a23;
14120
+ var _a24;
13940
14121
  self.rejectResultPromises(error);
13941
- await ((_a23 = telemetryDispatcher.onError) == null ? void 0 : _a23.call(telemetryDispatcher, { callId, error }));
14122
+ await ((_a24 = telemetryDispatcher.onError) == null ? void 0 : _a24.call(telemetryDispatcher, { callId, error }));
13942
14123
  stitchableStream.addStream(
13943
14124
  new ReadableStream({
13944
14125
  start(controller) {
@@ -14103,7 +14284,7 @@ async function generateSpeech({
14103
14284
  abortSignal,
14104
14285
  headers
14105
14286
  }) {
14106
- var _a23;
14287
+ var _a24;
14107
14288
  const resolvedModel = resolveSpeechModel(model);
14108
14289
  if (!resolvedModel) {
14109
14290
  throw new Error("Model could not be resolved");
@@ -14140,10 +14321,10 @@ async function generateSpeech({
14140
14321
  return new DefaultSpeechResult({
14141
14322
  audio: new DefaultGeneratedAudioFile({
14142
14323
  data: result.audio,
14143
- mediaType: (_a23 = detectMediaType3({
14324
+ mediaType: (_a24 = detectMediaType3({
14144
14325
  data: result.audio,
14145
14326
  topLevelType: "audio"
14146
- })) != null ? _a23 : "audio/mp3"
14327
+ })) != null ? _a24 : "audio/mp3"
14147
14328
  }),
14148
14329
  warnings: result.warnings,
14149
14330
  responses: [result.response],
@@ -14152,11 +14333,11 @@ async function generateSpeech({
14152
14333
  }
14153
14334
  var DefaultSpeechResult = class {
14154
14335
  constructor(options) {
14155
- var _a23;
14336
+ var _a24;
14156
14337
  this.audio = options.audio;
14157
14338
  this.warnings = options.warnings;
14158
14339
  this.responses = options.responses;
14159
- this.providerMetadata = (_a23 = options.providerMetadata) != null ? _a23 : {};
14340
+ this.providerMetadata = (_a24 = options.providerMetadata) != null ? _a24 : {};
14160
14341
  }
14161
14342
  };
14162
14343
 
@@ -14370,14 +14551,14 @@ function tagDescription(description) {
14370
14551
  }
14371
14552
  async function fingerprintTools(tools) {
14372
14553
  const entries = await Promise.all(
14373
- Object.keys(tools).map(async (name23) => {
14374
- const tool2 = tools[name23];
14554
+ Object.keys(tools).map(async (name24) => {
14555
+ const tool2 = tools[name24];
14375
14556
  const digest = await hashCanonical({
14376
14557
  description: tagDescription(tool2.description),
14377
14558
  inputSchema: await asSchema6(tool2.inputSchema).jsonSchema,
14378
14559
  title: tool2.title
14379
14560
  });
14380
- return [name23, digest];
14561
+ return [name24, digest];
14381
14562
  })
14382
14563
  );
14383
14564
  return Object.fromEntries(entries);
@@ -14386,16 +14567,16 @@ function detectToolDrift(current, baseline) {
14386
14567
  const added = [];
14387
14568
  const removed = [];
14388
14569
  const changed = [];
14389
- for (const name23 of Object.keys(current)) {
14390
- if (!Object.hasOwn(baseline, name23)) {
14391
- added.push(name23);
14392
- } else if (current[name23] !== baseline[name23]) {
14393
- changed.push(name23);
14570
+ for (const name24 of Object.keys(current)) {
14571
+ if (!Object.hasOwn(baseline, name24)) {
14572
+ added.push(name24);
14573
+ } else if (current[name24] !== baseline[name24]) {
14574
+ changed.push(name24);
14394
14575
  }
14395
14576
  }
14396
- for (const name23 of Object.keys(baseline)) {
14397
- if (!Object.hasOwn(current, name23)) {
14398
- removed.push(name23);
14577
+ for (const name24 of Object.keys(baseline)) {
14578
+ if (!Object.hasOwn(current, name24)) {
14579
+ removed.push(name24);
14399
14580
  }
14400
14581
  }
14401
14582
  return { added, removed, changed };
@@ -14431,7 +14612,7 @@ async function experimental_generateVideo({
14431
14612
  poll,
14432
14613
  webhook
14433
14614
  }) {
14434
- var _a23;
14615
+ var _a24;
14435
14616
  const model = resolveVideoModel(modelArg);
14436
14617
  const headersWithUserAgent = withUserAgentSuffix10(
14437
14618
  headers != null ? headers : {},
@@ -14448,7 +14629,7 @@ async function experimental_generateVideo({
14448
14629
  effectiveInputReferences,
14449
14630
  warnings
14450
14631
  } = normalizeVideoCallInputs({ promptArg, frameImages, inputReferences });
14451
- const maxVideosPerCallWithDefault = (_a23 = maxVideosPerCall != null ? maxVideosPerCall : await invokeModelMaxVideosPerCall(model)) != null ? _a23 : 1;
14632
+ const maxVideosPerCallWithDefault = (_a24 = maxVideosPerCall != null ? maxVideosPerCall : await invokeModelMaxVideosPerCall(model)) != null ? _a24 : 1;
14452
14633
  const hasStartStatus = model.doStart != null && model.doStatus != null;
14453
14634
  const useStartStatus = hasStartStatus && (poll != null || webhook != null || model.doGenerate == null);
14454
14635
  if (model.doGenerate == null && !hasStartStatus) {
@@ -14587,7 +14768,7 @@ async function executeStartStatusFlow({
14587
14768
  webhook: webhookFactory,
14588
14769
  retry
14589
14770
  }) {
14590
- var _a23, _b, _c, _d;
14771
+ var _a24, _b, _c, _d;
14591
14772
  const earlyWarnings = [];
14592
14773
  let webhookUrl;
14593
14774
  let webhookReceived;
@@ -14606,7 +14787,7 @@ async function executeStartStatusFlow({
14606
14787
  });
14607
14788
  }
14608
14789
  }
14609
- const callerIdempotencyKey = Object.entries((_a23 = callOptions.headers) != null ? _a23 : {}).find(
14790
+ const callerIdempotencyKey = Object.entries((_a24 = callOptions.headers) != null ? _a24 : {}).find(
14610
14791
  ([key, value]) => key.toLowerCase() === "idempotency-key" && value !== void 0
14611
14792
  );
14612
14793
  const startCallOptions = {
@@ -14736,7 +14917,7 @@ function normalizeVideoCallInputs({
14736
14917
  frameImages,
14737
14918
  inputReferences
14738
14919
  }) {
14739
- var _a23;
14920
+ var _a24;
14740
14921
  const { prompt, image } = normalizePrompt2(promptArg);
14741
14922
  const normalizedFrameImages = frameImages == null ? void 0 : frameImages.flatMap((frame) => {
14742
14923
  const normalizedImage = normalizeImageData(frame.image);
@@ -14754,9 +14935,9 @@ function normalizeVideoCallInputs({
14754
14935
  message: "inputReferences were ignored because frameImages were provided; frameImages and inputReferences cannot be combined."
14755
14936
  });
14756
14937
  }
14757
- const firstFrameImage = (_a23 = normalizedFrameImages == null ? void 0 : normalizedFrameImages.find(
14938
+ const firstFrameImage = (_a24 = normalizedFrameImages == null ? void 0 : normalizedFrameImages.find(
14758
14939
  (frame) => frame.frameType === "first_frame"
14759
- )) == null ? void 0 : _a23.image;
14940
+ )) == null ? void 0 : _a24.image;
14760
14941
  if (image != null && firstFrameImage != null) {
14761
14942
  warnings.push({
14762
14943
  type: "other",
@@ -15002,8 +15183,8 @@ function stripMarkdownCodeFenceSuffix(text2) {
15002
15183
  return text2.replace(/\n?```\s*$/, "").trimEnd();
15003
15184
  }
15004
15185
  function extractJsonMiddleware(options) {
15005
- var _a23;
15006
- const transform = (_a23 = options == null ? void 0 : options.transform) != null ? _a23 : defaultTransform;
15186
+ var _a24;
15187
+ const transform = (_a24 = options == null ? void 0 : options.transform) != null ? _a24 : defaultTransform;
15007
15188
  const hasCustomTransform = (options == null ? void 0 : options.transform) !== void 0;
15008
15189
  return {
15009
15190
  specificationVersion: "v4",
@@ -15379,13 +15560,13 @@ function addToolInputExamplesMiddleware({
15379
15560
  return {
15380
15561
  specificationVersion: "v4",
15381
15562
  transformParams: async ({ params }) => {
15382
- var _a23;
15383
- if (!((_a23 = params.tools) == null ? void 0 : _a23.length)) {
15563
+ var _a24;
15564
+ if (!((_a24 = params.tools) == null ? void 0 : _a24.length)) {
15384
15565
  return params;
15385
15566
  }
15386
15567
  const transformedTools = params.tools.map((tool2) => {
15387
- var _a24;
15388
- if (tool2.type !== "function" || !((_a24 = tool2.inputExamples) == null ? void 0 : _a24.length)) {
15568
+ var _a25;
15569
+ if (tool2.type !== "function" || !((_a25 = tool2.inputExamples) == null ? void 0 : _a25.length)) {
15389
15570
  return tool2;
15390
15571
  }
15391
15572
  const formattedExamples = tool2.inputExamples.map((example, index) => format(example, index)).join("\n");
@@ -15434,7 +15615,7 @@ var doWrap = ({
15434
15615
  modelId,
15435
15616
  providerId
15436
15617
  }) => {
15437
- var _a23, _b, _c;
15618
+ var _a24, _b, _c;
15438
15619
  async function doTransform({
15439
15620
  params,
15440
15621
  type
@@ -15443,7 +15624,7 @@ var doWrap = ({
15443
15624
  }
15444
15625
  return {
15445
15626
  specificationVersion: "v4",
15446
- provider: (_a23 = providerId != null ? providerId : overrideProvider == null ? void 0 : overrideProvider({ model })) != null ? _a23 : model.provider,
15627
+ provider: (_a24 = providerId != null ? providerId : overrideProvider == null ? void 0 : overrideProvider({ model })) != null ? _a24 : model.provider,
15447
15628
  modelId: (_b = modelId != null ? modelId : overrideModelId == null ? void 0 : overrideModelId({ model })) != null ? _b : model.modelId,
15448
15629
  supportedUrls: (_c = overrideSupportedUrls == null ? void 0 : overrideSupportedUrls({ model })) != null ? _c : model.supportedUrls,
15449
15630
  async doGenerate(params) {
@@ -15472,7 +15653,10 @@ var doWrap = ({
15472
15653
  };
15473
15654
 
15474
15655
  // src/middleware/wrap-embedding-model.ts
15475
- import { asArray as asArray9 } from "@ai-sdk/provider-utils";
15656
+ import {
15657
+ asArray as asArray9,
15658
+ EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL as EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL2
15659
+ } from "@ai-sdk/provider-utils";
15476
15660
  var wrapEmbeddingModel = ({
15477
15661
  model: inputModel,
15478
15662
  middleware: middlewareArg,
@@ -15497,7 +15681,7 @@ var doWrap2 = ({
15497
15681
  modelId,
15498
15682
  providerId
15499
15683
  }) => {
15500
- var _a23, _b, _c, _d;
15684
+ var _a24, _b, _c, _d;
15501
15685
  async function doTransform({
15502
15686
  params
15503
15687
  }) {
@@ -15505,9 +15689,10 @@ var doWrap2 = ({
15505
15689
  }
15506
15690
  return {
15507
15691
  specificationVersion: "v4",
15508
- provider: (_a23 = providerId != null ? providerId : overrideProvider == null ? void 0 : overrideProvider({ model })) != null ? _a23 : model.provider,
15692
+ provider: (_a24 = providerId != null ? providerId : overrideProvider == null ? void 0 : overrideProvider({ model })) != null ? _a24 : model.provider,
15509
15693
  modelId: (_b = modelId != null ? modelId : overrideModelId == null ? void 0 : overrideModelId({ model })) != null ? _b : model.modelId,
15510
15694
  maxEmbeddingsPerCall: (_c = overrideMaxEmbeddingsPerCall == null ? void 0 : overrideMaxEmbeddingsPerCall({ model })) != null ? _c : model.maxEmbeddingsPerCall,
15695
+ [EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL2]: getEmbeddingModelMaxInputBytesPerCall(model),
15511
15696
  supportsParallelCalls: (_d = overrideSupportsParallelCalls == null ? void 0 : overrideSupportsParallelCalls({ model })) != null ? _d : model.supportsParallelCalls,
15512
15697
  async doEmbed(params) {
15513
15698
  const transformedParams = await doTransform({ params });
@@ -15546,11 +15731,11 @@ var doWrap3 = ({
15546
15731
  modelId,
15547
15732
  providerId
15548
15733
  }) => {
15549
- var _a23, _b, _c;
15734
+ var _a24, _b, _c;
15550
15735
  async function doTransform({ params }) {
15551
15736
  return transformParams ? await transformParams({ params, model }) : params;
15552
15737
  }
15553
- const maxImagesPerCallRaw = (_a23 = overrideMaxImagesPerCall == null ? void 0 : overrideMaxImagesPerCall({ model })) != null ? _a23 : model.maxImagesPerCall;
15738
+ const maxImagesPerCallRaw = (_a24 = overrideMaxImagesPerCall == null ? void 0 : overrideMaxImagesPerCall({ model })) != null ? _a24 : model.maxImagesPerCall;
15554
15739
  const maxImagesPerCall = maxImagesPerCallRaw instanceof Function ? maxImagesPerCallRaw.bind(model) : maxImagesPerCallRaw;
15555
15740
  return {
15556
15741
  specificationVersion: "v4",
@@ -15652,7 +15837,7 @@ async function getRealtimeToolDefinitions({
15652
15837
  toolsContext = {}
15653
15838
  }) {
15654
15839
  const definitions = [];
15655
- for (const [name23, tool2] of Object.entries(tools)) {
15840
+ for (const [name24, tool2] of Object.entries(tools)) {
15656
15841
  const toolType = tool2.type;
15657
15842
  switch (toolType) {
15658
15843
  case void 0:
@@ -15660,12 +15845,12 @@ async function getRealtimeToolDefinitions({
15660
15845
  case "dynamic": {
15661
15846
  const description = resolveRealtimeToolDescription({
15662
15847
  tool: tool2,
15663
- toolName: name23,
15848
+ toolName: name24,
15664
15849
  toolsContext
15665
15850
  });
15666
15851
  definitions.push({
15667
15852
  type: "function",
15668
- name: name23,
15853
+ name: name24,
15669
15854
  description,
15670
15855
  parameters: await asSchema7(tool2.inputSchema).jsonSchema
15671
15856
  });
@@ -15739,8 +15924,8 @@ var BrowserRealtimeAudio = class {
15739
15924
  this.onCapturingChange(true);
15740
15925
  }
15741
15926
  stopCapture() {
15742
- var _a23, _b, _c, _d;
15743
- (_a23 = this.captureProcessor) == null ? void 0 : _a23.disconnect();
15927
+ var _a24, _b, _c, _d;
15928
+ (_a24 = this.captureProcessor) == null ? void 0 : _a24.disconnect();
15744
15929
  (_b = this.captureSource) == null ? void 0 : _b.disconnect();
15745
15930
  void ((_c = this.captureContext) == null ? void 0 : _c.close());
15746
15931
  (_d = this.captureStream) == null ? void 0 : _d.getTracks().forEach((track) => track.stop());
@@ -15776,16 +15961,16 @@ var BrowserRealtimeAudio = class {
15776
15961
  return (ctx.currentTime - this.playbackStartTime) * 1e3;
15777
15962
  }
15778
15963
  dispose() {
15779
- var _a23;
15964
+ var _a24;
15780
15965
  this.stopCapture();
15781
15966
  this.stopPlayback();
15782
- void ((_a23 = this.playbackContext) == null ? void 0 : _a23.close());
15967
+ void ((_a24 = this.playbackContext) == null ? void 0 : _a24.close());
15783
15968
  this.playbackContext = null;
15784
15969
  }
15785
15970
  setPlaying(isPlaying) {
15786
- var _a23, _b;
15971
+ var _a24, _b;
15787
15972
  if (isPlaying && !this.isPlaying) {
15788
- this.playbackStartTime = (_b = (_a23 = this.playbackContext) == null ? void 0 : _a23.currentTime) != null ? _b : 0;
15973
+ this.playbackStartTime = (_b = (_a24 = this.playbackContext) == null ? void 0 : _a24.currentTime) != null ? _b : 0;
15789
15974
  }
15790
15975
  if (this.isPlaying !== isPlaying) {
15791
15976
  this.isPlaying = isPlaying;
@@ -15838,8 +16023,8 @@ var BrowserRealtimeTransport = class {
15838
16023
  url,
15839
16024
  onOpen
15840
16025
  }) {
15841
- var _a23;
15842
- (_a23 = this.ws) == null ? void 0 : _a23.close();
16026
+ var _a24;
16027
+ (_a24 = this.ws) == null ? void 0 : _a24.close();
15843
16028
  this.ws = null;
15844
16029
  const wsConfig = this.model.getWebSocketConfig({ token, url });
15845
16030
  const ws = new WebSocket(wsConfig.url, wsConfig.protocols);
@@ -15863,8 +16048,8 @@ var BrowserRealtimeTransport = class {
15863
16048
  };
15864
16049
  }
15865
16050
  disconnect() {
15866
- var _a23;
15867
- (_a23 = this.ws) == null ? void 0 : _a23.close();
16051
+ var _a24;
16052
+ (_a24 = this.ws) == null ? void 0 : _a24.close();
15868
16053
  this.ws = null;
15869
16054
  }
15870
16055
  sendEvent(event) {
@@ -15880,8 +16065,8 @@ var BrowserRealtimeTransport = class {
15880
16065
  });
15881
16066
  }
15882
16067
  sendRaw(data) {
15883
- var _a23;
15884
- if (((_a23 = this.ws) == null ? void 0 : _a23.readyState) === WebSocket.OPEN) {
16068
+ var _a24;
16069
+ if (((_a24 = this.ws) == null ? void 0 : _a24.readyState) === WebSocket.OPEN) {
15885
16070
  if (typeof data === "string" || data instanceof ArrayBuffer || ArrayBuffer.isView(data) || data instanceof Blob) {
15886
16071
  this.ws.send(data);
15887
16072
  } else {
@@ -15974,7 +16159,7 @@ var RealtimeEventReducer = class {
15974
16159
  };
15975
16160
  }
15976
16161
  async reduceServerEvent(state, event) {
15977
- var _a23;
16162
+ var _a24;
15978
16163
  let nextState = this.pushEvent(state, event);
15979
16164
  const effects = [];
15980
16165
  switch (event.type) {
@@ -16041,7 +16226,7 @@ var RealtimeEventReducer = class {
16041
16226
  const { state: updatedState, messageId } = this.getOrCreateAssistantMessage(nextState);
16042
16227
  nextState = updatedState;
16043
16228
  this.toolCallIdToMessageId.set(event.callId, messageId);
16044
- const acc = (_a23 = this.toolArgAccumulators.get(event.callId)) != null ? _a23 : "";
16229
+ const acc = (_a24 = this.toolArgAccumulators.get(event.callId)) != null ? _a24 : "";
16045
16230
  this.toolArgAccumulators.set(event.callId, acc + event.delta);
16046
16231
  nextState = this.ensureToolPart(nextState, messageId, event.callId);
16047
16232
  break;
@@ -16115,7 +16300,7 @@ var RealtimeEventReducer = class {
16115
16300
  };
16116
16301
  }
16117
16302
  addInputTranscriptionMessage(state, itemId, transcript) {
16118
- var _a23;
16303
+ var _a24;
16119
16304
  const messageId = `user-${itemId}`;
16120
16305
  const existingMessage = state.messages.find(
16121
16306
  (message) => message.id === messageId
@@ -16138,7 +16323,7 @@ var RealtimeEventReducer = class {
16138
16323
  };
16139
16324
  }
16140
16325
  const insertIndex = Math.min(
16141
- (_a23 = this.inputAudioMessageInsertIndex.get(itemId)) != null ? _a23 : state.messages.length,
16326
+ (_a24 = this.inputAudioMessageInsertIndex.get(itemId)) != null ? _a24 : state.messages.length,
16142
16327
  state.messages.length
16143
16328
  );
16144
16329
  const messages = [...state.messages];
@@ -16159,9 +16344,9 @@ var RealtimeEventReducer = class {
16159
16344
  };
16160
16345
  }
16161
16346
  appendTextDelta(state, itemId, delta) {
16162
- var _a23;
16347
+ var _a24;
16163
16348
  const { state: stateWithMessage, messageId } = this.getOrCreateAssistantMessage(state);
16164
- const acc = (_a23 = this.textAccumulators.get(itemId)) != null ? _a23 : "";
16349
+ const acc = (_a24 = this.textAccumulators.get(itemId)) != null ? _a24 : "";
16165
16350
  const text2 = acc + delta;
16166
16351
  this.textAccumulators.set(itemId, text2);
16167
16352
  const location = this.itemIdToPartLocation.get(itemId);
@@ -16191,8 +16376,8 @@ var RealtimeEventReducer = class {
16191
16376
  };
16192
16377
  }
16193
16378
  finalizeText(state, itemId, finalText) {
16194
- var _a23;
16195
- const text2 = (_a23 = finalText != null ? finalText : this.textAccumulators.get(itemId)) != null ? _a23 : "";
16379
+ var _a24;
16380
+ const text2 = (_a24 = finalText != null ? finalText : this.textAccumulators.get(itemId)) != null ? _a24 : "";
16196
16381
  this.textAccumulators.delete(itemId);
16197
16382
  const location = this.itemIdToPartLocation.get(itemId);
16198
16383
  if (location == null)
@@ -16232,7 +16417,7 @@ var RealtimeEventReducer = class {
16232
16417
  })
16233
16418
  };
16234
16419
  }
16235
- markToolInputAvailable(state, messageId, callId, name23, input) {
16420
+ markToolInputAvailable(state, messageId, callId, name24, input) {
16236
16421
  return {
16237
16422
  ...state,
16238
16423
  messages: state.messages.map((message) => {
@@ -16248,7 +16433,7 @@ var RealtimeEventReducer = class {
16248
16433
  return part;
16249
16434
  return {
16250
16435
  ...toolPart,
16251
- toolName: name23,
16436
+ toolName: name24,
16252
16437
  state: "input-available",
16253
16438
  input
16254
16439
  };
@@ -16310,11 +16495,11 @@ var AbstractRealtimeSession = class {
16310
16495
  this.toolCallsInResponse = /* @__PURE__ */ new Set();
16311
16496
  this.submittedToolOutputs = /* @__PURE__ */ new Set();
16312
16497
  this.responseToolCallsClosed = false;
16313
- var _a23, _b, _c, _d, _e, _f, _g, _h;
16498
+ var _a24, _b, _c, _d, _e, _f, _g, _h;
16314
16499
  this.model = options.model;
16315
16500
  this.api = options.api;
16316
16501
  this.sessionConfig = options.sessionConfig;
16317
- this.maxEvents = (_a23 = options.maxEvents) != null ? _a23 : 500;
16502
+ this.maxEvents = (_a24 = options.maxEvents) != null ? _a24 : 500;
16318
16503
  this.reducer = new RealtimeEventReducer(this.maxEvents);
16319
16504
  this.onToolCall = options.onToolCall;
16320
16505
  this.onEvent = options.onEvent;
@@ -16326,9 +16511,9 @@ var AbstractRealtimeSession = class {
16326
16511
  model: this.model,
16327
16512
  onServerEvent: (event) => this.handleServerEvent(event),
16328
16513
  onError: (error) => {
16329
- var _a24;
16514
+ var _a25;
16330
16515
  this.applyState(this.reducer.setStatus(this.state, "error"));
16331
- (_a24 = this.onError) == null ? void 0 : _a24.call(this, error);
16516
+ (_a25 = this.onError) == null ? void 0 : _a25.call(this, error);
16332
16517
  },
16333
16518
  onClose: () => {
16334
16519
  this.applyState(this.reducer.setStatus(this.state, "disconnected"));
@@ -16348,7 +16533,7 @@ var AbstractRealtimeSession = class {
16348
16533
  }
16349
16534
  // ── Connection ─────────────────────────────────────────────────────
16350
16535
  async connect() {
16351
- var _a23;
16536
+ var _a24;
16352
16537
  this.applyState(this.reducer.setStatus(this.state, "connecting"));
16353
16538
  try {
16354
16539
  const response = await fetch(this.api.token, {
@@ -16378,7 +16563,7 @@ var AbstractRealtimeSession = class {
16378
16563
  });
16379
16564
  } catch (error) {
16380
16565
  this.applyState(this.reducer.setStatus(this.state, "error"));
16381
- (_a23 = this.onError) == null ? void 0 : _a23.call(
16566
+ (_a24 = this.onError) == null ? void 0 : _a24.call(
16382
16567
  this,
16383
16568
  error instanceof Error ? error : new Error(`Connection failed: ${String(error)}`)
16384
16569
  );
@@ -16504,18 +16689,18 @@ var AbstractRealtimeSession = class {
16504
16689
  }
16505
16690
  }
16506
16691
  async executeToolCall({
16507
- name: name23,
16692
+ name: name24,
16508
16693
  args,
16509
16694
  callId
16510
16695
  }) {
16511
- var _a23, _b;
16696
+ var _a24, _b;
16512
16697
  if (this.onToolCall == null) {
16513
- (_a23 = this.onError) == null ? void 0 : _a23.call(this, new Error(`No handler provided for tool "${name23}"`));
16698
+ (_a24 = this.onError) == null ? void 0 : _a24.call(this, new Error(`No handler provided for tool "${name24}"`));
16514
16699
  return;
16515
16700
  }
16516
16701
  try {
16517
16702
  const result = await this.onToolCall({
16518
- toolCall: { toolCallId: callId, toolName: name23, args }
16703
+ toolCall: { toolCallId: callId, toolName: name24, args }
16519
16704
  });
16520
16705
  if (result !== void 0) {
16521
16706
  this.addToolOutput(callId, result);
@@ -16528,10 +16713,10 @@ var AbstractRealtimeSession = class {
16528
16713
  }
16529
16714
  }
16530
16715
  async handleServerEvent(event) {
16531
- var _a23;
16716
+ var _a24;
16532
16717
  const result = await this.reducer.reduceServerEvent(this.state, event);
16533
16718
  this.applyState(result.state);
16534
- (_a23 = this.onEvent) == null ? void 0 : _a23.call(this, event);
16719
+ (_a24 = this.onEvent) == null ? void 0 : _a24.call(this, event);
16535
16720
  for (const effect of result.effects) {
16536
16721
  this.handleReducerEffect(effect);
16537
16722
  }
@@ -16541,7 +16726,7 @@ var AbstractRealtimeSession = class {
16541
16726
  }
16542
16727
  }
16543
16728
  handleReducerEffect(effect) {
16544
- var _a23;
16729
+ var _a24;
16545
16730
  switch (effect.type) {
16546
16731
  case "play-audio": {
16547
16732
  this.currentResponseItemId = effect.itemId;
@@ -16573,7 +16758,7 @@ var AbstractRealtimeSession = class {
16573
16758
  break;
16574
16759
  }
16575
16760
  case "error": {
16576
- (_a23 = this.onError) == null ? void 0 : _a23.call(this, effect.error);
16761
+ (_a24 = this.onError) == null ? void 0 : _a24.call(this, effect.error);
16577
16762
  break;
16578
16763
  }
16579
16764
  }
@@ -16686,11 +16871,11 @@ function customProvider({
16686
16871
  }
16687
16872
 
16688
16873
  // src/registry/no-such-provider-error.ts
16689
- import { AISDKError as AISDKError25, NoSuchModelError as NoSuchModelError3 } from "@ai-sdk/provider";
16690
- var name22 = "AI_NoSuchProviderError";
16691
- var marker22 = `vercel.ai.error.${name22}`;
16692
- var symbol22 = Symbol.for(marker22);
16693
- var _a22;
16874
+ import { AISDKError as AISDKError27, NoSuchModelError as NoSuchModelError3 } from "@ai-sdk/provider";
16875
+ var name23 = "AI_NoSuchProviderError";
16876
+ var marker23 = `vercel.ai.error.${name23}`;
16877
+ var symbol23 = Symbol.for(marker23);
16878
+ var _a23;
16694
16879
  var NoSuchProviderError = class extends NoSuchModelError3 {
16695
16880
  constructor({
16696
16881
  modelId,
@@ -16699,16 +16884,16 @@ var NoSuchProviderError = class extends NoSuchModelError3 {
16699
16884
  availableProviders,
16700
16885
  message = `No such provider: ${providerId} (available providers: ${availableProviders.join()})`
16701
16886
  }) {
16702
- super({ errorName: name22, modelId, modelType, message });
16703
- this[_a22] = true;
16887
+ super({ errorName: name23, modelId, modelType, message });
16888
+ this[_a23] = true;
16704
16889
  this.providerId = providerId;
16705
16890
  this.availableProviders = availableProviders;
16706
16891
  }
16707
16892
  static isInstance(error) {
16708
- return AISDKError25.hasMarker(error, marker22);
16893
+ return AISDKError27.hasMarker(error, marker23);
16709
16894
  }
16710
16895
  };
16711
- _a22 = symbol22;
16896
+ _a23 = symbol23;
16712
16897
 
16713
16898
  // src/registry/provider-registry.ts
16714
16899
  import {
@@ -16745,9 +16930,9 @@ var DefaultProviderRegistry = class {
16745
16930
  id,
16746
16931
  provider
16747
16932
  }) {
16748
- var _a23;
16933
+ var _a24;
16749
16934
  const providerV4 = asProviderV4(provider);
16750
- const videoModel = (_a23 = provider.videoModel) == null ? void 0 : _a23.bind(provider);
16935
+ const videoModel = (_a24 = provider.videoModel) == null ? void 0 : _a24.bind(provider);
16751
16936
  this.providers[id] = videoModel == null ? providerV4 : Object.assign(Object.create(Object.getPrototypeOf(providerV4)), {
16752
16937
  ...providerV4,
16753
16938
  videoModel: (modelId) => asVideoModelV4(videoModel(modelId))
@@ -16777,10 +16962,10 @@ var DefaultProviderRegistry = class {
16777
16962
  return [id.slice(0, index), id.slice(index + this.separator.length)];
16778
16963
  }
16779
16964
  languageModel(id) {
16780
- var _a23, _b;
16965
+ var _a24, _b;
16781
16966
  const [providerId, modelId] = this.splitId(id, "languageModel");
16782
- let model = (_b = (_a23 = this.getProvider(providerId, "languageModel")).languageModel) == null ? void 0 : _b.call(
16783
- _a23,
16967
+ let model = (_b = (_a24 = this.getProvider(providerId, "languageModel")).languageModel) == null ? void 0 : _b.call(
16968
+ _a24,
16784
16969
  modelId
16785
16970
  );
16786
16971
  if (model == null) {
@@ -16795,10 +16980,10 @@ var DefaultProviderRegistry = class {
16795
16980
  return model;
16796
16981
  }
16797
16982
  embeddingModel(id) {
16798
- var _a23;
16983
+ var _a24;
16799
16984
  const [providerId, modelId] = this.splitId(id, "embeddingModel");
16800
16985
  const provider = this.getProvider(providerId, "embeddingModel");
16801
- const model = (_a23 = provider.embeddingModel) == null ? void 0 : _a23.call(provider, modelId);
16986
+ const model = (_a24 = provider.embeddingModel) == null ? void 0 : _a24.call(provider, modelId);
16802
16987
  if (model == null) {
16803
16988
  throw new NoSuchModelError4({
16804
16989
  modelId: id,
@@ -16808,10 +16993,10 @@ var DefaultProviderRegistry = class {
16808
16993
  return model;
16809
16994
  }
16810
16995
  imageModel(id) {
16811
- var _a23;
16996
+ var _a24;
16812
16997
  const [providerId, modelId] = this.splitId(id, "imageModel");
16813
16998
  const provider = this.getProvider(providerId, "imageModel");
16814
- let model = (_a23 = provider.imageModel) == null ? void 0 : _a23.call(provider, modelId);
16999
+ let model = (_a24 = provider.imageModel) == null ? void 0 : _a24.call(provider, modelId);
16815
17000
  if (model == null) {
16816
17001
  throw new NoSuchModelError4({ modelId: id, modelType: "imageModel" });
16817
17002
  }
@@ -16824,10 +17009,10 @@ var DefaultProviderRegistry = class {
16824
17009
  return model;
16825
17010
  }
16826
17011
  transcriptionModel(id) {
16827
- var _a23;
17012
+ var _a24;
16828
17013
  const [providerId, modelId] = this.splitId(id, "transcriptionModel");
16829
17014
  const provider = this.getProvider(providerId, "transcriptionModel");
16830
- const model = (_a23 = provider.transcriptionModel) == null ? void 0 : _a23.call(provider, modelId);
17015
+ const model = (_a24 = provider.transcriptionModel) == null ? void 0 : _a24.call(provider, modelId);
16831
17016
  if (model == null) {
16832
17017
  throw new NoSuchModelError4({
16833
17018
  modelId: id,
@@ -16837,39 +17022,39 @@ var DefaultProviderRegistry = class {
16837
17022
  return model;
16838
17023
  }
16839
17024
  speechModel(id) {
16840
- var _a23;
17025
+ var _a24;
16841
17026
  const [providerId, modelId] = this.splitId(id, "speechModel");
16842
17027
  const provider = this.getProvider(providerId, "speechModel");
16843
- const model = (_a23 = provider.speechModel) == null ? void 0 : _a23.call(provider, modelId);
17028
+ const model = (_a24 = provider.speechModel) == null ? void 0 : _a24.call(provider, modelId);
16844
17029
  if (model == null) {
16845
17030
  throw new NoSuchModelError4({ modelId: id, modelType: "speechModel" });
16846
17031
  }
16847
17032
  return model;
16848
17033
  }
16849
17034
  rerankingModel(id) {
16850
- var _a23;
17035
+ var _a24;
16851
17036
  const [providerId, modelId] = this.splitId(id, "rerankingModel");
16852
17037
  const provider = this.getProvider(providerId, "rerankingModel");
16853
- const model = (_a23 = provider.rerankingModel) == null ? void 0 : _a23.call(provider, modelId);
17038
+ const model = (_a24 = provider.rerankingModel) == null ? void 0 : _a24.call(provider, modelId);
16854
17039
  if (model == null) {
16855
17040
  throw new NoSuchModelError4({ modelId: id, modelType: "rerankingModel" });
16856
17041
  }
16857
17042
  return model;
16858
17043
  }
16859
17044
  videoModel(id) {
16860
- var _a23;
17045
+ var _a24;
16861
17046
  const [providerId, modelId] = this.splitId(id, "videoModel");
16862
17047
  const provider = this.getProvider(providerId, "videoModel");
16863
- const model = (_a23 = provider.videoModel) == null ? void 0 : _a23.call(provider, modelId);
17048
+ const model = (_a24 = provider.videoModel) == null ? void 0 : _a24.call(provider, modelId);
16864
17049
  if (model == null) {
16865
17050
  throw new NoSuchModelError4({ modelId: id, modelType: "videoModel" });
16866
17051
  }
16867
17052
  return asVideoModelV4(model);
16868
17053
  }
16869
17054
  files(id) {
16870
- var _a23;
17055
+ var _a24;
16871
17056
  const provider = this.getProvider(id, "languageModel");
16872
- const files = (_a23 = provider.files) == null ? void 0 : _a23.call(provider);
17057
+ const files = (_a24 = provider.files) == null ? void 0 : _a24.call(provider);
16873
17058
  if (files == null) {
16874
17059
  throw new Error(
16875
17060
  `The provider "${id}" does not support file uploads. Make sure it exposes a files() method.`
@@ -16878,9 +17063,9 @@ var DefaultProviderRegistry = class {
16878
17063
  return files;
16879
17064
  }
16880
17065
  skills(id) {
16881
- var _a23;
17066
+ var _a24;
16882
17067
  const provider = this.getProvider(id, "languageModel");
16883
- const skills = (_a23 = provider.skills) == null ? void 0 : _a23.call(provider);
17068
+ const skills = (_a24 = provider.skills) == null ? void 0 : _a24.call(provider);
16884
17069
  if (skills == null) {
16885
17070
  throw new Error(
16886
17071
  `The provider "${id}" does not support skills. Make sure it exposes a skills() method.`
@@ -16915,7 +17100,7 @@ async function rerank({
16915
17100
  experimental_onEnd,
16916
17101
  _internal: { generateCallId = originalGenerateCallId6 } = {}
16917
17102
  }) {
16918
- var _a23;
17103
+ var _a24;
16919
17104
  const model = resolveRerankingModel(modelArg);
16920
17105
  const callId = generateCallId();
16921
17106
  const resolvedOnStart = onStart != null ? onStart : experimental_onStart;
@@ -16923,7 +17108,7 @@ async function rerank({
16923
17108
  const telemetryDispatcher = createTelemetryDispatcher({
16924
17109
  telemetry
16925
17110
  });
16926
- const runInTracingChannelSpan = (_a23 = telemetryDispatcher.runInTracingChannelSpan) != null ? _a23 : async ({ execute }) => await execute();
17111
+ const runInTracingChannelSpan = (_a24 = telemetryDispatcher.runInTracingChannelSpan) != null ? _a24 : async ({ execute }) => await execute();
16927
17112
  if (documents.length === 0) {
16928
17113
  await notify({
16929
17114
  event: {
@@ -16989,7 +17174,7 @@ async function rerank({
16989
17174
  type: "rerank",
16990
17175
  event: startEvent,
16991
17176
  execute: async () => {
16992
- var _a24, _b, _c, _d, _e;
17177
+ var _a25, _b, _c, _d, _e;
16993
17178
  await notify({
16994
17179
  event: startEvent,
16995
17180
  callbacks: [resolvedOnStart, telemetryDispatcher.onStart]
@@ -17060,7 +17245,7 @@ async function rerank({
17060
17245
  providerMetadata,
17061
17246
  response: {
17062
17247
  id: response == null ? void 0 : response.id,
17063
- timestamp: (_a24 = response == null ? void 0 : response.timestamp) != null ? _a24 : /* @__PURE__ */ new Date(),
17248
+ timestamp: (_a25 = response == null ? void 0 : response.timestamp) != null ? _a25 : /* @__PURE__ */ new Date(),
17064
17249
  modelId: (_b = response == null ? void 0 : response.modelId) != null ? _b : model.modelId,
17065
17250
  headers: response == null ? void 0 : response.headers,
17066
17251
  body: response == null ? void 0 : response.body
@@ -17133,16 +17318,16 @@ async function transcribe({
17133
17318
  const audioData = audio instanceof URL ? (await downloadFn({ url: audio, abortSignal })).data : convertDataContentToUint8Array(audio);
17134
17319
  const result = await retry(
17135
17320
  () => {
17136
- var _a23;
17321
+ var _a24;
17137
17322
  return resolvedModel.doGenerate({
17138
17323
  audio: audioData,
17139
17324
  abortSignal,
17140
17325
  headers: headersWithUserAgent,
17141
17326
  providerOptions,
17142
- mediaType: (_a23 = detectMediaType5({
17327
+ mediaType: (_a24 = detectMediaType5({
17143
17328
  data: audioData,
17144
17329
  topLevelType: "audio"
17145
- })) != null ? _a23 : "audio/wav"
17330
+ })) != null ? _a24 : "audio/wav"
17146
17331
  });
17147
17332
  }
17148
17333
  );
@@ -17166,14 +17351,14 @@ async function transcribe({
17166
17351
  }
17167
17352
  var DefaultTranscriptionResult = class {
17168
17353
  constructor(options) {
17169
- var _a23;
17354
+ var _a24;
17170
17355
  this.text = options.text;
17171
17356
  this.segments = options.segments;
17172
17357
  this.language = options.language;
17173
17358
  this.durationInSeconds = options.durationInSeconds;
17174
17359
  this.warnings = options.warnings;
17175
17360
  this.responses = options.responses;
17176
- this.providerMetadata = (_a23 = options.providerMetadata) != null ? _a23 : {};
17361
+ this.providerMetadata = (_a24 = options.providerMetadata) != null ? _a24 : {};
17177
17362
  }
17178
17363
  };
17179
17364
 
@@ -17195,12 +17380,12 @@ function streamTranscribe({
17195
17380
  includeRawChunks,
17196
17381
  _internal: { currentDate = () => /* @__PURE__ */ new Date() } = {}
17197
17382
  }) {
17198
- var _a23;
17383
+ var _a24;
17199
17384
  const resolvedModel = resolveTranscriptionModel(model);
17200
17385
  if (!resolvedModel) {
17201
17386
  throw new Error("Model could not be resolved");
17202
17387
  }
17203
- const doStream = (_a23 = resolvedModel.doStream) == null ? void 0 : _a23.bind(resolvedModel);
17388
+ const doStream = (_a24 = resolvedModel.doStream) == null ? void 0 : _a24.bind(resolvedModel);
17204
17389
  if (doStream == null) {
17205
17390
  throw new UnsupportedFunctionalityError5({
17206
17391
  functionality: "streaming transcription",
@@ -17247,7 +17432,7 @@ function streamTranscribe({
17247
17432
  const pipeAbortController = new AbortController();
17248
17433
  const transformer = {
17249
17434
  transform(value, controller) {
17250
- var _a24, _b, _c, _d;
17435
+ var _a25, _b, _c, _d;
17251
17436
  switch (value.type) {
17252
17437
  case "stream-start": {
17253
17438
  resolveWarnings(value.warnings);
@@ -17255,7 +17440,7 @@ function streamTranscribe({
17255
17440
  }
17256
17441
  case "response-metadata": {
17257
17442
  response = {
17258
- timestamp: (_a24 = value.timestamp) != null ? _a24 : currentResponseMetadata().timestamp,
17443
+ timestamp: (_a25 = value.timestamp) != null ? _a25 : currentResponseMetadata().timestamp,
17259
17444
  modelId: (_b = value.modelId) != null ? _b : currentResponseMetadata().modelId,
17260
17445
  headers: (_c = value.headers) != null ? _c : response == null ? void 0 : response.headers
17261
17446
  };
@@ -17303,7 +17488,7 @@ function streamTranscribe({
17303
17488
  };
17304
17489
  const transform = new TransformStream(transformer);
17305
17490
  void (async () => {
17306
- var _a24, _b, _c, _d, _e;
17491
+ var _a25, _b, _c, _d, _e;
17307
17492
  const result = await doStream({
17308
17493
  audio,
17309
17494
  inputAudioFormat,
@@ -17314,7 +17499,7 @@ function streamTranscribe({
17314
17499
  includeRawChunks
17315
17500
  });
17316
17501
  response = {
17317
- timestamp: (_b = (_a24 = result.response) == null ? void 0 : _a24.timestamp) != null ? _b : startedAt,
17502
+ timestamp: (_b = (_a25 = result.response) == null ? void 0 : _a25.timestamp) != null ? _b : startedAt,
17318
17503
  modelId: (_d = (_c = result.response) == null ? void 0 : _c.modelId) != null ? _d : resolvedModel.modelId,
17319
17504
  headers: (_e = result.response) == null ? void 0 : _e.headers
17320
17505
  };
@@ -17450,7 +17635,7 @@ function streamTranslate({
17450
17635
  let hasAudioOutput = false;
17451
17636
  const transformer = {
17452
17637
  transform(value, controller) {
17453
- var _a23, _b, _c, _d;
17638
+ var _a24, _b, _c, _d;
17454
17639
  switch (value.type) {
17455
17640
  case "stream-start": {
17456
17641
  resolveWarnings(value.warnings);
@@ -17458,7 +17643,7 @@ function streamTranslate({
17458
17643
  }
17459
17644
  case "response-metadata": {
17460
17645
  response = {
17461
- timestamp: (_a23 = value.timestamp) != null ? _a23 : currentResponseMetadata().timestamp,
17646
+ timestamp: (_a24 = value.timestamp) != null ? _a24 : currentResponseMetadata().timestamp,
17462
17647
  modelId: (_b = value.modelId) != null ? _b : currentResponseMetadata().modelId,
17463
17648
  headers: (_c = value.headers) != null ? _c : response == null ? void 0 : response.headers
17464
17649
  };
@@ -17517,7 +17702,7 @@ function streamTranslate({
17517
17702
  };
17518
17703
  const transform = new TransformStream(transformer);
17519
17704
  void (async () => {
17520
- var _a23, _b, _c, _d, _e;
17705
+ var _a24, _b, _c, _d, _e;
17521
17706
  const result = await doStream({
17522
17707
  audio,
17523
17708
  inputAudioFormat,
@@ -17531,7 +17716,7 @@ function streamTranslate({
17531
17716
  includeRawChunks
17532
17717
  });
17533
17718
  response = {
17534
- timestamp: (_b = (_a23 = result.response) == null ? void 0 : _a23.timestamp) != null ? _b : startedAt,
17719
+ timestamp: (_b = (_a24 = result.response) == null ? void 0 : _a24.timestamp) != null ? _b : startedAt,
17535
17720
  modelId: (_d = (_c = result.response) == null ? void 0 : _c.modelId) != null ? _d : resolvedModel.modelId,
17536
17721
  headers: (_e = result.response) == null ? void 0 : _e.headers
17537
17722
  };
@@ -17642,7 +17827,7 @@ async function callCompletionApi({
17642
17827
  onError,
17643
17828
  fetch: fetch2 = getOriginalFetch()
17644
17829
  }) {
17645
- var _a23;
17830
+ var _a24;
17646
17831
  try {
17647
17832
  setLoading(true);
17648
17833
  setError(void 0);
@@ -17670,7 +17855,7 @@ async function callCompletionApi({
17670
17855
  });
17671
17856
  if (!response.ok) {
17672
17857
  throw new Error(
17673
- (_a23 = await response.text()) != null ? _a23 : "Failed to fetch the chat response."
17858
+ (_a24 = await response.text()) != null ? _a24 : "Failed to fetch the chat response."
17674
17859
  );
17675
17860
  }
17676
17861
  if (!response.body) {
@@ -17756,12 +17941,12 @@ async function convertFileListToFileUIParts(files) {
17756
17941
  }
17757
17942
  return Promise.all(
17758
17943
  Array.from(files).map(async (file) => {
17759
- const { name: name23, type } = file;
17944
+ const { name: name24, type } = file;
17760
17945
  const dataUrl = await new Promise((resolve3, reject) => {
17761
17946
  const reader = new FileReader();
17762
17947
  reader.onload = (readerEvent) => {
17763
- var _a23;
17764
- resolve3((_a23 = readerEvent.target) == null ? void 0 : _a23.result);
17948
+ var _a24;
17949
+ resolve3((_a24 = readerEvent.target) == null ? void 0 : _a24.result);
17765
17950
  };
17766
17951
  reader.onerror = (error) => reject(error);
17767
17952
  reader.readAsDataURL(file);
@@ -17769,7 +17954,7 @@ async function convertFileListToFileUIParts(files) {
17769
17954
  return {
17770
17955
  type: "file",
17771
17956
  mediaType: type,
17772
- filename: name23,
17957
+ filename: name24,
17773
17958
  url: dataUrl
17774
17959
  };
17775
17960
  })
@@ -17806,7 +17991,7 @@ var HttpChatTransport = class {
17806
17991
  abortSignal,
17807
17992
  ...options
17808
17993
  }) {
17809
- var _a23, _b, _c, _d, _e;
17994
+ var _a24, _b, _c, _d, _e;
17810
17995
  const resolvedBody = await resolve2(this.body);
17811
17996
  const resolvedHeaders = await resolve2(this.headers);
17812
17997
  const resolvedCredentials = await resolve2(this.credentials);
@@ -17814,7 +17999,7 @@ var HttpChatTransport = class {
17814
17999
  ...normalizeHeaders(resolvedHeaders),
17815
18000
  ...normalizeHeaders(options.headers)
17816
18001
  };
17817
- const preparedRequest = await ((_a23 = this.prepareSendMessagesRequest) == null ? void 0 : _a23.call(this, {
18002
+ const preparedRequest = await ((_a24 = this.prepareSendMessagesRequest) == null ? void 0 : _a24.call(this, {
17818
18003
  api: this.api,
17819
18004
  id: options.chatId,
17820
18005
  messages: options.messages,
@@ -17858,7 +18043,7 @@ var HttpChatTransport = class {
17858
18043
  return this.processResponseStream(response.body);
17859
18044
  }
17860
18045
  async reconnectToStream(options) {
17861
- var _a23, _b, _c, _d, _e;
18046
+ var _a24, _b, _c, _d, _e;
17862
18047
  const resolvedBody = await resolve2(this.body);
17863
18048
  const resolvedHeaders = await resolve2(this.headers);
17864
18049
  const resolvedCredentials = await resolve2(this.credentials);
@@ -17866,7 +18051,7 @@ var HttpChatTransport = class {
17866
18051
  ...normalizeHeaders(resolvedHeaders),
17867
18052
  ...normalizeHeaders(options.headers)
17868
18053
  };
17869
- const preparedRequest = await ((_a23 = this.prepareReconnectToStreamRequest) == null ? void 0 : _a23.call(this, {
18054
+ const preparedRequest = await ((_a24 = this.prepareReconnectToStreamRequest) == null ? void 0 : _a24.call(this, {
17870
18055
  api: this.api,
17871
18056
  id: options.chatId,
17872
18057
  body: { ...resolvedBody, ...options.body },
@@ -17947,11 +18132,11 @@ var AbstractChat = class {
17947
18132
  * If a messageId is provided, the message will be replaced.
17948
18133
  */
17949
18134
  this.sendMessage = async (message, options) => {
17950
- var _a23, _b, _c, _d;
18135
+ var _a24, _b, _c, _d;
17951
18136
  if (message == null) {
17952
18137
  await this.makeRequest({
17953
18138
  trigger: "submit-message",
17954
- messageId: (_a23 = this.lastMessage) == null ? void 0 : _a23.id,
18139
+ messageId: (_a24 = this.lastMessage) == null ? void 0 : _a24.id,
17955
18140
  ...options
17956
18141
  });
17957
18142
  return;
@@ -18071,11 +18256,11 @@ var AbstractChat = class {
18071
18256
  }
18072
18257
  if (this.status !== "streaming" && this.status !== "submitted" && this.sendAutomaticallyWhen) {
18073
18258
  this.shouldSendAutomatically().then((shouldSend) => {
18074
- var _a23;
18259
+ var _a24;
18075
18260
  if (shouldSend) {
18076
18261
  this.makeRequest({
18077
18262
  trigger: "submit-message",
18078
- messageId: (_a23 = this.lastMessage) == null ? void 0 : _a23.id,
18263
+ messageId: (_a24 = this.lastMessage) == null ? void 0 : _a24.id,
18079
18264
  ...options
18080
18265
  });
18081
18266
  }
@@ -18101,11 +18286,11 @@ var AbstractChat = class {
18101
18286
  }
18102
18287
  if (this.status !== "streaming" && this.status !== "submitted" && this.sendAutomaticallyWhen) {
18103
18288
  this.shouldSendAutomatically().then((shouldSend) => {
18104
- var _a23;
18289
+ var _a24;
18105
18290
  if (shouldSend) {
18106
18291
  this.makeRequest({
18107
18292
  trigger: "submit-message",
18108
- messageId: (_a23 = this.lastMessage) == null ? void 0 : _a23.id,
18293
+ messageId: (_a24 = this.lastMessage) == null ? void 0 : _a24.id,
18109
18294
  ...options
18110
18295
  });
18111
18296
  }
@@ -18118,11 +18303,11 @@ var AbstractChat = class {
18118
18303
  * Abort the current request immediately, keep the generated tokens if any.
18119
18304
  */
18120
18305
  this.stop = async () => {
18121
- var _a23, _b;
18306
+ var _a24, _b;
18122
18307
  for (const controller of this.pendingMessagePreparations) {
18123
18308
  controller.abort();
18124
18309
  }
18125
- (_a23 = this.activeResumeRequest) == null ? void 0 : _a23.abortController.abort();
18310
+ (_a24 = this.activeResumeRequest) == null ? void 0 : _a24.abortController.abort();
18126
18311
  (_b = this.activeResponse) == null ? void 0 : _b.abortController.abort();
18127
18312
  };
18128
18313
  this.id = id;
@@ -18187,11 +18372,11 @@ var AbstractChat = class {
18187
18372
  body,
18188
18373
  messageId
18189
18374
  }) {
18190
- var _a23, _b, _c;
18375
+ var _a24, _b, _c;
18191
18376
  const abortController = new AbortController();
18192
18377
  const activeResumeRequest = trigger === "resume-stream" ? { abortController } : void 0;
18193
18378
  if (activeResumeRequest) {
18194
- (_a23 = this.activeResumeRequest) == null ? void 0 : _a23.abortController.abort();
18379
+ (_a24 = this.activeResumeRequest) == null ? void 0 : _a24.abortController.abort();
18195
18380
  this.activeResumeRequest = activeResumeRequest;
18196
18381
  }
18197
18382
  const isCurrentRequest = () => activeResumeRequest == null || this.activeResumeRequest === activeResumeRequest;
@@ -18248,7 +18433,7 @@ var AbstractChat = class {
18248
18433
  const lastMessage = this.lastMessage;
18249
18434
  let isAbort = false;
18250
18435
  let isDisconnect = false;
18251
- let isError = false;
18436
+ let isError2 = false;
18252
18437
  let activeResponse;
18253
18438
  try {
18254
18439
  const response = {
@@ -18287,14 +18472,14 @@ var AbstractChat = class {
18287
18472
  return job({
18288
18473
  state: response.state,
18289
18474
  write: ({ updateStatus = true } = {}) => {
18290
- var _a24;
18475
+ var _a25;
18291
18476
  if (response.abortController.signal.aborted) {
18292
18477
  return;
18293
18478
  }
18294
18479
  if (updateStatus) {
18295
18480
  this.setStatus({ status: "streaming" });
18296
18481
  }
18297
- const replaceLastMessage = response.state.message.id === ((_a24 = this.lastMessage) == null ? void 0 : _a24.id);
18482
+ const replaceLastMessage = response.state.message.id === ((_a25 = this.lastMessage) == null ? void 0 : _a25.id);
18298
18483
  if (replaceLastMessage) {
18299
18484
  this.state.replaceMessage(
18300
18485
  this.state.messages.length - 1,
@@ -18344,7 +18529,7 @@ var AbstractChat = class {
18344
18529
  if (!isCurrentRequest()) {
18345
18530
  return null;
18346
18531
  }
18347
- isError = true;
18532
+ isError2 = true;
18348
18533
  if (err instanceof TypeError && (err.message.toLowerCase().includes("fetch") || err.message.toLowerCase().includes("network"))) {
18349
18534
  isDisconnect = true;
18350
18535
  }
@@ -18360,7 +18545,7 @@ var AbstractChat = class {
18360
18545
  messages: this.state.messages,
18361
18546
  isAbort,
18362
18547
  isDisconnect,
18363
- isError,
18548
+ isError: isError2,
18364
18549
  finishReason: activeResponse.state.finishReason
18365
18550
  });
18366
18551
  }
@@ -18371,7 +18556,7 @@ var AbstractChat = class {
18371
18556
  clearActiveResumeRequest();
18372
18557
  }
18373
18558
  }
18374
- if (!isError && await this.shouldSendAutomatically()) {
18559
+ if (!isError2 && await this.shouldSendAutomatically()) {
18375
18560
  await this.makeRequest({
18376
18561
  trigger: "submit-message",
18377
18562
  messageId: (_c = this.lastMessage) == null ? void 0 : _c.id,
@@ -18520,9 +18705,9 @@ async function uploadFile({
18520
18705
  filename,
18521
18706
  providerOptions
18522
18707
  }) {
18523
- var _a23;
18708
+ var _a24;
18524
18709
  const data = dataArg instanceof Uint8Array || typeof dataArg === "string" ? { type: "data", data: dataArg } : dataArg;
18525
- const mediaType = mediaTypeArg != null ? mediaTypeArg : data.type === "text" ? "text/plain" : (_a23 = detectMediaType6({ data: data.data })) != null ? _a23 : isLikelyText(data.data) ? "text/plain" : "application/octet-stream";
18710
+ const mediaType = mediaTypeArg != null ? mediaTypeArg : data.type === "text" ? "text/plain" : (_a24 = detectMediaType6({ data: data.data })) != null ? _a24 : isLikelyText(data.data) ? "text/plain" : "application/octet-stream";
18526
18711
  const filesApi = "uploadFile" in api ? api : typeof api.files === "function" ? api.files() : (() => {
18527
18712
  throw new Error(
18528
18713
  "The provider does not support file uploads. Make sure it exposes a files() method."
@@ -18593,7 +18778,7 @@ async function uploadSkill({
18593
18778
  return result;
18594
18779
  }
18595
18780
  export {
18596
- AISDKError23 as AISDKError,
18781
+ AISDKError24 as AISDKError,
18597
18782
  AI_SDK_TELEMETRY_TRACING_CHANNEL,
18598
18783
  APICallError,
18599
18784
  AbstractChat,
@@ -18635,6 +18820,7 @@ export {
18635
18820
  output_exports as Output,
18636
18821
  RetryError,
18637
18822
  SerialJobExecutor,
18823
+ StreamProviderError,
18638
18824
  TextStreamChatTransport,
18639
18825
  TooManyEmbeddingValuesForCallError,
18640
18826
  ToolCallNotFoundForApprovalError,