@mastra/memory 1.41.0 → 1.41.1-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/docs/SKILL.md +3 -4
- package/dist/docs/assets/SOURCE_MAP.json +225 -191
- package/dist/docs/references/docs-harness-background-tasks.md +2 -1
- package/dist/docs/references/docs-harness-goals.md +1 -1
- package/dist/docs/references/docs-knowledge-overview.md +106 -0
- package/dist/docs/references/docs-memory-observational-memory.md +23 -23
- package/dist/docs/references/docs-memory-overview.md +19 -7
- package/dist/docs/references/docs-memory-semantic-recall.md +24 -1
- package/dist/docs/references/integrations-channels-github.md +63 -24
- package/dist/docs/references/integrations-databases-postgresql.md +46 -0
- package/dist/docs/references/reference-core-getMemory.md +2 -2
- package/dist/docs/references/reference-core-listMemory.md +3 -3
- package/dist/docs/references/reference-memory-memory-class.md +1 -1
- package/dist/docs/references/reference-memory-observational-memory.md +9 -7
- package/dist/docs/references/reference-processors-token-limiter-processor.md +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +26 -8
- 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/processor.d.ts.map +1 -1
- package/dist/{src-BncFunCW.js → src-BL6KZcyR.js} +309 -399
- package/dist/src-BL6KZcyR.js.map +1 -0
- package/dist/{src-gNoNdZv8.cjs → src-Bo9Kpfk_.cjs} +308 -398
- package/dist/src-Bo9Kpfk_.cjs.map +1 -0
- package/package.json +4 -4
- package/dist/docs/references/reference-migrations-agentnetwork.md +0 -102
- package/dist/docs/references/reference-migrations-upgrade-to-v1-memory.md +0 -290
- package/dist/src-BncFunCW.js.map +0 -1
- package/dist/src-gNoNdZv8.cjs.map +0 -1
|
@@ -3710,7 +3710,7 @@ function trimStartOfStream() {
|
|
|
3710
3710
|
return text2;
|
|
3711
3711
|
};
|
|
3712
3712
|
}
|
|
3713
|
-
// ../_vendored/ai_v5/dist/dist-
|
|
3713
|
+
// ../_vendored/ai_v5/dist/dist-BYnbJEqC.js
|
|
3714
3714
|
var marker$1$16 = "vercel.ai.error";
|
|
3715
3715
|
var symbol$1$17 = Symbol.for(marker$1$16);
|
|
3716
3716
|
var _a$1$2;
|
|
@@ -4271,7 +4271,7 @@ function withUserAgentSuffix$2(headers, ...userAgentSuffixParts) {
|
|
|
4271
4271
|
normalizedHeaders.set("user-agent", [currentUserAgentHeader, ...userAgentSuffixParts].filter(Boolean).join(" "));
|
|
4272
4272
|
return Object.fromEntries(normalizedHeaders.entries());
|
|
4273
4273
|
}
|
|
4274
|
-
var VERSION$8 = "3.0.
|
|
4274
|
+
var VERSION$8 = "3.0.44";
|
|
4275
4275
|
var getOriginalFetch$3 = () => globalThis.fetch;
|
|
4276
4276
|
var getFromApi$2 = async ({ url, headers = {}, successfulResponseHandler, failedResponseHandler, abortSignal, fetch = getOriginalFetch$3() }) => {
|
|
4277
4277
|
try {
|
|
@@ -5695,10 +5695,24 @@ function asSchema$2(schema) {
|
|
|
5695
5695
|
}) : isSchema$2(schema) ? schema : typeof schema === "function" ? schema() : zodSchema$2(schema);
|
|
5696
5696
|
}
|
|
5697
5697
|
var { btoa: btoa$3, atob: atob$6 } = globalThis;
|
|
5698
|
+
var typedArrayTag$2 = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Uint8Array.prototype), Symbol.toStringTag).get;
|
|
5699
|
+
var arrayBufferByteLength$2 = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "byteLength").get;
|
|
5700
|
+
function isUint8Array$2(value) {
|
|
5701
|
+
return ArrayBuffer.isView(value) && typedArrayTag$2.call(value) === "Uint8Array";
|
|
5702
|
+
}
|
|
5703
|
+
function isArrayBuffer$2(value) {
|
|
5704
|
+
if (typeof value !== "object" || value === null || !("byteLength" in value)) return false;
|
|
5705
|
+
try {
|
|
5706
|
+
arrayBufferByteLength$2.call(value);
|
|
5707
|
+
return true;
|
|
5708
|
+
} catch (e) {
|
|
5709
|
+
return false;
|
|
5710
|
+
}
|
|
5711
|
+
}
|
|
5698
5712
|
function withoutTrailingSlash$2(url) {
|
|
5699
5713
|
return url == null ? void 0 : url.replace(/\/$/, "");
|
|
5700
5714
|
}
|
|
5701
|
-
// ../_vendored/ai_v5/dist/dist-
|
|
5715
|
+
// ../_vendored/ai_v5/dist/dist-oTd7Lp_i.js
|
|
5702
5716
|
function getContext$2() {
|
|
5703
5717
|
return { headers: {} };
|
|
5704
5718
|
}
|
|
@@ -6034,6 +6048,7 @@ function isTimeoutError$2(error) {
|
|
|
6034
6048
|
}
|
|
6035
6049
|
async function asGatewayError$2(error, authMethod) {
|
|
6036
6050
|
var _a10;
|
|
6051
|
+
if ((error instanceof Error || typeof DOMException === "function" && error instanceof DOMException) && (error.name === "AbortError" || error.name === "TimeoutError")) throw error;
|
|
6037
6052
|
if (GatewayError$2.isInstance(error)) return error;
|
|
6038
6053
|
if (isTimeoutError$2(error)) return GatewayTimeoutError$2.createTimeoutError({
|
|
6039
6054
|
originalMessage: error instanceof Error ? error.message : "Unknown error",
|
|
@@ -6677,7 +6692,7 @@ async function getVercelRequestId$2() {
|
|
|
6677
6692
|
var _a10;
|
|
6678
6693
|
return (_a10 = getContext$2().headers) == null ? void 0 : _a10["x-vercel-id"];
|
|
6679
6694
|
}
|
|
6680
|
-
var VERSION$7 = "2.0.
|
|
6695
|
+
var VERSION$7 = "2.0.176";
|
|
6681
6696
|
var AI_GATEWAY_PROTOCOL_VERSION$2 = "0.0.1";
|
|
6682
6697
|
function createGatewayProvider$1(options = {}) {
|
|
6683
6698
|
var _a10, _b10;
|
|
@@ -7712,11 +7727,11 @@ function getGlobalProvider$2() {
|
|
|
7712
7727
|
var _a17;
|
|
7713
7728
|
return (_a17 = globalThis.AI_SDK_DEFAULT_PROVIDER) != null ? _a17 : gateway$2;
|
|
7714
7729
|
}
|
|
7715
|
-
var VERSION$6 = "5.0.
|
|
7730
|
+
var VERSION$6 = "5.0.285";
|
|
7716
7731
|
var dataContentSchema$1 = zod_v4.z.union([
|
|
7717
7732
|
zod_v4.z.string(),
|
|
7718
|
-
zod_v4.z.
|
|
7719
|
-
zod_v4.z.
|
|
7733
|
+
zod_v4.z.custom(isUint8Array$2, { message: "Must be a Uint8Array" }),
|
|
7734
|
+
zod_v4.z.custom(isArrayBuffer$2, { message: "Must be an ArrayBuffer" }),
|
|
7720
7735
|
zod_v4.z.custom((value) => {
|
|
7721
7736
|
var _a17, _b;
|
|
7722
7737
|
return (_b = (_a17 = globalThis.Buffer) == null ? void 0 : _a17.isBuffer(value)) != null ? _b : false;
|
|
@@ -8618,7 +8633,7 @@ var object$3 = ({ schema: inputSchema }) => {
|
|
|
8618
8633
|
}
|
|
8619
8634
|
};
|
|
8620
8635
|
};
|
|
8621
|
-
// ../_vendored/ai_v6/dist/dist-
|
|
8636
|
+
// ../_vendored/ai_v6/dist/dist-DwNW4Hp7.js
|
|
8622
8637
|
var marker$1$14 = "vercel.ai.error";
|
|
8623
8638
|
var symbol$1$15 = Symbol.for(marker$1$14);
|
|
8624
8639
|
var _a$1$1;
|
|
@@ -9022,6 +9037,20 @@ function convertUint8ArrayToBase64$1(array) {
|
|
|
9022
9037
|
for (let i = 0; i < array.length; i += chunkSize) chunks.push(String.fromCodePoint(...array.subarray(i, i + chunkSize)));
|
|
9023
9038
|
return btoa$2(chunks.join(""));
|
|
9024
9039
|
}
|
|
9040
|
+
var typedArrayTag$1 = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Uint8Array.prototype), Symbol.toStringTag).get;
|
|
9041
|
+
var arrayBufferByteLength$1 = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "byteLength").get;
|
|
9042
|
+
function isUint8Array$1(value) {
|
|
9043
|
+
return ArrayBuffer.isView(value) && typedArrayTag$1.call(value) === "Uint8Array";
|
|
9044
|
+
}
|
|
9045
|
+
function isArrayBuffer$1(value) {
|
|
9046
|
+
if (typeof value !== "object" || value === null || !("byteLength" in value)) return false;
|
|
9047
|
+
try {
|
|
9048
|
+
arrayBufferByteLength$1.call(value);
|
|
9049
|
+
return true;
|
|
9050
|
+
} catch (e) {
|
|
9051
|
+
return false;
|
|
9052
|
+
}
|
|
9053
|
+
}
|
|
9025
9054
|
async function cancelResponseBody$1(response) {
|
|
9026
9055
|
var _a2;
|
|
9027
9056
|
try {
|
|
@@ -9476,7 +9505,7 @@ function withUserAgentSuffix$1(headers, ...userAgentSuffixParts) {
|
|
|
9476
9505
|
normalizedHeaders.set("user-agent", [currentUserAgentHeader, ...userAgentSuffixParts].filter(Boolean).join(" "));
|
|
9477
9506
|
return Object.fromEntries(normalizedHeaders.entries());
|
|
9478
9507
|
}
|
|
9479
|
-
var VERSION$5 = "4.0.
|
|
9508
|
+
var VERSION$5 = "4.0.64";
|
|
9480
9509
|
var getOriginalFetch$1 = () => globalThis.fetch;
|
|
9481
9510
|
var getFromApi$1 = async ({ url, headers = {}, successfulResponseHandler, failedResponseHandler, abortSignal, fetch, validateUrl, credentialedOrigin, trustedOrigin }) => {
|
|
9482
9511
|
try {
|
|
@@ -10952,7 +10981,7 @@ var createJsonResponseHandler$1 = (responseSchema) => async ({ response, url, re
|
|
|
10952
10981
|
function withoutTrailingSlash$1(url) {
|
|
10953
10982
|
return url == null ? void 0 : url.replace(/\/$/, "");
|
|
10954
10983
|
}
|
|
10955
|
-
// ../_vendored/ai_v6/dist/dist-
|
|
10984
|
+
// ../_vendored/ai_v6/dist/dist-B9RoRXxy.js
|
|
10956
10985
|
function getContext$1() {
|
|
10957
10986
|
return { headers: {} };
|
|
10958
10987
|
}
|
|
@@ -11342,6 +11371,7 @@ function isTimeoutError$1(error) {
|
|
|
11342
11371
|
}
|
|
11343
11372
|
async function asGatewayError$1(error, authMethod) {
|
|
11344
11373
|
var _a11;
|
|
11374
|
+
if ((error instanceof Error || typeof DOMException === "function" && error instanceof DOMException) && (error.name === "AbortError" || error.name === "TimeoutError")) throw error;
|
|
11345
11375
|
if (GatewayError$1.isInstance(error)) return error;
|
|
11346
11376
|
if (isTimeoutError$1(error)) return GatewayTimeoutError$1.createTimeoutError({
|
|
11347
11377
|
originalMessage: error instanceof Error ? error.message : "Unknown error",
|
|
@@ -12402,6 +12432,54 @@ var browserbaseSearchToolFactory$1 = createProviderToolFactoryWithOutputSchema({
|
|
|
12402
12432
|
})])))
|
|
12403
12433
|
});
|
|
12404
12434
|
var browserbaseSearch$1 = (config = {}) => browserbaseSearchToolFactory$1(config);
|
|
12435
|
+
var gatewayToolErrorSchema$1 = () => zod.z.object({
|
|
12436
|
+
error: zod.z.enum([
|
|
12437
|
+
"api_error",
|
|
12438
|
+
"configuration_error",
|
|
12439
|
+
"execution_error",
|
|
12440
|
+
"gateway_rate_limit",
|
|
12441
|
+
"invalid_input",
|
|
12442
|
+
"rate_limit",
|
|
12443
|
+
"timeout",
|
|
12444
|
+
"unknown",
|
|
12445
|
+
"unknown_tool"
|
|
12446
|
+
]),
|
|
12447
|
+
message: zod.z.string(),
|
|
12448
|
+
statusCode: zod.z.number().optional(),
|
|
12449
|
+
retryAfter: zod.z.string().optional(),
|
|
12450
|
+
statusText: zod.z.string().optional()
|
|
12451
|
+
}).passthrough();
|
|
12452
|
+
var deepseekFetchToolFactory$1 = createProviderToolFactoryWithOutputSchema({
|
|
12453
|
+
id: "gateway.deepseek_fetch",
|
|
12454
|
+
inputSchema: lazySchema$1(() => zodSchema$1(zod.z.object({ url: zod.z.string().describe("URL to fetch, at most 8192 characters; HTTP(S) only, without a username or password.") }))),
|
|
12455
|
+
outputSchema: lazySchema$1(() => zodSchema$1(zod.z.union([zod.z.object({
|
|
12456
|
+
title: zod.z.string().nullish(),
|
|
12457
|
+
content: zod.z.string()
|
|
12458
|
+
}).passthrough(), gatewayToolErrorSchema$1()])))
|
|
12459
|
+
});
|
|
12460
|
+
var deepseekFetch$1 = (config = {}) => deepseekFetchToolFactory$1(config);
|
|
12461
|
+
var deepseekSearchToolFactory$1 = createProviderToolFactoryWithOutputSchema({
|
|
12462
|
+
id: "gateway.deepseek_search",
|
|
12463
|
+
inputSchema: lazySchema$1(() => zodSchema$1(zod.z.object({
|
|
12464
|
+
query: zod.z.string().describe("Web search query, 1 to 128 Unicode characters. Supports site:, -site:, lang:, after:, before:, and quoted phrases."),
|
|
12465
|
+
count: zod.z.number().int().optional().describe("Number of results, 1 to 50 (default: 10)."),
|
|
12466
|
+
need_content: zod.z.boolean().optional().describe("Include available page content (default: false)."),
|
|
12467
|
+
ori_question: zod.z.string().nullable().optional().describe("Original user question, 1 to 128 Unicode characters.")
|
|
12468
|
+
}))),
|
|
12469
|
+
outputSchema: lazySchema$1(() => zodSchema$1(zod.z.union([zod.z.object({ results: zod.z.array(zod.z.object({
|
|
12470
|
+
authority: zod.z.number().nullish(),
|
|
12471
|
+
content: zod.z.string().nullish(),
|
|
12472
|
+
date: zod.z.string().nullish(),
|
|
12473
|
+
rerank_score: zod.z.number().nullish(),
|
|
12474
|
+
site_icon: zod.z.string().nullish(),
|
|
12475
|
+
site_name: zod.z.string().nullish(),
|
|
12476
|
+
snippet: zod.z.string().nullish(),
|
|
12477
|
+
summary: zod.z.string().nullish(),
|
|
12478
|
+
title: zod.z.string().nullish(),
|
|
12479
|
+
url: zod.z.string().nullish()
|
|
12480
|
+
}).passthrough()) }).passthrough(), gatewayToolErrorSchema$1()])))
|
|
12481
|
+
});
|
|
12482
|
+
var deepseekSearch$1 = (config = {}) => deepseekSearchToolFactory$1(config);
|
|
12405
12483
|
var exaSearchToolFactory$1 = createProviderToolFactoryWithOutputSchema({
|
|
12406
12484
|
id: "gateway.exa_search",
|
|
12407
12485
|
inputSchema: lazySchema$1(() => zodSchema$1(zod.z.object({
|
|
@@ -12558,21 +12636,7 @@ var parallelSearchToolFactory$1 = createProviderToolFactoryWithOutputSchema({
|
|
|
12558
12636
|
count: zod.z.number().optional()
|
|
12559
12637
|
})).nullable().optional(),
|
|
12560
12638
|
session_id: zod.z.string().optional()
|
|
12561
|
-
}),
|
|
12562
|
-
error: zod.z.enum([
|
|
12563
|
-
"api_error",
|
|
12564
|
-
"configuration_error",
|
|
12565
|
-
"execution_error",
|
|
12566
|
-
"gateway_rate_limit",
|
|
12567
|
-
"invalid_input",
|
|
12568
|
-
"rate_limit",
|
|
12569
|
-
"timeout",
|
|
12570
|
-
"unknown",
|
|
12571
|
-
"unknown_tool"
|
|
12572
|
-
]),
|
|
12573
|
-
statusCode: zod.z.number().optional(),
|
|
12574
|
-
message: zod.z.string()
|
|
12575
|
-
})])))
|
|
12639
|
+
}), gatewayToolErrorSchema$1()])))
|
|
12576
12640
|
});
|
|
12577
12641
|
var parallelSearch$1 = (config = {}) => parallelSearchToolFactory$1(config);
|
|
12578
12642
|
var perplexitySearchToolFactory$1 = createProviderToolFactoryWithOutputSchema({
|
|
@@ -12803,19 +12867,7 @@ var takoSearchToolFactory$1 = createProviderToolFactoryWithOutputSchema({
|
|
|
12803
12867
|
}).nullish()
|
|
12804
12868
|
}).nullish(),
|
|
12805
12869
|
related: zod.z.array(zod.z.object({}).passthrough()).nullish()
|
|
12806
|
-
}).passthrough(),
|
|
12807
|
-
error: zod.z.enum([
|
|
12808
|
-
"api_error",
|
|
12809
|
-
"configuration_error",
|
|
12810
|
-
"execution_error",
|
|
12811
|
-
"invalid_input",
|
|
12812
|
-
"rate_limit",
|
|
12813
|
-
"timeout",
|
|
12814
|
-
"unknown_tool"
|
|
12815
|
-
]),
|
|
12816
|
-
statusCode: zod.z.number().optional(),
|
|
12817
|
-
message: zod.z.string()
|
|
12818
|
-
})])))
|
|
12870
|
+
}).passthrough(), gatewayToolErrorSchema$1()])))
|
|
12819
12871
|
});
|
|
12820
12872
|
var takoSearch$1 = (config = {}) => takoSearchToolFactory$1(config);
|
|
12821
12873
|
var gatewayTools$1 = {
|
|
@@ -12834,6 +12886,16 @@ var gatewayTools$1 = {
|
|
|
12834
12886
|
*/
|
|
12835
12887
|
browserbaseSearch: browserbaseSearch$1,
|
|
12836
12888
|
/**
|
|
12889
|
+
* Fetch a page as Markdown through DeepSeek's standalone Fetch API.
|
|
12890
|
+
* Executed by AI Gateway for any model, separate from native model web search.
|
|
12891
|
+
*/
|
|
12892
|
+
deepseekFetch: deepseekFetch$1,
|
|
12893
|
+
/**
|
|
12894
|
+
* Search the web through DeepSeek's standalone Search API.
|
|
12895
|
+
* Executed by AI Gateway for any model, separate from native model web search.
|
|
12896
|
+
*/
|
|
12897
|
+
deepseekSearch: deepseekSearch$1,
|
|
12898
|
+
/**
|
|
12837
12899
|
* Search the web using Exa for current information and token-efficient
|
|
12838
12900
|
* excerpts optimized for agent workflows.
|
|
12839
12901
|
*
|
|
@@ -12872,7 +12934,7 @@ async function getVercelRequestId$1() {
|
|
|
12872
12934
|
var _a11;
|
|
12873
12935
|
return (_a11 = getContext$1().headers) == null ? void 0 : _a11["x-vercel-id"];
|
|
12874
12936
|
}
|
|
12875
|
-
var VERSION$4 = "3.0.
|
|
12937
|
+
var VERSION$4 = "3.0.228";
|
|
12876
12938
|
var AI_GATEWAY_PROTOCOL_VERSION$1 = "0.0.1";
|
|
12877
12939
|
function createGatewayProvider(options = {}) {
|
|
12878
12940
|
var _a11, _b11;
|
|
@@ -14048,11 +14110,11 @@ function getTotalTimeoutMs(timeout) {
|
|
|
14048
14110
|
if (typeof timeout === "number") return timeout;
|
|
14049
14111
|
return timeout.totalMs;
|
|
14050
14112
|
}
|
|
14051
|
-
var VERSION$3 = "6.0.
|
|
14113
|
+
var VERSION$3 = "6.0.322";
|
|
14052
14114
|
var dataContentSchema = zod_v4.z.union([
|
|
14053
14115
|
zod_v4.z.string(),
|
|
14054
|
-
zod_v4.z.
|
|
14055
|
-
zod_v4.z.
|
|
14116
|
+
zod_v4.z.custom(isUint8Array$1, { message: "Must be a Uint8Array" }),
|
|
14117
|
+
zod_v4.z.custom(isArrayBuffer$1, { message: "Must be an ArrayBuffer" }),
|
|
14056
14118
|
zod_v4.z.custom((value) => {
|
|
14057
14119
|
var _a23, _b;
|
|
14058
14120
|
return (_b = (_a23 = globalThis.Buffer) == null ? void 0 : _a23.isBuffer(value)) != null ? _b : false;
|
|
@@ -15244,7 +15306,7 @@ createIdGenerator$1({
|
|
|
15244
15306
|
prefix: "aiobj",
|
|
15245
15307
|
size: 24
|
|
15246
15308
|
});
|
|
15247
|
-
// ../_vendored/ai_v7/dist/dist-
|
|
15309
|
+
// ../_vendored/ai_v7/dist/dist-CwN1TMYk.js
|
|
15248
15310
|
/**
|
|
15249
15311
|
* Symbol used for identifying AI SDK Error instances.
|
|
15250
15312
|
* Enables checking if an error is an instance of AISDKError across package versions.
|
|
@@ -15843,7 +15905,9 @@ const { btoa: btoa$1, atob: atob$2 } = globalThis;
|
|
|
15843
15905
|
function convertBase64ToUint8Array(base64String) {
|
|
15844
15906
|
const base64Url = base64String.replace(/-/g, "+").replace(/_/g, "/");
|
|
15845
15907
|
const latin1string = atob$2(base64Url);
|
|
15846
|
-
|
|
15908
|
+
const bytes = new Uint8Array(latin1string.length);
|
|
15909
|
+
for (let i = 0; i < latin1string.length; i++) bytes[i] = latin1string.charCodeAt(i);
|
|
15910
|
+
return bytes;
|
|
15847
15911
|
}
|
|
15848
15912
|
function convertUint8ArrayToBase64(array) {
|
|
15849
15913
|
if (typeof globalThis.Buffer?.from === "function") return globalThis.Buffer.from(array.buffer, array.byteOffset, array.byteLength).toString("base64");
|
|
@@ -15852,6 +15916,20 @@ function convertUint8ArrayToBase64(array) {
|
|
|
15852
15916
|
for (let i = 0; i < array.length; i += chunkSize) chunks.push(String.fromCodePoint(...array.subarray(i, i + chunkSize)));
|
|
15853
15917
|
return btoa$1(chunks.join(""));
|
|
15854
15918
|
}
|
|
15919
|
+
const typedArrayTag = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Uint8Array.prototype), Symbol.toStringTag).get;
|
|
15920
|
+
const arrayBufferByteLength = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "byteLength").get;
|
|
15921
|
+
function isUint8Array(value) {
|
|
15922
|
+
return ArrayBuffer.isView(value) && typedArrayTag.call(value) === "Uint8Array";
|
|
15923
|
+
}
|
|
15924
|
+
function isArrayBuffer(value) {
|
|
15925
|
+
if (typeof value !== "object" || value === null || !("byteLength" in value)) return false;
|
|
15926
|
+
try {
|
|
15927
|
+
arrayBufferByteLength.call(value);
|
|
15928
|
+
return true;
|
|
15929
|
+
} catch {
|
|
15930
|
+
return false;
|
|
15931
|
+
}
|
|
15932
|
+
}
|
|
15855
15933
|
/**
|
|
15856
15934
|
* Extracts the headers from a response object and returns them as a key-value object.
|
|
15857
15935
|
*
|
|
@@ -15929,7 +16007,7 @@ function handleFetchError({ error, url, requestBodyValues }) {
|
|
|
15929
16007
|
}
|
|
15930
16008
|
return error;
|
|
15931
16009
|
}
|
|
15932
|
-
const VERSION$2 = "5.0.
|
|
16010
|
+
const VERSION$2 = "5.0.74";
|
|
15933
16011
|
/**
|
|
15934
16012
|
* Normalizes different header inputs into a plain record with lower-case keys.
|
|
15935
16013
|
* Entries with `undefined` or `null` values are removed.
|
|
@@ -18420,7 +18498,7 @@ function isSegment(value) {
|
|
|
18420
18498
|
function withoutTrailingSlash(url) {
|
|
18421
18499
|
return url?.replace(/\/$/, "");
|
|
18422
18500
|
}
|
|
18423
|
-
// ../_vendored/ai_v7/dist/dist-
|
|
18501
|
+
// ../_vendored/ai_v7/dist/dist-D6YcYEgU.js
|
|
18424
18502
|
/**
|
|
18425
18503
|
* Symbol used to define custom serialization for user-defined class instances.
|
|
18426
18504
|
* The static method should accept an instance and return serializable data.
|
|
@@ -21125,6 +21203,54 @@ const browserbaseSearchToolFactory = createProviderExecutedToolFactory({
|
|
|
21125
21203
|
})])))
|
|
21126
21204
|
});
|
|
21127
21205
|
const browserbaseSearch = (config = {}) => browserbaseSearchToolFactory(config);
|
|
21206
|
+
const gatewayToolErrorSchema = () => z$5.object({
|
|
21207
|
+
error: z$5.enum([
|
|
21208
|
+
"api_error",
|
|
21209
|
+
"configuration_error",
|
|
21210
|
+
"execution_error",
|
|
21211
|
+
"gateway_rate_limit",
|
|
21212
|
+
"invalid_input",
|
|
21213
|
+
"rate_limit",
|
|
21214
|
+
"timeout",
|
|
21215
|
+
"unknown",
|
|
21216
|
+
"unknown_tool"
|
|
21217
|
+
]),
|
|
21218
|
+
message: z$5.string(),
|
|
21219
|
+
statusCode: z$5.number().optional(),
|
|
21220
|
+
retryAfter: z$5.string().optional(),
|
|
21221
|
+
statusText: z$5.string().optional()
|
|
21222
|
+
}).passthrough();
|
|
21223
|
+
const deepseekFetchToolFactory = createProviderExecutedToolFactory({
|
|
21224
|
+
id: "gateway.deepseek_fetch",
|
|
21225
|
+
inputSchema: lazySchema(() => zodSchema(z$5.object({ url: z$5.string().describe("URL to fetch, at most 8192 characters; HTTP(S) only, without a username or password.") }))),
|
|
21226
|
+
outputSchema: lazySchema(() => zodSchema(z$5.union([z$5.object({
|
|
21227
|
+
title: z$5.string().nullish(),
|
|
21228
|
+
content: z$5.string()
|
|
21229
|
+
}).passthrough(), gatewayToolErrorSchema()])))
|
|
21230
|
+
});
|
|
21231
|
+
const deepseekFetch = (config = {}) => deepseekFetchToolFactory(config);
|
|
21232
|
+
const deepseekSearchToolFactory = createProviderExecutedToolFactory({
|
|
21233
|
+
id: "gateway.deepseek_search",
|
|
21234
|
+
inputSchema: lazySchema(() => zodSchema(z$5.object({
|
|
21235
|
+
query: z$5.string().describe("Web search query, 1 to 128 Unicode characters. Supports site:, -site:, lang:, after:, before:, and quoted phrases."),
|
|
21236
|
+
count: z$5.number().int().optional().describe("Number of results, 1 to 50 (default: 10)."),
|
|
21237
|
+
need_content: z$5.boolean().optional().describe("Include available page content (default: false)."),
|
|
21238
|
+
ori_question: z$5.string().nullable().optional().describe("Original user question, 1 to 128 Unicode characters.")
|
|
21239
|
+
}))),
|
|
21240
|
+
outputSchema: lazySchema(() => zodSchema(z$5.union([z$5.object({ results: z$5.array(z$5.object({
|
|
21241
|
+
authority: z$5.number().nullish(),
|
|
21242
|
+
content: z$5.string().nullish(),
|
|
21243
|
+
date: z$5.string().nullish(),
|
|
21244
|
+
rerank_score: z$5.number().nullish(),
|
|
21245
|
+
site_icon: z$5.string().nullish(),
|
|
21246
|
+
site_name: z$5.string().nullish(),
|
|
21247
|
+
snippet: z$5.string().nullish(),
|
|
21248
|
+
summary: z$5.string().nullish(),
|
|
21249
|
+
title: z$5.string().nullish(),
|
|
21250
|
+
url: z$5.string().nullish()
|
|
21251
|
+
}).passthrough()) }).passthrough(), gatewayToolErrorSchema()])))
|
|
21252
|
+
});
|
|
21253
|
+
const deepseekSearch = (config = {}) => deepseekSearchToolFactory(config);
|
|
21128
21254
|
const exaSearchToolFactory = createProviderExecutedToolFactory({
|
|
21129
21255
|
id: "gateway.exa_search",
|
|
21130
21256
|
inputSchema: lazySchema(() => zodSchema(z$5.object({
|
|
@@ -21281,21 +21407,7 @@ const parallelSearchToolFactory = createProviderExecutedToolFactory({
|
|
|
21281
21407
|
count: z$5.number().optional()
|
|
21282
21408
|
})).nullable().optional(),
|
|
21283
21409
|
session_id: z$5.string().optional()
|
|
21284
|
-
}),
|
|
21285
|
-
error: z$5.enum([
|
|
21286
|
-
"api_error",
|
|
21287
|
-
"configuration_error",
|
|
21288
|
-
"execution_error",
|
|
21289
|
-
"gateway_rate_limit",
|
|
21290
|
-
"invalid_input",
|
|
21291
|
-
"rate_limit",
|
|
21292
|
-
"timeout",
|
|
21293
|
-
"unknown",
|
|
21294
|
-
"unknown_tool"
|
|
21295
|
-
]),
|
|
21296
|
-
statusCode: z$5.number().optional(),
|
|
21297
|
-
message: z$5.string()
|
|
21298
|
-
})])))
|
|
21410
|
+
}), gatewayToolErrorSchema()])))
|
|
21299
21411
|
});
|
|
21300
21412
|
const parallelSearch = (config = {}) => parallelSearchToolFactory(config);
|
|
21301
21413
|
const perplexitySearchToolFactory = createProviderExecutedToolFactory({
|
|
@@ -21526,19 +21638,7 @@ const takoSearchToolFactory = createProviderExecutedToolFactory({
|
|
|
21526
21638
|
}).nullish()
|
|
21527
21639
|
}).nullish(),
|
|
21528
21640
|
related: z$5.array(z$5.object({}).passthrough()).nullish()
|
|
21529
|
-
}).passthrough(),
|
|
21530
|
-
error: z$5.enum([
|
|
21531
|
-
"api_error",
|
|
21532
|
-
"configuration_error",
|
|
21533
|
-
"execution_error",
|
|
21534
|
-
"invalid_input",
|
|
21535
|
-
"rate_limit",
|
|
21536
|
-
"timeout",
|
|
21537
|
-
"unknown_tool"
|
|
21538
|
-
]),
|
|
21539
|
-
statusCode: z$5.number().optional(),
|
|
21540
|
-
message: z$5.string()
|
|
21541
|
-
})])))
|
|
21641
|
+
}).passthrough(), gatewayToolErrorSchema()])))
|
|
21542
21642
|
});
|
|
21543
21643
|
const takoSearch = (config = {}) => takoSearchToolFactory(config);
|
|
21544
21644
|
/**
|
|
@@ -21560,6 +21660,16 @@ const gatewayTools = {
|
|
|
21560
21660
|
*/
|
|
21561
21661
|
browserbaseSearch,
|
|
21562
21662
|
/**
|
|
21663
|
+
* Fetch a page as Markdown through DeepSeek's standalone Fetch API.
|
|
21664
|
+
* Executed by AI Gateway for any model, separate from native model web search.
|
|
21665
|
+
*/
|
|
21666
|
+
deepseekFetch,
|
|
21667
|
+
/**
|
|
21668
|
+
* Search the web through DeepSeek's standalone Search API.
|
|
21669
|
+
* Executed by AI Gateway for any model, separate from native model web search.
|
|
21670
|
+
*/
|
|
21671
|
+
deepseekSearch,
|
|
21672
|
+
/**
|
|
21563
21673
|
* Search the web using Exa for current information and token-efficient
|
|
21564
21674
|
* excerpts optimized for agent workflows.
|
|
21565
21675
|
*
|
|
@@ -21597,7 +21707,7 @@ const gatewayTools = {
|
|
|
21597
21707
|
async function getVercelRequestId() {
|
|
21598
21708
|
return getContext().headers?.["x-vercel-id"];
|
|
21599
21709
|
}
|
|
21600
|
-
const VERSION$1 = "4.0.
|
|
21710
|
+
const VERSION$1 = "4.0.135";
|
|
21601
21711
|
const AI_GATEWAY_PROTOCOL_VERSION = "0.0.1";
|
|
21602
21712
|
/** Response shape of `POST /v1/realtime/client-secrets`. `expiresAt` is epoch seconds. */
|
|
21603
21713
|
const gatewayClientSecretResponseSchema = lazySchema(() => zodSchema(z$5.object({
|
|
@@ -22405,7 +22515,7 @@ function resolveEmbeddingModel(model) {
|
|
|
22405
22515
|
function getGlobalProvider() {
|
|
22406
22516
|
return asProviderV4(globalThis.AI_SDK_DEFAULT_PROVIDER ?? gateway);
|
|
22407
22517
|
}
|
|
22408
|
-
const VERSION = "7.0.
|
|
22518
|
+
const VERSION = "7.0.162";
|
|
22409
22519
|
/**
|
|
22410
22520
|
* Reads a property by an untrusted key, ignoring inherited prototype members.
|
|
22411
22521
|
*
|
|
@@ -23275,8 +23385,8 @@ createIdGenerator({
|
|
|
23275
23385
|
});
|
|
23276
23386
|
const fileInlineDataSchema = z$4.union([
|
|
23277
23387
|
z$4.string(),
|
|
23278
|
-
z$4.
|
|
23279
|
-
z$4.
|
|
23388
|
+
z$4.custom(isUint8Array, { message: "Must be a Uint8Array" }),
|
|
23389
|
+
z$4.custom(isArrayBuffer, { message: "Must be an ArrayBuffer" }),
|
|
23280
23390
|
z$4.custom(isBuffer, { message: "Must be a Buffer" })
|
|
23281
23391
|
]);
|
|
23282
23392
|
const providerReferenceSchema = z$4.record(z$4.string(), z$4.string());
|
|
@@ -23579,15 +23689,7 @@ createIdGenerator({
|
|
|
23579
23689
|
size: 24
|
|
23580
23690
|
});
|
|
23581
23691
|
// src/processors/observational-memory/constants.ts
|
|
23582
|
-
var constants_exports = /* @__PURE__ */ __exportAll({
|
|
23583
|
-
OBSERVATIONAL_MEMORY_DEFAULTS: () => OBSERVATIONAL_MEMORY_DEFAULTS,
|
|
23584
|
-
OBSERVATION_CONTEXT_INSTRUCTIONS: () => OBSERVATION_CONTEXT_INSTRUCTIONS,
|
|
23585
|
-
OBSERVATION_CONTEXT_PROMPT: () => OBSERVATION_CONTEXT_PROMPT,
|
|
23586
|
-
OBSERVATION_CONTEXT_PROMPT_THREAD: () => OBSERVATION_CONTEXT_PROMPT_THREAD,
|
|
23587
|
-
OBSERVATION_CONTINUATION_HINT: () => OBSERVATION_CONTINUATION_HINT,
|
|
23588
|
-
getObservationContextPrompt: () => getObservationContextPrompt,
|
|
23589
|
-
getRetrievalInstructions: () => getRetrievalInstructions
|
|
23590
|
-
});
|
|
23692
|
+
var constants_exports = /* @__PURE__ */ __exportAll({ OBSERVATION_CONTINUATION_HINT: () => OBSERVATION_CONTINUATION_HINT });
|
|
23591
23693
|
/**
|
|
23592
23694
|
* Default configuration values matching the spec
|
|
23593
23695
|
*/
|
|
@@ -39757,7 +39859,8 @@ var ObservationalMemoryProcessor = class {
|
|
|
39757
39859
|
ctx = await step.prepare();
|
|
39758
39860
|
} catch (error) {
|
|
39759
39861
|
const err = error instanceof Error ? error : new Error(String(error));
|
|
39760
|
-
const
|
|
39862
|
+
const abortReason = abortSignal?.reason;
|
|
39863
|
+
const abortMessage = abortSignal?.aborted ? abortReason instanceof Error && abortReason.name !== "AbortError" ? `Agent execution was aborted: ${abortReason.message}` : "Agent execution was aborted" : `Encountered error during memory observation: ${err.message}`;
|
|
39761
39864
|
const failedTurn = this.turn;
|
|
39762
39865
|
await failedTurn.end().catch(() => {});
|
|
39763
39866
|
if (this.turn === failedTurn) this.turn = void 0;
|
|
@@ -39919,44 +40022,11 @@ function getObservationsAsOf(activeObservations, asOf) {
|
|
|
39919
40022
|
}
|
|
39920
40023
|
// src/processors/observational-memory/index.ts
|
|
39921
40024
|
var observational_memory_exports = /* @__PURE__ */ __exportAll({
|
|
39922
|
-
AUTO_MODEL_BY_PROVIDER: () => AUTO_MODEL_BY_PROVIDER,
|
|
39923
|
-
Extractor: () => Extractor,
|
|
39924
|
-
ModelByInputTokens: () => ModelByInputTokens,
|
|
39925
|
-
OBSERVATIONAL_MEMORY_DEFAULTS: () => OBSERVATIONAL_MEMORY_DEFAULTS,
|
|
39926
|
-
OBSERVATION_CONTEXT_INSTRUCTIONS: () => OBSERVATION_CONTEXT_INSTRUCTIONS,
|
|
39927
|
-
OBSERVATION_CONTEXT_PROMPT: () => OBSERVATION_CONTEXT_PROMPT,
|
|
39928
|
-
OBSERVATION_CONTEXT_PROMPT_THREAD: () => OBSERVATION_CONTEXT_PROMPT_THREAD,
|
|
39929
|
-
OBSERVATION_CONTINUATION_HINT: () => OBSERVATION_CONTINUATION_HINT,
|
|
39930
|
-
OBSERVER_SYSTEM_PROMPT: () => OBSERVER_SYSTEM_PROMPT,
|
|
39931
40025
|
ObservationalMemory: () => ObservationalMemory,
|
|
39932
|
-
ObservationalMemoryProcessor: () => ObservationalMemoryProcessor
|
|
39933
|
-
TokenCounter: () => TokenCounter,
|
|
39934
|
-
WorkingMemoryExtractor: () => WorkingMemoryExtractor,
|
|
39935
|
-
buildObserverPrompt: () => buildObserverPrompt,
|
|
39936
|
-
buildObserverSystemPrompt: () => buildObserverSystemPrompt,
|
|
39937
|
-
combineObservationGroupRanges: () => combineObservationGroupRanges,
|
|
39938
|
-
deriveObservationGroupProvenance: () => deriveObservationGroupProvenance,
|
|
39939
|
-
extractCurrentTask: () => extractCurrentTask,
|
|
39940
|
-
formatMessagesForObserver: () => formatMessagesForObserver,
|
|
39941
|
-
getObservationContextPrompt: () => getObservationContextPrompt,
|
|
39942
|
-
getObservationsAsOf: () => getObservationsAsOf,
|
|
39943
|
-
hasCurrentTaskSection: () => hasCurrentTaskSection,
|
|
39944
|
-
injectAnchorIds: () => injectAnchorIds,
|
|
39945
|
-
optimizeObservationsForContext: () => optimizeObservationsForContext,
|
|
39946
|
-
parseAnchorId: () => parseAnchorId,
|
|
39947
|
-
parseObservationGroups: () => parseObservationGroups,
|
|
39948
|
-
parseObserverOutput: () => parseObserverOutput,
|
|
39949
|
-
reconcileObservationGroupsFromReflection: () => reconcileObservationGroupsFromReflection,
|
|
39950
|
-
renderObservationGroupsForReflection: () => renderObservationGroupsForReflection,
|
|
39951
|
-
resolveAutoModelId: () => resolveAutoModelId,
|
|
39952
|
-
stripEphemeralAnchorIds: () => stripEphemeralAnchorIds,
|
|
39953
|
-
stripObservationGroups: () => stripObservationGroups,
|
|
39954
|
-
summarizeConversation: () => summarizeConversation,
|
|
39955
|
-
wrapInObservationGroup: () => wrapInObservationGroup
|
|
40026
|
+
ObservationalMemoryProcessor: () => ObservationalMemoryProcessor
|
|
39956
40027
|
});
|
|
39957
40028
|
// src/processors/working-memory-state/index.ts
|
|
39958
40029
|
var working_memory_state_exports = /* @__PURE__ */ __exportAll({
|
|
39959
|
-
WORKING_MEMORY_STATE_ID: () => WORKING_MEMORY_STATE_ID,
|
|
39960
40030
|
WORKING_MEMORY_STATE_PROCESSOR_ID: () => WORKING_MEMORY_STATE_PROCESSOR_ID,
|
|
39961
40031
|
WorkingMemoryStateProcessor: () => WorkingMemoryStateProcessor
|
|
39962
40032
|
});
|
|
@@ -40099,7 +40169,6 @@ function normalizeObservationalMemoryConfig(config) {
|
|
|
40099
40169
|
function hasWorkingMemoryExtractor(extractors) {
|
|
40100
40170
|
return !!extractors?.some((extractor) => extractor.slug === "working-memory");
|
|
40101
40171
|
}
|
|
40102
|
-
const CHARS_PER_TOKEN = 4;
|
|
40103
40172
|
const DEFAULT_MESSAGE_RANGE = {
|
|
40104
40173
|
before: 1,
|
|
40105
40174
|
after: 1
|
|
@@ -40242,6 +40311,7 @@ var Memory = class Memory extends _mastra_core_memory.MastraMemory {
|
|
|
40242
40311
|
});
|
|
40243
40312
|
this.assertWorkingMemoryStateSignalsCompatibility(mergedConfig);
|
|
40244
40313
|
this.threadConfig = mergedConfig;
|
|
40314
|
+
(0, _mastra_core_memory.resolveMaxChunkChars)({ maxChunkChars: this.configuredMaxChunkChars });
|
|
40245
40315
|
const omConfig = normalizeObservationalMemoryConfig(mergedConfig.observationalMemory);
|
|
40246
40316
|
if (omConfig?.retrieval && typeof omConfig.retrieval === "object" && omConfig.retrieval.vector) {
|
|
40247
40317
|
if (!this.vector) throw new Error("`retrieval: { vector: true }` requires a vector store. Pass a `vector` option to your Memory instance.");
|
|
@@ -40757,28 +40827,9 @@ ${workingMemory}`;
|
|
|
40757
40827
|
release();
|
|
40758
40828
|
}
|
|
40759
40829
|
}
|
|
40830
|
+
/** Splits text into chunks of at most `tokenSize` English tokens, measured as characters. */
|
|
40760
40831
|
chunkText(text, tokenSize = 4096) {
|
|
40761
|
-
|
|
40762
|
-
const chunks = [];
|
|
40763
|
-
let currentChunk = "";
|
|
40764
|
-
const words = text.split(/\s+/);
|
|
40765
|
-
for (const word of words) {
|
|
40766
|
-
if (word.length > charSize) {
|
|
40767
|
-
if (currentChunk) {
|
|
40768
|
-
chunks.push(currentChunk);
|
|
40769
|
-
currentChunk = "";
|
|
40770
|
-
}
|
|
40771
|
-
for (let i = 0; i < word.length; i += charSize) chunks.push(word.slice(i, i + charSize));
|
|
40772
|
-
continue;
|
|
40773
|
-
}
|
|
40774
|
-
const wordWithSpace = currentChunk ? " " + word : word;
|
|
40775
|
-
if (currentChunk.length + wordWithSpace.length > charSize) {
|
|
40776
|
-
if (currentChunk) chunks.push(currentChunk);
|
|
40777
|
-
currentChunk = word;
|
|
40778
|
-
} else currentChunk += wordWithSpace;
|
|
40779
|
-
}
|
|
40780
|
-
if (currentChunk) chunks.push(currentChunk);
|
|
40781
|
-
return chunks;
|
|
40832
|
+
return (0, _mastra_core_memory.chunkMessageText)(text, tokenSize * _mastra_core_memory.MESSAGE_EMBEDDING_CHARS_PER_TOKEN);
|
|
40782
40833
|
}
|
|
40783
40834
|
hasher = (0, xxhash_wasm.default)();
|
|
40784
40835
|
embeddingCache = new lru_cache.LRUCache({ max: DEFAULT_EMBEDDING_CACHE_MAX_SIZE });
|
|
@@ -40794,11 +40845,23 @@ ${workingMemory}`;
|
|
|
40794
40845
|
return cached;
|
|
40795
40846
|
}
|
|
40796
40847
|
const chunks = this.chunkText(content);
|
|
40848
|
+
const { embeddings, usage } = await this.embedValues(chunks);
|
|
40849
|
+
const result = {
|
|
40850
|
+
embeddings,
|
|
40851
|
+
chunks,
|
|
40852
|
+
usage,
|
|
40853
|
+
dimension: embeddings[0]?.length
|
|
40854
|
+
};
|
|
40855
|
+
this.embeddingCache.set(key, result);
|
|
40856
|
+
return result;
|
|
40857
|
+
}
|
|
40858
|
+
/** Sends texts to the embedder through the AI SDK version that matches its spec. */
|
|
40859
|
+
async embedValues(values) {
|
|
40797
40860
|
if (typeof this.embedder === `undefined`) throw new Error(`Tried to embed message content but this Memory instance doesn't have an attached embedder.`);
|
|
40798
40861
|
const isFastEmbed = this.embedder.provider === `fastembed`;
|
|
40799
40862
|
if (isFastEmbed && this.firstEmbed instanceof Promise) await this.firstEmbed;
|
|
40800
40863
|
const options = {
|
|
40801
|
-
values
|
|
40864
|
+
values,
|
|
40802
40865
|
maxRetries: 3
|
|
40803
40866
|
};
|
|
40804
40867
|
const model = this.embedder;
|
|
@@ -40833,106 +40896,87 @@ ${workingMemory}`;
|
|
|
40833
40896
|
}
|
|
40834
40897
|
if (isFastEmbed && !this.firstEmbed) this.firstEmbed = promise;
|
|
40835
40898
|
const { embeddings, usage } = await promise;
|
|
40836
|
-
|
|
40899
|
+
return {
|
|
40837
40900
|
embeddings,
|
|
40838
|
-
|
|
40839
|
-
usage,
|
|
40840
|
-
dimension: embeddings[0]?.length
|
|
40901
|
+
usage
|
|
40841
40902
|
};
|
|
40842
|
-
this.embeddingCache.set(key, result);
|
|
40843
|
-
return result;
|
|
40844
40903
|
}
|
|
40845
|
-
|
|
40904
|
+
/**
|
|
40905
|
+
* Metadata of each thread, spread onto that thread's vector rows so `semanticRecall.filter`
|
|
40906
|
+
* can match thread attributes.
|
|
40907
|
+
*/
|
|
40908
|
+
async loadThreadMetadata(threadIds) {
|
|
40909
|
+
const memoryStore = await this.getMemoryStore();
|
|
40910
|
+
const metadataByThread = /* @__PURE__ */ new Map();
|
|
40911
|
+
await Promise.all(threadIds.map(async (threadId) => {
|
|
40912
|
+
try {
|
|
40913
|
+
const thread = await memoryStore.getThreadById({ threadId });
|
|
40914
|
+
if (thread?.metadata) metadataByThread.set(threadId, thread.metadata);
|
|
40915
|
+
} catch (error) {
|
|
40916
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
40917
|
+
throw new Error(`Could not fetch metadata for thread ${threadId} while writing semantic recall embeddings: ${message}`);
|
|
40918
|
+
}
|
|
40919
|
+
}));
|
|
40920
|
+
return metadataByThread;
|
|
40921
|
+
}
|
|
40922
|
+
/**
|
|
40923
|
+
* Embeds messages into vector rows in the shared format, without writing them. Every
|
|
40924
|
+
* message-vector write in this class builds its rows here.
|
|
40925
|
+
*/
|
|
40926
|
+
async buildMessageVectorRows({ items, embeddedMessages }) {
|
|
40927
|
+
if (items.length === 0) return {
|
|
40928
|
+
ids: [],
|
|
40929
|
+
metadata: [],
|
|
40930
|
+
embeddedEntries: []
|
|
40931
|
+
};
|
|
40932
|
+
if (!this.embedder && !this.isSelfEmbedding) throw new Error(`Tried to embed message content but this Memory instance doesn't have an attached embedder.`);
|
|
40933
|
+
return (0, _mastra_core_memory.buildMessageEmbeddingRows)({
|
|
40934
|
+
items,
|
|
40935
|
+
embed: this.isSelfEmbedding ? void 0 : (chunks) => this.embedValues(chunks),
|
|
40936
|
+
maxChunkChars: (0, _mastra_core_memory.resolveMaxChunkChars)({
|
|
40937
|
+
maxChunkChars: this.configuredMaxChunkChars,
|
|
40938
|
+
embedder: this.embedder
|
|
40939
|
+
}),
|
|
40940
|
+
loadThreadMetadata: (threadIds) => this.loadThreadMetadata(threadIds),
|
|
40941
|
+
embeddedMessages,
|
|
40942
|
+
indexName: embeddedMessages ? this.getEmbeddingIndexName(this.isSelfEmbedding ? void 0 : await this.getEmbeddingDimension()) : void 0
|
|
40943
|
+
});
|
|
40944
|
+
}
|
|
40945
|
+
/** Writes rows from {@link buildMessageVectorRows} into the message index for `config`. */
|
|
40946
|
+
async writeMessageVectorRows({ rows, config, embeddedMessages }) {
|
|
40947
|
+
if (!this.vector || rows.ids.length === 0) return;
|
|
40948
|
+
const { indexName } = await this.createEmbeddingIndex(rows.dimension, config);
|
|
40949
|
+
await (0, _mastra_core_memory.upsertMessageVectors)(this.vector, indexName, rows, embeddedMessages);
|
|
40950
|
+
}
|
|
40951
|
+
/**
|
|
40952
|
+
* Embeds messages and writes their vector rows.
|
|
40953
|
+
*
|
|
40954
|
+
* @returns Tokens billed by the embedder, if any.
|
|
40955
|
+
*/
|
|
40956
|
+
async writeMessageVectors(args) {
|
|
40957
|
+
if (!this.vector) return void 0;
|
|
40958
|
+
const rows = await this.buildMessageVectorRows(args);
|
|
40959
|
+
await this.writeMessageVectorRows({
|
|
40960
|
+
...args,
|
|
40961
|
+
rows
|
|
40962
|
+
});
|
|
40963
|
+
return rows.usage;
|
|
40964
|
+
}
|
|
40965
|
+
async saveMessages({ messages, memoryConfig, observabilityContext, embeddedMessages }) {
|
|
40846
40966
|
const span = this.createMemorySpan("save", observabilityContext, void 0, { messageCount: messages.length });
|
|
40847
40967
|
try {
|
|
40848
40968
|
const updatedMessages = this.prepareMessagesForPersistence(messages);
|
|
40849
40969
|
const config = this.getMergedThreadConfig(memoryConfig);
|
|
40850
40970
|
const dbMessages = new _mastra_core_agent.MessageList({ generateMessageId: () => this.generateId() }).add(updatedMessages, "memory").get.all.db();
|
|
40851
|
-
const
|
|
40852
|
-
const
|
|
40853
|
-
|
|
40854
|
-
|
|
40855
|
-
|
|
40856
|
-
|
|
40857
|
-
if (message.threadId) {
|
|
40858
|
-
if (!messagesByThread.has(message.threadId)) messagesByThread.set(message.threadId, []);
|
|
40859
|
-
messagesByThread.get(message.threadId).push(message);
|
|
40860
|
-
}
|
|
40861
|
-
});
|
|
40862
|
-
const threadMetadataMap = /* @__PURE__ */ new Map();
|
|
40863
|
-
await Promise.all(Array.from(messagesByThread.keys()).map(async (threadId) => {
|
|
40864
|
-
try {
|
|
40865
|
-
const thread = await memoryStore.getThreadById({ threadId });
|
|
40866
|
-
if (thread?.metadata) threadMetadataMap.set(threadId, thread.metadata);
|
|
40867
|
-
} catch (error) {
|
|
40868
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
40869
|
-
throw new Error(`Could not fetch metadata for thread ${threadId} while saving semantic recall embeddings: ${message}`);
|
|
40870
|
-
}
|
|
40871
|
-
}));
|
|
40872
|
-
const embeddingData = [];
|
|
40873
|
-
let dimension;
|
|
40874
|
-
await Promise.all(updatedMessages.map(async (message) => {
|
|
40875
|
-
let textForEmbedding = null;
|
|
40876
|
-
if (message.content.content && typeof message.content.content === "string" && message.content.content.trim() !== "") textForEmbedding = message.content.content;
|
|
40877
|
-
else if (message.content.parts && message.content.parts.length > 0) {
|
|
40878
|
-
const joined = message.content.parts.filter((part) => part.type === "text").map((part) => part.text).join(" ").trim();
|
|
40879
|
-
if (joined) textForEmbedding = joined;
|
|
40880
|
-
}
|
|
40881
|
-
if (!textForEmbedding) return;
|
|
40882
|
-
let embeddings = [];
|
|
40883
|
-
let documents;
|
|
40884
|
-
let chunks;
|
|
40885
|
-
if (this.isSelfEmbedding) {
|
|
40886
|
-
chunks = this.chunkText(textForEmbedding);
|
|
40887
|
-
documents = chunks;
|
|
40888
|
-
} else {
|
|
40889
|
-
const result = await this.embedMessageContent(textForEmbedding);
|
|
40890
|
-
dimension = result.dimension;
|
|
40891
|
-
if (result.usage?.tokens) totalTokens += result.usage.tokens;
|
|
40892
|
-
embeddings = result.embeddings;
|
|
40893
|
-
chunks = result.chunks;
|
|
40894
|
-
}
|
|
40895
|
-
const threadMetadata = message.threadId ? threadMetadataMap.get(message.threadId) || {} : {};
|
|
40896
|
-
embeddingData.push({
|
|
40897
|
-
embeddings,
|
|
40898
|
-
documents,
|
|
40899
|
-
metadata: chunks.map(() => ({
|
|
40900
|
-
...threadMetadata,
|
|
40901
|
-
message_id: message.id,
|
|
40902
|
-
thread_id: message.threadId,
|
|
40903
|
-
resource_id: message.resourceId,
|
|
40904
|
-
role: message.role,
|
|
40905
|
-
content: textForEmbedding,
|
|
40906
|
-
created_at: message.createdAt instanceof Date ? message.createdAt.toISOString() : String(message.createdAt)
|
|
40907
|
-
}))
|
|
40908
|
-
});
|
|
40909
|
-
}));
|
|
40910
|
-
if (embeddingData.length > 0 && (this.isSelfEmbedding || dimension !== void 0)) {
|
|
40911
|
-
if (typeof this.vector === `undefined`) throw new Error(`Tried to upsert embeddings but this Memory instance doesn't have an attached vector db.`);
|
|
40912
|
-
const { indexName } = await this.createEmbeddingIndex(dimension, config);
|
|
40913
|
-
const allVectors = [];
|
|
40914
|
-
const allMetadata = [];
|
|
40915
|
-
const allDocuments = [];
|
|
40916
|
-
for (const data of embeddingData) {
|
|
40917
|
-
allVectors.push(...data.embeddings);
|
|
40918
|
-
if (data.documents) allDocuments.push(...data.documents);
|
|
40919
|
-
allMetadata.push(...data.metadata);
|
|
40920
|
-
}
|
|
40921
|
-
if (this.isSelfEmbedding) await this.vector.upsert({
|
|
40922
|
-
indexName,
|
|
40923
|
-
documents: allDocuments,
|
|
40924
|
-
metadata: allMetadata
|
|
40925
|
-
});
|
|
40926
|
-
else await this.vector.upsert({
|
|
40927
|
-
indexName,
|
|
40928
|
-
vectors: allVectors,
|
|
40929
|
-
metadata: allMetadata
|
|
40930
|
-
});
|
|
40931
|
-
}
|
|
40932
|
-
}
|
|
40971
|
+
const result = await (await this.getMemoryStore()).saveMessages({ messages: dbMessages });
|
|
40972
|
+
const usage = this.vector && config.semanticRecall ? await this.writeMessageVectors({
|
|
40973
|
+
items: updatedMessages.map((message) => ({ message })),
|
|
40974
|
+
config,
|
|
40975
|
+
embeddedMessages
|
|
40976
|
+
}) : void 0;
|
|
40933
40977
|
const saveResult = {
|
|
40934
40978
|
...result,
|
|
40935
|
-
usage
|
|
40979
|
+
usage
|
|
40936
40980
|
};
|
|
40937
40981
|
span?.end({
|
|
40938
40982
|
output: { success: true },
|
|
@@ -41655,51 +41699,6 @@ Notes:
|
|
|
41655
41699
|
return collected;
|
|
41656
41700
|
}
|
|
41657
41701
|
/**
|
|
41658
|
-
* Index a list of messages directly (without querying storage).
|
|
41659
|
-
* Used by observe-time indexing to vectorize newly-observed messages.
|
|
41660
|
-
*/
|
|
41661
|
-
async indexMessagesList(messages) {
|
|
41662
|
-
if (!this.vector || !this.embedder) return;
|
|
41663
|
-
const embeddingData = [];
|
|
41664
|
-
let dimension;
|
|
41665
|
-
await Promise.all(messages.map(async (message) => {
|
|
41666
|
-
let textForEmbedding = null;
|
|
41667
|
-
if (message.content.content && typeof message.content.content === "string" && message.content.content.trim() !== "") textForEmbedding = message.content.content;
|
|
41668
|
-
else if (message.content.parts && message.content.parts.length > 0) {
|
|
41669
|
-
const joined = message.content.parts.filter((part) => part.type === "text").map((part) => part.text).join(" ").trim();
|
|
41670
|
-
if (joined) textForEmbedding = joined;
|
|
41671
|
-
}
|
|
41672
|
-
if (!textForEmbedding) return;
|
|
41673
|
-
const embedResult = await this.embedMessageContent(textForEmbedding);
|
|
41674
|
-
dimension = embedResult.dimension;
|
|
41675
|
-
embeddingData.push({
|
|
41676
|
-
embeddings: embedResult.embeddings,
|
|
41677
|
-
metadata: embedResult.chunks.map(() => ({
|
|
41678
|
-
message_id: message.id,
|
|
41679
|
-
thread_id: message.threadId,
|
|
41680
|
-
resource_id: message.resourceId,
|
|
41681
|
-
role: message.role,
|
|
41682
|
-
content: textForEmbedding,
|
|
41683
|
-
created_at: message.createdAt instanceof Date ? message.createdAt.toISOString() : String(message.createdAt)
|
|
41684
|
-
}))
|
|
41685
|
-
});
|
|
41686
|
-
}));
|
|
41687
|
-
if (embeddingData.length > 0 && dimension !== void 0) {
|
|
41688
|
-
const { indexName } = await this.createEmbeddingIndex(dimension);
|
|
41689
|
-
const allVectors = [];
|
|
41690
|
-
const allMetadata = [];
|
|
41691
|
-
for (const data of embeddingData) {
|
|
41692
|
-
allVectors.push(...data.embeddings);
|
|
41693
|
-
allMetadata.push(...data.metadata);
|
|
41694
|
-
}
|
|
41695
|
-
await this.vector.upsert({
|
|
41696
|
-
indexName,
|
|
41697
|
-
vectors: allVectors,
|
|
41698
|
-
metadata: allMetadata
|
|
41699
|
-
});
|
|
41700
|
-
}
|
|
41701
|
-
}
|
|
41702
|
-
/**
|
|
41703
41702
|
* Check whether retrieval search (vector-based) is enabled.
|
|
41704
41703
|
* Returns true when `retrieval: { vector: true }` and Memory has a vector store plus either an
|
|
41705
41704
|
* embedder or a store that generates embeddings itself.
|
|
@@ -41805,43 +41804,19 @@ Notes:
|
|
|
41805
41804
|
const messagesWithTextUpdates = [...textForEmbeddingById.keys()].map((id) => ({ id }));
|
|
41806
41805
|
if (messagesWithTextUpdates.length > 0) {
|
|
41807
41806
|
const existingMessagesMap = new Map(existing.messages.map((m) => [m.id, m]));
|
|
41808
|
-
const
|
|
41809
|
-
|
|
41810
|
-
const
|
|
41811
|
-
|
|
41812
|
-
|
|
41813
|
-
|
|
41814
|
-
|
|
41815
|
-
|
|
41816
|
-
|
|
41817
|
-
|
|
41818
|
-
|
|
41819
|
-
|
|
41820
|
-
|
|
41821
|
-
chunks = this.chunkText(textForEmbedding);
|
|
41822
|
-
documents = chunks;
|
|
41823
|
-
} else {
|
|
41824
|
-
const result = await this.embedMessageContent(textForEmbedding);
|
|
41825
|
-
dimension = result.dimension;
|
|
41826
|
-
embeddings = result.embeddings;
|
|
41827
|
-
chunks = result.chunks;
|
|
41828
|
-
}
|
|
41829
|
-
embeddingData.push({
|
|
41830
|
-
embeddings,
|
|
41831
|
-
documents,
|
|
41832
|
-
metadata: chunks.map(() => ({
|
|
41833
|
-
message_id: message.id,
|
|
41834
|
-
thread_id: existingMessage.threadId,
|
|
41835
|
-
resource_id: existingMessage.resourceId,
|
|
41836
|
-
role: existingMessage.role,
|
|
41837
|
-
content: textForEmbedding,
|
|
41838
|
-
created_at: existingMessage.createdAt instanceof Date ? existingMessage.createdAt.toISOString() : String(existingMessage.createdAt)
|
|
41839
|
-
}))
|
|
41840
|
-
});
|
|
41841
|
-
messageIdsWithNewEmbeddings.add(message.id);
|
|
41842
|
-
} else messageIdsWithClearedContent.add(message.id);
|
|
41843
|
-
}));
|
|
41844
|
-
const messageIdsNeedingDeletion = /* @__PURE__ */ new Set([...messageIdsWithClearedContent, ...messageIdsWithNewEmbeddings]);
|
|
41807
|
+
const messageIdsNeedingDeletion = /* @__PURE__ */ new Set();
|
|
41808
|
+
const items = [];
|
|
41809
|
+
for (const { id } of messagesWithTextUpdates) {
|
|
41810
|
+
const existingMessage = existingMessagesMap.get(id);
|
|
41811
|
+
if (!existingMessage) continue;
|
|
41812
|
+
messageIdsNeedingDeletion.add(id);
|
|
41813
|
+
const text = textForEmbeddingById.get(id);
|
|
41814
|
+
if (text) items.push({
|
|
41815
|
+
message: existingMessage,
|
|
41816
|
+
text
|
|
41817
|
+
});
|
|
41818
|
+
}
|
|
41819
|
+
const rows = await this.buildMessageVectorRows({ items });
|
|
41845
41820
|
if (messageIdsNeedingDeletion.size > 0) try {
|
|
41846
41821
|
const memoryIndexes = await this.getMemoryVectorIndexes([this.messageIndexPrefix]);
|
|
41847
41822
|
const idsToDelete = [...messageIdsNeedingDeletion];
|
|
@@ -41864,27 +41839,10 @@ Notes:
|
|
|
41864
41839
|
} catch {
|
|
41865
41840
|
this.logger.debug("Failed to clean up old vectors during message update");
|
|
41866
41841
|
}
|
|
41867
|
-
|
|
41868
|
-
|
|
41869
|
-
|
|
41870
|
-
|
|
41871
|
-
const allDocuments = [];
|
|
41872
|
-
for (const data of embeddingData) {
|
|
41873
|
-
allVectors.push(...data.embeddings);
|
|
41874
|
-
if (data.documents) allDocuments.push(...data.documents);
|
|
41875
|
-
allMetadata.push(...data.metadata);
|
|
41876
|
-
}
|
|
41877
|
-
if (this.isSelfEmbedding) await this.vector.upsert({
|
|
41878
|
-
indexName,
|
|
41879
|
-
documents: allDocuments,
|
|
41880
|
-
metadata: allMetadata
|
|
41881
|
-
});
|
|
41882
|
-
else await this.vector.upsert({
|
|
41883
|
-
indexName,
|
|
41884
|
-
vectors: allVectors,
|
|
41885
|
-
metadata: allMetadata
|
|
41886
|
-
});
|
|
41887
|
-
}
|
|
41842
|
+
await this.writeMessageVectorRows({
|
|
41843
|
+
rows,
|
|
41844
|
+
config
|
|
41845
|
+
});
|
|
41888
41846
|
}
|
|
41889
41847
|
}
|
|
41890
41848
|
return memoryStore.updateMessages({ messages });
|
|
@@ -42149,6 +42107,7 @@ Notes:
|
|
|
42149
42107
|
threadId,
|
|
42150
42108
|
perPage: false
|
|
42151
42109
|
});
|
|
42110
|
+
const rows = await this.buildMessageVectorRows({ items: messages.map((message) => ({ message })) });
|
|
42152
42111
|
const messageIndexes = await this.getMemoryVectorIndexes([this.messageIndexPrefix]);
|
|
42153
42112
|
await Promise.all(messageIndexes.map(async (indexName) => {
|
|
42154
42113
|
await this.vector.deleteVectors({
|
|
@@ -42156,7 +42115,10 @@ Notes:
|
|
|
42156
42115
|
filter: { thread_id: threadId }
|
|
42157
42116
|
});
|
|
42158
42117
|
}));
|
|
42159
|
-
|
|
42118
|
+
await this.writeMessageVectorRows({
|
|
42119
|
+
rows,
|
|
42120
|
+
config
|
|
42121
|
+
});
|
|
42160
42122
|
} catch (error) {
|
|
42161
42123
|
this.logger.error("Failed to migrate semantic-recall vectors during thread transfer", {
|
|
42162
42124
|
threadId,
|
|
@@ -42304,67 +42266,15 @@ Notes:
|
|
|
42304
42266
|
return cloned;
|
|
42305
42267
|
}
|
|
42306
42268
|
/**
|
|
42307
|
-
* Embed cloned messages for semantic recall.
|
|
42308
|
-
*
|
|
42269
|
+
* Embed cloned messages for semantic recall. Cloned messages have new ids, so they get rows of
|
|
42270
|
+
* their own next to the source thread's rows.
|
|
42309
42271
|
*/
|
|
42310
42272
|
async embedClonedMessages(messages, config) {
|
|
42311
42273
|
if (!this.vector || !this.embedder && !this.isSelfEmbedding) return;
|
|
42312
|
-
|
|
42313
|
-
|
|
42314
|
-
|
|
42315
|
-
|
|
42316
|
-
if (message.content?.content && typeof message.content.content === "string" && message.content.content.trim() !== "") textForEmbedding = message.content.content;
|
|
42317
|
-
else if (message.content?.parts && message.content.parts.length > 0) {
|
|
42318
|
-
const joined = message.content.parts.filter((part) => part.type === "text").map((part) => part.text).join(" ").trim();
|
|
42319
|
-
if (joined) textForEmbedding = joined;
|
|
42320
|
-
}
|
|
42321
|
-
if (!textForEmbedding) return;
|
|
42322
|
-
let embeddings = [];
|
|
42323
|
-
let documents;
|
|
42324
|
-
let chunks;
|
|
42325
|
-
if (this.isSelfEmbedding) {
|
|
42326
|
-
chunks = this.chunkText(textForEmbedding);
|
|
42327
|
-
documents = chunks;
|
|
42328
|
-
} else {
|
|
42329
|
-
const result = await this.embedMessageContent(textForEmbedding);
|
|
42330
|
-
dimension = result.dimension;
|
|
42331
|
-
embeddings = result.embeddings;
|
|
42332
|
-
chunks = result.chunks;
|
|
42333
|
-
}
|
|
42334
|
-
embeddingData.push({
|
|
42335
|
-
embeddings,
|
|
42336
|
-
documents,
|
|
42337
|
-
metadata: chunks.map(() => ({
|
|
42338
|
-
message_id: message.id,
|
|
42339
|
-
thread_id: message.threadId,
|
|
42340
|
-
resource_id: message.resourceId,
|
|
42341
|
-
role: message.role,
|
|
42342
|
-
content: textForEmbedding,
|
|
42343
|
-
created_at: message.createdAt instanceof Date ? message.createdAt.toISOString() : String(message.createdAt)
|
|
42344
|
-
}))
|
|
42345
|
-
});
|
|
42346
|
-
}));
|
|
42347
|
-
if (embeddingData.length > 0 && (this.isSelfEmbedding || dimension !== void 0)) {
|
|
42348
|
-
const { indexName } = await this.createEmbeddingIndex(dimension, config);
|
|
42349
|
-
const allVectors = [];
|
|
42350
|
-
const allMetadata = [];
|
|
42351
|
-
const allDocuments = [];
|
|
42352
|
-
for (const data of embeddingData) {
|
|
42353
|
-
allVectors.push(...data.embeddings);
|
|
42354
|
-
if (data.documents) allDocuments.push(...data.documents);
|
|
42355
|
-
allMetadata.push(...data.metadata);
|
|
42356
|
-
}
|
|
42357
|
-
if (this.isSelfEmbedding) await this.vector.upsert({
|
|
42358
|
-
indexName,
|
|
42359
|
-
documents: allDocuments,
|
|
42360
|
-
metadata: allMetadata
|
|
42361
|
-
});
|
|
42362
|
-
else await this.vector.upsert({
|
|
42363
|
-
indexName,
|
|
42364
|
-
vectors: allVectors,
|
|
42365
|
-
metadata: allMetadata
|
|
42366
|
-
});
|
|
42367
|
-
}
|
|
42274
|
+
await this.writeMessageVectors({
|
|
42275
|
+
items: messages.map((message) => ({ message })),
|
|
42276
|
+
config
|
|
42277
|
+
});
|
|
42368
42278
|
}
|
|
42369
42279
|
/**
|
|
42370
42280
|
* Get the clone metadata from a thread if it was cloned from another thread.
|
|
@@ -42823,4 +42733,4 @@ Object.defineProperty(exports, "wrapInObservationGroup", {
|
|
|
42823
42733
|
}
|
|
42824
42734
|
});
|
|
42825
42735
|
|
|
42826
|
-
//# sourceMappingURL=src-
|
|
42736
|
+
//# sourceMappingURL=src-Bo9Kpfk_.cjs.map
|