| 1 | import { |
| 2 | HandThumbDownIcon, |
| 3 | HandThumbUpIcon, |
| 4 | } from "@heroicons/react/24/outline"; |
| 5 | import { ChatHistoryItem } from "core"; |
| 6 | import { useContext, useState } from "react"; |
| 7 | import { IdeMessengerContext } from "../context/IdeMessenger"; |
| 8 | import { useAppSelector } from "../redux/hooks"; |
| 9 | import HeaderButtonWithToolTip from "./gui/HeaderButtonWithToolTip"; |
| 10 | |
| 11 | export interface FeedbackButtonsProps { |
| 12 | item: ChatHistoryItem; |
| 13 | } |
| 14 | |
| 15 | export function FeedbackButtons({ item }: FeedbackButtonsProps) { |
| 16 | const [feedback, setFeedback] = useState<boolean | undefined>(undefined); |
| 17 | const ideMessenger = useContext(IdeMessengerContext); |
| 18 | const sessionId = useAppSelector((store) => store.session.id); |
| 19 | |
| 20 | const sendFeedback = (feedback: boolean) => { |
| 21 | setFeedback(feedback); |
| 22 | if (item.promptLogs?.length) { |
| 23 | for (const promptLog of item.promptLogs) { |
| 24 | const { modelTitle, modelProvider, ...logData } = promptLog; |
| 25 | ideMessenger.post("devdata/log", { |
| 26 | name: "chatFeedback", |
| 27 | data: { |
| 28 | ...logData, |
| 29 | completionOptions: {}, // TODO delete completionOptions from @continuedev/config-yaml |
| 30 | modelProvider: modelProvider || "unknown", |
| 31 | modelName: modelTitle, |
| 32 | modelTitle: modelTitle, |
| 33 | feedback, |
| 34 | sessionId, |
| 35 | }, |
| 36 | }); |
| 37 | } |
| 38 | } |
| 39 | }; |
| 40 | |
| 41 | return ( |
| 42 | <> |
| 43 | <HeaderButtonWithToolTip |
| 44 | text="Helpful" |
| 45 | tabIndex={-1} |
| 46 | onClick={() => sendFeedback(true)} |
| 47 | > |
| 48 | <HandThumbUpIcon |
| 49 | className={`mx-0.5 h-3.5 w-3.5 ${feedback === true ? "text-success" : "text-description-muted"}`} |
| 50 | /> |
| 51 | </HeaderButtonWithToolTip> |
| 52 | <HeaderButtonWithToolTip |
| 53 | text="Unhelpful" |
| 54 | tabIndex={-1} |
| 55 | onClick={() => sendFeedback(false)} |
| 56 | > |
| 57 | <HandThumbDownIcon |
| 58 | className={`h-3.5 w-3.5 ${feedback === false ? "text-error" : "text-description-muted"}`} |
| 59 | /> |
| 60 | </HeaderButtonWithToolTip> |
| 61 | </> |
| 62 | ); |
| 63 | } |