"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const node_fetch_1 = __importDefault(require("node-fetch"));
const logger_1 = __importDefault(require("../logger"));
class PromptfooHarmfulCompletionProvider {
    constructor(options) {
        this.purpose = options.purpose;
        this.harmCategory = options.harmCategory;
    }
    id() {
        return `promptfoo:redteam:${this.harmCategory}`;
    }
    toString() {
        return `[Promptfoo Harmful Completion Provider ${this.purpose} - ${this.harmCategory}]`;
    }
    async callApi(prompt, context, callApiOptions) {
        const body = {
            purpose: this.purpose,
            harmCategory: this.harmCategory,
        };
        try {
            logger_1.default.debug(`Calling promptfoo generate harmful API with body: ${JSON.stringify(body)}`);
            const response = await (0, node_fetch_1.default)('https://api.promptfoo.dev/redteam/generateHarmful', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify(body),
            });
            if (!response.ok) {
                throw new Error(`API call failed with status ${response.status}`);
            }
            const data = await response.json();
            logger_1.default.debug(`promptfoo API call response: ${JSON.stringify(data)}`);
            return {
                output: data.output,
            };
        }
        catch (err) {
            return {
                error: `API call error: ${String(err)}`,
            };
        }
    }
}
exports.default = PromptfooHarmfulCompletionProvider;
//# sourceMappingURL=promptfoo.js.map