@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.
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-deployment-workers.md +3 -0
- package/dist/docs/references/docs-storage.md +1 -0
- package/dist/index.cjs +231 -157
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +231 -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/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/domains/observability/index.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -3612,15 +3612,11 @@ var DatasetsLibSQL = class extends DatasetsStorage {
|
|
|
3612
3612
|
await this.#db.deleteData({ tableName: TABLE_DATASETS });
|
|
3613
3613
|
}
|
|
3614
3614
|
async experimentTablesExist() {
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
return Number(row?.c ?? 0) === 2;
|
|
3621
|
-
} catch {
|
|
3622
|
-
return false;
|
|
3623
|
-
}
|
|
3615
|
+
const row = (await this.#client.execute({
|
|
3616
|
+
sql: `SELECT COUNT(*) AS c FROM sqlite_master WHERE type = 'table' AND name IN (?, ?)`,
|
|
3617
|
+
args: [TABLE_EXPERIMENTS, TABLE_EXPERIMENT_RESULTS]
|
|
3618
|
+
})).rows?.[0];
|
|
3619
|
+
return Number(row?.c ?? 0) === 2;
|
|
3624
3620
|
}
|
|
3625
3621
|
transformDatasetRow(row) {
|
|
3626
3622
|
return {
|
|
@@ -3645,6 +3641,8 @@ var DatasetsLibSQL = class extends DatasetsStorage {
|
|
|
3645
3641
|
};
|
|
3646
3642
|
}
|
|
3647
3643
|
transformItemRow(row) {
|
|
3644
|
+
const metadata = row.metadata ? safelyParseJSON(row.metadata) : void 0;
|
|
3645
|
+
const emptyValue = metadata?.__purged === true ? null : void 0;
|
|
3648
3646
|
return {
|
|
3649
3647
|
id: row.id,
|
|
3650
3648
|
datasetId: row.datasetId,
|
|
@@ -3653,19 +3651,21 @@ var DatasetsLibSQL = class extends DatasetsStorage {
|
|
|
3653
3651
|
organizationId: row.organizationId ?? null,
|
|
3654
3652
|
projectId: row.projectId ?? null,
|
|
3655
3653
|
input: safelyParseJSON(row.input),
|
|
3656
|
-
groundTruth: row.groundTruth ? safelyParseJSON(row.groundTruth) :
|
|
3657
|
-
expectedTrajectory: row.expectedTrajectory ? safelyParseJSON(row.expectedTrajectory) :
|
|
3658
|
-
toolMocks: row.toolMocks ? safelyParseJSON(row.toolMocks) :
|
|
3659
|
-
unmockedToolPolicy: row.unmockedToolPolicy ??
|
|
3660
|
-
scorerIds: row.scorerIds ? safelyParseJSON(row.scorerIds) :
|
|
3661
|
-
requestContext: row.requestContext ? safelyParseJSON(row.requestContext) :
|
|
3662
|
-
metadata
|
|
3663
|
-
source: row.source ? safelyParseJSON(row.source) :
|
|
3654
|
+
groundTruth: row.groundTruth ? safelyParseJSON(row.groundTruth) : emptyValue,
|
|
3655
|
+
expectedTrajectory: row.expectedTrajectory ? safelyParseJSON(row.expectedTrajectory) : emptyValue,
|
|
3656
|
+
toolMocks: row.toolMocks ? safelyParseJSON(row.toolMocks) : emptyValue,
|
|
3657
|
+
unmockedToolPolicy: row.unmockedToolPolicy ?? emptyValue,
|
|
3658
|
+
scorerIds: row.scorerIds ? safelyParseJSON(row.scorerIds) : emptyValue,
|
|
3659
|
+
requestContext: row.requestContext ? safelyParseJSON(row.requestContext) : emptyValue,
|
|
3660
|
+
metadata,
|
|
3661
|
+
source: row.source ? safelyParseJSON(row.source) : emptyValue,
|
|
3664
3662
|
createdAt: ensureDate(row.createdAt),
|
|
3665
3663
|
updatedAt: ensureDate(row.updatedAt)
|
|
3666
3664
|
};
|
|
3667
3665
|
}
|
|
3668
3666
|
transformItemRowFull(row) {
|
|
3667
|
+
const metadata = row.metadata ? safelyParseJSON(row.metadata) : void 0;
|
|
3668
|
+
const emptyValue = metadata?.__purged === true ? null : void 0;
|
|
3669
3669
|
return {
|
|
3670
3670
|
id: row.id,
|
|
3671
3671
|
datasetId: row.datasetId,
|
|
@@ -3676,14 +3676,14 @@ var DatasetsLibSQL = class extends DatasetsStorage {
|
|
|
3676
3676
|
validTo: row.validTo,
|
|
3677
3677
|
isDeleted: Boolean(row.isDeleted),
|
|
3678
3678
|
input: safelyParseJSON(row.input),
|
|
3679
|
-
groundTruth: row.groundTruth ? safelyParseJSON(row.groundTruth) :
|
|
3680
|
-
expectedTrajectory: row.expectedTrajectory ? safelyParseJSON(row.expectedTrajectory) :
|
|
3681
|
-
toolMocks: row.toolMocks ? safelyParseJSON(row.toolMocks) :
|
|
3682
|
-
unmockedToolPolicy: row.unmockedToolPolicy ??
|
|
3683
|
-
scorerIds: row.scorerIds ? safelyParseJSON(row.scorerIds) :
|
|
3684
|
-
requestContext: row.requestContext ? safelyParseJSON(row.requestContext) :
|
|
3685
|
-
metadata
|
|
3686
|
-
source: row.source ? safelyParseJSON(row.source) :
|
|
3679
|
+
groundTruth: row.groundTruth ? safelyParseJSON(row.groundTruth) : emptyValue,
|
|
3680
|
+
expectedTrajectory: row.expectedTrajectory ? safelyParseJSON(row.expectedTrajectory) : emptyValue,
|
|
3681
|
+
toolMocks: row.toolMocks ? safelyParseJSON(row.toolMocks) : emptyValue,
|
|
3682
|
+
unmockedToolPolicy: row.unmockedToolPolicy ?? emptyValue,
|
|
3683
|
+
scorerIds: row.scorerIds ? safelyParseJSON(row.scorerIds) : emptyValue,
|
|
3684
|
+
requestContext: row.requestContext ? safelyParseJSON(row.requestContext) : emptyValue,
|
|
3685
|
+
metadata,
|
|
3686
|
+
source: row.source ? safelyParseJSON(row.source) : emptyValue,
|
|
3687
3687
|
createdAt: ensureDate(row.createdAt),
|
|
3688
3688
|
updatedAt: ensureDate(row.updatedAt)
|
|
3689
3689
|
};
|
|
@@ -4219,6 +4219,57 @@ var DatasetsLibSQL = class extends DatasetsStorage {
|
|
|
4219
4219
|
}, error);
|
|
4220
4220
|
}
|
|
4221
4221
|
}
|
|
4222
|
+
async _doPurgeItem({ id, datasetId }) {
|
|
4223
|
+
try {
|
|
4224
|
+
const experimentTablesExist = await this.experimentTablesExist();
|
|
4225
|
+
await withClientWriteLock(this.#client, async () => {
|
|
4226
|
+
const tx = await this.#client.transaction("write");
|
|
4227
|
+
try {
|
|
4228
|
+
if (!(await tx.execute({
|
|
4229
|
+
sql: `SELECT id FROM ${TABLE_DATASET_ITEMS} WHERE id = ? AND datasetId = ? LIMIT 1`,
|
|
4230
|
+
args: [id, datasetId]
|
|
4231
|
+
})).rows[0]) {
|
|
4232
|
+
await tx.commit();
|
|
4233
|
+
return;
|
|
4234
|
+
}
|
|
4235
|
+
const purgedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
4236
|
+
const purgedMetadata = JSON.stringify({
|
|
4237
|
+
__purged: true,
|
|
4238
|
+
purgedAt
|
|
4239
|
+
});
|
|
4240
|
+
await tx.execute({
|
|
4241
|
+
sql: `UPDATE ${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 = ?`,
|
|
4242
|
+
args: [
|
|
4243
|
+
purgedMetadata,
|
|
4244
|
+
id,
|
|
4245
|
+
datasetId
|
|
4246
|
+
]
|
|
4247
|
+
});
|
|
4248
|
+
if (experimentTablesExist) await tx.execute({
|
|
4249
|
+
sql: `UPDATE ${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 ${TABLE_EXPERIMENTS} WHERE datasetId = ?)`,
|
|
4250
|
+
args: [
|
|
4251
|
+
purgedMetadata,
|
|
4252
|
+
id,
|
|
4253
|
+
datasetId
|
|
4254
|
+
]
|
|
4255
|
+
});
|
|
4256
|
+
await tx.commit();
|
|
4257
|
+
} catch (error) {
|
|
4258
|
+
if (!tx.closed) await tx.rollback().catch((rollbackError) => {
|
|
4259
|
+
throw new AggregateError([error, rollbackError], "Transaction and rollback both failed");
|
|
4260
|
+
});
|
|
4261
|
+
throw error;
|
|
4262
|
+
}
|
|
4263
|
+
});
|
|
4264
|
+
} catch (error) {
|
|
4265
|
+
if (error instanceof MastraError) throw error;
|
|
4266
|
+
throw new MastraError({
|
|
4267
|
+
id: createStorageErrorId("LIBSQL", "PURGE_ITEM", "FAILED"),
|
|
4268
|
+
domain: ErrorDomain.STORAGE,
|
|
4269
|
+
category: ErrorCategory.THIRD_PARTY
|
|
4270
|
+
}, error);
|
|
4271
|
+
}
|
|
4272
|
+
}
|
|
4222
4273
|
async getItemById(args) {
|
|
4223
4274
|
try {
|
|
4224
4275
|
let result;
|
|
@@ -4671,6 +4722,35 @@ var ExperimentsLibSQL = class extends ExperimentsStorage {
|
|
|
4671
4722
|
initialBackoffMs: config.initialBackoffMs
|
|
4672
4723
|
});
|
|
4673
4724
|
}
|
|
4725
|
+
async #withPurgeBarrier(experimentId, itemId, fn) {
|
|
4726
|
+
return withClientWriteLock(this.#client, async () => {
|
|
4727
|
+
const tx = await this.#client.transaction("write");
|
|
4728
|
+
try {
|
|
4729
|
+
const row = (await tx.execute({
|
|
4730
|
+
sql: `SELECT json_extract(i."metadata", '$.__purged') AS "purged",
|
|
4731
|
+
json_extract(i."metadata", '$.purgedAt') AS "purgedAt"
|
|
4732
|
+
FROM ${TABLE_EXPERIMENTS} e
|
|
4733
|
+
JOIN ${TABLE_DATASET_ITEMS} i ON i."datasetId" = e."datasetId" AND i."id" = ?
|
|
4734
|
+
WHERE e."id" = ? AND json_extract(i."metadata", '$.__purged') = 1
|
|
4735
|
+
LIMIT 1`,
|
|
4736
|
+
args: [itemId, experimentId]
|
|
4737
|
+
})).rows[0];
|
|
4738
|
+
const result = await fn(tx, row?.purged === 1 ? {
|
|
4739
|
+
__purged: true,
|
|
4740
|
+
purgedAt: row.purgedAt
|
|
4741
|
+
} : null);
|
|
4742
|
+
await tx.commit();
|
|
4743
|
+
return result;
|
|
4744
|
+
} catch (error) {
|
|
4745
|
+
if (!tx.closed) await tx.rollback().catch((rollbackError) => {
|
|
4746
|
+
throw new AggregateError([error, rollbackError], "Transaction and rollback both failed");
|
|
4747
|
+
});
|
|
4748
|
+
throw error;
|
|
4749
|
+
} finally {
|
|
4750
|
+
tx.close();
|
|
4751
|
+
}
|
|
4752
|
+
});
|
|
4753
|
+
}
|
|
4674
4754
|
async init() {
|
|
4675
4755
|
await this.#db.createTable({
|
|
4676
4756
|
tableName: TABLE_EXPERIMENTS,
|
|
@@ -5142,30 +5222,37 @@ var ExperimentsLibSQL = class extends ExperimentsStorage {
|
|
|
5142
5222
|
const id = input.id ?? crypto.randomUUID();
|
|
5143
5223
|
const now = /* @__PURE__ */ new Date();
|
|
5144
5224
|
const nowIso = now.toISOString();
|
|
5145
|
-
await this.#
|
|
5146
|
-
|
|
5147
|
-
|
|
5148
|
-
|
|
5149
|
-
|
|
5150
|
-
|
|
5151
|
-
|
|
5152
|
-
|
|
5153
|
-
|
|
5154
|
-
|
|
5155
|
-
|
|
5156
|
-
|
|
5157
|
-
|
|
5158
|
-
|
|
5159
|
-
|
|
5160
|
-
|
|
5161
|
-
|
|
5162
|
-
|
|
5163
|
-
|
|
5164
|
-
|
|
5165
|
-
|
|
5166
|
-
|
|
5167
|
-
|
|
5168
|
-
|
|
5225
|
+
const purgeMetadata = await this.#withPurgeBarrier(input.experimentId, input.itemId, async (tx, marker) => {
|
|
5226
|
+
await tx.execute({
|
|
5227
|
+
sql: `INSERT INTO ${TABLE_EXPERIMENT_RESULTS} (
|
|
5228
|
+
"id", "experimentId", "itemId", "itemDatasetVersion", "organizationId", "projectId",
|
|
5229
|
+
"input", "output", "groundTruth", "metadata", "error", "startedAt", "completedAt",
|
|
5230
|
+
"retryCount", "attempt", "traceId", "status", "tags", "toolMockReport", "createdAt"
|
|
5231
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
5232
|
+
args: [
|
|
5233
|
+
id,
|
|
5234
|
+
input.experimentId,
|
|
5235
|
+
input.itemId,
|
|
5236
|
+
input.itemDatasetVersion ?? null,
|
|
5237
|
+
input.organizationId ?? null,
|
|
5238
|
+
input.projectId ?? null,
|
|
5239
|
+
JSON.stringify(marker ? null : input.input),
|
|
5240
|
+
JSON.stringify(marker ? null : input.output ?? null),
|
|
5241
|
+
JSON.stringify(marker ? null : input.groundTruth ?? null),
|
|
5242
|
+
JSON.stringify(marker ?? input.metadata ?? null),
|
|
5243
|
+
JSON.stringify(marker ? null : input.error ?? null),
|
|
5244
|
+
input.startedAt.toISOString(),
|
|
5245
|
+
input.completedAt.toISOString(),
|
|
5246
|
+
input.retryCount,
|
|
5247
|
+
input.attempt ?? 0,
|
|
5248
|
+
input.traceId ?? null,
|
|
5249
|
+
input.status ?? null,
|
|
5250
|
+
JSON.stringify(marker ? null : input.tags ?? null),
|
|
5251
|
+
JSON.stringify(marker ? null : input.toolMockReport ?? null),
|
|
5252
|
+
nowIso
|
|
5253
|
+
]
|
|
5254
|
+
});
|
|
5255
|
+
return marker;
|
|
5169
5256
|
});
|
|
5170
5257
|
return {
|
|
5171
5258
|
id,
|
|
@@ -5174,19 +5261,19 @@ var ExperimentsLibSQL = class extends ExperimentsStorage {
|
|
|
5174
5261
|
itemDatasetVersion: input.itemDatasetVersion,
|
|
5175
5262
|
organizationId: input.organizationId ?? null,
|
|
5176
5263
|
projectId: input.projectId ?? null,
|
|
5177
|
-
input: input.input,
|
|
5178
|
-
output: input.output,
|
|
5179
|
-
groundTruth: input.groundTruth,
|
|
5180
|
-
metadata: input.metadata ?? null,
|
|
5181
|
-
error: input.error,
|
|
5264
|
+
input: purgeMetadata ? null : input.input,
|
|
5265
|
+
output: purgeMetadata ? null : input.output,
|
|
5266
|
+
groundTruth: purgeMetadata ? null : input.groundTruth,
|
|
5267
|
+
metadata: purgeMetadata ?? input.metadata ?? null,
|
|
5268
|
+
error: purgeMetadata ? null : input.error,
|
|
5182
5269
|
startedAt: input.startedAt,
|
|
5183
5270
|
completedAt: input.completedAt,
|
|
5184
5271
|
retryCount: input.retryCount,
|
|
5185
5272
|
attempt: input.attempt ?? 0,
|
|
5186
5273
|
traceId: input.traceId ?? null,
|
|
5187
5274
|
status: input.status ?? null,
|
|
5188
|
-
tags: input.tags ?? null,
|
|
5189
|
-
toolMockReport: input.toolMockReport ?? null,
|
|
5275
|
+
tags: purgeMetadata ? null : input.tags ?? null,
|
|
5276
|
+
toolMockReport: purgeMetadata ? null : input.toolMockReport ?? null,
|
|
5190
5277
|
createdAt: now
|
|
5191
5278
|
};
|
|
5192
5279
|
} catch (error) {
|
|
@@ -5200,70 +5287,61 @@ var ExperimentsLibSQL = class extends ExperimentsStorage {
|
|
|
5200
5287
|
async upsertExperimentResult(input) {
|
|
5201
5288
|
try {
|
|
5202
5289
|
const attempt = input.attempt ?? 0;
|
|
5203
|
-
|
|
5204
|
-
|
|
5205
|
-
|
|
5206
|
-
|
|
5207
|
-
|
|
5208
|
-
|
|
5209
|
-
|
|
5210
|
-
|
|
5211
|
-
|
|
5212
|
-
|
|
5213
|
-
|
|
5214
|
-
|
|
5290
|
+
return await this.#withPurgeBarrier(input.experimentId, input.itemId, async (tx, marker) => {
|
|
5291
|
+
const id = crypto.randomUUID();
|
|
5292
|
+
await tx.execute({
|
|
5293
|
+
sql: `INSERT INTO ${TABLE_EXPERIMENT_RESULTS} (
|
|
5294
|
+
"id", "experimentId", "itemId", "itemDatasetVersion", "organizationId", "projectId",
|
|
5295
|
+
"input", "output", "groundTruth", "metadata", "error", "startedAt", "completedAt",
|
|
5296
|
+
"retryCount", "attempt", "traceId", "status", "tags", "toolMockReport", "createdAt"
|
|
5297
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
5298
|
+
ON CONFLICT("experimentId", "itemId", "attempt") DO UPDATE SET
|
|
5299
|
+
"itemDatasetVersion" = excluded."itemDatasetVersion", "organizationId" = excluded."organizationId",
|
|
5300
|
+
"projectId" = excluded."projectId", "input" = excluded."input", "output" = excluded."output",
|
|
5301
|
+
"groundTruth" = excluded."groundTruth", "metadata" = excluded."metadata", "error" = excluded."error",
|
|
5302
|
+
"startedAt" = excluded."startedAt", "completedAt" = excluded."completedAt",
|
|
5303
|
+
"retryCount" = excluded."retryCount", "attempt" = excluded."attempt", "traceId" = excluded."traceId",
|
|
5304
|
+
"status" = excluded."status", "tags" = excluded."tags", "toolMockReport" = excluded."toolMockReport",
|
|
5305
|
+
"comment" = CASE WHEN ? THEN NULL ELSE "comment" END`,
|
|
5306
|
+
args: [
|
|
5307
|
+
id,
|
|
5308
|
+
input.experimentId,
|
|
5309
|
+
input.itemId,
|
|
5310
|
+
input.itemDatasetVersion ?? null,
|
|
5311
|
+
input.organizationId ?? null,
|
|
5312
|
+
input.projectId ?? null,
|
|
5313
|
+
JSON.stringify(marker ? null : input.input),
|
|
5314
|
+
JSON.stringify(marker ? null : input.output ?? null),
|
|
5315
|
+
JSON.stringify(marker ? null : input.groundTruth ?? null),
|
|
5316
|
+
JSON.stringify(marker ?? input.metadata ?? null),
|
|
5317
|
+
JSON.stringify(marker ? null : input.error ?? null),
|
|
5318
|
+
input.startedAt.toISOString(),
|
|
5319
|
+
input.completedAt.toISOString(),
|
|
5320
|
+
input.retryCount,
|
|
5321
|
+
attempt,
|
|
5322
|
+
input.traceId ?? null,
|
|
5323
|
+
input.status ?? null,
|
|
5324
|
+
JSON.stringify(marker ? null : input.tags ?? null),
|
|
5325
|
+
JSON.stringify(marker ? null : input.toolMockReport ?? null),
|
|
5326
|
+
(/* @__PURE__ */ new Date()).toISOString(),
|
|
5327
|
+
Boolean(marker)
|
|
5328
|
+
]
|
|
5215
5329
|
});
|
|
5216
|
-
|
|
5217
|
-
|
|
5218
|
-
"SQLITE_CONSTRAINT",
|
|
5219
|
-
"SQLITE_CONSTRAINT_PRIMARYKEY",
|
|
5220
|
-
"SQLITE_CONSTRAINT_UNIQUE"
|
|
5221
|
-
]))) throw insertError;
|
|
5222
|
-
existingId = (await this.#client.execute({
|
|
5223
|
-
sql: `SELECT "id" FROM ${TABLE_EXPERIMENT_RESULTS} WHERE "experimentId" = ? AND "itemId" = ? AND COALESCE("attempt", 0) = ?`,
|
|
5330
|
+
const row = (await tx.execute({
|
|
5331
|
+
sql: `SELECT * FROM ${TABLE_EXPERIMENT_RESULTS} WHERE "experimentId" = ? AND "itemId" = ? AND COALESCE("attempt", 0) = ?`,
|
|
5224
5332
|
args: [
|
|
5225
5333
|
input.experimentId,
|
|
5226
5334
|
input.itemId,
|
|
5227
5335
|
attempt
|
|
5228
5336
|
]
|
|
5229
|
-
})).rows[0]
|
|
5230
|
-
if (!
|
|
5231
|
-
|
|
5232
|
-
|
|
5233
|
-
|
|
5234
|
-
|
|
5235
|
-
|
|
5236
|
-
"startedAt" = ?, "completedAt" = ?, "retryCount" = ?, "attempt" = ?,
|
|
5237
|
-
"traceId" = ?, "status" = ?, "tags" = ?, "toolMockReport" = ?
|
|
5238
|
-
WHERE "id" = ?`,
|
|
5239
|
-
args: [
|
|
5240
|
-
input.itemDatasetVersion ?? null,
|
|
5241
|
-
input.organizationId ?? null,
|
|
5242
|
-
input.projectId ?? null,
|
|
5243
|
-
JSON.stringify(input.input),
|
|
5244
|
-
input.output != null ? JSON.stringify(input.output) : null,
|
|
5245
|
-
input.groundTruth != null ? JSON.stringify(input.groundTruth) : null,
|
|
5246
|
-
input.metadata != null ? JSON.stringify(input.metadata) : null,
|
|
5247
|
-
input.error != null ? JSON.stringify(input.error) : null,
|
|
5248
|
-
input.startedAt.toISOString(),
|
|
5249
|
-
input.completedAt.toISOString(),
|
|
5250
|
-
input.retryCount,
|
|
5251
|
-
attempt,
|
|
5252
|
-
input.traceId ?? null,
|
|
5253
|
-
input.status ?? null,
|
|
5254
|
-
input.tags != null ? JSON.stringify(input.tags) : null,
|
|
5255
|
-
input.toolMockReport != null ? JSON.stringify(input.toolMockReport) : null,
|
|
5256
|
-
existingId
|
|
5257
|
-
]
|
|
5258
|
-
});
|
|
5259
|
-
const result = await this.getExperimentResultById({ id: existingId });
|
|
5260
|
-
if (!result) throw new MastraError({
|
|
5261
|
-
id: createStorageErrorId("LIBSQL", "UPSERT_EXPERIMENT_RESULT", "NOT_FOUND"),
|
|
5262
|
-
domain: ErrorDomain.STORAGE,
|
|
5263
|
-
category: ErrorCategory.USER,
|
|
5264
|
-
details: { resultId: existingId }
|
|
5337
|
+
})).rows[0];
|
|
5338
|
+
if (!row) throw new MastraError({
|
|
5339
|
+
id: createStorageErrorId("LIBSQL", "UPSERT_EXPERIMENT_RESULT", "NOT_FOUND"),
|
|
5340
|
+
domain: ErrorDomain.STORAGE,
|
|
5341
|
+
category: ErrorCategory.USER
|
|
5342
|
+
});
|
|
5343
|
+
return this.transformExperimentResultRow(row);
|
|
5265
5344
|
});
|
|
5266
|
-
return result;
|
|
5267
5345
|
} catch (error) {
|
|
5268
5346
|
if (error instanceof MastraError) throw error;
|
|
5269
5347
|
throw new MastraError({
|
|
@@ -5275,56 +5353,47 @@ var ExperimentsLibSQL = class extends ExperimentsStorage {
|
|
|
5275
5353
|
}
|
|
5276
5354
|
async updateExperimentResult(input) {
|
|
5277
5355
|
try {
|
|
5278
|
-
const
|
|
5279
|
-
|
|
5280
|
-
|
|
5281
|
-
|
|
5282
|
-
|
|
5283
|
-
|
|
5284
|
-
|
|
5285
|
-
|
|
5286
|
-
|
|
5287
|
-
}
|
|
5288
|
-
|
|
5289
|
-
|
|
5290
|
-
|
|
5291
|
-
|
|
5292
|
-
|
|
5293
|
-
|
|
5294
|
-
|
|
5356
|
+
const ownerRow = (await this.#client.execute({
|
|
5357
|
+
sql: `SELECT "experimentId", "itemId" FROM ${TABLE_EXPERIMENT_RESULTS} WHERE "id" = ?${input.experimentId ? " AND \"experimentId\" = ?" : ""}`,
|
|
5358
|
+
args: input.experimentId ? [input.id, input.experimentId] : [input.id]
|
|
5359
|
+
})).rows[0];
|
|
5360
|
+
if (!ownerRow) throw new MastraError({
|
|
5361
|
+
id: createStorageErrorId("LIBSQL", "UPDATE_EXPERIMENT_RESULT", "NOT_FOUND"),
|
|
5362
|
+
domain: ErrorDomain.STORAGE,
|
|
5363
|
+
category: ErrorCategory.USER,
|
|
5364
|
+
details: { resultId: input.id }
|
|
5365
|
+
});
|
|
5366
|
+
return await this.#withPurgeBarrier(String(ownerRow.experimentId), String(ownerRow.itemId), async (tx, marker) => {
|
|
5367
|
+
if ((await tx.execute({
|
|
5368
|
+
sql: `UPDATE ${TABLE_EXPERIMENT_RESULTS}
|
|
5369
|
+
SET "status" = CASE WHEN ? THEN ? ELSE "status" END,
|
|
5370
|
+
"tags" = CASE WHEN ? THEN NULL WHEN ? THEN ? ELSE "tags" END,
|
|
5371
|
+
"comment" = CASE WHEN ? THEN NULL WHEN ? THEN ? ELSE "comment" END
|
|
5372
|
+
WHERE "id" = ?${input.experimentId ? " AND \"experimentId\" = ?" : ""}`,
|
|
5373
|
+
args: [
|
|
5374
|
+
input.status !== void 0,
|
|
5375
|
+
input.status ?? null,
|
|
5376
|
+
Boolean(marker),
|
|
5377
|
+
input.tags !== void 0,
|
|
5378
|
+
JSON.stringify(input.tags ?? null),
|
|
5379
|
+
Boolean(marker),
|
|
5380
|
+
input.comment !== void 0,
|
|
5381
|
+
input.comment ?? null,
|
|
5382
|
+
input.id,
|
|
5383
|
+
...input.experimentId ? [input.experimentId] : []
|
|
5384
|
+
]
|
|
5385
|
+
})).rowsAffected === 0) throw new MastraError({
|
|
5295
5386
|
id: createStorageErrorId("LIBSQL", "UPDATE_EXPERIMENT_RESULT", "NOT_FOUND"),
|
|
5296
5387
|
domain: ErrorDomain.STORAGE,
|
|
5297
5388
|
category: ErrorCategory.USER,
|
|
5298
5389
|
details: { resultId: input.id }
|
|
5299
5390
|
});
|
|
5300
|
-
|
|
5301
|
-
|
|
5302
|
-
|
|
5303
|
-
|
|
5304
|
-
|
|
5305
|
-
values.push(input.experimentId);
|
|
5306
|
-
whereClause += ` AND "experimentId" = ?`;
|
|
5307
|
-
}
|
|
5308
|
-
if ((await this.#client.execute({
|
|
5309
|
-
sql: `UPDATE ${TABLE_EXPERIMENT_RESULTS} SET ${setClauses.join(", ")} WHERE ${whereClause}`,
|
|
5310
|
-
args: values
|
|
5311
|
-
})).rowsAffected === 0) throw new MastraError({
|
|
5312
|
-
id: createStorageErrorId("LIBSQL", "UPDATE_EXPERIMENT_RESULT", "NOT_FOUND"),
|
|
5313
|
-
domain: ErrorDomain.STORAGE,
|
|
5314
|
-
category: ErrorCategory.USER,
|
|
5315
|
-
details: {
|
|
5316
|
-
resultId: input.id,
|
|
5317
|
-
...input.experimentId ? { experimentId: input.experimentId } : {}
|
|
5318
|
-
}
|
|
5319
|
-
});
|
|
5320
|
-
const result = await this.getExperimentResultById({ id: input.id });
|
|
5321
|
-
if (!result) throw new MastraError({
|
|
5322
|
-
id: createStorageErrorId("LIBSQL", "UPDATE_EXPERIMENT_RESULT", "NOT_FOUND"),
|
|
5323
|
-
domain: ErrorDomain.STORAGE,
|
|
5324
|
-
category: ErrorCategory.USER,
|
|
5325
|
-
details: { resultId: input.id }
|
|
5391
|
+
const result = await tx.execute({
|
|
5392
|
+
sql: `SELECT ${buildSelectColumns(TABLE_EXPERIMENT_RESULTS)} FROM ${TABLE_EXPERIMENT_RESULTS} WHERE "id" = ?`,
|
|
5393
|
+
args: [input.id]
|
|
5394
|
+
});
|
|
5395
|
+
return this.transformExperimentResultRow(result.rows[0]);
|
|
5326
5396
|
});
|
|
5327
|
-
return result;
|
|
5328
5397
|
} catch (error) {
|
|
5329
5398
|
if (error instanceof MastraError) throw error;
|
|
5330
5399
|
throw new MastraError({
|
|
@@ -9352,6 +9421,10 @@ var MemoryLibSQL = class MemoryLibSQL extends MemoryStorage {
|
|
|
9352
9421
|
} catch {
|
|
9353
9422
|
existingChunks = [];
|
|
9354
9423
|
}
|
|
9424
|
+
if (existingChunks.some((existing) => existing.cycleId === input.chunk.cycleId)) {
|
|
9425
|
+
await tx.commit();
|
|
9426
|
+
return;
|
|
9427
|
+
}
|
|
9355
9428
|
const newChunk = {
|
|
9356
9429
|
id: `ombuf-${randomUUID()}`,
|
|
9357
9430
|
cycleId: input.chunk.cycleId,
|
|
@@ -10458,6 +10531,7 @@ var ObservabilityLibSQL = class ObservabilityLibSQL extends ObservabilityStorage
|
|
|
10458
10531
|
}
|
|
10459
10532
|
}
|
|
10460
10533
|
async batchDeleteTraces(args) {
|
|
10534
|
+
this.assertUnscopedBatchDeleteTraces(args);
|
|
10461
10535
|
try {
|
|
10462
10536
|
const keys = args.traceIds.map((traceId) => ({ traceId }));
|
|
10463
10537
|
return this.#db.batchDelete({
|