@mastra/server 1.65.0 → 1.66.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.
@@ -4694,7 +4694,7 @@ function splitLines(text) {
4694
4694
  return result;
4695
4695
  }
4696
4696
  //#endregion
4697
- //#region ../memory/dist/src-BFP4tRqs.js
4697
+ //#region ../memory/dist/src-DuA6bRSI.js
4698
4698
  var __defProp$3 = Object.defineProperty;
4699
4699
  var __exportAll = (all, no_symbols) => {
4700
4700
  let target = {};
@@ -24354,6 +24354,35 @@ async function withOmTracingSpan({ phase, model, inputTokens, requestContext, ob
24354
24354
  }
24355
24355
  });
24356
24356
  }
24357
+ /**
24358
+ * Run the `beforeObservation` transform hook. Returns the (possibly replaced)
24359
+ * message array; `undefined` from the hook means passthrough.
24360
+ */
24361
+ async function applyBeforeObservation(hooks, messages, context) {
24362
+ if (!hooks?.beforeObservation) return messages;
24363
+ const result = await hooks.beforeObservation({
24364
+ ...context,
24365
+ messages
24366
+ });
24367
+ if (!result) return messages;
24368
+ omDebug(`[OM:hooks] beforeObservation replaced messages: ${messages.length} -> ${result.messages.length}`);
24369
+ return result.messages;
24370
+ }
24371
+ /**
24372
+ * Run one of the text transform hooks. Returns the (possibly replaced)
24373
+ * observation text; `undefined` from the hook means passthrough.
24374
+ */
24375
+ async function applyTextTransform(hooks, name, observations, context) {
24376
+ const hook = hooks?.[name];
24377
+ if (!hook) return observations;
24378
+ const result = await hook({
24379
+ ...context,
24380
+ observations
24381
+ });
24382
+ if (!result) return observations;
24383
+ omDebug(`[OM:hooks] ${name} replaced observations: ${observations.length} -> ${result.observations.length} chars`);
24384
+ return result.observations;
24385
+ }
24357
24386
  function filterObserverExtractors(extractors, skipContinuationHints) {
24358
24387
  const configuredExtractors = extractors ?? [];
24359
24388
  if (!skipContinuationHints) return configuredExtractors;
@@ -24365,6 +24394,7 @@ var ObserverRunner = class {
24365
24394
  resolveModel;
24366
24395
  tokenCounter;
24367
24396
  memory;
24397
+ hooks;
24368
24398
  mastra;
24369
24399
  /** Captured prompt/response from the last observer call (for repro capture). */
24370
24400
  lastExchange;
@@ -24375,6 +24405,7 @@ var ObserverRunner = class {
24375
24405
  this.tokenCounter = opts.tokenCounter;
24376
24406
  this.mastra = opts.mastra;
24377
24407
  this.memory = opts.memory;
24408
+ this.hooks = opts.hooks;
24378
24409
  }
24379
24410
  __registerMastra(mastra) {
24380
24411
  this.mastra = mastra;
@@ -24428,9 +24459,25 @@ var ObserverRunner = class {
24428
24459
  return result;
24429
24460
  }
24430
24461
  /**
24431
- * Call the Observer agent for a single thread.
24462
+ * Call the Observer agent for a single thread, running the config-level
24463
+ * `beforeObservation` / `afterObservation` transform hooks around it.
24432
24464
  */
24433
24465
  async call(existingObservations, messagesToObserve, abortSignal, options) {
24466
+ const context = {
24467
+ threadId: options?.threadId ?? messagesToObserve[0]?.threadId,
24468
+ resourceId: options?.resourceId,
24469
+ trigger: options?.trigger
24470
+ };
24471
+ const messages = await applyBeforeObservation(this.hooks, messagesToObserve, context);
24472
+ if (messages.length === 0) {
24473
+ omDebug("[OM:callObserver] beforeObservation returned no messages, skipping observer call");
24474
+ return { observations: "" };
24475
+ }
24476
+ const result = await this.callObserver(existingObservations, messages, abortSignal, options);
24477
+ result.observations = await applyTextTransform(this.hooks, "afterObservation", result.observations, context);
24478
+ return result;
24479
+ }
24480
+ async callObserver(existingObservations, messagesToObserve, abortSignal, options) {
24434
24481
  const inputTokens = this.tokenCounter.countMessages(messagesToObserve);
24435
24482
  const resolvedModel = options?.model ? { model: options.model } : this.resolveModel(inputTokens);
24436
24483
  const activeExtractors = await resolveExtractors(filterObserverExtractors(this.observationConfig.extractors, options?.skipContinuationHints), {
@@ -24549,7 +24596,30 @@ var ObserverRunner = class {
24549
24596
  /**
24550
24597
  * Call the Observer agent for multiple threads in a single batched request.
24551
24598
  */
24552
- async callMultiThread(existingObservations, messagesByThread, threadOrder, abortSignal, requestContext, priorMetadataByThread, observabilityContext, model) {
24599
+ async callMultiThread(existingObservations, allMessagesByThread, allThreadOrder, abortSignal, requestContext, priorMetadataByThread, observabilityContext, model, hookContext) {
24600
+ const contextFor = (threadId) => ({
24601
+ threadId,
24602
+ ...hookContext
24603
+ });
24604
+ const messagesByThread = /* @__PURE__ */ new Map();
24605
+ for (const threadId of allThreadOrder) {
24606
+ const filtered = await applyBeforeObservation(this.hooks, allMessagesByThread.get(threadId) ?? [], contextFor(threadId));
24607
+ if (filtered.length > 0) messagesByThread.set(threadId, filtered);
24608
+ }
24609
+ const threadOrder = allThreadOrder.filter((threadId) => messagesByThread.has(threadId));
24610
+ const output = await this.callMultiThreadObserver(existingObservations, messagesByThread, threadOrder, abortSignal, requestContext, priorMetadataByThread, observabilityContext, model);
24611
+ for (const threadId of allThreadOrder) {
24612
+ const threadResult = output.results.get(threadId);
24613
+ if (!threadResult) {
24614
+ output.results.set(threadId, { observations: "" });
24615
+ continue;
24616
+ }
24617
+ threadResult.observations = await applyTextTransform(this.hooks, "afterObservation", threadResult.observations, contextFor(threadId));
24618
+ }
24619
+ return output;
24620
+ }
24621
+ async callMultiThreadObserver(existingObservations, messagesByThread, threadOrder, abortSignal, requestContext, priorMetadataByThread, observabilityContext, model) {
24622
+ if (threadOrder.length === 0) return { results: /* @__PURE__ */ new Map() };
24553
24623
  const inputTokens = Array.from(messagesByThread.values()).reduce((total, messages) => total + this.tokenCounter.countMessages(messages), 0);
24554
24624
  const resolvedModel = model ? { model } : this.resolveModel(inputTokens);
24555
24625
  const firstThreadMessages = messagesByThread.get(threadOrder[0] ?? "") ?? [];
@@ -24568,7 +24638,7 @@ var ObserverRunner = class {
24568
24638
  totalTokens: 0
24569
24639
  };
24570
24640
  for (const threadId of threadOrder) {
24571
- const threadResult = await this.call(existingObservations, messagesByThread.get(threadId) ?? [], abortSignal, {
24641
+ const threadResult = await this.callObserver(existingObservations, messagesByThread.get(threadId) ?? [], abortSignal, {
24572
24642
  requestContext,
24573
24643
  observabilityContext,
24574
24644
  priorCurrentTask: priorMetadataByThread?.get(threadId)?.currentTask,
@@ -28591,6 +28661,7 @@ var ObservationStrategy = class ObservationStrategy {
28591
28661
  sendSignal: this.opts.sendSignal,
28592
28662
  sendStateSignal: this.opts.sendStateSignal,
28593
28663
  reflectionHooks,
28664
+ trigger: this.opts.trigger,
28594
28665
  requestContext,
28595
28666
  observabilityContext: this.opts.observabilityContext
28596
28667
  });
@@ -28869,7 +28940,9 @@ var SyncObservationStrategy = class extends ObservationStrategy {
28869
28940
  priorSuggestedResponse: omMeta?.suggestedResponse,
28870
28941
  priorThreadTitle: omMeta?.threadTitle,
28871
28942
  priorExtractedValues: this.priorExtractedValues,
28943
+ threadId: this.opts.threadId,
28872
28944
  resourceId: this.opts.resourceId,
28945
+ trigger: this.opts.trigger,
28873
28946
  mainAgent: this.opts.agent
28874
28947
  });
28875
28948
  const hookedValues = await applyExtractorHooks({
@@ -29052,7 +29125,9 @@ var AsyncBufferObservationStrategy = class extends ObservationStrategy {
29052
29125
  requestContext: this.opts.requestContext,
29053
29126
  observabilityContext: this.opts.observabilityContext,
29054
29127
  priorExtractedValues: this.priorExtractedValues,
29128
+ threadId: this.opts.threadId,
29055
29129
  resourceId: this.opts.resourceId,
29130
+ trigger: this.opts.trigger,
29056
29131
  mainAgent: this.opts.agent
29057
29132
  });
29058
29133
  const hookedValues = await applyExtractorHooks({
@@ -29374,7 +29449,10 @@ var ResourceScopedObservationStrategy = class extends ObservationStrategy {
29374
29449
  }
29375
29450
  if (currentBatch.threadIds.length > 0) batches.push(currentBatch);
29376
29451
  const batchResults = await Promise.all(batches.map(async (batch) => {
29377
- return this.deps.observer.callMultiThread(_existingObservations, batch.threadMap, batch.threadIds, this.opts.abortSignal, this.opts.requestContext, this.priorMetadataByThread, this.opts.observabilityContext);
29452
+ return this.deps.observer.callMultiThread(_existingObservations, batch.threadMap, batch.threadIds, this.opts.abortSignal, this.opts.requestContext, this.priorMetadataByThread, this.opts.observabilityContext, void 0, {
29453
+ resourceId: this.opts.resourceId,
29454
+ trigger: this.opts.trigger
29455
+ });
29378
29456
  }));
29379
29457
  for (const batchResult of batchResults) {
29380
29458
  for (const [threadId, result] of batchResult.results) this.multiThreadResults.set(threadId, result);
@@ -29706,7 +29784,8 @@ var ObservationStep = class {
29706
29784
  threadId,
29707
29785
  resourceId,
29708
29786
  trigger: "turn-sync"
29709
- })
29787
+ }),
29788
+ trigger: "turn-sync"
29710
29789
  });
29711
29790
  await this.turn.refreshRecord();
29712
29791
  if (this.turn.record.generationCount > preReflectGeneration) reflected = true;
@@ -29909,7 +29988,8 @@ var ObservationStep = class {
29909
29988
  threadId,
29910
29989
  resourceId,
29911
29990
  trigger: "turn-sync"
29912
- })
29991
+ }),
29992
+ trigger: "turn-sync"
29913
29993
  });
29914
29994
  return {
29915
29995
  succeeded: true,
@@ -30540,6 +30620,7 @@ var ReflectorRunner = class {
30540
30620
  getCompressionStartLevel;
30541
30621
  memory;
30542
30622
  onReflectionCommitted;
30623
+ hooks;
30543
30624
  mastra;
30544
30625
  /**
30545
30626
  * Per-lock-key observation-token count of the last unproductive synchronous
@@ -30571,6 +30652,7 @@ var ReflectorRunner = class {
30571
30652
  this.mastra = opts.mastra;
30572
30653
  this.memory = opts.memory;
30573
30654
  this.onReflectionCommitted = opts.onReflectionCommitted;
30655
+ this.hooks = opts.hooks;
30574
30656
  }
30575
30657
  __registerMastra(mastra) {
30576
30658
  this.mastra = mastra;
@@ -30793,7 +30875,7 @@ var ReflectorRunner = class {
30793
30875
  /**
30794
30876
  * Start an async buffered reflection in the background.
30795
30877
  */
30796
- startAsyncBufferedReflection(record, observationTokens, lockKey, writer, requestContext, observabilityContext, reflectionHooks, priorExtractedValues, mainAgent, sendSignal) {
30878
+ startAsyncBufferedReflection(record, observationTokens, lockKey, writer, requestContext, observabilityContext, reflectionHooks, priorExtractedValues, mainAgent, sendSignal, trigger) {
30797
30879
  const bufferKey = this.buffering.getReflectionBufferKey(lockKey);
30798
30880
  if (this.buffering.isAsyncBufferingInProgress(bufferKey)) return;
30799
30881
  BufferingCoordinator.lastBufferedBoundary.set(bufferKey, observationTokens);
@@ -30806,7 +30888,7 @@ var ReflectorRunner = class {
30806
30888
  let reflectionError;
30807
30889
  try {
30808
30890
  await reflectionHooks?.onReflectionStart?.();
30809
- outcome = await this.doAsyncBufferedReflection(record, bufferKey, writer, requestContext, observabilityContext, priorExtractedValues, mainAgent, sendSignal);
30891
+ outcome = await this.doAsyncBufferedReflection(record, bufferKey, writer, requestContext, observabilityContext, priorExtractedValues, mainAgent, sendSignal, trigger);
30810
30892
  } catch (error) {
30811
30893
  reflectionError = error instanceof Error ? error : new Error(String(error));
30812
30894
  if (writer) try {
@@ -30852,7 +30934,7 @@ var ReflectorRunner = class {
30852
30934
  * Perform async buffered reflection — reflects observations and stores to bufferedReflection.
30853
30935
  * Does NOT create a new generation or update activeObservations.
30854
30936
  */
30855
- async doAsyncBufferedReflection(record, _bufferKey, writer, requestContext, observabilityContext, priorExtractedValues, mainAgent, sendSignal) {
30937
+ async doAsyncBufferedReflection(record, _bufferKey, writer, requestContext, observabilityContext, priorExtractedValues, mainAgent, sendSignal, trigger) {
30856
30938
  const currentRecord = await this.storage.getObservationalMemory(record.threadId, record.resourceId) ?? record;
30857
30939
  const observationTokens = currentRecord.observationTokenCount ?? 0;
30858
30940
  const reflectThreshold = getMaxThreshold(this.getEffectiveReflectionTokens(currentRecord));
@@ -30865,7 +30947,12 @@ var ReflectorRunner = class {
30865
30947
  const avgTokensPerLine = totalLines > 0 ? observationTokens / totalLines : 0;
30866
30948
  const activationPointTokens = reflectThreshold * bufferActivation;
30867
30949
  const linesToReflect = avgTokensPerLine > 0 ? Math.min(Math.floor(activationPointTokens / avgTokensPerLine), totalLines) : totalLines;
30868
- const activeObservations = allLines.slice(0, linesToReflect).join("\n");
30950
+ const hookContext = {
30951
+ threadId: currentRecord.threadId ?? void 0,
30952
+ resourceId: currentRecord.resourceId ?? void 0,
30953
+ trigger
30954
+ };
30955
+ const activeObservations = await applyTextTransform(this.hooks, "beforeReflection", allLines.slice(0, linesToReflect).join("\n"), hookContext);
30869
30956
  const reflectedObservationLineCount = linesToReflect;
30870
30957
  const sliceTokenEstimate = Math.round(avgTokensPerLine * linesToReflect);
30871
30958
  const compressionTarget = Math.round(sliceTokenEstimate * .75);
@@ -30889,6 +30976,7 @@ var ReflectorRunner = class {
30889
30976
  }
30890
30977
  const compressionStartLevel = await this.getCompressionStartLevel(requestContext);
30891
30978
  const reflectResult = await this.call(activeObservations, void 0, void 0, compressionTarget, void 0, true, compressionStartLevel, requestContext, priorExtractedValues, observabilityContext, void 0, mainAgent, sendSignal);
30979
+ reflectResult.observations = await applyTextTransform(this.hooks, "afterReflection", reflectResult.observations, hookContext);
30892
30980
  await persistThreadExtractedValues(this.storage, this.reflectionConfig.extractors, currentRecord.threadId ?? void 0, reflectResult.extractedValues);
30893
30981
  const reflectionTokenCount = this.tokenCounter.countObservations(reflectResult.observations);
30894
30982
  omDebug(`[OM:reflect] doAsyncBufferedReflection: reflector returned ${reflectionTokenCount} tokens (${reflectResult.observations?.length} chars), saving to recordId=${currentRecord.id}`);
@@ -31035,7 +31123,7 @@ var ReflectorRunner = class {
31035
31123
  * @internal Used by observation strategies. Do not call directly.
31036
31124
  */
31037
31125
  async maybeReflect(opts) {
31038
- const { record, observationTokens, writer, abortSignal, mainAgent, sendSignal, sendStateSignal, messageList, currentModel, reflectionHooks, requestContext, observabilityContext, lastActivityAt, threadId: requestedThreadId } = opts;
31126
+ const { record, observationTokens, writer, abortSignal, mainAgent, sendSignal, sendStateSignal, messageList, currentModel, reflectionHooks, trigger, requestContext, observabilityContext, lastActivityAt, threadId: requestedThreadId } = opts;
31039
31127
  const lockKey = this.buffering.getLockKey(record.threadId, record.resourceId);
31040
31128
  const reflectThreshold = getMaxThreshold(this.getEffectiveReflectionTokens(record));
31041
31129
  const priorExtractedValues = await getThreadExtractedValues(this.storage, this.reflectionConfig.extractors, requestedThreadId ?? record.threadId);
@@ -31053,7 +31141,7 @@ var ReflectorRunner = class {
31053
31141
  if (record.bufferedReflection) return false;
31054
31142
  const activationPoint = reflectThreshold * this.reflectionConfig.bufferActivation;
31055
31143
  return observationTokens >= activationPoint;
31056
- })()) this.startAsyncBufferedReflection(record, observationTokens, lockKey, writer, requestContext, observabilityContext, reflectionHooks, priorExtractedValues, mainAgent, sendSignal);
31144
+ })()) this.startAsyncBufferedReflection(record, observationTokens, lockKey, writer, requestContext, observabilityContext, reflectionHooks, priorExtractedValues, mainAgent, sendSignal, trigger);
31057
31145
  }
31058
31146
  const activateAfterIdle = resolveActivationTTL(this.reflectionConfig.activateAfterIdle, currentModel);
31059
31147
  const ttlExpiredMs = activateAfterIdle !== void 0 && lastActivityAt !== void 0 ? Date.now() - lastActivityAt : void 0;
@@ -31102,7 +31190,7 @@ var ReflectorRunner = class {
31102
31190
  return;
31103
31191
  }
31104
31192
  omDebug(`[OM:reflect] async activation failed, no blockAfter or below it (obsTokens=${observationTokens}, blockAfter=${this.reflectionConfig.blockAfter}) — starting background reflection`);
31105
- this.startAsyncBufferedReflection(record, observationTokens, lockKey, writer, requestContext, observabilityContext, reflectionHooks, priorExtractedValues, mainAgent, sendSignal);
31193
+ this.startAsyncBufferedReflection(record, observationTokens, lockKey, writer, requestContext, observabilityContext, reflectionHooks, priorExtractedValues, mainAgent, sendSignal, trigger);
31106
31194
  return;
31107
31195
  }
31108
31196
  }
@@ -31163,7 +31251,13 @@ var ReflectorRunner = class {
31163
31251
  throw error;
31164
31252
  }
31165
31253
  const compressionStartLevel = await this.getCompressionStartLevel(requestContext);
31166
- const reflectResult = await this.call(record.activeObservations, void 0, streamContext, reflectThreshold, abortSignal, void 0, compressionStartLevel, requestContext, priorExtractedValues, observabilityContext, void 0, mainAgent, sendSignal);
31254
+ const hookContext = {
31255
+ threadId: requestedThreadId ?? record.threadId ?? void 0,
31256
+ resourceId: record.resourceId ?? void 0,
31257
+ trigger
31258
+ };
31259
+ const reflectResult = await this.call(await applyTextTransform(this.hooks, "beforeReflection", record.activeObservations, hookContext), void 0, streamContext, reflectThreshold, abortSignal, void 0, compressionStartLevel, requestContext, priorExtractedValues, observabilityContext, void 0, mainAgent, sendSignal);
31260
+ reflectResult.observations = await applyTextTransform(this.hooks, "afterReflection", reflectResult.observations, hookContext);
31167
31261
  reflectionUsage = reflectResult.usage;
31168
31262
  reflectionProviderMetadata = reflectResult.providerMetadata;
31169
31263
  await persistThreadExtractedValues(this.storage, this.reflectionConfig.extractors, record.threadId ?? void 0, reflectResult.extractedValues);
@@ -31910,7 +32004,8 @@ var ObservationalMemory = class ObservationalMemory {
31910
32004
  resolveModel: (inputTokens) => this.resolveObservationModel(inputTokens),
31911
32005
  tokenCounter: this.tokenCounter,
31912
32006
  mastra: config.mastra,
31913
- memory: this.memory
32007
+ memory: this.memory,
32008
+ hooks: this.hooks
31914
32009
  });
31915
32010
  this.buffering = new BufferingCoordinator({
31916
32011
  observationConfig: this.observationConfig,
@@ -31931,7 +32026,8 @@ var ObservationalMemory = class ObservationalMemory {
31931
32026
  resolveModel: (inputTokens) => this.resolveReflectionModel(inputTokens),
31932
32027
  mastra: config.mastra,
31933
32028
  memory: this.memory,
31934
- onReflectionCommitted: config.onReflectionCommitted
32029
+ onReflectionCommitted: config.onReflectionCommitted,
32030
+ hooks: this.hooks
31935
32031
  });
31936
32032
  this.validateBufferConfig();
31937
32033
  omDebug(`[OM:init] new ObservationalMemory instance created — 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}`);
@@ -32787,7 +32883,8 @@ ${formattedMessages}
32787
32883
  startedAt,
32788
32884
  writer,
32789
32885
  requestContext,
32790
- observabilityContext
32886
+ observabilityContext,
32887
+ trigger: "async-buffer"
32791
32888
  }).run());
32792
32889
  const maxTs = this.getMaxMessageTimestamp(messagesToBuffer);
32793
32890
  const cursor = new Date(maxTs.getTime() + 1);
@@ -33408,7 +33505,8 @@ ${formattedMessages}
33408
33505
  sendStateSignal: opts.sendStateSignal,
33409
33506
  requestContext,
33410
33507
  currentModel: opts.currentModel,
33411
- observabilityContext
33508
+ observabilityContext,
33509
+ trigger: "async-buffer"
33412
33510
  }).run());
33413
33511
  if (isOmReproCaptureEnabled()) writeObserverExchangeReproCapture({
33414
33512
  threadId,
@@ -33722,10 +33820,11 @@ ${formattedMessages}
33722
33820
  async observe(opts) {
33723
33821
  const { threadId, resourceId, messages, requestContext } = opts;
33724
33822
  const lockKey = this.buffering.getLockKey(threadId, resourceId);
33823
+ const trigger = opts.trigger ?? "manual";
33725
33824
  const hooks = this.composeHooks(opts.hooks, {
33726
33825
  threadId,
33727
33826
  resourceId,
33728
- trigger: opts.trigger ?? "manual"
33827
+ trigger
33729
33828
  });
33730
33829
  const reflectionHooks = hooks ? {
33731
33830
  onReflectionStart: hooks.onReflectionStart,
@@ -33756,6 +33855,7 @@ ${formattedMessages}
33756
33855
  messages: unobservedMessages,
33757
33856
  messageList: opts.messageList,
33758
33857
  reflectionHooks,
33858
+ trigger,
33759
33859
  agent: opts.agent,
33760
33860
  sendSignal: opts.sendSignal,
33761
33861
  sendStateSignal: opts.sendStateSignal,
@@ -33822,11 +33922,12 @@ ${formattedMessages}
33822
33922
  }
33823
33923
  await this.storage.setReflectingFlag(record.id, true);
33824
33924
  registerOp(record.id, "reflecting");
33825
- const hooks = this.composeHooks(void 0, {
33925
+ const hookContext = {
33826
33926
  threadId,
33827
33927
  resourceId,
33828
33928
  trigger: "manual"
33829
- });
33929
+ };
33930
+ const hooks = this.composeHooks(void 0, hookContext);
33830
33931
  let reflectionUsage;
33831
33932
  let reflectionProviderMetadata;
33832
33933
  let reflectionError;
@@ -33843,7 +33944,8 @@ ${formattedMessages}
33843
33944
  const previousOmMetadata = (0, _mastra_core_memory.getThreadOMMetadata)(thread?.metadata);
33844
33945
  const priorExtractedValues = getPriorExtractedValues(previousOmMetadata, this.reflectionConfig.extractors);
33845
33946
  const reflectThreshold = getMaxThreshold(this.getEffectiveReflectionTokens(record));
33846
- const reflectResult = await this.reflector.call(record.activeObservations, prompt, void 0, reflectThreshold, void 0, void 0, void 0, requestContext, priorExtractedValues, observabilityContext, void 0);
33947
+ const reflectResult = await this.reflector.call(await applyTextTransform(this.hooks, "beforeReflection", record.activeObservations, hookContext), prompt, void 0, reflectThreshold, void 0, void 0, void 0, requestContext, priorExtractedValues, observabilityContext, void 0);
33948
+ reflectResult.observations = await applyTextTransform(this.hooks, "afterReflection", reflectResult.observations, hookContext);
33847
33949
  const reflectionTokenCount = this.tokenCounter.countObservations(reflectResult.observations);
33848
33950
  await this.storage.createReflectionGeneration({
33849
33951
  currentRecord: record,
@@ -34716,7 +34818,7 @@ var Memory = class Memory extends _mastra_core_memory.MastraMemory {
34716
34818
  });
34717
34819
  }
34718
34820
  async recall(args) {
34719
- const { threadId, resourceId, perPage: perPageArg, page, orderBy, threadConfig, vectorSearchString, includeSystemReminders, filter } = args;
34821
+ const { threadId, resourceId, perPage: perPageArg, page, orderBy, threadConfig, vectorSearchString, includeSystemReminders, filter, includeTotal } = args;
34720
34822
  const config = this.getMergedThreadConfig(threadConfig || {});
34721
34823
  const semanticRecallEnabled = Boolean(config.semanticRecall);
34722
34824
  const span = this.createMemorySpan("recall", args.observabilityContext, {
@@ -34803,6 +34905,7 @@ var Memory = class Memory extends _mastra_core_memory.MastraMemory {
34803
34905
  page,
34804
34906
  orderBy: effectiveOrderBy,
34805
34907
  filter,
34908
+ ...includeTotal !== void 0 ? { includeTotal } : {},
34806
34909
  ...filteredVectorResults?.length ? { include: filteredVectorResults.map((r) => ({
34807
34910
  id: r.metadata?.message_id,
34808
34911
  threadId: r.metadata?.thread_id,
@@ -35415,6 +35518,7 @@ ${workingMemory}`;
35415
35518
  direction: "ASC"
35416
35519
  },
35417
35520
  perPage: false,
35521
+ includeTotal: false,
35418
35522
  filter: dateFilter
35419
35523
  })).messages;
35420
35524
  };
@@ -35428,6 +35532,7 @@ ${workingMemory}`;
35428
35532
  direction: "ASC"
35429
35533
  },
35430
35534
  perPage: false,
35535
+ includeTotal: false,
35431
35536
  filter: dateFilter
35432
35537
  })).messages;
35433
35538
  };
@@ -35443,7 +35548,8 @@ ${workingMemory}`;
35443
35548
  field: "createdAt",
35444
35549
  direction: "DESC"
35445
35550
  },
35446
- perPage: typeof lastMessages === "number" ? lastMessages : void 0
35551
+ perPage: typeof lastMessages === "number" ? lastMessages : void 0,
35552
+ includeTotal: false
35447
35553
  })).messages.reverse();
35448
35554
  }
35449
35555
  return {
@@ -35805,7 +35911,8 @@ Notes:
35805
35911
  threadId,
35806
35912
  resourceId,
35807
35913
  perPage: SUMMARIZE_THREAD_DEFAULTS.pageSize,
35808
- page
35914
+ page,
35915
+ includeTotal: false
35809
35916
  });
35810
35917
  if (batch.length === 0) break;
35811
35918
  let reachedLimit = false;
@@ -46839,4 +46946,4 @@ const agentBuilderWorkflows = {
46839
46946
  //#endregion
46840
46947
  exports.agentBuilderWorkflows = agentBuilderWorkflows;
46841
46948
 
46842
- //# sourceMappingURL=dist-BLP1i9vT.cjs.map
46949
+ //# sourceMappingURL=dist-BnPncT17.cjs.map