ai 7.0.79 → 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 (47) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/dist/index.d.ts +95 -35
  3. package/dist/index.js +601 -418
  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/03-agents/06-policy-tool-approvals.mdx +1 -1
  12. package/docs/03-agents/06-tool-approvals.mdx +6 -0
  13. package/docs/03-ai-sdk-core/15-tools-and-tool-calling.mdx +6 -4
  14. package/docs/03-ai-sdk-core/50-error-handling.mdx +17 -2
  15. package/docs/04-ai-sdk-ui/03-chatbot-tool-usage.mdx +6 -0
  16. package/docs/04-ai-sdk-ui/50-stream-protocol.mdx +2 -2
  17. package/docs/07-reference/01-ai-sdk-core/01-generate-text.mdx +1 -1
  18. package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +5 -4
  19. package/docs/07-reference/01-ai-sdk-core/06-embed-many.mdx +6 -2
  20. package/docs/07-reference/01-ai-sdk-core/16-tool-loop-agent.mdx +1 -1
  21. package/docs/07-reference/02-ai-sdk-ui/31-convert-to-model-messages.mdx +2 -2
  22. package/docs/07-reference/04-ai-sdk-workflow/03-generate-video.mdx +157 -0
  23. package/docs/07-reference/04-ai-sdk-workflow/index.mdx +6 -0
  24. package/docs/07-reference/05-ai-sdk-errors/ai-stream-provider-error.mdx +52 -0
  25. package/docs/07-reference/05-ai-sdk-errors/index.mdx +1 -0
  26. package/package.json +14 -3
  27. package/src/embed/embed-many.ts +78 -8
  28. package/src/error/index.ts +1 -0
  29. package/src/error/stream-provider-error.ts +78 -0
  30. package/src/generate-text/execute-tools-from-stream.ts +3 -0
  31. package/src/generate-text/generate-text-result.ts +2 -1
  32. package/src/generate-text/generate-text.ts +6 -3
  33. package/src/generate-text/stream-language-model-call.ts +8 -0
  34. package/src/generate-text/to-response-messages.ts +1 -0
  35. package/src/generate-text/tool-approval-configuration.ts +5 -1
  36. package/src/generate-text/tool-approval-request-output.ts +5 -0
  37. package/src/middleware/wrap-embedding-model.ts +11 -2
  38. package/src/model/get-embedding-model-max-input-bytes-per-call.ts +15 -0
  39. package/src/prompt/content-part.ts +1 -0
  40. package/src/prompt/normalize-stream-provider-error.ts +131 -0
  41. package/src/test/mock-embedding-model-v4.ts +9 -0
  42. package/src/ui/convert-to-model-messages.ts +3 -0
  43. package/src/ui/process-ui-message-stream.ts +6 -0
  44. package/src/ui/ui-messages.ts +10 -0
  45. package/src/ui/validate-ui-messages.ts +10 -0
  46. package/src/ui-message-stream/to-ui-message-chunk.ts +1 -0
  47. package/src/ui-message-stream/ui-message-chunks.ts +2 -0
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
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
@@ -37,7 +37,7 @@ import {
37
37
 
38
38
  // src/error/index.ts
39
39
  import {
40
- AISDKError as AISDKError23,
40
+ AISDKError as AISDKError24,
41
41
  APICallError,
42
42
  EmptyResponseBodyError,
43
43
  InvalidPromptError,
@@ -416,31 +416,64 @@ var NoSuchToolError = class extends AISDKError15 {
416
416
  };
417
417
  _a15 = symbol15;
418
418
 
419
- // src/error/tool-call-repair-error.ts
420
- import { AISDKError as AISDKError16, getErrorMessage as getErrorMessage2 } from "@ai-sdk/provider";
421
- 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";
422
422
  var marker16 = `vercel.ai.error.${name16}`;
423
423
  var symbol16 = Symbol.for(marker16);
424
424
  var _a16;
425
- var ToolCallRepairError = class extends AISDKError16 {
425
+ var StreamProviderError = class extends AISDKError16 {
426
426
  constructor({
427
- cause,
428
- originalError,
429
- message = `Error repairing tool call: ${getErrorMessage2(cause)}`
427
+ message,
428
+ type,
429
+ code,
430
+ statusCode,
431
+ isRetryable = isRetryableStatusCode(statusCode),
432
+ data,
433
+ cause
430
434
  }) {
431
435
  super({ name: name16, message, cause });
432
436
  this[_a16] = true;
433
- this.originalError = originalError;
437
+ this.type = type;
438
+ this.code = code;
439
+ this.statusCode = statusCode;
440
+ this.isRetryable = isRetryable;
441
+ this.data = data;
434
442
  }
435
443
  static isInstance(error) {
436
444
  return AISDKError16.hasMarker(error, marker16);
437
445
  }
438
446
  };
439
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;
440
473
 
441
474
  // src/error/unsupported-model-version-error.ts
442
- import { AISDKError as AISDKError17 } from "@ai-sdk/provider";
443
- var UnsupportedModelVersionError = class extends AISDKError17 {
475
+ import { AISDKError as AISDKError18 } from "@ai-sdk/provider";
476
+ var UnsupportedModelVersionError = class extends AISDKError18 {
444
477
  constructor(options) {
445
478
  super({
446
479
  name: "AI_UnsupportedModelVersionError",
@@ -453,118 +486,118 @@ var UnsupportedModelVersionError = class extends AISDKError17 {
453
486
  };
454
487
 
455
488
  // src/error/ui-message-stream-error.ts
456
- import { AISDKError as AISDKError18 } from "@ai-sdk/provider";
457
- var name17 = "AI_UIMessageStreamError";
458
- var marker17 = `vercel.ai.error.${name17}`;
459
- var symbol17 = Symbol.for(marker17);
460
- var _a17;
461
- 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 {
462
495
  constructor({
463
496
  chunkType,
464
497
  chunkId,
465
498
  message
466
499
  }) {
467
- super({ name: name17, message });
468
- this[_a17] = true;
500
+ super({ name: name18, message });
501
+ this[_a18] = true;
469
502
  this.chunkType = chunkType;
470
503
  this.chunkId = chunkId;
471
504
  }
472
505
  static isInstance(error) {
473
- return AISDKError18.hasMarker(error, marker17);
506
+ return AISDKError19.hasMarker(error, marker18);
474
507
  }
475
508
  };
476
- _a17 = symbol17;
509
+ _a18 = symbol18;
477
510
 
478
511
  // src/prompt/invalid-data-content-error.ts
479
- import { AISDKError as AISDKError19 } from "@ai-sdk/provider";
480
- var name18 = "AI_InvalidDataContentError";
481
- var marker18 = `vercel.ai.error.${name18}`;
482
- var symbol18 = Symbol.for(marker18);
483
- var _a18;
484
- 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 {
485
518
  constructor({
486
519
  content,
487
520
  cause,
488
521
  message = `Invalid data content. Expected a base64 string, Uint8Array, ArrayBuffer, or Buffer, but got ${typeof content}.`
489
522
  }) {
490
- super({ name: name18, message, cause });
491
- this[_a18] = true;
523
+ super({ name: name19, message, cause });
524
+ this[_a19] = true;
492
525
  this.content = content;
493
526
  }
494
527
  static isInstance(error) {
495
- return AISDKError19.hasMarker(error, marker18);
528
+ return AISDKError20.hasMarker(error, marker19);
496
529
  }
497
530
  };
498
- _a18 = symbol18;
531
+ _a19 = symbol19;
499
532
 
500
533
  // src/prompt/invalid-message-role-error.ts
501
- import { AISDKError as AISDKError20 } from "@ai-sdk/provider";
502
- var name19 = "AI_InvalidMessageRoleError";
503
- var marker19 = `vercel.ai.error.${name19}`;
504
- var symbol19 = Symbol.for(marker19);
505
- var _a19;
506
- 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 {
507
540
  constructor({
508
541
  role,
509
542
  message = `Invalid message role: '${role}'. Must be one of: "system", "user", "assistant", "tool".`
510
543
  }) {
511
- super({ name: name19, message });
512
- this[_a19] = true;
544
+ super({ name: name20, message });
545
+ this[_a20] = true;
513
546
  this.role = role;
514
547
  }
515
548
  static isInstance(error) {
516
- return AISDKError20.hasMarker(error, marker19);
549
+ return AISDKError21.hasMarker(error, marker20);
517
550
  }
518
551
  };
519
- _a19 = symbol19;
552
+ _a20 = symbol20;
520
553
 
521
554
  // src/prompt/message-conversion-error.ts
522
- import { AISDKError as AISDKError21 } from "@ai-sdk/provider";
523
- var name20 = "AI_MessageConversionError";
524
- var marker20 = `vercel.ai.error.${name20}`;
525
- var symbol20 = Symbol.for(marker20);
526
- var _a20;
527
- 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 {
528
561
  constructor({
529
562
  originalMessage,
530
563
  message
531
564
  }) {
532
- super({ name: name20, message });
533
- this[_a20] = true;
565
+ super({ name: name21, message });
566
+ this[_a21] = true;
534
567
  this.originalMessage = originalMessage;
535
568
  }
536
569
  static isInstance(error) {
537
- return AISDKError21.hasMarker(error, marker20);
570
+ return AISDKError22.hasMarker(error, marker21);
538
571
  }
539
572
  };
540
- _a20 = symbol20;
573
+ _a21 = symbol21;
541
574
 
542
575
  // src/error/index.ts
543
576
  import { DownloadError } from "@ai-sdk/provider-utils";
544
577
 
545
578
  // src/util/retry-error.ts
546
- import { AISDKError as AISDKError22 } from "@ai-sdk/provider";
547
- var name21 = "AI_RetryError";
548
- var marker21 = `vercel.ai.error.${name21}`;
549
- var symbol21 = Symbol.for(marker21);
550
- var _a21;
551
- 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 {
552
585
  constructor({
553
586
  message,
554
587
  reason,
555
588
  errors
556
589
  }) {
557
- super({ name: name21, message });
558
- this[_a21] = true;
590
+ super({ name: name22, message });
591
+ this[_a22] = true;
559
592
  this.reason = reason;
560
593
  this.errors = errors;
561
594
  this.lastError = errors[errors.length - 1];
562
595
  }
563
596
  static isInstance(error) {
564
- return AISDKError22.hasMarker(error, marker21);
597
+ return AISDKError23.hasMarker(error, marker22);
565
598
  }
566
599
  };
567
- _a21 = symbol21;
600
+ _a22 = symbol22;
568
601
 
569
602
  // src/logger/log-warnings.ts
570
603
  function formatWarning({
@@ -984,9 +1017,9 @@ function resolveEmbeddingModel(model) {
984
1017
  return asEmbeddingModelV4(model);
985
1018
  }
986
1019
  function resolveTranscriptionModel(model) {
987
- var _a23, _b;
1020
+ var _a24, _b;
988
1021
  if (typeof model === "string") {
989
- 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);
990
1023
  }
991
1024
  if (!["v4", "v3", "v2"].includes(model.specificationVersion)) {
992
1025
  const unsupportedModel = model;
@@ -999,9 +1032,9 @@ function resolveTranscriptionModel(model) {
999
1032
  return asTranscriptionModelV4(model);
1000
1033
  }
1001
1034
  function resolveSpeechTranslationModel(model) {
1002
- var _a23;
1035
+ var _a24;
1003
1036
  if (typeof model === "string") {
1004
- const provider = (_a23 = globalThis.AI_SDK_DEFAULT_PROVIDER) != null ? _a23 : gateway;
1037
+ const provider = (_a24 = globalThis.AI_SDK_DEFAULT_PROVIDER) != null ? _a24 : gateway;
1005
1038
  const speechTranslationModel = provider.speechTranslationModel;
1006
1039
  if (!speechTranslationModel) {
1007
1040
  throw new Error(
@@ -1021,9 +1054,9 @@ function resolveSpeechTranslationModel(model) {
1021
1054
  return model;
1022
1055
  }
1023
1056
  function resolveSpeechModel(model) {
1024
- var _a23, _b;
1057
+ var _a24, _b;
1025
1058
  if (typeof model === "string") {
1026
- 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);
1027
1060
  }
1028
1061
  if (!["v4", "v3", "v2"].includes(model.specificationVersion)) {
1029
1062
  const unsupportedModel = model;
@@ -1050,9 +1083,9 @@ function resolveImageModel(model) {
1050
1083
  return asImageModelV4(model);
1051
1084
  }
1052
1085
  function resolveVideoModel(model) {
1053
- var _a23;
1086
+ var _a24;
1054
1087
  if (typeof model === "string") {
1055
- const provider = (_a23 = globalThis.AI_SDK_DEFAULT_PROVIDER) != null ? _a23 : gateway;
1088
+ const provider = (_a24 = globalThis.AI_SDK_DEFAULT_PROVIDER) != null ? _a24 : gateway;
1056
1089
  const videoModel = provider.videoModel;
1057
1090
  if (!videoModel) {
1058
1091
  throw new Error(
@@ -1093,8 +1126,8 @@ function resolveRerankingModel(model) {
1093
1126
  return asRerankingModelV4(model);
1094
1127
  }
1095
1128
  function getGlobalProvider() {
1096
- var _a23;
1097
- 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;
1098
1131
  return asProviderV4(provider);
1099
1132
  }
1100
1133
 
@@ -1146,7 +1179,7 @@ import {
1146
1179
  } from "@ai-sdk/provider-utils";
1147
1180
 
1148
1181
  // src/version.ts
1149
- var VERSION = true ? "7.0.79" : "0.0.0-test";
1182
+ var VERSION = true ? "7.0.82" : "0.0.0-test";
1150
1183
 
1151
1184
  // src/util/download/download.ts
1152
1185
  var download = async ({
@@ -1154,7 +1187,7 @@ var download = async ({
1154
1187
  maxBytes,
1155
1188
  abortSignal
1156
1189
  }) => {
1157
- var _a23;
1190
+ var _a24;
1158
1191
  const urlText = url.toString();
1159
1192
  try {
1160
1193
  const headers = withUserAgentSuffix(
@@ -1182,7 +1215,7 @@ var download = async ({
1182
1215
  });
1183
1216
  return {
1184
1217
  data,
1185
- mediaType: (_a23 = response.headers.get("content-type")) != null ? _a23 : void 0
1218
+ mediaType: (_a24 = response.headers.get("content-type")) != null ? _a24 : void 0
1186
1219
  };
1187
1220
  } catch (error) {
1188
1221
  if (DownloadError2.isInstance(error)) {
@@ -1649,14 +1682,14 @@ function convertToLanguageModelMessage({
1649
1682
  }
1650
1683
  }
1651
1684
  function convertImagePartToFilePart(part) {
1652
- var _a23;
1685
+ var _a24;
1653
1686
  if (part.type !== "image") {
1654
1687
  return part;
1655
1688
  }
1656
1689
  return {
1657
1690
  type: "file",
1658
1691
  data: part.image,
1659
- mediaType: (_a23 = part.mediaType) != null ? _a23 : "image",
1692
+ mediaType: (_a24 = part.mediaType) != null ? _a24 : "image",
1660
1693
  providerOptions: part.providerOptions
1661
1694
  };
1662
1695
  }
@@ -1778,7 +1811,7 @@ function mapToolResultOutput({
1778
1811
  return {
1779
1812
  type: "content",
1780
1813
  value: output.value.map((item) => {
1781
- var _a23;
1814
+ var _a24;
1782
1815
  switch (item.type) {
1783
1816
  case "file": {
1784
1817
  const convertedPart = convertPartToLanguageModelPart(
@@ -1807,7 +1840,7 @@ function mapToolResultOutput({
1807
1840
  };
1808
1841
  }
1809
1842
  case "file-url": {
1810
- const mediaType = (_a23 = item.mediaType) != null ? _a23 : getMediaTypeFromUrl(item.url);
1843
+ const mediaType = (_a24 = item.mediaType) != null ? _a24 : getMediaTypeFromUrl(item.url);
1811
1844
  let message = `The "file-url" type for tool result content is deprecated. Use the "file" type with mediaType and { type: 'url', url } instead.`;
1812
1845
  if (!item.mediaType) {
1813
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.`;
@@ -1961,10 +1994,10 @@ var URL_EXTENSION_TO_MEDIA_TYPE = {
1961
1994
  ogg: "audio/ogg"
1962
1995
  };
1963
1996
  function getMediaTypeFromUrl(url, fallbackMediaType = "application/octet-stream") {
1964
- var _a23;
1997
+ var _a24;
1965
1998
  try {
1966
1999
  const pathname = new URL(url).pathname;
1967
- const fileExtension = (_a23 = pathname.split(".").pop()) == null ? void 0 : _a23.toLowerCase();
2000
+ const fileExtension = (_a24 = pathname.split(".").pop()) == null ? void 0 : _a24.toLowerCase();
1968
2001
  if (fileExtension && Object.hasOwn(URL_EXTENSION_TO_MEDIA_TYPE, fileExtension)) {
1969
2002
  return URL_EXTENSION_TO_MEDIA_TYPE[fileExtension];
1970
2003
  }
@@ -2119,7 +2152,7 @@ async function prepareTools({
2119
2152
  return void 0;
2120
2153
  }
2121
2154
  const languageModelTools = [];
2122
- for (const [name23, tool2] of orderToolEntries({ tools, toolOrder })) {
2155
+ for (const [name24, tool2] of orderToolEntries({ tools, toolOrder })) {
2123
2156
  const toolType = tool2.type;
2124
2157
  switch (toolType) {
2125
2158
  case void 0:
@@ -2127,7 +2160,7 @@ async function prepareTools({
2127
2160
  case "function": {
2128
2161
  const description = resolveToolDescription({
2129
2162
  tool: tool2,
2130
- toolName: name23,
2163
+ toolName: name24,
2131
2164
  toolsContext,
2132
2165
  experimental_sandbox: sandbox
2133
2166
  });
@@ -2136,7 +2169,7 @@ async function prepareTools({
2136
2169
  const strict = tool2.strict;
2137
2170
  languageModelTools.push({
2138
2171
  type: "function",
2139
- name: name23,
2172
+ name: name24,
2140
2173
  inputSchema: await asSchema(tool2.inputSchema).jsonSchema,
2141
2174
  ...description != null ? { description } : {},
2142
2175
  ...inputExamples != null ? { inputExamples } : {},
@@ -2148,7 +2181,7 @@ async function prepareTools({
2148
2181
  case "provider": {
2149
2182
  languageModelTools.push({
2150
2183
  type: "provider",
2151
- name: name23,
2184
+ name: name24,
2152
2185
  id: tool2.id,
2153
2186
  args: tool2.args
2154
2187
  });
@@ -2170,10 +2203,10 @@ function orderToolEntries({
2170
2203
  return Object.entries(tools);
2171
2204
  }
2172
2205
  const toolEntries = Object.entries(tools);
2173
- const orderedTools = toolEntries.filter(([name23]) => toolOrder.includes(name23)).sort(
2206
+ const orderedTools = toolEntries.filter(([name24]) => toolOrder.includes(name24)).sort(
2174
2207
  ([nameA], [nameB]) => toolOrder.indexOf(nameA) - toolOrder.indexOf(nameB)
2175
2208
  );
2176
- 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);
2177
2210
  return [...orderedTools, ...unorderedTools];
2178
2211
  }
2179
2212
  function resolveToolDescription({
@@ -2217,11 +2250,11 @@ function getChunkTimeoutMs(timeout) {
2217
2250
  return timeout.chunkMs;
2218
2251
  }
2219
2252
  function getToolTimeoutMs(timeout, toolName) {
2220
- var _a23, _b;
2253
+ var _a24, _b;
2221
2254
  if (timeout == null || typeof timeout === "number") {
2222
2255
  return void 0;
2223
2256
  }
2224
- 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;
2225
2258
  }
2226
2259
 
2227
2260
  // src/prompt/standardize-prompt.ts
@@ -2484,7 +2517,8 @@ var toolApprovalRequestSchema = z.object(
2484
2517
  {
2485
2518
  type: z.literal("tool-approval-request"),
2486
2519
  approvalId: z.string(),
2487
- toolCallId: z.string()
2520
+ toolCallId: z.string(),
2521
+ reason: z.string().optional()
2488
2522
  }
2489
2523
  );
2490
2524
  var toolApprovalResponseSchema = z.object({
@@ -2603,14 +2637,14 @@ async function standardizePrompt({
2603
2637
 
2604
2638
  // src/prompt/wrap-gateway-error.ts
2605
2639
  import { GatewayAuthenticationError } from "@ai-sdk/gateway";
2606
- import { AISDKError as AISDKError24 } from "@ai-sdk/provider";
2640
+ import { AISDKError as AISDKError25 } from "@ai-sdk/provider";
2607
2641
  function wrapGatewayError(error) {
2608
2642
  if (!GatewayAuthenticationError.isInstance(error))
2609
2643
  return error;
2610
2644
  const isProductionEnv = (process == null ? void 0 : process.env.NODE_ENV) === "production";
2611
2645
  const moreInfoURL = "https://ai-sdk.dev/unauthenticated-ai-gateway";
2612
2646
  if (isProductionEnv) {
2613
- return new AISDKError24({
2647
+ return new AISDKError25({
2614
2648
  name: "GatewayError",
2615
2649
  message: `Unauthenticated. Configure AI_GATEWAY_API_KEY or use a provider module. Learn more: ${moreInfoURL}`
2616
2650
  });
@@ -2668,12 +2702,12 @@ function createNullLanguageModelUsage() {
2668
2702
  };
2669
2703
  }
2670
2704
  function addLanguageModelUsage(usage1, usage2) {
2671
- var _a23, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2705
+ var _a24, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2672
2706
  return {
2673
2707
  inputTokens: addTokenCounts(usage1.inputTokens, usage2.inputTokens),
2674
2708
  inputTokenDetails: {
2675
2709
  noCacheTokens: addTokenCounts(
2676
- (_a23 = usage1.inputTokenDetails) == null ? void 0 : _a23.noCacheTokens,
2710
+ (_a24 = usage1.inputTokenDetails) == null ? void 0 : _a24.noCacheTokens,
2677
2711
  (_b = usage2.inputTokenDetails) == null ? void 0 : _b.noCacheTokens
2678
2712
  ),
2679
2713
  cacheReadTokens: addTokenCounts(
@@ -2726,8 +2760,8 @@ function mergeAbortSignals(...signals) {
2726
2760
 
2727
2761
  // src/util/now.ts
2728
2762
  function now() {
2729
- var _a23, _b;
2730
- 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();
2731
2765
  }
2732
2766
 
2733
2767
  // src/util/notify.ts
@@ -3101,7 +3135,7 @@ function filterActiveTools({
3101
3135
  return tools;
3102
3136
  }
3103
3137
  return Object.fromEntries(
3104
- Object.entries(tools).filter(([name23]) => activeTools.includes(name23))
3138
+ Object.entries(tools).filter(([name24]) => activeTools.includes(name24))
3105
3139
  );
3106
3140
  }
3107
3141
 
@@ -3538,7 +3572,7 @@ var text = () => ({
3538
3572
  });
3539
3573
  var object2 = ({
3540
3574
  schema: inputSchema,
3541
- name: name23,
3575
+ name: name24,
3542
3576
  description
3543
3577
  }) => {
3544
3578
  const schema = asSchema2(inputSchema);
@@ -3547,7 +3581,7 @@ var object2 = ({
3547
3581
  responseFormat: resolve(schema.jsonSchema).then((jsonSchema2) => ({
3548
3582
  type: "json",
3549
3583
  schema: jsonSchema2,
3550
- ...name23 != null && { name: name23 },
3584
+ ...name24 != null && { name: name24 },
3551
3585
  ...description != null && { description }
3552
3586
  })),
3553
3587
  async parseCompleteOutput({ text: text2 }, context) {
@@ -3601,7 +3635,7 @@ var object2 = ({
3601
3635
  };
3602
3636
  var array2 = ({
3603
3637
  element: inputElementSchema,
3604
- name: name23,
3638
+ name: name24,
3605
3639
  description
3606
3640
  }) => {
3607
3641
  const elementSchema = asSchema2(inputElementSchema);
@@ -3628,7 +3662,7 @@ var array2 = ({
3628
3662
  required: ["elements"],
3629
3663
  additionalProperties: false
3630
3664
  },
3631
- ...name23 != null && { name: name23 },
3665
+ ...name24 != null && { name: name24 },
3632
3666
  ...description != null && { description }
3633
3667
  };
3634
3668
  }),
@@ -3722,7 +3756,7 @@ var array2 = ({
3722
3756
  };
3723
3757
  var choice = ({
3724
3758
  options: choiceOptions,
3725
- name: name23,
3759
+ name: name24,
3726
3760
  description
3727
3761
  }) => {
3728
3762
  return {
@@ -3739,7 +3773,7 @@ var choice = ({
3739
3773
  required: ["result"],
3740
3774
  additionalProperties: false
3741
3775
  },
3742
- ...name23 != null && { name: name23 },
3776
+ ...name24 != null && { name: name24 },
3743
3777
  ...description != null && { description }
3744
3778
  }),
3745
3779
  async parseCompleteOutput({ text: text2 }, context) {
@@ -3800,14 +3834,14 @@ var choice = ({
3800
3834
  };
3801
3835
  };
3802
3836
  var json = ({
3803
- name: name23,
3837
+ name: name24,
3804
3838
  description
3805
3839
  } = {}) => {
3806
3840
  return {
3807
3841
  name: "json",
3808
3842
  responseFormat: Promise.resolve({
3809
3843
  type: "json",
3810
- ...name23 != null && { name: name23 },
3844
+ ...name24 != null && { name: name24 },
3811
3845
  ...description != null && { description }
3812
3846
  }),
3813
3847
  async parseCompleteOutput({ text: text2 }, context) {
@@ -3882,8 +3916,8 @@ async function parseToolCall({
3882
3916
  toolCall,
3883
3917
  tools,
3884
3918
  inputSchema: async ({ toolName }) => {
3885
- var _a23;
3886
- 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;
3887
3921
  return await asSchema3(inputSchema).jsonSchema;
3888
3922
  },
3889
3923
  instructions,
@@ -4007,9 +4041,9 @@ function prepareStepCallSettings({
4007
4041
  callSettings,
4008
4042
  stepSettings
4009
4043
  }) {
4010
- var _a23, _b, _c, _d, _e, _f, _g, _h, _i;
4044
+ var _a24, _b, _c, _d, _e, _f, _g, _h, _i;
4011
4045
  return prepareLanguageModelCallOptions({
4012
- 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,
4013
4047
  temperature: (_b = stepSettings == null ? void 0 : stepSettings.temperature) != null ? _b : callSettings.temperature,
4014
4048
  topP: (_c = stepSettings == null ? void 0 : stepSettings.topP) != null ? _c : callSettings.topP,
4015
4049
  topK: (_d = stepSettings == null ? void 0 : stepSettings.topK) != null ? _d : callSettings.topK,
@@ -4141,8 +4175,8 @@ var AI_SDK_TELEMETRY_TRACING_CHANNEL = "ai:telemetry";
4141
4175
 
4142
4176
  // src/util/is-node-runtime.ts
4143
4177
  function isNodeRuntime() {
4144
- var _a23;
4145
- 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";
4146
4180
  }
4147
4181
 
4148
4182
  // src/telemetry/tracing-channel-publisher.ts
@@ -4159,18 +4193,18 @@ async function loadDiagnosticsChannel() {
4159
4193
  return diagnosticsChannelPromise;
4160
4194
  }
4161
4195
  function loadBuiltinModule(id) {
4162
- var _a23;
4196
+ var _a24;
4163
4197
  const processWithBuiltins = globalThis.process;
4164
4198
  try {
4165
- 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);
4166
4200
  } catch (e) {
4167
4201
  return void 0;
4168
4202
  }
4169
4203
  }
4170
4204
  async function runWithTracingChannelSpan(message, execute) {
4171
- var _a23;
4205
+ var _a24;
4172
4206
  const diagnosticsChannel = await loadDiagnosticsChannel();
4173
- 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(
4174
4208
  diagnosticsChannel,
4175
4209
  AI_SDK_TELEMETRY_TRACING_CHANNEL
4176
4210
  );
@@ -4221,7 +4255,7 @@ function openTelemetryChannelSpanContext({
4221
4255
  message,
4222
4256
  completion
4223
4257
  }) {
4224
- var _a23;
4258
+ var _a24;
4225
4259
  if (!isNodeRuntime()) {
4226
4260
  return void 0;
4227
4261
  }
@@ -4229,7 +4263,7 @@ function openTelemetryChannelSpanContext({
4229
4263
  "node:diagnostics_channel"
4230
4264
  );
4231
4265
  const asyncHooks = loadBuiltinModule("node:async_hooks");
4232
- 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(
4233
4267
  diagnosticsChannel,
4234
4268
  AI_SDK_TELEMETRY_TRACING_CHANNEL
4235
4269
  );
@@ -4287,8 +4321,8 @@ function registerTelemetry(...integrations) {
4287
4321
  globalThis.AI_SDK_TELEMETRY_INTEGRATIONS.push(...integrations);
4288
4322
  }
4289
4323
  function getGlobalTelemetryIntegrations() {
4290
- var _a23;
4291
- return (_a23 = globalThis.AI_SDK_TELEMETRY_INTEGRATIONS) != null ? _a23 : [];
4324
+ var _a24;
4325
+ return (_a24 = globalThis.AI_SDK_TELEMETRY_INTEGRATIONS) != null ? _a24 : [];
4292
4326
  }
4293
4327
 
4294
4328
  // src/telemetry/create-telemetry-dispatcher.ts
@@ -4314,8 +4348,8 @@ function createTelemetryDispatcher({
4314
4348
  };
4315
4349
  const mergeTelemetryCallback = (key) => {
4316
4350
  const integrationCallbacks = integrations.map((integration) => {
4317
- var _a23;
4318
- return (_a23 = integration[key]) == null ? void 0 : _a23.bind(integration);
4351
+ var _a24;
4352
+ return (_a24 = integration[key]) == null ? void 0 : _a24.bind(integration);
4319
4353
  }).filter(Boolean).map(
4320
4354
  (callback) => (event) => callback(augmentEvent(event, telemetryMetadata))
4321
4355
  );
@@ -4325,12 +4359,12 @@ function createTelemetryDispatcher({
4325
4359
  };
4326
4360
  };
4327
4361
  const executeLanguageModelCallWrappers = integrations.map((integration) => {
4328
- var _a23;
4329
- return (_a23 = integration.executeLanguageModelCall) == null ? void 0 : _a23.bind(integration);
4362
+ var _a24;
4363
+ return (_a24 = integration.executeLanguageModelCall) == null ? void 0 : _a24.bind(integration);
4330
4364
  }).filter(Boolean);
4331
4365
  const executeToolWrappers = integrations.map((integration) => {
4332
- var _a23;
4333
- return (_a23 = integration.executeTool) == null ? void 0 : _a23.bind(integration);
4366
+ var _a24;
4367
+ return (_a24 = integration.executeTool) == null ? void 0 : _a24.bind(integration);
4334
4368
  }).filter(Boolean);
4335
4369
  return {
4336
4370
  runInTracingChannelSpan: async ({ type, event, execute }) => await runWithTracingChannelSpan(
@@ -4574,8 +4608,8 @@ function createRestrictedTelemetryDispatcher({
4574
4608
  return {
4575
4609
  ...telemetryDispatcher,
4576
4610
  onStart: (event) => {
4577
- var _a23;
4578
- return (_a23 = telemetryDispatcher.onStart) == null ? void 0 : _a23.call(telemetryDispatcher, {
4611
+ var _a24;
4612
+ return (_a24 = telemetryDispatcher.onStart) == null ? void 0 : _a24.call(telemetryDispatcher, {
4579
4613
  ...event,
4580
4614
  runtimeContext: filterIncludedContext({
4581
4615
  context: event.runtimeContext,
@@ -4588,8 +4622,8 @@ function createRestrictedTelemetryDispatcher({
4588
4622
  });
4589
4623
  },
4590
4624
  onStepStart: (event) => {
4591
- var _a23;
4592
- return (_a23 = telemetryDispatcher.onStepStart) == null ? void 0 : _a23.call(telemetryDispatcher, {
4625
+ var _a24;
4626
+ return (_a24 = telemetryDispatcher.onStepStart) == null ? void 0 : _a24.call(telemetryDispatcher, {
4593
4627
  ...event,
4594
4628
  runtimeContext: filterIncludedContext({
4595
4629
  context: event.runtimeContext,
@@ -4609,8 +4643,8 @@ function createRestrictedTelemetryDispatcher({
4609
4643
  });
4610
4644
  },
4611
4645
  onStepEnd: (event) => {
4612
- var _a23;
4613
- return (_a23 = telemetryDispatcher.onStepEnd) == null ? void 0 : _a23.call(
4646
+ var _a24;
4647
+ return (_a24 = telemetryDispatcher.onStepEnd) == null ? void 0 : _a24.call(
4614
4648
  telemetryDispatcher,
4615
4649
  restrictStepResult({
4616
4650
  step: event,
@@ -4620,8 +4654,8 @@ function createRestrictedTelemetryDispatcher({
4620
4654
  );
4621
4655
  },
4622
4656
  onStepFinish: (event) => {
4623
- var _a23;
4624
- return (_a23 = telemetryDispatcher.onStepEnd) == null ? void 0 : _a23.call(
4657
+ var _a24;
4658
+ return (_a24 = telemetryDispatcher.onStepEnd) == null ? void 0 : _a24.call(
4625
4659
  telemetryDispatcher,
4626
4660
  restrictStepResult({
4627
4661
  step: event,
@@ -4631,8 +4665,8 @@ function createRestrictedTelemetryDispatcher({
4631
4665
  );
4632
4666
  },
4633
4667
  onEnd: (event) => {
4634
- var _a23;
4635
- return (_a23 = telemetryDispatcher.onEnd) == null ? void 0 : _a23.call(
4668
+ var _a24;
4669
+ return (_a24 = telemetryDispatcher.onEnd) == null ? void 0 : _a24.call(
4636
4670
  telemetryDispatcher,
4637
4671
  ((restrictedSteps) => {
4638
4672
  return {
@@ -4660,8 +4694,8 @@ function createRestrictedTelemetryDispatcher({
4660
4694
  );
4661
4695
  },
4662
4696
  onAbort: (event) => {
4663
- var _a23;
4664
- return (_a23 = telemetryDispatcher.onAbort) == null ? void 0 : _a23.call(telemetryDispatcher, {
4697
+ var _a24;
4698
+ return (_a24 = telemetryDispatcher.onAbort) == null ? void 0 : _a24.call(telemetryDispatcher, {
4665
4699
  ...event,
4666
4700
  steps: event.steps.map(
4667
4701
  (step) => restrictStepResult({
@@ -4673,8 +4707,8 @@ function createRestrictedTelemetryDispatcher({
4673
4707
  });
4674
4708
  },
4675
4709
  onToolExecutionStart: (event) => {
4676
- var _a23;
4677
- return (_a23 = telemetryDispatcher.onToolExecutionStart) == null ? void 0 : _a23.call(telemetryDispatcher, {
4710
+ var _a24;
4711
+ return (_a24 = telemetryDispatcher.onToolExecutionStart) == null ? void 0 : _a24.call(telemetryDispatcher, {
4678
4712
  ...event,
4679
4713
  toolContext: filterToolContext({
4680
4714
  toolName: event.toolCall.toolName,
@@ -4684,8 +4718,8 @@ function createRestrictedTelemetryDispatcher({
4684
4718
  });
4685
4719
  },
4686
4720
  onToolExecutionEnd: (event) => {
4687
- var _a23;
4688
- return (_a23 = telemetryDispatcher.onToolExecutionEnd) == null ? void 0 : _a23.call(telemetryDispatcher, {
4721
+ var _a24;
4722
+ return (_a24 = telemetryDispatcher.onToolExecutionEnd) == null ? void 0 : _a24.call(telemetryDispatcher, {
4689
4723
  ...event,
4690
4724
  toolContext: filterToolContext({
4691
4725
  toolName: event.toolCall.toolName,
@@ -4706,8 +4740,8 @@ function isLoopFinished() {
4706
4740
  }
4707
4741
  function hasToolCall(...toolName) {
4708
4742
  return ({ steps }) => {
4709
- var _a23, _b, _c;
4710
- 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(
4711
4745
  (toolCall) => toolName.includes(toolCall.toolName)
4712
4746
  )) != null ? _c : false;
4713
4747
  };
@@ -4832,6 +4866,7 @@ async function toResponseMessages({
4832
4866
  type: "tool-approval-request",
4833
4867
  approvalId: part.approvalId,
4834
4868
  toolCallId: part.toolCall.toolCallId,
4869
+ ...part.reason != null ? { reason: part.reason } : {},
4835
4870
  isAutomatic: part.isAutomatic,
4836
4871
  ...part.signature != null ? { signature: part.signature } : {}
4837
4872
  });
@@ -4971,7 +5006,7 @@ function prepareToolsForToolCallers({
4971
5006
  tools,
4972
5007
  toolCallers
4973
5008
  }) {
4974
- var _a23, _b;
5009
+ var _a24, _b;
4975
5010
  if (tools == null || toolCallers == null) {
4976
5011
  return { executionTools: tools, modelTools: tools };
4977
5012
  }
@@ -5004,7 +5039,7 @@ function prepareToolsForToolCallers({
5004
5039
  )
5005
5040
  };
5006
5041
  } else {
5007
- const localTools = (_a23 = localToolsByCaller.get(callerName)) != null ? _a23 : {};
5042
+ const localTools = (_a24 = localToolsByCaller.get(callerName)) != null ? _a24 : {};
5008
5043
  localTools[toolName] = preparedTool;
5009
5044
  localToolsByCaller.set(callerName, localTools);
5010
5045
  }
@@ -5163,7 +5198,7 @@ async function validateApprovedToolApprovals({
5163
5198
  runtimeContext,
5164
5199
  toolApprovalSecret
5165
5200
  }) {
5166
- var _a23;
5201
+ var _a24;
5167
5202
  const approved = [];
5168
5203
  const denied = [];
5169
5204
  const invalid = [];
@@ -5225,7 +5260,7 @@ async function validateApprovedToolApprovals({
5225
5260
  approvalResponse: {
5226
5261
  ...approval.approvalResponse,
5227
5262
  approved: false,
5228
- reason: (_a23 = approvalStatus.reason) != null ? _a23 : approval.approvalResponse.reason
5263
+ reason: (_a24 = approvalStatus.reason) != null ? _a24 : approval.approvalResponse.reason
5229
5264
  }
5230
5265
  });
5231
5266
  } else {
@@ -5304,9 +5339,9 @@ async function generateText({
5304
5339
  onEnd = onFinish,
5305
5340
  ...settings
5306
5341
  }) {
5307
- var _a23, _b, _c, _d;
5342
+ var _a24, _b, _c, _d;
5308
5343
  include = {
5309
- requestBody: (_a23 = include == null ? void 0 : include.requestBody) != null ? _a23 : false,
5344
+ requestBody: (_a24 = include == null ? void 0 : include.requestBody) != null ? _a24 : false,
5310
5345
  requestMessages: (_b = include == null ? void 0 : include.requestMessages) != null ? _b : false,
5311
5346
  responseBody: (_c = include == null ? void 0 : include.responseBody) != null ? _c : false
5312
5347
  };
@@ -5405,7 +5440,7 @@ async function generateText({
5405
5440
  toolsContext
5406
5441
  };
5407
5442
  const executeGenerateText = async () => {
5408
- var _a24;
5443
+ var _a25;
5409
5444
  await notify({
5410
5445
  event: generateTextStartEvent,
5411
5446
  callbacks: [resolvedOnStart, telemetryDispatcher.onStart]
@@ -5551,7 +5586,7 @@ async function generateText({
5551
5586
  type: "step",
5552
5587
  event: { callId, stepNumber },
5553
5588
  execute: async () => {
5554
- 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;
5555
5590
  const accumulatedResponseMessages = [
5556
5591
  ...initialResponseMessages,
5557
5592
  ...steps.flatMap((step) => step.response.messages)
@@ -5570,7 +5605,7 @@ async function generateText({
5570
5605
  toolsContext,
5571
5606
  experimental_sandbox: sandbox
5572
5607
  }));
5573
- 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;
5574
5609
  const stepModel = resolveLanguageModel(
5575
5610
  (_b2 = prepareStepResult == null ? void 0 : prepareStepResult.model) != null ? _b2 : model
5576
5611
  );
@@ -5665,7 +5700,7 @@ async function generateText({
5665
5700
  });
5666
5701
  const executeLanguageModelCallInTelemetryContext = (_n = telemetryDispatcher.executeLanguageModelCall) != null ? _n : async ({ execute }) => await execute();
5667
5702
  currentModelResponse = await retry(async () => {
5668
- var _a26, _b3, _c3, _d3, _e2, _f2, _g2, _h2;
5703
+ var _a27, _b3, _c3, _d3, _e2, _f2, _g2, _h2;
5669
5704
  const result = await executeLanguageModelCallInTelemetryContext(
5670
5705
  {
5671
5706
  ...languageModelCallStartEvent,
@@ -5682,7 +5717,7 @@ async function generateText({
5682
5717
  }
5683
5718
  );
5684
5719
  const responseData = {
5685
- 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(),
5686
5721
  timestamp: (_d3 = (_c3 = result.response) == null ? void 0 : _c3.timestamp) != null ? _d3 : /* @__PURE__ */ new Date(),
5687
5722
  modelId: (_f2 = (_e2 = result.response) == null ? void 0 : _e2.modelId) != null ? _f2 : stepModel.modelId,
5688
5723
  headers: (_g2 = result.response) == null ? void 0 : _g2.headers,
@@ -5804,6 +5839,7 @@ async function generateText({
5804
5839
  type: "tool-approval-request",
5805
5840
  approvalId,
5806
5841
  toolCall,
5842
+ ...toolApprovalStatus.reason != null ? { reason: toolApprovalStatus.reason } : {},
5807
5843
  ...signature != null ? { signature } : {}
5808
5844
  };
5809
5845
  blockedToolCallIds.add(toolCall.toolCallId);
@@ -6042,8 +6078,8 @@ async function generateText({
6042
6078
  const staticToolResults = steps.flatMap((step) => step.staticToolResults);
6043
6079
  const dynamicToolResults = steps.flatMap((step) => step.dynamicToolResults);
6044
6080
  const warnings = steps.flatMap((step) => {
6045
- var _a25;
6046
- return (_a25 = step.warnings) != null ? _a25 : [];
6081
+ var _a26;
6082
+ return (_a26 = step.warnings) != null ? _a26 : [];
6047
6083
  });
6048
6084
  const onEndEvent = {
6049
6085
  callId,
@@ -6083,7 +6119,7 @@ async function generateText({
6083
6119
  callbacks: [onEnd, telemetryDispatcher.onEnd]
6084
6120
  });
6085
6121
  let resolvedOutput;
6086
- if (lastStep.finishReason === "stop" || lastStep.finishReason == null && lastStep.text.length > 0) {
6122
+ if (lastStep.finishReason === "stop" || lastStep.finishReason !== "tool-calls" && lastStep.text.length > 0) {
6087
6123
  const outputSpecification = output != null ? output : text();
6088
6124
  resolvedOutput = await outputSpecification.parseCompleteOutput(
6089
6125
  { text: lastStep.text },
@@ -6101,7 +6137,7 @@ async function generateText({
6101
6137
  output: resolvedOutput
6102
6138
  });
6103
6139
  } catch (error) {
6104
- 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 }));
6105
6141
  throw wrapGatewayError(error);
6106
6142
  }
6107
6143
  };
@@ -6201,8 +6237,8 @@ var DefaultGenerateTextResult = class {
6201
6237
  }
6202
6238
  get warnings() {
6203
6239
  return this.steps.flatMap((step) => {
6204
- var _a23;
6205
- return (_a23 = step.warnings) != null ? _a23 : [];
6240
+ var _a24;
6241
+ return (_a24 = step.warnings) != null ? _a24 : [];
6206
6242
  });
6207
6243
  }
6208
6244
  get providerMetadata() {
@@ -6647,6 +6683,7 @@ var uiMessageChunkSchema = lazySchema(
6647
6683
  type: z.literal("tool-approval-request"),
6648
6684
  approvalId: z.string(),
6649
6685
  toolCallId: z.string(),
6686
+ reason: z.string().optional(),
6650
6687
  isAutomatic: z.boolean().optional(),
6651
6688
  signature: z.string().optional()
6652
6689
  }),
@@ -6850,7 +6887,7 @@ function processUIMessageStream({
6850
6887
  new TransformStream({
6851
6888
  async transform(chunk, controller) {
6852
6889
  await runUpdateMessageJob(async ({ state, write }) => {
6853
- var _a23, _b, _c, _d;
6890
+ var _a24, _b, _c, _d;
6854
6891
  function getCurrentStepParts() {
6855
6892
  const parts = state.message.parts;
6856
6893
  let currentStepStartIndex = parts.length - 1;
@@ -6890,8 +6927,8 @@ function processUIMessageStream({
6890
6927
  const toolInvocations = state.message.parts.filter(isToolUIPart);
6891
6928
  const toolInvocation = toolInvocations.find(
6892
6929
  (invocation) => {
6893
- var _a24;
6894
- return ((_a24 = invocation.approval) == null ? void 0 : _a24.id) === approvalId;
6930
+ var _a25;
6931
+ return ((_a25 = invocation.approval) == null ? void 0 : _a25.id) === approvalId;
6895
6932
  }
6896
6933
  );
6897
6934
  if (toolInvocation == null) {
@@ -6904,7 +6941,7 @@ function processUIMessageStream({
6904
6941
  return toolInvocation;
6905
6942
  }
6906
6943
  function updateToolPart(options, existingPart) {
6907
- var _a24;
6944
+ var _a25;
6908
6945
  const part = existingPart != null ? existingPart : getCurrentStepParts().find(
6909
6946
  (part2) => isStaticToolUIPart(part2) && part2.toolCallId === options.toolCallId
6910
6947
  );
@@ -6923,7 +6960,7 @@ function processUIMessageStream({
6923
6960
  if (options.toolMetadata !== void 0) {
6924
6961
  anyPart.toolMetadata = options.toolMetadata;
6925
6962
  }
6926
- anyPart.providerExecuted = (_a24 = anyOptions.providerExecuted) != null ? _a24 : part.providerExecuted;
6963
+ anyPart.providerExecuted = (_a25 = anyOptions.providerExecuted) != null ? _a25 : part.providerExecuted;
6927
6964
  const providerMetadata = anyOptions.providerMetadata;
6928
6965
  if (providerMetadata != null) {
6929
6966
  if (options.state === "output-available" || options.state === "output-error") {
@@ -6952,7 +6989,7 @@ function processUIMessageStream({
6952
6989
  }
6953
6990
  }
6954
6991
  function updateDynamicToolPart(options, existingPart) {
6955
- var _a24, _b2;
6992
+ var _a25, _b2;
6956
6993
  const part = existingPart != null ? existingPart : getCurrentStepParts().find(
6957
6994
  (part2) => part2.type === "dynamic-tool" && part2.toolCallId === options.toolCallId
6958
6995
  );
@@ -6964,7 +7001,7 @@ function processUIMessageStream({
6964
7001
  anyPart.input = anyOptions.input;
6965
7002
  anyPart.output = anyOptions.output;
6966
7003
  anyPart.errorText = anyOptions.errorText;
6967
- anyPart.rawInput = (_a24 = anyOptions.rawInput) != null ? _a24 : anyPart.rawInput;
7004
+ anyPart.rawInput = (_a25 = anyOptions.rawInput) != null ? _a25 : anyPart.rawInput;
6968
7005
  anyPart.preliminary = anyOptions.preliminary;
6969
7006
  if (options.title !== void 0) {
6970
7007
  anyPart.title = options.title;
@@ -7039,7 +7076,7 @@ function processUIMessageStream({
7039
7076
  });
7040
7077
  }
7041
7078
  textPart.text += chunk.delta;
7042
- textPart.providerMetadata = (_a23 = chunk.providerMetadata) != null ? _a23 : textPart.providerMetadata;
7079
+ textPart.providerMetadata = (_a24 = chunk.providerMetadata) != null ? _a24 : textPart.providerMetadata;
7043
7080
  write();
7044
7081
  break;
7045
7082
  }
@@ -7282,6 +7319,7 @@ function processUIMessageStream({
7282
7319
  toolInvocation.state = "approval-requested";
7283
7320
  toolInvocation.approval = {
7284
7321
  id: chunk.approvalId,
7322
+ ...chunk.reason != null ? { requestReason: chunk.reason } : {},
7285
7323
  ...chunk.isAutomatic === true ? { isAutomatic: true } : {},
7286
7324
  ...chunk.signature != null ? { signature: chunk.signature } : {}
7287
7325
  };
@@ -7297,6 +7335,7 @@ function processUIMessageStream({
7297
7335
  toolInvocation.approval = {
7298
7336
  id: chunk.approvalId,
7299
7337
  approved: chunk.approved,
7338
+ ...approval.requestReason != null ? { requestReason: approval.requestReason } : {},
7300
7339
  ...chunk.reason != null ? { reason: chunk.reason } : {},
7301
7340
  ...approval.isAutomatic === true ? { isAutomatic: true } : {},
7302
7341
  ...approval.signature != null ? { signature: approval.signature } : {}
@@ -7754,6 +7793,7 @@ function toUIMessageChunk(part, {
7754
7793
  type: "tool-approval-request",
7755
7794
  approvalId: part.approvalId,
7756
7795
  toolCallId: part.toolCall.toolCallId,
7796
+ ...part.reason != null ? { reason: part.reason } : {},
7757
7797
  ...part.isAutomatic != null ? { isAutomatic: part.isAutomatic } : {},
7758
7798
  ...part.signature != null ? { signature: part.signature } : {}
7759
7799
  };
@@ -7910,13 +7950,13 @@ function asAsyncIterableStream(stream) {
7910
7950
  const reader = this.getReader();
7911
7951
  let finished = false;
7912
7952
  async function cleanup(cancelStream) {
7913
- var _a23;
7953
+ var _a24;
7914
7954
  if (finished)
7915
7955
  return;
7916
7956
  finished = true;
7917
7957
  try {
7918
7958
  if (cancelStream) {
7919
- await ((_a23 = reader.cancel) == null ? void 0 : _a23.call(reader));
7959
+ await ((_a24 = reader.cancel) == null ? void 0 : _a24.call(reader));
7920
7960
  }
7921
7961
  } finally {
7922
7962
  try {
@@ -8034,7 +8074,7 @@ function createStitchableStream() {
8034
8074
  controller == null ? void 0 : controller.close();
8035
8075
  };
8036
8076
  const processPull = async () => {
8037
- var _a23;
8077
+ var _a24;
8038
8078
  if (isClosed && innerStreams.length === 0) {
8039
8079
  controller == null ? void 0 : controller.close();
8040
8080
  return;
@@ -8058,7 +8098,7 @@ function createStitchableStream() {
8058
8098
  controller == null ? void 0 : controller.enqueue(value);
8059
8099
  }
8060
8100
  } catch (error) {
8061
- (_a23 = currentStream.onError) == null ? void 0 : _a23.call(currentStream, error);
8101
+ (_a24 = currentStream.onError) == null ? void 0 : _a24.call(currentStream, error);
8062
8102
  controller == null ? void 0 : controller.error(error);
8063
8103
  innerStreams.shift();
8064
8104
  terminate();
@@ -8170,6 +8210,7 @@ function executeToolsFromStream({
8170
8210
  type: "tool-approval-request",
8171
8211
  approvalId,
8172
8212
  toolCall: chunk,
8213
+ ...toolApprovalStatus.reason != null ? { reason: toolApprovalStatus.reason } : {},
8173
8214
  ...signature != null ? { signature } : {}
8174
8215
  });
8175
8216
  return;
@@ -8334,6 +8375,77 @@ import {
8334
8375
  import {
8335
8376
  createIdGenerator as createIdGenerator2
8336
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
8337
8449
  var originalGenerateId2 = createIdGenerator2({
8338
8450
  prefix: "aitxt",
8339
8451
  size: 24
@@ -8487,7 +8599,7 @@ function createLanguageModelV4StreamPartToLanguageModelStreamPartTransform({
8487
8599
  const timeBetweenOutputChunksMs = [];
8488
8600
  return new TransformStream({
8489
8601
  async transform(chunk, controller) {
8490
- var _a23, _b, _c;
8602
+ var _a24, _b, _c;
8491
8603
  if (isOutputChunk(chunk)) {
8492
8604
  const outputChunkTimestampMs = now2();
8493
8605
  if (timeToFirstOutputMs == null) {
@@ -8500,6 +8612,12 @@ function createLanguageModelV4StreamPartToLanguageModelStreamPartTransform({
8500
8612
  previousOutputChunkTimestampMs = outputChunkTimestampMs;
8501
8613
  }
8502
8614
  switch (chunk.type) {
8615
+ case "error":
8616
+ controller.enqueue({
8617
+ type: "error",
8618
+ error: normalizeStreamProviderError(chunk.error)
8619
+ });
8620
+ break;
8503
8621
  case "text-start":
8504
8622
  upsertTextContentPart({
8505
8623
  content: modelCallContent,
@@ -8726,7 +8844,7 @@ function createLanguageModelV4StreamPartToLanguageModelStreamPartTransform({
8726
8844
  const tool2 = getOwn(tools, chunk.toolName);
8727
8845
  controller.enqueue({
8728
8846
  ...chunk,
8729
- 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",
8730
8848
  title: tool2 == null ? void 0 : tool2.title,
8731
8849
  ...(tool2 == null ? void 0 : tool2.metadata) != null ? { toolMetadata: tool2.metadata } : {}
8732
8850
  });
@@ -8920,7 +9038,7 @@ function streamText({
8920
9038
  } = {},
8921
9039
  ...settings
8922
9040
  }) {
8923
- var _a23, _b, _c, _d;
9041
+ var _a24, _b, _c, _d;
8924
9042
  const totalTimeoutMs = getTotalTimeoutMs(timeout);
8925
9043
  const stepTimeoutMs = getStepTimeoutMs(timeout);
8926
9044
  const firstChunkTimeoutMs = getFirstChunkTimeoutMs(timeout);
@@ -8994,7 +9112,7 @@ function streamText({
8994
9112
  download: download2,
8995
9113
  // assign default values to include:
8996
9114
  include: {
8997
- requestBody: (_a23 = include == null ? void 0 : include.requestBody) != null ? _a23 : false,
9115
+ requestBody: (_a24 = include == null ? void 0 : include.requestBody) != null ? _a24 : false,
8998
9116
  requestMessages: (_b = include == null ? void 0 : include.requestMessages) != null ? _b : false,
8999
9117
  rawChunks: (_d = (_c = include == null ? void 0 : include.rawChunks) != null ? _c : includeRawChunks) != null ? _d : false
9000
9118
  }
@@ -9029,7 +9147,7 @@ function createOutputTransformStream(output) {
9029
9147
  }
9030
9148
  return new TransformStream({
9031
9149
  async transform(chunk, controller) {
9032
- var _a23;
9150
+ var _a24;
9033
9151
  if (chunk.type === "finish-step" && textChunk.length > 0) {
9034
9152
  publishTextChunk({ controller });
9035
9153
  }
@@ -9056,7 +9174,7 @@ function createOutputTransformStream(output) {
9056
9174
  }
9057
9175
  text2 += chunk.text;
9058
9176
  textChunk += chunk.text;
9059
- textProviderMetadata = (_a23 = chunk.providerMetadata) != null ? _a23 : textProviderMetadata;
9177
+ textProviderMetadata = (_a24 = chunk.providerMetadata) != null ? _a24 : textProviderMetadata;
9060
9178
  if (chunk.text.length === 0 && chunk.providerMetadata != null) {
9061
9179
  controller.enqueue({ part: chunk, partialOutput: void 0 });
9062
9180
  return;
@@ -9179,7 +9297,7 @@ var DefaultStreamTextResult = class {
9179
9297
  let recordedNoOutputError;
9180
9298
  const eventProcessor = new TransformStream({
9181
9299
  async transform(chunk, controller) {
9182
- var _a23, _b, _c, _d;
9300
+ var _a24, _b, _c, _d;
9183
9301
  controller.enqueue(chunk);
9184
9302
  const { part } = chunk;
9185
9303
  await notify({
@@ -9220,7 +9338,7 @@ var DefaultStreamTextResult = class {
9220
9338
  return;
9221
9339
  }
9222
9340
  activeText.text += part.text;
9223
- activeText.providerMetadata = (_a23 = part.providerMetadata) != null ? _a23 : activeText.providerMetadata;
9341
+ activeText.providerMetadata = (_a24 = part.providerMetadata) != null ? _a24 : activeText.providerMetadata;
9224
9342
  }
9225
9343
  if (part.type === "text-end") {
9226
9344
  const activeText = activeTextContent[part.id];
@@ -9376,8 +9494,8 @@ var DefaultStreamTextResult = class {
9376
9494
  (step) => step.dynamicToolResults
9377
9495
  );
9378
9496
  const warnings = recordedSteps.flatMap((step) => {
9379
- var _a23;
9380
- return (_a23 = step.warnings) != null ? _a23 : [];
9497
+ var _a24;
9498
+ return (_a24 = step.warnings) != null ? _a24 : [];
9381
9499
  });
9382
9500
  await notify({
9383
9501
  event: {
@@ -9500,7 +9618,7 @@ var DefaultStreamTextResult = class {
9500
9618
  const self = this;
9501
9619
  const callId = generateCallId();
9502
9620
  (async () => {
9503
- var _a23;
9621
+ var _a24;
9504
9622
  const initialPrompt = await standardizePrompt({
9505
9623
  instructions,
9506
9624
  system,
@@ -9536,14 +9654,14 @@ var DefaultStreamTextResult = class {
9536
9654
  runtimeContext,
9537
9655
  toolsContext
9538
9656
  };
9539
- const streamTextTracingChannelContext = (_a23 = telemetryDispatcher.startTracingChannelContext) == null ? void 0 : _a23.call(telemetryDispatcher, {
9657
+ const streamTextTracingChannelContext = (_a24 = telemetryDispatcher.startTracingChannelContext) == null ? void 0 : _a24.call(telemetryDispatcher, {
9540
9658
  type: "streamText",
9541
9659
  event: startEvent,
9542
9660
  completion: self._totalUsage.promise.then(() => void 0)
9543
9661
  });
9544
9662
  const runInStreamTextTracingChannelContext = (execute) => {
9545
- var _a24;
9546
- 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();
9547
9665
  };
9548
9666
  const runInTracingChannelSpanInStreamText = telemetryDispatcher.runInTracingChannelSpan == null ? void 0 : (options) => runInStreamTextTracingChannelContext(
9549
9667
  () => telemetryDispatcher.runInTracingChannelSpan(options)
@@ -9700,7 +9818,7 @@ var DefaultStreamTextResult = class {
9700
9818
  currentStep,
9701
9819
  usage
9702
9820
  }) {
9703
- 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;
9704
9822
  const stepTimeoutId = setAbortTimeout({
9705
9823
  abortController: stepAbortController,
9706
9824
  label: "Step",
@@ -9759,14 +9877,14 @@ var DefaultStreamTextResult = class {
9759
9877
  });
9760
9878
  try {
9761
9879
  stepFinish = new DelayedPromise();
9762
- const stepTracingChannelContext = (_a24 = telemetryDispatcher.startTracingChannelContext) == null ? void 0 : _a24.call(telemetryDispatcher, {
9880
+ const stepTracingChannelContext = (_a25 = telemetryDispatcher.startTracingChannelContext) == null ? void 0 : _a25.call(telemetryDispatcher, {
9763
9881
  type: "step",
9764
9882
  event: { callId, stepNumber: currentStep },
9765
9883
  completion: stepFinish.promise
9766
9884
  });
9767
9885
  const runInStepTracingChannelContext = (execute) => {
9768
- var _a25;
9769
- 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();
9770
9888
  };
9771
9889
  const responseMessagesFromPreviousSteps = recordedSteps.flatMap(
9772
9890
  (step) => step.response.messages
@@ -9841,9 +9959,9 @@ var DefaultStreamTextResult = class {
9841
9959
  } = await runInStepTracingChannelContext(
9842
9960
  () => retry(
9843
9961
  async () => {
9844
- var _a25, _b2;
9962
+ var _a26, _b2;
9845
9963
  return streamLanguageModelCall({
9846
- model: (_a25 = prepareStepResult == null ? void 0 : prepareStepResult.model) != null ? _a25 : model,
9964
+ model: (_a26 = prepareStepResult == null ? void 0 : prepareStepResult.model) != null ? _a26 : model,
9847
9965
  tools: stepModelTools,
9848
9966
  toolOrder: stepToolOrder,
9849
9967
  toolChoice: (_b2 = prepareStepResult == null ? void 0 : prepareStepResult.toolChoice) != null ? _b2 : toolChoice,
@@ -9871,7 +9989,7 @@ var DefaultStreamTextResult = class {
9871
9989
  telemetryDispatcher.onLanguageModelCallEnd
9872
9990
  ),
9873
9991
  onStart: async ({ promptMessages }) => {
9874
- var _a26, _b3;
9992
+ var _a27, _b3;
9875
9993
  await notify({
9876
9994
  event: {
9877
9995
  callId,
@@ -9881,7 +9999,7 @@ var DefaultStreamTextResult = class {
9881
9999
  instructions: stepInstructions,
9882
10000
  messages: stepMessages,
9883
10001
  tools,
9884
- toolChoice: (_a26 = prepareStepResult == null ? void 0 : prepareStepResult.toolChoice) != null ? _a26 : toolChoice,
10002
+ toolChoice: (_a27 = prepareStepResult == null ? void 0 : prepareStepResult.toolChoice) != null ? _a27 : toolChoice,
9885
10003
  activeTools: (_b3 = prepareStepResult == null ? void 0 : prepareStepResult.activeTools) != null ? _b3 : activeTools,
9886
10004
  toolOrder: stepToolOrder,
9887
10005
  steps: [...recordedSteps],
@@ -9979,7 +10097,7 @@ var DefaultStreamTextResult = class {
9979
10097
  streamWithToolResults.pipeThrough(
9980
10098
  new TransformStream({
9981
10099
  async transform(chunk, controller) {
9982
- var _a25, _b2, _c2, _d2, _e2, _f2, _g2;
10100
+ var _a26, _b2, _c2, _d2, _e2, _f2, _g2;
9983
10101
  if (chunk.type === "model-call-start") {
9984
10102
  warnings = chunk.warnings;
9985
10103
  return;
@@ -10022,7 +10140,7 @@ var DefaultStreamTextResult = class {
10022
10140
  if (chunk.text.length > 0 || chunk.providerMetadata != null) {
10023
10141
  controller.enqueue({
10024
10142
  ...chunk,
10025
- id: (_a25 = textPartIds.get(chunk.id)) != null ? _a25 : chunk.id
10143
+ id: (_a26 = textPartIds.get(chunk.id)) != null ? _a26 : chunk.id
10026
10144
  });
10027
10145
  }
10028
10146
  break;
@@ -10235,8 +10353,8 @@ var DefaultStreamTextResult = class {
10235
10353
  )
10236
10354
  );
10237
10355
  })().catch(async (error) => {
10238
- var _a23;
10239
- 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 }));
10240
10358
  self._initialResponseMessages.reject(error);
10241
10359
  markPromiseAsHandled(self._initialResponseMessages.promise);
10242
10360
  self.addStream(
@@ -10262,8 +10380,8 @@ var DefaultStreamTextResult = class {
10262
10380
  }
10263
10381
  get warnings() {
10264
10382
  return this.steps.then((steps) => steps.flatMap((step) => {
10265
- var _a23;
10266
- return (_a23 = step.warnings) != null ? _a23 : [];
10383
+ var _a24;
10384
+ return (_a24 = step.warnings) != null ? _a24 : [];
10267
10385
  }));
10268
10386
  }
10269
10387
  get providerMetadata() {
@@ -10392,19 +10510,19 @@ var DefaultStreamTextResult = class {
10392
10510
  }
10393
10511
  }
10394
10512
  async consumeStream(options) {
10395
- var _a23;
10513
+ var _a24;
10396
10514
  try {
10397
10515
  await consumeStream({
10398
10516
  stream: this.stream,
10399
10517
  onError: (error) => {
10400
- var _a24;
10518
+ var _a25;
10401
10519
  this.rejectResultPromises(error);
10402
- (_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);
10403
10521
  }
10404
10522
  });
10405
10523
  } catch (error) {
10406
10524
  this.rejectResultPromises(error);
10407
- (_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);
10408
10526
  }
10409
10527
  }
10410
10528
  get experimental_partialOutputStream() {
@@ -10424,8 +10542,8 @@ var DefaultStreamTextResult = class {
10424
10542
  );
10425
10543
  }
10426
10544
  get elementStream() {
10427
- var _a23, _b, _c;
10428
- 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();
10429
10547
  if (transform == null) {
10430
10548
  throw new UnsupportedFunctionalityError2({
10431
10549
  functionality: `element streams in ${(_c = (_b = this.outputSpecification) == null ? void 0 : _b.name) != null ? _c : "text"} mode`
@@ -10435,8 +10553,8 @@ var DefaultStreamTextResult = class {
10435
10553
  }
10436
10554
  get output() {
10437
10555
  return this.finalStep.then((step) => {
10438
- var _a23;
10439
- const output = (_a23 = this.outputSpecification) != null ? _a23 : text();
10556
+ var _a24;
10557
+ const output = (_a24 = this.outputSpecification) != null ? _a24 : text();
10440
10558
  return output.parseCompleteOutput(
10441
10559
  { text: step.text },
10442
10560
  {
@@ -10567,7 +10685,7 @@ var ToolLoopAgent = class {
10567
10685
  return this.settings.tools;
10568
10686
  }
10569
10687
  async prepareCall(options) {
10570
- var _a23, _b, _c, _d;
10688
+ var _a24, _b, _c, _d;
10571
10689
  if (this.settings.callOptionsSchema != null && options.options !== void 0) {
10572
10690
  const validatedOptions = await validateTypes3({
10573
10691
  value: options.options,
@@ -10591,7 +10709,7 @@ var ToolLoopAgent = class {
10591
10709
  } = this.settings;
10592
10710
  const baseCallArgs = {
10593
10711
  ...settingsWithoutCallbacks,
10594
- stopWhen: (_a23 = this.settings.stopWhen) != null ? _a23 : isStepCount(20),
10712
+ stopWhen: (_a24 = this.settings.stopWhen) != null ? _a24 : isStepCount(20),
10595
10713
  ...options
10596
10714
  };
10597
10715
  const preparedCallArgs = (_d = await ((_c = (_b = this.settings).prepareCall) == null ? void 0 : _c.call(
@@ -10630,9 +10748,9 @@ var ToolLoopAgent = class {
10630
10748
  * downstream by generateText/streamText and the provider.
10631
10749
  */
10632
10750
  agentHeaders(preparedCall) {
10633
- var _a23;
10751
+ var _a24;
10634
10752
  return withUserAgentSuffix3(
10635
- (_a23 = preparedCall.headers) != null ? _a23 : {},
10753
+ (_a24 = preparedCall.headers) != null ? _a24 : {},
10636
10754
  "ai-sdk-agent/tool-loop"
10637
10755
  );
10638
10756
  }
@@ -10655,7 +10773,7 @@ var ToolLoopAgent = class {
10655
10773
  onEnd = onFinish,
10656
10774
  ...options
10657
10775
  }) {
10658
- var _a23, _b, _c;
10776
+ var _a24, _b, _c;
10659
10777
  const generate = generateText;
10660
10778
  const preparedCall = await this.prepareCall({
10661
10779
  ...options,
@@ -10666,7 +10784,7 @@ var ToolLoopAgent = class {
10666
10784
  timeout: timeout != null ? timeout : preparedCall.timeout,
10667
10785
  experimental_sandbox: sandbox,
10668
10786
  onStart: mergeCallbacks(
10669
- (_a23 = this.settings.onStart) != null ? _a23 : this.settings.experimental_onStart,
10787
+ (_a24 = this.settings.onStart) != null ? _a24 : this.settings.experimental_onStart,
10670
10788
  onStart != null ? onStart : experimental_onStart
10671
10789
  ),
10672
10790
  onStepStart: mergeCallbacks(
@@ -10713,7 +10831,7 @@ var ToolLoopAgent = class {
10713
10831
  onEnd = onFinish,
10714
10832
  ...options
10715
10833
  }) {
10716
- var _a23, _b, _c;
10834
+ var _a24, _b, _c;
10717
10835
  const stream = streamText;
10718
10836
  const preparedCall = await this.prepareCall({
10719
10837
  ...options,
@@ -10725,7 +10843,7 @@ var ToolLoopAgent = class {
10725
10843
  experimental_sandbox: sandbox,
10726
10844
  experimental_transform,
10727
10845
  onStart: mergeCallbacks(
10728
- (_a23 = this.settings.onStart) != null ? _a23 : this.settings.experimental_onStart,
10846
+ (_a24 = this.settings.onStart) != null ? _a24 : this.settings.experimental_onStart,
10729
10847
  onStart != null ? onStart : experimental_onStart
10730
10848
  ),
10731
10849
  onStepStart: mergeCallbacks(
@@ -10875,7 +10993,7 @@ function readUIMessageStream({
10875
10993
  onError,
10876
10994
  terminateOnError = false
10877
10995
  }) {
10878
- var _a23;
10996
+ var _a24;
10879
10997
  let controller;
10880
10998
  let hasErrored = false;
10881
10999
  const outputStream = new ReadableStream({
@@ -10884,7 +11002,7 @@ function readUIMessageStream({
10884
11002
  }
10885
11003
  });
10886
11004
  const state = createStreamingUIMessageState({
10887
- messageId: (_a23 = message == null ? void 0 : message.id) != null ? _a23 : "",
11005
+ messageId: (_a24 = message == null ? void 0 : message.id) != null ? _a24 : "",
10888
11006
  lastMessage: message
10889
11007
  });
10890
11008
  const handleError = (error) => {
@@ -10953,7 +11071,7 @@ async function convertToModelMessages(messages, options) {
10953
11071
  modelMessages.push({
10954
11072
  role: "user",
10955
11073
  content: message.parts.map((part) => {
10956
- var _a23;
11074
+ var _a24;
10957
11075
  if (isTextUIPart(part)) {
10958
11076
  return {
10959
11077
  type: "text",
@@ -10974,7 +11092,7 @@ async function convertToModelMessages(messages, options) {
10974
11092
  };
10975
11093
  }
10976
11094
  if (isDataUIPart(part)) {
10977
- 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(
10978
11096
  options,
10979
11097
  part
10980
11098
  );
@@ -10987,7 +11105,7 @@ async function convertToModelMessages(messages, options) {
10987
11105
  if (message.parts != null) {
10988
11106
  let block = [];
10989
11107
  async function processBlock() {
10990
- var _a23, _b, _c, _d, _e, _f, _g;
11108
+ var _a24, _b, _c, _d, _e, _f, _g;
10991
11109
  if (block.length === 0) {
10992
11110
  return;
10993
11111
  }
@@ -11036,7 +11154,7 @@ async function convertToModelMessages(messages, options) {
11036
11154
  type: "tool-call",
11037
11155
  toolCallId: part.toolCallId,
11038
11156
  toolName,
11039
- 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,
11040
11158
  providerExecuted: part.providerExecuted,
11041
11159
  ...part.callProviderMetadata != null ? { providerOptions: part.callProviderMetadata } : {}
11042
11160
  });
@@ -11046,6 +11164,7 @@ async function convertToModelMessages(messages, options) {
11046
11164
  approvalId: part.approval.id,
11047
11165
  toolCallId: part.toolCallId,
11048
11166
  isAutomatic: part.approval.isAutomatic,
11167
+ ...part.approval.requestReason != null ? { reason: part.approval.requestReason } : {},
11049
11168
  ...part.approval.signature != null ? { signature: part.approval.signature } : {}
11050
11169
  });
11051
11170
  }
@@ -11087,8 +11206,8 @@ async function convertToModelMessages(messages, options) {
11087
11206
  }
11088
11207
  const toolParts = block.filter(
11089
11208
  (part) => {
11090
- var _a24;
11091
- 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);
11092
11211
  }
11093
11212
  );
11094
11213
  if (toolParts.length > 0) {
@@ -11303,6 +11422,7 @@ var uiMessagesSchema = lazySchema2(
11303
11422
  approval: z.object({
11304
11423
  id: z.string(),
11305
11424
  approved: z.never().optional(),
11425
+ requestReason: z.string().optional(),
11306
11426
  reason: z.never().optional(),
11307
11427
  isAutomatic: z.boolean().optional(),
11308
11428
  signature: z.string().optional()
@@ -11322,6 +11442,7 @@ var uiMessagesSchema = lazySchema2(
11322
11442
  approval: z.object({
11323
11443
  id: z.string(),
11324
11444
  approved: z.boolean(),
11445
+ requestReason: z.string().optional(),
11325
11446
  reason: z.string().optional(),
11326
11447
  isAutomatic: z.boolean().optional(),
11327
11448
  signature: z.string().optional()
@@ -11343,6 +11464,7 @@ var uiMessagesSchema = lazySchema2(
11343
11464
  approval: z.object({
11344
11465
  id: z.string(),
11345
11466
  approved: z.literal(true),
11467
+ requestReason: z.string().optional(),
11346
11468
  reason: z.string().optional(),
11347
11469
  isAutomatic: z.boolean().optional(),
11348
11470
  signature: z.string().optional()
@@ -11364,6 +11486,7 @@ var uiMessagesSchema = lazySchema2(
11364
11486
  approval: z.object({
11365
11487
  id: z.string(),
11366
11488
  approved: z.literal(true),
11489
+ requestReason: z.string().optional(),
11367
11490
  reason: z.string().optional(),
11368
11491
  isAutomatic: z.boolean().optional(),
11369
11492
  signature: z.string().optional()
@@ -11383,6 +11506,7 @@ var uiMessagesSchema = lazySchema2(
11383
11506
  approval: z.object({
11384
11507
  id: z.string(),
11385
11508
  approved: z.literal(false),
11509
+ requestReason: z.string().optional(),
11386
11510
  reason: z.string().optional(),
11387
11511
  isAutomatic: z.boolean().optional(),
11388
11512
  signature: z.string().optional()
@@ -11425,6 +11549,7 @@ var uiMessagesSchema = lazySchema2(
11425
11549
  approval: z.object({
11426
11550
  id: z.string(),
11427
11551
  approved: z.never().optional(),
11552
+ requestReason: z.string().optional(),
11428
11553
  reason: z.never().optional(),
11429
11554
  isAutomatic: z.boolean().optional(),
11430
11555
  signature: z.string().optional()
@@ -11443,6 +11568,7 @@ var uiMessagesSchema = lazySchema2(
11443
11568
  approval: z.object({
11444
11569
  id: z.string(),
11445
11570
  approved: z.boolean(),
11571
+ requestReason: z.string().optional(),
11446
11572
  reason: z.string().optional(),
11447
11573
  isAutomatic: z.boolean().optional(),
11448
11574
  signature: z.string().optional()
@@ -11463,6 +11589,7 @@ var uiMessagesSchema = lazySchema2(
11463
11589
  approval: z.object({
11464
11590
  id: z.string(),
11465
11591
  approved: z.literal(true),
11592
+ requestReason: z.string().optional(),
11466
11593
  reason: z.string().optional(),
11467
11594
  isAutomatic: z.boolean().optional(),
11468
11595
  signature: z.string().optional()
@@ -11483,6 +11610,7 @@ var uiMessagesSchema = lazySchema2(
11483
11610
  approval: z.object({
11484
11611
  id: z.string(),
11485
11612
  approved: z.literal(true),
11613
+ requestReason: z.string().optional(),
11486
11614
  reason: z.string().optional(),
11487
11615
  isAutomatic: z.boolean().optional(),
11488
11616
  signature: z.string().optional()
@@ -11501,6 +11629,7 @@ var uiMessagesSchema = lazySchema2(
11501
11629
  approval: z.object({
11502
11630
  id: z.string(),
11503
11631
  approved: z.literal(false),
11632
+ requestReason: z.string().optional(),
11504
11633
  reason: z.string().optional(),
11505
11634
  isAutomatic: z.boolean().optional(),
11506
11635
  signature: z.string().optional()
@@ -11677,7 +11806,7 @@ async function createAgentUIStream({
11677
11806
  onStepFinish,
11678
11807
  ...uiMessageStreamOptions
11679
11808
  }) {
11680
- var _a23;
11809
+ var _a24;
11681
11810
  const validatedMessages = await validateUIMessages({
11682
11811
  messages: uiMessages,
11683
11812
  // tools are compatible; the casting is required because the context param is
@@ -11696,7 +11825,7 @@ async function createAgentUIStream({
11696
11825
  experimental_transform,
11697
11826
  onStepEnd: onStepEnd != null ? onStepEnd : onStepFinish
11698
11827
  });
11699
- const originalMessages = (_a23 = uiMessageStreamOptions.originalMessages) != null ? _a23 : validatedMessages;
11828
+ const originalMessages = (_a24 = uiMessageStreamOptions.originalMessages) != null ? _a24 : validatedMessages;
11700
11829
  return createAsyncIterableStream(
11701
11830
  toUIMessageStream({
11702
11831
  ...uiMessageStreamOptions,
@@ -11970,7 +12099,7 @@ function convertBatchItemResult(item) {
11970
12099
  };
11971
12100
  }
11972
12101
  function convertGenerateResult(result) {
11973
- var _a23;
12102
+ var _a24;
11974
12103
  return {
11975
12104
  text: result.content.filter(
11976
12105
  (part) => part.type === "text"
@@ -11981,7 +12110,7 @@ function convertGenerateResult(result) {
11981
12110
  ...result.response != null ? {
11982
12111
  response: {
11983
12112
  id: result.response.id,
11984
- timestamp: (_a23 = result.response.timestamp) == null ? void 0 : _a23.toISOString(),
12113
+ timestamp: (_a24 = result.response.timestamp) == null ? void 0 : _a24.toISOString(),
11985
12114
  modelId: result.response.modelId
11986
12115
  }
11987
12116
  } : {},
@@ -12013,7 +12142,7 @@ async function embed({
12013
12142
  experimental_onEnd,
12014
12143
  _internal: { generateCallId = originalGenerateCallId4 } = {}
12015
12144
  }) {
12016
- var _a23;
12145
+ var _a24;
12017
12146
  const model = resolveEmbeddingModel(modelArg);
12018
12147
  const { maxRetries, retry } = prepareRetries({
12019
12148
  maxRetries: maxRetriesArg,
@@ -12029,7 +12158,7 @@ async function embed({
12029
12158
  const telemetryDispatcher = createTelemetryDispatcher({
12030
12159
  telemetry
12031
12160
  });
12032
- const runInTracingChannelSpan = (_a23 = telemetryDispatcher.runInTracingChannelSpan) != null ? _a23 : async ({ execute }) => await execute();
12161
+ const runInTracingChannelSpan = (_a24 = telemetryDispatcher.runInTracingChannelSpan) != null ? _a24 : async ({ execute }) => await execute();
12033
12162
  const startEvent = {
12034
12163
  callId,
12035
12164
  operationId: "ai.embed",
@@ -12044,14 +12173,14 @@ async function embed({
12044
12173
  type: "embed",
12045
12174
  event: startEvent,
12046
12175
  execute: async () => {
12047
- var _a24;
12176
+ var _a25;
12048
12177
  await notify({
12049
12178
  event: startEvent,
12050
12179
  callbacks: [resolvedOnStart, telemetryDispatcher.onStart]
12051
12180
  });
12052
12181
  try {
12053
12182
  const { embedding, usage, warnings, response, providerMetadata } = await retry(async () => {
12054
- var _a25, _b;
12183
+ var _a26, _b;
12055
12184
  const embedCallId = generateCallId();
12056
12185
  await notify({
12057
12186
  event: {
@@ -12071,7 +12200,7 @@ async function embed({
12071
12200
  providerOptions
12072
12201
  });
12073
12202
  const embedding2 = modelResponse.embeddings[0];
12074
- const usage2 = (_a25 = modelResponse.usage) != null ? _a25 : { tokens: NaN };
12203
+ const usage2 = (_a26 = modelResponse.usage) != null ? _a26 : { tokens: NaN };
12075
12204
  await notify({
12076
12205
  event: {
12077
12206
  callId,
@@ -12122,7 +12251,7 @@ async function embed({
12122
12251
  response
12123
12252
  });
12124
12253
  } catch (error) {
12125
- 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 }));
12126
12255
  throw error;
12127
12256
  }
12128
12257
  }
@@ -12145,6 +12274,12 @@ import {
12145
12274
  withUserAgentSuffix as withUserAgentSuffix6
12146
12275
  } from "@ai-sdk/provider-utils";
12147
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
+
12148
12283
  // src/util/split-array.ts
12149
12284
  function splitArray(array3, chunkSize) {
12150
12285
  if (chunkSize <= 0) {
@@ -12178,7 +12313,7 @@ async function embedMany({
12178
12313
  experimental_onEnd,
12179
12314
  _internal: { generateCallId = originalGenerateCallId5 } = {}
12180
12315
  }) {
12181
- var _a23;
12316
+ var _a24;
12182
12317
  const model = resolveEmbeddingModel(modelArg);
12183
12318
  const { maxRetries, retry } = prepareRetries({
12184
12319
  maxRetries: maxRetriesArg,
@@ -12194,7 +12329,7 @@ async function embedMany({
12194
12329
  const telemetryDispatcher = createTelemetryDispatcher({
12195
12330
  telemetry
12196
12331
  });
12197
- const runInTracingChannelSpan = (_a23 = telemetryDispatcher.runInTracingChannelSpan) != null ? _a23 : async ({ execute }) => await execute();
12332
+ const runInTracingChannelSpan = (_a24 = telemetryDispatcher.runInTracingChannelSpan) != null ? _a24 : async ({ execute }) => await execute();
12198
12333
  const startEvent = {
12199
12334
  callId,
12200
12335
  operationId: "ai.embedMany",
@@ -12209,18 +12344,26 @@ async function embedMany({
12209
12344
  type: "embedMany",
12210
12345
  event: startEvent,
12211
12346
  execute: async () => {
12212
- var _a24, _b;
12347
+ var _a25, _b;
12213
12348
  await notify({
12214
12349
  event: startEvent,
12215
12350
  callbacks: [resolvedOnStart, telemetryDispatcher.onStart]
12216
12351
  });
12217
12352
  try {
12218
- const [maxEmbeddingsPerCall, supportsParallelCalls] = await Promise.all(
12219
- [model.maxEmbeddingsPerCall, model.supportsParallelCalls]
12220
- );
12221
- 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) {
12222
12365
  const { embeddings: embeddings2, usage, warnings: warnings2, response, providerMetadata: providerMetadata2 } = await retry(async () => {
12223
- var _a25, _b2;
12366
+ var _a26, _b2;
12224
12367
  const embedCallId = generateCallId();
12225
12368
  await notify({
12226
12369
  event: {
@@ -12240,7 +12383,7 @@ async function embedMany({
12240
12383
  providerOptions
12241
12384
  });
12242
12385
  const embeddings3 = modelResponse.embeddings;
12243
- const usage2 = (_a25 = modelResponse.usage) != null ? _a25 : { tokens: NaN };
12386
+ const usage2 = (_a26 = modelResponse.usage) != null ? _a26 : { tokens: NaN };
12244
12387
  await notify({
12245
12388
  event: {
12246
12389
  callId,
@@ -12291,7 +12434,11 @@ async function embedMany({
12291
12434
  responses: [response]
12292
12435
  });
12293
12436
  }
12294
- const valueChunks = splitArray(values, maxEmbeddingsPerCall);
12437
+ const valueChunks = splitByEmbeddingLimits({
12438
+ values,
12439
+ maxEmbeddingsPerCall: hasEmbeddingLimit ? maxEmbeddingsPerCall : Infinity,
12440
+ maxInputBytesPerCall: hasInputByteLimit ? maxInputBytesPerCall : Infinity
12441
+ });
12295
12442
  const embeddings = [];
12296
12443
  const warnings = [];
12297
12444
  const responses = [];
@@ -12305,7 +12452,7 @@ async function embedMany({
12305
12452
  const results = await Promise.all(
12306
12453
  parallelChunk.map((chunk) => {
12307
12454
  return retry(async () => {
12308
- var _a25, _b2;
12455
+ var _a26, _b2;
12309
12456
  const embedCallId = generateCallId();
12310
12457
  await notify({
12311
12458
  event: {
@@ -12325,7 +12472,7 @@ async function embedMany({
12325
12472
  providerOptions
12326
12473
  });
12327
12474
  const chunkEmbeddings = modelResponse.embeddings;
12328
- const usage = (_a25 = modelResponse.usage) != null ? _a25 : { tokens: NaN };
12475
+ const usage = (_a26 = modelResponse.usage) != null ? _a26 : { tokens: NaN };
12329
12476
  await notify({
12330
12477
  event: {
12331
12478
  callId,
@@ -12362,7 +12509,7 @@ async function embedMany({
12362
12509
  result.providerMetadata
12363
12510
  )) {
12364
12511
  providerMetadata[providerName] = {
12365
- ...(_a24 = providerMetadata[providerName]) != null ? _a24 : {},
12512
+ ...(_a25 = providerMetadata[providerName]) != null ? _a25 : {},
12366
12513
  ...metadata
12367
12514
  };
12368
12515
  }
@@ -12405,6 +12552,37 @@ async function embedMany({
12405
12552
  }
12406
12553
  });
12407
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
+ }
12408
12586
  var DefaultEmbedManyResult = class {
12409
12587
  constructor(options) {
12410
12588
  this.values = options.values;
@@ -12472,7 +12650,7 @@ async function generateImage({
12472
12650
  abortSignal,
12473
12651
  headers
12474
12652
  }) {
12475
- var _a23, _b;
12653
+ var _a24, _b;
12476
12654
  const model = resolveImageModel(modelArg);
12477
12655
  const headersWithUserAgent = withUserAgentSuffix7(
12478
12656
  headers != null ? headers : {},
@@ -12482,7 +12660,7 @@ async function generateImage({
12482
12660
  maxRetries: maxRetriesArg,
12483
12661
  abortSignal
12484
12662
  });
12485
- 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;
12486
12664
  const callCount = Math.ceil(n / maxImagesPerCallWithDefault);
12487
12665
  const callImageCounts = Array.from({ length: callCount }, (_, i) => {
12488
12666
  if (i < callCount - 1) {
@@ -12523,13 +12701,13 @@ async function generateImage({
12523
12701
  images.push(
12524
12702
  ...result.images.map(
12525
12703
  (image) => {
12526
- var _a24;
12704
+ var _a25;
12527
12705
  return new DefaultGeneratedFile({
12528
12706
  data: image,
12529
- mediaType: (_a24 = detectMediaType2({
12707
+ mediaType: (_a25 = detectMediaType2({
12530
12708
  data: image,
12531
12709
  topLevelType: "image"
12532
- })) != null ? _a24 : "image/png"
12710
+ })) != null ? _a25 : "image/png"
12533
12711
  });
12534
12712
  }
12535
12713
  )
@@ -12752,7 +12930,7 @@ var arrayOutputStrategy = (schema) => {
12752
12930
  isFirstDelta,
12753
12931
  isFinalDelta
12754
12932
  }) {
12755
- var _a23;
12933
+ var _a24;
12756
12934
  if (!isJSONObject(value) || !isJSONArray(value.elements)) {
12757
12935
  return {
12758
12936
  success: false,
@@ -12775,7 +12953,7 @@ var arrayOutputStrategy = (schema) => {
12775
12953
  }
12776
12954
  resultArray.push(result.value);
12777
12955
  }
12778
- 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;
12779
12957
  let textDelta = "";
12780
12958
  if (isFirstDelta) {
12781
12959
  textDelta += "[";
@@ -13119,7 +13297,7 @@ function validateObjectGenerationInput({
13119
13297
  // src/generate-object/generate-object.ts
13120
13298
  var originalGenerateId4 = createIdGenerator6({ prefix: "aiobj", size: 24 });
13121
13299
  async function generateObject(options) {
13122
- var _a23, _b, _c, _d, _e, _f, _g, _h, _i, _j;
13300
+ var _a24, _b, _c, _d, _e, _f, _g, _h, _i, _j;
13123
13301
  const {
13124
13302
  model: modelArg,
13125
13303
  output = "object",
@@ -13254,7 +13432,7 @@ async function generateObject(options) {
13254
13432
  })
13255
13433
  );
13256
13434
  const responseData = {
13257
- 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(),
13258
13436
  timestamp: (_d = (_c = generateResult.response) == null ? void 0 : _c.timestamp) != null ? _d : currentDate(),
13259
13437
  modelId: (_f = (_e = generateResult.response) == null ? void 0 : _e.modelId) != null ? _f : model.modelId,
13260
13438
  headers: (_g = generateResult.response) == null ? void 0 : _g.headers,
@@ -13352,9 +13530,9 @@ var DefaultGenerateObjectResult = class {
13352
13530
  this.reasoning = options.reasoning;
13353
13531
  }
13354
13532
  toJsonResponse(init) {
13355
- var _a23;
13533
+ var _a24;
13356
13534
  return new Response(JSON.stringify(this.object), {
13357
- status: (_a23 = init == null ? void 0 : init.status) != null ? _a23 : 200,
13535
+ status: (_a24 = init == null ? void 0 : init.status) != null ? _a24 : 200,
13358
13536
  headers: prepareHeaders(init == null ? void 0 : init.headers, {
13359
13537
  "content-type": "application/json; charset=utf-8"
13360
13538
  })
@@ -13488,8 +13666,8 @@ function simulateReadableStream({
13488
13666
  chunkDelayInMs = 0,
13489
13667
  _internal
13490
13668
  }) {
13491
- var _a23;
13492
- 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;
13493
13671
  let index = 0;
13494
13672
  return new ReadableStream({
13495
13673
  async pull(controller) {
@@ -13759,7 +13937,7 @@ var DefaultStreamObjectResult = class {
13759
13937
  const transformedStream = stream.pipeThrough(new TransformStream(transformer)).pipeThrough(
13760
13938
  new TransformStream({
13761
13939
  async transform(chunk, controller) {
13762
- var _a23, _b, _c;
13940
+ var _a24, _b, _c;
13763
13941
  if (typeof chunk === "object" && chunk.type === "stream-start") {
13764
13942
  warnings = chunk.warnings;
13765
13943
  return;
@@ -13803,7 +13981,7 @@ var DefaultStreamObjectResult = class {
13803
13981
  switch (chunk.type) {
13804
13982
  case "response-metadata": {
13805
13983
  fullResponse = {
13806
- id: (_a23 = chunk.id) != null ? _a23 : fullResponse.id,
13984
+ id: (_a24 = chunk.id) != null ? _a24 : fullResponse.id,
13807
13985
  timestamp: (_b = chunk.timestamp) != null ? _b : fullResponse.timestamp,
13808
13986
  modelId: (_c = chunk.modelId) != null ? _c : fullResponse.modelId
13809
13987
  };
@@ -13939,9 +14117,9 @@ var DefaultStreamObjectResult = class {
13939
14117
  }
13940
14118
  });
13941
14119
  })().catch(async (error) => {
13942
- var _a23;
14120
+ var _a24;
13943
14121
  self.rejectResultPromises(error);
13944
- 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 }));
13945
14123
  stitchableStream.addStream(
13946
14124
  new ReadableStream({
13947
14125
  start(controller) {
@@ -14106,7 +14284,7 @@ async function generateSpeech({
14106
14284
  abortSignal,
14107
14285
  headers
14108
14286
  }) {
14109
- var _a23;
14287
+ var _a24;
14110
14288
  const resolvedModel = resolveSpeechModel(model);
14111
14289
  if (!resolvedModel) {
14112
14290
  throw new Error("Model could not be resolved");
@@ -14143,10 +14321,10 @@ async function generateSpeech({
14143
14321
  return new DefaultSpeechResult({
14144
14322
  audio: new DefaultGeneratedAudioFile({
14145
14323
  data: result.audio,
14146
- mediaType: (_a23 = detectMediaType3({
14324
+ mediaType: (_a24 = detectMediaType3({
14147
14325
  data: result.audio,
14148
14326
  topLevelType: "audio"
14149
- })) != null ? _a23 : "audio/mp3"
14327
+ })) != null ? _a24 : "audio/mp3"
14150
14328
  }),
14151
14329
  warnings: result.warnings,
14152
14330
  responses: [result.response],
@@ -14155,11 +14333,11 @@ async function generateSpeech({
14155
14333
  }
14156
14334
  var DefaultSpeechResult = class {
14157
14335
  constructor(options) {
14158
- var _a23;
14336
+ var _a24;
14159
14337
  this.audio = options.audio;
14160
14338
  this.warnings = options.warnings;
14161
14339
  this.responses = options.responses;
14162
- this.providerMetadata = (_a23 = options.providerMetadata) != null ? _a23 : {};
14340
+ this.providerMetadata = (_a24 = options.providerMetadata) != null ? _a24 : {};
14163
14341
  }
14164
14342
  };
14165
14343
 
@@ -14373,14 +14551,14 @@ function tagDescription(description) {
14373
14551
  }
14374
14552
  async function fingerprintTools(tools) {
14375
14553
  const entries = await Promise.all(
14376
- Object.keys(tools).map(async (name23) => {
14377
- const tool2 = tools[name23];
14554
+ Object.keys(tools).map(async (name24) => {
14555
+ const tool2 = tools[name24];
14378
14556
  const digest = await hashCanonical({
14379
14557
  description: tagDescription(tool2.description),
14380
14558
  inputSchema: await asSchema6(tool2.inputSchema).jsonSchema,
14381
14559
  title: tool2.title
14382
14560
  });
14383
- return [name23, digest];
14561
+ return [name24, digest];
14384
14562
  })
14385
14563
  );
14386
14564
  return Object.fromEntries(entries);
@@ -14389,16 +14567,16 @@ function detectToolDrift(current, baseline) {
14389
14567
  const added = [];
14390
14568
  const removed = [];
14391
14569
  const changed = [];
14392
- for (const name23 of Object.keys(current)) {
14393
- if (!Object.hasOwn(baseline, name23)) {
14394
- added.push(name23);
14395
- } else if (current[name23] !== baseline[name23]) {
14396
- 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);
14397
14575
  }
14398
14576
  }
14399
- for (const name23 of Object.keys(baseline)) {
14400
- if (!Object.hasOwn(current, name23)) {
14401
- removed.push(name23);
14577
+ for (const name24 of Object.keys(baseline)) {
14578
+ if (!Object.hasOwn(current, name24)) {
14579
+ removed.push(name24);
14402
14580
  }
14403
14581
  }
14404
14582
  return { added, removed, changed };
@@ -14434,7 +14612,7 @@ async function experimental_generateVideo({
14434
14612
  poll,
14435
14613
  webhook
14436
14614
  }) {
14437
- var _a23;
14615
+ var _a24;
14438
14616
  const model = resolveVideoModel(modelArg);
14439
14617
  const headersWithUserAgent = withUserAgentSuffix10(
14440
14618
  headers != null ? headers : {},
@@ -14451,7 +14629,7 @@ async function experimental_generateVideo({
14451
14629
  effectiveInputReferences,
14452
14630
  warnings
14453
14631
  } = normalizeVideoCallInputs({ promptArg, frameImages, inputReferences });
14454
- 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;
14455
14633
  const hasStartStatus = model.doStart != null && model.doStatus != null;
14456
14634
  const useStartStatus = hasStartStatus && (poll != null || webhook != null || model.doGenerate == null);
14457
14635
  if (model.doGenerate == null && !hasStartStatus) {
@@ -14590,7 +14768,7 @@ async function executeStartStatusFlow({
14590
14768
  webhook: webhookFactory,
14591
14769
  retry
14592
14770
  }) {
14593
- var _a23, _b, _c, _d;
14771
+ var _a24, _b, _c, _d;
14594
14772
  const earlyWarnings = [];
14595
14773
  let webhookUrl;
14596
14774
  let webhookReceived;
@@ -14609,7 +14787,7 @@ async function executeStartStatusFlow({
14609
14787
  });
14610
14788
  }
14611
14789
  }
14612
- const callerIdempotencyKey = Object.entries((_a23 = callOptions.headers) != null ? _a23 : {}).find(
14790
+ const callerIdempotencyKey = Object.entries((_a24 = callOptions.headers) != null ? _a24 : {}).find(
14613
14791
  ([key, value]) => key.toLowerCase() === "idempotency-key" && value !== void 0
14614
14792
  );
14615
14793
  const startCallOptions = {
@@ -14739,7 +14917,7 @@ function normalizeVideoCallInputs({
14739
14917
  frameImages,
14740
14918
  inputReferences
14741
14919
  }) {
14742
- var _a23;
14920
+ var _a24;
14743
14921
  const { prompt, image } = normalizePrompt2(promptArg);
14744
14922
  const normalizedFrameImages = frameImages == null ? void 0 : frameImages.flatMap((frame) => {
14745
14923
  const normalizedImage = normalizeImageData(frame.image);
@@ -14757,9 +14935,9 @@ function normalizeVideoCallInputs({
14757
14935
  message: "inputReferences were ignored because frameImages were provided; frameImages and inputReferences cannot be combined."
14758
14936
  });
14759
14937
  }
14760
- const firstFrameImage = (_a23 = normalizedFrameImages == null ? void 0 : normalizedFrameImages.find(
14938
+ const firstFrameImage = (_a24 = normalizedFrameImages == null ? void 0 : normalizedFrameImages.find(
14761
14939
  (frame) => frame.frameType === "first_frame"
14762
- )) == null ? void 0 : _a23.image;
14940
+ )) == null ? void 0 : _a24.image;
14763
14941
  if (image != null && firstFrameImage != null) {
14764
14942
  warnings.push({
14765
14943
  type: "other",
@@ -15005,8 +15183,8 @@ function stripMarkdownCodeFenceSuffix(text2) {
15005
15183
  return text2.replace(/\n?```\s*$/, "").trimEnd();
15006
15184
  }
15007
15185
  function extractJsonMiddleware(options) {
15008
- var _a23;
15009
- 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;
15010
15188
  const hasCustomTransform = (options == null ? void 0 : options.transform) !== void 0;
15011
15189
  return {
15012
15190
  specificationVersion: "v4",
@@ -15382,13 +15560,13 @@ function addToolInputExamplesMiddleware({
15382
15560
  return {
15383
15561
  specificationVersion: "v4",
15384
15562
  transformParams: async ({ params }) => {
15385
- var _a23;
15386
- if (!((_a23 = params.tools) == null ? void 0 : _a23.length)) {
15563
+ var _a24;
15564
+ if (!((_a24 = params.tools) == null ? void 0 : _a24.length)) {
15387
15565
  return params;
15388
15566
  }
15389
15567
  const transformedTools = params.tools.map((tool2) => {
15390
- var _a24;
15391
- 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)) {
15392
15570
  return tool2;
15393
15571
  }
15394
15572
  const formattedExamples = tool2.inputExamples.map((example, index) => format(example, index)).join("\n");
@@ -15437,7 +15615,7 @@ var doWrap = ({
15437
15615
  modelId,
15438
15616
  providerId
15439
15617
  }) => {
15440
- var _a23, _b, _c;
15618
+ var _a24, _b, _c;
15441
15619
  async function doTransform({
15442
15620
  params,
15443
15621
  type
@@ -15446,7 +15624,7 @@ var doWrap = ({
15446
15624
  }
15447
15625
  return {
15448
15626
  specificationVersion: "v4",
15449
- 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,
15450
15628
  modelId: (_b = modelId != null ? modelId : overrideModelId == null ? void 0 : overrideModelId({ model })) != null ? _b : model.modelId,
15451
15629
  supportedUrls: (_c = overrideSupportedUrls == null ? void 0 : overrideSupportedUrls({ model })) != null ? _c : model.supportedUrls,
15452
15630
  async doGenerate(params) {
@@ -15475,7 +15653,10 @@ var doWrap = ({
15475
15653
  };
15476
15654
 
15477
15655
  // src/middleware/wrap-embedding-model.ts
15478
- 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";
15479
15660
  var wrapEmbeddingModel = ({
15480
15661
  model: inputModel,
15481
15662
  middleware: middlewareArg,
@@ -15500,7 +15681,7 @@ var doWrap2 = ({
15500
15681
  modelId,
15501
15682
  providerId
15502
15683
  }) => {
15503
- var _a23, _b, _c, _d;
15684
+ var _a24, _b, _c, _d;
15504
15685
  async function doTransform({
15505
15686
  params
15506
15687
  }) {
@@ -15508,9 +15689,10 @@ var doWrap2 = ({
15508
15689
  }
15509
15690
  return {
15510
15691
  specificationVersion: "v4",
15511
- 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,
15512
15693
  modelId: (_b = modelId != null ? modelId : overrideModelId == null ? void 0 : overrideModelId({ model })) != null ? _b : model.modelId,
15513
15694
  maxEmbeddingsPerCall: (_c = overrideMaxEmbeddingsPerCall == null ? void 0 : overrideMaxEmbeddingsPerCall({ model })) != null ? _c : model.maxEmbeddingsPerCall,
15695
+ [EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL2]: getEmbeddingModelMaxInputBytesPerCall(model),
15514
15696
  supportsParallelCalls: (_d = overrideSupportsParallelCalls == null ? void 0 : overrideSupportsParallelCalls({ model })) != null ? _d : model.supportsParallelCalls,
15515
15697
  async doEmbed(params) {
15516
15698
  const transformedParams = await doTransform({ params });
@@ -15549,11 +15731,11 @@ var doWrap3 = ({
15549
15731
  modelId,
15550
15732
  providerId
15551
15733
  }) => {
15552
- var _a23, _b, _c;
15734
+ var _a24, _b, _c;
15553
15735
  async function doTransform({ params }) {
15554
15736
  return transformParams ? await transformParams({ params, model }) : params;
15555
15737
  }
15556
- 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;
15557
15739
  const maxImagesPerCall = maxImagesPerCallRaw instanceof Function ? maxImagesPerCallRaw.bind(model) : maxImagesPerCallRaw;
15558
15740
  return {
15559
15741
  specificationVersion: "v4",
@@ -15655,7 +15837,7 @@ async function getRealtimeToolDefinitions({
15655
15837
  toolsContext = {}
15656
15838
  }) {
15657
15839
  const definitions = [];
15658
- for (const [name23, tool2] of Object.entries(tools)) {
15840
+ for (const [name24, tool2] of Object.entries(tools)) {
15659
15841
  const toolType = tool2.type;
15660
15842
  switch (toolType) {
15661
15843
  case void 0:
@@ -15663,12 +15845,12 @@ async function getRealtimeToolDefinitions({
15663
15845
  case "dynamic": {
15664
15846
  const description = resolveRealtimeToolDescription({
15665
15847
  tool: tool2,
15666
- toolName: name23,
15848
+ toolName: name24,
15667
15849
  toolsContext
15668
15850
  });
15669
15851
  definitions.push({
15670
15852
  type: "function",
15671
- name: name23,
15853
+ name: name24,
15672
15854
  description,
15673
15855
  parameters: await asSchema7(tool2.inputSchema).jsonSchema
15674
15856
  });
@@ -15742,8 +15924,8 @@ var BrowserRealtimeAudio = class {
15742
15924
  this.onCapturingChange(true);
15743
15925
  }
15744
15926
  stopCapture() {
15745
- var _a23, _b, _c, _d;
15746
- (_a23 = this.captureProcessor) == null ? void 0 : _a23.disconnect();
15927
+ var _a24, _b, _c, _d;
15928
+ (_a24 = this.captureProcessor) == null ? void 0 : _a24.disconnect();
15747
15929
  (_b = this.captureSource) == null ? void 0 : _b.disconnect();
15748
15930
  void ((_c = this.captureContext) == null ? void 0 : _c.close());
15749
15931
  (_d = this.captureStream) == null ? void 0 : _d.getTracks().forEach((track) => track.stop());
@@ -15779,16 +15961,16 @@ var BrowserRealtimeAudio = class {
15779
15961
  return (ctx.currentTime - this.playbackStartTime) * 1e3;
15780
15962
  }
15781
15963
  dispose() {
15782
- var _a23;
15964
+ var _a24;
15783
15965
  this.stopCapture();
15784
15966
  this.stopPlayback();
15785
- void ((_a23 = this.playbackContext) == null ? void 0 : _a23.close());
15967
+ void ((_a24 = this.playbackContext) == null ? void 0 : _a24.close());
15786
15968
  this.playbackContext = null;
15787
15969
  }
15788
15970
  setPlaying(isPlaying) {
15789
- var _a23, _b;
15971
+ var _a24, _b;
15790
15972
  if (isPlaying && !this.isPlaying) {
15791
- 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;
15792
15974
  }
15793
15975
  if (this.isPlaying !== isPlaying) {
15794
15976
  this.isPlaying = isPlaying;
@@ -15841,8 +16023,8 @@ var BrowserRealtimeTransport = class {
15841
16023
  url,
15842
16024
  onOpen
15843
16025
  }) {
15844
- var _a23;
15845
- (_a23 = this.ws) == null ? void 0 : _a23.close();
16026
+ var _a24;
16027
+ (_a24 = this.ws) == null ? void 0 : _a24.close();
15846
16028
  this.ws = null;
15847
16029
  const wsConfig = this.model.getWebSocketConfig({ token, url });
15848
16030
  const ws = new WebSocket(wsConfig.url, wsConfig.protocols);
@@ -15866,8 +16048,8 @@ var BrowserRealtimeTransport = class {
15866
16048
  };
15867
16049
  }
15868
16050
  disconnect() {
15869
- var _a23;
15870
- (_a23 = this.ws) == null ? void 0 : _a23.close();
16051
+ var _a24;
16052
+ (_a24 = this.ws) == null ? void 0 : _a24.close();
15871
16053
  this.ws = null;
15872
16054
  }
15873
16055
  sendEvent(event) {
@@ -15883,8 +16065,8 @@ var BrowserRealtimeTransport = class {
15883
16065
  });
15884
16066
  }
15885
16067
  sendRaw(data) {
15886
- var _a23;
15887
- 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) {
15888
16070
  if (typeof data === "string" || data instanceof ArrayBuffer || ArrayBuffer.isView(data) || data instanceof Blob) {
15889
16071
  this.ws.send(data);
15890
16072
  } else {
@@ -15977,7 +16159,7 @@ var RealtimeEventReducer = class {
15977
16159
  };
15978
16160
  }
15979
16161
  async reduceServerEvent(state, event) {
15980
- var _a23;
16162
+ var _a24;
15981
16163
  let nextState = this.pushEvent(state, event);
15982
16164
  const effects = [];
15983
16165
  switch (event.type) {
@@ -16044,7 +16226,7 @@ var RealtimeEventReducer = class {
16044
16226
  const { state: updatedState, messageId } = this.getOrCreateAssistantMessage(nextState);
16045
16227
  nextState = updatedState;
16046
16228
  this.toolCallIdToMessageId.set(event.callId, messageId);
16047
- const acc = (_a23 = this.toolArgAccumulators.get(event.callId)) != null ? _a23 : "";
16229
+ const acc = (_a24 = this.toolArgAccumulators.get(event.callId)) != null ? _a24 : "";
16048
16230
  this.toolArgAccumulators.set(event.callId, acc + event.delta);
16049
16231
  nextState = this.ensureToolPart(nextState, messageId, event.callId);
16050
16232
  break;
@@ -16118,7 +16300,7 @@ var RealtimeEventReducer = class {
16118
16300
  };
16119
16301
  }
16120
16302
  addInputTranscriptionMessage(state, itemId, transcript) {
16121
- var _a23;
16303
+ var _a24;
16122
16304
  const messageId = `user-${itemId}`;
16123
16305
  const existingMessage = state.messages.find(
16124
16306
  (message) => message.id === messageId
@@ -16141,7 +16323,7 @@ var RealtimeEventReducer = class {
16141
16323
  };
16142
16324
  }
16143
16325
  const insertIndex = Math.min(
16144
- (_a23 = this.inputAudioMessageInsertIndex.get(itemId)) != null ? _a23 : state.messages.length,
16326
+ (_a24 = this.inputAudioMessageInsertIndex.get(itemId)) != null ? _a24 : state.messages.length,
16145
16327
  state.messages.length
16146
16328
  );
16147
16329
  const messages = [...state.messages];
@@ -16162,9 +16344,9 @@ var RealtimeEventReducer = class {
16162
16344
  };
16163
16345
  }
16164
16346
  appendTextDelta(state, itemId, delta) {
16165
- var _a23;
16347
+ var _a24;
16166
16348
  const { state: stateWithMessage, messageId } = this.getOrCreateAssistantMessage(state);
16167
- const acc = (_a23 = this.textAccumulators.get(itemId)) != null ? _a23 : "";
16349
+ const acc = (_a24 = this.textAccumulators.get(itemId)) != null ? _a24 : "";
16168
16350
  const text2 = acc + delta;
16169
16351
  this.textAccumulators.set(itemId, text2);
16170
16352
  const location = this.itemIdToPartLocation.get(itemId);
@@ -16194,8 +16376,8 @@ var RealtimeEventReducer = class {
16194
16376
  };
16195
16377
  }
16196
16378
  finalizeText(state, itemId, finalText) {
16197
- var _a23;
16198
- 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 : "";
16199
16381
  this.textAccumulators.delete(itemId);
16200
16382
  const location = this.itemIdToPartLocation.get(itemId);
16201
16383
  if (location == null)
@@ -16235,7 +16417,7 @@ var RealtimeEventReducer = class {
16235
16417
  })
16236
16418
  };
16237
16419
  }
16238
- markToolInputAvailable(state, messageId, callId, name23, input) {
16420
+ markToolInputAvailable(state, messageId, callId, name24, input) {
16239
16421
  return {
16240
16422
  ...state,
16241
16423
  messages: state.messages.map((message) => {
@@ -16251,7 +16433,7 @@ var RealtimeEventReducer = class {
16251
16433
  return part;
16252
16434
  return {
16253
16435
  ...toolPart,
16254
- toolName: name23,
16436
+ toolName: name24,
16255
16437
  state: "input-available",
16256
16438
  input
16257
16439
  };
@@ -16313,11 +16495,11 @@ var AbstractRealtimeSession = class {
16313
16495
  this.toolCallsInResponse = /* @__PURE__ */ new Set();
16314
16496
  this.submittedToolOutputs = /* @__PURE__ */ new Set();
16315
16497
  this.responseToolCallsClosed = false;
16316
- var _a23, _b, _c, _d, _e, _f, _g, _h;
16498
+ var _a24, _b, _c, _d, _e, _f, _g, _h;
16317
16499
  this.model = options.model;
16318
16500
  this.api = options.api;
16319
16501
  this.sessionConfig = options.sessionConfig;
16320
- this.maxEvents = (_a23 = options.maxEvents) != null ? _a23 : 500;
16502
+ this.maxEvents = (_a24 = options.maxEvents) != null ? _a24 : 500;
16321
16503
  this.reducer = new RealtimeEventReducer(this.maxEvents);
16322
16504
  this.onToolCall = options.onToolCall;
16323
16505
  this.onEvent = options.onEvent;
@@ -16329,9 +16511,9 @@ var AbstractRealtimeSession = class {
16329
16511
  model: this.model,
16330
16512
  onServerEvent: (event) => this.handleServerEvent(event),
16331
16513
  onError: (error) => {
16332
- var _a24;
16514
+ var _a25;
16333
16515
  this.applyState(this.reducer.setStatus(this.state, "error"));
16334
- (_a24 = this.onError) == null ? void 0 : _a24.call(this, error);
16516
+ (_a25 = this.onError) == null ? void 0 : _a25.call(this, error);
16335
16517
  },
16336
16518
  onClose: () => {
16337
16519
  this.applyState(this.reducer.setStatus(this.state, "disconnected"));
@@ -16351,7 +16533,7 @@ var AbstractRealtimeSession = class {
16351
16533
  }
16352
16534
  // ── Connection ─────────────────────────────────────────────────────
16353
16535
  async connect() {
16354
- var _a23;
16536
+ var _a24;
16355
16537
  this.applyState(this.reducer.setStatus(this.state, "connecting"));
16356
16538
  try {
16357
16539
  const response = await fetch(this.api.token, {
@@ -16381,7 +16563,7 @@ var AbstractRealtimeSession = class {
16381
16563
  });
16382
16564
  } catch (error) {
16383
16565
  this.applyState(this.reducer.setStatus(this.state, "error"));
16384
- (_a23 = this.onError) == null ? void 0 : _a23.call(
16566
+ (_a24 = this.onError) == null ? void 0 : _a24.call(
16385
16567
  this,
16386
16568
  error instanceof Error ? error : new Error(`Connection failed: ${String(error)}`)
16387
16569
  );
@@ -16507,18 +16689,18 @@ var AbstractRealtimeSession = class {
16507
16689
  }
16508
16690
  }
16509
16691
  async executeToolCall({
16510
- name: name23,
16692
+ name: name24,
16511
16693
  args,
16512
16694
  callId
16513
16695
  }) {
16514
- var _a23, _b;
16696
+ var _a24, _b;
16515
16697
  if (this.onToolCall == null) {
16516
- (_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}"`));
16517
16699
  return;
16518
16700
  }
16519
16701
  try {
16520
16702
  const result = await this.onToolCall({
16521
- toolCall: { toolCallId: callId, toolName: name23, args }
16703
+ toolCall: { toolCallId: callId, toolName: name24, args }
16522
16704
  });
16523
16705
  if (result !== void 0) {
16524
16706
  this.addToolOutput(callId, result);
@@ -16531,10 +16713,10 @@ var AbstractRealtimeSession = class {
16531
16713
  }
16532
16714
  }
16533
16715
  async handleServerEvent(event) {
16534
- var _a23;
16716
+ var _a24;
16535
16717
  const result = await this.reducer.reduceServerEvent(this.state, event);
16536
16718
  this.applyState(result.state);
16537
- (_a23 = this.onEvent) == null ? void 0 : _a23.call(this, event);
16719
+ (_a24 = this.onEvent) == null ? void 0 : _a24.call(this, event);
16538
16720
  for (const effect of result.effects) {
16539
16721
  this.handleReducerEffect(effect);
16540
16722
  }
@@ -16544,7 +16726,7 @@ var AbstractRealtimeSession = class {
16544
16726
  }
16545
16727
  }
16546
16728
  handleReducerEffect(effect) {
16547
- var _a23;
16729
+ var _a24;
16548
16730
  switch (effect.type) {
16549
16731
  case "play-audio": {
16550
16732
  this.currentResponseItemId = effect.itemId;
@@ -16576,7 +16758,7 @@ var AbstractRealtimeSession = class {
16576
16758
  break;
16577
16759
  }
16578
16760
  case "error": {
16579
- (_a23 = this.onError) == null ? void 0 : _a23.call(this, effect.error);
16761
+ (_a24 = this.onError) == null ? void 0 : _a24.call(this, effect.error);
16580
16762
  break;
16581
16763
  }
16582
16764
  }
@@ -16689,11 +16871,11 @@ function customProvider({
16689
16871
  }
16690
16872
 
16691
16873
  // src/registry/no-such-provider-error.ts
16692
- import { AISDKError as AISDKError25, NoSuchModelError as NoSuchModelError3 } from "@ai-sdk/provider";
16693
- var name22 = "AI_NoSuchProviderError";
16694
- var marker22 = `vercel.ai.error.${name22}`;
16695
- var symbol22 = Symbol.for(marker22);
16696
- 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;
16697
16879
  var NoSuchProviderError = class extends NoSuchModelError3 {
16698
16880
  constructor({
16699
16881
  modelId,
@@ -16702,16 +16884,16 @@ var NoSuchProviderError = class extends NoSuchModelError3 {
16702
16884
  availableProviders,
16703
16885
  message = `No such provider: ${providerId} (available providers: ${availableProviders.join()})`
16704
16886
  }) {
16705
- super({ errorName: name22, modelId, modelType, message });
16706
- this[_a22] = true;
16887
+ super({ errorName: name23, modelId, modelType, message });
16888
+ this[_a23] = true;
16707
16889
  this.providerId = providerId;
16708
16890
  this.availableProviders = availableProviders;
16709
16891
  }
16710
16892
  static isInstance(error) {
16711
- return AISDKError25.hasMarker(error, marker22);
16893
+ return AISDKError27.hasMarker(error, marker23);
16712
16894
  }
16713
16895
  };
16714
- _a22 = symbol22;
16896
+ _a23 = symbol23;
16715
16897
 
16716
16898
  // src/registry/provider-registry.ts
16717
16899
  import {
@@ -16748,9 +16930,9 @@ var DefaultProviderRegistry = class {
16748
16930
  id,
16749
16931
  provider
16750
16932
  }) {
16751
- var _a23;
16933
+ var _a24;
16752
16934
  const providerV4 = asProviderV4(provider);
16753
- const videoModel = (_a23 = provider.videoModel) == null ? void 0 : _a23.bind(provider);
16935
+ const videoModel = (_a24 = provider.videoModel) == null ? void 0 : _a24.bind(provider);
16754
16936
  this.providers[id] = videoModel == null ? providerV4 : Object.assign(Object.create(Object.getPrototypeOf(providerV4)), {
16755
16937
  ...providerV4,
16756
16938
  videoModel: (modelId) => asVideoModelV4(videoModel(modelId))
@@ -16780,10 +16962,10 @@ var DefaultProviderRegistry = class {
16780
16962
  return [id.slice(0, index), id.slice(index + this.separator.length)];
16781
16963
  }
16782
16964
  languageModel(id) {
16783
- var _a23, _b;
16965
+ var _a24, _b;
16784
16966
  const [providerId, modelId] = this.splitId(id, "languageModel");
16785
- let model = (_b = (_a23 = this.getProvider(providerId, "languageModel")).languageModel) == null ? void 0 : _b.call(
16786
- _a23,
16967
+ let model = (_b = (_a24 = this.getProvider(providerId, "languageModel")).languageModel) == null ? void 0 : _b.call(
16968
+ _a24,
16787
16969
  modelId
16788
16970
  );
16789
16971
  if (model == null) {
@@ -16798,10 +16980,10 @@ var DefaultProviderRegistry = class {
16798
16980
  return model;
16799
16981
  }
16800
16982
  embeddingModel(id) {
16801
- var _a23;
16983
+ var _a24;
16802
16984
  const [providerId, modelId] = this.splitId(id, "embeddingModel");
16803
16985
  const provider = this.getProvider(providerId, "embeddingModel");
16804
- 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);
16805
16987
  if (model == null) {
16806
16988
  throw new NoSuchModelError4({
16807
16989
  modelId: id,
@@ -16811,10 +16993,10 @@ var DefaultProviderRegistry = class {
16811
16993
  return model;
16812
16994
  }
16813
16995
  imageModel(id) {
16814
- var _a23;
16996
+ var _a24;
16815
16997
  const [providerId, modelId] = this.splitId(id, "imageModel");
16816
16998
  const provider = this.getProvider(providerId, "imageModel");
16817
- 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);
16818
17000
  if (model == null) {
16819
17001
  throw new NoSuchModelError4({ modelId: id, modelType: "imageModel" });
16820
17002
  }
@@ -16827,10 +17009,10 @@ var DefaultProviderRegistry = class {
16827
17009
  return model;
16828
17010
  }
16829
17011
  transcriptionModel(id) {
16830
- var _a23;
17012
+ var _a24;
16831
17013
  const [providerId, modelId] = this.splitId(id, "transcriptionModel");
16832
17014
  const provider = this.getProvider(providerId, "transcriptionModel");
16833
- 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);
16834
17016
  if (model == null) {
16835
17017
  throw new NoSuchModelError4({
16836
17018
  modelId: id,
@@ -16840,39 +17022,39 @@ var DefaultProviderRegistry = class {
16840
17022
  return model;
16841
17023
  }
16842
17024
  speechModel(id) {
16843
- var _a23;
17025
+ var _a24;
16844
17026
  const [providerId, modelId] = this.splitId(id, "speechModel");
16845
17027
  const provider = this.getProvider(providerId, "speechModel");
16846
- 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);
16847
17029
  if (model == null) {
16848
17030
  throw new NoSuchModelError4({ modelId: id, modelType: "speechModel" });
16849
17031
  }
16850
17032
  return model;
16851
17033
  }
16852
17034
  rerankingModel(id) {
16853
- var _a23;
17035
+ var _a24;
16854
17036
  const [providerId, modelId] = this.splitId(id, "rerankingModel");
16855
17037
  const provider = this.getProvider(providerId, "rerankingModel");
16856
- 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);
16857
17039
  if (model == null) {
16858
17040
  throw new NoSuchModelError4({ modelId: id, modelType: "rerankingModel" });
16859
17041
  }
16860
17042
  return model;
16861
17043
  }
16862
17044
  videoModel(id) {
16863
- var _a23;
17045
+ var _a24;
16864
17046
  const [providerId, modelId] = this.splitId(id, "videoModel");
16865
17047
  const provider = this.getProvider(providerId, "videoModel");
16866
- 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);
16867
17049
  if (model == null) {
16868
17050
  throw new NoSuchModelError4({ modelId: id, modelType: "videoModel" });
16869
17051
  }
16870
17052
  return asVideoModelV4(model);
16871
17053
  }
16872
17054
  files(id) {
16873
- var _a23;
17055
+ var _a24;
16874
17056
  const provider = this.getProvider(id, "languageModel");
16875
- const files = (_a23 = provider.files) == null ? void 0 : _a23.call(provider);
17057
+ const files = (_a24 = provider.files) == null ? void 0 : _a24.call(provider);
16876
17058
  if (files == null) {
16877
17059
  throw new Error(
16878
17060
  `The provider "${id}" does not support file uploads. Make sure it exposes a files() method.`
@@ -16881,9 +17063,9 @@ var DefaultProviderRegistry = class {
16881
17063
  return files;
16882
17064
  }
16883
17065
  skills(id) {
16884
- var _a23;
17066
+ var _a24;
16885
17067
  const provider = this.getProvider(id, "languageModel");
16886
- const skills = (_a23 = provider.skills) == null ? void 0 : _a23.call(provider);
17068
+ const skills = (_a24 = provider.skills) == null ? void 0 : _a24.call(provider);
16887
17069
  if (skills == null) {
16888
17070
  throw new Error(
16889
17071
  `The provider "${id}" does not support skills. Make sure it exposes a skills() method.`
@@ -16918,7 +17100,7 @@ async function rerank({
16918
17100
  experimental_onEnd,
16919
17101
  _internal: { generateCallId = originalGenerateCallId6 } = {}
16920
17102
  }) {
16921
- var _a23;
17103
+ var _a24;
16922
17104
  const model = resolveRerankingModel(modelArg);
16923
17105
  const callId = generateCallId();
16924
17106
  const resolvedOnStart = onStart != null ? onStart : experimental_onStart;
@@ -16926,7 +17108,7 @@ async function rerank({
16926
17108
  const telemetryDispatcher = createTelemetryDispatcher({
16927
17109
  telemetry
16928
17110
  });
16929
- const runInTracingChannelSpan = (_a23 = telemetryDispatcher.runInTracingChannelSpan) != null ? _a23 : async ({ execute }) => await execute();
17111
+ const runInTracingChannelSpan = (_a24 = telemetryDispatcher.runInTracingChannelSpan) != null ? _a24 : async ({ execute }) => await execute();
16930
17112
  if (documents.length === 0) {
16931
17113
  await notify({
16932
17114
  event: {
@@ -16992,7 +17174,7 @@ async function rerank({
16992
17174
  type: "rerank",
16993
17175
  event: startEvent,
16994
17176
  execute: async () => {
16995
- var _a24, _b, _c, _d, _e;
17177
+ var _a25, _b, _c, _d, _e;
16996
17178
  await notify({
16997
17179
  event: startEvent,
16998
17180
  callbacks: [resolvedOnStart, telemetryDispatcher.onStart]
@@ -17063,7 +17245,7 @@ async function rerank({
17063
17245
  providerMetadata,
17064
17246
  response: {
17065
17247
  id: response == null ? void 0 : response.id,
17066
- 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(),
17067
17249
  modelId: (_b = response == null ? void 0 : response.modelId) != null ? _b : model.modelId,
17068
17250
  headers: response == null ? void 0 : response.headers,
17069
17251
  body: response == null ? void 0 : response.body
@@ -17136,16 +17318,16 @@ async function transcribe({
17136
17318
  const audioData = audio instanceof URL ? (await downloadFn({ url: audio, abortSignal })).data : convertDataContentToUint8Array(audio);
17137
17319
  const result = await retry(
17138
17320
  () => {
17139
- var _a23;
17321
+ var _a24;
17140
17322
  return resolvedModel.doGenerate({
17141
17323
  audio: audioData,
17142
17324
  abortSignal,
17143
17325
  headers: headersWithUserAgent,
17144
17326
  providerOptions,
17145
- mediaType: (_a23 = detectMediaType5({
17327
+ mediaType: (_a24 = detectMediaType5({
17146
17328
  data: audioData,
17147
17329
  topLevelType: "audio"
17148
- })) != null ? _a23 : "audio/wav"
17330
+ })) != null ? _a24 : "audio/wav"
17149
17331
  });
17150
17332
  }
17151
17333
  );
@@ -17169,14 +17351,14 @@ async function transcribe({
17169
17351
  }
17170
17352
  var DefaultTranscriptionResult = class {
17171
17353
  constructor(options) {
17172
- var _a23;
17354
+ var _a24;
17173
17355
  this.text = options.text;
17174
17356
  this.segments = options.segments;
17175
17357
  this.language = options.language;
17176
17358
  this.durationInSeconds = options.durationInSeconds;
17177
17359
  this.warnings = options.warnings;
17178
17360
  this.responses = options.responses;
17179
- this.providerMetadata = (_a23 = options.providerMetadata) != null ? _a23 : {};
17361
+ this.providerMetadata = (_a24 = options.providerMetadata) != null ? _a24 : {};
17180
17362
  }
17181
17363
  };
17182
17364
 
@@ -17198,12 +17380,12 @@ function streamTranscribe({
17198
17380
  includeRawChunks,
17199
17381
  _internal: { currentDate = () => /* @__PURE__ */ new Date() } = {}
17200
17382
  }) {
17201
- var _a23;
17383
+ var _a24;
17202
17384
  const resolvedModel = resolveTranscriptionModel(model);
17203
17385
  if (!resolvedModel) {
17204
17386
  throw new Error("Model could not be resolved");
17205
17387
  }
17206
- const doStream = (_a23 = resolvedModel.doStream) == null ? void 0 : _a23.bind(resolvedModel);
17388
+ const doStream = (_a24 = resolvedModel.doStream) == null ? void 0 : _a24.bind(resolvedModel);
17207
17389
  if (doStream == null) {
17208
17390
  throw new UnsupportedFunctionalityError5({
17209
17391
  functionality: "streaming transcription",
@@ -17250,7 +17432,7 @@ function streamTranscribe({
17250
17432
  const pipeAbortController = new AbortController();
17251
17433
  const transformer = {
17252
17434
  transform(value, controller) {
17253
- var _a24, _b, _c, _d;
17435
+ var _a25, _b, _c, _d;
17254
17436
  switch (value.type) {
17255
17437
  case "stream-start": {
17256
17438
  resolveWarnings(value.warnings);
@@ -17258,7 +17440,7 @@ function streamTranscribe({
17258
17440
  }
17259
17441
  case "response-metadata": {
17260
17442
  response = {
17261
- timestamp: (_a24 = value.timestamp) != null ? _a24 : currentResponseMetadata().timestamp,
17443
+ timestamp: (_a25 = value.timestamp) != null ? _a25 : currentResponseMetadata().timestamp,
17262
17444
  modelId: (_b = value.modelId) != null ? _b : currentResponseMetadata().modelId,
17263
17445
  headers: (_c = value.headers) != null ? _c : response == null ? void 0 : response.headers
17264
17446
  };
@@ -17306,7 +17488,7 @@ function streamTranscribe({
17306
17488
  };
17307
17489
  const transform = new TransformStream(transformer);
17308
17490
  void (async () => {
17309
- var _a24, _b, _c, _d, _e;
17491
+ var _a25, _b, _c, _d, _e;
17310
17492
  const result = await doStream({
17311
17493
  audio,
17312
17494
  inputAudioFormat,
@@ -17317,7 +17499,7 @@ function streamTranscribe({
17317
17499
  includeRawChunks
17318
17500
  });
17319
17501
  response = {
17320
- 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,
17321
17503
  modelId: (_d = (_c = result.response) == null ? void 0 : _c.modelId) != null ? _d : resolvedModel.modelId,
17322
17504
  headers: (_e = result.response) == null ? void 0 : _e.headers
17323
17505
  };
@@ -17453,7 +17635,7 @@ function streamTranslate({
17453
17635
  let hasAudioOutput = false;
17454
17636
  const transformer = {
17455
17637
  transform(value, controller) {
17456
- var _a23, _b, _c, _d;
17638
+ var _a24, _b, _c, _d;
17457
17639
  switch (value.type) {
17458
17640
  case "stream-start": {
17459
17641
  resolveWarnings(value.warnings);
@@ -17461,7 +17643,7 @@ function streamTranslate({
17461
17643
  }
17462
17644
  case "response-metadata": {
17463
17645
  response = {
17464
- timestamp: (_a23 = value.timestamp) != null ? _a23 : currentResponseMetadata().timestamp,
17646
+ timestamp: (_a24 = value.timestamp) != null ? _a24 : currentResponseMetadata().timestamp,
17465
17647
  modelId: (_b = value.modelId) != null ? _b : currentResponseMetadata().modelId,
17466
17648
  headers: (_c = value.headers) != null ? _c : response == null ? void 0 : response.headers
17467
17649
  };
@@ -17520,7 +17702,7 @@ function streamTranslate({
17520
17702
  };
17521
17703
  const transform = new TransformStream(transformer);
17522
17704
  void (async () => {
17523
- var _a23, _b, _c, _d, _e;
17705
+ var _a24, _b, _c, _d, _e;
17524
17706
  const result = await doStream({
17525
17707
  audio,
17526
17708
  inputAudioFormat,
@@ -17534,7 +17716,7 @@ function streamTranslate({
17534
17716
  includeRawChunks
17535
17717
  });
17536
17718
  response = {
17537
- 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,
17538
17720
  modelId: (_d = (_c = result.response) == null ? void 0 : _c.modelId) != null ? _d : resolvedModel.modelId,
17539
17721
  headers: (_e = result.response) == null ? void 0 : _e.headers
17540
17722
  };
@@ -17645,7 +17827,7 @@ async function callCompletionApi({
17645
17827
  onError,
17646
17828
  fetch: fetch2 = getOriginalFetch()
17647
17829
  }) {
17648
- var _a23;
17830
+ var _a24;
17649
17831
  try {
17650
17832
  setLoading(true);
17651
17833
  setError(void 0);
@@ -17673,7 +17855,7 @@ async function callCompletionApi({
17673
17855
  });
17674
17856
  if (!response.ok) {
17675
17857
  throw new Error(
17676
- (_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."
17677
17859
  );
17678
17860
  }
17679
17861
  if (!response.body) {
@@ -17759,12 +17941,12 @@ async function convertFileListToFileUIParts(files) {
17759
17941
  }
17760
17942
  return Promise.all(
17761
17943
  Array.from(files).map(async (file) => {
17762
- const { name: name23, type } = file;
17944
+ const { name: name24, type } = file;
17763
17945
  const dataUrl = await new Promise((resolve3, reject) => {
17764
17946
  const reader = new FileReader();
17765
17947
  reader.onload = (readerEvent) => {
17766
- var _a23;
17767
- resolve3((_a23 = readerEvent.target) == null ? void 0 : _a23.result);
17948
+ var _a24;
17949
+ resolve3((_a24 = readerEvent.target) == null ? void 0 : _a24.result);
17768
17950
  };
17769
17951
  reader.onerror = (error) => reject(error);
17770
17952
  reader.readAsDataURL(file);
@@ -17772,7 +17954,7 @@ async function convertFileListToFileUIParts(files) {
17772
17954
  return {
17773
17955
  type: "file",
17774
17956
  mediaType: type,
17775
- filename: name23,
17957
+ filename: name24,
17776
17958
  url: dataUrl
17777
17959
  };
17778
17960
  })
@@ -17809,7 +17991,7 @@ var HttpChatTransport = class {
17809
17991
  abortSignal,
17810
17992
  ...options
17811
17993
  }) {
17812
- var _a23, _b, _c, _d, _e;
17994
+ var _a24, _b, _c, _d, _e;
17813
17995
  const resolvedBody = await resolve2(this.body);
17814
17996
  const resolvedHeaders = await resolve2(this.headers);
17815
17997
  const resolvedCredentials = await resolve2(this.credentials);
@@ -17817,7 +17999,7 @@ var HttpChatTransport = class {
17817
17999
  ...normalizeHeaders(resolvedHeaders),
17818
18000
  ...normalizeHeaders(options.headers)
17819
18001
  };
17820
- 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, {
17821
18003
  api: this.api,
17822
18004
  id: options.chatId,
17823
18005
  messages: options.messages,
@@ -17861,7 +18043,7 @@ var HttpChatTransport = class {
17861
18043
  return this.processResponseStream(response.body);
17862
18044
  }
17863
18045
  async reconnectToStream(options) {
17864
- var _a23, _b, _c, _d, _e;
18046
+ var _a24, _b, _c, _d, _e;
17865
18047
  const resolvedBody = await resolve2(this.body);
17866
18048
  const resolvedHeaders = await resolve2(this.headers);
17867
18049
  const resolvedCredentials = await resolve2(this.credentials);
@@ -17869,7 +18051,7 @@ var HttpChatTransport = class {
17869
18051
  ...normalizeHeaders(resolvedHeaders),
17870
18052
  ...normalizeHeaders(options.headers)
17871
18053
  };
17872
- 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, {
17873
18055
  api: this.api,
17874
18056
  id: options.chatId,
17875
18057
  body: { ...resolvedBody, ...options.body },
@@ -17950,11 +18132,11 @@ var AbstractChat = class {
17950
18132
  * If a messageId is provided, the message will be replaced.
17951
18133
  */
17952
18134
  this.sendMessage = async (message, options) => {
17953
- var _a23, _b, _c, _d;
18135
+ var _a24, _b, _c, _d;
17954
18136
  if (message == null) {
17955
18137
  await this.makeRequest({
17956
18138
  trigger: "submit-message",
17957
- messageId: (_a23 = this.lastMessage) == null ? void 0 : _a23.id,
18139
+ messageId: (_a24 = this.lastMessage) == null ? void 0 : _a24.id,
17958
18140
  ...options
17959
18141
  });
17960
18142
  return;
@@ -18074,11 +18256,11 @@ var AbstractChat = class {
18074
18256
  }
18075
18257
  if (this.status !== "streaming" && this.status !== "submitted" && this.sendAutomaticallyWhen) {
18076
18258
  this.shouldSendAutomatically().then((shouldSend) => {
18077
- var _a23;
18259
+ var _a24;
18078
18260
  if (shouldSend) {
18079
18261
  this.makeRequest({
18080
18262
  trigger: "submit-message",
18081
- messageId: (_a23 = this.lastMessage) == null ? void 0 : _a23.id,
18263
+ messageId: (_a24 = this.lastMessage) == null ? void 0 : _a24.id,
18082
18264
  ...options
18083
18265
  });
18084
18266
  }
@@ -18104,11 +18286,11 @@ var AbstractChat = class {
18104
18286
  }
18105
18287
  if (this.status !== "streaming" && this.status !== "submitted" && this.sendAutomaticallyWhen) {
18106
18288
  this.shouldSendAutomatically().then((shouldSend) => {
18107
- var _a23;
18289
+ var _a24;
18108
18290
  if (shouldSend) {
18109
18291
  this.makeRequest({
18110
18292
  trigger: "submit-message",
18111
- messageId: (_a23 = this.lastMessage) == null ? void 0 : _a23.id,
18293
+ messageId: (_a24 = this.lastMessage) == null ? void 0 : _a24.id,
18112
18294
  ...options
18113
18295
  });
18114
18296
  }
@@ -18121,11 +18303,11 @@ var AbstractChat = class {
18121
18303
  * Abort the current request immediately, keep the generated tokens if any.
18122
18304
  */
18123
18305
  this.stop = async () => {
18124
- var _a23, _b;
18306
+ var _a24, _b;
18125
18307
  for (const controller of this.pendingMessagePreparations) {
18126
18308
  controller.abort();
18127
18309
  }
18128
- (_a23 = this.activeResumeRequest) == null ? void 0 : _a23.abortController.abort();
18310
+ (_a24 = this.activeResumeRequest) == null ? void 0 : _a24.abortController.abort();
18129
18311
  (_b = this.activeResponse) == null ? void 0 : _b.abortController.abort();
18130
18312
  };
18131
18313
  this.id = id;
@@ -18190,11 +18372,11 @@ var AbstractChat = class {
18190
18372
  body,
18191
18373
  messageId
18192
18374
  }) {
18193
- var _a23, _b, _c;
18375
+ var _a24, _b, _c;
18194
18376
  const abortController = new AbortController();
18195
18377
  const activeResumeRequest = trigger === "resume-stream" ? { abortController } : void 0;
18196
18378
  if (activeResumeRequest) {
18197
- (_a23 = this.activeResumeRequest) == null ? void 0 : _a23.abortController.abort();
18379
+ (_a24 = this.activeResumeRequest) == null ? void 0 : _a24.abortController.abort();
18198
18380
  this.activeResumeRequest = activeResumeRequest;
18199
18381
  }
18200
18382
  const isCurrentRequest = () => activeResumeRequest == null || this.activeResumeRequest === activeResumeRequest;
@@ -18251,7 +18433,7 @@ var AbstractChat = class {
18251
18433
  const lastMessage = this.lastMessage;
18252
18434
  let isAbort = false;
18253
18435
  let isDisconnect = false;
18254
- let isError = false;
18436
+ let isError2 = false;
18255
18437
  let activeResponse;
18256
18438
  try {
18257
18439
  const response = {
@@ -18290,14 +18472,14 @@ var AbstractChat = class {
18290
18472
  return job({
18291
18473
  state: response.state,
18292
18474
  write: ({ updateStatus = true } = {}) => {
18293
- var _a24;
18475
+ var _a25;
18294
18476
  if (response.abortController.signal.aborted) {
18295
18477
  return;
18296
18478
  }
18297
18479
  if (updateStatus) {
18298
18480
  this.setStatus({ status: "streaming" });
18299
18481
  }
18300
- 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);
18301
18483
  if (replaceLastMessage) {
18302
18484
  this.state.replaceMessage(
18303
18485
  this.state.messages.length - 1,
@@ -18347,7 +18529,7 @@ var AbstractChat = class {
18347
18529
  if (!isCurrentRequest()) {
18348
18530
  return null;
18349
18531
  }
18350
- isError = true;
18532
+ isError2 = true;
18351
18533
  if (err instanceof TypeError && (err.message.toLowerCase().includes("fetch") || err.message.toLowerCase().includes("network"))) {
18352
18534
  isDisconnect = true;
18353
18535
  }
@@ -18363,7 +18545,7 @@ var AbstractChat = class {
18363
18545
  messages: this.state.messages,
18364
18546
  isAbort,
18365
18547
  isDisconnect,
18366
- isError,
18548
+ isError: isError2,
18367
18549
  finishReason: activeResponse.state.finishReason
18368
18550
  });
18369
18551
  }
@@ -18374,7 +18556,7 @@ var AbstractChat = class {
18374
18556
  clearActiveResumeRequest();
18375
18557
  }
18376
18558
  }
18377
- if (!isError && await this.shouldSendAutomatically()) {
18559
+ if (!isError2 && await this.shouldSendAutomatically()) {
18378
18560
  await this.makeRequest({
18379
18561
  trigger: "submit-message",
18380
18562
  messageId: (_c = this.lastMessage) == null ? void 0 : _c.id,
@@ -18523,9 +18705,9 @@ async function uploadFile({
18523
18705
  filename,
18524
18706
  providerOptions
18525
18707
  }) {
18526
- var _a23;
18708
+ var _a24;
18527
18709
  const data = dataArg instanceof Uint8Array || typeof dataArg === "string" ? { type: "data", data: dataArg } : dataArg;
18528
- 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";
18529
18711
  const filesApi = "uploadFile" in api ? api : typeof api.files === "function" ? api.files() : (() => {
18530
18712
  throw new Error(
18531
18713
  "The provider does not support file uploads. Make sure it exposes a files() method."
@@ -18596,7 +18778,7 @@ async function uploadSkill({
18596
18778
  return result;
18597
18779
  }
18598
18780
  export {
18599
- AISDKError23 as AISDKError,
18781
+ AISDKError24 as AISDKError,
18600
18782
  AI_SDK_TELEMETRY_TRACING_CHANNEL,
18601
18783
  APICallError,
18602
18784
  AbstractChat,
@@ -18638,6 +18820,7 @@ export {
18638
18820
  output_exports as Output,
18639
18821
  RetryError,
18640
18822
  SerialJobExecutor,
18823
+ StreamProviderError,
18641
18824
  TextStreamChatTransport,
18642
18825
  TooManyEmbeddingValuesForCallError,
18643
18826
  ToolCallNotFoundForApprovalError,