@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.
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +18 -0
- package/dist/index.cjs +49 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +49 -0
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +9 -0
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +8 -0
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/storage/domains/memory/index.ts +67 -0
- package/src/storage/index.ts +12 -0
package/dist/index.js
CHANGED
|
@@ -622,6 +622,15 @@ var StoreMemoryUpstash = class extends MemoryStorage {
|
|
|
622
622
|
}
|
|
623
623
|
return [];
|
|
624
624
|
}
|
|
625
|
+
parseStoredMessage(storedMessage) {
|
|
626
|
+
const defaultMessageContent = { format: 2, parts: [{ type: "text", text: "" }] };
|
|
627
|
+
const { _index, ...rest } = storedMessage;
|
|
628
|
+
return {
|
|
629
|
+
...rest,
|
|
630
|
+
createdAt: new Date(rest.createdAt),
|
|
631
|
+
content: rest.content || defaultMessageContent
|
|
632
|
+
};
|
|
633
|
+
}
|
|
625
634
|
async getMessages({
|
|
626
635
|
threadId,
|
|
627
636
|
selectBy,
|
|
@@ -697,6 +706,40 @@ var StoreMemoryUpstash = class extends MemoryStorage {
|
|
|
697
706
|
);
|
|
698
707
|
}
|
|
699
708
|
}
|
|
709
|
+
async getMessagesById({
|
|
710
|
+
messageIds,
|
|
711
|
+
format
|
|
712
|
+
}) {
|
|
713
|
+
if (messageIds.length === 0) return [];
|
|
714
|
+
try {
|
|
715
|
+
const threadKeys = await this.client.keys("thread:*");
|
|
716
|
+
const result = await Promise.all(
|
|
717
|
+
threadKeys.map((threadKey) => {
|
|
718
|
+
const threadId = threadKey.split(":")[1];
|
|
719
|
+
if (!threadId) throw new Error(`Failed to parse thread ID from thread key "${threadKey}"`);
|
|
720
|
+
return this.client.mget(
|
|
721
|
+
messageIds.map((id) => getMessageKey(threadId, id))
|
|
722
|
+
);
|
|
723
|
+
})
|
|
724
|
+
);
|
|
725
|
+
const rawMessages = result.flat(1).filter((msg) => !!msg);
|
|
726
|
+
const list = new MessageList().add(rawMessages.map(this.parseStoredMessage), "memory");
|
|
727
|
+
if (format === `v1`) return list.get.all.v1();
|
|
728
|
+
return list.get.all.v2();
|
|
729
|
+
} catch (error) {
|
|
730
|
+
throw new MastraError(
|
|
731
|
+
{
|
|
732
|
+
id: "STORAGE_UPSTASH_STORAGE_GET_MESSAGES_BY_ID_FAILED",
|
|
733
|
+
domain: ErrorDomain.STORAGE,
|
|
734
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
735
|
+
details: {
|
|
736
|
+
messageIds: JSON.stringify(messageIds)
|
|
737
|
+
}
|
|
738
|
+
},
|
|
739
|
+
error
|
|
740
|
+
);
|
|
741
|
+
}
|
|
742
|
+
}
|
|
700
743
|
async getMessagesPaginated(args) {
|
|
701
744
|
const { threadId, selectBy, format } = args;
|
|
702
745
|
const { page = 0, perPage = 40, dateRange } = selectBy?.pagination || {};
|
|
@@ -1777,6 +1820,12 @@ var UpstashStore = class extends MastraStorage {
|
|
|
1777
1820
|
}) {
|
|
1778
1821
|
return this.stores.memory.getMessages({ threadId, selectBy, format });
|
|
1779
1822
|
}
|
|
1823
|
+
async getMessagesById({
|
|
1824
|
+
messageIds,
|
|
1825
|
+
format
|
|
1826
|
+
}) {
|
|
1827
|
+
return this.stores.memory.getMessagesById({ messageIds, format });
|
|
1828
|
+
}
|
|
1780
1829
|
async getMessagesPaginated(args) {
|
|
1781
1830
|
return this.stores.memory.getMessagesPaginated(args);
|
|
1782
1831
|
}
|