@mastra/cloudflare 0.11.5 → 0.11.7-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/dist/index.cjs +71 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +72 -16
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +8 -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/index.d.ts +13 -2
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +8 -8
package/dist/index.cjs
CHANGED
|
@@ -733,6 +733,41 @@ var MemoryStorageCloudflare = class extends storage.MemoryStorage {
|
|
|
733
733
|
return [];
|
|
734
734
|
}
|
|
735
735
|
}
|
|
736
|
+
async getMessagesById({
|
|
737
|
+
messageIds,
|
|
738
|
+
format
|
|
739
|
+
}) {
|
|
740
|
+
if (messageIds.length === 0) return [];
|
|
741
|
+
try {
|
|
742
|
+
const messages = (await Promise.all(messageIds.map((id) => this.findMessageInAnyThread(id)))).filter(
|
|
743
|
+
(result) => !!result
|
|
744
|
+
);
|
|
745
|
+
const prepared = messages.map(({ _index, ...message }) => ({
|
|
746
|
+
...message,
|
|
747
|
+
...message.type !== `v2` && { type: message.type },
|
|
748
|
+
createdAt: storage.ensureDate(message.createdAt)
|
|
749
|
+
}));
|
|
750
|
+
const list = new agent.MessageList().add(prepared, "memory");
|
|
751
|
+
if (format === `v1`) return list.get.all.v1();
|
|
752
|
+
return list.get.all.v2();
|
|
753
|
+
} catch (error$1) {
|
|
754
|
+
const mastraError = new error.MastraError(
|
|
755
|
+
{
|
|
756
|
+
id: "CLOUDFLARE_STORAGE_GET_MESSAGES_BY_ID_FAILED",
|
|
757
|
+
domain: error.ErrorDomain.STORAGE,
|
|
758
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
759
|
+
text: `Error retrieving messages by ID`,
|
|
760
|
+
details: {
|
|
761
|
+
messageIds: JSON.stringify(messageIds)
|
|
762
|
+
}
|
|
763
|
+
},
|
|
764
|
+
error$1
|
|
765
|
+
);
|
|
766
|
+
this.logger?.trackException(mastraError);
|
|
767
|
+
this.logger?.error(mastraError.toString());
|
|
768
|
+
return [];
|
|
769
|
+
}
|
|
770
|
+
}
|
|
736
771
|
async getMessagesPaginated(args) {
|
|
737
772
|
try {
|
|
738
773
|
const { threadId, selectBy, format = "v1" } = args;
|
|
@@ -1535,18 +1570,17 @@ var StoreOperationsCloudflare = class extends storage.StoreOperations {
|
|
|
1535
1570
|
}
|
|
1536
1571
|
};
|
|
1537
1572
|
function transformScoreRow(row) {
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
};
|
|
1573
|
+
const deserialized = { ...row };
|
|
1574
|
+
deserialized.input = storage.safelyParseJSON(row.input);
|
|
1575
|
+
deserialized.output = storage.safelyParseJSON(row.output);
|
|
1576
|
+
deserialized.scorer = storage.safelyParseJSON(row.scorer);
|
|
1577
|
+
deserialized.preprocessStepResult = storage.safelyParseJSON(row.preprocessStepResult);
|
|
1578
|
+
deserialized.analyzeStepResult = storage.safelyParseJSON(row.analyzeStepResult);
|
|
1579
|
+
deserialized.metadata = storage.safelyParseJSON(row.metadata);
|
|
1580
|
+
deserialized.additionalContext = storage.safelyParseJSON(row.additionalContext);
|
|
1581
|
+
deserialized.runtimeContext = storage.safelyParseJSON(row.runtimeContext);
|
|
1582
|
+
deserialized.entity = storage.safelyParseJSON(row.entity);
|
|
1583
|
+
return deserialized;
|
|
1550
1584
|
}
|
|
1551
1585
|
var ScoresStorageCloudflare = class extends storage.ScoresStorage {
|
|
1552
1586
|
operations;
|
|
@@ -1578,6 +1612,7 @@ var ScoresStorageCloudflare = class extends storage.ScoresStorage {
|
|
|
1578
1612
|
}
|
|
1579
1613
|
async saveScore(score) {
|
|
1580
1614
|
try {
|
|
1615
|
+
const id = crypto.randomUUID();
|
|
1581
1616
|
const { input, ...rest } = score;
|
|
1582
1617
|
const serializedRecord = {};
|
|
1583
1618
|
for (const [key, value] of Object.entries(rest)) {
|
|
@@ -1591,12 +1626,12 @@ var ScoresStorageCloudflare = class extends storage.ScoresStorage {
|
|
|
1591
1626
|
serializedRecord[key] = null;
|
|
1592
1627
|
}
|
|
1593
1628
|
}
|
|
1594
|
-
serializedRecord.
|
|
1629
|
+
serializedRecord.id = id;
|
|
1595
1630
|
serializedRecord.createdAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1596
1631
|
serializedRecord.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1597
1632
|
await this.operations.putKV({
|
|
1598
1633
|
tableName: storage.TABLE_SCORERS,
|
|
1599
|
-
key:
|
|
1634
|
+
key: id,
|
|
1600
1635
|
value: serializedRecord
|
|
1601
1636
|
});
|
|
1602
1637
|
const scoreFromDb = await this.getScoreById({ id: score.id });
|
|
@@ -1618,6 +1653,9 @@ var ScoresStorageCloudflare = class extends storage.ScoresStorage {
|
|
|
1618
1653
|
}
|
|
1619
1654
|
async getScoresByScorerId({
|
|
1620
1655
|
scorerId,
|
|
1656
|
+
entityId,
|
|
1657
|
+
entityType,
|
|
1658
|
+
source,
|
|
1621
1659
|
pagination
|
|
1622
1660
|
}) {
|
|
1623
1661
|
try {
|
|
@@ -1625,6 +1663,15 @@ var ScoresStorageCloudflare = class extends storage.ScoresStorage {
|
|
|
1625
1663
|
const scores = [];
|
|
1626
1664
|
for (const { name: key } of keys) {
|
|
1627
1665
|
const score = await this.operations.getKV(storage.TABLE_SCORERS, key);
|
|
1666
|
+
if (entityId && score.entityId !== entityId) {
|
|
1667
|
+
continue;
|
|
1668
|
+
}
|
|
1669
|
+
if (entityType && score.entityType !== entityType) {
|
|
1670
|
+
continue;
|
|
1671
|
+
}
|
|
1672
|
+
if (source && score.source !== source) {
|
|
1673
|
+
continue;
|
|
1674
|
+
}
|
|
1628
1675
|
if (score && score.scorerId === scorerId) {
|
|
1629
1676
|
scores.push(transformScoreRow(score));
|
|
1630
1677
|
}
|
|
@@ -2239,6 +2286,12 @@ var CloudflareStore = class extends storage.MastraStorage {
|
|
|
2239
2286
|
}) {
|
|
2240
2287
|
return this.stores.memory.getMessages({ threadId, resourceId, selectBy, format });
|
|
2241
2288
|
}
|
|
2289
|
+
async getMessagesById({
|
|
2290
|
+
messageIds,
|
|
2291
|
+
format
|
|
2292
|
+
}) {
|
|
2293
|
+
return this.stores.memory.getMessagesById({ messageIds, format });
|
|
2294
|
+
}
|
|
2242
2295
|
async persistWorkflowSnapshot(params) {
|
|
2243
2296
|
return this.stores.workflows.persistWorkflowSnapshot(params);
|
|
2244
2297
|
}
|
|
@@ -2329,9 +2382,12 @@ var CloudflareStore = class extends storage.MastraStorage {
|
|
|
2329
2382
|
}
|
|
2330
2383
|
async getScoresByScorerId({
|
|
2331
2384
|
scorerId,
|
|
2385
|
+
entityId,
|
|
2386
|
+
entityType,
|
|
2387
|
+
source,
|
|
2332
2388
|
pagination
|
|
2333
2389
|
}) {
|
|
2334
|
-
return this.stores.scores.getScoresByScorerId({ scorerId, pagination });
|
|
2390
|
+
return this.stores.scores.getScoresByScorerId({ scorerId, entityId, entityType, source, pagination });
|
|
2335
2391
|
}
|
|
2336
2392
|
async getResourceById({ resourceId }) {
|
|
2337
2393
|
return this.stores.memory.getResourceById({ resourceId });
|