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