import { listLogTransportsResponseSchema, listLogsResponseSchema, listLogsQuerySchema } from './chunk-BOIOGPBE.js';
import { validateBody, parseFilters } from './chunk-USR6JK77.js';
import { runIdSchema } from './chunk-USZD5AX2.js';
import { handleError } from './chunk-NA7LKQPZ.js';
import { createRoute } from './chunk-OLKVMPNB.js';
import { __export } from './chunk-PR4QN5HX.js';

// src/server/handlers/logs.ts
var logs_exports = {};
__export(logs_exports, {
  LIST_LOGS_BY_RUN_ID_ROUTE: () => LIST_LOGS_BY_RUN_ID_ROUTE,
  LIST_LOGS_ROUTE: () => LIST_LOGS_ROUTE,
  LIST_LOG_TRANSPORTS_ROUTE: () => LIST_LOG_TRANSPORTS_ROUTE
});
var LIST_LOG_TRANSPORTS_ROUTE = createRoute({
  method: "GET",
  path: "/logs/transports",
  responseType: "json",
  responseSchema: listLogTransportsResponseSchema,
  summary: "List log transports",
  description: "Returns a list of all available log transports",
  tags: ["Logs"],
  requiresAuth: true,
  handler: async ({ mastra }) => {
    try {
      const logger = mastra.getLogger();
      const transports = logger.getTransports();
      return {
        transports: transports ? [...transports.keys()] : []
      };
    } catch (error) {
      return handleError(error, "Error getting log Transports");
    }
  }
});
var LIST_LOGS_ROUTE = createRoute({
  method: "GET",
  path: "/logs",
  responseType: "json",
  queryParamSchema: listLogsQuerySchema,
  responseSchema: listLogsResponseSchema,
  summary: "List logs",
  description: "Returns logs from a specific transport with optional filtering by date range, log level, and custom filters",
  tags: ["Logs"],
  requiresAuth: true,
  handler: async ({ mastra, ...params }) => {
    try {
      const { transportId, fromDate, toDate, logLevel, filters: _filters, page, perPage } = params;
      validateBody({ transportId });
      const filters = parseFilters(_filters);
      const logs = await mastra.listLogs(transportId, {
        fromDate,
        toDate,
        logLevel,
        filters,
        page: page ? Number(page) : void 0,
        perPage: perPage ? Number(perPage) : void 0
      });
      return logs;
    } catch (error) {
      return handleError(error, "Error getting logs");
    }
  }
});
var LIST_LOGS_BY_RUN_ID_ROUTE = createRoute({
  method: "GET",
  path: "/logs/:runId",
  responseType: "json",
  pathParamSchema: runIdSchema,
  queryParamSchema: listLogsQuerySchema,
  responseSchema: listLogsResponseSchema,
  summary: "List logs by run ID",
  description: "Returns all logs for a specific execution run from a transport",
  tags: ["Logs"],
  requiresAuth: true,
  handler: async ({ mastra, runId, ...params }) => {
    try {
      const { transportId, fromDate, toDate, logLevel, filters: _filters, page, perPage } = params;
      validateBody({ runId, transportId });
      const filters = parseFilters(_filters);
      const logs = await mastra.listLogsByRunId({
        runId,
        transportId,
        fromDate,
        toDate,
        logLevel,
        filters,
        page: page ? Number(page) : void 0,
        perPage: perPage ? Number(perPage) : void 0
      });
      return logs;
    } catch (error) {
      return handleError(error, "Error getting logs by run ID");
    }
  }
});

export { LIST_LOGS_BY_RUN_ID_ROUTE, LIST_LOGS_ROUTE, LIST_LOG_TRANSPORTS_ROUTE, logs_exports };
//# sourceMappingURL=chunk-WAWVGCSA.js.map
//# sourceMappingURL=chunk-WAWVGCSA.js.map