import { useState } from 'react'; import { KeyRoundIcon } from 'lucide-react'; import { AuthType, AgentCapabilities } from 'librechat-data-provider'; import { useFormContext, Controller, useForm, useWatch } from 'react-hook-form'; import type { AgentForm } from '~/common'; import { Input, OGDialog, Checkbox, HoverCard, HoverCardContent, HoverCardPortal, HoverCardTrigger, Button, } from '~/components/ui'; import OGDialogTemplate from '~/components/ui/OGDialogTemplate'; import { useLocalize, useAuthCodeTool } from '~/hooks'; import { CircleHelpIcon } from '~/components/svg'; import { ESide } from '~/common'; type ApiKeyFormData = { apiKey: string; authType?: string | AuthType; }; export default function Action({ authType = '', isToolAuthenticated = false }) { const localize = useLocalize(); const methods = useFormContext(); const { control, setValue, getValues } = methods; const [isDialogOpen, setIsDialogOpen] = useState(false); const runCodeIsEnabled = useWatch({ control, name: AgentCapabilities.execute_code }); const { installTool, removeTool } = useAuthCodeTool({ isEntityTool: true }); const { reset, register, handleSubmit } = useForm(); const isUserProvided = authType === AuthType.USER_PROVIDED; const handleCheckboxChange = (checked: boolean) => { if (isToolAuthenticated) { setValue(AgentCapabilities.execute_code, checked, { shouldDirty: true }); } else if (runCodeIsEnabled) { setValue(AgentCapabilities.execute_code, false, { shouldDirty: true }); } else { setIsDialogOpen(true); } }; const onSubmit = (data: { apiKey: string }) => { reset(); installTool(data.apiKey); setIsDialogOpen(false); }; const handleRevokeApiKey = () => { reset(); removeTool(); setIsDialogOpen(false); }; return ( <>
( )} />
{isUserProvided && (isToolAuthenticated || runCodeIsEnabled) && ( )}

{/* // TODO: add a Code Interpreter description */}

(e.target.readOnly = false)} {...register('apiKey', { required: true })} /> } selection={{ selectHandler: handleSubmit(onSubmit), selectClasses: 'bg-green-500 hover:bg-green-600 text-white', selectText: localize('com_ui_save'), }} buttons={ isUserProvided && isToolAuthenticated && ( ) } showCancelButton={true} /> ); }