From 2cd70ebaf75a47e3f7b1f316be52aeb05a59ae51 Mon Sep 17 00:00:00 2001 From: Marco Beretta <81851188+berry-13@users.noreply.github.com> Date: Sun, 1 Nov 2026 00:38:11 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=8B=20refactor:=20Move=20the=20Copy=20?= =?UTF-8?q?Footer=20and=20Action=20Gate=20into=20@librechat/chat=20(#17585?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: Move useGenerationsByLatest and MinimalHoverButtons into @librechat/chat * test: Give the Consumer Spec Messages Host the Copy Member --- client/src/Providers/MessagesHostContext.tsx | 31 ++++++++++-- .../components/Chat/Messages/HoverButtons.tsx | 4 +- .../Chat/Messages/SearchMessage.tsx | 2 +- .../Subagents/SubagentConversation.test.tsx | 6 +-- .../Chat/Subagents/SubagentConversation.tsx | 2 +- client/src/components/Share/Message.tsx | 2 +- .../components/Share/Message.wakeup.spec.tsx | 3 +- client/src/hooks/index.ts | 1 - eslint-suppressions.json | 16 +++--- .../chat/src/__fixtures__/messagesHost.ts | 5 +- packages/chat/src/components.ts | 1 + .../messages}/MinimalHoverButtons.tsx | 35 +++++-------- .../__tests__/MinimalHoverButtons.spec.tsx | 49 +++++++++++++++++++ packages/chat/src/react.ts | 5 ++ .../messages/__tests__/generations.spec.ts | 2 +- .../chat/src/react/messages/generations.ts | 14 +++++- packages/chat/src/react/messages/host.tsx | 31 ++++++++++-- packages/chat/test/consumer.spec.tsx | 1 + 18 files changed, 156 insertions(+), 54 deletions(-) rename {client/src/components/Chat/Messages => packages/chat/src/components/messages}/MinimalHoverButtons.tsx (59%) create mode 100644 packages/chat/src/components/messages/__tests__/MinimalHoverButtons.spec.tsx rename client/src/hooks/__tests__/useGenerationsByLatest.spec.ts => packages/chat/src/react/messages/__tests__/generations.spec.ts (92%) rename client/src/hooks/useGenerationsByLatest.ts => packages/chat/src/react/messages/generations.ts (92%) diff --git a/client/src/Providers/MessagesHostContext.tsx b/client/src/Providers/MessagesHostContext.tsx index b99eaf4767..9b484230cc 100644 --- a/client/src/Providers/MessagesHostContext.tsx +++ b/client/src/Providers/MessagesHostContext.tsx @@ -4,12 +4,20 @@ import { useRecoilState } from 'recoil'; import { setDefaultMessagesHost } from '@librechat/chat/react'; import type { ForkEvents, + MessageCopy, MessagesHost, + MessageCopyInput, ForkPreferences, ForkConversation, MessagesScrolling, } from '@librechat/chat/react'; import type { TMessage } from 'librechat-data-provider'; +import { + hasCopyableText, + useNavigateToConvo, + getMessageClipboardSource, + useCopyMessageToClipboard, +} from '~/hooks'; import useConversationSeen from '~/hooks/Conversations/useConversationSeen'; import useMessageScrolling from '~/hooks/Messages/useMessageScrolling'; import MessageIcon from '~/components/Chat/Messages/MessageIcon'; @@ -18,7 +26,6 @@ import { useScreenshot } from '~/hooks/ScreenshotContext'; import { useForkConvoMutation } from '~/data-provider'; import useClockFormat from '~/hooks/useClockFormat'; import { autoScrollAtom } from '~/store/autoScroll'; -import { useNavigateToConvo } from '~/hooks'; import store from '~/store'; function useAppForkPreferences(): ForkPreferences { @@ -65,16 +72,30 @@ function useScrolling(messagesTree: TMessage[] | null | undefined): MessagesScro return { ...scrolling, conversationId: conversation?.conversationId }; } +function useAppMessageCopy({ message, searchResults, variant }: MessageCopyInput): MessageCopy { + const clipboardSource = useMemo(() => getMessageClipboardSource(message), [message]); + const copyToClipboard = useCopyMessageToClipboard({ + ...clipboardSource, + searchResults, + variant: clipboardSource.variant ?? variant, + }); + const canCopy = useMemo( + () => hasCopyableText({ ...clipboardSource, searchResults }), + [clipboardSource, searchResults], + ); + return { copyToClipboard, canCopy }; +} + /** What the message list reads from the app: the viewer's clock format and fork defaults, the - * fork request, its scrolling, screenshot and seen reporting, and the row pieces that still live - * here. Registered as the default when this module loads, so rows read it on every route, the - * shared view included. */ + * fork request, the rich-text copy, its scrolling, screenshot and seen reporting, and the row + * pieces that still live here. Registered as the default when this module loads, so rows read it + * on every route, the shared view included. */ export const appMessagesHost: MessagesHost = { useHour12: useClockFormat, renderFiles: (message) => , useForkPreferences: useAppForkPreferences, useForkConversation: useAppForkConversation, - + useMessageCopy: useAppMessageCopy, useScrolling, useScreenshotTarget: () => useScreenshot().screenshotTargetRef, useAutoScroll: () => useAtomValue(autoScrollAtom), diff --git a/client/src/components/Chat/Messages/HoverButtons.tsx b/client/src/components/Chat/Messages/HoverButtons.tsx index 75f2984f46..92a660a58c 100644 --- a/client/src/components/Chat/Messages/HoverButtons.tsx +++ b/client/src/components/Chat/Messages/HoverButtons.tsx @@ -3,8 +3,8 @@ import { Copy, Check } from 'lucide'; import { useAtomValue } from 'jotai'; import { useRecoilState } from 'recoil'; import { hasEditablePart } from '@librechat/chat'; -import { revealedQueuedTurnFamily } from '@librechat/chat/react'; import { hoverButtonClasses, Fork, Feedback } from '@librechat/chat/components'; +import { useGenerationsByLatest, revealedQueuedTurnFamily } from '@librechat/chat/react'; import { getSpeechText, findMessageById, isUserInitiatedCompaction } from 'librechat-data-provider'; import { Button, @@ -16,8 +16,8 @@ import { } from '@librechat/client'; import type { TConversation, TMessage, TFeedback } from 'librechat-data-provider'; import { useMessagesIsSubmitting, useOptionalMessagesOperations } from '~/Providers'; -import { useGenerationsByLatest, useLocalize } from '~/hooks'; import MessageAudio from './MessageAudio'; +import { useLocalize } from '~/hooks'; import { cn } from '~/utils'; import store from '~/store'; diff --git a/client/src/components/Chat/Messages/SearchMessage.tsx b/client/src/components/Chat/Messages/SearchMessage.tsx index 324b116765..9f0fb32e68 100644 --- a/client/src/components/Chat/Messages/SearchMessage.tsx +++ b/client/src/components/Chat/Messages/SearchMessage.tsx @@ -5,11 +5,11 @@ import { MessageRow, AuthorHeader, getHeaderModelName, + MinimalHoverButtons, getMessageRowWidthClass, } from '@librechat/chat/components'; import type { TMessage } from 'librechat-data-provider'; import type { TMessageProps, TMessageIcon } from '~/common'; -import MinimalHoverButtons from '~/components/Chat/Messages/MinimalHoverButtons'; import { getHeaderPrefixForScreenReader, getMessageAriaLabel } from '~/utils'; import SearchContent, { rendersMarkdownLite } from './Content/SearchContent'; import Icon from '~/components/Chat/Messages/MessageIcon'; diff --git a/client/src/components/Chat/Subagents/SubagentConversation.test.tsx b/client/src/components/Chat/Subagents/SubagentConversation.test.tsx index 2f867e14e2..d7f411bf7d 100644 --- a/client/src/components/Chat/Subagents/SubagentConversation.test.tsx +++ b/client/src/components/Chat/Subagents/SubagentConversation.test.tsx @@ -48,9 +48,9 @@ jest.mock('~/Providers/MessagePartsHostContext', () => { }; }); -jest.mock('~/components/Chat/Messages/MinimalHoverButtons', () => ({ - __esModule: true, - default: ({ message }: { message: TMessage }) => { +jest.mock('@librechat/chat/components', () => ({ + ...jest.requireActual('@librechat/chat/components'), + MinimalHoverButtons: ({ message }: { message: TMessage }) => { mockCopyMessage(message); return