@mastra/memory 1.18.1 → 1.18.2-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.
@@ -5532,7 +5532,7 @@ var IMAGE_FILE_EXTENSIONS = /* @__PURE__ */ new Set([
5532
5532
  "heif",
5533
5533
  "avif"
5534
5534
  ]);
5535
- var TOKEN_ESTIMATE_CACHE_VERSION = 6;
5535
+ var TOKEN_ESTIMATE_CACHE_VERSION = 7;
5536
5536
  var CLIENT_TOKEN_ESTIMATE_SOURCE = "client";
5537
5537
  var DEFAULT_IMAGE_ESTIMATOR = {
5538
5538
  baseTokens: 85,
@@ -6043,6 +6043,42 @@ function estimateAnthropicImageTokens(dimensions, sourceStats) {
6043
6043
  }
6044
6044
  return 1600;
6045
6045
  }
6046
+ function estimateFileTokensFromBytes(provider, mimeType, sizeBytes) {
6047
+ const normalizedMime = (mimeType ?? "").toLowerCase().split(";", 1)[0].trim();
6048
+ const isPdf = normalizedMime === "application/pdf";
6049
+ const isTextish = normalizedMime.startsWith("text/") || ["application/json", "application/xml", "application/x-yaml", "application/yaml"].includes(normalizedMime);
6050
+ if (isPdf) {
6051
+ if (provider === "google") return Math.max(258, Math.ceil(sizeBytes / 20));
6052
+ if (provider === "anthropic") return Math.max(1500, Math.ceil(sizeBytes / 3));
6053
+ return Math.max(500, Math.ceil(sizeBytes / 4));
6054
+ }
6055
+ if (isTextish) return Math.max(1, Math.ceil(sizeBytes / 4));
6056
+ return Math.max(1, Math.ceil(sizeBytes / 4));
6057
+ }
6058
+ function estimateNonImageFileTokens(modelContext, part) {
6059
+ const sourceStats = resolveImageSourceStats(getObjectValue(part, "data"));
6060
+ if (sourceStats.sizeBytes === void 0) {
6061
+ return void 0;
6062
+ }
6063
+ const provider = resolveProviderId(modelContext);
6064
+ const modelId = modelContext?.modelId ?? null;
6065
+ const mimeType = getAttachmentMimeType(part, "application/octet-stream");
6066
+ const filename = getAttachmentFilename(part) ?? null;
6067
+ const tokens = estimateFileTokensFromBytes(provider, mimeType, sourceStats.sizeBytes);
6068
+ return {
6069
+ tokens,
6070
+ cachePayload: JSON.stringify({
6071
+ kind: "non-image-file",
6072
+ provider: provider ?? "fallback",
6073
+ modelId,
6074
+ estimator: "bytes",
6075
+ source: sourceStats.source,
6076
+ sizeBytes: sourceStats.sizeBytes,
6077
+ mimeType,
6078
+ filename
6079
+ })
6080
+ };
6081
+ }
6046
6082
  function estimateGoogleImageTokens(modelContext, part, dimensions) {
6047
6083
  if (isGoogleGemini3Model(modelContext)) {
6048
6084
  const mediaResolution = resolveGoogleMediaResolution(part);
@@ -6470,6 +6506,15 @@ var TokenCounter = class _TokenCounter {
6470
6506
  return this.readOrPersistFixedPartEstimate(part, "image-like-file", estimate.cachePayload, estimate.tokens);
6471
6507
  }
6472
6508
  if (part.type === "file") {
6509
+ const byteEstimate = estimateNonImageFileTokens(this.getModelContext(), part);
6510
+ if (byteEstimate) {
6511
+ return this.readOrPersistFixedPartEstimate(
6512
+ part,
6513
+ "non-image-file",
6514
+ byteEstimate.cachePayload,
6515
+ byteEstimate.tokens
6516
+ );
6517
+ }
6473
6518
  return this.readOrPersistPartEstimate(part, "file-descriptor", serializeNonImageFilePartForTokenCounting(part));
6474
6519
  }
6475
6520
  return void 0;
@@ -9660,5 +9705,5 @@ function getObservationsAsOf(activeObservations, asOf) {
9660
9705
  }
9661
9706
 
9662
9707
  export { ModelByInputTokens, OBSERVER_SYSTEM_PROMPT, ObservationalMemory, ObservationalMemoryProcessor, TokenCounter, buildObserverPrompt, buildObserverSystemPrompt, combineObservationGroupRanges, deriveObservationGroupProvenance, extractCurrentTask, formatMessagesForObserver, formatToolResultForObserver, getObservationsAsOf, hasCurrentTaskSection, injectAnchorIds, optimizeObservationsForContext, parseAnchorId, parseObservationGroups, parseObserverOutput, reconcileObservationGroupsFromReflection, renderObservationGroupsForReflection, resolveToolResultValue, stripEphemeralAnchorIds, stripObservationGroups, truncateStringByTokens, wrapInObservationGroup };
9663
- //# sourceMappingURL=chunk-KGYJHNI6.js.map
9664
- //# sourceMappingURL=chunk-KGYJHNI6.js.map
9708
+ //# sourceMappingURL=chunk-LCALB7W6.js.map
9709
+ //# sourceMappingURL=chunk-LCALB7W6.js.map