import { d as defineEventHandler, b as getRouterParam, c as createError, l as findBySlugInActivePipeline, m as findByIssueAndColumnId } from '../../../../../nitro/nitro.mjs';
import 'node:http';
import 'node:https';
import 'node:crypto';
import 'stream';
import 'events';
import 'http';
import 'crypto';
import 'buffer';
import 'zlib';
import 'https';
import 'net';
import 'tls';
import 'url';
import 'node:events';
import 'node:buffer';
import 'node:fs';
import 'node:path';
import 'vue-router';
import '@prisma/client';
import '@prisma/adapter-better-sqlite3';
import 'fs';
import 'path';
import 'fs/promises';
import 'child_process';
import 'node:child_process';
import 'node:url';

const log_get = defineEventHandler(async (event) => {
  const id = getRouterParam(event, "id");
  const columnSlug = getRouterParam(event, "column");
  if (!id) {
    throw createError({
      statusCode: 400,
      message: "Issue ID required"
    });
  }
  if (!columnSlug) {
    throw createError({
      statusCode: 400,
      message: "Column slug required"
    });
  }
  const column = await findBySlugInActivePipeline(columnSlug);
  if (!column) {
    throw createError({
      statusCode: 404,
      message: `Column '${columnSlug}' not found in active pipeline`
    });
  }
  const logs = await findByIssueAndColumnId(id, column.id);
  const mostRecent = logs[0];
  if (!(mostRecent == null ? void 0 : mostRecent.terminalLog)) {
    return [];
  }
  return parseLogContent(mostRecent.terminalLog);
});
function parseLogContent(content) {
  var _a, _b;
  const lines = content.split("\n").filter(Boolean);
  const logs = [];
  for (const line of lines) {
    const match = line.match(/^\[(.+?)\]\s*\[(\w+)\]\s*(.+)$/);
    if (match) {
      const timestamp = match[1];
      const levelStr = (_b = (_a = match[2]) == null ? void 0 : _a.toLowerCase()) != null ? _b : "info";
      const message = match[3];
      if (timestamp && message) {
        logs.push({
          timestamp,
          level: levelStr,
          message
        });
      }
    } else {
      logs.push({
        timestamp: (/* @__PURE__ */ new Date()).toISOString(),
        level: "info",
        message: line
      });
    }
  }
  return logs;
}

export { log_get as default };
//# sourceMappingURL=log.get.mjs.map
