@mastra/pg 0.10.3 → 0.11.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/.turbo/turbo-build.log +10 -10
- package/CHANGELOG.md +25 -0
- package/dist/index.cjs +10 -3
- package/dist/index.js +10 -3
- package/package.json +7 -7
- package/src/storage/index.test.ts +22 -0
- package/src/storage/index.ts +13 -3
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/pg@0.
|
|
2
|
+
> @mastra/pg@0.11.0-alpha.1 build /home/runner/work/mastra/mastra/stores/pg
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
6
6
|
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
7
|
[34mCLI[39m tsup v8.5.0
|
|
8
8
|
[34mTSC[39m Build start
|
|
9
|
-
[32mTSC[39m ⚡️ Build success in
|
|
9
|
+
[32mTSC[39m ⚡️ Build success in 10371ms
|
|
10
10
|
[34mDTS[39m Build start
|
|
11
11
|
[34mCLI[39m Target: es2022
|
|
12
|
-
[34mCLI[39m Cleaning output folder
|
|
13
|
-
[34mESM[39m Build start
|
|
14
|
-
[34mCJS[39m Build start
|
|
15
12
|
Analysis will use the bundled TypeScript version 5.8.3
|
|
16
13
|
[36mWriting package typings: /home/runner/work/mastra/mastra/stores/pg/dist/_tsup-dts-rollup.d.ts[39m
|
|
17
14
|
Analysis will use the bundled TypeScript version 5.8.3
|
|
18
15
|
[36mWriting package typings: /home/runner/work/mastra/mastra/stores/pg/dist/_tsup-dts-rollup.d.cts[39m
|
|
19
|
-
[32mDTS[39m ⚡️ Build success in
|
|
20
|
-
[
|
|
21
|
-
[
|
|
22
|
-
[
|
|
23
|
-
[32mCJS[39m
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 11657ms
|
|
17
|
+
[34mCLI[39m Cleaning output folder
|
|
18
|
+
[34mESM[39m Build start
|
|
19
|
+
[34mCJS[39m Build start
|
|
20
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m68.06 KB[39m
|
|
21
|
+
[32mCJS[39m ⚡️ Build success in 1500ms
|
|
22
|
+
[32mESM[39m [1mdist/index.js [22m[32m67.49 KB[39m
|
|
23
|
+
[32mESM[39m ⚡️ Build success in 1504ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# @mastra/pg
|
|
2
2
|
|
|
3
|
+
## 0.11.0-alpha.1
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 704d1ca: Thread Timestamp Auto-Update Enhancement
|
|
8
|
+
Added automatic thread updatedAt timestamp updates when messages are saved across all storage providers
|
|
9
|
+
Enhanced user experience: Threads now accurately reflect their latest activity with automatic timestamp updates when new messages are added
|
|
10
|
+
Universal implementation: Consistent behavior across all 7 storage backends (ClickHouse, Cloudflare D1, DynamoDB, MongoDB, PostgreSQL, Upstash, LibSQL)
|
|
11
|
+
Performance optimized: Updates execute in parallel with message saving operations for minimal performance impact
|
|
12
|
+
Backwards compatible: No breaking changes - existing code continues to work unchanged
|
|
13
|
+
Improved conversation ordering: Chat interfaces can now properly sort threads by actual last activity
|
|
14
|
+
This enhancement resolves the issue where active conversations appeared stale due to outdated thread timestamps, providing better conversation management and user experience in chat applications.
|
|
15
|
+
|
|
16
|
+
## 0.10.4-alpha.0
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- 63f6b7d: dependencies updates:
|
|
21
|
+
- Updated dependency [`pg-promise@^11.14.0` ↗︎](https://www.npmjs.com/package/pg-promise/v/11.14.0) (from `^11.13.0`, in `dependencies`)
|
|
22
|
+
- Updated dependencies [63f6b7d]
|
|
23
|
+
- Updated dependencies [36f1c36]
|
|
24
|
+
- Updated dependencies [10d352e]
|
|
25
|
+
- Updated dependencies [53d3c37]
|
|
26
|
+
- @mastra/core@0.10.6-alpha.0
|
|
27
|
+
|
|
3
28
|
## 0.10.3
|
|
4
29
|
|
|
5
30
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -1594,7 +1594,7 @@ var PostgresStore = class extends storage.MastraStorage {
|
|
|
1594
1594
|
throw new Error(`Thread ${threadId} not found`);
|
|
1595
1595
|
}
|
|
1596
1596
|
await this.db.tx(async (t) => {
|
|
1597
|
-
|
|
1597
|
+
const messageInserts = messages.map((message) => {
|
|
1598
1598
|
if (!message.threadId) {
|
|
1599
1599
|
throw new Error(
|
|
1600
1600
|
`Expected to find a threadId for message, but couldn't find one. An unexpected error has occurred.`
|
|
@@ -1605,7 +1605,7 @@ var PostgresStore = class extends storage.MastraStorage {
|
|
|
1605
1605
|
`Expected to find a resourceId for message, but couldn't find one. An unexpected error has occurred.`
|
|
1606
1606
|
);
|
|
1607
1607
|
}
|
|
1608
|
-
|
|
1608
|
+
return t.none(
|
|
1609
1609
|
`INSERT INTO ${this.getTableName(storage.TABLE_MESSAGES)} (id, thread_id, content, "createdAt", role, type, "resourceId")
|
|
1610
1610
|
VALUES ($1, $2, $3, $4, $5, $6, $7)`,
|
|
1611
1611
|
[
|
|
@@ -1618,7 +1618,14 @@ var PostgresStore = class extends storage.MastraStorage {
|
|
|
1618
1618
|
message.resourceId
|
|
1619
1619
|
]
|
|
1620
1620
|
);
|
|
1621
|
-
}
|
|
1621
|
+
});
|
|
1622
|
+
const threadUpdate = t.none(
|
|
1623
|
+
`UPDATE ${this.getTableName(storage.TABLE_THREADS)}
|
|
1624
|
+
SET "updatedAt" = $1
|
|
1625
|
+
WHERE id = $2`,
|
|
1626
|
+
[(/* @__PURE__ */ new Date()).toISOString(), threadId]
|
|
1627
|
+
);
|
|
1628
|
+
await Promise.all([...messageInserts, threadUpdate]);
|
|
1622
1629
|
});
|
|
1623
1630
|
const list = new agent.MessageList().add(messages, "memory");
|
|
1624
1631
|
if (format === `v2`) return list.get.all.v2();
|
package/dist/index.js
CHANGED
|
@@ -1586,7 +1586,7 @@ var PostgresStore = class extends MastraStorage {
|
|
|
1586
1586
|
throw new Error(`Thread ${threadId} not found`);
|
|
1587
1587
|
}
|
|
1588
1588
|
await this.db.tx(async (t) => {
|
|
1589
|
-
|
|
1589
|
+
const messageInserts = messages.map((message) => {
|
|
1590
1590
|
if (!message.threadId) {
|
|
1591
1591
|
throw new Error(
|
|
1592
1592
|
`Expected to find a threadId for message, but couldn't find one. An unexpected error has occurred.`
|
|
@@ -1597,7 +1597,7 @@ var PostgresStore = class extends MastraStorage {
|
|
|
1597
1597
|
`Expected to find a resourceId for message, but couldn't find one. An unexpected error has occurred.`
|
|
1598
1598
|
);
|
|
1599
1599
|
}
|
|
1600
|
-
|
|
1600
|
+
return t.none(
|
|
1601
1601
|
`INSERT INTO ${this.getTableName(TABLE_MESSAGES)} (id, thread_id, content, "createdAt", role, type, "resourceId")
|
|
1602
1602
|
VALUES ($1, $2, $3, $4, $5, $6, $7)`,
|
|
1603
1603
|
[
|
|
@@ -1610,7 +1610,14 @@ var PostgresStore = class extends MastraStorage {
|
|
|
1610
1610
|
message.resourceId
|
|
1611
1611
|
]
|
|
1612
1612
|
);
|
|
1613
|
-
}
|
|
1613
|
+
});
|
|
1614
|
+
const threadUpdate = t.none(
|
|
1615
|
+
`UPDATE ${this.getTableName(TABLE_THREADS)}
|
|
1616
|
+
SET "updatedAt" = $1
|
|
1617
|
+
WHERE id = $2`,
|
|
1618
|
+
[(/* @__PURE__ */ new Date()).toISOString(), threadId]
|
|
1619
|
+
);
|
|
1620
|
+
await Promise.all([...messageInserts, threadUpdate]);
|
|
1614
1621
|
});
|
|
1615
1622
|
const list = new MessageList().add(messages, "memory");
|
|
1616
1623
|
if (format === `v2`) return list.get.all.v2();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/pg",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0-alpha.1",
|
|
4
4
|
"description": "Postgres provider for Mastra - includes both vector and db storage capabilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -22,20 +22,20 @@
|
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"async-mutex": "^0.5.0",
|
|
24
24
|
"pg": "^8.16.0",
|
|
25
|
-
"pg-promise": "^11.
|
|
25
|
+
"pg-promise": "^11.14.0",
|
|
26
26
|
"xxhash-wasm": "^1.1.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@microsoft/api-extractor": "^7.52.8",
|
|
30
|
-
"@types/node": "^20.
|
|
30
|
+
"@types/node": "^20.19.0",
|
|
31
31
|
"@types/pg": "^8.15.4",
|
|
32
32
|
"eslint": "^9.28.0",
|
|
33
33
|
"tsup": "^8.5.0",
|
|
34
|
-
"typescript": "^5.8.
|
|
35
|
-
"vitest": "^3.2.
|
|
34
|
+
"typescript": "^5.8.3",
|
|
35
|
+
"vitest": "^3.2.3",
|
|
36
36
|
"@internal/lint": "0.0.12",
|
|
37
|
-
"@
|
|
38
|
-
"@
|
|
37
|
+
"@internal/storage-test-utils": "0.0.8",
|
|
38
|
+
"@mastra/core": "0.10.6-alpha.0"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"@mastra/core": ">=0.10.4-0 <0.11.0"
|
|
@@ -173,6 +173,28 @@ describe('PostgresStore', () => {
|
|
|
173
173
|
const retrievedMessages = await store.getMessages({ threadId: thread.id });
|
|
174
174
|
expect(retrievedMessages).toHaveLength(0);
|
|
175
175
|
});
|
|
176
|
+
|
|
177
|
+
it('should update thread updatedAt when a message is saved to it', async () => {
|
|
178
|
+
const thread = createSampleThread();
|
|
179
|
+
await store.saveThread({ thread });
|
|
180
|
+
|
|
181
|
+
// Get the initial thread to capture the original updatedAt
|
|
182
|
+
const initialThread = await store.getThreadById({ threadId: thread.id });
|
|
183
|
+
expect(initialThread).toBeDefined();
|
|
184
|
+
const originalUpdatedAt = initialThread!.updatedAt;
|
|
185
|
+
|
|
186
|
+
// Wait a small amount to ensure different timestamp
|
|
187
|
+
await new Promise(resolve => setTimeout(resolve, 10));
|
|
188
|
+
|
|
189
|
+
// Create and save a message to the thread
|
|
190
|
+
const message = createSampleMessageV1({ threadId: thread.id });
|
|
191
|
+
await store.saveMessages({ messages: [message] });
|
|
192
|
+
|
|
193
|
+
// Retrieve the thread again and check that updatedAt was updated
|
|
194
|
+
const updatedThread = await store.getThreadById({ threadId: thread.id });
|
|
195
|
+
expect(updatedThread).toBeDefined();
|
|
196
|
+
expect(updatedThread!.updatedAt.getTime()).toBeGreaterThan(originalUpdatedAt.getTime());
|
|
197
|
+
});
|
|
176
198
|
});
|
|
177
199
|
|
|
178
200
|
describe('Message Operations', () => {
|
package/src/storage/index.ts
CHANGED
|
@@ -904,7 +904,8 @@ export class PostgresStore extends MastraStorage {
|
|
|
904
904
|
}
|
|
905
905
|
|
|
906
906
|
await this.db.tx(async t => {
|
|
907
|
-
|
|
907
|
+
// Execute message inserts and thread update in parallel for better performance
|
|
908
|
+
const messageInserts = messages.map(message => {
|
|
908
909
|
if (!message.threadId) {
|
|
909
910
|
throw new Error(
|
|
910
911
|
`Expected to find a threadId for message, but couldn't find one. An unexpected error has occurred.`,
|
|
@@ -915,7 +916,7 @@ export class PostgresStore extends MastraStorage {
|
|
|
915
916
|
`Expected to find a resourceId for message, but couldn't find one. An unexpected error has occurred.`,
|
|
916
917
|
);
|
|
917
918
|
}
|
|
918
|
-
|
|
919
|
+
return t.none(
|
|
919
920
|
`INSERT INTO ${this.getTableName(TABLE_MESSAGES)} (id, thread_id, content, "createdAt", role, type, "resourceId")
|
|
920
921
|
VALUES ($1, $2, $3, $4, $5, $6, $7)`,
|
|
921
922
|
[
|
|
@@ -928,7 +929,16 @@ export class PostgresStore extends MastraStorage {
|
|
|
928
929
|
message.resourceId,
|
|
929
930
|
],
|
|
930
931
|
);
|
|
931
|
-
}
|
|
932
|
+
});
|
|
933
|
+
|
|
934
|
+
const threadUpdate = t.none(
|
|
935
|
+
`UPDATE ${this.getTableName(TABLE_THREADS)}
|
|
936
|
+
SET "updatedAt" = $1
|
|
937
|
+
WHERE id = $2`,
|
|
938
|
+
[new Date().toISOString(), threadId],
|
|
939
|
+
);
|
|
940
|
+
|
|
941
|
+
await Promise.all([...messageInserts, threadUpdate]);
|
|
932
942
|
});
|
|
933
943
|
|
|
934
944
|
const list = new MessageList().add(messages, 'memory');
|