@mastra/duckdb 1.16.0-alpha.0 → 1.16.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/docs/references/reference-storage-retention.md +1 -1
- package/dist/docs/references/reference-vectors-duckdb.md +5 -5
- package/dist/{features-uOeZunqR.js → features-B8gl38Ue.js} +3 -5
- package/dist/{features-uOeZunqR.js.map → features-B8gl38Ue.js.map} +1 -1
- package/dist/{features-CEjjQRE6.cjs → features-DH60yLCA.cjs} +4 -7
- package/dist/{features-CEjjQRE6.cjs.map → features-DH60yLCA.cjs.map} +1 -1
- package/dist/index.cjs +7 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +7 -8
- package/dist/index.js.map +1 -1
- package/dist/{observability-DCB8fs52.cjs → observability-B-Vnz-ZL.cjs} +22 -67
- package/dist/observability-B-Vnz-ZL.cjs.map +1 -0
- package/dist/{observability-Bv3eObB-.js → observability-BWSYzhM2.js} +22 -67
- package/dist/observability-BWSYzhM2.js.map +1 -0
- package/dist/storage/domains/observability/thread-query.d.ts +0 -2
- package/dist/storage/domains/observability/thread-query.d.ts.map +1 -1
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +10 -10
- package/dist/observability-Bv3eObB-.js.map +0 -1
- package/dist/observability-DCB8fs52.cjs.map +0 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { a as timeToFirstChunkSupported, i as timeToFirstChunkFeatures, n as spanQueryFeatures, o as DuckDBConnection, s as DuckDBQueryTimeoutError, t as spanAggregateFeatures } from "./features-
|
|
1
|
+
import { a as timeToFirstChunkSupported, i as timeToFirstChunkFeatures, n as spanQueryFeatures, o as DuckDBConnection, s as DuckDBQueryTimeoutError, t as spanAggregateFeatures } from "./features-B8gl38Ue.js";
|
|
2
2
|
import { ErrorCategory, ErrorDomain, MastraError } from "@mastra/core/error";
|
|
3
3
|
import * as coreStorage from "@mastra/core/storage";
|
|
4
4
|
import { BRANCH_SPAN_TYPES, METRIC_DISTINCT_COLUMNS, ObservabilityStorage, computeTraceStatus, createStorageErrorId, executeRetentionPrune, feedbackRecordSchema, listBranchesArgsSchema, listFeedbackArgsSchema, listLogsArgsSchema, listMetricsArgsSchema, listScoresArgsSchema, listTracesArgsSchema, resolveRetentionTargets, retentionCutoffMs, toTraceSpans } from "@mastra/core/storage";
|
|
5
5
|
import { coreFeatures } from "@mastra/core/features";
|
|
6
6
|
import { EntityType } from "@mastra/core/observability";
|
|
7
7
|
import { parseFieldKey } from "@mastra/core/utils";
|
|
8
|
-
|
|
8
|
+
// src/storage/retention.ts
|
|
9
9
|
function cutoffFor(policy, now = Date.now()) {
|
|
10
10
|
return new Date(retentionCutoffMs(policy, now));
|
|
11
11
|
}
|
|
@@ -30,8 +30,7 @@ function resolveTargets({ policies, descriptor, order }) {
|
|
|
30
30
|
order
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
|
-
|
|
34
|
-
//#region src/storage/domains/observability/ddl.ts
|
|
33
|
+
// src/storage/domains/observability/ddl.ts
|
|
35
34
|
/**
|
|
36
35
|
* DDL statements for DuckDB observability tables.
|
|
37
36
|
* All tables use append-only patterns with a single `timestamp` column.
|
|
@@ -493,8 +492,7 @@ const ALL_MIGRATIONS = [
|
|
|
493
492
|
`ALTER TABLE feedback_events ADD COLUMN IF NOT EXISTS reviewStatus VARCHAR DEFAULT 'needs-review'`,
|
|
494
493
|
`ALTER TABLE feedback_events ALTER COLUMN traceId DROP NOT NULL`
|
|
495
494
|
];
|
|
496
|
-
|
|
497
|
-
//#region src/storage/domains/observability/discovery.ts
|
|
495
|
+
// src/storage/domains/observability/discovery.ts
|
|
498
496
|
function unionDistinctQueries(selects, orderBy) {
|
|
499
497
|
return `${selects.join("\nUNION\n")}\nORDER BY ${orderBy}`;
|
|
500
498
|
}
|
|
@@ -562,8 +560,7 @@ async function getTags(db, args) {
|
|
|
562
560
|
buildSelect("log_events")
|
|
563
561
|
], "tag"), params)).map((r) => r.tag) };
|
|
564
562
|
}
|
|
565
|
-
|
|
566
|
-
//#region src/storage/domains/observability/filters.ts
|
|
563
|
+
// src/storage/domains/observability/filters.ts
|
|
567
564
|
function buildJsonPath(key) {
|
|
568
565
|
try {
|
|
569
566
|
return `$.${parseFieldKey(key)}`;
|
|
@@ -713,8 +710,7 @@ function buildPaginationClause(pagination) {
|
|
|
713
710
|
params: [pagination.perPage, offset]
|
|
714
711
|
};
|
|
715
712
|
}
|
|
716
|
-
|
|
717
|
-
//#region src/storage/domains/observability/preview-compat.ts
|
|
713
|
+
// src/storage/domains/observability/preview-compat.ts
|
|
718
714
|
const generator = coreStorage.buildStoredPreview;
|
|
719
715
|
const canGeneratePreviews = typeof generator === "function";
|
|
720
716
|
/** SQL detection only; preview formatting stays in TypeScript. Empty strings are intentional. */
|
|
@@ -771,8 +767,7 @@ function buildSpanQueryResponse(...args) {
|
|
|
771
767
|
}
|
|
772
768
|
return response;
|
|
773
769
|
}
|
|
774
|
-
|
|
775
|
-
//#region src/storage/domains/observability/helpers.ts
|
|
770
|
+
// src/storage/domains/observability/helpers.ts
|
|
776
771
|
/** Shorthand for {@link DuckDBConnection.sqlValue}. */
|
|
777
772
|
const v = DuckDBConnection.sqlValue;
|
|
778
773
|
/** Serialize a value to JSON then SQL-escape it, or return 'NULL'. */
|
|
@@ -864,8 +859,7 @@ function previewFromPayload(value) {
|
|
|
864
859
|
function apiPreview(value) {
|
|
865
860
|
return readPreview(value);
|
|
866
861
|
}
|
|
867
|
-
|
|
868
|
-
//#region src/storage/domains/observability/polling.ts
|
|
862
|
+
// src/storage/domains/observability/polling.ts
|
|
869
863
|
const OBSERVABILITY_DELTA_POLLING_FEATURE = "observability-delta-polling";
|
|
870
864
|
function deltaPollingFeatureEnabled() {
|
|
871
865
|
return coreFeatures.has(OBSERVABILITY_DELTA_POLLING_FEATURE);
|
|
@@ -897,8 +891,7 @@ function extendWhereClause(baseClause, extraConditions) {
|
|
|
897
891
|
if (!baseClause) return `WHERE ${conditions.join(" AND ")}`;
|
|
898
892
|
return `${baseClause} AND ${conditions.join(" AND ")}`;
|
|
899
893
|
}
|
|
900
|
-
|
|
901
|
-
//#region src/storage/domains/observability/review-status.ts
|
|
894
|
+
// src/storage/domains/observability/review-status.ts
|
|
902
895
|
const FEEDBACK_REVIEW_STATUSES = ["needs-review", "reviewed"];
|
|
903
896
|
function isFeedbackReviewStatus(value) {
|
|
904
897
|
return FEEDBACK_REVIEW_STATUSES.some((status) => status === value);
|
|
@@ -922,8 +915,7 @@ function parseUpdateFeedbackReviewStatusArgs(args) {
|
|
|
922
915
|
reviewStatus: args.reviewStatus
|
|
923
916
|
};
|
|
924
917
|
}
|
|
925
|
-
|
|
926
|
-
//#region src/storage/domains/observability/feedback.ts
|
|
918
|
+
// src/storage/domains/observability/feedback.ts
|
|
927
919
|
const FEEDBACK_UPSERT_CLAUSE = `ON CONFLICT (feedbackId) DO UPDATE SET ${[
|
|
928
920
|
"timestamp",
|
|
929
921
|
"cursorId",
|
|
@@ -1452,8 +1444,7 @@ async function getFeedbackPercentiles(db, args) {
|
|
|
1452
1444
|
}
|
|
1453
1445
|
return { series };
|
|
1454
1446
|
}
|
|
1455
|
-
|
|
1456
|
-
//#region src/storage/domains/observability/logs.ts
|
|
1447
|
+
// src/storage/domains/observability/logs.ts
|
|
1457
1448
|
const COLUMNS_SQL$1 = [
|
|
1458
1449
|
"logId",
|
|
1459
1450
|
"timestamp",
|
|
@@ -1636,8 +1627,7 @@ async function getDeltaCursor$2(db, filterClause, filterParams) {
|
|
|
1636
1627
|
async function getStreamHeadCursor$2(db) {
|
|
1637
1628
|
return encodeDeltaCursor((await db.query(`SELECT max(cursorId) AS cursorId FROM log_events`))[0]?.cursorId);
|
|
1638
1629
|
}
|
|
1639
|
-
|
|
1640
|
-
//#region src/storage/domains/observability/metrics.ts
|
|
1630
|
+
// src/storage/domains/observability/metrics.ts
|
|
1641
1631
|
const METRIC_FILTER_FIELD_MAPPINGS = {
|
|
1642
1632
|
traceIds: "traceId",
|
|
1643
1633
|
experimentIds: "experimentId"
|
|
@@ -2170,8 +2160,7 @@ async function getMetricLabelValues(db, args) {
|
|
|
2170
2160
|
if (args.limit) params.push(args.limit);
|
|
2171
2161
|
return { values: (await db.query(`SELECT DISTINCT json_extract_string(labels, ?) AS val FROM metric_events WHERE ${conditions.join(" AND ")} ORDER BY val ${limitClause}`, [labelPath, ...params])).map((r) => r.val) };
|
|
2172
2162
|
}
|
|
2173
|
-
|
|
2174
|
-
//#region src/storage/domains/observability/migration.ts
|
|
2163
|
+
// src/storage/domains/observability/migration.ts
|
|
2175
2164
|
const CURSOR_ID_TABLES = [
|
|
2176
2165
|
"span_events",
|
|
2177
2166
|
"metric_events",
|
|
@@ -2320,8 +2309,7 @@ async function migrateSignalTables(db, logger) {
|
|
|
2320
2309
|
}
|
|
2321
2310
|
}
|
|
2322
2311
|
}
|
|
2323
|
-
|
|
2324
|
-
//#region src/storage/domains/observability/scores.ts
|
|
2312
|
+
// src/storage/domains/observability/scores.ts
|
|
2325
2313
|
const SCORE_UPSERT_CLAUSE = `ON CONFLICT (scoreId) DO UPDATE SET ${[
|
|
2326
2314
|
"timestamp",
|
|
2327
2315
|
"traceId",
|
|
@@ -2832,8 +2820,7 @@ async function getScorePercentiles(db, args) {
|
|
|
2832
2820
|
}
|
|
2833
2821
|
return { series };
|
|
2834
2822
|
}
|
|
2835
|
-
|
|
2836
|
-
//#region src/storage/domains/observability/trace-query.ts
|
|
2823
|
+
// src/storage/domains/observability/trace-query.ts
|
|
2837
2824
|
const TRACE_STATUS_SQL = `CASE WHEN r.error IS NOT NULL THEN 'error' ELSE 'success' END`;
|
|
2838
2825
|
function durationMsSql(startedAt, endedAt) {
|
|
2839
2826
|
return `date_diff('millisecond', ${startedAt}, ${endedAt})`;
|
|
@@ -3960,8 +3947,7 @@ function compileThreadQueryPredicate(predicate) {
|
|
|
3960
3947
|
parameterType: rule.valueKind === "timestamp" ? "timestamp" : "scalar"
|
|
3961
3948
|
}])));
|
|
3962
3949
|
}
|
|
3963
|
-
|
|
3964
|
-
//#region src/storage/domains/observability/span-query.ts
|
|
3950
|
+
// src/storage/domains/observability/span-query.ts
|
|
3965
3951
|
const identityFields = [
|
|
3966
3952
|
"organizationId",
|
|
3967
3953
|
"resourceId",
|
|
@@ -4178,8 +4164,7 @@ async function querySpans(db, plan) {
|
|
|
4178
4164
|
}
|
|
4179
4165
|
return buildSpanQueryResponse(plan, hydrated, payloads, metrics);
|
|
4180
4166
|
}
|
|
4181
|
-
|
|
4182
|
-
//#region src/storage/domains/observability/thread-query.ts
|
|
4167
|
+
// src/storage/domains/observability/thread-query.ts
|
|
4183
4168
|
const contextFields = [
|
|
4184
4169
|
"resourceId",
|
|
4185
4170
|
"userId",
|
|
@@ -4357,7 +4342,7 @@ async function queryThreadRows(db, plan, strategy = "auto") {
|
|
|
4357
4342
|
return `${field} ${field === "organizationId" || field === "resourceId" ? "IS NOT DISTINCT FROM" : "="} ?`;
|
|
4358
4343
|
}).join(" AND ")})`;
|
|
4359
4344
|
}));
|
|
4360
|
-
const payloads = await run(`SELECT organizationId, traceId, cursorId,
|
|
4345
|
+
const payloads = await run(`SELECT organizationId, traceId, cursorId,
|
|
4361
4346
|
${contextFields.map((field) => field === "executionSource" ? "source AS executionSource" : field).join(", ")},
|
|
4362
4347
|
CASE WHEN spanType = 'agent_run' THEN timeToFirstChunkMs END AS timeToFirstChunkMs,
|
|
4363
4348
|
CASE WHEN error IS NULL THEN 'success' ELSE 'error' END AS status,
|
|
@@ -4373,34 +4358,10 @@ async function queryThreadRows(db, plan, strategy = "auto") {
|
|
|
4373
4358
|
String(version)
|
|
4374
4359
|
]);
|
|
4375
4360
|
const byRoot = new Map(payloads.map((row) => [key(row.organizationId, row.traceId, row.cursorId), row]));
|
|
4376
|
-
const agents = page.filter((row) => byRoot.get(key(row.organizationId, row.firstTraceId, row.firstCursorId))?.spanType === "agent_run");
|
|
4377
|
-
const models = /* @__PURE__ */ new Map();
|
|
4378
|
-
if (agents.length) {
|
|
4379
|
-
const modelValues = [];
|
|
4380
|
-
const rows = await run(`WITH generations AS (
|
|
4381
|
-
SELECT organizationId, traceId, spanId, endedAt, cursorId, attributes,
|
|
4382
|
-
min(timestamp) FILTER (WHERE eventType = 'start') OVER (PARTITION BY organizationId, traceId, spanId) AS startedAt
|
|
4383
|
-
FROM span_events WHERE spanType = 'model_generation' AND (${agents.map((row) => `(${Object.entries({
|
|
4384
|
-
organizationId: row.organizationId,
|
|
4385
|
-
resourceId: row.resourceId,
|
|
4386
|
-
traceId: row.firstTraceId,
|
|
4387
|
-
parentSpanId: row.firstSpanId
|
|
4388
|
-
}).map(([field, value]) => {
|
|
4389
|
-
modelValues.push(value);
|
|
4390
|
-
return `${field} ${field === "organizationId" || field === "resourceId" ? "IS NOT DISTINCT FROM" : "="} ?`;
|
|
4391
|
-
}).join(" AND ")})`).join(" OR ")})
|
|
4392
|
-
) SELECT organizationId, traceId,
|
|
4393
|
-
CASE WHEN json_type(attributes, '$.model') = 'VARCHAR' THEN json_extract_string(attributes, '$.model') END AS model,
|
|
4394
|
-
CASE WHEN json_type(attributes, '$.provider') = 'VARCHAR' THEN json_extract_string(attributes, '$.provider') END AS provider
|
|
4395
|
-
FROM generations WHERE endedAt IS NOT NULL
|
|
4396
|
-
QUALIFY row_number() OVER (PARTITION BY organizationId, traceId ORDER BY startedAt, spanId, cursorId DESC) = 1`, modelValues);
|
|
4397
|
-
for (const row of rows) models.set(JSON.stringify([row.organizationId, row.traceId]), row);
|
|
4398
|
-
}
|
|
4399
4361
|
const threads = page.flatMap((row) => {
|
|
4400
4362
|
const first = byRoot.get(key(row.organizationId, row.firstTraceId, row.firstCursorId));
|
|
4401
4363
|
const last = byRoot.get(key(row.organizationId, row.lastTraceId, row.lastCursorId));
|
|
4402
4364
|
if (!first || !last) return [];
|
|
4403
|
-
const model = models.get(JSON.stringify([row.organizationId, row.firstTraceId]));
|
|
4404
4365
|
return [coreStorage.threadQueryRowSchema.parse({
|
|
4405
4366
|
organizationId: row.organizationId,
|
|
4406
4367
|
threadId: row.threadId,
|
|
@@ -4412,8 +4373,6 @@ async function queryThreadRows(db, plan, strategy = "auto") {
|
|
|
4412
4373
|
endedAt: row.endedAt.toISOString(),
|
|
4413
4374
|
traceCount: Number(row.traceCount),
|
|
4414
4375
|
timeToFirstChunkMs: first.timeToFirstChunkMs,
|
|
4415
|
-
model: model?.model ?? null,
|
|
4416
|
-
provider: model?.provider ?? null,
|
|
4417
4376
|
inputPreview: readPreview(first.inputPreview, first.input, true),
|
|
4418
4377
|
outputPreview: readPreview(last.outputPreview, last.output, true),
|
|
4419
4378
|
errorPreview: readPreview(last.errorPreview, last.error, true)
|
|
@@ -4429,8 +4388,7 @@ async function queryThreadRows(db, plan, strategy = "auto") {
|
|
|
4429
4388
|
}) : null }
|
|
4430
4389
|
};
|
|
4431
4390
|
}
|
|
4432
|
-
|
|
4433
|
-
//#region src/storage/domains/observability/trace-aggregate.ts
|
|
4391
|
+
// src/storage/domains/observability/trace-aggregate.ts
|
|
4434
4392
|
/** Trace-root column expressions (alias `r`) for each groupable dimension; same values `where` sees. */
|
|
4435
4393
|
const DIMENSION_SQL = {
|
|
4436
4394
|
entityType: "r.entityType",
|
|
@@ -4811,8 +4769,7 @@ async function runAggregate(db, plan, compiled) {
|
|
|
4811
4769
|
truncated
|
|
4812
4770
|
};
|
|
4813
4771
|
}
|
|
4814
|
-
|
|
4815
|
-
//#region src/storage/domains/observability/tracing.ts
|
|
4772
|
+
// src/storage/domains/observability/tracing.ts
|
|
4816
4773
|
const COLUMNS_SQL = [
|
|
4817
4774
|
"eventType",
|
|
4818
4775
|
"timestamp",
|
|
@@ -6166,8 +6123,7 @@ async function getBranchStreamHeadCursor(db, userSpanType) {
|
|
|
6166
6123
|
if (userSpanType) return encodeDeltaCursor((await db.query(`SELECT max(cursorId) AS cursorId FROM span_events WHERE eventType = 'start' AND spanType = ? AND cursorId IS NOT NULL`, [userSpanType]))[0]?.cursorId);
|
|
6167
6124
|
return encodeDeltaCursor((await db.query(`SELECT max(cursorId) AS cursorId FROM span_events WHERE eventType = 'start' AND spanType IN (${BRANCH_SPAN_TYPE_PLACEHOLDERS}) AND cursorId IS NOT NULL`, [...BRANCH_SPAN_TYPES]))[0]?.cursorId);
|
|
6168
6125
|
}
|
|
6169
|
-
|
|
6170
|
-
//#region src/storage/domains/observability/index.ts
|
|
6126
|
+
// src/storage/domains/observability/index.ts
|
|
6171
6127
|
function buildSignalMigrationRequiredMessage(args) {
|
|
6172
6128
|
return `
|
|
6173
6129
|
===========================================================================
|
|
@@ -6498,7 +6454,6 @@ var ObservabilityStorageDuckDB = class ObservabilityStorageDuckDB extends Observ
|
|
|
6498
6454
|
return getFeedbackPercentiles(this.db, args);
|
|
6499
6455
|
}
|
|
6500
6456
|
};
|
|
6501
|
-
//#endregion
|
|
6502
6457
|
export { ObservabilityStorageDuckDB };
|
|
6503
6458
|
|
|
6504
|
-
//# sourceMappingURL=observability-
|
|
6459
|
+
//# sourceMappingURL=observability-BWSYzhM2.js.map
|