@mastra/ai-sdk 1.1.3 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +2 -0
  3. package/dist/_types/@ai-sdk_provider/dist/index.d.ts +10 -4
  4. package/dist/_types/@internal_ai-sdk-v5/dist/index.d.ts +33 -46
  5. package/dist/{chunk-673A2GVJ.js → chunk-3YJ25IUJ.js} +4 -4
  6. package/dist/{chunk-673A2GVJ.js.map → chunk-3YJ25IUJ.js.map} +1 -1
  7. package/dist/chunk-HMOX24BQ.js +439 -0
  8. package/dist/chunk-HMOX24BQ.js.map +1 -0
  9. package/dist/chunk-VJW66KXQ.cjs +441 -0
  10. package/dist/chunk-VJW66KXQ.cjs.map +1 -0
  11. package/dist/{chunk-JQN3AXCI.cjs → chunk-WFARZCDO.cjs} +4 -4
  12. package/dist/{chunk-JQN3AXCI.cjs.map → chunk-WFARZCDO.cjs.map} +1 -1
  13. package/dist/convert-messages.d.ts +1 -1
  14. package/dist/convert-messages.d.ts.map +1 -1
  15. package/dist/index.cjs +479 -153
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.js +473 -147
  18. package/dist/index.js.map +1 -1
  19. package/dist/{token-6GSAFR2W-HVOHPJXC.js → token-APYSY3BW-INR55PKP.js} +11 -11
  20. package/dist/token-APYSY3BW-INR55PKP.js.map +1 -0
  21. package/dist/{token-6GSAFR2W-JSHXXRM2.cjs → token-APYSY3BW-Y5VD4L7Z.cjs} +14 -14
  22. package/dist/token-APYSY3BW-Y5VD4L7Z.cjs.map +1 -0
  23. package/dist/token-util-RMHT2CPJ-4YTBAZ23.cjs +10 -0
  24. package/dist/token-util-RMHT2CPJ-4YTBAZ23.cjs.map +1 -0
  25. package/dist/token-util-RMHT2CPJ-HCMQIDTV.js +8 -0
  26. package/dist/token-util-RMHT2CPJ-HCMQIDTV.js.map +1 -0
  27. package/package.json +9 -9
  28. package/dist/chunk-5S63TE4B.cjs +0 -252
  29. package/dist/chunk-5S63TE4B.cjs.map +0 -1
  30. package/dist/chunk-LDKSZEVM.js +0 -250
  31. package/dist/chunk-LDKSZEVM.js.map +0 -1
  32. package/dist/token-6GSAFR2W-HVOHPJXC.js.map +0 -1
  33. package/dist/token-6GSAFR2W-JSHXXRM2.cjs.map +0 -1
  34. package/dist/token-util-NEHG7TUY-EHD5JYKF.js +0 -8
  35. package/dist/token-util-NEHG7TUY-EHD5JYKF.js.map +0 -1
  36. package/dist/token-util-NEHG7TUY-XQELEZK2.cjs +0 -10
  37. package/dist/token-util-NEHG7TUY-XQELEZK2.cjs.map +0 -1
package/dist/index.js CHANGED
@@ -1,7 +1,8 @@
1
- import { __commonJS, require_token_error, __toESM } from './chunk-673A2GVJ.js';
1
+ import { __commonJS, require_token_error, __toESM } from './chunk-3YJ25IUJ.js';
2
2
  import * as z4 from 'zod/v4';
3
3
  import { z } from 'zod/v4';
4
4
  import { ZodFirstPartyTypeKind } from 'zod/v3';
5
+ import { z as z$1 } from 'zod';
5
6
  import { registerApiRoute } from '@mastra/core/server';
6
7
  import { TransformStream as TransformStream$1, ReadableStream as ReadableStream$1 } from 'stream/web';
7
8
  import { convertFullStreamChunkToMastra, DefaultGeneratedFile, DefaultGeneratedFileWithType } from '@mastra/core/stream';
@@ -12,7 +13,8 @@ import { WorkingMemory, MessageHistory, SemanticRecall } from '@mastra/core/proc
12
13
  var marker = "vercel.ai.error";
13
14
  var symbol = Symbol.for(marker);
14
15
  var _a;
15
- var _AISDKError = class _AISDKError2 extends Error {
16
+ var _b;
17
+ var AISDKError = class _AISDKError extends (_b = Error, _a = symbol, _b) {
16
18
  /**
17
19
  * Creates an AI SDK Error.
18
20
  *
@@ -22,13 +24,13 @@ var _AISDKError = class _AISDKError2 extends Error {
22
24
  * @param {unknown} [params.cause] - The underlying cause of the error.
23
25
  */
24
26
  constructor({
25
- name: name143,
27
+ name: name1422,
26
28
  message,
27
29
  cause
28
30
  }) {
29
31
  super(message);
30
32
  this[_a] = true;
31
- this.name = name143;
33
+ this.name = name1422;
32
34
  this.cause = cause;
33
35
  }
34
36
  /**
@@ -37,20 +39,19 @@ var _AISDKError = class _AISDKError2 extends Error {
37
39
  * @returns {boolean} True if the error is an AI SDK Error, false otherwise.
38
40
  */
39
41
  static isInstance(error) {
40
- return _AISDKError2.hasMarker(error, marker);
42
+ return _AISDKError.hasMarker(error, marker);
41
43
  }
42
- static hasMarker(error, marker153) {
43
- const markerSymbol = Symbol.for(marker153);
44
+ static hasMarker(error, marker1522) {
45
+ const markerSymbol = Symbol.for(marker1522);
44
46
  return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
45
47
  }
46
48
  };
47
- _a = symbol;
48
- var AISDKError = _AISDKError;
49
49
  var name = "AI_APICallError";
50
50
  var marker2 = `vercel.ai.error.${name}`;
51
51
  var symbol2 = Symbol.for(marker2);
52
52
  var _a2;
53
- var APICallError = class extends AISDKError {
53
+ var _b2;
54
+ var APICallError = class extends (_b2 = AISDKError, _a2 = symbol2, _b2) {
54
55
  constructor({
55
56
  message,
56
57
  url,
@@ -80,12 +81,12 @@ var APICallError = class extends AISDKError {
80
81
  return AISDKError.hasMarker(error, marker2);
81
82
  }
82
83
  };
83
- _a2 = symbol2;
84
84
  var name2 = "AI_EmptyResponseBodyError";
85
85
  var marker3 = `vercel.ai.error.${name2}`;
86
86
  var symbol3 = Symbol.for(marker3);
87
87
  var _a3;
88
- var EmptyResponseBodyError = class extends AISDKError {
88
+ var _b3;
89
+ var EmptyResponseBodyError = class extends (_b3 = AISDKError, _a3 = symbol3, _b3) {
89
90
  // used in isInstance
90
91
  constructor({ message = "Empty response body" } = {}) {
91
92
  super({ name: name2, message });
@@ -95,7 +96,6 @@ var EmptyResponseBodyError = class extends AISDKError {
95
96
  return AISDKError.hasMarker(error, marker3);
96
97
  }
97
98
  };
98
- _a3 = symbol3;
99
99
  function getErrorMessage(error) {
100
100
  if (error == null) {
101
101
  return "unknown error";
@@ -112,7 +112,8 @@ var name3 = "AI_InvalidArgumentError";
112
112
  var marker4 = `vercel.ai.error.${name3}`;
113
113
  var symbol4 = Symbol.for(marker4);
114
114
  var _a4;
115
- var InvalidArgumentError = class extends AISDKError {
115
+ var _b4;
116
+ var InvalidArgumentError = class extends (_b4 = AISDKError, _a4 = symbol4, _b4) {
116
117
  constructor({
117
118
  message,
118
119
  cause,
@@ -126,12 +127,12 @@ var InvalidArgumentError = class extends AISDKError {
126
127
  return AISDKError.hasMarker(error, marker4);
127
128
  }
128
129
  };
129
- _a4 = symbol4;
130
130
  var name6 = "AI_JSONParseError";
131
131
  var marker7 = `vercel.ai.error.${name6}`;
132
132
  var symbol7 = Symbol.for(marker7);
133
133
  var _a7;
134
- var JSONParseError = class extends AISDKError {
134
+ var _b7;
135
+ var JSONParseError = class extends (_b7 = AISDKError, _a7 = symbol7, _b7) {
135
136
  constructor({ text: text2, cause }) {
136
137
  super({
137
138
  name: name6,
@@ -146,12 +147,12 @@ Error message: ${getErrorMessage(cause)}`,
146
147
  return AISDKError.hasMarker(error, marker7);
147
148
  }
148
149
  };
149
- _a7 = symbol7;
150
150
  var name12 = "AI_TypeValidationError";
151
151
  var marker13 = `vercel.ai.error.${name12}`;
152
152
  var symbol13 = Symbol.for(marker13);
153
153
  var _a13;
154
- var _TypeValidationError = class _TypeValidationError2 extends AISDKError {
154
+ var _b13;
155
+ var TypeValidationError = class _TypeValidationError extends (_b13 = AISDKError, _a13 = symbol13, _b13) {
155
156
  constructor({ value, cause }) {
156
157
  super({
157
158
  name: name12,
@@ -179,11 +180,9 @@ Error message: ${getErrorMessage(cause)}`,
179
180
  value,
180
181
  cause
181
182
  }) {
182
- return _TypeValidationError2.isInstance(cause) && cause.value === value ? cause : new _TypeValidationError2({ value, cause });
183
+ return _TypeValidationError.isInstance(cause) && cause.value === value ? cause : new _TypeValidationError({ value, cause });
183
184
  }
184
185
  };
185
- _a13 = symbol13;
186
- var TypeValidationError = _TypeValidationError;
187
186
  var ParseError = class extends Error {
188
187
  constructor(message, options) {
189
188
  super(message), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
@@ -386,14 +385,14 @@ function handleFetchError({
386
385
  return error;
387
386
  }
388
387
  function getRuntimeEnvironmentUserAgent(globalThisAny = globalThis) {
389
- var _a153, _b8, _c;
388
+ var _a223, _b222, _c;
390
389
  if (globalThisAny.window) {
391
390
  return `runtime/browser`;
392
391
  }
393
- if ((_a153 = globalThisAny.navigator) == null ? void 0 : _a153.userAgent) {
392
+ if ((_a223 = globalThisAny.navigator) == null ? void 0 : _a223.userAgent) {
394
393
  return `runtime/${globalThisAny.navigator.userAgent.toLowerCase()}`;
395
394
  }
396
- if ((_c = (_b8 = globalThisAny.process) == null ? void 0 : _b8.versions) == null ? void 0 : _c.node) {
395
+ if ((_c = (_b222 = globalThisAny.process) == null ? void 0 : _b222.versions) == null ? void 0 : _c.node) {
397
396
  return `runtime/node.js/${globalThisAny.process.version.substring(0)}`;
398
397
  }
399
398
  if (globalThisAny.EdgeRuntime) {
@@ -431,7 +430,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
431
430
  );
432
431
  return Object.fromEntries(normalizedHeaders.entries());
433
432
  }
434
- var VERSION = "3.0.17";
433
+ var VERSION = "3.0.22";
435
434
  var getOriginalFetch = () => globalThis.fetch;
436
435
  var getFromApi = async ({
437
436
  url,
@@ -516,8 +515,8 @@ function loadOptionalSetting({
516
515
  }
517
516
  return settingValue;
518
517
  }
519
- var suspectProtoRx = /"__proto__"\s*:/;
520
- var suspectConstructorRx = /"constructor"\s*:/;
518
+ var suspectProtoRx = /"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/;
519
+ var suspectConstructorRx = /"(?: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*:/;
521
520
  function _parse(text2) {
522
521
  const obj = JSON.parse(text2);
523
522
  if (obj === null || typeof obj !== "object") {
@@ -537,7 +536,7 @@ function filter(obj) {
537
536
  if (Object.prototype.hasOwnProperty.call(node, "__proto__")) {
538
537
  throw new SyntaxError("Object contains forbidden prototype property");
539
538
  }
540
- if (Object.prototype.hasOwnProperty.call(node, "constructor") && Object.prototype.hasOwnProperty.call(node.constructor, "prototype")) {
539
+ if (Object.prototype.hasOwnProperty.call(node, "constructor") && node.constructor !== null && typeof node.constructor === "object" && Object.prototype.hasOwnProperty.call(node.constructor, "prototype")) {
541
540
  throw new SyntaxError("Object contains forbidden prototype property");
542
541
  }
543
542
  for (const key in node) {
@@ -773,6 +772,36 @@ var postToApi = async ({
773
772
  throw handleFetchError({ error, url, requestBodyValues: body.values });
774
773
  }
775
774
  };
775
+ function tool(tool2) {
776
+ return tool2;
777
+ }
778
+ function createProviderDefinedToolFactoryWithOutputSchema({
779
+ id,
780
+ name: name223,
781
+ inputSchema,
782
+ outputSchema: outputSchema2
783
+ }) {
784
+ return ({
785
+ execute,
786
+ toModelOutput,
787
+ onInputStart,
788
+ onInputDelta,
789
+ onInputAvailable,
790
+ ...args
791
+ }) => tool({
792
+ type: "provider-defined",
793
+ id,
794
+ name: name223,
795
+ args,
796
+ inputSchema,
797
+ outputSchema: outputSchema2,
798
+ execute,
799
+ toModelOutput,
800
+ onInputStart,
801
+ onInputDelta,
802
+ onInputAvailable
803
+ });
804
+ }
776
805
  async function resolve(value) {
777
806
  if (typeof value === "function") {
778
807
  value = value();
@@ -870,6 +899,31 @@ var createJsonResponseHandler = (responseSchema) => async ({ response, url, requ
870
899
  rawValue: parsedResult.rawValue
871
900
  };
872
901
  };
902
+ function addAdditionalPropertiesToJsonSchema(jsonSchema2) {
903
+ if (jsonSchema2.type === "object") {
904
+ jsonSchema2.additionalProperties = false;
905
+ const properties = jsonSchema2.properties;
906
+ if (properties != null) {
907
+ for (const property in properties) {
908
+ properties[property] = addAdditionalPropertiesToJsonSchema(
909
+ properties[property]
910
+ );
911
+ }
912
+ }
913
+ }
914
+ if (jsonSchema2.type === "array" && jsonSchema2.items != null) {
915
+ if (Array.isArray(jsonSchema2.items)) {
916
+ jsonSchema2.items = jsonSchema2.items.map(
917
+ (item) => addAdditionalPropertiesToJsonSchema(item)
918
+ );
919
+ } else {
920
+ jsonSchema2.items = addAdditionalPropertiesToJsonSchema(
921
+ jsonSchema2.items
922
+ );
923
+ }
924
+ }
925
+ return jsonSchema2;
926
+ }
873
927
  var getRelativePath = (pathA, pathB) => {
874
928
  let i = 0;
875
929
  for (; i < pathA.length && i < pathB.length; i++) {
@@ -912,11 +966,11 @@ function parseAnyDef() {
912
966
  return {};
913
967
  }
914
968
  function parseArrayDef(def, refs) {
915
- var _a153, _b8, _c;
969
+ var _a223, _b222, _c;
916
970
  const res = {
917
971
  type: "array"
918
972
  };
919
- if (((_a153 = def.type) == null ? void 0 : _a153._def) && ((_c = (_b8 = def.type) == null ? void 0 : _b8._def) == null ? void 0 : _c.typeName) !== ZodFirstPartyTypeKind.ZodAny) {
973
+ if (((_a223 = def.type) == null ? void 0 : _a223._def) && ((_c = (_b222 = def.type) == null ? void 0 : _b222._def) == null ? void 0 : _c.typeName) !== ZodFirstPartyTypeKind.ZodAny) {
920
974
  res.items = parseDef(def.type._def, {
921
975
  ...refs,
922
976
  currentPath: [...refs.currentPath, "items"]
@@ -1275,8 +1329,8 @@ function escapeNonAlphaNumeric(source) {
1275
1329
  return result;
1276
1330
  }
1277
1331
  function addFormat(schema, value, message, refs) {
1278
- var _a153;
1279
- if (schema.format || ((_a153 = schema.anyOf) == null ? void 0 : _a153.some((x) => x.format))) {
1332
+ var _a223;
1333
+ if (schema.format || ((_a223 = schema.anyOf) == null ? void 0 : _a223.some((x) => x.format))) {
1280
1334
  if (!schema.anyOf) {
1281
1335
  schema.anyOf = [];
1282
1336
  }
@@ -1295,8 +1349,8 @@ function addFormat(schema, value, message, refs) {
1295
1349
  }
1296
1350
  }
1297
1351
  function addPattern(schema, regex, message, refs) {
1298
- var _a153;
1299
- if (schema.pattern || ((_a153 = schema.allOf) == null ? void 0 : _a153.some((x) => x.pattern))) {
1352
+ var _a223;
1353
+ if (schema.pattern || ((_a223 = schema.allOf) == null ? void 0 : _a223.some((x) => x.pattern))) {
1300
1354
  if (!schema.allOf) {
1301
1355
  schema.allOf = [];
1302
1356
  }
@@ -1315,7 +1369,7 @@ function addPattern(schema, regex, message, refs) {
1315
1369
  }
1316
1370
  }
1317
1371
  function stringifyRegExpWithFlags(regex, refs) {
1318
- var _a153;
1372
+ var _a223;
1319
1373
  if (!refs.applyRegexFlags || !regex.flags) {
1320
1374
  return regex.source;
1321
1375
  }
@@ -1345,7 +1399,7 @@ function stringifyRegExpWithFlags(regex, refs) {
1345
1399
  pattern += source[i];
1346
1400
  pattern += `${source[i - 2]}-${source[i]}`.toUpperCase();
1347
1401
  inCharRange = false;
1348
- } else if (source[i + 1] === "-" && ((_a153 = source[i + 2]) == null ? void 0 : _a153.match(/[a-z]/))) {
1402
+ } else if (source[i + 1] === "-" && ((_a223 = source[i + 2]) == null ? void 0 : _a223.match(/[a-z]/))) {
1349
1403
  pattern += source[i];
1350
1404
  inCharRange = true;
1351
1405
  } else {
@@ -1387,15 +1441,15 @@ function stringifyRegExpWithFlags(regex, refs) {
1387
1441
  return pattern;
1388
1442
  }
1389
1443
  function parseRecordDef(def, refs) {
1390
- var _a153, _b8, _c, _d, _e, _f;
1444
+ var _a223, _b222, _c, _d, _e, _f;
1391
1445
  const schema = {
1392
1446
  type: "object",
1393
- additionalProperties: (_a153 = parseDef(def.valueType._def, {
1447
+ additionalProperties: (_a223 = parseDef(def.valueType._def, {
1394
1448
  ...refs,
1395
1449
  currentPath: [...refs.currentPath, "additionalProperties"]
1396
- })) != null ? _a153 : refs.allowedAdditionalProperties
1450
+ })) != null ? _a223 : refs.allowedAdditionalProperties
1397
1451
  };
1398
- if (((_b8 = def.keyType) == null ? void 0 : _b8._def.typeName) === ZodFirstPartyTypeKind.ZodString && ((_c = def.keyType._def.checks) == null ? void 0 : _c.length)) {
1452
+ if (((_b222 = def.keyType) == null ? void 0 : _b222._def.typeName) === ZodFirstPartyTypeKind.ZodString && ((_c = def.keyType._def.checks) == null ? void 0 : _c.length)) {
1399
1453
  const { type, ...keyType } = parseStringDef(def.keyType._def, refs);
1400
1454
  return {
1401
1455
  ...schema,
@@ -1650,8 +1704,8 @@ function safeIsOptional(schema) {
1650
1704
  }
1651
1705
  }
1652
1706
  var parseOptionalDef = (def, refs) => {
1653
- var _a153;
1654
- if (refs.currentPath.toString() === ((_a153 = refs.propertyPath) == null ? void 0 : _a153.toString())) {
1707
+ var _a223;
1708
+ if (refs.currentPath.toString() === ((_a223 = refs.propertyPath) == null ? void 0 : _a223.toString())) {
1655
1709
  return parseDef(def.innerType._def, refs);
1656
1710
  }
1657
1711
  const innerSchema = parseDef(def.innerType._def, {
@@ -1821,10 +1875,10 @@ var selectParser = (def, typeName, refs) => {
1821
1875
  }
1822
1876
  };
1823
1877
  function parseDef(def, refs, forceResolution = false) {
1824
- var _a153;
1878
+ var _a223;
1825
1879
  const seenItem = refs.seen.get(def);
1826
1880
  if (refs.override) {
1827
- const overrideResult = (_a153 = refs.override) == null ? void 0 : _a153.call(
1881
+ const overrideResult = (_a223 = refs.override) == null ? void 0 : _a223.call(
1828
1882
  refs,
1829
1883
  def,
1830
1884
  refs,
@@ -1890,11 +1944,11 @@ var getRefs = (options) => {
1890
1944
  currentPath,
1891
1945
  propertyPath: void 0,
1892
1946
  seen: new Map(
1893
- Object.entries(_options.definitions).map(([name143, def]) => [
1947
+ Object.entries(_options.definitions).map(([name223, def]) => [
1894
1948
  def._def,
1895
1949
  {
1896
1950
  def: def._def,
1897
- path: [..._options.basePath, _options.definitionPath, name143],
1951
+ path: [..._options.basePath, _options.definitionPath, name223],
1898
1952
  // Resolution of references will be forced even though seen, so it's ok that the schema is undefined here for now.
1899
1953
  jsonSchema: void 0
1900
1954
  }
@@ -1903,50 +1957,50 @@ var getRefs = (options) => {
1903
1957
  };
1904
1958
  };
1905
1959
  var zodToJsonSchema = (schema, options) => {
1906
- var _a153;
1960
+ var _a223;
1907
1961
  const refs = getRefs(options);
1908
1962
  let definitions = typeof options === "object" && options.definitions ? Object.entries(options.definitions).reduce(
1909
- (acc, [name223, schema2]) => {
1910
- var _a223;
1963
+ (acc, [name323, schema2]) => {
1964
+ var _a323;
1911
1965
  return {
1912
1966
  ...acc,
1913
- [name223]: (_a223 = parseDef(
1967
+ [name323]: (_a323 = parseDef(
1914
1968
  schema2._def,
1915
1969
  {
1916
1970
  ...refs,
1917
- currentPath: [...refs.basePath, refs.definitionPath, name223]
1971
+ currentPath: [...refs.basePath, refs.definitionPath, name323]
1918
1972
  },
1919
1973
  true
1920
- )) != null ? _a223 : parseAnyDef()
1974
+ )) != null ? _a323 : parseAnyDef()
1921
1975
  };
1922
1976
  },
1923
1977
  {}
1924
1978
  ) : void 0;
1925
- const name143 = typeof options === "string" ? options : (options == null ? void 0 : options.nameStrategy) === "title" ? void 0 : options == null ? void 0 : options.name;
1926
- const main = (_a153 = parseDef(
1979
+ const name223 = typeof options === "string" ? options : (options == null ? void 0 : options.nameStrategy) === "title" ? void 0 : options == null ? void 0 : options.name;
1980
+ const main = (_a223 = parseDef(
1927
1981
  schema._def,
1928
- name143 === void 0 ? refs : {
1982
+ name223 === void 0 ? refs : {
1929
1983
  ...refs,
1930
- currentPath: [...refs.basePath, refs.definitionPath, name143]
1984
+ currentPath: [...refs.basePath, refs.definitionPath, name223]
1931
1985
  },
1932
1986
  false
1933
- )) != null ? _a153 : parseAnyDef();
1987
+ )) != null ? _a223 : parseAnyDef();
1934
1988
  const title = typeof options === "object" && options.name !== void 0 && options.nameStrategy === "title" ? options.name : void 0;
1935
1989
  if (title !== void 0) {
1936
1990
  main.title = title;
1937
1991
  }
1938
- const combined = name143 === void 0 ? definitions ? {
1992
+ const combined = name223 === void 0 ? definitions ? {
1939
1993
  ...main,
1940
1994
  [refs.definitionPath]: definitions
1941
1995
  } : main : {
1942
1996
  $ref: [
1943
1997
  ...refs.$refStrategy === "relative" ? [] : refs.basePath,
1944
1998
  refs.definitionPath,
1945
- name143
1999
+ name223
1946
2000
  ].join("/"),
1947
2001
  [refs.definitionPath]: {
1948
2002
  ...definitions,
1949
- [name143]: main
2003
+ [name223]: main
1950
2004
  }
1951
2005
  };
1952
2006
  combined.$schema = "http://json-schema.org/draft-07/schema#";
@@ -1954,8 +2008,8 @@ var zodToJsonSchema = (schema, options) => {
1954
2008
  };
1955
2009
  var zod_to_json_schema_default = zodToJsonSchema;
1956
2010
  function zod3Schema(zodSchema2, options) {
1957
- var _a153;
1958
- const useReferences = (_a153 = void 0 ) != null ? _a153 : false;
2011
+ var _a223;
2012
+ const useReferences = (_a223 = void 0 ) != null ? _a223 : false;
1959
2013
  return jsonSchema(
1960
2014
  // defer json schema creation to avoid unnecessary computation when only validation is needed
1961
2015
  () => zod_to_json_schema_default(zodSchema2, {
@@ -1970,15 +2024,17 @@ function zod3Schema(zodSchema2, options) {
1970
2024
  );
1971
2025
  }
1972
2026
  function zod4Schema(zodSchema2, options) {
1973
- var _a153;
1974
- const useReferences = (_a153 = void 0 ) != null ? _a153 : false;
2027
+ var _a223;
2028
+ const useReferences = (_a223 = void 0 ) != null ? _a223 : false;
1975
2029
  return jsonSchema(
1976
2030
  // defer json schema creation to avoid unnecessary computation when only validation is needed
1977
- () => z4.toJSONSchema(zodSchema2, {
1978
- target: "draft-7",
1979
- io: "output",
1980
- reused: useReferences ? "ref" : "inline"
1981
- }),
2031
+ () => addAdditionalPropertiesToJsonSchema(
2032
+ z4.toJSONSchema(zodSchema2, {
2033
+ target: "draft-7",
2034
+ io: "input",
2035
+ reused: useReferences ? "ref" : "inline"
2036
+ })
2037
+ ),
1982
2038
  {
1983
2039
  validate: async (value) => {
1984
2040
  const result = await z4.safeParseAsync(zodSchema2, value);
@@ -1998,6 +2054,15 @@ function zodSchema(zodSchema2, options) {
1998
2054
  }
1999
2055
  }
2000
2056
  var schemaSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.schema");
2057
+ function lazySchema(createSchema) {
2058
+ let schema;
2059
+ return () => {
2060
+ if (schema == null) {
2061
+ schema = createSchema();
2062
+ }
2063
+ return schema;
2064
+ };
2065
+ }
2001
2066
  function jsonSchema(jsonSchema2, {
2002
2067
  validate
2003
2068
  } = {}) {
@@ -2028,7 +2093,7 @@ function withoutTrailingSlash(url) {
2028
2093
  return url == null ? void 0 : url.replace(/\/$/, "");
2029
2094
  }
2030
2095
  var require_get_context = __commonJS({
2031
- "../../../node_modules/.pnpm/@vercel+oidc@3.0.5/node_modules/@vercel/oidc/dist/get-context.js"(exports$1, module) {
2096
+ "../../../node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/get-context.js"(exports$1, module) {
2032
2097
  var __defProp2 = Object.defineProperty;
2033
2098
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
2034
2099
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -2060,7 +2125,7 @@ var require_get_context = __commonJS({
2060
2125
  }
2061
2126
  });
2062
2127
  var require_get_vercel_oidc_token = __commonJS({
2063
- "../../../node_modules/.pnpm/@vercel+oidc@3.0.5/node_modules/@vercel/oidc/dist/get-vercel-oidc-token.js"(exports$1, module) {
2128
+ "../../../node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/get-vercel-oidc-token.js"(exports$1, module) {
2064
2129
  var __defProp2 = Object.defineProperty;
2065
2130
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
2066
2131
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -2096,19 +2161,23 @@ var require_get_vercel_oidc_token = __commonJS({
2096
2161
  }
2097
2162
  try {
2098
2163
  const [{ getTokenPayload, isExpired }, { refreshToken }] = await Promise.all([
2099
- await import('./token-util-NEHG7TUY-EHD5JYKF.js'),
2100
- await import('./token-6GSAFR2W-HVOHPJXC.js')
2164
+ await import('./token-util-RMHT2CPJ-HCMQIDTV.js'),
2165
+ await import('./token-APYSY3BW-INR55PKP.js')
2101
2166
  ]);
2102
2167
  if (!token || isExpired(getTokenPayload(token))) {
2103
2168
  await refreshToken();
2104
2169
  token = getVercelOidcTokenSync2();
2105
2170
  }
2106
2171
  } catch (error) {
2107
- if (err?.message && error instanceof Error) {
2108
- error.message = `${err.message}
2172
+ let message = err instanceof Error ? err.message : "";
2173
+ if (error instanceof Error) {
2174
+ message = `${message}
2109
2175
  ${error.message}`;
2110
2176
  }
2111
- throw new import_token_error.VercelOidcTokenError(`Failed to refresh OIDC token`, error);
2177
+ if (message) {
2178
+ throw new import_token_error.VercelOidcTokenError(message);
2179
+ }
2180
+ throw error;
2112
2181
  }
2113
2182
  return token;
2114
2183
  }
@@ -2124,7 +2193,7 @@ ${error.message}`;
2124
2193
  }
2125
2194
  });
2126
2195
  var require_dist = __commonJS({
2127
- "../../../node_modules/.pnpm/@vercel+oidc@3.0.5/node_modules/@vercel/oidc/dist/index.js"(exports$1, module) {
2196
+ "../../../node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/index.js"(exports$1, module) {
2128
2197
  var __defProp2 = Object.defineProperty;
2129
2198
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
2130
2199
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -2155,18 +2224,18 @@ var require_dist = __commonJS({
2155
2224
  });
2156
2225
  var import_oidc = __toESM(require_dist(), 1);
2157
2226
  var import_oidc2 = __toESM(require_dist(), 1);
2158
- var marker15 = "vercel.ai.gateway.error";
2159
- var symbol15 = Symbol.for(marker15);
2160
- var _a15;
2161
- var _b;
2162
- var GatewayError = class _GatewayError extends (_b = Error, _a15 = symbol15, _b) {
2227
+ var marker16 = "vercel.ai.gateway.error";
2228
+ var symbol16 = Symbol.for(marker16);
2229
+ var _a16;
2230
+ var _b16;
2231
+ var GatewayError = class _GatewayError extends (_b16 = Error, _a16 = symbol16, _b16) {
2163
2232
  constructor({
2164
2233
  message,
2165
2234
  statusCode = 500,
2166
2235
  cause
2167
2236
  }) {
2168
2237
  super(message);
2169
- this[_a15] = true;
2238
+ this[_a16] = true;
2170
2239
  this.statusCode = statusCode;
2171
2240
  this.cause = cause;
2172
2241
  }
@@ -2179,15 +2248,15 @@ var GatewayError = class _GatewayError extends (_b = Error, _a15 = symbol15, _b)
2179
2248
  return _GatewayError.hasMarker(error);
2180
2249
  }
2181
2250
  static hasMarker(error) {
2182
- return typeof error === "object" && error !== null && symbol15 in error && error[symbol15] === true;
2251
+ return typeof error === "object" && error !== null && symbol16 in error && error[symbol16] === true;
2183
2252
  }
2184
2253
  };
2185
- var name14 = "GatewayAuthenticationError";
2186
- var marker22 = `vercel.ai.gateway.error.${name14}`;
2254
+ var name15 = "GatewayAuthenticationError";
2255
+ var marker22 = `vercel.ai.gateway.error.${name15}`;
2187
2256
  var symbol22 = Symbol.for(marker22);
2188
2257
  var _a22;
2189
- var _b2;
2190
- var GatewayAuthenticationError = class _GatewayAuthenticationError extends (_b2 = GatewayError, _a22 = symbol22, _b2) {
2258
+ var _b22;
2259
+ var GatewayAuthenticationError = class _GatewayAuthenticationError extends (_b22 = GatewayError, _a22 = symbol22, _b22) {
2191
2260
  constructor({
2192
2261
  message = "Authentication failed",
2193
2262
  statusCode = 401,
@@ -2195,7 +2264,7 @@ var GatewayAuthenticationError = class _GatewayAuthenticationError extends (_b2
2195
2264
  } = {}) {
2196
2265
  super({ message, statusCode, cause });
2197
2266
  this[_a22] = true;
2198
- this.name = name14;
2267
+ this.name = name15;
2199
2268
  this.type = "authentication_error";
2200
2269
  }
2201
2270
  static isInstance(error) {
@@ -2245,8 +2314,8 @@ var name22 = "GatewayInvalidRequestError";
2245
2314
  var marker32 = `vercel.ai.gateway.error.${name22}`;
2246
2315
  var symbol32 = Symbol.for(marker32);
2247
2316
  var _a32;
2248
- var _b3;
2249
- var GatewayInvalidRequestError = class extends (_b3 = GatewayError, _a32 = symbol32, _b3) {
2317
+ var _b32;
2318
+ var GatewayInvalidRequestError = class extends (_b32 = GatewayError, _a32 = symbol32, _b32) {
2250
2319
  constructor({
2251
2320
  message = "Invalid request",
2252
2321
  statusCode = 400,
@@ -2265,8 +2334,8 @@ var name32 = "GatewayRateLimitError";
2265
2334
  var marker42 = `vercel.ai.gateway.error.${name32}`;
2266
2335
  var symbol42 = Symbol.for(marker42);
2267
2336
  var _a42;
2268
- var _b4;
2269
- var GatewayRateLimitError = class extends (_b4 = GatewayError, _a42 = symbol42, _b4) {
2337
+ var _b42;
2338
+ var GatewayRateLimitError = class extends (_b42 = GatewayError, _a42 = symbol42, _b42) {
2270
2339
  constructor({
2271
2340
  message = "Rate limit exceeded",
2272
2341
  statusCode = 429,
@@ -2292,8 +2361,8 @@ var modelNotFoundParamSchema = lazyValidator(
2292
2361
  )
2293
2362
  );
2294
2363
  var _a52;
2295
- var _b5;
2296
- var GatewayModelNotFoundError = class extends (_b5 = GatewayError, _a52 = symbol52, _b5) {
2364
+ var _b52;
2365
+ var GatewayModelNotFoundError = class extends (_b52 = GatewayError, _a52 = symbol52, _b52) {
2297
2366
  constructor({
2298
2367
  message = "Model not found",
2299
2368
  statusCode = 404,
@@ -2314,8 +2383,8 @@ var name52 = "GatewayInternalServerError";
2314
2383
  var marker62 = `vercel.ai.gateway.error.${name52}`;
2315
2384
  var symbol62 = Symbol.for(marker62);
2316
2385
  var _a62;
2317
- var _b6;
2318
- var GatewayInternalServerError = class extends (_b6 = GatewayError, _a62 = symbol62, _b6) {
2386
+ var _b62;
2387
+ var GatewayInternalServerError = class extends (_b62 = GatewayError, _a62 = symbol62, _b62) {
2319
2388
  constructor({
2320
2389
  message = "Internal server error",
2321
2390
  statusCode = 500,
@@ -2334,8 +2403,8 @@ var name62 = "GatewayResponseError";
2334
2403
  var marker72 = `vercel.ai.gateway.error.${name62}`;
2335
2404
  var symbol72 = Symbol.for(marker72);
2336
2405
  var _a72;
2337
- var _b7;
2338
- var GatewayResponseError = class extends (_b7 = GatewayError, _a72 = symbol72, _b7) {
2406
+ var _b72;
2407
+ var GatewayResponseError = class extends (_b72 = GatewayError, _a72 = symbol72, _b72) {
2339
2408
  constructor({
2340
2409
  message = "Invalid response from Gateway",
2341
2410
  statusCode = 502,
@@ -2419,21 +2488,85 @@ var gatewayErrorResponseSchema = lazyValidator(
2419
2488
  })
2420
2489
  )
2421
2490
  );
2422
- function asGatewayError(error, authMethod) {
2423
- var _a83;
2491
+ var name72 = "GatewayTimeoutError";
2492
+ var marker82 = `vercel.ai.gateway.error.${name72}`;
2493
+ var symbol82 = Symbol.for(marker82);
2494
+ var _a82;
2495
+ var _b82;
2496
+ var GatewayTimeoutError = class _GatewayTimeoutError extends (_b82 = GatewayError, _a82 = symbol82, _b82) {
2497
+ constructor({
2498
+ message = "Request timed out",
2499
+ statusCode = 408,
2500
+ cause
2501
+ } = {}) {
2502
+ super({ message, statusCode, cause });
2503
+ this[_a82] = true;
2504
+ this.name = name72;
2505
+ this.type = "timeout_error";
2506
+ }
2507
+ static isInstance(error) {
2508
+ return GatewayError.hasMarker(error) && symbol82 in error;
2509
+ }
2510
+ /**
2511
+ * Creates a helpful timeout error message with troubleshooting guidance
2512
+ */
2513
+ static createTimeoutError({
2514
+ originalMessage,
2515
+ statusCode = 408,
2516
+ cause
2517
+ }) {
2518
+ const message = `Gateway request timed out: ${originalMessage}
2519
+
2520
+ 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`;
2521
+ return new _GatewayTimeoutError({
2522
+ message,
2523
+ statusCode,
2524
+ cause
2525
+ });
2526
+ }
2527
+ };
2528
+ function isTimeoutError(error) {
2529
+ if (!(error instanceof Error)) {
2530
+ return false;
2531
+ }
2532
+ const errorCode = error.code;
2533
+ if (typeof errorCode === "string") {
2534
+ const undiciTimeoutCodes = [
2535
+ "UND_ERR_HEADERS_TIMEOUT",
2536
+ "UND_ERR_BODY_TIMEOUT",
2537
+ "UND_ERR_CONNECT_TIMEOUT"
2538
+ ];
2539
+ return undiciTimeoutCodes.includes(errorCode);
2540
+ }
2541
+ return false;
2542
+ }
2543
+ async function asGatewayError(error, authMethod) {
2544
+ var _a93;
2424
2545
  if (GatewayError.isInstance(error)) {
2425
2546
  return error;
2426
2547
  }
2548
+ if (isTimeoutError(error)) {
2549
+ return GatewayTimeoutError.createTimeoutError({
2550
+ originalMessage: error instanceof Error ? error.message : "Unknown error",
2551
+ cause: error
2552
+ });
2553
+ }
2427
2554
  if (APICallError.isInstance(error)) {
2428
- return createGatewayErrorFromResponse({
2555
+ if (error.cause && isTimeoutError(error.cause)) {
2556
+ return GatewayTimeoutError.createTimeoutError({
2557
+ originalMessage: error.message,
2558
+ cause: error
2559
+ });
2560
+ }
2561
+ return await createGatewayErrorFromResponse({
2429
2562
  response: extractApiCallResponse(error),
2430
- statusCode: (_a83 = error.statusCode) != null ? _a83 : 500,
2563
+ statusCode: (_a93 = error.statusCode) != null ? _a93 : 500,
2431
2564
  defaultMessage: "Gateway request failed",
2432
2565
  cause: error,
2433
2566
  authMethod
2434
2567
  });
2435
2568
  }
2436
- return createGatewayErrorFromResponse({
2569
+ return await createGatewayErrorFromResponse({
2437
2570
  response: {},
2438
2571
  statusCode: 500,
2439
2572
  defaultMessage: error instanceof Error ? `Gateway request failed: ${error.message}` : "Unknown Gateway error",
@@ -2714,7 +2847,7 @@ var GatewayEmbeddingModel = class {
2714
2847
  abortSignal,
2715
2848
  providerOptions
2716
2849
  }) {
2717
- var _a83;
2850
+ var _a93;
2718
2851
  const resolvedHeaders = await resolve(this.config.headers());
2719
2852
  try {
2720
2853
  const {
@@ -2745,7 +2878,7 @@ var GatewayEmbeddingModel = class {
2745
2878
  });
2746
2879
  return {
2747
2880
  embeddings: responseBody.embeddings,
2748
- usage: (_a83 = responseBody.usage) != null ? _a83 : void 0,
2881
+ usage: (_a93 = responseBody.usage) != null ? _a93 : void 0,
2749
2882
  providerMetadata: responseBody.providerMetadata,
2750
2883
  response: { headers: responseHeaders, body: rawValue }
2751
2884
  };
@@ -2792,7 +2925,7 @@ var GatewayImageModel = class {
2792
2925
  headers,
2793
2926
  abortSignal
2794
2927
  }) {
2795
- var _a83;
2928
+ var _a93, _b92, _c, _d;
2796
2929
  const resolvedHeaders = await resolve(this.config.headers());
2797
2930
  try {
2798
2931
  const {
@@ -2827,16 +2960,23 @@ var GatewayImageModel = class {
2827
2960
  return {
2828
2961
  images: responseBody.images,
2829
2962
  // Always base64 strings from server
2830
- warnings: (_a83 = responseBody.warnings) != null ? _a83 : [],
2963
+ warnings: (_a93 = responseBody.warnings) != null ? _a93 : [],
2831
2964
  providerMetadata: responseBody.providerMetadata,
2832
2965
  response: {
2833
2966
  timestamp: /* @__PURE__ */ new Date(),
2834
2967
  modelId: this.modelId,
2835
2968
  headers: responseHeaders
2969
+ },
2970
+ ...responseBody.usage != null && {
2971
+ usage: {
2972
+ inputTokens: (_b92 = responseBody.usage.inputTokens) != null ? _b92 : void 0,
2973
+ outputTokens: (_c = responseBody.usage.outputTokens) != null ? _c : void 0,
2974
+ totalTokens: (_d = responseBody.usage.totalTokens) != null ? _d : void 0
2975
+ }
2836
2976
  }
2837
2977
  };
2838
2978
  } catch (error) {
2839
- throw asGatewayError(error, await parseAuthMethod(resolvedHeaders));
2979
+ throw await asGatewayError(error, await parseAuthMethod(resolvedHeaders));
2840
2980
  }
2841
2981
  }
2842
2982
  getUrl() {
@@ -2852,6 +2992,11 @@ var GatewayImageModel = class {
2852
2992
  var providerMetadataEntrySchema = z.object({
2853
2993
  images: z.array(z.unknown()).optional()
2854
2994
  }).catchall(z.unknown());
2995
+ var gatewayImageUsageSchema = z.object({
2996
+ inputTokens: z.number().nullish(),
2997
+ outputTokens: z.number().nullish(),
2998
+ totalTokens: z.number().nullish()
2999
+ });
2855
3000
  var gatewayImageResponseSchema = z.object({
2856
3001
  images: z.array(z.string()),
2857
3002
  // Always base64 strings over the wire
@@ -2861,21 +3006,196 @@ var gatewayImageResponseSchema = z.object({
2861
3006
  message: z.string()
2862
3007
  })
2863
3008
  ).optional(),
2864
- providerMetadata: z.record(z.string(), providerMetadataEntrySchema).optional()
3009
+ providerMetadata: z.record(z.string(), providerMetadataEntrySchema).optional(),
3010
+ usage: gatewayImageUsageSchema.optional()
3011
+ });
3012
+ var parallelSearchInputSchema = lazySchema(
3013
+ () => zodSchema(
3014
+ z$1.object({
3015
+ objective: z$1.string().describe(
3016
+ "Natural-language description of the web research goal, including source or freshness guidance and broader context from the task. Maximum 5000 characters."
3017
+ ),
3018
+ search_queries: z$1.array(z$1.string()).optional().describe(
3019
+ "Optional search queries to supplement the objective. Maximum 200 characters per query."
3020
+ ),
3021
+ mode: z$1.enum(["one-shot", "agentic"]).optional().describe(
3022
+ 'Mode preset: "one-shot" for comprehensive results with longer excerpts (default), "agentic" for concise, token-efficient results for multi-step workflows.'
3023
+ ),
3024
+ max_results: z$1.number().optional().describe(
3025
+ "Maximum number of results to return (1-20). Defaults to 10 if not specified."
3026
+ ),
3027
+ source_policy: z$1.object({
3028
+ include_domains: z$1.array(z$1.string()).optional().describe("List of domains to include in search results."),
3029
+ exclude_domains: z$1.array(z$1.string()).optional().describe("List of domains to exclude from search results."),
3030
+ after_date: z$1.string().optional().describe(
3031
+ "Only include results published after this date (ISO 8601 format)."
3032
+ )
3033
+ }).optional().describe(
3034
+ "Source policy for controlling which domains to include/exclude and freshness."
3035
+ ),
3036
+ excerpts: z$1.object({
3037
+ max_chars_per_result: z$1.number().optional().describe("Maximum characters per result."),
3038
+ max_chars_total: z$1.number().optional().describe("Maximum total characters across all results.")
3039
+ }).optional().describe("Excerpt configuration for controlling result length."),
3040
+ fetch_policy: z$1.object({
3041
+ max_age_seconds: z$1.number().optional().describe(
3042
+ "Maximum age in seconds for cached content. Set to 0 to always fetch fresh content."
3043
+ )
3044
+ }).optional().describe("Fetch policy for controlling content freshness.")
3045
+ })
3046
+ )
3047
+ );
3048
+ var parallelSearchOutputSchema = lazySchema(
3049
+ () => zodSchema(
3050
+ z$1.union([
3051
+ // Success response
3052
+ z$1.object({
3053
+ searchId: z$1.string(),
3054
+ results: z$1.array(
3055
+ z$1.object({
3056
+ url: z$1.string(),
3057
+ title: z$1.string(),
3058
+ excerpt: z$1.string(),
3059
+ publishDate: z$1.string().nullable().optional(),
3060
+ relevanceScore: z$1.number().optional()
3061
+ })
3062
+ )
3063
+ }),
3064
+ // Error response
3065
+ z$1.object({
3066
+ error: z$1.enum([
3067
+ "api_error",
3068
+ "rate_limit",
3069
+ "timeout",
3070
+ "invalid_input",
3071
+ "configuration_error",
3072
+ "unknown"
3073
+ ]),
3074
+ statusCode: z$1.number().optional(),
3075
+ message: z$1.string()
3076
+ })
3077
+ ])
3078
+ )
3079
+ );
3080
+ var parallelSearchToolFactory = createProviderDefinedToolFactoryWithOutputSchema({
3081
+ id: "gateway.parallel_search",
3082
+ name: "parallel_search",
3083
+ inputSchema: parallelSearchInputSchema,
3084
+ outputSchema: parallelSearchOutputSchema
2865
3085
  });
3086
+ var parallelSearch = (config = {}) => parallelSearchToolFactory(config);
3087
+ var perplexitySearchInputSchema = lazySchema(
3088
+ () => zodSchema(
3089
+ z$1.object({
3090
+ query: z$1.union([z$1.string(), z$1.array(z$1.string())]).describe(
3091
+ "Search query (string) or multiple queries (array of up to 5 strings). Multi-query searches return combined results from all queries."
3092
+ ),
3093
+ max_results: z$1.number().optional().describe(
3094
+ "Maximum number of search results to return (1-20, default: 10)"
3095
+ ),
3096
+ max_tokens_per_page: z$1.number().optional().describe(
3097
+ "Maximum number of tokens to extract per search result page (256-2048, default: 2048)"
3098
+ ),
3099
+ max_tokens: z$1.number().optional().describe(
3100
+ "Maximum total tokens across all search results (default: 25000, max: 1000000)"
3101
+ ),
3102
+ country: z$1.string().optional().describe(
3103
+ "Two-letter ISO 3166-1 alpha-2 country code for regional search results (e.g., 'US', 'GB', 'FR')"
3104
+ ),
3105
+ search_domain_filter: z$1.array(z$1.string()).optional().describe(
3106
+ "List of domains to include or exclude from search results (max 20). To include: ['nature.com', 'science.org']. To exclude: ['-example.com', '-spam.net']"
3107
+ ),
3108
+ search_language_filter: z$1.array(z$1.string()).optional().describe(
3109
+ "List of ISO 639-1 language codes to filter results (max 10, lowercase). Examples: ['en', 'fr', 'de']"
3110
+ ),
3111
+ search_after_date: z$1.string().optional().describe(
3112
+ "Include only results published after this date. Format: 'MM/DD/YYYY' (e.g., '3/1/2025'). Cannot be used with search_recency_filter."
3113
+ ),
3114
+ search_before_date: z$1.string().optional().describe(
3115
+ "Include only results published before this date. Format: 'MM/DD/YYYY' (e.g., '3/15/2025'). Cannot be used with search_recency_filter."
3116
+ ),
3117
+ last_updated_after_filter: z$1.string().optional().describe(
3118
+ "Include only results last updated after this date. Format: 'MM/DD/YYYY' (e.g., '3/1/2025'). Cannot be used with search_recency_filter."
3119
+ ),
3120
+ last_updated_before_filter: z$1.string().optional().describe(
3121
+ "Include only results last updated before this date. Format: 'MM/DD/YYYY' (e.g., '3/15/2025'). Cannot be used with search_recency_filter."
3122
+ ),
3123
+ search_recency_filter: z$1.enum(["day", "week", "month", "year"]).optional().describe(
3124
+ "Filter results by relative time period. Cannot be used with search_after_date or search_before_date."
3125
+ )
3126
+ })
3127
+ )
3128
+ );
3129
+ var perplexitySearchOutputSchema = lazySchema(
3130
+ () => zodSchema(
3131
+ z$1.union([
3132
+ // Success response
3133
+ z$1.object({
3134
+ results: z$1.array(
3135
+ z$1.object({
3136
+ title: z$1.string(),
3137
+ url: z$1.string(),
3138
+ snippet: z$1.string(),
3139
+ date: z$1.string().optional(),
3140
+ lastUpdated: z$1.string().optional()
3141
+ })
3142
+ ),
3143
+ id: z$1.string()
3144
+ }),
3145
+ // Error response
3146
+ z$1.object({
3147
+ error: z$1.enum([
3148
+ "api_error",
3149
+ "rate_limit",
3150
+ "timeout",
3151
+ "invalid_input",
3152
+ "unknown"
3153
+ ]),
3154
+ statusCode: z$1.number().optional(),
3155
+ message: z$1.string()
3156
+ })
3157
+ ])
3158
+ )
3159
+ );
3160
+ var perplexitySearchToolFactory = createProviderDefinedToolFactoryWithOutputSchema({
3161
+ id: "gateway.perplexity_search",
3162
+ name: "perplexity_search",
3163
+ inputSchema: perplexitySearchInputSchema,
3164
+ outputSchema: perplexitySearchOutputSchema
3165
+ });
3166
+ var perplexitySearch = (config = {}) => perplexitySearchToolFactory(config);
3167
+ var gatewayTools = {
3168
+ /**
3169
+ * Search the web using Parallel AI's Search API for LLM-optimized excerpts.
3170
+ *
3171
+ * Takes a natural language objective and returns relevant excerpts,
3172
+ * replacing multiple keyword searches with a single call for broad
3173
+ * or complex queries. Supports different search types for depth vs
3174
+ * breadth tradeoffs.
3175
+ */
3176
+ parallelSearch,
3177
+ /**
3178
+ * Search the web using Perplexity's Search API for real-time information,
3179
+ * news, research papers, and articles.
3180
+ *
3181
+ * Provides ranked search results with advanced filtering options including
3182
+ * domain, language, date range, and recency filters.
3183
+ */
3184
+ perplexitySearch
3185
+ };
2866
3186
  async function getVercelRequestId() {
2867
- var _a83;
2868
- return (_a83 = (0, import_oidc.getContext)().headers) == null ? void 0 : _a83["x-vercel-id"];
3187
+ var _a93;
3188
+ return (_a93 = (0, import_oidc.getContext)().headers) == null ? void 0 : _a93["x-vercel-id"];
2869
3189
  }
2870
- var VERSION2 = "2.0.15";
3190
+ var VERSION2 = "2.0.58";
2871
3191
  var AI_GATEWAY_PROTOCOL_VERSION = "0.0.1";
2872
3192
  function createGatewayProvider(options = {}) {
2873
- var _a83, _b8;
3193
+ var _a93, _b92;
2874
3194
  let pendingMetadata = null;
2875
3195
  let metadataCache = null;
2876
- const cacheRefreshMillis = (_a83 = options.metadataCacheRefreshMillis) != null ? _a83 : 1e3 * 60 * 5;
3196
+ const cacheRefreshMillis = (_a93 = options.metadataCacheRefreshMillis) != null ? _a93 : 1e3 * 60 * 5;
2877
3197
  let lastFetchTime = 0;
2878
- const baseURL = (_b8 = withoutTrailingSlash(options.baseURL)) != null ? _b8 : "https://ai-gateway.vercel.sh/v1/ai";
3198
+ const baseURL = (_b92 = withoutTrailingSlash(options.baseURL)) != null ? _b92 : "https://ai-gateway.vercel.sh/v1/ai";
2879
3199
  const getHeaders = async () => {
2880
3200
  const auth = await getGatewayAuthToken(options);
2881
3201
  if (auth) {
@@ -2908,13 +3228,18 @@ function createGatewayProvider(options = {}) {
2908
3228
  settingValue: void 0,
2909
3229
  environmentVariableName: "VERCEL_REGION"
2910
3230
  });
3231
+ const projectId = loadOptionalSetting({
3232
+ settingValue: void 0,
3233
+ environmentVariableName: "VERCEL_PROJECT_ID"
3234
+ });
2911
3235
  return async () => {
2912
3236
  const requestId = await getVercelRequestId();
2913
3237
  return {
2914
3238
  ...deploymentId && { "ai-o11y-deployment-id": deploymentId },
2915
3239
  ...environment && { "ai-o11y-environment": environment },
2916
3240
  ...region && { "ai-o11y-region": region },
2917
- ...requestId && { "ai-o11y-request-id": requestId }
3241
+ ...requestId && { "ai-o11y-request-id": requestId },
3242
+ ...projectId && { "ai-o11y-project-id": projectId }
2918
3243
  };
2919
3244
  };
2920
3245
  };
@@ -2928,8 +3253,8 @@ function createGatewayProvider(options = {}) {
2928
3253
  });
2929
3254
  };
2930
3255
  const getAvailableModels = async () => {
2931
- var _a922, _b9, _c;
2932
- const now2 = (_c = (_b9 = (_a922 = options._internal) == null ? void 0 : _a922.currentDate) == null ? void 0 : _b9.call(_a922).getTime()) != null ? _c : Date.now();
3256
+ var _a1022, _b102, _c;
3257
+ const now2 = (_c = (_b102 = (_a1022 = options._internal) == null ? void 0 : _a1022.currentDate) == null ? void 0 : _b102.call(_a1022).getTime()) != null ? _c : Date.now();
2933
3258
  if (!pendingMetadata || now2 - lastFetchTime > cacheRefreshMillis) {
2934
3259
  lastFetchTime = now2;
2935
3260
  pendingMetadata = new GatewayFetchMetadata({
@@ -2989,6 +3314,7 @@ function createGatewayProvider(options = {}) {
2989
3314
  o11yHeaders: createO11yHeaders()
2990
3315
  });
2991
3316
  };
3317
+ provider.tools = gatewayTools;
2992
3318
  return provider;
2993
3319
  }
2994
3320
  createGatewayProvider();
@@ -3084,11 +3410,11 @@ var major = VERSION22.split(".")[0];
3084
3410
  var GLOBAL_OPENTELEMETRY_API_KEY = /* @__PURE__ */ Symbol.for("opentelemetry.js.api." + major);
3085
3411
  var _global = _globalThis;
3086
3412
  function registerGlobal(type, instance, diag, allowOverride) {
3087
- var _a16;
3413
+ var _a162;
3088
3414
  if (allowOverride === void 0) {
3089
3415
  allowOverride = false;
3090
3416
  }
3091
- var api = _global[GLOBAL_OPENTELEMETRY_API_KEY] = (_a16 = _global[GLOBAL_OPENTELEMETRY_API_KEY]) !== null && _a16 !== void 0 ? _a16 : {
3417
+ var api = _global[GLOBAL_OPENTELEMETRY_API_KEY] = (_a162 = _global[GLOBAL_OPENTELEMETRY_API_KEY]) !== null && _a162 !== void 0 ? _a162 : {
3092
3418
  version: VERSION22
3093
3419
  };
3094
3420
  if (!allowOverride && api[type]) {
@@ -3106,12 +3432,12 @@ function registerGlobal(type, instance, diag, allowOverride) {
3106
3432
  return true;
3107
3433
  }
3108
3434
  function getGlobal(type) {
3109
- var _a16, _b8;
3110
- var globalVersion = (_a16 = _global[GLOBAL_OPENTELEMETRY_API_KEY]) === null || _a16 === void 0 ? void 0 : _a16.version;
3435
+ var _a162, _b92;
3436
+ var globalVersion = (_a162 = _global[GLOBAL_OPENTELEMETRY_API_KEY]) === null || _a162 === void 0 ? void 0 : _a162.version;
3111
3437
  if (!globalVersion || !isCompatible(globalVersion)) {
3112
3438
  return;
3113
3439
  }
3114
- return (_b8 = _global[GLOBAL_OPENTELEMETRY_API_KEY]) === null || _b8 === void 0 ? void 0 : _b8[type];
3440
+ return (_b92 = _global[GLOBAL_OPENTELEMETRY_API_KEY]) === null || _b92 === void 0 ? void 0 : _b92[type];
3115
3441
  }
3116
3442
  function unregisterGlobal(type, diag) {
3117
3443
  diag.debug("@opentelemetry/api: Unregistering a global for " + type + " v" + VERSION22 + ".");
@@ -3276,13 +3602,13 @@ var DiagAPI = (
3276
3602
  }
3277
3603
  var self = this;
3278
3604
  var setLogger = function(logger, optionsOrLogLevel) {
3279
- var _a16, _b8, _c;
3605
+ var _a162, _b92, _c;
3280
3606
  if (optionsOrLogLevel === void 0) {
3281
3607
  optionsOrLogLevel = { logLevel: DiagLogLevel.INFO };
3282
3608
  }
3283
3609
  if (logger === self) {
3284
3610
  var err = new Error("Cannot use diag as the logger for itself. Please use a DiagLogger implementation like ConsoleDiagLogger or a custom implementation");
3285
- self.error((_a16 = err.stack) !== null && _a16 !== void 0 ? _a16 : err.message);
3611
+ self.error((_a162 = err.stack) !== null && _a162 !== void 0 ? _a162 : err.message);
3286
3612
  return false;
3287
3613
  }
3288
3614
  if (typeof optionsOrLogLevel === "number") {
@@ -3291,7 +3617,7 @@ var DiagAPI = (
3291
3617
  };
3292
3618
  }
3293
3619
  var oldLogger = getGlobal("diag");
3294
- var newLogger = createLogLevelDiagLogger((_b8 = optionsOrLogLevel.logLevel) !== null && _b8 !== void 0 ? _b8 : DiagLogLevel.INFO, logger);
3620
+ var newLogger = createLogLevelDiagLogger((_b92 = optionsOrLogLevel.logLevel) !== null && _b92 !== void 0 ? _b92 : DiagLogLevel.INFO, logger);
3295
3621
  if (oldLogger && !optionsOrLogLevel.suppressOverrideMessage) {
3296
3622
  var stack = (_c = new Error().stack) !== null && _c !== void 0 ? _c : "<failed to generate stacktrace>";
3297
3623
  oldLogger.warn("Current logger will be overwritten from " + stack);
@@ -3447,12 +3773,12 @@ var ContextAPI = (
3447
3773
  return this._getContextManager().active();
3448
3774
  };
3449
3775
  ContextAPI2.prototype.with = function(context, fn, thisArg) {
3450
- var _a16;
3776
+ var _a162;
3451
3777
  var args = [];
3452
3778
  for (var _i = 3; _i < arguments.length; _i++) {
3453
3779
  args[_i - 3] = arguments[_i];
3454
3780
  }
3455
- return (_a16 = this._getContextManager()).with.apply(_a16, __spreadArray4([context, fn, thisArg], __read4(args), false));
3781
+ return (_a162 = this._getContextManager()).with.apply(_a162, __spreadArray4([context, fn, thisArg], __read4(args), false));
3456
3782
  };
3457
3783
  ContextAPI2.prototype.bind = function(context, target) {
3458
3784
  return this._getContextManager().bind(context, target);
@@ -3539,8 +3865,8 @@ function setSpanContext(context, spanContext) {
3539
3865
  return setSpan(context, new NonRecordingSpan(spanContext));
3540
3866
  }
3541
3867
  function getSpanContext(context) {
3542
- var _a16;
3543
- return (_a16 = getSpan(context)) === null || _a16 === void 0 ? void 0 : _a16.spanContext();
3868
+ var _a162;
3869
+ return (_a162 = getSpan(context)) === null || _a162 === void 0 ? void 0 : _a162.spanContext();
3544
3870
  }
3545
3871
  var VALID_TRACEID_REGEX = /^([0-9a-f]{32})$/i;
3546
3872
  var VALID_SPANID_REGEX = /^[0-9a-f]{16}$/i;
@@ -3653,19 +3979,19 @@ var ProxyTracerProvider = (
3653
3979
  function ProxyTracerProvider2() {
3654
3980
  }
3655
3981
  ProxyTracerProvider2.prototype.getTracer = function(name16, version, options) {
3656
- var _a16;
3657
- return (_a16 = this.getDelegateTracer(name16, version, options)) !== null && _a16 !== void 0 ? _a16 : new ProxyTracer(this, name16, version, options);
3982
+ var _a162;
3983
+ return (_a162 = this.getDelegateTracer(name16, version, options)) !== null && _a162 !== void 0 ? _a162 : new ProxyTracer(this, name16, version, options);
3658
3984
  };
3659
3985
  ProxyTracerProvider2.prototype.getDelegate = function() {
3660
- var _a16;
3661
- return (_a16 = this._delegate) !== null && _a16 !== void 0 ? _a16 : NOOP_TRACER_PROVIDER;
3986
+ var _a162;
3987
+ return (_a162 = this._delegate) !== null && _a162 !== void 0 ? _a162 : NOOP_TRACER_PROVIDER;
3662
3988
  };
3663
3989
  ProxyTracerProvider2.prototype.setDelegate = function(delegate) {
3664
3990
  this._delegate = delegate;
3665
3991
  };
3666
3992
  ProxyTracerProvider2.prototype.getDelegateTracer = function(name16, version, options) {
3667
- var _a16;
3668
- return (_a16 = this._delegate) === null || _a16 === void 0 ? void 0 : _a16.getTracer(name16, version, options);
3993
+ var _a162;
3994
+ return (_a162 = this._delegate) === null || _a162 === void 0 ? void 0 : _a162.getTracer(name16, version, options);
3669
3995
  };
3670
3996
  return ProxyTracerProvider2;
3671
3997
  })()
@@ -3755,8 +4081,8 @@ var dataContentSchema = z.union([
3755
4081
  z.custom(
3756
4082
  // Buffer might not be available in some environments such as CloudFlare:
3757
4083
  (value) => {
3758
- var _a16, _b8;
3759
- return (_b8 = (_a16 = globalThis.Buffer) == null ? void 0 : _a16.isBuffer(value)) != null ? _b8 : false;
4084
+ var _a162, _b92;
4085
+ return (_b92 = (_a162 = globalThis.Buffer) == null ? void 0 : _a162.isBuffer(value)) != null ? _b92 : false;
3760
4086
  },
3761
4087
  { message: "Must be a Buffer" }
3762
4088
  )
@@ -4345,7 +4671,7 @@ function processUIMessageStream({
4345
4671
  new TransformStream({
4346
4672
  async transform(chunk, controller) {
4347
4673
  await runUpdateMessageJob(async ({ state, write }) => {
4348
- var _a16, _b8, _c, _d;
4674
+ var _a162, _b92, _c, _d;
4349
4675
  function getToolInvocation(toolCallId) {
4350
4676
  const toolInvocations = state.message.parts.filter(isToolUIPart);
4351
4677
  const toolInvocation = toolInvocations.find(
@@ -4406,7 +4732,7 @@ function processUIMessageStream({
4406
4732
  }
4407
4733
  }
4408
4734
  function updateDynamicToolPart(options) {
4409
- var _a17, _b22;
4735
+ var _a17, _b222;
4410
4736
  const part = state.message.parts.find(
4411
4737
  (part2) => part2.type === "dynamic-tool" && part2.toolCallId === options.toolCallId
4412
4738
  );
@@ -4420,7 +4746,7 @@ function processUIMessageStream({
4420
4746
  anyPart.errorText = anyOptions.errorText;
4421
4747
  anyPart.rawInput = (_a17 = anyOptions.rawInput) != null ? _a17 : anyPart.rawInput;
4422
4748
  anyPart.preliminary = anyOptions.preliminary;
4423
- anyPart.providerExecuted = (_b22 = anyOptions.providerExecuted) != null ? _b22 : part.providerExecuted;
4749
+ anyPart.providerExecuted = (_b222 = anyOptions.providerExecuted) != null ? _b222 : part.providerExecuted;
4424
4750
  if (anyOptions.providerMetadata != null && part.state === "input-available") {
4425
4751
  part.callProviderMetadata = anyOptions.providerMetadata;
4426
4752
  }
@@ -4467,14 +4793,14 @@ function processUIMessageStream({
4467
4793
  case "text-delta": {
4468
4794
  const textPart = state.activeTextParts[chunk.id];
4469
4795
  textPart.text += chunk.delta;
4470
- textPart.providerMetadata = (_a16 = chunk.providerMetadata) != null ? _a16 : textPart.providerMetadata;
4796
+ textPart.providerMetadata = (_a162 = chunk.providerMetadata) != null ? _a162 : textPart.providerMetadata;
4471
4797
  write();
4472
4798
  break;
4473
4799
  }
4474
4800
  case "text-end": {
4475
4801
  const textPart = state.activeTextParts[chunk.id];
4476
4802
  textPart.state = "done";
4477
- textPart.providerMetadata = (_b8 = chunk.providerMetadata) != null ? _b8 : textPart.providerMetadata;
4803
+ textPart.providerMetadata = (_b92 = chunk.providerMetadata) != null ? _b92 : textPart.providerMetadata;
4478
4804
  delete state.activeTextParts[chunk.id];
4479
4805
  write();
4480
4806
  break;
@@ -4953,7 +5279,7 @@ var doWrap = ({
4953
5279
  modelId,
4954
5280
  providerId
4955
5281
  }) => {
4956
- var _a16, _b8, _c;
5282
+ var _a162, _b92, _c;
4957
5283
  async function doTransform({
4958
5284
  params,
4959
5285
  type
@@ -4962,8 +5288,8 @@ var doWrap = ({
4962
5288
  }
4963
5289
  return {
4964
5290
  specificationVersion: "v2",
4965
- provider: (_a16 = providerId != null ? providerId : overrideProvider == null ? void 0 : overrideProvider({ model })) != null ? _a16 : model.provider,
4966
- modelId: (_b8 = modelId != null ? modelId : overrideModelId == null ? void 0 : overrideModelId({ model })) != null ? _b8 : model.modelId,
5291
+ provider: (_a162 = providerId != null ? providerId : overrideProvider == null ? void 0 : overrideProvider({ model })) != null ? _a162 : model.provider,
5292
+ modelId: (_b92 = modelId != null ? modelId : overrideModelId == null ? void 0 : overrideModelId({ model })) != null ? _b92 : model.modelId,
4967
5293
  supportedUrls: (_c = overrideSupportedUrls == null ? void 0 : overrideSupportedUrls({ model })) != null ? _c : model.supportedUrls,
4968
5294
  async doGenerate(params) {
4969
5295
  const transformedParams = await doTransform({ params, type: "generate" });