@mastra/memory 1.19.1-alpha.0 → 1.20.0-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.
- package/CHANGELOG.md +17 -0
- package/dist/{chunk-BCYGTJF2.js → chunk-G72RLVRT.js} +50 -8
- package/dist/chunk-G72RLVRT.js.map +1 -0
- package/dist/{chunk-IRMLP4QH.cjs → chunk-PNKMNTE6.cjs} +49 -7
- package/dist/chunk-PNKMNTE6.cjs.map +1 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +47 -47
- package/dist/docs/references/docs-memory-multi-user-threads.md +1 -1
- package/dist/docs/references/docs-memory-observational-memory.md +2 -2
- package/dist/docs/references/docs-memory-storage.md +1 -1
- package/dist/docs/references/reference-memory-observational-memory.md +1 -1
- package/dist/docs/references/reference-storage-dsql.md +1 -1
- package/dist/docs/references/reference-storage-redis.md +1 -1
- package/dist/index.cjs +15 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -5
- package/dist/index.js.map +1 -1
- package/dist/{observational-memory-RWXMKXJP.cjs → observational-memory-25PDEXBJ.cjs} +26 -26
- package/dist/{observational-memory-RWXMKXJP.cjs.map → observational-memory-25PDEXBJ.cjs.map} +1 -1
- package/dist/{observational-memory-CSI3OZXQ.js → observational-memory-FBSRD6QN.js} +3 -3
- package/dist/{observational-memory-CSI3OZXQ.js.map → observational-memory-FBSRD6QN.js.map} +1 -1
- package/dist/processors/index.cjs +24 -24
- package/dist/processors/index.js +1 -1
- package/dist/processors/observational-memory/message-utils.d.ts +1 -0
- package/dist/processors/observational-memory/message-utils.d.ts.map +1 -1
- package/dist/processors/observational-memory/observation-strategies/async-buffer.d.ts.map +1 -1
- package/dist/processors/observational-memory/observation-strategies/sync.d.ts.map +1 -1
- package/dist/processors/observational-memory/observation-turn/step.d.ts.map +1 -1
- package/dist/processors/observational-memory/observer-runner.d.ts +11 -0
- package/dist/processors/observational-memory/observer-runner.d.ts.map +1 -1
- package/dist/processors/observational-memory/types.d.ts +7 -3
- package/dist/processors/observational-memory/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/dist/chunk-BCYGTJF2.js.map +0 -1
- package/dist/chunk-IRMLP4QH.cjs.map +0 -1
|
@@ -676,6 +676,7 @@ function filterObservedMessages(opts) {
|
|
|
676
676
|
const { messageList, record } = opts;
|
|
677
677
|
const allMessages = messageList.get.all.db();
|
|
678
678
|
const useMarkerBoundaryPruning = opts.useMarkerBoundaryPruning ?? true;
|
|
679
|
+
const preserveMessageIds = opts.preserveMessageIds ?? /* @__PURE__ */ new Set();
|
|
679
680
|
let markerMessageIndex = -1;
|
|
680
681
|
let markerMessage = null;
|
|
681
682
|
for (let i = allMessages.length - 1; i >= 0; i--) {
|
|
@@ -691,7 +692,7 @@ function filterObservedMessages(opts) {
|
|
|
691
692
|
const messagesToRemove = [];
|
|
692
693
|
for (let i = 0; i < markerMessageIndex; i++) {
|
|
693
694
|
const msg = allMessages[i];
|
|
694
|
-
if (msg?.id && msg.id !== "om-continuation") {
|
|
695
|
+
if (msg?.id && msg.id !== "om-continuation" && !preserveMessageIds.has(msg.id)) {
|
|
695
696
|
messagesToRemove.push(msg.id);
|
|
696
697
|
}
|
|
697
698
|
}
|
|
@@ -710,7 +711,7 @@ function filterObservedMessages(opts) {
|
|
|
710
711
|
const lastObservedAt = record.lastObservedAt;
|
|
711
712
|
const messagesToRemove = [];
|
|
712
713
|
for (const msg of allMessages) {
|
|
713
|
-
if (!msg?.id || msg.id === "om-continuation") continue;
|
|
714
|
+
if (!msg?.id || msg.id === "om-continuation" || preserveMessageIds.has(msg.id)) continue;
|
|
714
715
|
if (observedIds.has(msg.id)) {
|
|
715
716
|
messagesToRemove.push(msg.id);
|
|
716
717
|
continue;
|
|
@@ -2276,11 +2277,15 @@ var ObservationStep = class {
|
|
|
2276
2277
|
});
|
|
2277
2278
|
if (!didThresholdCleanup) {
|
|
2278
2279
|
const fallbackCursor = this.turn.record.threadId ? memory.getThreadOMMetadata((await om.getStorage().getThreadById({ threadId: this.turn.record.threadId }))?.metadata)?.lastObservedMessageCursor : void 0;
|
|
2280
|
+
const pendingMessageIds = new Set(
|
|
2281
|
+
[...messageList.get.input.db(), ...messageList.get.response.db()].map((msg) => msg.id).filter(Boolean)
|
|
2282
|
+
);
|
|
2279
2283
|
filterObservedMessages({
|
|
2280
2284
|
messageList,
|
|
2281
2285
|
record: this.turn.record,
|
|
2282
2286
|
useMarkerBoundaryPruning: this.stepNumber === 0,
|
|
2283
|
-
fallbackCursor
|
|
2287
|
+
fallbackCursor,
|
|
2288
|
+
preserveMessageIds: pendingMessageIds
|
|
2284
2289
|
});
|
|
2285
2290
|
}
|
|
2286
2291
|
this._context = {
|
|
@@ -4108,6 +4113,41 @@ var ObserverRunner = class {
|
|
|
4108
4113
|
}
|
|
4109
4114
|
return agent$1;
|
|
4110
4115
|
}
|
|
4116
|
+
/**
|
|
4117
|
+
* Extract a router-style model ID (`provider/model`) from a model config.
|
|
4118
|
+
* Handles strings, LanguageModel objects, and function-based models.
|
|
4119
|
+
*/
|
|
4120
|
+
extractModelRouterId(model, requestContext) {
|
|
4121
|
+
if (typeof model === "string") return model;
|
|
4122
|
+
if (typeof model === "function") {
|
|
4123
|
+
if (!requestContext) return void 0;
|
|
4124
|
+
try {
|
|
4125
|
+
const resolved = model({ requestContext });
|
|
4126
|
+
if (resolved instanceof Promise) return void 0;
|
|
4127
|
+
return this.extractModelRouterId(resolved);
|
|
4128
|
+
} catch {
|
|
4129
|
+
return void 0;
|
|
4130
|
+
}
|
|
4131
|
+
}
|
|
4132
|
+
const obj = model;
|
|
4133
|
+
if (typeof obj.provider === "string" && typeof obj.modelId === "string") {
|
|
4134
|
+
return `${obj.provider}/${obj.modelId}`;
|
|
4135
|
+
}
|
|
4136
|
+
return void 0;
|
|
4137
|
+
}
|
|
4138
|
+
/**
|
|
4139
|
+
* Resolve the attachment filter for a given model. When set to `'auto'`,
|
|
4140
|
+
* the provider capabilities registry is consulted to decide whether the
|
|
4141
|
+
* model accepts multimodal input.
|
|
4142
|
+
*/
|
|
4143
|
+
resolveAttachmentFilter(model, requestContext) {
|
|
4144
|
+
const raw = this.observationConfig.observeAttachments;
|
|
4145
|
+
if (raw !== "auto") return raw;
|
|
4146
|
+
const routerId = this.extractModelRouterId(model, requestContext);
|
|
4147
|
+
if (!routerId) return true;
|
|
4148
|
+
const supports = llm.modelSupportsAttachments(routerId);
|
|
4149
|
+
return supports ?? true;
|
|
4150
|
+
}
|
|
4111
4151
|
async withAbortCheck(fn, abortSignal) {
|
|
4112
4152
|
if (abortSignal?.aborted) {
|
|
4113
4153
|
throw new Error("The operation was aborted.");
|
|
@@ -4125,6 +4165,7 @@ var ObserverRunner = class {
|
|
|
4125
4165
|
const inputTokens = this.tokenCounter.countMessages(messagesToObserve);
|
|
4126
4166
|
const resolvedModel = options?.model ? { model: options.model } : this.resolveModel(inputTokens);
|
|
4127
4167
|
const agent = this.createAgent(resolvedModel.model);
|
|
4168
|
+
const attachmentFilter = this.resolveAttachmentFilter(resolvedModel.model, options?.requestContext);
|
|
4128
4169
|
const observerMessages = [
|
|
4129
4170
|
{
|
|
4130
4171
|
role: "user",
|
|
@@ -4134,7 +4175,7 @@ var ObserverRunner = class {
|
|
|
4134
4175
|
})
|
|
4135
4176
|
},
|
|
4136
4177
|
buildObserverHistoryMessage(messagesToObserve, {
|
|
4137
|
-
attachmentFilter
|
|
4178
|
+
attachmentFilter
|
|
4138
4179
|
})
|
|
4139
4180
|
];
|
|
4140
4181
|
const doGenerate = async () => {
|
|
@@ -4221,6 +4262,7 @@ var ObserverRunner = class {
|
|
|
4221
4262
|
);
|
|
4222
4263
|
const resolvedModel = model ? { model } : this.resolveModel(inputTokens);
|
|
4223
4264
|
const agent = this.createAgent(resolvedModel.model, true);
|
|
4265
|
+
const multiThreadAttachmentFilter = this.resolveAttachmentFilter(resolvedModel.model, requestContext);
|
|
4224
4266
|
const observerMessages = [
|
|
4225
4267
|
{
|
|
4226
4268
|
role: "user",
|
|
@@ -4233,7 +4275,7 @@ var ObserverRunner = class {
|
|
|
4233
4275
|
)
|
|
4234
4276
|
},
|
|
4235
4277
|
buildMultiThreadObserverHistoryMessage(messagesByThread, threadOrder, {
|
|
4236
|
-
attachmentFilter:
|
|
4278
|
+
attachmentFilter: multiThreadAttachmentFilter
|
|
4237
4279
|
})
|
|
4238
4280
|
];
|
|
4239
4281
|
for (const msgs of messagesByThread.values()) {
|
|
@@ -9841,5 +9883,5 @@ exports.stripEphemeralAnchorIds = stripEphemeralAnchorIds;
|
|
|
9841
9883
|
exports.stripObservationGroups = stripObservationGroups;
|
|
9842
9884
|
exports.truncateStringByTokens = truncateStringByTokens;
|
|
9843
9885
|
exports.wrapInObservationGroup = wrapInObservationGroup;
|
|
9844
|
-
//# sourceMappingURL=chunk-
|
|
9845
|
-
//# sourceMappingURL=chunk-
|
|
9886
|
+
//# sourceMappingURL=chunk-PNKMNTE6.cjs.map
|
|
9887
|
+
//# sourceMappingURL=chunk-PNKMNTE6.cjs.map
|