'use client' import remarkGfm from 'remark-gfm' import remarkMath from 'remark-math' import Image, { StaticImageData } from 'next/image' import { cn } from '@/lib/utils' import { CodeBlock } from '@/components/ui/codeblock' import { MemoizedReactMarkdown } from '@/components/markdown' import { IconF, IconYou, IconUser, IconW3GPT } from '@/components/ui/icons' import { ChatMessageActions } from '@/components/chat-message-actions' import { useEffect, useState } from 'react' import { Button } from './ui/button' import { number } from 'zod' import { Message } from '@aigxion/isdk' import defaultImage from '@/components/images/jellydrops.png'; // import defaultImage from '@/components/images/jellai.png'; export interface ChatMessageProps { message: Message avatarUrl?: string | null | undefined | StaticImageData } export function ChatMessage({ message, avatarUrl, ...props }: ChatMessageProps) { const [isExpanded, setIsExpanded] = useState(false) const [imageSrc, setImageSrc] = useState(avatarUrl); useEffect(() => { scrollToBottom(); }, [message]); const scrollToBottom = () => { // messageContainerRef.current?.scrollTo({ // top: messageContainerRef.current.scrollHeight, // behavior: "smooth" // }); // console.log(document.documentElement.scrollHeight) // if (!scrollContainer.current) return // scrollContainer.current.scrollTop = document.documentElement.scrollHeight window.scrollTo({ top: document.documentElement.scrollHeight, behavior: 'smooth' }); }; const onExpandClick = () => setIsExpanded(!isExpanded) if (message.function_call && !isExpanded) { return (
) } return (
{message.role === 'assistant' ? ( avatarUrl ? ( {'user { setImageSrc(defaultImage); }} /> ) : ( ) ) : message.function_call ? (
) : ( )}
{children}

}, code({ node, inline, className, children, ...props }) { if (children.length) { if (children[0] == '▍') { return ( ) } children[0] = (children[0] as string).replace('`▍`', '▍') } const match = /language-(\w+)/.exec(className || '') if (inline) { return ( {children} ) } return ( ) } }} > {message.content === '' ? typeof message.function_call === 'string' ? message.function_call : JSON.stringify(message.function_call) : message.content ?? ''}
) }