@mastra/memory 1.41.1 → 1.41.2-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.
@@ -26782,6 +26782,7 @@ function buildObserverHistoryMessage(messages, options) {
26782
26782
  }
26783
26783
  /** Truncate a string to maxLen characters, appending a note if truncated. */
26784
26784
  function maybeTruncate(str, maxLen) {
26785
+ if (typeof str !== "string") return "";
26785
26786
  if (!maxLen || str.length <= maxLen) return str;
26786
26787
  const truncated = safeSlice(str, maxLen);
26787
26788
  return `${truncated}\n... [truncated ${str.length - truncated.length} characters]`;
@@ -28078,6 +28079,19 @@ function buildEstimateKey(kind, text) {
28078
28079
  function resolveEstimatorId() {
28079
28080
  return "tokenx";
28080
28081
  }
28082
+ const ATTACHMENT_CONTENT_PART_TYPES = /* @__PURE__ */ new Set([
28083
+ "image",
28084
+ "image-data",
28085
+ "media",
28086
+ "audio",
28087
+ "file-data"
28088
+ ]);
28089
+ /** Mirrors the parts countMultimodalToolResultContent counts as attachments. */
28090
+ function isAttachmentContentPart(item) {
28091
+ if (!item || typeof item !== "object") return false;
28092
+ const contentPart = item;
28093
+ return ATTACHMENT_CONTENT_PART_TYPES.has(contentPart.type) && typeof contentPart.data === "string";
28094
+ }
28081
28095
  function isTokenEstimateEntry(value) {
28082
28096
  if (!value || typeof value !== "object") return false;
28083
28097
  const entry = value;
@@ -28870,12 +28884,12 @@ var TokenCounter = class TokenCounter {
28870
28884
  }
28871
28885
  countMultimodalToolResultContent(part, toolResult) {
28872
28886
  if (!toolResult || typeof toolResult !== "object") return;
28887
+ const output = toolResult;
28888
+ const content = output.type === "content" && Array.isArray(output.value) ? output.value : output.content;
28889
+ if (!Array.isArray(content) || !content.some(isAttachmentContentPart)) return;
28873
28890
  const resultKey = buildEstimateKey("tool-result-multimodal-content-source", JSON.stringify(toolResult));
28874
28891
  const cached = this.multimodalToolResultCounts.get(part);
28875
28892
  if (cached?.resultKey === resultKey) return cached.tokens;
28876
- const output = toolResult;
28877
- const content = output.type === "content" && Array.isArray(output.value) ? output.value : output.content;
28878
- if (!Array.isArray(content)) return;
28879
28893
  let hasAttachment = false;
28880
28894
  let tokens = 0;
28881
28895
  const cacheParts = [];
@@ -29724,7 +29738,10 @@ const __experimental_updateWorkingMemoryToolVNext = (config) => {
29724
29738
  }
29725
29739
  const workingMemory = workingMemoryInput.newMemory || "";
29726
29740
  if (!workingMemoryInput.updateReason) workingMemoryInput.updateReason = `append-new-memory`;
29727
- if (workingMemoryInput.searchString && config.workingMemory?.scope === `resource` && workingMemoryInput.updateReason === `replace-irrelevant-memory`) workingMemoryInput.searchString = void 0;
29741
+ if (workingMemoryInput.searchString && scope === "resource" && workingMemoryInput.updateReason === `replace-irrelevant-memory`) return {
29742
+ success: false,
29743
+ reason: `working memory is shared across all conversations for this resource, so it can't be replaced just because it isn't relevant to this conversation. Use clarify-existing-memory to correct it, or append-new-memory to add to it.`
29744
+ };
29728
29745
  if (workingMemoryInput.updateReason === `append-new-memory` && workingMemoryInput.searchString) workingMemoryInput.searchString = void 0;
29729
29746
  if (workingMemoryInput.updateReason !== `append-new-memory` && !workingMemoryInput.searchString) return {
29730
29747
  success: false,
@@ -42498,4 +42515,4 @@ Notes:
42498
42515
  };
42499
42516
  export { summarizeConversation as A, injectAnchorIds as B, wrapInObservationGroup as C, WorkingMemoryExtractor as D, Subconscious as E, extractCurrentTask as F, OBSERVATION_CONTEXT_INSTRUCTIONS as G, stripEphemeralAnchorIds as H, formatMessagesForObserver as I, OBSERVATION_CONTINUATION_HINT as J, OBSERVATION_CONTEXT_PROMPT as K, hasCurrentTaskSection as L, OBSERVER_SYSTEM_PROMPT as M, buildObserverPrompt as N, deepMergeWorkingMemory as O, buildObserverSystemPrompt as P, optimizeObservationsForContext as R, stripObservationGroups as S, StaleKnowledgeSemanticIndexError as T, Extractor as U, parseAnchorId as V, OBSERVATIONAL_MEMORY_DEFAULTS as W, getObservationContextPrompt as Y, combineObservationGroupRanges as _, extractWorkingMemoryContent as a, reconcileObservationGroupsFromReflection as b, getObservationsAsOf as c, AUTO_MODEL_BY_PROVIDER as d, resolveAutoModelId as f, ModelByInputTokens as g, WorkingMemoryStateProcessor as h, WorkingMemory as i, TokenCounter as j, SUMMARIZE_THREAD_DEFAULTS as k, ObservationalMemoryProcessor as l, WORKING_MEMORY_STATE_PROCESSOR_ID as m, MessageHistory$1 as n, extractWorkingMemoryTags as o, WORKING_MEMORY_STATE_ID as p, OBSERVATION_CONTEXT_PROMPT_THREAD as q, SemanticRecall as r, removeWorkingMemoryTags as s, Memory as t, ObservationalMemory as u, deriveObservationGroupProvenance as v, KnowledgeSemanticIndexCoordinator as w, renderObservationGroupsForReflection as x, parseObservationGroups as y, parseObserverOutput as z };
42500
42517
 
42501
- //# sourceMappingURL=src-MUc-jGgr.js.map
42518
+ //# sourceMappingURL=src-DGBUSKXy.js.map