import { ModelIcon } from "@/components/models/model-icon" import { WithTooltip } from "@/components/ui/with-tooltip" import { ChatbotUIContext } from "@/context/context" import { LLM_LIST } from "@/lib/models/llm/llm-list" import { cn } from "@/lib/utils" import { Tables } from "@/supabase/types" import { LLM } from "@/types" import { IconRobotFace } from "@tabler/icons-react" import Image from "next/image" import { useParams, useRouter } from "next/navigation" import { FC, useContext, useRef } from "react" import { DeleteChat } from "./delete-chat" import { UpdateChat } from "./update-chat" interface ChatItemProps { chat: Tables<"chats"> } export const ChatItem: FC = ({ chat }) => { const { selectedWorkspace, selectedChat, availableLocalModels, assistantImages, availableOpenRouterModels } = useContext(ChatbotUIContext) const router = useRouter() const params = useParams() const isActive = params.chatid === chat.id || selectedChat?.id === chat.id const itemRef = useRef(null) const handleClick = () => { if (!selectedWorkspace) return return router.push(`/${selectedWorkspace.id}/chat/${chat.id}`) } const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === "Enter") { e.stopPropagation() itemRef.current?.click() } } const MODEL_DATA = [ ...LLM_LIST, ...availableLocalModels, ...availableOpenRouterModels ].find(llm => llm.modelId === chat.model) as LLM const assistantImage = assistantImages.find( image => image.assistantId === chat.assistant_id )?.base64 return (
{chat.assistant_id ? ( assistantImage ? ( Assistant image ) : ( ) ) : ( {MODEL_DATA?.modelName}
} trigger={ } /> )}
{chat.name}
{ e.stopPropagation() e.preventDefault() }} className={`ml-2 flex space-x-2 ${!isActive && "w-11 opacity-0 group-hover:opacity-100"}`} >
) }