Merge pull request #5887 from continuedev/dallin/tools-ui-docs-tweaks

Fix tool call args UI overflow
This commit is contained in:
Dallin Romney 2025-05-28 18:06:44 -07:00 • committed by GitHub
commit c20ddb3c68
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 70 additions and 99 deletions

View file

@ -333,17 +333,16 @@ export function Chat() {
"assistant" &&
item.message.toolCalls &&
item.toolCallState ? (
<div>
<div className="">
{item.message.toolCalls?.map((toolCall, i) => {
return (
<div key={i}>
<ToolCallDiv
toolCallState={item.toolCallState!}
toolCall={toolCall}
output={history[index + 1]?.contextItems}
historyIndex={index}
/>
</div>
<ToolCallDiv
key={i}
toolCallState={item.toolCallState!}
toolCall={toolCall}
output={history[index + 1]?.contextItems}
historyIndex={index}
/>
);
})}
</div>

View file

@ -1,8 +1,8 @@
import { ChevronDownIcon, ChevronRightIcon } from "@heroicons/react/24/outline";
import { ChevronRightIcon } from "@heroicons/react/24/outline";
import { ContextItemWithId, Tool, ToolCallState } from "core";
import { ComponentType, useMemo, useState } from "react";
import { ContextItemsPeekItem } from "../../../components/mainInput/belowMainInput/ContextItemsPeek";
import { ArgsItems } from "./ToolCallArgs";
import { ArgsItems, ArgsToggleIcon } from "./ToolCallArgs";
import { ToolCallStatusMessage } from "./ToolCallStatusMessage";
interface SimpleToolCallUIProps {
@ -32,49 +32,35 @@ export function SimpleToolCallUI({
}, [toolCallState.parsedArgs]);
return (
<div className="flex flex-1 flex-col px-2 pt-2 hover:brightness-125">
<div className="flex flex-row justify-between">
<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="flex cursor-pointer items-center justify-start text-xs text-gray-300"
className="text-description flex min-w-0 cursor-pointer flex-row items-center justify-between gap-1.5 text-xs transition-colors duration-200 ease-in-out hover:brightness-125"
onClick={() => setOpen((prev) => !prev)}
onMouseEnter={() => setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)}
data-testid="context-items-peek"
>
<div className="relative mr-1 h-4 w-4">
<div className="flex h-4 w-4 flex-shrink-0 flex-col items-center justify-center">
{Icon && !isHovered && !open ? (
<Icon className={`absolute h-4 w-4 text-gray-400`} />
<Icon className={`text-description h-4 w-4`} />
) : (
<>
<ChevronRightIcon
className={`absolute h-4 w-4 text-gray-400 transition-all duration-200 ease-in-out ${
open ? "rotate-90 opacity-0" : "rotate-0 opacity-100"
}`}
/>
<ChevronDownIcon
className={`absolute h-4 w-4 text-gray-400 transition-all duration-200 ease-in-out ${
open ? "rotate-0 opacity-100" : "-rotate-90 opacity-0"
}`}
/>
</>
<ChevronRightIcon
className={`text-description h-4 w-4 transition-transform duration-200 ease-in-out ${
open ? "rotate-90" : "rotate-0"
}`}
/>
)}
</div>
<span
className="ml-1 text-xs text-gray-400 transition-colors duration-200"
data-testid="tool-call-title"
>
<ToolCallStatusMessage tool={tool} toolCallState={toolCallState} />
</span>
<ToolCallStatusMessage tool={tool} toolCallState={toolCallState} />
</div>
{/* <div>
{args.length > 0 ? (
<ArgsToggleIcon
isShowing={showingArgs}
setIsShowing={setShowingArgs}
toolCallId={toolCallState.toolCallId}
/>
) : null}
</div> */}
{args.length > 0 ? (
<ArgsToggleIcon
isShowing={showingArgs}
setIsShowing={setShowingArgs}
toolCallId={toolCallState.toolCallId}
/>
) : null}
</div>
<ArgsItems args={args} isShowing={showingArgs} />
<div
@ -87,7 +73,7 @@ export function SimpleToolCallUI({
<ContextItemsPeekItem key={idx} contextItem={contextItem} />
))
) : (
<div className="pl-2 text-xs italic text-gray-400">
<div className="text-description pl-5 text-xs italic">
No tool call output
</div>
)}

View file

@ -24,22 +24,20 @@ export function ToolCallDisplay({
return (
<>
<div className="relative flex flex-col justify-center p-4 pb-0">
<div className="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 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" />
)}
<div className="flex" data-testid="tool-call-status-message">
<ToolCallStatusMessage
tool={tool}
toolCallState={toolCallState}
/>
</div>
<ToolCallStatusMessage
tool={tool}
toolCallState={toolCallState}
/>
</div>
{!!args.length ? (
<ArgsToggleIcon

View file

@ -25,10 +25,9 @@ export const ArgsToggleIcon = ({
e.stopPropagation();
setIsShowing(!isShowing);
}}
className={`cursor-pointer select-none rounded-sm px-1 py-0.5 hover:bg-gray-400/40 hover:opacity-80 ${isShowing ? "bg-gray-400/40" : "bg-transparent"}`}
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-3 w-3 flex-shrink-0" />
{/* {`{}`} */}
<CodeBracketIcon className="h-2.5 w-2.5 flex-shrink-0 opacity-60" />
</div>
<ToolTip id={argsTooltipId}>
{isShowing ? "Hide args" : "Show args"}
@ -52,11 +51,13 @@ export const ArgsItems = ({ args, isShowing }: ArgsItemsProps) => {
}
return (
<div className="ml-7 mt-1">
<div className="ml-5 mr-2 mt-1 flex flex-col text-xs">
{args.map(([key, value]) => (
<div key={key} className="flex flex-row items-center gap-2 py-0.5">
<span className="text-lightgray">{key}:</span>
<code className="line-clamp-1">{value.toString()}</code>
<code className="line-clamp-1 break-all">
{JSON.stringify(value)}
</code>
</div>
))}
</div>

View file

@ -1,7 +1,5 @@
import { Tool, ToolCallState } from "core";
import Mustache from "mustache";
import { ReactNode } from "react";
import { getFontSize } from "../../../util";
import { useFontSize } from "../../../components/ui/font";
interface ToolCallStatusMessageProps {
@ -16,35 +14,26 @@ export function ToolCallStatusMessage({
const fontSize = useFontSize();
if (!tool) return "Agent tool use";
const defaultToolDescription = (
<>
<code>{tool.displayTitle ?? tool.function.name}</code> <span>tool</span>
</>
);
const toolName = tool.displayTitle ?? tool.function.name;
const defaultToolDescription = `${toolName} tool`;
const futureMessage = tool.wouldLikeTo ? (
Mustache.render(tool.wouldLikeTo, toolCallState.parsedArgs)
) : (
<>
<span>use the</span> {defaultToolDescription}
</>
);
const futureMessage: string = tool.wouldLikeTo
? Mustache.render(tool.wouldLikeTo, toolCallState.parsedArgs)
: `use the ${defaultToolDescription}`;
// TODO go back and replace arg string values and tool names with <code> tags
// to make them more readable
let intro = "";
let message: ReactNode = "";
let message = "";
if (
toolCallState.status === "done" ||
(tool.isInstant && toolCallState.status === "calling")
) {
intro = "";
message = tool.hasAlready ? (
Mustache.render(tool.hasAlready, toolCallState.parsedArgs)
) : (
<>
<span>used the</span> {defaultToolDescription}
</>
);
message = tool.hasAlready
? Mustache.render(tool.hasAlready, toolCallState.parsedArgs)
: `used the ${defaultToolDescription}`;
} else if (toolCallState.status === "generating") {
intro = "is generating output to";
message = futureMessage;
@ -53,13 +42,9 @@ export function ToolCallStatusMessage({
message = futureMessage;
} else if (toolCallState.status === "calling") {
intro = "is";
message = tool.isCurrently ? (
Mustache.render(tool.isCurrently, toolCallState.parsedArgs)
) : (
<>
<span>calling the</span> {defaultToolDescription}
</>
);
message = tool.isCurrently
? Mustache.render(tool.isCurrently, toolCallState.parsedArgs)
: `calling the ${defaultToolDescription}`;
} else if (
toolCallState.status === "canceled" ||
toolCallState.status === "errored"
@ -68,8 +53,12 @@ export function ToolCallStatusMessage({
message = futureMessage;
}
return (
<div className="block" style={{ fontSize }}>
<span>Continue</span> {intro} {message}
<div
className="text-description line-clamp-4 min-w-0 break-words"
style={{ fontSize }}
data-testid="tool-call-title"
>
{`Continue ${intro} ${message}`}
</div>
);
}

View file

@ -80,16 +80,14 @@ export function ToolCallDiv(props: ToolCallDivProps) {
if (icon) {
return (
<div className="ml-4 mt-2 flex">
<SimpleToolCallUI
tool={tool}
toolCallState={props.toolCallState}
icon={
props.toolCallState.status === "generated" ? ArrowRightIcon : icon
}
contextItems={props.output ?? []}
/>
</div>
<SimpleToolCallUI
tool={tool}
toolCallState={props.toolCallState}
icon={
props.toolCallState.status === "generated" ? ArrowRightIcon : icon
}
contextItems={props.output ?? []}
/>
);
}