diff --git a/packages/chat/src/components/messages/MessageRender.tsx b/packages/chat/src/components/messages/MessageRender.tsx index caa3043405..db29d39557 100644 --- a/packages/chat/src/components/messages/MessageRender.tsx +++ b/packages/chat/src/components/messages/MessageRender.tsx @@ -8,6 +8,7 @@ import { areMessageFieldsEqual, isSameTailRelation } from '../../react/messages/ import { getHeaderPrefixForScreenReader, getMessageAriaLabel } from './labels'; import { MessageIconSlot, useMessagesHost } from '../../react/messages/host'; import useContentMetadata from '../../react/messages/useContentMetadata'; +import { useUserTurnAuthor } from '../../react/messages/author'; import { parseWakeupMessage } from '../../core/parts/wakeup'; import { MessageContext } from '../../react/message'; import { getHeaderHoverLabel } from './HeaderLabel'; @@ -103,6 +104,7 @@ const MessageRender: NamedExoticComponent = memo(function Me chatContext, }); const maximizeChatSpace = host.useMaximizeChatSpace(); + const userAuthor = useUserTurnAuthor(); const handleRegenerateMessage = useCallback(() => regenerateMessage(), [regenerateMessage]); const getLatestMessageId = useCallback(() => chatContext.latestMessageId, [chatContext]); @@ -156,6 +158,8 @@ const MessageRender: NamedExoticComponent = memo(function Me const Row = subagentWakeup == null ? MessageRow : WakeupRow; const isUserSide = msg.isCreatedByUser === true && (edit || wakeupDisplay == null || subagentWakeup != null); + /** A user-side turn someone other than the reader wrote is drawn as that author's. */ + const authored = msg.isCreatedByUser === true && wakeupDisplay == null ? userAuthor : undefined; return ( = memo(function Me conversationId={msg.conversationId ?? conversation?.conversationId ?? ''} message={wakeupDisplay != null ? undefined : msg} id={msg.messageId} - icon={} - label={messageLabel ?? ''} - hoverLabel={getHeaderHoverLabel( - hasConfiguredSender, - agent?.model, - assistant?.model, - msg.model, - conversation?.model, - )} + icon={ + authored != null ? ( + authored.icon + ) : ( + + ) + } + label={authored != null ? authored.label : (messageLabel ?? '')} + showAuthor={authored != null} + hoverLabel={ + /** The model is the conversation's agent's, not this author's, so it is not shown. */ + authored != null + ? undefined + : getHeaderHoverLabel( + hasConfiguredSender, + agent?.model, + assistant?.model, + msg.model, + conversation?.model, + ) + } timestamp={msg.createdAt ?? msg.clientTimestamp} ariaLabel={getMessageAriaLabel(msg, localize)} headerPrefix={getHeaderPrefixForScreenReader(msg, localize)} diff --git a/packages/chat/src/components/pane/Followed.tsx b/packages/chat/src/components/pane/Followed.tsx index 449e36e794..3b99f7a8b0 100644 --- a/packages/chat/src/components/pane/Followed.tsx +++ b/packages/chat/src/components/pane/Followed.tsx @@ -2,11 +2,13 @@ import { useMemo } from 'react'; import { buildTree } from 'librechat-data-provider'; import type { TConversation } from 'librechat-data-provider'; import type { ReactElement } from 'react'; +import type { TMessageAuthor } from '../../react/messages/author'; import type { MessagesHost } from '../../react/messages/host'; import type { ChatScreenMessagesSlots } from './messages'; import type { FollowedChat } from '../../react/follow'; import { useMessagesHost, inertSeenSource, MessagesHostProvider } from '../../react/messages/host'; import { ChatContext, useChatContext } from '../../react/chat/context'; +import { UserTurnAuthorContext } from '../../react/messages/author'; import { useFollowedContract } from '../../react/chat/followed'; import ScreenMessages from './messages'; @@ -19,6 +21,8 @@ export type FollowedThreadProps = { conversation: TConversation | null; /** Replacements for the list's slots, over the ones a followed conversation leaves empty. */ slots?: ChatScreenMessagesSlots; + /** Who wrote the conversation's user-side turns, when the reader did not. */ + userAuthor?: TMessageAuthor; }; const none = (): null => null; @@ -69,6 +73,7 @@ export default function FollowedThread({ index, conversation, slots, + userAuthor, }: FollowedThreadProps): ReactElement { const contract = useFollowedContract({ id, followed, index, conversation }); const { messages } = followed; @@ -78,12 +83,14 @@ export default function FollowedThread({ return ( - + + + ); diff --git a/packages/chat/src/components/subagents/__tests__/followed.spec.tsx b/packages/chat/src/components/subagents/__tests__/followed.spec.tsx index f51897b1d6..17e5a7c170 100644 --- a/packages/chat/src/components/subagents/__tests__/followed.spec.tsx +++ b/packages/chat/src/components/subagents/__tests__/followed.spec.tsx @@ -6,7 +6,7 @@ import { Provider, createStore } from 'jotai'; import { fireEvent, render, screen } from '@testing-library/react'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { Constants, ContentTypes, QueryKeys } from 'librechat-data-provider'; -import type { TMessage, SubagentControlReceipt } from 'librechat-data-provider'; +import type { Agent, TMessage, SubagentControlReceipt } from 'librechat-data-provider'; import type { ReactElement } from 'react'; import type { ConversationSeenSource } from '../../../react/messages/host'; import type { ToolContentQuery } from '../../../react/parts/disclosure'; @@ -95,6 +95,8 @@ const messagesHost = createMessagesHost({ }); const partsHost = createMessagePartsHost({ + /** The child's agent has a model, which a reply's header may show; a brief's must not. */ + useAgent: () => ({ id: 'agent-1', name: 'Child agent', model: 'child-model' }) as Agent, renderContentParts: ({ messageId, content }) => ( { }); }); + it("draws the child's brief as the turn of the agent that sent it, not the reader's", () => { + mount(followedChat(), {}, { briefAuthor: { label: 'Lead agent', icon: LA } }); + + const brief = screen.getByRole('heading', { name: /Lead agent/ }); + expect(brief).toBeVisible(); + expect(brief).not.toHaveClass('sr-only'); + expect(brief).toHaveTextContent('LA'); + /** Named for its author alone: the model on offer is the child's, not the sender's. */ + expect(brief).not.toHaveTextContent('child-model'); + expect(rows()[0]).toBe('task:user=Investigate the release.'); + }); + + it('leaves a brief with no known sender as a plain user-side turn', () => { + mount(followedChat()); + + expect(screen.queryByText('LA')).toBeNull(); + }); + it("reads a tool call's full output through the host's parent-scoped query", () => { const useThreadToolContent = jest.fn() as unknown as ToolContentQuery; mount(followedChat(), { useThreadToolContent }); diff --git a/packages/chat/src/components/subagents/__tests__/panel.spec.tsx b/packages/chat/src/components/subagents/__tests__/panel.spec.tsx index a1f322e9cd..a7c35a2793 100644 --- a/packages/chat/src/components/subagents/__tests__/panel.spec.tsx +++ b/packages/chat/src/components/subagents/__tests__/panel.spec.tsx @@ -319,11 +319,13 @@ jest.mock('../followed', () => ({ threadId, agentId, followed, + briefAuthor, controls, onCancelControl, }: { threadId: string; agentId?: string; + briefAuthor?: { label: string }; followed: { isLoading: boolean }; controls?: Array<{ controlId?: string; status: string }>; onCancelControl?: (controlId: string) => void; @@ -338,6 +340,7 @@ jest.mock('../followed', () => ({ data-testid="followed-thread" data-thread={threadId} data-agent={agentId} + data-brief-author={briefAuthor?.label} data-loading={String(followed.isLoading)} data-receipt-scope={JSON.stringify(scope)} data-controls={(controls ?? []).map((control) => control.status).join(',')} @@ -4751,6 +4754,8 @@ describe('SubagentThreadPanel', () => { const thread = screen.getByTestId('followed-thread'); expect(thread).toHaveAttribute('data-thread', 'child-thread'); expect(thread).toHaveAttribute('data-agent', 'agent-1'); + /** The brief is the dispatching agent's turn; unresolved here, so its fallback name. */ + expect(thread).toHaveAttribute('data-brief-author', 'com_ui_subagent_parent_agent'); expect(thread).toHaveAttribute( 'data-receipt-scope', JSON.stringify({ @@ -4766,6 +4771,18 @@ describe('SubagentThreadPanel', () => { }); }); + it("names a self-spawn's brief for the agent it runs as, as the durable view does", () => { + view('completed'); + mockUseThreadChat.mockReturnValue(followedChat()); + + mount({ ...selection, subagentType: 'self' }); + + expect(screen.getByTestId('followed-thread')).toHaveAttribute( + 'data-brief-author', + 'Analyst One', + ); + }); + it('shows the thread while its messages load', () => { view('completed'); mockUseThreadChat.mockReturnValue(followedChat({ isLoading: true })); diff --git a/packages/chat/src/components/subagents/followed.tsx b/packages/chat/src/components/subagents/followed.tsx index bf14ae34e9..e828a41808 100644 --- a/packages/chat/src/components/subagents/followed.tsx +++ b/packages/chat/src/components/subagents/followed.tsx @@ -4,6 +4,7 @@ import { EModelEndpoint } from 'librechat-data-provider'; import type { TConversation, TMessageContentParts } from 'librechat-data-provider'; import type { ReactElement } from 'react'; import type { ChildActivity } from '../../react/subagents/adapters'; +import type { TMessageAuthor } from '../../react/messages/author'; import type { ChatScreenMessagesSlots } from '../pane/messages'; import type { FollowedChat } from '../../react/follow'; import { MessagePartsHostProvider, useMessagePartsHost } from '../../react/host'; @@ -24,6 +25,8 @@ export type FollowedChildThreadProps = { followed: FollowedChat; /** The agent the child runs as, which its replies are drawn for. */ agentId?: string; + /** Who briefed the child: the agent that dispatched it, which its brief is drawn for. */ + briefAuthor?: TMessageAuthor; /** The guidance sent to the task, as the task's durable view reports it. */ controls?: ChildActivity['controls']; /** Earlier guidance than `controls` holds exists. */ @@ -43,6 +46,7 @@ export default function FollowedChildThread({ threadId, followed, agentId, + briefAuthor, controls = noControls, controlsTruncated = false, onCancelControl, @@ -127,6 +131,7 @@ export default function FollowedChildThread({ followed={followed} conversation={conversation} slots={slots} + userAuthor={briefAuthor} /> diff --git a/packages/chat/src/components/subagents/panel.tsx b/packages/chat/src/components/subagents/panel.tsx index 83836e119e..016c333b7d 100644 --- a/packages/chat/src/components/subagents/panel.tsx +++ b/packages/chat/src/components/subagents/panel.tsx @@ -1036,6 +1036,16 @@ export default function SubagentThreadPanel({ threadView?.title, ], ); + /** + * Who a child's brief came from. A self-spawn is briefed by the agent it runs as, and its + * enclosing message can belong to another agent on a parallel lane, so the child's author is + * the one to show; any other child is briefed by the agent that dispatched it. + */ + const dispatcher = isSelfSpawn && selection.event == null ? childAuthor : parentAuthor; + const briefAuthor = useMemo( + () => ({ icon: dispatcher.icon, label: dispatcher.name }), + [dispatcher.icon, dispatcher.name], + ); const panelTitle = childAuthor.name; const actorOptions = useMemo(() => { if (selection.event == null) return []; @@ -1597,7 +1607,7 @@ export default function SubagentThreadPanel({ = createContext useContext(AuthorContext); + +/** + * Who wrote a list's user-side turns, when that is not the reader. A conversation the reader + * follows can hold such turns: a subagent's brief comes from the agent that dispatched it. A + * list under this context draws them with this author's name and face, shown, instead of the + * reader's. + */ +export const UserTurnAuthorContext: Context = createContext< + TMessageAuthor | undefined +>(undefined); +export const useUserTurnAuthor = (): TMessageAuthor | undefined => + useContext(UserTurnAuthorContext);