mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-22 06:00:56 +02:00
feat: capabilities filtering on AttachFileButton
This commit is contained in:
parent
bb6ee0dc58
commit
d8997fdf0e
1 changed files with 27 additions and 11 deletions
|
@ -1,13 +1,17 @@
|
||||||
import * as Ariakit from '@ariakit/react';
|
import * as Ariakit from '@ariakit/react';
|
||||||
import { EToolResources } from 'librechat-data-provider';
|
|
||||||
import React, { useRef, useState, useMemo, useCallback } from 'react';
|
import React, { useRef, useState, useMemo, useCallback } from 'react';
|
||||||
|
import { EToolResources, defaultAgentCapabilities } from 'librechat-data-provider';
|
||||||
import { FileSearch, ImageUpIcon, TerminalSquareIcon, FileType2Icon } from 'lucide-react';
|
import { FileSearch, ImageUpIcon, TerminalSquareIcon, FileType2Icon } from 'lucide-react';
|
||||||
import { FileUpload, DropdownPopup, AttachmentIcon, SharePointIcon } from '@librechat/client';
|
import { FileUpload, DropdownPopup, AttachmentIcon, SharePointIcon } from '@librechat/client';
|
||||||
import useSharePointFileHandling from '~/hooks/Files/useSharePointFileHandling';
|
import {
|
||||||
|
useLocalize,
|
||||||
|
useAgentCapabilities,
|
||||||
|
useGetAgentsConfig,
|
||||||
|
useSharePointFileHandling,
|
||||||
|
} from '~/hooks';
|
||||||
import { SharePointPickerDialog } from '~/components/SharePoint';
|
import { SharePointPickerDialog } from '~/components/SharePoint';
|
||||||
import { useGetStartupConfig } from '~/data-provider';
|
import { useGetStartupConfig } from '~/data-provider';
|
||||||
import { MenuItemProps } from '~/common';
|
import { MenuItemProps } from '~/common';
|
||||||
import { useLocalize } from '~/hooks';
|
|
||||||
|
|
||||||
interface AttachFileButtonProps {
|
interface AttachFileButtonProps {
|
||||||
handleFileChange?: (event: React.ChangeEvent<HTMLInputElement>, toolResource?: string) => void;
|
handleFileChange?: (event: React.ChangeEvent<HTMLInputElement>, toolResource?: string) => void;
|
||||||
|
@ -27,6 +31,8 @@ const AttachFileButton = ({ handleFileChange, disabled }: AttachFileButtonProps)
|
||||||
});
|
});
|
||||||
const { data: startupConfig } = useGetStartupConfig();
|
const { data: startupConfig } = useGetStartupConfig();
|
||||||
const sharePointEnabled = startupConfig?.sharePointFilePickerEnabled;
|
const sharePointEnabled = startupConfig?.sharePointFilePickerEnabled;
|
||||||
|
const { agentsConfig } = useGetAgentsConfig();
|
||||||
|
const capabilities = useAgentCapabilities(agentsConfig?.capabilities ?? defaultAgentCapabilities);
|
||||||
|
|
||||||
const handleUploadClick = useCallback((isImage?: boolean) => {
|
const handleUploadClick = useCallback((isImage?: boolean) => {
|
||||||
if (!inputRef.current) {
|
if (!inputRef.current) {
|
||||||
|
@ -49,31 +55,41 @@ const AttachFileButton = ({ handleFileChange, disabled }: AttachFileButtonProps)
|
||||||
},
|
},
|
||||||
icon: <ImageUpIcon className="icon-md" />,
|
icon: <ImageUpIcon className="icon-md" />,
|
||||||
},
|
},
|
||||||
{
|
];
|
||||||
|
|
||||||
|
if (capabilities.ocrEnabled) {
|
||||||
|
items.push({
|
||||||
label: localize('com_ui_upload_ocr_text'),
|
label: localize('com_ui_upload_ocr_text'),
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
setToolResource(EToolResources.ocr);
|
setToolResource(EToolResources.ocr);
|
||||||
onAction();
|
onAction();
|
||||||
},
|
},
|
||||||
icon: <FileType2Icon className="icon-md" />,
|
icon: <FileType2Icon className="icon-md" />,
|
||||||
},
|
});
|
||||||
{
|
}
|
||||||
|
|
||||||
|
if (capabilities.fileSearchEnabled) {
|
||||||
|
items.push({
|
||||||
label: localize('com_ui_upload_file_search'),
|
label: localize('com_ui_upload_file_search'),
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
setToolResource(EToolResources.file_search);
|
setToolResource(EToolResources.file_search);
|
||||||
onAction();
|
onAction();
|
||||||
},
|
},
|
||||||
icon: <FileSearch className="icon-md" />,
|
icon: <FileSearch className="icon-md" />,
|
||||||
},
|
});
|
||||||
{
|
}
|
||||||
|
|
||||||
|
if (capabilities.codeEnabled) {
|
||||||
|
items.push({
|
||||||
label: localize('com_ui_upload_code_files'),
|
label: localize('com_ui_upload_code_files'),
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
setToolResource(EToolResources.execute_code);
|
setToolResource(EToolResources.execute_code);
|
||||||
onAction();
|
onAction();
|
||||||
},
|
},
|
||||||
icon: <TerminalSquareIcon className="icon-md" />,
|
icon: <TerminalSquareIcon className="icon-md" />,
|
||||||
},
|
});
|
||||||
];
|
}
|
||||||
|
|
||||||
return items;
|
return items;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -93,7 +109,7 @@ const AttachFileButton = ({ handleFileChange, disabled }: AttachFileButtonProps)
|
||||||
}
|
}
|
||||||
|
|
||||||
return localItems;
|
return localItems;
|
||||||
}, [localize, handleUploadClick, sharePointEnabled, setIsSharePointDialogOpen]);
|
}, [capabilities, localize, handleUploadClick, sharePointEnabled, setIsSharePointDialogOpen]);
|
||||||
|
|
||||||
const menuTrigger = (
|
const menuTrigger = (
|
||||||
<Ariakit.MenuButton
|
<Ariakit.MenuButton
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue