@mastra/memory 1.18.0-alpha.3 → 1.18.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/CHANGELOG.md +33 -0
- package/dist/{chunk-XVVCS6R6.js → chunk-LPMZNXSF.js} +241 -104
- package/dist/chunk-LPMZNXSF.js.map +1 -0
- package/dist/{chunk-ET2TVAT3.cjs → chunk-NRYX4QWV.cjs} +241 -104
- 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/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 +97 -145
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +88 -136
- package/dist/index.js.map +1 -1
- package/dist/{observational-memory-2PRVG6BF.js → observational-memory-NL7AQHZV.js} +3 -3
- package/dist/{observational-memory-2PRVG6BF.js.map → observational-memory-NL7AQHZV.js.map} +1 -1
- package/dist/{observational-memory-UJUAQKJB.cjs → observational-memory-TZ67ZA32.cjs} +26 -26
- package/dist/{observational-memory-UJUAQKJB.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/observer-runner.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/package.json +8 -8
- package/dist/chunk-ET2TVAT3.cjs.map +0 -1
- package/dist/chunk-XVVCS6R6.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
# @mastra/memory
|
|
2
2
|
|
|
3
|
+
## 1.18.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Add metadata filtering support to semantic recall. ([#9256](https://github.com/mastra-ai/mastra/pull/9256))
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Fixed an issue where tool results containing AI SDK v5 `image-data` content blocks (returned via `toModelOutput`) were stringified into the observational memory prompt as raw base64 text. The base64 data overflowed the observer's context, causing token-limit errors and degenerate output. ([#16117](https://github.com/mastra-ai/mastra/pull/16117))
|
|
12
|
+
|
|
13
|
+
Image and file blocks (`image-data`, `image-url`, `file-data`, `file-url`, and `media`) inside tool results are now hoisted into the observer's input as proper attachments, the same way image and file message parts already are. The text body shows a placeholder like `[Image #1: image/png]` so the observer keeps positional context without seeing the bytes.
|
|
14
|
+
|
|
15
|
+
- 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))
|
|
16
|
+
|
|
17
|
+
- 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))
|
|
18
|
+
|
|
19
|
+
- Added extra defensive checks to prevent edge cases where system messages may have already been stored in message history. ([#15787](https://github.com/mastra-ai/mastra/pull/15787))
|
|
20
|
+
|
|
21
|
+
- Fixed read-only observational memory so existing context is still loaded. ([#16059](https://github.com/mastra-ai/mastra/pull/16059))
|
|
22
|
+
|
|
23
|
+
- Updated dependencies [[`9f17410`](https://github.com/mastra-ai/mastra/commit/9f1741080def23d42ee50b39887a385ae316a3c6), [`7ad5585`](https://github.com/mastra-ai/mastra/commit/7ad55856406f1de398dc713f6a9eaa78b2784bb6), [`ac47842`](https://github.com/mastra-ai/mastra/commit/ac478427aa7a5f5fdaed633a911218689b438c60), [`cc189cc`](https://github.com/mastra-ai/mastra/commit/cc189cc0128eb7af233476b5e421ec6888bffde7), [`d1fdbd0`](https://github.com/mastra-ai/mastra/commit/d1fdbd012add5623cb7e6b7f882b605ab358bbb4), [`210ea7a`](https://github.com/mastra-ai/mastra/commit/210ea7af559791b73a44fc9c12179908aaa3183f), [`7c275a8`](https://github.com/mastra-ai/mastra/commit/7c275a810595e1a6c41ccc39720531ab65734700), [`bae019e`](https://github.com/mastra-ai/mastra/commit/bae019ecb6694da96909f7ec7b9eb3a0a33aa887), [`890b24c`](https://github.com/mastra-ai/mastra/commit/890b24cc7d32ed6aa4dfe253e54dc6bf4099f690), [`f984b4d`](https://github.com/mastra-ai/mastra/commit/f984b4d6c60bf2ae2a9b156f0e8c35a66fe96c91), [`6742347`](https://github.com/mastra-ai/mastra/commit/6742347d71955d7639adc9ddf6ff8282de7ee3ba), [`b59316f`](https://github.com/mastra-ai/mastra/commit/b59316ffa0f7688165b0f9c81ccdf85da461e5b2), [`0f48ebf`](https://github.com/mastra-ai/mastra/commit/0f48ebfc7ac7897b2092a189f45751924cf56d1c), [`37c0dc5`](https://github.com/mastra-ai/mastra/commit/37c0dc5697d343db98628bf867bf71ce6deec6d7), [`087e413`](https://github.com/mastra-ai/mastra/commit/087e4133e5d6efa36619e9556c16750e4179c047), [`83218c8`](https://github.com/mastra-ai/mastra/commit/83218c88b37773c9424fbe733b37be556e55e94d), [`ef6b584`](https://github.com/mastra-ai/mastra/commit/ef6b5847ac33c0a7e80af3a86e8801e2933dd3ee), [`c6eb39e`](https://github.com/mastra-ai/mastra/commit/c6eb39ea6dca381c6563cb240237fbe608e02f93), [`7b0ad1f`](https://github.com/mastra-ai/mastra/commit/7b0ad1f5c53dc118c6da12ae82ae2587037dc2b8), [`d91ebe2`](https://github.com/mastra-ai/mastra/commit/d91ebe28ee065d8f2ed6df741c3c07f58d359529), [`62666c3`](https://github.com/mastra-ai/mastra/commit/62666c367eaeac3941ead454b1d38810cc855721), [`33f5061`](https://github.com/mastra-ai/mastra/commit/33f5061cd1c0335020c3faae61ce96de822854fa), [`4af2160`](https://github.com/mastra-ai/mastra/commit/4af2160322f4718cac421930cce85641e9512389), [`087e413`](https://github.com/mastra-ai/mastra/commit/087e4133e5d6efa36619e9556c16750e4179c047), [`265ec9f`](https://github.com/mastra-ai/mastra/commit/265ec9f887b5c81255c873a76ff7796f16e4f99b), [`ce01024`](https://github.com/mastra-ai/mastra/commit/ce010242eee9bdfc09e4c26725b9d37998679a8d), [`6ce80bf`](https://github.com/mastra-ai/mastra/commit/6ce80bf4872a891e0bddf8b80561a80584efb14b), [`f984b4d`](https://github.com/mastra-ai/mastra/commit/f984b4d6c60bf2ae2a9b156f0e8c35a66fe96c91), [`136c959`](https://github.com/mastra-ai/mastra/commit/136c9592fb0eeb0cd212f28629d8a29b7557a2fc), [`9268531`](https://github.com/mastra-ai/mastra/commit/9268531e7ec4be98beeba3b3ae8be0a7ea380662), [`13ead79`](https://github.com/mastra-ai/mastra/commit/13ead79149486b88144db7e11e6ff551caef5be1), [`dccd8f1`](https://github.com/mastra-ai/mastra/commit/dccd8f1f8b8f1ad203b77556207e5529567c616d), [`4df7cc7`](https://github.com/mastra-ai/mastra/commit/4df7cc79342fd065fe7fdeef93c094db14b12bcd), [`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), [`aca3121`](https://github.com/mastra-ai/mastra/commit/aca31211233dac25459f140ea4fcfb3a5af64c18), [`e06a159`](https://github.com/mastra-ai/mastra/commit/e06a1598ca07a6c3778aefc2a2d288363c6294ff), [`4dd900d`](https://github.com/mastra-ai/mastra/commit/4dd900d75dfe9be89f8c15188b368a8622aa1e18), [`b560d6f`](https://github.com/mastra-ai/mastra/commit/b560d6f88b9b904b15c10f75c949eb145bc27684), [`99869ec`](https://github.com/mastra-ai/mastra/commit/99869ecb1f2aa6dfcc44fa4e843e5ee0344efa64), [`900d086`](https://github.com/mastra-ai/mastra/commit/900d086bb737b9cf2fcf68f11b0389b801a2738c), [`c50ebc3`](https://github.com/mastra-ai/mastra/commit/c50ebc34da71044558315735e69bfb94fcfb74bf), [`4c0e286`](https://github.com/mastra-ai/mastra/commit/4c0e28637c9cfb4f416549b55e97ebfa13319dfc), [`55f1e2d`](https://github.com/mastra-ai/mastra/commit/55f1e2d65425b95a49ae788053b266f256e38c96), [`4ff5bdf`](https://github.com/mastra-ai/mastra/commit/4ff5bdfe170cba6dfb5260c6af0f4ba668430772), [`9cdf38e`](https://github.com/mastra-ai/mastra/commit/9cdf38e58506e1109c8b38f97cd7770978a4218e), [`087e413`](https://github.com/mastra-ai/mastra/commit/087e4133e5d6efa36619e9556c16750e4179c047), [`db34bc6`](https://github.com/mastra-ai/mastra/commit/db34bc6fb36cf125bda0c46be4d3fdc774b70cc4), [`990851e`](https://github.com/mastra-ai/mastra/commit/990851edcb0e30be5c2c18b6532f1a876cc2d335), [`bbcd93c`](https://github.com/mastra-ai/mastra/commit/bbcd93cf7d8aa1007d6d84bfd033b8015c912087), [`8373ff4`](https://github.com/mastra-ai/mastra/commit/8373ff46745d77af79f183c4470f80fa2727a6b2), [`d48a705`](https://github.com/mastra-ai/mastra/commit/d48a705ff3dfbdc7a996e07ecd8293b5effd9a2a), [`308bd07`](https://github.com/mastra-ai/mastra/commit/308bd074f35cef0c75d82fc1eb19382fe04ecf6f), [`6068a6c`](https://github.com/mastra-ai/mastra/commit/6068a6c42950fad3ebfc92346417896ba60803d2), [`36b3bbf`](https://github.com/mastra-ai/mastra/commit/36b3bbf5a8d59f7e23d47e29340e76c681b4929c), [`d86f031`](https://github.com/mastra-ai/mastra/commit/d86f031eb6b0b2570145afafea664e59bf688962), [`b275631`](https://github.com/mastra-ai/mastra/commit/b275631dc10541a482b2e2d4a3e3cfa843bd5fa1), [`00106be`](https://github.com/mastra-ai/mastra/commit/00106bede59b81e5b0e9cd6aad8d3b5dbc336387), [`bd36d8e`](https://github.com/mastra-ai/mastra/commit/bd36d8eb6de8c9a0310352649dbd4b06703c2299), [`11c1528`](https://github.com/mastra-ai/mastra/commit/11c152848c5d0ef227184853b5040f5b41ee7b1e), [`4999667`](https://github.com/mastra-ai/mastra/commit/49996678b68356cad7f088430009690406c50fbd), [`e2a079c`](https://github.com/mastra-ai/mastra/commit/e2a079cc3755b1895f7bd5dc36e9be81b11c7c22), [`8ac9141`](https://github.com/mastra-ai/mastra/commit/8ac9141439caa8fdd674944c4d84f29b3c730296), [`25184ff`](https://github.com/mastra-ai/mastra/commit/25184ffaf1293ec95119426eb1a1f8d38831b96c), [`534a456`](https://github.com/mastra-ai/mastra/commit/534a456a25e4df1e5407e7e632f4cb3b1fa14f9d), [`105e454`](https://github.com/mastra-ai/mastra/commit/105e454c95af06a7c741c15969d8f9b0f02463a7), [`aebde9c`](https://github.com/mastra-ai/mastra/commit/aebde9cfacf56592c6b6350cae721740fe090b8a), [`36bae07`](https://github.com/mastra-ai/mastra/commit/36bae07c0e70b1b3006f2fd20830e8883dcbd066), [`5688881`](https://github.com/mastra-ai/mastra/commit/5688881669c7ed157f31ac77f6fc5f8d95ceea32)]:
|
|
24
|
+
- @mastra/core@1.33.0
|
|
25
|
+
- @mastra/schema-compat@1.2.10
|
|
26
|
+
|
|
27
|
+
## 1.18.0-alpha.4
|
|
28
|
+
|
|
29
|
+
### Patch Changes
|
|
30
|
+
|
|
31
|
+
- 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))
|
|
32
|
+
|
|
33
|
+
- 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)]:
|
|
34
|
+
- @mastra/core@1.33.0-alpha.12
|
|
35
|
+
|
|
3
36
|
## 1.18.0-alpha.3
|
|
4
37
|
|
|
5
38
|
### Patch 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
|
);
|
|
@@ -9496,5 +9633,5 @@ function getObservationsAsOf(activeObservations, asOf) {
|
|
|
9496
9633
|
}
|
|
9497
9634
|
|
|
9498
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 };
|
|
9499
|
-
//# sourceMappingURL=chunk-
|
|
9500
|
-
//# sourceMappingURL=chunk-
|
|
9636
|
+
//# sourceMappingURL=chunk-LPMZNXSF.js.map
|
|
9637
|
+
//# sourceMappingURL=chunk-LPMZNXSF.js.map
|