import { IconBrain, IconCheck, IconChevronDown, IconCopy, } from "@tabler/icons-react" import { useAtom } from "jotai" import { useState } from "react" import { useTranslation } from "react-i18next" import ReactMarkdown from "react-markdown" import rehypeHighlight from "rehype-highlight" import rehypeRaw from "rehype-raw" import rehypeSanitize from "rehype-sanitize" import remarkGfm from "remark-gfm" import { Button } from "@/components/ui/button" import { formatMessageTime } from "@/hooks/use-pico-chat" import { cn } from "@/lib/utils" import { showThoughtsAtom } from "@/store/chat" interface AssistantMessageProps { content: string isThought?: boolean timestamp?: string | number } export function AssistantMessage({ content, isThought = false, timestamp = "", }: AssistantMessageProps) { const { t } = useTranslation() const [isCopied, setIsCopied] = useState(false) const [isExpanded, setIsExpanded] = useAtom(showThoughtsAtom) const formattedTimestamp = timestamp !== "" ? formatMessageTime(timestamp) : "" const handleCopy = () => { navigator.clipboard.writeText(content).then(() => { setIsCopied(true) setTimeout(() => setIsCopied(false), 2000) }) } return (
{!isThought && (
PicoClaw {formattedTimestamp && ( <> {formattedTimestamp} )}
)}
{isThought && (
setIsExpanded(!isExpanded)} >
{t("chat.reasoningLabel")}
)} {(!isThought || isExpanded) && (
{content}
)} {!isThought && ( )}
) }