@mastra/memory 1.5.2 → 1.6.0-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.
- package/CHANGELOG.md +27 -0
- package/LICENSE.md +15 -0
- package/dist/{chunk-PVFLHAZX.cjs → chunk-5UYAHJVJ.cjs} +77 -73
- package/dist/chunk-5UYAHJVJ.cjs.map +1 -0
- package/dist/{chunk-HNPAIFCZ.js → chunk-A62BQK35.js} +77 -73
- package/dist/chunk-A62BQK35.js.map +1 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +16 -16
- package/dist/docs/references/docs-memory-observational-memory.md +3 -5
- package/dist/docs/references/reference-memory-cloneThread.md +13 -1
- package/dist/docs/references/reference-memory-observational-memory.md +4 -2
- package/dist/index.cjs +106 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +106 -7
- package/dist/index.js.map +1 -1
- package/dist/{observational-memory-Q47HN5YL.cjs → observational-memory-MXI54VC7.cjs} +17 -17
- package/dist/{observational-memory-Q47HN5YL.cjs.map → observational-memory-MXI54VC7.cjs.map} +1 -1
- package/dist/{observational-memory-KAFD4QZK.js → observational-memory-SR6G4HN5.js} +3 -3
- package/dist/{observational-memory-KAFD4QZK.js.map → observational-memory-SR6G4HN5.js.map} +1 -1
- package/dist/processors/index.cjs +15 -15
- package/dist/processors/index.js +1 -1
- package/dist/processors/observational-memory/observational-memory.d.ts +3 -4
- package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -1
- package/dist/processors/observational-memory/types.d.ts +8 -2
- package/dist/processors/observational-memory/types.d.ts.map +1 -1
- package/package.json +6 -6
- package/dist/chunk-HNPAIFCZ.js.map +0 -1
- package/dist/chunk-PVFLHAZX.cjs.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -58,6 +58,10 @@ export declare class Memory extends MastraMemory {
|
|
|
58
58
|
usage?: {
|
|
59
59
|
tokens: number;
|
|
60
60
|
};
|
|
61
|
+
total: number;
|
|
62
|
+
page: number;
|
|
63
|
+
perPage: number | false;
|
|
64
|
+
hasMore: boolean;
|
|
61
65
|
}>;
|
|
62
66
|
getThreadById({ threadId }: {
|
|
63
67
|
threadId: string;
|
|
@@ -235,6 +239,17 @@ export declare class Memory extends MastraMemory {
|
|
|
235
239
|
* ```
|
|
236
240
|
*/
|
|
237
241
|
cloneThread(args: StorageCloneThreadInput, memoryConfig?: MemoryConfig): Promise<StorageCloneThreadOutput>;
|
|
242
|
+
/**
|
|
243
|
+
* Clone observational memory records when cloning a thread.
|
|
244
|
+
* Thread-scoped: always cloned to the new thread.
|
|
245
|
+
* Resource-scoped: cloned only when the resourceId changes (same resourceId shares OM naturally).
|
|
246
|
+
* All stored message/thread IDs are remapped to the cloned IDs.
|
|
247
|
+
*/
|
|
248
|
+
private cloneObservationalMemory;
|
|
249
|
+
/**
|
|
250
|
+
* Create a remapped copy of an OM record with new thread/message IDs.
|
|
251
|
+
*/
|
|
252
|
+
private remapObservationalMemoryRecord;
|
|
238
253
|
/**
|
|
239
254
|
* Embed cloned messages for semantic recall.
|
|
240
255
|
* This is similar to the embedding logic in saveMessages but operates on already-saved messages.
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAKhD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAG1D,OAAO,EAAE,YAAY,EAAwD,MAAM,qBAAqB,CAAC;AACzG,OAAO,KAAK,EACV,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,EAEnB,MAAM,qBAAqB,CAAC;AAe7B,OAAO,KAAK,EACV,cAAc,EACd,wBAAwB,EACxB,eAAe,EACf,yBAAyB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AE,cAAc,GACvB,OAAO,CAAC,eAAe,EAAE,CAAC;IAW7B;;;;OAIG;YACW,iBAAiB;CAyFhC;AAGD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAGxF,YAAY,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -15341,7 +15341,8 @@ var Memory = class extends MastraMemory {
|
|
|
15341
15341
|
const rawMessages = shouldGetNewestAndReverse ? paginatedResult.messages.reverse() : paginatedResult.messages;
|
|
15342
15342
|
const list = new MessageList({ threadId, resourceId }).add(rawMessages, "memory");
|
|
15343
15343
|
const messages = list.get.all.db();
|
|
15344
|
-
|
|
15344
|
+
const { total, page: resultPage, perPage: resultPerPage, hasMore } = paginatedResult;
|
|
15345
|
+
return { messages, usage, total, page: resultPage, perPage: resultPerPage, hasMore };
|
|
15345
15346
|
}
|
|
15346
15347
|
async getThreadById({ threadId }) {
|
|
15347
15348
|
const memoryStore = await this.getMemoryStore();
|
|
@@ -16096,13 +16097,10 @@ Notes:
|
|
|
16096
16097
|
const memoryStore = await this.getMemoryStore();
|
|
16097
16098
|
const result = await memoryStore.cloneThread(args);
|
|
16098
16099
|
const config = this.getMergedThreadConfig(memoryConfig);
|
|
16099
|
-
|
|
16100
|
-
|
|
16101
|
-
}
|
|
16100
|
+
const sourceThread = await this.getThreadById({ threadId: args.sourceThreadId });
|
|
16101
|
+
const sourceResourceId = sourceThread?.resourceId;
|
|
16102
16102
|
if (config.workingMemory?.enabled) {
|
|
16103
16103
|
const scope = config.workingMemory.scope || "resource";
|
|
16104
|
-
const sourceThread = await this.getThreadById({ threadId: args.sourceThreadId });
|
|
16105
|
-
const sourceResourceId = sourceThread?.resourceId;
|
|
16106
16104
|
const shouldCopy = scope === "thread" || scope === "resource" && args.resourceId && args.resourceId !== sourceResourceId;
|
|
16107
16105
|
if (shouldCopy) {
|
|
16108
16106
|
const sourceWm = await this.getWorkingMemory({
|
|
@@ -16120,8 +16118,109 @@ Notes:
|
|
|
16120
16118
|
}
|
|
16121
16119
|
}
|
|
16122
16120
|
}
|
|
16121
|
+
if (memoryStore.supportsObservationalMemory && sourceResourceId) {
|
|
16122
|
+
try {
|
|
16123
|
+
await this.cloneObservationalMemory(memoryStore, args.sourceThreadId, sourceResourceId, result);
|
|
16124
|
+
} catch (error) {
|
|
16125
|
+
try {
|
|
16126
|
+
await memoryStore.deleteThread({ threadId: result.thread.id });
|
|
16127
|
+
} catch (rollbackError) {
|
|
16128
|
+
this.logger.error("Failed to rollback cloned thread after OM clone failure", rollbackError);
|
|
16129
|
+
}
|
|
16130
|
+
throw error;
|
|
16131
|
+
}
|
|
16132
|
+
}
|
|
16133
|
+
if (this.vector && config.semanticRecall && result.clonedMessages.length > 0) {
|
|
16134
|
+
await this.embedClonedMessages(result.clonedMessages, config);
|
|
16135
|
+
}
|
|
16123
16136
|
return result;
|
|
16124
16137
|
}
|
|
16138
|
+
/**
|
|
16139
|
+
* Clone observational memory records when cloning a thread.
|
|
16140
|
+
* Thread-scoped: always cloned to the new thread.
|
|
16141
|
+
* Resource-scoped: cloned only when the resourceId changes (same resourceId shares OM naturally).
|
|
16142
|
+
* All stored message/thread IDs are remapped to the cloned IDs.
|
|
16143
|
+
*/
|
|
16144
|
+
async cloneObservationalMemory(memoryStore, sourceThreadId, sourceResourceId, result) {
|
|
16145
|
+
let sourceOM = await memoryStore.getObservationalMemory(sourceThreadId, sourceResourceId);
|
|
16146
|
+
if (!sourceOM) {
|
|
16147
|
+
sourceOM = await memoryStore.getObservationalMemory(null, sourceResourceId);
|
|
16148
|
+
}
|
|
16149
|
+
if (!sourceOM) return;
|
|
16150
|
+
const clonedThreadId = result.thread.id;
|
|
16151
|
+
const clonedResourceId = result.thread.resourceId;
|
|
16152
|
+
const resourceChanged = clonedResourceId !== sourceResourceId;
|
|
16153
|
+
if (sourceOM.scope === "resource" && !resourceChanged) return;
|
|
16154
|
+
const messageIdMap = result.messageIdMap ?? {};
|
|
16155
|
+
const hasher = await this.hasher;
|
|
16156
|
+
const cloned = this.remapObservationalMemoryRecord(sourceOM, {
|
|
16157
|
+
newThreadId: sourceOM.scope === "thread" ? clonedThreadId : null,
|
|
16158
|
+
newResourceId: clonedResourceId,
|
|
16159
|
+
messageIdMap,
|
|
16160
|
+
sourceThreadId: resourceChanged ? sourceThreadId : void 0,
|
|
16161
|
+
clonedThreadId: resourceChanged ? clonedThreadId : void 0,
|
|
16162
|
+
hasher: resourceChanged ? hasher : void 0
|
|
16163
|
+
});
|
|
16164
|
+
const now = /* @__PURE__ */ new Date();
|
|
16165
|
+
cloned.id = crypto.randomUUID();
|
|
16166
|
+
cloned.createdAt = now;
|
|
16167
|
+
cloned.updatedAt = now;
|
|
16168
|
+
await memoryStore.insertObservationalMemoryRecord(cloned);
|
|
16169
|
+
}
|
|
16170
|
+
/**
|
|
16171
|
+
* Create a remapped copy of an OM record with new thread/message IDs.
|
|
16172
|
+
*/
|
|
16173
|
+
remapObservationalMemoryRecord(record, opts) {
|
|
16174
|
+
const { newThreadId, newResourceId, messageIdMap, sourceThreadId, clonedThreadId, hasher } = opts;
|
|
16175
|
+
const cloned = { ...record };
|
|
16176
|
+
cloned.threadId = newThreadId;
|
|
16177
|
+
cloned.resourceId = newResourceId;
|
|
16178
|
+
if (Array.isArray(cloned.observedMessageIds)) {
|
|
16179
|
+
cloned.observedMessageIds = cloned.observedMessageIds.map((id) => messageIdMap[id]).filter((id) => Boolean(id));
|
|
16180
|
+
} else {
|
|
16181
|
+
cloned.observedMessageIds = void 0;
|
|
16182
|
+
}
|
|
16183
|
+
if (Array.isArray(cloned.bufferedMessageIds)) {
|
|
16184
|
+
cloned.bufferedMessageIds = cloned.bufferedMessageIds.map((id) => messageIdMap[id]).filter((id) => Boolean(id));
|
|
16185
|
+
} else {
|
|
16186
|
+
cloned.bufferedMessageIds = void 0;
|
|
16187
|
+
}
|
|
16188
|
+
if (Array.isArray(cloned.bufferedObservationChunks)) {
|
|
16189
|
+
cloned.bufferedObservationChunks = cloned.bufferedObservationChunks.map(
|
|
16190
|
+
(chunk) => ({
|
|
16191
|
+
...chunk,
|
|
16192
|
+
messageIds: Array.isArray(chunk.messageIds) ? chunk.messageIds.map((id) => messageIdMap[id]).filter((id) => Boolean(id)) : []
|
|
16193
|
+
})
|
|
16194
|
+
);
|
|
16195
|
+
} else {
|
|
16196
|
+
cloned.bufferedObservationChunks = void 0;
|
|
16197
|
+
}
|
|
16198
|
+
if (sourceThreadId && clonedThreadId && hasher) {
|
|
16199
|
+
const sourceObscured = hasher.h32ToString(sourceThreadId);
|
|
16200
|
+
const clonedObscured = hasher.h32ToString(clonedThreadId);
|
|
16201
|
+
if (sourceObscured !== clonedObscured) {
|
|
16202
|
+
const replaceThreadTags = (text4) => {
|
|
16203
|
+
if (!text4) return text4;
|
|
16204
|
+
return text4.replaceAll(`<thread id="${sourceObscured}">`, `<thread id="${clonedObscured}">`);
|
|
16205
|
+
};
|
|
16206
|
+
cloned.activeObservations = replaceThreadTags(cloned.activeObservations) ?? "";
|
|
16207
|
+
cloned.bufferedReflection = replaceThreadTags(cloned.bufferedReflection);
|
|
16208
|
+
if (cloned.bufferedObservationChunks) {
|
|
16209
|
+
cloned.bufferedObservationChunks = cloned.bufferedObservationChunks.map(
|
|
16210
|
+
(chunk) => ({
|
|
16211
|
+
...chunk,
|
|
16212
|
+
observations: replaceThreadTags(chunk.observations) ?? chunk.observations
|
|
16213
|
+
})
|
|
16214
|
+
);
|
|
16215
|
+
}
|
|
16216
|
+
}
|
|
16217
|
+
}
|
|
16218
|
+
cloned.isObserving = false;
|
|
16219
|
+
cloned.isReflecting = false;
|
|
16220
|
+
cloned.isBufferingObservation = false;
|
|
16221
|
+
cloned.isBufferingReflection = false;
|
|
16222
|
+
return cloned;
|
|
16223
|
+
}
|
|
16125
16224
|
/**
|
|
16126
16225
|
* Embed cloned messages for semantic recall.
|
|
16127
16226
|
* This is similar to the embedding logic in saveMessages but operates on already-saved messages.
|
|
@@ -16354,7 +16453,7 @@ Notes:
|
|
|
16354
16453
|
"Observational memory async buffering is enabled by default but the installed version of @mastra/core does not support it. Either upgrade @mastra/core, @mastra/memory, and your storage adapter (@mastra/libsql, @mastra/pg, or @mastra/mongodb) to the latest version, or explicitly disable async buffering by setting `observation: { bufferTokens: false }` in your observationalMemory config."
|
|
16355
16454
|
);
|
|
16356
16455
|
}
|
|
16357
|
-
const { ObservationalMemory } = await import('./observational-memory-
|
|
16456
|
+
const { ObservationalMemory } = await import('./observational-memory-SR6G4HN5.js');
|
|
16358
16457
|
return new ObservationalMemory({
|
|
16359
16458
|
storage: memoryStore,
|
|
16360
16459
|
scope: omConfig.scope,
|