| 1 | import { useAppDispatch, useAppSelector } from "../../redux/hooks"; |
| 2 | import { saveCurrentSession } from "../../redux/thunks/session"; |
| 3 | import { ToolTip } from "../gui/Tooltip"; |
| 4 | |
| 5 | const ContextStatus = () => { |
| 6 | const dispatch = useAppDispatch(); |
| 7 | const contextPercentage = useAppSelector( |
| 8 | (state) => state.session.contextPercentage, |
| 9 | ); |
| 10 | const history = useAppSelector((state) => state.session.history); |
| 11 | const percent = Math.round((contextPercentage ?? 0) * 100); |
| 12 | const isPruned = useAppSelector((state) => state.session.isPruned); |
| 13 | if (!isPruned && percent < 60) { |
| 14 | return null; |
| 15 | } |
| 16 | |
| 17 | const barColorClass = isPruned |
| 18 | ? "bg-error" |
| 19 | : percent > 80 |
| 20 | ? "bg-warning" |
| 21 | : "bg-description"; |
| 22 | |
| 23 | return ( |
| 24 | <div> |
| 25 | <ToolTip |
| 26 | id="context-status" |
| 27 | closeEvents={{ |
| 28 | // blur: false, |
| 29 | mouseleave: true, |
| 30 | click: true, |
| 31 | mouseup: false, |
| 32 | }} |
| 33 | clickable |
| 34 | > |
| 35 | <div className="flex flex-col gap-0"> |
| 36 | <span className="inline-block"> |
| 37 | {`${percent}% of context filled`} |
| 38 | </span> |
| 39 | {isPruned && ( |
| 40 | <span className="inline-block"> |
| 41 | {`Oldest messages are being removed`} |
| 42 | </span> |
| 43 | )} |
| 44 | {history.length > 0 && ( |
| 45 | <div> |
| 46 | <span className="inline-block">Start a</span>{" "} |
| 47 | <span |
| 48 | className="inline-block cursor-pointer underline" |
| 49 | onClick={() => { |
| 50 | void dispatch( |
| 51 | saveCurrentSession({ |
| 52 | openNewSession: true, |
| 53 | generateTitle: false, |
| 54 | }), |
| 55 | ); |
| 56 | }} |
| 57 | > |
| 58 | New Session |
| 59 | </span> |
| 60 | </div> |
| 61 | )} |
| 62 | </div> |
| 63 | </ToolTip> |
| 64 | <div |
| 65 | data-tooltip-id="context-status" |
| 66 | className="border-description-muted relative h-[14px] w-[7px] rounded-[1px] border-[0.5px] border-solid md:h-[10px] md:w-[5px]" |
| 67 | > |
| 68 | <div |
| 69 | className={`transition-height absolute bottom-0 left-0 w-full duration-300 ease-in-out ${barColorClass}`} |
| 70 | style={{ height: `${percent}%` }} |
| 71 | ></div> |
| 72 | </div> |
| 73 | </div> |
| 74 | ); |
| 75 | }; |
| 76 | |
| 77 | export default ContextStatus; |