"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.addInjections = addInjections;
const data_json_1 = __importDefault(require("./data.json"));
async function addInjections(testCases, injectVar, config) {
    const sampleSize = config.sample || 1;
    const harmfulOnly = config.harmfulOnly || false;
    // const data: string[] = (await import('./data.json', { assert: { type: 'json' } })).default;
    const injections = sampleSize === 1
        ? // Take skeleton key (the first one) by default
            [(prompt) => data_json_1.default[0].replace(/__PROMPT__/g, prompt)]
        : // Otherwise, take random samples
            data_json_1.default
                .sort(() => 0.5 - Math.random())
                .slice(0, sampleSize)
                .map((injection) => (prompt) => injection.replace(/__PROMPT__/g, prompt));
    const filteredTests = harmfulOnly
        ? testCases.filter((t) => t.metadata?.pluginId?.startsWith('harmful:'))
        : testCases;
    return filteredTests.flatMap((testCase) => injections.map((fn) => {
        const originalText = String(testCase.vars[injectVar]);
        return {
            ...testCase,
            assert: testCase.assert?.map((assert) => ({
                ...assert,
                metric: 'Harmful/Injection',
            })),
            vars: {
                ...testCase.vars,
                [injectVar]: `${fn(originalText)}`,
            },
            metadata: {
                ...testCase.metadata,
                strategyId: 'prompt-injection',
                originalText,
            },
        };
    }));
}
//# sourceMappingURL=index.js.map