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

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