@mastra/memory 1.18.2 → 1.18.3-alpha.0

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.
@@ -2440,7 +2440,12 @@ var ObservationTurn = class {
2440
2440
  return this._currentStep;
2441
2441
  }
2442
2442
  /**
2443
- * Finalize the turn: save any remaining messages and return the latest record state.
2443
+ * Finalize the turn: save any remaining messages and return the current cached record.
2444
+ *
2445
+ * When async observation buffering is enabled and there are unobserved messages,
2446
+ * a background buffer operation is kicked off so that observations are computed
2447
+ * proactively while the agent is idle, rather than waiting for the next turn.
2448
+ * The returned record does not wait for that background buffering pass to finish.
2444
2449
  */
2445
2450
  async end() {
2446
2451
  if (this._ended) throw new Error("Turn already ended");
@@ -2451,6 +2456,24 @@ var ObservationTurn = class {
2451
2456
  if (unsavedMessages.length > 0) {
2452
2457
  await this.om.persistMessages(unsavedMessages, this.threadId, this.resourceId);
2453
2458
  }
2459
+ if (this.om.buffering.isAsyncObservationEnabled()) {
2460
+ const allMessages = this.messageList.get.all.db();
2461
+ const record = this._record;
2462
+ const unobservedMessages = this.om.getUnobservedMessages(allMessages, record);
2463
+ if (unobservedMessages.length > 0) {
2464
+ void this.om.buffer({
2465
+ threadId: this.threadId,
2466
+ resourceId: this.resourceId,
2467
+ messages: unobservedMessages,
2468
+ record,
2469
+ writer: this.writer,
2470
+ requestContext: this.requestContext,
2471
+ observabilityContext: this.observabilityContext
2472
+ }).catch((err) => {
2473
+ omDebug(`[OM:turn.end] idle buffer failed: ${err?.message}`);
2474
+ });
2475
+ }
2476
+ }
2454
2477
  return { record: this._record };
2455
2478
  }
2456
2479
  /**
@@ -9705,5 +9728,5 @@ function getObservationsAsOf(activeObservations, asOf) {
9705
9728
  }
9706
9729
 
9707
9730
  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 };
9708
- //# sourceMappingURL=chunk-LCALB7W6.js.map
9709
- //# sourceMappingURL=chunk-LCALB7W6.js.map
9731
+ //# sourceMappingURL=chunk-KLETR4RS.js.map
9732
+ //# sourceMappingURL=chunk-KLETR4RS.js.map