@mastra/server 1.15.0-alpha.3 → 1.15.0-alpha.4
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 +7 -0
- package/dist/{chunk-IPQTQESA.cjs → chunk-26DWGZNJ.cjs} +434 -13
- package/dist/chunk-26DWGZNJ.cjs.map +1 -0
- package/dist/{chunk-OV64H74M.js → chunk-DVOXGNVI.js} +433 -12
- package/dist/chunk-DVOXGNVI.js.map +1 -0
- package/dist/{chunk-KH7BZQVQ.cjs → chunk-MJTEQGJT.cjs} +327 -25
- package/dist/chunk-MJTEQGJT.cjs.map +1 -0
- package/dist/{chunk-HPJ2CRVK.js → chunk-OVXPDSMT.js} +315 -27
- package/dist/chunk-OVXPDSMT.js.map +1 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/observational-memory-3XFCO6MX-WHVD3JTT.js +3 -0
- package/dist/{observational-memory-5NFPG6M3-MG2OMRFW.js.map → observational-memory-3XFCO6MX-WHVD3JTT.js.map} +1 -1
- package/dist/observational-memory-3XFCO6MX-WVUSRO35.cjs +108 -0
- package/dist/{observational-memory-5NFPG6M3-L7EU4ABW.cjs.map → observational-memory-3XFCO6MX-WVUSRO35.cjs.map} +1 -1
- package/dist/server/handlers/agent-builder.cjs +16 -16
- package/dist/server/handlers/agent-builder.js +1 -1
- package/dist/server/handlers.cjs +2 -2
- package/dist/server/handlers.js +1 -1
- package/dist/server/server-adapter/index.cjs +16 -16
- package/dist/server/server-adapter/index.js +1 -1
- package/package.json +5 -5
- package/dist/chunk-HPJ2CRVK.js.map +0 -1
- package/dist/chunk-IPQTQESA.cjs.map +0 -1
- package/dist/chunk-KH7BZQVQ.cjs.map +0 -1
- package/dist/chunk-OV64H74M.js.map +0 -1
- package/dist/observational-memory-5NFPG6M3-L7EU4ABW.cjs +0 -68
- package/dist/observational-memory-5NFPG6M3-MG2OMRFW.js +0 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @mastra/server
|
|
2
2
|
|
|
3
|
+
## 1.15.0-alpha.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`da93115`](https://github.com/mastra-ai/mastra/commit/da931155c1a9bc63d455d3d86b4ec984db5991fe), [`0efe12a`](https://github.com/mastra-ai/mastra/commit/0efe12a5f008a939a1aac71699486ba40138054e)]:
|
|
8
|
+
- @mastra/core@1.15.0-alpha.4
|
|
9
|
+
|
|
3
10
|
## 1.15.0-alpha.3
|
|
4
11
|
|
|
5
12
|
### Patch Changes
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var chunk5N66PU3H_cjs = require('./chunk-5N66PU3H.cjs');
|
|
4
4
|
var chunkEXKS4QPI_cjs = require('./chunk-EXKS4QPI.cjs');
|
|
5
5
|
var chunkFPURK3UW_cjs = require('./chunk-FPURK3UW.cjs');
|
|
6
|
-
var
|
|
6
|
+
var chunkMJTEQGJT_cjs = require('./chunk-MJTEQGJT.cjs');
|
|
7
7
|
var chunkR2ODPDKE_cjs = require('./chunk-R2ODPDKE.cjs');
|
|
8
8
|
var chunk7KSSSSLW_cjs = require('./chunk-7KSSSSLW.cjs');
|
|
9
9
|
var chunkFU22BXAG_cjs = require('./chunk-FU22BXAG.cjs');
|
|
@@ -23,8 +23,8 @@ var z4 = require('zod/v4');
|
|
|
23
23
|
var features = require('@mastra/core/features');
|
|
24
24
|
var memory = require('@mastra/core/memory');
|
|
25
25
|
var utils = require('@mastra/core/utils');
|
|
26
|
-
var schema = require('@mastra/core/schema');
|
|
27
26
|
var tools = require('@mastra/core/tools');
|
|
27
|
+
var schema = require('@mastra/core/schema');
|
|
28
28
|
var child_process = require('child_process');
|
|
29
29
|
var promises = require('fs/promises');
|
|
30
30
|
var path = require('path');
|
|
@@ -16138,6 +16138,426 @@ var DefaultEmbedManyResult3 = class {
|
|
|
16138
16138
|
};
|
|
16139
16139
|
createIdGenerator3({ prefix: "aiobj", size: 24 });
|
|
16140
16140
|
createIdGenerator3({ prefix: "aiobj", size: 24 });
|
|
16141
|
+
function hasVisibleParts(msg) {
|
|
16142
|
+
if (typeof msg.content === "string") return msg.content.length > 0;
|
|
16143
|
+
const parts = msg.content?.parts;
|
|
16144
|
+
if (!parts || !Array.isArray(parts)) return false;
|
|
16145
|
+
return parts.some((p) => !p.type?.startsWith("data-"));
|
|
16146
|
+
}
|
|
16147
|
+
function parseRangeFormat(cursor) {
|
|
16148
|
+
if (cursor.includes(",")) {
|
|
16149
|
+
const parts = cursor.split(",").map((p) => p.trim()).filter(Boolean);
|
|
16150
|
+
if (parts.length >= 1) {
|
|
16151
|
+
const first = parts[0];
|
|
16152
|
+
const last = parts[parts.length - 1];
|
|
16153
|
+
const firstColon = first.indexOf(":");
|
|
16154
|
+
const lastColon = last.indexOf(":");
|
|
16155
|
+
return {
|
|
16156
|
+
startId: firstColon > 0 ? first.slice(0, firstColon) : first,
|
|
16157
|
+
endId: lastColon > 0 ? last.slice(lastColon + 1) : last
|
|
16158
|
+
};
|
|
16159
|
+
}
|
|
16160
|
+
}
|
|
16161
|
+
const colonIndex = cursor.indexOf(":");
|
|
16162
|
+
if (colonIndex > 0 && colonIndex < cursor.length - 1) {
|
|
16163
|
+
return { startId: cursor.slice(0, colonIndex), endId: cursor.slice(colonIndex + 1) };
|
|
16164
|
+
}
|
|
16165
|
+
return null;
|
|
16166
|
+
}
|
|
16167
|
+
async function resolveCursorMessage(memory, cursor) {
|
|
16168
|
+
const normalized = cursor.trim();
|
|
16169
|
+
if (!normalized) {
|
|
16170
|
+
throw new Error("Cursor is required");
|
|
16171
|
+
}
|
|
16172
|
+
const rangeIds = parseRangeFormat(normalized);
|
|
16173
|
+
if (rangeIds) {
|
|
16174
|
+
return {
|
|
16175
|
+
hint: `The cursor "${cursor}" looks like a range. Use one of the individual message IDs as the cursor instead: start="${rangeIds.startId}" or end="${rangeIds.endId}".`,
|
|
16176
|
+
...rangeIds
|
|
16177
|
+
};
|
|
16178
|
+
}
|
|
16179
|
+
const memoryStore = await memory.getMemoryStore();
|
|
16180
|
+
const result = await memoryStore.listMessagesById({ messageIds: [normalized] });
|
|
16181
|
+
const message = result.messages.find((message2) => message2.id === normalized);
|
|
16182
|
+
if (!message) {
|
|
16183
|
+
throw new Error(`Could not resolve cursor message: ${cursor}`);
|
|
16184
|
+
}
|
|
16185
|
+
return message;
|
|
16186
|
+
}
|
|
16187
|
+
var LOW_DETAIL_PART_TOKENS = 30;
|
|
16188
|
+
var AUTO_EXPAND_TEXT_TOKENS = 100;
|
|
16189
|
+
var AUTO_EXPAND_TOOL_TOKENS = 20;
|
|
16190
|
+
var HIGH_DETAIL_TOOL_RESULT_TOKENS = 4e3;
|
|
16191
|
+
var DEFAULT_MAX_RESULT_TOKENS = 2e3;
|
|
16192
|
+
function formatTimestamp(date) {
|
|
16193
|
+
return date.toISOString().replace("T", " ").replace(/\.\d{3}Z$/, "Z");
|
|
16194
|
+
}
|
|
16195
|
+
function truncateByTokens(text42, maxTokens, hint) {
|
|
16196
|
+
if (chunkMJTEQGJT_cjs.estimateTokenCount(text42) <= maxTokens) return { text: text42, wasTruncated: false };
|
|
16197
|
+
const truncated = chunkMJTEQGJT_cjs.truncateStringByTokens(text42, maxTokens);
|
|
16198
|
+
const suffix = hint ? ` [${hint} for more]` : "";
|
|
16199
|
+
return { text: truncated + suffix, wasTruncated: true };
|
|
16200
|
+
}
|
|
16201
|
+
function lowDetailPartLimit(type) {
|
|
16202
|
+
if (type === "text") return AUTO_EXPAND_TEXT_TOKENS;
|
|
16203
|
+
if (type === "tool-result" || type === "tool-call") return AUTO_EXPAND_TOOL_TOKENS;
|
|
16204
|
+
return LOW_DETAIL_PART_TOKENS;
|
|
16205
|
+
}
|
|
16206
|
+
function makePart(msg, partIndex, type, fullText, detail) {
|
|
16207
|
+
if (detail === "high") {
|
|
16208
|
+
return { messageId: msg.id, partIndex, role: msg.role, type, text: fullText, fullText };
|
|
16209
|
+
}
|
|
16210
|
+
const hint = `recall cursor="${msg.id}" partIndex=${partIndex} detail="high"`;
|
|
16211
|
+
const { text: text42 } = truncateByTokens(fullText, lowDetailPartLimit(type), hint);
|
|
16212
|
+
return { messageId: msg.id, partIndex, role: msg.role, type, text: text42, fullText };
|
|
16213
|
+
}
|
|
16214
|
+
function formatMessageParts(msg, detail) {
|
|
16215
|
+
const parts = [];
|
|
16216
|
+
if (typeof msg.content === "string") {
|
|
16217
|
+
parts.push(makePart(msg, 0, "text", msg.content, detail));
|
|
16218
|
+
return parts;
|
|
16219
|
+
}
|
|
16220
|
+
if (msg.content?.parts && Array.isArray(msg.content.parts)) {
|
|
16221
|
+
for (let i = 0; i < msg.content.parts.length; i++) {
|
|
16222
|
+
const part = msg.content.parts[i];
|
|
16223
|
+
const partType = part.type;
|
|
16224
|
+
if (partType === "text") {
|
|
16225
|
+
const text42 = part.text;
|
|
16226
|
+
parts.push(makePart(msg, i, "text", text42, detail));
|
|
16227
|
+
} else if (partType === "tool-invocation") {
|
|
16228
|
+
const inv = part.toolInvocation;
|
|
16229
|
+
if (inv.state === "result") {
|
|
16230
|
+
const { value: resultValue } = chunkMJTEQGJT_cjs.resolveToolResultValue(
|
|
16231
|
+
part,
|
|
16232
|
+
inv.result
|
|
16233
|
+
);
|
|
16234
|
+
const resultStr = chunkMJTEQGJT_cjs.formatToolResultForObserver(resultValue, { maxTokens: HIGH_DETAIL_TOOL_RESULT_TOKENS });
|
|
16235
|
+
const fullText = `[Tool Result: ${inv.toolName}]
|
|
16236
|
+
${resultStr}`;
|
|
16237
|
+
parts.push(makePart(msg, i, "tool-result", fullText, detail));
|
|
16238
|
+
} else {
|
|
16239
|
+
const argsStr = detail === "low" ? "" : `
|
|
16240
|
+
${JSON.stringify(inv.args, null, 2)}`;
|
|
16241
|
+
const fullText = `[Tool Call: ${inv.toolName}]${argsStr}`;
|
|
16242
|
+
parts.push({ messageId: msg.id, partIndex: i, role: msg.role, type: "tool-call", text: fullText, fullText });
|
|
16243
|
+
}
|
|
16244
|
+
} else if (partType === "reasoning") {
|
|
16245
|
+
const reasoning = part.reasoning;
|
|
16246
|
+
if (reasoning) {
|
|
16247
|
+
parts.push(makePart(msg, i, "reasoning", reasoning, detail));
|
|
16248
|
+
}
|
|
16249
|
+
} else if (partType === "image" || partType === "file") {
|
|
16250
|
+
const filename = part.filename;
|
|
16251
|
+
const label = filename ? `: ${filename}` : "";
|
|
16252
|
+
const fullText = `[${partType === "image" ? "Image" : "File"}${label}]`;
|
|
16253
|
+
parts.push({ messageId: msg.id, partIndex: i, role: msg.role, type: partType, text: fullText, fullText });
|
|
16254
|
+
} else if (partType?.startsWith("data-")) ;
|
|
16255
|
+
else if (partType) {
|
|
16256
|
+
const fullText = `[${partType}]`;
|
|
16257
|
+
parts.push({ messageId: msg.id, partIndex: i, role: msg.role, type: partType, text: fullText, fullText });
|
|
16258
|
+
}
|
|
16259
|
+
}
|
|
16260
|
+
} else if (msg.content?.content) {
|
|
16261
|
+
parts.push(makePart(msg, 0, "text", msg.content.content, detail));
|
|
16262
|
+
}
|
|
16263
|
+
return parts;
|
|
16264
|
+
}
|
|
16265
|
+
function buildRenderedText(parts, timestamps) {
|
|
16266
|
+
let currentMessageId = "";
|
|
16267
|
+
const lines = [];
|
|
16268
|
+
for (const part of parts) {
|
|
16269
|
+
if (part.messageId !== currentMessageId) {
|
|
16270
|
+
currentMessageId = part.messageId;
|
|
16271
|
+
const ts = timestamps.get(part.messageId);
|
|
16272
|
+
const tsStr = ts ? ` (${formatTimestamp(ts)})` : "";
|
|
16273
|
+
if (lines.length > 0) lines.push("");
|
|
16274
|
+
lines.push(`**${part.role}${tsStr}** [${part.messageId}]:`);
|
|
16275
|
+
}
|
|
16276
|
+
const indexLabel = `[p${part.partIndex}]`;
|
|
16277
|
+
lines.push(` ${indexLabel} ${part.text}`);
|
|
16278
|
+
}
|
|
16279
|
+
return lines.join("\n");
|
|
16280
|
+
}
|
|
16281
|
+
var MAX_EXPAND_USER_TEXT_TOKENS = 200;
|
|
16282
|
+
var MAX_EXPAND_OTHER_TOKENS = 50;
|
|
16283
|
+
function expandLimit(part) {
|
|
16284
|
+
if (part.role === "user" && part.type === "text") return MAX_EXPAND_USER_TEXT_TOKENS;
|
|
16285
|
+
return MAX_EXPAND_OTHER_TOKENS;
|
|
16286
|
+
}
|
|
16287
|
+
function expandPriority(part) {
|
|
16288
|
+
if (part.role === "user" && part.type === "text") return 0;
|
|
16289
|
+
if (part.type === "text" || part.type === "reasoning") return 1;
|
|
16290
|
+
if (part.type === "tool-result") return 2;
|
|
16291
|
+
if (part.type === "tool-call") return 3;
|
|
16292
|
+
return 4;
|
|
16293
|
+
}
|
|
16294
|
+
function renderFormattedParts(parts, timestamps, options) {
|
|
16295
|
+
const text42 = buildRenderedText(parts, timestamps);
|
|
16296
|
+
let totalTokens = chunkMJTEQGJT_cjs.estimateTokenCount(text42);
|
|
16297
|
+
if (totalTokens > options.maxTokens) {
|
|
16298
|
+
const truncated = chunkMJTEQGJT_cjs.truncateStringByTokens(text42, options.maxTokens);
|
|
16299
|
+
return { text: truncated, truncated: true, tokenOffset: totalTokens - options.maxTokens };
|
|
16300
|
+
}
|
|
16301
|
+
const truncatedIndices = parts.map((p, i) => ({ part: p, index: i })).filter(({ part }) => part.text !== part.fullText).sort((a, b) => expandPriority(a.part) - expandPriority(b.part));
|
|
16302
|
+
if (truncatedIndices.length === 0) {
|
|
16303
|
+
return { text: text42, truncated: false, tokenOffset: 0 };
|
|
16304
|
+
}
|
|
16305
|
+
let remaining = options.maxTokens - totalTokens;
|
|
16306
|
+
for (const { part, index } of truncatedIndices) {
|
|
16307
|
+
if (remaining <= 0) break;
|
|
16308
|
+
const maxTokens = expandLimit(part);
|
|
16309
|
+
const fullTokens = chunkMJTEQGJT_cjs.estimateTokenCount(part.fullText);
|
|
16310
|
+
const currentTokens = chunkMJTEQGJT_cjs.estimateTokenCount(part.text);
|
|
16311
|
+
const targetTokens = Math.min(fullTokens, maxTokens);
|
|
16312
|
+
const delta = targetTokens - currentTokens;
|
|
16313
|
+
if (delta <= 0) continue;
|
|
16314
|
+
if (delta <= remaining && targetTokens >= fullTokens) {
|
|
16315
|
+
parts[index] = { ...part, text: part.fullText };
|
|
16316
|
+
remaining -= delta;
|
|
16317
|
+
} else {
|
|
16318
|
+
const expandedLimit = Math.min(currentTokens + remaining, maxTokens);
|
|
16319
|
+
const hint = `recall cursor="${part.messageId}" partIndex=${part.partIndex} detail="high"`;
|
|
16320
|
+
const { text: expanded2 } = truncateByTokens(part.fullText, expandedLimit, hint);
|
|
16321
|
+
const expandedDelta = chunkMJTEQGJT_cjs.estimateTokenCount(expanded2) - currentTokens;
|
|
16322
|
+
parts[index] = { ...part, text: expanded2 };
|
|
16323
|
+
remaining -= expandedDelta;
|
|
16324
|
+
}
|
|
16325
|
+
}
|
|
16326
|
+
const expanded = buildRenderedText(parts, timestamps);
|
|
16327
|
+
const expandedTokens = chunkMJTEQGJT_cjs.estimateTokenCount(expanded);
|
|
16328
|
+
if (expandedTokens <= options.maxTokens) {
|
|
16329
|
+
return { text: expanded, truncated: false, tokenOffset: 0 };
|
|
16330
|
+
}
|
|
16331
|
+
const hardTruncated = chunkMJTEQGJT_cjs.truncateStringByTokens(expanded, options.maxTokens);
|
|
16332
|
+
return { text: hardTruncated, truncated: true, tokenOffset: expandedTokens - options.maxTokens };
|
|
16333
|
+
}
|
|
16334
|
+
async function recallPart({
|
|
16335
|
+
memory,
|
|
16336
|
+
threadId,
|
|
16337
|
+
cursor,
|
|
16338
|
+
partIndex,
|
|
16339
|
+
maxTokens = DEFAULT_MAX_RESULT_TOKENS
|
|
16340
|
+
}) {
|
|
16341
|
+
if (!memory || typeof memory.getMemoryStore !== "function") {
|
|
16342
|
+
throw new Error("Memory instance is required for recall");
|
|
16343
|
+
}
|
|
16344
|
+
if (!threadId) {
|
|
16345
|
+
throw new Error("Thread ID is required for recall");
|
|
16346
|
+
}
|
|
16347
|
+
const resolved = await resolveCursorMessage(memory, cursor);
|
|
16348
|
+
if ("hint" in resolved) {
|
|
16349
|
+
throw new Error(resolved.hint);
|
|
16350
|
+
}
|
|
16351
|
+
if (resolved.threadId !== threadId) {
|
|
16352
|
+
throw new Error("The requested cursor does not belong to the current thread");
|
|
16353
|
+
}
|
|
16354
|
+
const allParts = formatMessageParts(resolved, "high");
|
|
16355
|
+
if (allParts.length === 0) {
|
|
16356
|
+
throw new Error(
|
|
16357
|
+
`Message ${cursor} has no visible content (it may be an internal system message). Try a neighboring message ID instead.`
|
|
16358
|
+
);
|
|
16359
|
+
}
|
|
16360
|
+
const target = allParts.find((p) => p.partIndex === partIndex);
|
|
16361
|
+
if (!target) {
|
|
16362
|
+
throw new Error(
|
|
16363
|
+
`Part index ${partIndex} not found in message ${cursor}. Available indices: ${allParts.map((p) => p.partIndex).join(", ")}`
|
|
16364
|
+
);
|
|
16365
|
+
}
|
|
16366
|
+
const truncatedText = chunkMJTEQGJT_cjs.truncateStringByTokens(target.text, maxTokens);
|
|
16367
|
+
const wasTruncated = truncatedText !== target.text;
|
|
16368
|
+
return {
|
|
16369
|
+
text: truncatedText,
|
|
16370
|
+
messageId: target.messageId,
|
|
16371
|
+
partIndex: target.partIndex,
|
|
16372
|
+
role: target.role,
|
|
16373
|
+
type: target.type,
|
|
16374
|
+
truncated: wasTruncated
|
|
16375
|
+
};
|
|
16376
|
+
}
|
|
16377
|
+
async function recallMessages({
|
|
16378
|
+
memory,
|
|
16379
|
+
threadId,
|
|
16380
|
+
resourceId,
|
|
16381
|
+
cursor,
|
|
16382
|
+
page = 1,
|
|
16383
|
+
limit = 20,
|
|
16384
|
+
detail = "low",
|
|
16385
|
+
maxTokens = DEFAULT_MAX_RESULT_TOKENS
|
|
16386
|
+
}) {
|
|
16387
|
+
if (!memory) {
|
|
16388
|
+
throw new Error("Memory instance is required for recall");
|
|
16389
|
+
}
|
|
16390
|
+
if (!threadId) {
|
|
16391
|
+
throw new Error("Thread ID is required for recall");
|
|
16392
|
+
}
|
|
16393
|
+
if (typeof memory.getMemoryStore !== "function") {
|
|
16394
|
+
throw new Error("recall requires a Memory instance with storage access");
|
|
16395
|
+
}
|
|
16396
|
+
const MAX_PAGE = 50;
|
|
16397
|
+
const MAX_LIMIT = 20;
|
|
16398
|
+
const rawPage = page === 0 ? 1 : page;
|
|
16399
|
+
const normalizedPage = Math.max(Math.min(rawPage, MAX_PAGE), -MAX_PAGE);
|
|
16400
|
+
const normalizedLimit = Math.min(limit, MAX_LIMIT);
|
|
16401
|
+
const resolved = await resolveCursorMessage(memory, cursor);
|
|
16402
|
+
if ("hint" in resolved) {
|
|
16403
|
+
return {
|
|
16404
|
+
messages: resolved.hint,
|
|
16405
|
+
count: 0,
|
|
16406
|
+
cursor,
|
|
16407
|
+
page: normalizedPage,
|
|
16408
|
+
limit: normalizedLimit,
|
|
16409
|
+
detail,
|
|
16410
|
+
hasNextPage: false,
|
|
16411
|
+
hasPrevPage: false,
|
|
16412
|
+
truncated: false,
|
|
16413
|
+
tokenOffset: 0
|
|
16414
|
+
};
|
|
16415
|
+
}
|
|
16416
|
+
const anchor = resolved;
|
|
16417
|
+
if (anchor.threadId !== threadId) {
|
|
16418
|
+
throw new Error("The requested cursor does not belong to the current thread");
|
|
16419
|
+
}
|
|
16420
|
+
const isForward = normalizedPage > 0;
|
|
16421
|
+
const pageIndex = Math.max(Math.abs(normalizedPage), 1) - 1;
|
|
16422
|
+
const skip = pageIndex * normalizedLimit;
|
|
16423
|
+
const fetchCount = skip + normalizedLimit + 1;
|
|
16424
|
+
const result = await memory.recall({
|
|
16425
|
+
threadId,
|
|
16426
|
+
resourceId,
|
|
16427
|
+
page: 0,
|
|
16428
|
+
perPage: fetchCount,
|
|
16429
|
+
orderBy: { field: "createdAt", direction: isForward ? "ASC" : "DESC" },
|
|
16430
|
+
filter: {
|
|
16431
|
+
dateRange: isForward ? {
|
|
16432
|
+
start: anchor.createdAt,
|
|
16433
|
+
startExclusive: true
|
|
16434
|
+
} : {
|
|
16435
|
+
end: anchor.createdAt,
|
|
16436
|
+
endExclusive: true
|
|
16437
|
+
}
|
|
16438
|
+
}
|
|
16439
|
+
});
|
|
16440
|
+
const visibleMessages = result.messages.filter(hasVisibleParts);
|
|
16441
|
+
const total = visibleMessages.length;
|
|
16442
|
+
const hasMore = total > skip + normalizedLimit;
|
|
16443
|
+
let messages;
|
|
16444
|
+
if (isForward) {
|
|
16445
|
+
messages = visibleMessages.slice(skip, skip + normalizedLimit);
|
|
16446
|
+
} else {
|
|
16447
|
+
const endIdx = Math.max(total - skip, 0);
|
|
16448
|
+
const startIdx = Math.max(endIdx - normalizedLimit, 0);
|
|
16449
|
+
messages = visibleMessages.slice(startIdx, endIdx);
|
|
16450
|
+
}
|
|
16451
|
+
const hasNextPage = isForward ? hasMore : pageIndex > 0;
|
|
16452
|
+
const hasPrevPage = isForward ? pageIndex > 0 : hasMore;
|
|
16453
|
+
const allParts = [];
|
|
16454
|
+
const timestamps = /* @__PURE__ */ new Map();
|
|
16455
|
+
for (const msg of messages) {
|
|
16456
|
+
timestamps.set(msg.id, msg.createdAt);
|
|
16457
|
+
allParts.push(...formatMessageParts(msg, detail));
|
|
16458
|
+
}
|
|
16459
|
+
if (detail === "high" && allParts.length > 0) {
|
|
16460
|
+
const firstPart = allParts[0];
|
|
16461
|
+
const sameMsgParts = allParts.filter((p) => p.messageId === firstPart.messageId);
|
|
16462
|
+
const otherMsgParts = allParts.filter((p) => p.messageId !== firstPart.messageId);
|
|
16463
|
+
const rendered2 = renderFormattedParts([firstPart], timestamps, { maxTokens });
|
|
16464
|
+
let text42 = rendered2.text;
|
|
16465
|
+
const hints = [];
|
|
16466
|
+
if (sameMsgParts.length > 1) {
|
|
16467
|
+
const nextPart = sameMsgParts[1];
|
|
16468
|
+
hints.push(`next part: partIndex=${nextPart.partIndex} on cursor="${firstPart.messageId}"`);
|
|
16469
|
+
}
|
|
16470
|
+
if (otherMsgParts.length > 0) {
|
|
16471
|
+
const next = otherMsgParts[0];
|
|
16472
|
+
hints.push(`next message: partIndex=${next.partIndex} on cursor="${next.messageId}"`);
|
|
16473
|
+
} else if (hasNextPage) {
|
|
16474
|
+
hints.push(`more messages available on page ${normalizedPage + 1}`);
|
|
16475
|
+
}
|
|
16476
|
+
if (hints.length > 0) {
|
|
16477
|
+
text42 += `
|
|
16478
|
+
|
|
16479
|
+
High detail returns 1 part at a time. To continue: ${hints.join(", or ")}.`;
|
|
16480
|
+
}
|
|
16481
|
+
return {
|
|
16482
|
+
messages: text42,
|
|
16483
|
+
count: 1,
|
|
16484
|
+
cursor,
|
|
16485
|
+
page: normalizedPage,
|
|
16486
|
+
limit: normalizedLimit,
|
|
16487
|
+
detail,
|
|
16488
|
+
hasNextPage: otherMsgParts.length > 0 || hasNextPage,
|
|
16489
|
+
hasPrevPage,
|
|
16490
|
+
truncated: rendered2.truncated,
|
|
16491
|
+
tokenOffset: rendered2.tokenOffset
|
|
16492
|
+
};
|
|
16493
|
+
}
|
|
16494
|
+
const rendered = renderFormattedParts(allParts, timestamps, { maxTokens });
|
|
16495
|
+
return {
|
|
16496
|
+
messages: rendered.text,
|
|
16497
|
+
count: messages.length,
|
|
16498
|
+
cursor,
|
|
16499
|
+
page: normalizedPage,
|
|
16500
|
+
limit: normalizedLimit,
|
|
16501
|
+
detail,
|
|
16502
|
+
hasNextPage,
|
|
16503
|
+
hasPrevPage,
|
|
16504
|
+
truncated: rendered.truncated,
|
|
16505
|
+
tokenOffset: rendered.tokenOffset
|
|
16506
|
+
};
|
|
16507
|
+
}
|
|
16508
|
+
var recallTool = (_memoryConfig) => {
|
|
16509
|
+
return tools.createTool({
|
|
16510
|
+
id: "recall",
|
|
16511
|
+
description: 'Retrieve raw message history near an observation group cursor. Observation group ranges use the format startId:endId. Pass either the start or end message ID as the cursor. Use detail="low" (default) for an overview, detail="high" for full content, or provide partIndex to fetch a specific part from the cursor message.',
|
|
16512
|
+
inputSchema: zod.z.object({
|
|
16513
|
+
cursor: zod.z.string().min(1).describe("A single message ID to use as the pagination cursor. Extract it from the start or end of a range."),
|
|
16514
|
+
page: zod.z.number().int().min(-50).max(50).optional().describe(
|
|
16515
|
+
"Pagination offset from the cursor. Positive pages move forward, negative pages move backward, and 0 is treated as 1."
|
|
16516
|
+
),
|
|
16517
|
+
limit: zod.z.number().int().positive().max(20).optional().describe("Maximum number of messages to return. Defaults to 20."),
|
|
16518
|
+
detail: zod.z.enum(["low", "high"]).optional().describe(
|
|
16519
|
+
'Detail level. "low" (default) returns truncated text and tool names. "high" returns full content with tool args/results.'
|
|
16520
|
+
),
|
|
16521
|
+
partIndex: zod.z.number().int().min(0).optional().describe(
|
|
16522
|
+
"Fetch a single part from the cursor message by its positional index. When provided, returns only that part at high detail. Indices are shown as [p0], [p1], etc. in recall results."
|
|
16523
|
+
)
|
|
16524
|
+
}),
|
|
16525
|
+
execute: async ({
|
|
16526
|
+
cursor,
|
|
16527
|
+
page,
|
|
16528
|
+
limit,
|
|
16529
|
+
detail,
|
|
16530
|
+
partIndex
|
|
16531
|
+
}, context2) => {
|
|
16532
|
+
const memory = context2?.memory;
|
|
16533
|
+
const threadId = context2?.agent?.threadId;
|
|
16534
|
+
const resourceId = context2?.agent?.resourceId;
|
|
16535
|
+
if (!memory) {
|
|
16536
|
+
throw new Error("Memory instance is required for recall");
|
|
16537
|
+
}
|
|
16538
|
+
if (!threadId) {
|
|
16539
|
+
throw new Error("Thread ID is required for recall");
|
|
16540
|
+
}
|
|
16541
|
+
if (partIndex !== void 0 && partIndex !== null) {
|
|
16542
|
+
return recallPart({
|
|
16543
|
+
memory,
|
|
16544
|
+
threadId,
|
|
16545
|
+
cursor,
|
|
16546
|
+
partIndex
|
|
16547
|
+
});
|
|
16548
|
+
}
|
|
16549
|
+
return recallMessages({
|
|
16550
|
+
memory,
|
|
16551
|
+
threadId,
|
|
16552
|
+
resourceId,
|
|
16553
|
+
cursor,
|
|
16554
|
+
page,
|
|
16555
|
+
limit,
|
|
16556
|
+
detail: detail ?? "low"
|
|
16557
|
+
});
|
|
16558
|
+
}
|
|
16559
|
+
});
|
|
16560
|
+
};
|
|
16141
16561
|
function deepMergeWorkingMemory(existing, update) {
|
|
16142
16562
|
if (!update || typeof update !== "object" || Object.keys(update).length === 0) {
|
|
16143
16563
|
return existing && typeof existing === "object" ? { ...existing } : {};
|
|
@@ -16765,7 +17185,7 @@ ${workingMemory}`;
|
|
|
16765
17185
|
}
|
|
16766
17186
|
return chunks;
|
|
16767
17187
|
}
|
|
16768
|
-
hasher =
|
|
17188
|
+
hasher = chunkMJTEQGJT_cjs.e();
|
|
16769
17189
|
// embedding is computationally expensive so cache content -> embeddings/chunks
|
|
16770
17190
|
embeddingCache = /* @__PURE__ */ new Map();
|
|
16771
17191
|
firstEmbed;
|
|
@@ -17117,15 +17537,15 @@ Notes:
|
|
|
17117
17537
|
}
|
|
17118
17538
|
listTools(config) {
|
|
17119
17539
|
const mergedConfig = this.getMergedThreadConfig(config);
|
|
17540
|
+
const tools = {};
|
|
17120
17541
|
if (mergedConfig.workingMemory?.enabled && !mergedConfig.readOnly) {
|
|
17121
|
-
|
|
17122
|
-
updateWorkingMemory: this.isVNextWorkingMemoryConfig(mergedConfig) ? (
|
|
17123
|
-
// use the new experimental tool
|
|
17124
|
-
__experimental_updateWorkingMemoryToolVNext(mergedConfig)
|
|
17125
|
-
) : updateWorkingMemoryTool(mergedConfig)
|
|
17126
|
-
};
|
|
17542
|
+
tools.updateWorkingMemory = this.isVNextWorkingMemoryConfig(mergedConfig) ? __experimental_updateWorkingMemoryToolVNext(mergedConfig) : updateWorkingMemoryTool(mergedConfig);
|
|
17127
17543
|
}
|
|
17128
|
-
|
|
17544
|
+
const omConfig = normalizeObservationalMemoryConfig(mergedConfig.observationalMemory);
|
|
17545
|
+
if (omConfig?.retrieval && (omConfig.scope ?? "thread") === "thread") {
|
|
17546
|
+
tools.recall = recallTool();
|
|
17547
|
+
}
|
|
17548
|
+
return tools;
|
|
17129
17549
|
}
|
|
17130
17550
|
/**
|
|
17131
17551
|
* Updates a list of messages and syncs the vector database for semantic recall.
|
|
@@ -17707,10 +18127,11 @@ Notes:
|
|
|
17707
18127
|
"Observational memory requires @mastra/core support for request-response-id-rotation. Please bump @mastra/core to a newer version."
|
|
17708
18128
|
);
|
|
17709
18129
|
}
|
|
17710
|
-
const { ObservationalMemory } = await import('./observational-memory-
|
|
18130
|
+
const { ObservationalMemory } = await import('./observational-memory-3XFCO6MX-WVUSRO35.cjs');
|
|
17711
18131
|
return new ObservationalMemory({
|
|
17712
18132
|
storage: memoryStore,
|
|
17713
18133
|
scope: omConfig.scope,
|
|
18134
|
+
retrieval: omConfig.retrieval,
|
|
17714
18135
|
shareTokenBudget: omConfig.shareTokenBudget,
|
|
17715
18136
|
model: omConfig.model,
|
|
17716
18137
|
observation: omConfig.observation ? {
|
|
@@ -28950,5 +29371,5 @@ exports.START_ASYNC_AGENT_BUILDER_ACTION_ROUTE = START_ASYNC_AGENT_BUILDER_ACTIO
|
|
|
28950
29371
|
exports.STREAM_AGENT_BUILDER_ACTION_ROUTE = STREAM_AGENT_BUILDER_ACTION_ROUTE;
|
|
28951
29372
|
exports.STREAM_LEGACY_AGENT_BUILDER_ACTION_ROUTE = STREAM_LEGACY_AGENT_BUILDER_ACTION_ROUTE;
|
|
28952
29373
|
exports.agent_builder_exports = agent_builder_exports;
|
|
28953
|
-
//# sourceMappingURL=chunk-
|
|
28954
|
-
//# sourceMappingURL=chunk-
|
|
29374
|
+
//# sourceMappingURL=chunk-26DWGZNJ.cjs.map
|
|
29375
|
+
//# sourceMappingURL=chunk-26DWGZNJ.cjs.map
|