@mastra/memory 1.18.0-alpha.2 → 1.18.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/CHANGELOG.md +19 -0
- package/dist/{chunk-PBZHHKPE.js → chunk-LPMZNXSF.js} +248 -109
- package/dist/chunk-LPMZNXSF.js.map +1 -0
- package/dist/{chunk-MJNTQ6GP.cjs → chunk-NRYX4QWV.cjs} +248 -109
- package/dist/chunk-NRYX4QWV.cjs.map +1 -0
- package/dist/docs/SKILL.md +2 -1
- package/dist/docs/assets/SOURCE_MAP.json +39 -39
- package/dist/docs/references/docs-memory-observational-memory.md +56 -12
- package/dist/docs/references/reference-memory-observational-memory.md +11 -1
- package/dist/docs/references/reference-storage-dsql.md +428 -0
- package/dist/docs/references/reference-storage-dynamodb.md +1 -1
- package/dist/docs/references/reference-storage-libsql.md +1 -1
- package/dist/docs/references/reference-storage-postgresql.md +1 -1
- package/dist/docs/references/reference-storage-upstash.md +1 -1
- package/dist/index.cjs +102 -147
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +93 -138
- package/dist/index.js.map +1 -1
- package/dist/{observational-memory-IP2RVQQG.js → observational-memory-NL7AQHZV.js} +3 -3
- package/dist/{observational-memory-IP2RVQQG.js.map → observational-memory-NL7AQHZV.js.map} +1 -1
- package/dist/{observational-memory-TASIB4PH.cjs → observational-memory-TZ67ZA32.cjs} +26 -26
- package/dist/{observational-memory-TASIB4PH.cjs.map → observational-memory-TZ67ZA32.cjs.map} +1 -1
- package/dist/processors/index.cjs +24 -24
- package/dist/processors/index.js +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/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.map +1 -1
- package/dist/processors/observational-memory/retry.d.ts +63 -0
- package/dist/processors/observational-memory/retry.d.ts.map +1 -0
- package/dist/processors/observational-memory/types.d.ts +35 -4
- package/dist/processors/observational-memory/types.d.ts.map +1 -1
- package/package.json +5 -5
- package/dist/chunk-MJNTQ6GP.cjs.map +0 -1
- package/dist/chunk-PBZHHKPE.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @mastra/memory
|
|
2
2
|
|
|
3
|
+
## 1.18.0-alpha.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Auto-recover from transient transport errors (e.g. undici `terminated`, `fetch failed`, `UND_ERR_*`, 5xx, 429) in the OM observer and reflector LLM calls. Adds an internal retry wrapper with exponential backoff (1s, 2s, 4s, 8s, 16s, 32s, 64s, 120s — per-attempt delay capped at 2 minutes, ~4 minute total budget per call) so a single network blip from any provider no longer kills the actor turn during long-running sessions. Non-transient errors (auth, validation, etc.) and user-initiated aborts still fail fast. No public API changes. ([#16454](https://github.com/mastra-ai/mastra/pull/16454))
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`b59316f`](https://github.com/mastra-ai/mastra/commit/b59316ffa0f7688165b0f9c81ccdf85da461e5b2), [`55f1e2d`](https://github.com/mastra-ai/mastra/commit/55f1e2d65425b95a49ae788053b266f256e38c96), [`d48a705`](https://github.com/mastra-ai/mastra/commit/d48a705ff3dfbdc7a996e07ecd8293b5effd9a2a)]:
|
|
10
|
+
- @mastra/core@1.33.0-alpha.12
|
|
11
|
+
|
|
12
|
+
## 1.18.0-alpha.3
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Default top-level observational memory early activation settings to observations only, while allowing per-phase overrides under `observation` and `reflection`. ([#16367](https://github.com/mastra-ai/mastra/pull/16367))
|
|
17
|
+
|
|
18
|
+
- Updated dependencies [[`7c275a8`](https://github.com/mastra-ai/mastra/commit/7c275a810595e1a6c41ccc39720531ab65734700), [`890b24c`](https://github.com/mastra-ai/mastra/commit/890b24cc7d32ed6aa4dfe253e54dc6bf4099f690), [`0f48ebf`](https://github.com/mastra-ai/mastra/commit/0f48ebfc7ac7897b2092a189f45751924cf56d1c), [`f180e49`](https://github.com/mastra-ai/mastra/commit/f180e4990e71b04c9a475b523584071712f0048f), [`9260e01`](https://github.com/mastra-ai/mastra/commit/9260e015276fb1b500f7878ee452b47476bf1583), [`2f6c54e`](https://github.com/mastra-ai/mastra/commit/2f6c54e17c041cac1def54baaa6b771647836414), [`e06a159`](https://github.com/mastra-ai/mastra/commit/e06a1598ca07a6c3778aefc2a2d288363c6294ff), [`c50ebc3`](https://github.com/mastra-ai/mastra/commit/c50ebc34da71044558315735e69bfb94fcfb74bf), [`db34bc6`](https://github.com/mastra-ai/mastra/commit/db34bc6fb36cf125bda0c46be4d3fdc774b70cc4)]:
|
|
19
|
+
- @mastra/core@1.33.0-alpha.8
|
|
20
|
+
- @mastra/schema-compat@1.2.10-alpha.0
|
|
21
|
+
|
|
3
22
|
## 1.18.0-alpha.2
|
|
4
23
|
|
|
5
24
|
### Minor Changes
|
|
@@ -1013,8 +1013,6 @@ var ObservationStrategy = class _ObservationStrategy {
|
|
|
1013
1013
|
this.scope = deps.scope;
|
|
1014
1014
|
this.retrieval = deps.retrieval;
|
|
1015
1015
|
}
|
|
1016
|
-
deps;
|
|
1017
|
-
opts;
|
|
1018
1016
|
storage;
|
|
1019
1017
|
messageHistory;
|
|
1020
1018
|
tokenCounter;
|
|
@@ -2043,8 +2041,6 @@ var ObservationStep = class {
|
|
|
2043
2041
|
this.turn = turn;
|
|
2044
2042
|
this.stepNumber = stepNumber;
|
|
2045
2043
|
}
|
|
2046
|
-
turn;
|
|
2047
|
-
stepNumber;
|
|
2048
2044
|
_prepared = false;
|
|
2049
2045
|
_context;
|
|
2050
2046
|
/** Whether this step has been prepared. */
|
|
@@ -3791,6 +3787,135 @@ function optimizeObservationsForContext(observations) {
|
|
|
3791
3787
|
optimized = optimized.replace(/\n{3,}/g, "\n\n");
|
|
3792
3788
|
return optimized.trim();
|
|
3793
3789
|
}
|
|
3790
|
+
|
|
3791
|
+
// src/processors/observational-memory/retry.ts
|
|
3792
|
+
var RETRY_CONFIG = {
|
|
3793
|
+
/** Maximum number of retry *attempts* (total tries = maxRetries + 1). */
|
|
3794
|
+
maxRetries: 8,
|
|
3795
|
+
/** Initial backoff delay in milliseconds. */
|
|
3796
|
+
initialDelayMs: 1e3,
|
|
3797
|
+
/** Multiplier applied to the delay after each failed attempt. */
|
|
3798
|
+
backoffFactor: 2,
|
|
3799
|
+
/** Cap on per-attempt delay (ms). */
|
|
3800
|
+
maxDelayMs: 12e4,
|
|
3801
|
+
/** Random jitter as a fraction of the computed delay (e.g. 0.2 = ±20%). */
|
|
3802
|
+
jitter: 0.2
|
|
3803
|
+
};
|
|
3804
|
+
var TRANSIENT_MESSAGE_SUBSTRINGS = [
|
|
3805
|
+
"terminated",
|
|
3806
|
+
"fetch failed",
|
|
3807
|
+
"econnreset",
|
|
3808
|
+
"econnrefused",
|
|
3809
|
+
"enotfound",
|
|
3810
|
+
"eai_again",
|
|
3811
|
+
"socket hang up",
|
|
3812
|
+
"network error",
|
|
3813
|
+
"request timed out",
|
|
3814
|
+
"request timeout",
|
|
3815
|
+
"connection reset",
|
|
3816
|
+
"connection closed"
|
|
3817
|
+
];
|
|
3818
|
+
function isRecord2(value) {
|
|
3819
|
+
return typeof value === "object" && value !== null;
|
|
3820
|
+
}
|
|
3821
|
+
function isAbortError(error) {
|
|
3822
|
+
if (!isRecord2(error)) return false;
|
|
3823
|
+
if (error.name === "AbortError") return true;
|
|
3824
|
+
if (typeof error.code === "string" && error.code === "ABORT_ERR") return true;
|
|
3825
|
+
return false;
|
|
3826
|
+
}
|
|
3827
|
+
function hasTransientMessage(value) {
|
|
3828
|
+
if (!isRecord2(value)) return false;
|
|
3829
|
+
const message = typeof value.message === "string" ? value.message.toLowerCase() : "";
|
|
3830
|
+
if (message && TRANSIENT_MESSAGE_SUBSTRINGS.some((sub) => message.includes(sub))) return true;
|
|
3831
|
+
if (typeof value.code === "string" && value.code.toUpperCase().startsWith("UND_ERR_")) return true;
|
|
3832
|
+
return false;
|
|
3833
|
+
}
|
|
3834
|
+
function hasRetryableHttpStatus(value) {
|
|
3835
|
+
if (!isRecord2(value)) return false;
|
|
3836
|
+
const status = typeof value.statusCode === "number" ? value.statusCode : void 0;
|
|
3837
|
+
if (status === void 0) return false;
|
|
3838
|
+
if (status === 408 || status === 425 || status === 429) return true;
|
|
3839
|
+
if (status >= 500 && status <= 599) return true;
|
|
3840
|
+
return false;
|
|
3841
|
+
}
|
|
3842
|
+
function hasIsRetryableFlag(value) {
|
|
3843
|
+
if (!isRecord2(value)) return false;
|
|
3844
|
+
return value.isRetryable === true;
|
|
3845
|
+
}
|
|
3846
|
+
function isTransientLLMError(error) {
|
|
3847
|
+
if (isAbortError(error)) return false;
|
|
3848
|
+
const visited = /* @__PURE__ */ new WeakSet();
|
|
3849
|
+
function visit(candidate) {
|
|
3850
|
+
if (isRecord2(candidate)) {
|
|
3851
|
+
if (visited.has(candidate)) return false;
|
|
3852
|
+
visited.add(candidate);
|
|
3853
|
+
}
|
|
3854
|
+
if (hasTransientMessage(candidate)) return true;
|
|
3855
|
+
if (hasRetryableHttpStatus(candidate)) return true;
|
|
3856
|
+
if (hasIsRetryableFlag(candidate)) return true;
|
|
3857
|
+
if (isRecord2(candidate)) {
|
|
3858
|
+
if (visit(candidate.cause)) return true;
|
|
3859
|
+
if (visit(candidate.error)) return true;
|
|
3860
|
+
}
|
|
3861
|
+
return false;
|
|
3862
|
+
}
|
|
3863
|
+
return visit(error);
|
|
3864
|
+
}
|
|
3865
|
+
function computeDelay(attempt) {
|
|
3866
|
+
const base = RETRY_CONFIG.initialDelayMs * Math.pow(RETRY_CONFIG.backoffFactor, attempt);
|
|
3867
|
+
const capped = Math.min(base, RETRY_CONFIG.maxDelayMs);
|
|
3868
|
+
const jitterRange = capped * RETRY_CONFIG.jitter;
|
|
3869
|
+
const offset = (Math.random() * 2 - 1) * jitterRange;
|
|
3870
|
+
return Math.max(0, Math.round(capped + offset));
|
|
3871
|
+
}
|
|
3872
|
+
function sleep(ms, abortSignal) {
|
|
3873
|
+
if (ms <= 0) return Promise.resolve();
|
|
3874
|
+
return new Promise((resolve, reject) => {
|
|
3875
|
+
if (abortSignal?.aborted) {
|
|
3876
|
+
reject(new Error("The operation was aborted."));
|
|
3877
|
+
return;
|
|
3878
|
+
}
|
|
3879
|
+
const timer = setTimeout(() => {
|
|
3880
|
+
abortSignal?.removeEventListener("abort", onAbort);
|
|
3881
|
+
resolve();
|
|
3882
|
+
}, ms);
|
|
3883
|
+
const onAbort = () => {
|
|
3884
|
+
clearTimeout(timer);
|
|
3885
|
+
abortSignal?.removeEventListener("abort", onAbort);
|
|
3886
|
+
reject(new Error("The operation was aborted."));
|
|
3887
|
+
};
|
|
3888
|
+
abortSignal?.addEventListener("abort", onAbort, { once: true });
|
|
3889
|
+
});
|
|
3890
|
+
}
|
|
3891
|
+
async function withRetry(fn, opts) {
|
|
3892
|
+
const { label, abortSignal } = opts;
|
|
3893
|
+
let attempt = 0;
|
|
3894
|
+
while (true) {
|
|
3895
|
+
if (abortSignal?.aborted) {
|
|
3896
|
+
throw new Error("The operation was aborted.");
|
|
3897
|
+
}
|
|
3898
|
+
try {
|
|
3899
|
+
return await fn();
|
|
3900
|
+
} catch (error) {
|
|
3901
|
+
if (isAbortError(error) || abortSignal?.aborted) throw error;
|
|
3902
|
+
if (attempt >= RETRY_CONFIG.maxRetries || !isTransientLLMError(error)) {
|
|
3903
|
+
if (attempt > 0) {
|
|
3904
|
+
omDebug(
|
|
3905
|
+
`[OM:retry:${label}] giving up after ${attempt} retry/retries: ${error instanceof Error ? error.message : String(error)}`
|
|
3906
|
+
);
|
|
3907
|
+
}
|
|
3908
|
+
throw error;
|
|
3909
|
+
}
|
|
3910
|
+
const delay = computeDelay(attempt);
|
|
3911
|
+
attempt++;
|
|
3912
|
+
omDebug(
|
|
3913
|
+
`[OM:retry:${label}] transient error on attempt ${attempt}, retrying in ${delay}ms: ${error instanceof Error ? error.message : String(error)}`
|
|
3914
|
+
);
|
|
3915
|
+
await sleep(delay, abortSignal);
|
|
3916
|
+
}
|
|
3917
|
+
}
|
|
3918
|
+
}
|
|
3794
3919
|
var PHASE_CONFIG = {
|
|
3795
3920
|
observer: {
|
|
3796
3921
|
name: "om.observer",
|
|
@@ -3901,32 +4026,35 @@ var ObserverRunner = class {
|
|
|
3901
4026
|
buildObserverHistoryMessage(messagesToObserve)
|
|
3902
4027
|
];
|
|
3903
4028
|
const doGenerate = async () => {
|
|
3904
|
-
return
|
|
3905
|
-
|
|
3906
|
-
|
|
3907
|
-
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
|
-
|
|
3912
|
-
|
|
3913
|
-
|
|
3914
|
-
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
|
|
3929
|
-
|
|
4029
|
+
return withRetry(
|
|
4030
|
+
() => withOmTracingSpan({
|
|
4031
|
+
phase: "observer",
|
|
4032
|
+
model: resolvedModel.model,
|
|
4033
|
+
inputTokens,
|
|
4034
|
+
requestContext: options?.requestContext,
|
|
4035
|
+
observabilityContext: options?.observabilityContext,
|
|
4036
|
+
metadata: {
|
|
4037
|
+
omPreviousObserverTokens: this.observationConfig.previousObserverTokens,
|
|
4038
|
+
omThreadTitleEnabled: this.observationConfig.threadTitle,
|
|
4039
|
+
omSkipContinuationHints: options?.skipContinuationHints ?? false,
|
|
4040
|
+
omWasTruncated: options?.wasTruncated ?? false,
|
|
4041
|
+
...resolvedModel.selectedThreshold !== void 0 ? { omSelectedThreshold: resolvedModel.selectedThreshold } : {},
|
|
4042
|
+
...resolvedModel.routingStrategy ? { omRoutingStrategy: resolvedModel.routingStrategy } : {},
|
|
4043
|
+
...resolvedModel.routingThresholds ? { omRoutingThresholds: resolvedModel.routingThresholds } : {}
|
|
4044
|
+
},
|
|
4045
|
+
callback: (childObservabilityContext) => this.withAbortCheck(async () => {
|
|
4046
|
+
const streamResult = await agent.stream(observerMessages, {
|
|
4047
|
+
modelSettings: { ...this.observationConfig.modelSettings },
|
|
4048
|
+
providerOptions: this.observationConfig.providerOptions,
|
|
4049
|
+
...abortSignal ? { abortSignal } : {},
|
|
4050
|
+
...options?.requestContext ? { requestContext: options.requestContext } : {},
|
|
4051
|
+
...childObservabilityContext
|
|
4052
|
+
});
|
|
4053
|
+
return streamResult.getFullOutput();
|
|
4054
|
+
}, abortSignal)
|
|
4055
|
+
}),
|
|
4056
|
+
{ label: "observer", abortSignal }
|
|
4057
|
+
);
|
|
3930
4058
|
};
|
|
3931
4059
|
let result = await doGenerate();
|
|
3932
4060
|
let parsed = parseObserverOutput(result.text);
|
|
@@ -4000,31 +4128,34 @@ var ObserverRunner = class {
|
|
|
4000
4128
|
}
|
|
4001
4129
|
}
|
|
4002
4130
|
const doGenerate = async () => {
|
|
4003
|
-
return
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
|
|
4131
|
+
return withRetry(
|
|
4132
|
+
() => withOmTracingSpan({
|
|
4133
|
+
phase: "observer-multi-thread",
|
|
4134
|
+
model: resolvedModel.model,
|
|
4135
|
+
inputTokens,
|
|
4136
|
+
requestContext,
|
|
4137
|
+
observabilityContext,
|
|
4138
|
+
metadata: {
|
|
4139
|
+
omThreadCount: threadOrder.length,
|
|
4140
|
+
omPreviousObserverTokens: this.observationConfig.previousObserverTokens,
|
|
4141
|
+
omThreadTitleEnabled: this.observationConfig.threadTitle,
|
|
4142
|
+
...resolvedModel.selectedThreshold !== void 0 ? { omSelectedThreshold: resolvedModel.selectedThreshold } : {},
|
|
4143
|
+
...resolvedModel.routingStrategy ? { omRoutingStrategy: resolvedModel.routingStrategy } : {},
|
|
4144
|
+
...resolvedModel.routingThresholds ? { omRoutingThresholds: resolvedModel.routingThresholds } : {}
|
|
4145
|
+
},
|
|
4146
|
+
callback: (childObservabilityContext) => this.withAbortCheck(async () => {
|
|
4147
|
+
const streamResult = await agent.stream(observerMessages, {
|
|
4148
|
+
modelSettings: { ...this.observationConfig.modelSettings },
|
|
4149
|
+
providerOptions: this.observationConfig.providerOptions,
|
|
4150
|
+
...abortSignal ? { abortSignal } : {},
|
|
4151
|
+
...requestContext ? { requestContext } : {},
|
|
4152
|
+
...childObservabilityContext
|
|
4153
|
+
});
|
|
4154
|
+
return streamResult.getFullOutput();
|
|
4155
|
+
}, abortSignal)
|
|
4156
|
+
}),
|
|
4157
|
+
{ label: "observer-multi-thread", abortSignal }
|
|
4158
|
+
);
|
|
4028
4159
|
};
|
|
4029
4160
|
let result = await doGenerate();
|
|
4030
4161
|
let parsed = parseMultiThreadObserverOutput(result.text);
|
|
@@ -4468,54 +4599,60 @@ var ReflectorRunner = class {
|
|
|
4468
4599
|
`[OM:callReflector] ${isRetry ? `retry #${attemptNumber - 1}` : "first attempt"}: level=${currentLevel}, originalTokens=${originalTokens}, targetThreshold=${targetThreshold}, promptLen=${prompt.length}, skipContinuationHints=${skipContinuationHints}`
|
|
4469
4600
|
);
|
|
4470
4601
|
let chunkCount = 0;
|
|
4471
|
-
const result = await
|
|
4472
|
-
|
|
4473
|
-
|
|
4474
|
-
|
|
4475
|
-
|
|
4476
|
-
|
|
4477
|
-
|
|
4478
|
-
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
|
|
4482
|
-
|
|
4483
|
-
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
|
|
4488
|
-
|
|
4489
|
-
|
|
4490
|
-
|
|
4491
|
-
|
|
4492
|
-
...abortSignal ? { abortSignal } : {},
|
|
4493
|
-
...requestContext ? { requestContext } : {},
|
|
4494
|
-
...childObservabilityContext,
|
|
4495
|
-
...attemptNumber === 1 ? {
|
|
4496
|
-
onChunk(chunk) {
|
|
4497
|
-
chunkCount++;
|
|
4498
|
-
if (chunkCount === 1 || chunkCount % 50 === 0) {
|
|
4499
|
-
const preview = chunk.type === "text-delta" ? ` text="${chunk.textDelta?.slice(0, 80)}..."` : chunk.type === "tool-call" ? ` tool=${chunk.toolName}` : "";
|
|
4500
|
-
omDebug(`[OM:callReflector] chunk#${chunkCount}: type=${chunk.type}${preview}`);
|
|
4501
|
-
}
|
|
4502
|
-
},
|
|
4503
|
-
onFinish(event) {
|
|
4504
|
-
omDebug(
|
|
4505
|
-
`[OM:callReflector] onFinish: chunks=${chunkCount}, finishReason=${event.finishReason}, inputTokens=${event.usage?.inputTokens}, outputTokens=${event.usage?.outputTokens}, textLen=${event.text?.length}`
|
|
4506
|
-
);
|
|
4507
|
-
},
|
|
4508
|
-
onAbort(event) {
|
|
4509
|
-
omDebug(`[OM:callReflector] onAbort: chunks=${chunkCount}, reason=${event?.reason ?? "unknown"}`);
|
|
4602
|
+
const result = await withRetry(
|
|
4603
|
+
() => withOmTracingSpan({
|
|
4604
|
+
phase: "reflector",
|
|
4605
|
+
model: resolvedModel.model,
|
|
4606
|
+
inputTokens: originalTokens,
|
|
4607
|
+
requestContext,
|
|
4608
|
+
observabilityContext,
|
|
4609
|
+
metadata: {
|
|
4610
|
+
omCompressionLevel: currentLevel,
|
|
4611
|
+
omCompressionAttempt: attemptNumber,
|
|
4612
|
+
omTargetThreshold: targetThreshold,
|
|
4613
|
+
omSkipContinuationHints: skipContinuationHints ?? false,
|
|
4614
|
+
...resolvedModel.selectedThreshold !== void 0 ? { omSelectedThreshold: resolvedModel.selectedThreshold } : {},
|
|
4615
|
+
...resolvedModel.routingStrategy ? { omRoutingStrategy: resolvedModel.routingStrategy } : {},
|
|
4616
|
+
...resolvedModel.routingThresholds ? { omRoutingThresholds: resolvedModel.routingThresholds } : {}
|
|
4617
|
+
},
|
|
4618
|
+
callback: (childObservabilityContext) => withAbortCheck(async () => {
|
|
4619
|
+
chunkCount = 0;
|
|
4620
|
+
const streamResult = await agent.stream(prompt, {
|
|
4621
|
+
modelSettings: {
|
|
4622
|
+
...this.reflectionConfig.modelSettings
|
|
4510
4623
|
},
|
|
4511
|
-
|
|
4512
|
-
|
|
4513
|
-
}
|
|
4514
|
-
|
|
4515
|
-
|
|
4516
|
-
|
|
4517
|
-
|
|
4518
|
-
|
|
4624
|
+
providerOptions: this.reflectionConfig.providerOptions,
|
|
4625
|
+
...abortSignal ? { abortSignal } : {},
|
|
4626
|
+
...requestContext ? { requestContext } : {},
|
|
4627
|
+
...childObservabilityContext,
|
|
4628
|
+
...attemptNumber === 1 ? {
|
|
4629
|
+
onChunk(chunk) {
|
|
4630
|
+
chunkCount++;
|
|
4631
|
+
if (chunkCount === 1 || chunkCount % 50 === 0) {
|
|
4632
|
+
const preview = chunk.type === "text-delta" ? ` text="${chunk.textDelta?.slice(0, 80)}..."` : chunk.type === "tool-call" ? ` tool=${chunk.toolName}` : "";
|
|
4633
|
+
omDebug(`[OM:callReflector] chunk#${chunkCount}: type=${chunk.type}${preview}`);
|
|
4634
|
+
}
|
|
4635
|
+
},
|
|
4636
|
+
onFinish(event) {
|
|
4637
|
+
omDebug(
|
|
4638
|
+
`[OM:callReflector] onFinish: chunks=${chunkCount}, finishReason=${event.finishReason}, inputTokens=${event.usage?.inputTokens}, outputTokens=${event.usage?.outputTokens}, textLen=${event.text?.length}`
|
|
4639
|
+
);
|
|
4640
|
+
},
|
|
4641
|
+
onAbort(event) {
|
|
4642
|
+
omDebug(
|
|
4643
|
+
`[OM:callReflector] onAbort: chunks=${chunkCount}, reason=${event?.reason ?? "unknown"}`
|
|
4644
|
+
);
|
|
4645
|
+
},
|
|
4646
|
+
onError({ error }) {
|
|
4647
|
+
omError(`[OM:callReflector] onError after ${chunkCount} chunks`, error);
|
|
4648
|
+
}
|
|
4649
|
+
} : {}
|
|
4650
|
+
});
|
|
4651
|
+
return streamResult.getFullOutput();
|
|
4652
|
+
}, abortSignal)
|
|
4653
|
+
}),
|
|
4654
|
+
{ label: "reflector", abortSignal }
|
|
4655
|
+
);
|
|
4519
4656
|
omDebug(
|
|
4520
4657
|
`[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}`
|
|
4521
4658
|
);
|
|
@@ -6659,7 +6796,7 @@ function getCurrentModel2(model) {
|
|
|
6659
6796
|
return formatModelContext2(model?.provider, model?.modelId);
|
|
6660
6797
|
}
|
|
6661
6798
|
function parseActivationTTL(value, fieldPath) {
|
|
6662
|
-
if (value === void 0) {
|
|
6799
|
+
if (value === void 0 || value === false) {
|
|
6663
6800
|
return void 0;
|
|
6664
6801
|
}
|
|
6665
6802
|
if (typeof value === "number") {
|
|
@@ -6807,6 +6944,8 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
|
|
|
6807
6944
|
);
|
|
6808
6945
|
}
|
|
6809
6946
|
}
|
|
6947
|
+
const observationActivateAfterIdle = config.observation?.activateAfterIdle ?? config.activateAfterIdle;
|
|
6948
|
+
const observationActivateAfterIdlePath = config.observation?.activateAfterIdle !== void 0 ? "observation.activateAfterIdle" : "activateAfterIdle";
|
|
6810
6949
|
this.observationConfig = {
|
|
6811
6950
|
model: observationModel,
|
|
6812
6951
|
// When shared budget, store as range: min = base threshold, max = total budget
|
|
@@ -6824,8 +6963,8 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
|
|
|
6824
6963
|
config.observation?.messageTokens ?? OBSERVATIONAL_MEMORY_DEFAULTS.observation.messageTokens
|
|
6825
6964
|
),
|
|
6826
6965
|
bufferActivation: asyncBufferingDisabled ? void 0 : config.observation?.bufferActivation ?? OBSERVATIONAL_MEMORY_DEFAULTS.observation.bufferActivation,
|
|
6827
|
-
activateAfterIdle: parseActivationTTL(
|
|
6828
|
-
activateOnProviderChange: config.activateOnProviderChange ?? false,
|
|
6966
|
+
activateAfterIdle: parseActivationTTL(observationActivateAfterIdle, observationActivateAfterIdlePath),
|
|
6967
|
+
activateOnProviderChange: config.observation?.activateOnProviderChange ?? config.activateOnProviderChange ?? false,
|
|
6829
6968
|
blockAfter: asyncBufferingDisabled ? void 0 : resolveBlockAfter(
|
|
6830
6969
|
config.observation?.blockAfter ?? (config.observation?.bufferTokens ?? OBSERVATIONAL_MEMORY_DEFAULTS.observation.bufferTokens ? 1.2 : void 0),
|
|
6831
6970
|
config.observation?.messageTokens ?? OBSERVATIONAL_MEMORY_DEFAULTS.observation.messageTokens
|
|
@@ -6844,8 +6983,8 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
|
|
|
6844
6983
|
},
|
|
6845
6984
|
providerOptions: config.reflection?.providerOptions ?? OBSERVATIONAL_MEMORY_DEFAULTS.reflection.providerOptions,
|
|
6846
6985
|
bufferActivation: asyncBufferingDisabled ? void 0 : config?.reflection?.bufferActivation ?? OBSERVATIONAL_MEMORY_DEFAULTS.reflection.bufferActivation,
|
|
6847
|
-
activateAfterIdle: parseActivationTTL(config.activateAfterIdle, "activateAfterIdle"),
|
|
6848
|
-
activateOnProviderChange: config.activateOnProviderChange ?? false,
|
|
6986
|
+
activateAfterIdle: parseActivationTTL(config.reflection?.activateAfterIdle, "reflection.activateAfterIdle"),
|
|
6987
|
+
activateOnProviderChange: config.reflection?.activateOnProviderChange ?? false,
|
|
6849
6988
|
blockAfter: asyncBufferingDisabled ? void 0 : resolveBlockAfter(
|
|
6850
6989
|
config.reflection?.blockAfter ?? (config.reflection?.bufferActivation ?? OBSERVATIONAL_MEMORY_DEFAULTS.reflection.bufferActivation ? 1.2 : void 0),
|
|
6851
6990
|
config.reflection?.observationTokens ?? OBSERVATIONAL_MEMORY_DEFAULTS.reflection.observationTokens
|
|
@@ -9494,5 +9633,5 @@ function getObservationsAsOf(activeObservations, asOf) {
|
|
|
9494
9633
|
}
|
|
9495
9634
|
|
|
9496
9635
|
export { ModelByInputTokens, OBSERVER_SYSTEM_PROMPT, ObservationalMemory, ObservationalMemoryProcessor, TokenCounter, buildObserverPrompt, buildObserverSystemPrompt, combineObservationGroupRanges, deriveObservationGroupProvenance, extractCurrentTask, formatMessagesForObserver, formatToolResultForObserver, getObservationsAsOf, hasCurrentTaskSection, injectAnchorIds, optimizeObservationsForContext, parseAnchorId, parseObservationGroups, parseObserverOutput, reconcileObservationGroupsFromReflection, renderObservationGroupsForReflection, resolveToolResultValue, stripEphemeralAnchorIds, stripObservationGroups, truncateStringByTokens, wrapInObservationGroup };
|
|
9497
|
-
//# sourceMappingURL=chunk-
|
|
9498
|
-
//# sourceMappingURL=chunk-
|
|
9636
|
+
//# sourceMappingURL=chunk-LPMZNXSF.js.map
|
|
9637
|
+
//# sourceMappingURL=chunk-LPMZNXSF.js.map
|