import { d as defineEventHandler, b as getRouterParam, c as createError, z as findByIssue, A as findByIssue$1, B as parseChanges } 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 fullHistory_get = defineEventHandler(async (event) => {
  var _a, _b;
  const id = getRouterParam(event, "id");
  if (!id) {
    throw createError({
      statusCode: 400,
      message: "Issue ID required"
    });
  }
  const [history, executionLogs] = await Promise.all([
    findByIssue(id),
    findByIssue$1(id)
  ]);
  const logsMap = /* @__PURE__ */ new Map();
  for (const log of executionLogs) {
    logsMap.set(log.sessionId, {
      prompt: (_a = log.prompt) != null ? _a : void 0,
      terminalLog: (_b = log.terminalLog) != null ? _b : void 0
    });
  }
  const entries = history.map((entry) => {
    var _a2;
    const baseEntry = {
      at: entry.at.toISOString(),
      action: entry.action,
      fromColumn: entry.fromColumn,
      toColumn: entry.toColumn,
      sessionId: (_a2 = entry.sessionId) != null ? _a2 : void 0,
      changes: entry.changes ? parseChanges(entry) : void 0
    };
    if (entry.sessionId && logsMap.has(entry.sessionId)) {
      const log = logsMap.get(entry.sessionId);
      baseEntry.prompt = log.prompt;
      baseEntry.terminalLog = log.terminalLog;
    }
    return baseEntry;
  });
  return {
    issueKey: id,
    entries
  };
});

export { fullHistory_get as default };
//# sourceMappingURL=full-history.get.mjs.map
