@mastra/duckdb 1.16.0 → 1.17.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/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-DH60yLCA.cjs → features-CBdrOdEO.cjs} +98 -9
- package/dist/features-CBdrOdEO.cjs.map +1 -0
- package/dist/{features-B8gl38Ue.js → features-D9RrctvA.js} +71 -6
- package/dist/features-D9RrctvA.js.map +1 -0
- package/dist/index.cjs +25 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +25 -8
- package/dist/index.js.map +1 -1
- package/dist/{observability-BEdkwaeY.cjs → observability-B_ARB4Uv.cjs} +85 -24
- package/dist/observability-B_ARB4Uv.cjs.map +1 -0
- package/dist/{observability-B-Kt8vrw.js → observability-CN4Rwgv9.js} +85 -24
- package/dist/observability-CN4Rwgv9.js.map +1 -0
- package/dist/storage/db/index.d.ts +5 -0
- package/dist/storage/db/index.d.ts.map +1 -1
- 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 +4 -0
- package/dist/storage/domains/observability/preview-compat.d.ts.map +1 -1
- package/dist/storage/domains/observability/span-query.d.ts +4 -0
- package/dist/storage/domains/observability/span-query.d.ts.map +1 -1
- package/dist/storage/domains/observability/thread-query.d.ts +1 -0
- package/dist/storage/domains/observability/thread-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 +9 -3
- package/dist/storage/features.d.ts.map +1 -1
- package/dist/storage/index.d.ts +3 -0
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/dist/features-B8gl38Ue.js.map +0 -1
- package/dist/features-DH60yLCA.cjs.map +0 -1
- package/dist/observability-B-Kt8vrw.js.map +0 -1
- package/dist/observability-BEdkwaeY.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";
|
|
@@ -2899,6 +2899,10 @@ const TRACE_FIELDS = {
|
|
|
2899
2899
|
sql: "r.timeToFirstChunkMs",
|
|
2900
2900
|
parameterType: "scalar"
|
|
2901
2901
|
},
|
|
2902
|
+
timeToFirstTokenMs: {
|
|
2903
|
+
sql: "r.timeToFirstTokenMs",
|
|
2904
|
+
parameterType: "scalar"
|
|
2905
|
+
},
|
|
2902
2906
|
entityId: {
|
|
2903
2907
|
sql: "r.entityId",
|
|
2904
2908
|
parameterType: "scalar"
|
|
@@ -2927,6 +2931,14 @@ const TRACE_FIELDS = {
|
|
|
2927
2931
|
sql: TRACE_STATUS_SQL,
|
|
2928
2932
|
parameterType: "scalar"
|
|
2929
2933
|
},
|
|
2934
|
+
outcome: {
|
|
2935
|
+
sql: "r.outcome",
|
|
2936
|
+
parameterType: "scalar"
|
|
2937
|
+
},
|
|
2938
|
+
stopReason: {
|
|
2939
|
+
sql: "r.stopReason",
|
|
2940
|
+
parameterType: "scalar"
|
|
2941
|
+
},
|
|
2930
2942
|
tags: {
|
|
2931
2943
|
sql: "r.tags",
|
|
2932
2944
|
parameterType: "scalar"
|
|
@@ -2965,10 +2977,22 @@ const SPAN_FIELDS = {
|
|
|
2965
2977
|
sql: "s.timeToFirstChunkMs",
|
|
2966
2978
|
parameterType: "scalar"
|
|
2967
2979
|
},
|
|
2980
|
+
timeToFirstTokenMs: {
|
|
2981
|
+
sql: "s.timeToFirstTokenMs",
|
|
2982
|
+
parameterType: "scalar"
|
|
2983
|
+
},
|
|
2968
2984
|
status: {
|
|
2969
2985
|
sql: "s.status",
|
|
2970
2986
|
parameterType: "scalar"
|
|
2971
2987
|
},
|
|
2988
|
+
outcome: {
|
|
2989
|
+
sql: "s.outcome",
|
|
2990
|
+
parameterType: "scalar"
|
|
2991
|
+
},
|
|
2992
|
+
stopReason: {
|
|
2993
|
+
sql: "s.stopReason",
|
|
2994
|
+
parameterType: "scalar"
|
|
2995
|
+
},
|
|
2972
2996
|
error: {
|
|
2973
2997
|
sql: "s.error",
|
|
2974
2998
|
parameterType: "scalar"
|
|
@@ -3175,9 +3199,13 @@ const TRACE_SELECT = `
|
|
|
3175
3199
|
r.startedAt AS startedAt,
|
|
3176
3200
|
r.endedAt AS endedAt,
|
|
3177
3201
|
r.timeToFirstChunkMs AS timeToFirstChunkMs,
|
|
3202
|
+
r.timeToFirstTokenMs AS timeToFirstTokenMs,
|
|
3178
3203
|
r.entityName AS entityName,
|
|
3179
3204
|
r.entityType AS entityType,
|
|
3180
3205
|
r.environment AS environment,
|
|
3206
|
+
r.outcome AS outcome,
|
|
3207
|
+
r.stopReason AS stopReason,
|
|
3208
|
+
r.stopReasonContext AS stopReasonContext,
|
|
3181
3209
|
${TRACE_STATUS_SQL} AS status`;
|
|
3182
3210
|
function fieldDefinition(registry, field) {
|
|
3183
3211
|
const definition = registry[field];
|
|
@@ -3411,6 +3439,7 @@ const ROOT_PUSHDOWN_FIELDS = /* @__PURE__ */ new Set([
|
|
|
3411
3439
|
"organizationId",
|
|
3412
3440
|
"endedAt",
|
|
3413
3441
|
"timeToFirstChunkMs",
|
|
3442
|
+
"timeToFirstTokenMs",
|
|
3414
3443
|
"entityId",
|
|
3415
3444
|
"entityName",
|
|
3416
3445
|
"entityType",
|
|
@@ -3532,17 +3561,22 @@ function compileDuckDBTraceScope(relatedCollections, scope, timeRange, rootPredi
|
|
|
3532
3561
|
traceId,
|
|
3533
3562
|
name,
|
|
3534
3563
|
spanType,
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
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,
|
|
3541
3572
|
startedAt,
|
|
3542
3573
|
endedAt,
|
|
3543
3574
|
${durationMsSql("startedAt", "endedAt")} AS durationMs,
|
|
3544
3575
|
timeToFirstChunkMs,
|
|
3576
|
+
timeToFirstTokenMs,
|
|
3545
3577
|
CASE WHEN error IS NOT NULL THEN 'error' ELSE 'success' END AS status,
|
|
3578
|
+
outcome,
|
|
3579
|
+
stopReason,
|
|
3546
3580
|
error,
|
|
3547
3581
|
entityType,
|
|
3548
3582
|
entityId,
|
|
@@ -3882,7 +3916,13 @@ function traceFromRow(row) {
|
|
|
3882
3916
|
entityType: row.entityType == null ? null : String(row.entityType),
|
|
3883
3917
|
environment: row.environment == null ? null : String(row.environment),
|
|
3884
3918
|
status: row.status,
|
|
3885
|
-
...timeToFirstChunkSupported && { timeToFirstChunkMs: row.timeToFirstChunkMs == null ? null : Number(row.timeToFirstChunkMs) }
|
|
3919
|
+
...timeToFirstChunkSupported && { timeToFirstChunkMs: row.timeToFirstChunkMs == null ? null : Number(row.timeToFirstChunkMs) },
|
|
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
|
+
}
|
|
3886
3926
|
};
|
|
3887
3927
|
}
|
|
3888
3928
|
async function queryTraces(db, plan) {
|
|
@@ -4003,7 +4043,10 @@ const fields = [
|
|
|
4003
4043
|
"experimentId",
|
|
4004
4044
|
"environment",
|
|
4005
4045
|
"executionSource",
|
|
4006
|
-
"timeToFirstChunkMs"
|
|
4046
|
+
"timeToFirstChunkMs",
|
|
4047
|
+
"timeToFirstTokenMs",
|
|
4048
|
+
"outcome",
|
|
4049
|
+
"stopReason"
|
|
4007
4050
|
];
|
|
4008
4051
|
function keys(rows, values, alias = "") {
|
|
4009
4052
|
return rows.map((row) => `(${identityFields.map((field) => {
|
|
@@ -4061,8 +4104,6 @@ function compileDuckDBSpanSelection(plan) {
|
|
|
4061
4104
|
values.push(plan.timeRange.from, plan.timeRange.to, ...predicate.values);
|
|
4062
4105
|
const join = identityFields.map((field) => `e.${field} IS NOT DISTINCT FROM c.${field}`).join(" AND ");
|
|
4063
4106
|
const partition = identityFields.map((field) => `e.${field}`).join(", ");
|
|
4064
|
-
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,
|
|
4065
|
-
CASE WHEN json_type(e.attributes, '$.provider') = 'VARCHAR' THEN json_extract_string(e.attributes, '$.provider') END AS provider,`;
|
|
4066
4107
|
return {
|
|
4067
4108
|
ctes: [
|
|
4068
4109
|
`candidates AS MATERIALIZED (
|
|
@@ -4074,7 +4115,7 @@ function compileDuckDBSpanSelection(plan) {
|
|
|
4074
4115
|
`span_versions AS (
|
|
4075
4116
|
SELECT ${fields.map(columnSql).join(", ")},
|
|
4076
4117
|
min(e.timestamp) FILTER (WHERE e.eventType = 'start') OVER (PARTITION BY ${partition}) AS startedAt, e.endedAt, e.cursorId,
|
|
4077
|
-
|
|
4118
|
+
e.model, e.provider,
|
|
4078
4119
|
date_diff('millisecond', min(e.timestamp) FILTER (WHERE e.eventType = 'start') OVER (PARTITION BY ${partition}), e.endedAt) AS durationMs,
|
|
4079
4120
|
CASE WHEN e.error IS NULL THEN 'success' ELSE 'error' END AS status,
|
|
4080
4121
|
CASE WHEN e.error IS NULL THEN NULL ELSE 'error' END AS error,
|
|
@@ -4130,11 +4171,16 @@ async function querySpans(db, plan) {
|
|
|
4130
4171
|
};
|
|
4131
4172
|
const compiled = compileDuckDBSpanQuery(plan);
|
|
4132
4173
|
const rows = await query(compiled.sql, compiled.values);
|
|
4133
|
-
const selected = rows.map(({ cursorId: _cursorId, startedAt, endedAt, timeToFirstChunkMs, ...row }) => ({
|
|
4174
|
+
const selected = rows.map(({ cursorId: _cursorId, startedAt, endedAt, timeToFirstChunkMs, timeToFirstTokenMs, outcome, stopReason, ...row }) => ({
|
|
4134
4175
|
...row,
|
|
4135
4176
|
startedAt: startedAt.toISOString(),
|
|
4136
4177
|
endedAt: endedAt.toISOString(),
|
|
4137
|
-
...timeToFirstChunkSupported && { timeToFirstChunkMs: timeToFirstChunkMs == null ? null : Number(timeToFirstChunkMs) }
|
|
4178
|
+
...timeToFirstChunkSupported && { timeToFirstChunkMs: timeToFirstChunkMs == null ? null : Number(timeToFirstChunkMs) },
|
|
4179
|
+
...timeToFirstTokenSupported && { timeToFirstTokenMs: timeToFirstTokenMs == null ? null : Number(timeToFirstTokenMs) },
|
|
4180
|
+
...spanQueryOutcomeFieldsSupported && {
|
|
4181
|
+
outcome: outcome ?? null,
|
|
4182
|
+
stopReason: stopReason ?? null
|
|
4183
|
+
}
|
|
4138
4184
|
}));
|
|
4139
4185
|
const page = rows.slice(0, plan.limit);
|
|
4140
4186
|
if (!page.length) return buildSpanQueryResponse(plan, [], []);
|
|
@@ -4144,9 +4190,9 @@ async function querySpans(db, plan) {
|
|
|
4144
4190
|
payloadValues.push(row.cursorId, row.endedAt);
|
|
4145
4191
|
return `(${key} AND cursorId IS NOT DISTINCT FROM ? AND endedAt = ?)`;
|
|
4146
4192
|
}).join(" OR ");
|
|
4147
|
-
const previewRows = await query(`SELECT DISTINCT ${identities},
|
|
4148
|
-
CASE WHEN json_type(attributes, '$.model') = 'VARCHAR' THEN json_extract_string(attributes, '$.model') END AS model,
|
|
4149
|
-
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,
|
|
4150
4196
|
${previewPayloads.map(([preview, payload]) => `${preview}, CASE WHEN ${missingPreviewSql(preview)} THEN CAST(${payload} AS VARCHAR) END AS ${preview}Payload`).join(",\n ")}
|
|
4151
4197
|
FROM span_events WHERE ${payloadWhere}`, payloadValues);
|
|
4152
4198
|
const payloads = previewRows.map((row) => {
|
|
@@ -4169,7 +4215,8 @@ async function querySpans(db, plan) {
|
|
|
4169
4215
|
const hydrated = selected.map((row) => ({
|
|
4170
4216
|
...row,
|
|
4171
4217
|
model: metadata.get(coreStorage.spanQueryIdentityKey(row))?.model ?? null,
|
|
4172
|
-
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 }
|
|
4173
4220
|
}));
|
|
4174
4221
|
let metrics = [];
|
|
4175
4222
|
if (!coreStorage.SPAN_QUERY_FIELD_REGISTRY) {
|
|
@@ -4278,8 +4325,12 @@ function compileDuckDBThreadRowsQuery(plan, strategy = "full") {
|
|
|
4278
4325
|
}
|
|
4279
4326
|
values.push(plan.limit + 1);
|
|
4280
4327
|
const filtered = predicateFields(plan.where);
|
|
4281
|
-
const firstContext = [
|
|
4282
|
-
|
|
4328
|
+
const firstContext = [
|
|
4329
|
+
...contextFields,
|
|
4330
|
+
"timeToFirstChunkMs",
|
|
4331
|
+
"timeToFirstTokenMs"
|
|
4332
|
+
].filter((field) => field === "resourceId" || filtered.has(field));
|
|
4333
|
+
const contextExpression = (field) => field === "executionSource" ? "source AS executionSource" : field === "timeToFirstChunkMs" || field === "timeToFirstTokenMs" ? `CASE WHEN spanType = 'agent_run' THEN ${field} END AS ${field}` : field;
|
|
4283
4334
|
const lastFields = [
|
|
4284
4335
|
"traceId",
|
|
4285
4336
|
"spanId",
|
|
@@ -4365,6 +4416,7 @@ async function queryThreadRows(db, plan, strategy = "auto") {
|
|
|
4365
4416
|
const payloads = await run(`SELECT organizationId, traceId, cursorId,
|
|
4366
4417
|
${contextFields.map((field) => field === "executionSource" ? "source AS executionSource" : field).join(", ")},
|
|
4367
4418
|
CASE WHEN spanType = 'agent_run' THEN timeToFirstChunkMs END AS timeToFirstChunkMs,
|
|
4419
|
+
CASE WHEN spanType = 'agent_run' THEN timeToFirstTokenMs END AS timeToFirstTokenMs,
|
|
4368
4420
|
CASE WHEN error IS NULL THEN 'success' ELSE 'error' END AS status,
|
|
4369
4421
|
${[
|
|
4370
4422
|
"input",
|
|
@@ -4393,6 +4445,7 @@ async function queryThreadRows(db, plan, strategy = "auto") {
|
|
|
4393
4445
|
endedAt: row.endedAt.toISOString(),
|
|
4394
4446
|
traceCount: Number(row.traceCount),
|
|
4395
4447
|
timeToFirstChunkMs: first.timeToFirstChunkMs,
|
|
4448
|
+
...timeToFirstTokenSupported && { timeToFirstTokenMs: first.timeToFirstTokenMs },
|
|
4396
4449
|
inputPreview: readPreview(first.inputPreview, first.input, true),
|
|
4397
4450
|
outputPreview: readPreview(last.outputPreview, last.output, true),
|
|
4398
4451
|
errorPreview: readPreview(last.errorPreview, last.error, true)
|
|
@@ -4418,6 +4471,8 @@ const DIMENSION_SQL = {
|
|
|
4418
4471
|
entityId: "r.entityId",
|
|
4419
4472
|
environment: "r.environment",
|
|
4420
4473
|
status: TRACE_STATUS_SQL,
|
|
4474
|
+
outcome: "r.outcome",
|
|
4475
|
+
stopReason: "r.stopReason",
|
|
4421
4476
|
serviceName: "r.serviceName",
|
|
4422
4477
|
executionSource: "r.source",
|
|
4423
4478
|
threadId: "r.threadId",
|
|
@@ -4440,6 +4495,8 @@ const SPAN_DIMENSION_SQL = Object.fromEntries([
|
|
|
4440
4495
|
"rootEntityName",
|
|
4441
4496
|
"environment",
|
|
4442
4497
|
"status",
|
|
4498
|
+
"outcome",
|
|
4499
|
+
"stopReason",
|
|
4443
4500
|
"serviceName",
|
|
4444
4501
|
"executionSource",
|
|
4445
4502
|
"threadId",
|
|
@@ -4447,7 +4504,9 @@ const SPAN_DIMENSION_SQL = Object.fromEntries([
|
|
|
4447
4504
|
"userId",
|
|
4448
4505
|
"sessionId",
|
|
4449
4506
|
"organizationId",
|
|
4450
|
-
"experimentId"
|
|
4507
|
+
"experimentId",
|
|
4508
|
+
"model",
|
|
4509
|
+
"provider"
|
|
4451
4510
|
].map((field) => [field, `r.${field}`]));
|
|
4452
4511
|
const PERCENTILES = {
|
|
4453
4512
|
"duration.p50": .5,
|
|
@@ -6340,7 +6399,8 @@ var ObservabilityStorageDuckDB = class ObservabilityStorageDuckDB extends Observ
|
|
|
6340
6399
|
"trace-query-tenant-scope",
|
|
6341
6400
|
"feedback",
|
|
6342
6401
|
"trace-query-context-ids",
|
|
6343
|
-
...
|
|
6402
|
+
...timingFeatures,
|
|
6403
|
+
...outcomeFeatures,
|
|
6344
6404
|
"trace-query-root-span-fields",
|
|
6345
6405
|
"trace-query-root-entity-id"
|
|
6346
6406
|
];
|
|
@@ -6365,7 +6425,8 @@ var ObservabilityStorageDuckDB = class ObservabilityStorageDuckDB extends Observ
|
|
|
6365
6425
|
"trace-query-tenant-scope",
|
|
6366
6426
|
"feedback",
|
|
6367
6427
|
"trace-query-context-ids",
|
|
6368
|
-
...
|
|
6428
|
+
...timingFeatures,
|
|
6429
|
+
...outcomeFeatures,
|
|
6369
6430
|
"trace-query-root-span-fields",
|
|
6370
6431
|
"trace-query-root-entity-id"
|
|
6371
6432
|
];
|
|
@@ -6531,4 +6592,4 @@ var ObservabilityStorageDuckDB = class ObservabilityStorageDuckDB extends Observ
|
|
|
6531
6592
|
};
|
|
6532
6593
|
export { ObservabilityStorageDuckDB };
|
|
6533
6594
|
|
|
6534
|
-
//# sourceMappingURL=observability-
|
|
6595
|
+
//# sourceMappingURL=observability-CN4Rwgv9.js.map
|