@mastra/cloudflare 1.0.0-beta.11 → 1.0.0-beta.13

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/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
2
- import { MemoryStorage, TABLE_MESSAGES, TABLE_THREADS, TABLE_RESOURCES, ensureDate, createStorageErrorId, normalizePerPage, calculatePagination, serializeDate, filterByDateRange, ScoresStorage, TABLE_SCORERS, WorkflowsStorage, TABLE_WORKFLOW_SNAPSHOT, MastraStorage, TABLE_TRACES, transformScoreRow as transformScoreRow$1 } from '@mastra/core/storage';
2
+ import { MemoryStorage, TABLE_MESSAGES, TABLE_THREADS, TABLE_RESOURCES, ensureDate, createStorageErrorId, normalizePerPage, calculatePagination, serializeDate, filterByDateRange, ScoresStorage, TABLE_SCORERS, WorkflowsStorage, TABLE_WORKFLOW_SNAPSHOT, MastraCompositeStore, TABLE_TRACES, transformScoreRow as transformScoreRow$1 } from '@mastra/core/storage';
3
3
  import Cloudflare from 'cloudflare';
4
4
  import { MessageList } from '@mastra/core/agent';
5
5
  import { MastraBase } from '@mastra/core/base';
@@ -614,21 +614,23 @@ var MemoryStorageCloudflare = class extends MemoryStorage {
614
614
  return null;
615
615
  }
616
616
  }
617
- async listThreadsByResourceId(args) {
617
+ async listThreads(args) {
618
+ const { page = 0, perPage: perPageInput, orderBy, filter } = args;
619
+ try {
620
+ this.validatePaginationInput(page, perPageInput ?? 100);
621
+ } catch (error) {
622
+ throw new MastraError(
623
+ {
624
+ id: createStorageErrorId("CLOUDFLARE", "LIST_THREADS", "INVALID_PAGE"),
625
+ domain: ErrorDomain.STORAGE,
626
+ category: ErrorCategory.USER,
627
+ details: { page, ...perPageInput !== void 0 && { perPage: perPageInput } }
628
+ },
629
+ error instanceof Error ? error : new Error("Invalid pagination parameters")
630
+ );
631
+ }
632
+ const perPage = normalizePerPage(perPageInput, 100);
618
633
  try {
619
- const { resourceId, page = 0, perPage: perPageInput, orderBy } = args;
620
- const perPage = normalizePerPage(perPageInput, 100);
621
- if (page < 0) {
622
- throw new MastraError(
623
- {
624
- id: createStorageErrorId("CLOUDFLARE", "LIST_THREADS_BY_RESOURCE_ID", "INVALID_PAGE"),
625
- domain: ErrorDomain.STORAGE,
626
- category: ErrorCategory.USER,
627
- details: { page }
628
- },
629
- new Error("page must be >= 0")
630
- );
631
- }
632
634
  const { offset, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
633
635
  const { field, direction } = this.parseOrderBy(orderBy);
634
636
  const prefix = this.#db.namespacePrefix ? `${this.#db.namespacePrefix}:` : "";
@@ -637,7 +639,15 @@ var MemoryStorageCloudflare = class extends MemoryStorage {
637
639
  for (const { name: key } of keyObjs) {
638
640
  const data = await this.#db.getKV(TABLE_THREADS, key);
639
641
  if (!data) continue;
640
- if (data.resourceId !== resourceId) continue;
642
+ if (filter?.resourceId && data.resourceId !== filter.resourceId) {
643
+ continue;
644
+ }
645
+ if (filter?.metadata && Object.keys(filter.metadata).length > 0) {
646
+ const metadata = this.ensureMetadata(data.metadata);
647
+ if (!metadata) continue;
648
+ const matches = Object.entries(filter.metadata).every(([key2, value]) => metadata[key2] === value);
649
+ if (!matches) continue;
650
+ }
641
651
  threads.push(data);
642
652
  }
643
653
  threads.sort((a, b) => {
@@ -657,10 +667,10 @@ var MemoryStorageCloudflare = class extends MemoryStorage {
657
667
  } catch (error) {
658
668
  throw new MastraError(
659
669
  {
660
- id: createStorageErrorId("CLOUDFLARE", "LIST_THREADS_BY_RESOURCE_ID", "FAILED"),
670
+ id: createStorageErrorId("CLOUDFLARE", "LIST_THREADS", "FAILED"),
661
671
  domain: ErrorDomain.STORAGE,
662
672
  category: ErrorCategory.THIRD_PARTY,
663
- text: "Failed to get threads by resource ID with pagination"
673
+ text: "Failed to list threads with filters"
664
674
  },
665
675
  error
666
676
  );
@@ -2153,7 +2163,7 @@ function isWorkersConfig(config) {
2153
2163
  }
2154
2164
 
2155
2165
  // src/storage/index.ts
2156
- var CloudflareStore = class extends MastraStorage {
2166
+ var CloudflareStore = class extends MastraCompositeStore {
2157
2167
  stores;
2158
2168
  client;
2159
2169
  accountId;