@mastra/memory 0.0.2-alpha.3 → 0.0.2-alpha.30
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 +210 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/kv/upstash.d.ts +5 -4
- package/dist/kv/upstash.d.ts.map +1 -0
- package/dist/memory.cjs.development.js +47 -65
- package/dist/memory.cjs.development.js.map +1 -1
- package/dist/memory.cjs.production.min.js +1 -1
- package/dist/memory.cjs.production.min.js.map +1 -1
- package/dist/memory.esm.js +47 -65
- package/dist/memory.esm.js.map +1 -1
- package/dist/postgres/index.d.ts +5 -4
- package/dist/postgres/index.d.ts.map +1 -0
- package/package.json +2 -3
- package/src/kv/upstash.ts +15 -5
- package/src/postgres/index.ts +7 -22
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,215 @@
|
|
|
1
1
|
# @mastra/memory
|
|
2
2
|
|
|
3
|
+
## 0.0.2-alpha.30
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [401a4d9]
|
|
8
|
+
- @mastra/core@0.1.27-alpha.50
|
|
9
|
+
|
|
10
|
+
## 0.0.2-alpha.29
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies [79acad0]
|
|
15
|
+
- Updated dependencies [f5dfa20]
|
|
16
|
+
- @mastra/core@0.1.27-alpha.49
|
|
17
|
+
|
|
18
|
+
## 0.0.2-alpha.28
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- Updated dependencies [b726bf5]
|
|
23
|
+
- @mastra/core@0.1.27-alpha.48
|
|
24
|
+
|
|
25
|
+
## 0.0.2-alpha.27
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- Updated dependencies [f6ba259]
|
|
30
|
+
- @mastra/core@0.1.27-alpha.47
|
|
31
|
+
|
|
32
|
+
## 0.0.2-alpha.26
|
|
33
|
+
|
|
34
|
+
### Patch Changes
|
|
35
|
+
|
|
36
|
+
- 8ae2bbc: Dane publishing
|
|
37
|
+
- 0bd142c: Fixes learned from docs
|
|
38
|
+
- ee4de15: Dane fixes
|
|
39
|
+
- Updated dependencies [8ae2bbc]
|
|
40
|
+
- Updated dependencies [0bd142c]
|
|
41
|
+
- Updated dependencies [ee4de15]
|
|
42
|
+
- @mastra/core@0.1.27-alpha.46
|
|
43
|
+
|
|
44
|
+
## 0.0.2-alpha.25
|
|
45
|
+
|
|
46
|
+
### Patch Changes
|
|
47
|
+
|
|
48
|
+
- 3220d26: Fix lastStep error in agent stream
|
|
49
|
+
|
|
50
|
+
## 0.0.2-alpha.24
|
|
51
|
+
|
|
52
|
+
### Patch Changes
|
|
53
|
+
|
|
54
|
+
- 002d6d8: add memory to playground agent
|
|
55
|
+
- Updated dependencies [e608d8c]
|
|
56
|
+
- Updated dependencies [002d6d8]
|
|
57
|
+
- @mastra/core@0.1.27-alpha.45
|
|
58
|
+
|
|
59
|
+
## 0.0.2-alpha.23
|
|
60
|
+
|
|
61
|
+
### Patch Changes
|
|
62
|
+
|
|
63
|
+
- Updated dependencies [2fa7f53]
|
|
64
|
+
- @mastra/core@0.1.27-alpha.44
|
|
65
|
+
|
|
66
|
+
## 0.0.2-alpha.22
|
|
67
|
+
|
|
68
|
+
### Patch Changes
|
|
69
|
+
|
|
70
|
+
- Updated dependencies [2e099d2]
|
|
71
|
+
- Updated dependencies [d6d8159]
|
|
72
|
+
- @mastra/core@0.1.27-alpha.43
|
|
73
|
+
|
|
74
|
+
## 0.0.2-alpha.21
|
|
75
|
+
|
|
76
|
+
### Patch Changes
|
|
77
|
+
|
|
78
|
+
- Updated dependencies [4a54c82]
|
|
79
|
+
- @mastra/core@0.1.27-alpha.42
|
|
80
|
+
|
|
81
|
+
## 0.0.2-alpha.20
|
|
82
|
+
|
|
83
|
+
### Patch Changes
|
|
84
|
+
|
|
85
|
+
- Updated dependencies [5cdfb88]
|
|
86
|
+
- @mastra/core@0.1.27-alpha.41
|
|
87
|
+
|
|
88
|
+
## 0.0.2-alpha.19
|
|
89
|
+
|
|
90
|
+
### Patch Changes
|
|
91
|
+
|
|
92
|
+
- Updated dependencies [9029796]
|
|
93
|
+
- @mastra/core@0.1.27-alpha.40
|
|
94
|
+
|
|
95
|
+
## 0.0.2-alpha.18
|
|
96
|
+
|
|
97
|
+
### Patch Changes
|
|
98
|
+
|
|
99
|
+
- Updated dependencies [2b01511]
|
|
100
|
+
- @mastra/core@0.1.27-alpha.39
|
|
101
|
+
|
|
102
|
+
## 0.0.2-alpha.17
|
|
103
|
+
|
|
104
|
+
### Patch Changes
|
|
105
|
+
|
|
106
|
+
- Updated dependencies [f031a1f]
|
|
107
|
+
- @mastra/core@0.1.27-alpha.38
|
|
108
|
+
|
|
109
|
+
## 0.0.2-alpha.16
|
|
110
|
+
|
|
111
|
+
### Patch Changes
|
|
112
|
+
|
|
113
|
+
- b5393f1: New example: Dane and many fixes to make it work
|
|
114
|
+
- Updated dependencies [c872875]
|
|
115
|
+
- Updated dependencies [f6da688]
|
|
116
|
+
- Updated dependencies [b5393f1]
|
|
117
|
+
- @mastra/core@0.1.27-alpha.37
|
|
118
|
+
|
|
119
|
+
## 0.0.2-alpha.15
|
|
120
|
+
|
|
121
|
+
### Patch Changes
|
|
122
|
+
|
|
123
|
+
- b898fad: Fix get context window in memory
|
|
124
|
+
- Updated dependencies [f537e33]
|
|
125
|
+
- Updated dependencies [bc40916]
|
|
126
|
+
- Updated dependencies [f7d1131]
|
|
127
|
+
- Updated dependencies [75bf3f0]
|
|
128
|
+
- Updated dependencies [3c4488b]
|
|
129
|
+
- Updated dependencies [d38f7a6]
|
|
130
|
+
- @mastra/core@0.1.27-alpha.36
|
|
131
|
+
|
|
132
|
+
## 0.0.2-alpha.14
|
|
133
|
+
|
|
134
|
+
### Patch Changes
|
|
135
|
+
|
|
136
|
+
- 033eda6: More fixes for refactor
|
|
137
|
+
- Updated dependencies [033eda6]
|
|
138
|
+
- @mastra/core@0.1.27-alpha.35
|
|
139
|
+
|
|
140
|
+
## 0.0.2-alpha.13
|
|
141
|
+
|
|
142
|
+
### Patch Changes
|
|
143
|
+
|
|
144
|
+
- 837a288: MAJOR Revamp of tools, workflows, syncs.
|
|
145
|
+
- Updated dependencies [837a288]
|
|
146
|
+
- Updated dependencies [5811de6]
|
|
147
|
+
- @mastra/core@0.1.27-alpha.34
|
|
148
|
+
|
|
149
|
+
## 0.0.2-alpha.12
|
|
150
|
+
|
|
151
|
+
### Patch Changes
|
|
152
|
+
|
|
153
|
+
- Updated dependencies [e1dd94a]
|
|
154
|
+
- @mastra/core@0.1.27-alpha.33
|
|
155
|
+
|
|
156
|
+
## 0.0.2-alpha.11
|
|
157
|
+
|
|
158
|
+
### Patch Changes
|
|
159
|
+
|
|
160
|
+
- Updated dependencies [2712098]
|
|
161
|
+
- @mastra/core@0.1.27-alpha.32
|
|
162
|
+
|
|
163
|
+
## 0.0.2-alpha.10
|
|
164
|
+
|
|
165
|
+
### Patch Changes
|
|
166
|
+
|
|
167
|
+
- Updated dependencies [c2dd6b5]
|
|
168
|
+
- @mastra/core@0.1.27-alpha.31
|
|
169
|
+
|
|
170
|
+
## 0.0.2-alpha.9
|
|
171
|
+
|
|
172
|
+
### Patch Changes
|
|
173
|
+
|
|
174
|
+
- Updated dependencies [963c15a]
|
|
175
|
+
- @mastra/core@0.1.27-alpha.30
|
|
176
|
+
|
|
177
|
+
## 0.0.2-alpha.8
|
|
178
|
+
|
|
179
|
+
### Patch Changes
|
|
180
|
+
|
|
181
|
+
- Updated dependencies [7d87a15]
|
|
182
|
+
- @mastra/core@0.1.27-alpha.29
|
|
183
|
+
|
|
184
|
+
## 0.0.2-alpha.7
|
|
185
|
+
|
|
186
|
+
### Patch Changes
|
|
187
|
+
|
|
188
|
+
- Updated dependencies [1ebd071]
|
|
189
|
+
- @mastra/core@0.1.27-alpha.28
|
|
190
|
+
|
|
191
|
+
## 0.0.2-alpha.6
|
|
192
|
+
|
|
193
|
+
### Patch Changes
|
|
194
|
+
|
|
195
|
+
- Updated dependencies [cd02c56]
|
|
196
|
+
- @mastra/core@0.1.27-alpha.27
|
|
197
|
+
|
|
198
|
+
## 0.0.2-alpha.5
|
|
199
|
+
|
|
200
|
+
### Patch Changes
|
|
201
|
+
|
|
202
|
+
- Updated dependencies [d5e12de]
|
|
203
|
+
- @mastra/core@0.1.27-alpha.26
|
|
204
|
+
|
|
205
|
+
## 0.0.2-alpha.4
|
|
206
|
+
|
|
207
|
+
### Patch Changes
|
|
208
|
+
|
|
209
|
+
- 01502b0: fix thread title containing unnecessary text and removed unnecessary logs in memory
|
|
210
|
+
- Updated dependencies [01502b0]
|
|
211
|
+
- @mastra/core@0.1.27-alpha.25
|
|
212
|
+
|
|
3
213
|
## 0.0.2-alpha.3
|
|
4
214
|
|
|
5
215
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -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"}
|
package/dist/kv/upstash.d.ts
CHANGED
|
@@ -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
|
|
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:
|
|
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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"}
|
|
@@ -635,68 +635,57 @@ var PgMemory = /*#__PURE__*/function (_MastraMemory) {
|
|
|
635
635
|
threadId: threadId,
|
|
636
636
|
toolName: toolName
|
|
637
637
|
})).digest('hex');
|
|
638
|
-
|
|
639
|
-
_context7.next = 12;
|
|
638
|
+
_context7.next = 11;
|
|
640
639
|
return client.query("SELECT tool_call_ids, \n tool_call_args,\n created_at\n FROM mastra_messages\n WHERE tool_call_args::jsonb @> $1\n AND tool_call_args_expire_at > $2\n ORDER BY created_at ASC\n LIMIT 1", [JSON.stringify([hashedToolArgs]), new Date().toISOString()]);
|
|
641
|
-
case
|
|
640
|
+
case 11:
|
|
642
641
|
toolArgsResult = _context7.sent;
|
|
643
642
|
if (!(toolArgsResult.rows.length > 0)) {
|
|
644
|
-
_context7.next =
|
|
643
|
+
_context7.next = 28;
|
|
645
644
|
break;
|
|
646
645
|
}
|
|
647
|
-
console.log('toolArgsResult====', JSON.stringify(toolArgsResult.rows[0], null, 2));
|
|
648
646
|
toolCallArgs = JSON.parse((_toolArgsResult$rows$ = toolArgsResult.rows[0]) == null ? void 0 : _toolArgsResult$rows$.tool_call_args);
|
|
649
647
|
toolCallIds = JSON.parse((_toolArgsResult$rows$2 = toolArgsResult.rows[0]) == null ? void 0 : _toolArgsResult$rows$2.tool_call_ids);
|
|
650
648
|
createdAt = (_toolArgsResult$rows$3 = toolArgsResult.rows[0]) == null ? void 0 : _toolArgsResult$rows$3.created_at;
|
|
651
|
-
console.log('toolCallArgs====', JSON.stringify(toolCallArgs, null, 2));
|
|
652
|
-
console.log('toolCallIds====', JSON.stringify(toolCallIds, null, 2));
|
|
653
|
-
console.log('createdAt====', createdAt);
|
|
654
649
|
toolCallArgsIndex = toolCallArgs.findIndex(function (arg) {
|
|
655
650
|
return arg === hashedToolArgs;
|
|
656
651
|
});
|
|
657
652
|
correspondingToolCallId = toolCallIds[toolCallArgsIndex];
|
|
658
|
-
|
|
659
|
-
correspondingToolCallId: correspondingToolCallId,
|
|
660
|
-
toolCallArgsIndex: toolCallArgsIndex
|
|
661
|
-
});
|
|
662
|
-
_context7.next = 26;
|
|
653
|
+
_context7.next = 20;
|
|
663
654
|
return client.query("SELECT content \n FROM mastra_messages \n WHERE thread_id = $1\n AND tool_call_ids ILIKE $2\n AND type = 'tool-result'\n AND created_at = $3\n LIMIT 1", [threadId, "%" + correspondingToolCallId + "%", new Date(createdAt).toISOString()]);
|
|
664
|
-
case
|
|
655
|
+
case 20:
|
|
665
656
|
toolResult = _context7.sent;
|
|
666
|
-
console.log('called toolResult');
|
|
667
657
|
if (!(toolResult.rows.length === 0)) {
|
|
668
|
-
_context7.next =
|
|
658
|
+
_context7.next = 24;
|
|
669
659
|
break;
|
|
670
660
|
}
|
|
671
661
|
console.log('no tool result found');
|
|
672
662
|
return _context7.abrupt("return", null);
|
|
673
|
-
case
|
|
663
|
+
case 24:
|
|
674
664
|
toolResultContent = JSON.parse((_toolResult$rows$ = toolResult.rows[0]) == null ? void 0 : _toolResult$rows$.content);
|
|
675
665
|
requiredToolResult = toolResultContent.find(function (part) {
|
|
676
666
|
return part.toolCallId === correspondingToolCallId;
|
|
677
667
|
});
|
|
678
|
-
console.log('requiredToolResult====', JSON.stringify(requiredToolResult, null, 2));
|
|
679
668
|
if (!requiredToolResult) {
|
|
680
|
-
_context7.next =
|
|
669
|
+
_context7.next = 28;
|
|
681
670
|
break;
|
|
682
671
|
}
|
|
683
672
|
return _context7.abrupt("return", requiredToolResult.result);
|
|
684
|
-
case
|
|
673
|
+
case 28:
|
|
685
674
|
return _context7.abrupt("return", null);
|
|
686
|
-
case
|
|
687
|
-
_context7.prev =
|
|
675
|
+
case 31:
|
|
676
|
+
_context7.prev = 31;
|
|
688
677
|
_context7.t0 = _context7["catch"](7);
|
|
689
678
|
console.log('error getting cached tool result====', _context7.t0);
|
|
690
679
|
return _context7.abrupt("return", null);
|
|
691
|
-
case
|
|
692
|
-
_context7.prev =
|
|
680
|
+
case 35:
|
|
681
|
+
_context7.prev = 35;
|
|
693
682
|
client.release();
|
|
694
|
-
return _context7.finish(
|
|
695
|
-
case
|
|
683
|
+
return _context7.finish(35);
|
|
684
|
+
case 38:
|
|
696
685
|
case "end":
|
|
697
686
|
return _context7.stop();
|
|
698
687
|
}
|
|
699
|
-
}, _callee7, this, [[7,
|
|
688
|
+
}, _callee7, this, [[7, 31, 35, 38]]);
|
|
700
689
|
}));
|
|
701
690
|
function getToolResult(_x9) {
|
|
702
691
|
return _getToolResult.apply(this, arguments);
|
|
@@ -723,14 +712,14 @@ var PgMemory = /*#__PURE__*/function (_MastraMemory) {
|
|
|
723
712
|
break;
|
|
724
713
|
}
|
|
725
714
|
_context8.next = 10;
|
|
726
|
-
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
|
|
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]);
|
|
727
716
|
case 10:
|
|
728
717
|
_result = _context8.sent;
|
|
729
718
|
console.log('Format', format);
|
|
730
719
|
return _context8.abrupt("return", this.parseMessages(_result.rows));
|
|
731
720
|
case 13:
|
|
732
721
|
_context8.next = 15;
|
|
733
|
-
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
|
|
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]);
|
|
734
723
|
case 15:
|
|
735
724
|
result = _context8.sent;
|
|
736
725
|
console.log('Format', format);
|
|
@@ -826,7 +815,6 @@ var PgMemory = /*#__PURE__*/function (_MastraMemory) {
|
|
|
826
815
|
while (1) switch (_context10.prev = _context10.next) {
|
|
827
816
|
case 0:
|
|
828
817
|
message = _step.value;
|
|
829
|
-
console.log('saving message====', JSON.stringify(message, null, 2));
|
|
830
818
|
id = message.id, content = message.content, role = message.role, createdAt = message.createdAt, threadId = message.threadId, toolCallIds = message.toolCallIds, toolCallArgs = message.toolCallArgs, type = message.type, toolNames = message.toolNames;
|
|
831
819
|
tokens = null;
|
|
832
820
|
if (type === 'text') {
|
|
@@ -843,39 +831,38 @@ var PgMemory = /*#__PURE__*/function (_MastraMemory) {
|
|
|
843
831
|
}) : null;
|
|
844
832
|
validArgExists = false;
|
|
845
833
|
if (!(hashedToolCallArgs != null && hashedToolCallArgs.length)) {
|
|
846
|
-
_context10.next =
|
|
834
|
+
_context10.next = 19;
|
|
847
835
|
break;
|
|
848
836
|
}
|
|
849
837
|
// Check all args sequentially
|
|
850
838
|
validArgExists = true; // Start true and set to false if any check fails
|
|
851
839
|
i = 0;
|
|
852
|
-
case
|
|
840
|
+
case 9:
|
|
853
841
|
if (!(i < hashedToolCallArgs.length)) {
|
|
854
|
-
_context10.next =
|
|
842
|
+
_context10.next = 19;
|
|
855
843
|
break;
|
|
856
844
|
}
|
|
857
|
-
_context10.next =
|
|
845
|
+
_context10.next = 12;
|
|
858
846
|
return _this2.validateToolCallArgs({
|
|
859
847
|
hashedArgs: hashedToolCallArgs[i]
|
|
860
848
|
});
|
|
861
|
-
case
|
|
849
|
+
case 12:
|
|
862
850
|
isValid = _context10.sent;
|
|
863
851
|
if (isValid) {
|
|
864
|
-
_context10.next =
|
|
852
|
+
_context10.next = 16;
|
|
865
853
|
break;
|
|
866
854
|
}
|
|
867
855
|
validArgExists = false;
|
|
868
|
-
return _context10.abrupt("break",
|
|
869
|
-
case
|
|
856
|
+
return _context10.abrupt("break", 19);
|
|
857
|
+
case 16:
|
|
870
858
|
i++;
|
|
871
|
-
_context10.next =
|
|
859
|
+
_context10.next = 9;
|
|
872
860
|
break;
|
|
873
|
-
case
|
|
861
|
+
case 19:
|
|
874
862
|
toolCallArgsExpireAt = !toolCallArgs ? null : validArgExists ? createdAt : new Date(createdAt.getTime() + 5 * 60 * 1000); // 5 minutes
|
|
875
|
-
|
|
876
|
-
_context10.next = 24;
|
|
863
|
+
_context10.next = 22;
|
|
877
864
|
return client.query("\n INSERT INTO mastra_messages (id, content, role, created_at, thread_id, tool_call_ids, tool_call_args, type, tokens, tool_call_args_expire_at)\n VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)\n ", [id, JSON.stringify(content), role, createdAt.toISOString(), threadId, JSON.stringify(toolCallIds), JSON.stringify(hashedToolCallArgs), type, tokens, toolCallArgsExpireAt == null ? void 0 : toolCallArgsExpireAt.toISOString()]);
|
|
878
|
-
case
|
|
865
|
+
case 22:
|
|
879
866
|
case "end":
|
|
880
867
|
return _context10.stop();
|
|
881
868
|
}
|
|
@@ -892,27 +879,26 @@ var PgMemory = /*#__PURE__*/function (_MastraMemory) {
|
|
|
892
879
|
_context11.next = 11;
|
|
893
880
|
break;
|
|
894
881
|
case 15:
|
|
895
|
-
|
|
896
|
-
_context11.next = 18;
|
|
882
|
+
_context11.next = 17;
|
|
897
883
|
return client.query('COMMIT');
|
|
898
|
-
case
|
|
884
|
+
case 17:
|
|
899
885
|
return _context11.abrupt("return", messages);
|
|
900
|
-
case
|
|
901
|
-
_context11.prev =
|
|
886
|
+
case 20:
|
|
887
|
+
_context11.prev = 20;
|
|
902
888
|
_context11.t1 = _context11["catch"](6);
|
|
903
|
-
_context11.next =
|
|
889
|
+
_context11.next = 24;
|
|
904
890
|
return client.query('ROLLBACK');
|
|
905
|
-
case
|
|
891
|
+
case 24:
|
|
906
892
|
throw _context11.t1;
|
|
907
|
-
case
|
|
908
|
-
_context11.prev =
|
|
893
|
+
case 25:
|
|
894
|
+
_context11.prev = 25;
|
|
909
895
|
client.release();
|
|
910
|
-
return _context11.finish(
|
|
911
|
-
case
|
|
896
|
+
return _context11.finish(25);
|
|
897
|
+
case 28:
|
|
912
898
|
case "end":
|
|
913
899
|
return _context11.stop();
|
|
914
900
|
}
|
|
915
|
-
}, _callee10, this, [[6,
|
|
901
|
+
}, _callee10, this, [[6, 20, 25, 28]]);
|
|
916
902
|
}));
|
|
917
903
|
function saveMessages(_x12) {
|
|
918
904
|
return _saveMessages.apply(this, arguments);
|
|
@@ -1275,19 +1261,17 @@ var UpstashKVMemory = /*#__PURE__*/function (_MastraMemory) {
|
|
|
1275
1261
|
}();
|
|
1276
1262
|
_proto.getContextWindow = /*#__PURE__*/function () {
|
|
1277
1263
|
var _getContextWindow = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(_ref6) {
|
|
1278
|
-
var threadId, startDate, endDate,
|
|
1264
|
+
var threadId, startDate, endDate, messagesKey, messages, filteredMessages, totalTokens, messagesWithinTokenLimit, _iterator, _step, _message$content$, message, content, tokens;
|
|
1279
1265
|
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
1280
1266
|
while (1) switch (_context8.prev = _context8.next) {
|
|
1281
1267
|
case 0:
|
|
1282
|
-
threadId = _ref6.threadId, startDate = _ref6.startDate, endDate = _ref6.endDate
|
|
1268
|
+
threadId = _ref6.threadId, startDate = _ref6.startDate, endDate = _ref6.endDate;
|
|
1283
1269
|
messagesKey = this.getMessagesKey(threadId);
|
|
1284
1270
|
_context8.next = 4;
|
|
1285
1271
|
return this.kv.lrange(messagesKey, 0, -1);
|
|
1286
1272
|
case 4:
|
|
1287
1273
|
messages = _context8.sent;
|
|
1288
|
-
filteredMessages = messages
|
|
1289
|
-
return msg.type === 'text';
|
|
1290
|
-
});
|
|
1274
|
+
filteredMessages = messages;
|
|
1291
1275
|
if (startDate) {
|
|
1292
1276
|
filteredMessages = filteredMessages.filter(function (msg) {
|
|
1293
1277
|
return new Date(msg.createdAt) >= startDate;
|
|
@@ -1299,7 +1283,7 @@ var UpstashKVMemory = /*#__PURE__*/function (_MastraMemory) {
|
|
|
1299
1283
|
});
|
|
1300
1284
|
}
|
|
1301
1285
|
if (!this.MAX_CONTEXT_TOKENS) {
|
|
1302
|
-
_context8.next =
|
|
1286
|
+
_context8.next = 23;
|
|
1303
1287
|
break;
|
|
1304
1288
|
}
|
|
1305
1289
|
totalTokens = 0;
|
|
@@ -1328,12 +1312,10 @@ var UpstashKVMemory = /*#__PURE__*/function (_MastraMemory) {
|
|
|
1328
1312
|
_context8.next = 12;
|
|
1329
1313
|
break;
|
|
1330
1314
|
case 22:
|
|
1331
|
-
console.log('Format:', format);
|
|
1332
|
-
// Return messages in chronological order
|
|
1333
1315
|
return _context8.abrupt("return", this.parseMessages(messagesWithinTokenLimit));
|
|
1334
|
-
case
|
|
1316
|
+
case 23:
|
|
1335
1317
|
return _context8.abrupt("return", this.parseMessages(filteredMessages));
|
|
1336
|
-
case
|
|
1318
|
+
case 24:
|
|
1337
1319
|
case "end":
|
|
1338
1320
|
return _context8.stop();
|
|
1339
1321
|
}
|