@mastra/memory 1.18.0 → 1.18.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.
@@ -1020,6 +1020,8 @@ var ObservationStrategy = class _ObservationStrategy {
1020
1020
  this.scope = deps.scope;
1021
1021
  this.retrieval = deps.retrieval;
1022
1022
  }
1023
+ deps;
1024
+ opts;
1023
1025
  storage;
1024
1026
  messageHistory;
1025
1027
  tokenCounter;
@@ -2048,6 +2050,8 @@ var ObservationStep = class {
2048
2050
  this.turn = turn;
2049
2051
  this.stepNumber = stepNumber;
2050
2052
  }
2053
+ turn;
2054
+ stepNumber;
2051
2055
  _prepared = false;
2052
2056
  _context;
2053
2057
  /** Whether this step has been prepared. */
@@ -5536,6 +5540,7 @@ var IMAGE_FILE_EXTENSIONS = /* @__PURE__ */ new Set([
5536
5540
  "avif"
5537
5541
  ]);
5538
5542
  var TOKEN_ESTIMATE_CACHE_VERSION = 6;
5543
+ var CLIENT_TOKEN_ESTIMATE_SOURCE = "client";
5539
5544
  var DEFAULT_IMAGE_ESTIMATOR = {
5540
5545
  baseTokens: 85,
5541
5546
  tileTokens: 170,
@@ -5643,6 +5648,16 @@ function setPartCacheEntry(part, key, entry) {
5643
5648
  const mastraMetadata = ensurePartMastraMetadata(part);
5644
5649
  mastraMetadata.tokenEstimate = mergeCacheEntry(mastraMetadata.tokenEstimate, key, entry);
5645
5650
  }
5651
+ function getClientPartTokenEstimate(part) {
5652
+ const cache = getPartMastraMetadata(part)?.tokenEstimate;
5653
+ if (!cache || typeof cache !== "object") return void 0;
5654
+ const matches = (entry) => isTokenEstimateEntry(entry) && entry.source === CLIENT_TOKEN_ESTIMATE_SOURCE && Number.isFinite(entry.tokens) && entry.tokens >= 0;
5655
+ if (matches(cache)) return cache;
5656
+ for (const value of Object.values(cache)) {
5657
+ if (matches(value)) return value;
5658
+ }
5659
+ return void 0;
5660
+ }
5646
5661
  function getMessageCacheEntry(message, key) {
5647
5662
  const contentLevelEntry = getCacheEntry(getContentMastraMetadata(message.content)?.tokenEstimate, key);
5648
5663
  if (contentLevelEntry) return contentLevelEntry;
@@ -6447,6 +6462,12 @@ var TokenCounter = class _TokenCounter {
6447
6462
  return this.estimateImageAssetTokens(part, part.data, "file");
6448
6463
  }
6449
6464
  countAttachmentPartSync(part) {
6465
+ if (part.type === "image" || part.type === "file") {
6466
+ const clientEstimate = getClientPartTokenEstimate(part);
6467
+ if (clientEstimate) {
6468
+ return clientEstimate.tokens;
6469
+ }
6470
+ }
6450
6471
  if (part.type === "image") {
6451
6472
  const estimate = this.estimateImageTokens(part);
6452
6473
  return this.readOrPersistFixedPartEstimate(part, "image", estimate.cachePayload, estimate.tokens);
@@ -6511,6 +6532,12 @@ var TokenCounter = class _TokenCounter {
6511
6532
  return void 0;
6512
6533
  }
6513
6534
  async countAttachmentPartAsync(part) {
6535
+ if (part.type === "image" || part.type === "file") {
6536
+ const clientEstimate = getClientPartTokenEstimate(part);
6537
+ if (clientEstimate) {
6538
+ return clientEstimate.tokens;
6539
+ }
6540
+ }
6514
6541
  const isImageAttachment = part.type === "image" || part.type === "file" && isImageLikeFilePart(part);
6515
6542
  const remotePayload = this.buildRemoteAttachmentCachePayload(part);
6516
6543
  if (remotePayload) {
@@ -9665,5 +9692,5 @@ exports.stripEphemeralAnchorIds = stripEphemeralAnchorIds;
9665
9692
  exports.stripObservationGroups = stripObservationGroups;
9666
9693
  exports.truncateStringByTokens = truncateStringByTokens;
9667
9694
  exports.wrapInObservationGroup = wrapInObservationGroup;
9668
- //# sourceMappingURL=chunk-NRYX4QWV.cjs.map
9669
- //# sourceMappingURL=chunk-NRYX4QWV.cjs.map
9695
+ //# sourceMappingURL=chunk-LCRYFBV3.cjs.map
9696
+ //# sourceMappingURL=chunk-LCRYFBV3.cjs.map