Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active
TypeScript aianthropicartifactsawsazurechatgptchatgpt-cloneclaudeclonedeepseekgeminigooglegpt-5librechatmcpo1openairesponses-apivisionwebui
🏗️ refactor: Lay Out the Chat Pane Through @librechat/chat (#17574)
Marco Beretta225810a16dac
diff --git a/client/src/components/Chat/ChatView.tsx b/client/src/components/Chat/ChatView.tsxindex 01e8e2c2d6..7068f18000 100644--- a/client/src/components/Chat/ChatView.tsx+++ b/client/src/components/Chat/ChatView.tsx@@ -1,14 +1,12 @@-import { memo, useMemo, useRef } from 'react';+import { memo, useMemo } from 'react';import { useAtomValue } from 'jotai';import { useRecoilValue } from 'recoil';import { useForm } from 'react-hook-form';-import { Spinner } from '@librechat/client';import { useParams } from 'react-router-dom';import { Constants, buildTree } from 'librechat-data-provider';-import { QueuedTurnPortalProvider } from '@librechat/chat/components';+import { ChatPane, getChatPaneView, QueuedTurnPortalProvider } from '@librechat/chat/components';import {submissionByIndex,- composerLiftFamily,ChatSessionProvider,ComposerRestoreProvider,} from '@librechat/chat/react';@@ -31,19 +29,8 @@ import { TraceSurface } from './Trace';import Lia from '~/components/Lia';import Landing from './Landing';import Header from './Header';-import { cn } from '~/utils';import store from '~/store';-function LoadingSpinner() {- return (- <div className="relative flex-1 overflow-hidden overflow-y-auto">- <div className="relative flex h-full items-center justify-center">- <Spinner className="text-text-primary" />- </div>- </div>- );-}-type ChatViewProps = {index?: number;project?: TChatProject;@@ -51,7 +38,7 @@ type ChatViewProps = {routePending?: boolean;};-function ChatPane({+function ChatViewPane({index = 0,project,routePending = false,@@ -75,7 +62,7 @@ function ChatPane({);/** The welcome screen reserves the message column's scrollbar band before any- * column exists to measure it (see the column's class list below). */+ * column exists to measure it (see the column classes in `ChatPane`). */useScrollbarGutterSeed();/** A conversation carries a footer only for configured content, and the@@ -84,12 +71,6 @@ function ChatPane({const configuredFooter = useConfiguredFooter();const landingFooter = useLandingFooter();- /** Room an open composer popover needs below the composer; see the atom. */- const composerLift = useAtomValue(composerLiftFamily(index));-- /** Lia, the welcome screen mascot, stands on the composer band's top edge. */- const composerBandRef = useRef<HTMLDivElement>(null);-const methods = useForm<ChatFormValues>({defaultValues: { text: '' },});@@ -109,28 +90,19 @@ function ChatPane({const activeSubagentThread = activeConversation?.subagentThread;const chatProjectId = activeConversation?.chatProjectId || undefined;- let content: JSX.Element | null | undefined;- const isLandingPage =- (!messagesTree || messagesTree.length === 0) &&- (conversationId === Constants.NEW_CONVO || !conversationId);+ 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 isNavigating = (!messagesTree || messagesTree.length === 0) && conversationId != null;const isProjectLandingPage = isLandingPage && project != null;- if (isLoading && conversationId !== Constants.NEW_CONVO) {- content = <LoadingSpinner />;- } else if ((isLoading || isNavigating) && !isLandingPage) {- content = <LoadingSpinner />;- } else if (!isLandingPage) {- content = <MessagesView messagesTree={messagesTree} messages={messages} />;- } else {- content = <Landing centerFormOnLanding={centerFormOnLanding} />;- }-const chatFormPlaceholder =isProjectLandingPage && project? localize('com_ui_new_chat_in_project', { name: project.name })@@ -156,98 +128,63 @@ function ChatPane({<ApprovalProvider pendingAction={pendingAction}><Presentation routePending={routePending}><TraceSurface conversationId={conversationId}>- <h1 className="sr-only">{pageHeading}</h1>- {/* Marks the header's controls as this pane's, so a pane-scoped- shortcut pressed from them acts here, not on the first pane. */}- <div data-chat-pane-portal={index} className="contents">- <Header- parentConversationId={parentConversationId}- readOnly={isSubagentThreadReadOnly}- />- </div>- {!isLandingPage && chatProjectId && <ProjectBadge projectId={chatProjectId} />}- <>- <div- data-chat-pane={index}- style={- isLandingPage && composerLift > 0- ? { transform: `translateY(-${composerLift}px)` }- : undefined- }- className={cn(- 'flex flex-col',- isLandingPage && 'relative',- isLandingPage- ? /* The gutter is reserved once per state, wherever the- centring happens. A conversation centres the composer- inside the band below, against a message column that- holds the scrollbar band back; the landing page centres- this whole column instead, greeting and composer- together, so it holds the same band back here. Without- it the composer lands 4px right of where a conversation- puts it and slides sideways on the way in. */- 'scrollbar-gutter-spacer flex-1 items-center justify-end sm:justify-center'- : 'h-full overflow-y-auto',- !isLandingPage && chatProjectId && 'pt-9',- )}- >+ <ChatPane+ index={index}+ view={view}+ heading={pageHeading}+ header={+ <Header+ parentConversationId={parentConversationId}+ readOnly={isSubagentThreadReadOnly}+ />+ }+ badge={chatProjectId ? <ProjectBadge projectId={chatProjectId} /> : null}+ messages={<MessagesView messagesTree={messagesTree} messages={messages} />}+ landing={<Landing centerFormOnLanding={centerFormOnLanding} />}+ renderColumn={(column) => (<OwnerTextProvidermessages={messages}conversationId={conversationId}isSubmitting={chat.isSubmitting}>- {content}+ {column}</OwnerTextProvider>- {/* Named + opaque so a view transition (the ask_user_question- popover ⇄ chat-card morph) paints the whole composer band- over the travelling card instead of letting it show- through below the composer. The background matches the- page, so normal rendering is unchanged. The named surface- is a stacking context; keep it above positioned tool glyphs- so they cannot paint through the approval preview. */}- <div- ref={composerBandRef}- className={cn(- 'bg-surface-canvas relative z-10 w-full [view-transition-name:chat-form]',- !isLandingPage && 'scrollbar-gutter-spacer',- isLandingPage && 'max-w-3xl transition-all duration-200 xl:max-w-4xl',- )}- >- {isLandingPage && <ConversationStarters />}- {isSubagentThreadReadOnly ? (- <div- className="text-text-secondary mx-auto w-full max-w-3xl px-4 py-3 text-center text-sm xl:max-w-4xl"- role="note"- >- {localize('com_ui_subagent_thread_read_only')}- </div>- ) : (- <ChatForm- index={index}- routePending={routePending}- placeholder={chatFormPlaceholder}- project={isProjectLandingPage ? project : undefined}- isLandingPage={isLandingPage}- enterToSend={enterToSend}- autoSendText={autoSendText}- speechSettingsInitialized={speechSettingsInitialized}- footerBelow={footerBelow}- centerFormOnLanding={centerFormOnLanding}- />- )}- {/* 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. */}- {!fullFooter && configuredFooter && <Footer configuredOnly />}- </div>+ )}+ starters={<ConversationStarters />}+ readOnlyNote={+ isSubagentThreadReadOnly+ ? localize('com_ui_subagent_thread_read_only')+ : undefined+ }+ composer={+ <ChatForm+ index={index}+ routePending={routePending}+ placeholder={chatFormPlaceholder}+ project={isProjectLandingPage ? project : undefined}+ isLandingPage={isLandingPage}+ enterToSend={enterToSend}+ autoSendText={autoSendText}+ speechSettingsInitialized={speechSettingsInitialized}+ footerBelow={footerBelow}+ centerFormOnLanding={centerFormOnLanding}+ />+ }+ /* 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 ? <Footer configuredOnly /> : null+ }+ footer={fullFooter ? <Footer /> : null}+ renderMascot={(bandRef) => (<Lia- bandRef={composerBandRef}+ bandRef={bandRef}landing={isLandingPage}submission={rootSubmission}/>- </div>- {fullFooter && <Footer />}- </>+ )}+ /></TraceSurface></Presentation></ApprovalProvider>@@ -266,7 +203,7 @@ function ChatView(props: ChatViewProps) {return (<ChatSessionProvider index={index} conversationId={conversationId}>{({ messages, isLoading }) => (- <ChatPane+ <ChatViewPane{...props}conversationId={conversationId}messages={messages}diff --git a/client/src/components/Chat/__tests__/ChatView.spec.tsx b/client/src/components/Chat/__tests__/ChatView.spec.tsxindex 07ef3f1fa5..a4d7ea3269 100644--- a/client/src/components/Chat/__tests__/ChatView.spec.tsx+++ b/client/src/components/Chat/__tests__/ChatView.spec.tsx@@ -78,6 +78,10 @@ jest.mock('../Input/ChatForm', () => ({},}));jest.mock('../Input/ConversationStarters', () => ({ __esModule: true, default: () => <div /> }));+jest.mock('~/components/Projects/ProjectBadge', () => ({+ __esModule: true,+ default: ({ projectId }: { projectId: string }) => <div data-testid={`project-${projectId}`} />,+}));describe('ChatView page heading', () => {beforeEach(() => {@@ -273,3 +277,27 @@ describe('ChatView landing footer', () => {);});});++describe('ChatView project badge', () => {+ beforeEach(() => {+ mockParams.mockReturnValue({ conversationId: 'convo-1' });+ });++ test('pins the conversation project above a column that leaves room for it', () => {+ mockConversation.mockReturnValue({ conversationId: 'convo-1', chatProjectId: 'atlas' });++ const { container } = render(<ChatView />);++ expect(screen.getByTestId('project-atlas')).toBeInTheDocument();+ expect(container.querySelector('[data-chat-pane="0"]')).toHaveClass('pt-9');+ });++ test('leaves the column unpadded for a conversation outside any project', () => {+ mockConversation.mockReturnValue({ conversationId: 'convo-1' });++ const { container } = render(<ChatView />);++ expect(screen.queryByTestId(/^project-/)).not.toBeInTheDocument();+ expect(container.querySelector('[data-chat-pane="0"]')).not.toHaveClass('pt-9');+ });+});diff --git a/client/src/components/Chat/__tests__/ChatView.subagent.spec.tsx b/client/src/components/Chat/__tests__/ChatView.subagent.spec.tsxindex 5ec6da0e12..21891dee23 100644--- a/client/src/components/Chat/__tests__/ChatView.subagent.spec.tsx+++ b/client/src/components/Chat/__tests__/ChatView.subagent.spec.tsx@@ -20,6 +20,7 @@ jest.mock('react-hook-form', () => ({jest.mock('@librechat/client', () => ({Spinner: () => <div data-testid="spinner" />,+ cn: (...values: Array<string | false | null | undefined>) => values.filter(Boolean).join(' '),}));jest.mock('librechat-data-provider', () => ({diff --git a/eslint-suppressions.json b/eslint-suppressions.jsonindex bbe69d111f..4e9470adda 100644--- a/eslint-suppressions.json+++ b/eslint-suppressions.json@@ -55,11 +55,6 @@"count": 1}},- "client/src/components/Chat/ChatView.tsx": {- "shadcn/no-restyle": {- "count": 1- }- },"client/src/components/Chat/ExportAndShareMenu.tsx": {"design/disabled-recipe": {"count": 1diff --git a/packages/chat/src/components.ts b/packages/chat/src/components.tsindex 29d22dbfbe..043034baec 100644--- a/packages/chat/src/components.ts+++ b/packages/chat/src/components.ts@@ -102,3 +102,9 @@ export type {ComposerHintKind,ComposerHintState,} from './components/composer/bar/hint';++/** Chat pane: the layout that seats the header, message column and composer band. */+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';diff --git a/packages/chat/src/components/pane/ChatPane.tsx b/packages/chat/src/components/pane/ChatPane.tsxnew file mode 100644index 0000000000..88f6af0458--- /dev/null+++ b/packages/chat/src/components/pane/ChatPane.tsx@@ -0,0 +1,145 @@+import { useRef } from 'react';+import { useAtomValue } from 'jotai';+import { cn, Spinner } from '@librechat/client';+import type { ReactElement, ReactNode, RefObject } from 'react';+import type { ChatPaneColumn, ChatPaneView } from './view';+import { composerLiftFamily } from '../../react/lift';++export type ChatPaneProps = {+ /** The pane's index among the open panes; scopes pane-local state such as the composer lift. */+ index?: number;+ /** The layout and the column to show; `getChatPaneView` derives both from the session. */+ view: ChatPaneView;+ /** The page's visually hidden heading: the conversation title or the new-chat label. */+ heading: string;+ /** The pane's header bar. */+ header?: ReactNode;+ /** A strip pinned above the message column, such as the conversation's project. The column+ * leaves room for it below the header. */+ badge?: ReactNode;+ /** The message list, shown when the column is `messages`. */+ messages?: ReactNode;+ /** The welcome screen, shown when the column is `landing`. */+ landing?: ReactNode;+ /** Wraps whichever column is showing, so a provider it needs stays mounted across views. */+ renderColumn?: (column: ReactNode) => ReactNode;+ /** Shown above the composer on the welcome screen, such as conversation starters. */+ starters?: ReactNode;+ /** The composer. */+ composer?: ReactNode;+ /** Replaces the composer with a note, for a conversation the reader cannot continue. */+ readOnlyNote?: string;+ /** Inside the composer band, under the composer. */+ bandFooter?: ReactNode;+ /** Below the whole column. */+ footer?: ReactNode;+ /** Rendered beside the composer band, given the band to position against. */+ renderMascot?: (bandRef: RefObject<HTMLDivElement>) => ReactNode;+};++function LoadingSpinner(): ReactElement {+ return (+ <div className="relative flex-1 overflow-hidden overflow-y-auto">+ <div className="text-text-primary relative flex h-full items-center justify-center">+ <Spinner />+ </div>+ </div>+ );+}++const columns: Record<ChatPaneColumn, (props: ChatPaneProps) => ReactNode> = {+ loading: () => <LoadingSpinner />,+ landing: ({ landing }) => landing,+ messages: ({ messages }) => messages,+};++/**+ * A chat pane's layout: the hidden page heading, the header, and a column holding the+ * messages (or the welcome screen) above the composer band. Every surface arrives as a slot,+ * so the app decides what fills it and the pane owns only how they sit together.+ */+export default function ChatPane(props: ChatPaneProps): ReactElement {+ const {+ index = 0,+ view,+ heading,+ header,+ badge,+ renderColumn,+ starters,+ composer,+ readOnlyNote,+ bandFooter,+ footer,+ renderMascot,+ } = props;+ const { isLanding } = view;+ /** Room an open composer popover needs below the composer; see the atom. */+ const composerLift = useAtomValue(composerLiftFamily(index));+ const bandRef = useRef<HTMLDivElement>(null);+ const column = columns[view.column](props);++ return (+ <>+ <h1 className="sr-only">{heading}</h1>+ {/* Marks the header's controls as this pane's, so a pane-scoped shortcut pressed from+ them acts here, not on the first pane. */}+ <div data-chat-pane-portal={index} className="contents">+ {header}+ </div>+ {!isLanding && badge}+ <div+ data-chat-pane={index}+ style={+ isLanding && composerLift > 0+ ? { transform: `translateY(-${composerLift}px)` }+ : undefined+ }+ className={cn(+ 'flex flex-col',+ isLanding && 'relative',+ isLanding+ ? /* The gutter is reserved once per state, wherever the centring happens. A+ conversation centres the composer inside the band below, against a message+ column that holds the scrollbar band back; the landing page centres this whole+ column instead, greeting and composer together, so it holds the same band back+ here. Without it the composer lands 4px right of where a conversation puts it+ and slides sideways on the way in. */+ 'scrollbar-gutter-spacer flex-1 items-center justify-end sm:justify-center'+ : 'h-full overflow-y-auto',+ !isLanding && badge != null && 'pt-9',+ )}+ >+ {renderColumn ? renderColumn(column) : column}+ {/* Named + opaque so a view transition (the ask_user_question popover and chat-card+ morph) paints the whole composer band over the travelling card instead of letting+ it show through below the composer. The background matches the page, so normal+ rendering is unchanged. The named surface is a stacking context; keep it above+ positioned tool glyphs so they cannot paint through the approval preview. */}+ <div+ ref={bandRef}+ className={cn(+ 'bg-surface-canvas relative z-10 w-full [view-transition-name:chat-form]',+ !isLanding && 'scrollbar-gutter-spacer',+ isLanding && 'max-w-3xl transition-all duration-200 xl:max-w-4xl',+ )}+ >+ {isLanding && starters}+ {readOnlyNote != null ? (+ <div+ className="text-text-secondary mx-auto w-full max-w-3xl px-4 py-3 text-center text-sm xl:max-w-4xl"+ role="note"+ >+ {readOnlyNote}+ </div>+ ) : (+ composer+ )}+ {bandFooter}+ </div>+ {renderMascot?.(bandRef)}+ </div>+ {footer}+ </>+ );+}diff --git a/packages/chat/src/components/pane/__tests__/ChatPane.spec.tsx b/packages/chat/src/components/pane/__tests__/ChatPane.spec.tsxnew file mode 100644index 0000000000..c3ae8e9bce--- /dev/null+++ b/packages/chat/src/components/pane/__tests__/ChatPane.spec.tsx@@ -0,0 +1,180 @@+/**+ * @jest-environment jsdom+ */+import { useEffect } from 'react';+import { Provider, createStore } from 'jotai';+import { Constants } from 'librechat-data-provider';+import { render, screen } from '@testing-library/react';+import type { ReactNode } from 'react';+import type { ChatPaneProps } from '../ChatPane';+import { composerLiftFamily } from '../../../react/lift';+import { getChatPaneView } from '../view';+import ChatPane from '../ChatPane';++function renderPane(props: Partial<ChatPaneProps> = {}, lift = 0) {+ const jotaiStore = createStore();+ jotaiStore.set(composerLiftFamily(0), lift);+ const pane = (next: Partial<ChatPaneProps>) => (+ <Provider store={jotaiStore}>+ <ChatPane+ view={{ isLanding: false, column: 'messages' }}+ heading="Deploy checklist"+ header={<div data-testid="header" />}+ messages={<ol aria-label="Messages" />}+ landing={<p>Welcome</p>}+ starters={<button type="button">Starter</button>}+ composer={<textarea aria-label="Message" />}+ {...next}+ />+ </Provider>+ );+ const result = render(pane(props));+ return { ...result, rerenderPane: (next: Partial<ChatPaneProps>) => result.rerender(pane(next)) };+}++const LANDING = { isLanding: true, column: 'landing' } as const;++const paneColumn = (container: HTMLElement) =>+ container.querySelector('[data-chat-pane="0"]') as HTMLElement;+const composerBand = (container: HTMLElement) =>+ paneColumn(container).querySelector('.bg-surface-canvas') as HTMLElement;++describe('getChatPaneView', () => {+ it.each([+ [{ conversationId: undefined, hasMessages: false, isLoading: false }, true, 'landing'],+ [{ conversationId: Constants.NEW_CONVO, hasMessages: false, isLoading: true }, true, 'landing'],+ [{ conversationId: undefined, hasMessages: false, isLoading: true }, true, 'loading'],+ [{ conversationId: 'convo-1', hasMessages: false, isLoading: true }, false, 'loading'],+ [{ conversationId: 'convo-1', hasMessages: false, isLoading: false }, false, 'loading'],+ [{ conversationId: Constants.NEW_CONVO, hasMessages: true, isLoading: true }, false, 'loading'],+ [{ conversationId: 'convo-1', hasMessages: true, isLoading: false }, false, 'messages'],+ [+ { conversationId: Constants.NEW_CONVO, hasMessages: true, isLoading: false },+ false,+ 'messages',+ ],+ ] as const)('%o lays out landing=%s and shows %s', (input, isLanding, column) => {+ expect(getChatPaneView(input)).toEqual({ isLanding, column });+ });+});++describe('ChatPane', () => {+ it('names the page and seats the header in its pane portal', () => {+ const { container } = renderPane();++ expect(screen.getByRole('heading', { level: 1 })).toHaveTextContent('Deploy checklist');+ expect(container.querySelector('[data-chat-pane-portal="0"]')).toContainElement(+ screen.getByTestId('header'),+ );+ });++ it('shows the message list above the composer in a scrolling conversation column', () => {+ const { container } = renderPane();++ expect(screen.getByRole('list', { name: 'Messages' })).toBeInTheDocument();+ expect(screen.queryByText('Welcome')).not.toBeInTheDocument();+ expect(screen.queryByRole('button', { name: 'Starter' })).not.toBeInTheDocument();+ expect(paneColumn(container)).toHaveClass('h-full', 'overflow-y-auto');+ expect(composerBand(container)).toHaveClass('scrollbar-gutter-spacer', 'relative', 'z-10');+ expect(composerBand(container)).toContainElement(+ screen.getByRole('textbox', { name: 'Message' }),+ );+ });++ it('centres the welcome screen and its starters without a scroll container', () => {+ const { container } = renderPane({ view: LANDING });++ expect(screen.getByText('Welcome')).toBeInTheDocument();+ expect(screen.queryByRole('list', { name: 'Messages' })).not.toBeInTheDocument();+ expect(screen.getByRole('button', { name: 'Starter' })).toBeInTheDocument();+ expect(paneColumn(container)).toHaveClass('scrollbar-gutter-spacer', 'flex-1');+ expect(paneColumn(container)).not.toHaveClass('overflow-y-auto');+ expect(composerBand(container)).not.toHaveClass('scrollbar-gutter-spacer');+ });++ it('shows a spinner in place of the column while loading', () => {+ renderPane({ view: { isLanding: false, column: 'loading' } });++ expect(screen.queryByRole('list', { name: 'Messages' })).not.toBeInTheDocument();+ expect(screen.queryByText('Welcome')).not.toBeInTheDocument();+ expect(screen.getByRole('textbox', { name: 'Message' })).toBeInTheDocument();+ });++ it('keeps the welcome layout under the spinner while a new session loads', () => {+ const { container } = renderPane({ view: { isLanding: true, column: 'loading' } });++ expect(screen.queryByText('Welcome')).not.toBeInTheDocument();+ expect(screen.getByRole('button', { name: 'Starter' })).toBeInTheDocument();+ expect(paneColumn(container)).toHaveClass('scrollbar-gutter-spacer', 'flex-1');+ expect(paneColumn(container)).not.toHaveClass('overflow-y-auto');+ });++ it('replaces the composer with a note for a conversation the reader cannot continue', () => {+ renderPane({ readOnlyNote: 'View only' });++ expect(screen.getByRole('note')).toHaveTextContent('View only');+ expect(screen.queryByRole('textbox', { name: 'Message' })).not.toBeInTheDocument();+ });++ it('pins the badge below the header only in a conversation', () => {+ const badge = <span>Project Atlas</span>;+ const { container, rerenderPane } = renderPane({ badge });++ expect(screen.getByText('Project Atlas')).toBeInTheDocument();+ expect(paneColumn(container)).toHaveClass('pt-9');++ rerenderPane({ badge, view: LANDING });+ expect(screen.queryByText('Project Atlas')).not.toBeInTheDocument();+ expect(paneColumn(container)).not.toHaveClass('pt-9');+ });++ it('lifts the welcome column by the room an open composer popover needs', () => {+ const { container } = renderPane({ view: LANDING }, 120);+ expect(paneColumn(container).style.transform).toBe('translateY(-120px)');+ });++ it('keeps a conversation column in place whatever the lift', () => {+ const { container } = renderPane({}, 120);+ expect(paneColumn(container).style.transform).toBe('');+ });++ it('seats the band footer inside the band and the footer below the column', () => {+ const { container } = renderPane({+ bandFooter: <p>Configured footer</p>,+ footer: <p>Full footer</p>,+ });++ expect(composerBand(container)).toContainElement(screen.getByText('Configured footer'));+ expect(paneColumn(container)).not.toContainElement(screen.getByText('Full footer'));+ });++ it('hands the mascot the composer band to stand on', () => {+ let band: HTMLElement | null = null;+ function Mascot({ bandRef }: { bandRef: { current: HTMLElement | null } }) {+ useEffect(() => {+ band = bandRef.current;+ }, [bandRef]);+ return null;+ }+ const { container } = renderPane({ renderMascot: (bandRef) => <Mascot bandRef={bandRef} /> });++ expect(band).toBe(composerBand(container));+ });++ it('keeps the column wrapper mounted when the view changes', () => {+ const mounts = jest.fn();+ function Wrapper({ children }: { children: ReactNode }) {+ useEffect(() => mounts(), []);+ return <section aria-label="Column">{children}</section>;+ }+ const renderColumn = (column: ReactNode) => <Wrapper>{column}</Wrapper>;+ const { rerenderPane } = renderPane({ view: LANDING, renderColumn });++ expect(screen.getByRole('region', { name: 'Column' })).toHaveTextContent('Welcome');+ rerenderPane({ view: { isLanding: false, column: 'messages' }, renderColumn });+ expect(screen.getByRole('region', { name: 'Column' })).toContainElement(+ screen.getByRole('list', { name: 'Messages' }),+ );+ expect(mounts).toHaveBeenCalledTimes(1);+ });+});diff --git a/packages/chat/src/components/pane/view.ts b/packages/chat/src/components/pane/view.tsnew file mode 100644index 0000000000..790e789212--- /dev/null+++ b/packages/chat/src/components/pane/view.ts@@ -0,0 +1,40 @@+import { Constants } from 'librechat-data-provider';++/** What a chat pane's message column shows. */+export type ChatPaneColumn = 'loading' | 'landing' | 'messages';++/** How a chat pane is laid out and what its column shows. */+export type ChatPaneView = {+ /** The welcome-screen layout: a new conversation with nothing in it. It holds while the+ * session loads, so the composer, starters and footer stay put under the spinner. */+ isLanding: boolean;+ column: ChatPaneColumn;+};++/**+ * Picks the pane's layout and column: the welcome screen for a new conversation with nothing in+ * it, a spinner while a conversation loads or the route moves to one that has no messages yet,+ * and the message list otherwise.+ */+export function getChatPaneView({+ conversationId,+ hasMessages,+ isLoading,+}: {+ conversationId?: string | null;+ hasMessages: boolean;+ isLoading: boolean;+}): ChatPaneView {+ const isNew = !conversationId || conversationId === Constants.NEW_CONVO;+ const isLanding = !hasMessages && isNew;+ if (isLoading && conversationId !== Constants.NEW_CONVO) {+ return { isLanding, column: 'loading' };+ }+ if (isLanding) {+ return { isLanding, column: 'landing' };+ }+ if (isLoading || (!hasMessages && conversationId != null)) {+ return { isLanding, column: 'loading' };+ }+ return { isLanding, column: 'messages' };+}