@mastra/dynamodb 1.1.2 → 1.1.3
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 +30 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/reference-storage-dynamodb.md +2 -2
- package/dist/index.cjs +92 -56
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +93 -57
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +11 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# @mastra/dynamodb
|
|
2
2
|
|
|
3
|
+
## 1.1.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fixed `listMessages()` silently truncating large threads, returning incorrect pagination metadata, and failing to retrieve included-message context beyond the first DynamoDB page. Large threads now return complete paginated results with correct `total` and `hasMore`, and `include` lookups (e.g. jumping to a message deep in a thread) again return the requested surrounding context instead of partial or empty windows. ([#19562](https://github.com/mastra-ai/mastra/pull/19562))
|
|
8
|
+
|
|
9
|
+
- Fixed a TypeScript build error in the DynamoDB store where date range filtering in listMessages failed strict null checks ([#19567](https://github.com/mastra-ai/mastra/pull/19567))
|
|
10
|
+
|
|
11
|
+
- Fixed `listMessages` pagination so `hasMore` is `false` when `include` (e.g. `withNextMessages`/`withPreviousMessages`) already returns every message in the queried thread(s). Previously `hasMore` was derived from `offset + perPage < total` only, so it stayed `true` even when the included context completed the full set — matching the behavior of the pg store. ([#19371](https://github.com/mastra-ai/mastra/pull/19371))
|
|
12
|
+
|
|
13
|
+
- Fixed `listMessages` reporting `hasMore: false` too early when `include` context messages fall outside the active `resourceId` or `dateRange` filters. Only messages matching the filters now count toward the returned total, so later filter-matching pages are no longer hidden. ([#19576](https://github.com/mastra-ai/mastra/pull/19576))
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [[`ec857fc`](https://github.com/mastra-ai/mastra/commit/ec857fc79c264b53b38e16478c789b7177f2ad59), [`d7385ad`](https://github.com/mastra-ai/mastra/commit/d7385ad9e88f9e4f33d15c0ec0bfebedde0cbc2e), [`41a5392`](https://github.com/mastra-ai/mastra/commit/41a5392d9f6c5e18d6b227f0fc0ddf49c50774e9), [`3d6e539`](https://github.com/mastra-ai/mastra/commit/3d6e539272eb2ea0407034605ee1906b3be06b39), [`1426af2`](https://github.com/mastra-ai/mastra/commit/1426af24975879c000d13ac75673f630fcc970c1), [`a40adeb`](https://github.com/mastra-ai/mastra/commit/a40adeb222b961a56a58af56a106106525721b74), [`8a0d145`](https://github.com/mastra-ai/mastra/commit/8a0d145aadbdf7278665aceaaec364b35dd9bd94), [`bd2f1d2`](https://github.com/mastra-ai/mastra/commit/bd2f1d274d05e60e2366f005ea0d94d5cea0d5ff), [`e1f2fae`](https://github.com/mastra-ai/mastra/commit/e1f2faebaf048c3d4c2e2c01d293767c195d5794), [`63aa799`](https://github.com/mastra-ai/mastra/commit/63aa799c6b44eacc7806cda6846b7c5bbee06b37), [`b7e79c3`](https://github.com/mastra-ai/mastra/commit/b7e79c3c02ac5cd415db34ba0975ceafc1464333), [`675fbff`](https://github.com/mastra-ai/mastra/commit/675fbff84d3274391b33e852f76083c38a5514e5), [`da009e1`](https://github.com/mastra-ai/mastra/commit/da009e1aacd89ed94b8d1b2af09c9d4fe7c4db49), [`3b77e77`](https://github.com/mastra-ai/mastra/commit/3b77e7704936522e4769d29de1b5ea6901f302bd), [`c7d30cd`](https://github.com/mastra-ai/mastra/commit/c7d30cd86009c407df91105591f03cd6e3d2854d), [`21a0eb8`](https://github.com/mastra-ai/mastra/commit/21a0eb86746ba0b703acea360d4f84c6a5a493f2), [`8b20926`](https://github.com/mastra-ai/mastra/commit/8b20926cd59e2ba3d66458e062fa0e6e2ada3e68), [`975295d`](https://github.com/mastra-ai/mastra/commit/975295d418552f0d46a59edfef4c3ee555f9930a), [`73db8db`](https://github.com/mastra-ai/mastra/commit/73db8db90d69ab6153c7942749f624db0d96952d), [`6b1bf3b`](https://github.com/mastra-ai/mastra/commit/6b1bf3b9494bd51aa8f654c68c9355d6046fa2a1), [`35c2181`](https://github.com/mastra-ai/mastra/commit/35c2181e6a50e47c90ba36260db7c9723d54696f), [`0a2c22c`](https://github.com/mastra-ai/mastra/commit/0a2c22c902604439ec490319e14c17f331e0c84c), [`4cfdd64`](https://github.com/mastra-ai/mastra/commit/4cfdd645794feaea0c4ea711e70ecdfbef0c5b8e), [`b75d749`](https://github.com/mastra-ai/mastra/commit/b75d749621ff5d17e86bcb4ee809d301fb4f7cf3), [`821648b`](https://github.com/mastra-ai/mastra/commit/821648bf2871ef840100c7bacbecf676010bd12a), [`de86fd7`](https://github.com/mastra-ai/mastra/commit/de86fd7119f0438381d1a642e3d258143c0b9c29), [`2745031`](https://github.com/mastra-ai/mastra/commit/2745031d1d4a4978f037092da371428c32e2842a), [`b4b7ea8`](https://github.com/mastra-ai/mastra/commit/b4b7ea8733f033fc441ea47ed03f6afb17ec2248), [`3a8024c`](https://github.com/mastra-ai/mastra/commit/3a8024ce615f8aa89479c0d71fe61d10bb0040be), [`35865a5`](https://github.com/mastra-ai/mastra/commit/35865a53e194aa9634d6a70a97010e7a6b9d58b1), [`74faf8b`](https://github.com/mastra-ai/mastra/commit/74faf8bd9c1018f2492653c06b1e25fc8300e9e6), [`ef03fbc`](https://github.com/mastra-ai/mastra/commit/ef03fbcc556bcbc04c9b3d06fab88771ecaa043c), [`675fbff`](https://github.com/mastra-ai/mastra/commit/675fbff84d3274391b33e852f76083c38a5514e5), [`70687f7`](https://github.com/mastra-ai/mastra/commit/70687f7e495a322a02070b4a67cb0c77a5ca91ec), [`1fadac4`](https://github.com/mastra-ai/mastra/commit/1fadac44537caeefe81f9f775ae2f2f3d94e9069), [`73db8db`](https://github.com/mastra-ai/mastra/commit/73db8db90d69ab6153c7942749f624db0d96952d), [`76b7181`](https://github.com/mastra-ai/mastra/commit/76b71810366e6d90b9d3973149d1c7ba3659ffb9), [`792ec9a`](https://github.com/mastra-ai/mastra/commit/792ec9a0869bab8274cf5e0ed2840738737a1607), [`712b864`](https://github.com/mastra-ai/mastra/commit/712b864aa1ed12b14c54390ec17b69de163c37f7), [`85e4fb5`](https://github.com/mastra-ai/mastra/commit/85e4fb50087a81c74df3a762f53b56373db0b912), [`0c0e8d7`](https://github.com/mastra-ai/mastra/commit/0c0e8d7becd4d1445c656b78d5d845f606c1ff9d), [`a7bbe77`](https://github.com/mastra-ai/mastra/commit/a7bbe773577f60bc4761b534ef7ec6b476332dad), [`72e437c`](https://github.com/mastra-ai/mastra/commit/72e437c515942c80b9def5b026e0bdee61b469d9), [`8f7a5de`](https://github.com/mastra-ai/mastra/commit/8f7a5dedc246cdc938bb65516703cf9b27b03756), [`a7bbe77`](https://github.com/mastra-ai/mastra/commit/a7bbe773577f60bc4761b534ef7ec6b476332dad), [`11f6cd9`](https://github.com/mastra-ai/mastra/commit/11f6cd96fe42582403416608beb212cc1a2cc79e), [`ef03c0c`](https://github.com/mastra-ai/mastra/commit/ef03c0cfc62367a458e4cc56462e2148b35681c5), [`4fb4d88`](https://github.com/mastra-ai/mastra/commit/4fb4d881bc107acee13890ad4d78661016c510ed), [`4e68363`](https://github.com/mastra-ai/mastra/commit/4e683634f94ebd062d26a3bb6093a8dfc7263d37), [`c328769`](https://github.com/mastra-ai/mastra/commit/c3287698ff8ef98dba86d415faa566fa3e5f4d56), [`9f7c67a`](https://github.com/mastra-ai/mastra/commit/9f7c67abeeb52c41c51a9b5edee60b62afe7cd8d), [`3b65e68`](https://github.com/mastra-ai/mastra/commit/3b65e68d7f1c771c7a70eea42d83fefdd28cad88), [`4eba27a`](https://github.com/mastra-ai/mastra/commit/4eba27adcf60f991df0e62f94b3e75b4e67f3b4b), [`c701be3`](https://github.com/mastra-ai/mastra/commit/c701be32d7d9aa94a66da8c6cc38dcac6856f464), [`db650ce`](https://github.com/mastra-ai/mastra/commit/db650ce490348914e85b93651d83acdf8f2a4c31), [`232fcbc`](https://github.com/mastra-ai/mastra/commit/232fcbc14fce625dd672ba043329c0b732c62be2), [`6354eeb`](https://github.com/mastra-ai/mastra/commit/6354eeb32efa9f5f68f51dda394e90e2ee76f1fb), [`a8799bb`](https://github.com/mastra-ai/mastra/commit/a8799bb8e44f4a60d01e4e2acd3448ff80bf14f8), [`3d6e539`](https://github.com/mastra-ai/mastra/commit/3d6e539272eb2ea0407034605ee1906b3be06b39), [`e3868e2`](https://github.com/mastra-ai/mastra/commit/e3868e22babfffd0133771669ca724501c2dd58e), [`9251370`](https://github.com/mastra-ai/mastra/commit/9251370ad413af464aa22d7566338bec5613e8de), [`3491666`](https://github.com/mastra-ai/mastra/commit/34916663c4fdd43b48c21f4ab2d5fb6dcccc94f9), [`c0bec73`](https://github.com/mastra-ai/mastra/commit/c0bec732c93d1a22ae5e51ed66cf8cacca8bd6a6)]:
|
|
16
|
+
- @mastra/core@1.52.0
|
|
17
|
+
|
|
18
|
+
## 1.1.3-alpha.0
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- Fixed `listMessages()` silently truncating large threads, returning incorrect pagination metadata, and failing to retrieve included-message context beyond the first DynamoDB page. Large threads now return complete paginated results with correct `total` and `hasMore`, and `include` lookups (e.g. jumping to a message deep in a thread) again return the requested surrounding context instead of partial or empty windows. ([#19562](https://github.com/mastra-ai/mastra/pull/19562))
|
|
23
|
+
|
|
24
|
+
- Fixed a TypeScript build error in the DynamoDB store where date range filtering in listMessages failed strict null checks ([#19567](https://github.com/mastra-ai/mastra/pull/19567))
|
|
25
|
+
|
|
26
|
+
- Fixed `listMessages` pagination so `hasMore` is `false` when `include` (e.g. `withNextMessages`/`withPreviousMessages`) already returns every message in the queried thread(s). Previously `hasMore` was derived from `offset + perPage < total` only, so it stayed `true` even when the included context completed the full set — matching the behavior of the pg store. ([#19371](https://github.com/mastra-ai/mastra/pull/19371))
|
|
27
|
+
|
|
28
|
+
- Fixed `listMessages` reporting `hasMore: false` too early when `include` context messages fall outside the active `resourceId` or `dateRange` filters. Only messages matching the filters now count toward the returned total, so later filter-matching pages are no longer hidden. ([#19576](https://github.com/mastra-ai/mastra/pull/19576))
|
|
29
|
+
|
|
30
|
+
- Updated dependencies [[`1426af2`](https://github.com/mastra-ai/mastra/commit/1426af24975879c000d13ac75673f630fcc970c1), [`975295d`](https://github.com/mastra-ai/mastra/commit/975295d418552f0d46a59edfef4c3ee555f9930a), [`85e4fb5`](https://github.com/mastra-ai/mastra/commit/85e4fb50087a81c74df3a762f53b56373db0b912), [`ef03c0c`](https://github.com/mastra-ai/mastra/commit/ef03c0cfc62367a458e4cc56462e2148b35681c5), [`4fb4d88`](https://github.com/mastra-ai/mastra/commit/4fb4d881bc107acee13890ad4d78661016c510ed), [`4eba27a`](https://github.com/mastra-ai/mastra/commit/4eba27adcf60f991df0e62f94b3e75b4e67f3b4b), [`c701be3`](https://github.com/mastra-ai/mastra/commit/c701be32d7d9aa94a66da8c6cc38dcac6856f464)]:
|
|
31
|
+
- @mastra/core@1.52.0-alpha.3
|
|
32
|
+
|
|
3
33
|
## 1.1.2
|
|
4
34
|
|
|
5
35
|
### Patch Changes
|
package/dist/docs/SKILL.md
CHANGED
|
@@ -6,7 +6,7 @@ The DynamoDB storage implementation provides a scalable and performant NoSQL dat
|
|
|
6
6
|
|
|
7
7
|
> **Observability Not Supported:** DynamoDB storage **doesn't support the observability domain**. Traces from the `MastraStorageExporter` can't be persisted to DynamoDB, and [Studio's](https://mastra.ai/docs/studio/overview) observability features won't work with DynamoDB as your only storage provider. To enable observability, use [composite storage](https://mastra.ai/reference/storage/composite) to route observability data to a supported provider like ClickHouse.
|
|
8
8
|
|
|
9
|
-
> **Item Size Limit:** DynamoDB enforces a **400 KB maximum item size**. This limit can be exceeded when storing messages with base64-encoded attachments such as images. See [Handling large attachments](https://mastra.ai/docs/memory/
|
|
9
|
+
> **Item Size Limit:** DynamoDB enforces a **400 KB maximum item size**. This limit can be exceeded when storing messages with base64-encoded attachments such as images. See [Handling large attachments](https://mastra.ai/docs/memory/memory-processors) for workarounds including uploading attachments to external storage.
|
|
10
10
|
|
|
11
11
|
## Features
|
|
12
12
|
|
|
@@ -118,7 +118,7 @@ For local development, you can use [DynamoDB Local](https://docs.aws.amazon.com/
|
|
|
118
118
|
|
|
119
119
|
**config.endpoint** (`string`): Custom endpoint for DynamoDB (e.g., 'http\://localhost:8000' for local development).
|
|
120
120
|
|
|
121
|
-
**config.credentials** (`object`): AWS credentials object with
|
|
121
|
+
**config.credentials** (`object`): AWS credentials object with accessKeyId and secretAccessKey. If not provided, the AWS SDK will attempt to source credentials from environment variables, IAM roles (e.g., for EC2/Lambda), or the shared AWS credentials file.
|
|
122
122
|
|
|
123
123
|
**config.ttl** (`object`): TTL (Time To Live) configuration for automatic data expiration. Configure per entity type: thread, message, trace, eval, workflow\_snapshot, resource, score. Each entity config includes: enabled (boolean), attributeName (string, default: 'ttl'), defaultTtlSeconds (number).
|
|
124
124
|
|
package/dist/index.cjs
CHANGED
|
@@ -1800,29 +1800,80 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
|
|
|
1800
1800
|
hasMore: false
|
|
1801
1801
|
};
|
|
1802
1802
|
}
|
|
1803
|
-
const
|
|
1804
|
-
const
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1803
|
+
const order = direction === "DESC" ? "desc" : "asc";
|
|
1804
|
+
const parseQueryMessages = (data) => data.map((item) => this.parseMessageData(item)).filter((msg) => "content" in msg && typeof msg.content === "object");
|
|
1805
|
+
const toIso = (value) => value instanceof Date ? value.toISOString() : String(value);
|
|
1806
|
+
const applyQueryFilters = (q) => {
|
|
1807
|
+
let query = q;
|
|
1808
|
+
const dateRange = filter?.dateRange;
|
|
1809
|
+
const startIso = dateRange?.start ? toIso(dateRange.start) : void 0;
|
|
1810
|
+
const endIso = dateRange?.end ? toIso(dateRange.end) : void 0;
|
|
1811
|
+
const startExclusive = dateRange?.startExclusive ?? false;
|
|
1812
|
+
const endExclusive = dateRange?.endExclusive ?? false;
|
|
1813
|
+
const startOp = startExclusive ? "gt" : "gte";
|
|
1814
|
+
const endOp = endExclusive ? "lt" : "lte";
|
|
1815
|
+
if (startIso && endIso) {
|
|
1816
|
+
query = query.between({ createdAt: startIso }, { createdAt: endIso });
|
|
1817
|
+
if (startExclusive || endExclusive) {
|
|
1818
|
+
query = query.where(({ createdAt }, { gt, lt }) => {
|
|
1819
|
+
if (startExclusive && endExclusive) {
|
|
1820
|
+
return `${gt(createdAt, startIso)} AND ${lt(createdAt, endIso)}`;
|
|
1821
|
+
}
|
|
1822
|
+
if (startExclusive) {
|
|
1823
|
+
return gt(createdAt, startIso);
|
|
1824
|
+
}
|
|
1825
|
+
return lt(createdAt, endIso);
|
|
1826
|
+
});
|
|
1827
|
+
}
|
|
1828
|
+
} else if (startIso) {
|
|
1829
|
+
query = query[startOp]({ createdAt: startIso });
|
|
1830
|
+
} else if (endIso) {
|
|
1831
|
+
query = query[endOp]({ createdAt: endIso });
|
|
1819
1832
|
}
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1833
|
+
if (resourceId) {
|
|
1834
|
+
query = query.where(({ resourceId: rid }, { eq }) => eq(rid, resourceId));
|
|
1835
|
+
}
|
|
1836
|
+
return query;
|
|
1837
|
+
};
|
|
1838
|
+
let paginatedMessages = [];
|
|
1839
|
+
let total = 0;
|
|
1840
|
+
const filteredMessageIds = /* @__PURE__ */ new Set();
|
|
1841
|
+
if (threadIds.length > 1) {
|
|
1842
|
+
const threadResults = await Promise.all(
|
|
1843
|
+
threadIds.map(async (tid) => {
|
|
1844
|
+
const q = applyQueryFilters(
|
|
1845
|
+
this.service.entities.message.query.byThread({ entity: "message", threadId: tid })
|
|
1846
|
+
);
|
|
1847
|
+
const countResult = await q.go({ pages: "all", attributes: ["id"] });
|
|
1848
|
+
const results = await q.go({ pages: "all", order });
|
|
1849
|
+
return { ids: countResult.data.map((item) => item.id), messages: parseQueryMessages(results.data) };
|
|
1850
|
+
})
|
|
1851
|
+
);
|
|
1852
|
+
for (const r of threadResults) {
|
|
1853
|
+
for (const id of r.ids) filteredMessageIds.add(id);
|
|
1854
|
+
}
|
|
1855
|
+
total = threadResults.reduce((sum, r) => sum + r.ids.length, 0);
|
|
1856
|
+
const merged = threadResults.flatMap((r) => r.messages);
|
|
1857
|
+
const sorted = this._sortMessages(merged, field, direction);
|
|
1858
|
+
paginatedMessages = perPageInput === false ? sorted : sorted.slice(offset, offset + perPage);
|
|
1859
|
+
} else {
|
|
1860
|
+
const baseQuery = this.service.entities.message.query.byThread({ entity: "message", threadId: threadIds[0] });
|
|
1861
|
+
const query = applyQueryFilters(baseQuery);
|
|
1862
|
+
const countResult = await query.go({ pages: "all", attributes: ["id"] });
|
|
1863
|
+
total = countResult.data.length;
|
|
1864
|
+
for (const item of countResult.data) filteredMessageIds.add(item.id);
|
|
1865
|
+
if (perPageInput === false) {
|
|
1866
|
+
const results = await query.go({ pages: "all", order });
|
|
1867
|
+
paginatedMessages = parseQueryMessages(results.data);
|
|
1868
|
+
} else {
|
|
1869
|
+
const results = await query.go({ count: offset + perPage, order });
|
|
1870
|
+
paginatedMessages = parseQueryMessages(results.data).slice(offset, offset + perPage);
|
|
1871
|
+
}
|
|
1872
|
+
if (field !== "createdAt") {
|
|
1873
|
+
paginatedMessages = this._sortMessages(paginatedMessages, field, direction);
|
|
1874
|
+
}
|
|
1875
|
+
}
|
|
1876
|
+
if (total === 0 && paginatedMessages.length === 0 && (!include || include.length === 0)) {
|
|
1826
1877
|
return {
|
|
1827
1878
|
messages: [],
|
|
1828
1879
|
total: 0,
|
|
@@ -1845,12 +1896,11 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
|
|
|
1845
1896
|
const list = new agent.MessageList().add(paginatedMessages, "memory");
|
|
1846
1897
|
let finalMessages = list.get.all.db();
|
|
1847
1898
|
finalMessages = this._sortMessages(finalMessages, field, direction);
|
|
1848
|
-
const
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
}
|
|
1899
|
+
const returnedFilteredMessageIds = new Set(
|
|
1900
|
+
finalMessages.filter((m) => filteredMessageIds.has(m.id)).map((m) => m.id)
|
|
1901
|
+
);
|
|
1902
|
+
const allFilteredMessagesReturned = returnedFilteredMessageIds.size >= total;
|
|
1903
|
+
const hasMore = perPageInput !== false && !allFilteredMessagesReturned && offset + perPage < total;
|
|
1854
1904
|
return {
|
|
1855
1905
|
messages: finalMessages,
|
|
1856
1906
|
total,
|
|
@@ -2055,43 +2105,29 @@ var MemoryStorageDynamoDB = class extends storage.MemoryStorage {
|
|
|
2055
2105
|
const targetMap = /* @__PURE__ */ new Map();
|
|
2056
2106
|
for (const { id, data } of targetResults) {
|
|
2057
2107
|
if (data) {
|
|
2058
|
-
|
|
2108
|
+
const createdAt = typeof data.createdAt === "string" ? data.createdAt : new Date(data.createdAt).toISOString();
|
|
2109
|
+
targetMap.set(id, { threadId: data.threadId, createdAt });
|
|
2059
2110
|
}
|
|
2060
2111
|
}
|
|
2061
2112
|
if (targetMap.size === 0) return [];
|
|
2062
|
-
const
|
|
2063
|
-
|
|
2064
|
-
await Promise.all(
|
|
2065
|
-
uniqueThreadIds.map(async (threadId) => {
|
|
2066
|
-
try {
|
|
2067
|
-
const query = this.service.entities.message.query.byThread({ entity: "message", threadId });
|
|
2068
|
-
const results = await query.go();
|
|
2069
|
-
const messages = results.data.map((data) => this.parseMessageData(data)).filter(
|
|
2070
|
-
(msg) => "content" in msg && typeof msg.content === "object"
|
|
2071
|
-
);
|
|
2072
|
-
messages.sort((a, b) => {
|
|
2073
|
-
const timeA = a.createdAt.getTime();
|
|
2074
|
-
const timeB = b.createdAt.getTime();
|
|
2075
|
-
if (timeA === timeB) return a.id.localeCompare(b.id);
|
|
2076
|
-
return timeA - timeB;
|
|
2077
|
-
});
|
|
2078
|
-
threadCache.set(threadId, messages);
|
|
2079
|
-
} catch {
|
|
2080
|
-
}
|
|
2081
|
-
})
|
|
2113
|
+
const parseQueryMessages = (data) => data.map((item) => this.parseMessageData(item)).filter(
|
|
2114
|
+
(msg) => "content" in msg && typeof msg.content === "object"
|
|
2082
2115
|
);
|
|
2083
2116
|
const includeMessages = [];
|
|
2084
2117
|
for (const includeItem of include) {
|
|
2085
2118
|
const { id, withPreviousMessages = 0, withNextMessages = 0 } = includeItem;
|
|
2086
2119
|
const target = targetMap.get(id);
|
|
2087
2120
|
if (!target) continue;
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2121
|
+
try {
|
|
2122
|
+
const prevResult = await this.service.entities.message.query.byThread({ entity: "message", threadId: target.threadId }).lte({ createdAt: target.createdAt }).go({ order: "desc", count: withPreviousMessages + 1 });
|
|
2123
|
+
const prevMessages = parseQueryMessages(prevResult.data).reverse();
|
|
2124
|
+
includeMessages.push(...prevMessages);
|
|
2125
|
+
if (withNextMessages > 0) {
|
|
2126
|
+
const nextResult = await this.service.entities.message.query.byThread({ entity: "message", threadId: target.threadId }).gt({ createdAt: target.createdAt }).go({ order: "asc", count: withNextMessages });
|
|
2127
|
+
includeMessages.push(...parseQueryMessages(nextResult.data));
|
|
2128
|
+
}
|
|
2129
|
+
} catch {
|
|
2130
|
+
}
|
|
2095
2131
|
}
|
|
2096
2132
|
const seen = /* @__PURE__ */ new Set();
|
|
2097
2133
|
return includeMessages.filter((msg) => {
|