@mastra/longmemeval 0.1.36 → 1.0.0-beta.0
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 +92 -56
- package/package.json +6 -6
- package/scripts/generate-wm-templates.ts +2 -1
- package/src/commands/__tests__/run.test.ts +0 -3
- package/src/commands/prepare.ts +2 -1
- package/src/commands/run.ts +4 -2
- package/src/storage/__tests__/benchmark-store.test.ts +18 -28
- package/src/storage/benchmark-store.ts +100 -154
package/CHANGELOG.md
CHANGED
|
@@ -1,94 +1,130 @@
|
|
|
1
1
|
# @mastra/longmemeval
|
|
2
2
|
|
|
3
|
-
## 0.
|
|
3
|
+
## 1.0.0-beta.0
|
|
4
4
|
|
|
5
|
-
###
|
|
5
|
+
### Major Changes
|
|
6
6
|
|
|
7
|
-
-
|
|
7
|
+
- **BREAKING:** Remove `getMessagesPaginated()` and add `perPage: false` support ([#9670](https://github.com/mastra-ai/mastra/pull/9670))
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
- @mastra/memory@0.15.11
|
|
11
|
-
- @mastra/libsql@0.16.2
|
|
12
|
-
- @mastra/rag@1.3.4
|
|
13
|
-
- @mastra/core@0.24.0
|
|
14
|
-
- @mastra/fastembed@0.10.7
|
|
9
|
+
Removes deprecated `getMessagesPaginated()` method. The `listMessages()` API and score handlers now support `perPage: false` to fetch all records without pagination limits.
|
|
15
10
|
|
|
16
|
-
|
|
11
|
+
**Storage changes:**
|
|
12
|
+
- `StoragePagination.perPage` type changed from `number` to `number | false`
|
|
13
|
+
- All storage implementations support `perPage: false`:
|
|
14
|
+
- Memory: `listMessages()`
|
|
15
|
+
- Scores: `listScoresBySpan()`, `listScoresByRunId()`, `listScoresByExecutionId()`
|
|
16
|
+
- HTTP query parser accepts `"false"` string (e.g., `?perPage=false`)
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
**Memory changes:**
|
|
19
|
+
- `memory.query()` parameter type changed from `StorageGetMessagesArg` to `StorageListMessagesInput`
|
|
20
|
+
- Uses flat parameters (`page`, `perPage`, `include`, `filter`, `vectorSearchString`) instead of `selectBy` object
|
|
19
21
|
|
|
20
|
-
|
|
22
|
+
**Stricter validation:**
|
|
23
|
+
- `listMessages()` requires non-empty, non-whitespace `threadId` (throws error instead of returning empty results)
|
|
21
24
|
|
|
22
|
-
|
|
23
|
-
- @mastra/memory@0.15.11-alpha.0
|
|
24
|
-
- @mastra/libsql@0.16.2-alpha.0
|
|
25
|
-
- @mastra/rag@1.3.4-alpha.0
|
|
26
|
-
- @mastra/core@0.24.0-alpha.0
|
|
27
|
-
- @mastra/fastembed@0.10.7-alpha.0
|
|
25
|
+
**Migration:**
|
|
28
26
|
|
|
29
|
-
|
|
27
|
+
```typescript
|
|
28
|
+
// Storage/Memory: Replace getMessagesPaginated with listMessages
|
|
29
|
+
- storage.getMessagesPaginated({ threadId, selectBy: { pagination: { page: 0, perPage: 20 } } })
|
|
30
|
+
+ storage.listMessages({ threadId, page: 0, perPage: 20 })
|
|
31
|
+
+ storage.listMessages({ threadId, page: 0, perPage: false }) // Fetch all
|
|
30
32
|
|
|
31
|
-
|
|
33
|
+
// Memory: Replace selectBy with flat parameters
|
|
34
|
+
- memory.query({ threadId, selectBy: { last: 20, include: [...] } })
|
|
35
|
+
+ memory.query({ threadId, perPage: 20, include: [...] })
|
|
32
36
|
|
|
33
|
-
|
|
34
|
-
-
|
|
37
|
+
// Client SDK
|
|
38
|
+
- thread.getMessagesPaginated({ selectBy: { pagination: { page: 0 } } })
|
|
39
|
+
+ thread.listMessages({ page: 0, perPage: 20 })
|
|
40
|
+
```
|
|
35
41
|
|
|
36
|
-
|
|
42
|
+
- # Major Changes ([#9695](https://github.com/mastra-ai/mastra/pull/9695))
|
|
37
43
|
|
|
38
|
-
|
|
44
|
+
## Storage Layer
|
|
39
45
|
|
|
40
|
-
|
|
41
|
-
- @mastra/core@0.23.3-alpha.0
|
|
46
|
+
### BREAKING: Removed `storage.getMessages()`
|
|
42
47
|
|
|
43
|
-
|
|
48
|
+
The `getMessages()` method has been removed from all storage implementations. Use `listMessages()` instead, which provides pagination support.
|
|
44
49
|
|
|
45
|
-
|
|
50
|
+
**Migration:**
|
|
46
51
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
-
|
|
52
|
+
```typescript
|
|
53
|
+
// Before
|
|
54
|
+
const messages = await storage.getMessages({ threadId: 'thread-1' });
|
|
50
55
|
|
|
51
|
-
|
|
56
|
+
// After
|
|
57
|
+
const result = await storage.listMessages({
|
|
58
|
+
threadId: 'thread-1',
|
|
59
|
+
page: 0,
|
|
60
|
+
perPage: 50,
|
|
61
|
+
});
|
|
62
|
+
const messages = result.messages; // Access messages array
|
|
63
|
+
console.log(result.total); // Total count
|
|
64
|
+
console.log(result.hasMore); // Whether more pages exist
|
|
65
|
+
```
|
|
52
66
|
|
|
53
|
-
###
|
|
67
|
+
### Message ordering default
|
|
54
68
|
|
|
55
|
-
|
|
56
|
-
- @mastra/core@0.23.2-alpha.1
|
|
69
|
+
`listMessages()` defaults to ASC (oldest first) ordering by `createdAt`, matching the previous `getMessages()` behavior.
|
|
57
70
|
|
|
58
|
-
|
|
71
|
+
**To use DESC ordering (newest first):**
|
|
59
72
|
|
|
60
|
-
|
|
73
|
+
```typescript
|
|
74
|
+
const result = await storage.listMessages({
|
|
75
|
+
threadId: 'thread-1',
|
|
76
|
+
orderBy: { field: 'createdAt', direction: 'DESC' },
|
|
77
|
+
});
|
|
78
|
+
```
|
|
61
79
|
|
|
62
|
-
|
|
63
|
-
- @mastra/core@0.23.2-alpha.0
|
|
64
|
-
- @mastra/memory@0.15.10-alpha.0
|
|
80
|
+
## Client SDK
|
|
65
81
|
|
|
66
|
-
|
|
82
|
+
### BREAKING: Renamed `client.getThreadMessages()` → `client.listThreadMessages()`
|
|
67
83
|
|
|
68
|
-
|
|
84
|
+
**Migration:**
|
|
69
85
|
|
|
70
|
-
|
|
86
|
+
```typescript
|
|
87
|
+
// Before
|
|
88
|
+
const response = await client.getThreadMessages(threadId, { agentId });
|
|
71
89
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
- @mastra/libsql@0.16.1
|
|
76
|
-
- @mastra/rag@1.3.3
|
|
77
|
-
- @mastra/core@0.23.1
|
|
90
|
+
// After
|
|
91
|
+
const response = await client.listThreadMessages(threadId, { agentId });
|
|
92
|
+
```
|
|
78
93
|
|
|
79
|
-
|
|
94
|
+
The response format remains the same.
|
|
80
95
|
|
|
81
|
-
|
|
96
|
+
## Type Changes
|
|
97
|
+
|
|
98
|
+
### BREAKING: Removed `StorageGetMessagesArg` type
|
|
99
|
+
|
|
100
|
+
Use `StorageListMessagesInput` instead:
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
// Before
|
|
104
|
+
import type { StorageGetMessagesArg } from '@mastra/core';
|
|
105
|
+
|
|
106
|
+
// After
|
|
107
|
+
import type { StorageListMessagesInput } from '@mastra/core';
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
- Bump minimum required Node.js version to 22.13.0 ([#9706](https://github.com/mastra-ai/mastra/pull/9706))
|
|
111
|
+
|
|
112
|
+
- Remove `getThreadsByResourceId` and `getThreadsByResourceIdPaginated` methods from storage interfaces in favor of `listThreadsByResourceId`. The new method uses `offset`/`limit` pagination and a nested `orderBy` object structure (`{ field, direction }`). ([#9536](https://github.com/mastra-ai/mastra/pull/9536))
|
|
113
|
+
|
|
114
|
+
- Removed old tracing code based on OpenTelemetry ([#9237](https://github.com/mastra-ai/mastra/pull/9237))
|
|
82
115
|
|
|
83
|
-
-
|
|
84
|
-
- @mastra/core@0.23.0
|
|
116
|
+
- Mark as stable ([`83d5942`](https://github.com/mastra-ai/mastra/commit/83d5942669ce7bba4a6ca4fd4da697a10eb5ebdc))
|
|
85
117
|
|
|
86
|
-
|
|
118
|
+
- Remove legacy evals from Mastra ([#9491](https://github.com/mastra-ai/mastra/pull/9491))
|
|
87
119
|
|
|
88
120
|
### Patch Changes
|
|
89
121
|
|
|
90
|
-
- Updated dependencies [[`f743dbb`](https://github.com/mastra-ai/mastra/commit/f743dbb8b40d1627b5c10c0e6fc154f4ebb6e394), [`5df9cce`](https://github.com/mastra-ai/mastra/commit/5df9cce1a753438413f64c11eeef8f845745c2a8), [`
|
|
91
|
-
- @mastra/core@0.
|
|
122
|
+
- Updated dependencies [[`39c9743`](https://github.com/mastra-ai/mastra/commit/39c97432d084294f8ba85fbf3ef28098ff21459e), [`f743dbb`](https://github.com/mastra-ai/mastra/commit/f743dbb8b40d1627b5c10c0e6fc154f4ebb6e394), [`fec5129`](https://github.com/mastra-ai/mastra/commit/fec5129de7fc64423ea03661a56cef31dc747a0d), [`0491e7c`](https://github.com/mastra-ai/mastra/commit/0491e7c9b714cb0ba22187ee062147ec2dd7c712), [`f6f4903`](https://github.com/mastra-ai/mastra/commit/f6f4903397314f73362061dc5a3e8e7c61ea34aa), [`0e8ed46`](https://github.com/mastra-ai/mastra/commit/0e8ed467c54d6901a6a365f270ec15d6faadb36c), [`735d8c1`](https://github.com/mastra-ai/mastra/commit/735d8c1c0d19fbc09e6f8b66cf41bc7655993838), [`6c049d9`](https://github.com/mastra-ai/mastra/commit/6c049d94063fdcbd5b81c4912a2bf82a92c9cc0b), [`2f897df`](https://github.com/mastra-ai/mastra/commit/2f897df208508f46f51b7625e5dd20c37f93e0e3), [`f0f8f12`](https://github.com/mastra-ai/mastra/commit/f0f8f125c308f2d0fd36942ef652fd852df7522f), [`3443770`](https://github.com/mastra-ai/mastra/commit/3443770662df8eb24c9df3589b2792d78cfcb811), [`f0a07e0`](https://github.com/mastra-ai/mastra/commit/f0a07e0111b3307c5fabfa4094c5c2cfb734fbe6), [`aaa40e7`](https://github.com/mastra-ai/mastra/commit/aaa40e788628b319baa8e889407d11ad626547fa), [`1521d71`](https://github.com/mastra-ai/mastra/commit/1521d716e5daedc74690c983fbd961123c56756b), [`9e1911d`](https://github.com/mastra-ai/mastra/commit/9e1911db2b4db85e0e768c3f15e0d61e319869f6), [`ebac155`](https://github.com/mastra-ai/mastra/commit/ebac15564a590117db7078233f927a7e28a85106), [`dd1c38d`](https://github.com/mastra-ai/mastra/commit/dd1c38d1b75f1b695c27b40d8d9d6ed00d5e0f6f), [`5948e6a`](https://github.com/mastra-ai/mastra/commit/5948e6a5146c83666ba3f294b2be576c82a513fb), [`8940859`](https://github.com/mastra-ai/mastra/commit/89408593658199b4ad67f7b65e888f344e64a442), [`f0f8f12`](https://github.com/mastra-ai/mastra/commit/f0f8f125c308f2d0fd36942ef652fd852df7522f), [`e629310`](https://github.com/mastra-ai/mastra/commit/e629310f1a73fa236d49ec7a1d1cceb6229dc7cc), [`844ea5d`](https://github.com/mastra-ai/mastra/commit/844ea5dc0c248961e7bf73629ae7dcff503e853c), [`4c6b492`](https://github.com/mastra-ai/mastra/commit/4c6b492c4dd591c6a592520c1f6855d6e936d71f), [`dff01d8`](https://github.com/mastra-ai/mastra/commit/dff01d81ce1f4e4087cfac20fa868e6db138dd14), [`9d819d5`](https://github.com/mastra-ai/mastra/commit/9d819d54b61481639f4008e4694791bddf187edd), [`a51cc81`](https://github.com/mastra-ai/mastra/commit/a51cc813e98fe115ef59df7de394fdbb9ffa7f9c), [`71c8d6c`](https://github.com/mastra-ai/mastra/commit/71c8d6c161253207b2b9588bdadb7eed604f7253), [`6179a9b`](https://github.com/mastra-ai/mastra/commit/6179a9ba36ffac326de3cc3c43cdc8028d37c251), [`00f4921`](https://github.com/mastra-ai/mastra/commit/00f4921dd2c91a1e5446799599ef7116a8214a1a), [`ca8041c`](https://github.com/mastra-ai/mastra/commit/ca8041cce0379fda22ed293a565bcb5b6ddca68a), [`7051bf3`](https://github.com/mastra-ai/mastra/commit/7051bf38b3b122a069008f861f7bfc004a6d9f6e), [`a8f1494`](https://github.com/mastra-ai/mastra/commit/a8f1494f4bbdc2770bcf327d4c7d869e332183f1), [`b88dd9d`](https://github.com/mastra-ai/mastra/commit/b88dd9dfd04a5f1a35d54f48eda944eac29923c2), [`0793497`](https://github.com/mastra-ai/mastra/commit/079349753620c40246ffd673e3f9d7d9820beff3), [`0d7618b`](https://github.com/mastra-ai/mastra/commit/0d7618bc650bf2800934b243eca5648f4aeed9c2), [`5df9cce`](https://github.com/mastra-ai/mastra/commit/5df9cce1a753438413f64c11eeef8f845745c2a8), [`a854ede`](https://github.com/mastra-ai/mastra/commit/a854ede62bf5ac0945a624ac48913dd69c73aabf), [`c576fc0`](https://github.com/mastra-ai/mastra/commit/c576fc0b100b2085afded91a37c97a0ea0ec09c7), [`3defc80`](https://github.com/mastra-ai/mastra/commit/3defc80cf2b88a1b7fc1cc4ddcb91e982a614609), [`16153fe`](https://github.com/mastra-ai/mastra/commit/16153fe7eb13c99401f48e6ca32707c965ee28b9), [`9f4a683`](https://github.com/mastra-ai/mastra/commit/9f4a6833e88b52574665c028fd5508ad5c2f6004), [`bc94344`](https://github.com/mastra-ai/mastra/commit/bc943444a1342d8a662151b7bce1df7dae32f59c), [`57d157f`](https://github.com/mastra-ai/mastra/commit/57d157f0b163a95c3e6c9eae31bdb11d1bfc64f9), [`903f67d`](https://github.com/mastra-ai/mastra/commit/903f67d184504a273893818c02b961f5423a79ad), [`2a90c55`](https://github.com/mastra-ai/mastra/commit/2a90c55a86a9210697d5adaab5ee94584b079adc), [`4c6b492`](https://github.com/mastra-ai/mastra/commit/4c6b492c4dd591c6a592520c1f6855d6e936d71f), [`eb09742`](https://github.com/mastra-ai/mastra/commit/eb09742197f66c4c38154c3beec78313e69760b2), [`ebac155`](https://github.com/mastra-ai/mastra/commit/ebac15564a590117db7078233f927a7e28a85106), [`96d35f6`](https://github.com/mastra-ai/mastra/commit/96d35f61376bc2b1bf148648a2c1985bd51bef55), [`5cbe88a`](https://github.com/mastra-ai/mastra/commit/5cbe88aefbd9f933bca669fd371ea36bf939ac6d), [`a1bd7b8`](https://github.com/mastra-ai/mastra/commit/a1bd7b8571db16b94eb01588f451a74758c96d65), [`d78b38d`](https://github.com/mastra-ai/mastra/commit/d78b38d898fce285260d3bbb4befade54331617f), [`0633100`](https://github.com/mastra-ai/mastra/commit/0633100a911ad22f5256471bdf753da21c104742), [`c710c16`](https://github.com/mastra-ai/mastra/commit/c710c1652dccfdc4111c8412bca7a6bb1d48b441), [`354ad0b`](https://github.com/mastra-ai/mastra/commit/354ad0b7b1b8183ac567f236a884fc7ede6d7138), [`cfae733`](https://github.com/mastra-ai/mastra/commit/cfae73394f4920635e6c919c8e95ff9a0788e2e5), [`e3dfda7`](https://github.com/mastra-ai/mastra/commit/e3dfda7b11bf3b8c4bb55637028befb5f387fc74), [`844ea5d`](https://github.com/mastra-ai/mastra/commit/844ea5dc0c248961e7bf73629ae7dcff503e853c), [`398fde3`](https://github.com/mastra-ai/mastra/commit/398fde3f39e707cda79372cdae8f9870e3b57c8d), [`f0f8f12`](https://github.com/mastra-ai/mastra/commit/f0f8f125c308f2d0fd36942ef652fd852df7522f), [`0d7618b`](https://github.com/mastra-ai/mastra/commit/0d7618bc650bf2800934b243eca5648f4aeed9c2), [`7b763e5`](https://github.com/mastra-ai/mastra/commit/7b763e52fc3eaf699c2a99f2adf418dd46e4e9a5), [`d36cfbb`](https://github.com/mastra-ai/mastra/commit/d36cfbbb6565ba5f827883cc9bb648eb14befdc1), [`3697853`](https://github.com/mastra-ai/mastra/commit/3697853deeb72017d90e0f38a93c1e29221aeca0), [`b2e45ec`](https://github.com/mastra-ai/mastra/commit/b2e45eca727a8db01a81ba93f1a5219c7183c839), [`d6d49f7`](https://github.com/mastra-ai/mastra/commit/d6d49f7b8714fa19a52ff9c7cf7fb7e73751901e), [`a534e95`](https://github.com/mastra-ai/mastra/commit/a534e9591f83b3cc1ebff99c67edf4cda7bf81d3), [`9d0e7fe`](https://github.com/mastra-ai/mastra/commit/9d0e7feca8ed98de959f53476ee1456073673348), [`53d927c`](https://github.com/mastra-ai/mastra/commit/53d927cc6f03bff33655b7e2b788da445a08731d), [`3f2faf2`](https://github.com/mastra-ai/mastra/commit/3f2faf2e2d685d6c053cc5af1bf9fedf267b2ce5), [`22f64bc`](https://github.com/mastra-ai/mastra/commit/22f64bc1d37149480b58bf2fefe35b79a1e3e7d5), [`83d5942`](https://github.com/mastra-ai/mastra/commit/83d5942669ce7bba4a6ca4fd4da697a10eb5ebdc), [`dff01d8`](https://github.com/mastra-ai/mastra/commit/dff01d81ce1f4e4087cfac20fa868e6db138dd14), [`b7959e6`](https://github.com/mastra-ai/mastra/commit/b7959e6e25a46b480f9ea2217c4c6c588c423791), [`bda6370`](https://github.com/mastra-ai/mastra/commit/bda637009360649aaf579919e7873e33553c273e), [`245820c`](https://github.com/mastra-ai/mastra/commit/245820cdea463218fd1c4e62eb2a349d6520fe71), [`d7acd8e`](https://github.com/mastra-ai/mastra/commit/d7acd8e987b5d7eff4fd98b0906c17c06a2e83d5), [`c7f1f7d`](https://github.com/mastra-ai/mastra/commit/c7f1f7d24f61f247f018cc2d1f33bf63212959a7), [`0bddc6d`](https://github.com/mastra-ai/mastra/commit/0bddc6d8dbd6f6008c0cba2e4960a2da75a55af1), [`735d8c1`](https://github.com/mastra-ai/mastra/commit/735d8c1c0d19fbc09e6f8b66cf41bc7655993838), [`acf322e`](https://github.com/mastra-ai/mastra/commit/acf322e0f1fd0189684cf529d91c694bea918a45), [`c942802`](https://github.com/mastra-ai/mastra/commit/c942802a477a925b01859a7b8688d4355715caaa), [`a0c8c1b`](https://github.com/mastra-ai/mastra/commit/a0c8c1b87d4fee252aebda73e8637fbe01d761c9), [`cc34739`](https://github.com/mastra-ai/mastra/commit/cc34739c34b6266a91bea561119240a7acf47887), [`c218bd3`](https://github.com/mastra-ai/mastra/commit/c218bd3759e32423735b04843a09404572631014), [`2c4438b`](https://github.com/mastra-ai/mastra/commit/2c4438b87817ab7eed818c7990fef010475af1a3), [`2b8893c`](https://github.com/mastra-ai/mastra/commit/2b8893cb108ef9acb72ee7835cd625610d2c1a4a), [`c218bd3`](https://github.com/mastra-ai/mastra/commit/c218bd3759e32423735b04843a09404572631014), [`8e5c75b`](https://github.com/mastra-ai/mastra/commit/8e5c75bdb1d08a42d45309a4c72def4b6890230f), [`e59e0d3`](https://github.com/mastra-ai/mastra/commit/e59e0d32afb5fcf2c9f3c00c8f81f6c21d3a63fa), [`fa8409b`](https://github.com/mastra-ai/mastra/commit/fa8409bc39cfd8ba6643b9db5269b90b22e2a2f7), [`173c535`](https://github.com/mastra-ai/mastra/commit/173c535c0645b0da404fe09f003778f0b0d4e019)]:
|
|
123
|
+
- @mastra/core@1.0.0-beta.0
|
|
124
|
+
- @mastra/libsql@1.0.0-beta.0
|
|
125
|
+
- @mastra/memory@1.0.0-beta.0
|
|
126
|
+
- @mastra/fastembed@1.0.0-beta.0
|
|
127
|
+
- @mastra/rag@2.0.0-beta.0
|
|
92
128
|
|
|
93
129
|
## 0.1.31
|
|
94
130
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/longmemeval",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-beta.0",
|
|
4
4
|
"description": "LongMemEval benchmark implementation for Mastra Memory",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@ai-sdk/openai": "^1.3.23",
|
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
"openai": "^4.73.1",
|
|
18
18
|
"ora": "^8.1.1",
|
|
19
19
|
"zod": "^3.23.8",
|
|
20
|
-
"@mastra/core": "0.
|
|
21
|
-
"@mastra/fastembed": "0.
|
|
22
|
-
"@mastra/
|
|
23
|
-
"@mastra/
|
|
20
|
+
"@mastra/core": "1.0.0-beta.0",
|
|
21
|
+
"@mastra/fastembed": "1.0.0-beta.0",
|
|
22
|
+
"@mastra/libsql": "1.0.0-beta.0",
|
|
23
|
+
"@mastra/memory": "1.0.0-beta.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@ai-sdk/google": "^1.2.19",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"vitest": "^2.1.8"
|
|
31
31
|
},
|
|
32
32
|
"engines": {
|
|
33
|
-
"node": ">=
|
|
33
|
+
"node": ">=22.13.0"
|
|
34
34
|
},
|
|
35
35
|
"homepage": "https://mastra.ai",
|
|
36
36
|
"repository": {
|
|
@@ -24,7 +24,8 @@ interface TemplateDatabase {
|
|
|
24
24
|
async function generateTemplate(question: LongMemEvalQuestion): Promise<string> {
|
|
25
25
|
// Create a simple agent for template generation
|
|
26
26
|
const agent = new Agent({
|
|
27
|
-
|
|
27
|
+
id: 'template-generator',
|
|
28
|
+
name: 'Template Generator',
|
|
28
29
|
instructions: `You are an expert at designing working memory templates for AI assistants.
|
|
29
30
|
|
|
30
31
|
Given a question and answer from a conversation history benchmark, generate a working memory instruction that would help an AI assistant extract and save the specific information needed to answer the question correctly.
|
|
@@ -148,7 +148,6 @@ describe('RunCommand', () => {
|
|
|
148
148
|
],
|
|
149
149
|
mastra_resources: [],
|
|
150
150
|
mastra_workflow_snapshot: [],
|
|
151
|
-
mastra_evals: [],
|
|
152
151
|
mastra_traces: [],
|
|
153
152
|
}),
|
|
154
153
|
);
|
|
@@ -225,7 +224,6 @@ describe('RunCommand', () => {
|
|
|
225
224
|
],
|
|
226
225
|
mastra_resources: [],
|
|
227
226
|
mastra_workflow_snapshot: [],
|
|
228
|
-
mastra_evals: [],
|
|
229
227
|
mastra_traces: [],
|
|
230
228
|
}),
|
|
231
229
|
);
|
|
@@ -322,7 +320,6 @@ describe('RunCommand', () => {
|
|
|
322
320
|
],
|
|
323
321
|
mastra_resources: [],
|
|
324
322
|
mastra_workflow_snapshot: [],
|
|
325
|
-
mastra_evals: [],
|
|
326
323
|
mastra_traces: [],
|
|
327
324
|
}),
|
|
328
325
|
);
|
package/src/commands/prepare.ts
CHANGED
|
@@ -475,7 +475,8 @@ export class PrepareCommand {
|
|
|
475
475
|
|
|
476
476
|
// Create agent with appropriate model
|
|
477
477
|
const agent = new Agent({
|
|
478
|
-
|
|
478
|
+
id: 'prep-agent',
|
|
479
|
+
name: 'Prep Agent',
|
|
479
480
|
instructions:
|
|
480
481
|
"You are a helpful assistant. Process and store conversation history. Only store working memory information if it's in the template. Other information is not relevant",
|
|
481
482
|
model: model,
|
package/src/commands/run.ts
CHANGED
|
@@ -335,7 +335,8 @@ For example, if the user previously mentioned they prefer a specific software, t
|
|
|
335
335
|
Be specific rather than generic when the user has expressed clear preferences in past conversations. If there is a clear preference, focus in on that, and do not add additional irrelevant information.`;
|
|
336
336
|
|
|
337
337
|
const agent = new Agent({
|
|
338
|
-
|
|
338
|
+
id: 'longmemeval-agent',
|
|
339
|
+
name: 'LongMemEval Agent',
|
|
339
340
|
model: modelProvider,
|
|
340
341
|
instructions: agentInstructions,
|
|
341
342
|
memory,
|
|
@@ -354,7 +355,8 @@ Be specific rather than generic when the user has expressed clear preferences in
|
|
|
354
355
|
});
|
|
355
356
|
|
|
356
357
|
const evalAgent = new Agent({
|
|
357
|
-
|
|
358
|
+
id: 'longmemeval-metric-agent',
|
|
359
|
+
name: 'LongMemEval Metric Agent',
|
|
358
360
|
model: retry4o.model,
|
|
359
361
|
instructions: 'You are an evaluation assistant. Answer questions precisely and concisely.',
|
|
360
362
|
});
|
|
@@ -117,9 +117,9 @@ describe('BenchmarkStore', () => {
|
|
|
117
117
|
expect(restoredThread).toBeTruthy();
|
|
118
118
|
expect(restoredThread?.title).toBe('Test Thread');
|
|
119
119
|
|
|
120
|
-
const
|
|
121
|
-
expect(
|
|
122
|
-
expect(
|
|
120
|
+
const result = await store2.listMessages({ threadId: 'test-thread-1' });
|
|
121
|
+
expect(result.messages).toHaveLength(1);
|
|
122
|
+
expect(result.messages[0].content).toMatchObject({ text: 'Hello' });
|
|
123
123
|
});
|
|
124
124
|
|
|
125
125
|
it('should throw error if file does not exist', async () => {
|
|
@@ -184,24 +184,22 @@ describe('BenchmarkStore', () => {
|
|
|
184
184
|
],
|
|
185
185
|
});
|
|
186
186
|
|
|
187
|
-
// Query using
|
|
188
|
-
const
|
|
187
|
+
// Query using include to get messages from different threads
|
|
188
|
+
const result = await store.listMessages({
|
|
189
189
|
threadId: 'thread-1',
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
],
|
|
199
|
-
},
|
|
190
|
+
include: [
|
|
191
|
+
{
|
|
192
|
+
id: 'msg-2',
|
|
193
|
+
threadId: 'thread-2', // Different thread!
|
|
194
|
+
withPreviousMessages: 0,
|
|
195
|
+
withNextMessages: 1,
|
|
196
|
+
},
|
|
197
|
+
],
|
|
200
198
|
});
|
|
201
199
|
|
|
202
|
-
expect(messages).toHaveLength(2);
|
|
203
|
-
expect(messages[0].content).
|
|
204
|
-
expect(messages[1].content).
|
|
200
|
+
expect(result.messages).toHaveLength(2);
|
|
201
|
+
expect(result.messages[0].content).toMatchObject({ text: 'Message in thread 2' });
|
|
202
|
+
expect(result.messages[1].content).toMatchObject({ text: 'Response in thread 2' });
|
|
205
203
|
});
|
|
206
204
|
});
|
|
207
205
|
|
|
@@ -260,19 +258,11 @@ describe('BenchmarkStore', () => {
|
|
|
260
258
|
|
|
261
259
|
describe('getting messages', () => {
|
|
262
260
|
it('should throw when threadId is an empty string or whitespace only', async () => {
|
|
263
|
-
await expect(() => store.
|
|
264
|
-
'threadId must be a non-empty string',
|
|
265
|
-
);
|
|
266
|
-
|
|
267
|
-
await expect(() => store.getMessagesPaginated({ threadId: '' })).rejects.toThrowError(
|
|
268
|
-
'threadId must be a non-empty string',
|
|
269
|
-
);
|
|
270
|
-
|
|
271
|
-
await expect(() => store.getMessages({ threadId: ' ' })).rejects.toThrowError(
|
|
261
|
+
await expect(() => store.listMessages({ threadId: '' })).rejects.toThrowError(
|
|
272
262
|
'threadId must be a non-empty string',
|
|
273
263
|
);
|
|
274
264
|
|
|
275
|
-
await expect(() => store.
|
|
265
|
+
await expect(() => store.listMessages({ threadId: ' ' })).rejects.toThrowError(
|
|
276
266
|
'threadId must be a non-empty string',
|
|
277
267
|
);
|
|
278
268
|
});
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { MastraStorage } from '@mastra/core/storage';
|
|
2
2
|
import { MessageList } from '@mastra/core/agent';
|
|
3
|
-
import type {
|
|
4
|
-
import type { MastraMessageV1, StorageThreadType } from '@mastra/core/memory';
|
|
5
|
-
import type { Trace } from '@mastra/core/telemetry';
|
|
3
|
+
import type { MastraMessageV1, MastraDBMessage, StorageThreadType } from '@mastra/core/memory';
|
|
6
4
|
import type {
|
|
7
5
|
TABLE_NAMES,
|
|
8
6
|
StorageColumn,
|
|
9
|
-
StorageGetMessagesArg,
|
|
10
7
|
StorageResourceType,
|
|
11
|
-
EvalRow,
|
|
12
8
|
WorkflowRun,
|
|
13
9
|
WorkflowRuns,
|
|
14
|
-
|
|
10
|
+
StorageListWorkflowRunsInput,
|
|
11
|
+
StorageListThreadsByResourceIdInput,
|
|
12
|
+
StorageListThreadsByResourceIdOutput,
|
|
13
|
+
StorageListMessagesInput,
|
|
14
|
+
StorageListMessagesOutput,
|
|
15
15
|
} from '@mastra/core/storage';
|
|
16
16
|
import { writeFile, readFile } from 'fs/promises';
|
|
17
17
|
import { existsSync } from 'fs';
|
|
@@ -21,7 +21,6 @@ type DBMode = 'read' | 'read-write';
|
|
|
21
21
|
export class BenchmarkStore extends MastraStorage {
|
|
22
22
|
private data: Record<TABLE_NAMES, Map<string, any>> = {
|
|
23
23
|
mastra_workflow_snapshot: new Map(),
|
|
24
|
-
mastra_evals: new Map(),
|
|
25
24
|
mastra_messages: new Map(),
|
|
26
25
|
mastra_threads: new Map(),
|
|
27
26
|
mastra_traces: new Map(),
|
|
@@ -79,16 +78,6 @@ export class BenchmarkStore extends MastraStorage {
|
|
|
79
78
|
return thread || null;
|
|
80
79
|
}
|
|
81
80
|
|
|
82
|
-
async getThreadsByResourceId({ resourceId }: { resourceId: string }): Promise<StorageThreadType[]> {
|
|
83
|
-
const threads: StorageThreadType[] = [];
|
|
84
|
-
for (const thread of this.data.mastra_threads.values()) {
|
|
85
|
-
if (thread.resourceId === resourceId) {
|
|
86
|
-
threads.push(thread);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return threads;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
81
|
async saveThread({ thread }: { thread: StorageThreadType }): Promise<StorageThreadType> {
|
|
93
82
|
this.data.mastra_threads.set(thread.id, thread);
|
|
94
83
|
return thread;
|
|
@@ -177,76 +166,11 @@ export class BenchmarkStore extends MastraStorage {
|
|
|
177
166
|
return resource;
|
|
178
167
|
}
|
|
179
168
|
|
|
180
|
-
async getMessages(args: StorageGetMessagesArg & { format?: 'v1' }): Promise<MastraMessageV1[]>;
|
|
181
|
-
async getMessages(args: StorageGetMessagesArg & { format: 'v2' }): Promise<MastraMessageV2[]>;
|
|
182
|
-
async getMessages(
|
|
183
|
-
args: StorageGetMessagesArg & { format?: 'v1' | 'v2' },
|
|
184
|
-
): Promise<MastraMessageV1[] | MastraMessageV2[]> {
|
|
185
|
-
const { threadId, resourceId, selectBy, format = 'v1' } = args;
|
|
186
|
-
if (!threadId.trim()) throw new Error('threadId must be a non-empty string');
|
|
187
|
-
|
|
188
|
-
let messages: any[] = [];
|
|
189
|
-
const includedMessageIds = new Set<string>();
|
|
190
|
-
|
|
191
|
-
// First, handle selectBy.include for cross-thread queries (resource scope support)
|
|
192
|
-
if (selectBy?.include?.length) {
|
|
193
|
-
for (const inc of selectBy.include) {
|
|
194
|
-
// Use the included threadId if provided (resource scope), otherwise use main threadId
|
|
195
|
-
const queryThreadId = inc.threadId || threadId;
|
|
196
|
-
|
|
197
|
-
// Get the target message and surrounding context
|
|
198
|
-
const threadMessages = Array.from(this.data.mastra_messages.values())
|
|
199
|
-
.filter((msg: any) => msg.threadId === queryThreadId)
|
|
200
|
-
.sort((a: any, b: any) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime());
|
|
201
|
-
|
|
202
|
-
const targetIndex = threadMessages.findIndex((msg: any) => msg.id === inc.id);
|
|
203
|
-
|
|
204
|
-
if (targetIndex >= 0) {
|
|
205
|
-
const startIdx = Math.max(0, targetIndex - (inc.withPreviousMessages || 0));
|
|
206
|
-
const endIdx = Math.min(threadMessages.length, targetIndex + (inc.withNextMessages || 0) + 1);
|
|
207
|
-
|
|
208
|
-
for (let i = startIdx; i < endIdx; i++) {
|
|
209
|
-
includedMessageIds.add(threadMessages[i].id);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
// Get base messages for the thread
|
|
216
|
-
let baseMessages: any[] = [];
|
|
217
|
-
if (threadId || resourceId) {
|
|
218
|
-
baseMessages = Array.from(this.data.mastra_messages.values()).filter((msg: any) => {
|
|
219
|
-
if (threadId && msg.threadId !== threadId) return false;
|
|
220
|
-
if (resourceId && msg.resourceId !== resourceId) return false;
|
|
221
|
-
return true;
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
// Apply selectBy.last to base messages only
|
|
225
|
-
if (selectBy?.last) {
|
|
226
|
-
// Sort first to ensure we get the actual last messages
|
|
227
|
-
baseMessages.sort((a: any, b: any) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime());
|
|
228
|
-
baseMessages = baseMessages.slice(-selectBy.last);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
// Combine base messages with included messages
|
|
233
|
-
const baseMessageIds = new Set(baseMessages.map((m: any) => m.id));
|
|
234
|
-
const allMessageIds = new Set([...baseMessageIds, ...includedMessageIds]);
|
|
235
|
-
|
|
236
|
-
// Get all unique messages
|
|
237
|
-
messages = Array.from(this.data.mastra_messages.values()).filter((msg: any) => allMessageIds.has(msg.id));
|
|
238
|
-
// Sort by createdAt
|
|
239
|
-
messages.sort((a: any, b: any) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime());
|
|
240
|
-
|
|
241
|
-
const list = new MessageList().add(messages, 'memory');
|
|
242
|
-
return format === 'v2' ? list.get.all.v2() : list.get.all.v1();
|
|
243
|
-
}
|
|
244
|
-
|
|
245
169
|
async saveMessages(args: { messages: MastraMessageV1[]; format?: undefined | 'v1' }): Promise<MastraMessageV1[]>;
|
|
246
|
-
async saveMessages(args: { messages:
|
|
170
|
+
async saveMessages(args: { messages: MastraDBMessage[]; format: 'v2' }): Promise<MastraDBMessage[]>;
|
|
247
171
|
async saveMessages(
|
|
248
|
-
args: { messages: MastraMessageV1[]; format?: undefined | 'v1' } | { messages:
|
|
249
|
-
): Promise<
|
|
172
|
+
args: { messages: MastraMessageV1[]; format?: undefined | 'v1' } | { messages: MastraDBMessage[]; format: 'v2' },
|
|
173
|
+
): Promise<MastraDBMessage[] | MastraMessageV1[]> {
|
|
250
174
|
if (this.mode === `read`) return [];
|
|
251
175
|
|
|
252
176
|
const { messages, format = 'v1' } = args;
|
|
@@ -256,11 +180,11 @@ export class BenchmarkStore extends MastraStorage {
|
|
|
256
180
|
}
|
|
257
181
|
|
|
258
182
|
const list = new MessageList().add(messages, 'memory');
|
|
259
|
-
return format === 'v2' ? list.get.all.
|
|
183
|
+
return format === 'v2' ? list.get.all.db() : list.get.all.v1();
|
|
260
184
|
}
|
|
261
185
|
|
|
262
|
-
async updateMessages(args: { messages: Partial<
|
|
263
|
-
const updatedMessages:
|
|
186
|
+
async updateMessages(args: { messages: Partial<MastraDBMessage> & { id: string }[] }): Promise<MastraDBMessage[]> {
|
|
187
|
+
const updatedMessages: MastraDBMessage[] = [];
|
|
264
188
|
|
|
265
189
|
if (this.mode === `read`) return [];
|
|
266
190
|
|
|
@@ -332,21 +256,14 @@ export class BenchmarkStore extends MastraStorage {
|
|
|
332
256
|
return evals as EvalRow[];
|
|
333
257
|
}
|
|
334
258
|
|
|
335
|
-
async
|
|
259
|
+
async listWorkflowRuns({
|
|
336
260
|
workflowName,
|
|
337
261
|
fromDate,
|
|
338
262
|
toDate,
|
|
339
263
|
limit,
|
|
340
264
|
offset,
|
|
341
265
|
resourceId,
|
|
342
|
-
}: {
|
|
343
|
-
workflowName?: string;
|
|
344
|
-
fromDate?: Date;
|
|
345
|
-
toDate?: Date;
|
|
346
|
-
limit?: number;
|
|
347
|
-
offset?: number;
|
|
348
|
-
resourceId?: string;
|
|
349
|
-
} = {}): Promise<WorkflowRuns> {
|
|
266
|
+
}: StorageListWorkflowRunsInput = {}): Promise<WorkflowRuns> {
|
|
350
267
|
let runs = Array.from(this.data.mastra_workflow_snapshot.values());
|
|
351
268
|
|
|
352
269
|
if (workflowName) runs = runs.filter((run: any) => run.workflow_name === workflowName);
|
|
@@ -403,78 +320,107 @@ export class BenchmarkStore extends MastraStorage {
|
|
|
403
320
|
return parsedRun as WorkflowRun;
|
|
404
321
|
}
|
|
405
322
|
|
|
406
|
-
async
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
attributes?: Record<string, string>;
|
|
418
|
-
page: number;
|
|
419
|
-
perPage: number;
|
|
420
|
-
fromDate?: Date;
|
|
421
|
-
toDate?: Date;
|
|
422
|
-
}): Promise<PaginationInfo & { traces: Trace[] }> {
|
|
423
|
-
const traces = await this.getTraces({ name, scope, page, perPage, attributes, fromDate, toDate });
|
|
424
|
-
const total = Array.from(this.data.mastra_traces.values()).length;
|
|
425
|
-
|
|
426
|
-
return {
|
|
427
|
-
traces,
|
|
428
|
-
total,
|
|
429
|
-
page,
|
|
430
|
-
perPage,
|
|
431
|
-
hasMore: total > (page + 1) * perPage,
|
|
432
|
-
};
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
async getThreadsByResourceIdPaginated(args: {
|
|
436
|
-
resourceId: string;
|
|
437
|
-
page: number;
|
|
438
|
-
perPage: number;
|
|
439
|
-
}): Promise<PaginationInfo & { threads: StorageThreadType[] }> {
|
|
440
|
-
const allThreads = await this.getThreadsByResourceId({ resourceId: args.resourceId });
|
|
441
|
-
const start = args.page * args.perPage;
|
|
442
|
-
const threads = allThreads.slice(start, start + args.perPage);
|
|
323
|
+
async listThreadsByResourceId(
|
|
324
|
+
args: StorageListThreadsByResourceIdInput,
|
|
325
|
+
): Promise<StorageListThreadsByResourceIdOutput> {
|
|
326
|
+
const allThreads: StorageThreadType[] = [];
|
|
327
|
+
for (const thread of this.data.mastra_threads.values()) {
|
|
328
|
+
if (thread.resourceId === args.resourceId) {
|
|
329
|
+
allThreads.push(thread);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
const start = args.offset * args.limit;
|
|
333
|
+
const threads = allThreads.slice(start, start + args.limit);
|
|
443
334
|
|
|
444
335
|
return {
|
|
445
336
|
threads,
|
|
446
337
|
total: allThreads.length,
|
|
447
|
-
page: args.
|
|
448
|
-
perPage: args.
|
|
449
|
-
hasMore: allThreads.length > (args.
|
|
338
|
+
page: args.offset,
|
|
339
|
+
perPage: args.limit,
|
|
340
|
+
hasMore: allThreads.length > (args.offset + 1) * args.limit,
|
|
450
341
|
};
|
|
451
342
|
}
|
|
452
343
|
|
|
453
|
-
async
|
|
454
|
-
|
|
455
|
-
): Promise<PaginationInfo & { messages: MastraMessageV1[] | MastraMessageV2[] }> {
|
|
456
|
-
const { threadId, selectBy, format = 'v1' } = args;
|
|
344
|
+
async listMessages(args: StorageListMessagesInput): Promise<StorageListMessagesOutput> {
|
|
345
|
+
const { threadId, page = 0, perPage = 40, resourceId, filter, include, orderBy } = args;
|
|
457
346
|
if (!threadId.trim()) throw new Error('threadId must be a non-empty string');
|
|
458
347
|
|
|
459
|
-
|
|
348
|
+
let messages: any[] = [];
|
|
349
|
+
const includedMessageIds = new Set<string>();
|
|
350
|
+
|
|
351
|
+
// Handle include for cross-thread queries (resource scope support)
|
|
352
|
+
if (include?.length) {
|
|
353
|
+
for (const inc of include) {
|
|
354
|
+
// Use the included threadId if provided (resource scope), otherwise use main threadId
|
|
355
|
+
const queryThreadId = inc.threadId || threadId;
|
|
460
356
|
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
357
|
+
// Get the target message and surrounding context
|
|
358
|
+
const threadMessages = Array.from(this.data.mastra_messages.values())
|
|
359
|
+
.filter((msg: any) => msg.threadId === queryThreadId)
|
|
360
|
+
.sort((a: any, b: any) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime());
|
|
361
|
+
|
|
362
|
+
const targetIndex = threadMessages.findIndex((msg: any) => msg.id === inc.id);
|
|
363
|
+
|
|
364
|
+
if (targetIndex >= 0) {
|
|
365
|
+
const startIdx = Math.max(0, targetIndex - (inc.withPreviousMessages || 0));
|
|
366
|
+
const endIdx = Math.min(threadMessages.length, targetIndex + (inc.withNextMessages || 0) + 1);
|
|
367
|
+
|
|
368
|
+
for (let i = startIdx; i < endIdx; i++) {
|
|
369
|
+
includedMessageIds.add(threadMessages[i].id);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// Get base messages for the thread
|
|
376
|
+
const baseMessages = Array.from(this.data.mastra_messages.values()).filter((msg: any) => {
|
|
377
|
+
if (msg.threadId !== threadId) return false;
|
|
378
|
+
if (resourceId && msg.resourceId !== resourceId) return false;
|
|
379
|
+
return true;
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
// Combine base messages with included messages
|
|
383
|
+
const baseMessageIds = new Set(baseMessages.map((m: any) => m.id));
|
|
384
|
+
const allMessageIds = new Set([...baseMessageIds, ...includedMessageIds]);
|
|
385
|
+
|
|
386
|
+
// Get all unique messages and convert to v2 format
|
|
387
|
+
const allMessages = Array.from(this.data.mastra_messages.values()).filter((msg: any) => allMessageIds.has(msg.id));
|
|
388
|
+
const list = new MessageList().add(allMessages, 'memory');
|
|
389
|
+
let filteredMessages = list.get.all.db();
|
|
390
|
+
|
|
391
|
+
// Apply date filters
|
|
392
|
+
if (filter?.dateRange?.start) {
|
|
393
|
+
filteredMessages = filteredMessages.filter((m: any) => new Date(m.createdAt) >= filter.dateRange!.start!);
|
|
394
|
+
}
|
|
395
|
+
if (filter?.dateRange?.end) {
|
|
396
|
+
filteredMessages = filteredMessages.filter((m: any) => new Date(m.createdAt) <= filter.dateRange!.end!);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
// Apply ordering - default to ASC by createdAt
|
|
400
|
+
const sortField = orderBy?.field || 'createdAt';
|
|
401
|
+
const sortDirection = orderBy?.direction || 'ASC';
|
|
402
|
+
const direction = sortDirection === 'ASC' ? 1 : -1;
|
|
403
|
+
|
|
404
|
+
filteredMessages.sort((a: any, b: any) => {
|
|
405
|
+
const aVal = a[sortField];
|
|
406
|
+
const bVal = b[sortField];
|
|
407
|
+
if (aVal instanceof Date && bVal instanceof Date) {
|
|
408
|
+
return direction * (aVal.getTime() - bVal.getTime());
|
|
409
|
+
}
|
|
410
|
+
return direction * (aVal < bVal ? -1 : aVal > bVal ? 1 : 0);
|
|
411
|
+
});
|
|
467
412
|
|
|
468
413
|
// Apply pagination
|
|
469
|
-
const
|
|
470
|
-
const
|
|
414
|
+
const normalizedPerPage = perPage === false ? filteredMessages.length : perPage;
|
|
415
|
+
const start = perPage === false ? 0 : page * normalizedPerPage;
|
|
416
|
+
messages = filteredMessages.slice(start, start + normalizedPerPage);
|
|
471
417
|
|
|
472
418
|
return {
|
|
473
|
-
messages,
|
|
474
|
-
total:
|
|
419
|
+
messages: messages as MastraDBMessage[],
|
|
420
|
+
total: filteredMessages.length,
|
|
475
421
|
page,
|
|
476
|
-
perPage,
|
|
477
|
-
hasMore:
|
|
422
|
+
perPage: perPage === false ? false : normalizedPerPage,
|
|
423
|
+
hasMore: perPage === false ? false : filteredMessages.length > (page + 1) * normalizedPerPage,
|
|
478
424
|
};
|
|
479
425
|
}
|
|
480
426
|
|