/**
 * Handler for terminal_kill messages.
 *
 * Kills a PTY process identified by terminalId.
 * The actual cleanup (removing from active map, closing DB session,
 * emitting terminal_exit) happens in the PTY onExit handler in terminal-manager.
 */
import { ErrorCode } from "@pocketcoder/shared/constants";
import { killTerminal } from "../services/terminal-manager.js";
import { logger } from "../utils/logger.js";
export async function handleTerminalKill(message, send) {
    const msg = message;
    const { requestId, payload } = msg;
    const { terminalId } = payload;
    try {
        killTerminal(terminalId);
        logger.info(`Terminal killed: ${terminalId}`);
    }
    catch (err) {
        const errMsg = err instanceof Error ? err.message : String(err);
        logger.error(`terminal_kill failed: ${errMsg}`);
        send({
            type: "terminal_kill",
            requestId,
            error: {
                code: ErrorCode.TERMINAL_NOT_FOUND,
                message: `Terminal not found: ${terminalId}`,
            },
        });
    }
}
//# sourceMappingURL=terminal-kill.js.map