Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions packages/chat/src/components/messages/MessageRender.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -103,6 +104,7 @@ const MessageRender: NamedExoticComponent<MessageRenderProps> = memo(function Me
chatContext,
});
const maximizeChatSpace = host.useMaximizeChatSpace();
const userAuthor = useUserTurnAuthor();

const handleRegenerateMessage = useCallback(() => regenerateMessage(), [regenerateMessage]);
const getLatestMessageId = useCallback(() => chatContext.latestMessageId, [chatContext]);
Expand Down Expand Up @@ -156,6 +158,8 @@ const MessageRender: NamedExoticComponent<MessageRenderProps> = 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 (
<Row
Expand All @@ -164,8 +168,15 @@ const MessageRender: NamedExoticComponent<MessageRenderProps> = memo(function Me
conversationId={msg.conversationId ?? conversation?.conversationId ?? ''}
message={wakeupDisplay != null ? undefined : msg}
id={msg.messageId}
icon={<MessageIconSlot iconData={iconData} assistant={assistant} agent={agent} />}
label={messageLabel ?? ''}
icon={
authored != null ? (
authored.icon
) : (
<MessageIconSlot iconData={iconData} assistant={assistant} agent={agent} />
)
}
label={authored != null ? authored.label : (messageLabel ?? '')}
showAuthor={authored != null}
hoverLabel={getHeaderHoverLabel(
hasConfiguredSender,

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid. Fixed in dee57ad: a turn drawn for an explicit author gets no model hover label. The label on offer was the model of the conversation's agent, which for a child thread is the child, so the brief's heading named the parent and revealed the child's model on hover and to screen readers. Pinned in subagents/__tests__/followed.spec.tsx (the brief's heading does not contain the child's model), which fails against the previous code.

agent?.model,
Expand Down
19 changes: 13 additions & 6 deletions packages/chat/src/components/pane/Followed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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;
Expand Down Expand Up @@ -69,6 +73,7 @@ export default function FollowedThread({
index,
conversation,
slots,
userAuthor,
}: FollowedThreadProps): ReactElement {
const contract = useFollowedContract({ id, followed, index, conversation });
const { messages } = followed;
Expand All @@ -78,12 +83,14 @@ export default function FollowedThread({
return (
<ChatContext.Provider value={contract}>
<MessagesHostProvider host={messagesHost}>
<ScreenMessages
messagesTree={messagesTree}
messages={messages}
slots={listSlots}
primary={false}
/>
<UserTurnAuthorContext.Provider value={userAuthor}>
<ScreenMessages
messagesTree={messagesTree}
messages={messages}
slots={listSlots}
primary={false}
/>
</UserTurnAuthorContext.Provider>
</MessagesHostProvider>
</ChatContext.Provider>
);
Expand Down
16 changes: 16 additions & 0 deletions packages/chat/src/components/subagents/__tests__/followed.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,22 @@ describe('FollowedChildThread', () => {
});
});

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: <span>LA</span> } });

const brief = screen.getByRole('heading', { name: /Lead agent/ });
expect(brief).toBeVisible();
expect(brief).not.toHaveClass('sr-only');
expect(brief).toHaveTextContent('LA');
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 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(',')}
Expand Down Expand Up @@ -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({
Expand Down
5 changes: 5 additions & 0 deletions packages/chat/src/components/subagents/followed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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. */
Expand All @@ -43,6 +46,7 @@ export default function FollowedChildThread({
threadId,
followed,
agentId,
briefAuthor,
controls = noControls,
controlsTruncated = false,
onCancelControl,
Expand Down Expand Up @@ -127,6 +131,7 @@ export default function FollowedChildThread({
followed={followed}
conversation={conversation}
slots={slots}
userAuthor={briefAuthor}
/>
</div>
</ToolContentQueryContext.Provider>
Expand Down
6 changes: 6 additions & 0 deletions packages/chat/src/components/subagents/panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ export default function SubagentThreadPanel({
selection.partIndex,
selection.durable?.threadId,
);
/** The brief is the dispatching agent's turn, drawn with its name and face. */
const briefAuthor = useMemo(
() => ({ icon: parentAuthor.icon, label: parentAuthor.name }),
[parentAuthor.icon, parentAuthor.name],
);
const threadId = selection.durable?.threadId ?? '';
const taskId = selection.durable?.taskId ?? '';
const receiptScope = useMemo(
Expand Down Expand Up @@ -1752,6 +1757,7 @@ export default function SubagentThreadPanel({
threadId={threadId}
followed={followed}
agentId={taskView?.agentId ?? foregroundAgentId}
briefAuthor={briefAuthor}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid. Fixed in dee57ad: the brief's author is now the same value the durable view passes as its turn's parent author, childAuthor for a self-spawn that is not an event thread and parentAuthor otherwise. It is computed once (dispatcher) and used by both bodies, so they cannot name the brief differently. Pinned in panel.spec.tsx (a self-spawn's brief is named for the agent it runs as), which fails with the parent author used unconditionally.

controls={activity.controls}
controlsTruncated={activity.controlsTruncated}
onCancelControl={
Expand Down
12 changes: 12 additions & 0 deletions packages/chat/src/react/messages/author.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,15 @@ export const AuthorContext: Context<TMessageAuthor | null> = createContext<TMess
null,
);
export const useAuthorContext = (): TMessageAuthor | null => 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<TMessageAuthor | undefined> = createContext<
TMessageAuthor | undefined
>(undefined);
export const useUserTurnAuthor = (): TMessageAuthor | undefined =>
useContext(UserTurnAuthorContext);
Loading