"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "createMessageContent", {
    enumerable: true,
    get: function() {
        return createMessageContent;
    }
});
const _Node = require("../Node.js");
const _utils = require("../embeddings/utils.js");
async function createMessageContent(prompt, nodes, extraParams = {}, metadataMode = _Node.MetadataMode.NONE) {
    const content = [];
    const nodeMap = (0, _Node.splitNodesByType)(nodes);
    for(const type in nodeMap){
        // for each retrieved modality type, create message content
        const nodes = nodeMap[type];
        if (nodes) {
            content.push(...await createContentPerModality(prompt, type, nodes, extraParams, metadataMode));
        }
    }
    return content;
}
// eslint-disable-next-line max-params
async function createContentPerModality(prompt, type, nodes, extraParams, metadataMode) {
    switch(type){
        case _Node.ModalityType.TEXT:
            return [
                {
                    type: "text",
                    text: prompt({
                        ...extraParams,
                        context: nodes.map((r)=>r.getContent(metadataMode)).join("\n\n")
                    })
                }
            ];
        case _Node.ModalityType.IMAGE:
            const images = await Promise.all(nodes.map(async (node)=>{
                return {
                    type: "image_url",
                    image_url: {
                        url: await (0, _utils.imageToDataUrl)(node.image)
                    }
                };
            }));
            return images;
        default:
            return [];
    }
}
