2024-12-19 13:04:48 -05:00
|
|
|
import React, { useMemo } from 'react';
|
|
|
|
|
import { EModelEndpoint, EToolResources } from 'librechat-data-provider';
|
2025-03-10 17:23:46 -04:00
|
|
|
import { FileSearch, ImageUpIcon, FileType2Icon, TerminalSquareIcon } from 'lucide-react';
|
2024-12-19 13:04:48 -05:00
|
|
|
import OGDialogTemplate from '~/components/ui/OGDialogTemplate';
|
2025-02-03 10:53:04 -05:00
|
|
|
import { useGetEndpointsQuery } from '~/data-provider';
|
2024-12-19 13:04:48 -05:00
|
|
|
import useLocalize from '~/hooks/useLocalize';
|
|
|
|
|
import { OGDialog } from '~/components/ui';
|
|
|
|
|
|
|
|
|
|
interface DragDropModalProps {
|
|
|
|
|
onOptionSelect: (option: string | undefined) => void;
|
|
|
|
|
files: File[];
|
|
|
|
|
isVisible: boolean;
|
|
|
|
|
setShowModal: (showModal: boolean) => void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface FileOption {
|
|
|
|
|
label: string;
|
|
|
|
|
value?: EToolResources;
|
|
|
|
|
icon: React.JSX.Element;
|
|
|
|
|
condition?: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const DragDropModal = ({ onOptionSelect, setShowModal, files, isVisible }: DragDropModalProps) => {
|
|
|
|
|
const localize = useLocalize();
|
|
|
|
|
const { data: endpointsConfig } = useGetEndpointsQuery();
|
|
|
|
|
const capabilities = useMemo(
|
|
|
|
|
() => endpointsConfig?.[EModelEndpoint.agents]?.capabilities ?? [],
|
|
|
|
|
[endpointsConfig],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const options = useMemo(() => {
|
|
|
|
|
const _options: FileOption[] = [
|
|
|
|
|
{
|
|
|
|
|
label: localize('com_ui_upload_image_input'),
|
|
|
|
|
value: undefined,
|
|
|
|
|
icon: <ImageUpIcon className="icon-md" />,
|
🧭 refactor: Modernize Nav/Header (#7094)
* refactor: streamline model preset handling in conversation setup
* refactor: integrate navigation and location hooks in chat functions and event handlers, prevent cache from fetching on final event handling
* fix: prevent adding code interpreter non-image output to file list on message attachment event, fix all unhandled edge cases when this is done (treating the file download as an image attachment, undefined fields, message tokenCount issues, use of `startsWith` on undefined "text") although it is now prevent altogether
* chore: remove unused jailbreak prop from MinimalIcon component in EndpointIcon
* feat: add new SVG icons (MobileSidebar, Sidebar, XAIcon), fix: xAI styling in dark vs. light modes, adjust styling of Landing icons
* fix: open conversation in new tab on navigation with ctrl/meta key
* refactor: update Nav & Header to use close/open sidebar buttons, as well as redesign "New Chat"/"Bookmarks" buttons to the top of the Nav, matching the latest design of ChatGPT for simplicity and to free up space
* chore: remove unused isToggleHovering state and simplify opacity logic in Nav component
* style: match mobile nav to mobile header
2025-04-27 14:03:25 -04:00
|
|
|
condition: files.every((file) => file.type?.startsWith('image/')),
|
2024-12-19 13:04:48 -05:00
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
for (const capability of capabilities) {
|
|
|
|
|
if (capability === EToolResources.file_search) {
|
|
|
|
|
_options.push({
|
|
|
|
|
label: localize('com_ui_upload_file_search'),
|
|
|
|
|
value: EToolResources.file_search,
|
|
|
|
|
icon: <FileSearch className="icon-md" />,
|
|
|
|
|
});
|
|
|
|
|
} else if (capability === EToolResources.execute_code) {
|
|
|
|
|
_options.push({
|
|
|
|
|
label: localize('com_ui_upload_code_files'),
|
|
|
|
|
value: EToolResources.execute_code,
|
|
|
|
|
icon: <TerminalSquareIcon className="icon-md" />,
|
|
|
|
|
});
|
2025-03-10 17:23:46 -04:00
|
|
|
} else if (capability === EToolResources.ocr) {
|
|
|
|
|
_options.push({
|
|
|
|
|
label: localize('com_ui_upload_ocr_text'),
|
|
|
|
|
value: EToolResources.ocr,
|
|
|
|
|
icon: <FileType2Icon className="icon-md" />,
|
|
|
|
|
});
|
2024-12-19 13:04:48 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _options;
|
|
|
|
|
}, [capabilities, files, localize]);
|
|
|
|
|
|
|
|
|
|
if (!isVisible) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<OGDialog open={isVisible} onOpenChange={setShowModal}>
|
|
|
|
|
<OGDialogTemplate
|
|
|
|
|
title={localize('com_ui_upload_type')}
|
|
|
|
|
className="w-11/12 sm:w-[440px] md:w-[400px] lg:w-[360px]"
|
|
|
|
|
main={
|
|
|
|
|
<div className="flex flex-col gap-2">
|
|
|
|
|
{options.map(
|
|
|
|
|
(option, index) =>
|
|
|
|
|
option.condition !== false && (
|
|
|
|
|
<button
|
|
|
|
|
key={index}
|
|
|
|
|
onClick={() => onOptionSelect(option.value)}
|
|
|
|
|
className="flex items-center gap-2 rounded-lg p-2 hover:bg-surface-active-alt"
|
|
|
|
|
>
|
|
|
|
|
{option.icon}
|
|
|
|
|
<span>{option.label}</span>
|
|
|
|
|
</button>
|
|
|
|
|
),
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
</OGDialog>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default DragDropModal;
|