@mastra/memory 1.31.0-alpha.0 → 1.31.0-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.
@@ -5,7 +5,7 @@ import * as z4 from "zod/v4";
5
5
  import { z as z$1 } from "zod/v4";
6
6
  import { Agent, MessageList } from "@mastra/core/agent";
7
7
  import { coreFeatures } from "@mastra/core/features";
8
- import { MastraMemory, getMemoryTokenBoundary, getThreadOMMetadata, isAfterMemoryTokenBoundary, loadMessageHistory, normalizeMessageHistoryConfig, parseMemoryRequestContext, setThreadOMMetadata } from "@mastra/core/memory";
8
+ import { MastraMemory, getMemoryTokenBoundary, getThreadOMMetadata, isAfterMemoryTokenBoundary, isThreadTitlePinned, loadMessageHistory, normalizeMessageHistoryConfig, parseMemoryRequestContext, setThreadOMMetadata } from "@mastra/core/memory";
9
9
  import { EntityType, SpanType, createObservabilityContext, getOrCreateSpan } from "@mastra/core/observability";
10
10
  import { MessageHistory, MessageHistory as MessageHistory$1, SemanticRecall, TokenLimiterProcessor, WorkingMemory } from "@mastra/core/processors";
11
11
  import { generateEmptyFromSchema } from "@mastra/core/utils";
@@ -24874,6 +24874,23 @@ var ObservationStrategy = class ObservationStrategy {
24874
24874
  }
24875
24875
  };
24876
24876
  //#endregion
24877
+ //#region src/processors/observational-memory/observation-strategies/thread-title.ts
24878
+ /**
24879
+ * Resolve the thread title an Observational Memory cycle should persist.
24880
+ *
24881
+ * Returns the trimmed candidate when it is a new, long-enough title, or
24882
+ * `undefined` when the current title must stay — including when the user
24883
+ * pinned it via `session.thread.rename()`, which sets the
24884
+ * `titlePinned` thread metadata flag.
24885
+ */
24886
+ function resolveThreadTitleUpdate(thread, generatedTitle) {
24887
+ const candidate = generatedTitle?.trim();
24888
+ if (!candidate || candidate.length < 3) return void 0;
24889
+ if (isThreadTitlePinned(thread?.metadata)) return void 0;
24890
+ if (candidate === thread?.title?.trim()) return void 0;
24891
+ return candidate;
24892
+ }
24893
+ //#endregion
24877
24894
  //#region src/processors/observational-memory/observation-strategies/sync.ts
24878
24895
  var SyncObservationStrategy = class extends ObservationStrategy {
24879
24896
  startedAt = (/* @__PURE__ */ new Date()).toISOString();
@@ -25026,8 +25043,8 @@ var SyncObservationStrategy = class extends ObservationStrategy {
25026
25043
  let threadUpdateMarker;
25027
25044
  if (thread) {
25028
25045
  const oldTitle = thread.title?.trim();
25029
- const newTitle = processed.threadTitle?.trim();
25030
- const shouldUpdateThreadTitle = !!newTitle && newTitle.length >= 3 && newTitle !== oldTitle;
25046
+ const newTitle = resolveThreadTitleUpdate(thread, processed.threadTitle);
25047
+ const shouldUpdateThreadTitle = newTitle !== void 0;
25031
25048
  const previousOmMetadata = getThreadOMMetadata(thread.metadata);
25032
25049
  const metadataUpdate = buildThreadMetadataFromExtractedValues(processed.extractors ?? this.observationConfig.extractors, processed.extractedValues);
25033
25050
  const newMetadata = setThreadOMMetadata(thread.metadata, {
@@ -25226,13 +25243,14 @@ var AsyncBufferObservationStrategy = class extends ObservationStrategy {
25226
25243
  abortSignal: this.opts.abortSignal
25227
25244
  });
25228
25245
  await this.indexObservationGroups(processed.observations, threadId, resourceId, processed.lastObservedAt);
25229
- const newTitle = processed.threadTitle?.trim();
25230
- const hasValidThreadTitle = !!newTitle && newTitle.length >= 3;
25246
+ const candidateTitle = processed.threadTitle?.trim();
25247
+ const hasValidThreadTitle = !!candidateTitle && candidateTitle.length >= 3;
25231
25248
  if (hasValidThreadTitle || processed.extractedValues) {
25232
25249
  const thread = await this.storage.getThreadById({ threadId });
25233
25250
  if (thread) {
25234
25251
  const oldTitle = thread.title?.trim();
25235
- const shouldUpdateThreadTitle = hasValidThreadTitle && newTitle !== oldTitle;
25252
+ const newTitle = resolveThreadTitleUpdate(thread, candidateTitle);
25253
+ const shouldUpdateThreadTitle = newTitle !== void 0;
25236
25254
  const previousOmMetadata = getThreadOMMetadata(thread.metadata);
25237
25255
  const metadataUpdate = buildThreadMetadataFromExtractedValues(processed.extractors ?? this.observationConfig.extractors, processed.extractedValues);
25238
25256
  const newMetadata = setThreadOMMetadata(thread.metadata, {
@@ -25589,8 +25607,8 @@ var ResourceScopedObservationStrategy = class extends ObservationStrategy {
25589
25607
  const thread = await this.storage.getThreadById({ threadId: update.threadId });
25590
25608
  if (thread) {
25591
25609
  const oldTitle = thread.title?.trim();
25592
- const newTitle = update.threadTitle?.trim();
25593
- const shouldUpdateThreadTitle = !!newTitle && newTitle.length >= 3 && newTitle !== oldTitle;
25610
+ const newTitle = resolveThreadTitleUpdate(thread, update.threadTitle);
25611
+ const shouldUpdateThreadTitle = newTitle !== void 0;
25594
25612
  const previousOmMetadata = getThreadOMMetadata(thread.metadata);
25595
25613
  const metadataUpdate = buildThreadMetadataFromExtractedValues(update.extractors ?? this.observationConfig.extractors, update.extracted);
25596
25614
  const newMetadata = setThreadOMMetadata(thread.metadata, {
@@ -29793,9 +29811,8 @@ ${formattedMessages}
29793
29811
  currentTask: lastActivated.currentTask,
29794
29812
  threadTitle: chunkThreadTitle
29795
29813
  });
29796
- const oldTitle = thread.title?.trim();
29797
- const newTitle = chunkThreadTitle?.trim();
29798
- const shouldUpdateThreadTitle = !!newTitle && newTitle.length >= 3 && newTitle !== oldTitle;
29814
+ const newTitle = resolveThreadTitleUpdate(thread, chunkThreadTitle);
29815
+ const shouldUpdateThreadTitle = newTitle !== void 0;
29799
29816
  await this.storage.patchThread({
29800
29817
  id: threadId,
29801
29818
  ...shouldUpdateThreadTitle ? { title: newTitle } : {},
@@ -31187,6 +31204,13 @@ var Memory = class Memory extends MastraMemory {
31187
31204
  });
31188
31205
  return savedThread;
31189
31206
  }
31207
+ /**
31208
+ * Update a thread's title or metadata.
31209
+ *
31210
+ * Unlike `session.thread.rename()`, this does not pin the title, so
31211
+ * Observational Memory may still replace it with an extracted title. To
31212
+ * protect a manual rename, set `metadata.titlePinned` to `true`.
31213
+ */
31190
31214
  async updateThread({ id, title, metadata, memoryConfig }) {
31191
31215
  const updatedThread = await (await this.getMemoryStore()).patchThread({
31192
31216
  id,
@@ -32942,4 +32966,4 @@ Notes:
32942
32966
  //#endregion
32943
32967
  export { formatMessagesForObserver as A, OBSERVATION_CONTINUATION_HINT as B, SUMMARIZE_THREAD_DEFAULTS as C, buildObserverPrompt as D, OBSERVER_SYSTEM_PROMPT as E, parseAnchorId as F, ModelByInputTokens as G, KnowledgeSemanticIndexCoordinator as H, stripEphemeralAnchorIds as I, publishSubconsciousActivity as J, SUBCONSCIOUS_ACTIVITY_STATE_ID as K, OBSERVATIONAL_MEMORY_DEFAULTS as L, optimizeObservationsForContext as M, parseObserverOutput as N, buildObserverSystemPrompt as O, injectAnchorIds as P, OBSERVATION_CONTEXT_INSTRUCTIONS as R, WorkingMemoryExtractor as S, TokenCounter as T, StaleKnowledgeSemanticIndexError as U, Subconscious as V, SubconsciousRemindExtractor as W, Extractor as X, renderSubconsciousActivity as Y, wrapInObservationGroup as _, extractWorkingMemoryContent as a, WorkingMemoryStateProcessor as b, getObservationsAsOf as c, combineObservationGroupRanges as d, deriveObservationGroupProvenance as f, stripObservationGroups as g, renderObservationGroupsForReflection as h, WorkingMemory as i, hasCurrentTaskSection as j, extractCurrentTask as k, ObservationalMemoryProcessor as l, reconcileObservationGroupsFromReflection as m, MessageHistory$1 as n, extractWorkingMemoryTags as o, parseObservationGroups as p, buildSubconsciousActivitySnapshot as q, SemanticRecall as r, removeWorkingMemoryTags as s, Memory as t, ObservationalMemory as u, WORKING_MEMORY_STATE_ID as v, summarizeConversation as w, deepMergeWorkingMemory as x, WORKING_MEMORY_STATE_PROCESSOR_ID as y, OBSERVATION_CONTEXT_PROMPT as z };
32944
32968
 
32945
- //# sourceMappingURL=src-DqLGJfSb.js.map
32969
+ //# sourceMappingURL=src-Ju0u9OWc.js.map