@mastra/pg 1.31.3-alpha.0 → 1.32.0-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/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +92 -33
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +92 -33
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/datasets/index.d.ts.map +1 -1
- package/dist/storage/domains/observability/v-next/index.d.ts +1 -1
- package/dist/storage/domains/observability/v-next/index.d.ts.map +1 -1
- package/dist/storage/domains/observability/v-next/metrics.d.ts.map +1 -1
- package/dist/storage/domains/observability/v-next/preview-compat.d.ts +18 -12
- package/dist/storage/domains/observability/v-next/preview-compat.d.ts.map +1 -1
- package/dist/storage/domains/observability/v-next/span-query.d.ts +18 -12
- package/dist/storage/domains/observability/v-next/span-query.d.ts.map +1 -1
- package/dist/storage/domains/observability/v-next/trace-query.d.ts +1 -1
- package/dist/storage/domains/observability/v-next/trace-query.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/docs/SKILL.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -6327,7 +6327,11 @@ var DatasetsPG = class DatasetsPG extends _mastra_core_storage.DatasetsStorage {
|
|
|
6327
6327
|
const queryParams = [];
|
|
6328
6328
|
let paramIndex = 1;
|
|
6329
6329
|
if (args.filters) {
|
|
6330
|
-
const { organizationId, projectId, candidateKey, candidateId, targetType, targetIds, name } = args.filters;
|
|
6330
|
+
const { organizationId, projectId, candidateKey, candidateId, targetType, targetIds, datasetIds, name } = args.filters;
|
|
6331
|
+
if (datasetIds !== void 0) {
|
|
6332
|
+
conditions.push(`"id" = ANY($${paramIndex++}::text[])`);
|
|
6333
|
+
queryParams.push(datasetIds);
|
|
6334
|
+
}
|
|
6331
6335
|
if (organizationId !== void 0) {
|
|
6332
6336
|
conditions.push(`"organizationId" = $${paramIndex++}`);
|
|
6333
6337
|
queryParams.push(organizationId);
|
|
@@ -17118,9 +17122,27 @@ function readPreview(preview, payload, jsonEncoded = false) {
|
|
|
17118
17122
|
}
|
|
17119
17123
|
/** Older response builders may shorten previews or turn empty strings into null. */
|
|
17120
17124
|
function buildSpanQueryResponse(...args) {
|
|
17121
|
-
|
|
17122
|
-
const
|
|
17123
|
-
|
|
17125
|
+
const [plan, selected, payloads, metrics = []] = args;
|
|
17126
|
+
const compatibleSelected = _mastra_core_storage.SPAN_QUERY_FIELD_REGISTRY ? selected : selected.map((row) => ({
|
|
17127
|
+
organizationId: row.organizationId,
|
|
17128
|
+
resourceId: row.resourceId,
|
|
17129
|
+
traceId: row.traceId,
|
|
17130
|
+
spanId: row.spanId,
|
|
17131
|
+
parentSpanId: row.parentSpanId,
|
|
17132
|
+
name: row.name,
|
|
17133
|
+
spanType: row.spanType,
|
|
17134
|
+
status: row.status,
|
|
17135
|
+
startedAt: row.startedAt,
|
|
17136
|
+
endedAt: row.endedAt,
|
|
17137
|
+
durationMs: row.durationMs,
|
|
17138
|
+
entityType: row.entityType,
|
|
17139
|
+
entityId: row.entityId,
|
|
17140
|
+
entityName: row.entityName,
|
|
17141
|
+
model: row.model,
|
|
17142
|
+
provider: row.provider
|
|
17143
|
+
}));
|
|
17144
|
+
if (canGeneratePreviews) return _mastra_core_storage.buildSpanQueryResponse(plan, compatibleSelected, payloads, metrics);
|
|
17145
|
+
const response = _mastra_core_storage.buildSpanQueryResponse(plan, compatibleSelected, [], metrics);
|
|
17124
17146
|
const byIdentity = new Map(payloads.map((payload) => [_mastra_core_storage.spanQueryIdentityKey(payload), payload]));
|
|
17125
17147
|
for (const span of response.spans) {
|
|
17126
17148
|
const payload = byIdentity.get(_mastra_core_storage.spanQueryIdentityKey(span));
|
|
@@ -18390,6 +18412,7 @@ async function listLogsDelta(client, table, filters, after, limit) {
|
|
|
18390
18412
|
function applyMetricFilters(acc, filters) {
|
|
18391
18413
|
applyCommonFilters(acc, filters);
|
|
18392
18414
|
applySingleOrArrayFilter(acc, "traceId", filters?.traceIds);
|
|
18415
|
+
applySingleOrArrayFilter(acc, "experimentId", filters?.experimentIds);
|
|
18393
18416
|
applySingleOrArrayFilter(acc, "name", filters?.name);
|
|
18394
18417
|
applySingleOrArrayFilter(acc, "provider", filters?.provider);
|
|
18395
18418
|
applySingleOrArrayFilter(acc, "model", filters?.model);
|
|
@@ -19216,6 +19239,25 @@ const SPAN_FIELDS = {
|
|
|
19216
19239
|
userId: "s.\"userId\"",
|
|
19217
19240
|
organizationId: "s.\"organizationId\""
|
|
19218
19241
|
};
|
|
19242
|
+
const SPAN_QUERY_FIELDS = {
|
|
19243
|
+
...SPAN_FIELDS,
|
|
19244
|
+
traceId: "s.\"traceId\"",
|
|
19245
|
+
spanId: "s.\"spanId\"",
|
|
19246
|
+
parentSpanId: "s.\"parentSpanId\"",
|
|
19247
|
+
threadId: "s.\"threadId\"",
|
|
19248
|
+
resourceId: "s.\"resourceId\"",
|
|
19249
|
+
requestId: "s.\"requestId\"",
|
|
19250
|
+
serviceName: "s.\"serviceName\"",
|
|
19251
|
+
experimentId: "s.\"experimentId\"",
|
|
19252
|
+
environment: "s.\"environment\"",
|
|
19253
|
+
executionSource: "s.\"executionSource\"",
|
|
19254
|
+
parentEntityType: "s.\"parentEntityType\"",
|
|
19255
|
+
parentEntityId: "s.\"parentEntityId\"",
|
|
19256
|
+
parentEntityName: "s.\"parentEntityName\"",
|
|
19257
|
+
rootEntityType: "s.\"rootEntityType\"",
|
|
19258
|
+
rootEntityId: "s.\"rootEntityId\"",
|
|
19259
|
+
rootEntityName: "s.\"rootEntityName\""
|
|
19260
|
+
};
|
|
19219
19261
|
const SCORE_FIELDS = {
|
|
19220
19262
|
scorerId: "s.\"scorerId\"",
|
|
19221
19263
|
scorerVersion: "s.\"scorerVersion\"",
|
|
@@ -20107,9 +20149,9 @@ async function queryThreads(client, schema, plan, timeoutMs) {
|
|
|
20107
20149
|
}) : null }
|
|
20108
20150
|
});
|
|
20109
20151
|
}
|
|
20110
|
-
/** Compile a span-
|
|
20152
|
+
/** Compile a direct span-query filter using its dedicated field mapping. */
|
|
20111
20153
|
function compileSpanQueryPredicate(predicate, offset) {
|
|
20112
|
-
return compileScalarPredicate(predicate,
|
|
20154
|
+
return compileScalarPredicate(predicate, SPAN_QUERY_FIELDS, offset);
|
|
20113
20155
|
}
|
|
20114
20156
|
//#endregion
|
|
20115
20157
|
//#region src/storage/domains/observability/v-next/span-query.ts
|
|
@@ -20128,11 +20170,23 @@ const fields = [
|
|
|
20128
20170
|
"entityId",
|
|
20129
20171
|
"entityName",
|
|
20130
20172
|
"entityVersionId",
|
|
20173
|
+
"parentEntityType",
|
|
20174
|
+
"parentEntityId",
|
|
20175
|
+
"parentEntityName",
|
|
20131
20176
|
"parentEntityVersionId",
|
|
20177
|
+
"rootEntityType",
|
|
20178
|
+
"rootEntityId",
|
|
20179
|
+
"rootEntityName",
|
|
20132
20180
|
"rootEntityVersionId",
|
|
20181
|
+
"threadId",
|
|
20133
20182
|
"runId",
|
|
20134
20183
|
"sessionId",
|
|
20135
|
-
"userId"
|
|
20184
|
+
"userId",
|
|
20185
|
+
"requestId",
|
|
20186
|
+
"serviceName",
|
|
20187
|
+
"experimentId",
|
|
20188
|
+
"environment",
|
|
20189
|
+
"executionSource"
|
|
20136
20190
|
];
|
|
20137
20191
|
const identities = identityFields.map((field) => `"${field}"`).join(", ");
|
|
20138
20192
|
const identityOrder = identityFields.map((field) => `"${field}" COLLATE "C" ASC NULLS LAST`).join(", ");
|
|
@@ -20182,6 +20236,8 @@ function compilePostgresSpanQuery(schema, plan) {
|
|
|
20182
20236
|
const after = afterCursor(plan, values);
|
|
20183
20237
|
values.push(plan.limit + 1);
|
|
20184
20238
|
const table = qualifiedTable(schema, TABLE_SPAN_EVENTS);
|
|
20239
|
+
const legacyModelFields = _mastra_core_storage.SPAN_QUERY_FIELD_REGISTRY ? "" : `CASE WHEN jsonb_typeof(attributes -> 'model') = 'string' THEN attributes ->> 'model' END AS model,
|
|
20240
|
+
CASE WHEN jsonb_typeof(attributes -> 'provider') = 'string' THEN attributes ->> 'provider' END AS provider,`;
|
|
20185
20241
|
return {
|
|
20186
20242
|
text: `WITH candidate_ids AS MATERIALIZED (
|
|
20187
20243
|
SELECT DISTINCT ${identities} FROM ${table}
|
|
@@ -20190,8 +20246,7 @@ function compilePostgresSpanQuery(schema, plan) {
|
|
|
20190
20246
|
), current_spans AS MATERIALIZED (
|
|
20191
20247
|
SELECT DISTINCT ON (${identities})
|
|
20192
20248
|
${fields.map((field) => `"${field}"`).join(", ")}, "startedAt", "endedAt", "cursorId"::text AS version,
|
|
20193
|
-
|
|
20194
|
-
CASE WHEN jsonb_typeof(attributes -> 'provider') = 'string' THEN attributes ->> 'provider' END AS provider,
|
|
20249
|
+
${legacyModelFields}
|
|
20195
20250
|
(EXTRACT(EPOCH FROM ("endedAt" - "startedAt")) * 1000)::float8 AS "durationMs",
|
|
20196
20251
|
CASE WHEN error IS NULL THEN 'success' ELSE 'error' END AS status,
|
|
20197
20252
|
error IS NOT NULL AS "hasError"
|
|
@@ -20206,15 +20261,7 @@ function compilePostgresSpanQuery(schema, plan) {
|
|
|
20206
20261
|
SELECT *, CASE WHEN "hasError" THEN 'error' ELSE NULL END AS error FROM current_spans
|
|
20207
20262
|
)
|
|
20208
20263
|
SELECT ${[
|
|
20209
|
-
...
|
|
20210
|
-
"parentSpanId",
|
|
20211
|
-
"name",
|
|
20212
|
-
"spanType",
|
|
20213
|
-
"entityType",
|
|
20214
|
-
"entityId",
|
|
20215
|
-
"entityName",
|
|
20216
|
-
"model",
|
|
20217
|
-
"provider",
|
|
20264
|
+
...fields,
|
|
20218
20265
|
"startedAt",
|
|
20219
20266
|
"endedAt",
|
|
20220
20267
|
"durationMs",
|
|
@@ -20261,7 +20308,7 @@ async function querySpans(client, schema, plan, timeoutMs) {
|
|
|
20261
20308
|
endedAt: endedAt.toISOString()
|
|
20262
20309
|
}));
|
|
20263
20310
|
const page = rows.slice(0, plan.limit);
|
|
20264
|
-
if (!page.length) return
|
|
20311
|
+
if (!page.length) return buildSpanQueryResponse(plan, [], []);
|
|
20265
20312
|
const remaining = async () => {
|
|
20266
20313
|
const ms = Math.floor(deadline - performance.now());
|
|
20267
20314
|
if (ms <= 0) throw new _mastra_core_storage.TraceQueryExecutionError();
|
|
@@ -20274,20 +20321,32 @@ async function querySpans(client, schema, plan, timeoutMs) {
|
|
|
20274
20321
|
payloadValues.push(row.version);
|
|
20275
20322
|
return `(${key} AND "cursorId" = $${payloadValues.length}::bigint)`;
|
|
20276
20323
|
}).join(" OR ");
|
|
20277
|
-
const
|
|
20324
|
+
const payloadRows = await tx.any(`SELECT ${identities},
|
|
20325
|
+
CASE WHEN jsonb_typeof(attributes -> 'model') = 'string' THEN attributes ->> 'model' END AS model,
|
|
20326
|
+
CASE WHEN jsonb_typeof(attributes -> 'provider') = 'string' THEN attributes ->> 'provider' END AS provider,
|
|
20278
20327
|
${PREVIEW_PAYLOADS$1.map(([preview, payload]) => `"${preview}", CASE WHEN ${missingPreviewSql(`"${preview}"`)} THEN "${payload}" END AS "${payload}"`).join(",\n ")}
|
|
20279
|
-
FROM ${qualifiedTable(schema, TABLE_SPAN_EVENTS)} WHERE ${payloadWhere}`, payloadValues)
|
|
20280
|
-
|
|
20281
|
-
const
|
|
20282
|
-
const
|
|
20283
|
-
|
|
20284
|
-
|
|
20285
|
-
|
|
20286
|
-
|
|
20287
|
-
|
|
20288
|
-
|
|
20289
|
-
|
|
20290
|
-
|
|
20328
|
+
FROM ${qualifiedTable(schema, TABLE_SPAN_EVENTS)} WHERE ${payloadWhere}`, payloadValues);
|
|
20329
|
+
const payloads = payloadRows.map(toSpanQueryPayload);
|
|
20330
|
+
const metadata = new Map(payloadRows.map((row) => [_mastra_core_storage.spanQueryIdentityKey(row), row]));
|
|
20331
|
+
const hydrated = selected.map((row) => ({
|
|
20332
|
+
...row,
|
|
20333
|
+
model: metadata.get(_mastra_core_storage.spanQueryIdentityKey(row))?.model ?? null,
|
|
20334
|
+
provider: metadata.get(_mastra_core_storage.spanQueryIdentityKey(row))?.provider ?? null
|
|
20335
|
+
}));
|
|
20336
|
+
let metrics = [];
|
|
20337
|
+
if (!_mastra_core_storage.SPAN_QUERY_FIELD_REGISTRY) {
|
|
20338
|
+
await remaining();
|
|
20339
|
+
const metricValues = [];
|
|
20340
|
+
const metricWhere = selectedKeys(page, metricValues);
|
|
20341
|
+
metrics = await tx.any(`SELECT ${identities}, name, "estimatedCost", "costUnit",
|
|
20342
|
+
"costMetadata" ->> 'allocation' AS allocation, COALESCE("costMetadata" ? 'error', false) AS "costError"
|
|
20343
|
+
FROM (SELECT DISTINCT ON (${identities}, "metricId") ${identities}, name, "estimatedCost", "costUnit", "costMetadata" FROM ${qualifiedTable(schema, TABLE_METRIC_EVENTS)}
|
|
20344
|
+
WHERE (${metricWhere}) AND name LIKE 'mastra_model_%'
|
|
20345
|
+
ORDER BY ${identities}, "metricId", "cursorId" DESC) m
|
|
20346
|
+
LIMIT ${_mastra_core_storage.SPAN_QUERY_MAX_COST_METRICS + 1}`, metricValues);
|
|
20347
|
+
if (metrics.length > _mastra_core_storage.SPAN_QUERY_MAX_COST_METRICS) throw new _mastra_core_storage.TraceQueryResourceLimitError();
|
|
20348
|
+
}
|
|
20349
|
+
return buildSpanQueryResponse(plan, hydrated, payloads, metrics);
|
|
20291
20350
|
}, { repeatableRead: true });
|
|
20292
20351
|
}
|
|
20293
20352
|
//#endregion
|
|
@@ -21331,7 +21390,7 @@ async function dangerouslyClearTracing(client, schema) {
|
|
|
21331
21390
|
* application database — observability writes will degrade app performance.
|
|
21332
21391
|
* Use it through `MastraCompositeStore` with a dedicated Postgres connection.
|
|
21333
21392
|
*/
|
|
21334
|
-
const spanQueryFeatures = typeof _mastra_core_storage.planSpanQuery === "function" ? ["span-query"] : [];
|
|
21393
|
+
const spanQueryFeatures = typeof _mastra_core_storage.planSpanQuery === "function" ? ["span-query", "span-query-context-fields"] : [];
|
|
21335
21394
|
function wrapError(op, error, details) {
|
|
21336
21395
|
if (error instanceof _mastra_core_error.MastraError || error instanceof _mastra_core_storage.TraceQueryCursorError || error instanceof _mastra_core_storage.TraceQueryExecutionError || error instanceof _mastra_core_storage.TraceQueryResourceLimitError) throw error;
|
|
21337
21396
|
throw new _mastra_core_error.MastraError({
|