import { EModelEndpoint } from 'librechat-data-provider'; import type { ReactNode } from 'react'; import { MessagesSquared, GPTIcon } from '~/components/svg'; import { useChatContext } from '~/Providers'; import { Button } from '~/components/ui'; import { useLocalize } from '~/hooks'; import { cn } from '~/utils/'; type TPopoverButton = { label: string; buttonClass: string; handler: () => void; icon: ReactNode; }; export default function PopoverButtons({ buttonClass, iconClass = '', }: { buttonClass?: string; iconClass?: string; }) { const { conversation, optionSettings, setOptionSettings, showAgentSettings, setShowAgentSettings, } = useChatContext(); const localize = useLocalize(); const { model, endpoint: _endpoint, endpointType } = conversation ?? {}; const endpoint = endpointType ?? _endpoint; const isGenerativeModel = model?.toLowerCase()?.includes('gemini'); const isChatModel = !isGenerativeModel && model?.toLowerCase()?.includes('chat'); const isTextModel = !isGenerativeModel && !isChatModel && /code|text/.test(model ?? ''); const { showExamples } = optionSettings; const showExamplesButton = !isGenerativeModel && !isTextModel && isChatModel; const triggerExamples = () => setOptionSettings((prev) => ({ ...prev, showExamples: !prev.showExamples })); const buttons: { [key: string]: TPopoverButton[] } = { [EModelEndpoint.google]: [ { label: localize(showExamples ? 'com_hide_examples' : 'com_show_examples'), buttonClass: isGenerativeModel || isTextModel ? 'disabled' : '', handler: triggerExamples, icon: , }, ], [EModelEndpoint.gptPlugins]: [ { label: localize( showAgentSettings ? 'com_show_completion_settings' : 'com_show_agent_settings', ), buttonClass: '', handler: () => setShowAgentSettings((prev) => !prev), icon: , }, ], }; const endpointButtons = buttons[endpoint ?? '']; if (!endpointButtons) { return null; } if (endpoint === EModelEndpoint.google && !showExamplesButton) { return null; } return (
{endpointButtons.map((button, index) => ( ))}
); }