"use strict";
/**
 * Conversation logging helper
 * Ensures Claude responses are paired with the latest user input before writing markdown logs
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.recordClaudeConversation = recordClaudeConversation;
const db_1 = require("./db");
const log_manager_1 = require("./log-manager");
const logger_1 = require("./logger");
const logger = (0, logger_1.createLogger)('conversation-logger');
/**
 * Persist the latest Claude response alongside the most recent user prompt.
 * Errors are swallowed so the calling API route can continue responding.
 */
async function recordClaudeConversation(db, worktreeId, claudeResponse, cliToolId = 'claude') {
    const lastUserMessage = (0, db_1.getLastUserMessage)(db, worktreeId);
    if (!lastUserMessage) {
        return;
    }
    try {
        await (0, log_manager_1.createLog)(worktreeId, lastUserMessage.content, claudeResponse, cliToolId);
    }
    catch (error) {
        logger.error('conversation:log-failed', { error: error instanceof Error ? error.message : String(error) });
    }
}
