@mastra/server 1.15.0-alpha.2 → 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.
Files changed (28) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/{chunk-IPQTQESA.cjs → chunk-26DWGZNJ.cjs} +434 -13
  3. package/dist/chunk-26DWGZNJ.cjs.map +1 -0
  4. package/dist/{chunk-OV64H74M.js → chunk-DVOXGNVI.js} +433 -12
  5. package/dist/chunk-DVOXGNVI.js.map +1 -0
  6. package/dist/{chunk-KH7BZQVQ.cjs → chunk-MJTEQGJT.cjs} +327 -25
  7. package/dist/chunk-MJTEQGJT.cjs.map +1 -0
  8. package/dist/{chunk-HPJ2CRVK.js → chunk-OVXPDSMT.js} +315 -27
  9. package/dist/chunk-OVXPDSMT.js.map +1 -0
  10. package/dist/docs/SKILL.md +1 -1
  11. package/dist/docs/assets/SOURCE_MAP.json +1 -1
  12. package/dist/observational-memory-3XFCO6MX-WHVD3JTT.js +3 -0
  13. package/dist/{observational-memory-5NFPG6M3-MG2OMRFW.js.map → observational-memory-3XFCO6MX-WHVD3JTT.js.map} +1 -1
  14. package/dist/observational-memory-3XFCO6MX-WVUSRO35.cjs +108 -0
  15. package/dist/{observational-memory-5NFPG6M3-L7EU4ABW.cjs.map → observational-memory-3XFCO6MX-WVUSRO35.cjs.map} +1 -1
  16. package/dist/server/handlers/agent-builder.cjs +16 -16
  17. package/dist/server/handlers/agent-builder.js +1 -1
  18. package/dist/server/handlers.cjs +2 -2
  19. package/dist/server/handlers.js +1 -1
  20. package/dist/server/server-adapter/index.cjs +16 -16
  21. package/dist/server/server-adapter/index.js +1 -1
  22. package/package.json +6 -6
  23. package/dist/chunk-HPJ2CRVK.js.map +0 -1
  24. package/dist/chunk-IPQTQESA.cjs.map +0 -1
  25. package/dist/chunk-KH7BZQVQ.cjs.map +0 -1
  26. package/dist/chunk-OV64H74M.js.map +0 -1
  27. package/dist/observational-memory-5NFPG6M3-L7EU4ABW.cjs +0 -68
  28. package/dist/observational-memory-5NFPG6M3-MG2OMRFW.js +0 -3
@@ -1,7 +1,7 @@
1
1
  import { __commonJS as __commonJS$3, require_token_error as require_token_error$2, __toESM as __toESM$3 } from './chunk-JWVHBH4H.js';
2
2
  import { __commonJS as __commonJS$1, require_token_error, __toESM } from './chunk-BZZVTO7B.js';
3
3
  import { __commonJS as __commonJS$2, require_token_error as require_token_error$1, __toESM as __toESM$1 } from './chunk-PWAXLHKP.js';
4
- import { e } from './chunk-HPJ2CRVK.js';
4
+ import { e, truncateStringByTokens, resolveToolResultValue, formatToolResultForObserver, estimateTokenCount } from './chunk-OVXPDSMT.js';
5
5
  import { openai } from './chunk-PALNMAC6.js';
6
6
  import { LIST_WORKFLOWS_ROUTE, GET_WORKFLOW_BY_ID_ROUTE, LIST_WORKFLOW_RUNS_ROUTE, GET_WORKFLOW_RUN_BY_ID_ROUTE, CREATE_WORKFLOW_RUN_ROUTE, STREAM_WORKFLOW_ROUTE, START_ASYNC_WORKFLOW_ROUTE, START_WORKFLOW_RUN_ROUTE, OBSERVE_STREAM_WORKFLOW_ROUTE, RESUME_ASYNC_WORKFLOW_ROUTE, RESUME_WORKFLOW_ROUTE, RESUME_STREAM_WORKFLOW_ROUTE, CANCEL_WORKFLOW_RUN_ROUTE, STREAM_LEGACY_WORKFLOW_ROUTE, OBSERVE_STREAM_LEGACY_WORKFLOW_ROUTE } from './chunk-OH2TKHUS.js';
7
7
  import { actionIdPathParams, actionRunPathParams, streamAgentBuilderBodySchema, startAsyncAgentBuilderBodySchema, resumeAgentBuilderBodySchema, streamLegacyAgentBuilderBodySchema } from './chunk-V7DWWIJ6.js';
@@ -22,8 +22,8 @@ import { z as z$1 } from 'zod/v4';
22
22
  import { coreFeatures } from '@mastra/core/features';
23
23
  import { MastraMemory, removeWorkingMemoryTags, extractWorkingMemoryContent } from '@mastra/core/memory';
24
24
  import { generateEmptyFromSchema } from '@mastra/core/utils';
25
- import { toStandardSchema, isStandardSchemaWithJSON as isStandardSchemaWithJSON$1 } from '@mastra/core/schema';
26
25
  import { createTool } from '@mastra/core/tools';
26
+ import { toStandardSchema, isStandardSchemaWithJSON as isStandardSchemaWithJSON$1 } from '@mastra/core/schema';
27
27
  import { exec as exec$1, execFile as execFile$1, spawn as spawn$1 } from 'child_process';
28
28
  import { mkdtemp, rm, readFile, writeFile, mkdir, copyFile, readdir, stat } from 'fs/promises';
29
29
  import { join, resolve as resolve$1, dirname, extname, basename, isAbsolute, relative } from 'path';
@@ -16117,6 +16117,426 @@ var DefaultEmbedManyResult3 = class {
16117
16117
  };
16118
16118
  createIdGenerator3({ prefix: "aiobj", size: 24 });
16119
16119
  createIdGenerator3({ prefix: "aiobj", size: 24 });
16120
+ function hasVisibleParts(msg) {
16121
+ if (typeof msg.content === "string") return msg.content.length > 0;
16122
+ const parts = msg.content?.parts;
16123
+ if (!parts || !Array.isArray(parts)) return false;
16124
+ return parts.some((p) => !p.type?.startsWith("data-"));
16125
+ }
16126
+ function parseRangeFormat(cursor) {
16127
+ if (cursor.includes(",")) {
16128
+ const parts = cursor.split(",").map((p) => p.trim()).filter(Boolean);
16129
+ if (parts.length >= 1) {
16130
+ const first = parts[0];
16131
+ const last = parts[parts.length - 1];
16132
+ const firstColon = first.indexOf(":");
16133
+ const lastColon = last.indexOf(":");
16134
+ return {
16135
+ startId: firstColon > 0 ? first.slice(0, firstColon) : first,
16136
+ endId: lastColon > 0 ? last.slice(lastColon + 1) : last
16137
+ };
16138
+ }
16139
+ }
16140
+ const colonIndex = cursor.indexOf(":");
16141
+ if (colonIndex > 0 && colonIndex < cursor.length - 1) {
16142
+ return { startId: cursor.slice(0, colonIndex), endId: cursor.slice(colonIndex + 1) };
16143
+ }
16144
+ return null;
16145
+ }
16146
+ async function resolveCursorMessage(memory, cursor) {
16147
+ const normalized = cursor.trim();
16148
+ if (!normalized) {
16149
+ throw new Error("Cursor is required");
16150
+ }
16151
+ const rangeIds = parseRangeFormat(normalized);
16152
+ if (rangeIds) {
16153
+ return {
16154
+ 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}".`,
16155
+ ...rangeIds
16156
+ };
16157
+ }
16158
+ const memoryStore = await memory.getMemoryStore();
16159
+ const result = await memoryStore.listMessagesById({ messageIds: [normalized] });
16160
+ const message = result.messages.find((message2) => message2.id === normalized);
16161
+ if (!message) {
16162
+ throw new Error(`Could not resolve cursor message: ${cursor}`);
16163
+ }
16164
+ return message;
16165
+ }
16166
+ var LOW_DETAIL_PART_TOKENS = 30;
16167
+ var AUTO_EXPAND_TEXT_TOKENS = 100;
16168
+ var AUTO_EXPAND_TOOL_TOKENS = 20;
16169
+ var HIGH_DETAIL_TOOL_RESULT_TOKENS = 4e3;
16170
+ var DEFAULT_MAX_RESULT_TOKENS = 2e3;
16171
+ function formatTimestamp(date) {
16172
+ return date.toISOString().replace("T", " ").replace(/\.\d{3}Z$/, "Z");
16173
+ }
16174
+ function truncateByTokens(text42, maxTokens, hint) {
16175
+ if (estimateTokenCount(text42) <= maxTokens) return { text: text42, wasTruncated: false };
16176
+ const truncated = truncateStringByTokens(text42, maxTokens);
16177
+ const suffix = hint ? ` [${hint} for more]` : "";
16178
+ return { text: truncated + suffix, wasTruncated: true };
16179
+ }
16180
+ function lowDetailPartLimit(type) {
16181
+ if (type === "text") return AUTO_EXPAND_TEXT_TOKENS;
16182
+ if (type === "tool-result" || type === "tool-call") return AUTO_EXPAND_TOOL_TOKENS;
16183
+ return LOW_DETAIL_PART_TOKENS;
16184
+ }
16185
+ function makePart(msg, partIndex, type, fullText, detail) {
16186
+ if (detail === "high") {
16187
+ return { messageId: msg.id, partIndex, role: msg.role, type, text: fullText, fullText };
16188
+ }
16189
+ const hint = `recall cursor="${msg.id}" partIndex=${partIndex} detail="high"`;
16190
+ const { text: text42 } = truncateByTokens(fullText, lowDetailPartLimit(type), hint);
16191
+ return { messageId: msg.id, partIndex, role: msg.role, type, text: text42, fullText };
16192
+ }
16193
+ function formatMessageParts(msg, detail) {
16194
+ const parts = [];
16195
+ if (typeof msg.content === "string") {
16196
+ parts.push(makePart(msg, 0, "text", msg.content, detail));
16197
+ return parts;
16198
+ }
16199
+ if (msg.content?.parts && Array.isArray(msg.content.parts)) {
16200
+ for (let i = 0; i < msg.content.parts.length; i++) {
16201
+ const part = msg.content.parts[i];
16202
+ const partType = part.type;
16203
+ if (partType === "text") {
16204
+ const text42 = part.text;
16205
+ parts.push(makePart(msg, i, "text", text42, detail));
16206
+ } else if (partType === "tool-invocation") {
16207
+ const inv = part.toolInvocation;
16208
+ if (inv.state === "result") {
16209
+ const { value: resultValue } = resolveToolResultValue(
16210
+ part,
16211
+ inv.result
16212
+ );
16213
+ const resultStr = formatToolResultForObserver(resultValue, { maxTokens: HIGH_DETAIL_TOOL_RESULT_TOKENS });
16214
+ const fullText = `[Tool Result: ${inv.toolName}]
16215
+ ${resultStr}`;
16216
+ parts.push(makePart(msg, i, "tool-result", fullText, detail));
16217
+ } else {
16218
+ const argsStr = detail === "low" ? "" : `
16219
+ ${JSON.stringify(inv.args, null, 2)}`;
16220
+ const fullText = `[Tool Call: ${inv.toolName}]${argsStr}`;
16221
+ parts.push({ messageId: msg.id, partIndex: i, role: msg.role, type: "tool-call", text: fullText, fullText });
16222
+ }
16223
+ } else if (partType === "reasoning") {
16224
+ const reasoning = part.reasoning;
16225
+ if (reasoning) {
16226
+ parts.push(makePart(msg, i, "reasoning", reasoning, detail));
16227
+ }
16228
+ } else if (partType === "image" || partType === "file") {
16229
+ const filename = part.filename;
16230
+ const label = filename ? `: ${filename}` : "";
16231
+ const fullText = `[${partType === "image" ? "Image" : "File"}${label}]`;
16232
+ parts.push({ messageId: msg.id, partIndex: i, role: msg.role, type: partType, text: fullText, fullText });
16233
+ } else if (partType?.startsWith("data-")) ;
16234
+ else if (partType) {
16235
+ const fullText = `[${partType}]`;
16236
+ parts.push({ messageId: msg.id, partIndex: i, role: msg.role, type: partType, text: fullText, fullText });
16237
+ }
16238
+ }
16239
+ } else if (msg.content?.content) {
16240
+ parts.push(makePart(msg, 0, "text", msg.content.content, detail));
16241
+ }
16242
+ return parts;
16243
+ }
16244
+ function buildRenderedText(parts, timestamps) {
16245
+ let currentMessageId = "";
16246
+ const lines = [];
16247
+ for (const part of parts) {
16248
+ if (part.messageId !== currentMessageId) {
16249
+ currentMessageId = part.messageId;
16250
+ const ts = timestamps.get(part.messageId);
16251
+ const tsStr = ts ? ` (${formatTimestamp(ts)})` : "";
16252
+ if (lines.length > 0) lines.push("");
16253
+ lines.push(`**${part.role}${tsStr}** [${part.messageId}]:`);
16254
+ }
16255
+ const indexLabel = `[p${part.partIndex}]`;
16256
+ lines.push(` ${indexLabel} ${part.text}`);
16257
+ }
16258
+ return lines.join("\n");
16259
+ }
16260
+ var MAX_EXPAND_USER_TEXT_TOKENS = 200;
16261
+ var MAX_EXPAND_OTHER_TOKENS = 50;
16262
+ function expandLimit(part) {
16263
+ if (part.role === "user" && part.type === "text") return MAX_EXPAND_USER_TEXT_TOKENS;
16264
+ return MAX_EXPAND_OTHER_TOKENS;
16265
+ }
16266
+ function expandPriority(part) {
16267
+ if (part.role === "user" && part.type === "text") return 0;
16268
+ if (part.type === "text" || part.type === "reasoning") return 1;
16269
+ if (part.type === "tool-result") return 2;
16270
+ if (part.type === "tool-call") return 3;
16271
+ return 4;
16272
+ }
16273
+ function renderFormattedParts(parts, timestamps, options) {
16274
+ const text42 = buildRenderedText(parts, timestamps);
16275
+ let totalTokens = estimateTokenCount(text42);
16276
+ if (totalTokens > options.maxTokens) {
16277
+ const truncated = truncateStringByTokens(text42, options.maxTokens);
16278
+ return { text: truncated, truncated: true, tokenOffset: totalTokens - options.maxTokens };
16279
+ }
16280
+ 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));
16281
+ if (truncatedIndices.length === 0) {
16282
+ return { text: text42, truncated: false, tokenOffset: 0 };
16283
+ }
16284
+ let remaining = options.maxTokens - totalTokens;
16285
+ for (const { part, index } of truncatedIndices) {
16286
+ if (remaining <= 0) break;
16287
+ const maxTokens = expandLimit(part);
16288
+ const fullTokens = estimateTokenCount(part.fullText);
16289
+ const currentTokens = estimateTokenCount(part.text);
16290
+ const targetTokens = Math.min(fullTokens, maxTokens);
16291
+ const delta = targetTokens - currentTokens;
16292
+ if (delta <= 0) continue;
16293
+ if (delta <= remaining && targetTokens >= fullTokens) {
16294
+ parts[index] = { ...part, text: part.fullText };
16295
+ remaining -= delta;
16296
+ } else {
16297
+ const expandedLimit = Math.min(currentTokens + remaining, maxTokens);
16298
+ const hint = `recall cursor="${part.messageId}" partIndex=${part.partIndex} detail="high"`;
16299
+ const { text: expanded2 } = truncateByTokens(part.fullText, expandedLimit, hint);
16300
+ const expandedDelta = estimateTokenCount(expanded2) - currentTokens;
16301
+ parts[index] = { ...part, text: expanded2 };
16302
+ remaining -= expandedDelta;
16303
+ }
16304
+ }
16305
+ const expanded = buildRenderedText(parts, timestamps);
16306
+ const expandedTokens = estimateTokenCount(expanded);
16307
+ if (expandedTokens <= options.maxTokens) {
16308
+ return { text: expanded, truncated: false, tokenOffset: 0 };
16309
+ }
16310
+ const hardTruncated = truncateStringByTokens(expanded, options.maxTokens);
16311
+ return { text: hardTruncated, truncated: true, tokenOffset: expandedTokens - options.maxTokens };
16312
+ }
16313
+ async function recallPart({
16314
+ memory,
16315
+ threadId,
16316
+ cursor,
16317
+ partIndex,
16318
+ maxTokens = DEFAULT_MAX_RESULT_TOKENS
16319
+ }) {
16320
+ if (!memory || typeof memory.getMemoryStore !== "function") {
16321
+ throw new Error("Memory instance is required for recall");
16322
+ }
16323
+ if (!threadId) {
16324
+ throw new Error("Thread ID is required for recall");
16325
+ }
16326
+ const resolved = await resolveCursorMessage(memory, cursor);
16327
+ if ("hint" in resolved) {
16328
+ throw new Error(resolved.hint);
16329
+ }
16330
+ if (resolved.threadId !== threadId) {
16331
+ throw new Error("The requested cursor does not belong to the current thread");
16332
+ }
16333
+ const allParts = formatMessageParts(resolved, "high");
16334
+ if (allParts.length === 0) {
16335
+ throw new Error(
16336
+ `Message ${cursor} has no visible content (it may be an internal system message). Try a neighboring message ID instead.`
16337
+ );
16338
+ }
16339
+ const target = allParts.find((p) => p.partIndex === partIndex);
16340
+ if (!target) {
16341
+ throw new Error(
16342
+ `Part index ${partIndex} not found in message ${cursor}. Available indices: ${allParts.map((p) => p.partIndex).join(", ")}`
16343
+ );
16344
+ }
16345
+ const truncatedText = truncateStringByTokens(target.text, maxTokens);
16346
+ const wasTruncated = truncatedText !== target.text;
16347
+ return {
16348
+ text: truncatedText,
16349
+ messageId: target.messageId,
16350
+ partIndex: target.partIndex,
16351
+ role: target.role,
16352
+ type: target.type,
16353
+ truncated: wasTruncated
16354
+ };
16355
+ }
16356
+ async function recallMessages({
16357
+ memory,
16358
+ threadId,
16359
+ resourceId,
16360
+ cursor,
16361
+ page = 1,
16362
+ limit = 20,
16363
+ detail = "low",
16364
+ maxTokens = DEFAULT_MAX_RESULT_TOKENS
16365
+ }) {
16366
+ if (!memory) {
16367
+ throw new Error("Memory instance is required for recall");
16368
+ }
16369
+ if (!threadId) {
16370
+ throw new Error("Thread ID is required for recall");
16371
+ }
16372
+ if (typeof memory.getMemoryStore !== "function") {
16373
+ throw new Error("recall requires a Memory instance with storage access");
16374
+ }
16375
+ const MAX_PAGE = 50;
16376
+ const MAX_LIMIT = 20;
16377
+ const rawPage = page === 0 ? 1 : page;
16378
+ const normalizedPage = Math.max(Math.min(rawPage, MAX_PAGE), -MAX_PAGE);
16379
+ const normalizedLimit = Math.min(limit, MAX_LIMIT);
16380
+ const resolved = await resolveCursorMessage(memory, cursor);
16381
+ if ("hint" in resolved) {
16382
+ return {
16383
+ messages: resolved.hint,
16384
+ count: 0,
16385
+ cursor,
16386
+ page: normalizedPage,
16387
+ limit: normalizedLimit,
16388
+ detail,
16389
+ hasNextPage: false,
16390
+ hasPrevPage: false,
16391
+ truncated: false,
16392
+ tokenOffset: 0
16393
+ };
16394
+ }
16395
+ const anchor = resolved;
16396
+ if (anchor.threadId !== threadId) {
16397
+ throw new Error("The requested cursor does not belong to the current thread");
16398
+ }
16399
+ const isForward = normalizedPage > 0;
16400
+ const pageIndex = Math.max(Math.abs(normalizedPage), 1) - 1;
16401
+ const skip = pageIndex * normalizedLimit;
16402
+ const fetchCount = skip + normalizedLimit + 1;
16403
+ const result = await memory.recall({
16404
+ threadId,
16405
+ resourceId,
16406
+ page: 0,
16407
+ perPage: fetchCount,
16408
+ orderBy: { field: "createdAt", direction: isForward ? "ASC" : "DESC" },
16409
+ filter: {
16410
+ dateRange: isForward ? {
16411
+ start: anchor.createdAt,
16412
+ startExclusive: true
16413
+ } : {
16414
+ end: anchor.createdAt,
16415
+ endExclusive: true
16416
+ }
16417
+ }
16418
+ });
16419
+ const visibleMessages = result.messages.filter(hasVisibleParts);
16420
+ const total = visibleMessages.length;
16421
+ const hasMore = total > skip + normalizedLimit;
16422
+ let messages;
16423
+ if (isForward) {
16424
+ messages = visibleMessages.slice(skip, skip + normalizedLimit);
16425
+ } else {
16426
+ const endIdx = Math.max(total - skip, 0);
16427
+ const startIdx = Math.max(endIdx - normalizedLimit, 0);
16428
+ messages = visibleMessages.slice(startIdx, endIdx);
16429
+ }
16430
+ const hasNextPage = isForward ? hasMore : pageIndex > 0;
16431
+ const hasPrevPage = isForward ? pageIndex > 0 : hasMore;
16432
+ const allParts = [];
16433
+ const timestamps = /* @__PURE__ */ new Map();
16434
+ for (const msg of messages) {
16435
+ timestamps.set(msg.id, msg.createdAt);
16436
+ allParts.push(...formatMessageParts(msg, detail));
16437
+ }
16438
+ if (detail === "high" && allParts.length > 0) {
16439
+ const firstPart = allParts[0];
16440
+ const sameMsgParts = allParts.filter((p) => p.messageId === firstPart.messageId);
16441
+ const otherMsgParts = allParts.filter((p) => p.messageId !== firstPart.messageId);
16442
+ const rendered2 = renderFormattedParts([firstPart], timestamps, { maxTokens });
16443
+ let text42 = rendered2.text;
16444
+ const hints = [];
16445
+ if (sameMsgParts.length > 1) {
16446
+ const nextPart = sameMsgParts[1];
16447
+ hints.push(`next part: partIndex=${nextPart.partIndex} on cursor="${firstPart.messageId}"`);
16448
+ }
16449
+ if (otherMsgParts.length > 0) {
16450
+ const next = otherMsgParts[0];
16451
+ hints.push(`next message: partIndex=${next.partIndex} on cursor="${next.messageId}"`);
16452
+ } else if (hasNextPage) {
16453
+ hints.push(`more messages available on page ${normalizedPage + 1}`);
16454
+ }
16455
+ if (hints.length > 0) {
16456
+ text42 += `
16457
+
16458
+ High detail returns 1 part at a time. To continue: ${hints.join(", or ")}.`;
16459
+ }
16460
+ return {
16461
+ messages: text42,
16462
+ count: 1,
16463
+ cursor,
16464
+ page: normalizedPage,
16465
+ limit: normalizedLimit,
16466
+ detail,
16467
+ hasNextPage: otherMsgParts.length > 0 || hasNextPage,
16468
+ hasPrevPage,
16469
+ truncated: rendered2.truncated,
16470
+ tokenOffset: rendered2.tokenOffset
16471
+ };
16472
+ }
16473
+ const rendered = renderFormattedParts(allParts, timestamps, { maxTokens });
16474
+ return {
16475
+ messages: rendered.text,
16476
+ count: messages.length,
16477
+ cursor,
16478
+ page: normalizedPage,
16479
+ limit: normalizedLimit,
16480
+ detail,
16481
+ hasNextPage,
16482
+ hasPrevPage,
16483
+ truncated: rendered.truncated,
16484
+ tokenOffset: rendered.tokenOffset
16485
+ };
16486
+ }
16487
+ var recallTool = (_memoryConfig) => {
16488
+ return createTool({
16489
+ id: "recall",
16490
+ 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.',
16491
+ inputSchema: z.object({
16492
+ cursor: 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."),
16493
+ page: z.number().int().min(-50).max(50).optional().describe(
16494
+ "Pagination offset from the cursor. Positive pages move forward, negative pages move backward, and 0 is treated as 1."
16495
+ ),
16496
+ limit: z.number().int().positive().max(20).optional().describe("Maximum number of messages to return. Defaults to 20."),
16497
+ detail: z.enum(["low", "high"]).optional().describe(
16498
+ 'Detail level. "low" (default) returns truncated text and tool names. "high" returns full content with tool args/results.'
16499
+ ),
16500
+ partIndex: z.number().int().min(0).optional().describe(
16501
+ "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."
16502
+ )
16503
+ }),
16504
+ execute: async ({
16505
+ cursor,
16506
+ page,
16507
+ limit,
16508
+ detail,
16509
+ partIndex
16510
+ }, context2) => {
16511
+ const memory = context2?.memory;
16512
+ const threadId = context2?.agent?.threadId;
16513
+ const resourceId = context2?.agent?.resourceId;
16514
+ if (!memory) {
16515
+ throw new Error("Memory instance is required for recall");
16516
+ }
16517
+ if (!threadId) {
16518
+ throw new Error("Thread ID is required for recall");
16519
+ }
16520
+ if (partIndex !== void 0 && partIndex !== null) {
16521
+ return recallPart({
16522
+ memory,
16523
+ threadId,
16524
+ cursor,
16525
+ partIndex
16526
+ });
16527
+ }
16528
+ return recallMessages({
16529
+ memory,
16530
+ threadId,
16531
+ resourceId,
16532
+ cursor,
16533
+ page,
16534
+ limit,
16535
+ detail: detail ?? "low"
16536
+ });
16537
+ }
16538
+ });
16539
+ };
16120
16540
  function deepMergeWorkingMemory(existing, update) {
16121
16541
  if (!update || typeof update !== "object" || Object.keys(update).length === 0) {
16122
16542
  return existing && typeof existing === "object" ? { ...existing } : {};
@@ -17096,15 +17516,15 @@ Notes:
17096
17516
  }
17097
17517
  listTools(config) {
17098
17518
  const mergedConfig = this.getMergedThreadConfig(config);
17519
+ const tools = {};
17099
17520
  if (mergedConfig.workingMemory?.enabled && !mergedConfig.readOnly) {
17100
- return {
17101
- updateWorkingMemory: this.isVNextWorkingMemoryConfig(mergedConfig) ? (
17102
- // use the new experimental tool
17103
- __experimental_updateWorkingMemoryToolVNext(mergedConfig)
17104
- ) : updateWorkingMemoryTool(mergedConfig)
17105
- };
17521
+ tools.updateWorkingMemory = this.isVNextWorkingMemoryConfig(mergedConfig) ? __experimental_updateWorkingMemoryToolVNext(mergedConfig) : updateWorkingMemoryTool(mergedConfig);
17106
17522
  }
17107
- return {};
17523
+ const omConfig = normalizeObservationalMemoryConfig(mergedConfig.observationalMemory);
17524
+ if (omConfig?.retrieval && (omConfig.scope ?? "thread") === "thread") {
17525
+ tools.recall = recallTool();
17526
+ }
17527
+ return tools;
17108
17528
  }
17109
17529
  /**
17110
17530
  * Updates a list of messages and syncs the vector database for semantic recall.
@@ -17686,10 +18106,11 @@ Notes:
17686
18106
  "Observational memory requires @mastra/core support for request-response-id-rotation. Please bump @mastra/core to a newer version."
17687
18107
  );
17688
18108
  }
17689
- const { ObservationalMemory } = await import('./observational-memory-5NFPG6M3-MG2OMRFW.js');
18109
+ const { ObservationalMemory } = await import('./observational-memory-3XFCO6MX-WHVD3JTT.js');
17690
18110
  return new ObservationalMemory({
17691
18111
  storage: memoryStore,
17692
18112
  scope: omConfig.scope,
18113
+ retrieval: omConfig.retrieval,
17693
18114
  shareTokenBudget: omConfig.shareTokenBudget,
17694
18115
  model: omConfig.model,
17695
18116
  observation: omConfig.observation ? {
@@ -28914,5 +29335,5 @@ var OBSERVE_STREAM_LEGACY_AGENT_BUILDER_ACTION_ROUTE = createRoute({
28914
29335
  });
28915
29336
 
28916
29337
  export { CANCEL_AGENT_BUILDER_ACTION_RUN_ROUTE, CREATE_AGENT_BUILDER_ACTION_RUN_ROUTE, GET_AGENT_BUILDER_ACTION_BY_ID_ROUTE, GET_AGENT_BUILDER_ACTION_RUN_BY_ID_ROUTE, LIST_AGENT_BUILDER_ACTIONS_ROUTE, LIST_AGENT_BUILDER_ACTION_RUNS_ROUTE, OBSERVE_STREAM_AGENT_BUILDER_ACTION_ROUTE, OBSERVE_STREAM_LEGACY_AGENT_BUILDER_ACTION_ROUTE, RESUME_AGENT_BUILDER_ACTION_ROUTE, RESUME_ASYNC_AGENT_BUILDER_ACTION_ROUTE, RESUME_STREAM_AGENT_BUILDER_ACTION_ROUTE, START_AGENT_BUILDER_ACTION_RUN_ROUTE, START_ASYNC_AGENT_BUILDER_ACTION_ROUTE, STREAM_AGENT_BUILDER_ACTION_ROUTE, STREAM_LEGACY_AGENT_BUILDER_ACTION_ROUTE, agent_builder_exports };
28917
- //# sourceMappingURL=chunk-OV64H74M.js.map
28918
- //# sourceMappingURL=chunk-OV64H74M.js.map
29338
+ //# sourceMappingURL=chunk-DVOXGNVI.js.map
29339
+ //# sourceMappingURL=chunk-DVOXGNVI.js.map