@mastra/cloudflare 0.0.0-trigger-playground-ui-package-20250506151043 → 0.0.0-tsconfig-compile-20250703214351

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/dist/index.cjs CHANGED
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
2
 
3
+ var agent = require('@mastra/core/agent');
4
+ var error = require('@mastra/core/error');
3
5
  var storage = require('@mastra/core/storage');
4
6
  var Cloudflare = require('cloudflare');
5
7
 
@@ -62,10 +64,15 @@ var CloudflareStore = class extends storage.MastraStorage {
62
64
  });
63
65
  this.logger.info("Using Cloudflare KV REST API");
64
66
  }
65
- } catch (error) {
66
- const message = error instanceof Error ? error.message : String(error);
67
- this.logger.error("Failed to initialize CloudflareStore:", { message });
68
- throw error;
67
+ } catch (error$1) {
68
+ throw new error.MastraError(
69
+ {
70
+ id: "CLOUDFLARE_STORAGE_INIT_FAILED",
71
+ domain: error.ErrorDomain.STORAGE,
72
+ category: error.ErrorCategory.THIRD_PARTY
73
+ },
74
+ error$1
75
+ );
69
76
  }
70
77
  }
71
78
  getBinding(tableName) {
@@ -86,7 +93,25 @@ var CloudflareStore = class extends storage.MastraStorage {
86
93
  }))
87
94
  };
88
95
  }
89
- return await this.client.kv.namespaces.list({ account_id: this.accountId });
96
+ let allNamespaces = [];
97
+ let currentPage = 1;
98
+ const perPage = 50;
99
+ let morePagesExist = true;
100
+ while (morePagesExist) {
101
+ const response = await this.client.kv.namespaces.list({
102
+ account_id: this.accountId,
103
+ page: currentPage,
104
+ per_page: perPage
105
+ });
106
+ if (response.result) {
107
+ allNamespaces = allNamespaces.concat(response.result);
108
+ }
109
+ morePagesExist = response.result ? response.result.length === perPage : false;
110
+ if (morePagesExist) {
111
+ currentPage++;
112
+ }
113
+ }
114
+ return { result: allNamespaces };
90
115
  }
91
116
  async getNamespaceValue(tableName, key) {
92
117
  try {
@@ -166,9 +191,18 @@ var CloudflareStore = class extends storage.MastraStorage {
166
191
  });
167
192
  return response.result;
168
193
  }
169
- } catch (error) {
170
- this.logger.error(`Failed to list keys for ${tableName}:`, error);
171
- throw new Error(`Failed to list keys: ${error.message}`);
194
+ } catch (error$1) {
195
+ throw new error.MastraError(
196
+ {
197
+ id: "CLOUDFLARE_STORAGE_LIST_NAMESPACE_KEYS_FAILED",
198
+ domain: error.ErrorDomain.STORAGE,
199
+ category: error.ErrorCategory.THIRD_PARTY,
200
+ details: {
201
+ tableName
202
+ }
203
+ },
204
+ error$1
205
+ );
172
206
  }
173
207
  }
174
208
  async createNamespaceById(title) {
@@ -219,18 +253,57 @@ var CloudflareStore = class extends storage.MastraStorage {
219
253
  async getNamespaceId(tableName) {
220
254
  const prefix = this.namespacePrefix ? `${this.namespacePrefix}_` : "";
221
255
  try {
222
- if (tableName === storage.TABLE_MESSAGES || tableName === storage.TABLE_THREADS) {
223
- return await this.getOrCreateNamespaceId(`${prefix}mastra_threads`);
224
- } else if (tableName === storage.TABLE_WORKFLOW_SNAPSHOT) {
225
- return await this.getOrCreateNamespaceId(`${prefix}mastra_workflows`);
226
- } else {
227
- return await this.getOrCreateNamespaceId(`${prefix}mastra_evals`);
256
+ const legacyNamespaceId = await this.checkLegacyNamespace(tableName, prefix);
257
+ if (legacyNamespaceId) {
258
+ return legacyNamespaceId;
228
259
  }
260
+ return await this.getOrCreateNamespaceId(`${prefix}${tableName}`);
229
261
  } catch (error) {
230
262
  this.logger.error("Error fetching namespace ID:", error);
231
263
  throw new Error(`Failed to fetch namespace ID for table ${tableName}: ${error.message}`);
232
264
  }
233
265
  }
266
+ LEGACY_NAMESPACE_MAP = {
267
+ [storage.TABLE_MESSAGES]: storage.TABLE_THREADS,
268
+ [storage.TABLE_WORKFLOW_SNAPSHOT]: "mastra_workflows",
269
+ [storage.TABLE_TRACES]: storage.TABLE_EVALS
270
+ };
271
+ /**
272
+ * There were a few legacy mappings for tables such as
273
+ * - messages -> threads
274
+ * - workflow_snapshot -> mastra_workflows
275
+ * - traces -> evals
276
+ * This has been updated to use dedicated namespaces for each table.
277
+ * In the case of data for a table existing in the legacy namespace, warn the user to migrate to the new namespace.
278
+ *
279
+ * @param tableName The table name to check for legacy data
280
+ * @param prefix The namespace prefix
281
+ * @returns The legacy namespace ID if data exists; otherwise, null
282
+ */
283
+ async checkLegacyNamespace(tableName, prefix) {
284
+ const legacyNamespaceBase = this.LEGACY_NAMESPACE_MAP[tableName];
285
+ if (legacyNamespaceBase) {
286
+ const legacyNamespace = `${prefix}${legacyNamespaceBase}`;
287
+ const keyPrefix = this.namespacePrefix ? `${this.namespacePrefix}:` : "";
288
+ const prefixKey = `${keyPrefix}${tableName}:`;
289
+ const legacyId = await this.getNamespaceIdByName(legacyNamespace);
290
+ if (legacyId) {
291
+ const response = await this.client.kv.namespaces.keys.list(legacyId, {
292
+ account_id: this.accountId,
293
+ prefix: prefixKey
294
+ });
295
+ const keys = response.result;
296
+ const hasTableData = keys.length > 0;
297
+ if (hasTableData) {
298
+ this.logger.warn(
299
+ `Using legacy namespace "${legacyNamespace}" for ${tableName}. Consider migrating to a dedicated namespace "${prefix}${tableName}".`
300
+ );
301
+ return legacyId;
302
+ }
303
+ }
304
+ }
305
+ return null;
306
+ }
234
307
  /**
235
308
  * Helper to safely serialize data for KV storage
236
309
  */
@@ -556,15 +629,6 @@ var CloudflareStore = class extends storage.MastraStorage {
556
629
  throw error;
557
630
  }
558
631
  }
559
- ensureDate(date) {
560
- if (!date) return void 0;
561
- return date instanceof Date ? date : new Date(date);
562
- }
563
- serializeDate(date) {
564
- if (!date) return void 0;
565
- const dateObj = this.ensureDate(date);
566
- return dateObj?.toISOString();
567
- }
568
632
  ensureMetadata(metadata) {
569
633
  if (!metadata) return {};
570
634
  return typeof metadata === "string" ? JSON.parse(metadata) : metadata;
@@ -581,15 +645,46 @@ var CloudflareStore = class extends storage.MastraStorage {
581
645
  createdAt: (/* @__PURE__ */ new Date()).toISOString()
582
646
  };
583
647
  await this.putKV({ tableName, key: schemaKey, value: schema, metadata });
584
- } catch (error) {
585
- this.logger.error(`Failed to store schema for ${tableName}:`, error);
586
- throw new Error(`Failed to store schema: ${error.message}`);
648
+ } catch (error$1) {
649
+ throw new error.MastraError(
650
+ {
651
+ id: "CLOUDFLARE_STORAGE_CREATE_TABLE_FAILED",
652
+ domain: error.ErrorDomain.STORAGE,
653
+ category: error.ErrorCategory.THIRD_PARTY,
654
+ details: {
655
+ tableName
656
+ }
657
+ },
658
+ error$1
659
+ );
587
660
  }
588
661
  }
662
+ /**
663
+ * No-op: This backend is schemaless and does not require schema changes.
664
+ * @param tableName Name of the table
665
+ * @param schema Schema of the table
666
+ * @param ifNotExists Array of column names to add if they don't exist
667
+ */
668
+ async alterTable(_args) {
669
+ }
589
670
  async clearTable({ tableName }) {
590
- const keys = await this.listKV(tableName);
591
- if (keys.length > 0) {
592
- await Promise.all(keys.map((keyObj) => this.deleteKV(tableName, keyObj.name)));
671
+ try {
672
+ const keys = await this.listKV(tableName);
673
+ if (keys.length > 0) {
674
+ await Promise.all(keys.map((keyObj) => this.deleteKV(tableName, keyObj.name)));
675
+ }
676
+ } catch (error$1) {
677
+ throw new error.MastraError(
678
+ {
679
+ id: "CLOUDFLARE_STORAGE_CLEAR_TABLE_FAILED",
680
+ domain: error.ErrorDomain.STORAGE,
681
+ category: error.ErrorCategory.THIRD_PARTY,
682
+ details: {
683
+ tableName
684
+ }
685
+ },
686
+ error$1
687
+ );
593
688
  }
594
689
  }
595
690
  async insert({
@@ -606,10 +701,18 @@ var CloudflareStore = class extends storage.MastraStorage {
606
701
  };
607
702
  await this.validateRecord(processedRecord, tableName);
608
703
  await this.putKV({ tableName, key, value: processedRecord });
609
- } catch (error) {
610
- const message = error instanceof Error ? error.message : String(error);
611
- this.logger.error(`Failed to insert record for ${tableName}:`, { message });
612
- throw error;
704
+ } catch (error$1) {
705
+ throw new error.MastraError(
706
+ {
707
+ id: "CLOUDFLARE_STORAGE_INSERT_FAILED",
708
+ domain: error.ErrorDomain.STORAGE,
709
+ category: error.ErrorCategory.THIRD_PARTY,
710
+ details: {
711
+ tableName
712
+ }
713
+ },
714
+ error$1
715
+ );
613
716
  }
614
717
  }
615
718
  async load({ tableName, keys }) {
@@ -624,10 +727,20 @@ var CloudflareStore = class extends storage.MastraStorage {
624
727
  metadata: this.ensureMetadata(data.metadata)
625
728
  };
626
729
  return processed;
627
- } catch (error) {
628
- this.logger.error(`Failed to load data for ${tableName}:`, {
629
- error: error instanceof Error ? error.message : String(error)
630
- });
730
+ } catch (error$1) {
731
+ const mastraError = new error.MastraError(
732
+ {
733
+ id: "CLOUDFLARE_STORAGE_LOAD_FAILED",
734
+ domain: error.ErrorDomain.STORAGE,
735
+ category: error.ErrorCategory.THIRD_PARTY,
736
+ details: {
737
+ tableName
738
+ }
739
+ },
740
+ error$1
741
+ );
742
+ this.logger?.trackException(mastraError);
743
+ this.logger?.error(mastraError.toString());
631
744
  return null;
632
745
  }
633
746
  }
@@ -641,10 +754,20 @@ var CloudflareStore = class extends storage.MastraStorage {
641
754
  updatedAt: this.ensureDate(thread.updatedAt),
642
755
  metadata: this.ensureMetadata(thread.metadata)
643
756
  };
644
- } catch (error) {
645
- this.logger.error(`Error processing thread ${threadId}:`, {
646
- error: error instanceof Error ? error.message : String(error)
647
- });
757
+ } catch (error$1) {
758
+ const mastraError = new error.MastraError(
759
+ {
760
+ id: "CLOUDFLARE_STORAGE_GET_THREAD_BY_ID_FAILED",
761
+ domain: error.ErrorDomain.STORAGE,
762
+ category: error.ErrorCategory.THIRD_PARTY,
763
+ details: {
764
+ threadId
765
+ }
766
+ },
767
+ error$1
768
+ );
769
+ this.logger?.trackException(mastraError);
770
+ this.logger?.error(mastraError.toString());
648
771
  return null;
649
772
  }
650
773
  }
@@ -664,17 +787,39 @@ var CloudflareStore = class extends storage.MastraStorage {
664
787
  updatedAt: this.ensureDate(thread.updatedAt),
665
788
  metadata: this.ensureMetadata(thread.metadata)
666
789
  };
667
- } catch (error) {
668
- const message = error instanceof Error ? error.message : String(error);
669
- this.logger.error(`Error processing thread from key ${keyObj.name}:`, { message });
790
+ } catch (error$1) {
791
+ const mastraError = new error.MastraError(
792
+ {
793
+ id: "CLOUDFLARE_STORAGE_GET_THREADS_BY_RESOURCE_ID_FAILED",
794
+ domain: error.ErrorDomain.STORAGE,
795
+ category: error.ErrorCategory.THIRD_PARTY,
796
+ details: {
797
+ resourceId
798
+ }
799
+ },
800
+ error$1
801
+ );
802
+ this.logger?.trackException(mastraError);
803
+ this.logger?.error(mastraError.toString());
670
804
  return null;
671
805
  }
672
806
  })
673
807
  );
674
808
  return threads.filter((thread) => thread !== null);
675
- } catch (error) {
676
- const message = error instanceof Error ? error.message : String(error);
677
- this.logger.error(`Error getting threads for resourceId ${resourceId}:`, { message });
809
+ } catch (error$1) {
810
+ const mastraError = new error.MastraError(
811
+ {
812
+ id: "CLOUDFLARE_STORAGE_GET_THREADS_BY_RESOURCE_ID_FAILED",
813
+ domain: error.ErrorDomain.STORAGE,
814
+ category: error.ErrorCategory.THIRD_PARTY,
815
+ details: {
816
+ resourceId
817
+ }
818
+ },
819
+ error$1
820
+ );
821
+ this.logger?.trackException(mastraError);
822
+ this.logger?.error(mastraError.toString());
678
823
  return [];
679
824
  }
680
825
  }
@@ -682,10 +827,18 @@ var CloudflareStore = class extends storage.MastraStorage {
682
827
  try {
683
828
  await this.insert({ tableName: storage.TABLE_THREADS, record: thread });
684
829
  return thread;
685
- } catch (error) {
686
- const message = error instanceof Error ? error.message : String(error);
687
- this.logger.error("Error saving thread:", { message });
688
- throw error;
830
+ } catch (error$1) {
831
+ throw new error.MastraError(
832
+ {
833
+ id: "CLOUDFLARE_STORAGE_SAVE_THREAD_FAILED",
834
+ domain: error.ErrorDomain.STORAGE,
835
+ category: error.ErrorCategory.THIRD_PARTY,
836
+ details: {
837
+ threadId: thread.id
838
+ }
839
+ },
840
+ error$1
841
+ );
689
842
  }
690
843
  }
691
844
  async updateThread({
@@ -709,10 +862,19 @@ var CloudflareStore = class extends storage.MastraStorage {
709
862
  };
710
863
  await this.insert({ tableName: storage.TABLE_THREADS, record: updatedThread });
711
864
  return updatedThread;
712
- } catch (error) {
713
- const message = error instanceof Error ? error.message : String(error);
714
- this.logger.error(`Error updating thread ${id}:`, { message });
715
- throw error;
865
+ } catch (error$1) {
866
+ throw new error.MastraError(
867
+ {
868
+ id: "CLOUDFLARE_STORAGE_UPDATE_THREAD_FAILED",
869
+ domain: error.ErrorDomain.STORAGE,
870
+ category: error.ErrorCategory.THIRD_PARTY,
871
+ details: {
872
+ threadId: id,
873
+ title
874
+ }
875
+ },
876
+ error$1
877
+ );
716
878
  }
717
879
  }
718
880
  async deleteThread({ threadId }) {
@@ -731,10 +893,18 @@ var CloudflareStore = class extends storage.MastraStorage {
731
893
  // Delete thread
732
894
  this.deleteKV(storage.TABLE_THREADS, this.getKey(storage.TABLE_THREADS, { id: threadId }))
733
895
  ]);
734
- } catch (error) {
735
- const message = error instanceof Error ? error.message : String(error);
736
- this.logger.error(`Error deleting thread ${threadId}:`, { message });
737
- throw error;
896
+ } catch (error$1) {
897
+ throw new error.MastraError(
898
+ {
899
+ id: "CLOUDFLARE_STORAGE_DELETE_THREAD_FAILED",
900
+ domain: error.ErrorDomain.STORAGE,
901
+ category: error.ErrorCategory.THIRD_PARTY,
902
+ details: {
903
+ threadId
904
+ }
905
+ },
906
+ error$1
907
+ );
738
908
  }
739
909
  }
740
910
  getMessageKey(threadId, messageId) {
@@ -755,7 +925,8 @@ var CloudflareStore = class extends storage.MastraStorage {
755
925
  throw error;
756
926
  }
757
927
  }
758
- async saveMessages({ messages }) {
928
+ async saveMessages(args) {
929
+ const { messages, format = "v1" } = args;
759
930
  if (!Array.isArray(messages) || messages.length === 0) return [];
760
931
  try {
761
932
  const validatedMessages = messages.map((message, index) => {
@@ -771,15 +942,17 @@ var CloudflareStore = class extends storage.MastraStorage {
771
942
  return {
772
943
  ...message,
773
944
  createdAt: this.ensureDate(message.createdAt),
774
- type: message.type || "text",
945
+ type: message.type || "v2",
775
946
  _index: index
776
947
  };
777
- });
948
+ }).filter((m) => !!m);
778
949
  const messagesByThread = validatedMessages.reduce((acc, message) => {
779
- if (!acc.has(message.threadId)) {
950
+ if (message.threadId && !acc.has(message.threadId)) {
780
951
  acc.set(message.threadId, []);
781
952
  }
782
- acc.get(message.threadId).push(message);
953
+ if (message.threadId) {
954
+ acc.get(message.threadId).push(message);
955
+ }
783
956
  return acc;
784
957
  }, /* @__PURE__ */ new Map());
785
958
  await Promise.all(
@@ -791,7 +964,7 @@ var CloudflareStore = class extends storage.MastraStorage {
791
964
  }
792
965
  await Promise.all(
793
966
  threadMessages.map(async (message) => {
794
- const key = await this.getMessageKey(threadId, message.id);
967
+ const key = this.getMessageKey(threadId, message.id);
795
968
  const { _index, ...cleanMessage } = message;
796
969
  const serializedMessage = {
797
970
  ...cleanMessage,
@@ -803,28 +976,46 @@ var CloudflareStore = class extends storage.MastraStorage {
803
976
  const orderKey = this.getThreadMessagesKey(threadId);
804
977
  const entries = await this.updateSorting(threadMessages);
805
978
  await this.updateSortedMessages(orderKey, entries);
806
- } catch (error) {
807
- const errorMessage = error instanceof Error ? error.message : String(error);
808
- this.logger.error(`Error processing messages for thread ${threadId}: ${errorMessage}`);
809
- throw error;
979
+ } catch (error$1) {
980
+ throw new error.MastraError(
981
+ {
982
+ id: "CLOUDFLARE_STORAGE_SAVE_MESSAGES_FAILED",
983
+ domain: error.ErrorDomain.STORAGE,
984
+ category: error.ErrorCategory.THIRD_PARTY,
985
+ details: {
986
+ threadId
987
+ }
988
+ },
989
+ error$1
990
+ );
810
991
  }
811
992
  })
812
993
  );
813
- return validatedMessages.map(({ _index, ...message }) => message);
814
- } catch (error) {
815
- const errorMessage = error instanceof Error ? error.message : String(error);
816
- this.logger.error(`Error saving messages: ${errorMessage}`);
817
- throw error;
994
+ const prepared = validatedMessages.map(
995
+ ({ _index, ...message }) => ({ ...message, type: message.type !== "v2" ? message.type : void 0 })
996
+ );
997
+ const list = new agent.MessageList().add(prepared, "memory");
998
+ if (format === `v2`) return list.get.all.v2();
999
+ return list.get.all.v1();
1000
+ } catch (error$1) {
1001
+ throw new error.MastraError(
1002
+ {
1003
+ id: "CLOUDFLARE_STORAGE_SAVE_MESSAGES_FAILED",
1004
+ domain: error.ErrorDomain.STORAGE,
1005
+ category: error.ErrorCategory.THIRD_PARTY
1006
+ },
1007
+ error$1
1008
+ );
818
1009
  }
819
1010
  }
820
- async getMessages({ threadId, selectBy }) {
1011
+ async getMessages({
1012
+ threadId,
1013
+ resourceId,
1014
+ selectBy,
1015
+ format
1016
+ }) {
821
1017
  if (!threadId) throw new Error("threadId is required");
822
- let limit = 40;
823
- if (typeof selectBy?.last === "number") {
824
- limit = Math.max(0, selectBy.last);
825
- } else if (selectBy?.last === false) {
826
- limit = 0;
827
- }
1018
+ const limit = this.resolveMessageLimit({ last: selectBy?.last, defaultLimit: 40 });
828
1019
  const messageIds = /* @__PURE__ */ new Set();
829
1020
  if (limit === 0 && !selectBy?.include?.length) return [];
830
1021
  try {
@@ -844,18 +1035,46 @@ var CloudflareStore = class extends storage.MastraStorage {
844
1035
  if (indexA !== void 0 && indexB !== void 0) return orderMap.get(a.id) - orderMap.get(b.id);
845
1036
  return new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime();
846
1037
  });
847
- } catch (error) {
848
- const errorMessage = error instanceof Error ? error.message : String(error);
849
- this.logger.warn(`Error sorting messages, falling back to creation time: ${errorMessage}`);
1038
+ } catch (error$1) {
1039
+ const mastraError = new error.MastraError(
1040
+ {
1041
+ id: "CLOUDFLARE_STORAGE_SORT_MESSAGES_FAILED",
1042
+ domain: error.ErrorDomain.STORAGE,
1043
+ category: error.ErrorCategory.THIRD_PARTY,
1044
+ text: `Error sorting messages for thread ${threadId} falling back to creation time`,
1045
+ details: {
1046
+ threadId
1047
+ }
1048
+ },
1049
+ error$1
1050
+ );
1051
+ this.logger?.trackException(mastraError);
1052
+ this.logger?.error(mastraError.toString());
850
1053
  messages.sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime());
851
1054
  }
852
- return messages.map(({ _index, ...message }) => ({
1055
+ const prepared = messages.map(({ _index, ...message }) => ({
853
1056
  ...message,
1057
+ type: message.type === `v2` ? void 0 : message.type,
854
1058
  createdAt: this.ensureDate(message.createdAt)
855
1059
  }));
856
- } catch (error) {
857
- const errorMessage = error instanceof Error ? error.message : String(error);
858
- this.logger.error(`Error retrieving messages for thread ${threadId}: ${errorMessage}`);
1060
+ const list = new agent.MessageList({ threadId, resourceId }).add(prepared, "memory");
1061
+ if (format === `v1`) return list.get.all.v1();
1062
+ return list.get.all.v2();
1063
+ } catch (error$1) {
1064
+ const mastraError = new error.MastraError(
1065
+ {
1066
+ id: "CLOUDFLARE_STORAGE_GET_MESSAGES_FAILED",
1067
+ domain: error.ErrorDomain.STORAGE,
1068
+ category: error.ErrorCategory.THIRD_PARTY,
1069
+ text: `Error retrieving messages for thread ${threadId}`,
1070
+ details: {
1071
+ threadId
1072
+ }
1073
+ },
1074
+ error$1
1075
+ );
1076
+ this.logger?.trackException(mastraError);
1077
+ this.logger?.error(mastraError.toString());
859
1078
  return [];
860
1079
  }
861
1080
  }
@@ -866,7 +1085,7 @@ var CloudflareStore = class extends storage.MastraStorage {
866
1085
  }
867
1086
  }
868
1087
  validateWorkflowState(state) {
869
- if (!state?.runId || !state?.value || !state?.context?.steps || !state?.context?.triggerData || !state?.context?.attempts || !state?.activePaths) {
1088
+ if (!state?.runId || !state?.value || !state?.context?.input || !state?.activePaths) {
870
1089
  throw new Error("Invalid workflow state structure");
871
1090
  }
872
1091
  }
@@ -882,18 +1101,17 @@ var CloudflareStore = class extends storage.MastraStorage {
882
1101
  return normalizedSteps;
883
1102
  }
884
1103
  normalizeWorkflowState(data) {
885
- const steps = data.context?.stepResults || data.context?.steps || {};
886
1104
  return {
887
1105
  runId: data.runId,
888
1106
  value: data.value,
889
- context: {
890
- steps: this.normalizeSteps(steps),
891
- triggerData: data.context?.triggerData || {},
892
- attempts: data.context?.attempts || {}
893
- },
1107
+ context: data.context,
1108
+ serializedStepGraph: data.serializedStepGraph,
894
1109
  suspendedPaths: data.suspendedPaths || {},
895
1110
  activePaths: data.activePaths || [],
896
- timestamp: data.timestamp || Date.now()
1111
+ timestamp: data.timestamp || Date.now(),
1112
+ status: data.status,
1113
+ result: data.result,
1114
+ error: data.error
897
1115
  };
898
1116
  }
899
1117
  async persistWorkflowSnapshot(params) {
@@ -913,10 +1131,21 @@ var CloudflareStore = class extends storage.MastraStorage {
913
1131
  updatedAt: /* @__PURE__ */ new Date()
914
1132
  }
915
1133
  });
916
- } catch (error) {
917
- const message = error instanceof Error ? error.message : String(error);
918
- this.logger.error("Error persisting workflow snapshot:", { message });
919
- throw error;
1134
+ } catch (error$1) {
1135
+ throw new error.MastraError(
1136
+ {
1137
+ id: "CLOUDFLARE_STORAGE_PERSIST_WORKFLOW_SNAPSHOT_FAILED",
1138
+ domain: error.ErrorDomain.STORAGE,
1139
+ category: error.ErrorCategory.THIRD_PARTY,
1140
+ text: `Error persisting workflow snapshot for namespace ${params.namespace}, workflow ${params.workflowName}, run ${params.runId}`,
1141
+ details: {
1142
+ namespace: params.namespace,
1143
+ workflowName: params.workflowName,
1144
+ runId: params.runId
1145
+ }
1146
+ },
1147
+ error$1
1148
+ );
920
1149
  }
921
1150
  }
922
1151
  async loadWorkflowSnapshot(params) {
@@ -929,10 +1158,23 @@ var CloudflareStore = class extends storage.MastraStorage {
929
1158
  const state = this.normalizeWorkflowState(data.snapshot || data);
930
1159
  this.validateWorkflowState(state);
931
1160
  return state;
932
- } catch (error) {
933
- this.logger.error("Error loading workflow snapshot:", {
934
- error: error instanceof Error ? error.message : String(error)
935
- });
1161
+ } catch (error$1) {
1162
+ const mastraError = new error.MastraError(
1163
+ {
1164
+ id: "CLOUDFLARE_STORAGE_LOAD_WORKFLOW_SNAPSHOT_FAILED",
1165
+ domain: error.ErrorDomain.STORAGE,
1166
+ category: error.ErrorCategory.THIRD_PARTY,
1167
+ text: `Error loading workflow snapshot for namespace ${params.namespace}, workflow ${params.workflowName}, run ${params.runId}`,
1168
+ details: {
1169
+ namespace: params.namespace,
1170
+ workflowName: params.workflowName,
1171
+ runId: params.runId
1172
+ }
1173
+ },
1174
+ error$1
1175
+ );
1176
+ this.logger?.trackException(mastraError);
1177
+ this.logger?.error(mastraError.toString());
936
1178
  return null;
937
1179
  }
938
1180
  }
@@ -951,10 +1193,19 @@ var CloudflareStore = class extends storage.MastraStorage {
951
1193
  await this.putKV({ tableName: input.tableName, key, value: processedRecord });
952
1194
  })
953
1195
  );
954
- } catch (error) {
955
- const message = error instanceof Error ? error.message : String(error);
956
- this.logger.error("Error in batch insert:", { message });
957
- throw error;
1196
+ } catch (error$1) {
1197
+ throw new error.MastraError(
1198
+ {
1199
+ id: "CLOUDFLARE_STORAGE_BATCH_INSERT_FAILED",
1200
+ domain: error.ErrorDomain.STORAGE,
1201
+ category: error.ErrorCategory.THIRD_PARTY,
1202
+ text: `Error in batch insert for table ${input.tableName}`,
1203
+ details: {
1204
+ tableName: input.tableName
1205
+ }
1206
+ },
1207
+ error$1
1208
+ );
958
1209
  }
959
1210
  }
960
1211
  async getTraces({
@@ -1033,9 +1284,18 @@ var CloudflareStore = class extends storage.MastraStorage {
1033
1284
  other: this.parseJSON(record.other) || {},
1034
1285
  createdAt: record.createdAt
1035
1286
  }));
1036
- } catch (error) {
1037
- const message = error instanceof Error ? error.message : String(error);
1038
- this.logger.error("Failed to get traces:", { message });
1287
+ } catch (error$1) {
1288
+ const mastraError = new error.MastraError(
1289
+ {
1290
+ id: "CLOUDFLARE_STORAGE_GET_TRACES_FAILED",
1291
+ domain: error.ErrorDomain.STORAGE,
1292
+ category: error.ErrorCategory.THIRD_PARTY,
1293
+ text: `Failed to get traces`
1294
+ },
1295
+ error$1
1296
+ );
1297
+ this.logger?.trackException(mastraError);
1298
+ this.logger?.error(mastraError.toString());
1039
1299
  return [];
1040
1300
  }
1041
1301
  }
@@ -1050,7 +1310,12 @@ var CloudflareStore = class extends storage.MastraStorage {
1050
1310
  return value;
1051
1311
  }
1052
1312
  getEvalsByAgentName(_agentName, _type) {
1053
- throw new Error("Method not implemented.");
1313
+ throw new error.MastraError({
1314
+ id: "CLOUDFLARE_STORAGE_GET_EVALS_BY_AGENT_NAME_FAILED",
1315
+ domain: error.ErrorDomain.STORAGE,
1316
+ category: error.ErrorCategory.THIRD_PARTY,
1317
+ text: `Failed to get evals by agent name`
1318
+ });
1054
1319
  }
1055
1320
  parseWorkflowRun(row) {
1056
1321
  let parsedSnapshot = row.snapshot;
@@ -1132,9 +1397,17 @@ var CloudflareStore = class extends storage.MastraStorage {
1132
1397
  runs: pagedRuns,
1133
1398
  total: runs.length
1134
1399
  };
1135
- } catch (error) {
1136
- const message = error instanceof Error ? error.message : String(error);
1137
- this.logger.error("Error in getWorkflowRuns:", { message });
1400
+ } catch (error$1) {
1401
+ const mastraError = new error.MastraError(
1402
+ {
1403
+ id: "CLOUDFLARE_STORAGE_GET_WORKFLOW_RUNS_FAILED",
1404
+ domain: error.ErrorDomain.STORAGE,
1405
+ category: error.ErrorCategory.THIRD_PARTY
1406
+ },
1407
+ error$1
1408
+ );
1409
+ this.logger?.trackException(mastraError);
1410
+ this.logger?.error(mastraError.toString());
1138
1411
  return { runs: [], total: 0 };
1139
1412
  }
1140
1413
  }
@@ -1156,14 +1429,55 @@ var CloudflareStore = class extends storage.MastraStorage {
1156
1429
  const state = this.normalizeWorkflowState(data.snapshot || data);
1157
1430
  this.validateWorkflowState(state);
1158
1431
  return this.parseWorkflowRun({ ...data, snapshot: state });
1159
- } catch (error) {
1160
- const message = error instanceof Error ? error.message : String(error);
1161
- this.logger.error("Error in getWorkflowRunById:", { message });
1432
+ } catch (error$1) {
1433
+ const mastraError = new error.MastraError(
1434
+ {
1435
+ id: "CLOUDFLARE_STORAGE_GET_WORKFLOW_RUN_BY_ID_FAILED",
1436
+ domain: error.ErrorDomain.STORAGE,
1437
+ category: error.ErrorCategory.THIRD_PARTY,
1438
+ details: {
1439
+ namespace,
1440
+ workflowName,
1441
+ runId
1442
+ }
1443
+ },
1444
+ error$1
1445
+ );
1446
+ this.logger?.trackException(mastraError);
1447
+ this.logger?.error(mastraError.toString());
1162
1448
  return null;
1163
1449
  }
1164
1450
  }
1451
+ async getTracesPaginated(_args) {
1452
+ throw new error.MastraError({
1453
+ id: "CLOUDFLARE_STORAGE_GET_TRACES_PAGINATED_FAILED",
1454
+ domain: error.ErrorDomain.STORAGE,
1455
+ category: error.ErrorCategory.THIRD_PARTY,
1456
+ text: "Method not implemented."
1457
+ });
1458
+ }
1459
+ async getThreadsByResourceIdPaginated(_args) {
1460
+ throw new error.MastraError({
1461
+ id: "CLOUDFLARE_STORAGE_GET_THREADS_BY_RESOURCE_ID_PAGINATED_FAILED",
1462
+ domain: error.ErrorDomain.STORAGE,
1463
+ category: error.ErrorCategory.THIRD_PARTY,
1464
+ text: "Method not implemented."
1465
+ });
1466
+ }
1467
+ async getMessagesPaginated(_args) {
1468
+ throw new error.MastraError({
1469
+ id: "CLOUDFLARE_STORAGE_GET_MESSAGES_PAGINATED_FAILED",
1470
+ domain: error.ErrorDomain.STORAGE,
1471
+ category: error.ErrorCategory.THIRD_PARTY,
1472
+ text: "Method not implemented."
1473
+ });
1474
+ }
1165
1475
  async close() {
1166
1476
  }
1477
+ async updateMessages(_args) {
1478
+ this.logger.error("updateMessages is not yet implemented in CloudflareStore");
1479
+ throw new Error("Method not implemented");
1480
+ }
1167
1481
  };
1168
1482
 
1169
1483
  exports.CloudflareStore = CloudflareStore;