@mastra/cloudflare 0.0.0-vnextWorkflows-20250422081019 → 0.0.0-workflow-deno-20250616132510

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.
@@ -1,11 +1,13 @@
1
1
  import type { EvalRow } from '@mastra/core/storage';
2
2
  import type { KVNamespace as KVNamespace_2 } from '@cloudflare/workers-types';
3
3
  import { KVNamespaceListKey as KVNamespaceListKey_2 } from '@cloudflare/workers-types';
4
+ import type { MastraMessageV1 } from '@mastra/core/memory';
5
+ import type { MastraMessageV2 } from '@mastra/core/memory';
4
6
  import { MastraStorage } from '@mastra/core/storage';
5
- import type { MessageType } from '@mastra/core/memory';
6
- import type { MessageType as MessageType_2 } from '@mastra/core';
7
+ import type { PaginationInfo } from '@mastra/core/storage';
7
8
  import type { StorageColumn } from '@mastra/core/storage';
8
9
  import type { StorageGetMessagesArg } from '@mastra/core/storage';
10
+ import type { StorageGetTracesArg } from '@mastra/core/storage';
9
11
  import type { StorageThreadType } from '@mastra/core/memory';
10
12
  import type { TABLE_EVALS } from '@mastra/core/storage';
11
13
  import type { TABLE_MESSAGES } from '@mastra/core/storage';
@@ -13,6 +15,8 @@ import type { TABLE_NAMES } from '@mastra/core/storage';
13
15
  import type { TABLE_THREADS } from '@mastra/core/storage';
14
16
  import type { TABLE_TRACES } from '@mastra/core/storage';
15
17
  import type { TABLE_WORKFLOW_SNAPSHOT } from '@mastra/core/storage';
18
+ import type { Trace } from '@mastra/core/telemetry';
19
+ import type { WorkflowRun } from '@mastra/core/storage';
16
20
  import type { WorkflowRuns } from '@mastra/core/storage';
17
21
  import type { WorkflowRunState } from '@mastra/core/workflows';
18
22
  import type { WorkflowRunState as WorkflowRunState_2 } from '@mastra/core';
@@ -46,15 +50,26 @@ declare class CloudflareStore extends MastraStorage {
46
50
  private getNamespaceValue;
47
51
  private putNamespaceValue;
48
52
  private deleteNamespaceValue;
49
- listNamespaceKeys(tableName: TABLE_NAMES, options?: {
50
- limit?: number;
51
- prefix?: string;
52
- }): Promise<KVNamespaceListKey_2<unknown, string>[]>;
53
+ listNamespaceKeys(tableName: TABLE_NAMES, options?: ListOptions): Promise<KVNamespaceListKey_2<unknown, string>[]>;
53
54
  private createNamespaceById;
54
55
  private getNamespaceIdByName;
55
56
  private createNamespace;
56
57
  private getOrCreateNamespaceId;
57
58
  private getNamespaceId;
59
+ private LEGACY_NAMESPACE_MAP;
60
+ /**
61
+ * There were a few legacy mappings for tables such as
62
+ * - messages -> threads
63
+ * - workflow_snapshot -> mastra_workflows
64
+ * - traces -> evals
65
+ * This has been updated to use dedicated namespaces for each table.
66
+ * In the case of data for a table existing in the legacy namespace, warn the user to migrate to the new namespace.
67
+ *
68
+ * @param tableName The table name to check for legacy data
69
+ * @param prefix The namespace prefix
70
+ * @returns The legacy namespace ID if data exists; otherwise, null
71
+ */
72
+ private checkLegacyNamespace;
58
73
  /**
59
74
  * Helper to safely serialize data for KV storage
60
75
  */
@@ -93,19 +108,28 @@ declare class CloudflareStore extends MastraStorage {
93
108
  private validateColumnValue;
94
109
  private validateAgainstSchema;
95
110
  private validateRecord;
96
- private ensureDate;
97
- private serializeDate;
98
111
  private ensureMetadata;
99
112
  createTable({ tableName, schema, }: {
100
113
  tableName: TABLE_NAMES;
101
114
  schema: Record<string, StorageColumn>;
102
115
  }): Promise<void>;
116
+ /**
117
+ * No-op: This backend is schemaless and does not require schema changes.
118
+ * @param tableName Name of the table
119
+ * @param schema Schema of the table
120
+ * @param ifNotExists Array of column names to add if they don't exist
121
+ */
122
+ alterTable(_args: {
123
+ tableName: TABLE_NAMES;
124
+ schema: Record<string, StorageColumn>;
125
+ ifNotExists: string[];
126
+ }): Promise<void>;
103
127
  clearTable({ tableName }: {
104
128
  tableName: TABLE_NAMES;
105
129
  }): Promise<void>;
106
- insert<T extends TABLE_NAMES>({ tableName, record }: {
130
+ insert<T extends TABLE_NAMES>({ tableName, record, }: {
107
131
  tableName: T;
108
- record: RecordTypes[T];
132
+ record: Record<string, any>;
109
133
  }): Promise<void>;
110
134
  load<R>({ tableName, keys }: {
111
135
  tableName: TABLE_NAMES;
@@ -130,10 +154,20 @@ declare class CloudflareStore extends MastraStorage {
130
154
  }): Promise<void>;
131
155
  private getMessageKey;
132
156
  private getThreadMessagesKey;
133
- saveMessages({ messages }: {
134
- messages: MessageType[];
135
- }): Promise<MessageType[]>;
136
- getMessages<T extends MessageType = MessageType>({ threadId, selectBy }: StorageGetMessagesArg): Promise<T[]>;
157
+ saveMessages(args: {
158
+ messages: MastraMessageV1[];
159
+ format?: undefined | 'v1';
160
+ }): Promise<MastraMessageV1[]>;
161
+ saveMessages(args: {
162
+ messages: MastraMessageV2[];
163
+ format: 'v2';
164
+ }): Promise<MastraMessageV2[]>;
165
+ getMessages(args: StorageGetMessagesArg & {
166
+ format?: 'v1';
167
+ }): Promise<MastraMessageV1[]>;
168
+ getMessages(args: StorageGetMessagesArg & {
169
+ format: 'v2';
170
+ }): Promise<MastraMessageV2[]>;
137
171
  private validateWorkflowParams;
138
172
  private validateWorkflowState;
139
173
  private normalizeSteps;
@@ -153,23 +187,46 @@ declare class CloudflareStore extends MastraStorage {
153
187
  tableName: T;
154
188
  records: Partial<RecordTypes[T]>[];
155
189
  }): Promise<void>;
156
- getTraces({ name, scope, page, perPage, attributes, }: {
190
+ getTraces({ name, scope, page, perPage, attributes, fromDate, toDate, }: {
157
191
  name?: string;
158
192
  scope?: string;
159
193
  page: number;
160
194
  perPage: number;
161
195
  attributes?: Record<string, string>;
196
+ fromDate?: Date;
197
+ toDate?: Date;
162
198
  }): Promise<any[]>;
163
199
  private parseJSON;
164
200
  getEvalsByAgentName(_agentName: string, _type?: 'test' | 'live'): Promise<EvalRow[]>;
165
- getWorkflowRuns(_args?: {
201
+ private parseWorkflowRun;
202
+ private buildWorkflowSnapshotPrefix;
203
+ getWorkflowRuns({ namespace, workflowName, limit, offset, resourceId, fromDate, toDate, }?: {
166
204
  namespace?: string;
167
205
  workflowName?: string;
168
- fromDate?: Date;
169
- toDate?: Date;
170
206
  limit?: number;
171
207
  offset?: number;
208
+ resourceId?: string;
209
+ fromDate?: Date;
210
+ toDate?: Date;
172
211
  }): Promise<WorkflowRuns>;
212
+ getWorkflowRunById({ namespace, runId, workflowName, }: {
213
+ namespace: string;
214
+ runId: string;
215
+ workflowName: string;
216
+ }): Promise<WorkflowRun | null>;
217
+ getTracesPaginated(_args: StorageGetTracesArg): Promise<PaginationInfo & {
218
+ traces: Trace[];
219
+ }>;
220
+ getThreadsByResourceIdPaginated(_args: {
221
+ resourceId: string;
222
+ page?: number;
223
+ perPage?: number;
224
+ }): Promise<PaginationInfo & {
225
+ threads: StorageThreadType[];
226
+ }>;
227
+ getMessagesPaginated(_args: StorageGetMessagesArg): Promise<PaginationInfo & {
228
+ messages: MastraMessageV1[] | MastraMessageV2[];
229
+ }>;
173
230
  close(): Promise<void>;
174
231
  }
175
232
  export { CloudflareStore }
@@ -192,19 +249,6 @@ export declare interface CloudflareWorkersConfig {
192
249
  keyPrefix?: string;
193
250
  }
194
251
 
195
- export declare const createSampleMessage: (threadId: string) => MessageType_2;
196
-
197
- export declare const createSampleThread: () => {
198
- id: string;
199
- resourceId: string;
200
- title: string;
201
- createdAt: Date;
202
- updatedAt: Date;
203
- metadata: {
204
- key: string;
205
- };
206
- };
207
-
208
252
  export declare const createSampleTrace: (name: string, scope?: string, attributes?: Record<string, string>) => {
209
253
  id: string;
210
254
  parentSpanId: string;
@@ -222,7 +266,11 @@ export declare const createSampleTrace: (name: string, scope?: string, attribute
222
266
  createdAt: string;
223
267
  };
224
268
 
225
- export declare const createSampleWorkflowSnapshot: (threadId: string) => WorkflowRunState_2;
269
+ export declare const createSampleWorkflowSnapshot: (threadId: string, status: string, createdAt?: Date) => {
270
+ snapshot: WorkflowRunState_2;
271
+ runId: string;
272
+ stepId: string;
273
+ };
226
274
 
227
275
  /**
228
276
  * Helper to determine if a config is using Workers bindings
@@ -243,9 +291,14 @@ export declare interface KVOperation {
243
291
  metadata?: any;
244
292
  }
245
293
 
294
+ export declare type ListOptions = {
295
+ limit?: number;
296
+ prefix?: string;
297
+ };
298
+
246
299
  export declare type RecordTypes = {
247
300
  [TABLE_THREADS]: StorageThreadType;
248
- [TABLE_MESSAGES]: MessageType;
301
+ [TABLE_MESSAGES]: MastraMessageV2;
249
302
  [TABLE_WORKFLOW_SNAPSHOT]: WorkflowRunState;
250
303
  [TABLE_EVALS]: EvalRow;
251
304
  [TABLE_TRACES]: any;
@@ -1,11 +1,13 @@
1
1
  import type { EvalRow } from '@mastra/core/storage';
2
2
  import type { KVNamespace as KVNamespace_2 } from '@cloudflare/workers-types';
3
3
  import { KVNamespaceListKey as KVNamespaceListKey_2 } from '@cloudflare/workers-types';
4
+ import type { MastraMessageV1 } from '@mastra/core/memory';
5
+ import type { MastraMessageV2 } from '@mastra/core/memory';
4
6
  import { MastraStorage } from '@mastra/core/storage';
5
- import type { MessageType } from '@mastra/core/memory';
6
- import type { MessageType as MessageType_2 } from '@mastra/core';
7
+ import type { PaginationInfo } from '@mastra/core/storage';
7
8
  import type { StorageColumn } from '@mastra/core/storage';
8
9
  import type { StorageGetMessagesArg } from '@mastra/core/storage';
10
+ import type { StorageGetTracesArg } from '@mastra/core/storage';
9
11
  import type { StorageThreadType } from '@mastra/core/memory';
10
12
  import type { TABLE_EVALS } from '@mastra/core/storage';
11
13
  import type { TABLE_MESSAGES } from '@mastra/core/storage';
@@ -13,6 +15,8 @@ import type { TABLE_NAMES } from '@mastra/core/storage';
13
15
  import type { TABLE_THREADS } from '@mastra/core/storage';
14
16
  import type { TABLE_TRACES } from '@mastra/core/storage';
15
17
  import type { TABLE_WORKFLOW_SNAPSHOT } from '@mastra/core/storage';
18
+ import type { Trace } from '@mastra/core/telemetry';
19
+ import type { WorkflowRun } from '@mastra/core/storage';
16
20
  import type { WorkflowRuns } from '@mastra/core/storage';
17
21
  import type { WorkflowRunState } from '@mastra/core/workflows';
18
22
  import type { WorkflowRunState as WorkflowRunState_2 } from '@mastra/core';
@@ -46,15 +50,26 @@ declare class CloudflareStore extends MastraStorage {
46
50
  private getNamespaceValue;
47
51
  private putNamespaceValue;
48
52
  private deleteNamespaceValue;
49
- listNamespaceKeys(tableName: TABLE_NAMES, options?: {
50
- limit?: number;
51
- prefix?: string;
52
- }): Promise<KVNamespaceListKey_2<unknown, string>[]>;
53
+ listNamespaceKeys(tableName: TABLE_NAMES, options?: ListOptions): Promise<KVNamespaceListKey_2<unknown, string>[]>;
53
54
  private createNamespaceById;
54
55
  private getNamespaceIdByName;
55
56
  private createNamespace;
56
57
  private getOrCreateNamespaceId;
57
58
  private getNamespaceId;
59
+ private LEGACY_NAMESPACE_MAP;
60
+ /**
61
+ * There were a few legacy mappings for tables such as
62
+ * - messages -> threads
63
+ * - workflow_snapshot -> mastra_workflows
64
+ * - traces -> evals
65
+ * This has been updated to use dedicated namespaces for each table.
66
+ * In the case of data for a table existing in the legacy namespace, warn the user to migrate to the new namespace.
67
+ *
68
+ * @param tableName The table name to check for legacy data
69
+ * @param prefix The namespace prefix
70
+ * @returns The legacy namespace ID if data exists; otherwise, null
71
+ */
72
+ private checkLegacyNamespace;
58
73
  /**
59
74
  * Helper to safely serialize data for KV storage
60
75
  */
@@ -93,19 +108,28 @@ declare class CloudflareStore extends MastraStorage {
93
108
  private validateColumnValue;
94
109
  private validateAgainstSchema;
95
110
  private validateRecord;
96
- private ensureDate;
97
- private serializeDate;
98
111
  private ensureMetadata;
99
112
  createTable({ tableName, schema, }: {
100
113
  tableName: TABLE_NAMES;
101
114
  schema: Record<string, StorageColumn>;
102
115
  }): Promise<void>;
116
+ /**
117
+ * No-op: This backend is schemaless and does not require schema changes.
118
+ * @param tableName Name of the table
119
+ * @param schema Schema of the table
120
+ * @param ifNotExists Array of column names to add if they don't exist
121
+ */
122
+ alterTable(_args: {
123
+ tableName: TABLE_NAMES;
124
+ schema: Record<string, StorageColumn>;
125
+ ifNotExists: string[];
126
+ }): Promise<void>;
103
127
  clearTable({ tableName }: {
104
128
  tableName: TABLE_NAMES;
105
129
  }): Promise<void>;
106
- insert<T extends TABLE_NAMES>({ tableName, record }: {
130
+ insert<T extends TABLE_NAMES>({ tableName, record, }: {
107
131
  tableName: T;
108
- record: RecordTypes[T];
132
+ record: Record<string, any>;
109
133
  }): Promise<void>;
110
134
  load<R>({ tableName, keys }: {
111
135
  tableName: TABLE_NAMES;
@@ -130,10 +154,20 @@ declare class CloudflareStore extends MastraStorage {
130
154
  }): Promise<void>;
131
155
  private getMessageKey;
132
156
  private getThreadMessagesKey;
133
- saveMessages({ messages }: {
134
- messages: MessageType[];
135
- }): Promise<MessageType[]>;
136
- getMessages<T extends MessageType = MessageType>({ threadId, selectBy }: StorageGetMessagesArg): Promise<T[]>;
157
+ saveMessages(args: {
158
+ messages: MastraMessageV1[];
159
+ format?: undefined | 'v1';
160
+ }): Promise<MastraMessageV1[]>;
161
+ saveMessages(args: {
162
+ messages: MastraMessageV2[];
163
+ format: 'v2';
164
+ }): Promise<MastraMessageV2[]>;
165
+ getMessages(args: StorageGetMessagesArg & {
166
+ format?: 'v1';
167
+ }): Promise<MastraMessageV1[]>;
168
+ getMessages(args: StorageGetMessagesArg & {
169
+ format: 'v2';
170
+ }): Promise<MastraMessageV2[]>;
137
171
  private validateWorkflowParams;
138
172
  private validateWorkflowState;
139
173
  private normalizeSteps;
@@ -153,23 +187,46 @@ declare class CloudflareStore extends MastraStorage {
153
187
  tableName: T;
154
188
  records: Partial<RecordTypes[T]>[];
155
189
  }): Promise<void>;
156
- getTraces({ name, scope, page, perPage, attributes, }: {
190
+ getTraces({ name, scope, page, perPage, attributes, fromDate, toDate, }: {
157
191
  name?: string;
158
192
  scope?: string;
159
193
  page: number;
160
194
  perPage: number;
161
195
  attributes?: Record<string, string>;
196
+ fromDate?: Date;
197
+ toDate?: Date;
162
198
  }): Promise<any[]>;
163
199
  private parseJSON;
164
200
  getEvalsByAgentName(_agentName: string, _type?: 'test' | 'live'): Promise<EvalRow[]>;
165
- getWorkflowRuns(_args?: {
201
+ private parseWorkflowRun;
202
+ private buildWorkflowSnapshotPrefix;
203
+ getWorkflowRuns({ namespace, workflowName, limit, offset, resourceId, fromDate, toDate, }?: {
166
204
  namespace?: string;
167
205
  workflowName?: string;
168
- fromDate?: Date;
169
- toDate?: Date;
170
206
  limit?: number;
171
207
  offset?: number;
208
+ resourceId?: string;
209
+ fromDate?: Date;
210
+ toDate?: Date;
172
211
  }): Promise<WorkflowRuns>;
212
+ getWorkflowRunById({ namespace, runId, workflowName, }: {
213
+ namespace: string;
214
+ runId: string;
215
+ workflowName: string;
216
+ }): Promise<WorkflowRun | null>;
217
+ getTracesPaginated(_args: StorageGetTracesArg): Promise<PaginationInfo & {
218
+ traces: Trace[];
219
+ }>;
220
+ getThreadsByResourceIdPaginated(_args: {
221
+ resourceId: string;
222
+ page?: number;
223
+ perPage?: number;
224
+ }): Promise<PaginationInfo & {
225
+ threads: StorageThreadType[];
226
+ }>;
227
+ getMessagesPaginated(_args: StorageGetMessagesArg): Promise<PaginationInfo & {
228
+ messages: MastraMessageV1[] | MastraMessageV2[];
229
+ }>;
173
230
  close(): Promise<void>;
174
231
  }
175
232
  export { CloudflareStore }
@@ -192,19 +249,6 @@ export declare interface CloudflareWorkersConfig {
192
249
  keyPrefix?: string;
193
250
  }
194
251
 
195
- export declare const createSampleMessage: (threadId: string) => MessageType_2;
196
-
197
- export declare const createSampleThread: () => {
198
- id: string;
199
- resourceId: string;
200
- title: string;
201
- createdAt: Date;
202
- updatedAt: Date;
203
- metadata: {
204
- key: string;
205
- };
206
- };
207
-
208
252
  export declare const createSampleTrace: (name: string, scope?: string, attributes?: Record<string, string>) => {
209
253
  id: string;
210
254
  parentSpanId: string;
@@ -222,7 +266,11 @@ export declare const createSampleTrace: (name: string, scope?: string, attribute
222
266
  createdAt: string;
223
267
  };
224
268
 
225
- export declare const createSampleWorkflowSnapshot: (threadId: string) => WorkflowRunState_2;
269
+ export declare const createSampleWorkflowSnapshot: (threadId: string, status: string, createdAt?: Date) => {
270
+ snapshot: WorkflowRunState_2;
271
+ runId: string;
272
+ stepId: string;
273
+ };
226
274
 
227
275
  /**
228
276
  * Helper to determine if a config is using Workers bindings
@@ -243,9 +291,14 @@ export declare interface KVOperation {
243
291
  metadata?: any;
244
292
  }
245
293
 
294
+ export declare type ListOptions = {
295
+ limit?: number;
296
+ prefix?: string;
297
+ };
298
+
246
299
  export declare type RecordTypes = {
247
300
  [TABLE_THREADS]: StorageThreadType;
248
- [TABLE_MESSAGES]: MessageType;
301
+ [TABLE_MESSAGES]: MastraMessageV2;
249
302
  [TABLE_WORKFLOW_SNAPSHOT]: WorkflowRunState;
250
303
  [TABLE_EVALS]: EvalRow;
251
304
  [TABLE_TRACES]: any;