@mastra/upstash 0.14.1 → 0.14.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.
@@ -1,4 +1,4 @@
1
1
 
2
- > @mastra/upstash@0.14.1-alpha.0 build /home/runner/work/mastra/mastra/stores/upstash
2
+ > @mastra/upstash@0.14.2-alpha.0 build /home/runner/work/mastra/mastra/stores/upstash
3
3
  > tsup --silent --config tsup.config.ts
4
4
 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @mastra/upstash
2
2
 
3
+ ## 0.14.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#6700](https://github.com/mastra-ai/mastra/pull/6700) [`a5a23d9`](https://github.com/mastra-ai/mastra/commit/a5a23d981920d458dc6078919992a5338931ef02) Thanks [@gpanakkal](https://github.com/gpanakkal)! - Add `getMessagesById` method to `MastraStorage` adapters
8
+
9
+ - Updated dependencies [[`6e7e120`](https://github.com/mastra-ai/mastra/commit/6e7e1207d6e8d8b838f9024f90bd10df1181ba27), [`0f00e17`](https://github.com/mastra-ai/mastra/commit/0f00e172953ccdccadb35ed3d70f5e4d89115869), [`217cd7a`](https://github.com/mastra-ai/mastra/commit/217cd7a4ce171e9a575c41bb8c83300f4db03236), [`a5a23d9`](https://github.com/mastra-ai/mastra/commit/a5a23d981920d458dc6078919992a5338931ef02)]:
10
+ - @mastra/core@0.14.1
11
+
12
+ ## 0.14.2-alpha.0
13
+
14
+ ### Patch Changes
15
+
16
+ - [#6700](https://github.com/mastra-ai/mastra/pull/6700) [`a5a23d9`](https://github.com/mastra-ai/mastra/commit/a5a23d981920d458dc6078919992a5338931ef02) Thanks [@gpanakkal](https://github.com/gpanakkal)! - Add `getMessagesById` method to `MastraStorage` adapters
17
+
18
+ - Updated dependencies [[`6e7e120`](https://github.com/mastra-ai/mastra/commit/6e7e1207d6e8d8b838f9024f90bd10df1181ba27), [`a5a23d9`](https://github.com/mastra-ai/mastra/commit/a5a23d981920d458dc6078919992a5338931ef02)]:
19
+ - @mastra/core@0.14.1-alpha.0
20
+
3
21
  ## 0.14.1
4
22
 
5
23
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -624,6 +624,15 @@ var StoreMemoryUpstash = class extends storage.MemoryStorage {
624
624
  }
625
625
  return [];
626
626
  }
627
+ parseStoredMessage(storedMessage) {
628
+ const defaultMessageContent = { format: 2, parts: [{ type: "text", text: "" }] };
629
+ const { _index, ...rest } = storedMessage;
630
+ return {
631
+ ...rest,
632
+ createdAt: new Date(rest.createdAt),
633
+ content: rest.content || defaultMessageContent
634
+ };
635
+ }
627
636
  async getMessages({
628
637
  threadId,
629
638
  selectBy,
@@ -699,6 +708,40 @@ var StoreMemoryUpstash = class extends storage.MemoryStorage {
699
708
  );
700
709
  }
701
710
  }
711
+ async getMessagesById({
712
+ messageIds,
713
+ format
714
+ }) {
715
+ if (messageIds.length === 0) return [];
716
+ try {
717
+ const threadKeys = await this.client.keys("thread:*");
718
+ const result = await Promise.all(
719
+ threadKeys.map((threadKey) => {
720
+ const threadId = threadKey.split(":")[1];
721
+ if (!threadId) throw new Error(`Failed to parse thread ID from thread key "${threadKey}"`);
722
+ return this.client.mget(
723
+ messageIds.map((id) => getMessageKey(threadId, id))
724
+ );
725
+ })
726
+ );
727
+ const rawMessages = result.flat(1).filter((msg) => !!msg);
728
+ const list = new agent.MessageList().add(rawMessages.map(this.parseStoredMessage), "memory");
729
+ if (format === `v1`) return list.get.all.v1();
730
+ return list.get.all.v2();
731
+ } catch (error$1) {
732
+ throw new error.MastraError(
733
+ {
734
+ id: "STORAGE_UPSTASH_STORAGE_GET_MESSAGES_BY_ID_FAILED",
735
+ domain: error.ErrorDomain.STORAGE,
736
+ category: error.ErrorCategory.THIRD_PARTY,
737
+ details: {
738
+ messageIds: JSON.stringify(messageIds)
739
+ }
740
+ },
741
+ error$1
742
+ );
743
+ }
744
+ }
702
745
  async getMessagesPaginated(args) {
703
746
  const { threadId, selectBy, format } = args;
704
747
  const { page = 0, perPage = 40, dateRange } = selectBy?.pagination || {};
@@ -1779,6 +1822,12 @@ var UpstashStore = class extends storage.MastraStorage {
1779
1822
  }) {
1780
1823
  return this.stores.memory.getMessages({ threadId, selectBy, format });
1781
1824
  }
1825
+ async getMessagesById({
1826
+ messageIds,
1827
+ format
1828
+ }) {
1829
+ return this.stores.memory.getMessagesById({ messageIds, format });
1830
+ }
1782
1831
  async getMessagesPaginated(args) {
1783
1832
  return this.stores.memory.getMessagesPaginated(args);
1784
1833
  }