// Issue #148 — Pure prompt composer for conversation send payloads (AC #4).
//
// The composer keeps the user-authored draft and the attached document context in distinct,
// labeled blocks separated by a fixed structural separator. The block headers and separator
// are exported so the test suite and the gateway can assert the separation contract directly.
// No IO, no redaction (the extractor already redacted), no error throwing.
export const CONVERSATION_USER_BLOCK_HEADER = "User message:";
export const CONVERSATION_CONTEXT_BLOCK_HEADER = "Attached document context:";
export const CONVERSATION_MEMORY_BLOCK_HEADER = "Included memory context:";
export const CONVERSATION_DOCUMENT_SEPARATOR = "---";
function renderDocumentBlock(doc) {
    const truncatedFlag = doc.truncated ? "yes" : "no";
    const header = `- [${doc.displayName}] (truncated: ${truncatedFlag}) ${String(doc.extractedBytes)} bytes`;
    const marker = doc.truncated && doc.truncationMarker !== undefined ? `\n${doc.truncationMarker}` : "";
    return `${header}\n${doc.text}${marker}\n${CONVERSATION_DOCUMENT_SEPARATOR}`;
}
export function composeConversationPrompt(draft, documentContext, memoryContextText) {
    if (documentContext.length === 0 &&
        (memoryContextText === undefined || memoryContextText.length === 0)) {
        return draft;
    }
    const blocks = [`${CONVERSATION_USER_BLOCK_HEADER}\n${draft}`];
    if (memoryContextText !== undefined && memoryContextText.length > 0) {
        blocks.push(`${CONVERSATION_MEMORY_BLOCK_HEADER}\n${memoryContextText}`);
    }
    if (documentContext.length > 0) {
        const contextBlocks = documentContext.map(renderDocumentBlock).join("\n");
        blocks.push(`${CONVERSATION_CONTEXT_BLOCK_HEADER}\n${contextBlocks}`);
    }
    return blocks.join("\n\n");
}
