@mastra/libsql 1.15.1 → 1.16.0-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/CHANGELOG.md +37 -0
- package/dist/docs/SKILL.md +4 -2
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-agent-builder-overview.md +4 -3
- package/dist/docs/references/docs-agents-agent-approval.md +25 -2
- package/dist/docs/references/docs-agents-networks.md +1 -1
- package/dist/docs/references/docs-memory-memory-processors.md +67 -0
- package/dist/docs/references/docs-memory-message-history.md +56 -2
- package/dist/docs/references/docs-memory-overview.md +8 -6
- package/dist/docs/references/docs-memory-semantic-recall.md +36 -2
- package/dist/docs/references/docs-memory-working-memory.md +3 -3
- package/dist/docs/references/docs-storage-overview.md +214 -0
- package/dist/docs/references/docs-workflows-snapshots.md +1 -1
- package/dist/docs/references/reference-core-mastra-class.md +1 -1
- package/dist/docs/references/reference-file-based-agents-memory.md +58 -0
- package/dist/docs/references/reference-file-based-agents-storage.md +30 -0
- package/dist/docs/references/reference-memory-memory-class.md +1 -1
- package/dist/docs/references/reference-storage-composite.md +64 -6
- package/dist/docs/references/reference-storage-dynamodb.md +1 -1
- package/dist/docs/references/reference-storage-retention.md +74 -6
- package/dist/index.cjs +148 -68
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +149 -69
- package/dist/index.js.map +1 -1
- package/dist/storage/db/index.d.ts +5 -0
- package/dist/storage/db/index.d.ts.map +1 -1
- package/dist/storage/domains/datasets/index.d.ts.map +1 -1
- package/dist/vector/index.d.ts +12 -0
- package/dist/vector/index.d.ts.map +1 -1
- package/package.json +10 -10
- package/dist/docs/references/docs-memory-storage.md +0 -267
package/dist/index.cjs
CHANGED
|
@@ -545,6 +545,31 @@ var LibSQLVector = class extends vector.MastraVector {
|
|
|
545
545
|
}
|
|
546
546
|
this.vectorIndexes = this.isMemoryDb ? Promise.resolve(/* @__PURE__ */ new Set()) : this.discoverVectorIndexes();
|
|
547
547
|
}
|
|
548
|
+
/**
|
|
549
|
+
* Closes the underlying libsql client, releasing all OS file handles.
|
|
550
|
+
*
|
|
551
|
+
* For local file databases, first runs PRAGMA wal_checkpoint(TRUNCATE) and
|
|
552
|
+
* switches back to journal_mode=DELETE so the -wal and -shm sidecar files
|
|
553
|
+
* are released promptly (mirrors LibSQLStore.close()).
|
|
554
|
+
*
|
|
555
|
+
* Remote (Turso) databases skip the WAL pragmas and just close the client.
|
|
556
|
+
*
|
|
557
|
+
* Safe to call more than once; subsequent calls are no-ops.
|
|
558
|
+
*/
|
|
559
|
+
async close() {
|
|
560
|
+
if (this.turso.closed) {
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
if (this.turso.protocol === "file" && !this.isMemoryDb) {
|
|
564
|
+
try {
|
|
565
|
+
await this.turso.execute("PRAGMA wal_checkpoint(TRUNCATE);");
|
|
566
|
+
await this.turso.execute("PRAGMA journal_mode=DELETE;");
|
|
567
|
+
} catch (err) {
|
|
568
|
+
this.logger.warn("LibSQLVector: Failed to checkpoint WAL before close.", err);
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
this.turso.close();
|
|
572
|
+
}
|
|
548
573
|
async discoverVectorIndexes() {
|
|
549
574
|
try {
|
|
550
575
|
const result = await this.turso.execute({
|
|
@@ -1572,6 +1597,19 @@ var LibSQLDB = class extends base.MastraBase {
|
|
|
1572
1597
|
insert(args) {
|
|
1573
1598
|
return this.executeWriteOperationWithRetry(() => this.doInsert(args), `insert into table ${args.tableName}`);
|
|
1574
1599
|
}
|
|
1600
|
+
/** Inserts a record without replacing an existing primary key. */
|
|
1601
|
+
insertOnly(args) {
|
|
1602
|
+
return this.executeWriteOperationWithRetry(async () => {
|
|
1603
|
+
const filteredRecord = await this.filterRecordToKnownColumns(args.tableName, args.record);
|
|
1604
|
+
if (Object.keys(filteredRecord).length === 0) return;
|
|
1605
|
+
const statement = prepareStatement({ tableName: args.tableName, record: filteredRecord });
|
|
1606
|
+
if (!statement.sql.startsWith("INSERT OR REPLACE")) {
|
|
1607
|
+
throw new Error(`Unexpected insert statement generated for table ${args.tableName}`);
|
|
1608
|
+
}
|
|
1609
|
+
statement.sql = statement.sql.replace("INSERT OR REPLACE", "INSERT");
|
|
1610
|
+
await withClientWriteLock(this.client, () => this.client.execute(statement));
|
|
1611
|
+
}, `insert into table ${args.tableName}`);
|
|
1612
|
+
}
|
|
1575
1613
|
/**
|
|
1576
1614
|
* Internal update implementation without retry logic.
|
|
1577
1615
|
*/
|
|
@@ -3881,6 +3919,7 @@ var DatasetsLibSQL = class extends storage.DatasetsStorage {
|
|
|
3881
3919
|
await this.#addColumnIfNotExists(storage.TABLE_DATASET_ITEMS, "organizationId", "TEXT");
|
|
3882
3920
|
await this.#addColumnIfNotExists(storage.TABLE_DATASET_ITEMS, "projectId", "TEXT");
|
|
3883
3921
|
await this.#addColumnIfNotExists(storage.TABLE_DATASET_ITEMS, "toolMocks", "TEXT");
|
|
3922
|
+
await this.#addColumnIfNotExists(storage.TABLE_DATASET_ITEMS, "externalId", "TEXT");
|
|
3884
3923
|
await this.#client.batch(
|
|
3885
3924
|
[
|
|
3886
3925
|
{
|
|
@@ -3891,6 +3930,10 @@ var DatasetsLibSQL = class extends storage.DatasetsStorage {
|
|
|
3891
3930
|
sql: `CREATE INDEX IF NOT EXISTS idx_dataset_items_dataset_version ON "${storage.TABLE_DATASET_ITEMS}" ("datasetId", "datasetVersion")`,
|
|
3892
3931
|
args: []
|
|
3893
3932
|
},
|
|
3933
|
+
{
|
|
3934
|
+
sql: `CREATE INDEX IF NOT EXISTS idx_dataset_items_dataset_externalid_version ON "${storage.TABLE_DATASET_ITEMS}" ("datasetId", "externalId", "datasetVersion")`,
|
|
3935
|
+
args: []
|
|
3936
|
+
},
|
|
3894
3937
|
{
|
|
3895
3938
|
sql: `CREATE INDEX IF NOT EXISTS idx_dataset_items_dataset_validto_deleted ON "${storage.TABLE_DATASET_ITEMS}" ("datasetId", "validTo", "isDeleted")`,
|
|
3896
3939
|
args: []
|
|
@@ -3970,6 +4013,7 @@ var DatasetsLibSQL = class extends storage.DatasetsStorage {
|
|
|
3970
4013
|
id: row.id,
|
|
3971
4014
|
datasetId: row.datasetId,
|
|
3972
4015
|
datasetVersion: row.datasetVersion,
|
|
4016
|
+
externalId: row.externalId ?? null,
|
|
3973
4017
|
organizationId: row.organizationId ?? null,
|
|
3974
4018
|
projectId: row.projectId ?? null,
|
|
3975
4019
|
input: storage.safelyParseJSON(row.input),
|
|
@@ -3988,6 +4032,7 @@ var DatasetsLibSQL = class extends storage.DatasetsStorage {
|
|
|
3988
4032
|
id: row.id,
|
|
3989
4033
|
datasetId: row.datasetId,
|
|
3990
4034
|
datasetVersion: row.datasetVersion,
|
|
4035
|
+
externalId: row.externalId ?? null,
|
|
3991
4036
|
organizationId: row.organizationId ?? null,
|
|
3992
4037
|
projectId: row.projectId ?? null,
|
|
3993
4038
|
validTo: row.validTo,
|
|
@@ -4014,10 +4059,11 @@ var DatasetsLibSQL = class extends storage.DatasetsStorage {
|
|
|
4014
4059
|
// --- Dataset CRUD ---
|
|
4015
4060
|
async createDataset(input) {
|
|
4016
4061
|
try {
|
|
4017
|
-
const id = crypto.randomUUID();
|
|
4062
|
+
const id = input.id ?? crypto.randomUUID();
|
|
4063
|
+
if (input.id !== void 0) this.validateCallerDefinedDatasetId(input.id);
|
|
4018
4064
|
const now = /* @__PURE__ */ new Date();
|
|
4019
4065
|
const nowIso = now.toISOString();
|
|
4020
|
-
await this.#db.
|
|
4066
|
+
await this.#db.insertOnly({
|
|
4021
4067
|
tableName: storage.TABLE_DATASETS,
|
|
4022
4068
|
record: {
|
|
4023
4069
|
id,
|
|
@@ -4059,6 +4105,11 @@ var DatasetsLibSQL = class extends storage.DatasetsStorage {
|
|
|
4059
4105
|
updatedAt: now
|
|
4060
4106
|
};
|
|
4061
4107
|
} catch (error$1) {
|
|
4108
|
+
if (input.id !== void 0 && storage.hasErrorCode(error$1, /* @__PURE__ */ new Set(["SQLITE_CONSTRAINT", "SQLITE_CONSTRAINT_PRIMARYKEY", "SQLITE_CONSTRAINT_UNIQUE"]))) {
|
|
4109
|
+
const existing = await this.getDatasetById({ id: input.id });
|
|
4110
|
+
if (existing) return this.resolveExistingDataset(existing, { ...input, id: input.id });
|
|
4111
|
+
}
|
|
4112
|
+
if (error$1 instanceof error.MastraError) throw error$1;
|
|
4062
4113
|
throw new error.MastraError(
|
|
4063
4114
|
{
|
|
4064
4115
|
id: storage.createStorageErrorId("LIBSQL", "CREATE_DATASET", "FAILED"),
|
|
@@ -4304,11 +4355,12 @@ var DatasetsLibSQL = class extends storage.DatasetsStorage {
|
|
|
4304
4355
|
args: [args.datasetId]
|
|
4305
4356
|
},
|
|
4306
4357
|
{
|
|
4307
|
-
sql: `INSERT INTO ${storage.TABLE_DATASET_ITEMS} (id, datasetId, datasetVersion, organizationId, projectId, validTo, isDeleted, input, groundTruth, expectedTrajectory, toolMocks, requestContext, metadata, source, createdAt, updatedAt) VALUES (?, ?, (SELECT version FROM ${storage.TABLE_DATASETS} WHERE id = ?), (SELECT organizationId FROM ${storage.TABLE_DATASETS} WHERE id = ?), (SELECT projectId FROM ${storage.TABLE_DATASETS} WHERE id = ?), NULL, 0, jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), ?, ?)`,
|
|
4358
|
+
sql: `INSERT INTO ${storage.TABLE_DATASET_ITEMS} (id, datasetId, datasetVersion, externalId, organizationId, projectId, validTo, isDeleted, input, groundTruth, expectedTrajectory, toolMocks, requestContext, metadata, source, createdAt, updatedAt) VALUES (?, ?, (SELECT version FROM ${storage.TABLE_DATASETS} WHERE id = ?), ?, (SELECT organizationId FROM ${storage.TABLE_DATASETS} WHERE id = ?), (SELECT projectId FROM ${storage.TABLE_DATASETS} WHERE id = ?), NULL, 0, jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), ?, ?)`,
|
|
4308
4359
|
args: [
|
|
4309
4360
|
id,
|
|
4310
4361
|
args.datasetId,
|
|
4311
4362
|
args.datasetId,
|
|
4363
|
+
args.externalId ?? null,
|
|
4312
4364
|
args.datasetId,
|
|
4313
4365
|
args.datasetId,
|
|
4314
4366
|
jsonbArg(args.input),
|
|
@@ -4334,6 +4386,7 @@ var DatasetsLibSQL = class extends storage.DatasetsStorage {
|
|
|
4334
4386
|
id,
|
|
4335
4387
|
datasetId: args.datasetId,
|
|
4336
4388
|
datasetVersion: newVersion,
|
|
4389
|
+
externalId: args.externalId ?? null,
|
|
4337
4390
|
organizationId: dataset?.organizationId ?? null,
|
|
4338
4391
|
projectId: dataset?.projectId ?? null,
|
|
4339
4392
|
input: args.input,
|
|
@@ -4399,11 +4452,12 @@ var DatasetsLibSQL = class extends storage.DatasetsStorage {
|
|
|
4399
4452
|
args: [args.datasetId, args.id]
|
|
4400
4453
|
},
|
|
4401
4454
|
{
|
|
4402
|
-
sql: `INSERT INTO ${storage.TABLE_DATASET_ITEMS} (id, datasetId, datasetVersion, organizationId, projectId, validTo, isDeleted, input, groundTruth, expectedTrajectory, toolMocks, requestContext, metadata, source, createdAt, updatedAt) VALUES (?, ?, (SELECT version FROM ${storage.TABLE_DATASETS} WHERE id = ?), (SELECT organizationId FROM ${storage.TABLE_DATASETS} WHERE id = ?), (SELECT projectId FROM ${storage.TABLE_DATASETS} WHERE id = ?), NULL, 0, jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), ?, ?)`,
|
|
4455
|
+
sql: `INSERT INTO ${storage.TABLE_DATASET_ITEMS} (id, datasetId, datasetVersion, externalId, organizationId, projectId, validTo, isDeleted, input, groundTruth, expectedTrajectory, toolMocks, requestContext, metadata, source, createdAt, updatedAt) VALUES (?, ?, (SELECT version FROM ${storage.TABLE_DATASETS} WHERE id = ?), ?, (SELECT organizationId FROM ${storage.TABLE_DATASETS} WHERE id = ?), (SELECT projectId FROM ${storage.TABLE_DATASETS} WHERE id = ?), NULL, 0, jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), ?, ?)`,
|
|
4403
4456
|
args: [
|
|
4404
4457
|
args.id,
|
|
4405
4458
|
args.datasetId,
|
|
4406
4459
|
args.datasetId,
|
|
4460
|
+
existing.externalId ?? null,
|
|
4407
4461
|
args.datasetId,
|
|
4408
4462
|
args.datasetId,
|
|
4409
4463
|
jsonbArg(mergedInput),
|
|
@@ -4476,11 +4530,12 @@ var DatasetsLibSQL = class extends storage.DatasetsStorage {
|
|
|
4476
4530
|
args: [datasetId, id]
|
|
4477
4531
|
},
|
|
4478
4532
|
{
|
|
4479
|
-
sql: `INSERT INTO ${storage.TABLE_DATASET_ITEMS} (id, datasetId, datasetVersion, organizationId, projectId, validTo, isDeleted, input, groundTruth, expectedTrajectory, toolMocks, requestContext, metadata, source, createdAt, updatedAt) VALUES (?, ?, (SELECT version FROM ${storage.TABLE_DATASETS} WHERE id = ?), (SELECT organizationId FROM ${storage.TABLE_DATASETS} WHERE id = ?), (SELECT projectId FROM ${storage.TABLE_DATASETS} WHERE id = ?), NULL, 1, jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), ?, ?)`,
|
|
4533
|
+
sql: `INSERT INTO ${storage.TABLE_DATASET_ITEMS} (id, datasetId, datasetVersion, externalId, organizationId, projectId, validTo, isDeleted, input, groundTruth, expectedTrajectory, toolMocks, requestContext, metadata, source, createdAt, updatedAt) VALUES (?, ?, (SELECT version FROM ${storage.TABLE_DATASETS} WHERE id = ?), ?, (SELECT organizationId FROM ${storage.TABLE_DATASETS} WHERE id = ?), (SELECT projectId FROM ${storage.TABLE_DATASETS} WHERE id = ?), NULL, 1, jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), ?, ?)`,
|
|
4480
4534
|
args: [
|
|
4481
4535
|
id,
|
|
4482
4536
|
datasetId,
|
|
4483
4537
|
datasetId,
|
|
4538
|
+
existing.externalId ?? null,
|
|
4484
4539
|
datasetId,
|
|
4485
4540
|
datasetId,
|
|
4486
4541
|
jsonbArg(existing.input),
|
|
@@ -4762,70 +4817,94 @@ var DatasetsLibSQL = class extends storage.DatasetsStorage {
|
|
|
4762
4817
|
// --- Bulk operations (SCD-2 internally) ---
|
|
4763
4818
|
async _doBatchInsertItems(input) {
|
|
4764
4819
|
try {
|
|
4765
|
-
|
|
4766
|
-
|
|
4767
|
-
|
|
4768
|
-
|
|
4769
|
-
|
|
4770
|
-
|
|
4771
|
-
|
|
4772
|
-
|
|
4773
|
-
|
|
4774
|
-
|
|
4775
|
-
|
|
4776
|
-
|
|
4777
|
-
|
|
4778
|
-
|
|
4779
|
-
|
|
4780
|
-
|
|
4820
|
+
if (input.items.length === 0) return [];
|
|
4821
|
+
return await withClientWriteLock(this.#client, async () => {
|
|
4822
|
+
const tx = await this.#client.transaction("write");
|
|
4823
|
+
try {
|
|
4824
|
+
const datasetResult = await tx.execute({
|
|
4825
|
+
sql: `SELECT version, organizationId, projectId FROM ${storage.TABLE_DATASETS} WHERE id = ?`,
|
|
4826
|
+
args: [input.datasetId]
|
|
4827
|
+
});
|
|
4828
|
+
const dataset = datasetResult.rows[0];
|
|
4829
|
+
if (!dataset)
|
|
4830
|
+
throw new error.MastraError({
|
|
4831
|
+
id: storage.createStorageErrorId("LIBSQL", "BULK_ADD_ITEMS", "DATASET_NOT_FOUND"),
|
|
4832
|
+
domain: error.ErrorDomain.STORAGE,
|
|
4833
|
+
category: error.ErrorCategory.USER,
|
|
4834
|
+
details: { datasetId: input.datasetId }
|
|
4835
|
+
});
|
|
4836
|
+
const externalIds = [...new Set(input.items.flatMap((item) => item.externalId ? [item.externalId] : []))];
|
|
4837
|
+
const historyResult = externalIds.length ? await tx.execute({
|
|
4838
|
+
sql: `SELECT id, datasetId, datasetVersion, externalId, organizationId, projectId, validTo, isDeleted, json(input) AS input, json(groundTruth) AS groundTruth, json(expectedTrajectory) AS expectedTrajectory, json(toolMocks) AS toolMocks, json(requestContext) AS requestContext, json(metadata) AS metadata, json(source) AS source, createdAt, updatedAt FROM ${storage.TABLE_DATASET_ITEMS} WHERE datasetId = ? AND externalId IN (${externalIds.map(() => "?").join(",")}) ORDER BY datasetVersion`,
|
|
4839
|
+
args: [input.datasetId, ...externalIds]
|
|
4840
|
+
}) : { rows: [] };
|
|
4841
|
+
const plan = this.planDatasetItemBatch(
|
|
4842
|
+
input.items,
|
|
4843
|
+
historyResult.rows.map((row) => this.transformItemRowFull(row)),
|
|
4844
|
+
() => crypto.randomUUID()
|
|
4845
|
+
);
|
|
4846
|
+
const resolved = new Map(
|
|
4847
|
+
[...plan.existingCurrentItems].map(([id, row]) => [id, this.datasetItemFromRow(row)])
|
|
4848
|
+
);
|
|
4849
|
+
if (plan.inserts.length > 0) {
|
|
4850
|
+
const newVersion = Number(dataset.version) + 1;
|
|
4851
|
+
const now = /* @__PURE__ */ new Date();
|
|
4852
|
+
const nowIso = now.toISOString();
|
|
4853
|
+
await tx.execute({
|
|
4854
|
+
sql: `UPDATE ${storage.TABLE_DATASETS} SET version = ? WHERE id = ?`,
|
|
4855
|
+
args: [newVersion, input.datasetId]
|
|
4856
|
+
});
|
|
4857
|
+
for (const { id, item } of plan.inserts) {
|
|
4858
|
+
await tx.execute({
|
|
4859
|
+
sql: `INSERT INTO ${storage.TABLE_DATASET_ITEMS} (id, datasetId, datasetVersion, externalId, organizationId, projectId, validTo, isDeleted, input, groundTruth, expectedTrajectory, toolMocks, requestContext, metadata, source, createdAt, updatedAt) VALUES (?, ?, ?, ?, ?, ?, NULL, 0, jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), ?, ?)`,
|
|
4860
|
+
args: [
|
|
4861
|
+
id,
|
|
4862
|
+
input.datasetId,
|
|
4863
|
+
newVersion,
|
|
4864
|
+
item.externalId ?? null,
|
|
4865
|
+
dataset.organizationId ?? null,
|
|
4866
|
+
dataset.projectId ?? null,
|
|
4867
|
+
jsonbArg(item.input),
|
|
4868
|
+
jsonbArg(item.groundTruth),
|
|
4869
|
+
jsonbArg(item.expectedTrajectory),
|
|
4870
|
+
jsonbArg(item.toolMocks),
|
|
4871
|
+
jsonbArg(item.requestContext),
|
|
4872
|
+
jsonbArg(item.metadata),
|
|
4873
|
+
jsonbArg(item.source),
|
|
4874
|
+
nowIso,
|
|
4875
|
+
nowIso
|
|
4876
|
+
]
|
|
4877
|
+
});
|
|
4878
|
+
resolved.set(id, {
|
|
4879
|
+
id,
|
|
4880
|
+
datasetId: input.datasetId,
|
|
4881
|
+
datasetVersion: newVersion,
|
|
4882
|
+
externalId: item.externalId ?? null,
|
|
4883
|
+
organizationId: dataset.organizationId,
|
|
4884
|
+
projectId: dataset.projectId,
|
|
4885
|
+
input: item.input,
|
|
4886
|
+
groundTruth: item.groundTruth,
|
|
4887
|
+
expectedTrajectory: item.expectedTrajectory,
|
|
4888
|
+
toolMocks: item.toolMocks,
|
|
4889
|
+
requestContext: item.requestContext,
|
|
4890
|
+
metadata: item.metadata,
|
|
4891
|
+
source: item.source,
|
|
4892
|
+
createdAt: now,
|
|
4893
|
+
updatedAt: now
|
|
4894
|
+
});
|
|
4895
|
+
}
|
|
4896
|
+
await tx.execute({
|
|
4897
|
+
sql: `INSERT INTO ${storage.TABLE_DATASET_VERSIONS} (id, datasetId, version, createdAt) VALUES (?, ?, ?, ?)`,
|
|
4898
|
+
args: [crypto.randomUUID(), input.datasetId, newVersion, nowIso]
|
|
4899
|
+
});
|
|
4900
|
+
}
|
|
4901
|
+
await tx.commit();
|
|
4902
|
+
return plan.resolvedIds.map((id) => resolved.get(id));
|
|
4903
|
+
} catch (error) {
|
|
4904
|
+
if (!tx.closed) await tx.rollback();
|
|
4905
|
+
throw error;
|
|
4781
4906
|
}
|
|
4782
|
-
];
|
|
4783
|
-
const items = [];
|
|
4784
|
-
for (const itemInput of input.items) {
|
|
4785
|
-
const id = crypto.randomUUID();
|
|
4786
|
-
items.push({ id, input: itemInput });
|
|
4787
|
-
statements.push({
|
|
4788
|
-
sql: `INSERT INTO ${storage.TABLE_DATASET_ITEMS} (id, datasetId, datasetVersion, organizationId, projectId, validTo, isDeleted, input, groundTruth, expectedTrajectory, toolMocks, requestContext, metadata, source, createdAt, updatedAt) VALUES (?, ?, (SELECT version FROM ${storage.TABLE_DATASETS} WHERE id = ?), ?, ?, NULL, 0, jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), ?, ?)`,
|
|
4789
|
-
args: [
|
|
4790
|
-
id,
|
|
4791
|
-
input.datasetId,
|
|
4792
|
-
input.datasetId,
|
|
4793
|
-
dataset.organizationId ?? null,
|
|
4794
|
-
dataset.projectId ?? null,
|
|
4795
|
-
jsonbArg(itemInput.input),
|
|
4796
|
-
jsonbArg(itemInput.groundTruth),
|
|
4797
|
-
jsonbArg(itemInput.expectedTrajectory),
|
|
4798
|
-
jsonbArg(itemInput.toolMocks),
|
|
4799
|
-
jsonbArg(itemInput.requestContext),
|
|
4800
|
-
jsonbArg(itemInput.metadata),
|
|
4801
|
-
jsonbArg(itemInput.source),
|
|
4802
|
-
nowIso,
|
|
4803
|
-
nowIso
|
|
4804
|
-
]
|
|
4805
|
-
});
|
|
4806
|
-
}
|
|
4807
|
-
statements.push({
|
|
4808
|
-
sql: `INSERT INTO ${storage.TABLE_DATASET_VERSIONS} (id, datasetId, version, createdAt) VALUES (?, ?, (SELECT version FROM ${storage.TABLE_DATASETS} WHERE id = ?), ?)`,
|
|
4809
|
-
args: [versionId, input.datasetId, input.datasetId, nowIso]
|
|
4810
4907
|
});
|
|
4811
|
-
const results = await this.#client.batch(statements, "write");
|
|
4812
|
-
const newVersion = Number(results[0].rows[0].version);
|
|
4813
|
-
return items.map(({ id, input: itemInput }) => ({
|
|
4814
|
-
id,
|
|
4815
|
-
datasetId: input.datasetId,
|
|
4816
|
-
datasetVersion: newVersion,
|
|
4817
|
-
organizationId: dataset.organizationId ?? null,
|
|
4818
|
-
projectId: dataset.projectId ?? null,
|
|
4819
|
-
input: itemInput.input,
|
|
4820
|
-
groundTruth: itemInput.groundTruth,
|
|
4821
|
-
expectedTrajectory: itemInput.expectedTrajectory,
|
|
4822
|
-
toolMocks: itemInput.toolMocks,
|
|
4823
|
-
requestContext: itemInput.requestContext,
|
|
4824
|
-
metadata: itemInput.metadata,
|
|
4825
|
-
source: itemInput.source,
|
|
4826
|
-
createdAt: now,
|
|
4827
|
-
updatedAt: now
|
|
4828
|
-
}));
|
|
4829
4908
|
} catch (error$1) {
|
|
4830
4909
|
if (error$1 instanceof error.MastraError) throw error$1;
|
|
4831
4910
|
throw new error.MastraError(
|
|
@@ -4871,11 +4950,12 @@ var DatasetsLibSQL = class extends storage.DatasetsStorage {
|
|
|
4871
4950
|
args: [input.datasetId, item.id]
|
|
4872
4951
|
});
|
|
4873
4952
|
statements.push({
|
|
4874
|
-
sql: `INSERT INTO ${storage.TABLE_DATASET_ITEMS} (id, datasetId, datasetVersion, organizationId, projectId, validTo, isDeleted, input, groundTruth, expectedTrajectory, toolMocks, requestContext, metadata, source, createdAt, updatedAt) VALUES (?, ?, (SELECT version FROM ${storage.TABLE_DATASETS} WHERE id = ?), ?, ?, NULL, 1, jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), ?, ?)`,
|
|
4953
|
+
sql: `INSERT INTO ${storage.TABLE_DATASET_ITEMS} (id, datasetId, datasetVersion, externalId, organizationId, projectId, validTo, isDeleted, input, groundTruth, expectedTrajectory, toolMocks, requestContext, metadata, source, createdAt, updatedAt) VALUES (?, ?, (SELECT version FROM ${storage.TABLE_DATASETS} WHERE id = ?), ?, ?, ?, NULL, 1, jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), ?, ?)`,
|
|
4875
4954
|
args: [
|
|
4876
4955
|
item.id,
|
|
4877
4956
|
input.datasetId,
|
|
4878
4957
|
input.datasetId,
|
|
4958
|
+
item.externalId ?? null,
|
|
4879
4959
|
dataset.organizationId ?? null,
|
|
4880
4960
|
dataset.projectId ?? null,
|
|
4881
4961
|
jsonbArg(item.input),
|