import { i as defineEventHandler, r as getActiveRun, e as createError } from '../../../nitro/nitro.mjs';
import 'node:path';
import 'node:module';
import 'node:fs';
import 'node:os';
import 'dotenv';
import 'node:http';
import 'node:https';
import 'node:events';
import 'node:buffer';
import 'node:crypto';
import 'node:async_hooks';
import 'node:url';
import 'node:net';
import '@iconify/utils';
import 'consola';

const cancel_post = defineEventHandler(() => {
  const active = getActiveRun();
  if (!active) {
    throw createError({ statusCode: 409, statusMessage: "No aidev run is currently active." });
  }
  const pid = active.child.pid;
  if (typeof pid !== "number") {
    throw createError({ statusCode: 500, statusMessage: "Active run has no PID." });
  }
  try {
    process.kill(pid, "SIGTERM");
  } catch (err) {
    const code = err.code;
    if (code !== "ESRCH") {
      throw createError({
        statusCode: 500,
        statusMessage: `Failed to signal pid ${pid}: ${err.message}`
      });
    }
  }
  return { ok: true, pid, status: active.status };
});

export { cancel_post as default };
//# sourceMappingURL=cancel.post.mjs.map
