import { ErrorCode, MessageStatus, ThreadMessage } from '@janhq/core' import { Button } from '@janhq/uikit' import { useAtomValue, useSetAtom } from 'jotai' import { RefreshCcw } from 'lucide-react' import AutoLink from '@/containers/AutoLink' import ModalTroubleShooting, { modalTroubleShootingAtom, } from '@/containers/ModalTroubleShoot' import { MainViewState } from '@/constants/screens' import { loadModelErrorAtom } from '@/hooks/useActiveModel' import useSendChatMessage from '@/hooks/useSendChatMessage' import { mainViewStateAtom } from '@/helpers/atoms/App.atom' import { getCurrentChatMessagesAtom } from '@/helpers/atoms/ChatMessage.atom' const ErrorMessage = ({ message }: { message: ThreadMessage }) => { const messages = useAtomValue(getCurrentChatMessagesAtom) const { resendChatMessage } = useSendChatMessage() const setModalTroubleShooting = useSetAtom(modalTroubleShootingAtom) const loadModelError = useAtomValue(loadModelErrorAtom) const setMainState = useSetAtom(mainViewStateAtom) const PORT_NOT_AVAILABLE = 'PORT_NOT_AVAILABLE' const regenerateMessage = async () => { const lastMessageIndex = messages.length - 1 const message = messages[lastMessageIndex] resendChatMessage(message) } const getErrorTitle = () => { switch (message.error_code) { case ErrorCode.Unknown: return 'Apologies, something’s amiss!' case ErrorCode.InvalidApiKey: return ( Invalid API key. Please check your API key from{' '} {' '} and try again. ) default: return } } return (
{message.status === MessageStatus.Stopped && (
Oops! The generation was interrupted. Let's give it another go!
)} {message.status === MessageStatus.Error && ( <> {loadModelError === PORT_NOT_AVAILABLE ? (

Port 3928 is currently unavailable. Check for conflicting apps, or access  setModalTroubleShooting(true)} > troubleshooting assistance  for further support.

) : loadModelError && loadModelError?.includes('EXTENSION_IS_NOT_INSTALLED') ? (

Model is currently unavailable. Please switch to a different model or install the{' '} {' '} to continue using it.

) : (
{getErrorTitle()}

Jan’s in beta. Access  setModalTroubleShooting(true)} > troubleshooting assistance  now.

)} )}
) } export default ErrorMessage