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: Read Mounted Pane Conversations through ChatSettings in Steer Recovery (#17137)
Marco Beretta4bd04b6f57cf
diff --git a/client/src/Providers/ChatSettingsContext.tsx b/client/src/Providers/ChatSettingsContext.tsxindex e351e35cda..e096431a1b 100644--- a/client/src/Providers/ChatSettingsContext.tsx+++ b/client/src/Providers/ChatSettingsContext.tsx@@ -11,6 +11,7 @@ export const defaultChatSettings: ChatSettings = {setIsTemporary: () => undefined,config: { feedbackEnabled: false, canRenameRunningChat: false },auth: {},+ getPaneConversations: () => [],};export const ChatSettingsContext = createContext<ChatSettings>(defaultChatSettings);diff --git a/client/src/hooks/Chat/__tests__/useSteerRecovery.spec.tsx b/client/src/hooks/Chat/__tests__/useSteerRecovery.spec.tsxindex 9e7dc72b1d..5e74d2eb48 100644--- a/client/src/hooks/Chat/__tests__/useSteerRecovery.spec.tsx+++ b/client/src/hooks/Chat/__tests__/useSteerRecovery.spec.tsx@@ -15,7 +15,9 @@ import {ComposerRestoreProvider,useComposerRestoreHost,} from '~/Providers/ComposerRestoreContext';+import { ChatSettingsContext, defaultChatSettings } from '~/Providers/ChatSettingsContext';import { queuedMessagesByConvoId, resetQueueFamilies } from '~/hooks/Chat/queue';+import { usePaneConversations } from '~/routes/ChatSettings';import useSteerRecovery from '../useSteerRecovery';import store from '~/store';@@ -53,6 +55,16 @@ function RewakePublisher({ rewake, children }: { rewake: RewakeDrain; children:return <>{children}</>;}+/** The app's own pane reader, behind the settings context the hook reads it from. */+function PaneSettings({ children }: { children: React.ReactNode }) {+ const getPaneConversations = usePaneConversations();+ const settings = React.useMemo(+ () => ({ ...defaultChatSettings, getPaneConversations }),+ [getPaneConversations],+ );+ return <ChatSettingsContext.Provider value={settings}>{children}</ChatSettingsContext.Provider>;+}+function setup(initialize?: (snapshot: MutableSnapshot) => void, rewake?: RewakeDrain) {const wrapper = ({ children }: { children: React.ReactNode }) => (<RecoilRoot@@ -61,9 +73,11 @@ function setup(initialize?: (snapshot: MutableSnapshot) => void, rewake?: Rewakeinitialize?.(snapshot);}}>- <ComposerRestoreProvider>- {rewake ? <RewakePublisher rewake={rewake}>{children}</RewakePublisher> : children}- </ComposerRestoreProvider>+ <PaneSettings>+ <ComposerRestoreProvider>+ {rewake ? <RewakePublisher rewake={rewake}>{children}</RewakePublisher> : children}+ </ComposerRestoreProvider>+ </PaneSettings></RecoilRoot>);return renderHook(@@ -279,9 +293,11 @@ describe('useSteerRecovery', () => {]);}}>- <RewakePublisher rewake={rewake}>- <Tree />- </RewakePublisher>+ <PaneSettings>+ <RewakePublisher rewake={rewake}>+ <Tree />+ </RewakePublisher>+ </PaneSettings></RecoilRoot></ComposerRestoreProvider>,);@@ -381,7 +397,9 @@ describe('useSteerRecovery', () => {]);}}>- <Tree />+ <PaneSettings>+ <Tree />+ </PaneSettings></RecoilRoot></ComposerRestoreProvider>,);@@ -540,8 +558,10 @@ describe('useSteerRecovery', () => {]);}}>- <Observer />- {live && <Recovery />}+ <PaneSettings>+ <Observer />+ {live && <Recovery />}+ </PaneSettings></RecoilRoot>);@@ -607,7 +627,9 @@ describe('useSteerRecovery', () => {]);}}>- <Tree />+ <PaneSettings>+ <Tree />+ </PaneSettings></RecoilRoot>,);diff --git a/client/src/hooks/Chat/contract.ts b/client/src/hooks/Chat/contract.tsindex 313d89c07b..983a92ef8f 100644--- a/client/src/hooks/Chat/contract.ts+++ b/client/src/hooks/Chat/contract.ts@@ -223,6 +223,16 @@ export type ChatSettings = {setIsTemporary: Dispatch<SetStateAction<boolean>>;config: ChatConfig;auth: ChatAuth;+ /** The conversation each mounted chat pane shows, read when called rather than at render:+ * steer recovery asks whether any pane holding a conversation is still running. */+ getPaneConversations: () => ReadonlyArray<PaneConversation>;+};++/** One mounted chat pane and the conversation it shows. */+export type PaneConversation = {+ /** The pane key, as the app keys its panes (`0` for the main chat). */+ index: string | number;+ conversationId: string | null;};/** The assistants abort route and the run it stops. */diff --git a/client/src/hooks/Chat/useSteerRecovery.ts b/client/src/hooks/Chat/useSteerRecovery.tsindex 3ec1005d72..ba63bb2289 100644--- a/client/src/hooks/Chat/useSteerRecovery.ts+++ b/client/src/hooks/Chat/useSteerRecovery.ts@@ -12,6 +12,7 @@ import {import { useSteerMessageMutation, useCancelSteerMutation } from '~/data-provider';import { useComposerRestoreHost } from '~/Providers/ComposerRestoreContext';import { carriedSteerContext, isLegacyDeliveryUncertain } from '~/utils';+import { useChatSettings } from '~/Providers/ChatSettingsContext';import { useSteerRehome } from '~/hooks/Chat/useSteerCancel';import useSteerConvert from '~/hooks/Chat/useSteerConvert';import store from '~/store';@@ -28,6 +29,7 @@ export default function useSteerRecovery(conversationId: string) {const rehomeSteer = useSteerRehome(conversationId);const { rewakeDrain } = useComposerRestoreHost();const jotaiStore = useStore();+ const { getPaneConversations } = useChatSettings();/** Whether the run this steer belongs to has finished, read live at ack time.* Unmounting is not the same signal: `PendingSteers` also unmounts when the@@ -36,17 +38,15 @@ export default function useSteerRecovery(conversationId: string) {* the server was already making. */const isRunOver = useCallback((snapshot: Snapshot) => {- const keys = snapshot.getLoadable(store.conversationKeysAtom).getValue();let held = false;- for (const key of keys) {- const convo = snapshot.getLoadable(store.conversationByIndex(key)).getValue();- if (convo?.conversationId !== conversationId) {+ for (const pane of getPaneConversations()) {+ if (pane.conversationId !== conversationId) {continue;}/* Comparison mode can hold one conversation in several panes, and onlythe pane that owns the run is submitting: any live pane means therun is still going, whichever slot comes first. */- if (snapshot.getLoadable(store.isSubmittingFamily(key)).getValue() === true) {+ if (snapshot.getLoadable(store.isSubmittingFamily(pane.index)).getValue() === true) {return false;}held = true;@@ -56,7 +56,7 @@ export default function useSteerRecovery(conversationId: string) {same mistake as reading the unmount as the end, one step further out. */return held;},- [conversationId],+ [conversationId, getPaneConversations],);const markStatus = useCallback(diff --git a/client/src/routes/ChatSettings.tsx b/client/src/routes/ChatSettings.tsxindex 9e300a111d..5e0f9318fc 100644--- a/client/src/routes/ChatSettings.tsx+++ b/client/src/routes/ChatSettings.tsx@@ -1,9 +1,9 @@import { useMemo } from 'react';import { useAtom } from 'jotai';import { supportsConversationTitleOwnership } from 'librechat-data-provider';-import { useRecoilState, useRecoilValue, useResetRecoilState } from 'recoil';+import { useRecoilState, useRecoilValue, useRecoilCallback, useResetRecoilState } from 'recoil';import type { ReactNode } from 'react';-import type { ChatSettings, ChatConfig, ChatAuth } from '~/hooks/Chat/contract';+import type { ChatAuth, ChatConfig, ChatSettings, PaneConversation } from '~/hooks/Chat/contract';import { ChatTransportContext, defaultChatTransport } from '~/Providers/ChatTransportContext';import { ChatSettingsContext } from '~/Providers/ChatSettingsContext';import { duringRunActionAtom } from '~/store/duringRun';@@ -11,6 +11,24 @@ import { useGetStartupConfig } from '~/data-provider';import { useAuthContext } from '~/hooks/AuthContext';import store from '~/store';+/** Reads the conversation each mounted pane shows from the app's pane store, at call time. */+export function usePaneConversations(): ChatSettings['getPaneConversations'] {+ return useRecoilCallback(+ ({ snapshot }) =>+ (): PaneConversation[] =>+ snapshot+ .getLoadable(store.conversationKeysAtom)+ .getValue()+ .map((index) => ({+ index,+ conversationId:+ snapshot.getLoadable(store.conversationByIndex(index)).getValue()?.conversationId ??+ null,+ })),+ [],+ );+}+/** Supplies the chat's app-global preferences from the app's own settings store, the deployment* config and signed-in account from the app's queries, and the transport its turns run over. */export default function ChatSettingsProvider({ children }: { children: ReactNode }) {@@ -34,6 +52,7 @@ export default function ChatSettingsProvider({ children }: { children: ReactNode};}, [startupConfig]);const auth = useMemo<ChatAuth>(() => ({ user }), [user]);+ const getPaneConversations = usePaneConversations();const settings = useMemo<ChatSettings>(() => ({@@ -45,6 +64,7 @@ export default function ChatSettingsProvider({ children }: { children: ReactNodesetIsTemporary,config,auth,+ getPaneConversations,}),[duringRunDefaultAction,@@ -55,6 +75,7 @@ export default function ChatSettingsProvider({ children }: { children: ReactNodesetIsTemporary,config,auth,+ getPaneConversations,],);diff --git a/client/src/routes/__tests__/ChatSettings.spec.tsx b/client/src/routes/__tests__/ChatSettings.spec.tsxindex bc5b47b3ee..4c5881b463 100644--- a/client/src/routes/__tests__/ChatSettings.spec.tsx+++ b/client/src/routes/__tests__/ChatSettings.spec.tsx@@ -71,6 +71,22 @@ describe('ChatSettingsProvider', () => {expect(result.current.visibleArtifacts).toBeNull();});+ it('reports the conversation each mounted pane shows when asked', () => {+ const { result } = renderSettings(({ set }) => {+ set(store.conversationKeysAtom, [0, 1]);+ set(store.conversationByIndex(0), { conversationId: 'convo-a' } as never);+ });++ expect(result.current.settings.getPaneConversations()).toEqual([+ { index: 0, conversationId: 'convo-a' },+ { index: 1, conversationId: null },+ ]);+ });++ it('knows no panes when no host supplies settings', () => {+ expect(defaultChatSettings.getPaneConversations()).toEqual([]);+ });+it('keeps feedback and running-chat rename off until the deployment answers', () => {const { result } = renderSettings();