@mastra/pg 0.13.0 → 0.13.1-alpha.0

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.
Files changed (50) hide show
  1. package/.turbo/turbo-build.log +2 -21
  2. package/CHANGELOG.md +11 -0
  3. package/dist/index.cjs +29 -17
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.d.ts +4 -5
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.js +29 -17
  8. package/dist/index.js.map +1 -0
  9. package/dist/storage/domains/legacy-evals/index.d.ts +20 -0
  10. package/dist/storage/domains/legacy-evals/index.d.ts.map +1 -0
  11. package/dist/storage/domains/memory/index.d.ts +88 -0
  12. package/dist/storage/domains/memory/index.d.ts.map +1 -0
  13. package/dist/storage/domains/operations/index.d.ts +50 -0
  14. package/dist/storage/domains/operations/index.d.ts.map +1 -0
  15. package/dist/storage/domains/scores/index.d.ts +44 -0
  16. package/dist/storage/domains/scores/index.d.ts.map +1 -0
  17. package/dist/storage/domains/traces/index.d.ts +23 -0
  18. package/dist/storage/domains/traces/index.d.ts.map +1 -0
  19. package/dist/storage/domains/utils.d.ts +6 -0
  20. package/dist/storage/domains/utils.d.ts.map +1 -0
  21. package/dist/storage/domains/workflows/index.d.ts +36 -0
  22. package/dist/storage/domains/workflows/index.d.ts.map +1 -0
  23. package/dist/storage/index.d.ts +211 -0
  24. package/dist/storage/index.d.ts.map +1 -0
  25. package/dist/storage/test-utils.d.ts +5 -0
  26. package/dist/storage/test-utils.d.ts.map +1 -0
  27. package/dist/vector/filter.d.ts +32 -0
  28. package/dist/vector/filter.d.ts.map +1 -0
  29. package/dist/vector/index.d.ts +99 -0
  30. package/dist/vector/index.d.ts.map +1 -0
  31. package/dist/vector/performance.helpers.d.ts +95 -0
  32. package/dist/vector/performance.helpers.d.ts.map +1 -0
  33. package/dist/vector/prompt.d.ts +6 -0
  34. package/dist/vector/prompt.d.ts.map +1 -0
  35. package/dist/vector/sql-builder.d.ts +8 -0
  36. package/dist/vector/sql-builder.d.ts.map +1 -0
  37. package/dist/vector/types.d.ts +15 -0
  38. package/dist/vector/types.d.ts.map +1 -0
  39. package/package.json +3 -3
  40. package/src/storage/domains/operations/index.ts +5 -3
  41. package/src/storage/domains/scores/index.ts +22 -8
  42. package/src/storage/domains/workflows/index.ts +5 -5
  43. package/src/storage/index.test.ts +1 -0
  44. package/src/storage/index.ts +1 -1
  45. package/tsconfig.build.json +9 -0
  46. package/tsconfig.json +1 -1
  47. package/tsup.config.ts +22 -0
  48. package/dist/_tsup-dts-rollup.d.cts +0 -786
  49. package/dist/_tsup-dts-rollup.d.ts +0 -786
  50. package/dist/index.d.cts +0 -5
@@ -0,0 +1,88 @@
1
+ import type { MastraMessageContentV2 } from '@mastra/core/agent';
2
+ import type { MastraMessageV1, MastraMessageV2, StorageThreadType } from '@mastra/core/memory';
3
+ import { MemoryStorage } from '@mastra/core/storage';
4
+ import type { StorageGetMessagesArg, PaginationInfo, StorageResourceType, ThreadSortOptions } from '@mastra/core/storage';
5
+ import type { IDatabase } from 'pg-promise';
6
+ import type { StoreOperationsPG } from '../operations';
7
+ export declare class MemoryPG extends MemoryStorage {
8
+ private client;
9
+ private schema;
10
+ private operations;
11
+ constructor({ client, schema, operations, }: {
12
+ client: IDatabase<{}>;
13
+ schema: string;
14
+ operations: StoreOperationsPG;
15
+ });
16
+ getThreadById({ threadId }: {
17
+ threadId: string;
18
+ }): Promise<StorageThreadType | null>;
19
+ /**
20
+ * @deprecated use getThreadsByResourceIdPaginated instead
21
+ */
22
+ getThreadsByResourceId(args: {
23
+ resourceId: string;
24
+ } & ThreadSortOptions): Promise<StorageThreadType[]>;
25
+ getThreadsByResourceIdPaginated(args: {
26
+ resourceId: string;
27
+ page: number;
28
+ perPage: number;
29
+ } & ThreadSortOptions): Promise<PaginationInfo & {
30
+ threads: StorageThreadType[];
31
+ }>;
32
+ saveThread({ thread }: {
33
+ thread: StorageThreadType;
34
+ }): Promise<StorageThreadType>;
35
+ updateThread({ id, title, metadata, }: {
36
+ id: string;
37
+ title: string;
38
+ metadata: Record<string, unknown>;
39
+ }): Promise<StorageThreadType>;
40
+ deleteThread({ threadId }: {
41
+ threadId: string;
42
+ }): Promise<void>;
43
+ private _getIncludedMessages;
44
+ /**
45
+ * @deprecated use getMessagesPaginated instead
46
+ */
47
+ getMessages(args: StorageGetMessagesArg & {
48
+ format?: 'v1';
49
+ }): Promise<MastraMessageV1[]>;
50
+ getMessages(args: StorageGetMessagesArg & {
51
+ format: 'v2';
52
+ }): Promise<MastraMessageV2[]>;
53
+ getMessagesPaginated(args: StorageGetMessagesArg & {
54
+ format?: 'v1' | 'v2';
55
+ }): Promise<PaginationInfo & {
56
+ messages: MastraMessageV1[] | MastraMessageV2[];
57
+ }>;
58
+ saveMessages(args: {
59
+ messages: MastraMessageV1[];
60
+ format?: undefined | 'v1';
61
+ }): Promise<MastraMessageV1[]>;
62
+ saveMessages(args: {
63
+ messages: MastraMessageV2[];
64
+ format: 'v2';
65
+ }): Promise<MastraMessageV2[]>;
66
+ updateMessages({ messages, }: {
67
+ messages: (Partial<Omit<MastraMessageV2, 'createdAt'>> & {
68
+ id: string;
69
+ content?: {
70
+ metadata?: MastraMessageContentV2['metadata'];
71
+ content?: MastraMessageContentV2['content'];
72
+ };
73
+ })[];
74
+ }): Promise<MastraMessageV2[]>;
75
+ deleteMessages(messageIds: string[]): Promise<void>;
76
+ getResourceById({ resourceId }: {
77
+ resourceId: string;
78
+ }): Promise<StorageResourceType | null>;
79
+ saveResource({ resource }: {
80
+ resource: StorageResourceType;
81
+ }): Promise<StorageResourceType>;
82
+ updateResource({ resourceId, workingMemory, metadata, }: {
83
+ resourceId: string;
84
+ workingMemory?: string;
85
+ metadata?: Record<string, unknown>;
86
+ }): Promise<StorageResourceType>;
87
+ }
88
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/memory/index.ts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EAAE;QACD,QAAQ,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,eAAe,EAAE,WAAW,CAAC,CAAC,GAAG;YACvD,EAAE,EAAE,MAAM,CAAC;YACX,OAAO,CAAC,EAAE;gBACR,QAAQ,CAAC,EAAE,sBAAsB,CAAC,UAAU,CAAC,CAAC;gBAC9C,OAAO,CAAC,EAAE,sBAAsB,CAAC,SAAS,CAAC,CAAC;aAC7C,CAAC;SACH,CAAC,EAAE,CAAC;KACN,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;IAqHxB,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IA6CnD,eAAe,CAAC,EAAE,UAAU,EAAE,EAAE;QAAE,UAAU,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC;IAoB5F,YAAY,CAAC,EAAE,QAAQ,EAAE,EAAE;QAAE,QAAQ,EAAE,mBAAmB,CAAA;KAAE,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAY3F,cAAc,CAAC,EACnB,UAAU,EACV,aAAa,EACb,QAAQ,GACT,EAAE;QACD,UAAU,EAAE,MAAM,CAAC;QACnB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACpC,GAAG,OAAO,CAAC,mBAAmB,CAAC;CAwDjC"}
@@ -0,0 +1,50 @@
1
+ import { StoreOperations } from '@mastra/core/storage';
2
+ import type { StorageColumn, TABLE_NAMES } from '@mastra/core/storage';
3
+ import type { IDatabase } from 'pg-promise';
4
+ export declare class StoreOperationsPG extends StoreOperations {
5
+ client: IDatabase<{}>;
6
+ schemaName?: string;
7
+ private setupSchemaPromise;
8
+ private schemaSetupComplete;
9
+ constructor({ client, schemaName }: {
10
+ client: IDatabase<{}>;
11
+ schemaName?: string;
12
+ });
13
+ hasColumn(table: string, column: string): Promise<boolean>;
14
+ private setupSchema;
15
+ insert({ tableName, record }: {
16
+ tableName: TABLE_NAMES;
17
+ record: Record<string, any>;
18
+ }): Promise<void>;
19
+ clearTable({ tableName }: {
20
+ tableName: TABLE_NAMES;
21
+ }): Promise<void>;
22
+ protected getDefaultValue(type: StorageColumn['type']): string;
23
+ createTable({ tableName, schema, }: {
24
+ tableName: TABLE_NAMES;
25
+ schema: Record<string, StorageColumn>;
26
+ }): Promise<void>;
27
+ /**
28
+ * Alters table schema to add columns if they don't exist
29
+ * @param tableName Name of the table
30
+ * @param schema Schema of the table
31
+ * @param ifNotExists Array of column names to add if they don't exist
32
+ */
33
+ alterTable({ tableName, schema, ifNotExists, }: {
34
+ tableName: TABLE_NAMES;
35
+ schema: Record<string, StorageColumn>;
36
+ ifNotExists: string[];
37
+ }): Promise<void>;
38
+ load<R>({ tableName, keys }: {
39
+ tableName: TABLE_NAMES;
40
+ keys: Record<string, string>;
41
+ }): Promise<R | null>;
42
+ batchInsert({ tableName, records }: {
43
+ tableName: TABLE_NAMES;
44
+ records: Record<string, any>[];
45
+ }): Promise<void>;
46
+ dropTable({ tableName }: {
47
+ tableName: TABLE_NAMES;
48
+ }): Promise<void>;
49
+ }
50
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/operations/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAA2B,MAAM,sBAAsB,CAAC;AAChF,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEvE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAG5C,qBAAa,iBAAkB,SAAQ,eAAe;IAC7C,MAAM,EAAE,SAAS,CAAC,EAAE,CAAC,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IAC3B,OAAO,CAAC,kBAAkB,CAA8B;IACxD,OAAO,CAAC,mBAAmB,CAAkC;g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CAAC;IAwCzG,WAAW,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE;QAAE,SAAS,EAAE,WAAW,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAwB9G,SAAS,CAAC,EAAE,SAAS,EAAE,EAAE;QAAE,SAAS,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAmB1E"}
@@ -0,0 +1,44 @@
1
+ import type { PaginationInfo, StoragePagination } from '@mastra/core';
2
+ import type { ScoreRowData } from '@mastra/core/scores';
3
+ import { ScoresStorage } from '@mastra/core/storage';
4
+ import type { IDatabase } from 'pg-promise';
5
+ import type { StoreOperationsPG } from '../operations';
6
+ export declare class ScoresPG extends ScoresStorage {
7
+ client: IDatabase<{}>;
8
+ private operations;
9
+ private schema?;
10
+ constructor({ client, operations, schema, }: {
11
+ client: IDatabase<{}>;
12
+ operations: StoreOperationsPG;
13
+ schema?: string;
14
+ });
15
+ getScoreById({ id }: {
16
+ id: string;
17
+ }): Promise<ScoreRowData | null>;
18
+ getScoresByScorerId({ scorerId, pagination, }: {
19
+ scorerId: string;
20
+ pagination: StoragePagination;
21
+ }): Promise<{
22
+ pagination: PaginationInfo;
23
+ scores: ScoreRowData[];
24
+ }>;
25
+ saveScore(score: Omit<ScoreRowData, 'createdAt' | 'updatedAt'>): Promise<{
26
+ score: ScoreRowData;
27
+ }>;
28
+ getScoresByRunId({ runId, pagination, }: {
29
+ runId: string;
30
+ pagination: StoragePagination;
31
+ }): Promise<{
32
+ pagination: PaginationInfo;
33
+ scores: ScoreRowData[];
34
+ }>;
35
+ getScoresByEntityId({ entityId, entityType, pagination, }: {
36
+ pagination: StoragePagination;
37
+ entityId: string;
38
+ entityType: string;
39
+ }): Promise<{
40
+ pagination: PaginationInfo;
41
+ scores: ScoreRowData[];
42
+ }>;
43
+ }
44
+ //# sourceMappingURL=index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rB,KAAK,EACL,UAAU,GACX,EAAE;QACD,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,EAAE,iBAAiB,CAAC;KAC/B,GAAG,OAAO,CAAC;QAAE,UAAU,EAAE,cAAc,CAAC;QAAC,MAAM,EAAE,YAAY,EAAE,CAAA;KAAE,CAAC;IA6C7D,mBAAmB,CAAC,EACxB,QAAQ,EACR,UAAU,EACV,UAAU,GACX,EAAE;QACD,UAAU,EAAE,iBAAiB,CAAC;QAC9B,QAAQ,EAAE,MAAM,CAAC;QACjB,UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC;QAAE,UAAU,EAAE,cAAc,CAAC;QAAC,MAAM,EAAE,YAAY,EAAE,CAAA;KAAE,CAAC;CA2CpE"}
@@ -0,0 +1,23 @@
1
+ import type { PaginationInfo, StorageGetTracesArg, StorageGetTracesPaginatedArg } from '@mastra/core/storage';
2
+ import { TracesStorage } from '@mastra/core/storage';
3
+ import type { Trace } from '@mastra/core/telemetry';
4
+ import type { IDatabase } from 'pg-promise';
5
+ import type { StoreOperationsPG } from '../operations';
6
+ export declare class TracesPG extends TracesStorage {
7
+ client: IDatabase<{}>;
8
+ private operations;
9
+ private schema?;
10
+ constructor({ client, operations, schema, }: {
11
+ client: IDatabase<{}>;
12
+ operations: StoreOperationsPG;
13
+ schema?: string;
14
+ });
15
+ getTraces(args: StorageGetTracesArg): Promise<Trace[]>;
16
+ getTracesPaginated(args: StorageGetTracesPaginatedArg): Promise<PaginationInfo & {
17
+ traces: Trace[];
18
+ }>;
19
+ batchTraceInsert({ records }: {
20
+ records: Record<string, any>[];
21
+ }): Promise<void>;
22
+ }
23
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/traces/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,4BAA4B,EAAE,MAAM,sBAAsB,CAAC;AAC9G,OAAO,EAAgB,aAAa,EAAmB,MAAM,sBAAsB,CAAC;AACpF,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAEpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAGvD,qBAAa,QAAS,SAAQ,aAAa;IAClC,MAAM,EAAE,SAAS,CAAC,EAAE,CAAC,CAAC;IAC7B,OAAO,CAAC,UAAU,CAAoB;IACtC,OAAO,CAAC,MAAM,CAAC,CAAS;gBAEZ,EACV,MAAM,EACN,UAAU,EACV,MAAM,GACP,EAAE;QACD,MAAM,EAAE,SAAS,CAAC,EAAE,CAAC,CAAC;QACtB,UAAU,EAAE,iBAAiB,CAAC;QAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB;IAOK,SAAS,CAAC,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;IAsBtD,kBAAkB,CAAC,IAAI,EAAE,4BAA4B,GAAG,OAAO,CAAC,cAAc,GAAG;QAAE,MAAM,EAAE,KAAK,EAAE,CAAA;KAAE,CAAC;IAqGrG,gBAAgB,CAAC,EAAE,OAAO,EAAE,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAOvF"}
@@ -0,0 +1,6 @@
1
+ export declare function getSchemaName(schema?: string): string | undefined;
2
+ export declare function getTableName({ indexName, schemaName }: {
3
+ indexName: string;
4
+ schemaName?: string;
5
+ }): string;
6
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/storage/domains/utils.ts"],"names":[],"mappings":"AAEA,wBAAgB,aAAa,CAAC,MAAM,CAAC,EAAE,MAAM,sBAE5C;AAED,wBAAgB,YAAY,CAAC,EAAE,SAAS,EAAE,UAAU,EAAE,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,UAKjG"}
@@ -0,0 +1,36 @@
1
+ import type { WorkflowRun, WorkflowRuns, WorkflowRunState } from '@mastra/core';
2
+ import { WorkflowsStorage } from '@mastra/core/storage';
3
+ import type { IDatabase } from 'pg-promise';
4
+ import type { StoreOperationsPG } from '../operations';
5
+ export declare class WorkflowsPG extends WorkflowsStorage {
6
+ client: IDatabase<{}>;
7
+ private operations;
8
+ private schema;
9
+ constructor({ client, operations, schema, }: {
10
+ client: IDatabase<{}>;
11
+ operations: StoreOperationsPG;
12
+ schema: string;
13
+ });
14
+ persistWorkflowSnapshot({ workflowName, runId, snapshot, }: {
15
+ workflowName: string;
16
+ runId: string;
17
+ snapshot: WorkflowRunState;
18
+ }): Promise<void>;
19
+ loadWorkflowSnapshot({ workflowName, runId, }: {
20
+ workflowName: string;
21
+ runId: string;
22
+ }): Promise<WorkflowRunState | null>;
23
+ getWorkflowRunById({ runId, workflowName, }: {
24
+ runId: string;
25
+ workflowName?: string;
26
+ }): Promise<WorkflowRun | null>;
27
+ getWorkflowRuns({ workflowName, fromDate, toDate, limit, offset, resourceId, }?: {
28
+ workflowName?: string;
29
+ fromDate?: Date;
30
+ toDate?: Date;
31
+ limit?: number;
32
+ offset?: number;
33
+ resourceId?: string;
34
+ }): Promise<WorkflowRuns>;
35
+ }
36
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/workflows/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhF,OAAO,EAAE,gBAAgB,EAA2B,MAAM,sBAAsB,CAAC;AACjF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,O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,YAAY,CAAC;CA8E/B"}
@@ -0,0 +1,211 @@
1
+ import type { MastraMessageContentV2, MastraMessageV2 } from '@mastra/core/agent';
2
+ import type { MastraMessageV1, StorageThreadType } from '@mastra/core/memory';
3
+ import type { ScoreRowData } from '@mastra/core/scores';
4
+ import { MastraStorage } from '@mastra/core/storage';
5
+ import type { EvalRow, PaginationInfo, StorageColumn, StorageGetMessagesArg, StorageGetTracesArg, StorageGetTracesPaginatedArg, StorageResourceType, TABLE_NAMES, WorkflowRun, WorkflowRuns, PaginationArgs, StoragePagination, StorageDomains, ThreadSortOptions } from '@mastra/core/storage';
6
+ import type { Trace } from '@mastra/core/telemetry';
7
+ import type { WorkflowRunState } from '@mastra/core/workflows';
8
+ import pgPromise from 'pg-promise';
9
+ import type { ISSLConfig } from 'pg-promise/typescript/pg-subset';
10
+ export type PostgresConfig = {
11
+ schemaName?: string;
12
+ } & ({
13
+ host: string;
14
+ port: number;
15
+ database: string;
16
+ user: string;
17
+ password: string;
18
+ ssl?: boolean | ISSLConfig;
19
+ } | {
20
+ connectionString: string;
21
+ });
22
+ export declare class PostgresStore extends MastraStorage {
23
+ db: pgPromise.IDatabase<{}>;
24
+ pgp: pgPromise.IMain;
25
+ private client;
26
+ private schema?;
27
+ stores: StorageDomains;
28
+ constructor(config: PostgresConfig);
29
+ get supports(): {
30
+ selectByIncludeResourceScope: boolean;
31
+ resourceWorkingMemory: boolean;
32
+ hasColumn: boolean;
33
+ createTable: boolean;
34
+ deleteMessages: boolean;
35
+ };
36
+ /** @deprecated use getEvals instead */
37
+ getEvalsByAgentName(agentName: string, type?: 'test' | 'live'): Promise<EvalRow[]>;
38
+ getEvals(options?: {
39
+ agentName?: string;
40
+ type?: 'test' | 'live';
41
+ } & PaginationArgs): Promise<PaginationInfo & {
42
+ evals: EvalRow[];
43
+ }>;
44
+ /**
45
+ * @deprecated use getTracesPaginated instead
46
+ */
47
+ getTraces(args: StorageGetTracesArg): Promise<Trace[]>;
48
+ getTracesPaginated(args: StorageGetTracesPaginatedArg): Promise<PaginationInfo & {
49
+ traces: Trace[];
50
+ }>;
51
+ batchTraceInsert({ records }: {
52
+ records: Record<string, any>[];
53
+ }): Promise<void>;
54
+ createTable({ tableName, schema, }: {
55
+ tableName: TABLE_NAMES;
56
+ schema: Record<string, StorageColumn>;
57
+ }): Promise<void>;
58
+ alterTable({ tableName, schema, ifNotExists, }: {
59
+ tableName: TABLE_NAMES;
60
+ schema: Record<string, StorageColumn>;
61
+ ifNotExists: string[];
62
+ }): Promise<void>;
63
+ clearTable({ tableName }: {
64
+ tableName: TABLE_NAMES;
65
+ }): Promise<void>;
66
+ dropTable({ tableName }: {
67
+ tableName: TABLE_NAMES;
68
+ }): Promise<void>;
69
+ insert({ tableName, record }: {
70
+ tableName: TABLE_NAMES;
71
+ record: Record<string, any>;
72
+ }): Promise<void>;
73
+ batchInsert({ tableName, records }: {
74
+ tableName: TABLE_NAMES;
75
+ records: Record<string, any>[];
76
+ }): Promise<void>;
77
+ load<R>({ tableName, keys }: {
78
+ tableName: TABLE_NAMES;
79
+ keys: Record<string, string>;
80
+ }): Promise<R | null>;
81
+ /**
82
+ * Memory
83
+ */
84
+ getThreadById({ threadId }: {
85
+ threadId: string;
86
+ }): Promise<StorageThreadType | null>;
87
+ /**
88
+ * @deprecated use getThreadsByResourceIdPaginated instead
89
+ */
90
+ getThreadsByResourceId(args: {
91
+ resourceId: string;
92
+ } & ThreadSortOptions): Promise<StorageThreadType[]>;
93
+ getThreadsByResourceIdPaginated(args: {
94
+ resourceId: string;
95
+ page: number;
96
+ perPage: number;
97
+ } & ThreadSortOptions): Promise<PaginationInfo & {
98
+ threads: StorageThreadType[];
99
+ }>;
100
+ saveThread({ thread }: {
101
+ thread: StorageThreadType;
102
+ }): Promise<StorageThreadType>;
103
+ updateThread({ id, title, metadata, }: {
104
+ id: string;
105
+ title: string;
106
+ metadata: Record<string, unknown>;
107
+ }): Promise<StorageThreadType>;
108
+ deleteThread({ threadId }: {
109
+ threadId: string;
110
+ }): Promise<void>;
111
+ /**
112
+ * @deprecated use getMessagesPaginated instead
113
+ */
114
+ getMessages(args: StorageGetMessagesArg & {
115
+ format?: 'v1';
116
+ }): Promise<MastraMessageV1[]>;
117
+ getMessages(args: StorageGetMessagesArg & {
118
+ format: 'v2';
119
+ }): Promise<MastraMessageV2[]>;
120
+ getMessagesPaginated(args: StorageGetMessagesArg & {
121
+ format?: 'v1' | 'v2';
122
+ }): Promise<PaginationInfo & {
123
+ messages: MastraMessageV1[] | MastraMessageV2[];
124
+ }>;
125
+ saveMessages(args: {
126
+ messages: MastraMessageV1[];
127
+ format?: undefined | 'v1';
128
+ }): Promise<MastraMessageV1[]>;
129
+ saveMessages(args: {
130
+ messages: MastraMessageV2[];
131
+ format: 'v2';
132
+ }): Promise<MastraMessageV2[]>;
133
+ updateMessages({ messages, }: {
134
+ messages: (Partial<Omit<MastraMessageV2, 'createdAt'>> & {
135
+ id: string;
136
+ content?: {
137
+ metadata?: MastraMessageContentV2['metadata'];
138
+ content?: MastraMessageContentV2['content'];
139
+ };
140
+ })[];
141
+ }): Promise<MastraMessageV2[]>;
142
+ deleteMessages(messageIds: string[]): Promise<void>;
143
+ getResourceById({ resourceId }: {
144
+ resourceId: string;
145
+ }): Promise<StorageResourceType | null>;
146
+ saveResource({ resource }: {
147
+ resource: StorageResourceType;
148
+ }): Promise<StorageResourceType>;
149
+ updateResource({ resourceId, workingMemory, metadata, }: {
150
+ resourceId: string;
151
+ workingMemory?: string;
152
+ metadata?: Record<string, unknown>;
153
+ }): Promise<StorageResourceType>;
154
+ /**
155
+ * Workflows
156
+ */
157
+ persistWorkflowSnapshot({ workflowName, runId, snapshot, }: {
158
+ workflowName: string;
159
+ runId: string;
160
+ snapshot: WorkflowRunState;
161
+ }): Promise<void>;
162
+ loadWorkflowSnapshot({ workflowName, runId, }: {
163
+ workflowName: string;
164
+ runId: string;
165
+ }): Promise<WorkflowRunState | null>;
166
+ getWorkflowRuns({ workflowName, fromDate, toDate, limit, offset, resourceId, }?: {
167
+ workflowName?: string;
168
+ fromDate?: Date;
169
+ toDate?: Date;
170
+ limit?: number;
171
+ offset?: number;
172
+ resourceId?: string;
173
+ }): Promise<WorkflowRuns>;
174
+ getWorkflowRunById({ runId, workflowName, }: {
175
+ runId: string;
176
+ workflowName?: string;
177
+ }): Promise<WorkflowRun | null>;
178
+ close(): Promise<void>;
179
+ /**
180
+ * Scorers
181
+ */
182
+ getScoreById({ id: _id }: {
183
+ id: string;
184
+ }): Promise<ScoreRowData | null>;
185
+ getScoresByScorerId({ scorerId: _scorerId, pagination: _pagination, }: {
186
+ scorerId: string;
187
+ pagination: StoragePagination;
188
+ }): Promise<{
189
+ pagination: PaginationInfo;
190
+ scores: ScoreRowData[];
191
+ }>;
192
+ saveScore(_score: ScoreRowData): Promise<{
193
+ score: ScoreRowData;
194
+ }>;
195
+ getScoresByRunId({ runId: _runId, pagination: _pagination, }: {
196
+ runId: string;
197
+ pagination: StoragePagination;
198
+ }): Promise<{
199
+ pagination: PaginationInfo;
200
+ scores: ScoreRowData[];
201
+ }>;
202
+ getScoresByEntityId({ entityId: _entityId, entityType: _entityType, pagination: _pagination, }: {
203
+ pagination: StoragePagination;
204
+ entityId: string;
205
+ entityType: string;
206
+ }): Promise<{
207
+ pagination: PaginationInfo;
208
+ scores: ScoreRowData[];
209
+ }>;
210
+ }
211
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/storage/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAElF,OAAO,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC9E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,KAAK,EACV,OAAO,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ACjB,UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC;QAAE,UAAU,EAAE,cAAc,CAAC;QAAC,MAAM,EAAE,YAAY,EAAE,CAAA;KAAE,CAAC;CAOpE"}
@@ -0,0 +1,5 @@
1
+ import type { PostgresConfig } from '.';
2
+ export declare const TEST_CONFIG: PostgresConfig;
3
+ export declare const connectionString: string;
4
+ export declare function pgTests(): void;
5
+ //# sourceMappingURL=test-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-utils.d.ts","sourceRoot":"","sources":["../../src/storage/test-utils.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,GAAG,CAAC;AAExC,eAAO,MAAM,WAAW,EAAE,cAMzB,CAAC;AAEF,eAAO,MAAM,gBAAgB,QAA6H,CAAC;AAE3J,wBAAgB,OAAO,SA8VtB"}
@@ -0,0 +1,32 @@
1
+ import { BaseFilterTranslator } from '@mastra/core/vector/filter';
2
+ import type { VectorFilter, OperatorSupport, OperatorValueMap, LogicalOperatorValueMap, BlacklistedRootOperators, VectorFieldValue } from '@mastra/core/vector/filter';
3
+ type PGOperatorValueMap = Omit<OperatorValueMap, '$in' | '$all' | '$nin' | '$eq' | '$ne'> & {
4
+ $size: number;
5
+ $contains: VectorFieldValue | Record<string, unknown>;
6
+ $all: VectorFieldValue;
7
+ $in: VectorFieldValue;
8
+ $nin: VectorFieldValue;
9
+ $eq: VectorFieldValue;
10
+ $ne: VectorFieldValue;
11
+ };
12
+ type PGBlacklisted = BlacklistedRootOperators | '$contains' | '$size';
13
+ type PGFilterValue = VectorFieldValue | RegExp;
14
+ export type PGVectorFilter = VectorFilter<keyof PGOperatorValueMap, PGOperatorValueMap, LogicalOperatorValueMap, PGBlacklisted, PGFilterValue>;
15
+ /**
16
+ * Translates MongoDB-style filters to PG compatible filters.
17
+ *
18
+ * Key differences from MongoDB:
19
+ *
20
+ * Logical Operators ($and, $or, $nor):
21
+ * - Can be used at the top level or nested within fields
22
+ * - Can take either a single condition or an array of conditions
23
+ *
24
+ */
25
+ export declare class PGFilterTranslator extends BaseFilterTranslator<PGVectorFilter> {
26
+ protected getSupportedOperators(): OperatorSupport;
27
+ translate(filter?: PGVectorFilter): PGVectorFilter;
28
+ private translateNode;
29
+ private translateRegexPattern;
30
+ }
31
+ export {};
32
+ //# sourceMappingURL=filter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../../src/vector/filter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,KAAK,EACV,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,uBAAuB,EACvB,wBAAwB,EACxB,gBAAgB,EACjB,MAAM,4BAA4B,CAAC;AAEpC,KAAK,kBAAkB,GAAG,IAAI,CAAC,gBAAgB,EAAE,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,GAAG,KAAK,CAAC,GAAG;IAC1F,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtD,IAAI,EAAE,gBAAgB,CAAC;IACvB,GAAG,EAAE,gBAAgB,CAAC;IACtB,IAAI,EAAE,gBAAgB,CAAC;IACvB,GAAG,EAAE,gBAAgB,CAAC;IACtB,GAAG,EAAE,gBAAgB,CAAC;CACvB,CAAC;AAEF,KAAK,aAAa,GAAG,wBAAwB,GAAG,WAAW,GAAG,OAAO,CAAC;AAEtE,KAAK,aAAa,GAAG,gBAAgB,GAAG,MAAM,CAAC;AAE/C,MAAM,MAAM,cAAc,GAAG,YAAY,CACvC,MAAM,kBAAkB,EACxB,kBAAkB,EAClB,uBAAuB,EACvB,aAAa,EACb,aAAa,CACd,CAAC;AAEF;;;;;;;;;GASG;AACH,qBAAa,kBAAmB,SAAQ,oBAAoB,CAAC,cAAc,CAAC;cACvD,qBAAqB,IAAI,eAAe;IAO3D,SAAS,CAAC,MAAM,CAAC,EAAE,cAAc,GAAG,cAAc;IAQlD,OAAO,CAAC,aAAa;IAmErB,OAAO,CAAC,qBAAqB;CAU9B"}
@@ -0,0 +1,99 @@
1
+ import { MastraVector } from '@mastra/core/vector';
2
+ import type { IndexStats, QueryResult, QueryVectorParams, CreateIndexParams, UpsertVectorParams, DescribeIndexParams, DeleteIndexParams, DeleteVectorParams, UpdateVectorParams } from '@mastra/core/vector';
3
+ import pg from 'pg';
4
+ import type { PGVectorFilter } from './filter';
5
+ import type { IndexConfig, IndexType } from './types';
6
+ export interface PGIndexStats extends IndexStats {
7
+ type: IndexType;
8
+ config: {
9
+ m?: number;
10
+ efConstruction?: number;
11
+ lists?: number;
12
+ probes?: number;
13
+ };
14
+ }
15
+ interface PgQueryVectorParams extends QueryVectorParams<PGVectorFilter> {
16
+ minScore?: number;
17
+ /**
18
+ * HNSW search parameter. Controls the size of the dynamic candidate
19
+ * list during search. Higher values improve accuracy at the cost of speed.
20
+ */
21
+ ef?: number;
22
+ /**
23
+ * IVFFlat probe parameter. Number of cells to visit during search.
24
+ * Higher values improve accuracy at the cost of speed.
25
+ */
26
+ probes?: number;
27
+ }
28
+ interface PgCreateIndexParams extends CreateIndexParams {
29
+ indexConfig?: IndexConfig;
30
+ buildIndex?: boolean;
31
+ }
32
+ interface PgDefineIndexParams {
33
+ indexName: string;
34
+ metric: 'cosine' | 'euclidean' | 'dotproduct';
35
+ indexConfig: IndexConfig;
36
+ }
37
+ export declare class PgVector extends MastraVector<PGVectorFilter> {
38
+ pool: pg.Pool;
39
+ private describeIndexCache;
40
+ private createdIndexes;
41
+ private mutexesByName;
42
+ private schema?;
43
+ private setupSchemaPromise;
44
+ private installVectorExtensionPromise;
45
+ private vectorExtensionInstalled;
46
+ private schemaSetupComplete;
47
+ constructor({ connectionString, schemaName, pgPoolOptions, }: {
48
+ connectionString: string;
49
+ schemaName?: string;
50
+ pgPoolOptions?: Omit<pg.PoolConfig, 'connectionString'>;
51
+ });
52
+ private getMutexByName;
53
+ private getTableName;
54
+ private getSchemaName;
55
+ transformFilter(filter?: PGVectorFilter): PGVectorFilter;
56
+ getIndexInfo({ indexName }: DescribeIndexParams): Promise<PGIndexStats>;
57
+ query({ indexName, queryVector, topK, filter, includeVector, minScore, ef, probes, }: PgQueryVectorParams): Promise<QueryResult[]>;
58
+ upsert({ indexName, vectors, metadata, ids }: UpsertVectorParams): Promise<string[]>;
59
+ private hasher;
60
+ private getIndexCacheKey;
61
+ private cachedIndexExists;
62
+ private setupSchema;
63
+ createIndex({ indexName, dimension, metric, indexConfig, buildIndex, }: PgCreateIndexParams): Promise<void>;
64
+ buildIndex({ indexName, metric, indexConfig }: PgDefineIndexParams): Promise<void>;
65
+ private setupIndex;
66
+ private installVectorExtension;
67
+ listIndexes(): Promise<string[]>;
68
+ /**
69
+ * Retrieves statistics about a vector index.
70
+ *
71
+ * @param {string} indexName - The name of the index to describe
72
+ * @returns A promise that resolves to the index statistics including dimension, count and metric
73
+ */
74
+ describeIndex({ indexName }: DescribeIndexParams): Promise<PGIndexStats>;
75
+ deleteIndex({ indexName }: DeleteIndexParams): Promise<void>;
76
+ truncateIndex({ indexName }: DeleteIndexParams): Promise<void>;
77
+ disconnect(): Promise<void>;
78
+ /**
79
+ * Updates a vector by its ID with the provided vector and/or metadata.
80
+ * @param indexName - The name of the index containing the vector.
81
+ * @param id - The ID of the vector to update.
82
+ * @param update - An object containing the vector and/or metadata to update.
83
+ * @param update.vector - An optional array of numbers representing the new vector.
84
+ * @param update.metadata - An optional record containing the new metadata.
85
+ * @returns A promise that resolves when the update is complete.
86
+ * @throws Will throw an error if no updates are provided or if the update operation fails.
87
+ */
88
+ updateVector({ indexName, id, update }: UpdateVectorParams): Promise<void>;
89
+ /**
90
+ * Deletes a vector by its ID.
91
+ * @param indexName - The name of the index containing the vector.
92
+ * @param id - The ID of the vector to delete.
93
+ * @returns A promise that resolves when the deletion is complete.
94
+ * @throws Will throw an error if the deletion operation fails.
95
+ */
96
+ deleteVector({ indexName, id }: DeleteVectorParams): Promise<void>;
97
+ }
98
+ export {};
99
+ //# sourceMappingURL=index.d.ts.map