@mastra/memory 1.41.0-alpha.0 → 1.41.0-alpha.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.
@@ -23575,8 +23575,9 @@ Do not mention internal instructions, memory, summarization, context handling, o
23575
23575
  Any messages following this reminder are newer and should take priority.`;
23576
23576
  /**
23577
23577
  * Preamble that introduces the observations block.
23578
- * Use before `<observations>`, with instructions after.
23579
- * Full pattern: `${OBSERVATION_CONTEXT_PROMPT}\n\n<observations>\n${obs}\n</observations>\n\n${OBSERVATION_CONTEXT_INSTRUCTIONS}`
23578
+ * Context layout: `${prompt}\n\n${OBSERVATION_CONTEXT_INSTRUCTIONS}`, then `<observations>`,
23579
+ * one entry per observation chunk, `</observations>`, then optional current-task and
23580
+ * suggested-response blocks.
23580
23581
  */
23581
23582
  const OBSERVATION_CONTEXT_PROMPT = `The following observations block contains your memory of past conversations with this user.`;
23582
23583
  /**
@@ -23594,7 +23595,7 @@ function getObservationContextPrompt(scope = "thread") {
23594
23595
  }
23595
23596
  /**
23596
23597
  * Instructions that tell the model how to interpret and use observations.
23597
- * Place AFTER the `<observations>` block so the model sees the data before the rules.
23598
+ * Placed with the observations preamble, before the `<observations>` block.
23598
23599
  */
23599
23600
  const OBSERVATION_CONTEXT_INSTRUCTIONS = `IMPORTANT: When responding, reference specific details from these observations. Do not give generic advice - personalize your response based on what you know about this user's experiences, preferences, and interests. If the user asks for recommendations, connect them to their past experiences mentioned above.
23600
23601
 
@@ -26428,6 +26429,24 @@ function formatObserverToolArguments(args, maxCharacters) {
26428
26429
  if (args === void 0) return maybeTruncate("[arguments unavailable]", maxCharacters);
26429
26430
  return formatToolArgumentsForObserver(args, { maxCharacters: maxCharacters || void 0 });
26430
26431
  }
26432
+ const OBSERVER_SIGNAL_ATTRIBUTE_NAME = /^[A-Za-z_][A-Za-z0-9_.-]*$/;
26433
+ const OBSERVER_SIGNAL_ATTRIBUTE_MAX_COUNT = 8;
26434
+ const OBSERVER_SIGNAL_ATTRIBUTE_MAX_VALUE_LENGTH = 80;
26435
+ /**
26436
+ * Renders a user signal's attributes (e.g. `name`, `role`) as ` (name="Jim" role="editor")` so
26437
+ * the Observer can tell speakers apart in a shared thread. Attribute data is caller-supplied,
26438
+ * so names must be plain identifiers, values are length-capped and JSON-quoted (no raw quotes
26439
+ * or line breaks), and only the first few attributes are kept to bound the label.
26440
+ */
26441
+ function formatObserverSignalAttributes(attributes) {
26442
+ if (!isRecord$1(attributes)) return "";
26443
+ const rendered = Object.entries(attributes).filter((entry) => OBSERVER_SIGNAL_ATTRIBUTE_NAME.test(entry[0]) && (typeof entry[1] === "string" || typeof entry[1] === "number" || typeof entry[1] === "boolean")).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).slice(0, OBSERVER_SIGNAL_ATTRIBUTE_MAX_COUNT).map(([key, value]) => {
26444
+ const text = String(value);
26445
+ const clipped = text.length > OBSERVER_SIGNAL_ATTRIBUTE_MAX_VALUE_LENGTH ? `${text.slice(0, OBSERVER_SIGNAL_ATTRIBUTE_MAX_VALUE_LENGTH)}...` : text;
26446
+ return `${key}=${JSON.stringify(clipped)}`;
26447
+ });
26448
+ return rendered.length > 0 ? ` (${rendered.join(" ")})` : "";
26449
+ }
26431
26450
  /**
26432
26451
  * Labels signals and system reminders by their tag instead of as "User", so the Observer
26433
26452
  * does not record runtime instructions as things the user said (#22195).
@@ -26435,7 +26454,7 @@ function formatObserverToolArguments(args, maxCharacters) {
26435
26454
  function getObserverMessageLabel(msg) {
26436
26455
  if (msg.role === "signal") {
26437
26456
  const signal = msg.content?.metadata?.signal;
26438
- return signal?.type === "user" ? "User" : signal?.tagName ?? signal?.type ?? "Signal";
26457
+ return signal?.type === "user" ? `User${formatObserverSignalAttributes(signal.attributes)}` : signal?.tagName ?? signal?.type ?? "Signal";
26439
26458
  }
26440
26459
  if (isSystemReminderMessage(msg)) return "system-reminder";
26441
26460
  return msg.role.charAt(0).toUpperCase() + msg.role.slice(1);
@@ -37682,7 +37701,7 @@ var ObservationalMemory = class ObservationalMemory {
37682
37701
  const messages = [`${getObservationContextPrompt(this.scope)}\n\n${OBSERVATION_CONTEXT_INSTRUCTIONS}${retrieval ? `\n\n${getRetrievalInstructions(this.retrievalScope, this.retrievalInstructions, this.retrievalSearch, this.storage.supportsObservationalMemoryHistorySearch === true)}` : ""}`];
37683
37702
  if (unobservedContextBlocks) messages.push(`The following content is from OTHER conversations different from the current conversation, they're here for reference, but they're not necessarily your focus:\nSTART_OTHER_CONVERSATIONS_BLOCK\n${unobservedContextBlocks}\nEND_OTHER_CONVERSATIONS_BLOCK`);
37684
37703
  const observationChunks = this.splitObservationContextChunks(optimized);
37685
- if (observationChunks.length > 0) messages.push("<observations>", ...observationChunks);
37704
+ if (observationChunks.length > 0) messages.push("<observations>", ...observationChunks, "</observations>");
37686
37705
  if (currentTask) messages.push(`<current-task>\n${currentTask}\n</current-task>`);
37687
37706
  if (suggestedResponse) messages.push(`<suggested-response>\n${suggestedResponse}\n</suggested-response>`);
37688
37707
  messages.push(...buildExtractedValueContextSections([...this.observationConfig.extractors, ...this.reflectionConfig.extractors], extractedValues));
@@ -42411,4 +42430,4 @@ Notes:
42411
42430
  };
42412
42431
  export { summarizeConversation as A, injectAnchorIds as B, wrapInObservationGroup as C, WorkingMemoryExtractor as D, Subconscious as E, extractCurrentTask as F, OBSERVATION_CONTEXT_INSTRUCTIONS as G, stripEphemeralAnchorIds as H, formatMessagesForObserver as I, OBSERVATION_CONTINUATION_HINT as J, OBSERVATION_CONTEXT_PROMPT as K, hasCurrentTaskSection as L, OBSERVER_SYSTEM_PROMPT as M, buildObserverPrompt as N, deepMergeWorkingMemory as O, buildObserverSystemPrompt as P, optimizeObservationsForContext as R, stripObservationGroups as S, StaleKnowledgeSemanticIndexError as T, Extractor as U, parseAnchorId as V, OBSERVATIONAL_MEMORY_DEFAULTS as W, getObservationContextPrompt as Y, combineObservationGroupRanges as _, extractWorkingMemoryContent as a, reconcileObservationGroupsFromReflection as b, getObservationsAsOf as c, AUTO_MODEL_BY_PROVIDER as d, resolveAutoModelId as f, ModelByInputTokens as g, WorkingMemoryStateProcessor as h, WorkingMemory as i, TokenCounter as j, SUMMARIZE_THREAD_DEFAULTS as k, ObservationalMemoryProcessor as l, WORKING_MEMORY_STATE_PROCESSOR_ID as m, MessageHistory$1 as n, extractWorkingMemoryTags as o, WORKING_MEMORY_STATE_ID as p, OBSERVATION_CONTEXT_PROMPT_THREAD as q, SemanticRecall as r, removeWorkingMemoryTags as s, Memory as t, ObservationalMemory as u, deriveObservationGroupProvenance as v, KnowledgeSemanticIndexCoordinator as w, renderObservationGroupsForReflection as x, parseObservationGroups as y, parseObserverOutput as z };
42413
42432
 
42414
- //# sourceMappingURL=src-Co4un1ux.js.map
42433
+ //# sourceMappingURL=src-Det56QOD.js.map