'use strict';

var chunkZKMVCV4G_cjs = require('./chunk-ZKMVCV4G.cjs');
var chunkMCYD5LW7_cjs = require('./chunk-MCYD5LW7.cjs');
var chunkSUKFO7UM_cjs = require('./chunk-SUKFO7UM.cjs');
var chunk4LVJBXI2_cjs = require('./chunk-4LVJBXI2.cjs');
var chunkO7I5CWRX_cjs = require('./chunk-O7I5CWRX.cjs');
var z = require('zod');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var z__default = /*#__PURE__*/_interopDefault(z);

// src/server/handlers/logs.ts
var logs_exports = {};
chunkO7I5CWRX_cjs.__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 listLogsQuerySchema = chunkMCYD5LW7_cjs.createPagePaginationSchema().extend({
  fromDate: z__default.default.coerce.date().optional(),
  toDate: z__default.default.coerce.date().optional(),
  logLevel: z__default.default.enum(["debug", "info", "warn", "error", "silent"]).optional(),
  filters: z__default.default.union([z__default.default.string(), z__default.default.array(z__default.default.string())]).optional(),
  transportId: z__default.default.string()
});
var listLogsResponseSchema = z__default.default.object({
  logs: z__default.default.array(chunkMCYD5LW7_cjs.baseLogMessageSchema),
  total: z__default.default.number(),
  page: z__default.default.number(),
  perPage: z__default.default.union([z__default.default.number(), z__default.default.literal(false)]),
  hasMore: z__default.default.boolean()
});
var listLogTransportsResponseSchema = z__default.default.object({
  transports: z__default.default.array(z__default.default.string())
});

// src/server/handlers/logs.ts
var LIST_LOG_TRANSPORTS_ROUTE = chunk4LVJBXI2_cjs.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 chunkSUKFO7UM_cjs.handleError(error, "Error getting log Transports");
    }
  }
});
var LIST_LOGS_ROUTE = chunk4LVJBXI2_cjs.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;
      chunkZKMVCV4G_cjs.validateBody({ transportId });
      const filters = chunkZKMVCV4G_cjs.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 chunkSUKFO7UM_cjs.handleError(error, "Error getting logs");
    }
  }
});
var LIST_LOGS_BY_RUN_ID_ROUTE = chunk4LVJBXI2_cjs.createRoute({
  method: "GET",
  path: "/logs/:runId",
  responseType: "json",
  pathParamSchema: chunkMCYD5LW7_cjs.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;
      chunkZKMVCV4G_cjs.validateBody({ runId, transportId });
      const filters = chunkZKMVCV4G_cjs.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 chunkSUKFO7UM_cjs.handleError(error, "Error getting logs by run ID");
    }
  }
});

exports.LIST_LOGS_BY_RUN_ID_ROUTE = LIST_LOGS_BY_RUN_ID_ROUTE;
exports.LIST_LOGS_ROUTE = LIST_LOGS_ROUTE;
exports.LIST_LOG_TRANSPORTS_ROUTE = LIST_LOG_TRANSPORTS_ROUTE;
exports.logs_exports = logs_exports;
//# sourceMappingURL=chunk-HDGF45K7.cjs.map
//# sourceMappingURL=chunk-HDGF45K7.cjs.map