From b4eb59c96c6de14c8fb58196f6dc0fdcb99eb0e8 Mon Sep 17 00:00:00 2001
From: Marco Beretta <81851188+berry-13@users.noreply.github.com>
Date: Sat, 31 Oct 2026 22:09:24 +0100
Subject: [PATCH] =?UTF-8?q?=F0=9F=AA=AA=20refactor:=20Move=20Subagent=20Au?=
=?UTF-8?q?thors=20Into=20@librechat/chat=20Behind=20a=20Message=20Icon=20?=
=?UTF-8?q?Slot=20(#17635)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* refactor: Move Subagent Authors Into @librechat/chat Behind a Message Icon Slot
* fix: Register the Message Parts Host From the App Entry
* test: Give the Consumer Spec's Messages Host the Icon Slot
---
client/src/App.jsx | 1 +
client/src/Providers/MessagesHostContext.tsx | 2 +
client/src/__tests__/hosts.test.tsx | 52 +++++++++++++++++++
client/src/common/types.ts | 7 +--
.../Messages/Content/Parts/SubagentCall.tsx | 2 +-
.../components/Chat/Messages/MessageIcon.tsx | 9 +---
.../components/Chat/Messages/ui/WakeupRow.tsx | 8 +--
.../__tests__/MessageRender.wakeup.spec.tsx | 2 +
.../SharedSubagentActivityDialog.test.tsx | 2 +
.../SharedSubagentActivityDialog.tsx | 6 +--
.../Subagents/SubagentConversation.test.tsx | 3 +-
.../Chat/Subagents/SubagentConversation.tsx | 3 +-
.../Subagents/SubagentThreadPanel.test.tsx | 2 +
.../Chat/Subagents/SubagentThreadPanel.tsx | 14 +++--
.../Chat/Subagents/author.public.test.tsx | 3 +-
.../components/Chat/Subagents/author.test.ts | 4 +-
.../components/Share/Message.wakeup.spec.tsx | 2 +
.../chat/src/__fixtures__/messagesHost.ts | 1 +
.../src/components/messages/HeaderLabel.tsx | 10 +---
packages/chat/src/core/documents.ts | 8 +++
packages/chat/src/core/index.ts | 1 +
packages/chat/src/react.ts | 3 ++
packages/chat/src/react/messages/host.tsx | 32 +++++++++++-
.../chat/src/react/subagents}/author.tsx | 25 +++++----
packages/chat/src/react/subagents/index.ts | 1 +
packages/chat/test/consumer.spec.tsx | 1 +
26 files changed, 149 insertions(+), 55 deletions(-)
create mode 100644 client/src/__tests__/hosts.test.tsx
create mode 100644 packages/chat/src/core/documents.ts
rename {client/src/components/Chat/Subagents => packages/chat/src/react/subagents}/author.tsx (94%)
diff --git a/client/src/App.jsx b/client/src/App.jsx
index 19318aae21..a03ebdf904 100644
--- a/client/src/App.jsx
+++ b/client/src/App.jsx
@@ -17,6 +17,7 @@ import { initializeFontSize } from '~/store/fontSize';
import { reopenTermsOnRefusal } from '~/utils/terms';
import { LiveAnnouncer } from '~/a11y';
import { router } from './routes';
+import '~/Providers/MessagePartsHostContext';
import '~/Providers/MessagesHostContext';
const App = () => {
diff --git a/client/src/Providers/MessagesHostContext.tsx b/client/src/Providers/MessagesHostContext.tsx
index 7a6b7f20d8..b99eaf4767 100644
--- a/client/src/Providers/MessagesHostContext.tsx
+++ b/client/src/Providers/MessagesHostContext.tsx
@@ -12,6 +12,7 @@ import type {
import type { TMessage } from 'librechat-data-provider';
import useConversationSeen from '~/hooks/Conversations/useConversationSeen';
import useMessageScrolling from '~/hooks/Messages/useMessageScrolling';
+import MessageIcon from '~/components/Chat/Messages/MessageIcon';
import Files from '~/components/Chat/Messages/Content/Files';
import { useScreenshot } from '~/hooks/ScreenshotContext';
import { useForkConvoMutation } from '~/data-provider';
@@ -78,6 +79,7 @@ export const appMessagesHost: MessagesHost = {
useScreenshotTarget: () => useScreenshot().screenshotTargetRef,
useAutoScroll: () => useAtomValue(autoScrollAtom),
useConversationSeen,
+ renderMessageIcon: (props) => ,
};
setDefaultMessagesHost(appMessagesHost);
diff --git a/client/src/__tests__/hosts.test.tsx b/client/src/__tests__/hosts.test.tsx
new file mode 100644
index 0000000000..7c75b9b8fa
--- /dev/null
+++ b/client/src/__tests__/hosts.test.tsx
@@ -0,0 +1,52 @@
+import React from 'react';
+import { join } from 'path';
+import { readFileSync } from 'fs';
+import { render, screen } from '@testing-library/react';
+import { agentAuthor, useParentAuthor } from '@librechat/chat/react';
+import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
+
+jest.mock('~/components/Chat/Messages/MessageIcon', () => ({
+ __esModule: true,
+ default: ({ iconData }: { iconData?: { modelLabel?: string } }) => (
+ {iconData?.modelLabel}
+ ),
+}));
+
+/** The registrations the app entry performs, loaded the way `App.jsx` loads them. Nothing here
+ * imports a message component, so the hosts cannot arrive as a side effect of one. */
+const ENTRY_HOSTS = ['~/Providers/MessagePartsHostContext', '~/Providers/MessagesHostContext'];
+ENTRY_HOSTS.forEach((path) => jest.requireActual(path));
+
+function ParentAuthor() {
+ const author = useParentAuthor('conversation', 'message', 'Parent agent');
+ return (
+ <>
+ {author.name}
+ {author.icon}
+ >
+ );
+}
+
+describe('app host registration', () => {
+ it('registers both default hosts from the app entry', () => {
+ const entry = readFileSync(join(__dirname, '..', 'App.jsx'), 'utf8');
+ for (const path of ENTRY_HOSTS) {
+ expect(entry).toContain(`import '${path}';`);
+ }
+ });
+
+ it('renders subagent authors through the app hosts the entry registers', () => {
+ render(
+
+
+ {agentAuthor(undefined, 'Child agent').icon}
+ ,
+ );
+
+ expect(screen.getByTestId('parent-name')).toHaveTextContent('Parent agent');
+ expect(screen.getAllByTestId('app-message-icon').map((node) => node.textContent)).toEqual([
+ 'Parent agent',
+ 'Child agent',
+ ]);
+ });
+});
diff --git a/client/src/common/types.ts b/client/src/common/types.ts
index 1c7166a48a..22e2a940a6 100644
--- a/client/src/common/types.ts
+++ b/client/src/common/types.ts
@@ -8,6 +8,7 @@ import type {
NewConversationParams,
} from '@librechat/chat/react';
import type { UseMutationResult } from '@tanstack/react-query';
+import type { MessageIconData } from '@librechat/chat/react';
import type { ExtendedFile } from '@librechat/chat';
import type * as t from 'librechat-data-provider';
import type { LucideIcon } from 'lucide-react';
@@ -306,11 +307,7 @@ export type TMessageProps = {
setSiblingIdx?: ((value: number) => void | React.Dispatch>) | null;
};
-export type TMessageIcon = { endpoint?: string | null; isCreatedByUser?: boolean } & Pick<
- t.TConversation,
- 'modelLabel'
-> &
- Pick;
+export type TMessageIcon = MessageIconData;
export type TInitialProps = {
text: string;
diff --git a/client/src/components/Chat/Messages/Content/Parts/SubagentCall.tsx b/client/src/components/Chat/Messages/Content/Parts/SubagentCall.tsx
index b28f8b3fdc..1b97793c0f 100644
--- a/client/src/components/Chat/Messages/Content/Parts/SubagentCall.tsx
+++ b/client/src/components/Chat/Messages/Content/Parts/SubagentCall.tsx
@@ -13,6 +13,7 @@ import {
subagentStatusLabelKey,
getSubagentPrompt,
useParentSubagents,
+ isSelfSpawn as isSelfSpawnType,
} from '@librechat/chat/react';
import type {
PartMetadata,
@@ -22,7 +23,6 @@ import type {
} from 'librechat-data-provider';
import type { SubagentContentPreview } from '@librechat/chat/react';
import type { SubagentTickerLine } from '@librechat/chat';
-import { isSelfSpawn as isSelfSpawnType } from '~/components/Chat/Subagents/author';
import { useOpenSubagentPanel } from '~/components/Chat/Subagents/surface';
import { MessageContext } from '~/Providers/MessageContext';
import { useShareContext } from '~/Providers/ShareContext';
diff --git a/client/src/components/Chat/Messages/MessageIcon.tsx b/client/src/components/Chat/Messages/MessageIcon.tsx
index 83f2bc1dfe..ffb34bf2c5 100644
--- a/client/src/components/Chat/Messages/MessageIcon.tsx
+++ b/client/src/components/Chat/Messages/MessageIcon.tsx
@@ -1,7 +1,6 @@
import { useMemo, memo } from 'react';
import { getEndpointField } from 'librechat-data-provider';
-import type { Assistant, Agent } from 'librechat-data-provider';
-import type { TMessageIcon } from '~/common';
+import type { MessageIconProps } from '@librechat/chat/react';
import ConvoIconURL from '~/components/Endpoints/ConvoIconURL';
import { useShareContext } from '~/Providers/ShareContext';
import { useGetEndpointsQuery } from '~/data-provider';
@@ -9,12 +8,6 @@ import Icon from '~/components/Endpoints/Icon';
import { isImageURL } from '~/utils/icons';
import { getIconEndpoint } from '~/utils';
-type MessageIconProps = {
- iconData?: TMessageIcon;
- assistant?: Assistant;
- agent?: Agent;
-};
-
/**
* Compares only the fields MessageIcon actually renders.
* `agent.id` / `assistant.id` are intentionally omitted because
diff --git a/client/src/components/Chat/Messages/ui/WakeupRow.tsx b/client/src/components/Chat/Messages/ui/WakeupRow.tsx
index 26858a4fe7..278224424a 100644
--- a/client/src/components/Chat/Messages/ui/WakeupRow.tsx
+++ b/client/src/components/Chat/Messages/ui/WakeupRow.tsx
@@ -1,15 +1,15 @@
import { useMemo } from 'react';
import { findSubagentDispatch } from '@librechat/chat';
import { MessageRow } from '@librechat/chat/components';
-import { useParentSubagents } from '@librechat/chat/react';
-import type { WakeupTask } from '@librechat/chat';
-import type { ComponentProps } from 'react';
import {
+ useParentSubagents,
messageAuthor,
resolveSubagentAuthor,
findAgentAuthorMessage,
useParentAuthor,
-} from '~/components/Chat/Subagents/author';
+} from '@librechat/chat/react';
+import type { WakeupTask } from '@librechat/chat';
+import type { ComponentProps } from 'react';
import { useOptionalMessagesOperations } from '~/Providers/MessagesViewContext';
import { useShareContext } from '~/Providers/ShareContext';
import { useAgentsMapContext } from '~/Providers';
diff --git a/client/src/components/Chat/Messages/ui/__tests__/MessageRender.wakeup.spec.tsx b/client/src/components/Chat/Messages/ui/__tests__/MessageRender.wakeup.spec.tsx
index 7843fd77a0..d52ac4f450 100644
--- a/client/src/components/Chat/Messages/ui/__tests__/MessageRender.wakeup.spec.tsx
+++ b/client/src/components/Chat/Messages/ui/__tests__/MessageRender.wakeup.spec.tsx
@@ -7,6 +7,8 @@ import type { TMessageChatContext } from '~/common';
import { ShareMessagesProvider } from '~/components/Share/ShareMessagesProvider';
import { ShareContext } from '~/Providers/ShareContext';
import MessageRender from '../MessageRender';
+import '~/Providers/MessagePartsHostContext';
+import '~/Providers/MessagesHostContext';
const mockAgentsMap = {
agent_reviewer: { id: 'agent_reviewer', name: 'Code Reviewer' },
diff --git a/client/src/components/Chat/Subagents/SharedSubagentActivityDialog.test.tsx b/client/src/components/Chat/Subagents/SharedSubagentActivityDialog.test.tsx
index de2a25e5e7..76928e1d9b 100644
--- a/client/src/components/Chat/Subagents/SharedSubagentActivityDialog.test.tsx
+++ b/client/src/components/Chat/Subagents/SharedSubagentActivityDialog.test.tsx
@@ -7,6 +7,8 @@ import SharedSubagentActivityDialog from './SharedSubagentActivityDialog';
import { MessageContext } from '~/Providers/MessageContext';
import { ShareContext } from '~/Providers/ShareContext';
import { ChatSurfaceHarness } from 'test/harness';
+import '~/Providers/MessagePartsHostContext';
+import '~/Providers/MessagesHostContext';
const mockUseSubagentThreadQuery = jest.fn();
diff --git a/client/src/components/Chat/Subagents/SharedSubagentActivityDialog.tsx b/client/src/components/Chat/Subagents/SharedSubagentActivityDialog.tsx
index 96b3697b7e..236308fbfc 100644
--- a/client/src/components/Chat/Subagents/SharedSubagentActivityDialog.tsx
+++ b/client/src/components/Chat/Subagents/SharedSubagentActivityDialog.tsx
@@ -5,15 +5,13 @@ import {
activeSubagentPanel,
adaptLivePersistedActivity,
resolveSubagentAgentId,
-} from '@librechat/chat/react';
-import type { TMessage } from 'librechat-data-provider';
-import {
isSelfSpawn as isSelfSpawnType,
messageAuthor,
findAgentLaneId,
resolveSubagentAuthor,
findAgentAuthorMessage,
-} from './author';
+} from '@librechat/chat/react';
+import type { TMessage } from 'librechat-data-provider';
import { MessageSurfaceContext } from '~/components/Chat/Messages/ui/surface';
import { SubagentActivityScrollSurface } from './SubagentActivity';
import SubagentConversation from './SubagentConversation';
diff --git a/client/src/components/Chat/Subagents/SubagentConversation.test.tsx b/client/src/components/Chat/Subagents/SubagentConversation.test.tsx
index 5df0773219..d9d9e3fa2e 100644
--- a/client/src/components/Chat/Subagents/SubagentConversation.test.tsx
+++ b/client/src/components/Chat/Subagents/SubagentConversation.test.tsx
@@ -8,9 +8,8 @@ import type {
TMessage,
TMessageContentParts,
} from 'librechat-data-provider';
-import type { ChildConversationTurn } from '@librechat/chat/react';
+import type { ChildConversationTurn, TurnAuthor } from '@librechat/chat/react';
import type { ChatContract } from '~/hooks/Chat/contract';
-import type { TurnAuthor } from './author';
import SubagentConversation from './SubagentConversation';
import { ChatContext } from '~/Providers/ChatContext';
import { ChatSurfaceHarness } from 'test/harness';
diff --git a/client/src/components/Chat/Subagents/SubagentConversation.tsx b/client/src/components/Chat/Subagents/SubagentConversation.tsx
index a8f98b50d4..7c5f56bad2 100644
--- a/client/src/components/Chat/Subagents/SubagentConversation.tsx
+++ b/client/src/components/Chat/Subagents/SubagentConversation.tsx
@@ -22,13 +22,12 @@ import {
ElapsedTimer,
MessageRow,
} from '@librechat/chat/components';
-import type { ChildConversationTurn, ToolContentQuery } from '@librechat/chat/react';
+import type { ChildConversationTurn, ToolContentQuery, TurnAuthor } from '@librechat/chat/react';
import type { TMessage, TMessageContentParts } from 'librechat-data-provider';
import type { ReactNode } from 'react';
import type { TaskContentScope } from '~/data-provider/Subagents/content';
import type { MessagePartsHost } from '~/hooks/Chat/contract';
import type { TranslationKeys } from '~/hooks';
-import type { TurnAuthor } from './author';
import {
TaskContentScopeContext,
useSubagentTaskContentQuery,
diff --git a/client/src/components/Chat/Subagents/SubagentThreadPanel.test.tsx b/client/src/components/Chat/Subagents/SubagentThreadPanel.test.tsx
index bf87e75738..08c62328d7 100644
--- a/client/src/components/Chat/Subagents/SubagentThreadPanel.test.tsx
+++ b/client/src/components/Chat/Subagents/SubagentThreadPanel.test.tsx
@@ -21,6 +21,8 @@ import { ChatSurfaceHarness, testChatSurface } from 'test/harness';
import SubagentThreadPanel from './SubagentThreadPanel';
import { useOpenSubagentPanel } from './surface';
import { getDraft } from '~/utils';
+import '~/Providers/MessagePartsHostContext';
+import '~/Providers/MessagesHostContext';
const mockUseSubagentThreadQuery = jest.fn();
const mockUseToolCallPartQuery = jest.fn(
diff --git a/client/src/components/Chat/Subagents/SubagentThreadPanel.tsx b/client/src/components/Chat/Subagents/SubagentThreadPanel.tsx
index c8fd8ad6eb..667d755370 100644
--- a/client/src/components/Chat/Subagents/SubagentThreadPanel.tsx
+++ b/client/src/components/Chat/Subagents/SubagentThreadPanel.tsx
@@ -31,6 +31,12 @@ import {
isLiveSubagentStatus,
getSubagentPrompt,
useParentSubagents,
+ agentAuthor,
+ resolveSubagentAuthor,
+ isSelfSpawn as isSelfSpawnType,
+ resolveChildAgent,
+ readableSubagentType,
+ useParentAuthor,
} from '@librechat/chat/react';
import type {
ParentSubagentTaskSummary,
@@ -51,14 +57,6 @@ import {
useSubagentControlMutation,
useSubagentThreadQuery,
} from '~/data-provider';
-import {
- agentAuthor,
- resolveSubagentAuthor,
- isSelfSpawn as isSelfSpawnType,
- resolveChildAgent,
- readableSubagentType,
- useParentAuthor,
-} from './author';
import SubagentActivity, { SubagentActivityScrollSurface } from './SubagentActivity';
import ApprovalProvider from '~/components/Chat/Messages/Content/ApprovalContext';
import { TaskContentScopeContext } from '~/data-provider/Subagents/content';
diff --git a/client/src/components/Chat/Subagents/author.public.test.tsx b/client/src/components/Chat/Subagents/author.public.test.tsx
index 3d44030c3e..c86726e105 100644
--- a/client/src/components/Chat/Subagents/author.public.test.tsx
+++ b/client/src/components/Chat/Subagents/author.public.test.tsx
@@ -1,10 +1,11 @@
import { RecoilRoot } from 'recoil';
import { render, screen, waitFor } from '@testing-library/react';
+import { agentAuthor, messageAuthor } from '@librechat/chat/react';
import { dataService, EModelEndpoint } from 'librechat-data-provider';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import type { TMessage } from 'librechat-data-provider';
import { ShareContext } from '~/Providers/ShareContext';
-import { agentAuthor, messageAuthor } from './author';
+import '~/Providers/MessagesHostContext';
jest.mock('librechat-data-provider', () => {
const actual = jest.requireActual('librechat-data-provider');
diff --git a/client/src/components/Chat/Subagents/author.test.ts b/client/src/components/Chat/Subagents/author.test.ts
index d0161b55c4..8ef48a5cff 100644
--- a/client/src/components/Chat/Subagents/author.test.ts
+++ b/client/src/components/Chat/Subagents/author.test.ts
@@ -1,5 +1,4 @@
import { ContentTypes, EModelEndpoint } from 'librechat-data-provider';
-import type { TMessage } from 'librechat-data-provider';
import {
isSelfSpawn,
messageAuthor,
@@ -10,7 +9,8 @@ import {
readableSubagentType,
readableSubagentTitle,
findAgentAuthorMessage,
-} from './author';
+} from '@librechat/chat/react';
+import type { TMessage } from 'librechat-data-provider';
function message(
messageId: string,
diff --git a/client/src/components/Share/Message.wakeup.spec.tsx b/client/src/components/Share/Message.wakeup.spec.tsx
index 8b5831720f..0fc023afb6 100644
--- a/client/src/components/Share/Message.wakeup.spec.tsx
+++ b/client/src/components/Share/Message.wakeup.spec.tsx
@@ -9,6 +9,8 @@ import { ShareMessagesProvider } from './ShareMessagesProvider';
import { AgentsMapContext } from '~/Providers/AgentsMapContext';
import { ShareContext } from '~/Providers/ShareContext';
import MessagesView from './MessagesView';
+import '~/Providers/MessagePartsHostContext';
+import '~/Providers/MessagesHostContext';
jest.mock('librechat-data-provider', () => {
const actual = jest.requireActual('librechat-data-provider');
diff --git a/packages/chat/src/__fixtures__/messagesHost.ts b/packages/chat/src/__fixtures__/messagesHost.ts
index 7918fe485c..28c11b6255 100644
--- a/packages/chat/src/__fixtures__/messagesHost.ts
+++ b/packages/chat/src/__fixtures__/messagesHost.ts
@@ -26,6 +26,7 @@ export function createMessagesHost(overrides: Partial = {}): Messa
useScreenshotTarget: () => undefined,
useAutoScroll: () => false,
useConversationSeen: () => () => undefined,
+ renderMessageIcon: () => null,
...overrides,
};
}
diff --git a/packages/chat/src/components/messages/HeaderLabel.tsx b/packages/chat/src/components/messages/HeaderLabel.tsx
index 71fa7a7f55..61182ab369 100644
--- a/packages/chat/src/components/messages/HeaderLabel.tsx
+++ b/packages/chat/src/components/messages/HeaderLabel.tsx
@@ -1,19 +1,13 @@
import { cn, useLocalize } from '@librechat/client';
import type { ReactElement } from 'react';
+import { isDocumentId } from '../../core/documents';
type HeaderLabelProps = {
label: string;
hoverLabel?: string | null;
};
-/** Agents and assistants are keyed by document id, and a message's `model`
- * carries that id rather than a model name, so neither prefix may reach the
- * header. */
-const DOCUMENT_ID_PREFIXES = ['agent_', 'asst_'];
-
-/** An agent or assistant document id: a storage key, never a name to show. */
-export const isDocumentId = (value: string): boolean =>
- DOCUMENT_ID_PREFIXES.some((prefix) => value.startsWith(prefix));
+export { isDocumentId };
/** Skip document ids so the hover label is a real model name. */
export function getHeaderModelName(
diff --git a/packages/chat/src/core/documents.ts b/packages/chat/src/core/documents.ts
new file mode 100644
index 0000000000..0840867c73
--- /dev/null
+++ b/packages/chat/src/core/documents.ts
@@ -0,0 +1,8 @@
+/** Agents and assistants are keyed by document id, and a message's `model`
+ * carries that id rather than a model name, so neither prefix may reach the
+ * header. */
+const DOCUMENT_ID_PREFIXES = ['agent_', 'asst_'];
+
+/** An agent or assistant document id: a storage key, never a name to show. */
+export const isDocumentId = (value: string): boolean =>
+ DOCUMENT_ID_PREFIXES.some((prefix) => value.startsWith(prefix));
diff --git a/packages/chat/src/core/index.ts b/packages/chat/src/core/index.ts
index e95b2a45db..4dd64333ad 100644
--- a/packages/chat/src/core/index.ts
+++ b/packages/chat/src/core/index.ts
@@ -25,3 +25,4 @@ export { strongDirection } from './direction';
export * from './shortcuts';
export { removeCharIfLast } from './textarea';
export * from './pane';
+export * from './documents';
diff --git a/packages/chat/src/react.ts b/packages/chat/src/react.ts
index 2d0d51e367..f3b5e26a75 100644
--- a/packages/chat/src/react.ts
+++ b/packages/chat/src/react.ts
@@ -127,6 +127,7 @@ export {
useMessagesHost,
MessagesHostProvider,
setDefaultMessagesHost,
+ MessageIconSlot,
} from './react/messages/host';
export type {
ForkEvents,
@@ -135,6 +136,8 @@ export type {
ForkConversation,
MessagesScrolling,
ReportNearBottom,
+ MessageIconData,
+ MessageIconProps,
} from './react/messages/host';
export {
SoleToolContext,
diff --git a/packages/chat/src/react/messages/host.tsx b/packages/chat/src/react/messages/host.tsx
index 4f729e65ca..147a5a45b6 100644
--- a/packages/chat/src/react/messages/host.tsx
+++ b/packages/chat/src/react/messages/host.tsx
@@ -1,5 +1,11 @@
import { useRef, createContext, useContext } from 'react';
-import type { TMessage, TForkConvoRequest } from 'librechat-data-provider';
+import type {
+ Agent,
+ TMessage,
+ Assistant,
+ TConversation,
+ TForkConvoRequest,
+} from 'librechat-data-provider';
import type { MouseEvent, ReactNode, RefObject } from 'react';
/** The scroll machinery of the message list, as the app's scrolling hook drives it. */
@@ -45,6 +51,21 @@ export type ForkEvents = {
/** Starts a fork of a conversation. */
export type ForkConversation = (request: TForkConvoRequest, events: ForkEvents) => void;
+/** What a message author's icon is drawn from: the endpoint and model, or the agent or
+ * assistant that wrote it. */
+export type MessageIconData = { endpoint?: string | null; isCreatedByUser?: boolean } & Pick<
+ TConversation,
+ 'modelLabel'
+> &
+ Pick;
+
+/** The props the app's message icon renders from. */
+export type MessageIconProps = {
+ iconData?: MessageIconData;
+ assistant?: Assistant;
+ agent?: Agent;
+};
+
/**
* Everything the message list reads from the app: viewer preferences, and render slots for the
* pieces of a row that have not moved into this package yet. Members are hooks or slots, called
@@ -83,6 +104,9 @@ export interface MessagesHost {
measureNearBottom: () => boolean | null,
isResponseRendered: (messageId: string) => boolean,
) => ReportNearBottom;
+
+ /** Renders a message author's icon with the app's endpoint and avatar icons. */
+ renderMessageIcon: (props: MessageIconProps) => ReactNode;
}
const noop = (): void => undefined;
@@ -124,6 +148,7 @@ const fallbackHost: MessagesHost = {
useScreenshotTarget: () => useRef(null),
useAutoScroll: () => false,
useConversationSeen: () => ignoreNearBottom,
+ renderMessageIcon: () => null,
};
const MessagesHostContext = createContext(null);
@@ -153,3 +178,8 @@ export function MessagesHostProvider({
export function useMessagesHost(): MessagesHost {
return useContext(MessagesHostContext) ?? defaultHost;
}
+
+/** A message author's icon, drawn by the host's slot. */
+export function MessageIconSlot(props: MessageIconProps): ReactNode {
+ return useMessagesHost().renderMessageIcon(props);
+}
diff --git a/client/src/components/Chat/Subagents/author.tsx b/packages/chat/src/react/subagents/author.tsx
similarity index 94%
rename from client/src/components/Chat/Subagents/author.tsx
rename to packages/chat/src/react/subagents/author.tsx
index 5dc9821410..ec1466334d 100644
--- a/client/src/components/Chat/Subagents/author.tsx
+++ b/packages/chat/src/react/subagents/author.tsx
@@ -1,12 +1,11 @@
import { useMemo, useSyncExternalStore } from 'react';
import { useQueryClient } from '@tanstack/react-query';
-import { findSubagentDispatch } from '@librechat/chat';
-import { isDocumentId } from '@librechat/chat/components';
import { EModelEndpoint, QueryKeys, ContentTypes } from 'librechat-data-provider';
import type { Agent, TMessage } from 'librechat-data-provider';
import type { ReactNode } from 'react';
-import MessageIcon from '~/components/Chat/Messages/MessageIcon';
-import { useAgentsMapContext } from '~/Providers';
+import { findSubagentDispatch, isDocumentId } from '../../core';
+import { MessageIconSlot } from '../messages/host';
+import { useMessagePartsHost } from '../host';
/** Who wrote a turn, in the form main chat's message header shows an author. */
export type TurnAuthor = { name: string; icon: ReactNode; agent?: Agent; agentId?: string };
@@ -136,7 +135,7 @@ export function agentAuthor(agent: Agent | undefined, fallbackName: string): Tur
agentId: agent?.id,
name,
icon: (
-
@@ -191,7 +190,7 @@ export function messageAuthor(
agentId,
name,
icon: (
- messageAuthor(snapshot?.message, agentsMap, fallbackName, snapshot?.laneId),
- [agentsMap, fallbackName, snapshot],
+ () =>
+ messageAuthor(
+ snapshot?.message,
+ agent == null ? undefined : { [agentId]: agent },
+ fallbackName,
+ snapshot?.laneId,
+ ),
+ [agent, agentId, fallbackName, snapshot],
);
}
diff --git a/packages/chat/src/react/subagents/index.ts b/packages/chat/src/react/subagents/index.ts
index 686cebb201..0e66f03e3e 100644
--- a/packages/chat/src/react/subagents/index.ts
+++ b/packages/chat/src/react/subagents/index.ts
@@ -9,3 +9,4 @@ export * from './recovery';
export * from './eventSelection';
export * from './attachments';
export * from './parents';
+export * from './author';
diff --git a/packages/chat/test/consumer.spec.tsx b/packages/chat/test/consumer.spec.tsx
index 375b4816dd..78d0c8a860 100644
--- a/packages/chat/test/consumer.spec.tsx
+++ b/packages/chat/test/consumer.spec.tsx
@@ -204,6 +204,7 @@ const messagesHost: MessagesHost = {
useScreenshotTarget: () => undefined,
useAutoScroll: () => false,
useConversationSeen: () => () => undefined,
+ renderMessageIcon: () => null,
};
const renderers: PartRenderers = {