| 1 | import { |
| 2 | BarsArrowDownIcon, |
| 3 | PlusIcon, |
| 4 | TrashIcon, |
| 5 | } from "@heroicons/react/24/outline"; |
| 6 | import { ChatHistoryItem } from "core"; |
| 7 | import { modelSupportsTools } from "core/llm/autodetect"; |
| 8 | import { renderChatMessage } from "core/util/messageContent"; |
| 9 | import { useMemo } from "react"; |
| 10 | import { useDispatch } from "react-redux"; |
| 11 | import { useAppSelector } from "../../redux/hooks"; |
| 12 | import { selectSelectedChatModel } from "../../redux/slices/configSlice"; |
| 13 | import { setDialogMessage, setShowDialog } from "../../redux/slices/uiSlice"; |
| 14 | import { FeedbackButtons } from "../FeedbackButtons"; |
| 15 | import { GenerateRuleDialog } from "../GenerateRuleDialog"; |
| 16 | import { CopyIconButton } from "../gui/CopyIconButton"; |
| 17 | import HeaderButtonWithToolTip from "../gui/HeaderButtonWithToolTip"; |
| 18 | |
| 19 | export interface ResponseActionsProps { |
| 20 | isTruncated: boolean; |
| 21 | onContinueGeneration: () => void; |
| 22 | index: number; |
| 23 | onDelete: () => void; |
| 24 | item: ChatHistoryItem; |
| 25 | isLast: boolean; |
| 26 | } |
| 27 | |
| 28 | export default function ResponseActions({ |
| 29 | onContinueGeneration, |
| 30 | index, |
| 31 | item, |
| 32 | isTruncated, |
| 33 | onDelete, |
| 34 | isLast, |
| 35 | }: ResponseActionsProps) { |
| 36 | const dispatch = useDispatch(); |
| 37 | const selectedModel = useAppSelector(selectSelectedChatModel); |
| 38 | const ruleGenerationSupported = useMemo(() => { |
| 39 | return selectedModel && modelSupportsTools(selectedModel); |
| 40 | }, [selectedModel]); |
| 41 | |
| 42 | const onGenerateRule = () => { |
| 43 | dispatch(setShowDialog(true)); |
| 44 | dispatch(setDialogMessage(<GenerateRuleDialog />)); |
| 45 | }; |
| 46 | |
| 47 | return ( |
| 48 | <div className="text-description-muted mx-2 flex cursor-default items-center justify-end space-x-1 bg-transparent pb-0 text-xs"> |
| 49 | {isLast && ruleGenerationSupported && ( |
| 50 | <div |
| 51 | className="mr-1 border-y-0 border-l-0 border-r border-solid pr-2" |
| 52 | onClick={onGenerateRule} |
| 53 | > |
| 54 | <span className="flex cursor-pointer items-center hover:brightness-125"> |
| 55 | <PlusIcon className="mr-1 h-3 w-3" /> |
| 56 | <span className="xs:block hidden whitespace-nowrap"> |
| 57 | Generate rule |
| 58 | </span> |
| 59 | <span className="xs:hidden block whitespace-nowrap">Rule</span> |
| 60 | </span> |
| 61 | </div> |
| 62 | )} |
| 63 | |
| 64 | {isTruncated && ( |
| 65 | <HeaderButtonWithToolTip |
| 66 | tabIndex={-1} |
| 67 | text="Continue generation" |
| 68 | onClick={onContinueGeneration} |
| 69 | > |
| 70 | <BarsArrowDownIcon className="text-description-muted h-3.5 w-3.5" /> |
| 71 | </HeaderButtonWithToolTip> |
| 72 | )} |
| 73 | |
| 74 | <HeaderButtonWithToolTip |
| 75 | testId={`delete-button-${index}`} |
| 76 | text="Delete" |
| 77 | tabIndex={-1} |
| 78 | onClick={onDelete} |
| 79 | > |
| 80 | <TrashIcon className="text-description-muted h-3.5 w-3.5" /> |
| 81 | </HeaderButtonWithToolTip> |
| 82 | |
| 83 | <CopyIconButton |
| 84 | tabIndex={-1} |
| 85 | text={renderChatMessage(item.message)} |
| 86 | clipboardIconClassName="h-3.5 w-3.5 text-description-muted" |
| 87 | checkIconClassName="h-3.5 w-3.5 text-success" |
| 88 | /> |
| 89 | |
| 90 | <FeedbackButtons item={item} /> |
| 91 | </div> |
| 92 | ); |
| 93 | } |