@mastra/memory 1.25.1-alpha.0 → 1.26.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +48 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-capabilities-subagents.md +23 -5
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/processors/index.cjs +1 -1
- package/dist/processors/index.js +1 -1
- package/dist/processors/observational-memory/extraction-runner.d.ts.map +1 -1
- package/dist/processors/observational-memory/extractor.d.ts +3 -0
- package/dist/processors/observational-memory/extractor.d.ts.map +1 -1
- package/dist/processors/observational-memory/message-utils.d.ts.map +1 -1
- package/dist/processors/observational-memory/observation-strategies/base.d.ts +5 -1
- package/dist/processors/observational-memory/observation-strategies/base.d.ts.map +1 -1
- package/dist/processors/observational-memory/observation-strategies/types.d.ts +7 -1
- package/dist/processors/observational-memory/observation-strategies/types.d.ts.map +1 -1
- package/dist/processors/observational-memory/observation-turn/step.d.ts +6 -0
- package/dist/processors/observational-memory/observation-turn/step.d.ts.map +1 -1
- package/dist/processors/observational-memory/observation-turn/turn.d.ts +2 -0
- package/dist/processors/observational-memory/observation-turn/turn.d.ts.map +1 -1
- package/dist/processors/observational-memory/observational-memory.d.ts +14 -0
- 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/token-counter.d.ts.map +1 -1
- package/dist/processors/observational-memory/working-memory-extractor.d.ts.map +1 -1
- package/dist/{src-DvQWV6nH.js → src-Iw-V5CfD.js} +285 -67
- package/dist/src-Iw-V5CfD.js.map +1 -0
- package/dist/{src-Bz9Fg416.cjs → src-x5iu_K3X.cjs} +287 -69
- package/dist/src-x5iu_K3X.cjs.map +1 -0
- package/package.json +9 -9
- package/dist/src-Bz9Fg416.cjs.map +0 -1
- package/dist/src-DvQWV6nH.js.map +0 -1
|
@@ -27,14 +27,14 @@ import { MessageHistory, MessageHistory as MessageHistory$1, SemanticRecall, Wor
|
|
|
27
27
|
import { inspect } from "util";
|
|
28
28
|
import { structuredPatch } from "diff";
|
|
29
29
|
//#region \0rolldown/runtime.js
|
|
30
|
-
var __defProp$
|
|
30
|
+
var __defProp$3 = Object.defineProperty;
|
|
31
31
|
var __exportAll = (all, no_symbols) => {
|
|
32
32
|
let target = {};
|
|
33
|
-
for (var name in all) __defProp$
|
|
33
|
+
for (var name in all) __defProp$3(target, name, {
|
|
34
34
|
get: all[name],
|
|
35
35
|
enumerable: true
|
|
36
36
|
});
|
|
37
|
-
if (!no_symbols) __defProp$
|
|
37
|
+
if (!no_symbols) __defProp$3(target, Symbol.toStringTag, { value: "Module" });
|
|
38
38
|
return target;
|
|
39
39
|
};
|
|
40
40
|
//#endregion
|
|
@@ -180,9 +180,9 @@ Error message: ${getErrorMessage$4(cause)}`,
|
|
|
180
180
|
_a13$5 = symbol13$5;
|
|
181
181
|
var TypeValidationError$2 = _TypeValidationError;
|
|
182
182
|
//#endregion
|
|
183
|
-
//#region ../_vendored/ai_v4/dist/
|
|
183
|
+
//#region ../_vendored/ai_v4/dist/index.js
|
|
184
184
|
var __create = Object.create;
|
|
185
|
-
var __defProp$
|
|
185
|
+
var __defProp$1$1 = Object.defineProperty;
|
|
186
186
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
187
187
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
188
188
|
var __getProtoOf = Object.getPrototypeOf;
|
|
@@ -191,14 +191,14 @@ var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).expor
|
|
|
191
191
|
var __copyProps = (to, from, except, desc) => {
|
|
192
192
|
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
193
193
|
key = keys[i];
|
|
194
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp$
|
|
194
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp$1$1(to, key, {
|
|
195
195
|
get: ((k) => from[k]).bind(null, key),
|
|
196
196
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
197
197
|
});
|
|
198
198
|
}
|
|
199
199
|
return to;
|
|
200
200
|
};
|
|
201
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp$
|
|
201
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp$1$1(target, "default", {
|
|
202
202
|
value: mod,
|
|
203
203
|
enumerable: true
|
|
204
204
|
}) : target, mod));
|
|
@@ -412,8 +412,6 @@ function safeParseJSON$2({ text, schema }) {
|
|
|
412
412
|
}
|
|
413
413
|
}
|
|
414
414
|
var { btoa: btoa$2, atob: atob$2 } = globalThis;
|
|
415
|
-
//#endregion
|
|
416
|
-
//#region ../_vendored/ai_v4/dist/index.js
|
|
417
415
|
const ignoreOverride$2 = Symbol("Let zodToJsonSchema decide on which parser to use");
|
|
418
416
|
const defaultOptions$2 = {
|
|
419
417
|
name: void 0,
|
|
@@ -3715,7 +3713,7 @@ function trimStartOfStream() {
|
|
|
3715
3713
|
};
|
|
3716
3714
|
}
|
|
3717
3715
|
//#endregion
|
|
3718
|
-
//#region ../_vendored/ai_v5/dist/dist-
|
|
3716
|
+
//#region ../_vendored/ai_v5/dist/dist-BuEMdYEn.js
|
|
3719
3717
|
var marker$1$4 = "vercel.ai.error";
|
|
3720
3718
|
var symbol$1$3 = Symbol.for(marker$1$4);
|
|
3721
3719
|
var _a$1$3;
|
|
@@ -4265,6 +4263,26 @@ async function cancelResponseBody$1(response) {
|
|
|
4265
4263
|
await ((_a2 = response.body) == null ? void 0 : _a2.cancel());
|
|
4266
4264
|
} catch (e) {}
|
|
4267
4265
|
}
|
|
4266
|
+
var initialGlobalFetch$1 = globalThis.fetch;
|
|
4267
|
+
isNodeDefaultFetch$1(initialGlobalFetch$1);
|
|
4268
|
+
function isNodeDefaultFetch$1(fetch) {
|
|
4269
|
+
const source = Function.prototype.toString.call(fetch);
|
|
4270
|
+
return source.includes("internal/deps/undici") || source.includes("lazy loading of undici");
|
|
4271
|
+
}
|
|
4272
|
+
function getCurrentModulePath$1() {
|
|
4273
|
+
const originalPrepareStackTrace = Error.prepareStackTrace;
|
|
4274
|
+
try {
|
|
4275
|
+
Error.prepareStackTrace = (_error, callSites) => callSites;
|
|
4276
|
+
const error = /* @__PURE__ */ new Error("Capture current module path");
|
|
4277
|
+
Error.captureStackTrace(error, getCurrentModulePath$1);
|
|
4278
|
+
const [caller] = error.stack;
|
|
4279
|
+
const fileName = caller == null ? void 0 : caller.getFileName();
|
|
4280
|
+
if (fileName == null) throw new Error("Unable to determine the current module path");
|
|
4281
|
+
return fileName;
|
|
4282
|
+
} finally {
|
|
4283
|
+
Error.prepareStackTrace = originalPrepareStackTrace;
|
|
4284
|
+
}
|
|
4285
|
+
}
|
|
4268
4286
|
var DEFAULT_MAX_DOWNLOAD_SIZE$1 = 2 * 1024 * 1024 * 1024;
|
|
4269
4287
|
async function readResponseWithSizeLimit$1({ response, url, maxBytes = DEFAULT_MAX_DOWNLOAD_SIZE$1 }) {
|
|
4270
4288
|
const contentLength = response.headers.get("content-length");
|
|
@@ -4374,11 +4392,11 @@ function withUserAgentSuffix$1(headers, ...userAgentSuffixParts) {
|
|
|
4374
4392
|
normalizedHeaders.set("user-agent", [currentUserAgentHeader, ...userAgentSuffixParts].filter(Boolean).join(" "));
|
|
4375
4393
|
return Object.fromEntries(normalizedHeaders.entries());
|
|
4376
4394
|
}
|
|
4377
|
-
var VERSION$4 = "3.0.
|
|
4395
|
+
var VERSION$4 = "3.0.31";
|
|
4378
4396
|
var getOriginalFetch$1 = () => globalThis.fetch;
|
|
4379
|
-
var getFromApi$1 = async ({ url, headers = {}, successfulResponseHandler, failedResponseHandler, abortSignal, fetch
|
|
4397
|
+
var getFromApi$1 = async ({ url, headers = {}, successfulResponseHandler, failedResponseHandler, abortSignal, fetch = getOriginalFetch$1() }) => {
|
|
4380
4398
|
try {
|
|
4381
|
-
const response = await
|
|
4399
|
+
const response = await fetch(url, {
|
|
4382
4400
|
method: "GET",
|
|
4383
4401
|
headers: withUserAgentSuffix$1(headers, `ai-sdk/provider-utils/${VERSION$4}`, getRuntimeEnvironmentUserAgent$1()),
|
|
4384
4402
|
signal: abortSignal
|
|
@@ -4604,7 +4622,7 @@ function parseJsonEventStream$1({ stream, schema }) {
|
|
|
4604
4622
|
} }));
|
|
4605
4623
|
}
|
|
4606
4624
|
var getOriginalFetch2$1 = () => globalThis.fetch;
|
|
4607
|
-
var postJsonToApi$1 = async ({ url, headers, body, failedResponseHandler, successfulResponseHandler, abortSignal, fetch
|
|
4625
|
+
var postJsonToApi$1 = async ({ url, headers, body, failedResponseHandler, successfulResponseHandler, abortSignal, fetch }) => postToApi$1({
|
|
4608
4626
|
url,
|
|
4609
4627
|
headers: {
|
|
4610
4628
|
"Content-Type": "application/json",
|
|
@@ -4617,11 +4635,11 @@ var postJsonToApi$1 = async ({ url, headers, body, failedResponseHandler, succes
|
|
|
4617
4635
|
failedResponseHandler,
|
|
4618
4636
|
successfulResponseHandler,
|
|
4619
4637
|
abortSignal,
|
|
4620
|
-
fetch
|
|
4638
|
+
fetch
|
|
4621
4639
|
});
|
|
4622
|
-
var postToApi$1 = async ({ url, headers = {}, body, successfulResponseHandler, failedResponseHandler, abortSignal, fetch
|
|
4640
|
+
var postToApi$1 = async ({ url, headers = {}, body, successfulResponseHandler, failedResponseHandler, abortSignal, fetch = getOriginalFetch2$1() }) => {
|
|
4623
4641
|
try {
|
|
4624
|
-
const response = await
|
|
4642
|
+
const response = await fetch(url, {
|
|
4625
4643
|
method: "POST",
|
|
4626
4644
|
headers: withUserAgentSuffix$1(headers, `ai-sdk/provider-utils/${VERSION$4}`, getRuntimeEnvironmentUserAgent$1()),
|
|
4627
4645
|
body: body.content,
|
|
@@ -6683,7 +6701,7 @@ async function getVercelRequestId$1() {
|
|
|
6683
6701
|
var _a10;
|
|
6684
6702
|
return (_a10 = getContext$1().headers) == null ? void 0 : _a10["x-vercel-id"];
|
|
6685
6703
|
}
|
|
6686
|
-
var VERSION$2$2 = "2.0.
|
|
6704
|
+
var VERSION$2$2 = "2.0.125";
|
|
6687
6705
|
var AI_GATEWAY_PROTOCOL_VERSION$1 = "0.0.1";
|
|
6688
6706
|
function createGatewayProvider$1(options = {}) {
|
|
6689
6707
|
var _a10, _b10;
|
|
@@ -7717,7 +7735,7 @@ function getGlobalProvider$1() {
|
|
|
7717
7735
|
var _a16;
|
|
7718
7736
|
return (_a16 = globalThis.AI_SDK_DEFAULT_PROVIDER) != null ? _a16 : gateway$1;
|
|
7719
7737
|
}
|
|
7720
|
-
var VERSION$5 = "5.0.
|
|
7738
|
+
var VERSION$5 = "5.0.226";
|
|
7721
7739
|
var dataContentSchema$1 = z$1.union([
|
|
7722
7740
|
z$1.string(),
|
|
7723
7741
|
z$1.instanceof(Uint8Array),
|
|
@@ -8583,7 +8601,7 @@ var object$1 = ({ schema: inputSchema }) => {
|
|
|
8583
8601
|
};
|
|
8584
8602
|
};
|
|
8585
8603
|
//#endregion
|
|
8586
|
-
//#region ../_vendored/ai_v6/dist/dist-
|
|
8604
|
+
//#region ../_vendored/ai_v6/dist/dist-BTWHzT8H.js
|
|
8587
8605
|
var marker$1 = "vercel.ai.error";
|
|
8588
8606
|
var symbol$1$1 = Symbol.for(marker$1);
|
|
8589
8607
|
var _a$1$1;
|
|
@@ -9154,6 +9172,26 @@ var DownloadError = class extends (_b$2 = AISDKError, _a$2 = symbol$2, _b$2) {
|
|
|
9154
9172
|
return AISDKError.hasMarker(error, marker$2);
|
|
9155
9173
|
}
|
|
9156
9174
|
};
|
|
9175
|
+
var initialGlobalFetch = globalThis.fetch;
|
|
9176
|
+
isNodeDefaultFetch(initialGlobalFetch);
|
|
9177
|
+
function isNodeDefaultFetch(fetch) {
|
|
9178
|
+
const source = Function.prototype.toString.call(fetch);
|
|
9179
|
+
return source.includes("internal/deps/undici") || source.includes("lazy loading of undici");
|
|
9180
|
+
}
|
|
9181
|
+
function getCurrentModulePath() {
|
|
9182
|
+
const originalPrepareStackTrace = Error.prepareStackTrace;
|
|
9183
|
+
try {
|
|
9184
|
+
Error.prepareStackTrace = (_error, callSites) => callSites;
|
|
9185
|
+
const error = /* @__PURE__ */ new Error("Capture current module path");
|
|
9186
|
+
Error.captureStackTrace(error, getCurrentModulePath);
|
|
9187
|
+
const [caller] = error.stack;
|
|
9188
|
+
const fileName = caller == null ? void 0 : caller.getFileName();
|
|
9189
|
+
if (fileName == null) throw new Error("Unable to determine the current module path");
|
|
9190
|
+
return fileName;
|
|
9191
|
+
} finally {
|
|
9192
|
+
Error.prepareStackTrace = originalPrepareStackTrace;
|
|
9193
|
+
}
|
|
9194
|
+
}
|
|
9157
9195
|
var DEFAULT_MAX_DOWNLOAD_SIZE = 2 * 1024 * 1024 * 1024;
|
|
9158
9196
|
async function readResponseWithSizeLimit({ response, url, maxBytes = DEFAULT_MAX_DOWNLOAD_SIZE }) {
|
|
9159
9197
|
const contentLength = response.headers.get("content-length");
|
|
@@ -9285,11 +9323,11 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
9285
9323
|
normalizedHeaders.set("user-agent", [currentUserAgentHeader, ...userAgentSuffixParts].filter(Boolean).join(" "));
|
|
9286
9324
|
return Object.fromEntries(normalizedHeaders.entries());
|
|
9287
9325
|
}
|
|
9288
|
-
var VERSION$3 = "4.0.
|
|
9326
|
+
var VERSION$3 = "4.0.41";
|
|
9289
9327
|
var getOriginalFetch = () => globalThis.fetch;
|
|
9290
|
-
var getFromApi = async ({ url, headers = {}, successfulResponseHandler, failedResponseHandler, abortSignal, fetch
|
|
9328
|
+
var getFromApi = async ({ url, headers = {}, successfulResponseHandler, failedResponseHandler, abortSignal, fetch = getOriginalFetch() }) => {
|
|
9291
9329
|
try {
|
|
9292
|
-
const response = await
|
|
9330
|
+
const response = await fetch(url, {
|
|
9293
9331
|
method: "GET",
|
|
9294
9332
|
headers: withUserAgentSuffix(headers, `ai-sdk/provider-utils/${VERSION$3}`, getRuntimeEnvironmentUserAgent()),
|
|
9295
9333
|
signal: abortSignal
|
|
@@ -10476,7 +10514,7 @@ function parseJsonEventStream({ stream, schema }) {
|
|
|
10476
10514
|
} }));
|
|
10477
10515
|
}
|
|
10478
10516
|
var getOriginalFetch2 = () => globalThis.fetch;
|
|
10479
|
-
var postJsonToApi = async ({ url, headers, body, failedResponseHandler, successfulResponseHandler, abortSignal, fetch
|
|
10517
|
+
var postJsonToApi = async ({ url, headers, body, failedResponseHandler, successfulResponseHandler, abortSignal, fetch }) => postToApi({
|
|
10480
10518
|
url,
|
|
10481
10519
|
headers: {
|
|
10482
10520
|
"Content-Type": "application/json",
|
|
@@ -10489,11 +10527,11 @@ var postJsonToApi = async ({ url, headers, body, failedResponseHandler, successf
|
|
|
10489
10527
|
failedResponseHandler,
|
|
10490
10528
|
successfulResponseHandler,
|
|
10491
10529
|
abortSignal,
|
|
10492
|
-
fetch
|
|
10530
|
+
fetch
|
|
10493
10531
|
});
|
|
10494
|
-
var postToApi = async ({ url, headers = {}, body, successfulResponseHandler, failedResponseHandler, abortSignal, fetch
|
|
10532
|
+
var postToApi = async ({ url, headers = {}, body, successfulResponseHandler, failedResponseHandler, abortSignal, fetch = getOriginalFetch2() }) => {
|
|
10495
10533
|
try {
|
|
10496
|
-
const response = await
|
|
10534
|
+
const response = await fetch(url, {
|
|
10497
10535
|
method: "POST",
|
|
10498
10536
|
headers: withUserAgentSuffix(headers, `ai-sdk/provider-utils/${VERSION$3}`, getRuntimeEnvironmentUserAgent()),
|
|
10499
10537
|
body: body.content,
|
|
@@ -10715,7 +10753,7 @@ function withoutTrailingSlash(url) {
|
|
|
10715
10753
|
return url == null ? void 0 : url.replace(/\/$/, "");
|
|
10716
10754
|
}
|
|
10717
10755
|
//#endregion
|
|
10718
|
-
//#region ../_vendored/ai_v6/dist/dist-
|
|
10756
|
+
//#region ../_vendored/ai_v6/dist/dist-3jq9sPhA.js
|
|
10719
10757
|
function getContext() {
|
|
10720
10758
|
return { headers: {} };
|
|
10721
10759
|
}
|
|
@@ -12274,7 +12312,7 @@ async function getVercelRequestId() {
|
|
|
12274
12312
|
var _a11;
|
|
12275
12313
|
return (_a11 = getContext().headers) == null ? void 0 : _a11["x-vercel-id"];
|
|
12276
12314
|
}
|
|
12277
|
-
var VERSION$2 = "3.0.
|
|
12315
|
+
var VERSION$2 = "3.0.163";
|
|
12278
12316
|
var AI_GATEWAY_PROTOCOL_VERSION = "0.0.1";
|
|
12279
12317
|
function createGatewayProvider(options = {}) {
|
|
12280
12318
|
var _a11, _b11;
|
|
@@ -13433,7 +13471,7 @@ function getTotalTimeoutMs(timeout) {
|
|
|
13433
13471
|
if (typeof timeout === "number") return timeout;
|
|
13434
13472
|
return timeout.totalMs;
|
|
13435
13473
|
}
|
|
13436
|
-
var VERSION = "6.0.
|
|
13474
|
+
var VERSION = "6.0.241";
|
|
13437
13475
|
var dataContentSchema = z$1.union([
|
|
13438
13476
|
z$1.string(),
|
|
13439
13477
|
z$1.instanceof(Uint8Array),
|
|
@@ -14797,6 +14835,7 @@ var Extractor = class Extractor {
|
|
|
14797
14835
|
includePreviousExtraction;
|
|
14798
14836
|
metadataKeyPath;
|
|
14799
14837
|
onExtracted;
|
|
14838
|
+
retryStructuredExtractionOnEmptyObject;
|
|
14800
14839
|
/** @internal */
|
|
14801
14840
|
internal;
|
|
14802
14841
|
instructionsConfig;
|
|
@@ -14819,6 +14858,7 @@ var Extractor = class Extractor {
|
|
|
14819
14858
|
this.includePreviousExtraction = config.includePreviousExtraction ?? true;
|
|
14820
14859
|
this.metadataKeyPath = config.metadataKeyPath ?? `extracted.${slug}`;
|
|
14821
14860
|
this.onExtracted = config.onExtracted;
|
|
14861
|
+
this.retryStructuredExtractionOnEmptyObject = config.retryStructuredExtractionOnEmptyObject ?? false;
|
|
14822
14862
|
this.internal = internal;
|
|
14823
14863
|
}
|
|
14824
14864
|
async resolve(context) {
|
|
@@ -14831,7 +14871,8 @@ var Extractor = class Extractor {
|
|
|
14831
14871
|
...schema ? { schema } : {},
|
|
14832
14872
|
includePreviousExtraction: this.includePreviousExtraction,
|
|
14833
14873
|
metadataKeyPath: this.metadataKeyPath,
|
|
14834
|
-
onExtracted: this.onExtracted
|
|
14874
|
+
onExtracted: this.onExtracted,
|
|
14875
|
+
retryStructuredExtractionOnEmptyObject: this.retryStructuredExtractionOnEmptyObject
|
|
14835
14876
|
}, this.internal);
|
|
14836
14877
|
}
|
|
14837
14878
|
};
|
|
@@ -15156,6 +15197,9 @@ if (OM_DEBUG_LOG) {
|
|
|
15156
15197
|
function isAbortError$1(error, abortSignal) {
|
|
15157
15198
|
return abortSignal?.aborted === true || error instanceof DOMException && error.name === "AbortError" || error instanceof Error && error.name === "AbortError";
|
|
15158
15199
|
}
|
|
15200
|
+
function shouldRetryEmptyStructuredObject(object, extractors) {
|
|
15201
|
+
return Object.keys(object).length === 0 && extractors.some((extractor) => extractor.retryStructuredExtractionOnEmptyObject);
|
|
15202
|
+
}
|
|
15159
15203
|
async function extractStructuredValues(opts) {
|
|
15160
15204
|
const structuredExtractors = (opts.extractors ?? []).filter((extractor) => extractor.mode === "structured");
|
|
15161
15205
|
if (structuredExtractors.length === 0) return {
|
|
@@ -15192,8 +15236,10 @@ ${extractorInstructions}${priorLines.length > 0 ? `\n\n## Prior Extracted Values
|
|
|
15192
15236
|
return output.object;
|
|
15193
15237
|
};
|
|
15194
15238
|
let object;
|
|
15239
|
+
let retryEmptyObject = false;
|
|
15195
15240
|
try {
|
|
15196
15241
|
object = await generateWithStructuredOutput();
|
|
15242
|
+
retryEmptyObject = shouldRetryEmptyStructuredObject(object, structuredExtractors);
|
|
15197
15243
|
} catch (error) {
|
|
15198
15244
|
if (isAbortError$1(error, opts.abortSignal)) throw error;
|
|
15199
15245
|
try {
|
|
@@ -15210,6 +15256,19 @@ ${extractorInstructions}${priorLines.length > 0 ? `\n\n## Prior Extracted Values
|
|
|
15210
15256
|
};
|
|
15211
15257
|
}
|
|
15212
15258
|
}
|
|
15259
|
+
if (retryEmptyObject) try {
|
|
15260
|
+
object = await generateWithStructuredOutput(coreFeatures.has("json-prompt-injection:inline") ? "inline" : true);
|
|
15261
|
+
} catch (fallbackError) {
|
|
15262
|
+
if (isAbortError$1(fallbackError, opts.abortSignal)) throw fallbackError;
|
|
15263
|
+
const message = fallbackError instanceof Error ? fallbackError.message : String(fallbackError);
|
|
15264
|
+
return {
|
|
15265
|
+
values,
|
|
15266
|
+
failures: structuredExtractors.map((extractor) => ({
|
|
15267
|
+
slug: extractor.slug,
|
|
15268
|
+
error: message
|
|
15269
|
+
}))
|
|
15270
|
+
};
|
|
15271
|
+
}
|
|
15213
15272
|
for (const extractor of structuredExtractors) {
|
|
15214
15273
|
const value = object[extractor.slug];
|
|
15215
15274
|
if (value === void 0 || value === null || value === "") continue;
|
|
@@ -18515,6 +18574,17 @@ var TokenCounter = class TokenCounter {
|
|
|
18515
18574
|
toolResultDelta
|
|
18516
18575
|
};
|
|
18517
18576
|
}
|
|
18577
|
+
if (invocation.state === "output-error") {
|
|
18578
|
+
toolResultDelta++;
|
|
18579
|
+
const errorText = invocation.errorText;
|
|
18580
|
+
const errorMessage = typeof errorText === "string" ? errorText : "Tool execution failed";
|
|
18581
|
+
tokens += this.readOrPersistPartEstimate(part, "tool-result-error", errorMessage);
|
|
18582
|
+
return {
|
|
18583
|
+
tokens,
|
|
18584
|
+
overheadDelta,
|
|
18585
|
+
toolResultDelta
|
|
18586
|
+
};
|
|
18587
|
+
}
|
|
18518
18588
|
throw new Error(`Unhandled tool-invocation state '${part.toolInvocation?.state}' in token counting for part type '${part.type}'`);
|
|
18519
18589
|
}
|
|
18520
18590
|
if (typeof part.type === "string" && part.type.startsWith("data-")) return {
|
|
@@ -18740,6 +18810,7 @@ var WorkingMemoryExtractor = class extends Extractor {
|
|
|
18740
18810
|
name: "Working Memory",
|
|
18741
18811
|
includePreviousExtraction: false,
|
|
18742
18812
|
metadataKeyPath: false,
|
|
18813
|
+
retryStructuredExtractionOnEmptyObject: true,
|
|
18743
18814
|
instructions: async (context) => buildWorkingMemoryInstructions(await getWorkingMemoryDetails(context)),
|
|
18744
18815
|
schema: async (context) => {
|
|
18745
18816
|
return (await getWorkingMemoryDetails(context)).usesSchema ? z.union([z.record(z.string(), z.unknown()), z.null()]) : void 0;
|
|
@@ -20439,6 +20510,68 @@ function isMessageAtOrBeforeCursor(msg, cursor) {
|
|
|
20439
20510
|
return false;
|
|
20440
20511
|
}
|
|
20441
20512
|
/**
|
|
20513
|
+
* Return the toolCallId of a tool-invocation part in the given state, or undefined.
|
|
20514
|
+
*/
|
|
20515
|
+
function getToolInvocationId(part, state) {
|
|
20516
|
+
if (part?.type !== "tool-invocation") return void 0;
|
|
20517
|
+
if (part.toolInvocation.state !== state) return void 0;
|
|
20518
|
+
return part.toolInvocation.toolCallId || void 0;
|
|
20519
|
+
}
|
|
20520
|
+
function collectPendingToolResultIds(allMessages, observedIds) {
|
|
20521
|
+
const pendingToolResultIds = /* @__PURE__ */ new Set();
|
|
20522
|
+
for (const msg of allMessages) {
|
|
20523
|
+
if (!msg?.id) continue;
|
|
20524
|
+
if (observedIds?.has(msg.id)) continue;
|
|
20525
|
+
const parts = msg.content?.parts;
|
|
20526
|
+
if (!parts || !Array.isArray(parts)) continue;
|
|
20527
|
+
for (const part of parts) {
|
|
20528
|
+
const id = getToolInvocationId(part, "result");
|
|
20529
|
+
if (id) pendingToolResultIds.add(id);
|
|
20530
|
+
}
|
|
20531
|
+
}
|
|
20532
|
+
return pendingToolResultIds;
|
|
20533
|
+
}
|
|
20534
|
+
function hasPendingToolResultPair(message, pendingToolResultIds) {
|
|
20535
|
+
if (pendingToolResultIds.size === 0) return false;
|
|
20536
|
+
const parts = message.content?.parts;
|
|
20537
|
+
if (!parts || !Array.isArray(parts)) return false;
|
|
20538
|
+
return parts.some((part) => {
|
|
20539
|
+
const id = getToolInvocationId(part, "call");
|
|
20540
|
+
return id !== void 0 && pendingToolResultIds.has(id);
|
|
20541
|
+
});
|
|
20542
|
+
}
|
|
20543
|
+
function collectPendingToolResultIdsAfterMarker(allMessages, markerMessageIndex, markerMessage) {
|
|
20544
|
+
const pendingToolResultIds = /* @__PURE__ */ new Set();
|
|
20545
|
+
const unobservedMarkerParts = getUnobservedParts(markerMessage);
|
|
20546
|
+
if (unobservedMarkerParts.length > 0) collectPendingToolResultIds([{
|
|
20547
|
+
...markerMessage,
|
|
20548
|
+
content: {
|
|
20549
|
+
...markerMessage.content,
|
|
20550
|
+
parts: unobservedMarkerParts
|
|
20551
|
+
}
|
|
20552
|
+
}], void 0).forEach((id) => pendingToolResultIds.add(id));
|
|
20553
|
+
collectPendingToolResultIds(allMessages.slice(markerMessageIndex + 1), void 0).forEach((id) => pendingToolResultIds.add(id));
|
|
20554
|
+
return pendingToolResultIds;
|
|
20555
|
+
}
|
|
20556
|
+
function getUnobservedPartsPreservingToolCallPairs(message) {
|
|
20557
|
+
const parts = message.content?.parts;
|
|
20558
|
+
if (!parts || !Array.isArray(parts)) return [];
|
|
20559
|
+
const endMarkerIndex = findLastCompletedObservationBoundary(message);
|
|
20560
|
+
if (endMarkerIndex === -1) return getUnobservedParts(message);
|
|
20561
|
+
const unobservedParts = getUnobservedParts(message);
|
|
20562
|
+
const unobservedResultIds = /* @__PURE__ */ new Set();
|
|
20563
|
+
for (const part of unobservedParts) {
|
|
20564
|
+
const id = getToolInvocationId(part, "result");
|
|
20565
|
+
if (id) unobservedResultIds.add(id);
|
|
20566
|
+
}
|
|
20567
|
+
if (unobservedResultIds.size === 0) return unobservedParts;
|
|
20568
|
+
const preservedCalls = parts.slice(0, endMarkerIndex).filter((part) => {
|
|
20569
|
+
const id = getToolInvocationId(part, "call");
|
|
20570
|
+
return id !== void 0 && unobservedResultIds.has(id);
|
|
20571
|
+
});
|
|
20572
|
+
return preservedCalls.length > 0 ? [...preservedCalls, ...unobservedParts] : unobservedParts;
|
|
20573
|
+
}
|
|
20574
|
+
/**
|
|
20442
20575
|
* Safely extract buffered observation chunks from a record.
|
|
20443
20576
|
* Handles both array and JSON-string formats, returning empty array if malformed.
|
|
20444
20577
|
*/
|
|
@@ -20454,6 +20587,7 @@ function filterObservedMessages(opts) {
|
|
|
20454
20587
|
const allMessages = messageList.get.all.db();
|
|
20455
20588
|
const useMarkerBoundaryPruning = opts.useMarkerBoundaryPruning ?? true;
|
|
20456
20589
|
const preserveMessageIds = opts.preserveMessageIds ?? /* @__PURE__ */ new Set();
|
|
20590
|
+
const observedIds = new Set(Array.isArray(record?.observedMessageIds) ? record.observedMessageIds : []);
|
|
20457
20591
|
let markerMessageIndex = -1;
|
|
20458
20592
|
let markerMessage = null;
|
|
20459
20593
|
for (let i = allMessages.length - 1; i >= 0; i--) {
|
|
@@ -20466,33 +20600,40 @@ function filterObservedMessages(opts) {
|
|
|
20466
20600
|
}
|
|
20467
20601
|
}
|
|
20468
20602
|
if (useMarkerBoundaryPruning && markerMessage && markerMessageIndex !== -1) {
|
|
20603
|
+
const pendingToolResultIds = collectPendingToolResultIdsAfterMarker(allMessages, markerMessageIndex, markerMessage);
|
|
20469
20604
|
const messagesToRemove = [];
|
|
20470
20605
|
for (let i = 0; i < markerMessageIndex; i++) {
|
|
20471
20606
|
const msg = allMessages[i];
|
|
20472
|
-
if (msg?.id && msg.id !== "om-continuation" && !preserveMessageIds.has(msg.id)) messagesToRemove.push(msg.id);
|
|
20607
|
+
if (msg?.id && msg.id !== "om-continuation" && !preserveMessageIds.has(msg.id) && !hasPendingToolResultPair(msg, pendingToolResultIds)) messagesToRemove.push(msg.id);
|
|
20473
20608
|
}
|
|
20474
20609
|
if (messagesToRemove.length > 0) messageList.removeByIds(messagesToRemove);
|
|
20475
|
-
const unobserved =
|
|
20610
|
+
const unobserved = getUnobservedPartsPreservingToolCallPairs(markerMessage);
|
|
20476
20611
|
if (unobserved.length === 0) {
|
|
20477
20612
|
if (markerMessage.id) messageList.removeByIds([markerMessage.id]);
|
|
20478
20613
|
} else if (unobserved.length < (markerMessage.content?.parts?.length ?? 0)) markerMessage.content.parts = unobserved;
|
|
20479
20614
|
} else if (record) {
|
|
20480
|
-
const
|
|
20615
|
+
const pendingToolResultIds = collectPendingToolResultIds(allMessages, observedIds);
|
|
20481
20616
|
const derivedCursor = opts.fallbackCursor ?? getLastObservedMessageCursor(allMessages.filter((msg) => !!msg?.id && observedIds.has(msg.id) && !!msg.createdAt));
|
|
20482
20617
|
const lastObservedAt = record.lastObservedAt;
|
|
20483
20618
|
const messagesToRemove = [];
|
|
20484
20619
|
for (const msg of allMessages) {
|
|
20485
20620
|
if (!msg?.id || msg.id === "om-continuation" || preserveMessageIds.has(msg.id)) continue;
|
|
20621
|
+
const hasPendingPair = hasPendingToolResultPair(msg, pendingToolResultIds);
|
|
20486
20622
|
if (observedIds.has(msg.id)) {
|
|
20623
|
+
if (hasPendingPair) continue;
|
|
20487
20624
|
messagesToRemove.push(msg.id);
|
|
20488
20625
|
continue;
|
|
20489
20626
|
}
|
|
20490
20627
|
if (derivedCursor && isMessageAtOrBeforeCursor(msg, derivedCursor)) {
|
|
20628
|
+
if (hasPendingPair) continue;
|
|
20491
20629
|
messagesToRemove.push(msg.id);
|
|
20492
20630
|
continue;
|
|
20493
20631
|
}
|
|
20494
20632
|
if (lastObservedAt && msg.createdAt) {
|
|
20495
|
-
if (new Date(msg.createdAt) <= lastObservedAt)
|
|
20633
|
+
if (new Date(msg.createdAt) <= lastObservedAt) {
|
|
20634
|
+
if (hasPendingPair) continue;
|
|
20635
|
+
messagesToRemove.push(msg.id);
|
|
20636
|
+
}
|
|
20496
20637
|
}
|
|
20497
20638
|
}
|
|
20498
20639
|
if (messagesToRemove.length > 0) messageList.removeByIds(messagesToRemove);
|
|
@@ -20861,7 +21002,7 @@ var ObservationStrategy = class ObservationStrategy {
|
|
|
20861
21002
|
transient: true
|
|
20862
21003
|
}).catch(() => {});
|
|
20863
21004
|
const markerThreadId = marker.data?.threadId ?? this.opts.threadId;
|
|
20864
|
-
await this.persistMarkerToStorage(marker, markerThreadId, this.opts.resourceId);
|
|
21005
|
+
if (!await this.persistMarkerToMessage(marker, this.opts.messageList, markerThreadId, this.opts.resourceId)) await this.persistMarkerToStorage(marker, markerThreadId, this.opts.resourceId);
|
|
20865
21006
|
}
|
|
20866
21007
|
getObservationMarkerConfig() {
|
|
20867
21008
|
return {
|
|
@@ -20989,9 +21130,13 @@ var ObservationStrategy = class ObservationStrategy {
|
|
|
20989
21130
|
/**
|
|
20990
21131
|
* Persist a marker part on the last assistant message in a MessageList
|
|
20991
21132
|
* AND save the updated message to the DB.
|
|
21133
|
+
*
|
|
21134
|
+
* @returns true when a marker was placed on an assistant message, false when
|
|
21135
|
+
* no list was provided or the list contains no assistant message (caller
|
|
21136
|
+
* should fall back to `persistMarkerToStorage`).
|
|
20992
21137
|
*/
|
|
20993
21138
|
async persistMarkerToMessage(marker, messageList, threadId, resourceId) {
|
|
20994
|
-
if (!messageList) return;
|
|
21139
|
+
if (!messageList) return false;
|
|
20995
21140
|
const allMsgs = messageList.get.all.db();
|
|
20996
21141
|
for (let i = allMsgs.length - 1; i >= 0; i--) {
|
|
20997
21142
|
const msg = allMsgs[i];
|
|
@@ -21007,9 +21152,10 @@ var ObservationStrategy = class ObservationStrategy {
|
|
|
21007
21152
|
} catch (e) {
|
|
21008
21153
|
omDebug(`[OM:persistMarker] failed to save marker to DB: ${e}`);
|
|
21009
21154
|
}
|
|
21010
|
-
return;
|
|
21155
|
+
return true;
|
|
21011
21156
|
}
|
|
21012
21157
|
}
|
|
21158
|
+
return false;
|
|
21013
21159
|
}
|
|
21014
21160
|
};
|
|
21015
21161
|
//#endregion
|
|
@@ -21818,6 +21964,12 @@ var ObservationStep = class {
|
|
|
21818
21964
|
stepNumber;
|
|
21819
21965
|
_prepared = false;
|
|
21820
21966
|
_context;
|
|
21967
|
+
/**
|
|
21968
|
+
* True when this step seeded an empty assistant response message for a step-0
|
|
21969
|
+
* observation. While set, the response-id rotation hook must NOT run — rotating
|
|
21970
|
+
* would orphan the seed (markers would sit on a message the agent never streams into).
|
|
21971
|
+
*/
|
|
21972
|
+
seededResponseMessage = false;
|
|
21821
21973
|
constructor(turn, stepNumber) {
|
|
21822
21974
|
this.turn = turn;
|
|
21823
21975
|
this.stepNumber = stepNumber;
|
|
@@ -21946,15 +22098,41 @@ var ObservationStep = class {
|
|
|
21946
22098
|
});
|
|
21947
22099
|
buffered = true;
|
|
21948
22100
|
}
|
|
21949
|
-
|
|
21950
|
-
|
|
21951
|
-
|
|
21952
|
-
|
|
21953
|
-
if (
|
|
21954
|
-
|
|
21955
|
-
|
|
22101
|
+
const willObserveNow = statusSnapshot.shouldObserve && !hasIncompleteToolCalls;
|
|
22102
|
+
/** In-flight message ids the step-0 cleanup must never remove from live context. */
|
|
22103
|
+
let step0PreserveIds;
|
|
22104
|
+
if (this.stepNumber > 0 || willObserveNow) {
|
|
22105
|
+
if (this.stepNumber > 0) {
|
|
22106
|
+
const newInput = messageList.clear.input.db();
|
|
22107
|
+
const newOutput = messageList.clear.response.db();
|
|
22108
|
+
const messagesToSave = [...newInput, ...newOutput];
|
|
22109
|
+
if (messagesToSave.length > 0) {
|
|
22110
|
+
await om.persistMessages(messagesToSave, threadId, resourceId);
|
|
22111
|
+
for (const msg of messagesToSave) messageList.add(msg, "memory");
|
|
22112
|
+
}
|
|
22113
|
+
} else {
|
|
22114
|
+
const pending = [...messageList.get.input.db(), ...messageList.get.response.db()];
|
|
22115
|
+
if (pending.length > 0) await om.persistMessages(pending, threadId, resourceId);
|
|
22116
|
+
step0PreserveIds = pending.map((msg) => msg.id);
|
|
21956
22117
|
}
|
|
21957
|
-
if (
|
|
22118
|
+
if (this.stepNumber === 0 && willObserveNow && this.turn.responseMessageId) {
|
|
22119
|
+
const seed = {
|
|
22120
|
+
id: this.turn.responseMessageId,
|
|
22121
|
+
role: "assistant",
|
|
22122
|
+
content: {
|
|
22123
|
+
format: 2,
|
|
22124
|
+
parts: []
|
|
22125
|
+
},
|
|
22126
|
+
type: "text",
|
|
22127
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
22128
|
+
threadId,
|
|
22129
|
+
resourceId
|
|
22130
|
+
};
|
|
22131
|
+
messageList.add(seed, "response");
|
|
22132
|
+
this.seededResponseMessage = true;
|
|
22133
|
+
omDebug(`[OM:step0] seeded response message ${seed.id} for step-0 observation markers`);
|
|
22134
|
+
}
|
|
22135
|
+
if (willObserveNow) {
|
|
21958
22136
|
const preObsGeneration = this.turn.record.generationCount;
|
|
21959
22137
|
const obsResult = await this.runThresholdObservation();
|
|
21960
22138
|
observerExchange = obsResult.observerExchange;
|
|
@@ -21968,7 +22146,8 @@ var ObservationStep = class {
|
|
|
21968
22146
|
resourceId,
|
|
21969
22147
|
messages: messageList,
|
|
21970
22148
|
observedMessageIds: observedIds,
|
|
21971
|
-
retentionFloor: minRemaining
|
|
22149
|
+
retentionFloor: minRemaining,
|
|
22150
|
+
preserveMessageIds: step0PreserveIds
|
|
21972
22151
|
});
|
|
21973
22152
|
if (statusSnapshot.asyncObservationEnabled) await om.resetBufferingState({
|
|
21974
22153
|
threadId,
|
|
@@ -22032,10 +22211,11 @@ var ObservationStep = class {
|
|
|
22032
22211
|
const { threadId, resourceId, messageList } = this.turn;
|
|
22033
22212
|
const om = this.turn.om;
|
|
22034
22213
|
await om.waitForBuffering(threadId, resourceId);
|
|
22214
|
+
const observableMessages = this.seededResponseMessage ? messageList.get.all.db().filter((msg) => msg.id !== this.turn.responseMessageId) : messageList.get.all.db();
|
|
22035
22215
|
const freshStatus = await om.getStatus({
|
|
22036
22216
|
threadId,
|
|
22037
22217
|
resourceId,
|
|
22038
|
-
messages:
|
|
22218
|
+
messages: observableMessages
|
|
22039
22219
|
});
|
|
22040
22220
|
if (!freshStatus.shouldObserve) return {
|
|
22041
22221
|
succeeded: false,
|
|
@@ -22045,7 +22225,7 @@ var ObservationStep = class {
|
|
|
22045
22225
|
const activation = await om.activate({
|
|
22046
22226
|
threadId,
|
|
22047
22227
|
resourceId,
|
|
22048
|
-
messages:
|
|
22228
|
+
messages: observableMessages,
|
|
22049
22229
|
currentModel: this.turn.actorModelContext,
|
|
22050
22230
|
writer: this.turn.writer,
|
|
22051
22231
|
messageList
|
|
@@ -22078,7 +22258,8 @@ var ObservationStep = class {
|
|
|
22078
22258
|
const obsResult = await om.observe({
|
|
22079
22259
|
threadId,
|
|
22080
22260
|
resourceId,
|
|
22081
|
-
messages:
|
|
22261
|
+
messages: observableMessages,
|
|
22262
|
+
messageList,
|
|
22082
22263
|
trigger: "turn-sync",
|
|
22083
22264
|
requestContext: this.turn.requestContext,
|
|
22084
22265
|
writer: this.turn.writer,
|
|
@@ -22095,10 +22276,12 @@ var ObservationStep = class {
|
|
|
22095
22276
|
break;
|
|
22096
22277
|
}
|
|
22097
22278
|
}
|
|
22098
|
-
|
|
22279
|
+
let messageToSeal = latestObservedIndex >= 0 ? liveMessages[latestObservedIndex] : void 0;
|
|
22280
|
+
if (this.stepNumber === 0 && messageToSeal?.role !== "assistant") messageToSeal = void 0;
|
|
22099
22281
|
const messagesToSeal = messageToSeal ? [messageToSeal] : [];
|
|
22100
22282
|
om.sealMessagesForBuffering(messagesToSeal);
|
|
22101
|
-
|
|
22283
|
+
if (this.seededResponseMessage) omDebug("[OM:observe] skipping response-id rotation — step-0 seeded response message holds the active id");
|
|
22284
|
+
else try {
|
|
22102
22285
|
await this.turn.hooks?.onSyncObservationComplete?.();
|
|
22103
22286
|
} catch (error) {
|
|
22104
22287
|
omDebug(`[OM:observe] onSyncObservationComplete hook failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
@@ -22159,6 +22342,8 @@ var ObservationTurn = class {
|
|
|
22159
22342
|
sendSignal;
|
|
22160
22343
|
/** Current actor model for this step. Updated by the processor before prepare(). */
|
|
22161
22344
|
actorModelContext;
|
|
22345
|
+
/** The active assistant response message ID for this step. Updated by the processor before prepare(). */
|
|
22346
|
+
responseMessageId;
|
|
22162
22347
|
/** Processor-provided hooks for turn/step lifecycle integration. */
|
|
22163
22348
|
hooks;
|
|
22164
22349
|
constructor(opts) {
|
|
@@ -23798,6 +23983,14 @@ var ObservationalMemory = class ObservationalMemory {
|
|
|
23798
23983
|
*/
|
|
23799
23984
|
locks = /* @__PURE__ */ new Map();
|
|
23800
23985
|
/**
|
|
23986
|
+
* Initial record lookup/creation promises keyed by the effective storage scope.
|
|
23987
|
+
* Concurrent callers share the full read-or-create operation so a stale read
|
|
23988
|
+
* cannot create another generation-zero record after the first insert finishes.
|
|
23989
|
+
* Entries are removed after both success and failure so later calls always
|
|
23990
|
+
* re-read storage and transient failures can be retried.
|
|
23991
|
+
*/
|
|
23992
|
+
recordInitializations = /* @__PURE__ */ new Map();
|
|
23993
|
+
/**
|
|
23801
23994
|
* Acquire a lock for the given key, execute the callback, then release.
|
|
23802
23995
|
* If a lock is already held, waits for it to be released before acquiring.
|
|
23803
23996
|
*/
|
|
@@ -24158,10 +24351,14 @@ var ObservationalMemory = class ObservationalMemory {
|
|
|
24158
24351
|
*/
|
|
24159
24352
|
async getOrCreateRecord(threadId, resourceId) {
|
|
24160
24353
|
const ids = this.getStorageIds(threadId, resourceId);
|
|
24161
|
-
|
|
24162
|
-
|
|
24354
|
+
const initializationKey = ids.threadId === null ? `resource:${ids.resourceId}` : `thread:${ids.threadId}`;
|
|
24355
|
+
const pendingInitialization = this.recordInitializations.get(initializationKey);
|
|
24356
|
+
if (pendingInitialization) return pendingInitialization;
|
|
24357
|
+
const initialization = Promise.resolve().then(async () => {
|
|
24358
|
+
const record = await this.storage.getObservationalMemory(ids.threadId, ids.resourceId);
|
|
24359
|
+
if (record) return record;
|
|
24163
24360
|
const observedTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
24164
|
-
|
|
24361
|
+
return this.storage.initializeObservationalMemory({
|
|
24165
24362
|
threadId: ids.threadId,
|
|
24166
24363
|
resourceId: ids.resourceId,
|
|
24167
24364
|
scope: this.scope,
|
|
@@ -24172,8 +24369,13 @@ var ObservationalMemory = class ObservationalMemory {
|
|
|
24172
24369
|
},
|
|
24173
24370
|
observedTimezone
|
|
24174
24371
|
});
|
|
24372
|
+
});
|
|
24373
|
+
this.recordInitializations.set(initializationKey, initialization);
|
|
24374
|
+
try {
|
|
24375
|
+
return await initialization;
|
|
24376
|
+
} finally {
|
|
24377
|
+
if (this.recordInitializations.get(initializationKey) === initialization) this.recordInitializations.delete(initializationKey);
|
|
24175
24378
|
}
|
|
24176
|
-
return record;
|
|
24177
24379
|
}
|
|
24178
24380
|
/**
|
|
24179
24381
|
* Get current config snapshot for observation markers.
|
|
@@ -24810,6 +25012,7 @@ ${formattedMessages}
|
|
|
24810
25012
|
*/
|
|
24811
25013
|
async getObservedMessageIdsForCleanup(opts) {
|
|
24812
25014
|
const { threadId, resourceId, messages, observedMessageIds, retentionFloor } = opts;
|
|
25015
|
+
const preserveSet = opts.preserveMessageIds?.length ? new Set(opts.preserveMessageIds) : null;
|
|
24813
25016
|
const record = await this.getOrCreateRecord(threadId, resourceId);
|
|
24814
25017
|
const effectiveObservedIds = observedMessageIds && observedMessageIds.length > 0 ? observedMessageIds : Array.isArray(record.observedMessageIds) ? record.observedMessageIds : [];
|
|
24815
25018
|
if (effectiveObservedIds.length === 0) return [];
|
|
@@ -24821,6 +25024,10 @@ ${formattedMessages}
|
|
|
24821
25024
|
const retentionCounter = typeof retentionFloor === "number" ? new TokenCounter() : null;
|
|
24822
25025
|
for (const msg of messages) {
|
|
24823
25026
|
if (!msg?.id || msg.id === "om-continuation" || !observedSet.has(msg.id)) continue;
|
|
25027
|
+
if (preserveSet?.has(msg.id)) {
|
|
25028
|
+
skipped += 1;
|
|
25029
|
+
continue;
|
|
25030
|
+
}
|
|
24824
25031
|
const unobservedParts = getUnobservedParts(msg);
|
|
24825
25032
|
const totalParts = msg.content?.parts?.length ?? 0;
|
|
24826
25033
|
if (unobservedParts.length > 0 && unobservedParts.length < totalParts) {
|
|
@@ -24865,7 +25072,7 @@ ${formattedMessages}
|
|
|
24865
25072
|
*/
|
|
24866
25073
|
/** @internal Used by ObservationStep. */
|
|
24867
25074
|
async cleanupMessages(opts) {
|
|
24868
|
-
const { threadId, resourceId, observedMessageIds, retentionFloor } = opts;
|
|
25075
|
+
const { threadId, resourceId, observedMessageIds, retentionFloor, preserveMessageIds } = opts;
|
|
24869
25076
|
const messageList = this.isMessageList(opts.messages) ? opts.messages : void 0;
|
|
24870
25077
|
const allMsgs = messageList ? messageList.get.all.db() : opts.messages;
|
|
24871
25078
|
let markerIdx = -1;
|
|
@@ -24886,7 +25093,8 @@ ${formattedMessages}
|
|
|
24886
25093
|
resourceId,
|
|
24887
25094
|
messages: allMsgs,
|
|
24888
25095
|
observedMessageIds,
|
|
24889
|
-
retentionFloor
|
|
25096
|
+
retentionFloor,
|
|
25097
|
+
preserveMessageIds
|
|
24890
25098
|
});
|
|
24891
25099
|
if (messageList) {
|
|
24892
25100
|
if (idsToRemoveList.length > 0) messageList.removeByIds(idsToRemoveList);
|
|
@@ -24898,18 +25106,21 @@ ${formattedMessages}
|
|
|
24898
25106
|
if (markerMsg && markerIdx !== -1) {
|
|
24899
25107
|
const idsToRemove = [];
|
|
24900
25108
|
const messagesToSave = [];
|
|
25109
|
+
const preserveSet = preserveMessageIds?.length ? new Set(preserveMessageIds) : null;
|
|
24901
25110
|
for (let i = 0; i < markerIdx; i++) {
|
|
24902
25111
|
const msg = allMsgs[i];
|
|
24903
|
-
if (msg?.id && msg.id !== "om-continuation") {
|
|
25112
|
+
if (msg?.id && msg.id !== "om-continuation" && !preserveSet?.has(msg.id)) {
|
|
24904
25113
|
idsToRemove.push(msg.id);
|
|
24905
25114
|
messagesToSave.push(msg);
|
|
24906
25115
|
}
|
|
24907
25116
|
}
|
|
24908
25117
|
messagesToSave.push(markerMsg);
|
|
24909
|
-
|
|
24910
|
-
|
|
24911
|
-
if (
|
|
24912
|
-
|
|
25118
|
+
if (!Boolean(markerMsg.id && preserveSet?.has(markerMsg.id))) {
|
|
25119
|
+
const unobservedParts = getUnobservedParts(markerMsg);
|
|
25120
|
+
if (unobservedParts.length === 0) {
|
|
25121
|
+
if (markerMsg.id) idsToRemove.push(markerMsg.id);
|
|
25122
|
+
} else if (unobservedParts.length < (markerMsg.content?.parts?.length ?? 0)) markerMsg.content.parts = unobservedParts;
|
|
25123
|
+
}
|
|
24913
25124
|
if (messageList) {
|
|
24914
25125
|
if (idsToRemove.length > 0) messageList.removeByIds(idsToRemove);
|
|
24915
25126
|
if (messagesToSave.length > 0) await this.persistMessages(messagesToSave, threadId, resourceId);
|
|
@@ -25696,6 +25907,7 @@ ${formattedMessages}
|
|
|
25696
25907
|
threadId,
|
|
25697
25908
|
resourceId,
|
|
25698
25909
|
messages: unobservedMessages,
|
|
25910
|
+
messageList: opts.messageList,
|
|
25699
25911
|
reflectionHooks,
|
|
25700
25912
|
agent: opts.agent,
|
|
25701
25913
|
requestContext,
|
|
@@ -26085,7 +26297,7 @@ var ObservationalMemoryProcessor = class {
|
|
|
26085
26297
|
this.temporalMarkers = options?.temporalMarkers ?? false;
|
|
26086
26298
|
}
|
|
26087
26299
|
async processInputStep(args) {
|
|
26088
|
-
const { messageList, requestContext, stepNumber, state: _state, writer, model, abortSignal, abort, rotateResponseMessageId } = args;
|
|
26300
|
+
const { messageList, requestContext, stepNumber, state: _state, writer, model, abortSignal, abort, messageId, rotateResponseMessageId } = args;
|
|
26089
26301
|
const state = _state ?? {};
|
|
26090
26302
|
omDebug(`[OM:processInputStep:ENTER] step=${stepNumber}, hasMastraMemory=${!!requestContext?.get("MastraMemory")}, hasMemoryInfo=${!!messageList?.serialize()?.memoryInfo?.threadId}`);
|
|
26091
26303
|
const context = this.engine.getThreadContext(requestContext, messageList);
|
|
@@ -26171,6 +26383,7 @@ var ObservationalMemoryProcessor = class {
|
|
|
26171
26383
|
state.__omObservabilityContext = observabilityContext;
|
|
26172
26384
|
this.turn.observabilityContext = observabilityContext;
|
|
26173
26385
|
this.turn.actorModelContext = actorModelContext;
|
|
26386
|
+
this.turn.responseMessageId = messageId;
|
|
26174
26387
|
{
|
|
26175
26388
|
const step = this.turn.step(stepNumber);
|
|
26176
26389
|
let ctx;
|
|
@@ -26541,6 +26754,11 @@ function filterSystemReminderMessages(messages, includeSystemReminders) {
|
|
|
26541
26754
|
if (includeSystemReminders) return messages;
|
|
26542
26755
|
return messages.filter((message) => !isSystemReminderMessage(message));
|
|
26543
26756
|
}
|
|
26757
|
+
function isTransientSignalMessage(message) {
|
|
26758
|
+
if (message.role !== "signal" || !isRecord(message.content)) return false;
|
|
26759
|
+
const metadata = message.content.metadata;
|
|
26760
|
+
return isRecord(metadata) && isRecord(metadata.signal) && !Array.isArray(metadata.signal) && metadata.signal.transient === true;
|
|
26761
|
+
}
|
|
26544
26762
|
function normalizeObservationalMemoryConfig(config) {
|
|
26545
26763
|
if (config === true) return { model: "google/gemini-2.5-flash" };
|
|
26546
26764
|
if (config === false || config === void 0) return void 0;
|
|
@@ -27074,7 +27292,7 @@ ${workingMemory}`;
|
|
|
27074
27292
|
async saveMessages({ messages, memoryConfig, observabilityContext }) {
|
|
27075
27293
|
const span = this.createMemorySpan("save", observabilityContext, void 0, { messageCount: messages.length });
|
|
27076
27294
|
try {
|
|
27077
|
-
const updatedMessages = messages.filter((m) => m.role !== "system").map((m) => {
|
|
27295
|
+
const updatedMessages = messages.filter((m) => m.role !== "system" && !isTransientSignalMessage(m)).map((m) => {
|
|
27078
27296
|
return this.updateMessageToHideWorkingMemoryV2(m);
|
|
27079
27297
|
}).filter((m) => Boolean(m));
|
|
27080
27298
|
const config = this.getMergedThreadConfig(memoryConfig);
|
|
@@ -27366,7 +27584,7 @@ ${workingMemory}`;
|
|
|
27366
27584
|
*/
|
|
27367
27585
|
async persistMessages(messages) {
|
|
27368
27586
|
if (messages.length === 0) return;
|
|
27369
|
-
const persistableMessages = messages.filter((m) => m.role !== "system");
|
|
27587
|
+
const persistableMessages = messages.filter((m) => m.role !== "system" && !isTransientSignalMessage(m));
|
|
27370
27588
|
if (persistableMessages.length === 0) return;
|
|
27371
27589
|
await (await this.getMemoryStore()).saveMessages({ messages: persistableMessages });
|
|
27372
27590
|
}
|
|
@@ -28313,4 +28531,4 @@ Notes:
|
|
|
28313
28531
|
//#endregion
|
|
28314
28532
|
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 };
|
|
28315
28533
|
|
|
28316
|
-
//# sourceMappingURL=src-
|
|
28534
|
+
//# sourceMappingURL=src-Iw-V5CfD.js.map
|