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: Move Pane Composer Files to Jotai in the Chat Package (#17193)
Marco Beretta59849fd5f9e8
diff --git a/client/src/common/types.ts b/client/src/common/types.tsindex ef32a10b79..f03493d51a 100644--- a/client/src/common/types.ts+++ b/client/src/common/types.ts@@ -1,7 +1,8 @@import { RefObject } from 'react';-import { FileSources, isEphemeralAgentId } from 'librechat-data-provider';+import { isEphemeralAgentId } from 'librechat-data-provider';import type { PaneOptionSettings } from '@librechat/chat/react';import type { UseMutationResult } from '@tanstack/react-query';+import type { ExtendedFile } from '@librechat/chat';import type * as t from 'librechat-data-provider';import type { LucideIcon } from 'lucide-react';import type { SetterOrUpdater } from 'recoil';@@ -509,25 +510,7 @@ export type PromptOption = MentionOption & {export type TOptionSettings = PaneOptionSettings;-export interface ExtendedFile {- file?: File;- file_id: string;- temp_file_id?: string;- type?: string;- filepath?: string;- filename?: string;- width?: number;- height?: number;- size: number;- preview?: string;- progress: number;- source?: FileSources;- attached?: boolean;- embedded?: boolean;- llmDeliveryPath?: t.TFile['llmDeliveryPath'];- tool_resource?: string;- metadata?: t.TFile['metadata'];-}+export type { ExtendedFile };export type TLoginLayoutContext = {startupConfig: t.TStartupConfig | null;diff --git a/client/src/components/Chat/Input/Files/Table/DataTable.tsx b/client/src/components/Chat/Input/Files/Table/DataTable.tsxindex 287064e96f..06b09418eb 100644--- a/client/src/components/Chat/Input/Files/Table/DataTable.tsx+++ b/client/src/components/Chat/Input/Files/Table/DataTable.tsx@@ -1,5 +1,6 @@import { useRef, useState, useEffect, useCallback } from 'react';-import { useSetRecoilState } from 'recoil';+import { useSetAtom } from 'jotai';+import { filesFamily } from '@librechat/chat/react';import { FileContext } from 'librechat-data-provider';import { useVirtualizer } from '@tanstack/react-virtual';import {@@ -33,7 +34,6 @@ import { ColumnVisibilityDropdown } from './ColumnVisibilityDropdown';import { useDeleteFilesFromTable } from '~/hooks/Files';import { useLocalize, TranslationKeys } from '~/hooks';import { cn } from '~/utils';-import store from '~/store';interface DataTableProps<TData, TValue> {columns: ColumnDef<TData, TValue>[];@@ -60,7 +60,7 @@ type Style = {export default function DataTable<TData, TValue>({ columns, data }: DataTableProps<TData, TValue>) {const localize = useLocalize();const [isDeleting, setIsDeleting] = useState(false);- const setFiles = useSetRecoilState(store.filesByIndex(0));+ const setFiles = useSetAtom(filesFamily(0));const { deleteFiles } = useDeleteFilesFromTable(() => setIsDeleting(false));const [rowSelection, setRowSelection] = useState({});diff --git a/client/src/components/Chat/Input/__tests__/ChatForm.approvalMode.spec.tsx b/client/src/components/Chat/Input/__tests__/ChatForm.approvalMode.spec.tsxindex 0869a16126..d713f99d0d 100644--- a/client/src/components/Chat/Input/__tests__/ChatForm.approvalMode.spec.tsx+++ b/client/src/components/Chat/Input/__tests__/ChatForm.approvalMode.spec.tsx@@ -1,10 +1,10 @@import React, { useMemo, useState } from 'react';import { getDefaultStore, useAtom } from 'jotai';-import { isSubmittingFamily, resetSubmitting } from '@librechat/chat/react';+import { filesFamily, isSubmittingFamily, resetSubmitting } from '@librechat/chat/react';import '@testing-library/jest-dom';+import { RecoilRoot } from 'recoil';import { DndProvider } from 'react-dnd';import { useForm } from 'react-hook-form';-import { RecoilRoot, useRecoilState } from 'recoil';import { HTML5Backend } from 'react-dnd-html5-backend';import { render, screen } from '@testing-library/react';import { BrowserRouter as Router } from 'react-router-dom';@@ -15,7 +15,6 @@ import type { ChatFormValues } from '~/common';import { ChatContext, ChatFormProvider } from '~/Providers';import { AuthContextProvider } from '~/hooks/AuthContext';import ChatForm from '../ChatForm';-import store from '~/store';import '~/Providers/SteerHostContext';jest.mock('~/hooks/Agents/useCodeApprovalMode', () => ({@@ -36,7 +35,7 @@ const conversation = {} as TConversation;function Harness() {- const [files, setFiles] = useRecoilState(store.filesByIndex(0));+ const [files, setFiles] = useAtom(filesFamily(0));const [isSubmitting] = useAtom(isSubmittingFamily(0));const [, setFilesLoading] = useState(false);const methods = useForm<ChatFormValues>({ defaultValues: { text: '' } });@@ -106,6 +105,7 @@ function renderComposer({ submitting }: { submitting: boolean }) {afterEach(() => {resetSubmitting(getDefaultStore());+ getDefaultStore().set(filesFamily(0), new Map());});describe('ChatForm code approval mode', () => {diff --git a/client/src/components/Chat/Input/__tests__/ChatForm.attachments.spec.tsx b/client/src/components/Chat/Input/__tests__/ChatForm.attachments.spec.tsxindex 621964e5bf..2c2be111f7 100644--- a/client/src/components/Chat/Input/__tests__/ChatForm.attachments.spec.tsx+++ b/client/src/components/Chat/Input/__tests__/ChatForm.attachments.spec.tsx@@ -1,5 +1,5 @@import React, { Profiler, useMemo, useState } from 'react';-import { isSubmittingFamily, resetSubmitting } from '@librechat/chat/react';+import { filesFamily, isSubmittingFamily, resetSubmitting } from '@librechat/chat/react';import '@testing-library/jest-dom';import { DndProvider } from 'react-dnd';import { useForm } from 'react-hook-form';@@ -92,7 +92,7 @@ class StubImage {let commits = 0;function Harness() {- const [files, setFiles] = useRecoilState(store.filesByIndex(0));+ const [files, setFiles] = useAtom(filesFamily(0));const [isSubmitting, setIsSubmitting] = useAtom(isSubmittingFamily(0));/* ChatView owns this read and passes it in; the harness stands in for it. */const [speechSettingsInitialized] = useRecoilState(store.speechSettingsInitialized);@@ -201,6 +201,7 @@ const image = () => new File(['image-bytes'], 'cat.png', { type: 'image/png' });afterEach(() => {resetSubmitting(getDefaultStore());+ getDefaultStore().set(filesFamily(0), new Map());});describe('ChatForm attachments', () => {diff --git a/client/src/components/Chat/Input/__tests__/ChatForm.enterToSend.spec.tsx b/client/src/components/Chat/Input/__tests__/ChatForm.enterToSend.spec.tsxindex d93625ad55..b3343480b9 100644--- a/client/src/components/Chat/Input/__tests__/ChatForm.enterToSend.spec.tsx+++ b/client/src/components/Chat/Input/__tests__/ChatForm.enterToSend.spec.tsx@@ -1,10 +1,10 @@import React, { useMemo, useState } from 'react';-import { useAtom } from 'jotai';-import { isSubmittingFamily } from '@librechat/chat/react';+import { getDefaultStore, useAtom } from 'jotai';+import { filesFamily, isSubmittingFamily } from '@librechat/chat/react';import '@testing-library/jest-dom';+import { RecoilRoot } from 'recoil';import { DndProvider } from 'react-dnd';import { useForm } from 'react-hook-form';-import { RecoilRoot, useRecoilState } from 'recoil';import userEvent from '@testing-library/user-event';import { HTML5Backend } from 'react-dnd-html5-backend';import { render, screen } from '@testing-library/react';@@ -16,7 +16,6 @@ import type { ChatFormValues } from '~/common';import { ChatContext, ChatFormProvider } from '~/Providers';import { AuthContextProvider } from '~/hooks/AuthContext';import ChatForm from '../ChatForm';-import store from '~/store';import '~/Providers/SteerHostContext';const conversation = {@@ -32,7 +31,7 @@ const conversation = {* passes it, not the atom it used to read directly, so each value is covered.*/function Harness({ enterToSend }: { enterToSend: boolean }) {- const [files, setFiles] = useRecoilState(store.filesByIndex(0));+ const [files, setFiles] = useAtom(filesFamily(0));const [isSubmitting] = useAtom(isSubmittingFamily(0));const [, setFilesLoading] = useState(false);const methods = useForm<ChatFormValues>({ defaultValues: { text: '' } });@@ -106,6 +105,10 @@ function renderComposer({ enterToSend }: { enterToSend: boolean }) {);}+afterEach(() => {+ getDefaultStore().set(filesFamily(0), new Map());+});+describe('ChatForm enterToSend prop', () => {beforeEach(() => {localStorage.clear();diff --git a/client/src/components/Chat/Input/__tests__/ChatForm.pasteUpload.spec.tsx b/client/src/components/Chat/Input/__tests__/ChatForm.pasteUpload.spec.tsxindex 1268c153de..c1cf175f8d 100644--- a/client/src/components/Chat/Input/__tests__/ChatForm.pasteUpload.spec.tsx+++ b/client/src/components/Chat/Input/__tests__/ChatForm.pasteUpload.spec.tsx@@ -1,10 +1,10 @@import React, { useMemo, useState } from 'react';-import { useAtom } from 'jotai';-import { isSubmittingFamily } from '@librechat/chat/react';+import { getDefaultStore, useAtom } from 'jotai';+import { filesFamily, isSubmittingFamily } from '@librechat/chat/react';import '@testing-library/jest-dom';+import { RecoilRoot } from 'recoil';import { DndProvider } from 'react-dnd';import { useForm } from 'react-hook-form';-import { RecoilRoot, useRecoilState } from 'recoil';import userEvent from '@testing-library/user-event';import { HTML5Backend } from 'react-dnd-html5-backend';import { BrowserRouter as Router } from 'react-router-dom';@@ -17,7 +17,6 @@ import { ChatContext, ChatFormProvider } from '~/Providers';import { AuthContextProvider } from '~/hooks/AuthContext';import DragDropWrapper from '../Files/DragDropWrapper';import ChatForm from '../ChatForm';-import store from '~/store';import '~/Providers/SteerHostContext';const mockUpload = jest.fn();@@ -68,7 +67,7 @@ class StubImage {}function Harness() {- const [files, setFiles] = useRecoilState(store.filesByIndex(0));+ const [files, setFiles] = useAtom(filesFamily(0));const [isSubmitting] = useAtom(isSubmittingFamily(0));const [, setFilesLoading] = useState(false);const methods = useForm<ChatFormValues>({ defaultValues: { text: '' } });@@ -161,6 +160,10 @@ const pasteImage = (textarea: HTMLElement) => {fireEvent(textarea, event);};+afterEach(() => {+ getDefaultStore().set(filesFamily(0), new Map());+});+/*** The upload-destination dialog is opened by the paste itself, so Radix has no* trigger to return focus to when it closes and used to leave focus ondiff --git a/client/src/components/Chat/Input/__tests__/ChatForm.queryParams.spec.tsx b/client/src/components/Chat/Input/__tests__/ChatForm.queryParams.spec.tsxindex 08b60788dd..7e6d397979 100644--- a/client/src/components/Chat/Input/__tests__/ChatForm.queryParams.spec.tsx+++ b/client/src/components/Chat/Input/__tests__/ChatForm.queryParams.spec.tsx@@ -1,13 +1,13 @@import React, { useMemo, useState } from 'react';+import { RecoilRoot } from 'recoil';import { DndProvider } from 'react-dnd';import { useForm } from 'react-hook-form';-import { RecoilRoot, useRecoilState } from 'recoil';import { HTML5Backend } from 'react-dnd-html5-backend';import { QueryKeys, EModelEndpoint } from 'librechat-data-provider';import { act, render, screen, fireEvent } from '@testing-library/react';import { QueryClient, QueryClientProvider } from '@tanstack/react-query';import { MemoryRouter, useNavigate, useLocation } from 'react-router-dom';-import { isSubmittingFamily, resetSubmitting } from '@librechat/chat/react';+import { filesFamily, isSubmittingFamily, resetSubmitting } from '@librechat/chat/react';import { Provider as JotaiProvider, createStore, getDefaultStore, useAtom } from 'jotai';import {activeGenerationCreatedAtByConvoId,@@ -58,7 +58,7 @@ function Harness({onAsk?: typeof ask;speechSettingsInitialized?: boolean;}) {- const [files, setFiles] = useRecoilState(store.filesByIndex(0));+ const [files, setFiles] = useAtom(filesFamily(0));const [isSubmitting] = useAtom(isSubmittingFamily(0));const [, setFilesLoading] = useState(false);const methods = useForm<ChatFormValues>({ defaultValues: { text: '' } });diff --git a/client/src/hooks/Chat/useChatHelpers.ts b/client/src/hooks/Chat/useChatHelpers.tsindex 927db58ef2..4ea1b22b5f 100644--- a/client/src/hooks/Chat/useChatHelpers.ts+++ b/client/src/hooks/Chat/useChatHelpers.ts@@ -1,9 +1,10 @@import { useCallback, useMemo, useRef, useState } from 'react';+import { useRecoilValue } from 'recoil';import { useQueryClient } from '@tanstack/react-query';-import { useRecoilState, useRecoilValue } from 'recoil';import { useAtom, useSetAtom, useStore, useAtomValue } from 'jotai';import { Constants, QueryKeys, isAssistantsEndpoint } from 'librechat-data-provider';import {+ filesFamily,presetFamily,optionSettingsFamily,activeGenerationCreatedAtByConvoId,@@ -35,7 +36,7 @@ const useLiveAttachments = () => useRecoilValue(store.messageAttachmentsMap);// this to be set somewhere elseexport default function useChatHelpers(index = 0, paramId?: string): ChatContract {const clearAllSubmissions = useClearSubmissions();- const [files, setFiles] = useRecoilState(store.filesByIndex(index));+ const [files, setFiles] = useAtom(filesFamily(index));const [filesLoading, setFilesLoading] = useState(false);const queryClient = useQueryClient();diff --git a/client/src/hooks/Config/__tests__/useClearStates.spec.tsx b/client/src/hooks/Config/__tests__/useClearStates.spec.tsxindex 9e52e083d3..f2da70325c 100644--- a/client/src/hooks/Config/__tests__/useClearStates.spec.tsx+++ b/client/src/hooks/Config/__tests__/useClearStates.spec.tsx@@ -4,6 +4,7 @@ import { act, renderHook } from '@testing-library/react';import { createStore, Provider as JotaiProvider } from 'jotai';import { Constants, ReasoningEffort } from 'librechat-data-provider';import {+ filesFamily,presetFamily,abortScrollFamily,optionSettingsFamily,@@ -11,6 +12,7 @@ import {submissionStartFamily,} from '@librechat/chat/react';import type { TPreset } from 'librechat-data-provider';+import type { ExtendedFile } from '~/common';import {pendingQuotesByConvoId,pendingManualSkillsByConvoId,@@ -122,16 +124,17 @@ describe('useClearStates', () => {expected.map((kept) => (kept ? 1000 : null)),);});- /* The preset and option toggles of each pane are per-session choices: a pane- that survives sign-out must not hand them to the next account. */+ /* The preset, option toggles and staged files of each pane are per-session+ state: a pane that survives sign-out must not hand them to the next account. */it.each([[false, [null, null]],[true, ['kept', null]],- ])('resets per-pane preset and option settings (skipFirst %s)', async (skipFirst, expected) => {+ ])('resets per-pane preset, options and files (skipFirst %s)', async (skipFirst, expected) => {const jotaiStore = createStore();for (const key of [0, 1]) {jotaiStore.set(presetFamily(key), { title: 'kept' } as TPreset);jotaiStore.set(optionSettingsFamily(key), { showExamples: true });+ jotaiStore.set(filesFamily(key), new Map([['kept', { file_id: 'kept' } as ExtendedFile]]));}const wrapper = ({ children }: { children: React.ReactNode }) => (<JotaiProvider store={jotaiStore}>@@ -150,5 +153,8 @@ describe('useClearStates', () => {expect([0, 1].map((key) => jotaiStore.get(optionSettingsFamily(key)).showExamples ?? null),).toEqual(expected.map((kept) => (kept ? true : null)));+ expect([0, 1].map((key) => jotaiStore.get(filesFamily(key)).has('kept') || null)).toEqual(+ expected.map((kept) => (kept ? true : null)),+ );});});diff --git a/client/src/hooks/Config/useClearStates.ts b/client/src/hooks/Config/useClearStates.tsindex 0615df9fcc..e2de38e778 100644--- a/client/src/hooks/Config/useClearStates.ts+++ b/client/src/hooks/Config/useClearStates.ts@@ -2,6 +2,7 @@ import { useStore } from 'jotai';import { useRecoilCallback } from 'recoil';import { Constants } from 'librechat-data-provider';import {+ filesFamily,presetFamily,abortScrollFamily,isSubmittingFamily,@@ -59,7 +60,7 @@ export default function useClearStates() {continue;}- reset(store.filesByIndex(key));+ jotaiStore.set(filesFamily(key), new Map());jotaiStore.set(presetFamily(key), null);jotaiStore.set(showStopButtonByIndex(key), false);jotaiStore.set(abortScrollFamily(key), false);diff --git a/client/src/hooks/Conversations/__tests__/useNewChat.spec.ts b/client/src/hooks/Conversations/__tests__/useNewChat.spec.tsindex 4ded82c257..dfa6516a38 100644--- a/client/src/hooks/Conversations/__tests__/useNewChat.spec.ts+++ b/client/src/hooks/Conversations/__tests__/useNewChat.spec.ts@@ -1,6 +1,8 @@+import { getDefaultStore } from 'jotai';+import { filesFamily } from '@librechat/chat/react';import { renderHook, act } from '@testing-library/react';-import type { MouseEvent } from 'react';+import type { ExtendedFile } from '~/common';import type { FilesDraft } from '~/utils';const mockNewConversation = jest.fn();@@ -28,7 +30,13 @@ const mockState = {tabId: 'this-tab',filesDraft: { fileIds: [], pendingPastes: {} } as FilesDraft,pendingFilesDraft: { fileIds: [], pendingPastes: {} } as FilesDraft,- files: new Map<string, LiveFile>(),+ /** Pane 0's live composer files, held in the real Jotai atom the hook reads. */+ get files(): Map<string, LiveFile> {+ return getDefaultStore().get(filesFamily(0));+ },+ set files(files: Map<string, LiveFile>) {+ getDefaultStore().set(filesFamily(0), files as Map<string, ExtendedFile>);+ },retainedDeletions: [] as { file_id: string; filepath: string; source: string }[],markedPasteIds: [] as string[],submittedPasteIds: [] as string[],@@ -61,9 +69,6 @@ jest.mock('recoil', () => ({if (typeof key === 'string' && key.startsWith('conversationIdByIndex')) {return 'convo-1';}- if (typeof key === 'string' && key.startsWith('files-by-index')) {- return mockState.files;- }if (typeof key === 'string' && key.startsWith('isSubmitting')) {return mockState.isSubmitting;}@@ -210,7 +215,6 @@ jest.mock('~/store', () => ({__esModule: true,default: {conversationIdByIndex: (index: number) => `conversationIdByIndex-${index}`,- filesByIndex: (index: number) => `files-by-index-${index}`,},}));diff --git a/client/src/hooks/Conversations/useNewChat.ts b/client/src/hooks/Conversations/useNewChat.tsindex 94a041f570..a34739b876 100644--- a/client/src/hooks/Conversations/useNewChat.ts+++ b/client/src/hooks/Conversations/useNewChat.ts@@ -1,5 +1,7 @@import { useCallback, useEffect, useState } from 'react';+import { useAtomValue } from 'jotai';import { useRecoilValue } from 'recoil';+import { filesFamily } from '@librechat/chat/react';import { QueryKeys } from 'librechat-data-provider';import { useQueryClient } from '@tanstack/react-query';import type { FileSources, TFile } from 'librechat-data-provider';@@ -119,7 +121,7 @@ export default function useNewChat({const queryClient = useQueryClient();const { newConversation } = useNewConvo(index);const conversationId = useRecoilValue(store.conversationIdByIndex(index));- const files = useRecoilValue(store.filesByIndex(index));+ const files = useAtomValue(filesFamily(index));const { saveDrafts } = useChatSettings();const { data: fileList } = useGetFiles<TFile[]>();const { mutateAsync } = useDeleteFilesMutation();diff --git a/client/src/hooks/__tests__/useNewConvo.spec.ts b/client/src/hooks/__tests__/useNewConvo.spec.tsindex c72c2cf782..d1bf07e272 100644--- a/client/src/hooks/__tests__/useNewConvo.spec.ts+++ b/client/src/hooks/__tests__/useNewConvo.spec.ts@@ -1,9 +1,11 @@+import { getDefaultStore } from 'jotai';+import { filesFamily } from '@librechat/chat/react';import { renderHook, act } from '@testing-library/react';import { Constants, EModelEndpoint } from 'librechat-data-provider';import type { TConversation } from 'librechat-data-provider';+import type { ExtendedFile } from '~/common';const mockDeleteFiles = jest.fn();-const mockSetFiles = jest.fn();const mockRemoveTabAttachmentPresence = jest.fn();const mockCollectForeignAttachmentClaims = jest.fn((_excludeDraftIds: string[], _excludeOwnPane?: number | 'tab') => new Set(mockForeignClaims),@@ -38,7 +40,6 @@ jest.mock('~/Providers/ChatSettingsContext', () => ({}));jest.mock('recoil', () => ({- useRecoilState: () => [mockFiles, mockSetFiles],useRecoilValue: (key: string) => {if (key === 'saveBadgesState') {return true;@@ -107,7 +108,6 @@ jest.mock('~/store', () => ({default: {defaultPreset: 'defaultPreset',saveBadgesState: 'saveBadgesState',- filesByIndex: () => 'filesByIndex',useClearConvoState: () => jest.fn(),useSetConversationAtom: () => ({ setConversation: jest.fn() }),},@@ -181,6 +181,10 @@ describe('useNewConvo reset cleanup', () => {filepath: '/uploads/own-file.txt',source: 'local',});+ /** The hook reads the real pane atom, so each pane a test renders starts on this map. */+ for (const index of [0, 2]) {+ getDefaultStore().set(filesFamily(index), mockFiles as Map<string, ExtendedFile>);+ }});it('does not delete a file claimed by another tab but deletes an unclaimed file', () => {diff --git a/client/src/hooks/useNewConvo.ts b/client/src/hooks/useNewConvo.tsindex 2b291b2c0b..244c217e5c 100644--- a/client/src/hooks/useNewConvo.ts+++ b/client/src/hooks/useNewConvo.ts@@ -1,9 +1,9 @@import { useCallback } from 'react';-import { useSetAtom } from 'jotai';-import { submissionByIndex } from '@librechat/chat/react';+import { useAtom, useSetAtom } from 'jotai';+import { useRecoilValue, useRecoilCallback } from 'recoil';import { useNavigate, useSearchParams } from 'react-router-dom';+import { filesFamily, submissionByIndex } from '@librechat/chat/react';import { useGetModelsQuery } from 'librechat-data-provider/react-query';-import { useRecoilState, useRecoilValue, useRecoilCallback } from 'recoil';import {Constants,FileSources,@@ -85,7 +85,7 @@ const useNewConvo = (index = 0) => {const clearAllConversations = store.useClearConvoState();const defaultPreset = useRecoilValue(store.defaultPreset);const { setConversation } = store.useSetConversationAtom(index);- const [files, setFiles] = useRecoilState(store.filesByIndex(index));+ const [files, setFiles] = useAtom(filesFamily(index));const setSubmission = useSetAtom(submissionByIndex(index));const { data: endpointsConfig = {} as TEndpointsConfig } = useGetEndpointsQuery();const agentsMap = useAgentsMapContext();diff --git a/client/src/store/families.ts b/client/src/store/families.tsindex 4856057c70..af3ab9fc40 100644--- a/client/src/store/families.ts+++ b/client/src/store/families.ts@@ -11,7 +11,6 @@ import {useRecoilCallback,} from 'recoil';import type { EModelEndpoint, TConversation } from 'librechat-data-provider';-import type { ExtendedFile } from '~/common';import {clearModelForNonEphemeralAgent,createChatSearchParams,@@ -90,11 +89,6 @@ const conversationByIndex = atomFamily<TConversation | null, string | number>({] as const,});-const filesByIndex = atomFamily<Map<string, ExtendedFile>, string | number>({- key: 'filesByIndex',- default: new Map(),-});-const conversationKeysAtom = atom<(string | number)[]>({key: 'conversationKeys',default: [],@@ -304,7 +298,6 @@ const updateConversationSelector = selectorFamily({export default {conversationKeysAtom,conversationByIndex,- filesByIndex,conversationIdByIndex,conversationEndpointByIndex,effectiveEndpointByIndex,diff --git a/packages/chat/src/core/files.ts b/packages/chat/src/core/files.tsindex 5ee4c5f80a..90b1677ef4 100644--- a/packages/chat/src/core/files.ts+++ b/packages/chat/src/core/files.ts@@ -1,4 +1,25 @@-import type { TFile, TMessage } from 'librechat-data-provider';+import type { FileSources, TFile, TMessage } from 'librechat-data-provider';++/** A file attached to a chat pane's composer, from local pick through upload. */+export interface ExtendedFile {+ file?: File;+ file_id: string;+ temp_file_id?: string;+ type?: string;+ filepath?: string;+ filename?: string;+ width?: number;+ height?: number;+ size: number;+ preview?: string;+ progress: number;+ source?: FileSources;+ attached?: boolean;+ embedded?: boolean;+ llmDeliveryPath?: TFile['llmDeliveryPath'];+ tool_resource?: string;+ metadata?: TFile['metadata'];+}export type FileDeliveryMetadataMap = Readonly<Record<string, Pick<TFile, 'llmDeliveryPath'> | undefined>diff --git a/packages/chat/src/react.ts b/packages/chat/src/react.tsindex 881a0268c1..88b6480078 100644--- a/packages/chat/src/react.ts+++ b/packages/chat/src/react.ts@@ -74,5 +74,5 @@ export type {SteerNotification,SteerRequestCallbacks,} from './react/steer/host';-export { presetFamily, optionSettingsFamily } from './react/pane';+export { presetFamily, filesFamily, optionSettingsFamily } from './react/pane';export type { PaneOptionSettings } from './react/pane';diff --git a/packages/chat/src/react/pane/__tests__/pane.spec.ts b/packages/chat/src/react/pane/__tests__/pane.spec.tsindex 7366903310..6eb343ff7c 100644--- a/packages/chat/src/react/pane/__tests__/pane.spec.ts+++ b/packages/chat/src/react/pane/__tests__/pane.spec.ts@@ -1,22 +1,27 @@import { createStore } from 'jotai';import type { TPreset } from 'librechat-data-provider';-import { presetFamily, optionSettingsFamily } from '../index';+import type { ExtendedFile } from '../../../core/files';+import { presetFamily, filesFamily, optionSettingsFamily } from '../index';describe('pane families', () => {it('start empty for every pane', () => {const store = createStore();expect(store.get(presetFamily(0))).toBeNull();expect(store.get(optionSettingsFamily(0))).toEqual({});+ expect(store.get(filesFamily(0)).size).toBe(0);});it('keep each pane independent', () => {const store = createStore();store.set(presetFamily(0), { title: 'first' } as TPreset);store.set(optionSettingsFamily(0), { showExamples: true });+ store.set(filesFamily(0), new Map([['file-1', { file_id: 'file-1' } as ExtendedFile]]));expect(store.get(presetFamily(1))).toBeNull();expect(store.get(optionSettingsFamily(1))).toEqual({});+ expect(store.get(filesFamily(1)).size).toBe(0);expect(store.get(presetFamily(0))?.title).toBe('first');expect(store.get(optionSettingsFamily(0)).showExamples).toBe(true);+ expect([...store.get(filesFamily(0)).keys()]).toEqual(['file-1']);});});diff --git a/packages/chat/src/react/pane/files.ts b/packages/chat/src/react/pane/files.tsnew file mode 100644index 0000000000..05777ff526--- /dev/null+++ b/packages/chat/src/react/pane/files.ts@@ -0,0 +1,12 @@+import { atom } from 'jotai';+import { atomFamily } from 'jotai/utils';+import type { PrimitiveAtom } from 'jotai';+import type { ExtendedFile } from '../../core/files';+import type { Family } from '../steer/family';++/** Files staged in one chat pane's composer, keyed by file id, per pane index. */+export const filesFamily: Family<+ Map<string, ExtendedFile>,+ PrimitiveAtom<Map<string, ExtendedFile>>,+ string | number+> = atomFamily((_index: string | number) => atom<Map<string, ExtendedFile>>(new Map()));diff --git a/packages/chat/src/react/pane/index.ts b/packages/chat/src/react/pane/index.tsindex 3f76a16735..5fa3083364 100644--- a/packages/chat/src/react/pane/index.ts+++ b/packages/chat/src/react/pane/index.ts@@ -1,3 +1,4 @@export { presetFamily } from './preset';+export { filesFamily } from './files';export { optionSettingsFamily } from './options';export type { PaneOptionSettings } from './options';