@mastra/memory 1.28.1 → 1.28.2-alpha.0

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.
@@ -16075,6 +16075,12 @@ function requireVisible(scope, options, label) {
16075
16075
  if (!isKnowledgeScopeVisible(scope, options.scope)) throw new Error(`${label} is outside the curator's visible scope.`);
16076
16076
  }
16077
16077
  function createKnowledgeWriteTools(memory, options) {
16078
+ async function resolveWritableNode(id) {
16079
+ const node = await (await getStore(memory)).getNode(id);
16080
+ if (!node || node.mergedInto) throw new Error(`Knowledge node not found: ${id}`);
16081
+ requireVisible(node.scope, options, "Knowledge node");
16082
+ return node;
16083
+ }
16078
16084
  return {
16079
16085
  knowledge_append: createTool({
16080
16086
  id: "knowledge_append",
@@ -16145,7 +16151,7 @@ function createKnowledgeWriteTools(memory, options) {
16145
16151
  }),
16146
16152
  knowledge_update_node: createTool({
16147
16153
  id: "knowledge_update_node",
16148
- description: "Update a visible node name or kind using optimistic concurrency. Provide at least one of name or kind.",
16154
+ description: "Atomically rename and re-kind a visible node using optimistic concurrency.",
16149
16155
  inputSchema: {
16150
16156
  type: "object",
16151
16157
  properties: {
@@ -16166,17 +16172,18 @@ function createKnowledgeWriteTools(memory, options) {
16166
16172
  minLength: 1
16167
16173
  }
16168
16174
  },
16169
- required: ["node", "expectedVersion"],
16175
+ required: [
16176
+ "node",
16177
+ "expectedVersion",
16178
+ "name",
16179
+ "kind"
16180
+ ],
16170
16181
  additionalProperties: false
16171
16182
  },
16172
16183
  execute: async (input) => {
16173
16184
  const value = input;
16174
- if (value.name === void 0 && value.kind === void 0) throw new Error("knowledge_update_node requires at least one of: name, kind.");
16175
- const store = await getStore(memory);
16176
- const node = await store.getNode(value.node);
16177
- if (!node || node.mergedInto) throw new Error(`Knowledge node not found: ${value.node}`);
16178
- requireVisible(node.scope, options, "Knowledge node");
16179
- return store.updateNode({
16185
+ const node = await resolveWritableNode(value.node);
16186
+ return (await getStore(memory)).updateNode({
16180
16187
  id: node.id,
16181
16188
  version: value.expectedVersion,
16182
16189
  name: value.name,
@@ -16184,6 +16191,78 @@ function createKnowledgeWriteTools(memory, options) {
16184
16191
  });
16185
16192
  }
16186
16193
  }),
16194
+ knowledge_rename_node: createTool({
16195
+ id: "knowledge_rename_node",
16196
+ description: "Rename a visible node using optimistic concurrency.",
16197
+ inputSchema: {
16198
+ type: "object",
16199
+ properties: {
16200
+ node: {
16201
+ type: "string",
16202
+ minLength: 1
16203
+ },
16204
+ expectedVersion: {
16205
+ type: "integer",
16206
+ minimum: 1
16207
+ },
16208
+ name: {
16209
+ type: "string",
16210
+ minLength: 1
16211
+ }
16212
+ },
16213
+ required: [
16214
+ "node",
16215
+ "expectedVersion",
16216
+ "name"
16217
+ ],
16218
+ additionalProperties: false
16219
+ },
16220
+ execute: async (input) => {
16221
+ const value = input;
16222
+ const node = await resolveWritableNode(value.node);
16223
+ return (await getStore(memory)).updateNode({
16224
+ id: node.id,
16225
+ version: value.expectedVersion,
16226
+ name: value.name
16227
+ });
16228
+ }
16229
+ }),
16230
+ knowledge_set_node_kind: createTool({
16231
+ id: "knowledge_set_node_kind",
16232
+ description: "Change a visible node kind using optimistic concurrency.",
16233
+ inputSchema: {
16234
+ type: "object",
16235
+ properties: {
16236
+ node: {
16237
+ type: "string",
16238
+ minLength: 1
16239
+ },
16240
+ expectedVersion: {
16241
+ type: "integer",
16242
+ minimum: 1
16243
+ },
16244
+ kind: {
16245
+ type: "string",
16246
+ minLength: 1
16247
+ }
16248
+ },
16249
+ required: [
16250
+ "node",
16251
+ "expectedVersion",
16252
+ "kind"
16253
+ ],
16254
+ additionalProperties: false
16255
+ },
16256
+ execute: async (input) => {
16257
+ const value = input;
16258
+ const node = await resolveWritableNode(value.node);
16259
+ return (await getStore(memory)).updateNode({
16260
+ id: node.id,
16261
+ version: value.expectedVersion,
16262
+ kind: value.kind
16263
+ });
16264
+ }
16265
+ }),
16187
16266
  knowledge_merge_nodes: createTool({
16188
16267
  id: "knowledge_merge_nodes",
16189
16268
  description: "Merge a visible duplicate node into another visible node using source-version CAS.",
@@ -16723,7 +16802,7 @@ var Subconscious = class {
16723
16802
  const CURATION_AGENT = "curate";
16724
16803
  const DEFAULT_INSTRUCTIONS$1 = `Maintain durable scoped knowledge from the committed observation worklist.
16725
16804
 
16726
- Use the read tools to inspect existing nodes, knowledge records, mentions, backlinks, and long-form node content. Use the write tools to merge true duplicates, repair names and links, soft-delete superseded knowledge records, rescope knowledge records only when justified and permitted by their ceilings, and synthesize useful node content. Never restore deleted knowledge records. Never invent provenance, capture timestamps, scopes, ceilings, IDs, or versions; those are enforced by code. Resolve optimistic-concurrency conflicts by reading the latest record and retrying the intended mutation. Keep the reserved capture-guidance node concise and update it only with durable guidance that will improve future capture.
16805
+ Use the read tools to inspect existing nodes, knowledge records, mentions, backlinks, and long-form node content. Use the write tools to merge true duplicates, repair names and links, soft-delete superseded knowledge records, rescope knowledge records only when justified and permitted by their ceilings, and synthesize useful node content. When both a node name and kind must change, use knowledge_update_node so they commit atomically under one expectedVersion; use the single-field tools only when changing one field. Never restore deleted knowledge records. Never invent provenance, capture timestamps, scopes, ceilings, IDs, or versions; those are enforced by code. Resolve optimistic-concurrency conflicts by reading the latest record and retrying the intended mutation. Keep the reserved capture-guidance node concise and update it only with durable guidance that will improve future capture.
16727
16806
 
16728
16807
  For each significant entity node touched by a KnowledgeRecord in the current worklist, including people, projects, pull requests, issues, repositories, documents, and organizations, maintain a short entity description; do not walk nodes outside the worklist for this. Use the supplied record and read the named node once; do not search or browse unless its identity is ambiguous. Describe what the entity is, its current state, and links to its real-world object, then write it with knowledge_write_node_description, which always requires expectedVersion from the node you just read; after a version conflict, re-read the node and regenerate the description from its current state before retrying. If the node does not exist yet, create it first with knowledge_write_node_content, then re-read it for its fresh version before writing the description. Write one or two plain-text sentences, roughly 40 to 75 tokens; storage rejects any description over its hard length cap, so keep them tight and put long-form detail in node content instead. Include links only from the entity's own records or observations that explicitly associate the link with that entity; never invent a URL, identifier, file path, or provenance. Leave long-form node content alone unless you are synthesizing it deliberately; never shrink content into a synopsis. For entity-description maintenance only, skip low-signal nodes with only a trivial record, any system-kind node, and the reserved capture-guidance node.
16729
16808
 
@@ -23198,20 +23277,20 @@ function getUnobservedPartsPreservingToolCallPairs(message) {
23198
23277
  /**
23199
23278
  * Get the messages Observational Memory is allowed to work with.
23200
23279
  *
23201
- * Messages supplied through the `context` option are per-run ephemeral input. Core's
23202
- * persistence contract already treats them as never-persist: `MessageStateManager` routes
23203
- * them into `userContextMessages`, and `drainUnsavedMessages` only drains input/response.
23280
+ * Messages supplied through the `context` option and the synthetic `om-continuation`
23281
+ * message are prompt-only input. Core's persistence contract already treats context as
23282
+ * never-persist, while the continuation remains memory-sourced so it can stay in the live
23283
+ * actor prompt.
23204
23284
  *
23205
- * OM builds its windows from `get.all.db()`, which includes context messages, and then
23206
- * seals and persists candidates directly turning ephemeral context into durable user
23207
- * messages. Excluding them here keeps OM's window, sealing, persistence and token
23208
- * accounting consistent with that contract.
23285
+ * OM builds its windows from `get.all.db()`, which includes both categories, and then seals
23286
+ * and persists candidates directly. Excluding them here keeps OM's observation, buffering,
23287
+ * persistence, and token accounting consistent with their ephemeral contract.
23209
23288
  */
23210
23289
  function getObservableMessages(messageList) {
23211
- const allMessages = messageList.get.all.db();
23212
23290
  const contextMessageIds = messageList.makeMessageSourceChecker().context;
23213
- if (contextMessageIds.size === 0) return allMessages;
23214
- return allMessages.filter((message) => !contextMessageIds.has(message.id));
23291
+ return messageList.get.all.db().filter((message) => {
23292
+ return message.id !== "om-continuation" && !contextMessageIds.has(message.id);
23293
+ });
23215
23294
  }
23216
23295
  /**
23217
23296
  * Safely extract buffered observation chunks from a record.
@@ -31555,4 +31634,4 @@ Notes:
31555
31634
  //#endregion
31556
31635
  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, SUBCONSCIOUS_ACTIVITY_STATE_ID as J, SubconsciousCaptureExtractor as K, OBSERVATIONAL_MEMORY_DEFAULTS as L, optimizeObservationsForContext as M, parseObserverOutput as N, buildObserverSystemPrompt as O, injectAnchorIds as P, Extractor as Q, OBSERVATION_CONTEXT_INSTRUCTIONS as R, WorkingMemoryExtractor as S, TokenCounter as T, StaleKnowledgeSemanticIndexError as U, Subconscious as V, SubconsciousRemindExtractor as W, publishSubconsciousActivity as X, buildSubconsciousActivitySnapshot as Y, renderSubconsciousActivity as Z, 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, subconsciousCaptureSchema 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 };
31557
31636
 
31558
- //# sourceMappingURL=src-BNtoxIHL.js.map
31637
+ //# sourceMappingURL=src-Br1yJXN1.js.map