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