@mastra/libsql 1.14.1-alpha.0 → 1.14.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/index.js CHANGED
@@ -3620,9 +3620,15 @@ var DatasetsLibSQL = class extends DatasetsStorage {
3620
3620
  await this.#addColumnIfNotExists(TABLE_DATASETS, "targetType", "TEXT");
3621
3621
  await this.#addColumnIfNotExists(TABLE_DATASETS, "targetIds", "TEXT");
3622
3622
  await this.#addColumnIfNotExists(TABLE_DATASETS, "scorerIds", "TEXT");
3623
+ await this.#addColumnIfNotExists(TABLE_DATASETS, "organizationId", "TEXT");
3624
+ await this.#addColumnIfNotExists(TABLE_DATASETS, "projectId", "TEXT");
3625
+ await this.#addColumnIfNotExists(TABLE_DATASETS, "candidateKey", "TEXT");
3626
+ await this.#addColumnIfNotExists(TABLE_DATASETS, "candidateId", "TEXT");
3623
3627
  await this.#addColumnIfNotExists(TABLE_DATASET_ITEMS, "requestContext", "TEXT");
3624
3628
  await this.#addColumnIfNotExists(TABLE_DATASET_ITEMS, "source", "TEXT");
3625
3629
  await this.#addColumnIfNotExists(TABLE_DATASET_ITEMS, "expectedTrajectory", "TEXT");
3630
+ await this.#addColumnIfNotExists(TABLE_DATASET_ITEMS, "organizationId", "TEXT");
3631
+ await this.#addColumnIfNotExists(TABLE_DATASET_ITEMS, "projectId", "TEXT");
3626
3632
  await this.#addColumnIfNotExists(TABLE_DATASET_ITEMS, "toolMocks", "TEXT");
3627
3633
  await this.#client.batch(
3628
3634
  [
@@ -3645,6 +3651,18 @@ var DatasetsLibSQL = class extends DatasetsStorage {
3645
3651
  {
3646
3652
  sql: `CREATE UNIQUE INDEX IF NOT EXISTS idx_dataset_versions_dataset_version_unique ON "${TABLE_DATASET_VERSIONS}" ("datasetId", "version")`,
3647
3653
  args: []
3654
+ },
3655
+ {
3656
+ sql: `CREATE INDEX IF NOT EXISTS idx_datasets_tenancy_createdat ON "${TABLE_DATASETS}" ("organizationId", "projectId", "createdAt", "id")`,
3657
+ args: []
3658
+ },
3659
+ {
3660
+ sql: `CREATE INDEX IF NOT EXISTS idx_datasets_tenancy_candidate ON "${TABLE_DATASETS}" ("organizationId", "projectId", "candidateKey", "candidateId")`,
3661
+ args: []
3662
+ },
3663
+ {
3664
+ sql: `CREATE INDEX IF NOT EXISTS idx_dataset_items_tenancy_list ON "${TABLE_DATASET_ITEMS}" ("organizationId", "projectId", "datasetId", "validTo", "isDeleted")`,
3665
+ args: []
3648
3666
  }
3649
3667
  ],
3650
3668
  "write"
@@ -3676,6 +3694,10 @@ var DatasetsLibSQL = class extends DatasetsStorage {
3676
3694
  targetIds: row.targetIds ? safelyParseJSON(row.targetIds) : void 0,
3677
3695
  scorerIds: row.scorerIds ? safelyParseJSON(row.scorerIds) : void 0,
3678
3696
  version: row.version,
3697
+ organizationId: row.organizationId ?? null,
3698
+ projectId: row.projectId ?? null,
3699
+ candidateKey: row.candidateKey ?? null,
3700
+ candidateId: row.candidateId ?? null,
3679
3701
  createdAt: ensureDate(row.createdAt),
3680
3702
  updatedAt: ensureDate(row.updatedAt)
3681
3703
  };
@@ -3685,6 +3707,8 @@ var DatasetsLibSQL = class extends DatasetsStorage {
3685
3707
  id: row.id,
3686
3708
  datasetId: row.datasetId,
3687
3709
  datasetVersion: row.datasetVersion,
3710
+ organizationId: row.organizationId ?? null,
3711
+ projectId: row.projectId ?? null,
3688
3712
  input: safelyParseJSON(row.input),
3689
3713
  groundTruth: row.groundTruth ? safelyParseJSON(row.groundTruth) : void 0,
3690
3714
  expectedTrajectory: row.expectedTrajectory ? safelyParseJSON(row.expectedTrajectory) : void 0,
@@ -3701,6 +3725,8 @@ var DatasetsLibSQL = class extends DatasetsStorage {
3701
3725
  id: row.id,
3702
3726
  datasetId: row.datasetId,
3703
3727
  datasetVersion: row.datasetVersion,
3728
+ organizationId: row.organizationId ?? null,
3729
+ projectId: row.projectId ?? null,
3704
3730
  validTo: row.validTo,
3705
3731
  isDeleted: Boolean(row.isDeleted),
3706
3732
  input: safelyParseJSON(row.input),
@@ -3742,6 +3768,10 @@ var DatasetsLibSQL = class extends DatasetsStorage {
3742
3768
  targetIds: input.targetIds ? JSON.stringify(input.targetIds) : null,
3743
3769
  scorerIds: input.scorerIds ? JSON.stringify(input.scorerIds) : null,
3744
3770
  version: 0,
3771
+ organizationId: input.organizationId ?? null,
3772
+ projectId: input.projectId ?? null,
3773
+ candidateKey: input.candidateKey ?? null,
3774
+ candidateId: input.candidateId ?? null,
3745
3775
  createdAt: nowIso,
3746
3776
  updatedAt: nowIso
3747
3777
  }
@@ -3758,6 +3788,10 @@ var DatasetsLibSQL = class extends DatasetsStorage {
3758
3788
  targetIds: input.targetIds ?? void 0,
3759
3789
  scorerIds: input.scorerIds ?? void 0,
3760
3790
  version: 0,
3791
+ organizationId: input.organizationId ?? null,
3792
+ projectId: input.projectId ?? null,
3793
+ candidateKey: input.candidateKey ?? null,
3794
+ candidateId: input.candidateId ?? null,
3761
3795
  createdAt: now,
3762
3796
  updatedAt: now
3763
3797
  };
@@ -3913,9 +3947,28 @@ var DatasetsLibSQL = class extends DatasetsStorage {
3913
3947
  async listDatasets(args) {
3914
3948
  try {
3915
3949
  const { page, perPage: perPageInput } = args.pagination;
3950
+ const filterConditions = [];
3951
+ const filterParams = [];
3952
+ if (args.filters?.organizationId !== void 0) {
3953
+ filterConditions.push("organizationId = ?");
3954
+ filterParams.push(args.filters.organizationId);
3955
+ }
3956
+ if (args.filters?.projectId !== void 0) {
3957
+ filterConditions.push("projectId = ?");
3958
+ filterParams.push(args.filters.projectId);
3959
+ }
3960
+ if (args.filters?.candidateKey !== void 0) {
3961
+ filterConditions.push("candidateKey = ?");
3962
+ filterParams.push(args.filters.candidateKey);
3963
+ }
3964
+ if (args.filters?.candidateId !== void 0) {
3965
+ filterConditions.push("candidateId = ?");
3966
+ filterParams.push(args.filters.candidateId);
3967
+ }
3968
+ const whereClause = filterConditions.length > 0 ? `WHERE ${filterConditions.join(" AND ")}` : "";
3916
3969
  const countResult = await this.#client.execute({
3917
- sql: `SELECT COUNT(*) as count FROM ${TABLE_DATASETS}`,
3918
- args: []
3970
+ sql: `SELECT COUNT(*) as count FROM ${TABLE_DATASETS} ${whereClause}`,
3971
+ args: filterParams
3919
3972
  });
3920
3973
  const total = Number(countResult.rows?.[0]?.count ?? 0);
3921
3974
  if (total === 0) {
@@ -3929,8 +3982,8 @@ var DatasetsLibSQL = class extends DatasetsStorage {
3929
3982
  const limitValue = perPageInput === false ? total : perPage;
3930
3983
  const end = perPageInput === false ? total : start + perPage;
3931
3984
  const result = await this.#client.execute({
3932
- sql: `SELECT ${buildSelectColumns(TABLE_DATASETS)} FROM ${TABLE_DATASETS} ORDER BY createdAt DESC, id ASC LIMIT ? OFFSET ?`,
3933
- args: [limitValue, start]
3985
+ sql: `SELECT ${buildSelectColumns(TABLE_DATASETS)} FROM ${TABLE_DATASETS} ${whereClause} ORDER BY createdAt DESC, id ASC LIMIT ? OFFSET ?`,
3986
+ args: [...filterParams, limitValue, start]
3934
3987
  });
3935
3988
  return {
3936
3989
  datasets: result.rows?.map((row) => this.transformDatasetRow(row)) ?? [],
@@ -3955,6 +4008,7 @@ var DatasetsLibSQL = class extends DatasetsStorage {
3955
4008
  // --- SCD-2 item mutations ---
3956
4009
  async _doAddItem(args) {
3957
4010
  try {
4011
+ const dataset = await this.getDatasetById({ id: args.datasetId });
3958
4012
  const id = crypto.randomUUID();
3959
4013
  const versionId = crypto.randomUUID();
3960
4014
  const now = /* @__PURE__ */ new Date();
@@ -3966,11 +4020,13 @@ var DatasetsLibSQL = class extends DatasetsStorage {
3966
4020
  args: [args.datasetId]
3967
4021
  },
3968
4022
  {
3969
- sql: `INSERT INTO ${TABLE_DATASET_ITEMS} (id, datasetId, datasetVersion, validTo, isDeleted, input, groundTruth, expectedTrajectory, toolMocks, requestContext, metadata, source, createdAt, updatedAt) VALUES (?, ?, (SELECT version FROM ${TABLE_DATASETS} WHERE id = ?), NULL, 0, jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), ?, ?)`,
4023
+ sql: `INSERT INTO ${TABLE_DATASET_ITEMS} (id, datasetId, datasetVersion, organizationId, projectId, validTo, isDeleted, input, groundTruth, expectedTrajectory, toolMocks, requestContext, metadata, source, createdAt, updatedAt) VALUES (?, ?, (SELECT version FROM ${TABLE_DATASETS} WHERE id = ?), (SELECT organizationId FROM ${TABLE_DATASETS} WHERE id = ?), (SELECT projectId FROM ${TABLE_DATASETS} WHERE id = ?), NULL, 0, jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), ?, ?)`,
3970
4024
  args: [
3971
4025
  id,
3972
4026
  args.datasetId,
3973
4027
  args.datasetId,
4028
+ args.datasetId,
4029
+ args.datasetId,
3974
4030
  jsonbArg(args.input),
3975
4031
  jsonbArg(args.groundTruth),
3976
4032
  jsonbArg(args.expectedTrajectory),
@@ -3994,6 +4050,8 @@ var DatasetsLibSQL = class extends DatasetsStorage {
3994
4050
  id,
3995
4051
  datasetId: args.datasetId,
3996
4052
  datasetVersion: newVersion,
4053
+ organizationId: dataset?.organizationId ?? null,
4054
+ projectId: dataset?.projectId ?? null,
3997
4055
  input: args.input,
3998
4056
  groundTruth: args.groundTruth,
3999
4057
  expectedTrajectory: args.expectedTrajectory,
@@ -4035,6 +4093,7 @@ var DatasetsLibSQL = class extends DatasetsStorage {
4035
4093
  details: { itemId: args.id, expectedDatasetId: args.datasetId, actualDatasetId: existing.datasetId }
4036
4094
  });
4037
4095
  }
4096
+ const dataset = await this.getDatasetById({ id: args.datasetId });
4038
4097
  const versionId = crypto.randomUUID();
4039
4098
  const now = /* @__PURE__ */ new Date();
4040
4099
  const nowIso = now.toISOString();
@@ -4056,11 +4115,13 @@ var DatasetsLibSQL = class extends DatasetsStorage {
4056
4115
  args: [args.datasetId, args.id]
4057
4116
  },
4058
4117
  {
4059
- sql: `INSERT INTO ${TABLE_DATASET_ITEMS} (id, datasetId, datasetVersion, validTo, isDeleted, input, groundTruth, expectedTrajectory, toolMocks, requestContext, metadata, source, createdAt, updatedAt) VALUES (?, ?, (SELECT version FROM ${TABLE_DATASETS} WHERE id = ?), NULL, 0, jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), ?, ?)`,
4118
+ sql: `INSERT INTO ${TABLE_DATASET_ITEMS} (id, datasetId, datasetVersion, organizationId, projectId, validTo, isDeleted, input, groundTruth, expectedTrajectory, toolMocks, requestContext, metadata, source, createdAt, updatedAt) VALUES (?, ?, (SELECT version FROM ${TABLE_DATASETS} WHERE id = ?), (SELECT organizationId FROM ${TABLE_DATASETS} WHERE id = ?), (SELECT projectId FROM ${TABLE_DATASETS} WHERE id = ?), NULL, 0, jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), ?, ?)`,
4060
4119
  args: [
4061
4120
  args.id,
4062
4121
  args.datasetId,
4063
4122
  args.datasetId,
4123
+ args.datasetId,
4124
+ args.datasetId,
4064
4125
  jsonbArg(mergedInput),
4065
4126
  jsonbArg(mergedGroundTruth),
4066
4127
  jsonbArg(mergedExpectedTrajectory),
@@ -4083,6 +4144,8 @@ var DatasetsLibSQL = class extends DatasetsStorage {
4083
4144
  return {
4084
4145
  ...existing,
4085
4146
  datasetVersion: newVersion,
4147
+ organizationId: dataset?.organizationId ?? null,
4148
+ projectId: dataset?.projectId ?? null,
4086
4149
  input: mergedInput,
4087
4150
  groundTruth: mergedGroundTruth,
4088
4151
  expectedTrajectory: mergedExpectedTrajectory,
@@ -4129,13 +4192,17 @@ var DatasetsLibSQL = class extends DatasetsStorage {
4129
4192
  args: [datasetId, id]
4130
4193
  },
4131
4194
  {
4132
- sql: `INSERT INTO ${TABLE_DATASET_ITEMS} (id, datasetId, datasetVersion, validTo, isDeleted, input, groundTruth, requestContext, metadata, source, createdAt, updatedAt) VALUES (?, ?, (SELECT version FROM ${TABLE_DATASETS} WHERE id = ?), NULL, 1, jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), ?, ?)`,
4195
+ sql: `INSERT INTO ${TABLE_DATASET_ITEMS} (id, datasetId, datasetVersion, organizationId, projectId, validTo, isDeleted, input, groundTruth, expectedTrajectory, toolMocks, requestContext, metadata, source, createdAt, updatedAt) VALUES (?, ?, (SELECT version FROM ${TABLE_DATASETS} WHERE id = ?), (SELECT organizationId FROM ${TABLE_DATASETS} WHERE id = ?), (SELECT projectId FROM ${TABLE_DATASETS} WHERE id = ?), NULL, 1, jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), ?, ?)`,
4133
4196
  args: [
4134
4197
  id,
4135
4198
  datasetId,
4136
4199
  datasetId,
4200
+ datasetId,
4201
+ datasetId,
4137
4202
  jsonbArg(existing.input),
4138
4203
  jsonbArg(existing.groundTruth),
4204
+ jsonbArg(existing.expectedTrajectory),
4205
+ jsonbArg(existing.toolMocks),
4139
4206
  jsonbArg(existing.requestContext),
4140
4207
  jsonbArg(existing.metadata),
4141
4208
  jsonbArg(existing.source),
@@ -4236,6 +4303,14 @@ var DatasetsLibSQL = class extends DatasetsStorage {
4236
4303
  "isDeleted = 0"
4237
4304
  ];
4238
4305
  const queryParams2 = [args.datasetId, args.version, args.version];
4306
+ if (args.filters?.organizationId !== void 0) {
4307
+ conditions2.push("organizationId = ?");
4308
+ queryParams2.push(args.filters.organizationId);
4309
+ }
4310
+ if (args.filters?.projectId !== void 0) {
4311
+ conditions2.push("projectId = ?");
4312
+ queryParams2.push(args.filters.projectId);
4313
+ }
4239
4314
  if (args.search) {
4240
4315
  conditions2.push(`(LOWER(json(input)) LIKE ? OR LOWER(COALESCE(json(groundTruth), '')) LIKE ?)`);
4241
4316
  const searchPattern = `%${args.search.toLowerCase()}%`;
@@ -4273,6 +4348,14 @@ var DatasetsLibSQL = class extends DatasetsStorage {
4273
4348
  }
4274
4349
  const conditions = ["datasetId = ?", "validTo IS NULL", "isDeleted = 0"];
4275
4350
  const queryParams = [args.datasetId];
4351
+ if (args.filters?.organizationId !== void 0) {
4352
+ conditions.push("organizationId = ?");
4353
+ queryParams.push(args.filters.organizationId);
4354
+ }
4355
+ if (args.filters?.projectId !== void 0) {
4356
+ conditions.push("projectId = ?");
4357
+ queryParams.push(args.filters.projectId);
4358
+ }
4276
4359
  if (args.search) {
4277
4360
  conditions.push(`(LOWER(json(input)) LIKE ? OR LOWER(COALESCE(json(groundTruth), '')) LIKE ?)`);
4278
4361
  const searchPattern = `%${args.search.toLowerCase()}%`;
@@ -4418,11 +4501,13 @@ var DatasetsLibSQL = class extends DatasetsStorage {
4418
4501
  const id = crypto.randomUUID();
4419
4502
  items.push({ id, input: itemInput });
4420
4503
  statements.push({
4421
- sql: `INSERT INTO ${TABLE_DATASET_ITEMS} (id, datasetId, datasetVersion, validTo, isDeleted, input, groundTruth, expectedTrajectory, toolMocks, requestContext, metadata, source, createdAt, updatedAt) VALUES (?, ?, (SELECT version FROM ${TABLE_DATASETS} WHERE id = ?), NULL, 0, jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), ?, ?)`,
4504
+ sql: `INSERT INTO ${TABLE_DATASET_ITEMS} (id, datasetId, datasetVersion, organizationId, projectId, validTo, isDeleted, input, groundTruth, expectedTrajectory, toolMocks, requestContext, metadata, source, createdAt, updatedAt) VALUES (?, ?, (SELECT version FROM ${TABLE_DATASETS} WHERE id = ?), ?, ?, NULL, 0, jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), ?, ?)`,
4422
4505
  args: [
4423
4506
  id,
4424
4507
  input.datasetId,
4425
4508
  input.datasetId,
4509
+ dataset.organizationId ?? null,
4510
+ dataset.projectId ?? null,
4426
4511
  jsonbArg(itemInput.input),
4427
4512
  jsonbArg(itemInput.groundTruth),
4428
4513
  jsonbArg(itemInput.expectedTrajectory),
@@ -4445,6 +4530,8 @@ var DatasetsLibSQL = class extends DatasetsStorage {
4445
4530
  id,
4446
4531
  datasetId: input.datasetId,
4447
4532
  datasetVersion: newVersion,
4533
+ organizationId: dataset.organizationId ?? null,
4534
+ projectId: dataset.projectId ?? null,
4448
4535
  input: itemInput.input,
4449
4536
  groundTruth: itemInput.groundTruth,
4450
4537
  expectedTrajectory: itemInput.expectedTrajectory,
@@ -4500,13 +4587,17 @@ var DatasetsLibSQL = class extends DatasetsStorage {
4500
4587
  args: [input.datasetId, item.id]
4501
4588
  });
4502
4589
  statements.push({
4503
- sql: `INSERT INTO ${TABLE_DATASET_ITEMS} (id, datasetId, datasetVersion, validTo, isDeleted, input, groundTruth, requestContext, metadata, source, createdAt, updatedAt) VALUES (?, ?, (SELECT version FROM ${TABLE_DATASETS} WHERE id = ?), NULL, 1, jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), ?, ?)`,
4590
+ sql: `INSERT INTO ${TABLE_DATASET_ITEMS} (id, datasetId, datasetVersion, organizationId, projectId, validTo, isDeleted, input, groundTruth, expectedTrajectory, toolMocks, requestContext, metadata, source, createdAt, updatedAt) VALUES (?, ?, (SELECT version FROM ${TABLE_DATASETS} WHERE id = ?), ?, ?, NULL, 1, jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), jsonb(?), ?, ?)`,
4504
4591
  args: [
4505
4592
  item.id,
4506
4593
  input.datasetId,
4507
4594
  input.datasetId,
4595
+ dataset.organizationId ?? null,
4596
+ dataset.projectId ?? null,
4508
4597
  jsonbArg(item.input),
4509
4598
  jsonbArg(item.groundTruth),
4599
+ jsonbArg(item.expectedTrajectory),
4600
+ jsonbArg(item.toolMocks),
4510
4601
  jsonbArg(item.requestContext),
4511
4602
  jsonbArg(item.metadata),
4512
4603
  jsonbArg(item.source),
@@ -4551,12 +4642,12 @@ var ExperimentsLibSQL = class extends ExperimentsStorage {
4551
4642
  await this.#db.alterTable({
4552
4643
  tableName: TABLE_EXPERIMENTS,
4553
4644
  schema: EXPERIMENTS_SCHEMA,
4554
- ifNotExists: ["agentVersion"]
4645
+ ifNotExists: ["agentVersion", "organizationId", "projectId"]
4555
4646
  });
4556
4647
  await this.#db.alterTable({
4557
4648
  tableName: TABLE_EXPERIMENT_RESULTS,
4558
4649
  schema: EXPERIMENT_RESULTS_SCHEMA,
4559
- ifNotExists: ["status", "tags", "toolMockReport"]
4650
+ ifNotExists: ["status", "tags", "toolMockReport", "organizationId", "projectId"]
4560
4651
  });
4561
4652
  await this.#client.batch(
4562
4653
  [
@@ -4571,6 +4662,15 @@ var ExperimentsLibSQL = class extends ExperimentsStorage {
4571
4662
  {
4572
4663
  sql: `CREATE UNIQUE INDEX IF NOT EXISTS idx_experiment_results_exp_item ON "${TABLE_EXPERIMENT_RESULTS}" ("experimentId", "itemId")`,
4573
4664
  args: []
4665
+ },
4666
+ // Tenancy: leading-tenant indexes for multi-tenant scans (parity with datasets domain).
4667
+ {
4668
+ sql: `CREATE INDEX IF NOT EXISTS idx_experiments_org_project ON "${TABLE_EXPERIMENTS}" ("organizationId", "projectId")`,
4669
+ args: []
4670
+ },
4671
+ {
4672
+ sql: `CREATE INDEX IF NOT EXISTS idx_experiment_results_org_project ON "${TABLE_EXPERIMENT_RESULTS}" ("organizationId", "projectId")`,
4673
+ args: []
4574
4674
  }
4575
4675
  ],
4576
4676
  "write"
@@ -4587,6 +4687,8 @@ var ExperimentsLibSQL = class extends ExperimentsStorage {
4587
4687
  datasetId: row.datasetId ?? null,
4588
4688
  datasetVersion: row.datasetVersion != null ? row.datasetVersion : null,
4589
4689
  agentVersion: row.agentVersion ?? null,
4690
+ organizationId: row.organizationId ?? null,
4691
+ projectId: row.projectId ?? null,
4590
4692
  targetType: row.targetType,
4591
4693
  targetId: row.targetId,
4592
4694
  name: row.name ?? void 0,
@@ -4610,6 +4712,8 @@ var ExperimentsLibSQL = class extends ExperimentsStorage {
4610
4712
  experimentId: row.experimentId,
4611
4713
  itemId: row.itemId,
4612
4714
  itemDatasetVersion: row.itemDatasetVersion != null ? row.itemDatasetVersion : null,
4715
+ organizationId: row.organizationId ?? null,
4716
+ projectId: row.projectId ?? null,
4613
4717
  input: safelyParseJSON(row.input),
4614
4718
  output: row.output ? safelyParseJSON(row.output) : null,
4615
4719
  groundTruth: row.groundTruth ? safelyParseJSON(row.groundTruth) : null,
@@ -4637,6 +4741,8 @@ var ExperimentsLibSQL = class extends ExperimentsStorage {
4637
4741
  datasetId: input.datasetId ?? null,
4638
4742
  datasetVersion: input.datasetVersion ?? null,
4639
4743
  agentVersion: input.agentVersion ?? null,
4744
+ organizationId: input.organizationId ?? null,
4745
+ projectId: input.projectId ?? null,
4640
4746
  targetType: input.targetType,
4641
4747
  targetId: input.targetId,
4642
4748
  name: input.name ?? null,
@@ -4658,6 +4764,8 @@ var ExperimentsLibSQL = class extends ExperimentsStorage {
4658
4764
  datasetId: input.datasetId,
4659
4765
  datasetVersion: input.datasetVersion,
4660
4766
  agentVersion: input.agentVersion ?? null,
4767
+ organizationId: input.organizationId ?? null,
4768
+ projectId: input.projectId ?? null,
4661
4769
  targetType: input.targetType,
4662
4770
  targetId: input.targetId,
4663
4771
  name: input.name,
@@ -4800,6 +4908,17 @@ var ExperimentsLibSQL = class extends ExperimentsStorage {
4800
4908
  conditions.push("status = ?");
4801
4909
  queryParams.push(args.status);
4802
4910
  }
4911
+ if (args.filters) {
4912
+ const { organizationId, projectId } = args.filters;
4913
+ if (organizationId !== void 0) {
4914
+ conditions.push("organizationId = ?");
4915
+ queryParams.push(organizationId);
4916
+ }
4917
+ if (projectId !== void 0) {
4918
+ conditions.push("projectId = ?");
4919
+ queryParams.push(projectId);
4920
+ }
4921
+ }
4803
4922
  const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
4804
4923
  const countResult = await this.#client.execute({
4805
4924
  sql: `SELECT COUNT(*) as count FROM ${TABLE_EXPERIMENTS} ${whereClause}`,
@@ -4874,6 +4993,8 @@ var ExperimentsLibSQL = class extends ExperimentsStorage {
4874
4993
  experimentId: input.experimentId,
4875
4994
  itemId: input.itemId,
4876
4995
  itemDatasetVersion: input.itemDatasetVersion ?? null,
4996
+ organizationId: input.organizationId ?? null,
4997
+ projectId: input.projectId ?? null,
4877
4998
  input: input.input,
4878
4999
  output: input.output,
4879
5000
  groundTruth: input.groundTruth,
@@ -4893,6 +5014,8 @@ var ExperimentsLibSQL = class extends ExperimentsStorage {
4893
5014
  experimentId: input.experimentId,
4894
5015
  itemId: input.itemId,
4895
5016
  itemDatasetVersion: input.itemDatasetVersion,
5017
+ organizationId: input.organizationId ?? null,
5018
+ projectId: input.projectId ?? null,
4896
5019
  input: input.input,
4897
5020
  output: input.output,
4898
5021
  groundTruth: input.groundTruth,
@@ -5012,6 +5135,17 @@ var ExperimentsLibSQL = class extends ExperimentsStorage {
5012
5135
  conditions.push("status = ?");
5013
5136
  queryParams.push(args.status);
5014
5137
  }
5138
+ if (args.filters) {
5139
+ const { organizationId, projectId } = args.filters;
5140
+ if (organizationId !== void 0) {
5141
+ conditions.push("organizationId = ?");
5142
+ queryParams.push(organizationId);
5143
+ }
5144
+ if (projectId !== void 0) {
5145
+ conditions.push("projectId = ?");
5146
+ queryParams.push(projectId);
5147
+ }
5148
+ }
5015
5149
  const whereClause = `WHERE ${conditions.join(" AND ")}`;
5016
5150
  const countResult = await this.#client.execute({
5017
5151
  sql: `SELECT COUNT(*) as count FROM ${TABLE_EXPERIMENT_RESULTS} ${whereClause}`,