@mastra/libsql 1.22.3 → 1.22.4-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.
@@ -3,7 +3,7 @@ name: mastra-libsql
3
3
  description: Documentation for @mastra/libsql. Use when working with @mastra/libsql APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/libsql"
6
- version: "1.22.3"
6
+ version: "1.22.4-alpha.1"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.22.3",
2
+ "version": "1.22.4-alpha.1",
3
3
  "package": "@mastra/libsql",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -285,6 +285,8 @@ curl http://localhost:4111/api/agents
285
285
 
286
286
  ### Kubernetes
287
287
 
288
+ > **Helm:** On Kubernetes, the [`mastra-projects` Helm chart](https://mastra.ai/integrations/deploy/kubernetes-helm) renders these deployments for you, with the workers on the same image and environment as the server. It also refuses to install combinations that would run every worker twice. The manifests below are for writing them by hand.
289
+
288
290
  Create separate Deployments for the API, orchestration worker, scheduler worker, and background task worker. Use the same image and Secret for each Deployment. Set only the role-specific environment variables directly on each container.
289
291
 
290
292
  The orchestration worker Deployment has the following shape:
@@ -391,4 +393,5 @@ If the API crashes while a step is executing, that work can be lost and the work
391
393
  - [Workers reference](https://mastra.ai/reference/workers/overview): Details about worker environment variables and types, with a list of supported storage backends
392
394
  - [CLI reference](https://mastra.ai/reference/cli/mastra): `mastra worker build` and `mastra worker start`
393
395
  - [PubSub](https://mastra.ai/docs/server/pubsub): Event delivery backends
396
+ - [Kubernetes (Helm)](https://mastra.ai/integrations/deploy/kubernetes-helm): Deploy worker roles with the official chart
394
397
  - [Scheduled workflows](https://mastra.ai/docs/workflows/scheduled-workflows): Declare cron schedules on workflows
@@ -205,6 +205,7 @@ Each provider page includes installation instructions, configuration parameters,
205
205
  - [libSQL](https://mastra.ai/integrations/databases/libsql)
206
206
  - [Mastra](https://mastra.ai/docs/mastra-platform/database)
207
207
  - [MongoDB](https://mastra.ai/integrations/databases/mongodb)
208
+ - [MySQL](https://mastra.ai/integrations/databases/mysql)
208
209
  - [MSSQL](https://mastra.ai/integrations/databases/mssql)
209
210
  - [Neon Postgres](https://mastra.ai/integrations/databases/neon)
210
211
  - [OracleDB](https://mastra.ai/integrations/databases/oracledb)
package/dist/index.cjs CHANGED
@@ -3613,15 +3613,11 @@ var DatasetsLibSQL = class extends _mastra_core_storage.DatasetsStorage {
3613
3613
  await this.#db.deleteData({ tableName: _mastra_core_storage.TABLE_DATASETS });
3614
3614
  }
3615
3615
  async experimentTablesExist() {
3616
- try {
3617
- const row = (await this.#client.execute({
3618
- sql: `SELECT COUNT(*) AS c FROM sqlite_master WHERE type = 'table' AND name IN (?, ?)`,
3619
- args: [_mastra_core_storage.TABLE_EXPERIMENTS, _mastra_core_storage.TABLE_EXPERIMENT_RESULTS]
3620
- })).rows?.[0];
3621
- return Number(row?.c ?? 0) === 2;
3622
- } catch {
3623
- return false;
3624
- }
3616
+ const row = (await this.#client.execute({
3617
+ sql: `SELECT COUNT(*) AS c FROM sqlite_master WHERE type = 'table' AND name IN (?, ?)`,
3618
+ args: [_mastra_core_storage.TABLE_EXPERIMENTS, _mastra_core_storage.TABLE_EXPERIMENT_RESULTS]
3619
+ })).rows?.[0];
3620
+ return Number(row?.c ?? 0) === 2;
3625
3621
  }
3626
3622
  transformDatasetRow(row) {
3627
3623
  return {
@@ -3646,6 +3642,8 @@ var DatasetsLibSQL = class extends _mastra_core_storage.DatasetsStorage {
3646
3642
  };
3647
3643
  }
3648
3644
  transformItemRow(row) {
3645
+ const metadata = row.metadata ? (0, _mastra_core_storage.safelyParseJSON)(row.metadata) : void 0;
3646
+ const emptyValue = metadata?.__purged === true ? null : void 0;
3649
3647
  return {
3650
3648
  id: row.id,
3651
3649
  datasetId: row.datasetId,
@@ -3654,19 +3652,21 @@ var DatasetsLibSQL = class extends _mastra_core_storage.DatasetsStorage {
3654
3652
  organizationId: row.organizationId ?? null,
3655
3653
  projectId: row.projectId ?? null,
3656
3654
  input: (0, _mastra_core_storage.safelyParseJSON)(row.input),
3657
- groundTruth: row.groundTruth ? (0, _mastra_core_storage.safelyParseJSON)(row.groundTruth) : void 0,
3658
- expectedTrajectory: row.expectedTrajectory ? (0, _mastra_core_storage.safelyParseJSON)(row.expectedTrajectory) : void 0,
3659
- toolMocks: row.toolMocks ? (0, _mastra_core_storage.safelyParseJSON)(row.toolMocks) : void 0,
3660
- unmockedToolPolicy: row.unmockedToolPolicy ?? void 0,
3661
- scorerIds: row.scorerIds ? (0, _mastra_core_storage.safelyParseJSON)(row.scorerIds) : void 0,
3662
- requestContext: row.requestContext ? (0, _mastra_core_storage.safelyParseJSON)(row.requestContext) : void 0,
3663
- metadata: row.metadata ? (0, _mastra_core_storage.safelyParseJSON)(row.metadata) : void 0,
3664
- source: row.source ? (0, _mastra_core_storage.safelyParseJSON)(row.source) : void 0,
3655
+ groundTruth: row.groundTruth ? (0, _mastra_core_storage.safelyParseJSON)(row.groundTruth) : emptyValue,
3656
+ expectedTrajectory: row.expectedTrajectory ? (0, _mastra_core_storage.safelyParseJSON)(row.expectedTrajectory) : emptyValue,
3657
+ toolMocks: row.toolMocks ? (0, _mastra_core_storage.safelyParseJSON)(row.toolMocks) : emptyValue,
3658
+ unmockedToolPolicy: row.unmockedToolPolicy ?? emptyValue,
3659
+ scorerIds: row.scorerIds ? (0, _mastra_core_storage.safelyParseJSON)(row.scorerIds) : emptyValue,
3660
+ requestContext: row.requestContext ? (0, _mastra_core_storage.safelyParseJSON)(row.requestContext) : emptyValue,
3661
+ metadata,
3662
+ source: row.source ? (0, _mastra_core_storage.safelyParseJSON)(row.source) : emptyValue,
3665
3663
  createdAt: (0, _mastra_core_storage.ensureDate)(row.createdAt),
3666
3664
  updatedAt: (0, _mastra_core_storage.ensureDate)(row.updatedAt)
3667
3665
  };
3668
3666
  }
3669
3667
  transformItemRowFull(row) {
3668
+ const metadata = row.metadata ? (0, _mastra_core_storage.safelyParseJSON)(row.metadata) : void 0;
3669
+ const emptyValue = metadata?.__purged === true ? null : void 0;
3670
3670
  return {
3671
3671
  id: row.id,
3672
3672
  datasetId: row.datasetId,
@@ -3677,14 +3677,14 @@ var DatasetsLibSQL = class extends _mastra_core_storage.DatasetsStorage {
3677
3677
  validTo: row.validTo,
3678
3678
  isDeleted: Boolean(row.isDeleted),
3679
3679
  input: (0, _mastra_core_storage.safelyParseJSON)(row.input),
3680
- groundTruth: row.groundTruth ? (0, _mastra_core_storage.safelyParseJSON)(row.groundTruth) : void 0,
3681
- expectedTrajectory: row.expectedTrajectory ? (0, _mastra_core_storage.safelyParseJSON)(row.expectedTrajectory) : void 0,
3682
- toolMocks: row.toolMocks ? (0, _mastra_core_storage.safelyParseJSON)(row.toolMocks) : void 0,
3683
- unmockedToolPolicy: row.unmockedToolPolicy ?? void 0,
3684
- scorerIds: row.scorerIds ? (0, _mastra_core_storage.safelyParseJSON)(row.scorerIds) : void 0,
3685
- requestContext: row.requestContext ? (0, _mastra_core_storage.safelyParseJSON)(row.requestContext) : void 0,
3686
- metadata: row.metadata ? (0, _mastra_core_storage.safelyParseJSON)(row.metadata) : void 0,
3687
- source: row.source ? (0, _mastra_core_storage.safelyParseJSON)(row.source) : void 0,
3680
+ groundTruth: row.groundTruth ? (0, _mastra_core_storage.safelyParseJSON)(row.groundTruth) : emptyValue,
3681
+ expectedTrajectory: row.expectedTrajectory ? (0, _mastra_core_storage.safelyParseJSON)(row.expectedTrajectory) : emptyValue,
3682
+ toolMocks: row.toolMocks ? (0, _mastra_core_storage.safelyParseJSON)(row.toolMocks) : emptyValue,
3683
+ unmockedToolPolicy: row.unmockedToolPolicy ?? emptyValue,
3684
+ scorerIds: row.scorerIds ? (0, _mastra_core_storage.safelyParseJSON)(row.scorerIds) : emptyValue,
3685
+ requestContext: row.requestContext ? (0, _mastra_core_storage.safelyParseJSON)(row.requestContext) : emptyValue,
3686
+ metadata,
3687
+ source: row.source ? (0, _mastra_core_storage.safelyParseJSON)(row.source) : emptyValue,
3688
3688
  createdAt: (0, _mastra_core_storage.ensureDate)(row.createdAt),
3689
3689
  updatedAt: (0, _mastra_core_storage.ensureDate)(row.updatedAt)
3690
3690
  };
@@ -4220,6 +4220,57 @@ var DatasetsLibSQL = class extends _mastra_core_storage.DatasetsStorage {
4220
4220
  }, error);
4221
4221
  }
4222
4222
  }
4223
+ async _doPurgeItem({ id, datasetId }) {
4224
+ try {
4225
+ const experimentTablesExist = await this.experimentTablesExist();
4226
+ await withClientWriteLock(this.#client, async () => {
4227
+ const tx = await this.#client.transaction("write");
4228
+ try {
4229
+ if (!(await tx.execute({
4230
+ sql: `SELECT id FROM ${_mastra_core_storage.TABLE_DATASET_ITEMS} WHERE id = ? AND datasetId = ? LIMIT 1`,
4231
+ args: [id, datasetId]
4232
+ })).rows[0]) {
4233
+ await tx.commit();
4234
+ return;
4235
+ }
4236
+ const purgedAt = (/* @__PURE__ */ new Date()).toISOString();
4237
+ const purgedMetadata = JSON.stringify({
4238
+ __purged: true,
4239
+ purgedAt
4240
+ });
4241
+ await tx.execute({
4242
+ sql: `UPDATE ${_mastra_core_storage.TABLE_DATASET_ITEMS} SET input = jsonb('null'), groundTruth = NULL, expectedTrajectory = NULL, toolMocks = NULL, unmockedToolPolicy = NULL, scorerIds = NULL, requestContext = NULL, metadata = jsonb(?), source = NULL WHERE id = ? AND datasetId = ?`,
4243
+ args: [
4244
+ purgedMetadata,
4245
+ id,
4246
+ datasetId
4247
+ ]
4248
+ });
4249
+ if (experimentTablesExist) await tx.execute({
4250
+ sql: `UPDATE ${_mastra_core_storage.TABLE_EXPERIMENT_RESULTS} SET input = jsonb('null'), output = NULL, groundTruth = NULL, error = NULL, toolMockReport = NULL, tags = NULL, comment = NULL, metadata = jsonb(?) WHERE itemId = ? AND experimentId IN (SELECT id FROM ${_mastra_core_storage.TABLE_EXPERIMENTS} WHERE datasetId = ?)`,
4251
+ args: [
4252
+ purgedMetadata,
4253
+ id,
4254
+ datasetId
4255
+ ]
4256
+ });
4257
+ await tx.commit();
4258
+ } catch (error) {
4259
+ if (!tx.closed) await tx.rollback().catch((rollbackError) => {
4260
+ throw new AggregateError([error, rollbackError], "Transaction and rollback both failed");
4261
+ });
4262
+ throw error;
4263
+ }
4264
+ });
4265
+ } catch (error) {
4266
+ if (error instanceof _mastra_core_error.MastraError) throw error;
4267
+ throw new _mastra_core_error.MastraError({
4268
+ id: (0, _mastra_core_storage.createStorageErrorId)("LIBSQL", "PURGE_ITEM", "FAILED"),
4269
+ domain: _mastra_core_error.ErrorDomain.STORAGE,
4270
+ category: _mastra_core_error.ErrorCategory.THIRD_PARTY
4271
+ }, error);
4272
+ }
4273
+ }
4223
4274
  async getItemById(args) {
4224
4275
  try {
4225
4276
  let result;
@@ -4672,6 +4723,35 @@ var ExperimentsLibSQL = class extends _mastra_core_storage.ExperimentsStorage {
4672
4723
  initialBackoffMs: config.initialBackoffMs
4673
4724
  });
4674
4725
  }
4726
+ async #withPurgeBarrier(experimentId, itemId, fn) {
4727
+ return withClientWriteLock(this.#client, async () => {
4728
+ const tx = await this.#client.transaction("write");
4729
+ try {
4730
+ const row = (await tx.execute({
4731
+ sql: `SELECT json_extract(i."metadata", '$.__purged') AS "purged",
4732
+ json_extract(i."metadata", '$.purgedAt') AS "purgedAt"
4733
+ FROM ${_mastra_core_storage.TABLE_EXPERIMENTS} e
4734
+ JOIN ${_mastra_core_storage.TABLE_DATASET_ITEMS} i ON i."datasetId" = e."datasetId" AND i."id" = ?
4735
+ WHERE e."id" = ? AND json_extract(i."metadata", '$.__purged') = 1
4736
+ LIMIT 1`,
4737
+ args: [itemId, experimentId]
4738
+ })).rows[0];
4739
+ const result = await fn(tx, row?.purged === 1 ? {
4740
+ __purged: true,
4741
+ purgedAt: row.purgedAt
4742
+ } : null);
4743
+ await tx.commit();
4744
+ return result;
4745
+ } catch (error) {
4746
+ if (!tx.closed) await tx.rollback().catch((rollbackError) => {
4747
+ throw new AggregateError([error, rollbackError], "Transaction and rollback both failed");
4748
+ });
4749
+ throw error;
4750
+ } finally {
4751
+ tx.close();
4752
+ }
4753
+ });
4754
+ }
4675
4755
  async init() {
4676
4756
  await this.#db.createTable({
4677
4757
  tableName: _mastra_core_storage.TABLE_EXPERIMENTS,
@@ -5143,30 +5223,37 @@ var ExperimentsLibSQL = class extends _mastra_core_storage.ExperimentsStorage {
5143
5223
  const id = input.id ?? crypto.randomUUID();
5144
5224
  const now = /* @__PURE__ */ new Date();
5145
5225
  const nowIso = now.toISOString();
5146
- await this.#db.insert({
5147
- tableName: _mastra_core_storage.TABLE_EXPERIMENT_RESULTS,
5148
- record: {
5149
- id,
5150
- experimentId: input.experimentId,
5151
- itemId: input.itemId,
5152
- itemDatasetVersion: input.itemDatasetVersion ?? null,
5153
- organizationId: input.organizationId ?? null,
5154
- projectId: input.projectId ?? null,
5155
- input: input.input,
5156
- output: input.output,
5157
- groundTruth: input.groundTruth,
5158
- metadata: input.metadata ?? null,
5159
- error: input.error ?? null,
5160
- startedAt: input.startedAt.toISOString(),
5161
- completedAt: input.completedAt.toISOString(),
5162
- retryCount: input.retryCount,
5163
- attempt: input.attempt ?? 0,
5164
- traceId: input.traceId ?? null,
5165
- status: input.status ?? null,
5166
- tags: input.tags !== void 0 && input.tags !== null ? JSON.stringify(input.tags) : null,
5167
- toolMockReport: input.toolMockReport ?? null,
5168
- createdAt: nowIso
5169
- }
5226
+ const purgeMetadata = await this.#withPurgeBarrier(input.experimentId, input.itemId, async (tx, marker) => {
5227
+ await tx.execute({
5228
+ sql: `INSERT INTO ${_mastra_core_storage.TABLE_EXPERIMENT_RESULTS} (
5229
+ "id", "experimentId", "itemId", "itemDatasetVersion", "organizationId", "projectId",
5230
+ "input", "output", "groundTruth", "metadata", "error", "startedAt", "completedAt",
5231
+ "retryCount", "attempt", "traceId", "status", "tags", "toolMockReport", "createdAt"
5232
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
5233
+ args: [
5234
+ id,
5235
+ input.experimentId,
5236
+ input.itemId,
5237
+ input.itemDatasetVersion ?? null,
5238
+ input.organizationId ?? null,
5239
+ input.projectId ?? null,
5240
+ JSON.stringify(marker ? null : input.input),
5241
+ JSON.stringify(marker ? null : input.output ?? null),
5242
+ JSON.stringify(marker ? null : input.groundTruth ?? null),
5243
+ JSON.stringify(marker ?? input.metadata ?? null),
5244
+ JSON.stringify(marker ? null : input.error ?? null),
5245
+ input.startedAt.toISOString(),
5246
+ input.completedAt.toISOString(),
5247
+ input.retryCount,
5248
+ input.attempt ?? 0,
5249
+ input.traceId ?? null,
5250
+ input.status ?? null,
5251
+ JSON.stringify(marker ? null : input.tags ?? null),
5252
+ JSON.stringify(marker ? null : input.toolMockReport ?? null),
5253
+ nowIso
5254
+ ]
5255
+ });
5256
+ return marker;
5170
5257
  });
5171
5258
  return {
5172
5259
  id,
@@ -5175,19 +5262,19 @@ var ExperimentsLibSQL = class extends _mastra_core_storage.ExperimentsStorage {
5175
5262
  itemDatasetVersion: input.itemDatasetVersion,
5176
5263
  organizationId: input.organizationId ?? null,
5177
5264
  projectId: input.projectId ?? null,
5178
- input: input.input,
5179
- output: input.output,
5180
- groundTruth: input.groundTruth,
5181
- metadata: input.metadata ?? null,
5182
- error: input.error,
5265
+ input: purgeMetadata ? null : input.input,
5266
+ output: purgeMetadata ? null : input.output,
5267
+ groundTruth: purgeMetadata ? null : input.groundTruth,
5268
+ metadata: purgeMetadata ?? input.metadata ?? null,
5269
+ error: purgeMetadata ? null : input.error,
5183
5270
  startedAt: input.startedAt,
5184
5271
  completedAt: input.completedAt,
5185
5272
  retryCount: input.retryCount,
5186
5273
  attempt: input.attempt ?? 0,
5187
5274
  traceId: input.traceId ?? null,
5188
5275
  status: input.status ?? null,
5189
- tags: input.tags ?? null,
5190
- toolMockReport: input.toolMockReport ?? null,
5276
+ tags: purgeMetadata ? null : input.tags ?? null,
5277
+ toolMockReport: purgeMetadata ? null : input.toolMockReport ?? null,
5191
5278
  createdAt: now
5192
5279
  };
5193
5280
  } catch (error) {
@@ -5201,70 +5288,61 @@ var ExperimentsLibSQL = class extends _mastra_core_storage.ExperimentsStorage {
5201
5288
  async upsertExperimentResult(input) {
5202
5289
  try {
5203
5290
  const attempt = input.attempt ?? 0;
5204
- let existingId = (await this.#client.execute({
5205
- sql: `SELECT "id" FROM ${_mastra_core_storage.TABLE_EXPERIMENT_RESULTS} WHERE "experimentId" = ? AND "itemId" = ? AND COALESCE("attempt", 0) = ?`,
5206
- args: [
5207
- input.experimentId,
5208
- input.itemId,
5209
- attempt
5210
- ]
5211
- })).rows[0]?.id;
5212
- if (!existingId) try {
5213
- return await this.addExperimentResult({
5214
- ...input,
5215
- attempt
5291
+ return await this.#withPurgeBarrier(input.experimentId, input.itemId, async (tx, marker) => {
5292
+ const id = crypto.randomUUID();
5293
+ await tx.execute({
5294
+ sql: `INSERT INTO ${_mastra_core_storage.TABLE_EXPERIMENT_RESULTS} (
5295
+ "id", "experimentId", "itemId", "itemDatasetVersion", "organizationId", "projectId",
5296
+ "input", "output", "groundTruth", "metadata", "error", "startedAt", "completedAt",
5297
+ "retryCount", "attempt", "traceId", "status", "tags", "toolMockReport", "createdAt"
5298
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
5299
+ ON CONFLICT("experimentId", "itemId", "attempt") DO UPDATE SET
5300
+ "itemDatasetVersion" = excluded."itemDatasetVersion", "organizationId" = excluded."organizationId",
5301
+ "projectId" = excluded."projectId", "input" = excluded."input", "output" = excluded."output",
5302
+ "groundTruth" = excluded."groundTruth", "metadata" = excluded."metadata", "error" = excluded."error",
5303
+ "startedAt" = excluded."startedAt", "completedAt" = excluded."completedAt",
5304
+ "retryCount" = excluded."retryCount", "attempt" = excluded."attempt", "traceId" = excluded."traceId",
5305
+ "status" = excluded."status", "tags" = excluded."tags", "toolMockReport" = excluded."toolMockReport",
5306
+ "comment" = CASE WHEN ? THEN NULL ELSE "comment" END`,
5307
+ args: [
5308
+ id,
5309
+ input.experimentId,
5310
+ input.itemId,
5311
+ input.itemDatasetVersion ?? null,
5312
+ input.organizationId ?? null,
5313
+ input.projectId ?? null,
5314
+ JSON.stringify(marker ? null : input.input),
5315
+ JSON.stringify(marker ? null : input.output ?? null),
5316
+ JSON.stringify(marker ? null : input.groundTruth ?? null),
5317
+ JSON.stringify(marker ?? input.metadata ?? null),
5318
+ JSON.stringify(marker ? null : input.error ?? null),
5319
+ input.startedAt.toISOString(),
5320
+ input.completedAt.toISOString(),
5321
+ input.retryCount,
5322
+ attempt,
5323
+ input.traceId ?? null,
5324
+ input.status ?? null,
5325
+ JSON.stringify(marker ? null : input.tags ?? null),
5326
+ JSON.stringify(marker ? null : input.toolMockReport ?? null),
5327
+ (/* @__PURE__ */ new Date()).toISOString(),
5328
+ Boolean(marker)
5329
+ ]
5216
5330
  });
5217
- } catch (insertError) {
5218
- if (!(0, _mastra_core_storage.hasErrorCode)(insertError, /* @__PURE__ */ new Set([
5219
- "SQLITE_CONSTRAINT",
5220
- "SQLITE_CONSTRAINT_PRIMARYKEY",
5221
- "SQLITE_CONSTRAINT_UNIQUE"
5222
- ]))) throw insertError;
5223
- existingId = (await this.#client.execute({
5224
- sql: `SELECT "id" FROM ${_mastra_core_storage.TABLE_EXPERIMENT_RESULTS} WHERE "experimentId" = ? AND "itemId" = ? AND COALESCE("attempt", 0) = ?`,
5331
+ const row = (await tx.execute({
5332
+ sql: `SELECT * FROM ${_mastra_core_storage.TABLE_EXPERIMENT_RESULTS} WHERE "experimentId" = ? AND "itemId" = ? AND COALESCE("attempt", 0) = ?`,
5225
5333
  args: [
5226
5334
  input.experimentId,
5227
5335
  input.itemId,
5228
5336
  attempt
5229
5337
  ]
5230
- })).rows[0]?.id;
5231
- if (!existingId) throw insertError;
5232
- }
5233
- await this.#client.execute({
5234
- sql: `UPDATE ${_mastra_core_storage.TABLE_EXPERIMENT_RESULTS} SET
5235
- "itemDatasetVersion" = ?, "organizationId" = ?, "projectId" = ?,
5236
- "input" = ?, "output" = ?, "groundTruth" = ?, "metadata" = ?, "error" = ?,
5237
- "startedAt" = ?, "completedAt" = ?, "retryCount" = ?, "attempt" = ?,
5238
- "traceId" = ?, "status" = ?, "tags" = ?, "toolMockReport" = ?
5239
- WHERE "id" = ?`,
5240
- args: [
5241
- input.itemDatasetVersion ?? null,
5242
- input.organizationId ?? null,
5243
- input.projectId ?? null,
5244
- JSON.stringify(input.input),
5245
- input.output != null ? JSON.stringify(input.output) : null,
5246
- input.groundTruth != null ? JSON.stringify(input.groundTruth) : null,
5247
- input.metadata != null ? JSON.stringify(input.metadata) : null,
5248
- input.error != null ? JSON.stringify(input.error) : null,
5249
- input.startedAt.toISOString(),
5250
- input.completedAt.toISOString(),
5251
- input.retryCount,
5252
- attempt,
5253
- input.traceId ?? null,
5254
- input.status ?? null,
5255
- input.tags != null ? JSON.stringify(input.tags) : null,
5256
- input.toolMockReport != null ? JSON.stringify(input.toolMockReport) : null,
5257
- existingId
5258
- ]
5259
- });
5260
- const result = await this.getExperimentResultById({ id: existingId });
5261
- if (!result) throw new _mastra_core_error.MastraError({
5262
- id: (0, _mastra_core_storage.createStorageErrorId)("LIBSQL", "UPSERT_EXPERIMENT_RESULT", "NOT_FOUND"),
5263
- domain: _mastra_core_error.ErrorDomain.STORAGE,
5264
- category: _mastra_core_error.ErrorCategory.USER,
5265
- details: { resultId: existingId }
5338
+ })).rows[0];
5339
+ if (!row) throw new _mastra_core_error.MastraError({
5340
+ id: (0, _mastra_core_storage.createStorageErrorId)("LIBSQL", "UPSERT_EXPERIMENT_RESULT", "NOT_FOUND"),
5341
+ domain: _mastra_core_error.ErrorDomain.STORAGE,
5342
+ category: _mastra_core_error.ErrorCategory.USER
5343
+ });
5344
+ return this.transformExperimentResultRow(row);
5266
5345
  });
5267
- return result;
5268
5346
  } catch (error) {
5269
5347
  if (error instanceof _mastra_core_error.MastraError) throw error;
5270
5348
  throw new _mastra_core_error.MastraError({
@@ -5276,56 +5354,47 @@ var ExperimentsLibSQL = class extends _mastra_core_storage.ExperimentsStorage {
5276
5354
  }
5277
5355
  async updateExperimentResult(input) {
5278
5356
  try {
5279
- const setClauses = [];
5280
- const values = [];
5281
- if (input.status !== void 0) {
5282
- setClauses.push(`"status" = ?`);
5283
- values.push(input.status);
5284
- }
5285
- if (input.tags !== void 0) {
5286
- setClauses.push(`"tags" = ?`);
5287
- values.push(JSON.stringify(input.tags));
5288
- }
5289
- if (input.comment !== void 0) {
5290
- setClauses.push(`"comment" = ?`);
5291
- values.push(input.comment);
5292
- }
5293
- if (setClauses.length === 0) {
5294
- const existing = await this.getExperimentResultById({ id: input.id });
5295
- if (!existing) throw new _mastra_core_error.MastraError({
5357
+ const ownerRow = (await this.#client.execute({
5358
+ sql: `SELECT "experimentId", "itemId" FROM ${_mastra_core_storage.TABLE_EXPERIMENT_RESULTS} WHERE "id" = ?${input.experimentId ? " AND \"experimentId\" = ?" : ""}`,
5359
+ args: input.experimentId ? [input.id, input.experimentId] : [input.id]
5360
+ })).rows[0];
5361
+ if (!ownerRow) throw new _mastra_core_error.MastraError({
5362
+ id: (0, _mastra_core_storage.createStorageErrorId)("LIBSQL", "UPDATE_EXPERIMENT_RESULT", "NOT_FOUND"),
5363
+ domain: _mastra_core_error.ErrorDomain.STORAGE,
5364
+ category: _mastra_core_error.ErrorCategory.USER,
5365
+ details: { resultId: input.id }
5366
+ });
5367
+ return await this.#withPurgeBarrier(String(ownerRow.experimentId), String(ownerRow.itemId), async (tx, marker) => {
5368
+ if ((await tx.execute({
5369
+ sql: `UPDATE ${_mastra_core_storage.TABLE_EXPERIMENT_RESULTS}
5370
+ SET "status" = CASE WHEN ? THEN ? ELSE "status" END,
5371
+ "tags" = CASE WHEN ? THEN NULL WHEN ? THEN ? ELSE "tags" END,
5372
+ "comment" = CASE WHEN ? THEN NULL WHEN ? THEN ? ELSE "comment" END
5373
+ WHERE "id" = ?${input.experimentId ? " AND \"experimentId\" = ?" : ""}`,
5374
+ args: [
5375
+ input.status !== void 0,
5376
+ input.status ?? null,
5377
+ Boolean(marker),
5378
+ input.tags !== void 0,
5379
+ JSON.stringify(input.tags ?? null),
5380
+ Boolean(marker),
5381
+ input.comment !== void 0,
5382
+ input.comment ?? null,
5383
+ input.id,
5384
+ ...input.experimentId ? [input.experimentId] : []
5385
+ ]
5386
+ })).rowsAffected === 0) throw new _mastra_core_error.MastraError({
5296
5387
  id: (0, _mastra_core_storage.createStorageErrorId)("LIBSQL", "UPDATE_EXPERIMENT_RESULT", "NOT_FOUND"),
5297
5388
  domain: _mastra_core_error.ErrorDomain.STORAGE,
5298
5389
  category: _mastra_core_error.ErrorCategory.USER,
5299
5390
  details: { resultId: input.id }
5300
5391
  });
5301
- return existing;
5302
- }
5303
- values.push(input.id);
5304
- let whereClause = `"id" = ?`;
5305
- if (input.experimentId) {
5306
- values.push(input.experimentId);
5307
- whereClause += ` AND "experimentId" = ?`;
5308
- }
5309
- if ((await this.#client.execute({
5310
- sql: `UPDATE ${_mastra_core_storage.TABLE_EXPERIMENT_RESULTS} SET ${setClauses.join(", ")} WHERE ${whereClause}`,
5311
- args: values
5312
- })).rowsAffected === 0) throw new _mastra_core_error.MastraError({
5313
- id: (0, _mastra_core_storage.createStorageErrorId)("LIBSQL", "UPDATE_EXPERIMENT_RESULT", "NOT_FOUND"),
5314
- domain: _mastra_core_error.ErrorDomain.STORAGE,
5315
- category: _mastra_core_error.ErrorCategory.USER,
5316
- details: {
5317
- resultId: input.id,
5318
- ...input.experimentId ? { experimentId: input.experimentId } : {}
5319
- }
5320
- });
5321
- const result = await this.getExperimentResultById({ id: input.id });
5322
- if (!result) throw new _mastra_core_error.MastraError({
5323
- id: (0, _mastra_core_storage.createStorageErrorId)("LIBSQL", "UPDATE_EXPERIMENT_RESULT", "NOT_FOUND"),
5324
- domain: _mastra_core_error.ErrorDomain.STORAGE,
5325
- category: _mastra_core_error.ErrorCategory.USER,
5326
- details: { resultId: input.id }
5392
+ const result = await tx.execute({
5393
+ sql: `SELECT ${buildSelectColumns(_mastra_core_storage.TABLE_EXPERIMENT_RESULTS)} FROM ${_mastra_core_storage.TABLE_EXPERIMENT_RESULTS} WHERE "id" = ?`,
5394
+ args: [input.id]
5395
+ });
5396
+ return this.transformExperimentResultRow(result.rows[0]);
5327
5397
  });
5328
- return result;
5329
5398
  } catch (error) {
5330
5399
  if (error instanceof _mastra_core_error.MastraError) throw error;
5331
5400
  throw new _mastra_core_error.MastraError({
@@ -9353,6 +9422,10 @@ var MemoryLibSQL = class MemoryLibSQL extends _mastra_core_storage.MemoryStorage
9353
9422
  } catch {
9354
9423
  existingChunks = [];
9355
9424
  }
9425
+ if (existingChunks.some((existing) => existing.cycleId === input.chunk.cycleId)) {
9426
+ await tx.commit();
9427
+ return;
9428
+ }
9356
9429
  const newChunk = {
9357
9430
  id: `ombuf-${(0, crypto$1.randomUUID)()}`,
9358
9431
  cycleId: input.chunk.cycleId,
@@ -10459,6 +10532,7 @@ var ObservabilityLibSQL = class ObservabilityLibSQL extends _mastra_core_storage
10459
10532
  }
10460
10533
  }
10461
10534
  async batchDeleteTraces(args) {
10535
+ this.assertUnscopedBatchDeleteTraces(args);
10462
10536
  try {
10463
10537
  const keys = args.traceIds.map((traceId) => ({ traceId }));
10464
10538
  return this.#db.batchDelete({