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