@mastra/memory 0.0.2-alpha.8 → 0.1.0-alpha.65

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,445 @@
1
1
  # @mastra/memory
2
2
 
3
+ ## 0.1.0-alpha.65
4
+
5
+ ### Minor Changes
6
+
7
+ - 30322ce: Added new Memory API for managed agent memory via MastraStorage and MastraVector classes
8
+
9
+ ### Patch Changes
10
+
11
+ - c35aa18: bug: not all models support multiple system messages
12
+ - 9625602: Use mastra core splitted bundles in other packages
13
+ - Updated dependencies [30322ce]
14
+ - Updated dependencies [78eec7c]
15
+ - Updated dependencies [9625602]
16
+ - Updated dependencies [8769a62]
17
+ - @mastra/core@0.2.0-alpha.83
18
+
19
+ ## 0.0.2-alpha.64
20
+
21
+ ### Patch Changes
22
+
23
+ - Updated dependencies [73d112c]
24
+ - @mastra/core@0.1.27-alpha.82
25
+
26
+ ## 0.0.2-alpha.63
27
+
28
+ ### Patch Changes
29
+
30
+ - Updated dependencies [9fb3039]
31
+ - @mastra/core@0.1.27-alpha.81
32
+
33
+ ## 0.0.2-alpha.62
34
+
35
+ ### Patch Changes
36
+
37
+ - 7f5b1b2: @mastra/memory tsup bundling
38
+
39
+ ## 0.0.2-alpha.61
40
+
41
+ ### Patch Changes
42
+
43
+ - Updated dependencies [327ece7]
44
+ - @mastra/core@0.1.27-alpha.80
45
+
46
+ ## 0.0.2-alpha.60
47
+
48
+ ### Patch Changes
49
+
50
+ - Updated dependencies [21fe536]
51
+ - @mastra/core@0.1.27-alpha.79
52
+
53
+ ## 0.0.2-alpha.59
54
+
55
+ ### Patch Changes
56
+
57
+ - Updated dependencies [685108a]
58
+ - Updated dependencies [685108a]
59
+ - @mastra/core@0.1.27-alpha.78
60
+
61
+ ## 0.0.2-alpha.58
62
+
63
+ ### Patch Changes
64
+
65
+ - Updated dependencies [8105fae]
66
+ - @mastra/core@0.1.27-alpha.77
67
+
68
+ ## 0.0.2-alpha.57
69
+
70
+ ### Patch Changes
71
+
72
+ - Updated dependencies [ae7bf94]
73
+ - Updated dependencies [ae7bf94]
74
+ - @mastra/core@0.1.27-alpha.76
75
+
76
+ ## 0.0.2-alpha.56
77
+
78
+ ### Patch Changes
79
+
80
+ - Updated dependencies [23dcb23]
81
+ - @mastra/core@0.1.27-alpha.75
82
+
83
+ ## 0.0.2-alpha.55
84
+
85
+ ### Patch Changes
86
+
87
+ - Updated dependencies [7b87567]
88
+ - @mastra/core@0.1.27-alpha.74
89
+
90
+ ## 0.0.2-alpha.54
91
+
92
+ ### Patch Changes
93
+
94
+ - Updated dependencies [3427b95]
95
+ - @mastra/core@0.1.27-alpha.73
96
+
97
+ ## 0.0.2-alpha.53
98
+
99
+ ### Patch Changes
100
+
101
+ - Updated dependencies [e4d4ede]
102
+ - Updated dependencies [06b2c0a]
103
+ - @mastra/core@0.1.27-alpha.72
104
+
105
+ ## 0.0.2-alpha.52
106
+
107
+ ### Patch Changes
108
+
109
+ - Updated dependencies [d9c8dd0]
110
+ - @mastra/core@0.1.27-alpha.71
111
+
112
+ ## 0.0.2-alpha.51
113
+
114
+ ### Patch Changes
115
+
116
+ - bdaf834: publish packages
117
+
118
+ ## 0.0.2-alpha.50
119
+
120
+ ### Patch Changes
121
+
122
+ - Updated dependencies [dd6d87f]
123
+ - Updated dependencies [04434b6]
124
+ - @mastra/core@0.1.27-alpha.70
125
+
126
+ ## 0.0.2-alpha.49
127
+
128
+ ### Patch Changes
129
+
130
+ - Updated dependencies [1944807]
131
+ - Updated dependencies [9ade36e]
132
+ - @mastra/core@0.1.27-alpha.69
133
+
134
+ ## 0.0.2-alpha.48
135
+
136
+ ### Patch Changes
137
+
138
+ - Updated dependencies [0be7181]
139
+ - Updated dependencies [0be7181]
140
+ - @mastra/core@0.1.27-alpha.68
141
+
142
+ ## 0.0.2-alpha.47
143
+
144
+ ### Patch Changes
145
+
146
+ - Updated dependencies [c8ff2f5]
147
+ - @mastra/core@0.1.27-alpha.67
148
+
149
+ ## 0.0.2-alpha.46
150
+
151
+ ### Patch Changes
152
+
153
+ - Updated dependencies [14064f2]
154
+ - @mastra/core@0.1.27-alpha.66
155
+
156
+ ## 0.0.2-alpha.45
157
+
158
+ ### Patch Changes
159
+
160
+ - Updated dependencies [e66643a]
161
+ - @mastra/core@0.1.27-alpha.65
162
+
163
+ ## 0.0.2-alpha.44
164
+
165
+ ### Patch Changes
166
+
167
+ - Updated dependencies [f368477]
168
+ - Updated dependencies [d5ec619]
169
+ - @mastra/core@0.1.27-alpha.64
170
+
171
+ ## 0.0.2-alpha.43
172
+
173
+ ### Patch Changes
174
+
175
+ - Updated dependencies [e097800]
176
+ - @mastra/core@0.1.27-alpha.63
177
+
178
+ ## 0.0.2-alpha.42
179
+
180
+ ### Patch Changes
181
+
182
+ - Updated dependencies [93a3719]
183
+ - @mastra/core@0.1.27-alpha.62
184
+
185
+ ## 0.0.2-alpha.41
186
+
187
+ ### Patch Changes
188
+
189
+ - Updated dependencies [dc90663]
190
+ - @mastra/core@0.1.27-alpha.61
191
+
192
+ ## 0.0.2-alpha.40
193
+
194
+ ### Patch Changes
195
+
196
+ - Updated dependencies [3967e69]
197
+ - @mastra/core@0.1.27-alpha.60
198
+
199
+ ## 0.0.2-alpha.39
200
+
201
+ ### Patch Changes
202
+
203
+ - Updated dependencies [b524c22]
204
+ - @mastra/core@0.1.27-alpha.59
205
+
206
+ ## 0.0.2-alpha.38
207
+
208
+ ### Patch Changes
209
+
210
+ - Updated dependencies [1874f40]
211
+ - Updated dependencies [4b1ce2c]
212
+ - @mastra/core@0.1.27-alpha.58
213
+
214
+ ## 0.0.2-alpha.37
215
+
216
+ ### Patch Changes
217
+
218
+ - Updated dependencies [fd494a3]
219
+ - @mastra/core@0.1.27-alpha.57
220
+
221
+ ## 0.0.2-alpha.36
222
+
223
+ ### Patch Changes
224
+
225
+ - Updated dependencies [9f3ab05]
226
+ - @mastra/core@0.1.27-alpha.56
227
+
228
+ ## 0.0.2-alpha.35
229
+
230
+ ### Patch Changes
231
+
232
+ - 837a288: MAJOR Revamp of tools, workflows, syncs.
233
+ - 0b74006: Workflow updates
234
+ - Updated dependencies [592e3cf]
235
+ - Updated dependencies [837a288]
236
+ - Updated dependencies [0b74006]
237
+ - @mastra/core@0.1.27-alpha.55
238
+
239
+ ## 0.0.2-alpha.34
240
+
241
+ ### Patch Changes
242
+
243
+ - Updated dependencies [d2cd535]
244
+ - @mastra/core@0.1.27-alpha.54
245
+
246
+ ## 0.0.2-alpha.33
247
+
248
+ ### Patch Changes
249
+
250
+ - Updated dependencies [8e7814f]
251
+ - @mastra/core@0.1.27-alpha.53
252
+
253
+ ## 0.0.2-alpha.32
254
+
255
+ ### Patch Changes
256
+
257
+ - Updated dependencies [eedb829]
258
+ - @mastra/core@0.1.27-alpha.52
259
+
260
+ ## 0.0.2-alpha.31
261
+
262
+ ### Patch Changes
263
+
264
+ - Updated dependencies [a7b016d]
265
+ - Updated dependencies [da2e8d3]
266
+ - Updated dependencies [538a136]
267
+ - @mastra/core@0.1.27-alpha.51
268
+
269
+ ## 0.0.2-alpha.30
270
+
271
+ ### Patch Changes
272
+
273
+ - Updated dependencies [401a4d9]
274
+ - @mastra/core@0.1.27-alpha.50
275
+
276
+ ## 0.0.2-alpha.29
277
+
278
+ ### Patch Changes
279
+
280
+ - Updated dependencies [79acad0]
281
+ - Updated dependencies [f5dfa20]
282
+ - @mastra/core@0.1.27-alpha.49
283
+
284
+ ## 0.0.2-alpha.28
285
+
286
+ ### Patch Changes
287
+
288
+ - Updated dependencies [b726bf5]
289
+ - @mastra/core@0.1.27-alpha.48
290
+
291
+ ## 0.0.2-alpha.27
292
+
293
+ ### Patch Changes
294
+
295
+ - Updated dependencies [f6ba259]
296
+ - @mastra/core@0.1.27-alpha.47
297
+
298
+ ## 0.0.2-alpha.26
299
+
300
+ ### Patch Changes
301
+
302
+ - 8ae2bbc: Dane publishing
303
+ - 0bd142c: Fixes learned from docs
304
+ - ee4de15: Dane fixes
305
+ - Updated dependencies [8ae2bbc]
306
+ - Updated dependencies [0bd142c]
307
+ - Updated dependencies [ee4de15]
308
+ - @mastra/core@0.1.27-alpha.46
309
+
310
+ ## 0.0.2-alpha.25
311
+
312
+ ### Patch Changes
313
+
314
+ - 3220d26: Fix lastStep error in agent stream
315
+
316
+ ## 0.0.2-alpha.24
317
+
318
+ ### Patch Changes
319
+
320
+ - 002d6d8: add memory to playground agent
321
+ - Updated dependencies [e608d8c]
322
+ - Updated dependencies [002d6d8]
323
+ - @mastra/core@0.1.27-alpha.45
324
+
325
+ ## 0.0.2-alpha.23
326
+
327
+ ### Patch Changes
328
+
329
+ - Updated dependencies [2fa7f53]
330
+ - @mastra/core@0.1.27-alpha.44
331
+
332
+ ## 0.0.2-alpha.22
333
+
334
+ ### Patch Changes
335
+
336
+ - Updated dependencies [2e099d2]
337
+ - Updated dependencies [d6d8159]
338
+ - @mastra/core@0.1.27-alpha.43
339
+
340
+ ## 0.0.2-alpha.21
341
+
342
+ ### Patch Changes
343
+
344
+ - Updated dependencies [4a54c82]
345
+ - @mastra/core@0.1.27-alpha.42
346
+
347
+ ## 0.0.2-alpha.20
348
+
349
+ ### Patch Changes
350
+
351
+ - Updated dependencies [5cdfb88]
352
+ - @mastra/core@0.1.27-alpha.41
353
+
354
+ ## 0.0.2-alpha.19
355
+
356
+ ### Patch Changes
357
+
358
+ - Updated dependencies [9029796]
359
+ - @mastra/core@0.1.27-alpha.40
360
+
361
+ ## 0.0.2-alpha.18
362
+
363
+ ### Patch Changes
364
+
365
+ - Updated dependencies [2b01511]
366
+ - @mastra/core@0.1.27-alpha.39
367
+
368
+ ## 0.0.2-alpha.17
369
+
370
+ ### Patch Changes
371
+
372
+ - Updated dependencies [f031a1f]
373
+ - @mastra/core@0.1.27-alpha.38
374
+
375
+ ## 0.0.2-alpha.16
376
+
377
+ ### Patch Changes
378
+
379
+ - b5393f1: New example: Dane and many fixes to make it work
380
+ - Updated dependencies [c872875]
381
+ - Updated dependencies [f6da688]
382
+ - Updated dependencies [b5393f1]
383
+ - @mastra/core@0.1.27-alpha.37
384
+
385
+ ## 0.0.2-alpha.15
386
+
387
+ ### Patch Changes
388
+
389
+ - b898fad: Fix get context window in memory
390
+ - Updated dependencies [f537e33]
391
+ - Updated dependencies [bc40916]
392
+ - Updated dependencies [f7d1131]
393
+ - Updated dependencies [75bf3f0]
394
+ - Updated dependencies [3c4488b]
395
+ - Updated dependencies [d38f7a6]
396
+ - @mastra/core@0.1.27-alpha.36
397
+
398
+ ## 0.0.2-alpha.14
399
+
400
+ ### Patch Changes
401
+
402
+ - 033eda6: More fixes for refactor
403
+ - Updated dependencies [033eda6]
404
+ - @mastra/core@0.1.27-alpha.35
405
+
406
+ ## 0.0.2-alpha.13
407
+
408
+ ### Patch Changes
409
+
410
+ - 837a288: MAJOR Revamp of tools, workflows, syncs.
411
+ - Updated dependencies [837a288]
412
+ - Updated dependencies [5811de6]
413
+ - @mastra/core@0.1.27-alpha.34
414
+
415
+ ## 0.0.2-alpha.12
416
+
417
+ ### Patch Changes
418
+
419
+ - Updated dependencies [e1dd94a]
420
+ - @mastra/core@0.1.27-alpha.33
421
+
422
+ ## 0.0.2-alpha.11
423
+
424
+ ### Patch Changes
425
+
426
+ - Updated dependencies [2712098]
427
+ - @mastra/core@0.1.27-alpha.32
428
+
429
+ ## 0.0.2-alpha.10
430
+
431
+ ### Patch Changes
432
+
433
+ - Updated dependencies [c2dd6b5]
434
+ - @mastra/core@0.1.27-alpha.31
435
+
436
+ ## 0.0.2-alpha.9
437
+
438
+ ### Patch Changes
439
+
440
+ - Updated dependencies [963c15a]
441
+ - @mastra/core@0.1.27-alpha.30
442
+
3
443
  ## 0.0.2-alpha.8
4
444
 
5
445
  ### Patch Changes
package/LICENSE ADDED
@@ -0,0 +1,44 @@
1
+ Elastic License 2.0 (ELv2)
2
+
3
+ **Acceptance**
4
+ By using the software, you agree to all of the terms and conditions below.
5
+
6
+ **Copyright License**
7
+ The licensor grants you a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable license to use, copy, distribute, make available, and prepare derivative works of the software, in each case subject to the limitations and conditions below
8
+
9
+ **Limitations**
10
+ You may not provide the software to third parties as a hosted or managed service, where the service provides users with access to any substantial set of the features or functionality of the software.
11
+
12
+ You may not move, change, disable, or circumvent the license key functionality in the software, and you may not remove or obscure any functionality in the software that is protected by the license key.
13
+
14
+ You may not alter, remove, or obscure any licensing, copyright, or other notices of the licensor in the software. Any use of the licensor’s trademarks is subject to applicable law.
15
+
16
+ **Patents**
17
+ The licensor grants you a license, under any patent claims the licensor can license, or becomes able to license, to make, have made, use, sell, offer for sale, import and have imported the software, in each case subject to the limitations and conditions in this license. This license does not cover any patent claims that you cause to be infringed by modifications or additions to the software. If you or your company make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
18
+
19
+ **Notices**
20
+ You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms.
21
+
22
+ If you modify the software, you must include in any modified copies of the software prominent notices stating that you have modified the software.
23
+
24
+ **No Other Rights**
25
+ These terms do not imply any licenses other than those expressly granted in these terms.
26
+
27
+ **Termination**
28
+ If you use the software in violation of these terms, such use is not licensed, and your licenses will automatically terminate. If the licensor provides you with a notice of your violation, and you cease all violation of this license no later than 30 days after you receive that notice, your licenses will be reinstated retroactively. However, if you violate these terms after such reinstatement, any additional violation of these terms will cause your licenses to terminate automatically and permanently.
29
+
30
+ **No Liability**
31
+ As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.
32
+
33
+ **Definitions**
34
+ The _licensor_ is the entity offering these terms, and the _software_ is the software the licensor makes available under these terms, including any portion of it.
35
+
36
+ _you_ refers to the individual or entity agreeing to these terms.
37
+
38
+ _your company_ is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. _control_ means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
39
+
40
+ _your licenses_ are all the licenses granted to you for the software under these terms.
41
+
42
+ _use_ means anything you do with the software requiring one of your licenses.
43
+
44
+ _trademark_ means trademarks, service marks, and similar rights.
package/dist/index.d.ts CHANGED
@@ -1,2 +1,44 @@
1
- export * from './postgres';
2
- export * from './kv/upstash';
1
+ import { CoreMessage } from '@mastra/core';
2
+ import { MastraMemory, SharedMemoryConfig, MemoryConfig, StorageThreadType, MessageType } from '@mastra/core/memory';
3
+ import { StorageGetMessagesArg } from '@mastra/core/storage';
4
+ import { Message } from 'ai';
5
+
6
+ /**
7
+ * Concrete implementation of MastraMemory that adds support for thread configuration
8
+ * and message injection.
9
+ */
10
+ declare class Memory extends MastraMemory {
11
+ constructor(config: SharedMemoryConfig);
12
+ getMessages({ threadId, selectBy, threadConfig, }: StorageGetMessagesArg): Promise<{
13
+ messages: CoreMessage[];
14
+ uiMessages: Message[];
15
+ }>;
16
+ rememberMessages({ threadId, vectorMessageSearch, config, }: {
17
+ threadId: string;
18
+ vectorMessageSearch?: string;
19
+ config?: MemoryConfig;
20
+ }): Promise<{
21
+ messages: CoreMessage[];
22
+ uiMessages: Message[];
23
+ }>;
24
+ getThreadById({ threadId }: {
25
+ threadId: string;
26
+ }): Promise<StorageThreadType | null>;
27
+ getThreadsByResourceId({ resourceId }: {
28
+ resourceId: string;
29
+ }): Promise<StorageThreadType[]>;
30
+ saveThread({ thread }: {
31
+ thread: StorageThreadType;
32
+ }): Promise<StorageThreadType>;
33
+ updateThread({ id, title, metadata, }: {
34
+ id: string;
35
+ title: string;
36
+ metadata: Record<string, unknown>;
37
+ }): Promise<StorageThreadType>;
38
+ saveMessages({ messages }: {
39
+ messages: MessageType[];
40
+ }): Promise<MessageType[]>;
41
+ deleteThread(threadId: string): Promise<void>;
42
+ }
43
+
44
+ export { Memory };
package/dist/index.js CHANGED
@@ -1,8 +1,119 @@
1
+ import { MastraMemory } from '@mastra/core/memory';
1
2
 
2
- 'use strict'
3
+ // src/index.ts
4
+ var Memory = class extends MastraMemory {
5
+ constructor(config) {
6
+ super({ name: "Memory", ...config });
7
+ }
8
+ async getMessages({
9
+ threadId,
10
+ selectBy,
11
+ threadConfig
12
+ }) {
13
+ let vectorResults = null;
14
+ this.logger.info(`Memory getMessages() with:`, {
15
+ threadId,
16
+ selectBy,
17
+ threadConfig
18
+ });
19
+ const config = this.getMergedThreadConfig(threadConfig || {});
20
+ const vectorConfig = typeof config?.injectVectorHistorySearch === `boolean` ? {
21
+ includeResults: 2,
22
+ includePrevious: 2,
23
+ includeNext: 2
24
+ } : {
25
+ includeResults: config?.injectVectorHistorySearch?.includeResults || 2,
26
+ includePrevious: config?.injectVectorHistorySearch?.includePrevious || 2,
27
+ includeNext: config?.injectVectorHistorySearch?.includeNext || 2
28
+ };
29
+ if (selectBy?.vectorSearchString && this.vector) {
30
+ const { embeddings } = await this.vector.embed(selectBy.vectorSearchString, this.parseEmbeddingOptions());
31
+ await this.vector.createIndex("memory_messages", 1536);
32
+ vectorResults = await this.vector.query("memory_messages", embeddings[0], vectorConfig.includeResults, {
33
+ thread_id: threadId
34
+ });
35
+ }
36
+ const rawMessages = await this.storage.__getMessages({
37
+ threadId,
38
+ selectBy: {
39
+ ...selectBy,
40
+ ...vectorResults?.length ? {
41
+ include: vectorResults.map((r) => ({
42
+ id: r.metadata?.message_id,
43
+ withNextMessages: vectorConfig.includeNext,
44
+ withPreviousMessages: vectorConfig.includePrevious
45
+ }))
46
+ } : {}
47
+ },
48
+ threadConfig: config
49
+ });
50
+ const messages = this.parseMessages(rawMessages);
51
+ const uiMessages = this.convertToUIMessages(rawMessages);
52
+ return { messages, uiMessages };
53
+ }
54
+ async rememberMessages({
55
+ threadId,
56
+ vectorMessageSearch,
57
+ config
58
+ }) {
59
+ const threadConfig = this.getMergedThreadConfig(config || {});
60
+ if (!threadConfig.injectRecentMessages && !threadConfig.injectVectorHistorySearch) {
61
+ return {
62
+ messages: [],
63
+ uiMessages: []
64
+ };
65
+ }
66
+ const messages = await this.getMessages({
67
+ threadId,
68
+ selectBy: {
69
+ last: threadConfig.injectRecentMessages,
70
+ vectorSearchString: threadConfig.injectVectorHistorySearch && vectorMessageSearch ? vectorMessageSearch : undefined
71
+ },
72
+ threadConfig: config
73
+ });
74
+ this.logger.info(`Remembered message history includes ${messages.messages.length} messages.`);
75
+ return messages;
76
+ }
77
+ async getThreadById({ threadId }) {
78
+ return this.storage.__getThreadById({ threadId });
79
+ }
80
+ async getThreadsByResourceId({ resourceId }) {
81
+ return this.storage.__getThreadsByResourceId({ resourceId });
82
+ }
83
+ async saveThread({ thread }) {
84
+ return this.storage.__saveThread({ thread });
85
+ }
86
+ async updateThread({
87
+ id,
88
+ title,
89
+ metadata
90
+ }) {
91
+ return this.storage.__updateThread({
92
+ id,
93
+ title,
94
+ metadata
95
+ });
96
+ }
97
+ async saveMessages({ messages }) {
98
+ if (this.vector) {
99
+ await this.vector.createIndex("memory_messages", 1536);
100
+ for (const message of messages) {
101
+ if (typeof message.content !== `string`) continue;
102
+ const { embeddings } = await this.vector.embed(message.content, this.parseEmbeddingOptions());
103
+ await this.vector.upsert("memory_messages", embeddings, [
104
+ {
105
+ text: message.content,
106
+ message_id: message.id,
107
+ thread_id: message.threadId
108
+ }
109
+ ]);
110
+ }
111
+ }
112
+ return this.storage.__saveMessages({ messages });
113
+ }
114
+ async deleteThread(threadId) {
115
+ await this.storage.__deleteThread({ threadId });
116
+ }
117
+ };
3
118
 
4
- if (process.env.NODE_ENV === 'production') {
5
- module.exports = require('./memory.cjs.production.min.js')
6
- } else {
7
- module.exports = require('./memory.cjs.development.js')
8
- }
119
+ export { Memory };