@mastra/cloudflare 1.2.3 → 1.3.0

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.
Files changed (62) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/chunk-E4MARS3A.cjs +2135 -0
  3. package/dist/chunk-E4MARS3A.cjs.map +1 -0
  4. package/dist/chunk-NSFHQATX.js +2128 -0
  5. package/dist/chunk-NSFHQATX.js.map +1 -0
  6. package/dist/chunk-O57GFJSB.js +2265 -0
  7. package/dist/chunk-O57GFJSB.js.map +1 -0
  8. package/dist/chunk-ZBYNKKG6.cjs +2275 -0
  9. package/dist/chunk-ZBYNKKG6.cjs.map +1 -0
  10. package/dist/do/index.cjs +32 -0
  11. package/dist/do/index.cjs.map +1 -0
  12. package/dist/do/index.d.ts +91 -0
  13. package/dist/do/index.d.ts.map +1 -0
  14. package/dist/do/index.js +3 -0
  15. package/dist/do/index.js.map +1 -0
  16. package/dist/do/storage/db/index.d.ts +76 -0
  17. package/dist/do/storage/db/index.d.ts.map +1 -0
  18. package/dist/do/storage/domains/memory/index.d.ts +60 -0
  19. package/dist/do/storage/domains/memory/index.d.ts.map +1 -0
  20. package/dist/do/storage/domains/scores/index.d.ts +38 -0
  21. package/dist/do/storage/domains/scores/index.d.ts.map +1 -0
  22. package/dist/do/storage/domains/utils.d.ts +3 -0
  23. package/dist/do/storage/domains/utils.d.ts.map +1 -0
  24. package/dist/do/storage/domains/workflows/index.d.ts +46 -0
  25. package/dist/do/storage/domains/workflows/index.d.ts.map +1 -0
  26. package/dist/do/storage/sql-builder.d.ts +128 -0
  27. package/dist/do/storage/sql-builder.d.ts.map +1 -0
  28. package/dist/docs/SKILL.md +2 -2
  29. package/dist/docs/assets/SOURCE_MAP.json +56 -2
  30. package/dist/docs/references/reference-storage-cloudflare.md +79 -8
  31. package/dist/index.cjs +49 -2269
  32. package/dist/index.cjs.map +1 -1
  33. package/dist/index.d.ts +4 -1
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +2 -2262
  36. package/dist/index.js.map +1 -1
  37. package/dist/kv/index.cjs +28 -0
  38. package/dist/kv/index.cjs.map +1 -0
  39. package/dist/{storage → kv}/index.d.ts +11 -7
  40. package/dist/kv/index.d.ts.map +1 -0
  41. package/dist/kv/index.js +3 -0
  42. package/dist/kv/index.js.map +1 -0
  43. package/dist/kv/storage/db/index.d.ts.map +1 -0
  44. package/dist/kv/storage/domains/memory/index.d.ts.map +1 -0
  45. package/dist/kv/storage/domains/scores/index.d.ts.map +1 -0
  46. package/dist/kv/storage/domains/workflows/index.d.ts.map +1 -0
  47. package/dist/kv/storage/test-utils.d.ts.map +1 -0
  48. package/dist/kv/storage/types.d.ts.map +1 -0
  49. package/package.json +26 -5
  50. package/dist/storage/db/index.d.ts.map +0 -1
  51. package/dist/storage/domains/memory/index.d.ts.map +0 -1
  52. package/dist/storage/domains/scores/index.d.ts.map +0 -1
  53. package/dist/storage/domains/workflows/index.d.ts.map +0 -1
  54. package/dist/storage/index.d.ts.map +0 -1
  55. package/dist/storage/test-utils.d.ts.map +0 -1
  56. package/dist/storage/types.d.ts.map +0 -1
  57. /package/dist/{storage → kv/storage}/db/index.d.ts +0 -0
  58. /package/dist/{storage → kv/storage}/domains/memory/index.d.ts +0 -0
  59. /package/dist/{storage → kv/storage}/domains/scores/index.d.ts +0 -0
  60. /package/dist/{storage → kv/storage}/domains/workflows/index.d.ts +0 -0
  61. /package/dist/{storage → kv/storage}/test-utils.d.ts +0 -0
  62. /package/dist/{storage → kv/storage}/types.d.ts +0 -0
@@ -0,0 +1,76 @@
1
+ import type { SqlStorage } from '@cloudflare/workers-types';
2
+ import { MastraBase } from '@mastra/core/base';
3
+ import type { TABLE_NAMES, StorageColumn } from '@mastra/core/storage';
4
+ import type { SqlQueryOptions } from '../sql-builder.js';
5
+ export interface DODBConfig {
6
+ sql: SqlStorage;
7
+ tablePrefix?: string;
8
+ }
9
+ /**
10
+ * Configuration for standalone domain usage with Durable Objects.
11
+ */
12
+ export interface DODomainConfig {
13
+ sql: SqlStorage;
14
+ tablePrefix?: string;
15
+ }
16
+ export declare class DODB extends MastraBase {
17
+ private sql;
18
+ private tablePrefix;
19
+ constructor(config: DODBConfig);
20
+ hasColumn(table: string, column: string): Promise<boolean>;
21
+ getTableName(tableName: TABLE_NAMES): string;
22
+ private formatSqlParams;
23
+ /**
24
+ * Execute a SQL query using Durable Objects SqlStorage.
25
+ * SqlStorage.exec() is synchronous but we wrap in Promise for interface compatibility.
26
+ */
27
+ executeQuery(options: SqlQueryOptions): Promise<Record<string, unknown>[] | Record<string, unknown> | null>;
28
+ private getTableColumns;
29
+ private serializeValue;
30
+ protected getSqlType(type: StorageColumn['type']): string;
31
+ protected getDefaultValue(type: StorageColumn['type']): string;
32
+ createTable({ tableName, schema, }: {
33
+ tableName: TABLE_NAMES;
34
+ schema: Record<string, StorageColumn>;
35
+ }): Promise<void>;
36
+ clearTable({ tableName }: {
37
+ tableName: TABLE_NAMES;
38
+ }): Promise<void>;
39
+ dropTable({ tableName }: {
40
+ tableName: TABLE_NAMES;
41
+ }): Promise<void>;
42
+ alterTable(args: {
43
+ tableName: TABLE_NAMES;
44
+ schema: Record<string, StorageColumn>;
45
+ ifNotExists: string[];
46
+ }): Promise<void>;
47
+ insert({ tableName, record }: {
48
+ tableName: TABLE_NAMES;
49
+ record: Record<string, unknown>;
50
+ }): Promise<void>;
51
+ batchInsert({ tableName, records, }: {
52
+ tableName: TABLE_NAMES;
53
+ records: Record<string, unknown>[];
54
+ }): Promise<void>;
55
+ load<R>({ tableName, keys, orderBy, }: {
56
+ tableName: TABLE_NAMES;
57
+ keys: Record<string, string>;
58
+ orderBy?: {
59
+ column: string;
60
+ direction: 'ASC' | 'DESC';
61
+ };
62
+ }): Promise<R | null>;
63
+ processRecord(record: Record<string, unknown>): Promise<Record<string, unknown>>;
64
+ /**
65
+ * Upsert multiple records in a batch operation
66
+ * @param tableName The table to insert into
67
+ * @param records The records to insert
68
+ * @param conflictKeys The columns to use for conflict detection (defaults to ['id'])
69
+ */
70
+ batchUpsert({ tableName, records, conflictKeys, }: {
71
+ tableName: TABLE_NAMES;
72
+ records: Record<string, unknown>[];
73
+ conflictKeys?: string[];
74
+ }): Promise<void>;
75
+ }
76
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/do/storage/db/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAG/C,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAIvE,OAAO,KAAK,EAAY,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEhE,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,UAAU,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,UAAU,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,qBAAa,IAAK,SAAQ,UAAU;IAClC,OAAO,CAAC,GAAG,CAAa;IACxB,OAAO,CAAC,WAAW,CAAS;gBAEhB,MAAM,EAAE,UAAU;IASxB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAqBhE,YAAY,CAAC,SAAS,EAAE,WAAW,GAAG,MAAM;IAI5C,OAAO,CAAC,eAAe;IAIvB;;;OAGG;IACG,YAAY,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;YA2BnG,eAAe;IA0B7B,OAAO,CAAC,cAAc;IAatB,SA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MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC7B,OAAO,CAAC,EAAE;YAAE,MAAM,EAAE,MAAM,CAAC;YAAC,SAAS,EAAE,KAAK,GAAG,MAAM,CAAA;SAAE,CAAC;KACzD,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IAkDf,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAQtF;;;;;OAKG;IACG,WAAW,CAAC,EAChB,SAAS,EACT,OAAO,EACP,YAAqB,GACtB,EAAE;QACD,SAAS,EAAE,WAAW,CAAC;QACvB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;QACnC,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;KACzB,GAAG,OAAO,CAAC,IAAI,CAAC;CAyElB"}
@@ -0,0 +1,60 @@
1
+ import type { MastraMessageContentV2 } from '@mastra/core/agent';
2
+ import type { MastraDBMessage, StorageThreadType } from '@mastra/core/memory';
3
+ import { MemoryStorage } from '@mastra/core/storage';
4
+ import type { StorageResourceType, StorageListMessagesInput, StorageListMessagesOutput, StorageListThreadsInput, StorageListThreadsOutput } from '@mastra/core/storage';
5
+ import type { DODomainConfig } from '../../db/index.js';
6
+ export declare class MemoryStorageDO extends MemoryStorage {
7
+ #private;
8
+ constructor(config: DODomainConfig);
9
+ init(): Promise<void>;
10
+ dangerouslyClearAll(): Promise<void>;
11
+ getResourceById({ resourceId }: {
12
+ resourceId: string;
13
+ }): Promise<StorageResourceType | null>;
14
+ saveResource({ resource }: {
15
+ resource: StorageResourceType;
16
+ }): Promise<StorageResourceType>;
17
+ updateResource({ resourceId, workingMemory, metadata, }: {
18
+ resourceId: string;
19
+ workingMemory?: string;
20
+ metadata?: Record<string, unknown>;
21
+ }): Promise<StorageResourceType>;
22
+ getThreadById({ threadId }: {
23
+ threadId: string;
24
+ }): Promise<StorageThreadType | null>;
25
+ listThreads(args: StorageListThreadsInput): Promise<StorageListThreadsOutput>;
26
+ saveThread({ thread }: {
27
+ thread: StorageThreadType;
28
+ }): Promise<StorageThreadType>;
29
+ updateThread({ id, title, metadata, }: {
30
+ id: string;
31
+ title: string;
32
+ metadata: Record<string, unknown>;
33
+ }): Promise<StorageThreadType>;
34
+ deleteThread({ threadId }: {
35
+ threadId: string;
36
+ }): Promise<void>;
37
+ saveMessages(args: {
38
+ messages: MastraDBMessage[];
39
+ }): Promise<{
40
+ messages: MastraDBMessage[];
41
+ }>;
42
+ private _getIncludedMessages;
43
+ listMessagesById({ messageIds }: {
44
+ messageIds: string[];
45
+ }): Promise<{
46
+ messages: MastraDBMessage[];
47
+ }>;
48
+ listMessages(args: StorageListMessagesInput): Promise<StorageListMessagesOutput>;
49
+ updateMessages(args: {
50
+ messages: (Partial<Omit<MastraDBMessage, 'createdAt'>> & {
51
+ id: string;
52
+ content?: {
53
+ metadata?: MastraMessageContentV2['metadata'];
54
+ content?: MastraMessageContentV2['content'];
55
+ };
56
+ })[];
57
+ }): Promise<MastraDBMessage[]>;
58
+ deleteMessages(messageIds: string[]): Promise<void>;
59
+ }
60
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/do/storage/domains/memory/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAEjE,OAAO,KAAK,EAAmB,eAAe,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC/F,OAAO,EAGL,aAAa,EAQd,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EACV,mBAAmB,EACnB,wBAAwB,EACxB,yBAAyB,EACzB,uBAAuB,EACvB,wBAAwB,EACzB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAA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AAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IA8B/D,YAAY,CAAC,IAAI,EAAE;QAAE,QAAQ,EAAE,eAAe,EAAE,CAAA;KAAE,GAAG,OAAO,CAAC;QAAE,QAAQ,EAAE,eAAe,EAAE,CAAA;KAAE,CAAC;YA6ErF,oBAAoB;IA2ErB,gBAAgB,CAAC,EAAE,UAAU,EAAE,EAAE;QAAE,UAAU,EAAE,MAAM,EAAE,CAAA;KAAE,GAAG,OAAO,CAAC;QAAE,QAAQ,EAAE,eAAe,EAAE,CAAA;KAAE,CAAC;IAkDpG,YAAY,CAAC,IAAI,EAAE,wBAAwB,GAAG,OAAO,CAAC,yBAAyB,CAAC;IAqOvF,cAAc,CAAC,IAAI,EAAE;QACzB,QAAQ,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,eAAe,EAAE,WAAW,CAAC,CAAC,GAAG;YACvD,EAAE,EAAE,MAAM,CAAC;YACX,OAAO,CAAC,EAAE;gBACR,QAAQ,CAAC,EAAE,sBAAsB,CAAC,UAAU,CAAC,CAAC;gBAC9C,OAAO,CAAC,EAAE,sBAAsB,CAAC,SAAS,CAAC,CAAC;aAC7C,CAAC;SACH,CAAC,EAAE,CAAC;KACN,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;IA2GxB,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAuB1D"}
@@ -0,0 +1,38 @@
1
+ import type { ListScoresResponse, SaveScorePayload, ScoreRowData, ScoringSource } from '@mastra/core/evals';
2
+ import { ScoresStorage } from '@mastra/core/storage';
3
+ import type { StoragePagination } from '@mastra/core/storage';
4
+ import type { DODomainConfig } from '../../db/index.js';
5
+ export declare class ScoresStorageDO extends ScoresStorage {
6
+ #private;
7
+ constructor(config: DODomainConfig);
8
+ init(): Promise<void>;
9
+ dangerouslyClearAll(): Promise<void>;
10
+ getScoreById({ id }: {
11
+ id: string;
12
+ }): Promise<ScoreRowData | null>;
13
+ saveScore(score: SaveScorePayload): Promise<{
14
+ score: ScoreRowData;
15
+ }>;
16
+ listScoresByScorerId({ scorerId, entityId, entityType, source, pagination, }: {
17
+ scorerId: string;
18
+ entityId?: string;
19
+ entityType?: string;
20
+ source?: ScoringSource;
21
+ pagination: StoragePagination;
22
+ }): Promise<ListScoresResponse>;
23
+ listScoresByRunId({ runId, pagination, }: {
24
+ runId: string;
25
+ pagination: StoragePagination;
26
+ }): Promise<ListScoresResponse>;
27
+ listScoresByEntityId({ entityId, entityType, pagination, }: {
28
+ pagination: StoragePagination;
29
+ entityId: string;
30
+ entityType: string;
31
+ }): Promise<ListScoresResponse>;
32
+ listScoresBySpan({ traceId, spanId, pagination, }: {
33
+ traceId: string;
34
+ spanId: string;
35
+ pagination: StoragePagination;
36
+ }): Promise<ListScoresResponse>;
37
+ }
38
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/do/storage/domains/scores/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAE5G,OAAO,EAEL,aAAa,EAMd,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAG9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAgB/C,qBAAa,eAAgB,SAAQ,aAAa;;gBAGpC,MAAM,EAAE,cAAc;IAK5B,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAIrB,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC;IAIpC,YAAY,CAAC,EAAE,EAAE,EAAE,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAyBlE,SAAS,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,YAAY,CAAA;KAAE,CAAC;IA4EpE,oBAAoB,CAAC,EACzB,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,MAAM,EACN,UAAU,GACX,EAAE;QACD,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,MAAM,CAAC,EAAE,aAAa,CAAC;QACvB,UAAU,EAAE,iBAAiB,CAAC;KAC/B,GAAG,OAAO,CAAC,kBAAkB,CAAC;IA+EzB,iBAAiB,CAAC,EACtB,KAAK,EACL,UAAU,GACX,EAAE;QACD,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,EAAE,iBAAiB,CAAC;KAC/B,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAgEzB,oBAAoB,CAAC,EACzB,QAAQ,EACR,UAAU,EACV,UAAU,GACX,EAAE;QACD,UAAU,EAAE,iBAAiB,CAAC;QAC9B,QAAQ,EAAE,MAAM,CAAC;QACjB,UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAqEzB,gBAAgB,CAAC,EACrB,OAAO,EACP,MAAM,EACN,UAAU,GACX,EAAE;QACD,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;QACf,UAAU,EAAE,iBAAiB,CAAC;KAC/B,GAAG,OAAO,CAAC,kBAAkB,CAAC;CAoEhC"}
@@ -0,0 +1,3 @@
1
+ export declare function isArrayOfRecords(value: unknown): value is Record<string, unknown>[];
2
+ export declare function deserializeValue(value: unknown, type?: string): unknown;
3
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/do/storage/domains/utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAEnF;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAwBvE"}
@@ -0,0 +1,46 @@
1
+ import type { WorkflowRun, WorkflowRuns, StorageListWorkflowRunsInput, UpdateWorkflowStateOptions } from '@mastra/core/storage';
2
+ import { WorkflowsStorage } from '@mastra/core/storage';
3
+ import type { StepResult, WorkflowRunState } from '@mastra/core/workflows';
4
+ import type { DODomainConfig } from '../../db/index.js';
5
+ export declare class WorkflowsStorageDO extends WorkflowsStorage {
6
+ #private;
7
+ constructor(config: DODomainConfig);
8
+ supportsConcurrentUpdates(): boolean;
9
+ init(): Promise<void>;
10
+ dangerouslyClearAll(): Promise<void>;
11
+ updateWorkflowResults({}: {
12
+ workflowName: string;
13
+ runId: string;
14
+ stepId: string;
15
+ result: StepResult<unknown, unknown, unknown, unknown>;
16
+ requestContext: Record<string, unknown>;
17
+ }): Promise<Record<string, StepResult<unknown, unknown, unknown, unknown>>>;
18
+ updateWorkflowState({}: {
19
+ workflowName: string;
20
+ runId: string;
21
+ opts: UpdateWorkflowStateOptions;
22
+ }): Promise<WorkflowRunState | undefined>;
23
+ persistWorkflowSnapshot({ workflowName, runId, resourceId, snapshot, createdAt, updatedAt, }: {
24
+ workflowName: string;
25
+ runId: string;
26
+ resourceId?: string;
27
+ snapshot: WorkflowRunState;
28
+ createdAt?: Date;
29
+ updatedAt?: Date;
30
+ }): Promise<void>;
31
+ loadWorkflowSnapshot(params: {
32
+ workflowName: string;
33
+ runId: string;
34
+ }): Promise<WorkflowRunState | null>;
35
+ private parseWorkflowRun;
36
+ listWorkflowRuns({ workflowName, fromDate, toDate, page, perPage, resourceId, status, }?: StorageListWorkflowRunsInput): Promise<WorkflowRuns>;
37
+ getWorkflowRunById({ runId, workflowName, }: {
38
+ runId: string;
39
+ workflowName?: string;
40
+ }): Promise<WorkflowRun | null>;
41
+ deleteWorkflowRunById({ runId, workflowName }: {
42
+ runId: string;
43
+ workflowName: string;
44
+ }): Promise<void>;
45
+ }
46
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/do/storage/domains/workflows/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,WAAW,EACX,YAAY,EACZ,4BAA4B,EAC5B,0BAA0B,EAC3B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAKL,gBAAgB,EACjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAG3E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAK/C,qBAAa,kBAAmB,SAAQ,gBAAgB;;gBAG1C,MAAM,EAAE,cAAc;IAKlC,yBAAyB,IAAI,OAAO;IAK9B,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAIrB,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC;IAI1C,qBAAqB,CACnB,EAMC,EAAE;QACD,YAAY,EAAE,MAAM,CAAC;QACrB,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QACvD,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACzC,GACA,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;IAG1E,mBAAmB,CACjB,EAIC,EAAE;QACD,YAAY,EAAE,MAAM,CAAC;QACrB,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,0BAA0B,CAAC;KAClC,GACA,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC;IAIlC,uBAAuB,CAAC,EAC5B,YAAY,EACZ,KAAK,EACL,UAAU,EACV,QAAQ,EACR,SAAS,EACT,SAAS,GACV,EAAE;QACD,YAAY,EAAE,MAAM,CAAC;QACrB,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,QAAQ,EAAE,gBAAgB,CAAC;QAC3B,SAAS,CAAC,EAAE,IAAI,CAAC;QACjB,SAAS,CAAC,EAAE,IAAI,CAAC;KAClB,GAAG,OAAO,CAAC,IAAI,CAAC;IAoEX,oBAAoB,CAAC,MAAM,EAAE;QAAE,YAAY,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC;IA6B7G,OAAO,CAAC,gBAAgB;IAqBlB,gBAAgB,CAAC,EACrB,YAAY,EACZ,QAAQ,EACR,MAAM,EACN,IAAI,EACJ,OAAO,EACP,UAAU,EACV,MAAM,GACP,GAAE,4BAAiC,GAAG,OAAO,CAAC,YAAY,CAAC;IA2EtD,kBAAkB,CAAC,EACvB,KAAK,EACL,YAAY,GACb,EAAE;QACD,KAAK,EAAE,MAAM,CAAC;QACd,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAgCzB,qBAAqB,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAmB7G"}
@@ -0,0 +1,128 @@
1
+ /**
2
+ * Type definition for SQL query parameters
3
+ */
4
+ export type SqlParam = string | number | boolean | null | undefined;
5
+ /**
6
+ * Interface for SQL query options with generic type support
7
+ */
8
+ export interface SqlQueryOptions {
9
+ /** SQL query to execute */
10
+ sql: string;
11
+ /** Parameters to bind to the query */
12
+ params?: SqlParam[];
13
+ /** Whether to return only the first result */
14
+ first?: boolean;
15
+ }
16
+ /**
17
+ * SQL Builder class for constructing type-safe SQL queries
18
+ * This helps create maintainable and secure SQL queries with proper parameter handling
19
+ */
20
+ export declare class SqlBuilder {
21
+ private sql;
22
+ private params;
23
+ private whereAdded;
24
+ select(columns?: string | string[]): SqlBuilder;
25
+ from(table: string): SqlBuilder;
26
+ /**
27
+ * Add a WHERE clause to the query
28
+ * @param condition The condition to add
29
+ * @param params Parameters to bind to the condition
30
+ */
31
+ where(condition: string, ...params: SqlParam[]): SqlBuilder;
32
+ /**
33
+ * Add a WHERE clause if it hasn't been added yet, otherwise add an AND clause
34
+ * @param condition The condition to add
35
+ * @param params Parameters to bind to the condition
36
+ */
37
+ whereAnd(condition: string, ...params: SqlParam[]): SqlBuilder;
38
+ andWhere(condition: string, ...params: SqlParam[]): SqlBuilder;
39
+ orWhere(condition: string, ...params: SqlParam[]): SqlBuilder;
40
+ orderBy(column: string, direction?: 'ASC' | 'DESC'): SqlBuilder;
41
+ limit(count: number): SqlBuilder;
42
+ offset(count: number): SqlBuilder;
43
+ count(): SqlBuilder;
44
+ /**
45
+ * Insert a row, or update specific columns on conflict (upsert).
46
+ * @param table Table name
47
+ * @param columns Columns to insert
48
+ * @param values Values to insert
49
+ * @param conflictColumns Columns to check for conflict (usually PK or UNIQUE)
50
+ * @param updateMap Object mapping columns to update to their new value (e.g. { name: 'excluded.name' })
51
+ */
52
+ insert(table: string, columns: string[], values: SqlParam[], conflictColumns?: string[], updateMap?: Record<string, string>): SqlBuilder;
53
+ update(table: string, columns: string[], values: SqlParam[]): SqlBuilder;
54
+ delete(table: string): SqlBuilder;
55
+ /**
56
+ * Create a table if it doesn't exist
57
+ * @param table The table name
58
+ * @param columnDefinitions The column definitions as an array of strings
59
+ * @param tableConstraints Optional constraints for the table
60
+ * @returns The builder instance
61
+ */
62
+ createTable(table: string, columnDefinitions: string[], tableConstraints?: string[]): SqlBuilder;
63
+ /**
64
+ * Check if an index exists in the database
65
+ * @param indexName The name of the index to check
66
+ * @param tableName The table the index is on
67
+ * @returns The builder instance
68
+ */
69
+ checkIndexExists(indexName: string, tableName: string): SqlBuilder;
70
+ /**
71
+ * Create an index if it doesn't exist
72
+ * @param indexName The name of the index to create
73
+ * @param tableName The table to create the index on
74
+ * @param columnName The column to index
75
+ * @param indexType Optional index type (e.g., 'UNIQUE')
76
+ * @returns The builder instance
77
+ */
78
+ createIndex(indexName: string, tableName: string, columnName: string, indexType?: string): SqlBuilder;
79
+ /**
80
+ * Add a LIKE condition to the query
81
+ * @param column The column to check
82
+ * @param value The value to match (will be wrapped with % for LIKE)
83
+ * @param exact If true, will not add % wildcards
84
+ */
85
+ like(column: string, value: string, exact?: boolean): SqlBuilder;
86
+ /**
87
+ * Add a JSON LIKE condition for searching in JSON fields
88
+ * @param column The JSON column to search in
89
+ * @param key The JSON key to match
90
+ * @param value The value to match
91
+ */
92
+ jsonLike(column: string, key: string, value: string): SqlBuilder;
93
+ /**
94
+ * Get the built query
95
+ * @returns Object containing the SQL string and parameters array
96
+ */
97
+ build(): {
98
+ sql: string;
99
+ params: SqlParam[];
100
+ };
101
+ /**
102
+ * Reset the builder for reuse
103
+ * @returns The reset builder instance
104
+ */
105
+ reset(): SqlBuilder;
106
+ }
107
+ export declare function createSqlBuilder(): SqlBuilder;
108
+ /** Represents a validated SQL SELECT column identifier (or '*', optionally with 'AS alias'). */
109
+ type SelectIdentifier = string & {
110
+ __brand: 'SelectIdentifier';
111
+ };
112
+ /**
113
+ * Parses and returns a valid SQL SELECT column identifier.
114
+ * Allows a single identifier (letters, numbers, underscores), or '*', optionally with 'AS alias'.
115
+ *
116
+ * @param column - The column identifier string to parse.
117
+ * @returns The validated column identifier as a branded type.
118
+ * @throws {Error} If invalid.
119
+ *
120
+ * @example
121
+ * const col = parseSelectIdentifier('user_id'); // Ok
122
+ * parseSelectIdentifier('user_id AS uid'); // Ok
123
+ * parseSelectIdentifier('*'); // Ok
124
+ * parseSelectIdentifier('user id'); // Throws error
125
+ */
126
+ export declare function parseSelectIdentifier(column: string): SelectIdentifier;
127
+ export {};
128
+ //# sourceMappingURL=sql-builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sql-builder.d.ts","sourceRoot":"","sources":["../../../src/do/storage/sql-builder.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC;AAEpE;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,2BAA2B;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,sCAAsC;IACtC,MAAM,CAAC,EAAE,QAAQ,EAAE,CAAC;IACpB,8CAA8C;IAC9C,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;;GAGG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,GAAG,CAAc;IACzB,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,UAAU,CAAkB;IAGpC,MAAM,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,UAAU;IAW/C,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU;IAM/B;;;;OAIG;IACH,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,QAAQ,EAAE,GAAG,UAAU;IAO3D;;;;OAIG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,QAAQ,EAAE,GAAG,UAAU;IAQ9D,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,QAAQ,EAAE,GAAG,UAAU;IAM9D,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,QAAQ,EAAE,GAAG,UAAU;IAM7D,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,GAAE,KAAK,GAAG,MAAc,GAAG,UAAU;IAStE,KAAK,CAAC,KAAK,EAAE,MAAM,G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gBAAgB,IAAI,UAAU,CAE7C;AAED,gGAAgG;AAChG,KAAK,gBAAgB,GAAG,MAAM,GAAG;IAAE,OAAO,EAAE,kBAAkB,CAAA;CAAE,CAAC;AAIjE;;;;;;;;;;;;;GAaG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,gBAAgB,CAOtE"}
@@ -3,7 +3,7 @@ name: mastra-cloudflare
3
3
  description: Documentation for @mastra/cloudflare. Use when working with @mastra/cloudflare APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/cloudflare"
6
- version: "1.2.3"
6
+ version: "1.3.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -16,7 +16,7 @@ Read the individual reference documents for detailed explanations and code examp
16
16
 
17
17
  ### Reference
18
18
 
19
- - [Reference: Cloudflare storage](references/reference-storage-cloudflare.md) - Documentation for the Cloudflare KV storage implementation in Mastra.
19
+ - [Reference: Cloudflare Storage](references/reference-storage-cloudflare.md) - Documentation for Cloudflare storage implementations in Mastra, including KV and Durable Objects.
20
20
 
21
21
 
22
22
  Read [assets/SOURCE_MAP.json](assets/SOURCE_MAP.json) for source code references.
@@ -1,6 +1,60 @@
1
1
  {
2
- "version": "1.2.3",
2
+ "version": "1.3.0",
3
3
  "package": "@mastra/cloudflare",
4
- "exports": {},
4
+ "exports": {
5
+ "CloudflareDOStorage": {
6
+ "types": "dist/index.d.ts",
7
+ "implementation": "dist/chunk-NSFHQATX.js",
8
+ "line": 2083
9
+ },
10
+ "DODB": {
11
+ "types": "dist/index.d.ts",
12
+ "implementation": "dist/chunk-NSFHQATX.js",
13
+ "line": 282
14
+ },
15
+ "DOStore": {
16
+ "types": "dist/index.d.ts",
17
+ "implementation": "dist/chunk-NSFHQATX.js"
18
+ },
19
+ "MemoryStorageDO": {
20
+ "types": "dist/index.d.ts",
21
+ "implementation": "dist/chunk-NSFHQATX.js",
22
+ "line": 661
23
+ },
24
+ "ScoresStorageDO": {
25
+ "types": "dist/index.d.ts",
26
+ "implementation": "dist/chunk-NSFHQATX.js",
27
+ "line": 1500
28
+ },
29
+ "WorkflowsStorageDO": {
30
+ "types": "dist/index.d.ts",
31
+ "implementation": "dist/chunk-NSFHQATX.js",
32
+ "line": 1818
33
+ },
34
+ "CloudflareKVStorage": {
35
+ "types": "dist/index.d.ts",
36
+ "implementation": "dist/chunk-O57GFJSB.js",
37
+ "line": 2176
38
+ },
39
+ "CloudflareStore": {
40
+ "types": "dist/index.d.ts",
41
+ "implementation": "dist/chunk-O57GFJSB.js"
42
+ },
43
+ "MemoryStorageCloudflare": {
44
+ "types": "dist/index.d.ts",
45
+ "implementation": "dist/chunk-O57GFJSB.js",
46
+ "line": 562
47
+ },
48
+ "ScoresStorageCloudflare": {
49
+ "types": "dist/index.d.ts",
50
+ "implementation": "dist/chunk-O57GFJSB.js",
51
+ "line": 1604
52
+ },
53
+ "WorkflowsStorageCloudflare": {
54
+ "types": "dist/index.d.ts",
55
+ "implementation": "dist/chunk-O57GFJSB.js",
56
+ "line": 1904
57
+ }
58
+ },
5
59
  "modules": {}
6
60
  }
@@ -1,8 +1,11 @@
1
1
  # Cloudflare storage
2
2
 
3
- The Cloudflare KV storage implementation provides a globally distributed, serverless key-value store solution using Cloudflare Workers KV.
3
+ Mastra provides two Cloudflare storage implementations:
4
4
 
5
- > **Observability Not Supported:** Cloudflare KV storage **doesn't support the observability domain**. Traces from the `DefaultExporter` can't be persisted to KV, and Mastra Studio's observability features won't work with Cloudflare KV as your only storage provider. To enable observability, use [composite storage](https://mastra.ai/reference/storage/composite) to route observability data to a supported provider like ClickHouse or PostgreSQL.
5
+ - **Cloudflare KV** (`CloudflareKVStorage`) - A globally distributed, eventually consistent key-value store
6
+ - **Cloudflare Durable Objects** (`CloudflareDOStorage`) - A strongly consistent, SQLite-based storage using Durable Objects
7
+
8
+ > **Observability Not Supported:** Cloudflare storage **does not support the observability domain**. Traces from the `DefaultExporter` cannot be persisted, and Mastra Studio's observability features won't work with Cloudflare as your only storage provider. To enable observability, use [composite storage](https://mastra.ai/reference/storage/composite) to route observability data to a supported provider like ClickHouse or PostgreSQL.
6
9
 
7
10
  ## Installation
8
11
 
@@ -30,13 +33,17 @@ yarn add @mastra/cloudflare@latest
30
33
  bun add @mastra/cloudflare@latest
31
34
  ```
32
35
 
33
- ## Usage
36
+ ## Cloudflare KV Storage
37
+
38
+ The KV storage implementation provides a globally distributed, serverless key-value store solution using Cloudflare Workers KV.
39
+
40
+ ### Usage
34
41
 
35
42
  ```typescript
36
- import { CloudflareStore } from '@mastra/cloudflare'
43
+ import { CloudflareKVStorage } from '@mastra/cloudflare/kv'
37
44
 
38
45
  // --- Example 1: Using Workers Binding ---
39
- const storageWorkers = new CloudflareStore({
46
+ const storageWorkers = new CloudflareKVStorage({
40
47
  id: 'cloudflare-workers-storage',
41
48
  bindings: {
42
49
  threads: THREADS_KV, // KVNamespace binding for threads table
@@ -47,7 +54,7 @@ const storageWorkers = new CloudflareStore({
47
54
  })
48
55
 
49
56
  // --- Example 2: Using REST API ---
50
- const storageRest = new CloudflareStore({
57
+ const storageRest = new CloudflareKVStorage({
51
58
  id: 'cloudflare-rest-storage',
52
59
  accountId: process.env.CLOUDFLARE_ACCOUNT_ID!, // Cloudflare Account ID
53
60
  apiToken: process.env.CLOUDFLARE_API_TOKEN!, // Cloudflare API Token
@@ -55,7 +62,7 @@ const storageRest = new CloudflareStore({
55
62
  })
56
63
  ```
57
64
 
58
- ## Parameters
65
+ ### Parameters
59
66
 
60
67
  **id** (`string`): Unique identifier for this storage instance.
61
68
 
@@ -85,4 +92,68 @@ Cloudflare KV is an eventually consistent store, meaning that data may not be im
85
92
 
86
93
  ### Key Structure & Namespacing
87
94
 
88
- Keys in Cloudflare KV are structured as a combination of a configurable prefix and a table-specific format (e.g., `threads:threadId`). For Workers deployments, `keyPrefix` is used to isolate data within a namespace; for REST API deployments, `namespacePrefix` is used to isolate entire namespaces between environments or applications.
95
+ Keys in Cloudflare KV are structured as a combination of a configurable prefix and a table-specific format (e.g., `threads:threadId`). For Workers deployments, `keyPrefix` is used to isolate data within a namespace; for REST API deployments, `namespacePrefix` is used to isolate entire namespaces between environments or applications.
96
+
97
+ ## Cloudflare Durable Objects Storage
98
+
99
+ The Durable Objects storage implementation provides strongly consistent, SQLite-based storage using Cloudflare Durable Objects. This is ideal for applications that require transactional consistency and SQL query capabilities.
100
+
101
+ ### Usage
102
+
103
+ ```typescript
104
+ import { DurableObject } from 'cloudflare:workers'
105
+ import { CloudflareDOStorage } from '@mastra/cloudflare/do'
106
+
107
+ class AgentDurableObject extends DurableObject<Env> {
108
+ private storage: CloudflareDOStorage
109
+
110
+ constructor(ctx: DurableObjectState, env: Env) {
111
+ super(ctx, env)
112
+ this.storage = new CloudflareDOStorage({
113
+ sql: ctx.storage.sql,
114
+ tablePrefix: 'mastra_', // Optional: prefix for table names
115
+ })
116
+ }
117
+
118
+ async run() {
119
+ const memory = await this.storage.getStore('memory')
120
+ await memory?.saveThread({
121
+ thread: { id: 'thread-1', resourceId: 'user-1', title: 'Chat', metadata: {} },
122
+ })
123
+ }
124
+ }
125
+ ```
126
+
127
+ ### Parameters
128
+
129
+ **sql** (`SqlStorage`): SqlStorage instance from Durable Objects ctx.storage.sql
130
+
131
+ **tablePrefix** (`string`): Optional prefix for table names (only letters, numbers, and underscores allowed)
132
+
133
+ **disableInit** (`boolean`): When true, automatic table creation/migrations are disabled. Useful for CI/CD pipelines where migrations run separately.
134
+
135
+ ### Strong Consistency
136
+
137
+ Unlike KV, Durable Objects provide strong consistency guarantees. All reads and writes within a Durable Object are serialized, making it very suitable for fast, long-running agents.
138
+
139
+ ### SQL Capabilities
140
+
141
+ Durable Objects storage uses SQLite under the hood, enabling efficient queries, filtering, and pagination that aren't possible with key-value storage.
142
+
143
+ ## Schema Management
144
+
145
+ Both storage implementations handle schema creation and updates automatically. They create the following tables:
146
+
147
+ - `threads`: Stores conversation threads
148
+ - `messages`: Stores individual messages
149
+ - `workflow_snapshot`: Stores workflow run state
150
+
151
+ ## Deprecated Aliases
152
+
153
+ For backwards compatibility, the following aliases are available:
154
+
155
+ ```typescript
156
+ // These are deprecated - use CloudflareKVStorage and CloudflareDOStorage instead
157
+ import { CloudflareStore } from '@mastra/cloudflare/kv' // alias for CloudflareKVStorage
158
+ import { DOStore } from '@mastra/cloudflare/do' // alias for CloudflareDOStorage
159
+ ```