@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
|
@@ -1689,8 +1689,9 @@ var ResourceScopedObservationStrategy = class extends ObservationStrategy {
|
|
|
1689
1689
|
orderBy: { field: "createdAt", direction: "ASC" },
|
|
1690
1690
|
filter: startDate ? { dateRange: { start: startDate } } : void 0
|
|
1691
1691
|
});
|
|
1692
|
-
|
|
1693
|
-
|
|
1692
|
+
const messages = result.messages.filter((msg) => msg.role !== "system");
|
|
1693
|
+
if (messages.length > 0) {
|
|
1694
|
+
this.messagesByThread.set(thread.id, messages);
|
|
1694
1695
|
}
|
|
1695
1696
|
}
|
|
1696
1697
|
if (currentThreadMessages.length > 0) {
|
|
@@ -2021,6 +2022,22 @@ ObservationStrategy.create = ((om, opts) => {
|
|
|
2021
2022
|
if (deps.scope === "resource" && opts.resourceId) return new ResourceScopedObservationStrategy(deps, opts);
|
|
2022
2023
|
return new SyncObservationStrategy(deps, opts);
|
|
2023
2024
|
});
|
|
2025
|
+
|
|
2026
|
+
// src/processors/observational-memory/observation-turn/load-memory-context.ts
|
|
2027
|
+
async function loadMemoryContextMessages({
|
|
2028
|
+
memory,
|
|
2029
|
+
messageList,
|
|
2030
|
+
threadId,
|
|
2031
|
+
resourceId
|
|
2032
|
+
}) {
|
|
2033
|
+
const ctx = await memory.getContext({ threadId, resourceId });
|
|
2034
|
+
for (const msg of ctx.messages) {
|
|
2035
|
+
if (msg.role !== "system") {
|
|
2036
|
+
messageList.add(msg, "memory");
|
|
2037
|
+
}
|
|
2038
|
+
}
|
|
2039
|
+
return ctx;
|
|
2040
|
+
}
|
|
2024
2041
|
var ObservationStep = class {
|
|
2025
2042
|
constructor(turn, stepNumber) {
|
|
2026
2043
|
this.turn = turn;
|
|
@@ -2388,12 +2405,12 @@ var ObservationTurn = class {
|
|
|
2388
2405
|
this._generationCountAtStart = this._record.generationCount;
|
|
2389
2406
|
this.memory = memory;
|
|
2390
2407
|
if (memory) {
|
|
2391
|
-
const ctx = await
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
}
|
|
2408
|
+
const ctx = await loadMemoryContextMessages({
|
|
2409
|
+
memory,
|
|
2410
|
+
messageList: this.messageList,
|
|
2411
|
+
threadId: this.threadId,
|
|
2412
|
+
resourceId: this.resourceId
|
|
2413
|
+
});
|
|
2397
2414
|
this._context = {
|
|
2398
2415
|
messages: ctx.messages,
|
|
2399
2416
|
systemMessage: ctx.systemMessage,
|
|
@@ -7419,6 +7436,9 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
|
|
|
7419
7436
|
}
|
|
7420
7437
|
const result = [];
|
|
7421
7438
|
for (const msg of allMessages) {
|
|
7439
|
+
if (msg.role === "system") {
|
|
7440
|
+
continue;
|
|
7441
|
+
}
|
|
7422
7442
|
if (observedMessageIds?.has(msg.id)) {
|
|
7423
7443
|
continue;
|
|
7424
7444
|
}
|
|
@@ -7729,7 +7749,7 @@ ${suggestedResponse}
|
|
|
7729
7749
|
} : void 0
|
|
7730
7750
|
});
|
|
7731
7751
|
}
|
|
7732
|
-
return result.messages;
|
|
7752
|
+
return result.messages.filter((msg) => msg.role !== "system");
|
|
7733
7753
|
}
|
|
7734
7754
|
/**
|
|
7735
7755
|
* Format unobserved messages from other threads as <unobserved-context> blocks.
|
|
@@ -9212,6 +9232,33 @@ var GATEWAY_STATE_KEY = "__isGatewayModel";
|
|
|
9212
9232
|
function isMastraGatewayModel(model) {
|
|
9213
9233
|
return typeof model === "object" && model !== null && "gatewayId" in model && model.gatewayId === "mastra";
|
|
9214
9234
|
}
|
|
9235
|
+
function injectObservationContextMessages({
|
|
9236
|
+
messageList,
|
|
9237
|
+
systemMessages,
|
|
9238
|
+
continuationMessage,
|
|
9239
|
+
threadId,
|
|
9240
|
+
resourceId
|
|
9241
|
+
}) {
|
|
9242
|
+
if (!systemMessages?.length) {
|
|
9243
|
+
return;
|
|
9244
|
+
}
|
|
9245
|
+
messageList.clearSystemMessages("observational-memory");
|
|
9246
|
+
for (const msg of systemMessages) {
|
|
9247
|
+
messageList.addSystem(msg, "observational-memory");
|
|
9248
|
+
}
|
|
9249
|
+
const contMsg = continuationMessage ?? {
|
|
9250
|
+
id: "om-continuation",
|
|
9251
|
+
role: "user",
|
|
9252
|
+
createdAt: /* @__PURE__ */ new Date(0),
|
|
9253
|
+
content: {
|
|
9254
|
+
format: 2,
|
|
9255
|
+
parts: [{ type: "text", text: `<system-reminder>${OBSERVATION_CONTINUATION_HINT}</system-reminder>` }]
|
|
9256
|
+
},
|
|
9257
|
+
threadId,
|
|
9258
|
+
resourceId
|
|
9259
|
+
};
|
|
9260
|
+
messageList.add(contMsg, "memory");
|
|
9261
|
+
}
|
|
9215
9262
|
var ObservationalMemoryProcessor = class {
|
|
9216
9263
|
id = "observational-memory";
|
|
9217
9264
|
name = "Observational Memory";
|
|
@@ -9266,6 +9313,25 @@ var ObservationalMemoryProcessor = class {
|
|
|
9266
9313
|
const preMessagesSnapshot = reproCaptureEnabled ? safeCaptureJson(messageList.get.all.db()) : null;
|
|
9267
9314
|
const preSerializedMessageList = reproCaptureEnabled ? safeCaptureJson(messageList.serialize()) : null;
|
|
9268
9315
|
if (readOnly) {
|
|
9316
|
+
const ctx = await loadMemoryContextMessages({
|
|
9317
|
+
memory: this.memory,
|
|
9318
|
+
messageList,
|
|
9319
|
+
threadId,
|
|
9320
|
+
resourceId
|
|
9321
|
+
});
|
|
9322
|
+
const systemMessages = ctx.hasObservations && ctx.omRecord ? await this.engine.buildContextSystemMessages({
|
|
9323
|
+
threadId,
|
|
9324
|
+
resourceId,
|
|
9325
|
+
record: ctx.omRecord,
|
|
9326
|
+
unobservedContextBlocks: ctx.otherThreadsContext
|
|
9327
|
+
}) : void 0;
|
|
9328
|
+
injectObservationContextMessages({
|
|
9329
|
+
messageList,
|
|
9330
|
+
systemMessages,
|
|
9331
|
+
continuationMessage: ctx.continuationMessage,
|
|
9332
|
+
threadId,
|
|
9333
|
+
resourceId
|
|
9334
|
+
});
|
|
9269
9335
|
return messageList;
|
|
9270
9336
|
}
|
|
9271
9337
|
const activeTurn = state.__omTurn ?? this.turn;
|
|
@@ -9321,26 +9387,13 @@ var ObservationalMemoryProcessor = class {
|
|
|
9321
9387
|
}
|
|
9322
9388
|
throw err;
|
|
9323
9389
|
}
|
|
9324
|
-
|
|
9325
|
-
messageList
|
|
9326
|
-
|
|
9327
|
-
|
|
9328
|
-
|
|
9329
|
-
|
|
9330
|
-
|
|
9331
|
-
role: "user",
|
|
9332
|
-
createdAt: /* @__PURE__ */ new Date(0),
|
|
9333
|
-
content: {
|
|
9334
|
-
format: 2,
|
|
9335
|
-
parts: [
|
|
9336
|
-
{ type: "text", text: `<system-reminder>${OBSERVATION_CONTINUATION_HINT}</system-reminder>` }
|
|
9337
|
-
]
|
|
9338
|
-
},
|
|
9339
|
-
threadId,
|
|
9340
|
-
resourceId
|
|
9341
|
-
};
|
|
9342
|
-
messageList.add(contMsg, "memory");
|
|
9343
|
-
}
|
|
9390
|
+
injectObservationContextMessages({
|
|
9391
|
+
messageList,
|
|
9392
|
+
systemMessages: ctx.systemMessage,
|
|
9393
|
+
continuationMessage: this.turn.context.continuation,
|
|
9394
|
+
threadId,
|
|
9395
|
+
resourceId
|
|
9396
|
+
});
|
|
9344
9397
|
const freshRecord = await this.engine.getOrCreateRecord(threadId, resourceId);
|
|
9345
9398
|
await this.engine.emitProgress({
|
|
9346
9399
|
record: freshRecord,
|
|
@@ -9441,5 +9494,5 @@ function getObservationsAsOf(activeObservations, asOf) {
|
|
|
9441
9494
|
}
|
|
9442
9495
|
|
|
9443
9496
|
export { ModelByInputTokens, OBSERVER_SYSTEM_PROMPT, ObservationalMemory, ObservationalMemoryProcessor, TokenCounter, buildObserverPrompt, buildObserverSystemPrompt, combineObservationGroupRanges, deriveObservationGroupProvenance, extractCurrentTask, formatMessagesForObserver, formatToolResultForObserver, getObservationsAsOf, hasCurrentTaskSection, injectAnchorIds, optimizeObservationsForContext, parseAnchorId, parseObservationGroups, parseObserverOutput, reconcileObservationGroupsFromReflection, renderObservationGroupsForReflection, resolveToolResultValue, stripEphemeralAnchorIds, stripObservationGroups, truncateStringByTokens, wrapInObservationGroup };
|
|
9444
|
-
//# sourceMappingURL=chunk-
|
|
9445
|
-
//# sourceMappingURL=chunk-
|
|
9497
|
+
//# sourceMappingURL=chunk-PBZHHKPE.js.map
|
|
9498
|
+
//# sourceMappingURL=chunk-PBZHHKPE.js.map
|