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
🔍 fix: Enable File Search When Attaching From the Files Panel (#16223)
James Todarobe6b5bf7f2c4
diff --git a/client/src/components/SidePanel/Files/PanelTable.tsx b/client/src/components/SidePanel/Files/PanelTable.tsxindex b526ce2ce1..38676ce168 100644--- a/client/src/components/SidePanel/Files/PanelTable.tsx+++ b/client/src/components/SidePanel/Files/PanelTable.tsx@@ -1,4 +1,5 @@import { useState, useCallback, useMemo, useRef } from 'react';+import { useSetRecoilState } from 'recoil';import { ArrowUpLeft } from 'lucide-react';import {Table,@@ -11,14 +12,6 @@ import {TableHeader,useToastContext,} from '@librechat/client';-import {- megabyte,- mergeFileConfig,- checkOpenAIStorage,- isAssistantsEndpoint,- getEndpointFileConfig,- fileConfig as defaultFileConfig,-} from 'librechat-data-provider';import {flexRender,getCoreRowModel,@@ -31,11 +24,24 @@ import {type VisibilityState,type ColumnFiltersState,} from '@tanstack/react-table';+import {+ megabyte,+ Constants,+ EToolResources,+ mergeFileConfig,+ checkOpenAIStorage,+ isEphemeralAgentId,+ isAssistantsEndpoint,+ getEndpointFileConfig,+ defaultAgentCapabilities,+ fileConfig as defaultFileConfig,+} from 'librechat-data-provider';import type { TFile } from 'librechat-data-provider';+import { useLocalize, useUpdateFiles, useGetAgentsConfig, useAgentCapabilities } from '~/hooks';import { MyFilesModal } from '~/components/Chat/Input/Files/MyFilesModal';import { useFileMapContext, useChatContext } from '~/Providers';-import { useLocalize, useUpdateFiles } from '~/hooks';import { useGetFileConfig } from '~/data-provider';+import { ephemeralAgentByConvoId } from '~/store';interface DataTableProps<TData, TValue> {columns: ColumnDef<TData, TValue>[];@@ -91,6 +97,11 @@ export default function DataTable<TData, TValue>({ columns, data }: DataTableProselect: (data) => mergeFileConfig(data),});const { addFile } = useUpdateFiles(setFiles);+ const setEphemeralAgent = useSetRecoilState(+ ephemeralAgentByConvoId(conversation?.conversationId ?? Constants.NEW_CONVO),+ );+ const { agentsConfig } = useGetAgentsConfig();+ const capabilities = useAgentCapabilities(agentsConfig?.capabilities ?? defaultAgentCapabilities);const handleFileClick = useCallback((file: TFile) => {@@ -184,6 +195,20 @@ export default function DataTable<TData, TValue>({ columns, data }: DataTablePro}}+ /** Mirror `AttachFileMenu`: an embedded file is unreadable unless file search is on.+ * The ephemeral flag governs direct chats only — a saved agent's own `tools` decide,+ * so writing it there would be dead state the badge row still reflects. */+ if (+ fileData.embedded === true &&+ capabilities.fileSearchEnabled &&+ isEphemeralAgentId(conversation.agent_id)+ ) {+ setEphemeralAgent((prev) => ({+ ...prev,+ [EToolResources.file_search]: true,+ }));+ }+addFile({progress: 1,attached: true,@@ -200,7 +225,17 @@ export default function DataTable<TData, TValue>({ columns, data }: DataTableProllmDeliveryPath: fileData.llmDeliveryPath,});},- [addFile, files, fileMap, conversation, localize, showToast, fileConfig],+ [+ addFile,+ files,+ fileMap,+ conversation,+ localize,+ showToast,+ fileConfig,+ setEphemeralAgent,+ capabilities.fileSearchEnabled,+ ],);const filenameFilter = table.getColumn('filename')?.getFilterValue() as string;diff --git a/client/src/components/SidePanel/Files/__tests__/PanelTable.spec.tsx b/client/src/components/SidePanel/Files/__tests__/PanelTable.spec.tsxindex 3039820c3b..2e46f2b83e 100644--- a/client/src/components/SidePanel/Files/__tests__/PanelTable.spec.tsx+++ b/client/src/components/SidePanel/Files/__tests__/PanelTable.spec.tsx@@ -1,6 +1,11 @@import React from 'react';import { render, screen, fireEvent } from '@testing-library/react';-import { FileSources, FileContext } from 'librechat-data-provider';+import {+ FileSources,+ FileContext,+ EToolResources,+ AgentCapabilities,+} from 'librechat-data-provider';import type { TFile } from 'librechat-data-provider';import type { ExtendedFile } from '~/common';import { columns } from '../PanelColumns';@@ -8,10 +13,14 @@ import DataTable from '../PanelTable';const mockShowToast = jest.fn();const mockAddFile = jest.fn();+const mockSetEphemeralAgent = jest.fn();let mockFileMap: Record<string, TFile> = {};let mockFiles: Map<string, ExtendedFile> = new Map();let mockConversation: Record<string, unknown> | null = { endpoint: 'openAI' };+let mockAgentsConfig: { capabilities?: string[] } | null = {+ capabilities: [AgentCapabilities.file_search],+};let mockRawFileConfig: Record<string, unknown> | null = {endpoints: {openAI: { fileLimit: 10, supportedMimeTypes: ['application/pdf', 'text/plain'] },@@ -59,9 +68,21 @@ jest.mock('~/Providers', () => ({}),}));+jest.mock('recoil', () => ({+ useSetRecoilState: () => mockSetEphemeralAgent,+}));++jest.mock('~/store', () => ({+ ephemeralAgentByConvoId: (conversationId: string) => ({ key: conversationId }),+}));+jest.mock('~/hooks', () => ({useLocalize: () => (key: string) => key,useUpdateFiles: () => ({ addFile: mockAddFile }),+ useGetAgentsConfig: () => ({ agentsConfig: mockAgentsConfig }),+ useAgentCapabilities: (capabilities?: string[]) => ({+ fileSearchEnabled: capabilities?.includes('file_search') ?? false,+ }),}));jest.mock('~/data-provider', () => ({@@ -124,6 +145,8 @@ describe('PanelTable handleFileClick', () => {beforeEach(() => {mockShowToast.mockClear();mockAddFile.mockClear();+ mockSetEphemeralAgent.mockClear();+ mockAgentsConfig = { capabilities: [AgentCapabilities.file_search] };mockFiles = new Map();mockConversation = { endpoint: 'openAI' };mockRawFileConfig = {@@ -271,4 +294,74 @@ describe('PanelTable handleFileClick', () => {expect(mockAddFile).toHaveBeenCalledTimes(1);});++ it('turns on file search when attaching an embedded file', () => {+ const file = makeFile({ file_id: 'embedded-file', embedded: true });+ mockFileMap = { [file.file_id]: file };++ renderTable([file]);+ clickFilenameCell();++ expect(mockAddFile).toHaveBeenCalledTimes(1);+ expect(mockSetEphemeralAgent).toHaveBeenCalledTimes(1);++ const updater = mockSetEphemeralAgent.mock.calls[0][0];+ expect(updater({ web_search: true })).toEqual({+ web_search: true,+ [EToolResources.file_search]: true,+ });+ });++ it('leaves file search alone for a file that was never embedded', () => {+ const file = makeFile({ file_id: 'plain-file', embedded: false });+ mockFileMap = { [file.file_id]: file };++ renderTable([file]);+ clickFilenameCell();++ expect(mockAddFile).toHaveBeenCalledTimes(1);+ expect(mockSetEphemeralAgent).not.toHaveBeenCalled();+ });++ it('leaves file search alone when the capability is disabled', () => {+ mockAgentsConfig = { capabilities: [] };+ const file = makeFile({ file_id: 'embedded-file', embedded: true });+ mockFileMap = { [file.file_id]: file };++ renderTable([file]);+ clickFilenameCell();++ expect(mockAddFile).toHaveBeenCalledTimes(1);+ expect(mockSetEphemeralAgent).not.toHaveBeenCalled();+ });++ it('leaves file search alone when a saved agent owns the conversation', () => {+ mockConversation = { endpoint: 'openAI', agent_id: 'agent_abc123' };+ const file = makeFile({ file_id: 'embedded-file', embedded: true });+ mockFileMap = { [file.file_id]: file };++ renderTable([file]);+ clickFilenameCell();++ expect(mockAddFile).toHaveBeenCalledTimes(1);+ expect(mockSetEphemeralAgent).not.toHaveBeenCalled();+ });++ it('leaves file search alone when the attachment itself is rejected', () => {+ const file = makeFile({ file_id: 'embedded-file', embedded: true });+ mockFileMap = { [file.file_id]: file };++ mockFiles = new Map(+ Array.from({ length: 5 }, (_, i) => [+ `existing-${i}`,+ makeExtendedFile({ file_id: `existing-${i}` }),+ ]),+ );++ renderTable([file]);+ clickFilenameCell();++ expect(mockAddFile).not.toHaveBeenCalled();+ expect(mockSetEphemeralAgent).not.toHaveBeenCalled();+ });});