@mastra/pg 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
@@ -5181,9 +5181,15 @@ var DatasetsPG = class _DatasetsPG extends DatasetsStorage {
5181
5181
  await this.#addColumnIfNotExists(TABLE_DATASETS, "targetType", "TEXT");
5182
5182
  await this.#addColumnIfNotExists(TABLE_DATASETS, "targetIds", "JSONB");
5183
5183
  await this.#addColumnIfNotExists(TABLE_DATASETS, "scorerIds", "JSONB");
5184
+ await this.#addColumnIfNotExists(TABLE_DATASETS, "organizationId", "TEXT");
5185
+ await this.#addColumnIfNotExists(TABLE_DATASETS, "projectId", "TEXT");
5186
+ await this.#addColumnIfNotExists(TABLE_DATASETS, "candidateKey", "TEXT");
5187
+ await this.#addColumnIfNotExists(TABLE_DATASETS, "candidateId", "TEXT");
5184
5188
  await this.#addColumnIfNotExists(TABLE_DATASET_ITEMS, "requestContext", "JSONB");
5185
5189
  await this.#addColumnIfNotExists(TABLE_DATASET_ITEMS, "source", "JSONB");
5186
5190
  await this.#addColumnIfNotExists(TABLE_DATASET_ITEMS, "expectedTrajectory", "JSONB");
5191
+ await this.#addColumnIfNotExists(TABLE_DATASET_ITEMS, "organizationId", "TEXT");
5192
+ await this.#addColumnIfNotExists(TABLE_DATASET_ITEMS, "projectId", "TEXT");
5187
5193
  await this.#addColumnIfNotExists(TABLE_DATASET_ITEMS, "toolMocks", "JSONB");
5188
5194
  await this.createDefaultIndexes();
5189
5195
  await this.createCustomIndexes();
@@ -5218,6 +5224,22 @@ var DatasetsPG = class _DatasetsPG extends DatasetsStorage {
5218
5224
  table: TABLE_DATASET_VERSIONS,
5219
5225
  columns: ["datasetId", "version"],
5220
5226
  unique: true
5227
+ },
5228
+ // Tenancy: leading-tenant indexes for multi-tenant scans (parity with observability storage).
5229
+ {
5230
+ name: "idx_datasets_org_project",
5231
+ table: TABLE_DATASETS,
5232
+ columns: ["organizationId", "projectId"]
5233
+ },
5234
+ {
5235
+ name: "idx_datasets_candidate",
5236
+ table: TABLE_DATASETS,
5237
+ columns: ["candidateKey", "candidateId"]
5238
+ },
5239
+ {
5240
+ name: "idx_dataset_items_org_project",
5241
+ table: TABLE_DATASET_ITEMS,
5242
+ columns: ["organizationId", "projectId"]
5221
5243
  }
5222
5244
  ];
5223
5245
  }
@@ -5255,6 +5277,10 @@ var DatasetsPG = class _DatasetsPG extends DatasetsStorage {
5255
5277
  targetType: row.targetType || null,
5256
5278
  targetIds: row.targetIds || null,
5257
5279
  scorerIds: row.scorerIds || null,
5280
+ organizationId: row.organizationId ?? null,
5281
+ projectId: row.projectId ?? null,
5282
+ candidateKey: row.candidateKey ?? null,
5283
+ candidateId: row.candidateId ?? null,
5258
5284
  version: row.version,
5259
5285
  createdAt: ensureDate(row.createdAtZ || row.createdAt),
5260
5286
  updatedAt: ensureDate(row.updatedAtZ || row.updatedAt)
@@ -5265,6 +5291,8 @@ var DatasetsPG = class _DatasetsPG extends DatasetsStorage {
5265
5291
  id: row.id,
5266
5292
  datasetId: row.datasetId,
5267
5293
  datasetVersion: row.datasetVersion,
5294
+ organizationId: row.organizationId ?? null,
5295
+ projectId: row.projectId ?? null,
5268
5296
  input: safelyParseJSON(row.input),
5269
5297
  groundTruth: row.groundTruth ? safelyParseJSON(row.groundTruth) : void 0,
5270
5298
  expectedTrajectory: row.expectedTrajectory ? safelyParseJSON(row.expectedTrajectory) : void 0,
@@ -5281,6 +5309,8 @@ var DatasetsPG = class _DatasetsPG extends DatasetsStorage {
5281
5309
  id: row.id,
5282
5310
  datasetId: row.datasetId,
5283
5311
  datasetVersion: row.datasetVersion,
5312
+ organizationId: row.organizationId ?? null,
5313
+ projectId: row.projectId ?? null,
5284
5314
  validTo: row.validTo,
5285
5315
  isDeleted: Boolean(row.isDeleted),
5286
5316
  input: safelyParseJSON(row.input),
@@ -5321,6 +5351,10 @@ var DatasetsPG = class _DatasetsPG extends DatasetsStorage {
5321
5351
  targetType: input.targetType ?? null,
5322
5352
  targetIds: input.targetIds !== void 0 ? JSON.stringify(input.targetIds) : null,
5323
5353
  scorerIds: input.scorerIds ? JSON.stringify(input.scorerIds) : null,
5354
+ organizationId: input.organizationId ?? null,
5355
+ projectId: input.projectId ?? null,
5356
+ candidateKey: input.candidateKey ?? null,
5357
+ candidateId: input.candidateId ?? null,
5324
5358
  version: 0,
5325
5359
  createdAt: nowIso,
5326
5360
  updatedAt: nowIso
@@ -5337,6 +5371,10 @@ var DatasetsPG = class _DatasetsPG extends DatasetsStorage {
5337
5371
  targetType: input.targetType ?? null,
5338
5372
  targetIds: input.targetIds ?? null,
5339
5373
  scorerIds: input.scorerIds ?? null,
5374
+ organizationId: input.organizationId ?? null,
5375
+ projectId: input.projectId ?? null,
5376
+ candidateKey: input.candidateKey ?? null,
5377
+ candidateId: input.candidateId ?? null,
5340
5378
  version: 0,
5341
5379
  createdAt: now,
5342
5380
  updatedAt: now
@@ -5441,6 +5479,10 @@ var DatasetsPG = class _DatasetsPG extends DatasetsStorage {
5441
5479
  targetType: (args.targetType !== void 0 ? args.targetType : existing.targetType) ?? null,
5442
5480
  targetIds: (args.targetIds !== void 0 ? args.targetIds : existing.targetIds) ?? null,
5443
5481
  scorerIds: (args.scorerIds !== void 0 ? args.scorerIds : existing.scorerIds) ?? null,
5482
+ organizationId: existing.organizationId ?? null,
5483
+ projectId: existing.projectId ?? null,
5484
+ candidateKey: existing.candidateKey ?? null,
5485
+ candidateId: existing.candidateId ?? null,
5444
5486
  updatedAt: new Date(now)
5445
5487
  };
5446
5488
  } catch (error) {
@@ -5503,7 +5545,33 @@ var DatasetsPG = class _DatasetsPG extends DatasetsStorage {
5503
5545
  try {
5504
5546
  const { page, perPage: perPageInput } = args.pagination;
5505
5547
  const tableName = getTableName2({ indexName: TABLE_DATASETS, schemaName: getSchemaName2(this.#schema) });
5506
- const countResult = await this.#db.client.one(`SELECT COUNT(*) as count FROM ${tableName}`);
5548
+ const conditions = [];
5549
+ const queryParams = [];
5550
+ let paramIndex = 1;
5551
+ if (args.filters) {
5552
+ const { organizationId, projectId, candidateKey, candidateId } = args.filters;
5553
+ if (organizationId !== void 0) {
5554
+ conditions.push(`"organizationId" = $${paramIndex++}`);
5555
+ queryParams.push(organizationId);
5556
+ }
5557
+ if (projectId !== void 0) {
5558
+ conditions.push(`"projectId" = $${paramIndex++}`);
5559
+ queryParams.push(projectId);
5560
+ }
5561
+ if (candidateKey !== void 0) {
5562
+ conditions.push(`"candidateKey" = $${paramIndex++}`);
5563
+ queryParams.push(candidateKey);
5564
+ }
5565
+ if (candidateId !== void 0) {
5566
+ conditions.push(`"candidateId" = $${paramIndex++}`);
5567
+ queryParams.push(candidateId);
5568
+ }
5569
+ }
5570
+ const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
5571
+ const countResult = await this.#db.client.one(
5572
+ `SELECT COUNT(*) as count FROM ${tableName} ${whereClause}`,
5573
+ queryParams
5574
+ );
5507
5575
  const total = parseInt(countResult.count, 10);
5508
5576
  if (total === 0) {
5509
5577
  return { datasets: [], pagination: { total: 0, page, perPage: perPageInput, hasMore: false } };
@@ -5512,8 +5580,8 @@ var DatasetsPG = class _DatasetsPG extends DatasetsStorage {
5512
5580
  const { offset, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
5513
5581
  const limitValue = perPageInput === false ? total : perPage;
5514
5582
  const rows = await this.#db.client.manyOrNone(
5515
- `SELECT * FROM ${tableName} ORDER BY "createdAt" DESC, "id" ASC LIMIT $1 OFFSET $2`,
5516
- [limitValue, offset]
5583
+ `SELECT * FROM ${tableName} ${whereClause} ORDER BY "createdAt" DESC, "id" ASC LIMIT $${paramIndex} OFFSET $${paramIndex + 1}`,
5584
+ [...queryParams, limitValue, offset]
5517
5585
  );
5518
5586
  return {
5519
5587
  datasets: (rows || []).map((row) => this.transformDatasetRow(row)),
@@ -5549,18 +5617,24 @@ var DatasetsPG = class _DatasetsPG extends DatasetsStorage {
5549
5617
  const now = /* @__PURE__ */ new Date();
5550
5618
  const nowIso = now.toISOString();
5551
5619
  let newVersion;
5620
+ let parentOrganizationId = null;
5621
+ let parentProjectId = null;
5552
5622
  await this.#db.client.tx(async (t) => {
5553
5623
  const row = await t.one(
5554
- `UPDATE ${datasetsTable} SET "version" = "version" + 1 WHERE "id" = $1 RETURNING "version"`,
5624
+ `UPDATE ${datasetsTable} SET "version" = "version" + 1 WHERE "id" = $1 RETURNING "version", "organizationId", "projectId"`,
5555
5625
  [args.datasetId]
5556
5626
  );
5557
5627
  newVersion = row.version;
5628
+ parentOrganizationId = row.organizationId ?? null;
5629
+ parentProjectId = row.projectId ?? null;
5558
5630
  await t.none(
5559
- `INSERT INTO ${itemsTable} ("id","datasetId","datasetVersion","validTo","isDeleted","input","groundTruth","expectedTrajectory","toolMocks","requestContext","metadata","source","createdAt","createdAtZ","updatedAt","updatedAtZ") VALUES ($1,$2,$3,NULL,false,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14)`,
5631
+ `INSERT INTO ${itemsTable} ("id","datasetId","datasetVersion","organizationId","projectId","validTo","isDeleted","input","groundTruth","expectedTrajectory","toolMocks","requestContext","metadata","source","createdAt","createdAtZ","updatedAt","updatedAtZ") VALUES ($1,$2,$3,$4,$5,NULL,false,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16)`,
5560
5632
  [
5561
5633
  id,
5562
5634
  args.datasetId,
5563
5635
  newVersion,
5636
+ parentOrganizationId,
5637
+ parentProjectId,
5564
5638
  JSON.stringify(args.input),
5565
5639
  jsonbArg(args.groundTruth),
5566
5640
  jsonbArg(args.expectedTrajectory),
@@ -5583,6 +5657,8 @@ var DatasetsPG = class _DatasetsPG extends DatasetsStorage {
5583
5657
  id,
5584
5658
  datasetId: args.datasetId,
5585
5659
  datasetVersion: newVersion,
5660
+ organizationId: parentOrganizationId,
5661
+ projectId: parentProjectId,
5586
5662
  input: args.input,
5587
5663
  groundTruth: args.groundTruth,
5588
5664
  expectedTrajectory: args.expectedTrajectory,
@@ -5641,22 +5717,28 @@ var DatasetsPG = class _DatasetsPG extends DatasetsStorage {
5641
5717
  const mergedMetadata = args.metadata !== void 0 ? args.metadata : existing.metadata;
5642
5718
  const mergedSource = args.source !== void 0 ? args.source : existing.source;
5643
5719
  let newVersion;
5720
+ let parentOrganizationId = null;
5721
+ let parentProjectId = null;
5644
5722
  await this.#db.client.tx(async (t) => {
5645
5723
  const row = await t.one(
5646
- `UPDATE ${datasetsTable} SET "version" = "version" + 1 WHERE "id" = $1 RETURNING "version"`,
5724
+ `UPDATE ${datasetsTable} SET "version" = "version" + 1 WHERE "id" = $1 RETURNING "version", "organizationId", "projectId"`,
5647
5725
  [args.datasetId]
5648
5726
  );
5649
5727
  newVersion = row.version;
5728
+ parentOrganizationId = row.organizationId ?? null;
5729
+ parentProjectId = row.projectId ?? null;
5650
5730
  await t.none(
5651
5731
  `UPDATE ${itemsTable} SET "validTo" = $1 WHERE "id" = $2 AND "validTo" IS NULL AND "isDeleted" = false`,
5652
5732
  [newVersion, args.id]
5653
5733
  );
5654
5734
  await t.none(
5655
- `INSERT INTO ${itemsTable} ("id","datasetId","datasetVersion","validTo","isDeleted","input","groundTruth","expectedTrajectory","toolMocks","requestContext","metadata","source","createdAt","createdAtZ","updatedAt","updatedAtZ") VALUES ($1,$2,$3,NULL,false,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14)`,
5735
+ `INSERT INTO ${itemsTable} ("id","datasetId","datasetVersion","organizationId","projectId","validTo","isDeleted","input","groundTruth","expectedTrajectory","toolMocks","requestContext","metadata","source","createdAt","createdAtZ","updatedAt","updatedAtZ") VALUES ($1,$2,$3,$4,$5,NULL,false,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16)`,
5656
5736
  [
5657
5737
  args.id,
5658
5738
  args.datasetId,
5659
5739
  newVersion,
5740
+ parentOrganizationId,
5741
+ parentProjectId,
5660
5742
  JSON.stringify(mergedInput),
5661
5743
  jsonbArg(mergedGroundTruth),
5662
5744
  jsonbArg(mergedExpectedTrajectory),
@@ -5678,6 +5760,8 @@ var DatasetsPG = class _DatasetsPG extends DatasetsStorage {
5678
5760
  return {
5679
5761
  ...existing,
5680
5762
  datasetVersion: newVersion,
5763
+ organizationId: parentOrganizationId,
5764
+ projectId: parentProjectId,
5681
5765
  input: mergedInput,
5682
5766
  groundTruth: mergedGroundTruth,
5683
5767
  expectedTrajectory: mergedExpectedTrajectory,
@@ -5721,20 +5805,24 @@ var DatasetsPG = class _DatasetsPG extends DatasetsStorage {
5721
5805
  const nowIso = (/* @__PURE__ */ new Date()).toISOString();
5722
5806
  await this.#db.client.tx(async (t) => {
5723
5807
  const row = await t.one(
5724
- `UPDATE ${datasetsTable} SET "version" = "version" + 1 WHERE "id" = $1 RETURNING "version"`,
5808
+ `UPDATE ${datasetsTable} SET "version" = "version" + 1 WHERE "id" = $1 RETURNING "version", "organizationId", "projectId"`,
5725
5809
  [datasetId]
5726
5810
  );
5727
5811
  const newVersion = row.version;
5812
+ const parentOrganizationId = row.organizationId ?? null;
5813
+ const parentProjectId = row.projectId ?? null;
5728
5814
  await t.none(
5729
5815
  `UPDATE ${itemsTable} SET "validTo" = $1 WHERE "id" = $2 AND "validTo" IS NULL AND "isDeleted" = false`,
5730
5816
  [newVersion, id]
5731
5817
  );
5732
5818
  await t.none(
5733
- `INSERT INTO ${itemsTable} ("id","datasetId","datasetVersion","validTo","isDeleted","input","groundTruth","expectedTrajectory","toolMocks","requestContext","metadata","source","createdAt","createdAtZ","updatedAt","updatedAtZ") VALUES ($1,$2,$3,NULL,true,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14)`,
5819
+ `INSERT INTO ${itemsTable} ("id","datasetId","datasetVersion","organizationId","projectId","validTo","isDeleted","input","groundTruth","expectedTrajectory","toolMocks","requestContext","metadata","source","createdAt","createdAtZ","updatedAt","updatedAtZ") VALUES ($1,$2,$3,$4,$5,NULL,true,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16)`,
5734
5820
  [
5735
5821
  id,
5736
5822
  datasetId,
5737
5823
  newVersion,
5824
+ parentOrganizationId,
5825
+ parentProjectId,
5738
5826
  JSON.stringify(existing.input),
5739
5827
  jsonbArg(existing.groundTruth),
5740
5828
  jsonbArg(existing.expectedTrajectory),
@@ -5786,6 +5874,8 @@ var DatasetsPG = class _DatasetsPG extends DatasetsStorage {
5786
5874
  const nowIso = now.toISOString();
5787
5875
  const versionId = crypto.randomUUID();
5788
5876
  const itemsWithIds = input.items.map((itemInput) => ({ id: crypto.randomUUID(), input: itemInput }));
5877
+ const parentOrganizationId = dataset.organizationId ?? null;
5878
+ const parentProjectId = dataset.projectId ?? null;
5789
5879
  let newVersion;
5790
5880
  await this.#db.client.tx(async (t) => {
5791
5881
  const row = await t.one(
@@ -5795,11 +5885,13 @@ var DatasetsPG = class _DatasetsPG extends DatasetsStorage {
5795
5885
  newVersion = row.version;
5796
5886
  for (const { id, input: itemInput } of itemsWithIds) {
5797
5887
  await t.none(
5798
- `INSERT INTO ${itemsTable} ("id","datasetId","datasetVersion","validTo","isDeleted","input","groundTruth","expectedTrajectory","toolMocks","requestContext","metadata","source","createdAt","createdAtZ","updatedAt","updatedAtZ") VALUES ($1,$2,$3,NULL,false,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14)`,
5888
+ `INSERT INTO ${itemsTable} ("id","datasetId","datasetVersion","organizationId","projectId","validTo","isDeleted","input","groundTruth","expectedTrajectory","toolMocks","requestContext","metadata","source","createdAt","createdAtZ","updatedAt","updatedAtZ") VALUES ($1,$2,$3,$4,$5,NULL,false,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16)`,
5799
5889
  [
5800
5890
  id,
5801
5891
  input.datasetId,
5802
5892
  newVersion,
5893
+ parentOrganizationId,
5894
+ parentProjectId,
5803
5895
  JSON.stringify(itemInput.input),
5804
5896
  jsonbArg(itemInput.groundTruth),
5805
5897
  jsonbArg(itemInput.expectedTrajectory),
@@ -5823,6 +5915,8 @@ var DatasetsPG = class _DatasetsPG extends DatasetsStorage {
5823
5915
  id,
5824
5916
  datasetId: input.datasetId,
5825
5917
  datasetVersion: newVersion,
5918
+ organizationId: parentOrganizationId,
5919
+ projectId: parentProjectId,
5826
5920
  input: itemInput.input,
5827
5921
  groundTruth: itemInput.groundTruth,
5828
5922
  expectedTrajectory: itemInput.expectedTrajectory,
@@ -5872,6 +5966,8 @@ var DatasetsPG = class _DatasetsPG extends DatasetsStorage {
5872
5966
  });
5873
5967
  const nowIso = (/* @__PURE__ */ new Date()).toISOString();
5874
5968
  const versionId = crypto.randomUUID();
5969
+ const parentOrganizationId = dataset.organizationId ?? null;
5970
+ const parentProjectId = dataset.projectId ?? null;
5875
5971
  await this.#db.client.tx(async (t) => {
5876
5972
  const row = await t.one(
5877
5973
  `UPDATE ${datasetsTable} SET "version" = "version" + 1 WHERE "id" = $1 RETURNING "version"`,
@@ -5884,11 +5980,13 @@ var DatasetsPG = class _DatasetsPG extends DatasetsStorage {
5884
5980
  [newVersion, item.id]
5885
5981
  );
5886
5982
  await t.none(
5887
- `INSERT INTO ${itemsTable} ("id","datasetId","datasetVersion","validTo","isDeleted","input","groundTruth","expectedTrajectory","toolMocks","requestContext","metadata","source","createdAt","createdAtZ","updatedAt","updatedAtZ") VALUES ($1,$2,$3,NULL,true,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14)`,
5983
+ `INSERT INTO ${itemsTable} ("id","datasetId","datasetVersion","organizationId","projectId","validTo","isDeleted","input","groundTruth","expectedTrajectory","toolMocks","requestContext","metadata","source","createdAt","createdAtZ","updatedAt","updatedAtZ") VALUES ($1,$2,$3,$4,$5,NULL,true,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16)`,
5888
5984
  [
5889
5985
  item.id,
5890
5986
  input.datasetId,
5891
5987
  newVersion,
5988
+ parentOrganizationId,
5989
+ parentProjectId,
5892
5990
  JSON.stringify(item.input),
5893
5991
  jsonbArg(item.groundTruth),
5894
5992
  jsonbArg(item.expectedTrajectory),
@@ -6010,6 +6108,17 @@ var DatasetsPG = class _DatasetsPG extends DatasetsStorage {
6010
6108
  queryParams.push(`%${args.search}%`);
6011
6109
  paramIndex++;
6012
6110
  }
6111
+ if (args.filters) {
6112
+ const { organizationId, projectId } = args.filters;
6113
+ if (organizationId !== void 0) {
6114
+ conditions.push(`"organizationId" = $${paramIndex++}`);
6115
+ queryParams.push(organizationId);
6116
+ }
6117
+ if (projectId !== void 0) {
6118
+ conditions.push(`"projectId" = $${paramIndex++}`);
6119
+ queryParams.push(projectId);
6120
+ }
6121
+ }
6013
6122
  const whereClause = `WHERE ${conditions.join(" AND ")}`;
6014
6123
  const countResult = await this.#db.client.one(
6015
6124
  `SELECT COUNT(*) as count FROM ${tableName} ${whereClause}`,
@@ -6148,12 +6257,12 @@ var ExperimentsPG = class _ExperimentsPG extends ExperimentsStorage {
6148
6257
  await this.#db.alterTable({
6149
6258
  tableName: TABLE_EXPERIMENTS,
6150
6259
  schema: EXPERIMENTS_SCHEMA,
6151
- ifNotExists: ["agentVersion"]
6260
+ ifNotExists: ["agentVersion", "organizationId", "projectId"]
6152
6261
  });
6153
6262
  await this.#db.alterTable({
6154
6263
  tableName: TABLE_EXPERIMENT_RESULTS,
6155
6264
  schema: EXPERIMENT_RESULTS_SCHEMA,
6156
- ifNotExists: ["status", "tags", "toolMockReport"]
6265
+ ifNotExists: ["status", "tags", "toolMockReport", "organizationId", "projectId"]
6157
6266
  });
6158
6267
  await this.createDefaultIndexes();
6159
6268
  await this.createCustomIndexes();
@@ -6167,6 +6276,17 @@ var ExperimentsPG = class _ExperimentsPG extends ExperimentsStorage {
6167
6276
  table: TABLE_EXPERIMENT_RESULTS,
6168
6277
  columns: ["experimentId", "itemId"],
6169
6278
  unique: true
6279
+ },
6280
+ // Tenancy: leading-tenant indexes for multi-tenant scans (parity with datasets domain).
6281
+ {
6282
+ name: "idx_experiments_org_project",
6283
+ table: TABLE_EXPERIMENTS,
6284
+ columns: ["organizationId", "projectId"]
6285
+ },
6286
+ {
6287
+ name: "idx_experiment_results_org_project",
6288
+ table: TABLE_EXPERIMENT_RESULTS,
6289
+ columns: ["organizationId", "projectId"]
6170
6290
  }
6171
6291
  ];
6172
6292
  }
@@ -6200,6 +6320,8 @@ var ExperimentsPG = class _ExperimentsPG extends ExperimentsStorage {
6200
6320
  datasetId: row.datasetId ?? null,
6201
6321
  datasetVersion: row.datasetVersion != null ? row.datasetVersion : null,
6202
6322
  agentVersion: row.agentVersion ?? null,
6323
+ organizationId: row.organizationId ?? null,
6324
+ projectId: row.projectId ?? null,
6203
6325
  targetType: row.targetType,
6204
6326
  targetId: row.targetId,
6205
6327
  status: row.status,
@@ -6219,6 +6341,8 @@ var ExperimentsPG = class _ExperimentsPG extends ExperimentsStorage {
6219
6341
  experimentId: row.experimentId,
6220
6342
  itemId: row.itemId,
6221
6343
  itemDatasetVersion: row.itemDatasetVersion != null ? row.itemDatasetVersion : null,
6344
+ organizationId: row.organizationId ?? null,
6345
+ projectId: row.projectId ?? null,
6222
6346
  input: safelyParseJSON(row.input),
6223
6347
  output: row.output ? safelyParseJSON(row.output) : null,
6224
6348
  groundTruth: row.groundTruth ? safelyParseJSON(row.groundTruth) : null,
@@ -6249,6 +6373,8 @@ var ExperimentsPG = class _ExperimentsPG extends ExperimentsStorage {
6249
6373
  datasetId: input.datasetId ?? null,
6250
6374
  datasetVersion: input.datasetVersion ?? null,
6251
6375
  agentVersion: input.agentVersion ?? null,
6376
+ organizationId: input.organizationId ?? null,
6377
+ projectId: input.projectId ?? null,
6252
6378
  targetType: input.targetType,
6253
6379
  targetId: input.targetId,
6254
6380
  status: "pending",
@@ -6270,6 +6396,8 @@ var ExperimentsPG = class _ExperimentsPG extends ExperimentsStorage {
6270
6396
  datasetId: input.datasetId ?? null,
6271
6397
  datasetVersion: input.datasetVersion ?? null,
6272
6398
  agentVersion: input.agentVersion ?? null,
6399
+ organizationId: input.organizationId ?? null,
6400
+ projectId: input.projectId ?? null,
6273
6401
  targetType: input.targetType,
6274
6402
  targetId: input.targetId,
6275
6403
  status: "pending",
@@ -6411,6 +6539,17 @@ var ExperimentsPG = class _ExperimentsPG extends ExperimentsStorage {
6411
6539
  conditions.push(`"status" = $${paramIndex++}`);
6412
6540
  queryParams.push(args.status);
6413
6541
  }
6542
+ if (args.filters) {
6543
+ const { organizationId, projectId } = args.filters;
6544
+ if (organizationId !== void 0) {
6545
+ conditions.push(`"organizationId" = $${paramIndex++}`);
6546
+ queryParams.push(organizationId);
6547
+ }
6548
+ if (projectId !== void 0) {
6549
+ conditions.push(`"projectId" = $${paramIndex++}`);
6550
+ queryParams.push(projectId);
6551
+ }
6552
+ }
6414
6553
  const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
6415
6554
  const countResult = await this.#db.client.one(
6416
6555
  `SELECT COUNT(*) as count FROM ${tableName} ${whereClause}`,
@@ -6480,6 +6619,8 @@ var ExperimentsPG = class _ExperimentsPG extends ExperimentsStorage {
6480
6619
  experimentId: input.experimentId,
6481
6620
  itemId: input.itemId,
6482
6621
  itemDatasetVersion: input.itemDatasetVersion ?? null,
6622
+ organizationId: input.organizationId ?? null,
6623
+ projectId: input.projectId ?? null,
6483
6624
  input: input.input,
6484
6625
  output: input.output ?? null,
6485
6626
  groundTruth: input.groundTruth ?? null,
@@ -6499,6 +6640,8 @@ var ExperimentsPG = class _ExperimentsPG extends ExperimentsStorage {
6499
6640
  experimentId: input.experimentId,
6500
6641
  itemId: input.itemId,
6501
6642
  itemDatasetVersion: input.itemDatasetVersion ?? null,
6643
+ organizationId: input.organizationId ?? null,
6644
+ projectId: input.projectId ?? null,
6502
6645
  input: input.input,
6503
6646
  output: input.output ?? null,
6504
6647
  groundTruth: input.groundTruth ?? null,
@@ -6612,6 +6755,17 @@ var ExperimentsPG = class _ExperimentsPG extends ExperimentsStorage {
6612
6755
  conditions.push(`"status" = $${paramIndex++}`);
6613
6756
  queryParams.push(args.status);
6614
6757
  }
6758
+ if (args.filters) {
6759
+ const { organizationId, projectId } = args.filters;
6760
+ if (organizationId !== void 0) {
6761
+ conditions.push(`"organizationId" = $${paramIndex++}`);
6762
+ queryParams.push(organizationId);
6763
+ }
6764
+ if (projectId !== void 0) {
6765
+ conditions.push(`"projectId" = $${paramIndex++}`);
6766
+ queryParams.push(projectId);
6767
+ }
6768
+ }
6615
6769
  const whereClause = `WHERE ${conditions.join(" AND ")}`;
6616
6770
  const countResult = await this.#db.client.one(
6617
6771
  `SELECT COUNT(*) as count FROM ${tableName} ${whereClause}`,