@mastra/spanner 1.8.0 → 1.8.1-alpha.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-spanner
3
3
  description: Documentation for @mastra/spanner. Use when working with @mastra/spanner APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/spanner"
6
- version: "1.8.0"
6
+ version: "1.8.1-alpha.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.8.0",
2
+ "version": "1.8.1-alpha.0",
3
3
  "package": "@mastra/spanner",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -15,7 +15,7 @@ Storage adapters use the shared core retention contract for `prune()`, or a data
15
15
  | Adapter | Mechanism | Retention support |
16
16
  | -------------------- | ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
17
17
  | libSQL | `prune()` | All supported growth domains |
18
- | PostgreSQL | `prune()` | All supported growth domains. V-next observability drops expired partitions or chunks |
18
+ | PostgreSQL | `prune()` | All supported growth domains. vNext observability drops expired partitions or chunks |
19
19
  | MongoDB | `prune()` or native TTL | All supported growth domains. Native TTL indexes are also available |
20
20
  | DuckDB | `prune()` | Observability spans, metrics, logs, scores, and feedback |
21
21
  | MySQL | `prune()` | Observability spans |
@@ -102,10 +102,10 @@ Each domain specifies its age-prunable tables and the timestamp column that anch
102
102
  | `memory` | `resources` | `createdAt` | Resource age |
103
103
  | `threadState` | `threadState` | `updatedAt` | Inactivity: state for still-active threads survives |
104
104
  | `observability` | `spans` | `startedAt` | Span age |
105
- | `observability` | `metrics` | `timestamp` | Metric event age (v-next only) |
106
- | `observability` | `logs` | `timestamp` | Log event age (v-next only) |
107
- | `observability` | `scores` | `timestamp` | Score event age (v-next only) |
108
- | `observability` | `feedback` | `timestamp` | Feedback event age (v-next only) |
105
+ | `observability` | `metrics` | `timestamp` | Metric event age (vNext only) |
106
+ | `observability` | `logs` | `timestamp` | Log event age (vNext only) |
107
+ | `observability` | `scores` | `timestamp` | Score event age (vNext only) |
108
+ | `observability` | `feedback` | `timestamp` | Feedback event age (vNext only) |
109
109
  | `scores` | `scorers` | `createdAt` | Score record age |
110
110
  | `workflows` | `workflowSnapshot` | `updatedAt` | Inactivity, suspended or long-running workflows survive |
111
111
  | `backgroundTasks` | `backgroundTasks` | `completedAt` | Time since completion, in-flight tasks (`NULL`) are never pruned |
@@ -122,7 +122,7 @@ Each domain specifies its age-prunable tables and the timestamp column that anch
122
122
  > - On PostgreSQL, timestamp anchors use the timezone-aware mirror columns (for example `createdAtZ`, `completedAtZ`).
123
123
  > - DuckDB observability stores append-only events for all five signals. Its `spans` policy uses the event `timestamp` column rather than `startedAt`.
124
124
  > - LibSQL and PostgreSQL support all domains above except `harness`, which PostgreSQL doesn't implement. MongoDB supports all except `threadState` and `harness`. DuckDB, MySQL, Microsoft SQL Server, Oracle Database, Amazon Aurora DSQL, and Google Cloud Spanner currently support retention only in their `observability` domains, with the signal coverage shown in the support matrix.
125
- > - The v-next PostgreSQL observability domain stores signal events in day-partitioned tables (`spans`, `metrics`, `logs`, `scores`, `feedback`). For it, `prune()` drops whole day partitions (or TimescaleDB chunks) that are entirely older than the cutoff instead of deleting rows: effective level of detail is one day, and a partition is only dropped once its entire day is past `maxAge`. `PruneResult.deleted` reports the number of rows in the dropped partitions.
125
+ > - The vNext PostgreSQL observability domain stores signal events in day-partitioned tables (`spans`, `metrics`, `logs`, `scores`, `feedback`). For it, `prune()` drops whole day partitions (or TimescaleDB chunks) that are entirely older than the cutoff instead of deleting rows: effective level of detail is one day, and a partition is only dropped once its entire day is past `maxAge`. `PruneResult.deleted` reports the number of rows in the dropped partitions.
126
126
 
127
127
  ## Methods
128
128
 
@@ -208,7 +208,9 @@ You can also cancel a long-running prune with an `AbortSignal`: the loop stops b
208
208
 
209
209
  ClickHouse observability storage uses native table TTLs instead of `prune()`. Configure retention as days per signal. `init()` applies the TTLs to new and existing tables and skips `ALTER TABLE` statements when the configured TTL is already present.
210
210
 
211
- For deployments that need to update TTL configuration without running the full initialization path, call `applyRetention()` on the v-next observability store:
211
+ Omitted signals, and signals set to zero or less, get no TTL. When you remove a signal from `retention`, the next `init()` or `applyRetention()` removes that table's TTL. If Mastra can't read the current TTLs from `system.tables`, it applies the configured TTLs and leaves the others unchanged.
212
+
213
+ For deployments that need to update TTL configuration without running the full initialization path, call `applyRetention()` on the vNext observability store:
212
214
 
213
215
  ```typescript
214
216
  import { ObservabilityStorageClickhouseVNext } from '@mastra/clickhouse'
package/dist/index.cjs CHANGED
@@ -2755,6 +2755,17 @@ var ChannelsSpanner = class ChannelsSpanner extends _mastra_core_storage.Channel
2755
2755
  function toDate$1(value) {
2756
2756
  return value instanceof Date ? value : new Date(value);
2757
2757
  }
2758
+ function jsonDataArg(value) {
2759
+ return value === void 0 ? null : JSON.stringify(value);
2760
+ }
2761
+ const ITEM_SELECT_COLUMNS = Object.keys(_mastra_core_storage.TABLE_SCHEMAS[_mastra_core_storage.TABLE_DATASET_ITEMS]).map((column) => {
2762
+ const name = quoteIdent(column, "column name");
2763
+ return [
2764
+ "input",
2765
+ "groundTruth",
2766
+ "expectedTrajectory"
2767
+ ].includes(column) ? `CASE WHEN ${name} IS NULL THEN NULL ELSE TO_JSON_STRING(${name}) END AS ${name}` : name;
2768
+ }).join(", ");
2758
2769
  function rowToDataset(row) {
2759
2770
  const t = transformFromSpannerRow({
2760
2771
  tableName: _mastra_core_storage.TABLE_DATASETS,
@@ -2768,10 +2779,10 @@ function rowToDataset(row) {
2768
2779
  inputSchema: t.inputSchema ?? void 0,
2769
2780
  groundTruthSchema: t.groundTruthSchema ?? void 0,
2770
2781
  requestContextSchema: t.requestContextSchema ?? void 0,
2771
- tags: t.tags ?? null,
2772
- targetType: t.targetType ?? null,
2773
- targetIds: t.targetIds ?? null,
2774
- scorerIds: t.scorerIds ?? null,
2782
+ tags: t.tags ?? void 0,
2783
+ targetType: t.targetType ?? void 0,
2784
+ targetIds: t.targetIds ?? void 0,
2785
+ scorerIds: t.scorerIds ?? void 0,
2775
2786
  version: Number(t.version ?? 0),
2776
2787
  organizationId: t.organizationId ?? null,
2777
2788
  projectId: t.projectId ?? null,
@@ -2795,8 +2806,8 @@ function rowToItem(row) {
2795
2806
  organizationId: t.organizationId ?? null,
2796
2807
  projectId: t.projectId ?? null,
2797
2808
  input: t.input,
2798
- groundTruth: t.groundTruth ?? emptyValue,
2799
- expectedTrajectory: t.expectedTrajectory ?? emptyValue,
2809
+ groundTruth: row.groundTruth == null ? emptyValue : t.groundTruth,
2810
+ expectedTrajectory: row.expectedTrajectory == null ? emptyValue : t.expectedTrajectory,
2800
2811
  toolMocks: t.toolMocks ?? emptyValue,
2801
2812
  unmockedToolPolicy: t.unmockedToolPolicy ?? emptyValue,
2802
2813
  scorerIds: t.scorerIds ?? emptyValue,
@@ -2973,10 +2984,10 @@ var DatasetsSpanner = class DatasetsSpanner extends _mastra_core_storage.Dataset
2973
2984
  inputSchema: input.inputSchema ?? void 0,
2974
2985
  groundTruthSchema: input.groundTruthSchema ?? void 0,
2975
2986
  requestContextSchema: input.requestContextSchema ?? void 0,
2976
- tags: null,
2977
- targetType: input.targetType ?? null,
2978
- targetIds: input.targetIds ?? null,
2979
- scorerIds: input.scorerIds ?? null,
2987
+ tags: void 0,
2988
+ targetType: input.targetType ?? void 0,
2989
+ targetIds: input.targetIds ?? void 0,
2990
+ scorerIds: input.scorerIds ?? void 0,
2980
2991
  version: 0,
2981
2992
  organizationId: input.organizationId ?? null,
2982
2993
  projectId: input.projectId ?? null,
@@ -3336,7 +3347,7 @@ var DatasetsSpanner = class DatasetsSpanner extends _mastra_core_storage.Dataset
3336
3347
  /** Reads the current live row for an item (validTo IS NULL, not deleted). */
3337
3348
  async loadCurrentItemRow(tx, itemId) {
3338
3349
  const [rows] = await tx.run({
3339
- sql: `SELECT * FROM ${quoteIdent(_mastra_core_storage.TABLE_DATASET_ITEMS, "table name")}
3350
+ sql: `SELECT ${ITEM_SELECT_COLUMNS} FROM ${quoteIdent(_mastra_core_storage.TABLE_DATASET_ITEMS, "table name")}
3340
3351
  WHERE ${quoteIdent("id", "column name")} = @id
3341
3352
  AND ${quoteIdent("validTo", "column name")} IS NULL
3342
3353
  AND ${quoteIdent("isDeleted", "column name")} = FALSE LIMIT 1`,
@@ -3364,9 +3375,9 @@ var DatasetsSpanner = class DatasetsSpanner extends _mastra_core_storage.Dataset
3364
3375
  projectId,
3365
3376
  validTo: null,
3366
3377
  isDeleted: false,
3367
- input: args.input,
3368
- groundTruth: args.groundTruth ?? null,
3369
- expectedTrajectory: args.expectedTrajectory ?? null,
3378
+ input: jsonDataArg(args.input),
3379
+ groundTruth: jsonDataArg(args.groundTruth),
3380
+ expectedTrajectory: jsonDataArg(args.expectedTrajectory),
3370
3381
  toolMocks: args.toolMocks ?? null,
3371
3382
  unmockedToolPolicy: args.unmockedToolPolicy ?? null,
3372
3383
  scorerIds: args.scorerIds ?? null,
@@ -3474,9 +3485,9 @@ var DatasetsSpanner = class DatasetsSpanner extends _mastra_core_storage.Dataset
3474
3485
  projectId,
3475
3486
  validTo: null,
3476
3487
  isDeleted: false,
3477
- input: merged.input,
3478
- groundTruth: merged.groundTruth ?? null,
3479
- expectedTrajectory: merged.expectedTrajectory ?? null,
3488
+ input: jsonDataArg(merged.input),
3489
+ groundTruth: jsonDataArg(merged.groundTruth),
3490
+ expectedTrajectory: jsonDataArg(merged.expectedTrajectory),
3480
3491
  toolMocks: merged.toolMocks ?? null,
3481
3492
  unmockedToolPolicy: merged.unmockedToolPolicy ?? null,
3482
3493
  scorerIds: merged.scorerIds ?? null,
@@ -3560,9 +3571,9 @@ var DatasetsSpanner = class DatasetsSpanner extends _mastra_core_storage.Dataset
3560
3571
  projectId,
3561
3572
  validTo: null,
3562
3573
  isDeleted: true,
3563
- input: existing.input,
3564
- groundTruth: existing.groundTruth ?? null,
3565
- expectedTrajectory: existing.expectedTrajectory ?? null,
3574
+ input: jsonDataArg(existing.input),
3575
+ groundTruth: jsonDataArg(existing.groundTruth),
3576
+ expectedTrajectory: jsonDataArg(existing.expectedTrajectory),
3566
3577
  toolMocks: existing.toolMocks ?? null,
3567
3578
  unmockedToolPolicy: existing.unmockedToolPolicy ?? null,
3568
3579
  scorerIds: existing.scorerIds ?? null,
@@ -3729,7 +3740,7 @@ var DatasetsSpanner = class DatasetsSpanner extends _mastra_core_storage.Dataset
3729
3740
  };
3730
3741
  const limit = perPageInput === false ? total : perPage;
3731
3742
  const [rows] = await this.database.run({
3732
- sql: `SELECT * FROM ${tableName} ${whereSql}
3743
+ sql: `SELECT ${ITEM_SELECT_COLUMNS} FROM ${tableName} ${whereSql}
3733
3744
  ORDER BY ${quoteIdent(orderBy.field, "column name")} ${orderBy.direction}, ${quoteIdent("id", "column name")} ASC
3734
3745
  LIMIT @limit OFFSET @offset`,
3735
3746
  params: {
@@ -3763,7 +3774,7 @@ var DatasetsSpanner = class DatasetsSpanner extends _mastra_core_storage.Dataset
3763
3774
  let sql;
3764
3775
  const params = { id: args.id };
3765
3776
  if (args.datasetVersion !== void 0) {
3766
- sql = `SELECT * FROM ${tableName}
3777
+ sql = `SELECT ${ITEM_SELECT_COLUMNS} FROM ${tableName}
3767
3778
  WHERE ${quoteIdent("id", "column name")} = @id
3768
3779
  AND ${quoteIdent("datasetVersion", "column name")} <= @datasetVersion
3769
3780
  AND (${quoteIdent("validTo", "column name")} IS NULL OR ${quoteIdent("validTo", "column name")} > @datasetVersion)
@@ -3771,7 +3782,7 @@ var DatasetsSpanner = class DatasetsSpanner extends _mastra_core_storage.Dataset
3771
3782
  ORDER BY ${quoteIdent("datasetVersion", "column name")} DESC
3772
3783
  LIMIT 1`;
3773
3784
  params.datasetVersion = args.datasetVersion;
3774
- } else sql = `SELECT * FROM ${tableName}
3785
+ } else sql = `SELECT ${ITEM_SELECT_COLUMNS} FROM ${tableName}
3775
3786
  WHERE ${quoteIdent("id", "column name")} = @id
3776
3787
  AND ${quoteIdent("validTo", "column name")} IS NULL
3777
3788
  AND ${quoteIdent("isDeleted", "column name")} = FALSE LIMIT 1`;
@@ -3795,7 +3806,7 @@ var DatasetsSpanner = class DatasetsSpanner extends _mastra_core_storage.Dataset
3795
3806
  try {
3796
3807
  const tableName = quoteIdent(_mastra_core_storage.TABLE_DATASET_ITEMS, "table name");
3797
3808
  const [rows] = await this.database.run({
3798
- sql: `SELECT * FROM ${tableName}
3809
+ sql: `SELECT ${ITEM_SELECT_COLUMNS} FROM ${tableName}
3799
3810
  WHERE ${quoteIdent("datasetId", "column name")} = @datasetId
3800
3811
  AND ${quoteIdent("datasetVersion", "column name")} <= @version
3801
3812
  AND (${quoteIdent("validTo", "column name")} IS NULL OR ${quoteIdent("validTo", "column name")} > @version)
@@ -3824,7 +3835,7 @@ var DatasetsSpanner = class DatasetsSpanner extends _mastra_core_storage.Dataset
3824
3835
  try {
3825
3836
  const tableName = quoteIdent(_mastra_core_storage.TABLE_DATASET_ITEMS, "table name");
3826
3837
  const [rows] = await this.database.run({
3827
- sql: `SELECT * FROM ${tableName}
3838
+ sql: `SELECT ${ITEM_SELECT_COLUMNS} FROM ${tableName}
3828
3839
  WHERE ${quoteIdent("id", "column name")} = @id
3829
3840
  ORDER BY ${quoteIdent("datasetVersion", "column name")} DESC`,
3830
3841
  params: { id: itemId },
@@ -3944,7 +3955,7 @@ var DatasetsSpanner = class DatasetsSpanner extends _mastra_core_storage.Dataset
3944
3955
  let historyRows = [];
3945
3956
  if (externalIds.length > 0) {
3946
3957
  const [rows] = await tx.run({
3947
- sql: `SELECT * FROM ${quoteIdent(_mastra_core_storage.TABLE_DATASET_ITEMS, "table name")} WHERE ${quoteIdent("datasetId", "column name")} = @datasetId AND ${quoteIdent("externalId", "column name")} IN UNNEST(@externalIds) ORDER BY ${quoteIdent("datasetVersion", "column name")}`,
3958
+ sql: `SELECT ${ITEM_SELECT_COLUMNS} FROM ${quoteIdent(_mastra_core_storage.TABLE_DATASET_ITEMS, "table name")} WHERE ${quoteIdent("datasetId", "column name")} = @datasetId AND ${quoteIdent("externalId", "column name")} IN UNNEST(@externalIds) ORDER BY ${quoteIdent("datasetVersion", "column name")}`,
3948
3959
  params: {
3949
3960
  datasetId: input.datasetId,
3950
3961
  externalIds
@@ -3986,6 +3997,9 @@ var DatasetsSpanner = class DatasetsSpanner extends _mastra_core_storage.Dataset
3986
3997
  tableName: _mastra_core_storage.TABLE_DATASET_ITEMS,
3987
3998
  record: {
3988
3999
  ...item,
4000
+ input: jsonDataArg(item.input),
4001
+ groundTruth: jsonDataArg(item.groundTruth),
4002
+ expectedTrajectory: jsonDataArg(item.expectedTrajectory),
3989
4003
  validTo: null,
3990
4004
  isDeleted: false
3991
4005
  },
@@ -4043,9 +4057,9 @@ var DatasetsSpanner = class DatasetsSpanner extends _mastra_core_storage.Dataset
4043
4057
  projectId,
4044
4058
  validTo: null,
4045
4059
  isDeleted: true,
4046
- input: existing.input,
4047
- groundTruth: existing.groundTruth ?? null,
4048
- expectedTrajectory: existing.expectedTrajectory ?? null,
4060
+ input: jsonDataArg(existing.input),
4061
+ groundTruth: jsonDataArg(existing.groundTruth),
4062
+ expectedTrajectory: jsonDataArg(existing.expectedTrajectory),
4049
4063
  toolMocks: existing.toolMocks ?? null,
4050
4064
  unmockedToolPolicy: existing.unmockedToolPolicy ?? null,
4051
4065
  scorerIds: existing.scorerIds ?? null,