@mastra/agent-builder 1.0.28 → 1.0.29-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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @mastra/agent-builder
2
2
 
3
+ ## 1.0.29-alpha.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`750b4d3`](https://github.com/mastra-ai/mastra/commit/750b4d3d8231f92e769b2c485921ac5a8ca639b9)]:
8
+ - @mastra/core@1.28.0-alpha.1
9
+ - @mastra/memory@1.17.1-alpha.0
10
+
3
11
  ## 1.0.28
4
12
 
5
13
  ### Patch Changes
package/dist/index.js CHANGED
@@ -1,4 +1,3 @@
1
- import { __commonJS, require_token_error, __toESM } from './chunk-DAXABV7F.js';
2
1
  import { Agent, isSupportedLanguageModel, tryGenerateWithJsonFallback, tryStreamWithJsonFallback } from '@mastra/core/agent';
3
2
  import { InMemoryStore } from '@mastra/core/storage';
4
3
  import { Memory } from '@mastra/memory';
@@ -21,6 +20,7 @@ import * as z4 from 'zod/v4';
21
20
  import { z as z$1 } from 'zod/v4';
22
21
  import { ZodFirstPartyTypeKind } from 'zod/v3';
23
22
 
23
+ // src/agent/index.ts
24
24
  var UNIT_KINDS = ["mcp-server", "tool", "workflow", "agent", "integration", "network", "other"];
25
25
  var TemplateUnitSchema = z.object({
26
26
  kind: z.enum(UNIT_KINDS),
@@ -4969,6 +4969,9 @@ var ParseError = class extends Error {
4969
4969
  super(message), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
4970
4970
  }
4971
4971
  };
4972
+ var LF = 10;
4973
+ var CR = 13;
4974
+ var SPACE = 32;
4972
4975
  function noop(_arg) {
4973
4976
  }
4974
4977
  function createParser(callbacks) {
@@ -4976,39 +4979,109 @@ function createParser(callbacks) {
4976
4979
  throw new TypeError(
4977
4980
  "`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?"
4978
4981
  );
4979
- const { onEvent = noop, onError = noop, onRetry = noop, onComment } = callbacks;
4980
- let incompleteLine = "", isFirstChunk = true, id, data = "", eventType = "";
4981
- function feed(newChunk) {
4982
- const chunk = isFirstChunk ? newChunk.replace(/^\xEF\xBB\xBF/, "") : newChunk, [complete, incomplete] = splitLines(`${incompleteLine}${chunk}`);
4983
- for (const line of complete)
4984
- parseLine(line);
4985
- incompleteLine = incomplete, isFirstChunk = false;
4986
- }
4987
- function parseLine(line) {
4988
- if (line === "") {
4982
+ const { onEvent = noop, onError = noop, onRetry = noop, onComment } = callbacks, pendingFragments = [];
4983
+ let isFirstChunk = true, id, data = "", dataLines = 0, eventType;
4984
+ function feed(chunk) {
4985
+ if (isFirstChunk && (isFirstChunk = false, chunk.charCodeAt(0) === 239 && chunk.charCodeAt(1) === 187 && chunk.charCodeAt(2) === 191 && (chunk = chunk.slice(3))), pendingFragments.length === 0) {
4986
+ const trailing2 = processLines(chunk);
4987
+ trailing2 !== "" && pendingFragments.push(trailing2);
4988
+ return;
4989
+ }
4990
+ if (chunk.indexOf(`
4991
+ `) === -1 && chunk.indexOf("\r") === -1) {
4992
+ pendingFragments.push(chunk);
4993
+ return;
4994
+ }
4995
+ pendingFragments.push(chunk);
4996
+ const input = pendingFragments.join("");
4997
+ pendingFragments.length = 0;
4998
+ const trailing = processLines(input);
4999
+ trailing !== "" && pendingFragments.push(trailing);
5000
+ }
5001
+ function processLines(chunk) {
5002
+ let searchIndex = 0;
5003
+ if (chunk.indexOf("\r") === -1) {
5004
+ let lfIndex = chunk.indexOf(`
5005
+ `, searchIndex);
5006
+ for (; lfIndex !== -1; ) {
5007
+ if (searchIndex === lfIndex) {
5008
+ dataLines > 0 && onEvent({ id, event: eventType, data }), id = void 0, data = "", dataLines = 0, eventType = void 0, searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
5009
+ `, searchIndex);
5010
+ continue;
5011
+ }
5012
+ const firstCharCode = chunk.charCodeAt(searchIndex);
5013
+ if (isDataPrefix(chunk, searchIndex, firstCharCode)) {
5014
+ const valueStart = chunk.charCodeAt(searchIndex + 5) === SPACE ? searchIndex + 6 : searchIndex + 5, value = chunk.slice(valueStart, lfIndex);
5015
+ if (dataLines === 0 && chunk.charCodeAt(lfIndex + 1) === LF) {
5016
+ onEvent({ id, event: eventType, data: value }), id = void 0, data = "", eventType = void 0, searchIndex = lfIndex + 2, lfIndex = chunk.indexOf(`
5017
+ `, searchIndex);
5018
+ continue;
5019
+ }
5020
+ data = dataLines === 0 ? value : `${data}
5021
+ ${value}`, dataLines++;
5022
+ } else isEventPrefix(chunk, searchIndex, firstCharCode) ? eventType = chunk.slice(
5023
+ chunk.charCodeAt(searchIndex + 6) === SPACE ? searchIndex + 7 : searchIndex + 6,
5024
+ lfIndex
5025
+ ) || void 0 : parseLine(chunk, searchIndex, lfIndex);
5026
+ searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
5027
+ `, searchIndex);
5028
+ }
5029
+ return chunk.slice(searchIndex);
5030
+ }
5031
+ for (; searchIndex < chunk.length; ) {
5032
+ const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
5033
+ `, searchIndex);
5034
+ let lineEnd = -1;
5035
+ if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = crIndex < lfIndex ? crIndex : lfIndex : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1)
5036
+ break;
5037
+ parseLine(chunk, searchIndex, lineEnd), searchIndex = lineEnd + 1, chunk.charCodeAt(searchIndex - 1) === CR && chunk.charCodeAt(searchIndex) === LF && searchIndex++;
5038
+ }
5039
+ return chunk.slice(searchIndex);
5040
+ }
5041
+ function parseLine(chunk, start, end) {
5042
+ if (start === end) {
4989
5043
  dispatchEvent();
4990
5044
  return;
4991
5045
  }
4992
- if (line.startsWith(":")) {
4993
- onComment && onComment(line.slice(line.startsWith(": ") ? 2 : 1));
5046
+ const firstCharCode = chunk.charCodeAt(start);
5047
+ if (isDataPrefix(chunk, start, firstCharCode)) {
5048
+ const valueStart = chunk.charCodeAt(start + 5) === SPACE ? start + 6 : start + 5, value2 = chunk.slice(valueStart, end);
5049
+ data = dataLines === 0 ? value2 : `${data}
5050
+ ${value2}`, dataLines++;
4994
5051
  return;
4995
5052
  }
4996
- const fieldSeparatorIndex = line.indexOf(":");
4997
- if (fieldSeparatorIndex !== -1) {
4998
- const field = line.slice(0, fieldSeparatorIndex), offset = line[fieldSeparatorIndex + 1] === " " ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
4999
- processField(field, value, line);
5053
+ if (isEventPrefix(chunk, start, firstCharCode)) {
5054
+ eventType = chunk.slice(chunk.charCodeAt(start + 6) === SPACE ? start + 7 : start + 6, end) || void 0;
5000
5055
  return;
5001
5056
  }
5002
- processField(line, "", line);
5057
+ if (firstCharCode === 105 && chunk.charCodeAt(start + 1) === 100 && chunk.charCodeAt(start + 2) === 58) {
5058
+ const value2 = chunk.slice(chunk.charCodeAt(start + 3) === SPACE ? start + 4 : start + 3, end);
5059
+ id = value2.includes("\0") ? void 0 : value2;
5060
+ return;
5061
+ }
5062
+ if (firstCharCode === 58) {
5063
+ if (onComment) {
5064
+ const line2 = chunk.slice(start, end);
5065
+ onComment(line2.slice(chunk.charCodeAt(start + 1) === SPACE ? 2 : 1));
5066
+ }
5067
+ return;
5068
+ }
5069
+ const line = chunk.slice(start, end), fieldSeparatorIndex = line.indexOf(":");
5070
+ if (fieldSeparatorIndex === -1) {
5071
+ processField(line, "", line);
5072
+ return;
5073
+ }
5074
+ const field = line.slice(0, fieldSeparatorIndex), offset = line.charCodeAt(fieldSeparatorIndex + 1) === SPACE ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
5075
+ processField(field, value, line);
5003
5076
  }
5004
5077
  function processField(field, value, line) {
5005
5078
  switch (field) {
5006
5079
  case "event":
5007
- eventType = value;
5080
+ eventType = value || void 0;
5008
5081
  break;
5009
5082
  case "data":
5010
- data = `${data}${value}
5011
- `;
5083
+ data = dataLines === 0 ? value : `${data}
5084
+ ${value}`, dataLines++;
5012
5085
  break;
5013
5086
  case "id":
5014
5087
  id = value.includes("\0") ? void 0 : value;
@@ -5033,37 +5106,26 @@ function createParser(callbacks) {
5033
5106
  }
5034
5107
  }
5035
5108
  function dispatchEvent() {
5036
- data.length > 0 && onEvent({
5109
+ dataLines > 0 && onEvent({
5037
5110
  id,
5038
- event: eventType || void 0,
5039
- // If the data buffer's last character is a U+000A LINE FEED (LF) character,
5040
- // then remove the last character from the data buffer.
5041
- data: data.endsWith(`
5042
- `) ? data.slice(0, -1) : data
5043
- }), id = void 0, data = "", eventType = "";
5111
+ event: eventType,
5112
+ data
5113
+ }), id = void 0, data = "", dataLines = 0, eventType = void 0;
5044
5114
  }
5045
5115
  function reset(options = {}) {
5046
- incompleteLine && options.consume && parseLine(incompleteLine), isFirstChunk = true, id = void 0, data = "", eventType = "", incompleteLine = "";
5116
+ if (options.consume && pendingFragments.length > 0) {
5117
+ const incompleteLine = pendingFragments.join("");
5118
+ parseLine(incompleteLine, 0, incompleteLine.length);
5119
+ }
5120
+ isFirstChunk = true, id = void 0, data = "", dataLines = 0, eventType = void 0, pendingFragments.length = 0;
5047
5121
  }
5048
5122
  return { feed, reset };
5049
5123
  }
5050
- function splitLines(chunk) {
5051
- const lines = [];
5052
- let incompleteLine = "", searchIndex = 0;
5053
- for (; searchIndex < chunk.length; ) {
5054
- const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
5055
- `, searchIndex);
5056
- let lineEnd = -1;
5057
- if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = Math.min(crIndex, lfIndex) : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1) {
5058
- incompleteLine = chunk.slice(searchIndex);
5059
- break;
5060
- } else {
5061
- const line = chunk.slice(searchIndex, lineEnd);
5062
- lines.push(line), searchIndex = lineEnd + 1, chunk[searchIndex - 1] === "\r" && chunk[searchIndex] === `
5063
- ` && searchIndex++;
5064
- }
5065
- }
5066
- return [lines, incompleteLine];
5124
+ function isDataPrefix(chunk, i, firstCharCode) {
5125
+ return firstCharCode === 100 && chunk.charCodeAt(i + 1) === 97 && chunk.charCodeAt(i + 2) === 116 && chunk.charCodeAt(i + 3) === 97 && chunk.charCodeAt(i + 4) === 58;
5126
+ }
5127
+ function isEventPrefix(chunk, i, firstCharCode) {
5128
+ return firstCharCode === 101 && chunk.charCodeAt(i + 1) === 118 && chunk.charCodeAt(i + 2) === 101 && chunk.charCodeAt(i + 3) === 110 && chunk.charCodeAt(i + 4) === 116 && chunk.charCodeAt(i + 5) === 58;
5067
5129
  }
5068
5130
  var EventSourceParserStream = class extends TransformStream {
5069
5131
  constructor({ onError, onRetry, onComment } = {}) {
@@ -5199,7 +5261,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
5199
5261
  );
5200
5262
  return Object.fromEntries(normalizedHeaders.entries());
5201
5263
  }
5202
- var VERSION = "3.0.22";
5264
+ var VERSION = "3.0.23";
5203
5265
  var getOriginalFetch = () => globalThis.fetch;
5204
5266
  var getFromApi = async ({
5205
5267
  url,
@@ -6861,138 +6923,17 @@ function asSchema(schema) {
6861
6923
  function withoutTrailingSlash(url) {
6862
6924
  return url == null ? void 0 : url.replace(/\/$/, "");
6863
6925
  }
6864
- var require_get_context = __commonJS({
6865
- "../../../node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/get-context.js"(exports$1, module) {
6866
- var __defProp2 = Object.defineProperty;
6867
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6868
- var __getOwnPropNames = Object.getOwnPropertyNames;
6869
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6870
- var __export2 = (target, all) => {
6871
- for (var name16 in all)
6872
- __defProp2(target, name16, { get: all[name16], enumerable: true });
6873
- };
6874
- var __copyProps = (to, from, except, desc) => {
6875
- if (from && typeof from === "object" || typeof from === "function") {
6876
- for (let key of __getOwnPropNames(from))
6877
- if (!__hasOwnProp.call(to, key) && key !== except)
6878
- __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
6879
- }
6880
- return to;
6881
- };
6882
- var __toCommonJS = (mod) => __copyProps(__defProp2({}, "__esModule", { value: true }), mod);
6883
- var get_context_exports = {};
6884
- __export2(get_context_exports, {
6885
- SYMBOL_FOR_REQ_CONTEXT: () => SYMBOL_FOR_REQ_CONTEXT,
6886
- getContext: () => getContext3
6887
- });
6888
- module.exports = __toCommonJS(get_context_exports);
6889
- var SYMBOL_FOR_REQ_CONTEXT = /* @__PURE__ */ Symbol.for("@vercel/request-context");
6890
- function getContext3() {
6891
- const fromSymbol = globalThis;
6892
- return fromSymbol[SYMBOL_FOR_REQ_CONTEXT]?.get?.() ?? {};
6893
- }
6894
- }
6895
- });
6896
- var require_get_vercel_oidc_token = __commonJS({
6897
- "../../../node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/get-vercel-oidc-token.js"(exports$1, module) {
6898
- var __defProp2 = Object.defineProperty;
6899
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6900
- var __getOwnPropNames = Object.getOwnPropertyNames;
6901
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6902
- var __export2 = (target, all) => {
6903
- for (var name16 in all)
6904
- __defProp2(target, name16, { get: all[name16], enumerable: true });
6905
- };
6906
- var __copyProps = (to, from, except, desc) => {
6907
- if (from && typeof from === "object" || typeof from === "function") {
6908
- for (let key of __getOwnPropNames(from))
6909
- if (!__hasOwnProp.call(to, key) && key !== except)
6910
- __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
6911
- }
6912
- return to;
6913
- };
6914
- var __toCommonJS = (mod) => __copyProps(__defProp2({}, "__esModule", { value: true }), mod);
6915
- var get_vercel_oidc_token_exports = {};
6916
- __export2(get_vercel_oidc_token_exports, {
6917
- getVercelOidcToken: () => getVercelOidcToken3,
6918
- getVercelOidcTokenSync: () => getVercelOidcTokenSync2
6919
- });
6920
- module.exports = __toCommonJS(get_vercel_oidc_token_exports);
6921
- var import_get_context = require_get_context();
6922
- var import_token_error = require_token_error();
6923
- async function getVercelOidcToken3() {
6924
- let token = "";
6925
- let err;
6926
- try {
6927
- token = getVercelOidcTokenSync2();
6928
- } catch (error) {
6929
- err = error;
6930
- }
6931
- try {
6932
- const [{ getTokenPayload, isExpired }, { refreshToken }] = await Promise.all([
6933
- await import('./token-util-RMHT2CPJ-Z4NYHFEI.js'),
6934
- await import('./token-APYSY3BW-IQ2CXU3Y.js')
6935
- ]);
6936
- if (!token || isExpired(getTokenPayload(token))) {
6937
- await refreshToken();
6938
- token = getVercelOidcTokenSync2();
6939
- }
6940
- } catch (error) {
6941
- let message = err instanceof Error ? err.message : "";
6942
- if (error instanceof Error) {
6943
- message = `${message}
6944
- ${error.message}`;
6945
- }
6946
- if (message) {
6947
- throw new import_token_error.VercelOidcTokenError(message);
6948
- }
6949
- throw error;
6950
- }
6951
- return token;
6952
- }
6953
- function getVercelOidcTokenSync2() {
6954
- const token = (0, import_get_context.getContext)().headers?.["x-vercel-oidc-token"] ?? process.env.VERCEL_OIDC_TOKEN;
6955
- if (!token) {
6956
- throw new Error(
6957
- `The 'x-vercel-oidc-token' header is missing from the request. Do you have the OIDC option enabled in the Vercel project settings?`
6958
- );
6959
- }
6960
- return token;
6961
- }
6962
- }
6963
- });
6964
- var require_dist = __commonJS({
6965
- "../../../node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/index.js"(exports$1, module) {
6966
- var __defProp2 = Object.defineProperty;
6967
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6968
- var __getOwnPropNames = Object.getOwnPropertyNames;
6969
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6970
- var __export2 = (target, all) => {
6971
- for (var name16 in all)
6972
- __defProp2(target, name16, { get: all[name16], enumerable: true });
6973
- };
6974
- var __copyProps = (to, from, except, desc) => {
6975
- if (from && typeof from === "object" || typeof from === "function") {
6976
- for (let key of __getOwnPropNames(from))
6977
- if (!__hasOwnProp.call(to, key) && key !== except)
6978
- __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
6979
- }
6980
- return to;
6981
- };
6982
- var __toCommonJS = (mod) => __copyProps(__defProp2({}, "__esModule", { value: true }), mod);
6983
- var src_exports = {};
6984
- __export2(src_exports, {
6985
- getContext: () => import_get_context.getContext,
6986
- getVercelOidcToken: () => import_get_vercel_oidc_token.getVercelOidcToken,
6987
- getVercelOidcTokenSync: () => import_get_vercel_oidc_token.getVercelOidcTokenSync
6988
- });
6989
- module.exports = __toCommonJS(src_exports);
6990
- var import_get_vercel_oidc_token = require_get_vercel_oidc_token();
6991
- var import_get_context = require_get_context();
6926
+ function getContext() {
6927
+ return {
6928
+ headers: {}
6929
+ };
6930
+ }
6931
+ async function getVercelOidcToken() {
6932
+ if (process.env.VERCEL_OIDC_TOKEN) {
6933
+ return process.env.VERCEL_OIDC_TOKEN ?? "";
6992
6934
  }
6993
- });
6994
- var import_oidc = __toESM(require_dist(), 1);
6995
- var import_oidc2 = __toESM(require_dist(), 1);
6935
+ throw new Error("@vercel/oidc is not available in the vendored @internal AI packages. Provide an API key instead.");
6936
+ }
6996
6937
  var marker16 = "vercel.ai.gateway.error";
6997
6938
  var symbol16 = Symbol.for(marker16);
6998
6939
  var _a16;
@@ -7367,6 +7308,7 @@ async function parseAuthMethod(headers) {
7367
7308
  var gatewayAuthMethodSchema = lazyValidator(
7368
7309
  () => zodSchema(z$1.union([z$1.literal("api-key"), z$1.literal("oidc")]))
7369
7310
  );
7311
+ var KNOWN_MODEL_TYPES = ["embedding", "image", "language"];
7370
7312
  var GatewayFetchMetadata = class {
7371
7313
  constructor(config) {
7372
7314
  this.config = config;
@@ -7437,8 +7379,12 @@ var gatewayAvailableModelsResponseSchema = lazyValidator(
7437
7379
  provider: z$1.string(),
7438
7380
  modelId: z$1.string()
7439
7381
  }),
7440
- modelType: z$1.enum(["language", "embedding", "image"]).nullish()
7382
+ modelType: z$1.string().nullish()
7441
7383
  })
7384
+ ).transform(
7385
+ (models) => models.filter(
7386
+ (m) => m.modelType == null || KNOWN_MODEL_TYPES.includes(m.modelType)
7387
+ )
7442
7388
  )
7443
7389
  })
7444
7390
  )
@@ -7454,6 +7400,187 @@ var gatewayCreditsResponseSchema = lazyValidator(
7454
7400
  }))
7455
7401
  )
7456
7402
  );
7403
+ var GatewaySpendReport = class {
7404
+ constructor(config) {
7405
+ this.config = config;
7406
+ }
7407
+ async getSpendReport(params) {
7408
+ try {
7409
+ const baseUrl = new URL(this.config.baseURL);
7410
+ const searchParams = new URLSearchParams();
7411
+ searchParams.set("start_date", params.startDate);
7412
+ searchParams.set("end_date", params.endDate);
7413
+ if (params.groupBy) {
7414
+ searchParams.set("group_by", params.groupBy);
7415
+ }
7416
+ if (params.datePart) {
7417
+ searchParams.set("date_part", params.datePart);
7418
+ }
7419
+ if (params.userId) {
7420
+ searchParams.set("user_id", params.userId);
7421
+ }
7422
+ if (params.model) {
7423
+ searchParams.set("model", params.model);
7424
+ }
7425
+ if (params.provider) {
7426
+ searchParams.set("provider", params.provider);
7427
+ }
7428
+ if (params.credentialType) {
7429
+ searchParams.set("credential_type", params.credentialType);
7430
+ }
7431
+ if (params.tags && params.tags.length > 0) {
7432
+ searchParams.set("tags", params.tags.join(","));
7433
+ }
7434
+ const { value } = await getFromApi({
7435
+ url: `${baseUrl.origin}/v1/report?${searchParams.toString()}`,
7436
+ headers: await resolve4(this.config.headers()),
7437
+ successfulResponseHandler: createJsonResponseHandler(
7438
+ gatewaySpendReportResponseSchema
7439
+ ),
7440
+ failedResponseHandler: createJsonErrorResponseHandler({
7441
+ errorSchema: z$1.any(),
7442
+ errorToMessage: (data) => data
7443
+ }),
7444
+ fetch: this.config.fetch
7445
+ });
7446
+ return value;
7447
+ } catch (error) {
7448
+ throw await asGatewayError(error);
7449
+ }
7450
+ }
7451
+ };
7452
+ var gatewaySpendReportResponseSchema = lazySchema(
7453
+ () => zodSchema(
7454
+ z$1.object({
7455
+ results: z$1.array(
7456
+ z$1.object({
7457
+ day: z$1.string().optional(),
7458
+ hour: z$1.string().optional(),
7459
+ user: z$1.string().optional(),
7460
+ model: z$1.string().optional(),
7461
+ tag: z$1.string().optional(),
7462
+ provider: z$1.string().optional(),
7463
+ credential_type: z$1.enum(["byok", "system"]).optional(),
7464
+ total_cost: z$1.number(),
7465
+ market_cost: z$1.number().optional(),
7466
+ input_tokens: z$1.number().optional(),
7467
+ output_tokens: z$1.number().optional(),
7468
+ cached_input_tokens: z$1.number().optional(),
7469
+ cache_creation_input_tokens: z$1.number().optional(),
7470
+ reasoning_tokens: z$1.number().optional(),
7471
+ request_count: z$1.number().optional()
7472
+ }).transform(
7473
+ ({
7474
+ credential_type,
7475
+ total_cost,
7476
+ market_cost,
7477
+ input_tokens,
7478
+ output_tokens,
7479
+ cached_input_tokens,
7480
+ cache_creation_input_tokens,
7481
+ reasoning_tokens,
7482
+ request_count,
7483
+ ...rest
7484
+ }) => ({
7485
+ ...rest,
7486
+ ...credential_type !== void 0 ? { credentialType: credential_type } : {},
7487
+ totalCost: total_cost,
7488
+ ...market_cost !== void 0 ? { marketCost: market_cost } : {},
7489
+ ...input_tokens !== void 0 ? { inputTokens: input_tokens } : {},
7490
+ ...output_tokens !== void 0 ? { outputTokens: output_tokens } : {},
7491
+ ...cached_input_tokens !== void 0 ? { cachedInputTokens: cached_input_tokens } : {},
7492
+ ...cache_creation_input_tokens !== void 0 ? { cacheCreationInputTokens: cache_creation_input_tokens } : {},
7493
+ ...reasoning_tokens !== void 0 ? { reasoningTokens: reasoning_tokens } : {},
7494
+ ...request_count !== void 0 ? { requestCount: request_count } : {}
7495
+ })
7496
+ )
7497
+ )
7498
+ })
7499
+ )
7500
+ );
7501
+ var GatewayGenerationInfoFetcher = class {
7502
+ constructor(config) {
7503
+ this.config = config;
7504
+ }
7505
+ async getGenerationInfo(params) {
7506
+ try {
7507
+ const baseUrl = new URL(this.config.baseURL);
7508
+ const { value } = await getFromApi({
7509
+ url: `${baseUrl.origin}/v1/generation?id=${encodeURIComponent(params.id)}`,
7510
+ headers: await resolve4(this.config.headers()),
7511
+ successfulResponseHandler: createJsonResponseHandler(
7512
+ gatewayGenerationInfoResponseSchema
7513
+ ),
7514
+ failedResponseHandler: createJsonErrorResponseHandler({
7515
+ errorSchema: z$1.any(),
7516
+ errorToMessage: (data) => data
7517
+ }),
7518
+ fetch: this.config.fetch
7519
+ });
7520
+ return value;
7521
+ } catch (error) {
7522
+ throw await asGatewayError(error);
7523
+ }
7524
+ }
7525
+ };
7526
+ var gatewayGenerationInfoResponseSchema = lazySchema(
7527
+ () => zodSchema(
7528
+ z$1.object({
7529
+ data: z$1.object({
7530
+ id: z$1.string(),
7531
+ total_cost: z$1.number(),
7532
+ upstream_inference_cost: z$1.number(),
7533
+ usage: z$1.number(),
7534
+ created_at: z$1.string(),
7535
+ model: z$1.string(),
7536
+ is_byok: z$1.boolean(),
7537
+ provider_name: z$1.string(),
7538
+ streamed: z$1.boolean(),
7539
+ finish_reason: z$1.string(),
7540
+ latency: z$1.number(),
7541
+ generation_time: z$1.number(),
7542
+ native_tokens_prompt: z$1.number(),
7543
+ native_tokens_completion: z$1.number(),
7544
+ native_tokens_reasoning: z$1.number(),
7545
+ native_tokens_cached: z$1.number(),
7546
+ native_tokens_cache_creation: z$1.number(),
7547
+ billable_web_search_calls: z$1.number()
7548
+ }).transform(
7549
+ ({
7550
+ total_cost,
7551
+ upstream_inference_cost,
7552
+ created_at,
7553
+ is_byok,
7554
+ provider_name,
7555
+ finish_reason,
7556
+ generation_time,
7557
+ native_tokens_prompt,
7558
+ native_tokens_completion,
7559
+ native_tokens_reasoning,
7560
+ native_tokens_cached,
7561
+ native_tokens_cache_creation,
7562
+ billable_web_search_calls,
7563
+ ...rest
7564
+ }) => ({
7565
+ ...rest,
7566
+ totalCost: total_cost,
7567
+ upstreamInferenceCost: upstream_inference_cost,
7568
+ createdAt: created_at,
7569
+ isByok: is_byok,
7570
+ providerName: provider_name,
7571
+ finishReason: finish_reason,
7572
+ generationTime: generation_time,
7573
+ promptTokens: native_tokens_prompt,
7574
+ completionTokens: native_tokens_completion,
7575
+ reasoningTokens: native_tokens_reasoning,
7576
+ cachedTokens: native_tokens_cached,
7577
+ cacheCreationTokens: native_tokens_cache_creation,
7578
+ billableWebSearchCalls: billable_web_search_calls
7579
+ })
7580
+ )
7581
+ }).transform(({ data }) => data)
7582
+ )
7583
+ );
7457
7584
  var GatewayLanguageModel = class {
7458
7585
  constructor(modelId, config) {
7459
7586
  this.modelId = modelId;
@@ -7954,9 +8081,9 @@ var gatewayTools = {
7954
8081
  };
7955
8082
  async function getVercelRequestId() {
7956
8083
  var _a93;
7957
- return (_a93 = (0, import_oidc.getContext)().headers) == null ? void 0 : _a93["x-vercel-id"];
8084
+ return (_a93 = getContext().headers) == null ? void 0 : _a93["x-vercel-id"];
7958
8085
  }
7959
- var VERSION2 = "2.0.59";
8086
+ var VERSION2 = "2.0.82";
7960
8087
  var AI_GATEWAY_PROTOCOL_VERSION = "0.0.1";
7961
8088
  function createGatewayProvider(options = {}) {
7962
8089
  var _a93, _b92;
@@ -8054,6 +8181,30 @@ function createGatewayProvider(options = {}) {
8054
8181
  );
8055
8182
  });
8056
8183
  };
8184
+ const getSpendReport = async (params) => {
8185
+ return new GatewaySpendReport({
8186
+ baseURL,
8187
+ headers: getHeaders,
8188
+ fetch: options.fetch
8189
+ }).getSpendReport(params).catch(async (error) => {
8190
+ throw await asGatewayError(
8191
+ error,
8192
+ await parseAuthMethod(await getHeaders())
8193
+ );
8194
+ });
8195
+ };
8196
+ const getGenerationInfo = async (params) => {
8197
+ return new GatewayGenerationInfoFetcher({
8198
+ baseURL,
8199
+ headers: getHeaders,
8200
+ fetch: options.fetch
8201
+ }).getGenerationInfo(params).catch(async (error) => {
8202
+ throw await asGatewayError(
8203
+ error,
8204
+ await parseAuthMethod(await getHeaders())
8205
+ );
8206
+ });
8207
+ };
8057
8208
  const provider = function(modelId) {
8058
8209
  if (new.target) {
8059
8210
  throw new Error(
@@ -8064,6 +8215,8 @@ function createGatewayProvider(options = {}) {
8064
8215
  };
8065
8216
  provider.getAvailableModels = getAvailableModels;
8066
8217
  provider.getCredits = getCredits;
8218
+ provider.getSpendReport = getSpendReport;
8219
+ provider.getGenerationInfo = getGenerationInfo;
8067
8220
  provider.imageModel = (modelId) => {
8068
8221
  return new GatewayImageModel(modelId, {
8069
8222
  provider: "gateway",
@@ -8099,7 +8252,7 @@ async function getGatewayAuthToken(options) {
8099
8252
  };
8100
8253
  }
8101
8254
  try {
8102
- const oidcToken = await (0, import_oidc2.getVercelOidcToken)();
8255
+ const oidcToken = await getVercelOidcToken();
8103
8256
  return {
8104
8257
  token: oidcToken,
8105
8258
  authMethod: "oidc"