@mastra/memory 1.17.6-alpha.1 → 1.18.0-alpha.3

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.
Files changed (32) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/dist/{chunk-WNLFJKTX.cjs → chunk-ET2TVAT3.cjs} +84 -33
  3. package/dist/chunk-ET2TVAT3.cjs.map +1 -0
  4. package/dist/{chunk-QZGJY67D.js → chunk-XVVCS6R6.js} +84 -33
  5. package/dist/chunk-XVVCS6R6.js.map +1 -0
  6. package/dist/docs/SKILL.md +1 -1
  7. package/dist/docs/assets/SOURCE_MAP.json +39 -39
  8. package/dist/docs/references/docs-memory-observational-memory.md +56 -12
  9. package/dist/docs/references/docs-memory-semantic-recall.md +68 -6
  10. package/dist/docs/references/reference-memory-observational-memory.md +11 -1
  11. package/dist/index.cjs +49 -20
  12. package/dist/index.cjs.map +1 -1
  13. package/dist/index.d.ts +2 -1
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +40 -11
  16. package/dist/index.js.map +1 -1
  17. package/dist/{observational-memory-HAJ3K5JJ.js → observational-memory-2PRVG6BF.js} +3 -3
  18. package/dist/{observational-memory-HAJ3K5JJ.js.map → observational-memory-2PRVG6BF.js.map} +1 -1
  19. package/dist/{observational-memory-BJF72NKJ.cjs → observational-memory-UJUAQKJB.cjs} +26 -26
  20. package/dist/{observational-memory-BJF72NKJ.cjs.map → observational-memory-UJUAQKJB.cjs.map} +1 -1
  21. package/dist/processors/index.cjs +24 -24
  22. package/dist/processors/index.js +1 -1
  23. package/dist/processors/observational-memory/observation-turn/load-memory-context.d.ts +9 -0
  24. package/dist/processors/observational-memory/observation-turn/load-memory-context.d.ts.map +1 -0
  25. package/dist/processors/observational-memory/observation-turn/turn.d.ts.map +1 -1
  26. package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -1
  27. package/dist/processors/observational-memory/processor.d.ts.map +1 -1
  28. package/dist/processors/observational-memory/types.d.ts +35 -4
  29. package/dist/processors/observational-memory/types.d.ts.map +1 -1
  30. package/package.json +5 -5
  31. package/dist/chunk-QZGJY67D.js.map +0 -1
  32. package/dist/chunk-WNLFJKTX.cjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # @mastra/memory
2
2
 
3
+ ## 1.18.0-alpha.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Default top-level observational memory early activation settings to observations only, while allowing per-phase overrides under `observation` and `reflection`. ([#16367](https://github.com/mastra-ai/mastra/pull/16367))
8
+
9
+ - Updated dependencies [[`7c275a8`](https://github.com/mastra-ai/mastra/commit/7c275a810595e1a6c41ccc39720531ab65734700), [`890b24c`](https://github.com/mastra-ai/mastra/commit/890b24cc7d32ed6aa4dfe253e54dc6bf4099f690), [`0f48ebf`](https://github.com/mastra-ai/mastra/commit/0f48ebfc7ac7897b2092a189f45751924cf56d1c), [`f180e49`](https://github.com/mastra-ai/mastra/commit/f180e4990e71b04c9a475b523584071712f0048f), [`9260e01`](https://github.com/mastra-ai/mastra/commit/9260e015276fb1b500f7878ee452b47476bf1583), [`2f6c54e`](https://github.com/mastra-ai/mastra/commit/2f6c54e17c041cac1def54baaa6b771647836414), [`e06a159`](https://github.com/mastra-ai/mastra/commit/e06a1598ca07a6c3778aefc2a2d288363c6294ff), [`c50ebc3`](https://github.com/mastra-ai/mastra/commit/c50ebc34da71044558315735e69bfb94fcfb74bf), [`db34bc6`](https://github.com/mastra-ai/mastra/commit/db34bc6fb36cf125bda0c46be4d3fdc774b70cc4)]:
10
+ - @mastra/core@1.33.0-alpha.8
11
+ - @mastra/schema-compat@1.2.10-alpha.0
12
+
13
+ ## 1.18.0-alpha.2
14
+
15
+ ### Minor Changes
16
+
17
+ - Add metadata filtering support to semantic recall. ([#9256](https://github.com/mastra-ai/mastra/pull/9256))
18
+
19
+ ### Patch Changes
20
+
21
+ - Fixed read-only observational memory so existing context is still loaded. ([#16059](https://github.com/mastra-ai/mastra/pull/16059))
22
+
23
+ - 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)]:
24
+ - @mastra/core@1.33.0-alpha.7
25
+
3
26
  ## 1.17.6-alpha.1
4
27
 
5
28
  ### 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,
@@ -6650,7 +6666,7 @@ function getCurrentModel2(model) {
6650
6666
  return formatModelContext2(model?.provider, model?.modelId);
6651
6667
  }
6652
6668
  function parseActivationTTL(value, fieldPath) {
6653
- if (value === void 0) {
6669
+ if (value === void 0 || value === false) {
6654
6670
  return void 0;
6655
6671
  }
6656
6672
  if (typeof value === "number") {
@@ -6798,6 +6814,8 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
6798
6814
  );
6799
6815
  }
6800
6816
  }
6817
+ const observationActivateAfterIdle = config.observation?.activateAfterIdle ?? config.activateAfterIdle;
6818
+ const observationActivateAfterIdlePath = config.observation?.activateAfterIdle !== void 0 ? "observation.activateAfterIdle" : "activateAfterIdle";
6801
6819
  this.observationConfig = {
6802
6820
  model: observationModel,
6803
6821
  // When shared budget, store as range: min = base threshold, max = total budget
@@ -6815,8 +6833,8 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
6815
6833
  config.observation?.messageTokens ?? chunkD4J4XPGM_cjs.OBSERVATIONAL_MEMORY_DEFAULTS.observation.messageTokens
6816
6834
  ),
6817
6835
  bufferActivation: asyncBufferingDisabled ? void 0 : config.observation?.bufferActivation ?? chunkD4J4XPGM_cjs.OBSERVATIONAL_MEMORY_DEFAULTS.observation.bufferActivation,
6818
- activateAfterIdle: parseActivationTTL(config.activateAfterIdle, "activateAfterIdle"),
6819
- activateOnProviderChange: config.activateOnProviderChange ?? false,
6836
+ activateAfterIdle: parseActivationTTL(observationActivateAfterIdle, observationActivateAfterIdlePath),
6837
+ activateOnProviderChange: config.observation?.activateOnProviderChange ?? config.activateOnProviderChange ?? false,
6820
6838
  blockAfter: asyncBufferingDisabled ? void 0 : resolveBlockAfter(
6821
6839
  config.observation?.blockAfter ?? (config.observation?.bufferTokens ?? chunkD4J4XPGM_cjs.OBSERVATIONAL_MEMORY_DEFAULTS.observation.bufferTokens ? 1.2 : void 0),
6822
6840
  config.observation?.messageTokens ?? chunkD4J4XPGM_cjs.OBSERVATIONAL_MEMORY_DEFAULTS.observation.messageTokens
@@ -6835,8 +6853,8 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
6835
6853
  },
6836
6854
  providerOptions: config.reflection?.providerOptions ?? chunkD4J4XPGM_cjs.OBSERVATIONAL_MEMORY_DEFAULTS.reflection.providerOptions,
6837
6855
  bufferActivation: asyncBufferingDisabled ? void 0 : config?.reflection?.bufferActivation ?? chunkD4J4XPGM_cjs.OBSERVATIONAL_MEMORY_DEFAULTS.reflection.bufferActivation,
6838
- activateAfterIdle: parseActivationTTL(config.activateAfterIdle, "activateAfterIdle"),
6839
- activateOnProviderChange: config.activateOnProviderChange ?? false,
6856
+ activateAfterIdle: parseActivationTTL(config.reflection?.activateAfterIdle, "reflection.activateAfterIdle"),
6857
+ activateOnProviderChange: config.reflection?.activateOnProviderChange ?? false,
6840
6858
  blockAfter: asyncBufferingDisabled ? void 0 : resolveBlockAfter(
6841
6859
  config.reflection?.blockAfter ?? (config.reflection?.bufferActivation ?? chunkD4J4XPGM_cjs.OBSERVATIONAL_MEMORY_DEFAULTS.reflection.bufferActivation ? 1.2 : void 0),
6842
6860
  config.reflection?.observationTokens ?? chunkD4J4XPGM_cjs.OBSERVATIONAL_MEMORY_DEFAULTS.reflection.observationTokens
@@ -9223,6 +9241,33 @@ var GATEWAY_STATE_KEY = "__isGatewayModel";
9223
9241
  function isMastraGatewayModel(model) {
9224
9242
  return typeof model === "object" && model !== null && "gatewayId" in model && model.gatewayId === "mastra";
9225
9243
  }
9244
+ function injectObservationContextMessages({
9245
+ messageList,
9246
+ systemMessages,
9247
+ continuationMessage,
9248
+ threadId,
9249
+ resourceId
9250
+ }) {
9251
+ if (!systemMessages?.length) {
9252
+ return;
9253
+ }
9254
+ messageList.clearSystemMessages("observational-memory");
9255
+ for (const msg of systemMessages) {
9256
+ messageList.addSystem(msg, "observational-memory");
9257
+ }
9258
+ const contMsg = continuationMessage ?? {
9259
+ id: "om-continuation",
9260
+ role: "user",
9261
+ createdAt: /* @__PURE__ */ new Date(0),
9262
+ content: {
9263
+ format: 2,
9264
+ parts: [{ type: "text", text: `<system-reminder>${chunkD4J4XPGM_cjs.OBSERVATION_CONTINUATION_HINT}</system-reminder>` }]
9265
+ },
9266
+ threadId,
9267
+ resourceId
9268
+ };
9269
+ messageList.add(contMsg, "memory");
9270
+ }
9226
9271
  var ObservationalMemoryProcessor = class {
9227
9272
  id = "observational-memory";
9228
9273
  name = "Observational Memory";
@@ -9277,6 +9322,25 @@ var ObservationalMemoryProcessor = class {
9277
9322
  const preMessagesSnapshot = reproCaptureEnabled ? safeCaptureJson(messageList.get.all.db()) : null;
9278
9323
  const preSerializedMessageList = reproCaptureEnabled ? safeCaptureJson(messageList.serialize()) : null;
9279
9324
  if (readOnly) {
9325
+ const ctx = await loadMemoryContextMessages({
9326
+ memory: this.memory,
9327
+ messageList,
9328
+ threadId,
9329
+ resourceId
9330
+ });
9331
+ const systemMessages = ctx.hasObservations && ctx.omRecord ? await this.engine.buildContextSystemMessages({
9332
+ threadId,
9333
+ resourceId,
9334
+ record: ctx.omRecord,
9335
+ unobservedContextBlocks: ctx.otherThreadsContext
9336
+ }) : void 0;
9337
+ injectObservationContextMessages({
9338
+ messageList,
9339
+ systemMessages,
9340
+ continuationMessage: ctx.continuationMessage,
9341
+ threadId,
9342
+ resourceId
9343
+ });
9280
9344
  return messageList;
9281
9345
  }
9282
9346
  const activeTurn = state.__omTurn ?? this.turn;
@@ -9332,26 +9396,13 @@ var ObservationalMemoryProcessor = class {
9332
9396
  }
9333
9397
  throw err;
9334
9398
  }
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
- }
9399
+ injectObservationContextMessages({
9400
+ messageList,
9401
+ systemMessages: ctx.systemMessage,
9402
+ continuationMessage: this.turn.context.continuation,
9403
+ threadId,
9404
+ resourceId
9405
+ });
9355
9406
  const freshRecord = await this.engine.getOrCreateRecord(threadId, resourceId);
9356
9407
  await this.engine.emitProgress({
9357
9408
  record: freshRecord,
@@ -9477,5 +9528,5 @@ exports.stripEphemeralAnchorIds = stripEphemeralAnchorIds;
9477
9528
  exports.stripObservationGroups = stripObservationGroups;
9478
9529
  exports.truncateStringByTokens = truncateStringByTokens;
9479
9530
  exports.wrapInObservationGroup = wrapInObservationGroup;
9480
- //# sourceMappingURL=chunk-WNLFJKTX.cjs.map
9481
- //# sourceMappingURL=chunk-WNLFJKTX.cjs.map
9531
+ //# sourceMappingURL=chunk-ET2TVAT3.cjs.map
9532
+ //# sourceMappingURL=chunk-ET2TVAT3.cjs.map