@mastra/memory 1.17.0 → 1.17.1

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 (72) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/{chunk-MPBMHIAQ.js → chunk-7742VTN5.js} +100 -44
  3. package/dist/chunk-7742VTN5.js.map +1 -0
  4. package/dist/{chunk-5MTY2UYL.cjs → chunk-J2XQSPAB.cjs} +100 -44
  5. package/dist/chunk-J2XQSPAB.cjs.map +1 -0
  6. package/dist/{constants-HXOCZPB7.cjs → constants-PJXB7ZIS.cjs} +2 -2
  7. package/dist/{constants-HXOCZPB7.cjs.map → constants-PJXB7ZIS.cjs.map} +1 -1
  8. package/dist/{constants-BDOITAO3.js → constants-XEHPYRDJ.js} +2 -2
  9. package/dist/{constants-BDOITAO3.js.map → constants-XEHPYRDJ.js.map} +1 -1
  10. package/dist/docs/SKILL.md +1 -1
  11. package/dist/docs/assets/SOURCE_MAP.json +39 -39
  12. package/dist/docs/references/docs-memory-working-memory.md +1 -1
  13. package/dist/index.cjs +785 -384
  14. package/dist/index.cjs.map +1 -1
  15. package/dist/index.js +776 -375
  16. package/dist/index.js.map +1 -1
  17. package/dist/{observational-memory-UCFGVLVW.cjs → observational-memory-ISRI7QGE.cjs} +26 -26
  18. package/dist/{observational-memory-UCFGVLVW.cjs.map → observational-memory-ISRI7QGE.cjs.map} +1 -1
  19. package/dist/{observational-memory-7YYZIIX4.js → observational-memory-YYO73QMY.js} +3 -3
  20. package/dist/{observational-memory-7YYZIIX4.js.map → observational-memory-YYO73QMY.js.map} +1 -1
  21. package/dist/processors/index.cjs +24 -24
  22. package/dist/processors/index.js +1 -1
  23. package/dist/processors/observational-memory/observation-strategies/async-buffer.d.ts.map +1 -1
  24. package/dist/processors/observational-memory/observation-strategies/base.d.ts.map +1 -1
  25. package/dist/processors/observational-memory/observation-turn/step.d.ts.map +1 -1
  26. package/dist/processors/observational-memory/observation-turn/turn.d.ts +3 -2
  27. package/dist/processors/observational-memory/observation-turn/turn.d.ts.map +1 -1
  28. package/dist/processors/observational-memory/observation-turn/types.d.ts +1 -0
  29. package/dist/processors/observational-memory/observation-turn/types.d.ts.map +1 -1
  30. package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -1
  31. package/dist/processors/observational-memory/processor.d.ts.map +1 -1
  32. package/dist/processors/observational-memory/reflector-runner.d.ts +1 -0
  33. package/dist/processors/observational-memory/reflector-runner.d.ts.map +1 -1
  34. package/package.json +10 -10
  35. package/dist/chunk-3PUO6DLX.js +0 -439
  36. package/dist/chunk-3PUO6DLX.js.map +0 -1
  37. package/dist/chunk-5MTY2UYL.cjs.map +0 -1
  38. package/dist/chunk-CK4U3AYR.cjs +0 -84
  39. package/dist/chunk-CK4U3AYR.cjs.map +0 -1
  40. package/dist/chunk-DAJJSFVA.cjs +0 -441
  41. package/dist/chunk-DAJJSFVA.cjs.map +0 -1
  42. package/dist/chunk-DGUM43GV.js +0 -10
  43. package/dist/chunk-DGUM43GV.js.map +0 -1
  44. package/dist/chunk-EQ4M72KU.js +0 -439
  45. package/dist/chunk-EQ4M72KU.js.map +0 -1
  46. package/dist/chunk-IDRQZVB4.cjs +0 -84
  47. package/dist/chunk-IDRQZVB4.cjs.map +0 -1
  48. package/dist/chunk-JEQ2X3Z6.cjs +0 -12
  49. package/dist/chunk-JEQ2X3Z6.cjs.map +0 -1
  50. package/dist/chunk-MPBMHIAQ.js.map +0 -1
  51. package/dist/chunk-RC6RZVYE.js +0 -79
  52. package/dist/chunk-RC6RZVYE.js.map +0 -1
  53. package/dist/chunk-SVPZMV27.js +0 -79
  54. package/dist/chunk-SVPZMV27.js.map +0 -1
  55. package/dist/chunk-ZD3BKU5O.cjs +0 -441
  56. package/dist/chunk-ZD3BKU5O.cjs.map +0 -1
  57. package/dist/token-APYSY3BW-2DN6RAUY.js +0 -61
  58. package/dist/token-APYSY3BW-2DN6RAUY.js.map +0 -1
  59. package/dist/token-APYSY3BW-POD4OUWN.cjs +0 -63
  60. package/dist/token-APYSY3BW-POD4OUWN.cjs.map +0 -1
  61. package/dist/token-APYSY3BW-YTVQELJT.js +0 -61
  62. package/dist/token-APYSY3BW-YTVQELJT.js.map +0 -1
  63. package/dist/token-APYSY3BW-ZQ7TMBY7.cjs +0 -63
  64. package/dist/token-APYSY3BW-ZQ7TMBY7.cjs.map +0 -1
  65. package/dist/token-util-RMHT2CPJ-6TGPE335.cjs +0 -10
  66. package/dist/token-util-RMHT2CPJ-6TGPE335.cjs.map +0 -1
  67. package/dist/token-util-RMHT2CPJ-77HHGIQN.cjs +0 -10
  68. package/dist/token-util-RMHT2CPJ-77HHGIQN.cjs.map +0 -1
  69. package/dist/token-util-RMHT2CPJ-RJEA3FAN.js +0 -8
  70. package/dist/token-util-RMHT2CPJ-RJEA3FAN.js.map +0 -1
  71. package/dist/token-util-RMHT2CPJ-WJZ2SYAR.js +0 -8
  72. package/dist/token-util-RMHT2CPJ-WJZ2SYAR.js.map +0 -1
package/dist/index.cjs CHANGED
@@ -1,8 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkCK4U3AYR_cjs = require('./chunk-CK4U3AYR.cjs');
4
- var chunkIDRQZVB4_cjs = require('./chunk-IDRQZVB4.cjs');
5
- var chunk5MTY2UYL_cjs = require('./chunk-5MTY2UYL.cjs');
3
+ var chunkJ2XQSPAB_cjs = require('./chunk-J2XQSPAB.cjs');
6
4
  var v3 = require('zod/v3');
7
5
  var zod = require('zod');
8
6
  var z4 = require('zod/v4');
@@ -49,7 +47,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
49
47
  var __getOwnPropNames = Object.getOwnPropertyNames;
50
48
  var __getProtoOf = Object.getPrototypeOf;
51
49
  var __hasOwnProp = Object.prototype.hasOwnProperty;
52
- var __commonJS3 = (cb, mod) => function __require2() {
50
+ var __commonJS = (cb, mod) => function __require2() {
53
51
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
54
52
  };
55
53
  var __copyProps = (to, from, except, desc) => {
@@ -60,7 +58,7 @@ var __copyProps = (to, from, except, desc) => {
60
58
  }
61
59
  return to;
62
60
  };
63
- var __toESM3 = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
61
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
64
62
  // If the importer is in node compatibility mode or this is not an ESM
65
63
  // file that has been converted to a CommonJS file using a Babel-
66
64
  // compatible transform (i.e. "__esModule" has not been set), then set
@@ -68,7 +66,7 @@ var __toESM3 = (mod, isNodeMode, target) => (target = mod != null ? __create(__g
68
66
  __defProp(target, "default", { value: mod, enumerable: true }),
69
67
  mod
70
68
  ));
71
- var require_secure_json_parse = __commonJS3({
69
+ var require_secure_json_parse = __commonJS({
72
70
  "../../../node_modules/.pnpm/secure-json-parse@2.7.0/node_modules/secure-json-parse/index.js"(exports$1, module) {
73
71
  var hasBuffer = typeof Buffer !== "undefined";
74
72
  var suspectProtoRx3 = /"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/;
@@ -339,7 +337,7 @@ var customAlphabet = (alphabet, defaultSize = 21) => {
339
337
  return id;
340
338
  };
341
339
  };
342
- var import_secure_json_parse = __toESM3(require_secure_json_parse());
340
+ var import_secure_json_parse = __toESM(require_secure_json_parse());
343
341
  function convertAsyncIteratorToReadableStream(iterator) {
344
342
  return new ReadableStream({
345
343
  /**
@@ -4316,6 +4314,9 @@ var ParseError = class extends Error {
4316
4314
  super(message), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
4317
4315
  }
4318
4316
  };
4317
+ var LF = 10;
4318
+ var CR = 13;
4319
+ var SPACE = 32;
4319
4320
  function noop(_arg) {
4320
4321
  }
4321
4322
  function createParser(callbacks) {
@@ -4323,39 +4324,109 @@ function createParser(callbacks) {
4323
4324
  throw new TypeError(
4324
4325
  "`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?"
4325
4326
  );
4326
- const { onEvent = noop, onError = noop, onRetry = noop, onComment } = callbacks;
4327
- let incompleteLine = "", isFirstChunk = true, id, data = "", eventType = "";
4328
- function feed(newChunk) {
4329
- const chunk = isFirstChunk ? newChunk.replace(/^\xEF\xBB\xBF/, "") : newChunk, [complete, incomplete] = splitLines(`${incompleteLine}${chunk}`);
4330
- for (const line of complete)
4331
- parseLine(line);
4332
- incompleteLine = incomplete, isFirstChunk = false;
4333
- }
4334
- function parseLine(line) {
4335
- if (line === "") {
4327
+ const { onEvent = noop, onError = noop, onRetry = noop, onComment } = callbacks, pendingFragments = [];
4328
+ let isFirstChunk = true, id, data = "", dataLines = 0, eventType;
4329
+ function feed(chunk) {
4330
+ if (isFirstChunk && (isFirstChunk = false, chunk.charCodeAt(0) === 239 && chunk.charCodeAt(1) === 187 && chunk.charCodeAt(2) === 191 && (chunk = chunk.slice(3))), pendingFragments.length === 0) {
4331
+ const trailing2 = processLines(chunk);
4332
+ trailing2 !== "" && pendingFragments.push(trailing2);
4333
+ return;
4334
+ }
4335
+ if (chunk.indexOf(`
4336
+ `) === -1 && chunk.indexOf("\r") === -1) {
4337
+ pendingFragments.push(chunk);
4338
+ return;
4339
+ }
4340
+ pendingFragments.push(chunk);
4341
+ const input = pendingFragments.join("");
4342
+ pendingFragments.length = 0;
4343
+ const trailing = processLines(input);
4344
+ trailing !== "" && pendingFragments.push(trailing);
4345
+ }
4346
+ function processLines(chunk) {
4347
+ let searchIndex = 0;
4348
+ if (chunk.indexOf("\r") === -1) {
4349
+ let lfIndex = chunk.indexOf(`
4350
+ `, searchIndex);
4351
+ for (; lfIndex !== -1; ) {
4352
+ if (searchIndex === lfIndex) {
4353
+ dataLines > 0 && onEvent({ id, event: eventType, data }), id = void 0, data = "", dataLines = 0, eventType = void 0, searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
4354
+ `, searchIndex);
4355
+ continue;
4356
+ }
4357
+ const firstCharCode = chunk.charCodeAt(searchIndex);
4358
+ if (isDataPrefix(chunk, searchIndex, firstCharCode)) {
4359
+ const valueStart = chunk.charCodeAt(searchIndex + 5) === SPACE ? searchIndex + 6 : searchIndex + 5, value = chunk.slice(valueStart, lfIndex);
4360
+ if (dataLines === 0 && chunk.charCodeAt(lfIndex + 1) === LF) {
4361
+ onEvent({ id, event: eventType, data: value }), id = void 0, data = "", eventType = void 0, searchIndex = lfIndex + 2, lfIndex = chunk.indexOf(`
4362
+ `, searchIndex);
4363
+ continue;
4364
+ }
4365
+ data = dataLines === 0 ? value : `${data}
4366
+ ${value}`, dataLines++;
4367
+ } else isEventPrefix(chunk, searchIndex, firstCharCode) ? eventType = chunk.slice(
4368
+ chunk.charCodeAt(searchIndex + 6) === SPACE ? searchIndex + 7 : searchIndex + 6,
4369
+ lfIndex
4370
+ ) || void 0 : parseLine(chunk, searchIndex, lfIndex);
4371
+ searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
4372
+ `, searchIndex);
4373
+ }
4374
+ return chunk.slice(searchIndex);
4375
+ }
4376
+ for (; searchIndex < chunk.length; ) {
4377
+ const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
4378
+ `, searchIndex);
4379
+ let lineEnd = -1;
4380
+ 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)
4381
+ break;
4382
+ parseLine(chunk, searchIndex, lineEnd), searchIndex = lineEnd + 1, chunk.charCodeAt(searchIndex - 1) === CR && chunk.charCodeAt(searchIndex) === LF && searchIndex++;
4383
+ }
4384
+ return chunk.slice(searchIndex);
4385
+ }
4386
+ function parseLine(chunk, start, end) {
4387
+ if (start === end) {
4336
4388
  dispatchEvent();
4337
4389
  return;
4338
4390
  }
4339
- if (line.startsWith(":")) {
4340
- onComment && onComment(line.slice(line.startsWith(": ") ? 2 : 1));
4391
+ const firstCharCode = chunk.charCodeAt(start);
4392
+ if (isDataPrefix(chunk, start, firstCharCode)) {
4393
+ const valueStart = chunk.charCodeAt(start + 5) === SPACE ? start + 6 : start + 5, value2 = chunk.slice(valueStart, end);
4394
+ data = dataLines === 0 ? value2 : `${data}
4395
+ ${value2}`, dataLines++;
4341
4396
  return;
4342
4397
  }
4343
- const fieldSeparatorIndex = line.indexOf(":");
4344
- if (fieldSeparatorIndex !== -1) {
4345
- const field = line.slice(0, fieldSeparatorIndex), offset = line[fieldSeparatorIndex + 1] === " " ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
4346
- processField(field, value, line);
4398
+ if (isEventPrefix(chunk, start, firstCharCode)) {
4399
+ eventType = chunk.slice(chunk.charCodeAt(start + 6) === SPACE ? start + 7 : start + 6, end) || void 0;
4347
4400
  return;
4348
4401
  }
4349
- processField(line, "", line);
4402
+ if (firstCharCode === 105 && chunk.charCodeAt(start + 1) === 100 && chunk.charCodeAt(start + 2) === 58) {
4403
+ const value2 = chunk.slice(chunk.charCodeAt(start + 3) === SPACE ? start + 4 : start + 3, end);
4404
+ id = value2.includes("\0") ? void 0 : value2;
4405
+ return;
4406
+ }
4407
+ if (firstCharCode === 58) {
4408
+ if (onComment) {
4409
+ const line2 = chunk.slice(start, end);
4410
+ onComment(line2.slice(chunk.charCodeAt(start + 1) === SPACE ? 2 : 1));
4411
+ }
4412
+ return;
4413
+ }
4414
+ const line = chunk.slice(start, end), fieldSeparatorIndex = line.indexOf(":");
4415
+ if (fieldSeparatorIndex === -1) {
4416
+ processField(line, "", line);
4417
+ return;
4418
+ }
4419
+ const field = line.slice(0, fieldSeparatorIndex), offset = line.charCodeAt(fieldSeparatorIndex + 1) === SPACE ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
4420
+ processField(field, value, line);
4350
4421
  }
4351
4422
  function processField(field, value, line) {
4352
4423
  switch (field) {
4353
4424
  case "event":
4354
- eventType = value;
4425
+ eventType = value || void 0;
4355
4426
  break;
4356
4427
  case "data":
4357
- data = `${data}${value}
4358
- `;
4428
+ data = dataLines === 0 ? value : `${data}
4429
+ ${value}`, dataLines++;
4359
4430
  break;
4360
4431
  case "id":
4361
4432
  id = value.includes("\0") ? void 0 : value;
@@ -4380,37 +4451,26 @@ function createParser(callbacks) {
4380
4451
  }
4381
4452
  }
4382
4453
  function dispatchEvent() {
4383
- data.length > 0 && onEvent({
4454
+ dataLines > 0 && onEvent({
4384
4455
  id,
4385
- event: eventType || void 0,
4386
- // If the data buffer's last character is a U+000A LINE FEED (LF) character,
4387
- // then remove the last character from the data buffer.
4388
- data: data.endsWith(`
4389
- `) ? data.slice(0, -1) : data
4390
- }), id = void 0, data = "", eventType = "";
4456
+ event: eventType,
4457
+ data
4458
+ }), id = void 0, data = "", dataLines = 0, eventType = void 0;
4391
4459
  }
4392
4460
  function reset(options = {}) {
4393
- incompleteLine && options.consume && parseLine(incompleteLine), isFirstChunk = true, id = void 0, data = "", eventType = "", incompleteLine = "";
4461
+ if (options.consume && pendingFragments.length > 0) {
4462
+ const incompleteLine = pendingFragments.join("");
4463
+ parseLine(incompleteLine, 0, incompleteLine.length);
4464
+ }
4465
+ isFirstChunk = true, id = void 0, data = "", dataLines = 0, eventType = void 0, pendingFragments.length = 0;
4394
4466
  }
4395
4467
  return { feed, reset };
4396
4468
  }
4397
- function splitLines(chunk) {
4398
- const lines = [];
4399
- let incompleteLine = "", searchIndex = 0;
4400
- for (; searchIndex < chunk.length; ) {
4401
- const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
4402
- `, searchIndex);
4403
- let lineEnd = -1;
4404
- 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) {
4405
- incompleteLine = chunk.slice(searchIndex);
4406
- break;
4407
- } else {
4408
- const line = chunk.slice(searchIndex, lineEnd);
4409
- lines.push(line), searchIndex = lineEnd + 1, chunk[searchIndex - 1] === "\r" && chunk[searchIndex] === `
4410
- ` && searchIndex++;
4411
- }
4412
- }
4413
- return [lines, incompleteLine];
4469
+ function isDataPrefix(chunk, i, firstCharCode) {
4470
+ return firstCharCode === 100 && chunk.charCodeAt(i + 1) === 97 && chunk.charCodeAt(i + 2) === 116 && chunk.charCodeAt(i + 3) === 97 && chunk.charCodeAt(i + 4) === 58;
4471
+ }
4472
+ function isEventPrefix(chunk, i, firstCharCode) {
4473
+ 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;
4414
4474
  }
4415
4475
  var EventSourceParserStream = class extends TransformStream {
4416
4476
  constructor({ onError, onRetry, onComment } = {}) {
@@ -4586,7 +4646,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
4586
4646
  );
4587
4647
  return Object.fromEntries(normalizedHeaders.entries());
4588
4648
  }
4589
- var VERSION2 = "3.0.22";
4649
+ var VERSION2 = "3.0.23";
4590
4650
  var getOriginalFetch = () => globalThis.fetch;
4591
4651
  var getFromApi = async ({
4592
4652
  url,
@@ -6248,138 +6308,17 @@ function asSchema2(schema) {
6248
6308
  function withoutTrailingSlash(url) {
6249
6309
  return url == null ? void 0 : url.replace(/\/$/, "");
6250
6310
  }
6251
- var require_get_context = chunkCK4U3AYR_cjs.__commonJS({
6252
- "../../../node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/get-context.js"(exports$1, module) {
6253
- var __defProp22 = Object.defineProperty;
6254
- var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
6255
- var __getOwnPropNames2 = Object.getOwnPropertyNames;
6256
- var __hasOwnProp2 = Object.prototype.hasOwnProperty;
6257
- var __export22 = (target, all) => {
6258
- for (var name163 in all)
6259
- __defProp22(target, name163, { get: all[name163], enumerable: true });
6260
- };
6261
- var __copyProps2 = (to, from, except, desc) => {
6262
- if (from && typeof from === "object" || typeof from === "function") {
6263
- for (let key of __getOwnPropNames2(from))
6264
- if (!__hasOwnProp2.call(to, key) && key !== except)
6265
- __defProp22(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
6266
- }
6267
- return to;
6268
- };
6269
- var __toCommonJS = (mod) => __copyProps2(__defProp22({}, "__esModule", { value: true }), mod);
6270
- var get_context_exports = {};
6271
- __export22(get_context_exports, {
6272
- SYMBOL_FOR_REQ_CONTEXT: () => SYMBOL_FOR_REQ_CONTEXT,
6273
- getContext: () => getContext3
6274
- });
6275
- module.exports = __toCommonJS(get_context_exports);
6276
- var SYMBOL_FOR_REQ_CONTEXT = /* @__PURE__ */ Symbol.for("@vercel/request-context");
6277
- function getContext3() {
6278
- const fromSymbol = globalThis;
6279
- return fromSymbol[SYMBOL_FOR_REQ_CONTEXT]?.get?.() ?? {};
6280
- }
6281
- }
6282
- });
6283
- var require_get_vercel_oidc_token = chunkCK4U3AYR_cjs.__commonJS({
6284
- "../../../node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/get-vercel-oidc-token.js"(exports$1, module) {
6285
- var __defProp22 = Object.defineProperty;
6286
- var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
6287
- var __getOwnPropNames2 = Object.getOwnPropertyNames;
6288
- var __hasOwnProp2 = Object.prototype.hasOwnProperty;
6289
- var __export22 = (target, all) => {
6290
- for (var name163 in all)
6291
- __defProp22(target, name163, { get: all[name163], enumerable: true });
6292
- };
6293
- var __copyProps2 = (to, from, except, desc) => {
6294
- if (from && typeof from === "object" || typeof from === "function") {
6295
- for (let key of __getOwnPropNames2(from))
6296
- if (!__hasOwnProp2.call(to, key) && key !== except)
6297
- __defProp22(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
6298
- }
6299
- return to;
6300
- };
6301
- var __toCommonJS = (mod) => __copyProps2(__defProp22({}, "__esModule", { value: true }), mod);
6302
- var get_vercel_oidc_token_exports = {};
6303
- __export22(get_vercel_oidc_token_exports, {
6304
- getVercelOidcToken: () => getVercelOidcToken3,
6305
- getVercelOidcTokenSync: () => getVercelOidcTokenSync2
6306
- });
6307
- module.exports = __toCommonJS(get_vercel_oidc_token_exports);
6308
- var import_get_context = require_get_context();
6309
- var import_token_error = chunkCK4U3AYR_cjs.require_token_error();
6310
- async function getVercelOidcToken3() {
6311
- let token = "";
6312
- let err;
6313
- try {
6314
- token = getVercelOidcTokenSync2();
6315
- } catch (error) {
6316
- err = error;
6317
- }
6318
- try {
6319
- const [{ getTokenPayload, isExpired }, { refreshToken }] = await Promise.all([
6320
- await import('./token-util-RMHT2CPJ-77HHGIQN.cjs'),
6321
- await import('./token-APYSY3BW-POD4OUWN.cjs')
6322
- ]);
6323
- if (!token || isExpired(getTokenPayload(token))) {
6324
- await refreshToken();
6325
- token = getVercelOidcTokenSync2();
6326
- }
6327
- } catch (error) {
6328
- let message = err instanceof Error ? err.message : "";
6329
- if (error instanceof Error) {
6330
- message = `${message}
6331
- ${error.message}`;
6332
- }
6333
- if (message) {
6334
- throw new import_token_error.VercelOidcTokenError(message);
6335
- }
6336
- throw error;
6337
- }
6338
- return token;
6339
- }
6340
- function getVercelOidcTokenSync2() {
6341
- const token = (0, import_get_context.getContext)().headers?.["x-vercel-oidc-token"] ?? process.env.VERCEL_OIDC_TOKEN;
6342
- if (!token) {
6343
- throw new Error(
6344
- `The 'x-vercel-oidc-token' header is missing from the request. Do you have the OIDC option enabled in the Vercel project settings?`
6345
- );
6346
- }
6347
- return token;
6348
- }
6349
- }
6350
- });
6351
- var require_dist = chunkCK4U3AYR_cjs.__commonJS({
6352
- "../../../node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/index.js"(exports$1, module) {
6353
- var __defProp22 = Object.defineProperty;
6354
- var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
6355
- var __getOwnPropNames2 = Object.getOwnPropertyNames;
6356
- var __hasOwnProp2 = Object.prototype.hasOwnProperty;
6357
- var __export22 = (target, all) => {
6358
- for (var name163 in all)
6359
- __defProp22(target, name163, { get: all[name163], enumerable: true });
6360
- };
6361
- var __copyProps2 = (to, from, except, desc) => {
6362
- if (from && typeof from === "object" || typeof from === "function") {
6363
- for (let key of __getOwnPropNames2(from))
6364
- if (!__hasOwnProp2.call(to, key) && key !== except)
6365
- __defProp22(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
6366
- }
6367
- return to;
6368
- };
6369
- var __toCommonJS = (mod) => __copyProps2(__defProp22({}, "__esModule", { value: true }), mod);
6370
- var src_exports = {};
6371
- __export22(src_exports, {
6372
- getContext: () => import_get_context.getContext,
6373
- getVercelOidcToken: () => import_get_vercel_oidc_token.getVercelOidcToken,
6374
- getVercelOidcTokenSync: () => import_get_vercel_oidc_token.getVercelOidcTokenSync
6375
- });
6376
- module.exports = __toCommonJS(src_exports);
6377
- var import_get_vercel_oidc_token = require_get_vercel_oidc_token();
6378
- var import_get_context = require_get_context();
6311
+ function getContext() {
6312
+ return {
6313
+ headers: {}
6314
+ };
6315
+ }
6316
+ async function getVercelOidcToken() {
6317
+ if (process.env.VERCEL_OIDC_TOKEN) {
6318
+ return process.env.VERCEL_OIDC_TOKEN ?? "";
6379
6319
  }
6380
- });
6381
- var import_oidc = chunkCK4U3AYR_cjs.__toESM(require_dist(), 1);
6382
- var import_oidc2 = chunkCK4U3AYR_cjs.__toESM(require_dist(), 1);
6320
+ throw new Error("@vercel/oidc is not available in the vendored @internal AI packages. Provide an API key instead.");
6321
+ }
6383
6322
  var marker18 = "vercel.ai.gateway.error";
6384
6323
  var symbol18 = Symbol.for(marker18);
6385
6324
  var _a18;
@@ -6754,6 +6693,7 @@ async function parseAuthMethod(headers) {
6754
6693
  var gatewayAuthMethodSchema = lazyValidator(
6755
6694
  () => zodSchema2(z4.z.union([z4.z.literal("api-key"), z4.z.literal("oidc")]))
6756
6695
  );
6696
+ var KNOWN_MODEL_TYPES = ["embedding", "image", "language"];
6757
6697
  var GatewayFetchMetadata = class {
6758
6698
  constructor(config) {
6759
6699
  this.config = config;
@@ -6824,8 +6764,12 @@ var gatewayAvailableModelsResponseSchema = lazyValidator(
6824
6764
  provider: z4.z.string(),
6825
6765
  modelId: z4.z.string()
6826
6766
  }),
6827
- modelType: z4.z.enum(["language", "embedding", "image"]).nullish()
6767
+ modelType: z4.z.string().nullish()
6828
6768
  })
6769
+ ).transform(
6770
+ (models) => models.filter(
6771
+ (m) => m.modelType == null || KNOWN_MODEL_TYPES.includes(m.modelType)
6772
+ )
6829
6773
  )
6830
6774
  })
6831
6775
  )
@@ -6841,6 +6785,187 @@ var gatewayCreditsResponseSchema = lazyValidator(
6841
6785
  }))
6842
6786
  )
6843
6787
  );
6788
+ var GatewaySpendReport = class {
6789
+ constructor(config) {
6790
+ this.config = config;
6791
+ }
6792
+ async getSpendReport(params) {
6793
+ try {
6794
+ const baseUrl = new URL(this.config.baseURL);
6795
+ const searchParams = new URLSearchParams();
6796
+ searchParams.set("start_date", params.startDate);
6797
+ searchParams.set("end_date", params.endDate);
6798
+ if (params.groupBy) {
6799
+ searchParams.set("group_by", params.groupBy);
6800
+ }
6801
+ if (params.datePart) {
6802
+ searchParams.set("date_part", params.datePart);
6803
+ }
6804
+ if (params.userId) {
6805
+ searchParams.set("user_id", params.userId);
6806
+ }
6807
+ if (params.model) {
6808
+ searchParams.set("model", params.model);
6809
+ }
6810
+ if (params.provider) {
6811
+ searchParams.set("provider", params.provider);
6812
+ }
6813
+ if (params.credentialType) {
6814
+ searchParams.set("credential_type", params.credentialType);
6815
+ }
6816
+ if (params.tags && params.tags.length > 0) {
6817
+ searchParams.set("tags", params.tags.join(","));
6818
+ }
6819
+ const { value } = await getFromApi({
6820
+ url: `${baseUrl.origin}/v1/report?${searchParams.toString()}`,
6821
+ headers: await resolve(this.config.headers()),
6822
+ successfulResponseHandler: createJsonResponseHandler(
6823
+ gatewaySpendReportResponseSchema
6824
+ ),
6825
+ failedResponseHandler: createJsonErrorResponseHandler({
6826
+ errorSchema: z4.z.any(),
6827
+ errorToMessage: (data) => data
6828
+ }),
6829
+ fetch: this.config.fetch
6830
+ });
6831
+ return value;
6832
+ } catch (error) {
6833
+ throw await asGatewayError(error);
6834
+ }
6835
+ }
6836
+ };
6837
+ var gatewaySpendReportResponseSchema = lazySchema(
6838
+ () => zodSchema2(
6839
+ z4.z.object({
6840
+ results: z4.z.array(
6841
+ z4.z.object({
6842
+ day: z4.z.string().optional(),
6843
+ hour: z4.z.string().optional(),
6844
+ user: z4.z.string().optional(),
6845
+ model: z4.z.string().optional(),
6846
+ tag: z4.z.string().optional(),
6847
+ provider: z4.z.string().optional(),
6848
+ credential_type: z4.z.enum(["byok", "system"]).optional(),
6849
+ total_cost: z4.z.number(),
6850
+ market_cost: z4.z.number().optional(),
6851
+ input_tokens: z4.z.number().optional(),
6852
+ output_tokens: z4.z.number().optional(),
6853
+ cached_input_tokens: z4.z.number().optional(),
6854
+ cache_creation_input_tokens: z4.z.number().optional(),
6855
+ reasoning_tokens: z4.z.number().optional(),
6856
+ request_count: z4.z.number().optional()
6857
+ }).transform(
6858
+ ({
6859
+ credential_type,
6860
+ total_cost,
6861
+ market_cost,
6862
+ input_tokens,
6863
+ output_tokens,
6864
+ cached_input_tokens,
6865
+ cache_creation_input_tokens,
6866
+ reasoning_tokens,
6867
+ request_count,
6868
+ ...rest
6869
+ }) => ({
6870
+ ...rest,
6871
+ ...credential_type !== void 0 ? { credentialType: credential_type } : {},
6872
+ totalCost: total_cost,
6873
+ ...market_cost !== void 0 ? { marketCost: market_cost } : {},
6874
+ ...input_tokens !== void 0 ? { inputTokens: input_tokens } : {},
6875
+ ...output_tokens !== void 0 ? { outputTokens: output_tokens } : {},
6876
+ ...cached_input_tokens !== void 0 ? { cachedInputTokens: cached_input_tokens } : {},
6877
+ ...cache_creation_input_tokens !== void 0 ? { cacheCreationInputTokens: cache_creation_input_tokens } : {},
6878
+ ...reasoning_tokens !== void 0 ? { reasoningTokens: reasoning_tokens } : {},
6879
+ ...request_count !== void 0 ? { requestCount: request_count } : {}
6880
+ })
6881
+ )
6882
+ )
6883
+ })
6884
+ )
6885
+ );
6886
+ var GatewayGenerationInfoFetcher = class {
6887
+ constructor(config) {
6888
+ this.config = config;
6889
+ }
6890
+ async getGenerationInfo(params) {
6891
+ try {
6892
+ const baseUrl = new URL(this.config.baseURL);
6893
+ const { value } = await getFromApi({
6894
+ url: `${baseUrl.origin}/v1/generation?id=${encodeURIComponent(params.id)}`,
6895
+ headers: await resolve(this.config.headers()),
6896
+ successfulResponseHandler: createJsonResponseHandler(
6897
+ gatewayGenerationInfoResponseSchema
6898
+ ),
6899
+ failedResponseHandler: createJsonErrorResponseHandler({
6900
+ errorSchema: z4.z.any(),
6901
+ errorToMessage: (data) => data
6902
+ }),
6903
+ fetch: this.config.fetch
6904
+ });
6905
+ return value;
6906
+ } catch (error) {
6907
+ throw await asGatewayError(error);
6908
+ }
6909
+ }
6910
+ };
6911
+ var gatewayGenerationInfoResponseSchema = lazySchema(
6912
+ () => zodSchema2(
6913
+ z4.z.object({
6914
+ data: z4.z.object({
6915
+ id: z4.z.string(),
6916
+ total_cost: z4.z.number(),
6917
+ upstream_inference_cost: z4.z.number(),
6918
+ usage: z4.z.number(),
6919
+ created_at: z4.z.string(),
6920
+ model: z4.z.string(),
6921
+ is_byok: z4.z.boolean(),
6922
+ provider_name: z4.z.string(),
6923
+ streamed: z4.z.boolean(),
6924
+ finish_reason: z4.z.string(),
6925
+ latency: z4.z.number(),
6926
+ generation_time: z4.z.number(),
6927
+ native_tokens_prompt: z4.z.number(),
6928
+ native_tokens_completion: z4.z.number(),
6929
+ native_tokens_reasoning: z4.z.number(),
6930
+ native_tokens_cached: z4.z.number(),
6931
+ native_tokens_cache_creation: z4.z.number(),
6932
+ billable_web_search_calls: z4.z.number()
6933
+ }).transform(
6934
+ ({
6935
+ total_cost,
6936
+ upstream_inference_cost,
6937
+ created_at,
6938
+ is_byok,
6939
+ provider_name,
6940
+ finish_reason,
6941
+ generation_time,
6942
+ native_tokens_prompt,
6943
+ native_tokens_completion,
6944
+ native_tokens_reasoning,
6945
+ native_tokens_cached,
6946
+ native_tokens_cache_creation,
6947
+ billable_web_search_calls,
6948
+ ...rest
6949
+ }) => ({
6950
+ ...rest,
6951
+ totalCost: total_cost,
6952
+ upstreamInferenceCost: upstream_inference_cost,
6953
+ createdAt: created_at,
6954
+ isByok: is_byok,
6955
+ providerName: provider_name,
6956
+ finishReason: finish_reason,
6957
+ generationTime: generation_time,
6958
+ promptTokens: native_tokens_prompt,
6959
+ completionTokens: native_tokens_completion,
6960
+ reasoningTokens: native_tokens_reasoning,
6961
+ cachedTokens: native_tokens_cached,
6962
+ cacheCreationTokens: native_tokens_cache_creation,
6963
+ billableWebSearchCalls: billable_web_search_calls
6964
+ })
6965
+ )
6966
+ }).transform(({ data }) => data)
6967
+ )
6968
+ );
6844
6969
  var GatewayLanguageModel = class {
6845
6970
  constructor(modelId, config) {
6846
6971
  this.modelId = modelId;
@@ -7341,9 +7466,9 @@ var gatewayTools = {
7341
7466
  };
7342
7467
  async function getVercelRequestId() {
7343
7468
  var _a932;
7344
- return (_a932 = (0, import_oidc.getContext)().headers) == null ? void 0 : _a932["x-vercel-id"];
7469
+ return (_a932 = getContext().headers) == null ? void 0 : _a932["x-vercel-id"];
7345
7470
  }
7346
- var VERSION3 = "2.0.59";
7471
+ var VERSION3 = "2.0.82";
7347
7472
  var AI_GATEWAY_PROTOCOL_VERSION = "0.0.1";
7348
7473
  function createGatewayProvider(options = {}) {
7349
7474
  var _a932, _b93;
@@ -7441,6 +7566,30 @@ function createGatewayProvider(options = {}) {
7441
7566
  );
7442
7567
  });
7443
7568
  };
7569
+ const getSpendReport = async (params) => {
7570
+ return new GatewaySpendReport({
7571
+ baseURL,
7572
+ headers: getHeaders,
7573
+ fetch: options.fetch
7574
+ }).getSpendReport(params).catch(async (error) => {
7575
+ throw await asGatewayError(
7576
+ error,
7577
+ await parseAuthMethod(await getHeaders())
7578
+ );
7579
+ });
7580
+ };
7581
+ const getGenerationInfo = async (params) => {
7582
+ return new GatewayGenerationInfoFetcher({
7583
+ baseURL,
7584
+ headers: getHeaders,
7585
+ fetch: options.fetch
7586
+ }).getGenerationInfo(params).catch(async (error) => {
7587
+ throw await asGatewayError(
7588
+ error,
7589
+ await parseAuthMethod(await getHeaders())
7590
+ );
7591
+ });
7592
+ };
7444
7593
  const provider = function(modelId) {
7445
7594
  if (new.target) {
7446
7595
  throw new Error(
@@ -7451,6 +7600,8 @@ function createGatewayProvider(options = {}) {
7451
7600
  };
7452
7601
  provider.getAvailableModels = getAvailableModels;
7453
7602
  provider.getCredits = getCredits;
7603
+ provider.getSpendReport = getSpendReport;
7604
+ provider.getGenerationInfo = getGenerationInfo;
7454
7605
  provider.imageModel = (modelId) => {
7455
7606
  return new GatewayImageModel(modelId, {
7456
7607
  provider: "gateway",
@@ -7486,7 +7637,7 @@ async function getGatewayAuthToken(options) {
7486
7637
  };
7487
7638
  }
7488
7639
  try {
7489
- const oidcToken = await (0, import_oidc2.getVercelOidcToken)();
7640
+ const oidcToken = await getVercelOidcToken();
7490
7641
  return {
7491
7642
  token: oidcToken,
7492
7643
  authMethod: "oidc"
@@ -8304,7 +8455,7 @@ function getGlobalProvider() {
8304
8455
  var _a163;
8305
8456
  return (_a163 = globalThis.AI_SDK_DEFAULT_PROVIDER) != null ? _a163 : gateway;
8306
8457
  }
8307
- var VERSION32 = "5.0.155";
8458
+ var VERSION32 = "5.0.179";
8308
8459
  var dataContentSchema2 = z4.z.union([
8309
8460
  z4.z.string(),
8310
8461
  z4.z.instanceof(Uint8Array),
@@ -9609,6 +9760,9 @@ var ParseError2 = class extends Error {
9609
9760
  super(message), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
9610
9761
  }
9611
9762
  };
9763
+ var LF2 = 10;
9764
+ var CR2 = 13;
9765
+ var SPACE2 = 32;
9612
9766
  function noop2(_arg) {
9613
9767
  }
9614
9768
  function createParser2(callbacks) {
@@ -9616,39 +9770,109 @@ function createParser2(callbacks) {
9616
9770
  throw new TypeError(
9617
9771
  "`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?"
9618
9772
  );
9619
- const { onEvent = noop2, onError = noop2, onRetry = noop2, onComment } = callbacks;
9620
- let incompleteLine = "", isFirstChunk = true, id, data = "", eventType = "";
9621
- function feed(newChunk) {
9622
- const chunk = isFirstChunk ? newChunk.replace(/^\xEF\xBB\xBF/, "") : newChunk, [complete, incomplete] = splitLines2(`${incompleteLine}${chunk}`);
9623
- for (const line of complete)
9624
- parseLine(line);
9625
- incompleteLine = incomplete, isFirstChunk = false;
9626
- }
9627
- function parseLine(line) {
9628
- if (line === "") {
9773
+ const { onEvent = noop2, onError = noop2, onRetry = noop2, onComment } = callbacks, pendingFragments = [];
9774
+ let isFirstChunk = true, id, data = "", dataLines = 0, eventType;
9775
+ function feed(chunk) {
9776
+ if (isFirstChunk && (isFirstChunk = false, chunk.charCodeAt(0) === 239 && chunk.charCodeAt(1) === 187 && chunk.charCodeAt(2) === 191 && (chunk = chunk.slice(3))), pendingFragments.length === 0) {
9777
+ const trailing2 = processLines(chunk);
9778
+ trailing2 !== "" && pendingFragments.push(trailing2);
9779
+ return;
9780
+ }
9781
+ if (chunk.indexOf(`
9782
+ `) === -1 && chunk.indexOf("\r") === -1) {
9783
+ pendingFragments.push(chunk);
9784
+ return;
9785
+ }
9786
+ pendingFragments.push(chunk);
9787
+ const input = pendingFragments.join("");
9788
+ pendingFragments.length = 0;
9789
+ const trailing = processLines(input);
9790
+ trailing !== "" && pendingFragments.push(trailing);
9791
+ }
9792
+ function processLines(chunk) {
9793
+ let searchIndex = 0;
9794
+ if (chunk.indexOf("\r") === -1) {
9795
+ let lfIndex = chunk.indexOf(`
9796
+ `, searchIndex);
9797
+ for (; lfIndex !== -1; ) {
9798
+ if (searchIndex === lfIndex) {
9799
+ dataLines > 0 && onEvent({ id, event: eventType, data }), id = void 0, data = "", dataLines = 0, eventType = void 0, searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
9800
+ `, searchIndex);
9801
+ continue;
9802
+ }
9803
+ const firstCharCode = chunk.charCodeAt(searchIndex);
9804
+ if (isDataPrefix2(chunk, searchIndex, firstCharCode)) {
9805
+ const valueStart = chunk.charCodeAt(searchIndex + 5) === SPACE2 ? searchIndex + 6 : searchIndex + 5, value = chunk.slice(valueStart, lfIndex);
9806
+ if (dataLines === 0 && chunk.charCodeAt(lfIndex + 1) === LF2) {
9807
+ onEvent({ id, event: eventType, data: value }), id = void 0, data = "", eventType = void 0, searchIndex = lfIndex + 2, lfIndex = chunk.indexOf(`
9808
+ `, searchIndex);
9809
+ continue;
9810
+ }
9811
+ data = dataLines === 0 ? value : `${data}
9812
+ ${value}`, dataLines++;
9813
+ } else isEventPrefix2(chunk, searchIndex, firstCharCode) ? eventType = chunk.slice(
9814
+ chunk.charCodeAt(searchIndex + 6) === SPACE2 ? searchIndex + 7 : searchIndex + 6,
9815
+ lfIndex
9816
+ ) || void 0 : parseLine(chunk, searchIndex, lfIndex);
9817
+ searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
9818
+ `, searchIndex);
9819
+ }
9820
+ return chunk.slice(searchIndex);
9821
+ }
9822
+ for (; searchIndex < chunk.length; ) {
9823
+ const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
9824
+ `, searchIndex);
9825
+ let lineEnd = -1;
9826
+ 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)
9827
+ break;
9828
+ parseLine(chunk, searchIndex, lineEnd), searchIndex = lineEnd + 1, chunk.charCodeAt(searchIndex - 1) === CR2 && chunk.charCodeAt(searchIndex) === LF2 && searchIndex++;
9829
+ }
9830
+ return chunk.slice(searchIndex);
9831
+ }
9832
+ function parseLine(chunk, start, end) {
9833
+ if (start === end) {
9629
9834
  dispatchEvent();
9630
9835
  return;
9631
9836
  }
9632
- if (line.startsWith(":")) {
9633
- onComment && onComment(line.slice(line.startsWith(": ") ? 2 : 1));
9837
+ const firstCharCode = chunk.charCodeAt(start);
9838
+ if (isDataPrefix2(chunk, start, firstCharCode)) {
9839
+ const valueStart = chunk.charCodeAt(start + 5) === SPACE2 ? start + 6 : start + 5, value2 = chunk.slice(valueStart, end);
9840
+ data = dataLines === 0 ? value2 : `${data}
9841
+ ${value2}`, dataLines++;
9842
+ return;
9843
+ }
9844
+ if (isEventPrefix2(chunk, start, firstCharCode)) {
9845
+ eventType = chunk.slice(chunk.charCodeAt(start + 6) === SPACE2 ? start + 7 : start + 6, end) || void 0;
9846
+ return;
9847
+ }
9848
+ if (firstCharCode === 105 && chunk.charCodeAt(start + 1) === 100 && chunk.charCodeAt(start + 2) === 58) {
9849
+ const value2 = chunk.slice(chunk.charCodeAt(start + 3) === SPACE2 ? start + 4 : start + 3, end);
9850
+ id = value2.includes("\0") ? void 0 : value2;
9851
+ return;
9852
+ }
9853
+ if (firstCharCode === 58) {
9854
+ if (onComment) {
9855
+ const line2 = chunk.slice(start, end);
9856
+ onComment(line2.slice(chunk.charCodeAt(start + 1) === SPACE2 ? 2 : 1));
9857
+ }
9634
9858
  return;
9635
9859
  }
9636
- const fieldSeparatorIndex = line.indexOf(":");
9637
- if (fieldSeparatorIndex !== -1) {
9638
- const field = line.slice(0, fieldSeparatorIndex), offset = line[fieldSeparatorIndex + 1] === " " ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
9639
- processField(field, value, line);
9860
+ const line = chunk.slice(start, end), fieldSeparatorIndex = line.indexOf(":");
9861
+ if (fieldSeparatorIndex === -1) {
9862
+ processField(line, "", line);
9640
9863
  return;
9641
9864
  }
9642
- processField(line, "", line);
9865
+ const field = line.slice(0, fieldSeparatorIndex), offset = line.charCodeAt(fieldSeparatorIndex + 1) === SPACE2 ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
9866
+ processField(field, value, line);
9643
9867
  }
9644
9868
  function processField(field, value, line) {
9645
9869
  switch (field) {
9646
9870
  case "event":
9647
- eventType = value;
9871
+ eventType = value || void 0;
9648
9872
  break;
9649
9873
  case "data":
9650
- data = `${data}${value}
9651
- `;
9874
+ data = dataLines === 0 ? value : `${data}
9875
+ ${value}`, dataLines++;
9652
9876
  break;
9653
9877
  case "id":
9654
9878
  id = value.includes("\0") ? void 0 : value;
@@ -9673,37 +9897,26 @@ function createParser2(callbacks) {
9673
9897
  }
9674
9898
  }
9675
9899
  function dispatchEvent() {
9676
- data.length > 0 && onEvent({
9900
+ dataLines > 0 && onEvent({
9677
9901
  id,
9678
- event: eventType || void 0,
9679
- // If the data buffer's last character is a U+000A LINE FEED (LF) character,
9680
- // then remove the last character from the data buffer.
9681
- data: data.endsWith(`
9682
- `) ? data.slice(0, -1) : data
9683
- }), id = void 0, data = "", eventType = "";
9902
+ event: eventType,
9903
+ data
9904
+ }), id = void 0, data = "", dataLines = 0, eventType = void 0;
9684
9905
  }
9685
9906
  function reset(options = {}) {
9686
- incompleteLine && options.consume && parseLine(incompleteLine), isFirstChunk = true, id = void 0, data = "", eventType = "", incompleteLine = "";
9907
+ if (options.consume && pendingFragments.length > 0) {
9908
+ const incompleteLine = pendingFragments.join("");
9909
+ parseLine(incompleteLine, 0, incompleteLine.length);
9910
+ }
9911
+ isFirstChunk = true, id = void 0, data = "", dataLines = 0, eventType = void 0, pendingFragments.length = 0;
9687
9912
  }
9688
9913
  return { feed, reset };
9689
9914
  }
9690
- function splitLines2(chunk) {
9691
- const lines = [];
9692
- let incompleteLine = "", searchIndex = 0;
9693
- for (; searchIndex < chunk.length; ) {
9694
- const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
9695
- `, searchIndex);
9696
- let lineEnd = -1;
9697
- 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) {
9698
- incompleteLine = chunk.slice(searchIndex);
9699
- break;
9700
- } else {
9701
- const line = chunk.slice(searchIndex, lineEnd);
9702
- lines.push(line), searchIndex = lineEnd + 1, chunk[searchIndex - 1] === "\r" && chunk[searchIndex] === `
9703
- ` && searchIndex++;
9704
- }
9705
- }
9706
- return [lines, incompleteLine];
9915
+ function isDataPrefix2(chunk, i, firstCharCode) {
9916
+ return firstCharCode === 100 && chunk.charCodeAt(i + 1) === 97 && chunk.charCodeAt(i + 2) === 116 && chunk.charCodeAt(i + 3) === 97 && chunk.charCodeAt(i + 4) === 58;
9917
+ }
9918
+ function isEventPrefix2(chunk, i, firstCharCode) {
9919
+ 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;
9707
9920
  }
9708
9921
  var EventSourceParserStream2 = class extends TransformStream {
9709
9922
  constructor({ onError, onRetry, onComment } = {}) {
@@ -9915,7 +10128,7 @@ function withUserAgentSuffix2(headers, ...userAgentSuffixParts) {
9915
10128
  );
9916
10129
  return Object.fromEntries(normalizedHeaders.entries());
9917
10130
  }
9918
- var VERSION4 = "4.0.19";
10131
+ var VERSION4 = "4.0.23";
9919
10132
  var getOriginalFetch3 = () => globalThis.fetch;
9920
10133
  var getFromApi2 = async ({
9921
10134
  url,
@@ -11575,138 +11788,17 @@ var createJsonResponseHandler2 = (responseSchema) => async ({ response, url, req
11575
11788
  function withoutTrailingSlash2(url) {
11576
11789
  return url == null ? void 0 : url.replace(/\/$/, "");
11577
11790
  }
11578
- var require_get_context2 = chunkIDRQZVB4_cjs.__commonJS({
11579
- "../../../node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/get-context.js"(exports$1, module) {
11580
- var __defProp22 = Object.defineProperty;
11581
- var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
11582
- var __getOwnPropNames2 = Object.getOwnPropertyNames;
11583
- var __hasOwnProp2 = Object.prototype.hasOwnProperty;
11584
- var __export22 = (target, all) => {
11585
- for (var name21 in all)
11586
- __defProp22(target, name21, { get: all[name21], enumerable: true });
11587
- };
11588
- var __copyProps2 = (to, from, except, desc) => {
11589
- if (from && typeof from === "object" || typeof from === "function") {
11590
- for (let key of __getOwnPropNames2(from))
11591
- if (!__hasOwnProp2.call(to, key) && key !== except)
11592
- __defProp22(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
11593
- }
11594
- return to;
11595
- };
11596
- var __toCommonJS = (mod) => __copyProps2(__defProp22({}, "__esModule", { value: true }), mod);
11597
- var get_context_exports = {};
11598
- __export22(get_context_exports, {
11599
- SYMBOL_FOR_REQ_CONTEXT: () => SYMBOL_FOR_REQ_CONTEXT,
11600
- getContext: () => getContext3
11601
- });
11602
- module.exports = __toCommonJS(get_context_exports);
11603
- var SYMBOL_FOR_REQ_CONTEXT = /* @__PURE__ */ Symbol.for("@vercel/request-context");
11604
- function getContext3() {
11605
- const fromSymbol = globalThis;
11606
- return fromSymbol[SYMBOL_FOR_REQ_CONTEXT]?.get?.() ?? {};
11607
- }
11608
- }
11609
- });
11610
- var require_get_vercel_oidc_token2 = chunkIDRQZVB4_cjs.__commonJS({
11611
- "../../../node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/get-vercel-oidc-token.js"(exports$1, module) {
11612
- var __defProp22 = Object.defineProperty;
11613
- var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
11614
- var __getOwnPropNames2 = Object.getOwnPropertyNames;
11615
- var __hasOwnProp2 = Object.prototype.hasOwnProperty;
11616
- var __export22 = (target, all) => {
11617
- for (var name21 in all)
11618
- __defProp22(target, name21, { get: all[name21], enumerable: true });
11619
- };
11620
- var __copyProps2 = (to, from, except, desc) => {
11621
- if (from && typeof from === "object" || typeof from === "function") {
11622
- for (let key of __getOwnPropNames2(from))
11623
- if (!__hasOwnProp2.call(to, key) && key !== except)
11624
- __defProp22(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
11625
- }
11626
- return to;
11627
- };
11628
- var __toCommonJS = (mod) => __copyProps2(__defProp22({}, "__esModule", { value: true }), mod);
11629
- var get_vercel_oidc_token_exports = {};
11630
- __export22(get_vercel_oidc_token_exports, {
11631
- getVercelOidcToken: () => getVercelOidcToken3,
11632
- getVercelOidcTokenSync: () => getVercelOidcTokenSync2
11633
- });
11634
- module.exports = __toCommonJS(get_vercel_oidc_token_exports);
11635
- var import_get_context = require_get_context2();
11636
- var import_token_error = chunkIDRQZVB4_cjs.require_token_error();
11637
- async function getVercelOidcToken3() {
11638
- let token = "";
11639
- let err;
11640
- try {
11641
- token = getVercelOidcTokenSync2();
11642
- } catch (error) {
11643
- err = error;
11644
- }
11645
- try {
11646
- const [{ getTokenPayload, isExpired }, { refreshToken }] = await Promise.all([
11647
- await import('./token-util-RMHT2CPJ-6TGPE335.cjs'),
11648
- await import('./token-APYSY3BW-ZQ7TMBY7.cjs')
11649
- ]);
11650
- if (!token || isExpired(getTokenPayload(token))) {
11651
- await refreshToken();
11652
- token = getVercelOidcTokenSync2();
11653
- }
11654
- } catch (error) {
11655
- let message = err instanceof Error ? err.message : "";
11656
- if (error instanceof Error) {
11657
- message = `${message}
11658
- ${error.message}`;
11659
- }
11660
- if (message) {
11661
- throw new import_token_error.VercelOidcTokenError(message);
11662
- }
11663
- throw error;
11664
- }
11665
- return token;
11666
- }
11667
- function getVercelOidcTokenSync2() {
11668
- const token = (0, import_get_context.getContext)().headers?.["x-vercel-oidc-token"] ?? process.env.VERCEL_OIDC_TOKEN;
11669
- if (!token) {
11670
- throw new Error(
11671
- `The 'x-vercel-oidc-token' header is missing from the request. Do you have the OIDC option enabled in the Vercel project settings?`
11672
- );
11673
- }
11674
- return token;
11675
- }
11676
- }
11677
- });
11678
- var require_dist2 = chunkIDRQZVB4_cjs.__commonJS({
11679
- "../../../node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/index.js"(exports$1, module) {
11680
- var __defProp22 = Object.defineProperty;
11681
- var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
11682
- var __getOwnPropNames2 = Object.getOwnPropertyNames;
11683
- var __hasOwnProp2 = Object.prototype.hasOwnProperty;
11684
- var __export22 = (target, all) => {
11685
- for (var name21 in all)
11686
- __defProp22(target, name21, { get: all[name21], enumerable: true });
11687
- };
11688
- var __copyProps2 = (to, from, except, desc) => {
11689
- if (from && typeof from === "object" || typeof from === "function") {
11690
- for (let key of __getOwnPropNames2(from))
11691
- if (!__hasOwnProp2.call(to, key) && key !== except)
11692
- __defProp22(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
11693
- }
11694
- return to;
11695
- };
11696
- var __toCommonJS = (mod) => __copyProps2(__defProp22({}, "__esModule", { value: true }), mod);
11697
- var src_exports = {};
11698
- __export22(src_exports, {
11699
- getContext: () => import_get_context.getContext,
11700
- getVercelOidcToken: () => import_get_vercel_oidc_token.getVercelOidcToken,
11701
- getVercelOidcTokenSync: () => import_get_vercel_oidc_token.getVercelOidcTokenSync
11702
- });
11703
- module.exports = __toCommonJS(src_exports);
11704
- var import_get_vercel_oidc_token = require_get_vercel_oidc_token2();
11705
- var import_get_context = require_get_context2();
11791
+ function getContext2() {
11792
+ return {
11793
+ headers: {}
11794
+ };
11795
+ }
11796
+ async function getVercelOidcToken2() {
11797
+ if (process.env.VERCEL_OIDC_TOKEN) {
11798
+ return process.env.VERCEL_OIDC_TOKEN ?? "";
11706
11799
  }
11707
- });
11708
- var import_oidc3 = chunkIDRQZVB4_cjs.__toESM(require_dist2(), 1);
11709
- var import_oidc22 = chunkIDRQZVB4_cjs.__toESM(require_dist2(), 1);
11800
+ throw new Error("@vercel/oidc is not available in the vendored @internal AI packages. Provide an API key instead.");
11801
+ }
11710
11802
  var marker20 = "vercel.ai.gateway.error";
11711
11803
  var symbol20 = Symbol.for(marker20);
11712
11804
  var _a20;
@@ -12121,6 +12213,13 @@ async function parseAuthMethod2(headers) {
12121
12213
  var gatewayAuthMethodSchema2 = lazySchema2(
12122
12214
  () => zodSchema3(z4.z.union([z4.z.literal("api-key"), z4.z.literal("oidc")]))
12123
12215
  );
12216
+ var KNOWN_MODEL_TYPES2 = [
12217
+ "embedding",
12218
+ "image",
12219
+ "language",
12220
+ "reranking",
12221
+ "video"
12222
+ ];
12124
12223
  var GatewayFetchMetadata2 = class {
12125
12224
  constructor(config) {
12126
12225
  this.config = config;
@@ -12191,8 +12290,12 @@ var gatewayAvailableModelsResponseSchema2 = lazySchema2(
12191
12290
  provider: z4.z.string(),
12192
12291
  modelId: z4.z.string()
12193
12292
  }),
12194
- modelType: z4.z.enum(["embedding", "image", "language", "video"]).nullish()
12293
+ modelType: z4.z.string().nullish()
12195
12294
  })
12295
+ ).transform(
12296
+ (models) => models.filter(
12297
+ (m) => m.modelType == null || KNOWN_MODEL_TYPES2.includes(m.modelType)
12298
+ )
12196
12299
  )
12197
12300
  })
12198
12301
  )
@@ -12208,6 +12311,187 @@ var gatewayCreditsResponseSchema2 = lazySchema2(
12208
12311
  }))
12209
12312
  )
12210
12313
  );
12314
+ var GatewaySpendReport2 = class {
12315
+ constructor(config) {
12316
+ this.config = config;
12317
+ }
12318
+ async getSpendReport(params) {
12319
+ try {
12320
+ const baseUrl = new URL(this.config.baseURL);
12321
+ const searchParams = new URLSearchParams();
12322
+ searchParams.set("start_date", params.startDate);
12323
+ searchParams.set("end_date", params.endDate);
12324
+ if (params.groupBy) {
12325
+ searchParams.set("group_by", params.groupBy);
12326
+ }
12327
+ if (params.datePart) {
12328
+ searchParams.set("date_part", params.datePart);
12329
+ }
12330
+ if (params.userId) {
12331
+ searchParams.set("user_id", params.userId);
12332
+ }
12333
+ if (params.model) {
12334
+ searchParams.set("model", params.model);
12335
+ }
12336
+ if (params.provider) {
12337
+ searchParams.set("provider", params.provider);
12338
+ }
12339
+ if (params.credentialType) {
12340
+ searchParams.set("credential_type", params.credentialType);
12341
+ }
12342
+ if (params.tags && params.tags.length > 0) {
12343
+ searchParams.set("tags", params.tags.join(","));
12344
+ }
12345
+ const { value } = await getFromApi2({
12346
+ url: `${baseUrl.origin}/v1/report?${searchParams.toString()}`,
12347
+ headers: await resolve2(this.config.headers()),
12348
+ successfulResponseHandler: createJsonResponseHandler2(
12349
+ gatewaySpendReportResponseSchema2
12350
+ ),
12351
+ failedResponseHandler: createJsonErrorResponseHandler2({
12352
+ errorSchema: z4.z.any(),
12353
+ errorToMessage: (data) => data
12354
+ }),
12355
+ fetch: this.config.fetch
12356
+ });
12357
+ return value;
12358
+ } catch (error) {
12359
+ throw await asGatewayError2(error);
12360
+ }
12361
+ }
12362
+ };
12363
+ var gatewaySpendReportResponseSchema2 = lazySchema2(
12364
+ () => zodSchema3(
12365
+ z4.z.object({
12366
+ results: z4.z.array(
12367
+ z4.z.object({
12368
+ day: z4.z.string().optional(),
12369
+ hour: z4.z.string().optional(),
12370
+ user: z4.z.string().optional(),
12371
+ model: z4.z.string().optional(),
12372
+ tag: z4.z.string().optional(),
12373
+ provider: z4.z.string().optional(),
12374
+ credential_type: z4.z.enum(["byok", "system"]).optional(),
12375
+ total_cost: z4.z.number(),
12376
+ market_cost: z4.z.number().optional(),
12377
+ input_tokens: z4.z.number().optional(),
12378
+ output_tokens: z4.z.number().optional(),
12379
+ cached_input_tokens: z4.z.number().optional(),
12380
+ cache_creation_input_tokens: z4.z.number().optional(),
12381
+ reasoning_tokens: z4.z.number().optional(),
12382
+ request_count: z4.z.number().optional()
12383
+ }).transform(
12384
+ ({
12385
+ credential_type,
12386
+ total_cost,
12387
+ market_cost,
12388
+ input_tokens,
12389
+ output_tokens,
12390
+ cached_input_tokens,
12391
+ cache_creation_input_tokens,
12392
+ reasoning_tokens,
12393
+ request_count,
12394
+ ...rest
12395
+ }) => ({
12396
+ ...rest,
12397
+ ...credential_type !== void 0 ? { credentialType: credential_type } : {},
12398
+ totalCost: total_cost,
12399
+ ...market_cost !== void 0 ? { marketCost: market_cost } : {},
12400
+ ...input_tokens !== void 0 ? { inputTokens: input_tokens } : {},
12401
+ ...output_tokens !== void 0 ? { outputTokens: output_tokens } : {},
12402
+ ...cached_input_tokens !== void 0 ? { cachedInputTokens: cached_input_tokens } : {},
12403
+ ...cache_creation_input_tokens !== void 0 ? { cacheCreationInputTokens: cache_creation_input_tokens } : {},
12404
+ ...reasoning_tokens !== void 0 ? { reasoningTokens: reasoning_tokens } : {},
12405
+ ...request_count !== void 0 ? { requestCount: request_count } : {}
12406
+ })
12407
+ )
12408
+ )
12409
+ })
12410
+ )
12411
+ );
12412
+ var GatewayGenerationInfoFetcher2 = class {
12413
+ constructor(config) {
12414
+ this.config = config;
12415
+ }
12416
+ async getGenerationInfo(params) {
12417
+ try {
12418
+ const baseUrl = new URL(this.config.baseURL);
12419
+ const { value } = await getFromApi2({
12420
+ url: `${baseUrl.origin}/v1/generation?id=${encodeURIComponent(params.id)}`,
12421
+ headers: await resolve2(this.config.headers()),
12422
+ successfulResponseHandler: createJsonResponseHandler2(
12423
+ gatewayGenerationInfoResponseSchema2
12424
+ ),
12425
+ failedResponseHandler: createJsonErrorResponseHandler2({
12426
+ errorSchema: z4.z.any(),
12427
+ errorToMessage: (data) => data
12428
+ }),
12429
+ fetch: this.config.fetch
12430
+ });
12431
+ return value;
12432
+ } catch (error) {
12433
+ throw await asGatewayError2(error);
12434
+ }
12435
+ }
12436
+ };
12437
+ var gatewayGenerationInfoResponseSchema2 = lazySchema2(
12438
+ () => zodSchema3(
12439
+ z4.z.object({
12440
+ data: z4.z.object({
12441
+ id: z4.z.string(),
12442
+ total_cost: z4.z.number(),
12443
+ upstream_inference_cost: z4.z.number(),
12444
+ usage: z4.z.number(),
12445
+ created_at: z4.z.string(),
12446
+ model: z4.z.string(),
12447
+ is_byok: z4.z.boolean(),
12448
+ provider_name: z4.z.string(),
12449
+ streamed: z4.z.boolean(),
12450
+ finish_reason: z4.z.string(),
12451
+ latency: z4.z.number(),
12452
+ generation_time: z4.z.number(),
12453
+ native_tokens_prompt: z4.z.number(),
12454
+ native_tokens_completion: z4.z.number(),
12455
+ native_tokens_reasoning: z4.z.number(),
12456
+ native_tokens_cached: z4.z.number(),
12457
+ native_tokens_cache_creation: z4.z.number(),
12458
+ billable_web_search_calls: z4.z.number()
12459
+ }).transform(
12460
+ ({
12461
+ total_cost,
12462
+ upstream_inference_cost,
12463
+ created_at,
12464
+ is_byok,
12465
+ provider_name,
12466
+ finish_reason,
12467
+ generation_time,
12468
+ native_tokens_prompt,
12469
+ native_tokens_completion,
12470
+ native_tokens_reasoning,
12471
+ native_tokens_cached,
12472
+ native_tokens_cache_creation,
12473
+ billable_web_search_calls,
12474
+ ...rest
12475
+ }) => ({
12476
+ ...rest,
12477
+ totalCost: total_cost,
12478
+ upstreamInferenceCost: upstream_inference_cost,
12479
+ createdAt: created_at,
12480
+ isByok: is_byok,
12481
+ providerName: provider_name,
12482
+ finishReason: finish_reason,
12483
+ generationTime: generation_time,
12484
+ promptTokens: native_tokens_prompt,
12485
+ completionTokens: native_tokens_completion,
12486
+ reasoningTokens: native_tokens_reasoning,
12487
+ cachedTokens: native_tokens_cached,
12488
+ cacheCreationTokens: native_tokens_cache_creation,
12489
+ billableWebSearchCalls: billable_web_search_calls
12490
+ })
12491
+ )
12492
+ }).transform(({ data }) => data)
12493
+ )
12494
+ );
12211
12495
  var GatewayLanguageModel2 = class {
12212
12496
  constructor(modelId, config) {
12213
12497
  this.modelId = modelId;
@@ -12755,6 +13039,86 @@ var gatewayVideoEventSchema = z4.z.discriminatedUnion("type", [
12755
13039
  param: z4.z.unknown().nullable()
12756
13040
  })
12757
13041
  ]);
13042
+ var GatewayRerankingModel = class {
13043
+ constructor(modelId, config) {
13044
+ this.modelId = modelId;
13045
+ this.config = config;
13046
+ this.specificationVersion = "v3";
13047
+ }
13048
+ get provider() {
13049
+ return this.config.provider;
13050
+ }
13051
+ async doRerank({
13052
+ documents,
13053
+ query,
13054
+ topN,
13055
+ headers,
13056
+ abortSignal,
13057
+ providerOptions
13058
+ }) {
13059
+ const resolvedHeaders = await resolve2(this.config.headers());
13060
+ try {
13061
+ const {
13062
+ responseHeaders,
13063
+ value: responseBody,
13064
+ rawValue
13065
+ } = await postJsonToApi2({
13066
+ url: this.getUrl(),
13067
+ headers: combineHeaders2(
13068
+ resolvedHeaders,
13069
+ headers != null ? headers : {},
13070
+ this.getModelConfigHeaders(),
13071
+ await resolve2(this.config.o11yHeaders)
13072
+ ),
13073
+ body: {
13074
+ documents,
13075
+ query,
13076
+ ...topN != null ? { topN } : {},
13077
+ ...providerOptions ? { providerOptions } : {}
13078
+ },
13079
+ successfulResponseHandler: createJsonResponseHandler2(
13080
+ gatewayRerankingResponseSchema
13081
+ ),
13082
+ failedResponseHandler: createJsonErrorResponseHandler2({
13083
+ errorSchema: z4.z.any(),
13084
+ errorToMessage: (data) => data
13085
+ }),
13086
+ ...abortSignal && { abortSignal },
13087
+ fetch: this.config.fetch
13088
+ });
13089
+ return {
13090
+ ranking: responseBody.ranking,
13091
+ providerMetadata: responseBody.providerMetadata,
13092
+ response: { headers: responseHeaders, body: rawValue },
13093
+ warnings: []
13094
+ };
13095
+ } catch (error) {
13096
+ throw await asGatewayError2(error, await parseAuthMethod2(resolvedHeaders));
13097
+ }
13098
+ }
13099
+ getUrl() {
13100
+ return `${this.config.baseURL}/reranking-model`;
13101
+ }
13102
+ getModelConfigHeaders() {
13103
+ return {
13104
+ "ai-reranking-model-specification-version": "3",
13105
+ "ai-model-id": this.modelId
13106
+ };
13107
+ }
13108
+ };
13109
+ var gatewayRerankingResponseSchema = lazySchema2(
13110
+ () => zodSchema3(
13111
+ z4.z.object({
13112
+ ranking: z4.z.array(
13113
+ z4.z.object({
13114
+ index: z4.z.number(),
13115
+ relevanceScore: z4.z.number()
13116
+ })
13117
+ ),
13118
+ providerMetadata: z4.z.record(z4.z.string(), z4.z.record(z4.z.string(), z4.z.unknown())).optional()
13119
+ })
13120
+ )
13121
+ );
12758
13122
  var parallelSearchInputSchema2 = lazySchema2(
12759
13123
  () => zodSchema3(
12760
13124
  zod.z.object({
@@ -12929,9 +13293,9 @@ var gatewayTools2 = {
12929
13293
  };
12930
13294
  async function getVercelRequestId2() {
12931
13295
  var _a932;
12932
- return (_a932 = (0, import_oidc3.getContext)().headers) == null ? void 0 : _a932["x-vercel-id"];
13296
+ return (_a932 = getContext2().headers) == null ? void 0 : _a932["x-vercel-id"];
12933
13297
  }
12934
- var VERSION5 = "3.0.66";
13298
+ var VERSION5 = "3.0.104";
12935
13299
  var AI_GATEWAY_PROTOCOL_VERSION2 = "0.0.1";
12936
13300
  function createGatewayProvider2(options = {}) {
12937
13301
  var _a932, _b93;
@@ -13031,6 +13395,30 @@ function createGatewayProvider2(options = {}) {
13031
13395
  );
13032
13396
  });
13033
13397
  };
13398
+ const getSpendReport = async (params) => {
13399
+ return new GatewaySpendReport2({
13400
+ baseURL,
13401
+ headers: getHeaders,
13402
+ fetch: options.fetch
13403
+ }).getSpendReport(params).catch(async (error) => {
13404
+ throw await asGatewayError2(
13405
+ error,
13406
+ await parseAuthMethod2(await getHeaders())
13407
+ );
13408
+ });
13409
+ };
13410
+ const getGenerationInfo = async (params) => {
13411
+ return new GatewayGenerationInfoFetcher2({
13412
+ baseURL,
13413
+ headers: getHeaders,
13414
+ fetch: options.fetch
13415
+ }).getGenerationInfo(params).catch(async (error) => {
13416
+ throw await asGatewayError2(
13417
+ error,
13418
+ await parseAuthMethod2(await getHeaders())
13419
+ );
13420
+ });
13421
+ };
13034
13422
  const provider = function(modelId) {
13035
13423
  if (new.target) {
13036
13424
  throw new Error(
@@ -13042,6 +13430,8 @@ function createGatewayProvider2(options = {}) {
13042
13430
  provider.specificationVersion = "v3";
13043
13431
  provider.getAvailableModels = getAvailableModels;
13044
13432
  provider.getCredits = getCredits;
13433
+ provider.getSpendReport = getSpendReport;
13434
+ provider.getGenerationInfo = getGenerationInfo;
13045
13435
  provider.imageModel = (modelId) => {
13046
13436
  return new GatewayImageModel2(modelId, {
13047
13437
  provider: "gateway",
@@ -13072,6 +13462,17 @@ function createGatewayProvider2(options = {}) {
13072
13462
  o11yHeaders: createO11yHeaders()
13073
13463
  });
13074
13464
  };
13465
+ const createRerankingModel = (modelId) => {
13466
+ return new GatewayRerankingModel(modelId, {
13467
+ provider: "gateway",
13468
+ baseURL,
13469
+ headers: getHeaders,
13470
+ fetch: options.fetch,
13471
+ o11yHeaders: createO11yHeaders()
13472
+ });
13473
+ };
13474
+ provider.rerankingModel = createRerankingModel;
13475
+ provider.reranking = createRerankingModel;
13075
13476
  provider.chat = provider.languageModel;
13076
13477
  provider.embedding = provider.embeddingModel;
13077
13478
  provider.image = provider.imageModel;
@@ -13091,7 +13492,7 @@ async function getGatewayAuthToken2(options) {
13091
13492
  authMethod: "api-key"
13092
13493
  };
13093
13494
  }
13094
- const oidcToken = await (0, import_oidc22.getVercelOidcToken)();
13495
+ const oidcToken = await getVercelOidcToken2();
13095
13496
  return {
13096
13497
  token: oidcToken,
13097
13498
  authMethod: "oidc"
@@ -14004,7 +14405,7 @@ function getTotalTimeoutMs(timeout) {
14004
14405
  }
14005
14406
  return timeout.totalMs;
14006
14407
  }
14007
- var VERSION33 = "6.0.116";
14408
+ var VERSION33 = "6.0.168";
14008
14409
  var dataContentSchema3 = z4.z.union([
14009
14410
  z4.z.string(),
14010
14411
  z4.z.instanceof(Uint8Array),
@@ -15709,7 +16110,7 @@ function formatTimestamp(date) {
15709
16110
  }
15710
16111
  function truncateByTokens(text4, maxTokens, hint) {
15711
16112
  if (tokenx.estimateTokenCount(text4) <= maxTokens) return { text: text4, wasTruncated: false };
15712
- const truncated = chunk5MTY2UYL_cjs.truncateStringByTokens(text4, maxTokens);
16113
+ const truncated = chunkJ2XQSPAB_cjs.truncateStringByTokens(text4, maxTokens);
15713
16114
  const suffix = hint ? ` [${hint} for more]` : "";
15714
16115
  return { text: truncated + suffix, wasTruncated: true };
15715
16116
  }
@@ -15761,11 +16162,11 @@ ${JSON.stringify(inv.args, null, 2)}`;
15761
16162
  });
15762
16163
  }
15763
16164
  if (inv.state === "result") {
15764
- const { value: resultValue } = chunk5MTY2UYL_cjs.resolveToolResultValue(
16165
+ const { value: resultValue } = chunkJ2XQSPAB_cjs.resolveToolResultValue(
15765
16166
  part,
15766
16167
  inv.result
15767
16168
  );
15768
- const resultStr = chunk5MTY2UYL_cjs.formatToolResultForObserver(resultValue, { maxTokens: HIGH_DETAIL_TOOL_RESULT_TOKENS });
16169
+ const resultStr = chunkJ2XQSPAB_cjs.formatToolResultForObserver(resultValue, { maxTokens: HIGH_DETAIL_TOOL_RESULT_TOKENS });
15769
16170
  const fullText = `[Tool Result: ${inv.toolName}]
15770
16171
  ${resultStr}`;
15771
16172
  parts.push(makePart(msg, i, "tool-result", fullText, detail, inv.toolName));
@@ -15792,7 +16193,7 @@ ${typeof rawArgs === "string" ? rawArgs : JSON.stringify(rawArgs, null, 2)}`;
15792
16193
  const toolName = part.toolName;
15793
16194
  if (toolName) {
15794
16195
  const rawResult = part.output ?? part.result;
15795
- const resultStr = chunk5MTY2UYL_cjs.formatToolResultForObserver(rawResult, { maxTokens: HIGH_DETAIL_TOOL_RESULT_TOKENS });
16196
+ const resultStr = chunkJ2XQSPAB_cjs.formatToolResultForObserver(rawResult, { maxTokens: HIGH_DETAIL_TOOL_RESULT_TOKENS });
15796
16197
  const fullText = `[Tool Result: ${toolName}]
15797
16198
  ${resultStr}`;
15798
16199
  parts.push(makePart(msg, i, "tool-result", fullText, detail, toolName));
@@ -15871,7 +16272,7 @@ function renderFormattedParts(parts, timestamps, options) {
15871
16272
  const text4 = buildRenderedText(parts, timestamps);
15872
16273
  let totalTokens = tokenx.estimateTokenCount(text4);
15873
16274
  if (totalTokens > options.maxTokens) {
15874
- const truncated = chunk5MTY2UYL_cjs.truncateStringByTokens(text4, options.maxTokens);
16275
+ const truncated = chunkJ2XQSPAB_cjs.truncateStringByTokens(text4, options.maxTokens);
15875
16276
  return { text: truncated, truncated: true, tokenOffset: totalTokens - options.maxTokens };
15876
16277
  }
15877
16278
  const truncatedIndices = parts.map((p, i) => ({ part: p, index: i })).filter(({ part }) => part.text !== part.fullText).sort((a, b) => expandPriority(a.part) - expandPriority(b.part));
@@ -15904,7 +16305,7 @@ function renderFormattedParts(parts, timestamps, options) {
15904
16305
  if (expandedTokens <= options.maxTokens) {
15905
16306
  return { text: expanded, truncated: false, tokenOffset: 0 };
15906
16307
  }
15907
- const hardTruncated = chunk5MTY2UYL_cjs.truncateStringByTokens(expanded, options.maxTokens);
16308
+ const hardTruncated = chunkJ2XQSPAB_cjs.truncateStringByTokens(expanded, options.maxTokens);
15908
16309
  return { text: hardTruncated, truncated: true, tokenOffset: expandedTokens - options.maxTokens };
15909
16310
  }
15910
16311
  async function recallPart({
@@ -15955,7 +16356,7 @@ async function recallPart({
15955
16356
 
15956
16357
  `;
15957
16358
  const fallbackText = `${fallbackNote}${firstNextPart.text}`;
15958
- const truncatedText2 = chunk5MTY2UYL_cjs.truncateStringByTokens(fallbackText, maxTokens);
16359
+ const truncatedText2 = chunkJ2XQSPAB_cjs.truncateStringByTokens(fallbackText, maxTokens);
15959
16360
  const wasTruncated2 = truncatedText2 !== fallbackText;
15960
16361
  return {
15961
16362
  text: truncatedText2,
@@ -15970,7 +16371,7 @@ async function recallPart({
15970
16371
  }
15971
16372
  throw new Error(`Part index ${partIndex} not found in message ${cursor}. Available indices: ${availableIndices}`);
15972
16373
  }
15973
- const truncatedText = chunk5MTY2UYL_cjs.truncateStringByTokens(target.text, maxTokens);
16374
+ const truncatedText = chunkJ2XQSPAB_cjs.truncateStringByTokens(target.text, maxTokens);
15974
16375
  const wasTruncated = truncatedText !== target.text;
15975
16376
  return {
15976
16377
  text: truncatedText,
@@ -17501,7 +17902,7 @@ ${workingMemory}`;
17501
17902
  if (obsSystemMessage) {
17502
17903
  systemParts.push(obsSystemMessage);
17503
17904
  }
17504
- const { OBSERVATION_CONTINUATION_HINT } = await import('./constants-HXOCZPB7.cjs');
17905
+ const { OBSERVATION_CONTINUATION_HINT } = await import('./constants-PJXB7ZIS.cjs');
17505
17906
  continuationMessage = {
17506
17907
  id: "om-continuation",
17507
17908
  role: "user",
@@ -17601,7 +18002,7 @@ ${workingMemory}`;
17601
18002
  "Observational memory requires @mastra/core support for request-response-id-rotation. Please bump @mastra/core to a newer version."
17602
18003
  );
17603
18004
  }
17604
- const { ObservationalMemory: OMClass } = await import('./observational-memory-UCFGVLVW.cjs');
18005
+ const { ObservationalMemory: OMClass } = await import('./observational-memory-ISRI7QGE.cjs');
17605
18006
  const onIndexObservations = this.hasRetrievalSearch(omConfig.retrieval) ? async (observation) => {
17606
18007
  await this.indexObservation(observation);
17607
18008
  } : void 0;
@@ -18526,7 +18927,7 @@ Notes:
18526
18927
  if (!effectiveConfig) return null;
18527
18928
  const engine = await this.omEngine;
18528
18929
  if (!engine) return null;
18529
- const { ObservationalMemoryProcessor } = await import('./observational-memory-UCFGVLVW.cjs');
18930
+ const { ObservationalMemoryProcessor } = await import('./observational-memory-ISRI7QGE.cjs');
18530
18931
  return new ObservationalMemoryProcessor(engine, this, {
18531
18932
  temporalMarkers: effectiveConfig.temporalMarkers
18532
18933
  });
@@ -18535,11 +18936,11 @@ Notes:
18535
18936
 
18536
18937
  Object.defineProperty(exports, "ModelByInputTokens", {
18537
18938
  enumerable: true,
18538
- get: function () { return chunk5MTY2UYL_cjs.ModelByInputTokens; }
18939
+ get: function () { return chunkJ2XQSPAB_cjs.ModelByInputTokens; }
18539
18940
  });
18540
18941
  Object.defineProperty(exports, "getObservationsAsOf", {
18541
18942
  enumerable: true,
18542
- get: function () { return chunk5MTY2UYL_cjs.getObservationsAsOf; }
18943
+ get: function () { return chunkJ2XQSPAB_cjs.getObservationsAsOf; }
18543
18944
  });
18544
18945
  Object.defineProperty(exports, "extractWorkingMemoryContent", {
18545
18946
  enumerable: true,