@mastra/server 1.72.0-alpha.9 → 1.73.0-alpha.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.
Files changed (97) hide show
  1. package/dist/{a2a-D2BffGsK.js → a2a-Dyd6lbnr.js} +35 -23
  2. package/dist/a2a-Dyd6lbnr.js.map +1 -0
  3. package/dist/{a2a-CAQVpVxH.cjs → a2a-rSyYjbA3.cjs} +35 -24
  4. package/dist/a2a-rSyYjbA3.cjs.map +1 -0
  5. package/dist/{api-schema-manifest-C9mzZvwb.cjs → api-schema-manifest-azbFW2gh.cjs} +2 -2
  6. package/dist/{api-schema-manifest-C9mzZvwb.cjs.map → api-schema-manifest-azbFW2gh.cjs.map} +1 -1
  7. package/dist/{api-schema-manifest-CeSyB2uX.js → api-schema-manifest-btfn_x2G.js} +2 -2
  8. package/dist/{api-schema-manifest-CeSyB2uX.js.map → api-schema-manifest-btfn_x2G.js.map} +1 -1
  9. package/dist/{dist-CYk5xS3y.js → dist-B2EGPe0Y.js} +219 -42
  10. package/dist/dist-B2EGPe0Y.js.map +1 -0
  11. package/dist/{dist-CRMvLG_8.cjs → dist-BJfoL3Lt.cjs} +219 -43
  12. package/dist/dist-BJfoL3Lt.cjs.map +1 -0
  13. package/dist/docs/SKILL.md +2 -1
  14. package/dist/docs/assets/SOURCE_MAP.json +1 -1
  15. package/dist/docs/references/docs-guides-mcp-authentication-authorization.md +136 -0
  16. package/dist/{observability-new-endpoints-BnLi_Bdm.cjs → observability-new-endpoints-7Zd6uEZf.cjs} +106 -1
  17. package/dist/observability-new-endpoints-7Zd6uEZf.cjs.map +1 -0
  18. package/dist/{observability-new-endpoints-aUBFBO-b.js → observability-new-endpoints-lNC3o66-.js} +102 -3
  19. package/dist/observability-new-endpoints-lNC3o66-.js.map +1 -0
  20. package/dist/{processors-88oJ_4J-.js → processors-33IULT8X.js} +7 -4
  21. package/dist/processors-33IULT8X.js.map +1 -0
  22. package/dist/{processors-D6lRjS0e.cjs → processors-80HWq8nr.cjs} +7 -4
  23. package/dist/processors-80HWq8nr.cjs.map +1 -0
  24. package/dist/{routes-T4x5ibCy.cjs → routes-BaQVELB2.cjs} +4 -3
  25. package/dist/routes-BaQVELB2.cjs.map +1 -0
  26. package/dist/{routes-D5OKIMYe.js → routes-BqoNkLiT.js} +4 -3
  27. package/dist/routes-BqoNkLiT.js.map +1 -0
  28. package/dist/server/a2a/agent-card-signing.d.ts.map +1 -1
  29. package/dist/server/handlers/a2a.cjs +1 -1
  30. package/dist/server/handlers/a2a.js +1 -1
  31. package/dist/server/handlers/agent-builder.cjs +1 -1
  32. package/dist/server/handlers/agent-builder.js +1 -1
  33. package/dist/server/handlers/agents.cjs +2 -2
  34. package/dist/server/handlers/agents.cjs.map +1 -1
  35. package/dist/server/handlers/agents.d.ts.map +1 -1
  36. package/dist/server/handlers/agents.js +3 -3
  37. package/dist/server/handlers/agents.js.map +1 -1
  38. package/dist/server/handlers/conversations.cjs +1 -2
  39. package/dist/server/handlers/conversations.cjs.map +1 -1
  40. package/dist/server/handlers/conversations.d.ts.map +1 -1
  41. package/dist/server/handlers/conversations.js +1 -2
  42. package/dist/server/handlers/conversations.js.map +1 -1
  43. package/dist/server/handlers/observability-new-endpoints.cjs +2 -1
  44. package/dist/server/handlers/observability-new-endpoints.d.ts +96 -0
  45. package/dist/server/handlers/observability-new-endpoints.d.ts.map +1 -1
  46. package/dist/server/handlers/observability-new-endpoints.js +2 -2
  47. package/dist/server/handlers/observability-shared.cjs +17 -0
  48. package/dist/server/handlers/observability-shared.cjs.map +1 -1
  49. package/dist/server/handlers/observability-shared.d.ts +9 -0
  50. package/dist/server/handlers/observability-shared.d.ts.map +1 -1
  51. package/dist/server/handlers/observability-shared.js +16 -1
  52. package/dist/server/handlers/observability-shared.js.map +1 -1
  53. package/dist/server/handlers/observability.cjs +3 -1
  54. package/dist/server/handlers/observability.cjs.map +1 -1
  55. package/dist/server/handlers/observability.js +3 -2
  56. package/dist/server/handlers/observability.js.map +1 -1
  57. package/dist/server/handlers/processors.cjs +3 -1
  58. package/dist/server/handlers/processors.cjs.map +1 -1
  59. package/dist/server/handlers/processors.d.ts +6 -3
  60. package/dist/server/handlers/processors.d.ts.map +1 -1
  61. package/dist/server/handlers/processors.js +3 -1
  62. package/dist/server/handlers/processors.js.map +1 -1
  63. package/dist/server/handlers/responses.adapter.cjs +1 -2
  64. package/dist/server/handlers/responses.adapter.cjs.map +1 -1
  65. package/dist/server/handlers/responses.adapter.d.ts.map +1 -1
  66. package/dist/server/handlers/responses.adapter.js +1 -2
  67. package/dist/server/handlers/responses.adapter.js.map +1 -1
  68. package/dist/server/handlers/responses.cjs +1 -2
  69. package/dist/server/handlers/responses.cjs.map +1 -1
  70. package/dist/server/handlers/responses.d.ts.map +1 -1
  71. package/dist/server/handlers/responses.js +1 -2
  72. package/dist/server/handlers/responses.js.map +1 -1
  73. package/dist/server/handlers/system.cjs +1 -1
  74. package/dist/server/handlers/system.js +1 -1
  75. package/dist/server/handlers.cjs +1 -1
  76. package/dist/server/handlers.js +1 -1
  77. package/dist/server/schemas/index.cjs +1 -1
  78. package/dist/server/schemas/index.js +1 -1
  79. package/dist/server/schemas/processors.d.ts +4 -0
  80. package/dist/server/schemas/processors.d.ts.map +1 -1
  81. package/dist/server/server-adapter/index.cjs +1 -1
  82. package/dist/server/server-adapter/index.js +1 -1
  83. package/dist/server/server-adapter/routes/observability.d.ts +95 -0
  84. package/dist/server/server-adapter/routes/observability.d.ts.map +1 -1
  85. package/dist/server/server-adapter/routes/processors.d.ts +6 -3
  86. package/dist/server/server-adapter/routes/processors.d.ts.map +1 -1
  87. package/package.json +9 -9
  88. package/dist/a2a-CAQVpVxH.cjs.map +0 -1
  89. package/dist/a2a-D2BffGsK.js.map +0 -1
  90. package/dist/dist-CRMvLG_8.cjs.map +0 -1
  91. package/dist/dist-CYk5xS3y.js.map +0 -1
  92. package/dist/observability-new-endpoints-BnLi_Bdm.cjs.map +0 -1
  93. package/dist/observability-new-endpoints-aUBFBO-b.js.map +0 -1
  94. package/dist/processors-88oJ_4J-.js.map +0 -1
  95. package/dist/processors-D6lRjS0e.cjs.map +0 -1
  96. package/dist/routes-D5OKIMYe.js.map +0 -1
  97. package/dist/routes-T4x5ibCy.cjs.map +0 -1
@@ -14,8 +14,6 @@ let _mastra_core_error = require("@mastra/core/error");
14
14
  let _mastra_core_llm = require("@mastra/core/llm");
15
15
  let _mastra_core_tools = require("@mastra/core/tools");
16
16
  let util = require("util");
17
- let crypto$1 = require("crypto");
18
- crypto$1 = require_rolldown_runtime.__toESM(crypto$1, 1);
19
17
  let _mastra_core_request_context = require("@mastra/core/request-context");
20
18
  let _mastra_core_utils = require("@mastra/core/utils");
21
19
  let _mastra_core_storage = require("@mastra/core/storage");
@@ -26,6 +24,7 @@ let _mastra_core_workflows = require("@mastra/core/workflows");
26
24
  let fs = require("fs");
27
25
  let os = require("os");
28
26
  let path = require("path");
27
+ let crypto$1 = require("crypto");
29
28
  let module$1 = require("module");
30
29
  let diagnostics_channel = require("diagnostics_channel");
31
30
  let async_hooks = require("async_hooks");
@@ -4638,7 +4637,7 @@ function splitLines(text) {
4638
4637
  return result;
4639
4638
  }
4640
4639
  //#endregion
4641
- //#region ../memory/dist/src-BdfOygyn.js
4640
+ //#region ../memory/dist/src-BYAwbfUo.js
4642
4641
  var __defProp$3 = Object.defineProperty;
4643
4642
  var __exportAll = (all, no_symbols) => {
4644
4643
  let target = {};
@@ -20236,6 +20235,10 @@ if (OM_DEBUG_LOG) {
20236
20235
  };
20237
20236
  }
20238
20237
  const SUBCONSCIOUS_ACTIVITY_STATE_ID = "subconscious-activity";
20238
+ async function hashContents(contents) {
20239
+ const digest = await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(contents));
20240
+ return Buffer.from(digest).toString("hex");
20241
+ }
20239
20242
  async function getActivityTarget(store, event, scope) {
20240
20243
  if (event.recordType === "node") {
20241
20244
  const node = await store.getNode(event.recordId);
@@ -20337,7 +20340,7 @@ async function publishSubconsciousError(input) {
20337
20340
  await input.sendStateSignal({
20338
20341
  id: SUBCONSCIOUS_ACTIVITY_STATE_ID,
20339
20342
  mode: "snapshot",
20340
- cacheKey: (0, crypto$1.createHash)("sha256").update(contents).digest("hex"),
20343
+ cacheKey: await hashContents(contents),
20341
20344
  tagName: "state",
20342
20345
  attributes: { id: SUBCONSCIOUS_ACTIVITY_STATE_ID },
20343
20346
  metadata: { origin: "subconscious" },
@@ -20349,7 +20352,7 @@ async function publishSubconsciousActivity(input) {
20349
20352
  if (!input.sendStateSignal) return void 0;
20350
20353
  const snapshot = await buildSubconsciousActivitySnapshot(input);
20351
20354
  const contents = renderSubconsciousActivity(snapshot);
20352
- const cacheKey = (0, crypto$1.createHash)("sha256").update(contents).digest("hex");
20355
+ const cacheKey = await hashContents(contents);
20353
20356
  await input.sendStateSignal({
20354
20357
  id: SUBCONSCIOUS_ACTIVITY_STATE_ID,
20355
20358
  mode: "snapshot",
@@ -22060,7 +22063,7 @@ function createAskMemoryTool(options) {
22060
22063
  status: "rejected",
22061
22064
  error: `ask_memory could not resolve calling agent ${parentAgentId} from the registered runtime.`
22062
22065
  };
22063
- const replyId = `subconscious:remind:${crypto$1.default.randomUUID()}:reply`;
22066
+ const replyId = `subconscious:remind:${crypto.randomUUID()}:reply`;
22064
22067
  try {
22065
22068
  const scope = resolveKnowledgeToolScope(context);
22066
22069
  const model = await resolveSubconsciousAgentModel({
@@ -22197,7 +22200,7 @@ function createReplyToMemoryQuestionTool(options) {
22197
22200
  reason: "already-terminal"
22198
22201
  };
22199
22202
  const trimmedAnswer = answer.trim();
22200
- const signalId = `${replyId}:${moreComing ? `partial:${crypto$1.default.createHash("sha256").update(trimmedAnswer).digest("hex").slice(0, 12)}` : "terminal"}:signal`;
22203
+ const signalId = `${replyId}:${moreComing ? `partial:${Buffer.from(await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(trimmedAnswer))).toString("hex").slice(0, 12)}` : "terminal"}:signal`;
22201
22204
  if (deliveredSignalIds.has(signalId)) return {
22202
22205
  delivered: true,
22203
22206
  replyId,
@@ -25827,7 +25830,7 @@ function optimizeObservationsForContext(observations) {
25827
25830
  }
25828
25831
  function createTemporaryOmMemoryContext(prefix) {
25829
25832
  const options = {
25830
- thread: `${prefix}-${(0, crypto$1.randomUUID)()}`,
25833
+ thread: `${prefix}-${globalThis.crypto.randomUUID()}`,
25831
25834
  resource: prefix,
25832
25835
  options: {
25833
25836
  lastMessages: 10,
@@ -26670,6 +26673,10 @@ function isLikelyBase64Content(value) {
26670
26673
  if (value.length < 16 || value.length % 4 !== 0 || /\s/.test(value) || isLikelyFilesystemPath(value)) return false;
26671
26674
  return /^[A-Za-z0-9+/]+={0,2}$/.test(value);
26672
26675
  }
26676
+ /**
26677
+ * Decodes a stored attachment payload (data URI, raw base64, Buffer, or typed array) into bytes.
26678
+ * Returns undefined for remote URLs, filesystem paths, and anything that isn't a decodable payload.
26679
+ */
26673
26680
  function decodeImageBuffer(value) {
26674
26681
  if (typeof Buffer !== "undefined" && Buffer.isBuffer(value)) return value;
26675
26682
  if (value instanceof Uint8Array) return Buffer.from(value);
@@ -28531,6 +28538,145 @@ function makePart(msg, partIndex, type, fullText, detail, toolName) {
28531
28538
  toolName
28532
28539
  };
28533
28540
  }
28541
+ const PROVIDER_FILE_ID_PATTERN = /^file-[A-Za-z0-9_-]+$/;
28542
+ const REUSABLE_URL_PATTERN = /^[a-z][a-z0-9+.-]*:\/\/\S+$/i;
28543
+ const DATA_URI_PATTERN = /^data:([^;,]*)/i;
28544
+ const INLINE_DATA_OMITTED = "(inline data omitted)";
28545
+ /**
28546
+ * Reads the payload and media type of a stored image/file part. Stored parts use the v4
28547
+ * (`data`/`mimeType`) or v5 (`url`/`mediaType`) shape; prompt-style image parts carry the
28548
+ * payload in `image`. A data URI's header supplies the media type when none was stored.
28549
+ */
28550
+ function readAttachmentPayload(part) {
28551
+ const payload = part.image ?? part.data ?? part.url;
28552
+ const payloadString = payload instanceof URL ? payload.href : typeof payload === "string" ? payload.trim() : "";
28553
+ const dataUriMatch = DATA_URI_PATTERN.exec(payloadString);
28554
+ const mediaType = [
28555
+ part.mimeType,
28556
+ part.mediaType,
28557
+ dataUriMatch?.[1]
28558
+ ].find((v) => typeof v === "string" && v.length > 0);
28559
+ const hasBytes = payload instanceof Uint8Array || payload instanceof ArrayBuffer;
28560
+ return {
28561
+ payload,
28562
+ payloadString,
28563
+ isDataUri: dataUriMatch !== null,
28564
+ hasBytes,
28565
+ mediaType
28566
+ };
28567
+ }
28568
+ /** Returns the reference text for a payload the agent can reuse, or undefined for inline data. */
28569
+ function describeReusableReference(payloadString) {
28570
+ if (PROVIDER_FILE_ID_PATTERN.test(payloadString)) return `file id: ${payloadString}`;
28571
+ if (REUSABLE_URL_PATTERN.test(payloadString)) return `url: ${payloadString}`;
28572
+ }
28573
+ /**
28574
+ * Renders an image/file part with its media type and, when the stored payload is a reusable
28575
+ * reference (URL or provider file ID), that reference so the agent can reuse the attachment.
28576
+ * Inline payloads (data URIs, base64, bytes) are never rendered.
28577
+ */
28578
+ function formatAttachmentPart(partType, part) {
28579
+ const filename = typeof part.filename === "string" && part.filename ? `: ${part.filename}` : "";
28580
+ const { payloadString, isDataUri, hasBytes, mediaType } = readAttachmentPayload(part);
28581
+ let reference = "";
28582
+ if (!isDataUri && payloadString) reference = describeReusableReference(payloadString) ?? INLINE_DATA_OMITTED;
28583
+ else if (isDataUri || hasBytes) reference = INLINE_DATA_OMITTED;
28584
+ return [
28585
+ `[${partType === "image" ? "Image" : "File"}${filename}]`,
28586
+ mediaType,
28587
+ reference
28588
+ ].filter(Boolean).join(" ");
28589
+ }
28590
+ const INLINE_MEDIA_PART_TYPES = /* @__PURE__ */ new Set([
28591
+ "media",
28592
+ "image-data",
28593
+ "file-data",
28594
+ "image",
28595
+ "file"
28596
+ ]);
28597
+ /**
28598
+ * Replaces inline media payloads nested in a stored tool result (for example a `media` part in
28599
+ * `modelOutput`, or a viewed attachment) with a placeholder, so rendering the result as text never
28600
+ * dumps base64. URLs and provider file IDs are kept because the agent can reuse them.
28601
+ */
28602
+ function omitInlineMediaPayloads(value, seen = /* @__PURE__ */ new WeakMap()) {
28603
+ if (typeof value !== "object" || value === null) return value;
28604
+ if (seen.has(value)) return seen.get(value);
28605
+ if (Array.isArray(value)) {
28606
+ const items = [];
28607
+ seen.set(value, items);
28608
+ for (const item of value) items.push(omitInlineMediaPayloads(item, seen));
28609
+ return items;
28610
+ }
28611
+ const record = value;
28612
+ const isMediaPart = typeof record.type === "string" && INLINE_MEDIA_PART_TYPES.has(record.type);
28613
+ const result = {};
28614
+ seen.set(value, result);
28615
+ for (const [key, entry] of Object.entries(record)) if (isMediaPart && (key === "data" || key === "image") && typeof entry === "string" && !describeReusableReference(entry.trim())) result[key] = INLINE_DATA_OMITTED;
28616
+ else result[key] = omitInlineMediaPayloads(entry, seen);
28617
+ return result;
28618
+ }
28619
+ /**
28620
+ * Media types the model can be handed directly. Mirrors the observational memory observer's
28621
+ * default `observeAttachments` allowlist — anything else (docx, pptx, video, …) is not a type
28622
+ * providers accept as an inline part, so it stays text-only.
28623
+ */
28624
+ function isViewableAttachmentMediaType(mediaType) {
28625
+ if (!mediaType) return false;
28626
+ const normalized = mediaType.toLowerCase();
28627
+ return normalized.startsWith("image/") || normalized === "application/pdf";
28628
+ }
28629
+ /** Mirrors core's DEFAULT_MAX_MEDIA_BYTES cap on inline media results. */
28630
+ const MAX_VIEWABLE_ATTACHMENT_BYTES = 10 * 1024 * 1024;
28631
+ function isRecallAttachmentContent(value) {
28632
+ if (typeof value !== "object" || value === null) return false;
28633
+ const content = value.content;
28634
+ if (!Array.isArray(content) || content.length !== 2) return false;
28635
+ return content.every((part) => {
28636
+ if (typeof part !== "object" || part === null) return false;
28637
+ const { type, text, data, mimeType } = part;
28638
+ if (type === "text") return typeof text === "string";
28639
+ return (type === "image" || type === "file") && typeof data === "string" && typeof mimeType === "string";
28640
+ });
28641
+ }
28642
+ /**
28643
+ * Turns an attachment part into a model-viewable payload. Only inline payloads are returned, as
28644
+ * base64 bytes. Everything else — remote URLs, provider file IDs, oversized payloads, unsupported
28645
+ * media types — comes back as an explanation for the agent instead.
28646
+ */
28647
+ function resolveViewableAttachment(part) {
28648
+ const { payload, payloadString, isDataUri, hasBytes, mediaType } = readAttachmentPayload(part);
28649
+ if (!payloadString && !hasBytes) return { note: "This attachment has no stored payload to show." };
28650
+ if (!isViewableAttachmentMediaType(mediaType)) return { note: mediaType ? `Attachments of type ${mediaType} can't be shown inline. Use the attachment's url or file id if you need to reference it.` : "This attachment has no media type recorded, so it can't be shown inline." };
28651
+ if (isHttpUrlString(payloadString)) return { note: "This attachment is stored at a remote URL, so it can't be shown inline. Use its url if you need to reference it." };
28652
+ if (payloadString.length * .75 > MAX_VIEWABLE_ATTACHMENT_BYTES) return { note: "This attachment is too large to show inline." };
28653
+ const bytes = decodeImageBuffer(isDataUri ? `data:${payloadString.slice(5)}` : payloadString || payload);
28654
+ if (!bytes) return { note: "This attachment's payload is not inline data, so it can't be shown." };
28655
+ if (bytes.byteLength > MAX_VIEWABLE_ATTACHMENT_BYTES) return { note: "This attachment is too large to show inline." };
28656
+ return {
28657
+ data: bytes.toString("base64"),
28658
+ mimeType: mediaType
28659
+ };
28660
+ }
28661
+ /**
28662
+ * Presents a resolved attachment to the model as a native base64 `media` part alongside its text
28663
+ * description.
28664
+ */
28665
+ function recallAttachmentToModelOutput(output) {
28666
+ if (!isRecallAttachmentContent(output)) return void 0;
28667
+ const [textPart, attachment] = output.content;
28668
+ return {
28669
+ type: "content",
28670
+ value: [{
28671
+ type: "text",
28672
+ text: textPart.text
28673
+ }, {
28674
+ type: "media",
28675
+ data: attachment.data,
28676
+ mediaType: attachment.mimeType
28677
+ }]
28678
+ };
28679
+ }
28534
28680
  function formatMessageParts(msg, detail) {
28535
28681
  const parts = [];
28536
28682
  if (typeof msg.content === "string") {
@@ -28563,7 +28709,7 @@ function formatMessageParts(msg, detail) {
28563
28709
  }
28564
28710
  if (inv.state === "result") {
28565
28711
  const { value: resultValue } = resolveToolResultValue(part, inv.result);
28566
- const resultStr = formatToolResultForObserver(resultValue, { maxTokens: HIGH_DETAIL_TOOL_RESULT_TOKENS });
28712
+ const resultStr = formatToolResultForObserver(omitInlineMediaPayloads(resultValue), { maxTokens: HIGH_DETAIL_TOOL_RESULT_TOKENS });
28567
28713
  const fullText = `[Tool Result: ${inv.toolName}]\n${resultStr}`;
28568
28714
  parts.push(makePart(msg, i, "tool-result", fullText, detail, inv.toolName));
28569
28715
  }
@@ -28586,25 +28732,14 @@ function formatMessageParts(msg, detail) {
28586
28732
  } else if (partType === "tool-result") {
28587
28733
  const toolName = part.toolName;
28588
28734
  if (toolName) {
28589
- const fullText = `[Tool Result: ${toolName}]\n${formatToolResultForObserver(part.output ?? part.result, { maxTokens: HIGH_DETAIL_TOOL_RESULT_TOKENS })}`;
28735
+ const fullText = `[Tool Result: ${toolName}]\n${formatToolResultForObserver(omitInlineMediaPayloads(part.output ?? part.result), { maxTokens: HIGH_DETAIL_TOOL_RESULT_TOKENS })}`;
28590
28736
  parts.push(makePart(msg, i, "tool-result", fullText, detail, toolName));
28591
28737
  }
28592
28738
  } else if (partType === "reasoning") {
28593
28739
  const reasoning = part.reasoning ?? part.text;
28594
28740
  if (reasoning) parts.push(makePart(msg, i, "reasoning", reasoning, detail));
28595
- } else if (partType === "image" || partType === "file") {
28596
- const filename = part.filename;
28597
- const label = filename ? `: ${filename}` : "";
28598
- const fullText = `[${partType === "image" ? "Image" : "File"}${label}]`;
28599
- parts.push({
28600
- messageId: msg.id,
28601
- partIndex: i,
28602
- role: msg.role,
28603
- type: partType,
28604
- text: fullText,
28605
- fullText
28606
- });
28607
- } else if (partType?.startsWith("data-")) {} else if (partType) {
28741
+ } else if (partType === "image" || partType === "file") parts.push(makePart(msg, i, partType, formatAttachmentPart(partType, part), detail));
28742
+ else if (partType?.startsWith("data-")) {} else if (partType) {
28608
28743
  const fullText = `[${partType}]`;
28609
28744
  parts.push({
28610
28745
  messageId: msg.id,
@@ -28777,6 +28912,29 @@ async function recallPart({ memory, threadId, resourceId, cursor, partIndex, cha
28777
28912
  note
28778
28913
  };
28779
28914
  }
28915
+ async function recallAttachmentView({ memory, threadId, resourceId, cursor, partIndex, threadScope, retrievalScope = "thread" }) {
28916
+ if (!memory || typeof memory.getMemoryStore !== "function") throw new Error("Memory instance is required for recall");
28917
+ if (!threadId) throw new Error("Thread ID is required for recall");
28918
+ const resolved = await resolveCursorMessage(memory, cursor, {
28919
+ resourceId,
28920
+ threadScope,
28921
+ enforceThreadScope: retrievalScope !== "resource"
28922
+ });
28923
+ if ("hint" in resolved) return { messages: resolved.hint };
28924
+ const rawPart = getMessageParts(resolved)[partIndex];
28925
+ const partType = rawPart?.type;
28926
+ if (!rawPart || partType !== "image" && partType !== "file") return { messages: `Part ${partIndex} of message ${cursor} is ${rawPart ? `a ${partType ?? "unknown"}-type part` : "missing"}, not an attachment. Call recall with the same cursor and partIndex without viewAttachment to read it.` };
28927
+ const resolvedAttachment = resolveViewableAttachment(rawPart);
28928
+ if ("note" in resolvedAttachment) return { messages: `${formatAttachmentPart(partType, rawPart)} — ${resolvedAttachment.note}` };
28929
+ return { content: [{
28930
+ type: "text",
28931
+ text: formatAttachmentPart(partType, rawPart)
28932
+ }, {
28933
+ type: partType === "image" ? "image" : "file",
28934
+ data: resolvedAttachment.data,
28935
+ mimeType: resolvedAttachment.mimeType
28936
+ }] };
28937
+ }
28780
28938
  async function recallMessages({ memory, threadId, resourceId, cursor, page = 1, limit = 20, detail = "low", partType, toolName, threadScope, retrievalScope = "thread", maxTokens = DEFAULT_MAX_RESULT_TOKENS }) {
28781
28939
  if (!memory) throw new Error("Memory instance is required for recall");
28782
28940
  if (!threadId) throw new Error("Thread ID is required for recall");
@@ -29062,11 +29220,15 @@ const recallTool = (_memoryConfig, options) => {
29062
29220
  type: "integer",
29063
29221
  minimum: 0,
29064
29222
  description: "Continue reading a truncated single part from this position. Pass the exact nextCharOffset value returned by a previous call; do not compute it yourself. Only applies with cursor and partIndex in mode=\"messages\"."
29223
+ },
29224
+ viewAttachment: {
29225
+ type: "boolean",
29226
+ description: "Show the actual attachment instead of just describing it. Requires cursor and partIndex, and only applies when that part is an image or file. Use it after recall shows you an attachment you need to look at."
29065
29227
  }
29066
29228
  }
29067
29229
  },
29068
29230
  execute: async (inputData, context) => {
29069
- const { mode, query, cursor, threadId: explicitThreadId, anchor, page, limit, detail, partType, toolName, partIndex, charOffset, before, after } = inputData;
29231
+ const { mode, query, cursor, threadId: explicitThreadId, anchor, page, limit, detail, partType, toolName, partIndex, charOffset, before, after, viewAttachment } = inputData;
29070
29232
  const memory = context?.memory;
29071
29233
  const currentThreadId = context?.agent?.threadId;
29072
29234
  const resourceId = context?.agent?.resourceId;
@@ -29155,6 +29317,7 @@ const recallTool = (_memoryConfig, options) => {
29155
29317
  targetThreadId = resolved.threadId;
29156
29318
  }
29157
29319
  if (!targetThreadId) throw new Error("Thread ID is required for recall");
29320
+ if (viewAttachment && (!cursor || partIndex === void 0 || partIndex === null)) return { messages: "viewAttachment needs both cursor and partIndex so it knows which attachment to show. Call recall with cursor, partIndex, and viewAttachment: true." };
29158
29321
  if (!cursor) {
29159
29322
  const result = await recallThreadFromStart({
29160
29323
  memory,
@@ -29173,16 +29336,27 @@ const recallTool = (_memoryConfig, options) => {
29173
29336
  };
29174
29337
  return result;
29175
29338
  }
29176
- if (partIndex !== void 0 && partIndex !== null) return recallPart({
29177
- memory,
29178
- threadId: targetThreadId,
29179
- resourceId,
29180
- cursor,
29181
- partIndex,
29182
- charOffset,
29183
- threadScope,
29184
- retrievalScope
29185
- });
29339
+ if (partIndex !== void 0 && partIndex !== null) {
29340
+ if (viewAttachment) return recallAttachmentView({
29341
+ memory,
29342
+ threadId: targetThreadId,
29343
+ resourceId,
29344
+ cursor,
29345
+ partIndex,
29346
+ threadScope,
29347
+ retrievalScope
29348
+ });
29349
+ return recallPart({
29350
+ memory,
29351
+ threadId: targetThreadId,
29352
+ resourceId,
29353
+ cursor,
29354
+ partIndex,
29355
+ charOffset,
29356
+ threadScope,
29357
+ retrievalScope
29358
+ });
29359
+ }
29186
29360
  return recallMessages({
29187
29361
  memory,
29188
29362
  threadId: targetThreadId,
@@ -29196,7 +29370,8 @@ const recallTool = (_memoryConfig, options) => {
29196
29370
  threadScope,
29197
29371
  retrievalScope
29198
29372
  });
29199
- }
29373
+ },
29374
+ toModelOutput: recallAttachmentToModelOutput
29200
29375
  });
29201
29376
  };
29202
29377
  /**
@@ -30139,7 +30314,7 @@ function stripReflectionGroupMetadata(body) {
30139
30314
  return body.replace(/^_range:\s*`[^`]*`_\s*\n?/m, "").trim();
30140
30315
  }
30141
30316
  function generateAnchorId() {
30142
- return (0, crypto$1.randomBytes)(8).toString("hex");
30317
+ return Buffer.from(globalThis.crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(8))).toString("hex");
30143
30318
  }
30144
30319
  function wrapInObservationGroup(observations, range, id = generateAnchorId(), _sourceGroupIds, kind) {
30145
30320
  const content = observations.trim();
@@ -33463,7 +33638,7 @@ function inferReproIdRemap(preMessages, postMessages) {
33463
33638
  }
33464
33639
  function createOmReproCaptureDir(threadId, label) {
33465
33640
  const sanitizedThreadId = sanitizeCapturePathSegment(threadId);
33466
- const captureDir = (0, path.join)(process.cwd(), getOmReproCaptureDir(), sanitizedThreadId, `${Date.now()}-${label}-${(0, crypto$1.randomUUID)()}`);
33641
+ const captureDir = (0, path.join)(process.cwd(), getOmReproCaptureDir(), sanitizedThreadId, `${Date.now()}-${label}-${globalThis.crypto.randomUUID()}`);
33467
33642
  (0, fs.mkdirSync)(captureDir, { recursive: true });
33468
33643
  return captureDir;
33469
33644
  }
@@ -37988,18 +38163,19 @@ Notes:
37988
38163
  const embedResult = await this.embedMessageContent(text);
37989
38164
  if (embedResult.embeddings.length === 0 || embedResult.dimension === void 0) return;
37990
38165
  const { indexName } = await this.createObservationEmbeddingIndex(embedResult.dimension);
37991
- const ids = embedResult.chunks.map((_, chunkIndex) => {
37992
- const hash = (0, crypto$1.createHash)("sha256").update(JSON.stringify([
38166
+ const ids = [];
38167
+ for (const [chunkIndex] of embedResult.chunks.entries()) {
38168
+ const hash = Buffer.from(await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(JSON.stringify([
37993
38169
  resourceId,
37994
38170
  threadId,
37995
38171
  groupId,
37996
38172
  chunkIndex
37997
- ])).digest();
38173
+ ]))));
37998
38174
  hash[6] = hash[6] & 15 | 128;
37999
38175
  hash[8] = hash[8] & 63 | 128;
38000
38176
  const hex = hash.toString("hex", 0, 16);
38001
- return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
38002
- });
38177
+ ids.push(`${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`);
38178
+ }
38003
38179
  await this.vector.upsert({
38004
38180
  indexName,
38005
38181
  ids,
@@ -49654,4 +49830,4 @@ const agentBuilderWorkflows = {
49654
49830
  //#endregion
49655
49831
  exports.agentBuilderWorkflows = agentBuilderWorkflows;
49656
49832
 
49657
- //# sourceMappingURL=dist-CRMvLG_8.cjs.map
49833
+ //# sourceMappingURL=dist-BJfoL3Lt.cjs.map