@mastra/memory 1.26.1-alpha.4 → 1.26.1-alpha.7
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 +32 -0
- package/dist/docs/SKILL.md +15 -9
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-agents-agent-approval.md +14 -0
- package/dist/docs/references/docs-agents-networks.md +2 -2
- package/dist/docs/references/docs-capabilities-subagents.md +6 -3
- package/dist/docs/references/docs-long-running-agents-goals.md +1 -1
- package/dist/docs/references/docs-memory-memory-processors.md +5 -5
- package/dist/docs/references/docs-memory-message-history.md +3 -3
- package/dist/docs/references/docs-memory-observational-memory.md +1 -1
- package/dist/docs/references/docs-storage-overview.md +14 -13
- package/dist/docs/references/integrations-channels-github.md +103 -0
- package/dist/docs/references/{reference-storage-dsql.md → integrations-databases-aurora-dsql.md} +1 -1
- package/dist/docs/references/{reference-storage-dynamodb.md → integrations-databases-dynamodb.md} +1 -1
- package/dist/docs/references/{reference-storage-libsql.md → integrations-databases-libsql.md} +2 -2
- package/dist/docs/references/{reference-storage-mongodb.md → integrations-databases-mongodb.md} +1 -1
- package/dist/docs/references/{reference-storage-oracledb.md → integrations-databases-oracledb.md} +1 -1
- package/dist/docs/references/{reference-storage-postgresql.md → integrations-databases-postgresql.md} +1 -1
- package/dist/docs/references/{reference-storage-redis.md → integrations-databases-redis.md} +1 -1
- package/dist/docs/references/{reference-storage-upstash.md → integrations-databases-upstash.md} +1 -1
- package/dist/docs/references/reference-file-based-agents-memory.md +2 -0
- package/dist/docs/references/reference-migrations-agentnetwork.md +100 -0
- package/dist/docs/references/reference-migrations-upgrade-to-v1-memory.md +288 -0
- package/dist/docs/references/reference-vectors-oracledb.md +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/processors/index.cjs +1 -1
- package/dist/processors/index.js +1 -1
- package/dist/processors/observational-memory/measure-image-buffer.d.ts +23 -0
- package/dist/processors/observational-memory/measure-image-buffer.d.ts.map +1 -0
- package/dist/processors/observational-memory/observation-strategies/async-buffer.d.ts.map +1 -1
- package/dist/{src-kjoZv97r.cjs → src-CTwoCwmY.cjs} +65 -32
- package/dist/src-CTwoCwmY.cjs.map +1 -0
- package/dist/{src-hv0DMVM-.js → src-DGdlH4fo.js} +64 -31
- package/dist/src-DGdlH4fo.js.map +1 -0
- package/package.json +4 -5
- package/dist/src-hv0DMVM-.js.map +0 -1
- package/dist/src-kjoZv97r.cjs.map +0 -1
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
> Discover all available pages from the documentation index: https://mastra.ai/llms.txt
|
|
2
|
+
|
|
3
|
+
# Memory
|
|
4
|
+
|
|
5
|
+
Memory configuration now requires explicit parameters, and default settings have been updated for better performance and predictability.
|
|
6
|
+
|
|
7
|
+
## Changed
|
|
8
|
+
|
|
9
|
+
### Default settings for semantic recall and last messages
|
|
10
|
+
|
|
11
|
+
Default settings have changed to more reasonable values based on usage patterns. The `lastMessages` default decreased from 40 to 10, `semanticRecall` is now disabled by default, and thread title generation is disabled by default. These changes improve performance and reduce unexpected LLM API calls.
|
|
12
|
+
|
|
13
|
+
To migrate, if you were relying on the old defaults, explicitly configure these settings.
|
|
14
|
+
|
|
15
|
+
```diff
|
|
16
|
+
const memory = new Memory({
|
|
17
|
+
storage,
|
|
18
|
+
vector,
|
|
19
|
+
embedder,
|
|
20
|
+
+ options: {
|
|
21
|
+
+ lastMessages: 40, // Was default before
|
|
22
|
+
+ semanticRecall: {
|
|
23
|
+
+ topK: 2,
|
|
24
|
+
+ messageRange: 2,
|
|
25
|
+
+ scope: 'thread',
|
|
26
|
+
+ }, // Was enabled by default before
|
|
27
|
+
+ generateTitle: true, // Was enabled by default before
|
|
28
|
+
+ },
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Default memory scope from `thread` to `resource`
|
|
33
|
+
|
|
34
|
+
The default scope for both working memory and semantic recall has changed from `'thread'` to `'resource'`. This change aligns with common use cases where applications want to remember user information across conversations. When semantic recall is enabled, it now defaults to searching across all user conversations rather than the current thread.
|
|
35
|
+
|
|
36
|
+
To migrate, if you want to maintain the old behavior where memory is isolated per conversation thread, explicitly set `scope: 'thread'`.
|
|
37
|
+
|
|
38
|
+
```diff
|
|
39
|
+
const memory = new Memory({
|
|
40
|
+
storage,
|
|
41
|
+
vector,
|
|
42
|
+
embedder,
|
|
43
|
+
options: {
|
|
44
|
+
workingMemory: {
|
|
45
|
+
enabled: true,
|
|
46
|
+
+ scope: 'thread', // Explicitly set to thread-scoped
|
|
47
|
+
template: `# User Profile...`,
|
|
48
|
+
},
|
|
49
|
+
semanticRecall: {
|
|
50
|
+
topK: 3,
|
|
51
|
+
+ scope: 'thread', // Explicitly set to thread-scoped
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Thread title generation location
|
|
58
|
+
|
|
59
|
+
The `generateTitle` option has been moved from `threads.generateTitle` to the top-level of memory options. This change simplifies the API by moving the option to where it logically belongs.
|
|
60
|
+
|
|
61
|
+
To migrate, move `generateTitle` from the `threads` config to the top level of options.
|
|
62
|
+
|
|
63
|
+
```diff
|
|
64
|
+
const memory = new Memory({
|
|
65
|
+
storage,
|
|
66
|
+
vector,
|
|
67
|
+
embedder,
|
|
68
|
+
options: {
|
|
69
|
+
- threads: {
|
|
70
|
+
- generateTitle: true,
|
|
71
|
+
- },
|
|
72
|
+
+ generateTitle: true,
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Semantic recall default settings optimization
|
|
78
|
+
|
|
79
|
+
The default settings for semantic recall have been optimized based on RAG research. The `topK` increased from 2 to 4, and `messageRange` changed from `{ before: 2, after: 2 }` to `{ before: 1, after: 1 }`. These changes provide better accuracy while only slightly increasing message count.
|
|
80
|
+
|
|
81
|
+
To migrate, if you were relying on the previous defaults, explicitly set these values.
|
|
82
|
+
|
|
83
|
+
```diff
|
|
84
|
+
const memory = new Memory({
|
|
85
|
+
storage,
|
|
86
|
+
vector,
|
|
87
|
+
embedder,
|
|
88
|
+
options: {
|
|
89
|
+
semanticRecall: {
|
|
90
|
+
+ topK: 2, // Was default before
|
|
91
|
+
+ messageRange: { before: 2, after: 2 }, // Was default before
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### `memory.readOnly` moved to `memory.options.readOnly`
|
|
98
|
+
|
|
99
|
+
The `readOnly` property has been moved from the top-level of the memory option to inside `options`. This change aligns `readOnly` with other memory configuration options like `lastMessages` and `semanticRecall`.
|
|
100
|
+
|
|
101
|
+
To migrate, move `readOnly` from the top level to inside `options`.
|
|
102
|
+
|
|
103
|
+
```diff
|
|
104
|
+
agent.stream('Hello', {
|
|
105
|
+
memory: {
|
|
106
|
+
thread: threadId,
|
|
107
|
+
resource: resourceId,
|
|
108
|
+
- readOnly: true,
|
|
109
|
+
+ options: {
|
|
110
|
+
+ readOnly: true,
|
|
111
|
+
+ },
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
> **Codemod:** You can use Mastra's codemod CLI to update your code automatically:
|
|
117
|
+
>
|
|
118
|
+
> ```bash
|
|
119
|
+
> npx @mastra/codemod@latest v1/memory-readonly-to-options .
|
|
120
|
+
> ```
|
|
121
|
+
|
|
122
|
+
### `Memory.query()` renamed to `Memory.recall()`
|
|
123
|
+
|
|
124
|
+
The `Memory.query()` method has been renamed to `Memory.recall()`. The new method returns a simpler format with `{ messages: MastraDBMessage[] }` instead of multiple format variations. This change better describes the action of retrieving messages from memory and simplifies the API.
|
|
125
|
+
|
|
126
|
+
To migrate, rename `query()` to `recall()` and update code that expects the old return format.
|
|
127
|
+
|
|
128
|
+
```diff
|
|
129
|
+
- const result = await memory.query({ threadId: 'thread-123' });
|
|
130
|
+
+ const result = await memory.recall({ threadId: 'thread-123' });
|
|
131
|
+
- // result: { messages: CoreMessage[], uiMessages: UIMessageWithMetadata[], messagesV2: MastraMessageV2[] }
|
|
132
|
+
+ // result: { messages: MastraDBMessage[] }
|
|
133
|
+
+ const messages = result.messages;
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
> **Codemod:** You can use Mastra's codemod CLI to update your code automatically:
|
|
137
|
+
>
|
|
138
|
+
> ```bash
|
|
139
|
+
> npx @mastra/codemod@latest v1/memory-query-to-recall .
|
|
140
|
+
> ```
|
|
141
|
+
|
|
142
|
+
### `Memory.recall()` parameter changes
|
|
143
|
+
|
|
144
|
+
The `Memory.recall()` method now uses `StorageListMessagesInput` format with pagination, and the `vectorMessageSearch` parameter has been renamed to `vectorSearchString`. These changes align the memory API with the storage pagination API and provide more consistent naming.
|
|
145
|
+
|
|
146
|
+
To migrate, update method name, query parameters, and the vector search parameter.
|
|
147
|
+
|
|
148
|
+
```diff
|
|
149
|
+
- memory.query({
|
|
150
|
+
+ memory.recall({
|
|
151
|
+
threadId: 'thread-123',
|
|
152
|
+
- vectorMessageSearch: 'What did we discuss?',
|
|
153
|
+
- selectBy: { ... },
|
|
154
|
+
+ vectorSearchString: 'What did we discuss?',
|
|
155
|
+
+ page: 0,
|
|
156
|
+
+ perPage: 20,
|
|
157
|
+
+ orderBy: 'createdAt',
|
|
158
|
+
+ filter: { ... },
|
|
159
|
+
+ threadConfig: { semanticRecall: true },
|
|
160
|
+
});
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
> **Codemod:** You can use Mastra's codemod CLI to update your code automatically:
|
|
164
|
+
>
|
|
165
|
+
> ```bash
|
|
166
|
+
> npx @mastra/codemod@latest v1/memory-vector-search-param .
|
|
167
|
+
> ```
|
|
168
|
+
|
|
169
|
+
### `MastraMessageV2` type renamed to `MastraDBMessage`
|
|
170
|
+
|
|
171
|
+
The `MastraMessageV2` type has been renamed to `MastraDBMessage` for clarity. This change better describes the purpose of this type as the database message format.
|
|
172
|
+
|
|
173
|
+
To migrate, replace all instances of `MastraMessageV2` with `MastraDBMessage`.
|
|
174
|
+
|
|
175
|
+
```diff
|
|
176
|
+
- import { MastraMessageV2 } from '@mastra/core';
|
|
177
|
+
- function yourCustomFunction(input: MastraMessageV2) {}
|
|
178
|
+
+ import { MastraDBMessage } from '@mastra/core';
|
|
179
|
+
+ function yourCustomFunction(input: MastraDBMessage) {}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
> **Codemod:** You can use Mastra's codemod CLI to update your code automatically:
|
|
183
|
+
>
|
|
184
|
+
> ```bash
|
|
185
|
+
> npx @mastra/codemod@latest v1/memory-message-v2-type .
|
|
186
|
+
> ```
|
|
187
|
+
|
|
188
|
+
## Removed
|
|
189
|
+
|
|
190
|
+
### Working memory `text-stream` mode
|
|
191
|
+
|
|
192
|
+
Working memory `use: "text-stream"` option has been removed. Only `tool-call` mode is supported. This change simplifies the working memory API by removing the less reliable streaming mode.
|
|
193
|
+
|
|
194
|
+
To migrate, remove the `use: "text-stream"` option. Working memory will default to tool-call mode.
|
|
195
|
+
|
|
196
|
+
```diff
|
|
197
|
+
const memory = new Memory({
|
|
198
|
+
storage,
|
|
199
|
+
vector,
|
|
200
|
+
embedder,
|
|
201
|
+
options: {
|
|
202
|
+
workingMemory: {
|
|
203
|
+
enabled: true,
|
|
204
|
+
- use: 'text-stream',
|
|
205
|
+
template: '...',
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
});
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### `Memory.rememberMessages()` method
|
|
212
|
+
|
|
213
|
+
The `Memory.rememberMessages()` method has been removed. This method performed the same function as `query()` (now `recall()`), and consolidating to one method simplifies the API.
|
|
214
|
+
|
|
215
|
+
To migrate, replace `rememberMessages()` calls with `recall()`.
|
|
216
|
+
|
|
217
|
+
```diff
|
|
218
|
+
- const { messages } = await memory.rememberMessages({
|
|
219
|
+
+ const { messages } = await memory.recall({
|
|
220
|
+
threadId,
|
|
221
|
+
resourceId,
|
|
222
|
+
});
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### `format` parameter from memory methods
|
|
226
|
+
|
|
227
|
+
The `format` parameter has been removed from all memory get methods. `MastraDBMessage` is now the default return format everywhere. AI SDK format conversion has moved to dedicated utility functions in `@mastra/ai-sdk/ui`. This change improves tree-shaking by moving UI-specific conversion code to a separate package.
|
|
228
|
+
|
|
229
|
+
To migrate, remove the `format` parameter and use conversion functions for AI SDK formats.
|
|
230
|
+
|
|
231
|
+
```diff
|
|
232
|
+
- const messages = await memory.getMessages({ threadId, format: 'v2' });
|
|
233
|
+
- const uiMessages = await memory.getMessages({ threadId, format: 'ui' });
|
|
234
|
+
|
|
235
|
+
+ const result = await memory.recall({ threadId });
|
|
236
|
+
+ const messages = result.messages; // Always MastraDBMessage[]
|
|
237
|
+
+
|
|
238
|
+
+ // Use conversion functions for AI SDK formats
|
|
239
|
+
+ import { toAISdkV5Messages } from '@mastra/ai-sdk/ui';
|
|
240
|
+
+ const uiMessages = toAISdkV5Messages(messages);
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
### `MastraMessageV3` type
|
|
244
|
+
|
|
245
|
+
The `MastraMessageV3` type and related conversion methods have been removed. Messages now convert directly between `MastraMessageV2` (now `MastraDBMessage`) and AI SDK v5 formats. This change simplifies the architecture by removing an intermediary format.
|
|
246
|
+
|
|
247
|
+
To migrate, use `MastraDBMessage` for storage or AI SDK v5 message formats directly.
|
|
248
|
+
|
|
249
|
+
```diff
|
|
250
|
+
- import type { MastraMessageV3 } from '@mastra/core/agent';
|
|
251
|
+
- const v3Messages = messageList.get.all.v3();
|
|
252
|
+
|
|
253
|
+
+ // For storage
|
|
254
|
+
+ const v2Messages = messageList.get.all.v2();
|
|
255
|
+
+
|
|
256
|
+
+ // For AI SDK v5
|
|
257
|
+
+ const uiMessages = messageList.get.all.aiV5.ui();
|
|
258
|
+
+ const modelMessages = messageList.get.all.aiV5.model();
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### `processors` config from Memory constructor
|
|
262
|
+
|
|
263
|
+
The `processors` config option in the Memory constructor is no longer supported and throws an error. Configure processors at the Agent level, where processor behavior is scoped to agent execution.
|
|
264
|
+
|
|
265
|
+
To migrate, move processor configuration from Memory to Agent using `inputProcessors` and/or `outputProcessors`.
|
|
266
|
+
|
|
267
|
+
```diff
|
|
268
|
+
+ import { TokenLimiter } from '@mastra/core/processors';
|
|
269
|
+
+
|
|
270
|
+
const memory = new Memory({
|
|
271
|
+
storage,
|
|
272
|
+
vector,
|
|
273
|
+
embedder,
|
|
274
|
+
- processors: [/* ... */],
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
const agent = new Agent({
|
|
278
|
+
id: 'agent',
|
|
279
|
+
memory,
|
|
280
|
+
+ inputProcessors: [
|
|
281
|
+
+ new TokenLimiter({ limit: 4000 }), // Limits historical messages to fit context window
|
|
282
|
+
+ ],
|
|
283
|
+
});
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
Additionally, the `@mastra/memory/processors` import path has been removed. Import processors from `@mastra/core/processors` instead. See the [processors migration guide](https://mastra.ai/reference/migrations/upgrade-to-v1/processors) for details.
|
|
287
|
+
|
|
288
|
+
For more information on using processors with agents, see the [Processors docs](https://mastra.ai/docs/agents/processors). For a complete example with memory, see the [TokenLimiter reference](https://mastra.ai/reference/processors/token-limiter-processor).
|
|
@@ -342,6 +342,6 @@ export const oracleAgent = new Agent({
|
|
|
342
342
|
|
|
343
343
|
## Related
|
|
344
344
|
|
|
345
|
-
- [OracleDB storage](https://mastra.ai/
|
|
345
|
+
- [OracleDB storage](https://mastra.ai/integrations/databases/oracledb)
|
|
346
346
|
- [Metadata Filters](https://mastra.ai/reference/rag/metadata-filters)
|
|
347
|
-
- [Vector databases](https://mastra.ai/
|
|
347
|
+
- [Vector databases](https://mastra.ai/reference/rag/vector-databases)
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_src = require("./src-
|
|
2
|
+
const require_src = require("./src-CTwoCwmY.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-
|
|
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-DGdlH4fo.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-
|
|
2
|
+
const require_src = require("../src-CTwoCwmY.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;
|
package/dist/processors/index.js
CHANGED
|
@@ -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-
|
|
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-DGdlH4fo.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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"async-buffer.d.ts","sourceRoot":"","sources":["../../../../src/processors/observational-memory/observation-strategies/async-buffer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAc1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAExF,qBAAa,8BAA+B,SAAQ,mBAAmB;IACrE,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,oBAAoB,CAAC,CAA0B;gBAE3C,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,kBAAkB;IAMxD,IAAI,SAAS,YAEZ;IACD,IAAI,eAAe,YAElB;IACD,IAAI,gBAAgB,YAEnB;cAEkB,eAAe,IAAI,MAAM;IAItC,OAAO;;;;IAQP,gBAAgB,CAAC,QAAQ,EAAE,MAAM;IAIjC,OAAO,CAAC,oBAAoB,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,EAAE;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"async-buffer.d.ts","sourceRoot":"","sources":["../../../../src/processors/observational-memory/observation-strategies/async-buffer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAc1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAExF,qBAAa,8BAA+B,SAAQ,mBAAmB;IACrE,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,oBAAoB,CAAC,CAA0B;gBAE3C,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,kBAAkB;IAMxD,IAAI,SAAS,YAEZ;IACD,IAAI,eAAe,YAElB;IACD,IAAI,gBAAgB,YAEnB;cAEkB,eAAe,IAAI,MAAM;IAItC,OAAO;;;;IAQP,gBAAgB,CAAC,QAAQ,EAAE,MAAM;IAIjC,OAAO,CAAC,oBAAoB,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,EAAE;;;;;;;;;uBAqJpD,CAAC;wBAAsB,CAAC;uBAAqB,CAAC;;;;IApH3D,OAAO,CAAC,MAAM,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC;IA6C7F,OAAO,CAAC,SAAS,EAAE,oBAAoB;IAkEvC,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,oBAAoB;IA6BhE,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO;CAkBzD"}
|
|
@@ -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
|
|
55
|
-
|
|
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
|
-
|
|
17676
|
-
|
|
17677
|
-
|
|
17678
|
-
|
|
17679
|
-
|
|
17680
|
-
|
|
17681
|
-
|
|
17682
|
-
|
|
17683
|
-
|
|
17684
|
-
|
|
17685
|
-
|
|
17686
|
-
|
|
17687
|
-
|
|
17688
|
-
|
|
17689
|
-
}
|
|
17690
|
-
|
|
17691
|
-
|
|
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, "");
|
|
@@ -21400,7 +21433,7 @@ var SyncObservationStrategy = class extends ObservationStrategy {
|
|
|
21400
21433
|
},
|
|
21401
21434
|
lastObservedMessageCursor: getLastObservedMessageCursor(messages)
|
|
21402
21435
|
});
|
|
21403
|
-
await this.storage.
|
|
21436
|
+
await this.storage.patchThread({
|
|
21404
21437
|
id: threadId,
|
|
21405
21438
|
...shouldUpdateThreadTitle ? { title: newTitle } : {},
|
|
21406
21439
|
metadata: newMetadata
|
|
@@ -21592,7 +21625,7 @@ var AsyncBufferObservationStrategy = class extends ObservationStrategy {
|
|
|
21592
21625
|
...metadataUpdate.extracted ?? {}
|
|
21593
21626
|
}
|
|
21594
21627
|
});
|
|
21595
|
-
await this.storage.
|
|
21628
|
+
await this.storage.patchThread({
|
|
21596
21629
|
id: threadId,
|
|
21597
21630
|
...shouldUpdateThreadTitle ? { title: newTitle } : {},
|
|
21598
21631
|
metadata: newMetadata
|
|
@@ -21937,7 +21970,7 @@ var ResourceScopedObservationStrategy = class extends ObservationStrategy {
|
|
|
21937
21970
|
},
|
|
21938
21971
|
lastObservedMessageCursor: update.lastObservedMessageCursor
|
|
21939
21972
|
});
|
|
21940
|
-
await this.storage.
|
|
21973
|
+
await this.storage.patchThread({
|
|
21941
21974
|
id: update.threadId,
|
|
21942
21975
|
...shouldUpdateThreadTitle ? { title: newTitle } : {},
|
|
21943
21976
|
metadata: newMetadata
|
|
@@ -22880,7 +22913,7 @@ async function persistThreadExtractedValues(storage, extractors, threadId, value
|
|
|
22880
22913
|
...metadataUpdate.extracted ?? {}
|
|
22881
22914
|
}
|
|
22882
22915
|
});
|
|
22883
|
-
await storage.
|
|
22916
|
+
await storage.patchThread({
|
|
22884
22917
|
id: threadId,
|
|
22885
22918
|
metadata: newMetadata
|
|
22886
22919
|
});
|
|
@@ -25851,7 +25884,7 @@ ${formattedMessages}
|
|
|
25851
25884
|
const oldTitle = thread.title?.trim();
|
|
25852
25885
|
const newTitle = chunkThreadTitle?.trim();
|
|
25853
25886
|
const shouldUpdateThreadTitle = !!newTitle && newTitle.length >= 3 && newTitle !== oldTitle;
|
|
25854
|
-
await this.storage.
|
|
25887
|
+
await this.storage.patchThread({
|
|
25855
25888
|
id: threadId,
|
|
25856
25889
|
...shouldUpdateThreadTitle ? { title: newTitle } : {},
|
|
25857
25890
|
metadata: newMetadata
|
|
@@ -26069,7 +26102,7 @@ ${formattedMessages}
|
|
|
26069
26102
|
...metadataUpdate.extracted ?? {}
|
|
26070
26103
|
}
|
|
26071
26104
|
});
|
|
26072
|
-
await this.storage.
|
|
26105
|
+
await this.storage.patchThread({
|
|
26073
26106
|
id: threadId,
|
|
26074
26107
|
metadata: newMetadata
|
|
26075
26108
|
});
|
|
@@ -27123,7 +27156,7 @@ var Memory = class extends _mastra_core_memory.MastraMemory {
|
|
|
27123
27156
|
return savedThread;
|
|
27124
27157
|
}
|
|
27125
27158
|
async updateThread({ id, title, metadata, memoryConfig }) {
|
|
27126
|
-
const updatedThread = await (await this.getMemoryStore()).
|
|
27159
|
+
const updatedThread = await (await this.getMemoryStore()).patchThread({
|
|
27127
27160
|
id,
|
|
27128
27161
|
title,
|
|
27129
27162
|
metadata
|
|
@@ -27214,7 +27247,7 @@ var Memory = class extends _mastra_core_memory.MastraMemory {
|
|
|
27214
27247
|
else {
|
|
27215
27248
|
const thread = await this.getThreadById({ threadId });
|
|
27216
27249
|
if (!thread) throw new Error(`Thread ${threadId} not found`);
|
|
27217
|
-
await memoryStore.
|
|
27250
|
+
await memoryStore.patchThread({
|
|
27218
27251
|
id: threadId,
|
|
27219
27252
|
metadata: {
|
|
27220
27253
|
...thread.metadata,
|
|
@@ -27302,7 +27335,7 @@ ${workingMemory}`;
|
|
|
27302
27335
|
} else {
|
|
27303
27336
|
const thread = await this.getThreadById({ threadId });
|
|
27304
27337
|
if (!thread) throw new Error(`Thread ${threadId} not found`);
|
|
27305
|
-
await memoryStore.
|
|
27338
|
+
await memoryStore.patchThread({
|
|
27306
27339
|
id: threadId,
|
|
27307
27340
|
metadata: {
|
|
27308
27341
|
...thread.metadata,
|
|
@@ -28873,4 +28906,4 @@ Object.defineProperty(exports, "wrapInObservationGroup", {
|
|
|
28873
28906
|
}
|
|
28874
28907
|
});
|
|
28875
28908
|
|
|
28876
|
-
//# sourceMappingURL=src-
|
|
28909
|
+
//# sourceMappingURL=src-CTwoCwmY.cjs.map
|