@mastra/memory 1.15.0-alpha.1 → 1.15.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.
@@ -4131,13 +4131,29 @@ var ReflectorRunner = class {
4131
4131
  model
4132
4132
  });
4133
4133
  }
4134
- getObservationMarkerConfig() {
4134
+ getObservationMarkerConfig(record) {
4135
4135
  return {
4136
4136
  messageTokens: getMaxThreshold(this.observationConfig.messageTokens),
4137
- observationTokens: getMaxThreshold(this.reflectionConfig.observationTokens),
4137
+ observationTokens: getMaxThreshold(
4138
+ record ? this.getEffectiveReflectionTokens(record) : this.reflectionConfig.observationTokens
4139
+ ),
4138
4140
  scope: this.scope
4139
4141
  };
4140
4142
  }
4143
+ /**
4144
+ * Resolve the effective reflection observationTokens for a record.
4145
+ * Only explicit per-record overrides (stored under `_overrides`) win;
4146
+ * the initial config snapshot is ignored so instance-level changes
4147
+ * still take effect for existing records.
4148
+ */
4149
+ getEffectiveReflectionTokens(record) {
4150
+ const overrides = record.config?._overrides;
4151
+ const recordTokens = overrides?.reflection?.observationTokens;
4152
+ if (recordTokens) {
4153
+ return recordTokens;
4154
+ }
4155
+ return this.reflectionConfig.observationTokens;
4156
+ }
4141
4157
  /**
4142
4158
  * Call the Reflector agent with escalating compression levels.
4143
4159
  */
@@ -4326,7 +4342,7 @@ var ReflectorRunner = class {
4326
4342
  const freshRecord = await this.storage.getObservationalMemory(record.threadId, record.resourceId);
4327
4343
  const currentRecord = freshRecord ?? record;
4328
4344
  const observationTokens = currentRecord.observationTokenCount ?? 0;
4329
- const reflectThreshold = getMaxThreshold(this.reflectionConfig.observationTokens);
4345
+ const reflectThreshold = getMaxThreshold(this.getEffectiveReflectionTokens(currentRecord));
4330
4346
  const bufferActivation = this.reflectionConfig.bufferActivation ?? 0.5;
4331
4347
  const startedAt = (/* @__PURE__ */ new Date()).toISOString();
4332
4348
  const cycleId = `reflect-buf-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
@@ -4355,7 +4371,7 @@ var ReflectorRunner = class {
4355
4371
  recordId: record.id,
4356
4372
  threadId: record.threadId ?? "",
4357
4373
  threadIds: record.threadId ? [record.threadId] : [],
4358
- config: this.getObservationMarkerConfig()
4374
+ config: this.getObservationMarkerConfig(currentRecord)
4359
4375
  });
4360
4376
  void writer.custom(startMarker).catch(() => {
4361
4377
  });
@@ -4467,7 +4483,7 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
4467
4483
  threadId: freshRecord.threadId ?? "",
4468
4484
  generationCount: afterRecord?.generationCount ?? freshRecord.generationCount ?? 0,
4469
4485
  observations: afterRecord?.activeObservations,
4470
- config: this.getObservationMarkerConfig()
4486
+ config: this.getObservationMarkerConfig(freshRecord)
4471
4487
  });
4472
4488
  void writer.custom(activationMarker).catch(() => {
4473
4489
  });
@@ -4498,7 +4514,7 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
4498
4514
  observabilityContext
4499
4515
  } = opts;
4500
4516
  const lockKey = this.buffering.getLockKey(record.threadId, record.resourceId);
4501
- const reflectThreshold = getMaxThreshold(this.reflectionConfig.observationTokens);
4517
+ const reflectThreshold = getMaxThreshold(this.getEffectiveReflectionTokens(record));
4502
4518
  if (this.buffering.isAsyncReflectionEnabled() && observationTokens < reflectThreshold) {
4503
4519
  const shouldTrigger = (() => {
4504
4520
  if (!this.buffering.isAsyncReflectionEnabled()) return false;
@@ -4577,7 +4593,7 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
4577
4593
  recordId: record.id,
4578
4594
  threadId,
4579
4595
  threadIds: [threadId],
4580
- config: this.getObservationMarkerConfig()
4596
+ config: this.getObservationMarkerConfig(record)
4581
4597
  });
4582
4598
  await writer.custom(startMarker).catch(() => {
4583
4599
  });
@@ -8613,6 +8629,10 @@ function getOmObservabilityContext(args) {
8613
8629
  metrics: args.metrics
8614
8630
  };
8615
8631
  }
8632
+ var GATEWAY_STATE_KEY = "__isGatewayModel";
8633
+ function isMastraGatewayModel(model) {
8634
+ return model instanceof llm.ModelRouterLanguageModel && model.gatewayId === "mastra";
8635
+ }
8616
8636
  var ObservationalMemoryProcessor = class {
8617
8637
  id = "observational-memory";
8618
8638
  name = "Observational Memory";
@@ -8648,6 +8668,11 @@ var ObservationalMemoryProcessor = class {
8648
8668
  omDebug(`[OM:processInputStep:NO-CONTEXT] getThreadContext returned null \u2014 returning early`);
8649
8669
  return messageList;
8650
8670
  }
8671
+ if (isMastraGatewayModel(model)) {
8672
+ state[GATEWAY_STATE_KEY] = true;
8673
+ omDebug(`[OM:processInputStep:GATEWAY] gateway handles OM \u2014 skipping local processing`);
8674
+ return messageList;
8675
+ }
8651
8676
  const { threadId, resourceId } = context;
8652
8677
  const memoryContext = memory.parseMemoryRequestContext(requestContext);
8653
8678
  const readOnly = memoryContext?.memoryConfig?.readOnly;
@@ -8764,6 +8789,7 @@ var ObservationalMemoryProcessor = class {
8764
8789
  const state = _state ?? {};
8765
8790
  const context = this.engine.getThreadContext(requestContext, messageList);
8766
8791
  if (!context) return messageList;
8792
+ if (state[GATEWAY_STATE_KEY]) return messageList;
8767
8793
  const observabilityContext = getOmObservabilityContext(args);
8768
8794
  state.__omObservabilityContext = observabilityContext;
8769
8795
  return this.engine.getTokenCounter().runWithModelContext(state.__omActorModelContext, async () => {
@@ -8840,5 +8866,5 @@ exports.stripEphemeralAnchorIds = stripEphemeralAnchorIds;
8840
8866
  exports.stripObservationGroups = stripObservationGroups;
8841
8867
  exports.truncateStringByTokens = truncateStringByTokens;
8842
8868
  exports.wrapInObservationGroup = wrapInObservationGroup;
8843
- //# sourceMappingURL=chunk-ANKEPFC6.cjs.map
8844
- //# sourceMappingURL=chunk-ANKEPFC6.cjs.map
8869
+ //# sourceMappingURL=chunk-WNLRMAHY.cjs.map
8870
+ //# sourceMappingURL=chunk-WNLRMAHY.cjs.map