| 1 | import { Tooltip } from "react-tooltip"; |
| 2 | import { useAppDispatch, useAppSelector } from "../../redux/hooks"; |
| 3 | import { saveCurrentSession } from "../../redux/thunks/session"; |
| 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 = percent > 80 ? "bg-warning" : "bg-description"; |
| 18 | |
| 19 | return ( |
| 20 | <div> |
| 21 | <Tooltip |
| 22 | id="context-status" |
| 23 | closeEvents={{ |
| 24 | // blur: false, |
| 25 | mouseleave: true, |
| 26 | click: true, |
| 27 | mouseup: false, |
| 28 | }} |
| 29 | clickable |
| 30 | > |
| 31 | <div className="flex flex-col gap-0"> |
| 32 | <span> {`${percent}% of context filled`}</span> |
| 33 | {isPruned && <span>Old messages are being removed</span>} |
| 34 | {history.length > 0 && ( |
| 35 | <span |
| 36 | className="cursor-pointer underline" |
| 37 | onClick={() => { |
| 38 | dispatch( |
| 39 | saveCurrentSession({ |
| 40 | openNewSession: true, |
| 41 | generateTitle: false, |
| 42 | }), |
| 43 | ); |
| 44 | }} |
| 45 | > |
| 46 | New Session |
| 47 | </span> |
| 48 | )} |
| 49 | </div> |
| 50 | </Tooltip> |
| 51 | <div |
| 52 | data-tooltip-id="context-status" |
| 53 | className="border-description-muted relative h-[10px] w-[5px] rounded-[1px] border-[0.5px] border-solid" |
| 54 | > |
| 55 | {/* <div className="absolute bottom-full left-1/4 h-[1px] w-1/2 border-[0.5px] border-solid" /> */} |
| 56 | <div |
| 57 | className={`transition-height absolute bottom-0 left-0 w-full duration-300 ease-in-out ${barColorClass}`} |
| 58 | style={{ height: `${percent}%` }} |
| 59 | ></div> |
| 60 | </div> |
| 61 | </div> |
| 62 | ); |
| 63 | }; |
| 64 | |
| 65 | export default ContextStatus; |