@mastra/agent-builder 1.0.15 → 1.0.16-alpha.0

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
@@ -1,4 +1,4 @@
1
- import { __commonJS, require_token_error, __toESM } from './chunk-RQJR2QYC.js';
1
+ import { __commonJS, require_token_error, __toESM } from './chunk-DAXABV7F.js';
2
2
  import { Agent, isSupportedLanguageModel, tryGenerateWithJsonFallback, tryStreamWithJsonFallback } from '@mastra/core/agent';
3
3
  import { InMemoryStore } from '@mastra/core/storage';
4
4
  import { Memory } from '@mastra/memory';
@@ -4790,7 +4790,8 @@ var shouldAbortWorkflow = (stepResult) => {
4790
4790
  var marker = "vercel.ai.error";
4791
4791
  var symbol = Symbol.for(marker);
4792
4792
  var _a;
4793
- var _AISDKError = class _AISDKError2 extends Error {
4793
+ var _b;
4794
+ var AISDKError = class _AISDKError extends (_b = Error, _a = symbol, _b) {
4794
4795
  /**
4795
4796
  * Creates an AI SDK Error.
4796
4797
  *
@@ -4800,13 +4801,13 @@ var _AISDKError = class _AISDKError2 extends Error {
4800
4801
  * @param {unknown} [params.cause] - The underlying cause of the error.
4801
4802
  */
4802
4803
  constructor({
4803
- name: name143,
4804
+ name: name1422,
4804
4805
  message,
4805
4806
  cause
4806
4807
  }) {
4807
4808
  super(message);
4808
4809
  this[_a] = true;
4809
- this.name = name143;
4810
+ this.name = name1422;
4810
4811
  this.cause = cause;
4811
4812
  }
4812
4813
  /**
@@ -4815,20 +4816,19 @@ var _AISDKError = class _AISDKError2 extends Error {
4815
4816
  * @returns {boolean} True if the error is an AI SDK Error, false otherwise.
4816
4817
  */
4817
4818
  static isInstance(error) {
4818
- return _AISDKError2.hasMarker(error, marker);
4819
+ return _AISDKError.hasMarker(error, marker);
4819
4820
  }
4820
- static hasMarker(error, marker153) {
4821
- const markerSymbol = Symbol.for(marker153);
4821
+ static hasMarker(error, marker1522) {
4822
+ const markerSymbol = Symbol.for(marker1522);
4822
4823
  return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
4823
4824
  }
4824
4825
  };
4825
- _a = symbol;
4826
- var AISDKError = _AISDKError;
4827
4826
  var name = "AI_APICallError";
4828
4827
  var marker2 = `vercel.ai.error.${name}`;
4829
4828
  var symbol2 = Symbol.for(marker2);
4830
4829
  var _a2;
4831
- var APICallError = class extends AISDKError {
4830
+ var _b2;
4831
+ var APICallError = class extends (_b2 = AISDKError, _a2 = symbol2, _b2) {
4832
4832
  constructor({
4833
4833
  message,
4834
4834
  url,
@@ -4858,12 +4858,12 @@ var APICallError = class extends AISDKError {
4858
4858
  return AISDKError.hasMarker(error, marker2);
4859
4859
  }
4860
4860
  };
4861
- _a2 = symbol2;
4862
4861
  var name2 = "AI_EmptyResponseBodyError";
4863
4862
  var marker3 = `vercel.ai.error.${name2}`;
4864
4863
  var symbol3 = Symbol.for(marker3);
4865
4864
  var _a3;
4866
- var EmptyResponseBodyError = class extends AISDKError {
4865
+ var _b3;
4866
+ var EmptyResponseBodyError = class extends (_b3 = AISDKError, _a3 = symbol3, _b3) {
4867
4867
  // used in isInstance
4868
4868
  constructor({ message = "Empty response body" } = {}) {
4869
4869
  super({ name: name2, message });
@@ -4873,7 +4873,6 @@ var EmptyResponseBodyError = class extends AISDKError {
4873
4873
  return AISDKError.hasMarker(error, marker3);
4874
4874
  }
4875
4875
  };
4876
- _a3 = symbol3;
4877
4876
  function getErrorMessage(error) {
4878
4877
  if (error == null) {
4879
4878
  return "unknown error";
@@ -4890,7 +4889,8 @@ var name3 = "AI_InvalidArgumentError";
4890
4889
  var marker4 = `vercel.ai.error.${name3}`;
4891
4890
  var symbol4 = Symbol.for(marker4);
4892
4891
  var _a4;
4893
- var InvalidArgumentError = class extends AISDKError {
4892
+ var _b4;
4893
+ var InvalidArgumentError = class extends (_b4 = AISDKError, _a4 = symbol4, _b4) {
4894
4894
  constructor({
4895
4895
  message,
4896
4896
  cause,
@@ -4904,12 +4904,12 @@ var InvalidArgumentError = class extends AISDKError {
4904
4904
  return AISDKError.hasMarker(error, marker4);
4905
4905
  }
4906
4906
  };
4907
- _a4 = symbol4;
4908
4907
  var name6 = "AI_JSONParseError";
4909
4908
  var marker7 = `vercel.ai.error.${name6}`;
4910
4909
  var symbol7 = Symbol.for(marker7);
4911
4910
  var _a7;
4912
- var JSONParseError = class extends AISDKError {
4911
+ var _b7;
4912
+ var JSONParseError = class extends (_b7 = AISDKError, _a7 = symbol7, _b7) {
4913
4913
  constructor({ text: text2, cause }) {
4914
4914
  super({
4915
4915
  name: name6,
@@ -4924,12 +4924,12 @@ Error message: ${getErrorMessage(cause)}`,
4924
4924
  return AISDKError.hasMarker(error, marker7);
4925
4925
  }
4926
4926
  };
4927
- _a7 = symbol7;
4928
4927
  var name12 = "AI_TypeValidationError";
4929
4928
  var marker13 = `vercel.ai.error.${name12}`;
4930
4929
  var symbol13 = Symbol.for(marker13);
4931
4930
  var _a13;
4932
- var _TypeValidationError = class _TypeValidationError2 extends AISDKError {
4931
+ var _b13;
4932
+ var TypeValidationError = class _TypeValidationError extends (_b13 = AISDKError, _a13 = symbol13, _b13) {
4933
4933
  constructor({ value, cause }) {
4934
4934
  super({
4935
4935
  name: name12,
@@ -4957,11 +4957,9 @@ Error message: ${getErrorMessage(cause)}`,
4957
4957
  value,
4958
4958
  cause
4959
4959
  }) {
4960
- return _TypeValidationError2.isInstance(cause) && cause.value === value ? cause : new _TypeValidationError2({ value, cause });
4960
+ return _TypeValidationError.isInstance(cause) && cause.value === value ? cause : new _TypeValidationError({ value, cause });
4961
4961
  }
4962
4962
  };
4963
- _a13 = symbol13;
4964
- var TypeValidationError = _TypeValidationError;
4965
4963
  var ParseError = class extends Error {
4966
4964
  constructor(message, options) {
4967
4965
  super(message), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
@@ -5152,14 +5150,14 @@ function handleFetchError({
5152
5150
  return error;
5153
5151
  }
5154
5152
  function getRuntimeEnvironmentUserAgent(globalThisAny = globalThis) {
5155
- var _a153, _b8, _c;
5153
+ var _a223, _b222, _c;
5156
5154
  if (globalThisAny.window) {
5157
5155
  return `runtime/browser`;
5158
5156
  }
5159
- if ((_a153 = globalThisAny.navigator) == null ? void 0 : _a153.userAgent) {
5157
+ if ((_a223 = globalThisAny.navigator) == null ? void 0 : _a223.userAgent) {
5160
5158
  return `runtime/${globalThisAny.navigator.userAgent.toLowerCase()}`;
5161
5159
  }
5162
- if ((_c = (_b8 = globalThisAny.process) == null ? void 0 : _b8.versions) == null ? void 0 : _c.node) {
5160
+ if ((_c = (_b222 = globalThisAny.process) == null ? void 0 : _b222.versions) == null ? void 0 : _c.node) {
5163
5161
  return `runtime/node.js/${globalThisAny.process.version.substring(0)}`;
5164
5162
  }
5165
5163
  if (globalThisAny.EdgeRuntime) {
@@ -5197,7 +5195,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
5197
5195
  );
5198
5196
  return Object.fromEntries(normalizedHeaders.entries());
5199
5197
  }
5200
- var VERSION = "3.0.17";
5198
+ var VERSION = "3.0.22";
5201
5199
  var getOriginalFetch = () => globalThis.fetch;
5202
5200
  var getFromApi = async ({
5203
5201
  url,
@@ -5282,8 +5280,8 @@ function loadOptionalSetting({
5282
5280
  }
5283
5281
  return settingValue;
5284
5282
  }
5285
- var suspectProtoRx = /"__proto__"\s*:/;
5286
- var suspectConstructorRx = /"constructor"\s*:/;
5283
+ var suspectProtoRx = /"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/;
5284
+ 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*:/;
5287
5285
  function _parse(text2) {
5288
5286
  const obj = JSON.parse(text2);
5289
5287
  if (obj === null || typeof obj !== "object") {
@@ -5303,7 +5301,7 @@ function filter(obj) {
5303
5301
  if (Object.prototype.hasOwnProperty.call(node, "__proto__")) {
5304
5302
  throw new SyntaxError("Object contains forbidden prototype property");
5305
5303
  }
5306
- if (Object.prototype.hasOwnProperty.call(node, "constructor") && Object.prototype.hasOwnProperty.call(node.constructor, "prototype")) {
5304
+ if (Object.prototype.hasOwnProperty.call(node, "constructor") && node.constructor !== null && typeof node.constructor === "object" && Object.prototype.hasOwnProperty.call(node.constructor, "prototype")) {
5307
5305
  throw new SyntaxError("Object contains forbidden prototype property");
5308
5306
  }
5309
5307
  for (const key in node) {
@@ -5539,6 +5537,36 @@ var postToApi = async ({
5539
5537
  throw handleFetchError({ error, url, requestBodyValues: body.values });
5540
5538
  }
5541
5539
  };
5540
+ function tool(tool2) {
5541
+ return tool2;
5542
+ }
5543
+ function createProviderDefinedToolFactoryWithOutputSchema({
5544
+ id,
5545
+ name: name223,
5546
+ inputSchema,
5547
+ outputSchema: outputSchema2
5548
+ }) {
5549
+ return ({
5550
+ execute,
5551
+ toModelOutput,
5552
+ onInputStart,
5553
+ onInputDelta,
5554
+ onInputAvailable,
5555
+ ...args
5556
+ }) => tool({
5557
+ type: "provider-defined",
5558
+ id,
5559
+ name: name223,
5560
+ args,
5561
+ inputSchema,
5562
+ outputSchema: outputSchema2,
5563
+ execute,
5564
+ toModelOutput,
5565
+ onInputStart,
5566
+ onInputDelta,
5567
+ onInputAvailable
5568
+ });
5569
+ }
5542
5570
  async function resolve4(value) {
5543
5571
  if (typeof value === "function") {
5544
5572
  value = value();
@@ -5636,6 +5664,31 @@ var createJsonResponseHandler = (responseSchema) => async ({ response, url, requ
5636
5664
  rawValue: parsedResult.rawValue
5637
5665
  };
5638
5666
  };
5667
+ function addAdditionalPropertiesToJsonSchema(jsonSchema2) {
5668
+ if (jsonSchema2.type === "object") {
5669
+ jsonSchema2.additionalProperties = false;
5670
+ const properties = jsonSchema2.properties;
5671
+ if (properties != null) {
5672
+ for (const property in properties) {
5673
+ properties[property] = addAdditionalPropertiesToJsonSchema(
5674
+ properties[property]
5675
+ );
5676
+ }
5677
+ }
5678
+ }
5679
+ if (jsonSchema2.type === "array" && jsonSchema2.items != null) {
5680
+ if (Array.isArray(jsonSchema2.items)) {
5681
+ jsonSchema2.items = jsonSchema2.items.map(
5682
+ (item) => addAdditionalPropertiesToJsonSchema(item)
5683
+ );
5684
+ } else {
5685
+ jsonSchema2.items = addAdditionalPropertiesToJsonSchema(
5686
+ jsonSchema2.items
5687
+ );
5688
+ }
5689
+ }
5690
+ return jsonSchema2;
5691
+ }
5639
5692
  var getRelativePath = (pathA, pathB) => {
5640
5693
  let i = 0;
5641
5694
  for (; i < pathA.length && i < pathB.length; i++) {
@@ -5678,11 +5731,11 @@ function parseAnyDef() {
5678
5731
  return {};
5679
5732
  }
5680
5733
  function parseArrayDef(def, refs) {
5681
- var _a153, _b8, _c;
5734
+ var _a223, _b222, _c;
5682
5735
  const res = {
5683
5736
  type: "array"
5684
5737
  };
5685
- 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) {
5738
+ 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) {
5686
5739
  res.items = parseDef(def.type._def, {
5687
5740
  ...refs,
5688
5741
  currentPath: [...refs.currentPath, "items"]
@@ -6041,8 +6094,8 @@ function escapeNonAlphaNumeric(source) {
6041
6094
  return result;
6042
6095
  }
6043
6096
  function addFormat(schema, value, message, refs) {
6044
- var _a153;
6045
- if (schema.format || ((_a153 = schema.anyOf) == null ? void 0 : _a153.some((x) => x.format))) {
6097
+ var _a223;
6098
+ if (schema.format || ((_a223 = schema.anyOf) == null ? void 0 : _a223.some((x) => x.format))) {
6046
6099
  if (!schema.anyOf) {
6047
6100
  schema.anyOf = [];
6048
6101
  }
@@ -6061,8 +6114,8 @@ function addFormat(schema, value, message, refs) {
6061
6114
  }
6062
6115
  }
6063
6116
  function addPattern(schema, regex, message, refs) {
6064
- var _a153;
6065
- if (schema.pattern || ((_a153 = schema.allOf) == null ? void 0 : _a153.some((x) => x.pattern))) {
6117
+ var _a223;
6118
+ if (schema.pattern || ((_a223 = schema.allOf) == null ? void 0 : _a223.some((x) => x.pattern))) {
6066
6119
  if (!schema.allOf) {
6067
6120
  schema.allOf = [];
6068
6121
  }
@@ -6081,7 +6134,7 @@ function addPattern(schema, regex, message, refs) {
6081
6134
  }
6082
6135
  }
6083
6136
  function stringifyRegExpWithFlags(regex, refs) {
6084
- var _a153;
6137
+ var _a223;
6085
6138
  if (!refs.applyRegexFlags || !regex.flags) {
6086
6139
  return regex.source;
6087
6140
  }
@@ -6111,7 +6164,7 @@ function stringifyRegExpWithFlags(regex, refs) {
6111
6164
  pattern += source[i];
6112
6165
  pattern += `${source[i - 2]}-${source[i]}`.toUpperCase();
6113
6166
  inCharRange = false;
6114
- } else if (source[i + 1] === "-" && ((_a153 = source[i + 2]) == null ? void 0 : _a153.match(/[a-z]/))) {
6167
+ } else if (source[i + 1] === "-" && ((_a223 = source[i + 2]) == null ? void 0 : _a223.match(/[a-z]/))) {
6115
6168
  pattern += source[i];
6116
6169
  inCharRange = true;
6117
6170
  } else {
@@ -6153,15 +6206,15 @@ function stringifyRegExpWithFlags(regex, refs) {
6153
6206
  return pattern;
6154
6207
  }
6155
6208
  function parseRecordDef(def, refs) {
6156
- var _a153, _b8, _c, _d, _e, _f;
6209
+ var _a223, _b222, _c, _d, _e, _f;
6157
6210
  const schema = {
6158
6211
  type: "object",
6159
- additionalProperties: (_a153 = parseDef(def.valueType._def, {
6212
+ additionalProperties: (_a223 = parseDef(def.valueType._def, {
6160
6213
  ...refs,
6161
6214
  currentPath: [...refs.currentPath, "additionalProperties"]
6162
- })) != null ? _a153 : refs.allowedAdditionalProperties
6215
+ })) != null ? _a223 : refs.allowedAdditionalProperties
6163
6216
  };
6164
- if (((_b8 = def.keyType) == null ? void 0 : _b8._def.typeName) === ZodFirstPartyTypeKind.ZodString && ((_c = def.keyType._def.checks) == null ? void 0 : _c.length)) {
6217
+ if (((_b222 = def.keyType) == null ? void 0 : _b222._def.typeName) === ZodFirstPartyTypeKind.ZodString && ((_c = def.keyType._def.checks) == null ? void 0 : _c.length)) {
6165
6218
  const { type, ...keyType } = parseStringDef(def.keyType._def, refs);
6166
6219
  return {
6167
6220
  ...schema,
@@ -6416,8 +6469,8 @@ function safeIsOptional(schema) {
6416
6469
  }
6417
6470
  }
6418
6471
  var parseOptionalDef = (def, refs) => {
6419
- var _a153;
6420
- if (refs.currentPath.toString() === ((_a153 = refs.propertyPath) == null ? void 0 : _a153.toString())) {
6472
+ var _a223;
6473
+ if (refs.currentPath.toString() === ((_a223 = refs.propertyPath) == null ? void 0 : _a223.toString())) {
6421
6474
  return parseDef(def.innerType._def, refs);
6422
6475
  }
6423
6476
  const innerSchema = parseDef(def.innerType._def, {
@@ -6587,10 +6640,10 @@ var selectParser = (def, typeName, refs) => {
6587
6640
  }
6588
6641
  };
6589
6642
  function parseDef(def, refs, forceResolution = false) {
6590
- var _a153;
6643
+ var _a223;
6591
6644
  const seenItem = refs.seen.get(def);
6592
6645
  if (refs.override) {
6593
- const overrideResult = (_a153 = refs.override) == null ? void 0 : _a153.call(
6646
+ const overrideResult = (_a223 = refs.override) == null ? void 0 : _a223.call(
6594
6647
  refs,
6595
6648
  def,
6596
6649
  refs,
@@ -6656,11 +6709,11 @@ var getRefs = (options) => {
6656
6709
  currentPath,
6657
6710
  propertyPath: void 0,
6658
6711
  seen: new Map(
6659
- Object.entries(_options.definitions).map(([name143, def]) => [
6712
+ Object.entries(_options.definitions).map(([name223, def]) => [
6660
6713
  def._def,
6661
6714
  {
6662
6715
  def: def._def,
6663
- path: [..._options.basePath, _options.definitionPath, name143],
6716
+ path: [..._options.basePath, _options.definitionPath, name223],
6664
6717
  // Resolution of references will be forced even though seen, so it's ok that the schema is undefined here for now.
6665
6718
  jsonSchema: void 0
6666
6719
  }
@@ -6669,50 +6722,50 @@ var getRefs = (options) => {
6669
6722
  };
6670
6723
  };
6671
6724
  var zodToJsonSchema = (schema, options) => {
6672
- var _a153;
6725
+ var _a223;
6673
6726
  const refs = getRefs(options);
6674
6727
  let definitions = typeof options === "object" && options.definitions ? Object.entries(options.definitions).reduce(
6675
- (acc, [name223, schema2]) => {
6676
- var _a223;
6728
+ (acc, [name323, schema2]) => {
6729
+ var _a323;
6677
6730
  return {
6678
6731
  ...acc,
6679
- [name223]: (_a223 = parseDef(
6732
+ [name323]: (_a323 = parseDef(
6680
6733
  schema2._def,
6681
6734
  {
6682
6735
  ...refs,
6683
- currentPath: [...refs.basePath, refs.definitionPath, name223]
6736
+ currentPath: [...refs.basePath, refs.definitionPath, name323]
6684
6737
  },
6685
6738
  true
6686
- )) != null ? _a223 : parseAnyDef()
6739
+ )) != null ? _a323 : parseAnyDef()
6687
6740
  };
6688
6741
  },
6689
6742
  {}
6690
6743
  ) : void 0;
6691
- const name143 = typeof options === "string" ? options : (options == null ? void 0 : options.nameStrategy) === "title" ? void 0 : options == null ? void 0 : options.name;
6692
- const main = (_a153 = parseDef(
6744
+ const name223 = typeof options === "string" ? options : (options == null ? void 0 : options.nameStrategy) === "title" ? void 0 : options == null ? void 0 : options.name;
6745
+ const main = (_a223 = parseDef(
6693
6746
  schema._def,
6694
- name143 === void 0 ? refs : {
6747
+ name223 === void 0 ? refs : {
6695
6748
  ...refs,
6696
- currentPath: [...refs.basePath, refs.definitionPath, name143]
6749
+ currentPath: [...refs.basePath, refs.definitionPath, name223]
6697
6750
  },
6698
6751
  false
6699
- )) != null ? _a153 : parseAnyDef();
6752
+ )) != null ? _a223 : parseAnyDef();
6700
6753
  const title = typeof options === "object" && options.name !== void 0 && options.nameStrategy === "title" ? options.name : void 0;
6701
6754
  if (title !== void 0) {
6702
6755
  main.title = title;
6703
6756
  }
6704
- const combined = name143 === void 0 ? definitions ? {
6757
+ const combined = name223 === void 0 ? definitions ? {
6705
6758
  ...main,
6706
6759
  [refs.definitionPath]: definitions
6707
6760
  } : main : {
6708
6761
  $ref: [
6709
6762
  ...refs.$refStrategy === "relative" ? [] : refs.basePath,
6710
6763
  refs.definitionPath,
6711
- name143
6764
+ name223
6712
6765
  ].join("/"),
6713
6766
  [refs.definitionPath]: {
6714
6767
  ...definitions,
6715
- [name143]: main
6768
+ [name223]: main
6716
6769
  }
6717
6770
  };
6718
6771
  combined.$schema = "http://json-schema.org/draft-07/schema#";
@@ -6720,8 +6773,8 @@ var zodToJsonSchema = (schema, options) => {
6720
6773
  };
6721
6774
  var zod_to_json_schema_default = zodToJsonSchema;
6722
6775
  function zod3Schema(zodSchema2, options) {
6723
- var _a153;
6724
- const useReferences = (_a153 = void 0 ) != null ? _a153 : false;
6776
+ var _a223;
6777
+ const useReferences = (_a223 = void 0 ) != null ? _a223 : false;
6725
6778
  return jsonSchema(
6726
6779
  // defer json schema creation to avoid unnecessary computation when only validation is needed
6727
6780
  () => zod_to_json_schema_default(zodSchema2, {
@@ -6736,15 +6789,17 @@ function zod3Schema(zodSchema2, options) {
6736
6789
  );
6737
6790
  }
6738
6791
  function zod4Schema(zodSchema2, options) {
6739
- var _a153;
6740
- const useReferences = (_a153 = void 0 ) != null ? _a153 : false;
6792
+ var _a223;
6793
+ const useReferences = (_a223 = void 0 ) != null ? _a223 : false;
6741
6794
  return jsonSchema(
6742
6795
  // defer json schema creation to avoid unnecessary computation when only validation is needed
6743
- () => z4.toJSONSchema(zodSchema2, {
6744
- target: "draft-7",
6745
- io: "output",
6746
- reused: useReferences ? "ref" : "inline"
6747
- }),
6796
+ () => addAdditionalPropertiesToJsonSchema(
6797
+ z4.toJSONSchema(zodSchema2, {
6798
+ target: "draft-7",
6799
+ io: "input",
6800
+ reused: useReferences ? "ref" : "inline"
6801
+ })
6802
+ ),
6748
6803
  {
6749
6804
  validate: async (value) => {
6750
6805
  const result = await z4.safeParseAsync(zodSchema2, value);
@@ -6764,6 +6819,15 @@ function zodSchema(zodSchema2, options) {
6764
6819
  }
6765
6820
  }
6766
6821
  var schemaSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.schema");
6822
+ function lazySchema(createSchema) {
6823
+ let schema;
6824
+ return () => {
6825
+ if (schema == null) {
6826
+ schema = createSchema();
6827
+ }
6828
+ return schema;
6829
+ };
6830
+ }
6767
6831
  function jsonSchema(jsonSchema2, {
6768
6832
  validate
6769
6833
  } = {}) {
@@ -6794,7 +6858,7 @@ function withoutTrailingSlash(url) {
6794
6858
  return url == null ? void 0 : url.replace(/\/$/, "");
6795
6859
  }
6796
6860
  var require_get_context = __commonJS({
6797
- "../../../node_modules/.pnpm/@vercel+oidc@3.0.5/node_modules/@vercel/oidc/dist/get-context.js"(exports$1, module) {
6861
+ "../../../node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/get-context.js"(exports$1, module) {
6798
6862
  var __defProp2 = Object.defineProperty;
6799
6863
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6800
6864
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -6826,7 +6890,7 @@ var require_get_context = __commonJS({
6826
6890
  }
6827
6891
  });
6828
6892
  var require_get_vercel_oidc_token = __commonJS({
6829
- "../../../node_modules/.pnpm/@vercel+oidc@3.0.5/node_modules/@vercel/oidc/dist/get-vercel-oidc-token.js"(exports$1, module) {
6893
+ "../../../node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/get-vercel-oidc-token.js"(exports$1, module) {
6830
6894
  var __defProp2 = Object.defineProperty;
6831
6895
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6832
6896
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -6862,19 +6926,23 @@ var require_get_vercel_oidc_token = __commonJS({
6862
6926
  }
6863
6927
  try {
6864
6928
  const [{ getTokenPayload, isExpired }, { refreshToken }] = await Promise.all([
6865
- await import('./token-util-NEHG7TUY-4YJ4EPCL.js'),
6866
- await import('./token-6GSAFR2W-F2L44NEJ.js')
6929
+ await import('./token-util-RMHT2CPJ-Z4NYHFEI.js'),
6930
+ await import('./token-APYSY3BW-IQ2CXU3Y.js')
6867
6931
  ]);
6868
6932
  if (!token || isExpired(getTokenPayload(token))) {
6869
6933
  await refreshToken();
6870
6934
  token = getVercelOidcTokenSync2();
6871
6935
  }
6872
6936
  } catch (error) {
6873
- if (err?.message && error instanceof Error) {
6874
- error.message = `${err.message}
6937
+ let message = err instanceof Error ? err.message : "";
6938
+ if (error instanceof Error) {
6939
+ message = `${message}
6875
6940
  ${error.message}`;
6876
6941
  }
6877
- throw new import_token_error.VercelOidcTokenError(`Failed to refresh OIDC token`, error);
6942
+ if (message) {
6943
+ throw new import_token_error.VercelOidcTokenError(message);
6944
+ }
6945
+ throw error;
6878
6946
  }
6879
6947
  return token;
6880
6948
  }
@@ -6890,7 +6958,7 @@ ${error.message}`;
6890
6958
  }
6891
6959
  });
6892
6960
  var require_dist = __commonJS({
6893
- "../../../node_modules/.pnpm/@vercel+oidc@3.0.5/node_modules/@vercel/oidc/dist/index.js"(exports$1, module) {
6961
+ "../../../node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/index.js"(exports$1, module) {
6894
6962
  var __defProp2 = Object.defineProperty;
6895
6963
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6896
6964
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -6921,18 +6989,18 @@ var require_dist = __commonJS({
6921
6989
  });
6922
6990
  var import_oidc = __toESM(require_dist(), 1);
6923
6991
  var import_oidc2 = __toESM(require_dist(), 1);
6924
- var marker15 = "vercel.ai.gateway.error";
6925
- var symbol15 = Symbol.for(marker15);
6926
- var _a15;
6927
- var _b;
6928
- var GatewayError = class _GatewayError extends (_b = Error, _a15 = symbol15, _b) {
6992
+ var marker16 = "vercel.ai.gateway.error";
6993
+ var symbol16 = Symbol.for(marker16);
6994
+ var _a16;
6995
+ var _b16;
6996
+ var GatewayError = class _GatewayError extends (_b16 = Error, _a16 = symbol16, _b16) {
6929
6997
  constructor({
6930
6998
  message,
6931
6999
  statusCode = 500,
6932
7000
  cause
6933
7001
  }) {
6934
7002
  super(message);
6935
- this[_a15] = true;
7003
+ this[_a16] = true;
6936
7004
  this.statusCode = statusCode;
6937
7005
  this.cause = cause;
6938
7006
  }
@@ -6945,15 +7013,15 @@ var GatewayError = class _GatewayError extends (_b = Error, _a15 = symbol15, _b)
6945
7013
  return _GatewayError.hasMarker(error);
6946
7014
  }
6947
7015
  static hasMarker(error) {
6948
- return typeof error === "object" && error !== null && symbol15 in error && error[symbol15] === true;
7016
+ return typeof error === "object" && error !== null && symbol16 in error && error[symbol16] === true;
6949
7017
  }
6950
7018
  };
6951
- var name14 = "GatewayAuthenticationError";
6952
- var marker22 = `vercel.ai.gateway.error.${name14}`;
7019
+ var name15 = "GatewayAuthenticationError";
7020
+ var marker22 = `vercel.ai.gateway.error.${name15}`;
6953
7021
  var symbol22 = Symbol.for(marker22);
6954
7022
  var _a22;
6955
- var _b2;
6956
- var GatewayAuthenticationError = class _GatewayAuthenticationError extends (_b2 = GatewayError, _a22 = symbol22, _b2) {
7023
+ var _b22;
7024
+ var GatewayAuthenticationError = class _GatewayAuthenticationError extends (_b22 = GatewayError, _a22 = symbol22, _b22) {
6957
7025
  constructor({
6958
7026
  message = "Authentication failed",
6959
7027
  statusCode = 401,
@@ -6961,7 +7029,7 @@ var GatewayAuthenticationError = class _GatewayAuthenticationError extends (_b2
6961
7029
  } = {}) {
6962
7030
  super({ message, statusCode, cause });
6963
7031
  this[_a22] = true;
6964
- this.name = name14;
7032
+ this.name = name15;
6965
7033
  this.type = "authentication_error";
6966
7034
  }
6967
7035
  static isInstance(error) {
@@ -7011,8 +7079,8 @@ var name22 = "GatewayInvalidRequestError";
7011
7079
  var marker32 = `vercel.ai.gateway.error.${name22}`;
7012
7080
  var symbol32 = Symbol.for(marker32);
7013
7081
  var _a32;
7014
- var _b3;
7015
- var GatewayInvalidRequestError = class extends (_b3 = GatewayError, _a32 = symbol32, _b3) {
7082
+ var _b32;
7083
+ var GatewayInvalidRequestError = class extends (_b32 = GatewayError, _a32 = symbol32, _b32) {
7016
7084
  constructor({
7017
7085
  message = "Invalid request",
7018
7086
  statusCode = 400,
@@ -7031,8 +7099,8 @@ var name32 = "GatewayRateLimitError";
7031
7099
  var marker42 = `vercel.ai.gateway.error.${name32}`;
7032
7100
  var symbol42 = Symbol.for(marker42);
7033
7101
  var _a42;
7034
- var _b4;
7035
- var GatewayRateLimitError = class extends (_b4 = GatewayError, _a42 = symbol42, _b4) {
7102
+ var _b42;
7103
+ var GatewayRateLimitError = class extends (_b42 = GatewayError, _a42 = symbol42, _b42) {
7036
7104
  constructor({
7037
7105
  message = "Rate limit exceeded",
7038
7106
  statusCode = 429,
@@ -7058,8 +7126,8 @@ var modelNotFoundParamSchema = lazyValidator(
7058
7126
  )
7059
7127
  );
7060
7128
  var _a52;
7061
- var _b5;
7062
- var GatewayModelNotFoundError = class extends (_b5 = GatewayError, _a52 = symbol52, _b5) {
7129
+ var _b52;
7130
+ var GatewayModelNotFoundError = class extends (_b52 = GatewayError, _a52 = symbol52, _b52) {
7063
7131
  constructor({
7064
7132
  message = "Model not found",
7065
7133
  statusCode = 404,
@@ -7080,8 +7148,8 @@ var name52 = "GatewayInternalServerError";
7080
7148
  var marker62 = `vercel.ai.gateway.error.${name52}`;
7081
7149
  var symbol62 = Symbol.for(marker62);
7082
7150
  var _a62;
7083
- var _b6;
7084
- var GatewayInternalServerError = class extends (_b6 = GatewayError, _a62 = symbol62, _b6) {
7151
+ var _b62;
7152
+ var GatewayInternalServerError = class extends (_b62 = GatewayError, _a62 = symbol62, _b62) {
7085
7153
  constructor({
7086
7154
  message = "Internal server error",
7087
7155
  statusCode = 500,
@@ -7100,8 +7168,8 @@ var name62 = "GatewayResponseError";
7100
7168
  var marker72 = `vercel.ai.gateway.error.${name62}`;
7101
7169
  var symbol72 = Symbol.for(marker72);
7102
7170
  var _a72;
7103
- var _b7;
7104
- var GatewayResponseError = class extends (_b7 = GatewayError, _a72 = symbol72, _b7) {
7171
+ var _b72;
7172
+ var GatewayResponseError = class extends (_b72 = GatewayError, _a72 = symbol72, _b72) {
7105
7173
  constructor({
7106
7174
  message = "Invalid response from Gateway",
7107
7175
  statusCode = 502,
@@ -7185,21 +7253,85 @@ var gatewayErrorResponseSchema = lazyValidator(
7185
7253
  })
7186
7254
  )
7187
7255
  );
7188
- function asGatewayError(error, authMethod) {
7189
- var _a83;
7256
+ var name72 = "GatewayTimeoutError";
7257
+ var marker82 = `vercel.ai.gateway.error.${name72}`;
7258
+ var symbol82 = Symbol.for(marker82);
7259
+ var _a82;
7260
+ var _b82;
7261
+ var GatewayTimeoutError = class _GatewayTimeoutError extends (_b82 = GatewayError, _a82 = symbol82, _b82) {
7262
+ constructor({
7263
+ message = "Request timed out",
7264
+ statusCode = 408,
7265
+ cause
7266
+ } = {}) {
7267
+ super({ message, statusCode, cause });
7268
+ this[_a82] = true;
7269
+ this.name = name72;
7270
+ this.type = "timeout_error";
7271
+ }
7272
+ static isInstance(error) {
7273
+ return GatewayError.hasMarker(error) && symbol82 in error;
7274
+ }
7275
+ /**
7276
+ * Creates a helpful timeout error message with troubleshooting guidance
7277
+ */
7278
+ static createTimeoutError({
7279
+ originalMessage,
7280
+ statusCode = 408,
7281
+ cause
7282
+ }) {
7283
+ const message = `Gateway request timed out: ${originalMessage}
7284
+
7285
+ 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`;
7286
+ return new _GatewayTimeoutError({
7287
+ message,
7288
+ statusCode,
7289
+ cause
7290
+ });
7291
+ }
7292
+ };
7293
+ function isTimeoutError(error) {
7294
+ if (!(error instanceof Error)) {
7295
+ return false;
7296
+ }
7297
+ const errorCode = error.code;
7298
+ if (typeof errorCode === "string") {
7299
+ const undiciTimeoutCodes = [
7300
+ "UND_ERR_HEADERS_TIMEOUT",
7301
+ "UND_ERR_BODY_TIMEOUT",
7302
+ "UND_ERR_CONNECT_TIMEOUT"
7303
+ ];
7304
+ return undiciTimeoutCodes.includes(errorCode);
7305
+ }
7306
+ return false;
7307
+ }
7308
+ async function asGatewayError(error, authMethod) {
7309
+ var _a93;
7190
7310
  if (GatewayError.isInstance(error)) {
7191
7311
  return error;
7192
7312
  }
7313
+ if (isTimeoutError(error)) {
7314
+ return GatewayTimeoutError.createTimeoutError({
7315
+ originalMessage: error instanceof Error ? error.message : "Unknown error",
7316
+ cause: error
7317
+ });
7318
+ }
7193
7319
  if (APICallError.isInstance(error)) {
7194
- return createGatewayErrorFromResponse({
7320
+ if (error.cause && isTimeoutError(error.cause)) {
7321
+ return GatewayTimeoutError.createTimeoutError({
7322
+ originalMessage: error.message,
7323
+ cause: error
7324
+ });
7325
+ }
7326
+ return await createGatewayErrorFromResponse({
7195
7327
  response: extractApiCallResponse(error),
7196
- statusCode: (_a83 = error.statusCode) != null ? _a83 : 500,
7328
+ statusCode: (_a93 = error.statusCode) != null ? _a93 : 500,
7197
7329
  defaultMessage: "Gateway request failed",
7198
7330
  cause: error,
7199
7331
  authMethod
7200
7332
  });
7201
7333
  }
7202
- return createGatewayErrorFromResponse({
7334
+ return await createGatewayErrorFromResponse({
7203
7335
  response: {},
7204
7336
  statusCode: 500,
7205
7337
  defaultMessage: error instanceof Error ? `Gateway request failed: ${error.message}` : "Unknown Gateway error",
@@ -7480,7 +7612,7 @@ var GatewayEmbeddingModel = class {
7480
7612
  abortSignal,
7481
7613
  providerOptions
7482
7614
  }) {
7483
- var _a83;
7615
+ var _a93;
7484
7616
  const resolvedHeaders = await resolve4(this.config.headers());
7485
7617
  try {
7486
7618
  const {
@@ -7511,7 +7643,7 @@ var GatewayEmbeddingModel = class {
7511
7643
  });
7512
7644
  return {
7513
7645
  embeddings: responseBody.embeddings,
7514
- usage: (_a83 = responseBody.usage) != null ? _a83 : void 0,
7646
+ usage: (_a93 = responseBody.usage) != null ? _a93 : void 0,
7515
7647
  providerMetadata: responseBody.providerMetadata,
7516
7648
  response: { headers: responseHeaders, body: rawValue }
7517
7649
  };
@@ -7558,7 +7690,7 @@ var GatewayImageModel = class {
7558
7690
  headers,
7559
7691
  abortSignal
7560
7692
  }) {
7561
- var _a83;
7693
+ var _a93, _b92, _c, _d;
7562
7694
  const resolvedHeaders = await resolve4(this.config.headers());
7563
7695
  try {
7564
7696
  const {
@@ -7593,16 +7725,23 @@ var GatewayImageModel = class {
7593
7725
  return {
7594
7726
  images: responseBody.images,
7595
7727
  // Always base64 strings from server
7596
- warnings: (_a83 = responseBody.warnings) != null ? _a83 : [],
7728
+ warnings: (_a93 = responseBody.warnings) != null ? _a93 : [],
7597
7729
  providerMetadata: responseBody.providerMetadata,
7598
7730
  response: {
7599
7731
  timestamp: /* @__PURE__ */ new Date(),
7600
7732
  modelId: this.modelId,
7601
7733
  headers: responseHeaders
7734
+ },
7735
+ ...responseBody.usage != null && {
7736
+ usage: {
7737
+ inputTokens: (_b92 = responseBody.usage.inputTokens) != null ? _b92 : void 0,
7738
+ outputTokens: (_c = responseBody.usage.outputTokens) != null ? _c : void 0,
7739
+ totalTokens: (_d = responseBody.usage.totalTokens) != null ? _d : void 0
7740
+ }
7602
7741
  }
7603
7742
  };
7604
7743
  } catch (error) {
7605
- throw asGatewayError(error, await parseAuthMethod(resolvedHeaders));
7744
+ throw await asGatewayError(error, await parseAuthMethod(resolvedHeaders));
7606
7745
  }
7607
7746
  }
7608
7747
  getUrl() {
@@ -7618,6 +7757,11 @@ var GatewayImageModel = class {
7618
7757
  var providerMetadataEntrySchema = z$1.object({
7619
7758
  images: z$1.array(z$1.unknown()).optional()
7620
7759
  }).catchall(z$1.unknown());
7760
+ var gatewayImageUsageSchema = z$1.object({
7761
+ inputTokens: z$1.number().nullish(),
7762
+ outputTokens: z$1.number().nullish(),
7763
+ totalTokens: z$1.number().nullish()
7764
+ });
7621
7765
  var gatewayImageResponseSchema = z$1.object({
7622
7766
  images: z$1.array(z$1.string()),
7623
7767
  // Always base64 strings over the wire
@@ -7627,21 +7771,196 @@ var gatewayImageResponseSchema = z$1.object({
7627
7771
  message: z$1.string()
7628
7772
  })
7629
7773
  ).optional(),
7630
- providerMetadata: z$1.record(z$1.string(), providerMetadataEntrySchema).optional()
7774
+ providerMetadata: z$1.record(z$1.string(), providerMetadataEntrySchema).optional(),
7775
+ usage: gatewayImageUsageSchema.optional()
7631
7776
  });
7777
+ var parallelSearchInputSchema = lazySchema(
7778
+ () => zodSchema(
7779
+ z.object({
7780
+ objective: z.string().describe(
7781
+ "Natural-language description of the web research goal, including source or freshness guidance and broader context from the task. Maximum 5000 characters."
7782
+ ),
7783
+ search_queries: z.array(z.string()).optional().describe(
7784
+ "Optional search queries to supplement the objective. Maximum 200 characters per query."
7785
+ ),
7786
+ mode: z.enum(["one-shot", "agentic"]).optional().describe(
7787
+ 'Mode preset: "one-shot" for comprehensive results with longer excerpts (default), "agentic" for concise, token-efficient results for multi-step workflows.'
7788
+ ),
7789
+ max_results: z.number().optional().describe(
7790
+ "Maximum number of results to return (1-20). Defaults to 10 if not specified."
7791
+ ),
7792
+ source_policy: z.object({
7793
+ include_domains: z.array(z.string()).optional().describe("List of domains to include in search results."),
7794
+ exclude_domains: z.array(z.string()).optional().describe("List of domains to exclude from search results."),
7795
+ after_date: z.string().optional().describe(
7796
+ "Only include results published after this date (ISO 8601 format)."
7797
+ )
7798
+ }).optional().describe(
7799
+ "Source policy for controlling which domains to include/exclude and freshness."
7800
+ ),
7801
+ excerpts: z.object({
7802
+ max_chars_per_result: z.number().optional().describe("Maximum characters per result."),
7803
+ max_chars_total: z.number().optional().describe("Maximum total characters across all results.")
7804
+ }).optional().describe("Excerpt configuration for controlling result length."),
7805
+ fetch_policy: z.object({
7806
+ max_age_seconds: z.number().optional().describe(
7807
+ "Maximum age in seconds for cached content. Set to 0 to always fetch fresh content."
7808
+ )
7809
+ }).optional().describe("Fetch policy for controlling content freshness.")
7810
+ })
7811
+ )
7812
+ );
7813
+ var parallelSearchOutputSchema = lazySchema(
7814
+ () => zodSchema(
7815
+ z.union([
7816
+ // Success response
7817
+ z.object({
7818
+ searchId: z.string(),
7819
+ results: z.array(
7820
+ z.object({
7821
+ url: z.string(),
7822
+ title: z.string(),
7823
+ excerpt: z.string(),
7824
+ publishDate: z.string().nullable().optional(),
7825
+ relevanceScore: z.number().optional()
7826
+ })
7827
+ )
7828
+ }),
7829
+ // Error response
7830
+ z.object({
7831
+ error: z.enum([
7832
+ "api_error",
7833
+ "rate_limit",
7834
+ "timeout",
7835
+ "invalid_input",
7836
+ "configuration_error",
7837
+ "unknown"
7838
+ ]),
7839
+ statusCode: z.number().optional(),
7840
+ message: z.string()
7841
+ })
7842
+ ])
7843
+ )
7844
+ );
7845
+ var parallelSearchToolFactory = createProviderDefinedToolFactoryWithOutputSchema({
7846
+ id: "gateway.parallel_search",
7847
+ name: "parallel_search",
7848
+ inputSchema: parallelSearchInputSchema,
7849
+ outputSchema: parallelSearchOutputSchema
7850
+ });
7851
+ var parallelSearch = (config = {}) => parallelSearchToolFactory(config);
7852
+ var perplexitySearchInputSchema = lazySchema(
7853
+ () => zodSchema(
7854
+ z.object({
7855
+ query: z.union([z.string(), z.array(z.string())]).describe(
7856
+ "Search query (string) or multiple queries (array of up to 5 strings). Multi-query searches return combined results from all queries."
7857
+ ),
7858
+ max_results: z.number().optional().describe(
7859
+ "Maximum number of search results to return (1-20, default: 10)"
7860
+ ),
7861
+ max_tokens_per_page: z.number().optional().describe(
7862
+ "Maximum number of tokens to extract per search result page (256-2048, default: 2048)"
7863
+ ),
7864
+ max_tokens: z.number().optional().describe(
7865
+ "Maximum total tokens across all search results (default: 25000, max: 1000000)"
7866
+ ),
7867
+ country: z.string().optional().describe(
7868
+ "Two-letter ISO 3166-1 alpha-2 country code for regional search results (e.g., 'US', 'GB', 'FR')"
7869
+ ),
7870
+ search_domain_filter: z.array(z.string()).optional().describe(
7871
+ "List of domains to include or exclude from search results (max 20). To include: ['nature.com', 'science.org']. To exclude: ['-example.com', '-spam.net']"
7872
+ ),
7873
+ search_language_filter: z.array(z.string()).optional().describe(
7874
+ "List of ISO 639-1 language codes to filter results (max 10, lowercase). Examples: ['en', 'fr', 'de']"
7875
+ ),
7876
+ search_after_date: z.string().optional().describe(
7877
+ "Include only results published after this date. Format: 'MM/DD/YYYY' (e.g., '3/1/2025'). Cannot be used with search_recency_filter."
7878
+ ),
7879
+ search_before_date: z.string().optional().describe(
7880
+ "Include only results published before this date. Format: 'MM/DD/YYYY' (e.g., '3/15/2025'). Cannot be used with search_recency_filter."
7881
+ ),
7882
+ last_updated_after_filter: z.string().optional().describe(
7883
+ "Include only results last updated after this date. Format: 'MM/DD/YYYY' (e.g., '3/1/2025'). Cannot be used with search_recency_filter."
7884
+ ),
7885
+ last_updated_before_filter: z.string().optional().describe(
7886
+ "Include only results last updated before this date. Format: 'MM/DD/YYYY' (e.g., '3/15/2025'). Cannot be used with search_recency_filter."
7887
+ ),
7888
+ search_recency_filter: z.enum(["day", "week", "month", "year"]).optional().describe(
7889
+ "Filter results by relative time period. Cannot be used with search_after_date or search_before_date."
7890
+ )
7891
+ })
7892
+ )
7893
+ );
7894
+ var perplexitySearchOutputSchema = lazySchema(
7895
+ () => zodSchema(
7896
+ z.union([
7897
+ // Success response
7898
+ z.object({
7899
+ results: z.array(
7900
+ z.object({
7901
+ title: z.string(),
7902
+ url: z.string(),
7903
+ snippet: z.string(),
7904
+ date: z.string().optional(),
7905
+ lastUpdated: z.string().optional()
7906
+ })
7907
+ ),
7908
+ id: z.string()
7909
+ }),
7910
+ // Error response
7911
+ z.object({
7912
+ error: z.enum([
7913
+ "api_error",
7914
+ "rate_limit",
7915
+ "timeout",
7916
+ "invalid_input",
7917
+ "unknown"
7918
+ ]),
7919
+ statusCode: z.number().optional(),
7920
+ message: z.string()
7921
+ })
7922
+ ])
7923
+ )
7924
+ );
7925
+ var perplexitySearchToolFactory = createProviderDefinedToolFactoryWithOutputSchema({
7926
+ id: "gateway.perplexity_search",
7927
+ name: "perplexity_search",
7928
+ inputSchema: perplexitySearchInputSchema,
7929
+ outputSchema: perplexitySearchOutputSchema
7930
+ });
7931
+ var perplexitySearch = (config = {}) => perplexitySearchToolFactory(config);
7932
+ var gatewayTools = {
7933
+ /**
7934
+ * Search the web using Parallel AI's Search API for LLM-optimized excerpts.
7935
+ *
7936
+ * Takes a natural language objective and returns relevant excerpts,
7937
+ * replacing multiple keyword searches with a single call for broad
7938
+ * or complex queries. Supports different search types for depth vs
7939
+ * breadth tradeoffs.
7940
+ */
7941
+ parallelSearch,
7942
+ /**
7943
+ * Search the web using Perplexity's Search API for real-time information,
7944
+ * news, research papers, and articles.
7945
+ *
7946
+ * Provides ranked search results with advanced filtering options including
7947
+ * domain, language, date range, and recency filters.
7948
+ */
7949
+ perplexitySearch
7950
+ };
7632
7951
  async function getVercelRequestId() {
7633
- var _a83;
7634
- return (_a83 = (0, import_oidc.getContext)().headers) == null ? void 0 : _a83["x-vercel-id"];
7952
+ var _a93;
7953
+ return (_a93 = (0, import_oidc.getContext)().headers) == null ? void 0 : _a93["x-vercel-id"];
7635
7954
  }
7636
- var VERSION2 = "2.0.15";
7955
+ var VERSION2 = "2.0.58";
7637
7956
  var AI_GATEWAY_PROTOCOL_VERSION = "0.0.1";
7638
7957
  function createGatewayProvider(options = {}) {
7639
- var _a83, _b8;
7958
+ var _a93, _b92;
7640
7959
  let pendingMetadata = null;
7641
7960
  let metadataCache = null;
7642
- const cacheRefreshMillis = (_a83 = options.metadataCacheRefreshMillis) != null ? _a83 : 1e3 * 60 * 5;
7961
+ const cacheRefreshMillis = (_a93 = options.metadataCacheRefreshMillis) != null ? _a93 : 1e3 * 60 * 5;
7643
7962
  let lastFetchTime = 0;
7644
- const baseURL = (_b8 = withoutTrailingSlash(options.baseURL)) != null ? _b8 : "https://ai-gateway.vercel.sh/v1/ai";
7963
+ const baseURL = (_b92 = withoutTrailingSlash(options.baseURL)) != null ? _b92 : "https://ai-gateway.vercel.sh/v1/ai";
7645
7964
  const getHeaders = async () => {
7646
7965
  const auth = await getGatewayAuthToken(options);
7647
7966
  if (auth) {
@@ -7674,13 +7993,18 @@ function createGatewayProvider(options = {}) {
7674
7993
  settingValue: void 0,
7675
7994
  environmentVariableName: "VERCEL_REGION"
7676
7995
  });
7996
+ const projectId = loadOptionalSetting({
7997
+ settingValue: void 0,
7998
+ environmentVariableName: "VERCEL_PROJECT_ID"
7999
+ });
7677
8000
  return async () => {
7678
8001
  const requestId = await getVercelRequestId();
7679
8002
  return {
7680
8003
  ...deploymentId && { "ai-o11y-deployment-id": deploymentId },
7681
8004
  ...environment && { "ai-o11y-environment": environment },
7682
8005
  ...region && { "ai-o11y-region": region },
7683
- ...requestId && { "ai-o11y-request-id": requestId }
8006
+ ...requestId && { "ai-o11y-request-id": requestId },
8007
+ ...projectId && { "ai-o11y-project-id": projectId }
7684
8008
  };
7685
8009
  };
7686
8010
  };
@@ -7694,8 +8018,8 @@ function createGatewayProvider(options = {}) {
7694
8018
  });
7695
8019
  };
7696
8020
  const getAvailableModels = async () => {
7697
- var _a922, _b9, _c;
7698
- const now2 = (_c = (_b9 = (_a922 = options._internal) == null ? void 0 : _a922.currentDate) == null ? void 0 : _b9.call(_a922).getTime()) != null ? _c : Date.now();
8021
+ var _a1022, _b102, _c;
8022
+ const now2 = (_c = (_b102 = (_a1022 = options._internal) == null ? void 0 : _a1022.currentDate) == null ? void 0 : _b102.call(_a1022).getTime()) != null ? _c : Date.now();
7699
8023
  if (!pendingMetadata || now2 - lastFetchTime > cacheRefreshMillis) {
7700
8024
  lastFetchTime = now2;
7701
8025
  pendingMetadata = new GatewayFetchMetadata({
@@ -7755,6 +8079,7 @@ function createGatewayProvider(options = {}) {
7755
8079
  o11yHeaders: createO11yHeaders()
7756
8080
  });
7757
8081
  };
8082
+ provider.tools = gatewayTools;
7758
8083
  return provider;
7759
8084
  }
7760
8085
  createGatewayProvider();
@@ -7850,11 +8175,11 @@ var major = VERSION22.split(".")[0];
7850
8175
  var GLOBAL_OPENTELEMETRY_API_KEY = /* @__PURE__ */ Symbol.for("opentelemetry.js.api." + major);
7851
8176
  var _global = _globalThis;
7852
8177
  function registerGlobal(type, instance, diag, allowOverride) {
7853
- var _a16;
8178
+ var _a162;
7854
8179
  if (allowOverride === void 0) {
7855
8180
  allowOverride = false;
7856
8181
  }
7857
- var api = _global[GLOBAL_OPENTELEMETRY_API_KEY] = (_a16 = _global[GLOBAL_OPENTELEMETRY_API_KEY]) !== null && _a16 !== void 0 ? _a16 : {
8182
+ var api = _global[GLOBAL_OPENTELEMETRY_API_KEY] = (_a162 = _global[GLOBAL_OPENTELEMETRY_API_KEY]) !== null && _a162 !== void 0 ? _a162 : {
7858
8183
  version: VERSION22
7859
8184
  };
7860
8185
  if (!allowOverride && api[type]) {
@@ -7872,12 +8197,12 @@ function registerGlobal(type, instance, diag, allowOverride) {
7872
8197
  return true;
7873
8198
  }
7874
8199
  function getGlobal(type) {
7875
- var _a16, _b8;
7876
- var globalVersion = (_a16 = _global[GLOBAL_OPENTELEMETRY_API_KEY]) === null || _a16 === void 0 ? void 0 : _a16.version;
8200
+ var _a162, _b92;
8201
+ var globalVersion = (_a162 = _global[GLOBAL_OPENTELEMETRY_API_KEY]) === null || _a162 === void 0 ? void 0 : _a162.version;
7877
8202
  if (!globalVersion || !isCompatible(globalVersion)) {
7878
8203
  return;
7879
8204
  }
7880
- return (_b8 = _global[GLOBAL_OPENTELEMETRY_API_KEY]) === null || _b8 === void 0 ? void 0 : _b8[type];
8205
+ return (_b92 = _global[GLOBAL_OPENTELEMETRY_API_KEY]) === null || _b92 === void 0 ? void 0 : _b92[type];
7881
8206
  }
7882
8207
  function unregisterGlobal(type, diag) {
7883
8208
  diag.debug("@opentelemetry/api: Unregistering a global for " + type + " v" + VERSION22 + ".");
@@ -8042,13 +8367,13 @@ var DiagAPI = (
8042
8367
  }
8043
8368
  var self = this;
8044
8369
  var setLogger = function(logger, optionsOrLogLevel) {
8045
- var _a16, _b8, _c;
8370
+ var _a162, _b92, _c;
8046
8371
  if (optionsOrLogLevel === void 0) {
8047
8372
  optionsOrLogLevel = { logLevel: DiagLogLevel.INFO };
8048
8373
  }
8049
8374
  if (logger === self) {
8050
8375
  var err = new Error("Cannot use diag as the logger for itself. Please use a DiagLogger implementation like ConsoleDiagLogger or a custom implementation");
8051
- self.error((_a16 = err.stack) !== null && _a16 !== void 0 ? _a16 : err.message);
8376
+ self.error((_a162 = err.stack) !== null && _a162 !== void 0 ? _a162 : err.message);
8052
8377
  return false;
8053
8378
  }
8054
8379
  if (typeof optionsOrLogLevel === "number") {
@@ -8057,7 +8382,7 @@ var DiagAPI = (
8057
8382
  };
8058
8383
  }
8059
8384
  var oldLogger = getGlobal("diag");
8060
- var newLogger = createLogLevelDiagLogger((_b8 = optionsOrLogLevel.logLevel) !== null && _b8 !== void 0 ? _b8 : DiagLogLevel.INFO, logger);
8385
+ var newLogger = createLogLevelDiagLogger((_b92 = optionsOrLogLevel.logLevel) !== null && _b92 !== void 0 ? _b92 : DiagLogLevel.INFO, logger);
8061
8386
  if (oldLogger && !optionsOrLogLevel.suppressOverrideMessage) {
8062
8387
  var stack = (_c = new Error().stack) !== null && _c !== void 0 ? _c : "<failed to generate stacktrace>";
8063
8388
  oldLogger.warn("Current logger will be overwritten from " + stack);
@@ -8213,12 +8538,12 @@ var ContextAPI = (
8213
8538
  return this._getContextManager().active();
8214
8539
  };
8215
8540
  ContextAPI2.prototype.with = function(context, fn, thisArg) {
8216
- var _a16;
8541
+ var _a162;
8217
8542
  var args = [];
8218
8543
  for (var _i = 3; _i < arguments.length; _i++) {
8219
8544
  args[_i - 3] = arguments[_i];
8220
8545
  }
8221
- return (_a16 = this._getContextManager()).with.apply(_a16, __spreadArray4([context, fn, thisArg], __read4(args), false));
8546
+ return (_a162 = this._getContextManager()).with.apply(_a162, __spreadArray4([context, fn, thisArg], __read4(args), false));
8222
8547
  };
8223
8548
  ContextAPI2.prototype.bind = function(context, target) {
8224
8549
  return this._getContextManager().bind(context, target);
@@ -8305,8 +8630,8 @@ function setSpanContext(context, spanContext) {
8305
8630
  return setSpan(context, new NonRecordingSpan(spanContext));
8306
8631
  }
8307
8632
  function getSpanContext(context) {
8308
- var _a16;
8309
- return (_a16 = getSpan(context)) === null || _a16 === void 0 ? void 0 : _a16.spanContext();
8633
+ var _a162;
8634
+ return (_a162 = getSpan(context)) === null || _a162 === void 0 ? void 0 : _a162.spanContext();
8310
8635
  }
8311
8636
  var VALID_TRACEID_REGEX = /^([0-9a-f]{32})$/i;
8312
8637
  var VALID_SPANID_REGEX = /^[0-9a-f]{16}$/i;
@@ -8419,19 +8744,19 @@ var ProxyTracerProvider = (
8419
8744
  function ProxyTracerProvider2() {
8420
8745
  }
8421
8746
  ProxyTracerProvider2.prototype.getTracer = function(name16, version, options) {
8422
- var _a16;
8423
- return (_a16 = this.getDelegateTracer(name16, version, options)) !== null && _a16 !== void 0 ? _a16 : new ProxyTracer(this, name16, version, options);
8747
+ var _a162;
8748
+ return (_a162 = this.getDelegateTracer(name16, version, options)) !== null && _a162 !== void 0 ? _a162 : new ProxyTracer(this, name16, version, options);
8424
8749
  };
8425
8750
  ProxyTracerProvider2.prototype.getDelegate = function() {
8426
- var _a16;
8427
- return (_a16 = this._delegate) !== null && _a16 !== void 0 ? _a16 : NOOP_TRACER_PROVIDER;
8751
+ var _a162;
8752
+ return (_a162 = this._delegate) !== null && _a162 !== void 0 ? _a162 : NOOP_TRACER_PROVIDER;
8428
8753
  };
8429
8754
  ProxyTracerProvider2.prototype.setDelegate = function(delegate) {
8430
8755
  this._delegate = delegate;
8431
8756
  };
8432
8757
  ProxyTracerProvider2.prototype.getDelegateTracer = function(name16, version, options) {
8433
- var _a16;
8434
- return (_a16 = this._delegate) === null || _a16 === void 0 ? void 0 : _a16.getTracer(name16, version, options);
8758
+ var _a162;
8759
+ return (_a162 = this._delegate) === null || _a162 === void 0 ? void 0 : _a162.getTracer(name16, version, options);
8435
8760
  };
8436
8761
  return ProxyTracerProvider2;
8437
8762
  })()
@@ -8521,8 +8846,8 @@ var dataContentSchema = z$1.union([
8521
8846
  z$1.custom(
8522
8847
  // Buffer might not be available in some environments such as CloudFlare:
8523
8848
  (value) => {
8524
- var _a16, _b8;
8525
- return (_b8 = (_a16 = globalThis.Buffer) == null ? void 0 : _a16.isBuffer(value)) != null ? _b8 : false;
8849
+ var _a162, _b92;
8850
+ return (_b92 = (_a162 = globalThis.Buffer) == null ? void 0 : _a162.isBuffer(value)) != null ? _b92 : false;
8526
8851
  },
8527
8852
  { message: "Must be a Buffer" }
8528
8853
  )