@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.
@@ -15614,6 +15614,16 @@ function sanitizeToolResultValue(value, seen = /* @__PURE__ */ new WeakMap()) {
15614
15614
  }
15615
15615
  return sanitizedObject;
15616
15616
  }
15617
+ /**
15618
+ * Serializes a tool result without truncating it.
15619
+ *
15620
+ * Token accounting must see the full result: the truncation applied by
15621
+ * {@link formatToolResultForObserver} exists to bound what the Observer LLM reads,
15622
+ * not to describe what the agent's provider context actually holds.
15623
+ */
15624
+ function serializeToolResultForTokenCounting(value) {
15625
+ return stringifyToolResult(value);
15626
+ }
15617
15627
  function stringifyToolResult(value) {
15618
15628
  if (typeof value === "string") return value;
15619
15629
  const sanitized = sanitizeToolResultValue(value);
@@ -18219,7 +18229,7 @@ var TokenCounter = class TokenCounter {
18219
18229
  let tokens = 0;
18220
18230
  const cacheParts = [];
18221
18231
  const countJsonContentPart = (contentPart) => {
18222
- const formatted = formatToolResultForObserver(contentPart);
18232
+ const formatted = serializeToolResultForTokenCounting(contentPart);
18223
18233
  tokens += this.countString(formatted);
18224
18234
  cacheParts.push({
18225
18235
  type: "json",
@@ -18582,7 +18592,7 @@ var TokenCounter = class TokenCounter {
18582
18592
  const contentTokens = this.countMultimodalToolResultContent(part, resultForCounting);
18583
18593
  if (contentTokens !== void 0) tokens += contentTokens;
18584
18594
  else {
18585
- const formattedResult = formatToolResultForObserver(resultForCounting);
18595
+ const formattedResult = serializeToolResultForTokenCounting(resultForCounting);
18586
18596
  tokens += this.readOrPersistPartEstimate(part, usingStoredModelOutput ? "tool-result-model-output-json" : "tool-result-json", formattedResult);
18587
18597
  }
18588
18598
  if (typeof resultForCounting !== "string") overheadDelta -= 12;
@@ -21371,7 +21381,7 @@ var SyncObservationStrategy = class extends ObservationStrategy {
21371
21381
  });
21372
21382
  await this.storage.updateThread({
21373
21383
  id: threadId,
21374
- title: shouldUpdateThreadTitle ? newTitle : thread.title ?? "",
21384
+ ...shouldUpdateThreadTitle ? { title: newTitle } : {},
21375
21385
  metadata: newMetadata
21376
21386
  });
21377
21387
  if (shouldUpdateThreadTitle) threadUpdateMarker = createThreadUpdateMarker({
@@ -21563,7 +21573,7 @@ var AsyncBufferObservationStrategy = class extends ObservationStrategy {
21563
21573
  });
21564
21574
  await this.storage.updateThread({
21565
21575
  id: threadId,
21566
- title: shouldUpdateThreadTitle ? newTitle : thread.title ?? "",
21576
+ ...shouldUpdateThreadTitle ? { title: newTitle } : {},
21567
21577
  metadata: newMetadata
21568
21578
  });
21569
21579
  if (shouldUpdateThreadTitle) {
@@ -21908,7 +21918,7 @@ var ResourceScopedObservationStrategy = class extends ObservationStrategy {
21908
21918
  });
21909
21919
  await this.storage.updateThread({
21910
21920
  id: update.threadId,
21911
- title: shouldUpdateThreadTitle ? newTitle : thread.title ?? "",
21921
+ ...shouldUpdateThreadTitle ? { title: newTitle } : {},
21912
21922
  metadata: newMetadata
21913
21923
  });
21914
21924
  if (shouldUpdateThreadTitle) threadUpdateMarkers.push(createThreadUpdateMarker({
@@ -22851,7 +22861,6 @@ async function persistThreadExtractedValues(storage, extractors, threadId, value
22851
22861
  });
22852
22862
  await storage.updateThread({
22853
22863
  id: threadId,
22854
- title: thread.title ?? "",
22855
22864
  metadata: newMetadata
22856
22865
  });
22857
22866
  }
@@ -25823,7 +25832,7 @@ ${formattedMessages}
25823
25832
  const shouldUpdateThreadTitle = !!newTitle && newTitle.length >= 3 && newTitle !== oldTitle;
25824
25833
  await this.storage.updateThread({
25825
25834
  id: threadId,
25826
- title: shouldUpdateThreadTitle ? newTitle : thread.title ?? "",
25835
+ ...shouldUpdateThreadTitle ? { title: newTitle } : {},
25827
25836
  metadata: newMetadata
25828
25837
  });
25829
25838
  }
@@ -26041,7 +26050,6 @@ ${formattedMessages}
26041
26050
  });
26042
26051
  await this.storage.updateThread({
26043
26052
  id: threadId,
26044
- title: thread.title ?? "",
26045
26053
  metadata: newMetadata
26046
26054
  });
26047
26055
  }
@@ -27187,7 +27195,6 @@ var Memory = class extends MastraMemory {
27187
27195
  if (!thread) throw new Error(`Thread ${threadId} not found`);
27188
27196
  await memoryStore.updateThread({
27189
27197
  id: threadId,
27190
- title: thread.title || "",
27191
27198
  metadata: {
27192
27199
  ...thread.metadata,
27193
27200
  workingMemory
@@ -27276,7 +27283,6 @@ ${workingMemory}`;
27276
27283
  if (!thread) throw new Error(`Thread ${threadId} not found`);
27277
27284
  await memoryStore.updateThread({
27278
27285
  id: threadId,
27279
- title: thread.title || "",
27280
27286
  metadata: {
27281
27287
  ...thread.metadata,
27282
27288
  workingMemory
@@ -28613,4 +28619,4 @@ Notes:
28613
28619
  //#endregion
28614
28620
  export { extractCurrentTask as A, OBSERVATION_CONTEXT_INSTRUCTIONS as B, WorkingMemoryExtractor as C, OBSERVER_SYSTEM_PROMPT as D, TokenCounter as E, injectAnchorIds as F, OBSERVATION_CONTINUATION_HINT as H, parseAnchorId as I, stripEphemeralAnchorIds as L, hasCurrentTaskSection as M, optimizeObservationsForContext as N, buildObserverPrompt as O, parseObserverOutput as P, Extractor as R, deepMergeWorkingMemory as S, summarizeConversation as T, OBSERVATION_CONTEXT_PROMPT as V, reconcileObservationGroupsFromReflection as _, extractWorkingMemoryContent as a, wrapInObservationGroup as b, WORKING_MEMORY_STATE_ID as c, getObservationsAsOf as d, ObservationalMemoryProcessor as f, parseObservationGroups as g, deriveObservationGroupProvenance as h, WorkingMemory as i, formatMessagesForObserver as j, buildObserverSystemPrompt as k, WORKING_MEMORY_STATE_PROCESSOR_ID as l, combineObservationGroupRanges as m, MessageHistory$1 as n, extractWorkingMemoryTags as o, ObservationalMemory as p, SemanticRecall as r, removeWorkingMemoryTags as s, Memory as t, WorkingMemoryStateProcessor as u, renderObservationGroupsForReflection as v, SUMMARIZE_THREAD_DEFAULTS as w, ModelByInputTokens as x, stripObservationGroups as y, OBSERVATIONAL_MEMORY_DEFAULTS as z };
28615
28621
 
28616
- //# sourceMappingURL=src-MScpLVRh.js.map
28622
+ //# sourceMappingURL=src-hv0DMVM-.js.map