const joinUnderCharLimit = (chunks, characterLimit, separator) => {
    let result = '';
    for (const chunk of chunks) {
        if (result.length + chunk.length + separator.length > characterLimit) {
            break;
        }
        if (result === '') {
            result += chunk;
        }
        else {
            result += separator + chunk;
        }
    }
    return result;
};
const getUnderCharLimit = (chunks, characterLimit) => {
    let totalLength = 0;
    const newChunks = [];
    for (const chunk of chunks) {
        if (totalLength + chunk.length > characterLimit) {
            const remainingCharacters = characterLimit - totalLength;
            if (remainingCharacters > 0) {
                newChunks.push(chunk.substring(0, remainingCharacters));
            }
            break;
        }
        newChunks.push(chunk);
        totalLength += chunk.length;
    }
    return newChunks;
};
export const previewChunks = (chunks, charLimit) => joinUnderCharLimit(chunks, charLimit - '...\n'.length, '\n...\n');
export const limitChunks = (chunks, charLimit) => getUnderCharLimit(chunks, charLimit);
export const tokensToChars = (tokenCnt) => tokenCnt * 4;
export const charsToTokens = (charCnt) => Math.floor(charCnt / 4);
