@mastra/memory 1.39.0-alpha.3 → 1.39.0-alpha.4
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/reference-memory-settled.md +13 -5
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +4 -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/extraction-runner.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/sync.d.ts.map +1 -1
- package/dist/processors/observational-memory/observation-turn/step.d.ts.map +1 -1
- package/dist/processors/observational-memory/observation-turn/turn.d.ts.map +1 -1
- package/dist/processors/observational-memory/observational-memory.d.ts +17 -3
- package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -1
- 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 +1 -1
- package/dist/processors/observational-memory/reflector-runner.d.ts.map +1 -1
- package/dist/processors/observational-memory/retry.d.ts +28 -1
- package/dist/processors/observational-memory/retry.d.ts.map +1 -1
- package/dist/{src-Dg8w4Ud-.js → src--zkaCof1.js} +134 -38
- package/dist/{src-Dg8w4Ud-.js.map → src--zkaCof1.js.map} +1 -1
- package/dist/{src-GHUZVCL8.cjs → src-BGgY5kgl.cjs} +134 -38
- package/dist/{src-GHUZVCL8.cjs.map → src-BGgY5kgl.cjs.map} +1 -1
- package/package.json +3 -3
|
@@ -18664,7 +18664,15 @@ const RETRY_CONFIG = {
|
|
|
18664
18664
|
/** Cap on per-attempt delay (ms). */
|
|
18665
18665
|
maxDelayMs: 12e4,
|
|
18666
18666
|
/** Random jitter as a fraction of the computed delay (e.g. 0.2 = ±20%). */
|
|
18667
|
-
jitter: .2
|
|
18667
|
+
jitter: .2,
|
|
18668
|
+
/**
|
|
18669
|
+
* How long one observer, reflector, or extraction model call may go without streaming any
|
|
18670
|
+
* output before it is aborted and retried. Without it a provider that accepts the request but
|
|
18671
|
+
* never answers stalls the call forever, and the retry schedule above never gets a chance to run.
|
|
18672
|
+
* It measures inactivity, not total duration, so a long reply that keeps streaming is never cut
|
|
18673
|
+
* off. It is generous because reasoning models can think silently before their first token.
|
|
18674
|
+
*/
|
|
18675
|
+
modelCallIdleTimeoutMs: 3e5
|
|
18668
18676
|
};
|
|
18669
18677
|
const TRANSIENT_MESSAGE_SUBSTRINGS = [
|
|
18670
18678
|
"terminated",
|
|
@@ -18683,6 +18691,19 @@ const TRANSIENT_MESSAGE_SUBSTRINGS = [
|
|
|
18683
18691
|
];
|
|
18684
18692
|
const INCOMPLETE_FINISH_REASONS = /* @__PURE__ */ new Set(["other", "unknown"]);
|
|
18685
18693
|
/**
|
|
18694
|
+
* A model call that streamed nothing for `RETRY_CONFIG.modelCallIdleTimeoutMs`. Retryable, and
|
|
18695
|
+
* deliberately not an AbortError so `withRetry` doesn't treat it as cancellation.
|
|
18696
|
+
*
|
|
18697
|
+
* @internal
|
|
18698
|
+
*/
|
|
18699
|
+
var OmModelCallTimeoutError = class extends Error {
|
|
18700
|
+
isRetryable = true;
|
|
18701
|
+
constructor(label, idleTimeoutMs) {
|
|
18702
|
+
super(`${label} call produced no output for ${idleTimeoutMs}ms`);
|
|
18703
|
+
this.name = "OmModelCallTimeoutError";
|
|
18704
|
+
}
|
|
18705
|
+
};
|
|
18706
|
+
/**
|
|
18686
18707
|
* A model reply that ended before the model finished. Carries the AI SDK's
|
|
18687
18708
|
* `isRetryable` flag, which `isTransientLLMError` and core's error processors
|
|
18688
18709
|
* already recognize.
|
|
@@ -18825,6 +18846,51 @@ function sleep(ms, abortSignal) {
|
|
|
18825
18846
|
});
|
|
18826
18847
|
}
|
|
18827
18848
|
/**
|
|
18849
|
+
* Run one attempt, failing with a retryable `OmModelCallTimeoutError` if it
|
|
18850
|
+
* goes `idleTimeoutMs` without calling `onActivity`. `fn` gets a signal that
|
|
18851
|
+
* aborts on timeout or on the caller's signal, so the underlying request is
|
|
18852
|
+
* cancelled too.
|
|
18853
|
+
*/
|
|
18854
|
+
async function attemptWithIdleTimeout(fn, label, idleTimeoutMs, abortSignal) {
|
|
18855
|
+
const controller = new AbortController();
|
|
18856
|
+
let rejectOnAbort;
|
|
18857
|
+
const callerAborted = new Promise((_, reject) => {
|
|
18858
|
+
rejectOnAbort = reject;
|
|
18859
|
+
});
|
|
18860
|
+
const onAbort = () => {
|
|
18861
|
+
controller.abort(abortSignal?.reason);
|
|
18862
|
+
rejectOnAbort(abortSignal?.reason ?? /* @__PURE__ */ new Error("The operation was aborted."));
|
|
18863
|
+
};
|
|
18864
|
+
abortSignal?.addEventListener("abort", onAbort, { once: true });
|
|
18865
|
+
let timer;
|
|
18866
|
+
let rejectOnIdle;
|
|
18867
|
+
const idle = new Promise((_, reject) => {
|
|
18868
|
+
rejectOnIdle = reject;
|
|
18869
|
+
});
|
|
18870
|
+
const armIdleTimer = () => {
|
|
18871
|
+
clearTimeout(timer);
|
|
18872
|
+
timer = setTimeout(() => {
|
|
18873
|
+
const error = new OmModelCallTimeoutError(label, idleTimeoutMs);
|
|
18874
|
+
rejectOnIdle(error);
|
|
18875
|
+
controller.abort(error);
|
|
18876
|
+
}, idleTimeoutMs);
|
|
18877
|
+
};
|
|
18878
|
+
const onActivity = () => {
|
|
18879
|
+
if (!controller.signal.aborted) armIdleTimer();
|
|
18880
|
+
};
|
|
18881
|
+
armIdleTimer();
|
|
18882
|
+
try {
|
|
18883
|
+
return await Promise.race([
|
|
18884
|
+
fn(controller.signal, onActivity),
|
|
18885
|
+
idle,
|
|
18886
|
+
callerAborted
|
|
18887
|
+
]);
|
|
18888
|
+
} finally {
|
|
18889
|
+
clearTimeout(timer);
|
|
18890
|
+
abortSignal?.removeEventListener("abort", onAbort);
|
|
18891
|
+
}
|
|
18892
|
+
}
|
|
18893
|
+
/**
|
|
18828
18894
|
* Run `fn` with retries on transient transport-class errors.
|
|
18829
18895
|
*
|
|
18830
18896
|
* Non-transient errors (auth, validation, schema, etc.) are rethrown
|
|
@@ -18833,14 +18899,16 @@ function sleep(ms, abortSignal) {
|
|
|
18833
18899
|
* @internal
|
|
18834
18900
|
*/
|
|
18835
18901
|
async function withRetry(fn, opts) {
|
|
18836
|
-
const { label, abortSignal, maxRetries = RETRY_CONFIG.maxRetries } = opts;
|
|
18902
|
+
const { label, abortSignal, maxRetries = RETRY_CONFIG.maxRetries, idleTimeoutMs } = opts;
|
|
18837
18903
|
let attempt = 0;
|
|
18838
18904
|
while (true) {
|
|
18839
18905
|
if (abortSignal?.aborted) throw new Error("The operation was aborted.");
|
|
18840
18906
|
try {
|
|
18841
|
-
return await fn();
|
|
18907
|
+
if (idleTimeoutMs === void 0) return await fn(abortSignal ?? new AbortController().signal, () => {});
|
|
18908
|
+
return await attemptWithIdleTimeout(fn, label, idleTimeoutMs, abortSignal);
|
|
18842
18909
|
} catch (error) {
|
|
18843
|
-
if (
|
|
18910
|
+
if (abortSignal?.aborted) throw error;
|
|
18911
|
+
if (!(error instanceof OmModelCallTimeoutError) && hasAbortInChain(error)) throw error;
|
|
18844
18912
|
if (attempt >= maxRetries || !isTransientLLMError(error)) {
|
|
18845
18913
|
if (attempt > 0) omDebug(`[OM:retry:${label}] giving up after ${attempt} retry/retries: ${error instanceof Error ? error.message : String(error)}`);
|
|
18846
18914
|
throw error;
|
|
@@ -18960,19 +19028,21 @@ If a prior value is still applicable and carry-forward is enabled, return that p
|
|
|
18960
19028
|
${extractorInstructions}${priorLines.length > 0 ? `\n\n## Prior Extracted Values\n\n${priorLines.join("\n\n")}` : ""}`;
|
|
18961
19029
|
const values = {};
|
|
18962
19030
|
const failures = [];
|
|
18963
|
-
const streamWithStructuredOutput = async (jsonPromptInjection) => withRetry(() => streamOnce(jsonPromptInjection), {
|
|
19031
|
+
const streamWithStructuredOutput = async (jsonPromptInjection) => withRetry((attemptSignal, onActivity) => streamOnce(jsonPromptInjection, attemptSignal, onActivity), {
|
|
18964
19032
|
label: `om-${opts.source}-structured-extraction`,
|
|
18965
19033
|
abortSignal: opts.abortSignal,
|
|
18966
|
-
maxRetries: 1
|
|
19034
|
+
maxRetries: 1,
|
|
19035
|
+
idleTimeoutMs: RETRY_CONFIG.modelCallIdleTimeoutMs
|
|
18967
19036
|
});
|
|
18968
|
-
const streamOnce = async (jsonPromptInjection) => {
|
|
19037
|
+
const streamOnce = async (jsonPromptInjection, abortSignal, onActivity) => {
|
|
18969
19038
|
const object = await (await opts.agent.stream(prompt, {
|
|
18970
19039
|
structuredOutput: {
|
|
18971
19040
|
schema,
|
|
18972
19041
|
...jsonPromptInjection ? { jsonPromptInjection } : {}
|
|
18973
19042
|
},
|
|
18974
19043
|
...opts.memory ? { memory: opts.memory } : {},
|
|
18975
|
-
|
|
19044
|
+
abortSignal,
|
|
19045
|
+
onChunk: onActivity,
|
|
18976
19046
|
...opts.requestContext ? { requestContext: opts.requestContext } : {},
|
|
18977
19047
|
...opts.observabilityContext
|
|
18978
19048
|
})).object;
|
|
@@ -21740,7 +21810,7 @@ var ObserverRunner = class {
|
|
|
21740
21810
|
timeZone: options?.timeZone
|
|
21741
21811
|
})];
|
|
21742
21812
|
const doGenerate = async () => {
|
|
21743
|
-
return withRetry(() => withOmTracingSpan({
|
|
21813
|
+
return withRetry((attemptSignal, onActivity) => withOmTracingSpan({
|
|
21744
21814
|
phase: "observer",
|
|
21745
21815
|
model: resolvedModel.model,
|
|
21746
21816
|
inputTokens,
|
|
@@ -21763,7 +21833,8 @@ var ObserverRunner = class {
|
|
|
21763
21833
|
modelSettings: { ...this.observationConfig.modelSettings },
|
|
21764
21834
|
providerOptions: this.observationConfig.providerOptions,
|
|
21765
21835
|
...attemptMemory ? { memory: attemptMemory } : {},
|
|
21766
|
-
|
|
21836
|
+
abortSignal: attemptSignal,
|
|
21837
|
+
onChunk: onActivity,
|
|
21767
21838
|
...internalRequestContext ? { requestContext: internalRequestContext } : {},
|
|
21768
21839
|
...childObservabilityContext
|
|
21769
21840
|
})).getFullOutput(), "OM observer");
|
|
@@ -21785,6 +21856,7 @@ var ObserverRunner = class {
|
|
|
21785
21856
|
}), {
|
|
21786
21857
|
label: "observer",
|
|
21787
21858
|
abortSignal,
|
|
21859
|
+
idleTimeoutMs: RETRY_CONFIG.modelCallIdleTimeoutMs,
|
|
21788
21860
|
maxRetries: this.observationConfig.maxRetries
|
|
21789
21861
|
});
|
|
21790
21862
|
};
|
|
@@ -21953,7 +22025,7 @@ var ObserverRunner = class {
|
|
|
21953
22025
|
timeZone
|
|
21954
22026
|
})];
|
|
21955
22027
|
const doGenerate = async () => {
|
|
21956
|
-
return withRetry(() => withOmTracingSpan({
|
|
22028
|
+
return withRetry((attemptSignal, onActivity) => withOmTracingSpan({
|
|
21957
22029
|
phase: "observer-multi-thread",
|
|
21958
22030
|
model: resolvedModel.model,
|
|
21959
22031
|
inputTokens,
|
|
@@ -21974,7 +22046,8 @@ var ObserverRunner = class {
|
|
|
21974
22046
|
maxSteps: 1,
|
|
21975
22047
|
modelSettings: { ...this.observationConfig.modelSettings },
|
|
21976
22048
|
providerOptions: this.observationConfig.providerOptions,
|
|
21977
|
-
|
|
22049
|
+
abortSignal: attemptSignal,
|
|
22050
|
+
onChunk: onActivity,
|
|
21978
22051
|
...internalRequestContext ? { requestContext: internalRequestContext } : {},
|
|
21979
22052
|
...childObservabilityContext
|
|
21980
22053
|
})).getFullOutput(), "OM multi-thread observer");
|
|
@@ -21998,6 +22071,7 @@ var ObserverRunner = class {
|
|
|
21998
22071
|
}), {
|
|
21999
22072
|
label: "observer-multi-thread",
|
|
22000
22073
|
abortSignal,
|
|
22074
|
+
idleTimeoutMs: RETRY_CONFIG.modelCallIdleTimeoutMs,
|
|
22001
22075
|
maxRetries: this.observationConfig.maxRetries
|
|
22002
22076
|
});
|
|
22003
22077
|
};
|
|
@@ -28679,7 +28753,10 @@ var ObservationStep = class {
|
|
|
28679
28753
|
observabilityContext: this.turn.observabilityContext
|
|
28680
28754
|
}).catch((err) => {
|
|
28681
28755
|
omDebug(`[OM:buffer] fire-and-forget buffer failed: ${err?.message}`);
|
|
28682
|
-
})
|
|
28756
|
+
}), {
|
|
28757
|
+
threadId,
|
|
28758
|
+
resourceId
|
|
28759
|
+
});
|
|
28683
28760
|
buffered = true;
|
|
28684
28761
|
}
|
|
28685
28762
|
}
|
|
@@ -29232,7 +29309,10 @@ var ObservationTurn = class {
|
|
|
29232
29309
|
skipMinimumTokenCheck: true
|
|
29233
29310
|
}).catch((err) => {
|
|
29234
29311
|
omDebug(`[OM:turn.end] idle buffer failed: ${err?.message}`);
|
|
29235
|
-
})
|
|
29312
|
+
}), {
|
|
29313
|
+
threadId: this.threadId,
|
|
29314
|
+
resourceId: this.resourceId
|
|
29315
|
+
});
|
|
29236
29316
|
}
|
|
29237
29317
|
return { record: this._record };
|
|
29238
29318
|
}
|
|
@@ -29790,7 +29870,7 @@ var ReflectorRunner = class {
|
|
|
29790
29870
|
const prompt = buildReflectorPrompt(observations, manualPrompt, currentLevel, skipContinuationHints, activeExtractors, priorExtractedValues);
|
|
29791
29871
|
omDebug(`[OM:callReflector] ${isRetry ? `retry #${attemptNumber - 1}` : "first attempt"}: level=${currentLevel}, originalTokens=${originalTokens}, targetThreshold=${targetThreshold}, promptLen=${prompt.length}, skipContinuationHints=${skipContinuationHints}`);
|
|
29792
29872
|
let chunkCount = 0;
|
|
29793
|
-
const result = await withRetry(() => withOmTracingSpan({
|
|
29873
|
+
const result = await withRetry((attemptSignal, onActivity) => withOmTracingSpan({
|
|
29794
29874
|
phase: "reflector",
|
|
29795
29875
|
model: resolvedModel.model,
|
|
29796
29876
|
inputTokens: originalTokens,
|
|
@@ -29814,17 +29894,19 @@ var ReflectorRunner = class {
|
|
|
29814
29894
|
modelSettings: { ...this.reflectionConfig.modelSettings },
|
|
29815
29895
|
providerOptions: this.reflectionConfig.providerOptions,
|
|
29816
29896
|
...attemptMemory ? { memory: attemptMemory } : {},
|
|
29817
|
-
|
|
29897
|
+
abortSignal: attemptSignal,
|
|
29818
29898
|
...internalRequestContext ? { requestContext: internalRequestContext } : {},
|
|
29819
29899
|
...childObservabilityContext,
|
|
29900
|
+
onChunk(chunk) {
|
|
29901
|
+
onActivity();
|
|
29902
|
+
if (attemptNumber !== 1) return;
|
|
29903
|
+
chunkCount++;
|
|
29904
|
+
if (chunkCount === 1 || chunkCount % 50 === 0) {
|
|
29905
|
+
const preview = chunk.type === "text-delta" ? ` text="${chunk.textDelta?.slice(0, 80)}..."` : chunk.type === "tool-call" ? ` tool=${chunk.toolName}` : "";
|
|
29906
|
+
omDebug(`[OM:callReflector] chunk#${chunkCount}: type=${chunk.type}${preview}`);
|
|
29907
|
+
}
|
|
29908
|
+
},
|
|
29820
29909
|
...attemptNumber === 1 ? {
|
|
29821
|
-
onChunk(chunk) {
|
|
29822
|
-
chunkCount++;
|
|
29823
|
-
if (chunkCount === 1 || chunkCount % 50 === 0) {
|
|
29824
|
-
const preview = chunk.type === "text-delta" ? ` text="${chunk.textDelta?.slice(0, 80)}..."` : chunk.type === "tool-call" ? ` tool=${chunk.toolName}` : "";
|
|
29825
|
-
omDebug(`[OM:callReflector] chunk#${chunkCount}: type=${chunk.type}${preview}`);
|
|
29826
|
-
}
|
|
29827
|
-
},
|
|
29828
29910
|
onFinish(event) {
|
|
29829
29911
|
omDebug(`[OM:callReflector] onFinish: chunks=${chunkCount}, finishReason=${event.finishReason}, inputTokens=${event.usage?.inputTokens}, outputTokens=${event.usage?.outputTokens}, textLen=${event.text?.length}`);
|
|
29830
29912
|
},
|
|
@@ -29844,6 +29926,7 @@ var ReflectorRunner = class {
|
|
|
29844
29926
|
}), {
|
|
29845
29927
|
label: "reflector",
|
|
29846
29928
|
abortSignal,
|
|
29929
|
+
idleTimeoutMs: RETRY_CONFIG.modelCallIdleTimeoutMs,
|
|
29847
29930
|
maxRetries: this.reflectionConfig.maxRetries
|
|
29848
29931
|
});
|
|
29849
29932
|
omDebug(`[OM:callReflector] attempt #${attemptNumber} returned: textLen=${result.text?.length}, textPreview="${result.text?.slice(0, 120)}...", inputTokens=${result.usage?.inputTokens ?? result.totalUsage?.inputTokens}, outputTokens=${result.usage?.outputTokens ?? result.totalUsage?.outputTokens}`);
|
|
@@ -30002,7 +30085,7 @@ var ReflectorRunner = class {
|
|
|
30002
30085
|
}
|
|
30003
30086
|
})();
|
|
30004
30087
|
BufferingCoordinator.asyncBufferingOps.set(bufferKey, asyncOp);
|
|
30005
|
-
this.trackBackgroundWork?.(asyncOp);
|
|
30088
|
+
this.trackBackgroundWork?.(asyncOp, lockKey);
|
|
30006
30089
|
}
|
|
30007
30090
|
/**
|
|
30008
30091
|
* Perform async buffered reflection — reflects observations and stores to bufferedReflection.
|
|
@@ -31030,32 +31113,44 @@ var ObservationalMemory = class ObservationalMemory {
|
|
|
31030
31113
|
* Tracked so callers can join them via `settled()` before closing a storage
|
|
31031
31114
|
* connection they own — otherwise a background cycle's tail statements race the close.
|
|
31032
31115
|
*/
|
|
31033
|
-
pendingBackgroundWork = /* @__PURE__ */ new
|
|
31116
|
+
pendingBackgroundWork = /* @__PURE__ */ new Map();
|
|
31034
31117
|
/**
|
|
31035
31118
|
* Register fire-and-forget background work so `settled()` can join it.
|
|
31119
|
+
* `scope` is the conversation the work belongs to (thread/resource ids, or a lock key from
|
|
31120
|
+
* `buffering.getLockKey`),
|
|
31121
|
+
* so a scoped `settled()` can wait for one conversation without waiting for every other.
|
|
31036
31122
|
* Returns the original promise so callers keep their own rejection handling.
|
|
31037
31123
|
*/
|
|
31038
|
-
trackBackgroundWork(work) {
|
|
31124
|
+
trackBackgroundWork(work, scope) {
|
|
31125
|
+
const lockKey = typeof scope === "string" ? scope : this.buffering.getLockKey(scope.threadId, scope.resourceId);
|
|
31039
31126
|
const tracked = work.catch(() => {}).finally(() => {
|
|
31040
31127
|
this.pendingBackgroundWork.delete(tracked);
|
|
31041
31128
|
});
|
|
31042
|
-
this.pendingBackgroundWork.
|
|
31129
|
+
this.pendingBackgroundWork.set(tracked, lockKey);
|
|
31043
31130
|
return work;
|
|
31044
31131
|
}
|
|
31045
31132
|
/**
|
|
31046
|
-
* Resolve once
|
|
31133
|
+
* Resolve once background observational-memory work started so far has finished.
|
|
31134
|
+
*
|
|
31135
|
+
* Pass `threadId`/`resourceId` to wait only for that conversation's work. An engine shared by
|
|
31136
|
+
* many busy threads may never be fully idle, so an unscoped wait can last indefinitely there.
|
|
31137
|
+
* A scope without the id this engine keys work on (`resourceId` for resource scope, `threadId`
|
|
31138
|
+
* for thread scope) can't be matched to its work, so it falls back to waiting for all work.
|
|
31047
31139
|
*
|
|
31048
31140
|
* Background cycles enqueue further background work (a buffered observation can
|
|
31049
31141
|
* trigger a reflection, which runs nested agent streams), so this drains repeatedly
|
|
31050
31142
|
* until nothing is left rather than joining a single snapshot.
|
|
31051
31143
|
*/
|
|
31052
|
-
async settled() {
|
|
31144
|
+
async settled(scope) {
|
|
31145
|
+
const lockKey = (this.scope === "resource" ? scope?.resourceId : scope?.threadId) ? this.buffering.getLockKey(scope.threadId, scope.resourceId) : void 0;
|
|
31146
|
+
const pending = () => [...this.pendingBackgroundWork].filter(([, key]) => lockKey === void 0 || key === lockKey).map(([w]) => w);
|
|
31053
31147
|
const maxDrainRounds = 100;
|
|
31054
31148
|
for (let round = 0; round < maxDrainRounds; round++) {
|
|
31055
|
-
|
|
31056
|
-
|
|
31149
|
+
const work = pending();
|
|
31150
|
+
if (work.length === 0) return;
|
|
31151
|
+
await Promise.allSettled(work);
|
|
31057
31152
|
}
|
|
31058
|
-
if (
|
|
31153
|
+
if (pending().length === 0) return;
|
|
31059
31154
|
omError(`[OM:settled] background work still pending after ${maxDrainRounds} drain rounds; giving up waiting`);
|
|
31060
31155
|
}
|
|
31061
31156
|
/**
|
|
@@ -31212,7 +31307,7 @@ var ObservationalMemory = class ObservationalMemory {
|
|
|
31212
31307
|
memory: this.memory,
|
|
31213
31308
|
onReflectionCommitted: config.onReflectionCommitted,
|
|
31214
31309
|
hooks: this.hooks,
|
|
31215
|
-
trackBackgroundWork: (work) => this.trackBackgroundWork(work)
|
|
31310
|
+
trackBackgroundWork: (work, lockKey) => this.trackBackgroundWork(work, lockKey)
|
|
31216
31311
|
});
|
|
31217
31312
|
this.validateBufferConfig();
|
|
31218
31313
|
if (this.scope === "resource" && !hasWarnedResourceScopeDeprecation) {
|
|
@@ -32068,11 +32163,12 @@ ${formattedMessages}
|
|
|
32068
32163
|
}).finally(() => {
|
|
32069
32164
|
if (BufferingCoordinator.asyncBufferingOps.get(bufferKey) === asyncOp) BufferingCoordinator.asyncBufferingOps.delete(bufferKey);
|
|
32070
32165
|
unregisterOp(record.id, "bufferingObservation");
|
|
32071
|
-
runOMCommit(lockKey, () => this.storage.setBufferingObservationFlag(record.id, false)).catch((err) => {
|
|
32166
|
+
return runOMCommit(lockKey, () => this.storage.setBufferingObservationFlag(record.id, false)).catch((err) => {
|
|
32072
32167
|
omError("[OM] Failed to clear buffering observation flag", err);
|
|
32073
32168
|
});
|
|
32074
32169
|
});
|
|
32075
32170
|
BufferingCoordinator.asyncBufferingOps.set(bufferKey, asyncOp);
|
|
32171
|
+
return { op: asyncOp };
|
|
32076
32172
|
}
|
|
32077
32173
|
/**
|
|
32078
32174
|
* Internal method that waits for existing buffering operation and then runs new buffering.
|
|
@@ -32172,7 +32268,7 @@ ${formattedMessages}
|
|
|
32172
32268
|
if (!this.buffering.isAsyncObservationEnabled()) return false;
|
|
32173
32269
|
const lockKey = this.buffering.getLockKey(opts.threadId, opts.resourceId);
|
|
32174
32270
|
const shouldTrigger = this.buffering.shouldTriggerAsyncObservation(opts.pendingTokens, lockKey, opts.record, this.storage, opts.threshold);
|
|
32175
|
-
if (shouldTrigger) this.trackBackgroundWork(this.startAsyncBufferedObservation(opts.record, opts.threadId, opts.unobservedMessages, lockKey, opts.writer, opts.unbufferedPendingTokens, opts.requestContext, opts.observabilityContext));
|
|
32271
|
+
if (shouldTrigger) this.trackBackgroundWork(this.startAsyncBufferedObservation(opts.record, opts.threadId, opts.unobservedMessages, lockKey, opts.writer, opts.unbufferedPendingTokens, opts.requestContext, opts.observabilityContext).then(({ op }) => op), lockKey);
|
|
32176
32272
|
return shouldTrigger;
|
|
32177
32273
|
}
|
|
32178
32274
|
isMessageList(value) {
|
|
@@ -34224,9 +34320,9 @@ var Memory = class Memory extends MastraMemory {
|
|
|
34224
34320
|
* await store.close();
|
|
34225
34321
|
* ```
|
|
34226
34322
|
*/
|
|
34227
|
-
async settled() {
|
|
34323
|
+
async settled(scope) {
|
|
34228
34324
|
await this.pendingVectorCleanup;
|
|
34229
|
-
await (this._omEngine ? await this._omEngine : this._omEngineInstance)?.settled();
|
|
34325
|
+
await (this._omEngine ? await this._omEngine : this._omEngineInstance)?.settled(scope);
|
|
34230
34326
|
await this.pendingVectorCleanup;
|
|
34231
34327
|
}
|
|
34232
34328
|
/** The shared ObservationalMemory engine. Lazily created on first access. */
|
|
@@ -36515,4 +36611,4 @@ Notes:
|
|
|
36515
36611
|
//#endregion
|
|
36516
36612
|
export { renderSubconsciousActivity as $, buildObserverSystemPrompt as A, OBSERVATION_CONTEXT_INSTRUCTIONS as B, WorkingMemoryExtractor as C, TokenCounter as D, summarizeConversation as E, parseObserverOutput as F, Subconscious as G, OBSERVATION_CONTEXT_PROMPT_THREAD as H, injectAnchorIds as I, SubconsciousRemindExtractor as J, KnowledgeSemanticIndexCoordinator as K, parseAnchorId as L, formatMessagesForObserver as M, hasCurrentTaskSection as N, OBSERVER_SYSTEM_PROMPT as O, optimizeObservationsForContext as P, publishSubconsciousActivity as Q, stripEphemeralAnchorIds as R, wrapInObservationGroup as S, SUMMARIZE_THREAD_DEFAULTS as T, OBSERVATION_CONTINUATION_HINT as U, OBSERVATION_CONTEXT_PROMPT as V, getObservationContextPrompt as W, SUBCONSCIOUS_ACTIVITY_STATE_ID as X, ModelByInputTokens as Y, buildSubconsciousActivitySnapshot as Z, deriveObservationGroupProvenance as _, extractWorkingMemoryContent as a, renderObservationGroupsForReflection as b, getObservationsAsOf as c, AUTO_MODEL_BY_PROVIDER as d, Extractor as et, resolveAutoModelId as f, combineObservationGroupRanges as g, WorkingMemoryStateProcessor as h, WorkingMemory as i, extractCurrentTask as j, buildObserverPrompt as k, ObservationalMemoryProcessor as l, WORKING_MEMORY_STATE_PROCESSOR_ID as m, MessageHistory$1 as n, extractWorkingMemoryTags as o, WORKING_MEMORY_STATE_ID as p, StaleKnowledgeSemanticIndexError as q, SemanticRecall as r, removeWorkingMemoryTags as s, Memory as t, ObservationalMemory as u, parseObservationGroups as v, deepMergeWorkingMemory as w, stripObservationGroups as x, reconcileObservationGroupsFromReflection as y, OBSERVATIONAL_MEMORY_DEFAULTS as z };
|
|
36517
36613
|
|
|
36518
|
-
//# sourceMappingURL=src
|
|
36614
|
+
//# sourceMappingURL=src--zkaCof1.js.map
|