@mastra/mysql 0.3.0-alpha.0 → 0.3.0

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
@@ -2130,6 +2130,16 @@ var DatasetsMySQL = class _DatasetsMySQL extends DatasetsStorage {
2130
2130
  await this.operations.createTable({ tableName: TABLE_DATASETS, schema: DATASETS_SCHEMA });
2131
2131
  await this.operations.createTable({ tableName: TABLE_DATASET_ITEMS, schema: DATASET_ITEMS_SCHEMA });
2132
2132
  await this.operations.createTable({ tableName: TABLE_DATASET_VERSIONS, schema: DATASET_VERSIONS_SCHEMA });
2133
+ await this.operations.alterTable({
2134
+ tableName: TABLE_DATASETS,
2135
+ schema: DATASETS_SCHEMA,
2136
+ ifNotExists: ["organizationId", "projectId", "candidateKey", "candidateId"]
2137
+ });
2138
+ await this.operations.alterTable({
2139
+ tableName: TABLE_DATASET_ITEMS,
2140
+ schema: DATASET_ITEMS_SCHEMA,
2141
+ ifNotExists: ["organizationId", "projectId"]
2142
+ });
2133
2143
  await this.createDefaultIndexes();
2134
2144
  await this.createCustomIndexes();
2135
2145
  }
@@ -2148,6 +2158,10 @@ var DatasetsMySQL = class _DatasetsMySQL extends DatasetsStorage {
2148
2158
  inputSchema: parseJSON(row.inputSchema),
2149
2159
  groundTruthSchema: parseJSON(row.groundTruthSchema),
2150
2160
  version: row.version,
2161
+ organizationId: row.organizationId ?? null,
2162
+ projectId: row.projectId ?? null,
2163
+ candidateKey: row.candidateKey ?? null,
2164
+ candidateId: row.candidateId ?? null,
2151
2165
  createdAt: parseDateTime(row.createdAt) ?? /* @__PURE__ */ new Date(),
2152
2166
  updatedAt: parseDateTime(row.updatedAt) ?? /* @__PURE__ */ new Date()
2153
2167
  };
@@ -2157,6 +2171,8 @@ var DatasetsMySQL = class _DatasetsMySQL extends DatasetsStorage {
2157
2171
  id: row.id,
2158
2172
  datasetId: row.datasetId,
2159
2173
  datasetVersion: row.datasetVersion,
2174
+ organizationId: row.organizationId ?? null,
2175
+ projectId: row.projectId ?? null,
2160
2176
  input: parseJSON(row.input),
2161
2177
  groundTruth: row.groundTruth ? parseJSON(row.groundTruth) : void 0,
2162
2178
  metadata: row.metadata ? parseJSON(row.metadata) : void 0,
@@ -2169,6 +2185,8 @@ var DatasetsMySQL = class _DatasetsMySQL extends DatasetsStorage {
2169
2185
  id: row.id,
2170
2186
  datasetId: row.datasetId,
2171
2187
  datasetVersion: row.datasetVersion,
2188
+ organizationId: row.organizationId ?? null,
2189
+ projectId: row.projectId ?? null,
2172
2190
  validTo: row.validTo,
2173
2191
  isDeleted: Boolean(row.isDeleted),
2174
2192
  input: parseJSON(row.input),
@@ -2201,6 +2219,10 @@ var DatasetsMySQL = class _DatasetsMySQL extends DatasetsStorage {
2201
2219
  inputSchema: jsonArg(input.inputSchema),
2202
2220
  groundTruthSchema: jsonArg(input.groundTruthSchema),
2203
2221
  version: 0,
2222
+ organizationId: input.organizationId ?? null,
2223
+ projectId: input.projectId ?? null,
2224
+ candidateKey: input.candidateKey ?? null,
2225
+ candidateId: input.candidateId ?? null,
2204
2226
  createdAt: now,
2205
2227
  updatedAt: now
2206
2228
  }
@@ -2213,6 +2235,10 @@ var DatasetsMySQL = class _DatasetsMySQL extends DatasetsStorage {
2213
2235
  inputSchema: input.inputSchema ?? void 0,
2214
2236
  groundTruthSchema: input.groundTruthSchema ?? void 0,
2215
2237
  version: 0,
2238
+ organizationId: input.organizationId ?? null,
2239
+ projectId: input.projectId ?? null,
2240
+ candidateKey: input.candidateKey ?? null,
2241
+ candidateId: input.candidateId ?? null,
2216
2242
  createdAt: now,
2217
2243
  updatedAt: now
2218
2244
  };
@@ -2335,7 +2361,28 @@ var DatasetsMySQL = class _DatasetsMySQL extends DatasetsStorage {
2335
2361
  async listDatasets(args) {
2336
2362
  try {
2337
2363
  const { page, perPage: perPageInput } = args.pagination;
2338
- const whereClause = { sql: "", args: [] };
2364
+ const filterParts = [];
2365
+ const filterArgs = [];
2366
+ if (args.filters?.organizationId !== void 0) {
2367
+ filterParts.push(`${quoteIdentifier("organizationId", "column name")} = ?`);
2368
+ filterArgs.push(args.filters.organizationId);
2369
+ }
2370
+ if (args.filters?.projectId !== void 0) {
2371
+ filterParts.push(`${quoteIdentifier("projectId", "column name")} = ?`);
2372
+ filterArgs.push(args.filters.projectId);
2373
+ }
2374
+ if (args.filters?.candidateKey !== void 0) {
2375
+ filterParts.push(`${quoteIdentifier("candidateKey", "column name")} = ?`);
2376
+ filterArgs.push(args.filters.candidateKey);
2377
+ }
2378
+ if (args.filters?.candidateId !== void 0) {
2379
+ filterParts.push(`${quoteIdentifier("candidateId", "column name")} = ?`);
2380
+ filterArgs.push(args.filters.candidateId);
2381
+ }
2382
+ const whereClause = {
2383
+ sql: filterParts.length > 0 ? `WHERE ${filterParts.join(" AND ")}` : "",
2384
+ args: filterArgs
2385
+ };
2339
2386
  const total = await this.operations.loadTotalCount({ tableName: TABLE_DATASETS, whereClause });
2340
2387
  if (total === 0) {
2341
2388
  return {
@@ -2388,17 +2435,22 @@ var DatasetsMySQL = class _DatasetsMySQL extends DatasetsStorage {
2388
2435
  await connection.execute(`UPDATE ${tableDatasetsName} SET \`version\` = \`version\` + 1 WHERE id = ?`, [
2389
2436
  args.datasetId
2390
2437
  ]);
2391
- const [versionRows] = await connection.execute(
2392
- `SELECT \`version\` FROM ${tableDatasetsName} WHERE id = ?`,
2438
+ const [datasetRows] = await connection.execute(
2439
+ `SELECT \`version\`, \`organizationId\`, \`projectId\` FROM ${tableDatasetsName} WHERE id = ?`,
2393
2440
  [args.datasetId]
2394
2441
  );
2395
- const newVersion = versionRows[0]?.version;
2442
+ const parentRow = datasetRows[0];
2443
+ const newVersion = parentRow?.version;
2444
+ const parentOrganizationId = parentRow?.organizationId ?? null;
2445
+ const parentProjectId = parentRow?.projectId ?? null;
2396
2446
  await connection.execute(
2397
- `INSERT INTO ${tableItemsName} (\`id\`, \`datasetId\`, \`datasetVersion\`, \`validTo\`, \`isDeleted\`, \`input\`, \`groundTruth\`, \`metadata\`, \`createdAt\`, \`updatedAt\`) VALUES (?, ?, ?, NULL, 0, ?, ?, ?, ?, ?)`,
2447
+ `INSERT INTO ${tableItemsName} (\`id\`, \`datasetId\`, \`datasetVersion\`, \`organizationId\`, \`projectId\`, \`validTo\`, \`isDeleted\`, \`input\`, \`groundTruth\`, \`metadata\`, \`createdAt\`, \`updatedAt\`) VALUES (?, ?, ?, ?, ?, NULL, 0, ?, ?, ?, ?, ?)`,
2398
2448
  [
2399
2449
  id,
2400
2450
  args.datasetId,
2401
2451
  newVersion,
2452
+ parentOrganizationId,
2453
+ parentProjectId,
2402
2454
  jsonArg(args.input),
2403
2455
  jsonArg(args.groundTruth),
2404
2456
  jsonArg(args.metadata),
@@ -2415,6 +2467,8 @@ var DatasetsMySQL = class _DatasetsMySQL extends DatasetsStorage {
2415
2467
  id,
2416
2468
  datasetId: args.datasetId,
2417
2469
  datasetVersion: newVersion,
2470
+ organizationId: parentOrganizationId,
2471
+ projectId: parentProjectId,
2418
2472
  input: args.input,
2419
2473
  groundTruth: args.groundTruth,
2420
2474
  metadata: args.metadata,
@@ -2469,21 +2523,26 @@ var DatasetsMySQL = class _DatasetsMySQL extends DatasetsStorage {
2469
2523
  await connection.execute(`UPDATE ${tableDatasetsName} SET \`version\` = \`version\` + 1 WHERE id = ?`, [
2470
2524
  args.datasetId
2471
2525
  ]);
2472
- const [versionRows] = await connection.execute(
2473
- `SELECT \`version\` FROM ${tableDatasetsName} WHERE id = ?`,
2526
+ const [datasetRows] = await connection.execute(
2527
+ `SELECT \`version\`, \`organizationId\`, \`projectId\` FROM ${tableDatasetsName} WHERE id = ?`,
2474
2528
  [args.datasetId]
2475
2529
  );
2476
- const newVersion = versionRows[0]?.version;
2530
+ const parentRow = datasetRows[0];
2531
+ const newVersion = parentRow?.version;
2532
+ const parentOrganizationId = parentRow?.organizationId ?? null;
2533
+ const parentProjectId = parentRow?.projectId ?? null;
2477
2534
  await connection.execute(
2478
2535
  `UPDATE ${tableItemsName} SET \`validTo\` = ? WHERE \`id\` = ? AND \`validTo\` IS NULL AND \`isDeleted\` = 0`,
2479
2536
  [newVersion, args.id]
2480
2537
  );
2481
2538
  await connection.execute(
2482
- `INSERT INTO ${tableItemsName} (\`id\`, \`datasetId\`, \`datasetVersion\`, \`validTo\`, \`isDeleted\`, \`input\`, \`groundTruth\`, \`metadata\`, \`createdAt\`, \`updatedAt\`) VALUES (?, ?, ?, NULL, 0, ?, ?, ?, ?, ?)`,
2539
+ `INSERT INTO ${tableItemsName} (\`id\`, \`datasetId\`, \`datasetVersion\`, \`organizationId\`, \`projectId\`, \`validTo\`, \`isDeleted\`, \`input\`, \`groundTruth\`, \`metadata\`, \`createdAt\`, \`updatedAt\`) VALUES (?, ?, ?, ?, ?, NULL, 0, ?, ?, ?, ?, ?)`,
2483
2540
  [
2484
2541
  args.id,
2485
2542
  args.datasetId,
2486
2543
  newVersion,
2544
+ parentOrganizationId,
2545
+ parentProjectId,
2487
2546
  jsonArg(mergedInput),
2488
2547
  jsonArg(mergedGroundTruth),
2489
2548
  jsonArg(mergedMetadata),
@@ -2499,6 +2558,8 @@ var DatasetsMySQL = class _DatasetsMySQL extends DatasetsStorage {
2499
2558
  return {
2500
2559
  ...existing,
2501
2560
  datasetVersion: newVersion,
2561
+ organizationId: parentOrganizationId,
2562
+ projectId: parentProjectId,
2502
2563
  input: mergedInput,
2503
2564
  groundTruth: mergedGroundTruth,
2504
2565
  metadata: mergedMetadata,
@@ -2541,21 +2602,26 @@ var DatasetsMySQL = class _DatasetsMySQL extends DatasetsStorage {
2541
2602
  await connection.execute(`UPDATE ${tableDatasetsName} SET \`version\` = \`version\` + 1 WHERE id = ?`, [
2542
2603
  datasetId
2543
2604
  ]);
2544
- const [versionRows] = await connection.execute(
2545
- `SELECT \`version\` FROM ${tableDatasetsName} WHERE id = ?`,
2605
+ const [datasetRows] = await connection.execute(
2606
+ `SELECT \`version\`, \`organizationId\`, \`projectId\` FROM ${tableDatasetsName} WHERE id = ?`,
2546
2607
  [datasetId]
2547
2608
  );
2548
- const newVersion = versionRows[0]?.version;
2609
+ const parentRow = datasetRows[0];
2610
+ const newVersion = parentRow?.version;
2611
+ const parentOrganizationId = parentRow?.organizationId ?? null;
2612
+ const parentProjectId = parentRow?.projectId ?? null;
2549
2613
  await connection.execute(
2550
2614
  `UPDATE ${tableItemsName} SET \`validTo\` = ? WHERE \`id\` = ? AND \`validTo\` IS NULL AND \`isDeleted\` = 0`,
2551
2615
  [newVersion, id]
2552
2616
  );
2553
2617
  await connection.execute(
2554
- `INSERT INTO ${tableItemsName} (\`id\`, \`datasetId\`, \`datasetVersion\`, \`validTo\`, \`isDeleted\`, \`input\`, \`groundTruth\`, \`metadata\`, \`createdAt\`, \`updatedAt\`) VALUES (?, ?, ?, NULL, 1, ?, ?, ?, ?, ?)`,
2618
+ `INSERT INTO ${tableItemsName} (\`id\`, \`datasetId\`, \`datasetVersion\`, \`organizationId\`, \`projectId\`, \`validTo\`, \`isDeleted\`, \`input\`, \`groundTruth\`, \`metadata\`, \`createdAt\`, \`updatedAt\`) VALUES (?, ?, ?, ?, ?, NULL, 1, ?, ?, ?, ?, ?)`,
2555
2619
  [
2556
2620
  id,
2557
2621
  datasetId,
2558
2622
  newVersion,
2623
+ parentOrganizationId,
2624
+ parentProjectId,
2559
2625
  jsonArg(existing.input),
2560
2626
  jsonArg(existing.groundTruth),
2561
2627
  jsonArg(existing.metadata),
@@ -2664,6 +2730,14 @@ var DatasetsMySQL = class _DatasetsMySQL extends DatasetsStorage {
2664
2730
  conditions.push(`\`validTo\` IS NULL`);
2665
2731
  conditions.push(`\`isDeleted\` = 0`);
2666
2732
  }
2733
+ if (args.filters?.organizationId !== void 0) {
2734
+ conditions.push(`\`organizationId\` = ?`);
2735
+ params.push(args.filters.organizationId);
2736
+ }
2737
+ if (args.filters?.projectId !== void 0) {
2738
+ conditions.push(`\`projectId\` = ?`);
2739
+ params.push(args.filters.projectId);
2740
+ }
2667
2741
  if (args.search) {
2668
2742
  conditions.push(`(LOWER(\`input\`) LIKE ? OR LOWER(COALESCE(\`groundTruth\`, '')) LIKE ?)`);
2669
2743
  const searchPattern = `%${args.search.toLowerCase()}%`;
@@ -2808,16 +2882,20 @@ var DatasetsMySQL = class _DatasetsMySQL extends DatasetsStorage {
2808
2882
  [input.datasetId]
2809
2883
  );
2810
2884
  const newVersion = versionRows[0]?.version;
2885
+ const parentOrganizationId = dataset.organizationId ?? null;
2886
+ const parentProjectId = dataset.projectId ?? null;
2811
2887
  const items = [];
2812
2888
  for (const itemInput of input.items) {
2813
2889
  const id = randomUUID();
2814
2890
  items.push({ id, itemInput });
2815
2891
  await connection.execute(
2816
- `INSERT INTO ${tableItemsName} (\`id\`, \`datasetId\`, \`datasetVersion\`, \`validTo\`, \`isDeleted\`, \`input\`, \`groundTruth\`, \`metadata\`, \`createdAt\`, \`updatedAt\`) VALUES (?, ?, ?, NULL, 0, ?, ?, ?, ?, ?)`,
2892
+ `INSERT INTO ${tableItemsName} (\`id\`, \`datasetId\`, \`datasetVersion\`, \`organizationId\`, \`projectId\`, \`validTo\`, \`isDeleted\`, \`input\`, \`groundTruth\`, \`metadata\`, \`createdAt\`, \`updatedAt\`) VALUES (?, ?, ?, ?, ?, NULL, 0, ?, ?, ?, ?, ?)`,
2817
2893
  [
2818
2894
  id,
2819
2895
  input.datasetId,
2820
2896
  newVersion,
2897
+ parentOrganizationId,
2898
+ parentProjectId,
2821
2899
  jsonArg(itemInput.input),
2822
2900
  jsonArg(itemInput.groundTruth),
2823
2901
  jsonArg(itemInput.metadata),
@@ -2835,6 +2913,8 @@ var DatasetsMySQL = class _DatasetsMySQL extends DatasetsStorage {
2835
2913
  id,
2836
2914
  datasetId: input.datasetId,
2837
2915
  datasetVersion: newVersion,
2916
+ organizationId: parentOrganizationId,
2917
+ projectId: parentProjectId,
2838
2918
  input: itemInput.input,
2839
2919
  groundTruth: itemInput.groundTruth,
2840
2920
  metadata: itemInput.metadata,
@@ -2890,17 +2970,21 @@ var DatasetsMySQL = class _DatasetsMySQL extends DatasetsStorage {
2890
2970
  [input.datasetId]
2891
2971
  );
2892
2972
  const newVersion = versionRows[0]?.version;
2973
+ const parentOrganizationId = dataset.organizationId ?? null;
2974
+ const parentProjectId = dataset.projectId ?? null;
2893
2975
  for (const item of currentItems) {
2894
2976
  await connection.execute(
2895
2977
  `UPDATE ${tableItemsName} SET \`validTo\` = ? WHERE \`id\` = ? AND \`validTo\` IS NULL AND \`isDeleted\` = 0`,
2896
2978
  [newVersion, item.id]
2897
2979
  );
2898
2980
  await connection.execute(
2899
- `INSERT INTO ${tableItemsName} (\`id\`, \`datasetId\`, \`datasetVersion\`, \`validTo\`, \`isDeleted\`, \`input\`, \`groundTruth\`, \`metadata\`, \`createdAt\`, \`updatedAt\`) VALUES (?, ?, ?, NULL, 1, ?, ?, ?, ?, ?)`,
2981
+ `INSERT INTO ${tableItemsName} (\`id\`, \`datasetId\`, \`datasetVersion\`, \`organizationId\`, \`projectId\`, \`validTo\`, \`isDeleted\`, \`input\`, \`groundTruth\`, \`metadata\`, \`createdAt\`, \`updatedAt\`) VALUES (?, ?, ?, ?, ?, NULL, 1, ?, ?, ?, ?, ?)`,
2900
2982
  [
2901
2983
  item.id,
2902
2984
  input.datasetId,
2903
2985
  newVersion,
2986
+ parentOrganizationId,
2987
+ parentProjectId,
2904
2988
  jsonArg(item.input),
2905
2989
  jsonArg(item.groundTruth),
2906
2990
  jsonArg(item.metadata),
@@ -2952,10 +3036,22 @@ var ExperimentsMySQL = class _ExperimentsMySQL extends ExperimentsStorage {
2952
3036
  static MANAGED_TABLES = [TABLE_EXPERIMENTS, TABLE_EXPERIMENT_RESULTS];
2953
3037
  /**
2954
3038
  * Returns default index definitions for the experiments domain tables.
2955
- * Currently no default indexes are defined for experiments.
2956
3039
  */
2957
3040
  static getDefaultIndexDefs(_prefix = "") {
2958
- return [];
3041
+ return [
3042
+ // Tenancy: leading-tenant indexes for multi-tenant scans (parity with
3043
+ // pg/libsql/spanner/mongodb experiments adapters).
3044
+ {
3045
+ name: "idx_experiments_org_project",
3046
+ table: TABLE_EXPERIMENTS,
3047
+ columns: ["organizationId", "projectId"]
3048
+ },
3049
+ {
3050
+ name: "idx_experiment_results_org_project",
3051
+ table: TABLE_EXPERIMENT_RESULTS,
3052
+ columns: ["organizationId", "projectId"]
3053
+ }
3054
+ ];
2959
3055
  }
2960
3056
  /**
2961
3057
  * Exports DDL statements for all managed tables.
@@ -2986,10 +3082,12 @@ var ExperimentsMySQL = class _ExperimentsMySQL extends ExperimentsStorage {
2986
3082
  }
2987
3083
  /**
2988
3084
  * Creates default indexes for optimal query performance.
2989
- * Currently no default indexes are defined for experiments.
2990
3085
  */
2991
3086
  async createDefaultIndexes() {
2992
3087
  if (this.#skipDefaultIndexes) return;
3088
+ for (const indexDef of this.getDefaultIndexDefinitions()) {
3089
+ await this.operations.createIndex(indexDef);
3090
+ }
2993
3091
  }
2994
3092
  /**
2995
3093
  * Creates custom user-defined indexes for this domain's tables.
@@ -3003,6 +3101,16 @@ var ExperimentsMySQL = class _ExperimentsMySQL extends ExperimentsStorage {
3003
3101
  async init() {
3004
3102
  await this.operations.createTable({ tableName: TABLE_EXPERIMENTS, schema: EXPERIMENTS_SCHEMA });
3005
3103
  await this.operations.createTable({ tableName: TABLE_EXPERIMENT_RESULTS, schema: EXPERIMENT_RESULTS_SCHEMA });
3104
+ await this.operations.alterTable({
3105
+ tableName: TABLE_EXPERIMENTS,
3106
+ schema: EXPERIMENTS_SCHEMA,
3107
+ ifNotExists: ["organizationId", "projectId"]
3108
+ });
3109
+ await this.operations.alterTable({
3110
+ tableName: TABLE_EXPERIMENT_RESULTS,
3111
+ schema: EXPERIMENT_RESULTS_SCHEMA,
3112
+ ifNotExists: ["organizationId", "projectId"]
3113
+ });
3006
3114
  await this.createDefaultIndexes();
3007
3115
  await this.createCustomIndexes();
3008
3116
  }
@@ -3015,6 +3123,8 @@ var ExperimentsMySQL = class _ExperimentsMySQL extends ExperimentsStorage {
3015
3123
  id: row.id,
3016
3124
  datasetId: row.datasetId ?? null,
3017
3125
  datasetVersion: row.datasetVersion ?? null,
3126
+ organizationId: row.organizationId ?? null,
3127
+ projectId: row.projectId ?? null,
3018
3128
  targetType: row.targetType,
3019
3129
  targetId: row.targetId,
3020
3130
  name: row.name ?? void 0,
@@ -3037,6 +3147,8 @@ var ExperimentsMySQL = class _ExperimentsMySQL extends ExperimentsStorage {
3037
3147
  experimentId: row.experimentId,
3038
3148
  itemId: row.itemId,
3039
3149
  itemDatasetVersion: row.itemDatasetVersion ?? null,
3150
+ organizationId: row.organizationId ?? null,
3151
+ projectId: row.projectId ?? null,
3040
3152
  input: parseJSON2(row.input),
3041
3153
  output: row.output ? parseJSON2(row.output) : null,
3042
3154
  groundTruth: row.groundTruth ? parseJSON2(row.groundTruth) : null,
@@ -3060,6 +3172,8 @@ var ExperimentsMySQL = class _ExperimentsMySQL extends ExperimentsStorage {
3060
3172
  id,
3061
3173
  datasetId: input.datasetId ?? null,
3062
3174
  datasetVersion: input.datasetVersion ?? null,
3175
+ organizationId: input.organizationId ?? null,
3176
+ projectId: input.projectId ?? null,
3063
3177
  targetType: input.targetType,
3064
3178
  targetId: input.targetId,
3065
3179
  name: input.name ?? null,
@@ -3080,6 +3194,8 @@ var ExperimentsMySQL = class _ExperimentsMySQL extends ExperimentsStorage {
3080
3194
  id,
3081
3195
  datasetId: input.datasetId,
3082
3196
  datasetVersion: input.datasetVersion,
3197
+ organizationId: input.organizationId ?? null,
3198
+ projectId: input.projectId ?? null,
3083
3199
  targetType: input.targetType,
3084
3200
  targetId: input.targetId,
3085
3201
  name: input.name,
@@ -3174,6 +3290,17 @@ var ExperimentsMySQL = class _ExperimentsMySQL extends ExperimentsStorage {
3174
3290
  conditions.push(`${quoteIdentifier("datasetId", "column name")} = ?`);
3175
3291
  params.push(args.datasetId);
3176
3292
  }
3293
+ if (args.filters) {
3294
+ const { organizationId, projectId } = args.filters;
3295
+ if (organizationId !== void 0) {
3296
+ conditions.push(`${quoteIdentifier("organizationId", "column name")} = ?`);
3297
+ params.push(organizationId);
3298
+ }
3299
+ if (projectId !== void 0) {
3300
+ conditions.push(`${quoteIdentifier("projectId", "column name")} = ?`);
3301
+ params.push(projectId);
3302
+ }
3303
+ }
3177
3304
  const whereClause = {
3178
3305
  sql: conditions.length > 0 ? ` WHERE ${conditions.join(" AND ")}` : "",
3179
3306
  args: params
@@ -3277,6 +3404,8 @@ var ExperimentsMySQL = class _ExperimentsMySQL extends ExperimentsStorage {
3277
3404
  experimentId: input.experimentId,
3278
3405
  itemId: input.itemId,
3279
3406
  itemDatasetVersion: input.itemDatasetVersion ?? null,
3407
+ organizationId: input.organizationId ?? null,
3408
+ projectId: input.projectId ?? null,
3280
3409
  input: JSON.stringify(input.input),
3281
3410
  output: input.output ? JSON.stringify(input.output) : null,
3282
3411
  groundTruth: input.groundTruth ? JSON.stringify(input.groundTruth) : null,
@@ -3295,6 +3424,8 @@ var ExperimentsMySQL = class _ExperimentsMySQL extends ExperimentsStorage {
3295
3424
  experimentId: input.experimentId,
3296
3425
  itemId: input.itemId,
3297
3426
  itemDatasetVersion: input.itemDatasetVersion,
3427
+ organizationId: input.organizationId ?? null,
3428
+ projectId: input.projectId ?? null,
3298
3429
  input: input.input,
3299
3430
  output: input.output,
3300
3431
  groundTruth: input.groundTruth,
@@ -3412,9 +3543,30 @@ var ExperimentsMySQL = class _ExperimentsMySQL extends ExperimentsStorage {
3412
3543
  async listExperimentResults(args) {
3413
3544
  try {
3414
3545
  const { page, perPage: perPageInput } = args.pagination;
3546
+ const conditions = [`${quoteIdentifier("experimentId", "column name")} = ?`];
3547
+ const params = [args.experimentId];
3548
+ if (args.traceId) {
3549
+ conditions.push(`${quoteIdentifier("traceId", "column name")} = ?`);
3550
+ params.push(args.traceId);
3551
+ }
3552
+ if (args.status) {
3553
+ conditions.push(`${quoteIdentifier("status", "column name")} = ?`);
3554
+ params.push(args.status);
3555
+ }
3556
+ if (args.filters) {
3557
+ const { organizationId, projectId } = args.filters;
3558
+ if (organizationId !== void 0) {
3559
+ conditions.push(`${quoteIdentifier("organizationId", "column name")} = ?`);
3560
+ params.push(organizationId);
3561
+ }
3562
+ if (projectId !== void 0) {
3563
+ conditions.push(`${quoteIdentifier("projectId", "column name")} = ?`);
3564
+ params.push(projectId);
3565
+ }
3566
+ }
3415
3567
  const whereClause = {
3416
- sql: ` WHERE ${quoteIdentifier("experimentId", "column name")} = ?`,
3417
- args: [args.experimentId]
3568
+ sql: ` WHERE ${conditions.join(" AND ")}`,
3569
+ args: params
3418
3570
  };
3419
3571
  const total = await this.operations.loadTotalCount({ tableName: TABLE_EXPERIMENT_RESULTS, whereClause });
3420
3572
  if (total === 0) {