"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateMessage = void 0;
const extensions_core_1 = require("@awell-health/extensions-core");
const generateMessageWithLLM_1 = require("./lib/generateMessageWithLLM");
const config_1 = require("./config");
const utils_1 = require("../../../../src/utils");
const createOpenAIModel_1 = require("../../../../src/lib/llm/openai/createOpenAIModel");
const constants_1 = require("../../../../src/lib/llm/openai/constants");
/**
 * Awell Action: Message Generation
 *
 * Takes communication objective and personalization inputs, uses LLM to:
 * 1. Generate a personalized message
 * 2. Create appropriate subject line
 *
 * @returns subject and HTML-formatted message
 */
exports.generateMessage = {
    key: 'generateMessage',
    category: extensions_core_1.Category.WORKFLOW,
    title: 'Generate Message (Beta)',
    description: 'Generate a personalized message',
    fields: config_1.fields,
    previewable: false,
    dataPoints: config_1.dataPoints,
    onEvent: async ({ payload, onComplete, onError, helpers }) => {
        // 1. Validate input fields
        const { communicationObjective, personalizationInput, stakeholder, language, } = config_1.FieldsValidationSchema.parse(payload.fields);
        // 2. Initialize OpenAI model with metadata
        const { model, metadata, callbacks } = await (0, createOpenAIModel_1.createOpenAIModel)({
            settings: {}, // we use built-in API key for OpenAI
            helpers,
            payload,
            modelType: constants_1.OPENAI_MODELS.GPT4o, // Using GPT4 for high-quality message generation
        });
        // 3. Generate message
        const { subject, message } = await (0, generateMessageWithLLM_1.generateMessageWithLLM)({
            model,
            communicationObjective,
            personalizationInput,
            stakeholder,
            language,
            metadata,
            callbacks,
        });
        // 4. Format and return results
        const htmlMessage = await (0, utils_1.markdownToHtml)(message);
        await onComplete({
            data_points: { subject, message: htmlMessage },
        });
    },
};
//# sourceMappingURL=generateMessage.js.map