import { XIcon, SendHorizontal, RefreshCcw, Pencil, Copy, CopyCheck, ChevronLeft, ChevronRight, } from "lucide-react"; import { TooltipIconButton } from "../tooltip-icon-button"; import { AnimatePresence, motion } from "framer-motion"; import { useState } from "react"; import { Button } from "@/components/ui/button"; function ContentCopyable({ content, disabled, }: { content: string; disabled: boolean; }) { const [copied, setCopied] = useState(false); const handleCopy = (e: React.MouseEvent) => { e.stopPropagation(); navigator.clipboard.writeText(content); setCopied(true); setTimeout(() => setCopied(false), 2000); }; return ( handleCopy(e)} variant="ghost" tooltip="Copy content" disabled={disabled} > {copied ? ( ) : ( )} ); } export function BranchSwitcher({ branch, branchOptions, onSelect, isLoading, }: { branch: string | undefined; branchOptions: string[] | undefined; onSelect: (branch: string) => void; isLoading: boolean; }) { if (!branchOptions || !branch) return null; const index = branchOptions.indexOf(branch); return (
{index + 1} / {branchOptions.length}
); } export function CommandBar({ content, isHumanMessage, isAiMessage, isEditing, setIsEditing, handleSubmitEdit, handleRegenerate, isLoading, }: { content: string; isHumanMessage?: boolean; isAiMessage?: boolean; isEditing?: boolean; setIsEditing?: React.Dispatch>; handleSubmitEdit?: () => void; handleRegenerate?: () => void; isLoading: boolean; }) { if (isHumanMessage && isAiMessage) { throw new Error( "Can only set one of isHumanMessage or isAiMessage to true, not both.", ); } if (!isHumanMessage && !isAiMessage) { throw new Error( "One of isHumanMessage or isAiMessage must be set to true.", ); } if ( isHumanMessage && (isEditing === undefined || setIsEditing === undefined || handleSubmitEdit === undefined) ) { throw new Error( "If isHumanMessage is true, all of isEditing, setIsEditing, and handleSubmitEdit must be set.", ); } const showEdit = isHumanMessage && isEditing !== undefined && !!setIsEditing && !!handleSubmitEdit; if (isHumanMessage && isEditing && !!setIsEditing && !!handleSubmitEdit) { return (
{ setIsEditing(false); }} >
); } return (
{isAiMessage && !!handleRegenerate && ( )} {showEdit && ( { setIsEditing?.(true); }} > )}
); }