'use strict';

var chunkKTKTSTDR_cjs = require('./chunk-KTKTSTDR.cjs');
var chunkZYXDUS6Q_cjs = require('./chunk-ZYXDUS6Q.cjs');
var chunkY2BKW5ND_cjs = require('./chunk-Y2BKW5ND.cjs');
var chunk6P7P7Y5U_cjs = require('./chunk-6P7P7Y5U.cjs');
var chunk64ITUOXI_cjs = require('./chunk-64ITUOXI.cjs');
var error = require('@mastra/core/error');
var features = require('@mastra/core/features');

function assertDatasetsAvailable() {
  if (!features.coreFeatures.has("datasets")) {
    throw new chunk64ITUOXI_cjs.HTTPException(501, { message: "Datasets require @mastra/core >= 1.4.0" });
  }
}
function isSchemaValidationError(error) {
  return error instanceof Error && error.name === "SchemaValidationError";
}
function isSchemaUpdateValidationError(error) {
  return error instanceof Error && error.name === "SchemaUpdateValidationError";
}
function getHttpStatusForMastraError(errorId) {
  switch (errorId) {
    case "DATASET_NOT_FOUND":
    case "EXPERIMENT_NOT_FOUND":
      return 404;
    case "EXPERIMENT_NO_ITEMS":
      return 400;
    default:
      return 500;
  }
}
var LIST_DATASETS_ROUTE = chunk6P7P7Y5U_cjs.createRoute({
  method: "GET",
  path: "/datasets",
  responseType: "json",
  queryParamSchema: chunkKTKTSTDR_cjs.paginationQuerySchema,
  responseSchema: chunkKTKTSTDR_cjs.listDatasetsResponseSchema,
  summary: "List all datasets",
  description: "Returns a paginated list of all datasets",
  tags: ["Datasets"],
  requiresAuth: true,
  handler: async ({ mastra, ...params }) => {
    assertDatasetsAvailable();
    try {
      const { page, perPage } = params;
      const result = await mastra.datasets.list({ page: page ?? 0, perPage: perPage ?? 10 });
      return {
        datasets: result.datasets,
        pagination: result.pagination
      };
    } catch (error$1) {
      if (error$1 instanceof error.MastraError) {
        throw new chunk64ITUOXI_cjs.HTTPException(getHttpStatusForMastraError(error$1.id), { message: error$1.message });
      }
      return chunkY2BKW5ND_cjs.handleError(error$1, "Error listing datasets");
    }
  }
});
var CREATE_DATASET_ROUTE = chunk6P7P7Y5U_cjs.createRoute({
  method: "POST",
  path: "/datasets",
  responseType: "json",
  bodySchema: chunkKTKTSTDR_cjs.createDatasetBodySchema,
  responseSchema: chunkKTKTSTDR_cjs.datasetResponseSchema,
  summary: "Create a new dataset",
  description: "Creates a new dataset with the specified name and optional metadata",
  tags: ["Datasets"],
  requiresAuth: true,
  handler: async ({ mastra, ...params }) => {
    assertDatasetsAvailable();
    try {
      const { name, description, metadata, inputSchema, groundTruthSchema, requestContextSchema } = params;
      const ds = await mastra.datasets.create({
        name,
        description,
        metadata,
        inputSchema,
        groundTruthSchema,
        requestContextSchema
      });
      const details = await ds.getDetails();
      return details;
    } catch (error$1) {
      if (error$1 instanceof error.MastraError) {
        throw new chunk64ITUOXI_cjs.HTTPException(getHttpStatusForMastraError(error$1.id), { message: error$1.message });
      }
      return chunkY2BKW5ND_cjs.handleError(error$1, "Error creating dataset");
    }
  }
});
var GET_DATASET_ROUTE = chunk6P7P7Y5U_cjs.createRoute({
  method: "GET",
  path: "/datasets/:datasetId",
  responseType: "json",
  pathParamSchema: chunkKTKTSTDR_cjs.datasetIdPathParams,
  responseSchema: chunkKTKTSTDR_cjs.datasetResponseSchema.nullable(),
  summary: "Get dataset by ID",
  description: "Returns details for a specific dataset",
  tags: ["Datasets"],
  requiresAuth: true,
  handler: async ({ mastra, datasetId }) => {
    assertDatasetsAvailable();
    try {
      const ds = await mastra.datasets.get({ id: datasetId });
      return await ds.getDetails();
    } catch (error$1) {
      if (error$1 instanceof error.MastraError) {
        throw new chunk64ITUOXI_cjs.HTTPException(getHttpStatusForMastraError(error$1.id), { message: error$1.message });
      }
      return chunkY2BKW5ND_cjs.handleError(error$1, "Error getting dataset");
    }
  }
});
var UPDATE_DATASET_ROUTE = chunk6P7P7Y5U_cjs.createRoute({
  method: "PATCH",
  path: "/datasets/:datasetId",
  responseType: "json",
  pathParamSchema: chunkKTKTSTDR_cjs.datasetIdPathParams,
  bodySchema: chunkKTKTSTDR_cjs.updateDatasetBodySchema,
  responseSchema: chunkKTKTSTDR_cjs.datasetResponseSchema,
  summary: "Update dataset",
  description: "Updates a dataset with the specified fields",
  tags: ["Datasets"],
  requiresAuth: true,
  handler: async ({ mastra, datasetId, ...params }) => {
    assertDatasetsAvailable();
    try {
      const { name, description, metadata, inputSchema, groundTruthSchema, requestContextSchema } = params;
      const ds = await mastra.datasets.get({ id: datasetId });
      const result = await ds.update({
        name,
        description,
        metadata,
        inputSchema,
        groundTruthSchema,
        requestContextSchema
      });
      return result;
    } catch (error$1) {
      if (isSchemaUpdateValidationError(error$1)) {
        throw new chunk64ITUOXI_cjs.HTTPException(400, {
          message: error$1.message,
          cause: { failingItems: error$1.failingItems }
        });
      }
      if (isSchemaValidationError(error$1)) {
        throw new chunk64ITUOXI_cjs.HTTPException(400, {
          message: error$1.message,
          cause: { field: error$1.field, errors: error$1.errors }
        });
      }
      if (error$1 instanceof error.MastraError) {
        throw new chunk64ITUOXI_cjs.HTTPException(getHttpStatusForMastraError(error$1.id), { message: error$1.message });
      }
      return chunkY2BKW5ND_cjs.handleError(error$1, "Error updating dataset");
    }
  }
});
var DELETE_DATASET_ROUTE = chunk6P7P7Y5U_cjs.createRoute({
  method: "DELETE",
  path: "/datasets/:datasetId",
  responseType: "json",
  pathParamSchema: chunkKTKTSTDR_cjs.datasetIdPathParams,
  responseSchema: chunkZYXDUS6Q_cjs.successResponseSchema,
  summary: "Delete dataset",
  description: "Deletes a dataset and all its items",
  tags: ["Datasets"],
  requiresAuth: true,
  handler: async ({ mastra, datasetId }) => {
    assertDatasetsAvailable();
    try {
      await mastra.datasets.get({ id: datasetId });
      await mastra.datasets.delete({ id: datasetId });
      return { success: true };
    } catch (error$1) {
      if (error$1 instanceof error.MastraError) {
        throw new chunk64ITUOXI_cjs.HTTPException(getHttpStatusForMastraError(error$1.id), { message: error$1.message });
      }
      return chunkY2BKW5ND_cjs.handleError(error$1, "Error deleting dataset");
    }
  }
});
var LIST_ITEMS_ROUTE = chunk6P7P7Y5U_cjs.createRoute({
  method: "GET",
  path: "/datasets/:datasetId/items",
  responseType: "json",
  pathParamSchema: chunkKTKTSTDR_cjs.datasetIdPathParams,
  queryParamSchema: chunkKTKTSTDR_cjs.listItemsQuerySchema,
  responseSchema: chunkKTKTSTDR_cjs.listItemsResponseSchema,
  summary: "List dataset items",
  description: "Returns a paginated list of items in the dataset",
  tags: ["Datasets"],
  requiresAuth: true,
  handler: async ({ mastra, datasetId, ...params }) => {
    assertDatasetsAvailable();
    try {
      const { page, perPage, version, search } = params;
      const ds = await mastra.datasets.get({ id: datasetId });
      const result = await ds.listItems({
        page: page ?? 0,
        perPage: perPage ?? 10,
        version,
        search
      });
      if (Array.isArray(result)) {
        return { items: result, pagination: { total: result.length, page: 0, perPage: result.length, hasMore: false } };
      }
      return { items: result.items, pagination: result.pagination };
    } catch (error$1) {
      if (error$1 instanceof error.MastraError) {
        throw new chunk64ITUOXI_cjs.HTTPException(getHttpStatusForMastraError(error$1.id), { message: error$1.message });
      }
      return chunkY2BKW5ND_cjs.handleError(error$1, "Error listing dataset items");
    }
  }
});
var ADD_ITEM_ROUTE = chunk6P7P7Y5U_cjs.createRoute({
  method: "POST",
  path: "/datasets/:datasetId/items",
  responseType: "json",
  pathParamSchema: chunkKTKTSTDR_cjs.datasetIdPathParams,
  bodySchema: chunkKTKTSTDR_cjs.addItemBodySchema,
  responseSchema: chunkKTKTSTDR_cjs.datasetItemResponseSchema,
  summary: "Add item to dataset",
  description: "Adds a new item to the dataset (auto-increments dataset version)",
  tags: ["Datasets"],
  requiresAuth: true,
  handler: async ({ mastra, datasetId, ...params }) => {
    assertDatasetsAvailable();
    try {
      const { input, groundTruth, requestContext, metadata } = params;
      const ds = await mastra.datasets.get({ id: datasetId });
      return await ds.addItem({ input, groundTruth, requestContext, metadata });
    } catch (error$1) {
      if (isSchemaValidationError(error$1)) {
        throw new chunk64ITUOXI_cjs.HTTPException(400, {
          message: error$1.message,
          cause: { field: error$1.field, errors: error$1.errors }
        });
      }
      if (error$1 instanceof error.MastraError) {
        throw new chunk64ITUOXI_cjs.HTTPException(getHttpStatusForMastraError(error$1.id), { message: error$1.message });
      }
      return chunkY2BKW5ND_cjs.handleError(error$1, "Error adding item to dataset");
    }
  }
});
var GET_ITEM_ROUTE = chunk6P7P7Y5U_cjs.createRoute({
  method: "GET",
  path: "/datasets/:datasetId/items/:itemId",
  responseType: "json",
  pathParamSchema: chunkKTKTSTDR_cjs.datasetAndItemIdPathParams,
  responseSchema: chunkKTKTSTDR_cjs.datasetItemResponseSchema.nullable(),
  summary: "Get dataset item by ID",
  description: "Returns details for a specific dataset item",
  tags: ["Datasets"],
  requiresAuth: true,
  handler: async ({ mastra, datasetId, itemId }) => {
    assertDatasetsAvailable();
    try {
      const ds = await mastra.datasets.get({ id: datasetId });
      const item = await ds.getItem({ itemId });
      if (!item || item.datasetId !== datasetId) {
        throw new chunk64ITUOXI_cjs.HTTPException(404, { message: `Item not found: ${itemId}` });
      }
      return item;
    } catch (error$1) {
      if (error$1 instanceof error.MastraError) {
        throw new chunk64ITUOXI_cjs.HTTPException(getHttpStatusForMastraError(error$1.id), { message: error$1.message });
      }
      return chunkY2BKW5ND_cjs.handleError(error$1, "Error getting dataset item");
    }
  }
});
var UPDATE_ITEM_ROUTE = chunk6P7P7Y5U_cjs.createRoute({
  method: "PATCH",
  path: "/datasets/:datasetId/items/:itemId",
  responseType: "json",
  pathParamSchema: chunkKTKTSTDR_cjs.datasetAndItemIdPathParams,
  bodySchema: chunkKTKTSTDR_cjs.updateItemBodySchema,
  responseSchema: chunkKTKTSTDR_cjs.datasetItemResponseSchema,
  summary: "Update dataset item",
  description: "Updates a dataset item (auto-increments dataset version)",
  tags: ["Datasets"],
  requiresAuth: true,
  handler: async ({ mastra, datasetId, itemId, ...params }) => {
    assertDatasetsAvailable();
    try {
      const { input, groundTruth, requestContext, metadata } = params;
      const ds = await mastra.datasets.get({ id: datasetId });
      const existing = await ds.getItem({ itemId });
      if (!existing || existing.datasetId !== datasetId) {
        throw new chunk64ITUOXI_cjs.HTTPException(404, { message: `Item not found: ${itemId}` });
      }
      return await ds.updateItem({ itemId, input, groundTruth, requestContext, metadata });
    } catch (error$1) {
      if (isSchemaValidationError(error$1)) {
        throw new chunk64ITUOXI_cjs.HTTPException(400, {
          message: error$1.message,
          cause: { field: error$1.field, errors: error$1.errors }
        });
      }
      if (error$1 instanceof error.MastraError) {
        throw new chunk64ITUOXI_cjs.HTTPException(getHttpStatusForMastraError(error$1.id), { message: error$1.message });
      }
      return chunkY2BKW5ND_cjs.handleError(error$1, "Error updating dataset item");
    }
  }
});
var DELETE_ITEM_ROUTE = chunk6P7P7Y5U_cjs.createRoute({
  method: "DELETE",
  path: "/datasets/:datasetId/items/:itemId",
  responseType: "json",
  pathParamSchema: chunkKTKTSTDR_cjs.datasetAndItemIdPathParams,
  responseSchema: chunkZYXDUS6Q_cjs.successResponseSchema,
  summary: "Delete dataset item",
  description: "Deletes a dataset item",
  tags: ["Datasets"],
  requiresAuth: true,
  handler: async ({ mastra, datasetId, itemId }) => {
    assertDatasetsAvailable();
    try {
      const ds = await mastra.datasets.get({ id: datasetId });
      const existing = await ds.getItem({ itemId });
      if (!existing || existing.datasetId !== datasetId) {
        throw new chunk64ITUOXI_cjs.HTTPException(404, { message: `Item not found: ${itemId}` });
      }
      await ds.deleteItem({ itemId });
      return { success: true };
    } catch (error$1) {
      if (error$1 instanceof error.MastraError) {
        throw new chunk64ITUOXI_cjs.HTTPException(getHttpStatusForMastraError(error$1.id), { message: error$1.message });
      }
      return chunkY2BKW5ND_cjs.handleError(error$1, "Error deleting dataset item");
    }
  }
});
var LIST_EXPERIMENTS_ROUTE = chunk6P7P7Y5U_cjs.createRoute({
  method: "GET",
  path: "/datasets/:datasetId/experiments",
  responseType: "json",
  pathParamSchema: chunkKTKTSTDR_cjs.datasetIdPathParams,
  queryParamSchema: chunkKTKTSTDR_cjs.paginationQuerySchema,
  responseSchema: chunkKTKTSTDR_cjs.listExperimentsResponseSchema,
  summary: "List experiments for dataset",
  description: "Returns a paginated list of experiments for the dataset",
  tags: ["Datasets"],
  requiresAuth: true,
  handler: async ({ mastra, datasetId, ...params }) => {
    assertDatasetsAvailable();
    try {
      const { page, perPage } = params;
      const ds = await mastra.datasets.get({ id: datasetId });
      const result = await ds.listExperiments({ page: page ?? 0, perPage: perPage ?? 10 });
      return { experiments: result.experiments, pagination: result.pagination };
    } catch (error$1) {
      if (error$1 instanceof error.MastraError) {
        throw new chunk64ITUOXI_cjs.HTTPException(getHttpStatusForMastraError(error$1.id), { message: error$1.message });
      }
      return chunkY2BKW5ND_cjs.handleError(error$1, "Error listing experiments");
    }
  }
});
var TRIGGER_EXPERIMENT_ROUTE = chunk6P7P7Y5U_cjs.createRoute({
  method: "POST",
  path: "/datasets/:datasetId/experiments",
  responseType: "json",
  pathParamSchema: chunkKTKTSTDR_cjs.datasetIdPathParams,
  bodySchema: chunkKTKTSTDR_cjs.triggerExperimentBodySchema,
  responseSchema: chunkKTKTSTDR_cjs.experimentSummaryResponseSchema,
  summary: "Trigger a new experiment",
  description: "Triggers a new experiment on the dataset against the specified target. Returns immediately with pending status; execution happens in background.",
  tags: ["Datasets"],
  requiresAuth: true,
  handler: async ({ mastra, datasetId, ...params }) => {
    assertDatasetsAvailable();
    try {
      const { targetType, targetId, scorerIds, version, maxConcurrency, requestContext } = params;
      const ds = await mastra.datasets.get({ id: datasetId });
      const result = await ds.startExperimentAsync({
        targetType,
        targetId,
        scorers: scorerIds,
        version,
        maxConcurrency,
        requestContext
      });
      return {
        experimentId: result.experimentId,
        status: result.status,
        totalItems: result.totalItems ?? 0,
        succeededCount: 0,
        failedCount: 0,
        startedAt: /* @__PURE__ */ new Date(),
        completedAt: null,
        results: []
      };
    } catch (error$1) {
      if (error$1 instanceof error.MastraError) {
        throw new chunk64ITUOXI_cjs.HTTPException(getHttpStatusForMastraError(error$1.id), { message: error$1.message });
      }
      return chunkY2BKW5ND_cjs.handleError(error$1, "Error triggering experiment");
    }
  }
});
var GET_EXPERIMENT_ROUTE = chunk6P7P7Y5U_cjs.createRoute({
  method: "GET",
  path: "/datasets/:datasetId/experiments/:experimentId",
  responseType: "json",
  pathParamSchema: chunkKTKTSTDR_cjs.datasetAndExperimentIdPathParams,
  responseSchema: chunkKTKTSTDR_cjs.experimentResponseSchema.nullable(),
  summary: "Get experiment by ID",
  description: "Returns details for a specific experiment",
  tags: ["Datasets"],
  requiresAuth: true,
  handler: async ({ mastra, datasetId, experimentId }) => {
    assertDatasetsAvailable();
    try {
      const ds = await mastra.datasets.get({ id: datasetId });
      const run = await ds.getExperiment({ experimentId });
      if (!run || run.datasetId !== datasetId) {
        throw new chunk64ITUOXI_cjs.HTTPException(404, { message: `Experiment not found: ${experimentId}` });
      }
      return run;
    } catch (error$1) {
      if (error$1 instanceof error.MastraError) {
        throw new chunk64ITUOXI_cjs.HTTPException(getHttpStatusForMastraError(error$1.id), { message: error$1.message });
      }
      return chunkY2BKW5ND_cjs.handleError(error$1, "Error getting experiment");
    }
  }
});
var LIST_EXPERIMENT_RESULTS_ROUTE = chunk6P7P7Y5U_cjs.createRoute({
  method: "GET",
  path: "/datasets/:datasetId/experiments/:experimentId/results",
  responseType: "json",
  pathParamSchema: chunkKTKTSTDR_cjs.datasetAndExperimentIdPathParams,
  queryParamSchema: chunkKTKTSTDR_cjs.paginationQuerySchema,
  responseSchema: chunkKTKTSTDR_cjs.listExperimentResultsResponseSchema,
  summary: "List experiment results",
  description: "Returns a paginated list of results for the experiment",
  tags: ["Datasets"],
  requiresAuth: true,
  handler: async ({ mastra, datasetId, experimentId, ...params }) => {
    assertDatasetsAvailable();
    try {
      const { page, perPage } = params;
      const ds = await mastra.datasets.get({ id: datasetId });
      const run = await ds.getExperiment({ experimentId });
      if (!run || run.datasetId !== datasetId) {
        throw new chunk64ITUOXI_cjs.HTTPException(404, { message: `Experiment not found: ${experimentId}` });
      }
      const result = await ds.listExperimentResults({ experimentId, page: page ?? 0, perPage: perPage ?? 10 });
      return {
        results: result.results.map(({ experimentId: _eid, ...rest }) => ({ experimentId, ...rest })),
        pagination: result.pagination
      };
    } catch (error$1) {
      if (error$1 instanceof error.MastraError) {
        throw new chunk64ITUOXI_cjs.HTTPException(getHttpStatusForMastraError(error$1.id), { message: error$1.message });
      }
      return chunkY2BKW5ND_cjs.handleError(error$1, "Error listing experiment results");
    }
  }
});
var COMPARE_EXPERIMENTS_ROUTE = chunk6P7P7Y5U_cjs.createRoute({
  method: "POST",
  path: "/datasets/:datasetId/compare",
  responseType: "json",
  pathParamSchema: chunkKTKTSTDR_cjs.datasetIdPathParams,
  bodySchema: chunkKTKTSTDR_cjs.compareExperimentsBodySchema,
  responseSchema: chunkKTKTSTDR_cjs.comparisonResponseSchema,
  summary: "Compare two experiments",
  description: "Compares two experiments to detect score regressions",
  tags: ["Datasets"],
  requiresAuth: true,
  handler: async ({ mastra, datasetId, ...params }) => {
    assertDatasetsAvailable();
    try {
      const { experimentIdA, experimentIdB } = params;
      await mastra.datasets.get({ id: datasetId });
      const result = await mastra.datasets.compareExperiments({
        experimentIds: [experimentIdA, experimentIdB],
        baselineId: experimentIdA
      });
      return result;
    } catch (error$1) {
      if (error$1 instanceof error.MastraError) {
        throw new chunk64ITUOXI_cjs.HTTPException(getHttpStatusForMastraError(error$1.id), { message: error$1.message });
      }
      return chunkY2BKW5ND_cjs.handleError(error$1, "Error comparing experiments");
    }
  }
});
var LIST_DATASET_VERSIONS_ROUTE = chunk6P7P7Y5U_cjs.createRoute({
  method: "GET",
  path: "/datasets/:datasetId/versions",
  responseType: "json",
  pathParamSchema: chunkKTKTSTDR_cjs.datasetIdPathParams,
  queryParamSchema: chunkKTKTSTDR_cjs.paginationQuerySchema,
  responseSchema: chunkKTKTSTDR_cjs.listDatasetVersionsResponseSchema,
  summary: "List dataset versions",
  description: "Returns a paginated list of all versions for the dataset",
  tags: ["Datasets"],
  requiresAuth: true,
  handler: async ({ mastra, datasetId, ...params }) => {
    assertDatasetsAvailable();
    try {
      const { page, perPage } = params;
      const ds = await mastra.datasets.get({ id: datasetId });
      const result = await ds.listVersions({ page: page ?? 0, perPage: perPage ?? 10 });
      return { versions: result.versions, pagination: result.pagination };
    } catch (error$1) {
      if (error$1 instanceof error.MastraError) {
        throw new chunk64ITUOXI_cjs.HTTPException(getHttpStatusForMastraError(error$1.id), { message: error$1.message });
      }
      return chunkY2BKW5ND_cjs.handleError(error$1, "Error listing dataset versions");
    }
  }
});
var LIST_ITEM_VERSIONS_ROUTE = chunk6P7P7Y5U_cjs.createRoute({
  method: "GET",
  path: "/datasets/:datasetId/items/:itemId/history",
  responseType: "json",
  pathParamSchema: chunkKTKTSTDR_cjs.datasetAndItemIdPathParams,
  responseSchema: chunkKTKTSTDR_cjs.listItemVersionsResponseSchema,
  summary: "Get item history",
  description: "Returns the full SCD-2 history of the item across all dataset versions",
  tags: ["Datasets"],
  requiresAuth: true,
  handler: async ({ mastra, datasetId, itemId }) => {
    assertDatasetsAvailable();
    try {
      const ds = await mastra.datasets.get({ id: datasetId });
      const rows = await ds.getItemHistory({ itemId });
      if (rows.length > 0 && rows[0]?.datasetId !== datasetId) {
        throw new chunk64ITUOXI_cjs.HTTPException(404, { message: `Item not found in dataset: ${itemId}` });
      }
      return { history: rows };
    } catch (error$1) {
      if (error$1 instanceof error.MastraError) {
        throw new chunk64ITUOXI_cjs.HTTPException(getHttpStatusForMastraError(error$1.id), { message: error$1.message });
      }
      return chunkY2BKW5ND_cjs.handleError(error$1, "Error listing item history");
    }
  }
});
var GET_ITEM_VERSION_ROUTE = chunk6P7P7Y5U_cjs.createRoute({
  method: "GET",
  path: "/datasets/:datasetId/items/:itemId/versions/:datasetVersion",
  responseType: "json",
  pathParamSchema: chunkKTKTSTDR_cjs.datasetItemVersionPathParams,
  responseSchema: chunkKTKTSTDR_cjs.datasetItemResponseSchema.nullable(),
  summary: "Get item at specific dataset version",
  description: "Returns the item as it existed at a specific dataset version",
  tags: ["Datasets"],
  requiresAuth: true,
  handler: async ({ mastra, datasetId, itemId, datasetVersion }) => {
    assertDatasetsAvailable();
    try {
      const ds = await mastra.datasets.get({ id: datasetId });
      const item = await ds.getItem({ itemId, version: datasetVersion });
      if (!item) {
        throw new chunk64ITUOXI_cjs.HTTPException(404, { message: `Item ${itemId} not found at version ${datasetVersion}` });
      }
      if (item.datasetId !== datasetId) {
        throw new chunk64ITUOXI_cjs.HTTPException(404, { message: `Item not found in dataset: ${itemId}` });
      }
      return item;
    } catch (error$1) {
      if (error$1 instanceof error.MastraError) {
        throw new chunk64ITUOXI_cjs.HTTPException(getHttpStatusForMastraError(error$1.id), { message: error$1.message });
      }
      return chunkY2BKW5ND_cjs.handleError(error$1, "Error getting item version");
    }
  }
});
var BATCH_INSERT_ITEMS_ROUTE = chunk6P7P7Y5U_cjs.createRoute({
  method: "POST",
  path: "/datasets/:datasetId/items/batch",
  responseType: "json",
  pathParamSchema: chunkKTKTSTDR_cjs.datasetIdPathParams,
  bodySchema: chunkKTKTSTDR_cjs.batchInsertItemsBodySchema,
  responseSchema: chunkKTKTSTDR_cjs.batchInsertItemsResponseSchema,
  summary: "Batch insert items to dataset",
  description: "Adds multiple items to the dataset in a single operation (single version entry)",
  tags: ["Datasets"],
  requiresAuth: true,
  handler: async ({ mastra, datasetId, ...params }) => {
    assertDatasetsAvailable();
    try {
      const { items } = params;
      const ds = await mastra.datasets.get({ id: datasetId });
      const addedItems = await ds.addItems({ items });
      return { items: addedItems, count: addedItems.length };
    } catch (error$1) {
      if (isSchemaValidationError(error$1)) {
        throw new chunk64ITUOXI_cjs.HTTPException(400, {
          message: error$1.message,
          cause: { field: error$1.field, errors: error$1.errors }
        });
      }
      if (error$1 instanceof error.MastraError) {
        throw new chunk64ITUOXI_cjs.HTTPException(getHttpStatusForMastraError(error$1.id), { message: error$1.message });
      }
      return chunkY2BKW5ND_cjs.handleError(error$1, "Error batch inserting items");
    }
  }
});
var BATCH_DELETE_ITEMS_ROUTE = chunk6P7P7Y5U_cjs.createRoute({
  method: "DELETE",
  path: "/datasets/:datasetId/items/batch",
  responseType: "json",
  pathParamSchema: chunkKTKTSTDR_cjs.datasetIdPathParams,
  bodySchema: chunkKTKTSTDR_cjs.batchDeleteItemsBodySchema,
  responseSchema: chunkKTKTSTDR_cjs.batchDeleteItemsResponseSchema,
  summary: "Batch delete items from dataset",
  description: "Deletes multiple items from the dataset in a single operation (single version entry)",
  tags: ["Datasets"],
  requiresAuth: true,
  handler: async ({ mastra, datasetId, ...params }) => {
    assertDatasetsAvailable();
    try {
      const { itemIds } = params;
      const ds = await mastra.datasets.get({ id: datasetId });
      await ds.deleteItems({ itemIds });
      return { success: true, deletedCount: itemIds.length };
    } catch (error$1) {
      if (error$1 instanceof error.MastraError) {
        throw new chunk64ITUOXI_cjs.HTTPException(getHttpStatusForMastraError(error$1.id), { message: error$1.message });
      }
      return chunkY2BKW5ND_cjs.handleError(error$1, "Error bulk deleting items");
    }
  }
});

exports.ADD_ITEM_ROUTE = ADD_ITEM_ROUTE;
exports.BATCH_DELETE_ITEMS_ROUTE = BATCH_DELETE_ITEMS_ROUTE;
exports.BATCH_INSERT_ITEMS_ROUTE = BATCH_INSERT_ITEMS_ROUTE;
exports.COMPARE_EXPERIMENTS_ROUTE = COMPARE_EXPERIMENTS_ROUTE;
exports.CREATE_DATASET_ROUTE = CREATE_DATASET_ROUTE;
exports.DELETE_DATASET_ROUTE = DELETE_DATASET_ROUTE;
exports.DELETE_ITEM_ROUTE = DELETE_ITEM_ROUTE;
exports.GET_DATASET_ROUTE = GET_DATASET_ROUTE;
exports.GET_EXPERIMENT_ROUTE = GET_EXPERIMENT_ROUTE;
exports.GET_ITEM_ROUTE = GET_ITEM_ROUTE;
exports.GET_ITEM_VERSION_ROUTE = GET_ITEM_VERSION_ROUTE;
exports.LIST_DATASETS_ROUTE = LIST_DATASETS_ROUTE;
exports.LIST_DATASET_VERSIONS_ROUTE = LIST_DATASET_VERSIONS_ROUTE;
exports.LIST_EXPERIMENTS_ROUTE = LIST_EXPERIMENTS_ROUTE;
exports.LIST_EXPERIMENT_RESULTS_ROUTE = LIST_EXPERIMENT_RESULTS_ROUTE;
exports.LIST_ITEMS_ROUTE = LIST_ITEMS_ROUTE;
exports.LIST_ITEM_VERSIONS_ROUTE = LIST_ITEM_VERSIONS_ROUTE;
exports.TRIGGER_EXPERIMENT_ROUTE = TRIGGER_EXPERIMENT_ROUTE;
exports.UPDATE_DATASET_ROUTE = UPDATE_DATASET_ROUTE;
exports.UPDATE_ITEM_ROUTE = UPDATE_ITEM_ROUTE;
//# sourceMappingURL=chunk-P445W4ET.cjs.map
//# sourceMappingURL=chunk-P445W4ET.cjs.map