import { d as defineEventHandler, b as getRouterParam, c as createError, z as findByIssue, B as parseChanges, C as findBySessionId } 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 history_get = defineEventHandler(async (event) => {
  const id = getRouterParam(event, "id");
  if (!id) {
    throw createError({
      statusCode: 400,
      message: "Issue ID required"
    });
  }
  const history = await findByIssue(id);
  const enrichedHistory = await Promise.all(
    history.map(async (entry) => {
      var _a;
      const baseEntry = {
        at: entry.at.toISOString(),
        action: entry.action,
        from: entry.fromColumn,
        to: entry.toColumn,
        sessionId: (_a = entry.sessionId) != null ? _a : void 0,
        changes: entry.changes ? parseChanges(entry) : void 0
      };
      if (!entry.sessionId) {
        return baseEntry;
      }
      const log = await findBySessionId(entry.sessionId);
      return {
        ...baseEntry,
        artifactsAvailable: {
          prompt: !!(log == null ? void 0 : log.prompt),
          terminal: !!(log == null ? void 0 : log.terminalLog)
        }
      };
    })
  );
  return enrichedHistory;
});

export { history_get as default };
//# sourceMappingURL=history.get.mjs.map
