| 1 | import { TrashIcon } from "@heroicons/react/24/outline"; |
| 2 | import { ChevronDownIcon, ChevronUpIcon } from "@heroicons/react/24/solid"; |
| 3 | import { ChatHistoryItem } from "core"; |
| 4 | import { useState } from "react"; |
| 5 | import { useAppSelector } from "../../redux/hooks"; |
| 6 | import { useDeleteCompaction } from "../../util/compactConversation"; |
| 7 | import { AnimatedEllipsis } from "../AnimatedEllipsis"; |
| 8 | import HeaderButtonWithToolTip from "../gui/HeaderButtonWithToolTip"; |
| 9 | import StyledMarkdownPreview from "../StyledMarkdownPreview"; |
| 10 | |
| 11 | interface ConversationSummaryProps { |
| 12 | item: ChatHistoryItem; |
| 13 | index: number; |
| 14 | } |
| 15 | |
| 16 | export default function ConversationSummary(props: ConversationSummaryProps) { |
| 17 | const [open, setOpen] = useState(true); |
| 18 | const isLoading = useAppSelector( |
| 19 | (state) => state.session.compactionLoading[props.index] || false, |
| 20 | ); |
| 21 | const deleteCompaction = useDeleteCompaction(); |
| 22 | |
| 23 | if (!props.item.conversationSummary && !isLoading) { |
| 24 | return null; |
| 25 | } |
| 26 | |
| 27 | // Loading state - much simpler |
| 28 | if (isLoading) { |
| 29 | return ( |
| 30 | <div className="mx-1.5 mb-4 mt-2"> |
| 31 | <div className="bg-vsc-input-background rounded-md shadow-sm"> |
| 32 | <div className="text-description flex items-center justify-start px-3 py-2 text-xs"> |
| 33 | <span>Generating conversation summary</span> |
| 34 | <AnimatedEllipsis /> |
| 35 | </div> |
| 36 | </div> |
| 37 | </div> |
| 38 | ); |
| 39 | } |
| 40 | |
| 41 | // Normal state with content |
| 42 | return ( |
| 43 | <div className="mx-1.5 mb-4 mt-2"> |
| 44 | <div className="bg-vsc-input-background rounded-md shadow-sm"> |
| 45 | <div |
| 46 | className="text-description flex cursor-pointer items-center gap-2 px-3 py-2 text-xs transition-colors duration-200 hover:brightness-105" |
| 47 | onClick={() => setOpen(!open)} |
| 48 | > |
| 49 | {open ? ( |
| 50 | <ChevronUpIcon className="h-3 w-3" /> |
| 51 | ) : ( |
| 52 | <ChevronDownIcon className="h-3 w-3" /> |
| 53 | )} |
| 54 | <span className="flex-1">Conversation Summary</span> |
| 55 | <HeaderButtonWithToolTip |
| 56 | text="Delete summary" |
| 57 | onClick={(e) => { |
| 58 | e.stopPropagation(); |
| 59 | deleteCompaction(props.index); |
| 60 | }} |
| 61 | > |
| 62 | <TrashIcon className="text-description-muted h-3 w-3" /> |
| 63 | </HeaderButtonWithToolTip> |
| 64 | </div> |
| 65 | {open && ( |
| 66 | <> |
| 67 | <div className="border-border border-0 border-t border-solid"></div> |
| 68 | <div className="max-h-[400px] overflow-y-auto px-3 pb-3 pt-2"> |
| 69 | <StyledMarkdownPreview |
| 70 | isRenderingInStepContainer |
| 71 | source={props.item.conversationSummary} |
| 72 | itemIndex={props.index} |
| 73 | useParentBackgroundColor |
| 74 | /> |
| 75 | </div> |
| 76 | </> |
| 77 | )} |
| 78 | </div> |
| 79 | </div> |
| 80 | ); |
| 81 | } |