/**
 * Detect V3 agent SSE keepalive/heartbeat events that exist only to keep
 * connections alive — not substantive work the CLI should surface as progress.
 */
const PLANNING_KEEPALIVE = /^Planning in progress\.\.\.\s*\(\d+s(?:\s+elapsed)?\)$/i;
const PARALLEL_KEEPALIVE = /^Parallel tasks in progress\.\.\.\s*\(\d+s(?:\s+elapsed)?\)$/i;
const GENERIC_ELAPSED_KEEPALIVE = /\bin progress\b.*\(\d+s(?:\s+elapsed)?\)$/i;
export function isV3StreamKeepaliveEvent(event) {
    if (!event || typeof event !== 'object') {
        return false;
    }
    const record = event;
    const type = typeof record.type === 'string' ? record.type : '';
    if (type === 'heartbeat') {
        return true;
    }
    if (type === 'progress' || type === 'status') {
        const content = String(record.content || record.message || record.status || '').trim();
        if (!content) {
            return false;
        }
        if (PLANNING_KEEPALIVE.test(content) || PARALLEL_KEEPALIVE.test(content)) {
            return true;
        }
        if (GENERIC_ELAPSED_KEEPALIVE.test(content)) {
            return true;
        }
    }
    if (type === 'plan') {
        const plan = record.plan;
        if (plan && typeof plan === 'object') {
            const planRecord = plan;
            const status = typeof planRecord.status === 'string' ? planRecord.status : '';
            const tasks = planRecord.tasks;
            if (status === 'planning' && !Array.isArray(tasks)) {
                return true;
            }
        }
    }
    return false;
}
