@mastra/upstash 1.4.0-alpha.0 → 1.4.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/CHANGELOG.md +10 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +27 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +27 -4
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +7 -0
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @mastra/upstash
|
|
2
2
|
|
|
3
|
+
## 1.4.0-alpha.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fixed resource-scoped message includes across storage adapters so included context cannot cross resource boundaries. ([#20984](https://github.com/mastra-ai/mastra/pull/20984))
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`6445eba`](https://github.com/mastra-ai/mastra/commit/6445eba6020abac681aba1cc9289f446cb400cbe), [`df31eb0`](https://github.com/mastra-ai/mastra/commit/df31eb0c7087d782a0d9346e467f9a4af4b0eef6), [`df31eb0`](https://github.com/mastra-ai/mastra/commit/df31eb0c7087d782a0d9346e467f9a4af4b0eef6), [`fcd0667`](https://github.com/mastra-ai/mastra/commit/fcd0667a4e378be35c9a1b1eb19cce78fbfd7282), [`bab06b1`](https://github.com/mastra-ai/mastra/commit/bab06b18923873a584bdfc71a6b4ec7fb4727fb7)]:
|
|
10
|
+
- @mastra/core@1.58.0-alpha.5
|
|
11
|
+
- @mastra/redis@1.4.0-alpha.1
|
|
12
|
+
|
|
3
13
|
## 1.4.0-alpha.0
|
|
4
14
|
|
|
5
15
|
### Minor Changes
|
package/dist/docs/SKILL.md
CHANGED
|
@@ -3,7 +3,7 @@ name: mastra-upstash
|
|
|
3
3
|
description: Documentation for @mastra/upstash. Use when working with @mastra/upstash APIs, configuration, or implementation.
|
|
4
4
|
metadata:
|
|
5
5
|
package: "@mastra/upstash"
|
|
6
|
-
version: "1.4.0-alpha.
|
|
6
|
+
version: "1.4.0-alpha.1"
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
## When to use
|
package/dist/index.cjs
CHANGED
|
@@ -658,16 +658,38 @@ var StoreMemoryUpstash = class extends _mastra_core_storage.MemoryStorage {
|
|
|
658
658
|
return direction === "ASC" ? aValue - bValue : bValue - aValue;
|
|
659
659
|
});
|
|
660
660
|
}
|
|
661
|
-
|
|
661
|
+
/**
|
|
662
|
+
* Fetches the messages named by `include` together with their surrounding context.
|
|
663
|
+
*
|
|
664
|
+
* @param include - Message ids to pin, each with an optional before/after window.
|
|
665
|
+
* @param resourceId - When set, drops any pinned or context message owned by another
|
|
666
|
+
* resource so an id from another resource returns nothing.
|
|
667
|
+
*/
|
|
668
|
+
async _getIncludedMessages(include, resourceId) {
|
|
662
669
|
if (!include?.length) return [];
|
|
663
670
|
const messageIds = /* @__PURE__ */ new Set();
|
|
664
671
|
const messageIdToThreadIds = {};
|
|
665
672
|
for (const item of include) {
|
|
666
673
|
const itemThreadId = await this._getThreadIdForMessage(item.id);
|
|
667
674
|
if (!itemThreadId) continue;
|
|
675
|
+
const itemThreadMessagesKey = getThreadMessagesKey(itemThreadId);
|
|
676
|
+
if (resourceId !== void 0) {
|
|
677
|
+
const threadMessageIds = await this.client.zrange(itemThreadMessagesKey, 0, -1);
|
|
678
|
+
const threadPipeline = this.client.pipeline();
|
|
679
|
+
threadMessageIds.forEach((id) => threadPipeline.get(getMessageKey(itemThreadId, id)));
|
|
680
|
+
const threadMessages = (await threadPipeline.exec()).filter((message) => message !== null).filter((message) => message.resourceId === resourceId);
|
|
681
|
+
const targetIndex = threadMessages.findIndex((message) => message.id === item.id);
|
|
682
|
+
if (targetIndex === -1) continue;
|
|
683
|
+
const start = Math.max(0, targetIndex - (item.withPreviousMessages ?? 0));
|
|
684
|
+
const end = Math.min(threadMessages.length, targetIndex + (item.withNextMessages ?? 0) + 1);
|
|
685
|
+
for (const message of threadMessages.slice(start, end)) {
|
|
686
|
+
messageIds.add(message.id);
|
|
687
|
+
messageIdToThreadIds[message.id] = itemThreadId;
|
|
688
|
+
}
|
|
689
|
+
continue;
|
|
690
|
+
}
|
|
668
691
|
messageIds.add(item.id);
|
|
669
692
|
messageIdToThreadIds[item.id] = itemThreadId;
|
|
670
|
-
const itemThreadMessagesKey = getThreadMessagesKey(itemThreadId);
|
|
671
693
|
const rank = await this.client.zrank(itemThreadMessagesKey, item.id);
|
|
672
694
|
if (rank === null) continue;
|
|
673
695
|
if (item.withPreviousMessages) {
|
|
@@ -688,7 +710,8 @@ var StoreMemoryUpstash = class extends _mastra_core_storage.MemoryStorage {
|
|
|
688
710
|
const tId = messageIdToThreadIds[id];
|
|
689
711
|
pipeline.get(getMessageKey(tId, id));
|
|
690
712
|
});
|
|
691
|
-
|
|
713
|
+
const includedMessages = (await pipeline.exec()).filter((result) => result !== null);
|
|
714
|
+
return resourceId ? includedMessages.filter((message) => message.resourceId === resourceId) : includedMessages;
|
|
692
715
|
}
|
|
693
716
|
parseStoredMessage(storedMessage) {
|
|
694
717
|
const defaultMessageContent = {
|
|
@@ -782,7 +805,7 @@ var StoreMemoryUpstash = class extends _mastra_core_storage.MemoryStorage {
|
|
|
782
805
|
hasMore: false
|
|
783
806
|
};
|
|
784
807
|
let includedMessages = [];
|
|
785
|
-
if (include && include.length > 0) includedMessages = (await this._getIncludedMessages(include)).map(this.parseStoredMessage);
|
|
808
|
+
if (include && include.length > 0) includedMessages = (await this._getIncludedMessages(include, resourceId)).map(this.parseStoredMessage);
|
|
786
809
|
if (perPage === 0 && include && include.length > 0) {
|
|
787
810
|
const list = new _mastra_core_agent.MessageList().add(includedMessages, "memory");
|
|
788
811
|
return {
|