@mastra/memory 1.26.1-alpha.4 → 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.
@@ -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";
@@ -17345,6 +17345,42 @@ var ObserverRunner = class {
17345
17345
  }
17346
17346
  };
17347
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
17348
17384
  //#region src/processors/observational-memory/token-counter.ts
17349
17385
  const IMAGE_FILE_EXTENSIONS = /* @__PURE__ */ new Set([
17350
17386
  "png",
@@ -17651,26 +17687,23 @@ function resolveImageDimensions(part) {
17651
17687
  width,
17652
17688
  height
17653
17689
  };
17654
- try {
17655
- const measured = imageSize(buffer);
17656
- const measuredWidth = getFiniteNumber(measured.width);
17657
- const measuredHeight = getFiniteNumber(measured.height);
17658
- if (!measuredWidth || !measuredHeight) return {
17659
- width,
17660
- height
17661
- };
17662
- const resolved = {
17663
- width: width ?? measuredWidth,
17664
- height: height ?? measuredHeight
17665
- };
17666
- persistImageDimensions(part, resolved);
17667
- return resolved;
17668
- } catch {
17669
- return {
17670
- width,
17671
- height
17672
- };
17673
- }
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;
17674
17707
  }
17675
17708
  function getBase64Size(base64) {
17676
17709
  const sanitized = base64.replace(/\s+/g, "");
@@ -28619,4 +28652,4 @@ Notes:
28619
28652
  //#endregion
28620
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 };
28621
28654
 
28622
- //# sourceMappingURL=src-hv0DMVM-.js.map
28655
+ //# sourceMappingURL=src-B_n15_Xg.js.map