@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
@@ -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 {
@@ -6602,6 +6620,7 @@ var ObservationalMemory = class _ObservationalMemory {
6602
6620
  buffering;
6603
6621
  shouldObscureThreadIds = false;
6604
6622
  hasher = xxhash__default.default();
6623
+ mastra;
6605
6624
  /**
6606
6625
  * Track message IDs observed during this instance's lifetime.
6607
6626
  * Prevents re-observing messages when per-thread lastObservedAt cursors
@@ -6668,20 +6687,10 @@ var ObservationalMemory = class _ObservationalMemory {
6668
6687
  this.scope = config.scope ?? "thread";
6669
6688
  this.retrieval = Boolean(config.retrieval);
6670
6689
  this.onIndexObservations = config.onIndexObservations;
6671
- const resolveModel = (m) => m === "default" ? chunkD4J4XPGM_cjs.OBSERVATIONAL_MEMORY_DEFAULTS.observation.model : m;
6672
- const observationModel = resolveModel(config.model) ?? resolveModel(config.observation?.model) ?? resolveModel(config.reflection?.model);
6673
- const reflectionModel = resolveModel(config.model) ?? resolveModel(config.reflection?.model) ?? resolveModel(config.observation?.model);
6674
- if (!observationModel || !reflectionModel) {
6675
- throw new Error(
6676
- `Observational Memory requires a model to be set. Use \`observationalMemory: true\` for the default (google/gemini-2.5-flash), or set a model explicitly:
6677
-
6678
- observationalMemory: {
6679
- model: "$provider/$model",
6680
- }
6681
-
6682
- See https://mastra.ai/docs/memory/observational-memory#models for model recommendations and alternatives.`
6683
- );
6684
- }
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;
6685
6694
  const messageTokens = config.observation?.messageTokens ?? chunkD4J4XPGM_cjs.OBSERVATIONAL_MEMORY_DEFAULTS.observation.messageTokens;
6686
6695
  const observationTokens = config.reflection?.observationTokens ?? chunkD4J4XPGM_cjs.OBSERVATIONAL_MEMORY_DEFAULTS.reflection.observationTokens;
6687
6696
  const isSharedBudget = config.shareTokenBudget ?? false;
@@ -6767,7 +6776,8 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
6767
6776
  observationConfig: this.observationConfig,
6768
6777
  observedMessageIds: this.observedMessageIds,
6769
6778
  resolveModel: (inputTokens) => this.resolveObservationModel(inputTokens),
6770
- tokenCounter: this.tokenCounter
6779
+ tokenCounter: this.tokenCounter,
6780
+ mastra: config.mastra
6771
6781
  });
6772
6782
  this.buffering = new BufferingCoordinator({
6773
6783
  observationConfig: this.observationConfig,
@@ -6785,13 +6795,19 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
6785
6795
  persistMarkerToStorage: (m, t, r) => this.persistMarkerToStorage(m, t, r),
6786
6796
  persistMarkerToMessage: (m, ml, t, r) => this.persistMarkerToMessage(m, ml, t, r),
6787
6797
  getCompressionStartLevel: (rc) => this.getCompressionStartLevel(rc),
6788
- resolveModel: (inputTokens) => this.resolveReflectionModel(inputTokens)
6798
+ resolveModel: (inputTokens) => this.resolveReflectionModel(inputTokens),
6799
+ mastra: config.mastra
6789
6800
  });
6790
6801
  this.validateBufferConfig();
6791
6802
  omDebug(
6792
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}`
6793
6804
  );
6794
6805
  }
6806
+ __registerMastra(mastra) {
6807
+ this.mastra = mastra;
6808
+ this.observer.__registerMastra(mastra);
6809
+ this.reflector.__registerMastra(mastra);
6810
+ }
6795
6811
  /**
6796
6812
  * Get the current configuration for this OM instance.
6797
6813
  * Used by the server to expose config to the UI when OM is added via processors.
@@ -6900,7 +6916,7 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
6900
6916
  if (!modelToResolve) {
6901
6917
  return void 0;
6902
6918
  }
6903
- const resolved = await llm.resolveModelConfig(modelToResolve, requestContext);
6919
+ const resolved = await llm.resolveModelConfig(modelToResolve, requestContext, this.mastra);
6904
6920
  return {
6905
6921
  provider: resolved.provider,
6906
6922
  modelId: resolved.modelId
@@ -9382,5 +9398,5 @@ exports.stripEphemeralAnchorIds = stripEphemeralAnchorIds;
9382
9398
  exports.stripObservationGroups = stripObservationGroups;
9383
9399
  exports.truncateStringByTokens = truncateStringByTokens;
9384
9400
  exports.wrapInObservationGroup = wrapInObservationGroup;
9385
- //# sourceMappingURL=chunk-6ODYOMHN.cjs.map
9386
- //# sourceMappingURL=chunk-6ODYOMHN.cjs.map
9401
+ //# sourceMappingURL=chunk-UZDSNIGD.cjs.map
9402
+ //# sourceMappingURL=chunk-UZDSNIGD.cjs.map