diff --git a/client/src/components/Chat/ChatView.tsx b/client/src/components/Chat/ChatView.tsx
index e1504af643..61d67cd9f8 100644
--- a/client/src/components/Chat/ChatView.tsx
+++ b/client/src/components/Chat/ChatView.tsx
@@ -1,10 +1,10 @@
-import { memo, useMemo } from 'react';
+import { memo } from 'react';
import { useAtomValue } from 'jotai';
import { useRecoilValue } from 'recoil';
import { useForm } from 'react-hook-form';
import { useParams } from 'react-router-dom';
-import { Constants, buildTree } from 'librechat-data-provider';
-import { ChatPane, getChatPaneView, QueuedTurnPortalProvider } from '@librechat/chat/components';
+import { Constants } from 'librechat-data-provider';
+import { ChatScreen, QueuedTurnPortalProvider } from '@librechat/chat/components';
import {
submissionByIndex,
ChatSessionProvider,
@@ -22,8 +22,8 @@ import ApprovalProvider from './Messages/Content/ApprovalContext';
import ConversationStarters from './Input/ConversationStarters';
import ProjectBadge from '~/components/Projects/ProjectBadge';
import { OwnerTextProvider } from './Messages/PrivateText';
-import { useAddedResponse, useLocalize } from '~/hooks';
import MessagesView from './Messages/MessagesView';
+import { useAddedResponse } from '~/hooks';
import Presentation from './Presentation';
import ChatForm from './Input/ChatForm';
import { TraceSurface } from './Trace';
@@ -51,7 +51,6 @@ function ChatViewPane({
messages: TMessage[] | null;
isLoading: boolean;
}) {
- const localize = useLocalize();
const rootSubmission = useAtomValue(submissionByIndex(index));
const { saveDrafts } = useChatSettings();
const enterToSend = useRecoilValue(store.enterToSend);
@@ -67,7 +66,7 @@ function ChatViewPane({
useScrollbarGutterSeed();
/** A conversation carries a footer only for configured content, and the
- * composer's clearance has to account for the bar when it does — including
+ * composer's clearance has to account for the bar when it does, including
* before the config answers, so a cold load does not jump. */
const configuredFooter = useConfiguredFooter();
const landingFooter = useLandingFooter();
@@ -77,49 +76,9 @@ function ChatViewPane({
});
const fileMap = useFileMapContext();
-
- const messagesTree = useMemo(() => {
- const dataTree = buildTree({ messages, fileMap });
- return dataTree?.length === 0 ? null : (dataTree ?? null);
- }, [messages, fileMap]);
-
const chat = useChatContext();
const addedChatHelpers = useAddedResponse();
- const activeConversation =
- chat.conversation?.conversationId === conversationId ? chat.conversation : undefined;
- const activeSubagentThread = activeConversation?.subagentThread;
- const chatProjectId = activeConversation?.chatProjectId || undefined;
-
- const view = getChatPaneView({
- conversationId,
- isLoading,
- hasMessages: messagesTree != null && messagesTree.length > 0,
- });
- const { isLanding: isLandingPage } = view;
-
- /** The welcome screen carries the full footer unless the deployment turned it
- * off; otherwise a footer bar renders only for configured content. */
- const fullFooter = isLandingPage && landingFooter;
- const footerBelow = fullFooter || configuredFooter;
- const isProjectLandingPage = isLandingPage && project != null;
-
- const chatFormPlaceholder =
- isProjectLandingPage && project
- ? localize('com_ui_new_chat_in_project', { name: project.name })
- : undefined;
-
- // Recoil conversation can lag the route during navigation; only announce a
- // title that belongs to the conversation currently in the URL.
- const conversationTitle = activeConversation?.title?.trim();
- const pageHeading =
- isLandingPage || !conversationTitle ? localize('com_ui_new_chat') : conversationTitle;
- const parentConversationId = activeSubagentThread?.parentConversationId;
- /** Durable child threads are an execution record owned by their parent agent.
- * Human continuation is a separate future fork/promotion flow, never an
- * in-place mutation of this canonical child transcript. */
- const isSubagentThreadReadOnly = activeSubagentThread != null;
-
return (
@@ -129,18 +88,20 @@ function ChatViewPane({
-
- }
- badge={chatProjectId ? : null}
- messages={}
+ conversationId={conversationId}
+ messages={messages}
+ fileMap={fileMap}
+ isLoading={isLoading}
+ project={project}
+ landingFooter={landingFooter}
+ configuredFooter={configuredFooter}
+ renderHeader={({ parentConversationId, readOnly }) => (
+
+ )}
+ renderBadge={(projectId) => }
+ renderMessages={(thread) => }
landing={}
renderColumn={(column) => (
)}
starters={}
- readOnlyNote={
- isSubagentThreadReadOnly
- ? localize('com_ui_subagent_thread_read_only')
- : undefined
- }
- composer={
+ renderComposer={({ isLanding, footerBelow, project, placeholder }) => (
- }
+ )}
/* The generic disclaimer and the policy links are the welcome
screen's; a deployment's own footer stays with the
conversation that always showed it. */
- bandFooter={
- !fullFooter && configuredFooter ? : null
+ renderFooter={(placement) =>
+ placement === 'band' ? :
}
- footer={fullFooter ? : null}
- renderMascot={(bandRef) => (
-
+ renderMascot={(bandRef, landing) => (
+
)}
/>
diff --git a/client/src/components/Chat/__tests__/ChatView.subagent.spec.tsx b/client/src/components/Chat/__tests__/ChatView.subagent.spec.tsx
index d2041c4f19..3a81c16899 100644
--- a/client/src/components/Chat/__tests__/ChatView.subagent.spec.tsx
+++ b/client/src/components/Chat/__tests__/ChatView.subagent.spec.tsx
@@ -21,6 +21,7 @@ jest.mock('react-hook-form', () => ({
jest.mock('@librechat/client', () => ({
Spinner: () => ,
cn: (...values: Array) => values.filter(Boolean).join(' '),
+ useLocalize: () => (key: string) => key,
}));
jest.mock('librechat-data-provider', () => ({
diff --git a/packages/chat/src/components.ts b/packages/chat/src/components.ts
index 4835bdc938..6ba29c8cb3 100644
--- a/packages/chat/src/components.ts
+++ b/packages/chat/src/components.ts
@@ -132,6 +132,10 @@ export { default as ChatPane } from './components/pane/ChatPane';
export { getChatPaneView } from './components/pane/view';
export type { ChatPaneProps } from './components/pane/ChatPane';
export type { ChatPaneView, ChatPaneColumn } from './components/pane/view';
+export { default as ChatScreen } from './components/pane/Screen';
+export { getChatPaneChrome } from './components/pane/chrome';
+export type { ChatScreenProps, ChatScreenComposerProps } from './components/pane/Screen';
+export type { ChatPaneChrome } from './components/pane/chrome';
/** Message list root: the scroll container, mount window and pending tail around the thread. */
export { default as MessagesView } from './components/messages/MessagesView';
diff --git a/packages/chat/src/components/pane/Screen.tsx b/packages/chat/src/components/pane/Screen.tsx
new file mode 100644
index 0000000000..33d944d11d
--- /dev/null
+++ b/packages/chat/src/components/pane/Screen.tsx
@@ -0,0 +1,132 @@
+import { useMemo } from 'react';
+import { useLocalize } from '@librechat/client';
+import { buildTree } from 'librechat-data-provider';
+import type { TChatProject, TFile, TMessage } from 'librechat-data-provider';
+import type { ReactElement, ReactNode, RefObject } from 'react';
+import type { ChatPaneProps } from './ChatPane';
+import type { ChatPaneChrome } from './chrome';
+import { useChatContext } from '../../react/chat/context';
+import { getChatPaneChrome } from './chrome';
+import { getChatPaneView } from './view';
+import ChatPane from './ChatPane';
+
+/** What the composer slot needs from the pane's decisions. */
+export type ChatScreenComposerProps = {
+ isLanding: boolean;
+ /** A footer sits below the composer, so its clearance accounts for the bar. */
+ footerBelow: boolean;
+ /** The project a new chat starts in, on a project's welcome screen. */
+ project?: TChatProject;
+ /** The composer's placeholder on a project's welcome screen. */
+ placeholder?: string;
+};
+
+export type ChatScreenProps = Pick<
+ ChatPaneProps,
+ 'index' | 'landing' | 'renderColumn' | 'starters'
+> & {
+ /** The routed conversation. */
+ conversationId?: string;
+ /** The session's messages, flat; `null` before it has any. */
+ messages: TMessage[] | null;
+ /** The conversation's files by id, which hydrate the files of the tree's messages. */
+ fileMap?: Record;
+ /** The session is loading the routed conversation. */
+ isLoading: boolean;
+ /** The project the route opens a new chat in. */
+ project?: TChatProject;
+ /** The deployment shows the full footer on the welcome screen. */
+ landingFooter: boolean;
+ /** The deployment configured footer content. */
+ configuredFooter: boolean;
+ /** The pane's header, given the pane's decisions (a subagent thread's parent, read-only). */
+ renderHeader?: (chrome: ChatPaneChrome) => ReactNode;
+ /** The badge of the routed conversation's project. */
+ renderBadge?: (projectId: string) => ReactNode;
+ /** The message list, given the session's messages and the tree built from them. */
+ renderMessages: (props: {
+ messagesTree: TMessage[] | null;
+ messages: TMessage[] | null;
+ }) => ReactNode;
+ /** The composer, unless the thread is read-only. */
+ renderComposer?: (props: ChatScreenComposerProps) => ReactNode;
+ /** The footer: the full one below the column, or the configured one inside the composer band. */
+ renderFooter?: (placement: 'full' | 'band') => ReactNode;
+ /** Rendered beside the composer band, given the band and whether the welcome screen shows. */
+ renderMascot?: (bandRef: RefObject, isLanding: boolean) => ReactNode;
+};
+
+/**
+ * A chat screen: builds the message tree from the session, decides the pane's layout, heading,
+ * footers, project and read-only state, and lays them out in `ChatPane`. The app supplies the
+ * surfaces as slots; the slots that depend on a decision receive it instead of recomputing it.
+ */
+export default function ChatScreen({
+ index = 0,
+ conversationId,
+ messages,
+ fileMap,
+ isLoading,
+ project,
+ landingFooter,
+ configuredFooter,
+ landing,
+ renderColumn,
+ starters,
+ renderHeader,
+ renderBadge,
+ renderMessages,
+ renderComposer,
+ renderFooter,
+ renderMascot,
+}: ChatScreenProps): ReactElement {
+ const localize = useLocalize();
+ const { conversation } = useChatContext();
+
+ const messagesTree = useMemo(() => {
+ const tree = buildTree({ messages, fileMap });
+ return tree?.length === 0 ? null : (tree ?? null);
+ }, [messages, fileMap]);
+
+ const view = getChatPaneView({
+ conversationId,
+ isLoading,
+ hasMessages: messagesTree != null && messagesTree.length > 0,
+ });
+ const chrome = getChatPaneChrome({
+ view,
+ conversation,
+ conversationId,
+ project,
+ landingFooter,
+ configuredFooter,
+ });
+ const { landingProject } = chrome;
+
+ return (
+ renderMascot(bandRef, view.isLanding) : undefined}
+ />
+ );
+}
diff --git a/packages/chat/src/components/pane/__tests__/Screen.spec.tsx b/packages/chat/src/components/pane/__tests__/Screen.spec.tsx
new file mode 100644
index 0000000000..db88f869bc
--- /dev/null
+++ b/packages/chat/src/components/pane/__tests__/Screen.spec.tsx
@@ -0,0 +1,148 @@
+/**
+ * @jest-environment jsdom
+ */
+import { Provider, createStore } from 'jotai';
+import { render, screen } from '@testing-library/react';
+import type { TChatProject, TConversation, TFile, TMessage } from 'librechat-data-provider';
+import type { ChatContract } from '../../../react/chat/contract';
+import type { ChatScreenProps } from '../Screen';
+import { ChatContext } from '../../../react/chat/context';
+import { initEnglish } from '../../../__fixtures__/i18n';
+import ChatScreen from '../Screen';
+
+beforeAll(initEnglish);
+
+const ROOT = '00000000-0000-0000-0000-000000000000';
+
+const messages = [
+ {
+ messageId: 'u1',
+ parentMessageId: ROOT,
+ conversationId: 'c1',
+ isCreatedByUser: true,
+ text: 'Hi',
+ files: [{ file_id: 'f1' }],
+ },
+ {
+ messageId: 'a1',
+ parentMessageId: 'u1',
+ conversationId: 'c1',
+ isCreatedByUser: false,
+ text: 'Hello',
+ },
+] as TMessage[];
+
+const project = { _id: 'p1', name: 'Research' } as unknown as TChatProject;
+
+function renderScreen(
+ props: Partial,
+ conversation: Partial | null = { conversationId: 'c1', title: 'Plans' },
+ fileMap?: Record,
+) {
+ return render(
+
+
+ (
+
+ )}
+ renderBadge={(projectId) => Badge {projectId}
}
+ renderMessages={({ messagesTree }) => (
+
+ {messagesTree?.map((message) => (
+ -
+ {message.text} {message.files?.map((file) => file.filename).join(',')}
+ {message.children?.map((child) => child.text).join(',')}
+
+ ))}
+
+ )}
+ landing={Welcome
}
+ renderComposer={({ isLanding, footerBelow, project: landingProject, placeholder }) => (
+
+ )}
+ renderFooter={(placement) => }
+ renderMascot={(_bandRef, isLanding) => (
+
+ )}
+ {...props}
+ />
+
+ ,
+ );
+}
+
+const composer = () => screen.getByRole('textbox', { name: 'Message' });
+
+describe('ChatScreen', () => {
+ it('builds the tree from the session, hydrating files from the host, under the conversation title', () => {
+ renderScreen({}, undefined, { f1: { file_id: 'f1', filename: 'notes.txt' } as TFile });
+
+ expect(screen.getByRole('heading', { level: 1 })).toHaveTextContent('Plans');
+ const roots = screen.getAllByRole('listitem');
+ expect(roots).toHaveLength(1);
+ expect(roots[0]).toHaveTextContent('Hi notes.txt');
+ expect(roots[0]).toHaveTextContent('Hello');
+ expect(composer()).toHaveAttribute('data-landing', 'false');
+ expect(screen.getByTestId('mascot')).toHaveAttribute('data-landing', 'false');
+ });
+
+ it('greets a new chat with the new-chat heading, the full footer and the welcome screen', () => {
+ const { container } = renderScreen({ conversationId: undefined, messages: null }, null);
+
+ expect(screen.getByRole('heading', { level: 1 })).toHaveTextContent('New chat');
+ expect(screen.getByText('Welcome')).toBeInTheDocument();
+ expect(composer()).toHaveAttribute('data-landing', 'true');
+ expect(composer()).toHaveAttribute('data-footer-below', 'true');
+ expect(container.querySelectorAll('footer')).toHaveLength(1);
+ expect(container.querySelector('footer')).toHaveAttribute('data-placement', 'full');
+ });
+
+ it("keeps a deployment's configured footer in the conversation's composer band", () => {
+ const { container } = renderScreen({ configuredFooter: true });
+
+ expect(container.querySelector('footer')).toHaveAttribute('data-placement', 'band');
+ expect(composer()).toHaveAttribute('data-footer-below', 'true');
+ });
+
+ it("starts a new chat in the routed project with the project's placeholder", () => {
+ renderScreen({ conversationId: undefined, messages: null, project }, null);
+
+ expect(composer()).toHaveAttribute('data-project', 'Research');
+ expect(composer()).toHaveAttribute('placeholder', expect.stringContaining('Research'));
+ });
+
+ it("badges the conversation's project", () => {
+ renderScreen({}, { conversationId: 'c1', title: 'Plans', chatProjectId: 'p1' });
+
+ expect(screen.getByText('Badge p1')).toBeInTheDocument();
+ });
+
+ it("replaces the composer with the read-only note in a subagent's thread", () => {
+ const { container } = renderScreen(
+ {},
+ {
+ conversationId: 'c1',
+ title: 'Child',
+ subagentThread: { parentConversationId: 'parent' } as TConversation['subagentThread'],
+ },
+ );
+
+ expect(screen.queryByRole('textbox', { name: 'Message' })).not.toBeInTheDocument();
+ expect(screen.getByText(/This child thread is view-only here/)).toBeInTheDocument();
+ expect(container.querySelector('header')).toHaveAttribute('data-read-only', 'true');
+ expect(container.querySelector('header')).toHaveAttribute('data-parent', 'parent');
+ });
+});
diff --git a/packages/chat/src/components/pane/__tests__/chrome.spec.ts b/packages/chat/src/components/pane/__tests__/chrome.spec.ts
new file mode 100644
index 0000000000..8c6dff71b0
--- /dev/null
+++ b/packages/chat/src/components/pane/__tests__/chrome.spec.ts
@@ -0,0 +1,190 @@
+import type { TChatProject, TConversation } from 'librechat-data-provider';
+import type { ChatPaneChrome } from '../chrome';
+import type { ChatPaneView } from '../view';
+import { getChatPaneChrome } from '../chrome';
+
+type Input = Parameters[0];
+
+/**
+ * The derivation as `ChatView` wrote it inline before it moved here, line for line, so the
+ * helper is held to the decisions the app made, not to a restatement of them.
+ */
+function inlineChatView({
+ view,
+ conversation,
+ conversationId,
+ project,
+ landingFooter,
+ configuredFooter,
+}: Input): ChatPaneChrome {
+ const activeConversation =
+ conversation?.conversationId === conversationId ? conversation : undefined;
+ const activeSubagentThread = activeConversation?.subagentThread;
+ const chatProjectId = activeConversation?.chatProjectId || undefined;
+ const { isLanding: isLandingPage } = view;
+ const fullFooter = isLandingPage && landingFooter;
+ const footerBelow = fullFooter || configuredFooter;
+ const isProjectLandingPage = isLandingPage && project != null;
+ const conversationTitle = activeConversation?.title?.trim();
+ const newChat = isLandingPage || !conversationTitle;
+ const parentConversationId = activeSubagentThread?.parentConversationId;
+ const isSubagentThreadReadOnly = activeSubagentThread != null;
+ return {
+ title: newChat ? null : (conversationTitle ?? null),
+ fullFooter,
+ bandFooter: !fullFooter && configuredFooter,
+ footerBelow,
+ landingProject: isProjectLandingPage ? project : undefined,
+ projectId: chatProjectId,
+ readOnly: isSubagentThreadReadOnly,
+ parentConversationId,
+ };
+}
+
+const project = { _id: 'p1', name: 'Research' } as unknown as TChatProject;
+const lineage = {
+ rootConversationId: 'parent',
+ parentConversationId: 'parent',
+ parentMessageId: 'm1',
+ parentToolCallId: 'call-1',
+ subagentType: 'researcher',
+ subagentKind: 'agent',
+ depth: 1,
+} as TConversation['subagentThread'];
+
+const conversations: Array = [
+ null,
+ { conversationId: 'c1', title: 'Plans' } as TConversation,
+ { conversationId: 'c1', title: ' Plans ' } as TConversation,
+ { conversationId: 'c1', title: ' ' } as TConversation,
+ { conversationId: 'c1' } as TConversation,
+ { conversationId: 'other', title: 'Lagging', chatProjectId: 'p2' } as TConversation,
+ { conversationId: 'c1', title: 'Child', subagentThread: lineage } as TConversation,
+ { conversationId: 'c1', title: 'In project', chatProjectId: 'p1' } as TConversation,
+ { conversationId: 'c1', title: 'Empty project', chatProjectId: '' } as TConversation,
+];
+
+const views: ChatPaneView[] = [
+ { isLanding: true, column: 'landing' },
+ { isLanding: true, column: 'loading' },
+ { isLanding: false, column: 'messages' },
+ { isLanding: false, column: 'loading' },
+];
+
+function* inputs(): Generator {
+ for (const view of views) {
+ for (const conversation of conversations) {
+ for (const conversationId of ['c1', undefined]) {
+ for (const routeProject of [undefined, project]) {
+ for (const landingFooter of [false, true]) {
+ for (const configuredFooter of [false, true]) {
+ yield {
+ view,
+ conversation,
+ conversationId,
+ project: routeProject,
+ landingFooter,
+ configuredFooter,
+ };
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+describe('getChatPaneChrome', () => {
+ it('makes the decisions ChatView made inline, for every combination', () => {
+ let cases = 0;
+ for (const input of inputs()) {
+ expect(getChatPaneChrome(input)).toEqual(inlineChatView(input));
+ cases += 1;
+ }
+ expect(cases).toBe(views.length * conversations.length * 2 * 2 * 2 * 2);
+ });
+
+ const conversationView: ChatPaneView = { isLanding: false, column: 'messages' };
+ const landingView: ChatPaneView = { isLanding: true, column: 'landing' };
+ const base = { landingFooter: true, configuredFooter: false };
+
+ it.each([
+ ['the routed conversation names the heading, trimmed', conversations[2], 'c1', 'Plans'],
+ ['a blank title falls back to the new-chat label', conversations[3], 'c1', null],
+ ['a conversation that lags the route never names it', conversations[5], 'c1', null],
+ ])('%s', (_name, conversation, conversationId, title) => {
+ const chrome = getChatPaneChrome({
+ ...base,
+ view: conversationView,
+ conversation,
+ conversationId,
+ });
+ expect(chrome.title).toBe(title);
+ });
+
+ it('labels the welcome screen as a new chat even when the conversation has a title', () => {
+ const chrome = getChatPaneChrome({
+ ...base,
+ view: landingView,
+ conversation: conversations[1],
+ conversationId: 'c1',
+ });
+ expect(chrome.title).toBeNull();
+ });
+
+ it.each([
+ [landingView, true, false, { fullFooter: true, bandFooter: false, footerBelow: true }],
+ [landingView, true, true, { fullFooter: true, bandFooter: false, footerBelow: true }],
+ [landingView, false, true, { fullFooter: false, bandFooter: true, footerBelow: true }],
+ [landingView, false, false, { fullFooter: false, bandFooter: false, footerBelow: false }],
+ [conversationView, true, false, { fullFooter: false, bandFooter: false, footerBelow: false }],
+ [conversationView, true, true, { fullFooter: false, bandFooter: true, footerBelow: true }],
+ ])('places the footers (%#)', (view, landingFooter, configuredFooter, expected) => {
+ expect(getChatPaneChrome({ view, landingFooter, configuredFooter })).toMatchObject(expected);
+ });
+
+ it('starts a new chat in the routed project only on the welcome screen', () => {
+ expect(getChatPaneChrome({ ...base, view: landingView, project }).landingProject).toBe(project);
+ expect(
+ getChatPaneChrome({ ...base, view: conversationView, project }).landingProject,
+ ).toBeUndefined();
+ });
+
+ it("badges the routed conversation's project, not a lagging one's", () => {
+ expect(
+ getChatPaneChrome({
+ ...base,
+ view: conversationView,
+ conversation: conversations[7],
+ conversationId: 'c1',
+ }).projectId,
+ ).toBe('p1');
+ expect(
+ getChatPaneChrome({
+ ...base,
+ view: conversationView,
+ conversation: conversations[5],
+ conversationId: 'c1',
+ }).projectId,
+ ).toBeUndefined();
+ });
+
+ it("makes a subagent's thread read-only and names its parent", () => {
+ expect(
+ getChatPaneChrome({
+ ...base,
+ view: conversationView,
+ conversation: conversations[6],
+ conversationId: 'c1',
+ }),
+ ).toMatchObject({ readOnly: true, parentConversationId: 'parent' });
+ expect(
+ getChatPaneChrome({
+ ...base,
+ view: conversationView,
+ conversation: conversations[6],
+ conversationId: undefined,
+ }),
+ ).toMatchObject({ readOnly: false, parentConversationId: undefined });
+ });
+});
diff --git a/packages/chat/src/components/pane/chrome.ts b/packages/chat/src/components/pane/chrome.ts
new file mode 100644
index 0000000000..bb11bf91ff
--- /dev/null
+++ b/packages/chat/src/components/pane/chrome.ts
@@ -0,0 +1,62 @@
+import type { TChatProject, TConversation } from 'librechat-data-provider';
+import type { ChatPaneView } from './view';
+
+/** What the pane shows around its column, derived from the session and the host's footers. */
+export type ChatPaneChrome = {
+ /** The conversation's title for the page heading, or `null` for the new-chat label. */
+ title: string | null;
+ /** The full footer below the column: the welcome screen, with the landing footer on. */
+ fullFooter: boolean;
+ /** The configured footer inside the composer band, wherever the full one is not shown. */
+ bandFooter: boolean;
+ /** Whether a footer sits below the composer, which the composer's clearance accounts for. */
+ footerBelow: boolean;
+ /** The project a new chat starts in, on a project's welcome screen. */
+ landingProject?: TChatProject;
+ /** The project of the routed conversation, for its badge. */
+ projectId?: string;
+ /** A subagent's thread: an execution record its parent owns, which the reader cannot continue. */
+ readOnly: boolean;
+ /** The conversation that owns a subagent's thread. */
+ parentConversationId?: string;
+};
+
+/**
+ * Derives the pane's chrome. The app's conversation can lag the route during navigation, so only
+ * a conversation whose id matches the routed one names the title, the project and the subagent
+ * lineage.
+ */
+export function getChatPaneChrome({
+ view,
+ conversation,
+ conversationId,
+ project,
+ landingFooter,
+ configuredFooter,
+}: {
+ view: ChatPaneView;
+ conversation?: TConversation | null;
+ /** The routed conversation. */
+ conversationId?: string;
+ /** The project the route opens a new chat in. */
+ project?: TChatProject;
+ /** The deployment shows the full footer on the welcome screen. */
+ landingFooter: boolean;
+ /** The deployment configured footer content. */
+ configuredFooter: boolean;
+}): ChatPaneChrome {
+ const active = conversation?.conversationId === conversationId ? conversation : undefined;
+ const subagentThread = active?.subagentThread;
+ const fullFooter = view.isLanding && landingFooter;
+ const title = active?.title?.trim();
+ return {
+ title: view.isLanding || !title ? null : title,
+ fullFooter,
+ bandFooter: !fullFooter && configuredFooter,
+ footerBelow: fullFooter || configuredFooter,
+ landingProject: view.isLanding && project != null ? project : undefined,
+ projectId: active?.chatProjectId || undefined,
+ readOnly: subagentThread != null,
+ parentConversationId: subagentThread?.parentConversationId,
+ };
+}
diff --git a/packages/chat/test/consumer.spec.tsx b/packages/chat/test/consumer.spec.tsx
index d4bf615f8f..a5f6174375 100644
--- a/packages/chat/test/consumer.spec.tsx
+++ b/packages/chat/test/consumer.spec.tsx
@@ -11,6 +11,7 @@ import {
Text,
MessageRow,
MentionPopover,
+ ChatScreen,
getHeaderHoverLabel,
EventSubagentActivityGroup,
} from '@librechat/chat/components';
@@ -18,6 +19,7 @@ import { initReactI18next, I18nextProvider } from 'react-i18next';
import { act, fireEvent, render, screen, within } from '@testing-library/react';
import { Button, Textarea, ThemeProvider, clickHouseTheme } from '@librechat/client';
import {
+ ChatContext,
MessageContext,
MessagePartIndex,
StreamHostProvider,
@@ -37,6 +39,7 @@ import type { PartRenderers } from '@librechat/chat/components';
import type {
StreamHost,
ChatSurface,
+ ChatContract,
MessagesHost,
MessagePartsHost,
} from '@librechat/chat/react';
@@ -417,6 +420,48 @@ describe('a consumer built on the public entries', () => {
expect(onSelectMention).toHaveBeenCalledWith(expect.objectContaining({ value: 'review' }));
textarea.remove();
});
+
+ it('lays out a chat screen from a session, with the app surfaces as slots', () => {
+ const root = '00000000-0000-0000-0000-000000000000';
+ const base = { conversationId: 'convo', createdAt: new Date().toISOString() };
+ const messages: TMessage[] = [
+ { ...base, messageId: 'u1', parentMessageId: root, isCreatedByUser: true, text: 'Question' },
+ { ...base, messageId: 'a1', parentMessageId: 'u1', isCreatedByUser: false, text: 'Answer' },
+ ];
+ const screenFor = (session: { conversationId?: string; messages: TMessage[] | null }) => (
+
+
+ Welcome
}
+ renderMessages={({ messagesTree }) => (
+
+ {messagesTree?.map((message) => (
+ - {message.text}
+ ))}
+
+ )}
+ renderComposer={() => }
+ />
+
+
+ );
+
+ const view = render(screenFor({ messages: null }));
+ expect(screen.getByText('Welcome')).toBeInTheDocument();
+ expect(screen.getByRole('textbox', { name: 'Message' })).toBeInTheDocument();
+
+ view.rerender(screenFor({ conversationId: 'convo', messages }));
+ expect(screen.getByRole('heading', { level: 1 })).toHaveTextContent('Plans');
+ expect(
+ within(screen.getByRole('list', { name: 'Messages' })).getByText('Question'),
+ ).toBeInTheDocument();
+ });
});
describe('a consumer rendering subagent activity', () => {