@mastra/pg 0.10.1-alpha.1 → 0.10.1-alpha.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.
@@ -1,23 +1,23 @@
1
1
 
2
- > @mastra/pg@0.10.1-alpha.1 build /home/runner/work/mastra/mastra/stores/pg
2
+ > @mastra/pg@0.10.1-alpha.2 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.4.0
8
8
  TSC Build start
9
- TSC ⚡️ Build success in 11415ms
9
+ TSC ⚡️ Build success in 10689ms
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 11422ms
16
+ DTS ⚡️ Build success in 11615ms
17
17
  CLI Cleaning output folder
18
18
  ESM Build start
19
19
  CJS Build start
20
- CJS dist/index.cjs 57.87 KB
21
- CJS ⚡️ Build success in 1565ms
22
- ESM dist/index.js 57.36 KB
23
- ESM ⚡️ Build success in 1566ms
20
+ CJS dist/index.cjs 58.05 KB
21
+ CJS ⚡️ Build success in 1169ms
22
+ ESM dist/index.js 57.55 KB
23
+ ESM ⚡️ Build success in 1169ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @mastra/pg
2
2
 
3
+ ## 0.10.1-alpha.2
4
+
5
+ ### Patch Changes
6
+
7
+ - c5bf1ce: Add backwards compat code for new MessageList in storage
8
+ - Updated dependencies [c5bf1ce]
9
+ - Updated dependencies [12b7002]
10
+ - @mastra/core@0.10.2-alpha.4
11
+
3
12
  ## 0.10.1-alpha.1
4
13
 
5
14
  ### Patch Changes
package/README.md CHANGED
@@ -20,7 +20,7 @@ npm install @mastra/pg
20
20
  ```typescript
21
21
  import { PgVector } from '@mastra/pg';
22
22
 
23
- const vectorStore = new PgVector('postgresql://user:pass@localhost:5432/db');
23
+ const vectorStore = new PgVector({ connectionString: 'postgresql://user:pass@localhost:5432/db' });
24
24
 
25
25
  // Create a new table with vector support
26
26
  await vectorStore.createIndex({
@@ -6,6 +6,7 @@ import type { DescribeIndexParams } from '@mastra/core/vector';
6
6
  import type { EvalRow } from '@mastra/core/storage';
7
7
  import type { IndexStats } from '@mastra/core/vector';
8
8
  import type { ISSLConfig } from 'pg-promise/typescript/pg-subset';
9
+ import type { MastraMessageV1 } from '@mastra/core/memory';
9
10
  import type { MastraMessageV2 } from '@mastra/core/agent';
10
11
  import { MastraStorage } from '@mastra/core/storage';
11
12
  import { MastraVector } from '@mastra/core/vector';
@@ -320,8 +321,13 @@ declare class PostgresStore extends MastraStorage {
320
321
  threadId: string;
321
322
  }): Promise<void>;
322
323
  getMessages<T = unknown>({ threadId, selectBy }: StorageGetMessagesArg): Promise<T[]>;
323
- saveMessages({ messages }: {
324
+ saveMessages(args: {
325
+ messages: MastraMessageV1[];
326
+ format?: undefined | 'v1';
327
+ }): Promise<MastraMessageV1[]>;
328
+ saveMessages(args: {
324
329
  messages: MastraMessageV2[];
330
+ format: 'v2';
325
331
  }): Promise<MastraMessageV2[]>;
326
332
  persistWorkflowSnapshot({ workflowName, runId, snapshot, }: {
327
333
  workflowName: string;
@@ -6,6 +6,7 @@ import type { DescribeIndexParams } from '@mastra/core/vector';
6
6
  import type { EvalRow } from '@mastra/core/storage';
7
7
  import type { IndexStats } from '@mastra/core/vector';
8
8
  import type { ISSLConfig } from 'pg-promise/typescript/pg-subset';
9
+ import type { MastraMessageV1 } from '@mastra/core/memory';
9
10
  import type { MastraMessageV2 } from '@mastra/core/agent';
10
11
  import { MastraStorage } from '@mastra/core/storage';
11
12
  import { MastraVector } from '@mastra/core/vector';
@@ -320,8 +321,13 @@ declare class PostgresStore extends MastraStorage {
320
321
  threadId: string;
321
322
  }): Promise<void>;
322
323
  getMessages<T = unknown>({ threadId, selectBy }: StorageGetMessagesArg): Promise<T[]>;
323
- saveMessages({ messages }: {
324
+ saveMessages(args: {
325
+ messages: MastraMessageV1[];
326
+ format?: undefined | 'v1';
327
+ }): Promise<MastraMessageV1[]>;
328
+ saveMessages(args: {
324
329
  messages: MastraMessageV2[];
330
+ format: 'v2';
325
331
  }): Promise<MastraMessageV2[]>;
326
332
  persistWorkflowSnapshot({ workflowName, runId, snapshot, }: {
327
333
  workflowName: string;
package/dist/index.cjs CHANGED
@@ -6,6 +6,7 @@ var asyncMutex = require('async-mutex');
6
6
  var pg = require('pg');
7
7
  var xxhash = require('xxhash-wasm');
8
8
  var filter = require('@mastra/core/vector/filter');
9
+ var agent = require('@mastra/core/agent');
9
10
  var storage = require('@mastra/core/storage');
10
11
  var pgPromise = require('pg-promise');
11
12
 
@@ -1418,7 +1419,10 @@ var PostgresStore = class extends storage.MastraStorage {
1418
1419
  throw error;
1419
1420
  }
1420
1421
  }
1421
- async saveMessages({ messages }) {
1422
+ async saveMessages({
1423
+ messages,
1424
+ format
1425
+ }) {
1422
1426
  if (messages.length === 0) return messages;
1423
1427
  try {
1424
1428
  const threadId = messages[0]?.threadId;
@@ -1445,7 +1449,9 @@ var PostgresStore = class extends storage.MastraStorage {
1445
1449
  );
1446
1450
  }
1447
1451
  });
1448
- return messages;
1452
+ const list = new agent.MessageList().add(messages, "memory");
1453
+ if (format === `v2`) return list.get.all.v2();
1454
+ return list.get.all.v1();
1449
1455
  } catch (error) {
1450
1456
  console.error("Error saving messages:", error);
1451
1457
  throw error;
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ import { Mutex } from 'async-mutex';
4
4
  import pg from 'pg';
5
5
  import xxhash from 'xxhash-wasm';
6
6
  import { BaseFilterTranslator } from '@mastra/core/vector/filter';
7
+ import { MessageList } from '@mastra/core/agent';
7
8
  import { MastraStorage, TABLE_EVALS, TABLE_TRACES, TABLE_WORKFLOW_SNAPSHOT, TABLE_THREADS, TABLE_MESSAGES } from '@mastra/core/storage';
8
9
  import pgPromise from 'pg-promise';
9
10
 
@@ -1410,7 +1411,10 @@ var PostgresStore = class extends MastraStorage {
1410
1411
  throw error;
1411
1412
  }
1412
1413
  }
1413
- async saveMessages({ messages }) {
1414
+ async saveMessages({
1415
+ messages,
1416
+ format
1417
+ }) {
1414
1418
  if (messages.length === 0) return messages;
1415
1419
  try {
1416
1420
  const threadId = messages[0]?.threadId;
@@ -1437,7 +1441,9 @@ var PostgresStore = class extends MastraStorage {
1437
1441
  );
1438
1442
  }
1439
1443
  });
1440
- return messages;
1444
+ const list = new MessageList().add(messages, "memory");
1445
+ if (format === `v2`) return list.get.all.v2();
1446
+ return list.get.all.v1();
1441
1447
  } catch (error) {
1442
1448
  console.error("Error saving messages:", error);
1443
1449
  throw error;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/pg",
3
- "version": "0.10.1-alpha.1",
3
+ "version": "0.10.1-alpha.2",
4
4
  "description": "Postgres provider for Mastra - includes both vector and db storage capabilities",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -33,8 +33,8 @@
33
33
  "tsup": "^8.4.0",
34
34
  "typescript": "^5.8.2",
35
35
  "vitest": "^3.1.2",
36
- "@mastra/core": "0.10.2-alpha.2",
37
- "@internal/lint": "0.0.7"
36
+ "@internal/lint": "0.0.7",
37
+ "@mastra/core": "0.10.2-alpha.4"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "@mastra/core": "^0.10.0-alpha.0"
@@ -1,6 +1,6 @@
1
1
  import { randomUUID } from 'crypto';
2
2
  import type { MetricResult } from '@mastra/core/eval';
3
- import type { MessageType } from '@mastra/core/memory';
3
+ import type { MastraMessageV1 } from '@mastra/core/memory';
4
4
  import { TABLE_WORKFLOW_SNAPSHOT, TABLE_MESSAGES, TABLE_THREADS, TABLE_EVALS } from '@mastra/core/storage';
5
5
  import type { WorkflowRunState } from '@mastra/core/workflows';
6
6
  import pgPromise from 'pg-promise';
@@ -31,10 +31,16 @@ const createSampleThread = () => ({
31
31
  metadata: { key: 'value' },
32
32
  });
33
33
 
34
- const createSampleMessage = (threadId: string): MessageType => ({
34
+ let role: 'user' | 'assistant' = 'assistant';
35
+ const getRole = () => {
36
+ if (role === `user`) role = `assistant`;
37
+ else role = `user`;
38
+ return role;
39
+ };
40
+ const createSampleMessage = (threadId: string): MastraMessageV1 => ({
35
41
  id: `msg-${randomUUID()}`,
36
42
  resourceId: `resource-${randomUUID()}`,
37
- role: 'user',
43
+ role: getRole(),
38
44
  type: 'text',
39
45
  threadId,
40
46
  content: [{ type: 'text', text: 'Hello' }],
@@ -58,6 +64,7 @@ const createSampleWorkflowSnapshot = (status: WorkflowRunState['context'][string
58
64
  },
59
65
  input: {},
60
66
  },
67
+ serializedStepGraph: [],
61
68
  activePaths: [],
62
69
  suspendedPaths: {},
63
70
  runId,
@@ -259,14 +266,17 @@ describe('PostgresStore', () => {
259
266
  await store.saveThread({ thread });
260
267
 
261
268
  const messages = [
262
- { ...createSampleMessage(thread.id), content: [{ type: 'text', text: 'First' }] as MessageType['content'] },
263
- { ...createSampleMessage(thread.id), content: [{ type: 'text', text: 'Second' }] as MessageType['content'] },
264
- { ...createSampleMessage(thread.id), content: [{ type: 'text', text: 'Third' }] as MessageType['content'] },
265
- ];
269
+ { ...createSampleMessage(thread.id), content: [{ type: 'text', text: 'First' }] },
270
+ {
271
+ ...createSampleMessage(thread.id),
272
+ content: [{ type: 'text', text: 'Second' }],
273
+ },
274
+ { ...createSampleMessage(thread.id), content: [{ type: 'text', text: 'Third' }] },
275
+ ] satisfies MastraMessageV1[];
266
276
 
267
277
  await store.saveMessages({ messages });
268
278
 
269
- const retrievedMessages = await store.getMessages<MessageType>({ threadId: thread.id });
279
+ const retrievedMessages = await store.getMessages<MastraMessageV1>({ threadId: thread.id });
270
280
  expect(retrievedMessages).toHaveLength(3);
271
281
 
272
282
  // Verify order is maintained
@@ -1,6 +1,7 @@
1
+ import { MessageList } from '@mastra/core/agent';
1
2
  import type { MastraMessageV2 } from '@mastra/core/agent';
2
3
  import type { MetricResult } from '@mastra/core/eval';
3
- import type { StorageThreadType } from '@mastra/core/memory';
4
+ import type { MastraMessageV1, StorageThreadType } from '@mastra/core/memory';
4
5
  import {
5
6
  MastraStorage,
6
7
  TABLE_MESSAGES,
@@ -677,7 +678,14 @@ export class PostgresStore extends MastraStorage {
677
678
  }
678
679
  }
679
680
 
680
- async saveMessages({ messages }: { messages: MastraMessageV2[] }): Promise<MastraMessageV2[]> {
681
+ async saveMessages(args: { messages: MastraMessageV1[]; format?: undefined | 'v1' }): Promise<MastraMessageV1[]>;
682
+ async saveMessages(args: { messages: MastraMessageV2[]; format: 'v2' }): Promise<MastraMessageV2[]>;
683
+ async saveMessages({
684
+ messages,
685
+ format,
686
+ }:
687
+ | { messages: MastraMessageV1[]; format?: undefined | 'v1' }
688
+ | { messages: MastraMessageV2[]; format: 'v2' }): Promise<MastraMessageV2[] | MastraMessageV1[]> {
681
689
  if (messages.length === 0) return messages;
682
690
 
683
691
  try {
@@ -709,7 +717,9 @@ export class PostgresStore extends MastraStorage {
709
717
  }
710
718
  });
711
719
 
712
- return messages;
720
+ const list = new MessageList().add(messages, 'memory');
721
+ if (format === `v2`) return list.get.all.v2();
722
+ return list.get.all.v1();
713
723
  } catch (error) {
714
724
  console.error('Error saving messages:', error);
715
725
  throw error;