@mastra/memory 1.20.1-alpha.0 → 1.20.1-alpha.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 (28) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/_types/@internal_ai-sdk-v4/dist/index.d.ts +2 -160
  3. package/dist/{chunk-LXU26UVM.js → chunk-KMJQDCCZ.js} +128 -12
  4. package/dist/{chunk-LXU26UVM.js.map → chunk-KMJQDCCZ.js.map} +1 -1
  5. package/dist/{chunk-R2H7SJS2.cjs → chunk-P4BYW7GY.cjs} +127 -11
  6. package/dist/chunk-P4BYW7GY.cjs.map +1 -0
  7. package/dist/docs/SKILL.md +1 -1
  8. package/dist/docs/assets/SOURCE_MAP.json +28 -28
  9. package/dist/docs/references/docs-agents-agent-approval.md +14 -0
  10. package/dist/docs/references/docs-memory-semantic-recall.md +1 -1
  11. package/dist/docs/references/reference-vectors-pg.md +2 -0
  12. package/dist/index.cjs +198 -203
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +189 -194
  16. package/dist/index.js.map +1 -1
  17. package/dist/{observational-memory-L32TPJ5J.cjs → observational-memory-CDLGZL67.cjs} +26 -26
  18. package/dist/{observational-memory-L32TPJ5J.cjs.map → observational-memory-CDLGZL67.cjs.map} +1 -1
  19. package/dist/{observational-memory-GE5MP6W7.js → observational-memory-TJFOX3YN.js} +3 -3
  20. package/dist/{observational-memory-GE5MP6W7.js.map → observational-memory-TJFOX3YN.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/temporal-markers.d.ts.map +1 -1
  24. package/dist/processors/observational-memory/token-counter.d.ts +1 -0
  25. package/dist/processors/observational-memory/token-counter.d.ts.map +1 -1
  26. package/dist/tools/working-memory.d.ts.map +1 -1
  27. package/package.json +5 -5
  28. package/dist/chunk-R2H7SJS2.cjs.map +0 -1
@@ -5762,7 +5762,7 @@ function ensureMessageMastraMetadata(message) {
5762
5762
  return typedMessage.metadata.mastra;
5763
5763
  }
5764
5764
  function buildEstimateKey(kind, text) {
5765
- const payloadHash = crypto$1.createHash("sha1").update(text).digest("hex");
5765
+ const payloadHash = crypto$1.createHash("sha256").update(text).digest("hex");
5766
5766
  return `${kind}:${payloadHash}`;
5767
5767
  }
5768
5768
  function resolveEstimatorId() {
@@ -6305,7 +6305,7 @@ function getAttachmentFingerprint(asset) {
6305
6305
  }
6306
6306
  const base64 = encodeAttachmentBase64(asset);
6307
6307
  if (base64) {
6308
- return { contentHash: crypto$1.createHash("sha1").update(base64).digest("hex") };
6308
+ return { contentHash: crypto$1.createHash("sha256").update(base64).digest("hex") };
6309
6309
  }
6310
6310
  return {};
6311
6311
  }
@@ -6584,6 +6584,116 @@ var TokenCounter = class _TokenCounter {
6584
6584
  resolveToolResultForTokenCounting(part, invocationResult) {
6585
6585
  return resolveToolResultValue(part, invocationResult);
6586
6586
  }
6587
+ countMultimodalToolResultContent(part, toolResult) {
6588
+ if (!toolResult || typeof toolResult !== "object") {
6589
+ return void 0;
6590
+ }
6591
+ const output = toolResult;
6592
+ const content = output.type === "content" && Array.isArray(output.value) ? output.value : output.content;
6593
+ if (!Array.isArray(content)) {
6594
+ return void 0;
6595
+ }
6596
+ let hasAttachment = false;
6597
+ let tokens = 0;
6598
+ const cacheParts = [];
6599
+ const countJsonContentPart = (contentPart) => {
6600
+ const formatted = formatToolResultForObserver(contentPart);
6601
+ tokens += this.countString(formatted);
6602
+ cacheParts.push({ type: "json", valueHash: crypto$1.createHash("sha256").update(formatted).digest("hex") });
6603
+ };
6604
+ for (const item of content) {
6605
+ if (!item || typeof item !== "object") {
6606
+ continue;
6607
+ }
6608
+ const contentPart = item;
6609
+ const partType = contentPart.type;
6610
+ if (partType === "text") {
6611
+ const text = typeof contentPart.text === "string" ? contentPart.text : String(contentPart.value ?? "");
6612
+ tokens += this.countString(text);
6613
+ cacheParts.push({ type: "text", textHash: crypto$1.createHash("sha256").update(text).digest("hex") });
6614
+ continue;
6615
+ }
6616
+ if (partType === "image" || partType === "image-data" || partType === "media" && String(contentPart.mediaType ?? "").startsWith("image/")) {
6617
+ if (typeof contentPart.data !== "string") {
6618
+ countJsonContentPart(contentPart);
6619
+ continue;
6620
+ }
6621
+ hasAttachment = true;
6622
+ const imagePart = {
6623
+ type: "image",
6624
+ image: contentPart.data,
6625
+ mimeType: contentPart.mediaType ?? contentPart.mimeType,
6626
+ providerOptions: contentPart.providerOptions,
6627
+ providerMetadata: contentPart.providerMetadata
6628
+ };
6629
+ const clientEstimate = getClientPartTokenEstimate(imagePart);
6630
+ if (clientEstimate) {
6631
+ tokens += clientEstimate.tokens;
6632
+ cacheParts.push({
6633
+ type: "image-data-client-estimate",
6634
+ key: clientEstimate.key,
6635
+ tokens: clientEstimate.tokens
6636
+ });
6637
+ continue;
6638
+ }
6639
+ const estimate = this.estimateImageTokens(imagePart);
6640
+ tokens += estimate.tokens;
6641
+ cacheParts.push({ type: "image-data", estimate: JSON.parse(estimate.cachePayload) });
6642
+ continue;
6643
+ }
6644
+ if (partType === "audio" || partType === "file-data" || partType === "media") {
6645
+ if (typeof contentPart.data !== "string") {
6646
+ countJsonContentPart(contentPart);
6647
+ continue;
6648
+ }
6649
+ hasAttachment = true;
6650
+ const filePart = {
6651
+ type: "file",
6652
+ data: contentPart.data,
6653
+ mimeType: contentPart.mediaType ?? contentPart.mimeType,
6654
+ filename: contentPart.filename,
6655
+ providerOptions: contentPart.providerOptions,
6656
+ providerMetadata: contentPart.providerMetadata
6657
+ };
6658
+ const clientEstimate = getClientPartTokenEstimate(filePart);
6659
+ if (clientEstimate) {
6660
+ tokens += clientEstimate.tokens;
6661
+ cacheParts.push({
6662
+ type: "file-data-client-estimate",
6663
+ key: clientEstimate.key,
6664
+ tokens: clientEstimate.tokens
6665
+ });
6666
+ continue;
6667
+ }
6668
+ if (isImageLikeFilePart(filePart)) {
6669
+ const estimate = this.estimateImageLikeFileTokens(filePart);
6670
+ tokens += estimate.tokens;
6671
+ cacheParts.push({ type: "image-like-file-data", estimate: JSON.parse(estimate.cachePayload) });
6672
+ continue;
6673
+ }
6674
+ const byteEstimate = estimateNonImageFileTokens(this.getModelContext(), filePart);
6675
+ if (byteEstimate) {
6676
+ tokens += byteEstimate.tokens;
6677
+ cacheParts.push({ type: "file-data", estimate: JSON.parse(byteEstimate.cachePayload) });
6678
+ continue;
6679
+ }
6680
+ const descriptor = serializeNonImageFilePartForTokenCounting(filePart);
6681
+ tokens += this.countString(descriptor);
6682
+ cacheParts.push({ type: "file-data-descriptor", descriptor });
6683
+ continue;
6684
+ }
6685
+ countJsonContentPart(contentPart);
6686
+ }
6687
+ if (!hasAttachment) {
6688
+ return void 0;
6689
+ }
6690
+ return this.readOrPersistFixedPartEstimate(
6691
+ part,
6692
+ "tool-result-multimodal-content",
6693
+ JSON.stringify({ type: "content", value: cacheParts }),
6694
+ tokens
6695
+ );
6696
+ }
6587
6697
  estimateImageAssetTokens(part, asset, kind) {
6588
6698
  const modelContext = this.getModelContext();
6589
6699
  const provider = resolveProviderId(modelContext);
@@ -6842,12 +6952,17 @@ var TokenCounter = class _TokenCounter {
6842
6952
  invocation.result
6843
6953
  );
6844
6954
  if (resultForCounting !== void 0) {
6845
- const formattedResult = formatToolResultForObserver(resultForCounting);
6846
- tokens += this.readOrPersistPartEstimate(
6847
- part,
6848
- usingStoredModelOutput ? "tool-result-model-output-json" : "tool-result-json",
6849
- formattedResult
6850
- );
6955
+ const contentTokens = this.countMultimodalToolResultContent(part, resultForCounting);
6956
+ if (contentTokens !== void 0) {
6957
+ tokens += contentTokens;
6958
+ } else {
6959
+ const formattedResult = formatToolResultForObserver(resultForCounting);
6960
+ tokens += this.readOrPersistPartEstimate(
6961
+ part,
6962
+ usingStoredModelOutput ? "tool-result-model-output-json" : "tool-result-json",
6963
+ formattedResult
6964
+ );
6965
+ }
6851
6966
  if (typeof resultForCounting !== "string") {
6852
6967
  overheadDelta -= 12;
6853
6968
  }
@@ -9583,7 +9698,8 @@ async function insertTemporalGapMarkers({
9583
9698
  }
9584
9699
  await sendSignal?.({
9585
9700
  id: `__temporal_gap_${crypto.randomUUID()}`,
9586
- type: "system-reminder",
9701
+ type: "reactive",
9702
+ tagName: "system-reminder",
9587
9703
  contents: getTemporalGapReminderText(gapText, timestamp),
9588
9704
  createdAt: new Date(timestamp - 1),
9589
9705
  acceptedAt: new Date(timestamp),
@@ -9896,5 +10012,5 @@ exports.stripEphemeralAnchorIds = stripEphemeralAnchorIds;
9896
10012
  exports.stripObservationGroups = stripObservationGroups;
9897
10013
  exports.truncateStringByTokens = truncateStringByTokens;
9898
10014
  exports.wrapInObservationGroup = wrapInObservationGroup;
9899
- //# sourceMappingURL=chunk-R2H7SJS2.cjs.map
9900
- //# sourceMappingURL=chunk-R2H7SJS2.cjs.map
10015
+ //# sourceMappingURL=chunk-P4BYW7GY.cjs.map
10016
+ //# sourceMappingURL=chunk-P4BYW7GY.cjs.map