@mastra/pg 1.23.1-alpha.0 → 1.24.0-alpha.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/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +133 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +133 -15
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/experiments/index.d.ts.map +1 -1
- package/dist/storage/domains/observability/v-next/feedback.d.ts +7 -1
- package/dist/storage/domains/observability/v-next/feedback.d.ts.map +1 -1
- package/dist/storage/domains/observability/v-next/index.d.ts +3 -1
- package/dist/storage/domains/observability/v-next/index.d.ts.map +1 -1
- package/dist/storage/domains/observability/v-next/scores.d.ts +7 -1
- package/dist/storage/domains/observability/v-next/scores.d.ts.map +1 -1
- package/dist/storage/domains/observability/v-next/trace-query.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/docs/SKILL.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -7108,6 +7108,12 @@ var ExperimentsPG = class ExperimentsPG extends _mastra_core_storage.Experiments
|
|
|
7108
7108
|
name: "idx_experiment_results_org_project",
|
|
7109
7109
|
table: _mastra_core_storage.TABLE_EXPERIMENT_RESULTS,
|
|
7110
7110
|
columns: ["organizationId", "projectId"]
|
|
7111
|
+
},
|
|
7112
|
+
{
|
|
7113
|
+
name: "idx_experiment_results_tags_gin",
|
|
7114
|
+
table: _mastra_core_storage.TABLE_EXPERIMENT_RESULTS,
|
|
7115
|
+
columns: ["tags"],
|
|
7116
|
+
method: "gin"
|
|
7111
7117
|
}
|
|
7112
7118
|
];
|
|
7113
7119
|
}
|
|
@@ -7716,6 +7722,10 @@ var ExperimentsPG = class ExperimentsPG extends _mastra_core_storage.Experiments
|
|
|
7716
7722
|
conditions.push(`"status" = $${paramIndex++}`);
|
|
7717
7723
|
queryParams.push(args.status);
|
|
7718
7724
|
}
|
|
7725
|
+
for (const tag of args.tags ?? []) {
|
|
7726
|
+
conditions.push(`"tags" @> $${paramIndex++}::jsonb`);
|
|
7727
|
+
queryParams.push(JSON.stringify([tag]));
|
|
7728
|
+
}
|
|
7719
7729
|
if (args.filters) {
|
|
7720
7730
|
const { organizationId, projectId } = args.filters;
|
|
7721
7731
|
if (organizationId !== void 0) {
|
|
@@ -16145,6 +16155,26 @@ async function updateFeedbackReviewStatus(client, schema, args) {
|
|
|
16145
16155
|
});
|
|
16146
16156
|
return rowToFeedbackRecord(row);
|
|
16147
16157
|
}
|
|
16158
|
+
/**
|
|
16159
|
+
* Delete feedback events by feedbackId. Optional `organizationId` and
|
|
16160
|
+
* `resourceId` values are ANDed into the predicate to restrict deletion to
|
|
16161
|
+
* records with matching scope fields.
|
|
16162
|
+
*/
|
|
16163
|
+
async function deleteFeedback(client, schema, args) {
|
|
16164
|
+
if (args.feedbackIds.length === 0) return;
|
|
16165
|
+
const table = qualifiedTable(schema, TABLE_FEEDBACK_EVENTS);
|
|
16166
|
+
const values = [...args.feedbackIds];
|
|
16167
|
+
const conditions = [`"feedbackId" IN (${args.feedbackIds.map((_, i) => `$${i + 1}`).join(", ")})`];
|
|
16168
|
+
if (args.organizationId !== void 0) {
|
|
16169
|
+
values.push(args.organizationId);
|
|
16170
|
+
conditions.push(`"organizationId" = $${values.length}`);
|
|
16171
|
+
}
|
|
16172
|
+
if (args.resourceId !== void 0) {
|
|
16173
|
+
values.push(args.resourceId);
|
|
16174
|
+
conditions.push(`"resourceId" = $${values.length}`);
|
|
16175
|
+
}
|
|
16176
|
+
await client.query(`DELETE FROM ${table} WHERE ${conditions.join(" AND ")}`, values);
|
|
16177
|
+
}
|
|
16148
16178
|
async function listFeedback(client, schema, args) {
|
|
16149
16179
|
const { mode, filters, pagination, orderBy, after, limit } = _mastra_core_storage.listFeedbackArgsSchema.parse(args);
|
|
16150
16180
|
const table = qualifiedTable(schema, TABLE_FEEDBACK_EVENTS);
|
|
@@ -16905,6 +16935,26 @@ async function batchCreateScores(client, schema, args) {
|
|
|
16905
16935
|
const insert = buildInsert(schema, TABLE_SCORE_EVENTS, args.scores.map(scoreRecordToRow));
|
|
16906
16936
|
if (insert) await client.query(insert.text, insert.values);
|
|
16907
16937
|
}
|
|
16938
|
+
/**
|
|
16939
|
+
* Delete score events by scoreId. Optional `organizationId` and `resourceId`
|
|
16940
|
+
* values are ANDed into the predicate to restrict deletion to records with
|
|
16941
|
+
* matching scope fields.
|
|
16942
|
+
*/
|
|
16943
|
+
async function deleteScores(client, schema, args) {
|
|
16944
|
+
if (args.scoreIds.length === 0) return;
|
|
16945
|
+
const table = qualifiedTable(schema, TABLE_SCORE_EVENTS);
|
|
16946
|
+
const values = [...args.scoreIds];
|
|
16947
|
+
const conditions = [`"scoreId" IN (${args.scoreIds.map((_, i) => `$${i + 1}`).join(", ")})`];
|
|
16948
|
+
if (args.organizationId !== void 0) {
|
|
16949
|
+
values.push(args.organizationId);
|
|
16950
|
+
conditions.push(`"organizationId" = $${values.length}`);
|
|
16951
|
+
}
|
|
16952
|
+
if (args.resourceId !== void 0) {
|
|
16953
|
+
values.push(args.resourceId);
|
|
16954
|
+
conditions.push(`"resourceId" = $${values.length}`);
|
|
16955
|
+
}
|
|
16956
|
+
await client.query(`DELETE FROM ${table} WHERE ${conditions.join(" AND ")}`, values);
|
|
16957
|
+
}
|
|
16908
16958
|
async function listScores(client, schema, args) {
|
|
16909
16959
|
const { mode, filters, pagination, orderBy, after, limit } = _mastra_core_storage.listScoresArgsSchema.parse(args);
|
|
16910
16960
|
const table = qualifiedTable(schema, TABLE_SCORE_EVENTS);
|
|
@@ -17081,12 +17131,32 @@ const TRACE_FIELDS = {
|
|
|
17081
17131
|
status: TRACE_STATUS_SQL
|
|
17082
17132
|
};
|
|
17083
17133
|
const SPAN_FIELDS = {
|
|
17134
|
+
name: "s.\"name\"",
|
|
17084
17135
|
spanType: "s.\"spanType\"",
|
|
17085
|
-
|
|
17136
|
+
model: "s.\"model\"",
|
|
17137
|
+
provider: "s.\"provider\"",
|
|
17138
|
+
startedAt: "s.\"startedAt\"",
|
|
17139
|
+
endedAt: "s.\"endedAt\"",
|
|
17140
|
+
durationMs: "s.\"durationMs\"",
|
|
17141
|
+
status: "s.\"status\"",
|
|
17142
|
+
error: "s.\"error\"",
|
|
17143
|
+
entityType: "s.\"entityType\"",
|
|
17144
|
+
entityId: "s.\"entityId\"",
|
|
17145
|
+
entityName: "s.\"entityName\"",
|
|
17146
|
+
entityVersionId: "s.\"entityVersionId\"",
|
|
17147
|
+
parentEntityVersionId: "s.\"parentEntityVersionId\"",
|
|
17148
|
+
rootEntityVersionId: "s.\"rootEntityVersionId\""
|
|
17086
17149
|
};
|
|
17087
17150
|
const SCORE_FIELDS = {
|
|
17088
17151
|
scorerId: "s.\"scorerId\"",
|
|
17089
|
-
|
|
17152
|
+
scorerVersion: "s.\"scorerVersion\"",
|
|
17153
|
+
scoreSource: "s.\"scoreSource\"",
|
|
17154
|
+
score: "s.\"score\"",
|
|
17155
|
+
timestamp: "s.\"timestamp\"",
|
|
17156
|
+
spanId: "s.\"spanId\"",
|
|
17157
|
+
entityVersionId: "s.\"entityVersionId\"",
|
|
17158
|
+
parentEntityVersionId: "s.\"parentEntityVersionId\"",
|
|
17159
|
+
rootEntityVersionId: "s.\"rootEntityVersionId\""
|
|
17090
17160
|
};
|
|
17091
17161
|
const TRACE_SELECT = `
|
|
17092
17162
|
r."traceId" AS "traceId",
|
|
@@ -17104,15 +17174,18 @@ function fieldSql(registry, field) {
|
|
|
17104
17174
|
if (sql === void 0) throw new Error(`Unsupported trusted trace-query field: ${field}`);
|
|
17105
17175
|
return sql;
|
|
17106
17176
|
}
|
|
17177
|
+
function isMetadataField(field) {
|
|
17178
|
+
return field.startsWith("metadata.");
|
|
17179
|
+
}
|
|
17107
17180
|
function placeholders(values, offset) {
|
|
17108
17181
|
return values.map((_, index) => `$${offset + index}`).join(", ");
|
|
17109
17182
|
}
|
|
17110
|
-
function compileScalarPredicate(predicate, registry, parameterOffset) {
|
|
17183
|
+
function compileScalarPredicate(predicate, registry, parameterOffset, allowMetadata = false) {
|
|
17111
17184
|
if (predicate.type === "boolean") {
|
|
17112
17185
|
const values = [];
|
|
17113
17186
|
return {
|
|
17114
17187
|
sql: predicate.args.map((arg) => {
|
|
17115
|
-
const compiled = compileScalarPredicate(arg, registry, parameterOffset + values.length);
|
|
17188
|
+
const compiled = compileScalarPredicate(arg, registry, parameterOffset + values.length, allowMetadata);
|
|
17116
17189
|
values.push(...compiled.values);
|
|
17117
17190
|
return `(${compiled.sql})`;
|
|
17118
17191
|
}).join(predicate.operator === "and" ? " AND " : " OR "),
|
|
@@ -17120,26 +17193,36 @@ function compileScalarPredicate(predicate, registry, parameterOffset) {
|
|
|
17120
17193
|
};
|
|
17121
17194
|
}
|
|
17122
17195
|
if (predicate.type === "not") {
|
|
17123
|
-
const compiled = compileScalarPredicate(predicate.arg, registry, parameterOffset);
|
|
17196
|
+
const compiled = compileScalarPredicate(predicate.arg, registry, parameterOffset, allowMetadata);
|
|
17124
17197
|
return {
|
|
17125
17198
|
sql: `NOT (${compiled.sql})`,
|
|
17126
17199
|
values: compiled.values
|
|
17127
17200
|
};
|
|
17128
17201
|
}
|
|
17129
|
-
|
|
17202
|
+
let field;
|
|
17203
|
+
let fieldValues = [];
|
|
17204
|
+
if (isMetadataField(predicate.field)) {
|
|
17205
|
+
if (!allowMetadata) throw new Error(`Unsupported trusted trace-query field: ${predicate.field}`);
|
|
17206
|
+
const keyParameter = `$${parameterOffset++}`;
|
|
17207
|
+
field = `COALESCE(
|
|
17208
|
+
CASE WHEN jsonb_typeof(r."metadataSearch" -> ${keyParameter}) = 'string' THEN r."metadataSearch" ->> ${keyParameter} END,
|
|
17209
|
+
CASE WHEN jsonb_typeof(r."metadataRaw" -> ${keyParameter}) = 'string' THEN NULLIF(btrim(r."metadataRaw" ->> ${keyParameter}), '') END
|
|
17210
|
+
)`;
|
|
17211
|
+
fieldValues = [predicate.field.slice(9)];
|
|
17212
|
+
} else field = fieldSql(registry, predicate.field);
|
|
17130
17213
|
if (predicate.type === "presence") return {
|
|
17131
17214
|
sql: `${field} IS ${predicate.operator === "exists" ? "NOT " : ""}NULL`,
|
|
17132
|
-
values:
|
|
17215
|
+
values: fieldValues
|
|
17133
17216
|
};
|
|
17134
17217
|
if (predicate.type === "membership") {
|
|
17135
17218
|
const list = placeholders(predicate.values, parameterOffset);
|
|
17136
17219
|
if (predicate.operator === "in") return {
|
|
17137
17220
|
sql: `${field} IS NOT NULL AND ${field} IN (${list})`,
|
|
17138
|
-
values: predicate.values
|
|
17221
|
+
values: [...fieldValues, ...predicate.values]
|
|
17139
17222
|
};
|
|
17140
17223
|
return {
|
|
17141
17224
|
sql: `${field} IS NULL OR ${field} NOT IN (${list})`,
|
|
17142
|
-
values: predicate.values
|
|
17225
|
+
values: [...fieldValues, ...predicate.values]
|
|
17143
17226
|
};
|
|
17144
17227
|
}
|
|
17145
17228
|
const parameter = `$${parameterOffset}`;
|
|
@@ -17151,17 +17234,17 @@ function compileScalarPredicate(predicate, registry, parameterOffset) {
|
|
|
17151
17234
|
};
|
|
17152
17235
|
if (predicate.operator === "eq") return {
|
|
17153
17236
|
sql: `${field} IS NOT DISTINCT FROM ${parameter}`,
|
|
17154
|
-
values: [predicate.value]
|
|
17237
|
+
values: [...fieldValues, predicate.value]
|
|
17155
17238
|
};
|
|
17156
17239
|
if (predicate.operator === "ne") return {
|
|
17157
17240
|
sql: `${field} IS DISTINCT FROM ${parameter}`,
|
|
17158
|
-
values: [predicate.value]
|
|
17241
|
+
values: [...fieldValues, predicate.value]
|
|
17159
17242
|
};
|
|
17160
17243
|
const operator = operators[predicate.operator];
|
|
17161
17244
|
if (operator === void 0) throw new Error(`Unsupported trusted trace-query operator: ${predicate.operator}`);
|
|
17162
17245
|
return {
|
|
17163
17246
|
sql: `${field} IS NOT NULL AND ${field} ${operator} ${parameter}`,
|
|
17164
|
-
values: [predicate.value]
|
|
17247
|
+
values: [...fieldValues, predicate.value]
|
|
17165
17248
|
};
|
|
17166
17249
|
}
|
|
17167
17250
|
function latestRootPredicate$1(spanTable) {
|
|
@@ -17226,7 +17309,7 @@ function compilePredicate(predicate, parameterOffset) {
|
|
|
17226
17309
|
values: compiled.values
|
|
17227
17310
|
};
|
|
17228
17311
|
}
|
|
17229
|
-
return compileScalarPredicate(predicate, TRACE_FIELDS, parameterOffset);
|
|
17312
|
+
return compileScalarPredicate(predicate, TRACE_FIELDS, parameterOffset, true);
|
|
17230
17313
|
}
|
|
17231
17314
|
function compilePostgresTraceQuery(schema, plan) {
|
|
17232
17315
|
const spanTable = qualifiedTable(schema, TABLE_SPAN_EVENTS);
|
|
@@ -17246,14 +17329,43 @@ function compilePostgresTraceQuery(schema, plan) {
|
|
|
17246
17329
|
].join("\n AND ")}
|
|
17247
17330
|
)`];
|
|
17248
17331
|
if (relationCollections.has("spans")) ctes.push(`current_spans AS MATERIALIZED (
|
|
17249
|
-
SELECT
|
|
17332
|
+
SELECT
|
|
17333
|
+
s."traceId",
|
|
17334
|
+
s."name",
|
|
17335
|
+
s."spanType",
|
|
17336
|
+
CASE WHEN jsonb_typeof(s."attributes" -> 'model') = 'string' THEN s."attributes" ->> 'model' END AS "model",
|
|
17337
|
+
CASE WHEN jsonb_typeof(s."attributes" -> 'provider') = 'string' THEN s."attributes" ->> 'provider' END AS "provider",
|
|
17338
|
+
s."startedAt",
|
|
17339
|
+
CASE WHEN s."isPending" THEN NULL ELSE s."endedAt" END AS "endedAt",
|
|
17340
|
+
CASE
|
|
17341
|
+
WHEN s."isPending" THEN NULL
|
|
17342
|
+
ELSE EXTRACT(EPOCH FROM (s."endedAt" - s."startedAt")) * 1000
|
|
17343
|
+
END AS "durationMs",
|
|
17344
|
+
CASE WHEN s."error" IS NOT NULL THEN 'error' ELSE 'success' END AS "status",
|
|
17345
|
+
s."error",
|
|
17346
|
+
s."entityType",
|
|
17347
|
+
s."entityId",
|
|
17348
|
+
s."entityName",
|
|
17349
|
+
s."entityVersionId",
|
|
17350
|
+
s."parentEntityVersionId",
|
|
17351
|
+
s."rootEntityVersionId"
|
|
17250
17352
|
FROM ${spanTable} s
|
|
17251
17353
|
WHERE s."traceId" IS NOT NULL
|
|
17252
17354
|
AND s."traceId" IN (SELECT "traceId" FROM root_scope)
|
|
17253
17355
|
AND ${latestSpanPredicate$1(spanTable)}
|
|
17254
17356
|
)`);
|
|
17255
17357
|
if (relationCollections.has("scores")) ctes.push(`current_scores AS MATERIALIZED (
|
|
17256
|
-
SELECT
|
|
17358
|
+
SELECT
|
|
17359
|
+
s."traceId",
|
|
17360
|
+
s."spanId",
|
|
17361
|
+
s."timestamp",
|
|
17362
|
+
s."scorerId",
|
|
17363
|
+
s."scorerVersion",
|
|
17364
|
+
s."scoreSource",
|
|
17365
|
+
s."score",
|
|
17366
|
+
s."entityVersionId",
|
|
17367
|
+
s."parentEntityVersionId",
|
|
17368
|
+
s."rootEntityVersionId"
|
|
17257
17369
|
FROM ${scoreTable} s
|
|
17258
17370
|
WHERE s."traceId" IS NOT NULL
|
|
17259
17371
|
AND s."traceId" IN (SELECT "traceId" FROM root_scope)
|
|
@@ -18332,6 +18444,12 @@ var ObservabilityStoragePostgresVNext = class ObservabilityStoragePostgresVNext
|
|
|
18332
18444
|
async batchCreateFeedback(args) {
|
|
18333
18445
|
await this.#run("BATCH_CREATE_FEEDBACK", () => batchCreateFeedback(this.#client, this.#schema, args), { count: args.feedbacks.length });
|
|
18334
18446
|
}
|
|
18447
|
+
async deleteScores(args) {
|
|
18448
|
+
await this.#run("DELETE_SCORES", () => deleteScores(this.#client, this.#schema, args), { count: args.scoreIds.length });
|
|
18449
|
+
}
|
|
18450
|
+
async deleteFeedback(args) {
|
|
18451
|
+
await this.#run("DELETE_FEEDBACK", () => deleteFeedback(this.#client, this.#schema, args), { count: args.feedbackIds.length });
|
|
18452
|
+
}
|
|
18335
18453
|
async listLogs(args) {
|
|
18336
18454
|
return this.#run("LIST_LOGS", () => listLogs(this.#readClient, this.#schema, args));
|
|
18337
18455
|
}
|