@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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # @mastra/memory
2
2
 
3
+ ## 1.26.1-alpha.6
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`2e4624e`](https://github.com/mastra-ai/mastra/commit/2e4624edb6917e61249cb60ee377735e7af7e4a9), [`e6534fa`](https://github.com/mastra-ai/mastra/commit/e6534fab031216f6cb48c4c9907cbfdce9d60bc6), [`7fdcaa6`](https://github.com/mastra-ai/mastra/commit/7fdcaa66105d64290f9b14432a12ec99f39c4d3a), [`5dba2a4`](https://github.com/mastra-ai/mastra/commit/5dba2a41600385751f5aace79878904e1972609d), [`cfd0d9e`](https://github.com/mastra-ai/mastra/commit/cfd0d9ec77ec3c69dd96f79cdb579e03d79f22ce), [`d9d93b2`](https://github.com/mastra-ai/mastra/commit/d9d93b25e4a65ad5fa153fa35be7ed149c8d587f)]:
8
+ - @mastra/core@1.58.0-alpha.12
9
+ - @mastra/schema-compat@1.3.6-alpha.3
10
+
11
+ ## 1.26.1-alpha.5
12
+
13
+ ### Patch Changes
14
+
15
+ - Remove the `image-size` dependency from `@mastra/memory` and measure image dimensions with the already-present `probe-image-size` instead. ([#21120](https://github.com/mastra-ai/mastra/pull/21120))
16
+
17
+ Every published version of `image-size` carries unfixed denial-of-service advisories (GHSA-w3rx-r6r6-pgpr / CVE-2025-71330 and GHSA-5p2g-fcmc-qvqq): a malformed image could hang its parse loop and exhaust the heap. The repository is archived, so no fixed release is coming, and the previous pin to `1.2.1` moved between two equally affected releases rather than remediating the flaw. Because image bytes reaching agent memory are untrusted, a crafted 32-byte image was enough to crash the process.
18
+
19
+ Dimension detection still covers the formats models accept (PNG, JPEG, WebP, GIF, AVIF, BMP, ICO, PSD, SVG, TIFF). Unrecognized formats now report unknown dimensions, which token counting already handled.
20
+
21
+ - Updated dependencies [[`b8ce7ec`](https://github.com/mastra-ai/mastra/commit/b8ce7ec96e39343c6c2f36d12d68a9ad816c09f7), [`a3a3624`](https://github.com/mastra-ai/mastra/commit/a3a3624f646b98e409424d8defccbd334da9e8b8), [`6246914`](https://github.com/mastra-ai/mastra/commit/62469146636911f3cbbe0880bd011c6a897a59a7), [`3f73c07`](https://github.com/mastra-ai/mastra/commit/3f73c076727e8c36b4fff7a1b40290fb68957fa8), [`7c1ebb1`](https://github.com/mastra-ai/mastra/commit/7c1ebb15690c4b3f0eabb19077cf8af573311e57), [`32980a3`](https://github.com/mastra-ai/mastra/commit/32980a3e2413d0274ac244d32c37d910edc13f00), [`4bcdfaf`](https://github.com/mastra-ai/mastra/commit/4bcdfaf0eac3199d7cb171b0a19a92c9c341eea4), [`af4636a`](https://github.com/mastra-ai/mastra/commit/af4636a74463275d71c1d13a38f7d2b738f128bf), [`a463cdf`](https://github.com/mastra-ai/mastra/commit/a463cdf1c95c3059e70f0bff27959e8558bb899d), [`0ea6b80`](https://github.com/mastra-ai/mastra/commit/0ea6b8001408ce02b56e8be0536b0fd8cbaf8ad2)]:
22
+ - @mastra/core@1.58.0-alpha.11
23
+
3
24
  ## 1.26.1-alpha.4
4
25
 
5
26
  ### Patch Changes
@@ -3,7 +3,7 @@ name: mastra-memory
3
3
  description: Documentation for @mastra/memory. Use when working with @mastra/memory APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/memory"
6
- version: "1.26.1-alpha.4"
6
+ version: "1.26.1-alpha.6"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.26.1-alpha.4",
2
+ "version": "1.26.1-alpha.6",
3
3
  "package": "@mastra/memory",
4
4
  "exports": {},
5
5
  "modules": {
@@ -90,6 +90,20 @@ for await (const chunk of stream.fullStream) {
90
90
  }
91
91
  ```
92
92
 
93
+ #### Explaining a decline
94
+
95
+ `declineToolCall()`, `declineToolCallGenerate()`, and `declineNetworkToolCall()` accept an optional `reason`. The reason is returned to the model in place of the tool result, so the model can adjust instead of retrying blindly. It's also stored on the tool call's `approval` metadata, so it's still there when the conversation is recalled.
96
+
97
+ ```typescript
98
+ const declined = await agent.declineToolCall({
99
+ runId: stream.runId,
100
+ toolCallId,
101
+ reason: 'Reading other users PII is not allowed, ask the user for their own email instead',
102
+ })
103
+ ```
104
+
105
+ Without a `reason`, the model receives the default message `Tool call was not approved by the user`.
106
+
93
107
  #### Conditional approval with a function
94
108
 
95
109
  Instead of a boolean, `requireToolApproval` accepts a function that decides per tool call. It receives the `toolName`, the `args` the model passed, the `requestContext`, and the `workspace`. Return `true` to require approval for that call, or `false` to allow it. This lets you gate approval at runtime, for example, only for tools whose name matches a pattern:
@@ -113,7 +113,7 @@ The `context` object includes:
113
113
 
114
114
  ### Request context at the delegation boundary
115
115
 
116
- Each delegation receives a request context whose entries are shallowly copied from the parent run, excluding run-scoped identity keys. Setting or deleting entries during the subagent run does not affect the parent's context. Set entries on `context.requestContext` in `onDelegationStart` to pass values to the delegated run:
116
+ Each delegation receives a request context whose entries are shallowly copied from the parent run, excluding run-scoped identity keys. Setting or deleting entries during the subagent run doesn't affect the parent's context. Set entries on `context.requestContext` in `onDelegationStart` to pass values to the delegated run:
117
117
 
118
118
  ```typescript
119
119
  const stream = await parentAgent.stream('Research AI trends', {
@@ -134,6 +134,9 @@ Called after a delegation finishes. Use it to inspect results or provide feedbac
134
134
 
135
135
  - `context.bail()`: Stop the parent agent's loop immediately
136
136
  - Return `{ feedback: '...' }`: Add feedback that gets saved to the parent agent's memory and is visible to subsequent iterations
137
+ - Return `{ resultText: '...' }`: Replace the tool result text the parent model sees for this delegation, within the current run
138
+
139
+ Use `resultText` when the subagent's own result would mislead the parent immediately. For example, a subagent that stops on a tool-calls step returns empty text, which the parent model reads as a successful but empty delegation. Unlike `feedback`, which only reaches the model on the next turn, `resultText` changes what the parent reasons on right away.
137
140
 
138
141
  ```typescript
139
142
  const stream = await parentAgent.stream('Research AI trends', {
@@ -4,7 +4,7 @@
4
4
 
5
5
  **Added in:** `@mastra/core@1.42.0`
6
6
 
7
- > **Beta:** The Goals feature is in beta stage and subject to breaking changes in minor versions until it graduates from its beta status.
7
+ > **Beta:** Breaking changes may occur without a major version bump until the API is stable.
8
8
 
9
9
  A goal is a durable, thread-scoped objective: a standing instruction the agent keeps working toward across loop iterations until a judge model decides it's satisfied or a run budget is exhausted.
10
10
 
@@ -6,7 +6,7 @@ Message history is the most basic and important form of memory. It gives the LLM
6
6
 
7
7
  You can also retrieve message history to display past conversations in your UI.
8
8
 
9
- > **Info:** Each message belongs to a thread (the conversation) and a resource (the user or entity it's associated with). See [Threads and resources](#threads-and-resources) for more detail.
9
+ > **Note:** Each message belongs to a thread (the conversation) and a resource (the user or entity it's associated with). See [Threads and resources](#threads-and-resources) for more detail.
10
10
 
11
11
  > **Warning:** When you use memory with a client application, send **only the new message** from the client instead of the full conversation history.
12
12
  >
@@ -113,7 +113,7 @@ await agent.stream('Hello', {
113
113
  })
114
114
  ```
115
115
 
116
- > **Info:** Threads and messages are created automatically when you call `agent.generate()` or `agent.stream()`, but you can also create them manually with [`createThread()`](https://mastra.ai/reference/memory/createThread) and [`saveMessages()`](https://mastra.ai/reference/memory/memory-class).
116
+ > **Note:** Threads and messages are created automatically when you call `agent.generate()` or `agent.stream()`, but you can also create them manually with [`createThread()`](https://mastra.ai/reference/memory/createThread) and [`saveMessages()`](https://mastra.ai/reference/memory/memory-class).
117
117
 
118
118
  You can use this history in two ways:
119
119
 
@@ -2,6 +2,8 @@
2
2
 
3
3
  # Memory
4
4
 
5
+ > **Beta:** Breaking changes may occur without a major version bump until the API is stable.
6
+
5
7
  A file-based agent gets [memory](https://mastra.ai/docs/memory/overview) from a `memory.ts` file that default-exports a [`Memory`](https://mastra.ai/reference/memory/memory-class) instance. Use this page for the file-based convention; use the memory docs for message history, semantic recall, storage, and processors.
6
8
 
7
9
  Without `memory.ts` or `config.memory`, the agent has no memory by default. Each `generate()` or `stream()` call starts without remembered conversation state unless you pass the prior context yourself.
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_src = require("./src-kjoZv97r.cjs");
2
+ const require_src = require("./src-B2WSEEmS.cjs");
3
3
  let _mastra_core_processors = require("@mastra/core/processors");
4
4
  exports.Extractor = require_src.Extractor;
5
5
  exports.Memory = require_src.Memory;
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import { C as WorkingMemoryExtractor, R as Extractor, S as deepMergeWorkingMemory, T as summarizeConversation, a as extractWorkingMemoryContent, c as WORKING_MEMORY_STATE_ID, d as getObservationsAsOf, i as WorkingMemory, l as WORKING_MEMORY_STATE_PROCESSOR_ID, n as MessageHistory, o as extractWorkingMemoryTags, r as SemanticRecall, s as removeWorkingMemoryTags, t as Memory, u as WorkingMemoryStateProcessor, w as SUMMARIZE_THREAD_DEFAULTS, x as ModelByInputTokens } from "./src-hv0DMVM-.js";
1
+ import { C as WorkingMemoryExtractor, R as Extractor, S as deepMergeWorkingMemory, T as summarizeConversation, a as extractWorkingMemoryContent, c as WORKING_MEMORY_STATE_ID, d as getObservationsAsOf, i as WorkingMemory, l as WORKING_MEMORY_STATE_PROCESSOR_ID, n as MessageHistory, o as extractWorkingMemoryTags, r as SemanticRecall, s as removeWorkingMemoryTags, t as Memory, u as WorkingMemoryStateProcessor, w as SUMMARIZE_THREAD_DEFAULTS, x as ModelByInputTokens } from "./src-B_n15_Xg.js";
2
2
  export { Extractor, Memory, MessageHistory, ModelByInputTokens, SUMMARIZE_THREAD_DEFAULTS, SemanticRecall, WORKING_MEMORY_STATE_ID, WORKING_MEMORY_STATE_PROCESSOR_ID, WorkingMemory, WorkingMemoryExtractor, WorkingMemoryStateProcessor, deepMergeWorkingMemory, extractWorkingMemoryContent, extractWorkingMemoryTags, getObservationsAsOf, removeWorkingMemoryTags, summarizeConversation };
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_src = require("../src-kjoZv97r.cjs");
2
+ const require_src = require("../src-B2WSEEmS.cjs");
3
3
  exports.Extractor = require_src.Extractor;
4
4
  exports.ModelByInputTokens = require_src.ModelByInputTokens;
5
5
  exports.OBSERVATIONAL_MEMORY_DEFAULTS = require_src.OBSERVATIONAL_MEMORY_DEFAULTS;
@@ -1,2 +1,2 @@
1
- import { A as extractCurrentTask, B as OBSERVATION_CONTEXT_INSTRUCTIONS, C as WorkingMemoryExtractor, D as OBSERVER_SYSTEM_PROMPT, E as TokenCounter, F as injectAnchorIds, H as OBSERVATION_CONTINUATION_HINT, I as parseAnchorId, L as stripEphemeralAnchorIds, M as hasCurrentTaskSection, N as optimizeObservationsForContext, O as buildObserverPrompt, P as parseObserverOutput, R as Extractor, T as summarizeConversation, V as OBSERVATION_CONTEXT_PROMPT, _ as reconcileObservationGroupsFromReflection, b as wrapInObservationGroup, d as getObservationsAsOf, f as ObservationalMemoryProcessor, g as parseObservationGroups, h as deriveObservationGroupProvenance, j as formatMessagesForObserver, k as buildObserverSystemPrompt, m as combineObservationGroupRanges, p as ObservationalMemory, v as renderObservationGroupsForReflection, x as ModelByInputTokens, y as stripObservationGroups, z as OBSERVATIONAL_MEMORY_DEFAULTS } from "../src-hv0DMVM-.js";
1
+ import { A as extractCurrentTask, B as OBSERVATION_CONTEXT_INSTRUCTIONS, C as WorkingMemoryExtractor, D as OBSERVER_SYSTEM_PROMPT, E as TokenCounter, F as injectAnchorIds, H as OBSERVATION_CONTINUATION_HINT, I as parseAnchorId, L as stripEphemeralAnchorIds, M as hasCurrentTaskSection, N as optimizeObservationsForContext, O as buildObserverPrompt, P as parseObserverOutput, R as Extractor, T as summarizeConversation, V as OBSERVATION_CONTEXT_PROMPT, _ as reconcileObservationGroupsFromReflection, b as wrapInObservationGroup, d as getObservationsAsOf, f as ObservationalMemoryProcessor, g as parseObservationGroups, h as deriveObservationGroupProvenance, j as formatMessagesForObserver, k as buildObserverSystemPrompt, m as combineObservationGroupRanges, p as ObservationalMemory, v as renderObservationGroupsForReflection, x as ModelByInputTokens, y as stripObservationGroups, z as OBSERVATIONAL_MEMORY_DEFAULTS } from "../src-B_n15_Xg.js";
2
2
  export { Extractor, ModelByInputTokens, OBSERVATIONAL_MEMORY_DEFAULTS, OBSERVATION_CONTEXT_INSTRUCTIONS, OBSERVATION_CONTEXT_PROMPT, OBSERVATION_CONTINUATION_HINT, OBSERVER_SYSTEM_PROMPT, ObservationalMemory, ObservationalMemoryProcessor, TokenCounter, WorkingMemoryExtractor, buildObserverPrompt, buildObserverSystemPrompt, combineObservationGroupRanges, deriveObservationGroupProvenance, extractCurrentTask, formatMessagesForObserver, getObservationsAsOf, hasCurrentTaskSection, injectAnchorIds, optimizeObservationsForContext, parseAnchorId, parseObservationGroups, parseObserverOutput, reconcileObservationGroupsFromReflection, renderObservationGroupsForReflection, stripEphemeralAnchorIds, stripObservationGroups, summarizeConversation, wrapInObservationGroup };
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Synchronous image dimension lookup for in-memory image buffers.
3
+ *
4
+ * Uses `probe-image-size`'s sync parsers rather than `image-size`, which has unfixed
5
+ * denial-of-service advisories (GHSA-w3rx-r6r6-pgpr / CVE-2025-71330 and
6
+ * GHSA-5p2g-fcmc-qvqq) affecting every published version, on an archived repository
7
+ * with no fixed release coming. A malformed 32-byte ICNS buffer was enough to hang the
8
+ * parse loop and exhaust the heap, and image bytes reaching agent memory are untrusted.
9
+ *
10
+ * `probe-image-size` covers the formats models actually accept (PNG, JPEG, WebP, GIF,
11
+ * AVIF, BMP, ICO, PSD, SVG, TIFF). Anything else returns `undefined`, which callers
12
+ * already handle as "dimensions unknown".
13
+ */
14
+ /**
15
+ * Read the pixel dimensions of an image buffer.
16
+ *
17
+ * @returns The dimensions, or `undefined` if the buffer isn't a recognized image.
18
+ */
19
+ export declare function measureImageBuffer(buffer: Uint8Array): {
20
+ width: number;
21
+ height: number;
22
+ } | undefined;
23
+ //# sourceMappingURL=measure-image-buffer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"measure-image-buffer.d.ts","sourceRoot":"","sources":["../../../src/processors/observational-memory/measure-image-buffer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAWH;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,UAAU,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAmBpG"}
@@ -51,8 +51,8 @@ let tokenx = require("tokenx");
51
51
  let crypto$1 = require("crypto");
52
52
  let _mastra_core_storage = require("@mastra/core/storage");
53
53
  let async_hooks = require("async_hooks");
54
- let image_size = require("image-size");
55
- image_size = __toESM$1(image_size, 1);
54
+ let probe_image_size_sync_js = require("probe-image-size/sync.js");
55
+ probe_image_size_sync_js = __toESM$1(probe_image_size_sync_js, 1);
56
56
  let _mastra_core_tools = require("@mastra/core/tools");
57
57
  let _mastra_core_schema = require("@mastra/core/schema");
58
58
  let _mastra_core_error = require("@mastra/core/error");
@@ -17366,6 +17366,42 @@ var ObserverRunner = class {
17366
17366
  }
17367
17367
  };
17368
17368
  //#endregion
17369
+ //#region src/processors/observational-memory/measure-image-buffer.ts
17370
+ /**
17371
+ * Synchronous image dimension lookup for in-memory image buffers.
17372
+ *
17373
+ * Uses `probe-image-size`'s sync parsers rather than `image-size`, which has unfixed
17374
+ * denial-of-service advisories (GHSA-w3rx-r6r6-pgpr / CVE-2025-71330 and
17375
+ * GHSA-5p2g-fcmc-qvqq) affecting every published version, on an archived repository
17376
+ * with no fixed release coming. A malformed 32-byte ICNS buffer was enough to hang the
17377
+ * parse loop and exhaust the heap, and image bytes reaching agent memory are untrusted.
17378
+ *
17379
+ * `probe-image-size` covers the formats models actually accept (PNG, JPEG, WebP, GIF,
17380
+ * AVIF, BMP, ICO, PSD, SVG, TIFF). Anything else returns `undefined`, which callers
17381
+ * already handle as "dimensions unknown".
17382
+ */
17383
+ const probeBuffer = probe_image_size_sync_js.default;
17384
+ /**
17385
+ * Read the pixel dimensions of an image buffer.
17386
+ *
17387
+ * @returns The dimensions, or `undefined` if the buffer isn't a recognized image.
17388
+ */
17389
+ function measureImageBuffer(buffer) {
17390
+ let probed;
17391
+ try {
17392
+ probed = probeBuffer(buffer);
17393
+ } catch {
17394
+ return;
17395
+ }
17396
+ if (!probed) return;
17397
+ const { width, height } = probed;
17398
+ if (typeof width !== "number" || !Number.isFinite(width) || typeof height !== "number" || !Number.isFinite(height)) return;
17399
+ return {
17400
+ width,
17401
+ height
17402
+ };
17403
+ }
17404
+ //#endregion
17369
17405
  //#region src/processors/observational-memory/token-counter.ts
17370
17406
  const IMAGE_FILE_EXTENSIONS = /* @__PURE__ */ new Set([
17371
17407
  "png",
@@ -17672,26 +17708,23 @@ function resolveImageDimensions(part) {
17672
17708
  width,
17673
17709
  height
17674
17710
  };
17675
- try {
17676
- const measured = (0, image_size.default)(buffer);
17677
- const measuredWidth = getFiniteNumber(measured.width);
17678
- const measuredHeight = getFiniteNumber(measured.height);
17679
- if (!measuredWidth || !measuredHeight) return {
17680
- width,
17681
- height
17682
- };
17683
- const resolved = {
17684
- width: width ?? measuredWidth,
17685
- height: height ?? measuredHeight
17686
- };
17687
- persistImageDimensions(part, resolved);
17688
- return resolved;
17689
- } catch {
17690
- return {
17691
- width,
17692
- height
17693
- };
17694
- }
17711
+ const measured = measureImageBuffer(buffer);
17712
+ if (!measured) return {
17713
+ width,
17714
+ height
17715
+ };
17716
+ const measuredWidth = getFiniteNumber(measured.width);
17717
+ const measuredHeight = getFiniteNumber(measured.height);
17718
+ if (!measuredWidth || !measuredHeight) return {
17719
+ width,
17720
+ height
17721
+ };
17722
+ const resolved = {
17723
+ width: width ?? measuredWidth,
17724
+ height: height ?? measuredHeight
17725
+ };
17726
+ persistImageDimensions(part, resolved);
17727
+ return resolved;
17695
17728
  }
17696
17729
  function getBase64Size(base64) {
17697
17730
  const sanitized = base64.replace(/\s+/g, "");
@@ -28873,4 +28906,4 @@ Object.defineProperty(exports, "wrapInObservationGroup", {
28873
28906
  }
28874
28907
  });
28875
28908
 
28876
- //# sourceMappingURL=src-kjoZv97r.cjs.map
28909
+ //# sourceMappingURL=src-B2WSEEmS.cjs.map