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