@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/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
|
|
2
|
-
import { MastraStorage, TABLE_THREADS, TABLE_MESSAGES, TABLE_WORKFLOW_SNAPSHOT, TABLE_SCORERS, StoreOperations, TABLE_TRACES, WorkflowsStorage, ensureDate, normalizePerPage, MemoryStorage, calculatePagination, serializeDate, TABLE_RESOURCES, ScoresStorage,
|
|
2
|
+
import { MastraStorage, TABLE_THREADS, TABLE_MESSAGES, TABLE_WORKFLOW_SNAPSHOT, TABLE_SCORERS, createStorageErrorId, StoreOperations, TABLE_TRACES, WorkflowsStorage, ensureDate, normalizePerPage, MemoryStorage, calculatePagination, serializeDate, TABLE_RESOURCES, ScoresStorage, transformScoreRow as transformScoreRow$1 } from '@mastra/core/storage';
|
|
3
3
|
import Cloudflare from 'cloudflare';
|
|
4
4
|
import { MessageList } from '@mastra/core/agent';
|
|
5
5
|
import { saveScorePayloadSchema } from '@mastra/core/evals';
|
|
@@ -39,7 +39,7 @@ var MemoryStorageCloudflare = class extends MemoryStorage {
|
|
|
39
39
|
} catch (error) {
|
|
40
40
|
const mastraError = new MastraError(
|
|
41
41
|
{
|
|
42
|
-
id: "
|
|
42
|
+
id: createStorageErrorId("CLOUDFLARE", "GET_THREAD_BY_ID", "FAILED"),
|
|
43
43
|
domain: ErrorDomain.STORAGE,
|
|
44
44
|
category: ErrorCategory.THIRD_PARTY,
|
|
45
45
|
details: {
|
|
@@ -60,7 +60,7 @@ var MemoryStorageCloudflare = class extends MemoryStorage {
|
|
|
60
60
|
if (page < 0) {
|
|
61
61
|
throw new MastraError(
|
|
62
62
|
{
|
|
63
|
-
id: "
|
|
63
|
+
id: createStorageErrorId("CLOUDFLARE", "LIST_THREADS_BY_RESOURCE_ID", "INVALID_PAGE"),
|
|
64
64
|
domain: ErrorDomain.STORAGE,
|
|
65
65
|
category: ErrorCategory.USER,
|
|
66
66
|
details: { page }
|
|
@@ -96,7 +96,7 @@ var MemoryStorageCloudflare = class extends MemoryStorage {
|
|
|
96
96
|
} catch (error) {
|
|
97
97
|
throw new MastraError(
|
|
98
98
|
{
|
|
99
|
-
id: "
|
|
99
|
+
id: createStorageErrorId("CLOUDFLARE", "LIST_THREADS_BY_RESOURCE_ID", "FAILED"),
|
|
100
100
|
domain: ErrorDomain.STORAGE,
|
|
101
101
|
category: ErrorCategory.THIRD_PARTY,
|
|
102
102
|
text: "Failed to get threads by resource ID with pagination"
|
|
@@ -112,7 +112,7 @@ var MemoryStorageCloudflare = class extends MemoryStorage {
|
|
|
112
112
|
} catch (error) {
|
|
113
113
|
throw new MastraError(
|
|
114
114
|
{
|
|
115
|
-
id: "
|
|
115
|
+
id: createStorageErrorId("CLOUDFLARE", "SAVE_THREAD", "FAILED"),
|
|
116
116
|
domain: ErrorDomain.STORAGE,
|
|
117
117
|
category: ErrorCategory.THIRD_PARTY,
|
|
118
118
|
details: {
|
|
@@ -147,7 +147,7 @@ var MemoryStorageCloudflare = class extends MemoryStorage {
|
|
|
147
147
|
} catch (error) {
|
|
148
148
|
throw new MastraError(
|
|
149
149
|
{
|
|
150
|
-
id: "
|
|
150
|
+
id: createStorageErrorId("CLOUDFLARE", "UPDATE_THREAD", "FAILED"),
|
|
151
151
|
domain: ErrorDomain.STORAGE,
|
|
152
152
|
category: ErrorCategory.THIRD_PARTY,
|
|
153
153
|
details: {
|
|
@@ -196,7 +196,7 @@ var MemoryStorageCloudflare = class extends MemoryStorage {
|
|
|
196
196
|
} catch (error) {
|
|
197
197
|
throw new MastraError(
|
|
198
198
|
{
|
|
199
|
-
id: "
|
|
199
|
+
id: createStorageErrorId("CLOUDFLARE", "DELETE_THREAD", "FAILED"),
|
|
200
200
|
domain: ErrorDomain.STORAGE,
|
|
201
201
|
category: ErrorCategory.THIRD_PARTY,
|
|
202
202
|
details: {
|
|
@@ -207,6 +207,17 @@ var MemoryStorageCloudflare = class extends MemoryStorage {
|
|
|
207
207
|
);
|
|
208
208
|
}
|
|
209
209
|
}
|
|
210
|
+
/**
|
|
211
|
+
* Searches all threads in the KV store to find a message by its ID.
|
|
212
|
+
*
|
|
213
|
+
* **Performance Warning**: This method sequentially scans all threads to locate
|
|
214
|
+
* the message. For stores with many threads, this can result in significant
|
|
215
|
+
* latency and API calls. When possible, callers should provide the `threadId`
|
|
216
|
+
* directly to avoid this full scan.
|
|
217
|
+
*
|
|
218
|
+
* @param messageId - The globally unique message ID to search for
|
|
219
|
+
* @returns The message with its threadId if found, null otherwise
|
|
220
|
+
*/
|
|
210
221
|
async findMessageInAnyThread(messageId) {
|
|
211
222
|
try {
|
|
212
223
|
const prefix = this.operations.namespacePrefix ? `${this.operations.namespacePrefix}:` : "";
|
|
@@ -390,7 +401,7 @@ var MemoryStorageCloudflare = class extends MemoryStorage {
|
|
|
390
401
|
} catch (error) {
|
|
391
402
|
throw new MastraError(
|
|
392
403
|
{
|
|
393
|
-
id: "
|
|
404
|
+
id: createStorageErrorId("CLOUDFLARE", "SAVE_MESSAGES", "FAILED"),
|
|
394
405
|
domain: ErrorDomain.STORAGE,
|
|
395
406
|
category: ErrorCategory.THIRD_PARTY,
|
|
396
407
|
details: {
|
|
@@ -410,7 +421,7 @@ var MemoryStorageCloudflare = class extends MemoryStorage {
|
|
|
410
421
|
} catch (error) {
|
|
411
422
|
throw new MastraError(
|
|
412
423
|
{
|
|
413
|
-
id: "
|
|
424
|
+
id: createStorageErrorId("CLOUDFLARE", "SAVE_MESSAGES", "FAILED"),
|
|
414
425
|
domain: ErrorDomain.STORAGE,
|
|
415
426
|
category: ErrorCategory.THIRD_PARTY
|
|
416
427
|
},
|
|
@@ -436,10 +447,25 @@ var MemoryStorageCloudflare = class extends MemoryStorage {
|
|
|
436
447
|
async getFullOrder(orderKey) {
|
|
437
448
|
return this.getRange(orderKey, 0, -1);
|
|
438
449
|
}
|
|
439
|
-
|
|
450
|
+
/**
|
|
451
|
+
* Retrieves messages specified in the include array along with their surrounding context.
|
|
452
|
+
*
|
|
453
|
+
* **Performance Note**: When `threadId` is not provided in an include entry, this method
|
|
454
|
+
* must call `findMessageInAnyThread` which sequentially scans all threads in the KV store.
|
|
455
|
+
* For optimal performance, callers should provide `threadId` in include entries when known.
|
|
456
|
+
*
|
|
457
|
+
* @param include - Array of message IDs to include, optionally with context windows
|
|
458
|
+
* @param messageIds - Set to accumulate the message IDs that should be fetched
|
|
459
|
+
*/
|
|
460
|
+
async getIncludedMessagesWithContext(include, messageIds) {
|
|
440
461
|
await Promise.all(
|
|
441
462
|
include.map(async (item) => {
|
|
442
|
-
|
|
463
|
+
let targetThreadId = item.threadId;
|
|
464
|
+
if (!targetThreadId) {
|
|
465
|
+
const foundMessage = await this.findMessageInAnyThread(item.id);
|
|
466
|
+
if (!foundMessage) return;
|
|
467
|
+
targetThreadId = foundMessage.threadId;
|
|
468
|
+
}
|
|
443
469
|
if (!targetThreadId) return;
|
|
444
470
|
const threadMessagesKey = this.getThreadMessagesKey(targetThreadId);
|
|
445
471
|
messageIds.add(item.id);
|
|
@@ -472,6 +498,13 @@ var MemoryStorageCloudflare = class extends MemoryStorage {
|
|
|
472
498
|
this.logger?.debug(`No message order found for thread ${threadId}, skipping latest messages`);
|
|
473
499
|
}
|
|
474
500
|
}
|
|
501
|
+
/**
|
|
502
|
+
* Fetches and parses messages from one or more threads.
|
|
503
|
+
*
|
|
504
|
+
* **Performance Note**: When neither `include` entries with `threadId` nor `targetThreadId`
|
|
505
|
+
* are provided, this method falls back to `findMessageInAnyThread` which scans all threads.
|
|
506
|
+
* For optimal performance, provide `threadId` in include entries or specify `targetThreadId`.
|
|
507
|
+
*/
|
|
475
508
|
async fetchAndParseMessagesFromMultipleThreads(messageIds, include, targetThreadId) {
|
|
476
509
|
const messageIdToThreadId = /* @__PURE__ */ new Map();
|
|
477
510
|
if (include) {
|
|
@@ -513,6 +546,14 @@ var MemoryStorageCloudflare = class extends MemoryStorage {
|
|
|
513
546
|
);
|
|
514
547
|
return messages.filter((msg) => msg !== null);
|
|
515
548
|
}
|
|
549
|
+
/**
|
|
550
|
+
* Retrieves messages by their IDs.
|
|
551
|
+
*
|
|
552
|
+
* **Performance Warning**: This method calls `findMessageInAnyThread` for each message ID,
|
|
553
|
+
* which scans all threads in the KV store. For large numbers of messages or threads,
|
|
554
|
+
* this can result in significant latency. Consider using `listMessages` with specific
|
|
555
|
+
* thread IDs when the thread context is known.
|
|
556
|
+
*/
|
|
516
557
|
async listMessagesById({ messageIds }) {
|
|
517
558
|
if (messageIds.length === 0) return { messages: [] };
|
|
518
559
|
try {
|
|
@@ -529,7 +570,7 @@ var MemoryStorageCloudflare = class extends MemoryStorage {
|
|
|
529
570
|
} catch (error) {
|
|
530
571
|
const mastraError = new MastraError(
|
|
531
572
|
{
|
|
532
|
-
id: "
|
|
573
|
+
id: createStorageErrorId("CLOUDFLARE", "LIST_MESSAGES_BY_ID", "FAILED"),
|
|
533
574
|
domain: ErrorDomain.STORAGE,
|
|
534
575
|
category: ErrorCategory.THIRD_PARTY,
|
|
535
576
|
text: `Error retrieving messages by ID`,
|
|
@@ -546,15 +587,17 @@ var MemoryStorageCloudflare = class extends MemoryStorage {
|
|
|
546
587
|
}
|
|
547
588
|
async listMessages(args) {
|
|
548
589
|
const { threadId, resourceId, include, filter, perPage: perPageInput, page = 0, orderBy } = args;
|
|
549
|
-
|
|
590
|
+
const threadIds = Array.isArray(threadId) ? threadId : [threadId];
|
|
591
|
+
const isValidThreadId = (id) => typeof id === "string" && id.trim().length > 0;
|
|
592
|
+
if (threadIds.length === 0 || threadIds.some((id) => !isValidThreadId(id))) {
|
|
550
593
|
throw new MastraError(
|
|
551
594
|
{
|
|
552
|
-
id: "
|
|
595
|
+
id: createStorageErrorId("CLOUDFLARE", "LIST_MESSAGES", "INVALID_THREAD_ID"),
|
|
553
596
|
domain: ErrorDomain.STORAGE,
|
|
554
597
|
category: ErrorCategory.THIRD_PARTY,
|
|
555
|
-
details: { threadId }
|
|
598
|
+
details: { threadId: Array.isArray(threadId) ? JSON.stringify(threadId) : String(threadId) }
|
|
556
599
|
},
|
|
557
|
-
new Error("threadId must be a non-empty string")
|
|
600
|
+
new Error("threadId must be a non-empty string or array of non-empty strings")
|
|
558
601
|
);
|
|
559
602
|
}
|
|
560
603
|
const perPage = normalizePerPage(perPageInput, 40);
|
|
@@ -563,7 +606,7 @@ var MemoryStorageCloudflare = class extends MemoryStorage {
|
|
|
563
606
|
if (page < 0) {
|
|
564
607
|
throw new MastraError(
|
|
565
608
|
{
|
|
566
|
-
id: "
|
|
609
|
+
id: createStorageErrorId("CLOUDFLARE", "LIST_MESSAGES", "INVALID_PAGE"),
|
|
567
610
|
domain: ErrorDomain.STORAGE,
|
|
568
611
|
category: ErrorCategory.USER,
|
|
569
612
|
details: { page }
|
|
@@ -573,16 +616,18 @@ var MemoryStorageCloudflare = class extends MemoryStorage {
|
|
|
573
616
|
}
|
|
574
617
|
const { field, direction } = this.parseOrderBy(orderBy, "ASC");
|
|
575
618
|
const threadMessageIds = /* @__PURE__ */ new Set();
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
619
|
+
for (const tid of threadIds) {
|
|
620
|
+
try {
|
|
621
|
+
const threadMessagesKey = this.getThreadMessagesKey(tid);
|
|
622
|
+
const allIds = await this.getFullOrder(threadMessagesKey);
|
|
623
|
+
allIds.forEach((id) => threadMessageIds.add(id));
|
|
624
|
+
} catch {
|
|
625
|
+
}
|
|
581
626
|
}
|
|
582
627
|
const threadMessages = await this.fetchAndParseMessagesFromMultipleThreads(
|
|
583
628
|
Array.from(threadMessageIds),
|
|
584
629
|
void 0,
|
|
585
|
-
|
|
630
|
+
threadIds.length === 1 ? threadIds[0] : void 0
|
|
586
631
|
);
|
|
587
632
|
let filteredThreadMessages = threadMessages;
|
|
588
633
|
if (resourceId) {
|
|
@@ -627,7 +672,7 @@ var MemoryStorageCloudflare = class extends MemoryStorage {
|
|
|
627
672
|
let includedMessages = [];
|
|
628
673
|
if (include && include.length > 0) {
|
|
629
674
|
const includedMessageIds = /* @__PURE__ */ new Set();
|
|
630
|
-
await this.getIncludedMessagesWithContext(
|
|
675
|
+
await this.getIncludedMessagesWithContext(include, includedMessageIds);
|
|
631
676
|
const paginatedIds = new Set(paginatedMessages.map((m) => m.id));
|
|
632
677
|
const idsToFetch = Array.from(includedMessageIds).filter((id) => !paginatedIds.has(id));
|
|
633
678
|
if (idsToFetch.length > 0) {
|
|
@@ -673,7 +718,11 @@ var MemoryStorageCloudflare = class extends MemoryStorage {
|
|
|
673
718
|
type: message.type !== "v2" ? message.type : void 0,
|
|
674
719
|
createdAt: ensureDate(message.createdAt)
|
|
675
720
|
}));
|
|
676
|
-
const
|
|
721
|
+
const primaryThreadId = Array.isArray(threadId) ? threadId[0] : threadId;
|
|
722
|
+
const list = new MessageList({ threadId: primaryThreadId, resourceId }).add(
|
|
723
|
+
prepared,
|
|
724
|
+
"memory"
|
|
725
|
+
);
|
|
677
726
|
let finalMessages = list.get.all.db();
|
|
678
727
|
finalMessages = finalMessages.sort((a, b) => {
|
|
679
728
|
const isDateField = field === "createdAt" || field === "updatedAt";
|
|
@@ -689,7 +738,10 @@ var MemoryStorageCloudflare = class extends MemoryStorage {
|
|
|
689
738
|
const cmp = direction === "ASC" ? String(aVal).localeCompare(String(bVal)) : String(bVal).localeCompare(String(aVal));
|
|
690
739
|
return cmp !== 0 ? cmp : a.id.localeCompare(b.id);
|
|
691
740
|
});
|
|
692
|
-
const
|
|
741
|
+
const threadIdSet = new Set(threadIds);
|
|
742
|
+
const returnedThreadMessageIds = new Set(
|
|
743
|
+
finalMessages.filter((m) => m.threadId && threadIdSet.has(m.threadId)).map((m) => m.id)
|
|
744
|
+
);
|
|
693
745
|
const allThreadMessagesReturned = returnedThreadMessageIds.size >= total;
|
|
694
746
|
const hasMore = perPageInput !== false && !allThreadMessagesReturned && offset + paginatedCount < total;
|
|
695
747
|
return {
|
|
@@ -702,12 +754,12 @@ var MemoryStorageCloudflare = class extends MemoryStorage {
|
|
|
702
754
|
} catch (error) {
|
|
703
755
|
const mastraError = new MastraError(
|
|
704
756
|
{
|
|
705
|
-
id: "
|
|
757
|
+
id: createStorageErrorId("CLOUDFLARE", "LIST_MESSAGES", "FAILED"),
|
|
706
758
|
domain: ErrorDomain.STORAGE,
|
|
707
759
|
category: ErrorCategory.THIRD_PARTY,
|
|
708
|
-
text: `Failed to list messages for thread ${threadId}: ${error instanceof Error ? error.message : String(error)}`,
|
|
760
|
+
text: `Failed to list messages for thread ${Array.isArray(threadId) ? threadId.join(",") : threadId}: ${error instanceof Error ? error.message : String(error)}`,
|
|
709
761
|
details: {
|
|
710
|
-
threadId,
|
|
762
|
+
threadId: Array.isArray(threadId) ? threadId.join(",") : threadId,
|
|
711
763
|
resourceId: resourceId ?? ""
|
|
712
764
|
}
|
|
713
765
|
},
|
|
@@ -824,7 +876,7 @@ var MemoryStorageCloudflare = class extends MemoryStorage {
|
|
|
824
876
|
} catch (error) {
|
|
825
877
|
throw new MastraError(
|
|
826
878
|
{
|
|
827
|
-
id: "
|
|
879
|
+
id: createStorageErrorId("CLOUDFLARE", "UPDATE_MESSAGES", "FAILED"),
|
|
828
880
|
domain: ErrorDomain.STORAGE,
|
|
829
881
|
category: ErrorCategory.THIRD_PARTY,
|
|
830
882
|
text: "Failed to update messages"
|
|
@@ -847,7 +899,7 @@ var MemoryStorageCloudflare = class extends MemoryStorage {
|
|
|
847
899
|
} catch (error) {
|
|
848
900
|
const mastraError = new MastraError(
|
|
849
901
|
{
|
|
850
|
-
id: "
|
|
902
|
+
id: createStorageErrorId("CLOUDFLARE", "GET_RESOURCE_BY_ID", "FAILED"),
|
|
851
903
|
domain: ErrorDomain.STORAGE,
|
|
852
904
|
category: ErrorCategory.THIRD_PARTY,
|
|
853
905
|
details: {
|
|
@@ -876,7 +928,7 @@ var MemoryStorageCloudflare = class extends MemoryStorage {
|
|
|
876
928
|
} catch (error) {
|
|
877
929
|
throw new MastraError(
|
|
878
930
|
{
|
|
879
|
-
id: "
|
|
931
|
+
id: createStorageErrorId("CLOUDFLARE", "SAVE_RESOURCE", "FAILED"),
|
|
880
932
|
domain: ErrorDomain.STORAGE,
|
|
881
933
|
category: ErrorCategory.THIRD_PARTY,
|
|
882
934
|
details: {
|
|
@@ -947,7 +999,7 @@ var StoreOperationsCloudflare = class extends StoreOperations {
|
|
|
947
999
|
} catch (error) {
|
|
948
1000
|
throw new MastraError(
|
|
949
1001
|
{
|
|
950
|
-
id: "
|
|
1002
|
+
id: createStorageErrorId("CLOUDFLARE", "CLEAR_TABLE", "FAILED"),
|
|
951
1003
|
domain: ErrorDomain.STORAGE,
|
|
952
1004
|
category: ErrorCategory.THIRD_PARTY,
|
|
953
1005
|
details: {
|
|
@@ -967,7 +1019,7 @@ var StoreOperationsCloudflare = class extends StoreOperations {
|
|
|
967
1019
|
} catch (error) {
|
|
968
1020
|
throw new MastraError(
|
|
969
1021
|
{
|
|
970
|
-
id: "
|
|
1022
|
+
id: createStorageErrorId("CLOUDFLARE", "DROP_TABLE", "FAILED"),
|
|
971
1023
|
domain: ErrorDomain.STORAGE,
|
|
972
1024
|
category: ErrorCategory.THIRD_PARTY,
|
|
973
1025
|
details: {
|
|
@@ -1269,7 +1321,7 @@ var StoreOperationsCloudflare = class extends StoreOperations {
|
|
|
1269
1321
|
} catch (error) {
|
|
1270
1322
|
throw new MastraError(
|
|
1271
1323
|
{
|
|
1272
|
-
id: "
|
|
1324
|
+
id: createStorageErrorId("CLOUDFLARE", "INSERT", "FAILED"),
|
|
1273
1325
|
domain: ErrorDomain.STORAGE,
|
|
1274
1326
|
category: ErrorCategory.THIRD_PARTY,
|
|
1275
1327
|
details: {
|
|
@@ -1289,7 +1341,7 @@ var StoreOperationsCloudflare = class extends StoreOperations {
|
|
|
1289
1341
|
} catch (error) {
|
|
1290
1342
|
const mastraError = new MastraError(
|
|
1291
1343
|
{
|
|
1292
|
-
id: "
|
|
1344
|
+
id: createStorageErrorId("CLOUDFLARE", "LOAD", "FAILED"),
|
|
1293
1345
|
domain: ErrorDomain.STORAGE,
|
|
1294
1346
|
category: ErrorCategory.THIRD_PARTY,
|
|
1295
1347
|
details: {
|
|
@@ -1315,7 +1367,7 @@ var StoreOperationsCloudflare = class extends StoreOperations {
|
|
|
1315
1367
|
} catch (error) {
|
|
1316
1368
|
throw new MastraError(
|
|
1317
1369
|
{
|
|
1318
|
-
id: "
|
|
1370
|
+
id: createStorageErrorId("CLOUDFLARE", "BATCH_INSERT", "FAILED"),
|
|
1319
1371
|
domain: ErrorDomain.STORAGE,
|
|
1320
1372
|
category: ErrorCategory.THIRD_PARTY,
|
|
1321
1373
|
text: `Error in batch insert for table ${input.tableName}`,
|
|
@@ -1387,7 +1439,7 @@ var StoreOperationsCloudflare = class extends StoreOperations {
|
|
|
1387
1439
|
} catch (error) {
|
|
1388
1440
|
throw new MastraError(
|
|
1389
1441
|
{
|
|
1390
|
-
id: "
|
|
1442
|
+
id: createStorageErrorId("CLOUDFLARE", "CREATE_TABLE", "FAILED"),
|
|
1391
1443
|
domain: ErrorDomain.STORAGE,
|
|
1392
1444
|
category: ErrorCategory.THIRD_PARTY,
|
|
1393
1445
|
details: {
|
|
@@ -1419,7 +1471,7 @@ var StoreOperationsCloudflare = class extends StoreOperations {
|
|
|
1419
1471
|
} catch (error) {
|
|
1420
1472
|
throw new MastraError(
|
|
1421
1473
|
{
|
|
1422
|
-
id: "
|
|
1474
|
+
id: createStorageErrorId("CLOUDFLARE", "LIST_NAMESPACE_KEYS", "FAILED"),
|
|
1423
1475
|
domain: ErrorDomain.STORAGE,
|
|
1424
1476
|
category: ErrorCategory.THIRD_PARTY,
|
|
1425
1477
|
details: {
|
|
@@ -1459,17 +1511,7 @@ var StoreOperationsCloudflare = class extends StoreOperations {
|
|
|
1459
1511
|
}
|
|
1460
1512
|
};
|
|
1461
1513
|
function transformScoreRow(row) {
|
|
1462
|
-
|
|
1463
|
-
deserialized.input = safelyParseJSON(row.input);
|
|
1464
|
-
deserialized.output = safelyParseJSON(row.output);
|
|
1465
|
-
deserialized.scorer = safelyParseJSON(row.scorer);
|
|
1466
|
-
deserialized.preprocessStepResult = safelyParseJSON(row.preprocessStepResult);
|
|
1467
|
-
deserialized.analyzeStepResult = safelyParseJSON(row.analyzeStepResult);
|
|
1468
|
-
deserialized.metadata = safelyParseJSON(row.metadata);
|
|
1469
|
-
deserialized.additionalContext = safelyParseJSON(row.additionalContext);
|
|
1470
|
-
deserialized.requestContext = safelyParseJSON(row.requestContext);
|
|
1471
|
-
deserialized.entity = safelyParseJSON(row.entity);
|
|
1472
|
-
return deserialized;
|
|
1514
|
+
return transformScoreRow$1(row);
|
|
1473
1515
|
}
|
|
1474
1516
|
var ScoresStorageCloudflare = class extends ScoresStorage {
|
|
1475
1517
|
operations;
|
|
@@ -1487,7 +1529,7 @@ var ScoresStorageCloudflare = class extends ScoresStorage {
|
|
|
1487
1529
|
} catch (error) {
|
|
1488
1530
|
const mastraError = new MastraError(
|
|
1489
1531
|
{
|
|
1490
|
-
id: "
|
|
1532
|
+
id: createStorageErrorId("CLOUDFLARE", "GET_SCORE_BY_ID", "FAILED"),
|
|
1491
1533
|
domain: ErrorDomain.STORAGE,
|
|
1492
1534
|
category: ErrorCategory.THIRD_PARTY,
|
|
1493
1535
|
text: `Failed to get score by id: ${id}`
|
|
@@ -1506,7 +1548,7 @@ var ScoresStorageCloudflare = class extends ScoresStorage {
|
|
|
1506
1548
|
} catch (error) {
|
|
1507
1549
|
throw new MastraError(
|
|
1508
1550
|
{
|
|
1509
|
-
id: "
|
|
1551
|
+
id: createStorageErrorId("CLOUDFLARE", "SAVE_SCORE", "VALIDATION_FAILED"),
|
|
1510
1552
|
domain: ErrorDomain.STORAGE,
|
|
1511
1553
|
category: ErrorCategory.USER,
|
|
1512
1554
|
details: { scoreId: score.id }
|
|
@@ -1541,7 +1583,7 @@ var ScoresStorageCloudflare = class extends ScoresStorage {
|
|
|
1541
1583
|
} catch (error) {
|
|
1542
1584
|
const mastraError = new MastraError(
|
|
1543
1585
|
{
|
|
1544
|
-
id: "
|
|
1586
|
+
id: createStorageErrorId("CLOUDFLARE", "SAVE_SCORE", "FAILED"),
|
|
1545
1587
|
domain: ErrorDomain.STORAGE,
|
|
1546
1588
|
category: ErrorCategory.THIRD_PARTY,
|
|
1547
1589
|
text: `Failed to save score: ${score.id}`
|
|
@@ -1601,7 +1643,7 @@ var ScoresStorageCloudflare = class extends ScoresStorage {
|
|
|
1601
1643
|
} catch (error) {
|
|
1602
1644
|
const mastraError = new MastraError(
|
|
1603
1645
|
{
|
|
1604
|
-
id: "
|
|
1646
|
+
id: createStorageErrorId("CLOUDFLARE", "GET_SCORES_BY_SCORER_ID", "FAILED"),
|
|
1605
1647
|
domain: ErrorDomain.STORAGE,
|
|
1606
1648
|
category: ErrorCategory.THIRD_PARTY,
|
|
1607
1649
|
text: `Failed to get scores by scorer id: ${scorerId}`
|
|
@@ -1649,7 +1691,7 @@ var ScoresStorageCloudflare = class extends ScoresStorage {
|
|
|
1649
1691
|
} catch (error) {
|
|
1650
1692
|
const mastraError = new MastraError(
|
|
1651
1693
|
{
|
|
1652
|
-
id: "
|
|
1694
|
+
id: createStorageErrorId("CLOUDFLARE", "GET_SCORES_BY_RUN_ID", "FAILED"),
|
|
1653
1695
|
domain: ErrorDomain.STORAGE,
|
|
1654
1696
|
category: ErrorCategory.THIRD_PARTY,
|
|
1655
1697
|
text: `Failed to get scores by run id: ${runId}`
|
|
@@ -1698,7 +1740,7 @@ var ScoresStorageCloudflare = class extends ScoresStorage {
|
|
|
1698
1740
|
} catch (error) {
|
|
1699
1741
|
const mastraError = new MastraError(
|
|
1700
1742
|
{
|
|
1701
|
-
id: "
|
|
1743
|
+
id: createStorageErrorId("CLOUDFLARE", "GET_SCORES_BY_ENTITY_ID", "FAILED"),
|
|
1702
1744
|
domain: ErrorDomain.STORAGE,
|
|
1703
1745
|
category: ErrorCategory.THIRD_PARTY,
|
|
1704
1746
|
text: `Failed to get scores by entity id: ${entityId}, type: ${entityType}`
|
|
@@ -1747,7 +1789,7 @@ var ScoresStorageCloudflare = class extends ScoresStorage {
|
|
|
1747
1789
|
} catch (error) {
|
|
1748
1790
|
const mastraError = new MastraError(
|
|
1749
1791
|
{
|
|
1750
|
-
id: "
|
|
1792
|
+
id: createStorageErrorId("CLOUDFLARE", "GET_SCORES_BY_SPAN", "FAILED"),
|
|
1751
1793
|
domain: ErrorDomain.STORAGE,
|
|
1752
1794
|
category: ErrorCategory.THIRD_PARTY,
|
|
1753
1795
|
text: `Failed to get scores by span: traceId=${traceId}, spanId=${spanId}`
|
|
@@ -1806,7 +1848,7 @@ var WorkflowsStorageCloudflare = class extends WorkflowsStorage {
|
|
|
1806
1848
|
} catch (error) {
|
|
1807
1849
|
throw new MastraError(
|
|
1808
1850
|
{
|
|
1809
|
-
id: "
|
|
1851
|
+
id: createStorageErrorId("CLOUDFLARE", "PERSIST_WORKFLOW_SNAPSHOT", "FAILED"),
|
|
1810
1852
|
domain: ErrorDomain.STORAGE,
|
|
1811
1853
|
category: ErrorCategory.THIRD_PARTY,
|
|
1812
1854
|
text: `Error persisting workflow snapshot for workflow ${params.workflowName}, run ${params.runId}`,
|
|
@@ -1831,7 +1873,7 @@ var WorkflowsStorageCloudflare = class extends WorkflowsStorage {
|
|
|
1831
1873
|
} catch (error) {
|
|
1832
1874
|
const mastraError = new MastraError(
|
|
1833
1875
|
{
|
|
1834
|
-
id: "
|
|
1876
|
+
id: createStorageErrorId("CLOUDFLARE", "LOAD_WORKFLOW_SNAPSHOT", "FAILED"),
|
|
1835
1877
|
domain: ErrorDomain.STORAGE,
|
|
1836
1878
|
category: ErrorCategory.THIRD_PARTY,
|
|
1837
1879
|
text: `Error loading workflow snapshot for workflow ${params.workflowName}, run ${params.runId}`,
|
|
@@ -1890,7 +1932,7 @@ var WorkflowsStorageCloudflare = class extends WorkflowsStorage {
|
|
|
1890
1932
|
if (page < 0 || !Number.isInteger(page)) {
|
|
1891
1933
|
throw new MastraError(
|
|
1892
1934
|
{
|
|
1893
|
-
id: "
|
|
1935
|
+
id: createStorageErrorId("CLOUDFLARE", "LIST_WORKFLOW_RUNS", "INVALID_PAGE"),
|
|
1894
1936
|
domain: ErrorDomain.STORAGE,
|
|
1895
1937
|
category: ErrorCategory.USER,
|
|
1896
1938
|
details: { page }
|
|
@@ -1945,7 +1987,7 @@ var WorkflowsStorageCloudflare = class extends WorkflowsStorage {
|
|
|
1945
1987
|
} catch (error) {
|
|
1946
1988
|
const mastraError = new MastraError(
|
|
1947
1989
|
{
|
|
1948
|
-
id: "
|
|
1990
|
+
id: createStorageErrorId("CLOUDFLARE", "LIST_WORKFLOW_RUNS", "FAILED"),
|
|
1949
1991
|
domain: ErrorDomain.STORAGE,
|
|
1950
1992
|
category: ErrorCategory.THIRD_PARTY
|
|
1951
1993
|
},
|
|
@@ -1983,7 +2025,7 @@ var WorkflowsStorageCloudflare = class extends WorkflowsStorage {
|
|
|
1983
2025
|
} catch (error) {
|
|
1984
2026
|
const mastraError = new MastraError(
|
|
1985
2027
|
{
|
|
1986
|
-
id: "
|
|
2028
|
+
id: createStorageErrorId("CLOUDFLARE", "GET_WORKFLOW_RUN_BY_ID", "FAILED"),
|
|
1987
2029
|
domain: ErrorDomain.STORAGE,
|
|
1988
2030
|
category: ErrorCategory.THIRD_PARTY,
|
|
1989
2031
|
details: {
|
|
@@ -2045,7 +2087,7 @@ var CloudflareStore = class extends MastraStorage {
|
|
|
2045
2087
|
return supports;
|
|
2046
2088
|
}
|
|
2047
2089
|
constructor(config) {
|
|
2048
|
-
super({ id: config.id, name: "Cloudflare" });
|
|
2090
|
+
super({ id: config.id, name: "Cloudflare", disableInit: config.disableInit });
|
|
2049
2091
|
try {
|
|
2050
2092
|
if (isWorkersConfig(config)) {
|
|
2051
2093
|
this.validateWorkersConfig(config);
|
|
@@ -2085,7 +2127,7 @@ var CloudflareStore = class extends MastraStorage {
|
|
|
2085
2127
|
} catch (error) {
|
|
2086
2128
|
throw new MastraError(
|
|
2087
2129
|
{
|
|
2088
|
-
id: "
|
|
2130
|
+
id: createStorageErrorId("CLOUDFLARE", "INIT", "FAILED"),
|
|
2089
2131
|
domain: ErrorDomain.STORAGE,
|
|
2090
2132
|
category: ErrorCategory.THIRD_PARTY
|
|
2091
2133
|
},
|