"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "ResponseSynthesizer", {
    enumerable: true,
    get: function() {
        return ResponseSynthesizer;
    }
});
const _Node = require("../Node.js");
const _Response = require("../Response.js");
const _utils = require("../llm/utils.js");
const _Mixin = require("../prompts/Mixin.js");
const _builders = require("./builders.js");
class ResponseSynthesizer extends _Mixin.PromptMixin {
    responseBuilder;
    metadataMode;
    constructor({ responseBuilder, serviceContext, metadataMode = _Node.MetadataMode.NONE } = {}){
        super();
        this.responseBuilder = responseBuilder ?? (0, _builders.getResponseBuilder)(serviceContext);
        this.metadataMode = metadataMode;
    }
    _getPromptModules() {
        return {};
    }
    _getPrompts() {
        const prompts = this.responseBuilder.getPrompts?.();
        return {
            ...prompts
        };
    }
    _updatePrompts(promptsDict) {
        this.responseBuilder.updatePrompts?.(promptsDict);
    }
    async synthesize({ query, nodesWithScore, stream }) {
        const textChunks = nodesWithScore.map(({ node })=>node.getContent(this.metadataMode));
        if (stream) {
            const response = await this.responseBuilder.getResponse({
                query,
                textChunks,
                stream
            });
            return (0, _utils.streamConverter)(response, (chunk)=>new _Response.Response(chunk, nodesWithScore));
        }
        const response = await this.responseBuilder.getResponse({
            query,
            textChunks
        });
        return new _Response.Response(response, nodesWithScore);
    }
}
