From be6b5bf7f2c45ea46b06cad57f5e62fd85e69e91 Mon Sep 17 00:00:00 2001 From: James Todaro <30529065+jtodaroii@users.noreply.github.com> Date: Tue, 22 Sep 2026 19:50:19 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=8D=20fix:=20Enable=20File=20Search=20?= =?UTF-8?q?When=20Attaching=20From=20the=20Files=20Panel=20(#16223)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🔍 fix: Enable File Search When Attaching From the Files Panel * 🔍 fix: Skip the Ephemeral File Search Flag for Saved Agents --- .../components/SidePanel/Files/PanelTable.tsx | 55 +++++++++-- .../Files/__tests__/PanelTable.spec.tsx | 95 ++++++++++++++++++- 2 files changed, 139 insertions(+), 11 deletions(-) diff --git a/client/src/components/SidePanel/Files/PanelTable.tsx b/client/src/components/SidePanel/Files/PanelTable.tsx index 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 { columns: ColumnDef[]; @@ -91,6 +97,11 @@ export default function DataTable({ columns, data }: DataTablePro select: (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({ 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({ columns, data }: DataTablePro llmDeliveryPath: 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.tsx index 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 = {}; let mockFiles: Map = new Map(); let mockConversation: Record | null = { endpoint: 'openAI' }; +let mockAgentsConfig: { capabilities?: string[] } | null = { + capabilities: [AgentCapabilities.file_search], +}; let mockRawFileConfig: Record | 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(); + }); });