@mastra/memory 1.28.1 → 1.28.2-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.
Files changed (30) hide show
  1. package/dist/docs/SKILL.md +48 -48
  2. package/dist/docs/assets/SOURCE_MAP.json +1 -1
  3. package/dist/docs/references/docs-agents-human-in-the-loop.md +1 -1
  4. package/dist/docs/references/docs-agents-networks.md +1 -1
  5. package/dist/docs/references/docs-guides-context-engineering.md +1 -1
  6. package/dist/docs/references/docs-harness-background-tasks.md +1 -1
  7. package/dist/docs/references/docs-memory-message-history.md +3 -3
  8. package/dist/docs/references/docs-memory-observational-memory.md +18 -18
  9. package/dist/docs/references/docs-memory-overview.md +1 -1
  10. package/dist/docs/references/docs-memory-semantic-recall.md +0 -2
  11. package/dist/docs/references/docs-memory-working-memory.md +1 -1
  12. package/dist/docs/references/docs-subagents.md +2 -2
  13. package/dist/docs/references/reference-memory-observational-memory.md +4 -4
  14. package/dist/docs/references/reference-memory-settled.md +1 -1
  15. package/dist/docs/references/reference-processors-token-limiter-processor.md +1 -1
  16. package/dist/docs/references/reference-vectors-mongodb.md +2 -2
  17. package/dist/index.cjs +1 -1
  18. package/dist/index.js +1 -1
  19. package/dist/processors/index.cjs +1 -1
  20. package/dist/processors/index.js +1 -1
  21. package/dist/processors/observational-memory/message-utils.d.ts +7 -7
  22. package/dist/processors/observational-memory/observation-utils.d.ts +1 -0
  23. package/dist/processors/observational-memory/observation-utils.d.ts.map +1 -1
  24. package/dist/processors/observational-memory/subconscious/knowledge-write-tools.d.ts.map +1 -1
  25. package/dist/{src-Br56ncef.cjs → src-Bq1Ng-3M.cjs} +99 -20
  26. package/dist/{src-Br56ncef.cjs.map → src-Bq1Ng-3M.cjs.map} +1 -1
  27. package/dist/{src-BNtoxIHL.js → src-Br1yJXN1.js} +99 -20
  28. package/dist/{src-BNtoxIHL.js.map → src-Br1yJXN1.js.map} +1 -1
  29. package/package.json +18 -14
  30. package/CHANGELOG.md +0 -8626
@@ -16096,6 +16096,12 @@ function requireVisible(scope, options, label) {
16096
16096
  if (!(0, _mastra_core_storage.isKnowledgeScopeVisible)(scope, options.scope)) throw new Error(`${label} is outside the curator's visible scope.`);
16097
16097
  }
16098
16098
  function createKnowledgeWriteTools(memory, options) {
16099
+ async function resolveWritableNode(id) {
16100
+ const node = await (await getStore(memory)).getNode(id);
16101
+ if (!node || node.mergedInto) throw new Error(`Knowledge node not found: ${id}`);
16102
+ requireVisible(node.scope, options, "Knowledge node");
16103
+ return node;
16104
+ }
16099
16105
  return {
16100
16106
  knowledge_append: (0, _mastra_core_tools.createTool)({
16101
16107
  id: "knowledge_append",
@@ -16166,7 +16172,7 @@ function createKnowledgeWriteTools(memory, options) {
16166
16172
  }),
16167
16173
  knowledge_update_node: (0, _mastra_core_tools.createTool)({
16168
16174
  id: "knowledge_update_node",
16169
- description: "Update a visible node name or kind using optimistic concurrency. Provide at least one of name or kind.",
16175
+ description: "Atomically rename and re-kind a visible node using optimistic concurrency.",
16170
16176
  inputSchema: {
16171
16177
  type: "object",
16172
16178
  properties: {
@@ -16187,17 +16193,18 @@ function createKnowledgeWriteTools(memory, options) {
16187
16193
  minLength: 1
16188
16194
  }
16189
16195
  },
16190
- required: ["node", "expectedVersion"],
16196
+ required: [
16197
+ "node",
16198
+ "expectedVersion",
16199
+ "name",
16200
+ "kind"
16201
+ ],
16191
16202
  additionalProperties: false
16192
16203
  },
16193
16204
  execute: async (input) => {
16194
16205
  const value = input;
16195
- if (value.name === void 0 && value.kind === void 0) throw new Error("knowledge_update_node requires at least one of: name, kind.");
16196
- const store = await getStore(memory);
16197
- const node = await store.getNode(value.node);
16198
- if (!node || node.mergedInto) throw new Error(`Knowledge node not found: ${value.node}`);
16199
- requireVisible(node.scope, options, "Knowledge node");
16200
- return store.updateNode({
16206
+ const node = await resolveWritableNode(value.node);
16207
+ return (await getStore(memory)).updateNode({
16201
16208
  id: node.id,
16202
16209
  version: value.expectedVersion,
16203
16210
  name: value.name,
@@ -16205,6 +16212,78 @@ function createKnowledgeWriteTools(memory, options) {
16205
16212
  });
16206
16213
  }
16207
16214
  }),
16215
+ knowledge_rename_node: (0, _mastra_core_tools.createTool)({
16216
+ id: "knowledge_rename_node",
16217
+ description: "Rename a visible node using optimistic concurrency.",
16218
+ inputSchema: {
16219
+ type: "object",
16220
+ properties: {
16221
+ node: {
16222
+ type: "string",
16223
+ minLength: 1
16224
+ },
16225
+ expectedVersion: {
16226
+ type: "integer",
16227
+ minimum: 1
16228
+ },
16229
+ name: {
16230
+ type: "string",
16231
+ minLength: 1
16232
+ }
16233
+ },
16234
+ required: [
16235
+ "node",
16236
+ "expectedVersion",
16237
+ "name"
16238
+ ],
16239
+ additionalProperties: false
16240
+ },
16241
+ execute: async (input) => {
16242
+ const value = input;
16243
+ const node = await resolveWritableNode(value.node);
16244
+ return (await getStore(memory)).updateNode({
16245
+ id: node.id,
16246
+ version: value.expectedVersion,
16247
+ name: value.name
16248
+ });
16249
+ }
16250
+ }),
16251
+ knowledge_set_node_kind: (0, _mastra_core_tools.createTool)({
16252
+ id: "knowledge_set_node_kind",
16253
+ description: "Change a visible node kind using optimistic concurrency.",
16254
+ inputSchema: {
16255
+ type: "object",
16256
+ properties: {
16257
+ node: {
16258
+ type: "string",
16259
+ minLength: 1
16260
+ },
16261
+ expectedVersion: {
16262
+ type: "integer",
16263
+ minimum: 1
16264
+ },
16265
+ kind: {
16266
+ type: "string",
16267
+ minLength: 1
16268
+ }
16269
+ },
16270
+ required: [
16271
+ "node",
16272
+ "expectedVersion",
16273
+ "kind"
16274
+ ],
16275
+ additionalProperties: false
16276
+ },
16277
+ execute: async (input) => {
16278
+ const value = input;
16279
+ const node = await resolveWritableNode(value.node);
16280
+ return (await getStore(memory)).updateNode({
16281
+ id: node.id,
16282
+ version: value.expectedVersion,
16283
+ kind: value.kind
16284
+ });
16285
+ }
16286
+ }),
16208
16287
  knowledge_merge_nodes: (0, _mastra_core_tools.createTool)({
16209
16288
  id: "knowledge_merge_nodes",
16210
16289
  description: "Merge a visible duplicate node into another visible node using source-version CAS.",
@@ -16744,7 +16823,7 @@ var Subconscious = class {
16744
16823
  const CURATION_AGENT = "curate";
16745
16824
  const DEFAULT_INSTRUCTIONS$1 = `Maintain durable scoped knowledge from the committed observation worklist.
16746
16825
 
16747
- 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.
16826
+ 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.
16748
16827
 
16749
16828
  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.
16750
16829
 
@@ -23219,20 +23298,20 @@ function getUnobservedPartsPreservingToolCallPairs(message) {
23219
23298
  /**
23220
23299
  * Get the messages Observational Memory is allowed to work with.
23221
23300
  *
23222
- * Messages supplied through the `context` option are per-run ephemeral input. Core's
23223
- * persistence contract already treats them as never-persist: `MessageStateManager` routes
23224
- * them into `userContextMessages`, and `drainUnsavedMessages` only drains input/response.
23301
+ * Messages supplied through the `context` option and the synthetic `om-continuation`
23302
+ * message are prompt-only input. Core's persistence contract already treats context as
23303
+ * never-persist, while the continuation remains memory-sourced so it can stay in the live
23304
+ * actor prompt.
23225
23305
  *
23226
- * OM builds its windows from `get.all.db()`, which includes context messages, and then
23227
- * seals and persists candidates directly turning ephemeral context into durable user
23228
- * messages. Excluding them here keeps OM's window, sealing, persistence and token
23229
- * accounting consistent with that contract.
23306
+ * OM builds its windows from `get.all.db()`, which includes both categories, and then seals
23307
+ * and persists candidates directly. Excluding them here keeps OM's observation, buffering,
23308
+ * persistence, and token accounting consistent with their ephemeral contract.
23230
23309
  */
23231
23310
  function getObservableMessages(messageList) {
23232
- const allMessages = messageList.get.all.db();
23233
23311
  const contextMessageIds = messageList.makeMessageSourceChecker().context;
23234
- if (contextMessageIds.size === 0) return allMessages;
23235
- return allMessages.filter((message) => !contextMessageIds.has(message.id));
23312
+ return messageList.get.all.db().filter((message) => {
23313
+ return message.id !== "om-continuation" && !contextMessageIds.has(message.id);
23314
+ });
23236
23315
  }
23237
23316
  /**
23238
23317
  * Safely extract buffered observation chunks from a record.
@@ -31869,4 +31948,4 @@ Object.defineProperty(exports, "wrapInObservationGroup", {
31869
31948
  }
31870
31949
  });
31871
31950
 
31872
- //# sourceMappingURL=src-Br56ncef.cjs.map
31951
+ //# sourceMappingURL=src-Bq1Ng-3M.cjs.map