import { useState, useId } from 'react'; import { PlusCircle } from 'lucide-react'; import * as Menu from '@ariakit/react/menu'; import { useFormContext } from 'react-hook-form'; import { DropdownPopup } from '@librechat/client'; import { specialVariables } from 'librechat-data-provider'; import type { TSpecialVarLabel } from 'librechat-data-provider'; import { useLocalize } from '~/hooks'; interface VariableOption { label: TSpecialVarLabel; value: string; } const variableOptions: VariableOption[] = Object.keys(specialVariables).map((key) => ({ label: `com_ui_special_var_${key}` as TSpecialVarLabel, value: `{{${key}}}`, })); interface VariablesDropdownProps { fieldName?: string; className?: string; } export default function VariablesDropdown({ fieldName = 'prompt', className = '', }: VariablesDropdownProps) { const menuId = useId(); const localize = useLocalize(); const methods = useFormContext(); const { setValue, getValues } = methods; const [isMenuOpen, setIsMenuOpen] = useState(false); const handleAddVariable = (label: TSpecialVarLabel, value: string) => { const currentText = getValues(fieldName) || ''; const spacer = currentText.length > 0 ? '\n\n' : ''; const prefix = localize(label); setValue(fieldName, currentText + spacer + prefix + ': ' + value); setIsMenuOpen(false); }; return (