tool call args display

This commit is contained in:
Dallin Romney 2025-03-16 17:41:15 -07:00
parent 432221b87d
commit a8522f7090
3 changed files with 102 additions and 79 deletions

View file

@ -1,75 +0,0 @@
import { Tool, ToolCallDelta, ToolCallState } from "core";
import Mustache from "mustache";
import styled from "styled-components";
import { useAppSelector } from "../../../redux/hooks";
interface ThreadDivProps {
children: React.ReactNode;
icon: React.ReactNode;
toolCall: ToolCallDelta;
toolCallState: ToolCallState;
}
const Container = styled.div`
display: flex;
flex-direction: column;
justify-content: center;
position: relative;
padding: 8px;
padding-bottom: 0;
`;
const ChildrenDiv = styled.div``;
const W = 16;
const HeaderDiv = styled.div`
display: flex;
align-items: center;
gap: 6px;
margin-bottom: 8px;
`;
export function ThreadDiv(props: ThreadDivProps) {
const availableTools = useAppSelector((state) => state.config.config.tools);
function renderWouldLikeToMessage(
tool: Tool | undefined,
toolCallState: ToolCallState,
): string {
if (!tool) return "";
const rendered = Mustache.render(
tool.wouldLikeTo,
toolCallState.parsedArgs,
);
return rendered;
}
const tool = availableTools.find(
(tool) => props.toolCall.function?.name === tool.function.name,
);
return (
<Container>
<HeaderDiv>
<div
style={{
width: `${W}px`,
height: `${W}px`,
fontWeight: "bolder",
marginTop: "1px",
flexShrink: 0,
}}
>
{props.icon}
</div>
{tool?.faviconUrl && (
<img src={tool.faviconUrl} className="h-4 w-4 rounded-sm" />
)}
Continue wants to {renderWouldLikeToMessage(tool, props.toolCallState)}
</HeaderDiv>
<ChildrenDiv>{props.children}</ChildrenDiv>
</Container>
);
}

View file

@ -0,0 +1,98 @@
import { ChevronDownIcon, ChevronUpIcon } from "@heroicons/react/24/outline";
import { ToolCallDelta, ToolCallState } from "core";
import Mustache from "mustache";
import { useMemo, useState } from "react";
import { ToolTip } from "../../../components/gui/Tooltip";
import { useAppSelector } from "../../../redux/hooks";
interface ToolCallDisplayProps {
children: React.ReactNode;
icon: React.ReactNode;
toolCall: ToolCallDelta;
toolCallState: ToolCallState;
}
export function ToolCallDisplay(props: ToolCallDisplayProps) {
const [isExpanded, setIsExpanded] = useState(false);
const availableTools = useAppSelector((state) => state.config.config.tools);
const tool = useMemo(() => {
return availableTools.find(
(tool) => props.toolCall.function?.name === tool.function.name,
);
}, [availableTools, props.toolCall]);
const wouldLikeToMessage = useMemo(() => {
if (!tool) return "";
const rendered = Mustache.render(
tool.wouldLikeTo,
props.toolCallState.parsedArgs,
);
return rendered;
}, [props.toolCallState, tool]);
const args: [string, any][] = useMemo(() => {
return Object.entries(props.toolCallState.parsedArgs);
}, [props.toolCallState.parsedArgs]);
const argsTooltipId = useMemo(() => {
return "args-hover-" + props.toolCallState.toolCallId;
}, [props.toolCallState]);
return (
<>
<div className="relative flex flex-col justify-center p-4 pb-0">
<div className="mb-4 flex flex-col">
<div className="flex flex-row items-center justify-between gap-3">
<div className="flex flex-row gap-2">
<div
style={{
width: `16px`,
height: `16px`,
fontWeight: "bolder",
marginTop: "1px",
flexShrink: 0,
}}
>
{props.icon}
</div>
{tool?.faviconUrl && (
<img src={tool.faviconUrl} className="h-4 w-4 rounded-sm" />
)}
<span className="">Continue wants to{wouldLikeToMessage}</span>
</div>
{!!args.length ? (
<div
data-tooltip-id={argsTooltipId}
onClick={() => setIsExpanded(!isExpanded)}
className="ml-2 cursor-pointer hover:opacity-80"
>
{isExpanded ? (
<ChevronUpIcon className="h-4 w-4" />
) : (
<ChevronDownIcon className="h-4 w-4" />
)}
</div>
) : null}
<ToolTip id={argsTooltipId}>
{isExpanded ? "Hide args" : "Show args"}
</ToolTip>
</div>
{isExpanded && !!args.length && (
<div className="ml-7">
{args.map(([key, value]) => (
<div key={key} className="flex gap-2 py-1">
<span className="text-lightgray">{key}:</span>
<code className="lines lines-1">{value}</code>
</div>
))}
</div>
)}
</div>
<div>{props.children}</div>
</div>
</>
);
}

View file

@ -3,11 +3,11 @@ import {
CheckIcon,
XMarkIcon,
} from "@heroicons/react/24/outline";
import { ToolCall, ToolCallDelta, ToolCallState, ToolStatus } from "core";
import { ToolCallDelta, ToolCallState, ToolStatus } from "core";
import { vscButtonBackground } from "../../../components";
import Spinner from "../../../components/gui/Spinner";
import FunctionSpecificToolCallDiv from "./FunctionSpecificToolCallDiv";
import { ThreadDiv } from "./ThreadDiv";
import { ToolCallDisplay } from "./ToolCall";
interface ToolCallDivProps {
toolCall: ToolCallDelta;
@ -30,7 +30,7 @@ export function ToolCallDiv(props: ToolCallDivProps) {
}
return (
<ThreadDiv
<ToolCallDisplay
icon={getIcon(props.toolCallState.status)}
toolCall={props.toolCall}
toolCallState={props.toolCallState}
@ -39,6 +39,6 @@ export function ToolCallDiv(props: ToolCallDivProps) {
toolCall={props.toolCall}
toolCallState={props.toolCallState}
/>
</ThreadDiv>
</ToolCallDisplay>
);
}