@mastra/memory 1.23.1 → 1.24.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.
- package/CHANGELOG.md +50 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +3 -205
- package/dist/docs/references/docs-memory-message-history.md +19 -1
- package/dist/docs/references/reference-memory-memory-class.md +1 -1
- package/dist/docs/references/reference-vectors-mongodb.md +185 -4
- package/dist/index.cjs +30 -72
- package/dist/index.d.ts +2 -30
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -4
- package/dist/processors/index.cjs +32 -129
- package/dist/processors/index.js +2 -4
- package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -1
- package/dist/processors/observational-memory/reflector-runner.d.ts.map +1 -1
- package/dist/src-Ci_GvBVm.js +28106 -0
- package/dist/src-Ci_GvBVm.js.map +1 -0
- package/dist/src-VD6qMn-H.cjs +28360 -0
- package/dist/src-VD6qMn-H.cjs.map +1 -0
- package/package.json +11 -10
- package/dist/chunk-43FJOLKM.cjs +0 -108
- package/dist/chunk-43FJOLKM.cjs.map +0 -1
- package/dist/chunk-D4J4XPGM.cjs +0 -111
- package/dist/chunk-D4J4XPGM.cjs.map +0 -1
- package/dist/chunk-EGRHWZRV.js +0 -3
- package/dist/chunk-EGRHWZRV.js.map +0 -1
- package/dist/chunk-LSJJAJAF.js +0 -105
- package/dist/chunk-LSJJAJAF.js.map +0 -1
- package/dist/chunk-NKIQRCOM.cjs +0 -4
- package/dist/chunk-NKIQRCOM.cjs.map +0 -1
- package/dist/chunk-TSABI3S4.cjs +0 -31496
- package/dist/chunk-TSABI3S4.cjs.map +0 -1
- package/dist/chunk-WCGXQIEN.js +0 -103
- package/dist/chunk-WCGXQIEN.js.map +0 -1
- package/dist/chunk-XOCZP6LJ.js +0 -31429
- package/dist/chunk-XOCZP6LJ.js.map +0 -1
- package/dist/constants-RMCTOZE3.js +0 -3
- package/dist/constants-RMCTOZE3.js.map +0 -1
- package/dist/constants-ZEKSZ4UM.cjs +0 -28
- package/dist/constants-ZEKSZ4UM.cjs.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/observational-memory-HQ4AP566.js +0 -4
- package/dist/observational-memory-HQ4AP566.js.map +0 -1
- package/dist/observational-memory-NZSUTGPH.cjs +0 -129
- package/dist/observational-memory-NZSUTGPH.cjs.map +0 -1
- package/dist/processors/index.cjs.map +0 -1
- package/dist/processors/index.js.map +0 -1
- package/dist/working-memory-state-LDPWYVCG.cjs +0 -24
- package/dist/working-memory-state-LDPWYVCG.cjs.map +0 -1
- package/dist/working-memory-state-OMSMSYAW.js +0 -3
- package/dist/working-memory-state-OMSMSYAW.js.map +0 -1
package/dist/chunk-WCGXQIEN.js
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { createHash } from 'crypto';
|
|
2
|
-
import { structuredPatch } from 'diff';
|
|
3
|
-
|
|
4
|
-
// src/processors/working-memory-state/processor.ts
|
|
5
|
-
var WORKING_MEMORY_STATE_ID = "working-memory";
|
|
6
|
-
var WORKING_MEMORY_STATE_PROCESSOR_ID = "working-memory-state";
|
|
7
|
-
var WorkingMemoryStateProcessor = class {
|
|
8
|
-
constructor(memory, memoryConfig) {
|
|
9
|
-
this.memory = memory;
|
|
10
|
-
this.memoryConfig = memoryConfig;
|
|
11
|
-
}
|
|
12
|
-
memory;
|
|
13
|
-
memoryConfig;
|
|
14
|
-
id = WORKING_MEMORY_STATE_PROCESSOR_ID;
|
|
15
|
-
stateId = WORKING_MEMORY_STATE_ID;
|
|
16
|
-
async computeStateSignal(args) {
|
|
17
|
-
const template = await this.memory.getWorkingMemoryTemplate({ memoryConfig: this.memoryConfig });
|
|
18
|
-
if (!template) return;
|
|
19
|
-
const data = await this.memory.getWorkingMemory({
|
|
20
|
-
threadId: args.threadId,
|
|
21
|
-
resourceId: args.resourceId,
|
|
22
|
-
memoryConfig: this.memoryConfig
|
|
23
|
-
});
|
|
24
|
-
const contents = data?.trim();
|
|
25
|
-
if (!contents) return;
|
|
26
|
-
const cacheKey = stableWorkingMemoryCacheKey({ format: template.format, data: contents });
|
|
27
|
-
const shouldMakeSnapshot = !args.contextWindow.hasSnapshot;
|
|
28
|
-
if (args.tracking?.currentCacheKey === cacheKey && !shouldMakeSnapshot) return;
|
|
29
|
-
const mergedConfig = this.memory.getMergedThreadConfig(this.memoryConfig);
|
|
30
|
-
const scope = mergedConfig.workingMemory?.scope ?? "resource";
|
|
31
|
-
const deltaCandidate = template.format === "markdown" && !shouldMakeSnapshot ? buildMarkdownDelta({
|
|
32
|
-
lastSnapshot: args.lastSnapshot,
|
|
33
|
-
deltasSinceSnapshot: args.deltasSinceSnapshot,
|
|
34
|
-
nextContents: contents
|
|
35
|
-
}) : void 0;
|
|
36
|
-
if (deltaCandidate) {
|
|
37
|
-
return {
|
|
38
|
-
id: WORKING_MEMORY_STATE_ID,
|
|
39
|
-
mode: "delta",
|
|
40
|
-
cacheKey,
|
|
41
|
-
tagName: "working-memory",
|
|
42
|
-
contents: deltaCandidate.contents,
|
|
43
|
-
delta: deltaCandidate.contents,
|
|
44
|
-
// Stash the full post-edit text on the signal so the next turn can
|
|
45
|
-
// diff against the most recently emitted state instead of the older
|
|
46
|
-
// snapshot. Invisible to the model.
|
|
47
|
-
value: contents,
|
|
48
|
-
attributes: {
|
|
49
|
-
format: template.format,
|
|
50
|
-
scope,
|
|
51
|
-
patch: "unified-diff"
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
return {
|
|
56
|
-
id: WORKING_MEMORY_STATE_ID,
|
|
57
|
-
mode: "snapshot",
|
|
58
|
-
cacheKey,
|
|
59
|
-
tagName: "working-memory",
|
|
60
|
-
contents,
|
|
61
|
-
// Mirror contents in value so the first delta after a snapshot has a
|
|
62
|
-
// typed prior-state to diff against without falling back to contents.
|
|
63
|
-
value: contents,
|
|
64
|
-
attributes: {
|
|
65
|
-
format: template.format,
|
|
66
|
-
scope
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
function stableWorkingMemoryCacheKey(input) {
|
|
72
|
-
const hash = createHash("sha256");
|
|
73
|
-
hash.update(input.format);
|
|
74
|
-
hash.update("\0");
|
|
75
|
-
hash.update(input.data ?? "");
|
|
76
|
-
return `sha256:${hash.digest("hex")}`;
|
|
77
|
-
}
|
|
78
|
-
function buildMarkdownDelta(args) {
|
|
79
|
-
const { lastSnapshot, deltasSinceSnapshot, nextContents } = args;
|
|
80
|
-
const latestDelta = deltasSinceSnapshot.at(-1);
|
|
81
|
-
const prior = pickStringValue(readSignalValue(latestDelta)) ?? pickStringValue(readSignalValue(lastSnapshot)) ?? (typeof lastSnapshot?.contents === "string" ? lastSnapshot.contents : void 0);
|
|
82
|
-
if (!prior) return;
|
|
83
|
-
const patch = renderHunksOnly(prior, nextContents);
|
|
84
|
-
return { contents: patch };
|
|
85
|
-
}
|
|
86
|
-
function pickStringValue(value) {
|
|
87
|
-
return typeof value === "string" ? value : void 0;
|
|
88
|
-
}
|
|
89
|
-
function readSignalValue(signal) {
|
|
90
|
-
return signal?.metadata?.value;
|
|
91
|
-
}
|
|
92
|
-
function renderHunksOnly(prior, next) {
|
|
93
|
-
const { hunks } = structuredPatch("", "", prior, next, "", "", { context: 0 });
|
|
94
|
-
return hunks.map((hunk) => {
|
|
95
|
-
const header = `@@ -${hunk.oldStart},${hunk.oldLines} +${hunk.newStart},${hunk.newLines} @@`;
|
|
96
|
-
const lines = hunk.lines.filter((line) => !line.startsWith("\"));
|
|
97
|
-
return [header, ...lines].join("\n");
|
|
98
|
-
}).join("\n");
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export { WORKING_MEMORY_STATE_ID, WORKING_MEMORY_STATE_PROCESSOR_ID, WorkingMemoryStateProcessor, stableWorkingMemoryCacheKey };
|
|
102
|
-
//# sourceMappingURL=chunk-WCGXQIEN.js.map
|
|
103
|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,QAAQ,CAAA,CAAA,EAAI,IAAA,CAAK,QAAQ,CAAA,GAAA,CAAA;AACvF,IAAA,MAAM,KAAA,GAAQ,KAAK,KAAA,CAAM,MAAA,CAAO,UAAQ,CAAC,IAAA,CAAK,UAAA,CAAW,8BAA8B,CAAC,CAAA;AACxF,IAAA,OAAO,CAAC,MAAA,EAAQ,GAAG,KAAK,CAAA,CAAE,KAAK,IAAI,CAAA;AAAA,EACrC,CAAC,CAAA,CACA,IAAA,CAAK,IAAI,CAAA;AACd","file":"chunk-WCGXQIEN.js","sourcesContent":["/**\n * WorkingMemoryStateProcessor\n *\n * Experimental: delivers working memory to the model as a state signal instead\n * of folding it into the system message. Storage and the `setWorkingMemory`\n * tool are unchanged — this processor only changes the delivery path.\n *\n * Pattern matches `BrowserContextProcessor` in `@mastra/core/browser`:\n * - `stateId` namespaces the state lane on the thread.\n * - `cacheKey` is derived from the rendered payload so dedup is automatic.\n * - `contextWindow.hasSnapshot` re-injection ensures the model still sees the\n * current snapshot after older messages drop out of the window.\n *\n * Delta emission (markdown mode only): when a prior snapshot exists in the\n * context window, the processor emits a unified-diff delta against that\n * snapshot's contents. Schema mode and the snapshot fallback always emit a\n * full snapshot.\n *\n * @example\n * ```ts\n * new Memory({\n * options: {\n * workingMemory: {\n * enabled: true,\n * template: '...',\n * useStateSignals: true, // auto-attaches this processor\n * },\n * },\n * });\n * ```\n */\n\nimport { createHash } from 'node:crypto';\n\nimport type { MastraMemory, MemoryConfigInternal, WorkingMemoryTemplate } from '@mastra/core/memory';\nimport type {\n ComputeStateSignalArgs,\n ComputeStateSignalResult,\n Processor,\n ProcessorActiveStateSignal,\n} from '@mastra/core/processors';\nimport { structuredPatch } from 'diff';\n\nexport const WORKING_MEMORY_STATE_ID = 'working-memory';\nexport const WORKING_MEMORY_STATE_PROCESSOR_ID = 'working-memory-state';\n\nexport class WorkingMemoryStateProcessor implements Processor<typeof WORKING_MEMORY_STATE_PROCESSOR_ID> {\n readonly id = WORKING_MEMORY_STATE_PROCESSOR_ID;\n readonly stateId = WORKING_MEMORY_STATE_ID;\n\n constructor(\n private readonly memory: MastraMemory,\n private readonly memoryConfig?: MemoryConfigInternal,\n ) {}\n\n async computeStateSignal(args: ComputeStateSignalArgs): Promise<ComputeStateSignalResult> {\n const template = await this.memory.getWorkingMemoryTemplate({ memoryConfig: this.memoryConfig });\n if (!template) return;\n\n const data = await this.memory.getWorkingMemory({\n threadId: args.threadId,\n resourceId: args.resourceId,\n memoryConfig: this.memoryConfig,\n });\n\n // Nothing stored yet — no state to broadcast. The setWorkingMemory tool\n // description tells the model the expected shape; the signal carries state.\n const contents = data?.trim();\n if (!contents) return;\n\n const cacheKey = stableWorkingMemoryCacheKey({ format: template.format, data: contents });\n const shouldMakeSnapshot = !args.contextWindow.hasSnapshot;\n if (args.tracking?.currentCacheKey === cacheKey && !shouldMakeSnapshot) return;\n\n const mergedConfig = this.memory.getMergedThreadConfig(this.memoryConfig);\n const scope = mergedConfig.workingMemory?.scope ?? 'resource';\n\n const deltaCandidate =\n template.format === 'markdown' && !shouldMakeSnapshot\n ? buildMarkdownDelta({\n lastSnapshot: args.lastSnapshot,\n deltasSinceSnapshot: args.deltasSinceSnapshot,\n nextContents: contents,\n })\n : undefined;\n\n if (deltaCandidate) {\n return {\n id: WORKING_MEMORY_STATE_ID,\n mode: 'delta',\n cacheKey,\n tagName: 'working-memory',\n contents: deltaCandidate.contents,\n delta: deltaCandidate.contents,\n // Stash the full post-edit text on the signal so the next turn can\n // diff against the most recently emitted state instead of the older\n // snapshot. Invisible to the model.\n value: contents,\n attributes: {\n format: template.format,\n scope,\n patch: 'unified-diff',\n },\n };\n }\n\n return {\n id: WORKING_MEMORY_STATE_ID,\n mode: 'snapshot',\n cacheKey,\n tagName: 'working-memory',\n contents,\n // Mirror contents in value so the first delta after a snapshot has a\n // typed prior-state to diff against without falling back to contents.\n value: contents,\n attributes: {\n format: template.format,\n scope,\n },\n };\n }\n}\n\n/**\n * Stable cache key for the rendered working memory payload. Returns a SHA-256\n * digest so dedup metadata stays compact regardless of payload size (working\n * memory blobs can grow arbitrarily long).\n */\nexport function stableWorkingMemoryCacheKey(input: {\n format: WorkingMemoryTemplate['format'];\n data: string | null;\n}): string {\n const hash = createHash('sha256');\n hash.update(input.format);\n hash.update('\\0');\n hash.update(input.data ?? '');\n return `sha256:${hash.digest('hex')}`;\n}\n\n/**\n * Build a unified-diff delta against the most recently emitted state. Prefers\n * the latest delta's `value` (the post-edit full text) when available, falling\n * back to the snapshot's `value` and finally the snapshot's `contents`. This\n * keeps deltas incremental (B→C) instead of cumulative against a stale\n * snapshot (A→C), which matters when many small edits land between snapshots.\n *\n * Returns undefined when:\n * - there's no prior state to diff against\n * - the prior state isn't a plain string (multimodal signal)\n *\n * In either case the caller falls back to emitting a full snapshot.\n */\nfunction buildMarkdownDelta(args: {\n lastSnapshot?: ProcessorActiveStateSignal;\n deltasSinceSnapshot: ProcessorActiveStateSignal[];\n nextContents: string;\n}): { contents: string } | undefined {\n const { lastSnapshot, deltasSinceSnapshot, nextContents } = args;\n\n // `value` is stored on the persisted signal's metadata (see applyStateSignal\n // in @mastra/core/agent/state-signals). Read from there to recover the\n // post-edit full text from the most recently emitted state.\n const latestDelta = deltasSinceSnapshot.at(-1);\n const prior =\n pickStringValue(readSignalValue(latestDelta)) ??\n pickStringValue(readSignalValue(lastSnapshot)) ??\n (typeof lastSnapshot?.contents === 'string' ? lastSnapshot.contents : undefined);\n ('');\n if (!prior) return;\n\n const patch = renderHunksOnly(prior, nextContents);\n\n return { contents: patch };\n}\n\nfunction pickStringValue(value: unknown): string | undefined {\n return typeof value === 'string' ? value : undefined;\n}\n\nfunction readSignalValue(signal: ProcessorActiveStateSignal | undefined): unknown {\n return (signal?.metadata as { value?: unknown } | undefined)?.value;\n}\n\n/**\n * Render a unified-diff-style patch body containing only `@@` hunks and their\n * lines — dropping the filename preamble (`Index:` / `===` / `---` / `+++`)\n * that `createPatch` emits and the `\` trailer.\n * The preamble exists for tooling like `patch -p1` to know which file to\n * apply to; we only ever diff a single working-memory blob. The newline\n * trailer is semantically meaningless to the model and adds noise to the\n * state signal.\n */\nfunction renderHunksOnly(prior: string, next: string): string {\n const { hunks } = structuredPatch('', '', prior, next, '', '', { context: 0 });\n return hunks\n .map(hunk => {\n const header = `@@ -${hunk.oldStart},${hunk.oldLines} +${hunk.newStart},${hunk.newLines} @@`;\n const lines = hunk.lines.filter(line => !line.startsWith('\\\'));\n return [header, ...lines].join('\\n');\n })\n .join('\\n');\n}\n"]}
|