@mastra/memory 1.17.4 → 1.17.5-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.
Files changed (36) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/{chunk-4C4ERX6N.js → chunk-BPJLUC2F.js} +44 -21
  3. package/dist/chunk-BPJLUC2F.js.map +1 -0
  4. package/dist/{chunk-M6QU3KKP.cjs → chunk-UZDSNIGD.cjs} +44 -21
  5. package/dist/chunk-UZDSNIGD.cjs.map +1 -0
  6. package/dist/docs/SKILL.md +1 -1
  7. package/dist/docs/assets/SOURCE_MAP.json +29 -29
  8. package/dist/docs/references/docs-agents-supervisor-agents.md +16 -0
  9. package/dist/docs/references/docs-memory-observational-memory.md +3 -3
  10. package/dist/docs/references/reference-vectors-mongodb.md +0 -2
  11. package/dist/index.cjs +32 -14
  12. package/dist/index.cjs.map +1 -1
  13. package/dist/index.d.ts +4 -0
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +23 -5
  16. package/dist/index.js.map +1 -1
  17. package/dist/{observational-memory-ZS2HJPUO.js → observational-memory-FBBKXNO5.js} +3 -3
  18. package/dist/{observational-memory-ZS2HJPUO.js.map → observational-memory-FBBKXNO5.js.map} +1 -1
  19. package/dist/{observational-memory-TC2CBKCL.cjs → observational-memory-KWFKMLG6.cjs} +26 -26
  20. package/dist/{observational-memory-TC2CBKCL.cjs.map → observational-memory-KWFKMLG6.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-strategies/async-buffer.d.ts.map +1 -1
  24. package/dist/processors/observational-memory/observation-strategies/sync.d.ts.map +1 -1
  25. package/dist/processors/observational-memory/observational-memory.d.ts +3 -0
  26. package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -1
  27. package/dist/processors/observational-memory/observer-runner.d.ts +4 -0
  28. package/dist/processors/observational-memory/observer-runner.d.ts.map +1 -1
  29. package/dist/processors/observational-memory/processor.d.ts.map +1 -1
  30. package/dist/processors/observational-memory/reflector-runner.d.ts +4 -0
  31. package/dist/processors/observational-memory/reflector-runner.d.ts.map +1 -1
  32. package/dist/processors/observational-memory/types.d.ts +3 -0
  33. package/dist/processors/observational-memory/types.d.ts.map +1 -1
  34. package/package.json +7 -7
  35. package/dist/chunk-4C4ERX6N.js.map +0 -1
  36. package/dist/chunk-M6QU3KKP.cjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @mastra/memory
2
2
 
3
+ ## 1.17.5-alpha.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Fixed Observational Memory model resolution for user-defined gateways. Models such as `cloudflare/google/gemini-2.5-flash-lite` now resolve through registered gateways instead of failing with provider-config errors. Closes #13841. ([#16083](https://github.com/mastra-ai/mastra/pull/16083))
8
+
9
+ - Updated dependencies [[`7679a63`](https://github.com/mastra-ai/mastra/commit/7679a634eae8e8ca459fd87538fdf72b4389b07f), [`1d64a76`](https://github.com/mastra-ai/mastra/commit/1d64a765861a0772ea187bab76e5ed37bf82d042), [`7679a63`](https://github.com/mastra-ai/mastra/commit/7679a634eae8e8ca459fd87538fdf72b4389b07f), [`a0d9b6d`](https://github.com/mastra-ai/mastra/commit/a0d9b6d6b810aeaa9e177a0dcc99a4402e609634)]:
10
+ - @mastra/core@1.32.0-alpha.4
11
+
12
+ ## 1.17.5-alpha.0
13
+
14
+ ### Patch Changes
15
+
16
+ - Fixed async reflection buffering incorrectly triggering during idle timeout and provider-change activations when observation tokens are below the reflection activation threshold ([#16076](https://github.com/mastra-ai/mastra/pull/16076))
17
+
18
+ - Updated dependencies [[`c05c9a1`](https://github.com/mastra-ai/mastra/commit/c05c9a13230988cef6d438a62f37760f31927bc7), [`e24aacb`](https://github.com/mastra-ai/mastra/commit/e24aacba07bd66f5d95b636dc24016fca26b52cf), [`c721164`](https://github.com/mastra-ai/mastra/commit/c7211643f7ac861f83b19a3757cc921487fc9d75), [`1b55954`](https://github.com/mastra-ai/mastra/commit/1b559541c1e08a10e49d01ffc51a634dfc37a286), [`5adc55e`](https://github.com/mastra-ai/mastra/commit/5adc55e63407be8ee977914957d68bcc2a075ceb), [`70017d7`](https://github.com/mastra-ai/mastra/commit/70017d72ab741b5d7040e2a15c251a317782e39e), [`e4942bc`](https://github.com/mastra-ai/mastra/commit/e4942bc7fdc903572f7d84f26d5e15f9d39c763d)]:
19
+ - @mastra/core@1.32.0-alpha.1
20
+
3
21
  ## 1.17.4
4
22
 
5
23
  ### Patch Changes
@@ -3752,6 +3752,7 @@ var ObserverRunner = class {
3752
3752
  observedMessageIds;
3753
3753
  resolveModel;
3754
3754
  tokenCounter;
3755
+ mastra;
3755
3756
  /** Captured prompt/response from the last observer call (for repro capture). */
3756
3757
  lastExchange;
3757
3758
  constructor(opts) {
@@ -3759,9 +3760,13 @@ var ObserverRunner = class {
3759
3760
  this.observedMessageIds = opts.observedMessageIds;
3760
3761
  this.resolveModel = opts.resolveModel;
3761
3762
  this.tokenCounter = opts.tokenCounter;
3763
+ this.mastra = opts.mastra;
3764
+ }
3765
+ __registerMastra(mastra) {
3766
+ this.mastra = mastra;
3762
3767
  }
3763
3768
  createAgent(model, isMultiThread = false) {
3764
- return new Agent({
3769
+ const agent = new Agent({
3765
3770
  id: isMultiThread ? "multi-thread-observer" : "observational-memory-observer",
3766
3771
  name: isMultiThread ? "multi-thread-observer" : "Observer",
3767
3772
  instructions: buildObserverSystemPrompt(
@@ -3771,6 +3776,10 @@ var ObserverRunner = class {
3771
3776
  ),
3772
3777
  model
3773
3778
  });
3779
+ if (this.mastra) {
3780
+ agent.__registerMastra(this.mastra);
3781
+ }
3782
+ return agent;
3774
3783
  }
3775
3784
  async withAbortCheck(fn, abortSignal) {
3776
3785
  if (abortSignal?.aborted) {
@@ -4290,6 +4299,7 @@ var ReflectorRunner = class {
4290
4299
  persistMarkerToStorage;
4291
4300
  persistMarkerToMessage;
4292
4301
  getCompressionStartLevel;
4302
+ mastra;
4293
4303
  constructor(opts) {
4294
4304
  this.reflectionConfig = opts.reflectionConfig;
4295
4305
  this.observationConfig = opts.observationConfig;
@@ -4302,14 +4312,22 @@ var ReflectorRunner = class {
4302
4312
  this.persistMarkerToStorage = opts.persistMarkerToStorage;
4303
4313
  this.persistMarkerToMessage = opts.persistMarkerToMessage;
4304
4314
  this.getCompressionStartLevel = opts.getCompressionStartLevel;
4315
+ this.mastra = opts.mastra;
4316
+ }
4317
+ __registerMastra(mastra) {
4318
+ this.mastra = mastra;
4305
4319
  }
4306
4320
  createAgent(model) {
4307
- return new Agent({
4321
+ const agent = new Agent({
4308
4322
  id: "observational-memory-reflector",
4309
4323
  name: "Reflector",
4310
4324
  instructions: buildReflectorSystemPrompt(this.reflectionConfig.instruction),
4311
4325
  model
4312
4326
  });
4327
+ if (this.mastra) {
4328
+ agent.__registerMastra(this.mastra);
4329
+ }
4330
+ return agent;
4313
4331
  }
4314
4332
  getObservationMarkerConfig(record) {
4315
4333
  return {
@@ -4814,6 +4832,13 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
4814
4832
  `[OM:reflect] blockAfter exceeded (${observationTokens} >= ${this.reflectionConfig.blockAfter}), falling through to sync reflection`
4815
4833
  );
4816
4834
  } else {
4835
+ const activationPoint = reflectThreshold * this.reflectionConfig.bufferActivation;
4836
+ if (observationTokens < activationPoint) {
4837
+ omDebug(
4838
+ `[OM:reflect] skipping async reflection \u2014 observationTokens (${observationTokens}) below activation point (${activationPoint}), triggered by ${activationTriggeredBy}`
4839
+ );
4840
+ return;
4841
+ }
4817
4842
  omDebug(
4818
4843
  `[OM:reflect] async activation failed, no blockAfter or below it (obsTokens=${observationTokens}, blockAfter=${this.reflectionConfig.blockAfter}) \u2014 starting background reflection`
4819
4844
  );
@@ -6588,6 +6613,7 @@ var ObservationalMemory = class _ObservationalMemory {
6588
6613
  buffering;
6589
6614
  shouldObscureThreadIds = false;
6590
6615
  hasher = xxhash();
6616
+ mastra;
6591
6617
  /**
6592
6618
  * Track message IDs observed during this instance's lifetime.
6593
6619
  * Prevents re-observing messages when per-thread lastObservedAt cursors
@@ -6654,20 +6680,10 @@ var ObservationalMemory = class _ObservationalMemory {
6654
6680
  this.scope = config.scope ?? "thread";
6655
6681
  this.retrieval = Boolean(config.retrieval);
6656
6682
  this.onIndexObservations = config.onIndexObservations;
6657
- const resolveModel = (m) => m === "default" ? OBSERVATIONAL_MEMORY_DEFAULTS.observation.model : m;
6658
- const observationModel = resolveModel(config.model) ?? resolveModel(config.observation?.model) ?? resolveModel(config.reflection?.model);
6659
- const reflectionModel = resolveModel(config.model) ?? resolveModel(config.reflection?.model) ?? resolveModel(config.observation?.model);
6660
- if (!observationModel || !reflectionModel) {
6661
- throw new Error(
6662
- `Observational Memory requires a model to be set. Use \`observationalMemory: true\` for the default (google/gemini-2.5-flash), or set a model explicitly:
6663
-
6664
- observationalMemory: {
6665
- model: "$provider/$model",
6666
- }
6667
-
6668
- See https://mastra.ai/docs/memory/observational-memory#models for model recommendations and alternatives.`
6669
- );
6670
- }
6683
+ this.mastra = config.mastra;
6684
+ const resolveModel = (model, defaultModel) => model === "default" ? defaultModel : model;
6685
+ const observationModel = resolveModel(config.model, OBSERVATIONAL_MEMORY_DEFAULTS.observation.model) ?? resolveModel(config.observation?.model, OBSERVATIONAL_MEMORY_DEFAULTS.observation.model) ?? resolveModel(config.reflection?.model, OBSERVATIONAL_MEMORY_DEFAULTS.observation.model) ?? OBSERVATIONAL_MEMORY_DEFAULTS.observation.model;
6686
+ const reflectionModel = resolveModel(config.model, OBSERVATIONAL_MEMORY_DEFAULTS.reflection.model) ?? resolveModel(config.reflection?.model, OBSERVATIONAL_MEMORY_DEFAULTS.reflection.model) ?? resolveModel(config.observation?.model, OBSERVATIONAL_MEMORY_DEFAULTS.reflection.model) ?? OBSERVATIONAL_MEMORY_DEFAULTS.reflection.model;
6671
6687
  const messageTokens = config.observation?.messageTokens ?? OBSERVATIONAL_MEMORY_DEFAULTS.observation.messageTokens;
6672
6688
  const observationTokens = config.reflection?.observationTokens ?? OBSERVATIONAL_MEMORY_DEFAULTS.reflection.observationTokens;
6673
6689
  const isSharedBudget = config.shareTokenBudget ?? false;
@@ -6753,7 +6769,8 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
6753
6769
  observationConfig: this.observationConfig,
6754
6770
  observedMessageIds: this.observedMessageIds,
6755
6771
  resolveModel: (inputTokens) => this.resolveObservationModel(inputTokens),
6756
- tokenCounter: this.tokenCounter
6772
+ tokenCounter: this.tokenCounter,
6773
+ mastra: config.mastra
6757
6774
  });
6758
6775
  this.buffering = new BufferingCoordinator({
6759
6776
  observationConfig: this.observationConfig,
@@ -6771,13 +6788,19 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
6771
6788
  persistMarkerToStorage: (m, t, r) => this.persistMarkerToStorage(m, t, r),
6772
6789
  persistMarkerToMessage: (m, ml, t, r) => this.persistMarkerToMessage(m, ml, t, r),
6773
6790
  getCompressionStartLevel: (rc) => this.getCompressionStartLevel(rc),
6774
- resolveModel: (inputTokens) => this.resolveReflectionModel(inputTokens)
6791
+ resolveModel: (inputTokens) => this.resolveReflectionModel(inputTokens),
6792
+ mastra: config.mastra
6775
6793
  });
6776
6794
  this.validateBufferConfig();
6777
6795
  omDebug(
6778
6796
  `[OM:init] new ObservationalMemory instance created \u2014 scope=${this.scope}, messageTokens=${JSON.stringify(this.observationConfig.messageTokens)}, obsAsyncEnabled=${this.buffering.isAsyncObservationEnabled()}, bufferTokens=${this.observationConfig.bufferTokens}, bufferActivation=${this.observationConfig.bufferActivation}, blockAfter=${this.observationConfig.blockAfter}, reflectionTokens=${this.reflectionConfig.observationTokens}, refAsyncEnabled=${this.buffering.isAsyncReflectionEnabled()}, refAsyncActivation=${this.reflectionConfig.bufferActivation}, refBlockAfter=${this.reflectionConfig.blockAfter}`
6779
6797
  );
6780
6798
  }
6799
+ __registerMastra(mastra) {
6800
+ this.mastra = mastra;
6801
+ this.observer.__registerMastra(mastra);
6802
+ this.reflector.__registerMastra(mastra);
6803
+ }
6781
6804
  /**
6782
6805
  * Get the current configuration for this OM instance.
6783
6806
  * Used by the server to expose config to the UI when OM is added via processors.
@@ -6886,7 +6909,7 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
6886
6909
  if (!modelToResolve) {
6887
6910
  return void 0;
6888
6911
  }
6889
- const resolved = await resolveModelConfig(modelToResolve, requestContext);
6912
+ const resolved = await resolveModelConfig(modelToResolve, requestContext, this.mastra);
6890
6913
  return {
6891
6914
  provider: resolved.provider,
6892
6915
  modelId: resolved.modelId
@@ -9343,5 +9366,5 @@ function getObservationsAsOf(activeObservations, asOf) {
9343
9366
  }
9344
9367
 
9345
9368
  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 };
9346
- //# sourceMappingURL=chunk-4C4ERX6N.js.map
9347
- //# sourceMappingURL=chunk-4C4ERX6N.js.map
9369
+ //# sourceMappingURL=chunk-BPJLUC2F.js.map
9370
+ //# sourceMappingURL=chunk-BPJLUC2F.js.map