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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ import { Readable } from "stream";
7
7
  import { pipeline } from "stream/promises";
8
8
  import * as ort from "onnxruntime-node";
9
9
  import { downloadFile } from "@huggingface/hub";
10
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v4/core/util.js
10
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v4/core/util.js
11
11
  function getEnumValues(entries) {
12
12
  const numericValues = Object.values(entries).filter((v) => typeof v === "number");
13
13
  return Object.entries(entries).filter(([k, _]) => numericValues.indexOf(+k) === -1).map(([_, v]) => v);
@@ -332,6 +332,17 @@ function prefixIssues(path, issues) {
332
332
  function unwrapMessage(message) {
333
333
  return typeof message === "string" ? message : message?.message;
334
334
  }
335
+ /** The leading size checks of `defChecks` that set an upper bound, each paired with it. */
336
+ function sizeCaps(defChecks) {
337
+ const caps = [];
338
+ for (const ch of defChecks ?? []) {
339
+ const d = ch._zod.def;
340
+ if (!/_(length|size)$|_equals$/.test(d.check)) break;
341
+ const max = d.maximum ?? d.length ?? d.size;
342
+ if (max >= 0) caps.push([max, ch]);
343
+ }
344
+ return caps;
345
+ }
335
346
  function attachSchema(issues, start, inst) {
336
347
  var _a;
337
348
  for (let i = start; i < issues.length; i++) (_a = issues[i]).schema ?? (_a.schema = inst);
@@ -546,7 +557,7 @@ function constantCatch(value) {
546
557
  return fn;
547
558
  }
548
559
  //#endregion
549
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v4/core/core.js
560
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v4/core/core.js
550
561
  var _a$8;
551
562
  const _zodDesc = {
552
563
  value: void 0,
@@ -652,7 +663,7 @@ function config(newConfig) {
652
663
  return globalConfig;
653
664
  }
654
665
  //#endregion
655
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v4/core/errors.js
666
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v4/core/errors.js
656
667
  function _getMessage() {
657
668
  const internals = this._zod;
658
669
  internals.message ?? (internals.message = JSON.stringify(internals.def, jsonStringifyReplacer, 2));
@@ -766,7 +777,7 @@ function formatError(error, mapper = (issue) => issue.message) {
766
777
  return fieldErrors;
767
778
  }
768
779
  //#endregion
769
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v4/core/parse.js
780
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v4/core/parse.js
770
781
  function finalizeParams(callee, params) {
771
782
  return {
772
783
  callee: params?.callee ?? callee,
@@ -969,7 +980,7 @@ const _safeDecodeAsync = (_Err) => async (schema, value, _ctx) => {
969
980
  return _safeParseAsync(_Err)(schema, value, _ctx);
970
981
  };
971
982
  //#endregion
972
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v4/core/regexes.js
983
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v4/core/regexes.js
973
984
  /**
974
985
  * @deprecated CUID v1 is deprecated by its authors due to information leakage
975
986
  * (timestamps embedded in the id). Use {@link cuid2} instead.
@@ -1042,7 +1053,7 @@ const _null$2 = /^null$/i;
1042
1053
  const lowercase = /^[^A-Z]*$/;
1043
1054
  const uppercase = /^[^a-z]*$/;
1044
1055
  //#endregion
1045
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v4/core/checks.js
1056
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v4/core/checks.js
1046
1057
  const $ZodCheck = /*@__PURE__*/ $constructor("$ZodCheck", (inst, def) => {
1047
1058
  var _a;
1048
1059
  inst._zod ?? (inst._zod = {});
@@ -1373,7 +1384,7 @@ const $ZodCheckOverwrite = /*@__PURE__*/ $constructor("$ZodCheckOverwrite", (ins
1373
1384
  };
1374
1385
  });
1375
1386
  //#endregion
1376
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v4/core/doc.js
1387
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v4/core/doc.js
1377
1388
  var Doc = class {
1378
1389
  constructor(args = [], closed = {}) {
1379
1390
  this.content = [];
@@ -1407,14 +1418,14 @@ var Doc = class {
1407
1418
  }
1408
1419
  };
1409
1420
  //#endregion
1410
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v4/core/versions.js
1421
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v4/core/versions.js
1411
1422
  const version = {
1412
1423
  major: 4,
1413
1424
  minor: 6,
1414
- patch: 5
1425
+ patch: 7
1415
1426
  };
1416
1427
  //#endregion
1417
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v4/core/schemas.js
1428
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v4/core/schemas.js
1418
1429
  const $ZodType = /*@__PURE__*/ $constructor("$ZodType", (inst, def) => {
1419
1430
  var _a;
1420
1431
  inst ?? (inst = {});
@@ -1911,10 +1922,6 @@ const $ZodNull = /*@__PURE__*/ $constructor("$ZodNull", (inst, def) => {
1911
1922
  return payload;
1912
1923
  };
1913
1924
  });
1914
- const $ZodAny = /*@__PURE__*/ $constructor("$ZodAny", (inst, def) => {
1915
- $ZodType.init(inst, def);
1916
- inst._zod.parse = (payload) => payload;
1917
- });
1918
1925
  const $ZodUnknown = /*@__PURE__*/ $constructor("$ZodUnknown", (inst, def) => {
1919
1926
  $ZodType.init(inst, def);
1920
1927
  inst._zod.parse = (payload) => payload;
@@ -1931,6 +1938,26 @@ const $ZodNever = /*@__PURE__*/ $constructor("$ZodNever", (inst, def) => {
1931
1938
  return payload;
1932
1939
  };
1933
1940
  });
1941
+ function capSize(inst, size) {
1942
+ const caps = sizeCaps(inst._zod.def.checks);
1943
+ if (!caps.length) return;
1944
+ const cap = Math.min(...caps.map((c) => c[0]));
1945
+ const parse = inst._zod.parse;
1946
+ inst._zod.parse = (payload, ctx) => {
1947
+ const n = size(payload.value);
1948
+ if (n > cap && !ctx?.skipChecks && ctx?.direction !== "backward") {
1949
+ for (const [max, ch] of sizeCaps(inst._zod.def.checks)) if (n > max && ch._zod.def.when(payload)) {
1950
+ const start = payload.issues.length;
1951
+ ch._zod.check(payload);
1952
+ payload.issues[start].continue = false;
1953
+ attachSchema(payload.issues, start, inst);
1954
+ return payload;
1955
+ }
1956
+ }
1957
+ return parse(payload, ctx);
1958
+ };
1959
+ }
1960
+ const arraySize = (input) => Array.isArray(input) ? input.length : -1;
1934
1961
  function handleArrayResult(result, final, index) {
1935
1962
  if (result.issues.length) final.issues.push(...prefixIssues(index, result.issues));
1936
1963
  final.value[index] = result.value;
@@ -1968,6 +1995,7 @@ const $ZodArray = /*@__PURE__*/ $constructor("$ZodArray", (inst, def) => {
1968
1995
  if (proms.length) return Promise.all(proms).then(() => payload);
1969
1996
  return payload;
1970
1997
  };
1998
+ capSize(inst, arraySize);
1971
1999
  });
1972
2000
  function handlePropertyResult(result, final, key, input, optin, optout) {
1973
2001
  const isPresent = key in input;
@@ -2881,7 +2909,7 @@ function handleRefineResult(result, payload, input, inst) {
2881
2909
  }
2882
2910
  }
2883
2911
  //#endregion
2884
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v4/core/memoizer.js
2912
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v4/core/memoizer.js
2885
2913
  var $ZodCyclicError = class extends Error {
2886
2914
  constructor() {
2887
2915
  super(`Cannot parse a reference cycle that closes through a transform`);
@@ -3134,7 +3162,7 @@ function isBackEdge(ctx, value) {
3134
3162
  return backEdges !== void 0 && isRef(value) && backEdges.has(value);
3135
3163
  }
3136
3164
  //#endregion
3137
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v4/locales/en.js
3165
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v4/locales/en.js
3138
3166
  const error = () => {
3139
3167
  const Sizable = {
3140
3168
  string: {
@@ -3242,7 +3270,7 @@ function en_default() {
3242
3270
  return { localeError: error() };
3243
3271
  }
3244
3272
  //#endregion
3245
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v4/core/registries.js
3273
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v4/core/registries.js
3246
3274
  var _a$6;
3247
3275
  var $ZodRegistry = class {
3248
3276
  constructor() {
@@ -3289,7 +3317,7 @@ function registry() {
3289
3317
  (_a$6 = globalThis).__zod_globalRegistry ?? (_a$6.__zod_globalRegistry = registry());
3290
3318
  const globalRegistry = globalThis.__zod_globalRegistry;
3291
3319
  //#endregion
3292
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v4/core/api.js
3320
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v4/core/api.js
3293
3321
  function snapshotChecks(def) {
3294
3322
  if (def.checks) def.checks = [...def.checks];
3295
3323
  return def;
@@ -3602,10 +3630,6 @@ function _null$1(Class, params) {
3602
3630
  });
3603
3631
  }
3604
3632
  // @__NO_SIDE_EFFECTS__
3605
- function _any(Class) {
3606
- return new Class({ type: "any" });
3607
- }
3608
- // @__NO_SIDE_EFFECTS__
3609
3633
  function _unknown(Class) {
3610
3634
  return new Class({ type: "unknown" });
3611
3635
  }
@@ -3828,7 +3852,7 @@ function _check(fn, params) {
3828
3852
  return ch;
3829
3853
  }
3830
3854
  //#endregion
3831
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v4/core/to-json-schema.js
3855
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v4/core/to-json-schema.js
3832
3856
  function assignProps(target, ...sources) {
3833
3857
  for (const source of sources) for (const key of Reflect.ownKeys(source)) if (Object.prototype.propertyIsEnumerable.call(source, key)) assignProp(target, key, source[key]);
3834
3858
  return target;
@@ -4270,7 +4294,7 @@ const createStandardJSONSchemaMethod = (schema, io, processors = {}) => (params)
4270
4294
  return finalize(ctx, schema);
4271
4295
  };
4272
4296
  //#endregion
4273
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v4/core/json-schema-processors.js
4297
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v4/core/json-schema-processors.js
4274
4298
  const narrowMin = (agg, key, value) => {
4275
4299
  if (agg[key] === void 0 || value > agg[key]) agg[key] = value;
4276
4300
  };
@@ -4914,7 +4938,7 @@ function toJSONSchema(input, params) {
4914
4938
  return finalize(ctx, input);
4915
4939
  }
4916
4940
  //#endregion
4917
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v4/classic/errors.js
4941
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v4/classic/errors.js
4918
4942
  const _installedErrorProtos = /* @__PURE__ */ new WeakSet([Object.prototype, Error.prototype]);
4919
4943
  function _lazyMethod(proto, key, make) {
4920
4944
  Object.defineProperty(proto, key, {
@@ -4964,7 +4988,7 @@ const initializer = (inst, issues) => {
4964
4988
  };
4965
4989
  const ZodRealError = /*@__PURE__*/ $constructor("ZodError", initializer, void 0, { Parent: Error });
4966
4990
  //#endregion
4967
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v4/classic/parse.js
4991
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v4/classic/parse.js
4968
4992
  const parse = /* @__PURE__ */ _parse$2(ZodRealError);
4969
4993
  const parseAsync = /* @__PURE__ */ _parseAsync(ZodRealError);
4970
4994
  const safeParse = /* @__PURE__ */ _safeParse(ZodRealError);
@@ -4978,7 +5002,7 @@ const safeDecode = /* @__PURE__ */ _safeDecode(ZodRealError);
4978
5002
  const safeEncodeAsync = /* @__PURE__ */ _safeEncodeAsync(ZodRealError);
4979
5003
  const safeDecodeAsync = /* @__PURE__ */ _safeDecodeAsync(ZodRealError);
4980
5004
  //#endregion
4981
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v4/classic/schemas.js
5005
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v4/classic/schemas.js
4982
5006
  function _ensureDefaultLocale() {
4983
5007
  if (!globalConfig.localeError) config(en_default());
4984
5008
  }
@@ -5489,14 +5513,6 @@ const ZodNull$1 = /*@__PURE__*/ $constructor("ZodNull", (inst, def) => {
5489
5513
  function _null(params) {
5490
5514
  return /* @__PURE__ */ _null$1(ZodNull$1, params);
5491
5515
  }
5492
- const ZodAny$1 = /*@__PURE__*/ $constructor("ZodAny", (inst, def) => {
5493
- $ZodAny.init(inst, def);
5494
- ZodType$1.init(inst, def);
5495
- inst._zod.processJSONSchema = (ctx, json, params) => void 0;
5496
- });
5497
- function any() {
5498
- return /* @__PURE__ */ _any(ZodAny$1);
5499
- }
5500
5516
  const ZodUnknown$1 = /*@__PURE__*/ $constructor("ZodUnknown", (inst, def) => {
5501
5517
  $ZodUnknown.init(inst, def);
5502
5518
  ZodType$1.init(inst, def);
@@ -5916,7 +5932,7 @@ function _instanceof(cls, params = {}) {
5916
5932
  return inst;
5917
5933
  }
5918
5934
  //#endregion
5919
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v3/helpers/util.js
5935
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v3/helpers/util.js
5920
5936
  var util;
5921
5937
  (function(util) {
5922
5938
  util.assertEqual = (_) => {};
@@ -6012,7 +6028,7 @@ const getParsedType = (data) => {
6012
6028
  }
6013
6029
  };
6014
6030
  //#endregion
6015
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v3/ZodError.js
6031
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v3/ZodError.js
6016
6032
  const ZodIssueCode = util.arrayToEnum([
6017
6033
  "invalid_type",
6018
6034
  "invalid_literal",
@@ -6120,7 +6136,7 @@ ZodError.create = (issues) => {
6120
6136
  return new ZodError(issues);
6121
6137
  };
6122
6138
  //#endregion
6123
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v3/locales/en.js
6139
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v3/locales/en.js
6124
6140
  const errorMap = (issue, _ctx) => {
6125
6141
  let message;
6126
6142
  switch (issue.code) {
@@ -6197,13 +6213,13 @@ const errorMap = (issue, _ctx) => {
6197
6213
  return { message };
6198
6214
  };
6199
6215
  //#endregion
6200
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v3/errors.js
6216
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v3/errors.js
6201
6217
  let overrideErrorMap = errorMap;
6202
6218
  function getErrorMap() {
6203
6219
  return overrideErrorMap;
6204
6220
  }
6205
6221
  //#endregion
6206
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v3/helpers/parseUtil.js
6222
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v3/helpers/parseUtil.js
6207
6223
  const makeIssue = (params) => {
6208
6224
  const { data, path, errorMaps, issueData } = params;
6209
6225
  const fullPath = [...path, ...issueData.path || []];
@@ -6307,14 +6323,14 @@ const isDirty = (x) => x.status === "dirty";
6307
6323
  const isValid = (x) => x.status === "valid";
6308
6324
  const isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
6309
6325
  //#endregion
6310
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v3/helpers/errorUtil.js
6326
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v3/helpers/errorUtil.js
6311
6327
  var errorUtil;
6312
6328
  (function(errorUtil) {
6313
6329
  errorUtil.errToObj = (message) => typeof message === "string" ? { message } : message || {};
6314
6330
  errorUtil.toString = (message) => typeof message === "string" ? message : message?.message;
6315
6331
  })(errorUtil || (errorUtil = {}));
6316
6332
  //#endregion
6317
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.5/6448fd814698825170f93bd428080c609bd45ccbc007f4c2dfd5fac1bb52f28d/node_modules/zod/v3/types.js
6333
+ //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/zod/4.6.7/4c9f15c99caaca8b83ba8ab68f247a75121c86fb7e498876ed36daccd0f3d3ce/node_modules/zod/v3/types.js
6318
6334
  var ParseInputLazyPath = class {
6319
6335
  constructor(parent, value, path, key) {
6320
6336
  this._cachedPath = [];
@@ -9470,12 +9486,12 @@ ZodNullable.create;
9470
9486
  ZodEffects.createWithPreprocess;
9471
9487
  ZodPipeline.create;
9472
9488
  //#endregion
9473
- //#region ../_vendored/ai_v5/dist/dist-CwCWl16R.js
9474
- var marker$2$6 = "vercel.ai.error";
9475
- var symbol$2$6 = Symbol.for(marker$2$6);
9476
- var _a$2$6;
9477
- var _b$2$2;
9478
- var AISDKError$1$3 = class _AISDKError extends (_b$2$2 = Error, _a$2$6 = symbol$2$6, _b$2$2) {
9489
+ //#region ../_vendored/ai_v5/dist/dist-D-EBFNkO.js
9490
+ var marker$1$6 = "vercel.ai.error";
9491
+ var symbol$1$6 = Symbol.for(marker$1$6);
9492
+ var _a$1$6;
9493
+ var _b$1$1;
9494
+ var AISDKError$2 = class _AISDKError extends (_b$1$1 = Error, _a$1$6 = symbol$1$6, _b$1$1) {
9479
9495
  /**
9480
9496
  * Creates an AI SDK Error.
9481
9497
  *
@@ -9486,7 +9502,7 @@ var AISDKError$1$3 = class _AISDKError extends (_b$2$2 = Error, _a$2$6 = symbol$
9486
9502
  */
9487
9503
  constructor({ name: name14, message, cause }) {
9488
9504
  super(message);
9489
- this[_a$2$6] = true;
9505
+ this[_a$1$6] = true;
9490
9506
  this.name = name14;
9491
9507
  this.cause = cause;
9492
9508
  }
@@ -9496,26 +9512,26 @@ var AISDKError$1$3 = class _AISDKError extends (_b$2$2 = Error, _a$2$6 = symbol$
9496
9512
  * @returns {boolean} True if the error is an AI SDK Error, false otherwise.
9497
9513
  */
9498
9514
  static isInstance(error) {
9499
- return _AISDKError.hasMarker(error, marker$2$6);
9515
+ return _AISDKError.hasMarker(error, marker$1$6);
9500
9516
  }
9501
9517
  static hasMarker(error, marker15) {
9502
9518
  const markerSymbol = Symbol.for(marker15);
9503
9519
  return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
9504
9520
  }
9505
9521
  };
9506
- var name$2$6 = "AI_APICallError";
9507
- var marker2$1$7 = `vercel.ai.error.${name$2$6}`;
9508
- var symbol2$1$7 = Symbol.for(marker2$1$7);
9509
- var _a2$1$7;
9510
- var _b2$1$3;
9511
- var APICallError$1$1 = class extends (_b2$1$3 = AISDKError$1$3, _a2$1$7 = symbol2$1$7, _b2$1$3) {
9522
+ var name$1$6 = "AI_APICallError";
9523
+ var marker2$5 = `vercel.ai.error.${name$1$6}`;
9524
+ var symbol2$5 = Symbol.for(marker2$5);
9525
+ var _a2$5;
9526
+ var _b2$1;
9527
+ (class extends (_b2$1 = AISDKError$2, _a2$5 = symbol2$5, _b2$1) {
9512
9528
  constructor({ message, url, requestBodyValues, statusCode, responseHeaders, responseBody, cause, isRetryable = statusCode != null && (statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500), data }) {
9513
9529
  super({
9514
- name: name$2$6,
9530
+ name: name$1$6,
9515
9531
  message,
9516
9532
  cause
9517
9533
  });
9518
- this[_a2$1$7] = true;
9534
+ this[_a2$5] = true;
9519
9535
  this.url = url;
9520
9536
  this.requestBodyValues = requestBodyValues;
9521
9537
  this.statusCode = statusCode;
@@ -9525,217 +9541,217 @@ var APICallError$1$1 = class extends (_b2$1$3 = AISDKError$1$3, _a2$1$7 = symbol
9525
9541
  this.data = data;
9526
9542
  }
9527
9543
  static isInstance(error) {
9528
- return AISDKError$1$3.hasMarker(error, marker2$1$7);
9544
+ return AISDKError$2.hasMarker(error, marker2$5);
9529
9545
  }
9530
- };
9531
- var name2$1$7 = "AI_EmptyResponseBodyError";
9532
- var marker3$1$7 = `vercel.ai.error.${name2$1$7}`;
9533
- var symbol3$1$7 = Symbol.for(marker3$1$7);
9534
- var _a3$1$7;
9535
- var _b3$1$3;
9536
- var EmptyResponseBodyError$1$1 = class extends (_b3$1$3 = AISDKError$1$3, _a3$1$7 = symbol3$1$7, _b3$1$3) {
9546
+ });
9547
+ var name2$5 = "AI_EmptyResponseBodyError";
9548
+ var marker3$5 = `vercel.ai.error.${name2$5}`;
9549
+ var symbol3$5 = Symbol.for(marker3$5);
9550
+ var _a3$5;
9551
+ var _b3$1;
9552
+ (class extends (_b3$1 = AISDKError$2, _a3$5 = symbol3$5, _b3$1) {
9537
9553
  constructor({ message = "Empty response body" } = {}) {
9538
9554
  super({
9539
- name: name2$1$7,
9555
+ name: name2$5,
9540
9556
  message
9541
9557
  });
9542
- this[_a3$1$7] = true;
9558
+ this[_a3$5] = true;
9543
9559
  }
9544
9560
  static isInstance(error) {
9545
- return AISDKError$1$3.hasMarker(error, marker3$1$7);
9561
+ return AISDKError$2.hasMarker(error, marker3$5);
9546
9562
  }
9547
- };
9548
- function getErrorMessage$2$1(error) {
9563
+ });
9564
+ function getErrorMessage$1$1(error) {
9549
9565
  if (error == null) return "unknown error";
9550
9566
  if (typeof error === "string") return error;
9551
9567
  if (error instanceof Error) return error.message;
9552
9568
  return JSON.stringify(error);
9553
9569
  }
9554
- var name3$1$7 = "AI_InvalidArgumentError";
9555
- var marker4$1$7 = `vercel.ai.error.${name3$1$7}`;
9556
- var symbol4$1$7 = Symbol.for(marker4$1$7);
9557
- var _a4$1$7;
9558
- var _b4$1$3;
9559
- var InvalidArgumentError$1$3 = class extends (_b4$1$3 = AISDKError$1$3, _a4$1$7 = symbol4$1$7, _b4$1$3) {
9570
+ var name3$5 = "AI_InvalidArgumentError";
9571
+ var marker4$5 = `vercel.ai.error.${name3$5}`;
9572
+ var symbol4$5 = Symbol.for(marker4$5);
9573
+ var _a4$5;
9574
+ var _b4$1;
9575
+ var InvalidArgumentError$2 = class extends (_b4$1 = AISDKError$2, _a4$5 = symbol4$5, _b4$1) {
9560
9576
  constructor({ message, cause, argument }) {
9561
9577
  super({
9562
- name: name3$1$7,
9578
+ name: name3$5,
9563
9579
  message,
9564
9580
  cause
9565
9581
  });
9566
- this[_a4$1$7] = true;
9582
+ this[_a4$5] = true;
9567
9583
  this.argument = argument;
9568
9584
  }
9569
9585
  static isInstance(error) {
9570
- return AISDKError$1$3.hasMarker(error, marker4$1$7);
9586
+ return AISDKError$2.hasMarker(error, marker4$5);
9571
9587
  }
9572
9588
  };
9573
- var name4$1$7 = "AI_InvalidPromptError";
9574
- var marker5$1$7 = `vercel.ai.error.${name4$1$7}`;
9575
- var symbol5$1$7 = Symbol.for(marker5$1$7);
9576
- var _a5$1$7;
9577
- var _b5$1$3;
9578
- (class extends (_b5$1$3 = AISDKError$1$3, _a5$1$7 = symbol5$1$7, _b5$1$3) {
9589
+ var name4$5 = "AI_InvalidPromptError";
9590
+ var marker5$5 = `vercel.ai.error.${name4$5}`;
9591
+ var symbol5$5 = Symbol.for(marker5$5);
9592
+ var _a5$5;
9593
+ var _b5$1;
9594
+ (class extends (_b5$1 = AISDKError$2, _a5$5 = symbol5$5, _b5$1) {
9579
9595
  constructor({ prompt, message, cause }) {
9580
9596
  super({
9581
- name: name4$1$7,
9597
+ name: name4$5,
9582
9598
  message: `Invalid prompt: ${message}`,
9583
9599
  cause
9584
9600
  });
9585
- this[_a5$1$7] = true;
9601
+ this[_a5$5] = true;
9586
9602
  this.prompt = prompt;
9587
9603
  }
9588
9604
  static isInstance(error) {
9589
- return AISDKError$1$3.hasMarker(error, marker5$1$7);
9605
+ return AISDKError$2.hasMarker(error, marker5$5);
9590
9606
  }
9591
9607
  });
9592
- var name5$1$7 = "AI_InvalidResponseDataError";
9593
- var marker6$1$7 = `vercel.ai.error.${name5$1$7}`;
9594
- var symbol6$1$7 = Symbol.for(marker6$1$7);
9595
- var _a6$1$7;
9596
- var _b6$1$3;
9597
- (class extends (_b6$1$3 = AISDKError$1$3, _a6$1$7 = symbol6$1$7, _b6$1$3) {
9608
+ var name5$5 = "AI_InvalidResponseDataError";
9609
+ var marker6$5 = `vercel.ai.error.${name5$5}`;
9610
+ var symbol6$5 = Symbol.for(marker6$5);
9611
+ var _a6$5;
9612
+ var _b6$1;
9613
+ (class extends (_b6$1 = AISDKError$2, _a6$5 = symbol6$5, _b6$1) {
9598
9614
  constructor({ data, message = `Invalid response data: ${JSON.stringify(data)}.` }) {
9599
9615
  super({
9600
- name: name5$1$7,
9616
+ name: name5$5,
9601
9617
  message
9602
9618
  });
9603
- this[_a6$1$7] = true;
9619
+ this[_a6$5] = true;
9604
9620
  this.data = data;
9605
9621
  }
9606
9622
  static isInstance(error) {
9607
- return AISDKError$1$3.hasMarker(error, marker6$1$7);
9623
+ return AISDKError$2.hasMarker(error, marker6$5);
9608
9624
  }
9609
9625
  });
9610
- var name6$1$7 = "AI_JSONParseError";
9611
- var marker7$1$7 = `vercel.ai.error.${name6$1$7}`;
9612
- var symbol7$1$7 = Symbol.for(marker7$1$7);
9613
- var _a7$1$7;
9614
- var _b7$1$3;
9615
- var JSONParseError$1$3 = class extends (_b7$1$3 = AISDKError$1$3, _a7$1$7 = symbol7$1$7, _b7$1$3) {
9626
+ var name6$5 = "AI_JSONParseError";
9627
+ var marker7$5 = `vercel.ai.error.${name6$5}`;
9628
+ var symbol7$5 = Symbol.for(marker7$5);
9629
+ var _a7$5;
9630
+ var _b7$1;
9631
+ var JSONParseError$2 = class extends (_b7$1 = AISDKError$2, _a7$5 = symbol7$5, _b7$1) {
9616
9632
  constructor({ text, cause }) {
9617
9633
  super({
9618
- name: name6$1$7,
9634
+ name: name6$5,
9619
9635
  message: `JSON parsing failed: Text: ${text}.
9620
- Error message: ${getErrorMessage$2$1(cause)}`,
9636
+ Error message: ${getErrorMessage$1$1(cause)}`,
9621
9637
  cause
9622
9638
  });
9623
- this[_a7$1$7] = true;
9639
+ this[_a7$5] = true;
9624
9640
  this.text = text;
9625
9641
  }
9626
9642
  static isInstance(error) {
9627
- return AISDKError$1$3.hasMarker(error, marker7$1$7);
9643
+ return AISDKError$2.hasMarker(error, marker7$5);
9628
9644
  }
9629
9645
  };
9630
- var name7$1$7 = "AI_LoadAPIKeyError";
9631
- var marker8$1$7 = `vercel.ai.error.${name7$1$7}`;
9632
- var symbol8$1$7 = Symbol.for(marker8$1$7);
9633
- var _a8$1$7;
9634
- var _b8$1$3;
9635
- (class extends (_b8$1$3 = AISDKError$1$3, _a8$1$7 = symbol8$1$7, _b8$1$3) {
9646
+ var name7$5 = "AI_LoadAPIKeyError";
9647
+ var marker8$5 = `vercel.ai.error.${name7$5}`;
9648
+ var symbol8$5 = Symbol.for(marker8$5);
9649
+ var _a8$5;
9650
+ var _b8$1;
9651
+ (class extends (_b8$1 = AISDKError$2, _a8$5 = symbol8$5, _b8$1) {
9636
9652
  constructor({ message }) {
9637
9653
  super({
9638
- name: name7$1$7,
9654
+ name: name7$5,
9639
9655
  message
9640
9656
  });
9641
- this[_a8$1$7] = true;
9657
+ this[_a8$5] = true;
9642
9658
  }
9643
9659
  static isInstance(error) {
9644
- return AISDKError$1$3.hasMarker(error, marker8$1$7);
9660
+ return AISDKError$2.hasMarker(error, marker8$5);
9645
9661
  }
9646
9662
  });
9647
- var name8$1$6 = "AI_LoadSettingError";
9648
- var marker9$1$6 = `vercel.ai.error.${name8$1$6}`;
9649
- var symbol9$1$6 = Symbol.for(marker9$1$6);
9650
- var _a9$1$6;
9651
- var _b9$1$3;
9652
- (class extends (_b9$1$3 = AISDKError$1$3, _a9$1$6 = symbol9$1$6, _b9$1$3) {
9663
+ var name8$4 = "AI_LoadSettingError";
9664
+ var marker9$4 = `vercel.ai.error.${name8$4}`;
9665
+ var symbol9$4 = Symbol.for(marker9$4);
9666
+ var _a9$4;
9667
+ var _b9$1;
9668
+ (class extends (_b9$1 = AISDKError$2, _a9$4 = symbol9$4, _b9$1) {
9653
9669
  constructor({ message }) {
9654
9670
  super({
9655
- name: name8$1$6,
9671
+ name: name8$4,
9656
9672
  message
9657
9673
  });
9658
- this[_a9$1$6] = true;
9674
+ this[_a9$4] = true;
9659
9675
  }
9660
9676
  static isInstance(error) {
9661
- return AISDKError$1$3.hasMarker(error, marker9$1$6);
9677
+ return AISDKError$2.hasMarker(error, marker9$4);
9662
9678
  }
9663
9679
  });
9664
- var name9$1$6 = "AI_NoContentGeneratedError";
9665
- var marker10$1$6 = `vercel.ai.error.${name9$1$6}`;
9666
- var symbol10$1$6 = Symbol.for(marker10$1$6);
9667
- var _a10$1$6;
9668
- var _b10$1$1;
9669
- (class extends (_b10$1$1 = AISDKError$1$3, _a10$1$6 = symbol10$1$6, _b10$1$1) {
9680
+ var name9$5 = "AI_NoContentGeneratedError";
9681
+ var marker10$5 = `vercel.ai.error.${name9$5}`;
9682
+ var symbol10$5 = Symbol.for(marker10$5);
9683
+ var _a10$5;
9684
+ var _b10$1;
9685
+ (class extends (_b10$1 = AISDKError$2, _a10$5 = symbol10$5, _b10$1) {
9670
9686
  constructor({ message = "No content generated." } = {}) {
9671
9687
  super({
9672
- name: name9$1$6,
9688
+ name: name9$5,
9673
9689
  message
9674
9690
  });
9675
- this[_a10$1$6] = true;
9691
+ this[_a10$5] = true;
9676
9692
  }
9677
9693
  static isInstance(error) {
9678
- return AISDKError$1$3.hasMarker(error, marker10$1$6);
9694
+ return AISDKError$2.hasMarker(error, marker10$5);
9679
9695
  }
9680
9696
  });
9681
- var name10$1$6 = "AI_NoSuchModelError";
9682
- var marker11$1$6 = `vercel.ai.error.${name10$1$6}`;
9683
- var symbol11$1$6 = Symbol.for(marker11$1$6);
9684
- var _a11$1$6;
9685
- var _b11$1$1;
9686
- (class extends (_b11$1$1 = AISDKError$1$3, _a11$1$6 = symbol11$1$6, _b11$1$1) {
9687
- constructor({ errorName = name10$1$6, modelId, modelType, message = `No such ${modelType}: ${modelId}` }) {
9697
+ var name10$5 = "AI_NoSuchModelError";
9698
+ var marker11$5 = `vercel.ai.error.${name10$5}`;
9699
+ var symbol11$5 = Symbol.for(marker11$5);
9700
+ var _a11$5;
9701
+ var _b11$1;
9702
+ var NoSuchModelError$2 = class extends (_b11$1 = AISDKError$2, _a11$5 = symbol11$5, _b11$1) {
9703
+ constructor({ errorName = name10$5, modelId, modelType, message = `No such ${modelType}: ${modelId}` }) {
9688
9704
  super({
9689
9705
  name: errorName,
9690
9706
  message
9691
9707
  });
9692
- this[_a11$1$6] = true;
9708
+ this[_a11$5] = true;
9693
9709
  this.modelId = modelId;
9694
9710
  this.modelType = modelType;
9695
9711
  }
9696
9712
  static isInstance(error) {
9697
- return AISDKError$1$3.hasMarker(error, marker11$1$6);
9713
+ return AISDKError$2.hasMarker(error, marker11$5);
9698
9714
  }
9699
- });
9700
- var name11$1$5 = "AI_TooManyEmbeddingValuesForCallError";
9701
- var marker12$1$5 = `vercel.ai.error.${name11$1$5}`;
9702
- var symbol12$1$5 = Symbol.for(marker12$1$5);
9703
- var _a12$1$5;
9704
- var _b12$1$1;
9705
- (class extends (_b12$1$1 = AISDKError$1$3, _a12$1$5 = symbol12$1$5, _b12$1$1) {
9715
+ };
9716
+ var name11$4 = "AI_TooManyEmbeddingValuesForCallError";
9717
+ var marker12$4 = `vercel.ai.error.${name11$4}`;
9718
+ var symbol12$4 = Symbol.for(marker12$4);
9719
+ var _a12$4;
9720
+ var _b12$1;
9721
+ (class extends (_b12$1 = AISDKError$2, _a12$4 = symbol12$4, _b12$1) {
9706
9722
  constructor(options) {
9707
9723
  super({
9708
- name: name11$1$5,
9724
+ name: name11$4,
9709
9725
  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.`
9710
9726
  });
9711
- this[_a12$1$5] = true;
9727
+ this[_a12$4] = true;
9712
9728
  this.provider = options.provider;
9713
9729
  this.modelId = options.modelId;
9714
9730
  this.maxEmbeddingsPerCall = options.maxEmbeddingsPerCall;
9715
9731
  this.values = options.values;
9716
9732
  }
9717
9733
  static isInstance(error) {
9718
- return AISDKError$1$3.hasMarker(error, marker12$1$5);
9734
+ return AISDKError$2.hasMarker(error, marker12$4);
9719
9735
  }
9720
9736
  });
9721
- var name12$1$6 = "AI_TypeValidationError";
9722
- var marker13$1$6 = `vercel.ai.error.${name12$1$6}`;
9723
- var symbol13$1$6 = Symbol.for(marker13$1$6);
9724
- var _a13$1$6;
9725
- var _b13$1$1;
9726
- var TypeValidationError$1$3 = class _TypeValidationError extends (_b13$1$1 = AISDKError$1$3, _a13$1$6 = symbol13$1$6, _b13$1$1) {
9737
+ var name12$5 = "AI_TypeValidationError";
9738
+ var marker13$5 = `vercel.ai.error.${name12$5}`;
9739
+ var symbol13$5 = Symbol.for(marker13$5);
9740
+ var _a13$5;
9741
+ var _b13$1;
9742
+ var TypeValidationError$2 = class _TypeValidationError extends (_b13$1 = AISDKError$2, _a13$5 = symbol13$5, _b13$1) {
9727
9743
  constructor({ value, cause }) {
9728
9744
  super({
9729
- name: name12$1$6,
9745
+ name: name12$5,
9730
9746
  message: `Type validation failed: Value: ${JSON.stringify(value)}.
9731
- Error message: ${getErrorMessage$2$1(cause)}`,
9747
+ Error message: ${getErrorMessage$1$1(cause)}`,
9732
9748
  cause
9733
9749
  });
9734
- this[_a13$1$6] = true;
9750
+ this[_a13$5] = true;
9735
9751
  this.value = value;
9736
9752
  }
9737
9753
  static isInstance(error) {
9738
- return AISDKError$1$3.hasMarker(error, marker13$1$6);
9754
+ return AISDKError$2.hasMarker(error, marker13$5);
9739
9755
  }
9740
9756
  /**
9741
9757
  * Wraps an error into a TypeValidationError.
@@ -9754,253 +9770,46 @@ Error message: ${getErrorMessage$2$1(cause)}`,
9754
9770
  });
9755
9771
  }
9756
9772
  };
9757
- var name13$1$6 = "AI_UnsupportedFunctionalityError";
9758
- var marker14$1$6 = `vercel.ai.error.${name13$1$6}`;
9759
- var symbol14$1$6 = Symbol.for(marker14$1$6);
9760
- var _a14$1$6;
9761
- var _b14$1$1;
9762
- (class extends (_b14$1$1 = AISDKError$1$3, _a14$1$6 = symbol14$1$6, _b14$1$1) {
9773
+ var name13$5 = "AI_UnsupportedFunctionalityError";
9774
+ var marker14$5 = `vercel.ai.error.${name13$5}`;
9775
+ var symbol14$5 = Symbol.for(marker14$5);
9776
+ var _a14$5;
9777
+ var _b14$1;
9778
+ (class extends (_b14$1 = AISDKError$2, _a14$5 = symbol14$5, _b14$1) {
9763
9779
  constructor({ functionality, message = `'${functionality}' functionality not supported.` }) {
9764
9780
  super({
9765
- name: name13$1$6,
9781
+ name: name13$5,
9766
9782
  message
9767
9783
  });
9768
- this[_a14$1$6] = true;
9784
+ this[_a14$5] = true;
9769
9785
  this.functionality = functionality;
9770
9786
  }
9771
9787
  static isInstance(error) {
9772
- return AISDKError$1$3.hasMarker(error, marker14$1$6);
9788
+ return AISDKError$2.hasMarker(error, marker14$5);
9773
9789
  }
9774
9790
  });
9775
- var ParseError$1 = class extends Error {
9776
- constructor(message, options) {
9777
- super(message), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
9778
- }
9779
- };
9780
- const LF$1 = 10;
9781
- const CR$1 = 13;
9782
- const SPACE$1 = 32;
9783
- function noop$1(_arg) {}
9784
- function createParser$1(callbacks) {
9785
- if (typeof callbacks == "function") throw new TypeError("`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?");
9786
- const { onEvent = noop$1, onError = noop$1, onRetry = noop$1, onComment } = callbacks, pendingFragments = [];
9787
- let isFirstChunk = !0, id, data = "", dataLines = 0, eventType;
9788
- function feed(chunk) {
9789
- if (isFirstChunk && (isFirstChunk = !1, chunk.charCodeAt(0) === 239 && chunk.charCodeAt(1) === 187 && chunk.charCodeAt(2) === 191 && (chunk = chunk.slice(3))), pendingFragments.length === 0) {
9790
- const trailing2 = processLines(chunk);
9791
- trailing2 !== "" && pendingFragments.push(trailing2);
9792
- return;
9793
- }
9794
- if (chunk.indexOf(`
9795
- `) === -1 && chunk.indexOf("\r") === -1) {
9796
- pendingFragments.push(chunk);
9797
- return;
9798
- }
9799
- pendingFragments.push(chunk);
9800
- const input = pendingFragments.join("");
9801
- pendingFragments.length = 0;
9802
- const trailing = processLines(input);
9803
- trailing !== "" && pendingFragments.push(trailing);
9804
- }
9805
- function processLines(chunk) {
9806
- let searchIndex = 0;
9807
- if (chunk.indexOf("\r") === -1) {
9808
- let lfIndex = chunk.indexOf(`
9809
- `, searchIndex);
9810
- for (; lfIndex !== -1;) {
9811
- if (searchIndex === lfIndex) {
9812
- dataLines > 0 && onEvent({
9813
- id,
9814
- event: eventType,
9815
- data
9816
- }), id = void 0, data = "", dataLines = 0, eventType = void 0, searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
9817
- `, searchIndex);
9818
- continue;
9819
- }
9820
- const firstCharCode = chunk.charCodeAt(searchIndex);
9821
- if (isDataPrefix$1(chunk, searchIndex, firstCharCode)) {
9822
- const valueStart = chunk.charCodeAt(searchIndex + 5) === SPACE$1 ? searchIndex + 6 : searchIndex + 5, value = chunk.slice(valueStart, lfIndex);
9823
- if (dataLines === 0 && chunk.charCodeAt(lfIndex + 1) === LF$1) {
9824
- onEvent({
9825
- id,
9826
- event: eventType,
9827
- data: value
9828
- }), id = void 0, data = "", eventType = void 0, searchIndex = lfIndex + 2, lfIndex = chunk.indexOf(`
9829
- `, searchIndex);
9830
- continue;
9831
- }
9832
- data = dataLines === 0 ? value : `${data}
9833
- ${value}`, dataLines++;
9834
- } 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);
9835
- searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
9836
- `, searchIndex);
9837
- }
9838
- return chunk.slice(searchIndex);
9839
- }
9840
- for (; searchIndex < chunk.length;) {
9841
- const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
9842
- `, searchIndex);
9843
- let lineEnd = -1;
9844
- 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;
9845
- parseLine(chunk, searchIndex, lineEnd), searchIndex = lineEnd + 1, chunk.charCodeAt(searchIndex - 1) === CR$1 && chunk.charCodeAt(searchIndex) === LF$1 && searchIndex++;
9846
- }
9847
- return chunk.slice(searchIndex);
9848
- }
9849
- function parseLine(chunk, start, end) {
9850
- if (start === end) {
9851
- dispatchEvent();
9852
- return;
9853
- }
9854
- const firstCharCode = chunk.charCodeAt(start);
9855
- if (isDataPrefix$1(chunk, start, firstCharCode)) {
9856
- const valueStart = chunk.charCodeAt(start + 5) === SPACE$1 ? start + 6 : start + 5, value2 = chunk.slice(valueStart, end);
9857
- data = dataLines === 0 ? value2 : `${data}
9858
- ${value2}`, dataLines++;
9859
- return;
9860
- }
9861
- if (isEventPrefix$1(chunk, start, firstCharCode)) {
9862
- eventType = chunk.slice(chunk.charCodeAt(start + 6) === SPACE$1 ? start + 7 : start + 6, end) || void 0;
9863
- return;
9864
- }
9865
- if (firstCharCode === 105 && chunk.charCodeAt(start + 1) === 100 && chunk.charCodeAt(start + 2) === 58) {
9866
- const value2 = chunk.slice(chunk.charCodeAt(start + 3) === SPACE$1 ? start + 4 : start + 3, end);
9867
- id = value2.includes("\0") ? void 0 : value2;
9868
- return;
9869
- }
9870
- if (firstCharCode === 58) {
9871
- if (onComment) {
9872
- const line2 = chunk.slice(start, end);
9873
- onComment(line2.slice(chunk.charCodeAt(start + 1) === SPACE$1 ? 2 : 1));
9874
- }
9875
- return;
9876
- }
9877
- const line = chunk.slice(start, end), fieldSeparatorIndex = line.indexOf(":");
9878
- if (fieldSeparatorIndex === -1) {
9879
- processField(line, "", line);
9880
- return;
9881
- }
9882
- const field = line.slice(0, fieldSeparatorIndex), offset = line.charCodeAt(fieldSeparatorIndex + 1) === SPACE$1 ? 2 : 1;
9883
- processField(field, line.slice(fieldSeparatorIndex + offset), line);
9884
- }
9885
- function processField(field, value, line) {
9886
- switch (field) {
9887
- case "event":
9888
- eventType = value || void 0;
9889
- break;
9890
- case "data":
9891
- data = dataLines === 0 ? value : `${data}
9892
- ${value}`, dataLines++;
9893
- break;
9894
- case "id":
9895
- id = value.includes("\0") ? void 0 : value;
9896
- break;
9897
- case "retry":
9898
- /^\d+$/.test(value) ? onRetry(parseInt(value, 10)) : onError(new ParseError$1(`Invalid \`retry\` value: "${value}"`, {
9899
- type: "invalid-retry",
9900
- value,
9901
- line
9902
- }));
9903
- break;
9904
- default:
9905
- onError(new ParseError$1(`Unknown field "${field.length > 20 ? `${field.slice(0, 20)}\u2026` : field}"`, {
9906
- type: "unknown-field",
9907
- field,
9908
- value,
9909
- line
9910
- }));
9911
- break;
9912
- }
9913
- }
9914
- function dispatchEvent() {
9915
- dataLines > 0 && onEvent({
9916
- id,
9917
- event: eventType,
9918
- data
9919
- }), id = void 0, data = "", dataLines = 0, eventType = void 0;
9920
- }
9921
- function reset(options = {}) {
9922
- if (options.consume && pendingFragments.length > 0) {
9923
- const incompleteLine = pendingFragments.join("");
9924
- parseLine(incompleteLine, 0, incompleteLine.length);
9925
- }
9926
- isFirstChunk = !0, id = void 0, data = "", dataLines = 0, eventType = void 0, pendingFragments.length = 0;
9927
- }
9928
- return {
9929
- feed,
9930
- reset
9931
- };
9932
- }
9933
- function isDataPrefix$1(chunk, i, firstCharCode) {
9934
- return firstCharCode === 100 && chunk.charCodeAt(i + 1) === 97 && chunk.charCodeAt(i + 2) === 116 && chunk.charCodeAt(i + 3) === 97 && chunk.charCodeAt(i + 4) === 58;
9935
- }
9936
- function isEventPrefix$1(chunk, i, firstCharCode) {
9937
- 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;
9938
- }
9939
- var EventSourceParserStream$1 = class extends TransformStream {
9940
- constructor({ onError, onRetry, onComment } = {}) {
9941
- let parser;
9942
- super({
9943
- start(controller) {
9944
- parser = createParser$1({
9945
- onEvent: (event) => {
9946
- controller.enqueue(event);
9947
- },
9948
- onError(error) {
9949
- onError === "terminate" ? controller.error(error) : typeof onError == "function" && onError(error);
9950
- },
9951
- onRetry,
9952
- onComment
9953
- });
9954
- },
9955
- transform(chunk) {
9956
- parser.feed(chunk);
9957
- }
9958
- });
9959
- }
9960
- };
9961
- function combineHeaders(...headers) {
9962
- return headers.reduce((combinedHeaders, currentHeaders) => ({
9963
- ...combinedHeaders,
9964
- ...currentHeaders
9965
- }), {});
9966
- }
9967
- function extractResponseHeaders(response) {
9968
- return Object.fromEntries([...response.headers]);
9969
- }
9970
- var name$1$8 = "AI_DownloadError";
9971
- var marker$1$7 = `vercel.ai.error.${name$1$8}`;
9972
- var symbol$1$8 = Symbol.for(marker$1$7);
9973
- var _a$1$8;
9974
- var _b$1$4;
9975
- var DownloadError$1 = class extends (_b$1$4 = AISDKError$1$3, _a$1$8 = symbol$1$8, _b$1$4) {
9791
+ TransformStream;
9792
+ var name$7 = "AI_DownloadError";
9793
+ var marker$7 = `vercel.ai.error.${name$7}`;
9794
+ var symbol$7 = Symbol.for(marker$7);
9795
+ var _a$7;
9796
+ var _b$2;
9797
+ (class extends (_b$2 = AISDKError$2, _a$7 = symbol$7, _b$2) {
9976
9798
  constructor({ url, statusCode, statusText, cause, message = cause == null ? `Failed to download ${url}: ${statusCode} ${statusText}` : `Failed to download ${url}: ${cause}` }) {
9977
9799
  super({
9978
- name: name$1$8,
9800
+ name: name$7,
9979
9801
  message,
9980
9802
  cause
9981
9803
  });
9982
- this[_a$1$8] = true;
9804
+ this[_a$7] = true;
9983
9805
  this.url = url;
9984
9806
  this.statusCode = statusCode;
9985
9807
  this.statusText = statusText;
9986
9808
  }
9987
9809
  static isInstance(error) {
9988
- return AISDKError$1$3.hasMarker(error, marker$1$7);
9810
+ return AISDKError$2.hasMarker(error, marker$7);
9989
9811
  }
9990
- };
9991
- async function cancelResponseBody$1(response) {
9992
- var _a2;
9993
- try {
9994
- await ((_a2 = response.body) == null ? void 0 : _a2.cancel());
9995
- } catch (e) {}
9996
- }
9997
- var initialGlobalFetch$1 = globalThis.fetch;
9998
- isNodeDefaultFetch$1(initialGlobalFetch$1);
9999
- function isNodeDefaultFetch$1(fetch) {
10000
- if (typeof fetch !== "function") return false;
10001
- const source = Function.prototype.toString.call(fetch);
10002
- return source.includes("internal/deps/undici") || source.includes("lazy loading of undici");
10003
- }
9812
+ });
10004
9813
  function getCurrentModulePath$1() {
10005
9814
  const originalPrepareStackTrace = Error.prepareStackTrace;
10006
9815
  try {
@@ -10015,50 +9824,6 @@ function getCurrentModulePath$1() {
10015
9824
  Error.prepareStackTrace = originalPrepareStackTrace;
10016
9825
  }
10017
9826
  }
10018
- var DEFAULT_MAX_DOWNLOAD_SIZE$1 = 2 * 1024 * 1024 * 1024;
10019
- async function readResponseWithSizeLimit$1({ response, url, maxBytes = DEFAULT_MAX_DOWNLOAD_SIZE$1 }) {
10020
- const contentLength = response.headers.get("content-length");
10021
- if (contentLength != null) {
10022
- const length = parseInt(contentLength, 10);
10023
- if (!isNaN(length) && length > maxBytes) {
10024
- await cancelResponseBody$1(response);
10025
- throw new DownloadError$1({
10026
- url,
10027
- message: `Download of ${url} exceeded maximum size of ${maxBytes} bytes (Content-Length: ${length}).`
10028
- });
10029
- }
10030
- }
10031
- const body = response.body;
10032
- if (body == null) return /* @__PURE__ */ new Uint8Array(0);
10033
- const reader = body.getReader();
10034
- const chunks = [];
10035
- let totalBytes = 0;
10036
- try {
10037
- while (true) {
10038
- const { done, value } = await reader.read();
10039
- if (done) break;
10040
- totalBytes += value.length;
10041
- if (totalBytes > maxBytes) throw new DownloadError$1({
10042
- url,
10043
- message: `Download of ${url} exceeded maximum size of ${maxBytes} bytes.`
10044
- });
10045
- chunks.push(value);
10046
- }
10047
- } finally {
10048
- try {
10049
- await reader.cancel();
10050
- } catch (e) {} finally {
10051
- reader.releaseLock();
10052
- }
10053
- }
10054
- const result = new Uint8Array(totalBytes);
10055
- let offset = 0;
10056
- for (const chunk of chunks) {
10057
- result.set(chunk, offset);
10058
- offset += chunk.length;
10059
- }
10060
- return result;
10061
- }
10062
9827
  var createIdGenerator$2 = ({ prefix, size = 16, alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", separator = "-" } = {}) => {
10063
9828
  const generator = () => {
10064
9829
  const alphabetLength = alphabet.length;
@@ -10067,166 +9832,13 @@ var createIdGenerator$2 = ({ prefix, size = 16, alphabet = "0123456789ABCDEFGHIJ
10067
9832
  return chars.join("");
10068
9833
  };
10069
9834
  if (prefix == null) return generator;
10070
- if (alphabet.includes(separator)) throw new InvalidArgumentError$1$3({
9835
+ if (alphabet.includes(separator)) throw new InvalidArgumentError$2({
10071
9836
  argument: "separator",
10072
9837
  message: `The separator "${separator}" must not be part of the alphabet "${alphabet}".`
10073
9838
  });
10074
9839
  return () => `${prefix}${separator}${generator()}`;
10075
9840
  };
10076
9841
  createIdGenerator$2();
10077
- function isAbortError(error) {
10078
- return (error instanceof Error || error instanceof DOMException) && (error.name === "AbortError" || error.name === "ResponseAborted" || error.name === "TimeoutError");
10079
- }
10080
- var FETCH_FAILED_ERROR_MESSAGES = ["fetch failed", "failed to fetch"];
10081
- var RETRYABLE_NETWORK_ERROR_CODES = /* @__PURE__ */ new Set([
10082
- "ConnectionRefused",
10083
- "ConnectionClosed",
10084
- "FailedToOpenSocket",
10085
- "ECONNRESET",
10086
- "ECONNREFUSED",
10087
- "ETIMEDOUT",
10088
- "EPIPE",
10089
- "UND_ERR_SOCKET",
10090
- "UND_ERR_HEADERS_TIMEOUT",
10091
- "UND_ERR_BODY_TIMEOUT",
10092
- "UND_ERR_CONNECT_TIMEOUT"
10093
- ]);
10094
- function findNetworkError(error) {
10095
- const visited = /* @__PURE__ */ new Set();
10096
- let current = error;
10097
- while (current instanceof Error && !visited.has(current)) {
10098
- visited.add(current);
10099
- const errorWithCode = current;
10100
- if (typeof errorWithCode.code === "string" && RETRYABLE_NETWORK_ERROR_CODES.has(errorWithCode.code)) return errorWithCode;
10101
- current = current.cause;
10102
- }
10103
- }
10104
- function handleFetchError({ error, url, requestBodyValues }) {
10105
- if (isAbortError(error)) return error;
10106
- if (error instanceof TypeError && FETCH_FAILED_ERROR_MESSAGES.includes(error.message.toLowerCase())) {
10107
- const cause = error.cause;
10108
- if (cause != null) return new APICallError$1$1({
10109
- message: `Cannot connect to API: ${cause.message}`,
10110
- cause,
10111
- url,
10112
- requestBodyValues,
10113
- isRetryable: true
10114
- });
10115
- }
10116
- const networkError = findNetworkError(error);
10117
- if (networkError != null) {
10118
- if (APICallError$1$1.isInstance(error)) return new APICallError$1$1({
10119
- message: error.message,
10120
- cause: error.cause,
10121
- url: error.url,
10122
- requestBodyValues: error.requestBodyValues,
10123
- statusCode: error.statusCode,
10124
- responseHeaders: error.responseHeaders,
10125
- responseBody: error.responseBody,
10126
- data: error.data,
10127
- isRetryable: true
10128
- });
10129
- return new APICallError$1$1({
10130
- message: `Cannot connect to API: ${error instanceof Error ? error.message : networkError.message}`,
10131
- cause: error,
10132
- url,
10133
- requestBodyValues,
10134
- isRetryable: true
10135
- });
10136
- }
10137
- return error;
10138
- }
10139
- function getRuntimeEnvironmentUserAgent$1(globalThisAny = globalThis) {
10140
- var _a2, _b2, _c;
10141
- if (globalThisAny.window) return `runtime/browser`;
10142
- if ((_a2 = globalThisAny.navigator) == null ? void 0 : _a2.userAgent) return `runtime/${globalThisAny.navigator.userAgent.toLowerCase()}`;
10143
- if ((_c = (_b2 = globalThisAny.process) == null ? void 0 : _b2.versions) == null ? void 0 : _c.node) return `runtime/node.js/${globalThisAny.process.version.substring(0)}`;
10144
- if (globalThisAny.EdgeRuntime) return `runtime/vercel-edge`;
10145
- return "runtime/unknown";
10146
- }
10147
- function normalizeHeaders$1(headers) {
10148
- if (headers == null) return {};
10149
- const normalized = {};
10150
- if (headers instanceof Headers) headers.forEach((value, key) => {
10151
- normalized[key.toLowerCase()] = value;
10152
- });
10153
- else {
10154
- if (!Array.isArray(headers)) headers = Object.entries(headers);
10155
- for (const [key, value] of headers) if (value != null) normalized[key.toLowerCase()] = value;
10156
- }
10157
- return normalized;
10158
- }
10159
- function withUserAgentSuffix$1(headers, ...userAgentSuffixParts) {
10160
- const normalizedHeaders = new Headers(normalizeHeaders$1(headers));
10161
- const currentUserAgentHeader = normalizedHeaders.get("user-agent") || "";
10162
- normalizedHeaders.set("user-agent", [currentUserAgentHeader, ...userAgentSuffixParts].filter(Boolean).join(" "));
10163
- return Object.fromEntries(normalizedHeaders.entries());
10164
- }
10165
- var VERSION$4 = "3.0.40";
10166
- var getOriginalFetch = () => globalThis.fetch;
10167
- var getFromApi = async ({ url, headers = {}, successfulResponseHandler, failedResponseHandler, abortSignal, fetch = getOriginalFetch() }) => {
10168
- try {
10169
- const response = await fetch(url, {
10170
- method: "GET",
10171
- headers: withUserAgentSuffix$1(headers, `ai-sdk/provider-utils/${VERSION$4}`, getRuntimeEnvironmentUserAgent$1()),
10172
- signal: abortSignal
10173
- });
10174
- const responseHeaders = extractResponseHeaders(response);
10175
- if (!response.ok) {
10176
- let errorInformation;
10177
- try {
10178
- errorInformation = await failedResponseHandler({
10179
- response,
10180
- url,
10181
- requestBodyValues: {}
10182
- });
10183
- } catch (error) {
10184
- if (isAbortError(error) || APICallError$1$1.isInstance(error)) throw error;
10185
- throw new APICallError$1$1({
10186
- message: "Failed to process error response",
10187
- cause: error,
10188
- statusCode: response.status,
10189
- url,
10190
- responseHeaders,
10191
- requestBodyValues: {}
10192
- });
10193
- }
10194
- throw errorInformation.value;
10195
- }
10196
- try {
10197
- return await successfulResponseHandler({
10198
- response,
10199
- url,
10200
- requestBodyValues: {}
10201
- });
10202
- } catch (error) {
10203
- if (error instanceof Error) {
10204
- if (isAbortError(error) || APICallError$1$1.isInstance(error)) throw error;
10205
- }
10206
- throw new APICallError$1$1({
10207
- message: "Failed to process successful response",
10208
- cause: error,
10209
- statusCode: response.status,
10210
- url,
10211
- responseHeaders,
10212
- requestBodyValues: {}
10213
- });
10214
- }
10215
- } catch (error) {
10216
- throw handleFetchError({
10217
- error,
10218
- url,
10219
- requestBodyValues: {}
10220
- });
10221
- }
10222
- };
10223
- function loadOptionalSetting({ settingValue, environmentVariableName }) {
10224
- if (typeof settingValue === "string") return settingValue;
10225
- if (settingValue != null || typeof process === "undefined") return;
10226
- settingValue = process.env[environmentVariableName];
10227
- if (settingValue == null || typeof settingValue !== "string") return;
10228
- return settingValue;
10229
- }
10230
9842
  var suspectProtoRx$1 = /"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/;
10231
9843
  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*:/;
10232
9844
  function _parse$1(text) {
@@ -10274,13 +9886,6 @@ function validator$1(validate) {
10274
9886
  function isValidator$1(value) {
10275
9887
  return typeof value === "object" && value !== null && validatorSymbol$1 in value && value[validatorSymbol$1] === true && "validate" in value;
10276
9888
  }
10277
- function lazyValidator(createValidator) {
10278
- let validator2;
10279
- return () => {
10280
- if (validator2 == null) validator2 = createValidator();
10281
- return validator2;
10282
- };
10283
- }
10284
9889
  function asValidator$1(value) {
10285
9890
  return isValidator$1(value) ? value : "~standard" in value ? standardSchemaValidator(value) : value();
10286
9891
  }
@@ -10292,24 +9897,13 @@ function standardSchemaValidator(standardSchema) {
10292
9897
  value: result.value
10293
9898
  } : {
10294
9899
  success: false,
10295
- error: new TypeValidationError$1$3({
9900
+ error: new TypeValidationError$2({
10296
9901
  value,
10297
9902
  cause: result.issues
10298
9903
  })
10299
9904
  };
10300
9905
  });
10301
9906
  }
10302
- async function validateTypes({ value, schema }) {
10303
- const result = await safeValidateTypes$2({
10304
- value,
10305
- schema
10306
- });
10307
- if (!result.success) throw TypeValidationError$1$3.wrap({
10308
- value,
10309
- cause: result.error
10310
- });
10311
- return result.value;
10312
- }
10313
9907
  async function safeValidateTypes$2({ value, schema }) {
10314
9908
  const validator2 = asValidator$1(schema);
10315
9909
  try {
@@ -10326,7 +9920,7 @@ async function safeValidateTypes$2({ value, schema }) {
10326
9920
  };
10327
9921
  return {
10328
9922
  success: false,
10329
- error: TypeValidationError$1$3.wrap({
9923
+ error: TypeValidationError$2.wrap({
10330
9924
  value,
10331
9925
  cause: result.error
10332
9926
  }),
@@ -10335,7 +9929,7 @@ async function safeValidateTypes$2({ value, schema }) {
10335
9929
  } catch (error) {
10336
9930
  return {
10337
9931
  success: false,
10338
- error: TypeValidationError$1$3.wrap({
9932
+ error: TypeValidationError$2.wrap({
10339
9933
  value,
10340
9934
  cause: error
10341
9935
  }),
@@ -10343,22 +9937,6 @@ async function safeValidateTypes$2({ value, schema }) {
10343
9937
  };
10344
9938
  }
10345
9939
  }
10346
- async function parseJSON({ text, schema }) {
10347
- try {
10348
- const value = secureJsonParse$1(text);
10349
- if (schema == null) return value;
10350
- return validateTypes({
10351
- value,
10352
- schema
10353
- });
10354
- } catch (error) {
10355
- if (JSONParseError$1$3.isInstance(error) || TypeValidationError$1$3.isInstance(error)) throw error;
10356
- throw new JSONParseError$1$3({
10357
- text,
10358
- cause: error
10359
- });
10360
- }
10361
- }
10362
9940
  async function safeParseJSON$2({ text, schema }) {
10363
9941
  try {
10364
9942
  const value = secureJsonParse$1(text);
@@ -10374,7 +9952,7 @@ async function safeParseJSON$2({ text, schema }) {
10374
9952
  } catch (error) {
10375
9953
  return {
10376
9954
  success: false,
10377
- error: JSONParseError$1$3.isInstance(error) ? error : new JSONParseError$1$3({
9955
+ error: JSONParseError$2.isInstance(error) ? error : new JSONParseError$2({
10378
9956
  text,
10379
9957
  cause: error
10380
9958
  }),
@@ -10382,275 +9960,19 @@ async function safeParseJSON$2({ text, schema }) {
10382
9960
  };
10383
9961
  }
10384
9962
  }
10385
- function parseJsonEventStream({ stream, schema }) {
10386
- return stream.pipeThrough(new TextDecoderStream()).pipeThrough(new EventSourceParserStream$1()).pipeThrough(new TransformStream({ async transform({ data }, controller) {
10387
- if (data === "[DONE]") return;
10388
- controller.enqueue(await safeParseJSON$2({
10389
- text: data,
10390
- schema
10391
- }));
10392
- } }));
10393
- }
10394
- var getOriginalFetch2 = () => globalThis.fetch;
10395
- var postJsonToApi = async ({ url, headers, body, failedResponseHandler, successfulResponseHandler, abortSignal, fetch }) => postToApi({
10396
- url,
10397
- headers: {
10398
- "Content-Type": "application/json",
10399
- ...headers
10400
- },
10401
- body: {
10402
- content: JSON.stringify(body),
10403
- values: body
10404
- },
10405
- failedResponseHandler,
10406
- successfulResponseHandler,
10407
- abortSignal,
10408
- fetch
10409
- });
10410
- var postToApi = async ({ url, headers = {}, body, successfulResponseHandler, failedResponseHandler, abortSignal, fetch = getOriginalFetch2() }) => {
10411
- try {
10412
- const response = await fetch(url, {
10413
- method: "POST",
10414
- headers: withUserAgentSuffix$1(headers, `ai-sdk/provider-utils/${VERSION$4}`, getRuntimeEnvironmentUserAgent$1()),
10415
- body: body.content,
10416
- signal: abortSignal
10417
- });
10418
- const responseHeaders = extractResponseHeaders(response);
10419
- if (!response.ok) {
10420
- let errorInformation;
10421
- try {
10422
- errorInformation = await failedResponseHandler({
10423
- response,
10424
- url,
10425
- requestBodyValues: body.values
10426
- });
10427
- } catch (error) {
10428
- if (isAbortError(error) || APICallError$1$1.isInstance(error)) throw error;
10429
- throw new APICallError$1$1({
10430
- message: "Failed to process error response",
10431
- cause: error,
10432
- statusCode: response.status,
10433
- url,
10434
- responseHeaders,
10435
- requestBodyValues: body.values
10436
- });
10437
- }
10438
- throw errorInformation.value;
10439
- }
10440
- try {
10441
- return await successfulResponseHandler({
10442
- response,
10443
- url,
10444
- requestBodyValues: body.values
10445
- });
10446
- } catch (error) {
10447
- if (error instanceof Error) {
10448
- if (isAbortError(error) || APICallError$1$1.isInstance(error)) throw error;
10449
- }
10450
- throw new APICallError$1$1({
10451
- message: "Failed to process successful response",
10452
- cause: error,
10453
- statusCode: response.status,
10454
- url,
10455
- responseHeaders,
10456
- requestBodyValues: body.values
10457
- });
10458
- }
10459
- } catch (error) {
10460
- throw handleFetchError({
10461
- error,
10462
- url,
10463
- requestBodyValues: body.values
10464
- });
10465
- }
10466
- };
10467
- function tool(tool2) {
10468
- return tool2;
10469
- }
10470
- function createProviderDefinedToolFactoryWithOutputSchema({ id, name: name2, inputSchema, outputSchema }) {
10471
- return ({ execute, toModelOutput, onInputStart, onInputDelta, onInputAvailable, ...args }) => tool({
10472
- type: "provider-defined",
10473
- id,
10474
- name: name2,
10475
- args,
10476
- inputSchema,
10477
- outputSchema,
10478
- execute,
10479
- toModelOutput,
10480
- onInputStart,
10481
- onInputDelta,
10482
- onInputAvailable
10483
- });
10484
- }
10485
- async function resolve$1(value) {
10486
- if (typeof value === "function") value = value();
10487
- return Promise.resolve(value);
10488
- }
10489
- var textDecoder$1 = new TextDecoder();
10490
- function wrapResponseBodyStream({ stream, url, requestBodyValues, statusCode, responseHeaders }) {
10491
- const reader = stream.getReader();
10492
- let readerReleased = false;
10493
- const releaseReader = () => {
10494
- if (!readerReleased) {
10495
- reader.releaseLock();
10496
- readerReleased = true;
10497
- }
10498
- };
10499
- return new ReadableStream({
10500
- async pull(controller) {
10501
- try {
10502
- const { done, value } = await reader.read();
10503
- if (done) {
10504
- releaseReader();
10505
- controller.close();
10506
- } else controller.enqueue(value);
10507
- } catch (error) {
10508
- releaseReader();
10509
- if (isAbortError(error)) {
10510
- controller.error(error);
10511
- return;
10512
- }
10513
- controller.error(handleFetchError({
10514
- error: new APICallError$1$1({
10515
- message: "Failed to process successful response",
10516
- cause: error,
10517
- statusCode,
10518
- url,
10519
- responseHeaders,
10520
- requestBodyValues
10521
- }),
10522
- url,
10523
- requestBodyValues
10524
- }));
10525
- }
10526
- },
10527
- async cancel(reason) {
10528
- try {
10529
- await reader.cancel(reason);
10530
- } finally {
10531
- releaseReader();
10532
- }
10533
- }
10534
- });
10535
- }
10536
- async function readResponseBodyAsText({ response, url }) {
10537
- return textDecoder$1.decode(await readResponseWithSizeLimit$1({
10538
- response,
10539
- url
10540
- }));
10541
- }
10542
- var createJsonErrorResponseHandler = ({ errorSchema, errorToMessage, isRetryable }) => async ({ response, url, requestBodyValues }) => {
10543
- const responseBody = await readResponseBodyAsText({
10544
- response,
10545
- url
10546
- });
10547
- const responseHeaders = extractResponseHeaders(response);
10548
- if (responseBody.trim() === "") return {
10549
- responseHeaders,
10550
- value: new APICallError$1$1({
10551
- message: response.statusText,
10552
- url,
10553
- requestBodyValues,
10554
- statusCode: response.status,
10555
- responseHeaders,
10556
- responseBody,
10557
- isRetryable: isRetryable == null ? void 0 : isRetryable(response)
10558
- })
10559
- };
10560
- try {
10561
- const parsedError = await parseJSON({
10562
- text: responseBody,
10563
- schema: errorSchema
10564
- });
10565
- return {
10566
- responseHeaders,
10567
- value: new APICallError$1$1({
10568
- message: errorToMessage(parsedError),
10569
- url,
10570
- requestBodyValues,
10571
- statusCode: response.status,
10572
- responseHeaders,
10573
- responseBody,
10574
- data: parsedError,
10575
- isRetryable: isRetryable == null ? void 0 : isRetryable(response, parsedError)
10576
- })
10577
- };
10578
- } catch (parseError) {
10579
- return {
10580
- responseHeaders,
10581
- value: new APICallError$1$1({
10582
- message: response.statusText,
10583
- url,
10584
- requestBodyValues,
10585
- statusCode: response.status,
10586
- responseHeaders,
10587
- responseBody,
10588
- isRetryable: isRetryable == null ? void 0 : isRetryable(response)
10589
- })
10590
- };
10591
- }
10592
- };
10593
- var createEventSourceResponseHandler = (chunkSchema) => async ({ response, url, requestBodyValues }) => {
10594
- const responseHeaders = extractResponseHeaders(response);
10595
- if (response.body == null) throw new EmptyResponseBodyError$1$1({});
10596
- return {
10597
- responseHeaders,
10598
- value: parseJsonEventStream({
10599
- stream: wrapResponseBodyStream({
10600
- stream: response.body,
10601
- url,
10602
- requestBodyValues,
10603
- statusCode: response.status,
10604
- responseHeaders
10605
- }),
10606
- schema: chunkSchema
10607
- })
10608
- };
10609
- };
10610
- var createJsonResponseHandler = (responseSchema) => async ({ response, url, requestBodyValues }) => {
10611
- const responseBody = await readResponseBodyAsText({
10612
- response,
10613
- url
10614
- });
10615
- const parsedResult = await safeParseJSON$2({
10616
- text: responseBody,
10617
- schema: responseSchema
10618
- });
10619
- const responseHeaders = extractResponseHeaders(response);
10620
- if (!parsedResult.success) throw new APICallError$1$1({
10621
- message: "Invalid JSON response",
10622
- cause: parsedResult.error,
10623
- statusCode: response.status,
10624
- responseHeaders,
10625
- responseBody,
10626
- url,
10627
- requestBodyValues
10628
- });
10629
- return {
10630
- responseHeaders,
10631
- value: parsedResult.value,
10632
- rawValue: parsedResult.rawValue
10633
- };
10634
- };
10635
- var schemaSymbol$2 = /* @__PURE__ */ Symbol.for("vercel.ai.schema");
10636
- function lazySchema$1(createSchema) {
10637
- let schema;
10638
- return () => {
10639
- if (schema == null) schema = createSchema();
10640
- return schema;
10641
- };
10642
- }
10643
- function jsonSchema$2(jsonSchema2, { validate } = {}) {
10644
- return {
10645
- [schemaSymbol$2]: true,
10646
- _type: void 0,
10647
- [validatorSymbol$1]: true,
10648
- get jsonSchema() {
10649
- if (typeof jsonSchema2 === "function") jsonSchema2 = jsonSchema2();
10650
- return jsonSchema2;
10651
- },
10652
- validate
10653
- };
9963
+ new TextDecoder();
9964
+ var schemaSymbol$2 = /* @__PURE__ */ Symbol.for("vercel.ai.schema");
9965
+ function jsonSchema$2(jsonSchema2, { validate } = {}) {
9966
+ return {
9967
+ [schemaSymbol$2]: true,
9968
+ _type: void 0,
9969
+ [validatorSymbol$1]: true,
9970
+ get jsonSchema() {
9971
+ if (typeof jsonSchema2 === "function") jsonSchema2 = jsonSchema2();
9972
+ return jsonSchema2;
9973
+ },
9974
+ validate
9975
+ };
10654
9976
  }
10655
9977
  function addAdditionalPropertiesToJsonSchema$1(jsonSchema2) {
10656
9978
  if (jsonSchema2.type === "object") {
@@ -11425,1560 +10747,181 @@ var selectParser$2 = (def, typeName, refs) => {
11425
10747
  case ZodFirstPartyTypeKind.ZodReadonly: return parseReadonlyDef$2(def, refs);
11426
10748
  case ZodFirstPartyTypeKind.ZodCatch: return parseCatchDef$2(def, refs);
11427
10749
  case ZodFirstPartyTypeKind.ZodPipeline: return parsePipelineDef$2(def, refs);
11428
- case ZodFirstPartyTypeKind.ZodFunction:
11429
- case ZodFirstPartyTypeKind.ZodVoid:
11430
- case ZodFirstPartyTypeKind.ZodSymbol: return;
11431
- default: return /* @__PURE__ */ ((_) => void 0)(typeName);
11432
- }
11433
- };
11434
- var getRelativePath$2 = (pathA, pathB) => {
11435
- let i = 0;
11436
- for (; i < pathA.length && i < pathB.length; i++) if (pathA[i] !== pathB[i]) break;
11437
- return [(pathA.length - i).toString(), ...pathB.slice(i)].join("/");
11438
- };
11439
- function parseDef$2(def, refs, forceResolution = false) {
11440
- var _a2;
11441
- const seenItem = refs.seen.get(def);
11442
- if (refs.override) {
11443
- const overrideResult = (_a2 = refs.override) == null ? void 0 : _a2.call(refs, def, refs, seenItem, forceResolution);
11444
- if (overrideResult !== ignoreOverride$2) return overrideResult;
11445
- }
11446
- if (seenItem && !forceResolution) {
11447
- const seenSchema = get$ref$2(seenItem, refs);
11448
- if (seenSchema !== void 0) return seenSchema;
11449
- }
11450
- const newItem = {
11451
- def,
11452
- path: refs.currentPath,
11453
- jsonSchema: void 0
11454
- };
11455
- refs.seen.set(def, newItem);
11456
- const jsonSchemaOrGetter = selectParser$2(def, def.typeName, refs);
11457
- const jsonSchema2 = typeof jsonSchemaOrGetter === "function" ? parseDef$2(jsonSchemaOrGetter(), refs) : jsonSchemaOrGetter;
11458
- if (jsonSchema2) addMeta$2(def, refs, jsonSchema2);
11459
- if (refs.postProcess) {
11460
- const postProcessResult = refs.postProcess(jsonSchema2, def, refs);
11461
- newItem.jsonSchema = jsonSchema2;
11462
- return postProcessResult;
11463
- }
11464
- newItem.jsonSchema = jsonSchema2;
11465
- return jsonSchema2;
11466
- }
11467
- var get$ref$2 = (item, refs) => {
11468
- switch (refs.$refStrategy) {
11469
- case "root": return { $ref: item.path.join("/") };
11470
- case "relative": return { $ref: getRelativePath$2(refs.currentPath, item.path) };
11471
- case "none":
11472
- case "seen":
11473
- if (item.path.length < refs.currentPath.length && item.path.every((value, index) => refs.currentPath[index] === value)) {
11474
- console.warn(`Recursive reference detected at ${refs.currentPath.join("/")}! Defaulting to any`);
11475
- return parseAnyDef$2();
11476
- }
11477
- return refs.$refStrategy === "seen" ? parseAnyDef$2() : void 0;
11478
- }
11479
- };
11480
- var addMeta$2 = (def, refs, jsonSchema2) => {
11481
- if (def.description) jsonSchema2.description = def.description;
11482
- return jsonSchema2;
11483
- };
11484
- var getRefs$2 = (options) => {
11485
- const _options = getDefaultOptions$2(options);
11486
- const currentPath = _options.name !== void 0 ? [
11487
- ..._options.basePath,
11488
- _options.definitionPath,
11489
- _options.name
11490
- ] : _options.basePath;
11491
- return {
11492
- ..._options,
11493
- currentPath,
11494
- propertyPath: void 0,
11495
- seen: new Map(Object.entries(_options.definitions).map(([name2, def]) => [def._def, {
11496
- def: def._def,
11497
- path: [
11498
- ..._options.basePath,
11499
- _options.definitionPath,
11500
- name2
11501
- ],
11502
- jsonSchema: void 0
11503
- }]))
11504
- };
11505
- };
11506
- var zodToJsonSchema$1 = (schema, options) => {
11507
- var _a2;
11508
- const refs = getRefs$2(options);
11509
- let definitions = typeof options === "object" && options.definitions ? Object.entries(options.definitions).reduce((acc, [name3, schema2]) => {
11510
- var _a3;
11511
- return {
11512
- ...acc,
11513
- [name3]: (_a3 = parseDef$2(schema2._def, {
11514
- ...refs,
11515
- currentPath: [
11516
- ...refs.basePath,
11517
- refs.definitionPath,
11518
- name3
11519
- ]
11520
- }, true)) != null ? _a3 : parseAnyDef$2()
11521
- };
11522
- }, {}) : void 0;
11523
- const name2 = typeof options === "string" ? options : (options == null ? void 0 : options.nameStrategy) === "title" ? void 0 : options == null ? void 0 : options.name;
11524
- const main = (_a2 = parseDef$2(schema._def, name2 === void 0 ? refs : {
11525
- ...refs,
11526
- currentPath: [
11527
- ...refs.basePath,
11528
- refs.definitionPath,
11529
- name2
11530
- ]
11531
- }, false)) != null ? _a2 : parseAnyDef$2();
11532
- const title = typeof options === "object" && options.name !== void 0 && options.nameStrategy === "title" ? options.name : void 0;
11533
- if (title !== void 0) main.title = title;
11534
- const combined = name2 === void 0 ? definitions ? {
11535
- ...main,
11536
- [refs.definitionPath]: definitions
11537
- } : main : {
11538
- $ref: [
11539
- ...refs.$refStrategy === "relative" ? [] : refs.basePath,
11540
- refs.definitionPath,
11541
- name2
11542
- ].join("/"),
11543
- [refs.definitionPath]: {
11544
- ...definitions,
11545
- [name2]: main
11546
- }
11547
- };
11548
- combined.$schema = "http://json-schema.org/draft-07/schema#";
11549
- return combined;
11550
- };
11551
- var zod_to_json_schema_default = zodToJsonSchema$1;
11552
- function zod3Schema$1(zodSchema2, options) {
11553
- var _a2;
11554
- const useReferences = (_a2 = options == null ? void 0 : options.useReferences) != null ? _a2 : false;
11555
- return jsonSchema$2(() => zod_to_json_schema_default(zodSchema2, { $refStrategy: useReferences ? "root" : "none" }), { validate: async (value) => {
11556
- const result = await zodSchema2.safeParseAsync(value);
11557
- return result.success ? {
11558
- success: true,
11559
- value: result.data
11560
- } : {
11561
- success: false,
11562
- error: result.error
11563
- };
11564
- } });
11565
- }
11566
- function zod4Schema$1(zodSchema2, options) {
11567
- var _a2;
11568
- const useReferences = (_a2 = options == null ? void 0 : options.useReferences) != null ? _a2 : false;
11569
- return jsonSchema$2(() => addAdditionalPropertiesToJsonSchema$1(toJSONSchema(zodSchema2, {
11570
- target: "draft-7",
11571
- io: "input",
11572
- reused: useReferences ? "ref" : "inline"
11573
- })), { validate: async (value) => {
11574
- const result = await safeParseAsync(zodSchema2, value);
11575
- return result.success ? {
11576
- success: true,
11577
- value: result.data
11578
- } : {
11579
- success: false,
11580
- error: result.error
11581
- };
11582
- } });
11583
- }
11584
- function isZod4Schema$1(zodSchema2) {
11585
- return "_zod" in zodSchema2;
11586
- }
11587
- function zodSchema$2(zodSchema2, options) {
11588
- if (isZod4Schema$1(zodSchema2)) return zod4Schema$1(zodSchema2, options);
11589
- else return zod3Schema$1(zodSchema2, options);
11590
- }
11591
- function isSchema$2(value) {
11592
- return typeof value === "object" && value !== null && schemaSymbol$2 in value && value[schemaSymbol$2] === true && "jsonSchema" in value && "validate" in value;
11593
- }
11594
- function asSchema$2(schema) {
11595
- return schema == null ? jsonSchema$2({
11596
- properties: {},
11597
- additionalProperties: false
11598
- }) : isSchema$2(schema) ? schema : typeof schema === "function" ? schema() : zodSchema$2(schema);
11599
- }
11600
- var { btoa: btoa$3, atob: atob$3 } = globalThis;
11601
- function withoutTrailingSlash(url) {
11602
- return url == null ? void 0 : url.replace(/\/$/, "");
11603
- }
11604
- var marker$7 = "vercel.ai.error";
11605
- var symbol$9 = Symbol.for(marker$7);
11606
- var _a$9;
11607
- var _b$5;
11608
- var AISDKError$4 = class _AISDKError extends (_b$5 = Error, _a$9 = symbol$9, _b$5) {
11609
- /**
11610
- * Creates an AI SDK Error.
11611
- *
11612
- * @param {Object} params - The parameters for creating the error.
11613
- * @param {string} params.name - The name of the error.
11614
- * @param {string} params.message - The error message.
11615
- * @param {unknown} [params.cause] - The underlying cause of the error.
11616
- */
11617
- constructor({ name: name14, message, cause }) {
11618
- super(message);
11619
- this[_a$9] = true;
11620
- this.name = name14;
11621
- this.cause = cause;
11622
- }
11623
- /**
11624
- * Checks if the given error is an AI SDK Error.
11625
- * @param {unknown} error - The error to check.
11626
- * @returns {boolean} True if the error is an AI SDK Error, false otherwise.
11627
- */
11628
- static isInstance(error) {
11629
- return _AISDKError.hasMarker(error, marker$7);
11630
- }
11631
- static hasMarker(error, marker15) {
11632
- const markerSymbol = Symbol.for(marker15);
11633
- return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
11634
- }
11635
- };
11636
- var name$9 = "AI_APICallError";
11637
- var marker2$5 = `vercel.ai.error.${name$9}`;
11638
- var symbol2$5 = Symbol.for(marker2$5);
11639
- var _a2$5;
11640
- var _b2$4;
11641
- var APICallError$2 = class extends (_b2$4 = AISDKError$4, _a2$5 = symbol2$5, _b2$4) {
11642
- constructor({ message, url, requestBodyValues, statusCode, responseHeaders, responseBody, cause, isRetryable = statusCode != null && (statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500), data }) {
11643
- super({
11644
- name: name$9,
11645
- message,
11646
- cause
11647
- });
11648
- this[_a2$5] = true;
11649
- this.url = url;
11650
- this.requestBodyValues = requestBodyValues;
11651
- this.statusCode = statusCode;
11652
- this.responseHeaders = responseHeaders;
11653
- this.responseBody = responseBody;
11654
- this.isRetryable = isRetryable;
11655
- this.data = data;
11656
- }
11657
- static isInstance(error) {
11658
- return AISDKError$4.hasMarker(error, marker2$5);
11659
- }
11660
- };
11661
- var name2$5 = "AI_EmptyResponseBodyError";
11662
- var marker3$5 = `vercel.ai.error.${name2$5}`;
11663
- var symbol3$5 = Symbol.for(marker3$5);
11664
- var _a3$5;
11665
- var _b3$4;
11666
- (class extends (_b3$4 = AISDKError$4, _a3$5 = symbol3$5, _b3$4) {
11667
- constructor({ message = "Empty response body" } = {}) {
11668
- super({
11669
- name: name2$5,
11670
- message
11671
- });
11672
- this[_a3$5] = true;
11673
- }
11674
- static isInstance(error) {
11675
- return AISDKError$4.hasMarker(error, marker3$5);
11676
- }
11677
- });
11678
- function getErrorMessage$3(error) {
11679
- if (error == null) return "unknown error";
11680
- if (typeof error === "string") return error;
11681
- if (error instanceof Error) return error.message;
11682
- return JSON.stringify(error);
11683
- }
11684
- var name3$5 = "AI_InvalidArgumentError";
11685
- var marker4$5 = `vercel.ai.error.${name3$5}`;
11686
- var symbol4$5 = Symbol.for(marker4$5);
11687
- var _a4$5;
11688
- var _b4$4;
11689
- (class extends (_b4$4 = AISDKError$4, _a4$5 = symbol4$5, _b4$4) {
11690
- constructor({ message, cause, argument }) {
11691
- super({
11692
- name: name3$5,
11693
- message,
11694
- cause
11695
- });
11696
- this[_a4$5] = true;
11697
- this.argument = argument;
11698
- }
11699
- static isInstance(error) {
11700
- return AISDKError$4.hasMarker(error, marker4$5);
11701
- }
11702
- });
11703
- var name4$5 = "AI_InvalidPromptError";
11704
- var marker5$5 = `vercel.ai.error.${name4$5}`;
11705
- var symbol5$5 = Symbol.for(marker5$5);
11706
- var _a5$5;
11707
- var _b5$4;
11708
- (class extends (_b5$4 = AISDKError$4, _a5$5 = symbol5$5, _b5$4) {
11709
- constructor({ prompt, message, cause }) {
11710
- super({
11711
- name: name4$5,
11712
- message: `Invalid prompt: ${message}`,
11713
- cause
11714
- });
11715
- this[_a5$5] = true;
11716
- this.prompt = prompt;
11717
- }
11718
- static isInstance(error) {
11719
- return AISDKError$4.hasMarker(error, marker5$5);
11720
- }
11721
- });
11722
- var name5$5 = "AI_InvalidResponseDataError";
11723
- var marker6$5 = `vercel.ai.error.${name5$5}`;
11724
- var symbol6$5 = Symbol.for(marker6$5);
11725
- var _a6$5;
11726
- var _b6$4;
11727
- (class extends (_b6$4 = AISDKError$4, _a6$5 = symbol6$5, _b6$4) {
11728
- constructor({ data, message = `Invalid response data: ${JSON.stringify(data)}.` }) {
11729
- super({
11730
- name: name5$5,
11731
- message
11732
- });
11733
- this[_a6$5] = true;
11734
- this.data = data;
11735
- }
11736
- static isInstance(error) {
11737
- return AISDKError$4.hasMarker(error, marker6$5);
11738
- }
11739
- });
11740
- var name6$5 = "AI_JSONParseError";
11741
- var marker7$5 = `vercel.ai.error.${name6$5}`;
11742
- var symbol7$5 = Symbol.for(marker7$5);
11743
- var _a7$5;
11744
- var _b7$4;
11745
- (class extends (_b7$4 = AISDKError$4, _a7$5 = symbol7$5, _b7$4) {
11746
- constructor({ text, cause }) {
11747
- super({
11748
- name: name6$5,
11749
- message: `JSON parsing failed: Text: ${text}.
11750
- Error message: ${getErrorMessage$3(cause)}`,
11751
- cause
11752
- });
11753
- this[_a7$5] = true;
11754
- this.text = text;
11755
- }
11756
- static isInstance(error) {
11757
- return AISDKError$4.hasMarker(error, marker7$5);
11758
- }
11759
- });
11760
- var name7$5 = "AI_LoadAPIKeyError";
11761
- var marker8$5 = `vercel.ai.error.${name7$5}`;
11762
- var symbol8$5 = Symbol.for(marker8$5);
11763
- var _a8$5;
11764
- var _b8$4;
11765
- (class extends (_b8$4 = AISDKError$4, _a8$5 = symbol8$5, _b8$4) {
11766
- constructor({ message }) {
11767
- super({
11768
- name: name7$5,
11769
- message
11770
- });
11771
- this[_a8$5] = true;
11772
- }
11773
- static isInstance(error) {
11774
- return AISDKError$4.hasMarker(error, marker8$5);
11775
- }
11776
- });
11777
- var name8$4 = "AI_LoadSettingError";
11778
- var marker9$4 = `vercel.ai.error.${name8$4}`;
11779
- var symbol9$4 = Symbol.for(marker9$4);
11780
- var _a9$4;
11781
- var _b9$4;
11782
- (class extends (_b9$4 = AISDKError$4, _a9$4 = symbol9$4, _b9$4) {
11783
- constructor({ message }) {
11784
- super({
11785
- name: name8$4,
11786
- message
11787
- });
11788
- this[_a9$4] = true;
11789
- }
11790
- static isInstance(error) {
11791
- return AISDKError$4.hasMarker(error, marker9$4);
11792
- }
11793
- });
11794
- var name9$7 = "AI_NoContentGeneratedError";
11795
- var marker10$7 = `vercel.ai.error.${name9$7}`;
11796
- var symbol10$7 = Symbol.for(marker10$7);
11797
- var _a10$7;
11798
- var _b10$2;
11799
- (class extends (_b10$2 = AISDKError$4, _a10$7 = symbol10$7, _b10$2) {
11800
- constructor({ message = "No content generated." } = {}) {
11801
- super({
11802
- name: name9$7,
11803
- message
11804
- });
11805
- this[_a10$7] = true;
11806
- }
11807
- static isInstance(error) {
11808
- return AISDKError$4.hasMarker(error, marker10$7);
11809
- }
11810
- });
11811
- var name10$7 = "AI_NoSuchModelError";
11812
- var marker11$7 = `vercel.ai.error.${name10$7}`;
11813
- var symbol11$7 = Symbol.for(marker11$7);
11814
- var _a11$7;
11815
- var _b11$2;
11816
- var NoSuchModelError$2 = class extends (_b11$2 = AISDKError$4, _a11$7 = symbol11$7, _b11$2) {
11817
- constructor({ errorName = name10$7, modelId, modelType, message = `No such ${modelType}: ${modelId}` }) {
11818
- super({
11819
- name: errorName,
11820
- message
11821
- });
11822
- this[_a11$7] = true;
11823
- this.modelId = modelId;
11824
- this.modelType = modelType;
11825
- }
11826
- static isInstance(error) {
11827
- return AISDKError$4.hasMarker(error, marker11$7);
11828
- }
11829
- };
11830
- var name11$6 = "AI_TooManyEmbeddingValuesForCallError";
11831
- var marker12$6 = `vercel.ai.error.${name11$6}`;
11832
- var symbol12$6 = Symbol.for(marker12$6);
11833
- var _a12$6;
11834
- var _b12$2;
11835
- (class extends (_b12$2 = AISDKError$4, _a12$6 = symbol12$6, _b12$2) {
11836
- constructor(options) {
11837
- super({
11838
- name: name11$6,
11839
- 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.`
11840
- });
11841
- this[_a12$6] = true;
11842
- this.provider = options.provider;
11843
- this.modelId = options.modelId;
11844
- this.maxEmbeddingsPerCall = options.maxEmbeddingsPerCall;
11845
- this.values = options.values;
11846
- }
11847
- static isInstance(error) {
11848
- return AISDKError$4.hasMarker(error, marker12$6);
11849
- }
11850
- });
11851
- var name12$7 = "AI_TypeValidationError";
11852
- var marker13$7 = `vercel.ai.error.${name12$7}`;
11853
- var symbol13$7 = Symbol.for(marker13$7);
11854
- var _a13$7;
11855
- var _b13$2;
11856
- (class _TypeValidationError extends (_b13$2 = AISDKError$4, _a13$7 = symbol13$7, _b13$2) {
11857
- constructor({ value, cause }) {
11858
- super({
11859
- name: name12$7,
11860
- message: `Type validation failed: Value: ${JSON.stringify(value)}.
11861
- Error message: ${getErrorMessage$3(cause)}`,
11862
- cause
11863
- });
11864
- this[_a13$7] = true;
11865
- this.value = value;
11866
- }
11867
- static isInstance(error) {
11868
- return AISDKError$4.hasMarker(error, marker13$7);
11869
- }
11870
- /**
11871
- * Wraps an error into a TypeValidationError.
11872
- * If the cause is already a TypeValidationError with the same value, it returns the cause.
11873
- * Otherwise, it creates a new TypeValidationError.
11874
- *
11875
- * @param {Object} params - The parameters for wrapping the error.
11876
- * @param {unknown} params.value - The value that failed validation.
11877
- * @param {unknown} params.cause - The original error or cause of the validation failure.
11878
- * @returns {TypeValidationError} A TypeValidationError instance.
11879
- */
11880
- static wrap({ value, cause }) {
11881
- return _TypeValidationError.isInstance(cause) && cause.value === value ? cause : new _TypeValidationError({
11882
- value,
11883
- cause
11884
- });
11885
- }
11886
- });
11887
- var name13$7 = "AI_UnsupportedFunctionalityError";
11888
- var marker14$7 = `vercel.ai.error.${name13$7}`;
11889
- var symbol14$7 = Symbol.for(marker14$7);
11890
- var _a14$7;
11891
- var _b14$2;
11892
- (class extends (_b14$2 = AISDKError$4, _a14$7 = symbol14$7, _b14$2) {
11893
- constructor({ functionality, message = `'${functionality}' functionality not supported.` }) {
11894
- super({
11895
- name: name13$7,
11896
- message
11897
- });
11898
- this[_a14$7] = true;
11899
- this.functionality = functionality;
11900
- }
11901
- static isInstance(error) {
11902
- return AISDKError$4.hasMarker(error, marker14$7);
11903
- }
11904
- });
11905
- //#endregion
11906
- //#region ../_vendored/ai_v5/dist/index.js
11907
- function getContext() {
11908
- return { headers: {} };
11909
- }
11910
- async function getVercelOidcToken() {
11911
- if (process.env.VERCEL_OIDC_TOKEN) return process.env.VERCEL_OIDC_TOKEN ?? "";
11912
- throw new Error("@vercel/oidc is not available in the vendored @internal AI packages. Provide an API key instead.");
11913
- }
11914
- var symbol$1$6 = Symbol.for("vercel.ai.gateway.error");
11915
- var _a$1$6;
11916
- var _b$3;
11917
- var GatewayError = class _GatewayError extends (_b$3 = Error, _a$1$6 = symbol$1$6, _b$3) {
11918
- constructor({ message, statusCode = 500, cause }) {
11919
- super(message);
11920
- this[_a$1$6] = true;
11921
- this.statusCode = statusCode;
11922
- this.cause = cause;
11923
- }
11924
- /**
11925
- * Checks if the given error is a Gateway Error.
11926
- * @param {unknown} error - The error to check.
11927
- * @returns {boolean} True if the error is a Gateway Error, false otherwise.
11928
- */
11929
- static isInstance(error) {
11930
- return _GatewayError.hasMarker(error);
11931
- }
11932
- static hasMarker(error) {
11933
- return typeof error === "object" && error !== null && symbol$1$6 in error && error[symbol$1$6] === true;
11934
- }
11935
- };
11936
- var name$1$6 = "GatewayAuthenticationError";
11937
- var marker2$1$5 = `vercel.ai.gateway.error.${name$1$6}`;
11938
- var symbol2$1$5 = Symbol.for(marker2$1$5);
11939
- var _a2$1$5;
11940
- var _b2$2;
11941
- var GatewayAuthenticationError = class _GatewayAuthenticationError extends (_b2$2 = GatewayError, _a2$1$5 = symbol2$1$5, _b2$2) {
11942
- constructor({ message = "Authentication failed", statusCode = 401, cause } = {}) {
11943
- super({
11944
- message,
11945
- statusCode,
11946
- cause
11947
- });
11948
- this[_a2$1$5] = true;
11949
- this.name = name$1$6;
11950
- this.type = "authentication_error";
11951
- }
11952
- static isInstance(error) {
11953
- return GatewayError.hasMarker(error) && symbol2$1$5 in error;
11954
- }
11955
- /**
11956
- * Creates a contextual error message when authentication fails
11957
- */
11958
- static createContextualError({ apiKeyProvided, oidcTokenProvided, message = "Authentication failed", statusCode = 401, cause }) {
11959
- let contextualMessage;
11960
- if (apiKeyProvided) contextualMessage = `AI Gateway authentication failed: Invalid API key.
11961
-
11962
- Create a new API key: https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai%2Fapi-keys
11963
-
11964
- Provide via 'apiKey' option or 'AI_GATEWAY_API_KEY' environment variable.`;
11965
- else if (oidcTokenProvided) contextualMessage = `AI Gateway authentication failed: Invalid OIDC token.
11966
-
11967
- Run 'npx vercel link' to link your project, then 'vc env pull' to fetch the token.
11968
-
11969
- Alternatively, use an API key: https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai%2Fapi-keys`;
11970
- else contextualMessage = `AI Gateway authentication failed: No authentication provided.
11971
-
11972
- Option 1 - API key:
11973
- Create an API key: https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai%2Fapi-keys
11974
- Provide via 'apiKey' option or 'AI_GATEWAY_API_KEY' environment variable.
11975
-
11976
- Option 2 - OIDC token:
11977
- Run 'npx vercel link' to link your project, then 'vc env pull' to fetch the token.`;
11978
- return new _GatewayAuthenticationError({
11979
- message: contextualMessage,
11980
- statusCode,
11981
- cause
11982
- });
11983
- }
11984
- };
11985
- var name2$1$5 = "GatewayForbiddenError";
11986
- var marker3$1$5 = `vercel.ai.gateway.error.${name2$1$5}`;
11987
- var symbol3$1$5 = Symbol.for(marker3$1$5);
11988
- var forbiddenParamSchema = lazyValidator(() => zodSchema$2(object$3({ ruleId: string() })));
11989
- var _a3$1$5;
11990
- var _b3$2;
11991
- var GatewayForbiddenError = class extends (_b3$2 = GatewayError, _a3$1$5 = symbol3$1$5, _b3$2) {
11992
- constructor({ message = "Forbidden", statusCode = 403, cause, ruleId } = {}) {
11993
- super({
11994
- message,
11995
- statusCode,
11996
- cause
11997
- });
11998
- this[_a3$1$5] = true;
11999
- this.name = name2$1$5;
12000
- this.type = "forbidden";
12001
- this.ruleId = ruleId;
12002
- }
12003
- static isInstance(error) {
12004
- return GatewayError.hasMarker(error) && symbol3$1$5 in error;
12005
- }
12006
- };
12007
- var name3$1$5 = "GatewayInvalidRequestError";
12008
- var marker4$1$5 = `vercel.ai.gateway.error.${name3$1$5}`;
12009
- var symbol4$1$5 = Symbol.for(marker4$1$5);
12010
- var _a4$1$5;
12011
- var _b4$2;
12012
- var GatewayInvalidRequestError = class extends (_b4$2 = GatewayError, _a4$1$5 = symbol4$1$5, _b4$2) {
12013
- constructor({ message = "Invalid request", statusCode = 400, cause } = {}) {
12014
- super({
12015
- message,
12016
- statusCode,
12017
- cause
12018
- });
12019
- this[_a4$1$5] = true;
12020
- this.name = name3$1$5;
12021
- this.type = "invalid_request_error";
12022
- }
12023
- static isInstance(error) {
12024
- return GatewayError.hasMarker(error) && symbol4$1$5 in error;
12025
- }
12026
- };
12027
- var name4$1$5 = "GatewayRateLimitError";
12028
- var marker5$1$5 = `vercel.ai.gateway.error.${name4$1$5}`;
12029
- var symbol5$1$5 = Symbol.for(marker5$1$5);
12030
- var _a5$1$5;
12031
- var _b5$2;
12032
- var GatewayRateLimitError = class extends (_b5$2 = GatewayError, _a5$1$5 = symbol5$1$5, _b5$2) {
12033
- constructor({ message = "Rate limit exceeded", statusCode = 429, cause } = {}) {
12034
- super({
12035
- message,
12036
- statusCode,
12037
- cause
12038
- });
12039
- this[_a5$1$5] = true;
12040
- this.name = name4$1$5;
12041
- this.type = "rate_limit_exceeded";
12042
- }
12043
- static isInstance(error) {
12044
- return GatewayError.hasMarker(error) && symbol5$1$5 in error;
12045
- }
12046
- };
12047
- var name5$1$5 = "GatewayModelNotFoundError";
12048
- var marker6$1$5 = `vercel.ai.gateway.error.${name5$1$5}`;
12049
- var symbol6$1$5 = Symbol.for(marker6$1$5);
12050
- var modelNotFoundParamSchema = lazyValidator(() => zodSchema$2(object$3({ modelId: string() })));
12051
- var _a6$1$5;
12052
- var _b6$2;
12053
- var GatewayModelNotFoundError = class extends (_b6$2 = GatewayError, _a6$1$5 = symbol6$1$5, _b6$2) {
12054
- constructor({ message = "Model not found", statusCode = 404, modelId, cause } = {}) {
12055
- super({
12056
- message,
12057
- statusCode,
12058
- cause
12059
- });
12060
- this[_a6$1$5] = true;
12061
- this.name = name5$1$5;
12062
- this.type = "model_not_found";
12063
- this.modelId = modelId;
12064
- }
12065
- static isInstance(error) {
12066
- return GatewayError.hasMarker(error) && symbol6$1$5 in error;
12067
- }
12068
- };
12069
- var name6$1$5 = "GatewayInternalServerError";
12070
- var marker7$1$5 = `vercel.ai.gateway.error.${name6$1$5}`;
12071
- var symbol7$1$5 = Symbol.for(marker7$1$5);
12072
- var _a7$1$5;
12073
- var _b7$2;
12074
- var GatewayInternalServerError = class extends (_b7$2 = GatewayError, _a7$1$5 = symbol7$1$5, _b7$2) {
12075
- constructor({ message = "Internal server error", statusCode = 500, cause } = {}) {
12076
- super({
12077
- message,
12078
- statusCode,
12079
- cause
12080
- });
12081
- this[_a7$1$5] = true;
12082
- this.name = name6$1$5;
12083
- this.type = "internal_server_error";
12084
- }
12085
- static isInstance(error) {
12086
- return GatewayError.hasMarker(error) && symbol7$1$5 in error;
12087
- }
12088
- };
12089
- var name7$1$5 = "GatewayResponseError";
12090
- var marker8$1$5 = `vercel.ai.gateway.error.${name7$1$5}`;
12091
- var symbol8$1$5 = Symbol.for(marker8$1$5);
12092
- var _a8$1$5;
12093
- var _b8$2;
12094
- var GatewayResponseError = class extends (_b8$2 = GatewayError, _a8$1$5 = symbol8$1$5, _b8$2) {
12095
- constructor({ message = "Invalid response from Gateway", statusCode = 502, response, validationError, cause } = {}) {
12096
- super({
12097
- message,
12098
- statusCode,
12099
- cause
12100
- });
12101
- this[_a8$1$5] = true;
12102
- this.name = name7$1$5;
12103
- this.type = "response_error";
12104
- this.response = response;
12105
- this.validationError = validationError;
12106
- }
12107
- static isInstance(error) {
12108
- return GatewayError.hasMarker(error) && symbol8$1$5 in error;
12109
- }
12110
- };
12111
- async function createGatewayErrorFromResponse({ response, statusCode, defaultMessage = "Gateway request failed", cause, authMethod }) {
12112
- const parseResult = await safeValidateTypes$2({
12113
- value: response,
12114
- schema: gatewayErrorResponseSchema
12115
- });
12116
- if (!parseResult.success) return new GatewayResponseError({
12117
- message: `Invalid error response format: ${defaultMessage}`,
12118
- statusCode,
12119
- response,
12120
- validationError: parseResult.error,
12121
- cause
12122
- });
12123
- const validatedResponse = parseResult.value;
12124
- const errorType = validatedResponse.error.type;
12125
- const message = validatedResponse.error.message;
12126
- switch (errorType) {
12127
- case "authentication_error": return GatewayAuthenticationError.createContextualError({
12128
- apiKeyProvided: authMethod === "api-key",
12129
- oidcTokenProvided: authMethod === "oidc",
12130
- statusCode,
12131
- cause
12132
- });
12133
- case "invalid_request_error": return new GatewayInvalidRequestError({
12134
- message,
12135
- statusCode,
12136
- cause
12137
- });
12138
- case "rate_limit_exceeded": return new GatewayRateLimitError({
12139
- message,
12140
- statusCode,
12141
- cause
12142
- });
12143
- case "model_not_found": {
12144
- const modelResult = await safeValidateTypes$2({
12145
- value: validatedResponse.error.param,
12146
- schema: modelNotFoundParamSchema
12147
- });
12148
- return new GatewayModelNotFoundError({
12149
- message,
12150
- statusCode,
12151
- modelId: modelResult.success ? modelResult.value.modelId : void 0,
12152
- cause
12153
- });
12154
- }
12155
- case "internal_server_error": return new GatewayInternalServerError({
12156
- message,
12157
- statusCode,
12158
- cause
12159
- });
12160
- case "forbidden": {
12161
- const ruleResult = await safeValidateTypes$2({
12162
- value: validatedResponse.error.param,
12163
- schema: forbiddenParamSchema
12164
- });
12165
- return new GatewayForbiddenError({
12166
- message,
12167
- statusCode,
12168
- cause,
12169
- ruleId: ruleResult.success ? ruleResult.value.ruleId : void 0
12170
- });
12171
- }
12172
- default: return new GatewayInternalServerError({
12173
- message,
12174
- statusCode,
12175
- cause
12176
- });
12177
- }
12178
- }
12179
- var gatewayErrorResponseSchema = lazyValidator(() => zodSchema$2(object$3({ error: object$3({
12180
- message: string(),
12181
- type: string().nullish(),
12182
- param: unknown().nullish(),
12183
- code: union([string(), number()]).nullish()
12184
- }) })));
12185
- function extractApiCallResponse(error) {
12186
- if (error.data !== void 0) return error.data;
12187
- if (error.responseBody != null) try {
12188
- return JSON.parse(error.responseBody);
12189
- } catch (e) {
12190
- return error.responseBody;
12191
- }
12192
- return {};
12193
- }
12194
- var name8$1$4 = "GatewayTimeoutError";
12195
- var marker9$1$4 = `vercel.ai.gateway.error.${name8$1$4}`;
12196
- var symbol9$1$4 = Symbol.for(marker9$1$4);
12197
- var _a9$1$4;
12198
- var _b9$2;
12199
- var GatewayTimeoutError = class _GatewayTimeoutError extends (_b9$2 = GatewayError, _a9$1$4 = symbol9$1$4, _b9$2) {
12200
- constructor({ message = "Request timed out", statusCode = 408, cause } = {}) {
12201
- super({
12202
- message,
12203
- statusCode,
12204
- cause
12205
- });
12206
- this[_a9$1$4] = true;
12207
- this.name = name8$1$4;
12208
- this.type = "timeout_error";
12209
- }
12210
- static isInstance(error) {
12211
- return GatewayError.hasMarker(error) && symbol9$1$4 in error;
12212
- }
12213
- /**
12214
- * Creates a helpful timeout error message with troubleshooting guidance
12215
- */
12216
- static createTimeoutError({ originalMessage, statusCode = 408, cause }) {
12217
- const message = `Gateway request timed out: ${originalMessage}
12218
-
12219
- 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`;
12220
- return new _GatewayTimeoutError({
12221
- message,
12222
- statusCode,
12223
- cause
12224
- });
12225
- }
12226
- };
12227
- function isTimeoutError(error) {
12228
- if (!(error instanceof Error)) return false;
12229
- const errorCode = error.code;
12230
- if (typeof errorCode === "string") return [
12231
- "UND_ERR_HEADERS_TIMEOUT",
12232
- "UND_ERR_BODY_TIMEOUT",
12233
- "UND_ERR_CONNECT_TIMEOUT"
12234
- ].includes(errorCode);
12235
- return false;
12236
- }
12237
- async function asGatewayError(error, authMethod) {
12238
- var _a10;
12239
- if (GatewayError.isInstance(error)) return error;
12240
- if (isTimeoutError(error)) return GatewayTimeoutError.createTimeoutError({
12241
- originalMessage: error instanceof Error ? error.message : "Unknown error",
12242
- cause: error
12243
- });
12244
- if (APICallError$2.isInstance(error)) {
12245
- if (error.cause && isTimeoutError(error.cause)) return GatewayTimeoutError.createTimeoutError({
12246
- originalMessage: error.message,
12247
- cause: error
12248
- });
12249
- return await createGatewayErrorFromResponse({
12250
- response: extractApiCallResponse(error),
12251
- statusCode: (_a10 = error.statusCode) != null ? _a10 : 500,
12252
- defaultMessage: "Gateway request failed",
12253
- cause: error,
12254
- authMethod
12255
- });
12256
- }
12257
- return await createGatewayErrorFromResponse({
12258
- response: {},
12259
- statusCode: 500,
12260
- defaultMessage: error instanceof Error ? `Gateway request failed: ${error.message}` : "Unknown Gateway error",
12261
- cause: error,
12262
- authMethod
12263
- });
12264
- }
12265
- var GATEWAY_AUTH_METHOD_HEADER = "ai-gateway-auth-method";
12266
- async function parseAuthMethod(headers) {
12267
- const result = await safeValidateTypes$2({
12268
- value: headers[GATEWAY_AUTH_METHOD_HEADER],
12269
- schema: gatewayAuthMethodSchema
12270
- });
12271
- return result.success ? result.value : void 0;
12272
- }
12273
- var gatewayAuthMethodSchema = lazyValidator(() => zodSchema$2(union([literal("api-key"), literal("oidc")])));
12274
- var KNOWN_MODEL_TYPES = [
12275
- "embedding",
12276
- "image",
12277
- "language"
12278
- ];
12279
- var GatewayFetchMetadata = class {
12280
- constructor(config) {
12281
- this.config = config;
12282
- }
12283
- async getAvailableModels() {
12284
- try {
12285
- const { value } = await getFromApi({
12286
- url: `${this.config.baseURL}/config`,
12287
- headers: await resolve$1(this.config.headers()),
12288
- successfulResponseHandler: createJsonResponseHandler(gatewayAvailableModelsResponseSchema),
12289
- failedResponseHandler: createJsonErrorResponseHandler({
12290
- errorSchema: any(),
12291
- errorToMessage: (data) => data
12292
- }),
12293
- fetch: this.config.fetch
12294
- });
12295
- return value;
12296
- } catch (error) {
12297
- throw await asGatewayError(error);
12298
- }
12299
- }
12300
- async getCredits() {
12301
- try {
12302
- const { value } = await getFromApi({
12303
- url: `${new URL(this.config.baseURL).origin}/v1/credits`,
12304
- headers: await resolve$1(this.config.headers()),
12305
- successfulResponseHandler: createJsonResponseHandler(gatewayCreditsResponseSchema),
12306
- failedResponseHandler: createJsonErrorResponseHandler({
12307
- errorSchema: any(),
12308
- errorToMessage: (data) => data
12309
- }),
12310
- fetch: this.config.fetch
12311
- });
12312
- return value;
12313
- } catch (error) {
12314
- throw await asGatewayError(error);
12315
- }
12316
- }
12317
- };
12318
- var gatewayAvailableModelsResponseSchema = lazyValidator(() => zodSchema$2(object$3({ models: array$1(object$3({
12319
- id: string(),
12320
- name: string(),
12321
- description: string().nullish(),
12322
- pricing: object$3({
12323
- input: string(),
12324
- output: string(),
12325
- input_cache_read: string().nullish(),
12326
- input_cache_write: string().nullish()
12327
- }).transform(({ input, output, input_cache_read, input_cache_write }) => ({
12328
- input,
12329
- output,
12330
- ...input_cache_read ? { cachedInputTokens: input_cache_read } : {},
12331
- ...input_cache_write ? { cacheCreationInputTokens: input_cache_write } : {}
12332
- })).nullish(),
12333
- specification: object$3({
12334
- specificationVersion: literal("v2"),
12335
- provider: string(),
12336
- modelId: string()
12337
- }),
12338
- modelType: string().nullish()
12339
- })).transform((models) => models.filter((m) => m.modelType == null || KNOWN_MODEL_TYPES.includes(m.modelType))) })));
12340
- var gatewayCreditsResponseSchema = lazyValidator(() => zodSchema$2(object$3({
12341
- balance: string(),
12342
- total_used: string()
12343
- }).transform(({ balance, total_used }) => ({
12344
- balance,
12345
- totalUsed: total_used
12346
- }))));
12347
- var GatewaySpendReport = class {
12348
- constructor(config) {
12349
- this.config = config;
12350
- }
12351
- async getSpendReport(params) {
12352
- try {
12353
- const baseUrl = new URL(this.config.baseURL);
12354
- const searchParams = new URLSearchParams();
12355
- searchParams.set("start_date", params.startDate);
12356
- searchParams.set("end_date", params.endDate);
12357
- if (params.groupBy) searchParams.set("group_by", params.groupBy);
12358
- if (params.datePart) searchParams.set("date_part", params.datePart);
12359
- if (params.userId) searchParams.set("user_id", params.userId);
12360
- if (params.model) searchParams.set("model", params.model);
12361
- if (params.provider) searchParams.set("provider", params.provider);
12362
- if (params.credentialType) searchParams.set("credential_type", params.credentialType);
12363
- if (params.tags && params.tags.length > 0) searchParams.set("tags", params.tags.join(","));
12364
- const { value } = await getFromApi({
12365
- url: `${baseUrl.origin}/v1/report?${searchParams.toString()}`,
12366
- headers: await resolve$1(this.config.headers()),
12367
- successfulResponseHandler: createJsonResponseHandler(gatewaySpendReportResponseSchema),
12368
- failedResponseHandler: createJsonErrorResponseHandler({
12369
- errorSchema: any(),
12370
- errorToMessage: (data) => data
12371
- }),
12372
- fetch: this.config.fetch
12373
- });
12374
- return value;
12375
- } catch (error) {
12376
- throw await asGatewayError(error);
12377
- }
12378
- }
12379
- };
12380
- var gatewaySpendReportResponseSchema = lazySchema$1(() => zodSchema$2(object$3({ results: array$1(object$3({
12381
- day: string().optional(),
12382
- hour: string().optional(),
12383
- user: string().optional(),
12384
- model: string().optional(),
12385
- tag: string().optional(),
12386
- provider: string().optional(),
12387
- credential_type: _enum(["byok", "system"]).optional(),
12388
- total_cost: number(),
12389
- market_cost: number().optional(),
12390
- input_tokens: number().optional(),
12391
- output_tokens: number().optional(),
12392
- cached_input_tokens: number().optional(),
12393
- cache_creation_input_tokens: number().optional(),
12394
- reasoning_tokens: number().optional(),
12395
- request_count: number().optional()
12396
- }).transform(({ credential_type, total_cost, market_cost, input_tokens, output_tokens, cached_input_tokens, cache_creation_input_tokens, reasoning_tokens, request_count, ...rest }) => ({
12397
- ...rest,
12398
- ...credential_type !== void 0 ? { credentialType: credential_type } : {},
12399
- totalCost: total_cost,
12400
- ...market_cost !== void 0 ? { marketCost: market_cost } : {},
12401
- ...input_tokens !== void 0 ? { inputTokens: input_tokens } : {},
12402
- ...output_tokens !== void 0 ? { outputTokens: output_tokens } : {},
12403
- ...cached_input_tokens !== void 0 ? { cachedInputTokens: cached_input_tokens } : {},
12404
- ...cache_creation_input_tokens !== void 0 ? { cacheCreationInputTokens: cache_creation_input_tokens } : {},
12405
- ...reasoning_tokens !== void 0 ? { reasoningTokens: reasoning_tokens } : {},
12406
- ...request_count !== void 0 ? { requestCount: request_count } : {}
12407
- }))) })));
12408
- var GatewayGenerationInfoFetcher = class {
12409
- constructor(config) {
12410
- this.config = config;
12411
- }
12412
- async getGenerationInfo(params) {
12413
- try {
12414
- const { value } = await getFromApi({
12415
- url: `${new URL(this.config.baseURL).origin}/v1/generation?id=${encodeURIComponent(params.id)}`,
12416
- headers: await resolve$1(this.config.headers()),
12417
- successfulResponseHandler: createJsonResponseHandler(gatewayGenerationInfoResponseSchema),
12418
- failedResponseHandler: createJsonErrorResponseHandler({
12419
- errorSchema: any(),
12420
- errorToMessage: (data) => data
12421
- }),
12422
- fetch: this.config.fetch
12423
- });
12424
- return value;
12425
- } catch (error) {
12426
- throw await asGatewayError(error);
12427
- }
12428
- }
12429
- };
12430
- var gatewayGenerationInfoResponseSchema = lazySchema$1(() => zodSchema$2(object$3({ data: object$3({
12431
- id: string(),
12432
- total_cost: number(),
12433
- upstream_inference_cost: number(),
12434
- usage: number(),
12435
- created_at: string(),
12436
- model: string(),
12437
- is_byok: boolean(),
12438
- provider_name: string(),
12439
- streamed: boolean(),
12440
- finish_reason: string(),
12441
- latency: number(),
12442
- generation_time: number(),
12443
- native_tokens_prompt: number(),
12444
- native_tokens_completion: number(),
12445
- native_tokens_reasoning: number(),
12446
- native_tokens_cached: number(),
12447
- native_tokens_cache_creation: number(),
12448
- billable_web_search_calls: number()
12449
- }).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 }) => ({
12450
- ...rest,
12451
- totalCost: total_cost,
12452
- upstreamInferenceCost: upstream_inference_cost,
12453
- createdAt: created_at,
12454
- isByok: is_byok,
12455
- providerName: provider_name,
12456
- finishReason: finish_reason,
12457
- generationTime: generation_time,
12458
- promptTokens: native_tokens_prompt,
12459
- completionTokens: native_tokens_completion,
12460
- reasoningTokens: native_tokens_reasoning,
12461
- cachedTokens: native_tokens_cached,
12462
- cacheCreationTokens: native_tokens_cache_creation,
12463
- billableWebSearchCalls: billable_web_search_calls
12464
- })) }).transform(({ data }) => data)));
12465
- var GatewayLanguageModel = class {
12466
- constructor(modelId, config) {
12467
- this.modelId = modelId;
12468
- this.config = config;
12469
- this.specificationVersion = "v2";
12470
- this.supportedUrls = { "*/*": [/.*/] };
12471
- }
12472
- get provider() {
12473
- return this.config.provider;
12474
- }
12475
- async getArgs(options) {
12476
- const { abortSignal: _abortSignal, ...optionsWithoutSignal } = options;
12477
- return {
12478
- args: this.maybeEncodeFileParts(optionsWithoutSignal),
12479
- warnings: []
12480
- };
12481
- }
12482
- async doGenerate(options) {
12483
- const { args, warnings } = await this.getArgs(options);
12484
- const { abortSignal } = options;
12485
- const resolvedHeaders = await resolve$1(this.config.headers());
12486
- try {
12487
- const { responseHeaders, value: responseBody, rawValue: rawResponse } = await postJsonToApi({
12488
- url: this.getUrl(),
12489
- headers: combineHeaders(resolvedHeaders, options.headers, this.getModelConfigHeaders(this.modelId, false), await resolve$1(this.config.o11yHeaders)),
12490
- body: args,
12491
- successfulResponseHandler: createJsonResponseHandler(any()),
12492
- failedResponseHandler: createJsonErrorResponseHandler({
12493
- errorSchema: any(),
12494
- errorToMessage: (data) => data
12495
- }),
12496
- ...abortSignal && { abortSignal },
12497
- fetch: this.config.fetch
12498
- });
12499
- return {
12500
- ...responseBody,
12501
- request: { body: args },
12502
- response: {
12503
- headers: responseHeaders,
12504
- body: rawResponse
12505
- },
12506
- warnings
12507
- };
12508
- } catch (error) {
12509
- throw await asGatewayError(error, await parseAuthMethod(resolvedHeaders));
12510
- }
12511
- }
12512
- async doStream(options) {
12513
- const { args, warnings } = await this.getArgs(options);
12514
- const { abortSignal } = options;
12515
- const resolvedHeaders = await resolve$1(this.config.headers());
12516
- try {
12517
- const { value: response, responseHeaders } = await postJsonToApi({
12518
- url: this.getUrl(),
12519
- headers: combineHeaders(resolvedHeaders, options.headers, this.getModelConfigHeaders(this.modelId, true), await resolve$1(this.config.o11yHeaders)),
12520
- body: args,
12521
- successfulResponseHandler: createEventSourceResponseHandler(any()),
12522
- failedResponseHandler: createJsonErrorResponseHandler({
12523
- errorSchema: any(),
12524
- errorToMessage: (data) => data
12525
- }),
12526
- ...abortSignal && { abortSignal },
12527
- fetch: this.config.fetch
12528
- });
12529
- return {
12530
- stream: response.pipeThrough(new TransformStream({
12531
- start(controller) {
12532
- if (warnings.length > 0) controller.enqueue({
12533
- type: "stream-start",
12534
- warnings
12535
- });
12536
- },
12537
- transform(chunk, controller) {
12538
- if (chunk.success) {
12539
- const streamPart = chunk.value;
12540
- if (streamPart.type === "raw" && !options.includeRawChunks) return;
12541
- if (streamPart.type === "response-metadata" && streamPart.timestamp && typeof streamPart.timestamp === "string") streamPart.timestamp = new Date(streamPart.timestamp);
12542
- controller.enqueue(streamPart);
12543
- } else controller.error(chunk.error);
12544
- }
12545
- })),
12546
- request: { body: args },
12547
- response: { headers: responseHeaders }
12548
- };
12549
- } catch (error) {
12550
- throw await asGatewayError(error, await parseAuthMethod(resolvedHeaders));
12551
- }
12552
- }
12553
- isFilePart(part) {
12554
- return part && typeof part === "object" && "type" in part && part.type === "file";
12555
- }
12556
- /**
12557
- * Encodes file parts in the prompt to base64. Mutates the passed options
12558
- * instance directly to avoid copying the file data.
12559
- * @param options - The options to encode.
12560
- * @returns The options with the file parts encoded.
12561
- */
12562
- maybeEncodeFileParts(options) {
12563
- for (const message of options.prompt) for (const part of message.content) if (this.isFilePart(part)) {
12564
- const filePart = part;
12565
- if (filePart.data instanceof Uint8Array) {
12566
- const buffer = Uint8Array.from(filePart.data);
12567
- const base64Data = Buffer.from(buffer).toString("base64");
12568
- filePart.data = new URL(`data:${filePart.mediaType || "application/octet-stream"};base64,${base64Data}`);
12569
- }
12570
- }
12571
- return options;
12572
- }
12573
- getUrl() {
12574
- return `${this.config.baseURL}/language-model`;
12575
- }
12576
- getModelConfigHeaders(modelId, streaming) {
12577
- return {
12578
- "ai-language-model-specification-version": "2",
12579
- "ai-language-model-id": modelId,
12580
- "ai-language-model-streaming": String(streaming)
12581
- };
12582
- }
12583
- };
12584
- var GatewayEmbeddingModel = class {
12585
- constructor(modelId, config) {
12586
- this.modelId = modelId;
12587
- this.config = config;
12588
- this.specificationVersion = "v2";
12589
- this.maxEmbeddingsPerCall = 2048;
12590
- this.supportsParallelCalls = true;
12591
- }
12592
- get provider() {
12593
- return this.config.provider;
12594
- }
12595
- async doEmbed({ values, headers, abortSignal, providerOptions }) {
12596
- var _a10;
12597
- const resolvedHeaders = await resolve$1(this.config.headers());
12598
- try {
12599
- const { responseHeaders, value: responseBody, rawValue } = await postJsonToApi({
12600
- url: this.getUrl(),
12601
- headers: combineHeaders(resolvedHeaders, headers != null ? headers : {}, this.getModelConfigHeaders(), await resolve$1(this.config.o11yHeaders)),
12602
- body: {
12603
- input: values.length === 1 ? values[0] : values,
12604
- ...providerOptions ? { providerOptions } : {}
12605
- },
12606
- successfulResponseHandler: createJsonResponseHandler(gatewayEmbeddingResponseSchema),
12607
- failedResponseHandler: createJsonErrorResponseHandler({
12608
- errorSchema: any(),
12609
- errorToMessage: (data) => data
12610
- }),
12611
- ...abortSignal && { abortSignal },
12612
- fetch: this.config.fetch
12613
- });
12614
- return {
12615
- embeddings: responseBody.embeddings,
12616
- usage: (_a10 = responseBody.usage) != null ? _a10 : void 0,
12617
- providerMetadata: responseBody.providerMetadata,
12618
- response: {
12619
- headers: responseHeaders,
12620
- body: rawValue
12621
- }
12622
- };
12623
- } catch (error) {
12624
- throw await asGatewayError(error, await parseAuthMethod(resolvedHeaders));
12625
- }
12626
- }
12627
- getUrl() {
12628
- return `${this.config.baseURL}/embedding-model`;
12629
- }
12630
- getModelConfigHeaders() {
12631
- return {
12632
- "ai-embedding-model-specification-version": "2",
12633
- "ai-model-id": this.modelId
12634
- };
10750
+ case ZodFirstPartyTypeKind.ZodFunction:
10751
+ case ZodFirstPartyTypeKind.ZodVoid:
10752
+ case ZodFirstPartyTypeKind.ZodSymbol: return;
10753
+ default: return /* @__PURE__ */ ((_) => void 0)(typeName);
12635
10754
  }
12636
10755
  };
12637
- var gatewayEmbeddingResponseSchema = lazyValidator(() => zodSchema$2(object$3({
12638
- embeddings: array$1(array$1(number())),
12639
- usage: object$3({ tokens: number() }).nullish(),
12640
- providerMetadata: record(string(), record(string(), unknown())).optional()
12641
- })));
12642
- var GatewayImageModel = class {
12643
- constructor(modelId, config) {
12644
- this.modelId = modelId;
12645
- this.config = config;
12646
- this.specificationVersion = "v2";
12647
- this.maxImagesPerCall = Number.MAX_SAFE_INTEGER;
12648
- }
12649
- get provider() {
12650
- return this.config.provider;
10756
+ var getRelativePath$2 = (pathA, pathB) => {
10757
+ let i = 0;
10758
+ for (; i < pathA.length && i < pathB.length; i++) if (pathA[i] !== pathB[i]) break;
10759
+ return [(pathA.length - i).toString(), ...pathB.slice(i)].join("/");
10760
+ };
10761
+ function parseDef$2(def, refs, forceResolution = false) {
10762
+ var _a2;
10763
+ const seenItem = refs.seen.get(def);
10764
+ if (refs.override) {
10765
+ const overrideResult = (_a2 = refs.override) == null ? void 0 : _a2.call(refs, def, refs, seenItem, forceResolution);
10766
+ if (overrideResult !== ignoreOverride$2) return overrideResult;
12651
10767
  }
12652
- async doGenerate({ prompt, n, size, aspectRatio, seed, providerOptions, headers, abortSignal }) {
12653
- var _a10, _b10, _c, _d;
12654
- const resolvedHeaders = await resolve$1(this.config.headers());
12655
- try {
12656
- const { responseHeaders, value: responseBody, rawValue } = await postJsonToApi({
12657
- url: this.getUrl(),
12658
- headers: combineHeaders(resolvedHeaders, headers != null ? headers : {}, this.getModelConfigHeaders(), await resolve$1(this.config.o11yHeaders)),
12659
- body: {
12660
- prompt,
12661
- n,
12662
- ...size && { size },
12663
- ...aspectRatio && { aspectRatio },
12664
- ...seed && { seed },
12665
- ...providerOptions && { providerOptions }
12666
- },
12667
- successfulResponseHandler: createJsonResponseHandler(gatewayImageResponseSchema),
12668
- failedResponseHandler: createJsonErrorResponseHandler({
12669
- errorSchema: any(),
12670
- errorToMessage: (data) => data
12671
- }),
12672
- ...abortSignal && { abortSignal },
12673
- fetch: this.config.fetch
12674
- });
12675
- return {
12676
- images: responseBody.images,
12677
- warnings: (_a10 = responseBody.warnings) != null ? _a10 : [],
12678
- providerMetadata: responseBody.providerMetadata,
12679
- response: {
12680
- timestamp: /* @__PURE__ */ new Date(),
12681
- modelId: this.modelId,
12682
- headers: responseHeaders
12683
- },
12684
- ...responseBody.usage != null && { usage: {
12685
- inputTokens: (_b10 = responseBody.usage.inputTokens) != null ? _b10 : void 0,
12686
- outputTokens: (_c = responseBody.usage.outputTokens) != null ? _c : void 0,
12687
- totalTokens: (_d = responseBody.usage.totalTokens) != null ? _d : void 0
12688
- } }
12689
- };
12690
- } catch (error) {
12691
- throw await asGatewayError(error, await parseAuthMethod(resolvedHeaders));
12692
- }
10768
+ if (seenItem && !forceResolution) {
10769
+ const seenSchema = get$ref$2(seenItem, refs);
10770
+ if (seenSchema !== void 0) return seenSchema;
12693
10771
  }
12694
- getUrl() {
12695
- return `${this.config.baseURL}/image-model`;
10772
+ const newItem = {
10773
+ def,
10774
+ path: refs.currentPath,
10775
+ jsonSchema: void 0
10776
+ };
10777
+ refs.seen.set(def, newItem);
10778
+ const jsonSchemaOrGetter = selectParser$2(def, def.typeName, refs);
10779
+ const jsonSchema2 = typeof jsonSchemaOrGetter === "function" ? parseDef$2(jsonSchemaOrGetter(), refs) : jsonSchemaOrGetter;
10780
+ if (jsonSchema2) addMeta$2(def, refs, jsonSchema2);
10781
+ if (refs.postProcess) {
10782
+ const postProcessResult = refs.postProcess(jsonSchema2, def, refs);
10783
+ newItem.jsonSchema = jsonSchema2;
10784
+ return postProcessResult;
12696
10785
  }
12697
- getModelConfigHeaders() {
12698
- return {
12699
- "ai-image-model-specification-version": "2",
12700
- "ai-model-id": this.modelId
12701
- };
10786
+ newItem.jsonSchema = jsonSchema2;
10787
+ return jsonSchema2;
10788
+ }
10789
+ var get$ref$2 = (item, refs) => {
10790
+ switch (refs.$refStrategy) {
10791
+ case "root": return { $ref: item.path.join("/") };
10792
+ case "relative": return { $ref: getRelativePath$2(refs.currentPath, item.path) };
10793
+ case "none":
10794
+ case "seen":
10795
+ if (item.path.length < refs.currentPath.length && item.path.every((value, index) => refs.currentPath[index] === value)) {
10796
+ console.warn(`Recursive reference detected at ${refs.currentPath.join("/")}! Defaulting to any`);
10797
+ return parseAnyDef$2();
10798
+ }
10799
+ return refs.$refStrategy === "seen" ? parseAnyDef$2() : void 0;
12702
10800
  }
12703
10801
  };
12704
- var providerMetadataEntrySchema = object$3({ images: array$1(unknown()).optional() }).catchall(unknown());
12705
- var gatewayImageUsageSchema = object$3({
12706
- inputTokens: number().nullish(),
12707
- outputTokens: number().nullish(),
12708
- totalTokens: number().nullish()
12709
- });
12710
- var gatewayImageResponseSchema = object$3({
12711
- images: array$1(string()),
12712
- warnings: array$1(object$3({
12713
- type: literal("other"),
12714
- message: string()
12715
- })).optional(),
12716
- providerMetadata: record(string(), providerMetadataEntrySchema).optional(),
12717
- usage: gatewayImageUsageSchema.optional()
12718
- });
12719
- var parallelSearchToolFactory = createProviderDefinedToolFactoryWithOutputSchema({
12720
- id: "gateway.parallel_search",
12721
- name: "parallel_search",
12722
- inputSchema: lazySchema$1(() => zodSchema$2(object$3({
12723
- 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."),
12724
- search_queries: array$1(string()).optional().describe("Optional search queries to supplement the objective. Maximum 200 characters per query."),
12725
- 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."),
12726
- max_results: number().optional().describe("Maximum number of results to return (1-20). Defaults to 10 if not specified."),
12727
- source_policy: object$3({
12728
- include_domains: array$1(string()).optional().describe("List of domains to include in search results."),
12729
- exclude_domains: array$1(string()).optional().describe("List of domains to exclude from search results."),
12730
- after_date: string().optional().describe("Only include results published after this date (ISO 8601 format).")
12731
- }).optional().describe("Source policy for controlling which domains to include/exclude and freshness."),
12732
- excerpts: object$3({
12733
- max_chars_per_result: number().optional().describe("Maximum characters per result."),
12734
- max_chars_total: number().optional().describe("Maximum total characters across all results.")
12735
- }).optional().describe("Excerpt configuration for controlling result length."),
12736
- 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.")
12737
- }))),
12738
- outputSchema: lazySchema$1(() => zodSchema$2(union([object$3({
12739
- searchId: string(),
12740
- results: array$1(object$3({
12741
- url: string(),
12742
- title: string(),
12743
- excerpt: string(),
12744
- publishDate: string().nullable().optional(),
12745
- relevanceScore: number().optional()
12746
- }))
12747
- }), object$3({
12748
- error: _enum([
12749
- "api_error",
12750
- "rate_limit",
12751
- "timeout",
12752
- "invalid_input",
12753
- "configuration_error",
12754
- "unknown"
12755
- ]),
12756
- statusCode: number().optional(),
12757
- message: string()
12758
- })])))
12759
- });
12760
- var parallelSearch = (config = {}) => parallelSearchToolFactory(config);
12761
- var perplexitySearchToolFactory = createProviderDefinedToolFactoryWithOutputSchema({
12762
- id: "gateway.perplexity_search",
12763
- name: "perplexity_search",
12764
- inputSchema: lazySchema$1(() => zodSchema$2(object$3({
12765
- 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."),
12766
- max_results: number().optional().describe("Maximum number of search results to return (1-20, default: 10)"),
12767
- max_tokens_per_page: number().optional().describe("Maximum number of tokens to extract per search result page (256-2048, default: 2048)"),
12768
- max_tokens: number().optional().describe("Maximum total tokens across all search results (default: 25000, max: 1000000)"),
12769
- country: string().optional().describe("Two-letter ISO 3166-1 alpha-2 country code for regional search results (e.g., 'US', 'GB', 'FR')"),
12770
- 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']"),
12771
- 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']"),
12772
- 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."),
12773
- 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."),
12774
- 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."),
12775
- 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."),
12776
- search_recency_filter: _enum([
12777
- "day",
12778
- "week",
12779
- "month",
12780
- "year"
12781
- ]).optional().describe("Filter results by relative time period. Cannot be used with search_after_date or search_before_date.")
12782
- }))),
12783
- outputSchema: lazySchema$1(() => zodSchema$2(union([object$3({
12784
- results: array$1(object$3({
12785
- title: string(),
12786
- url: string(),
12787
- snippet: string(),
12788
- date: string().optional(),
12789
- lastUpdated: string().optional()
12790
- })),
12791
- id: string()
12792
- }), object$3({
12793
- error: _enum([
12794
- "api_error",
12795
- "rate_limit",
12796
- "timeout",
12797
- "invalid_input",
12798
- "unknown"
12799
- ]),
12800
- statusCode: number().optional(),
12801
- message: string()
12802
- })])))
12803
- });
12804
- var perplexitySearch = (config = {}) => perplexitySearchToolFactory(config);
12805
- var gatewayTools = {
12806
- /**
12807
- * Search the web using Parallel AI's Search API for LLM-optimized excerpts.
12808
- *
12809
- * Takes a natural language objective and returns relevant excerpts,
12810
- * replacing multiple keyword searches with a single call for broad
12811
- * or complex queries. Supports different search types for depth vs
12812
- * breadth tradeoffs.
12813
- */
12814
- parallelSearch,
12815
- /**
12816
- * Search the web using Perplexity's Search API for real-time information,
12817
- * news, research papers, and articles.
12818
- *
12819
- * Provides ranked search results with advanced filtering options including
12820
- * domain, language, date range, and recency filters.
12821
- */
12822
- perplexitySearch
12823
- };
12824
- async function getVercelRequestId() {
12825
- var _a10;
12826
- return (_a10 = getContext().headers) == null ? void 0 : _a10["x-vercel-id"];
12827
- }
12828
- var VERSION$2$1 = "2.0.125";
12829
- var AI_GATEWAY_PROTOCOL_VERSION = "0.0.1";
12830
- function createGatewayProvider(options = {}) {
12831
- var _a10, _b10;
12832
- let pendingMetadata = null;
12833
- let metadataCache = null;
12834
- const cacheRefreshMillis = (_a10 = options.metadataCacheRefreshMillis) != null ? _a10 : 1e3 * 60 * 5;
12835
- let lastFetchTime = 0;
12836
- const baseURL = (_b10 = withoutTrailingSlash(options.baseURL)) != null ? _b10 : "https://ai-gateway.vercel.sh/v1/ai";
12837
- const getHeaders = async () => {
12838
- const auth = await getGatewayAuthToken(options);
12839
- if (auth) return withUserAgentSuffix$1({
12840
- Authorization: `Bearer ${auth.token}`,
12841
- "ai-gateway-protocol-version": AI_GATEWAY_PROTOCOL_VERSION,
12842
- [GATEWAY_AUTH_METHOD_HEADER]: auth.authMethod,
12843
- ...options.headers
12844
- }, `ai-sdk/gateway/${VERSION$2$1}`);
12845
- throw GatewayAuthenticationError.createContextualError({
12846
- apiKeyProvided: false,
12847
- oidcTokenProvided: false,
12848
- statusCode: 401
12849
- });
10802
+ var addMeta$2 = (def, refs, jsonSchema2) => {
10803
+ if (def.description) jsonSchema2.description = def.description;
10804
+ return jsonSchema2;
10805
+ };
10806
+ var getRefs$2 = (options) => {
10807
+ const _options = getDefaultOptions$2(options);
10808
+ const currentPath = _options.name !== void 0 ? [
10809
+ ..._options.basePath,
10810
+ _options.definitionPath,
10811
+ _options.name
10812
+ ] : _options.basePath;
10813
+ return {
10814
+ ..._options,
10815
+ currentPath,
10816
+ propertyPath: void 0,
10817
+ seen: new Map(Object.entries(_options.definitions).map(([name2, def]) => [def._def, {
10818
+ def: def._def,
10819
+ path: [
10820
+ ..._options.basePath,
10821
+ _options.definitionPath,
10822
+ name2
10823
+ ],
10824
+ jsonSchema: void 0
10825
+ }]))
12850
10826
  };
12851
- const createO11yHeaders = () => {
12852
- const deploymentId = loadOptionalSetting({
12853
- settingValue: void 0,
12854
- environmentVariableName: "VERCEL_DEPLOYMENT_ID"
12855
- });
12856
- const environment = loadOptionalSetting({
12857
- settingValue: void 0,
12858
- environmentVariableName: "VERCEL_ENV"
12859
- });
12860
- const region = loadOptionalSetting({
12861
- settingValue: void 0,
12862
- environmentVariableName: "VERCEL_REGION"
12863
- });
12864
- const projectId = loadOptionalSetting({
12865
- settingValue: void 0,
12866
- environmentVariableName: "VERCEL_PROJECT_ID"
12867
- });
12868
- return async () => {
12869
- const requestId = await getVercelRequestId();
12870
- return {
12871
- ...deploymentId && { "ai-o11y-deployment-id": deploymentId },
12872
- ...environment && { "ai-o11y-environment": environment },
12873
- ...region && { "ai-o11y-region": region },
12874
- ...requestId && { "ai-o11y-request-id": requestId },
12875
- ...projectId && { "ai-o11y-project-id": projectId }
12876
- };
10827
+ };
10828
+ var zodToJsonSchema$1 = (schema, options) => {
10829
+ var _a2;
10830
+ const refs = getRefs$2(options);
10831
+ let definitions = typeof options === "object" && options.definitions ? Object.entries(options.definitions).reduce((acc, [name3, schema2]) => {
10832
+ var _a3;
10833
+ return {
10834
+ ...acc,
10835
+ [name3]: (_a3 = parseDef$2(schema2._def, {
10836
+ ...refs,
10837
+ currentPath: [
10838
+ ...refs.basePath,
10839
+ refs.definitionPath,
10840
+ name3
10841
+ ]
10842
+ }, true)) != null ? _a3 : parseAnyDef$2()
12877
10843
  };
12878
- };
12879
- const createLanguageModel = (modelId) => {
12880
- return new GatewayLanguageModel(modelId, {
12881
- provider: "gateway",
12882
- baseURL,
12883
- headers: getHeaders,
12884
- fetch: options.fetch,
12885
- o11yHeaders: createO11yHeaders()
12886
- });
12887
- };
12888
- const getAvailableModels = async () => {
12889
- var _a11, _b11, _c;
12890
- const now = (_c = (_b11 = (_a11 = options._internal) == null ? void 0 : _a11.currentDate) == null ? void 0 : _b11.call(_a11).getTime()) != null ? _c : Date.now();
12891
- if (!pendingMetadata || now - lastFetchTime > cacheRefreshMillis) {
12892
- lastFetchTime = now;
12893
- pendingMetadata = new GatewayFetchMetadata({
12894
- baseURL,
12895
- headers: getHeaders,
12896
- fetch: options.fetch
12897
- }).getAvailableModels().then((metadata) => {
12898
- metadataCache = metadata;
12899
- return metadata;
12900
- }).catch(async (error) => {
12901
- throw await asGatewayError(error, await parseAuthMethod(await getHeaders()));
12902
- });
10844
+ }, {}) : void 0;
10845
+ const name2 = typeof options === "string" ? options : (options == null ? void 0 : options.nameStrategy) === "title" ? void 0 : options == null ? void 0 : options.name;
10846
+ const main = (_a2 = parseDef$2(schema._def, name2 === void 0 ? refs : {
10847
+ ...refs,
10848
+ currentPath: [
10849
+ ...refs.basePath,
10850
+ refs.definitionPath,
10851
+ name2
10852
+ ]
10853
+ }, false)) != null ? _a2 : parseAnyDef$2();
10854
+ const title = typeof options === "object" && options.name !== void 0 && options.nameStrategy === "title" ? options.name : void 0;
10855
+ if (title !== void 0) main.title = title;
10856
+ const combined = name2 === void 0 ? definitions ? {
10857
+ ...main,
10858
+ [refs.definitionPath]: definitions
10859
+ } : main : {
10860
+ $ref: [
10861
+ ...refs.$refStrategy === "relative" ? [] : refs.basePath,
10862
+ refs.definitionPath,
10863
+ name2
10864
+ ].join("/"),
10865
+ [refs.definitionPath]: {
10866
+ ...definitions,
10867
+ [name2]: main
12903
10868
  }
12904
- return metadataCache ? Promise.resolve(metadataCache) : pendingMetadata;
12905
10869
  };
12906
- const getCredits = async () => {
12907
- return new GatewayFetchMetadata({
12908
- baseURL,
12909
- headers: getHeaders,
12910
- fetch: options.fetch
12911
- }).getCredits().catch(async (error) => {
12912
- throw await asGatewayError(error, await parseAuthMethod(await getHeaders()));
12913
- });
12914
- };
12915
- const getSpendReport = async (params) => {
12916
- return new GatewaySpendReport({
12917
- baseURL,
12918
- headers: getHeaders,
12919
- fetch: options.fetch
12920
- }).getSpendReport(params).catch(async (error) => {
12921
- throw await asGatewayError(error, await parseAuthMethod(await getHeaders()));
12922
- });
12923
- };
12924
- const getGenerationInfo = async (params) => {
12925
- return new GatewayGenerationInfoFetcher({
12926
- baseURL,
12927
- headers: getHeaders,
12928
- fetch: options.fetch
12929
- }).getGenerationInfo(params).catch(async (error) => {
12930
- throw await asGatewayError(error, await parseAuthMethod(await getHeaders()));
12931
- });
12932
- };
12933
- const provider = function(modelId) {
12934
- if (new.target) throw new Error("The Gateway Provider model function cannot be called with the new keyword.");
12935
- return createLanguageModel(modelId);
12936
- };
12937
- provider.getAvailableModels = getAvailableModels;
12938
- provider.getCredits = getCredits;
12939
- provider.getSpendReport = getSpendReport;
12940
- provider.getGenerationInfo = getGenerationInfo;
12941
- provider.imageModel = (modelId) => {
12942
- return new GatewayImageModel(modelId, {
12943
- provider: "gateway",
12944
- baseURL,
12945
- headers: getHeaders,
12946
- fetch: options.fetch,
12947
- o11yHeaders: createO11yHeaders()
12948
- });
12949
- };
12950
- provider.languageModel = createLanguageModel;
12951
- provider.textEmbeddingModel = (modelId) => {
12952
- return new GatewayEmbeddingModel(modelId, {
12953
- provider: "gateway",
12954
- baseURL,
12955
- headers: getHeaders,
12956
- fetch: options.fetch,
12957
- o11yHeaders: createO11yHeaders()
12958
- });
12959
- };
12960
- provider.tools = gatewayTools;
12961
- return provider;
10870
+ combined.$schema = "http://json-schema.org/draft-07/schema#";
10871
+ return combined;
10872
+ };
10873
+ var zod_to_json_schema_default = zodToJsonSchema$1;
10874
+ function zod3Schema$1(zodSchema2, options) {
10875
+ var _a2;
10876
+ const useReferences = (_a2 = options == null ? void 0 : options.useReferences) != null ? _a2 : false;
10877
+ return jsonSchema$2(() => zod_to_json_schema_default(zodSchema2, { $refStrategy: useReferences ? "root" : "none" }), { validate: async (value) => {
10878
+ const result = await zodSchema2.safeParseAsync(value);
10879
+ return result.success ? {
10880
+ success: true,
10881
+ value: result.data
10882
+ } : {
10883
+ success: false,
10884
+ error: result.error
10885
+ };
10886
+ } });
12962
10887
  }
12963
- createGatewayProvider();
12964
- async function getGatewayAuthToken(options) {
12965
- const apiKey = loadOptionalSetting({
12966
- settingValue: options.apiKey,
12967
- environmentVariableName: "AI_GATEWAY_API_KEY"
12968
- });
12969
- if (apiKey) return {
12970
- token: apiKey,
12971
- authMethod: "api-key"
12972
- };
12973
- try {
12974
- return {
12975
- token: await getVercelOidcToken(),
12976
- authMethod: "oidc"
10888
+ function zod4Schema$1(zodSchema2, options) {
10889
+ var _a2;
10890
+ const useReferences = (_a2 = options == null ? void 0 : options.useReferences) != null ? _a2 : false;
10891
+ return jsonSchema$2(() => addAdditionalPropertiesToJsonSchema$1(toJSONSchema(zodSchema2, {
10892
+ target: "draft-7",
10893
+ io: "input",
10894
+ reused: useReferences ? "ref" : "inline"
10895
+ })), { validate: async (value) => {
10896
+ const result = await safeParseAsync(zodSchema2, value);
10897
+ return result.success ? {
10898
+ success: true,
10899
+ value: result.data
10900
+ } : {
10901
+ success: false,
10902
+ error: result.error
12977
10903
  };
12978
- } catch (e) {
12979
- return null;
12980
- }
10904
+ } });
10905
+ }
10906
+ function isZod4Schema$1(zodSchema2) {
10907
+ return "_zod" in zodSchema2;
10908
+ }
10909
+ function zodSchema$2(zodSchema2, options) {
10910
+ if (isZod4Schema$1(zodSchema2)) return zod4Schema$1(zodSchema2, options);
10911
+ else return zod3Schema$1(zodSchema2, options);
10912
+ }
10913
+ function isSchema$2(value) {
10914
+ return typeof value === "object" && value !== null && schemaSymbol$2 in value && value[schemaSymbol$2] === true && "jsonSchema" in value && "validate" in value;
10915
+ }
10916
+ function asSchema$2(schema) {
10917
+ return schema == null ? jsonSchema$2({
10918
+ properties: {},
10919
+ additionalProperties: false
10920
+ }) : isSchema$2(schema) ? schema : typeof schema === "function" ? schema() : zodSchema$2(schema);
12981
10921
  }
10922
+ var { btoa: btoa$3, atob: atob$5 } = globalThis;
10923
+ //#endregion
10924
+ //#region ../_vendored/ai_v5/dist/index.js
12982
10925
  /** only globals that common to node and browsers are allowed */
12983
10926
  var _globalThis$1 = typeof globalThis === "object" ? globalThis : global;
12984
10927
  var VERSION$1$3 = "1.9.0";
@@ -13771,28 +11714,28 @@ var __export$2 = (target, all) => {
13771
11714
  enumerable: true
13772
11715
  });
13773
11716
  };
13774
- var name6$6 = "AI_NoObjectGeneratedError";
13775
- var marker6$6 = `vercel.ai.error.${name6$6}`;
13776
- var symbol6$6 = Symbol.for(marker6$6);
13777
- var _a6$6;
13778
- var NoObjectGeneratedError$2 = class extends AISDKError$4 {
11717
+ var name6$4 = "AI_NoObjectGeneratedError";
11718
+ var marker6$4 = `vercel.ai.error.${name6$4}`;
11719
+ var symbol6$4 = Symbol.for(marker6$4);
11720
+ var _a6$4;
11721
+ var NoObjectGeneratedError$2 = class extends AISDKError$2 {
13779
11722
  constructor({ message = "No object generated.", cause, text: text2, response, usage, finishReason }) {
13780
11723
  super({
13781
- name: name6$6,
11724
+ name: name6$4,
13782
11725
  message,
13783
11726
  cause
13784
11727
  });
13785
- this[_a6$6] = true;
11728
+ this[_a6$4] = true;
13786
11729
  this.text = text2;
13787
11730
  this.response = response;
13788
11731
  this.usage = usage;
13789
11732
  this.finishReason = finishReason;
13790
11733
  }
13791
11734
  static isInstance(error) {
13792
- return AISDKError$4.hasMarker(error, marker6$6);
11735
+ return AISDKError$2.hasMarker(error, marker6$4);
13793
11736
  }
13794
11737
  };
13795
- _a6$6 = symbol6$6;
11738
+ _a6$4 = symbol6$4;
13796
11739
  var dataContentSchema$2 = union([
13797
11740
  string(),
13798
11741
  _instanceof(Uint8Array),
@@ -13807,7 +11750,7 @@ var jsonValueSchema$2 = lazy(() => union([
13807
11750
  string(),
13808
11751
  number(),
13809
11752
  boolean(),
13810
- record(string(), jsonValueSchema$2),
11753
+ record(string(), jsonValueSchema$2.optional()),
13811
11754
  array$1(jsonValueSchema$2)
13812
11755
  ]));
13813
11756
  var providerMetadataSchema$2 = record(string(), record(string(), jsonValueSchema$2));
@@ -14186,10 +12129,12 @@ createIdGenerator$2({
14186
12129
  prefix: "aitxt",
14187
12130
  size: 24
14188
12131
  });
12132
+ new TextEncoder();
14189
12133
  createIdGenerator$2({
14190
12134
  prefix: "aiobj",
14191
12135
  size: 24
14192
12136
  });
12137
+ var { atob: atob$4 } = globalThis;
14193
12138
  createIdGenerator$2({
14194
12139
  prefix: "aiobj",
14195
12140
  size: 24
@@ -14301,9 +12246,9 @@ function customProvider$2({ languageModels, textEmbeddingModels, imageModels, tr
14301
12246
  }
14302
12247
  //#endregion
14303
12248
  //#region ../_vendored/ai_v4/dist/dist-Cm5DZgxA.js
14304
- var marker$5 = "vercel.ai.error";
14305
- var symbol$5 = Symbol.for(marker$5);
14306
- var _a$5;
12249
+ var marker$4 = "vercel.ai.error";
12250
+ var symbol$4 = Symbol.for(marker$4);
12251
+ var _a$4;
14307
12252
  var _AISDKError = class _AISDKError extends Error {
14308
12253
  /**
14309
12254
  * Creates an AI SDK Error.
@@ -14315,7 +12260,7 @@ var _AISDKError = class _AISDKError extends Error {
14315
12260
  */
14316
12261
  constructor({ name: name14, message, cause }) {
14317
12262
  super(message);
14318
- this[_a$5] = true;
12263
+ this[_a$4] = true;
14319
12264
  this.name = name14;
14320
12265
  this.cause = cause;
14321
12266
  }
@@ -14325,96 +12270,96 @@ var _AISDKError = class _AISDKError extends Error {
14325
12270
  * @returns {boolean} True if the error is an AI SDK Error, false otherwise.
14326
12271
  */
14327
12272
  static isInstance(error) {
14328
- return _AISDKError.hasMarker(error, marker$5);
12273
+ return _AISDKError.hasMarker(error, marker$4);
14329
12274
  }
14330
12275
  static hasMarker(error, marker15) {
14331
12276
  const markerSymbol = Symbol.for(marker15);
14332
12277
  return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
14333
12278
  }
14334
12279
  };
14335
- _a$5 = symbol$5;
14336
- var AISDKError$2 = _AISDKError;
14337
- function getErrorMessage$1(error) {
12280
+ _a$4 = symbol$4;
12281
+ var AISDKError$1 = _AISDKError;
12282
+ function getErrorMessage(error) {
14338
12283
  if (error == null) return "unknown error";
14339
12284
  if (typeof error === "string") return error;
14340
12285
  if (error instanceof Error) return error.message;
14341
12286
  return JSON.stringify(error);
14342
12287
  }
14343
- var name3$4 = "AI_InvalidArgumentError";
14344
- var marker4$4 = `vercel.ai.error.${name3$4}`;
14345
- var symbol4$4 = Symbol.for(marker4$4);
14346
- var _a4$4;
14347
- var InvalidArgumentError$2 = class extends AISDKError$2 {
12288
+ var name3$3 = "AI_InvalidArgumentError";
12289
+ var marker4$3 = `vercel.ai.error.${name3$3}`;
12290
+ var symbol4$3 = Symbol.for(marker4$3);
12291
+ var _a4$3;
12292
+ var InvalidArgumentError$1 = class extends AISDKError$1 {
14348
12293
  constructor({ message, cause, argument }) {
14349
12294
  super({
14350
- name: name3$4,
12295
+ name: name3$3,
14351
12296
  message,
14352
12297
  cause
14353
12298
  });
14354
- this[_a4$4] = true;
12299
+ this[_a4$3] = true;
14355
12300
  this.argument = argument;
14356
12301
  }
14357
12302
  static isInstance(error) {
14358
- return AISDKError$2.hasMarker(error, marker4$4);
12303
+ return AISDKError$1.hasMarker(error, marker4$3);
14359
12304
  }
14360
12305
  };
14361
- _a4$4 = symbol4$4;
14362
- var name6$4 = "AI_JSONParseError";
14363
- var marker7$4 = `vercel.ai.error.${name6$4}`;
14364
- var symbol7$4 = Symbol.for(marker7$4);
14365
- var _a7$4;
14366
- var JSONParseError$2 = class extends AISDKError$2 {
12306
+ _a4$3 = symbol4$3;
12307
+ var name6$3 = "AI_JSONParseError";
12308
+ var marker7$3 = `vercel.ai.error.${name6$3}`;
12309
+ var symbol7$3 = Symbol.for(marker7$3);
12310
+ var _a7$3;
12311
+ var JSONParseError$1 = class extends AISDKError$1 {
14367
12312
  constructor({ text, cause }) {
14368
12313
  super({
14369
- name: name6$4,
12314
+ name: name6$3,
14370
12315
  message: `JSON parsing failed: Text: ${text}.
14371
- Error message: ${getErrorMessage$1(cause)}`,
12316
+ Error message: ${getErrorMessage(cause)}`,
14372
12317
  cause
14373
12318
  });
14374
- this[_a7$4] = true;
12319
+ this[_a7$3] = true;
14375
12320
  this.text = text;
14376
12321
  }
14377
12322
  static isInstance(error) {
14378
- return AISDKError$2.hasMarker(error, marker7$4);
12323
+ return AISDKError$1.hasMarker(error, marker7$3);
14379
12324
  }
14380
12325
  };
14381
- _a7$4 = symbol7$4;
14382
- var name10$4 = "AI_NoSuchModelError";
14383
- var marker11$4 = `vercel.ai.error.${name10$4}`;
14384
- var symbol11$4 = Symbol.for(marker11$4);
14385
- var _a11$4;
14386
- var NoSuchModelError$1 = class extends AISDKError$2 {
14387
- constructor({ errorName = name10$4, modelId, modelType, message = `No such ${modelType}: ${modelId}` }) {
12326
+ _a7$3 = symbol7$3;
12327
+ var name10$3 = "AI_NoSuchModelError";
12328
+ var marker11$3 = `vercel.ai.error.${name10$3}`;
12329
+ var symbol11$3 = Symbol.for(marker11$3);
12330
+ var _a11$3;
12331
+ var NoSuchModelError$1 = class extends AISDKError$1 {
12332
+ constructor({ errorName = name10$3, modelId, modelType, message = `No such ${modelType}: ${modelId}` }) {
14388
12333
  super({
14389
12334
  name: errorName,
14390
12335
  message
14391
12336
  });
14392
- this[_a11$4] = true;
12337
+ this[_a11$3] = true;
14393
12338
  this.modelId = modelId;
14394
12339
  this.modelType = modelType;
14395
12340
  }
14396
12341
  static isInstance(error) {
14397
- return AISDKError$2.hasMarker(error, marker11$4);
12342
+ return AISDKError$1.hasMarker(error, marker11$3);
14398
12343
  }
14399
12344
  };
14400
- _a11$4 = symbol11$4;
14401
- var name12$4 = "AI_TypeValidationError";
14402
- var marker13$4 = `vercel.ai.error.${name12$4}`;
14403
- var symbol13$4 = Symbol.for(marker13$4);
14404
- var _a13$4;
14405
- var _TypeValidationError = class _TypeValidationError extends AISDKError$2 {
12345
+ _a11$3 = symbol11$3;
12346
+ var name12$3 = "AI_TypeValidationError";
12347
+ var marker13$3 = `vercel.ai.error.${name12$3}`;
12348
+ var symbol13$3 = Symbol.for(marker13$3);
12349
+ var _a13$3;
12350
+ var _TypeValidationError = class _TypeValidationError extends AISDKError$1 {
14406
12351
  constructor({ value, cause }) {
14407
12352
  super({
14408
- name: name12$4,
12353
+ name: name12$3,
14409
12354
  message: `Type validation failed: Value: ${JSON.stringify(value)}.
14410
- Error message: ${getErrorMessage$1(cause)}`,
12355
+ Error message: ${getErrorMessage(cause)}`,
14411
12356
  cause
14412
12357
  });
14413
- this[_a13$4] = true;
12358
+ this[_a13$3] = true;
14414
12359
  this.value = value;
14415
12360
  }
14416
12361
  static isInstance(error) {
14417
- return AISDKError$2.hasMarker(error, marker13$4);
12362
+ return AISDKError$1.hasMarker(error, marker13$3);
14418
12363
  }
14419
12364
  /**
14420
12365
  * Wraps an error into a TypeValidationError.
@@ -14433,8 +12378,8 @@ Error message: ${getErrorMessage$1(cause)}`,
14433
12378
  });
14434
12379
  }
14435
12380
  };
14436
- _a13$4 = symbol13$4;
14437
- var TypeValidationError$2 = _TypeValidationError;
12381
+ _a13$3 = symbol13$3;
12382
+ var TypeValidationError$1 = _TypeValidationError;
14438
12383
  //#endregion
14439
12384
  //#region ../_vendored/ai_v4/dist/index.js
14440
12385
  var __create = Object.create;
@@ -14571,7 +12516,7 @@ function convertAsyncIteratorToReadableStream(iterator) {
14571
12516
  var createIdGenerator$1 = ({ prefix, size: defaultSize = 16, alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", separator = "-" } = {}) => {
14572
12517
  const generator = customAlphabet(alphabet, defaultSize);
14573
12518
  if (prefix == null) return generator;
14574
- if (alphabet.includes(separator)) throw new InvalidArgumentError$2({
12519
+ if (alphabet.includes(separator)) throw new InvalidArgumentError$1({
14575
12520
  argument: "separator",
14576
12521
  message: `The separator "${separator}" must not be part of the alphabet "${alphabet}".`
14577
12522
  });
@@ -14614,7 +12559,7 @@ function safeValidateTypes$1({ value, schema }) {
14614
12559
  if (result.success) return result;
14615
12560
  return {
14616
12561
  success: false,
14617
- error: TypeValidationError$2.wrap({
12562
+ error: TypeValidationError$1.wrap({
14618
12563
  value,
14619
12564
  cause: result.error
14620
12565
  })
@@ -14622,7 +12567,7 @@ function safeValidateTypes$1({ value, schema }) {
14622
12567
  } catch (error) {
14623
12568
  return {
14624
12569
  success: false,
14625
- error: TypeValidationError$2.wrap({
12570
+ error: TypeValidationError$1.wrap({
14626
12571
  value,
14627
12572
  cause: error
14628
12573
  })
@@ -14648,14 +12593,14 @@ function safeParseJSON$1({ text, schema }) {
14648
12593
  } catch (error) {
14649
12594
  return {
14650
12595
  success: false,
14651
- error: JSONParseError$2.isInstance(error) ? error : new JSONParseError$2({
12596
+ error: JSONParseError$1.isInstance(error) ? error : new JSONParseError$1({
14652
12597
  text,
14653
12598
  cause: error
14654
12599
  })
14655
12600
  };
14656
12601
  }
14657
12602
  }
14658
- var { btoa: btoa$2, atob: atob$2 } = globalThis;
12603
+ var { btoa: btoa$2, atob: atob$3 } = globalThis;
14659
12604
  const ignoreOverride$1 = Symbol("Let zodToJsonSchema decide on which parser to use");
14660
12605
  const defaultOptions$1 = {
14661
12606
  name: void 0,
@@ -17039,28 +14984,28 @@ function prepareResponseHeaders(headers, { contentType, dataStreamVersion }) {
17039
14984
  if (dataStreamVersion !== void 0) responseHeaders.set("X-Vercel-AI-Data-Stream", dataStreamVersion);
17040
14985
  return responseHeaders;
17041
14986
  }
17042
- var name4$3 = "AI_NoObjectGeneratedError";
17043
- var marker4$3 = `vercel.ai.error.${name4$3}`;
17044
- var symbol4$3 = Symbol.for(marker4$3);
17045
- var _a4$3;
17046
- var NoObjectGeneratedError$1 = class extends AISDKError$2 {
14987
+ var name4$2 = "AI_NoObjectGeneratedError";
14988
+ var marker4$2 = `vercel.ai.error.${name4$2}`;
14989
+ var symbol4$2 = Symbol.for(marker4$2);
14990
+ var _a4$2;
14991
+ var NoObjectGeneratedError$1 = class extends AISDKError$1 {
17047
14992
  constructor({ message = "No object generated.", cause, text: text2, response, usage, finishReason }) {
17048
14993
  super({
17049
- name: name4$3,
14994
+ name: name4$2,
17050
14995
  message,
17051
14996
  cause
17052
14997
  });
17053
- this[_a4$3] = true;
14998
+ this[_a4$2] = true;
17054
14999
  this.text = text2;
17055
15000
  this.response = response;
17056
15001
  this.usage = usage;
17057
15002
  this.finishReason = finishReason;
17058
15003
  }
17059
15004
  static isInstance(error) {
17060
- return AISDKError$2.hasMarker(error, marker4$3);
15005
+ return AISDKError$1.hasMarker(error, marker4$2);
17061
15006
  }
17062
15007
  };
17063
- _a4$3 = symbol4$3;
15008
+ _a4$2 = symbol4$2;
17064
15009
  var dataContentSchema$1 = union([
17065
15010
  string(),
17066
15011
  _instanceof(Uint8Array),
@@ -17590,12 +15535,12 @@ function trimStartOfStream() {
17590
15535
  };
17591
15536
  }
17592
15537
  //#endregion
17593
- //#region ../_vendored/ai_v6/dist/dist-B5Rt0qDx.js
17594
- var marker$2 = "vercel.ai.error";
17595
- var symbol$2 = Symbol.for(marker$2);
17596
- var _a$2;
17597
- var _b$2;
17598
- var AISDKError$1 = class _AISDKError extends (_b$2 = Error, _a$2 = symbol$2, _b$2) {
15538
+ //#region ../_vendored/ai_v6/dist/dist-CMCOMbq-.js
15539
+ var marker$1 = "vercel.ai.error";
15540
+ var symbol$1 = Symbol.for(marker$1);
15541
+ var _a$1;
15542
+ var _b$1;
15543
+ var AISDKError = class _AISDKError extends (_b$1 = Error, _a$1 = symbol$1, _b$1) {
17599
15544
  /**
17600
15545
  * Creates an AI SDK Error.
17601
15546
  *
@@ -17606,7 +15551,7 @@ var AISDKError$1 = class _AISDKError extends (_b$2 = Error, _a$2 = symbol$2, _b$
17606
15551
  */
17607
15552
  constructor({ name: name14, message, cause }) {
17608
15553
  super(message);
17609
- this[_a$2] = true;
15554
+ this[_a$1] = true;
17610
15555
  this.name = name14;
17611
15556
  this.cause = cause;
17612
15557
  }
@@ -17616,22 +15561,22 @@ var AISDKError$1 = class _AISDKError extends (_b$2 = Error, _a$2 = symbol$2, _b$
17616
15561
  * @returns {boolean} True if the error is an AI SDK Error, false otherwise.
17617
15562
  */
17618
15563
  static isInstance(error) {
17619
- return _AISDKError.hasMarker(error, marker$2);
15564
+ return _AISDKError.hasMarker(error, marker$1);
17620
15565
  }
17621
15566
  static hasMarker(error, marker15) {
17622
15567
  const markerSymbol = Symbol.for(marker15);
17623
15568
  return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
17624
15569
  }
17625
15570
  };
17626
- var name$2 = "AI_APICallError";
17627
- var marker2$1 = `vercel.ai.error.${name$2}`;
15571
+ var name$1 = "AI_APICallError";
15572
+ var marker2$1 = `vercel.ai.error.${name$1}`;
17628
15573
  var symbol2$1 = Symbol.for(marker2$1);
17629
15574
  var _a2$1;
17630
- var _b2$1;
17631
- (class extends (_b2$1 = AISDKError$1, _a2$1 = symbol2$1, _b2$1) {
15575
+ var _b2;
15576
+ (class extends (_b2 = AISDKError, _a2$1 = symbol2$1, _b2) {
17632
15577
  constructor({ message, url, requestBodyValues, statusCode, responseHeaders, responseBody, cause, isRetryable = statusCode != null && (statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500), data }) {
17633
15578
  super({
17634
- name: name$2,
15579
+ name: name$1,
17635
15580
  message,
17636
15581
  cause
17637
15582
  });
@@ -17645,15 +15590,15 @@ var _b2$1;
17645
15590
  this.data = data;
17646
15591
  }
17647
15592
  static isInstance(error) {
17648
- return AISDKError$1.hasMarker(error, marker2$1);
15593
+ return AISDKError.hasMarker(error, marker2$1);
17649
15594
  }
17650
15595
  });
17651
15596
  var name2$1 = "AI_EmptyResponseBodyError";
17652
15597
  var marker3$1 = `vercel.ai.error.${name2$1}`;
17653
15598
  var symbol3$1 = Symbol.for(marker3$1);
17654
15599
  var _a3$1;
17655
- var _b3$1;
17656
- (class extends (_b3$1 = AISDKError$1, _a3$1 = symbol3$1, _b3$1) {
15600
+ var _b3;
15601
+ (class extends (_b3 = AISDKError, _a3$1 = symbol3$1, _b3) {
17657
15602
  constructor({ message = "Empty response body" } = {}) {
17658
15603
  super({
17659
15604
  name: name2$1,
@@ -17662,10 +15607,10 @@ var _b3$1;
17662
15607
  this[_a3$1] = true;
17663
15608
  }
17664
15609
  static isInstance(error) {
17665
- return AISDKError$1.hasMarker(error, marker3$1);
15610
+ return AISDKError.hasMarker(error, marker3$1);
17666
15611
  }
17667
15612
  });
17668
- function getErrorMessage$2(error) {
15613
+ function getErrorMessage$1(error) {
17669
15614
  if (error == null) return "unknown error";
17670
15615
  if (typeof error === "string") return error;
17671
15616
  if (error instanceof Error) return error.message;
@@ -17675,8 +15620,8 @@ var name3$1 = "AI_InvalidArgumentError";
17675
15620
  var marker4$1 = `vercel.ai.error.${name3$1}`;
17676
15621
  var symbol4$1 = Symbol.for(marker4$1);
17677
15622
  var _a4$1;
17678
- var _b4$1;
17679
- var InvalidArgumentError$1 = class extends (_b4$1 = AISDKError$1, _a4$1 = symbol4$1, _b4$1) {
15623
+ var _b4;
15624
+ var InvalidArgumentError = class extends (_b4 = AISDKError, _a4$1 = symbol4$1, _b4) {
17680
15625
  constructor({ message, cause, argument }) {
17681
15626
  super({
17682
15627
  name: name3$1,
@@ -17687,15 +15632,15 @@ var InvalidArgumentError$1 = class extends (_b4$1 = AISDKError$1, _a4$1 = symbol
17687
15632
  this.argument = argument;
17688
15633
  }
17689
15634
  static isInstance(error) {
17690
- return AISDKError$1.hasMarker(error, marker4$1);
15635
+ return AISDKError.hasMarker(error, marker4$1);
17691
15636
  }
17692
15637
  };
17693
15638
  var name4$1 = "AI_InvalidPromptError";
17694
15639
  var marker5$1 = `vercel.ai.error.${name4$1}`;
17695
15640
  var symbol5$1 = Symbol.for(marker5$1);
17696
15641
  var _a5$1;
17697
- var _b5$1;
17698
- (class extends (_b5$1 = AISDKError$1, _a5$1 = symbol5$1, _b5$1) {
15642
+ var _b5;
15643
+ (class extends (_b5 = AISDKError, _a5$1 = symbol5$1, _b5) {
17699
15644
  constructor({ prompt, message, cause }) {
17700
15645
  super({
17701
15646
  name: name4$1,
@@ -17706,15 +15651,15 @@ var _b5$1;
17706
15651
  this.prompt = prompt;
17707
15652
  }
17708
15653
  static isInstance(error) {
17709
- return AISDKError$1.hasMarker(error, marker5$1);
15654
+ return AISDKError.hasMarker(error, marker5$1);
17710
15655
  }
17711
15656
  });
17712
15657
  var name5$1 = "AI_InvalidResponseDataError";
17713
15658
  var marker6$1 = `vercel.ai.error.${name5$1}`;
17714
15659
  var symbol6$1 = Symbol.for(marker6$1);
17715
15660
  var _a6$1;
17716
- var _b6$1;
17717
- (class extends (_b6$1 = AISDKError$1, _a6$1 = symbol6$1, _b6$1) {
15661
+ var _b6;
15662
+ (class extends (_b6 = AISDKError, _a6$1 = symbol6$1, _b6) {
17718
15663
  constructor({ data, message = `Invalid response data: ${JSON.stringify(data)}.` }) {
17719
15664
  super({
17720
15665
  name: name5$1,
@@ -17724,35 +15669,35 @@ var _b6$1;
17724
15669
  this.data = data;
17725
15670
  }
17726
15671
  static isInstance(error) {
17727
- return AISDKError$1.hasMarker(error, marker6$1);
15672
+ return AISDKError.hasMarker(error, marker6$1);
17728
15673
  }
17729
15674
  });
17730
15675
  var name6$1 = "AI_JSONParseError";
17731
15676
  var marker7$1 = `vercel.ai.error.${name6$1}`;
17732
15677
  var symbol7$1 = Symbol.for(marker7$1);
17733
15678
  var _a7$1;
17734
- var _b7$1;
17735
- var JSONParseError$1 = class extends (_b7$1 = AISDKError$1, _a7$1 = symbol7$1, _b7$1) {
15679
+ var _b7;
15680
+ var JSONParseError = class extends (_b7 = AISDKError, _a7$1 = symbol7$1, _b7) {
17736
15681
  constructor({ text, cause }) {
17737
15682
  super({
17738
15683
  name: name6$1,
17739
15684
  message: `JSON parsing failed: Text: ${text}.
17740
- Error message: ${getErrorMessage$2(cause)}`,
15685
+ Error message: ${getErrorMessage$1(cause)}`,
17741
15686
  cause
17742
15687
  });
17743
15688
  this[_a7$1] = true;
17744
15689
  this.text = text;
17745
15690
  }
17746
15691
  static isInstance(error) {
17747
- return AISDKError$1.hasMarker(error, marker7$1);
15692
+ return AISDKError.hasMarker(error, marker7$1);
17748
15693
  }
17749
15694
  };
17750
15695
  var name7$1 = "AI_LoadAPIKeyError";
17751
15696
  var marker8$1 = `vercel.ai.error.${name7$1}`;
17752
15697
  var symbol8$1 = Symbol.for(marker8$1);
17753
15698
  var _a8$1;
17754
- var _b8$1;
17755
- (class extends (_b8$1 = AISDKError$1, _a8$1 = symbol8$1, _b8$1) {
15699
+ var _b8;
15700
+ (class extends (_b8 = AISDKError, _a8$1 = symbol8$1, _b8) {
17756
15701
  constructor({ message }) {
17757
15702
  super({
17758
15703
  name: name7$1,
@@ -17761,15 +15706,15 @@ var _b8$1;
17761
15706
  this[_a8$1] = true;
17762
15707
  }
17763
15708
  static isInstance(error) {
17764
- return AISDKError$1.hasMarker(error, marker8$1);
15709
+ return AISDKError.hasMarker(error, marker8$1);
17765
15710
  }
17766
15711
  });
17767
15712
  var name8$1 = "AI_LoadSettingError";
17768
15713
  var marker9$1 = `vercel.ai.error.${name8$1}`;
17769
15714
  var symbol9$1 = Symbol.for(marker9$1);
17770
15715
  var _a9$1;
17771
- var _b9$1;
17772
- (class extends (_b9$1 = AISDKError$1, _a9$1 = symbol9$1, _b9$1) {
15716
+ var _b9;
15717
+ (class extends (_b9 = AISDKError, _a9$1 = symbol9$1, _b9) {
17773
15718
  constructor({ message }) {
17774
15719
  super({
17775
15720
  name: name8$1,
@@ -17778,15 +15723,15 @@ var _b9$1;
17778
15723
  this[_a9$1] = true;
17779
15724
  }
17780
15725
  static isInstance(error) {
17781
- return AISDKError$1.hasMarker(error, marker9$1);
15726
+ return AISDKError.hasMarker(error, marker9$1);
17782
15727
  }
17783
15728
  });
17784
15729
  var name9$1 = "AI_NoContentGeneratedError";
17785
15730
  var marker10$1 = `vercel.ai.error.${name9$1}`;
17786
15731
  var symbol10$1 = Symbol.for(marker10$1);
17787
15732
  var _a10$1;
17788
- var _b10$1;
17789
- (class extends (_b10$1 = AISDKError$1, _a10$1 = symbol10$1, _b10$1) {
15733
+ var _b10;
15734
+ (class extends (_b10 = AISDKError, _a10$1 = symbol10$1, _b10) {
17790
15735
  constructor({ message = "No content generated." } = {}) {
17791
15736
  super({
17792
15737
  name: name9$1,
@@ -17795,15 +15740,15 @@ var _b10$1;
17795
15740
  this[_a10$1] = true;
17796
15741
  }
17797
15742
  static isInstance(error) {
17798
- return AISDKError$1.hasMarker(error, marker10$1);
15743
+ return AISDKError.hasMarker(error, marker10$1);
17799
15744
  }
17800
15745
  });
17801
15746
  var name10$1 = "AI_NoSuchModelError";
17802
15747
  var marker11$1 = `vercel.ai.error.${name10$1}`;
17803
15748
  var symbol11$1 = Symbol.for(marker11$1);
17804
15749
  var _a11$1;
17805
- var _b11$1;
17806
- (class extends (_b11$1 = AISDKError$1, _a11$1 = symbol11$1, _b11$1) {
15750
+ var _b11;
15751
+ var NoSuchModelError = class extends (_b11 = AISDKError, _a11$1 = symbol11$1, _b11) {
17807
15752
  constructor({ errorName = name10$1, modelId, modelType, message = `No such ${modelType}: ${modelId}` }) {
17808
15753
  super({
17809
15754
  name: errorName,
@@ -17814,15 +15759,15 @@ var _b11$1;
17814
15759
  this.modelType = modelType;
17815
15760
  }
17816
15761
  static isInstance(error) {
17817
- return AISDKError$1.hasMarker(error, marker11$1);
15762
+ return AISDKError.hasMarker(error, marker11$1);
17818
15763
  }
17819
- });
15764
+ };
17820
15765
  var name11$1 = "AI_TooManyEmbeddingValuesForCallError";
17821
15766
  var marker12$1 = `vercel.ai.error.${name11$1}`;
17822
15767
  var symbol12$1 = Symbol.for(marker12$1);
17823
15768
  var _a12$1;
17824
- var _b12$1;
17825
- (class extends (_b12$1 = AISDKError$1, _a12$1 = symbol12$1, _b12$1) {
15769
+ var _b12;
15770
+ (class extends (_b12 = AISDKError, _a12$1 = symbol12$1, _b12) {
17826
15771
  constructor(options) {
17827
15772
  super({
17828
15773
  name: name11$1,
@@ -17835,15 +15780,15 @@ var _b12$1;
17835
15780
  this.values = options.values;
17836
15781
  }
17837
15782
  static isInstance(error) {
17838
- return AISDKError$1.hasMarker(error, marker12$1);
15783
+ return AISDKError.hasMarker(error, marker12$1);
17839
15784
  }
17840
15785
  });
17841
15786
  var name12$1 = "AI_TypeValidationError";
17842
15787
  var marker13$1 = `vercel.ai.error.${name12$1}`;
17843
15788
  var symbol13$1 = Symbol.for(marker13$1);
17844
15789
  var _a13$1;
17845
- var _b13$1;
17846
- var TypeValidationError$1 = class _TypeValidationError extends (_b13$1 = AISDKError$1, _a13$1 = symbol13$1, _b13$1) {
15790
+ var _b13;
15791
+ var TypeValidationError = class _TypeValidationError extends (_b13 = AISDKError, _a13$1 = symbol13$1, _b13) {
17847
15792
  constructor({ value, cause, context }) {
17848
15793
  let contextPrefix = "Type validation failed";
17849
15794
  if (context == null ? void 0 : context.field) contextPrefix += ` for ${context.field}`;
@@ -17858,7 +15803,7 @@ var TypeValidationError$1 = class _TypeValidationError extends (_b13$1 = AISDKEr
17858
15803
  super({
17859
15804
  name: name12$1,
17860
15805
  message: `${contextPrefix}: Value: ${JSON.stringify(value)}.
17861
- Error message: ${getErrorMessage$2(cause)}`,
15806
+ Error message: ${getErrorMessage$1(cause)}`,
17862
15807
  cause
17863
15808
  });
17864
15809
  this[_a13$1] = true;
@@ -17866,7 +15811,7 @@ Error message: ${getErrorMessage$2(cause)}`,
17866
15811
  this.context = context;
17867
15812
  }
17868
15813
  static isInstance(error) {
17869
- return AISDKError$1.hasMarker(error, marker13$1);
15814
+ return AISDKError.hasMarker(error, marker13$1);
17870
15815
  }
17871
15816
  /**
17872
15817
  * Wraps an error into a TypeValidationError.
@@ -17893,8 +15838,8 @@ var name13$1 = "AI_UnsupportedFunctionalityError";
17893
15838
  var marker14$1 = `vercel.ai.error.${name13$1}`;
17894
15839
  var symbol14$1 = Symbol.for(marker14$1);
17895
15840
  var _a14$1;
17896
- var _b14$1;
17897
- (class extends (_b14$1 = AISDKError$1, _a14$1 = symbol14$1, _b14$1) {
15841
+ var _b14;
15842
+ (class extends (_b14 = AISDKError, _a14$1 = symbol14$1, _b14) {
17898
15843
  constructor({ functionality, message = `'${functionality}' functionality not supported.` }) {
17899
15844
  super({
17900
15845
  name: name13$1,
@@ -17904,39 +15849,32 @@ var _b14$1;
17904
15849
  this.functionality = functionality;
17905
15850
  }
17906
15851
  static isInstance(error) {
17907
- return AISDKError$1.hasMarker(error, marker14$1);
15852
+ return AISDKError.hasMarker(error, marker14$1);
17908
15853
  }
17909
15854
  });
17910
15855
  TransformStream;
17911
- var { btoa: btoa$1, atob: atob$1 } = globalThis;
17912
- var name$1 = "AI_DownloadError";
17913
- var marker$1 = `vercel.ai.error.${name$1}`;
17914
- var symbol$1 = Symbol.for(marker$1);
17915
- var _a$1;
17916
- var _b$1;
17917
- (class extends (_b$1 = AISDKError$1, _a$1 = symbol$1, _b$1) {
15856
+ var { btoa: btoa$1, atob: atob$2 } = globalThis;
15857
+ var name$2 = "AI_DownloadError";
15858
+ var marker$2 = `vercel.ai.error.${name$2}`;
15859
+ var symbol$2 = Symbol.for(marker$2);
15860
+ var _a$2;
15861
+ var _b;
15862
+ (class extends (_b = AISDKError, _a$2 = symbol$2, _b) {
17918
15863
  constructor({ url, statusCode, statusText, cause, message = cause == null ? `Failed to download ${url}: ${statusCode} ${statusText}` : `Failed to download ${url}: ${cause}` }) {
17919
15864
  super({
17920
- name: name$1,
15865
+ name: name$2,
17921
15866
  message,
17922
15867
  cause
17923
15868
  });
17924
- this[_a$1] = true;
15869
+ this[_a$2] = true;
17925
15870
  this.url = url;
17926
15871
  this.statusCode = statusCode;
17927
15872
  this.statusText = statusText;
17928
15873
  }
17929
15874
  static isInstance(error) {
17930
- return AISDKError$1.hasMarker(error, marker$1);
15875
+ return AISDKError.hasMarker(error, marker$2);
17931
15876
  }
17932
15877
  });
17933
- var initialGlobalFetch = globalThis.fetch;
17934
- isNodeDefaultFetch(initialGlobalFetch);
17935
- function isNodeDefaultFetch(fetch) {
17936
- if (typeof fetch !== "function") return false;
17937
- const source = Function.prototype.toString.call(fetch);
17938
- return source.includes("internal/deps/undici") || source.includes("lazy loading of undici");
17939
- }
17940
15878
  function getCurrentModulePath() {
17941
15879
  const originalPrepareStackTrace = Error.prepareStackTrace;
17942
15880
  try {
@@ -17959,7 +15897,7 @@ var createIdGenerator = ({ prefix, size = 16, alphabet = "0123456789ABCDEFGHIJKL
17959
15897
  return chars.join("");
17960
15898
  };
17961
15899
  if (prefix == null) return generator;
17962
- if (alphabet.includes(separator)) throw new InvalidArgumentError$1({
15900
+ if (alphabet.includes(separator)) throw new InvalidArgumentError({
17963
15901
  argument: "separator",
17964
15902
  message: `The separator "${separator}" must not be part of the alphabet "${alphabet}".`
17965
15903
  });
@@ -18940,7 +16878,7 @@ function standardSchema(standardSchema2) {
18940
16878
  value: result.value
18941
16879
  } : {
18942
16880
  success: false,
18943
- error: new TypeValidationError$1({
16881
+ error: new TypeValidationError({
18944
16882
  value,
18945
16883
  cause: result.issues
18946
16884
  })
@@ -19005,7 +16943,7 @@ async function safeValidateTypes({ value, schema, context }) {
19005
16943
  };
19006
16944
  return {
19007
16945
  success: false,
19008
- error: TypeValidationError$1.wrap({
16946
+ error: TypeValidationError.wrap({
19009
16947
  value,
19010
16948
  cause: result.error,
19011
16949
  context
@@ -19015,7 +16953,7 @@ async function safeValidateTypes({ value, schema, context }) {
19015
16953
  } catch (error) {
19016
16954
  return {
19017
16955
  success: false,
19018
- error: TypeValidationError$1.wrap({
16956
+ error: TypeValidationError.wrap({
19019
16957
  value,
19020
16958
  cause: error,
19021
16959
  context
@@ -19039,7 +16977,7 @@ async function safeParseJSON({ text, schema }) {
19039
16977
  } catch (error) {
19040
16978
  return {
19041
16979
  success: false,
19042
- error: JSONParseError$1.isInstance(error) ? error : new JSONParseError$1({
16980
+ error: JSONParseError.isInstance(error) ? error : new JSONParseError({
19043
16981
  text,
19044
16982
  cause: error
19045
16983
  }),
@@ -19052,322 +16990,6 @@ async function resolve(value) {
19052
16990
  return value;
19053
16991
  }
19054
16992
  new TextDecoder();
19055
- var marker$3 = "vercel.ai.error";
19056
- var symbol$3 = Symbol.for(marker$3);
19057
- var _a$3;
19058
- var _b;
19059
- var AISDKError = class _AISDKError extends (_b = Error, _a$3 = symbol$3, _b) {
19060
- /**
19061
- * Creates an AI SDK Error.
19062
- *
19063
- * @param {Object} params - The parameters for creating the error.
19064
- * @param {string} params.name - The name of the error.
19065
- * @param {string} params.message - The error message.
19066
- * @param {unknown} [params.cause] - The underlying cause of the error.
19067
- */
19068
- constructor({ name: name14, message, cause }) {
19069
- super(message);
19070
- this[_a$3] = true;
19071
- this.name = name14;
19072
- this.cause = cause;
19073
- }
19074
- /**
19075
- * Checks if the given error is an AI SDK Error.
19076
- * @param {unknown} error - The error to check.
19077
- * @returns {boolean} True if the error is an AI SDK Error, false otherwise.
19078
- */
19079
- static isInstance(error) {
19080
- return _AISDKError.hasMarker(error, marker$3);
19081
- }
19082
- static hasMarker(error, marker15) {
19083
- const markerSymbol = Symbol.for(marker15);
19084
- return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
19085
- }
19086
- };
19087
- var name$3 = "AI_APICallError";
19088
- var marker2$2 = `vercel.ai.error.${name$3}`;
19089
- var symbol2$2 = Symbol.for(marker2$2);
19090
- var _a2$2;
19091
- var _b2;
19092
- (class extends (_b2 = AISDKError, _a2$2 = symbol2$2, _b2) {
19093
- constructor({ message, url, requestBodyValues, statusCode, responseHeaders, responseBody, cause, isRetryable = statusCode != null && (statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500), data }) {
19094
- super({
19095
- name: name$3,
19096
- message,
19097
- cause
19098
- });
19099
- this[_a2$2] = true;
19100
- this.url = url;
19101
- this.requestBodyValues = requestBodyValues;
19102
- this.statusCode = statusCode;
19103
- this.responseHeaders = responseHeaders;
19104
- this.responseBody = responseBody;
19105
- this.isRetryable = isRetryable;
19106
- this.data = data;
19107
- }
19108
- static isInstance(error) {
19109
- return AISDKError.hasMarker(error, marker2$2);
19110
- }
19111
- });
19112
- var name2$2 = "AI_EmptyResponseBodyError";
19113
- var marker3$2 = `vercel.ai.error.${name2$2}`;
19114
- var symbol3$2 = Symbol.for(marker3$2);
19115
- var _a3$2;
19116
- var _b3;
19117
- (class extends (_b3 = AISDKError, _a3$2 = symbol3$2, _b3) {
19118
- constructor({ message = "Empty response body" } = {}) {
19119
- super({
19120
- name: name2$2,
19121
- message
19122
- });
19123
- this[_a3$2] = true;
19124
- }
19125
- static isInstance(error) {
19126
- return AISDKError.hasMarker(error, marker3$2);
19127
- }
19128
- });
19129
- function getErrorMessage(error) {
19130
- if (error == null) return "unknown error";
19131
- if (typeof error === "string") return error;
19132
- if (error instanceof Error) return error.message;
19133
- return JSON.stringify(error);
19134
- }
19135
- var name3$2 = "AI_InvalidArgumentError";
19136
- var marker4$2 = `vercel.ai.error.${name3$2}`;
19137
- var symbol4$2 = Symbol.for(marker4$2);
19138
- var _a4$2;
19139
- var _b4;
19140
- (class extends (_b4 = AISDKError, _a4$2 = symbol4$2, _b4) {
19141
- constructor({ message, cause, argument }) {
19142
- super({
19143
- name: name3$2,
19144
- message,
19145
- cause
19146
- });
19147
- this[_a4$2] = true;
19148
- this.argument = argument;
19149
- }
19150
- static isInstance(error) {
19151
- return AISDKError.hasMarker(error, marker4$2);
19152
- }
19153
- });
19154
- var name4$2 = "AI_InvalidPromptError";
19155
- var marker5$2 = `vercel.ai.error.${name4$2}`;
19156
- var symbol5$2 = Symbol.for(marker5$2);
19157
- var _a5$2;
19158
- var _b5;
19159
- (class extends (_b5 = AISDKError, _a5$2 = symbol5$2, _b5) {
19160
- constructor({ prompt, message, cause }) {
19161
- super({
19162
- name: name4$2,
19163
- message: `Invalid prompt: ${message}`,
19164
- cause
19165
- });
19166
- this[_a5$2] = true;
19167
- this.prompt = prompt;
19168
- }
19169
- static isInstance(error) {
19170
- return AISDKError.hasMarker(error, marker5$2);
19171
- }
19172
- });
19173
- var name5$2 = "AI_InvalidResponseDataError";
19174
- var marker6$2 = `vercel.ai.error.${name5$2}`;
19175
- var symbol6$2 = Symbol.for(marker6$2);
19176
- var _a6$2;
19177
- var _b6;
19178
- (class extends (_b6 = AISDKError, _a6$2 = symbol6$2, _b6) {
19179
- constructor({ data, message = `Invalid response data: ${JSON.stringify(data)}.` }) {
19180
- super({
19181
- name: name5$2,
19182
- message
19183
- });
19184
- this[_a6$2] = true;
19185
- this.data = data;
19186
- }
19187
- static isInstance(error) {
19188
- return AISDKError.hasMarker(error, marker6$2);
19189
- }
19190
- });
19191
- var name6$2 = "AI_JSONParseError";
19192
- var marker7$2 = `vercel.ai.error.${name6$2}`;
19193
- var symbol7$2 = Symbol.for(marker7$2);
19194
- var _a7$2;
19195
- var _b7;
19196
- (class extends (_b7 = AISDKError, _a7$2 = symbol7$2, _b7) {
19197
- constructor({ text, cause }) {
19198
- super({
19199
- name: name6$2,
19200
- message: `JSON parsing failed: Text: ${text}.
19201
- Error message: ${getErrorMessage(cause)}`,
19202
- cause
19203
- });
19204
- this[_a7$2] = true;
19205
- this.text = text;
19206
- }
19207
- static isInstance(error) {
19208
- return AISDKError.hasMarker(error, marker7$2);
19209
- }
19210
- });
19211
- var name7$2 = "AI_LoadAPIKeyError";
19212
- var marker8$2 = `vercel.ai.error.${name7$2}`;
19213
- var symbol8$2 = Symbol.for(marker8$2);
19214
- var _a8$2;
19215
- var _b8;
19216
- (class extends (_b8 = AISDKError, _a8$2 = symbol8$2, _b8) {
19217
- constructor({ message }) {
19218
- super({
19219
- name: name7$2,
19220
- message
19221
- });
19222
- this[_a8$2] = true;
19223
- }
19224
- static isInstance(error) {
19225
- return AISDKError.hasMarker(error, marker8$2);
19226
- }
19227
- });
19228
- var name8$2 = "AI_LoadSettingError";
19229
- var marker9$2 = `vercel.ai.error.${name8$2}`;
19230
- var symbol9$2 = Symbol.for(marker9$2);
19231
- var _a9$2;
19232
- var _b9;
19233
- (class extends (_b9 = AISDKError, _a9$2 = symbol9$2, _b9) {
19234
- constructor({ message }) {
19235
- super({
19236
- name: name8$2,
19237
- message
19238
- });
19239
- this[_a9$2] = true;
19240
- }
19241
- static isInstance(error) {
19242
- return AISDKError.hasMarker(error, marker9$2);
19243
- }
19244
- });
19245
- var name9$2 = "AI_NoContentGeneratedError";
19246
- var marker10$2 = `vercel.ai.error.${name9$2}`;
19247
- var symbol10$2 = Symbol.for(marker10$2);
19248
- var _a10$2;
19249
- var _b10;
19250
- (class extends (_b10 = AISDKError, _a10$2 = symbol10$2, _b10) {
19251
- constructor({ message = "No content generated." } = {}) {
19252
- super({
19253
- name: name9$2,
19254
- message
19255
- });
19256
- this[_a10$2] = true;
19257
- }
19258
- static isInstance(error) {
19259
- return AISDKError.hasMarker(error, marker10$2);
19260
- }
19261
- });
19262
- var name10$2 = "AI_NoSuchModelError";
19263
- var marker11$2 = `vercel.ai.error.${name10$2}`;
19264
- var symbol11$2 = Symbol.for(marker11$2);
19265
- var _a11$2;
19266
- var _b11;
19267
- var NoSuchModelError = class extends (_b11 = AISDKError, _a11$2 = symbol11$2, _b11) {
19268
- constructor({ errorName = name10$2, modelId, modelType, message = `No such ${modelType}: ${modelId}` }) {
19269
- super({
19270
- name: errorName,
19271
- message
19272
- });
19273
- this[_a11$2] = true;
19274
- this.modelId = modelId;
19275
- this.modelType = modelType;
19276
- }
19277
- static isInstance(error) {
19278
- return AISDKError.hasMarker(error, marker11$2);
19279
- }
19280
- };
19281
- var name11$2 = "AI_TooManyEmbeddingValuesForCallError";
19282
- var marker12$2 = `vercel.ai.error.${name11$2}`;
19283
- var symbol12$2 = Symbol.for(marker12$2);
19284
- var _a12$2;
19285
- var _b12;
19286
- (class extends (_b12 = AISDKError, _a12$2 = symbol12$2, _b12) {
19287
- constructor(options) {
19288
- super({
19289
- name: name11$2,
19290
- 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.`
19291
- });
19292
- this[_a12$2] = true;
19293
- this.provider = options.provider;
19294
- this.modelId = options.modelId;
19295
- this.maxEmbeddingsPerCall = options.maxEmbeddingsPerCall;
19296
- this.values = options.values;
19297
- }
19298
- static isInstance(error) {
19299
- return AISDKError.hasMarker(error, marker12$2);
19300
- }
19301
- });
19302
- var name12$2 = "AI_TypeValidationError";
19303
- var marker13$2 = `vercel.ai.error.${name12$2}`;
19304
- var symbol13$2 = Symbol.for(marker13$2);
19305
- var _a13$2;
19306
- var _b13;
19307
- var TypeValidationError = class _TypeValidationError extends (_b13 = AISDKError, _a13$2 = symbol13$2, _b13) {
19308
- constructor({ value, cause, context }) {
19309
- let contextPrefix = "Type validation failed";
19310
- if (context == null ? void 0 : context.field) contextPrefix += ` for ${context.field}`;
19311
- if ((context == null ? void 0 : context.entityName) || (context == null ? void 0 : context.entityId)) {
19312
- contextPrefix += " (";
19313
- const parts = [];
19314
- if (context.entityName) parts.push(context.entityName);
19315
- if (context.entityId) parts.push(`id: "${context.entityId}"`);
19316
- contextPrefix += parts.join(", ");
19317
- contextPrefix += ")";
19318
- }
19319
- super({
19320
- name: name12$2,
19321
- message: `${contextPrefix}: Value: ${JSON.stringify(value)}.
19322
- Error message: ${getErrorMessage(cause)}`,
19323
- cause
19324
- });
19325
- this[_a13$2] = true;
19326
- this.value = value;
19327
- this.context = context;
19328
- }
19329
- static isInstance(error) {
19330
- return AISDKError.hasMarker(error, marker13$2);
19331
- }
19332
- /**
19333
- * Wraps an error into a TypeValidationError.
19334
- * If the cause is already a TypeValidationError with the same value and context, it returns the cause.
19335
- * Otherwise, it creates a new TypeValidationError.
19336
- *
19337
- * @param {Object} params - The parameters for wrapping the error.
19338
- * @param {unknown} params.value - The value that failed validation.
19339
- * @param {unknown} params.cause - The original error or cause of the validation failure.
19340
- * @param {TypeValidationContext} params.context - Optional context about what is being validated.
19341
- * @returns {TypeValidationError} A TypeValidationError instance.
19342
- */
19343
- static wrap({ value, cause, context }) {
19344
- var _a15, _b15, _c;
19345
- 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;
19346
- return new _TypeValidationError({
19347
- value,
19348
- cause,
19349
- context
19350
- });
19351
- }
19352
- };
19353
- var name13$2 = "AI_UnsupportedFunctionalityError";
19354
- var marker14$2 = `vercel.ai.error.${name13$2}`;
19355
- var symbol14$2 = Symbol.for(marker14$2);
19356
- var _a14$2;
19357
- var _b14;
19358
- (class extends (_b14 = AISDKError, _a14$2 = symbol14$2, _b14) {
19359
- constructor({ functionality, message = `'${functionality}' functionality not supported.` }) {
19360
- super({
19361
- name: name13$2,
19362
- message
19363
- });
19364
- this[_a14$2] = true;
19365
- this.functionality = functionality;
19366
- }
19367
- static isInstance(error) {
19368
- return AISDKError.hasMarker(error, marker14$2);
19369
- }
19370
- });
19371
16993
  //#endregion
19372
16994
  //#region ../_vendored/ai_v6/dist/index.js
19373
16995
  const VERSION$1 = "1.9.1";
@@ -20156,8 +17778,8 @@ const API_NAME = "trace";
20156
17778
  }).getInstance();
20157
17779
  var __defProp = Object.defineProperty;
20158
17780
  var __export = (target, all) => {
20159
- for (var name22 in all) __defProp(target, name22, {
20160
- get: all[name22],
17781
+ for (var name23 in all) __defProp(target, name23, {
17782
+ get: all[name23],
20161
17783
  enumerable: true
20162
17784
  });
20163
17785
  };
@@ -20315,7 +17937,8 @@ function convertV2UsageToV3(usage) {
20315
17937
  total: usage.outputTokens,
20316
17938
  text: void 0,
20317
17939
  reasoning: usage.reasoningTokens
20318
- }
17940
+ },
17941
+ raw: usage.totalTokens == null ? void 0 : { totalTokens: usage.totalTokens }
20319
17942
  };
20320
17943
  }
20321
17944
  function asSpeechModelV3(model) {
@@ -20345,8 +17968,8 @@ var dataContentSchema = union([
20345
17968
  _instanceof(Uint8Array),
20346
17969
  _instanceof(ArrayBuffer),
20347
17970
  custom((value) => {
20348
- var _a22, _b;
20349
- return (_b = (_a22 = globalThis.Buffer) == null ? void 0 : _a22.isBuffer(value)) != null ? _b : false;
17971
+ var _a23, _b;
17972
+ return (_b = (_a23 = globalThis.Buffer) == null ? void 0 : _a23.isBuffer(value)) != null ? _b : false;
20350
17973
  }, { message: "Must be a Buffer" })
20351
17974
  ]);
20352
17975
  var jsonValueSchema = lazy(() => union([
@@ -20438,6 +18061,7 @@ var outputSchema = discriminatedUnion("type", [
20438
18061
  object$3({
20439
18062
  type: literal("file-url"),
20440
18063
  url: string(),
18064
+ mediaType: string().optional(),
20441
18065
  providerOptions: providerMetadataSchema.optional()
20442
18066
  }),
20443
18067
  object$3({
@@ -20478,7 +18102,9 @@ var toolResultPartSchema = object$3({
20478
18102
  var toolApprovalRequestSchema = object$3({
20479
18103
  type: literal("tool-approval-request"),
20480
18104
  approvalId: string(),
20481
- toolCallId: string()
18105
+ toolCallId: string(),
18106
+ signature: string().optional(),
18107
+ inputSchemaInput: unknown().optional()
20482
18108
  });
20483
18109
  var toolApprovalResponseSchema = object$3({
20484
18110
  type: literal("tool-approval-response"),
@@ -20821,14 +18447,14 @@ var text = () => ({
20821
18447
  },
20822
18448
  createElementStreamTransform() {}
20823
18449
  });
20824
- var object = ({ schema: inputSchema, name: name22, description }) => {
18450
+ var object = ({ schema: inputSchema, name: name23, description }) => {
20825
18451
  const schema = asSchema(inputSchema);
20826
18452
  return {
20827
18453
  name: "object",
20828
18454
  responseFormat: resolve(schema.jsonSchema).then((jsonSchema2) => ({
20829
18455
  type: "json",
20830
18456
  schema: jsonSchema2,
20831
- ...name22 != null && { name: name22 },
18457
+ ...name23 != null && { name: name23 },
20832
18458
  ...description != null && { description }
20833
18459
  })),
20834
18460
  async parseCompleteOutput({ text: text2 }, context2) {
@@ -20867,7 +18493,7 @@ var object = ({ schema: inputSchema, name: name22, description }) => {
20867
18493
  createElementStreamTransform() {}
20868
18494
  };
20869
18495
  };
20870
- var array = ({ element: inputElementSchema, name: name22, description }) => {
18496
+ var array = ({ element: inputElementSchema, name: name23, description }) => {
20871
18497
  const elementSchema = asSchema(inputElementSchema);
20872
18498
  return {
20873
18499
  name: "array",
@@ -20885,7 +18511,7 @@ var array = ({ element: inputElementSchema, name: name22, description }) => {
20885
18511
  required: ["elements"],
20886
18512
  additionalProperties: false
20887
18513
  },
20888
- ...name22 != null && { name: name22 },
18514
+ ...name23 != null && { name: name23 },
20889
18515
  ...description != null && { description }
20890
18516
  };
20891
18517
  }),
@@ -20959,7 +18585,7 @@ var array = ({ element: inputElementSchema, name: name22, description }) => {
20959
18585
  }
20960
18586
  };
20961
18587
  };
20962
- var choice = ({ options: choiceOptions, name: name22, description }) => {
18588
+ var choice = ({ options: choiceOptions, name: name23, description }) => {
20963
18589
  return {
20964
18590
  name: "choice",
20965
18591
  responseFormat: Promise.resolve({
@@ -20974,7 +18600,7 @@ var choice = ({ options: choiceOptions, name: name22, description }) => {
20974
18600
  required: ["result"],
20975
18601
  additionalProperties: false
20976
18602
  },
20977
- ...name22 != null && { name: name22 },
18603
+ ...name23 != null && { name: name23 },
20978
18604
  ...description != null && { description }
20979
18605
  }),
20980
18606
  async parseCompleteOutput({ text: text2 }, context2) {
@@ -21019,12 +18645,12 @@ var choice = ({ options: choiceOptions, name: name22, description }) => {
21019
18645
  createElementStreamTransform() {}
21020
18646
  };
21021
18647
  };
21022
- var json = ({ name: name22, description } = {}) => {
18648
+ var json = ({ name: name23, description } = {}) => {
21023
18649
  return {
21024
18650
  name: "json",
21025
18651
  responseFormat: Promise.resolve({
21026
18652
  type: "json",
21027
- ...name22 != null && { name: name22 },
18653
+ ...name23 != null && { name: name23 },
21028
18654
  ...description != null && { description }
21029
18655
  }),
21030
18656
  async parseCompleteOutput({ text: text2 }, context2) {
@@ -21062,10 +18688,12 @@ createIdGenerator({
21062
18688
  size: 24
21063
18689
  });
21064
18690
  record(string(), jsonValueSchema.optional());
18691
+ new TextEncoder();
21065
18692
  createIdGenerator({
21066
18693
  prefix: "aiobj",
21067
18694
  size: 24
21068
18695
  });
18696
+ var { atob: atob$1 } = globalThis;
21069
18697
  createIdGenerator({
21070
18698
  prefix: "aiobj",
21071
18699
  size: 24
@@ -21267,6 +18895,9 @@ function loadTokenizerFromDir(modelDir, maxLength) {
21267
18895
  }
21268
18896
  return tokenizer;
21269
18897
  }
18898
+ function assertValidBatchSize(batchSize) {
18899
+ if (!Number.isSafeInteger(batchSize) || batchSize <= 0) throw new RangeError(`batchSize must be a positive safe integer, received ${String(batchSize)}`);
18900
+ }
21270
18901
  var FlagEmbedding = class FlagEmbedding extends Embedding {
21271
18902
  constructor(tokenizer, session, model) {
21272
18903
  super();
@@ -21294,6 +18925,7 @@ var FlagEmbedding = class FlagEmbedding extends Embedding {
21294
18925
  * Counts texts longer than the model's token window. `embed()` silently truncates these to `maxLength`.
21295
18926
  */
21296
18927
  async countTruncated(textStrings, batchSize = 256) {
18928
+ assertValidBatchSize(batchSize);
21297
18929
  let count = 0;
21298
18930
  let maxLength = 0;
21299
18931
  for (let i = 0; i < textStrings.length; i += batchSize) {
@@ -21352,6 +18984,7 @@ var FlagEmbedding = class FlagEmbedding extends Embedding {
21352
18984
  return modelDir;
21353
18985
  }
21354
18986
  async *embed(textStrings, batchSize = 256) {
18987
+ assertValidBatchSize(batchSize);
21355
18988
  for (let i = 0; i < textStrings.length; i += batchSize) {
21356
18989
  const batchTexts = textStrings.slice(i, i + batchSize);
21357
18990
  const encodedTexts = await Promise.all(batchTexts.map((textString) => this.tokenizer.encode(textString)));
@@ -21476,6 +19109,7 @@ var SparseTextEmbedding = class SparseTextEmbedding extends SparseEmbedding {
21476
19109
  return modelDir;
21477
19110
  }
21478
19111
  async *embed(textStrings, batchSize = 256) {
19112
+ assertValidBatchSize(batchSize);
21479
19113
  for (let i = 0; i < textStrings.length; i += batchSize) {
21480
19114
  const batchTexts = textStrings.slice(i, i + batchSize);
21481
19115
  const encodedTexts = await Promise.all(batchTexts.map((textString) => this.tokenizer.encode(textString)));
@@ -21575,6 +19209,7 @@ async function generateEmbeddings(values, modelType) {
21575
19209
  const allResults = [];
21576
19210
  for await (const result of embeddings) allResults.push(...result.map((embedding) => Array.from(embedding)));
21577
19211
  if (allResults.length === 0) throw new Error("No embeddings generated");
19212
+ if (allResults.length !== values.length) throw new Error(`Expected ${values.length} embeddings but received ${allResults.length}`);
21578
19213
  return { embeddings: allResults };
21579
19214
  }
21580
19215
  function applyPrefix(values, prefix) {