66 lines
2.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { MessageStatus, ThreadMessage } from '@janhq/core'
import { Button } from '@janhq/uikit'
import { useAtomValue, useSetAtom } from 'jotai'
import { RefreshCcw } from 'lucide-react'
import ModalTroubleShooting, {
modalTroubleShootingAtom,
} from '@/containers/ModalTroubleShoot'
import useSendChatMessage from '@/hooks/useSendChatMessage'
import { getCurrentChatMessagesAtom } from '@/helpers/atoms/ChatMessage.atom'
const ErrorMessage = ({ message }: { message: ThreadMessage }) => {
const messages = useAtomValue(getCurrentChatMessagesAtom)
const { resendChatMessage } = useSendChatMessage()
const setModalTroubleShooting = useSetAtom(modalTroubleShootingAtom)
const regenerateMessage = async () => {
const lastMessageIndex = messages.length - 1
const message = messages[lastMessageIndex]
resendChatMessage(message)
}
return (
<>
{message.status === MessageStatus.Stopped && (
<div key={message.id} className="mt-10 flex flex-col items-center">
<span className="mb-3 text-center text-sm font-medium text-gray-500">
Oops! The generation was interrupted. Let&apos;s give it another go!
</span>
<Button
className="w-min"
themes="outline"
onClick={regenerateMessage}
>
<RefreshCcw size={14} className="" />
<span className="w-2" />
Regenerate
</Button>
</div>
)}
{message.status === MessageStatus.Error && (
<div
key={message.id}
className="flex flex-col items-center text-center text-sm font-medium text-gray-500"
>
<p>{`Apologies, somethings amiss!`}</p>
<p>
Jans in beta. Access&nbsp;
<span
className="cursor-pointer text-primary dark:text-blue-400"
onClick={() => setModalTroubleShooting(true)}
>
troubleshooting assistance
</span>
&nbsp;now.
</p>
<ModalTroubleShooting />
</div>
)}
</>
)
}
export default ErrorMessage