@mastra/memory 1.12.1 → 1.13.0-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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @mastra/memory
2
2
 
3
+ ## 1.13.0-alpha.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Added `loadUnobservedMessages({ threadId, resourceId? })` as a public method on `ObservationalMemory`. ([#14921](https://github.com/mastra-ai/mastra/pull/14921))
8
+
9
+ This lets external consumers (e.g. the Mastra gateway proxy) load previously-stored messages that haven't been observed yet, without having to reimplement the internal storage query and part-level filtering logic. The method fetches the OM record, queries storage for messages after the `lastObservedAt` cursor, and applies part-level filtering so partially-observed messages only return their unobserved parts.
10
+
11
+ ```ts
12
+ const unobserved = await om.loadUnobservedMessages({
13
+ threadId: 'thread-123',
14
+ resourceId: 'user-456',
15
+ });
16
+ ```
17
+
18
+ ### Patch Changes
19
+
20
+ - Updated dependencies [[`13f4327`](https://github.com/mastra-ai/mastra/commit/13f4327f052faebe199cefbe906d33bf90238767)]:
21
+ - @mastra/core@1.21.0-alpha.1
22
+
3
23
  ## 1.12.1
4
24
 
5
25
  ### Patch Changes
@@ -6715,7 +6715,7 @@ ${suggestedResponse}
6715
6715
  * In resource scope mode, loads messages for the entire resource (all threads).
6716
6716
  * In thread scope mode, loads messages for just the current thread.
6717
6717
  */
6718
- async loadUnobservedMessages(threadId, resourceId, lastObservedAt) {
6718
+ async loadMessagesFromStorage(threadId, resourceId, lastObservedAt) {
6719
6719
  const startDate = lastObservedAt ? new Date(lastObservedAt.getTime() + 1) : void 0;
6720
6720
  let result;
6721
6721
  if (this.scope === "resource" && resourceId) {
@@ -7403,7 +7403,7 @@ ${grouped}` : grouped;
7403
7403
  if (opts.messages) {
7404
7404
  unobservedMessages = this.getUnobservedMessages(opts.messages, record);
7405
7405
  } else {
7406
- const rawMessages = await this.loadUnobservedMessages(
7406
+ const rawMessages = await this.loadMessagesFromStorage(
7407
7407
  threadId,
7408
7408
  resourceId,
7409
7409
  record.lastObservedAt ? new Date(record.lastObservedAt) : void 0
@@ -7516,6 +7516,27 @@ ${grouped}` : grouped;
7516
7516
  const record = await this.getOrCreateRecord(threadId, resourceId);
7517
7517
  return this.getUnobservedMessages(messages, record);
7518
7518
  }
7519
+ /**
7520
+ * Load unobserved messages from storage for a thread/resource.
7521
+ *
7522
+ * Fetches the OM record, queries storage for messages after the
7523
+ * lastObservedAt cursor, then applies part-level filtering so
7524
+ * partially-observed messages only include their unobserved parts.
7525
+ *
7526
+ * Use this when you need to load stored conversation history that
7527
+ * hasn't been observed yet (e.g. in a stateless gateway proxy that
7528
+ * only receives the latest message from the HTTP request).
7529
+ */
7530
+ async loadUnobservedMessages(opts) {
7531
+ const { threadId, resourceId } = opts;
7532
+ const record = await this.getOrCreateRecord(threadId, resourceId);
7533
+ const rawMessages = await this.loadMessagesFromStorage(
7534
+ threadId,
7535
+ resourceId,
7536
+ record.lastObservedAt ? new Date(record.lastObservedAt) : void 0
7537
+ );
7538
+ return this.getUnobservedMessages(rawMessages, record);
7539
+ }
7519
7540
  /**
7520
7541
  * Create a buffered observation chunk without merging into active observations.
7521
7542
  *
@@ -7577,7 +7598,7 @@ ${grouped}` : grouped;
7577
7598
  if (opts.messages) {
7578
7599
  candidateMessages = this.getUnobservedMessages(opts.messages, record, { excludeBuffered: true });
7579
7600
  } else {
7580
- const rawMessages = await this.loadUnobservedMessages(
7601
+ const rawMessages = await this.loadMessagesFromStorage(
7581
7602
  threadId,
7582
7603
  resourceId,
7583
7604
  record.lastObservedAt ? new Date(record.lastObservedAt) : void 0
@@ -7819,7 +7840,7 @@ ${grouped}` : grouped;
7819
7840
  await this.withLock(lockKey, async () => {
7820
7841
  const freshRecord = await this.getOrCreateRecord(threadId, resourceId);
7821
7842
  generationBefore = freshRecord.generationCount;
7822
- const unobservedMessages = messages ? this.getUnobservedMessages(messages, freshRecord) : await this.loadUnobservedMessages(
7843
+ const unobservedMessages = messages ? this.getUnobservedMessages(messages, freshRecord) : await this.loadMessagesFromStorage(
7823
7844
  threadId,
7824
7845
  resourceId,
7825
7846
  freshRecord.lastObservedAt ? new Date(freshRecord.lastObservedAt) : void 0
@@ -8475,5 +8496,5 @@ exports.stripEphemeralAnchorIds = stripEphemeralAnchorIds;
8475
8496
  exports.stripObservationGroups = stripObservationGroups;
8476
8497
  exports.truncateStringByTokens = truncateStringByTokens;
8477
8498
  exports.wrapInObservationGroup = wrapInObservationGroup;
8478
- //# sourceMappingURL=chunk-HLGFIN4J.cjs.map
8479
- //# sourceMappingURL=chunk-HLGFIN4J.cjs.map
8499
+ //# sourceMappingURL=chunk-O3KNDDJV.cjs.map
8500
+ //# sourceMappingURL=chunk-O3KNDDJV.cjs.map