@mastra/libsql 1.21.1-alpha.0 → 1.21.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/CHANGELOG.md +90 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/reference-rag-retrieval.md +113 -5
- package/dist/index.cjs +108 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +108 -12
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/datasets/index.d.ts.map +1 -1
- package/dist/storage/domains/experiments/index.d.ts +2 -1
- package/dist/storage/domains/experiments/index.d.ts.map +1 -1
- package/dist/storage/domains/scores/index.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -4135,8 +4135,12 @@ var DatasetsLibSQL = class extends DatasetsStorage {
|
|
|
4135
4135
|
try {
|
|
4136
4136
|
let result;
|
|
4137
4137
|
if (args.datasetVersion !== void 0) result = await this.#client.execute({
|
|
4138
|
-
sql: `SELECT ${buildSelectColumns(TABLE_DATASET_ITEMS)} FROM ${TABLE_DATASET_ITEMS} WHERE id = ? AND datasetVersion
|
|
4139
|
-
args: [
|
|
4138
|
+
sql: `SELECT ${buildSelectColumns(TABLE_DATASET_ITEMS)} FROM ${TABLE_DATASET_ITEMS} WHERE id = ? AND datasetVersion <= ? AND (validTo IS NULL OR validTo > ?) AND isDeleted = 0 ORDER BY datasetVersion DESC LIMIT 1`,
|
|
4139
|
+
args: [
|
|
4140
|
+
args.id,
|
|
4141
|
+
args.datasetVersion,
|
|
4142
|
+
args.datasetVersion
|
|
4143
|
+
]
|
|
4140
4144
|
});
|
|
4141
4145
|
else result = await this.#client.execute({
|
|
4142
4146
|
sql: `SELECT ${buildSelectColumns(TABLE_DATASET_ITEMS)} FROM ${TABLE_DATASET_ITEMS} WHERE id = ? AND validTo IS NULL AND isDeleted = 0`,
|
|
@@ -4600,7 +4604,8 @@ var ExperimentsLibSQL = class extends ExperimentsStorage {
|
|
|
4600
4604
|
"experimentSetId",
|
|
4601
4605
|
"comparisonId",
|
|
4602
4606
|
"variantId",
|
|
4603
|
-
"trialIndex"
|
|
4607
|
+
"trialIndex",
|
|
4608
|
+
"scorerIds"
|
|
4604
4609
|
]
|
|
4605
4610
|
});
|
|
4606
4611
|
await this.#db.alterTable({
|
|
@@ -4612,7 +4617,8 @@ var ExperimentsLibSQL = class extends ExperimentsStorage {
|
|
|
4612
4617
|
"comment",
|
|
4613
4618
|
"toolMockReport",
|
|
4614
4619
|
"organizationId",
|
|
4615
|
-
"projectId"
|
|
4620
|
+
"projectId",
|
|
4621
|
+
"attempt"
|
|
4616
4622
|
]
|
|
4617
4623
|
});
|
|
4618
4624
|
await this.#client.batch([
|
|
@@ -4629,7 +4635,11 @@ var ExperimentsLibSQL = class extends ExperimentsStorage {
|
|
|
4629
4635
|
args: []
|
|
4630
4636
|
},
|
|
4631
4637
|
{
|
|
4632
|
-
sql: `
|
|
4638
|
+
sql: `DROP INDEX IF EXISTS idx_experiment_results_exp_item`,
|
|
4639
|
+
args: []
|
|
4640
|
+
},
|
|
4641
|
+
{
|
|
4642
|
+
sql: `CREATE UNIQUE INDEX IF NOT EXISTS idx_experiment_results_exp_item_attempt ON "${TABLE_EXPERIMENT_RESULTS}" ("experimentId", "itemId", "attempt")`,
|
|
4633
4643
|
args: []
|
|
4634
4644
|
},
|
|
4635
4645
|
{
|
|
@@ -4718,8 +4728,9 @@ var ExperimentsLibSQL = class extends ExperimentsStorage {
|
|
|
4718
4728
|
agentVersion: row.agentVersion ?? null,
|
|
4719
4729
|
organizationId: row.organizationId ?? null,
|
|
4720
4730
|
projectId: row.projectId ?? null,
|
|
4721
|
-
targetType: row.targetType,
|
|
4722
|
-
targetId: row.targetId,
|
|
4731
|
+
targetType: row.targetType ?? null,
|
|
4732
|
+
targetId: row.targetId ?? null,
|
|
4733
|
+
scorerIds: row.scorerIds ? safelyParseJSON(row.scorerIds) : null,
|
|
4723
4734
|
name: row.name ?? void 0,
|
|
4724
4735
|
description: row.description ?? void 0,
|
|
4725
4736
|
metadata: row.metadata ? safelyParseJSON(row.metadata) : void 0,
|
|
@@ -4755,6 +4766,7 @@ var ExperimentsLibSQL = class extends ExperimentsStorage {
|
|
|
4755
4766
|
startedAt: ensureDate(row.startedAt),
|
|
4756
4767
|
completedAt: ensureDate(row.completedAt),
|
|
4757
4768
|
retryCount: row.retryCount,
|
|
4769
|
+
attempt: row.attempt != null ? Number(row.attempt) : 0,
|
|
4758
4770
|
traceId: row.traceId ?? null,
|
|
4759
4771
|
status: row.status ?? null,
|
|
4760
4772
|
tags: row.tags ? safelyParseJSON(row.tags) : null,
|
|
@@ -4777,8 +4789,9 @@ var ExperimentsLibSQL = class extends ExperimentsStorage {
|
|
|
4777
4789
|
agentVersion: input.agentVersion ?? null,
|
|
4778
4790
|
organizationId: input.organizationId ?? null,
|
|
4779
4791
|
projectId: input.projectId ?? null,
|
|
4780
|
-
targetType: input.targetType,
|
|
4781
|
-
targetId: input.targetId,
|
|
4792
|
+
targetType: input.targetType ?? null,
|
|
4793
|
+
targetId: input.targetId ?? null,
|
|
4794
|
+
scorerIds: input.scorerIds ?? null,
|
|
4782
4795
|
name: input.name ?? null,
|
|
4783
4796
|
description: input.description ?? null,
|
|
4784
4797
|
metadata: input.metadata ?? null,
|
|
@@ -4806,8 +4819,9 @@ var ExperimentsLibSQL = class extends ExperimentsStorage {
|
|
|
4806
4819
|
agentVersion: input.agentVersion ?? null,
|
|
4807
4820
|
organizationId: input.organizationId ?? null,
|
|
4808
4821
|
projectId: input.projectId ?? null,
|
|
4809
|
-
targetType: input.targetType,
|
|
4810
|
-
targetId: input.targetId,
|
|
4822
|
+
targetType: input.targetType ?? null,
|
|
4823
|
+
targetId: input.targetId ?? null,
|
|
4824
|
+
scorerIds: input.scorerIds ?? null,
|
|
4811
4825
|
name: input.name,
|
|
4812
4826
|
description: input.description,
|
|
4813
4827
|
metadata: input.metadata,
|
|
@@ -5054,6 +5068,7 @@ var ExperimentsLibSQL = class extends ExperimentsStorage {
|
|
|
5054
5068
|
startedAt: input.startedAt.toISOString(),
|
|
5055
5069
|
completedAt: input.completedAt.toISOString(),
|
|
5056
5070
|
retryCount: input.retryCount,
|
|
5071
|
+
attempt: input.attempt ?? 0,
|
|
5057
5072
|
traceId: input.traceId ?? null,
|
|
5058
5073
|
status: input.status ?? null,
|
|
5059
5074
|
tags: input.tags !== void 0 && input.tags !== null ? JSON.stringify(input.tags) : null,
|
|
@@ -5075,6 +5090,7 @@ var ExperimentsLibSQL = class extends ExperimentsStorage {
|
|
|
5075
5090
|
startedAt: input.startedAt,
|
|
5076
5091
|
completedAt: input.completedAt,
|
|
5077
5092
|
retryCount: input.retryCount,
|
|
5093
|
+
attempt: input.attempt ?? 0,
|
|
5078
5094
|
traceId: input.traceId ?? null,
|
|
5079
5095
|
status: input.status ?? null,
|
|
5080
5096
|
tags: input.tags ?? null,
|
|
@@ -5089,6 +5105,81 @@ var ExperimentsLibSQL = class extends ExperimentsStorage {
|
|
|
5089
5105
|
}, error);
|
|
5090
5106
|
}
|
|
5091
5107
|
}
|
|
5108
|
+
async upsertExperimentResult(input) {
|
|
5109
|
+
try {
|
|
5110
|
+
const attempt = input.attempt ?? 0;
|
|
5111
|
+
let existingId = (await this.#client.execute({
|
|
5112
|
+
sql: `SELECT "id" FROM ${TABLE_EXPERIMENT_RESULTS} WHERE "experimentId" = ? AND "itemId" = ? AND COALESCE("attempt", 0) = ?`,
|
|
5113
|
+
args: [
|
|
5114
|
+
input.experimentId,
|
|
5115
|
+
input.itemId,
|
|
5116
|
+
attempt
|
|
5117
|
+
]
|
|
5118
|
+
})).rows[0]?.id;
|
|
5119
|
+
if (!existingId) try {
|
|
5120
|
+
return await this.addExperimentResult({
|
|
5121
|
+
...input,
|
|
5122
|
+
attempt
|
|
5123
|
+
});
|
|
5124
|
+
} catch (insertError) {
|
|
5125
|
+
if (!hasErrorCode(insertError, /* @__PURE__ */ new Set([
|
|
5126
|
+
"SQLITE_CONSTRAINT",
|
|
5127
|
+
"SQLITE_CONSTRAINT_PRIMARYKEY",
|
|
5128
|
+
"SQLITE_CONSTRAINT_UNIQUE"
|
|
5129
|
+
]))) throw insertError;
|
|
5130
|
+
existingId = (await this.#client.execute({
|
|
5131
|
+
sql: `SELECT "id" FROM ${TABLE_EXPERIMENT_RESULTS} WHERE "experimentId" = ? AND "itemId" = ? AND COALESCE("attempt", 0) = ?`,
|
|
5132
|
+
args: [
|
|
5133
|
+
input.experimentId,
|
|
5134
|
+
input.itemId,
|
|
5135
|
+
attempt
|
|
5136
|
+
]
|
|
5137
|
+
})).rows[0]?.id;
|
|
5138
|
+
if (!existingId) throw insertError;
|
|
5139
|
+
}
|
|
5140
|
+
await this.#client.execute({
|
|
5141
|
+
sql: `UPDATE ${TABLE_EXPERIMENT_RESULTS} SET
|
|
5142
|
+
"itemDatasetVersion" = ?, "organizationId" = ?, "projectId" = ?,
|
|
5143
|
+
"input" = ?, "output" = ?, "groundTruth" = ?, "error" = ?,
|
|
5144
|
+
"startedAt" = ?, "completedAt" = ?, "retryCount" = ?, "attempt" = ?,
|
|
5145
|
+
"traceId" = ?, "status" = ?, "tags" = ?, "toolMockReport" = ?
|
|
5146
|
+
WHERE "id" = ?`,
|
|
5147
|
+
args: [
|
|
5148
|
+
input.itemDatasetVersion ?? null,
|
|
5149
|
+
input.organizationId ?? null,
|
|
5150
|
+
input.projectId ?? null,
|
|
5151
|
+
JSON.stringify(input.input),
|
|
5152
|
+
input.output != null ? JSON.stringify(input.output) : null,
|
|
5153
|
+
input.groundTruth != null ? JSON.stringify(input.groundTruth) : null,
|
|
5154
|
+
input.error != null ? JSON.stringify(input.error) : null,
|
|
5155
|
+
input.startedAt.toISOString(),
|
|
5156
|
+
input.completedAt.toISOString(),
|
|
5157
|
+
input.retryCount,
|
|
5158
|
+
attempt,
|
|
5159
|
+
input.traceId ?? null,
|
|
5160
|
+
input.status ?? null,
|
|
5161
|
+
input.tags != null ? JSON.stringify(input.tags) : null,
|
|
5162
|
+
input.toolMockReport != null ? JSON.stringify(input.toolMockReport) : null,
|
|
5163
|
+
existingId
|
|
5164
|
+
]
|
|
5165
|
+
});
|
|
5166
|
+
const result = await this.getExperimentResultById({ id: existingId });
|
|
5167
|
+
if (!result) throw new MastraError({
|
|
5168
|
+
id: createStorageErrorId("LIBSQL", "UPSERT_EXPERIMENT_RESULT", "NOT_FOUND"),
|
|
5169
|
+
domain: ErrorDomain.STORAGE,
|
|
5170
|
+
category: ErrorCategory.USER,
|
|
5171
|
+
details: { resultId: existingId }
|
|
5172
|
+
});
|
|
5173
|
+
return result;
|
|
5174
|
+
} catch (error) {
|
|
5175
|
+
if (error instanceof MastraError) throw error;
|
|
5176
|
+
throw new MastraError({
|
|
5177
|
+
id: createStorageErrorId("LIBSQL", "UPSERT_EXPERIMENT_RESULT", "FAILED"),
|
|
5178
|
+
domain: ErrorDomain.STORAGE,
|
|
5179
|
+
category: ErrorCategory.THIRD_PARTY
|
|
5180
|
+
}, error);
|
|
5181
|
+
}
|
|
5182
|
+
}
|
|
5092
5183
|
async updateExperimentResult(input) {
|
|
5093
5184
|
try {
|
|
5094
5185
|
const setClauses = [];
|
|
@@ -11608,8 +11699,13 @@ var ScoresLibSQL = class ScoresLibSQL extends ScoresStorage {
|
|
|
11608
11699
|
}, error);
|
|
11609
11700
|
}
|
|
11610
11701
|
try {
|
|
11611
|
-
const
|
|
11702
|
+
const suppliedId = parsedScore.id;
|
|
11703
|
+
const id = suppliedId ?? crypto.randomUUID();
|
|
11612
11704
|
const now = /* @__PURE__ */ new Date();
|
|
11705
|
+
if (suppliedId) await this.#client.execute({
|
|
11706
|
+
sql: `DELETE FROM ${TABLE_SCORERS} WHERE id = ?`,
|
|
11707
|
+
args: [suppliedId]
|
|
11708
|
+
});
|
|
11613
11709
|
await this.#db.insert({
|
|
11614
11710
|
tableName: TABLE_SCORERS,
|
|
11615
11711
|
record: {
|