mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-17 05:20:55 +00:00
🔍 fix: Enable File Search When Attaching From the Files Panel (#16223)
Some checks are pending
Backend Unit Tests / Build packages (push) Waiting to run
Backend Unit Tests / Codegraph select (push) Waiting to run
Backend Unit Tests / TypeScript type checks (push) Blocked by required conditions
Backend Unit Tests / Circular dependency checks (push) Waiting to run
Backend Unit Tests / Tests: api (shard 1/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 2/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 3/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: data-provider (push) Blocked by required conditions
Backend Unit Tests / Tests: data-schemas (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 1/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 2/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 3/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 4/4) (push) Blocked by required conditions
Codegraph E2E Votes / vote (full suite) (push) Waiting to run
Docker Dev Branch Images Build / publish (push) Waiting to run
Frontend Unit Tests / Client build recovery regression (push) Waiting to run
Frontend Unit Tests / Codegraph select (push) Waiting to run
Frontend Unit Tests / Build packages (push) Waiting to run
Frontend Unit Tests / TypeScript type checks (client) (push) Blocked by required conditions
Frontend Unit Tests / Tests: @librechat/client (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 1/2) (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 2/2) (push) Blocked by required conditions
Frontend Unit Tests / Vite build verification (push) Blocked by required conditions
Some checks are pending
Backend Unit Tests / Build packages (push) Waiting to run
Backend Unit Tests / Codegraph select (push) Waiting to run
Backend Unit Tests / TypeScript type checks (push) Blocked by required conditions
Backend Unit Tests / Circular dependency checks (push) Waiting to run
Backend Unit Tests / Tests: api (shard 1/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 2/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 3/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: data-provider (push) Blocked by required conditions
Backend Unit Tests / Tests: data-schemas (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 1/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 2/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 3/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 4/4) (push) Blocked by required conditions
Codegraph E2E Votes / vote (full suite) (push) Waiting to run
Docker Dev Branch Images Build / publish (push) Waiting to run
Frontend Unit Tests / Client build recovery regression (push) Waiting to run
Frontend Unit Tests / Codegraph select (push) Waiting to run
Frontend Unit Tests / Build packages (push) Waiting to run
Frontend Unit Tests / TypeScript type checks (client) (push) Blocked by required conditions
Frontend Unit Tests / Tests: @librechat/client (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 1/2) (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 2/2) (push) Blocked by required conditions
Frontend Unit Tests / Vite build verification (push) Blocked by required conditions
* 🔍 fix: Enable File Search When Attaching From the Files Panel * 🔍 fix: Skip the Ephemeral File Search Flag for Saved Agents
This commit is contained in:
parent
a9d63d0fe2
commit
be6b5bf7f2
2 changed files with 139 additions and 11 deletions
|
|
@ -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 }: 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<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 }: 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;
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue