@mastra/memory 1.25.1-alpha.0 → 1.26.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 +24 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- 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/message-utils.d.ts.map +1 -1
- package/dist/processors/observational-memory/observational-memory.d.ts +8 -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/{src-Bz9Fg416.cjs → src-CjTEWCUF.cjs} +173 -43
- package/dist/src-CjTEWCUF.cjs.map +1 -0
- package/dist/{src-DvQWV6nH.js → src-Cwt9gefz.js} +171 -41
- package/dist/src-Cwt9gefz.js.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),
|
|
@@ -20439,6 +20477,68 @@ function isMessageAtOrBeforeCursor(msg, cursor) {
|
|
|
20439
20477
|
return false;
|
|
20440
20478
|
}
|
|
20441
20479
|
/**
|
|
20480
|
+
* Return the toolCallId of a tool-invocation part in the given state, or undefined.
|
|
20481
|
+
*/
|
|
20482
|
+
function getToolInvocationId(part, state) {
|
|
20483
|
+
if (part?.type !== "tool-invocation") return void 0;
|
|
20484
|
+
if (part.toolInvocation.state !== state) return void 0;
|
|
20485
|
+
return part.toolInvocation.toolCallId || void 0;
|
|
20486
|
+
}
|
|
20487
|
+
function collectPendingToolResultIds(allMessages, observedIds) {
|
|
20488
|
+
const pendingToolResultIds = /* @__PURE__ */ new Set();
|
|
20489
|
+
for (const msg of allMessages) {
|
|
20490
|
+
if (!msg?.id) continue;
|
|
20491
|
+
if (observedIds?.has(msg.id)) continue;
|
|
20492
|
+
const parts = msg.content?.parts;
|
|
20493
|
+
if (!parts || !Array.isArray(parts)) continue;
|
|
20494
|
+
for (const part of parts) {
|
|
20495
|
+
const id = getToolInvocationId(part, "result");
|
|
20496
|
+
if (id) pendingToolResultIds.add(id);
|
|
20497
|
+
}
|
|
20498
|
+
}
|
|
20499
|
+
return pendingToolResultIds;
|
|
20500
|
+
}
|
|
20501
|
+
function hasPendingToolResultPair(message, pendingToolResultIds) {
|
|
20502
|
+
if (pendingToolResultIds.size === 0) return false;
|
|
20503
|
+
const parts = message.content?.parts;
|
|
20504
|
+
if (!parts || !Array.isArray(parts)) return false;
|
|
20505
|
+
return parts.some((part) => {
|
|
20506
|
+
const id = getToolInvocationId(part, "call");
|
|
20507
|
+
return id !== void 0 && pendingToolResultIds.has(id);
|
|
20508
|
+
});
|
|
20509
|
+
}
|
|
20510
|
+
function collectPendingToolResultIdsAfterMarker(allMessages, markerMessageIndex, markerMessage) {
|
|
20511
|
+
const pendingToolResultIds = /* @__PURE__ */ new Set();
|
|
20512
|
+
const unobservedMarkerParts = getUnobservedParts(markerMessage);
|
|
20513
|
+
if (unobservedMarkerParts.length > 0) collectPendingToolResultIds([{
|
|
20514
|
+
...markerMessage,
|
|
20515
|
+
content: {
|
|
20516
|
+
...markerMessage.content,
|
|
20517
|
+
parts: unobservedMarkerParts
|
|
20518
|
+
}
|
|
20519
|
+
}], void 0).forEach((id) => pendingToolResultIds.add(id));
|
|
20520
|
+
collectPendingToolResultIds(allMessages.slice(markerMessageIndex + 1), void 0).forEach((id) => pendingToolResultIds.add(id));
|
|
20521
|
+
return pendingToolResultIds;
|
|
20522
|
+
}
|
|
20523
|
+
function getUnobservedPartsPreservingToolCallPairs(message) {
|
|
20524
|
+
const parts = message.content?.parts;
|
|
20525
|
+
if (!parts || !Array.isArray(parts)) return [];
|
|
20526
|
+
const endMarkerIndex = findLastCompletedObservationBoundary(message);
|
|
20527
|
+
if (endMarkerIndex === -1) return getUnobservedParts(message);
|
|
20528
|
+
const unobservedParts = getUnobservedParts(message);
|
|
20529
|
+
const unobservedResultIds = /* @__PURE__ */ new Set();
|
|
20530
|
+
for (const part of unobservedParts) {
|
|
20531
|
+
const id = getToolInvocationId(part, "result");
|
|
20532
|
+
if (id) unobservedResultIds.add(id);
|
|
20533
|
+
}
|
|
20534
|
+
if (unobservedResultIds.size === 0) return unobservedParts;
|
|
20535
|
+
const preservedCalls = parts.slice(0, endMarkerIndex).filter((part) => {
|
|
20536
|
+
const id = getToolInvocationId(part, "call");
|
|
20537
|
+
return id !== void 0 && unobservedResultIds.has(id);
|
|
20538
|
+
});
|
|
20539
|
+
return preservedCalls.length > 0 ? [...preservedCalls, ...unobservedParts] : unobservedParts;
|
|
20540
|
+
}
|
|
20541
|
+
/**
|
|
20442
20542
|
* Safely extract buffered observation chunks from a record.
|
|
20443
20543
|
* Handles both array and JSON-string formats, returning empty array if malformed.
|
|
20444
20544
|
*/
|
|
@@ -20454,6 +20554,7 @@ function filterObservedMessages(opts) {
|
|
|
20454
20554
|
const allMessages = messageList.get.all.db();
|
|
20455
20555
|
const useMarkerBoundaryPruning = opts.useMarkerBoundaryPruning ?? true;
|
|
20456
20556
|
const preserveMessageIds = opts.preserveMessageIds ?? /* @__PURE__ */ new Set();
|
|
20557
|
+
const observedIds = new Set(Array.isArray(record?.observedMessageIds) ? record.observedMessageIds : []);
|
|
20457
20558
|
let markerMessageIndex = -1;
|
|
20458
20559
|
let markerMessage = null;
|
|
20459
20560
|
for (let i = allMessages.length - 1; i >= 0; i--) {
|
|
@@ -20466,33 +20567,40 @@ function filterObservedMessages(opts) {
|
|
|
20466
20567
|
}
|
|
20467
20568
|
}
|
|
20468
20569
|
if (useMarkerBoundaryPruning && markerMessage && markerMessageIndex !== -1) {
|
|
20570
|
+
const pendingToolResultIds = collectPendingToolResultIdsAfterMarker(allMessages, markerMessageIndex, markerMessage);
|
|
20469
20571
|
const messagesToRemove = [];
|
|
20470
20572
|
for (let i = 0; i < markerMessageIndex; i++) {
|
|
20471
20573
|
const msg = allMessages[i];
|
|
20472
|
-
if (msg?.id && msg.id !== "om-continuation" && !preserveMessageIds.has(msg.id)) messagesToRemove.push(msg.id);
|
|
20574
|
+
if (msg?.id && msg.id !== "om-continuation" && !preserveMessageIds.has(msg.id) && !hasPendingToolResultPair(msg, pendingToolResultIds)) messagesToRemove.push(msg.id);
|
|
20473
20575
|
}
|
|
20474
20576
|
if (messagesToRemove.length > 0) messageList.removeByIds(messagesToRemove);
|
|
20475
|
-
const unobserved =
|
|
20577
|
+
const unobserved = getUnobservedPartsPreservingToolCallPairs(markerMessage);
|
|
20476
20578
|
if (unobserved.length === 0) {
|
|
20477
20579
|
if (markerMessage.id) messageList.removeByIds([markerMessage.id]);
|
|
20478
20580
|
} else if (unobserved.length < (markerMessage.content?.parts?.length ?? 0)) markerMessage.content.parts = unobserved;
|
|
20479
20581
|
} else if (record) {
|
|
20480
|
-
const
|
|
20582
|
+
const pendingToolResultIds = collectPendingToolResultIds(allMessages, observedIds);
|
|
20481
20583
|
const derivedCursor = opts.fallbackCursor ?? getLastObservedMessageCursor(allMessages.filter((msg) => !!msg?.id && observedIds.has(msg.id) && !!msg.createdAt));
|
|
20482
20584
|
const lastObservedAt = record.lastObservedAt;
|
|
20483
20585
|
const messagesToRemove = [];
|
|
20484
20586
|
for (const msg of allMessages) {
|
|
20485
20587
|
if (!msg?.id || msg.id === "om-continuation" || preserveMessageIds.has(msg.id)) continue;
|
|
20588
|
+
const hasPendingPair = hasPendingToolResultPair(msg, pendingToolResultIds);
|
|
20486
20589
|
if (observedIds.has(msg.id)) {
|
|
20590
|
+
if (hasPendingPair) continue;
|
|
20487
20591
|
messagesToRemove.push(msg.id);
|
|
20488
20592
|
continue;
|
|
20489
20593
|
}
|
|
20490
20594
|
if (derivedCursor && isMessageAtOrBeforeCursor(msg, derivedCursor)) {
|
|
20595
|
+
if (hasPendingPair) continue;
|
|
20491
20596
|
messagesToRemove.push(msg.id);
|
|
20492
20597
|
continue;
|
|
20493
20598
|
}
|
|
20494
20599
|
if (lastObservedAt && msg.createdAt) {
|
|
20495
|
-
if (new Date(msg.createdAt) <= lastObservedAt)
|
|
20600
|
+
if (new Date(msg.createdAt) <= lastObservedAt) {
|
|
20601
|
+
if (hasPendingPair) continue;
|
|
20602
|
+
messagesToRemove.push(msg.id);
|
|
20603
|
+
}
|
|
20496
20604
|
}
|
|
20497
20605
|
}
|
|
20498
20606
|
if (messagesToRemove.length > 0) messageList.removeByIds(messagesToRemove);
|
|
@@ -23798,6 +23906,14 @@ var ObservationalMemory = class ObservationalMemory {
|
|
|
23798
23906
|
*/
|
|
23799
23907
|
locks = /* @__PURE__ */ new Map();
|
|
23800
23908
|
/**
|
|
23909
|
+
* Initial record lookup/creation promises keyed by the effective storage scope.
|
|
23910
|
+
* Concurrent callers share the full read-or-create operation so a stale read
|
|
23911
|
+
* cannot create another generation-zero record after the first insert finishes.
|
|
23912
|
+
* Entries are removed after both success and failure so later calls always
|
|
23913
|
+
* re-read storage and transient failures can be retried.
|
|
23914
|
+
*/
|
|
23915
|
+
recordInitializations = /* @__PURE__ */ new Map();
|
|
23916
|
+
/**
|
|
23801
23917
|
* Acquire a lock for the given key, execute the callback, then release.
|
|
23802
23918
|
* If a lock is already held, waits for it to be released before acquiring.
|
|
23803
23919
|
*/
|
|
@@ -24158,10 +24274,14 @@ var ObservationalMemory = class ObservationalMemory {
|
|
|
24158
24274
|
*/
|
|
24159
24275
|
async getOrCreateRecord(threadId, resourceId) {
|
|
24160
24276
|
const ids = this.getStorageIds(threadId, resourceId);
|
|
24161
|
-
|
|
24162
|
-
|
|
24277
|
+
const initializationKey = ids.threadId === null ? `resource:${ids.resourceId}` : `thread:${ids.threadId}`;
|
|
24278
|
+
const pendingInitialization = this.recordInitializations.get(initializationKey);
|
|
24279
|
+
if (pendingInitialization) return pendingInitialization;
|
|
24280
|
+
const initialization = Promise.resolve().then(async () => {
|
|
24281
|
+
const record = await this.storage.getObservationalMemory(ids.threadId, ids.resourceId);
|
|
24282
|
+
if (record) return record;
|
|
24163
24283
|
const observedTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
24164
|
-
|
|
24284
|
+
return this.storage.initializeObservationalMemory({
|
|
24165
24285
|
threadId: ids.threadId,
|
|
24166
24286
|
resourceId: ids.resourceId,
|
|
24167
24287
|
scope: this.scope,
|
|
@@ -24172,8 +24292,13 @@ var ObservationalMemory = class ObservationalMemory {
|
|
|
24172
24292
|
},
|
|
24173
24293
|
observedTimezone
|
|
24174
24294
|
});
|
|
24295
|
+
});
|
|
24296
|
+
this.recordInitializations.set(initializationKey, initialization);
|
|
24297
|
+
try {
|
|
24298
|
+
return await initialization;
|
|
24299
|
+
} finally {
|
|
24300
|
+
if (this.recordInitializations.get(initializationKey) === initialization) this.recordInitializations.delete(initializationKey);
|
|
24175
24301
|
}
|
|
24176
|
-
return record;
|
|
24177
24302
|
}
|
|
24178
24303
|
/**
|
|
24179
24304
|
* Get current config snapshot for observation markers.
|
|
@@ -26541,6 +26666,11 @@ function filterSystemReminderMessages(messages, includeSystemReminders) {
|
|
|
26541
26666
|
if (includeSystemReminders) return messages;
|
|
26542
26667
|
return messages.filter((message) => !isSystemReminderMessage(message));
|
|
26543
26668
|
}
|
|
26669
|
+
function isTransientSignalMessage(message) {
|
|
26670
|
+
if (message.role !== "signal" || !isRecord(message.content)) return false;
|
|
26671
|
+
const metadata = message.content.metadata;
|
|
26672
|
+
return isRecord(metadata) && isRecord(metadata.signal) && !Array.isArray(metadata.signal) && metadata.signal.transient === true;
|
|
26673
|
+
}
|
|
26544
26674
|
function normalizeObservationalMemoryConfig(config) {
|
|
26545
26675
|
if (config === true) return { model: "google/gemini-2.5-flash" };
|
|
26546
26676
|
if (config === false || config === void 0) return void 0;
|
|
@@ -27074,7 +27204,7 @@ ${workingMemory}`;
|
|
|
27074
27204
|
async saveMessages({ messages, memoryConfig, observabilityContext }) {
|
|
27075
27205
|
const span = this.createMemorySpan("save", observabilityContext, void 0, { messageCount: messages.length });
|
|
27076
27206
|
try {
|
|
27077
|
-
const updatedMessages = messages.filter((m) => m.role !== "system").map((m) => {
|
|
27207
|
+
const updatedMessages = messages.filter((m) => m.role !== "system" && !isTransientSignalMessage(m)).map((m) => {
|
|
27078
27208
|
return this.updateMessageToHideWorkingMemoryV2(m);
|
|
27079
27209
|
}).filter((m) => Boolean(m));
|
|
27080
27210
|
const config = this.getMergedThreadConfig(memoryConfig);
|
|
@@ -27366,7 +27496,7 @@ ${workingMemory}`;
|
|
|
27366
27496
|
*/
|
|
27367
27497
|
async persistMessages(messages) {
|
|
27368
27498
|
if (messages.length === 0) return;
|
|
27369
|
-
const persistableMessages = messages.filter((m) => m.role !== "system");
|
|
27499
|
+
const persistableMessages = messages.filter((m) => m.role !== "system" && !isTransientSignalMessage(m));
|
|
27370
27500
|
if (persistableMessages.length === 0) return;
|
|
27371
27501
|
await (await this.getMemoryStore()).saveMessages({ messages: persistableMessages });
|
|
27372
27502
|
}
|
|
@@ -28313,4 +28443,4 @@ Notes:
|
|
|
28313
28443
|
//#endregion
|
|
28314
28444
|
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
28445
|
|
|
28316
|
-
//# sourceMappingURL=src-
|
|
28446
|
+
//# sourceMappingURL=src-Cwt9gefz.js.map
|