@mastra/pg 0.10.4-alpha.0 → 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.
@@ -1,23 +1,23 @@
1
1
 
2
- > @mastra/pg@0.10.4-alpha.0 build /home/runner/work/mastra/mastra/stores/pg
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
  CLI Building entry: src/index.ts
6
6
  CLI Using tsconfig: tsconfig.json
7
7
  CLI tsup v8.5.0
8
8
  TSC Build start
9
- TSC ⚡️ Build success in 11001ms
9
+ TSC ⚡️ Build success in 10371ms
10
10
  DTS Build start
11
11
  CLI Target: es2022
12
12
  Analysis will use the bundled TypeScript version 5.8.3
13
13
  Writing package typings: /home/runner/work/mastra/mastra/stores/pg/dist/_tsup-dts-rollup.d.ts
14
14
  Analysis will use the bundled TypeScript version 5.8.3
15
15
  Writing package typings: /home/runner/work/mastra/mastra/stores/pg/dist/_tsup-dts-rollup.d.cts
16
- DTS ⚡️ Build success in 11284ms
16
+ DTS ⚡️ Build success in 11657ms
17
17
  CLI Cleaning output folder
18
18
  ESM Build start
19
19
  CJS Build start
20
- ESM dist/index.js 67.19 KB
21
- ESM ⚡️ Build success in 1382ms
22
- CJS dist/index.cjs 67.75 KB
23
- CJS ⚡️ Build success in 1382ms
20
+ CJS dist/index.cjs 68.06 KB
21
+ CJS ⚡️ Build success in 1500ms
22
+ ESM dist/index.js 67.49 KB
23
+ ESM ⚡️ Build success in 1504ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
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
+
3
16
  ## 0.10.4-alpha.0
4
17
 
5
18
  ### 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
- for (const message of messages) {
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
- await t.none(
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
- for (const message of messages) {
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
- await t.none(
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.10.4-alpha.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",
@@ -34,8 +34,8 @@
34
34
  "typescript": "^5.8.3",
35
35
  "vitest": "^3.2.3",
36
36
  "@internal/lint": "0.0.12",
37
- "@mastra/core": "0.10.6-alpha.0",
38
- "@internal/storage-test-utils": "0.0.8"
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', () => {
@@ -904,7 +904,8 @@ export class PostgresStore extends MastraStorage {
904
904
  }
905
905
 
906
906
  await this.db.tx(async t => {
907
- for (const message of messages) {
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
- await t.none(
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');