@mastra/memory 1.17.5-alpha.0 → 1.17.5

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 (34) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/{chunk-Z5GWA7LB.js → chunk-BPJLUC2F.js} +37 -21
  3. package/dist/chunk-BPJLUC2F.js.map +1 -0
  4. package/dist/{chunk-6ODYOMHN.cjs → chunk-UZDSNIGD.cjs} +37 -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-memory-observational-memory.md +3 -3
  9. package/dist/index.cjs +32 -14
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.ts +4 -0
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +23 -5
  14. package/dist/index.js.map +1 -1
  15. package/dist/{observational-memory-UMDC4VC2.js → observational-memory-FBBKXNO5.js} +3 -3
  16. package/dist/{observational-memory-UMDC4VC2.js.map → observational-memory-FBBKXNO5.js.map} +1 -1
  17. package/dist/{observational-memory-OVSEK47Z.cjs → observational-memory-KWFKMLG6.cjs} +26 -26
  18. package/dist/{observational-memory-OVSEK47Z.cjs.map → observational-memory-KWFKMLG6.cjs.map} +1 -1
  19. package/dist/processors/index.cjs +24 -24
  20. package/dist/processors/index.js +1 -1
  21. package/dist/processors/observational-memory/observation-strategies/async-buffer.d.ts.map +1 -1
  22. package/dist/processors/observational-memory/observation-strategies/sync.d.ts.map +1 -1
  23. package/dist/processors/observational-memory/observational-memory.d.ts +3 -0
  24. package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -1
  25. package/dist/processors/observational-memory/observer-runner.d.ts +4 -0
  26. package/dist/processors/observational-memory/observer-runner.d.ts.map +1 -1
  27. package/dist/processors/observational-memory/processor.d.ts.map +1 -1
  28. package/dist/processors/observational-memory/reflector-runner.d.ts +4 -0
  29. package/dist/processors/observational-memory/reflector-runner.d.ts.map +1 -1
  30. package/dist/processors/observational-memory/types.d.ts +3 -0
  31. package/dist/processors/observational-memory/types.d.ts.map +1 -1
  32. package/package.json +7 -7
  33. package/dist/chunk-6ODYOMHN.cjs.map +0 -1
  34. package/dist/chunk-Z5GWA7LB.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @mastra/memory
2
2
 
3
+ ## 1.17.5
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
+ - 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))
10
+
11
+ - Updated dependencies [[`6dcd65f`](https://github.com/mastra-ai/mastra/commit/6dcd65f2a34069e6dc43ba35f1d11119b9b40bef), [`86c0298`](https://github.com/mastra-ai/mastra/commit/86c0298e647306423c842f9d5ac827bd616bd13d), [`c05c9a1`](https://github.com/mastra-ai/mastra/commit/c05c9a13230988cef6d438a62f37760f31927bc7), [`ca28c23`](https://github.com/mastra-ai/mastra/commit/ca28c232a2f18801a6cf20fe053479237b4d4fb0), [`e24aacb`](https://github.com/mastra-ai/mastra/commit/e24aacba07bd66f5d95b636dc24016fca26b52cf), [`7679a63`](https://github.com/mastra-ai/mastra/commit/7679a634eae8e8ca459fd87538fdf72b4389b07f), [`7fce309`](https://github.com/mastra-ai/mastra/commit/7fce30912b14170bfc41f0ac736cca0f39fe0cd4), [`1d64a76`](https://github.com/mastra-ai/mastra/commit/1d64a765861a0772ea187bab76e5ed37bf82d042), [`1c2dda8`](https://github.com/mastra-ai/mastra/commit/1c2dda805fbfccc0abf55d4cb20cc34402dc3f0c), [`c721164`](https://github.com/mastra-ai/mastra/commit/c7211643f7ac861f83b19a3757cc921487fc9d75), [`1b55954`](https://github.com/mastra-ai/mastra/commit/1b559541c1e08a10e49d01ffc51a634dfc37a286), [`7997c2e`](https://github.com/mastra-ai/mastra/commit/7997c2e55ddd121562a4098cd8d2b89c68433bf1), [`5adc55e`](https://github.com/mastra-ai/mastra/commit/5adc55e63407be8ee977914957d68bcc2a075ceb), [`7679a63`](https://github.com/mastra-ai/mastra/commit/7679a634eae8e8ca459fd87538fdf72b4389b07f), [`a0d9b6d`](https://github.com/mastra-ai/mastra/commit/a0d9b6d6b810aeaa9e177a0dcc99a4402e609634), [`e97ccb9`](https://github.com/mastra-ai/mastra/commit/e97ccb900f8b7a390ce82c9f8eb8d6eb2c5e3777), [`c5daf48`](https://github.com/mastra-ai/mastra/commit/c5daf48556e98c46ae06caf00f92c249912007e9), [`70017d7`](https://github.com/mastra-ai/mastra/commit/70017d72ab741b5d7040e2a15c251a317782e39e), [`cd96779`](https://github.com/mastra-ai/mastra/commit/cd9677937f113b2856dc8b9f3d4bdabcee58bb2e), [`b0c7022`](https://github.com/mastra-ai/mastra/commit/b0c70224f80dad7c0cdbfb22cbff22e0f75c064f), [`e4942bc`](https://github.com/mastra-ai/mastra/commit/e4942bc7fdc903572f7d84f26d5e15f9d39c763d)]:
12
+ - @mastra/core@1.32.0
13
+
14
+ ## 1.17.5-alpha.1
15
+
16
+ ### Patch Changes
17
+
18
+ - 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))
19
+
20
+ - 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)]:
21
+ - @mastra/core@1.32.0-alpha.4
22
+
3
23
  ## 1.17.5-alpha.0
4
24
 
5
25
  ### 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 {
@@ -6595,6 +6613,7 @@ var ObservationalMemory = class _ObservationalMemory {
6595
6613
  buffering;
6596
6614
  shouldObscureThreadIds = false;
6597
6615
  hasher = xxhash();
6616
+ mastra;
6598
6617
  /**
6599
6618
  * Track message IDs observed during this instance's lifetime.
6600
6619
  * Prevents re-observing messages when per-thread lastObservedAt cursors
@@ -6661,20 +6680,10 @@ var ObservationalMemory = class _ObservationalMemory {
6661
6680
  this.scope = config.scope ?? "thread";
6662
6681
  this.retrieval = Boolean(config.retrieval);
6663
6682
  this.onIndexObservations = config.onIndexObservations;
6664
- const resolveModel = (m) => m === "default" ? OBSERVATIONAL_MEMORY_DEFAULTS.observation.model : m;
6665
- const observationModel = resolveModel(config.model) ?? resolveModel(config.observation?.model) ?? resolveModel(config.reflection?.model);
6666
- const reflectionModel = resolveModel(config.model) ?? resolveModel(config.reflection?.model) ?? resolveModel(config.observation?.model);
6667
- if (!observationModel || !reflectionModel) {
6668
- throw new Error(
6669
- `Observational Memory requires a model to be set. Use \`observationalMemory: true\` for the default (google/gemini-2.5-flash), or set a model explicitly:
6670
-
6671
- observationalMemory: {
6672
- model: "$provider/$model",
6673
- }
6674
-
6675
- See https://mastra.ai/docs/memory/observational-memory#models for model recommendations and alternatives.`
6676
- );
6677
- }
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;
6678
6687
  const messageTokens = config.observation?.messageTokens ?? OBSERVATIONAL_MEMORY_DEFAULTS.observation.messageTokens;
6679
6688
  const observationTokens = config.reflection?.observationTokens ?? OBSERVATIONAL_MEMORY_DEFAULTS.reflection.observationTokens;
6680
6689
  const isSharedBudget = config.shareTokenBudget ?? false;
@@ -6760,7 +6769,8 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
6760
6769
  observationConfig: this.observationConfig,
6761
6770
  observedMessageIds: this.observedMessageIds,
6762
6771
  resolveModel: (inputTokens) => this.resolveObservationModel(inputTokens),
6763
- tokenCounter: this.tokenCounter
6772
+ tokenCounter: this.tokenCounter,
6773
+ mastra: config.mastra
6764
6774
  });
6765
6775
  this.buffering = new BufferingCoordinator({
6766
6776
  observationConfig: this.observationConfig,
@@ -6778,13 +6788,19 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
6778
6788
  persistMarkerToStorage: (m, t, r) => this.persistMarkerToStorage(m, t, r),
6779
6789
  persistMarkerToMessage: (m, ml, t, r) => this.persistMarkerToMessage(m, ml, t, r),
6780
6790
  getCompressionStartLevel: (rc) => this.getCompressionStartLevel(rc),
6781
- resolveModel: (inputTokens) => this.resolveReflectionModel(inputTokens)
6791
+ resolveModel: (inputTokens) => this.resolveReflectionModel(inputTokens),
6792
+ mastra: config.mastra
6782
6793
  });
6783
6794
  this.validateBufferConfig();
6784
6795
  omDebug(
6785
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}`
6786
6797
  );
6787
6798
  }
6799
+ __registerMastra(mastra) {
6800
+ this.mastra = mastra;
6801
+ this.observer.__registerMastra(mastra);
6802
+ this.reflector.__registerMastra(mastra);
6803
+ }
6788
6804
  /**
6789
6805
  * Get the current configuration for this OM instance.
6790
6806
  * Used by the server to expose config to the UI when OM is added via processors.
@@ -6893,7 +6909,7 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
6893
6909
  if (!modelToResolve) {
6894
6910
  return void 0;
6895
6911
  }
6896
- const resolved = await resolveModelConfig(modelToResolve, requestContext);
6912
+ const resolved = await resolveModelConfig(modelToResolve, requestContext, this.mastra);
6897
6913
  return {
6898
6914
  provider: resolved.provider,
6899
6915
  modelId: resolved.modelId
@@ -9350,5 +9366,5 @@ function getObservationsAsOf(activeObservations, asOf) {
9350
9366
  }
9351
9367
 
9352
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 };
9353
- //# sourceMappingURL=chunk-Z5GWA7LB.js.map
9354
- //# sourceMappingURL=chunk-Z5GWA7LB.js.map
9369
+ //# sourceMappingURL=chunk-BPJLUC2F.js.map
9370
+ //# sourceMappingURL=chunk-BPJLUC2F.js.map