Changesets · Branches · Tags · Compare
| Changeset | f7ae11f353f9e83d6bd2e387e52fb8e753dbc9bea6f3cea690678458a258d1a1 |
|---|---|
| Author | Dallin Romney <dallinromney@gmail.com> · 2025-07-18 21:01 +02:00 |
| Committer | GitHub <noreply@github.com> · 2025-07-18 21:01 +02:00 |
| Parents | 7668a8715766, 5bd6280cc559 |
5 files changed
modified gui/src/components/StepContainer/ConversationSummary.tsx +14 −1
| @@ -1,9 +1,12 @@ | ||
| 1 | 1 | import { ChevronDownIcon, ChevronUpIcon } from "@heroicons/react/24/solid"; |
| 2 | +import { TrashIcon } from "@heroicons/react/24/outline"; | |
| 2 | 3 | import { ChatHistoryItem } from "core"; |
| 3 | 4 | import { useState } from "react"; |
| 4 | 5 | import { AnimatedEllipsis } from "../"; |
| 5 | 6 | import { useAppSelector } from "../../redux/hooks"; |
| 6 | 7 | import StyledMarkdownPreview from "../StyledMarkdownPreview"; |
| 8 | +import { useDeleteCompaction } from "../../util/compactConversation"; | |
| 9 | +import HeaderButtonWithToolTip from "../gui/HeaderButtonWithToolTip"; | |
| 7 | 10 | |
| 8 | 11 | interface ConversationSummaryProps { |
| 9 | 12 | item: ChatHistoryItem; |
| @@ -15,6 +18,7 @@ | ||
| 15 | 18 | const isLoading = useAppSelector( |
| 16 | 19 | (state) => state.session.compactionLoading[props.index] || false, |
| 17 | 20 | ); |
| 21 | + const deleteCompaction = useDeleteCompaction(); | |
| 18 | 22 | |
| 19 | 23 | if (!props.item.conversationSummary && !isLoading) { |
| 20 | 24 | return null; |
| @@ -47,7 +51,16 @@ | ||
| 47 | 51 | ) : ( |
| 48 | 52 | <ChevronDownIcon className="h-3 w-3" /> |
| 49 | 53 | )} |
| 50 | - <span>Conversation Summary</span> | |
| 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> | |
| 51 | 64 | </div> |
| 52 | 65 | {open && ( |
| 53 | 66 | <> |
modified gui/src/components/StepContainer/ResponseActions.tsx +40 −44
| @@ -7,13 +7,11 @@ | ||
| 7 | 7 | import { ChatHistoryItem } from "core"; |
| 8 | 8 | import { modelSupportsTools } from "core/llm/autodetect"; |
| 9 | 9 | import { renderChatMessage } from "core/util/messageContent"; |
| 10 | -import { useContext, useMemo } from "react"; | |
| 11 | -import { IdeMessengerContext } from "../../context/IdeMessenger"; | |
| 10 | +import { useMemo } from "react"; | |
| 12 | 11 | import { useAppDispatch, useAppSelector } from "../../redux/hooks"; |
| 13 | 12 | import { selectSelectedChatModel } from "../../redux/slices/configSlice"; |
| 14 | -import { setCompactionLoading } from "../../redux/slices/sessionSlice"; | |
| 15 | 13 | import { setDialogMessage, setShowDialog } from "../../redux/slices/uiSlice"; |
| 16 | -import { loadSession } from "../../redux/thunks/session"; | |
| 14 | +import { useCompactConversation } from "../../util/compactConversation"; | |
| 17 | 15 | import { FeedbackButtons } from "../FeedbackButtons"; |
| 18 | 16 | import { GenerateRuleDialog } from "../GenerateRuleDialog"; |
| 19 | 17 | import { CopyIconButton } from "../gui/CopyIconButton"; |
| @@ -37,49 +35,56 @@ | ||
| 37 | 35 | isLast, |
| 38 | 36 | }: ResponseActionsProps) { |
| 39 | 37 | const dispatch = useAppDispatch(); |
| 40 | - const ideMessenger = useContext(IdeMessengerContext); | |
| 41 | - const currentSessionId = useAppSelector((state) => state.session.id); | |
| 42 | 38 | const selectedModel = useAppSelector(selectSelectedChatModel); |
| 39 | + const contextPercentage = useAppSelector( | |
| 40 | + (state) => state.session.contextPercentage, | |
| 41 | + ); | |
| 42 | + const isPruned = useAppSelector((state) => state.session.isPruned); | |
| 43 | 43 | const ruleGenerationSupported = useMemo(() => { |
| 44 | 44 | return selectedModel && modelSupportsTools(selectedModel); |
| 45 | 45 | }, [selectedModel]); |
| 46 | 46 | |
| 47 | + const percent = Math.round((contextPercentage ?? 0) * 100); | |
| 48 | + const buttonColorClass = | |
| 49 | + isLast && (isPruned || percent > 80) | |
| 50 | + ? "text-warning" | |
| 51 | + : "text-description-muted"; | |
| 52 | + | |
| 53 | + const showLabel = isLast && (isPruned || percent >= 60); | |
| 54 | + | |
| 55 | + const compactConversation = useCompactConversation(); | |
| 56 | + | |
| 47 | 57 | const onGenerateRule = () => { |
| 48 | 58 | dispatch(setShowDialog(true)); |
| 49 | 59 | dispatch(setDialogMessage(<GenerateRuleDialog />)); |
| 50 | 60 | }; |
| 51 | 61 | |
| 52 | - const onCompactConversation = async () => { | |
| 53 | - if (!currentSessionId) { | |
| 54 | - return; | |
| 55 | - } | |
| 56 | - | |
| 57 | - try { | |
| 58 | - // Set loading state | |
| 59 | - dispatch(setCompactionLoading({ index, loading: true })); | |
| 60 | - | |
| 61 | - await ideMessenger.request("conversation/compact", { | |
| 62 | - index, | |
| 63 | - sessionId: currentSessionId, | |
| 64 | - }); | |
| 65 | - | |
| 66 | - // Reload the current session to refresh the conversation state | |
| 67 | - dispatch( | |
| 68 | - loadSession({ | |
| 69 | - sessionId: currentSessionId, | |
| 70 | - saveCurrentSession: false, | |
| 71 | - }), | |
| 72 | - ); | |
| 73 | - } catch (error) { | |
| 74 | - console.error("Error compacting conversation:", error); | |
| 75 | - } finally { | |
| 76 | - // Clear loading state | |
| 77 | - dispatch(setCompactionLoading({ index, loading: false })); | |
| 78 | - } | |
| 79 | - }; | |
| 80 | - | |
| 81 | 62 | return ( |
| 82 | 63 | <div className="text-description-muted mx-2 flex cursor-default items-center justify-end space-x-1 bg-transparent pb-0 text-xs"> |
| 64 | + <HeaderButtonWithToolTip | |
| 65 | + testId={`compact-button-${index}`} | |
| 66 | + text={ | |
| 67 | + showLabel | |
| 68 | + ? "Summarize conversation to reduce context length" | |
| 69 | + : "Compact conversation" | |
| 70 | + } | |
| 71 | + tabIndex={-1} | |
| 72 | + onClick={() => compactConversation(index)} | |
| 73 | + > | |
| 74 | + <div className="flex items-center space-x-1"> | |
| 75 | + <ArrowsPointingInIcon | |
| 76 | + className={`h-3.5 w-3.5 ${buttonColorClass || "text-description-muted"}`} | |
| 77 | + /> | |
| 78 | + {showLabel && ( | |
| 79 | + <span | |
| 80 | + className={`text-xs ${buttonColorClass || "text-description-muted"}`} | |
| 81 | + > | |
| 82 | + Compact conversation | |
| 83 | + </span> | |
| 84 | + )} | |
| 85 | + </div> | |
| 86 | + </HeaderButtonWithToolTip> | |
| 87 | + | |
| 83 | 88 | {isLast && ruleGenerationSupported && ( |
| 84 | 89 | <HeaderButtonWithToolTip |
| 85 | 90 | tabIndex={-1} |
| @@ -100,15 +105,6 @@ | ||
| 100 | 105 | </HeaderButtonWithToolTip> |
| 101 | 106 | )} |
| 102 | 107 | |
| 103 | - <HeaderButtonWithToolTip | |
| 104 | - testId={`compact-button-${index}`} | |
| 105 | - text="Compact conversation" | |
| 106 | - tabIndex={-1} | |
| 107 | - onClick={onCompactConversation} | |
| 108 | - > | |
| 109 | - <ArrowsPointingInIcon className="text-description-muted h-3.5 w-3.5" /> | |
| 110 | - </HeaderButtonWithToolTip> | |
| 111 | - | |
| 112 | 108 | <HeaderButtonWithToolTip |
| 113 | 109 | testId={`delete-button-${index}`} |
| 114 | 110 | text="Delete" |
modified gui/src/components/mainInput/ContextStatus.tsx +28 −16
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | import { useAppDispatch, useAppSelector } from "../../redux/hooks"; |
| 2 | 2 | import { saveCurrentSession } from "../../redux/thunks/session"; |
| 3 | +import { useCompactConversation } from "../../util/compactConversation"; | |
| 3 | 4 | import { ToolTip } from "../gui/Tooltip"; |
| 4 | 5 | |
| 5 | 6 | const ContextStatus = () => { |
| @@ -10,6 +11,8 @@ | ||
| 10 | 11 | const history = useAppSelector((state) => state.session.history); |
| 11 | 12 | const percent = Math.round((contextPercentage ?? 0) * 100); |
| 12 | 13 | const isPruned = useAppSelector((state) => state.session.isPruned); |
| 14 | + | |
| 15 | + const compactConversation = useCompactConversation(); | |
| 13 | 16 | if (!isPruned && percent < 60) { |
| 14 | 17 | return null; |
| 15 | 18 | } |
| @@ -32,7 +35,7 @@ | ||
| 32 | 35 | }} |
| 33 | 36 | clickable |
| 34 | 37 | > |
| 35 | - <div className="flex flex-col gap-0"> | |
| 38 | + <div className="flex flex-col gap-0 text-xs"> | |
| 36 | 39 | <span className="inline-block"> |
| 37 | 40 | {`${percent}% of context filled`} |
| 38 | 41 | </span> |
| @@ -42,21 +45,30 @@ | ||
| 42 | 45 | </span> |
| 43 | 46 | )} |
| 44 | 47 | {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> | |
| 48 | + <div className="flex flex-col gap-1 whitespace-pre"> | |
| 49 | + <div> | |
| 50 | + <span | |
| 51 | + className="inline-block cursor-pointer underline" | |
| 52 | + onClick={() => compactConversation(history.length - 1)} | |
| 53 | + > | |
| 54 | + Compact conversation | |
| 55 | + </span> | |
| 56 | + {"\n"} | |
| 57 | + <span className="inline-block">or</span> {"\n"} | |
| 58 | + <span | |
| 59 | + className="inline-block cursor-pointer underline" | |
| 60 | + onClick={() => { | |
| 61 | + dispatch( | |
| 62 | + saveCurrentSession({ | |
| 63 | + openNewSession: true, | |
| 64 | + generateTitle: false, | |
| 65 | + }), | |
| 66 | + ); | |
| 67 | + }} | |
| 68 | + > | |
| 69 | + Start a new session | |
| 70 | + </span> | |
| 71 | + </div> | |
| 60 | 72 | </div> |
| 61 | 73 | )} |
| 62 | 74 | </div> |
modified gui/src/redux/slices/sessionSlice.ts +11 −0
| @@ -445,6 +445,16 @@ | ||
| 445 | 445 | state.isPruned = false; |
| 446 | 446 | state.contextPercentage = undefined; |
| 447 | 447 | }, |
| 448 | + deleteCompaction: (state, action: PayloadAction<number>) => { | |
| 449 | + // Removes the conversation summary from the specified message | |
| 450 | + const historyItem = state.history[action.payload]; | |
| 451 | + if (historyItem?.conversationSummary) { | |
| 452 | + state.history[action.payload] = { | |
| 453 | + ...historyItem, | |
| 454 | + conversationSummary: undefined, | |
| 455 | + }; | |
| 456 | + } | |
| 457 | + }, | |
| 448 | 458 | updateHistoryItemAtIndex: ( |
| 449 | 459 | state, |
| 450 | 460 | { |
| @@ -1000,6 +1010,7 @@ | ||
| 1000 | 1010 | clearDanglingMessages, |
| 1001 | 1011 | setMainEditorContentTrigger, |
| 1002 | 1012 | deleteMessage, |
| 1013 | + deleteCompaction, | |
| 1003 | 1014 | setIsGatheringContext, |
| 1004 | 1015 | resetNextCodeBlockToApplyIndex, |
| 1005 | 1016 | updateApplyState, |
added gui/src/util/compactConversation.ts +58 −0
| @@ -0,0 +1,58 @@ | ||
| 1 | +import { useContext } from "react"; | |
| 2 | +import { IdeMessengerContext } from "../context/IdeMessenger"; | |
| 3 | +import { useAppDispatch, useAppSelector } from "../redux/hooks"; | |
| 4 | +import { | |
| 5 | + setCompactionLoading, | |
| 6 | + deleteCompaction, | |
| 7 | +} from "../redux/slices/sessionSlice"; | |
| 8 | +import { loadSession, saveCurrentSession } from "../redux/thunks/session"; | |
| 9 | + | |
| 10 | +export const useCompactConversation = () => { | |
| 11 | + const dispatch = useAppDispatch(); | |
| 12 | + const ideMessenger = useContext(IdeMessengerContext); | |
| 13 | + const currentSessionId = useAppSelector((state) => state.session.id); | |
| 14 | + | |
| 15 | + return async (index: number) => { | |
| 16 | + if (!currentSessionId) { | |
| 17 | + return; | |
| 18 | + } | |
| 19 | + | |
| 20 | + try { | |
| 21 | + // Set loading state | |
| 22 | + dispatch(setCompactionLoading({ index, loading: true })); | |
| 23 | + | |
| 24 | + await ideMessenger.request("conversation/compact", { | |
| 25 | + index, | |
| 26 | + sessionId: currentSessionId, | |
| 27 | + }); | |
| 28 | + | |
| 29 | + // Reload the current session to refresh the conversation state | |
| 30 | + dispatch( | |
| 31 | + loadSession({ | |
| 32 | + sessionId: currentSessionId, | |
| 33 | + saveCurrentSession: false, | |
| 34 | + }), | |
| 35 | + ); | |
| 36 | + } catch (error) { | |
| 37 | + console.error("Error compacting conversation:", error); | |
| 38 | + } finally { | |
| 39 | + // Clear loading state | |
| 40 | + dispatch(setCompactionLoading({ index, loading: false })); | |
| 41 | + } | |
| 42 | + }; | |
| 43 | +}; | |
| 44 | + | |
| 45 | +export const useDeleteCompaction = () => { | |
| 46 | + const dispatch = useAppDispatch(); | |
| 47 | + | |
| 48 | + return (index: number) => { | |
| 49 | + // Update local state and save to persistence | |
| 50 | + dispatch(deleteCompaction(index)); | |
| 51 | + dispatch( | |
| 52 | + saveCurrentSession({ | |
| 53 | + openNewSession: false, | |
| 54 | + generateTitle: false, | |
| 55 | + }), | |
| 56 | + ); | |
| 57 | + }; | |
| 58 | +}; |