@mastra/fastembed 1.3.4-alpha.1 → 1.3.4-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -35,7 +35,7 @@ let stream_promises = require("stream/promises");
35
35
  let onnxruntime_node = require("onnxruntime-node");
36
36
  onnxruntime_node = __toESM$1(onnxruntime_node, 1);
37
37
  let _huggingface_hub = require("@huggingface/hub");
38
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v4/core/util.js
38
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v4/core/util.js
39
39
  function getEnumValues(entries) {
40
40
  const numericValues = Object.values(entries).filter((v) => typeof v === "number");
41
41
  return Object.entries(entries).filter(([k, _]) => numericValues.indexOf(+k) === -1).map(([_, v]) => v);
@@ -360,6 +360,17 @@ function prefixIssues(path, issues) {
360
360
  function unwrapMessage(message) {
361
361
  return typeof message === "string" ? message : message?.message;
362
362
  }
363
+ /** The leading size checks of `defChecks` that set an upper bound, each paired with it. */
364
+ function sizeCaps(defChecks) {
365
+ const caps = [];
366
+ for (const ch of defChecks ?? []) {
367
+ const d = ch._zod.def;
368
+ if (!/_(length|size)$|_equals$/.test(d.check)) break;
369
+ const max = d.maximum ?? d.length ?? d.size;
370
+ if (max >= 0) caps.push([max, ch]);
371
+ }
372
+ return caps;
373
+ }
363
374
  function attachSchema(issues, start, inst) {
364
375
  var _a;
365
376
  for (let i = start; i < issues.length; i++) (_a = issues[i]).schema ?? (_a.schema = inst);
@@ -574,7 +585,7 @@ function constantCatch(value) {
574
585
  return fn;
575
586
  }
576
587
  //#endregion
577
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v4/core/core.js
588
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v4/core/core.js
578
589
  var _a$8;
579
590
  const _zodDesc = {
580
591
  value: void 0,
@@ -680,7 +691,7 @@ function config(newConfig) {
680
691
  return globalConfig;
681
692
  }
682
693
  //#endregion
683
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v4/core/errors.js
694
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v4/core/errors.js
684
695
  function _getMessage() {
685
696
  const internals = this._zod;
686
697
  internals.message ?? (internals.message = JSON.stringify(internals.def, jsonStringifyReplacer, 2));
@@ -794,7 +805,7 @@ function formatError(error, mapper = (issue) => issue.message) {
794
805
  return fieldErrors;
795
806
  }
796
807
  //#endregion
797
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v4/core/parse.js
808
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v4/core/parse.js
798
809
  function finalizeParams(callee, params) {
799
810
  return {
800
811
  callee: params?.callee ?? callee,
@@ -997,7 +1008,7 @@ const _safeDecodeAsync = (_Err) => async (schema, value, _ctx) => {
997
1008
  return _safeParseAsync(_Err)(schema, value, _ctx);
998
1009
  };
999
1010
  //#endregion
1000
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v4/core/regexes.js
1011
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v4/core/regexes.js
1001
1012
  /**
1002
1013
  * @deprecated CUID v1 is deprecated by its authors due to information leakage
1003
1014
  * (timestamps embedded in the id). Use {@link cuid2} instead.
@@ -1070,7 +1081,7 @@ const _null$2 = /^null$/i;
1070
1081
  const lowercase = /^[^A-Z]*$/;
1071
1082
  const uppercase = /^[^a-z]*$/;
1072
1083
  //#endregion
1073
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v4/core/checks.js
1084
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v4/core/checks.js
1074
1085
  const $ZodCheck = /*@__PURE__*/ $constructor("$ZodCheck", (inst, def) => {
1075
1086
  var _a;
1076
1087
  inst._zod ?? (inst._zod = {});
@@ -1401,7 +1412,7 @@ const $ZodCheckOverwrite = /*@__PURE__*/ $constructor("$ZodCheckOverwrite", (ins
1401
1412
  };
1402
1413
  });
1403
1414
  //#endregion
1404
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v4/core/doc.js
1415
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v4/core/doc.js
1405
1416
  var Doc = class {
1406
1417
  constructor(args = [], closed = {}) {
1407
1418
  this.content = [];
@@ -1435,14 +1446,14 @@ var Doc = class {
1435
1446
  }
1436
1447
  };
1437
1448
  //#endregion
1438
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v4/core/versions.js
1449
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v4/core/versions.js
1439
1450
  const version = {
1440
1451
  major: 4,
1441
1452
  minor: 6,
1442
- patch: 5
1453
+ patch: 7
1443
1454
  };
1444
1455
  //#endregion
1445
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v4/core/schemas.js
1456
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v4/core/schemas.js
1446
1457
  const $ZodType = /*@__PURE__*/ $constructor("$ZodType", (inst, def) => {
1447
1458
  var _a;
1448
1459
  inst ?? (inst = {});
@@ -1939,10 +1950,6 @@ const $ZodNull = /*@__PURE__*/ $constructor("$ZodNull", (inst, def) => {
1939
1950
  return payload;
1940
1951
  };
1941
1952
  });
1942
- const $ZodAny = /*@__PURE__*/ $constructor("$ZodAny", (inst, def) => {
1943
- $ZodType.init(inst, def);
1944
- inst._zod.parse = (payload) => payload;
1945
- });
1946
1953
  const $ZodUnknown = /*@__PURE__*/ $constructor("$ZodUnknown", (inst, def) => {
1947
1954
  $ZodType.init(inst, def);
1948
1955
  inst._zod.parse = (payload) => payload;
@@ -1959,6 +1966,26 @@ const $ZodNever = /*@__PURE__*/ $constructor("$ZodNever", (inst, def) => {
1959
1966
  return payload;
1960
1967
  };
1961
1968
  });
1969
+ function capSize(inst, size) {
1970
+ const caps = sizeCaps(inst._zod.def.checks);
1971
+ if (!caps.length) return;
1972
+ const cap = Math.min(...caps.map((c) => c[0]));
1973
+ const parse = inst._zod.parse;
1974
+ inst._zod.parse = (payload, ctx) => {
1975
+ const n = size(payload.value);
1976
+ if (n > cap && !ctx?.skipChecks && ctx?.direction !== "backward") {
1977
+ for (const [max, ch] of sizeCaps(inst._zod.def.checks)) if (n > max && ch._zod.def.when(payload)) {
1978
+ const start = payload.issues.length;
1979
+ ch._zod.check(payload);
1980
+ payload.issues[start].continue = false;
1981
+ attachSchema(payload.issues, start, inst);
1982
+ return payload;
1983
+ }
1984
+ }
1985
+ return parse(payload, ctx);
1986
+ };
1987
+ }
1988
+ const arraySize = (input) => Array.isArray(input) ? input.length : -1;
1962
1989
  function handleArrayResult(result, final, index) {
1963
1990
  if (result.issues.length) final.issues.push(...prefixIssues(index, result.issues));
1964
1991
  final.value[index] = result.value;
@@ -1996,6 +2023,7 @@ const $ZodArray = /*@__PURE__*/ $constructor("$ZodArray", (inst, def) => {
1996
2023
  if (proms.length) return Promise.all(proms).then(() => payload);
1997
2024
  return payload;
1998
2025
  };
2026
+ capSize(inst, arraySize);
1999
2027
  });
2000
2028
  function handlePropertyResult(result, final, key, input, optin, optout) {
2001
2029
  const isPresent = key in input;
@@ -2909,7 +2937,7 @@ function handleRefineResult(result, payload, input, inst) {
2909
2937
  }
2910
2938
  }
2911
2939
  //#endregion
2912
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v4/core/memoizer.js
2940
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v4/core/memoizer.js
2913
2941
  var $ZodCyclicError = class extends Error {
2914
2942
  constructor() {
2915
2943
  super(`Cannot parse a reference cycle that closes through a transform`);
@@ -3162,7 +3190,7 @@ function isBackEdge(ctx, value) {
3162
3190
  return backEdges !== void 0 && isRef(value) && backEdges.has(value);
3163
3191
  }
3164
3192
  //#endregion
3165
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v4/locales/en.js
3193
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v4/locales/en.js
3166
3194
  const error = () => {
3167
3195
  const Sizable = {
3168
3196
  string: {
@@ -3270,7 +3298,7 @@ function en_default() {
3270
3298
  return { localeError: error() };
3271
3299
  }
3272
3300
  //#endregion
3273
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v4/core/registries.js
3301
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v4/core/registries.js
3274
3302
  var _a$6;
3275
3303
  var $ZodRegistry = class {
3276
3304
  constructor() {
@@ -3317,7 +3345,7 @@ function registry() {
3317
3345
  (_a$6 = globalThis).__zod_globalRegistry ?? (_a$6.__zod_globalRegistry = registry());
3318
3346
  const globalRegistry = globalThis.__zod_globalRegistry;
3319
3347
  //#endregion
3320
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v4/core/api.js
3348
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v4/core/api.js
3321
3349
  function snapshotChecks(def) {
3322
3350
  if (def.checks) def.checks = [...def.checks];
3323
3351
  return def;
@@ -3630,10 +3658,6 @@ function _null$1(Class, params) {
3630
3658
  });
3631
3659
  }
3632
3660
  // @__NO_SIDE_EFFECTS__
3633
- function _any(Class) {
3634
- return new Class({ type: "any" });
3635
- }
3636
- // @__NO_SIDE_EFFECTS__
3637
3661
  function _unknown(Class) {
3638
3662
  return new Class({ type: "unknown" });
3639
3663
  }
@@ -3856,7 +3880,7 @@ function _check(fn, params) {
3856
3880
  return ch;
3857
3881
  }
3858
3882
  //#endregion
3859
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v4/core/to-json-schema.js
3883
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v4/core/to-json-schema.js
3860
3884
  function assignProps(target, ...sources) {
3861
3885
  for (const source of sources) for (const key of Reflect.ownKeys(source)) if (Object.prototype.propertyIsEnumerable.call(source, key)) assignProp(target, key, source[key]);
3862
3886
  return target;
@@ -4298,7 +4322,7 @@ const createStandardJSONSchemaMethod = (schema, io, processors = {}) => (params)
4298
4322
  return finalize(ctx, schema);
4299
4323
  };
4300
4324
  //#endregion
4301
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v4/core/json-schema-processors.js
4325
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v4/core/json-schema-processors.js
4302
4326
  const narrowMin = (agg, key, value) => {
4303
4327
  if (agg[key] === void 0 || value > agg[key]) agg[key] = value;
4304
4328
  };
@@ -4942,7 +4966,7 @@ function toJSONSchema(input, params) {
4942
4966
  return finalize(ctx, input);
4943
4967
  }
4944
4968
  //#endregion
4945
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v4/classic/errors.js
4969
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v4/classic/errors.js
4946
4970
  const _installedErrorProtos = /* @__PURE__ */ new WeakSet([Object.prototype, Error.prototype]);
4947
4971
  function _lazyMethod(proto, key, make) {
4948
4972
  Object.defineProperty(proto, key, {
@@ -4992,7 +5016,7 @@ const initializer = (inst, issues) => {
4992
5016
  };
4993
5017
  const ZodRealError = /*@__PURE__*/ $constructor("ZodError", initializer, void 0, { Parent: Error });
4994
5018
  //#endregion
4995
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v4/classic/parse.js
5019
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v4/classic/parse.js
4996
5020
  const parse = /* @__PURE__ */ _parse$2(ZodRealError);
4997
5021
  const parseAsync = /* @__PURE__ */ _parseAsync(ZodRealError);
4998
5022
  const safeParse = /* @__PURE__ */ _safeParse(ZodRealError);
@@ -5006,7 +5030,7 @@ const safeDecode = /* @__PURE__ */ _safeDecode(ZodRealError);
5006
5030
  const safeEncodeAsync = /* @__PURE__ */ _safeEncodeAsync(ZodRealError);
5007
5031
  const safeDecodeAsync = /* @__PURE__ */ _safeDecodeAsync(ZodRealError);
5008
5032
  //#endregion
5009
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v4/classic/schemas.js
5033
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v4/classic/schemas.js
5010
5034
  function _ensureDefaultLocale() {
5011
5035
  if (!globalConfig.localeError) config(en_default());
5012
5036
  }
@@ -5517,14 +5541,6 @@ const ZodNull$1 = /*@__PURE__*/ $constructor("ZodNull", (inst, def) => {
5517
5541
  function _null(params) {
5518
5542
  return /* @__PURE__ */ _null$1(ZodNull$1, params);
5519
5543
  }
5520
- const ZodAny$1 = /*@__PURE__*/ $constructor("ZodAny", (inst, def) => {
5521
- $ZodAny.init(inst, def);
5522
- ZodType$1.init(inst, def);
5523
- inst._zod.processJSONSchema = (ctx, json, params) => void 0;
5524
- });
5525
- function any() {
5526
- return /* @__PURE__ */ _any(ZodAny$1);
5527
- }
5528
5544
  const ZodUnknown$1 = /*@__PURE__*/ $constructor("ZodUnknown", (inst, def) => {
5529
5545
  $ZodUnknown.init(inst, def);
5530
5546
  ZodType$1.init(inst, def);
@@ -5944,7 +5960,7 @@ function _instanceof(cls, params = {}) {
5944
5960
  return inst;
5945
5961
  }
5946
5962
  //#endregion
5947
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v3/helpers/util.js
5963
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v3/helpers/util.js
5948
5964
  var util;
5949
5965
  (function(util) {
5950
5966
  util.assertEqual = (_) => {};
@@ -6040,7 +6056,7 @@ const getParsedType = (data) => {
6040
6056
  }
6041
6057
  };
6042
6058
  //#endregion
6043
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v3/ZodError.js
6059
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v3/ZodError.js
6044
6060
  const ZodIssueCode = util.arrayToEnum([
6045
6061
  "invalid_type",
6046
6062
  "invalid_literal",
@@ -6148,7 +6164,7 @@ ZodError.create = (issues) => {
6148
6164
  return new ZodError(issues);
6149
6165
  };
6150
6166
  //#endregion
6151
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v3/locales/en.js
6167
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v3/locales/en.js
6152
6168
  const errorMap = (issue, _ctx) => {
6153
6169
  let message;
6154
6170
  switch (issue.code) {
@@ -6225,13 +6241,13 @@ const errorMap = (issue, _ctx) => {
6225
6241
  return { message };
6226
6242
  };
6227
6243
  //#endregion
6228
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v3/errors.js
6244
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v3/errors.js
6229
6245
  let overrideErrorMap = errorMap;
6230
6246
  function getErrorMap() {
6231
6247
  return overrideErrorMap;
6232
6248
  }
6233
6249
  //#endregion
6234
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v3/helpers/parseUtil.js
6250
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v3/helpers/parseUtil.js
6235
6251
  const makeIssue = (params) => {
6236
6252
  const { data, path, errorMaps, issueData } = params;
6237
6253
  const fullPath = [...path, ...issueData.path || []];
@@ -6335,14 +6351,14 @@ const isDirty = (x) => x.status === "dirty";
6335
6351
  const isValid = (x) => x.status === "valid";
6336
6352
  const isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
6337
6353
  //#endregion
6338
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v3/helpers/errorUtil.js
6354
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v3/helpers/errorUtil.js
6339
6355
  var errorUtil;
6340
6356
  (function(errorUtil) {
6341
6357
  errorUtil.errToObj = (message) => typeof message === "string" ? { message } : message || {};
6342
6358
  errorUtil.toString = (message) => typeof message === "string" ? message : message?.message;
6343
6359
  })(errorUtil || (errorUtil = {}));
6344
6360
  //#endregion
6345
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v3/types.js
6361
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v3/types.js
6346
6362
  var ParseInputLazyPath = class {
6347
6363
  constructor(parent, value, path, key) {
6348
6364
  this._cachedPath = [];
@@ -9498,12 +9514,12 @@ ZodNullable.create;
9498
9514
  ZodEffects.createWithPreprocess;
9499
9515
  ZodPipeline.create;
9500
9516
  //#endregion
9501
- //#region ../_vendored/ai_v5/dist/dist-CwCWl16R.js
9502
- var marker$2$6 = "vercel.ai.error";
9503
- var symbol$2$6 = Symbol.for(marker$2$6);
9504
- var _a$2$6;
9505
- var _b$2$2;
9506
- var AISDKError$1$3 = class _AISDKError extends (_b$2$2 = Error, _a$2$6 = symbol$2$6, _b$2$2) {
9517
+ //#region ../_vendored/ai_v5/dist/dist-D-EBFNkO.js
9518
+ var marker$1$6 = "vercel.ai.error";
9519
+ var symbol$1$6 = Symbol.for(marker$1$6);
9520
+ var _a$1$6;
9521
+ var _b$1$1;
9522
+ var AISDKError$2 = class _AISDKError extends (_b$1$1 = Error, _a$1$6 = symbol$1$6, _b$1$1) {
9507
9523
  /**
9508
9524
  * Creates an AI SDK Error.
9509
9525
  *
@@ -9514,7 +9530,7 @@ var AISDKError$1$3 = class _AISDKError extends (_b$2$2 = Error, _a$2$6 = symbol$
9514
9530
  */
9515
9531
  constructor({ name: name14, message, cause }) {
9516
9532
  super(message);
9517
- this[_a$2$6] = true;
9533
+ this[_a$1$6] = true;
9518
9534
  this.name = name14;
9519
9535
  this.cause = cause;
9520
9536
  }
@@ -9524,26 +9540,26 @@ var AISDKError$1$3 = class _AISDKError extends (_b$2$2 = Error, _a$2$6 = symbol$
9524
9540
  * @returns {boolean} True if the error is an AI SDK Error, false otherwise.
9525
9541
  */
9526
9542
  static isInstance(error) {
9527
- return _AISDKError.hasMarker(error, marker$2$6);
9543
+ return _AISDKError.hasMarker(error, marker$1$6);
9528
9544
  }
9529
9545
  static hasMarker(error, marker15) {
9530
9546
  const markerSymbol = Symbol.for(marker15);
9531
9547
  return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
9532
9548
  }
9533
9549
  };
9534
- var name$2$6 = "AI_APICallError";
9535
- var marker2$1$7 = `vercel.ai.error.${name$2$6}`;
9536
- var symbol2$1$7 = Symbol.for(marker2$1$7);
9537
- var _a2$1$7;
9538
- var _b2$1$3;
9539
- var APICallError$1$1 = class extends (_b2$1$3 = AISDKError$1$3, _a2$1$7 = symbol2$1$7, _b2$1$3) {
9550
+ var name$1$6 = "AI_APICallError";
9551
+ var marker2$5 = `vercel.ai.error.${name$1$6}`;
9552
+ var symbol2$5 = Symbol.for(marker2$5);
9553
+ var _a2$5;
9554
+ var _b2$1;
9555
+ (class extends (_b2$1 = AISDKError$2, _a2$5 = symbol2$5, _b2$1) {
9540
9556
  constructor({ message, url, requestBodyValues, statusCode, responseHeaders, responseBody, cause, isRetryable = statusCode != null && (statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500), data }) {
9541
9557
  super({
9542
- name: name$2$6,
9558
+ name: name$1$6,
9543
9559
  message,
9544
9560
  cause
9545
9561
  });
9546
- this[_a2$1$7] = true;
9562
+ this[_a2$5] = true;
9547
9563
  this.url = url;
9548
9564
  this.requestBodyValues = requestBodyValues;
9549
9565
  this.statusCode = statusCode;
@@ -9553,217 +9569,217 @@ var APICallError$1$1 = class extends (_b2$1$3 = AISDKError$1$3, _a2$1$7 = symbol
9553
9569
  this.data = data;
9554
9570
  }
9555
9571
  static isInstance(error) {
9556
- return AISDKError$1$3.hasMarker(error, marker2$1$7);
9572
+ return AISDKError$2.hasMarker(error, marker2$5);
9557
9573
  }
9558
- };
9559
- var name2$1$7 = "AI_EmptyResponseBodyError";
9560
- var marker3$1$7 = `vercel.ai.error.${name2$1$7}`;
9561
- var symbol3$1$7 = Symbol.for(marker3$1$7);
9562
- var _a3$1$7;
9563
- var _b3$1$3;
9564
- var EmptyResponseBodyError$1$1 = class extends (_b3$1$3 = AISDKError$1$3, _a3$1$7 = symbol3$1$7, _b3$1$3) {
9574
+ });
9575
+ var name2$5 = "AI_EmptyResponseBodyError";
9576
+ var marker3$5 = `vercel.ai.error.${name2$5}`;
9577
+ var symbol3$5 = Symbol.for(marker3$5);
9578
+ var _a3$5;
9579
+ var _b3$1;
9580
+ (class extends (_b3$1 = AISDKError$2, _a3$5 = symbol3$5, _b3$1) {
9565
9581
  constructor({ message = "Empty response body" } = {}) {
9566
9582
  super({
9567
- name: name2$1$7,
9583
+ name: name2$5,
9568
9584
  message
9569
9585
  });
9570
- this[_a3$1$7] = true;
9586
+ this[_a3$5] = true;
9571
9587
  }
9572
9588
  static isInstance(error) {
9573
- return AISDKError$1$3.hasMarker(error, marker3$1$7);
9589
+ return AISDKError$2.hasMarker(error, marker3$5);
9574
9590
  }
9575
- };
9576
- function getErrorMessage$2$1(error) {
9591
+ });
9592
+ function getErrorMessage$1$1(error) {
9577
9593
  if (error == null) return "unknown error";
9578
9594
  if (typeof error === "string") return error;
9579
9595
  if (error instanceof Error) return error.message;
9580
9596
  return JSON.stringify(error);
9581
9597
  }
9582
- var name3$1$7 = "AI_InvalidArgumentError";
9583
- var marker4$1$7 = `vercel.ai.error.${name3$1$7}`;
9584
- var symbol4$1$7 = Symbol.for(marker4$1$7);
9585
- var _a4$1$7;
9586
- var _b4$1$3;
9587
- var InvalidArgumentError$1$3 = class extends (_b4$1$3 = AISDKError$1$3, _a4$1$7 = symbol4$1$7, _b4$1$3) {
9598
+ var name3$5 = "AI_InvalidArgumentError";
9599
+ var marker4$5 = `vercel.ai.error.${name3$5}`;
9600
+ var symbol4$5 = Symbol.for(marker4$5);
9601
+ var _a4$5;
9602
+ var _b4$1;
9603
+ var InvalidArgumentError$2 = class extends (_b4$1 = AISDKError$2, _a4$5 = symbol4$5, _b4$1) {
9588
9604
  constructor({ message, cause, argument }) {
9589
9605
  super({
9590
- name: name3$1$7,
9606
+ name: name3$5,
9591
9607
  message,
9592
9608
  cause
9593
9609
  });
9594
- this[_a4$1$7] = true;
9610
+ this[_a4$5] = true;
9595
9611
  this.argument = argument;
9596
9612
  }
9597
9613
  static isInstance(error) {
9598
- return AISDKError$1$3.hasMarker(error, marker4$1$7);
9614
+ return AISDKError$2.hasMarker(error, marker4$5);
9599
9615
  }
9600
9616
  };
9601
- var name4$1$7 = "AI_InvalidPromptError";
9602
- var marker5$1$7 = `vercel.ai.error.${name4$1$7}`;
9603
- var symbol5$1$7 = Symbol.for(marker5$1$7);
9604
- var _a5$1$7;
9605
- var _b5$1$3;
9606
- (class extends (_b5$1$3 = AISDKError$1$3, _a5$1$7 = symbol5$1$7, _b5$1$3) {
9617
+ var name4$5 = "AI_InvalidPromptError";
9618
+ var marker5$5 = `vercel.ai.error.${name4$5}`;
9619
+ var symbol5$5 = Symbol.for(marker5$5);
9620
+ var _a5$5;
9621
+ var _b5$1;
9622
+ (class extends (_b5$1 = AISDKError$2, _a5$5 = symbol5$5, _b5$1) {
9607
9623
  constructor({ prompt, message, cause }) {
9608
9624
  super({
9609
- name: name4$1$7,
9625
+ name: name4$5,
9610
9626
  message: `Invalid prompt: ${message}`,
9611
9627
  cause
9612
9628
  });
9613
- this[_a5$1$7] = true;
9629
+ this[_a5$5] = true;
9614
9630
  this.prompt = prompt;
9615
9631
  }
9616
9632
  static isInstance(error) {
9617
- return AISDKError$1$3.hasMarker(error, marker5$1$7);
9633
+ return AISDKError$2.hasMarker(error, marker5$5);
9618
9634
  }
9619
9635
  });
9620
- var name5$1$7 = "AI_InvalidResponseDataError";
9621
- var marker6$1$7 = `vercel.ai.error.${name5$1$7}`;
9622
- var symbol6$1$7 = Symbol.for(marker6$1$7);
9623
- var _a6$1$7;
9624
- var _b6$1$3;
9625
- (class extends (_b6$1$3 = AISDKError$1$3, _a6$1$7 = symbol6$1$7, _b6$1$3) {
9636
+ var name5$5 = "AI_InvalidResponseDataError";
9637
+ var marker6$5 = `vercel.ai.error.${name5$5}`;
9638
+ var symbol6$5 = Symbol.for(marker6$5);
9639
+ var _a6$5;
9640
+ var _b6$1;
9641
+ (class extends (_b6$1 = AISDKError$2, _a6$5 = symbol6$5, _b6$1) {
9626
9642
  constructor({ data, message = `Invalid response data: ${JSON.stringify(data)}.` }) {
9627
9643
  super({
9628
- name: name5$1$7,
9644
+ name: name5$5,
9629
9645
  message
9630
9646
  });
9631
- this[_a6$1$7] = true;
9647
+ this[_a6$5] = true;
9632
9648
  this.data = data;
9633
9649
  }
9634
9650
  static isInstance(error) {
9635
- return AISDKError$1$3.hasMarker(error, marker6$1$7);
9651
+ return AISDKError$2.hasMarker(error, marker6$5);
9636
9652
  }
9637
9653
  });
9638
- var name6$1$7 = "AI_JSONParseError";
9639
- var marker7$1$7 = `vercel.ai.error.${name6$1$7}`;
9640
- var symbol7$1$7 = Symbol.for(marker7$1$7);
9641
- var _a7$1$7;
9642
- var _b7$1$3;
9643
- var JSONParseError$1$3 = class extends (_b7$1$3 = AISDKError$1$3, _a7$1$7 = symbol7$1$7, _b7$1$3) {
9654
+ var name6$5 = "AI_JSONParseError";
9655
+ var marker7$5 = `vercel.ai.error.${name6$5}`;
9656
+ var symbol7$5 = Symbol.for(marker7$5);
9657
+ var _a7$5;
9658
+ var _b7$1;
9659
+ var JSONParseError$2 = class extends (_b7$1 = AISDKError$2, _a7$5 = symbol7$5, _b7$1) {
9644
9660
  constructor({ text, cause }) {
9645
9661
  super({
9646
- name: name6$1$7,
9662
+ name: name6$5,
9647
9663
  message: `JSON parsing failed: Text: ${text}.
9648
- Error message: ${getErrorMessage$2$1(cause)}`,
9664
+ Error message: ${getErrorMessage$1$1(cause)}`,
9649
9665
  cause
9650
9666
  });
9651
- this[_a7$1$7] = true;
9667
+ this[_a7$5] = true;
9652
9668
  this.text = text;
9653
9669
  }
9654
9670
  static isInstance(error) {
9655
- return AISDKError$1$3.hasMarker(error, marker7$1$7);
9671
+ return AISDKError$2.hasMarker(error, marker7$5);
9656
9672
  }
9657
9673
  };
9658
- var name7$1$7 = "AI_LoadAPIKeyError";
9659
- var marker8$1$7 = `vercel.ai.error.${name7$1$7}`;
9660
- var symbol8$1$7 = Symbol.for(marker8$1$7);
9661
- var _a8$1$7;
9662
- var _b8$1$3;
9663
- (class extends (_b8$1$3 = AISDKError$1$3, _a8$1$7 = symbol8$1$7, _b8$1$3) {
9674
+ var name7$5 = "AI_LoadAPIKeyError";
9675
+ var marker8$5 = `vercel.ai.error.${name7$5}`;
9676
+ var symbol8$5 = Symbol.for(marker8$5);
9677
+ var _a8$5;
9678
+ var _b8$1;
9679
+ (class extends (_b8$1 = AISDKError$2, _a8$5 = symbol8$5, _b8$1) {
9664
9680
  constructor({ message }) {
9665
9681
  super({
9666
- name: name7$1$7,
9682
+ name: name7$5,
9667
9683
  message
9668
9684
  });
9669
- this[_a8$1$7] = true;
9685
+ this[_a8$5] = true;
9670
9686
  }
9671
9687
  static isInstance(error) {
9672
- return AISDKError$1$3.hasMarker(error, marker8$1$7);
9688
+ return AISDKError$2.hasMarker(error, marker8$5);
9673
9689
  }
9674
9690
  });
9675
- var name8$1$6 = "AI_LoadSettingError";
9676
- var marker9$1$6 = `vercel.ai.error.${name8$1$6}`;
9677
- var symbol9$1$6 = Symbol.for(marker9$1$6);
9678
- var _a9$1$6;
9679
- var _b9$1$3;
9680
- (class extends (_b9$1$3 = AISDKError$1$3, _a9$1$6 = symbol9$1$6, _b9$1$3) {
9691
+ var name8$4 = "AI_LoadSettingError";
9692
+ var marker9$4 = `vercel.ai.error.${name8$4}`;
9693
+ var symbol9$4 = Symbol.for(marker9$4);
9694
+ var _a9$4;
9695
+ var _b9$1;
9696
+ (class extends (_b9$1 = AISDKError$2, _a9$4 = symbol9$4, _b9$1) {
9681
9697
  constructor({ message }) {
9682
9698
  super({
9683
- name: name8$1$6,
9699
+ name: name8$4,
9684
9700
  message
9685
9701
  });
9686
- this[_a9$1$6] = true;
9702
+ this[_a9$4] = true;
9687
9703
  }
9688
9704
  static isInstance(error) {
9689
- return AISDKError$1$3.hasMarker(error, marker9$1$6);
9705
+ return AISDKError$2.hasMarker(error, marker9$4);
9690
9706
  }
9691
9707
  });
9692
- var name9$1$6 = "AI_NoContentGeneratedError";
9693
- var marker10$1$6 = `vercel.ai.error.${name9$1$6}`;
9694
- var symbol10$1$6 = Symbol.for(marker10$1$6);
9695
- var _a10$1$6;
9696
- var _b10$1$1;
9697
- (class extends (_b10$1$1 = AISDKError$1$3, _a10$1$6 = symbol10$1$6, _b10$1$1) {
9708
+ var name9$5 = "AI_NoContentGeneratedError";
9709
+ var marker10$5 = `vercel.ai.error.${name9$5}`;
9710
+ var symbol10$5 = Symbol.for(marker10$5);
9711
+ var _a10$5;
9712
+ var _b10$1;
9713
+ (class extends (_b10$1 = AISDKError$2, _a10$5 = symbol10$5, _b10$1) {
9698
9714
  constructor({ message = "No content generated." } = {}) {
9699
9715
  super({
9700
- name: name9$1$6,
9716
+ name: name9$5,
9701
9717
  message
9702
9718
  });
9703
- this[_a10$1$6] = true;
9719
+ this[_a10$5] = true;
9704
9720
  }
9705
9721
  static isInstance(error) {
9706
- return AISDKError$1$3.hasMarker(error, marker10$1$6);
9722
+ return AISDKError$2.hasMarker(error, marker10$5);
9707
9723
  }
9708
9724
  });
9709
- var name10$1$6 = "AI_NoSuchModelError";
9710
- var marker11$1$6 = `vercel.ai.error.${name10$1$6}`;
9711
- var symbol11$1$6 = Symbol.for(marker11$1$6);
9712
- var _a11$1$6;
9713
- var _b11$1$1;
9714
- (class extends (_b11$1$1 = AISDKError$1$3, _a11$1$6 = symbol11$1$6, _b11$1$1) {
9715
- constructor({ errorName = name10$1$6, modelId, modelType, message = `No such ${modelType}: ${modelId}` }) {
9725
+ var name10$5 = "AI_NoSuchModelError";
9726
+ var marker11$5 = `vercel.ai.error.${name10$5}`;
9727
+ var symbol11$5 = Symbol.for(marker11$5);
9728
+ var _a11$5;
9729
+ var _b11$1;
9730
+ var NoSuchModelError$2 = class extends (_b11$1 = AISDKError$2, _a11$5 = symbol11$5, _b11$1) {
9731
+ constructor({ errorName = name10$5, modelId, modelType, message = `No such ${modelType}: ${modelId}` }) {
9716
9732
  super({
9717
9733
  name: errorName,
9718
9734
  message
9719
9735
  });
9720
- this[_a11$1$6] = true;
9736
+ this[_a11$5] = true;
9721
9737
  this.modelId = modelId;
9722
9738
  this.modelType = modelType;
9723
9739
  }
9724
9740
  static isInstance(error) {
9725
- return AISDKError$1$3.hasMarker(error, marker11$1$6);
9741
+ return AISDKError$2.hasMarker(error, marker11$5);
9726
9742
  }
9727
- });
9728
- var name11$1$5 = "AI_TooManyEmbeddingValuesForCallError";
9729
- var marker12$1$5 = `vercel.ai.error.${name11$1$5}`;
9730
- var symbol12$1$5 = Symbol.for(marker12$1$5);
9731
- var _a12$1$5;
9732
- var _b12$1$1;
9733
- (class extends (_b12$1$1 = AISDKError$1$3, _a12$1$5 = symbol12$1$5, _b12$1$1) {
9743
+ };
9744
+ var name11$4 = "AI_TooManyEmbeddingValuesForCallError";
9745
+ var marker12$4 = `vercel.ai.error.${name11$4}`;
9746
+ var symbol12$4 = Symbol.for(marker12$4);
9747
+ var _a12$4;
9748
+ var _b12$1;
9749
+ (class extends (_b12$1 = AISDKError$2, _a12$4 = symbol12$4, _b12$1) {
9734
9750
  constructor(options) {
9735
9751
  super({
9736
- name: name11$1$5,
9752
+ name: name11$4,
9737
9753
  message: `Too many values for a single embedding call. The ${options.provider} model "${options.modelId}" can only embed up to ${options.maxEmbeddingsPerCall} values per call, but ${options.values.length} values were provided.`
9738
9754
  });
9739
- this[_a12$1$5] = true;
9755
+ this[_a12$4] = true;
9740
9756
  this.provider = options.provider;
9741
9757
  this.modelId = options.modelId;
9742
9758
  this.maxEmbeddingsPerCall = options.maxEmbeddingsPerCall;
9743
9759
  this.values = options.values;
9744
9760
  }
9745
9761
  static isInstance(error) {
9746
- return AISDKError$1$3.hasMarker(error, marker12$1$5);
9762
+ return AISDKError$2.hasMarker(error, marker12$4);
9747
9763
  }
9748
9764
  });
9749
- var name12$1$6 = "AI_TypeValidationError";
9750
- var marker13$1$6 = `vercel.ai.error.${name12$1$6}`;
9751
- var symbol13$1$6 = Symbol.for(marker13$1$6);
9752
- var _a13$1$6;
9753
- var _b13$1$1;
9754
- var TypeValidationError$1$3 = class _TypeValidationError extends (_b13$1$1 = AISDKError$1$3, _a13$1$6 = symbol13$1$6, _b13$1$1) {
9765
+ var name12$5 = "AI_TypeValidationError";
9766
+ var marker13$5 = `vercel.ai.error.${name12$5}`;
9767
+ var symbol13$5 = Symbol.for(marker13$5);
9768
+ var _a13$5;
9769
+ var _b13$1;
9770
+ var TypeValidationError$2 = class _TypeValidationError extends (_b13$1 = AISDKError$2, _a13$5 = symbol13$5, _b13$1) {
9755
9771
  constructor({ value, cause }) {
9756
9772
  super({
9757
- name: name12$1$6,
9773
+ name: name12$5,
9758
9774
  message: `Type validation failed: Value: ${JSON.stringify(value)}.
9759
- Error message: ${getErrorMessage$2$1(cause)}`,
9775
+ Error message: ${getErrorMessage$1$1(cause)}`,
9760
9776
  cause
9761
9777
  });
9762
- this[_a13$1$6] = true;
9778
+ this[_a13$5] = true;
9763
9779
  this.value = value;
9764
9780
  }
9765
9781
  static isInstance(error) {
9766
- return AISDKError$1$3.hasMarker(error, marker13$1$6);
9782
+ return AISDKError$2.hasMarker(error, marker13$5);
9767
9783
  }
9768
9784
  /**
9769
9785
  * Wraps an error into a TypeValidationError.
@@ -9782,253 +9798,46 @@ Error message: ${getErrorMessage$2$1(cause)}`,
9782
9798
  });
9783
9799
  }
9784
9800
  };
9785
- var name13$1$6 = "AI_UnsupportedFunctionalityError";
9786
- var marker14$1$6 = `vercel.ai.error.${name13$1$6}`;
9787
- var symbol14$1$6 = Symbol.for(marker14$1$6);
9788
- var _a14$1$6;
9789
- var _b14$1$1;
9790
- (class extends (_b14$1$1 = AISDKError$1$3, _a14$1$6 = symbol14$1$6, _b14$1$1) {
9801
+ var name13$5 = "AI_UnsupportedFunctionalityError";
9802
+ var marker14$5 = `vercel.ai.error.${name13$5}`;
9803
+ var symbol14$5 = Symbol.for(marker14$5);
9804
+ var _a14$5;
9805
+ var _b14$1;
9806
+ (class extends (_b14$1 = AISDKError$2, _a14$5 = symbol14$5, _b14$1) {
9791
9807
  constructor({ functionality, message = `'${functionality}' functionality not supported.` }) {
9792
9808
  super({
9793
- name: name13$1$6,
9809
+ name: name13$5,
9794
9810
  message
9795
9811
  });
9796
- this[_a14$1$6] = true;
9812
+ this[_a14$5] = true;
9797
9813
  this.functionality = functionality;
9798
9814
  }
9799
9815
  static isInstance(error) {
9800
- return AISDKError$1$3.hasMarker(error, marker14$1$6);
9816
+ return AISDKError$2.hasMarker(error, marker14$5);
9801
9817
  }
9802
9818
  });
9803
- var ParseError$1 = class extends Error {
9804
- constructor(message, options) {
9805
- super(message), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
9806
- }
9807
- };
9808
- const LF$1 = 10;
9809
- const CR$1 = 13;
9810
- const SPACE$1 = 32;
9811
- function noop$1(_arg) {}
9812
- function createParser$1(callbacks) {
9813
- if (typeof callbacks == "function") throw new TypeError("`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?");
9814
- const { onEvent = noop$1, onError = noop$1, onRetry = noop$1, onComment } = callbacks, pendingFragments = [];
9815
- let isFirstChunk = !0, id, data = "", dataLines = 0, eventType;
9816
- function feed(chunk) {
9817
- if (isFirstChunk && (isFirstChunk = !1, chunk.charCodeAt(0) === 239 && chunk.charCodeAt(1) === 187 && chunk.charCodeAt(2) === 191 && (chunk = chunk.slice(3))), pendingFragments.length === 0) {
9818
- const trailing2 = processLines(chunk);
9819
- trailing2 !== "" && pendingFragments.push(trailing2);
9820
- return;
9821
- }
9822
- if (chunk.indexOf(`
9823
- `) === -1 && chunk.indexOf("\r") === -1) {
9824
- pendingFragments.push(chunk);
9825
- return;
9826
- }
9827
- pendingFragments.push(chunk);
9828
- const input = pendingFragments.join("");
9829
- pendingFragments.length = 0;
9830
- const trailing = processLines(input);
9831
- trailing !== "" && pendingFragments.push(trailing);
9832
- }
9833
- function processLines(chunk) {
9834
- let searchIndex = 0;
9835
- if (chunk.indexOf("\r") === -1) {
9836
- let lfIndex = chunk.indexOf(`
9837
- `, searchIndex);
9838
- for (; lfIndex !== -1;) {
9839
- if (searchIndex === lfIndex) {
9840
- dataLines > 0 && onEvent({
9841
- id,
9842
- event: eventType,
9843
- data
9844
- }), id = void 0, data = "", dataLines = 0, eventType = void 0, searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
9845
- `, searchIndex);
9846
- continue;
9847
- }
9848
- const firstCharCode = chunk.charCodeAt(searchIndex);
9849
- if (isDataPrefix$1(chunk, searchIndex, firstCharCode)) {
9850
- const valueStart = chunk.charCodeAt(searchIndex + 5) === SPACE$1 ? searchIndex + 6 : searchIndex + 5, value = chunk.slice(valueStart, lfIndex);
9851
- if (dataLines === 0 && chunk.charCodeAt(lfIndex + 1) === LF$1) {
9852
- onEvent({
9853
- id,
9854
- event: eventType,
9855
- data: value
9856
- }), id = void 0, data = "", eventType = void 0, searchIndex = lfIndex + 2, lfIndex = chunk.indexOf(`
9857
- `, searchIndex);
9858
- continue;
9859
- }
9860
- data = dataLines === 0 ? value : `${data}
9861
- ${value}`, dataLines++;
9862
- } else isEventPrefix$1(chunk, searchIndex, firstCharCode) ? eventType = chunk.slice(chunk.charCodeAt(searchIndex + 6) === SPACE$1 ? searchIndex + 7 : searchIndex + 6, lfIndex) || void 0 : parseLine(chunk, searchIndex, lfIndex);
9863
- searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
9864
- `, searchIndex);
9865
- }
9866
- return chunk.slice(searchIndex);
9867
- }
9868
- for (; searchIndex < chunk.length;) {
9869
- const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
9870
- `, searchIndex);
9871
- let lineEnd = -1;
9872
- if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = crIndex < lfIndex ? crIndex : lfIndex : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1) break;
9873
- parseLine(chunk, searchIndex, lineEnd), searchIndex = lineEnd + 1, chunk.charCodeAt(searchIndex - 1) === CR$1 && chunk.charCodeAt(searchIndex) === LF$1 && searchIndex++;
9874
- }
9875
- return chunk.slice(searchIndex);
9876
- }
9877
- function parseLine(chunk, start, end) {
9878
- if (start === end) {
9879
- dispatchEvent();
9880
- return;
9881
- }
9882
- const firstCharCode = chunk.charCodeAt(start);
9883
- if (isDataPrefix$1(chunk, start, firstCharCode)) {
9884
- const valueStart = chunk.charCodeAt(start + 5) === SPACE$1 ? start + 6 : start + 5, value2 = chunk.slice(valueStart, end);
9885
- data = dataLines === 0 ? value2 : `${data}
9886
- ${value2}`, dataLines++;
9887
- return;
9888
- }
9889
- if (isEventPrefix$1(chunk, start, firstCharCode)) {
9890
- eventType = chunk.slice(chunk.charCodeAt(start + 6) === SPACE$1 ? start + 7 : start + 6, end) || void 0;
9891
- return;
9892
- }
9893
- if (firstCharCode === 105 && chunk.charCodeAt(start + 1) === 100 && chunk.charCodeAt(start + 2) === 58) {
9894
- const value2 = chunk.slice(chunk.charCodeAt(start + 3) === SPACE$1 ? start + 4 : start + 3, end);
9895
- id = value2.includes("\0") ? void 0 : value2;
9896
- return;
9897
- }
9898
- if (firstCharCode === 58) {
9899
- if (onComment) {
9900
- const line2 = chunk.slice(start, end);
9901
- onComment(line2.slice(chunk.charCodeAt(start + 1) === SPACE$1 ? 2 : 1));
9902
- }
9903
- return;
9904
- }
9905
- const line = chunk.slice(start, end), fieldSeparatorIndex = line.indexOf(":");
9906
- if (fieldSeparatorIndex === -1) {
9907
- processField(line, "", line);
9908
- return;
9909
- }
9910
- const field = line.slice(0, fieldSeparatorIndex), offset = line.charCodeAt(fieldSeparatorIndex + 1) === SPACE$1 ? 2 : 1;
9911
- processField(field, line.slice(fieldSeparatorIndex + offset), line);
9912
- }
9913
- function processField(field, value, line) {
9914
- switch (field) {
9915
- case "event":
9916
- eventType = value || void 0;
9917
- break;
9918
- case "data":
9919
- data = dataLines === 0 ? value : `${data}
9920
- ${value}`, dataLines++;
9921
- break;
9922
- case "id":
9923
- id = value.includes("\0") ? void 0 : value;
9924
- break;
9925
- case "retry":
9926
- /^\d+$/.test(value) ? onRetry(parseInt(value, 10)) : onError(new ParseError$1(`Invalid \`retry\` value: "${value}"`, {
9927
- type: "invalid-retry",
9928
- value,
9929
- line
9930
- }));
9931
- break;
9932
- default:
9933
- onError(new ParseError$1(`Unknown field "${field.length > 20 ? `${field.slice(0, 20)}\u2026` : field}"`, {
9934
- type: "unknown-field",
9935
- field,
9936
- value,
9937
- line
9938
- }));
9939
- break;
9940
- }
9941
- }
9942
- function dispatchEvent() {
9943
- dataLines > 0 && onEvent({
9944
- id,
9945
- event: eventType,
9946
- data
9947
- }), id = void 0, data = "", dataLines = 0, eventType = void 0;
9948
- }
9949
- function reset(options = {}) {
9950
- if (options.consume && pendingFragments.length > 0) {
9951
- const incompleteLine = pendingFragments.join("");
9952
- parseLine(incompleteLine, 0, incompleteLine.length);
9953
- }
9954
- isFirstChunk = !0, id = void 0, data = "", dataLines = 0, eventType = void 0, pendingFragments.length = 0;
9955
- }
9956
- return {
9957
- feed,
9958
- reset
9959
- };
9960
- }
9961
- function isDataPrefix$1(chunk, i, firstCharCode) {
9962
- return firstCharCode === 100 && chunk.charCodeAt(i + 1) === 97 && chunk.charCodeAt(i + 2) === 116 && chunk.charCodeAt(i + 3) === 97 && chunk.charCodeAt(i + 4) === 58;
9963
- }
9964
- function isEventPrefix$1(chunk, i, firstCharCode) {
9965
- return firstCharCode === 101 && chunk.charCodeAt(i + 1) === 118 && chunk.charCodeAt(i + 2) === 101 && chunk.charCodeAt(i + 3) === 110 && chunk.charCodeAt(i + 4) === 116 && chunk.charCodeAt(i + 5) === 58;
9966
- }
9967
- var EventSourceParserStream$1 = class extends TransformStream {
9968
- constructor({ onError, onRetry, onComment } = {}) {
9969
- let parser;
9970
- super({
9971
- start(controller) {
9972
- parser = createParser$1({
9973
- onEvent: (event) => {
9974
- controller.enqueue(event);
9975
- },
9976
- onError(error) {
9977
- onError === "terminate" ? controller.error(error) : typeof onError == "function" && onError(error);
9978
- },
9979
- onRetry,
9980
- onComment
9981
- });
9982
- },
9983
- transform(chunk) {
9984
- parser.feed(chunk);
9985
- }
9986
- });
9987
- }
9988
- };
9989
- function combineHeaders(...headers) {
9990
- return headers.reduce((combinedHeaders, currentHeaders) => ({
9991
- ...combinedHeaders,
9992
- ...currentHeaders
9993
- }), {});
9994
- }
9995
- function extractResponseHeaders(response) {
9996
- return Object.fromEntries([...response.headers]);
9997
- }
9998
- var name$1$8 = "AI_DownloadError";
9999
- var marker$1$7 = `vercel.ai.error.${name$1$8}`;
10000
- var symbol$1$8 = Symbol.for(marker$1$7);
10001
- var _a$1$8;
10002
- var _b$1$4;
10003
- var DownloadError$1 = class extends (_b$1$4 = AISDKError$1$3, _a$1$8 = symbol$1$8, _b$1$4) {
9819
+ TransformStream;
9820
+ var name$7 = "AI_DownloadError";
9821
+ var marker$7 = `vercel.ai.error.${name$7}`;
9822
+ var symbol$7 = Symbol.for(marker$7);
9823
+ var _a$7;
9824
+ var _b$2;
9825
+ (class extends (_b$2 = AISDKError$2, _a$7 = symbol$7, _b$2) {
10004
9826
  constructor({ url, statusCode, statusText, cause, message = cause == null ? `Failed to download ${url}: ${statusCode} ${statusText}` : `Failed to download ${url}: ${cause}` }) {
10005
9827
  super({
10006
- name: name$1$8,
9828
+ name: name$7,
10007
9829
  message,
10008
9830
  cause
10009
9831
  });
10010
- this[_a$1$8] = true;
9832
+ this[_a$7] = true;
10011
9833
  this.url = url;
10012
9834
  this.statusCode = statusCode;
10013
9835
  this.statusText = statusText;
10014
9836
  }
10015
9837
  static isInstance(error) {
10016
- return AISDKError$1$3.hasMarker(error, marker$1$7);
9838
+ return AISDKError$2.hasMarker(error, marker$7);
10017
9839
  }
10018
- };
10019
- async function cancelResponseBody$1(response) {
10020
- var _a2;
10021
- try {
10022
- await ((_a2 = response.body) == null ? void 0 : _a2.cancel());
10023
- } catch (e) {}
10024
- }
10025
- var initialGlobalFetch$1 = globalThis.fetch;
10026
- isNodeDefaultFetch$1(initialGlobalFetch$1);
10027
- function isNodeDefaultFetch$1(fetch) {
10028
- if (typeof fetch !== "function") return false;
10029
- const source = Function.prototype.toString.call(fetch);
10030
- return source.includes("internal/deps/undici") || source.includes("lazy loading of undici");
10031
- }
9840
+ });
10032
9841
  function getCurrentModulePath$1() {
10033
9842
  const originalPrepareStackTrace = Error.prepareStackTrace;
10034
9843
  try {
@@ -10043,50 +9852,6 @@ function getCurrentModulePath$1() {
10043
9852
  Error.prepareStackTrace = originalPrepareStackTrace;
10044
9853
  }
10045
9854
  }
10046
- var DEFAULT_MAX_DOWNLOAD_SIZE$1 = 2 * 1024 * 1024 * 1024;
10047
- async function readResponseWithSizeLimit$1({ response, url, maxBytes = DEFAULT_MAX_DOWNLOAD_SIZE$1 }) {
10048
- const contentLength = response.headers.get("content-length");
10049
- if (contentLength != null) {
10050
- const length = parseInt(contentLength, 10);
10051
- if (!isNaN(length) && length > maxBytes) {
10052
- await cancelResponseBody$1(response);
10053
- throw new DownloadError$1({
10054
- url,
10055
- message: `Download of ${url} exceeded maximum size of ${maxBytes} bytes (Content-Length: ${length}).`
10056
- });
10057
- }
10058
- }
10059
- const body = response.body;
10060
- if (body == null) return /* @__PURE__ */ new Uint8Array(0);
10061
- const reader = body.getReader();
10062
- const chunks = [];
10063
- let totalBytes = 0;
10064
- try {
10065
- while (true) {
10066
- const { done, value } = await reader.read();
10067
- if (done) break;
10068
- totalBytes += value.length;
10069
- if (totalBytes > maxBytes) throw new DownloadError$1({
10070
- url,
10071
- message: `Download of ${url} exceeded maximum size of ${maxBytes} bytes.`
10072
- });
10073
- chunks.push(value);
10074
- }
10075
- } finally {
10076
- try {
10077
- await reader.cancel();
10078
- } catch (e) {} finally {
10079
- reader.releaseLock();
10080
- }
10081
- }
10082
- const result = new Uint8Array(totalBytes);
10083
- let offset = 0;
10084
- for (const chunk of chunks) {
10085
- result.set(chunk, offset);
10086
- offset += chunk.length;
10087
- }
10088
- return result;
10089
- }
10090
9855
  var createIdGenerator$2 = ({ prefix, size = 16, alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", separator = "-" } = {}) => {
10091
9856
  const generator = () => {
10092
9857
  const alphabetLength = alphabet.length;
@@ -10095,166 +9860,13 @@ var createIdGenerator$2 = ({ prefix, size = 16, alphabet = "0123456789ABCDEFGHIJ
10095
9860
  return chars.join("");
10096
9861
  };
10097
9862
  if (prefix == null) return generator;
10098
- if (alphabet.includes(separator)) throw new InvalidArgumentError$1$3({
9863
+ if (alphabet.includes(separator)) throw new InvalidArgumentError$2({
10099
9864
  argument: "separator",
10100
9865
  message: `The separator "${separator}" must not be part of the alphabet "${alphabet}".`
10101
9866
  });
10102
9867
  return () => `${prefix}${separator}${generator()}`;
10103
9868
  };
10104
9869
  createIdGenerator$2();
10105
- function isAbortError(error) {
10106
- return (error instanceof Error || error instanceof DOMException) && (error.name === "AbortError" || error.name === "ResponseAborted" || error.name === "TimeoutError");
10107
- }
10108
- var FETCH_FAILED_ERROR_MESSAGES = ["fetch failed", "failed to fetch"];
10109
- var RETRYABLE_NETWORK_ERROR_CODES = /* @__PURE__ */ new Set([
10110
- "ConnectionRefused",
10111
- "ConnectionClosed",
10112
- "FailedToOpenSocket",
10113
- "ECONNRESET",
10114
- "ECONNREFUSED",
10115
- "ETIMEDOUT",
10116
- "EPIPE",
10117
- "UND_ERR_SOCKET",
10118
- "UND_ERR_HEADERS_TIMEOUT",
10119
- "UND_ERR_BODY_TIMEOUT",
10120
- "UND_ERR_CONNECT_TIMEOUT"
10121
- ]);
10122
- function findNetworkError(error) {
10123
- const visited = /* @__PURE__ */ new Set();
10124
- let current = error;
10125
- while (current instanceof Error && !visited.has(current)) {
10126
- visited.add(current);
10127
- const errorWithCode = current;
10128
- if (typeof errorWithCode.code === "string" && RETRYABLE_NETWORK_ERROR_CODES.has(errorWithCode.code)) return errorWithCode;
10129
- current = current.cause;
10130
- }
10131
- }
10132
- function handleFetchError({ error, url, requestBodyValues }) {
10133
- if (isAbortError(error)) return error;
10134
- if (error instanceof TypeError && FETCH_FAILED_ERROR_MESSAGES.includes(error.message.toLowerCase())) {
10135
- const cause = error.cause;
10136
- if (cause != null) return new APICallError$1$1({
10137
- message: `Cannot connect to API: ${cause.message}`,
10138
- cause,
10139
- url,
10140
- requestBodyValues,
10141
- isRetryable: true
10142
- });
10143
- }
10144
- const networkError = findNetworkError(error);
10145
- if (networkError != null) {
10146
- if (APICallError$1$1.isInstance(error)) return new APICallError$1$1({
10147
- message: error.message,
10148
- cause: error.cause,
10149
- url: error.url,
10150
- requestBodyValues: error.requestBodyValues,
10151
- statusCode: error.statusCode,
10152
- responseHeaders: error.responseHeaders,
10153
- responseBody: error.responseBody,
10154
- data: error.data,
10155
- isRetryable: true
10156
- });
10157
- return new APICallError$1$1({
10158
- message: `Cannot connect to API: ${error instanceof Error ? error.message : networkError.message}`,
10159
- cause: error,
10160
- url,
10161
- requestBodyValues,
10162
- isRetryable: true
10163
- });
10164
- }
10165
- return error;
10166
- }
10167
- function getRuntimeEnvironmentUserAgent$1(globalThisAny = globalThis) {
10168
- var _a2, _b2, _c;
10169
- if (globalThisAny.window) return `runtime/browser`;
10170
- if ((_a2 = globalThisAny.navigator) == null ? void 0 : _a2.userAgent) return `runtime/${globalThisAny.navigator.userAgent.toLowerCase()}`;
10171
- if ((_c = (_b2 = globalThisAny.process) == null ? void 0 : _b2.versions) == null ? void 0 : _c.node) return `runtime/node.js/${globalThisAny.process.version.substring(0)}`;
10172
- if (globalThisAny.EdgeRuntime) return `runtime/vercel-edge`;
10173
- return "runtime/unknown";
10174
- }
10175
- function normalizeHeaders$1(headers) {
10176
- if (headers == null) return {};
10177
- const normalized = {};
10178
- if (headers instanceof Headers) headers.forEach((value, key) => {
10179
- normalized[key.toLowerCase()] = value;
10180
- });
10181
- else {
10182
- if (!Array.isArray(headers)) headers = Object.entries(headers);
10183
- for (const [key, value] of headers) if (value != null) normalized[key.toLowerCase()] = value;
10184
- }
10185
- return normalized;
10186
- }
10187
- function withUserAgentSuffix$1(headers, ...userAgentSuffixParts) {
10188
- const normalizedHeaders = new Headers(normalizeHeaders$1(headers));
10189
- const currentUserAgentHeader = normalizedHeaders.get("user-agent") || "";
10190
- normalizedHeaders.set("user-agent", [currentUserAgentHeader, ...userAgentSuffixParts].filter(Boolean).join(" "));
10191
- return Object.fromEntries(normalizedHeaders.entries());
10192
- }
10193
- var VERSION$4 = "3.0.40";
10194
- var getOriginalFetch = () => globalThis.fetch;
10195
- var getFromApi = async ({ url, headers = {}, successfulResponseHandler, failedResponseHandler, abortSignal, fetch = getOriginalFetch() }) => {
10196
- try {
10197
- const response = await fetch(url, {
10198
- method: "GET",
10199
- headers: withUserAgentSuffix$1(headers, `ai-sdk/provider-utils/${VERSION$4}`, getRuntimeEnvironmentUserAgent$1()),
10200
- signal: abortSignal
10201
- });
10202
- const responseHeaders = extractResponseHeaders(response);
10203
- if (!response.ok) {
10204
- let errorInformation;
10205
- try {
10206
- errorInformation = await failedResponseHandler({
10207
- response,
10208
- url,
10209
- requestBodyValues: {}
10210
- });
10211
- } catch (error) {
10212
- if (isAbortError(error) || APICallError$1$1.isInstance(error)) throw error;
10213
- throw new APICallError$1$1({
10214
- message: "Failed to process error response",
10215
- cause: error,
10216
- statusCode: response.status,
10217
- url,
10218
- responseHeaders,
10219
- requestBodyValues: {}
10220
- });
10221
- }
10222
- throw errorInformation.value;
10223
- }
10224
- try {
10225
- return await successfulResponseHandler({
10226
- response,
10227
- url,
10228
- requestBodyValues: {}
10229
- });
10230
- } catch (error) {
10231
- if (error instanceof Error) {
10232
- if (isAbortError(error) || APICallError$1$1.isInstance(error)) throw error;
10233
- }
10234
- throw new APICallError$1$1({
10235
- message: "Failed to process successful response",
10236
- cause: error,
10237
- statusCode: response.status,
10238
- url,
10239
- responseHeaders,
10240
- requestBodyValues: {}
10241
- });
10242
- }
10243
- } catch (error) {
10244
- throw handleFetchError({
10245
- error,
10246
- url,
10247
- requestBodyValues: {}
10248
- });
10249
- }
10250
- };
10251
- function loadOptionalSetting({ settingValue, environmentVariableName }) {
10252
- if (typeof settingValue === "string") return settingValue;
10253
- if (settingValue != null || typeof process === "undefined") return;
10254
- settingValue = process.env[environmentVariableName];
10255
- if (settingValue == null || typeof settingValue !== "string") return;
10256
- return settingValue;
10257
- }
10258
9870
  var suspectProtoRx$1 = /"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/;
10259
9871
  var suspectConstructorRx$1 = /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;
10260
9872
  function _parse$1(text) {
@@ -10302,13 +9914,6 @@ function validator$1(validate) {
10302
9914
  function isValidator$1(value) {
10303
9915
  return typeof value === "object" && value !== null && validatorSymbol$1 in value && value[validatorSymbol$1] === true && "validate" in value;
10304
9916
  }
10305
- function lazyValidator(createValidator) {
10306
- let validator2;
10307
- return () => {
10308
- if (validator2 == null) validator2 = createValidator();
10309
- return validator2;
10310
- };
10311
- }
10312
9917
  function asValidator$1(value) {
10313
9918
  return isValidator$1(value) ? value : "~standard" in value ? standardSchemaValidator(value) : value();
10314
9919
  }
@@ -10320,24 +9925,13 @@ function standardSchemaValidator(standardSchema) {
10320
9925
  value: result.value
10321
9926
  } : {
10322
9927
  success: false,
10323
- error: new TypeValidationError$1$3({
9928
+ error: new TypeValidationError$2({
10324
9929
  value,
10325
9930
  cause: result.issues
10326
9931
  })
10327
9932
  };
10328
9933
  });
10329
9934
  }
10330
- async function validateTypes({ value, schema }) {
10331
- const result = await safeValidateTypes$2({
10332
- value,
10333
- schema
10334
- });
10335
- if (!result.success) throw TypeValidationError$1$3.wrap({
10336
- value,
10337
- cause: result.error
10338
- });
10339
- return result.value;
10340
- }
10341
9935
  async function safeValidateTypes$2({ value, schema }) {
10342
9936
  const validator2 = asValidator$1(schema);
10343
9937
  try {
@@ -10354,7 +9948,7 @@ async function safeValidateTypes$2({ value, schema }) {
10354
9948
  };
10355
9949
  return {
10356
9950
  success: false,
10357
- error: TypeValidationError$1$3.wrap({
9951
+ error: TypeValidationError$2.wrap({
10358
9952
  value,
10359
9953
  cause: result.error
10360
9954
  }),
@@ -10363,7 +9957,7 @@ async function safeValidateTypes$2({ value, schema }) {
10363
9957
  } catch (error) {
10364
9958
  return {
10365
9959
  success: false,
10366
- error: TypeValidationError$1$3.wrap({
9960
+ error: TypeValidationError$2.wrap({
10367
9961
  value,
10368
9962
  cause: error
10369
9963
  }),
@@ -10371,22 +9965,6 @@ async function safeValidateTypes$2({ value, schema }) {
10371
9965
  };
10372
9966
  }
10373
9967
  }
10374
- async function parseJSON({ text, schema }) {
10375
- try {
10376
- const value = secureJsonParse$1(text);
10377
- if (schema == null) return value;
10378
- return validateTypes({
10379
- value,
10380
- schema
10381
- });
10382
- } catch (error) {
10383
- if (JSONParseError$1$3.isInstance(error) || TypeValidationError$1$3.isInstance(error)) throw error;
10384
- throw new JSONParseError$1$3({
10385
- text,
10386
- cause: error
10387
- });
10388
- }
10389
- }
10390
9968
  async function safeParseJSON$2({ text, schema }) {
10391
9969
  try {
10392
9970
  const value = secureJsonParse$1(text);
@@ -10402,7 +9980,7 @@ async function safeParseJSON$2({ text, schema }) {
10402
9980
  } catch (error) {
10403
9981
  return {
10404
9982
  success: false,
10405
- error: JSONParseError$1$3.isInstance(error) ? error : new JSONParseError$1$3({
9983
+ error: JSONParseError$2.isInstance(error) ? error : new JSONParseError$2({
10406
9984
  text,
10407
9985
  cause: error
10408
9986
  }),
@@ -10410,275 +9988,19 @@ async function safeParseJSON$2({ text, schema }) {
10410
9988
  };
10411
9989
  }
10412
9990
  }
10413
- function parseJsonEventStream({ stream, schema }) {
10414
- return stream.pipeThrough(new TextDecoderStream()).pipeThrough(new EventSourceParserStream$1()).pipeThrough(new TransformStream({ async transform({ data }, controller) {
10415
- if (data === "[DONE]") return;
10416
- controller.enqueue(await safeParseJSON$2({
10417
- text: data,
10418
- schema
10419
- }));
10420
- } }));
10421
- }
10422
- var getOriginalFetch2 = () => globalThis.fetch;
10423
- var postJsonToApi = async ({ url, headers, body, failedResponseHandler, successfulResponseHandler, abortSignal, fetch }) => postToApi({
10424
- url,
10425
- headers: {
10426
- "Content-Type": "application/json",
10427
- ...headers
10428
- },
10429
- body: {
10430
- content: JSON.stringify(body),
10431
- values: body
10432
- },
10433
- failedResponseHandler,
10434
- successfulResponseHandler,
10435
- abortSignal,
10436
- fetch
10437
- });
10438
- var postToApi = async ({ url, headers = {}, body, successfulResponseHandler, failedResponseHandler, abortSignal, fetch = getOriginalFetch2() }) => {
10439
- try {
10440
- const response = await fetch(url, {
10441
- method: "POST",
10442
- headers: withUserAgentSuffix$1(headers, `ai-sdk/provider-utils/${VERSION$4}`, getRuntimeEnvironmentUserAgent$1()),
10443
- body: body.content,
10444
- signal: abortSignal
10445
- });
10446
- const responseHeaders = extractResponseHeaders(response);
10447
- if (!response.ok) {
10448
- let errorInformation;
10449
- try {
10450
- errorInformation = await failedResponseHandler({
10451
- response,
10452
- url,
10453
- requestBodyValues: body.values
10454
- });
10455
- } catch (error) {
10456
- if (isAbortError(error) || APICallError$1$1.isInstance(error)) throw error;
10457
- throw new APICallError$1$1({
10458
- message: "Failed to process error response",
10459
- cause: error,
10460
- statusCode: response.status,
10461
- url,
10462
- responseHeaders,
10463
- requestBodyValues: body.values
10464
- });
10465
- }
10466
- throw errorInformation.value;
10467
- }
10468
- try {
10469
- return await successfulResponseHandler({
10470
- response,
10471
- url,
10472
- requestBodyValues: body.values
10473
- });
10474
- } catch (error) {
10475
- if (error instanceof Error) {
10476
- if (isAbortError(error) || APICallError$1$1.isInstance(error)) throw error;
10477
- }
10478
- throw new APICallError$1$1({
10479
- message: "Failed to process successful response",
10480
- cause: error,
10481
- statusCode: response.status,
10482
- url,
10483
- responseHeaders,
10484
- requestBodyValues: body.values
10485
- });
10486
- }
10487
- } catch (error) {
10488
- throw handleFetchError({
10489
- error,
10490
- url,
10491
- requestBodyValues: body.values
10492
- });
10493
- }
10494
- };
10495
- function tool(tool2) {
10496
- return tool2;
10497
- }
10498
- function createProviderDefinedToolFactoryWithOutputSchema({ id, name: name2, inputSchema, outputSchema }) {
10499
- return ({ execute, toModelOutput, onInputStart, onInputDelta, onInputAvailable, ...args }) => tool({
10500
- type: "provider-defined",
10501
- id,
10502
- name: name2,
10503
- args,
10504
- inputSchema,
10505
- outputSchema,
10506
- execute,
10507
- toModelOutput,
10508
- onInputStart,
10509
- onInputDelta,
10510
- onInputAvailable
10511
- });
10512
- }
10513
- async function resolve$1(value) {
10514
- if (typeof value === "function") value = value();
10515
- return Promise.resolve(value);
10516
- }
10517
- var textDecoder$1 = new TextDecoder();
10518
- function wrapResponseBodyStream({ stream, url, requestBodyValues, statusCode, responseHeaders }) {
10519
- const reader = stream.getReader();
10520
- let readerReleased = false;
10521
- const releaseReader = () => {
10522
- if (!readerReleased) {
10523
- reader.releaseLock();
10524
- readerReleased = true;
10525
- }
10526
- };
10527
- return new ReadableStream({
10528
- async pull(controller) {
10529
- try {
10530
- const { done, value } = await reader.read();
10531
- if (done) {
10532
- releaseReader();
10533
- controller.close();
10534
- } else controller.enqueue(value);
10535
- } catch (error) {
10536
- releaseReader();
10537
- if (isAbortError(error)) {
10538
- controller.error(error);
10539
- return;
10540
- }
10541
- controller.error(handleFetchError({
10542
- error: new APICallError$1$1({
10543
- message: "Failed to process successful response",
10544
- cause: error,
10545
- statusCode,
10546
- url,
10547
- responseHeaders,
10548
- requestBodyValues
10549
- }),
10550
- url,
10551
- requestBodyValues
10552
- }));
10553
- }
10554
- },
10555
- async cancel(reason) {
10556
- try {
10557
- await reader.cancel(reason);
10558
- } finally {
10559
- releaseReader();
10560
- }
10561
- }
10562
- });
10563
- }
10564
- async function readResponseBodyAsText({ response, url }) {
10565
- return textDecoder$1.decode(await readResponseWithSizeLimit$1({
10566
- response,
10567
- url
10568
- }));
10569
- }
10570
- var createJsonErrorResponseHandler = ({ errorSchema, errorToMessage, isRetryable }) => async ({ response, url, requestBodyValues }) => {
10571
- const responseBody = await readResponseBodyAsText({
10572
- response,
10573
- url
10574
- });
10575
- const responseHeaders = extractResponseHeaders(response);
10576
- if (responseBody.trim() === "") return {
10577
- responseHeaders,
10578
- value: new APICallError$1$1({
10579
- message: response.statusText,
10580
- url,
10581
- requestBodyValues,
10582
- statusCode: response.status,
10583
- responseHeaders,
10584
- responseBody,
10585
- isRetryable: isRetryable == null ? void 0 : isRetryable(response)
10586
- })
10587
- };
10588
- try {
10589
- const parsedError = await parseJSON({
10590
- text: responseBody,
10591
- schema: errorSchema
10592
- });
10593
- return {
10594
- responseHeaders,
10595
- value: new APICallError$1$1({
10596
- message: errorToMessage(parsedError),
10597
- url,
10598
- requestBodyValues,
10599
- statusCode: response.status,
10600
- responseHeaders,
10601
- responseBody,
10602
- data: parsedError,
10603
- isRetryable: isRetryable == null ? void 0 : isRetryable(response, parsedError)
10604
- })
10605
- };
10606
- } catch (parseError) {
10607
- return {
10608
- responseHeaders,
10609
- value: new APICallError$1$1({
10610
- message: response.statusText,
10611
- url,
10612
- requestBodyValues,
10613
- statusCode: response.status,
10614
- responseHeaders,
10615
- responseBody,
10616
- isRetryable: isRetryable == null ? void 0 : isRetryable(response)
10617
- })
10618
- };
10619
- }
10620
- };
10621
- var createEventSourceResponseHandler = (chunkSchema) => async ({ response, url, requestBodyValues }) => {
10622
- const responseHeaders = extractResponseHeaders(response);
10623
- if (response.body == null) throw new EmptyResponseBodyError$1$1({});
10624
- return {
10625
- responseHeaders,
10626
- value: parseJsonEventStream({
10627
- stream: wrapResponseBodyStream({
10628
- stream: response.body,
10629
- url,
10630
- requestBodyValues,
10631
- statusCode: response.status,
10632
- responseHeaders
10633
- }),
10634
- schema: chunkSchema
10635
- })
10636
- };
10637
- };
10638
- var createJsonResponseHandler = (responseSchema) => async ({ response, url, requestBodyValues }) => {
10639
- const responseBody = await readResponseBodyAsText({
10640
- response,
10641
- url
10642
- });
10643
- const parsedResult = await safeParseJSON$2({
10644
- text: responseBody,
10645
- schema: responseSchema
10646
- });
10647
- const responseHeaders = extractResponseHeaders(response);
10648
- if (!parsedResult.success) throw new APICallError$1$1({
10649
- message: "Invalid JSON response",
10650
- cause: parsedResult.error,
10651
- statusCode: response.status,
10652
- responseHeaders,
10653
- responseBody,
10654
- url,
10655
- requestBodyValues
10656
- });
10657
- return {
10658
- responseHeaders,
10659
- value: parsedResult.value,
10660
- rawValue: parsedResult.rawValue
10661
- };
10662
- };
10663
- var schemaSymbol$2 = /* @__PURE__ */ Symbol.for("vercel.ai.schema");
10664
- function lazySchema$1(createSchema) {
10665
- let schema;
10666
- return () => {
10667
- if (schema == null) schema = createSchema();
10668
- return schema;
10669
- };
10670
- }
10671
- function jsonSchema$2(jsonSchema2, { validate } = {}) {
10672
- return {
10673
- [schemaSymbol$2]: true,
10674
- _type: void 0,
10675
- [validatorSymbol$1]: true,
10676
- get jsonSchema() {
10677
- if (typeof jsonSchema2 === "function") jsonSchema2 = jsonSchema2();
10678
- return jsonSchema2;
10679
- },
10680
- validate
10681
- };
9991
+ new TextDecoder();
9992
+ var schemaSymbol$2 = /* @__PURE__ */ Symbol.for("vercel.ai.schema");
9993
+ function jsonSchema$2(jsonSchema2, { validate } = {}) {
9994
+ return {
9995
+ [schemaSymbol$2]: true,
9996
+ _type: void 0,
9997
+ [validatorSymbol$1]: true,
9998
+ get jsonSchema() {
9999
+ if (typeof jsonSchema2 === "function") jsonSchema2 = jsonSchema2();
10000
+ return jsonSchema2;
10001
+ },
10002
+ validate
10003
+ };
10682
10004
  }
10683
10005
  function addAdditionalPropertiesToJsonSchema$1(jsonSchema2) {
10684
10006
  if (jsonSchema2.type === "object") {
@@ -11453,1560 +10775,181 @@ var selectParser$2 = (def, typeName, refs) => {
11453
10775
  case ZodFirstPartyTypeKind.ZodReadonly: return parseReadonlyDef$2(def, refs);
11454
10776
  case ZodFirstPartyTypeKind.ZodCatch: return parseCatchDef$2(def, refs);
11455
10777
  case ZodFirstPartyTypeKind.ZodPipeline: return parsePipelineDef$2(def, refs);
11456
- case ZodFirstPartyTypeKind.ZodFunction:
11457
- case ZodFirstPartyTypeKind.ZodVoid:
11458
- case ZodFirstPartyTypeKind.ZodSymbol: return;
11459
- default: return /* @__PURE__ */ ((_) => void 0)(typeName);
11460
- }
11461
- };
11462
- var getRelativePath$2 = (pathA, pathB) => {
11463
- let i = 0;
11464
- for (; i < pathA.length && i < pathB.length; i++) if (pathA[i] !== pathB[i]) break;
11465
- return [(pathA.length - i).toString(), ...pathB.slice(i)].join("/");
11466
- };
11467
- function parseDef$2(def, refs, forceResolution = false) {
11468
- var _a2;
11469
- const seenItem = refs.seen.get(def);
11470
- if (refs.override) {
11471
- const overrideResult = (_a2 = refs.override) == null ? void 0 : _a2.call(refs, def, refs, seenItem, forceResolution);
11472
- if (overrideResult !== ignoreOverride$2) return overrideResult;
11473
- }
11474
- if (seenItem && !forceResolution) {
11475
- const seenSchema = get$ref$2(seenItem, refs);
11476
- if (seenSchema !== void 0) return seenSchema;
11477
- }
11478
- const newItem = {
11479
- def,
11480
- path: refs.currentPath,
11481
- jsonSchema: void 0
11482
- };
11483
- refs.seen.set(def, newItem);
11484
- const jsonSchemaOrGetter = selectParser$2(def, def.typeName, refs);
11485
- const jsonSchema2 = typeof jsonSchemaOrGetter === "function" ? parseDef$2(jsonSchemaOrGetter(), refs) : jsonSchemaOrGetter;
11486
- if (jsonSchema2) addMeta$2(def, refs, jsonSchema2);
11487
- if (refs.postProcess) {
11488
- const postProcessResult = refs.postProcess(jsonSchema2, def, refs);
11489
- newItem.jsonSchema = jsonSchema2;
11490
- return postProcessResult;
11491
- }
11492
- newItem.jsonSchema = jsonSchema2;
11493
- return jsonSchema2;
11494
- }
11495
- var get$ref$2 = (item, refs) => {
11496
- switch (refs.$refStrategy) {
11497
- case "root": return { $ref: item.path.join("/") };
11498
- case "relative": return { $ref: getRelativePath$2(refs.currentPath, item.path) };
11499
- case "none":
11500
- case "seen":
11501
- if (item.path.length < refs.currentPath.length && item.path.every((value, index) => refs.currentPath[index] === value)) {
11502
- console.warn(`Recursive reference detected at ${refs.currentPath.join("/")}! Defaulting to any`);
11503
- return parseAnyDef$2();
11504
- }
11505
- return refs.$refStrategy === "seen" ? parseAnyDef$2() : void 0;
11506
- }
11507
- };
11508
- var addMeta$2 = (def, refs, jsonSchema2) => {
11509
- if (def.description) jsonSchema2.description = def.description;
11510
- return jsonSchema2;
11511
- };
11512
- var getRefs$2 = (options) => {
11513
- const _options = getDefaultOptions$2(options);
11514
- const currentPath = _options.name !== void 0 ? [
11515
- ..._options.basePath,
11516
- _options.definitionPath,
11517
- _options.name
11518
- ] : _options.basePath;
11519
- return {
11520
- ..._options,
11521
- currentPath,
11522
- propertyPath: void 0,
11523
- seen: new Map(Object.entries(_options.definitions).map(([name2, def]) => [def._def, {
11524
- def: def._def,
11525
- path: [
11526
- ..._options.basePath,
11527
- _options.definitionPath,
11528
- name2
11529
- ],
11530
- jsonSchema: void 0
11531
- }]))
11532
- };
11533
- };
11534
- var zodToJsonSchema$1 = (schema, options) => {
11535
- var _a2;
11536
- const refs = getRefs$2(options);
11537
- let definitions = typeof options === "object" && options.definitions ? Object.entries(options.definitions).reduce((acc, [name3, schema2]) => {
11538
- var _a3;
11539
- return {
11540
- ...acc,
11541
- [name3]: (_a3 = parseDef$2(schema2._def, {
11542
- ...refs,
11543
- currentPath: [
11544
- ...refs.basePath,
11545
- refs.definitionPath,
11546
- name3
11547
- ]
11548
- }, true)) != null ? _a3 : parseAnyDef$2()
11549
- };
11550
- }, {}) : void 0;
11551
- const name2 = typeof options === "string" ? options : (options == null ? void 0 : options.nameStrategy) === "title" ? void 0 : options == null ? void 0 : options.name;
11552
- const main = (_a2 = parseDef$2(schema._def, name2 === void 0 ? refs : {
11553
- ...refs,
11554
- currentPath: [
11555
- ...refs.basePath,
11556
- refs.definitionPath,
11557
- name2
11558
- ]
11559
- }, false)) != null ? _a2 : parseAnyDef$2();
11560
- const title = typeof options === "object" && options.name !== void 0 && options.nameStrategy === "title" ? options.name : void 0;
11561
- if (title !== void 0) main.title = title;
11562
- const combined = name2 === void 0 ? definitions ? {
11563
- ...main,
11564
- [refs.definitionPath]: definitions
11565
- } : main : {
11566
- $ref: [
11567
- ...refs.$refStrategy === "relative" ? [] : refs.basePath,
11568
- refs.definitionPath,
11569
- name2
11570
- ].join("/"),
11571
- [refs.definitionPath]: {
11572
- ...definitions,
11573
- [name2]: main
11574
- }
11575
- };
11576
- combined.$schema = "http://json-schema.org/draft-07/schema#";
11577
- return combined;
11578
- };
11579
- var zod_to_json_schema_default = zodToJsonSchema$1;
11580
- function zod3Schema$1(zodSchema2, options) {
11581
- var _a2;
11582
- const useReferences = (_a2 = options == null ? void 0 : options.useReferences) != null ? _a2 : false;
11583
- return jsonSchema$2(() => zod_to_json_schema_default(zodSchema2, { $refStrategy: useReferences ? "root" : "none" }), { validate: async (value) => {
11584
- const result = await zodSchema2.safeParseAsync(value);
11585
- return result.success ? {
11586
- success: true,
11587
- value: result.data
11588
- } : {
11589
- success: false,
11590
- error: result.error
11591
- };
11592
- } });
11593
- }
11594
- function zod4Schema$1(zodSchema2, options) {
11595
- var _a2;
11596
- const useReferences = (_a2 = options == null ? void 0 : options.useReferences) != null ? _a2 : false;
11597
- return jsonSchema$2(() => addAdditionalPropertiesToJsonSchema$1(toJSONSchema(zodSchema2, {
11598
- target: "draft-7",
11599
- io: "input",
11600
- reused: useReferences ? "ref" : "inline"
11601
- })), { validate: async (value) => {
11602
- const result = await safeParseAsync(zodSchema2, value);
11603
- return result.success ? {
11604
- success: true,
11605
- value: result.data
11606
- } : {
11607
- success: false,
11608
- error: result.error
11609
- };
11610
- } });
11611
- }
11612
- function isZod4Schema$1(zodSchema2) {
11613
- return "_zod" in zodSchema2;
11614
- }
11615
- function zodSchema$2(zodSchema2, options) {
11616
- if (isZod4Schema$1(zodSchema2)) return zod4Schema$1(zodSchema2, options);
11617
- else return zod3Schema$1(zodSchema2, options);
11618
- }
11619
- function isSchema$2(value) {
11620
- return typeof value === "object" && value !== null && schemaSymbol$2 in value && value[schemaSymbol$2] === true && "jsonSchema" in value && "validate" in value;
11621
- }
11622
- function asSchema$2(schema) {
11623
- return schema == null ? jsonSchema$2({
11624
- properties: {},
11625
- additionalProperties: false
11626
- }) : isSchema$2(schema) ? schema : typeof schema === "function" ? schema() : zodSchema$2(schema);
11627
- }
11628
- var { btoa: btoa$3, atob: atob$3 } = globalThis;
11629
- function withoutTrailingSlash(url) {
11630
- return url == null ? void 0 : url.replace(/\/$/, "");
11631
- }
11632
- var marker$7 = "vercel.ai.error";
11633
- var symbol$9 = Symbol.for(marker$7);
11634
- var _a$9;
11635
- var _b$5;
11636
- var AISDKError$4 = class _AISDKError extends (_b$5 = Error, _a$9 = symbol$9, _b$5) {
11637
- /**
11638
- * Creates an AI SDK Error.
11639
- *
11640
- * @param {Object} params - The parameters for creating the error.
11641
- * @param {string} params.name - The name of the error.
11642
- * @param {string} params.message - The error message.
11643
- * @param {unknown} [params.cause] - The underlying cause of the error.
11644
- */
11645
- constructor({ name: name14, message, cause }) {
11646
- super(message);
11647
- this[_a$9] = true;
11648
- this.name = name14;
11649
- this.cause = cause;
11650
- }
11651
- /**
11652
- * Checks if the given error is an AI SDK Error.
11653
- * @param {unknown} error - The error to check.
11654
- * @returns {boolean} True if the error is an AI SDK Error, false otherwise.
11655
- */
11656
- static isInstance(error) {
11657
- return _AISDKError.hasMarker(error, marker$7);
11658
- }
11659
- static hasMarker(error, marker15) {
11660
- const markerSymbol = Symbol.for(marker15);
11661
- return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
11662
- }
11663
- };
11664
- var name$9 = "AI_APICallError";
11665
- var marker2$5 = `vercel.ai.error.${name$9}`;
11666
- var symbol2$5 = Symbol.for(marker2$5);
11667
- var _a2$5;
11668
- var _b2$4;
11669
- var APICallError$2 = class extends (_b2$4 = AISDKError$4, _a2$5 = symbol2$5, _b2$4) {
11670
- constructor({ message, url, requestBodyValues, statusCode, responseHeaders, responseBody, cause, isRetryable = statusCode != null && (statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500), data }) {
11671
- super({
11672
- name: name$9,
11673
- message,
11674
- cause
11675
- });
11676
- this[_a2$5] = true;
11677
- this.url = url;
11678
- this.requestBodyValues = requestBodyValues;
11679
- this.statusCode = statusCode;
11680
- this.responseHeaders = responseHeaders;
11681
- this.responseBody = responseBody;
11682
- this.isRetryable = isRetryable;
11683
- this.data = data;
11684
- }
11685
- static isInstance(error) {
11686
- return AISDKError$4.hasMarker(error, marker2$5);
11687
- }
11688
- };
11689
- var name2$5 = "AI_EmptyResponseBodyError";
11690
- var marker3$5 = `vercel.ai.error.${name2$5}`;
11691
- var symbol3$5 = Symbol.for(marker3$5);
11692
- var _a3$5;
11693
- var _b3$4;
11694
- (class extends (_b3$4 = AISDKError$4, _a3$5 = symbol3$5, _b3$4) {
11695
- constructor({ message = "Empty response body" } = {}) {
11696
- super({
11697
- name: name2$5,
11698
- message
11699
- });
11700
- this[_a3$5] = true;
11701
- }
11702
- static isInstance(error) {
11703
- return AISDKError$4.hasMarker(error, marker3$5);
11704
- }
11705
- });
11706
- function getErrorMessage$3(error) {
11707
- if (error == null) return "unknown error";
11708
- if (typeof error === "string") return error;
11709
- if (error instanceof Error) return error.message;
11710
- return JSON.stringify(error);
11711
- }
11712
- var name3$5 = "AI_InvalidArgumentError";
11713
- var marker4$5 = `vercel.ai.error.${name3$5}`;
11714
- var symbol4$5 = Symbol.for(marker4$5);
11715
- var _a4$5;
11716
- var _b4$4;
11717
- (class extends (_b4$4 = AISDKError$4, _a4$5 = symbol4$5, _b4$4) {
11718
- constructor({ message, cause, argument }) {
11719
- super({
11720
- name: name3$5,
11721
- message,
11722
- cause
11723
- });
11724
- this[_a4$5] = true;
11725
- this.argument = argument;
11726
- }
11727
- static isInstance(error) {
11728
- return AISDKError$4.hasMarker(error, marker4$5);
11729
- }
11730
- });
11731
- var name4$5 = "AI_InvalidPromptError";
11732
- var marker5$5 = `vercel.ai.error.${name4$5}`;
11733
- var symbol5$5 = Symbol.for(marker5$5);
11734
- var _a5$5;
11735
- var _b5$4;
11736
- (class extends (_b5$4 = AISDKError$4, _a5$5 = symbol5$5, _b5$4) {
11737
- constructor({ prompt, message, cause }) {
11738
- super({
11739
- name: name4$5,
11740
- message: `Invalid prompt: ${message}`,
11741
- cause
11742
- });
11743
- this[_a5$5] = true;
11744
- this.prompt = prompt;
11745
- }
11746
- static isInstance(error) {
11747
- return AISDKError$4.hasMarker(error, marker5$5);
11748
- }
11749
- });
11750
- var name5$5 = "AI_InvalidResponseDataError";
11751
- var marker6$5 = `vercel.ai.error.${name5$5}`;
11752
- var symbol6$5 = Symbol.for(marker6$5);
11753
- var _a6$5;
11754
- var _b6$4;
11755
- (class extends (_b6$4 = AISDKError$4, _a6$5 = symbol6$5, _b6$4) {
11756
- constructor({ data, message = `Invalid response data: ${JSON.stringify(data)}.` }) {
11757
- super({
11758
- name: name5$5,
11759
- message
11760
- });
11761
- this[_a6$5] = true;
11762
- this.data = data;
11763
- }
11764
- static isInstance(error) {
11765
- return AISDKError$4.hasMarker(error, marker6$5);
11766
- }
11767
- });
11768
- var name6$5 = "AI_JSONParseError";
11769
- var marker7$5 = `vercel.ai.error.${name6$5}`;
11770
- var symbol7$5 = Symbol.for(marker7$5);
11771
- var _a7$5;
11772
- var _b7$4;
11773
- (class extends (_b7$4 = AISDKError$4, _a7$5 = symbol7$5, _b7$4) {
11774
- constructor({ text, cause }) {
11775
- super({
11776
- name: name6$5,
11777
- message: `JSON parsing failed: Text: ${text}.
11778
- Error message: ${getErrorMessage$3(cause)}`,
11779
- cause
11780
- });
11781
- this[_a7$5] = true;
11782
- this.text = text;
11783
- }
11784
- static isInstance(error) {
11785
- return AISDKError$4.hasMarker(error, marker7$5);
11786
- }
11787
- });
11788
- var name7$5 = "AI_LoadAPIKeyError";
11789
- var marker8$5 = `vercel.ai.error.${name7$5}`;
11790
- var symbol8$5 = Symbol.for(marker8$5);
11791
- var _a8$5;
11792
- var _b8$4;
11793
- (class extends (_b8$4 = AISDKError$4, _a8$5 = symbol8$5, _b8$4) {
11794
- constructor({ message }) {
11795
- super({
11796
- name: name7$5,
11797
- message
11798
- });
11799
- this[_a8$5] = true;
11800
- }
11801
- static isInstance(error) {
11802
- return AISDKError$4.hasMarker(error, marker8$5);
11803
- }
11804
- });
11805
- var name8$4 = "AI_LoadSettingError";
11806
- var marker9$4 = `vercel.ai.error.${name8$4}`;
11807
- var symbol9$4 = Symbol.for(marker9$4);
11808
- var _a9$4;
11809
- var _b9$4;
11810
- (class extends (_b9$4 = AISDKError$4, _a9$4 = symbol9$4, _b9$4) {
11811
- constructor({ message }) {
11812
- super({
11813
- name: name8$4,
11814
- message
11815
- });
11816
- this[_a9$4] = true;
11817
- }
11818
- static isInstance(error) {
11819
- return AISDKError$4.hasMarker(error, marker9$4);
11820
- }
11821
- });
11822
- var name9$7 = "AI_NoContentGeneratedError";
11823
- var marker10$7 = `vercel.ai.error.${name9$7}`;
11824
- var symbol10$7 = Symbol.for(marker10$7);
11825
- var _a10$7;
11826
- var _b10$2;
11827
- (class extends (_b10$2 = AISDKError$4, _a10$7 = symbol10$7, _b10$2) {
11828
- constructor({ message = "No content generated." } = {}) {
11829
- super({
11830
- name: name9$7,
11831
- message
11832
- });
11833
- this[_a10$7] = true;
11834
- }
11835
- static isInstance(error) {
11836
- return AISDKError$4.hasMarker(error, marker10$7);
11837
- }
11838
- });
11839
- var name10$7 = "AI_NoSuchModelError";
11840
- var marker11$7 = `vercel.ai.error.${name10$7}`;
11841
- var symbol11$7 = Symbol.for(marker11$7);
11842
- var _a11$7;
11843
- var _b11$2;
11844
- var NoSuchModelError$2 = class extends (_b11$2 = AISDKError$4, _a11$7 = symbol11$7, _b11$2) {
11845
- constructor({ errorName = name10$7, modelId, modelType, message = `No such ${modelType}: ${modelId}` }) {
11846
- super({
11847
- name: errorName,
11848
- message
11849
- });
11850
- this[_a11$7] = true;
11851
- this.modelId = modelId;
11852
- this.modelType = modelType;
11853
- }
11854
- static isInstance(error) {
11855
- return AISDKError$4.hasMarker(error, marker11$7);
11856
- }
11857
- };
11858
- var name11$6 = "AI_TooManyEmbeddingValuesForCallError";
11859
- var marker12$6 = `vercel.ai.error.${name11$6}`;
11860
- var symbol12$6 = Symbol.for(marker12$6);
11861
- var _a12$6;
11862
- var _b12$2;
11863
- (class extends (_b12$2 = AISDKError$4, _a12$6 = symbol12$6, _b12$2) {
11864
- constructor(options) {
11865
- super({
11866
- name: name11$6,
11867
- message: `Too many values for a single embedding call. The ${options.provider} model "${options.modelId}" can only embed up to ${options.maxEmbeddingsPerCall} values per call, but ${options.values.length} values were provided.`
11868
- });
11869
- this[_a12$6] = true;
11870
- this.provider = options.provider;
11871
- this.modelId = options.modelId;
11872
- this.maxEmbeddingsPerCall = options.maxEmbeddingsPerCall;
11873
- this.values = options.values;
11874
- }
11875
- static isInstance(error) {
11876
- return AISDKError$4.hasMarker(error, marker12$6);
11877
- }
11878
- });
11879
- var name12$7 = "AI_TypeValidationError";
11880
- var marker13$7 = `vercel.ai.error.${name12$7}`;
11881
- var symbol13$7 = Symbol.for(marker13$7);
11882
- var _a13$7;
11883
- var _b13$2;
11884
- (class _TypeValidationError extends (_b13$2 = AISDKError$4, _a13$7 = symbol13$7, _b13$2) {
11885
- constructor({ value, cause }) {
11886
- super({
11887
- name: name12$7,
11888
- message: `Type validation failed: Value: ${JSON.stringify(value)}.
11889
- Error message: ${getErrorMessage$3(cause)}`,
11890
- cause
11891
- });
11892
- this[_a13$7] = true;
11893
- this.value = value;
11894
- }
11895
- static isInstance(error) {
11896
- return AISDKError$4.hasMarker(error, marker13$7);
11897
- }
11898
- /**
11899
- * Wraps an error into a TypeValidationError.
11900
- * If the cause is already a TypeValidationError with the same value, it returns the cause.
11901
- * Otherwise, it creates a new TypeValidationError.
11902
- *
11903
- * @param {Object} params - The parameters for wrapping the error.
11904
- * @param {unknown} params.value - The value that failed validation.
11905
- * @param {unknown} params.cause - The original error or cause of the validation failure.
11906
- * @returns {TypeValidationError} A TypeValidationError instance.
11907
- */
11908
- static wrap({ value, cause }) {
11909
- return _TypeValidationError.isInstance(cause) && cause.value === value ? cause : new _TypeValidationError({
11910
- value,
11911
- cause
11912
- });
11913
- }
11914
- });
11915
- var name13$7 = "AI_UnsupportedFunctionalityError";
11916
- var marker14$7 = `vercel.ai.error.${name13$7}`;
11917
- var symbol14$7 = Symbol.for(marker14$7);
11918
- var _a14$7;
11919
- var _b14$2;
11920
- (class extends (_b14$2 = AISDKError$4, _a14$7 = symbol14$7, _b14$2) {
11921
- constructor({ functionality, message = `'${functionality}' functionality not supported.` }) {
11922
- super({
11923
- name: name13$7,
11924
- message
11925
- });
11926
- this[_a14$7] = true;
11927
- this.functionality = functionality;
11928
- }
11929
- static isInstance(error) {
11930
- return AISDKError$4.hasMarker(error, marker14$7);
11931
- }
11932
- });
11933
- //#endregion
11934
- //#region ../_vendored/ai_v5/dist/index.js
11935
- function getContext() {
11936
- return { headers: {} };
11937
- }
11938
- async function getVercelOidcToken() {
11939
- if (process.env.VERCEL_OIDC_TOKEN) return process.env.VERCEL_OIDC_TOKEN ?? "";
11940
- throw new Error("@vercel/oidc is not available in the vendored @internal AI packages. Provide an API key instead.");
11941
- }
11942
- var symbol$1$6 = Symbol.for("vercel.ai.gateway.error");
11943
- var _a$1$6;
11944
- var _b$3;
11945
- var GatewayError = class _GatewayError extends (_b$3 = Error, _a$1$6 = symbol$1$6, _b$3) {
11946
- constructor({ message, statusCode = 500, cause }) {
11947
- super(message);
11948
- this[_a$1$6] = true;
11949
- this.statusCode = statusCode;
11950
- this.cause = cause;
11951
- }
11952
- /**
11953
- * Checks if the given error is a Gateway Error.
11954
- * @param {unknown} error - The error to check.
11955
- * @returns {boolean} True if the error is a Gateway Error, false otherwise.
11956
- */
11957
- static isInstance(error) {
11958
- return _GatewayError.hasMarker(error);
11959
- }
11960
- static hasMarker(error) {
11961
- return typeof error === "object" && error !== null && symbol$1$6 in error && error[symbol$1$6] === true;
11962
- }
11963
- };
11964
- var name$1$6 = "GatewayAuthenticationError";
11965
- var marker2$1$5 = `vercel.ai.gateway.error.${name$1$6}`;
11966
- var symbol2$1$5 = Symbol.for(marker2$1$5);
11967
- var _a2$1$5;
11968
- var _b2$2;
11969
- var GatewayAuthenticationError = class _GatewayAuthenticationError extends (_b2$2 = GatewayError, _a2$1$5 = symbol2$1$5, _b2$2) {
11970
- constructor({ message = "Authentication failed", statusCode = 401, cause } = {}) {
11971
- super({
11972
- message,
11973
- statusCode,
11974
- cause
11975
- });
11976
- this[_a2$1$5] = true;
11977
- this.name = name$1$6;
11978
- this.type = "authentication_error";
11979
- }
11980
- static isInstance(error) {
11981
- return GatewayError.hasMarker(error) && symbol2$1$5 in error;
11982
- }
11983
- /**
11984
- * Creates a contextual error message when authentication fails
11985
- */
11986
- static createContextualError({ apiKeyProvided, oidcTokenProvided, message = "Authentication failed", statusCode = 401, cause }) {
11987
- let contextualMessage;
11988
- if (apiKeyProvided) contextualMessage = `AI Gateway authentication failed: Invalid API key.
11989
-
11990
- Create a new API key: https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai%2Fapi-keys
11991
-
11992
- Provide via 'apiKey' option or 'AI_GATEWAY_API_KEY' environment variable.`;
11993
- else if (oidcTokenProvided) contextualMessage = `AI Gateway authentication failed: Invalid OIDC token.
11994
-
11995
- Run 'npx vercel link' to link your project, then 'vc env pull' to fetch the token.
11996
-
11997
- Alternatively, use an API key: https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai%2Fapi-keys`;
11998
- else contextualMessage = `AI Gateway authentication failed: No authentication provided.
11999
-
12000
- Option 1 - API key:
12001
- Create an API key: https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai%2Fapi-keys
12002
- Provide via 'apiKey' option or 'AI_GATEWAY_API_KEY' environment variable.
12003
-
12004
- Option 2 - OIDC token:
12005
- Run 'npx vercel link' to link your project, then 'vc env pull' to fetch the token.`;
12006
- return new _GatewayAuthenticationError({
12007
- message: contextualMessage,
12008
- statusCode,
12009
- cause
12010
- });
12011
- }
12012
- };
12013
- var name2$1$5 = "GatewayForbiddenError";
12014
- var marker3$1$5 = `vercel.ai.gateway.error.${name2$1$5}`;
12015
- var symbol3$1$5 = Symbol.for(marker3$1$5);
12016
- var forbiddenParamSchema = lazyValidator(() => zodSchema$2(object$3({ ruleId: string() })));
12017
- var _a3$1$5;
12018
- var _b3$2;
12019
- var GatewayForbiddenError = class extends (_b3$2 = GatewayError, _a3$1$5 = symbol3$1$5, _b3$2) {
12020
- constructor({ message = "Forbidden", statusCode = 403, cause, ruleId } = {}) {
12021
- super({
12022
- message,
12023
- statusCode,
12024
- cause
12025
- });
12026
- this[_a3$1$5] = true;
12027
- this.name = name2$1$5;
12028
- this.type = "forbidden";
12029
- this.ruleId = ruleId;
12030
- }
12031
- static isInstance(error) {
12032
- return GatewayError.hasMarker(error) && symbol3$1$5 in error;
12033
- }
12034
- };
12035
- var name3$1$5 = "GatewayInvalidRequestError";
12036
- var marker4$1$5 = `vercel.ai.gateway.error.${name3$1$5}`;
12037
- var symbol4$1$5 = Symbol.for(marker4$1$5);
12038
- var _a4$1$5;
12039
- var _b4$2;
12040
- var GatewayInvalidRequestError = class extends (_b4$2 = GatewayError, _a4$1$5 = symbol4$1$5, _b4$2) {
12041
- constructor({ message = "Invalid request", statusCode = 400, cause } = {}) {
12042
- super({
12043
- message,
12044
- statusCode,
12045
- cause
12046
- });
12047
- this[_a4$1$5] = true;
12048
- this.name = name3$1$5;
12049
- this.type = "invalid_request_error";
12050
- }
12051
- static isInstance(error) {
12052
- return GatewayError.hasMarker(error) && symbol4$1$5 in error;
12053
- }
12054
- };
12055
- var name4$1$5 = "GatewayRateLimitError";
12056
- var marker5$1$5 = `vercel.ai.gateway.error.${name4$1$5}`;
12057
- var symbol5$1$5 = Symbol.for(marker5$1$5);
12058
- var _a5$1$5;
12059
- var _b5$2;
12060
- var GatewayRateLimitError = class extends (_b5$2 = GatewayError, _a5$1$5 = symbol5$1$5, _b5$2) {
12061
- constructor({ message = "Rate limit exceeded", statusCode = 429, cause } = {}) {
12062
- super({
12063
- message,
12064
- statusCode,
12065
- cause
12066
- });
12067
- this[_a5$1$5] = true;
12068
- this.name = name4$1$5;
12069
- this.type = "rate_limit_exceeded";
12070
- }
12071
- static isInstance(error) {
12072
- return GatewayError.hasMarker(error) && symbol5$1$5 in error;
12073
- }
12074
- };
12075
- var name5$1$5 = "GatewayModelNotFoundError";
12076
- var marker6$1$5 = `vercel.ai.gateway.error.${name5$1$5}`;
12077
- var symbol6$1$5 = Symbol.for(marker6$1$5);
12078
- var modelNotFoundParamSchema = lazyValidator(() => zodSchema$2(object$3({ modelId: string() })));
12079
- var _a6$1$5;
12080
- var _b6$2;
12081
- var GatewayModelNotFoundError = class extends (_b6$2 = GatewayError, _a6$1$5 = symbol6$1$5, _b6$2) {
12082
- constructor({ message = "Model not found", statusCode = 404, modelId, cause } = {}) {
12083
- super({
12084
- message,
12085
- statusCode,
12086
- cause
12087
- });
12088
- this[_a6$1$5] = true;
12089
- this.name = name5$1$5;
12090
- this.type = "model_not_found";
12091
- this.modelId = modelId;
12092
- }
12093
- static isInstance(error) {
12094
- return GatewayError.hasMarker(error) && symbol6$1$5 in error;
12095
- }
12096
- };
12097
- var name6$1$5 = "GatewayInternalServerError";
12098
- var marker7$1$5 = `vercel.ai.gateway.error.${name6$1$5}`;
12099
- var symbol7$1$5 = Symbol.for(marker7$1$5);
12100
- var _a7$1$5;
12101
- var _b7$2;
12102
- var GatewayInternalServerError = class extends (_b7$2 = GatewayError, _a7$1$5 = symbol7$1$5, _b7$2) {
12103
- constructor({ message = "Internal server error", statusCode = 500, cause } = {}) {
12104
- super({
12105
- message,
12106
- statusCode,
12107
- cause
12108
- });
12109
- this[_a7$1$5] = true;
12110
- this.name = name6$1$5;
12111
- this.type = "internal_server_error";
12112
- }
12113
- static isInstance(error) {
12114
- return GatewayError.hasMarker(error) && symbol7$1$5 in error;
12115
- }
12116
- };
12117
- var name7$1$5 = "GatewayResponseError";
12118
- var marker8$1$5 = `vercel.ai.gateway.error.${name7$1$5}`;
12119
- var symbol8$1$5 = Symbol.for(marker8$1$5);
12120
- var _a8$1$5;
12121
- var _b8$2;
12122
- var GatewayResponseError = class extends (_b8$2 = GatewayError, _a8$1$5 = symbol8$1$5, _b8$2) {
12123
- constructor({ message = "Invalid response from Gateway", statusCode = 502, response, validationError, cause } = {}) {
12124
- super({
12125
- message,
12126
- statusCode,
12127
- cause
12128
- });
12129
- this[_a8$1$5] = true;
12130
- this.name = name7$1$5;
12131
- this.type = "response_error";
12132
- this.response = response;
12133
- this.validationError = validationError;
12134
- }
12135
- static isInstance(error) {
12136
- return GatewayError.hasMarker(error) && symbol8$1$5 in error;
12137
- }
12138
- };
12139
- async function createGatewayErrorFromResponse({ response, statusCode, defaultMessage = "Gateway request failed", cause, authMethod }) {
12140
- const parseResult = await safeValidateTypes$2({
12141
- value: response,
12142
- schema: gatewayErrorResponseSchema
12143
- });
12144
- if (!parseResult.success) return new GatewayResponseError({
12145
- message: `Invalid error response format: ${defaultMessage}`,
12146
- statusCode,
12147
- response,
12148
- validationError: parseResult.error,
12149
- cause
12150
- });
12151
- const validatedResponse = parseResult.value;
12152
- const errorType = validatedResponse.error.type;
12153
- const message = validatedResponse.error.message;
12154
- switch (errorType) {
12155
- case "authentication_error": return GatewayAuthenticationError.createContextualError({
12156
- apiKeyProvided: authMethod === "api-key",
12157
- oidcTokenProvided: authMethod === "oidc",
12158
- statusCode,
12159
- cause
12160
- });
12161
- case "invalid_request_error": return new GatewayInvalidRequestError({
12162
- message,
12163
- statusCode,
12164
- cause
12165
- });
12166
- case "rate_limit_exceeded": return new GatewayRateLimitError({
12167
- message,
12168
- statusCode,
12169
- cause
12170
- });
12171
- case "model_not_found": {
12172
- const modelResult = await safeValidateTypes$2({
12173
- value: validatedResponse.error.param,
12174
- schema: modelNotFoundParamSchema
12175
- });
12176
- return new GatewayModelNotFoundError({
12177
- message,
12178
- statusCode,
12179
- modelId: modelResult.success ? modelResult.value.modelId : void 0,
12180
- cause
12181
- });
12182
- }
12183
- case "internal_server_error": return new GatewayInternalServerError({
12184
- message,
12185
- statusCode,
12186
- cause
12187
- });
12188
- case "forbidden": {
12189
- const ruleResult = await safeValidateTypes$2({
12190
- value: validatedResponse.error.param,
12191
- schema: forbiddenParamSchema
12192
- });
12193
- return new GatewayForbiddenError({
12194
- message,
12195
- statusCode,
12196
- cause,
12197
- ruleId: ruleResult.success ? ruleResult.value.ruleId : void 0
12198
- });
12199
- }
12200
- default: return new GatewayInternalServerError({
12201
- message,
12202
- statusCode,
12203
- cause
12204
- });
12205
- }
12206
- }
12207
- var gatewayErrorResponseSchema = lazyValidator(() => zodSchema$2(object$3({ error: object$3({
12208
- message: string(),
12209
- type: string().nullish(),
12210
- param: unknown().nullish(),
12211
- code: union([string(), number()]).nullish()
12212
- }) })));
12213
- function extractApiCallResponse(error) {
12214
- if (error.data !== void 0) return error.data;
12215
- if (error.responseBody != null) try {
12216
- return JSON.parse(error.responseBody);
12217
- } catch (e) {
12218
- return error.responseBody;
12219
- }
12220
- return {};
12221
- }
12222
- var name8$1$4 = "GatewayTimeoutError";
12223
- var marker9$1$4 = `vercel.ai.gateway.error.${name8$1$4}`;
12224
- var symbol9$1$4 = Symbol.for(marker9$1$4);
12225
- var _a9$1$4;
12226
- var _b9$2;
12227
- var GatewayTimeoutError = class _GatewayTimeoutError extends (_b9$2 = GatewayError, _a9$1$4 = symbol9$1$4, _b9$2) {
12228
- constructor({ message = "Request timed out", statusCode = 408, cause } = {}) {
12229
- super({
12230
- message,
12231
- statusCode,
12232
- cause
12233
- });
12234
- this[_a9$1$4] = true;
12235
- this.name = name8$1$4;
12236
- this.type = "timeout_error";
12237
- }
12238
- static isInstance(error) {
12239
- return GatewayError.hasMarker(error) && symbol9$1$4 in error;
12240
- }
12241
- /**
12242
- * Creates a helpful timeout error message with troubleshooting guidance
12243
- */
12244
- static createTimeoutError({ originalMessage, statusCode = 408, cause }) {
12245
- const message = `Gateway request timed out: ${originalMessage}
12246
-
12247
- This is a client-side timeout. To resolve this, increase your timeout configuration: https://vercel.com/docs/ai-gateway/capabilities/video-generation#extending-timeouts-for-node.js`;
12248
- return new _GatewayTimeoutError({
12249
- message,
12250
- statusCode,
12251
- cause
12252
- });
12253
- }
12254
- };
12255
- function isTimeoutError(error) {
12256
- if (!(error instanceof Error)) return false;
12257
- const errorCode = error.code;
12258
- if (typeof errorCode === "string") return [
12259
- "UND_ERR_HEADERS_TIMEOUT",
12260
- "UND_ERR_BODY_TIMEOUT",
12261
- "UND_ERR_CONNECT_TIMEOUT"
12262
- ].includes(errorCode);
12263
- return false;
12264
- }
12265
- async function asGatewayError(error, authMethod) {
12266
- var _a10;
12267
- if (GatewayError.isInstance(error)) return error;
12268
- if (isTimeoutError(error)) return GatewayTimeoutError.createTimeoutError({
12269
- originalMessage: error instanceof Error ? error.message : "Unknown error",
12270
- cause: error
12271
- });
12272
- if (APICallError$2.isInstance(error)) {
12273
- if (error.cause && isTimeoutError(error.cause)) return GatewayTimeoutError.createTimeoutError({
12274
- originalMessage: error.message,
12275
- cause: error
12276
- });
12277
- return await createGatewayErrorFromResponse({
12278
- response: extractApiCallResponse(error),
12279
- statusCode: (_a10 = error.statusCode) != null ? _a10 : 500,
12280
- defaultMessage: "Gateway request failed",
12281
- cause: error,
12282
- authMethod
12283
- });
12284
- }
12285
- return await createGatewayErrorFromResponse({
12286
- response: {},
12287
- statusCode: 500,
12288
- defaultMessage: error instanceof Error ? `Gateway request failed: ${error.message}` : "Unknown Gateway error",
12289
- cause: error,
12290
- authMethod
12291
- });
12292
- }
12293
- var GATEWAY_AUTH_METHOD_HEADER = "ai-gateway-auth-method";
12294
- async function parseAuthMethod(headers) {
12295
- const result = await safeValidateTypes$2({
12296
- value: headers[GATEWAY_AUTH_METHOD_HEADER],
12297
- schema: gatewayAuthMethodSchema
12298
- });
12299
- return result.success ? result.value : void 0;
12300
- }
12301
- var gatewayAuthMethodSchema = lazyValidator(() => zodSchema$2(union([literal("api-key"), literal("oidc")])));
12302
- var KNOWN_MODEL_TYPES = [
12303
- "embedding",
12304
- "image",
12305
- "language"
12306
- ];
12307
- var GatewayFetchMetadata = class {
12308
- constructor(config) {
12309
- this.config = config;
12310
- }
12311
- async getAvailableModels() {
12312
- try {
12313
- const { value } = await getFromApi({
12314
- url: `${this.config.baseURL}/config`,
12315
- headers: await resolve$1(this.config.headers()),
12316
- successfulResponseHandler: createJsonResponseHandler(gatewayAvailableModelsResponseSchema),
12317
- failedResponseHandler: createJsonErrorResponseHandler({
12318
- errorSchema: any(),
12319
- errorToMessage: (data) => data
12320
- }),
12321
- fetch: this.config.fetch
12322
- });
12323
- return value;
12324
- } catch (error) {
12325
- throw await asGatewayError(error);
12326
- }
12327
- }
12328
- async getCredits() {
12329
- try {
12330
- const { value } = await getFromApi({
12331
- url: `${new URL(this.config.baseURL).origin}/v1/credits`,
12332
- headers: await resolve$1(this.config.headers()),
12333
- successfulResponseHandler: createJsonResponseHandler(gatewayCreditsResponseSchema),
12334
- failedResponseHandler: createJsonErrorResponseHandler({
12335
- errorSchema: any(),
12336
- errorToMessage: (data) => data
12337
- }),
12338
- fetch: this.config.fetch
12339
- });
12340
- return value;
12341
- } catch (error) {
12342
- throw await asGatewayError(error);
12343
- }
12344
- }
12345
- };
12346
- var gatewayAvailableModelsResponseSchema = lazyValidator(() => zodSchema$2(object$3({ models: array$1(object$3({
12347
- id: string(),
12348
- name: string(),
12349
- description: string().nullish(),
12350
- pricing: object$3({
12351
- input: string(),
12352
- output: string(),
12353
- input_cache_read: string().nullish(),
12354
- input_cache_write: string().nullish()
12355
- }).transform(({ input, output, input_cache_read, input_cache_write }) => ({
12356
- input,
12357
- output,
12358
- ...input_cache_read ? { cachedInputTokens: input_cache_read } : {},
12359
- ...input_cache_write ? { cacheCreationInputTokens: input_cache_write } : {}
12360
- })).nullish(),
12361
- specification: object$3({
12362
- specificationVersion: literal("v2"),
12363
- provider: string(),
12364
- modelId: string()
12365
- }),
12366
- modelType: string().nullish()
12367
- })).transform((models) => models.filter((m) => m.modelType == null || KNOWN_MODEL_TYPES.includes(m.modelType))) })));
12368
- var gatewayCreditsResponseSchema = lazyValidator(() => zodSchema$2(object$3({
12369
- balance: string(),
12370
- total_used: string()
12371
- }).transform(({ balance, total_used }) => ({
12372
- balance,
12373
- totalUsed: total_used
12374
- }))));
12375
- var GatewaySpendReport = class {
12376
- constructor(config) {
12377
- this.config = config;
12378
- }
12379
- async getSpendReport(params) {
12380
- try {
12381
- const baseUrl = new URL(this.config.baseURL);
12382
- const searchParams = new URLSearchParams();
12383
- searchParams.set("start_date", params.startDate);
12384
- searchParams.set("end_date", params.endDate);
12385
- if (params.groupBy) searchParams.set("group_by", params.groupBy);
12386
- if (params.datePart) searchParams.set("date_part", params.datePart);
12387
- if (params.userId) searchParams.set("user_id", params.userId);
12388
- if (params.model) searchParams.set("model", params.model);
12389
- if (params.provider) searchParams.set("provider", params.provider);
12390
- if (params.credentialType) searchParams.set("credential_type", params.credentialType);
12391
- if (params.tags && params.tags.length > 0) searchParams.set("tags", params.tags.join(","));
12392
- const { value } = await getFromApi({
12393
- url: `${baseUrl.origin}/v1/report?${searchParams.toString()}`,
12394
- headers: await resolve$1(this.config.headers()),
12395
- successfulResponseHandler: createJsonResponseHandler(gatewaySpendReportResponseSchema),
12396
- failedResponseHandler: createJsonErrorResponseHandler({
12397
- errorSchema: any(),
12398
- errorToMessage: (data) => data
12399
- }),
12400
- fetch: this.config.fetch
12401
- });
12402
- return value;
12403
- } catch (error) {
12404
- throw await asGatewayError(error);
12405
- }
12406
- }
12407
- };
12408
- var gatewaySpendReportResponseSchema = lazySchema$1(() => zodSchema$2(object$3({ results: array$1(object$3({
12409
- day: string().optional(),
12410
- hour: string().optional(),
12411
- user: string().optional(),
12412
- model: string().optional(),
12413
- tag: string().optional(),
12414
- provider: string().optional(),
12415
- credential_type: _enum(["byok", "system"]).optional(),
12416
- total_cost: number(),
12417
- market_cost: number().optional(),
12418
- input_tokens: number().optional(),
12419
- output_tokens: number().optional(),
12420
- cached_input_tokens: number().optional(),
12421
- cache_creation_input_tokens: number().optional(),
12422
- reasoning_tokens: number().optional(),
12423
- request_count: number().optional()
12424
- }).transform(({ credential_type, total_cost, market_cost, input_tokens, output_tokens, cached_input_tokens, cache_creation_input_tokens, reasoning_tokens, request_count, ...rest }) => ({
12425
- ...rest,
12426
- ...credential_type !== void 0 ? { credentialType: credential_type } : {},
12427
- totalCost: total_cost,
12428
- ...market_cost !== void 0 ? { marketCost: market_cost } : {},
12429
- ...input_tokens !== void 0 ? { inputTokens: input_tokens } : {},
12430
- ...output_tokens !== void 0 ? { outputTokens: output_tokens } : {},
12431
- ...cached_input_tokens !== void 0 ? { cachedInputTokens: cached_input_tokens } : {},
12432
- ...cache_creation_input_tokens !== void 0 ? { cacheCreationInputTokens: cache_creation_input_tokens } : {},
12433
- ...reasoning_tokens !== void 0 ? { reasoningTokens: reasoning_tokens } : {},
12434
- ...request_count !== void 0 ? { requestCount: request_count } : {}
12435
- }))) })));
12436
- var GatewayGenerationInfoFetcher = class {
12437
- constructor(config) {
12438
- this.config = config;
12439
- }
12440
- async getGenerationInfo(params) {
12441
- try {
12442
- const { value } = await getFromApi({
12443
- url: `${new URL(this.config.baseURL).origin}/v1/generation?id=${encodeURIComponent(params.id)}`,
12444
- headers: await resolve$1(this.config.headers()),
12445
- successfulResponseHandler: createJsonResponseHandler(gatewayGenerationInfoResponseSchema),
12446
- failedResponseHandler: createJsonErrorResponseHandler({
12447
- errorSchema: any(),
12448
- errorToMessage: (data) => data
12449
- }),
12450
- fetch: this.config.fetch
12451
- });
12452
- return value;
12453
- } catch (error) {
12454
- throw await asGatewayError(error);
12455
- }
12456
- }
12457
- };
12458
- var gatewayGenerationInfoResponseSchema = lazySchema$1(() => zodSchema$2(object$3({ data: object$3({
12459
- id: string(),
12460
- total_cost: number(),
12461
- upstream_inference_cost: number(),
12462
- usage: number(),
12463
- created_at: string(),
12464
- model: string(),
12465
- is_byok: boolean(),
12466
- provider_name: string(),
12467
- streamed: boolean(),
12468
- finish_reason: string(),
12469
- latency: number(),
12470
- generation_time: number(),
12471
- native_tokens_prompt: number(),
12472
- native_tokens_completion: number(),
12473
- native_tokens_reasoning: number(),
12474
- native_tokens_cached: number(),
12475
- native_tokens_cache_creation: number(),
12476
- billable_web_search_calls: number()
12477
- }).transform(({ total_cost, upstream_inference_cost, created_at, is_byok, provider_name, finish_reason, generation_time, native_tokens_prompt, native_tokens_completion, native_tokens_reasoning, native_tokens_cached, native_tokens_cache_creation, billable_web_search_calls, ...rest }) => ({
12478
- ...rest,
12479
- totalCost: total_cost,
12480
- upstreamInferenceCost: upstream_inference_cost,
12481
- createdAt: created_at,
12482
- isByok: is_byok,
12483
- providerName: provider_name,
12484
- finishReason: finish_reason,
12485
- generationTime: generation_time,
12486
- promptTokens: native_tokens_prompt,
12487
- completionTokens: native_tokens_completion,
12488
- reasoningTokens: native_tokens_reasoning,
12489
- cachedTokens: native_tokens_cached,
12490
- cacheCreationTokens: native_tokens_cache_creation,
12491
- billableWebSearchCalls: billable_web_search_calls
12492
- })) }).transform(({ data }) => data)));
12493
- var GatewayLanguageModel = class {
12494
- constructor(modelId, config) {
12495
- this.modelId = modelId;
12496
- this.config = config;
12497
- this.specificationVersion = "v2";
12498
- this.supportedUrls = { "*/*": [/.*/] };
12499
- }
12500
- get provider() {
12501
- return this.config.provider;
12502
- }
12503
- async getArgs(options) {
12504
- const { abortSignal: _abortSignal, ...optionsWithoutSignal } = options;
12505
- return {
12506
- args: this.maybeEncodeFileParts(optionsWithoutSignal),
12507
- warnings: []
12508
- };
12509
- }
12510
- async doGenerate(options) {
12511
- const { args, warnings } = await this.getArgs(options);
12512
- const { abortSignal } = options;
12513
- const resolvedHeaders = await resolve$1(this.config.headers());
12514
- try {
12515
- const { responseHeaders, value: responseBody, rawValue: rawResponse } = await postJsonToApi({
12516
- url: this.getUrl(),
12517
- headers: combineHeaders(resolvedHeaders, options.headers, this.getModelConfigHeaders(this.modelId, false), await resolve$1(this.config.o11yHeaders)),
12518
- body: args,
12519
- successfulResponseHandler: createJsonResponseHandler(any()),
12520
- failedResponseHandler: createJsonErrorResponseHandler({
12521
- errorSchema: any(),
12522
- errorToMessage: (data) => data
12523
- }),
12524
- ...abortSignal && { abortSignal },
12525
- fetch: this.config.fetch
12526
- });
12527
- return {
12528
- ...responseBody,
12529
- request: { body: args },
12530
- response: {
12531
- headers: responseHeaders,
12532
- body: rawResponse
12533
- },
12534
- warnings
12535
- };
12536
- } catch (error) {
12537
- throw await asGatewayError(error, await parseAuthMethod(resolvedHeaders));
12538
- }
12539
- }
12540
- async doStream(options) {
12541
- const { args, warnings } = await this.getArgs(options);
12542
- const { abortSignal } = options;
12543
- const resolvedHeaders = await resolve$1(this.config.headers());
12544
- try {
12545
- const { value: response, responseHeaders } = await postJsonToApi({
12546
- url: this.getUrl(),
12547
- headers: combineHeaders(resolvedHeaders, options.headers, this.getModelConfigHeaders(this.modelId, true), await resolve$1(this.config.o11yHeaders)),
12548
- body: args,
12549
- successfulResponseHandler: createEventSourceResponseHandler(any()),
12550
- failedResponseHandler: createJsonErrorResponseHandler({
12551
- errorSchema: any(),
12552
- errorToMessage: (data) => data
12553
- }),
12554
- ...abortSignal && { abortSignal },
12555
- fetch: this.config.fetch
12556
- });
12557
- return {
12558
- stream: response.pipeThrough(new TransformStream({
12559
- start(controller) {
12560
- if (warnings.length > 0) controller.enqueue({
12561
- type: "stream-start",
12562
- warnings
12563
- });
12564
- },
12565
- transform(chunk, controller) {
12566
- if (chunk.success) {
12567
- const streamPart = chunk.value;
12568
- if (streamPart.type === "raw" && !options.includeRawChunks) return;
12569
- if (streamPart.type === "response-metadata" && streamPart.timestamp && typeof streamPart.timestamp === "string") streamPart.timestamp = new Date(streamPart.timestamp);
12570
- controller.enqueue(streamPart);
12571
- } else controller.error(chunk.error);
12572
- }
12573
- })),
12574
- request: { body: args },
12575
- response: { headers: responseHeaders }
12576
- };
12577
- } catch (error) {
12578
- throw await asGatewayError(error, await parseAuthMethod(resolvedHeaders));
12579
- }
12580
- }
12581
- isFilePart(part) {
12582
- return part && typeof part === "object" && "type" in part && part.type === "file";
12583
- }
12584
- /**
12585
- * Encodes file parts in the prompt to base64. Mutates the passed options
12586
- * instance directly to avoid copying the file data.
12587
- * @param options - The options to encode.
12588
- * @returns The options with the file parts encoded.
12589
- */
12590
- maybeEncodeFileParts(options) {
12591
- for (const message of options.prompt) for (const part of message.content) if (this.isFilePart(part)) {
12592
- const filePart = part;
12593
- if (filePart.data instanceof Uint8Array) {
12594
- const buffer = Uint8Array.from(filePart.data);
12595
- const base64Data = Buffer.from(buffer).toString("base64");
12596
- filePart.data = new URL(`data:${filePart.mediaType || "application/octet-stream"};base64,${base64Data}`);
12597
- }
12598
- }
12599
- return options;
12600
- }
12601
- getUrl() {
12602
- return `${this.config.baseURL}/language-model`;
12603
- }
12604
- getModelConfigHeaders(modelId, streaming) {
12605
- return {
12606
- "ai-language-model-specification-version": "2",
12607
- "ai-language-model-id": modelId,
12608
- "ai-language-model-streaming": String(streaming)
12609
- };
12610
- }
12611
- };
12612
- var GatewayEmbeddingModel = class {
12613
- constructor(modelId, config) {
12614
- this.modelId = modelId;
12615
- this.config = config;
12616
- this.specificationVersion = "v2";
12617
- this.maxEmbeddingsPerCall = 2048;
12618
- this.supportsParallelCalls = true;
12619
- }
12620
- get provider() {
12621
- return this.config.provider;
12622
- }
12623
- async doEmbed({ values, headers, abortSignal, providerOptions }) {
12624
- var _a10;
12625
- const resolvedHeaders = await resolve$1(this.config.headers());
12626
- try {
12627
- const { responseHeaders, value: responseBody, rawValue } = await postJsonToApi({
12628
- url: this.getUrl(),
12629
- headers: combineHeaders(resolvedHeaders, headers != null ? headers : {}, this.getModelConfigHeaders(), await resolve$1(this.config.o11yHeaders)),
12630
- body: {
12631
- input: values.length === 1 ? values[0] : values,
12632
- ...providerOptions ? { providerOptions } : {}
12633
- },
12634
- successfulResponseHandler: createJsonResponseHandler(gatewayEmbeddingResponseSchema),
12635
- failedResponseHandler: createJsonErrorResponseHandler({
12636
- errorSchema: any(),
12637
- errorToMessage: (data) => data
12638
- }),
12639
- ...abortSignal && { abortSignal },
12640
- fetch: this.config.fetch
12641
- });
12642
- return {
12643
- embeddings: responseBody.embeddings,
12644
- usage: (_a10 = responseBody.usage) != null ? _a10 : void 0,
12645
- providerMetadata: responseBody.providerMetadata,
12646
- response: {
12647
- headers: responseHeaders,
12648
- body: rawValue
12649
- }
12650
- };
12651
- } catch (error) {
12652
- throw await asGatewayError(error, await parseAuthMethod(resolvedHeaders));
12653
- }
12654
- }
12655
- getUrl() {
12656
- return `${this.config.baseURL}/embedding-model`;
12657
- }
12658
- getModelConfigHeaders() {
12659
- return {
12660
- "ai-embedding-model-specification-version": "2",
12661
- "ai-model-id": this.modelId
12662
- };
10778
+ case ZodFirstPartyTypeKind.ZodFunction:
10779
+ case ZodFirstPartyTypeKind.ZodVoid:
10780
+ case ZodFirstPartyTypeKind.ZodSymbol: return;
10781
+ default: return /* @__PURE__ */ ((_) => void 0)(typeName);
12663
10782
  }
12664
10783
  };
12665
- var gatewayEmbeddingResponseSchema = lazyValidator(() => zodSchema$2(object$3({
12666
- embeddings: array$1(array$1(number())),
12667
- usage: object$3({ tokens: number() }).nullish(),
12668
- providerMetadata: record(string(), record(string(), unknown())).optional()
12669
- })));
12670
- var GatewayImageModel = class {
12671
- constructor(modelId, config) {
12672
- this.modelId = modelId;
12673
- this.config = config;
12674
- this.specificationVersion = "v2";
12675
- this.maxImagesPerCall = Number.MAX_SAFE_INTEGER;
12676
- }
12677
- get provider() {
12678
- return this.config.provider;
10784
+ var getRelativePath$2 = (pathA, pathB) => {
10785
+ let i = 0;
10786
+ for (; i < pathA.length && i < pathB.length; i++) if (pathA[i] !== pathB[i]) break;
10787
+ return [(pathA.length - i).toString(), ...pathB.slice(i)].join("/");
10788
+ };
10789
+ function parseDef$2(def, refs, forceResolution = false) {
10790
+ var _a2;
10791
+ const seenItem = refs.seen.get(def);
10792
+ if (refs.override) {
10793
+ const overrideResult = (_a2 = refs.override) == null ? void 0 : _a2.call(refs, def, refs, seenItem, forceResolution);
10794
+ if (overrideResult !== ignoreOverride$2) return overrideResult;
12679
10795
  }
12680
- async doGenerate({ prompt, n, size, aspectRatio, seed, providerOptions, headers, abortSignal }) {
12681
- var _a10, _b10, _c, _d;
12682
- const resolvedHeaders = await resolve$1(this.config.headers());
12683
- try {
12684
- const { responseHeaders, value: responseBody, rawValue } = await postJsonToApi({
12685
- url: this.getUrl(),
12686
- headers: combineHeaders(resolvedHeaders, headers != null ? headers : {}, this.getModelConfigHeaders(), await resolve$1(this.config.o11yHeaders)),
12687
- body: {
12688
- prompt,
12689
- n,
12690
- ...size && { size },
12691
- ...aspectRatio && { aspectRatio },
12692
- ...seed && { seed },
12693
- ...providerOptions && { providerOptions }
12694
- },
12695
- successfulResponseHandler: createJsonResponseHandler(gatewayImageResponseSchema),
12696
- failedResponseHandler: createJsonErrorResponseHandler({
12697
- errorSchema: any(),
12698
- errorToMessage: (data) => data
12699
- }),
12700
- ...abortSignal && { abortSignal },
12701
- fetch: this.config.fetch
12702
- });
12703
- return {
12704
- images: responseBody.images,
12705
- warnings: (_a10 = responseBody.warnings) != null ? _a10 : [],
12706
- providerMetadata: responseBody.providerMetadata,
12707
- response: {
12708
- timestamp: /* @__PURE__ */ new Date(),
12709
- modelId: this.modelId,
12710
- headers: responseHeaders
12711
- },
12712
- ...responseBody.usage != null && { usage: {
12713
- inputTokens: (_b10 = responseBody.usage.inputTokens) != null ? _b10 : void 0,
12714
- outputTokens: (_c = responseBody.usage.outputTokens) != null ? _c : void 0,
12715
- totalTokens: (_d = responseBody.usage.totalTokens) != null ? _d : void 0
12716
- } }
12717
- };
12718
- } catch (error) {
12719
- throw await asGatewayError(error, await parseAuthMethod(resolvedHeaders));
12720
- }
10796
+ if (seenItem && !forceResolution) {
10797
+ const seenSchema = get$ref$2(seenItem, refs);
10798
+ if (seenSchema !== void 0) return seenSchema;
12721
10799
  }
12722
- getUrl() {
12723
- return `${this.config.baseURL}/image-model`;
10800
+ const newItem = {
10801
+ def,
10802
+ path: refs.currentPath,
10803
+ jsonSchema: void 0
10804
+ };
10805
+ refs.seen.set(def, newItem);
10806
+ const jsonSchemaOrGetter = selectParser$2(def, def.typeName, refs);
10807
+ const jsonSchema2 = typeof jsonSchemaOrGetter === "function" ? parseDef$2(jsonSchemaOrGetter(), refs) : jsonSchemaOrGetter;
10808
+ if (jsonSchema2) addMeta$2(def, refs, jsonSchema2);
10809
+ if (refs.postProcess) {
10810
+ const postProcessResult = refs.postProcess(jsonSchema2, def, refs);
10811
+ newItem.jsonSchema = jsonSchema2;
10812
+ return postProcessResult;
12724
10813
  }
12725
- getModelConfigHeaders() {
12726
- return {
12727
- "ai-image-model-specification-version": "2",
12728
- "ai-model-id": this.modelId
12729
- };
10814
+ newItem.jsonSchema = jsonSchema2;
10815
+ return jsonSchema2;
10816
+ }
10817
+ var get$ref$2 = (item, refs) => {
10818
+ switch (refs.$refStrategy) {
10819
+ case "root": return { $ref: item.path.join("/") };
10820
+ case "relative": return { $ref: getRelativePath$2(refs.currentPath, item.path) };
10821
+ case "none":
10822
+ case "seen":
10823
+ if (item.path.length < refs.currentPath.length && item.path.every((value, index) => refs.currentPath[index] === value)) {
10824
+ console.warn(`Recursive reference detected at ${refs.currentPath.join("/")}! Defaulting to any`);
10825
+ return parseAnyDef$2();
10826
+ }
10827
+ return refs.$refStrategy === "seen" ? parseAnyDef$2() : void 0;
12730
10828
  }
12731
10829
  };
12732
- var providerMetadataEntrySchema = object$3({ images: array$1(unknown()).optional() }).catchall(unknown());
12733
- var gatewayImageUsageSchema = object$3({
12734
- inputTokens: number().nullish(),
12735
- outputTokens: number().nullish(),
12736
- totalTokens: number().nullish()
12737
- });
12738
- var gatewayImageResponseSchema = object$3({
12739
- images: array$1(string()),
12740
- warnings: array$1(object$3({
12741
- type: literal("other"),
12742
- message: string()
12743
- })).optional(),
12744
- providerMetadata: record(string(), providerMetadataEntrySchema).optional(),
12745
- usage: gatewayImageUsageSchema.optional()
12746
- });
12747
- var parallelSearchToolFactory = createProviderDefinedToolFactoryWithOutputSchema({
12748
- id: "gateway.parallel_search",
12749
- name: "parallel_search",
12750
- inputSchema: lazySchema$1(() => zodSchema$2(object$3({
12751
- objective: string().describe("Natural-language description of the web research goal, including source or freshness guidance and broader context from the task. Maximum 5000 characters."),
12752
- search_queries: array$1(string()).optional().describe("Optional search queries to supplement the objective. Maximum 200 characters per query."),
12753
- mode: _enum(["one-shot", "agentic"]).optional().describe("Mode preset: \"one-shot\" for comprehensive results with longer excerpts (default), \"agentic\" for concise, token-efficient results for multi-step workflows."),
12754
- max_results: number().optional().describe("Maximum number of results to return (1-20). Defaults to 10 if not specified."),
12755
- source_policy: object$3({
12756
- include_domains: array$1(string()).optional().describe("List of domains to include in search results."),
12757
- exclude_domains: array$1(string()).optional().describe("List of domains to exclude from search results."),
12758
- after_date: string().optional().describe("Only include results published after this date (ISO 8601 format).")
12759
- }).optional().describe("Source policy for controlling which domains to include/exclude and freshness."),
12760
- excerpts: object$3({
12761
- max_chars_per_result: number().optional().describe("Maximum characters per result."),
12762
- max_chars_total: number().optional().describe("Maximum total characters across all results.")
12763
- }).optional().describe("Excerpt configuration for controlling result length."),
12764
- fetch_policy: object$3({ max_age_seconds: number().optional().describe("Maximum age in seconds for cached content. Set to 0 to always fetch fresh content.") }).optional().describe("Fetch policy for controlling content freshness.")
12765
- }))),
12766
- outputSchema: lazySchema$1(() => zodSchema$2(union([object$3({
12767
- searchId: string(),
12768
- results: array$1(object$3({
12769
- url: string(),
12770
- title: string(),
12771
- excerpt: string(),
12772
- publishDate: string().nullable().optional(),
12773
- relevanceScore: number().optional()
12774
- }))
12775
- }), object$3({
12776
- error: _enum([
12777
- "api_error",
12778
- "rate_limit",
12779
- "timeout",
12780
- "invalid_input",
12781
- "configuration_error",
12782
- "unknown"
12783
- ]),
12784
- statusCode: number().optional(),
12785
- message: string()
12786
- })])))
12787
- });
12788
- var parallelSearch = (config = {}) => parallelSearchToolFactory(config);
12789
- var perplexitySearchToolFactory = createProviderDefinedToolFactoryWithOutputSchema({
12790
- id: "gateway.perplexity_search",
12791
- name: "perplexity_search",
12792
- inputSchema: lazySchema$1(() => zodSchema$2(object$3({
12793
- query: union([string(), array$1(string())]).describe("Search query (string) or multiple queries (array of up to 5 strings). Multi-query searches return combined results from all queries."),
12794
- max_results: number().optional().describe("Maximum number of search results to return (1-20, default: 10)"),
12795
- max_tokens_per_page: number().optional().describe("Maximum number of tokens to extract per search result page (256-2048, default: 2048)"),
12796
- max_tokens: number().optional().describe("Maximum total tokens across all search results (default: 25000, max: 1000000)"),
12797
- country: string().optional().describe("Two-letter ISO 3166-1 alpha-2 country code for regional search results (e.g., 'US', 'GB', 'FR')"),
12798
- search_domain_filter: array$1(string()).optional().describe("List of domains to include or exclude from search results (max 20). To include: ['nature.com', 'science.org']. To exclude: ['-example.com', '-spam.net']"),
12799
- search_language_filter: array$1(string()).optional().describe("List of ISO 639-1 language codes to filter results (max 10, lowercase). Examples: ['en', 'fr', 'de']"),
12800
- search_after_date: string().optional().describe("Include only results published after this date. Format: 'MM/DD/YYYY' (e.g., '3/1/2025'). Cannot be used with search_recency_filter."),
12801
- search_before_date: string().optional().describe("Include only results published before this date. Format: 'MM/DD/YYYY' (e.g., '3/15/2025'). Cannot be used with search_recency_filter."),
12802
- last_updated_after_filter: string().optional().describe("Include only results last updated after this date. Format: 'MM/DD/YYYY' (e.g., '3/1/2025'). Cannot be used with search_recency_filter."),
12803
- last_updated_before_filter: string().optional().describe("Include only results last updated before this date. Format: 'MM/DD/YYYY' (e.g., '3/15/2025'). Cannot be used with search_recency_filter."),
12804
- search_recency_filter: _enum([
12805
- "day",
12806
- "week",
12807
- "month",
12808
- "year"
12809
- ]).optional().describe("Filter results by relative time period. Cannot be used with search_after_date or search_before_date.")
12810
- }))),
12811
- outputSchema: lazySchema$1(() => zodSchema$2(union([object$3({
12812
- results: array$1(object$3({
12813
- title: string(),
12814
- url: string(),
12815
- snippet: string(),
12816
- date: string().optional(),
12817
- lastUpdated: string().optional()
12818
- })),
12819
- id: string()
12820
- }), object$3({
12821
- error: _enum([
12822
- "api_error",
12823
- "rate_limit",
12824
- "timeout",
12825
- "invalid_input",
12826
- "unknown"
12827
- ]),
12828
- statusCode: number().optional(),
12829
- message: string()
12830
- })])))
12831
- });
12832
- var perplexitySearch = (config = {}) => perplexitySearchToolFactory(config);
12833
- var gatewayTools = {
12834
- /**
12835
- * Search the web using Parallel AI's Search API for LLM-optimized excerpts.
12836
- *
12837
- * Takes a natural language objective and returns relevant excerpts,
12838
- * replacing multiple keyword searches with a single call for broad
12839
- * or complex queries. Supports different search types for depth vs
12840
- * breadth tradeoffs.
12841
- */
12842
- parallelSearch,
12843
- /**
12844
- * Search the web using Perplexity's Search API for real-time information,
12845
- * news, research papers, and articles.
12846
- *
12847
- * Provides ranked search results with advanced filtering options including
12848
- * domain, language, date range, and recency filters.
12849
- */
12850
- perplexitySearch
12851
- };
12852
- async function getVercelRequestId() {
12853
- var _a10;
12854
- return (_a10 = getContext().headers) == null ? void 0 : _a10["x-vercel-id"];
12855
- }
12856
- var VERSION$2$1 = "2.0.125";
12857
- var AI_GATEWAY_PROTOCOL_VERSION = "0.0.1";
12858
- function createGatewayProvider(options = {}) {
12859
- var _a10, _b10;
12860
- let pendingMetadata = null;
12861
- let metadataCache = null;
12862
- const cacheRefreshMillis = (_a10 = options.metadataCacheRefreshMillis) != null ? _a10 : 1e3 * 60 * 5;
12863
- let lastFetchTime = 0;
12864
- const baseURL = (_b10 = withoutTrailingSlash(options.baseURL)) != null ? _b10 : "https://ai-gateway.vercel.sh/v1/ai";
12865
- const getHeaders = async () => {
12866
- const auth = await getGatewayAuthToken(options);
12867
- if (auth) return withUserAgentSuffix$1({
12868
- Authorization: `Bearer ${auth.token}`,
12869
- "ai-gateway-protocol-version": AI_GATEWAY_PROTOCOL_VERSION,
12870
- [GATEWAY_AUTH_METHOD_HEADER]: auth.authMethod,
12871
- ...options.headers
12872
- }, `ai-sdk/gateway/${VERSION$2$1}`);
12873
- throw GatewayAuthenticationError.createContextualError({
12874
- apiKeyProvided: false,
12875
- oidcTokenProvided: false,
12876
- statusCode: 401
12877
- });
10830
+ var addMeta$2 = (def, refs, jsonSchema2) => {
10831
+ if (def.description) jsonSchema2.description = def.description;
10832
+ return jsonSchema2;
10833
+ };
10834
+ var getRefs$2 = (options) => {
10835
+ const _options = getDefaultOptions$2(options);
10836
+ const currentPath = _options.name !== void 0 ? [
10837
+ ..._options.basePath,
10838
+ _options.definitionPath,
10839
+ _options.name
10840
+ ] : _options.basePath;
10841
+ return {
10842
+ ..._options,
10843
+ currentPath,
10844
+ propertyPath: void 0,
10845
+ seen: new Map(Object.entries(_options.definitions).map(([name2, def]) => [def._def, {
10846
+ def: def._def,
10847
+ path: [
10848
+ ..._options.basePath,
10849
+ _options.definitionPath,
10850
+ name2
10851
+ ],
10852
+ jsonSchema: void 0
10853
+ }]))
12878
10854
  };
12879
- const createO11yHeaders = () => {
12880
- const deploymentId = loadOptionalSetting({
12881
- settingValue: void 0,
12882
- environmentVariableName: "VERCEL_DEPLOYMENT_ID"
12883
- });
12884
- const environment = loadOptionalSetting({
12885
- settingValue: void 0,
12886
- environmentVariableName: "VERCEL_ENV"
12887
- });
12888
- const region = loadOptionalSetting({
12889
- settingValue: void 0,
12890
- environmentVariableName: "VERCEL_REGION"
12891
- });
12892
- const projectId = loadOptionalSetting({
12893
- settingValue: void 0,
12894
- environmentVariableName: "VERCEL_PROJECT_ID"
12895
- });
12896
- return async () => {
12897
- const requestId = await getVercelRequestId();
12898
- return {
12899
- ...deploymentId && { "ai-o11y-deployment-id": deploymentId },
12900
- ...environment && { "ai-o11y-environment": environment },
12901
- ...region && { "ai-o11y-region": region },
12902
- ...requestId && { "ai-o11y-request-id": requestId },
12903
- ...projectId && { "ai-o11y-project-id": projectId }
12904
- };
10855
+ };
10856
+ var zodToJsonSchema$1 = (schema, options) => {
10857
+ var _a2;
10858
+ const refs = getRefs$2(options);
10859
+ let definitions = typeof options === "object" && options.definitions ? Object.entries(options.definitions).reduce((acc, [name3, schema2]) => {
10860
+ var _a3;
10861
+ return {
10862
+ ...acc,
10863
+ [name3]: (_a3 = parseDef$2(schema2._def, {
10864
+ ...refs,
10865
+ currentPath: [
10866
+ ...refs.basePath,
10867
+ refs.definitionPath,
10868
+ name3
10869
+ ]
10870
+ }, true)) != null ? _a3 : parseAnyDef$2()
12905
10871
  };
12906
- };
12907
- const createLanguageModel = (modelId) => {
12908
- return new GatewayLanguageModel(modelId, {
12909
- provider: "gateway",
12910
- baseURL,
12911
- headers: getHeaders,
12912
- fetch: options.fetch,
12913
- o11yHeaders: createO11yHeaders()
12914
- });
12915
- };
12916
- const getAvailableModels = async () => {
12917
- var _a11, _b11, _c;
12918
- const now = (_c = (_b11 = (_a11 = options._internal) == null ? void 0 : _a11.currentDate) == null ? void 0 : _b11.call(_a11).getTime()) != null ? _c : Date.now();
12919
- if (!pendingMetadata || now - lastFetchTime > cacheRefreshMillis) {
12920
- lastFetchTime = now;
12921
- pendingMetadata = new GatewayFetchMetadata({
12922
- baseURL,
12923
- headers: getHeaders,
12924
- fetch: options.fetch
12925
- }).getAvailableModels().then((metadata) => {
12926
- metadataCache = metadata;
12927
- return metadata;
12928
- }).catch(async (error) => {
12929
- throw await asGatewayError(error, await parseAuthMethod(await getHeaders()));
12930
- });
10872
+ }, {}) : void 0;
10873
+ const name2 = typeof options === "string" ? options : (options == null ? void 0 : options.nameStrategy) === "title" ? void 0 : options == null ? void 0 : options.name;
10874
+ const main = (_a2 = parseDef$2(schema._def, name2 === void 0 ? refs : {
10875
+ ...refs,
10876
+ currentPath: [
10877
+ ...refs.basePath,
10878
+ refs.definitionPath,
10879
+ name2
10880
+ ]
10881
+ }, false)) != null ? _a2 : parseAnyDef$2();
10882
+ const title = typeof options === "object" && options.name !== void 0 && options.nameStrategy === "title" ? options.name : void 0;
10883
+ if (title !== void 0) main.title = title;
10884
+ const combined = name2 === void 0 ? definitions ? {
10885
+ ...main,
10886
+ [refs.definitionPath]: definitions
10887
+ } : main : {
10888
+ $ref: [
10889
+ ...refs.$refStrategy === "relative" ? [] : refs.basePath,
10890
+ refs.definitionPath,
10891
+ name2
10892
+ ].join("/"),
10893
+ [refs.definitionPath]: {
10894
+ ...definitions,
10895
+ [name2]: main
12931
10896
  }
12932
- return metadataCache ? Promise.resolve(metadataCache) : pendingMetadata;
12933
10897
  };
12934
- const getCredits = async () => {
12935
- return new GatewayFetchMetadata({
12936
- baseURL,
12937
- headers: getHeaders,
12938
- fetch: options.fetch
12939
- }).getCredits().catch(async (error) => {
12940
- throw await asGatewayError(error, await parseAuthMethod(await getHeaders()));
12941
- });
12942
- };
12943
- const getSpendReport = async (params) => {
12944
- return new GatewaySpendReport({
12945
- baseURL,
12946
- headers: getHeaders,
12947
- fetch: options.fetch
12948
- }).getSpendReport(params).catch(async (error) => {
12949
- throw await asGatewayError(error, await parseAuthMethod(await getHeaders()));
12950
- });
12951
- };
12952
- const getGenerationInfo = async (params) => {
12953
- return new GatewayGenerationInfoFetcher({
12954
- baseURL,
12955
- headers: getHeaders,
12956
- fetch: options.fetch
12957
- }).getGenerationInfo(params).catch(async (error) => {
12958
- throw await asGatewayError(error, await parseAuthMethod(await getHeaders()));
12959
- });
12960
- };
12961
- const provider = function(modelId) {
12962
- if (new.target) throw new Error("The Gateway Provider model function cannot be called with the new keyword.");
12963
- return createLanguageModel(modelId);
12964
- };
12965
- provider.getAvailableModels = getAvailableModels;
12966
- provider.getCredits = getCredits;
12967
- provider.getSpendReport = getSpendReport;
12968
- provider.getGenerationInfo = getGenerationInfo;
12969
- provider.imageModel = (modelId) => {
12970
- return new GatewayImageModel(modelId, {
12971
- provider: "gateway",
12972
- baseURL,
12973
- headers: getHeaders,
12974
- fetch: options.fetch,
12975
- o11yHeaders: createO11yHeaders()
12976
- });
12977
- };
12978
- provider.languageModel = createLanguageModel;
12979
- provider.textEmbeddingModel = (modelId) => {
12980
- return new GatewayEmbeddingModel(modelId, {
12981
- provider: "gateway",
12982
- baseURL,
12983
- headers: getHeaders,
12984
- fetch: options.fetch,
12985
- o11yHeaders: createO11yHeaders()
12986
- });
12987
- };
12988
- provider.tools = gatewayTools;
12989
- return provider;
10898
+ combined.$schema = "http://json-schema.org/draft-07/schema#";
10899
+ return combined;
10900
+ };
10901
+ var zod_to_json_schema_default = zodToJsonSchema$1;
10902
+ function zod3Schema$1(zodSchema2, options) {
10903
+ var _a2;
10904
+ const useReferences = (_a2 = options == null ? void 0 : options.useReferences) != null ? _a2 : false;
10905
+ return jsonSchema$2(() => zod_to_json_schema_default(zodSchema2, { $refStrategy: useReferences ? "root" : "none" }), { validate: async (value) => {
10906
+ const result = await zodSchema2.safeParseAsync(value);
10907
+ return result.success ? {
10908
+ success: true,
10909
+ value: result.data
10910
+ } : {
10911
+ success: false,
10912
+ error: result.error
10913
+ };
10914
+ } });
12990
10915
  }
12991
- createGatewayProvider();
12992
- async function getGatewayAuthToken(options) {
12993
- const apiKey = loadOptionalSetting({
12994
- settingValue: options.apiKey,
12995
- environmentVariableName: "AI_GATEWAY_API_KEY"
12996
- });
12997
- if (apiKey) return {
12998
- token: apiKey,
12999
- authMethod: "api-key"
13000
- };
13001
- try {
13002
- return {
13003
- token: await getVercelOidcToken(),
13004
- authMethod: "oidc"
10916
+ function zod4Schema$1(zodSchema2, options) {
10917
+ var _a2;
10918
+ const useReferences = (_a2 = options == null ? void 0 : options.useReferences) != null ? _a2 : false;
10919
+ return jsonSchema$2(() => addAdditionalPropertiesToJsonSchema$1(toJSONSchema(zodSchema2, {
10920
+ target: "draft-7",
10921
+ io: "input",
10922
+ reused: useReferences ? "ref" : "inline"
10923
+ })), { validate: async (value) => {
10924
+ const result = await safeParseAsync(zodSchema2, value);
10925
+ return result.success ? {
10926
+ success: true,
10927
+ value: result.data
10928
+ } : {
10929
+ success: false,
10930
+ error: result.error
13005
10931
  };
13006
- } catch (e) {
13007
- return null;
13008
- }
10932
+ } });
10933
+ }
10934
+ function isZod4Schema$1(zodSchema2) {
10935
+ return "_zod" in zodSchema2;
10936
+ }
10937
+ function zodSchema$2(zodSchema2, options) {
10938
+ if (isZod4Schema$1(zodSchema2)) return zod4Schema$1(zodSchema2, options);
10939
+ else return zod3Schema$1(zodSchema2, options);
10940
+ }
10941
+ function isSchema$2(value) {
10942
+ return typeof value === "object" && value !== null && schemaSymbol$2 in value && value[schemaSymbol$2] === true && "jsonSchema" in value && "validate" in value;
10943
+ }
10944
+ function asSchema$2(schema) {
10945
+ return schema == null ? jsonSchema$2({
10946
+ properties: {},
10947
+ additionalProperties: false
10948
+ }) : isSchema$2(schema) ? schema : typeof schema === "function" ? schema() : zodSchema$2(schema);
13009
10949
  }
10950
+ var { btoa: btoa$3, atob: atob$5 } = globalThis;
10951
+ //#endregion
10952
+ //#region ../_vendored/ai_v5/dist/index.js
13010
10953
  /** only globals that common to node and browsers are allowed */
13011
10954
  var _globalThis$1 = typeof globalThis === "object" ? globalThis : global;
13012
10955
  var VERSION$1$3 = "1.9.0";
@@ -13799,28 +11742,28 @@ var __export$2 = (target, all) => {
13799
11742
  enumerable: true
13800
11743
  });
13801
11744
  };
13802
- var name6$6 = "AI_NoObjectGeneratedError";
13803
- var marker6$6 = `vercel.ai.error.${name6$6}`;
13804
- var symbol6$6 = Symbol.for(marker6$6);
13805
- var _a6$6;
13806
- var NoObjectGeneratedError$2 = class extends AISDKError$4 {
11745
+ var name6$4 = "AI_NoObjectGeneratedError";
11746
+ var marker6$4 = `vercel.ai.error.${name6$4}`;
11747
+ var symbol6$4 = Symbol.for(marker6$4);
11748
+ var _a6$4;
11749
+ var NoObjectGeneratedError$2 = class extends AISDKError$2 {
13807
11750
  constructor({ message = "No object generated.", cause, text: text2, response, usage, finishReason }) {
13808
11751
  super({
13809
- name: name6$6,
11752
+ name: name6$4,
13810
11753
  message,
13811
11754
  cause
13812
11755
  });
13813
- this[_a6$6] = true;
11756
+ this[_a6$4] = true;
13814
11757
  this.text = text2;
13815
11758
  this.response = response;
13816
11759
  this.usage = usage;
13817
11760
  this.finishReason = finishReason;
13818
11761
  }
13819
11762
  static isInstance(error) {
13820
- return AISDKError$4.hasMarker(error, marker6$6);
11763
+ return AISDKError$2.hasMarker(error, marker6$4);
13821
11764
  }
13822
11765
  };
13823
- _a6$6 = symbol6$6;
11766
+ _a6$4 = symbol6$4;
13824
11767
  var dataContentSchema$2 = union([
13825
11768
  string(),
13826
11769
  _instanceof(Uint8Array),
@@ -13835,7 +11778,7 @@ var jsonValueSchema$2 = lazy(() => union([
13835
11778
  string(),
13836
11779
  number(),
13837
11780
  boolean(),
13838
- record(string(), jsonValueSchema$2),
11781
+ record(string(), jsonValueSchema$2.optional()),
13839
11782
  array$1(jsonValueSchema$2)
13840
11783
  ]));
13841
11784
  var providerMetadataSchema$2 = record(string(), record(string(), jsonValueSchema$2));
@@ -14214,10 +12157,12 @@ createIdGenerator$2({
14214
12157
  prefix: "aitxt",
14215
12158
  size: 24
14216
12159
  });
12160
+ new TextEncoder();
14217
12161
  createIdGenerator$2({
14218
12162
  prefix: "aiobj",
14219
12163
  size: 24
14220
12164
  });
12165
+ var { atob: atob$4 } = globalThis;
14221
12166
  createIdGenerator$2({
14222
12167
  prefix: "aiobj",
14223
12168
  size: 24
@@ -14329,9 +12274,9 @@ function customProvider$2({ languageModels, textEmbeddingModels, imageModels, tr
14329
12274
  }
14330
12275
  //#endregion
14331
12276
  //#region ../_vendored/ai_v4/dist/dist-Cm5DZgxA.js
14332
- var marker$5 = "vercel.ai.error";
14333
- var symbol$5 = Symbol.for(marker$5);
14334
- var _a$5;
12277
+ var marker$4 = "vercel.ai.error";
12278
+ var symbol$4 = Symbol.for(marker$4);
12279
+ var _a$4;
14335
12280
  var _AISDKError = class _AISDKError extends Error {
14336
12281
  /**
14337
12282
  * Creates an AI SDK Error.
@@ -14343,7 +12288,7 @@ var _AISDKError = class _AISDKError extends Error {
14343
12288
  */
14344
12289
  constructor({ name: name14, message, cause }) {
14345
12290
  super(message);
14346
- this[_a$5] = true;
12291
+ this[_a$4] = true;
14347
12292
  this.name = name14;
14348
12293
  this.cause = cause;
14349
12294
  }
@@ -14353,96 +12298,96 @@ var _AISDKError = class _AISDKError extends Error {
14353
12298
  * @returns {boolean} True if the error is an AI SDK Error, false otherwise.
14354
12299
  */
14355
12300
  static isInstance(error) {
14356
- return _AISDKError.hasMarker(error, marker$5);
12301
+ return _AISDKError.hasMarker(error, marker$4);
14357
12302
  }
14358
12303
  static hasMarker(error, marker15) {
14359
12304
  const markerSymbol = Symbol.for(marker15);
14360
12305
  return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
14361
12306
  }
14362
12307
  };
14363
- _a$5 = symbol$5;
14364
- var AISDKError$2 = _AISDKError;
14365
- function getErrorMessage$1(error) {
12308
+ _a$4 = symbol$4;
12309
+ var AISDKError$1 = _AISDKError;
12310
+ function getErrorMessage(error) {
14366
12311
  if (error == null) return "unknown error";
14367
12312
  if (typeof error === "string") return error;
14368
12313
  if (error instanceof Error) return error.message;
14369
12314
  return JSON.stringify(error);
14370
12315
  }
14371
- var name3$4 = "AI_InvalidArgumentError";
14372
- var marker4$4 = `vercel.ai.error.${name3$4}`;
14373
- var symbol4$4 = Symbol.for(marker4$4);
14374
- var _a4$4;
14375
- var InvalidArgumentError$2 = class extends AISDKError$2 {
12316
+ var name3$3 = "AI_InvalidArgumentError";
12317
+ var marker4$3 = `vercel.ai.error.${name3$3}`;
12318
+ var symbol4$3 = Symbol.for(marker4$3);
12319
+ var _a4$3;
12320
+ var InvalidArgumentError$1 = class extends AISDKError$1 {
14376
12321
  constructor({ message, cause, argument }) {
14377
12322
  super({
14378
- name: name3$4,
12323
+ name: name3$3,
14379
12324
  message,
14380
12325
  cause
14381
12326
  });
14382
- this[_a4$4] = true;
12327
+ this[_a4$3] = true;
14383
12328
  this.argument = argument;
14384
12329
  }
14385
12330
  static isInstance(error) {
14386
- return AISDKError$2.hasMarker(error, marker4$4);
12331
+ return AISDKError$1.hasMarker(error, marker4$3);
14387
12332
  }
14388
12333
  };
14389
- _a4$4 = symbol4$4;
14390
- var name6$4 = "AI_JSONParseError";
14391
- var marker7$4 = `vercel.ai.error.${name6$4}`;
14392
- var symbol7$4 = Symbol.for(marker7$4);
14393
- var _a7$4;
14394
- var JSONParseError$2 = class extends AISDKError$2 {
12334
+ _a4$3 = symbol4$3;
12335
+ var name6$3 = "AI_JSONParseError";
12336
+ var marker7$3 = `vercel.ai.error.${name6$3}`;
12337
+ var symbol7$3 = Symbol.for(marker7$3);
12338
+ var _a7$3;
12339
+ var JSONParseError$1 = class extends AISDKError$1 {
14395
12340
  constructor({ text, cause }) {
14396
12341
  super({
14397
- name: name6$4,
12342
+ name: name6$3,
14398
12343
  message: `JSON parsing failed: Text: ${text}.
14399
- Error message: ${getErrorMessage$1(cause)}`,
12344
+ Error message: ${getErrorMessage(cause)}`,
14400
12345
  cause
14401
12346
  });
14402
- this[_a7$4] = true;
12347
+ this[_a7$3] = true;
14403
12348
  this.text = text;
14404
12349
  }
14405
12350
  static isInstance(error) {
14406
- return AISDKError$2.hasMarker(error, marker7$4);
12351
+ return AISDKError$1.hasMarker(error, marker7$3);
14407
12352
  }
14408
12353
  };
14409
- _a7$4 = symbol7$4;
14410
- var name10$4 = "AI_NoSuchModelError";
14411
- var marker11$4 = `vercel.ai.error.${name10$4}`;
14412
- var symbol11$4 = Symbol.for(marker11$4);
14413
- var _a11$4;
14414
- var NoSuchModelError$1 = class extends AISDKError$2 {
14415
- constructor({ errorName = name10$4, modelId, modelType, message = `No such ${modelType}: ${modelId}` }) {
12354
+ _a7$3 = symbol7$3;
12355
+ var name10$3 = "AI_NoSuchModelError";
12356
+ var marker11$3 = `vercel.ai.error.${name10$3}`;
12357
+ var symbol11$3 = Symbol.for(marker11$3);
12358
+ var _a11$3;
12359
+ var NoSuchModelError$1 = class extends AISDKError$1 {
12360
+ constructor({ errorName = name10$3, modelId, modelType, message = `No such ${modelType}: ${modelId}` }) {
14416
12361
  super({
14417
12362
  name: errorName,
14418
12363
  message
14419
12364
  });
14420
- this[_a11$4] = true;
12365
+ this[_a11$3] = true;
14421
12366
  this.modelId = modelId;
14422
12367
  this.modelType = modelType;
14423
12368
  }
14424
12369
  static isInstance(error) {
14425
- return AISDKError$2.hasMarker(error, marker11$4);
12370
+ return AISDKError$1.hasMarker(error, marker11$3);
14426
12371
  }
14427
12372
  };
14428
- _a11$4 = symbol11$4;
14429
- var name12$4 = "AI_TypeValidationError";
14430
- var marker13$4 = `vercel.ai.error.${name12$4}`;
14431
- var symbol13$4 = Symbol.for(marker13$4);
14432
- var _a13$4;
14433
- var _TypeValidationError = class _TypeValidationError extends AISDKError$2 {
12373
+ _a11$3 = symbol11$3;
12374
+ var name12$3 = "AI_TypeValidationError";
12375
+ var marker13$3 = `vercel.ai.error.${name12$3}`;
12376
+ var symbol13$3 = Symbol.for(marker13$3);
12377
+ var _a13$3;
12378
+ var _TypeValidationError = class _TypeValidationError extends AISDKError$1 {
14434
12379
  constructor({ value, cause }) {
14435
12380
  super({
14436
- name: name12$4,
12381
+ name: name12$3,
14437
12382
  message: `Type validation failed: Value: ${JSON.stringify(value)}.
14438
- Error message: ${getErrorMessage$1(cause)}`,
12383
+ Error message: ${getErrorMessage(cause)}`,
14439
12384
  cause
14440
12385
  });
14441
- this[_a13$4] = true;
12386
+ this[_a13$3] = true;
14442
12387
  this.value = value;
14443
12388
  }
14444
12389
  static isInstance(error) {
14445
- return AISDKError$2.hasMarker(error, marker13$4);
12390
+ return AISDKError$1.hasMarker(error, marker13$3);
14446
12391
  }
14447
12392
  /**
14448
12393
  * Wraps an error into a TypeValidationError.
@@ -14461,8 +12406,8 @@ Error message: ${getErrorMessage$1(cause)}`,
14461
12406
  });
14462
12407
  }
14463
12408
  };
14464
- _a13$4 = symbol13$4;
14465
- var TypeValidationError$2 = _TypeValidationError;
12409
+ _a13$3 = symbol13$3;
12410
+ var TypeValidationError$1 = _TypeValidationError;
14466
12411
  //#endregion
14467
12412
  //#region ../_vendored/ai_v4/dist/index.js
14468
12413
  var __create = Object.create;
@@ -14599,7 +12544,7 @@ function convertAsyncIteratorToReadableStream(iterator) {
14599
12544
  var createIdGenerator$1 = ({ prefix, size: defaultSize = 16, alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", separator = "-" } = {}) => {
14600
12545
  const generator = customAlphabet(alphabet, defaultSize);
14601
12546
  if (prefix == null) return generator;
14602
- if (alphabet.includes(separator)) throw new InvalidArgumentError$2({
12547
+ if (alphabet.includes(separator)) throw new InvalidArgumentError$1({
14603
12548
  argument: "separator",
14604
12549
  message: `The separator "${separator}" must not be part of the alphabet "${alphabet}".`
14605
12550
  });
@@ -14642,7 +12587,7 @@ function safeValidateTypes$1({ value, schema }) {
14642
12587
  if (result.success) return result;
14643
12588
  return {
14644
12589
  success: false,
14645
- error: TypeValidationError$2.wrap({
12590
+ error: TypeValidationError$1.wrap({
14646
12591
  value,
14647
12592
  cause: result.error
14648
12593
  })
@@ -14650,7 +12595,7 @@ function safeValidateTypes$1({ value, schema }) {
14650
12595
  } catch (error) {
14651
12596
  return {
14652
12597
  success: false,
14653
- error: TypeValidationError$2.wrap({
12598
+ error: TypeValidationError$1.wrap({
14654
12599
  value,
14655
12600
  cause: error
14656
12601
  })
@@ -14676,14 +12621,14 @@ function safeParseJSON$1({ text, schema }) {
14676
12621
  } catch (error) {
14677
12622
  return {
14678
12623
  success: false,
14679
- error: JSONParseError$2.isInstance(error) ? error : new JSONParseError$2({
12624
+ error: JSONParseError$1.isInstance(error) ? error : new JSONParseError$1({
14680
12625
  text,
14681
12626
  cause: error
14682
12627
  })
14683
12628
  };
14684
12629
  }
14685
12630
  }
14686
- var { btoa: btoa$2, atob: atob$2 } = globalThis;
12631
+ var { btoa: btoa$2, atob: atob$3 } = globalThis;
14687
12632
  const ignoreOverride$1 = Symbol("Let zodToJsonSchema decide on which parser to use");
14688
12633
  const defaultOptions$1 = {
14689
12634
  name: void 0,
@@ -17067,28 +15012,28 @@ function prepareResponseHeaders(headers, { contentType, dataStreamVersion }) {
17067
15012
  if (dataStreamVersion !== void 0) responseHeaders.set("X-Vercel-AI-Data-Stream", dataStreamVersion);
17068
15013
  return responseHeaders;
17069
15014
  }
17070
- var name4$3 = "AI_NoObjectGeneratedError";
17071
- var marker4$3 = `vercel.ai.error.${name4$3}`;
17072
- var symbol4$3 = Symbol.for(marker4$3);
17073
- var _a4$3;
17074
- var NoObjectGeneratedError$1 = class extends AISDKError$2 {
15015
+ var name4$2 = "AI_NoObjectGeneratedError";
15016
+ var marker4$2 = `vercel.ai.error.${name4$2}`;
15017
+ var symbol4$2 = Symbol.for(marker4$2);
15018
+ var _a4$2;
15019
+ var NoObjectGeneratedError$1 = class extends AISDKError$1 {
17075
15020
  constructor({ message = "No object generated.", cause, text: text2, response, usage, finishReason }) {
17076
15021
  super({
17077
- name: name4$3,
15022
+ name: name4$2,
17078
15023
  message,
17079
15024
  cause
17080
15025
  });
17081
- this[_a4$3] = true;
15026
+ this[_a4$2] = true;
17082
15027
  this.text = text2;
17083
15028
  this.response = response;
17084
15029
  this.usage = usage;
17085
15030
  this.finishReason = finishReason;
17086
15031
  }
17087
15032
  static isInstance(error) {
17088
- return AISDKError$2.hasMarker(error, marker4$3);
15033
+ return AISDKError$1.hasMarker(error, marker4$2);
17089
15034
  }
17090
15035
  };
17091
- _a4$3 = symbol4$3;
15036
+ _a4$2 = symbol4$2;
17092
15037
  var dataContentSchema$1 = union([
17093
15038
  string(),
17094
15039
  _instanceof(Uint8Array),
@@ -17618,12 +15563,12 @@ function trimStartOfStream() {
17618
15563
  };
17619
15564
  }
17620
15565
  //#endregion
17621
- //#region ../_vendored/ai_v6/dist/dist-B5Rt0qDx.js
17622
- var marker$2 = "vercel.ai.error";
17623
- var symbol$2 = Symbol.for(marker$2);
17624
- var _a$2;
17625
- var _b$2;
17626
- var AISDKError$1 = class _AISDKError extends (_b$2 = Error, _a$2 = symbol$2, _b$2) {
15566
+ //#region ../_vendored/ai_v6/dist/dist-CMCOMbq-.js
15567
+ var marker$1 = "vercel.ai.error";
15568
+ var symbol$1 = Symbol.for(marker$1);
15569
+ var _a$1;
15570
+ var _b$1;
15571
+ var AISDKError = class _AISDKError extends (_b$1 = Error, _a$1 = symbol$1, _b$1) {
17627
15572
  /**
17628
15573
  * Creates an AI SDK Error.
17629
15574
  *
@@ -17634,7 +15579,7 @@ var AISDKError$1 = class _AISDKError extends (_b$2 = Error, _a$2 = symbol$2, _b$
17634
15579
  */
17635
15580
  constructor({ name: name14, message, cause }) {
17636
15581
  super(message);
17637
- this[_a$2] = true;
15582
+ this[_a$1] = true;
17638
15583
  this.name = name14;
17639
15584
  this.cause = cause;
17640
15585
  }
@@ -17644,22 +15589,22 @@ var AISDKError$1 = class _AISDKError extends (_b$2 = Error, _a$2 = symbol$2, _b$
17644
15589
  * @returns {boolean} True if the error is an AI SDK Error, false otherwise.
17645
15590
  */
17646
15591
  static isInstance(error) {
17647
- return _AISDKError.hasMarker(error, marker$2);
15592
+ return _AISDKError.hasMarker(error, marker$1);
17648
15593
  }
17649
15594
  static hasMarker(error, marker15) {
17650
15595
  const markerSymbol = Symbol.for(marker15);
17651
15596
  return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
17652
15597
  }
17653
15598
  };
17654
- var name$2 = "AI_APICallError";
17655
- var marker2$1 = `vercel.ai.error.${name$2}`;
15599
+ var name$1 = "AI_APICallError";
15600
+ var marker2$1 = `vercel.ai.error.${name$1}`;
17656
15601
  var symbol2$1 = Symbol.for(marker2$1);
17657
15602
  var _a2$1;
17658
- var _b2$1;
17659
- (class extends (_b2$1 = AISDKError$1, _a2$1 = symbol2$1, _b2$1) {
15603
+ var _b2;
15604
+ (class extends (_b2 = AISDKError, _a2$1 = symbol2$1, _b2) {
17660
15605
  constructor({ message, url, requestBodyValues, statusCode, responseHeaders, responseBody, cause, isRetryable = statusCode != null && (statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500), data }) {
17661
15606
  super({
17662
- name: name$2,
15607
+ name: name$1,
17663
15608
  message,
17664
15609
  cause
17665
15610
  });
@@ -17673,15 +15618,15 @@ var _b2$1;
17673
15618
  this.data = data;
17674
15619
  }
17675
15620
  static isInstance(error) {
17676
- return AISDKError$1.hasMarker(error, marker2$1);
15621
+ return AISDKError.hasMarker(error, marker2$1);
17677
15622
  }
17678
15623
  });
17679
15624
  var name2$1 = "AI_EmptyResponseBodyError";
17680
15625
  var marker3$1 = `vercel.ai.error.${name2$1}`;
17681
15626
  var symbol3$1 = Symbol.for(marker3$1);
17682
15627
  var _a3$1;
17683
- var _b3$1;
17684
- (class extends (_b3$1 = AISDKError$1, _a3$1 = symbol3$1, _b3$1) {
15628
+ var _b3;
15629
+ (class extends (_b3 = AISDKError, _a3$1 = symbol3$1, _b3) {
17685
15630
  constructor({ message = "Empty response body" } = {}) {
17686
15631
  super({
17687
15632
  name: name2$1,
@@ -17690,10 +15635,10 @@ var _b3$1;
17690
15635
  this[_a3$1] = true;
17691
15636
  }
17692
15637
  static isInstance(error) {
17693
- return AISDKError$1.hasMarker(error, marker3$1);
15638
+ return AISDKError.hasMarker(error, marker3$1);
17694
15639
  }
17695
15640
  });
17696
- function getErrorMessage$2(error) {
15641
+ function getErrorMessage$1(error) {
17697
15642
  if (error == null) return "unknown error";
17698
15643
  if (typeof error === "string") return error;
17699
15644
  if (error instanceof Error) return error.message;
@@ -17703,8 +15648,8 @@ var name3$1 = "AI_InvalidArgumentError";
17703
15648
  var marker4$1 = `vercel.ai.error.${name3$1}`;
17704
15649
  var symbol4$1 = Symbol.for(marker4$1);
17705
15650
  var _a4$1;
17706
- var _b4$1;
17707
- var InvalidArgumentError$1 = class extends (_b4$1 = AISDKError$1, _a4$1 = symbol4$1, _b4$1) {
15651
+ var _b4;
15652
+ var InvalidArgumentError = class extends (_b4 = AISDKError, _a4$1 = symbol4$1, _b4) {
17708
15653
  constructor({ message, cause, argument }) {
17709
15654
  super({
17710
15655
  name: name3$1,
@@ -17715,15 +15660,15 @@ var InvalidArgumentError$1 = class extends (_b4$1 = AISDKError$1, _a4$1 = symbol
17715
15660
  this.argument = argument;
17716
15661
  }
17717
15662
  static isInstance(error) {
17718
- return AISDKError$1.hasMarker(error, marker4$1);
15663
+ return AISDKError.hasMarker(error, marker4$1);
17719
15664
  }
17720
15665
  };
17721
15666
  var name4$1 = "AI_InvalidPromptError";
17722
15667
  var marker5$1 = `vercel.ai.error.${name4$1}`;
17723
15668
  var symbol5$1 = Symbol.for(marker5$1);
17724
15669
  var _a5$1;
17725
- var _b5$1;
17726
- (class extends (_b5$1 = AISDKError$1, _a5$1 = symbol5$1, _b5$1) {
15670
+ var _b5;
15671
+ (class extends (_b5 = AISDKError, _a5$1 = symbol5$1, _b5) {
17727
15672
  constructor({ prompt, message, cause }) {
17728
15673
  super({
17729
15674
  name: name4$1,
@@ -17734,15 +15679,15 @@ var _b5$1;
17734
15679
  this.prompt = prompt;
17735
15680
  }
17736
15681
  static isInstance(error) {
17737
- return AISDKError$1.hasMarker(error, marker5$1);
15682
+ return AISDKError.hasMarker(error, marker5$1);
17738
15683
  }
17739
15684
  });
17740
15685
  var name5$1 = "AI_InvalidResponseDataError";
17741
15686
  var marker6$1 = `vercel.ai.error.${name5$1}`;
17742
15687
  var symbol6$1 = Symbol.for(marker6$1);
17743
15688
  var _a6$1;
17744
- var _b6$1;
17745
- (class extends (_b6$1 = AISDKError$1, _a6$1 = symbol6$1, _b6$1) {
15689
+ var _b6;
15690
+ (class extends (_b6 = AISDKError, _a6$1 = symbol6$1, _b6) {
17746
15691
  constructor({ data, message = `Invalid response data: ${JSON.stringify(data)}.` }) {
17747
15692
  super({
17748
15693
  name: name5$1,
@@ -17752,35 +15697,35 @@ var _b6$1;
17752
15697
  this.data = data;
17753
15698
  }
17754
15699
  static isInstance(error) {
17755
- return AISDKError$1.hasMarker(error, marker6$1);
15700
+ return AISDKError.hasMarker(error, marker6$1);
17756
15701
  }
17757
15702
  });
17758
15703
  var name6$1 = "AI_JSONParseError";
17759
15704
  var marker7$1 = `vercel.ai.error.${name6$1}`;
17760
15705
  var symbol7$1 = Symbol.for(marker7$1);
17761
15706
  var _a7$1;
17762
- var _b7$1;
17763
- var JSONParseError$1 = class extends (_b7$1 = AISDKError$1, _a7$1 = symbol7$1, _b7$1) {
15707
+ var _b7;
15708
+ var JSONParseError = class extends (_b7 = AISDKError, _a7$1 = symbol7$1, _b7) {
17764
15709
  constructor({ text, cause }) {
17765
15710
  super({
17766
15711
  name: name6$1,
17767
15712
  message: `JSON parsing failed: Text: ${text}.
17768
- Error message: ${getErrorMessage$2(cause)}`,
15713
+ Error message: ${getErrorMessage$1(cause)}`,
17769
15714
  cause
17770
15715
  });
17771
15716
  this[_a7$1] = true;
17772
15717
  this.text = text;
17773
15718
  }
17774
15719
  static isInstance(error) {
17775
- return AISDKError$1.hasMarker(error, marker7$1);
15720
+ return AISDKError.hasMarker(error, marker7$1);
17776
15721
  }
17777
15722
  };
17778
15723
  var name7$1 = "AI_LoadAPIKeyError";
17779
15724
  var marker8$1 = `vercel.ai.error.${name7$1}`;
17780
15725
  var symbol8$1 = Symbol.for(marker8$1);
17781
15726
  var _a8$1;
17782
- var _b8$1;
17783
- (class extends (_b8$1 = AISDKError$1, _a8$1 = symbol8$1, _b8$1) {
15727
+ var _b8;
15728
+ (class extends (_b8 = AISDKError, _a8$1 = symbol8$1, _b8) {
17784
15729
  constructor({ message }) {
17785
15730
  super({
17786
15731
  name: name7$1,
@@ -17789,15 +15734,15 @@ var _b8$1;
17789
15734
  this[_a8$1] = true;
17790
15735
  }
17791
15736
  static isInstance(error) {
17792
- return AISDKError$1.hasMarker(error, marker8$1);
15737
+ return AISDKError.hasMarker(error, marker8$1);
17793
15738
  }
17794
15739
  });
17795
15740
  var name8$1 = "AI_LoadSettingError";
17796
15741
  var marker9$1 = `vercel.ai.error.${name8$1}`;
17797
15742
  var symbol9$1 = Symbol.for(marker9$1);
17798
15743
  var _a9$1;
17799
- var _b9$1;
17800
- (class extends (_b9$1 = AISDKError$1, _a9$1 = symbol9$1, _b9$1) {
15744
+ var _b9;
15745
+ (class extends (_b9 = AISDKError, _a9$1 = symbol9$1, _b9) {
17801
15746
  constructor({ message }) {
17802
15747
  super({
17803
15748
  name: name8$1,
@@ -17806,15 +15751,15 @@ var _b9$1;
17806
15751
  this[_a9$1] = true;
17807
15752
  }
17808
15753
  static isInstance(error) {
17809
- return AISDKError$1.hasMarker(error, marker9$1);
15754
+ return AISDKError.hasMarker(error, marker9$1);
17810
15755
  }
17811
15756
  });
17812
15757
  var name9$1 = "AI_NoContentGeneratedError";
17813
15758
  var marker10$1 = `vercel.ai.error.${name9$1}`;
17814
15759
  var symbol10$1 = Symbol.for(marker10$1);
17815
15760
  var _a10$1;
17816
- var _b10$1;
17817
- (class extends (_b10$1 = AISDKError$1, _a10$1 = symbol10$1, _b10$1) {
15761
+ var _b10;
15762
+ (class extends (_b10 = AISDKError, _a10$1 = symbol10$1, _b10) {
17818
15763
  constructor({ message = "No content generated." } = {}) {
17819
15764
  super({
17820
15765
  name: name9$1,
@@ -17823,15 +15768,15 @@ var _b10$1;
17823
15768
  this[_a10$1] = true;
17824
15769
  }
17825
15770
  static isInstance(error) {
17826
- return AISDKError$1.hasMarker(error, marker10$1);
15771
+ return AISDKError.hasMarker(error, marker10$1);
17827
15772
  }
17828
15773
  });
17829
15774
  var name10$1 = "AI_NoSuchModelError";
17830
15775
  var marker11$1 = `vercel.ai.error.${name10$1}`;
17831
15776
  var symbol11$1 = Symbol.for(marker11$1);
17832
15777
  var _a11$1;
17833
- var _b11$1;
17834
- (class extends (_b11$1 = AISDKError$1, _a11$1 = symbol11$1, _b11$1) {
15778
+ var _b11;
15779
+ var NoSuchModelError = class extends (_b11 = AISDKError, _a11$1 = symbol11$1, _b11) {
17835
15780
  constructor({ errorName = name10$1, modelId, modelType, message = `No such ${modelType}: ${modelId}` }) {
17836
15781
  super({
17837
15782
  name: errorName,
@@ -17842,15 +15787,15 @@ var _b11$1;
17842
15787
  this.modelType = modelType;
17843
15788
  }
17844
15789
  static isInstance(error) {
17845
- return AISDKError$1.hasMarker(error, marker11$1);
15790
+ return AISDKError.hasMarker(error, marker11$1);
17846
15791
  }
17847
- });
15792
+ };
17848
15793
  var name11$1 = "AI_TooManyEmbeddingValuesForCallError";
17849
15794
  var marker12$1 = `vercel.ai.error.${name11$1}`;
17850
15795
  var symbol12$1 = Symbol.for(marker12$1);
17851
15796
  var _a12$1;
17852
- var _b12$1;
17853
- (class extends (_b12$1 = AISDKError$1, _a12$1 = symbol12$1, _b12$1) {
15797
+ var _b12;
15798
+ (class extends (_b12 = AISDKError, _a12$1 = symbol12$1, _b12) {
17854
15799
  constructor(options) {
17855
15800
  super({
17856
15801
  name: name11$1,
@@ -17863,15 +15808,15 @@ var _b12$1;
17863
15808
  this.values = options.values;
17864
15809
  }
17865
15810
  static isInstance(error) {
17866
- return AISDKError$1.hasMarker(error, marker12$1);
15811
+ return AISDKError.hasMarker(error, marker12$1);
17867
15812
  }
17868
15813
  });
17869
15814
  var name12$1 = "AI_TypeValidationError";
17870
15815
  var marker13$1 = `vercel.ai.error.${name12$1}`;
17871
15816
  var symbol13$1 = Symbol.for(marker13$1);
17872
15817
  var _a13$1;
17873
- var _b13$1;
17874
- var TypeValidationError$1 = class _TypeValidationError extends (_b13$1 = AISDKError$1, _a13$1 = symbol13$1, _b13$1) {
15818
+ var _b13;
15819
+ var TypeValidationError = class _TypeValidationError extends (_b13 = AISDKError, _a13$1 = symbol13$1, _b13) {
17875
15820
  constructor({ value, cause, context }) {
17876
15821
  let contextPrefix = "Type validation failed";
17877
15822
  if (context == null ? void 0 : context.field) contextPrefix += ` for ${context.field}`;
@@ -17886,7 +15831,7 @@ var TypeValidationError$1 = class _TypeValidationError extends (_b13$1 = AISDKEr
17886
15831
  super({
17887
15832
  name: name12$1,
17888
15833
  message: `${contextPrefix}: Value: ${JSON.stringify(value)}.
17889
- Error message: ${getErrorMessage$2(cause)}`,
15834
+ Error message: ${getErrorMessage$1(cause)}`,
17890
15835
  cause
17891
15836
  });
17892
15837
  this[_a13$1] = true;
@@ -17894,7 +15839,7 @@ Error message: ${getErrorMessage$2(cause)}`,
17894
15839
  this.context = context;
17895
15840
  }
17896
15841
  static isInstance(error) {
17897
- return AISDKError$1.hasMarker(error, marker13$1);
15842
+ return AISDKError.hasMarker(error, marker13$1);
17898
15843
  }
17899
15844
  /**
17900
15845
  * Wraps an error into a TypeValidationError.
@@ -17921,8 +15866,8 @@ var name13$1 = "AI_UnsupportedFunctionalityError";
17921
15866
  var marker14$1 = `vercel.ai.error.${name13$1}`;
17922
15867
  var symbol14$1 = Symbol.for(marker14$1);
17923
15868
  var _a14$1;
17924
- var _b14$1;
17925
- (class extends (_b14$1 = AISDKError$1, _a14$1 = symbol14$1, _b14$1) {
15869
+ var _b14;
15870
+ (class extends (_b14 = AISDKError, _a14$1 = symbol14$1, _b14) {
17926
15871
  constructor({ functionality, message = `'${functionality}' functionality not supported.` }) {
17927
15872
  super({
17928
15873
  name: name13$1,
@@ -17932,39 +15877,32 @@ var _b14$1;
17932
15877
  this.functionality = functionality;
17933
15878
  }
17934
15879
  static isInstance(error) {
17935
- return AISDKError$1.hasMarker(error, marker14$1);
15880
+ return AISDKError.hasMarker(error, marker14$1);
17936
15881
  }
17937
15882
  });
17938
15883
  TransformStream;
17939
- var { btoa: btoa$1, atob: atob$1 } = globalThis;
17940
- var name$1 = "AI_DownloadError";
17941
- var marker$1 = `vercel.ai.error.${name$1}`;
17942
- var symbol$1 = Symbol.for(marker$1);
17943
- var _a$1;
17944
- var _b$1;
17945
- (class extends (_b$1 = AISDKError$1, _a$1 = symbol$1, _b$1) {
15884
+ var { btoa: btoa$1, atob: atob$2 } = globalThis;
15885
+ var name$2 = "AI_DownloadError";
15886
+ var marker$2 = `vercel.ai.error.${name$2}`;
15887
+ var symbol$2 = Symbol.for(marker$2);
15888
+ var _a$2;
15889
+ var _b;
15890
+ (class extends (_b = AISDKError, _a$2 = symbol$2, _b) {
17946
15891
  constructor({ url, statusCode, statusText, cause, message = cause == null ? `Failed to download ${url}: ${statusCode} ${statusText}` : `Failed to download ${url}: ${cause}` }) {
17947
15892
  super({
17948
- name: name$1,
15893
+ name: name$2,
17949
15894
  message,
17950
15895
  cause
17951
15896
  });
17952
- this[_a$1] = true;
15897
+ this[_a$2] = true;
17953
15898
  this.url = url;
17954
15899
  this.statusCode = statusCode;
17955
15900
  this.statusText = statusText;
17956
15901
  }
17957
15902
  static isInstance(error) {
17958
- return AISDKError$1.hasMarker(error, marker$1);
15903
+ return AISDKError.hasMarker(error, marker$2);
17959
15904
  }
17960
15905
  });
17961
- var initialGlobalFetch = globalThis.fetch;
17962
- isNodeDefaultFetch(initialGlobalFetch);
17963
- function isNodeDefaultFetch(fetch) {
17964
- if (typeof fetch !== "function") return false;
17965
- const source = Function.prototype.toString.call(fetch);
17966
- return source.includes("internal/deps/undici") || source.includes("lazy loading of undici");
17967
- }
17968
15906
  function getCurrentModulePath() {
17969
15907
  const originalPrepareStackTrace = Error.prepareStackTrace;
17970
15908
  try {
@@ -17987,7 +15925,7 @@ var createIdGenerator = ({ prefix, size = 16, alphabet = "0123456789ABCDEFGHIJKL
17987
15925
  return chars.join("");
17988
15926
  };
17989
15927
  if (prefix == null) return generator;
17990
- if (alphabet.includes(separator)) throw new InvalidArgumentError$1({
15928
+ if (alphabet.includes(separator)) throw new InvalidArgumentError({
17991
15929
  argument: "separator",
17992
15930
  message: `The separator "${separator}" must not be part of the alphabet "${alphabet}".`
17993
15931
  });
@@ -18968,7 +16906,7 @@ function standardSchema(standardSchema2) {
18968
16906
  value: result.value
18969
16907
  } : {
18970
16908
  success: false,
18971
- error: new TypeValidationError$1({
16909
+ error: new TypeValidationError({
18972
16910
  value,
18973
16911
  cause: result.issues
18974
16912
  })
@@ -19033,7 +16971,7 @@ async function safeValidateTypes({ value, schema, context }) {
19033
16971
  };
19034
16972
  return {
19035
16973
  success: false,
19036
- error: TypeValidationError$1.wrap({
16974
+ error: TypeValidationError.wrap({
19037
16975
  value,
19038
16976
  cause: result.error,
19039
16977
  context
@@ -19043,7 +16981,7 @@ async function safeValidateTypes({ value, schema, context }) {
19043
16981
  } catch (error) {
19044
16982
  return {
19045
16983
  success: false,
19046
- error: TypeValidationError$1.wrap({
16984
+ error: TypeValidationError.wrap({
19047
16985
  value,
19048
16986
  cause: error,
19049
16987
  context
@@ -19067,7 +17005,7 @@ async function safeParseJSON({ text, schema }) {
19067
17005
  } catch (error) {
19068
17006
  return {
19069
17007
  success: false,
19070
- error: JSONParseError$1.isInstance(error) ? error : new JSONParseError$1({
17008
+ error: JSONParseError.isInstance(error) ? error : new JSONParseError({
19071
17009
  text,
19072
17010
  cause: error
19073
17011
  }),
@@ -19080,322 +17018,6 @@ async function resolve(value) {
19080
17018
  return value;
19081
17019
  }
19082
17020
  new TextDecoder();
19083
- var marker$3 = "vercel.ai.error";
19084
- var symbol$3 = Symbol.for(marker$3);
19085
- var _a$3;
19086
- var _b;
19087
- var AISDKError = class _AISDKError extends (_b = Error, _a$3 = symbol$3, _b) {
19088
- /**
19089
- * Creates an AI SDK Error.
19090
- *
19091
- * @param {Object} params - The parameters for creating the error.
19092
- * @param {string} params.name - The name of the error.
19093
- * @param {string} params.message - The error message.
19094
- * @param {unknown} [params.cause] - The underlying cause of the error.
19095
- */
19096
- constructor({ name: name14, message, cause }) {
19097
- super(message);
19098
- this[_a$3] = true;
19099
- this.name = name14;
19100
- this.cause = cause;
19101
- }
19102
- /**
19103
- * Checks if the given error is an AI SDK Error.
19104
- * @param {unknown} error - The error to check.
19105
- * @returns {boolean} True if the error is an AI SDK Error, false otherwise.
19106
- */
19107
- static isInstance(error) {
19108
- return _AISDKError.hasMarker(error, marker$3);
19109
- }
19110
- static hasMarker(error, marker15) {
19111
- const markerSymbol = Symbol.for(marker15);
19112
- return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
19113
- }
19114
- };
19115
- var name$3 = "AI_APICallError";
19116
- var marker2$2 = `vercel.ai.error.${name$3}`;
19117
- var symbol2$2 = Symbol.for(marker2$2);
19118
- var _a2$2;
19119
- var _b2;
19120
- (class extends (_b2 = AISDKError, _a2$2 = symbol2$2, _b2) {
19121
- constructor({ message, url, requestBodyValues, statusCode, responseHeaders, responseBody, cause, isRetryable = statusCode != null && (statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500), data }) {
19122
- super({
19123
- name: name$3,
19124
- message,
19125
- cause
19126
- });
19127
- this[_a2$2] = true;
19128
- this.url = url;
19129
- this.requestBodyValues = requestBodyValues;
19130
- this.statusCode = statusCode;
19131
- this.responseHeaders = responseHeaders;
19132
- this.responseBody = responseBody;
19133
- this.isRetryable = isRetryable;
19134
- this.data = data;
19135
- }
19136
- static isInstance(error) {
19137
- return AISDKError.hasMarker(error, marker2$2);
19138
- }
19139
- });
19140
- var name2$2 = "AI_EmptyResponseBodyError";
19141
- var marker3$2 = `vercel.ai.error.${name2$2}`;
19142
- var symbol3$2 = Symbol.for(marker3$2);
19143
- var _a3$2;
19144
- var _b3;
19145
- (class extends (_b3 = AISDKError, _a3$2 = symbol3$2, _b3) {
19146
- constructor({ message = "Empty response body" } = {}) {
19147
- super({
19148
- name: name2$2,
19149
- message
19150
- });
19151
- this[_a3$2] = true;
19152
- }
19153
- static isInstance(error) {
19154
- return AISDKError.hasMarker(error, marker3$2);
19155
- }
19156
- });
19157
- function getErrorMessage(error) {
19158
- if (error == null) return "unknown error";
19159
- if (typeof error === "string") return error;
19160
- if (error instanceof Error) return error.message;
19161
- return JSON.stringify(error);
19162
- }
19163
- var name3$2 = "AI_InvalidArgumentError";
19164
- var marker4$2 = `vercel.ai.error.${name3$2}`;
19165
- var symbol4$2 = Symbol.for(marker4$2);
19166
- var _a4$2;
19167
- var _b4;
19168
- (class extends (_b4 = AISDKError, _a4$2 = symbol4$2, _b4) {
19169
- constructor({ message, cause, argument }) {
19170
- super({
19171
- name: name3$2,
19172
- message,
19173
- cause
19174
- });
19175
- this[_a4$2] = true;
19176
- this.argument = argument;
19177
- }
19178
- static isInstance(error) {
19179
- return AISDKError.hasMarker(error, marker4$2);
19180
- }
19181
- });
19182
- var name4$2 = "AI_InvalidPromptError";
19183
- var marker5$2 = `vercel.ai.error.${name4$2}`;
19184
- var symbol5$2 = Symbol.for(marker5$2);
19185
- var _a5$2;
19186
- var _b5;
19187
- (class extends (_b5 = AISDKError, _a5$2 = symbol5$2, _b5) {
19188
- constructor({ prompt, message, cause }) {
19189
- super({
19190
- name: name4$2,
19191
- message: `Invalid prompt: ${message}`,
19192
- cause
19193
- });
19194
- this[_a5$2] = true;
19195
- this.prompt = prompt;
19196
- }
19197
- static isInstance(error) {
19198
- return AISDKError.hasMarker(error, marker5$2);
19199
- }
19200
- });
19201
- var name5$2 = "AI_InvalidResponseDataError";
19202
- var marker6$2 = `vercel.ai.error.${name5$2}`;
19203
- var symbol6$2 = Symbol.for(marker6$2);
19204
- var _a6$2;
19205
- var _b6;
19206
- (class extends (_b6 = AISDKError, _a6$2 = symbol6$2, _b6) {
19207
- constructor({ data, message = `Invalid response data: ${JSON.stringify(data)}.` }) {
19208
- super({
19209
- name: name5$2,
19210
- message
19211
- });
19212
- this[_a6$2] = true;
19213
- this.data = data;
19214
- }
19215
- static isInstance(error) {
19216
- return AISDKError.hasMarker(error, marker6$2);
19217
- }
19218
- });
19219
- var name6$2 = "AI_JSONParseError";
19220
- var marker7$2 = `vercel.ai.error.${name6$2}`;
19221
- var symbol7$2 = Symbol.for(marker7$2);
19222
- var _a7$2;
19223
- var _b7;
19224
- (class extends (_b7 = AISDKError, _a7$2 = symbol7$2, _b7) {
19225
- constructor({ text, cause }) {
19226
- super({
19227
- name: name6$2,
19228
- message: `JSON parsing failed: Text: ${text}.
19229
- Error message: ${getErrorMessage(cause)}`,
19230
- cause
19231
- });
19232
- this[_a7$2] = true;
19233
- this.text = text;
19234
- }
19235
- static isInstance(error) {
19236
- return AISDKError.hasMarker(error, marker7$2);
19237
- }
19238
- });
19239
- var name7$2 = "AI_LoadAPIKeyError";
19240
- var marker8$2 = `vercel.ai.error.${name7$2}`;
19241
- var symbol8$2 = Symbol.for(marker8$2);
19242
- var _a8$2;
19243
- var _b8;
19244
- (class extends (_b8 = AISDKError, _a8$2 = symbol8$2, _b8) {
19245
- constructor({ message }) {
19246
- super({
19247
- name: name7$2,
19248
- message
19249
- });
19250
- this[_a8$2] = true;
19251
- }
19252
- static isInstance(error) {
19253
- return AISDKError.hasMarker(error, marker8$2);
19254
- }
19255
- });
19256
- var name8$2 = "AI_LoadSettingError";
19257
- var marker9$2 = `vercel.ai.error.${name8$2}`;
19258
- var symbol9$2 = Symbol.for(marker9$2);
19259
- var _a9$2;
19260
- var _b9;
19261
- (class extends (_b9 = AISDKError, _a9$2 = symbol9$2, _b9) {
19262
- constructor({ message }) {
19263
- super({
19264
- name: name8$2,
19265
- message
19266
- });
19267
- this[_a9$2] = true;
19268
- }
19269
- static isInstance(error) {
19270
- return AISDKError.hasMarker(error, marker9$2);
19271
- }
19272
- });
19273
- var name9$2 = "AI_NoContentGeneratedError";
19274
- var marker10$2 = `vercel.ai.error.${name9$2}`;
19275
- var symbol10$2 = Symbol.for(marker10$2);
19276
- var _a10$2;
19277
- var _b10;
19278
- (class extends (_b10 = AISDKError, _a10$2 = symbol10$2, _b10) {
19279
- constructor({ message = "No content generated." } = {}) {
19280
- super({
19281
- name: name9$2,
19282
- message
19283
- });
19284
- this[_a10$2] = true;
19285
- }
19286
- static isInstance(error) {
19287
- return AISDKError.hasMarker(error, marker10$2);
19288
- }
19289
- });
19290
- var name10$2 = "AI_NoSuchModelError";
19291
- var marker11$2 = `vercel.ai.error.${name10$2}`;
19292
- var symbol11$2 = Symbol.for(marker11$2);
19293
- var _a11$2;
19294
- var _b11;
19295
- var NoSuchModelError = class extends (_b11 = AISDKError, _a11$2 = symbol11$2, _b11) {
19296
- constructor({ errorName = name10$2, modelId, modelType, message = `No such ${modelType}: ${modelId}` }) {
19297
- super({
19298
- name: errorName,
19299
- message
19300
- });
19301
- this[_a11$2] = true;
19302
- this.modelId = modelId;
19303
- this.modelType = modelType;
19304
- }
19305
- static isInstance(error) {
19306
- return AISDKError.hasMarker(error, marker11$2);
19307
- }
19308
- };
19309
- var name11$2 = "AI_TooManyEmbeddingValuesForCallError";
19310
- var marker12$2 = `vercel.ai.error.${name11$2}`;
19311
- var symbol12$2 = Symbol.for(marker12$2);
19312
- var _a12$2;
19313
- var _b12;
19314
- (class extends (_b12 = AISDKError, _a12$2 = symbol12$2, _b12) {
19315
- constructor(options) {
19316
- super({
19317
- name: name11$2,
19318
- message: `Too many values for a single embedding call. The ${options.provider} model "${options.modelId}" can only embed up to ${options.maxEmbeddingsPerCall} values per call, but ${options.values.length} values were provided.`
19319
- });
19320
- this[_a12$2] = true;
19321
- this.provider = options.provider;
19322
- this.modelId = options.modelId;
19323
- this.maxEmbeddingsPerCall = options.maxEmbeddingsPerCall;
19324
- this.values = options.values;
19325
- }
19326
- static isInstance(error) {
19327
- return AISDKError.hasMarker(error, marker12$2);
19328
- }
19329
- });
19330
- var name12$2 = "AI_TypeValidationError";
19331
- var marker13$2 = `vercel.ai.error.${name12$2}`;
19332
- var symbol13$2 = Symbol.for(marker13$2);
19333
- var _a13$2;
19334
- var _b13;
19335
- var TypeValidationError = class _TypeValidationError extends (_b13 = AISDKError, _a13$2 = symbol13$2, _b13) {
19336
- constructor({ value, cause, context }) {
19337
- let contextPrefix = "Type validation failed";
19338
- if (context == null ? void 0 : context.field) contextPrefix += ` for ${context.field}`;
19339
- if ((context == null ? void 0 : context.entityName) || (context == null ? void 0 : context.entityId)) {
19340
- contextPrefix += " (";
19341
- const parts = [];
19342
- if (context.entityName) parts.push(context.entityName);
19343
- if (context.entityId) parts.push(`id: "${context.entityId}"`);
19344
- contextPrefix += parts.join(", ");
19345
- contextPrefix += ")";
19346
- }
19347
- super({
19348
- name: name12$2,
19349
- message: `${contextPrefix}: Value: ${JSON.stringify(value)}.
19350
- Error message: ${getErrorMessage(cause)}`,
19351
- cause
19352
- });
19353
- this[_a13$2] = true;
19354
- this.value = value;
19355
- this.context = context;
19356
- }
19357
- static isInstance(error) {
19358
- return AISDKError.hasMarker(error, marker13$2);
19359
- }
19360
- /**
19361
- * Wraps an error into a TypeValidationError.
19362
- * If the cause is already a TypeValidationError with the same value and context, it returns the cause.
19363
- * Otherwise, it creates a new TypeValidationError.
19364
- *
19365
- * @param {Object} params - The parameters for wrapping the error.
19366
- * @param {unknown} params.value - The value that failed validation.
19367
- * @param {unknown} params.cause - The original error or cause of the validation failure.
19368
- * @param {TypeValidationContext} params.context - Optional context about what is being validated.
19369
- * @returns {TypeValidationError} A TypeValidationError instance.
19370
- */
19371
- static wrap({ value, cause, context }) {
19372
- var _a15, _b15, _c;
19373
- if (_TypeValidationError.isInstance(cause) && cause.value === value && ((_a15 = cause.context) == null ? void 0 : _a15.field) === (context == null ? void 0 : context.field) && ((_b15 = cause.context) == null ? void 0 : _b15.entityName) === (context == null ? void 0 : context.entityName) && ((_c = cause.context) == null ? void 0 : _c.entityId) === (context == null ? void 0 : context.entityId)) return cause;
19374
- return new _TypeValidationError({
19375
- value,
19376
- cause,
19377
- context
19378
- });
19379
- }
19380
- };
19381
- var name13$2 = "AI_UnsupportedFunctionalityError";
19382
- var marker14$2 = `vercel.ai.error.${name13$2}`;
19383
- var symbol14$2 = Symbol.for(marker14$2);
19384
- var _a14$2;
19385
- var _b14;
19386
- (class extends (_b14 = AISDKError, _a14$2 = symbol14$2, _b14) {
19387
- constructor({ functionality, message = `'${functionality}' functionality not supported.` }) {
19388
- super({
19389
- name: name13$2,
19390
- message
19391
- });
19392
- this[_a14$2] = true;
19393
- this.functionality = functionality;
19394
- }
19395
- static isInstance(error) {
19396
- return AISDKError.hasMarker(error, marker14$2);
19397
- }
19398
- });
19399
17021
  //#endregion
19400
17022
  //#region ../_vendored/ai_v6/dist/index.js
19401
17023
  const VERSION$1 = "1.9.1";
@@ -20184,8 +17806,8 @@ const API_NAME = "trace";
20184
17806
  }).getInstance();
20185
17807
  var __defProp = Object.defineProperty;
20186
17808
  var __export = (target, all) => {
20187
- for (var name22 in all) __defProp(target, name22, {
20188
- get: all[name22],
17809
+ for (var name23 in all) __defProp(target, name23, {
17810
+ get: all[name23],
20189
17811
  enumerable: true
20190
17812
  });
20191
17813
  };
@@ -20343,7 +17965,8 @@ function convertV2UsageToV3(usage) {
20343
17965
  total: usage.outputTokens,
20344
17966
  text: void 0,
20345
17967
  reasoning: usage.reasoningTokens
20346
- }
17968
+ },
17969
+ raw: usage.totalTokens == null ? void 0 : { totalTokens: usage.totalTokens }
20347
17970
  };
20348
17971
  }
20349
17972
  function asSpeechModelV3(model) {
@@ -20373,8 +17996,8 @@ var dataContentSchema = union([
20373
17996
  _instanceof(Uint8Array),
20374
17997
  _instanceof(ArrayBuffer),
20375
17998
  custom((value) => {
20376
- var _a22, _b;
20377
- return (_b = (_a22 = globalThis.Buffer) == null ? void 0 : _a22.isBuffer(value)) != null ? _b : false;
17999
+ var _a23, _b;
18000
+ return (_b = (_a23 = globalThis.Buffer) == null ? void 0 : _a23.isBuffer(value)) != null ? _b : false;
20378
18001
  }, { message: "Must be a Buffer" })
20379
18002
  ]);
20380
18003
  var jsonValueSchema = lazy(() => union([
@@ -20466,6 +18089,7 @@ var outputSchema = discriminatedUnion("type", [
20466
18089
  object$3({
20467
18090
  type: literal("file-url"),
20468
18091
  url: string(),
18092
+ mediaType: string().optional(),
20469
18093
  providerOptions: providerMetadataSchema.optional()
20470
18094
  }),
20471
18095
  object$3({
@@ -20506,7 +18130,9 @@ var toolResultPartSchema = object$3({
20506
18130
  var toolApprovalRequestSchema = object$3({
20507
18131
  type: literal("tool-approval-request"),
20508
18132
  approvalId: string(),
20509
- toolCallId: string()
18133
+ toolCallId: string(),
18134
+ signature: string().optional(),
18135
+ inputSchemaInput: unknown().optional()
20510
18136
  });
20511
18137
  var toolApprovalResponseSchema = object$3({
20512
18138
  type: literal("tool-approval-response"),
@@ -20849,14 +18475,14 @@ var text = () => ({
20849
18475
  },
20850
18476
  createElementStreamTransform() {}
20851
18477
  });
20852
- var object = ({ schema: inputSchema, name: name22, description }) => {
18478
+ var object = ({ schema: inputSchema, name: name23, description }) => {
20853
18479
  const schema = asSchema(inputSchema);
20854
18480
  return {
20855
18481
  name: "object",
20856
18482
  responseFormat: resolve(schema.jsonSchema).then((jsonSchema2) => ({
20857
18483
  type: "json",
20858
18484
  schema: jsonSchema2,
20859
- ...name22 != null && { name: name22 },
18485
+ ...name23 != null && { name: name23 },
20860
18486
  ...description != null && { description }
20861
18487
  })),
20862
18488
  async parseCompleteOutput({ text: text2 }, context2) {
@@ -20895,7 +18521,7 @@ var object = ({ schema: inputSchema, name: name22, description }) => {
20895
18521
  createElementStreamTransform() {}
20896
18522
  };
20897
18523
  };
20898
- var array = ({ element: inputElementSchema, name: name22, description }) => {
18524
+ var array = ({ element: inputElementSchema, name: name23, description }) => {
20899
18525
  const elementSchema = asSchema(inputElementSchema);
20900
18526
  return {
20901
18527
  name: "array",
@@ -20913,7 +18539,7 @@ var array = ({ element: inputElementSchema, name: name22, description }) => {
20913
18539
  required: ["elements"],
20914
18540
  additionalProperties: false
20915
18541
  },
20916
- ...name22 != null && { name: name22 },
18542
+ ...name23 != null && { name: name23 },
20917
18543
  ...description != null && { description }
20918
18544
  };
20919
18545
  }),
@@ -20987,7 +18613,7 @@ var array = ({ element: inputElementSchema, name: name22, description }) => {
20987
18613
  }
20988
18614
  };
20989
18615
  };
20990
- var choice = ({ options: choiceOptions, name: name22, description }) => {
18616
+ var choice = ({ options: choiceOptions, name: name23, description }) => {
20991
18617
  return {
20992
18618
  name: "choice",
20993
18619
  responseFormat: Promise.resolve({
@@ -21002,7 +18628,7 @@ var choice = ({ options: choiceOptions, name: name22, description }) => {
21002
18628
  required: ["result"],
21003
18629
  additionalProperties: false
21004
18630
  },
21005
- ...name22 != null && { name: name22 },
18631
+ ...name23 != null && { name: name23 },
21006
18632
  ...description != null && { description }
21007
18633
  }),
21008
18634
  async parseCompleteOutput({ text: text2 }, context2) {
@@ -21047,12 +18673,12 @@ var choice = ({ options: choiceOptions, name: name22, description }) => {
21047
18673
  createElementStreamTransform() {}
21048
18674
  };
21049
18675
  };
21050
- var json = ({ name: name22, description } = {}) => {
18676
+ var json = ({ name: name23, description } = {}) => {
21051
18677
  return {
21052
18678
  name: "json",
21053
18679
  responseFormat: Promise.resolve({
21054
18680
  type: "json",
21055
- ...name22 != null && { name: name22 },
18681
+ ...name23 != null && { name: name23 },
21056
18682
  ...description != null && { description }
21057
18683
  }),
21058
18684
  async parseCompleteOutput({ text: text2 }, context2) {
@@ -21090,10 +18716,12 @@ createIdGenerator({
21090
18716
  size: 24
21091
18717
  });
21092
18718
  record(string(), jsonValueSchema.optional());
18719
+ new TextEncoder();
21093
18720
  createIdGenerator({
21094
18721
  prefix: "aiobj",
21095
18722
  size: 24
21096
18723
  });
18724
+ var { atob: atob$1 } = globalThis;
21097
18725
  createIdGenerator({
21098
18726
  prefix: "aiobj",
21099
18727
  size: 24
@@ -21295,6 +18923,9 @@ function loadTokenizerFromDir(modelDir, maxLength) {
21295
18923
  }
21296
18924
  return tokenizer;
21297
18925
  }
18926
+ function assertValidBatchSize(batchSize) {
18927
+ if (!Number.isSafeInteger(batchSize) || batchSize <= 0) throw new RangeError(`batchSize must be a positive safe integer, received ${String(batchSize)}`);
18928
+ }
21298
18929
  var FlagEmbedding = class FlagEmbedding extends Embedding {
21299
18930
  constructor(tokenizer, session, model) {
21300
18931
  super();
@@ -21322,6 +18953,7 @@ var FlagEmbedding = class FlagEmbedding extends Embedding {
21322
18953
  * Counts texts longer than the model's token window. `embed()` silently truncates these to `maxLength`.
21323
18954
  */
21324
18955
  async countTruncated(textStrings, batchSize = 256) {
18956
+ assertValidBatchSize(batchSize);
21325
18957
  let count = 0;
21326
18958
  let maxLength = 0;
21327
18959
  for (let i = 0; i < textStrings.length; i += batchSize) {
@@ -21380,6 +19012,7 @@ var FlagEmbedding = class FlagEmbedding extends Embedding {
21380
19012
  return modelDir;
21381
19013
  }
21382
19014
  async *embed(textStrings, batchSize = 256) {
19015
+ assertValidBatchSize(batchSize);
21383
19016
  for (let i = 0; i < textStrings.length; i += batchSize) {
21384
19017
  const batchTexts = textStrings.slice(i, i + batchSize);
21385
19018
  const encodedTexts = await Promise.all(batchTexts.map((textString) => this.tokenizer.encode(textString)));
@@ -21504,6 +19137,7 @@ var SparseTextEmbedding = class SparseTextEmbedding extends SparseEmbedding {
21504
19137
  return modelDir;
21505
19138
  }
21506
19139
  async *embed(textStrings, batchSize = 256) {
19140
+ assertValidBatchSize(batchSize);
21507
19141
  for (let i = 0; i < textStrings.length; i += batchSize) {
21508
19142
  const batchTexts = textStrings.slice(i, i + batchSize);
21509
19143
  const encodedTexts = await Promise.all(batchTexts.map((textString) => this.tokenizer.encode(textString)));
@@ -21603,6 +19237,7 @@ async function generateEmbeddings(values, modelType) {
21603
19237
  const allResults = [];
21604
19238
  for await (const result of embeddings) allResults.push(...result.map((embedding) => Array.from(embedding)));
21605
19239
  if (allResults.length === 0) throw new Error("No embeddings generated");
19240
+ if (allResults.length !== values.length) throw new Error(`Expected ${values.length} embeddings but received ${allResults.length}`);
21606
19241
  return { embeddings: allResults };
21607
19242
  }
21608
19243
  function applyPrefix(values, prefix) {