@mastra/pg 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 +56 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +56 -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 +72 -0
- package/src/storage/index.ts +12 -0
package/.turbo/turbo-build.log
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @mastra/pg
|
|
2
2
|
|
|
3
|
+
## 0.14.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#6700](https://github.com/mastra-ai/mastra/pull/6700) [`a5a23d9`](https://github.com/mastra-ai/mastra/commit/a5a23d981920d458dc6078919992a5338931ef02) Thanks [@gpanakkal](https://github.com/gpanakkal)! - Add `getMessagesById` method to `MastraStorage` adapters
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`6e7e120`](https://github.com/mastra-ai/mastra/commit/6e7e1207d6e8d8b838f9024f90bd10df1181ba27), [`0f00e17`](https://github.com/mastra-ai/mastra/commit/0f00e172953ccdccadb35ed3d70f5e4d89115869), [`217cd7a`](https://github.com/mastra-ai/mastra/commit/217cd7a4ce171e9a575c41bb8c83300f4db03236), [`a5a23d9`](https://github.com/mastra-ai/mastra/commit/a5a23d981920d458dc6078919992a5338931ef02)]:
|
|
10
|
+
- @mastra/core@0.14.1
|
|
11
|
+
|
|
12
|
+
## 0.14.2-alpha.0
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- [#6700](https://github.com/mastra-ai/mastra/pull/6700) [`a5a23d9`](https://github.com/mastra-ai/mastra/commit/a5a23d981920d458dc6078919992a5338931ef02) Thanks [@gpanakkal](https://github.com/gpanakkal)! - Add `getMessagesById` method to `MastraStorage` adapters
|
|
17
|
+
|
|
18
|
+
- Updated dependencies [[`6e7e120`](https://github.com/mastra-ai/mastra/commit/6e7e1207d6e8d8b838f9024f90bd10df1181ba27), [`a5a23d9`](https://github.com/mastra-ai/mastra/commit/a5a23d981920d458dc6078919992a5338931ef02)]:
|
|
19
|
+
- @mastra/core@0.14.1-alpha.0
|
|
20
|
+
|
|
3
21
|
## 0.14.1
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -1551,6 +1551,22 @@ var MemoryPG = class extends storage.MemoryStorage {
|
|
|
1551
1551
|
});
|
|
1552
1552
|
return dedupedRows;
|
|
1553
1553
|
}
|
|
1554
|
+
parseRow(row) {
|
|
1555
|
+
let content = row.content;
|
|
1556
|
+
try {
|
|
1557
|
+
content = JSON.parse(row.content);
|
|
1558
|
+
} catch {
|
|
1559
|
+
}
|
|
1560
|
+
return {
|
|
1561
|
+
id: row.id,
|
|
1562
|
+
content,
|
|
1563
|
+
role: row.role,
|
|
1564
|
+
createdAt: new Date(row.createdAt),
|
|
1565
|
+
threadId: row.threadId,
|
|
1566
|
+
resourceId: row.resourceId,
|
|
1567
|
+
...row.type && row.type !== "v2" ? { type: row.type } : {}
|
|
1568
|
+
};
|
|
1569
|
+
}
|
|
1554
1570
|
async getMessages(args) {
|
|
1555
1571
|
const { threadId, format, selectBy } = args;
|
|
1556
1572
|
const selectStatement = `SELECT id, content, role, type, "createdAt", thread_id AS "threadId", "resourceId"`;
|
|
@@ -1609,6 +1625,40 @@ var MemoryPG = class extends storage.MemoryStorage {
|
|
|
1609
1625
|
return [];
|
|
1610
1626
|
}
|
|
1611
1627
|
}
|
|
1628
|
+
async getMessagesById({
|
|
1629
|
+
messageIds,
|
|
1630
|
+
format
|
|
1631
|
+
}) {
|
|
1632
|
+
if (messageIds.length === 0) return [];
|
|
1633
|
+
const selectStatement = `SELECT id, content, role, type, "createdAt", thread_id AS "threadId", "resourceId"`;
|
|
1634
|
+
try {
|
|
1635
|
+
const tableName = getTableName({ indexName: storage.TABLE_MESSAGES, schemaName: getSchemaName(this.schema) });
|
|
1636
|
+
const query = `
|
|
1637
|
+
${selectStatement} FROM ${tableName}
|
|
1638
|
+
WHERE id IN (${messageIds.map((_, i) => `$${i + 1}`).join(", ")})
|
|
1639
|
+
ORDER BY "createdAt" DESC
|
|
1640
|
+
`;
|
|
1641
|
+
const resultRows = await this.client.manyOrNone(query, messageIds);
|
|
1642
|
+
const list = new agent.MessageList().add(resultRows.map(this.parseRow), "memory");
|
|
1643
|
+
if (format === `v1`) return list.get.all.v1();
|
|
1644
|
+
return list.get.all.v2();
|
|
1645
|
+
} catch (error$1) {
|
|
1646
|
+
const mastraError = new error.MastraError(
|
|
1647
|
+
{
|
|
1648
|
+
id: "MASTRA_STORAGE_PG_STORE_GET_MESSAGES_BY_ID_FAILED",
|
|
1649
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1650
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1651
|
+
details: {
|
|
1652
|
+
messageIds: JSON.stringify(messageIds)
|
|
1653
|
+
}
|
|
1654
|
+
},
|
|
1655
|
+
error$1
|
|
1656
|
+
);
|
|
1657
|
+
this.logger?.error?.(mastraError.toString());
|
|
1658
|
+
this.logger?.trackException(mastraError);
|
|
1659
|
+
return [];
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1612
1662
|
async getMessagesPaginated(args) {
|
|
1613
1663
|
const { threadId, format, selectBy } = args;
|
|
1614
1664
|
const { page = 0, perPage: perPageInput, dateRange } = selectBy?.pagination || {};
|
|
@@ -3062,6 +3112,12 @@ var PostgresStore = class extends storage.MastraStorage {
|
|
|
3062
3112
|
async getMessages(args) {
|
|
3063
3113
|
return this.stores.memory.getMessages(args);
|
|
3064
3114
|
}
|
|
3115
|
+
async getMessagesById({
|
|
3116
|
+
messageIds,
|
|
3117
|
+
format
|
|
3118
|
+
}) {
|
|
3119
|
+
return this.stores.memory.getMessagesById({ messageIds, format });
|
|
3120
|
+
}
|
|
3065
3121
|
async getMessagesPaginated(args) {
|
|
3066
3122
|
return this.stores.memory.getMessagesPaginated(args);
|
|
3067
3123
|
}
|