@mastra/pg 0.10.1-alpha.1 → 0.10.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 +7 -7
- package/CHANGELOG.md +35 -0
- package/README.md +1 -1
- package/dist/_tsup-dts-rollup.d.cts +7 -1
- package/dist/_tsup-dts-rollup.d.ts +7 -1
- package/dist/index.cjs +8 -2
- package/dist/index.js +8 -2
- package/package.json +4 -4
- package/src/storage/index.test.ts +18 -8
- package/src/storage/index.ts +13 -3
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/pg@0.10.1-alpha.
|
|
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
|
[34mCLI[39m Building entry: src/index.ts
|
|
6
6
|
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
7
|
[34mCLI[39m tsup v8.4.0
|
|
8
8
|
[34mTSC[39m Build start
|
|
9
|
-
[32mTSC[39m ⚡️ Build success in
|
|
9
|
+
[32mTSC[39m ⚡️ Build success in 8555ms
|
|
10
10
|
[34mDTS[39m Build start
|
|
11
11
|
[34mCLI[39m Target: es2022
|
|
12
12
|
Analysis will use the bundled TypeScript version 5.8.3
|
|
13
13
|
[36mWriting package typings: /home/runner/work/mastra/mastra/stores/pg/dist/_tsup-dts-rollup.d.ts[39m
|
|
14
14
|
Analysis will use the bundled TypeScript version 5.8.3
|
|
15
15
|
[36mWriting package typings: /home/runner/work/mastra/mastra/stores/pg/dist/_tsup-dts-rollup.d.cts[39m
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 11494ms
|
|
17
17
|
[34mCLI[39m Cleaning output folder
|
|
18
18
|
[34mESM[39m Build start
|
|
19
19
|
[34mCJS[39m Build start
|
|
20
|
-
[
|
|
21
|
-
[
|
|
22
|
-
[
|
|
23
|
-
[
|
|
20
|
+
[32mESM[39m [1mdist/index.js [22m[32m57.55 KB[39m
|
|
21
|
+
[32mESM[39m ⚡️ Build success in 996ms
|
|
22
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m58.05 KB[39m
|
|
23
|
+
[32mCJS[39m ⚡️ Build success in 1541ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,40 @@
|
|
|
1
1
|
# @mastra/pg
|
|
2
2
|
|
|
3
|
+
## 0.10.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- e5dc18d: Added a backwards compatible layer to begin storing/retrieving UIMessages in storage instead of CoreMessages
|
|
8
|
+
- c5bf1ce: Add backwards compat code for new MessageList in storage
|
|
9
|
+
- f0d559f: Fix peerdeps for alpha channel
|
|
10
|
+
- Updated dependencies [ee77e78]
|
|
11
|
+
- Updated dependencies [592a2db]
|
|
12
|
+
- Updated dependencies [e5dc18d]
|
|
13
|
+
- Updated dependencies [ab5adbe]
|
|
14
|
+
- Updated dependencies [1e8bb40]
|
|
15
|
+
- Updated dependencies [1b5fc55]
|
|
16
|
+
- Updated dependencies [195c428]
|
|
17
|
+
- Updated dependencies [f73e11b]
|
|
18
|
+
- Updated dependencies [37643b8]
|
|
19
|
+
- Updated dependencies [99fd6cf]
|
|
20
|
+
- Updated dependencies [c5bf1ce]
|
|
21
|
+
- Updated dependencies [add596e]
|
|
22
|
+
- Updated dependencies [8dc94d8]
|
|
23
|
+
- Updated dependencies [ecebbeb]
|
|
24
|
+
- Updated dependencies [79d5145]
|
|
25
|
+
- Updated dependencies [12b7002]
|
|
26
|
+
- Updated dependencies [2901125]
|
|
27
|
+
- @mastra/core@0.10.2
|
|
28
|
+
|
|
29
|
+
## 0.10.1-alpha.2
|
|
30
|
+
|
|
31
|
+
### Patch Changes
|
|
32
|
+
|
|
33
|
+
- c5bf1ce: Add backwards compat code for new MessageList in storage
|
|
34
|
+
- Updated dependencies [c5bf1ce]
|
|
35
|
+
- Updated dependencies [12b7002]
|
|
36
|
+
- @mastra/core@0.10.2-alpha.4
|
|
37
|
+
|
|
3
38
|
## 0.10.1-alpha.1
|
|
4
39
|
|
|
5
40
|
### 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(
|
|
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(
|
|
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({
|
|
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
|
-
|
|
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({
|
|
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
|
-
|
|
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
|
|
3
|
+
"version": "0.10.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",
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
"tsup": "^8.4.0",
|
|
34
34
|
"typescript": "^5.8.2",
|
|
35
35
|
"vitest": "^3.1.2",
|
|
36
|
-
"@
|
|
37
|
-
"@
|
|
36
|
+
"@internal/lint": "0.0.8",
|
|
37
|
+
"@mastra/core": "0.10.2"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"@mastra/core": "^0.10.
|
|
40
|
+
"@mastra/core": "^0.10.2-alpha.0"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
43
|
"build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { randomUUID } from 'crypto';
|
|
2
2
|
import type { MetricResult } from '@mastra/core/eval';
|
|
3
|
-
import type {
|
|
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
|
-
|
|
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:
|
|
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' }]
|
|
263
|
-
{
|
|
264
|
-
|
|
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<
|
|
279
|
+
const retrievedMessages = await store.getMessages<MastraMessageV1>({ threadId: thread.id });
|
|
270
280
|
expect(retrievedMessages).toHaveLength(3);
|
|
271
281
|
|
|
272
282
|
// Verify order is maintained
|
package/src/storage/index.ts
CHANGED
|
@@ -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(
|
|
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
|
-
|
|
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;
|