@mastra/duckdb 1.17.0-alpha.0 → 1.17.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/README.md +1 -1
- package/dist/docs/SKILL.md +2 -2
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/integrations-databases-duckdb.md +2 -2
- package/dist/{features-CMkGwt1J.cjs → features-CBdrOdEO.cjs} +29 -3
- package/dist/{features-CMkGwt1J.cjs.map → features-CBdrOdEO.cjs.map} +1 -1
- package/dist/{features-dc98I6Rx.js → features-D9RrctvA.js} +12 -4
- package/dist/{features-dc98I6Rx.js.map → features-D9RrctvA.js.map} +1 -1
- package/dist/index.cjs +4 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/{observability-Dr89aflR.cjs → observability-B_ARB4Uv.cjs} +61 -20
- package/dist/observability-B_ARB4Uv.cjs.map +1 -0
- package/dist/{observability-DlRTQlrI.js → observability-CN4Rwgv9.js} +61 -20
- package/dist/observability-CN4Rwgv9.js.map +1 -0
- package/dist/storage/domains/observability/index.d.ts +1 -1
- package/dist/storage/domains/observability/index.d.ts.map +1 -1
- package/dist/storage/domains/observability/preview-compat.d.ts +3 -0
- package/dist/storage/domains/observability/preview-compat.d.ts.map +1 -1
- package/dist/storage/domains/observability/span-query.d.ts +3 -0
- package/dist/storage/domains/observability/span-query.d.ts.map +1 -1
- package/dist/storage/domains/observability/trace-aggregate.d.ts.map +1 -1
- package/dist/storage/domains/observability/trace-query.d.ts.map +1 -1
- package/dist/storage/features.d.ts +6 -2
- package/dist/storage/features.d.ts.map +1 -1
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +5 -5
- package/dist/observability-DlRTQlrI.js.map +0 -1
- package/dist/observability-Dr89aflR.cjs.map +0 -1
- /package/dist/docs/references/{reference-vectors-duckdb.md → integrations-vectors-duckdb.md} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as timingFeatures, d as DuckDBQueryTimeoutError, i as spanQueryOutcomeFieldsSupported, l as traceQueryOutcomeFieldsSupported, n as spanAggregateFeatures, o as timeToFirstChunkSupported, r as spanQueryFeatures, s as timeToFirstTokenSupported, t as outcomeFeatures, u as DuckDBConnection } from "./features-D9RrctvA.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, getStringAttribute, listBranchesArgsSchema, listFeedbackArgsSchema, listLogsArgsSchema, listMetricsArgsSchema, listScoresArgsSchema, listTracesArgsSchema, resolveRetentionTargets, retentionCutoffMs, toTraceSpans } from "@mastra/core/storage";
|
|
@@ -2931,6 +2931,14 @@ const TRACE_FIELDS = {
|
|
|
2931
2931
|
sql: TRACE_STATUS_SQL,
|
|
2932
2932
|
parameterType: "scalar"
|
|
2933
2933
|
},
|
|
2934
|
+
outcome: {
|
|
2935
|
+
sql: "r.outcome",
|
|
2936
|
+
parameterType: "scalar"
|
|
2937
|
+
},
|
|
2938
|
+
stopReason: {
|
|
2939
|
+
sql: "r.stopReason",
|
|
2940
|
+
parameterType: "scalar"
|
|
2941
|
+
},
|
|
2934
2942
|
tags: {
|
|
2935
2943
|
sql: "r.tags",
|
|
2936
2944
|
parameterType: "scalar"
|
|
@@ -2977,6 +2985,14 @@ const SPAN_FIELDS = {
|
|
|
2977
2985
|
sql: "s.status",
|
|
2978
2986
|
parameterType: "scalar"
|
|
2979
2987
|
},
|
|
2988
|
+
outcome: {
|
|
2989
|
+
sql: "s.outcome",
|
|
2990
|
+
parameterType: "scalar"
|
|
2991
|
+
},
|
|
2992
|
+
stopReason: {
|
|
2993
|
+
sql: "s.stopReason",
|
|
2994
|
+
parameterType: "scalar"
|
|
2995
|
+
},
|
|
2980
2996
|
error: {
|
|
2981
2997
|
sql: "s.error",
|
|
2982
2998
|
parameterType: "scalar"
|
|
@@ -3187,6 +3203,9 @@ const TRACE_SELECT = `
|
|
|
3187
3203
|
r.entityName AS entityName,
|
|
3188
3204
|
r.entityType AS entityType,
|
|
3189
3205
|
r.environment AS environment,
|
|
3206
|
+
r.outcome AS outcome,
|
|
3207
|
+
r.stopReason AS stopReason,
|
|
3208
|
+
r.stopReasonContext AS stopReasonContext,
|
|
3190
3209
|
${TRACE_STATUS_SQL} AS status`;
|
|
3191
3210
|
function fieldDefinition(registry, field) {
|
|
3192
3211
|
const definition = registry[field];
|
|
@@ -3542,18 +3561,22 @@ function compileDuckDBTraceScope(relatedCollections, scope, timeRange, rootPredi
|
|
|
3542
3561
|
traceId,
|
|
3543
3562
|
name,
|
|
3544
3563
|
spanType,
|
|
3545
|
-
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
|
|
3564
|
+
COALESCE(
|
|
3565
|
+
model,
|
|
3566
|
+
CASE WHEN json_type(attributes, '$.model') = 'VARCHAR' THEN json_extract_string(attributes, '$.model') END
|
|
3567
|
+
) AS model,
|
|
3568
|
+
COALESCE(
|
|
3569
|
+
provider,
|
|
3570
|
+
CASE WHEN json_type(attributes, '$.provider') = 'VARCHAR' THEN json_extract_string(attributes, '$.provider') END
|
|
3571
|
+
) AS provider,
|
|
3551
3572
|
startedAt,
|
|
3552
3573
|
endedAt,
|
|
3553
3574
|
${durationMsSql("startedAt", "endedAt")} AS durationMs,
|
|
3554
3575
|
timeToFirstChunkMs,
|
|
3555
3576
|
timeToFirstTokenMs,
|
|
3556
3577
|
CASE WHEN error IS NOT NULL THEN 'error' ELSE 'success' END AS status,
|
|
3578
|
+
outcome,
|
|
3579
|
+
stopReason,
|
|
3557
3580
|
error,
|
|
3558
3581
|
entityType,
|
|
3559
3582
|
entityId,
|
|
@@ -3894,7 +3917,12 @@ function traceFromRow(row) {
|
|
|
3894
3917
|
environment: row.environment == null ? null : String(row.environment),
|
|
3895
3918
|
status: row.status,
|
|
3896
3919
|
...timeToFirstChunkSupported && { timeToFirstChunkMs: row.timeToFirstChunkMs == null ? null : Number(row.timeToFirstChunkMs) },
|
|
3897
|
-
...timeToFirstTokenSupported && { timeToFirstTokenMs: row.timeToFirstTokenMs == null ? null : Number(row.timeToFirstTokenMs) }
|
|
3920
|
+
...timeToFirstTokenSupported && { timeToFirstTokenMs: row.timeToFirstTokenMs == null ? null : Number(row.timeToFirstTokenMs) },
|
|
3921
|
+
...traceQueryOutcomeFieldsSupported && {
|
|
3922
|
+
outcome: row.outcome == null ? null : String(row.outcome),
|
|
3923
|
+
stopReason: row.stopReason == null ? null : String(row.stopReason),
|
|
3924
|
+
stopReasonContext: parseJson(row.stopReasonContext) ?? null
|
|
3925
|
+
}
|
|
3898
3926
|
};
|
|
3899
3927
|
}
|
|
3900
3928
|
async function queryTraces(db, plan) {
|
|
@@ -4016,7 +4044,9 @@ const fields = [
|
|
|
4016
4044
|
"environment",
|
|
4017
4045
|
"executionSource",
|
|
4018
4046
|
"timeToFirstChunkMs",
|
|
4019
|
-
"timeToFirstTokenMs"
|
|
4047
|
+
"timeToFirstTokenMs",
|
|
4048
|
+
"outcome",
|
|
4049
|
+
"stopReason"
|
|
4020
4050
|
];
|
|
4021
4051
|
function keys(rows, values, alias = "") {
|
|
4022
4052
|
return rows.map((row) => `(${identityFields.map((field) => {
|
|
@@ -4074,8 +4104,6 @@ function compileDuckDBSpanSelection(plan) {
|
|
|
4074
4104
|
values.push(plan.timeRange.from, plan.timeRange.to, ...predicate.values);
|
|
4075
4105
|
const join = identityFields.map((field) => `e.${field} IS NOT DISTINCT FROM c.${field}`).join(" AND ");
|
|
4076
4106
|
const partition = identityFields.map((field) => `e.${field}`).join(", ");
|
|
4077
|
-
const legacyModelFields = coreStorage.SPAN_QUERY_FIELD_REGISTRY ? "" : `CASE WHEN json_type(e.attributes, '$.model') = 'VARCHAR' THEN json_extract_string(e.attributes, '$.model') END AS model,
|
|
4078
|
-
CASE WHEN json_type(e.attributes, '$.provider') = 'VARCHAR' THEN json_extract_string(e.attributes, '$.provider') END AS provider,`;
|
|
4079
4107
|
return {
|
|
4080
4108
|
ctes: [
|
|
4081
4109
|
`candidates AS MATERIALIZED (
|
|
@@ -4087,7 +4115,7 @@ function compileDuckDBSpanSelection(plan) {
|
|
|
4087
4115
|
`span_versions AS (
|
|
4088
4116
|
SELECT ${fields.map(columnSql).join(", ")},
|
|
4089
4117
|
min(e.timestamp) FILTER (WHERE e.eventType = 'start') OVER (PARTITION BY ${partition}) AS startedAt, e.endedAt, e.cursorId,
|
|
4090
|
-
|
|
4118
|
+
e.model, e.provider,
|
|
4091
4119
|
date_diff('millisecond', min(e.timestamp) FILTER (WHERE e.eventType = 'start') OVER (PARTITION BY ${partition}), e.endedAt) AS durationMs,
|
|
4092
4120
|
CASE WHEN e.error IS NULL THEN 'success' ELSE 'error' END AS status,
|
|
4093
4121
|
CASE WHEN e.error IS NULL THEN NULL ELSE 'error' END AS error,
|
|
@@ -4143,12 +4171,16 @@ async function querySpans(db, plan) {
|
|
|
4143
4171
|
};
|
|
4144
4172
|
const compiled = compileDuckDBSpanQuery(plan);
|
|
4145
4173
|
const rows = await query(compiled.sql, compiled.values);
|
|
4146
|
-
const selected = rows.map(({ cursorId: _cursorId, startedAt, endedAt, timeToFirstChunkMs, timeToFirstTokenMs, ...row }) => ({
|
|
4174
|
+
const selected = rows.map(({ cursorId: _cursorId, startedAt, endedAt, timeToFirstChunkMs, timeToFirstTokenMs, outcome, stopReason, ...row }) => ({
|
|
4147
4175
|
...row,
|
|
4148
4176
|
startedAt: startedAt.toISOString(),
|
|
4149
4177
|
endedAt: endedAt.toISOString(),
|
|
4150
4178
|
...timeToFirstChunkSupported && { timeToFirstChunkMs: timeToFirstChunkMs == null ? null : Number(timeToFirstChunkMs) },
|
|
4151
|
-
...timeToFirstTokenSupported && { timeToFirstTokenMs: timeToFirstTokenMs == null ? null : Number(timeToFirstTokenMs) }
|
|
4179
|
+
...timeToFirstTokenSupported && { timeToFirstTokenMs: timeToFirstTokenMs == null ? null : Number(timeToFirstTokenMs) },
|
|
4180
|
+
...spanQueryOutcomeFieldsSupported && {
|
|
4181
|
+
outcome: outcome ?? null,
|
|
4182
|
+
stopReason: stopReason ?? null
|
|
4183
|
+
}
|
|
4152
4184
|
}));
|
|
4153
4185
|
const page = rows.slice(0, plan.limit);
|
|
4154
4186
|
if (!page.length) return buildSpanQueryResponse(plan, [], []);
|
|
@@ -4158,9 +4190,9 @@ async function querySpans(db, plan) {
|
|
|
4158
4190
|
payloadValues.push(row.cursorId, row.endedAt);
|
|
4159
4191
|
return `(${key} AND cursorId IS NOT DISTINCT FROM ? AND endedAt = ?)`;
|
|
4160
4192
|
}).join(" OR ");
|
|
4161
|
-
const previewRows = await query(`SELECT DISTINCT ${identities},
|
|
4162
|
-
CASE WHEN json_type(attributes, '$.model') = 'VARCHAR' THEN json_extract_string(attributes, '$.model') END AS model,
|
|
4163
|
-
CASE WHEN json_type(attributes, '$.provider') = 'VARCHAR' THEN json_extract_string(attributes, '$.provider') END AS provider,
|
|
4193
|
+
const previewRows = await query(`SELECT DISTINCT ${identities}, CAST(stopReasonContext AS VARCHAR) AS stopReasonContext,
|
|
4194
|
+
COALESCE(model, CASE WHEN json_type(attributes, '$.model') = 'VARCHAR' THEN json_extract_string(attributes, '$.model') END) AS model,
|
|
4195
|
+
COALESCE(provider, CASE WHEN json_type(attributes, '$.provider') = 'VARCHAR' THEN json_extract_string(attributes, '$.provider') END) AS provider,
|
|
4164
4196
|
${previewPayloads.map(([preview, payload]) => `${preview}, CASE WHEN ${missingPreviewSql(preview)} THEN CAST(${payload} AS VARCHAR) END AS ${preview}Payload`).join(",\n ")}
|
|
4165
4197
|
FROM span_events WHERE ${payloadWhere}`, payloadValues);
|
|
4166
4198
|
const payloads = previewRows.map((row) => {
|
|
@@ -4183,7 +4215,8 @@ async function querySpans(db, plan) {
|
|
|
4183
4215
|
const hydrated = selected.map((row) => ({
|
|
4184
4216
|
...row,
|
|
4185
4217
|
model: metadata.get(coreStorage.spanQueryIdentityKey(row))?.model ?? null,
|
|
4186
|
-
provider: metadata.get(coreStorage.spanQueryIdentityKey(row))?.provider ?? null
|
|
4218
|
+
provider: metadata.get(coreStorage.spanQueryIdentityKey(row))?.provider ?? null,
|
|
4219
|
+
...spanQueryOutcomeFieldsSupported && { stopReasonContext: parseJson(metadata.get(coreStorage.spanQueryIdentityKey(row))?.stopReasonContext) ?? null }
|
|
4187
4220
|
}));
|
|
4188
4221
|
let metrics = [];
|
|
4189
4222
|
if (!coreStorage.SPAN_QUERY_FIELD_REGISTRY) {
|
|
@@ -4438,6 +4471,8 @@ const DIMENSION_SQL = {
|
|
|
4438
4471
|
entityId: "r.entityId",
|
|
4439
4472
|
environment: "r.environment",
|
|
4440
4473
|
status: TRACE_STATUS_SQL,
|
|
4474
|
+
outcome: "r.outcome",
|
|
4475
|
+
stopReason: "r.stopReason",
|
|
4441
4476
|
serviceName: "r.serviceName",
|
|
4442
4477
|
executionSource: "r.source",
|
|
4443
4478
|
threadId: "r.threadId",
|
|
@@ -4460,6 +4495,8 @@ const SPAN_DIMENSION_SQL = Object.fromEntries([
|
|
|
4460
4495
|
"rootEntityName",
|
|
4461
4496
|
"environment",
|
|
4462
4497
|
"status",
|
|
4498
|
+
"outcome",
|
|
4499
|
+
"stopReason",
|
|
4463
4500
|
"serviceName",
|
|
4464
4501
|
"executionSource",
|
|
4465
4502
|
"threadId",
|
|
@@ -4467,7 +4504,9 @@ const SPAN_DIMENSION_SQL = Object.fromEntries([
|
|
|
4467
4504
|
"userId",
|
|
4468
4505
|
"sessionId",
|
|
4469
4506
|
"organizationId",
|
|
4470
|
-
"experimentId"
|
|
4507
|
+
"experimentId",
|
|
4508
|
+
"model",
|
|
4509
|
+
"provider"
|
|
4471
4510
|
].map((field) => [field, `r.${field}`]));
|
|
4472
4511
|
const PERCENTILES = {
|
|
4473
4512
|
"duration.p50": .5,
|
|
@@ -6361,6 +6400,7 @@ var ObservabilityStorageDuckDB = class ObservabilityStorageDuckDB extends Observ
|
|
|
6361
6400
|
"feedback",
|
|
6362
6401
|
"trace-query-context-ids",
|
|
6363
6402
|
...timingFeatures,
|
|
6403
|
+
...outcomeFeatures,
|
|
6364
6404
|
"trace-query-root-span-fields",
|
|
6365
6405
|
"trace-query-root-entity-id"
|
|
6366
6406
|
];
|
|
@@ -6386,6 +6426,7 @@ var ObservabilityStorageDuckDB = class ObservabilityStorageDuckDB extends Observ
|
|
|
6386
6426
|
"feedback",
|
|
6387
6427
|
"trace-query-context-ids",
|
|
6388
6428
|
...timingFeatures,
|
|
6429
|
+
...outcomeFeatures,
|
|
6389
6430
|
"trace-query-root-span-fields",
|
|
6390
6431
|
"trace-query-root-entity-id"
|
|
6391
6432
|
];
|
|
@@ -6551,4 +6592,4 @@ var ObservabilityStorageDuckDB = class ObservabilityStorageDuckDB extends Observ
|
|
|
6551
6592
|
};
|
|
6552
6593
|
export { ObservabilityStorageDuckDB };
|
|
6553
6594
|
|
|
6554
|
-
//# sourceMappingURL=observability-
|
|
6595
|
+
//# sourceMappingURL=observability-CN4Rwgv9.js.map
|