@mastra/server 1.9.0 → 1.10.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 +32 -0
- package/dist/{chunk-YMHD5QN4.cjs → chunk-4IA52F5N.cjs} +6 -6
- package/dist/{chunk-YMHD5QN4.cjs.map → chunk-4IA52F5N.cjs.map} +1 -1
- package/dist/{chunk-IXA4YZMV.js → chunk-4WMV5R64.js} +59 -11
- package/dist/chunk-4WMV5R64.js.map +1 -0
- package/dist/{chunk-ICZV5UXL.js → chunk-7Z23EFVZ.js} +248 -59
- package/dist/chunk-7Z23EFVZ.js.map +1 -0
- package/dist/{chunk-NZGPG5ZI.js → chunk-AC5X66E2.js} +3 -3
- package/dist/{chunk-NZGPG5ZI.js.map → chunk-AC5X66E2.js.map} +1 -1
- package/dist/{chunk-AAZLFKSD.js → chunk-B5GSYU7J.js} +9 -2
- package/dist/chunk-B5GSYU7J.js.map +1 -0
- package/dist/{chunk-4DEUEWUP.cjs → chunk-BF34CMII.cjs} +5 -5
- package/dist/{chunk-4DEUEWUP.cjs.map → chunk-BF34CMII.cjs.map} +1 -1
- package/dist/{chunk-QVQKUSBW.cjs → chunk-BZO7NV5A.cjs} +6 -6
- package/dist/{chunk-QVQKUSBW.cjs.map → chunk-BZO7NV5A.cjs.map} +1 -1
- package/dist/{chunk-EGWACN4Q.cjs → chunk-CARPBU5W.cjs} +9 -2
- package/dist/chunk-CARPBU5W.cjs.map +1 -0
- package/dist/{chunk-TXC7QU6O.cjs → chunk-E5I4COAV.cjs} +248 -59
- package/dist/chunk-E5I4COAV.cjs.map +1 -0
- package/dist/{chunk-HLFFDNMA.js → chunk-G4F3KPUR.js} +3 -3
- package/dist/{chunk-HLFFDNMA.js.map → chunk-G4F3KPUR.js.map} +1 -1
- package/dist/{chunk-P6HZ2B4Z.cjs → chunk-MHB5LKA4.cjs} +4 -4
- package/dist/{chunk-P6HZ2B4Z.cjs.map → chunk-MHB5LKA4.cjs.map} +1 -1
- package/dist/{chunk-QUZKXCTG.js → chunk-QITXZQID.js} +3 -3
- package/dist/{chunk-QUZKXCTG.js.map → chunk-QITXZQID.js.map} +1 -1
- package/dist/{chunk-PKBWZ2N5.js → chunk-QJ7ZMX7Y.js} +3 -3
- package/dist/{chunk-PKBWZ2N5.js.map → chunk-QJ7ZMX7Y.js.map} +1 -1
- package/dist/{chunk-OMLZSETB.cjs → chunk-TVJYM7U2.cjs} +59 -11
- package/dist/chunk-TVJYM7U2.cjs.map +1 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/reference-server-create-route.md +14 -14
- package/dist/docs/references/reference-server-mastra-server.md +10 -10
- package/dist/{observational-memory-SR6G4HN5-G66HNVG4.cjs → observational-memory-QFQUF5EY-5VPKVXKI.cjs} +653 -532
- package/dist/observational-memory-QFQUF5EY-5VPKVXKI.cjs.map +1 -0
- package/dist/{observational-memory-SR6G4HN5-PSFX73LD.js → observational-memory-QFQUF5EY-GQK2OWVA.js} +653 -532
- package/dist/observational-memory-QFQUF5EY-GQK2OWVA.js.map +1 -0
- package/dist/server/handlers/a2a.cjs +9 -9
- package/dist/server/handlers/a2a.js +1 -1
- package/dist/server/handlers/agent-builder.cjs +16 -16
- package/dist/server/handlers/agent-builder.js +1 -1
- package/dist/server/handlers/agents.cjs +33 -33
- package/dist/server/handlers/agents.d.ts +3 -2
- package/dist/server/handlers/agents.d.ts.map +1 -1
- package/dist/server/handlers/agents.js +1 -1
- package/dist/server/handlers/auth.cjs +9 -9
- package/dist/server/handlers/auth.d.ts.map +1 -1
- package/dist/server/handlers/auth.js +1 -1
- package/dist/server/handlers/mcp.d.ts +1 -1
- package/dist/server/handlers/scores.cjs +7 -7
- package/dist/server/handlers/scores.js +1 -1
- package/dist/server/handlers/tools.cjs +6 -6
- package/dist/server/handlers/tools.js +1 -1
- package/dist/server/handlers/voice.cjs +8 -8
- package/dist/server/handlers/voice.js +1 -1
- package/dist/server/handlers.cjs +12 -12
- package/dist/server/handlers.js +6 -6
- package/dist/server/schemas/mcp.d.ts +2 -2
- package/dist/server/server-adapter/index.cjs +66 -66
- package/dist/server/server-adapter/index.js +7 -7
- package/package.json +6 -6
- package/dist/chunk-AAZLFKSD.js.map +0 -1
- package/dist/chunk-EGWACN4Q.cjs.map +0 -1
- package/dist/chunk-ICZV5UXL.js.map +0 -1
- package/dist/chunk-IXA4YZMV.js.map +0 -1
- package/dist/chunk-OMLZSETB.cjs.map +0 -1
- package/dist/chunk-TXC7QU6O.cjs.map +0 -1
- package/dist/observational-memory-SR6G4HN5-G66HNVG4.cjs.map +0 -1
- package/dist/observational-memory-SR6G4HN5-PSFX73LD.js.map +0 -1
|
@@ -22496,7 +22496,7 @@ function withUserAgentSuffix2(headers, ...userAgentSuffixParts) {
|
|
|
22496
22496
|
);
|
|
22497
22497
|
return Object.fromEntries(normalizedHeaders.entries());
|
|
22498
22498
|
}
|
|
22499
|
-
var VERSION4 = "4.0.
|
|
22499
|
+
var VERSION4 = "4.0.19";
|
|
22500
22500
|
var getOriginalFetch3 = () => globalThis.fetch;
|
|
22501
22501
|
var getFromApi2 = async ({
|
|
22502
22502
|
url,
|
|
@@ -22581,8 +22581,8 @@ function loadOptionalSetting2({
|
|
|
22581
22581
|
}
|
|
22582
22582
|
return settingValue;
|
|
22583
22583
|
}
|
|
22584
|
-
var suspectProtoRx2 = /"
|
|
22585
|
-
var suspectConstructorRx2 = /"
|
|
22584
|
+
var suspectProtoRx2 = /"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/;
|
|
22585
|
+
var suspectConstructorRx2 = /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;
|
|
22586
22586
|
function _parse2(text42) {
|
|
22587
22587
|
const obj = JSON.parse(text42);
|
|
22588
22588
|
if (obj === null || typeof obj !== "object") {
|
|
@@ -22602,7 +22602,7 @@ function filter2(obj) {
|
|
|
22602
22602
|
if (Object.prototype.hasOwnProperty.call(node, "__proto__")) {
|
|
22603
22603
|
throw new SyntaxError("Object contains forbidden prototype property");
|
|
22604
22604
|
}
|
|
22605
|
-
if (Object.prototype.hasOwnProperty.call(node, "constructor") && Object.prototype.hasOwnProperty.call(node.constructor, "prototype")) {
|
|
22605
|
+
if (Object.prototype.hasOwnProperty.call(node, "constructor") && node.constructor !== null && typeof node.constructor === "object" && Object.prototype.hasOwnProperty.call(node.constructor, "prototype")) {
|
|
22606
22606
|
throw new SyntaxError("Object contains forbidden prototype property");
|
|
22607
22607
|
}
|
|
22608
22608
|
for (const key in node) {
|
|
@@ -25166,16 +25166,14 @@ var GatewayVideoModel = class {
|
|
|
25166
25166
|
var _a932;
|
|
25167
25167
|
const resolvedHeaders = await resolve2(this.config.headers());
|
|
25168
25168
|
try {
|
|
25169
|
-
const {
|
|
25170
|
-
responseHeaders,
|
|
25171
|
-
value: responseBody
|
|
25172
|
-
} = await postJsonToApi2({
|
|
25169
|
+
const { responseHeaders, value: responseBody } = await postJsonToApi2({
|
|
25173
25170
|
url: this.getUrl(),
|
|
25174
25171
|
headers: combineHeaders2(
|
|
25175
25172
|
resolvedHeaders,
|
|
25176
25173
|
headers != null ? headers : {},
|
|
25177
25174
|
this.getModelConfigHeaders(),
|
|
25178
|
-
await resolve2(this.config.o11yHeaders)
|
|
25175
|
+
await resolve2(this.config.o11yHeaders),
|
|
25176
|
+
{ accept: "text/event-stream" }
|
|
25179
25177
|
),
|
|
25180
25178
|
body: {
|
|
25181
25179
|
prompt,
|
|
@@ -25188,9 +25186,70 @@ var GatewayVideoModel = class {
|
|
|
25188
25186
|
...providerOptions && { providerOptions },
|
|
25189
25187
|
...image && { image: maybeEncodeVideoFile(image) }
|
|
25190
25188
|
},
|
|
25191
|
-
successfulResponseHandler:
|
|
25192
|
-
|
|
25193
|
-
|
|
25189
|
+
successfulResponseHandler: async ({
|
|
25190
|
+
response,
|
|
25191
|
+
url,
|
|
25192
|
+
requestBodyValues
|
|
25193
|
+
}) => {
|
|
25194
|
+
if (response.body == null) {
|
|
25195
|
+
throw new APICallError3({
|
|
25196
|
+
message: "SSE response body is empty",
|
|
25197
|
+
url,
|
|
25198
|
+
requestBodyValues,
|
|
25199
|
+
statusCode: response.status
|
|
25200
|
+
});
|
|
25201
|
+
}
|
|
25202
|
+
const eventStream = parseJsonEventStream2({
|
|
25203
|
+
stream: response.body,
|
|
25204
|
+
schema: gatewayVideoEventSchema
|
|
25205
|
+
});
|
|
25206
|
+
const reader = eventStream.getReader();
|
|
25207
|
+
const { done, value: parseResult } = await reader.read();
|
|
25208
|
+
reader.releaseLock();
|
|
25209
|
+
if (done || !parseResult) {
|
|
25210
|
+
throw new APICallError3({
|
|
25211
|
+
message: "SSE stream ended without a data event",
|
|
25212
|
+
url,
|
|
25213
|
+
requestBodyValues,
|
|
25214
|
+
statusCode: response.status
|
|
25215
|
+
});
|
|
25216
|
+
}
|
|
25217
|
+
if (!parseResult.success) {
|
|
25218
|
+
throw new APICallError3({
|
|
25219
|
+
message: "Failed to parse video SSE event",
|
|
25220
|
+
cause: parseResult.error,
|
|
25221
|
+
url,
|
|
25222
|
+
requestBodyValues,
|
|
25223
|
+
statusCode: response.status
|
|
25224
|
+
});
|
|
25225
|
+
}
|
|
25226
|
+
const event = parseResult.value;
|
|
25227
|
+
if (event.type === "error") {
|
|
25228
|
+
throw new APICallError3({
|
|
25229
|
+
message: event.message,
|
|
25230
|
+
statusCode: event.statusCode,
|
|
25231
|
+
url,
|
|
25232
|
+
requestBodyValues,
|
|
25233
|
+
responseHeaders: Object.fromEntries([...response.headers]),
|
|
25234
|
+
responseBody: JSON.stringify(event),
|
|
25235
|
+
data: {
|
|
25236
|
+
error: {
|
|
25237
|
+
message: event.message,
|
|
25238
|
+
type: event.errorType,
|
|
25239
|
+
param: event.param
|
|
25240
|
+
}
|
|
25241
|
+
}
|
|
25242
|
+
});
|
|
25243
|
+
}
|
|
25244
|
+
return {
|
|
25245
|
+
value: {
|
|
25246
|
+
videos: event.videos,
|
|
25247
|
+
warnings: event.warnings,
|
|
25248
|
+
providerMetadata: event.providerMetadata
|
|
25249
|
+
},
|
|
25250
|
+
responseHeaders: Object.fromEntries([...response.headers])
|
|
25251
|
+
};
|
|
25252
|
+
},
|
|
25194
25253
|
failedResponseHandler: createJsonErrorResponseHandler2({
|
|
25195
25254
|
errorSchema: z42.z.any(),
|
|
25196
25255
|
errorToMessage: (data) => data
|
|
@@ -25262,11 +25321,21 @@ var gatewayVideoWarningSchema = z42.z.discriminatedUnion("type", [
|
|
|
25262
25321
|
message: z42.z.string()
|
|
25263
25322
|
})
|
|
25264
25323
|
]);
|
|
25265
|
-
var
|
|
25266
|
-
|
|
25267
|
-
|
|
25268
|
-
|
|
25269
|
-
|
|
25324
|
+
var gatewayVideoEventSchema = z42.z.discriminatedUnion("type", [
|
|
25325
|
+
z42.z.object({
|
|
25326
|
+
type: z42.z.literal("result"),
|
|
25327
|
+
videos: z42.z.array(gatewayVideoDataSchema),
|
|
25328
|
+
warnings: z42.z.array(gatewayVideoWarningSchema).optional(),
|
|
25329
|
+
providerMetadata: z42.z.record(z42.z.string(), providerMetadataEntrySchema22).optional()
|
|
25330
|
+
}),
|
|
25331
|
+
z42.z.object({
|
|
25332
|
+
type: z42.z.literal("error"),
|
|
25333
|
+
message: z42.z.string(),
|
|
25334
|
+
errorType: z42.z.string(),
|
|
25335
|
+
statusCode: z42.z.number(),
|
|
25336
|
+
param: z42.z.unknown().nullable()
|
|
25337
|
+
})
|
|
25338
|
+
]);
|
|
25270
25339
|
var parallelSearchInputSchema = lazySchema(
|
|
25271
25340
|
() => zodSchema3(
|
|
25272
25341
|
z18.z.object({
|
|
@@ -25443,7 +25512,7 @@ async function getVercelRequestId2() {
|
|
|
25443
25512
|
var _a932;
|
|
25444
25513
|
return (_a932 = (0, import_oidc3.getContext)().headers) == null ? void 0 : _a932["x-vercel-id"];
|
|
25445
25514
|
}
|
|
25446
|
-
var VERSION5 = "3.0.
|
|
25515
|
+
var VERSION5 = "3.0.66";
|
|
25447
25516
|
var AI_GATEWAY_PROTOCOL_VERSION2 = "0.0.1";
|
|
25448
25517
|
function createGatewayProvider2(options = {}) {
|
|
25449
25518
|
var _a932, _b92;
|
|
@@ -25486,13 +25555,18 @@ function createGatewayProvider2(options = {}) {
|
|
|
25486
25555
|
settingValue: void 0,
|
|
25487
25556
|
environmentVariableName: "VERCEL_REGION"
|
|
25488
25557
|
});
|
|
25558
|
+
const projectId = loadOptionalSetting2({
|
|
25559
|
+
settingValue: void 0,
|
|
25560
|
+
environmentVariableName: "VERCEL_PROJECT_ID"
|
|
25561
|
+
});
|
|
25489
25562
|
return async () => {
|
|
25490
25563
|
const requestId = await getVercelRequestId2();
|
|
25491
25564
|
return {
|
|
25492
25565
|
...deploymentId && { "ai-o11y-deployment-id": deploymentId },
|
|
25493
25566
|
...environment && { "ai-o11y-environment": environment },
|
|
25494
25567
|
...region && { "ai-o11y-region": region },
|
|
25495
|
-
...requestId && { "ai-o11y-request-id": requestId }
|
|
25568
|
+
...requestId && { "ai-o11y-request-id": requestId },
|
|
25569
|
+
...projectId && { "ai-o11y-project-id": projectId }
|
|
25496
25570
|
};
|
|
25497
25571
|
};
|
|
25498
25572
|
};
|
|
@@ -26511,7 +26585,7 @@ function getTotalTimeoutMs(timeout) {
|
|
|
26511
26585
|
}
|
|
26512
26586
|
return timeout.totalMs;
|
|
26513
26587
|
}
|
|
26514
|
-
var VERSION33 = "6.0.
|
|
26588
|
+
var VERSION33 = "6.0.116";
|
|
26515
26589
|
var dataContentSchema3 = z42.z.union([
|
|
26516
26590
|
z42.z.string(),
|
|
26517
26591
|
z42.z.instanceof(Uint8Array),
|
|
@@ -28061,6 +28135,25 @@ var updateWorkingMemoryTool = (memoryConfig) => {
|
|
|
28061
28135
|
workingMemory = JSON.stringify(mergedData);
|
|
28062
28136
|
} else {
|
|
28063
28137
|
workingMemory = typeof inputData.memory === "string" ? inputData.memory : JSON.stringify(inputData.memory);
|
|
28138
|
+
const existingRaw = await memory.getWorkingMemory({
|
|
28139
|
+
threadId,
|
|
28140
|
+
resourceId,
|
|
28141
|
+
memoryConfig
|
|
28142
|
+
});
|
|
28143
|
+
if (existingRaw) {
|
|
28144
|
+
const template = await memory.getWorkingMemoryTemplate({ memoryConfig });
|
|
28145
|
+
if (template?.content) {
|
|
28146
|
+
const normalizedNew = workingMemory.replace(/\s+/g, " ").trim();
|
|
28147
|
+
const normalizedTemplate = template.content.replace(/\s+/g, " ").trim();
|
|
28148
|
+
const normalizedExisting = existingRaw.replace(/\s+/g, " ").trim();
|
|
28149
|
+
if (normalizedNew === normalizedTemplate && normalizedExisting !== normalizedTemplate) {
|
|
28150
|
+
return {
|
|
28151
|
+
success: false,
|
|
28152
|
+
message: "Attempted to replace existing working memory with empty template. Update skipped to prevent data loss."
|
|
28153
|
+
};
|
|
28154
|
+
}
|
|
28155
|
+
}
|
|
28156
|
+
}
|
|
28064
28157
|
}
|
|
28065
28158
|
await memory.updateWorkingMemory({
|
|
28066
28159
|
threadId,
|
|
@@ -28151,6 +28244,7 @@ function normalizeObservationalMemoryConfig(config) {
|
|
|
28151
28244
|
var CHARS_PER_TOKEN = 4;
|
|
28152
28245
|
var DEFAULT_MESSAGE_RANGE = { before: 1, after: 1 };
|
|
28153
28246
|
var DEFAULT_TOP_K = 4;
|
|
28247
|
+
var VECTOR_DELETE_BATCH_SIZE = 100;
|
|
28154
28248
|
var isZodObject = (v) => v instanceof z18.ZodObject;
|
|
28155
28249
|
var Memory = class extends memory.MastraMemory {
|
|
28156
28250
|
constructor(config = {}) {
|
|
@@ -28340,6 +28434,45 @@ var Memory = class extends memory.MastraMemory {
|
|
|
28340
28434
|
async deleteThread(threadId) {
|
|
28341
28435
|
const memoryStore = await this.getMemoryStore();
|
|
28342
28436
|
await memoryStore.deleteThread({ threadId });
|
|
28437
|
+
if (this.vector) {
|
|
28438
|
+
void this.deleteThreadVectors(threadId);
|
|
28439
|
+
}
|
|
28440
|
+
}
|
|
28441
|
+
/**
|
|
28442
|
+
* Lists all vector indexes that match the memory messages prefix.
|
|
28443
|
+
* Handles separator differences across vector store backends (e.g. '_' vs '-').
|
|
28444
|
+
*/
|
|
28445
|
+
async getMemoryVectorIndexes() {
|
|
28446
|
+
if (!this.vector) return [];
|
|
28447
|
+
const separator = this.vector.indexSeparator ?? "_";
|
|
28448
|
+
const prefix = `memory${separator}messages`;
|
|
28449
|
+
const indexes = await this.vector.listIndexes();
|
|
28450
|
+
return indexes.filter((name21) => name21.startsWith(prefix));
|
|
28451
|
+
}
|
|
28452
|
+
/**
|
|
28453
|
+
* Deletes all vector embeddings associated with a thread.
|
|
28454
|
+
* This is called internally by deleteThread to clean up orphaned vectors.
|
|
28455
|
+
*
|
|
28456
|
+
* @param threadId - The ID of the thread whose vectors should be deleted
|
|
28457
|
+
*/
|
|
28458
|
+
async deleteThreadVectors(threadId) {
|
|
28459
|
+
try {
|
|
28460
|
+
const memoryIndexes = await this.getMemoryVectorIndexes();
|
|
28461
|
+
await Promise.all(
|
|
28462
|
+
memoryIndexes.map(async (indexName) => {
|
|
28463
|
+
try {
|
|
28464
|
+
await this.vector.deleteVectors({
|
|
28465
|
+
indexName,
|
|
28466
|
+
filter: { thread_id: threadId }
|
|
28467
|
+
});
|
|
28468
|
+
} catch {
|
|
28469
|
+
this.logger.debug(`Failed to delete vectors for thread ${threadId} in ${indexName}, skipping`);
|
|
28470
|
+
}
|
|
28471
|
+
})
|
|
28472
|
+
);
|
|
28473
|
+
} catch {
|
|
28474
|
+
this.logger.debug(`Failed to clean up vectors for thread ${threadId}`);
|
|
28475
|
+
}
|
|
28343
28476
|
}
|
|
28344
28477
|
async updateWorkingMemory({
|
|
28345
28478
|
threadId,
|
|
@@ -28357,25 +28490,33 @@ var Memory = class extends memory.MastraMemory {
|
|
|
28357
28490
|
`Memory error: Resource-scoped working memory is enabled but no resourceId was provided. Either provide a resourceId or explicitly set workingMemory.scope to 'thread'.`
|
|
28358
28491
|
);
|
|
28359
28492
|
}
|
|
28360
|
-
const
|
|
28361
|
-
|
|
28362
|
-
|
|
28363
|
-
|
|
28364
|
-
|
|
28365
|
-
|
|
28366
|
-
|
|
28367
|
-
|
|
28368
|
-
|
|
28369
|
-
throw new Error(`Thread ${threadId} not found`);
|
|
28370
|
-
}
|
|
28371
|
-
await memoryStore.updateThread({
|
|
28372
|
-
id: threadId,
|
|
28373
|
-
title: thread.title || "",
|
|
28374
|
-
metadata: {
|
|
28375
|
-
...thread.metadata,
|
|
28493
|
+
const mutexKey = scope === "resource" ? `resource-${resourceId}` : `thread-${threadId}`;
|
|
28494
|
+
const mutex = this.updateWorkingMemoryMutexes.has(mutexKey) ? this.updateWorkingMemoryMutexes.get(mutexKey) : new Mutex();
|
|
28495
|
+
this.updateWorkingMemoryMutexes.set(mutexKey, mutex);
|
|
28496
|
+
const release = await mutex.acquire();
|
|
28497
|
+
try {
|
|
28498
|
+
const memoryStore = await this.getMemoryStore();
|
|
28499
|
+
if (scope === "resource" && resourceId) {
|
|
28500
|
+
await memoryStore.updateResource({
|
|
28501
|
+
resourceId,
|
|
28376
28502
|
workingMemory
|
|
28503
|
+
});
|
|
28504
|
+
} else {
|
|
28505
|
+
const thread = await this.getThreadById({ threadId });
|
|
28506
|
+
if (!thread) {
|
|
28507
|
+
throw new Error(`Thread ${threadId} not found`);
|
|
28377
28508
|
}
|
|
28378
|
-
|
|
28509
|
+
await memoryStore.updateThread({
|
|
28510
|
+
id: threadId,
|
|
28511
|
+
title: thread.title || "",
|
|
28512
|
+
metadata: {
|
|
28513
|
+
...thread.metadata,
|
|
28514
|
+
workingMemory
|
|
28515
|
+
}
|
|
28516
|
+
});
|
|
28517
|
+
}
|
|
28518
|
+
} finally {
|
|
28519
|
+
release();
|
|
28379
28520
|
}
|
|
28380
28521
|
}
|
|
28381
28522
|
updateWorkingMemoryMutexes = /* @__PURE__ */ new Map();
|
|
@@ -28401,16 +28542,26 @@ var Memory = class extends memory.MastraMemory {
|
|
|
28401
28542
|
const existingWorkingMemory = await this.getWorkingMemory({ threadId, resourceId, memoryConfig }) || "";
|
|
28402
28543
|
const template = await this.getWorkingMemoryTemplate({ memoryConfig });
|
|
28403
28544
|
let reason = "";
|
|
28545
|
+
const normalizeForComparison = (str) => str.replace(/\s+/g, " ").trim();
|
|
28546
|
+
const normalizedNewMemory = normalizeForComparison(workingMemory);
|
|
28547
|
+
const normalizedTemplate = template?.content ? normalizeForComparison(template.content) : "";
|
|
28404
28548
|
if (existingWorkingMemory) {
|
|
28405
28549
|
if (searchString && existingWorkingMemory?.includes(searchString)) {
|
|
28406
28550
|
workingMemory = existingWorkingMemory.replace(searchString, workingMemory);
|
|
28407
28551
|
reason = `found and replaced searchString with newMemory`;
|
|
28408
|
-
} else if (existingWorkingMemory.includes(workingMemory) || template?.content?.trim() === workingMemory.trim()
|
|
28552
|
+
} else if (existingWorkingMemory.includes(workingMemory) || template?.content?.trim() === workingMemory.trim() || // Also check normalized versions to catch template variations with different whitespace
|
|
28553
|
+
normalizedNewMemory === normalizedTemplate) {
|
|
28409
28554
|
return {
|
|
28410
28555
|
success: false,
|
|
28411
28556
|
reason: `attempted to insert duplicate data into working memory. this entry was skipped`
|
|
28412
28557
|
};
|
|
28413
28558
|
} else {
|
|
28559
|
+
if (normalizedNewMemory === normalizedTemplate) {
|
|
28560
|
+
return {
|
|
28561
|
+
success: false,
|
|
28562
|
+
reason: `attempted to append empty template to working memory. this entry was skipped`
|
|
28563
|
+
};
|
|
28564
|
+
}
|
|
28414
28565
|
if (searchString) {
|
|
28415
28566
|
reason = `attempted to replace working memory string that doesn't exist. Appending to working memory instead.`;
|
|
28416
28567
|
} else {
|
|
@@ -28419,7 +28570,7 @@ var Memory = class extends memory.MastraMemory {
|
|
|
28419
28570
|
workingMemory = existingWorkingMemory + `
|
|
28420
28571
|
${workingMemory}`;
|
|
28421
28572
|
}
|
|
28422
|
-
} else if (workingMemory === template?.content) {
|
|
28573
|
+
} else if (workingMemory === template?.content || normalizedNewMemory === normalizedTemplate) {
|
|
28423
28574
|
return {
|
|
28424
28575
|
success: false,
|
|
28425
28576
|
reason: `try again when you have data to add. newMemory was equal to the working memory template`
|
|
@@ -28427,7 +28578,13 @@ ${workingMemory}`;
|
|
|
28427
28578
|
} else {
|
|
28428
28579
|
reason = `started new working memory`;
|
|
28429
28580
|
}
|
|
28430
|
-
|
|
28581
|
+
if (template?.content) {
|
|
28582
|
+
workingMemory = workingMemory.replaceAll(template.content, "");
|
|
28583
|
+
const templateWithUnixLineEndings = template.content.replace(/\r\n/g, "\n");
|
|
28584
|
+
const templateWithWindowsLineEndings = template.content.replace(/\n/g, "\r\n");
|
|
28585
|
+
workingMemory = workingMemory.replaceAll(templateWithUnixLineEndings, "");
|
|
28586
|
+
workingMemory = workingMemory.replaceAll(templateWithWindowsLineEndings, "");
|
|
28587
|
+
}
|
|
28431
28588
|
const scope = config.workingMemory.scope || "resource";
|
|
28432
28589
|
if (scope === "resource" && !resourceId) {
|
|
28433
28590
|
throw new Error(
|
|
@@ -28903,24 +29060,25 @@ Notes:
|
|
|
28903
29060
|
const messageIdsNeedingDeletion = /* @__PURE__ */ new Set([...messageIdsWithClearedContent, ...messageIdsWithNewEmbeddings]);
|
|
28904
29061
|
if (messageIdsNeedingDeletion.size > 0) {
|
|
28905
29062
|
try {
|
|
28906
|
-
const
|
|
28907
|
-
const
|
|
28908
|
-
|
|
28909
|
-
|
|
28910
|
-
|
|
28911
|
-
|
|
28912
|
-
|
|
28913
|
-
|
|
28914
|
-
|
|
28915
|
-
|
|
28916
|
-
|
|
28917
|
-
|
|
28918
|
-
|
|
29063
|
+
const memoryIndexes = await this.getMemoryVectorIndexes();
|
|
29064
|
+
const idsToDelete = [...messageIdsNeedingDeletion];
|
|
29065
|
+
await Promise.all(
|
|
29066
|
+
memoryIndexes.map(async (indexName) => {
|
|
29067
|
+
for (let i = 0; i < idsToDelete.length; i += VECTOR_DELETE_BATCH_SIZE) {
|
|
29068
|
+
const batch = idsToDelete.slice(i, i + VECTOR_DELETE_BATCH_SIZE);
|
|
29069
|
+
try {
|
|
29070
|
+
await this.vector.deleteVectors({
|
|
29071
|
+
indexName,
|
|
29072
|
+
filter: { message_id: { $in: batch } }
|
|
29073
|
+
});
|
|
29074
|
+
} catch {
|
|
29075
|
+
this.logger.debug(`Failed to delete vector batch in ${indexName} (batch offset ${i}), skipping`);
|
|
29076
|
+
}
|
|
28919
29077
|
}
|
|
28920
|
-
}
|
|
28921
|
-
|
|
29078
|
+
})
|
|
29079
|
+
);
|
|
28922
29080
|
} catch {
|
|
28923
|
-
this.logger.debug(`
|
|
29081
|
+
this.logger.debug(`Failed to clean up old vectors during message update`);
|
|
28924
29082
|
}
|
|
28925
29083
|
}
|
|
28926
29084
|
if (embeddingData.length > 0 && dimension !== void 0) {
|
|
@@ -28971,6 +29129,37 @@ Notes:
|
|
|
28971
29129
|
}
|
|
28972
29130
|
const memoryStore = await this.getMemoryStore();
|
|
28973
29131
|
await memoryStore.deleteMessages(messageIds);
|
|
29132
|
+
if (this.vector) {
|
|
29133
|
+
void this.deleteMessageVectors(messageIds);
|
|
29134
|
+
}
|
|
29135
|
+
}
|
|
29136
|
+
/**
|
|
29137
|
+
* Deletes vector embeddings for specific messages.
|
|
29138
|
+
* This is called internally by deleteMessages to clean up orphaned vectors.
|
|
29139
|
+
*
|
|
29140
|
+
* @param messageIds - The IDs of the messages whose vectors should be deleted
|
|
29141
|
+
*/
|
|
29142
|
+
async deleteMessageVectors(messageIds) {
|
|
29143
|
+
try {
|
|
29144
|
+
const memoryIndexes = await this.getMemoryVectorIndexes();
|
|
29145
|
+
await Promise.all(
|
|
29146
|
+
memoryIndexes.map(async (indexName) => {
|
|
29147
|
+
for (let i = 0; i < messageIds.length; i += VECTOR_DELETE_BATCH_SIZE) {
|
|
29148
|
+
const batch = messageIds.slice(i, i + VECTOR_DELETE_BATCH_SIZE);
|
|
29149
|
+
try {
|
|
29150
|
+
await this.vector.deleteVectors({
|
|
29151
|
+
indexName,
|
|
29152
|
+
filter: { message_id: { $in: batch } }
|
|
29153
|
+
});
|
|
29154
|
+
} catch {
|
|
29155
|
+
this.logger.debug(`Failed to delete vector batch in ${indexName} (batch offset ${i}), skipping`);
|
|
29156
|
+
}
|
|
29157
|
+
}
|
|
29158
|
+
})
|
|
29159
|
+
);
|
|
29160
|
+
} catch {
|
|
29161
|
+
this.logger.debug(`Failed to clean up vectors for deleted messages`);
|
|
29162
|
+
}
|
|
28974
29163
|
}
|
|
28975
29164
|
/**
|
|
28976
29165
|
* Clone a thread and its messages to create a new independent thread.
|
|
@@ -29385,7 +29574,7 @@ Notes:
|
|
|
29385
29574
|
"Observational memory async buffering is enabled by default but the installed version of @mastra/core does not support it. Either upgrade @mastra/core, @mastra/memory, and your storage adapter (@mastra/libsql, @mastra/pg, or @mastra/mongodb) to the latest version, or explicitly disable async buffering by setting `observation: { bufferTokens: false }` in your observationalMemory config."
|
|
29386
29575
|
);
|
|
29387
29576
|
}
|
|
29388
|
-
const { ObservationalMemory } = await import('./observational-memory-
|
|
29577
|
+
const { ObservationalMemory } = await import('./observational-memory-QFQUF5EY-5VPKVXKI.cjs');
|
|
29389
29578
|
return new ObservationalMemory({
|
|
29390
29579
|
storage: memoryStore,
|
|
29391
29580
|
scope: omConfig.scope,
|
|
@@ -40303,5 +40492,5 @@ exports.START_ASYNC_AGENT_BUILDER_ACTION_ROUTE = START_ASYNC_AGENT_BUILDER_ACTIO
|
|
|
40303
40492
|
exports.STREAM_AGENT_BUILDER_ACTION_ROUTE = STREAM_AGENT_BUILDER_ACTION_ROUTE;
|
|
40304
40493
|
exports.STREAM_LEGACY_AGENT_BUILDER_ACTION_ROUTE = STREAM_LEGACY_AGENT_BUILDER_ACTION_ROUTE;
|
|
40305
40494
|
exports.agent_builder_exports = agent_builder_exports;
|
|
40306
|
-
//# sourceMappingURL=chunk-
|
|
40307
|
-
//# sourceMappingURL=chunk-
|
|
40495
|
+
//# sourceMappingURL=chunk-E5I4COAV.cjs.map
|
|
40496
|
+
//# sourceMappingURL=chunk-E5I4COAV.cjs.map
|