@mastra/duckdb 1.16.0-alpha.1 → 1.16.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.
@@ -3,7 +3,7 @@ name: mastra-duckdb
3
3
  description: Documentation for @mastra/duckdb. Use when working with @mastra/duckdb APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/duckdb"
6
- version: "1.16.0-alpha.1"
6
+ version: "1.16.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.16.0-alpha.1",
2
+ "version": "1.16.0",
3
3
  "package": "@mastra/duckdb",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -245,11 +245,11 @@ const results = await store.query({
245
245
 
246
246
  ## Distance metrics
247
247
 
248
- | Metric | Description | Score Interpretation | Best For |
249
- | ------------ | ----------------- | ---------------------- | ----------------------------------- |
250
- | `cosine` | Cosine similarity | 0-1 (1 = most similar) | Text embeddings, normalized vectors |
251
- | `euclidean` | L2 distance | 0-∞ (0 = most similar) | Image embeddings, spatial data |
252
- | `dotproduct` | Inner product | Higher = more similar | When vector magnitude matters |
248
+ | Metric | Description | Score Interpretation | Best For |
249
+ | ------------ | ----------------- | ------------------------------------------------------------- | ----------------------------------- |
250
+ | `cosine` | Cosine similarity | -1 to 1, computed as `1 - cosine distance` (1 = most similar) | Text embeddings, normalized vectors |
251
+ | `euclidean` | L2 distance | 0-1, computed as `1 / (1 + distance)` (1 = most similar) | Image embeddings, spatial data |
252
+ | `dotproduct` | Inner product | Higher = more similar | When vector magnitude matters |
253
253
 
254
254
  ## Error handling
255
255
 
package/dist/index.cjs CHANGED
@@ -564,7 +564,7 @@ var ObservabilityStorageDuckDB = class extends _mastra_core_storage.Observabilit
564
564
  async loadDelegate() {
565
565
  if (this.delegate) return this.delegate;
566
566
  if (this.unavailableError) return null;
567
- if (!this.loadPromise) this.loadPromise = Promise.resolve().then(() => require("./observability-Dlt85fvH.cjs")).then(({ ObservabilityStorageDuckDB }) => {
567
+ if (!this.loadPromise) this.loadPromise = Promise.resolve().then(() => require("./observability-BEdkwaeY.cjs")).then(({ ObservabilityStorageDuckDB }) => {
568
568
  const delegate = new ObservabilityStorageDuckDB({ db: this.db });
569
569
  this.delegate = delegate;
570
570
  return delegate;
package/dist/index.js CHANGED
@@ -563,7 +563,7 @@ var ObservabilityStorageDuckDB = class extends ObservabilityStorage {
563
563
  async loadDelegate() {
564
564
  if (this.delegate) return this.delegate;
565
565
  if (this.unavailableError) return null;
566
- if (!this.loadPromise) this.loadPromise = import("./observability-Chrw9Di2.js").then(({ ObservabilityStorageDuckDB }) => {
566
+ if (!this.loadPromise) this.loadPromise = import("./observability-B-Kt8vrw.js").then(({ ObservabilityStorageDuckDB }) => {
567
567
  const delegate = new ObservabilityStorageDuckDB({ db: this.db });
568
568
  this.delegate = delegate;
569
569
  return delegate;
@@ -1,7 +1,7 @@
1
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
- 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";
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";
5
5
  import { coreFeatures } from "@mastra/core/features";
6
6
  import { EntityType } from "@mastra/core/observability";
7
7
  import { parseFieldKey } from "@mastra/core/utils";
@@ -106,6 +106,17 @@ CREATE TABLE IF NOT EXISTS span_events (
106
106
  endedAt TIMESTAMP,
107
107
  timeToFirstChunkMs DOUBLE,
108
108
 
109
+ -- Native span fields, stored as supplied (NULL when the producer set none)
110
+ externalParentSpanId VARCHAR,
111
+ resumedFromSpanId VARCHAR,
112
+ model VARCHAR,
113
+ provider VARCHAR,
114
+ outcome VARCHAR,
115
+ stopReason VARCHAR,
116
+ timeToFirstTokenMs DOUBLE,
117
+ errorCount INTEGER,
118
+ stopReasonContext JSON,
119
+
109
120
  -- JSON fields
110
121
  attributes JSON,
111
122
  metadata JSON,
@@ -377,6 +388,15 @@ const ALL_MIGRATIONS = [
377
388
  `ALTER TABLE span_events ADD COLUMN IF NOT EXISTS hasOutputPayload BOOLEAN`,
378
389
  `ALTER TABLE span_events ADD COLUMN IF NOT EXISTS hasErrorPayload BOOLEAN`,
379
390
  `ALTER TABLE span_events ADD COLUMN IF NOT EXISTS timeToFirstChunkMs DOUBLE`,
391
+ `ALTER TABLE span_events ADD COLUMN IF NOT EXISTS externalParentSpanId VARCHAR`,
392
+ `ALTER TABLE span_events ADD COLUMN IF NOT EXISTS resumedFromSpanId VARCHAR`,
393
+ `ALTER TABLE span_events ADD COLUMN IF NOT EXISTS model VARCHAR`,
394
+ `ALTER TABLE span_events ADD COLUMN IF NOT EXISTS provider VARCHAR`,
395
+ `ALTER TABLE span_events ADD COLUMN IF NOT EXISTS outcome VARCHAR`,
396
+ `ALTER TABLE span_events ADD COLUMN IF NOT EXISTS stopReason VARCHAR`,
397
+ `ALTER TABLE span_events ADD COLUMN IF NOT EXISTS timeToFirstTokenMs DOUBLE`,
398
+ `ALTER TABLE span_events ADD COLUMN IF NOT EXISTS errorCount INTEGER`,
399
+ `ALTER TABLE span_events ADD COLUMN IF NOT EXISTS stopReasonContext JSON`,
380
400
  `ALTER TABLE span_events ADD COLUMN IF NOT EXISTS parentEntityType VARCHAR`,
381
401
  `ALTER TABLE span_events ADD COLUMN IF NOT EXISTS parentEntityId VARCHAR`,
382
402
  `ALTER TABLE span_events ADD COLUMN IF NOT EXISTS parentEntityName VARCHAR`,
@@ -4342,7 +4362,7 @@ async function queryThreadRows(db, plan, strategy = "auto") {
4342
4362
  return `${field} ${field === "organizationId" || field === "resourceId" ? "IS NOT DISTINCT FROM" : "="} ?`;
4343
4363
  }).join(" AND ")})`;
4344
4364
  }));
4345
- const payloads = await run(`SELECT organizationId, traceId, cursorId, spanType,
4365
+ const payloads = await run(`SELECT organizationId, traceId, cursorId,
4346
4366
  ${contextFields.map((field) => field === "executionSource" ? "source AS executionSource" : field).join(", ")},
4347
4367
  CASE WHEN spanType = 'agent_run' THEN timeToFirstChunkMs END AS timeToFirstChunkMs,
4348
4368
  CASE WHEN error IS NULL THEN 'success' ELSE 'error' END AS status,
@@ -4358,34 +4378,10 @@ async function queryThreadRows(db, plan, strategy = "auto") {
4358
4378
  String(version)
4359
4379
  ]);
4360
4380
  const byRoot = new Map(payloads.map((row) => [key(row.organizationId, row.traceId, row.cursorId), row]));
4361
- const agents = page.filter((row) => byRoot.get(key(row.organizationId, row.firstTraceId, row.firstCursorId))?.spanType === "agent_run");
4362
- const models = /* @__PURE__ */ new Map();
4363
- if (agents.length) {
4364
- const modelValues = [];
4365
- const rows = await run(`WITH generations AS (
4366
- SELECT organizationId, traceId, spanId, endedAt, cursorId, attributes,
4367
- min(timestamp) FILTER (WHERE eventType = 'start') OVER (PARTITION BY organizationId, traceId, spanId) AS startedAt
4368
- FROM span_events WHERE spanType = 'model_generation' AND (${agents.map((row) => `(${Object.entries({
4369
- organizationId: row.organizationId,
4370
- resourceId: row.resourceId,
4371
- traceId: row.firstTraceId,
4372
- parentSpanId: row.firstSpanId
4373
- }).map(([field, value]) => {
4374
- modelValues.push(value);
4375
- return `${field} ${field === "organizationId" || field === "resourceId" ? "IS NOT DISTINCT FROM" : "="} ?`;
4376
- }).join(" AND ")})`).join(" OR ")})
4377
- ) SELECT organizationId, traceId,
4378
- CASE WHEN json_type(attributes, '$.model') = 'VARCHAR' THEN json_extract_string(attributes, '$.model') END AS model,
4379
- CASE WHEN json_type(attributes, '$.provider') = 'VARCHAR' THEN json_extract_string(attributes, '$.provider') END AS provider
4380
- FROM generations WHERE endedAt IS NOT NULL
4381
- QUALIFY row_number() OVER (PARTITION BY organizationId, traceId ORDER BY startedAt, spanId, cursorId DESC) = 1`, modelValues);
4382
- for (const row of rows) models.set(JSON.stringify([row.organizationId, row.traceId]), row);
4383
- }
4384
4381
  const threads = page.flatMap((row) => {
4385
4382
  const first = byRoot.get(key(row.organizationId, row.firstTraceId, row.firstCursorId));
4386
4383
  const last = byRoot.get(key(row.organizationId, row.lastTraceId, row.lastCursorId));
4387
4384
  if (!first || !last) return [];
4388
- const model = models.get(JSON.stringify([row.organizationId, row.firstTraceId]));
4389
4385
  return [coreStorage.threadQueryRowSchema.parse({
4390
4386
  organizationId: row.organizationId,
4391
4387
  threadId: row.threadId,
@@ -4397,8 +4393,6 @@ async function queryThreadRows(db, plan, strategy = "auto") {
4397
4393
  endedAt: row.endedAt.toISOString(),
4398
4394
  traceCount: Number(row.traceCount),
4399
4395
  timeToFirstChunkMs: first.timeToFirstChunkMs,
4400
- model: model?.model ?? null,
4401
- provider: model?.provider ?? null,
4402
4396
  inputPreview: readPreview(first.inputPreview, first.input, true),
4403
4397
  outputPreview: readPreview(last.outputPreview, last.output, true),
4404
4398
  errorPreview: readPreview(last.errorPreview, last.error, true)
@@ -4808,6 +4802,15 @@ const COLUMNS_SQL = [
4808
4802
  "isEvent",
4809
4803
  "endedAt",
4810
4804
  "timeToFirstChunkMs",
4805
+ "externalParentSpanId",
4806
+ "resumedFromSpanId",
4807
+ "model",
4808
+ "provider",
4809
+ "outcome",
4810
+ "stopReason",
4811
+ "timeToFirstTokenMs",
4812
+ "errorCount",
4813
+ "stopReasonContext",
4811
4814
  "experimentId",
4812
4815
  "entityType",
4813
4816
  "entityId",
@@ -4923,7 +4926,16 @@ const SPAN_RECONSTRUCT_SELECT = `
4923
4926
  ${argMaxNonNull("input")},
4924
4927
  ${argMaxNonNull("output")},
4925
4928
  ${argMaxNonNull("error")},
4926
- ${argMaxNonNull("requestContext")}
4929
+ ${argMaxNonNull("requestContext")},
4930
+ ${argMaxNonNull("externalParentSpanId")},
4931
+ ${argMaxNonNull("resumedFromSpanId")},
4932
+ ${argMaxNonNull("model")},
4933
+ ${argMaxNonNull("provider")},
4934
+ ${argMaxNonNull("outcome")},
4935
+ ${argMaxNonNull("stopReason")},
4936
+ ${argMaxNonNull("timeToFirstTokenMs")},
4937
+ ${argMaxNonNull("errorCount")},
4938
+ ${argMaxNonNull("stopReasonContext")}
4927
4939
  FROM span_events
4928
4940
  `;
4929
4941
  /** Lightweight variant — only timeline-relevant columns. */
@@ -5119,6 +5131,7 @@ function rowToLightSpanRecordWithPreview(row) {
5119
5131
  };
5120
5132
  }
5121
5133
  function rowToSpanRecord(row) {
5134
+ const attributes = parseJson(row.attributes);
5122
5135
  return {
5123
5136
  traceId: row.traceId,
5124
5137
  spanId: row.spanId,
@@ -5128,6 +5141,15 @@ function rowToSpanRecord(row) {
5128
5141
  isEvent: row.isEvent,
5129
5142
  startedAt: toDate(row.startedAt),
5130
5143
  endedAt: rowEndedAt(row),
5144
+ externalParentSpanId: row.externalParentSpanId ?? null,
5145
+ resumedFromSpanId: row.resumedFromSpanId ?? null,
5146
+ model: row.model ?? getStringAttribute(attributes, "model"),
5147
+ provider: row.provider ?? getStringAttribute(attributes, "provider"),
5148
+ outcome: row.outcome ?? null,
5149
+ stopReason: row.stopReason ?? null,
5150
+ timeToFirstTokenMs: row.timeToFirstTokenMs ?? null,
5151
+ errorCount: row.errorCount ?? null,
5152
+ stopReasonContext: parseJson(row.stopReasonContext),
5131
5153
  experimentId: row.experimentId ?? null,
5132
5154
  entityType: row.entityType ?? null,
5133
5155
  entityId: row.entityId ?? null,
@@ -5151,7 +5173,7 @@ function rowToSpanRecord(row) {
5151
5173
  environment: row.environment ?? null,
5152
5174
  source: row.source ?? null,
5153
5175
  serviceName: row.serviceName ?? null,
5154
- attributes: parseJson(row.attributes),
5176
+ attributes,
5155
5177
  metadata: parseJson(row.metadata),
5156
5178
  tags: parseJsonArray(row.tags),
5157
5179
  scope: parseJson(row.scope),
@@ -5314,6 +5336,15 @@ function toValuesTuple(row) {
5314
5336
  v(row.isEvent),
5315
5337
  v(row.endedAt),
5316
5338
  v(row.timeToFirstChunkMs),
5339
+ v(row.externalParentSpanId),
5340
+ v(row.resumedFromSpanId),
5341
+ v(row.model),
5342
+ v(row.provider),
5343
+ v(row.outcome),
5344
+ v(row.stopReason),
5345
+ v(row.timeToFirstTokenMs),
5346
+ v(row.errorCount),
5347
+ jsonV(row.stopReasonContext),
5317
5348
  v(row.experimentId),
5318
5349
  v(row.entityType),
5319
5350
  v(row.entityId),
@@ -5359,6 +5390,24 @@ async function insertSpanEvents(db, rows) {
5359
5390
  const tuples = rows.map((row) => `(${toValuesTuple(row)})`).join(",\n");
5360
5391
  await db.execute(`INSERT INTO span_events (${COLUMNS_SQL}) VALUES ${tuples}`);
5361
5392
  }
5393
+ /**
5394
+ * Columns copied as supplied onto both event rows (NULL when unset). Previews
5395
+ * stay out: the start row derives them from the payload it keeps.
5396
+ */
5397
+ function copiedSpanColumns(s) {
5398
+ return {
5399
+ timeToFirstChunkMs: s.timeToFirstChunkMs ?? null,
5400
+ externalParentSpanId: s.externalParentSpanId ?? null,
5401
+ resumedFromSpanId: s.resumedFromSpanId ?? null,
5402
+ model: s.model ?? null,
5403
+ provider: s.provider ?? null,
5404
+ outcome: s.outcome ?? null,
5405
+ stopReason: s.stopReason ?? null,
5406
+ timeToFirstTokenMs: s.timeToFirstTokenMs ?? null,
5407
+ errorCount: s.errorCount ?? null,
5408
+ stopReasonContext: s.stopReasonContext ?? null
5409
+ };
5410
+ }
5362
5411
  function createStartSpanRow(s) {
5363
5412
  const payloadOnEndRow = !!s.endedAt && !s.isEvent;
5364
5413
  const input = previewOf(!payloadOnEndRow, s.input, s.inputPreview);
@@ -5372,7 +5421,7 @@ function createStartSpanRow(s) {
5372
5421
  spanType: s.spanType,
5373
5422
  isEvent: s.isEvent,
5374
5423
  endedAt: s.isEvent ? s.startedAt : null,
5375
- timeToFirstChunkMs: s.timeToFirstChunkMs ?? null,
5424
+ ...copiedSpanColumns(s),
5376
5425
  experimentId: s.experimentId ?? null,
5377
5426
  entityType: s.entityType ?? null,
5378
5427
  entityId: s.entityId ?? null,
@@ -5427,7 +5476,7 @@ function createEndSpanRow(s) {
5427
5476
  spanType: s.spanType,
5428
5477
  isEvent: s.isEvent,
5429
5478
  endedAt: s.endedAt ?? null,
5430
- timeToFirstChunkMs: s.timeToFirstChunkMs ?? null,
5479
+ ...copiedSpanColumns(s),
5431
5480
  experimentId: s.experimentId ?? null,
5432
5481
  entityType: s.entityType ?? null,
5433
5482
  entityId: s.entityId ?? null,
@@ -6482,4 +6531,4 @@ var ObservabilityStorageDuckDB = class ObservabilityStorageDuckDB extends Observ
6482
6531
  };
6483
6532
  export { ObservabilityStorageDuckDB };
6484
6533
 
6485
- //# sourceMappingURL=observability-Chrw9Di2.js.map
6534
+ //# sourceMappingURL=observability-B-Kt8vrw.js.map