@mastra/memory 1.26.1-alpha.2 → 1.26.1-alpha.3

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @mastra/memory
2
2
 
3
+ ## 1.26.1-alpha.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Fixed a crash in Observational Memory token counting for tool calls that wait for approval. Threads that hold a tool invocation in the `approval-requested` or `approval-responded` state no longer throw `Unhandled tool-invocation state`, so memory extraction keeps running on approval-gated conversations. ([#20985](https://github.com/mastra-ai/mastra/pull/20985))
8
+
9
+ The counter also no longer stops on a tool-invocation state it does not know. A message that a different `@mastra/core` version wrote now gets an estimate instead of an error.
10
+
11
+ - Fix schema-based working memory losing stored data on partial updates. When a model updated one section of working memory, unrelated sections could be wiped out. Tools can now set `strict: false` to opt out of strict structured-output schema rewriting, which previously forced every field to be required and left models no way to signal "leave this field alone". ([#20992](https://github.com/mastra-ai/mastra/pull/20992))
12
+
13
+ - Updated dependencies [[`6445eba`](https://github.com/mastra-ai/mastra/commit/6445eba6020abac681aba1cc9289f446cb400cbe), [`df31eb0`](https://github.com/mastra-ai/mastra/commit/df31eb0c7087d782a0d9346e467f9a4af4b0eef6), [`fcd0667`](https://github.com/mastra-ai/mastra/commit/fcd0667a4e378be35c9a1b1eb19cce78fbfd7282), [`bab06b1`](https://github.com/mastra-ai/mastra/commit/bab06b18923873a584bdfc71a6b4ec7fb4727fb7)]:
14
+ - @mastra/core@1.58.0-alpha.5
15
+
3
16
  ## 1.26.1-alpha.2
4
17
 
5
18
  ### Patch Changes
@@ -3,7 +3,7 @@ name: mastra-memory
3
3
  description: Documentation for @mastra/memory. Use when working with @mastra/memory APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/memory"
6
- version: "1.26.1-alpha.2"
6
+ version: "1.26.1-alpha.3"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.26.1-alpha.2",
2
+ "version": "1.26.1-alpha.3",
3
3
  "package": "@mastra/memory",
4
4
  "exports": {},
5
5
  "modules": {
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_src = require("./src-DY9-_lul.cjs");
2
+ const require_src = require("./src-CTQrRb5X.cjs");
3
3
  let _mastra_core_processors = require("@mastra/core/processors");
4
4
  exports.Extractor = require_src.Extractor;
5
5
  exports.Memory = require_src.Memory;
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import { C as WorkingMemoryExtractor, R as Extractor, S as deepMergeWorkingMemory, T as summarizeConversation, a as extractWorkingMemoryContent, c as WORKING_MEMORY_STATE_ID, d as getObservationsAsOf, i as WorkingMemory, l as WORKING_MEMORY_STATE_PROCESSOR_ID, n as MessageHistory, o as extractWorkingMemoryTags, r as SemanticRecall, s as removeWorkingMemoryTags, t as Memory, u as WorkingMemoryStateProcessor, w as SUMMARIZE_THREAD_DEFAULTS, x as ModelByInputTokens } from "./src-CdqJP57F.js";
1
+ import { C as WorkingMemoryExtractor, R as Extractor, S as deepMergeWorkingMemory, T as summarizeConversation, a as extractWorkingMemoryContent, c as WORKING_MEMORY_STATE_ID, d as getObservationsAsOf, i as WorkingMemory, l as WORKING_MEMORY_STATE_PROCESSOR_ID, n as MessageHistory, o as extractWorkingMemoryTags, r as SemanticRecall, s as removeWorkingMemoryTags, t as Memory, u as WorkingMemoryStateProcessor, w as SUMMARIZE_THREAD_DEFAULTS, x as ModelByInputTokens } from "./src-MScpLVRh.js";
2
2
  export { Extractor, Memory, MessageHistory, ModelByInputTokens, SUMMARIZE_THREAD_DEFAULTS, SemanticRecall, WORKING_MEMORY_STATE_ID, WORKING_MEMORY_STATE_PROCESSOR_ID, WorkingMemory, WorkingMemoryExtractor, WorkingMemoryStateProcessor, deepMergeWorkingMemory, extractWorkingMemoryContent, extractWorkingMemoryTags, getObservationsAsOf, removeWorkingMemoryTags, summarizeConversation };
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_src = require("../src-DY9-_lul.cjs");
2
+ const require_src = require("../src-CTQrRb5X.cjs");
3
3
  exports.Extractor = require_src.Extractor;
4
4
  exports.ModelByInputTokens = require_src.ModelByInputTokens;
5
5
  exports.OBSERVATIONAL_MEMORY_DEFAULTS = require_src.OBSERVATIONAL_MEMORY_DEFAULTS;
@@ -1,2 +1,2 @@
1
- import { A as extractCurrentTask, B as OBSERVATION_CONTEXT_INSTRUCTIONS, C as WorkingMemoryExtractor, D as OBSERVER_SYSTEM_PROMPT, E as TokenCounter, F as injectAnchorIds, H as OBSERVATION_CONTINUATION_HINT, I as parseAnchorId, L as stripEphemeralAnchorIds, M as hasCurrentTaskSection, N as optimizeObservationsForContext, O as buildObserverPrompt, P as parseObserverOutput, R as Extractor, T as summarizeConversation, V as OBSERVATION_CONTEXT_PROMPT, _ as reconcileObservationGroupsFromReflection, b as wrapInObservationGroup, d as getObservationsAsOf, f as ObservationalMemoryProcessor, g as parseObservationGroups, h as deriveObservationGroupProvenance, j as formatMessagesForObserver, k as buildObserverSystemPrompt, m as combineObservationGroupRanges, p as ObservationalMemory, v as renderObservationGroupsForReflection, x as ModelByInputTokens, y as stripObservationGroups, z as OBSERVATIONAL_MEMORY_DEFAULTS } from "../src-CdqJP57F.js";
1
+ import { A as extractCurrentTask, B as OBSERVATION_CONTEXT_INSTRUCTIONS, C as WorkingMemoryExtractor, D as OBSERVER_SYSTEM_PROMPT, E as TokenCounter, F as injectAnchorIds, H as OBSERVATION_CONTINUATION_HINT, I as parseAnchorId, L as stripEphemeralAnchorIds, M as hasCurrentTaskSection, N as optimizeObservationsForContext, O as buildObserverPrompt, P as parseObserverOutput, R as Extractor, T as summarizeConversation, V as OBSERVATION_CONTEXT_PROMPT, _ as reconcileObservationGroupsFromReflection, b as wrapInObservationGroup, d as getObservationsAsOf, f as ObservationalMemoryProcessor, g as parseObservationGroups, h as deriveObservationGroupProvenance, j as formatMessagesForObserver, k as buildObserverSystemPrompt, m as combineObservationGroupRanges, p as ObservationalMemory, v as renderObservationGroupsForReflection, x as ModelByInputTokens, y as stripObservationGroups, z as OBSERVATIONAL_MEMORY_DEFAULTS } from "../src-MScpLVRh.js";
2
2
  export { Extractor, ModelByInputTokens, OBSERVATIONAL_MEMORY_DEFAULTS, OBSERVATION_CONTEXT_INSTRUCTIONS, OBSERVATION_CONTEXT_PROMPT, OBSERVATION_CONTINUATION_HINT, OBSERVER_SYSTEM_PROMPT, ObservationalMemory, ObservationalMemoryProcessor, TokenCounter, WorkingMemoryExtractor, buildObserverPrompt, buildObserverSystemPrompt, combineObservationGroupRanges, deriveObservationGroupProvenance, extractCurrentTask, formatMessagesForObserver, getObservationsAsOf, hasCurrentTaskSection, injectAnchorIds, optimizeObservationsForContext, parseAnchorId, parseObservationGroups, parseObserverOutput, reconcileObservationGroupsFromReflection, renderObservationGroupsForReflection, stripEphemeralAnchorIds, stripObservationGroups, summarizeConversation, wrapInObservationGroup };
@@ -37,6 +37,13 @@ export declare class TokenCounter {
37
37
  private buildRemoteAttachmentCachePayload;
38
38
  private fetchProviderAttachmentTokenEstimate;
39
39
  private countAttachmentPartAsync;
40
+ /**
41
+ * Count the name and the arguments of a tool call. Every state before the tool produces an
42
+ * output holds the same call signature in the context window, so all of those states share
43
+ * these cache kinds. `buildEstimateKey` hashes the text, so a shared kind stays correct and
44
+ * keeps the estimate warm while the invocation moves from one state to the next.
45
+ */
46
+ private countToolCallSignature;
40
47
  private countNonAttachmentPart;
41
48
  /**
42
49
  * Count tokens in a single message
@@ -1 +1 @@
1
- {"version":3,"file":"token-counter.d.ts","sourceRoot":"","sources":["../../../src/processors/observational-memory/token-counter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAa1D,MAAM,MAAM,wBAAwB,GAAG;IACrC,QAAQ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AA4B;IAkBpC,OAAO,CAAC,iCAAiC;IAOzC,OAAO,CAAC,gCAAgC;IAkIxC,OAAO,CAAC,wBAAwB;IAsEhC,OAAO,CAAC,mBAAmB;IAI3B,OAAO,CAAC,2BAA2B;IAInC,OAAO,CAAC,uBAAuB;IAkC/B,OAAO,CAAC,iCAAiC;YAiC3B,oCAAoC;YAyBpC,wBAAwB;IAyFtC;;;;;OAKG;IACH,OAAO,CAAC,sBAAsB;IAuB9B,OAAO,CAAC,sBAAsB;IA6G9B;;OAEG;IACH,YAAY,CAAC,OAAO,EAAE,eAAe,GAAG,MAAM;IAiCxC,iBAAiB,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC;IAiClE;;OAEG;IACH,aAAa,CAAC,QAAQ,EAAE,eAAe,EAAE,GAAG,MAAM;IAU5C,kBAAkB,CAAC,QAAQ,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAOtE;;OAEG;IACH,iBAAiB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM;CAGhD"}
@@ -18542,33 +18542,62 @@ var TokenCounter = class TokenCounter {
18542
18542
  if (isImageAttachment) await resolveImageDimensionsAsync(part);
18543
18543
  return this.countAttachmentPartSync(part);
18544
18544
  }
18545
+ /**
18546
+ * Count the name and the arguments of a tool call. Every state before the tool produces an
18547
+ * output holds the same call signature in the context window, so all of those states share
18548
+ * these cache kinds. `buildEstimateKey` hashes the text, so a shared kind stays correct and
18549
+ * keeps the estimate warm while the invocation moves from one state to the next.
18550
+ */
18551
+ countToolCallSignature(part, invocation) {
18552
+ let tokens = 0;
18553
+ let overheadDelta = 0;
18554
+ if (invocation.toolName) tokens += this.readOrPersistPartEstimate(part, "tool-call-name", invocation.toolName);
18555
+ if (invocation.args) if (typeof invocation.args === "string") tokens += this.readOrPersistPartEstimate(part, "tool-call-args", invocation.args);
18556
+ else {
18557
+ const argsJson = JSON.stringify(invocation.args);
18558
+ tokens += this.readOrPersistPartEstimate(part, "tool-call-args-json", argsJson);
18559
+ overheadDelta -= 12;
18560
+ }
18561
+ return {
18562
+ tokens,
18563
+ overheadDelta
18564
+ };
18565
+ }
18545
18566
  countNonAttachmentPart(part) {
18546
18567
  let overheadDelta = 0;
18547
- let toolResultDelta = 0;
18568
+ let extraMessageDelta = 0;
18548
18569
  if (part.type === "text") return {
18549
18570
  tokens: this.readOrPersistPartEstimate(part, "text", part.text),
18550
18571
  overheadDelta,
18551
- toolResultDelta
18572
+ extraMessageDelta
18552
18573
  };
18553
18574
  if (part.type === "tool-invocation") {
18554
18575
  const invocation = part.toolInvocation;
18576
+ const state = invocation.state;
18555
18577
  let tokens = 0;
18556
- if (invocation.state === "call" || invocation.state === "partial-call") {
18557
- if (invocation.toolName) tokens += this.readOrPersistPartEstimate(part, `tool-${invocation.state}-name`, invocation.toolName);
18558
- if (invocation.args) if (typeof invocation.args === "string") tokens += this.readOrPersistPartEstimate(part, `tool-${invocation.state}-args`, invocation.args);
18559
- else {
18560
- const argsJson = JSON.stringify(invocation.args);
18561
- tokens += this.readOrPersistPartEstimate(part, `tool-${invocation.state}-args-json`, argsJson);
18562
- overheadDelta -= 12;
18563
- }
18578
+ if (state === "call" || state === "partial-call" || state === "approval-requested") {
18579
+ const signature = this.countToolCallSignature(part, invocation);
18580
+ return {
18581
+ tokens: signature.tokens,
18582
+ overheadDelta: overheadDelta + signature.overheadDelta,
18583
+ extraMessageDelta
18584
+ };
18585
+ }
18586
+ if (state === "approval-responded") {
18587
+ extraMessageDelta++;
18588
+ const signature = this.countToolCallSignature(part, invocation);
18589
+ tokens += signature.tokens;
18590
+ overheadDelta += signature.overheadDelta;
18591
+ const reason = invocation.approval?.reason;
18592
+ if (reason) tokens += this.readOrPersistPartEstimate(part, "tool-approval-reason", reason);
18564
18593
  return {
18565
18594
  tokens,
18566
18595
  overheadDelta,
18567
- toolResultDelta
18596
+ extraMessageDelta
18568
18597
  };
18569
18598
  }
18570
- if (invocation.state === "result") {
18571
- toolResultDelta++;
18599
+ if (state === "result") {
18600
+ extraMessageDelta++;
18572
18601
  const { value: resultForCounting, usingStoredModelOutput } = this.resolveToolResultForTokenCounting(part, invocation.result);
18573
18602
  if (resultForCounting !== void 0) {
18574
18603
  const contentTokens = this.countMultimodalToolResultContent(part, resultForCounting);
@@ -18582,47 +18611,45 @@ var TokenCounter = class TokenCounter {
18582
18611
  return {
18583
18612
  tokens,
18584
18613
  overheadDelta,
18585
- toolResultDelta
18614
+ extraMessageDelta
18586
18615
  };
18587
18616
  }
18588
- if (invocation.state === "output-denied") {
18589
- toolResultDelta++;
18617
+ if (state === "output-denied") {
18618
+ extraMessageDelta++;
18590
18619
  const reason = invocation.approval?.reason ?? "Tool call was not approved by the user";
18591
18620
  tokens += this.readOrPersistPartEstimate(part, "tool-result-denied", reason);
18592
18621
  return {
18593
18622
  tokens,
18594
18623
  overheadDelta,
18595
- toolResultDelta
18624
+ extraMessageDelta
18596
18625
  };
18597
18626
  }
18598
- if (invocation.state === "output-error") {
18599
- toolResultDelta++;
18600
- const errorText = invocation.errorText;
18601
- const errorMessage = typeof errorText === "string" ? errorText : "Tool execution failed";
18627
+ if (state === "output-error") {
18628
+ extraMessageDelta++;
18629
+ const errorMessage = typeof invocation.errorText === "string" ? invocation.errorText : "Tool execution failed";
18602
18630
  tokens += this.readOrPersistPartEstimate(part, "tool-result-error", errorMessage);
18603
18631
  return {
18604
18632
  tokens,
18605
18633
  overheadDelta,
18606
- toolResultDelta
18634
+ extraMessageDelta
18607
18635
  };
18608
18636
  }
18609
- throw new Error(`Unhandled tool-invocation state '${part.toolInvocation?.state}' in token counting for part type '${part.type}'`);
18610
18637
  }
18611
18638
  if (typeof part.type === "string" && part.type.startsWith("data-")) return {
18612
18639
  tokens: 0,
18613
18640
  overheadDelta,
18614
- toolResultDelta
18641
+ extraMessageDelta
18615
18642
  };
18616
18643
  if (part.type === "reasoning") return {
18617
18644
  tokens: 0,
18618
18645
  overheadDelta,
18619
- toolResultDelta
18646
+ extraMessageDelta
18620
18647
  };
18621
18648
  const serialized = serializePartForTokenCounting(part);
18622
18649
  return {
18623
18650
  tokens: this.readOrPersistPartEstimate(part, `part-${part.type}`, serialized),
18624
18651
  overheadDelta,
18625
- toolResultDelta
18652
+ extraMessageDelta
18626
18653
  };
18627
18654
  }
18628
18655
  /**
@@ -18631,7 +18658,7 @@ var TokenCounter = class TokenCounter {
18631
18658
  countMessage(message) {
18632
18659
  let payloadTokens = this.countString(message.role);
18633
18660
  let overhead = TokenCounter.TOKENS_PER_MESSAGE;
18634
- let toolResultCount = 0;
18661
+ let extraMessageCount = 0;
18635
18662
  if (typeof message.content === "string") payloadTokens += this.readOrPersistMessageEstimate(message, "message-content", message.content);
18636
18663
  else if (message.content && typeof message.content === "object") {
18637
18664
  if (message.content.content && !Array.isArray(message.content.parts)) payloadTokens += this.readOrPersistMessageEstimate(message, "content-content", message.content.content);
@@ -18644,16 +18671,16 @@ var TokenCounter = class TokenCounter {
18644
18671
  const result = this.countNonAttachmentPart(part);
18645
18672
  payloadTokens += result.tokens;
18646
18673
  overhead += result.overheadDelta;
18647
- toolResultCount += result.toolResultDelta;
18674
+ extraMessageCount += result.extraMessageDelta;
18648
18675
  }
18649
18676
  }
18650
- if (toolResultCount > 0) overhead += toolResultCount * TokenCounter.TOKENS_PER_MESSAGE;
18677
+ if (extraMessageCount > 0) overhead += extraMessageCount * TokenCounter.TOKENS_PER_MESSAGE;
18651
18678
  return Math.round(payloadTokens + overhead);
18652
18679
  }
18653
18680
  async countMessageAsync(message) {
18654
18681
  let payloadTokens = this.countString(message.role);
18655
18682
  let overhead = TokenCounter.TOKENS_PER_MESSAGE;
18656
- let toolResultCount = 0;
18683
+ let extraMessageCount = 0;
18657
18684
  if (typeof message.content === "string") payloadTokens += this.readOrPersistMessageEstimate(message, "message-content", message.content);
18658
18685
  else if (message.content && typeof message.content === "object") {
18659
18686
  if (message.content.content && !Array.isArray(message.content.parts)) payloadTokens += this.readOrPersistMessageEstimate(message, "content-content", message.content.content);
@@ -18666,10 +18693,10 @@ var TokenCounter = class TokenCounter {
18666
18693
  const result = this.countNonAttachmentPart(part);
18667
18694
  payloadTokens += result.tokens;
18668
18695
  overhead += result.overheadDelta;
18669
- toolResultCount += result.toolResultDelta;
18696
+ extraMessageCount += result.extraMessageDelta;
18670
18697
  }
18671
18698
  }
18672
- if (toolResultCount > 0) overhead += toolResultCount * TokenCounter.TOKENS_PER_MESSAGE;
18699
+ if (extraMessageCount > 0) overhead += extraMessageCount * TokenCounter.TOKENS_PER_MESSAGE;
18673
18700
  return Math.round(payloadTokens + overhead);
18674
18701
  }
18675
18702
  /**
@@ -19772,6 +19799,7 @@ function deepMergeWorkingMemory(existing, update) {
19772
19799
  for (const key of Object.keys(update)) {
19773
19800
  const updateValue = update[key];
19774
19801
  const existingValue = result[key];
19802
+ if (updateValue === void 0) continue;
19775
19803
  if (updateValue === null) delete result[key];
19776
19804
  else if (Array.isArray(updateValue)) result[key] = updateValue;
19777
19805
  else if (typeof updateValue === "object" && updateValue !== null && typeof existingValue === "object" && existingValue !== null && !Array.isArray(existingValue)) result[key] = deepMergeWorkingMemory(existingValue, updateValue);
@@ -19824,7 +19852,7 @@ const updateWorkingMemoryTool = (memoryConfig) => {
19824
19852
  version: 1,
19825
19853
  vendor: "mastra",
19826
19854
  validate: (value) => {
19827
- const memoryValue = !!value && typeof value === "object" && !Array.isArray(value) && "memory" in value ? value.memory : stripNullsFromOptional(value, jsonSchema);
19855
+ const memoryValue = stripNullsFromOptional(!!value && typeof value === "object" && !Array.isArray(value) && "memory" in value ? value.memory : value, jsonSchema);
19828
19856
  const result = validateMemory(memoryValue);
19829
19857
  return result instanceof Promise ? result.then(toWrappedResult) : toWrappedResult(result);
19830
19858
  },
@@ -19841,6 +19869,7 @@ const updateWorkingMemoryTool = (memoryConfig) => {
19841
19869
  id: "update-working-memory",
19842
19870
  description: schema ? useStateSignals ? `${stateSignalsPreamble} Data is merged with existing memory — only include fields you want to add or update.` : `Update the working memory with new information. Data is merged with existing memory - only include fields you want to add or update. To preserve existing data, omit the field entirely. Arrays are replaced entirely when provided, so pass the complete array or omit it to keep the existing values.` : useStateSignals ? `${stateSignalsPreamble} Pass the full updated Markdown blob as a string in the memory field.` : `Update the working memory with new information. Any data not included will be overwritten. Always pass data as string to the memory field. Never pass an object.`,
19843
19871
  inputSchema,
19872
+ ...usesMergeSemantics ? { strict: false } : {},
19844
19873
  execute: async (inputData, context) => {
19845
19874
  const workingMemoryInput = inputData;
19846
19875
  const threadId = context?.agent?.threadId;
@@ -28838,4 +28867,4 @@ Object.defineProperty(exports, "wrapInObservationGroup", {
28838
28867
  }
28839
28868
  });
28840
28869
 
28841
- //# sourceMappingURL=src-DY9-_lul.cjs.map
28870
+ //# sourceMappingURL=src-CTQrRb5X.cjs.map