"use strict";
/**
 * Registry of agentic attack providers that support per-turn/per-iteration layer transforms.
 *
 * These are strategies internally implemented as providers that orchestrate
 * adversarial attacks over multiple iterations or turns.
 *
 * Two categories:
 *
 * 1. **Multi-turn conversation** (hydra, crescendo, goat, custom):
 *    - Target sees all previous messages (conversation context)
 *    - Uses hybrid format: text history + audio/image current turn
 *
 * 2. **Multi-attempt single-turn** (meta, tree):
 *    - Each iteration is independent (target sees one message per attempt)
 *    - Transforms each single message directly (no hybrid format needed)
 *
 * Note: This is a subset of MULTI_TURN_STRATEGIES + AGENTIC_STRATEGIES.
 * Not all strategies support per-turn transforms:
 * - simba: Different architecture, not yet supported
 * - mischievous-user: Different implementation pattern
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.ATTACK_PROVIDER_IDS = void 0;
exports.isAttackProvider = isAttackProvider;
exports.getAttackProviderFullId = getAttackProviderFullId;
exports.isMultiTurnStrategy = isMultiTurnStrategy;
const strategies_1 = require("../constants/strategies");
/**
 * Attack providers that support per-turn/per-iteration layer transforms.
 *
 * These providers:
 * 1. Accept `_perTurnLayers` config to apply transforms per turn/iteration
 * 2. Multi-turn: Send hybrid payloads (text history + audio/image current turn)
 * 3. Single-turn iterative: Send transformed single message
 * 4. Store promptAudio/promptImage in redteamHistory for UI rendering
 */
exports.ATTACK_PROVIDER_IDS = [
    // Multi-turn conversation (hybrid format with history)
    'hydra', // jailbreak:hydra
    'crescendo',
    'goat',
    'custom',
    // Multi-attempt single-turn (direct transform, no history)
    'iterative', // jailbreak (base)
    'iterative:meta', // jailbreak:meta
    'iterative:tree', // jailbreak:tree
];
/**
 * Check if a strategy ID corresponds to an attack provider
 * that supports per-turn/per-iteration layer transforms.
 *
 * Handles various ID formats:
 * - Short: 'hydra', 'crescendo', 'goat', 'custom', 'meta', 'tree'
 * - Full: 'trusys:redteam:hydra', 'trusys:redteam:iterative:meta'
 * - Prefixed: 'jailbreak:hydra', 'jailbreak:meta', 'jailbreak:tree'
 *
 * @param id - The strategy ID to check
 * @returns true if this is an attack provider supporting per-turn transforms
 */
function isAttackProvider(id) {
    // Normalize the ID by removing common prefixes
    let baseId = id.replace('trusys:redteam:', '');
    // Handle jailbreak and jailbreak: prefix for iterative strategies
    if (baseId === 'jailbreak') {
        baseId = 'iterative';
    }
    else if (baseId.startsWith('jailbreak:')) {
        const jailbreakType = baseId.replace('jailbreak:', '');
        // jailbreak:hydra -> hydra
        // jailbreak:meta -> iterative:meta
        // jailbreak:tree -> iterative:tree
        if (jailbreakType === 'meta') {
            baseId = 'iterative:meta';
        }
        else if (jailbreakType === 'tree') {
            baseId = 'iterative:tree';
        }
        else {
            baseId = jailbreakType;
        }
    }
    // Handle 'custom:...' variants
    if (baseId.startsWith('custom:') || baseId === 'custom') {
        baseId = 'custom';
    }
    return exports.ATTACK_PROVIDER_IDS.includes(baseId);
}
/**
 * Get the full provider ID for an attack provider.
 *
 * @param id - The strategy ID (e.g., 'hydra', 'jailbreak', 'jailbreak:hydra', 'jailbreak:meta')
 * @returns The full provider ID (e.g., 'trusys:redteam:hydra', 'trusys:redteam:iterative')
 */
function getAttackProviderFullId(id) {
    if (id.startsWith('trusys:redteam:')) {
        return id;
    }
    // Handle jailbreak (base) -> trusys:iterative
    if (id === 'jailbreak') {
        return 'trusys:redteam:iterative';
    }
    // Handle jailbreak: prefix
    if (id.startsWith('jailbreak:')) {
        const jailbreakType = id.replace('jailbreak:', '');
        // jailbreak:meta -> trusys:iterative:meta
        // jailbreak:tree -> trusys:iterative:tree
        // jailbreak:hydra -> trusys:hydra
        if (jailbreakType === 'meta') {
            return 'trusys:redteam:iterative:meta';
        }
        else if (jailbreakType === 'tree') {
            return 'trusys:redteam:iterative:tree';
        }
        return `trusys:redteam:${jailbreakType}`;
    }
    // Handle custom:foo -> trusys:custom
    if (id.startsWith('custom:') || id === 'custom') {
        return 'trusys:redteam:custom';
    }
    return `trusys:redteam:${id}`;
}
/**
 * Check if a strategy is a multi-turn strategy (broader than attack providers).
 * This includes all strategies from MULTI_TURN_STRATEGIES constant.
 *
 * Note: Not all multi-turn strategies support per-turn layer transforms.
 * Use isAttackProvider() to check for that capability.
 */
function isMultiTurnStrategy(id) {
    const normalizedId = id.replace('trusys:redteam:', '').replace('jailbreak:', '');
    return strategies_1.MULTI_TURN_STRATEGIES.some((strategy) => {
        const normalizedStrategy = strategy.replace('jailbreak:', '');
        return normalizedId === normalizedStrategy;
    });
}
//# sourceMappingURL=attackProviders.js.map