export async function requestPortConflictDecisionFromParent(request, timeoutMs = 30_000) {
    if (!process.send) {
        throw new Error(`[vextjs] Port ${request.port} is already in use and no IPC parent is available for prompt mode.`);
    }
    return new Promise((resolve, reject) => {
        let settled = false;
        const cleanup = () => {
            settled = true;
            clearTimeout(timer);
            process.removeListener("message", onMessage);
        };
        const timer = setTimeout(() => {
            if (!settled) {
                cleanup();
                reject(new Error(`[vextjs] Timed out waiting for port conflict decision on ${request.port}.`));
            }
        }, timeoutMs);
        const onMessage = (message) => {
            if (typeof message === "object" &&
                message !== null &&
                message.type === "port-conflict-decision") {
                cleanup();
                const action = message
                    .action;
                resolve(action ?? "abort");
            }
        };
        process.on("message", onMessage);
        process.send?.({ type: "port-conflict", ...request });
    });
}
export function sendLifecycleLevelToParent(level) {
    if (process.env.VEXT_MODE !== "start" && process.env.VEXT_MODE !== "dev") {
        return;
    }
    process.send?.({ type: "lifecycle-config", level });
}
