import { useState } from 'react'; import { Settings } from 'lucide-react'; import { useRecoilValue } from 'recoil'; import { EModelEndpoint } from 'librechat-data-provider'; import { useGetEndpointsQuery } from 'librechat-data-provider/react-query'; import type { FC } from 'react'; import type { TPreset } from 'librechat-data-provider'; import { useLocalize, useUserKey, useDefaultConvo } from '~/hooks'; import { SetKeyDialog } from '~/components/Input/SetKeyDialog'; import { cn, getEndpointField } from '~/utils'; import { useChatContext } from '~/Providers'; import { icons } from './Icons'; import store from '~/store'; type MenuItemProps = { title: string; value: EModelEndpoint; selected: boolean; description?: string; userProvidesKey: boolean; // iconPath: string; // hoverContent?: string; }; const MenuItem: FC = ({ title, value: endpoint, description, selected, userProvidesKey, ...rest }) => { const modularChat = useRecoilValue(store.modularChat); const [isDialogOpen, setDialogOpen] = useState(false); const { data: endpointsConfig } = useGetEndpointsQuery(); const { conversation, newConversation } = useChatContext(); const getDefaultConversation = useDefaultConvo(); const { getExpiry } = useUserKey(endpoint); const localize = useLocalize(); const expiryTime = getExpiry(); const onSelectEndpoint = (newEndpoint: EModelEndpoint) => { if (!newEndpoint) { return; } else { if (!expiryTime) { setDialogOpen(true); } const template: Partial = { endpoint: newEndpoint, conversationId: 'new' }; const { conversationId } = conversation ?? {}; if (modularChat && conversationId && conversationId !== 'new') { template.endpointType = getEndpointField(endpointsConfig, newEndpoint, 'type'); const currentConvo = getDefaultConversation({ /* target endpointType is necessary to avoid endpoint mixing */ conversation: { ...(conversation ?? {}), endpointType: template.endpointType }, preset: template, }); /* We don't reset the latest message, only when changing settings mid-converstion */ newConversation({ template: currentConvo, keepLatestMessage: true }); return; } newConversation({ template }); } }; const endpointType = getEndpointField(endpointsConfig, endpoint, 'type'); const iconKey = endpointType ? 'unknown' : endpoint ?? 'unknown'; const Icon = icons[iconKey]; return ( <>
onSelectEndpoint(endpoint)} >
{ }
{title}
{description}
{userProvidesKey ? (
) : null} {selected && ( )} {(!userProvidesKey || expiryTime) && (
{!userProvidesKey &&
{localize('com_ui_new_chat')}
}
)}
{userProvidesKey && ( )} ); }; export default MenuItem;