/**
 * Find the index of the most recent user message
 */
function findLastUserMessageIndex(messages) {
    let count = 0;
    for (let i = messages.length - 1; i >= 0; i--) {
        if (messages[i].role !== "user") {
            continue;
        }
        count++;
        if (count > 0) {
            return i;
        }
    }
    return -1;
}
export function getLastUserMessage(messages) {
    const lastUserIndex = findLastUserMessageIndex(messages);
    return lastUserIndex >= 0 ? messages[lastUserIndex] : undefined;
}
//# sourceMappingURL=extract-history.js.map