@mastra/memory 1.24.0 → 1.25.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +43 -0
- package/dist/docs/SKILL.md +6 -6
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-agents-agent-approval.md +85 -11
- package/dist/docs/references/docs-agents-networks.md +2 -2
- package/dist/docs/references/docs-agents-supervisor-agents.md +19 -13
- package/dist/docs/references/docs-evals-evals-with-memory.md +4 -4
- package/dist/docs/references/docs-long-running-agents-background-tasks.md +10 -10
- package/dist/docs/references/docs-long-running-agents-goals.md +15 -11
- package/dist/docs/references/docs-memory-memory-processors.md +10 -10
- package/dist/docs/references/docs-memory-message-history.md +11 -5
- package/dist/docs/references/docs-memory-multi-user-threads.md +6 -6
- package/dist/docs/references/docs-memory-observational-memory.md +57 -38
- package/dist/docs/references/docs-memory-overview.md +24 -10
- package/dist/docs/references/docs-memory-semantic-recall.md +3 -3
- package/dist/docs/references/docs-memory-working-memory.md +8 -8
- package/dist/docs/references/docs-storage-overview.md +2 -2
- package/dist/docs/references/reference-memory-clone-utilities.md +1 -1
- package/dist/docs/references/reference-memory-cloneThread.md +3 -3
- package/dist/docs/references/reference-memory-listThreads.md +1 -1
- package/dist/docs/references/reference-memory-memory-class.md +4 -4
- package/dist/docs/references/reference-memory-observational-memory.md +88 -38
- package/dist/docs/references/reference-memory-summarizeConversation.md +3 -3
- package/dist/docs/references/reference-memory-summarizeThread.md +3 -3
- package/dist/docs/references/reference-processors-token-limiter-processor.md +4 -4
- package/dist/docs/references/reference-storage-dsql.md +3 -3
- package/dist/docs/references/reference-storage-dynamodb.md +7 -7
- package/dist/docs/references/reference-storage-mongodb.md +2 -2
- package/dist/docs/references/reference-storage-postgresql.md +2 -2
- package/dist/docs/references/reference-storage-redis.md +1 -1
- package/dist/docs/references/reference-storage-upstash.md +1 -1
- package/dist/docs/references/reference-vectors-libsql.md +2 -2
- package/dist/docs/references/reference-vectors-mongodb.md +16 -16
- package/dist/docs/references/reference-vectors-pg.md +5 -5
- package/dist/docs/references/reference-vectors-upstash.md +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -0
- 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/internal-request-context.d.ts +7 -0
- package/dist/processors/observational-memory/internal-request-context.d.ts.map +1 -1
- package/dist/processors/observational-memory/observation-strategies/types.d.ts +6 -0
- 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 +30 -1
- package/dist/processors/observational-memory/observational-memory.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.map +1 -1
- package/dist/processors/observational-memory/types.d.ts +50 -6
- package/dist/processors/observational-memory/types.d.ts.map +1 -1
- package/dist/{src-VD6qMn-H.cjs → src-C3u7zaSu.cjs} +182 -32
- package/dist/{src-VD6qMn-H.cjs.map → src-C3u7zaSu.cjs.map} +1 -1
- package/dist/{src-Ci_GvBVm.js → src-DoNjfXNm.js} +182 -32
- package/dist/{src-Ci_GvBVm.js.map → src-DoNjfXNm.js.map} +1 -1
- package/package.json +7 -7
|
@@ -15190,13 +15190,19 @@ ${extractorInstructions}${priorLines.length > 0 ? `\n\n## Prior Extracted Values
|
|
|
15190
15190
|
* auth, versions, routing hints, and resource id, but they must not present as
|
|
15191
15191
|
* another run on the parent thread or core's cross-agent thread wait can block
|
|
15192
15192
|
* on the parent run that is waiting for OM to complete.
|
|
15193
|
+
*
|
|
15194
|
+
* A fresh RequestContext clone is always returned so that memory-scoped writes
|
|
15195
|
+
* made by the internal agent run (e.g. the `MastraMemory` entry that agent.generate
|
|
15196
|
+
* sets from the observer's temporary `structured-observer` memory) cannot leak back
|
|
15197
|
+
* into the parent's RequestContext. Without this isolation the parent's OM turn later
|
|
15198
|
+
* reads the temporary observer's resourceId and injects a continuation message that
|
|
15199
|
+
* fails MessageList's resourceId validation.
|
|
15193
15200
|
*/
|
|
15194
15201
|
function withOmInternalThreadId(requestContext, omAgentId) {
|
|
15195
15202
|
if (!requestContext) return void 0;
|
|
15196
|
-
const parentThreadId = requestContext.get(MASTRA_THREAD_ID_KEY);
|
|
15197
|
-
if (typeof parentThreadId !== "string" || !parentThreadId) return requestContext;
|
|
15198
15203
|
const internalRequestContext = new RequestContext(requestContext.entries());
|
|
15199
|
-
|
|
15204
|
+
const parentThreadId = requestContext.get(MASTRA_THREAD_ID_KEY);
|
|
15205
|
+
if (typeof parentThreadId === "string" && parentThreadId) internalRequestContext.set(MASTRA_THREAD_ID_KEY, `${parentThreadId}-${omAgentId}`);
|
|
15200
15206
|
return internalRequestContext;
|
|
15201
15207
|
}
|
|
15202
15208
|
//#endregion
|
|
@@ -17030,7 +17036,7 @@ var ObserverRunner = class {
|
|
|
17030
17036
|
extractors: activeExtractors,
|
|
17031
17037
|
memory: temporaryMemory?.options,
|
|
17032
17038
|
priorExtractedValues: options?.priorExtractedValues,
|
|
17033
|
-
requestContext:
|
|
17039
|
+
requestContext: internalRequestContext,
|
|
17034
17040
|
observabilityContext: options?.observabilityContext,
|
|
17035
17041
|
abortSignal
|
|
17036
17042
|
});
|
|
@@ -20794,7 +20800,10 @@ var ObservationStrategy = class ObservationStrategy {
|
|
|
20794
20800
|
await this.persistMarkerToStorage(failedMarkerForStorage, threadId, this.opts.resourceId).catch(() => {});
|
|
20795
20801
|
if (abortSignal?.aborted) throw error;
|
|
20796
20802
|
omError("[OM] Observation failed", error);
|
|
20797
|
-
return {
|
|
20803
|
+
return {
|
|
20804
|
+
observed: false,
|
|
20805
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
20806
|
+
};
|
|
20798
20807
|
}
|
|
20799
20808
|
omError("[OM] Observation failed", error);
|
|
20800
20809
|
throw error;
|
|
@@ -21844,7 +21853,12 @@ var ObservationStep = class {
|
|
|
21844
21853
|
currentModel: this.turn.actorModelContext,
|
|
21845
21854
|
requestContext: this.turn.requestContext,
|
|
21846
21855
|
observabilityContext: this.turn.observabilityContext,
|
|
21847
|
-
lastActivityAt: getLastActivityFromMessages(messageList.get.all.db())
|
|
21856
|
+
lastActivityAt: getLastActivityFromMessages(messageList.get.all.db()),
|
|
21857
|
+
reflectionHooks: om.composeHooks(void 0, {
|
|
21858
|
+
threadId,
|
|
21859
|
+
resourceId,
|
|
21860
|
+
trigger: "turn-sync"
|
|
21861
|
+
})
|
|
21848
21862
|
});
|
|
21849
21863
|
await this.turn.refreshRecord();
|
|
21850
21864
|
if (this.turn.record.generationCount > preReflectGeneration) reflected = true;
|
|
@@ -22004,7 +22018,12 @@ var ObservationStep = class {
|
|
|
22004
22018
|
currentModel: this.turn.actorModelContext,
|
|
22005
22019
|
requestContext: this.turn.requestContext,
|
|
22006
22020
|
observabilityContext: this.turn.observabilityContext,
|
|
22007
|
-
lastActivityAt: getLastActivityFromMessages(messageList.get.all.db())
|
|
22021
|
+
lastActivityAt: getLastActivityFromMessages(messageList.get.all.db()),
|
|
22022
|
+
reflectionHooks: om.composeHooks(void 0, {
|
|
22023
|
+
threadId,
|
|
22024
|
+
resourceId,
|
|
22025
|
+
trigger: "turn-sync"
|
|
22026
|
+
})
|
|
22008
22027
|
});
|
|
22009
22028
|
return {
|
|
22010
22029
|
succeeded: true,
|
|
@@ -22017,6 +22036,7 @@ var ObservationStep = class {
|
|
|
22017
22036
|
threadId,
|
|
22018
22037
|
resourceId,
|
|
22019
22038
|
messages: messageList.get.all.db(),
|
|
22039
|
+
trigger: "turn-sync",
|
|
22020
22040
|
requestContext: this.turn.requestContext,
|
|
22021
22041
|
writer: this.turn.writer,
|
|
22022
22042
|
observabilityContext: this.turn.observabilityContext
|
|
@@ -22806,7 +22826,7 @@ var ReflectorRunner = class {
|
|
|
22806
22826
|
extractors: activeExtractors,
|
|
22807
22827
|
memory: temporaryMemory?.options,
|
|
22808
22828
|
priorExtractedValues,
|
|
22809
|
-
requestContext,
|
|
22829
|
+
requestContext: internalRequestContext,
|
|
22810
22830
|
observabilityContext,
|
|
22811
22831
|
abortSignal
|
|
22812
22832
|
});
|
|
@@ -22848,12 +22868,16 @@ var ReflectorRunner = class {
|
|
|
22848
22868
|
});
|
|
22849
22869
|
reflectionHooks?.onReflectionStart?.();
|
|
22850
22870
|
const asyncOp = this.doAsyncBufferedReflection(record, bufferKey, writer, requestContext, observabilityContext, priorExtractedValues, mainAgent, sendSignal).then((outcome) => {
|
|
22851
|
-
|
|
22852
|
-
|
|
22853
|
-
|
|
22854
|
-
|
|
22855
|
-
|
|
22856
|
-
|
|
22871
|
+
try {
|
|
22872
|
+
reflectionHooks?.onReflectionEnd?.({
|
|
22873
|
+
usage: outcome?.usage,
|
|
22874
|
+
...outcome?.providerMetadata ? { providerMetadata: outcome.providerMetadata } : {}
|
|
22875
|
+
});
|
|
22876
|
+
} catch (hookError) {
|
|
22877
|
+
omError("[OM] onReflectionEnd hook failed after async buffered reflection", hookError);
|
|
22878
|
+
}
|
|
22879
|
+
}, async (error) => {
|
|
22880
|
+
if (writer) try {
|
|
22857
22881
|
const failedMarker = createBufferingFailedMarker({
|
|
22858
22882
|
cycleId: `reflect-buf-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`,
|
|
22859
22883
|
operationType: "reflection",
|
|
@@ -22868,12 +22892,18 @@ var ReflectorRunner = class {
|
|
|
22868
22892
|
transient: true
|
|
22869
22893
|
}).catch(() => {});
|
|
22870
22894
|
await this.persistMarkerToStorage(failedMarker, record.threadId ?? "", record.resourceId ?? void 0);
|
|
22895
|
+
} catch (markerError) {
|
|
22896
|
+
omError("[OM] Failed to persist buffering-failed marker after async buffered reflection failure", markerError);
|
|
22871
22897
|
}
|
|
22872
22898
|
omError("[OM] Async buffered reflection failed", error);
|
|
22873
|
-
|
|
22874
|
-
|
|
22875
|
-
|
|
22876
|
-
|
|
22899
|
+
try {
|
|
22900
|
+
reflectionHooks?.onReflectionEnd?.({
|
|
22901
|
+
usage: void 0,
|
|
22902
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
22903
|
+
});
|
|
22904
|
+
} catch (hookError) {
|
|
22905
|
+
omError("[OM] onReflectionEnd hook failed after async buffered reflection failure", hookError);
|
|
22906
|
+
}
|
|
22877
22907
|
BufferingCoordinator.lastBufferedBoundary.delete(bufferKey);
|
|
22878
22908
|
}).finally(() => {
|
|
22879
22909
|
BufferingCoordinator.asyncBufferingOps.delete(bufferKey);
|
|
@@ -23120,7 +23150,6 @@ var ReflectorRunner = class {
|
|
|
23120
23150
|
return;
|
|
23121
23151
|
}
|
|
23122
23152
|
}
|
|
23123
|
-
reflectionHooks?.onReflectionStart?.();
|
|
23124
23153
|
await this.storage.setReflectingFlag(record.id, true);
|
|
23125
23154
|
registerOp(record.id, "reflecting");
|
|
23126
23155
|
const cycleId = crypto.randomUUID();
|
|
@@ -23161,6 +23190,7 @@ var ReflectorRunner = class {
|
|
|
23161
23190
|
let reflectionUsage;
|
|
23162
23191
|
let reflectionProviderMetadata;
|
|
23163
23192
|
let reflectionError;
|
|
23193
|
+
reflectionHooks?.onReflectionStart?.();
|
|
23164
23194
|
try {
|
|
23165
23195
|
const compressionStartLevel = await this.getCompressionStartLevel(requestContext);
|
|
23166
23196
|
const reflectResult = await this.call(record.activeObservations, void 0, streamContext, reflectThreshold, abortSignal, void 0, compressionStartLevel, requestContext, priorExtractedValues, observabilityContext, void 0, mainAgent, sendSignal);
|
|
@@ -23224,12 +23254,15 @@ var ReflectorRunner = class {
|
|
|
23224
23254
|
omError("[OM] Reflection failed", error);
|
|
23225
23255
|
} finally {
|
|
23226
23256
|
await this.storage.setReflectingFlag(record.id, false);
|
|
23227
|
-
|
|
23228
|
-
|
|
23229
|
-
|
|
23230
|
-
|
|
23231
|
-
|
|
23232
|
-
|
|
23257
|
+
try {
|
|
23258
|
+
reflectionHooks?.onReflectionEnd?.({
|
|
23259
|
+
usage: reflectionUsage,
|
|
23260
|
+
error: reflectionError,
|
|
23261
|
+
...reflectionProviderMetadata ? { providerMetadata: reflectionProviderMetadata } : {}
|
|
23262
|
+
});
|
|
23263
|
+
} finally {
|
|
23264
|
+
unregisterOp(record.id, "reflecting");
|
|
23265
|
+
}
|
|
23233
23266
|
}
|
|
23234
23267
|
}
|
|
23235
23268
|
};
|
|
@@ -23682,6 +23715,8 @@ var ObservationalMemory = class ObservationalMemory {
|
|
|
23682
23715
|
reflectionConfig;
|
|
23683
23716
|
onDebugEvent;
|
|
23684
23717
|
onIndexObservations;
|
|
23718
|
+
/** Config-level lifecycle hooks fired for every observation/reflection cycle. */
|
|
23719
|
+
hooks;
|
|
23685
23720
|
/** Observer agent runner — handles LLM calls for extracting observations. */
|
|
23686
23721
|
observer;
|
|
23687
23722
|
/** Reflector agent runner — handles LLM calls for compressing observations. */
|
|
@@ -23742,6 +23777,7 @@ var ObservationalMemory = class ObservationalMemory {
|
|
|
23742
23777
|
this.scope = config.scope ?? "thread";
|
|
23743
23778
|
this.retrieval = Boolean(config.retrieval);
|
|
23744
23779
|
this.onIndexObservations = config.onIndexObservations;
|
|
23780
|
+
this.hooks = config.hooks;
|
|
23745
23781
|
this.mastra = config.mastra;
|
|
23746
23782
|
this.memory = config.memory;
|
|
23747
23783
|
const resolveModel = (model, defaultModel) => model === "default" ? defaultModel : model;
|
|
@@ -24663,7 +24699,11 @@ ${formattedMessages}
|
|
|
24663
24699
|
transient: true
|
|
24664
24700
|
}).catch(() => {});
|
|
24665
24701
|
omDebug(`[OM:bufferInput] cycleId=${cycleId}, msgCount=${messagesToBuffer.length}, msgTokens=${tokensToBuffer}, ids=${messagesToBuffer.map((m) => `${m.id?.slice(0, 8)}@${m.createdAt ? new Date(m.createdAt).toISOString() : "none"}`).join(",")}`);
|
|
24666
|
-
await
|
|
24702
|
+
await this.runBufferedObservationCycle({
|
|
24703
|
+
threadId,
|
|
24704
|
+
resourceId: freshRecord.resourceId ?? void 0,
|
|
24705
|
+
trigger: "async-buffer"
|
|
24706
|
+
}, () => ObservationStrategy.create(this, {
|
|
24667
24707
|
record: freshRecord,
|
|
24668
24708
|
threadId,
|
|
24669
24709
|
resourceId: freshRecord.resourceId ?? void 0,
|
|
@@ -24673,7 +24713,7 @@ ${formattedMessages}
|
|
|
24673
24713
|
writer,
|
|
24674
24714
|
requestContext,
|
|
24675
24715
|
observabilityContext
|
|
24676
|
-
}).run();
|
|
24716
|
+
}).run());
|
|
24677
24717
|
const maxTs = this.getMaxMessageTimestamp(messagesToBuffer);
|
|
24678
24718
|
const cursor = new Date(maxTs.getTime() + 1);
|
|
24679
24719
|
BufferingCoordinator.lastBufferedAtTime.set(bufferKey, cursor);
|
|
@@ -25246,7 +25286,11 @@ ${formattedMessages}
|
|
|
25246
25286
|
...startMarker,
|
|
25247
25287
|
transient: true
|
|
25248
25288
|
}).catch(() => {});
|
|
25249
|
-
await
|
|
25289
|
+
await this.runBufferedObservationCycle({
|
|
25290
|
+
threadId,
|
|
25291
|
+
resourceId: record.resourceId ?? resourceId,
|
|
25292
|
+
trigger: "async-buffer"
|
|
25293
|
+
}, () => ObservationStrategy.create(this, {
|
|
25250
25294
|
record,
|
|
25251
25295
|
threadId,
|
|
25252
25296
|
resourceId: record.resourceId ?? void 0,
|
|
@@ -25259,7 +25303,7 @@ ${formattedMessages}
|
|
|
25259
25303
|
requestContext,
|
|
25260
25304
|
currentModel: opts.currentModel,
|
|
25261
25305
|
observabilityContext
|
|
25262
|
-
}).run();
|
|
25306
|
+
}).run());
|
|
25263
25307
|
if (isOmReproCaptureEnabled()) writeObserverExchangeReproCapture({
|
|
25264
25308
|
threadId,
|
|
25265
25309
|
resourceId: record.resourceId ?? void 0,
|
|
@@ -25469,6 +25513,88 @@ ${formattedMessages}
|
|
|
25469
25513
|
};
|
|
25470
25514
|
}
|
|
25471
25515
|
/**
|
|
25516
|
+
* Compose the config-level hooks with optional per-call hooks into a single
|
|
25517
|
+
* `ObserveHooks` object, binding call context onto the config-level
|
|
25518
|
+
* callbacks. Config-level hooks are guarded so a throwing consumer hook can
|
|
25519
|
+
* never fail an observation/reflection cycle; per-call hooks keep their
|
|
25520
|
+
* existing payloads and propagation semantics. Returns undefined when
|
|
25521
|
+
* neither is configured, so call sites stay zero-cost.
|
|
25522
|
+
*
|
|
25523
|
+
* Used internally by every pipeline path (manual observe/reflect,
|
|
25524
|
+
* turn-engine sync observation, async buffering); public only so the
|
|
25525
|
+
* observation turn engine can thread config-level reflection hooks into
|
|
25526
|
+
* reflector calls.
|
|
25527
|
+
*
|
|
25528
|
+
* @internal
|
|
25529
|
+
*/
|
|
25530
|
+
composeHooks(callHooks, context) {
|
|
25531
|
+
const configHooks = this.hooks;
|
|
25532
|
+
if (!configHooks) return callHooks;
|
|
25533
|
+
if (!callHooks && !Object.keys(configHooks).length) return void 0;
|
|
25534
|
+
const fireConfigHook = (name, arg) => {
|
|
25535
|
+
const hook = configHooks[name];
|
|
25536
|
+
if (!hook) return;
|
|
25537
|
+
const logHookFailure = (error) => omDebug(`[OM:hooks] config-level ${name} hook failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
25538
|
+
try {
|
|
25539
|
+
const out = hook(arg);
|
|
25540
|
+
if (out && typeof out.then === "function") out.then(void 0, logHookFailure);
|
|
25541
|
+
} catch (error) {
|
|
25542
|
+
logHookFailure(error);
|
|
25543
|
+
}
|
|
25544
|
+
};
|
|
25545
|
+
return {
|
|
25546
|
+
onObservationStart: () => {
|
|
25547
|
+
fireConfigHook("onObservationStart", context);
|
|
25548
|
+
callHooks?.onObservationStart?.();
|
|
25549
|
+
},
|
|
25550
|
+
onObservationEnd: (result) => {
|
|
25551
|
+
fireConfigHook("onObservationEnd", {
|
|
25552
|
+
...context,
|
|
25553
|
+
...result
|
|
25554
|
+
});
|
|
25555
|
+
callHooks?.onObservationEnd?.(result);
|
|
25556
|
+
},
|
|
25557
|
+
onReflectionStart: () => {
|
|
25558
|
+
fireConfigHook("onReflectionStart", context);
|
|
25559
|
+
callHooks?.onReflectionStart?.();
|
|
25560
|
+
},
|
|
25561
|
+
onReflectionEnd: (result) => {
|
|
25562
|
+
fireConfigHook("onReflectionEnd", {
|
|
25563
|
+
...context,
|
|
25564
|
+
...result
|
|
25565
|
+
});
|
|
25566
|
+
callHooks?.onReflectionEnd?.(result);
|
|
25567
|
+
}
|
|
25568
|
+
};
|
|
25569
|
+
}
|
|
25570
|
+
/**
|
|
25571
|
+
* Run one buffered observation cycle, firing config-level hooks around it.
|
|
25572
|
+
* Shared by both async-buffer lanes — buffer() and
|
|
25573
|
+
* runAsyncBufferedObservation() — whose fire-and-forget callers never see
|
|
25574
|
+
* the strategy result. The async-buffer strategy swallows failures
|
|
25575
|
+
* (rethrowOnFailure=false) and surfaces them on the result instead, so the
|
|
25576
|
+
* end hook reports `error` for failed cycles even though nothing throws.
|
|
25577
|
+
*/
|
|
25578
|
+
async runBufferedObservationCycle(context, run) {
|
|
25579
|
+
const hooks = this.composeHooks(void 0, context);
|
|
25580
|
+
hooks?.onObservationStart?.();
|
|
25581
|
+
let runResult;
|
|
25582
|
+
let runError;
|
|
25583
|
+
try {
|
|
25584
|
+
runResult = await run();
|
|
25585
|
+
return runResult;
|
|
25586
|
+
} catch (error) {
|
|
25587
|
+
runError = error instanceof Error ? error : new Error(String(error));
|
|
25588
|
+
throw error;
|
|
25589
|
+
} finally {
|
|
25590
|
+
hooks?.onObservationEnd?.({
|
|
25591
|
+
usage: runResult?.usage,
|
|
25592
|
+
error: runError ?? runResult?.error,
|
|
25593
|
+
...runResult?.providerMetadata ? { providerMetadata: runResult.providerMetadata } : {}
|
|
25594
|
+
});
|
|
25595
|
+
}
|
|
25596
|
+
}
|
|
25597
|
+
/**
|
|
25472
25598
|
* Manually trigger observation.
|
|
25473
25599
|
*
|
|
25474
25600
|
* When `messages` is provided, those are used directly (filtered for unobserved)
|
|
@@ -25479,8 +25605,13 @@ ${formattedMessages}
|
|
|
25479
25605
|
* along with the updated record.
|
|
25480
25606
|
*/
|
|
25481
25607
|
async observe(opts) {
|
|
25482
|
-
const { threadId, resourceId, messages,
|
|
25608
|
+
const { threadId, resourceId, messages, requestContext } = opts;
|
|
25483
25609
|
const lockKey = this.buffering.getLockKey(threadId, resourceId);
|
|
25610
|
+
const hooks = this.composeHooks(opts.hooks, {
|
|
25611
|
+
threadId,
|
|
25612
|
+
resourceId,
|
|
25613
|
+
trigger: opts.trigger ?? "manual"
|
|
25614
|
+
});
|
|
25484
25615
|
const reflectionHooks = hooks ? {
|
|
25485
25616
|
onReflectionStart: hooks.onReflectionStart,
|
|
25486
25617
|
onReflectionEnd: hooks.onReflectionEnd
|
|
@@ -25553,6 +25684,15 @@ ${formattedMessages}
|
|
|
25553
25684
|
};
|
|
25554
25685
|
await this.storage.setReflectingFlag(record.id, true);
|
|
25555
25686
|
registerOp(record.id, "reflecting");
|
|
25687
|
+
const hooks = this.composeHooks(void 0, {
|
|
25688
|
+
threadId,
|
|
25689
|
+
resourceId,
|
|
25690
|
+
trigger: "manual"
|
|
25691
|
+
});
|
|
25692
|
+
hooks?.onReflectionStart?.();
|
|
25693
|
+
let reflectionUsage;
|
|
25694
|
+
let reflectionProviderMetadata;
|
|
25695
|
+
let reflectionError;
|
|
25556
25696
|
try {
|
|
25557
25697
|
const thread = await this.storage.getThreadById({ threadId });
|
|
25558
25698
|
const previousOmMetadata = getThreadOMMetadata(thread?.metadata);
|
|
@@ -25582,12 +25722,16 @@ ${formattedMessages}
|
|
|
25582
25722
|
metadata: newMetadata
|
|
25583
25723
|
});
|
|
25584
25724
|
}
|
|
25725
|
+
const updatedRecord = await this.getOrCreateRecord(threadId, resourceId);
|
|
25726
|
+
reflectionUsage = reflectResult.usage;
|
|
25727
|
+
reflectionProviderMetadata = reflectResult.providerMetadata;
|
|
25585
25728
|
return {
|
|
25586
25729
|
reflected: true,
|
|
25587
|
-
record:
|
|
25730
|
+
record: updatedRecord,
|
|
25588
25731
|
usage: reflectResult.usage
|
|
25589
25732
|
};
|
|
25590
25733
|
} catch (error) {
|
|
25734
|
+
reflectionError = error instanceof Error ? error : new Error(String(error));
|
|
25591
25735
|
omError("[OM] reflect() failed", error);
|
|
25592
25736
|
return {
|
|
25593
25737
|
reflected: false,
|
|
@@ -25595,6 +25739,11 @@ ${formattedMessages}
|
|
|
25595
25739
|
usage: void 0
|
|
25596
25740
|
};
|
|
25597
25741
|
} finally {
|
|
25742
|
+
hooks?.onReflectionEnd?.({
|
|
25743
|
+
usage: reflectionUsage,
|
|
25744
|
+
error: reflectionError,
|
|
25745
|
+
...reflectionProviderMetadata ? { providerMetadata: reflectionProviderMetadata } : {}
|
|
25746
|
+
});
|
|
25598
25747
|
await this.storage.setReflectingFlag(record.id, false);
|
|
25599
25748
|
unregisterOp(record.id, "reflecting");
|
|
25600
25749
|
}
|
|
@@ -27188,6 +27337,7 @@ ${workingMemory}`;
|
|
|
27188
27337
|
model: omConfig.model,
|
|
27189
27338
|
mastra: this._mastraInstance,
|
|
27190
27339
|
onIndexObservations,
|
|
27340
|
+
hooks: omConfig.hooks,
|
|
27191
27341
|
observation: omConfig.observation ? {
|
|
27192
27342
|
model: omConfig.observation.model,
|
|
27193
27343
|
messageTokens: omConfig.observation.messageTokens,
|
|
@@ -28103,4 +28253,4 @@ Notes:
|
|
|
28103
28253
|
//#endregion
|
|
28104
28254
|
export { extractCurrentTask as A, OBSERVATION_CONTEXT_INSTRUCTIONS as B, WorkingMemoryExtractor as C, OBSERVER_SYSTEM_PROMPT as D, TokenCounter as E, injectAnchorIds as F, OBSERVATION_CONTINUATION_HINT as H, parseAnchorId as I, stripEphemeralAnchorIds as L, hasCurrentTaskSection as M, optimizeObservationsForContext as N, buildObserverPrompt as O, parseObserverOutput as P, Extractor as R, deepMergeWorkingMemory as S, summarizeConversation as T, OBSERVATION_CONTEXT_PROMPT as V, reconcileObservationGroupsFromReflection as _, extractWorkingMemoryContent as a, wrapInObservationGroup as b, WORKING_MEMORY_STATE_ID as c, getObservationsAsOf as d, ObservationalMemoryProcessor as f, parseObservationGroups as g, deriveObservationGroupProvenance as h, WorkingMemory as i, formatMessagesForObserver as j, buildObserverSystemPrompt as k, WORKING_MEMORY_STATE_PROCESSOR_ID as l, combineObservationGroupRanges as m, MessageHistory$1 as n, extractWorkingMemoryTags as o, ObservationalMemory as p, SemanticRecall as r, removeWorkingMemoryTags as s, Memory as t, WorkingMemoryStateProcessor as u, renderObservationGroupsForReflection as v, SUMMARIZE_THREAD_DEFAULTS as w, ModelByInputTokens as x, stripObservationGroups as y, OBSERVATIONAL_MEMORY_DEFAULTS as z };
|
|
28105
28255
|
|
|
28106
|
-
//# sourceMappingURL=src-
|
|
28256
|
+
//# sourceMappingURL=src-DoNjfXNm.js.map
|