import { KeyRoundIcon } from 'lucide-react'; import { AuthType, AgentCapabilities } from 'librechat-data-provider'; import { useFormContext, Controller, useWatch } from 'react-hook-form'; import type { AgentForm } from '~/common'; import { Checkbox, HoverCard, HoverCardContent, HoverCardPortal, HoverCardTrigger, } from '~/components/ui'; import { useLocalize, useSearchApiKeyForm } from '~/hooks'; import { CircleHelpIcon } from '~/components/svg'; import ApiKeyDialog from './ApiKeyDialog'; import { ESide } from '~/common'; export default function Action({ authTypes = [], isToolAuthenticated = false, }: { authTypes?: [string, AuthType][]; isToolAuthenticated?: boolean; }) { const localize = useLocalize(); const methods = useFormContext(); const { control, setValue, getValues } = methods; const { onSubmit, isDialogOpen, setIsDialogOpen, handleRevokeApiKey, methods: keyFormMethods, } = useSearchApiKeyForm({ onSubmit: () => { setValue(AgentCapabilities.web_search, true, { shouldDirty: true }); }, onRevoke: () => { setValue(AgentCapabilities.web_search, false, { shouldDirty: true }); }, }); const webSearchIsEnabled = useWatch({ control, name: AgentCapabilities.web_search }); const isUserProvided = authTypes?.some(([, authType]) => authType === AuthType.USER_PROVIDED); const handleCheckboxChange = (checked: boolean) => { if (isToolAuthenticated) { setValue(AgentCapabilities.web_search, checked, { shouldDirty: true }); } else if (webSearchIsEnabled) { setValue(AgentCapabilities.web_search, false, { shouldDirty: true }); } else { setIsDialogOpen(true); } }; return ( <>
( )} />
{isUserProvided && (isToolAuthenticated || webSearchIsEnabled) && ( )}

{localize('com_agents_search_info')}

); }