feat: tool call status icon for search and replace UI (#7112)

This commit is contained in:
Dallin Romney 2025-08-12 20:22:43 -07:00 • committed by GitHub
parent 08842da68b
commit c7fdfe4979
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 76 additions and 38 deletions

View file

@ -1,10 +1,13 @@
import { ChevronDownIcon } from "@heroicons/react/24/outline";
import { inferResolvedUriFromRelativePath } from "core/util/ideUtils";
import { renderContextItems } from "core/util/messageContent";
import { useContext, useEffect, useMemo, useState } from "react";
import { IdeMessengerContext } from "../../../context/IdeMessenger";
import { useIdeMessengerRequest } from "../../../hooks/useIdeMessengerRequest";
import { useWebviewListener } from "../../../hooks/useWebviewListener";
import { getStatusIcon } from "../../../pages/gui/ToolCallDiv/utils";
import { useAppSelector } from "../../../redux/hooks";
import { selectToolCallById } from "../../../redux/selectors/selectToolCalls";
import {
selectApplyStateByStreamId,
selectApplyStateByToolCallId,
@ -21,6 +24,7 @@ import { InsertButton } from "./InsertButton";
import { RunInTerminalButton } from "./RunInTerminalButton";
export interface StepContainerPreToolbarProps {
showToolCallStatusIcon?: boolean;
codeBlockContent: string;
language: string | null;
relativeFilepath?: string;
@ -37,6 +41,7 @@ export interface StepContainerPreToolbarProps {
}
export function StepContainerPreToolbar({
showToolCallStatusIcon,
codeBlockContent,
language,
relativeFilepath,
@ -81,6 +86,30 @@ export function StepContainerPreToolbar({
selectApplyStateByToolCallId(state, forceToolCallId),
);
const toolCallState = useAppSelector((state) =>
forceToolCallId ? selectToolCallById(state, forceToolCallId) : undefined,
);
const toolCallStatusIcon =
showToolCallStatusIcon &&
(toolCallState?.status === "canceled" ||
toolCallState?.status === "errored" ||
toolCallState?.status === "done") ? (
<div
className={`mr-1 h-4 w-4 ${toolCallState.output ? "cursor-pointer" : ""}`}
onClick={() => {
if (toolCallState.output) {
ideMessenger.post("showVirtualFile", {
name: "Edit output",
content: renderContextItems(toolCallState.output),
});
}
}}
>
{getStatusIcon(toolCallState.status)}
</div>
) : null;
/**
* In the case where `relativeFilepath` is defined, this will just be `relativeFilepathUri`.
* However, if no `relativeFilepath` is defined, then this will
@ -269,6 +298,7 @@ export function StepContainerPreToolbar({
style={{ fontSize: `${getFontSize() - 2}px` }}
>
<div className="flex max-w-[50%] flex-row items-center">
{toolCallStatusIcon}
<ChevronDownIcon
data-testid="toggle-codeblock"
onClick={() => setIsExpanded(!isExpanded)}

View file

@ -123,6 +123,7 @@ const StyledMarkdown = styled.div<{
`;
interface StyledMarkdownPreviewProps {
showToolCallStatusIcon?: boolean;
source?: string;
className?: string;
isRenderingInStepContainer?: boolean; // Currently only used to control the rendering of codeblocks
@ -300,6 +301,7 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview(
return (
<StepContainerPreToolbar
showToolCallStatusIcon={props.showToolCallStatusIcon}
codeBlockContent={codeBlockContent}
itemIndex={itemIndexRef.current}
codeBlockIndex={codeBlockIndex}
@ -357,6 +359,7 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview(
const uiConfig = useAppSelector(selectUIConfig);
const codeWrapState = uiConfig?.codeWrap ? "pre-wrap" : "pre";
return (
<StyledMarkdown
fontSize={getFontSize()}

View file

@ -1,11 +1,15 @@
import { ContextItem, ToolCallState } from "core";
import { getMarkdownLanguageTagForFile } from "core/util";
import StyledMarkdownPreview from "../../../components/StyledMarkdownPreview";
type EditToolCallProps = {
showToolCallStatusIcon?: boolean;
relativeFilePath: string;
changes: string;
historyIndex: number;
toolCallId?: string;
output?: undefined | ContextItem[];
status?: ToolCallState["status"];
};
export function EditFile(props: EditToolCallProps) {
@ -17,6 +21,7 @@ export function EditFile(props: EditToolCallProps) {
return (
<StyledMarkdownPreview
showToolCallStatusIcon={props.showToolCallStatusIcon}
expandCodeblocks={false}
isRenderingInStepContainer
disableManualApply

View file

@ -38,8 +38,11 @@ function FunctionSpecificToolCallDiv({
? args.diffs.join("\n\n---\n\n")
: args.diffs
: "";
return (
<EditFile
showToolCallStatusIcon={true}
status={toolCallState.status}
relativeFilePath={args?.filepath ?? ""}
changes={changes}
toolCallId={toolCall.id}

View file

@ -63,7 +63,7 @@ export function SimpleToolCallUI({
}
return (
<div className="flex flex-col">
<div className="mt-1 flex flex-col px-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 ${

View file

@ -26,40 +26,35 @@ export function ToolCallDisplay({
}, [toolCallState.parsedArgs]);
return (
<>
<div className="flex flex-col justify-center">
<div className="mb-2 flex flex-col">
<div className="flex flex-row items-center justify-between gap-1.5">
<div className="flex min-w-0 flex-row items-center gap-2">
<div className="mt-[1px] h-4 w-4 flex-shrink-0 font-semibold">
{icon}
</div>
{tool?.faviconUrl && (
<img src={tool.faviconUrl} className="h-4 w-4 rounded-sm" />
)}
<ToolCallStatusMessage
tool={tool}
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}
/>
) : null}
<div className="flex flex-col justify-center px-4">
<div className="mb-2 flex flex-col">
<div className="flex flex-row items-center justify-between gap-1.5">
<div className="flex min-w-0 flex-row items-center gap-2">
<div className="mt-[1px] h-4 w-4 flex-shrink-0 font-semibold">
{icon}
</div>
{tool?.faviconUrl && (
<img src={tool.faviconUrl} className="h-4 w-4 rounded-sm" />
)}
<ToolCallStatusMessage tool={tool} 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}
/>
) : null}
</div>
{argsExpanded && !!args.length && (
<ArgsItems args={args} isShowing={argsExpanded} />
)}
</div>
<div>{children}</div>
{argsExpanded && !!args.length && (
<ArgsItems args={args} isShowing={argsExpanded} />
)}
</div>
</>
<div>{children}</div>
</div>
);
}

View file

@ -56,10 +56,12 @@ export function ToolCallDiv({
// But we'd need a nicer place to put the truncate button and the X icon when tool call fails
if (functionName === BuiltInToolNames.SearchAndReplaceInFile) {
return (
<FunctionSpecificToolCallDiv
toolCallState={toolCallState}
historyIndex={historyIndex}
/>
<div className="flex flex-col px-1">
<FunctionSpecificToolCallDiv
toolCallState={toolCallState}
historyIndex={historyIndex}
/>
</div>
);
}
@ -80,7 +82,7 @@ export function ToolCallDiv({
if (shouldShowGroupedUI) {
return (
<div className="border-border rounded-lg border p-3 pb-0">
<div className="border-border rounded-lg border px-4 py-3 pb-0">
<GroupedToolCallHeader
toolCallStates={toolCallStates}
activeCalls={activeCalls}
@ -103,7 +105,7 @@ export function ToolCallDiv({
}
return toolCallStates.map((toolCallState) => (
<div className="px-4 py-1" key={toolCallState.toolCallId}>
<div className="py-1" key={toolCallState.toolCallId}>
{renderToolCall(toolCallState)}
</div>
));