Elffuss BraidHub

kikocis/continue public

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