@mastra/cloudflare 1.0.0-beta.2 → 1.0.0-beta.4
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 +56 -0
- package/dist/index.cjs +105 -63
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +106 -64
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +36 -0
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/domains/operations/index.d.ts.map +1 -1
- package/dist/storage/domains/scores/index.d.ts.map +1 -1
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/types.d.ts +28 -5
- package/dist/storage/types.d.ts.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,61 @@
|
|
|
1
1
|
# @mastra/cloudflare
|
|
2
2
|
|
|
3
|
+
## 1.0.0-beta.4
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Add `disableInit` option to all storage adapters ([#10851](https://github.com/mastra-ai/mastra/pull/10851))
|
|
8
|
+
|
|
9
|
+
Adds a new `disableInit` config option to all storage providers that allows users to disable automatic table creation/migrations at runtime. This is useful for CI/CD pipelines where you want to run migrations during deployment with elevated credentials, then run the application with `disableInit: true` so it doesn't attempt schema changes at runtime.
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
// CI/CD script - run migrations
|
|
13
|
+
const storage = new PostgresStore({
|
|
14
|
+
connectionString: DATABASE_URL,
|
|
15
|
+
id: 'pg-storage',
|
|
16
|
+
});
|
|
17
|
+
await storage.init();
|
|
18
|
+
|
|
19
|
+
// Runtime - skip auto-init
|
|
20
|
+
const storage = new PostgresStore({
|
|
21
|
+
connectionString: DATABASE_URL,
|
|
22
|
+
id: 'pg-storage',
|
|
23
|
+
disableInit: true,
|
|
24
|
+
});
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- Standardize error IDs across all storage and vector stores using centralized helper functions (`createStorageErrorId` and `createVectorErrorId`). This ensures consistent error ID patterns (`MASTRA_STORAGE_{STORE}_{OPERATION}_{STATUS}` and `MASTRA_VECTOR_{STORE}_{OPERATION}_{STATUS}`) across the codebase for better error tracking and debugging. ([#10913](https://github.com/mastra-ai/mastra/pull/10913))
|
|
30
|
+
|
|
31
|
+
- Updated dependencies [[`3076c67`](https://github.com/mastra-ai/mastra/commit/3076c6778b18988ae7d5c4c5c466366974b2d63f), [`85d7ee1`](https://github.com/mastra-ai/mastra/commit/85d7ee18ff4e14d625a8a30ec6656bb49804989b), [`c6c1092`](https://github.com/mastra-ai/mastra/commit/c6c1092f8fbf76109303f69e000e96fd1960c4ce), [`81dc110`](https://github.com/mastra-ai/mastra/commit/81dc11008d147cf5bdc8996ead1aa61dbdebb6fc), [`7aedb74`](https://github.com/mastra-ai/mastra/commit/7aedb74883adf66af38e270e4068fd42e7a37036), [`8f02d80`](https://github.com/mastra-ai/mastra/commit/8f02d800777397e4b45d7f1ad041988a8b0c6630), [`d7aad50`](https://github.com/mastra-ai/mastra/commit/d7aad501ce61646b76b4b511e558ac4eea9884d0), [`ce0a73a`](https://github.com/mastra-ai/mastra/commit/ce0a73abeaa75b10ca38f9e40a255a645d50ebfb), [`a02e542`](https://github.com/mastra-ai/mastra/commit/a02e542d23179bad250b044b17ff023caa61739f), [`a372c64`](https://github.com/mastra-ai/mastra/commit/a372c640ad1fd12e8f0613cebdc682fc156b4d95), [`8846867`](https://github.com/mastra-ai/mastra/commit/8846867ffa9a3746767618e314bebac08eb77d87), [`42a42cf`](https://github.com/mastra-ai/mastra/commit/42a42cf3132b9786feecbb8c13c583dce5b0e198), [`ae08bf0`](https://github.com/mastra-ai/mastra/commit/ae08bf0ebc6a4e4da992b711c4a389c32ba84cf4), [`21735a7`](https://github.com/mastra-ai/mastra/commit/21735a7ef306963554a69a89b44f06c3bcd85141), [`1d877b8`](https://github.com/mastra-ai/mastra/commit/1d877b8d7b536a251c1a7a18db7ddcf4f68d6f8b)]:
|
|
32
|
+
- @mastra/core@1.0.0-beta.7
|
|
33
|
+
|
|
34
|
+
## 1.0.0-beta.3
|
|
35
|
+
|
|
36
|
+
### Patch Changes
|
|
37
|
+
|
|
38
|
+
- feat(storage): support querying messages from multiple threads ([#10663](https://github.com/mastra-ai/mastra/pull/10663))
|
|
39
|
+
- Fixed TypeScript errors where `threadId: string | string[]` was being passed to places expecting `Scalar` type
|
|
40
|
+
- Added proper multi-thread support for `listMessages` across all adapters when `threadId` is an array
|
|
41
|
+
- Updated `_getIncludedMessages` to look up message threadId by ID (since message IDs are globally unique)
|
|
42
|
+
- **upstash**: Added `msg-idx:{messageId}` index for O(1) message lookups (backwards compatible with fallback to scan for old messages, with automatic backfill)
|
|
43
|
+
|
|
44
|
+
- fix: ensure score responses match saved payloads for Mastra Stores. ([#10557](https://github.com/mastra-ai/mastra/pull/10557))
|
|
45
|
+
|
|
46
|
+
- Unify transformScoreRow functions across storage adapters ([#10648](https://github.com/mastra-ai/mastra/pull/10648))
|
|
47
|
+
|
|
48
|
+
Added a unified `transformScoreRow` function in `@mastra/core/storage` that provides schema-driven row transformation for score data. This eliminates code duplication across 10 storage adapters while maintaining store-specific behavior through configurable options:
|
|
49
|
+
- `preferredTimestampFields`: Preferred source fields for timestamps (PostgreSQL, Cloudflare D1)
|
|
50
|
+
- `convertTimestamps`: Convert timestamp strings to Date objects (MSSQL, MongoDB, ClickHouse)
|
|
51
|
+
- `nullValuePattern`: Skip values matching pattern (ClickHouse's `'_null_'`)
|
|
52
|
+
- `fieldMappings`: Map source column names to schema fields (LibSQL's `additionalLLMContext`)
|
|
53
|
+
|
|
54
|
+
Each store adapter now uses the unified function with appropriate options, reducing ~200 lines of duplicate transformation logic while ensuring consistent behavior across all storage backends.
|
|
55
|
+
|
|
56
|
+
- Updated dependencies [[`ac0d2f4`](https://github.com/mastra-ai/mastra/commit/ac0d2f4ff8831f72c1c66c2be809706d17f65789), [`1a0d3fc`](https://github.com/mastra-ai/mastra/commit/1a0d3fc811482c9c376cdf79ee615c23bae9b2d6), [`85a628b`](https://github.com/mastra-ai/mastra/commit/85a628b1224a8f64cd82ea7f033774bf22df7a7e), [`c237233`](https://github.com/mastra-ai/mastra/commit/c23723399ccedf7f5744b3f40997b79246bfbe64), [`15f9e21`](https://github.com/mastra-ai/mastra/commit/15f9e216177201ea6e3f6d0bfb063fcc0953444f), [`ff94dea`](https://github.com/mastra-ai/mastra/commit/ff94dea935f4e34545c63bcb6c29804732698809), [`5b2ff46`](https://github.com/mastra-ai/mastra/commit/5b2ff4651df70c146523a7fca773f8eb0a2272f8), [`db41688`](https://github.com/mastra-ai/mastra/commit/db4168806d007417e2e60b4f68656dca4e5f40c9), [`5ca599d`](https://github.com/mastra-ai/mastra/commit/5ca599d0bb59a1595f19f58473fcd67cc71cef58), [`bff1145`](https://github.com/mastra-ai/mastra/commit/bff114556b3cbadad9b2768488708f8ad0e91475), [`5c8ca24`](https://github.com/mastra-ai/mastra/commit/5c8ca247094e0cc2cdbd7137822fb47241f86e77), [`e191844`](https://github.com/mastra-ai/mastra/commit/e1918444ca3f80e82feef1dad506cd4ec6e2875f), [`22553f1`](https://github.com/mastra-ai/mastra/commit/22553f11c63ee5e966a9c034a349822249584691), [`7237163`](https://github.com/mastra-ai/mastra/commit/72371635dbf96a87df4b073cc48fc655afbdce3d), [`2500740`](https://github.com/mastra-ai/mastra/commit/2500740ea23da067d6e50ec71c625ab3ce275e64), [`873ecbb`](https://github.com/mastra-ai/mastra/commit/873ecbb517586aa17d2f1e99283755b3ebb2863f), [`4f9bbe5`](https://github.com/mastra-ai/mastra/commit/4f9bbe5968f42c86f4930b8193de3c3c17e5bd36), [`02e51fe`](https://github.com/mastra-ai/mastra/commit/02e51feddb3d4155cfbcc42624fd0d0970d032c0), [`8f3fa3a`](https://github.com/mastra-ai/mastra/commit/8f3fa3a652bb77da092f913ec51ae46e3a7e27dc), [`cd29ad2`](https://github.com/mastra-ai/mastra/commit/cd29ad23a255534e8191f249593849ed29160886), [`bdf4d8c`](https://github.com/mastra-ai/mastra/commit/bdf4d8cdc656d8a2c21d81834bfa3bfa70f56c16), [`854e3da`](https://github.com/mastra-ai/mastra/commit/854e3dad5daac17a91a20986399d3a51f54bf68b), [`ce18d38`](https://github.com/mastra-ai/mastra/commit/ce18d38678c65870350d123955014a8432075fd9), [`cccf9c8`](https://github.com/mastra-ai/mastra/commit/cccf9c8b2d2dfc1a5e63919395b83d78c89682a0), [`61a5705`](https://github.com/mastra-ai/mastra/commit/61a570551278b6743e64243b3ce7d73de915ca8a), [`db70a48`](https://github.com/mastra-ai/mastra/commit/db70a48aeeeeb8e5f92007e8ede52c364ce15287), [`f0fdc14`](https://github.com/mastra-ai/mastra/commit/f0fdc14ee233d619266b3d2bbdeea7d25cfc6d13), [`db18bc9`](https://github.com/mastra-ai/mastra/commit/db18bc9c3825e2c1a0ad9a183cc9935f6691bfa1), [`9b37b56`](https://github.com/mastra-ai/mastra/commit/9b37b565e1f2a76c24f728945cc740c2b09be9da), [`41a23c3`](https://github.com/mastra-ai/mastra/commit/41a23c32f9877d71810f37e24930515df2ff7a0f), [`5d171ad`](https://github.com/mastra-ai/mastra/commit/5d171ad9ef340387276b77c2bb3e83e83332d729), [`f03ae60`](https://github.com/mastra-ai/mastra/commit/f03ae60500fe350c9d828621006cdafe1975fdd8), [`d1e74a0`](https://github.com/mastra-ai/mastra/commit/d1e74a0a293866dece31022047f5dbab65a304d0), [`39e7869`](https://github.com/mastra-ai/mastra/commit/39e7869bc7d0ee391077ce291474d8a84eedccff), [`5761926`](https://github.com/mastra-ai/mastra/commit/57619260c4a2cdd598763abbacd90de594c6bc76), [`c900fdd`](https://github.com/mastra-ai/mastra/commit/c900fdd504c41348efdffb205cfe80d48c38fa33), [`604a79f`](https://github.com/mastra-ai/mastra/commit/604a79fecf276e26a54a3fe01bb94e65315d2e0e), [`887f0b4`](https://github.com/mastra-ai/mastra/commit/887f0b4746cdbd7cb7d6b17ac9f82aeb58037ea5), [`2562143`](https://github.com/mastra-ai/mastra/commit/256214336b4faa78646c9c1776612393790d8784), [`ef11a61`](https://github.com/mastra-ai/mastra/commit/ef11a61920fa0ed08a5b7ceedd192875af119749)]:
|
|
57
|
+
- @mastra/core@1.0.0-beta.6
|
|
58
|
+
|
|
3
59
|
## 1.0.0-beta.2
|
|
4
60
|
|
|
5
61
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -45,7 +45,7 @@ var MemoryStorageCloudflare = class extends storage.MemoryStorage {
|
|
|
45
45
|
} catch (error$1) {
|
|
46
46
|
const mastraError = new error.MastraError(
|
|
47
47
|
{
|
|
48
|
-
id: "
|
|
48
|
+
id: storage.createStorageErrorId("CLOUDFLARE", "GET_THREAD_BY_ID", "FAILED"),
|
|
49
49
|
domain: error.ErrorDomain.STORAGE,
|
|
50
50
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
51
51
|
details: {
|
|
@@ -66,7 +66,7 @@ var MemoryStorageCloudflare = class extends storage.MemoryStorage {
|
|
|
66
66
|
if (page < 0) {
|
|
67
67
|
throw new error.MastraError(
|
|
68
68
|
{
|
|
69
|
-
id: "
|
|
69
|
+
id: storage.createStorageErrorId("CLOUDFLARE", "LIST_THREADS_BY_RESOURCE_ID", "INVALID_PAGE"),
|
|
70
70
|
domain: error.ErrorDomain.STORAGE,
|
|
71
71
|
category: error.ErrorCategory.USER,
|
|
72
72
|
details: { page }
|
|
@@ -102,7 +102,7 @@ var MemoryStorageCloudflare = class extends storage.MemoryStorage {
|
|
|
102
102
|
} catch (error$1) {
|
|
103
103
|
throw new error.MastraError(
|
|
104
104
|
{
|
|
105
|
-
id: "
|
|
105
|
+
id: storage.createStorageErrorId("CLOUDFLARE", "LIST_THREADS_BY_RESOURCE_ID", "FAILED"),
|
|
106
106
|
domain: error.ErrorDomain.STORAGE,
|
|
107
107
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
108
108
|
text: "Failed to get threads by resource ID with pagination"
|
|
@@ -118,7 +118,7 @@ var MemoryStorageCloudflare = class extends storage.MemoryStorage {
|
|
|
118
118
|
} catch (error$1) {
|
|
119
119
|
throw new error.MastraError(
|
|
120
120
|
{
|
|
121
|
-
id: "
|
|
121
|
+
id: storage.createStorageErrorId("CLOUDFLARE", "SAVE_THREAD", "FAILED"),
|
|
122
122
|
domain: error.ErrorDomain.STORAGE,
|
|
123
123
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
124
124
|
details: {
|
|
@@ -153,7 +153,7 @@ var MemoryStorageCloudflare = class extends storage.MemoryStorage {
|
|
|
153
153
|
} catch (error$1) {
|
|
154
154
|
throw new error.MastraError(
|
|
155
155
|
{
|
|
156
|
-
id: "
|
|
156
|
+
id: storage.createStorageErrorId("CLOUDFLARE", "UPDATE_THREAD", "FAILED"),
|
|
157
157
|
domain: error.ErrorDomain.STORAGE,
|
|
158
158
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
159
159
|
details: {
|
|
@@ -202,7 +202,7 @@ var MemoryStorageCloudflare = class extends storage.MemoryStorage {
|
|
|
202
202
|
} catch (error$1) {
|
|
203
203
|
throw new error.MastraError(
|
|
204
204
|
{
|
|
205
|
-
id: "
|
|
205
|
+
id: storage.createStorageErrorId("CLOUDFLARE", "DELETE_THREAD", "FAILED"),
|
|
206
206
|
domain: error.ErrorDomain.STORAGE,
|
|
207
207
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
208
208
|
details: {
|
|
@@ -213,6 +213,17 @@ var MemoryStorageCloudflare = class extends storage.MemoryStorage {
|
|
|
213
213
|
);
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
|
+
/**
|
|
217
|
+
* Searches all threads in the KV store to find a message by its ID.
|
|
218
|
+
*
|
|
219
|
+
* **Performance Warning**: This method sequentially scans all threads to locate
|
|
220
|
+
* the message. For stores with many threads, this can result in significant
|
|
221
|
+
* latency and API calls. When possible, callers should provide the `threadId`
|
|
222
|
+
* directly to avoid this full scan.
|
|
223
|
+
*
|
|
224
|
+
* @param messageId - The globally unique message ID to search for
|
|
225
|
+
* @returns The message with its threadId if found, null otherwise
|
|
226
|
+
*/
|
|
216
227
|
async findMessageInAnyThread(messageId) {
|
|
217
228
|
try {
|
|
218
229
|
const prefix = this.operations.namespacePrefix ? `${this.operations.namespacePrefix}:` : "";
|
|
@@ -396,7 +407,7 @@ var MemoryStorageCloudflare = class extends storage.MemoryStorage {
|
|
|
396
407
|
} catch (error$1) {
|
|
397
408
|
throw new error.MastraError(
|
|
398
409
|
{
|
|
399
|
-
id: "
|
|
410
|
+
id: storage.createStorageErrorId("CLOUDFLARE", "SAVE_MESSAGES", "FAILED"),
|
|
400
411
|
domain: error.ErrorDomain.STORAGE,
|
|
401
412
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
402
413
|
details: {
|
|
@@ -416,7 +427,7 @@ var MemoryStorageCloudflare = class extends storage.MemoryStorage {
|
|
|
416
427
|
} catch (error$1) {
|
|
417
428
|
throw new error.MastraError(
|
|
418
429
|
{
|
|
419
|
-
id: "
|
|
430
|
+
id: storage.createStorageErrorId("CLOUDFLARE", "SAVE_MESSAGES", "FAILED"),
|
|
420
431
|
domain: error.ErrorDomain.STORAGE,
|
|
421
432
|
category: error.ErrorCategory.THIRD_PARTY
|
|
422
433
|
},
|
|
@@ -442,10 +453,25 @@ var MemoryStorageCloudflare = class extends storage.MemoryStorage {
|
|
|
442
453
|
async getFullOrder(orderKey) {
|
|
443
454
|
return this.getRange(orderKey, 0, -1);
|
|
444
455
|
}
|
|
445
|
-
|
|
456
|
+
/**
|
|
457
|
+
* Retrieves messages specified in the include array along with their surrounding context.
|
|
458
|
+
*
|
|
459
|
+
* **Performance Note**: When `threadId` is not provided in an include entry, this method
|
|
460
|
+
* must call `findMessageInAnyThread` which sequentially scans all threads in the KV store.
|
|
461
|
+
* For optimal performance, callers should provide `threadId` in include entries when known.
|
|
462
|
+
*
|
|
463
|
+
* @param include - Array of message IDs to include, optionally with context windows
|
|
464
|
+
* @param messageIds - Set to accumulate the message IDs that should be fetched
|
|
465
|
+
*/
|
|
466
|
+
async getIncludedMessagesWithContext(include, messageIds) {
|
|
446
467
|
await Promise.all(
|
|
447
468
|
include.map(async (item) => {
|
|
448
|
-
|
|
469
|
+
let targetThreadId = item.threadId;
|
|
470
|
+
if (!targetThreadId) {
|
|
471
|
+
const foundMessage = await this.findMessageInAnyThread(item.id);
|
|
472
|
+
if (!foundMessage) return;
|
|
473
|
+
targetThreadId = foundMessage.threadId;
|
|
474
|
+
}
|
|
449
475
|
if (!targetThreadId) return;
|
|
450
476
|
const threadMessagesKey = this.getThreadMessagesKey(targetThreadId);
|
|
451
477
|
messageIds.add(item.id);
|
|
@@ -478,6 +504,13 @@ var MemoryStorageCloudflare = class extends storage.MemoryStorage {
|
|
|
478
504
|
this.logger?.debug(`No message order found for thread ${threadId}, skipping latest messages`);
|
|
479
505
|
}
|
|
480
506
|
}
|
|
507
|
+
/**
|
|
508
|
+
* Fetches and parses messages from one or more threads.
|
|
509
|
+
*
|
|
510
|
+
* **Performance Note**: When neither `include` entries with `threadId` nor `targetThreadId`
|
|
511
|
+
* are provided, this method falls back to `findMessageInAnyThread` which scans all threads.
|
|
512
|
+
* For optimal performance, provide `threadId` in include entries or specify `targetThreadId`.
|
|
513
|
+
*/
|
|
481
514
|
async fetchAndParseMessagesFromMultipleThreads(messageIds, include, targetThreadId) {
|
|
482
515
|
const messageIdToThreadId = /* @__PURE__ */ new Map();
|
|
483
516
|
if (include) {
|
|
@@ -519,6 +552,14 @@ var MemoryStorageCloudflare = class extends storage.MemoryStorage {
|
|
|
519
552
|
);
|
|
520
553
|
return messages.filter((msg) => msg !== null);
|
|
521
554
|
}
|
|
555
|
+
/**
|
|
556
|
+
* Retrieves messages by their IDs.
|
|
557
|
+
*
|
|
558
|
+
* **Performance Warning**: This method calls `findMessageInAnyThread` for each message ID,
|
|
559
|
+
* which scans all threads in the KV store. For large numbers of messages or threads,
|
|
560
|
+
* this can result in significant latency. Consider using `listMessages` with specific
|
|
561
|
+
* thread IDs when the thread context is known.
|
|
562
|
+
*/
|
|
522
563
|
async listMessagesById({ messageIds }) {
|
|
523
564
|
if (messageIds.length === 0) return { messages: [] };
|
|
524
565
|
try {
|
|
@@ -535,7 +576,7 @@ var MemoryStorageCloudflare = class extends storage.MemoryStorage {
|
|
|
535
576
|
} catch (error$1) {
|
|
536
577
|
const mastraError = new error.MastraError(
|
|
537
578
|
{
|
|
538
|
-
id: "
|
|
579
|
+
id: storage.createStorageErrorId("CLOUDFLARE", "LIST_MESSAGES_BY_ID", "FAILED"),
|
|
539
580
|
domain: error.ErrorDomain.STORAGE,
|
|
540
581
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
541
582
|
text: `Error retrieving messages by ID`,
|
|
@@ -552,15 +593,17 @@ var MemoryStorageCloudflare = class extends storage.MemoryStorage {
|
|
|
552
593
|
}
|
|
553
594
|
async listMessages(args) {
|
|
554
595
|
const { threadId, resourceId, include, filter, perPage: perPageInput, page = 0, orderBy } = args;
|
|
555
|
-
|
|
596
|
+
const threadIds = Array.isArray(threadId) ? threadId : [threadId];
|
|
597
|
+
const isValidThreadId = (id) => typeof id === "string" && id.trim().length > 0;
|
|
598
|
+
if (threadIds.length === 0 || threadIds.some((id) => !isValidThreadId(id))) {
|
|
556
599
|
throw new error.MastraError(
|
|
557
600
|
{
|
|
558
|
-
id: "
|
|
601
|
+
id: storage.createStorageErrorId("CLOUDFLARE", "LIST_MESSAGES", "INVALID_THREAD_ID"),
|
|
559
602
|
domain: error.ErrorDomain.STORAGE,
|
|
560
603
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
561
|
-
details: { threadId }
|
|
604
|
+
details: { threadId: Array.isArray(threadId) ? JSON.stringify(threadId) : String(threadId) }
|
|
562
605
|
},
|
|
563
|
-
new Error("threadId must be a non-empty string")
|
|
606
|
+
new Error("threadId must be a non-empty string or array of non-empty strings")
|
|
564
607
|
);
|
|
565
608
|
}
|
|
566
609
|
const perPage = storage.normalizePerPage(perPageInput, 40);
|
|
@@ -569,7 +612,7 @@ var MemoryStorageCloudflare = class extends storage.MemoryStorage {
|
|
|
569
612
|
if (page < 0) {
|
|
570
613
|
throw new error.MastraError(
|
|
571
614
|
{
|
|
572
|
-
id: "
|
|
615
|
+
id: storage.createStorageErrorId("CLOUDFLARE", "LIST_MESSAGES", "INVALID_PAGE"),
|
|
573
616
|
domain: error.ErrorDomain.STORAGE,
|
|
574
617
|
category: error.ErrorCategory.USER,
|
|
575
618
|
details: { page }
|
|
@@ -579,16 +622,18 @@ var MemoryStorageCloudflare = class extends storage.MemoryStorage {
|
|
|
579
622
|
}
|
|
580
623
|
const { field, direction } = this.parseOrderBy(orderBy, "ASC");
|
|
581
624
|
const threadMessageIds = /* @__PURE__ */ new Set();
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
625
|
+
for (const tid of threadIds) {
|
|
626
|
+
try {
|
|
627
|
+
const threadMessagesKey = this.getThreadMessagesKey(tid);
|
|
628
|
+
const allIds = await this.getFullOrder(threadMessagesKey);
|
|
629
|
+
allIds.forEach((id) => threadMessageIds.add(id));
|
|
630
|
+
} catch {
|
|
631
|
+
}
|
|
587
632
|
}
|
|
588
633
|
const threadMessages = await this.fetchAndParseMessagesFromMultipleThreads(
|
|
589
634
|
Array.from(threadMessageIds),
|
|
590
635
|
void 0,
|
|
591
|
-
|
|
636
|
+
threadIds.length === 1 ? threadIds[0] : void 0
|
|
592
637
|
);
|
|
593
638
|
let filteredThreadMessages = threadMessages;
|
|
594
639
|
if (resourceId) {
|
|
@@ -633,7 +678,7 @@ var MemoryStorageCloudflare = class extends storage.MemoryStorage {
|
|
|
633
678
|
let includedMessages = [];
|
|
634
679
|
if (include && include.length > 0) {
|
|
635
680
|
const includedMessageIds = /* @__PURE__ */ new Set();
|
|
636
|
-
await this.getIncludedMessagesWithContext(
|
|
681
|
+
await this.getIncludedMessagesWithContext(include, includedMessageIds);
|
|
637
682
|
const paginatedIds = new Set(paginatedMessages.map((m) => m.id));
|
|
638
683
|
const idsToFetch = Array.from(includedMessageIds).filter((id) => !paginatedIds.has(id));
|
|
639
684
|
if (idsToFetch.length > 0) {
|
|
@@ -679,7 +724,11 @@ var MemoryStorageCloudflare = class extends storage.MemoryStorage {
|
|
|
679
724
|
type: message.type !== "v2" ? message.type : void 0,
|
|
680
725
|
createdAt: storage.ensureDate(message.createdAt)
|
|
681
726
|
}));
|
|
682
|
-
const
|
|
727
|
+
const primaryThreadId = Array.isArray(threadId) ? threadId[0] : threadId;
|
|
728
|
+
const list = new agent.MessageList({ threadId: primaryThreadId, resourceId }).add(
|
|
729
|
+
prepared,
|
|
730
|
+
"memory"
|
|
731
|
+
);
|
|
683
732
|
let finalMessages = list.get.all.db();
|
|
684
733
|
finalMessages = finalMessages.sort((a, b) => {
|
|
685
734
|
const isDateField = field === "createdAt" || field === "updatedAt";
|
|
@@ -695,7 +744,10 @@ var MemoryStorageCloudflare = class extends storage.MemoryStorage {
|
|
|
695
744
|
const cmp = direction === "ASC" ? String(aVal).localeCompare(String(bVal)) : String(bVal).localeCompare(String(aVal));
|
|
696
745
|
return cmp !== 0 ? cmp : a.id.localeCompare(b.id);
|
|
697
746
|
});
|
|
698
|
-
const
|
|
747
|
+
const threadIdSet = new Set(threadIds);
|
|
748
|
+
const returnedThreadMessageIds = new Set(
|
|
749
|
+
finalMessages.filter((m) => m.threadId && threadIdSet.has(m.threadId)).map((m) => m.id)
|
|
750
|
+
);
|
|
699
751
|
const allThreadMessagesReturned = returnedThreadMessageIds.size >= total;
|
|
700
752
|
const hasMore = perPageInput !== false && !allThreadMessagesReturned && offset + paginatedCount < total;
|
|
701
753
|
return {
|
|
@@ -708,12 +760,12 @@ var MemoryStorageCloudflare = class extends storage.MemoryStorage {
|
|
|
708
760
|
} catch (error$1) {
|
|
709
761
|
const mastraError = new error.MastraError(
|
|
710
762
|
{
|
|
711
|
-
id: "
|
|
763
|
+
id: storage.createStorageErrorId("CLOUDFLARE", "LIST_MESSAGES", "FAILED"),
|
|
712
764
|
domain: error.ErrorDomain.STORAGE,
|
|
713
765
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
714
|
-
text: `Failed to list messages for thread ${threadId}: ${error$1 instanceof Error ? error$1.message : String(error$1)}`,
|
|
766
|
+
text: `Failed to list messages for thread ${Array.isArray(threadId) ? threadId.join(",") : threadId}: ${error$1 instanceof Error ? error$1.message : String(error$1)}`,
|
|
715
767
|
details: {
|
|
716
|
-
threadId,
|
|
768
|
+
threadId: Array.isArray(threadId) ? threadId.join(",") : threadId,
|
|
717
769
|
resourceId: resourceId ?? ""
|
|
718
770
|
}
|
|
719
771
|
},
|
|
@@ -830,7 +882,7 @@ var MemoryStorageCloudflare = class extends storage.MemoryStorage {
|
|
|
830
882
|
} catch (error$1) {
|
|
831
883
|
throw new error.MastraError(
|
|
832
884
|
{
|
|
833
|
-
id: "
|
|
885
|
+
id: storage.createStorageErrorId("CLOUDFLARE", "UPDATE_MESSAGES", "FAILED"),
|
|
834
886
|
domain: error.ErrorDomain.STORAGE,
|
|
835
887
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
836
888
|
text: "Failed to update messages"
|
|
@@ -853,7 +905,7 @@ var MemoryStorageCloudflare = class extends storage.MemoryStorage {
|
|
|
853
905
|
} catch (error$1) {
|
|
854
906
|
const mastraError = new error.MastraError(
|
|
855
907
|
{
|
|
856
|
-
id: "
|
|
908
|
+
id: storage.createStorageErrorId("CLOUDFLARE", "GET_RESOURCE_BY_ID", "FAILED"),
|
|
857
909
|
domain: error.ErrorDomain.STORAGE,
|
|
858
910
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
859
911
|
details: {
|
|
@@ -882,7 +934,7 @@ var MemoryStorageCloudflare = class extends storage.MemoryStorage {
|
|
|
882
934
|
} catch (error$1) {
|
|
883
935
|
throw new error.MastraError(
|
|
884
936
|
{
|
|
885
|
-
id: "
|
|
937
|
+
id: storage.createStorageErrorId("CLOUDFLARE", "SAVE_RESOURCE", "FAILED"),
|
|
886
938
|
domain: error.ErrorDomain.STORAGE,
|
|
887
939
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
888
940
|
details: {
|
|
@@ -953,7 +1005,7 @@ var StoreOperationsCloudflare = class extends storage.StoreOperations {
|
|
|
953
1005
|
} catch (error$1) {
|
|
954
1006
|
throw new error.MastraError(
|
|
955
1007
|
{
|
|
956
|
-
id: "
|
|
1008
|
+
id: storage.createStorageErrorId("CLOUDFLARE", "CLEAR_TABLE", "FAILED"),
|
|
957
1009
|
domain: error.ErrorDomain.STORAGE,
|
|
958
1010
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
959
1011
|
details: {
|
|
@@ -973,7 +1025,7 @@ var StoreOperationsCloudflare = class extends storage.StoreOperations {
|
|
|
973
1025
|
} catch (error$1) {
|
|
974
1026
|
throw new error.MastraError(
|
|
975
1027
|
{
|
|
976
|
-
id: "
|
|
1028
|
+
id: storage.createStorageErrorId("CLOUDFLARE", "DROP_TABLE", "FAILED"),
|
|
977
1029
|
domain: error.ErrorDomain.STORAGE,
|
|
978
1030
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
979
1031
|
details: {
|
|
@@ -1275,7 +1327,7 @@ var StoreOperationsCloudflare = class extends storage.StoreOperations {
|
|
|
1275
1327
|
} catch (error$1) {
|
|
1276
1328
|
throw new error.MastraError(
|
|
1277
1329
|
{
|
|
1278
|
-
id: "
|
|
1330
|
+
id: storage.createStorageErrorId("CLOUDFLARE", "INSERT", "FAILED"),
|
|
1279
1331
|
domain: error.ErrorDomain.STORAGE,
|
|
1280
1332
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1281
1333
|
details: {
|
|
@@ -1295,7 +1347,7 @@ var StoreOperationsCloudflare = class extends storage.StoreOperations {
|
|
|
1295
1347
|
} catch (error$1) {
|
|
1296
1348
|
const mastraError = new error.MastraError(
|
|
1297
1349
|
{
|
|
1298
|
-
id: "
|
|
1350
|
+
id: storage.createStorageErrorId("CLOUDFLARE", "LOAD", "FAILED"),
|
|
1299
1351
|
domain: error.ErrorDomain.STORAGE,
|
|
1300
1352
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1301
1353
|
details: {
|
|
@@ -1321,7 +1373,7 @@ var StoreOperationsCloudflare = class extends storage.StoreOperations {
|
|
|
1321
1373
|
} catch (error$1) {
|
|
1322
1374
|
throw new error.MastraError(
|
|
1323
1375
|
{
|
|
1324
|
-
id: "
|
|
1376
|
+
id: storage.createStorageErrorId("CLOUDFLARE", "BATCH_INSERT", "FAILED"),
|
|
1325
1377
|
domain: error.ErrorDomain.STORAGE,
|
|
1326
1378
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1327
1379
|
text: `Error in batch insert for table ${input.tableName}`,
|
|
@@ -1393,7 +1445,7 @@ var StoreOperationsCloudflare = class extends storage.StoreOperations {
|
|
|
1393
1445
|
} catch (error$1) {
|
|
1394
1446
|
throw new error.MastraError(
|
|
1395
1447
|
{
|
|
1396
|
-
id: "
|
|
1448
|
+
id: storage.createStorageErrorId("CLOUDFLARE", "CREATE_TABLE", "FAILED"),
|
|
1397
1449
|
domain: error.ErrorDomain.STORAGE,
|
|
1398
1450
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1399
1451
|
details: {
|
|
@@ -1425,7 +1477,7 @@ var StoreOperationsCloudflare = class extends storage.StoreOperations {
|
|
|
1425
1477
|
} catch (error$1) {
|
|
1426
1478
|
throw new error.MastraError(
|
|
1427
1479
|
{
|
|
1428
|
-
id: "
|
|
1480
|
+
id: storage.createStorageErrorId("CLOUDFLARE", "LIST_NAMESPACE_KEYS", "FAILED"),
|
|
1429
1481
|
domain: error.ErrorDomain.STORAGE,
|
|
1430
1482
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1431
1483
|
details: {
|
|
@@ -1465,17 +1517,7 @@ var StoreOperationsCloudflare = class extends storage.StoreOperations {
|
|
|
1465
1517
|
}
|
|
1466
1518
|
};
|
|
1467
1519
|
function transformScoreRow(row) {
|
|
1468
|
-
|
|
1469
|
-
deserialized.input = storage.safelyParseJSON(row.input);
|
|
1470
|
-
deserialized.output = storage.safelyParseJSON(row.output);
|
|
1471
|
-
deserialized.scorer = storage.safelyParseJSON(row.scorer);
|
|
1472
|
-
deserialized.preprocessStepResult = storage.safelyParseJSON(row.preprocessStepResult);
|
|
1473
|
-
deserialized.analyzeStepResult = storage.safelyParseJSON(row.analyzeStepResult);
|
|
1474
|
-
deserialized.metadata = storage.safelyParseJSON(row.metadata);
|
|
1475
|
-
deserialized.additionalContext = storage.safelyParseJSON(row.additionalContext);
|
|
1476
|
-
deserialized.requestContext = storage.safelyParseJSON(row.requestContext);
|
|
1477
|
-
deserialized.entity = storage.safelyParseJSON(row.entity);
|
|
1478
|
-
return deserialized;
|
|
1520
|
+
return storage.transformScoreRow(row);
|
|
1479
1521
|
}
|
|
1480
1522
|
var ScoresStorageCloudflare = class extends storage.ScoresStorage {
|
|
1481
1523
|
operations;
|
|
@@ -1493,7 +1535,7 @@ var ScoresStorageCloudflare = class extends storage.ScoresStorage {
|
|
|
1493
1535
|
} catch (error$1) {
|
|
1494
1536
|
const mastraError = new error.MastraError(
|
|
1495
1537
|
{
|
|
1496
|
-
id: "
|
|
1538
|
+
id: storage.createStorageErrorId("CLOUDFLARE", "GET_SCORE_BY_ID", "FAILED"),
|
|
1497
1539
|
domain: error.ErrorDomain.STORAGE,
|
|
1498
1540
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1499
1541
|
text: `Failed to get score by id: ${id}`
|
|
@@ -1512,7 +1554,7 @@ var ScoresStorageCloudflare = class extends storage.ScoresStorage {
|
|
|
1512
1554
|
} catch (error$1) {
|
|
1513
1555
|
throw new error.MastraError(
|
|
1514
1556
|
{
|
|
1515
|
-
id: "
|
|
1557
|
+
id: storage.createStorageErrorId("CLOUDFLARE", "SAVE_SCORE", "VALIDATION_FAILED"),
|
|
1516
1558
|
domain: error.ErrorDomain.STORAGE,
|
|
1517
1559
|
category: error.ErrorCategory.USER,
|
|
1518
1560
|
details: { scoreId: score.id }
|
|
@@ -1547,7 +1589,7 @@ var ScoresStorageCloudflare = class extends storage.ScoresStorage {
|
|
|
1547
1589
|
} catch (error$1) {
|
|
1548
1590
|
const mastraError = new error.MastraError(
|
|
1549
1591
|
{
|
|
1550
|
-
id: "
|
|
1592
|
+
id: storage.createStorageErrorId("CLOUDFLARE", "SAVE_SCORE", "FAILED"),
|
|
1551
1593
|
domain: error.ErrorDomain.STORAGE,
|
|
1552
1594
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1553
1595
|
text: `Failed to save score: ${score.id}`
|
|
@@ -1607,7 +1649,7 @@ var ScoresStorageCloudflare = class extends storage.ScoresStorage {
|
|
|
1607
1649
|
} catch (error$1) {
|
|
1608
1650
|
const mastraError = new error.MastraError(
|
|
1609
1651
|
{
|
|
1610
|
-
id: "
|
|
1652
|
+
id: storage.createStorageErrorId("CLOUDFLARE", "GET_SCORES_BY_SCORER_ID", "FAILED"),
|
|
1611
1653
|
domain: error.ErrorDomain.STORAGE,
|
|
1612
1654
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1613
1655
|
text: `Failed to get scores by scorer id: ${scorerId}`
|
|
@@ -1655,7 +1697,7 @@ var ScoresStorageCloudflare = class extends storage.ScoresStorage {
|
|
|
1655
1697
|
} catch (error$1) {
|
|
1656
1698
|
const mastraError = new error.MastraError(
|
|
1657
1699
|
{
|
|
1658
|
-
id: "
|
|
1700
|
+
id: storage.createStorageErrorId("CLOUDFLARE", "GET_SCORES_BY_RUN_ID", "FAILED"),
|
|
1659
1701
|
domain: error.ErrorDomain.STORAGE,
|
|
1660
1702
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1661
1703
|
text: `Failed to get scores by run id: ${runId}`
|
|
@@ -1704,7 +1746,7 @@ var ScoresStorageCloudflare = class extends storage.ScoresStorage {
|
|
|
1704
1746
|
} catch (error$1) {
|
|
1705
1747
|
const mastraError = new error.MastraError(
|
|
1706
1748
|
{
|
|
1707
|
-
id: "
|
|
1749
|
+
id: storage.createStorageErrorId("CLOUDFLARE", "GET_SCORES_BY_ENTITY_ID", "FAILED"),
|
|
1708
1750
|
domain: error.ErrorDomain.STORAGE,
|
|
1709
1751
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1710
1752
|
text: `Failed to get scores by entity id: ${entityId}, type: ${entityType}`
|
|
@@ -1753,7 +1795,7 @@ var ScoresStorageCloudflare = class extends storage.ScoresStorage {
|
|
|
1753
1795
|
} catch (error$1) {
|
|
1754
1796
|
const mastraError = new error.MastraError(
|
|
1755
1797
|
{
|
|
1756
|
-
id: "
|
|
1798
|
+
id: storage.createStorageErrorId("CLOUDFLARE", "GET_SCORES_BY_SPAN", "FAILED"),
|
|
1757
1799
|
domain: error.ErrorDomain.STORAGE,
|
|
1758
1800
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1759
1801
|
text: `Failed to get scores by span: traceId=${traceId}, spanId=${spanId}`
|
|
@@ -1812,7 +1854,7 @@ var WorkflowsStorageCloudflare = class extends storage.WorkflowsStorage {
|
|
|
1812
1854
|
} catch (error$1) {
|
|
1813
1855
|
throw new error.MastraError(
|
|
1814
1856
|
{
|
|
1815
|
-
id: "
|
|
1857
|
+
id: storage.createStorageErrorId("CLOUDFLARE", "PERSIST_WORKFLOW_SNAPSHOT", "FAILED"),
|
|
1816
1858
|
domain: error.ErrorDomain.STORAGE,
|
|
1817
1859
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1818
1860
|
text: `Error persisting workflow snapshot for workflow ${params.workflowName}, run ${params.runId}`,
|
|
@@ -1837,7 +1879,7 @@ var WorkflowsStorageCloudflare = class extends storage.WorkflowsStorage {
|
|
|
1837
1879
|
} catch (error$1) {
|
|
1838
1880
|
const mastraError = new error.MastraError(
|
|
1839
1881
|
{
|
|
1840
|
-
id: "
|
|
1882
|
+
id: storage.createStorageErrorId("CLOUDFLARE", "LOAD_WORKFLOW_SNAPSHOT", "FAILED"),
|
|
1841
1883
|
domain: error.ErrorDomain.STORAGE,
|
|
1842
1884
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1843
1885
|
text: `Error loading workflow snapshot for workflow ${params.workflowName}, run ${params.runId}`,
|
|
@@ -1896,7 +1938,7 @@ var WorkflowsStorageCloudflare = class extends storage.WorkflowsStorage {
|
|
|
1896
1938
|
if (page < 0 || !Number.isInteger(page)) {
|
|
1897
1939
|
throw new error.MastraError(
|
|
1898
1940
|
{
|
|
1899
|
-
id: "
|
|
1941
|
+
id: storage.createStorageErrorId("CLOUDFLARE", "LIST_WORKFLOW_RUNS", "INVALID_PAGE"),
|
|
1900
1942
|
domain: error.ErrorDomain.STORAGE,
|
|
1901
1943
|
category: error.ErrorCategory.USER,
|
|
1902
1944
|
details: { page }
|
|
@@ -1951,7 +1993,7 @@ var WorkflowsStorageCloudflare = class extends storage.WorkflowsStorage {
|
|
|
1951
1993
|
} catch (error$1) {
|
|
1952
1994
|
const mastraError = new error.MastraError(
|
|
1953
1995
|
{
|
|
1954
|
-
id: "
|
|
1996
|
+
id: storage.createStorageErrorId("CLOUDFLARE", "LIST_WORKFLOW_RUNS", "FAILED"),
|
|
1955
1997
|
domain: error.ErrorDomain.STORAGE,
|
|
1956
1998
|
category: error.ErrorCategory.THIRD_PARTY
|
|
1957
1999
|
},
|
|
@@ -1989,7 +2031,7 @@ var WorkflowsStorageCloudflare = class extends storage.WorkflowsStorage {
|
|
|
1989
2031
|
} catch (error$1) {
|
|
1990
2032
|
const mastraError = new error.MastraError(
|
|
1991
2033
|
{
|
|
1992
|
-
id: "
|
|
2034
|
+
id: storage.createStorageErrorId("CLOUDFLARE", "GET_WORKFLOW_RUN_BY_ID", "FAILED"),
|
|
1993
2035
|
domain: error.ErrorDomain.STORAGE,
|
|
1994
2036
|
category: error.ErrorCategory.THIRD_PARTY,
|
|
1995
2037
|
details: {
|
|
@@ -2051,7 +2093,7 @@ var CloudflareStore = class extends storage.MastraStorage {
|
|
|
2051
2093
|
return supports;
|
|
2052
2094
|
}
|
|
2053
2095
|
constructor(config) {
|
|
2054
|
-
super({ id: config.id, name: "Cloudflare" });
|
|
2096
|
+
super({ id: config.id, name: "Cloudflare", disableInit: config.disableInit });
|
|
2055
2097
|
try {
|
|
2056
2098
|
if (isWorkersConfig(config)) {
|
|
2057
2099
|
this.validateWorkersConfig(config);
|
|
@@ -2091,7 +2133,7 @@ var CloudflareStore = class extends storage.MastraStorage {
|
|
|
2091
2133
|
} catch (error$1) {
|
|
2092
2134
|
throw new error.MastraError(
|
|
2093
2135
|
{
|
|
2094
|
-
id: "
|
|
2136
|
+
id: storage.createStorageErrorId("CLOUDFLARE", "INIT", "FAILED"),
|
|
2095
2137
|
domain: error.ErrorDomain.STORAGE,
|
|
2096
2138
|
category: error.ErrorCategory.THIRD_PARTY
|
|
2097
2139
|
},
|