import { contentPartsToMessageContent } from "./contentPartsToMessageContent.js";
function isMessageContentEmpty(content) {
    if (typeof content === 'string')
        return content.trim() === '';
    return Array.isArray(content) && content.length === 0;
}
export function buildFinalMessages(params) {
    const { baseMessages, completedAssistantMessages, currentAssistantMessageId, contentParts } = params;
    const currentContent = contentPartsToMessageContent(contentParts);
    const completedWithContent = completedAssistantMessages.filter((m) => !isMessageContentEmpty(m.content));
    const result = [...baseMessages];
    for (const m of completedWithContent) {
        result.push({
            id: m.id,
            role: 'assistant',
            content: m.content,
        });
    }
    if (!isMessageContentEmpty(currentContent)) {
        result.push({
            id: currentAssistantMessageId,
            role: 'assistant',
            content: currentContent,
        });
    }
    return result;
}
//# sourceMappingURL=buildFinalMessages.js.map
