@mastra/libsql 1.22.4-alpha.0 → 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.
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +226 -157
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +226 -157
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/datasets/index.d.ts +2 -1
- package/dist/storage/domains/datasets/index.d.ts.map +1 -1
- package/dist/storage/domains/experiments/index.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/docs/SKILL.md
CHANGED
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
|
-
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
|
|
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) :
|
|
3658
|
-
expectedTrajectory: row.expectedTrajectory ? (0, _mastra_core_storage.safelyParseJSON)(row.expectedTrajectory) :
|
|
3659
|
-
toolMocks: row.toolMocks ? (0, _mastra_core_storage.safelyParseJSON)(row.toolMocks) :
|
|
3660
|
-
unmockedToolPolicy: row.unmockedToolPolicy ??
|
|
3661
|
-
scorerIds: row.scorerIds ? (0, _mastra_core_storage.safelyParseJSON)(row.scorerIds) :
|
|
3662
|
-
requestContext: row.requestContext ? (0, _mastra_core_storage.safelyParseJSON)(row.requestContext) :
|
|
3663
|
-
metadata
|
|
3664
|
-
source: row.source ? (0, _mastra_core_storage.safelyParseJSON)(row.source) :
|
|
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) :
|
|
3681
|
-
expectedTrajectory: row.expectedTrajectory ? (0, _mastra_core_storage.safelyParseJSON)(row.expectedTrajectory) :
|
|
3682
|
-
toolMocks: row.toolMocks ? (0, _mastra_core_storage.safelyParseJSON)(row.toolMocks) :
|
|
3683
|
-
unmockedToolPolicy: row.unmockedToolPolicy ??
|
|
3684
|
-
scorerIds: row.scorerIds ? (0, _mastra_core_storage.safelyParseJSON)(row.scorerIds) :
|
|
3685
|
-
requestContext: row.requestContext ? (0, _mastra_core_storage.safelyParseJSON)(row.requestContext) :
|
|
3686
|
-
metadata
|
|
3687
|
-
source: row.source ? (0, _mastra_core_storage.safelyParseJSON)(row.source) :
|
|
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.#
|
|
5147
|
-
|
|
5148
|
-
|
|
5149
|
-
|
|
5150
|
-
|
|
5151
|
-
|
|
5152
|
-
|
|
5153
|
-
|
|
5154
|
-
|
|
5155
|
-
|
|
5156
|
-
|
|
5157
|
-
|
|
5158
|
-
|
|
5159
|
-
|
|
5160
|
-
|
|
5161
|
-
|
|
5162
|
-
|
|
5163
|
-
|
|
5164
|
-
|
|
5165
|
-
|
|
5166
|
-
|
|
5167
|
-
|
|
5168
|
-
|
|
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
|
-
|
|
5205
|
-
|
|
5206
|
-
|
|
5207
|
-
|
|
5208
|
-
|
|
5209
|
-
|
|
5210
|
-
|
|
5211
|
-
|
|
5212
|
-
|
|
5213
|
-
|
|
5214
|
-
|
|
5215
|
-
|
|
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
|
-
|
|
5218
|
-
|
|
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]
|
|
5231
|
-
if (!
|
|
5232
|
-
|
|
5233
|
-
|
|
5234
|
-
|
|
5235
|
-
|
|
5236
|
-
|
|
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
|
|
5280
|
-
|
|
5281
|
-
|
|
5282
|
-
|
|
5283
|
-
|
|
5284
|
-
|
|
5285
|
-
|
|
5286
|
-
|
|
5287
|
-
|
|
5288
|
-
}
|
|
5289
|
-
|
|
5290
|
-
|
|
5291
|
-
|
|
5292
|
-
|
|
5293
|
-
|
|
5294
|
-
|
|
5295
|
-
|
|
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
|
-
|
|
5302
|
-
|
|
5303
|
-
|
|
5304
|
-
|
|
5305
|
-
|
|
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({
|