@mastra/cloudflare 0.11.4 → 0.11.5

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,583 +0,0 @@
1
- import type { default as Cloudflare_2 } from 'cloudflare';
2
- import type { EvalRow } from '@mastra/core/storage';
3
- import type { KVNamespace as KVNamespace_2 } from '@cloudflare/workers-types';
4
- import { KVNamespaceListKey as KVNamespaceListKey_2 } from '@cloudflare/workers-types';
5
- import { LegacyEvalsStorage } from '@mastra/core/storage';
6
- import type { MastraMessageContentV2 } from '@mastra/core/agent';
7
- import type { MastraMessageV1 } from '@mastra/core/memory';
8
- import type { MastraMessageV1 as MastraMessageV1_2 } from '@mastra/core';
9
- import type { MastraMessageV2 } from '@mastra/core/memory';
10
- import type { MastraMessageV2 as MastraMessageV2_2 } from '@mastra/core';
11
- import { MastraStorage } from '@mastra/core/storage';
12
- import { MemoryStorage } from '@mastra/core/storage';
13
- import type { PaginationArgs } from '@mastra/core/storage';
14
- import type { PaginationInfo } from '@mastra/core/storage';
15
- import type { PaginationInfo as PaginationInfo_2 } from '@mastra/core';
16
- import type { ScoreRowData } from '@mastra/core/scores';
17
- import { ScoresStorage } from '@mastra/core/storage';
18
- import type { StorageColumn } from '@mastra/core/storage';
19
- import type { StorageDomains } from '@mastra/core/storage';
20
- import type { StorageGetMessagesArg } from '@mastra/core/storage';
21
- import type { StorageGetMessagesArg as StorageGetMessagesArg_2 } from '@mastra/core';
22
- import type { StorageGetTracesArg } from '@mastra/core/storage';
23
- import type { StorageGetTracesPaginatedArg } from '@mastra/core/storage';
24
- import type { StoragePagination } from '@mastra/core/storage';
25
- import type { StorageResourceType } from '@mastra/core/storage';
26
- import type { StorageResourceType as StorageResourceType_2 } from '@mastra/core';
27
- import type { StorageThreadType } from '@mastra/core/memory';
28
- import type { StorageThreadType as StorageThreadType_2 } from '@mastra/core';
29
- import { StoreOperations } from '@mastra/core/storage';
30
- import type { TABLE_EVALS } from '@mastra/core/storage';
31
- import type { TABLE_MESSAGES } from '@mastra/core/storage';
32
- import type { TABLE_NAMES } from '@mastra/core/storage';
33
- import type { TABLE_RESOURCES } from '@mastra/core/storage';
34
- import type { TABLE_SCORERS } from '@mastra/core/storage';
35
- import type { TABLE_THREADS } from '@mastra/core/storage';
36
- import type { TABLE_TRACES } from '@mastra/core/storage';
37
- import type { TABLE_WORKFLOW_SNAPSHOT } from '@mastra/core/storage';
38
- import type { Trace } from '@mastra/core/telemetry';
39
- import { TracesStorage } from '@mastra/core/storage';
40
- import type { WorkflowRun } from '@mastra/core/storage';
41
- import type { WorkflowRuns } from '@mastra/core/storage';
42
- import type { WorkflowRunState } from '@mastra/core/workflows';
43
- import type { WorkflowRunState as WorkflowRunState_2 } from '@mastra/core';
44
- import { WorkflowsStorage } from '@mastra/core/storage';
45
-
46
- /**
47
- * Configuration for Cloudflare KV using REST API
48
- */
49
- export declare interface CloudflareRestConfig {
50
- /** Cloudflare account ID */
51
- accountId: string;
52
- /** Cloudflare API token with KV access */
53
- apiToken: string;
54
- /**
55
- * Prefix for KV namespace names.
56
- * Recommended for production use to ensure data isolation between different instances.
57
- * If not provided, no prefix will be used
58
- */
59
- namespacePrefix?: string;
60
- }
61
-
62
- declare class CloudflareStore extends MastraStorage {
63
- stores: StorageDomains;
64
- private client?;
65
- private accountId?;
66
- private namespacePrefix;
67
- private bindings?;
68
- private validateWorkersConfig;
69
- private validateRestConfig;
70
- constructor(config: CloudflareStoreConfig);
71
- createTable({ tableName, schema, }: {
72
- tableName: TABLE_NAMES;
73
- schema: Record<string, StorageColumn>;
74
- }): Promise<void>;
75
- alterTable(_args: {
76
- tableName: TABLE_NAMES;
77
- schema: Record<string, StorageColumn>;
78
- ifNotExists: string[];
79
- }): Promise<void>;
80
- clearTable({ tableName }: {
81
- tableName: TABLE_NAMES;
82
- }): Promise<void>;
83
- dropTable({ tableName }: {
84
- tableName: TABLE_NAMES;
85
- }): Promise<void>;
86
- insert<T extends TABLE_NAMES>({ tableName, record, }: {
87
- tableName: T;
88
- record: Record<string, any>;
89
- }): Promise<void>;
90
- load<R>({ tableName, keys }: {
91
- tableName: TABLE_NAMES;
92
- keys: Record<string, string>;
93
- }): Promise<R | null>;
94
- getThreadById({ threadId }: {
95
- threadId: string;
96
- }): Promise<StorageThreadType | null>;
97
- getThreadsByResourceId({ resourceId }: {
98
- resourceId: string;
99
- }): Promise<StorageThreadType[]>;
100
- saveThread({ thread }: {
101
- thread: StorageThreadType;
102
- }): Promise<StorageThreadType>;
103
- updateThread({ id, title, metadata, }: {
104
- id: string;
105
- title: string;
106
- metadata: Record<string, unknown>;
107
- }): Promise<StorageThreadType>;
108
- deleteThread({ threadId }: {
109
- threadId: string;
110
- }): Promise<void>;
111
- saveMessages(args: {
112
- messages: MastraMessageV1[];
113
- format?: undefined | 'v1';
114
- }): Promise<MastraMessageV1[]>;
115
- saveMessages(args: {
116
- messages: MastraMessageV2[];
117
- format: 'v2';
118
- }): Promise<MastraMessageV2[]>;
119
- getMessages(args: StorageGetMessagesArg & {
120
- format?: 'v1';
121
- }): Promise<MastraMessageV1[]>;
122
- getMessages(args: StorageGetMessagesArg & {
123
- format: 'v2';
124
- }): Promise<MastraMessageV2[]>;
125
- persistWorkflowSnapshot(params: {
126
- workflowName: string;
127
- runId: string;
128
- snapshot: WorkflowRunState;
129
- }): Promise<void>;
130
- loadWorkflowSnapshot(params: {
131
- workflowName: string;
132
- runId: string;
133
- }): Promise<WorkflowRunState | null>;
134
- batchInsert<T extends TABLE_NAMES>(input: {
135
- tableName: T;
136
- records: Partial<RecordTypes[T]>[];
137
- }): Promise<void>;
138
- getTraces({ name, scope, page, perPage, attributes, fromDate, toDate, }: {
139
- name?: string;
140
- scope?: string;
141
- page: number;
142
- perPage: number;
143
- attributes?: Record<string, string>;
144
- fromDate?: Date;
145
- toDate?: Date;
146
- }): Promise<any[]>;
147
- getEvalsByAgentName(agentName: string, type?: 'test' | 'live'): Promise<EvalRow[]>;
148
- getEvals(options: {
149
- agentName?: string;
150
- type?: 'test' | 'live';
151
- dateRange?: {
152
- start?: Date;
153
- end?: Date;
154
- };
155
- } & PaginationArgs): Promise<PaginationInfo & {
156
- evals: EvalRow[];
157
- }>;
158
- getWorkflowRuns({ workflowName, limit, offset, resourceId, fromDate, toDate, }?: {
159
- workflowName?: string;
160
- limit?: number;
161
- offset?: number;
162
- resourceId?: string;
163
- fromDate?: Date;
164
- toDate?: Date;
165
- }): Promise<WorkflowRuns>;
166
- getWorkflowRunById({ runId, workflowName, }: {
167
- runId: string;
168
- workflowName: string;
169
- }): Promise<WorkflowRun | null>;
170
- getTracesPaginated(args: StorageGetTracesPaginatedArg): Promise<PaginationInfo & {
171
- traces: Trace[];
172
- }>;
173
- getThreadsByResourceIdPaginated(args: {
174
- resourceId: string;
175
- page: number;
176
- perPage: number;
177
- }): Promise<PaginationInfo & {
178
- threads: StorageThreadType[];
179
- }>;
180
- getMessagesPaginated(args: StorageGetMessagesArg): Promise<PaginationInfo & {
181
- messages: MastraMessageV1[] | MastraMessageV2[];
182
- }>;
183
- updateMessages(args: {
184
- messages: Partial<Omit<MastraMessageV2, 'createdAt'>> & {
185
- id: string;
186
- content?: {
187
- metadata?: MastraMessageContentV2['metadata'];
188
- content?: MastraMessageContentV2['content'];
189
- };
190
- }[];
191
- }): Promise<MastraMessageV2[]>;
192
- getScoreById({ id }: {
193
- id: string;
194
- }): Promise<ScoreRowData | null>;
195
- saveScore(score: ScoreRowData): Promise<{
196
- score: ScoreRowData;
197
- }>;
198
- getScoresByRunId({ runId, pagination, }: {
199
- runId: string;
200
- pagination: StoragePagination;
201
- }): Promise<{
202
- pagination: PaginationInfo;
203
- scores: ScoreRowData[];
204
- }>;
205
- getScoresByEntityId({ entityId, entityType, pagination, }: {
206
- pagination: StoragePagination;
207
- entityId: string;
208
- entityType: string;
209
- }): Promise<{
210
- pagination: PaginationInfo;
211
- scores: ScoreRowData[];
212
- }>;
213
- getScoresByScorerId({ scorerId, pagination, }: {
214
- scorerId: string;
215
- pagination: StoragePagination;
216
- }): Promise<{
217
- pagination: PaginationInfo;
218
- scores: ScoreRowData[];
219
- }>;
220
- getResourceById({ resourceId }: {
221
- resourceId: string;
222
- }): Promise<StorageResourceType | null>;
223
- saveResource({ resource }: {
224
- resource: StorageResourceType;
225
- }): Promise<StorageResourceType>;
226
- updateResource({ resourceId, workingMemory, metadata, }: {
227
- resourceId: string;
228
- workingMemory?: string;
229
- metadata?: Record<string, unknown>;
230
- }): Promise<StorageResourceType>;
231
- close(): Promise<void>;
232
- }
233
- export { CloudflareStore }
234
- export { CloudflareStore as CloudflareStore_alias_1 }
235
-
236
- /**
237
- * Combined configuration type supporting both REST API and Workers Binding API
238
- */
239
- export declare type CloudflareStoreConfig = CloudflareRestConfig | CloudflareWorkersConfig;
240
-
241
- /**
242
- * Configuration for Cloudflare KV using Workers Binding API
243
- */
244
- export declare interface CloudflareWorkersConfig {
245
- /** KV namespace bindings from Workers environment */
246
- bindings: {
247
- [key in TABLE_NAMES]: KVNamespace_2;
248
- };
249
- /** Optional prefix for keys within namespaces */
250
- keyPrefix?: string;
251
- }
252
-
253
- export declare const createSampleTrace: (name: string, scope?: string, attributes?: Record<string, string>) => {
254
- id: string;
255
- parentSpanId: string;
256
- traceId: string;
257
- name: string;
258
- scope: string | undefined;
259
- kind: string;
260
- status: string;
261
- events: string;
262
- links: string;
263
- attributes: string | undefined;
264
- startTime: string;
265
- endTime: string;
266
- other: string;
267
- createdAt: string;
268
- };
269
-
270
- export declare const createSampleWorkflowSnapshot: (threadId: string, status: string, createdAt?: Date) => {
271
- snapshot: WorkflowRunState_2;
272
- runId: string;
273
- stepId: string;
274
- };
275
-
276
- /**
277
- * Helper to determine if a config is using Workers bindings
278
- */
279
- export declare function isWorkersConfig(config: CloudflareStoreConfig): config is CloudflareWorkersConfig;
280
-
281
- /**
282
- * Interface for KV operations with type support
283
- */
284
- export declare interface KVOperation {
285
- /** Table/namespace to operate on */
286
- tableName: TABLE_NAMES;
287
- /** Key to read/write */
288
- key: string;
289
- /** Value to write (for put operations) */
290
- value?: any;
291
- /** Optional metadata to associate with the value */
292
- metadata?: any;
293
- }
294
-
295
- export declare class LegacyEvalsStorageCloudflare extends LegacyEvalsStorage {
296
- operations: StoreOperationsCloudflare;
297
- constructor({ operations }: {
298
- operations: StoreOperationsCloudflare;
299
- });
300
- getEvalsByAgentName(agentName: string, type?: 'test' | 'live'): Promise<EvalRow[]>;
301
- getEvals(options: {
302
- agentName?: string;
303
- type?: 'test' | 'live';
304
- dateRange?: {
305
- start?: Date;
306
- end?: Date;
307
- };
308
- } & PaginationArgs): Promise<PaginationInfo & {
309
- evals: EvalRow[];
310
- }>;
311
- }
312
-
313
- export declare type ListOptions = {
314
- limit?: number;
315
- prefix?: string;
316
- };
317
-
318
- export declare class MemoryStorageCloudflare extends MemoryStorage {
319
- operations: StoreOperationsCloudflare;
320
- constructor({ operations }: {
321
- operations: StoreOperationsCloudflare;
322
- });
323
- private ensureMetadata;
324
- getThreadById({ threadId }: {
325
- threadId: string;
326
- }): Promise<StorageThreadType_2 | null>;
327
- getThreadsByResourceId({ resourceId }: {
328
- resourceId: string;
329
- }): Promise<StorageThreadType_2[]>;
330
- getThreadsByResourceIdPaginated(args: {
331
- resourceId: string;
332
- page?: number;
333
- perPage?: number;
334
- }): Promise<PaginationInfo_2 & {
335
- threads: StorageThreadType_2[];
336
- }>;
337
- saveThread({ thread }: {
338
- thread: StorageThreadType_2;
339
- }): Promise<StorageThreadType_2>;
340
- updateThread({ id, title, metadata, }: {
341
- id: string;
342
- title: string;
343
- metadata: Record<string, unknown>;
344
- }): Promise<StorageThreadType_2>;
345
- private getMessageKey;
346
- private getThreadMessagesKey;
347
- deleteThread({ threadId }: {
348
- threadId: string;
349
- }): Promise<void>;
350
- private findMessageInAnyThread;
351
- /**
352
- * Queue for serializing sorted order updates.
353
- * Updates the sorted order for a given key. This operation is eventually consistent.
354
- */
355
- private updateQueue;
356
- private updateSorting;
357
- /**
358
- * Updates the sorted order for a given key. This operation is eventually consistent.
359
- * Note: Operations on the same orderKey are serialized using a queue to prevent
360
- * concurrent updates from conflicting with each other.
361
- */
362
- private updateSortedMessages;
363
- private getSortedMessages;
364
- private migrateMessage;
365
- saveMessages(args: {
366
- messages: MastraMessageV1_2[];
367
- format?: undefined | 'v1';
368
- }): Promise<MastraMessageV1_2[]>;
369
- saveMessages(args: {
370
- messages: MastraMessageV2_2[];
371
- format: 'v2';
372
- }): Promise<MastraMessageV2_2[]>;
373
- private getRank;
374
- private getRange;
375
- private getLastN;
376
- private getFullOrder;
377
- private getIncludedMessagesWithContext;
378
- private getRecentMessages;
379
- private fetchAndParseMessagesFromMultipleThreads;
380
- getMessages(args: StorageGetMessagesArg_2 & {
381
- format?: 'v1';
382
- }): Promise<MastraMessageV1_2[]>;
383
- getMessages(args: StorageGetMessagesArg_2 & {
384
- format: 'v2';
385
- }): Promise<MastraMessageV2_2[]>;
386
- getMessagesPaginated(args: StorageGetMessagesArg_2): Promise<PaginationInfo_2 & {
387
- messages: MastraMessageV1_2[] | MastraMessageV2_2[];
388
- }>;
389
- updateMessages(args: {
390
- messages: (Partial<Omit<MastraMessageV2_2, 'createdAt'>> & {
391
- id: string;
392
- threadId?: string;
393
- content?: {
394
- metadata?: MastraMessageContentV2['metadata'];
395
- content?: MastraMessageContentV2['content'];
396
- };
397
- })[];
398
- }): Promise<MastraMessageV2_2[]>;
399
- getResourceById({ resourceId }: {
400
- resourceId: string;
401
- }): Promise<StorageResourceType_2 | null>;
402
- saveResource({ resource }: {
403
- resource: StorageResourceType_2;
404
- }): Promise<StorageResourceType_2>;
405
- updateResource({ resourceId, workingMemory, metadata, }: {
406
- resourceId: string;
407
- workingMemory?: string;
408
- metadata?: Record<string, unknown>;
409
- }): Promise<StorageResourceType_2>;
410
- }
411
-
412
- export declare type RecordTypes = {
413
- [TABLE_THREADS]: StorageThreadType;
414
- [TABLE_MESSAGES]: MastraMessageV2;
415
- [TABLE_WORKFLOW_SNAPSHOT]: WorkflowRunState;
416
- [TABLE_EVALS]: EvalRow;
417
- [TABLE_SCORERS]: ScoreRowData;
418
- [TABLE_TRACES]: any;
419
- [TABLE_RESOURCES]: StorageResourceType;
420
- };
421
-
422
- export declare const retryUntil: <T>(fn: () => Promise<T>, condition: (result: T) => boolean, timeout?: number, // REST API needs longer timeout due to higher latency
423
- interval?: number) => Promise<T>;
424
-
425
- export declare class ScoresStorageCloudflare extends ScoresStorage {
426
- private operations;
427
- constructor({ operations }: {
428
- operations: StoreOperationsCloudflare;
429
- });
430
- getScoreById({ id }: {
431
- id: string;
432
- }): Promise<ScoreRowData | null>;
433
- saveScore(score: Omit<ScoreRowData, 'createdAt' | 'updatedAt'>): Promise<{
434
- score: ScoreRowData;
435
- }>;
436
- getScoresByScorerId({ scorerId, pagination, }: {
437
- scorerId: string;
438
- pagination: StoragePagination;
439
- }): Promise<{
440
- pagination: PaginationInfo;
441
- scores: ScoreRowData[];
442
- }>;
443
- getScoresByRunId({ runId, pagination, }: {
444
- runId: string;
445
- pagination: StoragePagination;
446
- }): Promise<{
447
- pagination: PaginationInfo;
448
- scores: ScoreRowData[];
449
- }>;
450
- getScoresByEntityId({ entityId, entityType, pagination, }: {
451
- pagination: StoragePagination;
452
- entityId: string;
453
- entityType: string;
454
- }): Promise<{
455
- pagination: PaginationInfo;
456
- scores: ScoreRowData[];
457
- }>;
458
- }
459
-
460
- export declare class StoreOperationsCloudflare extends StoreOperations {
461
- private bindings?;
462
- client?: Cloudflare_2;
463
- accountId?: string;
464
- namespacePrefix: string;
465
- constructor({ namespacePrefix, bindings, client, accountId, }: {
466
- bindings?: Record<TABLE_NAMES, KVNamespace_2>;
467
- namespacePrefix: string;
468
- client?: Cloudflare_2;
469
- accountId?: string;
470
- });
471
- hasColumn(): Promise<boolean>;
472
- alterTable(_args: {
473
- tableName: TABLE_NAMES;
474
- schema: Record<string, StorageColumn>;
475
- ifNotExists: string[];
476
- }): Promise<void>;
477
- clearTable({ tableName }: {
478
- tableName: TABLE_NAMES;
479
- }): Promise<void>;
480
- dropTable({ tableName }: {
481
- tableName: TABLE_NAMES;
482
- }): Promise<void>;
483
- private getBinding;
484
- getKey<T extends TABLE_NAMES>(tableName: T, record: Record<string, string>): string;
485
- private getSchemaKey;
486
- /**
487
- * Helper to safely parse data from KV storage
488
- */
489
- private safeParse;
490
- private createNamespaceById;
491
- private createNamespace;
492
- private listNamespaces;
493
- private getNamespaceIdByName;
494
- private getOrCreateNamespaceId;
495
- private getNamespaceId;
496
- private getNamespaceValue;
497
- getKV(tableName: TABLE_NAMES, key: string): Promise<any>;
498
- private getTableSchema;
499
- private validateColumnValue;
500
- private validateAgainstSchema;
501
- private validateRecord;
502
- insert({ tableName, record }: {
503
- tableName: TABLE_NAMES;
504
- record: Record<string, any>;
505
- }): Promise<void>;
506
- private ensureMetadata;
507
- load<R>({ tableName, keys }: {
508
- tableName: TABLE_NAMES;
509
- keys: Record<string, string>;
510
- }): Promise<R | null>;
511
- batchInsert<T extends TABLE_NAMES>(input: {
512
- tableName: T;
513
- records: Partial<RecordTypes[T]>[];
514
- }): Promise<void>;
515
- /**
516
- * Helper to safely serialize data for KV storage
517
- */
518
- private safeSerialize;
519
- private putNamespaceValue;
520
- putKV({ tableName, key, value, metadata, }: {
521
- tableName: TABLE_NAMES;
522
- key: string;
523
- value: any;
524
- metadata?: any;
525
- }): Promise<void>;
526
- createTable({ tableName, schema, }: {
527
- tableName: TABLE_NAMES;
528
- schema: Record<string, StorageColumn>;
529
- }): Promise<void>;
530
- listNamespaceKeys(tableName: TABLE_NAMES, options?: ListOptions): Promise<KVNamespaceListKey_2<unknown, string>[]>;
531
- private deleteNamespaceValue;
532
- deleteKV(tableName: TABLE_NAMES, key: string): Promise<void>;
533
- listKV(tableName: TABLE_NAMES, options?: ListOptions): Promise<Array<{
534
- name: string;
535
- }>>;
536
- }
537
-
538
- export declare class TracesStorageCloudflare extends TracesStorage {
539
- private operations;
540
- constructor({ operations }: {
541
- operations: StoreOperationsCloudflare;
542
- });
543
- getTraces(args: StorageGetTracesArg): Promise<Trace[]>;
544
- getTracesPaginated(args: StorageGetTracesPaginatedArg): Promise<PaginationInfo & {
545
- traces: Trace[];
546
- }>;
547
- batchTraceInsert({ records }: {
548
- records: Record<string, any>[];
549
- }): Promise<void>;
550
- }
551
-
552
- export declare class WorkflowsStorageCloudflare extends WorkflowsStorage {
553
- private operations;
554
- constructor({ operations }: {
555
- operations: StoreOperationsCloudflare;
556
- });
557
- private validateWorkflowParams;
558
- persistWorkflowSnapshot(params: {
559
- workflowName: string;
560
- runId: string;
561
- snapshot: WorkflowRunState;
562
- }): Promise<void>;
563
- loadWorkflowSnapshot(params: {
564
- workflowName: string;
565
- runId: string;
566
- }): Promise<WorkflowRunState | null>;
567
- private parseWorkflowRun;
568
- private buildWorkflowSnapshotPrefix;
569
- getWorkflowRuns({ workflowName, limit, offset, resourceId, fromDate, toDate, }?: {
570
- workflowName?: string;
571
- limit?: number;
572
- offset?: number;
573
- resourceId?: string;
574
- fromDate?: Date;
575
- toDate?: Date;
576
- }): Promise<WorkflowRuns>;
577
- getWorkflowRunById({ runId, workflowName, }: {
578
- runId: string;
579
- workflowName: string;
580
- }): Promise<WorkflowRun | null>;
581
- }
582
-
583
- export { }