@mastra/pg 0.11.1-alpha.0 → 0.11.1-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 +7 -7
- package/CHANGELOG.md +14 -0
- package/dist/_tsup-dts-rollup.d.cts +1 -0
- package/dist/_tsup-dts-rollup.d.ts +1 -0
- package/dist/index.cjs +714 -247
- package/dist/index.js +690 -223
- package/package.json +3 -3
- package/src/storage/index.test.ts +73 -34
- package/src/storage/index.ts +477 -192
- package/src/vector/index.ts +279 -86
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/pg",
|
|
3
|
-
"version": "0.11.1-alpha.
|
|
3
|
+
"version": "0.11.1-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",
|
|
@@ -33,9 +33,9 @@
|
|
|
33
33
|
"tsup": "^8.5.0",
|
|
34
34
|
"typescript": "^5.8.3",
|
|
35
35
|
"vitest": "^3.2.3",
|
|
36
|
-
"@internal/lint": "0.0.13",
|
|
37
36
|
"@internal/storage-test-utils": "0.0.9",
|
|
38
|
-
"@
|
|
37
|
+
"@internal/lint": "0.0.13",
|
|
38
|
+
"@mastra/core": "0.10.7-alpha.1"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"@mastra/core": ">=0.10.4-0 <0.11.0"
|
|
@@ -4,11 +4,12 @@ import {
|
|
|
4
4
|
createSampleTraceForDB,
|
|
5
5
|
createSampleThread,
|
|
6
6
|
createSampleMessageV1,
|
|
7
|
+
createSampleMessageV2,
|
|
7
8
|
createSampleWorkflowSnapshot,
|
|
8
9
|
resetRole,
|
|
9
10
|
checkWorkflowSnapshot,
|
|
10
11
|
} from '@internal/storage-test-utils';
|
|
11
|
-
import type {
|
|
12
|
+
import type { MastraMessageV2 } from '@mastra/core/agent';
|
|
12
13
|
import type { MastraMessageV1, StorageThreadType } from '@mastra/core/memory';
|
|
13
14
|
import type { StorageColumn, TABLE_NAMES } from '@mastra/core/storage';
|
|
14
15
|
import {
|
|
@@ -37,37 +38,6 @@ const connectionString = `postgresql://${TEST_CONFIG.user}:${TEST_CONFIG.passwor
|
|
|
37
38
|
|
|
38
39
|
vi.setConfig({ testTimeout: 60_000, hookTimeout: 60_000 });
|
|
39
40
|
|
|
40
|
-
const createSampleMessageV2 = ({
|
|
41
|
-
threadId,
|
|
42
|
-
resourceId,
|
|
43
|
-
role = 'user',
|
|
44
|
-
content,
|
|
45
|
-
createdAt,
|
|
46
|
-
thread,
|
|
47
|
-
}: {
|
|
48
|
-
threadId: string;
|
|
49
|
-
resourceId?: string;
|
|
50
|
-
role?: 'user' | 'assistant';
|
|
51
|
-
content?: Partial<MastraMessageContentV2>;
|
|
52
|
-
createdAt?: Date;
|
|
53
|
-
thread?: StorageThreadType;
|
|
54
|
-
}): MastraMessageV2 => {
|
|
55
|
-
return {
|
|
56
|
-
id: randomUUID(),
|
|
57
|
-
threadId,
|
|
58
|
-
resourceId: resourceId || thread?.resourceId || 'test-resource',
|
|
59
|
-
role,
|
|
60
|
-
createdAt: createdAt || new Date(),
|
|
61
|
-
content: {
|
|
62
|
-
format: 2,
|
|
63
|
-
parts: content?.parts || [{ type: 'text', text: content?.content ?? '' }],
|
|
64
|
-
content: content?.content || `Sample content ${randomUUID()}`,
|
|
65
|
-
...content,
|
|
66
|
-
},
|
|
67
|
-
type: 'v2',
|
|
68
|
-
};
|
|
69
|
-
};
|
|
70
|
-
|
|
71
41
|
describe('PostgresStore', () => {
|
|
72
42
|
let store: PostgresStore;
|
|
73
43
|
|
|
@@ -426,6 +396,75 @@ describe('PostgresStore', () => {
|
|
|
426
396
|
expect(crossThreadMessages3.filter(m => m.threadId === `thread-one`)).toHaveLength(3);
|
|
427
397
|
expect(crossThreadMessages3.filter(m => m.threadId === `thread-two`)).toHaveLength(0);
|
|
428
398
|
});
|
|
399
|
+
|
|
400
|
+
it('should return messages using both last and include (cross-thread, deduped)', async () => {
|
|
401
|
+
const thread = createSampleThread({ id: 'thread-one' });
|
|
402
|
+
await store.saveThread({ thread });
|
|
403
|
+
|
|
404
|
+
const thread2 = createSampleThread({ id: 'thread-two' });
|
|
405
|
+
await store.saveThread({ thread: thread2 });
|
|
406
|
+
|
|
407
|
+
const now = new Date();
|
|
408
|
+
|
|
409
|
+
// Setup: create messages in two threads
|
|
410
|
+
const messages = [
|
|
411
|
+
createSampleMessageV2({
|
|
412
|
+
threadId: 'thread-one',
|
|
413
|
+
content: { content: 'A' },
|
|
414
|
+
createdAt: new Date(now.getTime()),
|
|
415
|
+
}),
|
|
416
|
+
createSampleMessageV2({
|
|
417
|
+
threadId: 'thread-one',
|
|
418
|
+
content: { content: 'B' },
|
|
419
|
+
createdAt: new Date(now.getTime() + 1000),
|
|
420
|
+
}),
|
|
421
|
+
createSampleMessageV2({
|
|
422
|
+
threadId: 'thread-one',
|
|
423
|
+
content: { content: 'C' },
|
|
424
|
+
createdAt: new Date(now.getTime() + 2000),
|
|
425
|
+
}),
|
|
426
|
+
createSampleMessageV2({
|
|
427
|
+
threadId: 'thread-two',
|
|
428
|
+
content: { content: 'D' },
|
|
429
|
+
createdAt: new Date(now.getTime() + 3000),
|
|
430
|
+
}),
|
|
431
|
+
createSampleMessageV2({
|
|
432
|
+
threadId: 'thread-two',
|
|
433
|
+
content: { content: 'E' },
|
|
434
|
+
createdAt: new Date(now.getTime() + 4000),
|
|
435
|
+
}),
|
|
436
|
+
createSampleMessageV2({
|
|
437
|
+
threadId: 'thread-two',
|
|
438
|
+
content: { content: 'F' },
|
|
439
|
+
createdAt: new Date(now.getTime() + 5000),
|
|
440
|
+
}),
|
|
441
|
+
];
|
|
442
|
+
await store.saveMessages({ messages, format: 'v2' });
|
|
443
|
+
|
|
444
|
+
// Use last: 2 and include a message from another thread with context
|
|
445
|
+
const result = await store.getMessages({
|
|
446
|
+
threadId: 'thread-one',
|
|
447
|
+
format: 'v2',
|
|
448
|
+
selectBy: {
|
|
449
|
+
last: 2,
|
|
450
|
+
include: [
|
|
451
|
+
{
|
|
452
|
+
id: messages[4].id, // 'E' from thread-bar
|
|
453
|
+
threadId: 'thread-two',
|
|
454
|
+
withPreviousMessages: 1,
|
|
455
|
+
withNextMessages: 1,
|
|
456
|
+
},
|
|
457
|
+
],
|
|
458
|
+
},
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
// Should include last 2 from thread-one and 3 from thread-two (D, E, F)
|
|
462
|
+
expect(result.map(m => m.content.content).sort()).toEqual(['B', 'C', 'D', 'E', 'F']);
|
|
463
|
+
// Should include 2 from thread-one
|
|
464
|
+
expect(result.filter(m => m.threadId === 'thread-one').map(m => m.content.content)).toEqual(['B', 'C']);
|
|
465
|
+
// Should include 3 from thread-two
|
|
466
|
+
expect(result.filter(m => m.threadId === 'thread-two').map(m => m.content.content)).toEqual(['D', 'E', 'F']);
|
|
467
|
+
});
|
|
429
468
|
});
|
|
430
469
|
|
|
431
470
|
describe('updateMessages', () => {
|
|
@@ -1730,7 +1769,7 @@ describe('PostgresStore', () => {
|
|
|
1730
1769
|
record: { id: '1', name: 'Alice' },
|
|
1731
1770
|
});
|
|
1732
1771
|
|
|
1733
|
-
const row = await store.load({
|
|
1772
|
+
const row: any = await store.load({
|
|
1734
1773
|
tableName: camelCaseTable as TABLE_NAMES,
|
|
1735
1774
|
keys: { id: '1' },
|
|
1736
1775
|
});
|
|
@@ -1750,7 +1789,7 @@ describe('PostgresStore', () => {
|
|
|
1750
1789
|
record: { id: '2', name: 'Bob' },
|
|
1751
1790
|
});
|
|
1752
1791
|
|
|
1753
|
-
const row = await store.load({
|
|
1792
|
+
const row: any = await store.load({
|
|
1754
1793
|
tableName: snakeCaseTable as TABLE_NAMES,
|
|
1755
1794
|
keys: { id: '2' },
|
|
1756
1795
|
});
|