@mastra/memory 0.0.2-alpha.6 → 0.0.2-alpha.61

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,423 @@
1
1
  # @mastra/memory
2
2
 
3
+ ## 0.0.2-alpha.61
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [327ece7]
8
+ - @mastra/core@0.1.27-alpha.80
9
+
10
+ ## 0.0.2-alpha.60
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies [21fe536]
15
+ - @mastra/core@0.1.27-alpha.79
16
+
17
+ ## 0.0.2-alpha.59
18
+
19
+ ### Patch Changes
20
+
21
+ - Updated dependencies [685108a]
22
+ - Updated dependencies [685108a]
23
+ - @mastra/core@0.1.27-alpha.78
24
+
25
+ ## 0.0.2-alpha.58
26
+
27
+ ### Patch Changes
28
+
29
+ - Updated dependencies [8105fae]
30
+ - @mastra/core@0.1.27-alpha.77
31
+
32
+ ## 0.0.2-alpha.57
33
+
34
+ ### Patch Changes
35
+
36
+ - Updated dependencies [ae7bf94]
37
+ - Updated dependencies [ae7bf94]
38
+ - @mastra/core@0.1.27-alpha.76
39
+
40
+ ## 0.0.2-alpha.56
41
+
42
+ ### Patch Changes
43
+
44
+ - Updated dependencies [23dcb23]
45
+ - @mastra/core@0.1.27-alpha.75
46
+
47
+ ## 0.0.2-alpha.55
48
+
49
+ ### Patch Changes
50
+
51
+ - Updated dependencies [7b87567]
52
+ - @mastra/core@0.1.27-alpha.74
53
+
54
+ ## 0.0.2-alpha.54
55
+
56
+ ### Patch Changes
57
+
58
+ - Updated dependencies [3427b95]
59
+ - @mastra/core@0.1.27-alpha.73
60
+
61
+ ## 0.0.2-alpha.53
62
+
63
+ ### Patch Changes
64
+
65
+ - Updated dependencies [e4d4ede]
66
+ - Updated dependencies [06b2c0a]
67
+ - @mastra/core@0.1.27-alpha.72
68
+
69
+ ## 0.0.2-alpha.52
70
+
71
+ ### Patch Changes
72
+
73
+ - Updated dependencies [d9c8dd0]
74
+ - @mastra/core@0.1.27-alpha.71
75
+
76
+ ## 0.0.2-alpha.51
77
+
78
+ ### Patch Changes
79
+
80
+ - bdaf834: publish packages
81
+
82
+ ## 0.0.2-alpha.50
83
+
84
+ ### Patch Changes
85
+
86
+ - Updated dependencies [dd6d87f]
87
+ - Updated dependencies [04434b6]
88
+ - @mastra/core@0.1.27-alpha.70
89
+
90
+ ## 0.0.2-alpha.49
91
+
92
+ ### Patch Changes
93
+
94
+ - Updated dependencies [1944807]
95
+ - Updated dependencies [9ade36e]
96
+ - @mastra/core@0.1.27-alpha.69
97
+
98
+ ## 0.0.2-alpha.48
99
+
100
+ ### Patch Changes
101
+
102
+ - Updated dependencies [0be7181]
103
+ - Updated dependencies [0be7181]
104
+ - @mastra/core@0.1.27-alpha.68
105
+
106
+ ## 0.0.2-alpha.47
107
+
108
+ ### Patch Changes
109
+
110
+ - Updated dependencies [c8ff2f5]
111
+ - @mastra/core@0.1.27-alpha.67
112
+
113
+ ## 0.0.2-alpha.46
114
+
115
+ ### Patch Changes
116
+
117
+ - Updated dependencies [14064f2]
118
+ - @mastra/core@0.1.27-alpha.66
119
+
120
+ ## 0.0.2-alpha.45
121
+
122
+ ### Patch Changes
123
+
124
+ - Updated dependencies [e66643a]
125
+ - @mastra/core@0.1.27-alpha.65
126
+
127
+ ## 0.0.2-alpha.44
128
+
129
+ ### Patch Changes
130
+
131
+ - Updated dependencies [f368477]
132
+ - Updated dependencies [d5ec619]
133
+ - @mastra/core@0.1.27-alpha.64
134
+
135
+ ## 0.0.2-alpha.43
136
+
137
+ ### Patch Changes
138
+
139
+ - Updated dependencies [e097800]
140
+ - @mastra/core@0.1.27-alpha.63
141
+
142
+ ## 0.0.2-alpha.42
143
+
144
+ ### Patch Changes
145
+
146
+ - Updated dependencies [93a3719]
147
+ - @mastra/core@0.1.27-alpha.62
148
+
149
+ ## 0.0.2-alpha.41
150
+
151
+ ### Patch Changes
152
+
153
+ - Updated dependencies [dc90663]
154
+ - @mastra/core@0.1.27-alpha.61
155
+
156
+ ## 0.0.2-alpha.40
157
+
158
+ ### Patch Changes
159
+
160
+ - Updated dependencies [3967e69]
161
+ - @mastra/core@0.1.27-alpha.60
162
+
163
+ ## 0.0.2-alpha.39
164
+
165
+ ### Patch Changes
166
+
167
+ - Updated dependencies [b524c22]
168
+ - @mastra/core@0.1.27-alpha.59
169
+
170
+ ## 0.0.2-alpha.38
171
+
172
+ ### Patch Changes
173
+
174
+ - Updated dependencies [1874f40]
175
+ - Updated dependencies [4b1ce2c]
176
+ - @mastra/core@0.1.27-alpha.58
177
+
178
+ ## 0.0.2-alpha.37
179
+
180
+ ### Patch Changes
181
+
182
+ - Updated dependencies [fd494a3]
183
+ - @mastra/core@0.1.27-alpha.57
184
+
185
+ ## 0.0.2-alpha.36
186
+
187
+ ### Patch Changes
188
+
189
+ - Updated dependencies [9f3ab05]
190
+ - @mastra/core@0.1.27-alpha.56
191
+
192
+ ## 0.0.2-alpha.35
193
+
194
+ ### Patch Changes
195
+
196
+ - 837a288: MAJOR Revamp of tools, workflows, syncs.
197
+ - 0b74006: Workflow updates
198
+ - Updated dependencies [592e3cf]
199
+ - Updated dependencies [837a288]
200
+ - Updated dependencies [0b74006]
201
+ - @mastra/core@0.1.27-alpha.55
202
+
203
+ ## 0.0.2-alpha.34
204
+
205
+ ### Patch Changes
206
+
207
+ - Updated dependencies [d2cd535]
208
+ - @mastra/core@0.1.27-alpha.54
209
+
210
+ ## 0.0.2-alpha.33
211
+
212
+ ### Patch Changes
213
+
214
+ - Updated dependencies [8e7814f]
215
+ - @mastra/core@0.1.27-alpha.53
216
+
217
+ ## 0.0.2-alpha.32
218
+
219
+ ### Patch Changes
220
+
221
+ - Updated dependencies [eedb829]
222
+ - @mastra/core@0.1.27-alpha.52
223
+
224
+ ## 0.0.2-alpha.31
225
+
226
+ ### Patch Changes
227
+
228
+ - Updated dependencies [a7b016d]
229
+ - Updated dependencies [da2e8d3]
230
+ - Updated dependencies [538a136]
231
+ - @mastra/core@0.1.27-alpha.51
232
+
233
+ ## 0.0.2-alpha.30
234
+
235
+ ### Patch Changes
236
+
237
+ - Updated dependencies [401a4d9]
238
+ - @mastra/core@0.1.27-alpha.50
239
+
240
+ ## 0.0.2-alpha.29
241
+
242
+ ### Patch Changes
243
+
244
+ - Updated dependencies [79acad0]
245
+ - Updated dependencies [f5dfa20]
246
+ - @mastra/core@0.1.27-alpha.49
247
+
248
+ ## 0.0.2-alpha.28
249
+
250
+ ### Patch Changes
251
+
252
+ - Updated dependencies [b726bf5]
253
+ - @mastra/core@0.1.27-alpha.48
254
+
255
+ ## 0.0.2-alpha.27
256
+
257
+ ### Patch Changes
258
+
259
+ - Updated dependencies [f6ba259]
260
+ - @mastra/core@0.1.27-alpha.47
261
+
262
+ ## 0.0.2-alpha.26
263
+
264
+ ### Patch Changes
265
+
266
+ - 8ae2bbc: Dane publishing
267
+ - 0bd142c: Fixes learned from docs
268
+ - ee4de15: Dane fixes
269
+ - Updated dependencies [8ae2bbc]
270
+ - Updated dependencies [0bd142c]
271
+ - Updated dependencies [ee4de15]
272
+ - @mastra/core@0.1.27-alpha.46
273
+
274
+ ## 0.0.2-alpha.25
275
+
276
+ ### Patch Changes
277
+
278
+ - 3220d26: Fix lastStep error in agent stream
279
+
280
+ ## 0.0.2-alpha.24
281
+
282
+ ### Patch Changes
283
+
284
+ - 002d6d8: add memory to playground agent
285
+ - Updated dependencies [e608d8c]
286
+ - Updated dependencies [002d6d8]
287
+ - @mastra/core@0.1.27-alpha.45
288
+
289
+ ## 0.0.2-alpha.23
290
+
291
+ ### Patch Changes
292
+
293
+ - Updated dependencies [2fa7f53]
294
+ - @mastra/core@0.1.27-alpha.44
295
+
296
+ ## 0.0.2-alpha.22
297
+
298
+ ### Patch Changes
299
+
300
+ - Updated dependencies [2e099d2]
301
+ - Updated dependencies [d6d8159]
302
+ - @mastra/core@0.1.27-alpha.43
303
+
304
+ ## 0.0.2-alpha.21
305
+
306
+ ### Patch Changes
307
+
308
+ - Updated dependencies [4a54c82]
309
+ - @mastra/core@0.1.27-alpha.42
310
+
311
+ ## 0.0.2-alpha.20
312
+
313
+ ### Patch Changes
314
+
315
+ - Updated dependencies [5cdfb88]
316
+ - @mastra/core@0.1.27-alpha.41
317
+
318
+ ## 0.0.2-alpha.19
319
+
320
+ ### Patch Changes
321
+
322
+ - Updated dependencies [9029796]
323
+ - @mastra/core@0.1.27-alpha.40
324
+
325
+ ## 0.0.2-alpha.18
326
+
327
+ ### Patch Changes
328
+
329
+ - Updated dependencies [2b01511]
330
+ - @mastra/core@0.1.27-alpha.39
331
+
332
+ ## 0.0.2-alpha.17
333
+
334
+ ### Patch Changes
335
+
336
+ - Updated dependencies [f031a1f]
337
+ - @mastra/core@0.1.27-alpha.38
338
+
339
+ ## 0.0.2-alpha.16
340
+
341
+ ### Patch Changes
342
+
343
+ - b5393f1: New example: Dane and many fixes to make it work
344
+ - Updated dependencies [c872875]
345
+ - Updated dependencies [f6da688]
346
+ - Updated dependencies [b5393f1]
347
+ - @mastra/core@0.1.27-alpha.37
348
+
349
+ ## 0.0.2-alpha.15
350
+
351
+ ### Patch Changes
352
+
353
+ - b898fad: Fix get context window in memory
354
+ - Updated dependencies [f537e33]
355
+ - Updated dependencies [bc40916]
356
+ - Updated dependencies [f7d1131]
357
+ - Updated dependencies [75bf3f0]
358
+ - Updated dependencies [3c4488b]
359
+ - Updated dependencies [d38f7a6]
360
+ - @mastra/core@0.1.27-alpha.36
361
+
362
+ ## 0.0.2-alpha.14
363
+
364
+ ### Patch Changes
365
+
366
+ - 033eda6: More fixes for refactor
367
+ - Updated dependencies [033eda6]
368
+ - @mastra/core@0.1.27-alpha.35
369
+
370
+ ## 0.0.2-alpha.13
371
+
372
+ ### Patch Changes
373
+
374
+ - 837a288: MAJOR Revamp of tools, workflows, syncs.
375
+ - Updated dependencies [837a288]
376
+ - Updated dependencies [5811de6]
377
+ - @mastra/core@0.1.27-alpha.34
378
+
379
+ ## 0.0.2-alpha.12
380
+
381
+ ### Patch Changes
382
+
383
+ - Updated dependencies [e1dd94a]
384
+ - @mastra/core@0.1.27-alpha.33
385
+
386
+ ## 0.0.2-alpha.11
387
+
388
+ ### Patch Changes
389
+
390
+ - Updated dependencies [2712098]
391
+ - @mastra/core@0.1.27-alpha.32
392
+
393
+ ## 0.0.2-alpha.10
394
+
395
+ ### Patch Changes
396
+
397
+ - Updated dependencies [c2dd6b5]
398
+ - @mastra/core@0.1.27-alpha.31
399
+
400
+ ## 0.0.2-alpha.9
401
+
402
+ ### Patch Changes
403
+
404
+ - Updated dependencies [963c15a]
405
+ - @mastra/core@0.1.27-alpha.30
406
+
407
+ ## 0.0.2-alpha.8
408
+
409
+ ### Patch Changes
410
+
411
+ - Updated dependencies [7d87a15]
412
+ - @mastra/core@0.1.27-alpha.29
413
+
414
+ ## 0.0.2-alpha.7
415
+
416
+ ### Patch Changes
417
+
418
+ - Updated dependencies [1ebd071]
419
+ - @mastra/core@0.1.27-alpha.28
420
+
3
421
  ## 0.0.2-alpha.6
4
422
 
5
423
  ### 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,3 @@
1
1
  export * from './postgres';
2
2
  export * from './kv/upstash';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC"}
@@ -1,6 +1,6 @@
1
- import { MastraMemory, MessageType as BaseMastraMessageType, ThreadType, MessageResponse } from '@mastra/core';
1
+ import { MastraMemory, MessageType as BaseMastraMessageType, ThreadType, MessageResponse, AiMessageType } from '@mastra/core';
2
2
  import { Redis } from '@upstash/redis';
3
- import { ToolResultPart, Message as AiMessage } from 'ai';
3
+ import { ToolResultPart } from 'ai';
4
4
  interface MessageType extends BaseMastraMessageType {
5
5
  tokens?: number;
6
6
  }
@@ -51,11 +51,11 @@ export declare class UpstashKVMemory extends MastraMemory {
51
51
  /**
52
52
  * Messages
53
53
  */
54
- getMessages({ threadId }: {
54
+ getMessages({ threadId, }: {
55
55
  threadId: string;
56
56
  }): Promise<{
57
57
  messages: MessageType[];
58
- uiMessages: AiMessage[];
58
+ uiMessages: AiMessageType[];
59
59
  }>;
60
60
  saveMessages({ messages }: {
61
61
  messages: MessageType[];
@@ -69,3 +69,4 @@ export declare class UpstashKVMemory extends MastraMemory {
69
69
  parseMessages(messages: MessageType[]): MessageType[];
70
70
  }
71
71
  export {};
72
+ //# sourceMappingURL=upstash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upstash.d.ts","sourceRoot":"","sources":["../../src/kv/upstash.ts"],"names":[],"mappings":"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"}
@@ -712,14 +712,14 @@ var PgMemory = /*#__PURE__*/function (_MastraMemory) {
712
712
  break;
713
713
  }
714
714
  _context8.next = 10;
715
- return client.query("WITH RankedMessages AS (\n SELECT *,\n SUM(tokens) OVER (ORDER BY created_at DESC) as running_total\n FROM mastra_messages\n WHERE thread_id = $1\n AND type = 'text'\n " + (startDate ? "AND created_at >= '" + startDate.toISOString() + "'" : '') + "\n " + (endDate ? "AND created_at <= '" + endDate.toISOString() + "'" : '') + "\n ORDER BY created_at DESC\n )\n SELECT id, \n content, \n role, \n type,\n created_at AS createdAt, \n thread_id AS threadId\n FROM RankedMessages\n WHERE running_total <= $2\n ORDER BY created_at ASC", [threadId, this.MAX_CONTEXT_TOKENS]);
715
+ return client.query("WITH RankedMessages AS (\n SELECT *,\n SUM(tokens) OVER (ORDER BY created_at DESC) as running_total\n FROM mastra_messages\n WHERE thread_id = $1\n " + (startDate ? "AND created_at >= '" + startDate.toISOString() + "'" : '') + "\n " + (endDate ? "AND created_at <= '" + endDate.toISOString() + "'" : '') + "\n ORDER BY created_at DESC\n )\n SELECT id, \n content, \n role, \n type,\n created_at AS createdAt, \n thread_id AS threadId\n FROM RankedMessages\n WHERE running_total <= $2\n ORDER BY created_at ASC", [threadId, this.MAX_CONTEXT_TOKENS]);
716
716
  case 10:
717
717
  _result = _context8.sent;
718
718
  console.log('Format', format);
719
719
  return _context8.abrupt("return", this.parseMessages(_result.rows));
720
720
  case 13:
721
721
  _context8.next = 15;
722
- return client.query("SELECT id, \n content, \n role, \n type,\n created_at AS createdAt, \n thread_id AS threadId\n FROM mastra_messages\n WHERE thread_id = $1\n AND type = 'text'\n " + (startDate ? "AND created_at >= '" + startDate.toISOString() + "'" : '') + "\n " + (endDate ? "AND created_at <= '" + endDate.toISOString() + "'" : '') + "\n ORDER BY created_at ASC", [threadId]);
722
+ return client.query("SELECT id, \n content, \n role, \n type,\n created_at AS createdAt, \n thread_id AS threadId\n FROM mastra_messages\n WHERE thread_id = $1\n " + (startDate ? "AND created_at >= '" + startDate.toISOString() + "'" : '') + "\n " + (endDate ? "AND created_at <= '" + endDate.toISOString() + "'" : '') + "\n ORDER BY created_at ASC", [threadId]);
723
723
  case 15:
724
724
  result = _context8.sent;
725
725
  console.log('Format', format);
@@ -1261,19 +1261,17 @@ var UpstashKVMemory = /*#__PURE__*/function (_MastraMemory) {
1261
1261
  }();
1262
1262
  _proto.getContextWindow = /*#__PURE__*/function () {
1263
1263
  var _getContextWindow = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(_ref6) {
1264
- var threadId, startDate, endDate, _ref6$format, format, messagesKey, messages, filteredMessages, totalTokens, messagesWithinTokenLimit, _iterator, _step, _message$content$, message, content, tokens;
1264
+ var threadId, startDate, endDate, messagesKey, messages, filteredMessages, totalTokens, messagesWithinTokenLimit, _iterator, _step, _message$content$, message, content, tokens;
1265
1265
  return _regeneratorRuntime().wrap(function _callee8$(_context8) {
1266
1266
  while (1) switch (_context8.prev = _context8.next) {
1267
1267
  case 0:
1268
- threadId = _ref6.threadId, startDate = _ref6.startDate, endDate = _ref6.endDate, _ref6$format = _ref6.format, format = _ref6$format === void 0 ? 'raw' : _ref6$format;
1268
+ threadId = _ref6.threadId, startDate = _ref6.startDate, endDate = _ref6.endDate;
1269
1269
  messagesKey = this.getMessagesKey(threadId);
1270
1270
  _context8.next = 4;
1271
1271
  return this.kv.lrange(messagesKey, 0, -1);
1272
1272
  case 4:
1273
1273
  messages = _context8.sent;
1274
- filteredMessages = messages.filter(function (msg) {
1275
- return msg.type === 'text';
1276
- });
1274
+ filteredMessages = messages;
1277
1275
  if (startDate) {
1278
1276
  filteredMessages = filteredMessages.filter(function (msg) {
1279
1277
  return new Date(msg.createdAt) >= startDate;
@@ -1285,7 +1283,7 @@ var UpstashKVMemory = /*#__PURE__*/function (_MastraMemory) {
1285
1283
  });
1286
1284
  }
1287
1285
  if (!this.MAX_CONTEXT_TOKENS) {
1288
- _context8.next = 24;
1286
+ _context8.next = 23;
1289
1287
  break;
1290
1288
  }
1291
1289
  totalTokens = 0;
@@ -1314,12 +1312,10 @@ var UpstashKVMemory = /*#__PURE__*/function (_MastraMemory) {
1314
1312
  _context8.next = 12;
1315
1313
  break;
1316
1314
  case 22:
1317
- console.log('Format:', format);
1318
- // Return messages in chronological order
1319
1315
  return _context8.abrupt("return", this.parseMessages(messagesWithinTokenLimit));
1320
- case 24:
1316
+ case 23:
1321
1317
  return _context8.abrupt("return", this.parseMessages(filteredMessages));
1322
- case 25:
1318
+ case 24:
1323
1319
  case "end":
1324
1320
  return _context8.stop();
1325
1321
  }