2024-07-20 01:51:59 -04:00
|
|
|
import { ContentTypes, Constants } from 'librechat-data-provider';
|
2024-05-30 18:39:21 -04:00
|
|
|
import type { TMessage } from 'librechat-data-provider';
|
|
|
|
|
|
2024-07-20 01:51:59 -04:00
|
|
|
export const getLengthAndLastTenChars = (str?: string): string => {
|
|
|
|
|
if (!str) {
|
|
|
|
|
return '0';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const length = str.length;
|
|
|
|
|
const lastTenChars = str.slice(-10);
|
|
|
|
|
return `${length}${lastTenChars}`;
|
2024-05-30 18:39:21 -04:00
|
|
|
};
|
|
|
|
|
|
2024-07-20 01:51:59 -04:00
|
|
|
export const getLatestText = (message?: TMessage | null, includeIndex?: boolean) => {
|
2024-05-30 18:39:21 -04:00
|
|
|
if (!message) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
if (message.text) {
|
|
|
|
|
return message.text;
|
|
|
|
|
}
|
|
|
|
|
if (message.content?.length) {
|
|
|
|
|
for (let i = message.content.length - 1; i >= 0; i--) {
|
|
|
|
|
const part = message.content[i];
|
|
|
|
|
if (part.type === ContentTypes.TEXT && part[ContentTypes.TEXT]?.value?.length > 0) {
|
2024-07-20 01:51:59 -04:00
|
|
|
const text = part[ContentTypes.TEXT].value;
|
|
|
|
|
if (includeIndex) {
|
|
|
|
|
return `${text}-${i}`;
|
|
|
|
|
} else {
|
|
|
|
|
return text;
|
|
|
|
|
}
|
2024-05-30 18:39:21 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return '';
|
|
|
|
|
};
|
2024-07-20 01:51:59 -04:00
|
|
|
|
|
|
|
|
export const getTextKey = (message?: TMessage | null, convoId?: string | null) => {
|
|
|
|
|
if (!message) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
const text = getLatestText(message, true);
|
|
|
|
|
return `${message.messageId ?? ''}${Constants.COMMON_DIVIDER}${getLengthAndLastTenChars(text)}${
|
|
|
|
|
Constants.COMMON_DIVIDER
|
|
|
|
|
}${message.conversationId ?? convoId}`;
|
|
|
|
|
};
|
2024-08-08 14:52:12 -04:00
|
|
|
|
|
|
|
|
export const scrollToEnd = () => {
|
2024-08-09 15:17:13 -04:00
|
|
|
const messagesEndElement = document.getElementById('messages-end');
|
|
|
|
|
if (messagesEndElement) {
|
|
|
|
|
messagesEndElement.scrollIntoView({ behavior: 'instant' });
|
|
|
|
|
}
|
2024-08-08 14:52:12 -04:00
|
|
|
};
|