@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/index.js
CHANGED
|
@@ -7084,6 +7084,12 @@ var ExperimentsPG = class ExperimentsPG extends ExperimentsStorage {
|
|
|
7084
7084
|
name: "idx_experiment_results_org_project",
|
|
7085
7085
|
table: TABLE_EXPERIMENT_RESULTS,
|
|
7086
7086
|
columns: ["organizationId", "projectId"]
|
|
7087
|
+
},
|
|
7088
|
+
{
|
|
7089
|
+
name: "idx_experiment_results_tags_gin",
|
|
7090
|
+
table: TABLE_EXPERIMENT_RESULTS,
|
|
7091
|
+
columns: ["tags"],
|
|
7092
|
+
method: "gin"
|
|
7087
7093
|
}
|
|
7088
7094
|
];
|
|
7089
7095
|
}
|
|
@@ -7692,6 +7698,10 @@ var ExperimentsPG = class ExperimentsPG extends ExperimentsStorage {
|
|
|
7692
7698
|
conditions.push(`"status" = $${paramIndex++}`);
|
|
7693
7699
|
queryParams.push(args.status);
|
|
7694
7700
|
}
|
|
7701
|
+
for (const tag of args.tags ?? []) {
|
|
7702
|
+
conditions.push(`"tags" @> $${paramIndex++}::jsonb`);
|
|
7703
|
+
queryParams.push(JSON.stringify([tag]));
|
|
7704
|
+
}
|
|
7695
7705
|
if (args.filters) {
|
|
7696
7706
|
const { organizationId, projectId } = args.filters;
|
|
7697
7707
|
if (organizationId !== void 0) {
|
|
@@ -16121,6 +16131,26 @@ async function updateFeedbackReviewStatus(client, schema, args) {
|
|
|
16121
16131
|
});
|
|
16122
16132
|
return rowToFeedbackRecord(row);
|
|
16123
16133
|
}
|
|
16134
|
+
/**
|
|
16135
|
+
* Delete feedback events by feedbackId. Optional `organizationId` and
|
|
16136
|
+
* `resourceId` values are ANDed into the predicate to restrict deletion to
|
|
16137
|
+
* records with matching scope fields.
|
|
16138
|
+
*/
|
|
16139
|
+
async function deleteFeedback(client, schema, args) {
|
|
16140
|
+
if (args.feedbackIds.length === 0) return;
|
|
16141
|
+
const table = qualifiedTable(schema, TABLE_FEEDBACK_EVENTS);
|
|
16142
|
+
const values = [...args.feedbackIds];
|
|
16143
|
+
const conditions = [`"feedbackId" IN (${args.feedbackIds.map((_, i) => `$${i + 1}`).join(", ")})`];
|
|
16144
|
+
if (args.organizationId !== void 0) {
|
|
16145
|
+
values.push(args.organizationId);
|
|
16146
|
+
conditions.push(`"organizationId" = $${values.length}`);
|
|
16147
|
+
}
|
|
16148
|
+
if (args.resourceId !== void 0) {
|
|
16149
|
+
values.push(args.resourceId);
|
|
16150
|
+
conditions.push(`"resourceId" = $${values.length}`);
|
|
16151
|
+
}
|
|
16152
|
+
await client.query(`DELETE FROM ${table} WHERE ${conditions.join(" AND ")}`, values);
|
|
16153
|
+
}
|
|
16124
16154
|
async function listFeedback(client, schema, args) {
|
|
16125
16155
|
const { mode, filters, pagination, orderBy, after, limit } = listFeedbackArgsSchema.parse(args);
|
|
16126
16156
|
const table = qualifiedTable(schema, TABLE_FEEDBACK_EVENTS);
|
|
@@ -16881,6 +16911,26 @@ async function batchCreateScores(client, schema, args) {
|
|
|
16881
16911
|
const insert = buildInsert(schema, TABLE_SCORE_EVENTS, args.scores.map(scoreRecordToRow));
|
|
16882
16912
|
if (insert) await client.query(insert.text, insert.values);
|
|
16883
16913
|
}
|
|
16914
|
+
/**
|
|
16915
|
+
* Delete score events by scoreId. Optional `organizationId` and `resourceId`
|
|
16916
|
+
* values are ANDed into the predicate to restrict deletion to records with
|
|
16917
|
+
* matching scope fields.
|
|
16918
|
+
*/
|
|
16919
|
+
async function deleteScores(client, schema, args) {
|
|
16920
|
+
if (args.scoreIds.length === 0) return;
|
|
16921
|
+
const table = qualifiedTable(schema, TABLE_SCORE_EVENTS);
|
|
16922
|
+
const values = [...args.scoreIds];
|
|
16923
|
+
const conditions = [`"scoreId" IN (${args.scoreIds.map((_, i) => `$${i + 1}`).join(", ")})`];
|
|
16924
|
+
if (args.organizationId !== void 0) {
|
|
16925
|
+
values.push(args.organizationId);
|
|
16926
|
+
conditions.push(`"organizationId" = $${values.length}`);
|
|
16927
|
+
}
|
|
16928
|
+
if (args.resourceId !== void 0) {
|
|
16929
|
+
values.push(args.resourceId);
|
|
16930
|
+
conditions.push(`"resourceId" = $${values.length}`);
|
|
16931
|
+
}
|
|
16932
|
+
await client.query(`DELETE FROM ${table} WHERE ${conditions.join(" AND ")}`, values);
|
|
16933
|
+
}
|
|
16884
16934
|
async function listScores(client, schema, args) {
|
|
16885
16935
|
const { mode, filters, pagination, orderBy, after, limit } = listScoresArgsSchema.parse(args);
|
|
16886
16936
|
const table = qualifiedTable(schema, TABLE_SCORE_EVENTS);
|
|
@@ -17057,12 +17107,32 @@ const TRACE_FIELDS = {
|
|
|
17057
17107
|
status: TRACE_STATUS_SQL
|
|
17058
17108
|
};
|
|
17059
17109
|
const SPAN_FIELDS = {
|
|
17110
|
+
name: "s.\"name\"",
|
|
17060
17111
|
spanType: "s.\"spanType\"",
|
|
17061
|
-
|
|
17112
|
+
model: "s.\"model\"",
|
|
17113
|
+
provider: "s.\"provider\"",
|
|
17114
|
+
startedAt: "s.\"startedAt\"",
|
|
17115
|
+
endedAt: "s.\"endedAt\"",
|
|
17116
|
+
durationMs: "s.\"durationMs\"",
|
|
17117
|
+
status: "s.\"status\"",
|
|
17118
|
+
error: "s.\"error\"",
|
|
17119
|
+
entityType: "s.\"entityType\"",
|
|
17120
|
+
entityId: "s.\"entityId\"",
|
|
17121
|
+
entityName: "s.\"entityName\"",
|
|
17122
|
+
entityVersionId: "s.\"entityVersionId\"",
|
|
17123
|
+
parentEntityVersionId: "s.\"parentEntityVersionId\"",
|
|
17124
|
+
rootEntityVersionId: "s.\"rootEntityVersionId\""
|
|
17062
17125
|
};
|
|
17063
17126
|
const SCORE_FIELDS = {
|
|
17064
17127
|
scorerId: "s.\"scorerId\"",
|
|
17065
|
-
|
|
17128
|
+
scorerVersion: "s.\"scorerVersion\"",
|
|
17129
|
+
scoreSource: "s.\"scoreSource\"",
|
|
17130
|
+
score: "s.\"score\"",
|
|
17131
|
+
timestamp: "s.\"timestamp\"",
|
|
17132
|
+
spanId: "s.\"spanId\"",
|
|
17133
|
+
entityVersionId: "s.\"entityVersionId\"",
|
|
17134
|
+
parentEntityVersionId: "s.\"parentEntityVersionId\"",
|
|
17135
|
+
rootEntityVersionId: "s.\"rootEntityVersionId\""
|
|
17066
17136
|
};
|
|
17067
17137
|
const TRACE_SELECT = `
|
|
17068
17138
|
r."traceId" AS "traceId",
|
|
@@ -17080,15 +17150,18 @@ function fieldSql(registry, field) {
|
|
|
17080
17150
|
if (sql === void 0) throw new Error(`Unsupported trusted trace-query field: ${field}`);
|
|
17081
17151
|
return sql;
|
|
17082
17152
|
}
|
|
17153
|
+
function isMetadataField(field) {
|
|
17154
|
+
return field.startsWith("metadata.");
|
|
17155
|
+
}
|
|
17083
17156
|
function placeholders(values, offset) {
|
|
17084
17157
|
return values.map((_, index) => `$${offset + index}`).join(", ");
|
|
17085
17158
|
}
|
|
17086
|
-
function compileScalarPredicate(predicate, registry, parameterOffset) {
|
|
17159
|
+
function compileScalarPredicate(predicate, registry, parameterOffset, allowMetadata = false) {
|
|
17087
17160
|
if (predicate.type === "boolean") {
|
|
17088
17161
|
const values = [];
|
|
17089
17162
|
return {
|
|
17090
17163
|
sql: predicate.args.map((arg) => {
|
|
17091
|
-
const compiled = compileScalarPredicate(arg, registry, parameterOffset + values.length);
|
|
17164
|
+
const compiled = compileScalarPredicate(arg, registry, parameterOffset + values.length, allowMetadata);
|
|
17092
17165
|
values.push(...compiled.values);
|
|
17093
17166
|
return `(${compiled.sql})`;
|
|
17094
17167
|
}).join(predicate.operator === "and" ? " AND " : " OR "),
|
|
@@ -17096,26 +17169,36 @@ function compileScalarPredicate(predicate, registry, parameterOffset) {
|
|
|
17096
17169
|
};
|
|
17097
17170
|
}
|
|
17098
17171
|
if (predicate.type === "not") {
|
|
17099
|
-
const compiled = compileScalarPredicate(predicate.arg, registry, parameterOffset);
|
|
17172
|
+
const compiled = compileScalarPredicate(predicate.arg, registry, parameterOffset, allowMetadata);
|
|
17100
17173
|
return {
|
|
17101
17174
|
sql: `NOT (${compiled.sql})`,
|
|
17102
17175
|
values: compiled.values
|
|
17103
17176
|
};
|
|
17104
17177
|
}
|
|
17105
|
-
|
|
17178
|
+
let field;
|
|
17179
|
+
let fieldValues = [];
|
|
17180
|
+
if (isMetadataField(predicate.field)) {
|
|
17181
|
+
if (!allowMetadata) throw new Error(`Unsupported trusted trace-query field: ${predicate.field}`);
|
|
17182
|
+
const keyParameter = `$${parameterOffset++}`;
|
|
17183
|
+
field = `COALESCE(
|
|
17184
|
+
CASE WHEN jsonb_typeof(r."metadataSearch" -> ${keyParameter}) = 'string' THEN r."metadataSearch" ->> ${keyParameter} END,
|
|
17185
|
+
CASE WHEN jsonb_typeof(r."metadataRaw" -> ${keyParameter}) = 'string' THEN NULLIF(btrim(r."metadataRaw" ->> ${keyParameter}), '') END
|
|
17186
|
+
)`;
|
|
17187
|
+
fieldValues = [predicate.field.slice(9)];
|
|
17188
|
+
} else field = fieldSql(registry, predicate.field);
|
|
17106
17189
|
if (predicate.type === "presence") return {
|
|
17107
17190
|
sql: `${field} IS ${predicate.operator === "exists" ? "NOT " : ""}NULL`,
|
|
17108
|
-
values:
|
|
17191
|
+
values: fieldValues
|
|
17109
17192
|
};
|
|
17110
17193
|
if (predicate.type === "membership") {
|
|
17111
17194
|
const list = placeholders(predicate.values, parameterOffset);
|
|
17112
17195
|
if (predicate.operator === "in") return {
|
|
17113
17196
|
sql: `${field} IS NOT NULL AND ${field} IN (${list})`,
|
|
17114
|
-
values: predicate.values
|
|
17197
|
+
values: [...fieldValues, ...predicate.values]
|
|
17115
17198
|
};
|
|
17116
17199
|
return {
|
|
17117
17200
|
sql: `${field} IS NULL OR ${field} NOT IN (${list})`,
|
|
17118
|
-
values: predicate.values
|
|
17201
|
+
values: [...fieldValues, ...predicate.values]
|
|
17119
17202
|
};
|
|
17120
17203
|
}
|
|
17121
17204
|
const parameter = `$${parameterOffset}`;
|
|
@@ -17127,17 +17210,17 @@ function compileScalarPredicate(predicate, registry, parameterOffset) {
|
|
|
17127
17210
|
};
|
|
17128
17211
|
if (predicate.operator === "eq") return {
|
|
17129
17212
|
sql: `${field} IS NOT DISTINCT FROM ${parameter}`,
|
|
17130
|
-
values: [predicate.value]
|
|
17213
|
+
values: [...fieldValues, predicate.value]
|
|
17131
17214
|
};
|
|
17132
17215
|
if (predicate.operator === "ne") return {
|
|
17133
17216
|
sql: `${field} IS DISTINCT FROM ${parameter}`,
|
|
17134
|
-
values: [predicate.value]
|
|
17217
|
+
values: [...fieldValues, predicate.value]
|
|
17135
17218
|
};
|
|
17136
17219
|
const operator = operators[predicate.operator];
|
|
17137
17220
|
if (operator === void 0) throw new Error(`Unsupported trusted trace-query operator: ${predicate.operator}`);
|
|
17138
17221
|
return {
|
|
17139
17222
|
sql: `${field} IS NOT NULL AND ${field} ${operator} ${parameter}`,
|
|
17140
|
-
values: [predicate.value]
|
|
17223
|
+
values: [...fieldValues, predicate.value]
|
|
17141
17224
|
};
|
|
17142
17225
|
}
|
|
17143
17226
|
function latestRootPredicate$1(spanTable) {
|
|
@@ -17202,7 +17285,7 @@ function compilePredicate(predicate, parameterOffset) {
|
|
|
17202
17285
|
values: compiled.values
|
|
17203
17286
|
};
|
|
17204
17287
|
}
|
|
17205
|
-
return compileScalarPredicate(predicate, TRACE_FIELDS, parameterOffset);
|
|
17288
|
+
return compileScalarPredicate(predicate, TRACE_FIELDS, parameterOffset, true);
|
|
17206
17289
|
}
|
|
17207
17290
|
function compilePostgresTraceQuery(schema, plan) {
|
|
17208
17291
|
const spanTable = qualifiedTable(schema, TABLE_SPAN_EVENTS);
|
|
@@ -17222,14 +17305,43 @@ function compilePostgresTraceQuery(schema, plan) {
|
|
|
17222
17305
|
].join("\n AND ")}
|
|
17223
17306
|
)`];
|
|
17224
17307
|
if (relationCollections.has("spans")) ctes.push(`current_spans AS MATERIALIZED (
|
|
17225
|
-
SELECT
|
|
17308
|
+
SELECT
|
|
17309
|
+
s."traceId",
|
|
17310
|
+
s."name",
|
|
17311
|
+
s."spanType",
|
|
17312
|
+
CASE WHEN jsonb_typeof(s."attributes" -> 'model') = 'string' THEN s."attributes" ->> 'model' END AS "model",
|
|
17313
|
+
CASE WHEN jsonb_typeof(s."attributes" -> 'provider') = 'string' THEN s."attributes" ->> 'provider' END AS "provider",
|
|
17314
|
+
s."startedAt",
|
|
17315
|
+
CASE WHEN s."isPending" THEN NULL ELSE s."endedAt" END AS "endedAt",
|
|
17316
|
+
CASE
|
|
17317
|
+
WHEN s."isPending" THEN NULL
|
|
17318
|
+
ELSE EXTRACT(EPOCH FROM (s."endedAt" - s."startedAt")) * 1000
|
|
17319
|
+
END AS "durationMs",
|
|
17320
|
+
CASE WHEN s."error" IS NOT NULL THEN 'error' ELSE 'success' END AS "status",
|
|
17321
|
+
s."error",
|
|
17322
|
+
s."entityType",
|
|
17323
|
+
s."entityId",
|
|
17324
|
+
s."entityName",
|
|
17325
|
+
s."entityVersionId",
|
|
17326
|
+
s."parentEntityVersionId",
|
|
17327
|
+
s."rootEntityVersionId"
|
|
17226
17328
|
FROM ${spanTable} s
|
|
17227
17329
|
WHERE s."traceId" IS NOT NULL
|
|
17228
17330
|
AND s."traceId" IN (SELECT "traceId" FROM root_scope)
|
|
17229
17331
|
AND ${latestSpanPredicate$1(spanTable)}
|
|
17230
17332
|
)`);
|
|
17231
17333
|
if (relationCollections.has("scores")) ctes.push(`current_scores AS MATERIALIZED (
|
|
17232
|
-
SELECT
|
|
17334
|
+
SELECT
|
|
17335
|
+
s."traceId",
|
|
17336
|
+
s."spanId",
|
|
17337
|
+
s."timestamp",
|
|
17338
|
+
s."scorerId",
|
|
17339
|
+
s."scorerVersion",
|
|
17340
|
+
s."scoreSource",
|
|
17341
|
+
s."score",
|
|
17342
|
+
s."entityVersionId",
|
|
17343
|
+
s."parentEntityVersionId",
|
|
17344
|
+
s."rootEntityVersionId"
|
|
17233
17345
|
FROM ${scoreTable} s
|
|
17234
17346
|
WHERE s."traceId" IS NOT NULL
|
|
17235
17347
|
AND s."traceId" IN (SELECT "traceId" FROM root_scope)
|
|
@@ -18308,6 +18420,12 @@ var ObservabilityStoragePostgresVNext = class ObservabilityStoragePostgresVNext
|
|
|
18308
18420
|
async batchCreateFeedback(args) {
|
|
18309
18421
|
await this.#run("BATCH_CREATE_FEEDBACK", () => batchCreateFeedback(this.#client, this.#schema, args), { count: args.feedbacks.length });
|
|
18310
18422
|
}
|
|
18423
|
+
async deleteScores(args) {
|
|
18424
|
+
await this.#run("DELETE_SCORES", () => deleteScores(this.#client, this.#schema, args), { count: args.scoreIds.length });
|
|
18425
|
+
}
|
|
18426
|
+
async deleteFeedback(args) {
|
|
18427
|
+
await this.#run("DELETE_FEEDBACK", () => deleteFeedback(this.#client, this.#schema, args), { count: args.feedbackIds.length });
|
|
18428
|
+
}
|
|
18311
18429
|
async listLogs(args) {
|
|
18312
18430
|
return this.#run("LIST_LOGS", () => listLogs(this.#readClient, this.#schema, args));
|
|
18313
18431
|
}
|