@mastra/pg 0.13.2-alpha.0 → 0.13.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.
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +37 -0
- package/dist/index.cjs +33 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +33 -14
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +1 -1
- package/dist/storage/domains/scores/index.d.ts +1 -1
- package/dist/storage/domains/scores/index.d.ts.map +1 -1
- package/dist/storage/domains/traces/index.d.ts +1 -1
- package/dist/storage/domains/workflows/index.d.ts +1 -1
- package/dist/vector/index.d.ts +2 -2
- package/dist/vector/performance.helpers.d.ts +1 -1
- package/dist/vector/sql-builder.d.ts +1 -1
- package/package.json +8 -7
- package/src/storage/domains/scores/index.ts +35 -16
- package/src/storage/domains/traces/index.ts +5 -5
- package/tsup.config.ts +2 -7
|
@@ -3,7 +3,7 @@ import type { MastraMessageV1, MastraMessageV2, StorageThreadType } from '@mastr
|
|
|
3
3
|
import { MemoryStorage } from '@mastra/core/storage';
|
|
4
4
|
import type { StorageGetMessagesArg, PaginationInfo, StorageResourceType, ThreadSortOptions } from '@mastra/core/storage';
|
|
5
5
|
import type { IDatabase } from 'pg-promise';
|
|
6
|
-
import type { StoreOperationsPG } from '../operations';
|
|
6
|
+
import type { StoreOperationsPG } from '../operations/index.js';
|
|
7
7
|
export declare class MemoryPG extends MemoryStorage {
|
|
8
8
|
private client;
|
|
9
9
|
private schema;
|
|
@@ -2,7 +2,7 @@ import type { PaginationInfo, StoragePagination } from '@mastra/core';
|
|
|
2
2
|
import type { ScoreRowData } from '@mastra/core/scores';
|
|
3
3
|
import { ScoresStorage } from '@mastra/core/storage';
|
|
4
4
|
import type { IDatabase } from 'pg-promise';
|
|
5
|
-
import type { StoreOperationsPG } from '../operations';
|
|
5
|
+
import type { StoreOperationsPG } from '../operations/index.js';
|
|
6
6
|
export declare class ScoresPG extends ScoresStorage {
|
|
7
7
|
client: IDatabase<{}>;
|
|
8
8
|
private operations;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/scores/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEtE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/scores/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEtE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAmB,aAAa,EAAiB,MAAM,sBAAsB,CAAC;AACrF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAoBvD,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,YAAY,CAAC,EAAE,EAAE,EAAE,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAoBlE,mBAAmB,CAAC,EACxB,QAAQ,EACR,UAAU,GACX,EAAE;QACD,QAAQ,EAAE,MAAM,CAAC;QACjB,UAAU,EAAE,iBAAiB,CAAC;KAC/B,GAAG,OAAO,CAAC;QAAE,UAAU,EAAE,cAAc,CAAC;QAAC,MAAM,EAAE,YAAY,EAAE,CAAA;KAAE,CAAC;IA2C7D,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,YAAY,EAAE,IAAI,GAAG,WAAW,GAAG,WAAW,CAAC,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,YAAY,CAAA;KAAE,CAAC;IAmDxG,gBAAgB,CAAC,EACrB,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;IA2C7D,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"}
|
|
@@ -2,7 +2,7 @@ import type { PaginationInfo, StorageGetTracesArg, StorageGetTracesPaginatedArg
|
|
|
2
2
|
import { TracesStorage } from '@mastra/core/storage';
|
|
3
3
|
import type { Trace } from '@mastra/core/telemetry';
|
|
4
4
|
import type { IDatabase } from 'pg-promise';
|
|
5
|
-
import type { StoreOperationsPG } from '../operations';
|
|
5
|
+
import type { StoreOperationsPG } from '../operations/index.js';
|
|
6
6
|
export declare class TracesPG extends TracesStorage {
|
|
7
7
|
client: IDatabase<{}>;
|
|
8
8
|
private operations;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { WorkflowRun, WorkflowRuns, WorkflowRunState } from '@mastra/core';
|
|
2
2
|
import { WorkflowsStorage } from '@mastra/core/storage';
|
|
3
3
|
import type { IDatabase } from 'pg-promise';
|
|
4
|
-
import type { StoreOperationsPG } from '../operations';
|
|
4
|
+
import type { StoreOperationsPG } from '../operations/index.js';
|
|
5
5
|
export declare class WorkflowsPG extends WorkflowsStorage {
|
|
6
6
|
client: IDatabase<{}>;
|
|
7
7
|
private operations;
|
package/dist/vector/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { MastraVector } from '@mastra/core/vector';
|
|
2
2
|
import type { IndexStats, QueryResult, QueryVectorParams, CreateIndexParams, UpsertVectorParams, DescribeIndexParams, DeleteIndexParams, DeleteVectorParams, UpdateVectorParams } from '@mastra/core/vector';
|
|
3
3
|
import pg from 'pg';
|
|
4
|
-
import type { PGVectorFilter } from './filter';
|
|
5
|
-
import type { IndexConfig, IndexType } from './types';
|
|
4
|
+
import type { PGVectorFilter } from './filter.js';
|
|
5
|
+
import type { IndexConfig, IndexType } from './types.js';
|
|
6
6
|
export interface PGIndexStats extends IndexStats {
|
|
7
7
|
type: IndexType;
|
|
8
8
|
config: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/pg",
|
|
3
|
-
"version": "0.13.2
|
|
3
|
+
"version": "0.13.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",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"default": "./dist/index.js"
|
|
13
13
|
},
|
|
14
14
|
"require": {
|
|
15
|
-
"types": "./dist/index.d.
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
16
|
"default": "./dist/index.cjs"
|
|
17
17
|
}
|
|
18
18
|
},
|
|
@@ -28,17 +28,18 @@
|
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@microsoft/api-extractor": "^7.52.8",
|
|
30
30
|
"@types/node": "^20.19.0",
|
|
31
|
-
"@types/pg": "^8.15.
|
|
31
|
+
"@types/pg": "^8.15.5",
|
|
32
32
|
"eslint": "^9.30.1",
|
|
33
33
|
"tsup": "^8.5.0",
|
|
34
34
|
"typescript": "^5.8.3",
|
|
35
35
|
"vitest": "^3.2.4",
|
|
36
|
-
"@internal/lint": "0.0.
|
|
37
|
-
"@
|
|
38
|
-
"@
|
|
36
|
+
"@internal/lint": "0.0.27",
|
|
37
|
+
"@mastra/core": "0.13.0",
|
|
38
|
+
"@internal/storage-test-utils": "0.0.23",
|
|
39
|
+
"@internal/types-builder": "0.0.2"
|
|
39
40
|
},
|
|
40
41
|
"peerDependencies": {
|
|
41
|
-
"@mastra/core": ">=0.
|
|
42
|
+
"@mastra/core": ">=0.13.0-0 <0.14.0-0"
|
|
42
43
|
},
|
|
43
44
|
"scripts": {
|
|
44
45
|
"build": "tsup --silent --config tsup.config.ts",
|
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
import type { PaginationInfo, StoragePagination } from '@mastra/core';
|
|
2
2
|
import { ErrorCategory, ErrorDomain, MastraError } from '@mastra/core/error';
|
|
3
3
|
import type { ScoreRowData } from '@mastra/core/scores';
|
|
4
|
-
import { ScoresStorage, TABLE_SCORERS } from '@mastra/core/storage';
|
|
4
|
+
import { safelyParseJSON, ScoresStorage, TABLE_SCORERS } from '@mastra/core/storage';
|
|
5
5
|
import type { IDatabase } from 'pg-promise';
|
|
6
6
|
import type { StoreOperationsPG } from '../operations';
|
|
7
7
|
import { getTableName } from '../utils';
|
|
8
8
|
|
|
9
9
|
function transformScoreRow(row: Record<string, any>): ScoreRowData {
|
|
10
|
-
let input = undefined;
|
|
11
|
-
|
|
12
|
-
if (row.input) {
|
|
13
|
-
try {
|
|
14
|
-
input = JSON.parse(row.input);
|
|
15
|
-
} catch {
|
|
16
|
-
input = row.input;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
10
|
return {
|
|
20
11
|
...row,
|
|
21
|
-
input,
|
|
12
|
+
input: safelyParseJSON(row.input),
|
|
13
|
+
scorer: safelyParseJSON(row.scorer),
|
|
14
|
+
preprocessStepResult: safelyParseJSON(row.preprocessStepResult),
|
|
15
|
+
analyzeStepResult: safelyParseJSON(row.analyzeStepResult),
|
|
16
|
+
metadata: safelyParseJSON(row.metadata),
|
|
17
|
+
output: safelyParseJSON(row.output),
|
|
18
|
+
additionalContext: safelyParseJSON(row.additionalContext),
|
|
19
|
+
runtimeContext: safelyParseJSON(row.runtimeContext),
|
|
20
|
+
entity: safelyParseJSON(row.entity),
|
|
22
21
|
createdAt: row.createdAtZ || row.createdAt,
|
|
23
22
|
updatedAt: row.updatedAtZ || row.updatedAt,
|
|
24
23
|
} as ScoreRowData;
|
|
@@ -99,7 +98,7 @@ export class ScoresPG extends ScoresStorage {
|
|
|
99
98
|
perPage: pagination.perPage,
|
|
100
99
|
hasMore: Number(total?.count) > (pagination.page + 1) * pagination.perPage,
|
|
101
100
|
},
|
|
102
|
-
scores: result,
|
|
101
|
+
scores: result.map(transformScoreRow),
|
|
103
102
|
};
|
|
104
103
|
} catch (error) {
|
|
105
104
|
throw new MastraError(
|
|
@@ -118,13 +117,33 @@ export class ScoresPG extends ScoresStorage {
|
|
|
118
117
|
// Generate ID like other storage implementations
|
|
119
118
|
const scoreId = crypto.randomUUID();
|
|
120
119
|
|
|
121
|
-
const {
|
|
120
|
+
const {
|
|
121
|
+
scorer,
|
|
122
|
+
preprocessStepResult,
|
|
123
|
+
analyzeStepResult,
|
|
124
|
+
metadata,
|
|
125
|
+
input,
|
|
126
|
+
output,
|
|
127
|
+
additionalContext,
|
|
128
|
+
runtimeContext,
|
|
129
|
+
entity,
|
|
130
|
+
...rest
|
|
131
|
+
} = score;
|
|
132
|
+
|
|
122
133
|
await this.operations.insert({
|
|
123
134
|
tableName: TABLE_SCORERS,
|
|
124
135
|
record: {
|
|
125
136
|
id: scoreId,
|
|
126
137
|
...rest,
|
|
127
|
-
input: JSON.stringify(input),
|
|
138
|
+
input: JSON.stringify(input) || '',
|
|
139
|
+
output: JSON.stringify(output) || '',
|
|
140
|
+
scorer: scorer ? JSON.stringify(scorer) : null,
|
|
141
|
+
preprocessStepResult: preprocessStepResult ? JSON.stringify(preprocessStepResult) : null,
|
|
142
|
+
analyzeStepResult: analyzeStepResult ? JSON.stringify(analyzeStepResult) : null,
|
|
143
|
+
metadata: metadata ? JSON.stringify(metadata) : null,
|
|
144
|
+
additionalContext: additionalContext ? JSON.stringify(additionalContext) : null,
|
|
145
|
+
runtimeContext: runtimeContext ? JSON.stringify(runtimeContext) : null,
|
|
146
|
+
entity: entity ? JSON.stringify(entity) : null,
|
|
128
147
|
createdAt: new Date().toISOString(),
|
|
129
148
|
updatedAt: new Date().toISOString(),
|
|
130
149
|
},
|
|
@@ -179,7 +198,7 @@ export class ScoresPG extends ScoresStorage {
|
|
|
179
198
|
perPage: pagination.perPage,
|
|
180
199
|
hasMore: Number(total?.count) > (pagination.page + 1) * pagination.perPage,
|
|
181
200
|
},
|
|
182
|
-
scores: result,
|
|
201
|
+
scores: result.map(transformScoreRow),
|
|
183
202
|
};
|
|
184
203
|
} catch (error) {
|
|
185
204
|
throw new MastraError(
|
|
@@ -231,7 +250,7 @@ export class ScoresPG extends ScoresStorage {
|
|
|
231
250
|
perPage: pagination.perPage,
|
|
232
251
|
hasMore: Number(total?.count) > (pagination.page + 1) * pagination.perPage,
|
|
233
252
|
},
|
|
234
|
-
scores: result,
|
|
253
|
+
scores: result.map(transformScoreRow),
|
|
235
254
|
};
|
|
236
255
|
} catch (error) {
|
|
237
256
|
throw new MastraError(
|
|
@@ -121,13 +121,13 @@ export class TracesPG extends TracesStorage {
|
|
|
121
121
|
name: row.name,
|
|
122
122
|
scope: row.scope,
|
|
123
123
|
kind: row.kind,
|
|
124
|
-
status: safelyParseJSON(row.status
|
|
125
|
-
events: safelyParseJSON(row.events
|
|
126
|
-
links: safelyParseJSON(row.links
|
|
127
|
-
attributes: safelyParseJSON(row.attributes
|
|
124
|
+
status: safelyParseJSON(row.status),
|
|
125
|
+
events: safelyParseJSON(row.events),
|
|
126
|
+
links: safelyParseJSON(row.links),
|
|
127
|
+
attributes: safelyParseJSON(row.attributes),
|
|
128
128
|
startTime: row.startTime,
|
|
129
129
|
endTime: row.endTime,
|
|
130
|
-
other: safelyParseJSON(row.other
|
|
130
|
+
other: safelyParseJSON(row.other),
|
|
131
131
|
createdAt: row.createdAtZ || row.createdAt,
|
|
132
132
|
})) as Trace[];
|
|
133
133
|
|
package/tsup.config.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { promisify } from 'util';
|
|
1
|
+
import { generateTypes } from '@internal/types-builder';
|
|
3
2
|
import { defineConfig } from 'tsup';
|
|
4
3
|
|
|
5
|
-
const exec = promisify(spawn);
|
|
6
|
-
|
|
7
4
|
export default defineConfig({
|
|
8
5
|
entry: ['src/index.ts'],
|
|
9
6
|
format: ['esm', 'cjs'],
|
|
@@ -15,8 +12,6 @@ export default defineConfig({
|
|
|
15
12
|
},
|
|
16
13
|
sourcemap: true,
|
|
17
14
|
onSuccess: async () => {
|
|
18
|
-
await
|
|
19
|
-
stdio: 'inherit',
|
|
20
|
-
});
|
|
15
|
+
await generateTypes(process.cwd());
|
|
21
16
|
},
|
|
22
17
|
});
|