move the tool truncation icon to a different PR

This commit is contained in:
Dallin Romney 2025-07-01 12:40:46 -07:00
parent c31c1ed887
commit eb7a5b63d5
7 changed files with 38 additions and 111 deletions

View file

@ -18,7 +18,6 @@ import {
PlusIcon,
SparklesIcon,
TrashIcon,
WrenchScrewdriverIcon,
} from "@heroicons/react/24/outline";
import { DiscordIcon } from "../svg/DiscordIcon";
import { GithubIcon } from "../svg/GithubIcon";
@ -56,5 +55,4 @@ export const NAMED_ICONS: { [key: string]: any } = {
"gitlab-mr": GitlabIcon,
http: GlobeAltIcon,
trash: TrashIcon,
toolCall: WrenchScrewdriverIcon,
};

View file

@ -319,7 +319,7 @@ export function Chat() {
inputId={item.message.id}
/>
</>
) : item.message.role === "tool" ? null : item.message.role === // /> // toolCallId={item.message.toolCallId} // contextItems={item.contextItems} // <ToolOutput
) : item.message.role === "tool" ? null : item.message.role ===
"assistant" &&
item.message.toolCalls &&
item.toolCallState ? (
@ -330,6 +330,7 @@ export function Chat() {
key={i}
toolCallState={item.toolCallState!}
toolCall={toolCall}
output={history[index + 1]?.contextItems}
historyIndex={index}
/>
);

View file

@ -1,5 +1,5 @@
import { ChevronRightIcon } from "@heroicons/react/24/outline";
import { Tool, ToolCallState } from "core";
import { ContextItemWithId, Tool, ToolCallState } from "core";
import { ComponentType, useContext, useMemo, useState } from "react";
import {
ContextItemsPeekItem,
@ -7,28 +7,26 @@ 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 shownContextItems = useMemo(() => {
const contextItems = toolCallStateToContextItems(toolCallState);
return contextItems.filter((item) => !item.hidden);
}, [toolCallState]);
const ctxItems = useMemo(() => {
return contextItems?.filter((ctxItem) => !ctxItem.hidden) ?? [];
}, [contextItems]);
const [open, setOpen] = useState(false);
const [isHovered, setIsHovered] = useState(false);
@ -38,8 +36,8 @@ export function SimpleToolCallUI({
return Object.entries(toolCallState.parsedArgs);
}, [toolCallState.parsedArgs]);
const isToggleable = shownContextItems.length > 1;
const isSingleItem = shownContextItems.length === 1;
const isToggleable = ctxItems.length > 1;
const isSingleItem = ctxItems.length === 1;
const shouldShowContent = isToggleable ? open : false;
const isClickable = isToggleable || isSingleItem;
@ -47,7 +45,7 @@ export function SimpleToolCallUI({
if (isToggleable) {
setOpen((prev) => !prev);
} else if (isSingleItem) {
openContextItem(shownContextItems[0], ideMessenger);
openContextItem(ctxItems[0], ideMessenger);
}
}
@ -73,7 +71,7 @@ export function SimpleToolCallUI({
}
return (
<div className="flex flex-col py-4 pl-5 pr-2">
<div className="flex flex-col pl-5 pr-2 pt-4">
<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 ${
@ -89,19 +87,15 @@ export function SimpleToolCallUI({
</div>
<ToolCallStatusMessage tool={tool} toolCallState={toolCallState} />
</div>
<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>
{args.length > 0 && (
<ArgsToggleIcon
isShowing={showingArgs}
setIsShowing={setShowingArgs}
toolCallId={toolCallState.toolCallId}
/>
)}
</div>
<ArgsItems args={args} isShowing={showingArgs} />
{isToggleable && (
@ -110,8 +104,8 @@ export function SimpleToolCallUI({
shouldShowContent ? "max-h-[50vh] opacity-100" : "max-h-0 opacity-0"
}`}
>
{shownContextItems.length > 0 ? (
shownContextItems.map((contextItem, idx) => (
{ctxItems.length > 0 ? (
ctxItems.map((contextItem, idx) => (
<ContextItemsPeekItem key={idx} contextItem={contextItem} />
))
) : (

View file

@ -2,14 +2,12 @@ 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({
@ -17,7 +15,6 @@ export function ToolCallDisplay({
toolCallState,
children,
icon,
historyIndex,
}: ToolCallDisplayProps) {
const [argsExpanded, setArgsExpanded] = useState(false);
@ -42,18 +39,13 @@ export function ToolCallDisplay({
toolCallState={toolCallState}
/>
</div>
<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>
{!!args.length ? (
<ArgsToggleIcon
isShowing={argsExpanded}
setIsShowing={setArgsExpanded}
toolCallId={toolCallState.toolCallId}
/>
) : null}
</div>
{argsExpanded && !!args.length && (
<ArgsItems args={args} isShowing={argsExpanded} />

View file

@ -1,40 +0,0 @@
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="Truncate chat to this message"
onClick={() => {
dispatch(
truncateHistoryToMessage({
index: historyIndex,
}),
);
mainEditor?.commands.focus();
}}
>
<BarsArrowUpIcon className="h-2.5 w-2.5 flex-shrink-0" />
</ToolbarButtonWithTooltip>
);
}

View file

@ -12,7 +12,12 @@ import {
PencilIcon,
XMarkIcon,
} from "@heroicons/react/24/outline";
import { ToolCallDelta, ToolCallState, ToolStatus } from "core";
import {
ContextItemWithId,
ToolCallDelta,
ToolCallState,
ToolStatus,
} from "core";
import { BuiltInToolNames } from "core/tools/builtIn";
import { ComponentType, useMemo } from "react";
import { vscButtonBackground } from "../../../components";
@ -25,6 +30,7 @@ import { ToolCallDisplay } from "./ToolCall";
interface ToolCallDivProps {
toolCall: ToolCallDelta;
toolCallState: ToolCallState;
output?: ContextItemWithId[];
historyIndex: number;
}
@ -80,7 +86,7 @@ export function ToolCallDiv(props: ToolCallDivProps) {
icon={
props.toolCallState.status === "generated" ? ArrowRightIcon : icon
}
historyIndex={props.historyIndex}
contextItems={props.output ?? []}
/>
);
}
@ -90,7 +96,6 @@ export function ToolCallDiv(props: ToolCallDivProps) {
icon={getStatusIcon(props.toolCallState.status)}
tool={tool}
toolCallState={props.toolCallState}
historyIndex={props.historyIndex}
>
<FunctionSpecificToolCallDiv
toolCall={props.toolCall}

View file

@ -171,28 +171,6 @@ export const sessionSlice = createSlice({
state.history[index].contextItems = contextItems;
}
},
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: [],
});
}
},
submitEditorAndInitAtIndex: (
state,
{
@ -733,7 +711,6 @@ export const {
addPromptCompletionPair,
setActive,
submitEditorAndInitAtIndex,
truncateHistoryToMessage,
updateHistoryItemAtIndex,
clearDanglingMessages,
setMainEditorContentTrigger,