@mastra/cloudflare-d1 0.10.1-alpha.1 → 0.10.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 +18 -8
- package/dist/_tsup-dts-rollup.d.ts +18 -8
- package/dist/index.cjs +14 -29
- package/dist/index.js +14 -29
- package/package.json +2 -2
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { D1Database as D1Database_2 } from '@cloudflare/workers-types';
|
|
2
2
|
import type { EvalRow } from '@mastra/core/storage';
|
|
3
|
+
import type { MastraMessageV1 } from '@mastra/core/memory';
|
|
4
|
+
import type { MastraMessageV2 } from '@mastra/core/memory';
|
|
5
|
+
import type { MastraMessageV2 as MastraMessageV2_2 } from '@mastra/core';
|
|
3
6
|
import { MastraStorage } from '@mastra/core/storage';
|
|
4
|
-
import type { MessageType } from '@mastra/core/memory';
|
|
5
|
-
import type { MessageType as MessageType_2 } from '@mastra/core';
|
|
6
7
|
import type { StorageColumn } from '@mastra/core/storage';
|
|
7
8
|
import type { StorageGetMessagesArg } from '@mastra/core/storage';
|
|
8
9
|
import type { StorageThreadType } from '@mastra/core/memory';
|
|
@@ -14,7 +15,7 @@ import type { WorkflowRunState as WorkflowRunState_2 } from '@mastra/core';
|
|
|
14
15
|
|
|
15
16
|
export declare const checkWorkflowSnapshot: (snapshot: WorkflowRunState_2 | string, stepId: string, status: string) => void;
|
|
16
17
|
|
|
17
|
-
export declare const createSampleMessage: (threadId: string) =>
|
|
18
|
+
export declare const createSampleMessage: (threadId: string, parts?: MastraMessageV2_2["content"]["parts"]) => MastraMessageV2_2;
|
|
18
19
|
|
|
19
20
|
export declare const createSampleThread: () => {
|
|
20
21
|
id: string;
|
|
@@ -92,7 +93,6 @@ declare class D1Store extends MastraStorage {
|
|
|
92
93
|
constructor(config: D1StoreConfig);
|
|
93
94
|
private getTableName;
|
|
94
95
|
private formatSqlParams;
|
|
95
|
-
private createIndexIfNotExists;
|
|
96
96
|
private executeWorkersBindingQuery;
|
|
97
97
|
private executeRestQuery;
|
|
98
98
|
/**
|
|
@@ -139,10 +139,20 @@ declare class D1Store extends MastraStorage {
|
|
|
139
139
|
deleteThread({ threadId }: {
|
|
140
140
|
threadId: string;
|
|
141
141
|
}): Promise<void>;
|
|
142
|
-
saveMessages(
|
|
143
|
-
messages:
|
|
144
|
-
|
|
145
|
-
|
|
142
|
+
saveMessages(args: {
|
|
143
|
+
messages: MastraMessageV1[];
|
|
144
|
+
format?: undefined | 'v1';
|
|
145
|
+
}): Promise<MastraMessageV1[]>;
|
|
146
|
+
saveMessages(args: {
|
|
147
|
+
messages: MastraMessageV2[];
|
|
148
|
+
format: 'v2';
|
|
149
|
+
}): Promise<MastraMessageV2[]>;
|
|
150
|
+
getMessages(args: StorageGetMessagesArg & {
|
|
151
|
+
format?: 'v1';
|
|
152
|
+
}): Promise<MastraMessageV1[]>;
|
|
153
|
+
getMessages(args: StorageGetMessagesArg & {
|
|
154
|
+
format: 'v2';
|
|
155
|
+
}): Promise<MastraMessageV2[]>;
|
|
146
156
|
persistWorkflowSnapshot({ workflowName, runId, snapshot, }: {
|
|
147
157
|
workflowName: string;
|
|
148
158
|
runId: string;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { D1Database as D1Database_2 } from '@cloudflare/workers-types';
|
|
2
2
|
import type { EvalRow } from '@mastra/core/storage';
|
|
3
|
+
import type { MastraMessageV1 } from '@mastra/core/memory';
|
|
4
|
+
import type { MastraMessageV2 } from '@mastra/core/memory';
|
|
5
|
+
import type { MastraMessageV2 as MastraMessageV2_2 } from '@mastra/core';
|
|
3
6
|
import { MastraStorage } from '@mastra/core/storage';
|
|
4
|
-
import type { MessageType } from '@mastra/core/memory';
|
|
5
|
-
import type { MessageType as MessageType_2 } from '@mastra/core';
|
|
6
7
|
import type { StorageColumn } from '@mastra/core/storage';
|
|
7
8
|
import type { StorageGetMessagesArg } from '@mastra/core/storage';
|
|
8
9
|
import type { StorageThreadType } from '@mastra/core/memory';
|
|
@@ -14,7 +15,7 @@ import type { WorkflowRunState as WorkflowRunState_2 } from '@mastra/core';
|
|
|
14
15
|
|
|
15
16
|
export declare const checkWorkflowSnapshot: (snapshot: WorkflowRunState_2 | string, stepId: string, status: string) => void;
|
|
16
17
|
|
|
17
|
-
export declare const createSampleMessage: (threadId: string) =>
|
|
18
|
+
export declare const createSampleMessage: (threadId: string, parts?: MastraMessageV2_2["content"]["parts"]) => MastraMessageV2_2;
|
|
18
19
|
|
|
19
20
|
export declare const createSampleThread: () => {
|
|
20
21
|
id: string;
|
|
@@ -92,7 +93,6 @@ declare class D1Store extends MastraStorage {
|
|
|
92
93
|
constructor(config: D1StoreConfig);
|
|
93
94
|
private getTableName;
|
|
94
95
|
private formatSqlParams;
|
|
95
|
-
private createIndexIfNotExists;
|
|
96
96
|
private executeWorkersBindingQuery;
|
|
97
97
|
private executeRestQuery;
|
|
98
98
|
/**
|
|
@@ -139,10 +139,20 @@ declare class D1Store extends MastraStorage {
|
|
|
139
139
|
deleteThread({ threadId }: {
|
|
140
140
|
threadId: string;
|
|
141
141
|
}): Promise<void>;
|
|
142
|
-
saveMessages(
|
|
143
|
-
messages:
|
|
144
|
-
|
|
145
|
-
|
|
142
|
+
saveMessages(args: {
|
|
143
|
+
messages: MastraMessageV1[];
|
|
144
|
+
format?: undefined | 'v1';
|
|
145
|
+
}): Promise<MastraMessageV1[]>;
|
|
146
|
+
saveMessages(args: {
|
|
147
|
+
messages: MastraMessageV2[];
|
|
148
|
+
format: 'v2';
|
|
149
|
+
}): Promise<MastraMessageV2[]>;
|
|
150
|
+
getMessages(args: StorageGetMessagesArg & {
|
|
151
|
+
format?: 'v1';
|
|
152
|
+
}): Promise<MastraMessageV1[]>;
|
|
153
|
+
getMessages(args: StorageGetMessagesArg & {
|
|
154
|
+
format: 'v2';
|
|
155
|
+
}): Promise<MastraMessageV2[]>;
|
|
146
156
|
persistWorkflowSnapshot({ workflowName, runId, snapshot, }: {
|
|
147
157
|
workflowName: string;
|
|
148
158
|
runId: string;
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var agent = require('@mastra/core/agent');
|
|
3
4
|
var storage = require('@mastra/core/storage');
|
|
4
5
|
var Cloudflare = require('cloudflare');
|
|
5
6
|
var utils = require('@mastra/core/utils');
|
|
@@ -285,30 +286,6 @@ var D1Store = class extends storage.MastraStorage {
|
|
|
285
286
|
formatSqlParams(params) {
|
|
286
287
|
return params.map((p) => p === void 0 || p === null ? null : p);
|
|
287
288
|
}
|
|
288
|
-
// Helper method to create SQL indexes for better query performance
|
|
289
|
-
async createIndexIfNotExists(tableName, columnName, indexType = "") {
|
|
290
|
-
const fullTableName = this.getTableName(tableName);
|
|
291
|
-
const indexName = `idx_${tableName}_${columnName}`;
|
|
292
|
-
try {
|
|
293
|
-
const checkQuery = createSqlBuilder().checkIndexExists(indexName, fullTableName);
|
|
294
|
-
const { sql: checkSql, params: checkParams } = checkQuery.build();
|
|
295
|
-
const indexExists = await this.executeQuery({
|
|
296
|
-
sql: checkSql,
|
|
297
|
-
params: checkParams,
|
|
298
|
-
first: true
|
|
299
|
-
});
|
|
300
|
-
if (!indexExists) {
|
|
301
|
-
const createQuery = createSqlBuilder().createIndex(indexName, fullTableName, columnName, indexType);
|
|
302
|
-
const { sql: createSql, params: createParams } = createQuery.build();
|
|
303
|
-
await this.executeQuery({ sql: createSql, params: createParams });
|
|
304
|
-
this.logger.debug(`Created index ${indexName} on ${fullTableName}(${columnName})`);
|
|
305
|
-
}
|
|
306
|
-
} catch (error) {
|
|
307
|
-
this.logger.error(`Error creating index on ${fullTableName}(${columnName}):`, {
|
|
308
|
-
message: error instanceof Error ? error.message : String(error)
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
289
|
async executeWorkersBindingQuery({
|
|
313
290
|
sql,
|
|
314
291
|
params = [],
|
|
@@ -687,8 +664,8 @@ var D1Store = class extends storage.MastraStorage {
|
|
|
687
664
|
throw new Error(`Failed to delete thread ${threadId}: ${error}`);
|
|
688
665
|
}
|
|
689
666
|
}
|
|
690
|
-
|
|
691
|
-
|
|
667
|
+
async saveMessages(args) {
|
|
668
|
+
const { messages, format = "v1" } = args;
|
|
692
669
|
if (messages.length === 0) return [];
|
|
693
670
|
try {
|
|
694
671
|
const now = /* @__PURE__ */ new Date();
|
|
@@ -718,13 +695,19 @@ var D1Store = class extends storage.MastraStorage {
|
|
|
718
695
|
records: messagesToInsert
|
|
719
696
|
});
|
|
720
697
|
this.logger.debug(`Saved ${messages.length} messages`);
|
|
721
|
-
|
|
698
|
+
const list = new agent.MessageList().add(messages, "memory");
|
|
699
|
+
if (format === `v2`) return list.get.all.v2();
|
|
700
|
+
return list.get.all.v1();
|
|
722
701
|
} catch (error) {
|
|
723
702
|
this.logger.error("Error saving messages:", { message: error instanceof Error ? error.message : String(error) });
|
|
724
703
|
throw error;
|
|
725
704
|
}
|
|
726
705
|
}
|
|
727
|
-
async getMessages({
|
|
706
|
+
async getMessages({
|
|
707
|
+
threadId,
|
|
708
|
+
selectBy,
|
|
709
|
+
format
|
|
710
|
+
}) {
|
|
728
711
|
const fullTableName = this.getTableName(storage.TABLE_MESSAGES);
|
|
729
712
|
const limit = typeof selectBy?.last === "number" ? selectBy.last : 40;
|
|
730
713
|
const include = selectBy?.include || [];
|
|
@@ -795,7 +778,9 @@ var D1Store = class extends storage.MastraStorage {
|
|
|
795
778
|
return processedMsg;
|
|
796
779
|
});
|
|
797
780
|
this.logger.debug(`Retrieved ${messages.length} messages for thread ${threadId}`);
|
|
798
|
-
|
|
781
|
+
const list = new agent.MessageList().add(processedMessages, "memory");
|
|
782
|
+
if (format === `v2`) return list.get.all.v2();
|
|
783
|
+
return list.get.all.v1();
|
|
799
784
|
} catch (error) {
|
|
800
785
|
this.logger.error("Error retrieving messages for thread", {
|
|
801
786
|
threadId,
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { MessageList } from '@mastra/core/agent';
|
|
1
2
|
import { MastraStorage, TABLE_THREADS, TABLE_MESSAGES, TABLE_WORKFLOW_SNAPSHOT, TABLE_TRACES, TABLE_EVALS } from '@mastra/core/storage';
|
|
2
3
|
import Cloudflare from 'cloudflare';
|
|
3
4
|
import { parseSqlIdentifier } from '@mastra/core/utils';
|
|
@@ -279,30 +280,6 @@ var D1Store = class extends MastraStorage {
|
|
|
279
280
|
formatSqlParams(params) {
|
|
280
281
|
return params.map((p) => p === void 0 || p === null ? null : p);
|
|
281
282
|
}
|
|
282
|
-
// Helper method to create SQL indexes for better query performance
|
|
283
|
-
async createIndexIfNotExists(tableName, columnName, indexType = "") {
|
|
284
|
-
const fullTableName = this.getTableName(tableName);
|
|
285
|
-
const indexName = `idx_${tableName}_${columnName}`;
|
|
286
|
-
try {
|
|
287
|
-
const checkQuery = createSqlBuilder().checkIndexExists(indexName, fullTableName);
|
|
288
|
-
const { sql: checkSql, params: checkParams } = checkQuery.build();
|
|
289
|
-
const indexExists = await this.executeQuery({
|
|
290
|
-
sql: checkSql,
|
|
291
|
-
params: checkParams,
|
|
292
|
-
first: true
|
|
293
|
-
});
|
|
294
|
-
if (!indexExists) {
|
|
295
|
-
const createQuery = createSqlBuilder().createIndex(indexName, fullTableName, columnName, indexType);
|
|
296
|
-
const { sql: createSql, params: createParams } = createQuery.build();
|
|
297
|
-
await this.executeQuery({ sql: createSql, params: createParams });
|
|
298
|
-
this.logger.debug(`Created index ${indexName} on ${fullTableName}(${columnName})`);
|
|
299
|
-
}
|
|
300
|
-
} catch (error) {
|
|
301
|
-
this.logger.error(`Error creating index on ${fullTableName}(${columnName}):`, {
|
|
302
|
-
message: error instanceof Error ? error.message : String(error)
|
|
303
|
-
});
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
283
|
async executeWorkersBindingQuery({
|
|
307
284
|
sql,
|
|
308
285
|
params = [],
|
|
@@ -681,8 +658,8 @@ var D1Store = class extends MastraStorage {
|
|
|
681
658
|
throw new Error(`Failed to delete thread ${threadId}: ${error}`);
|
|
682
659
|
}
|
|
683
660
|
}
|
|
684
|
-
|
|
685
|
-
|
|
661
|
+
async saveMessages(args) {
|
|
662
|
+
const { messages, format = "v1" } = args;
|
|
686
663
|
if (messages.length === 0) return [];
|
|
687
664
|
try {
|
|
688
665
|
const now = /* @__PURE__ */ new Date();
|
|
@@ -712,13 +689,19 @@ var D1Store = class extends MastraStorage {
|
|
|
712
689
|
records: messagesToInsert
|
|
713
690
|
});
|
|
714
691
|
this.logger.debug(`Saved ${messages.length} messages`);
|
|
715
|
-
|
|
692
|
+
const list = new MessageList().add(messages, "memory");
|
|
693
|
+
if (format === `v2`) return list.get.all.v2();
|
|
694
|
+
return list.get.all.v1();
|
|
716
695
|
} catch (error) {
|
|
717
696
|
this.logger.error("Error saving messages:", { message: error instanceof Error ? error.message : String(error) });
|
|
718
697
|
throw error;
|
|
719
698
|
}
|
|
720
699
|
}
|
|
721
|
-
async getMessages({
|
|
700
|
+
async getMessages({
|
|
701
|
+
threadId,
|
|
702
|
+
selectBy,
|
|
703
|
+
format
|
|
704
|
+
}) {
|
|
722
705
|
const fullTableName = this.getTableName(TABLE_MESSAGES);
|
|
723
706
|
const limit = typeof selectBy?.last === "number" ? selectBy.last : 40;
|
|
724
707
|
const include = selectBy?.include || [];
|
|
@@ -789,7 +772,9 @@ var D1Store = class extends MastraStorage {
|
|
|
789
772
|
return processedMsg;
|
|
790
773
|
});
|
|
791
774
|
this.logger.debug(`Retrieved ${messages.length} messages for thread ${threadId}`);
|
|
792
|
-
|
|
775
|
+
const list = new MessageList().add(processedMessages, "memory");
|
|
776
|
+
if (format === `v2`) return list.get.all.v2();
|
|
777
|
+
return list.get.all.v1();
|
|
793
778
|
} catch (error) {
|
|
794
779
|
this.logger.error("Error retrieving messages for thread", {
|
|
795
780
|
threadId,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/cloudflare-d1",
|
|
3
|
-
"version": "0.10.1-alpha.
|
|
3
|
+
"version": "0.10.1-alpha.2",
|
|
4
4
|
"description": "D1 provider for Mastra - includes db storage capabilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"typescript": "^5.8.2",
|
|
36
36
|
"vitest": "^3.1.2",
|
|
37
37
|
"@internal/lint": "0.0.7",
|
|
38
|
-
"@mastra/core": "0.10.2-alpha.
|
|
38
|
+
"@mastra/core": "0.10.2-alpha.4"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"@mastra/core": "^0.10.0-alpha.0"
|