@mastra/cloudflare-d1 0.11.1-alpha.0 → 0.11.1-alpha.2
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/_tsup-dts-rollup.d.cts +6 -0
- package/dist/_tsup-dts-rollup.d.ts +6 -0
- package/dist/index.cjs +490 -207
- package/dist/index.js +470 -187
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var agent = require('@mastra/core/agent');
|
|
4
|
+
var error = require('@mastra/core/error');
|
|
4
5
|
var storage = require('@mastra/core/storage');
|
|
5
6
|
var Cloudflare = require('cloudflare');
|
|
6
7
|
var utils = require('@mastra/core/utils');
|
|
@@ -256,27 +257,39 @@ var D1Store = class extends storage.MastraStorage {
|
|
|
256
257
|
* @param config Configuration for D1 access (either REST API or Workers Binding API)
|
|
257
258
|
*/
|
|
258
259
|
constructor(config) {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
this.tablePrefix = config.tablePrefix || "";
|
|
264
|
-
if ("binding" in config) {
|
|
265
|
-
if (!config.binding) {
|
|
266
|
-
throw new Error("D1 binding is required when using Workers Binding API");
|
|
260
|
+
try {
|
|
261
|
+
super({ name: "D1" });
|
|
262
|
+
if (config.tablePrefix && !/^[a-zA-Z0-9_]*$/.test(config.tablePrefix)) {
|
|
263
|
+
throw new Error("Invalid tablePrefix: only letters, numbers, and underscores are allowed.");
|
|
267
264
|
}
|
|
268
|
-
this.
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
265
|
+
this.tablePrefix = config.tablePrefix || "";
|
|
266
|
+
if ("binding" in config) {
|
|
267
|
+
if (!config.binding) {
|
|
268
|
+
throw new Error("D1 binding is required when using Workers Binding API");
|
|
269
|
+
}
|
|
270
|
+
this.binding = config.binding;
|
|
271
|
+
this.logger.info("Using D1 Workers Binding API");
|
|
272
|
+
} else {
|
|
273
|
+
if (!config.accountId || !config.databaseId || !config.apiToken) {
|
|
274
|
+
throw new Error("accountId, databaseId, and apiToken are required when using REST API");
|
|
275
|
+
}
|
|
276
|
+
this.accountId = config.accountId;
|
|
277
|
+
this.databaseId = config.databaseId;
|
|
278
|
+
this.client = new Cloudflare__default.default({
|
|
279
|
+
apiToken: config.apiToken
|
|
280
|
+
});
|
|
281
|
+
this.logger.info("Using D1 REST API");
|
|
273
282
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
283
|
+
} catch (error$1) {
|
|
284
|
+
throw new error.MastraError(
|
|
285
|
+
{
|
|
286
|
+
id: "CLOUDFLARE_D1_STORAGE_INITIALIZATION_ERROR",
|
|
287
|
+
domain: error.ErrorDomain.STORAGE,
|
|
288
|
+
category: error.ErrorCategory.SYSTEM,
|
|
289
|
+
text: "Error initializing D1Store"
|
|
290
|
+
},
|
|
291
|
+
error$1
|
|
292
|
+
);
|
|
280
293
|
}
|
|
281
294
|
}
|
|
282
295
|
// Helper method to get the full table name with prefix
|
|
@@ -468,16 +481,25 @@ var D1Store = class extends storage.MastraStorage {
|
|
|
468
481
|
if (tableName === storage.TABLE_WORKFLOW_SNAPSHOT) {
|
|
469
482
|
tableConstraints.push("UNIQUE (workflow_name, run_id)");
|
|
470
483
|
}
|
|
471
|
-
const query = createSqlBuilder().createTable(fullTableName, columnDefinitions, tableConstraints);
|
|
472
|
-
const { sql, params } = query.build();
|
|
473
484
|
try {
|
|
485
|
+
const query = createSqlBuilder().createTable(fullTableName, columnDefinitions, tableConstraints);
|
|
486
|
+
const { sql, params } = query.build();
|
|
474
487
|
await this.executeQuery({ sql, params });
|
|
475
488
|
this.logger.debug(`Created table ${fullTableName}`);
|
|
476
|
-
} catch (error) {
|
|
489
|
+
} catch (error$1) {
|
|
477
490
|
this.logger.error(`Error creating table ${fullTableName}:`, {
|
|
478
|
-
message: error instanceof Error ? error.message : String(error)
|
|
491
|
+
message: error$1 instanceof Error ? error$1.message : String(error$1)
|
|
479
492
|
});
|
|
480
|
-
throw new
|
|
493
|
+
throw new error.MastraError(
|
|
494
|
+
{
|
|
495
|
+
id: "CLOUDFLARE_D1_STORAGE_CREATE_TABLE_ERROR",
|
|
496
|
+
domain: error.ErrorDomain.STORAGE,
|
|
497
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
498
|
+
text: `Failed to create table ${fullTableName}: ${error$1 instanceof Error ? error$1.message : String(error$1)}`,
|
|
499
|
+
details: { tableName }
|
|
500
|
+
},
|
|
501
|
+
error$1
|
|
502
|
+
);
|
|
481
503
|
}
|
|
482
504
|
}
|
|
483
505
|
/**
|
|
@@ -506,11 +528,17 @@ var D1Store = class extends storage.MastraStorage {
|
|
|
506
528
|
this.logger.debug(`Added column ${columnName} to table ${fullTableName}`);
|
|
507
529
|
}
|
|
508
530
|
}
|
|
509
|
-
} catch (error) {
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
531
|
+
} catch (error$1) {
|
|
532
|
+
throw new error.MastraError(
|
|
533
|
+
{
|
|
534
|
+
id: "CLOUDFLARE_D1_STORAGE_ALTER_TABLE_ERROR",
|
|
535
|
+
domain: error.ErrorDomain.STORAGE,
|
|
536
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
537
|
+
text: `Failed to alter table ${fullTableName}: ${error$1 instanceof Error ? error$1.message : String(error$1)}`,
|
|
538
|
+
details: { tableName }
|
|
539
|
+
},
|
|
540
|
+
error$1
|
|
541
|
+
);
|
|
514
542
|
}
|
|
515
543
|
}
|
|
516
544
|
async clearTable({ tableName }) {
|
|
@@ -520,11 +548,17 @@ var D1Store = class extends storage.MastraStorage {
|
|
|
520
548
|
const { sql, params } = query.build();
|
|
521
549
|
await this.executeQuery({ sql, params });
|
|
522
550
|
this.logger.debug(`Cleared table ${fullTableName}`);
|
|
523
|
-
} catch (error) {
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
551
|
+
} catch (error$1) {
|
|
552
|
+
throw new error.MastraError(
|
|
553
|
+
{
|
|
554
|
+
id: "CLOUDFLARE_D1_STORAGE_CLEAR_TABLE_ERROR",
|
|
555
|
+
domain: error.ErrorDomain.STORAGE,
|
|
556
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
557
|
+
text: `Failed to clear table ${fullTableName}: ${error$1 instanceof Error ? error$1.message : String(error$1)}`,
|
|
558
|
+
details: { tableName }
|
|
559
|
+
},
|
|
560
|
+
error$1
|
|
561
|
+
);
|
|
528
562
|
}
|
|
529
563
|
}
|
|
530
564
|
async processRecord(record) {
|
|
@@ -543,10 +577,17 @@ var D1Store = class extends storage.MastraStorage {
|
|
|
543
577
|
const { sql, params } = query.build();
|
|
544
578
|
try {
|
|
545
579
|
await this.executeQuery({ sql, params });
|
|
546
|
-
} catch (error) {
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
580
|
+
} catch (error$1) {
|
|
581
|
+
throw new error.MastraError(
|
|
582
|
+
{
|
|
583
|
+
id: "CLOUDFLARE_D1_STORAGE_INSERT_ERROR",
|
|
584
|
+
domain: error.ErrorDomain.STORAGE,
|
|
585
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
586
|
+
text: `Failed to insert into ${fullTableName}: ${error$1 instanceof Error ? error$1.message : String(error$1)}`,
|
|
587
|
+
details: { tableName }
|
|
588
|
+
},
|
|
589
|
+
error$1
|
|
590
|
+
);
|
|
550
591
|
}
|
|
551
592
|
}
|
|
552
593
|
async load({ tableName, keys }) {
|
|
@@ -571,11 +612,17 @@ var D1Store = class extends storage.MastraStorage {
|
|
|
571
612
|
processedResult[key] = this.deserializeValue(value);
|
|
572
613
|
}
|
|
573
614
|
return processedResult;
|
|
574
|
-
} catch (error) {
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
615
|
+
} catch (error$1) {
|
|
616
|
+
throw new error.MastraError(
|
|
617
|
+
{
|
|
618
|
+
id: "CLOUDFLARE_D1_STORAGE_LOAD_ERROR",
|
|
619
|
+
domain: error.ErrorDomain.STORAGE,
|
|
620
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
621
|
+
text: `Failed to load from ${fullTableName}: ${error$1 instanceof Error ? error$1.message : String(error$1)}`,
|
|
622
|
+
details: { tableName }
|
|
623
|
+
},
|
|
624
|
+
error$1
|
|
625
|
+
);
|
|
579
626
|
}
|
|
580
627
|
}
|
|
581
628
|
async getThreadById({ threadId }) {
|
|
@@ -591,10 +638,19 @@ var D1Store = class extends storage.MastraStorage {
|
|
|
591
638
|
updatedAt: this.ensureDate(thread.updatedAt),
|
|
592
639
|
metadata: typeof thread.metadata === "string" ? JSON.parse(thread.metadata || "{}") : thread.metadata || {}
|
|
593
640
|
};
|
|
594
|
-
} catch (error) {
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
641
|
+
} catch (error$1) {
|
|
642
|
+
const mastraError = new error.MastraError(
|
|
643
|
+
{
|
|
644
|
+
id: "CLOUDFLARE_D1_STORAGE_GET_THREAD_BY_ID_ERROR",
|
|
645
|
+
domain: error.ErrorDomain.STORAGE,
|
|
646
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
647
|
+
text: `Error processing thread ${threadId}: ${error$1 instanceof Error ? error$1.message : String(error$1)}`,
|
|
648
|
+
details: { threadId }
|
|
649
|
+
},
|
|
650
|
+
error$1
|
|
651
|
+
);
|
|
652
|
+
this.logger?.error(mastraError.toString());
|
|
653
|
+
this.logger?.trackException(mastraError);
|
|
598
654
|
return null;
|
|
599
655
|
}
|
|
600
656
|
}
|
|
@@ -613,10 +669,19 @@ var D1Store = class extends storage.MastraStorage {
|
|
|
613
669
|
updatedAt: this.ensureDate(thread.updatedAt),
|
|
614
670
|
metadata: typeof thread.metadata === "string" ? JSON.parse(thread.metadata || "{}") : thread.metadata || {}
|
|
615
671
|
}));
|
|
616
|
-
} catch (error) {
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
672
|
+
} catch (error$1) {
|
|
673
|
+
const mastraError = new error.MastraError(
|
|
674
|
+
{
|
|
675
|
+
id: "CLOUDFLARE_D1_STORAGE_GET_THREADS_BY_RESOURCE_ID_ERROR",
|
|
676
|
+
domain: error.ErrorDomain.STORAGE,
|
|
677
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
678
|
+
text: `Error getting threads by resourceId ${resourceId}: ${error$1 instanceof Error ? error$1.message : String(error$1)}`,
|
|
679
|
+
details: { resourceId }
|
|
680
|
+
},
|
|
681
|
+
error$1
|
|
682
|
+
);
|
|
683
|
+
this.logger?.error(mastraError.toString());
|
|
684
|
+
this.logger?.trackException(mastraError);
|
|
620
685
|
return [];
|
|
621
686
|
}
|
|
622
687
|
}
|
|
@@ -629,19 +694,41 @@ var D1Store = class extends storage.MastraStorage {
|
|
|
629
694
|
updatedAt: this.ensureDate(row.updatedAt),
|
|
630
695
|
metadata: typeof row.metadata === "string" ? JSON.parse(row.metadata || "{}") : row.metadata || {}
|
|
631
696
|
});
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
697
|
+
try {
|
|
698
|
+
const countQuery = createSqlBuilder().count().from(fullTableName).where("resourceId = ?", resourceId);
|
|
699
|
+
const countResult = await this.executeQuery(countQuery.build());
|
|
700
|
+
const total = Number(countResult?.[0]?.count ?? 0);
|
|
701
|
+
const selectQuery = createSqlBuilder().select("*").from(fullTableName).where("resourceId = ?", resourceId).orderBy("createdAt", "DESC").limit(perPage).offset(page * perPage);
|
|
702
|
+
const results = await this.executeQuery(selectQuery.build());
|
|
703
|
+
const threads = results.map(mapRowToStorageThreadType);
|
|
704
|
+
return {
|
|
705
|
+
threads,
|
|
706
|
+
total,
|
|
707
|
+
page,
|
|
708
|
+
perPage,
|
|
709
|
+
hasMore: page * perPage + threads.length < total
|
|
710
|
+
};
|
|
711
|
+
} catch (error$1) {
|
|
712
|
+
const mastraError = new error.MastraError(
|
|
713
|
+
{
|
|
714
|
+
id: "CLOUDFLARE_D1_STORAGE_GET_THREADS_BY_RESOURCE_ID_PAGINATED_ERROR",
|
|
715
|
+
domain: error.ErrorDomain.STORAGE,
|
|
716
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
717
|
+
text: `Error getting threads by resourceId ${resourceId}: ${error$1 instanceof Error ? error$1.message : String(error$1)}`,
|
|
718
|
+
details: { resourceId }
|
|
719
|
+
},
|
|
720
|
+
error$1
|
|
721
|
+
);
|
|
722
|
+
this.logger?.error(mastraError.toString());
|
|
723
|
+
this.logger?.trackException(mastraError);
|
|
724
|
+
return {
|
|
725
|
+
threads: [],
|
|
726
|
+
total: 0,
|
|
727
|
+
page,
|
|
728
|
+
perPage,
|
|
729
|
+
hasMore: false
|
|
730
|
+
};
|
|
731
|
+
}
|
|
645
732
|
}
|
|
646
733
|
async saveThread({ thread }) {
|
|
647
734
|
const fullTableName = this.getTableName(storage.TABLE_THREADS);
|
|
@@ -668,10 +755,17 @@ var D1Store = class extends storage.MastraStorage {
|
|
|
668
755
|
try {
|
|
669
756
|
await this.executeQuery({ sql, params });
|
|
670
757
|
return thread;
|
|
671
|
-
} catch (error) {
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
758
|
+
} catch (error$1) {
|
|
759
|
+
throw new error.MastraError(
|
|
760
|
+
{
|
|
761
|
+
id: "CLOUDFLARE_D1_STORAGE_SAVE_THREAD_ERROR",
|
|
762
|
+
domain: error.ErrorDomain.STORAGE,
|
|
763
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
764
|
+
text: `Failed to save thread to ${fullTableName}: ${error$1 instanceof Error ? error$1.message : String(error$1)}`,
|
|
765
|
+
details: { threadId: thread.id }
|
|
766
|
+
},
|
|
767
|
+
error$1
|
|
768
|
+
);
|
|
675
769
|
}
|
|
676
770
|
}
|
|
677
771
|
async updateThread({
|
|
@@ -680,19 +774,19 @@ var D1Store = class extends storage.MastraStorage {
|
|
|
680
774
|
metadata
|
|
681
775
|
}) {
|
|
682
776
|
const thread = await this.getThreadById({ threadId: id });
|
|
683
|
-
if (!thread) {
|
|
684
|
-
throw new Error(`Thread ${id} not found`);
|
|
685
|
-
}
|
|
686
|
-
const fullTableName = this.getTableName(storage.TABLE_THREADS);
|
|
687
|
-
const mergedMetadata = {
|
|
688
|
-
...typeof thread.metadata === "string" ? JSON.parse(thread.metadata) : thread.metadata,
|
|
689
|
-
...metadata
|
|
690
|
-
};
|
|
691
|
-
const columns = ["title", "metadata", "updatedAt"];
|
|
692
|
-
const values = [title, JSON.stringify(mergedMetadata), (/* @__PURE__ */ new Date()).toISOString()];
|
|
693
|
-
const query = createSqlBuilder().update(fullTableName, columns, values).where("id = ?", id);
|
|
694
|
-
const { sql, params } = query.build();
|
|
695
777
|
try {
|
|
778
|
+
if (!thread) {
|
|
779
|
+
throw new Error(`Thread ${id} not found`);
|
|
780
|
+
}
|
|
781
|
+
const fullTableName = this.getTableName(storage.TABLE_THREADS);
|
|
782
|
+
const mergedMetadata = {
|
|
783
|
+
...typeof thread.metadata === "string" ? JSON.parse(thread.metadata) : thread.metadata,
|
|
784
|
+
...metadata
|
|
785
|
+
};
|
|
786
|
+
const columns = ["title", "metadata", "updatedAt"];
|
|
787
|
+
const values = [title, JSON.stringify(mergedMetadata), (/* @__PURE__ */ new Date()).toISOString()];
|
|
788
|
+
const query = createSqlBuilder().update(fullTableName, columns, values).where("id = ?", id);
|
|
789
|
+
const { sql, params } = query.build();
|
|
696
790
|
await this.executeQuery({ sql, params });
|
|
697
791
|
return {
|
|
698
792
|
...thread,
|
|
@@ -703,10 +797,17 @@ var D1Store = class extends storage.MastraStorage {
|
|
|
703
797
|
},
|
|
704
798
|
updatedAt: /* @__PURE__ */ new Date()
|
|
705
799
|
};
|
|
706
|
-
} catch (error) {
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
800
|
+
} catch (error$1) {
|
|
801
|
+
throw new error.MastraError(
|
|
802
|
+
{
|
|
803
|
+
id: "CLOUDFLARE_D1_STORAGE_UPDATE_THREAD_ERROR",
|
|
804
|
+
domain: error.ErrorDomain.STORAGE,
|
|
805
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
806
|
+
text: `Failed to update thread ${id}: ${error$1 instanceof Error ? error$1.message : String(error$1)}`,
|
|
807
|
+
details: { threadId: id }
|
|
808
|
+
},
|
|
809
|
+
error$1
|
|
810
|
+
);
|
|
710
811
|
}
|
|
711
812
|
}
|
|
712
813
|
async deleteThread({ threadId }) {
|
|
@@ -719,11 +820,17 @@ var D1Store = class extends storage.MastraStorage {
|
|
|
719
820
|
const deleteMessagesQuery = createSqlBuilder().delete(messagesTableName).where("thread_id = ?", threadId);
|
|
720
821
|
const { sql: messagesSql, params: messagesParams } = deleteMessagesQuery.build();
|
|
721
822
|
await this.executeQuery({ sql: messagesSql, params: messagesParams });
|
|
722
|
-
} catch (error) {
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
823
|
+
} catch (error$1) {
|
|
824
|
+
throw new error.MastraError(
|
|
825
|
+
{
|
|
826
|
+
id: "CLOUDFLARE_D1_STORAGE_DELETE_THREAD_ERROR",
|
|
827
|
+
domain: error.ErrorDomain.STORAGE,
|
|
828
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
829
|
+
text: `Failed to delete thread ${threadId}: ${error$1 instanceof Error ? error$1.message : String(error$1)}`,
|
|
830
|
+
details: { threadId }
|
|
831
|
+
},
|
|
832
|
+
error$1
|
|
833
|
+
);
|
|
727
834
|
}
|
|
728
835
|
}
|
|
729
836
|
async saveMessages(args) {
|
|
@@ -755,7 +862,7 @@ var D1Store = class extends storage.MastraStorage {
|
|
|
755
862
|
};
|
|
756
863
|
});
|
|
757
864
|
await Promise.all([
|
|
758
|
-
this.
|
|
865
|
+
this.batchUpsert({
|
|
759
866
|
tableName: storage.TABLE_MESSAGES,
|
|
760
867
|
records: messagesToInsert
|
|
761
868
|
}),
|
|
@@ -769,9 +876,16 @@ var D1Store = class extends storage.MastraStorage {
|
|
|
769
876
|
const list = new agent.MessageList().add(messages, "memory");
|
|
770
877
|
if (format === `v2`) return list.get.all.v2();
|
|
771
878
|
return list.get.all.v1();
|
|
772
|
-
} catch (error) {
|
|
773
|
-
|
|
774
|
-
|
|
879
|
+
} catch (error$1) {
|
|
880
|
+
throw new error.MastraError(
|
|
881
|
+
{
|
|
882
|
+
id: "CLOUDFLARE_D1_STORAGE_SAVE_MESSAGES_ERROR",
|
|
883
|
+
domain: error.ErrorDomain.STORAGE,
|
|
884
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
885
|
+
text: `Failed to save messages: ${error$1 instanceof Error ? error$1.message : String(error$1)}`
|
|
886
|
+
},
|
|
887
|
+
error$1
|
|
888
|
+
);
|
|
775
889
|
}
|
|
776
890
|
}
|
|
777
891
|
async _getIncludedMessages(threadId, selectBy) {
|
|
@@ -826,7 +940,7 @@ var D1Store = class extends storage.MastraStorage {
|
|
|
826
940
|
format
|
|
827
941
|
}) {
|
|
828
942
|
const fullTableName = this.getTableName(storage.TABLE_MESSAGES);
|
|
829
|
-
const limit =
|
|
943
|
+
const limit = this.resolveMessageLimit({ last: selectBy?.last, defaultLimit: 40 });
|
|
830
944
|
const include = selectBy?.include || [];
|
|
831
945
|
const messages = [];
|
|
832
946
|
try {
|
|
@@ -862,12 +976,20 @@ var D1Store = class extends storage.MastraStorage {
|
|
|
862
976
|
const list = new agent.MessageList().add(processedMessages, "memory");
|
|
863
977
|
if (format === `v2`) return list.get.all.v2();
|
|
864
978
|
return list.get.all.v1();
|
|
865
|
-
} catch (error) {
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
979
|
+
} catch (error$1) {
|
|
980
|
+
const mastraError = new error.MastraError(
|
|
981
|
+
{
|
|
982
|
+
id: "CLOUDFLARE_D1_STORAGE_GET_MESSAGES_ERROR",
|
|
983
|
+
domain: error.ErrorDomain.STORAGE,
|
|
984
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
985
|
+
text: `Failed to retrieve messages for thread ${threadId}: ${error$1 instanceof Error ? error$1.message : String(error$1)}`,
|
|
986
|
+
details: { threadId }
|
|
987
|
+
},
|
|
988
|
+
error$1
|
|
989
|
+
);
|
|
990
|
+
this.logger?.error(mastraError.toString());
|
|
991
|
+
this.logger?.trackException(mastraError);
|
|
992
|
+
throw mastraError;
|
|
871
993
|
}
|
|
872
994
|
}
|
|
873
995
|
async getMessagesPaginated({
|
|
@@ -879,37 +1001,59 @@ var D1Store = class extends storage.MastraStorage {
|
|
|
879
1001
|
const { start: fromDate, end: toDate } = dateRange || {};
|
|
880
1002
|
const fullTableName = this.getTableName(storage.TABLE_MESSAGES);
|
|
881
1003
|
const messages = [];
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
1004
|
+
try {
|
|
1005
|
+
if (selectBy?.include?.length) {
|
|
1006
|
+
const includeResult = await this._getIncludedMessages(threadId, selectBy);
|
|
1007
|
+
if (Array.isArray(includeResult)) messages.push(...includeResult);
|
|
1008
|
+
}
|
|
1009
|
+
const countQuery = createSqlBuilder().count().from(fullTableName).where("thread_id = ?", threadId);
|
|
1010
|
+
if (fromDate) {
|
|
1011
|
+
countQuery.andWhere("createdAt >= ?", this.serializeDate(fromDate));
|
|
1012
|
+
}
|
|
1013
|
+
if (toDate) {
|
|
1014
|
+
countQuery.andWhere("createdAt <= ?", this.serializeDate(toDate));
|
|
1015
|
+
}
|
|
1016
|
+
const countResult = await this.executeQuery(countQuery.build());
|
|
1017
|
+
const total = Number(countResult[0]?.count ?? 0);
|
|
1018
|
+
const query = createSqlBuilder().select(["id", "content", "role", "type", "createdAt", "thread_id AS threadId"]).from(fullTableName).where("thread_id = ?", threadId);
|
|
1019
|
+
if (fromDate) {
|
|
1020
|
+
query.andWhere("createdAt >= ?", this.serializeDate(fromDate));
|
|
1021
|
+
}
|
|
1022
|
+
if (toDate) {
|
|
1023
|
+
query.andWhere("createdAt <= ?", this.serializeDate(toDate));
|
|
1024
|
+
}
|
|
1025
|
+
query.orderBy("createdAt", "DESC").limit(perPage).offset(page * perPage);
|
|
1026
|
+
const results = await this.executeQuery(query.build());
|
|
1027
|
+
const list = new agent.MessageList().add(results, "memory");
|
|
1028
|
+
messages.push(...format === `v2` ? list.get.all.v2() : list.get.all.v1());
|
|
1029
|
+
return {
|
|
1030
|
+
messages,
|
|
1031
|
+
total,
|
|
1032
|
+
page,
|
|
1033
|
+
perPage,
|
|
1034
|
+
hasMore: page * perPage + messages.length < total
|
|
1035
|
+
};
|
|
1036
|
+
} catch (error$1) {
|
|
1037
|
+
const mastraError = new error.MastraError(
|
|
1038
|
+
{
|
|
1039
|
+
id: "CLOUDFLARE_D1_STORAGE_GET_MESSAGES_PAGINATED_ERROR",
|
|
1040
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1041
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1042
|
+
text: `Failed to retrieve messages for thread ${threadId}: ${error$1 instanceof Error ? error$1.message : String(error$1)}`,
|
|
1043
|
+
details: { threadId }
|
|
1044
|
+
},
|
|
1045
|
+
error$1
|
|
1046
|
+
);
|
|
1047
|
+
this.logger?.error(mastraError.toString());
|
|
1048
|
+
this.logger?.trackException(mastraError);
|
|
1049
|
+
return {
|
|
1050
|
+
messages: [],
|
|
1051
|
+
total: 0,
|
|
1052
|
+
page,
|
|
1053
|
+
perPage,
|
|
1054
|
+
hasMore: false
|
|
1055
|
+
};
|
|
901
1056
|
}
|
|
902
|
-
query.orderBy("createdAt", "DESC").limit(perPage).offset(page * perPage);
|
|
903
|
-
const results = await this.executeQuery(query.build());
|
|
904
|
-
const list = new agent.MessageList().add(results, "memory");
|
|
905
|
-
messages.push(...format === `v2` ? list.get.all.v2() : list.get.all.v1());
|
|
906
|
-
return {
|
|
907
|
-
messages,
|
|
908
|
-
total,
|
|
909
|
-
page,
|
|
910
|
-
perPage,
|
|
911
|
-
hasMore: page * perPage + messages.length < total
|
|
912
|
-
};
|
|
913
1057
|
}
|
|
914
1058
|
async persistWorkflowSnapshot({
|
|
915
1059
|
workflowName,
|
|
@@ -945,24 +1089,43 @@ var D1Store = class extends storage.MastraStorage {
|
|
|
945
1089
|
const { sql, params } = query.build();
|
|
946
1090
|
try {
|
|
947
1091
|
await this.executeQuery({ sql, params });
|
|
948
|
-
} catch (error) {
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
1092
|
+
} catch (error$1) {
|
|
1093
|
+
throw new error.MastraError(
|
|
1094
|
+
{
|
|
1095
|
+
id: "CLOUDFLARE_D1_STORAGE_PERSIST_WORKFLOW_SNAPSHOT_ERROR",
|
|
1096
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1097
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1098
|
+
text: `Failed to persist workflow snapshot: ${error$1 instanceof Error ? error$1.message : String(error$1)}`,
|
|
1099
|
+
details: { workflowName, runId }
|
|
1100
|
+
},
|
|
1101
|
+
error$1
|
|
1102
|
+
);
|
|
953
1103
|
}
|
|
954
1104
|
}
|
|
955
1105
|
async loadWorkflowSnapshot(params) {
|
|
956
1106
|
const { workflowName, runId } = params;
|
|
957
1107
|
this.logger.debug("Loading workflow snapshot", { workflowName, runId });
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
1108
|
+
try {
|
|
1109
|
+
const d = await this.load({
|
|
1110
|
+
tableName: storage.TABLE_WORKFLOW_SNAPSHOT,
|
|
1111
|
+
keys: {
|
|
1112
|
+
workflow_name: workflowName,
|
|
1113
|
+
run_id: runId
|
|
1114
|
+
}
|
|
1115
|
+
});
|
|
1116
|
+
return d ? d.snapshot : null;
|
|
1117
|
+
} catch (error$1) {
|
|
1118
|
+
throw new error.MastraError(
|
|
1119
|
+
{
|
|
1120
|
+
id: "CLOUDFLARE_D1_STORAGE_LOAD_WORKFLOW_SNAPSHOT_ERROR",
|
|
1121
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1122
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1123
|
+
text: `Failed to load workflow snapshot: ${error$1 instanceof Error ? error$1.message : String(error$1)}`,
|
|
1124
|
+
details: { workflowName, runId }
|
|
1125
|
+
},
|
|
1126
|
+
error$1
|
|
1127
|
+
);
|
|
1128
|
+
}
|
|
966
1129
|
}
|
|
967
1130
|
/**
|
|
968
1131
|
* Insert multiple records in a batch operation
|
|
@@ -996,11 +1159,72 @@ var D1Store = class extends storage.MastraStorage {
|
|
|
996
1159
|
);
|
|
997
1160
|
}
|
|
998
1161
|
this.logger.debug(`Successfully batch inserted ${records.length} records into ${tableName}`);
|
|
999
|
-
} catch (error) {
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1162
|
+
} catch (error$1) {
|
|
1163
|
+
throw new error.MastraError(
|
|
1164
|
+
{
|
|
1165
|
+
id: "CLOUDFLARE_D1_STORAGE_BATCH_INSERT_ERROR",
|
|
1166
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1167
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1168
|
+
text: `Failed to batch insert into ${tableName}: ${error$1 instanceof Error ? error$1.message : String(error$1)}`,
|
|
1169
|
+
details: { tableName }
|
|
1170
|
+
},
|
|
1171
|
+
error$1
|
|
1172
|
+
);
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
/**
|
|
1176
|
+
* Upsert multiple records in a batch operation
|
|
1177
|
+
* @param tableName The table to insert into
|
|
1178
|
+
* @param records The records to insert
|
|
1179
|
+
*/
|
|
1180
|
+
async batchUpsert({
|
|
1181
|
+
tableName,
|
|
1182
|
+
records
|
|
1183
|
+
}) {
|
|
1184
|
+
if (records.length === 0) return;
|
|
1185
|
+
const fullTableName = this.getTableName(tableName);
|
|
1186
|
+
try {
|
|
1187
|
+
const batchSize = 50;
|
|
1188
|
+
for (let i = 0; i < records.length; i += batchSize) {
|
|
1189
|
+
const batch = records.slice(i, i + batchSize);
|
|
1190
|
+
const recordsToInsert = batch;
|
|
1191
|
+
if (recordsToInsert.length > 0) {
|
|
1192
|
+
const firstRecord = recordsToInsert[0];
|
|
1193
|
+
const columns = Object.keys(firstRecord || {});
|
|
1194
|
+
for (const record of recordsToInsert) {
|
|
1195
|
+
const values = columns.map((col) => {
|
|
1196
|
+
if (!record) return null;
|
|
1197
|
+
const value = typeof col === "string" ? record[col] : null;
|
|
1198
|
+
return this.serializeValue(value);
|
|
1199
|
+
});
|
|
1200
|
+
const recordToUpsert = columns.reduce(
|
|
1201
|
+
(acc, col) => {
|
|
1202
|
+
if (col !== "createdAt") acc[col] = `excluded.${col}`;
|
|
1203
|
+
return acc;
|
|
1204
|
+
},
|
|
1205
|
+
{}
|
|
1206
|
+
);
|
|
1207
|
+
const query = createSqlBuilder().insert(fullTableName, columns, values, ["id"], recordToUpsert);
|
|
1208
|
+
const { sql, params } = query.build();
|
|
1209
|
+
await this.executeQuery({ sql, params });
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
this.logger.debug(
|
|
1213
|
+
`Processed batch ${Math.floor(i / batchSize) + 1} of ${Math.ceil(records.length / batchSize)}`
|
|
1214
|
+
);
|
|
1215
|
+
}
|
|
1216
|
+
this.logger.debug(`Successfully batch upserted ${records.length} records into ${tableName}`);
|
|
1217
|
+
} catch (error$1) {
|
|
1218
|
+
throw new error.MastraError(
|
|
1219
|
+
{
|
|
1220
|
+
id: "CLOUDFLARE_D1_STORAGE_BATCH_UPSERT_ERROR",
|
|
1221
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1222
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1223
|
+
text: `Failed to batch upsert into ${tableName}: ${error$1 instanceof Error ? error$1.message : String(error$1)}`,
|
|
1224
|
+
details: { tableName }
|
|
1225
|
+
},
|
|
1226
|
+
error$1
|
|
1227
|
+
);
|
|
1004
1228
|
}
|
|
1005
1229
|
}
|
|
1006
1230
|
/**
|
|
@@ -1048,8 +1272,22 @@ var D1Store = class extends storage.MastraStorage {
|
|
|
1048
1272
|
other: this.deserializeValue(trace.other, "jsonb")
|
|
1049
1273
|
})
|
|
1050
1274
|
) : [];
|
|
1051
|
-
} catch (error) {
|
|
1052
|
-
|
|
1275
|
+
} catch (error$1) {
|
|
1276
|
+
const mastraError = new error.MastraError(
|
|
1277
|
+
{
|
|
1278
|
+
id: "CLOUDFLARE_D1_STORAGE_GET_TRACES_ERROR",
|
|
1279
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1280
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1281
|
+
text: `Failed to retrieve traces: ${error$1 instanceof Error ? error$1.message : String(error$1)}`,
|
|
1282
|
+
details: {
|
|
1283
|
+
name: name ?? "",
|
|
1284
|
+
scope: scope ?? ""
|
|
1285
|
+
}
|
|
1286
|
+
},
|
|
1287
|
+
error$1
|
|
1288
|
+
);
|
|
1289
|
+
this.logger?.error(mastraError.toString());
|
|
1290
|
+
this.logger?.trackException(mastraError);
|
|
1053
1291
|
return [];
|
|
1054
1292
|
}
|
|
1055
1293
|
}
|
|
@@ -1104,8 +1342,19 @@ var D1Store = class extends storage.MastraStorage {
|
|
|
1104
1342
|
perPage,
|
|
1105
1343
|
hasMore: page * perPage + traces.length < total
|
|
1106
1344
|
};
|
|
1107
|
-
} catch (error) {
|
|
1108
|
-
|
|
1345
|
+
} catch (error$1) {
|
|
1346
|
+
const mastraError = new error.MastraError(
|
|
1347
|
+
{
|
|
1348
|
+
id: "CLOUDFLARE_D1_STORAGE_GET_TRACES_ERROR",
|
|
1349
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1350
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1351
|
+
text: `Failed to retrieve traces: ${error$1 instanceof Error ? error$1.message : String(error$1)}`,
|
|
1352
|
+
details: { name: name ?? "", scope: scope ?? "" }
|
|
1353
|
+
},
|
|
1354
|
+
error$1
|
|
1355
|
+
);
|
|
1356
|
+
this.logger?.error(mastraError.toString());
|
|
1357
|
+
this.logger?.trackException(mastraError);
|
|
1109
1358
|
return { traces: [], total: 0, page, perPage, hasMore: false };
|
|
1110
1359
|
}
|
|
1111
1360
|
}
|
|
@@ -1140,10 +1389,19 @@ var D1Store = class extends storage.MastraStorage {
|
|
|
1140
1389
|
testInfo
|
|
1141
1390
|
};
|
|
1142
1391
|
}) : [];
|
|
1143
|
-
} catch (error) {
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1392
|
+
} catch (error$1) {
|
|
1393
|
+
const mastraError = new error.MastraError(
|
|
1394
|
+
{
|
|
1395
|
+
id: "CLOUDFLARE_D1_STORAGE_GET_EVALS_ERROR",
|
|
1396
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1397
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1398
|
+
text: `Failed to retrieve evals for agent ${agentName}: ${error$1 instanceof Error ? error$1.message : String(error$1)}`,
|
|
1399
|
+
details: { agentName }
|
|
1400
|
+
},
|
|
1401
|
+
error$1
|
|
1402
|
+
);
|
|
1403
|
+
this.logger?.error(mastraError.toString());
|
|
1404
|
+
this.logger?.trackException(mastraError);
|
|
1147
1405
|
return [];
|
|
1148
1406
|
}
|
|
1149
1407
|
}
|
|
@@ -1174,52 +1432,65 @@ var D1Store = class extends storage.MastraStorage {
|
|
|
1174
1432
|
countQueryBuilder.where(conditions.join(" AND "), ...queryParams);
|
|
1175
1433
|
}
|
|
1176
1434
|
const { sql: countSql, params: countParams } = countQueryBuilder.build();
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1435
|
+
try {
|
|
1436
|
+
const countResult = await this.executeQuery({ sql: countSql, params: countParams, first: true });
|
|
1437
|
+
const total = Number(countResult?.count || 0);
|
|
1438
|
+
const currentOffset = page * perPage;
|
|
1439
|
+
if (total === 0) {
|
|
1440
|
+
return {
|
|
1441
|
+
evals: [],
|
|
1442
|
+
total: 0,
|
|
1443
|
+
page,
|
|
1444
|
+
perPage,
|
|
1445
|
+
hasMore: false
|
|
1446
|
+
};
|
|
1447
|
+
}
|
|
1448
|
+
const dataQueryBuilder = createSqlBuilder().select("*").from(fullTableName);
|
|
1449
|
+
if (conditions.length > 0) {
|
|
1450
|
+
dataQueryBuilder.where(conditions.join(" AND "), ...queryParams);
|
|
1451
|
+
}
|
|
1452
|
+
dataQueryBuilder.orderBy("createdAt", "DESC").limit(perPage).offset(currentOffset);
|
|
1453
|
+
const { sql: dataSql, params: dataParams } = dataQueryBuilder.build();
|
|
1454
|
+
const rows = await this.executeQuery({ sql: dataSql, params: dataParams });
|
|
1455
|
+
const evals = (isArrayOfRecords(rows) ? rows : []).map((row) => {
|
|
1456
|
+
const result = this.deserializeValue(row.result);
|
|
1457
|
+
const testInfo = row.test_info ? this.deserializeValue(row.test_info) : void 0;
|
|
1458
|
+
if (!result || typeof result !== "object" || !("score" in result)) {
|
|
1459
|
+
throw new Error(`Invalid MetricResult format: ${JSON.stringify(result)}`);
|
|
1460
|
+
}
|
|
1461
|
+
return {
|
|
1462
|
+
input: row.input,
|
|
1463
|
+
output: row.output,
|
|
1464
|
+
result,
|
|
1465
|
+
agentName: row.agent_name,
|
|
1466
|
+
metricName: row.metric_name,
|
|
1467
|
+
instructions: row.instructions,
|
|
1468
|
+
testInfo,
|
|
1469
|
+
globalRunId: row.global_run_id,
|
|
1470
|
+
runId: row.run_id,
|
|
1471
|
+
createdAt: row.createdAt
|
|
1472
|
+
};
|
|
1473
|
+
});
|
|
1474
|
+
const hasMore = currentOffset + evals.length < total;
|
|
1181
1475
|
return {
|
|
1182
|
-
evals
|
|
1183
|
-
total
|
|
1476
|
+
evals,
|
|
1477
|
+
total,
|
|
1184
1478
|
page,
|
|
1185
1479
|
perPage,
|
|
1186
|
-
hasMore
|
|
1480
|
+
hasMore
|
|
1187
1481
|
};
|
|
1482
|
+
} catch (error$1) {
|
|
1483
|
+
throw new error.MastraError(
|
|
1484
|
+
{
|
|
1485
|
+
id: "CLOUDFLARE_D1_STORAGE_GET_EVALS_ERROR",
|
|
1486
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1487
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1488
|
+
text: `Failed to retrieve evals for agent ${agentName}: ${error$1 instanceof Error ? error$1.message : String(error$1)}`,
|
|
1489
|
+
details: { agentName: agentName ?? "", type: type ?? "" }
|
|
1490
|
+
},
|
|
1491
|
+
error$1
|
|
1492
|
+
);
|
|
1188
1493
|
}
|
|
1189
|
-
const dataQueryBuilder = createSqlBuilder().select("*").from(fullTableName);
|
|
1190
|
-
if (conditions.length > 0) {
|
|
1191
|
-
dataQueryBuilder.where(conditions.join(" AND "), ...queryParams);
|
|
1192
|
-
}
|
|
1193
|
-
dataQueryBuilder.orderBy("createdAt", "DESC").limit(perPage).offset(currentOffset);
|
|
1194
|
-
const { sql: dataSql, params: dataParams } = dataQueryBuilder.build();
|
|
1195
|
-
const rows = await this.executeQuery({ sql: dataSql, params: dataParams });
|
|
1196
|
-
const evals = (isArrayOfRecords(rows) ? rows : []).map((row) => {
|
|
1197
|
-
const result = this.deserializeValue(row.result);
|
|
1198
|
-
const testInfo = row.test_info ? this.deserializeValue(row.test_info) : void 0;
|
|
1199
|
-
if (!result || typeof result !== "object" || !("score" in result)) {
|
|
1200
|
-
throw new Error(`Invalid MetricResult format: ${JSON.stringify(result)}`);
|
|
1201
|
-
}
|
|
1202
|
-
return {
|
|
1203
|
-
input: row.input,
|
|
1204
|
-
output: row.output,
|
|
1205
|
-
result,
|
|
1206
|
-
agentName: row.agent_name,
|
|
1207
|
-
metricName: row.metric_name,
|
|
1208
|
-
instructions: row.instructions,
|
|
1209
|
-
testInfo,
|
|
1210
|
-
globalRunId: row.global_run_id,
|
|
1211
|
-
runId: row.run_id,
|
|
1212
|
-
createdAt: row.createdAt
|
|
1213
|
-
};
|
|
1214
|
-
});
|
|
1215
|
-
const hasMore = currentOffset + evals.length < total;
|
|
1216
|
-
return {
|
|
1217
|
-
evals,
|
|
1218
|
-
total,
|
|
1219
|
-
page,
|
|
1220
|
-
perPage,
|
|
1221
|
-
hasMore
|
|
1222
|
-
};
|
|
1223
1494
|
}
|
|
1224
1495
|
parseWorkflowRun(row) {
|
|
1225
1496
|
let parsedSnapshot = row.snapshot;
|
|
@@ -1288,11 +1559,17 @@ var D1Store = class extends storage.MastraStorage {
|
|
|
1288
1559
|
const results = await this.executeQuery({ sql, params });
|
|
1289
1560
|
const runs = (isArrayOfRecords(results) ? results : []).map((row) => this.parseWorkflowRun(row));
|
|
1290
1561
|
return { runs, total: total || runs.length };
|
|
1291
|
-
} catch (error) {
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1562
|
+
} catch (error$1) {
|
|
1563
|
+
throw new error.MastraError(
|
|
1564
|
+
{
|
|
1565
|
+
id: "CLOUDFLARE_D1_STORAGE_GET_WORKFLOW_RUNS_ERROR",
|
|
1566
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1567
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1568
|
+
text: `Failed to retrieve workflow runs: ${error$1 instanceof Error ? error$1.message : String(error$1)}`,
|
|
1569
|
+
details: { workflowName: workflowName ?? "", resourceId: resourceId ?? "" }
|
|
1570
|
+
},
|
|
1571
|
+
error$1
|
|
1572
|
+
);
|
|
1296
1573
|
}
|
|
1297
1574
|
}
|
|
1298
1575
|
async getWorkflowRunById({
|
|
@@ -1316,11 +1593,17 @@ var D1Store = class extends storage.MastraStorage {
|
|
|
1316
1593
|
const result = await this.executeQuery({ sql, params, first: true });
|
|
1317
1594
|
if (!result) return null;
|
|
1318
1595
|
return this.parseWorkflowRun(result);
|
|
1319
|
-
} catch (error) {
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1596
|
+
} catch (error$1) {
|
|
1597
|
+
throw new error.MastraError(
|
|
1598
|
+
{
|
|
1599
|
+
id: "CLOUDFLARE_D1_STORAGE_GET_WORKFLOW_RUN_BY_ID_ERROR",
|
|
1600
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1601
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1602
|
+
text: `Failed to retrieve workflow run by ID: ${error$1 instanceof Error ? error$1.message : String(error$1)}`,
|
|
1603
|
+
details: { runId, workflowName: workflowName ?? "" }
|
|
1604
|
+
},
|
|
1605
|
+
error$1
|
|
1606
|
+
);
|
|
1324
1607
|
}
|
|
1325
1608
|
}
|
|
1326
1609
|
/**
|