import { formatSentinelKillError } from '../security/sentinel-run-failure.js';
export const SENTINEL_KILL_CHECK_INTERVAL_MS = 250;
export async function executeWithSentinelWatch(runId, execute, getRunStatus) {
    let timer;
    const watchPromise = new Promise((_, reject) => {
        timer = setInterval(() => {
            const state = getRunStatus(runId);
            if (state?.status === 'killed') {
                reject(new Error(formatSentinelKillError(state.killReason ?? 'unknown')));
            }
        }, SENTINEL_KILL_CHECK_INTERVAL_MS);
    });
    try {
        return await Promise.race([execute(), watchPromise]);
    }
    finally {
        if (timer !== undefined) {
            clearInterval(timer);
        }
    }
}
//# sourceMappingURL=sentinel-execute-watch.js.map