@mastra/cloudflare 0.11.11 → 0.12.0-alpha.1

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
@@ -590,6 +590,7 @@ var MemoryStorageCloudflare = class extends MemoryStorage {
590
590
  );
591
591
  }
592
592
  async getRecentMessages(threadId, limit, messageIds) {
593
+ if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
593
594
  if (limit <= 0) return;
594
595
  try {
595
596
  const threadMessagesKey = this.getThreadMessagesKey(threadId);
@@ -649,14 +650,13 @@ var MemoryStorageCloudflare = class extends MemoryStorage {
649
650
  format
650
651
  }) {
651
652
  console.log(`getMessages called with format: ${format}, threadId: ${threadId}`);
652
- if (!threadId) throw new Error("threadId is required");
653
653
  const actualFormat = format || "v1";
654
654
  console.log(`Using format: ${actualFormat}`);
655
- if (!threadId) throw new Error("threadId is required");
656
655
  const limit = resolveMessageLimit({ last: selectBy?.last, defaultLimit: 40 });
657
656
  const messageIds = /* @__PURE__ */ new Set();
658
657
  if (limit === 0 && !selectBy?.include?.length) return [];
659
658
  try {
659
+ if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
660
660
  await Promise.all([
661
661
  selectBy?.include?.length ? this.getIncludedMessagesWithContext(threadId, selectBy.include, messageIds) : Promise.resolve(),
662
662
  limit > 0 ? this.getRecentMessages(threadId, limit, messageIds) : Promise.resolve()
@@ -717,7 +717,8 @@ var MemoryStorageCloudflare = class extends MemoryStorage {
717
717
  category: ErrorCategory.THIRD_PARTY,
718
718
  text: `Error retrieving messages for thread ${threadId}`,
719
719
  details: {
720
- threadId
720
+ threadId,
721
+ resourceId: resourceId ?? ""
721
722
  }
722
723
  },
723
724
  error
@@ -763,9 +764,10 @@ var MemoryStorageCloudflare = class extends MemoryStorage {
763
764
  }
764
765
  }
765
766
  async getMessagesPaginated(args) {
767
+ const { threadId, resourceId, selectBy, format = "v1" } = args;
768
+ const { page = 0, perPage = 100 } = selectBy?.pagination || {};
766
769
  try {
767
- const { threadId, selectBy, format = "v1" } = args;
768
- const { page = 0, perPage = 100 } = selectBy?.pagination || {};
770
+ if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
769
771
  const messages = format === "v2" ? await this.getMessages({ threadId, selectBy, format: "v2" }) : await this.getMessages({ threadId, selectBy, format: "v1" });
770
772
  let filteredMessages = messages;
771
773
  if (selectBy?.pagination?.dateRange) {
@@ -788,15 +790,22 @@ var MemoryStorageCloudflare = class extends MemoryStorage {
788
790
  messages: paginatedMessages
789
791
  };
790
792
  } catch (error) {
791
- throw new MastraError(
793
+ const mastraError = new MastraError(
792
794
  {
793
795
  id: "CLOUDFLARE_STORAGE_GET_MESSAGES_PAGINATED_FAILED",
794
796
  domain: ErrorDomain.STORAGE,
795
797
  category: ErrorCategory.THIRD_PARTY,
796
- text: "Failed to get messages with pagination"
798
+ text: "Failed to get messages with pagination",
799
+ details: {
800
+ threadId,
801
+ resourceId: resourceId ?? ""
802
+ }
797
803
  },
798
804
  error
799
805
  );
806
+ this.logger?.trackException?.(mastraError);
807
+ this.logger?.error?.(mastraError.toString());
808
+ return { messages: [], total: 0, page, perPage: perPage || 40, hasMore: false };
800
809
  }
801
810
  }
802
811
  async updateMessages(args) {