@mastra/memory 1.17.6-alpha.0 → 1.18.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.
- package/CHANGELOG.md +22 -0
- package/dist/{chunk-ZUUSLGY6.cjs → chunk-MJNTQ6GP.cjs} +84 -31
- package/dist/chunk-MJNTQ6GP.cjs.map +1 -0
- package/dist/{chunk-NUYSX3DD.js → chunk-PBZHHKPE.js} +84 -31
- package/dist/chunk-PBZHHKPE.js.map +1 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +39 -39
- package/dist/docs/references/docs-agents-background-tasks.md +62 -2
- package/dist/docs/references/docs-memory-observational-memory.md +7 -2
- package/dist/docs/references/docs-memory-overview.md +2 -1
- package/dist/docs/references/docs-memory-semantic-recall.md +68 -6
- package/dist/index.cjs +329 -177
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +320 -168
- package/dist/index.js.map +1 -1
- package/dist/{observational-memory-KH7G7Y6B.js → observational-memory-IP2RVQQG.js} +3 -3
- package/dist/{observational-memory-KH7G7Y6B.js.map → observational-memory-IP2RVQQG.js.map} +1 -1
- package/dist/{observational-memory-BOXSRJOR.cjs → observational-memory-TASIB4PH.cjs} +26 -26
- package/dist/{observational-memory-BOXSRJOR.cjs.map → observational-memory-TASIB4PH.cjs.map} +1 -1
- package/dist/processors/index.cjs +24 -24
- package/dist/processors/index.js +1 -1
- package/dist/processors/observational-memory/observation-strategies/resource-scoped.d.ts.map +1 -1
- package/dist/processors/observational-memory/observation-turn/load-memory-context.d.ts +9 -0
- package/dist/processors/observational-memory/observation-turn/load-memory-context.d.ts.map +1 -0
- package/dist/processors/observational-memory/observation-turn/turn.d.ts.map +1 -1
- package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -1
- package/dist/processors/observational-memory/processor.d.ts.map +1 -1
- package/package.json +4 -4
- package/dist/chunk-NUYSX3DD.js.map +0 -1
- package/dist/chunk-ZUUSLGY6.cjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @mastra/memory
|
|
2
2
|
|
|
3
|
+
## 1.18.0-alpha.2
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Add metadata filtering support to semantic recall. ([#9256](https://github.com/mastra-ai/mastra/pull/9256))
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Fixed read-only observational memory so existing context is still loaded. ([#16059](https://github.com/mastra-ai/mastra/pull/16059))
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [[`6742347`](https://github.com/mastra-ai/mastra/commit/6742347d71955d7639adc9ddf6ff8282de7ee3ba), [`7b0ad1f`](https://github.com/mastra-ai/mastra/commit/7b0ad1f5c53dc118c6da12ae82ae2587037dc2b8), [`62666c3`](https://github.com/mastra-ai/mastra/commit/62666c367eaeac3941ead454b1d38810cc855721), [`4af2160`](https://github.com/mastra-ai/mastra/commit/4af2160322f4718cac421930cce85641e9512389), [`136c959`](https://github.com/mastra-ai/mastra/commit/136c9592fb0eeb0cd212f28629d8a29b7557a2fc), [`4df7cc7`](https://github.com/mastra-ai/mastra/commit/4df7cc79342fd065fe7fdeef93c094db14b12bcd), [`aca3121`](https://github.com/mastra-ai/mastra/commit/aca31211233dac25459f140ea4fcfb3a5af64c18), [`9cdf38e`](https://github.com/mastra-ai/mastra/commit/9cdf38e58506e1109c8b38f97cd7770978a4218e), [`990851e`](https://github.com/mastra-ai/mastra/commit/990851edcb0e30be5c2c18b6532f1a876cc2d335), [`6068a6c`](https://github.com/mastra-ai/mastra/commit/6068a6c42950fad3ebfc92346417896ba60803d2), [`00106be`](https://github.com/mastra-ai/mastra/commit/00106bede59b81e5b0e9cd6aad8d3b5dbc336387), [`e2a079c`](https://github.com/mastra-ai/mastra/commit/e2a079cc3755b1895f7bd5dc36e9be81b11c7c22), [`534a456`](https://github.com/mastra-ai/mastra/commit/534a456a25e4df1e5407e7e632f4cb3b1fa14f9d), [`36bae07`](https://github.com/mastra-ai/mastra/commit/36bae07c0e70b1b3006f2fd20830e8883dcbd066)]:
|
|
14
|
+
- @mastra/core@1.33.0-alpha.7
|
|
15
|
+
|
|
16
|
+
## 1.17.6-alpha.1
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- Added extra defensive checks to prevent edge cases where system messages may have already been stored in message history. ([#15787](https://github.com/mastra-ai/mastra/pull/15787))
|
|
21
|
+
|
|
22
|
+
- Updated dependencies [[`b560d6f`](https://github.com/mastra-ai/mastra/commit/b560d6f88b9b904b15c10f75c949eb145bc27684), [`36b3bbf`](https://github.com/mastra-ai/mastra/commit/36b3bbf5a8d59f7e23d47e29340e76c681b4929c), [`b275631`](https://github.com/mastra-ai/mastra/commit/b275631dc10541a482b2e2d4a3e3cfa843bd5fa1)]:
|
|
23
|
+
- @mastra/core@1.33.0-alpha.6
|
|
24
|
+
|
|
3
25
|
## 1.17.6-alpha.0
|
|
4
26
|
|
|
5
27
|
### Patch Changes
|
|
@@ -1696,8 +1696,9 @@ var ResourceScopedObservationStrategy = class extends ObservationStrategy {
|
|
|
1696
1696
|
orderBy: { field: "createdAt", direction: "ASC" },
|
|
1697
1697
|
filter: startDate ? { dateRange: { start: startDate } } : void 0
|
|
1698
1698
|
});
|
|
1699
|
-
|
|
1700
|
-
|
|
1699
|
+
const messages = result.messages.filter((msg) => msg.role !== "system");
|
|
1700
|
+
if (messages.length > 0) {
|
|
1701
|
+
this.messagesByThread.set(thread.id, messages);
|
|
1701
1702
|
}
|
|
1702
1703
|
}
|
|
1703
1704
|
if (currentThreadMessages.length > 0) {
|
|
@@ -2028,6 +2029,22 @@ ObservationStrategy.create = ((om, opts) => {
|
|
|
2028
2029
|
if (deps.scope === "resource" && opts.resourceId) return new ResourceScopedObservationStrategy(deps, opts);
|
|
2029
2030
|
return new SyncObservationStrategy(deps, opts);
|
|
2030
2031
|
});
|
|
2032
|
+
|
|
2033
|
+
// src/processors/observational-memory/observation-turn/load-memory-context.ts
|
|
2034
|
+
async function loadMemoryContextMessages({
|
|
2035
|
+
memory,
|
|
2036
|
+
messageList,
|
|
2037
|
+
threadId,
|
|
2038
|
+
resourceId
|
|
2039
|
+
}) {
|
|
2040
|
+
const ctx = await memory.getContext({ threadId, resourceId });
|
|
2041
|
+
for (const msg of ctx.messages) {
|
|
2042
|
+
if (msg.role !== "system") {
|
|
2043
|
+
messageList.add(msg, "memory");
|
|
2044
|
+
}
|
|
2045
|
+
}
|
|
2046
|
+
return ctx;
|
|
2047
|
+
}
|
|
2031
2048
|
var ObservationStep = class {
|
|
2032
2049
|
constructor(turn, stepNumber) {
|
|
2033
2050
|
this.turn = turn;
|
|
@@ -2395,12 +2412,12 @@ var ObservationTurn = class {
|
|
|
2395
2412
|
this._generationCountAtStart = this._record.generationCount;
|
|
2396
2413
|
this.memory = memory;
|
|
2397
2414
|
if (memory) {
|
|
2398
|
-
const ctx = await
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
}
|
|
2415
|
+
const ctx = await loadMemoryContextMessages({
|
|
2416
|
+
memory,
|
|
2417
|
+
messageList: this.messageList,
|
|
2418
|
+
threadId: this.threadId,
|
|
2419
|
+
resourceId: this.resourceId
|
|
2420
|
+
});
|
|
2404
2421
|
this._context = {
|
|
2405
2422
|
messages: ctx.messages,
|
|
2406
2423
|
systemMessage: ctx.systemMessage,
|
|
@@ -7426,6 +7443,9 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
|
|
|
7426
7443
|
}
|
|
7427
7444
|
const result = [];
|
|
7428
7445
|
for (const msg of allMessages) {
|
|
7446
|
+
if (msg.role === "system") {
|
|
7447
|
+
continue;
|
|
7448
|
+
}
|
|
7429
7449
|
if (observedMessageIds?.has(msg.id)) {
|
|
7430
7450
|
continue;
|
|
7431
7451
|
}
|
|
@@ -7736,7 +7756,7 @@ ${suggestedResponse}
|
|
|
7736
7756
|
} : void 0
|
|
7737
7757
|
});
|
|
7738
7758
|
}
|
|
7739
|
-
return result.messages;
|
|
7759
|
+
return result.messages.filter((msg) => msg.role !== "system");
|
|
7740
7760
|
}
|
|
7741
7761
|
/**
|
|
7742
7762
|
* Format unobserved messages from other threads as <unobserved-context> blocks.
|
|
@@ -9219,6 +9239,33 @@ var GATEWAY_STATE_KEY = "__isGatewayModel";
|
|
|
9219
9239
|
function isMastraGatewayModel(model) {
|
|
9220
9240
|
return typeof model === "object" && model !== null && "gatewayId" in model && model.gatewayId === "mastra";
|
|
9221
9241
|
}
|
|
9242
|
+
function injectObservationContextMessages({
|
|
9243
|
+
messageList,
|
|
9244
|
+
systemMessages,
|
|
9245
|
+
continuationMessage,
|
|
9246
|
+
threadId,
|
|
9247
|
+
resourceId
|
|
9248
|
+
}) {
|
|
9249
|
+
if (!systemMessages?.length) {
|
|
9250
|
+
return;
|
|
9251
|
+
}
|
|
9252
|
+
messageList.clearSystemMessages("observational-memory");
|
|
9253
|
+
for (const msg of systemMessages) {
|
|
9254
|
+
messageList.addSystem(msg, "observational-memory");
|
|
9255
|
+
}
|
|
9256
|
+
const contMsg = continuationMessage ?? {
|
|
9257
|
+
id: "om-continuation",
|
|
9258
|
+
role: "user",
|
|
9259
|
+
createdAt: /* @__PURE__ */ new Date(0),
|
|
9260
|
+
content: {
|
|
9261
|
+
format: 2,
|
|
9262
|
+
parts: [{ type: "text", text: `<system-reminder>${chunkD4J4XPGM_cjs.OBSERVATION_CONTINUATION_HINT}</system-reminder>` }]
|
|
9263
|
+
},
|
|
9264
|
+
threadId,
|
|
9265
|
+
resourceId
|
|
9266
|
+
};
|
|
9267
|
+
messageList.add(contMsg, "memory");
|
|
9268
|
+
}
|
|
9222
9269
|
var ObservationalMemoryProcessor = class {
|
|
9223
9270
|
id = "observational-memory";
|
|
9224
9271
|
name = "Observational Memory";
|
|
@@ -9273,6 +9320,25 @@ var ObservationalMemoryProcessor = class {
|
|
|
9273
9320
|
const preMessagesSnapshot = reproCaptureEnabled ? safeCaptureJson(messageList.get.all.db()) : null;
|
|
9274
9321
|
const preSerializedMessageList = reproCaptureEnabled ? safeCaptureJson(messageList.serialize()) : null;
|
|
9275
9322
|
if (readOnly) {
|
|
9323
|
+
const ctx = await loadMemoryContextMessages({
|
|
9324
|
+
memory: this.memory,
|
|
9325
|
+
messageList,
|
|
9326
|
+
threadId,
|
|
9327
|
+
resourceId
|
|
9328
|
+
});
|
|
9329
|
+
const systemMessages = ctx.hasObservations && ctx.omRecord ? await this.engine.buildContextSystemMessages({
|
|
9330
|
+
threadId,
|
|
9331
|
+
resourceId,
|
|
9332
|
+
record: ctx.omRecord,
|
|
9333
|
+
unobservedContextBlocks: ctx.otherThreadsContext
|
|
9334
|
+
}) : void 0;
|
|
9335
|
+
injectObservationContextMessages({
|
|
9336
|
+
messageList,
|
|
9337
|
+
systemMessages,
|
|
9338
|
+
continuationMessage: ctx.continuationMessage,
|
|
9339
|
+
threadId,
|
|
9340
|
+
resourceId
|
|
9341
|
+
});
|
|
9276
9342
|
return messageList;
|
|
9277
9343
|
}
|
|
9278
9344
|
const activeTurn = state.__omTurn ?? this.turn;
|
|
@@ -9328,26 +9394,13 @@ var ObservationalMemoryProcessor = class {
|
|
|
9328
9394
|
}
|
|
9329
9395
|
throw err;
|
|
9330
9396
|
}
|
|
9331
|
-
|
|
9332
|
-
messageList
|
|
9333
|
-
|
|
9334
|
-
|
|
9335
|
-
|
|
9336
|
-
|
|
9337
|
-
|
|
9338
|
-
role: "user",
|
|
9339
|
-
createdAt: /* @__PURE__ */ new Date(0),
|
|
9340
|
-
content: {
|
|
9341
|
-
format: 2,
|
|
9342
|
-
parts: [
|
|
9343
|
-
{ type: "text", text: `<system-reminder>${chunkD4J4XPGM_cjs.OBSERVATION_CONTINUATION_HINT}</system-reminder>` }
|
|
9344
|
-
]
|
|
9345
|
-
},
|
|
9346
|
-
threadId,
|
|
9347
|
-
resourceId
|
|
9348
|
-
};
|
|
9349
|
-
messageList.add(contMsg, "memory");
|
|
9350
|
-
}
|
|
9397
|
+
injectObservationContextMessages({
|
|
9398
|
+
messageList,
|
|
9399
|
+
systemMessages: ctx.systemMessage,
|
|
9400
|
+
continuationMessage: this.turn.context.continuation,
|
|
9401
|
+
threadId,
|
|
9402
|
+
resourceId
|
|
9403
|
+
});
|
|
9351
9404
|
const freshRecord = await this.engine.getOrCreateRecord(threadId, resourceId);
|
|
9352
9405
|
await this.engine.emitProgress({
|
|
9353
9406
|
record: freshRecord,
|
|
@@ -9473,5 +9526,5 @@ exports.stripEphemeralAnchorIds = stripEphemeralAnchorIds;
|
|
|
9473
9526
|
exports.stripObservationGroups = stripObservationGroups;
|
|
9474
9527
|
exports.truncateStringByTokens = truncateStringByTokens;
|
|
9475
9528
|
exports.wrapInObservationGroup = wrapInObservationGroup;
|
|
9476
|
-
//# sourceMappingURL=chunk-
|
|
9477
|
-
//# sourceMappingURL=chunk-
|
|
9529
|
+
//# sourceMappingURL=chunk-MJNTQ6GP.cjs.map
|
|
9530
|
+
//# sourceMappingURL=chunk-MJNTQ6GP.cjs.map
|