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

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.
@@ -15635,6 +15635,16 @@ function sanitizeToolResultValue(value, seen = /* @__PURE__ */ new WeakMap()) {
15635
15635
  }
15636
15636
  return sanitizedObject;
15637
15637
  }
15638
+ /**
15639
+ * Serializes a tool result without truncating it.
15640
+ *
15641
+ * Token accounting must see the full result: the truncation applied by
15642
+ * {@link formatToolResultForObserver} exists to bound what the Observer LLM reads,
15643
+ * not to describe what the agent's provider context actually holds.
15644
+ */
15645
+ function serializeToolResultForTokenCounting(value) {
15646
+ return stringifyToolResult(value);
15647
+ }
15638
15648
  function stringifyToolResult(value) {
15639
15649
  if (typeof value === "string") return value;
15640
15650
  const sanitized = sanitizeToolResultValue(value);
@@ -18240,7 +18250,7 @@ var TokenCounter = class TokenCounter {
18240
18250
  let tokens = 0;
18241
18251
  const cacheParts = [];
18242
18252
  const countJsonContentPart = (contentPart) => {
18243
- const formatted = formatToolResultForObserver(contentPart);
18253
+ const formatted = serializeToolResultForTokenCounting(contentPart);
18244
18254
  tokens += this.countString(formatted);
18245
18255
  cacheParts.push({
18246
18256
  type: "json",
@@ -18603,7 +18613,7 @@ var TokenCounter = class TokenCounter {
18603
18613
  const contentTokens = this.countMultimodalToolResultContent(part, resultForCounting);
18604
18614
  if (contentTokens !== void 0) tokens += contentTokens;
18605
18615
  else {
18606
- const formattedResult = formatToolResultForObserver(resultForCounting);
18616
+ const formattedResult = serializeToolResultForTokenCounting(resultForCounting);
18607
18617
  tokens += this.readOrPersistPartEstimate(part, usingStoredModelOutput ? "tool-result-model-output-json" : "tool-result-json", formattedResult);
18608
18618
  }
18609
18619
  if (typeof resultForCounting !== "string") overheadDelta -= 12;
@@ -21392,7 +21402,7 @@ var SyncObservationStrategy = class extends ObservationStrategy {
21392
21402
  });
21393
21403
  await this.storage.updateThread({
21394
21404
  id: threadId,
21395
- title: shouldUpdateThreadTitle ? newTitle : thread.title ?? "",
21405
+ ...shouldUpdateThreadTitle ? { title: newTitle } : {},
21396
21406
  metadata: newMetadata
21397
21407
  });
21398
21408
  if (shouldUpdateThreadTitle) threadUpdateMarker = createThreadUpdateMarker({
@@ -21584,7 +21594,7 @@ var AsyncBufferObservationStrategy = class extends ObservationStrategy {
21584
21594
  });
21585
21595
  await this.storage.updateThread({
21586
21596
  id: threadId,
21587
- title: shouldUpdateThreadTitle ? newTitle : thread.title ?? "",
21597
+ ...shouldUpdateThreadTitle ? { title: newTitle } : {},
21588
21598
  metadata: newMetadata
21589
21599
  });
21590
21600
  if (shouldUpdateThreadTitle) {
@@ -21929,7 +21939,7 @@ var ResourceScopedObservationStrategy = class extends ObservationStrategy {
21929
21939
  });
21930
21940
  await this.storage.updateThread({
21931
21941
  id: update.threadId,
21932
- title: shouldUpdateThreadTitle ? newTitle : thread.title ?? "",
21942
+ ...shouldUpdateThreadTitle ? { title: newTitle } : {},
21933
21943
  metadata: newMetadata
21934
21944
  });
21935
21945
  if (shouldUpdateThreadTitle) threadUpdateMarkers.push(createThreadUpdateMarker({
@@ -22872,7 +22882,6 @@ async function persistThreadExtractedValues(storage, extractors, threadId, value
22872
22882
  });
22873
22883
  await storage.updateThread({
22874
22884
  id: threadId,
22875
- title: thread.title ?? "",
22876
22885
  metadata: newMetadata
22877
22886
  });
22878
22887
  }
@@ -25844,7 +25853,7 @@ ${formattedMessages}
25844
25853
  const shouldUpdateThreadTitle = !!newTitle && newTitle.length >= 3 && newTitle !== oldTitle;
25845
25854
  await this.storage.updateThread({
25846
25855
  id: threadId,
25847
- title: shouldUpdateThreadTitle ? newTitle : thread.title ?? "",
25856
+ ...shouldUpdateThreadTitle ? { title: newTitle } : {},
25848
25857
  metadata: newMetadata
25849
25858
  });
25850
25859
  }
@@ -26062,7 +26071,6 @@ ${formattedMessages}
26062
26071
  });
26063
26072
  await this.storage.updateThread({
26064
26073
  id: threadId,
26065
- title: thread.title ?? "",
26066
26074
  metadata: newMetadata
26067
26075
  });
26068
26076
  }
@@ -27208,7 +27216,6 @@ var Memory = class extends _mastra_core_memory.MastraMemory {
27208
27216
  if (!thread) throw new Error(`Thread ${threadId} not found`);
27209
27217
  await memoryStore.updateThread({
27210
27218
  id: threadId,
27211
- title: thread.title || "",
27212
27219
  metadata: {
27213
27220
  ...thread.metadata,
27214
27221
  workingMemory
@@ -27297,7 +27304,6 @@ ${workingMemory}`;
27297
27304
  if (!thread) throw new Error(`Thread ${threadId} not found`);
27298
27305
  await memoryStore.updateThread({
27299
27306
  id: threadId,
27300
- title: thread.title || "",
27301
27307
  metadata: {
27302
27308
  ...thread.metadata,
27303
27309
  workingMemory
@@ -28867,4 +28873,4 @@ Object.defineProperty(exports, "wrapInObservationGroup", {
28867
28873
  }
28868
28874
  });
28869
28875
 
28870
- //# sourceMappingURL=src-CTQrRb5X.cjs.map
28876
+ //# sourceMappingURL=src-kjoZv97r.cjs.map