@mastra/upstash 0.10.3 → 0.11.0-alpha.0
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 +14 -14
- package/CHANGELOG.md +13 -0
- package/dist/index.cjs +1065 -458
- package/dist/index.js +1066 -459
- package/package.json +7 -7
- package/src/storage/index.ts +14 -0
- package/src/storage/upstash.test.ts +25 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/upstash",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0-alpha.0",
|
|
4
4
|
"description": "Upstash provider for Mastra - includes both vector and db storage capabilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -25,15 +25,15 @@
|
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@microsoft/api-extractor": "^7.52.8",
|
|
28
|
-
"@types/node": "^20.
|
|
28
|
+
"@types/node": "^20.19.0",
|
|
29
29
|
"dotenv": "^16.5.0",
|
|
30
30
|
"eslint": "^9.28.0",
|
|
31
31
|
"tsup": "^8.5.0",
|
|
32
|
-
"typescript": "^5.8.
|
|
33
|
-
"vitest": "^3.2.
|
|
34
|
-
"@internal/storage-test-utils": "0.0.
|
|
35
|
-
"@internal/lint": "0.0.
|
|
36
|
-
"@mastra/core": "0.10.
|
|
32
|
+
"typescript": "^5.8.3",
|
|
33
|
+
"vitest": "^3.2.3",
|
|
34
|
+
"@internal/storage-test-utils": "0.0.8",
|
|
35
|
+
"@internal/lint": "0.0.12",
|
|
36
|
+
"@mastra/core": "0.10.6-alpha.0"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"@mastra/core": ">=0.10.4-0 <0.11.0"
|
package/src/storage/index.ts
CHANGED
|
@@ -628,10 +628,15 @@ export class UpstashStore extends MastraStorage {
|
|
|
628
628
|
_index: index,
|
|
629
629
|
}));
|
|
630
630
|
|
|
631
|
+
// Get current thread data once (all messages belong to same thread)
|
|
632
|
+
const threadKey = this.getKey(TABLE_THREADS, { id: threadId });
|
|
633
|
+
const existingThread = await this.redis.get<StorageThreadType>(threadKey);
|
|
634
|
+
|
|
631
635
|
const batchSize = 1000;
|
|
632
636
|
for (let i = 0; i < messagesWithIndex.length; i += batchSize) {
|
|
633
637
|
const batch = messagesWithIndex.slice(i, i + batchSize);
|
|
634
638
|
const pipeline = this.redis.pipeline();
|
|
639
|
+
|
|
635
640
|
for (const message of batch) {
|
|
636
641
|
const key = this.getMessageKey(message.threadId!, message.id);
|
|
637
642
|
const createdAtScore = new Date(message.createdAt).getTime();
|
|
@@ -647,6 +652,15 @@ export class UpstashStore extends MastraStorage {
|
|
|
647
652
|
});
|
|
648
653
|
}
|
|
649
654
|
|
|
655
|
+
// Update the thread's updatedAt field (only in the first batch)
|
|
656
|
+
if (i === 0 && existingThread) {
|
|
657
|
+
const updatedThread = {
|
|
658
|
+
...existingThread,
|
|
659
|
+
updatedAt: new Date(),
|
|
660
|
+
};
|
|
661
|
+
pipeline.set(threadKey, this.processRecord(TABLE_THREADS, updatedThread).processedRecord);
|
|
662
|
+
}
|
|
663
|
+
|
|
650
664
|
await pipeline.exec();
|
|
651
665
|
}
|
|
652
666
|
|
|
@@ -187,6 +187,29 @@ describe('UpstashStore', () => {
|
|
|
187
187
|
updated: 'value',
|
|
188
188
|
});
|
|
189
189
|
});
|
|
190
|
+
|
|
191
|
+
it('should update thread updatedAt when a message is saved to it', async () => {
|
|
192
|
+
const thread = createSampleThread();
|
|
193
|
+
await store.saveThread({ thread });
|
|
194
|
+
|
|
195
|
+
// Get the initial thread to capture the original updatedAt
|
|
196
|
+
const initialThread = await store.getThreadById({ threadId: thread.id });
|
|
197
|
+
expect(initialThread).toBeDefined();
|
|
198
|
+
const originalUpdatedAt = initialThread!.updatedAt;
|
|
199
|
+
|
|
200
|
+
// Wait a small amount to ensure different timestamp
|
|
201
|
+
await new Promise(resolve => setTimeout(resolve, 10));
|
|
202
|
+
|
|
203
|
+
// Create and save a message to the thread
|
|
204
|
+
const message = createSampleMessageV2({ threadId: thread.id });
|
|
205
|
+
await store.saveMessages({ messages: [message], format: 'v2' });
|
|
206
|
+
|
|
207
|
+
// Retrieve the thread again and check that updatedAt was updated
|
|
208
|
+
const updatedThread = await store.getThreadById({ threadId: thread.id });
|
|
209
|
+
expect(updatedThread).toBeDefined();
|
|
210
|
+
expect(updatedThread!.updatedAt.getTime()).toBeGreaterThan(originalUpdatedAt.getTime());
|
|
211
|
+
});
|
|
212
|
+
|
|
190
213
|
it('should fetch >100000 threads by resource ID', async () => {
|
|
191
214
|
const resourceId = `resource-${randomUUID()}`;
|
|
192
215
|
const total = 100_000;
|
|
@@ -669,13 +692,14 @@ describe('UpstashStore', () => {
|
|
|
669
692
|
activePaths: [],
|
|
670
693
|
suspendedPaths: {},
|
|
671
694
|
timestamp: Date.now(),
|
|
695
|
+
status: 'success',
|
|
672
696
|
};
|
|
673
697
|
|
|
674
698
|
await store.persistWorkflowSnapshot({
|
|
675
699
|
namespace: testNamespace,
|
|
676
700
|
workflowName: testWorkflow,
|
|
677
701
|
runId: testRunId,
|
|
678
|
-
snapshot: mockSnapshot,
|
|
702
|
+
snapshot: mockSnapshot as WorkflowRunState,
|
|
679
703
|
});
|
|
680
704
|
|
|
681
705
|
const loadedSnapshot = await store.loadWorkflowSnapshot({
|