@mastra/memory 1.26.1-alpha.3 → 1.26.1-alpha.6

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 (35) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/dist/docs/SKILL.md +3 -1
  3. package/dist/docs/assets/SOURCE_MAP.json +1 -1
  4. package/dist/docs/references/docs-agents-agent-approval.md +14 -0
  5. package/dist/docs/references/docs-capabilities-subagents.md +4 -1
  6. package/dist/docs/references/docs-long-running-agents-goals.md +1 -1
  7. package/dist/docs/references/docs-memory-message-history.md +2 -2
  8. package/dist/docs/references/docs-memory-multi-user-threads.md +1 -1
  9. package/dist/docs/references/docs-memory-observational-memory.md +1 -1
  10. package/dist/docs/references/docs-memory-semantic-recall.md +2 -1
  11. package/dist/docs/references/docs-memory-working-memory.md +1 -0
  12. package/dist/docs/references/docs-storage-overview.md +1 -0
  13. package/dist/docs/references/reference-file-based-agents-memory.md +2 -0
  14. package/dist/docs/references/reference-storage-oracledb.md +239 -0
  15. package/dist/docs/references/reference-vectors-oracledb.md +347 -0
  16. package/dist/index.cjs +1 -1
  17. package/dist/index.d.ts +2 -2
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +1 -1
  20. package/dist/processors/index.cjs +1 -1
  21. package/dist/processors/index.js +1 -1
  22. package/dist/processors/observational-memory/measure-image-buffer.d.ts +23 -0
  23. package/dist/processors/observational-memory/measure-image-buffer.d.ts.map +1 -0
  24. package/dist/processors/observational-memory/observation-strategies/async-buffer.d.ts.map +1 -1
  25. package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -1
  26. package/dist/processors/observational-memory/reflector-runner.d.ts.map +1 -1
  27. package/dist/processors/observational-memory/tool-result-helpers.d.ts +8 -0
  28. package/dist/processors/observational-memory/tool-result-helpers.d.ts.map +1 -1
  29. package/dist/{src-CTQrRb5X.cjs → src-B2WSEEmS.cjs} +72 -33
  30. package/dist/src-B2WSEEmS.cjs.map +1 -0
  31. package/dist/{src-MScpLVRh.js → src-B_n15_Xg.js} +71 -32
  32. package/dist/src-B_n15_Xg.js.map +1 -0
  33. package/package.json +6 -7
  34. package/dist/src-CTQrRb5X.cjs.map +0 -1
  35. package/dist/src-MScpLVRh.js.map +0 -1
@@ -19,7 +19,7 @@ import { estimateTokenCount } from "tokenx";
19
19
  import { createHash, randomBytes, randomUUID } from "crypto";
20
20
  import { InMemoryStore } from "@mastra/core/storage";
21
21
  import { AsyncLocalStorage } from "async_hooks";
22
- import imageSize from "image-size";
22
+ import probeImageSizeSync from "probe-image-size/sync.js";
23
23
  import { createTool } from "@mastra/core/tools";
24
24
  import { isStandardSchemaWithJSON as isStandardSchemaWithJSON$1, toStandardSchema as toStandardSchema$1 } from "@mastra/core/schema";
25
25
  import { ErrorCategory, ErrorDomain, MastraError } from "@mastra/core/error";
@@ -15614,6 +15614,16 @@ function sanitizeToolResultValue(value, seen = /* @__PURE__ */ new WeakMap()) {
15614
15614
  }
15615
15615
  return sanitizedObject;
15616
15616
  }
15617
+ /**
15618
+ * Serializes a tool result without truncating it.
15619
+ *
15620
+ * Token accounting must see the full result: the truncation applied by
15621
+ * {@link formatToolResultForObserver} exists to bound what the Observer LLM reads,
15622
+ * not to describe what the agent's provider context actually holds.
15623
+ */
15624
+ function serializeToolResultForTokenCounting(value) {
15625
+ return stringifyToolResult(value);
15626
+ }
15617
15627
  function stringifyToolResult(value) {
15618
15628
  if (typeof value === "string") return value;
15619
15629
  const sanitized = sanitizeToolResultValue(value);
@@ -17335,6 +17345,42 @@ var ObserverRunner = class {
17335
17345
  }
17336
17346
  };
17337
17347
  //#endregion
17348
+ //#region src/processors/observational-memory/measure-image-buffer.ts
17349
+ /**
17350
+ * Synchronous image dimension lookup for in-memory image buffers.
17351
+ *
17352
+ * Uses `probe-image-size`'s sync parsers rather than `image-size`, which has unfixed
17353
+ * denial-of-service advisories (GHSA-w3rx-r6r6-pgpr / CVE-2025-71330 and
17354
+ * GHSA-5p2g-fcmc-qvqq) affecting every published version, on an archived repository
17355
+ * with no fixed release coming. A malformed 32-byte ICNS buffer was enough to hang the
17356
+ * parse loop and exhaust the heap, and image bytes reaching agent memory are untrusted.
17357
+ *
17358
+ * `probe-image-size` covers the formats models actually accept (PNG, JPEG, WebP, GIF,
17359
+ * AVIF, BMP, ICO, PSD, SVG, TIFF). Anything else returns `undefined`, which callers
17360
+ * already handle as "dimensions unknown".
17361
+ */
17362
+ const probeBuffer = probeImageSizeSync;
17363
+ /**
17364
+ * Read the pixel dimensions of an image buffer.
17365
+ *
17366
+ * @returns The dimensions, or `undefined` if the buffer isn't a recognized image.
17367
+ */
17368
+ function measureImageBuffer(buffer) {
17369
+ let probed;
17370
+ try {
17371
+ probed = probeBuffer(buffer);
17372
+ } catch {
17373
+ return;
17374
+ }
17375
+ if (!probed) return;
17376
+ const { width, height } = probed;
17377
+ if (typeof width !== "number" || !Number.isFinite(width) || typeof height !== "number" || !Number.isFinite(height)) return;
17378
+ return {
17379
+ width,
17380
+ height
17381
+ };
17382
+ }
17383
+ //#endregion
17338
17384
  //#region src/processors/observational-memory/token-counter.ts
17339
17385
  const IMAGE_FILE_EXTENSIONS = /* @__PURE__ */ new Set([
17340
17386
  "png",
@@ -17641,26 +17687,23 @@ function resolveImageDimensions(part) {
17641
17687
  width,
17642
17688
  height
17643
17689
  };
17644
- try {
17645
- const measured = imageSize(buffer);
17646
- const measuredWidth = getFiniteNumber(measured.width);
17647
- const measuredHeight = getFiniteNumber(measured.height);
17648
- if (!measuredWidth || !measuredHeight) return {
17649
- width,
17650
- height
17651
- };
17652
- const resolved = {
17653
- width: width ?? measuredWidth,
17654
- height: height ?? measuredHeight
17655
- };
17656
- persistImageDimensions(part, resolved);
17657
- return resolved;
17658
- } catch {
17659
- return {
17660
- width,
17661
- height
17662
- };
17663
- }
17690
+ const measured = measureImageBuffer(buffer);
17691
+ if (!measured) return {
17692
+ width,
17693
+ height
17694
+ };
17695
+ const measuredWidth = getFiniteNumber(measured.width);
17696
+ const measuredHeight = getFiniteNumber(measured.height);
17697
+ if (!measuredWidth || !measuredHeight) return {
17698
+ width,
17699
+ height
17700
+ };
17701
+ const resolved = {
17702
+ width: width ?? measuredWidth,
17703
+ height: height ?? measuredHeight
17704
+ };
17705
+ persistImageDimensions(part, resolved);
17706
+ return resolved;
17664
17707
  }
17665
17708
  function getBase64Size(base64) {
17666
17709
  const sanitized = base64.replace(/\s+/g, "");
@@ -18219,7 +18262,7 @@ var TokenCounter = class TokenCounter {
18219
18262
  let tokens = 0;
18220
18263
  const cacheParts = [];
18221
18264
  const countJsonContentPart = (contentPart) => {
18222
- const formatted = formatToolResultForObserver(contentPart);
18265
+ const formatted = serializeToolResultForTokenCounting(contentPart);
18223
18266
  tokens += this.countString(formatted);
18224
18267
  cacheParts.push({
18225
18268
  type: "json",
@@ -18582,7 +18625,7 @@ var TokenCounter = class TokenCounter {
18582
18625
  const contentTokens = this.countMultimodalToolResultContent(part, resultForCounting);
18583
18626
  if (contentTokens !== void 0) tokens += contentTokens;
18584
18627
  else {
18585
- const formattedResult = formatToolResultForObserver(resultForCounting);
18628
+ const formattedResult = serializeToolResultForTokenCounting(resultForCounting);
18586
18629
  tokens += this.readOrPersistPartEstimate(part, usingStoredModelOutput ? "tool-result-model-output-json" : "tool-result-json", formattedResult);
18587
18630
  }
18588
18631
  if (typeof resultForCounting !== "string") overheadDelta -= 12;
@@ -21371,7 +21414,7 @@ var SyncObservationStrategy = class extends ObservationStrategy {
21371
21414
  });
21372
21415
  await this.storage.updateThread({
21373
21416
  id: threadId,
21374
- title: shouldUpdateThreadTitle ? newTitle : thread.title ?? "",
21417
+ ...shouldUpdateThreadTitle ? { title: newTitle } : {},
21375
21418
  metadata: newMetadata
21376
21419
  });
21377
21420
  if (shouldUpdateThreadTitle) threadUpdateMarker = createThreadUpdateMarker({
@@ -21563,7 +21606,7 @@ var AsyncBufferObservationStrategy = class extends ObservationStrategy {
21563
21606
  });
21564
21607
  await this.storage.updateThread({
21565
21608
  id: threadId,
21566
- title: shouldUpdateThreadTitle ? newTitle : thread.title ?? "",
21609
+ ...shouldUpdateThreadTitle ? { title: newTitle } : {},
21567
21610
  metadata: newMetadata
21568
21611
  });
21569
21612
  if (shouldUpdateThreadTitle) {
@@ -21908,7 +21951,7 @@ var ResourceScopedObservationStrategy = class extends ObservationStrategy {
21908
21951
  });
21909
21952
  await this.storage.updateThread({
21910
21953
  id: update.threadId,
21911
- title: shouldUpdateThreadTitle ? newTitle : thread.title ?? "",
21954
+ ...shouldUpdateThreadTitle ? { title: newTitle } : {},
21912
21955
  metadata: newMetadata
21913
21956
  });
21914
21957
  if (shouldUpdateThreadTitle) threadUpdateMarkers.push(createThreadUpdateMarker({
@@ -22851,7 +22894,6 @@ async function persistThreadExtractedValues(storage, extractors, threadId, value
22851
22894
  });
22852
22895
  await storage.updateThread({
22853
22896
  id: threadId,
22854
- title: thread.title ?? "",
22855
22897
  metadata: newMetadata
22856
22898
  });
22857
22899
  }
@@ -25823,7 +25865,7 @@ ${formattedMessages}
25823
25865
  const shouldUpdateThreadTitle = !!newTitle && newTitle.length >= 3 && newTitle !== oldTitle;
25824
25866
  await this.storage.updateThread({
25825
25867
  id: threadId,
25826
- title: shouldUpdateThreadTitle ? newTitle : thread.title ?? "",
25868
+ ...shouldUpdateThreadTitle ? { title: newTitle } : {},
25827
25869
  metadata: newMetadata
25828
25870
  });
25829
25871
  }
@@ -26041,7 +26083,6 @@ ${formattedMessages}
26041
26083
  });
26042
26084
  await this.storage.updateThread({
26043
26085
  id: threadId,
26044
- title: thread.title ?? "",
26045
26086
  metadata: newMetadata
26046
26087
  });
26047
26088
  }
@@ -27187,7 +27228,6 @@ var Memory = class extends MastraMemory {
27187
27228
  if (!thread) throw new Error(`Thread ${threadId} not found`);
27188
27229
  await memoryStore.updateThread({
27189
27230
  id: threadId,
27190
- title: thread.title || "",
27191
27231
  metadata: {
27192
27232
  ...thread.metadata,
27193
27233
  workingMemory
@@ -27276,7 +27316,6 @@ ${workingMemory}`;
27276
27316
  if (!thread) throw new Error(`Thread ${threadId} not found`);
27277
27317
  await memoryStore.updateThread({
27278
27318
  id: threadId,
27279
- title: thread.title || "",
27280
27319
  metadata: {
27281
27320
  ...thread.metadata,
27282
27321
  workingMemory
@@ -28613,4 +28652,4 @@ Notes:
28613
28652
  //#endregion
28614
28653
  export { extractCurrentTask as A, OBSERVATION_CONTEXT_INSTRUCTIONS as B, WorkingMemoryExtractor as C, OBSERVER_SYSTEM_PROMPT as D, TokenCounter as E, injectAnchorIds as F, OBSERVATION_CONTINUATION_HINT as H, parseAnchorId as I, stripEphemeralAnchorIds as L, hasCurrentTaskSection as M, optimizeObservationsForContext as N, buildObserverPrompt as O, parseObserverOutput as P, Extractor as R, deepMergeWorkingMemory as S, summarizeConversation as T, OBSERVATION_CONTEXT_PROMPT as V, reconcileObservationGroupsFromReflection as _, extractWorkingMemoryContent as a, wrapInObservationGroup as b, WORKING_MEMORY_STATE_ID as c, getObservationsAsOf as d, ObservationalMemoryProcessor as f, parseObservationGroups as g, deriveObservationGroupProvenance as h, WorkingMemory as i, formatMessagesForObserver as j, buildObserverSystemPrompt as k, WORKING_MEMORY_STATE_PROCESSOR_ID as l, combineObservationGroupRanges as m, MessageHistory$1 as n, extractWorkingMemoryTags as o, ObservationalMemory as p, SemanticRecall as r, removeWorkingMemoryTags as s, Memory as t, WorkingMemoryStateProcessor as u, renderObservationGroupsForReflection as v, SUMMARIZE_THREAD_DEFAULTS as w, ModelByInputTokens as x, stripObservationGroups as y, OBSERVATIONAL_MEMORY_DEFAULTS as z };
28615
28654
 
28616
- //# sourceMappingURL=src-MScpLVRh.js.map
28655
+ //# sourceMappingURL=src-B_n15_Xg.js.map