@mastra/upstash 0.14.0 → 0.14.2-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 +1 -1
- package/CHANGELOG.md +40 -0
- package/dist/index.cjs +67 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +67 -3
- 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/domains/scores/index.d.ts +5 -2
- package/dist/storage/domains/scores/index.d.ts.map +1 -1
- package/dist/storage/domains/utils.d.ts.map +1 -1
- package/dist/storage/index.d.ts +13 -2
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/storage/domains/memory/index.ts +67 -0
- package/src/storage/domains/scores/index.ts +15 -2
- package/src/storage/domains/utils.ts +9 -1
- package/src/storage/index.ts +20 -2
package/dist/index.js
CHANGED
|
@@ -251,6 +251,8 @@ function processRecord(tableName, record) {
|
|
|
251
251
|
});
|
|
252
252
|
} else if (tableName === TABLE_EVALS) {
|
|
253
253
|
key = getKey(tableName, { id: record.run_id });
|
|
254
|
+
} else if (tableName === TABLE_SCORERS) {
|
|
255
|
+
key = getKey(tableName, { runId: record.runId });
|
|
254
256
|
} else {
|
|
255
257
|
key = getKey(tableName, { id: record.id });
|
|
256
258
|
}
|
|
@@ -620,6 +622,15 @@ var StoreMemoryUpstash = class extends MemoryStorage {
|
|
|
620
622
|
}
|
|
621
623
|
return [];
|
|
622
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
|
+
}
|
|
623
634
|
async getMessages({
|
|
624
635
|
threadId,
|
|
625
636
|
selectBy,
|
|
@@ -695,6 +706,40 @@ var StoreMemoryUpstash = class extends MemoryStorage {
|
|
|
695
706
|
);
|
|
696
707
|
}
|
|
697
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
|
+
}
|
|
698
743
|
async getMessagesPaginated(args) {
|
|
699
744
|
const { threadId, selectBy, format } = args;
|
|
700
745
|
const { page = 0, perPage = 40, dateRange } = selectBy?.pagination || {};
|
|
@@ -1199,6 +1244,9 @@ var ScoresUpstash = class extends ScoresStorage {
|
|
|
1199
1244
|
}
|
|
1200
1245
|
async getScoresByScorerId({
|
|
1201
1246
|
scorerId,
|
|
1247
|
+
entityId,
|
|
1248
|
+
entityType,
|
|
1249
|
+
source,
|
|
1202
1250
|
pagination = { page: 0, perPage: 20 }
|
|
1203
1251
|
}) {
|
|
1204
1252
|
const pattern = `${TABLE_SCORERS}:*`;
|
|
@@ -1212,7 +1260,14 @@ var ScoresUpstash = class extends ScoresStorage {
|
|
|
1212
1260
|
const pipeline = this.client.pipeline();
|
|
1213
1261
|
keys.forEach((key) => pipeline.get(key));
|
|
1214
1262
|
const results = await pipeline.exec();
|
|
1215
|
-
const filtered = results.map((row) => row).filter((row) =>
|
|
1263
|
+
const filtered = results.map((row) => row).filter((row) => {
|
|
1264
|
+
if (!row || typeof row !== "object") return false;
|
|
1265
|
+
if (row.scorerId !== scorerId) return false;
|
|
1266
|
+
if (entityId && row.entityId !== entityId) return false;
|
|
1267
|
+
if (entityType && row.entityType !== entityType) return false;
|
|
1268
|
+
if (source && row.source !== source) return false;
|
|
1269
|
+
return true;
|
|
1270
|
+
});
|
|
1216
1271
|
const total = filtered.length;
|
|
1217
1272
|
const { page, perPage } = pagination;
|
|
1218
1273
|
const start = page * perPage;
|
|
@@ -1765,6 +1820,12 @@ var UpstashStore = class extends MastraStorage {
|
|
|
1765
1820
|
}) {
|
|
1766
1821
|
return this.stores.memory.getMessages({ threadId, selectBy, format });
|
|
1767
1822
|
}
|
|
1823
|
+
async getMessagesById({
|
|
1824
|
+
messageIds,
|
|
1825
|
+
format
|
|
1826
|
+
}) {
|
|
1827
|
+
return this.stores.memory.getMessagesById({ messageIds, format });
|
|
1828
|
+
}
|
|
1768
1829
|
async getMessagesPaginated(args) {
|
|
1769
1830
|
return this.stores.memory.getMessagesPaginated(args);
|
|
1770
1831
|
}
|
|
@@ -1836,9 +1897,12 @@ var UpstashStore = class extends MastraStorage {
|
|
|
1836
1897
|
}
|
|
1837
1898
|
async getScoresByScorerId({
|
|
1838
1899
|
scorerId,
|
|
1839
|
-
pagination
|
|
1900
|
+
pagination,
|
|
1901
|
+
entityId,
|
|
1902
|
+
entityType,
|
|
1903
|
+
source
|
|
1840
1904
|
}) {
|
|
1841
|
-
return this.stores.scores.getScoresByScorerId({ scorerId, pagination });
|
|
1905
|
+
return this.stores.scores.getScoresByScorerId({ scorerId, pagination, entityId, entityType, source });
|
|
1842
1906
|
}
|
|
1843
1907
|
};
|
|
1844
1908
|
var UpstashFilterTranslator = class extends BaseFilterTranslator {
|