ai 6.0.271 → 6.0.272

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __export = (target, all) => {
3
- for (var name22 in all)
4
- __defProp(target, name22, { get: all[name22], enumerable: true });
3
+ for (var name23 in all)
4
+ __defProp(target, name23, { get: all[name23], enumerable: true });
5
5
  };
6
6
 
7
7
  // src/index.ts
@@ -29,7 +29,7 @@ import {
29
29
 
30
30
  // src/error/index.ts
31
31
  import {
32
- AISDKError as AISDKError22,
32
+ AISDKError as AISDKError23,
33
33
  APICallError,
34
34
  EmptyResponseBodyError,
35
35
  InvalidPromptError,
@@ -386,31 +386,62 @@ var NoSuchToolError = class extends AISDKError14 {
386
386
  };
387
387
  _a14 = symbol14;
388
388
 
389
- // src/error/tool-call-repair-error.ts
390
- import { AISDKError as AISDKError15, getErrorMessage as getErrorMessage2 } from "@ai-sdk/provider";
391
- var name15 = "AI_ToolCallRepairError";
389
+ // src/error/tool-choice-violation-error.ts
390
+ import {
391
+ AISDKError as AISDKError15
392
+ } from "@ai-sdk/provider";
393
+ var name15 = "AI_ToolChoiceViolationError";
392
394
  var marker15 = `vercel.ai.error.${name15}`;
393
395
  var symbol15 = Symbol.for(marker15);
394
396
  var _a15;
395
- var ToolCallRepairError = class extends AISDKError15 {
397
+ var ToolChoiceViolationError = class extends AISDKError15 {
398
+ constructor({
399
+ toolChoice,
400
+ finishReason,
401
+ provider,
402
+ modelId,
403
+ content,
404
+ message = toolChoice.type === "required" ? "Model response did not contain a tool call even though tool choice was required." : `Model response did not contain a call to the required tool '${toolChoice.toolName}'.`
405
+ }) {
406
+ super({ name: name15, message });
407
+ this[_a15] = true;
408
+ this.toolChoice = toolChoice;
409
+ this.finishReason = finishReason;
410
+ this.provider = provider;
411
+ this.modelId = modelId;
412
+ this.content = content;
413
+ }
414
+ static isInstance(error) {
415
+ return AISDKError15.hasMarker(error, marker15);
416
+ }
417
+ };
418
+ _a15 = symbol15;
419
+
420
+ // src/error/tool-call-repair-error.ts
421
+ import { AISDKError as AISDKError16, getErrorMessage as getErrorMessage2 } from "@ai-sdk/provider";
422
+ var name16 = "AI_ToolCallRepairError";
423
+ var marker16 = `vercel.ai.error.${name16}`;
424
+ var symbol16 = Symbol.for(marker16);
425
+ var _a16;
426
+ var ToolCallRepairError = class extends AISDKError16 {
396
427
  constructor({
397
428
  cause,
398
429
  originalError,
399
430
  message = `Error repairing tool call: ${getErrorMessage2(cause)}`
400
431
  }) {
401
- super({ name: name15, message, cause });
402
- this[_a15] = true;
432
+ super({ name: name16, message, cause });
433
+ this[_a16] = true;
403
434
  this.originalError = originalError;
404
435
  }
405
436
  static isInstance(error) {
406
- return AISDKError15.hasMarker(error, marker15);
437
+ return AISDKError16.hasMarker(error, marker16);
407
438
  }
408
439
  };
409
- _a15 = symbol15;
440
+ _a16 = symbol16;
410
441
 
411
442
  // src/error/unsupported-model-version-error.ts
412
- import { AISDKError as AISDKError16 } from "@ai-sdk/provider";
413
- var UnsupportedModelVersionError = class extends AISDKError16 {
443
+ import { AISDKError as AISDKError17 } from "@ai-sdk/provider";
444
+ var UnsupportedModelVersionError = class extends AISDKError17 {
414
445
  constructor(options) {
415
446
  super({
416
447
  name: "AI_UnsupportedModelVersionError",
@@ -423,118 +454,118 @@ var UnsupportedModelVersionError = class extends AISDKError16 {
423
454
  };
424
455
 
425
456
  // src/error/ui-message-stream-error.ts
426
- import { AISDKError as AISDKError17 } from "@ai-sdk/provider";
427
- var name16 = "AI_UIMessageStreamError";
428
- var marker16 = `vercel.ai.error.${name16}`;
429
- var symbol16 = Symbol.for(marker16);
430
- var _a16;
431
- var UIMessageStreamError = class extends AISDKError17 {
457
+ import { AISDKError as AISDKError18 } from "@ai-sdk/provider";
458
+ var name17 = "AI_UIMessageStreamError";
459
+ var marker17 = `vercel.ai.error.${name17}`;
460
+ var symbol17 = Symbol.for(marker17);
461
+ var _a17;
462
+ var UIMessageStreamError = class extends AISDKError18 {
432
463
  constructor({
433
464
  chunkType,
434
465
  chunkId,
435
466
  message
436
467
  }) {
437
- super({ name: name16, message });
438
- this[_a16] = true;
468
+ super({ name: name17, message });
469
+ this[_a17] = true;
439
470
  this.chunkType = chunkType;
440
471
  this.chunkId = chunkId;
441
472
  }
442
473
  static isInstance(error) {
443
- return AISDKError17.hasMarker(error, marker16);
474
+ return AISDKError18.hasMarker(error, marker17);
444
475
  }
445
476
  };
446
- _a16 = symbol16;
477
+ _a17 = symbol17;
447
478
 
448
479
  // src/prompt/invalid-data-content-error.ts
449
- import { AISDKError as AISDKError18 } from "@ai-sdk/provider";
450
- var name17 = "AI_InvalidDataContentError";
451
- var marker17 = `vercel.ai.error.${name17}`;
452
- var symbol17 = Symbol.for(marker17);
453
- var _a17;
454
- var InvalidDataContentError = class extends AISDKError18 {
480
+ import { AISDKError as AISDKError19 } from "@ai-sdk/provider";
481
+ var name18 = "AI_InvalidDataContentError";
482
+ var marker18 = `vercel.ai.error.${name18}`;
483
+ var symbol18 = Symbol.for(marker18);
484
+ var _a18;
485
+ var InvalidDataContentError = class extends AISDKError19 {
455
486
  constructor({
456
487
  content,
457
488
  cause,
458
489
  message = `Invalid data content. Expected a base64 string, Uint8Array, ArrayBuffer, or Buffer, but got ${typeof content}.`
459
490
  }) {
460
- super({ name: name17, message, cause });
461
- this[_a17] = true;
491
+ super({ name: name18, message, cause });
492
+ this[_a18] = true;
462
493
  this.content = content;
463
494
  }
464
495
  static isInstance(error) {
465
- return AISDKError18.hasMarker(error, marker17);
496
+ return AISDKError19.hasMarker(error, marker18);
466
497
  }
467
498
  };
468
- _a17 = symbol17;
499
+ _a18 = symbol18;
469
500
 
470
501
  // src/prompt/invalid-message-role-error.ts
471
- import { AISDKError as AISDKError19 } from "@ai-sdk/provider";
472
- var name18 = "AI_InvalidMessageRoleError";
473
- var marker18 = `vercel.ai.error.${name18}`;
474
- var symbol18 = Symbol.for(marker18);
475
- var _a18;
476
- var InvalidMessageRoleError = class extends AISDKError19 {
502
+ import { AISDKError as AISDKError20 } from "@ai-sdk/provider";
503
+ var name19 = "AI_InvalidMessageRoleError";
504
+ var marker19 = `vercel.ai.error.${name19}`;
505
+ var symbol19 = Symbol.for(marker19);
506
+ var _a19;
507
+ var InvalidMessageRoleError = class extends AISDKError20 {
477
508
  constructor({
478
509
  role,
479
510
  message = `Invalid message role: '${role}'. Must be one of: "system", "user", "assistant", "tool".`
480
511
  }) {
481
- super({ name: name18, message });
482
- this[_a18] = true;
512
+ super({ name: name19, message });
513
+ this[_a19] = true;
483
514
  this.role = role;
484
515
  }
485
516
  static isInstance(error) {
486
- return AISDKError19.hasMarker(error, marker18);
517
+ return AISDKError20.hasMarker(error, marker19);
487
518
  }
488
519
  };
489
- _a18 = symbol18;
520
+ _a19 = symbol19;
490
521
 
491
522
  // src/prompt/message-conversion-error.ts
492
- import { AISDKError as AISDKError20 } from "@ai-sdk/provider";
493
- var name19 = "AI_MessageConversionError";
494
- var marker19 = `vercel.ai.error.${name19}`;
495
- var symbol19 = Symbol.for(marker19);
496
- var _a19;
497
- var MessageConversionError = class extends AISDKError20 {
523
+ import { AISDKError as AISDKError21 } from "@ai-sdk/provider";
524
+ var name20 = "AI_MessageConversionError";
525
+ var marker20 = `vercel.ai.error.${name20}`;
526
+ var symbol20 = Symbol.for(marker20);
527
+ var _a20;
528
+ var MessageConversionError = class extends AISDKError21 {
498
529
  constructor({
499
530
  originalMessage,
500
531
  message
501
532
  }) {
502
- super({ name: name19, message });
503
- this[_a19] = true;
533
+ super({ name: name20, message });
534
+ this[_a20] = true;
504
535
  this.originalMessage = originalMessage;
505
536
  }
506
537
  static isInstance(error) {
507
- return AISDKError20.hasMarker(error, marker19);
538
+ return AISDKError21.hasMarker(error, marker20);
508
539
  }
509
540
  };
510
- _a19 = symbol19;
541
+ _a20 = symbol20;
511
542
 
512
543
  // src/error/index.ts
513
544
  import { DownloadError } from "@ai-sdk/provider-utils";
514
545
 
515
546
  // src/util/retry-error.ts
516
- import { AISDKError as AISDKError21 } from "@ai-sdk/provider";
517
- var name20 = "AI_RetryError";
518
- var marker20 = `vercel.ai.error.${name20}`;
519
- var symbol20 = Symbol.for(marker20);
520
- var _a20;
521
- var RetryError = class extends AISDKError21 {
547
+ import { AISDKError as AISDKError22 } from "@ai-sdk/provider";
548
+ var name21 = "AI_RetryError";
549
+ var marker21 = `vercel.ai.error.${name21}`;
550
+ var symbol21 = Symbol.for(marker21);
551
+ var _a21;
552
+ var RetryError = class extends AISDKError22 {
522
553
  constructor({
523
554
  message,
524
555
  reason,
525
556
  errors
526
557
  }) {
527
- super({ name: name20, message });
528
- this[_a20] = true;
558
+ super({ name: name21, message });
559
+ this[_a21] = true;
529
560
  this.reason = reason;
530
561
  this.errors = errors;
531
562
  this.lastError = errors[errors.length - 1];
532
563
  }
533
564
  static isInstance(error) {
534
- return AISDKError21.hasMarker(error, marker20);
565
+ return AISDKError22.hasMarker(error, marker21);
535
566
  }
536
567
  };
537
- _a20 = symbol20;
568
+ _a21 = symbol21;
538
569
 
539
570
  // src/util/as-array.ts
540
571
  function asArray(value) {
@@ -814,7 +845,7 @@ function resolveEmbeddingModel(model) {
814
845
  return getGlobalProvider().embeddingModel(model);
815
846
  }
816
847
  function resolveTranscriptionModel(model) {
817
- var _a22, _b;
848
+ var _a23, _b;
818
849
  if (typeof model !== "string") {
819
850
  if (model.specificationVersion !== "v3" && model.specificationVersion !== "v2") {
820
851
  const unsupportedModel = model;
@@ -826,10 +857,10 @@ function resolveTranscriptionModel(model) {
826
857
  }
827
858
  return asTranscriptionModelV3(model);
828
859
  }
829
- return (_b = (_a22 = getGlobalProvider()).transcriptionModel) == null ? void 0 : _b.call(_a22, model);
860
+ return (_b = (_a23 = getGlobalProvider()).transcriptionModel) == null ? void 0 : _b.call(_a23, model);
830
861
  }
831
862
  function resolveSpeechModel(model) {
832
- var _a22, _b;
863
+ var _a23, _b;
833
864
  if (typeof model !== "string") {
834
865
  if (model.specificationVersion !== "v3" && model.specificationVersion !== "v2") {
835
866
  const unsupportedModel = model;
@@ -841,7 +872,7 @@ function resolveSpeechModel(model) {
841
872
  }
842
873
  return asSpeechModelV3(model);
843
874
  }
844
- return (_b = (_a22 = getGlobalProvider()).speechModel) == null ? void 0 : _b.call(_a22, model);
875
+ return (_b = (_a23 = getGlobalProvider()).speechModel) == null ? void 0 : _b.call(_a23, model);
845
876
  }
846
877
  function resolveImageModel(model) {
847
878
  if (typeof model !== "string") {
@@ -900,8 +931,8 @@ function resolveRerankingModel(model) {
900
931
  return model;
901
932
  }
902
933
  function getGlobalProvider() {
903
- var _a22;
904
- return (_a22 = globalThis.AI_SDK_DEFAULT_PROVIDER) != null ? _a22 : gateway;
934
+ var _a23;
935
+ return (_a23 = globalThis.AI_SDK_DEFAULT_PROVIDER) != null ? _a23 : gateway;
905
936
  }
906
937
 
907
938
  // src/prompt/call-settings.ts
@@ -1193,7 +1224,7 @@ import {
1193
1224
  } from "@ai-sdk/provider-utils";
1194
1225
 
1195
1226
  // src/version.ts
1196
- var VERSION = true ? "6.0.271" : "0.0.0-test";
1227
+ var VERSION = true ? "6.0.272" : "0.0.0-test";
1197
1228
 
1198
1229
  // src/util/download/download.ts
1199
1230
  var download = async ({
@@ -1201,7 +1232,7 @@ var download = async ({
1201
1232
  maxBytes,
1202
1233
  abortSignal
1203
1234
  }) => {
1204
- var _a22;
1235
+ var _a23;
1205
1236
  const urlText = url.toString();
1206
1237
  try {
1207
1238
  const headers = withUserAgentSuffix(
@@ -1229,7 +1260,7 @@ var download = async ({
1229
1260
  });
1230
1261
  return {
1231
1262
  data,
1232
- mediaType: (_a22 = response.headers.get("content-type")) != null ? _a22 : void 0
1263
+ mediaType: (_a23 = response.headers.get("content-type")) != null ? _a23 : void 0
1233
1264
  };
1234
1265
  } catch (error) {
1235
1266
  if (DownloadError2.isInstance(error)) {
@@ -1283,7 +1314,7 @@ function mergeObjects(base, overrides) {
1283
1314
  }
1284
1315
 
1285
1316
  // src/prompt/data-content.ts
1286
- import { AISDKError as AISDKError23 } from "@ai-sdk/provider";
1317
+ import { AISDKError as AISDKError24 } from "@ai-sdk/provider";
1287
1318
  import {
1288
1319
  convertBase64ToUint8Array as convertBase64ToUint8Array2,
1289
1320
  convertUint8ArrayToBase64
@@ -1314,8 +1345,8 @@ var dataContentSchema = z.union([
1314
1345
  z.custom(
1315
1346
  // Buffer might not be available in some environments such as CloudFlare:
1316
1347
  (value) => {
1317
- var _a22, _b;
1318
- return (_b = (_a22 = globalThis.Buffer) == null ? void 0 : _a22.isBuffer(value)) != null ? _b : false;
1348
+ var _a23, _b;
1349
+ return (_b = (_a23 = globalThis.Buffer) == null ? void 0 : _a23.isBuffer(value)) != null ? _b : false;
1319
1350
  },
1320
1351
  { message: "Must be a Buffer" }
1321
1352
  )
@@ -1338,7 +1369,7 @@ function convertToLanguageModelV3DataContent(content) {
1338
1369
  content.toString()
1339
1370
  );
1340
1371
  if (dataUrlMediaType == null || base64Content == null) {
1341
- throw new AISDKError23({
1372
+ throw new AISDKError24({
1342
1373
  name: "InvalidDataContentError",
1343
1374
  message: `Invalid data URL format in content ${content.toString()}`
1344
1375
  });
@@ -1629,7 +1660,7 @@ function convertToLanguageModelMessage({
1629
1660
  }
1630
1661
  }
1631
1662
  async function downloadAssets(messages, download2, supportedUrls) {
1632
- var _a22;
1663
+ var _a23;
1633
1664
  const downloadableFiles = [];
1634
1665
  for (const message of messages) {
1635
1666
  if (message.role === "user" && Array.isArray(message.content)) {
@@ -1637,7 +1668,7 @@ async function downloadAssets(messages, download2, supportedUrls) {
1637
1668
  if (part.type === "image" || part.type === "file") {
1638
1669
  downloadableFiles.push({
1639
1670
  data: part.type === "image" ? part.image : part.data,
1640
- mediaType: (_a22 = part.mediaType) != null ? _a22 : part.type === "image" ? "image/*" : void 0
1671
+ mediaType: (_a23 = part.mediaType) != null ? _a23 : part.type === "image" ? "image/*" : void 0
1641
1672
  });
1642
1673
  }
1643
1674
  }
@@ -1689,7 +1720,7 @@ async function downloadAssets(messages, download2, supportedUrls) {
1689
1720
  );
1690
1721
  }
1691
1722
  function convertPartToLanguageModelPart(part, downloadedAssets) {
1692
- var _a22;
1723
+ var _a23;
1693
1724
  if (part.type === "text") {
1694
1725
  return {
1695
1726
  type: "text",
@@ -1722,7 +1753,7 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
1722
1753
  switch (type) {
1723
1754
  case "image": {
1724
1755
  if (data instanceof Uint8Array || typeof data === "string") {
1725
- mediaType = (_a22 = detectMediaType({ data, signatures: imageMediaTypeSignatures })) != null ? _a22 : mediaType;
1756
+ mediaType = (_a23 = detectMediaType({ data, signatures: imageMediaTypeSignatures })) != null ? _a23 : mediaType;
1726
1757
  }
1727
1758
  return {
1728
1759
  type: "file",
@@ -1757,14 +1788,14 @@ function mapToolResultOutput({
1757
1788
  return {
1758
1789
  type: "content",
1759
1790
  value: output.value.map((item) => {
1760
- var _a22, _b;
1791
+ var _a23, _b;
1761
1792
  if (item.type === "image-url") {
1762
1793
  const downloadedFile = downloadedAssets[new URL(item.url).toString()];
1763
1794
  if (downloadedFile) {
1764
1795
  return {
1765
1796
  type: "image-data",
1766
1797
  data: convertDataContentToBase64String(downloadedFile.data),
1767
- mediaType: (_a22 = downloadedFile.mediaType) != null ? _a22 : "image/*",
1798
+ mediaType: (_a23 = downloadedFile.mediaType) != null ? _a23 : "image/*",
1768
1799
  providerOptions: item.providerOptions
1769
1800
  };
1770
1801
  }
@@ -1938,10 +1969,10 @@ async function prepareToolsAndToolChoice({
1938
1969
  };
1939
1970
  }
1940
1971
  const filteredTools = activeTools != null ? Object.entries(tools).filter(
1941
- ([name22]) => activeTools.includes(name22)
1972
+ ([name23]) => activeTools.includes(name23)
1942
1973
  ) : Object.entries(tools);
1943
1974
  const languageModelTools = [];
1944
- for (const [name22, tool2] of filteredTools) {
1975
+ for (const [name23, tool2] of filteredTools) {
1945
1976
  const toolType = tool2.type;
1946
1977
  switch (toolType) {
1947
1978
  case void 0:
@@ -1949,7 +1980,7 @@ async function prepareToolsAndToolChoice({
1949
1980
  case "function":
1950
1981
  languageModelTools.push({
1951
1982
  type: "function",
1952
- name: name22,
1983
+ name: name23,
1953
1984
  description: tool2.description,
1954
1985
  inputSchema: await asSchema(tool2.inputSchema).jsonSchema,
1955
1986
  ...tool2.inputExamples != null ? { inputExamples: tool2.inputExamples } : {},
@@ -1960,7 +1991,7 @@ async function prepareToolsAndToolChoice({
1960
1991
  case "provider":
1961
1992
  languageModelTools.push({
1962
1993
  type: "provider",
1963
- name: name22,
1994
+ name: name23,
1964
1995
  id: tool2.id,
1965
1996
  args: tool2.args
1966
1997
  });
@@ -2260,14 +2291,14 @@ async function standardizePrompt({
2260
2291
 
2261
2292
  // src/prompt/wrap-gateway-error.ts
2262
2293
  import { GatewayAuthenticationError } from "@ai-sdk/gateway";
2263
- import { AISDKError as AISDKError24 } from "@ai-sdk/provider";
2294
+ import { AISDKError as AISDKError25 } from "@ai-sdk/provider";
2264
2295
  function wrapGatewayError(error) {
2265
2296
  if (!GatewayAuthenticationError.isInstance(error))
2266
2297
  return error;
2267
2298
  const isProductionEnv = (process == null ? void 0 : process.env.NODE_ENV) === "production";
2268
2299
  const moreInfoURL = "https://ai-sdk.dev/unauthenticated-ai-gateway";
2269
2300
  if (isProductionEnv) {
2270
- return new AISDKError24({
2301
+ return new AISDKError25({
2271
2302
  name: "GatewayError",
2272
2303
  message: `Unauthenticated. Configure AI_GATEWAY_API_KEY or use a provider module. Learn more: ${moreInfoURL}`
2273
2304
  });
@@ -2308,7 +2339,7 @@ function getBaseTelemetryAttributes({
2308
2339
  telemetry,
2309
2340
  headers
2310
2341
  }) {
2311
- var _a22;
2342
+ var _a23;
2312
2343
  return {
2313
2344
  "ai.model.provider": model.provider,
2314
2345
  "ai.model.id": model.modelId,
@@ -2327,7 +2358,7 @@ function getBaseTelemetryAttributes({
2327
2358
  return attributes;
2328
2359
  }, {}),
2329
2360
  // add metadata as attributes:
2330
- ...Object.entries((_a22 = telemetry == null ? void 0 : telemetry.metadata) != null ? _a22 : {}).reduce(
2361
+ ...Object.entries((_a23 = telemetry == null ? void 0 : telemetry.metadata) != null ? _a23 : {}).reduce(
2331
2362
  (attributes, [key, value]) => {
2332
2363
  attributes[`ai.telemetry.metadata.${key}`] = value;
2333
2364
  return attributes;
@@ -2352,7 +2383,7 @@ var noopTracer = {
2352
2383
  startSpan() {
2353
2384
  return noopSpan;
2354
2385
  },
2355
- startActiveSpan(name22, arg1, arg2, arg3) {
2386
+ startActiveSpan(name23, arg1, arg2, arg3) {
2356
2387
  if (typeof arg1 === "function") {
2357
2388
  return arg1(noopSpan);
2358
2389
  }
@@ -2425,7 +2456,7 @@ import {
2425
2456
  context
2426
2457
  } from "@opentelemetry/api";
2427
2458
  async function recordSpan({
2428
- name: name22,
2459
+ name: name23,
2429
2460
  tracer,
2430
2461
  attributes,
2431
2462
  fn,
@@ -2433,7 +2464,7 @@ async function recordSpan({
2433
2464
  endOnError = endWhenDone
2434
2465
  }) {
2435
2466
  return tracer.startActiveSpan(
2436
- name22,
2467
+ name23,
2437
2468
  { attributes: await attributes },
2438
2469
  async (span) => {
2439
2470
  const ctx = context.active();
@@ -2563,15 +2594,15 @@ function registerTelemetryIntegration(integration) {
2563
2594
  globalThis.AI_SDK_TELEMETRY_INTEGRATIONS.push(integration);
2564
2595
  }
2565
2596
  function getGlobalTelemetryIntegrations() {
2566
- var _a22;
2567
- return (_a22 = globalThis.AI_SDK_TELEMETRY_INTEGRATIONS) != null ? _a22 : [];
2597
+ var _a23;
2598
+ return (_a23 = globalThis.AI_SDK_TELEMETRY_INTEGRATIONS) != null ? _a23 : [];
2568
2599
  }
2569
2600
 
2570
2601
  // src/telemetry/get-global-telemetry-integration.ts
2571
2602
  function bindTelemetryIntegration(integration) {
2572
- var _a22, _b, _c, _d, _e, _f;
2603
+ var _a23, _b, _c, _d, _e, _f;
2573
2604
  return {
2574
- onStart: (_a22 = integration.onStart) == null ? void 0 : _a22.bind(integration),
2605
+ onStart: (_a23 = integration.onStart) == null ? void 0 : _a23.bind(integration),
2575
2606
  onStepStart: (_b = integration.onStepStart) == null ? void 0 : _b.bind(integration),
2576
2607
  onToolCallStart: (_c = integration.onToolCallStart) == null ? void 0 : _c.bind(integration),
2577
2608
  onToolCallFinish: (_d = integration.onToolCallFinish) == null ? void 0 : _d.bind(integration),
@@ -2655,12 +2686,12 @@ function createNullLanguageModelUsage() {
2655
2686
  };
2656
2687
  }
2657
2688
  function addLanguageModelUsage(usage1, usage2) {
2658
- var _a22, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2689
+ var _a23, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2659
2690
  return {
2660
2691
  inputTokens: addTokenCounts(usage1.inputTokens, usage2.inputTokens),
2661
2692
  inputTokenDetails: {
2662
2693
  noCacheTokens: addTokenCounts(
2663
- (_a22 = usage1.inputTokenDetails) == null ? void 0 : _a22.noCacheTokens,
2694
+ (_a23 = usage1.inputTokenDetails) == null ? void 0 : _a23.noCacheTokens,
2664
2695
  (_b = usage2.inputTokenDetails) == null ? void 0 : _b.noCacheTokens
2665
2696
  ),
2666
2697
  cacheReadTokens: addTokenCounts(
@@ -2889,8 +2920,8 @@ import { executeTool } from "@ai-sdk/provider-utils";
2889
2920
 
2890
2921
  // src/util/now.ts
2891
2922
  function now() {
2892
- var _a22, _b;
2893
- return (_b = (_a22 = globalThis == null ? void 0 : globalThis.performance) == null ? void 0 : _a22.now()) != null ? _b : Date.now();
2923
+ var _a23, _b;
2924
+ return (_b = (_a23 = globalThis == null ? void 0 : globalThis.performance) == null ? void 0 : _a23.now()) != null ? _b : Date.now();
2894
2925
  }
2895
2926
 
2896
2927
  // src/generate-text/execute-tool-call.ts
@@ -2908,7 +2939,7 @@ async function executeToolCall({
2908
2939
  onToolCallStart,
2909
2940
  onToolCallFinish
2910
2941
  }) {
2911
- var _a22;
2942
+ var _a23;
2912
2943
  const { toolName, toolCallId, input } = toolCall;
2913
2944
  const tool2 = tools == null ? void 0 : tools[toolName];
2914
2945
  if ((tool2 == null ? void 0 : tool2.execute) == null) {
@@ -2934,7 +2965,7 @@ async function executeToolCall({
2934
2965
  telemetry
2935
2966
  }),
2936
2967
  ...Object.fromEntries(
2937
- Object.entries((_a22 = telemetry == null ? void 0 : telemetry.metadata) != null ? _a22 : {}).map(([key, value]) => [
2968
+ Object.entries((_a23 = telemetry == null ? void 0 : telemetry.metadata) != null ? _a23 : {}).map(([key, value]) => [
2938
2969
  `ai.telemetry.metadata.${key}`,
2939
2970
  value
2940
2971
  ])
@@ -3063,7 +3094,7 @@ function filterActiveTools({
3063
3094
  }
3064
3095
  return Object.fromEntries(
3065
3096
  Object.entries(tools).filter(
3066
- ([name22]) => activeTools.includes(name22)
3097
+ ([name23]) => activeTools.includes(name23)
3067
3098
  )
3068
3099
  );
3069
3100
  }
@@ -3235,7 +3266,7 @@ async function validateApprovedToolApprovals({
3235
3266
  experimental_context,
3236
3267
  toolApprovalSecret
3237
3268
  }) {
3238
- var _a22;
3269
+ var _a23;
3239
3270
  const approved = [];
3240
3271
  const denied = [];
3241
3272
  const invalid = [];
@@ -3297,7 +3328,7 @@ async function validateApprovedToolApprovals({
3297
3328
  approvalResponse: {
3298
3329
  ...approval.approvalResponse,
3299
3330
  approved: false,
3300
- reason: (_a22 = approval.approvalResponse.reason) != null ? _a22 : `Tool "${toolCall.toolName}" does not require approval`
3331
+ reason: (_a23 = approval.approvalResponse.reason) != null ? _a23 : `Tool "${toolCall.toolName}" does not require approval`
3301
3332
  }
3302
3333
  });
3303
3334
  }
@@ -3700,7 +3731,7 @@ var text = () => ({
3700
3731
  });
3701
3732
  var object = ({
3702
3733
  schema: inputSchema,
3703
- name: name22,
3734
+ name: name23,
3704
3735
  description
3705
3736
  }) => {
3706
3737
  const schema = asSchema3(inputSchema);
@@ -3709,7 +3740,7 @@ var object = ({
3709
3740
  responseFormat: resolve(schema.jsonSchema).then((jsonSchema2) => ({
3710
3741
  type: "json",
3711
3742
  schema: jsonSchema2,
3712
- ...name22 != null && { name: name22 },
3743
+ ...name23 != null && { name: name23 },
3713
3744
  ...description != null && { description }
3714
3745
  })),
3715
3746
  async parseCompleteOutput({ text: text2 }, context2) {
@@ -3763,7 +3794,7 @@ var object = ({
3763
3794
  };
3764
3795
  var array = ({
3765
3796
  element: inputElementSchema,
3766
- name: name22,
3797
+ name: name23,
3767
3798
  description
3768
3799
  }) => {
3769
3800
  const elementSchema = asSchema3(inputElementSchema);
@@ -3783,7 +3814,7 @@ var array = ({
3783
3814
  required: ["elements"],
3784
3815
  additionalProperties: false
3785
3816
  },
3786
- ...name22 != null && { name: name22 },
3817
+ ...name23 != null && { name: name23 },
3787
3818
  ...description != null && { description }
3788
3819
  };
3789
3820
  }),
@@ -3877,7 +3908,7 @@ var array = ({
3877
3908
  };
3878
3909
  var choice = ({
3879
3910
  options: choiceOptions,
3880
- name: name22,
3911
+ name: name23,
3881
3912
  description
3882
3913
  }) => {
3883
3914
  return {
@@ -3894,7 +3925,7 @@ var choice = ({
3894
3925
  required: ["result"],
3895
3926
  additionalProperties: false
3896
3927
  },
3897
- ...name22 != null && { name: name22 },
3928
+ ...name23 != null && { name: name23 },
3898
3929
  ...description != null && { description }
3899
3930
  }),
3900
3931
  async parseCompleteOutput({ text: text2 }, context2) {
@@ -3955,14 +3986,14 @@ var choice = ({
3955
3986
  };
3956
3987
  };
3957
3988
  var json = ({
3958
- name: name22,
3989
+ name: name23,
3959
3990
  description
3960
3991
  } = {}) => {
3961
3992
  return {
3962
3993
  name: "json",
3963
3994
  responseFormat: Promise.resolve({
3964
3995
  type: "json",
3965
- ...name22 != null && { name: name22 },
3996
+ ...name23 != null && { name: name23 },
3966
3997
  ...description != null && { description }
3967
3998
  }),
3968
3999
  async parseCompleteOutput({ text: text2 }, context2) {
@@ -4137,9 +4168,9 @@ function prepareStepCallSettings({
4137
4168
  callSettings,
4138
4169
  stepSettings
4139
4170
  }) {
4140
- var _a22, _b, _c, _d, _e, _f, _g, _h;
4171
+ var _a23, _b, _c, _d, _e, _f, _g, _h;
4141
4172
  return prepareCallSettings({
4142
- maxOutputTokens: (_a22 = stepSettings == null ? void 0 : stepSettings.maxOutputTokens) != null ? _a22 : callSettings.maxOutputTokens,
4173
+ maxOutputTokens: (_a23 = stepSettings == null ? void 0 : stepSettings.maxOutputTokens) != null ? _a23 : callSettings.maxOutputTokens,
4143
4174
  temperature: (_b = stepSettings == null ? void 0 : stepSettings.temperature) != null ? _b : callSettings.temperature,
4144
4175
  topP: (_c = stepSettings == null ? void 0 : stepSettings.topP) != null ? _c : callSettings.topP,
4145
4176
  topK: (_d = stepSettings == null ? void 0 : stepSettings.topK) != null ? _d : callSettings.topK,
@@ -4233,8 +4264,8 @@ function isLoopFinished() {
4233
4264
  }
4234
4265
  function hasToolCall(toolName) {
4235
4266
  return ({ steps }) => {
4236
- var _a22, _b, _c;
4237
- return (_c = (_b = (_a22 = steps[steps.length - 1]) == null ? void 0 : _a22.toolCalls) == null ? void 0 : _b.some(
4267
+ var _a23, _b, _c;
4268
+ return (_c = (_b = (_a23 = steps[steps.length - 1]) == null ? void 0 : _a23.toolCalls) == null ? void 0 : _b.some(
4238
4269
  (toolCall) => toolCall.toolName === toolName
4239
4270
  )) != null ? _c : false;
4240
4271
  };
@@ -4564,7 +4595,7 @@ async function generateText({
4564
4595
  }),
4565
4596
  tracer,
4566
4597
  fn: async (span) => {
4567
- var _a22, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
4598
+ var _a23, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
4568
4599
  const initialMessages = initialPrompt.messages;
4569
4600
  const responseMessages = [];
4570
4601
  const {
@@ -4689,7 +4720,7 @@ async function generateText({
4689
4720
  experimental_context
4690
4721
  }));
4691
4722
  const stepModel = resolveLanguageModel(
4692
- (_a22 = prepareStepResult == null ? void 0 : prepareStepResult.model) != null ? _a22 : model
4723
+ (_a23 = prepareStepResult == null ? void 0 : prepareStepResult.model) != null ? _a23 : model
4693
4724
  );
4694
4725
  const stepModelInfo = {
4695
4726
  provider: stepModel.provider,
@@ -4789,7 +4820,7 @@ async function generateText({
4789
4820
  }),
4790
4821
  tracer,
4791
4822
  fn: async (span2) => {
4792
- var _a23, _b2, _c2, _d2, _e2, _f2, _g2, _h2;
4823
+ var _a24, _b2, _c2, _d2, _e2, _f2, _g2, _h2;
4793
4824
  const result = await stepModel.doGenerate({
4794
4825
  ...stepCallSettings,
4795
4826
  tools: stepTools,
@@ -4801,7 +4832,7 @@ async function generateText({
4801
4832
  headers: headersWithUserAgent
4802
4833
  });
4803
4834
  const responseData = {
4804
- id: (_b2 = (_a23 = result.response) == null ? void 0 : _a23.id) != null ? _b2 : generateId2(),
4835
+ id: (_b2 = (_a24 = result.response) == null ? void 0 : _a24.id) != null ? _b2 : generateId2(),
4805
4836
  timestamp: (_d2 = (_c2 = result.response) == null ? void 0 : _c2.timestamp) != null ? _d2 : /* @__PURE__ */ new Date(),
4806
4837
  modelId: (_f2 = (_e2 = result.response) == null ? void 0 : _e2.modelId) != null ? _f2 : stepModel.modelId,
4807
4838
  headers: (_g2 = result.response) == null ? void 0 : _g2.headers,
@@ -4869,6 +4900,18 @@ async function generateText({
4869
4900
  })
4870
4901
  )
4871
4902
  );
4903
+ const enforcedToolChoice = (stepToolChoice == null ? void 0 : stepToolChoice.type) === "required" || (stepToolChoice == null ? void 0 : stepToolChoice.type) === "tool" ? stepToolChoice : void 0;
4904
+ if (enforcedToolChoice != null && !stepToolCalls.some(
4905
+ (toolCall) => enforcedToolChoice.type === "required" || toolCall.toolName === enforcedToolChoice.toolName
4906
+ )) {
4907
+ throw new ToolChoiceViolationError({
4908
+ toolChoice: enforcedToolChoice,
4909
+ finishReason: currentModelResponse.finishReason.unified,
4910
+ provider: stepModel.provider,
4911
+ modelId: stepModel.modelId,
4912
+ content: currentModelResponse.content
4913
+ });
4914
+ }
4872
4915
  const toolApprovalRequests = {};
4873
4916
  for (const toolCall of stepToolCalls) {
4874
4917
  if (toolCall.invalid) {
@@ -5793,7 +5836,7 @@ function processUIMessageStream({
5793
5836
  new TransformStream({
5794
5837
  async transform(chunk, controller) {
5795
5838
  await runUpdateMessageJob(async ({ state, write }) => {
5796
- var _a22, _b, _c, _d;
5839
+ var _a23, _b, _c, _d;
5797
5840
  function getCurrentStepParts() {
5798
5841
  const parts = state.message.parts;
5799
5842
  let currentStepStartIndex = parts.length - 1;
@@ -5830,7 +5873,7 @@ function processUIMessageStream({
5830
5873
  return toolInvocation;
5831
5874
  }
5832
5875
  function updateToolPart(options, existingPart) {
5833
- var _a23;
5876
+ var _a24;
5834
5877
  const part = existingPart != null ? existingPart : getCurrentStepParts().find(
5835
5878
  (part2) => isStaticToolUIPart(part2) && part2.toolCallId === options.toolCallId
5836
5879
  );
@@ -5849,7 +5892,7 @@ function processUIMessageStream({
5849
5892
  if (options.toolMetadata !== void 0) {
5850
5893
  anyPart.toolMetadata = options.toolMetadata;
5851
5894
  }
5852
- anyPart.providerExecuted = (_a23 = anyOptions.providerExecuted) != null ? _a23 : part.providerExecuted;
5895
+ anyPart.providerExecuted = (_a24 = anyOptions.providerExecuted) != null ? _a24 : part.providerExecuted;
5853
5896
  const providerMetadata = anyOptions.providerMetadata;
5854
5897
  if (providerMetadata != null) {
5855
5898
  if (options.state === "output-available" || options.state === "output-error") {
@@ -5878,7 +5921,7 @@ function processUIMessageStream({
5878
5921
  }
5879
5922
  }
5880
5923
  function updateDynamicToolPart(options, existingPart) {
5881
- var _a23, _b2;
5924
+ var _a24, _b2;
5882
5925
  const part = existingPart != null ? existingPart : getCurrentStepParts().find(
5883
5926
  (part2) => part2.type === "dynamic-tool" && part2.toolCallId === options.toolCallId
5884
5927
  );
@@ -5890,7 +5933,7 @@ function processUIMessageStream({
5890
5933
  anyPart.input = anyOptions.input;
5891
5934
  anyPart.output = anyOptions.output;
5892
5935
  anyPart.errorText = anyOptions.errorText;
5893
- anyPart.rawInput = (_a23 = anyOptions.rawInput) != null ? _a23 : anyPart.rawInput;
5936
+ anyPart.rawInput = (_a24 = anyOptions.rawInput) != null ? _a24 : anyPart.rawInput;
5894
5937
  anyPart.preliminary = anyOptions.preliminary;
5895
5938
  if (options.title !== void 0) {
5896
5939
  anyPart.title = options.title;
@@ -5965,7 +6008,7 @@ function processUIMessageStream({
5965
6008
  });
5966
6009
  }
5967
6010
  textPart.text += chunk.delta;
5968
- textPart.providerMetadata = (_a22 = chunk.providerMetadata) != null ? _a22 : textPart.providerMetadata;
6011
+ textPart.providerMetadata = (_a23 = chunk.providerMetadata) != null ? _a23 : textPart.providerMetadata;
5969
6012
  write();
5970
6013
  break;
5971
6014
  }
@@ -6432,13 +6475,13 @@ function handleUIMessageStreamFinish({
6432
6475
  };
6433
6476
  let finishCalled = false;
6434
6477
  const callOnFinish = async () => {
6435
- var _a22;
6478
+ var _a23;
6436
6479
  if (finishCalled || !onFinish) {
6437
6480
  return;
6438
6481
  }
6439
6482
  finishCalled = true;
6440
6483
  const isContinuation = state.message.id === (lastMessage == null ? void 0 : lastMessage.id);
6441
- const declaredOutcome = (_a22 = getOutcome == null ? void 0 : getOutcome()) != null ? _a22 : { status: "unknown" };
6484
+ const declaredOutcome = (_a23 = getOutcome == null ? void 0 : getOutcome()) != null ? _a23 : { status: "unknown" };
6442
6485
  const outcome = hasProcessingFailure ? { status: "failed", error: processingError } : declaredOutcome.status === "unknown" && isAborted ? { status: "aborted" } : declaredOutcome;
6443
6486
  await onFinish({
6444
6487
  isAborted: isAborted || outcome.status === "aborted",
@@ -6532,13 +6575,13 @@ function createAsyncIterableStream(source) {
6532
6575
  const reader = this.getReader();
6533
6576
  let finished = false;
6534
6577
  async function cleanup(cancelStream) {
6535
- var _a22;
6578
+ var _a23;
6536
6579
  if (finished)
6537
6580
  return;
6538
6581
  finished = true;
6539
6582
  try {
6540
6583
  if (cancelStream) {
6541
- await ((_a22 = reader.cancel) == null ? void 0 : _a22.call(reader));
6584
+ await ((_a23 = reader.cancel) == null ? void 0 : _a23.call(reader));
6542
6585
  }
6543
6586
  } finally {
6544
6587
  try {
@@ -6653,7 +6696,7 @@ function createStitchableStream() {
6653
6696
  controller == null ? void 0 : controller.close();
6654
6697
  };
6655
6698
  const processPull = async () => {
6656
- var _a22;
6699
+ var _a23;
6657
6700
  if (isCancelled) {
6658
6701
  return;
6659
6702
  }
@@ -6686,7 +6729,7 @@ function createStitchableStream() {
6686
6729
  if (isCancelled) {
6687
6730
  return;
6688
6731
  }
6689
- (_a22 = currentStream.onError) == null ? void 0 : _a22.call(currentStream, error);
6732
+ (_a23 = currentStream.onError) == null ? void 0 : _a23.call(currentStream, error);
6690
6733
  controller == null ? void 0 : controller.error(error);
6691
6734
  innerStreams.shift();
6692
6735
  terminate();
@@ -6710,9 +6753,9 @@ function createStitchableStream() {
6710
6753
  }
6711
6754
  }),
6712
6755
  addStream: (innerStream, callbacks) => {
6713
- var _a22;
6756
+ var _a23;
6714
6757
  if (isCancelled) {
6715
- (_a22 = callbacks == null ? void 0 : callbacks.onCancel) == null ? void 0 : _a22.call(callbacks);
6758
+ (_a23 = callbacks == null ? void 0 : callbacks.onCancel) == null ? void 0 : _a23.call(callbacks);
6716
6759
  void innerStream.cancel().catch(() => {
6717
6760
  });
6718
6761
  return;
@@ -7193,7 +7236,7 @@ function createOutputTransformStream(output) {
7193
7236
  }
7194
7237
  return new TransformStream({
7195
7238
  async transform(chunk, controller) {
7196
- var _a22;
7239
+ var _a23;
7197
7240
  if (chunk.type === "finish-step" && textChunk.length > 0) {
7198
7241
  publishTextChunk({ controller });
7199
7242
  }
@@ -7220,7 +7263,7 @@ function createOutputTransformStream(output) {
7220
7263
  }
7221
7264
  text2 += chunk.text;
7222
7265
  textChunk += chunk.text;
7223
- textProviderMetadata = (_a22 = chunk.providerMetadata) != null ? _a22 : textProviderMetadata;
7266
+ textProviderMetadata = (_a23 = chunk.providerMetadata) != null ? _a23 : textProviderMetadata;
7224
7267
  if (chunk.text.length === 0 && chunk.providerMetadata != null) {
7225
7268
  controller.enqueue({ part: chunk, partialOutput: void 0 });
7226
7269
  return;
@@ -7326,7 +7369,7 @@ var DefaultStreamTextResult = class {
7326
7369
  let activeReasoningContent = createIdMap();
7327
7370
  const eventProcessor = new TransformStream({
7328
7371
  async transform(chunk, controller) {
7329
- var _a22, _b, _c, _d;
7372
+ var _a23, _b, _c, _d;
7330
7373
  controller.enqueue(chunk);
7331
7374
  const { part } = chunk;
7332
7375
  if (part.type === "text-delta" || part.type === "reasoning-delta" || part.type === "source" || part.type === "tool-call" || part.type === "tool-result" || part.type === "tool-input-start" || part.type === "tool-input-delta" || part.type === "raw") {
@@ -7366,7 +7409,7 @@ var DefaultStreamTextResult = class {
7366
7409
  return;
7367
7410
  }
7368
7411
  activeText.text += part.text;
7369
- activeText.providerMetadata = (_a22 = part.providerMetadata) != null ? _a22 : activeText.providerMetadata;
7412
+ activeText.providerMetadata = (_a23 = part.providerMetadata) != null ? _a23 : activeText.providerMetadata;
7370
7413
  }
7371
7414
  if (part.type === "text-end") {
7372
7415
  const activeText = activeTextContent[part.id];
@@ -7492,7 +7535,7 @@ var DefaultStreamTextResult = class {
7492
7535
  }
7493
7536
  },
7494
7537
  async flush(controller) {
7495
- var _a22, _b, _c, _d, _e, _f, _g;
7538
+ var _a23, _b, _c, _d, _e, _f, _g;
7496
7539
  try {
7497
7540
  if (recordedSteps.length === 0 || recordedNoOutputError != null) {
7498
7541
  const error = (abortSignal == null ? void 0 : abortSignal.aborted) ? abortSignal.reason : recordedNoOutputError != null ? recordedNoOutputError : new NoOutputGeneratedError({
@@ -7556,15 +7599,15 @@ var DefaultStreamTextResult = class {
7556
7599
  },
7557
7600
  "ai.response.toolCalls": {
7558
7601
  output: () => {
7559
- var _a23;
7560
- return ((_a23 = finalStep.toolCalls) == null ? void 0 : _a23.length) ? JSON.stringify(finalStep.toolCalls) : void 0;
7602
+ var _a24;
7603
+ return ((_a24 = finalStep.toolCalls) == null ? void 0 : _a24.length) ? JSON.stringify(finalStep.toolCalls) : void 0;
7561
7604
  }
7562
7605
  },
7563
7606
  "ai.response.providerMetadata": JSON.stringify(
7564
7607
  finalStep.providerMetadata
7565
7608
  ),
7566
7609
  "ai.usage.inputTokens": totalUsage.inputTokens,
7567
- "ai.usage.inputTokenDetails.noCacheTokens": (_a22 = totalUsage.inputTokenDetails) == null ? void 0 : _a22.noCacheTokens,
7610
+ "ai.usage.inputTokenDetails.noCacheTokens": (_a23 = totalUsage.inputTokenDetails) == null ? void 0 : _a23.noCacheTokens,
7568
7611
  "ai.usage.inputTokenDetails.cacheReadTokens": (_b = totalUsage.inputTokenDetails) == null ? void 0 : _b.cacheReadTokens,
7569
7612
  "ai.usage.inputTokenDetails.cacheWriteTokens": (_c = totalUsage.inputTokenDetails) == null ? void 0 : _c.cacheWriteTokens,
7570
7613
  "ai.usage.outputTokens": totalUsage.outputTokens,
@@ -7854,7 +7897,7 @@ var DefaultStreamTextResult = class {
7854
7897
  responseMessages,
7855
7898
  usage
7856
7899
  }) {
7857
- var _a22, _b, _c, _d, _e, _f, _g, _h, _i;
7900
+ var _a23, _b, _c, _d, _e, _f, _g, _h, _i;
7858
7901
  const includeRawChunks2 = self.includeRawChunks;
7859
7902
  const stepTimeoutId = setAbortTimeout({
7860
7903
  abortController: stepAbortController,
@@ -7905,7 +7948,7 @@ var DefaultStreamTextResult = class {
7905
7948
  experimental_context
7906
7949
  }));
7907
7950
  const stepModel = resolveLanguageModel(
7908
- (_a22 = prepareStepResult == null ? void 0 : prepareStepResult.model) != null ? _a22 : model
7951
+ (_a23 = prepareStepResult == null ? void 0 : prepareStepResult.model) != null ? _a23 : model
7909
7952
  );
7910
7953
  const stepModelInfo = {
7911
7954
  provider: stepModel.provider,
@@ -8075,7 +8118,7 @@ var DefaultStreamTextResult = class {
8075
8118
  streamWithToolResults.pipeThrough(
8076
8119
  new TransformStream({
8077
8120
  async transform(chunk, controller) {
8078
- var _a23, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2;
8121
+ var _a24, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2;
8079
8122
  resetChunkTimeout();
8080
8123
  if (chunk.type === "stream-start") {
8081
8124
  warnings = chunk.warnings;
@@ -8114,7 +8157,7 @@ var DefaultStreamTextResult = class {
8114
8157
  case "text-end": {
8115
8158
  controller.enqueue({
8116
8159
  ...chunk,
8117
- id: (_a23 = textPartIds.get(chunk.id)) != null ? _a23 : chunk.id
8160
+ id: (_a24 = textPartIds.get(chunk.id)) != null ? _a24 : chunk.id
8118
8161
  });
8119
8162
  textPartIds.delete(chunk.id);
8120
8163
  break;
@@ -8261,7 +8304,7 @@ var DefaultStreamTextResult = class {
8261
8304
  },
8262
8305
  // invoke onFinish callback and resolve toolResults promise when the stream is about to close:
8263
8306
  async flush(controller) {
8264
- var _a23, _b2, _c2, _d2, _e2, _f2, _g2;
8307
+ var _a24, _b2, _c2, _d2, _e2, _f2, _g2;
8265
8308
  if (!hasReceivedTerminalChunk && !hasReceivedOutputChunk) {
8266
8309
  controller.enqueue({
8267
8310
  type: "error",
@@ -8288,7 +8331,7 @@ var DefaultStreamTextResult = class {
8288
8331
  "ai.response.model": stepResponse.modelId,
8289
8332
  "ai.response.timestamp": stepResponse.timestamp.toISOString(),
8290
8333
  "ai.usage.inputTokens": stepUsage.inputTokens,
8291
- "ai.usage.inputTokenDetails.noCacheTokens": (_a23 = stepUsage.inputTokenDetails) == null ? void 0 : _a23.noCacheTokens,
8334
+ "ai.usage.inputTokenDetails.noCacheTokens": (_a24 = stepUsage.inputTokenDetails) == null ? void 0 : _a24.noCacheTokens,
8292
8335
  "ai.usage.inputTokenDetails.cacheReadTokens": (_b2 = stepUsage.inputTokenDetails) == null ? void 0 : _b2.cacheReadTokens,
8293
8336
  "ai.usage.inputTokenDetails.cacheWriteTokens": (_c2 = stepUsage.inputTokenDetails) == null ? void 0 : _c2.cacheWriteTokens,
8294
8337
  "ai.usage.outputTokens": stepUsage.outputTokens,
@@ -8565,19 +8608,19 @@ var DefaultStreamTextResult = class {
8565
8608
  this._steps.reject(error);
8566
8609
  }
8567
8610
  async consumeStream(options) {
8568
- var _a22;
8611
+ var _a23;
8569
8612
  try {
8570
8613
  await consumeStream({
8571
8614
  stream: this.fullStream,
8572
8615
  onError: (error) => {
8573
- var _a23;
8616
+ var _a24;
8574
8617
  this.rejectResultPromises(error);
8575
- (_a23 = options == null ? void 0 : options.onError) == null ? void 0 : _a23.call(options, error);
8618
+ (_a24 = options == null ? void 0 : options.onError) == null ? void 0 : _a24.call(options, error);
8576
8619
  }
8577
8620
  });
8578
8621
  } catch (error) {
8579
8622
  this.rejectResultPromises(error);
8580
- (_a22 = options == null ? void 0 : options.onError) == null ? void 0 : _a22.call(options, error);
8623
+ (_a23 = options == null ? void 0 : options.onError) == null ? void 0 : _a23.call(options, error);
8581
8624
  }
8582
8625
  }
8583
8626
  get experimental_partialOutputStream() {
@@ -8597,8 +8640,8 @@ var DefaultStreamTextResult = class {
8597
8640
  );
8598
8641
  }
8599
8642
  get elementStream() {
8600
- var _a22, _b, _c;
8601
- const transform = (_a22 = this.outputSpecification) == null ? void 0 : _a22.createElementStreamTransform();
8643
+ var _a23, _b, _c;
8644
+ const transform = (_a23 = this.outputSpecification) == null ? void 0 : _a23.createElementStreamTransform();
8602
8645
  if (transform == null) {
8603
8646
  throw new UnsupportedFunctionalityError2({
8604
8647
  functionality: `element streams in ${(_c = (_b = this.outputSpecification) == null ? void 0 : _b.name) != null ? _c : "text"} mode`
@@ -8608,8 +8651,8 @@ var DefaultStreamTextResult = class {
8608
8651
  }
8609
8652
  get output() {
8610
8653
  return this.finalStep.then((step) => {
8611
- var _a22;
8612
- const output = (_a22 = this.outputSpecification) != null ? _a22 : text();
8654
+ var _a23;
8655
+ const output = (_a23 = this.outputSpecification) != null ? _a23 : text();
8613
8656
  return output.parseCompleteOutput(
8614
8657
  { text: step.text },
8615
8658
  {
@@ -8648,8 +8691,8 @@ var DefaultStreamTextResult = class {
8648
8691
  responseMessageId: generateMessageId
8649
8692
  }) : void 0;
8650
8693
  const isDynamic = (part) => {
8651
- var _a22;
8652
- const tool2 = (_a22 = this.tools) == null ? void 0 : _a22[part.toolName];
8694
+ var _a23;
8695
+ const tool2 = (_a23 = this.tools) == null ? void 0 : _a23[part.toolName];
8653
8696
  if (tool2 == null) {
8654
8697
  return part.dynamic;
8655
8698
  }
@@ -9047,7 +9090,7 @@ var ToolLoopAgent = class {
9047
9090
  return this.settings.tools;
9048
9091
  }
9049
9092
  async prepareCall(options) {
9050
- var _a22, _b, _c, _d;
9093
+ var _a23, _b, _c, _d;
9051
9094
  if (this.settings.callOptionsSchema != null && options.options !== void 0) {
9052
9095
  const validatedOptions = await validateTypes2({
9053
9096
  value: options.options,
@@ -9059,7 +9102,7 @@ var ToolLoopAgent = class {
9059
9102
  const { onStepFinish: _settingsOnStepFinish, ...settingsWithoutCallback } = this.settings;
9060
9103
  const baseCallArgs = {
9061
9104
  ...settingsWithoutCallback,
9062
- stopWhen: (_a22 = this.settings.stopWhen) != null ? _a22 : stepCountIs(20),
9105
+ stopWhen: (_a23 = this.settings.stopWhen) != null ? _a23 : stepCountIs(20),
9063
9106
  ...options
9064
9107
  };
9065
9108
  const preparedCallArgs = (_d = await ((_c = (_b = this.settings).prepareCall) == null ? void 0 : _c.call(
@@ -9273,7 +9316,7 @@ function readUIMessageStream({
9273
9316
  onError,
9274
9317
  terminateOnError = false
9275
9318
  }) {
9276
- var _a22;
9319
+ var _a23;
9277
9320
  let controller;
9278
9321
  let hasErrored = false;
9279
9322
  const outputStream = new ReadableStream({
@@ -9282,7 +9325,7 @@ function readUIMessageStream({
9282
9325
  }
9283
9326
  });
9284
9327
  const state = createStreamingUIMessageState({
9285
- messageId: (_a22 = message == null ? void 0 : message.id) != null ? _a22 : "",
9328
+ messageId: (_a23 = message == null ? void 0 : message.id) != null ? _a23 : "",
9286
9329
  lastMessage: message
9287
9330
  });
9288
9331
  const handleError = (error) => {
@@ -9351,7 +9394,7 @@ async function convertToModelMessages(messages, options) {
9351
9394
  modelMessages.push({
9352
9395
  role: "user",
9353
9396
  content: message.parts.map((part) => {
9354
- var _a22;
9397
+ var _a23;
9355
9398
  if (isTextUIPart(part)) {
9356
9399
  return {
9357
9400
  type: "text",
@@ -9369,7 +9412,7 @@ async function convertToModelMessages(messages, options) {
9369
9412
  };
9370
9413
  }
9371
9414
  if (isDataUIPart(part)) {
9372
- return (_a22 = options == null ? void 0 : options.convertDataPart) == null ? void 0 : _a22.call(
9415
+ return (_a23 = options == null ? void 0 : options.convertDataPart) == null ? void 0 : _a23.call(
9373
9416
  options,
9374
9417
  part
9375
9418
  );
@@ -9382,7 +9425,7 @@ async function convertToModelMessages(messages, options) {
9382
9425
  if (message.parts != null) {
9383
9426
  let block = [];
9384
9427
  async function processBlock() {
9385
- var _a22, _b, _c, _d, _e, _f, _g, _h;
9428
+ var _a23, _b, _c, _d, _e, _f, _g, _h;
9386
9429
  if (block.length === 0) {
9387
9430
  return;
9388
9431
  }
@@ -9415,7 +9458,7 @@ async function convertToModelMessages(messages, options) {
9415
9458
  type: "tool-call",
9416
9459
  toolCallId: part.toolCallId,
9417
9460
  toolName,
9418
- input: part.state === "output-error" ? (_a22 = part.input) != null ? _a22 : "rawInput" in part ? part.rawInput : void 0 : part.input,
9461
+ input: part.state === "output-error" ? (_a23 = part.input) != null ? _a23 : "rawInput" in part ? part.rawInput : void 0 : part.input,
9419
9462
  providerExecuted: part.providerExecuted,
9420
9463
  ...part.callProviderMetadata != null ? { providerOptions: part.callProviderMetadata } : {}
9421
9464
  });
@@ -9465,8 +9508,8 @@ async function convertToModelMessages(messages, options) {
9465
9508
  }
9466
9509
  const toolParts = block.filter(
9467
9510
  (part) => {
9468
- var _a23;
9469
- return isToolUIPart(part) && (part.providerExecuted !== true || ((_a23 = part.approval) == null ? void 0 : _a23.approved) != null);
9511
+ var _a24;
9512
+ return isToolUIPart(part) && (part.providerExecuted !== true || ((_a24 = part.approval) == null ? void 0 : _a24.approved) != null);
9470
9513
  }
9471
9514
  );
9472
9515
  if (toolParts.length > 0) {
@@ -10077,7 +10120,7 @@ async function createAgentUIStream({
10077
10120
  onStepFinish,
10078
10121
  ...uiMessageStreamOptions
10079
10122
  }) {
10080
- var _a22;
10123
+ var _a23;
10081
10124
  const validatedMessages = await validateUIMessagesForAgent({
10082
10125
  messages: uiMessages,
10083
10126
  tools: agent.tools
@@ -10096,7 +10139,7 @@ async function createAgentUIStream({
10096
10139
  return result.toUIMessageStream({
10097
10140
  ...uiMessageStreamOptions,
10098
10141
  // TODO reading `originalMessages` is here for bc, always use `validatedMessages` in v7
10099
- originalMessages: (_a22 = uiMessageStreamOptions.originalMessages) != null ? _a22 : validatedMessages
10142
+ originalMessages: (_a23 = uiMessageStreamOptions.originalMessages) != null ? _a23 : validatedMessages
10100
10143
  });
10101
10144
  }
10102
10145
 
@@ -10196,7 +10239,7 @@ async function embed({
10196
10239
  }),
10197
10240
  tracer,
10198
10241
  fn: async (doEmbedSpan) => {
10199
- var _a22, _b;
10242
+ var _a23, _b;
10200
10243
  const modelResponse = await model.doEmbed({
10201
10244
  values: [value],
10202
10245
  abortSignal,
@@ -10204,7 +10247,7 @@ async function embed({
10204
10247
  providerOptions
10205
10248
  });
10206
10249
  const embedding2 = modelResponse.embeddings[0];
10207
- const usage2 = (_a22 = modelResponse.usage) != null ? _a22 : { tokens: NaN };
10250
+ const usage2 = (_a23 = modelResponse.usage) != null ? _a23 : { tokens: NaN };
10208
10251
  doEmbedSpan.setAttributes(
10209
10252
  await selectTelemetryAttributes({
10210
10253
  telemetry,
@@ -10326,7 +10369,7 @@ async function embedMany({
10326
10369
  }),
10327
10370
  tracer,
10328
10371
  fn: async (span) => {
10329
- var _a22;
10372
+ var _a23;
10330
10373
  const [
10331
10374
  maxEmbeddingsPerCall,
10332
10375
  maxInputBytesPerCall,
@@ -10358,7 +10401,7 @@ async function embedMany({
10358
10401
  }),
10359
10402
  tracer,
10360
10403
  fn: async (doEmbedSpan) => {
10361
- var _a23, _b;
10404
+ var _a24, _b;
10362
10405
  const modelResponse = await model.doEmbed({
10363
10406
  values,
10364
10407
  abortSignal,
@@ -10366,7 +10409,7 @@ async function embedMany({
10366
10409
  providerOptions
10367
10410
  });
10368
10411
  const embeddings3 = modelResponse.embeddings;
10369
- const usage2 = (_a23 = modelResponse.usage) != null ? _a23 : { tokens: NaN };
10412
+ const usage2 = (_a24 = modelResponse.usage) != null ? _a24 : { tokens: NaN };
10370
10413
  doEmbedSpan.setAttributes(
10371
10414
  await selectTelemetryAttributes({
10372
10415
  telemetry,
@@ -10451,7 +10494,7 @@ async function embedMany({
10451
10494
  }),
10452
10495
  tracer,
10453
10496
  fn: async (doEmbedSpan) => {
10454
- var _a23, _b;
10497
+ var _a24, _b;
10455
10498
  const modelResponse = await model.doEmbed({
10456
10499
  values: chunk,
10457
10500
  abortSignal,
@@ -10459,7 +10502,7 @@ async function embedMany({
10459
10502
  providerOptions
10460
10503
  });
10461
10504
  const embeddings2 = modelResponse.embeddings;
10462
- const usage = (_a23 = modelResponse.usage) != null ? _a23 : { tokens: NaN };
10505
+ const usage = (_a24 = modelResponse.usage) != null ? _a24 : { tokens: NaN };
10463
10506
  doEmbedSpan.setAttributes(
10464
10507
  await selectTelemetryAttributes({
10465
10508
  telemetry,
@@ -10498,7 +10541,7 @@ async function embedMany({
10498
10541
  result.providerMetadata
10499
10542
  )) {
10500
10543
  providerMetadata[providerName] = {
10501
- ...(_a22 = providerMetadata[providerName]) != null ? _a22 : {},
10544
+ ...(_a23 = providerMetadata[providerName]) != null ? _a23 : {},
10502
10545
  ...metadata
10503
10546
  };
10504
10547
  }
@@ -10593,7 +10636,7 @@ async function generateImage({
10593
10636
  abortSignal,
10594
10637
  headers
10595
10638
  }) {
10596
- var _a22, _b;
10639
+ var _a23, _b;
10597
10640
  const model = resolveImageModel(modelArg);
10598
10641
  const headersWithUserAgent = withUserAgentSuffix5(
10599
10642
  headers != null ? headers : {},
@@ -10603,7 +10646,7 @@ async function generateImage({
10603
10646
  maxRetries: maxRetriesArg,
10604
10647
  abortSignal
10605
10648
  });
10606
- const maxImagesPerCallWithDefault = (_a22 = maxImagesPerCall != null ? maxImagesPerCall : await invokeModelMaxImagesPerCall(model)) != null ? _a22 : 1;
10649
+ const maxImagesPerCallWithDefault = (_a23 = maxImagesPerCall != null ? maxImagesPerCall : await invokeModelMaxImagesPerCall(model)) != null ? _a23 : 1;
10607
10650
  const callCount = Math.ceil(n / maxImagesPerCallWithDefault);
10608
10651
  const callImageCounts = Array.from({ length: callCount }, (_, i) => {
10609
10652
  if (i < callCount - 1) {
@@ -10644,13 +10687,13 @@ async function generateImage({
10644
10687
  images.push(
10645
10688
  ...result.images.map(
10646
10689
  (image) => {
10647
- var _a23;
10690
+ var _a24;
10648
10691
  return new DefaultGeneratedFile({
10649
10692
  data: image,
10650
- mediaType: (_a23 = detectMediaType({
10693
+ mediaType: (_a24 = detectMediaType({
10651
10694
  data: image,
10652
10695
  signatures: imageMediaTypeSignatures
10653
- })) != null ? _a23 : "image/png"
10696
+ })) != null ? _a24 : "image/png"
10654
10697
  });
10655
10698
  }
10656
10699
  )
@@ -10850,7 +10893,7 @@ var arrayOutputStrategy = (schema) => {
10850
10893
  isFirstDelta,
10851
10894
  isFinalDelta
10852
10895
  }) {
10853
- var _a22;
10896
+ var _a23;
10854
10897
  if (!isJSONObject(value) || !isJSONArray(value.elements)) {
10855
10898
  return {
10856
10899
  success: false,
@@ -10873,7 +10916,7 @@ var arrayOutputStrategy = (schema) => {
10873
10916
  }
10874
10917
  resultArray.push(result.value);
10875
10918
  }
10876
- const publishedElementCount = (_a22 = latestObject == null ? void 0 : latestObject.length) != null ? _a22 : 0;
10919
+ const publishedElementCount = (_a23 = latestObject == null ? void 0 : latestObject.length) != null ? _a23 : 0;
10877
10920
  let textDelta = "";
10878
10921
  if (isFirstDelta) {
10879
10922
  textDelta += "[";
@@ -11296,7 +11339,7 @@ async function generateObject(options) {
11296
11339
  }),
11297
11340
  tracer,
11298
11341
  fn: async (span) => {
11299
- var _a22;
11342
+ var _a23;
11300
11343
  let result;
11301
11344
  let finishReason;
11302
11345
  let usage;
@@ -11343,7 +11386,7 @@ async function generateObject(options) {
11343
11386
  }),
11344
11387
  tracer,
11345
11388
  fn: async (span2) => {
11346
- var _a23, _b, _c, _d, _e, _f, _g, _h;
11389
+ var _a24, _b, _c, _d, _e, _f, _g, _h;
11347
11390
  const result2 = await model.doGenerate({
11348
11391
  responseFormat: {
11349
11392
  type: "json",
@@ -11358,7 +11401,7 @@ async function generateObject(options) {
11358
11401
  headers: headersWithUserAgent
11359
11402
  });
11360
11403
  const responseData = {
11361
- id: (_b = (_a23 = result2.response) == null ? void 0 : _a23.id) != null ? _b : generateId2(),
11404
+ id: (_b = (_a24 = result2.response) == null ? void 0 : _a24.id) != null ? _b : generateId2(),
11362
11405
  timestamp: (_d = (_c = result2.response) == null ? void 0 : _c.timestamp) != null ? _d : currentDate(),
11363
11406
  modelId: (_f = (_e = result2.response) == null ? void 0 : _e.modelId) != null ? _f : model.modelId,
11364
11407
  headers: (_g = result2.response) == null ? void 0 : _g.headers,
@@ -11414,7 +11457,7 @@ async function generateObject(options) {
11414
11457
  usage = asLanguageModelUsage(generateResult.usage);
11415
11458
  warnings = generateResult.warnings;
11416
11459
  resultProviderMetadata = generateResult.providerMetadata;
11417
- request = (_a22 = generateResult.request) != null ? _a22 : {};
11460
+ request = (_a23 = generateResult.request) != null ? _a23 : {};
11418
11461
  response = generateResult.responseData;
11419
11462
  reasoning = generateResult.reasoning;
11420
11463
  logWarnings({
@@ -11477,9 +11520,9 @@ var DefaultGenerateObjectResult = class {
11477
11520
  this.reasoning = options.reasoning;
11478
11521
  }
11479
11522
  toJsonResponse(init) {
11480
- var _a22;
11523
+ var _a23;
11481
11524
  return new Response(JSON.stringify(this.object), {
11482
- status: (_a22 = init == null ? void 0 : init.status) != null ? _a22 : 200,
11525
+ status: (_a23 = init == null ? void 0 : init.status) != null ? _a23 : 200,
11483
11526
  headers: prepareHeaders(init == null ? void 0 : init.headers, {
11484
11527
  "content-type": "application/json; charset=utf-8"
11485
11528
  })
@@ -11613,8 +11656,8 @@ function simulateReadableStream({
11613
11656
  chunkDelayInMs = 0,
11614
11657
  _internal
11615
11658
  }) {
11616
- var _a22;
11617
- const delay = (_a22 = _internal == null ? void 0 : _internal.delay) != null ? _a22 : delayFunction;
11659
+ var _a23;
11660
+ const delay = (_a23 = _internal == null ? void 0 : _internal.delay) != null ? _a23 : delayFunction;
11618
11661
  let index = 0;
11619
11662
  return new ReadableStream({
11620
11663
  async pull(controller) {
@@ -11888,7 +11931,7 @@ var DefaultStreamObjectResult = class {
11888
11931
  const transformedStream = stream.pipeThrough(new TransformStream(transformer)).pipeThrough(
11889
11932
  new TransformStream({
11890
11933
  async transform(chunk, controller) {
11891
- var _a22, _b, _c;
11934
+ var _a23, _b, _c;
11892
11935
  if (typeof chunk === "object" && chunk.type === "stream-start") {
11893
11936
  warnings = chunk.warnings;
11894
11937
  return;
@@ -11938,7 +11981,7 @@ var DefaultStreamObjectResult = class {
11938
11981
  switch (chunk.type) {
11939
11982
  case "response-metadata": {
11940
11983
  fullResponse = {
11941
- id: (_a22 = chunk.id) != null ? _a22 : fullResponse.id,
11984
+ id: (_a23 = chunk.id) != null ? _a23 : fullResponse.id,
11942
11985
  timestamp: (_b = chunk.timestamp) != null ? _b : fullResponse.timestamp,
11943
11986
  modelId: (_c = chunk.modelId) != null ? _c : fullResponse.modelId
11944
11987
  };
@@ -12254,7 +12297,7 @@ async function generateSpeech({
12254
12297
  abortSignal,
12255
12298
  headers
12256
12299
  }) {
12257
- var _a22;
12300
+ var _a23;
12258
12301
  const resolvedModel = resolveSpeechModel(model);
12259
12302
  if (!resolvedModel) {
12260
12303
  throw new Error("Model could not be resolved");
@@ -12291,10 +12334,10 @@ async function generateSpeech({
12291
12334
  return new DefaultSpeechResult({
12292
12335
  audio: new DefaultGeneratedAudioFile({
12293
12336
  data: result.audio,
12294
- mediaType: (_a22 = detectMediaType({
12337
+ mediaType: (_a23 = detectMediaType({
12295
12338
  data: result.audio,
12296
12339
  signatures: audioMediaTypeSignatures
12297
- })) != null ? _a22 : "audio/mp3"
12340
+ })) != null ? _a23 : "audio/mp3"
12298
12341
  }),
12299
12342
  warnings: result.warnings,
12300
12343
  responses: [result.response],
@@ -12303,11 +12346,11 @@ async function generateSpeech({
12303
12346
  }
12304
12347
  var DefaultSpeechResult = class {
12305
12348
  constructor(options) {
12306
- var _a22;
12349
+ var _a23;
12307
12350
  this.audio = options.audio;
12308
12351
  this.warnings = options.warnings;
12309
12352
  this.responses = options.responses;
12310
- this.providerMetadata = (_a22 = options.providerMetadata) != null ? _a22 : {};
12353
+ this.providerMetadata = (_a23 = options.providerMetadata) != null ? _a23 : {};
12311
12354
  }
12312
12355
  };
12313
12356
 
@@ -12530,7 +12573,7 @@ async function experimental_generateVideo({
12530
12573
  headers,
12531
12574
  download: downloadFn = defaultDownload
12532
12575
  }) {
12533
- var _a22, _b;
12576
+ var _a23, _b;
12534
12577
  const model = resolveVideoModel(modelArg);
12535
12578
  const headersWithUserAgent = withUserAgentSuffix8(
12536
12579
  headers != null ? headers : {},
@@ -12557,9 +12600,9 @@ async function experimental_generateVideo({
12557
12600
  message: "inputReferences were ignored because frameImages were provided; frameImages and inputReferences cannot be combined."
12558
12601
  });
12559
12602
  }
12560
- const firstFrameImage = (_a22 = normalizedFrameImages == null ? void 0 : normalizedFrameImages.find(
12603
+ const firstFrameImage = (_a23 = normalizedFrameImages == null ? void 0 : normalizedFrameImages.find(
12561
12604
  (frame) => frame.frameType === "first_frame"
12562
- )) == null ? void 0 : _a22.image;
12605
+ )) == null ? void 0 : _a23.image;
12563
12606
  if (image != null && firstFrameImage != null) {
12564
12607
  warnings.push({
12565
12608
  type: "other",
@@ -12703,8 +12746,8 @@ function normalizePrompt2(promptArg) {
12703
12746
  };
12704
12747
  }
12705
12748
  function detectFileMediaType(data, restrictToImages) {
12706
- var _a22;
12707
- const detected = restrictToImages ? detectMediaType({ data, signatures: imageMediaTypeSignatures }) : (_a22 = detectMediaType({ data, signatures: imageMediaTypeSignatures })) != null ? _a22 : detectMediaType({ data, signatures: videoMediaTypeSignatures });
12749
+ var _a23;
12750
+ const detected = restrictToImages ? detectMediaType({ data, signatures: imageMediaTypeSignatures }) : (_a23 = detectMediaType({ data, signatures: imageMediaTypeSignatures })) != null ? _a23 : detectMediaType({ data, signatures: videoMediaTypeSignatures });
12708
12751
  return detected != null ? detected : "image/png";
12709
12752
  }
12710
12753
  function normalizeImageData(dataContent, { restrictToImages = true } = {}) {
@@ -12798,8 +12841,8 @@ function stripMarkdownCodeFenceSuffix(text2) {
12798
12841
  return text2.replace(/\n?```\s*$/, "").trimEnd();
12799
12842
  }
12800
12843
  function extractJsonMiddleware(options) {
12801
- var _a22;
12802
- const transform = (_a22 = options == null ? void 0 : options.transform) != null ? _a22 : defaultTransform;
12844
+ var _a23;
12845
+ const transform = (_a23 = options == null ? void 0 : options.transform) != null ? _a23 : defaultTransform;
12803
12846
  const hasCustomTransform = (options == null ? void 0 : options.transform) !== void 0;
12804
12847
  return {
12805
12848
  specificationVersion: "v3",
@@ -13175,13 +13218,13 @@ function addToolInputExamplesMiddleware({
13175
13218
  return {
13176
13219
  specificationVersion: "v3",
13177
13220
  transformParams: async ({ params }) => {
13178
- var _a22;
13179
- if (!((_a22 = params.tools) == null ? void 0 : _a22.length)) {
13221
+ var _a23;
13222
+ if (!((_a23 = params.tools) == null ? void 0 : _a23.length)) {
13180
13223
  return params;
13181
13224
  }
13182
13225
  const transformedTools = params.tools.map((tool2) => {
13183
- var _a23;
13184
- if (tool2.type !== "function" || !((_a23 = tool2.inputExamples) == null ? void 0 : _a23.length)) {
13226
+ var _a24;
13227
+ if (tool2.type !== "function" || !((_a24 = tool2.inputExamples) == null ? void 0 : _a24.length)) {
13185
13228
  return tool2;
13186
13229
  }
13187
13230
  const formattedExamples = tool2.inputExamples.map((example, index) => format(example, index)).join("\n");
@@ -13228,7 +13271,7 @@ var doWrap = ({
13228
13271
  modelId,
13229
13272
  providerId
13230
13273
  }) => {
13231
- var _a22, _b, _c;
13274
+ var _a23, _b, _c;
13232
13275
  async function doTransform({
13233
13276
  params,
13234
13277
  type
@@ -13237,7 +13280,7 @@ var doWrap = ({
13237
13280
  }
13238
13281
  return {
13239
13282
  specificationVersion: "v3",
13240
- provider: (_a22 = providerId != null ? providerId : overrideProvider == null ? void 0 : overrideProvider({ model })) != null ? _a22 : model.provider,
13283
+ provider: (_a23 = providerId != null ? providerId : overrideProvider == null ? void 0 : overrideProvider({ model })) != null ? _a23 : model.provider,
13241
13284
  modelId: (_b = modelId != null ? modelId : overrideModelId == null ? void 0 : overrideModelId({ model })) != null ? _b : model.modelId,
13242
13285
  supportedUrls: (_c = overrideSupportedUrls == null ? void 0 : overrideSupportedUrls({ model })) != null ? _c : model.supportedUrls,
13243
13286
  async doGenerate(params) {
@@ -13285,7 +13328,7 @@ var doWrap2 = ({
13285
13328
  modelId,
13286
13329
  providerId
13287
13330
  }) => {
13288
- var _a22, _b, _c, _d;
13331
+ var _a23, _b, _c, _d;
13289
13332
  async function doTransform({
13290
13333
  params
13291
13334
  }) {
@@ -13293,7 +13336,7 @@ var doWrap2 = ({
13293
13336
  }
13294
13337
  return {
13295
13338
  specificationVersion: "v3",
13296
- provider: (_a22 = providerId != null ? providerId : overrideProvider == null ? void 0 : overrideProvider({ model })) != null ? _a22 : model.provider,
13339
+ provider: (_a23 = providerId != null ? providerId : overrideProvider == null ? void 0 : overrideProvider({ model })) != null ? _a23 : model.provider,
13297
13340
  modelId: (_b = modelId != null ? modelId : overrideModelId == null ? void 0 : overrideModelId({ model })) != null ? _b : model.modelId,
13298
13341
  maxEmbeddingsPerCall: (_c = overrideMaxEmbeddingsPerCall == null ? void 0 : overrideMaxEmbeddingsPerCall({ model })) != null ? _c : model.maxEmbeddingsPerCall,
13299
13342
  [EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL2]: getEmbeddingModelMaxInputBytesPerCall(model),
@@ -13333,11 +13376,11 @@ var doWrap3 = ({
13333
13376
  modelId,
13334
13377
  providerId
13335
13378
  }) => {
13336
- var _a22, _b, _c;
13379
+ var _a23, _b, _c;
13337
13380
  async function doTransform({ params }) {
13338
13381
  return transformParams ? await transformParams({ params, model }) : params;
13339
13382
  }
13340
- const maxImagesPerCallRaw = (_a22 = overrideMaxImagesPerCall == null ? void 0 : overrideMaxImagesPerCall({ model })) != null ? _a22 : model.maxImagesPerCall;
13383
+ const maxImagesPerCallRaw = (_a23 = overrideMaxImagesPerCall == null ? void 0 : overrideMaxImagesPerCall({ model })) != null ? _a23 : model.maxImagesPerCall;
13341
13384
  const maxImagesPerCall = maxImagesPerCallRaw instanceof Function ? maxImagesPerCallRaw.bind(model) : maxImagesPerCallRaw;
13342
13385
  return {
13343
13386
  specificationVersion: "v3",
@@ -13487,11 +13530,11 @@ function customProvider({
13487
13530
  var experimental_customProvider = customProvider;
13488
13531
 
13489
13532
  // src/registry/no-such-provider-error.ts
13490
- import { AISDKError as AISDKError25, NoSuchModelError as NoSuchModelError3 } from "@ai-sdk/provider";
13491
- var name21 = "AI_NoSuchProviderError";
13492
- var marker21 = `vercel.ai.error.${name21}`;
13493
- var symbol21 = Symbol.for(marker21);
13494
- var _a21;
13533
+ import { AISDKError as AISDKError26, NoSuchModelError as NoSuchModelError3 } from "@ai-sdk/provider";
13534
+ var name22 = "AI_NoSuchProviderError";
13535
+ var marker22 = `vercel.ai.error.${name22}`;
13536
+ var symbol22 = Symbol.for(marker22);
13537
+ var _a22;
13495
13538
  var NoSuchProviderError = class extends NoSuchModelError3 {
13496
13539
  constructor({
13497
13540
  modelId,
@@ -13500,16 +13543,16 @@ var NoSuchProviderError = class extends NoSuchModelError3 {
13500
13543
  availableProviders,
13501
13544
  message = `No such provider: ${providerId} (available providers: ${availableProviders.join()})`
13502
13545
  }) {
13503
- super({ errorName: name21, modelId, modelType, message });
13504
- this[_a21] = true;
13546
+ super({ errorName: name22, modelId, modelType, message });
13547
+ this[_a22] = true;
13505
13548
  this.providerId = providerId;
13506
13549
  this.availableProviders = availableProviders;
13507
13550
  }
13508
13551
  static isInstance(error) {
13509
- return AISDKError25.hasMarker(error, marker21);
13552
+ return AISDKError26.hasMarker(error, marker22);
13510
13553
  }
13511
13554
  };
13512
- _a21 = symbol21;
13555
+ _a22 = symbol22;
13513
13556
 
13514
13557
  // src/registry/provider-registry.ts
13515
13558
  import {
@@ -13572,10 +13615,10 @@ var DefaultProviderRegistry = class {
13572
13615
  return [id.slice(0, index), id.slice(index + this.separator.length)];
13573
13616
  }
13574
13617
  languageModel(id) {
13575
- var _a22, _b;
13618
+ var _a23, _b;
13576
13619
  const [providerId, modelId] = this.splitId(id, "languageModel");
13577
- let model = (_b = (_a22 = this.getProvider(providerId, "languageModel")).languageModel) == null ? void 0 : _b.call(
13578
- _a22,
13620
+ let model = (_b = (_a23 = this.getProvider(providerId, "languageModel")).languageModel) == null ? void 0 : _b.call(
13621
+ _a23,
13579
13622
  modelId
13580
13623
  );
13581
13624
  if (model == null) {
@@ -13590,10 +13633,10 @@ var DefaultProviderRegistry = class {
13590
13633
  return model;
13591
13634
  }
13592
13635
  embeddingModel(id) {
13593
- var _a22;
13636
+ var _a23;
13594
13637
  const [providerId, modelId] = this.splitId(id, "embeddingModel");
13595
13638
  const provider = this.getProvider(providerId, "embeddingModel");
13596
- const model = (_a22 = provider.embeddingModel) == null ? void 0 : _a22.call(provider, modelId);
13639
+ const model = (_a23 = provider.embeddingModel) == null ? void 0 : _a23.call(provider, modelId);
13597
13640
  if (model == null) {
13598
13641
  throw new NoSuchModelError4({
13599
13642
  modelId: id,
@@ -13603,10 +13646,10 @@ var DefaultProviderRegistry = class {
13603
13646
  return model;
13604
13647
  }
13605
13648
  imageModel(id) {
13606
- var _a22;
13649
+ var _a23;
13607
13650
  const [providerId, modelId] = this.splitId(id, "imageModel");
13608
13651
  const provider = this.getProvider(providerId, "imageModel");
13609
- let model = (_a22 = provider.imageModel) == null ? void 0 : _a22.call(provider, modelId);
13652
+ let model = (_a23 = provider.imageModel) == null ? void 0 : _a23.call(provider, modelId);
13610
13653
  if (model == null) {
13611
13654
  throw new NoSuchModelError4({ modelId: id, modelType: "imageModel" });
13612
13655
  }
@@ -13619,10 +13662,10 @@ var DefaultProviderRegistry = class {
13619
13662
  return model;
13620
13663
  }
13621
13664
  transcriptionModel(id) {
13622
- var _a22;
13665
+ var _a23;
13623
13666
  const [providerId, modelId] = this.splitId(id, "transcriptionModel");
13624
13667
  const provider = this.getProvider(providerId, "transcriptionModel");
13625
- const model = (_a22 = provider.transcriptionModel) == null ? void 0 : _a22.call(provider, modelId);
13668
+ const model = (_a23 = provider.transcriptionModel) == null ? void 0 : _a23.call(provider, modelId);
13626
13669
  if (model == null) {
13627
13670
  throw new NoSuchModelError4({
13628
13671
  modelId: id,
@@ -13632,20 +13675,20 @@ var DefaultProviderRegistry = class {
13632
13675
  return model;
13633
13676
  }
13634
13677
  speechModel(id) {
13635
- var _a22;
13678
+ var _a23;
13636
13679
  const [providerId, modelId] = this.splitId(id, "speechModel");
13637
13680
  const provider = this.getProvider(providerId, "speechModel");
13638
- const model = (_a22 = provider.speechModel) == null ? void 0 : _a22.call(provider, modelId);
13681
+ const model = (_a23 = provider.speechModel) == null ? void 0 : _a23.call(provider, modelId);
13639
13682
  if (model == null) {
13640
13683
  throw new NoSuchModelError4({ modelId: id, modelType: "speechModel" });
13641
13684
  }
13642
13685
  return model;
13643
13686
  }
13644
13687
  rerankingModel(id) {
13645
- var _a22;
13688
+ var _a23;
13646
13689
  const [providerId, modelId] = this.splitId(id, "rerankingModel");
13647
13690
  const provider = this.getProvider(providerId, "rerankingModel");
13648
- const model = (_a22 = provider.rerankingModel) == null ? void 0 : _a22.call(provider, modelId);
13691
+ const model = (_a23 = provider.rerankingModel) == null ? void 0 : _a23.call(provider, modelId);
13649
13692
  if (model == null) {
13650
13693
  throw new NoSuchModelError4({ modelId: id, modelType: "rerankingModel" });
13651
13694
  }
@@ -13703,7 +13746,7 @@ async function rerank({
13703
13746
  }),
13704
13747
  tracer,
13705
13748
  fn: async () => {
13706
- var _a22, _b;
13749
+ var _a23, _b;
13707
13750
  const { ranking, response, providerMetadata, warnings } = await retry(
13708
13751
  () => recordSpan({
13709
13752
  name: "ai.rerank.doRerank",
@@ -13767,7 +13810,7 @@ async function rerank({
13767
13810
  providerMetadata,
13768
13811
  response: {
13769
13812
  id: response == null ? void 0 : response.id,
13770
- timestamp: (_a22 = response == null ? void 0 : response.timestamp) != null ? _a22 : /* @__PURE__ */ new Date(),
13813
+ timestamp: (_a23 = response == null ? void 0 : response.timestamp) != null ? _a23 : /* @__PURE__ */ new Date(),
13771
13814
  modelId: (_b = response == null ? void 0 : response.modelId) != null ? _b : model.modelId,
13772
13815
  headers: response == null ? void 0 : response.headers,
13773
13816
  body: response == null ? void 0 : response.body
@@ -13817,16 +13860,16 @@ async function transcribe({
13817
13860
  const audioData = audio instanceof URL ? (await downloadFn({ url: audio, abortSignal })).data : convertDataContentToUint8Array(audio);
13818
13861
  const result = await retry(
13819
13862
  () => {
13820
- var _a22;
13863
+ var _a23;
13821
13864
  return resolvedModel.doGenerate({
13822
13865
  audio: audioData,
13823
13866
  abortSignal,
13824
13867
  headers: headersWithUserAgent,
13825
13868
  providerOptions,
13826
- mediaType: (_a22 = detectMediaType({
13869
+ mediaType: (_a23 = detectMediaType({
13827
13870
  data: audioData,
13828
13871
  signatures: audioMediaTypeSignatures
13829
- })) != null ? _a22 : "audio/wav"
13872
+ })) != null ? _a23 : "audio/wav"
13830
13873
  });
13831
13874
  }
13832
13875
  );
@@ -13850,14 +13893,14 @@ async function transcribe({
13850
13893
  }
13851
13894
  var DefaultTranscriptionResult = class {
13852
13895
  constructor(options) {
13853
- var _a22;
13896
+ var _a23;
13854
13897
  this.text = options.text;
13855
13898
  this.segments = options.segments;
13856
13899
  this.language = options.language;
13857
13900
  this.durationInSeconds = options.durationInSeconds;
13858
13901
  this.warnings = options.warnings;
13859
13902
  this.responses = options.responses;
13860
- this.providerMetadata = (_a22 = options.providerMetadata) != null ? _a22 : {};
13903
+ this.providerMetadata = (_a23 = options.providerMetadata) != null ? _a23 : {};
13861
13904
  }
13862
13905
  };
13863
13906
 
@@ -13900,7 +13943,7 @@ async function callCompletionApi({
13900
13943
  onError,
13901
13944
  fetch: fetch2 = getOriginalFetch()
13902
13945
  }) {
13903
- var _a22;
13946
+ var _a23;
13904
13947
  try {
13905
13948
  setLoading(true);
13906
13949
  setError(void 0);
@@ -13928,7 +13971,7 @@ async function callCompletionApi({
13928
13971
  });
13929
13972
  if (!response.ok) {
13930
13973
  throw new Error(
13931
- (_a22 = await response.text()) != null ? _a22 : "Failed to fetch the chat response."
13974
+ (_a23 = await response.text()) != null ? _a23 : "Failed to fetch the chat response."
13932
13975
  );
13933
13976
  }
13934
13977
  if (!response.body) {
@@ -14014,12 +14057,12 @@ async function convertFileListToFileUIParts(files) {
14014
14057
  }
14015
14058
  return Promise.all(
14016
14059
  Array.from(files).map(async (file) => {
14017
- const { name: name22, type } = file;
14060
+ const { name: name23, type } = file;
14018
14061
  const dataUrl = await new Promise((resolve3, reject) => {
14019
14062
  const reader = new FileReader();
14020
14063
  reader.onload = (readerEvent) => {
14021
- var _a22;
14022
- resolve3((_a22 = readerEvent.target) == null ? void 0 : _a22.result);
14064
+ var _a23;
14065
+ resolve3((_a23 = readerEvent.target) == null ? void 0 : _a23.result);
14023
14066
  };
14024
14067
  reader.onerror = (error) => reject(error);
14025
14068
  reader.readAsDataURL(file);
@@ -14027,7 +14070,7 @@ async function convertFileListToFileUIParts(files) {
14027
14070
  return {
14028
14071
  type: "file",
14029
14072
  mediaType: type,
14030
- filename: name22,
14073
+ filename: name23,
14031
14074
  url: dataUrl
14032
14075
  };
14033
14076
  })
@@ -14064,7 +14107,7 @@ var HttpChatTransport = class {
14064
14107
  abortSignal,
14065
14108
  ...options
14066
14109
  }) {
14067
- var _a22, _b, _c, _d, _e;
14110
+ var _a23, _b, _c, _d, _e;
14068
14111
  const resolvedBody = await resolve2(this.body);
14069
14112
  const resolvedHeaders = await resolve2(this.headers);
14070
14113
  const resolvedCredentials = await resolve2(this.credentials);
@@ -14072,7 +14115,7 @@ var HttpChatTransport = class {
14072
14115
  ...normalizeHeaders(resolvedHeaders),
14073
14116
  ...normalizeHeaders(options.headers)
14074
14117
  };
14075
- const preparedRequest = await ((_a22 = this.prepareSendMessagesRequest) == null ? void 0 : _a22.call(this, {
14118
+ const preparedRequest = await ((_a23 = this.prepareSendMessagesRequest) == null ? void 0 : _a23.call(this, {
14076
14119
  api: this.api,
14077
14120
  id: options.chatId,
14078
14121
  messages: options.messages,
@@ -14116,7 +14159,7 @@ var HttpChatTransport = class {
14116
14159
  return this.processResponseStream(response.body);
14117
14160
  }
14118
14161
  async reconnectToStream(options) {
14119
- var _a22, _b, _c, _d, _e;
14162
+ var _a23, _b, _c, _d, _e;
14120
14163
  const resolvedBody = await resolve2(this.body);
14121
14164
  const resolvedHeaders = await resolve2(this.headers);
14122
14165
  const resolvedCredentials = await resolve2(this.credentials);
@@ -14124,7 +14167,7 @@ var HttpChatTransport = class {
14124
14167
  ...normalizeHeaders(resolvedHeaders),
14125
14168
  ...normalizeHeaders(options.headers)
14126
14169
  };
14127
- const preparedRequest = await ((_a22 = this.prepareReconnectToStreamRequest) == null ? void 0 : _a22.call(this, {
14170
+ const preparedRequest = await ((_a23 = this.prepareReconnectToStreamRequest) == null ? void 0 : _a23.call(this, {
14128
14171
  api: this.api,
14129
14172
  id: options.chatId,
14130
14173
  body: { ...resolvedBody, ...options.body },
@@ -14204,11 +14247,11 @@ var AbstractChat = class {
14204
14247
  * If a messageId is provided, the message will be replaced.
14205
14248
  */
14206
14249
  this.sendMessage = async (message, options) => {
14207
- var _a22, _b, _c, _d;
14250
+ var _a23, _b, _c, _d;
14208
14251
  if (message == null) {
14209
14252
  await this.makeRequest({
14210
14253
  trigger: "submit-message",
14211
- messageId: (_a22 = this.lastMessage) == null ? void 0 : _a22.id,
14254
+ messageId: (_a23 = this.lastMessage) == null ? void 0 : _a23.id,
14212
14255
  ...options
14213
14256
  });
14214
14257
  return;
@@ -14318,11 +14361,11 @@ var AbstractChat = class {
14318
14361
  }
14319
14362
  if (this.status !== "streaming" && this.status !== "submitted" && this.sendAutomaticallyWhen) {
14320
14363
  this.shouldSendAutomatically().then((shouldSend) => {
14321
- var _a22;
14364
+ var _a23;
14322
14365
  if (shouldSend) {
14323
14366
  this.makeRequest({
14324
14367
  trigger: "submit-message",
14325
- messageId: (_a22 = this.lastMessage) == null ? void 0 : _a22.id,
14368
+ messageId: (_a23 = this.lastMessage) == null ? void 0 : _a23.id,
14326
14369
  ...options
14327
14370
  });
14328
14371
  }
@@ -14348,11 +14391,11 @@ var AbstractChat = class {
14348
14391
  }
14349
14392
  if (this.status !== "streaming" && this.status !== "submitted" && this.sendAutomaticallyWhen) {
14350
14393
  this.shouldSendAutomatically().then((shouldSend) => {
14351
- var _a22;
14394
+ var _a23;
14352
14395
  if (shouldSend) {
14353
14396
  this.makeRequest({
14354
14397
  trigger: "submit-message",
14355
- messageId: (_a22 = this.lastMessage) == null ? void 0 : _a22.id,
14398
+ messageId: (_a23 = this.lastMessage) == null ? void 0 : _a23.id,
14356
14399
  ...options
14357
14400
  });
14358
14401
  }
@@ -14365,8 +14408,8 @@ var AbstractChat = class {
14365
14408
  * Abort the current request immediately, keep the generated tokens if any.
14366
14409
  */
14367
14410
  this.stop = async () => {
14368
- var _a22, _b;
14369
- (_a22 = this.activeResumeRequest) == null ? void 0 : _a22.abortController.abort();
14411
+ var _a23, _b;
14412
+ (_a23 = this.activeResumeRequest) == null ? void 0 : _a23.abortController.abort();
14370
14413
  (_b = this.activeResponse) == null ? void 0 : _b.abortController.abort();
14371
14414
  };
14372
14415
  this.id = id;
@@ -14431,11 +14474,11 @@ var AbstractChat = class {
14431
14474
  body,
14432
14475
  messageId
14433
14476
  }) {
14434
- var _a22, _b, _c;
14477
+ var _a23, _b, _c;
14435
14478
  const abortController = new AbortController();
14436
14479
  const activeResumeRequest = trigger === "resume-stream" ? { abortController } : void 0;
14437
14480
  if (activeResumeRequest) {
14438
- (_a22 = this.activeResumeRequest) == null ? void 0 : _a22.abortController.abort();
14481
+ (_a23 = this.activeResumeRequest) == null ? void 0 : _a23.abortController.abort();
14439
14482
  this.activeResumeRequest = activeResumeRequest;
14440
14483
  }
14441
14484
  const isCurrentRequest = () => activeResumeRequest == null || this.activeResumeRequest === activeResumeRequest;
@@ -14531,14 +14574,14 @@ var AbstractChat = class {
14531
14574
  return job({
14532
14575
  state: response.state,
14533
14576
  write: ({ updateStatus = true } = {}) => {
14534
- var _a23;
14577
+ var _a24;
14535
14578
  if (response.abortController.signal.aborted) {
14536
14579
  return;
14537
14580
  }
14538
14581
  if (updateStatus) {
14539
14582
  this.setStatus({ status: "streaming" });
14540
14583
  }
14541
- const replaceLastMessage = response.state.message.id === ((_a23 = this.lastMessage) == null ? void 0 : _a23.id);
14584
+ const replaceLastMessage = response.state.message.id === ((_a24 = this.lastMessage) == null ? void 0 : _a24.id);
14542
14585
  if (replaceLastMessage) {
14543
14586
  this.state.replaceMessage(
14544
14587
  this.state.messages.length - 1,
@@ -14746,7 +14789,7 @@ var TextStreamChatTransport = class extends HttpChatTransport {
14746
14789
  }
14747
14790
  };
14748
14791
  export {
14749
- AISDKError22 as AISDKError,
14792
+ AISDKError23 as AISDKError,
14750
14793
  APICallError,
14751
14794
  AbstractChat,
14752
14795
  DefaultChatTransport,
@@ -14788,6 +14831,7 @@ export {
14788
14831
  TooManyEmbeddingValuesForCallError,
14789
14832
  ToolCallNotFoundForApprovalError,
14790
14833
  ToolCallRepairError,
14834
+ ToolChoiceViolationError,
14791
14835
  ToolLoopAgent,
14792
14836
  TypeValidationError,
14793
14837
  UIMessageStreamError,