From 299d1fa6a3d6788db78584fe87d0e7717bcc4f76 Mon Sep 17 00:00:00 2001 From: Marco Beretta <81851188+berry-13@users.noreply.github.com> Date: Thu, 5 Nov 2026 17:06:43 +0100 Subject: [PATCH] =?UTF-8?q?=E2=8F=B0=20refactor:=20Move=20the=20Wake-Up=20?= =?UTF-8?q?Row=20Into=20@librechat/chat=20(#17780)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: Move the Wake-Up Row Into @librechat/chat * test: Drive the Wake-Up Row Spec Through the Real Subagent Index --- .../Chat/Messages/ui/MessageRender.tsx | 6 +- .../__tests__/MessageRender.wakeup.spec.tsx | 33 +-- client/src/components/Share/Message.tsx | 6 +- packages/chat/src/components.ts | 1 + .../src/components/messages}/WakeupRow.tsx | 40 ++-- .../messages/__tests__/WakeupRow.spec.tsx | 190 ++++++++++++++++++ 6 files changed, 241 insertions(+), 35 deletions(-) rename {client/src/components/Chat/Messages/ui => packages/chat/src/components/messages}/WakeupRow.tsx (65%) create mode 100644 packages/chat/src/components/messages/__tests__/WakeupRow.spec.tsx diff --git a/client/src/components/Chat/Messages/ui/MessageRender.tsx b/client/src/components/Chat/Messages/ui/MessageRender.tsx index 3151465ced..3abda94241 100644 --- a/client/src/components/Chat/Messages/ui/MessageRender.tsx +++ b/client/src/components/Chat/Messages/ui/MessageRender.tsx @@ -6,6 +6,7 @@ import { MessageFooter, getHeaderHoverLabel, MessageRow, + WakeupRow, } from '@librechat/chat/components'; import type { TMessage } from 'librechat-data-provider'; import type { TMessageProps, TMessageIcon, TMessageChatContext } from '~/common'; @@ -18,10 +19,9 @@ import { import MessageContent from '~/components/Chat/Messages/Content/MessageContent'; import { useLocalize, useMessageActions, useContentMetadata } from '~/hooks'; import { PrivateText } from '~/components/Chat/Messages/PrivateText'; +import { MessageContext, useAgentsMapContext } from '~/Providers'; import MessageIcon from '~/components/Chat/Messages/MessageIcon'; import Wakeup from '~/components/Chat/Messages/Content/Wakeup'; -import { MessageContext } from '~/Providers'; -import WakeupRow from './WakeupRow'; import store from '~/store'; type MessageRenderProps = { @@ -86,6 +86,7 @@ const MessageRender = memo(function MessageRender({ latestMessageDepth, }: MessageRenderProps) { const localize = useLocalize(); + const agentsMap = useAgentsMapContext(); const { ask, edit, @@ -165,6 +166,7 @@ const MessageRender = memo(function MessageRender({ return ( (); -jest.mock('@librechat/chat/react', () => ({ - ...jest.requireActual('@librechat/chat/react'), - useParentSubagents: () => ({ byThreadId: mockChildren }), -})); jest.mock('~/Providers', () => ({ - ...jest.requireActual('~/Providers/MessageContext'), + ...jest.requireActual('~/Providers'), useAgentsMapContext: () => mockAgentsMap, })); @@ -116,6 +114,11 @@ function renderMessage( }, ], ); + queryClient.setQueryData([QueryKeys.parentSubagents, 'conversation-1'], { + parentConversationId: 'conversation-1', + children: [...mockChildren.values()], + childrenTruncated: false, + }); const message = { messageId: 'wake', parentMessageId: 'parent', @@ -125,13 +128,17 @@ function renderMessage( text, } as unknown as TMessage; const row = ( - undefined} - {...siblings} - /> + + + undefined} + {...siblings} + /> + + ); const sharedReply: TMessage = { messageId: 'shared-reply', @@ -272,7 +279,7 @@ describe('MessageRender wake-up rows', () => { }); renderMessage(subagentWakeup('agent_unknown')); - expect(screen.getByRole('heading', { name: /com_ui_subagent_actor$/ })).toBeInTheDocument(); + expect(screen.getByRole('heading', { name: 'Agent' })).toBeInTheDocument(); expect(screen.queryByText(/agent_unknown/)).not.toBeInTheDocument(); }); diff --git a/client/src/components/Share/Message.tsx b/client/src/components/Share/Message.tsx index 9c64c10c03..152af49589 100644 --- a/client/src/components/Share/Message.tsx +++ b/client/src/components/Share/Message.tsx @@ -3,6 +3,7 @@ import { parseWakeupMessage } from '@librechat/chat'; import { SubRow, MessageRow, + WakeupRow, AuthorHeader, SiblingSwitch, getHeaderHoverLabel, @@ -12,17 +13,17 @@ import type { TMessageProps } from '~/common'; import SearchContent, { rendersMarkdownLite, } from '~/components/Chat/Messages/Content/SearchContent'; +import { MessageContext, useShareContext, useAgentsMapContext } from '~/Providers'; import MessageContent from '~/components/Chat/Messages/Content/MessageContent'; import { getHeaderPrefixForScreenReader, getMessageAriaLabel } from '~/utils'; -import WakeupRow from '~/components/Chat/Messages/ui/WakeupRow'; import Wakeup from '~/components/Chat/Messages/Content/Wakeup'; -import { MessageContext, useShareContext } from '~/Providers'; import { useAttachments, useLocalize } from '~/hooks'; import MultiMessage from './MultiMessage'; import Icon from './MessageIcon'; export default function Message(props: TMessageProps) { const localize = useLocalize(); + const agentsMap = useAgentsMapContext(); const { hasConfiguredSender } = useShareContext(); const { message, @@ -68,6 +69,7 @@ export default function Message(props: TMessageProps) {
& { task?: WakeupTask; conversationId: string }) { +}: ComponentProps & { + task?: WakeupTask; + conversationId: string; + /** The viewer's agents by id, for naming and drawing a turn's author; undefined until loaded. */ + agentsMap: Record | undefined; +}): ReactElement { const localize = useLocalize(); - const agentsMap = useAgentsMapContext(); - const { isSharedConvo } = useShareContext(); - const { getMessages } = useOptionalMessagesOperations(); + const { isSharedConvo } = useMessagePartsHost().useShare(); + const getMessages = useMessagesHost().useGetMessages(); const { byThreadId } = useParentSubagents(); const child = task?.threadId == null ? undefined : byThreadId.get(task.threadId); const dispatch = useMemo( - () => - child == null ? findSubagentDispatch(getMessages(conversationId), task?.threadId) : undefined, - [child, conversationId, getMessages, task?.threadId], + () => (child == null ? findSubagentDispatch(getMessages(), task?.threadId) : undefined), + [child, getMessages, task?.threadId], ); const parentMessageId = child?.parentMessageId ?? dispatch?.message.messageId ?? props.id ?? ''; const fallbackName = localize('com_ui_subagent_actor'); diff --git a/packages/chat/src/components/messages/__tests__/WakeupRow.spec.tsx b/packages/chat/src/components/messages/__tests__/WakeupRow.spec.tsx new file mode 100644 index 0000000000..592dba0b84 --- /dev/null +++ b/packages/chat/src/components/messages/__tests__/WakeupRow.spec.tsx @@ -0,0 +1,190 @@ +/** + * @jest-environment jsdom + */ +import { render, screen } from '@testing-library/react'; +import { ContentTypes, EModelEndpoint } from 'librechat-data-provider'; +import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; +import type { Agent, ParentSubagentSummary, TMessage } from 'librechat-data-provider'; +import type { MessagePartsHost, MessagePartsShare } from '../../../react/host'; +import { createMessagesHost } from '../../../__fixtures__/messagesHost'; +import { MessagesHostProvider } from '../../../react/messages/host'; +import { MessagePartsHostProvider } from '../../../react/host'; +import { initEnglish } from '../../../__fixtures__/i18n'; +import WakeupRow from '../WakeupRow'; + +let mockChildren = new Map(); +jest.mock('../../../react/subagents/parents', () => ({ + ...jest.requireActual('../../../react/subagents/parents'), + useParentSubagents: () => ({ byThreadId: mockChildren }), +})); + +beforeAll(initEnglish); +beforeEach(() => { + mockChildren = new Map(); +}); + +const BODY = 'One finding.'; + +const agent = (id: string, name: string): Agent => ({ + id, + name, + description: null, + created_at: 0, + avatar: null, + provider: EModelEndpoint.openAI, + model: 'test', + model_parameters: { + temperature: 1, + maxContextTokens: 4096, + max_context_tokens: 4096, + max_output_tokens: 1024, + top_p: 1, + frequency_penalty: 0, + presence_penalty: 0, + }, +}); + +const child = (overrides: Partial = {}): ParentSubagentSummary => ({ + threadId: 'thread-1', + parentMessageId: 'parent-1', + subagentType: 'agent_reviewer', + subagentKind: 'agent', + agentId: 'agent_reviewer', + title: 'Reviewer', + origin: 'event', + status: 'completed', + tasks: [], + tasksTruncated: false, + ...overrides, +}); + +const dispatchMessage: TMessage = { + messageId: 'dispatch', + parentMessageId: null, + conversationId: 'convo-1', + isCreatedByUser: false, + text: '', + sender: 'Outer Parent', + model: 'agent_outer', + endpoint: EModelEndpoint.agents, + content: [ + { + type: ContentTypes.TOOL_CALL, + agentId: 'agent_lane', + tool_call: { + id: 'call', + name: 'subagent', + args: { run_in_background: true }, + output: JSON.stringify({ + background_task_id: 'task-1', + subagent_thread_id: 'thread-1', + tool: 'subagent', + subagent_type: 'self', + status: 'running', + message: 'Poll with background_task_id task-1.', + }), + subagentIdentity: { subagentKind: 'agent', subagentAgentId: 'agent_lane' }, + }, + }, + ], +}; + +const partsHost: MessagePartsHost = { + useMessage: () => ({ messageId: 'wake', isSubmitting: false, isLatestMessage: true }), + renderMarkdown: ({ content }) => {content}, + renderImage: () => null, + renderFilePreview: () => null, + useSmoothStreaming: () => false, + useAgent: () => undefined, + renderAgentIcon: () => null, + renderAgentAvatar: () => null, + renderContentParts: () => null, + useFontSize: () => 'text-base', + useShowThinking: () => false, + useAutoExpandTools: () => false, + useLaTeXParsing: () => false, + useChatDirection: () => 'ltr', + useUserTextPreferences: () => ({ + usernameDisplay: true, + enableUserMsgMarkdown: true, + collapseLongUserMessages: false, + }), + useUser: () => undefined, + useFileMap: () => undefined, + useToast: () => () => undefined, + useSandboxStarting: () => false, + useToolArtifactClaim: () => [null, () => undefined], + useSteerEscalating: () => false, + usePaneConversationId: () => null, + useLiveAppliedSteer: () => [false, () => undefined], + useShare: () => ({}), +}; + +function renderRow({ + agentsMap, + share = {}, + messages, + subagentType = 'agent_reviewer', +}: { + agentsMap?: Record; + share?: MessagePartsShare; + messages?: TMessage[]; + subagentType?: string; +}): void { + const queryClient = new QueryClient(); + render( + + share }}> + () => messages })}> + +

{BODY}

+
+
+
+
, + ); +} + +describe('WakeupRow', () => { + it('labels the row with the known child author and outlines it', () => { + mockChildren = new Map([['thread-1', child()]]); + renderRow({ agentsMap: { agent_reviewer: agent('agent_reviewer', 'Reviewer') } }); + + expect(screen.getByRole('heading', { name: 'Reviewer' })).toBeVisible(); + expect(screen.getByText(BODY).parentElement).toHaveClass('border', 'border-border-medium'); + expect(screen.getByText(BODY).parentElement).not.toHaveClass('bg-surface-user-message'); + }); + + it('takes the author from the dispatch message and the agents map in a shared conversation', () => { + renderRow({ + agentsMap: { agent_lane: agent('agent_lane', 'Lane Parent') }, + share: { isSharedConvo: true }, + messages: [dispatchMessage], + subagentType: 'self', + }); + + expect(screen.getByRole('heading', { name: 'Lane Parent' })).toBeVisible(); + expect(screen.queryByRole('heading', { name: 'Outer Parent' })).not.toBeInTheDocument(); + }); + + it('falls back to the localized subagent label when no agent is found', () => { + renderRow({ agentsMap: undefined, subagentType: 'self' }); + + expect(screen.getByRole('heading', { name: 'Agent' })).toBeVisible(); + }); +});