Elffuss BraidHub

kikocis/continue public

bd477015e5d4 · 2.7 KiBRawPermalink
1import {
2 BarsArrowDownIcon,
3 PencilSquareIcon,
4 TrashIcon,
5} from "@heroicons/react/24/outline";
6import { ChatHistoryItem } from "core";
7import { modelSupportsTools } from "core/llm/autodetect";
8import { renderChatMessage } from "core/util/messageContent";
9import { useMemo } from "react";
10import { useDispatch } from "react-redux";
11import { useAppSelector } from "../../redux/hooks";
12import { selectSelectedChatModel } from "../../redux/slices/configSlice";
13import { setDialogMessage, setShowDialog } from "../../redux/slices/uiSlice";
14import { FeedbackButtons } from "../FeedbackButtons";
15import { GenerateRuleDialog } from "../GenerateRuleDialog";
16import { CopyIconButton } from "../gui/CopyIconButton";
17import HeaderButtonWithToolTip from "../gui/HeaderButtonWithToolTip";
18
19export interface ResponseActionsProps {
20 isTruncated: boolean;
21 onContinueGeneration: () => void;
22 index: number;
23 onDelete: () => void;
24 item: ChatHistoryItem;
25 isLast: boolean;
26}
27
28export 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 <HeaderButtonWithToolTip
51 tabIndex={-1}
52 text="Generate rule"
53 onClick={onGenerateRule}
54 >
55 <PencilSquareIcon className="text-description-muted h-3.5 w-3.5" />
56 </HeaderButtonWithToolTip>
57 )}
58
59 {isTruncated && (
60 <HeaderButtonWithToolTip
61 tabIndex={-1}
62 text="Continue generation"
63 onClick={onContinueGeneration}
64 >
65 <BarsArrowDownIcon className="text-description-muted h-3.5 w-3.5" />
66 </HeaderButtonWithToolTip>
67 )}
68
69 <HeaderButtonWithToolTip
70 testId={`delete-button-${index}`}
71 text="Delete"
72 tabIndex={-1}
73 onClick={onDelete}
74 >
75 <TrashIcon className="text-description-muted h-3.5 w-3.5" />
76 </HeaderButtonWithToolTip>
77
78 <CopyIconButton
79 tabIndex={-1}
80 text={renderChatMessage(item.message)}
81 clipboardIconClassName="h-3.5 w-3.5 text-description-muted"
82 checkIconClassName="h-3.5 w-3.5 text-success"
83 />
84
85 <FeedbackButtons item={item} />
86 </div>
87 );
88}