import { SquareSlash } from 'lucide-react'; import { Constants } from 'librechat-data-provider'; import { useState, useEffect } from 'react'; import { useLocalize } from '~/hooks'; const Command = ({ initialValue, onValueChange, disabled, tabIndex, }: { initialValue?: string; onValueChange?: (value: string) => void; disabled?: boolean; tabIndex?: number; }) => { const localize = useLocalize(); const [command, setCommand] = useState(initialValue || ''); const [charCount, setCharCount] = useState(initialValue?.length || 0); useEffect(() => { setCommand(initialValue || ''); setCharCount(initialValue?.length || 0); }, [initialValue]); useEffect(() => { setCharCount(command.length); }, [command]); const handleInputChange: React.ChangeEventHandler = (e) => { let newValue = e.target.value.toLowerCase(); newValue = newValue.replace(/\s/g, '-').replace(/[^a-z0-9-]/g, ''); if (newValue.length <= Constants.COMMANDS_MAX_LENGTH) { setCommand(newValue); onValueChange?.(newValue); } }; if (disabled === true && !command) { return null; } return (

{disabled !== true && ( {`${charCount}/${Constants.COMMANDS_MAX_LENGTH}`} )}

); }; export default Command;