@mastra/pg 0.13.3-alpha.0 → 0.14.0-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.
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +24 -0
- package/dist/index.cjs +88 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +88 -29
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/scores/index.d.ts +5 -2
- package/dist/storage/domains/scores/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +13 -6
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/test-utils.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/storage/domains/scores/index.ts +40 -9
- package/src/storage/index.ts +70 -23
- package/src/storage/test-utils.ts +7 -0
package/.turbo/turbo-build.log
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @mastra/pg
|
|
2
2
|
|
|
3
|
+
## 0.14.0-alpha.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 79d34ce: improve cloudflare workers compatibility
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- b32c50d: Filter scores by source
|
|
12
|
+
- Updated dependencies [d5330bf]
|
|
13
|
+
- Updated dependencies [a239d41]
|
|
14
|
+
- Updated dependencies [b32c50d]
|
|
15
|
+
- Updated dependencies [121a3f8]
|
|
16
|
+
- Updated dependencies [ec510e7]
|
|
17
|
+
- @mastra/core@0.13.2-alpha.2
|
|
18
|
+
|
|
19
|
+
## 0.13.3
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- 3e49b7a: Fix PostgreSQL vector metadata filtering for Memory system - changed default minScore to -1 to include all similarity results and added comprehensive metadata filtering tests
|
|
24
|
+
- Updated dependencies [cd0042e]
|
|
25
|
+
- @mastra/core@0.13.1
|
|
26
|
+
|
|
3
27
|
## 0.13.3-alpha.0
|
|
4
28
|
|
|
5
29
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -2296,6 +2296,7 @@ var StoreOperationsPG = class extends storage.StoreOperations {
|
|
|
2296
2296
|
}
|
|
2297
2297
|
};
|
|
2298
2298
|
function transformScoreRow(row) {
|
|
2299
|
+
console.log(`row is`, JSON.stringify(row, null, 2));
|
|
2299
2300
|
return {
|
|
2300
2301
|
...row,
|
|
2301
2302
|
input: storage.safelyParseJSON(row.input),
|
|
@@ -2331,7 +2332,7 @@ var ScoresPG = class extends storage.ScoresStorage {
|
|
|
2331
2332
|
`SELECT * FROM ${getTableName({ indexName: storage.TABLE_SCORERS, schemaName: this.schema })} WHERE id = $1`,
|
|
2332
2333
|
[id]
|
|
2333
2334
|
);
|
|
2334
|
-
return transformScoreRow(result);
|
|
2335
|
+
return result ? transformScoreRow(result) : null;
|
|
2335
2336
|
} catch (error$1) {
|
|
2336
2337
|
throw new error.MastraError(
|
|
2337
2338
|
{
|
|
@@ -2345,12 +2346,31 @@ var ScoresPG = class extends storage.ScoresStorage {
|
|
|
2345
2346
|
}
|
|
2346
2347
|
async getScoresByScorerId({
|
|
2347
2348
|
scorerId,
|
|
2348
|
-
pagination
|
|
2349
|
+
pagination,
|
|
2350
|
+
entityId,
|
|
2351
|
+
entityType,
|
|
2352
|
+
source
|
|
2349
2353
|
}) {
|
|
2350
2354
|
try {
|
|
2355
|
+
const conditions = [`"scorerId" = $1`];
|
|
2356
|
+
const queryParams = [scorerId];
|
|
2357
|
+
let paramIndex = 2;
|
|
2358
|
+
if (entityId) {
|
|
2359
|
+
conditions.push(`"entityId" = $${paramIndex++}`);
|
|
2360
|
+
queryParams.push(entityId);
|
|
2361
|
+
}
|
|
2362
|
+
if (entityType) {
|
|
2363
|
+
conditions.push(`"entityType" = $${paramIndex++}`);
|
|
2364
|
+
queryParams.push(entityType);
|
|
2365
|
+
}
|
|
2366
|
+
if (source) {
|
|
2367
|
+
conditions.push(`"source" = $${paramIndex++}`);
|
|
2368
|
+
queryParams.push(source);
|
|
2369
|
+
}
|
|
2370
|
+
const whereClause = conditions.join(" AND ");
|
|
2351
2371
|
const total = await this.client.oneOrNone(
|
|
2352
|
-
`SELECT COUNT(*) FROM ${getTableName({ indexName: storage.TABLE_SCORERS, schemaName: this.schema })} WHERE
|
|
2353
|
-
|
|
2372
|
+
`SELECT COUNT(*) FROM ${getTableName({ indexName: storage.TABLE_SCORERS, schemaName: this.schema })} WHERE ${whereClause}`,
|
|
2373
|
+
queryParams
|
|
2354
2374
|
);
|
|
2355
2375
|
if (total?.count === "0" || !total?.count) {
|
|
2356
2376
|
return {
|
|
@@ -2364,8 +2384,8 @@ var ScoresPG = class extends storage.ScoresStorage {
|
|
|
2364
2384
|
};
|
|
2365
2385
|
}
|
|
2366
2386
|
const result = await this.client.manyOrNone(
|
|
2367
|
-
`SELECT * FROM ${getTableName({ indexName: storage.TABLE_SCORERS, schemaName: this.schema })} WHERE "
|
|
2368
|
-
[
|
|
2387
|
+
`SELECT * FROM ${getTableName({ indexName: storage.TABLE_SCORERS, schemaName: this.schema })} WHERE ${whereClause} ORDER BY "createdAt" DESC LIMIT $${paramIndex++} OFFSET $${paramIndex++}`,
|
|
2388
|
+
[...queryParams, pagination.perPage, pagination.page * pagination.perPage]
|
|
2369
2389
|
);
|
|
2370
2390
|
return {
|
|
2371
2391
|
pagination: {
|
|
@@ -2389,7 +2409,7 @@ var ScoresPG = class extends storage.ScoresStorage {
|
|
|
2389
2409
|
}
|
|
2390
2410
|
async saveScore(score) {
|
|
2391
2411
|
try {
|
|
2392
|
-
const
|
|
2412
|
+
const id = crypto.randomUUID();
|
|
2393
2413
|
const {
|
|
2394
2414
|
scorer,
|
|
2395
2415
|
preprocessStepResult,
|
|
@@ -2402,10 +2422,11 @@ var ScoresPG = class extends storage.ScoresStorage {
|
|
|
2402
2422
|
entity,
|
|
2403
2423
|
...rest
|
|
2404
2424
|
} = score;
|
|
2425
|
+
console.log(`saving score with id: ${id}`);
|
|
2405
2426
|
await this.operations.insert({
|
|
2406
2427
|
tableName: storage.TABLE_SCORERS,
|
|
2407
2428
|
record: {
|
|
2408
|
-
id
|
|
2429
|
+
id,
|
|
2409
2430
|
...rest,
|
|
2410
2431
|
input: JSON.stringify(input) || "",
|
|
2411
2432
|
output: JSON.stringify(output) || "",
|
|
@@ -2420,7 +2441,7 @@ var ScoresPG = class extends storage.ScoresStorage {
|
|
|
2420
2441
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
2421
2442
|
}
|
|
2422
2443
|
});
|
|
2423
|
-
const scoreFromDb = await this.getScoreById({ id
|
|
2444
|
+
const scoreFromDb = await this.getScoreById({ id });
|
|
2424
2445
|
return { score: scoreFromDb };
|
|
2425
2446
|
} catch (error$1) {
|
|
2426
2447
|
throw new error.MastraError(
|
|
@@ -2856,10 +2877,11 @@ var WorkflowsPG = class extends storage.WorkflowsStorage {
|
|
|
2856
2877
|
|
|
2857
2878
|
// src/storage/index.ts
|
|
2858
2879
|
var PostgresStore = class extends storage.MastraStorage {
|
|
2859
|
-
db;
|
|
2860
|
-
pgp;
|
|
2861
|
-
|
|
2880
|
+
#db;
|
|
2881
|
+
#pgp;
|
|
2882
|
+
#config;
|
|
2862
2883
|
schema;
|
|
2884
|
+
isConnected = false;
|
|
2863
2885
|
stores;
|
|
2864
2886
|
constructor(config) {
|
|
2865
2887
|
try {
|
|
@@ -2880,10 +2902,11 @@ var PostgresStore = class extends storage.MastraStorage {
|
|
|
2880
2902
|
}
|
|
2881
2903
|
}
|
|
2882
2904
|
super({ name: "PostgresStore" });
|
|
2883
|
-
this.pgp = pgPromise__default.default();
|
|
2884
2905
|
this.schema = config.schemaName || "public";
|
|
2885
|
-
this
|
|
2886
|
-
|
|
2906
|
+
this.#config = {
|
|
2907
|
+
max: config.max,
|
|
2908
|
+
idleTimeoutMillis: config.idleTimeoutMillis,
|
|
2909
|
+
...`connectionString` in config ? { connectionString: config.connectionString } : {
|
|
2887
2910
|
host: config.host,
|
|
2888
2911
|
port: config.port,
|
|
2889
2912
|
database: config.database,
|
|
@@ -2891,14 +2914,33 @@ var PostgresStore = class extends storage.MastraStorage {
|
|
|
2891
2914
|
password: config.password,
|
|
2892
2915
|
ssl: config.ssl
|
|
2893
2916
|
}
|
|
2917
|
+
};
|
|
2918
|
+
this.stores = {};
|
|
2919
|
+
} catch (e) {
|
|
2920
|
+
throw new error.MastraError(
|
|
2921
|
+
{
|
|
2922
|
+
id: "MASTRA_STORAGE_PG_STORE_INITIALIZATION_FAILED",
|
|
2923
|
+
domain: error.ErrorDomain.STORAGE,
|
|
2924
|
+
category: error.ErrorCategory.USER
|
|
2925
|
+
},
|
|
2926
|
+
e
|
|
2894
2927
|
);
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2928
|
+
}
|
|
2929
|
+
}
|
|
2930
|
+
async init() {
|
|
2931
|
+
if (this.isConnected) {
|
|
2932
|
+
return;
|
|
2933
|
+
}
|
|
2934
|
+
try {
|
|
2935
|
+
this.isConnected = true;
|
|
2936
|
+
this.#pgp = pgPromise__default.default();
|
|
2937
|
+
this.#db = this.#pgp(this.#config);
|
|
2938
|
+
const operations = new StoreOperationsPG({ client: this.#db, schemaName: this.schema });
|
|
2939
|
+
const scores = new ScoresPG({ client: this.#db, operations, schema: this.schema });
|
|
2940
|
+
const traces = new TracesPG({ client: this.#db, operations, schema: this.schema });
|
|
2941
|
+
const workflows = new WorkflowsPG({ client: this.#db, operations, schema: this.schema });
|
|
2942
|
+
const legacyEvals = new LegacyEvalsPG({ client: this.#db, schema: this.schema });
|
|
2943
|
+
const memory = new MemoryPG({ client: this.#db, schema: this.schema, operations });
|
|
2902
2944
|
this.stores = {
|
|
2903
2945
|
operations,
|
|
2904
2946
|
scores,
|
|
@@ -2907,17 +2949,31 @@ var PostgresStore = class extends storage.MastraStorage {
|
|
|
2907
2949
|
legacyEvals,
|
|
2908
2950
|
memory
|
|
2909
2951
|
};
|
|
2910
|
-
|
|
2952
|
+
await super.init();
|
|
2953
|
+
} catch (error$1) {
|
|
2954
|
+
this.isConnected = false;
|
|
2911
2955
|
throw new error.MastraError(
|
|
2912
2956
|
{
|
|
2913
|
-
id: "
|
|
2957
|
+
id: "MASTRA_STORAGE_POSTGRES_STORE_INIT_FAILED",
|
|
2914
2958
|
domain: error.ErrorDomain.STORAGE,
|
|
2915
|
-
category: error.ErrorCategory.
|
|
2959
|
+
category: error.ErrorCategory.THIRD_PARTY
|
|
2916
2960
|
},
|
|
2917
|
-
|
|
2961
|
+
error$1
|
|
2918
2962
|
);
|
|
2919
2963
|
}
|
|
2920
2964
|
}
|
|
2965
|
+
get db() {
|
|
2966
|
+
if (!this.#db) {
|
|
2967
|
+
throw new Error(`PostgresStore: Store is not initialized, please call "init()" first.`);
|
|
2968
|
+
}
|
|
2969
|
+
return this.#db;
|
|
2970
|
+
}
|
|
2971
|
+
get pgp() {
|
|
2972
|
+
if (!this.#pgp) {
|
|
2973
|
+
throw new Error(`PostgresStore: Store is not initialized, please call "init()" first.`);
|
|
2974
|
+
}
|
|
2975
|
+
return this.#pgp;
|
|
2976
|
+
}
|
|
2921
2977
|
get supports() {
|
|
2922
2978
|
return {
|
|
2923
2979
|
selectByIncludeResourceScope: true,
|
|
@@ -3074,10 +3130,13 @@ var PostgresStore = class extends storage.MastraStorage {
|
|
|
3074
3130
|
return this.stores.scores.getScoreById({ id: _id });
|
|
3075
3131
|
}
|
|
3076
3132
|
async getScoresByScorerId({
|
|
3077
|
-
scorerId
|
|
3078
|
-
pagination
|
|
3133
|
+
scorerId,
|
|
3134
|
+
pagination,
|
|
3135
|
+
entityId,
|
|
3136
|
+
entityType,
|
|
3137
|
+
source
|
|
3079
3138
|
}) {
|
|
3080
|
-
return this.stores.scores.getScoresByScorerId({ scorerId
|
|
3139
|
+
return this.stores.scores.getScoresByScorerId({ scorerId, pagination, entityId, entityType, source });
|
|
3081
3140
|
}
|
|
3082
3141
|
async saveScore(_score) {
|
|
3083
3142
|
return this.stores.scores.saveScore(_score);
|