Merge pull request #6382 from continuedev/dallin/tool-truncation-message
Add icon to truncate history at last tool call
This commit is contained in:
commit
1951259e53
8 changed files with 111 additions and 38 deletions
|
|
@ -18,6 +18,7 @@ import {
|
|||
PlusIcon,
|
||||
SparklesIcon,
|
||||
TrashIcon,
|
||||
WrenchScrewdriverIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { DiscordIcon } from "../svg/DiscordIcon";
|
||||
import { GithubIcon } from "../svg/GithubIcon";
|
||||
|
|
@ -55,4 +56,5 @@ export const NAMED_ICONS: { [key: string]: any } = {
|
|||
"gitlab-mr": GitlabIcon,
|
||||
http: GlobeAltIcon,
|
||||
trash: TrashIcon,
|
||||
toolCall: WrenchScrewdriverIcon,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -330,7 +330,6 @@ export function Chat() {
|
|||
key={i}
|
||||
toolCallState={item.toolCallState!}
|
||||
toolCall={toolCall}
|
||||
output={history[index + 1]?.contextItems}
|
||||
historyIndex={index}
|
||||
/>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { ChevronRightIcon } from "@heroicons/react/24/outline";
|
||||
import { ContextItemWithId, Tool, ToolCallState } from "core";
|
||||
import { Tool, ToolCallState } from "core";
|
||||
import { ComponentType, useContext, useMemo, useState } from "react";
|
||||
import {
|
||||
ContextItemsPeekItem,
|
||||
|
|
@ -7,26 +7,28 @@ import {
|
|||
} from "../../../components/mainInput/belowMainInput/ContextItemsPeek";
|
||||
import { IdeMessengerContext } from "../../../context/IdeMessenger";
|
||||
import { ArgsItems, ArgsToggleIcon } from "./ToolCallArgs";
|
||||
import { toolCallStateToContextItems } from "./toolCallStateToContextItem";
|
||||
import { ToolCallStatusMessage } from "./ToolCallStatusMessage";
|
||||
import { ToolTruncateHistoryIcon } from "./ToolTruncateHistoryIcon";
|
||||
|
||||
interface SimpleToolCallUIProps {
|
||||
toolCallState: ToolCallState;
|
||||
tool: Tool | undefined;
|
||||
contextItems: ContextItemWithId[];
|
||||
icon?: ComponentType<React.SVGProps<SVGSVGElement>>;
|
||||
historyIndex: number;
|
||||
}
|
||||
|
||||
export function SimpleToolCallUI({
|
||||
contextItems,
|
||||
icon: Icon,
|
||||
toolCallState,
|
||||
tool,
|
||||
historyIndex,
|
||||
}: SimpleToolCallUIProps) {
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
|
||||
const ctxItems = useMemo(() => {
|
||||
return contextItems?.filter((ctxItem) => !ctxItem.hidden) ?? [];
|
||||
}, [contextItems]);
|
||||
const shownContextItems = useMemo(() => {
|
||||
const contextItems = toolCallStateToContextItems(toolCallState);
|
||||
return contextItems.filter((item) => !item.hidden);
|
||||
}, [toolCallState]);
|
||||
|
||||
const [open, setOpen] = useState(false);
|
||||
const [isHovered, setIsHovered] = useState(false);
|
||||
|
|
@ -36,8 +38,8 @@ export function SimpleToolCallUI({
|
|||
return Object.entries(toolCallState.parsedArgs);
|
||||
}, [toolCallState.parsedArgs]);
|
||||
|
||||
const isToggleable = ctxItems.length > 1;
|
||||
const isSingleItem = ctxItems.length === 1;
|
||||
const isToggleable = shownContextItems.length > 1;
|
||||
const isSingleItem = shownContextItems.length === 1;
|
||||
const shouldShowContent = isToggleable ? open : false;
|
||||
const isClickable = isToggleable || isSingleItem;
|
||||
|
||||
|
|
@ -45,7 +47,7 @@ export function SimpleToolCallUI({
|
|||
if (isToggleable) {
|
||||
setOpen((prev) => !prev);
|
||||
} else if (isSingleItem) {
|
||||
openContextItem(ctxItems[0], ideMessenger);
|
||||
openContextItem(shownContextItems[0], ideMessenger);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -71,7 +73,7 @@ export function SimpleToolCallUI({
|
|||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col pl-5 pr-2 pt-4">
|
||||
<div className="flex flex-col py-4 pl-5 pr-2">
|
||||
<div className="flex min-w-0 flex-row items-center justify-between gap-2">
|
||||
<div
|
||||
className={`text-description flex min-w-0 flex-row items-center justify-between gap-1.5 text-xs transition-colors duration-200 ease-in-out ${
|
||||
|
|
@ -87,15 +89,19 @@ export function SimpleToolCallUI({
|
|||
</div>
|
||||
<ToolCallStatusMessage tool={tool} toolCallState={toolCallState} />
|
||||
</div>
|
||||
{args.length > 0 && (
|
||||
<ArgsToggleIcon
|
||||
isShowing={showingArgs}
|
||||
setIsShowing={setShowingArgs}
|
||||
toolCallId={toolCallState.toolCallId}
|
||||
/>
|
||||
)}
|
||||
<div className="flex flex-row items-center gap-1.5">
|
||||
{!!toolCallState.output?.length && (
|
||||
<ToolTruncateHistoryIcon historyIndex={historyIndex} />
|
||||
)}
|
||||
{args.length > 0 ? (
|
||||
<ArgsToggleIcon
|
||||
isShowing={showingArgs}
|
||||
setIsShowing={setShowingArgs}
|
||||
toolCallId={toolCallState.toolCallId}
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ArgsItems args={args} isShowing={showingArgs} />
|
||||
|
||||
{isToggleable && (
|
||||
|
|
@ -104,8 +110,8 @@ export function SimpleToolCallUI({
|
|||
shouldShowContent ? "max-h-[50vh] opacity-100" : "max-h-0 opacity-0"
|
||||
}`}
|
||||
>
|
||||
{ctxItems.length > 0 ? (
|
||||
ctxItems.map((contextItem, idx) => (
|
||||
{shownContextItems.length > 0 ? (
|
||||
shownContextItems.map((contextItem, idx) => (
|
||||
<ContextItemsPeekItem key={idx} contextItem={contextItem} />
|
||||
))
|
||||
) : (
|
||||
|
|
|
|||
|
|
@ -2,12 +2,14 @@ import { Tool, ToolCallState } from "core";
|
|||
import { useMemo, useState } from "react";
|
||||
import { ArgsItems, ArgsToggleIcon } from "./ToolCallArgs";
|
||||
import { ToolCallStatusMessage } from "./ToolCallStatusMessage";
|
||||
import { ToolTruncateHistoryIcon } from "./ToolTruncateHistoryIcon";
|
||||
|
||||
interface ToolCallDisplayProps {
|
||||
children: React.ReactNode;
|
||||
icon: React.ReactNode;
|
||||
tool: Tool | undefined;
|
||||
toolCallState: ToolCallState;
|
||||
historyIndex: number;
|
||||
}
|
||||
|
||||
export function ToolCallDisplay({
|
||||
|
|
@ -15,6 +17,7 @@ export function ToolCallDisplay({
|
|||
toolCallState,
|
||||
children,
|
||||
icon,
|
||||
historyIndex,
|
||||
}: ToolCallDisplayProps) {
|
||||
const [argsExpanded, setArgsExpanded] = useState(false);
|
||||
|
||||
|
|
@ -39,13 +42,18 @@ export function ToolCallDisplay({
|
|||
toolCallState={toolCallState}
|
||||
/>
|
||||
</div>
|
||||
{!!args.length ? (
|
||||
<ArgsToggleIcon
|
||||
isShowing={argsExpanded}
|
||||
setIsShowing={setArgsExpanded}
|
||||
toolCallId={toolCallState.toolCallId}
|
||||
/>
|
||||
) : null}
|
||||
<div className="flex flex-row items-center gap-1.5">
|
||||
{!!toolCallState.output && (
|
||||
<ToolTruncateHistoryIcon historyIndex={historyIndex} />
|
||||
)}
|
||||
{!!args.length ? (
|
||||
<ArgsToggleIcon
|
||||
isShowing={argsExpanded}
|
||||
setIsShowing={setArgsExpanded}
|
||||
toolCallId={toolCallState.toolCallId}
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
{argsExpanded && !!args.length && (
|
||||
<ArgsItems args={args} isShowing={argsExpanded} />
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ export const ArgsToggleIcon = ({
|
|||
}}
|
||||
className={`hover:description-muted/30 cursor-pointer select-none rounded px-1 py-0.5 hover:opacity-80 ${isShowing ? "bg-description-muted/30" : "bg-transparent"}`}
|
||||
>
|
||||
<CodeBracketIcon className="h-2.5 w-2.5 flex-shrink-0 opacity-60" />
|
||||
<CodeBracketIcon className="h-3 w-3 flex-shrink-0 opacity-60" />
|
||||
</div>
|
||||
<ToolTip id={argsTooltipId}>
|
||||
{isShowing ? "Hide args" : "Show args"}
|
||||
|
|
|
|||
40
gui/src/pages/gui/ToolCallDiv/ToolTruncateHistoryIcon.tsx
Normal file
40
gui/src/pages/gui/ToolCallDiv/ToolTruncateHistoryIcon.tsx
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import { BarsArrowUpIcon } from "@heroicons/react/24/outline";
|
||||
import { chatMessageIsEmpty } from "core/llm/messages";
|
||||
import { findLastIndex } from "core/util/findLast";
|
||||
import { useMemo } from "react";
|
||||
import { useMainEditor } from "../../../components/mainInput/TipTapEditor";
|
||||
import { ToolbarButtonWithTooltip } from "../../../components/StyledMarkdownPreview/StepContainerPreToolbar/ToolbarButtonWithTooltip";
|
||||
import { useAppDispatch, useAppSelector } from "../../../redux/hooks";
|
||||
import { truncateHistoryToMessage } from "../../../redux/slices/sessionSlice";
|
||||
|
||||
export function ToolTruncateHistoryIcon({
|
||||
historyIndex,
|
||||
}: {
|
||||
historyIndex: number;
|
||||
}) {
|
||||
const isStreaming = useAppSelector((state) => state.session.isStreaming);
|
||||
const history = useAppSelector((state) => state.session.history);
|
||||
const lastMessageIndex = useMemo(() => {
|
||||
return findLastIndex(history, (item) => !chatMessageIsEmpty(item.message));
|
||||
}, [history]);
|
||||
const dispatch = useAppDispatch();
|
||||
const { mainEditor } = useMainEditor();
|
||||
if (isStreaming || historyIndex === lastMessageIndex) {
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<ToolbarButtonWithTooltip
|
||||
tooltipContent="Trim chat to this message"
|
||||
onClick={() => {
|
||||
dispatch(
|
||||
truncateHistoryToMessage({
|
||||
index: historyIndex,
|
||||
}),
|
||||
);
|
||||
mainEditor?.commands.focus();
|
||||
}}
|
||||
>
|
||||
<BarsArrowUpIcon className="h-3 w-3 flex-shrink-0" />
|
||||
</ToolbarButtonWithTooltip>
|
||||
);
|
||||
}
|
||||
|
|
@ -12,12 +12,7 @@ import {
|
|||
PencilIcon,
|
||||
XMarkIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import {
|
||||
ContextItemWithId,
|
||||
ToolCallDelta,
|
||||
ToolCallState,
|
||||
ToolStatus,
|
||||
} from "core";
|
||||
import { ToolCallDelta, ToolCallState, ToolStatus } from "core";
|
||||
import { BuiltInToolNames } from "core/tools/builtIn";
|
||||
import { ComponentType, useMemo } from "react";
|
||||
import { vscButtonBackground } from "../../../components";
|
||||
|
|
@ -30,7 +25,6 @@ import { ToolCallDisplay } from "./ToolCall";
|
|||
interface ToolCallDivProps {
|
||||
toolCall: ToolCallDelta;
|
||||
toolCallState: ToolCallState;
|
||||
output?: ContextItemWithId[];
|
||||
historyIndex: number;
|
||||
}
|
||||
|
||||
|
|
@ -86,7 +80,7 @@ export function ToolCallDiv(props: ToolCallDivProps) {
|
|||
icon={
|
||||
props.toolCallState.status === "generated" ? ArrowRightIcon : icon
|
||||
}
|
||||
contextItems={props.output ?? []}
|
||||
historyIndex={props.historyIndex}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
@ -96,6 +90,7 @@ export function ToolCallDiv(props: ToolCallDivProps) {
|
|||
icon={getStatusIcon(props.toolCallState.status)}
|
||||
tool={tool}
|
||||
toolCallState={props.toolCallState}
|
||||
historyIndex={props.historyIndex}
|
||||
>
|
||||
<FunctionSpecificToolCallDiv
|
||||
toolCall={props.toolCall}
|
||||
|
|
|
|||
|
|
@ -233,6 +233,28 @@ export const sessionSlice = createSlice({
|
|||
|
||||
state.isStreaming = true;
|
||||
},
|
||||
truncateHistoryToMessage: (
|
||||
state,
|
||||
{
|
||||
payload,
|
||||
}: PayloadAction<{
|
||||
index: number;
|
||||
}>,
|
||||
) => {
|
||||
const { index } = payload;
|
||||
|
||||
if (state.history.length && index < state.history.length) {
|
||||
state.codeBlockApplyStates.curIndex = 0;
|
||||
state.history = state.history.slice(0, index + 1).concat({
|
||||
message: {
|
||||
id: uuidv4(),
|
||||
role: "assistant",
|
||||
content: "", // IMPORTANT - this is subsequently updated by response streaming
|
||||
},
|
||||
contextItems: [],
|
||||
});
|
||||
}
|
||||
},
|
||||
deleteMessage: (state, action: PayloadAction<number>) => {
|
||||
// Deletes the current assistant message and the previous user message
|
||||
state.history.splice(action.payload - 1, 2);
|
||||
|
|
@ -730,6 +752,7 @@ export const {
|
|||
addPromptCompletionPair,
|
||||
setActive,
|
||||
submitEditorAndInitAtIndex,
|
||||
truncateHistoryToMessage,
|
||||
updateHistoryItemAtIndex,
|
||||
clearDanglingMessages,
|
||||
setMainEditorContentTrigger,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue