@mastra/memory 1.17.6-alpha.1 → 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 CHANGED
@@ -1,5 +1,18 @@
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
+
3
16
  ## 1.17.6-alpha.1
4
17
 
5
18
  ### Patch Changes
@@ -2029,6 +2029,22 @@ ObservationStrategy.create = ((om, opts) => {
2029
2029
  if (deps.scope === "resource" && opts.resourceId) return new ResourceScopedObservationStrategy(deps, opts);
2030
2030
  return new SyncObservationStrategy(deps, opts);
2031
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
+ }
2032
2048
  var ObservationStep = class {
2033
2049
  constructor(turn, stepNumber) {
2034
2050
  this.turn = turn;
@@ -2396,12 +2412,12 @@ var ObservationTurn = class {
2396
2412
  this._generationCountAtStart = this._record.generationCount;
2397
2413
  this.memory = memory;
2398
2414
  if (memory) {
2399
- const ctx = await memory.getContext({ threadId: this.threadId, resourceId: this.resourceId });
2400
- for (const msg of ctx.messages) {
2401
- if (msg.role !== "system") {
2402
- this.messageList.add(msg, "memory");
2403
- }
2404
- }
2415
+ const ctx = await loadMemoryContextMessages({
2416
+ memory,
2417
+ messageList: this.messageList,
2418
+ threadId: this.threadId,
2419
+ resourceId: this.resourceId
2420
+ });
2405
2421
  this._context = {
2406
2422
  messages: ctx.messages,
2407
2423
  systemMessage: ctx.systemMessage,
@@ -9223,6 +9239,33 @@ var GATEWAY_STATE_KEY = "__isGatewayModel";
9223
9239
  function isMastraGatewayModel(model) {
9224
9240
  return typeof model === "object" && model !== null && "gatewayId" in model && model.gatewayId === "mastra";
9225
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
+ }
9226
9269
  var ObservationalMemoryProcessor = class {
9227
9270
  id = "observational-memory";
9228
9271
  name = "Observational Memory";
@@ -9277,6 +9320,25 @@ var ObservationalMemoryProcessor = class {
9277
9320
  const preMessagesSnapshot = reproCaptureEnabled ? safeCaptureJson(messageList.get.all.db()) : null;
9278
9321
  const preSerializedMessageList = reproCaptureEnabled ? safeCaptureJson(messageList.serialize()) : null;
9279
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
+ });
9280
9342
  return messageList;
9281
9343
  }
9282
9344
  const activeTurn = state.__omTurn ?? this.turn;
@@ -9332,26 +9394,13 @@ var ObservationalMemoryProcessor = class {
9332
9394
  }
9333
9395
  throw err;
9334
9396
  }
9335
- if (ctx.systemMessage) {
9336
- messageList.clearSystemMessages("observational-memory");
9337
- for (const msg of ctx.systemMessage) {
9338
- messageList.addSystem(msg, "observational-memory");
9339
- }
9340
- const contMsg = this.turn.context.continuation ?? {
9341
- id: "om-continuation",
9342
- role: "user",
9343
- createdAt: /* @__PURE__ */ new Date(0),
9344
- content: {
9345
- format: 2,
9346
- parts: [
9347
- { type: "text", text: `<system-reminder>${chunkD4J4XPGM_cjs.OBSERVATION_CONTINUATION_HINT}</system-reminder>` }
9348
- ]
9349
- },
9350
- threadId,
9351
- resourceId
9352
- };
9353
- messageList.add(contMsg, "memory");
9354
- }
9397
+ injectObservationContextMessages({
9398
+ messageList,
9399
+ systemMessages: ctx.systemMessage,
9400
+ continuationMessage: this.turn.context.continuation,
9401
+ threadId,
9402
+ resourceId
9403
+ });
9355
9404
  const freshRecord = await this.engine.getOrCreateRecord(threadId, resourceId);
9356
9405
  await this.engine.emitProgress({
9357
9406
  record: freshRecord,
@@ -9477,5 +9526,5 @@ exports.stripEphemeralAnchorIds = stripEphemeralAnchorIds;
9477
9526
  exports.stripObservationGroups = stripObservationGroups;
9478
9527
  exports.truncateStringByTokens = truncateStringByTokens;
9479
9528
  exports.wrapInObservationGroup = wrapInObservationGroup;
9480
- //# sourceMappingURL=chunk-WNLFJKTX.cjs.map
9481
- //# sourceMappingURL=chunk-WNLFJKTX.cjs.map
9529
+ //# sourceMappingURL=chunk-MJNTQ6GP.cjs.map
9530
+ //# sourceMappingURL=chunk-MJNTQ6GP.cjs.map