@mastra/pg 0.14.6-alpha.0 → 0.14.6-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/CHANGELOG.md +9 -0
- package/package.json +17 -4
- package/.turbo/turbo-build.log +0 -4
- package/docker-compose.perf.yaml +0 -21
- package/docker-compose.yaml +0 -14
- package/eslint.config.js +0 -6
- package/src/index.ts +0 -3
- package/src/storage/domains/legacy-evals/index.ts +0 -151
- package/src/storage/domains/memory/index.ts +0 -1028
- package/src/storage/domains/operations/index.ts +0 -370
- package/src/storage/domains/scores/index.ts +0 -297
- package/src/storage/domains/traces/index.ts +0 -160
- package/src/storage/domains/utils.ts +0 -12
- package/src/storage/domains/workflows/index.ts +0 -291
- package/src/storage/index.test.ts +0 -11
- package/src/storage/index.ts +0 -514
- package/src/storage/test-utils.ts +0 -377
- package/src/vector/filter.test.ts +0 -967
- package/src/vector/filter.ts +0 -136
- package/src/vector/index.test.ts +0 -2729
- package/src/vector/index.ts +0 -926
- package/src/vector/performance.helpers.ts +0 -286
- package/src/vector/prompt.ts +0 -101
- package/src/vector/sql-builder.ts +0 -358
- package/src/vector/types.ts +0 -16
- package/src/vector/vector.performance.test.ts +0 -367
- package/tsconfig.build.json +0 -9
- package/tsconfig.json +0 -5
- package/tsup.config.ts +0 -17
- package/vitest.config.ts +0 -12
- package/vitest.perf.config.ts +0 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @mastra/pg
|
|
2
2
|
|
|
3
|
+
## 0.14.6-alpha.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#7343](https://github.com/mastra-ai/mastra/pull/7343) [`de3cbc6`](https://github.com/mastra-ai/mastra/commit/de3cbc61079211431bd30487982ea3653517278e) Thanks [@LekoArts](https://github.com/LekoArts)! - Update the `package.json` file to include additional fields like `repository`, `homepage` or `files`.
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`85ef90b`](https://github.com/mastra-ai/mastra/commit/85ef90bb2cd4ae4df855c7ac175f7d392c55c1bf), [`de3cbc6`](https://github.com/mastra-ai/mastra/commit/de3cbc61079211431bd30487982ea3653517278e)]:
|
|
10
|
+
- @mastra/core@0.15.3-alpha.5
|
|
11
|
+
|
|
3
12
|
## 0.14.6-alpha.0
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/pg",
|
|
3
|
-
"version": "0.14.6-alpha.
|
|
3
|
+
"version": "0.14.6-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",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"./package.json": "./package.json"
|
|
20
20
|
},
|
|
21
|
-
"license": "
|
|
21
|
+
"license": "Apache-2.0",
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"async-mutex": "^0.5.0",
|
|
24
24
|
"pg": "^8.16.3",
|
|
@@ -33,14 +33,27 @@
|
|
|
33
33
|
"tsup": "^8.5.0",
|
|
34
34
|
"typescript": "^5.8.3",
|
|
35
35
|
"vitest": "^3.2.4",
|
|
36
|
-
"@mastra/core": "0.15.3-alpha.4",
|
|
37
|
-
"@internal/lint": "0.0.34",
|
|
38
36
|
"@internal/storage-test-utils": "0.0.30",
|
|
37
|
+
"@internal/lint": "0.0.34",
|
|
38
|
+
"@mastra/core": "0.15.3-alpha.5",
|
|
39
39
|
"@internal/types-builder": "0.0.9"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"@mastra/core": ">=0.13.0-0 <0.16.0-0"
|
|
43
43
|
},
|
|
44
|
+
"files": [
|
|
45
|
+
"dist",
|
|
46
|
+
"CHANGELOG.md"
|
|
47
|
+
],
|
|
48
|
+
"homepage": "https://mastra.ai",
|
|
49
|
+
"repository": {
|
|
50
|
+
"type": "git",
|
|
51
|
+
"url": "git+https://github.com/mastra-ai/mastra.git",
|
|
52
|
+
"directory": "stores/pg"
|
|
53
|
+
},
|
|
54
|
+
"bugs": {
|
|
55
|
+
"url": "https://github.com/mastra-ai/mastra/issues"
|
|
56
|
+
},
|
|
44
57
|
"scripts": {
|
|
45
58
|
"build": "tsup --silent --config tsup.config.ts",
|
|
46
59
|
"build:watch": "pnpm build --watch",
|
package/.turbo/turbo-build.log
DELETED
package/docker-compose.perf.yaml
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
services:
|
|
2
|
-
db:
|
|
3
|
-
image: pgvector/pgvector:pg16
|
|
4
|
-
container_name: 'pg-perf-test-db'
|
|
5
|
-
ports:
|
|
6
|
-
- '5435:5432'
|
|
7
|
-
environment:
|
|
8
|
-
POSTGRES_USER: ${POSTGRES_USER:-postgres}
|
|
9
|
-
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
|
|
10
|
-
POSTGRES_DB: ${POSTGRES_DB:-mastra}
|
|
11
|
-
shm_size: 1gb
|
|
12
|
-
command:
|
|
13
|
-
- 'postgres'
|
|
14
|
-
- '-c'
|
|
15
|
-
- 'shared_buffers=512MB'
|
|
16
|
-
- '-c'
|
|
17
|
-
- 'maintenance_work_mem=1024MB'
|
|
18
|
-
- '-c'
|
|
19
|
-
- 'work_mem=512MB'
|
|
20
|
-
tmpfs:
|
|
21
|
-
- /var/lib/postgresql/data
|
package/docker-compose.yaml
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
services:
|
|
2
|
-
db:
|
|
3
|
-
image: pgvector/pgvector:pg16
|
|
4
|
-
container_name: 'pg-test-db'
|
|
5
|
-
ports:
|
|
6
|
-
- '5434:5432'
|
|
7
|
-
environment:
|
|
8
|
-
POSTGRES_USER: ${POSTGRES_USER:-postgres}
|
|
9
|
-
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
|
|
10
|
-
POSTGRES_DB: ${POSTGRES_DB:-mastra}
|
|
11
|
-
volumes:
|
|
12
|
-
- pgdata:/var/lib/postgresql/data
|
|
13
|
-
volumes:
|
|
14
|
-
pgdata:
|
package/eslint.config.js
DELETED
package/src/index.ts
DELETED
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import { ErrorCategory, ErrorDomain, MastraError } from '@mastra/core/error';
|
|
2
|
-
import type { MetricResult } from '@mastra/core/eval';
|
|
3
|
-
import { LegacyEvalsStorage, TABLE_EVALS } from '@mastra/core/storage';
|
|
4
|
-
import type { PaginationArgs, PaginationInfo, EvalRow } from '@mastra/core/storage';
|
|
5
|
-
import type { IDatabase } from 'pg-promise';
|
|
6
|
-
import { getSchemaName, getTableName } from '../utils';
|
|
7
|
-
|
|
8
|
-
function transformEvalRow(row: Record<string, any>): EvalRow {
|
|
9
|
-
let testInfoValue = null;
|
|
10
|
-
if (row.test_info) {
|
|
11
|
-
try {
|
|
12
|
-
testInfoValue = typeof row.test_info === 'string' ? JSON.parse(row.test_info) : row.test_info;
|
|
13
|
-
} catch (e) {
|
|
14
|
-
console.warn('Failed to parse test_info:', e);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return {
|
|
19
|
-
agentName: row.agent_name as string,
|
|
20
|
-
input: row.input as string,
|
|
21
|
-
output: row.output as string,
|
|
22
|
-
result: row.result as MetricResult,
|
|
23
|
-
metricName: row.metric_name as string,
|
|
24
|
-
instructions: row.instructions as string,
|
|
25
|
-
testInfo: testInfoValue,
|
|
26
|
-
globalRunId: row.global_run_id as string,
|
|
27
|
-
runId: row.run_id as string,
|
|
28
|
-
createdAt: row.created_atZ || (row.created_at as string),
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export class LegacyEvalsPG extends LegacyEvalsStorage {
|
|
33
|
-
private client: IDatabase<{}>;
|
|
34
|
-
private schema: string;
|
|
35
|
-
constructor({ client, schema }: { client: IDatabase<{}>; schema: string }) {
|
|
36
|
-
super();
|
|
37
|
-
this.client = client;
|
|
38
|
-
this.schema = schema;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/** @deprecated use getEvals instead */
|
|
42
|
-
async getEvalsByAgentName(agentName: string, type?: 'test' | 'live'): Promise<EvalRow[]> {
|
|
43
|
-
try {
|
|
44
|
-
const baseQuery = `SELECT * FROM ${getTableName({ indexName: TABLE_EVALS, schemaName: getSchemaName(this.schema) })} WHERE agent_name = $1`;
|
|
45
|
-
const typeCondition =
|
|
46
|
-
type === 'test'
|
|
47
|
-
? " AND test_info IS NOT NULL AND test_info->>'testPath' IS NOT NULL"
|
|
48
|
-
: type === 'live'
|
|
49
|
-
? " AND (test_info IS NULL OR test_info->>'testPath' IS NULL)"
|
|
50
|
-
: '';
|
|
51
|
-
|
|
52
|
-
const query = `${baseQuery}${typeCondition} ORDER BY created_at DESC`;
|
|
53
|
-
|
|
54
|
-
const rows = await this.client.manyOrNone(query, [agentName]);
|
|
55
|
-
return rows?.map(row => transformEvalRow(row)) ?? [];
|
|
56
|
-
} catch (error) {
|
|
57
|
-
// Handle case where table doesn't exist yet
|
|
58
|
-
if (error instanceof Error && error.message.includes('relation') && error.message.includes('does not exist')) {
|
|
59
|
-
return [];
|
|
60
|
-
}
|
|
61
|
-
console.error('Failed to get evals for the specified agent: ' + (error as any)?.message);
|
|
62
|
-
throw error;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
async getEvals(
|
|
67
|
-
options: {
|
|
68
|
-
agentName?: string;
|
|
69
|
-
type?: 'test' | 'live';
|
|
70
|
-
} & PaginationArgs = {},
|
|
71
|
-
): Promise<PaginationInfo & { evals: EvalRow[] }> {
|
|
72
|
-
const tableName = getTableName({ indexName: TABLE_EVALS, schemaName: getSchemaName(this.schema) });
|
|
73
|
-
|
|
74
|
-
const { agentName, type, page = 0, perPage = 100, dateRange } = options;
|
|
75
|
-
const fromDate = dateRange?.start;
|
|
76
|
-
const toDate = dateRange?.end;
|
|
77
|
-
|
|
78
|
-
const conditions: string[] = [];
|
|
79
|
-
const queryParams: any[] = [];
|
|
80
|
-
let paramIndex = 1;
|
|
81
|
-
|
|
82
|
-
if (agentName) {
|
|
83
|
-
conditions.push(`agent_name = $${paramIndex++}`);
|
|
84
|
-
queryParams.push(agentName);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (type === 'test') {
|
|
88
|
-
conditions.push(`(test_info IS NOT NULL AND test_info->>'testPath' IS NOT NULL)`);
|
|
89
|
-
} else if (type === 'live') {
|
|
90
|
-
conditions.push(`(test_info IS NULL OR test_info->>'testPath' IS NULL)`);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (fromDate) {
|
|
94
|
-
conditions.push(`created_at >= $${paramIndex++}`);
|
|
95
|
-
queryParams.push(fromDate);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (toDate) {
|
|
99
|
-
conditions.push(`created_at <= $${paramIndex++}`);
|
|
100
|
-
queryParams.push(toDate);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : '';
|
|
104
|
-
|
|
105
|
-
const countQuery = `SELECT COUNT(*) FROM ${tableName} ${whereClause}`;
|
|
106
|
-
try {
|
|
107
|
-
const countResult = await this.client.one(countQuery, queryParams);
|
|
108
|
-
const total = parseInt(countResult.count, 10);
|
|
109
|
-
const currentOffset = page * perPage;
|
|
110
|
-
|
|
111
|
-
if (total === 0) {
|
|
112
|
-
return {
|
|
113
|
-
evals: [],
|
|
114
|
-
total: 0,
|
|
115
|
-
page,
|
|
116
|
-
perPage,
|
|
117
|
-
hasMore: false,
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const dataQuery = `SELECT * FROM ${tableName} ${whereClause} ORDER BY created_at DESC LIMIT $${paramIndex++} OFFSET $${paramIndex++}`;
|
|
122
|
-
const rows = await this.client.manyOrNone(dataQuery, [...queryParams, perPage, currentOffset]);
|
|
123
|
-
|
|
124
|
-
return {
|
|
125
|
-
evals: rows?.map(row => transformEvalRow(row)) ?? [],
|
|
126
|
-
total,
|
|
127
|
-
page,
|
|
128
|
-
perPage,
|
|
129
|
-
hasMore: currentOffset + (rows?.length ?? 0) < total,
|
|
130
|
-
};
|
|
131
|
-
} catch (error) {
|
|
132
|
-
const mastraError = new MastraError(
|
|
133
|
-
{
|
|
134
|
-
id: 'MASTRA_STORAGE_PG_STORE_GET_EVALS_FAILED',
|
|
135
|
-
domain: ErrorDomain.STORAGE,
|
|
136
|
-
category: ErrorCategory.THIRD_PARTY,
|
|
137
|
-
details: {
|
|
138
|
-
agentName: agentName || 'all',
|
|
139
|
-
type: type || 'all',
|
|
140
|
-
page,
|
|
141
|
-
perPage,
|
|
142
|
-
},
|
|
143
|
-
},
|
|
144
|
-
error,
|
|
145
|
-
);
|
|
146
|
-
this.logger?.error?.(mastraError.toString());
|
|
147
|
-
this.logger?.trackException(mastraError);
|
|
148
|
-
throw mastraError;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|