@mastra/memory 1.32.1 → 1.32.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.
@@ -23180,7 +23180,7 @@ async function summarizeConversation(opts) {
23180
23180
  }
23181
23181
  //#endregion
23182
23182
  //#region src/tools/working-memory.ts
23183
- const UPDATE_WORKING_MEMORY_TOOL_NAME = "updateWorkingMemory";
23183
+ const UPDATE_WORKING_MEMORY_TOOL_NAME$1 = "updateWorkingMemory";
23184
23184
  const SET_WORKING_MEMORY_TOOL_NAME = "setWorkingMemory";
23185
23185
  /**
23186
23186
  * Deep merges two objects, with special handling for null values (delete) and arrays (replace).
@@ -23438,7 +23438,7 @@ function createWorkingMemoryTool(config, options = {}) {
23438
23438
  const useStateSignals = config.workingMemory?.useStateSignals === true;
23439
23439
  const tool = options.vNext ? __experimental_updateWorkingMemoryToolVNext(config) : updateWorkingMemoryTool(config);
23440
23440
  return {
23441
- name: useStateSignals ? SET_WORKING_MEMORY_TOOL_NAME : UPDATE_WORKING_MEMORY_TOOL_NAME,
23441
+ name: useStateSignals ? SET_WORKING_MEMORY_TOOL_NAME : UPDATE_WORKING_MEMORY_TOOL_NAME$1,
23442
23442
  tool
23443
23443
  };
23444
23444
  }
@@ -28955,6 +28955,7 @@ function parseActivationTTL(value, fieldPath) {
28955
28955
  if (!Number.isFinite(amount) || amount < 0) throw new Error(`${fieldPath} must be a non-negative number of milliseconds or a duration string like "5m".`);
28956
28956
  return amount * (unit === "ms" || unit === "msec" || unit === "msecs" || unit === "millisecond" || unit === "milliseconds" ? 1 : unit === "s" || unit === "sec" || unit === "secs" || unit === "second" || unit === "seconds" ? 1e3 : unit === "m" || unit === "min" || unit === "mins" || unit === "minute" || unit === "minutes" ? 6e4 : 36e5);
28957
28957
  }
28958
+ let hasWarnedResourceScopeDeprecation = false;
28958
28959
  /**
28959
28960
  * ObservationalMemory - A three-agent memory system for long conversations.
28960
28961
  *
@@ -29233,6 +29234,10 @@ var ObservationalMemory = class ObservationalMemory {
29233
29234
  hooks: this.hooks
29234
29235
  });
29235
29236
  this.validateBufferConfig();
29237
+ if (this.scope === "resource" && !hasWarnedResourceScopeDeprecation) {
29238
+ hasWarnedResourceScopeDeprecation = true;
29239
+ console.warn("[Mastra] Observational memory `scope: 'resource'` is deprecated and will be removed in a future release because it works much worse than thread scope for prompt caching and agent understanding. Remove `scope` to use the default thread scope, and enable `retrieval` for cross-thread recall. See https://mastra.ai/docs/memory/observational-memory#resource-scope-deprecated");
29240
+ }
29236
29241
  omDebug(`[OM:init] new ObservationalMemory instance created — scope=${this.scope}, messageTokens=${JSON.stringify(this.observationConfig.messageTokens)}, obsAsyncEnabled=${this.buffering.isAsyncObservationEnabled()}, bufferTokens=${this.observationConfig.bufferTokens}, bufferActivation=${this.observationConfig.bufferActivation}, blockAfter=${this.observationConfig.blockAfter}, reflectionTokens=${this.reflectionConfig.observationTokens}, refAsyncEnabled=${this.buffering.isAsyncReflectionEnabled()}, refAsyncActivation=${this.reflectionConfig.bufferActivation}, refBlockAfter=${this.reflectionConfig.blockAfter}`);
29237
29242
  }
29238
29243
  __registerMastra(mastra) {
@@ -31825,6 +31830,40 @@ function extractWorkingMemoryContent(text) {
31825
31830
  if (end === -1) return null;
31826
31831
  return text.substring(contentStart, end);
31827
31832
  }
31833
+ const UPDATE_WORKING_MEMORY_TOOL_NAME = "updateWorkingMemory";
31834
+ /**
31835
+ * Removes `updateWorkingMemory` tool invocations from stored message parts, one step
31836
+ * at a time. A step starts at a `step-start` part, or where a tool part is followed by
31837
+ * a non-tool part (the same boundary prompt conversion uses when markers are missing).
31838
+ * A step whose tool calls were all working-memory calls loses its tool-call/tool-result
31839
+ * boundary once they are removed. If only reasoning is left, the whole step is dropped:
31840
+ * replaying that signed reasoning merges it into the next step's assistant message,
31841
+ * which providers such as Anthropic reject (see #22798).
31842
+ */
31843
+ function removeWorkingMemoryToolInvocationParts(parts) {
31844
+ const isWorkingMemoryCall = (part) => part?.type === "tool-invocation" && part.toolInvocation?.toolName === UPDATE_WORKING_MEMORY_TOOL_NAME;
31845
+ if (!parts.some(isWorkingMemoryCall)) return parts;
31846
+ const steps = [];
31847
+ parts.forEach((part, i) => {
31848
+ const previous = parts[i - 1];
31849
+ if (part?.type === "step-start" || previous?.type === "tool-invocation" && part?.type !== "tool-invocation" || steps.length === 0) steps.push([]);
31850
+ steps[steps.length - 1].push(part);
31851
+ });
31852
+ return steps.flatMap((step) => {
31853
+ if (!step.some(isWorkingMemoryCall)) return step;
31854
+ const remaining = step.filter((part) => !isWorkingMemoryCall(part));
31855
+ return remaining.every((part) => part?.type === "step-start" || part?.type === "reasoning" || part?.type === "text" && !removeWorkingMemoryTags(part.text ?? "").trim()) ? [] : remaining;
31856
+ });
31857
+ }
31858
+ /**
31859
+ * Removes `updateWorkingMemory` entries from the legacy `toolInvocations` array so
31860
+ * prompt conversion cannot re-add a stripped working-memory call.
31861
+ */
31862
+ function removeWorkingMemoryToolInvocations(toolInvocations) {
31863
+ if (!toolInvocations?.some((invocation) => invocation.toolName === UPDATE_WORKING_MEMORY_TOOL_NAME)) return toolInvocations;
31864
+ const remaining = toolInvocations.filter((invocation) => invocation.toolName !== UPDATE_WORKING_MEMORY_TOOL_NAME);
31865
+ return remaining.length > 0 ? remaining : void 0;
31866
+ }
31828
31867
  function isRecallSignalType(type) {
31829
31868
  return type === "user" || type === "state" || type === "reactive" || type === "notification" || type === "user-message" || type === "system-reminder";
31830
31869
  }
@@ -32684,10 +32723,8 @@ ${workingMemory}`;
32684
32723
  if (message.content && typeof message.content === "object" && !Array.isArray(message.content)) newMessage.content = { ...message.content };
32685
32724
  if (typeof newMessage.content?.content === "string" && newMessage.content.content.length > 0) newMessage.content.content = removeWorkingMemoryTags(newMessage.content.content).trim();
32686
32725
  if (Array.isArray(newMessage.content?.parts)) {
32687
- newMessage.content.parts = newMessage.content.parts.filter((part) => {
32688
- if (part?.type === "tool-invocation") return part.toolInvocation?.toolName !== "updateWorkingMemory";
32689
- return true;
32690
- }).map((part) => {
32726
+ if (Array.isArray(newMessage.content.toolInvocations)) newMessage.content.toolInvocations = removeWorkingMemoryToolInvocations(newMessage.content.toolInvocations);
32727
+ newMessage.content.parts = removeWorkingMemoryToolInvocationParts(newMessage.content.parts).map((part) => {
32691
32728
  if (part?.type === "text") {
32692
32729
  const text = typeof part.text === "string" ? part.text : "";
32693
32730
  return {
@@ -33040,7 +33077,7 @@ ${hasEmptyWorkingMemoryTemplateObject ? "When working with json data, the object
33040
33077
  ${hasEmptyWorkingMemoryTemplateObject ? JSON.stringify(emptyWorkingMemoryTemplateObject) : ""}
33041
33078
 
33042
33079
  <working_memory_data>
33043
- ${data}
33080
+ ${data || "No working memory data available."}
33044
33081
  </working_memory_data>
33045
33082
 
33046
33083
  Notes:
@@ -33069,7 +33106,7 @@ ${template.content}
33069
33106
  </working_memory_template>
33070
33107
 
33071
33108
  <working_memory_data>
33072
- ${data}
33109
+ ${data || "No working memory data available."}
33073
33110
  </working_memory_data>
33074
33111
 
33075
33112
  Notes:
@@ -34357,4 +34394,4 @@ Object.defineProperty(exports, "wrapInObservationGroup", {
34357
34394
  }
34358
34395
  });
34359
34396
 
34360
- //# sourceMappingURL=src-DS-duN3y.cjs.map
34397
+ //# sourceMappingURL=src-CBxKXo2w.cjs.map