From a8522f7090dc782e529713e26ba143e109f95b39 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Sun, 16 Mar 2025 17:41:15 -0700 Subject: [PATCH] tool call args display --- gui/src/pages/gui/ToolCallDiv/ThreadDiv.tsx | 75 ---------------- gui/src/pages/gui/ToolCallDiv/ToolCall.tsx | 98 +++++++++++++++++++++ gui/src/pages/gui/ToolCallDiv/index.tsx | 8 +- 3 files changed, 102 insertions(+), 79 deletions(-) delete mode 100644 gui/src/pages/gui/ToolCallDiv/ThreadDiv.tsx create mode 100644 gui/src/pages/gui/ToolCallDiv/ToolCall.tsx diff --git a/gui/src/pages/gui/ToolCallDiv/ThreadDiv.tsx b/gui/src/pages/gui/ToolCallDiv/ThreadDiv.tsx deleted file mode 100644 index 503f54cb4..000000000 --- a/gui/src/pages/gui/ToolCallDiv/ThreadDiv.tsx +++ /dev/null @@ -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 ( - - -
- {props.icon} -
- {tool?.faviconUrl && ( - - )} - Continue wants to {renderWouldLikeToMessage(tool, props.toolCallState)} -
- {props.children} -
- ); -} diff --git a/gui/src/pages/gui/ToolCallDiv/ToolCall.tsx b/gui/src/pages/gui/ToolCallDiv/ToolCall.tsx new file mode 100644 index 000000000..de67e9ef7 --- /dev/null +++ b/gui/src/pages/gui/ToolCallDiv/ToolCall.tsx @@ -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 ( + <> +
+
+
+
+
+ {props.icon} +
+ {tool?.faviconUrl && ( + + )} + Continue wants to{wouldLikeToMessage} +
+ {!!args.length ? ( +
setIsExpanded(!isExpanded)} + className="ml-2 cursor-pointer hover:opacity-80" + > + {isExpanded ? ( + + ) : ( + + )} +
+ ) : null} + + {isExpanded ? "Hide args" : "Show args"} + +
+ + {isExpanded && !!args.length && ( +
+ {args.map(([key, value]) => ( +
+ {key}: + {value} +
+ ))} +
+ )} +
+
{props.children}
+
+ + ); +} diff --git a/gui/src/pages/gui/ToolCallDiv/index.tsx b/gui/src/pages/gui/ToolCallDiv/index.tsx index 9e3e1fc0f..22c5f9de8 100644 --- a/gui/src/pages/gui/ToolCallDiv/index.tsx +++ b/gui/src/pages/gui/ToolCallDiv/index.tsx @@ -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 ( - - + ); }