diff --git a/gui/src/components/StepContainer/ConversationSummary.tsx b/gui/src/components/StepContainer/ConversationSummary.tsx
index 78c3043f9..6980ba5f7 100644
--- a/gui/src/components/StepContainer/ConversationSummary.tsx
+++ b/gui/src/components/StepContainer/ConversationSummary.tsx
@@ -1,9 +1,12 @@
import { ChevronDownIcon, ChevronUpIcon } from "@heroicons/react/24/solid";
+import { TrashIcon } from "@heroicons/react/24/outline";
import { ChatHistoryItem } from "core";
import { useState } from "react";
import { AnimatedEllipsis } from "../";
import { useAppSelector } from "../../redux/hooks";
import StyledMarkdownPreview from "../StyledMarkdownPreview";
+import { useDeleteCompaction } from "../../util/compactConversation";
+import HeaderButtonWithToolTip from "../gui/HeaderButtonWithToolTip";
interface ConversationSummaryProps {
item: ChatHistoryItem;
@@ -15,6 +18,7 @@ export default function ConversationSummary(props: ConversationSummaryProps) {
const isLoading = useAppSelector(
(state) => state.session.compactionLoading[props.index] || false,
);
+ const deleteCompaction = useDeleteCompaction();
if (!props.item.conversationSummary && !isLoading) {
return null;
@@ -47,7 +51,16 @@ export default function ConversationSummary(props: ConversationSummaryProps) {
) : (
)}
- Conversation Summary
+ Conversation Summary
+ {
+ e.stopPropagation();
+ deleteCompaction(props.index);
+ }}
+ >
+
+
{open && (
<>
diff --git a/gui/src/components/StepContainer/ResponseActions.tsx b/gui/src/components/StepContainer/ResponseActions.tsx
index 96cb1bab1..068432792 100644
--- a/gui/src/components/StepContainer/ResponseActions.tsx
+++ b/gui/src/components/StepContainer/ResponseActions.tsx
@@ -7,13 +7,11 @@ import {
import { ChatHistoryItem } from "core";
import { modelSupportsTools } from "core/llm/autodetect";
import { renderChatMessage } from "core/util/messageContent";
-import { useContext, useMemo } from "react";
-import { IdeMessengerContext } from "../../context/IdeMessenger";
+import { useMemo } from "react";
import { useAppDispatch, useAppSelector } from "../../redux/hooks";
import { selectSelectedChatModel } from "../../redux/slices/configSlice";
-import { setCompactionLoading } from "../../redux/slices/sessionSlice";
import { setDialogMessage, setShowDialog } from "../../redux/slices/uiSlice";
-import { loadSession } from "../../redux/thunks/session";
+import { useCompactConversation } from "../../util/compactConversation";
import { FeedbackButtons } from "../FeedbackButtons";
import { GenerateRuleDialog } from "../GenerateRuleDialog";
import { CopyIconButton } from "../gui/CopyIconButton";
@@ -37,49 +35,56 @@ export default function ResponseActions({
isLast,
}: ResponseActionsProps) {
const dispatch = useAppDispatch();
- const ideMessenger = useContext(IdeMessengerContext);
- const currentSessionId = useAppSelector((state) => state.session.id);
const selectedModel = useAppSelector(selectSelectedChatModel);
+ const contextPercentage = useAppSelector(
+ (state) => state.session.contextPercentage,
+ );
+ const isPruned = useAppSelector((state) => state.session.isPruned);
const ruleGenerationSupported = useMemo(() => {
return selectedModel && modelSupportsTools(selectedModel);
}, [selectedModel]);
+ const percent = Math.round((contextPercentage ?? 0) * 100);
+ const buttonColorClass =
+ isLast && (isPruned || percent > 80)
+ ? "text-warning"
+ : "text-description-muted";
+
+ const showLabel = isLast && (isPruned || percent >= 60);
+
+ const compactConversation = useCompactConversation();
+
const onGenerateRule = () => {
dispatch(setShowDialog(true));
dispatch(setDialogMessage());
};
- const onCompactConversation = async () => {
- if (!currentSessionId) {
- return;
- }
-
- try {
- // Set loading state
- dispatch(setCompactionLoading({ index, loading: true }));
-
- await ideMessenger.request("conversation/compact", {
- index,
- sessionId: currentSessionId,
- });
-
- // Reload the current session to refresh the conversation state
- dispatch(
- loadSession({
- sessionId: currentSessionId,
- saveCurrentSession: false,
- }),
- );
- } catch (error) {
- console.error("Error compacting conversation:", error);
- } finally {
- // Clear loading state
- dispatch(setCompactionLoading({ index, loading: false }));
- }
- };
-
return (
+
compactConversation(index)}
+ >
+
+
+ {showLabel && (
+
+ Compact conversation
+
+ )}
+
+
+
{isLast && ruleGenerationSupported && (
)}
-
-
-
-
{
@@ -10,6 +11,8 @@ const ContextStatus = () => {
const history = useAppSelector((state) => state.session.history);
const percent = Math.round((contextPercentage ?? 0) * 100);
const isPruned = useAppSelector((state) => state.session.isPruned);
+
+ const compactConversation = useCompactConversation();
if (!isPruned && percent < 60) {
return null;
}
@@ -32,7 +35,7 @@ const ContextStatus = () => {
}}
clickable
>
-
+
{`${percent}% of context filled`}
@@ -42,21 +45,30 @@ const ContextStatus = () => {
)}
{history.length > 0 && (
-
-
Start a{" "}
-
{
- void dispatch(
- saveCurrentSession({
- openNewSession: true,
- generateTitle: false,
- }),
- );
- }}
- >
- New Session
-
+
+
+ compactConversation(history.length - 1)}
+ >
+ Compact conversation
+
+ {"\n"}
+ or {"\n"}
+ {
+ dispatch(
+ saveCurrentSession({
+ openNewSession: true,
+ generateTitle: false,
+ }),
+ );
+ }}
+ >
+ Start a new session
+
+
)}
diff --git a/gui/src/redux/slices/sessionSlice.ts b/gui/src/redux/slices/sessionSlice.ts
index 8ede0e55f..7f13b87fe 100644
--- a/gui/src/redux/slices/sessionSlice.ts
+++ b/gui/src/redux/slices/sessionSlice.ts
@@ -445,6 +445,16 @@ export const sessionSlice = createSlice({
state.isPruned = false;
state.contextPercentage = undefined;
},
+ deleteCompaction: (state, action: PayloadAction
) => {
+ // Removes the conversation summary from the specified message
+ const historyItem = state.history[action.payload];
+ if (historyItem?.conversationSummary) {
+ state.history[action.payload] = {
+ ...historyItem,
+ conversationSummary: undefined,
+ };
+ }
+ },
updateHistoryItemAtIndex: (
state,
{
@@ -1000,6 +1010,7 @@ export const {
clearDanglingMessages,
setMainEditorContentTrigger,
deleteMessage,
+ deleteCompaction,
setIsGatheringContext,
resetNextCodeBlockToApplyIndex,
updateApplyState,
diff --git a/gui/src/util/compactConversation.ts b/gui/src/util/compactConversation.ts
new file mode 100644
index 000000000..cbe57a619
--- /dev/null
+++ b/gui/src/util/compactConversation.ts
@@ -0,0 +1,58 @@
+import { useContext } from "react";
+import { IdeMessengerContext } from "../context/IdeMessenger";
+import { useAppDispatch, useAppSelector } from "../redux/hooks";
+import {
+ setCompactionLoading,
+ deleteCompaction,
+} from "../redux/slices/sessionSlice";
+import { loadSession, saveCurrentSession } from "../redux/thunks/session";
+
+export const useCompactConversation = () => {
+ const dispatch = useAppDispatch();
+ const ideMessenger = useContext(IdeMessengerContext);
+ const currentSessionId = useAppSelector((state) => state.session.id);
+
+ return async (index: number) => {
+ if (!currentSessionId) {
+ return;
+ }
+
+ try {
+ // Set loading state
+ dispatch(setCompactionLoading({ index, loading: true }));
+
+ await ideMessenger.request("conversation/compact", {
+ index,
+ sessionId: currentSessionId,
+ });
+
+ // Reload the current session to refresh the conversation state
+ dispatch(
+ loadSession({
+ sessionId: currentSessionId,
+ saveCurrentSession: false,
+ }),
+ );
+ } catch (error) {
+ console.error("Error compacting conversation:", error);
+ } finally {
+ // Clear loading state
+ dispatch(setCompactionLoading({ index, loading: false }));
+ }
+ };
+};
+
+export const useDeleteCompaction = () => {
+ const dispatch = useAppDispatch();
+
+ return (index: number) => {
+ // Update local state and save to persistence
+ dispatch(deleteCompaction(index));
+ dispatch(
+ saveCurrentSession({
+ openNewSession: false,
+ generateTitle: false,
+ }),
+ );
+ };
+};