@mastra/memory 1.28.3-alpha.4 → 1.29.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/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-memory-message-history.md +1 -1
- package/dist/docs/references/docs-memory-multi-user-threads.md +1 -1
- package/dist/docs/references/docs-memory-observational-memory.md +41 -1
- package/dist/docs/references/docs-memory-overview.md +4 -4
- package/dist/docs/references/reference-memory-observational-memory.md +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/processors/index.cjs +1 -1
- package/dist/processors/index.js +1 -1
- package/dist/processors/observational-memory/index.d.ts +1 -1
- package/dist/processors/observational-memory/index.d.ts.map +1 -1
- package/dist/processors/observational-memory/observation-strategies/async-buffer.d.ts.map +1 -1
- package/dist/processors/observational-memory/observation-strategies/base.d.ts.map +1 -1
- package/dist/processors/observational-memory/observation-strategies/resource-scoped.d.ts.map +1 -1
- package/dist/processors/observational-memory/observation-strategies/sync.d.ts.map +1 -1
- package/dist/processors/observational-memory/observation-strategies/types.d.ts +3 -1
- package/dist/processors/observational-memory/observation-strategies/types.d.ts.map +1 -1
- package/dist/processors/observational-memory/observation-turn/step.d.ts.map +1 -1
- package/dist/processors/observational-memory/observational-memory.d.ts +3 -3
- package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -1
- package/dist/processors/observational-memory/observer-runner.d.ts +60 -46
- package/dist/processors/observational-memory/observer-runner.d.ts.map +1 -1
- package/dist/processors/observational-memory/processor.d.ts.map +1 -1
- package/dist/processors/observational-memory/reflector-runner.d.ts +5 -1
- package/dist/processors/observational-memory/reflector-runner.d.ts.map +1 -1
- package/dist/processors/observational-memory/transform-hooks.d.ts +15 -0
- package/dist/processors/observational-memory/transform-hooks.d.ts.map +1 -0
- package/dist/processors/observational-memory/types.d.ts +71 -2
- package/dist/processors/observational-memory/types.d.ts.map +1 -1
- package/dist/{src-D4Wm6M4v.cjs → src-CG7RR0Ep.cjs} +135 -26
- package/dist/src-CG7RR0Ep.cjs.map +1 -0
- package/dist/{src-BFP4tRqs.js → src-DuA6bRSI.js} +135 -26
- package/dist/src-DuA6bRSI.js.map +1 -0
- package/package.json +8 -8
- package/dist/src-BFP4tRqs.js.map +0 -1
- package/dist/src-D4Wm6M4v.cjs.map +0 -1
|
@@ -19789,6 +19789,37 @@ async function withOmTracingSpan({ phase, model, inputTokens, requestContext, ob
|
|
|
19789
19789
|
});
|
|
19790
19790
|
}
|
|
19791
19791
|
//#endregion
|
|
19792
|
+
//#region src/processors/observational-memory/transform-hooks.ts
|
|
19793
|
+
/**
|
|
19794
|
+
* Run the `beforeObservation` transform hook. Returns the (possibly replaced)
|
|
19795
|
+
* message array; `undefined` from the hook means passthrough.
|
|
19796
|
+
*/
|
|
19797
|
+
async function applyBeforeObservation(hooks, messages, context) {
|
|
19798
|
+
if (!hooks?.beforeObservation) return messages;
|
|
19799
|
+
const result = await hooks.beforeObservation({
|
|
19800
|
+
...context,
|
|
19801
|
+
messages
|
|
19802
|
+
});
|
|
19803
|
+
if (!result) return messages;
|
|
19804
|
+
omDebug(`[OM:hooks] beforeObservation replaced messages: ${messages.length} -> ${result.messages.length}`);
|
|
19805
|
+
return result.messages;
|
|
19806
|
+
}
|
|
19807
|
+
/**
|
|
19808
|
+
* Run one of the text transform hooks. Returns the (possibly replaced)
|
|
19809
|
+
* observation text; `undefined` from the hook means passthrough.
|
|
19810
|
+
*/
|
|
19811
|
+
async function applyTextTransform(hooks, name, observations, context) {
|
|
19812
|
+
const hook = hooks?.[name];
|
|
19813
|
+
if (!hook) return observations;
|
|
19814
|
+
const result = await hook({
|
|
19815
|
+
...context,
|
|
19816
|
+
observations
|
|
19817
|
+
});
|
|
19818
|
+
if (!result) return observations;
|
|
19819
|
+
omDebug(`[OM:hooks] ${name} replaced observations: ${observations.length} -> ${result.observations.length} chars`);
|
|
19820
|
+
return result.observations;
|
|
19821
|
+
}
|
|
19822
|
+
//#endregion
|
|
19792
19823
|
//#region src/processors/observational-memory/observer-runner.ts
|
|
19793
19824
|
function filterObserverExtractors(extractors, skipContinuationHints) {
|
|
19794
19825
|
const configuredExtractors = extractors ?? [];
|
|
@@ -19801,6 +19832,7 @@ var ObserverRunner = class {
|
|
|
19801
19832
|
resolveModel;
|
|
19802
19833
|
tokenCounter;
|
|
19803
19834
|
memory;
|
|
19835
|
+
hooks;
|
|
19804
19836
|
mastra;
|
|
19805
19837
|
/** Captured prompt/response from the last observer call (for repro capture). */
|
|
19806
19838
|
lastExchange;
|
|
@@ -19811,6 +19843,7 @@ var ObserverRunner = class {
|
|
|
19811
19843
|
this.tokenCounter = opts.tokenCounter;
|
|
19812
19844
|
this.mastra = opts.mastra;
|
|
19813
19845
|
this.memory = opts.memory;
|
|
19846
|
+
this.hooks = opts.hooks;
|
|
19814
19847
|
}
|
|
19815
19848
|
__registerMastra(mastra) {
|
|
19816
19849
|
this.mastra = mastra;
|
|
@@ -19864,9 +19897,25 @@ var ObserverRunner = class {
|
|
|
19864
19897
|
return result;
|
|
19865
19898
|
}
|
|
19866
19899
|
/**
|
|
19867
|
-
* Call the Observer agent for a single thread
|
|
19900
|
+
* Call the Observer agent for a single thread, running the config-level
|
|
19901
|
+
* `beforeObservation` / `afterObservation` transform hooks around it.
|
|
19868
19902
|
*/
|
|
19869
19903
|
async call(existingObservations, messagesToObserve, abortSignal, options) {
|
|
19904
|
+
const context = {
|
|
19905
|
+
threadId: options?.threadId ?? messagesToObserve[0]?.threadId,
|
|
19906
|
+
resourceId: options?.resourceId,
|
|
19907
|
+
trigger: options?.trigger
|
|
19908
|
+
};
|
|
19909
|
+
const messages = await applyBeforeObservation(this.hooks, messagesToObserve, context);
|
|
19910
|
+
if (messages.length === 0) {
|
|
19911
|
+
omDebug("[OM:callObserver] beforeObservation returned no messages, skipping observer call");
|
|
19912
|
+
return { observations: "" };
|
|
19913
|
+
}
|
|
19914
|
+
const result = await this.callObserver(existingObservations, messages, abortSignal, options);
|
|
19915
|
+
result.observations = await applyTextTransform(this.hooks, "afterObservation", result.observations, context);
|
|
19916
|
+
return result;
|
|
19917
|
+
}
|
|
19918
|
+
async callObserver(existingObservations, messagesToObserve, abortSignal, options) {
|
|
19870
19919
|
const inputTokens = this.tokenCounter.countMessages(messagesToObserve);
|
|
19871
19920
|
const resolvedModel = options?.model ? { model: options.model } : this.resolveModel(inputTokens);
|
|
19872
19921
|
const activeExtractors = await resolveExtractors(filterObserverExtractors(this.observationConfig.extractors, options?.skipContinuationHints), {
|
|
@@ -19985,7 +20034,30 @@ var ObserverRunner = class {
|
|
|
19985
20034
|
/**
|
|
19986
20035
|
* Call the Observer agent for multiple threads in a single batched request.
|
|
19987
20036
|
*/
|
|
19988
|
-
async callMultiThread(existingObservations,
|
|
20037
|
+
async callMultiThread(existingObservations, allMessagesByThread, allThreadOrder, abortSignal, requestContext, priorMetadataByThread, observabilityContext, model, hookContext) {
|
|
20038
|
+
const contextFor = (threadId) => ({
|
|
20039
|
+
threadId,
|
|
20040
|
+
...hookContext
|
|
20041
|
+
});
|
|
20042
|
+
const messagesByThread = /* @__PURE__ */ new Map();
|
|
20043
|
+
for (const threadId of allThreadOrder) {
|
|
20044
|
+
const filtered = await applyBeforeObservation(this.hooks, allMessagesByThread.get(threadId) ?? [], contextFor(threadId));
|
|
20045
|
+
if (filtered.length > 0) messagesByThread.set(threadId, filtered);
|
|
20046
|
+
}
|
|
20047
|
+
const threadOrder = allThreadOrder.filter((threadId) => messagesByThread.has(threadId));
|
|
20048
|
+
const output = await this.callMultiThreadObserver(existingObservations, messagesByThread, threadOrder, abortSignal, requestContext, priorMetadataByThread, observabilityContext, model);
|
|
20049
|
+
for (const threadId of allThreadOrder) {
|
|
20050
|
+
const threadResult = output.results.get(threadId);
|
|
20051
|
+
if (!threadResult) {
|
|
20052
|
+
output.results.set(threadId, { observations: "" });
|
|
20053
|
+
continue;
|
|
20054
|
+
}
|
|
20055
|
+
threadResult.observations = await applyTextTransform(this.hooks, "afterObservation", threadResult.observations, contextFor(threadId));
|
|
20056
|
+
}
|
|
20057
|
+
return output;
|
|
20058
|
+
}
|
|
20059
|
+
async callMultiThreadObserver(existingObservations, messagesByThread, threadOrder, abortSignal, requestContext, priorMetadataByThread, observabilityContext, model) {
|
|
20060
|
+
if (threadOrder.length === 0) return { results: /* @__PURE__ */ new Map() };
|
|
19989
20061
|
const inputTokens = Array.from(messagesByThread.values()).reduce((total, messages) => total + this.tokenCounter.countMessages(messages), 0);
|
|
19990
20062
|
const resolvedModel = model ? { model } : this.resolveModel(inputTokens);
|
|
19991
20063
|
const firstThreadMessages = messagesByThread.get(threadOrder[0] ?? "") ?? [];
|
|
@@ -20004,7 +20076,7 @@ var ObserverRunner = class {
|
|
|
20004
20076
|
totalTokens: 0
|
|
20005
20077
|
};
|
|
20006
20078
|
for (const threadId of threadOrder) {
|
|
20007
|
-
const threadResult = await this.
|
|
20079
|
+
const threadResult = await this.callObserver(existingObservations, messagesByThread.get(threadId) ?? [], abortSignal, {
|
|
20008
20080
|
requestContext,
|
|
20009
20081
|
observabilityContext,
|
|
20010
20082
|
priorCurrentTask: priorMetadataByThread?.get(threadId)?.currentTask,
|
|
@@ -24061,6 +24133,7 @@ var ObservationStrategy = class ObservationStrategy {
|
|
|
24061
24133
|
sendSignal: this.opts.sendSignal,
|
|
24062
24134
|
sendStateSignal: this.opts.sendStateSignal,
|
|
24063
24135
|
reflectionHooks,
|
|
24136
|
+
trigger: this.opts.trigger,
|
|
24064
24137
|
requestContext,
|
|
24065
24138
|
observabilityContext: this.opts.observabilityContext
|
|
24066
24139
|
});
|
|
@@ -24341,7 +24414,9 @@ var SyncObservationStrategy = class extends ObservationStrategy {
|
|
|
24341
24414
|
priorSuggestedResponse: omMeta?.suggestedResponse,
|
|
24342
24415
|
priorThreadTitle: omMeta?.threadTitle,
|
|
24343
24416
|
priorExtractedValues: this.priorExtractedValues,
|
|
24417
|
+
threadId: this.opts.threadId,
|
|
24344
24418
|
resourceId: this.opts.resourceId,
|
|
24419
|
+
trigger: this.opts.trigger,
|
|
24345
24420
|
mainAgent: this.opts.agent
|
|
24346
24421
|
});
|
|
24347
24422
|
const hookedValues = await applyExtractorHooks({
|
|
@@ -24526,7 +24601,9 @@ var AsyncBufferObservationStrategy = class extends ObservationStrategy {
|
|
|
24526
24601
|
requestContext: this.opts.requestContext,
|
|
24527
24602
|
observabilityContext: this.opts.observabilityContext,
|
|
24528
24603
|
priorExtractedValues: this.priorExtractedValues,
|
|
24604
|
+
threadId: this.opts.threadId,
|
|
24529
24605
|
resourceId: this.opts.resourceId,
|
|
24606
|
+
trigger: this.opts.trigger,
|
|
24530
24607
|
mainAgent: this.opts.agent
|
|
24531
24608
|
});
|
|
24532
24609
|
const hookedValues = await applyExtractorHooks({
|
|
@@ -24850,7 +24927,10 @@ var ResourceScopedObservationStrategy = class extends ObservationStrategy {
|
|
|
24850
24927
|
}
|
|
24851
24928
|
if (currentBatch.threadIds.length > 0) batches.push(currentBatch);
|
|
24852
24929
|
const batchResults = await Promise.all(batches.map(async (batch) => {
|
|
24853
|
-
return this.deps.observer.callMultiThread(_existingObservations, batch.threadMap, batch.threadIds, this.opts.abortSignal, this.opts.requestContext, this.priorMetadataByThread, this.opts.observabilityContext
|
|
24930
|
+
return this.deps.observer.callMultiThread(_existingObservations, batch.threadMap, batch.threadIds, this.opts.abortSignal, this.opts.requestContext, this.priorMetadataByThread, this.opts.observabilityContext, void 0, {
|
|
24931
|
+
resourceId: this.opts.resourceId,
|
|
24932
|
+
trigger: this.opts.trigger
|
|
24933
|
+
});
|
|
24854
24934
|
}));
|
|
24855
24935
|
for (const batchResult of batchResults) {
|
|
24856
24936
|
for (const [threadId, result] of batchResult.results) this.multiThreadResults.set(threadId, result);
|
|
@@ -25188,7 +25268,8 @@ var ObservationStep = class {
|
|
|
25188
25268
|
threadId,
|
|
25189
25269
|
resourceId,
|
|
25190
25270
|
trigger: "turn-sync"
|
|
25191
|
-
})
|
|
25271
|
+
}),
|
|
25272
|
+
trigger: "turn-sync"
|
|
25192
25273
|
});
|
|
25193
25274
|
await this.turn.refreshRecord();
|
|
25194
25275
|
if (this.turn.record.generationCount > preReflectGeneration) reflected = true;
|
|
@@ -25391,7 +25472,8 @@ var ObservationStep = class {
|
|
|
25391
25472
|
threadId,
|
|
25392
25473
|
resourceId,
|
|
25393
25474
|
trigger: "turn-sync"
|
|
25394
|
-
})
|
|
25475
|
+
}),
|
|
25476
|
+
trigger: "turn-sync"
|
|
25395
25477
|
});
|
|
25396
25478
|
return {
|
|
25397
25479
|
succeeded: true,
|
|
@@ -26028,6 +26110,7 @@ var ReflectorRunner = class {
|
|
|
26028
26110
|
getCompressionStartLevel;
|
|
26029
26111
|
memory;
|
|
26030
26112
|
onReflectionCommitted;
|
|
26113
|
+
hooks;
|
|
26031
26114
|
mastra;
|
|
26032
26115
|
/**
|
|
26033
26116
|
* Per-lock-key observation-token count of the last unproductive synchronous
|
|
@@ -26059,6 +26142,7 @@ var ReflectorRunner = class {
|
|
|
26059
26142
|
this.mastra = opts.mastra;
|
|
26060
26143
|
this.memory = opts.memory;
|
|
26061
26144
|
this.onReflectionCommitted = opts.onReflectionCommitted;
|
|
26145
|
+
this.hooks = opts.hooks;
|
|
26062
26146
|
}
|
|
26063
26147
|
__registerMastra(mastra) {
|
|
26064
26148
|
this.mastra = mastra;
|
|
@@ -26281,7 +26365,7 @@ var ReflectorRunner = class {
|
|
|
26281
26365
|
/**
|
|
26282
26366
|
* Start an async buffered reflection in the background.
|
|
26283
26367
|
*/
|
|
26284
|
-
startAsyncBufferedReflection(record, observationTokens, lockKey, writer, requestContext, observabilityContext, reflectionHooks, priorExtractedValues, mainAgent, sendSignal) {
|
|
26368
|
+
startAsyncBufferedReflection(record, observationTokens, lockKey, writer, requestContext, observabilityContext, reflectionHooks, priorExtractedValues, mainAgent, sendSignal, trigger) {
|
|
26285
26369
|
const bufferKey = this.buffering.getReflectionBufferKey(lockKey);
|
|
26286
26370
|
if (this.buffering.isAsyncBufferingInProgress(bufferKey)) return;
|
|
26287
26371
|
BufferingCoordinator.lastBufferedBoundary.set(bufferKey, observationTokens);
|
|
@@ -26294,7 +26378,7 @@ var ReflectorRunner = class {
|
|
|
26294
26378
|
let reflectionError;
|
|
26295
26379
|
try {
|
|
26296
26380
|
await reflectionHooks?.onReflectionStart?.();
|
|
26297
|
-
outcome = await this.doAsyncBufferedReflection(record, bufferKey, writer, requestContext, observabilityContext, priorExtractedValues, mainAgent, sendSignal);
|
|
26381
|
+
outcome = await this.doAsyncBufferedReflection(record, bufferKey, writer, requestContext, observabilityContext, priorExtractedValues, mainAgent, sendSignal, trigger);
|
|
26298
26382
|
} catch (error) {
|
|
26299
26383
|
reflectionError = error instanceof Error ? error : new Error(String(error));
|
|
26300
26384
|
if (writer) try {
|
|
@@ -26340,7 +26424,7 @@ var ReflectorRunner = class {
|
|
|
26340
26424
|
* Perform async buffered reflection — reflects observations and stores to bufferedReflection.
|
|
26341
26425
|
* Does NOT create a new generation or update activeObservations.
|
|
26342
26426
|
*/
|
|
26343
|
-
async doAsyncBufferedReflection(record, _bufferKey, writer, requestContext, observabilityContext, priorExtractedValues, mainAgent, sendSignal) {
|
|
26427
|
+
async doAsyncBufferedReflection(record, _bufferKey, writer, requestContext, observabilityContext, priorExtractedValues, mainAgent, sendSignal, trigger) {
|
|
26344
26428
|
const currentRecord = await this.storage.getObservationalMemory(record.threadId, record.resourceId) ?? record;
|
|
26345
26429
|
const observationTokens = currentRecord.observationTokenCount ?? 0;
|
|
26346
26430
|
const reflectThreshold = getMaxThreshold(this.getEffectiveReflectionTokens(currentRecord));
|
|
@@ -26353,7 +26437,12 @@ var ReflectorRunner = class {
|
|
|
26353
26437
|
const avgTokensPerLine = totalLines > 0 ? observationTokens / totalLines : 0;
|
|
26354
26438
|
const activationPointTokens = reflectThreshold * bufferActivation;
|
|
26355
26439
|
const linesToReflect = avgTokensPerLine > 0 ? Math.min(Math.floor(activationPointTokens / avgTokensPerLine), totalLines) : totalLines;
|
|
26356
|
-
const
|
|
26440
|
+
const hookContext = {
|
|
26441
|
+
threadId: currentRecord.threadId ?? void 0,
|
|
26442
|
+
resourceId: currentRecord.resourceId ?? void 0,
|
|
26443
|
+
trigger
|
|
26444
|
+
};
|
|
26445
|
+
const activeObservations = await applyTextTransform(this.hooks, "beforeReflection", allLines.slice(0, linesToReflect).join("\n"), hookContext);
|
|
26357
26446
|
const reflectedObservationLineCount = linesToReflect;
|
|
26358
26447
|
const sliceTokenEstimate = Math.round(avgTokensPerLine * linesToReflect);
|
|
26359
26448
|
const compressionTarget = Math.round(sliceTokenEstimate * .75);
|
|
@@ -26377,6 +26466,7 @@ var ReflectorRunner = class {
|
|
|
26377
26466
|
}
|
|
26378
26467
|
const compressionStartLevel = await this.getCompressionStartLevel(requestContext);
|
|
26379
26468
|
const reflectResult = await this.call(activeObservations, void 0, void 0, compressionTarget, void 0, true, compressionStartLevel, requestContext, priorExtractedValues, observabilityContext, void 0, mainAgent, sendSignal);
|
|
26469
|
+
reflectResult.observations = await applyTextTransform(this.hooks, "afterReflection", reflectResult.observations, hookContext);
|
|
26380
26470
|
await persistThreadExtractedValues(this.storage, this.reflectionConfig.extractors, currentRecord.threadId ?? void 0, reflectResult.extractedValues);
|
|
26381
26471
|
const reflectionTokenCount = this.tokenCounter.countObservations(reflectResult.observations);
|
|
26382
26472
|
omDebug(`[OM:reflect] doAsyncBufferedReflection: reflector returned ${reflectionTokenCount} tokens (${reflectResult.observations?.length} chars), saving to recordId=${currentRecord.id}`);
|
|
@@ -26523,7 +26613,7 @@ var ReflectorRunner = class {
|
|
|
26523
26613
|
* @internal Used by observation strategies. Do not call directly.
|
|
26524
26614
|
*/
|
|
26525
26615
|
async maybeReflect(opts) {
|
|
26526
|
-
const { record, observationTokens, writer, abortSignal, mainAgent, sendSignal, sendStateSignal, messageList, currentModel, reflectionHooks, requestContext, observabilityContext, lastActivityAt, threadId: requestedThreadId } = opts;
|
|
26616
|
+
const { record, observationTokens, writer, abortSignal, mainAgent, sendSignal, sendStateSignal, messageList, currentModel, reflectionHooks, trigger, requestContext, observabilityContext, lastActivityAt, threadId: requestedThreadId } = opts;
|
|
26527
26617
|
const lockKey = this.buffering.getLockKey(record.threadId, record.resourceId);
|
|
26528
26618
|
const reflectThreshold = getMaxThreshold(this.getEffectiveReflectionTokens(record));
|
|
26529
26619
|
const priorExtractedValues = await getThreadExtractedValues(this.storage, this.reflectionConfig.extractors, requestedThreadId ?? record.threadId);
|
|
@@ -26541,7 +26631,7 @@ var ReflectorRunner = class {
|
|
|
26541
26631
|
if (record.bufferedReflection) return false;
|
|
26542
26632
|
const activationPoint = reflectThreshold * this.reflectionConfig.bufferActivation;
|
|
26543
26633
|
return observationTokens >= activationPoint;
|
|
26544
|
-
})()) this.startAsyncBufferedReflection(record, observationTokens, lockKey, writer, requestContext, observabilityContext, reflectionHooks, priorExtractedValues, mainAgent, sendSignal);
|
|
26634
|
+
})()) this.startAsyncBufferedReflection(record, observationTokens, lockKey, writer, requestContext, observabilityContext, reflectionHooks, priorExtractedValues, mainAgent, sendSignal, trigger);
|
|
26545
26635
|
}
|
|
26546
26636
|
const activateAfterIdle = resolveActivationTTL(this.reflectionConfig.activateAfterIdle, currentModel);
|
|
26547
26637
|
const ttlExpiredMs = activateAfterIdle !== void 0 && lastActivityAt !== void 0 ? Date.now() - lastActivityAt : void 0;
|
|
@@ -26590,7 +26680,7 @@ var ReflectorRunner = class {
|
|
|
26590
26680
|
return;
|
|
26591
26681
|
}
|
|
26592
26682
|
omDebug(`[OM:reflect] async activation failed, no blockAfter or below it (obsTokens=${observationTokens}, blockAfter=${this.reflectionConfig.blockAfter}) — starting background reflection`);
|
|
26593
|
-
this.startAsyncBufferedReflection(record, observationTokens, lockKey, writer, requestContext, observabilityContext, reflectionHooks, priorExtractedValues, mainAgent, sendSignal);
|
|
26683
|
+
this.startAsyncBufferedReflection(record, observationTokens, lockKey, writer, requestContext, observabilityContext, reflectionHooks, priorExtractedValues, mainAgent, sendSignal, trigger);
|
|
26594
26684
|
return;
|
|
26595
26685
|
}
|
|
26596
26686
|
}
|
|
@@ -26651,7 +26741,13 @@ var ReflectorRunner = class {
|
|
|
26651
26741
|
throw error;
|
|
26652
26742
|
}
|
|
26653
26743
|
const compressionStartLevel = await this.getCompressionStartLevel(requestContext);
|
|
26654
|
-
const
|
|
26744
|
+
const hookContext = {
|
|
26745
|
+
threadId: requestedThreadId ?? record.threadId ?? void 0,
|
|
26746
|
+
resourceId: record.resourceId ?? void 0,
|
|
26747
|
+
trigger
|
|
26748
|
+
};
|
|
26749
|
+
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);
|
|
26750
|
+
reflectResult.observations = await applyTextTransform(this.hooks, "afterReflection", reflectResult.observations, hookContext);
|
|
26655
26751
|
reflectionUsage = reflectResult.usage;
|
|
26656
26752
|
reflectionProviderMetadata = reflectResult.providerMetadata;
|
|
26657
26753
|
await persistThreadExtractedValues(this.storage, this.reflectionConfig.extractors, record.threadId ?? void 0, reflectResult.extractedValues);
|
|
@@ -27402,7 +27498,8 @@ var ObservationalMemory = class ObservationalMemory {
|
|
|
27402
27498
|
resolveModel: (inputTokens) => this.resolveObservationModel(inputTokens),
|
|
27403
27499
|
tokenCounter: this.tokenCounter,
|
|
27404
27500
|
mastra: config.mastra,
|
|
27405
|
-
memory: this.memory
|
|
27501
|
+
memory: this.memory,
|
|
27502
|
+
hooks: this.hooks
|
|
27406
27503
|
});
|
|
27407
27504
|
this.buffering = new BufferingCoordinator({
|
|
27408
27505
|
observationConfig: this.observationConfig,
|
|
@@ -27423,7 +27520,8 @@ var ObservationalMemory = class ObservationalMemory {
|
|
|
27423
27520
|
resolveModel: (inputTokens) => this.resolveReflectionModel(inputTokens),
|
|
27424
27521
|
mastra: config.mastra,
|
|
27425
27522
|
memory: this.memory,
|
|
27426
|
-
onReflectionCommitted: config.onReflectionCommitted
|
|
27523
|
+
onReflectionCommitted: config.onReflectionCommitted,
|
|
27524
|
+
hooks: this.hooks
|
|
27427
27525
|
});
|
|
27428
27526
|
this.validateBufferConfig();
|
|
27429
27527
|
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}`);
|
|
@@ -28279,7 +28377,8 @@ ${formattedMessages}
|
|
|
28279
28377
|
startedAt,
|
|
28280
28378
|
writer,
|
|
28281
28379
|
requestContext,
|
|
28282
|
-
observabilityContext
|
|
28380
|
+
observabilityContext,
|
|
28381
|
+
trigger: "async-buffer"
|
|
28283
28382
|
}).run());
|
|
28284
28383
|
const maxTs = this.getMaxMessageTimestamp(messagesToBuffer);
|
|
28285
28384
|
const cursor = new Date(maxTs.getTime() + 1);
|
|
@@ -28900,7 +28999,8 @@ ${formattedMessages}
|
|
|
28900
28999
|
sendStateSignal: opts.sendStateSignal,
|
|
28901
29000
|
requestContext,
|
|
28902
29001
|
currentModel: opts.currentModel,
|
|
28903
|
-
observabilityContext
|
|
29002
|
+
observabilityContext,
|
|
29003
|
+
trigger: "async-buffer"
|
|
28904
29004
|
}).run());
|
|
28905
29005
|
if (isOmReproCaptureEnabled()) writeObserverExchangeReproCapture({
|
|
28906
29006
|
threadId,
|
|
@@ -29214,10 +29314,11 @@ ${formattedMessages}
|
|
|
29214
29314
|
async observe(opts) {
|
|
29215
29315
|
const { threadId, resourceId, messages, requestContext } = opts;
|
|
29216
29316
|
const lockKey = this.buffering.getLockKey(threadId, resourceId);
|
|
29317
|
+
const trigger = opts.trigger ?? "manual";
|
|
29217
29318
|
const hooks = this.composeHooks(opts.hooks, {
|
|
29218
29319
|
threadId,
|
|
29219
29320
|
resourceId,
|
|
29220
|
-
trigger
|
|
29321
|
+
trigger
|
|
29221
29322
|
});
|
|
29222
29323
|
const reflectionHooks = hooks ? {
|
|
29223
29324
|
onReflectionStart: hooks.onReflectionStart,
|
|
@@ -29248,6 +29349,7 @@ ${formattedMessages}
|
|
|
29248
29349
|
messages: unobservedMessages,
|
|
29249
29350
|
messageList: opts.messageList,
|
|
29250
29351
|
reflectionHooks,
|
|
29352
|
+
trigger,
|
|
29251
29353
|
agent: opts.agent,
|
|
29252
29354
|
sendSignal: opts.sendSignal,
|
|
29253
29355
|
sendStateSignal: opts.sendStateSignal,
|
|
@@ -29314,11 +29416,12 @@ ${formattedMessages}
|
|
|
29314
29416
|
}
|
|
29315
29417
|
await this.storage.setReflectingFlag(record.id, true);
|
|
29316
29418
|
registerOp(record.id, "reflecting");
|
|
29317
|
-
const
|
|
29419
|
+
const hookContext = {
|
|
29318
29420
|
threadId,
|
|
29319
29421
|
resourceId,
|
|
29320
29422
|
trigger: "manual"
|
|
29321
|
-
}
|
|
29423
|
+
};
|
|
29424
|
+
const hooks = this.composeHooks(void 0, hookContext);
|
|
29322
29425
|
let reflectionUsage;
|
|
29323
29426
|
let reflectionProviderMetadata;
|
|
29324
29427
|
let reflectionError;
|
|
@@ -29335,7 +29438,8 @@ ${formattedMessages}
|
|
|
29335
29438
|
const previousOmMetadata = getThreadOMMetadata(thread?.metadata);
|
|
29336
29439
|
const priorExtractedValues = getPriorExtractedValues(previousOmMetadata, this.reflectionConfig.extractors);
|
|
29337
29440
|
const reflectThreshold = getMaxThreshold(this.getEffectiveReflectionTokens(record));
|
|
29338
|
-
const reflectResult = await this.reflector.call(record.activeObservations, prompt, void 0, reflectThreshold, void 0, void 0, void 0, requestContext, priorExtractedValues, observabilityContext, void 0);
|
|
29441
|
+
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);
|
|
29442
|
+
reflectResult.observations = await applyTextTransform(this.hooks, "afterReflection", reflectResult.observations, hookContext);
|
|
29339
29443
|
const reflectionTokenCount = this.tokenCounter.countObservations(reflectResult.observations);
|
|
29340
29444
|
await this.storage.createReflectionGeneration({
|
|
29341
29445
|
currentRecord: record,
|
|
@@ -30233,7 +30337,7 @@ var Memory = class Memory extends MastraMemory {
|
|
|
30233
30337
|
});
|
|
30234
30338
|
}
|
|
30235
30339
|
async recall(args) {
|
|
30236
|
-
const { threadId, resourceId, perPage: perPageArg, page, orderBy, threadConfig, vectorSearchString, includeSystemReminders, filter } = args;
|
|
30340
|
+
const { threadId, resourceId, perPage: perPageArg, page, orderBy, threadConfig, vectorSearchString, includeSystemReminders, filter, includeTotal } = args;
|
|
30237
30341
|
const config = this.getMergedThreadConfig(threadConfig || {});
|
|
30238
30342
|
const semanticRecallEnabled = Boolean(config.semanticRecall);
|
|
30239
30343
|
const span = this.createMemorySpan("recall", args.observabilityContext, {
|
|
@@ -30320,6 +30424,7 @@ var Memory = class Memory extends MastraMemory {
|
|
|
30320
30424
|
page,
|
|
30321
30425
|
orderBy: effectiveOrderBy,
|
|
30322
30426
|
filter,
|
|
30427
|
+
...includeTotal !== void 0 ? { includeTotal } : {},
|
|
30323
30428
|
...filteredVectorResults?.length ? { include: filteredVectorResults.map((r) => ({
|
|
30324
30429
|
id: r.metadata?.message_id,
|
|
30325
30430
|
threadId: r.metadata?.thread_id,
|
|
@@ -30932,6 +31037,7 @@ ${workingMemory}`;
|
|
|
30932
31037
|
direction: "ASC"
|
|
30933
31038
|
},
|
|
30934
31039
|
perPage: false,
|
|
31040
|
+
includeTotal: false,
|
|
30935
31041
|
filter: dateFilter
|
|
30936
31042
|
})).messages;
|
|
30937
31043
|
};
|
|
@@ -30945,6 +31051,7 @@ ${workingMemory}`;
|
|
|
30945
31051
|
direction: "ASC"
|
|
30946
31052
|
},
|
|
30947
31053
|
perPage: false,
|
|
31054
|
+
includeTotal: false,
|
|
30948
31055
|
filter: dateFilter
|
|
30949
31056
|
})).messages;
|
|
30950
31057
|
};
|
|
@@ -30960,7 +31067,8 @@ ${workingMemory}`;
|
|
|
30960
31067
|
field: "createdAt",
|
|
30961
31068
|
direction: "DESC"
|
|
30962
31069
|
},
|
|
30963
|
-
perPage: typeof lastMessages === "number" ? lastMessages : void 0
|
|
31070
|
+
perPage: typeof lastMessages === "number" ? lastMessages : void 0,
|
|
31071
|
+
includeTotal: false
|
|
30964
31072
|
})).messages.reverse();
|
|
30965
31073
|
}
|
|
30966
31074
|
return {
|
|
@@ -31322,7 +31430,8 @@ Notes:
|
|
|
31322
31430
|
threadId,
|
|
31323
31431
|
resourceId,
|
|
31324
31432
|
perPage: SUMMARIZE_THREAD_DEFAULTS.pageSize,
|
|
31325
|
-
page
|
|
31433
|
+
page,
|
|
31434
|
+
includeTotal: false
|
|
31326
31435
|
});
|
|
31327
31436
|
if (batch.length === 0) break;
|
|
31328
31437
|
let reachedLimit = false;
|
|
@@ -31973,4 +32082,4 @@ Notes:
|
|
|
31973
32082
|
//#endregion
|
|
31974
32083
|
export { formatMessagesForObserver as A, OBSERVATION_CONTINUATION_HINT as B, SUMMARIZE_THREAD_DEFAULTS as C, buildObserverPrompt as D, OBSERVER_SYSTEM_PROMPT as E, parseAnchorId as F, ModelByInputTokens as G, KnowledgeSemanticIndexCoordinator as H, stripEphemeralAnchorIds as I, publishSubconsciousActivity as J, SUBCONSCIOUS_ACTIVITY_STATE_ID as K, OBSERVATIONAL_MEMORY_DEFAULTS as L, optimizeObservationsForContext as M, parseObserverOutput as N, buildObserverSystemPrompt as O, injectAnchorIds as P, OBSERVATION_CONTEXT_INSTRUCTIONS as R, WorkingMemoryExtractor as S, TokenCounter as T, StaleKnowledgeSemanticIndexError as U, Subconscious as V, SubconsciousRemindExtractor as W, Extractor as X, renderSubconsciousActivity as Y, wrapInObservationGroup as _, extractWorkingMemoryContent as a, WorkingMemoryStateProcessor as b, getObservationsAsOf as c, combineObservationGroupRanges as d, deriveObservationGroupProvenance as f, stripObservationGroups as g, renderObservationGroupsForReflection as h, WorkingMemory as i, hasCurrentTaskSection as j, extractCurrentTask as k, ObservationalMemoryProcessor as l, reconcileObservationGroupsFromReflection as m, MessageHistory$1 as n, extractWorkingMemoryTags as o, parseObservationGroups as p, buildSubconsciousActivitySnapshot as q, SemanticRecall as r, removeWorkingMemoryTags as s, Memory as t, ObservationalMemory as u, WORKING_MEMORY_STATE_ID as v, summarizeConversation as w, deepMergeWorkingMemory as x, WORKING_MEMORY_STATE_PROCESSOR_ID as y, OBSERVATION_CONTEXT_PROMPT as z };
|
|
31975
32084
|
|
|
31976
|
-
//# sourceMappingURL=src-
|
|
32085
|
+
//# sourceMappingURL=src-DuA6bRSI.js.map
|