import { EngineManager, ErrorCode, MessageStatus, ThreadMessage, } from '@janhq/core' import { Button } from '@janhq/joi' 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 useSendChatMessage from '@/hooks/useSendChatMessage' import { mainViewStateAtom } from '@/helpers/atoms/App.atom' import { getCurrentChatMessagesAtom } from '@/helpers/atoms/ChatMessage.atom' import { selectedSettingAtom } from '@/helpers/atoms/Setting.atom' import { activeThreadAtom } from '@/helpers/atoms/Thread.atom' const ErrorMessage = ({ message }: { message: ThreadMessage }) => { const messages = useAtomValue(getCurrentChatMessagesAtom) const { resendChatMessage } = useSendChatMessage() const setModalTroubleShooting = useSetAtom(modalTroubleShootingAtom) const setMainState = useSetAtom(mainViewStateAtom) const setSelectedSettingScreen = useSetAtom(selectedSettingAtom) const activeThread = useAtomValue(activeThreadAtom) 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: case ErrorCode.InvalidRequestError: return ( Invalid API key. Please check your API key from{' '} {' '} and try again. ) default: return ( <> {message.content[0]?.text?.value && ( )} ) } } return (
{message.status === MessageStatus.Stopped && (
Oops! The generation was interrupted. Let's give it another go!
)} {message.status === MessageStatus.Error && (
{getErrorTitle()}

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

)}
) } export default ErrorMessage