clean up tool call args UI
This commit is contained in:
parent
0a898ed2de
commit
204a96fe13
6 changed files with 55 additions and 83 deletions
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
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";
|
||||
|
|
@ -32,39 +32,27 @@ export function SimpleToolCallUI({
|
|||
}, [toolCallState.parsedArgs]);
|
||||
|
||||
return (
|
||||
<div className="flex flex-1 flex-col pl-1 pr-2 pt-2">
|
||||
<div className="flex flex-row items-center justify-between gap-2 hover:brightness-125">
|
||||
<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 cursor-pointer items-center justify-between gap-1.5 text-xs"
|
||||
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={`text-description absolute h-4 w-4`} />
|
||||
<Icon className={`text-description h-4 w-4`} />
|
||||
) : (
|
||||
<>
|
||||
<ChevronRightIcon
|
||||
className={`text-description absolute h-4 w-4 transition-all duration-200 ease-in-out ${
|
||||
open ? "rotate-90 opacity-0" : "rotate-0 opacity-100"
|
||||
}`}
|
||||
/>
|
||||
<ChevronDownIcon
|
||||
className={`text-description absolute h-4 w-4 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>
|
||||
<div
|
||||
className="text-description ml-1 inline-block text-xs transition-colors duration-200"
|
||||
data-testid="tool-call-title"
|
||||
>
|
||||
<ToolCallStatusMessage tool={tool} toolCallState={toolCallState} />
|
||||
</div>
|
||||
<ToolCallStatusMessage tool={tool} toolCallState={toolCallState} />
|
||||
</div>
|
||||
{args.length > 0 ? (
|
||||
<ArgsToggleIcon
|
||||
|
|
|
|||
|
|
@ -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-1.5">
|
||||
<div className="flex flex-row items-center gap-2">
|
||||
<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
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ export const ArgsItems = ({ args, isShowing }: ArgsItemsProps) => {
|
|||
}
|
||||
|
||||
return (
|
||||
<div className="ml-5 mr-2 mt-1 flex flex-col">
|
||||
<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>
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 ?? []}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue