@mastra/cloudflare 1.2.2 → 1.2.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 CHANGED
@@ -1,5 +1,23 @@
1
1
  # @mastra/cloudflare
2
2
 
3
+ ## 1.2.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Improved semantic recall performance for large message histories. Semantic recall no longer loads entire threads when only the recalled messages are needed, eliminating delays that previously scaled with total message count. (Fixes #11702) ([#14022](https://github.com/mastra-ai/mastra/pull/14022))
8
+
9
+ - Updated dependencies [[`4f71b43`](https://github.com/mastra-ai/mastra/commit/4f71b436a4a6b8839842d8da47b57b84509af56c), [`a070277`](https://github.com/mastra-ai/mastra/commit/a07027766ce195ba74d0783116d894cbab25d44c), [`b628b91`](https://github.com/mastra-ai/mastra/commit/b628b9128b372c0f54214d902b07279f03443900), [`332c014`](https://github.com/mastra-ai/mastra/commit/332c014e076b81edf7fe45b58205882726415e90), [`6b63153`](https://github.com/mastra-ai/mastra/commit/6b63153878ea841c0f4ce632ba66bb33e57e9c1b), [`4246e34`](https://github.com/mastra-ai/mastra/commit/4246e34cec9c26636d0965942268e6d07c346671), [`b8837ee`](https://github.com/mastra-ai/mastra/commit/b8837ee77e2e84197609762bfabd8b3da326d30c), [`866cc2c`](https://github.com/mastra-ai/mastra/commit/866cc2cb1f0e3b314afab5194f69477fada745d1), [`5d950f7`](https://github.com/mastra-ai/mastra/commit/5d950f7bf426a215a1808f0abef7de5c8336ba1c), [`28c85b1`](https://github.com/mastra-ai/mastra/commit/28c85b184fc32b40f7f160483c982da6d388ecbd), [`e9a08fb`](https://github.com/mastra-ai/mastra/commit/e9a08fbef1ada7e50e961e2f54f55e8c10b4a45c), [`1d0a8a8`](https://github.com/mastra-ai/mastra/commit/1d0a8a8acf33203d5744fc429b090ad8598aa8ed), [`631ffd8`](https://github.com/mastra-ai/mastra/commit/631ffd82fed108648b448b28e6a90e38c5f53bf5), [`6bcbf8a`](https://github.com/mastra-ai/mastra/commit/6bcbf8a6774d5a53b21d61db8a45ce2593ca1616), [`aae2295`](https://github.com/mastra-ai/mastra/commit/aae2295838a2d329ad6640829e87934790ffe5b8), [`aa61f29`](https://github.com/mastra-ai/mastra/commit/aa61f29ff8095ce46a4ae16e46c4d8c79b2b685b), [`7ff3714`](https://github.com/mastra-ai/mastra/commit/7ff37148515439bb3be009a60e02c3e363299760), [`18c3a90`](https://github.com/mastra-ai/mastra/commit/18c3a90c9e48cf69500e308affeb8eba5860b2af), [`41d79a1`](https://github.com/mastra-ai/mastra/commit/41d79a14bd8cb6de1e2565fd0a04786bae2f211b), [`f35487b`](https://github.com/mastra-ai/mastra/commit/f35487bb2d46c636e22aa71d90025613ae38235a), [`6dc2192`](https://github.com/mastra-ai/mastra/commit/6dc21921aef0f0efab15cd0805fa3d18f277a76f), [`eeb3a3f`](https://github.com/mastra-ai/mastra/commit/eeb3a3f43aca10cf49479eed2a84b7d9ecea02ba), [`e673376`](https://github.com/mastra-ai/mastra/commit/e6733763ad1321aa7e5ae15096b9c2104f93b1f3), [`05f8d90`](https://github.com/mastra-ai/mastra/commit/05f8d9009290ce6aa03428b3add635268615db85), [`b2204c9`](https://github.com/mastra-ai/mastra/commit/b2204c98a42848bbfb6f0440f005dc2b6354f1cd), [`a1bf1e3`](https://github.com/mastra-ai/mastra/commit/a1bf1e385ed4c0ef6f11b56c5887442970d127f2), [`b6f647a`](https://github.com/mastra-ai/mastra/commit/b6f647ae2388e091f366581595feb957e37d5b40), [`0c57b8b`](https://github.com/mastra-ai/mastra/commit/0c57b8b0a69a97b5a4ae3f79be6c610f29f3cf7b), [`b081f27`](https://github.com/mastra-ai/mastra/commit/b081f272cf411716e1d6bd72ceac4bcee2657b19), [`4b8da97`](https://github.com/mastra-ai/mastra/commit/4b8da97a5ce306e97869df6c39535d9069e563db), [`0c09eac`](https://github.com/mastra-ai/mastra/commit/0c09eacb1926f64cfdc9ae5c6d63385cf8c9f72c), [`6b9b93d`](https://github.com/mastra-ai/mastra/commit/6b9b93d6f459d1ba6e36f163abf62a085ddb3d64), [`31b6067`](https://github.com/mastra-ai/mastra/commit/31b6067d0cc3ab10e1b29c36147f3b5266bc714a), [`797ac42`](https://github.com/mastra-ai/mastra/commit/797ac4276de231ad2d694d9aeca75980f6cd0419), [`0bc289e`](https://github.com/mastra-ai/mastra/commit/0bc289e2d476bf46c5b91c21969e8d0c6864691c), [`9b75a06`](https://github.com/mastra-ai/mastra/commit/9b75a06e53ebb0b950ba7c1e83a0142047185f46), [`4c3a1b1`](https://github.com/mastra-ai/mastra/commit/4c3a1b122ea083e003d71092f30f3b31680b01c0), [`256df35`](https://github.com/mastra-ai/mastra/commit/256df3571d62beb3ad4971faa432927cc140e603), [`85cc3b3`](https://github.com/mastra-ai/mastra/commit/85cc3b3b6f32ae4b083c26498f50d5b250ba944b), [`97ea28c`](https://github.com/mastra-ai/mastra/commit/97ea28c746e9e4147d56047bbb1c4a92417a3fec), [`d567299`](https://github.com/mastra-ai/mastra/commit/d567299cf81e02bd9d5221d4bc05967d6c224161), [`716ffe6`](https://github.com/mastra-ai/mastra/commit/716ffe68bed81f7c2690bc8581b9e140f7bf1c3d), [`8296332`](https://github.com/mastra-ai/mastra/commit/8296332de21c16e3dfc3d0b2d615720a6dc88f2f), [`4df2116`](https://github.com/mastra-ai/mastra/commit/4df211619dd922c047d396ca41cd7027c8c4c8e7), [`2219c1a`](https://github.com/mastra-ai/mastra/commit/2219c1acbd21da116da877f0036ffb985a9dd5a3), [`17c4145`](https://github.com/mastra-ai/mastra/commit/17c4145166099354545582335b5252bdfdfd908b)]:
10
+ - @mastra/core@1.11.0
11
+
12
+ ## 1.2.3-alpha.0
13
+
14
+ ### Patch Changes
15
+
16
+ - Improved semantic recall performance for large message histories. Semantic recall no longer loads entire threads when only the recalled messages are needed, eliminating delays that previously scaled with total message count. (Fixes #11702) ([#14022](https://github.com/mastra-ai/mastra/pull/14022))
17
+
18
+ - Updated dependencies [[`4f71b43`](https://github.com/mastra-ai/mastra/commit/4f71b436a4a6b8839842d8da47b57b84509af56c), [`a070277`](https://github.com/mastra-ai/mastra/commit/a07027766ce195ba74d0783116d894cbab25d44c), [`b628b91`](https://github.com/mastra-ai/mastra/commit/b628b9128b372c0f54214d902b07279f03443900), [`332c014`](https://github.com/mastra-ai/mastra/commit/332c014e076b81edf7fe45b58205882726415e90), [`6b63153`](https://github.com/mastra-ai/mastra/commit/6b63153878ea841c0f4ce632ba66bb33e57e9c1b), [`4246e34`](https://github.com/mastra-ai/mastra/commit/4246e34cec9c26636d0965942268e6d07c346671), [`b8837ee`](https://github.com/mastra-ai/mastra/commit/b8837ee77e2e84197609762bfabd8b3da326d30c), [`5d950f7`](https://github.com/mastra-ai/mastra/commit/5d950f7bf426a215a1808f0abef7de5c8336ba1c), [`28c85b1`](https://github.com/mastra-ai/mastra/commit/28c85b184fc32b40f7f160483c982da6d388ecbd), [`e9a08fb`](https://github.com/mastra-ai/mastra/commit/e9a08fbef1ada7e50e961e2f54f55e8c10b4a45c), [`631ffd8`](https://github.com/mastra-ai/mastra/commit/631ffd82fed108648b448b28e6a90e38c5f53bf5), [`aae2295`](https://github.com/mastra-ai/mastra/commit/aae2295838a2d329ad6640829e87934790ffe5b8), [`aa61f29`](https://github.com/mastra-ai/mastra/commit/aa61f29ff8095ce46a4ae16e46c4d8c79b2b685b), [`7ff3714`](https://github.com/mastra-ai/mastra/commit/7ff37148515439bb3be009a60e02c3e363299760), [`41d79a1`](https://github.com/mastra-ai/mastra/commit/41d79a14bd8cb6de1e2565fd0a04786bae2f211b), [`e673376`](https://github.com/mastra-ai/mastra/commit/e6733763ad1321aa7e5ae15096b9c2104f93b1f3), [`b2204c9`](https://github.com/mastra-ai/mastra/commit/b2204c98a42848bbfb6f0440f005dc2b6354f1cd), [`a1bf1e3`](https://github.com/mastra-ai/mastra/commit/a1bf1e385ed4c0ef6f11b56c5887442970d127f2), [`b6f647a`](https://github.com/mastra-ai/mastra/commit/b6f647ae2388e091f366581595feb957e37d5b40), [`0c57b8b`](https://github.com/mastra-ai/mastra/commit/0c57b8b0a69a97b5a4ae3f79be6c610f29f3cf7b), [`b081f27`](https://github.com/mastra-ai/mastra/commit/b081f272cf411716e1d6bd72ceac4bcee2657b19), [`0c09eac`](https://github.com/mastra-ai/mastra/commit/0c09eacb1926f64cfdc9ae5c6d63385cf8c9f72c), [`6b9b93d`](https://github.com/mastra-ai/mastra/commit/6b9b93d6f459d1ba6e36f163abf62a085ddb3d64), [`31b6067`](https://github.com/mastra-ai/mastra/commit/31b6067d0cc3ab10e1b29c36147f3b5266bc714a), [`797ac42`](https://github.com/mastra-ai/mastra/commit/797ac4276de231ad2d694d9aeca75980f6cd0419), [`0bc289e`](https://github.com/mastra-ai/mastra/commit/0bc289e2d476bf46c5b91c21969e8d0c6864691c), [`9b75a06`](https://github.com/mastra-ai/mastra/commit/9b75a06e53ebb0b950ba7c1e83a0142047185f46), [`4c3a1b1`](https://github.com/mastra-ai/mastra/commit/4c3a1b122ea083e003d71092f30f3b31680b01c0), [`85cc3b3`](https://github.com/mastra-ai/mastra/commit/85cc3b3b6f32ae4b083c26498f50d5b250ba944b), [`97ea28c`](https://github.com/mastra-ai/mastra/commit/97ea28c746e9e4147d56047bbb1c4a92417a3fec), [`d567299`](https://github.com/mastra-ai/mastra/commit/d567299cf81e02bd9d5221d4bc05967d6c224161), [`716ffe6`](https://github.com/mastra-ai/mastra/commit/716ffe68bed81f7c2690bc8581b9e140f7bf1c3d), [`8296332`](https://github.com/mastra-ai/mastra/commit/8296332de21c16e3dfc3d0b2d615720a6dc88f2f), [`4df2116`](https://github.com/mastra-ai/mastra/commit/4df211619dd922c047d396ca41cd7027c8c4c8e7), [`2219c1a`](https://github.com/mastra-ai/mastra/commit/2219c1acbd21da116da877f0036ffb985a9dd5a3), [`17c4145`](https://github.com/mastra-ai/mastra/commit/17c4145166099354545582335b5252bdfdfd908b)]:
19
+ - @mastra/core@1.11.0-alpha.0
20
+
3
21
  ## 1.2.2
4
22
 
5
23
  ### Patch Changes
@@ -3,7 +3,7 @@ name: mastra-cloudflare
3
3
  description: Documentation for @mastra/cloudflare. Use when working with @mastra/cloudflare APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/cloudflare"
6
- version: "1.2.2"
6
+ version: "1.2.3"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -16,7 +16,7 @@ Read the individual reference documents for detailed explanations and code examp
16
16
 
17
17
  ### Reference
18
18
 
19
- - [Reference: Cloudflare Storage](references/reference-storage-cloudflare.md) - Documentation for the Cloudflare KV storage implementation in Mastra.
19
+ - [Reference: Cloudflare storage](references/reference-storage-cloudflare.md) - Documentation for the Cloudflare KV storage implementation in Mastra.
20
20
 
21
21
 
22
22
  Read [assets/SOURCE_MAP.json](assets/SOURCE_MAP.json) for source code references.
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.2.2",
2
+ "version": "1.2.3",
3
3
  "package": "@mastra/cloudflare",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -1,8 +1,8 @@
1
- # Cloudflare Storage
1
+ # Cloudflare storage
2
2
 
3
3
  The Cloudflare KV storage implementation provides a globally distributed, serverless key-value store solution using Cloudflare Workers KV.
4
4
 
5
- > **Observability Not Supported:** Cloudflare KV storage **does not support the observability domain**. Traces from the `DefaultExporter` cannot be persisted to KV, and Mastra Studio's observability features won't work with Cloudflare KV 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 or PostgreSQL.
5
+ > **Observability Not Supported:** Cloudflare KV storage **doesn't support the observability domain**. Traces from the `DefaultExporter` can't be persisted to KV, and Mastra Studio's observability features won't work with Cloudflare KV 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 or PostgreSQL.
6
6
 
7
7
  ## Installation
8
8
 
@@ -57,19 +57,19 @@ const storageRest = new CloudflareStore({
57
57
 
58
58
  ## Parameters
59
59
 
60
- **id:** (`string`): Unique identifier for this storage instance.
60
+ **id** (`string`): Unique identifier for this storage instance.
61
61
 
62
- **bindings?:** (`Record<string, KVNamespace>`): Cloudflare Workers KV bindings (for Workers runtime)
62
+ **bindings** (`Record<string, KVNamespace>`): Cloudflare Workers KV bindings (for Workers runtime)
63
63
 
64
- **accountId?:** (`string`): Cloudflare Account ID (for REST API)
64
+ **accountId** (`string`): Cloudflare Account ID (for REST API)
65
65
 
66
- **apiToken?:** (`string`): Cloudflare API Token (for REST API)
66
+ **apiToken** (`string`): Cloudflare API Token (for REST API)
67
67
 
68
- **namespacePrefix?:** (`string`): Optional prefix for all namespace names (useful for environment isolation)
68
+ **namespacePrefix** (`string`): Optional prefix for all namespace names (useful for environment isolation)
69
69
 
70
- **keyPrefix?:** (`string`): Optional prefix for all keys (useful for environment isolation)
70
+ **keyPrefix** (`string`): Optional prefix for all keys (useful for environment isolation)
71
71
 
72
- ### Additional Notes
72
+ ### Additional notes
73
73
 
74
74
  ### Schema Management
75
75
 
package/dist/index.cjs CHANGED
@@ -1034,6 +1034,22 @@ var MemoryStorageCloudflare = class extends storage.MemoryStorage {
1034
1034
  * @param include - Array of message IDs to include, optionally with context windows
1035
1035
  * @param messageIds - Set to accumulate the message IDs that should be fetched
1036
1036
  */
1037
+ _sortMessages(messages, field, direction) {
1038
+ return messages.sort((a, b) => {
1039
+ const isDateField = field === "createdAt" || field === "updatedAt";
1040
+ const aVal = isDateField ? new Date(a[field]).getTime() : a[field];
1041
+ const bVal = isDateField ? new Date(b[field]).getTime() : b[field];
1042
+ if (aVal == null && bVal == null) return a.id.localeCompare(b.id);
1043
+ if (aVal == null) return 1;
1044
+ if (bVal == null) return -1;
1045
+ if (typeof aVal === "number" && typeof bVal === "number") {
1046
+ const cmp2 = direction === "ASC" ? aVal - bVal : bVal - aVal;
1047
+ return cmp2 !== 0 ? cmp2 : a.id.localeCompare(b.id);
1048
+ }
1049
+ const cmp = direction === "ASC" ? String(aVal).localeCompare(String(bVal)) : String(bVal).localeCompare(String(aVal));
1050
+ return cmp !== 0 ? cmp : a.id.localeCompare(b.id);
1051
+ });
1052
+ }
1037
1053
  async getIncludedMessagesWithContext(include, messageIds) {
1038
1054
  await Promise.all(
1039
1055
  include.map(async (item) => {
@@ -1192,6 +1208,26 @@ var MemoryStorageCloudflare = class extends storage.MemoryStorage {
1192
1208
  );
1193
1209
  }
1194
1210
  const { field, direction } = this.parseOrderBy(orderBy, "ASC");
1211
+ if (perPage === 0 && include && include.length > 0) {
1212
+ const includedMessageIds = /* @__PURE__ */ new Set();
1213
+ await this.getIncludedMessagesWithContext(include, includedMessageIds);
1214
+ const includedMessages2 = await this.fetchAndParseMessagesFromMultipleThreads(
1215
+ Array.from(includedMessageIds),
1216
+ include,
1217
+ void 0
1218
+ );
1219
+ const list2 = new agent.MessageList().add(includedMessages2, "memory");
1220
+ return {
1221
+ messages: this._sortMessages(list2.get.all.db(), field, direction),
1222
+ total: 0,
1223
+ page,
1224
+ perPage: perPageForResponse,
1225
+ hasMore: false
1226
+ };
1227
+ }
1228
+ if (perPage === 0 && (!include || include.length === 0)) {
1229
+ return { messages: [], total: 0, page, perPage: perPageForResponse, hasMore: false };
1230
+ }
1195
1231
  const threadMessageIds = /* @__PURE__ */ new Set();
1196
1232
  for (const tid of threadIds) {
1197
1233
  try {
@@ -1216,15 +1252,6 @@ var MemoryStorageCloudflare = class extends storage.MemoryStorage {
1216
1252
  filter?.dateRange
1217
1253
  );
1218
1254
  const total = filteredThreadMessages.length;
1219
- if (perPage === 0 && (!include || include.length === 0)) {
1220
- return {
1221
- messages: [],
1222
- total,
1223
- page,
1224
- perPage: perPageForResponse,
1225
- hasMore: offset < total
1226
- };
1227
- }
1228
1255
  filteredThreadMessages.sort((a, b) => {
1229
1256
  const timeA = new Date(a.createdAt).getTime();
1230
1257
  const timeB = new Date(b.createdAt).getTime();
@@ -1296,21 +1323,7 @@ var MemoryStorageCloudflare = class extends storage.MemoryStorage {
1296
1323
  prepared,
1297
1324
  "memory"
1298
1325
  );
1299
- let finalMessages = list.get.all.db();
1300
- finalMessages = finalMessages.sort((a, b) => {
1301
- const isDateField = field === "createdAt" || field === "updatedAt";
1302
- const aVal = isDateField ? new Date(a[field]).getTime() : a[field];
1303
- const bVal = isDateField ? new Date(b[field]).getTime() : b[field];
1304
- if (aVal == null && bVal == null) return a.id.localeCompare(b.id);
1305
- if (aVal == null) return 1;
1306
- if (bVal == null) return -1;
1307
- if (typeof aVal === "number" && typeof bVal === "number") {
1308
- const cmp2 = direction === "ASC" ? aVal - bVal : bVal - aVal;
1309
- return cmp2 !== 0 ? cmp2 : a.id.localeCompare(b.id);
1310
- }
1311
- const cmp = direction === "ASC" ? String(aVal).localeCompare(String(bVal)) : String(bVal).localeCompare(String(aVal));
1312
- return cmp !== 0 ? cmp : a.id.localeCompare(b.id);
1313
- });
1326
+ const finalMessages = this._sortMessages(list.get.all.db(), field, direction);
1314
1327
  const threadIdSet = new Set(threadIds);
1315
1328
  const returnedThreadMessageIds = new Set(
1316
1329
  finalMessages.filter((m) => m.threadId && threadIdSet.has(m.threadId)).map((m) => m.id)