@mastra/memory 1.26.2-alpha.0 → 1.26.2

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.
Files changed (30) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/dist/docs/SKILL.md +1 -1
  3. package/dist/docs/assets/SOURCE_MAP.json +1 -1
  4. package/dist/docs/references/docs-capabilities-subagents.md +2 -2
  5. package/dist/docs/references/docs-long-running-agents-background-tasks.md +2 -2
  6. package/dist/docs/references/docs-long-running-agents-goals.md +3 -2
  7. package/dist/docs/references/docs-memory-memory-processors.md +1 -1
  8. package/dist/docs/references/docs-memory-message-history.md +2 -2
  9. package/dist/docs/references/docs-memory-observational-memory.md +13 -13
  10. package/dist/docs/references/docs-memory-semantic-recall.md +1 -1
  11. package/dist/docs/references/docs-memory-working-memory.md +1 -1
  12. package/dist/docs/references/reference-memory-observational-memory.md +12 -4
  13. package/dist/docs/references/reference-vectors-mongodb.md +2 -2
  14. package/dist/docs/references/reference-vectors-pg.md +1 -1
  15. package/dist/index.cjs +1 -1
  16. package/dist/index.js +1 -1
  17. package/dist/processors/index.cjs +1 -1
  18. package/dist/processors/index.js +1 -1
  19. package/dist/processors/observational-memory/constants.d.ts.map +1 -1
  20. package/dist/processors/observational-memory/observation-turn/step.d.ts +2 -1
  21. package/dist/processors/observational-memory/observation-turn/step.d.ts.map +1 -1
  22. package/dist/processors/observational-memory/types.d.ts +12 -10
  23. package/dist/processors/observational-memory/types.d.ts.map +1 -1
  24. package/dist/{src-DGdlH4fo.js → src-BYD6Wp5m.js} +58 -14
  25. package/dist/{src-DGdlH4fo.js.map → src-BYD6Wp5m.js.map} +1 -1
  26. package/dist/{src-CTwoCwmY.cjs → src-b5E69E65.cjs} +58 -14
  27. package/dist/{src-CTwoCwmY.cjs.map → src-b5E69E65.cjs.map} +1 -1
  28. package/dist/tools/om-tools.d.ts +5 -1
  29. package/dist/tools/om-tools.d.ts.map +1 -1
  30. package/package.json +8 -8
@@ -14748,7 +14748,7 @@ By default recall returns **low** detail: truncated text and tool names only. Ea
14748
14748
  - Use \`detail: "high"\` to get full message content including tool arguments and results. This will only return the high detail version of a single message part at a time.
14749
14749
  - Use \`partIndex\` with a cursor to fetch a single part at full detail — for example, to read one specific tool result or code block without loading every part.
14750
14750
 
14751
- If the result says \`truncated: true\`, the output was cut to fit the token budget. You can paginate or use \`partIndex\` to target specific content.
14751
+ If the result says \`truncated: true\`, the output was cut to fit the token budget. You can paginate or use \`partIndex\` to target specific content. If a single part is itself too large, follow the returned \`nextCharOffset\` as described below.
14752
14752
 
14753
14753
  ### Following up on truncated parts
14754
14754
  Low-detail results may include truncation hints like:
@@ -14756,6 +14756,8 @@ Low-detail results may include truncation hints like:
14756
14756
 
14757
14757
  **When you see these hints and need the full content, make the exact call described in the hint.** This is the normal workflow: first recall at low detail to scan, then drill into specific parts at high detail. Do not stop at the low-detail result if the user asked for exact content.
14758
14758
 
14759
+ If a single part is larger than the token budget, the \`partIndex\` result is \`truncated: true\` and includes \`nextCharOffset\`. Repeat the same call with \`charOffset\` set to that exact value to read the next chunk from where the previous one ended. Keep following \`nextCharOffset\` until the result no longer includes it — the chunks together contain the full part. Retrying without \`charOffset\` returns the same prefix again.
14760
+
14759
14761
  ### When recall is NOT needed
14760
14762
  - The user is asking for a high-level summary and your observations already cover it
14761
14763
  - The question is about general preferences or facts that don't require source text
@@ -19122,6 +19124,36 @@ function truncateByTokens(text, maxTokens, hint) {
19122
19124
  wasTruncated: true
19123
19125
  };
19124
19126
  }
19127
+ function chunkTextByTokens(text, maxTokens, charOffset = 0) {
19128
+ let startOffset = Math.max(0, Math.min(Math.floor(charOffset), text.length));
19129
+ const startCode = text.charCodeAt(startOffset);
19130
+ if (startCode >= 56320 && startCode <= 57343) startOffset += 1;
19131
+ const remaining = text.slice(startOffset);
19132
+ if (!remaining || estimateTokenCount(remaining) <= maxTokens) return {
19133
+ text: remaining,
19134
+ charOffset: startOffset,
19135
+ truncated: false
19136
+ };
19137
+ let low = 0;
19138
+ let high = remaining.length;
19139
+ let best = "";
19140
+ while (low <= high) {
19141
+ const mid = Math.floor((low + high) / 2);
19142
+ const candidate = safeSlice(remaining, mid);
19143
+ const candidateTokens = estimateTokenCount(candidate);
19144
+ if (candidate && candidateTokens <= maxTokens) {
19145
+ best = candidate;
19146
+ low = mid + 1;
19147
+ } else high = mid - 1;
19148
+ }
19149
+ const nextCharOffset = startOffset + best.length;
19150
+ return {
19151
+ text: best,
19152
+ charOffset: startOffset,
19153
+ nextCharOffset,
19154
+ truncated: nextCharOffset < text.length
19155
+ };
19156
+ }
19125
19157
  function lowDetailPartLimit(type) {
19126
19158
  if (type === "text") return AUTO_EXPAND_TEXT_TOKENS;
19127
19159
  if (type === "tool-result" || type === "tool-call") return AUTO_EXPAND_TOOL_TOKENS;
@@ -19339,7 +19371,7 @@ function renderFormattedParts(parts, timestamps, options) {
19339
19371
  tokenOffset: expandedTokens - options.maxTokens
19340
19372
  };
19341
19373
  }
19342
- async function recallPart({ memory, threadId, resourceId, cursor, partIndex, threadScope, maxTokens = DEFAULT_MAX_RESULT_TOKENS }) {
19374
+ async function recallPart({ memory, threadId, resourceId, cursor, partIndex, charOffset, threadScope, maxTokens = DEFAULT_MAX_RESULT_TOKENS }) {
19343
19375
  if (!memory || typeof memory.getMemoryStore !== "function") throw new Error("Memory instance is required for recall");
19344
19376
  if (!threadId) throw new Error("Thread ID is required for recall");
19345
19377
  const resolved = await resolveCursorMessage(memory, cursor, {
@@ -19363,31 +19395,36 @@ async function recallPart({ memory, threadId, resourceId, cursor, partIndex, thr
19363
19395
  if (nextMessage) {
19364
19396
  const firstNextPart = formatMessageParts(nextMessage, "high")[0];
19365
19397
  if (firstNextPart) {
19366
- const fallbackText = `${`Part index ${partIndex} not found in message ${cursor}; showing partIndex ${firstNextPart.partIndex} from next message ${firstNextPart.messageId}.\n\n`}${firstNextPart.text}`;
19367
- const truncatedText = truncateStringByTokens(fallbackText, maxTokens);
19368
- const wasTruncated = truncatedText !== fallbackText;
19398
+ const fallbackChunk = chunkTextByTokens(`${`Part index ${partIndex} not found in message ${cursor}; showing partIndex ${firstNextPart.partIndex} from next message ${firstNextPart.messageId}.\n\n`}${firstNextPart.text}`, maxTokens, charOffset);
19399
+ const fallbackContinuation = fallbackChunk.nextCharOffset ? `To continue this part, call recall cursor="${cursor}" partIndex=${partIndex} detail="high" charOffset=${fallbackChunk.nextCharOffset}.` : void 0;
19369
19400
  return {
19370
- text: truncatedText,
19401
+ text: fallbackChunk.text,
19371
19402
  messageId: firstNextPart.messageId,
19372
19403
  partIndex: firstNextPart.partIndex,
19373
19404
  role: firstNextPart.role,
19374
19405
  type: firstNextPart.type,
19375
- truncated: wasTruncated
19406
+ truncated: fallbackChunk.truncated,
19407
+ charOffset: fallbackChunk.charOffset,
19408
+ nextCharOffset: fallbackChunk.nextCharOffset,
19409
+ note: fallbackContinuation
19376
19410
  };
19377
19411
  }
19378
19412
  }
19379
19413
  }
19380
19414
  throw new Error(`Part index ${partIndex} not found in message ${cursor}. Available indices: ${availableIndices}`);
19381
19415
  }
19382
- const truncatedText = truncateStringByTokens(target.text, maxTokens);
19383
- const wasTruncated = truncatedText !== target.text;
19416
+ const chunk = chunkTextByTokens(target.text, maxTokens, charOffset);
19417
+ const note = chunk.nextCharOffset ? `To continue this part, call recall cursor="${target.messageId}" partIndex=${target.partIndex} detail="high" charOffset=${chunk.nextCharOffset}.` : void 0;
19384
19418
  return {
19385
- text: truncatedText,
19419
+ text: chunk.text,
19386
19420
  messageId: target.messageId,
19387
19421
  partIndex: target.partIndex,
19388
19422
  role: target.role,
19389
19423
  type: target.type,
19390
- truncated: wasTruncated
19424
+ truncated: chunk.truncated,
19425
+ charOffset: chunk.charOffset,
19426
+ nextCharOffset: chunk.nextCharOffset,
19427
+ note
19391
19428
  };
19392
19429
  }
19393
19430
  async function recallMessages({ memory, threadId, resourceId, cursor, page = 1, limit = 20, detail = "low", partType, toolName, threadScope, maxTokens = DEFAULT_MAX_RESULT_TOKENS }) {
@@ -19669,11 +19706,16 @@ const recallTool = (_memoryConfig, options) => {
19669
19706
  type: "integer",
19670
19707
  minimum: 0,
19671
19708
  description: "Fetch a single part from the cursor message by its positional index. When provided, returns only that part at high detail. Indices are shown as [p0], [p1], etc. in recall results."
19709
+ },
19710
+ charOffset: {
19711
+ type: "integer",
19712
+ minimum: 0,
19713
+ description: "Continue reading a truncated single part from this position. Pass the exact nextCharOffset value returned by a previous call; do not compute it yourself. Only applies with cursor and partIndex in mode=\"messages\"."
19672
19714
  }
19673
19715
  }
19674
19716
  },
19675
19717
  execute: async (inputData, context) => {
19676
- const { mode, query, cursor, threadId: explicitThreadId, anchor, page, limit, detail, partType, toolName, partIndex, before, after } = inputData;
19718
+ const { mode, query, cursor, threadId: explicitThreadId, anchor, page, limit, detail, partType, toolName, partIndex, charOffset, before, after } = inputData;
19677
19719
  const memory = context?.memory;
19678
19720
  const currentThreadId = context?.agent?.threadId;
19679
19721
  const resourceId = context?.agent?.resourceId;
@@ -19786,6 +19828,7 @@ const recallTool = (_memoryConfig, options) => {
19786
19828
  resourceId: isResourceScope ? resourceId : void 0,
19787
19829
  cursor,
19788
19830
  partIndex,
19831
+ charOffset,
19789
19832
  threadScope
19790
19833
  });
19791
19834
  return recallMessages({
@@ -22299,7 +22342,8 @@ var ObservationStep = class {
22299
22342
  }
22300
22343
  /**
22301
22344
  * Run the full threshold observation pipeline:
22302
- * waitForBuffering → re-check → activate → reflect → blockAfter gate observe
22345
+ * waitForBuffering → re-check → activate → reflect → observe (sync fallback when
22346
+ * buffered activation did not happen)
22303
22347
  */
22304
22348
  async runThresholdObservation() {
22305
22349
  const { threadId, resourceId, messageList } = this.turn;
@@ -28652,4 +28696,4 @@ Notes:
28652
28696
  //#endregion
28653
28697
  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 };
28654
28698
 
28655
- //# sourceMappingURL=src-DGdlH4fo.js.map
28699
+ //# sourceMappingURL=src-BYD6Wp5m.js.map