@mastra/memory 1.1.0 → 1.2.0-alpha.0

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 (95) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/dist/_types/@internal_ai-sdk-v4/dist/index.d.ts +30 -17
  3. package/dist/{chunk-FQJWVCDF.cjs → chunk-AWE2QQPI.cjs} +1884 -312
  4. package/dist/chunk-AWE2QQPI.cjs.map +1 -0
  5. package/dist/chunk-EQ4M72KU.js +439 -0
  6. package/dist/chunk-EQ4M72KU.js.map +1 -0
  7. package/dist/{chunk-O3CS4UGX.cjs → chunk-IDRQZVB4.cjs} +4 -4
  8. package/dist/{chunk-O3CS4UGX.cjs.map → chunk-IDRQZVB4.cjs.map} +1 -1
  9. package/dist/{chunk-YF4R74L2.js → chunk-RC6RZVYE.js} +4 -4
  10. package/dist/{chunk-YF4R74L2.js.map → chunk-RC6RZVYE.js.map} +1 -1
  11. package/dist/{chunk-6TXUWFIU.js → chunk-TYVPTNCP.js} +1885 -313
  12. package/dist/chunk-TYVPTNCP.js.map +1 -0
  13. package/dist/chunk-ZD3BKU5O.cjs +441 -0
  14. package/dist/chunk-ZD3BKU5O.cjs.map +1 -0
  15. package/dist/docs/SKILL.md +51 -50
  16. package/dist/docs/{SOURCE_MAP.json → assets/SOURCE_MAP.json} +22 -22
  17. package/dist/docs/{agents/03-agent-approval.md → references/docs-agents-agent-approval.md} +19 -19
  18. package/dist/docs/references/docs-agents-agent-memory.md +212 -0
  19. package/dist/docs/{agents/04-network-approval.md → references/docs-agents-network-approval.md} +13 -12
  20. package/dist/docs/{agents/02-networks.md → references/docs-agents-networks.md} +10 -12
  21. package/dist/docs/{memory/06-memory-processors.md → references/docs-memory-memory-processors.md} +6 -8
  22. package/dist/docs/{memory/03-message-history.md → references/docs-memory-message-history.md} +31 -20
  23. package/dist/docs/references/docs-memory-observational-memory.md +238 -0
  24. package/dist/docs/{memory/01-overview.md → references/docs-memory-overview.md} +8 -8
  25. package/dist/docs/{memory/05-semantic-recall.md → references/docs-memory-semantic-recall.md} +33 -17
  26. package/dist/docs/{memory/02-storage.md → references/docs-memory-storage.md} +29 -39
  27. package/dist/docs/{memory/04-working-memory.md → references/docs-memory-working-memory.md} +16 -27
  28. package/dist/docs/references/reference-core-getMemory.md +50 -0
  29. package/dist/docs/references/reference-core-listMemory.md +56 -0
  30. package/dist/docs/references/reference-memory-clone-utilities.md +199 -0
  31. package/dist/docs/references/reference-memory-cloneThread.md +130 -0
  32. package/dist/docs/references/reference-memory-createThread.md +68 -0
  33. package/dist/docs/references/reference-memory-getThreadById.md +24 -0
  34. package/dist/docs/references/reference-memory-listThreads.md +145 -0
  35. package/dist/docs/references/reference-memory-memory-class.md +147 -0
  36. package/dist/docs/references/reference-memory-observational-memory.md +528 -0
  37. package/dist/docs/{processors/01-reference.md → references/reference-processors-token-limiter-processor.md} +25 -12
  38. package/dist/docs/references/reference-storage-dynamodb.md +282 -0
  39. package/dist/docs/references/reference-storage-libsql.md +135 -0
  40. package/dist/docs/references/reference-storage-mongodb.md +262 -0
  41. package/dist/docs/references/reference-storage-postgresql.md +529 -0
  42. package/dist/docs/references/reference-storage-upstash.md +160 -0
  43. package/dist/docs/references/reference-vectors-libsql.md +305 -0
  44. package/dist/docs/references/reference-vectors-mongodb.md +295 -0
  45. package/dist/docs/references/reference-vectors-pg.md +408 -0
  46. package/dist/docs/references/reference-vectors-upstash.md +294 -0
  47. package/dist/index.cjs +919 -507
  48. package/dist/index.cjs.map +1 -1
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/index.js +914 -502
  51. package/dist/index.js.map +1 -1
  52. package/dist/{observational-memory-3Q42SITP.cjs → observational-memory-3UO64HYD.cjs} +14 -14
  53. package/dist/{observational-memory-3Q42SITP.cjs.map → observational-memory-3UO64HYD.cjs.map} +1 -1
  54. package/dist/{observational-memory-VXLHOSDZ.js → observational-memory-TVHT3HP4.js} +3 -3
  55. package/dist/{observational-memory-VXLHOSDZ.js.map → observational-memory-TVHT3HP4.js.map} +1 -1
  56. package/dist/processors/index.cjs +12 -12
  57. package/dist/processors/index.js +1 -1
  58. package/dist/processors/observational-memory/index.d.ts +1 -1
  59. package/dist/processors/observational-memory/index.d.ts.map +1 -1
  60. package/dist/processors/observational-memory/observational-memory.d.ts +267 -1
  61. package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -1
  62. package/dist/processors/observational-memory/observer-agent.d.ts +3 -1
  63. package/dist/processors/observational-memory/observer-agent.d.ts.map +1 -1
  64. package/dist/processors/observational-memory/reflector-agent.d.ts +10 -3
  65. package/dist/processors/observational-memory/reflector-agent.d.ts.map +1 -1
  66. package/dist/processors/observational-memory/types.d.ts +243 -19
  67. package/dist/processors/observational-memory/types.d.ts.map +1 -1
  68. package/dist/{token-6GSAFR2W-WGTMOPEU.js → token-APYSY3BW-2DN6RAUY.js} +11 -11
  69. package/dist/token-APYSY3BW-2DN6RAUY.js.map +1 -0
  70. package/dist/{token-6GSAFR2W-2B4WM6AQ.cjs → token-APYSY3BW-ZQ7TMBY7.cjs} +14 -14
  71. package/dist/token-APYSY3BW-ZQ7TMBY7.cjs.map +1 -0
  72. package/dist/token-util-RMHT2CPJ-6TGPE335.cjs +10 -0
  73. package/dist/token-util-RMHT2CPJ-6TGPE335.cjs.map +1 -0
  74. package/dist/token-util-RMHT2CPJ-RJEA3FAN.js +8 -0
  75. package/dist/token-util-RMHT2CPJ-RJEA3FAN.js.map +1 -0
  76. package/dist/tools/working-memory.d.ts.map +1 -1
  77. package/package.json +6 -7
  78. package/dist/chunk-6TXUWFIU.js.map +0 -1
  79. package/dist/chunk-FQJWVCDF.cjs.map +0 -1
  80. package/dist/chunk-WM6IIUQW.js +0 -250
  81. package/dist/chunk-WM6IIUQW.js.map +0 -1
  82. package/dist/chunk-ZSBBXHNM.cjs +0 -252
  83. package/dist/chunk-ZSBBXHNM.cjs.map +0 -1
  84. package/dist/docs/README.md +0 -36
  85. package/dist/docs/agents/01-agent-memory.md +0 -166
  86. package/dist/docs/core/01-reference.md +0 -114
  87. package/dist/docs/memory/07-reference.md +0 -687
  88. package/dist/docs/storage/01-reference.md +0 -1218
  89. package/dist/docs/vectors/01-reference.md +0 -942
  90. package/dist/token-6GSAFR2W-2B4WM6AQ.cjs.map +0 -1
  91. package/dist/token-6GSAFR2W-WGTMOPEU.js.map +0 -1
  92. package/dist/token-util-NEHG7TUY-TV2H7N56.js +0 -8
  93. package/dist/token-util-NEHG7TUY-TV2H7N56.js.map +0 -1
  94. package/dist/token-util-NEHG7TUY-WJZIPNNX.cjs +0 -10
  95. package/dist/token-util-NEHG7TUY-WJZIPNNX.cjs.map +0 -1
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { __commonJS, require_token_error, __toESM } from './chunk-BSDWQEU3.js';
2
- import { __commonJS as __commonJS$1, require_token_error as require_token_error$1, __toESM as __toESM$1 } from './chunk-YF4R74L2.js';
3
- import { z, ZodObject, ZodFirstPartyTypeKind as ZodFirstPartyTypeKind$1 } from 'zod';
2
+ import { __commonJS as __commonJS$1, require_token_error as require_token_error$1, __toESM as __toESM$1 } from './chunk-RC6RZVYE.js';
3
+ import { ZodFirstPartyTypeKind } from 'zod/v3';
4
+ import { z, ZodObject } from 'zod';
4
5
  import * as z4 from 'zod/v4';
5
6
  import { z as z$1 } from 'zod/v4';
6
- import { ZodFirstPartyTypeKind } from 'zod/v3';
7
7
  import { MessageList } from '@mastra/core/agent';
8
8
  import { coreFeatures } from '@mastra/core/features';
9
9
  import { MastraMemory, removeWorkingMemoryTags, extractWorkingMemoryContent } from '@mastra/core/memory';
@@ -156,13 +156,13 @@ var _AISDKError = class _AISDKError2 extends Error {
156
156
  * @param {unknown} [params.cause] - The underlying cause of the error.
157
157
  */
158
158
  constructor({
159
- name: name144,
159
+ name: name145,
160
160
  message,
161
161
  cause
162
162
  }) {
163
163
  super(message);
164
164
  this[_a] = true;
165
- this.name = name144;
165
+ this.name = name145;
166
166
  this.cause = cause;
167
167
  }
168
168
  /**
@@ -173,8 +173,8 @@ var _AISDKError = class _AISDKError2 extends Error {
173
173
  static isInstance(error) {
174
174
  return _AISDKError2.hasMarker(error, marker);
175
175
  }
176
- static hasMarker(error, marker154) {
177
- const markerSymbol = Symbol.for(marker154);
176
+ static hasMarker(error, marker155) {
177
+ const markerSymbol = Symbol.for(marker155);
178
178
  return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
179
179
  }
180
180
  };
@@ -476,11 +476,11 @@ var getRefs = (options) => {
476
476
  flags: { hasReferencedOpenAiAnyType: false },
477
477
  currentPath,
478
478
  propertyPath: void 0,
479
- seen: new Map(Object.entries(_options.definitions).map(([name172, def]) => [
479
+ seen: new Map(Object.entries(_options.definitions).map(([name173, def]) => [
480
480
  def._def,
481
481
  {
482
482
  def: def._def,
483
- path: [..._options.basePath, _options.definitionPath, name172],
483
+ path: [..._options.basePath, _options.definitionPath, name173],
484
484
  // Resolution of references will be forced even though seen, so it's ok that the schema is undefined here for now.
485
485
  jsonSchema: void 0
486
486
  }
@@ -527,7 +527,7 @@ function parseArrayDef(def, refs) {
527
527
  const res = {
528
528
  type: "array"
529
529
  };
530
- if (def.type?._def && def.type?._def?.typeName !== ZodFirstPartyTypeKind$1.ZodAny) {
530
+ if (def.type?._def && def.type?._def?.typeName !== ZodFirstPartyTypeKind.ZodAny) {
531
531
  res.items = parseDef(def.type._def, {
532
532
  ...refs,
533
533
  currentPath: [...refs.currentPath, "items"]
@@ -1044,7 +1044,7 @@ function parseRecordDef(def, refs) {
1044
1044
  if (refs.target === "openAi") {
1045
1045
  console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead.");
1046
1046
  }
1047
- if (refs.target === "openApi3" && def.keyType?._def.typeName === ZodFirstPartyTypeKind$1.ZodEnum) {
1047
+ if (refs.target === "openApi3" && def.keyType?._def.typeName === ZodFirstPartyTypeKind.ZodEnum) {
1048
1048
  return {
1049
1049
  type: "object",
1050
1050
  required: def.keyType._def.values,
@@ -1068,20 +1068,20 @@ function parseRecordDef(def, refs) {
1068
1068
  if (refs.target === "openApi3") {
1069
1069
  return schema;
1070
1070
  }
1071
- if (def.keyType?._def.typeName === ZodFirstPartyTypeKind$1.ZodString && def.keyType._def.checks?.length) {
1071
+ if (def.keyType?._def.typeName === ZodFirstPartyTypeKind.ZodString && def.keyType._def.checks?.length) {
1072
1072
  const { type, ...keyType } = parseStringDef(def.keyType._def, refs);
1073
1073
  return {
1074
1074
  ...schema,
1075
1075
  propertyNames: keyType
1076
1076
  };
1077
- } else if (def.keyType?._def.typeName === ZodFirstPartyTypeKind$1.ZodEnum) {
1077
+ } else if (def.keyType?._def.typeName === ZodFirstPartyTypeKind.ZodEnum) {
1078
1078
  return {
1079
1079
  ...schema,
1080
1080
  propertyNames: {
1081
1081
  enum: def.keyType._def.values
1082
1082
  }
1083
1083
  };
1084
- } else if (def.keyType?._def.typeName === ZodFirstPartyTypeKind$1.ZodBranded && def.keyType._def.type._def.typeName === ZodFirstPartyTypeKind$1.ZodString && def.keyType._def.type._def.checks?.length) {
1084
+ } else if (def.keyType?._def.typeName === ZodFirstPartyTypeKind.ZodBranded && def.keyType._def.type._def.typeName === ZodFirstPartyTypeKind.ZodString && def.keyType._def.type._def.checks?.length) {
1085
1085
  const { type, ...keyType } = parseBrandedDef(def.keyType._def, refs);
1086
1086
  return {
1087
1087
  ...schema,
@@ -1447,73 +1447,73 @@ var parseReadonlyDef = (def, refs) => {
1447
1447
  };
1448
1448
  var selectParser = (def, typeName, refs) => {
1449
1449
  switch (typeName) {
1450
- case ZodFirstPartyTypeKind$1.ZodString:
1450
+ case ZodFirstPartyTypeKind.ZodString:
1451
1451
  return parseStringDef(def, refs);
1452
- case ZodFirstPartyTypeKind$1.ZodNumber:
1452
+ case ZodFirstPartyTypeKind.ZodNumber:
1453
1453
  return parseNumberDef(def, refs);
1454
- case ZodFirstPartyTypeKind$1.ZodObject:
1454
+ case ZodFirstPartyTypeKind.ZodObject:
1455
1455
  return parseObjectDef(def, refs);
1456
- case ZodFirstPartyTypeKind$1.ZodBigInt:
1456
+ case ZodFirstPartyTypeKind.ZodBigInt:
1457
1457
  return parseBigintDef(def, refs);
1458
- case ZodFirstPartyTypeKind$1.ZodBoolean:
1458
+ case ZodFirstPartyTypeKind.ZodBoolean:
1459
1459
  return parseBooleanDef();
1460
- case ZodFirstPartyTypeKind$1.ZodDate:
1460
+ case ZodFirstPartyTypeKind.ZodDate:
1461
1461
  return parseDateDef(def, refs);
1462
- case ZodFirstPartyTypeKind$1.ZodUndefined:
1462
+ case ZodFirstPartyTypeKind.ZodUndefined:
1463
1463
  return parseUndefinedDef(refs);
1464
- case ZodFirstPartyTypeKind$1.ZodNull:
1464
+ case ZodFirstPartyTypeKind.ZodNull:
1465
1465
  return parseNullDef(refs);
1466
- case ZodFirstPartyTypeKind$1.ZodArray:
1466
+ case ZodFirstPartyTypeKind.ZodArray:
1467
1467
  return parseArrayDef(def, refs);
1468
- case ZodFirstPartyTypeKind$1.ZodUnion:
1469
- case ZodFirstPartyTypeKind$1.ZodDiscriminatedUnion:
1468
+ case ZodFirstPartyTypeKind.ZodUnion:
1469
+ case ZodFirstPartyTypeKind.ZodDiscriminatedUnion:
1470
1470
  return parseUnionDef(def, refs);
1471
- case ZodFirstPartyTypeKind$1.ZodIntersection:
1471
+ case ZodFirstPartyTypeKind.ZodIntersection:
1472
1472
  return parseIntersectionDef(def, refs);
1473
- case ZodFirstPartyTypeKind$1.ZodTuple:
1473
+ case ZodFirstPartyTypeKind.ZodTuple:
1474
1474
  return parseTupleDef(def, refs);
1475
- case ZodFirstPartyTypeKind$1.ZodRecord:
1475
+ case ZodFirstPartyTypeKind.ZodRecord:
1476
1476
  return parseRecordDef(def, refs);
1477
- case ZodFirstPartyTypeKind$1.ZodLiteral:
1477
+ case ZodFirstPartyTypeKind.ZodLiteral:
1478
1478
  return parseLiteralDef(def, refs);
1479
- case ZodFirstPartyTypeKind$1.ZodEnum:
1479
+ case ZodFirstPartyTypeKind.ZodEnum:
1480
1480
  return parseEnumDef(def);
1481
- case ZodFirstPartyTypeKind$1.ZodNativeEnum:
1481
+ case ZodFirstPartyTypeKind.ZodNativeEnum:
1482
1482
  return parseNativeEnumDef(def);
1483
- case ZodFirstPartyTypeKind$1.ZodNullable:
1483
+ case ZodFirstPartyTypeKind.ZodNullable:
1484
1484
  return parseNullableDef(def, refs);
1485
- case ZodFirstPartyTypeKind$1.ZodOptional:
1485
+ case ZodFirstPartyTypeKind.ZodOptional:
1486
1486
  return parseOptionalDef(def, refs);
1487
- case ZodFirstPartyTypeKind$1.ZodMap:
1487
+ case ZodFirstPartyTypeKind.ZodMap:
1488
1488
  return parseMapDef(def, refs);
1489
- case ZodFirstPartyTypeKind$1.ZodSet:
1489
+ case ZodFirstPartyTypeKind.ZodSet:
1490
1490
  return parseSetDef(def, refs);
1491
- case ZodFirstPartyTypeKind$1.ZodLazy:
1491
+ case ZodFirstPartyTypeKind.ZodLazy:
1492
1492
  return () => def.getter()._def;
1493
- case ZodFirstPartyTypeKind$1.ZodPromise:
1493
+ case ZodFirstPartyTypeKind.ZodPromise:
1494
1494
  return parsePromiseDef(def, refs);
1495
- case ZodFirstPartyTypeKind$1.ZodNaN:
1496
- case ZodFirstPartyTypeKind$1.ZodNever:
1495
+ case ZodFirstPartyTypeKind.ZodNaN:
1496
+ case ZodFirstPartyTypeKind.ZodNever:
1497
1497
  return parseNeverDef(refs);
1498
- case ZodFirstPartyTypeKind$1.ZodEffects:
1498
+ case ZodFirstPartyTypeKind.ZodEffects:
1499
1499
  return parseEffectsDef(def, refs);
1500
- case ZodFirstPartyTypeKind$1.ZodAny:
1500
+ case ZodFirstPartyTypeKind.ZodAny:
1501
1501
  return parseAnyDef(refs);
1502
- case ZodFirstPartyTypeKind$1.ZodUnknown:
1502
+ case ZodFirstPartyTypeKind.ZodUnknown:
1503
1503
  return parseUnknownDef(refs);
1504
- case ZodFirstPartyTypeKind$1.ZodDefault:
1504
+ case ZodFirstPartyTypeKind.ZodDefault:
1505
1505
  return parseDefaultDef(def, refs);
1506
- case ZodFirstPartyTypeKind$1.ZodBranded:
1506
+ case ZodFirstPartyTypeKind.ZodBranded:
1507
1507
  return parseBrandedDef(def, refs);
1508
- case ZodFirstPartyTypeKind$1.ZodReadonly:
1508
+ case ZodFirstPartyTypeKind.ZodReadonly:
1509
1509
  return parseReadonlyDef(def, refs);
1510
- case ZodFirstPartyTypeKind$1.ZodCatch:
1510
+ case ZodFirstPartyTypeKind.ZodCatch:
1511
1511
  return parseCatchDef(def, refs);
1512
- case ZodFirstPartyTypeKind$1.ZodPipeline:
1512
+ case ZodFirstPartyTypeKind.ZodPipeline:
1513
1513
  return parsePipelineDef(def, refs);
1514
- case ZodFirstPartyTypeKind$1.ZodFunction:
1515
- case ZodFirstPartyTypeKind$1.ZodVoid:
1516
- case ZodFirstPartyTypeKind$1.ZodSymbol:
1514
+ case ZodFirstPartyTypeKind.ZodFunction:
1515
+ case ZodFirstPartyTypeKind.ZodVoid:
1516
+ case ZodFirstPartyTypeKind.ZodSymbol:
1517
1517
  return void 0;
1518
1518
  default:
1519
1519
  return /* @__PURE__ */ ((_) => void 0)();
@@ -1575,17 +1575,17 @@ var addMeta = (def, refs, jsonSchema22) => {
1575
1575
  };
1576
1576
  var zodToJsonSchema = (schema, options) => {
1577
1577
  const refs = getRefs(options);
1578
- let definitions = typeof options === "object" && options.definitions ? Object.entries(options.definitions).reduce((acc, [name182, schema2]) => ({
1578
+ let definitions = typeof options === "object" && options.definitions ? Object.entries(options.definitions).reduce((acc, [name183, schema2]) => ({
1579
1579
  ...acc,
1580
- [name182]: parseDef(schema2._def, {
1580
+ [name183]: parseDef(schema2._def, {
1581
1581
  ...refs,
1582
- currentPath: [...refs.basePath, refs.definitionPath, name182]
1582
+ currentPath: [...refs.basePath, refs.definitionPath, name183]
1583
1583
  }, true) ?? parseAnyDef(refs)
1584
1584
  }), {}) : void 0;
1585
- const name172 = typeof options === "string" ? options : options?.nameStrategy === "title" ? void 0 : options?.name;
1586
- const main = parseDef(schema._def, name172 === void 0 ? refs : {
1585
+ const name173 = typeof options === "string" ? options : options?.nameStrategy === "title" ? void 0 : options?.name;
1586
+ const main = parseDef(schema._def, name173 === void 0 ? refs : {
1587
1587
  ...refs,
1588
- currentPath: [...refs.basePath, refs.definitionPath, name172]
1588
+ currentPath: [...refs.basePath, refs.definitionPath, name173]
1589
1589
  }, false) ?? parseAnyDef(refs);
1590
1590
  const title = typeof options === "object" && options.name !== void 0 && options.nameStrategy === "title" ? options.name : void 0;
1591
1591
  if (title !== void 0) {
@@ -1609,18 +1609,18 @@ var zodToJsonSchema = (schema, options) => {
1609
1609
  };
1610
1610
  }
1611
1611
  }
1612
- const combined = name172 === void 0 ? definitions ? {
1612
+ const combined = name173 === void 0 ? definitions ? {
1613
1613
  ...main,
1614
1614
  [refs.definitionPath]: definitions
1615
1615
  } : main : {
1616
1616
  $ref: [
1617
1617
  ...refs.$refStrategy === "relative" ? [] : refs.basePath,
1618
1618
  refs.definitionPath,
1619
- name172
1619
+ name173
1620
1620
  ].join("/"),
1621
1621
  [refs.definitionPath]: {
1622
1622
  ...definitions,
1623
- [name172]: main
1623
+ [name173]: main
1624
1624
  }
1625
1625
  };
1626
1626
  if (refs.target === "jsonSchema7") {
@@ -2228,8 +2228,8 @@ function formatDataStreamPart(type, value) {
2228
2228
  `;
2229
2229
  }
2230
2230
  function zodSchema(zodSchema22, options) {
2231
- var _a172;
2232
- const useReferences = (_a172 = void 0 ) != null ? _a172 : false;
2231
+ var _a173;
2232
+ const useReferences = (_a173 = void 0 ) != null ? _a173 : false;
2233
2233
  return jsonSchema(
2234
2234
  esm_default(zodSchema22, {
2235
2235
  $refStrategy: useReferences ? "root" : "none",
@@ -2334,11 +2334,11 @@ var major = VERSION.split(".")[0];
2334
2334
  var GLOBAL_OPENTELEMETRY_API_KEY = /* @__PURE__ */ Symbol.for("opentelemetry.js.api." + major);
2335
2335
  var _global = _globalThis;
2336
2336
  function registerGlobal(type, instance, diag, allowOverride) {
2337
- var _a172;
2337
+ var _a173;
2338
2338
  if (allowOverride === void 0) {
2339
2339
  allowOverride = false;
2340
2340
  }
2341
- var api = _global[GLOBAL_OPENTELEMETRY_API_KEY] = (_a172 = _global[GLOBAL_OPENTELEMETRY_API_KEY]) !== null && _a172 !== void 0 ? _a172 : {
2341
+ var api = _global[GLOBAL_OPENTELEMETRY_API_KEY] = (_a173 = _global[GLOBAL_OPENTELEMETRY_API_KEY]) !== null && _a173 !== void 0 ? _a173 : {
2342
2342
  version: VERSION
2343
2343
  };
2344
2344
  if (!allowOverride && api[type]) {
@@ -2356,8 +2356,8 @@ function registerGlobal(type, instance, diag, allowOverride) {
2356
2356
  return true;
2357
2357
  }
2358
2358
  function getGlobal(type) {
2359
- var _a172, _b17;
2360
- var globalVersion = (_a172 = _global[GLOBAL_OPENTELEMETRY_API_KEY]) === null || _a172 === void 0 ? void 0 : _a172.version;
2359
+ var _a173, _b17;
2360
+ var globalVersion = (_a173 = _global[GLOBAL_OPENTELEMETRY_API_KEY]) === null || _a173 === void 0 ? void 0 : _a173.version;
2361
2361
  if (!globalVersion || !isCompatible(globalVersion)) {
2362
2362
  return;
2363
2363
  }
@@ -2526,13 +2526,13 @@ var DiagAPI = (
2526
2526
  }
2527
2527
  var self = this;
2528
2528
  var setLogger = function(logger, optionsOrLogLevel) {
2529
- var _a172, _b17, _c;
2529
+ var _a173, _b17, _c;
2530
2530
  if (optionsOrLogLevel === void 0) {
2531
2531
  optionsOrLogLevel = { logLevel: DiagLogLevel.INFO };
2532
2532
  }
2533
2533
  if (logger === self) {
2534
2534
  var err = new Error("Cannot use diag as the logger for itself. Please use a DiagLogger implementation like ConsoleDiagLogger or a custom implementation");
2535
- self.error((_a172 = err.stack) !== null && _a172 !== void 0 ? _a172 : err.message);
2535
+ self.error((_a173 = err.stack) !== null && _a173 !== void 0 ? _a173 : err.message);
2536
2536
  return false;
2537
2537
  }
2538
2538
  if (typeof optionsOrLogLevel === "number") {
@@ -2584,14 +2584,14 @@ var BaseContext = (
2584
2584
  return self._currentContext.get(key);
2585
2585
  };
2586
2586
  self.setValue = function(key, value) {
2587
- var context = new BaseContext22(self._currentContext);
2588
- context._currentContext.set(key, value);
2589
- return context;
2587
+ var context2 = new BaseContext22(self._currentContext);
2588
+ context2._currentContext.set(key, value);
2589
+ return context2;
2590
2590
  };
2591
2591
  self.deleteValue = function(key) {
2592
- var context = new BaseContext22(self._currentContext);
2593
- context._currentContext.delete(key);
2594
- return context;
2592
+ var context2 = new BaseContext22(self._currentContext);
2593
+ context2._currentContext.delete(key);
2594
+ return context2;
2595
2595
  };
2596
2596
  }
2597
2597
  return BaseContext22;
@@ -2696,16 +2696,16 @@ var ContextAPI = (
2696
2696
  ContextAPI22.prototype.active = function() {
2697
2697
  return this._getContextManager().active();
2698
2698
  };
2699
- ContextAPI22.prototype.with = function(context, fn, thisArg) {
2700
- var _a172;
2699
+ ContextAPI22.prototype.with = function(context2, fn, thisArg) {
2700
+ var _a173;
2701
2701
  var args = [];
2702
2702
  for (var _i = 3; _i < arguments.length; _i++) {
2703
2703
  args[_i - 3] = arguments[_i];
2704
2704
  }
2705
- return (_a172 = this._getContextManager()).with.apply(_a172, __spreadArray4([context, fn, thisArg], __read4(args), false));
2705
+ return (_a173 = this._getContextManager()).with.apply(_a173, __spreadArray4([context2, fn, thisArg], __read4(args), false));
2706
2706
  };
2707
- ContextAPI22.prototype.bind = function(context, target) {
2708
- return this._getContextManager().bind(context, target);
2707
+ ContextAPI22.prototype.bind = function(context2, target) {
2708
+ return this._getContextManager().bind(context2, target);
2709
2709
  };
2710
2710
  ContextAPI22.prototype._getContextManager = function() {
2711
2711
  return getGlobal(API_NAME2) || NOOP_CONTEXT_MANAGER;
@@ -2773,24 +2773,24 @@ var NonRecordingSpan = (
2773
2773
  })()
2774
2774
  );
2775
2775
  var SPAN_KEY = createContextKey("OpenTelemetry Context Key SPAN");
2776
- function getSpan(context) {
2777
- return context.getValue(SPAN_KEY) || void 0;
2776
+ function getSpan(context2) {
2777
+ return context2.getValue(SPAN_KEY) || void 0;
2778
2778
  }
2779
2779
  function getActiveSpan() {
2780
2780
  return getSpan(ContextAPI.getInstance().active());
2781
2781
  }
2782
- function setSpan(context, span) {
2783
- return context.setValue(SPAN_KEY, span);
2782
+ function setSpan(context2, span) {
2783
+ return context2.setValue(SPAN_KEY, span);
2784
2784
  }
2785
- function deleteSpan(context) {
2786
- return context.deleteValue(SPAN_KEY);
2785
+ function deleteSpan(context2) {
2786
+ return context2.deleteValue(SPAN_KEY);
2787
2787
  }
2788
- function setSpanContext(context, spanContext) {
2789
- return setSpan(context, new NonRecordingSpan(spanContext));
2788
+ function setSpanContext(context2, spanContext) {
2789
+ return setSpan(context2, new NonRecordingSpan(spanContext));
2790
2790
  }
2791
- function getSpanContext(context) {
2792
- var _a172;
2793
- return (_a172 = getSpan(context)) === null || _a172 === void 0 ? void 0 : _a172.spanContext();
2791
+ function getSpanContext(context2) {
2792
+ var _a173;
2793
+ return (_a173 = getSpan(context2)) === null || _a173 === void 0 ? void 0 : _a173.spanContext();
2794
2794
  }
2795
2795
  var VALID_TRACEID_REGEX = /^([0-9a-f]{32})$/i;
2796
2796
  var VALID_SPANID_REGEX = /^[0-9a-f]{16}$/i;
@@ -2812,22 +2812,22 @@ var NoopTracer = (
2812
2812
  (function() {
2813
2813
  function NoopTracer22() {
2814
2814
  }
2815
- NoopTracer22.prototype.startSpan = function(name172, options, context) {
2816
- if (context === void 0) {
2817
- context = contextApi.active();
2815
+ NoopTracer22.prototype.startSpan = function(name173, options, context2) {
2816
+ if (context2 === void 0) {
2817
+ context2 = contextApi.active();
2818
2818
  }
2819
2819
  var root = Boolean(options === null || options === void 0 ? void 0 : options.root);
2820
2820
  if (root) {
2821
2821
  return new NonRecordingSpan();
2822
2822
  }
2823
- var parentFromContext = context && getSpanContext(context);
2823
+ var parentFromContext = context2 && getSpanContext(context2);
2824
2824
  if (isSpanContext(parentFromContext) && isSpanContextValid(parentFromContext)) {
2825
2825
  return new NonRecordingSpan(parentFromContext);
2826
2826
  } else {
2827
2827
  return new NonRecordingSpan();
2828
2828
  }
2829
2829
  };
2830
- NoopTracer22.prototype.startActiveSpan = function(name172, arg2, arg3, arg4) {
2830
+ NoopTracer22.prototype.startActiveSpan = function(name173, arg2, arg3, arg4) {
2831
2831
  var opts;
2832
2832
  var ctx;
2833
2833
  var fn;
@@ -2844,7 +2844,7 @@ var NoopTracer = (
2844
2844
  fn = arg4;
2845
2845
  }
2846
2846
  var parentContext = ctx !== null && ctx !== void 0 ? ctx : contextApi.active();
2847
- var span = this.startSpan(name172, opts, parentContext);
2847
+ var span = this.startSpan(name173, opts, parentContext);
2848
2848
  var contextWithSpanSet = setSpan(parentContext, span);
2849
2849
  return contextApi.with(contextWithSpanSet, fn, void 0, span);
2850
2850
  };
@@ -2858,14 +2858,14 @@ var NOOP_TRACER = new NoopTracer();
2858
2858
  var ProxyTracer = (
2859
2859
  /** @class */
2860
2860
  (function() {
2861
- function ProxyTracer22(_provider, name172, version, options) {
2861
+ function ProxyTracer22(_provider, name173, version, options) {
2862
2862
  this._provider = _provider;
2863
- this.name = name172;
2863
+ this.name = name173;
2864
2864
  this.version = version;
2865
2865
  this.options = options;
2866
2866
  }
2867
- ProxyTracer22.prototype.startSpan = function(name172, options, context) {
2868
- return this._getTracer().startSpan(name172, options, context);
2867
+ ProxyTracer22.prototype.startSpan = function(name173, options, context2) {
2868
+ return this._getTracer().startSpan(name173, options, context2);
2869
2869
  };
2870
2870
  ProxyTracer22.prototype.startActiveSpan = function(_name, _options, _context, _fn) {
2871
2871
  var tracer = this._getTracer();
@@ -2902,20 +2902,20 @@ var ProxyTracerProvider = (
2902
2902
  (function() {
2903
2903
  function ProxyTracerProvider22() {
2904
2904
  }
2905
- ProxyTracerProvider22.prototype.getTracer = function(name172, version, options) {
2906
- var _a172;
2907
- return (_a172 = this.getDelegateTracer(name172, version, options)) !== null && _a172 !== void 0 ? _a172 : new ProxyTracer(this, name172, version, options);
2905
+ ProxyTracerProvider22.prototype.getTracer = function(name173, version, options) {
2906
+ var _a173;
2907
+ return (_a173 = this.getDelegateTracer(name173, version, options)) !== null && _a173 !== void 0 ? _a173 : new ProxyTracer(this, name173, version, options);
2908
2908
  };
2909
2909
  ProxyTracerProvider22.prototype.getDelegate = function() {
2910
- var _a172;
2911
- return (_a172 = this._delegate) !== null && _a172 !== void 0 ? _a172 : NOOP_TRACER_PROVIDER;
2910
+ var _a173;
2911
+ return (_a173 = this._delegate) !== null && _a173 !== void 0 ? _a173 : NOOP_TRACER_PROVIDER;
2912
2912
  };
2913
2913
  ProxyTracerProvider22.prototype.setDelegate = function(delegate) {
2914
2914
  this._delegate = delegate;
2915
2915
  };
2916
- ProxyTracerProvider22.prototype.getDelegateTracer = function(name172, version, options) {
2917
- var _a172;
2918
- return (_a172 = this._delegate) === null || _a172 === void 0 ? void 0 : _a172.getTracer(name172, version, options);
2916
+ ProxyTracerProvider22.prototype.getDelegateTracer = function(name173, version, options) {
2917
+ var _a173;
2918
+ return (_a173 = this._delegate) === null || _a173 === void 0 ? void 0 : _a173.getTracer(name173, version, options);
2919
2919
  };
2920
2920
  return ProxyTracerProvider22;
2921
2921
  })()
@@ -2957,8 +2957,8 @@ var TraceAPI = (
2957
2957
  TraceAPI22.prototype.getTracerProvider = function() {
2958
2958
  return getGlobal(API_NAME3) || this._proxyTracerProvider;
2959
2959
  };
2960
- TraceAPI22.prototype.getTracer = function(name172, version) {
2961
- return this.getTracerProvider().getTracer(name172, version);
2960
+ TraceAPI22.prototype.getTracer = function(name173, version) {
2961
+ return this.getTracerProvider().getTracer(name173, version);
2962
2962
  };
2963
2963
  TraceAPI22.prototype.disable = function() {
2964
2964
  unregisterGlobal(API_NAME3, DiagAPI.instance());
@@ -2970,8 +2970,8 @@ var TraceAPI = (
2970
2970
  var trace = TraceAPI.getInstance();
2971
2971
  var __defProp2 = Object.defineProperty;
2972
2972
  var __export = (target, all) => {
2973
- for (var name172 in all)
2974
- __defProp2(target, name172, { get: all[name172], enumerable: true });
2973
+ for (var name173 in all)
2974
+ __defProp2(target, name173, { get: all[name173], enumerable: true });
2975
2975
  };
2976
2976
  function prepareResponseHeaders(headers, {
2977
2977
  contentType,
@@ -3133,7 +3133,7 @@ function getBaseTelemetryAttributes({
3133
3133
  telemetry,
3134
3134
  headers
3135
3135
  }) {
3136
- var _a172;
3136
+ var _a173;
3137
3137
  return {
3138
3138
  "ai.model.provider": model.provider,
3139
3139
  "ai.model.id": model.modelId,
@@ -3143,7 +3143,7 @@ function getBaseTelemetryAttributes({
3143
3143
  return attributes;
3144
3144
  }, {}),
3145
3145
  // add metadata as attributes:
3146
- ...Object.entries((_a172 = telemetry == null ? void 0 : telemetry.metadata) != null ? _a172 : {}).reduce(
3146
+ ...Object.entries((_a173 = telemetry == null ? void 0 : telemetry.metadata) != null ? _a173 : {}).reduce(
3147
3147
  (attributes, [key, value]) => {
3148
3148
  attributes[`ai.telemetry.metadata.${key}`] = value;
3149
3149
  return attributes;
@@ -3163,7 +3163,7 @@ var noopTracer = {
3163
3163
  startSpan() {
3164
3164
  return noopSpan;
3165
3165
  },
3166
- startActiveSpan(name172, arg1, arg2, arg3) {
3166
+ startActiveSpan(name173, arg1, arg2, arg3) {
3167
3167
  if (typeof arg1 === "function") {
3168
3168
  return arg1(noopSpan);
3169
3169
  }
@@ -3228,13 +3228,13 @@ function getTracer({
3228
3228
  return trace.getTracer("ai");
3229
3229
  }
3230
3230
  function recordSpan({
3231
- name: name172,
3231
+ name: name173,
3232
3232
  tracer,
3233
3233
  attributes,
3234
3234
  fn,
3235
3235
  endWhenDone = true
3236
3236
  }) {
3237
- return tracer.startActiveSpan(name172, { attributes }, async (span) => {
3237
+ return tracer.startActiveSpan(name173, { attributes }, async (span) => {
3238
3238
  try {
3239
3239
  const result = await fn(span);
3240
3240
  if (endWhenDone) {
@@ -3359,14 +3359,14 @@ async function embedMany({
3359
3359
  }),
3360
3360
  tracer,
3361
3361
  fn: async (doEmbedSpan) => {
3362
- var _a172;
3362
+ var _a173;
3363
3363
  const modelResponse = await model.doEmbed({
3364
3364
  values,
3365
3365
  abortSignal,
3366
3366
  headers
3367
3367
  });
3368
3368
  const embeddings3 = modelResponse.embeddings;
3369
- const usage2 = (_a172 = modelResponse.usage) != null ? _a172 : { tokens: NaN };
3369
+ const usage2 = (_a173 = modelResponse.usage) != null ? _a173 : { tokens: NaN };
3370
3370
  doEmbedSpan.setAttributes(
3371
3371
  selectTelemetryAttributes({
3372
3372
  telemetry,
@@ -3418,14 +3418,14 @@ async function embedMany({
3418
3418
  }),
3419
3419
  tracer,
3420
3420
  fn: async (doEmbedSpan) => {
3421
- var _a172;
3421
+ var _a173;
3422
3422
  const modelResponse = await model.doEmbed({
3423
3423
  values: chunk,
3424
3424
  abortSignal,
3425
3425
  headers
3426
3426
  });
3427
3427
  const embeddings2 = modelResponse.embeddings;
3428
- const usage2 = (_a172 = modelResponse.usage) != null ? _a172 : { tokens: NaN };
3428
+ const usage2 = (_a173 = modelResponse.usage) != null ? _a173 : { tokens: NaN };
3429
3429
  doEmbedSpan.setAttributes(
3430
3430
  selectTelemetryAttributes({
3431
3431
  telemetry,
@@ -3502,8 +3502,8 @@ var dataContentSchema = z.union([
3502
3502
  z.custom(
3503
3503
  // Buffer might not be available in some environments such as CloudFlare:
3504
3504
  (value) => {
3505
- var _a172, _b17;
3506
- return (_b17 = (_a172 = globalThis.Buffer) == null ? void 0 : _a172.isBuffer(value)) != null ? _b17 : false;
3505
+ var _a173, _b17;
3506
+ return (_b17 = (_a173 = globalThis.Buffer) == null ? void 0 : _a173.isBuffer(value)) != null ? _b17 : false;
3507
3507
  },
3508
3508
  { message: "Must be a Buffer" }
3509
3509
  )
@@ -3707,16 +3707,16 @@ var object = ({
3707
3707
  }
3708
3708
  }
3709
3709
  },
3710
- parseOutput({ text: text22 }, context) {
3710
+ parseOutput({ text: text22 }, context2) {
3711
3711
  const parseResult = safeParseJSON({ text: text22 });
3712
3712
  if (!parseResult.success) {
3713
3713
  throw new NoObjectGeneratedError({
3714
3714
  message: "No object generated: could not parse the response.",
3715
3715
  cause: parseResult.error,
3716
3716
  text: text22,
3717
- response: context.response,
3718
- usage: context.usage,
3719
- finishReason: context.finishReason
3717
+ response: context2.response,
3718
+ usage: context2.usage,
3719
+ finishReason: context2.finishReason
3720
3720
  });
3721
3721
  }
3722
3722
  const validationResult = safeValidateTypes({
@@ -3728,9 +3728,9 @@ var object = ({
3728
3728
  message: "No object generated: response did not match schema.",
3729
3729
  cause: validationResult.error,
3730
3730
  text: text22,
3731
- response: context.response,
3732
- usage: context.usage,
3733
- finishReason: context.finishReason
3731
+ response: context2.response,
3732
+ usage: context2.usage,
3733
+ finishReason: context2.finishReason
3734
3734
  });
3735
3735
  }
3736
3736
  return validationResult.value;
@@ -3992,7 +3992,7 @@ function toDataStreamInternal(stream, callbacks) {
3992
3992
  return stream.pipeThrough(
3993
3993
  new TransformStream({
3994
3994
  transform: async (value, controller) => {
3995
- var _a172;
3995
+ var _a173;
3996
3996
  if (typeof value === "string") {
3997
3997
  controller.enqueue(value);
3998
3998
  return;
@@ -4000,7 +4000,7 @@ function toDataStreamInternal(stream, callbacks) {
4000
4000
  if ("event" in value) {
4001
4001
  if (value.event === "on_chat_model_stream") {
4002
4002
  forwardAIMessageChunk(
4003
- (_a172 = value.data) == null ? void 0 : _a172.chunk,
4003
+ (_a173 = value.data) == null ? void 0 : _a173.chunk,
4004
4004
  controller
4005
4005
  );
4006
4006
  }
@@ -4023,7 +4023,7 @@ function toDataStream(stream, callbacks) {
4023
4023
  );
4024
4024
  }
4025
4025
  function toDataStreamResponse(stream, options) {
4026
- var _a172;
4026
+ var _a173;
4027
4027
  const dataStream = toDataStreamInternal(
4028
4028
  stream,
4029
4029
  options == null ? void 0 : options.callbacks
@@ -4032,7 +4032,7 @@ function toDataStreamResponse(stream, options) {
4032
4032
  const init = options == null ? void 0 : options.init;
4033
4033
  const responseStream = data ? mergeStreams(data.stream, dataStream) : dataStream;
4034
4034
  return new Response(responseStream, {
4035
- status: (_a172 = init == null ? void 0 : init.status) != null ? _a172 : 200,
4035
+ status: (_a173 = init == null ? void 0 : init.status) != null ? _a173 : 200,
4036
4036
  statusText: init == null ? void 0 : init.statusText,
4037
4037
  headers: prepareResponseHeaders(init == null ? void 0 : init.headers, {
4038
4038
  contentType: "text/plain; charset=utf-8",
@@ -4083,14 +4083,14 @@ function toDataStream2(stream, callbacks) {
4083
4083
  );
4084
4084
  }
4085
4085
  function toDataStreamResponse2(stream, options = {}) {
4086
- var _a172;
4086
+ var _a173;
4087
4087
  const { init, data, callbacks } = options;
4088
4088
  const dataStream = toDataStreamInternal2(stream, callbacks).pipeThrough(
4089
4089
  new TextEncoderStream()
4090
4090
  );
4091
4091
  const responseStream = data ? mergeStreams(data.stream, dataStream) : dataStream;
4092
4092
  return new Response(responseStream, {
4093
- status: (_a172 = init == null ? void 0 : init.status) != null ? _a172 : 200,
4093
+ status: (_a173 = init == null ? void 0 : init.status) != null ? _a173 : 200,
4094
4094
  statusText: init == null ? void 0 : init.statusText,
4095
4095
  headers: prepareResponseHeaders(init == null ? void 0 : init.headers, {
4096
4096
  contentType: "text/plain; charset=utf-8",
@@ -4125,13 +4125,13 @@ var _AISDKError3 = class _AISDKError22 extends Error {
4125
4125
  * @param {unknown} [params.cause] - The underlying cause of the error.
4126
4126
  */
4127
4127
  constructor({
4128
- name: name144,
4128
+ name: name145,
4129
4129
  message,
4130
4130
  cause
4131
4131
  }) {
4132
4132
  super(message);
4133
4133
  this[_a17] = true;
4134
- this.name = name144;
4134
+ this.name = name145;
4135
4135
  this.cause = cause;
4136
4136
  }
4137
4137
  /**
@@ -4142,8 +4142,8 @@ var _AISDKError3 = class _AISDKError22 extends Error {
4142
4142
  static isInstance(error) {
4143
4143
  return _AISDKError22.hasMarker(error, marker17);
4144
4144
  }
4145
- static hasMarker(error, marker154) {
4146
- const markerSymbol = Symbol.for(marker154);
4145
+ static hasMarker(error, marker155) {
4146
+ const markerSymbol = Symbol.for(marker155);
4147
4147
  return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
4148
4148
  }
4149
4149
  };
@@ -4517,11 +4517,11 @@ function handleFetchError({
4517
4517
  return error;
4518
4518
  }
4519
4519
  function getRuntimeEnvironmentUserAgent(globalThisAny = globalThis) {
4520
- var _a154, _b17, _c;
4520
+ var _a155, _b17, _c;
4521
4521
  if (globalThisAny.window) {
4522
4522
  return `runtime/browser`;
4523
4523
  }
4524
- if ((_a154 = globalThisAny.navigator) == null ? void 0 : _a154.userAgent) {
4524
+ if ((_a155 = globalThisAny.navigator) == null ? void 0 : _a155.userAgent) {
4525
4525
  return `runtime/${globalThisAny.navigator.userAgent.toLowerCase()}`;
4526
4526
  }
4527
4527
  if ((_c = (_b17 = globalThisAny.process) == null ? void 0 : _b17.versions) == null ? void 0 : _c.node) {
@@ -5043,11 +5043,11 @@ function parseAnyDef2() {
5043
5043
  return {};
5044
5044
  }
5045
5045
  function parseArrayDef2(def, refs) {
5046
- var _a154, _b17, _c;
5046
+ var _a155, _b17, _c;
5047
5047
  const res = {
5048
5048
  type: "array"
5049
5049
  };
5050
- if (((_a154 = def.type) == null ? void 0 : _a154._def) && ((_c = (_b17 = def.type) == null ? void 0 : _b17._def) == null ? void 0 : _c.typeName) !== ZodFirstPartyTypeKind.ZodAny) {
5050
+ if (((_a155 = def.type) == null ? void 0 : _a155._def) && ((_c = (_b17 = def.type) == null ? void 0 : _b17._def) == null ? void 0 : _c.typeName) !== ZodFirstPartyTypeKind.ZodAny) {
5051
5051
  res.items = parseDef2(def.type._def, {
5052
5052
  ...refs,
5053
5053
  currentPath: [...refs.currentPath, "items"]
@@ -5406,8 +5406,8 @@ function escapeNonAlphaNumeric2(source) {
5406
5406
  return result;
5407
5407
  }
5408
5408
  function addFormat2(schema, value, message, refs) {
5409
- var _a154;
5410
- if (schema.format || ((_a154 = schema.anyOf) == null ? void 0 : _a154.some((x) => x.format))) {
5409
+ var _a155;
5410
+ if (schema.format || ((_a155 = schema.anyOf) == null ? void 0 : _a155.some((x) => x.format))) {
5411
5411
  if (!schema.anyOf) {
5412
5412
  schema.anyOf = [];
5413
5413
  }
@@ -5426,8 +5426,8 @@ function addFormat2(schema, value, message, refs) {
5426
5426
  }
5427
5427
  }
5428
5428
  function addPattern2(schema, regex, message, refs) {
5429
- var _a154;
5430
- if (schema.pattern || ((_a154 = schema.allOf) == null ? void 0 : _a154.some((x) => x.pattern))) {
5429
+ var _a155;
5430
+ if (schema.pattern || ((_a155 = schema.allOf) == null ? void 0 : _a155.some((x) => x.pattern))) {
5431
5431
  if (!schema.allOf) {
5432
5432
  schema.allOf = [];
5433
5433
  }
@@ -5446,7 +5446,7 @@ function addPattern2(schema, regex, message, refs) {
5446
5446
  }
5447
5447
  }
5448
5448
  function stringifyRegExpWithFlags2(regex, refs) {
5449
- var _a154;
5449
+ var _a155;
5450
5450
  if (!refs.applyRegexFlags || !regex.flags) {
5451
5451
  return regex.source;
5452
5452
  }
@@ -5476,7 +5476,7 @@ function stringifyRegExpWithFlags2(regex, refs) {
5476
5476
  pattern += source[i];
5477
5477
  pattern += `${source[i - 2]}-${source[i]}`.toUpperCase();
5478
5478
  inCharRange = false;
5479
- } else if (source[i + 1] === "-" && ((_a154 = source[i + 2]) == null ? void 0 : _a154.match(/[a-z]/))) {
5479
+ } else if (source[i + 1] === "-" && ((_a155 = source[i + 2]) == null ? void 0 : _a155.match(/[a-z]/))) {
5480
5480
  pattern += source[i];
5481
5481
  inCharRange = true;
5482
5482
  } else {
@@ -5518,13 +5518,13 @@ function stringifyRegExpWithFlags2(regex, refs) {
5518
5518
  return pattern;
5519
5519
  }
5520
5520
  function parseRecordDef2(def, refs) {
5521
- var _a154, _b17, _c, _d, _e, _f;
5521
+ var _a155, _b17, _c, _d, _e, _f;
5522
5522
  const schema = {
5523
5523
  type: "object",
5524
- additionalProperties: (_a154 = parseDef2(def.valueType._def, {
5524
+ additionalProperties: (_a155 = parseDef2(def.valueType._def, {
5525
5525
  ...refs,
5526
5526
  currentPath: [...refs.currentPath, "additionalProperties"]
5527
- })) != null ? _a154 : refs.allowedAdditionalProperties
5527
+ })) != null ? _a155 : refs.allowedAdditionalProperties
5528
5528
  };
5529
5529
  if (((_b17 = def.keyType) == null ? void 0 : _b17._def.typeName) === ZodFirstPartyTypeKind.ZodString && ((_c = def.keyType._def.checks) == null ? void 0 : _c.length)) {
5530
5530
  const { type, ...keyType } = parseStringDef2(def.keyType._def, refs);
@@ -5781,8 +5781,8 @@ function safeIsOptional2(schema) {
5781
5781
  }
5782
5782
  }
5783
5783
  var parseOptionalDef2 = (def, refs) => {
5784
- var _a154;
5785
- if (refs.currentPath.toString() === ((_a154 = refs.propertyPath) == null ? void 0 : _a154.toString())) {
5784
+ var _a155;
5785
+ if (refs.currentPath.toString() === ((_a155 = refs.propertyPath) == null ? void 0 : _a155.toString())) {
5786
5786
  return parseDef2(def.innerType._def, refs);
5787
5787
  }
5788
5788
  const innerSchema = parseDef2(def.innerType._def, {
@@ -5952,10 +5952,10 @@ var selectParser2 = (def, typeName, refs) => {
5952
5952
  }
5953
5953
  };
5954
5954
  function parseDef2(def, refs, forceResolution = false) {
5955
- var _a154;
5955
+ var _a155;
5956
5956
  const seenItem = refs.seen.get(def);
5957
5957
  if (refs.override) {
5958
- const overrideResult = (_a154 = refs.override) == null ? void 0 : _a154.call(
5958
+ const overrideResult = (_a155 = refs.override) == null ? void 0 : _a155.call(
5959
5959
  refs,
5960
5960
  def,
5961
5961
  refs,
@@ -6021,11 +6021,11 @@ var getRefs2 = (options) => {
6021
6021
  currentPath,
6022
6022
  propertyPath: void 0,
6023
6023
  seen: new Map(
6024
- Object.entries(_options.definitions).map(([name144, def]) => [
6024
+ Object.entries(_options.definitions).map(([name145, def]) => [
6025
6025
  def._def,
6026
6026
  {
6027
6027
  def: def._def,
6028
- path: [..._options.basePath, _options.definitionPath, name144],
6028
+ path: [..._options.basePath, _options.definitionPath, name145],
6029
6029
  // Resolution of references will be forced even though seen, so it's ok that the schema is undefined here for now.
6030
6030
  jsonSchema: void 0
6031
6031
  }
@@ -6034,7 +6034,7 @@ var getRefs2 = (options) => {
6034
6034
  };
6035
6035
  };
6036
6036
  var zodToJsonSchema2 = (schema, options) => {
6037
- var _a154;
6037
+ var _a155;
6038
6038
  const refs = getRefs2(options);
6039
6039
  let definitions = typeof options === "object" && options.definitions ? Object.entries(options.definitions).reduce(
6040
6040
  (acc, [name224, schema2]) => {
@@ -6053,31 +6053,31 @@ var zodToJsonSchema2 = (schema, options) => {
6053
6053
  },
6054
6054
  {}
6055
6055
  ) : void 0;
6056
- const name144 = typeof options === "string" ? options : (options == null ? void 0 : options.nameStrategy) === "title" ? void 0 : options == null ? void 0 : options.name;
6057
- const main = (_a154 = parseDef2(
6056
+ const name145 = typeof options === "string" ? options : (options == null ? void 0 : options.nameStrategy) === "title" ? void 0 : options == null ? void 0 : options.name;
6057
+ const main = (_a155 = parseDef2(
6058
6058
  schema._def,
6059
- name144 === void 0 ? refs : {
6059
+ name145 === void 0 ? refs : {
6060
6060
  ...refs,
6061
- currentPath: [...refs.basePath, refs.definitionPath, name144]
6061
+ currentPath: [...refs.basePath, refs.definitionPath, name145]
6062
6062
  },
6063
6063
  false
6064
- )) != null ? _a154 : parseAnyDef2();
6064
+ )) != null ? _a155 : parseAnyDef2();
6065
6065
  const title = typeof options === "object" && options.name !== void 0 && options.nameStrategy === "title" ? options.name : void 0;
6066
6066
  if (title !== void 0) {
6067
6067
  main.title = title;
6068
6068
  }
6069
- const combined = name144 === void 0 ? definitions ? {
6069
+ const combined = name145 === void 0 ? definitions ? {
6070
6070
  ...main,
6071
6071
  [refs.definitionPath]: definitions
6072
6072
  } : main : {
6073
6073
  $ref: [
6074
6074
  ...refs.$refStrategy === "relative" ? [] : refs.basePath,
6075
6075
  refs.definitionPath,
6076
- name144
6076
+ name145
6077
6077
  ].join("/"),
6078
6078
  [refs.definitionPath]: {
6079
6079
  ...definitions,
6080
- [name144]: main
6080
+ [name145]: main
6081
6081
  }
6082
6082
  };
6083
6083
  combined.$schema = "http://json-schema.org/draft-07/schema#";
@@ -6085,8 +6085,8 @@ var zodToJsonSchema2 = (schema, options) => {
6085
6085
  };
6086
6086
  var zod_to_json_schema_default = zodToJsonSchema2;
6087
6087
  function zod3Schema(zodSchema22, options) {
6088
- var _a154;
6089
- const useReferences = (_a154 = void 0 ) != null ? _a154 : false;
6088
+ var _a155;
6089
+ const useReferences = (_a155 = void 0 ) != null ? _a155 : false;
6090
6090
  return jsonSchema2(
6091
6091
  // defer json schema creation to avoid unnecessary computation when only validation is needed
6092
6092
  () => zod_to_json_schema_default(zodSchema22, {
@@ -6101,8 +6101,8 @@ function zod3Schema(zodSchema22, options) {
6101
6101
  );
6102
6102
  }
6103
6103
  function zod4Schema(zodSchema22, options) {
6104
- var _a154;
6105
- const useReferences = (_a154 = void 0 ) != null ? _a154 : false;
6104
+ var _a155;
6105
+ const useReferences = (_a155 = void 0 ) != null ? _a155 : false;
6106
6106
  return jsonSchema2(
6107
6107
  // defer json schema creation to avoid unnecessary computation when only validation is needed
6108
6108
  () => z4.toJSONSchema(zodSchema22, {
@@ -6165,8 +6165,8 @@ var require_get_context = __commonJS({
6165
6165
  var __getOwnPropNames2 = Object.getOwnPropertyNames;
6166
6166
  var __hasOwnProp2 = Object.prototype.hasOwnProperty;
6167
6167
  var __export22 = (target, all) => {
6168
- for (var name162 in all)
6169
- __defProp22(target, name162, { get: all[name162], enumerable: true });
6168
+ for (var name163 in all)
6169
+ __defProp22(target, name163, { get: all[name163], enumerable: true });
6170
6170
  };
6171
6171
  var __copyProps2 = (to, from, except, desc) => {
6172
6172
  if (from && typeof from === "object" || typeof from === "function") {
@@ -6197,8 +6197,8 @@ var require_get_vercel_oidc_token = __commonJS({
6197
6197
  var __getOwnPropNames2 = Object.getOwnPropertyNames;
6198
6198
  var __hasOwnProp2 = Object.prototype.hasOwnProperty;
6199
6199
  var __export22 = (target, all) => {
6200
- for (var name162 in all)
6201
- __defProp22(target, name162, { get: all[name162], enumerable: true });
6200
+ for (var name163 in all)
6201
+ __defProp22(target, name163, { get: all[name163], enumerable: true });
6202
6202
  };
6203
6203
  var __copyProps2 = (to, from, except, desc) => {
6204
6204
  if (from && typeof from === "object" || typeof from === "function") {
@@ -6261,8 +6261,8 @@ var require_dist = __commonJS({
6261
6261
  var __getOwnPropNames2 = Object.getOwnPropertyNames;
6262
6262
  var __hasOwnProp2 = Object.prototype.hasOwnProperty;
6263
6263
  var __export22 = (target, all) => {
6264
- for (var name162 in all)
6265
- __defProp22(target, name162, { get: all[name162], enumerable: true });
6264
+ for (var name163 in all)
6265
+ __defProp22(target, name163, { get: all[name163], enumerable: true });
6266
6266
  };
6267
6267
  var __copyProps2 = (to, from, except, desc) => {
6268
6268
  if (from && typeof from === "object" || typeof from === "function") {
@@ -7215,11 +7215,11 @@ var major2 = VERSION22.split(".")[0];
7215
7215
  var GLOBAL_OPENTELEMETRY_API_KEY2 = /* @__PURE__ */ Symbol.for("opentelemetry.js.api." + major2);
7216
7216
  var _global2 = _globalThis2;
7217
7217
  function registerGlobal2(type, instance, diag, allowOverride) {
7218
- var _a162;
7218
+ var _a163;
7219
7219
  if (allowOverride === void 0) {
7220
7220
  allowOverride = false;
7221
7221
  }
7222
- var api = _global2[GLOBAL_OPENTELEMETRY_API_KEY2] = (_a162 = _global2[GLOBAL_OPENTELEMETRY_API_KEY2]) !== null && _a162 !== void 0 ? _a162 : {
7222
+ var api = _global2[GLOBAL_OPENTELEMETRY_API_KEY2] = (_a163 = _global2[GLOBAL_OPENTELEMETRY_API_KEY2]) !== null && _a163 !== void 0 ? _a163 : {
7223
7223
  version: VERSION22
7224
7224
  };
7225
7225
  if (!allowOverride && api[type]) {
@@ -7237,8 +7237,8 @@ function registerGlobal2(type, instance, diag, allowOverride) {
7237
7237
  return true;
7238
7238
  }
7239
7239
  function getGlobal2(type) {
7240
- var _a162, _b83;
7241
- var globalVersion = (_a162 = _global2[GLOBAL_OPENTELEMETRY_API_KEY2]) === null || _a162 === void 0 ? void 0 : _a162.version;
7240
+ var _a163, _b83;
7241
+ var globalVersion = (_a163 = _global2[GLOBAL_OPENTELEMETRY_API_KEY2]) === null || _a163 === void 0 ? void 0 : _a163.version;
7242
7242
  if (!globalVersion || !isCompatible2(globalVersion)) {
7243
7243
  return;
7244
7244
  }
@@ -7407,13 +7407,13 @@ var DiagAPI2 = (
7407
7407
  }
7408
7408
  var self = this;
7409
7409
  var setLogger = function(logger, optionsOrLogLevel) {
7410
- var _a162, _b83, _c;
7410
+ var _a163, _b83, _c;
7411
7411
  if (optionsOrLogLevel === void 0) {
7412
7412
  optionsOrLogLevel = { logLevel: DiagLogLevel2.INFO };
7413
7413
  }
7414
7414
  if (logger === self) {
7415
7415
  var err = new Error("Cannot use diag as the logger for itself. Please use a DiagLogger implementation like ConsoleDiagLogger or a custom implementation");
7416
- self.error((_a162 = err.stack) !== null && _a162 !== void 0 ? _a162 : err.message);
7416
+ self.error((_a163 = err.stack) !== null && _a163 !== void 0 ? _a163 : err.message);
7417
7417
  return false;
7418
7418
  }
7419
7419
  if (typeof optionsOrLogLevel === "number") {
@@ -7465,14 +7465,14 @@ var BaseContext2 = (
7465
7465
  return self._currentContext.get(key);
7466
7466
  };
7467
7467
  self.setValue = function(key, value) {
7468
- var context = new BaseContext22(self._currentContext);
7469
- context._currentContext.set(key, value);
7470
- return context;
7468
+ var context2 = new BaseContext22(self._currentContext);
7469
+ context2._currentContext.set(key, value);
7470
+ return context2;
7471
7471
  };
7472
7472
  self.deleteValue = function(key) {
7473
- var context = new BaseContext22(self._currentContext);
7474
- context._currentContext.delete(key);
7475
- return context;
7473
+ var context2 = new BaseContext22(self._currentContext);
7474
+ context2._currentContext.delete(key);
7475
+ return context2;
7476
7476
  };
7477
7477
  }
7478
7478
  return BaseContext22;
@@ -7577,16 +7577,16 @@ var ContextAPI2 = (
7577
7577
  ContextAPI22.prototype.active = function() {
7578
7578
  return this._getContextManager().active();
7579
7579
  };
7580
- ContextAPI22.prototype.with = function(context, fn, thisArg) {
7581
- var _a162;
7580
+ ContextAPI22.prototype.with = function(context2, fn, thisArg) {
7581
+ var _a163;
7582
7582
  var args = [];
7583
7583
  for (var _i = 3; _i < arguments.length; _i++) {
7584
7584
  args[_i - 3] = arguments[_i];
7585
7585
  }
7586
- return (_a162 = this._getContextManager()).with.apply(_a162, __spreadArray42([context, fn, thisArg], __read42(args), false));
7586
+ return (_a163 = this._getContextManager()).with.apply(_a163, __spreadArray42([context2, fn, thisArg], __read42(args), false));
7587
7587
  };
7588
- ContextAPI22.prototype.bind = function(context, target) {
7589
- return this._getContextManager().bind(context, target);
7588
+ ContextAPI22.prototype.bind = function(context2, target) {
7589
+ return this._getContextManager().bind(context2, target);
7590
7590
  };
7591
7591
  ContextAPI22.prototype._getContextManager = function() {
7592
7592
  return getGlobal2(API_NAME22) || NOOP_CONTEXT_MANAGER2;
@@ -7654,24 +7654,24 @@ var NonRecordingSpan2 = (
7654
7654
  })()
7655
7655
  );
7656
7656
  var SPAN_KEY2 = createContextKey2("OpenTelemetry Context Key SPAN");
7657
- function getSpan2(context) {
7658
- return context.getValue(SPAN_KEY2) || void 0;
7657
+ function getSpan2(context2) {
7658
+ return context2.getValue(SPAN_KEY2) || void 0;
7659
7659
  }
7660
7660
  function getActiveSpan2() {
7661
7661
  return getSpan2(ContextAPI2.getInstance().active());
7662
7662
  }
7663
- function setSpan2(context, span) {
7664
- return context.setValue(SPAN_KEY2, span);
7663
+ function setSpan2(context2, span) {
7664
+ return context2.setValue(SPAN_KEY2, span);
7665
7665
  }
7666
- function deleteSpan2(context) {
7667
- return context.deleteValue(SPAN_KEY2);
7666
+ function deleteSpan2(context2) {
7667
+ return context2.deleteValue(SPAN_KEY2);
7668
7668
  }
7669
- function setSpanContext2(context, spanContext) {
7670
- return setSpan2(context, new NonRecordingSpan2(spanContext));
7669
+ function setSpanContext2(context2, spanContext) {
7670
+ return setSpan2(context2, new NonRecordingSpan2(spanContext));
7671
7671
  }
7672
- function getSpanContext2(context) {
7673
- var _a162;
7674
- return (_a162 = getSpan2(context)) === null || _a162 === void 0 ? void 0 : _a162.spanContext();
7672
+ function getSpanContext2(context2) {
7673
+ var _a163;
7674
+ return (_a163 = getSpan2(context2)) === null || _a163 === void 0 ? void 0 : _a163.spanContext();
7675
7675
  }
7676
7676
  var VALID_TRACEID_REGEX2 = /^([0-9a-f]{32})$/i;
7677
7677
  var VALID_SPANID_REGEX2 = /^[0-9a-f]{16}$/i;
@@ -7693,22 +7693,22 @@ var NoopTracer2 = (
7693
7693
  (function() {
7694
7694
  function NoopTracer22() {
7695
7695
  }
7696
- NoopTracer22.prototype.startSpan = function(name162, options, context) {
7697
- if (context === void 0) {
7698
- context = contextApi2.active();
7696
+ NoopTracer22.prototype.startSpan = function(name163, options, context2) {
7697
+ if (context2 === void 0) {
7698
+ context2 = contextApi2.active();
7699
7699
  }
7700
7700
  var root = Boolean(options === null || options === void 0 ? void 0 : options.root);
7701
7701
  if (root) {
7702
7702
  return new NonRecordingSpan2();
7703
7703
  }
7704
- var parentFromContext = context && getSpanContext2(context);
7704
+ var parentFromContext = context2 && getSpanContext2(context2);
7705
7705
  if (isSpanContext2(parentFromContext) && isSpanContextValid2(parentFromContext)) {
7706
7706
  return new NonRecordingSpan2(parentFromContext);
7707
7707
  } else {
7708
7708
  return new NonRecordingSpan2();
7709
7709
  }
7710
7710
  };
7711
- NoopTracer22.prototype.startActiveSpan = function(name162, arg2, arg3, arg4) {
7711
+ NoopTracer22.prototype.startActiveSpan = function(name163, arg2, arg3, arg4) {
7712
7712
  var opts;
7713
7713
  var ctx;
7714
7714
  var fn;
@@ -7725,7 +7725,7 @@ var NoopTracer2 = (
7725
7725
  fn = arg4;
7726
7726
  }
7727
7727
  var parentContext = ctx !== null && ctx !== void 0 ? ctx : contextApi2.active();
7728
- var span = this.startSpan(name162, opts, parentContext);
7728
+ var span = this.startSpan(name163, opts, parentContext);
7729
7729
  var contextWithSpanSet = setSpan2(parentContext, span);
7730
7730
  return contextApi2.with(contextWithSpanSet, fn, void 0, span);
7731
7731
  };
@@ -7739,14 +7739,14 @@ var NOOP_TRACER2 = new NoopTracer2();
7739
7739
  var ProxyTracer2 = (
7740
7740
  /** @class */
7741
7741
  (function() {
7742
- function ProxyTracer22(_provider, name162, version, options) {
7742
+ function ProxyTracer22(_provider, name163, version, options) {
7743
7743
  this._provider = _provider;
7744
- this.name = name162;
7744
+ this.name = name163;
7745
7745
  this.version = version;
7746
7746
  this.options = options;
7747
7747
  }
7748
- ProxyTracer22.prototype.startSpan = function(name162, options, context) {
7749
- return this._getTracer().startSpan(name162, options, context);
7748
+ ProxyTracer22.prototype.startSpan = function(name163, options, context2) {
7749
+ return this._getTracer().startSpan(name163, options, context2);
7750
7750
  };
7751
7751
  ProxyTracer22.prototype.startActiveSpan = function(_name, _options, _context, _fn) {
7752
7752
  var tracer = this._getTracer();
@@ -7783,20 +7783,20 @@ var ProxyTracerProvider2 = (
7783
7783
  (function() {
7784
7784
  function ProxyTracerProvider22() {
7785
7785
  }
7786
- ProxyTracerProvider22.prototype.getTracer = function(name162, version, options) {
7787
- var _a162;
7788
- return (_a162 = this.getDelegateTracer(name162, version, options)) !== null && _a162 !== void 0 ? _a162 : new ProxyTracer2(this, name162, version, options);
7786
+ ProxyTracerProvider22.prototype.getTracer = function(name163, version, options) {
7787
+ var _a163;
7788
+ return (_a163 = this.getDelegateTracer(name163, version, options)) !== null && _a163 !== void 0 ? _a163 : new ProxyTracer2(this, name163, version, options);
7789
7789
  };
7790
7790
  ProxyTracerProvider22.prototype.getDelegate = function() {
7791
- var _a162;
7792
- return (_a162 = this._delegate) !== null && _a162 !== void 0 ? _a162 : NOOP_TRACER_PROVIDER2;
7791
+ var _a163;
7792
+ return (_a163 = this._delegate) !== null && _a163 !== void 0 ? _a163 : NOOP_TRACER_PROVIDER2;
7793
7793
  };
7794
7794
  ProxyTracerProvider22.prototype.setDelegate = function(delegate) {
7795
7795
  this._delegate = delegate;
7796
7796
  };
7797
- ProxyTracerProvider22.prototype.getDelegateTracer = function(name162, version, options) {
7798
- var _a162;
7799
- return (_a162 = this._delegate) === null || _a162 === void 0 ? void 0 : _a162.getTracer(name162, version, options);
7797
+ ProxyTracerProvider22.prototype.getDelegateTracer = function(name163, version, options) {
7798
+ var _a163;
7799
+ return (_a163 = this._delegate) === null || _a163 === void 0 ? void 0 : _a163.getTracer(name163, version, options);
7800
7800
  };
7801
7801
  return ProxyTracerProvider22;
7802
7802
  })()
@@ -7838,8 +7838,8 @@ var TraceAPI2 = (
7838
7838
  TraceAPI22.prototype.getTracerProvider = function() {
7839
7839
  return getGlobal2(API_NAME32) || this._proxyTracerProvider;
7840
7840
  };
7841
- TraceAPI22.prototype.getTracer = function(name162, version) {
7842
- return this.getTracerProvider().getTracer(name162, version);
7841
+ TraceAPI22.prototype.getTracer = function(name163, version) {
7842
+ return this.getTracerProvider().getTracer(name163, version);
7843
7843
  };
7844
7844
  TraceAPI22.prototype.disable = function() {
7845
7845
  unregisterGlobal2(API_NAME32, DiagAPI2.instance());
@@ -7851,8 +7851,8 @@ var TraceAPI2 = (
7851
7851
  var trace2 = TraceAPI2.getInstance();
7852
7852
  var __defProp3 = Object.defineProperty;
7853
7853
  var __export2 = (target, all) => {
7854
- for (var name162 in all)
7855
- __defProp3(target, name162, { get: all[name162], enumerable: true });
7854
+ for (var name163 in all)
7855
+ __defProp3(target, name163, { get: all[name163], enumerable: true });
7856
7856
  };
7857
7857
  var name222 = "AI_InvalidArgumentError";
7858
7858
  var marker222 = `vercel.ai.error.${name222}`;
@@ -7950,8 +7950,8 @@ function resolveEmbeddingModel(model) {
7950
7950
  );
7951
7951
  }
7952
7952
  function getGlobalProvider() {
7953
- var _a162;
7954
- return (_a162 = globalThis.AI_SDK_DEFAULT_PROVIDER) != null ? _a162 : gateway;
7953
+ var _a163;
7954
+ return (_a163 = globalThis.AI_SDK_DEFAULT_PROVIDER) != null ? _a163 : gateway;
7955
7955
  }
7956
7956
  var VERSION32 = "5.0.101";
7957
7957
  var dataContentSchema2 = z$1.union([
@@ -7961,8 +7961,8 @@ var dataContentSchema2 = z$1.union([
7961
7961
  z$1.custom(
7962
7962
  // Buffer might not be available in some environments such as CloudFlare:
7963
7963
  (value) => {
7964
- var _a162, _b83;
7965
- return (_b83 = (_a162 = globalThis.Buffer) == null ? void 0 : _a162.isBuffer(value)) != null ? _b83 : false;
7964
+ var _a163, _b83;
7965
+ return (_b83 = (_a163 = globalThis.Buffer) == null ? void 0 : _a163.isBuffer(value)) != null ? _b83 : false;
7966
7966
  },
7967
7967
  { message: "Must be a Buffer" }
7968
7968
  )
@@ -8114,7 +8114,7 @@ function getBaseTelemetryAttributes2({
8114
8114
  telemetry,
8115
8115
  headers
8116
8116
  }) {
8117
- var _a162;
8117
+ var _a163;
8118
8118
  return {
8119
8119
  "ai.model.provider": model.provider,
8120
8120
  "ai.model.id": model.modelId,
@@ -8124,7 +8124,7 @@ function getBaseTelemetryAttributes2({
8124
8124
  return attributes;
8125
8125
  }, {}),
8126
8126
  // add metadata as attributes:
8127
- ...Object.entries((_a162 = telemetry == null ? void 0 : telemetry.metadata) != null ? _a162 : {}).reduce(
8127
+ ...Object.entries((_a163 = telemetry == null ? void 0 : telemetry.metadata) != null ? _a163 : {}).reduce(
8128
8128
  (attributes, [key, value]) => {
8129
8129
  attributes[`ai.telemetry.metadata.${key}`] = value;
8130
8130
  return attributes;
@@ -8144,7 +8144,7 @@ var noopTracer2 = {
8144
8144
  startSpan() {
8145
8145
  return noopSpan2;
8146
8146
  },
8147
- startActiveSpan(name162, arg1, arg2, arg3) {
8147
+ startActiveSpan(name163, arg1, arg2, arg3) {
8148
8148
  if (typeof arg1 === "function") {
8149
8149
  return arg1(noopSpan2);
8150
8150
  }
@@ -8209,13 +8209,13 @@ function getTracer2({
8209
8209
  return trace2.getTracer("ai");
8210
8210
  }
8211
8211
  function recordSpan2({
8212
- name: name162,
8212
+ name: name163,
8213
8213
  tracer,
8214
8214
  attributes,
8215
8215
  fn,
8216
8216
  endWhenDone = true
8217
8217
  }) {
8218
- return tracer.startActiveSpan(name162, { attributes }, async (span) => {
8218
+ return tracer.startActiveSpan(name163, { attributes }, async (span) => {
8219
8219
  try {
8220
8220
  const result = await fn(span);
8221
8221
  if (endWhenDone) {
@@ -8787,7 +8787,7 @@ async function embedMany2({
8787
8787
  }),
8788
8788
  tracer,
8789
8789
  fn: async (span) => {
8790
- var _a162;
8790
+ var _a163;
8791
8791
  const [maxEmbeddingsPerCall, supportsParallelCalls] = await Promise.all([
8792
8792
  model.maxEmbeddingsPerCall,
8793
8793
  model.supportsParallelCalls
@@ -8813,7 +8813,7 @@ async function embedMany2({
8813
8813
  }),
8814
8814
  tracer,
8815
8815
  fn: async (doEmbedSpan) => {
8816
- var _a172;
8816
+ var _a173;
8817
8817
  const modelResponse = await model.doEmbed({
8818
8818
  values,
8819
8819
  abortSignal,
@@ -8821,7 +8821,7 @@ async function embedMany2({
8821
8821
  providerOptions
8822
8822
  });
8823
8823
  const embeddings3 = modelResponse.embeddings;
8824
- const usage2 = (_a172 = modelResponse.usage) != null ? _a172 : { tokens: NaN };
8824
+ const usage2 = (_a173 = modelResponse.usage) != null ? _a173 : { tokens: NaN };
8825
8825
  doEmbedSpan.setAttributes(
8826
8826
  selectTelemetryAttributes2({
8827
8827
  telemetry,
@@ -8895,7 +8895,7 @@ async function embedMany2({
8895
8895
  }),
8896
8896
  tracer,
8897
8897
  fn: async (doEmbedSpan) => {
8898
- var _a172;
8898
+ var _a173;
8899
8899
  const modelResponse = await model.doEmbed({
8900
8900
  values: chunk,
8901
8901
  abortSignal,
@@ -8903,7 +8903,7 @@ async function embedMany2({
8903
8903
  providerOptions
8904
8904
  });
8905
8905
  const embeddings2 = modelResponse.embeddings;
8906
- const usage = (_a172 = modelResponse.usage) != null ? _a172 : { tokens: NaN };
8906
+ const usage = (_a173 = modelResponse.usage) != null ? _a173 : { tokens: NaN };
8907
8907
  doEmbedSpan.setAttributes(
8908
8908
  selectTelemetryAttributes2({
8909
8909
  telemetry,
@@ -8940,7 +8940,7 @@ async function embedMany2({
8940
8940
  result.providerMetadata
8941
8941
  )) {
8942
8942
  providerMetadata[providerName] = {
8943
- ...(_a162 = providerMetadata[providerName]) != null ? _a162 : {},
8943
+ ...(_a163 = providerMetadata[providerName]) != null ? _a163 : {},
8944
8944
  ...metadata
8945
8945
  };
8946
8946
  }
@@ -9023,16 +9023,16 @@ var object2 = ({
9023
9023
  }
9024
9024
  }
9025
9025
  },
9026
- async parseOutput({ text: text22 }, context) {
9026
+ async parseOutput({ text: text22 }, context2) {
9027
9027
  const parseResult = await safeParseJSON2({ text: text22 });
9028
9028
  if (!parseResult.success) {
9029
9029
  throw new NoObjectGeneratedError2({
9030
9030
  message: "No object generated: could not parse the response.",
9031
9031
  cause: parseResult.error,
9032
9032
  text: text22,
9033
- response: context.response,
9034
- usage: context.usage,
9035
- finishReason: context.finishReason
9033
+ response: context2.response,
9034
+ usage: context2.usage,
9035
+ finishReason: context2.finishReason
9036
9036
  });
9037
9037
  }
9038
9038
  const validationResult = await safeValidateTypes2({
@@ -9044,9 +9044,9 @@ var object2 = ({
9044
9044
  message: "No object generated: response did not match schema.",
9045
9045
  cause: validationResult.error,
9046
9046
  text: text22,
9047
- response: context.response,
9048
- usage: context.usage,
9049
- finishReason: context.finishReason
9047
+ response: context2.response,
9048
+ usage: context2.usage,
9049
+ finishReason: context2.finishReason
9050
9050
  });
9051
9051
  }
9052
9052
  return validationResult.value;
@@ -9196,34 +9196,61 @@ var symbol135 = Symbol.for(marker135);
9196
9196
  var _a135;
9197
9197
  var _b13;
9198
9198
  var TypeValidationError3 = class _TypeValidationError4 extends (_b13 = AISDKError3, _a135 = symbol135, _b13) {
9199
- constructor({ value, cause }) {
9199
+ constructor({
9200
+ value,
9201
+ cause,
9202
+ context: context2
9203
+ }) {
9204
+ let contextPrefix = "Type validation failed";
9205
+ if (context2 == null ? void 0 : context2.field) {
9206
+ contextPrefix += ` for ${context2.field}`;
9207
+ }
9208
+ if ((context2 == null ? void 0 : context2.entityName) || (context2 == null ? void 0 : context2.entityId)) {
9209
+ contextPrefix += " (";
9210
+ const parts = [];
9211
+ if (context2.entityName) {
9212
+ parts.push(context2.entityName);
9213
+ }
9214
+ if (context2.entityId) {
9215
+ parts.push(`id: "${context2.entityId}"`);
9216
+ }
9217
+ contextPrefix += parts.join(", ");
9218
+ contextPrefix += ")";
9219
+ }
9200
9220
  super({
9201
9221
  name: name125,
9202
- message: `Type validation failed: Value: ${JSON.stringify(value)}.
9222
+ message: `${contextPrefix}: Value: ${JSON.stringify(value)}.
9203
9223
  Error message: ${getErrorMessage4(cause)}`,
9204
9224
  cause
9205
9225
  });
9206
9226
  this[_a135] = true;
9207
9227
  this.value = value;
9228
+ this.context = context2;
9208
9229
  }
9209
9230
  static isInstance(error) {
9210
9231
  return AISDKError3.hasMarker(error, marker135);
9211
9232
  }
9212
9233
  /**
9213
9234
  * Wraps an error into a TypeValidationError.
9214
- * If the cause is already a TypeValidationError with the same value, it returns the cause.
9235
+ * If the cause is already a TypeValidationError with the same value and context, it returns the cause.
9215
9236
  * Otherwise, it creates a new TypeValidationError.
9216
9237
  *
9217
9238
  * @param {Object} params - The parameters for wrapping the error.
9218
9239
  * @param {unknown} params.value - The value that failed validation.
9219
9240
  * @param {unknown} params.cause - The original error or cause of the validation failure.
9241
+ * @param {TypeValidationContext} params.context - Optional context about what is being validated.
9220
9242
  * @returns {TypeValidationError} A TypeValidationError instance.
9221
9243
  */
9222
9244
  static wrap({
9223
9245
  value,
9224
- cause
9246
+ cause,
9247
+ context: context2
9225
9248
  }) {
9226
- return _TypeValidationError4.isInstance(cause) && cause.value === value ? cause : new _TypeValidationError4({ value, cause });
9249
+ var _a1522, _b152, _c;
9250
+ if (_TypeValidationError4.isInstance(cause) && cause.value === value && ((_a1522 = cause.context) == null ? void 0 : _a1522.field) === (context2 == null ? void 0 : context2.field) && ((_b152 = cause.context) == null ? void 0 : _b152.entityName) === (context2 == null ? void 0 : context2.entityName) && ((_c = cause.context) == null ? void 0 : _c.entityId) === (context2 == null ? void 0 : context2.entityId)) {
9251
+ return cause;
9252
+ }
9253
+ return new _TypeValidationError4({ value, cause, context: context2 });
9227
9254
  }
9228
9255
  };
9229
9256
  var ParseError2 = class extends Error {
@@ -9389,6 +9416,14 @@ function createAbortError2() {
9389
9416
  function extractResponseHeaders2(response) {
9390
9417
  return Object.fromEntries([...response.headers]);
9391
9418
  }
9419
+ var { btoa: btoa3} = globalThis;
9420
+ function convertUint8ArrayToBase643(array2) {
9421
+ let latin1string = "";
9422
+ for (let i = 0; i < array2.length; i++) {
9423
+ latin1string += String.fromCodePoint(array2[i]);
9424
+ }
9425
+ return btoa3(latin1string);
9426
+ }
9392
9427
  var createIdGenerator3 = ({
9393
9428
  prefix,
9394
9429
  size = 16,
@@ -9432,6 +9467,25 @@ function isAbortError3(error) {
9432
9467
  error.name === "TimeoutError");
9433
9468
  }
9434
9469
  var FETCH_FAILED_ERROR_MESSAGES2 = ["fetch failed", "failed to fetch"];
9470
+ var BUN_ERROR_CODES = [
9471
+ "ConnectionRefused",
9472
+ "ConnectionClosed",
9473
+ "FailedToOpenSocket",
9474
+ "ECONNRESET",
9475
+ "ECONNREFUSED",
9476
+ "ETIMEDOUT",
9477
+ "EPIPE"
9478
+ ];
9479
+ function isBunNetworkError(error) {
9480
+ if (!(error instanceof Error)) {
9481
+ return false;
9482
+ }
9483
+ const code = error.code;
9484
+ if (typeof code === "string" && BUN_ERROR_CODES.includes(code)) {
9485
+ return true;
9486
+ }
9487
+ return false;
9488
+ }
9435
9489
  function handleFetchError2({
9436
9490
  error,
9437
9491
  url,
@@ -9453,6 +9507,15 @@ function handleFetchError2({
9453
9507
  });
9454
9508
  }
9455
9509
  }
9510
+ if (isBunNetworkError(error)) {
9511
+ return new APICallError3({
9512
+ message: `Cannot connect to API: ${error.message}`,
9513
+ cause: error,
9514
+ url,
9515
+ requestBodyValues,
9516
+ isRetryable: true
9517
+ });
9518
+ }
9456
9519
  return error;
9457
9520
  }
9458
9521
  function getRuntimeEnvironmentUserAgent2(globalThisAny = globalThis) {
@@ -9501,7 +9564,7 @@ function withUserAgentSuffix2(headers, ...userAgentSuffixParts) {
9501
9564
  );
9502
9565
  return Object.fromEntries(normalizedHeaders.entries());
9503
9566
  }
9504
- var VERSION4 = "4.0.0";
9567
+ var VERSION4 = "4.0.13";
9505
9568
  var getOriginalFetch3 = () => globalThis.fetch;
9506
9569
  var getFromApi2 = async ({
9507
9570
  url,
@@ -9634,30 +9697,39 @@ function secureJsonParse2(text4) {
9634
9697
  }
9635
9698
  }
9636
9699
  function addAdditionalPropertiesToJsonSchema(jsonSchema22) {
9637
- if (jsonSchema22.type === "object") {
9700
+ if (jsonSchema22.type === "object" || Array.isArray(jsonSchema22.type) && jsonSchema22.type.includes("object")) {
9638
9701
  jsonSchema22.additionalProperties = false;
9639
- const properties = jsonSchema22.properties;
9702
+ const { properties } = jsonSchema22;
9640
9703
  if (properties != null) {
9641
- for (const property in properties) {
9642
- properties[property] = addAdditionalPropertiesToJsonSchema(
9643
- properties[property]
9644
- );
9704
+ for (const key of Object.keys(properties)) {
9705
+ properties[key] = visit(properties[key]);
9645
9706
  }
9646
9707
  }
9647
9708
  }
9648
- if (jsonSchema22.type === "array" && jsonSchema22.items != null) {
9649
- if (Array.isArray(jsonSchema22.items)) {
9650
- jsonSchema22.items = jsonSchema22.items.map(
9651
- (item) => addAdditionalPropertiesToJsonSchema(item)
9652
- );
9653
- } else {
9654
- jsonSchema22.items = addAdditionalPropertiesToJsonSchema(
9655
- jsonSchema22.items
9656
- );
9709
+ if (jsonSchema22.items != null) {
9710
+ jsonSchema22.items = Array.isArray(jsonSchema22.items) ? jsonSchema22.items.map(visit) : visit(jsonSchema22.items);
9711
+ }
9712
+ if (jsonSchema22.anyOf != null) {
9713
+ jsonSchema22.anyOf = jsonSchema22.anyOf.map(visit);
9714
+ }
9715
+ if (jsonSchema22.allOf != null) {
9716
+ jsonSchema22.allOf = jsonSchema22.allOf.map(visit);
9717
+ }
9718
+ if (jsonSchema22.oneOf != null) {
9719
+ jsonSchema22.oneOf = jsonSchema22.oneOf.map(visit);
9720
+ }
9721
+ const { definitions } = jsonSchema22;
9722
+ if (definitions != null) {
9723
+ for (const key of Object.keys(definitions)) {
9724
+ definitions[key] = visit(definitions[key]);
9657
9725
  }
9658
9726
  }
9659
9727
  return jsonSchema22;
9660
9728
  }
9729
+ function visit(def) {
9730
+ if (typeof def === "boolean") return def;
9731
+ return addAdditionalPropertiesToJsonSchema(def);
9732
+ }
9661
9733
  var ignoreOverride3 = /* @__PURE__ */ Symbol(
9662
9734
  "Let zodToJsonSchema decide on which parser to use"
9663
9735
  );
@@ -10774,9 +10846,11 @@ function asSchema3(schema) {
10774
10846
  }
10775
10847
  function standardSchema(standardSchema2) {
10776
10848
  return jsonSchema3(
10777
- () => standardSchema2["~standard"].jsonSchema.input({
10778
- target: "draft-07"
10779
- }),
10849
+ () => addAdditionalPropertiesToJsonSchema(
10850
+ standardSchema2["~standard"].jsonSchema.input({
10851
+ target: "draft-07"
10852
+ })
10853
+ ),
10780
10854
  {
10781
10855
  validate: async (value) => {
10782
10856
  const result = await standardSchema2["~standard"].validate(value);
@@ -10839,17 +10913,19 @@ function zodSchema3(zodSchema22, options) {
10839
10913
  }
10840
10914
  async function validateTypes2({
10841
10915
  value,
10842
- schema
10916
+ schema,
10917
+ context: context2
10843
10918
  }) {
10844
- const result = await safeValidateTypes3({ value, schema });
10919
+ const result = await safeValidateTypes3({ value, schema, context: context2 });
10845
10920
  if (!result.success) {
10846
- throw TypeValidationError3.wrap({ value, cause: result.error });
10921
+ throw TypeValidationError3.wrap({ value, cause: result.error, context: context2 });
10847
10922
  }
10848
10923
  return result.value;
10849
10924
  }
10850
10925
  async function safeValidateTypes3({
10851
10926
  value,
10852
- schema
10927
+ schema,
10928
+ context: context2
10853
10929
  }) {
10854
10930
  const actualSchema = asSchema3(schema);
10855
10931
  try {
@@ -10862,13 +10938,13 @@ async function safeValidateTypes3({
10862
10938
  }
10863
10939
  return {
10864
10940
  success: false,
10865
- error: TypeValidationError3.wrap({ value, cause: result.error }),
10941
+ error: TypeValidationError3.wrap({ value, cause: result.error, context: context2 }),
10866
10942
  rawValue: value
10867
10943
  };
10868
10944
  } catch (error) {
10869
10945
  return {
10870
10946
  success: false,
10871
- error: TypeValidationError3.wrap({ value, cause: error }),
10947
+ error: TypeValidationError3.wrap({ value, cause: error, context: context2 }),
10872
10948
  rawValue: value
10873
10949
  };
10874
10950
  }
@@ -11016,6 +11092,38 @@ var postToApi2 = async ({
11016
11092
  throw handleFetchError2({ error, url, requestBodyValues: body.values });
11017
11093
  }
11018
11094
  };
11095
+ function tool(tool2) {
11096
+ return tool2;
11097
+ }
11098
+ function createProviderToolFactoryWithOutputSchema({
11099
+ id,
11100
+ inputSchema,
11101
+ outputSchema: outputSchema3,
11102
+ supportsDeferredResults
11103
+ }) {
11104
+ return ({
11105
+ execute,
11106
+ needsApproval,
11107
+ toModelOutput,
11108
+ onInputStart,
11109
+ onInputDelta,
11110
+ onInputAvailable,
11111
+ ...args
11112
+ }) => tool({
11113
+ type: "provider",
11114
+ id,
11115
+ args,
11116
+ inputSchema,
11117
+ outputSchema: outputSchema3,
11118
+ execute,
11119
+ needsApproval,
11120
+ toModelOutput,
11121
+ onInputStart,
11122
+ onInputDelta,
11123
+ onInputAvailable,
11124
+ supportsDeferredResults
11125
+ });
11126
+ }
11019
11127
  async function resolve2(value) {
11020
11128
  if (typeof value === "function") {
11021
11129
  value = value();
@@ -11117,14 +11225,14 @@ function withoutTrailingSlash2(url) {
11117
11225
  return url == null ? void 0 : url.replace(/\/$/, "");
11118
11226
  }
11119
11227
  var require_get_context2 = __commonJS$1({
11120
- "../../../node_modules/.pnpm/@vercel+oidc@3.0.5/node_modules/@vercel/oidc/dist/get-context.js"(exports$1, module) {
11228
+ "../../../node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/get-context.js"(exports$1, module) {
11121
11229
  var __defProp22 = Object.defineProperty;
11122
11230
  var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
11123
11231
  var __getOwnPropNames2 = Object.getOwnPropertyNames;
11124
11232
  var __hasOwnProp2 = Object.prototype.hasOwnProperty;
11125
11233
  var __export22 = (target, all) => {
11126
- for (var name144 in all)
11127
- __defProp22(target, name144, { get: all[name144], enumerable: true });
11234
+ for (var name21 in all)
11235
+ __defProp22(target, name21, { get: all[name21], enumerable: true });
11128
11236
  };
11129
11237
  var __copyProps2 = (to, from, except, desc) => {
11130
11238
  if (from && typeof from === "object" || typeof from === "function") {
@@ -11149,14 +11257,14 @@ var require_get_context2 = __commonJS$1({
11149
11257
  }
11150
11258
  });
11151
11259
  var require_get_vercel_oidc_token2 = __commonJS$1({
11152
- "../../../node_modules/.pnpm/@vercel+oidc@3.0.5/node_modules/@vercel/oidc/dist/get-vercel-oidc-token.js"(exports$1, module) {
11260
+ "../../../node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/get-vercel-oidc-token.js"(exports$1, module) {
11153
11261
  var __defProp22 = Object.defineProperty;
11154
11262
  var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
11155
11263
  var __getOwnPropNames2 = Object.getOwnPropertyNames;
11156
11264
  var __hasOwnProp2 = Object.prototype.hasOwnProperty;
11157
11265
  var __export22 = (target, all) => {
11158
- for (var name144 in all)
11159
- __defProp22(target, name144, { get: all[name144], enumerable: true });
11266
+ for (var name21 in all)
11267
+ __defProp22(target, name21, { get: all[name21], enumerable: true });
11160
11268
  };
11161
11269
  var __copyProps2 = (to, from, except, desc) => {
11162
11270
  if (from && typeof from === "object" || typeof from === "function") {
@@ -11185,19 +11293,23 @@ var require_get_vercel_oidc_token2 = __commonJS$1({
11185
11293
  }
11186
11294
  try {
11187
11295
  const [{ getTokenPayload, isExpired }, { refreshToken }] = await Promise.all([
11188
- await import('./token-util-NEHG7TUY-TV2H7N56.js'),
11189
- await import('./token-6GSAFR2W-WGTMOPEU.js')
11296
+ await import('./token-util-RMHT2CPJ-RJEA3FAN.js'),
11297
+ await import('./token-APYSY3BW-2DN6RAUY.js')
11190
11298
  ]);
11191
11299
  if (!token || isExpired(getTokenPayload(token))) {
11192
11300
  await refreshToken();
11193
11301
  token = getVercelOidcTokenSync2();
11194
11302
  }
11195
11303
  } catch (error) {
11196
- if (err?.message && error instanceof Error) {
11197
- error.message = `${err.message}
11304
+ let message = err instanceof Error ? err.message : "";
11305
+ if (error instanceof Error) {
11306
+ message = `${message}
11198
11307
  ${error.message}`;
11199
11308
  }
11200
- throw new import_token_error.VercelOidcTokenError(`Failed to refresh OIDC token`, error);
11309
+ if (message) {
11310
+ throw new import_token_error.VercelOidcTokenError(message);
11311
+ }
11312
+ throw error;
11201
11313
  }
11202
11314
  return token;
11203
11315
  }
@@ -11213,14 +11325,14 @@ ${error.message}`;
11213
11325
  }
11214
11326
  });
11215
11327
  var require_dist2 = __commonJS$1({
11216
- "../../../node_modules/.pnpm/@vercel+oidc@3.0.5/node_modules/@vercel/oidc/dist/index.js"(exports$1, module) {
11328
+ "../../../node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/index.js"(exports$1, module) {
11217
11329
  var __defProp22 = Object.defineProperty;
11218
11330
  var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
11219
11331
  var __getOwnPropNames2 = Object.getOwnPropertyNames;
11220
11332
  var __hasOwnProp2 = Object.prototype.hasOwnProperty;
11221
11333
  var __export22 = (target, all) => {
11222
- for (var name144 in all)
11223
- __defProp22(target, name144, { get: all[name144], enumerable: true });
11334
+ for (var name21 in all)
11335
+ __defProp22(target, name21, { get: all[name21], enumerable: true });
11224
11336
  };
11225
11337
  var __copyProps2 = (to, from, except, desc) => {
11226
11338
  if (from && typeof from === "object" || typeof from === "function") {
@@ -11252,12 +11364,14 @@ var GatewayError2 = class _GatewayError2 extends (_b16 = Error, _a20 = symbol20,
11252
11364
  constructor({
11253
11365
  message,
11254
11366
  statusCode = 500,
11255
- cause
11367
+ cause,
11368
+ generationId
11256
11369
  }) {
11257
- super(message);
11370
+ super(generationId ? `${message} [${generationId}]` : message);
11258
11371
  this[_a20] = true;
11259
11372
  this.statusCode = statusCode;
11260
11373
  this.cause = cause;
11374
+ this.generationId = generationId;
11261
11375
  }
11262
11376
  /**
11263
11377
  * Checks if the given error is a Gateway Error.
@@ -11280,9 +11394,10 @@ var GatewayAuthenticationError2 = class _GatewayAuthenticationError2 extends (_b
11280
11394
  constructor({
11281
11395
  message = "Authentication failed",
11282
11396
  statusCode = 401,
11283
- cause
11397
+ cause,
11398
+ generationId
11284
11399
  } = {}) {
11285
- super({ message, statusCode, cause });
11400
+ super({ message, statusCode, cause, generationId });
11286
11401
  this[_a26] = true;
11287
11402
  this.name = name20;
11288
11403
  this.type = "authentication_error";
@@ -11298,7 +11413,8 @@ var GatewayAuthenticationError2 = class _GatewayAuthenticationError2 extends (_b
11298
11413
  oidcTokenProvided,
11299
11414
  message = "Authentication failed",
11300
11415
  statusCode = 401,
11301
- cause
11416
+ cause,
11417
+ generationId
11302
11418
  }) {
11303
11419
  let contextualMessage;
11304
11420
  if (apiKeyProvided) {
@@ -11326,7 +11442,8 @@ Run 'npx vercel link' to link your project, then 'vc env pull' to fetch the toke
11326
11442
  return new _GatewayAuthenticationError2({
11327
11443
  message: contextualMessage,
11328
11444
  statusCode,
11329
- cause
11445
+ cause,
11446
+ generationId
11330
11447
  });
11331
11448
  }
11332
11449
  };
@@ -11339,9 +11456,10 @@ var GatewayInvalidRequestError2 = class extends (_b33 = GatewayError2, _a36 = sy
11339
11456
  constructor({
11340
11457
  message = "Invalid request",
11341
11458
  statusCode = 400,
11342
- cause
11459
+ cause,
11460
+ generationId
11343
11461
  } = {}) {
11344
- super({ message, statusCode, cause });
11462
+ super({ message, statusCode, cause, generationId });
11345
11463
  this[_a36] = true;
11346
11464
  this.name = name26;
11347
11465
  this.type = "invalid_request_error";
@@ -11359,9 +11477,10 @@ var GatewayRateLimitError2 = class extends (_b43 = GatewayError2, _a46 = symbol4
11359
11477
  constructor({
11360
11478
  message = "Rate limit exceeded",
11361
11479
  statusCode = 429,
11362
- cause
11480
+ cause,
11481
+ generationId
11363
11482
  } = {}) {
11364
- super({ message, statusCode, cause });
11483
+ super({ message, statusCode, cause, generationId });
11365
11484
  this[_a46] = true;
11366
11485
  this.name = name36;
11367
11486
  this.type = "rate_limit_exceeded";
@@ -11387,9 +11506,10 @@ var GatewayModelNotFoundError2 = class extends (_b53 = GatewayError2, _a56 = sym
11387
11506
  message = "Model not found",
11388
11507
  statusCode = 404,
11389
11508
  modelId,
11390
- cause
11509
+ cause,
11510
+ generationId
11391
11511
  } = {}) {
11392
- super({ message, statusCode, cause });
11512
+ super({ message, statusCode, cause, generationId });
11393
11513
  this[_a56] = true;
11394
11514
  this.name = name46;
11395
11515
  this.type = "model_not_found";
@@ -11408,9 +11528,10 @@ var GatewayInternalServerError2 = class extends (_b63 = GatewayError2, _a66 = sy
11408
11528
  constructor({
11409
11529
  message = "Internal server error",
11410
11530
  statusCode = 500,
11411
- cause
11531
+ cause,
11532
+ generationId
11412
11533
  } = {}) {
11413
- super({ message, statusCode, cause });
11534
+ super({ message, statusCode, cause, generationId });
11414
11535
  this[_a66] = true;
11415
11536
  this.name = name56;
11416
11537
  this.type = "internal_server_error";
@@ -11430,9 +11551,10 @@ var GatewayResponseError2 = class extends (_b73 = GatewayError2, _a76 = symbol76
11430
11551
  statusCode = 502,
11431
11552
  response,
11432
11553
  validationError,
11433
- cause
11554
+ cause,
11555
+ generationId
11434
11556
  } = {}) {
11435
- super({ message, statusCode, cause });
11557
+ super({ message, statusCode, cause, generationId });
11436
11558
  this[_a76] = true;
11437
11559
  this.name = name66;
11438
11560
  this.type = "response_error";
@@ -11450,34 +11572,49 @@ async function createGatewayErrorFromResponse2({
11450
11572
  cause,
11451
11573
  authMethod
11452
11574
  }) {
11575
+ var _a832;
11453
11576
  const parseResult = await safeValidateTypes3({
11454
11577
  value: response,
11455
11578
  schema: gatewayErrorResponseSchema2
11456
11579
  });
11457
11580
  if (!parseResult.success) {
11581
+ const rawGenerationId = typeof response === "object" && response !== null && "generationId" in response ? response.generationId : void 0;
11458
11582
  return new GatewayResponseError2({
11459
11583
  message: `Invalid error response format: ${defaultMessage}`,
11460
11584
  statusCode,
11461
11585
  response,
11462
11586
  validationError: parseResult.error,
11463
- cause
11587
+ cause,
11588
+ generationId: rawGenerationId
11464
11589
  });
11465
11590
  }
11466
11591
  const validatedResponse = parseResult.value;
11467
11592
  const errorType = validatedResponse.error.type;
11468
11593
  const message = validatedResponse.error.message;
11594
+ const generationId = (_a832 = validatedResponse.generationId) != null ? _a832 : void 0;
11469
11595
  switch (errorType) {
11470
11596
  case "authentication_error":
11471
11597
  return GatewayAuthenticationError2.createContextualError({
11472
11598
  apiKeyProvided: authMethod === "api-key",
11473
11599
  oidcTokenProvided: authMethod === "oidc",
11474
11600
  statusCode,
11475
- cause
11601
+ cause,
11602
+ generationId
11476
11603
  });
11477
11604
  case "invalid_request_error":
11478
- return new GatewayInvalidRequestError2({ message, statusCode, cause });
11605
+ return new GatewayInvalidRequestError2({
11606
+ message,
11607
+ statusCode,
11608
+ cause,
11609
+ generationId
11610
+ });
11479
11611
  case "rate_limit_exceeded":
11480
- return new GatewayRateLimitError2({ message, statusCode, cause });
11612
+ return new GatewayRateLimitError2({
11613
+ message,
11614
+ statusCode,
11615
+ cause,
11616
+ generationId
11617
+ });
11481
11618
  case "model_not_found": {
11482
11619
  const modelResult = await safeValidateTypes3({
11483
11620
  value: validatedResponse.error.param,
@@ -11487,13 +11624,24 @@ async function createGatewayErrorFromResponse2({
11487
11624
  message,
11488
11625
  statusCode,
11489
11626
  modelId: modelResult.success ? modelResult.value.modelId : void 0,
11490
- cause
11627
+ cause,
11628
+ generationId
11491
11629
  });
11492
11630
  }
11493
11631
  case "internal_server_error":
11494
- return new GatewayInternalServerError2({ message, statusCode, cause });
11632
+ return new GatewayInternalServerError2({
11633
+ message,
11634
+ statusCode,
11635
+ cause,
11636
+ generationId
11637
+ });
11495
11638
  default:
11496
- return new GatewayInternalServerError2({ message, statusCode, cause });
11639
+ return new GatewayInternalServerError2({
11640
+ message,
11641
+ statusCode,
11642
+ cause,
11643
+ generationId
11644
+ });
11497
11645
  }
11498
11646
  }
11499
11647
  var gatewayErrorResponseSchema2 = lazySchema(
@@ -11504,7 +11652,8 @@ var gatewayErrorResponseSchema2 = lazySchema(
11504
11652
  type: z$1.string().nullish(),
11505
11653
  param: z$1.unknown().nullish(),
11506
11654
  code: z$1.union([z$1.string(), z$1.number()]).nullish()
11507
- })
11655
+ }),
11656
+ generationId: z$1.string().nullish()
11508
11657
  })
11509
11658
  )
11510
11659
  );
@@ -11780,7 +11929,7 @@ var GatewayLanguageModel2 = class {
11780
11929
  }
11781
11930
  getModelConfigHeaders(modelId, streaming) {
11782
11931
  return {
11783
- "ai-language-model-specification-version": "2",
11932
+ "ai-language-model-specification-version": "3",
11784
11933
  "ai-language-model-id": modelId,
11785
11934
  "ai-language-model-streaming": String(streaming)
11786
11935
  };
@@ -11848,7 +11997,7 @@ var GatewayEmbeddingModel2 = class {
11848
11997
  }
11849
11998
  getModelConfigHeaders() {
11850
11999
  return {
11851
- "ai-embedding-model-specification-version": "2",
12000
+ "ai-embedding-model-specification-version": "3",
11852
12001
  "ai-model-id": this.modelId
11853
12002
  };
11854
12003
  }
@@ -11878,6 +12027,8 @@ var GatewayImageModel2 = class {
11878
12027
  size,
11879
12028
  aspectRatio,
11880
12029
  seed,
12030
+ files,
12031
+ mask,
11881
12032
  providerOptions,
11882
12033
  headers,
11883
12034
  abortSignal
@@ -11902,7 +12053,11 @@ var GatewayImageModel2 = class {
11902
12053
  ...size && { size },
11903
12054
  ...aspectRatio && { aspectRatio },
11904
12055
  ...seed && { seed },
11905
- ...providerOptions && { providerOptions }
12056
+ ...providerOptions && { providerOptions },
12057
+ ...files && {
12058
+ files: files.map((file) => maybeEncodeImageFile(file))
12059
+ },
12060
+ ...mask && { mask: maybeEncodeImageFile(mask) }
11906
12061
  },
11907
12062
  successfulResponseHandler: createJsonResponseHandler2(
11908
12063
  gatewayImageResponseSchema2
@@ -11934,11 +12089,20 @@ var GatewayImageModel2 = class {
11934
12089
  }
11935
12090
  getModelConfigHeaders() {
11936
12091
  return {
11937
- "ai-image-model-specification-version": "2",
12092
+ "ai-image-model-specification-version": "3",
11938
12093
  "ai-model-id": this.modelId
11939
12094
  };
11940
12095
  }
11941
12096
  };
12097
+ function maybeEncodeImageFile(file) {
12098
+ if (file.type === "file" && file.data instanceof Uint8Array) {
12099
+ return {
12100
+ ...file,
12101
+ data: convertUint8ArrayToBase643(file.data)
12102
+ };
12103
+ }
12104
+ return file;
12105
+ }
11942
12106
  var providerMetadataEntrySchema2 = z$1.object({
11943
12107
  images: z$1.array(z$1.unknown()).optional()
11944
12108
  }).catchall(z$1.unknown());
@@ -11953,11 +12117,183 @@ var gatewayImageResponseSchema2 = z$1.object({
11953
12117
  ).optional(),
11954
12118
  providerMetadata: z$1.record(z$1.string(), providerMetadataEntrySchema2).optional()
11955
12119
  });
12120
+ var parallelSearchInputSchema = lazySchema(
12121
+ () => zodSchema3(
12122
+ z.object({
12123
+ objective: z.string().describe(
12124
+ "Natural-language description of the web research goal, including source or freshness guidance and broader context from the task. Maximum 5000 characters."
12125
+ ),
12126
+ search_queries: z.array(z.string()).optional().describe(
12127
+ "Optional search queries to supplement the objective. Maximum 200 characters per query."
12128
+ ),
12129
+ mode: z.enum(["one-shot", "agentic"]).optional().describe(
12130
+ 'Mode preset: "one-shot" for comprehensive results with longer excerpts (default), "agentic" for concise, token-efficient results for multi-step workflows.'
12131
+ ),
12132
+ max_results: z.number().optional().describe(
12133
+ "Maximum number of results to return (1-20). Defaults to 10 if not specified."
12134
+ ),
12135
+ source_policy: z.object({
12136
+ include_domains: z.array(z.string()).optional().describe("List of domains to include in search results."),
12137
+ exclude_domains: z.array(z.string()).optional().describe("List of domains to exclude from search results."),
12138
+ after_date: z.string().optional().describe(
12139
+ "Only include results published after this date (ISO 8601 format)."
12140
+ )
12141
+ }).optional().describe(
12142
+ "Source policy for controlling which domains to include/exclude and freshness."
12143
+ ),
12144
+ excerpts: z.object({
12145
+ max_chars_per_result: z.number().optional().describe("Maximum characters per result."),
12146
+ max_chars_total: z.number().optional().describe("Maximum total characters across all results.")
12147
+ }).optional().describe("Excerpt configuration for controlling result length."),
12148
+ fetch_policy: z.object({
12149
+ max_age_seconds: z.number().optional().describe(
12150
+ "Maximum age in seconds for cached content. Set to 0 to always fetch fresh content."
12151
+ )
12152
+ }).optional().describe("Fetch policy for controlling content freshness.")
12153
+ })
12154
+ )
12155
+ );
12156
+ var parallelSearchOutputSchema = lazySchema(
12157
+ () => zodSchema3(
12158
+ z.union([
12159
+ // Success response
12160
+ z.object({
12161
+ searchId: z.string(),
12162
+ results: z.array(
12163
+ z.object({
12164
+ url: z.string(),
12165
+ title: z.string(),
12166
+ excerpt: z.string(),
12167
+ publishDate: z.string().nullable().optional(),
12168
+ relevanceScore: z.number().optional()
12169
+ })
12170
+ )
12171
+ }),
12172
+ // Error response
12173
+ z.object({
12174
+ error: z.enum([
12175
+ "api_error",
12176
+ "rate_limit",
12177
+ "timeout",
12178
+ "invalid_input",
12179
+ "configuration_error",
12180
+ "unknown"
12181
+ ]),
12182
+ statusCode: z.number().optional(),
12183
+ message: z.string()
12184
+ })
12185
+ ])
12186
+ )
12187
+ );
12188
+ var parallelSearchToolFactory = createProviderToolFactoryWithOutputSchema({
12189
+ id: "gateway.parallel_search",
12190
+ inputSchema: parallelSearchInputSchema,
12191
+ outputSchema: parallelSearchOutputSchema
12192
+ });
12193
+ var parallelSearch = (config = {}) => parallelSearchToolFactory(config);
12194
+ var perplexitySearchInputSchema = lazySchema(
12195
+ () => zodSchema3(
12196
+ z.object({
12197
+ query: z.union([z.string(), z.array(z.string())]).describe(
12198
+ "Search query (string) or multiple queries (array of up to 5 strings). Multi-query searches return combined results from all queries."
12199
+ ),
12200
+ max_results: z.number().optional().describe(
12201
+ "Maximum number of search results to return (1-20, default: 10)"
12202
+ ),
12203
+ max_tokens_per_page: z.number().optional().describe(
12204
+ "Maximum number of tokens to extract per search result page (256-2048, default: 2048)"
12205
+ ),
12206
+ max_tokens: z.number().optional().describe(
12207
+ "Maximum total tokens across all search results (default: 25000, max: 1000000)"
12208
+ ),
12209
+ country: z.string().optional().describe(
12210
+ "Two-letter ISO 3166-1 alpha-2 country code for regional search results (e.g., 'US', 'GB', 'FR')"
12211
+ ),
12212
+ search_domain_filter: z.array(z.string()).optional().describe(
12213
+ "List of domains to include or exclude from search results (max 20). To include: ['nature.com', 'science.org']. To exclude: ['-example.com', '-spam.net']"
12214
+ ),
12215
+ search_language_filter: z.array(z.string()).optional().describe(
12216
+ "List of ISO 639-1 language codes to filter results (max 10, lowercase). Examples: ['en', 'fr', 'de']"
12217
+ ),
12218
+ search_after_date: z.string().optional().describe(
12219
+ "Include only results published after this date. Format: 'MM/DD/YYYY' (e.g., '3/1/2025'). Cannot be used with search_recency_filter."
12220
+ ),
12221
+ search_before_date: z.string().optional().describe(
12222
+ "Include only results published before this date. Format: 'MM/DD/YYYY' (e.g., '3/15/2025'). Cannot be used with search_recency_filter."
12223
+ ),
12224
+ last_updated_after_filter: z.string().optional().describe(
12225
+ "Include only results last updated after this date. Format: 'MM/DD/YYYY' (e.g., '3/1/2025'). Cannot be used with search_recency_filter."
12226
+ ),
12227
+ last_updated_before_filter: z.string().optional().describe(
12228
+ "Include only results last updated before this date. Format: 'MM/DD/YYYY' (e.g., '3/15/2025'). Cannot be used with search_recency_filter."
12229
+ ),
12230
+ search_recency_filter: z.enum(["day", "week", "month", "year"]).optional().describe(
12231
+ "Filter results by relative time period. Cannot be used with search_after_date or search_before_date."
12232
+ )
12233
+ })
12234
+ )
12235
+ );
12236
+ var perplexitySearchOutputSchema = lazySchema(
12237
+ () => zodSchema3(
12238
+ z.union([
12239
+ // Success response
12240
+ z.object({
12241
+ results: z.array(
12242
+ z.object({
12243
+ title: z.string(),
12244
+ url: z.string(),
12245
+ snippet: z.string(),
12246
+ date: z.string().optional(),
12247
+ lastUpdated: z.string().optional()
12248
+ })
12249
+ ),
12250
+ id: z.string()
12251
+ }),
12252
+ // Error response
12253
+ z.object({
12254
+ error: z.enum([
12255
+ "api_error",
12256
+ "rate_limit",
12257
+ "timeout",
12258
+ "invalid_input",
12259
+ "unknown"
12260
+ ]),
12261
+ statusCode: z.number().optional(),
12262
+ message: z.string()
12263
+ })
12264
+ ])
12265
+ )
12266
+ );
12267
+ var perplexitySearchToolFactory = createProviderToolFactoryWithOutputSchema({
12268
+ id: "gateway.perplexity_search",
12269
+ inputSchema: perplexitySearchInputSchema,
12270
+ outputSchema: perplexitySearchOutputSchema
12271
+ });
12272
+ var perplexitySearch = (config = {}) => perplexitySearchToolFactory(config);
12273
+ var gatewayTools = {
12274
+ /**
12275
+ * Search the web using Parallel AI's Search API for LLM-optimized excerpts.
12276
+ *
12277
+ * Takes a natural language objective and returns relevant excerpts,
12278
+ * replacing multiple keyword searches with a single call for broad
12279
+ * or complex queries. Supports different search types for depth vs
12280
+ * breadth tradeoffs.
12281
+ */
12282
+ parallelSearch,
12283
+ /**
12284
+ * Search the web using Perplexity's Search API for real-time information,
12285
+ * news, research papers, and articles.
12286
+ *
12287
+ * Provides ranked search results with advanced filtering options including
12288
+ * domain, language, date range, and recency filters.
12289
+ */
12290
+ perplexitySearch
12291
+ };
11956
12292
  async function getVercelRequestId2() {
11957
12293
  var _a832;
11958
12294
  return (_a832 = (0, import_oidc3.getContext)().headers) == null ? void 0 : _a832["x-vercel-id"];
11959
12295
  }
11960
- var VERSION5 = "3.0.0";
12296
+ var VERSION5 = "3.0.32";
11961
12297
  var AI_GATEWAY_PROTOCOL_VERSION2 = "0.0.1";
11962
12298
  function createGatewayProvider2(options = {}) {
11963
12299
  var _a832, _b83;
@@ -11967,8 +12303,8 @@ function createGatewayProvider2(options = {}) {
11967
12303
  let lastFetchTime = 0;
11968
12304
  const baseURL = (_b83 = withoutTrailingSlash2(options.baseURL)) != null ? _b83 : "https://ai-gateway.vercel.sh/v3/ai";
11969
12305
  const getHeaders = async () => {
11970
- const auth = await getGatewayAuthToken2(options);
11971
- if (auth) {
12306
+ try {
12307
+ const auth = await getGatewayAuthToken2(options);
11972
12308
  return withUserAgentSuffix2(
11973
12309
  {
11974
12310
  Authorization: `Bearer ${auth.token}`,
@@ -11978,12 +12314,14 @@ function createGatewayProvider2(options = {}) {
11978
12314
  },
11979
12315
  `ai-sdk/gateway/${VERSION5}`
11980
12316
  );
12317
+ } catch (error) {
12318
+ throw GatewayAuthenticationError2.createContextualError({
12319
+ apiKeyProvided: false,
12320
+ oidcTokenProvided: false,
12321
+ statusCode: 401,
12322
+ cause: error
12323
+ });
11981
12324
  }
11982
- throw GatewayAuthenticationError2.createContextualError({
11983
- apiKeyProvided: false,
11984
- oidcTokenProvided: false,
11985
- statusCode: 401
11986
- });
11987
12325
  };
11988
12326
  const createO11yHeaders = () => {
11989
12327
  const deploymentId = loadOptionalSetting2({
@@ -12082,6 +12420,7 @@ function createGatewayProvider2(options = {}) {
12082
12420
  };
12083
12421
  provider.embeddingModel = createEmbeddingModel;
12084
12422
  provider.textEmbeddingModel = createEmbeddingModel;
12423
+ provider.tools = gatewayTools;
12085
12424
  return provider;
12086
12425
  }
12087
12426
  var gateway2 = createGatewayProvider2();
@@ -12096,15 +12435,11 @@ async function getGatewayAuthToken2(options) {
12096
12435
  authMethod: "api-key"
12097
12436
  };
12098
12437
  }
12099
- try {
12100
- const oidcToken = await (0, import_oidc22.getVercelOidcToken)();
12101
- return {
12102
- token: oidcToken,
12103
- authMethod: "oidc"
12104
- };
12105
- } catch (e) {
12106
- return null;
12107
- }
12438
+ const oidcToken = await (0, import_oidc22.getVercelOidcToken)();
12439
+ return {
12440
+ token: oidcToken,
12441
+ authMethod: "oidc"
12442
+ };
12108
12443
  }
12109
12444
  var _globalThis3 = typeof globalThis === "object" ? globalThis : global;
12110
12445
  var VERSION23 = "1.9.0";
@@ -12177,11 +12512,11 @@ var major3 = VERSION23.split(".")[0];
12177
12512
  var GLOBAL_OPENTELEMETRY_API_KEY3 = /* @__PURE__ */ Symbol.for("opentelemetry.js.api." + major3);
12178
12513
  var _global3 = _globalThis3;
12179
12514
  function registerGlobal3(type, instance, diag, allowOverride) {
12180
- var _a146;
12515
+ var _a21;
12181
12516
  if (allowOverride === void 0) {
12182
12517
  allowOverride = false;
12183
12518
  }
12184
- var api = _global3[GLOBAL_OPENTELEMETRY_API_KEY3] = (_a146 = _global3[GLOBAL_OPENTELEMETRY_API_KEY3]) !== null && _a146 !== void 0 ? _a146 : {
12519
+ var api = _global3[GLOBAL_OPENTELEMETRY_API_KEY3] = (_a21 = _global3[GLOBAL_OPENTELEMETRY_API_KEY3]) !== null && _a21 !== void 0 ? _a21 : {
12185
12520
  version: VERSION23
12186
12521
  };
12187
12522
  if (!allowOverride && api[type]) {
@@ -12199,8 +12534,8 @@ function registerGlobal3(type, instance, diag, allowOverride) {
12199
12534
  return true;
12200
12535
  }
12201
12536
  function getGlobal3(type) {
12202
- var _a146, _b83;
12203
- var globalVersion = (_a146 = _global3[GLOBAL_OPENTELEMETRY_API_KEY3]) === null || _a146 === void 0 ? void 0 : _a146.version;
12537
+ var _a21, _b83;
12538
+ var globalVersion = (_a21 = _global3[GLOBAL_OPENTELEMETRY_API_KEY3]) === null || _a21 === void 0 ? void 0 : _a21.version;
12204
12539
  if (!globalVersion || !isCompatible3(globalVersion)) {
12205
12540
  return;
12206
12541
  }
@@ -12369,13 +12704,13 @@ var DiagAPI3 = (
12369
12704
  }
12370
12705
  var self = this;
12371
12706
  var setLogger = function(logger, optionsOrLogLevel) {
12372
- var _a146, _b83, _c;
12707
+ var _a21, _b83, _c;
12373
12708
  if (optionsOrLogLevel === void 0) {
12374
12709
  optionsOrLogLevel = { logLevel: DiagLogLevel3.INFO };
12375
12710
  }
12376
12711
  if (logger === self) {
12377
12712
  var err = new Error("Cannot use diag as the logger for itself. Please use a DiagLogger implementation like ConsoleDiagLogger or a custom implementation");
12378
- self.error((_a146 = err.stack) !== null && _a146 !== void 0 ? _a146 : err.message);
12713
+ self.error((_a21 = err.stack) !== null && _a21 !== void 0 ? _a21 : err.message);
12379
12714
  return false;
12380
12715
  }
12381
12716
  if (typeof optionsOrLogLevel === "number") {
@@ -12427,14 +12762,14 @@ var BaseContext3 = (
12427
12762
  return self._currentContext.get(key);
12428
12763
  };
12429
12764
  self.setValue = function(key, value) {
12430
- var context = new BaseContext22(self._currentContext);
12431
- context._currentContext.set(key, value);
12432
- return context;
12765
+ var context2 = new BaseContext22(self._currentContext);
12766
+ context2._currentContext.set(key, value);
12767
+ return context2;
12433
12768
  };
12434
12769
  self.deleteValue = function(key) {
12435
- var context = new BaseContext22(self._currentContext);
12436
- context._currentContext.delete(key);
12437
- return context;
12770
+ var context2 = new BaseContext22(self._currentContext);
12771
+ context2._currentContext.delete(key);
12772
+ return context2;
12438
12773
  };
12439
12774
  }
12440
12775
  return BaseContext22;
@@ -12539,16 +12874,16 @@ var ContextAPI3 = (
12539
12874
  ContextAPI22.prototype.active = function() {
12540
12875
  return this._getContextManager().active();
12541
12876
  };
12542
- ContextAPI22.prototype.with = function(context, fn, thisArg) {
12543
- var _a146;
12877
+ ContextAPI22.prototype.with = function(context2, fn, thisArg) {
12878
+ var _a21;
12544
12879
  var args = [];
12545
12880
  for (var _i = 3; _i < arguments.length; _i++) {
12546
12881
  args[_i - 3] = arguments[_i];
12547
12882
  }
12548
- return (_a146 = this._getContextManager()).with.apply(_a146, __spreadArray43([context, fn, thisArg], __read43(args), false));
12883
+ return (_a21 = this._getContextManager()).with.apply(_a21, __spreadArray43([context2, fn, thisArg], __read43(args), false));
12549
12884
  };
12550
- ContextAPI22.prototype.bind = function(context, target) {
12551
- return this._getContextManager().bind(context, target);
12885
+ ContextAPI22.prototype.bind = function(context2, target) {
12886
+ return this._getContextManager().bind(context2, target);
12552
12887
  };
12553
12888
  ContextAPI22.prototype._getContextManager = function() {
12554
12889
  return getGlobal3(API_NAME23) || NOOP_CONTEXT_MANAGER3;
@@ -12616,24 +12951,24 @@ var NonRecordingSpan3 = (
12616
12951
  })()
12617
12952
  );
12618
12953
  var SPAN_KEY3 = createContextKey3("OpenTelemetry Context Key SPAN");
12619
- function getSpan3(context) {
12620
- return context.getValue(SPAN_KEY3) || void 0;
12954
+ function getSpan3(context2) {
12955
+ return context2.getValue(SPAN_KEY3) || void 0;
12621
12956
  }
12622
12957
  function getActiveSpan3() {
12623
12958
  return getSpan3(ContextAPI3.getInstance().active());
12624
12959
  }
12625
- function setSpan3(context, span) {
12626
- return context.setValue(SPAN_KEY3, span);
12960
+ function setSpan3(context2, span) {
12961
+ return context2.setValue(SPAN_KEY3, span);
12627
12962
  }
12628
- function deleteSpan3(context) {
12629
- return context.deleteValue(SPAN_KEY3);
12963
+ function deleteSpan3(context2) {
12964
+ return context2.deleteValue(SPAN_KEY3);
12630
12965
  }
12631
- function setSpanContext3(context, spanContext) {
12632
- return setSpan3(context, new NonRecordingSpan3(spanContext));
12966
+ function setSpanContext3(context2, spanContext) {
12967
+ return setSpan3(context2, new NonRecordingSpan3(spanContext));
12633
12968
  }
12634
- function getSpanContext3(context) {
12635
- var _a146;
12636
- return (_a146 = getSpan3(context)) === null || _a146 === void 0 ? void 0 : _a146.spanContext();
12969
+ function getSpanContext3(context2) {
12970
+ var _a21;
12971
+ return (_a21 = getSpan3(context2)) === null || _a21 === void 0 ? void 0 : _a21.spanContext();
12637
12972
  }
12638
12973
  var VALID_TRACEID_REGEX3 = /^([0-9a-f]{32})$/i;
12639
12974
  var VALID_SPANID_REGEX3 = /^[0-9a-f]{16}$/i;
@@ -12655,22 +12990,22 @@ var NoopTracer3 = (
12655
12990
  (function() {
12656
12991
  function NoopTracer22() {
12657
12992
  }
12658
- NoopTracer22.prototype.startSpan = function(name144, options, context) {
12659
- if (context === void 0) {
12660
- context = contextApi3.active();
12993
+ NoopTracer22.prototype.startSpan = function(name21, options, context2) {
12994
+ if (context2 === void 0) {
12995
+ context2 = contextApi3.active();
12661
12996
  }
12662
12997
  var root = Boolean(options === null || options === void 0 ? void 0 : options.root);
12663
12998
  if (root) {
12664
12999
  return new NonRecordingSpan3();
12665
13000
  }
12666
- var parentFromContext = context && getSpanContext3(context);
13001
+ var parentFromContext = context2 && getSpanContext3(context2);
12667
13002
  if (isSpanContext3(parentFromContext) && isSpanContextValid3(parentFromContext)) {
12668
13003
  return new NonRecordingSpan3(parentFromContext);
12669
13004
  } else {
12670
13005
  return new NonRecordingSpan3();
12671
13006
  }
12672
13007
  };
12673
- NoopTracer22.prototype.startActiveSpan = function(name144, arg2, arg3, arg4) {
13008
+ NoopTracer22.prototype.startActiveSpan = function(name21, arg2, arg3, arg4) {
12674
13009
  var opts;
12675
13010
  var ctx;
12676
13011
  var fn;
@@ -12687,7 +13022,7 @@ var NoopTracer3 = (
12687
13022
  fn = arg4;
12688
13023
  }
12689
13024
  var parentContext = ctx !== null && ctx !== void 0 ? ctx : contextApi3.active();
12690
- var span = this.startSpan(name144, opts, parentContext);
13025
+ var span = this.startSpan(name21, opts, parentContext);
12691
13026
  var contextWithSpanSet = setSpan3(parentContext, span);
12692
13027
  return contextApi3.with(contextWithSpanSet, fn, void 0, span);
12693
13028
  };
@@ -12701,14 +13036,14 @@ var NOOP_TRACER3 = new NoopTracer3();
12701
13036
  var ProxyTracer3 = (
12702
13037
  /** @class */
12703
13038
  (function() {
12704
- function ProxyTracer22(_provider, name144, version, options) {
13039
+ function ProxyTracer22(_provider, name21, version, options) {
12705
13040
  this._provider = _provider;
12706
- this.name = name144;
13041
+ this.name = name21;
12707
13042
  this.version = version;
12708
13043
  this.options = options;
12709
13044
  }
12710
- ProxyTracer22.prototype.startSpan = function(name144, options, context) {
12711
- return this._getTracer().startSpan(name144, options, context);
13045
+ ProxyTracer22.prototype.startSpan = function(name21, options, context2) {
13046
+ return this._getTracer().startSpan(name21, options, context2);
12712
13047
  };
12713
13048
  ProxyTracer22.prototype.startActiveSpan = function(_name, _options, _context, _fn) {
12714
13049
  var tracer = this._getTracer();
@@ -12745,20 +13080,20 @@ var ProxyTracerProvider3 = (
12745
13080
  (function() {
12746
13081
  function ProxyTracerProvider22() {
12747
13082
  }
12748
- ProxyTracerProvider22.prototype.getTracer = function(name144, version, options) {
12749
- var _a146;
12750
- return (_a146 = this.getDelegateTracer(name144, version, options)) !== null && _a146 !== void 0 ? _a146 : new ProxyTracer3(this, name144, version, options);
13083
+ ProxyTracerProvider22.prototype.getTracer = function(name21, version, options) {
13084
+ var _a21;
13085
+ return (_a21 = this.getDelegateTracer(name21, version, options)) !== null && _a21 !== void 0 ? _a21 : new ProxyTracer3(this, name21, version, options);
12751
13086
  };
12752
13087
  ProxyTracerProvider22.prototype.getDelegate = function() {
12753
- var _a146;
12754
- return (_a146 = this._delegate) !== null && _a146 !== void 0 ? _a146 : NOOP_TRACER_PROVIDER3;
13088
+ var _a21;
13089
+ return (_a21 = this._delegate) !== null && _a21 !== void 0 ? _a21 : NOOP_TRACER_PROVIDER3;
12755
13090
  };
12756
13091
  ProxyTracerProvider22.prototype.setDelegate = function(delegate) {
12757
13092
  this._delegate = delegate;
12758
13093
  };
12759
- ProxyTracerProvider22.prototype.getDelegateTracer = function(name144, version, options) {
12760
- var _a146;
12761
- return (_a146 = this._delegate) === null || _a146 === void 0 ? void 0 : _a146.getTracer(name144, version, options);
13094
+ ProxyTracerProvider22.prototype.getDelegateTracer = function(name21, version, options) {
13095
+ var _a21;
13096
+ return (_a21 = this._delegate) === null || _a21 === void 0 ? void 0 : _a21.getTracer(name21, version, options);
12762
13097
  };
12763
13098
  return ProxyTracerProvider22;
12764
13099
  })()
@@ -12769,6 +13104,7 @@ var SpanStatusCode3;
12769
13104
  SpanStatusCode22[SpanStatusCode22["OK"] = 1] = "OK";
12770
13105
  SpanStatusCode22[SpanStatusCode22["ERROR"] = 2] = "ERROR";
12771
13106
  })(SpanStatusCode3 || (SpanStatusCode3 = {}));
13107
+ var context = ContextAPI3.getInstance();
12772
13108
  var API_NAME33 = "trace";
12773
13109
  var TraceAPI3 = (
12774
13110
  /** @class */
@@ -12800,8 +13136,8 @@ var TraceAPI3 = (
12800
13136
  TraceAPI22.prototype.getTracerProvider = function() {
12801
13137
  return getGlobal3(API_NAME33) || this._proxyTracerProvider;
12802
13138
  };
12803
- TraceAPI22.prototype.getTracer = function(name144, version) {
12804
- return this.getTracerProvider().getTracer(name144, version);
13139
+ TraceAPI22.prototype.getTracer = function(name21, version) {
13140
+ return this.getTracerProvider().getTracer(name21, version);
12805
13141
  };
12806
13142
  TraceAPI22.prototype.disable = function() {
12807
13143
  unregisterGlobal3(API_NAME33, DiagAPI3.instance());
@@ -12813,8 +13149,8 @@ var TraceAPI3 = (
12813
13149
  var trace3 = TraceAPI3.getInstance();
12814
13150
  var __defProp4 = Object.defineProperty;
12815
13151
  var __export3 = (target, all) => {
12816
- for (var name144 in all)
12817
- __defProp4(target, name144, { get: all[name144], enumerable: true });
13152
+ for (var name21 in all)
13153
+ __defProp4(target, name21, { get: all[name21], enumerable: true });
12818
13154
  };
12819
13155
  var name76 = "AI_InvalidArgumentError";
12820
13156
  var marker86 = `vercel.ai.error.${name76}`;
@@ -12839,10 +13175,10 @@ var InvalidArgumentError23 = class extends AISDKError3 {
12839
13175
  }
12840
13176
  };
12841
13177
  _a86 = symbol86;
12842
- var name523 = "AI_NoObjectGeneratedError";
12843
- var marker523 = `vercel.ai.error.${name523}`;
12844
- var symbol523 = Symbol.for(marker523);
12845
- var _a523;
13178
+ var name86 = "AI_NoObjectGeneratedError";
13179
+ var marker823 = `vercel.ai.error.${name86}`;
13180
+ var symbol823 = Symbol.for(marker823);
13181
+ var _a823;
12846
13182
  var NoObjectGeneratedError3 = class extends AISDKError3 {
12847
13183
  constructor({
12848
13184
  message = "No object generated.",
@@ -12852,18 +13188,18 @@ var NoObjectGeneratedError3 = class extends AISDKError3 {
12852
13188
  usage,
12853
13189
  finishReason
12854
13190
  }) {
12855
- super({ name: name523, message, cause });
12856
- this[_a523] = true;
13191
+ super({ name: name86, message, cause });
13192
+ this[_a823] = true;
12857
13193
  this.text = text22;
12858
13194
  this.response = response;
12859
13195
  this.usage = usage;
12860
13196
  this.finishReason = finishReason;
12861
13197
  }
12862
13198
  static isInstance(error) {
12863
- return AISDKError3.hasMarker(error, marker523);
13199
+ return AISDKError3.hasMarker(error, marker823);
12864
13200
  }
12865
13201
  };
12866
- _a523 = symbol523;
13202
+ _a823 = symbol823;
12867
13203
  var UnsupportedModelVersionError3 = class extends AISDKError3 {
12868
13204
  constructor(options) {
12869
13205
  super({
@@ -12875,27 +13211,27 @@ var UnsupportedModelVersionError3 = class extends AISDKError3 {
12875
13211
  this.modelId = options.modelId;
12876
13212
  }
12877
13213
  };
12878
- var name126 = "AI_RetryError";
12879
- var marker125 = `vercel.ai.error.${name126}`;
12880
- var symbol125 = Symbol.for(marker125);
12881
- var _a125;
13214
+ var name192 = "AI_RetryError";
13215
+ var marker192 = `vercel.ai.error.${name192}`;
13216
+ var symbol192 = Symbol.for(marker192);
13217
+ var _a192;
12882
13218
  var RetryError3 = class extends AISDKError3 {
12883
13219
  constructor({
12884
13220
  message,
12885
13221
  reason,
12886
13222
  errors
12887
13223
  }) {
12888
- super({ name: name126, message });
12889
- this[_a125] = true;
13224
+ super({ name: name192, message });
13225
+ this[_a192] = true;
12890
13226
  this.reason = reason;
12891
13227
  this.errors = errors;
12892
13228
  this.lastError = errors[errors.length - 1];
12893
13229
  }
12894
13230
  static isInstance(error) {
12895
- return AISDKError3.hasMarker(error, marker125);
13231
+ return AISDKError3.hasMarker(error, marker192);
12896
13232
  }
12897
13233
  };
12898
- _a125 = symbol125;
13234
+ _a192 = symbol192;
12899
13235
  function formatWarning({
12900
13236
  warning,
12901
13237
  provider,
@@ -13000,10 +13336,19 @@ function resolveEmbeddingModel2(model) {
13000
13336
  return getGlobalProvider2().embeddingModel(model);
13001
13337
  }
13002
13338
  function getGlobalProvider2() {
13003
- var _a146;
13004
- return (_a146 = globalThis.AI_SDK_DEFAULT_PROVIDER) != null ? _a146 : gateway2;
13339
+ var _a21;
13340
+ return (_a21 = globalThis.AI_SDK_DEFAULT_PROVIDER) != null ? _a21 : gateway2;
13341
+ }
13342
+ function getTotalTimeoutMs(timeout) {
13343
+ if (timeout == null) {
13344
+ return void 0;
13345
+ }
13346
+ if (typeof timeout === "number") {
13347
+ return timeout;
13348
+ }
13349
+ return timeout.totalMs;
13005
13350
  }
13006
- var VERSION33 = "6.0.1";
13351
+ var VERSION33 = "6.0.69";
13007
13352
  var dataContentSchema3 = z$1.union([
13008
13353
  z$1.string(),
13009
13354
  z$1.instanceof(Uint8Array),
@@ -13011,8 +13356,8 @@ var dataContentSchema3 = z$1.union([
13011
13356
  z$1.custom(
13012
13357
  // Buffer might not be available in some environments such as CloudFlare:
13013
13358
  (value) => {
13014
- var _a146, _b83;
13015
- return (_b83 = (_a146 = globalThis.Buffer) == null ? void 0 : _a146.isBuffer(value)) != null ? _b83 : false;
13359
+ var _a21, _b83;
13360
+ return (_b83 = (_a21 = globalThis.Buffer) == null ? void 0 : _a21.isBuffer(value)) != null ? _b83 : false;
13016
13361
  },
13017
13362
  { message: "Must be a Buffer" }
13018
13363
  )
@@ -13226,17 +13571,26 @@ function getBaseTelemetryAttributes3({
13226
13571
  telemetry,
13227
13572
  headers
13228
13573
  }) {
13229
- var _a146;
13574
+ var _a21;
13230
13575
  return {
13231
13576
  "ai.model.provider": model.provider,
13232
13577
  "ai.model.id": model.modelId,
13233
13578
  // settings:
13234
13579
  ...Object.entries(settings).reduce((attributes, [key, value]) => {
13235
- attributes[`ai.settings.${key}`] = value;
13580
+ if (key === "timeout") {
13581
+ const totalTimeoutMs = getTotalTimeoutMs(
13582
+ value
13583
+ );
13584
+ if (totalTimeoutMs != null) {
13585
+ attributes[`ai.settings.${key}`] = totalTimeoutMs;
13586
+ }
13587
+ } else {
13588
+ attributes[`ai.settings.${key}`] = value;
13589
+ }
13236
13590
  return attributes;
13237
13591
  }, {}),
13238
13592
  // add metadata as attributes:
13239
- ...Object.entries((_a146 = telemetry == null ? void 0 : telemetry.metadata) != null ? _a146 : {}).reduce(
13593
+ ...Object.entries((_a21 = telemetry == null ? void 0 : telemetry.metadata) != null ? _a21 : {}).reduce(
13240
13594
  (attributes, [key, value]) => {
13241
13595
  attributes[`ai.telemetry.metadata.${key}`] = value;
13242
13596
  return attributes;
@@ -13256,7 +13610,7 @@ var noopTracer3 = {
13256
13610
  startSpan() {
13257
13611
  return noopSpan3;
13258
13612
  },
13259
- startActiveSpan(name144, arg1, arg2, arg3) {
13613
+ startActiveSpan(name21, arg1, arg2, arg3) {
13260
13614
  if (typeof arg1 === "function") {
13261
13615
  return arg1(noopSpan3);
13262
13616
  }
@@ -13321,18 +13675,19 @@ function getTracer3({
13321
13675
  return trace3.getTracer("ai");
13322
13676
  }
13323
13677
  async function recordSpan3({
13324
- name: name144,
13678
+ name: name21,
13325
13679
  tracer,
13326
13680
  attributes,
13327
13681
  fn,
13328
13682
  endWhenDone = true
13329
13683
  }) {
13330
13684
  return tracer.startActiveSpan(
13331
- name144,
13685
+ name21,
13332
13686
  { attributes: await attributes },
13333
13687
  async (span) => {
13688
+ const ctx = context.active();
13334
13689
  try {
13335
- const result = await fn(span);
13690
+ const result = await context.with(ctx, () => fn(span));
13336
13691
  if (endWhenDone) {
13337
13692
  span.end();
13338
13693
  }
@@ -13861,37 +14216,42 @@ async function parsePartialJson3(jsonText) {
13861
14216
  return { value: void 0, state: "failed-parse" };
13862
14217
  }
13863
14218
  var text3 = () => ({
14219
+ name: "text",
13864
14220
  responseFormat: Promise.resolve({ type: "text" }),
13865
14221
  async parseCompleteOutput({ text: text22 }) {
13866
14222
  return text22;
13867
14223
  },
13868
14224
  async parsePartialOutput({ text: text22 }) {
13869
14225
  return { partial: text22 };
14226
+ },
14227
+ createElementStreamTransform() {
14228
+ return void 0;
13870
14229
  }
13871
14230
  });
13872
14231
  var object3 = ({
13873
14232
  schema: inputSchema,
13874
- name: name144,
14233
+ name: name21,
13875
14234
  description
13876
14235
  }) => {
13877
14236
  const schema = asSchema3(inputSchema);
13878
14237
  return {
14238
+ name: "object",
13879
14239
  responseFormat: resolve2(schema.jsonSchema).then((jsonSchema22) => ({
13880
14240
  type: "json",
13881
14241
  schema: jsonSchema22,
13882
- ...name144 != null && { name: name144 },
14242
+ ...name21 != null && { name: name21 },
13883
14243
  ...description != null && { description }
13884
14244
  })),
13885
- async parseCompleteOutput({ text: text22 }, context) {
14245
+ async parseCompleteOutput({ text: text22 }, context2) {
13886
14246
  const parseResult = await safeParseJSON3({ text: text22 });
13887
14247
  if (!parseResult.success) {
13888
14248
  throw new NoObjectGeneratedError3({
13889
14249
  message: "No object generated: could not parse the response.",
13890
14250
  cause: parseResult.error,
13891
14251
  text: text22,
13892
- response: context.response,
13893
- usage: context.usage,
13894
- finishReason: context.finishReason
14252
+ response: context2.response,
14253
+ usage: context2.usage,
14254
+ finishReason: context2.finishReason
13895
14255
  });
13896
14256
  }
13897
14257
  const validationResult = await safeValidateTypes3({
@@ -13903,9 +14263,9 @@ var object3 = ({
13903
14263
  message: "No object generated: response did not match schema.",
13904
14264
  cause: validationResult.error,
13905
14265
  text: text22,
13906
- response: context.response,
13907
- usage: context.usage,
13908
- finishReason: context.finishReason
14266
+ response: context2.response,
14267
+ usage: context2.usage,
14268
+ finishReason: context2.finishReason
13909
14269
  });
13910
14270
  }
13911
14271
  return validationResult.value;
@@ -13925,16 +14285,20 @@ var object3 = ({
13925
14285
  };
13926
14286
  }
13927
14287
  }
14288
+ },
14289
+ createElementStreamTransform() {
14290
+ return void 0;
13928
14291
  }
13929
14292
  };
13930
14293
  };
13931
14294
  var array = ({
13932
14295
  element: inputElementSchema,
13933
- name: name144,
14296
+ name: name21,
13934
14297
  description
13935
14298
  }) => {
13936
14299
  const elementSchema = asSchema3(inputElementSchema);
13937
14300
  return {
14301
+ name: "array",
13938
14302
  // JSON schema that describes an array of elements:
13939
14303
  responseFormat: resolve2(elementSchema.jsonSchema).then((jsonSchema22) => {
13940
14304
  const { $schema, ...itemSchema } = jsonSchema22;
@@ -13949,20 +14313,20 @@ var array = ({
13949
14313
  required: ["elements"],
13950
14314
  additionalProperties: false
13951
14315
  },
13952
- ...name144 != null && { name: name144 },
14316
+ ...name21 != null && { name: name21 },
13953
14317
  ...description != null && { description }
13954
14318
  };
13955
14319
  }),
13956
- async parseCompleteOutput({ text: text22 }, context) {
14320
+ async parseCompleteOutput({ text: text22 }, context2) {
13957
14321
  const parseResult = await safeParseJSON3({ text: text22 });
13958
14322
  if (!parseResult.success) {
13959
14323
  throw new NoObjectGeneratedError3({
13960
14324
  message: "No object generated: could not parse the response.",
13961
14325
  cause: parseResult.error,
13962
14326
  text: text22,
13963
- response: context.response,
13964
- usage: context.usage,
13965
- finishReason: context.finishReason
14327
+ response: context2.response,
14328
+ usage: context2.usage,
14329
+ finishReason: context2.finishReason
13966
14330
  });
13967
14331
  }
13968
14332
  const outerValue = parseResult.value;
@@ -13974,9 +14338,9 @@ var array = ({
13974
14338
  cause: "response must be an object with an elements array"
13975
14339
  }),
13976
14340
  text: text22,
13977
- response: context.response,
13978
- usage: context.usage,
13979
- finishReason: context.finishReason
14341
+ response: context2.response,
14342
+ usage: context2.usage,
14343
+ finishReason: context2.finishReason
13980
14344
  });
13981
14345
  }
13982
14346
  for (const element of outerValue.elements) {
@@ -13989,9 +14353,9 @@ var array = ({
13989
14353
  message: "No object generated: response did not match schema.",
13990
14354
  cause: validationResult.error,
13991
14355
  text: text22,
13992
- response: context.response,
13993
- usage: context.usage,
13994
- finishReason: context.finishReason
14356
+ response: context2.response,
14357
+ usage: context2.usage,
14358
+ finishReason: context2.finishReason
13995
14359
  });
13996
14360
  }
13997
14361
  }
@@ -14024,15 +14388,28 @@ var array = ({
14024
14388
  return { partial: parsedElements };
14025
14389
  }
14026
14390
  }
14391
+ },
14392
+ createElementStreamTransform() {
14393
+ let publishedElements = 0;
14394
+ return new TransformStream({
14395
+ transform({ partialOutput }, controller) {
14396
+ if (partialOutput != null) {
14397
+ for (; publishedElements < partialOutput.length; publishedElements++) {
14398
+ controller.enqueue(partialOutput[publishedElements]);
14399
+ }
14400
+ }
14401
+ }
14402
+ });
14027
14403
  }
14028
14404
  };
14029
14405
  };
14030
14406
  var choice = ({
14031
14407
  options: choiceOptions,
14032
- name: name144,
14408
+ name: name21,
14033
14409
  description
14034
14410
  }) => {
14035
14411
  return {
14412
+ name: "choice",
14036
14413
  // JSON schema that describes an enumeration:
14037
14414
  responseFormat: Promise.resolve({
14038
14415
  type: "json",
@@ -14045,19 +14422,19 @@ var choice = ({
14045
14422
  required: ["result"],
14046
14423
  additionalProperties: false
14047
14424
  },
14048
- ...name144 != null && { name: name144 },
14425
+ ...name21 != null && { name: name21 },
14049
14426
  ...description != null && { description }
14050
14427
  }),
14051
- async parseCompleteOutput({ text: text22 }, context) {
14428
+ async parseCompleteOutput({ text: text22 }, context2) {
14052
14429
  const parseResult = await safeParseJSON3({ text: text22 });
14053
14430
  if (!parseResult.success) {
14054
14431
  throw new NoObjectGeneratedError3({
14055
14432
  message: "No object generated: could not parse the response.",
14056
14433
  cause: parseResult.error,
14057
14434
  text: text22,
14058
- response: context.response,
14059
- usage: context.usage,
14060
- finishReason: context.finishReason
14435
+ response: context2.response,
14436
+ usage: context2.usage,
14437
+ finishReason: context2.finishReason
14061
14438
  });
14062
14439
  }
14063
14440
  const outerValue = parseResult.value;
@@ -14069,9 +14446,9 @@ var choice = ({
14069
14446
  cause: "response must be an object that contains a choice value."
14070
14447
  }),
14071
14448
  text: text22,
14072
- response: context.response,
14073
- usage: context.usage,
14074
- finishReason: context.finishReason
14449
+ response: context2.response,
14450
+ usage: context2.usage,
14451
+ finishReason: context2.finishReason
14075
14452
  });
14076
14453
  }
14077
14454
  return outerValue.result;
@@ -14099,29 +14476,33 @@ var choice = ({
14099
14476
  }
14100
14477
  }
14101
14478
  }
14479
+ },
14480
+ createElementStreamTransform() {
14481
+ return void 0;
14102
14482
  }
14103
14483
  };
14104
14484
  };
14105
14485
  var json = ({
14106
- name: name144,
14486
+ name: name21,
14107
14487
  description
14108
14488
  } = {}) => {
14109
14489
  return {
14490
+ name: "json",
14110
14491
  responseFormat: Promise.resolve({
14111
14492
  type: "json",
14112
- ...name144 != null && { name: name144 },
14493
+ ...name21 != null && { name: name21 },
14113
14494
  ...description != null && { description }
14114
14495
  }),
14115
- async parseCompleteOutput({ text: text22 }, context) {
14496
+ async parseCompleteOutput({ text: text22 }, context2) {
14116
14497
  const parseResult = await safeParseJSON3({ text: text22 });
14117
14498
  if (!parseResult.success) {
14118
14499
  throw new NoObjectGeneratedError3({
14119
14500
  message: "No object generated: could not parse the response.",
14120
14501
  cause: parseResult.error,
14121
14502
  text: text22,
14122
- response: context.response,
14123
- usage: context.usage,
14124
- finishReason: context.finishReason
14503
+ response: context2.response,
14504
+ usage: context2.usage,
14505
+ finishReason: context2.finishReason
14125
14506
  });
14126
14507
  }
14127
14508
  return parseResult.value;
@@ -14138,6 +14519,9 @@ var json = ({
14138
14519
  return result.value === void 0 ? void 0 : { partial: result.value };
14139
14520
  }
14140
14521
  }
14522
+ },
14523
+ createElementStreamTransform() {
14524
+ return void 0;
14141
14525
  }
14142
14526
  };
14143
14527
  };
@@ -14200,7 +14584,7 @@ async function embedMany3({
14200
14584
  }),
14201
14585
  tracer,
14202
14586
  fn: async (span) => {
14203
- var _a146;
14587
+ var _a21;
14204
14588
  const [maxEmbeddingsPerCall, supportsParallelCalls] = await Promise.all([
14205
14589
  model.maxEmbeddingsPerCall,
14206
14590
  model.supportsParallelCalls
@@ -14225,7 +14609,7 @@ async function embedMany3({
14225
14609
  }),
14226
14610
  tracer,
14227
14611
  fn: async (doEmbedSpan) => {
14228
- var _a154;
14612
+ var _a2222;
14229
14613
  const modelResponse = await model.doEmbed({
14230
14614
  values,
14231
14615
  abortSignal,
@@ -14233,7 +14617,7 @@ async function embedMany3({
14233
14617
  providerOptions
14234
14618
  });
14235
14619
  const embeddings3 = modelResponse.embeddings;
14236
- const usage2 = (_a154 = modelResponse.usage) != null ? _a154 : { tokens: NaN };
14620
+ const usage2 = (_a2222 = modelResponse.usage) != null ? _a2222 : { tokens: NaN };
14237
14621
  doEmbedSpan.setAttributes(
14238
14622
  await selectTelemetryAttributes3({
14239
14623
  telemetry,
@@ -14314,7 +14698,7 @@ async function embedMany3({
14314
14698
  }),
14315
14699
  tracer,
14316
14700
  fn: async (doEmbedSpan) => {
14317
- var _a154;
14701
+ var _a2222;
14318
14702
  const modelResponse = await model.doEmbed({
14319
14703
  values: chunk,
14320
14704
  abortSignal,
@@ -14322,7 +14706,7 @@ async function embedMany3({
14322
14706
  providerOptions
14323
14707
  });
14324
14708
  const embeddings2 = modelResponse.embeddings;
14325
- const usage = (_a154 = modelResponse.usage) != null ? _a154 : { tokens: NaN };
14709
+ const usage = (_a2222 = modelResponse.usage) != null ? _a2222 : { tokens: NaN };
14326
14710
  doEmbedSpan.setAttributes(
14327
14711
  await selectTelemetryAttributes3({
14328
14712
  telemetry,
@@ -14361,7 +14745,7 @@ async function embedMany3({
14361
14745
  result.providerMetadata
14362
14746
  )) {
14363
14747
  providerMetadata[providerName] = {
14364
- ...(_a146 = providerMetadata[providerName]) != null ? _a146 : {},
14748
+ ...(_a21 = providerMetadata[providerName]) != null ? _a21 : {},
14365
14749
  ...metadata
14366
14750
  };
14367
14751
  }
@@ -14452,23 +14836,32 @@ var updateWorkingMemoryTool = (memoryConfig) => {
14452
14836
  id: "update-working-memory",
14453
14837
  description,
14454
14838
  inputSchema,
14455
- execute: async (inputData, context) => {
14456
- const threadId = context?.agent?.threadId;
14457
- const resourceId = context?.agent?.resourceId;
14458
- const memory = context?.memory;
14459
- if (!threadId || !memory || !resourceId) {
14460
- throw new Error("Thread ID, Memory instance, and resourceId are required for working memory updates");
14461
- }
14462
- let thread = await memory.getThreadById({ threadId });
14463
- if (!thread) {
14464
- thread = await memory.createThread({
14465
- threadId,
14466
- resourceId,
14467
- memoryConfig
14468
- });
14839
+ execute: async (inputData, context2) => {
14840
+ const threadId = context2?.agent?.threadId;
14841
+ const resourceId = context2?.agent?.resourceId;
14842
+ const memory = context2?.memory;
14843
+ if (!memory) {
14844
+ throw new Error("Memory instance is required for working memory updates");
14845
+ }
14846
+ const scope = memoryConfig?.workingMemory?.scope || "resource";
14847
+ if (scope === "thread" && !threadId) {
14848
+ throw new Error("Thread ID is required for thread-scoped working memory updates");
14469
14849
  }
14470
- if (thread.resourceId && thread.resourceId !== resourceId) {
14471
- throw new Error(`Thread with id ${threadId} resourceId does not match the current resourceId ${resourceId}`);
14850
+ if (scope === "resource" && !resourceId) {
14851
+ throw new Error("Resource ID is required for resource-scoped working memory updates");
14852
+ }
14853
+ if (threadId) {
14854
+ let thread = await memory.getThreadById({ threadId });
14855
+ if (!thread) {
14856
+ thread = await memory.createThread({
14857
+ threadId,
14858
+ resourceId,
14859
+ memoryConfig
14860
+ });
14861
+ }
14862
+ if (thread.resourceId && resourceId && thread.resourceId !== resourceId) {
14863
+ throw new Error(`Thread with id ${threadId} resourceId does not match the current resourceId ${resourceId}`);
14864
+ }
14472
14865
  }
14473
14866
  let workingMemory;
14474
14867
  if (usesMergeSemantics) {
@@ -14531,23 +14924,32 @@ var __experimental_updateWorkingMemoryToolVNext = (config) => {
14531
14924
  "The reason you're updating working memory. Passing any value other than 'append-new-memory' requires a searchString to be provided. Defaults to append-new-memory"
14532
14925
  )
14533
14926
  }),
14534
- execute: async (inputData, context) => {
14535
- const threadId = context?.agent?.threadId;
14536
- const resourceId = context?.agent?.resourceId;
14537
- const memory = context?.memory;
14538
- if (!threadId || !memory || !resourceId) {
14539
- throw new Error("Thread ID, Memory instance, and resourceId are required for working memory updates");
14540
- }
14541
- let thread = await memory.getThreadById({ threadId });
14542
- if (!thread) {
14543
- thread = await memory.createThread({
14544
- threadId,
14545
- resourceId,
14546
- memoryConfig: config
14547
- });
14927
+ execute: async (inputData, context2) => {
14928
+ const threadId = context2?.agent?.threadId;
14929
+ const resourceId = context2?.agent?.resourceId;
14930
+ const memory = context2?.memory;
14931
+ if (!memory) {
14932
+ throw new Error("Memory instance is required for working memory updates");
14933
+ }
14934
+ const scope = config.workingMemory?.scope || "resource";
14935
+ if (scope === "thread" && !threadId) {
14936
+ throw new Error("Thread ID is required for thread-scoped working memory updates");
14937
+ }
14938
+ if (scope === "resource" && !resourceId) {
14939
+ throw new Error("Resource ID is required for resource-scoped working memory updates");
14548
14940
  }
14549
- if (thread.resourceId && thread.resourceId !== resourceId) {
14550
- throw new Error(`Thread with id ${threadId} resourceId does not match the current resourceId ${resourceId}`);
14941
+ if (threadId) {
14942
+ let thread = await memory.getThreadById({ threadId });
14943
+ if (!thread) {
14944
+ thread = await memory.createThread({
14945
+ threadId,
14946
+ resourceId,
14947
+ memoryConfig: config
14948
+ });
14949
+ }
14950
+ if (thread.resourceId && resourceId && thread.resourceId !== resourceId) {
14951
+ throw new Error(`Thread with id ${threadId} resourceId does not match the current resourceId ${resourceId}`);
14952
+ }
14551
14953
  }
14552
14954
  const workingMemory = inputData.newMemory || "";
14553
14955
  if (!inputData.updateReason) inputData.updateReason = `append-new-memory`;
@@ -14578,7 +14980,7 @@ var __experimental_updateWorkingMemoryToolVNext = (config) => {
14578
14980
  });
14579
14981
  };
14580
14982
  function normalizeObservationalMemoryConfig(config) {
14581
- if (config === true) return {};
14983
+ if (config === true) return { model: "google/gemini-2.5-flash" };
14582
14984
  if (config === false || config === void 0) return void 0;
14583
14985
  if (typeof config === "object" && config.enabled === false) return void 0;
14584
14986
  return config;
@@ -15641,9 +16043,9 @@ Notes:
15641
16043
  * @param context - Request context for runtime configuration
15642
16044
  * @returns Array of input processors configured for this memory instance
15643
16045
  */
15644
- async getInputProcessors(configuredProcessors = [], context) {
15645
- const processors = await super.getInputProcessors(configuredProcessors, context);
15646
- const om = await this.createOMProcessor(configuredProcessors, context);
16046
+ async getInputProcessors(configuredProcessors = [], context2) {
16047
+ const processors = await super.getInputProcessors(configuredProcessors, context2);
16048
+ const om = await this.createOMProcessor(configuredProcessors, context2);
15647
16049
  if (om) {
15648
16050
  processors.push(om);
15649
16051
  }
@@ -15654,9 +16056,9 @@ Notes:
15654
16056
  * OM needs processOutputResult to save messages at the end of the agent turn,
15655
16057
  * even when the observation threshold was never reached during the loop.
15656
16058
  */
15657
- async getOutputProcessors(configuredProcessors = [], context) {
15658
- const processors = await super.getOutputProcessors(configuredProcessors, context);
15659
- const om = await this.createOMProcessor(configuredProcessors, context);
16059
+ async getOutputProcessors(configuredProcessors = [], context2) {
16060
+ const processors = await super.getOutputProcessors(configuredProcessors, context2);
16061
+ const om = await this.createOMProcessor(configuredProcessors, context2);
15660
16062
  if (om) {
15661
16063
  processors.push(om);
15662
16064
  }
@@ -15667,11 +16069,11 @@ Notes:
15667
16069
  * A new instance is created per call — processorStates (e.g., sealedIds) are shared
15668
16070
  * via the ProcessorRunner's state map keyed by processor ID, not by instance identity.
15669
16071
  */
15670
- async createOMProcessor(configuredProcessors = [], context) {
16072
+ async createOMProcessor(configuredProcessors = [], context2) {
15671
16073
  const hasObservationalMemory = configuredProcessors.some(
15672
16074
  (p) => !("workflow" in p) && p.id === "observational-memory"
15673
16075
  );
15674
- const memoryContext = context?.get("MastraMemory");
16076
+ const memoryContext = context2?.get("MastraMemory");
15675
16077
  const runtimeMemoryConfig = memoryContext?.memoryConfig;
15676
16078
  const effectiveConfig = runtimeMemoryConfig ? this.getMergedThreadConfig(runtimeMemoryConfig) : this.threadConfig;
15677
16079
  const omConfig = normalizeObservationalMemoryConfig(effectiveConfig.observationalMemory);
@@ -15695,7 +16097,12 @@ Notes:
15695
16097
  `Observational memory is enabled but the storage adapter (${memoryStore.constructor.name}) does not support it. If you're using @mastra/libsql, @mastra/pg, or @mastra/mongodb, upgrade to the latest version. Otherwise, use one of those adapters or disable observational memory.`
15696
16098
  );
15697
16099
  }
15698
- const { ObservationalMemory } = await import('./observational-memory-VXLHOSDZ.js');
16100
+ if (omConfig.observation?.bufferTokens !== false && !coreFeatures.has("asyncBuffering")) {
16101
+ throw new Error(
16102
+ "Observational memory async buffering is enabled by default but the installed version of @mastra/core does not support it. Either upgrade @mastra/core, @mastra/memory, and your storage adapter (@mastra/libsql, @mastra/pg, or @mastra/mongodb) to the latest version, or explicitly disable async buffering by setting `observation: { bufferTokens: false }` in your observationalMemory config."
16103
+ );
16104
+ }
16105
+ const { ObservationalMemory } = await import('./observational-memory-TVHT3HP4.js');
15699
16106
  return new ObservationalMemory({
15700
16107
  storage: memoryStore,
15701
16108
  scope: omConfig.scope,
@@ -15706,13 +16113,18 @@ Notes:
15706
16113
  messageTokens: omConfig.observation.messageTokens,
15707
16114
  modelSettings: omConfig.observation.modelSettings,
15708
16115
  maxTokensPerBatch: omConfig.observation.maxTokensPerBatch,
15709
- providerOptions: omConfig.observation.providerOptions
16116
+ providerOptions: omConfig.observation.providerOptions,
16117
+ bufferTokens: omConfig.observation.bufferTokens,
16118
+ bufferActivation: omConfig.observation.bufferActivation,
16119
+ blockAfter: omConfig.observation.blockAfter
15710
16120
  } : void 0,
15711
16121
  reflection: omConfig.reflection ? {
15712
16122
  model: omConfig.reflection.model,
15713
16123
  observationTokens: omConfig.reflection.observationTokens,
15714
16124
  modelSettings: omConfig.reflection.modelSettings,
15715
- providerOptions: omConfig.reflection.providerOptions
16125
+ providerOptions: omConfig.reflection.providerOptions,
16126
+ bufferActivation: omConfig.reflection.bufferActivation,
16127
+ blockAfter: omConfig.reflection.blockAfter
15716
16128
  } : void 0
15717
16129
  });
15718
16130
  }