import React, { useState } from 'react'; import { useFormContext } from 'react-hook-form'; import type { TPlugin } from 'librechat-data-provider'; import { useUpdateUserPluginsMutation } from 'librechat-data-provider/react-query'; import { OGDialog, OGDialogTrigger, Label } from '~/components/ui'; import OGDialogTemplate from '~/components/ui/OGDialogTemplate'; import { useToastContext } from '~/Providers'; import { TrashIcon } from '~/components/svg'; import { useLocalize } from '~/hooks'; import { cn } from '~/utils'; export default function AssistantTool({ tool, allTools, assistant_id = '', }: { tool: string; allTools: TPlugin[]; assistant_id?: string; }) { const [isHovering, setIsHovering] = useState(false); const localize = useLocalize(); const { showToast } = useToastContext(); const updateUserPlugins = useUpdateUserPluginsMutation(); const { getValues, setValue } = useFormContext(); const currentTool = allTools.find((t) => t.pluginKey === tool); const removeTool = (tool: string) => { if (tool) { updateUserPlugins.mutate( { pluginKey: tool, action: 'uninstall', auth: null, isEntityTool: true }, { onError: (error: unknown) => { showToast({ message: `Error while deleting the tool: ${error}`, status: 'error' }); }, onSuccess: () => { const fns = getValues('functions').filter((fn) => fn !== tool); setValue('functions', fns); showToast({ message: 'Tool deleted successfully', status: 'success' }); }, }, ); } }; if (!currentTool) { return null; } return (
setIsHovering(true)} onMouseLeave={() => setIsHovering(false)} >
{currentTool.icon && (
)}
{currentTool.name}
{isHovering && ( )}
{localize('com_ui_delete_tool_confirm')} } selection={{ selectHandler: () => removeTool(currentTool.pluginKey), selectClasses: 'bg-red-700 dark:bg-red-600 hover:bg-red-800 dark:hover:bg-red-800 transition-colors duration-200 text-white', selectText: localize('com_ui_delete'), }} /> ); }