@mastra/memory 1.14.0 → 1.15.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/{chunk-ZVRO2GUN.cjs → chunk-ANKEPFC6.cjs} +545 -391
  3. package/dist/chunk-ANKEPFC6.cjs.map +1 -0
  4. package/dist/{chunk-GXDPND6K.js → chunk-ZEKCVX4E.js} +546 -392
  5. package/dist/chunk-ZEKCVX4E.js.map +1 -0
  6. package/dist/docs/SKILL.md +1 -1
  7. package/dist/docs/assets/SOURCE_MAP.json +35 -35
  8. package/dist/index.cjs +142 -50
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.js +136 -44
  11. package/dist/index.js.map +1 -1
  12. package/dist/{observational-memory-IRCDSDUB.cjs → observational-memory-NKF66CFX.cjs} +26 -26
  13. package/dist/{observational-memory-IRCDSDUB.cjs.map → observational-memory-NKF66CFX.cjs.map} +1 -1
  14. package/dist/{observational-memory-OVRHDQRG.js → observational-memory-S6YN56D3.js} +3 -3
  15. package/dist/{observational-memory-OVRHDQRG.js.map → observational-memory-S6YN56D3.js.map} +1 -1
  16. package/dist/processors/index.cjs +24 -24
  17. package/dist/processors/index.js +1 -1
  18. package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -1
  19. package/dist/processors/observational-memory/observer-agent.d.ts.map +1 -1
  20. package/dist/processors/observational-memory/processor.d.ts.map +1 -1
  21. package/dist/processors/observational-memory/repro-capture.d.ts +8 -0
  22. package/dist/processors/observational-memory/repro-capture.d.ts.map +1 -1
  23. package/dist/tools/om-tools.d.ts +14 -2
  24. package/dist/tools/om-tools.d.ts.map +1 -1
  25. package/package.json +3 -3
  26. package/dist/chunk-GXDPND6K.js.map +0 -1
  27. package/dist/chunk-ZVRO2GUN.cjs.map +0 -1
@@ -12,9 +12,9 @@ var crypto$1 = require('crypto');
12
12
  var tokenx = require('tokenx');
13
13
  var agent = require('@mastra/core/agent');
14
14
  var observability = require('@mastra/core/observability');
15
+ var util = require('util');
15
16
  var async_hooks = require('async_hooks');
16
17
  var imageSize = require('image-size');
17
- var util = require('util');
18
18
 
19
19
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
20
20
 
@@ -2929,11 +2929,13 @@ var OBSERVER_IMAGE_FILE_EXTENSIONS = /* @__PURE__ */ new Set([
2929
2929
  "heif",
2930
2930
  "avif"
2931
2931
  ]);
2932
- function formatObserverTimestamp(createdAt) {
2933
- return createdAt ? new Date(createdAt).toLocaleString("en-US", {
2934
- year: "numeric",
2935
- month: "short",
2936
- day: "numeric",
2932
+ function formatObserverDate(createdAt) {
2933
+ return createdAt ? `${createdAt.toLocaleDateString("en-US", {
2934
+ month: "short"
2935
+ })} ${createdAt.getDate()} ${createdAt.getFullYear()}` : "";
2936
+ }
2937
+ function formatObserverTime(createdAt) {
2938
+ return createdAt ? createdAt.toLocaleTimeString("en-US", {
2937
2939
  hour: "numeric",
2938
2940
  minute: "2-digit",
2939
2941
  hour12: true
@@ -3024,19 +3026,72 @@ function formatObserverAttachmentPlaceholder(part, counter) {
3024
3026
  const label = resolveObserverAttachmentLabel(part);
3025
3027
  return label ? `[${attachmentType} #${attachmentId}: ${label}]` : `[${attachmentType} #${attachmentId}]`;
3026
3028
  }
3029
+ function formatObserverPartLine(title, body, time, previousTime) {
3030
+ const timeLabel = time && time !== previousTime ? ` (${time})` : "";
3031
+ return `${title}${timeLabel}: ${body}`;
3032
+ }
3033
+ function normalizeObserverCreatedAt(createdAt) {
3034
+ if (createdAt instanceof Date) {
3035
+ if (Number.isNaN(createdAt.getTime())) {
3036
+ return void 0;
3037
+ }
3038
+ return createdAt;
3039
+ }
3040
+ if (typeof createdAt === "number" || typeof createdAt === "string") {
3041
+ const date = new Date(createdAt);
3042
+ if (Number.isNaN(date.getTime())) {
3043
+ return void 0;
3044
+ }
3045
+ return date;
3046
+ }
3047
+ return void 0;
3048
+ }
3049
+ function formatObserverLines(lines, context = {}) {
3050
+ const output = [];
3051
+ let previousDate = context.previousDate;
3052
+ let previousTime = context.previousTime;
3053
+ for (const line of lines) {
3054
+ if (line.date && line.date !== previousDate) {
3055
+ output.push(`${line.date}:`);
3056
+ previousDate = line.date;
3057
+ previousTime = void 0;
3058
+ }
3059
+ output.push(formatObserverPartLine(line.title, line.body, line.time, previousTime));
3060
+ previousTime = line.time || previousTime;
3061
+ }
3062
+ return {
3063
+ text: output.join("\n"),
3064
+ context: { previousDate, previousTime }
3065
+ };
3066
+ }
3027
3067
  function formatObserverMessage(msg, counter, options) {
3028
3068
  const maxLen = options?.maxPartLength;
3029
3069
  const maxToolResultTokens = options?.maxToolResultTokens ?? DEFAULT_OBSERVER_TOOL_RESULT_MAX_TOKENS;
3030
- const timestamp = formatObserverTimestamp(msg.createdAt);
3031
3070
  const role = msg.role.charAt(0).toUpperCase() + msg.role.slice(1);
3032
- const timestampStr = timestamp ? ` (${timestamp})` : "";
3033
3071
  const attachments = [];
3034
- let content = "";
3072
+ const messageCreatedAt = normalizeObserverCreatedAt(msg.createdAt);
3073
+ let lines = [];
3074
+ const pushLine = (title, body, createdAt) => {
3075
+ if (!body) {
3076
+ return;
3077
+ }
3078
+ const normalizedCreatedAt = normalizeObserverCreatedAt(createdAt) ?? messageCreatedAt;
3079
+ lines.push({
3080
+ date: formatObserverDate(normalizedCreatedAt),
3081
+ time: formatObserverTime(normalizedCreatedAt),
3082
+ title,
3083
+ body
3084
+ });
3085
+ };
3035
3086
  if (typeof msg.content === "string") {
3036
- content = maybeTruncate(msg.content, maxLen);
3087
+ pushLine(role, maybeTruncate(msg.content, maxLen), messageCreatedAt);
3037
3088
  } else if (msg.content?.parts && Array.isArray(msg.content.parts) && msg.content.parts.length > 0) {
3038
- content = msg.content.parts.map((part) => {
3039
- if (part.type === "text") return maybeTruncate(part.text, maxLen);
3089
+ msg.content.parts.forEach((part) => {
3090
+ const partCreatedAt = normalizeObserverCreatedAt(part.createdAt) ?? messageCreatedAt;
3091
+ if (part.type === "text") {
3092
+ pushLine(role, maybeTruncate(part.text, maxLen), partCreatedAt);
3093
+ return;
3094
+ }
3040
3095
  if (part.type === "tool-invocation") {
3041
3096
  const inv = part.toolInvocation;
3042
3097
  if (inv.state === "result") {
@@ -3044,19 +3099,24 @@ function formatObserverMessage(msg, counter, options) {
3044
3099
  part,
3045
3100
  inv.result
3046
3101
  );
3047
- const resultStr = formatToolResultForObserver(resultForObserver, { maxTokens: maxToolResultTokens });
3048
- return `[Tool Result: ${inv.toolName}]
3049
- ${maybeTruncate(resultStr, maxLen)}`;
3102
+ pushLine(
3103
+ `Tool Result ${inv.toolName}`,
3104
+ maybeTruncate(formatToolResultForObserver(resultForObserver, { maxTokens: maxToolResultTokens }), maxLen),
3105
+ partCreatedAt
3106
+ );
3107
+ return;
3050
3108
  }
3051
- const argsStr = JSON.stringify(inv.args, null, 2);
3052
- return `[Tool Call: ${inv.toolName}]
3053
- ${maybeTruncate(argsStr, maxLen)}`;
3109
+ pushLine(`Tool Call ${inv.toolName}`, maybeTruncate(JSON.stringify(inv.args, null, 2), maxLen), partCreatedAt);
3110
+ return;
3054
3111
  }
3055
3112
  const partType = part.type;
3056
3113
  if (partType === "reasoning") {
3057
3114
  const reasoning = part.reasoning;
3058
- if (reasoning) return maybeTruncate(reasoning, maxLen);
3059
- return "";
3115
+ if (!reasoning) {
3116
+ return;
3117
+ }
3118
+ pushLine("Reasoning", maybeTruncate(reasoning, maxLen), partCreatedAt);
3119
+ return;
3060
3120
  }
3061
3121
  if (partType === "image" || partType === "file") {
3062
3122
  const attachment = part;
@@ -3064,40 +3124,58 @@ ${maybeTruncate(argsStr, maxLen)}`;
3064
3124
  if (inputAttachment) {
3065
3125
  attachments.push(inputAttachment);
3066
3126
  }
3067
- return formatObserverAttachmentPlaceholder(attachment, counter);
3127
+ pushLine(
3128
+ partType === "image" ? "Image" : "File",
3129
+ formatObserverAttachmentPlaceholder(attachment, counter),
3130
+ partCreatedAt
3131
+ );
3068
3132
  }
3069
- if (partType?.startsWith("data-")) return "";
3070
- return "";
3071
- }).filter(Boolean).join("\n");
3133
+ });
3072
3134
  } else if (msg.content?.content) {
3073
- content = maybeTruncate(msg.content.content, maxLen);
3135
+ pushLine(role, maybeTruncate(msg.content.content, maxLen), messageCreatedAt);
3074
3136
  }
3075
- if (!content && attachments.length === 0) {
3076
- return { text: "", attachments };
3137
+ if (lines.length === 0 && attachments.length === 0) {
3138
+ return { lines: [], attachments };
3077
3139
  }
3078
3140
  return {
3079
- text: `**${role}${timestampStr}:**
3080
- ${content}`,
3141
+ lines,
3081
3142
  attachments
3082
3143
  };
3083
3144
  }
3084
3145
  function formatMessagesForObserver(messages, options) {
3085
3146
  const counter = { nextImageId: 1, nextFileId: 1 };
3086
- return messages.map((msg) => formatObserverMessage(msg, counter, options).text).filter(Boolean).join("\n\n---\n\n");
3147
+ const sections = [];
3148
+ let context = {};
3149
+ for (const message of messages) {
3150
+ const formatted = formatObserverMessage(message, counter, options);
3151
+ if (formatted.lines.length === 0) {
3152
+ continue;
3153
+ }
3154
+ const rendered = formatObserverLines(formatted.lines, context);
3155
+ if (!rendered.text) {
3156
+ continue;
3157
+ }
3158
+ sections.push(rendered.text);
3159
+ context = rendered.context;
3160
+ }
3161
+ return sections.join("\n");
3162
+ }
3163
+ function appendFormattedObserverMessage(content, formatted, context) {
3164
+ const rendered = formatObserverLines(formatted.lines, context);
3165
+ if (rendered.text) {
3166
+ content.push({ type: "text", text: rendered.text });
3167
+ }
3168
+ content.push(...formatted.attachments);
3169
+ return rendered.context;
3087
3170
  }
3088
3171
  function buildObserverHistoryMessage(messages, options) {
3089
3172
  const counter = { nextImageId: 1, nextFileId: 1 };
3090
3173
  const content = [{ type: "text", text: "## New Message History to Observe\n\n" }];
3091
- let visibleCount = 0;
3174
+ let context = {};
3092
3175
  messages.forEach((message) => {
3093
3176
  const formatted = formatObserverMessage(message, counter, options);
3094
- if (!formatted.text && formatted.attachments.length === 0) return;
3095
- if (visibleCount > 0) {
3096
- content.push({ type: "text", text: "\n\n---\n\n" });
3097
- }
3098
- content.push({ type: "text", text: formatted.text });
3099
- content.push(...formatted.attachments);
3100
- visibleCount++;
3177
+ if (formatted.lines.length === 0 && formatted.attachments.length === 0) return;
3178
+ context = appendFormattedObserverMessage(content, formatted, context);
3101
3179
  });
3102
3180
  return {
3103
3181
  role: "user",
@@ -3127,18 +3205,15 @@ The following messages are from ${threadOrder.length} different conversation thr
3127
3205
  const messages = messagesByThread.get(threadId);
3128
3206
  if (!messages || messages.length === 0) return;
3129
3207
  const threadContent = [];
3130
- let visibleCount = 0;
3208
+ let context = {};
3209
+ let hasVisibleContent = false;
3131
3210
  messages.forEach((message) => {
3132
3211
  const formatted = formatObserverMessage(message, counter, options);
3133
- if (!formatted.text && formatted.attachments.length === 0) return;
3134
- if (visibleCount > 0) {
3135
- threadContent.push({ type: "text", text: "\n\n---\n\n" });
3136
- }
3137
- threadContent.push({ type: "text", text: formatted.text });
3138
- threadContent.push(...formatted.attachments);
3139
- visibleCount++;
3212
+ if (formatted.lines.length === 0 && formatted.attachments.length === 0) return;
3213
+ context = appendFormattedObserverMessage(threadContent, formatted, context);
3214
+ hasVisibleContent = true;
3140
3215
  });
3141
- if (visibleCount === 0) return;
3216
+ if (!hasVisibleContent) return;
3142
3217
  content.push({ type: "text", text: `<thread id="${threadId}">
3143
3218
  ` });
3144
3219
  content.push(...threadContent);
@@ -4594,101 +4669,423 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
4594
4669
  }
4595
4670
  }
4596
4671
  };
4597
- var IMAGE_FILE_EXTENSIONS = /* @__PURE__ */ new Set([
4598
- "png",
4599
- "jpg",
4600
- "jpeg",
4601
- "webp",
4602
- "gif",
4603
- "bmp",
4604
- "tiff",
4605
- "tif",
4606
- "heic",
4607
- "heif",
4608
- "avif"
4609
- ]);
4610
- var TOKEN_ESTIMATE_CACHE_VERSION = 6;
4611
- var DEFAULT_IMAGE_ESTIMATOR = {
4612
- baseTokens: 85,
4613
- tileTokens: 170,
4614
- fallbackTiles: 4
4615
- };
4616
- var GOOGLE_LEGACY_IMAGE_TOKENS_PER_TILE = 258;
4617
- var GOOGLE_GEMINI_3_IMAGE_TOKENS_BY_RESOLUTION = {
4618
- low: 280,
4619
- medium: 560,
4620
- high: 1120,
4621
- ultra_high: 2240,
4622
- unspecified: 1120
4623
- };
4624
- var ANTHROPIC_IMAGE_TOKENS_PER_PIXEL = 1 / 750;
4625
- var ANTHROPIC_IMAGE_MAX_LONG_EDGE = 1568;
4626
- var GOOGLE_MEDIA_RESOLUTION_VALUES = /* @__PURE__ */ new Set([
4627
- "low",
4628
- "medium",
4629
- "high",
4630
- "ultra_high",
4631
- "unspecified"
4632
- ]);
4633
- var ATTACHMENT_COUNT_TIMEOUT_MS = 2e4;
4634
- var REMOTE_IMAGE_PROBE_TIMEOUT_MS = 2500;
4635
- var PROVIDER_API_KEY_ENV_VARS = {
4636
- openai: ["OPENAI_API_KEY"],
4637
- google: ["GOOGLE_GENERATIVE_AI_API_KEY", "GOOGLE_API_KEY"],
4638
- anthropic: ["ANTHROPIC_API_KEY"]
4639
- };
4640
- function getPartMastraMetadata(part) {
4641
- return part.providerMetadata?.mastra;
4672
+ function getOmReproCaptureDir() {
4673
+ return process.env.OM_REPRO_CAPTURE_DIR ?? ".mastra-om-repro";
4642
4674
  }
4643
- function ensurePartMastraMetadata(part) {
4644
- const typedPart = part;
4645
- typedPart.providerMetadata ??= {};
4646
- typedPart.providerMetadata.mastra ??= {};
4647
- return typedPart.providerMetadata.mastra;
4675
+ function sanitizeCapturePathSegment(value) {
4676
+ const sanitized = value.replace(/[\\/]+/g, "_").replace(/\.{2,}/g, "_").trim();
4677
+ return sanitized.length > 0 ? sanitized : "unknown-thread";
4648
4678
  }
4649
- function getContentMastraMetadata(content) {
4650
- if (!content || typeof content !== "object") {
4651
- return void 0;
4679
+ function isOmReproCaptureEnabled() {
4680
+ return process.env.OM_REPRO_CAPTURE === "1";
4681
+ }
4682
+ function safeCaptureJson(value) {
4683
+ return JSON.parse(
4684
+ JSON.stringify(value, (_key, current) => {
4685
+ if (typeof current === "bigint") return current.toString();
4686
+ if (typeof current === "function") return "[function]";
4687
+ if (typeof current === "symbol") return current.toString();
4688
+ if (current instanceof Error) return { name: current.name, message: current.message, stack: current.stack };
4689
+ if (current instanceof Set) return { __type: "Set", values: Array.from(current.values()) };
4690
+ if (current instanceof Map) return { __type: "Map", entries: Array.from(current.entries()) };
4691
+ return current;
4692
+ })
4693
+ );
4694
+ }
4695
+ function safeCaptureJsonOrError(value) {
4696
+ try {
4697
+ return { ok: true, value: safeCaptureJson(value) };
4698
+ } catch (error) {
4699
+ return {
4700
+ ok: false,
4701
+ error: safeCaptureJson({
4702
+ message: error instanceof Error ? error.message : String(error),
4703
+ stack: error instanceof Error ? error.stack : void 0,
4704
+ inspected: util.inspect(value, { depth: 3, maxArrayLength: 20, breakLength: 120 })
4705
+ })
4706
+ };
4652
4707
  }
4653
- return content.metadata?.mastra;
4654
4708
  }
4655
- function ensureContentMastraMetadata(content) {
4656
- if (!content || typeof content !== "object") {
4709
+ function formatCaptureDate(value) {
4710
+ if (!value) return void 0;
4711
+ if (value instanceof Date) return value.toISOString();
4712
+ try {
4713
+ return new Date(value).toISOString();
4714
+ } catch {
4657
4715
  return void 0;
4658
4716
  }
4659
- const typedContent = content;
4660
- typedContent.metadata ??= {};
4661
- typedContent.metadata.mastra ??= {};
4662
- return typedContent.metadata.mastra;
4663
4717
  }
4664
- function getMessageMastraMetadata(message) {
4665
- return message.metadata?.mastra;
4718
+ function summarizeOmTurn(value) {
4719
+ if (!value || typeof value !== "object") {
4720
+ return value;
4721
+ }
4722
+ const turn = value;
4723
+ return {
4724
+ __type: "ObservationTurn",
4725
+ threadId: turn.threadId,
4726
+ resourceId: turn.resourceId,
4727
+ started: turn._started,
4728
+ ended: turn._ended,
4729
+ generationCountAtStart: turn._generationCountAtStart,
4730
+ record: turn._record ? {
4731
+ id: turn._record.id,
4732
+ scope: turn._record.scope,
4733
+ threadId: turn._record.threadId,
4734
+ resourceId: turn._record.resourceId,
4735
+ createdAt: formatCaptureDate(turn._record.createdAt),
4736
+ updatedAt: formatCaptureDate(turn._record.updatedAt),
4737
+ lastObservedAt: formatCaptureDate(turn._record.lastObservedAt),
4738
+ generationCount: turn._record.generationCount,
4739
+ observationTokenCount: turn._record.observationTokenCount,
4740
+ pendingMessageTokens: turn._record.pendingMessageTokens,
4741
+ isBufferingObservation: turn._record.isBufferingObservation,
4742
+ isBufferingReflection: turn._record.isBufferingReflection
4743
+ } : void 0,
4744
+ context: turn._context ? {
4745
+ messageCount: Array.isArray(turn._context.messages) ? turn._context.messages.length : void 0,
4746
+ hasSystemMessage: Array.isArray(turn._context.systemMessage) ? turn._context.systemMessage.length > 0 : Boolean(turn._context.systemMessage),
4747
+ continuationId: turn._context.continuation?.id,
4748
+ hasOtherThreadsContext: Boolean(turn._context.otherThreadsContext),
4749
+ recordId: turn._context.record?.id
4750
+ } : void 0,
4751
+ currentStep: turn._currentStep ? {
4752
+ stepNumber: turn._currentStep.stepNumber,
4753
+ prepared: turn._currentStep._prepared,
4754
+ context: turn._currentStep._context ? {
4755
+ activated: turn._currentStep._context.activated,
4756
+ observed: turn._currentStep._context.observed,
4757
+ buffered: turn._currentStep._context.buffered,
4758
+ reflected: turn._currentStep._context.reflected,
4759
+ didThresholdCleanup: turn._currentStep._context.didThresholdCleanup,
4760
+ messageCount: Array.isArray(turn._currentStep._context.messages) ? turn._currentStep._context.messages.length : void 0,
4761
+ systemMessageCount: Array.isArray(turn._currentStep._context.systemMessage) ? turn._currentStep._context.systemMessage.length : void 0
4762
+ } : void 0
4763
+ } : void 0
4764
+ };
4666
4765
  }
4667
- function ensureMessageMastraMetadata(message) {
4668
- const typedMessage = message;
4669
- typedMessage.metadata ??= {};
4670
- typedMessage.metadata.mastra ??= {};
4671
- return typedMessage.metadata.mastra;
4766
+ function sanitizeCaptureState(rawState) {
4767
+ return Object.fromEntries(
4768
+ Object.entries(rawState).map(([key, value]) => {
4769
+ if (key === "__omTurn") {
4770
+ return [key, summarizeOmTurn(value)];
4771
+ }
4772
+ return [key, value];
4773
+ })
4774
+ );
4672
4775
  }
4673
- function buildEstimateKey(kind, text) {
4674
- const payloadHash = crypto$1.createHash("sha1").update(text).digest("hex");
4675
- return `${kind}:${payloadHash}`;
4776
+ function buildReproMessageFingerprint(message) {
4777
+ const createdAt = message.createdAt instanceof Date ? message.createdAt.toISOString() : message.createdAt ? new Date(message.createdAt).toISOString() : "";
4778
+ return JSON.stringify({
4779
+ role: message.role,
4780
+ createdAt,
4781
+ content: message.content
4782
+ });
4676
4783
  }
4677
- function resolveEstimatorId() {
4678
- return "tokenx";
4784
+ function inferReproIdRemap(preMessages, postMessages) {
4785
+ const preByFingerprint = /* @__PURE__ */ new Map();
4786
+ const postByFingerprint = /* @__PURE__ */ new Map();
4787
+ for (const message of preMessages) {
4788
+ if (!message.id) continue;
4789
+ const fingerprint = buildReproMessageFingerprint(message);
4790
+ const list = preByFingerprint.get(fingerprint) ?? [];
4791
+ list.push(message.id);
4792
+ preByFingerprint.set(fingerprint, list);
4793
+ }
4794
+ for (const message of postMessages) {
4795
+ if (!message.id) continue;
4796
+ const fingerprint = buildReproMessageFingerprint(message);
4797
+ const list = postByFingerprint.get(fingerprint) ?? [];
4798
+ list.push(message.id);
4799
+ postByFingerprint.set(fingerprint, list);
4800
+ }
4801
+ const remap = [];
4802
+ for (const [fingerprint, preIds] of preByFingerprint.entries()) {
4803
+ const postIds = postByFingerprint.get(fingerprint);
4804
+ if (!postIds || preIds.length !== 1 || postIds.length !== 1) continue;
4805
+ const fromId = preIds[0];
4806
+ const toId = postIds[0];
4807
+ if (!fromId || !toId || fromId === toId) {
4808
+ continue;
4809
+ }
4810
+ remap.push({ fromId, toId, fingerprint });
4811
+ }
4812
+ return remap;
4679
4813
  }
4680
- function isTokenEstimateEntry(value) {
4681
- if (!value || typeof value !== "object") return false;
4682
- const entry = value;
4683
- return typeof entry.v === "number" && typeof entry.source === "string" && typeof entry.key === "string" && typeof entry.tokens === "number";
4814
+ function createOmReproCaptureDir(threadId, label) {
4815
+ const sanitizedThreadId = sanitizeCapturePathSegment(threadId);
4816
+ const captureDir = path.join(
4817
+ process.cwd(),
4818
+ getOmReproCaptureDir(),
4819
+ sanitizedThreadId,
4820
+ `${Date.now()}-${label}-${crypto$1.randomUUID()}`
4821
+ );
4822
+ fs.mkdirSync(captureDir, { recursive: true });
4823
+ return captureDir;
4684
4824
  }
4685
- function getCacheEntry(cache, key) {
4686
- if (!cache || typeof cache !== "object") return void 0;
4687
- if (isTokenEstimateEntry(cache)) {
4688
- return cache.key === key ? cache : void 0;
4825
+ function writeObserverExchangeReproCapture(params) {
4826
+ if (!isOmReproCaptureEnabled() || !params.observerExchange) {
4827
+ return;
4828
+ }
4829
+ try {
4830
+ const captureDir = createOmReproCaptureDir(params.threadId, params.label);
4831
+ const payloads = [
4832
+ {
4833
+ fileName: "input.json",
4834
+ data: {
4835
+ threadId: params.threadId,
4836
+ resourceId: params.resourceId,
4837
+ label: params.label
4838
+ }
4839
+ },
4840
+ {
4841
+ fileName: "output.json",
4842
+ data: {
4843
+ details: params.details ?? {}
4844
+ }
4845
+ },
4846
+ {
4847
+ fileName: "observer-exchange.json",
4848
+ data: params.observerExchange
4849
+ }
4850
+ ];
4851
+ const captureErrors = [];
4852
+ for (const payload of payloads) {
4853
+ const serialized = safeCaptureJsonOrError(payload.data);
4854
+ if (serialized.ok) {
4855
+ fs.writeFileSync(path.join(captureDir, payload.fileName), `${JSON.stringify(serialized.value, null, 2)}
4856
+ `);
4857
+ continue;
4858
+ }
4859
+ captureErrors.push({ fileName: payload.fileName, error: serialized.error });
4860
+ fs.writeFileSync(
4861
+ path.join(captureDir, payload.fileName),
4862
+ `${JSON.stringify({ __captureError: serialized.error }, null, 2)}
4863
+ `
4864
+ );
4865
+ }
4866
+ if (captureErrors.length > 0) {
4867
+ fs.writeFileSync(path.join(captureDir, "capture-error.json"), `${JSON.stringify(captureErrors, null, 2)}
4868
+ `);
4869
+ params.debug?.(
4870
+ `[OM:repro-capture] wrote ${params.label} capture with ${captureErrors.length} serialization error(s) to ${captureDir}`
4871
+ );
4872
+ return;
4873
+ }
4874
+ params.debug?.(`[OM:repro-capture] wrote ${params.label} capture to ${captureDir}`);
4875
+ } catch (error) {
4876
+ params.debug?.(`[OM:repro-capture] failed to write ${params.label} capture: ${String(error)}`);
4689
4877
  }
4690
- const keyedEntry = cache[key];
4691
- return isTokenEstimateEntry(keyedEntry) ? keyedEntry : void 0;
4878
+ }
4879
+ function writeProcessInputStepReproCapture(params) {
4880
+ if (!isOmReproCaptureEnabled()) {
4881
+ return;
4882
+ }
4883
+ try {
4884
+ const captureDir = createOmReproCaptureDir(params.threadId, `step-${params.stepNumber}`);
4885
+ const contextMessages = params.messageList.get.all.db();
4886
+ const memoryContext = memory.parseMemoryRequestContext(params.args.requestContext);
4887
+ const preMessageIds = new Set(params.preMessages.map((message) => message.id));
4888
+ const postMessageIds = new Set(contextMessages.map((message) => message.id));
4889
+ const removedMessageIds = params.preMessages.map((message) => message.id).filter((id) => Boolean(id) && !postMessageIds.has(id));
4890
+ const addedMessageIds = contextMessages.map((message) => message.id).filter((id) => Boolean(id) && !preMessageIds.has(id));
4891
+ const idRemap = inferReproIdRemap(params.preMessages, contextMessages);
4892
+ const rawState = params.args.state ?? {};
4893
+ const sanitizedState = sanitizeCaptureState(rawState);
4894
+ const payloads = [
4895
+ {
4896
+ fileName: "input.json",
4897
+ data: {
4898
+ stepNumber: params.stepNumber,
4899
+ threadId: params.threadId,
4900
+ resourceId: params.resourceId,
4901
+ readOnly: memoryContext?.memoryConfig?.readOnly,
4902
+ messageCount: contextMessages.length,
4903
+ messageIds: contextMessages.map((message) => message.id),
4904
+ stateKeys: Object.keys(rawState),
4905
+ state: sanitizedState,
4906
+ args: {
4907
+ messages: params.args.messages,
4908
+ steps: params.args.steps,
4909
+ systemMessages: params.args.systemMessages,
4910
+ retryCount: params.args.retryCount,
4911
+ toolChoice: params.args.toolChoice,
4912
+ activeTools: params.args.activeTools,
4913
+ modelSettings: params.args.modelSettings,
4914
+ structuredOutput: params.args.structuredOutput
4915
+ }
4916
+ }
4917
+ },
4918
+ {
4919
+ fileName: "pre-state.json",
4920
+ data: {
4921
+ record: params.preRecord,
4922
+ bufferedChunks: params.preBufferedChunks,
4923
+ contextTokenCount: params.preContextTokenCount,
4924
+ messages: params.preMessages,
4925
+ messageList: params.preSerializedMessageList
4926
+ }
4927
+ },
4928
+ {
4929
+ fileName: "output.json",
4930
+ data: {
4931
+ details: params.details,
4932
+ messageDiff: {
4933
+ removedMessageIds,
4934
+ addedMessageIds,
4935
+ idRemap
4936
+ }
4937
+ }
4938
+ },
4939
+ {
4940
+ fileName: "post-state.json",
4941
+ data: {
4942
+ record: params.postRecord,
4943
+ bufferedChunks: params.postBufferedChunks,
4944
+ contextTokenCount: params.postContextTokenCount,
4945
+ messageCount: contextMessages.length,
4946
+ messageIds: contextMessages.map((message) => message.id),
4947
+ messages: contextMessages,
4948
+ messageList: params.messageList.serialize()
4949
+ }
4950
+ }
4951
+ ];
4952
+ const captureErrors = [];
4953
+ for (const payload of payloads) {
4954
+ const serialized = safeCaptureJsonOrError(payload.data);
4955
+ if (serialized.ok) {
4956
+ fs.writeFileSync(path.join(captureDir, payload.fileName), `${JSON.stringify(serialized.value, null, 2)}
4957
+ `);
4958
+ continue;
4959
+ }
4960
+ captureErrors.push({ fileName: payload.fileName, error: serialized.error });
4961
+ fs.writeFileSync(
4962
+ path.join(captureDir, payload.fileName),
4963
+ `${JSON.stringify({ __captureError: serialized.error }, null, 2)}
4964
+ `
4965
+ );
4966
+ }
4967
+ if (params.observerExchange) {
4968
+ const serialized = safeCaptureJsonOrError(params.observerExchange);
4969
+ if (serialized.ok) {
4970
+ fs.writeFileSync(path.join(captureDir, "observer-exchange.json"), `${JSON.stringify(serialized.value, null, 2)}
4971
+ `);
4972
+ } else {
4973
+ captureErrors.push({ fileName: "observer-exchange.json", error: serialized.error });
4974
+ fs.writeFileSync(
4975
+ path.join(captureDir, "observer-exchange.json"),
4976
+ `${JSON.stringify({ __captureError: serialized.error }, null, 2)}
4977
+ `
4978
+ );
4979
+ }
4980
+ }
4981
+ if (captureErrors.length > 0) {
4982
+ fs.writeFileSync(path.join(captureDir, "capture-error.json"), `${JSON.stringify(captureErrors, null, 2)}
4983
+ `);
4984
+ params.debug?.(
4985
+ `[OM:repro-capture] wrote processInputStep capture with ${captureErrors.length} serialization error(s) to ${captureDir}`
4986
+ );
4987
+ return;
4988
+ }
4989
+ params.debug?.(`[OM:repro-capture] wrote processInputStep capture to ${captureDir}`);
4990
+ } catch (error) {
4991
+ params.debug?.(`[OM:repro-capture] failed to write processInputStep capture: ${String(error)}`);
4992
+ }
4993
+ }
4994
+ var IMAGE_FILE_EXTENSIONS = /* @__PURE__ */ new Set([
4995
+ "png",
4996
+ "jpg",
4997
+ "jpeg",
4998
+ "webp",
4999
+ "gif",
5000
+ "bmp",
5001
+ "tiff",
5002
+ "tif",
5003
+ "heic",
5004
+ "heif",
5005
+ "avif"
5006
+ ]);
5007
+ var TOKEN_ESTIMATE_CACHE_VERSION = 6;
5008
+ var DEFAULT_IMAGE_ESTIMATOR = {
5009
+ baseTokens: 85,
5010
+ tileTokens: 170,
5011
+ fallbackTiles: 4
5012
+ };
5013
+ var GOOGLE_LEGACY_IMAGE_TOKENS_PER_TILE = 258;
5014
+ var GOOGLE_GEMINI_3_IMAGE_TOKENS_BY_RESOLUTION = {
5015
+ low: 280,
5016
+ medium: 560,
5017
+ high: 1120,
5018
+ ultra_high: 2240,
5019
+ unspecified: 1120
5020
+ };
5021
+ var ANTHROPIC_IMAGE_TOKENS_PER_PIXEL = 1 / 750;
5022
+ var ANTHROPIC_IMAGE_MAX_LONG_EDGE = 1568;
5023
+ var GOOGLE_MEDIA_RESOLUTION_VALUES = /* @__PURE__ */ new Set([
5024
+ "low",
5025
+ "medium",
5026
+ "high",
5027
+ "ultra_high",
5028
+ "unspecified"
5029
+ ]);
5030
+ var ATTACHMENT_COUNT_TIMEOUT_MS = 2e4;
5031
+ var REMOTE_IMAGE_PROBE_TIMEOUT_MS = 2500;
5032
+ var PROVIDER_API_KEY_ENV_VARS = {
5033
+ openai: ["OPENAI_API_KEY"],
5034
+ google: ["GOOGLE_GENERATIVE_AI_API_KEY", "GOOGLE_API_KEY"],
5035
+ anthropic: ["ANTHROPIC_API_KEY"]
5036
+ };
5037
+ function getPartMastraMetadata(part) {
5038
+ return part.providerMetadata?.mastra;
5039
+ }
5040
+ function ensurePartMastraMetadata(part) {
5041
+ const typedPart = part;
5042
+ typedPart.providerMetadata ??= {};
5043
+ typedPart.providerMetadata.mastra ??= {};
5044
+ return typedPart.providerMetadata.mastra;
5045
+ }
5046
+ function getContentMastraMetadata(content) {
5047
+ if (!content || typeof content !== "object") {
5048
+ return void 0;
5049
+ }
5050
+ return content.metadata?.mastra;
5051
+ }
5052
+ function ensureContentMastraMetadata(content) {
5053
+ if (!content || typeof content !== "object") {
5054
+ return void 0;
5055
+ }
5056
+ const typedContent = content;
5057
+ typedContent.metadata ??= {};
5058
+ typedContent.metadata.mastra ??= {};
5059
+ return typedContent.metadata.mastra;
5060
+ }
5061
+ function getMessageMastraMetadata(message) {
5062
+ return message.metadata?.mastra;
5063
+ }
5064
+ function ensureMessageMastraMetadata(message) {
5065
+ const typedMessage = message;
5066
+ typedMessage.metadata ??= {};
5067
+ typedMessage.metadata.mastra ??= {};
5068
+ return typedMessage.metadata.mastra;
5069
+ }
5070
+ function buildEstimateKey(kind, text) {
5071
+ const payloadHash = crypto$1.createHash("sha1").update(text).digest("hex");
5072
+ return `${kind}:${payloadHash}`;
5073
+ }
5074
+ function resolveEstimatorId() {
5075
+ return "tokenx";
5076
+ }
5077
+ function isTokenEstimateEntry(value) {
5078
+ if (!value || typeof value !== "object") return false;
5079
+ const entry = value;
5080
+ return typeof entry.v === "number" && typeof entry.source === "string" && typeof entry.key === "string" && typeof entry.tokens === "number";
5081
+ }
5082
+ function getCacheEntry(cache, key) {
5083
+ if (!cache || typeof cache !== "object") return void 0;
5084
+ if (isTokenEstimateEntry(cache)) {
5085
+ return cache.key === key ? cache : void 0;
5086
+ }
5087
+ const keyedEntry = cache[key];
5088
+ return isTokenEstimateEntry(keyedEntry) ? keyedEntry : void 0;
4692
5089
  }
4693
5090
  function mergeCacheEntry(cache, key, entry) {
4694
5091
  if (isTokenEstimateEntry(cache)) {
@@ -7793,6 +8190,23 @@ ${grouped}` : grouped;
7793
8190
  requestContext,
7794
8191
  observabilityContext
7795
8192
  }).run();
8193
+ if (isOmReproCaptureEnabled()) {
8194
+ writeObserverExchangeReproCapture({
8195
+ threadId,
8196
+ resourceId: record.resourceId ?? void 0,
8197
+ label: `buffer-${cycleId}`,
8198
+ observerExchange: this.observer.lastExchange,
8199
+ details: {
8200
+ cycleId,
8201
+ startedAt,
8202
+ buffered: true,
8203
+ candidateMessageIds: candidateMessages.map((message) => message.id),
8204
+ candidateMessageCount: candidateMessages.length,
8205
+ pendingTokens: currentTokens,
8206
+ newTokens
8207
+ }
8208
+ });
8209
+ }
7796
8210
  await this.storage.setBufferingObservationFlag(record.id, false, newTokens).catch(() => {
7797
8211
  });
7798
8212
  flagCleared = true;
@@ -8188,266 +8602,6 @@ ${grouped}` : grouped;
8188
8602
  });
8189
8603
  }
8190
8604
  };
8191
- var OM_REPRO_CAPTURE_DIR = process.env.OM_REPRO_CAPTURE_DIR ?? ".mastra-om-repro";
8192
- function sanitizeCapturePathSegment(value) {
8193
- const sanitized = value.replace(/[\\/]+/g, "_").replace(/\.{2,}/g, "_").trim();
8194
- return sanitized.length > 0 ? sanitized : "unknown-thread";
8195
- }
8196
- function isOmReproCaptureEnabled() {
8197
- return process.env.OM_REPRO_CAPTURE === "1";
8198
- }
8199
- function safeCaptureJson(value) {
8200
- return JSON.parse(
8201
- JSON.stringify(value, (_key, current) => {
8202
- if (typeof current === "bigint") return current.toString();
8203
- if (typeof current === "function") return "[function]";
8204
- if (typeof current === "symbol") return current.toString();
8205
- if (current instanceof Error) return { name: current.name, message: current.message, stack: current.stack };
8206
- if (current instanceof Set) return { __type: "Set", values: Array.from(current.values()) };
8207
- if (current instanceof Map) return { __type: "Map", entries: Array.from(current.entries()) };
8208
- return current;
8209
- })
8210
- );
8211
- }
8212
- function safeCaptureJsonOrError(value) {
8213
- try {
8214
- return { ok: true, value: safeCaptureJson(value) };
8215
- } catch (error) {
8216
- return {
8217
- ok: false,
8218
- error: safeCaptureJson({
8219
- message: error instanceof Error ? error.message : String(error),
8220
- stack: error instanceof Error ? error.stack : void 0,
8221
- inspected: util.inspect(value, { depth: 3, maxArrayLength: 20, breakLength: 120 })
8222
- })
8223
- };
8224
- }
8225
- }
8226
- function formatCaptureDate(value) {
8227
- if (!value) return void 0;
8228
- if (value instanceof Date) return value.toISOString();
8229
- try {
8230
- return new Date(value).toISOString();
8231
- } catch {
8232
- return void 0;
8233
- }
8234
- }
8235
- function summarizeOmTurn(value) {
8236
- if (!value || typeof value !== "object") {
8237
- return value;
8238
- }
8239
- const turn = value;
8240
- return {
8241
- __type: "ObservationTurn",
8242
- threadId: turn.threadId,
8243
- resourceId: turn.resourceId,
8244
- started: turn._started,
8245
- ended: turn._ended,
8246
- generationCountAtStart: turn._generationCountAtStart,
8247
- record: turn._record ? {
8248
- id: turn._record.id,
8249
- scope: turn._record.scope,
8250
- threadId: turn._record.threadId,
8251
- resourceId: turn._record.resourceId,
8252
- createdAt: formatCaptureDate(turn._record.createdAt),
8253
- updatedAt: formatCaptureDate(turn._record.updatedAt),
8254
- lastObservedAt: formatCaptureDate(turn._record.lastObservedAt),
8255
- generationCount: turn._record.generationCount,
8256
- observationTokenCount: turn._record.observationTokenCount,
8257
- pendingMessageTokens: turn._record.pendingMessageTokens,
8258
- isBufferingObservation: turn._record.isBufferingObservation,
8259
- isBufferingReflection: turn._record.isBufferingReflection
8260
- } : void 0,
8261
- context: turn._context ? {
8262
- messageCount: Array.isArray(turn._context.messages) ? turn._context.messages.length : void 0,
8263
- hasSystemMessage: Array.isArray(turn._context.systemMessage) ? turn._context.systemMessage.length > 0 : Boolean(turn._context.systemMessage),
8264
- continuationId: turn._context.continuation?.id,
8265
- hasOtherThreadsContext: Boolean(turn._context.otherThreadsContext),
8266
- recordId: turn._context.record?.id
8267
- } : void 0,
8268
- currentStep: turn._currentStep ? {
8269
- stepNumber: turn._currentStep.stepNumber,
8270
- prepared: turn._currentStep._prepared,
8271
- context: turn._currentStep._context ? {
8272
- activated: turn._currentStep._context.activated,
8273
- observed: turn._currentStep._context.observed,
8274
- buffered: turn._currentStep._context.buffered,
8275
- reflected: turn._currentStep._context.reflected,
8276
- didThresholdCleanup: turn._currentStep._context.didThresholdCleanup,
8277
- messageCount: Array.isArray(turn._currentStep._context.messages) ? turn._currentStep._context.messages.length : void 0,
8278
- systemMessageCount: Array.isArray(turn._currentStep._context.systemMessage) ? turn._currentStep._context.systemMessage.length : void 0
8279
- } : void 0
8280
- } : void 0
8281
- };
8282
- }
8283
- function sanitizeCaptureState(rawState) {
8284
- return Object.fromEntries(
8285
- Object.entries(rawState).map(([key, value]) => {
8286
- if (key === "__omTurn") {
8287
- return [key, summarizeOmTurn(value)];
8288
- }
8289
- return [key, value];
8290
- })
8291
- );
8292
- }
8293
- function buildReproMessageFingerprint(message) {
8294
- const createdAt = message.createdAt instanceof Date ? message.createdAt.toISOString() : message.createdAt ? new Date(message.createdAt).toISOString() : "";
8295
- return JSON.stringify({
8296
- role: message.role,
8297
- createdAt,
8298
- content: message.content
8299
- });
8300
- }
8301
- function inferReproIdRemap(preMessages, postMessages) {
8302
- const preByFingerprint = /* @__PURE__ */ new Map();
8303
- const postByFingerprint = /* @__PURE__ */ new Map();
8304
- for (const message of preMessages) {
8305
- if (!message.id) continue;
8306
- const fingerprint = buildReproMessageFingerprint(message);
8307
- const list = preByFingerprint.get(fingerprint) ?? [];
8308
- list.push(message.id);
8309
- preByFingerprint.set(fingerprint, list);
8310
- }
8311
- for (const message of postMessages) {
8312
- if (!message.id) continue;
8313
- const fingerprint = buildReproMessageFingerprint(message);
8314
- const list = postByFingerprint.get(fingerprint) ?? [];
8315
- list.push(message.id);
8316
- postByFingerprint.set(fingerprint, list);
8317
- }
8318
- const remap = [];
8319
- for (const [fingerprint, preIds] of preByFingerprint.entries()) {
8320
- const postIds = postByFingerprint.get(fingerprint);
8321
- if (!postIds || preIds.length !== 1 || postIds.length !== 1) continue;
8322
- const fromId = preIds[0];
8323
- const toId = postIds[0];
8324
- if (!fromId || !toId || fromId === toId) {
8325
- continue;
8326
- }
8327
- remap.push({ fromId, toId, fingerprint });
8328
- }
8329
- return remap;
8330
- }
8331
- function writeProcessInputStepReproCapture(params) {
8332
- if (!isOmReproCaptureEnabled()) {
8333
- return;
8334
- }
8335
- try {
8336
- const sanitizedThreadId = sanitizeCapturePathSegment(params.threadId);
8337
- const runId = `${Date.now()}-step-${params.stepNumber}-${crypto$1.randomUUID()}`;
8338
- const captureDir = path.join(process.cwd(), OM_REPRO_CAPTURE_DIR, sanitizedThreadId, runId);
8339
- fs.mkdirSync(captureDir, { recursive: true });
8340
- const contextMessages = params.messageList.get.all.db();
8341
- const memoryContext = memory.parseMemoryRequestContext(params.args.requestContext);
8342
- const preMessageIds = new Set(params.preMessages.map((message) => message.id));
8343
- const postMessageIds = new Set(contextMessages.map((message) => message.id));
8344
- const removedMessageIds = params.preMessages.map((message) => message.id).filter((id) => Boolean(id) && !postMessageIds.has(id));
8345
- const addedMessageIds = contextMessages.map((message) => message.id).filter((id) => Boolean(id) && !preMessageIds.has(id));
8346
- const idRemap = inferReproIdRemap(params.preMessages, contextMessages);
8347
- const rawState = params.args.state ?? {};
8348
- const sanitizedState = sanitizeCaptureState(rawState);
8349
- const payloads = [
8350
- {
8351
- fileName: "input.json",
8352
- data: {
8353
- stepNumber: params.stepNumber,
8354
- threadId: params.threadId,
8355
- resourceId: params.resourceId,
8356
- readOnly: memoryContext?.memoryConfig?.readOnly,
8357
- messageCount: contextMessages.length,
8358
- messageIds: contextMessages.map((message) => message.id),
8359
- stateKeys: Object.keys(rawState),
8360
- state: sanitizedState,
8361
- args: {
8362
- messages: params.args.messages,
8363
- steps: params.args.steps,
8364
- systemMessages: params.args.systemMessages,
8365
- retryCount: params.args.retryCount,
8366
- toolChoice: params.args.toolChoice,
8367
- activeTools: params.args.activeTools,
8368
- modelSettings: params.args.modelSettings,
8369
- structuredOutput: params.args.structuredOutput
8370
- }
8371
- }
8372
- },
8373
- {
8374
- fileName: "pre-state.json",
8375
- data: {
8376
- record: params.preRecord,
8377
- bufferedChunks: params.preBufferedChunks,
8378
- contextTokenCount: params.preContextTokenCount,
8379
- messages: params.preMessages,
8380
- messageList: params.preSerializedMessageList
8381
- }
8382
- },
8383
- {
8384
- fileName: "output.json",
8385
- data: {
8386
- details: params.details,
8387
- messageDiff: {
8388
- removedMessageIds,
8389
- addedMessageIds,
8390
- idRemap
8391
- }
8392
- }
8393
- },
8394
- {
8395
- fileName: "post-state.json",
8396
- data: {
8397
- record: params.postRecord,
8398
- bufferedChunks: params.postBufferedChunks,
8399
- contextTokenCount: params.postContextTokenCount,
8400
- messageCount: contextMessages.length,
8401
- messageIds: contextMessages.map((message) => message.id),
8402
- messages: contextMessages,
8403
- messageList: params.messageList.serialize()
8404
- }
8405
- }
8406
- ];
8407
- const captureErrors = [];
8408
- for (const payload of payloads) {
8409
- const serialized = safeCaptureJsonOrError(payload.data);
8410
- if (serialized.ok) {
8411
- fs.writeFileSync(path.join(captureDir, payload.fileName), `${JSON.stringify(serialized.value, null, 2)}
8412
- `);
8413
- continue;
8414
- }
8415
- captureErrors.push({ fileName: payload.fileName, error: serialized.error });
8416
- fs.writeFileSync(
8417
- path.join(captureDir, payload.fileName),
8418
- `${JSON.stringify({ __captureError: serialized.error }, null, 2)}
8419
- `
8420
- );
8421
- }
8422
- if (params.observerExchange) {
8423
- const serialized = safeCaptureJsonOrError(params.observerExchange);
8424
- if (serialized.ok) {
8425
- fs.writeFileSync(path.join(captureDir, "observer-exchange.json"), `${JSON.stringify(serialized.value, null, 2)}
8426
- `);
8427
- } else {
8428
- captureErrors.push({ fileName: "observer-exchange.json", error: serialized.error });
8429
- fs.writeFileSync(
8430
- path.join(captureDir, "observer-exchange.json"),
8431
- `${JSON.stringify({ __captureError: serialized.error }, null, 2)}
8432
- `
8433
- );
8434
- }
8435
- }
8436
- if (captureErrors.length > 0) {
8437
- fs.writeFileSync(path.join(captureDir, "capture-error.json"), `${JSON.stringify(captureErrors, null, 2)}
8438
- `);
8439
- params.debug?.(
8440
- `[OM:repro-capture] wrote processInputStep capture with ${captureErrors.length} serialization error(s) to ${captureDir}`
8441
- );
8442
- return;
8443
- }
8444
- params.debug?.(`[OM:repro-capture] wrote processInputStep capture to ${captureDir}`);
8445
- } catch (error) {
8446
- params.debug?.(`[OM:repro-capture] failed to write processInputStep capture: ${String(error)}`);
8447
- }
8448
- }
8449
-
8450
- // src/processors/observational-memory/processor.ts
8451
8605
  function getOmObservabilityContext(args) {
8452
8606
  if (!args.tracing || !args.tracingContext || !args.loggerVNext || !args.metrics) {
8453
8607
  return void 0;
@@ -8686,5 +8840,5 @@ exports.stripEphemeralAnchorIds = stripEphemeralAnchorIds;
8686
8840
  exports.stripObservationGroups = stripObservationGroups;
8687
8841
  exports.truncateStringByTokens = truncateStringByTokens;
8688
8842
  exports.wrapInObservationGroup = wrapInObservationGroup;
8689
- //# sourceMappingURL=chunk-ZVRO2GUN.cjs.map
8690
- //# sourceMappingURL=chunk-ZVRO2GUN.cjs.map
8843
+ //# sourceMappingURL=chunk-ANKEPFC6.cjs.map
8844
+ //# sourceMappingURL=chunk-ANKEPFC6.cjs.map