@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
@@ -3759,6 +3759,7 @@ var ObserverRunner = class {
3759
3759
  observedMessageIds;
3760
3760
  resolveModel;
3761
3761
  tokenCounter;
3762
+ mastra;
3762
3763
  /** Captured prompt/response from the last observer call (for repro capture). */
3763
3764
  lastExchange;
3764
3765
  constructor(opts) {
@@ -3766,9 +3767,13 @@ var ObserverRunner = class {
3766
3767
  this.observedMessageIds = opts.observedMessageIds;
3767
3768
  this.resolveModel = opts.resolveModel;
3768
3769
  this.tokenCounter = opts.tokenCounter;
3770
+ this.mastra = opts.mastra;
3771
+ }
3772
+ __registerMastra(mastra) {
3773
+ this.mastra = mastra;
3769
3774
  }
3770
3775
  createAgent(model, isMultiThread = false) {
3771
- return new agent.Agent({
3776
+ const agent$1 = new agent.Agent({
3772
3777
  id: isMultiThread ? "multi-thread-observer" : "observational-memory-observer",
3773
3778
  name: isMultiThread ? "multi-thread-observer" : "Observer",
3774
3779
  instructions: buildObserverSystemPrompt(
@@ -3778,6 +3783,10 @@ var ObserverRunner = class {
3778
3783
  ),
3779
3784
  model
3780
3785
  });
3786
+ if (this.mastra) {
3787
+ agent$1.__registerMastra(this.mastra);
3788
+ }
3789
+ return agent$1;
3781
3790
  }
3782
3791
  async withAbortCheck(fn, abortSignal) {
3783
3792
  if (abortSignal?.aborted) {
@@ -4297,6 +4306,7 @@ var ReflectorRunner = class {
4297
4306
  persistMarkerToStorage;
4298
4307
  persistMarkerToMessage;
4299
4308
  getCompressionStartLevel;
4309
+ mastra;
4300
4310
  constructor(opts) {
4301
4311
  this.reflectionConfig = opts.reflectionConfig;
4302
4312
  this.observationConfig = opts.observationConfig;
@@ -4309,14 +4319,22 @@ var ReflectorRunner = class {
4309
4319
  this.persistMarkerToStorage = opts.persistMarkerToStorage;
4310
4320
  this.persistMarkerToMessage = opts.persistMarkerToMessage;
4311
4321
  this.getCompressionStartLevel = opts.getCompressionStartLevel;
4322
+ this.mastra = opts.mastra;
4323
+ }
4324
+ __registerMastra(mastra) {
4325
+ this.mastra = mastra;
4312
4326
  }
4313
4327
  createAgent(model) {
4314
- return new agent.Agent({
4328
+ const agent$1 = new agent.Agent({
4315
4329
  id: "observational-memory-reflector",
4316
4330
  name: "Reflector",
4317
4331
  instructions: buildReflectorSystemPrompt(this.reflectionConfig.instruction),
4318
4332
  model
4319
4333
  });
4334
+ if (this.mastra) {
4335
+ agent$1.__registerMastra(this.mastra);
4336
+ }
4337
+ return agent$1;
4320
4338
  }
4321
4339
  getObservationMarkerConfig(record) {
4322
4340
  return {
@@ -4821,6 +4839,13 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
4821
4839
  `[OM:reflect] blockAfter exceeded (${observationTokens} >= ${this.reflectionConfig.blockAfter}), falling through to sync reflection`
4822
4840
  );
4823
4841
  } else {
4842
+ const activationPoint = reflectThreshold * this.reflectionConfig.bufferActivation;
4843
+ if (observationTokens < activationPoint) {
4844
+ omDebug(
4845
+ `[OM:reflect] skipping async reflection \u2014 observationTokens (${observationTokens}) below activation point (${activationPoint}), triggered by ${activationTriggeredBy}`
4846
+ );
4847
+ return;
4848
+ }
4824
4849
  omDebug(
4825
4850
  `[OM:reflect] async activation failed, no blockAfter or below it (obsTokens=${observationTokens}, blockAfter=${this.reflectionConfig.blockAfter}) \u2014 starting background reflection`
4826
4851
  );
@@ -6595,6 +6620,7 @@ var ObservationalMemory = class _ObservationalMemory {
6595
6620
  buffering;
6596
6621
  shouldObscureThreadIds = false;
6597
6622
  hasher = xxhash__default.default();
6623
+ mastra;
6598
6624
  /**
6599
6625
  * Track message IDs observed during this instance's lifetime.
6600
6626
  * Prevents re-observing messages when per-thread lastObservedAt cursors
@@ -6661,20 +6687,10 @@ var ObservationalMemory = class _ObservationalMemory {
6661
6687
  this.scope = config.scope ?? "thread";
6662
6688
  this.retrieval = Boolean(config.retrieval);
6663
6689
  this.onIndexObservations = config.onIndexObservations;
6664
- const resolveModel = (m) => m === "default" ? chunkD4J4XPGM_cjs.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
- }
6690
+ this.mastra = config.mastra;
6691
+ const resolveModel = (model, defaultModel) => model === "default" ? defaultModel : model;
6692
+ const observationModel = resolveModel(config.model, chunkD4J4XPGM_cjs.OBSERVATIONAL_MEMORY_DEFAULTS.observation.model) ?? resolveModel(config.observation?.model, chunkD4J4XPGM_cjs.OBSERVATIONAL_MEMORY_DEFAULTS.observation.model) ?? resolveModel(config.reflection?.model, chunkD4J4XPGM_cjs.OBSERVATIONAL_MEMORY_DEFAULTS.observation.model) ?? chunkD4J4XPGM_cjs.OBSERVATIONAL_MEMORY_DEFAULTS.observation.model;
6693
+ const reflectionModel = resolveModel(config.model, chunkD4J4XPGM_cjs.OBSERVATIONAL_MEMORY_DEFAULTS.reflection.model) ?? resolveModel(config.reflection?.model, chunkD4J4XPGM_cjs.OBSERVATIONAL_MEMORY_DEFAULTS.reflection.model) ?? resolveModel(config.observation?.model, chunkD4J4XPGM_cjs.OBSERVATIONAL_MEMORY_DEFAULTS.reflection.model) ?? chunkD4J4XPGM_cjs.OBSERVATIONAL_MEMORY_DEFAULTS.reflection.model;
6678
6694
  const messageTokens = config.observation?.messageTokens ?? chunkD4J4XPGM_cjs.OBSERVATIONAL_MEMORY_DEFAULTS.observation.messageTokens;
6679
6695
  const observationTokens = config.reflection?.observationTokens ?? chunkD4J4XPGM_cjs.OBSERVATIONAL_MEMORY_DEFAULTS.reflection.observationTokens;
6680
6696
  const isSharedBudget = config.shareTokenBudget ?? false;
@@ -6760,7 +6776,8 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
6760
6776
  observationConfig: this.observationConfig,
6761
6777
  observedMessageIds: this.observedMessageIds,
6762
6778
  resolveModel: (inputTokens) => this.resolveObservationModel(inputTokens),
6763
- tokenCounter: this.tokenCounter
6779
+ tokenCounter: this.tokenCounter,
6780
+ mastra: config.mastra
6764
6781
  });
6765
6782
  this.buffering = new BufferingCoordinator({
6766
6783
  observationConfig: this.observationConfig,
@@ -6778,13 +6795,19 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
6778
6795
  persistMarkerToStorage: (m, t, r) => this.persistMarkerToStorage(m, t, r),
6779
6796
  persistMarkerToMessage: (m, ml, t, r) => this.persistMarkerToMessage(m, ml, t, r),
6780
6797
  getCompressionStartLevel: (rc) => this.getCompressionStartLevel(rc),
6781
- resolveModel: (inputTokens) => this.resolveReflectionModel(inputTokens)
6798
+ resolveModel: (inputTokens) => this.resolveReflectionModel(inputTokens),
6799
+ mastra: config.mastra
6782
6800
  });
6783
6801
  this.validateBufferConfig();
6784
6802
  omDebug(
6785
6803
  `[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
6804
  );
6787
6805
  }
6806
+ __registerMastra(mastra) {
6807
+ this.mastra = mastra;
6808
+ this.observer.__registerMastra(mastra);
6809
+ this.reflector.__registerMastra(mastra);
6810
+ }
6788
6811
  /**
6789
6812
  * Get the current configuration for this OM instance.
6790
6813
  * Used by the server to expose config to the UI when OM is added via processors.
@@ -6893,7 +6916,7 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
6893
6916
  if (!modelToResolve) {
6894
6917
  return void 0;
6895
6918
  }
6896
- const resolved = await llm.resolveModelConfig(modelToResolve, requestContext);
6919
+ const resolved = await llm.resolveModelConfig(modelToResolve, requestContext, this.mastra);
6897
6920
  return {
6898
6921
  provider: resolved.provider,
6899
6922
  modelId: resolved.modelId
@@ -9375,5 +9398,5 @@ exports.stripEphemeralAnchorIds = stripEphemeralAnchorIds;
9375
9398
  exports.stripObservationGroups = stripObservationGroups;
9376
9399
  exports.truncateStringByTokens = truncateStringByTokens;
9377
9400
  exports.wrapInObservationGroup = wrapInObservationGroup;
9378
- //# sourceMappingURL=chunk-M6QU3KKP.cjs.map
9379
- //# sourceMappingURL=chunk-M6QU3KKP.cjs.map
9401
+ //# sourceMappingURL=chunk-UZDSNIGD.cjs.map
9402
+ //# sourceMappingURL=chunk-UZDSNIGD.cjs.map