mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 00:40:14 +01:00
* chore: update package version to 0.7.416 * chore: Update Role.js imports order * refactor: move updateTagsInConvo to tags route, add RBAC for tags * refactor: add updateTagsInConvoOptions * fix: loading state for bookmark form * refactor: update primaryText class in TitleButton component * refactor: remove duplicate bookmarks and theming * refactor: update EditIcon component to use React.forwardRef * refactor: add _id field to tConversationTagSchema * refactor: remove promises * refactor: move mutation logic from BookmarkForm -> BookmarkEditDialog * refactor: update button class in BookmarkForm component * fix: conversation mutations and add better logging to useConversationTagMutation * refactor: update logger message in BookmarkEditDialog component * refactor: improve UI consistency in BookmarkNav and NewChat components * refactor: update logger message in BookmarkEditDialog component * refactor: Add tags prop to BookmarkForm component * refactor: Update BookmarkForm to avoid tag mutation if the tag already exists; also close dialog on submission programmatically * refactor: general role helper function to support updating access permissions for different permission types * refactor: Update getLatestText function to handle undefined values in message.content * refactor: Update useHasAccess hook to handle null role values for authenticated users * feat: toggle bookmarks access * refactor: Update PromptsCommand to handle access permissions for prompts * feat: updateConversationSelector * refactor: rename `vars` to `tagToDelete` for clarity * fix: prevent recreation of deleted tags in BookmarkMenu on Item Click * ci: mock updateBookmarksAccess function * ci: mock updateBookmarksAccess function
60 lines
1.7 KiB
TypeScript
60 lines
1.7 KiB
TypeScript
import { ContentTypes, Constants } from 'librechat-data-provider';
|
|
import type { TMessage } from 'librechat-data-provider';
|
|
|
|
export const getLengthAndLastTenChars = (str?: string): string => {
|
|
if (typeof str !== 'string' || str.length === 0) {
|
|
return '0';
|
|
}
|
|
|
|
const length = str.length;
|
|
const lastTenChars = str.slice(-10);
|
|
return `${length}${lastTenChars}`;
|
|
};
|
|
|
|
export const getLatestText = (message?: TMessage | null, includeIndex?: boolean) => {
|
|
if (!message) {
|
|
return '';
|
|
}
|
|
if (message.text) {
|
|
return message.text;
|
|
}
|
|
if (message.content && message.content.length > 0) {
|
|
for (let i = message.content.length - 1; i >= 0; i--) {
|
|
const part = message.content[i];
|
|
if (
|
|
part.type === ContentTypes.TEXT &&
|
|
((part[ContentTypes.TEXT].value as string | undefined)?.length ?? 0) > 0
|
|
) {
|
|
const text = part[ContentTypes.TEXT].value;
|
|
if (includeIndex === true) {
|
|
return `${text}-${i}`;
|
|
} else {
|
|
return text;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return '';
|
|
};
|
|
|
|
export const getTextKey = (message?: TMessage | null, convoId?: string | null) => {
|
|
if (!message) {
|
|
return '';
|
|
}
|
|
const text = getLatestText(message, true);
|
|
return `${(message.messageId as string | null) ?? ''}${
|
|
Constants.COMMON_DIVIDER
|
|
}${getLengthAndLastTenChars(text)}${Constants.COMMON_DIVIDER}${
|
|
message.conversationId ?? convoId
|
|
}`;
|
|
};
|
|
|
|
export const scrollToEnd = (callback?: () => void) => {
|
|
const messagesEndElement = document.getElementById('messages-end');
|
|
if (messagesEndElement) {
|
|
messagesEndElement.scrollIntoView({ behavior: 'instant' });
|
|
if (callback) {
|
|
callback();
|
|
}
|
|
}
|
|
};
|