feat: delete compaction
This commit is contained in:
parent
5b854675ea
commit
e19400bf5a
8 changed files with 131 additions and 3 deletions
16
core/core.ts
16
core/core.ts
|
|
@ -24,7 +24,7 @@ import { createNewPromptFileV2 } from "./promptFiles/createNewPromptFile";
|
|||
import { callTool } from "./tools/callTool";
|
||||
import { ChatDescriber } from "./util/chatDescriber";
|
||||
import { clipboardCache } from "./util/clipboardCache";
|
||||
import { compactConversation } from "./util/conversationCompaction";
|
||||
import { compactConversation, deleteCompaction } from "./util/conversationCompaction";
|
||||
import { GlobalContext } from "./util/GlobalContext";
|
||||
import historyManager from "./util/history";
|
||||
import { editConfigFile, migrateV1DevDataFiles } from "./util/paths";
|
||||
|
|
@ -572,6 +572,20 @@ export class Core {
|
|||
}
|
||||
});
|
||||
|
||||
on("conversation/deleteCompaction", async (msg) => {
|
||||
try {
|
||||
await deleteCompaction({
|
||||
sessionId: msg.data.sessionId,
|
||||
index: msg.data.index,
|
||||
historyManager,
|
||||
});
|
||||
return undefined;
|
||||
} catch (error) {
|
||||
console.error("Error deleting compaction:", error);
|
||||
return undefined;
|
||||
}
|
||||
});
|
||||
|
||||
// Autocomplete
|
||||
on("autocomplete/complete", async (msg) => {
|
||||
const outcome =
|
||||
|
|
|
|||
|
|
@ -193,6 +193,13 @@ export type ToCoreFromIdeOrWebviewProtocol = {
|
|||
},
|
||||
string | undefined,
|
||||
];
|
||||
"conversation/deleteCompaction": [
|
||||
{
|
||||
index: number;
|
||||
sessionId: string;
|
||||
},
|
||||
void,
|
||||
];
|
||||
"stats/getTokensPerDay": [
|
||||
undefined,
|
||||
{ day: string; promptTokens: number; generatedTokens: number }[],
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ export const WEBVIEW_TO_CORE_PASS_THROUGH: (keyof ToCoreFromWebviewProtocol)[] =
|
|||
"streamDiffLines",
|
||||
"chatDescriber/describe",
|
||||
"conversation/compact",
|
||||
"conversation/deleteCompaction",
|
||||
"stats/getTokensPerDay",
|
||||
"stats/getTokensPerModel",
|
||||
// Codebase
|
||||
|
|
|
|||
|
|
@ -9,6 +9,12 @@ export interface CompactionParams {
|
|||
currentModel: ILLM;
|
||||
}
|
||||
|
||||
export interface DeleteCompactionParams {
|
||||
sessionId: string;
|
||||
index: number;
|
||||
historyManager: HistoryManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compacts conversation history up to a specified index by generating a summary.
|
||||
* This helper function extracts the compaction logic from the main core handler.
|
||||
|
|
@ -87,3 +93,38 @@ export async function compactConversation({
|
|||
|
||||
historyManager.save(updatedSession);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a conversation summary from a specific message in the history.
|
||||
* This function removes the conversationSummary property from the specified message.
|
||||
*
|
||||
* @param params - Object containing sessionId, index, and historyManager
|
||||
* @returns Promise<void> - Updates the session with the conversation summary removed
|
||||
*/
|
||||
export async function deleteCompaction({
|
||||
sessionId,
|
||||
index,
|
||||
historyManager,
|
||||
}: DeleteCompactionParams): Promise<void> {
|
||||
// Get the current session
|
||||
const session = historyManager.load(sessionId);
|
||||
|
||||
// Create a copy of the history
|
||||
const updatedHistory = [...session.history];
|
||||
|
||||
// Remove the conversation summary from the specified message
|
||||
if (updatedHistory[index]?.conversationSummary) {
|
||||
updatedHistory[index] = {
|
||||
...updatedHistory[index],
|
||||
conversationSummary: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
// Update the session with the modified history
|
||||
const updatedSession = {
|
||||
...session,
|
||||
history: updatedHistory,
|
||||
};
|
||||
|
||||
historyManager.save(updatedSession);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -114,6 +114,7 @@ class MessageTypes {
|
|||
"streamDiffLines",
|
||||
"chatDescriber/describe",
|
||||
"conversation/compact",
|
||||
"conversation/deleteCompaction",
|
||||
"stats/getTokensPerDay",
|
||||
"stats/getTokensPerModel",
|
||||
// Codebase
|
||||
|
|
|
|||
|
|
@ -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) {
|
|||
) : (
|
||||
<ChevronDownIcon className="h-3 w-3" />
|
||||
)}
|
||||
<span>Conversation Summary</span>
|
||||
<span className="flex-1">Conversation Summary</span>
|
||||
<HeaderButtonWithToolTip
|
||||
text="Delete summary"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
deleteCompaction(props.index);
|
||||
}}
|
||||
>
|
||||
<TrashIcon className="h-3 w-3 text-description-muted" />
|
||||
</HeaderButtonWithToolTip>
|
||||
</div>
|
||||
{open && (
|
||||
<>
|
||||
|
|
|
|||
|
|
@ -437,6 +437,16 @@ export const sessionSlice = createSlice({
|
|||
state.isPruned = false;
|
||||
state.contextPercentage = undefined;
|
||||
},
|
||||
deleteCompaction: (state, action: PayloadAction<number>) => {
|
||||
// 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,
|
||||
{
|
||||
|
|
@ -992,6 +1002,7 @@ export const {
|
|||
clearDanglingMessages,
|
||||
setMainEditorContentTrigger,
|
||||
deleteMessage,
|
||||
deleteCompaction,
|
||||
setIsGatheringContext,
|
||||
resetNextCodeBlockToApplyIndex,
|
||||
updateApplyState,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { useContext } from "react";
|
||||
import { IdeMessengerContext } from "../context/IdeMessenger";
|
||||
import { useAppDispatch, useAppSelector } from "../redux/hooks";
|
||||
import { setCompactionLoading } from "../redux/slices/sessionSlice";
|
||||
import { setCompactionLoading, deleteCompaction } from "../redux/slices/sessionSlice";
|
||||
import { loadSession } from "../redux/thunks/session";
|
||||
|
||||
export const useCompactConversation = () => {
|
||||
|
|
@ -37,4 +37,44 @@ export const useCompactConversation = () => {
|
|||
dispatch(setCompactionLoading({ index, loading: false }));
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export const useDeleteCompaction = () => {
|
||||
const dispatch = useAppDispatch();
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const currentSessionId = useAppSelector((state) => state.session.id);
|
||||
|
||||
return async (index: number) => {
|
||||
if (!currentSessionId) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// Update local state immediately
|
||||
dispatch(deleteCompaction(index));
|
||||
|
||||
// Communicate with core to persist the change
|
||||
await ideMessenger.request("conversation/deleteCompaction", {
|
||||
index,
|
||||
sessionId: currentSessionId,
|
||||
});
|
||||
|
||||
// Reload the current session to refresh the conversation state
|
||||
dispatch(
|
||||
loadSession({
|
||||
sessionId: currentSessionId,
|
||||
saveCurrentSession: false,
|
||||
}),
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("Error deleting compaction:", error);
|
||||
// Optionally reload session to revert optimistic update
|
||||
dispatch(
|
||||
loadSession({
|
||||
sessionId: currentSessionId,
|
||||
saveCurrentSession: false,
|
||||
}),
|
||||
);
|
||||
}
|
||||
};
|
||||
};
|
||||
Loading…
Add table
Reference in a new issue