@mastra/memory 1.13.0 → 1.13.1-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.
Files changed (29) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/{chunk-O3KNDDJV.cjs → chunk-HNVSYZRA.cjs} +103 -8
  3. package/dist/chunk-HNVSYZRA.cjs.map +1 -0
  4. package/dist/{chunk-ZVRY34YB.js → chunk-SWCWXIDJ.js} +103 -8
  5. package/dist/chunk-SWCWXIDJ.js.map +1 -0
  6. package/dist/docs/SKILL.md +1 -1
  7. package/dist/docs/assets/SOURCE_MAP.json +39 -39
  8. package/dist/index.cjs +12 -12
  9. package/dist/index.js +4 -4
  10. package/dist/{observational-memory-HBQCXPBU.cjs → observational-memory-4VT6QEB7.cjs} +26 -26
  11. package/dist/{observational-memory-HBQCXPBU.cjs.map → observational-memory-4VT6QEB7.cjs.map} +1 -1
  12. package/dist/{observational-memory-WOEVNCG4.js → observational-memory-74TRS2R6.js} +3 -3
  13. package/dist/{observational-memory-WOEVNCG4.js.map → observational-memory-74TRS2R6.js.map} +1 -1
  14. package/dist/processors/index.cjs +24 -24
  15. package/dist/processors/index.js +1 -1
  16. package/dist/processors/observational-memory/observation-strategies/async-buffer.d.ts.map +1 -1
  17. package/dist/processors/observational-memory/observation-strategies/sync.d.ts.map +1 -1
  18. package/dist/processors/observational-memory/observation-turn/step.d.ts.map +1 -1
  19. package/dist/processors/observational-memory/observation-turn/types.d.ts +3 -0
  20. package/dist/processors/observational-memory/observation-turn/types.d.ts.map +1 -1
  21. package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -1
  22. package/dist/processors/observational-memory/observer-runner.d.ts +21 -0
  23. package/dist/processors/observational-memory/observer-runner.d.ts.map +1 -1
  24. package/dist/processors/observational-memory/processor.d.ts.map +1 -1
  25. package/dist/processors/observational-memory/repro-capture.d.ts +2 -0
  26. package/dist/processors/observational-memory/repro-capture.d.ts.map +1 -1
  27. package/package.json +5 -5
  28. package/dist/chunk-O3KNDDJV.cjs.map +0 -1
  29. package/dist/chunk-ZVRY34YB.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @mastra/memory
2
2
 
3
+ ## 1.13.1-alpha.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Fixed thread titles not persisting when generated during async buffered observation. Titles now update immediately when the observer produces them, rather than being lost until activation. ([#14992](https://github.com/mastra-ai/mastra/pull/14992))
8
+
9
+ - Updated dependencies [[`cb15509`](https://github.com/mastra-ai/mastra/commit/cb15509b58f6a83e11b765c945082afc027db972), [`80c5668`](https://github.com/mastra-ai/mastra/commit/80c5668e365470d3a96d3e953868fd7a643ff67c), [`3d478c1`](https://github.com/mastra-ai/mastra/commit/3d478c1e13f17b80f330ac49d7aa42ef929b93ff), [`6039f17`](https://github.com/mastra-ai/mastra/commit/6039f176f9c457304825ff1df8c83b8e457376c0), [`06b928d`](https://github.com/mastra-ai/mastra/commit/06b928dfc2f5630d023467476cc5919dfa858d0a), [`6a8d984`](https://github.com/mastra-ai/mastra/commit/6a8d9841f2933456ee1598099f488d742b600054)]:
10
+ - @mastra/core@1.22.0-alpha.2
11
+
3
12
  ## 1.13.0
4
13
 
5
14
  ### Minor Changes
@@ -1406,8 +1406,6 @@ var SyncObservationStrategy = class extends ObservationStrategy {
1406
1406
  }
1407
1407
  }
1408
1408
  };
1409
-
1410
- // src/processors/observational-memory/observation-strategies/async-buffer.ts
1411
1409
  var AsyncBufferObservationStrategy = class extends ObservationStrategy {
1412
1410
  startedAt;
1413
1411
  cycleId;
@@ -1498,6 +1496,30 @@ var AsyncBufferObservationStrategy = class extends ObservationStrategy {
1498
1496
  lastBufferedAtTime: processed.lastObservedAt
1499
1497
  });
1500
1498
  await this.indexObservationGroups(processed.observations, threadId, resourceId, processed.lastObservedAt);
1499
+ const newTitle = processed.threadTitle?.trim();
1500
+ if (newTitle && newTitle.length >= 3) {
1501
+ const thread = await this.storage.getThreadById({ threadId });
1502
+ if (thread) {
1503
+ const oldTitle = thread.title?.trim();
1504
+ if (newTitle !== oldTitle) {
1505
+ const newMetadata = memory.setThreadOMMetadata(thread.metadata, {
1506
+ threadTitle: processed.threadTitle
1507
+ });
1508
+ await this.storage.updateThread({
1509
+ id: threadId,
1510
+ title: newTitle,
1511
+ metadata: newMetadata
1512
+ });
1513
+ const marker = createThreadUpdateMarker({
1514
+ cycleId: this.cycleId,
1515
+ threadId,
1516
+ oldTitle,
1517
+ newTitle
1518
+ });
1519
+ await this.streamMarker(marker);
1520
+ }
1521
+ }
1522
+ }
1501
1523
  }
1502
1524
  async emitEndMarkers(_cycleId, processed) {
1503
1525
  if (!processed.observations || !this.opts.writer) return;
@@ -1952,6 +1974,7 @@ var ObservationStep = class {
1952
1974
  let buffered = false;
1953
1975
  let reflected = false;
1954
1976
  let didThresholdCleanup = false;
1977
+ let observerExchange;
1955
1978
  if (this.stepNumber === 0) {
1956
1979
  const step0Messages = messageList.get.all.db();
1957
1980
  const activation = await om.activate({
@@ -2050,6 +2073,7 @@ var ObservationStep = class {
2050
2073
  if (statusSnapshot.shouldObserve && !hasIncompleteToolCalls) {
2051
2074
  const preObsGeneration = this.turn.record.generationCount;
2052
2075
  const obsResult = await this.runThresholdObservation();
2076
+ observerExchange = obsResult.observerExchange;
2053
2077
  if (obsResult.succeeded) {
2054
2078
  observed = true;
2055
2079
  didThresholdCleanup = true;
@@ -2103,6 +2127,7 @@ var ObservationStep = class {
2103
2127
  }
2104
2128
  this._context = {
2105
2129
  systemMessage,
2130
+ observerExchange,
2106
2131
  activated,
2107
2132
  observed,
2108
2133
  buffered,
@@ -2170,7 +2195,11 @@ var ObservationStep = class {
2170
2195
  writer: this.turn.writer,
2171
2196
  observabilityContext: this.turn.observabilityContext
2172
2197
  });
2173
- return { succeeded: obsResult.observed, record: obsResult.record };
2198
+ return {
2199
+ succeeded: obsResult.observed,
2200
+ record: obsResult.record,
2201
+ observerExchange: om.observer.lastExchange
2202
+ };
2174
2203
  }
2175
2204
  };
2176
2205
 
@@ -3496,6 +3525,8 @@ var ObserverRunner = class {
3496
3525
  observedMessageIds;
3497
3526
  resolveModel;
3498
3527
  tokenCounter;
3528
+ /** Captured prompt/response from the last observer call (for repro capture). */
3529
+ lastExchange;
3499
3530
  constructor(opts) {
3500
3531
  this.observationConfig = opts.observationConfig;
3501
3532
  this.observedMessageIds = opts.observedMessageIds;
@@ -3571,15 +3602,38 @@ var ObserverRunner = class {
3571
3602
  };
3572
3603
  let result = await doGenerate();
3573
3604
  let parsed = parseObserverOutput(result.text);
3605
+ let retriedDueToDegenerate = false;
3574
3606
  if (parsed.degenerate) {
3575
3607
  omDebug(`[OM:callObserver] degenerate repetition detected, retrying once`);
3576
3608
  result = await doGenerate();
3577
3609
  parsed = parseObserverOutput(result.text);
3610
+ retriedDueToDegenerate = true;
3578
3611
  if (parsed.degenerate) {
3579
3612
  omDebug(`[OM:callObserver] degenerate repetition on retry, failing`);
3580
3613
  throw new Error("Observer produced degenerate output after retry");
3581
3614
  }
3582
3615
  }
3616
+ const systemPrompt = buildObserverSystemPrompt(
3617
+ false,
3618
+ this.observationConfig.instruction,
3619
+ this.observationConfig.threadTitle
3620
+ );
3621
+ this.lastExchange = {
3622
+ systemPrompt,
3623
+ observerMessages,
3624
+ rawOutput: result.text,
3625
+ parsedResult: {
3626
+ observations: parsed.observations,
3627
+ currentTask: parsed.currentTask,
3628
+ suggestedContinuation: parsed.suggestedContinuation,
3629
+ threadTitle: parsed.threadTitle,
3630
+ degenerate: parsed.degenerate
3631
+ },
3632
+ model: String(resolvedModel.model),
3633
+ inputTokens,
3634
+ isMultiThread: false,
3635
+ retriedDueToDegenerate
3636
+ };
3583
3637
  const usage = result.totalUsage ?? result.usage;
3584
3638
  return {
3585
3639
  observations: parsed.observations,
@@ -3646,15 +3700,36 @@ var ObserverRunner = class {
3646
3700
  };
3647
3701
  let result = await doGenerate();
3648
3702
  let parsed = parseMultiThreadObserverOutput(result.text);
3703
+ let retriedDueToDegenerate = false;
3649
3704
  if (parsed.degenerate) {
3650
3705
  omDebug(`[OM:callMultiThreadObserver] degenerate repetition detected, retrying once`);
3651
3706
  result = await doGenerate();
3652
3707
  parsed = parseMultiThreadObserverOutput(result.text);
3708
+ retriedDueToDegenerate = true;
3653
3709
  if (parsed.degenerate) {
3654
3710
  omDebug(`[OM:callMultiThreadObserver] degenerate repetition on retry, failing`);
3655
3711
  throw new Error("Multi-thread observer produced degenerate output after retry");
3656
3712
  }
3657
3713
  }
3714
+ const systemPrompt = buildObserverSystemPrompt(
3715
+ true,
3716
+ this.observationConfig.instruction,
3717
+ this.observationConfig.threadTitle
3718
+ );
3719
+ this.lastExchange = {
3720
+ systemPrompt,
3721
+ observerMessages,
3722
+ rawOutput: result.text,
3723
+ parsedResult: {
3724
+ observations: Array.from(parsed.threads.values()).map((t) => t.observations).join("\n"),
3725
+ threadTitle: Array.from(parsed.threads.values()).map((t) => t.threadTitle).filter(Boolean).join(", "),
3726
+ degenerate: parsed.degenerate
3727
+ },
3728
+ model: String(resolvedModel.model),
3729
+ inputTokens,
3730
+ isMultiThread: true,
3731
+ retriedDueToDegenerate
3732
+ };
3658
3733
  const results = /* @__PURE__ */ new Map();
3659
3734
  for (const [threadId, threadResult] of parsed.threads) {
3660
3735
  results.set(threadId, {
@@ -7803,13 +7878,18 @@ ${grouped}` : grouped;
7803
7878
  const activatedChunks = freshChunks.filter((c) => activationResult.activatedCycleIds.includes(c.cycleId));
7804
7879
  const lastActivated = activatedChunks[activatedChunks.length - 1];
7805
7880
  if (lastActivated) {
7881
+ const chunkThreadTitle = lastActivated.threadTitle;
7806
7882
  const newMetadata = memory.setThreadOMMetadata(thread.metadata, {
7807
7883
  suggestedResponse: lastActivated.suggestedContinuation,
7808
- currentTask: lastActivated.currentTask
7884
+ currentTask: lastActivated.currentTask,
7885
+ threadTitle: chunkThreadTitle
7809
7886
  });
7887
+ const oldTitle = thread.title?.trim();
7888
+ const newTitle = chunkThreadTitle?.trim();
7889
+ const shouldUpdateThreadTitle = !!newTitle && newTitle.length >= 3 && newTitle !== oldTitle;
7810
7890
  await this.storage.updateThread({
7811
7891
  id: threadId,
7812
- title: thread.title ?? "",
7892
+ title: shouldUpdateThreadTitle ? newTitle : thread.title ?? "",
7813
7893
  metadata: newMetadata
7814
7894
  });
7815
7895
  }
@@ -8244,6 +8324,20 @@ function writeProcessInputStepReproCapture(params) {
8244
8324
  `
8245
8325
  );
8246
8326
  }
8327
+ if (params.observerExchange) {
8328
+ const serialized = safeCaptureJsonOrError(params.observerExchange);
8329
+ if (serialized.ok) {
8330
+ fs.writeFileSync(path.join(captureDir, "observer-exchange.json"), `${JSON.stringify(serialized.value, null, 2)}
8331
+ `);
8332
+ } else {
8333
+ captureErrors.push({ fileName: "observer-exchange.json", error: serialized.error });
8334
+ fs.writeFileSync(
8335
+ path.join(captureDir, "observer-exchange.json"),
8336
+ `${JSON.stringify({ __captureError: serialized.error }, null, 2)}
8337
+ `
8338
+ );
8339
+ }
8340
+ }
8247
8341
  if (captureErrors.length > 0) {
8248
8342
  fs.writeFileSync(path.join(captureDir, "capture-error.json"), `${JSON.stringify(captureErrors, null, 2)}
8249
8343
  `);
@@ -8408,7 +8502,8 @@ var ObservationalMemoryProcessor = class {
8408
8502
  postBufferedChunks: [],
8409
8503
  postContextTokenCount: finalTotalPending,
8410
8504
  messageList,
8411
- details: {}
8505
+ details: {},
8506
+ observerExchange: ctx.observerExchange
8412
8507
  });
8413
8508
  }
8414
8509
  }
@@ -8496,5 +8591,5 @@ exports.stripEphemeralAnchorIds = stripEphemeralAnchorIds;
8496
8591
  exports.stripObservationGroups = stripObservationGroups;
8497
8592
  exports.truncateStringByTokens = truncateStringByTokens;
8498
8593
  exports.wrapInObservationGroup = wrapInObservationGroup;
8499
- //# sourceMappingURL=chunk-O3KNDDJV.cjs.map
8500
- //# sourceMappingURL=chunk-O3KNDDJV.cjs.map
8594
+ //# sourceMappingURL=chunk-HNVSYZRA.cjs.map
8595
+ //# sourceMappingURL=chunk-HNVSYZRA.cjs.map