@mastra/cloudflare 1.3.1 → 1.3.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.
Files changed (33) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/{chunk-ZBYNKKG6.cjs → chunk-3SMRLX2Z.cjs} +141 -6
  3. package/dist/chunk-3SMRLX2Z.cjs.map +1 -0
  4. package/dist/{chunk-NSFHQATX.js → chunk-7THHWTAZ.js} +276 -7
  5. package/dist/chunk-7THHWTAZ.js.map +1 -0
  6. package/dist/{chunk-O57GFJSB.js → chunk-HJZCD37D.js} +142 -8
  7. package/dist/chunk-HJZCD37D.js.map +1 -0
  8. package/dist/{chunk-E4MARS3A.cjs → chunk-T2WSIEXQ.cjs} +275 -5
  9. package/dist/chunk-T2WSIEXQ.cjs.map +1 -0
  10. package/dist/do/index.cjs +11 -7
  11. package/dist/do/index.d.ts +2 -1
  12. package/dist/do/index.d.ts.map +1 -1
  13. package/dist/do/index.js +1 -1
  14. package/dist/do/storage/domains/background-tasks/index.d.ts +18 -0
  15. package/dist/do/storage/domains/background-tasks/index.d.ts.map +1 -0
  16. package/dist/docs/SKILL.md +1 -1
  17. package/dist/docs/assets/SOURCE_MAP.json +20 -20
  18. package/dist/docs/references/reference-storage-cloudflare.md +3 -3
  19. package/dist/index.cjs +13 -13
  20. package/dist/index.js +2 -2
  21. package/dist/kv/index.cjs +10 -6
  22. package/dist/kv/index.d.ts +2 -1
  23. package/dist/kv/index.d.ts.map +1 -1
  24. package/dist/kv/index.js +1 -1
  25. package/dist/kv/storage/domains/background-tasks/index.d.ts +17 -0
  26. package/dist/kv/storage/domains/background-tasks/index.d.ts.map +1 -0
  27. package/dist/kv/storage/types.d.ts +1 -0
  28. package/dist/kv/storage/types.d.ts.map +1 -1
  29. package/package.json +11 -11
  30. package/dist/chunk-E4MARS3A.cjs.map +0 -1
  31. package/dist/chunk-NSFHQATX.js.map +0 -1
  32. package/dist/chunk-O57GFJSB.js.map +0 -1
  33. package/dist/chunk-ZBYNKKG6.cjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @mastra/cloudflare
2
2
 
3
+ ## 1.3.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Add `BackgroundTasksStorage` domain implementation so `@mastra/core` background task execution works with any storage adapter. ([#15307](https://github.com/mastra-ai/mastra/pull/15307))
8
+
9
+ - Updated dependencies [[`20f59b8`](https://github.com/mastra-ai/mastra/commit/20f59b876cf91199efbc49a0e36b391240708f08), [`aba393e`](https://github.com/mastra-ai/mastra/commit/aba393e2da7390c69b80e516a4f153cda6f09376), [`3d83d06`](https://github.com/mastra-ai/mastra/commit/3d83d06f776f00fb5f4163dddd32a030c5c20844), [`e2687a7`](https://github.com/mastra-ai/mastra/commit/e2687a7408790c384563816a9a28ed06735684c9), [`fdd54cf`](https://github.com/mastra-ai/mastra/commit/fdd54cf612a9af876e9fdd85e534454f6e7dd518), [`6315317`](https://github.com/mastra-ai/mastra/commit/63153175fe9a7b224e5be7c209bbebc01dd9b0d5), [`a371ac5`](https://github.com/mastra-ai/mastra/commit/a371ac534aa1bb368a1acf9d8b313378dfdc787e), [`0474c2b`](https://github.com/mastra-ai/mastra/commit/0474c2b2e7c7e1ad8691dca031284841391ff1ef), [`0a5fa1d`](https://github.com/mastra-ai/mastra/commit/0a5fa1d3cb0583889d06687155f26fd7d2edc76c), [`7e0e63e`](https://github.com/mastra-ai/mastra/commit/7e0e63e2e485e84442351f4c7a79a424c83539dc), [`ea43e64`](https://github.com/mastra-ai/mastra/commit/ea43e646dd95d507694b6112b0bf1df22ad552b2), [`f607106`](https://github.com/mastra-ai/mastra/commit/f607106854c6416c4a07d4082604b9f66d047221), [`30456b6`](https://github.com/mastra-ai/mastra/commit/30456b6b08c8fd17e109dd093b73d93b65e83bc5), [`9d11a8c`](https://github.com/mastra-ai/mastra/commit/9d11a8c1c8924eb975a245a5884d40ca1b7e0491), [`9d3b24b`](https://github.com/mastra-ai/mastra/commit/9d3b24b19407ae9c09586cf7766d38dc4dff4a69), [`00d1b16`](https://github.com/mastra-ai/mastra/commit/00d1b16b401199cb294fa23f43336547db4dca9b), [`47cee3e`](https://github.com/mastra-ai/mastra/commit/47cee3e137fe39109cf7fffd2a8cf47b76dc702e), [`62919a6`](https://github.com/mastra-ai/mastra/commit/62919a6ee0fbf3779ad21a97b1ec6696515d5104), [`d246696`](https://github.com/mastra-ai/mastra/commit/d246696139a3144a5b21b042d41c532688e957e1), [`354f9ce`](https://github.com/mastra-ai/mastra/commit/354f9ce1ca6af2074b6a196a23f8ec30012dccca), [`16e34ca`](https://github.com/mastra-ai/mastra/commit/16e34caa98b9a114b17a6125e4e3fd87f169d0d0), [`7020c06`](https://github.com/mastra-ai/mastra/commit/7020c0690b199d9da337f0e805f16948e557922e), [`8786a61`](https://github.com/mastra-ai/mastra/commit/8786a61fa54ba265f85eeff9985ca39863d18bb6), [`9467ea8`](https://github.com/mastra-ai/mastra/commit/9467ea87695749a53dfc041576410ebf9ee7bb67), [`7338d94`](https://github.com/mastra-ai/mastra/commit/7338d949380cf68b095342e8e42610dc51d557c1), [`c80dc16`](https://github.com/mastra-ai/mastra/commit/c80dc16e113e6cc159f510ffde501ad4711b2189), [`af8a57e`](https://github.com/mastra-ai/mastra/commit/af8a57ed9ba9685ad8601d5b71ae3706da6222f9), [`d63ffdb`](https://github.com/mastra-ai/mastra/commit/d63ffdbb2c11e76fe5ea45faab44bc15460f010c), [`47cee3e`](https://github.com/mastra-ai/mastra/commit/47cee3e137fe39109cf7fffd2a8cf47b76dc702e), [`1bd5104`](https://github.com/mastra-ai/mastra/commit/1bd51048b6da93507276d6623e3fd96a9e1a8944), [`e9837b5`](https://github.com/mastra-ai/mastra/commit/e9837b53699e18711b09e0ca010a4106376f2653), [`8f1b280`](https://github.com/mastra-ai/mastra/commit/8f1b280b7fe6999ec654f160cb69c1a8719e7a57), [`92dcf02`](https://github.com/mastra-ai/mastra/commit/92dcf029294210ac91b090900c1a0555a425c57a), [`0fd90a2`](https://github.com/mastra-ai/mastra/commit/0fd90a215caf5fca8099c15a67ca03e4427747a3), [`8fb2405`](https://github.com/mastra-ai/mastra/commit/8fb2405138f2d208b7962ad03f121ca25bcc28c5), [`12df98c`](https://github.com/mastra-ai/mastra/commit/12df98c4904643d9481f5c78f3bed443725b4c96)]:
10
+ - @mastra/core@1.26.0
11
+
12
+ ## 1.3.2-alpha.0
13
+
14
+ ### Patch Changes
15
+
16
+ - Add `BackgroundTasksStorage` domain implementation so `@mastra/core` background task execution works with any storage adapter. ([#15307](https://github.com/mastra-ai/mastra/pull/15307))
17
+
18
+ - Updated dependencies [[`d63ffdb`](https://github.com/mastra-ai/mastra/commit/d63ffdbb2c11e76fe5ea45faab44bc15460f010c)]:
19
+ - @mastra/core@1.25.1-alpha.0
20
+
3
21
  ## 1.3.1
4
22
 
5
23
  ### Patch Changes
@@ -3,8 +3,8 @@
3
3
  var error = require('@mastra/core/error');
4
4
  var storage = require('@mastra/core/storage');
5
5
  var Cloudflare = require('cloudflare');
6
- var agent = require('@mastra/core/agent');
7
6
  var base = require('@mastra/core/base');
7
+ var agent = require('@mastra/core/agent');
8
8
  var evals = require('@mastra/core/evals');
9
9
 
10
10
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
@@ -564,7 +564,131 @@ var CloudflareKVDB = class extends base.MastraBase {
564
564
  }
565
565
  };
566
566
 
567
- // src/kv/storage/domains/memory/index.ts
567
+ // src/kv/storage/domains/background-tasks/index.ts
568
+ function toRecord(task) {
569
+ return {
570
+ id: task.id,
571
+ tool_call_id: task.toolCallId,
572
+ tool_name: task.toolName,
573
+ agent_id: task.agentId,
574
+ thread_id: task.threadId ?? null,
575
+ resource_id: task.resourceId ?? null,
576
+ run_id: task.runId,
577
+ status: task.status,
578
+ args: task.args,
579
+ result: task.result ?? null,
580
+ error: task.error ?? null,
581
+ retry_count: task.retryCount,
582
+ max_retries: task.maxRetries,
583
+ timeout_ms: task.timeoutMs,
584
+ createdAt: task.createdAt.toISOString(),
585
+ startedAt: task.startedAt?.toISOString() ?? null,
586
+ completedAt: task.completedAt?.toISOString() ?? null
587
+ };
588
+ }
589
+ function fromRecord(record) {
590
+ return {
591
+ id: record.id,
592
+ status: record.status,
593
+ toolName: record.tool_name,
594
+ toolCallId: record.tool_call_id,
595
+ args: record.args ?? {},
596
+ agentId: record.agent_id,
597
+ threadId: record.thread_id ?? void 0,
598
+ resourceId: record.resource_id ?? void 0,
599
+ runId: record.run_id ?? "",
600
+ result: record.result ?? void 0,
601
+ error: record.error ?? void 0,
602
+ retryCount: Number(record.retry_count ?? 0),
603
+ maxRetries: Number(record.max_retries ?? 0),
604
+ timeoutMs: Number(record.timeout_ms ?? 3e5),
605
+ createdAt: new Date(record.createdAt),
606
+ startedAt: record.startedAt ? new Date(record.startedAt) : void 0,
607
+ completedAt: record.completedAt ? new Date(record.completedAt) : void 0
608
+ };
609
+ }
610
+ var BackgroundTasksStorageCloudflare = class extends storage.BackgroundTasksStorage {
611
+ #db;
612
+ constructor(config) {
613
+ super();
614
+ this.#db = new CloudflareKVDB(resolveCloudflareConfig(config));
615
+ }
616
+ async dangerouslyClearAll() {
617
+ await this.#db.clearTable({ tableName: storage.TABLE_BACKGROUND_TASKS });
618
+ }
619
+ async createTask(task) {
620
+ await this.#db.putKV({ tableName: storage.TABLE_BACKGROUND_TASKS, key: task.id, value: toRecord(task) });
621
+ }
622
+ async updateTask(taskId, update) {
623
+ const existing = await this.getTask(taskId);
624
+ if (!existing) return;
625
+ const merged = { ...existing };
626
+ if ("status" in update) merged.status = update.status;
627
+ if ("result" in update) merged.result = update.result;
628
+ if ("error" in update) merged.error = update.error;
629
+ if ("retryCount" in update) merged.retryCount = update.retryCount;
630
+ if ("startedAt" in update) merged.startedAt = update.startedAt;
631
+ if ("completedAt" in update) merged.completedAt = update.completedAt;
632
+ await this.#db.putKV({ tableName: storage.TABLE_BACKGROUND_TASKS, key: taskId, value: toRecord(merged) });
633
+ }
634
+ async getTask(taskId) {
635
+ const data = await this.#db.getKV(storage.TABLE_BACKGROUND_TASKS, taskId);
636
+ return data ? fromRecord(data) : null;
637
+ }
638
+ async listTasks(filter) {
639
+ const keys = await this.#db.listKV(storage.TABLE_BACKGROUND_TASKS);
640
+ if (keys.length === 0) return { tasks: [], total: 0 };
641
+ const records = await Promise.all(keys.map((k) => this.#db.getKV(storage.TABLE_BACKGROUND_TASKS, k.name)));
642
+ let tasks = records.filter(Boolean).map((r) => fromRecord(r));
643
+ if (filter.status) {
644
+ const s = Array.isArray(filter.status) ? filter.status : [filter.status];
645
+ tasks = tasks.filter((t) => s.includes(t.status));
646
+ }
647
+ if (filter.agentId) tasks = tasks.filter((t) => t.agentId === filter.agentId);
648
+ if (filter.threadId) tasks = tasks.filter((t) => t.threadId === filter.threadId);
649
+ if (filter.toolName) tasks = tasks.filter((t) => t.toolName === filter.toolName);
650
+ if (filter.runId) tasks = tasks.filter((t) => t.runId === filter.runId);
651
+ const dateCol = filter.dateFilterBy ?? "createdAt";
652
+ if (filter.fromDate) {
653
+ tasks = tasks.filter((t) => {
654
+ const val = t[dateCol];
655
+ return val != null && val >= filter.fromDate;
656
+ });
657
+ }
658
+ if (filter.toDate) {
659
+ tasks = tasks.filter((t) => {
660
+ const val = t[dateCol];
661
+ return val != null && val < filter.toDate;
662
+ });
663
+ }
664
+ const orderBy = filter.orderBy ?? "createdAt";
665
+ const dir = filter.orderDirection === "desc" ? -1 : 1;
666
+ tasks.sort((a, b) => ((a[orderBy]?.getTime() ?? 0) - (b[orderBy]?.getTime() ?? 0)) * dir);
667
+ const total = tasks.length;
668
+ if (filter.page != null && filter.perPage != null) {
669
+ const start = filter.page * filter.perPage;
670
+ tasks = tasks.slice(start, start + filter.perPage);
671
+ } else if (filter.perPage != null) {
672
+ tasks = tasks.slice(0, filter.perPage);
673
+ }
674
+ return { tasks, total };
675
+ }
676
+ async deleteTask(taskId) {
677
+ await this.#db.deleteKV(storage.TABLE_BACKGROUND_TASKS, taskId);
678
+ }
679
+ async deleteTasks(filter) {
680
+ const { tasks } = await this.listTasks(filter);
681
+ await Promise.all(tasks.map((t) => this.#db.deleteKV(storage.TABLE_BACKGROUND_TASKS, t.id)));
682
+ }
683
+ async getRunningCount() {
684
+ const { total } = await this.listTasks({ status: "running" });
685
+ return total;
686
+ }
687
+ async getRunningCountByAgent(agentId) {
688
+ const { total } = await this.listTasks({ status: "running", agentId });
689
+ return total;
690
+ }
691
+ };
568
692
  var MemoryStorageCloudflare = class extends storage.MemoryStorage {
569
693
  #db;
570
694
  constructor(config) {
@@ -2192,7 +2316,13 @@ var CloudflareKVStorage = class extends storage.MastraCompositeStore {
2192
2316
  if (!config.bindings) {
2193
2317
  throw new Error("KV bindings are required when using Workers Binding API");
2194
2318
  }
2195
- const requiredTables = [storage.TABLE_THREADS, storage.TABLE_MESSAGES, storage.TABLE_WORKFLOW_SNAPSHOT, storage.TABLE_SCORERS];
2319
+ const requiredTables = [
2320
+ storage.TABLE_THREADS,
2321
+ storage.TABLE_MESSAGES,
2322
+ storage.TABLE_WORKFLOW_SNAPSHOT,
2323
+ storage.TABLE_SCORERS,
2324
+ storage.TABLE_BACKGROUND_TASKS
2325
+ ];
2196
2326
  for (const table of requiredTables) {
2197
2327
  if (!(table in config.bindings)) {
2198
2328
  throw new Error(`Missing KV binding for table: ${table}`);
@@ -2216,6 +2346,7 @@ var CloudflareKVStorage = class extends storage.MastraCompositeStore {
2216
2346
  let workflows;
2217
2347
  let memory;
2218
2348
  let scores;
2349
+ let backgroundTasks;
2219
2350
  if (isWorkersConfig(config)) {
2220
2351
  this.validateWorkersConfig(config);
2221
2352
  this.bindings = config.bindings;
@@ -2228,6 +2359,7 @@ var CloudflareKVStorage = class extends storage.MastraCompositeStore {
2228
2359
  workflows = new WorkflowsStorageCloudflare(domainConfig);
2229
2360
  memory = new MemoryStorageCloudflare(domainConfig);
2230
2361
  scores = new ScoresStorageCloudflare(domainConfig);
2362
+ backgroundTasks = new BackgroundTasksStorageCloudflare(domainConfig);
2231
2363
  } else {
2232
2364
  this.validateRestConfig(config);
2233
2365
  this.accountId = config.accountId.trim();
@@ -2244,11 +2376,13 @@ var CloudflareKVStorage = class extends storage.MastraCompositeStore {
2244
2376
  workflows = new WorkflowsStorageCloudflare(domainConfig);
2245
2377
  memory = new MemoryStorageCloudflare(domainConfig);
2246
2378
  scores = new ScoresStorageCloudflare(domainConfig);
2379
+ backgroundTasks = new BackgroundTasksStorageCloudflare(domainConfig);
2247
2380
  }
2248
2381
  this.stores = {
2249
2382
  workflows,
2250
2383
  memory,
2251
- scores
2384
+ scores,
2385
+ backgroundTasks
2252
2386
  };
2253
2387
  } catch (error$1) {
2254
2388
  throw new error.MastraError(
@@ -2266,10 +2400,11 @@ var CloudflareKVStorage = class extends storage.MastraCompositeStore {
2266
2400
  };
2267
2401
  var CloudflareStore = CloudflareKVStorage;
2268
2402
 
2403
+ exports.BackgroundTasksStorageCloudflare = BackgroundTasksStorageCloudflare;
2269
2404
  exports.CloudflareKVStorage = CloudflareKVStorage;
2270
2405
  exports.CloudflareStore = CloudflareStore;
2271
2406
  exports.MemoryStorageCloudflare = MemoryStorageCloudflare;
2272
2407
  exports.ScoresStorageCloudflare = ScoresStorageCloudflare;
2273
2408
  exports.WorkflowsStorageCloudflare = WorkflowsStorageCloudflare;
2274
- //# sourceMappingURL=chunk-ZBYNKKG6.cjs.map
2275
- //# sourceMappingURL=chunk-ZBYNKKG6.cjs.map
2409
+ //# sourceMappingURL=chunk-3SMRLX2Z.cjs.map
2410
+ //# sourceMappingURL=chunk-3SMRLX2Z.cjs.map