Elffuss BraidHub

kikocis/continue public

Merge pull request #6319 from continuedev/nate/tool-call-ui

Improve UI for tool calls that only have one context item
Changesetc9f65f59bfedfc3af81595836ee7f9f98ad54943136d76a1f6c51d77024cdb99
AuthorPatrick Erichsen <patrick.a.erichsen@gmail.com> · 2025-06-30 14:27 -07:00
CommitterGitHub <noreply@github.com> · 2025-06-30 14:27 -07:00
Parents331f3efaf2d8, 86933b774919

Browse the files at this changeset

2 files changed

modified gui/src/components/mainInput/belowMainInput/ContextItemsPeek.tsx +29 −23
@@ -4,7 +4,10 @@
44 import { getUriPathBasename } from "core/util/uri";
55 import { ComponentType, useContext, useMemo } from "react";
66 import { AnimatedEllipsis } from "../..";
7-import { IdeMessengerContext } from "../../../context/IdeMessenger";
7+import {
8+ IdeMessengerContext,
9+ IIdeMessenger,
10+} from "../../../context/IdeMessenger";
811 import { useAppSelector } from "../../../redux/hooks";
912 import { selectIsGatheringContext } from "../../../redux/slices/sessionSlice";
1013 import FileIcon from "../../FileIcon";
@@ -24,33 +27,36 @@
2427 contextItem: ContextItemWithId;
2528 }
2629
30+export function openContextItem(
31+ contextItem: ContextItemWithId,
32+ ideMessenger: IIdeMessenger,
33+) {
34+ const { uri, name, content } = contextItem;
35+
36+ if (uri && uri?.type === "file") {
37+ const isRangeInFile = name.includes(" (") && name.endsWith(")");
38+
39+ if (isRangeInFile) {
40+ const rif = ctxItemToRifWithContents(contextItem, true);
41+ void ideMessenger.ide.showLines(
42+ rif.filepath,
43+ rif.range.start.line,
44+ rif.range.end.line,
45+ );
46+ } else {
47+ void ideMessenger.ide.openFile(uri.value);
48+ }
49+ } else {
50+ void ideMessenger.ide.showVirtualFile(name, content);
51+ }
52+}
53+
2754 export function ContextItemsPeekItem({
2855 contextItem,
2956 }: ContextItemsPeekItemProps) {
3057 const ideMessenger = useContext(IdeMessengerContext);
3158 const isUrl = contextItem.uri?.type === "url";
3259
33- function openContextItem() {
34- const { uri, name, content } = contextItem;
35-
36- if (uri && uri?.type === "file") {
37- const isRangeInFile = name.includes(" (") && name.endsWith(")");
38-
39- if (isRangeInFile) {
40- const rif = ctxItemToRifWithContents(contextItem, true);
41- void ideMessenger.ide.showLines(
42- rif.filepath,
43- rif.range.start.line,
44- rif.range.end.line,
45- );
46- } else {
47- void ideMessenger.ide.openFile(uri.value);
48- }
49- } else {
50- void ideMessenger.ide.showVirtualFile(name, content);
51- }
52- }
53-
5460 function getContextItemIcon() {
5561 const dimensions = "18px";
5662
@@ -116,7 +122,7 @@
116122
117123 return (
118124 <div
119- onClick={openContextItem}
125+ onClick={() => openContextItem(contextItem, ideMessenger)}
120126 className="group mr-2 flex cursor-pointer items-center overflow-hidden text-ellipsis whitespace-nowrap rounded px-1.5 py-1 text-xs hover:bg-white/10"
121127 data-testid="context-items-peek-item"
122128 >
modified gui/src/pages/gui/ToolCallDiv/SimpleToolCallUI.tsx +70 −33
@@ -1,7 +1,11 @@
11 import { ChevronRightIcon } from "@heroicons/react/24/outline";
22 import { ContextItemWithId, Tool, ToolCallState } from "core";
3-import { ComponentType, useMemo, useState } from "react";
4-import { ContextItemsPeekItem } from "../../../components/mainInput/belowMainInput/ContextItemsPeek";
3+import { ComponentType, useContext, useMemo, useState } from "react";
4+import {
5+ ContextItemsPeekItem,
6+ openContextItem,
7+} from "../../../components/mainInput/belowMainInput/ContextItemsPeek";
8+import { IdeMessengerContext } from "../../../context/IdeMessenger";
59 import { ArgsItems, ArgsToggleIcon } from "./ToolCallArgs";
610 import { ToolCallStatusMessage } from "./ToolCallStatusMessage";
711
@@ -18,66 +22,99 @@
1822 toolCallState,
1923 tool,
2024 }: SimpleToolCallUIProps) {
25+ const ideMessenger = useContext(IdeMessengerContext);
26+
2127 const ctxItems = useMemo(() => {
2228 return contextItems?.filter((ctxItem) => !ctxItem.hidden) ?? [];
2329 }, [contextItems]);
2430
2531 const [open, setOpen] = useState(false);
2632 const [isHovered, setIsHovered] = useState(false);
27-
2833 const [showingArgs, setShowingArgs] = useState(false);
2934
3035 const args: [string, any][] = useMemo(() => {
3136 return Object.entries(toolCallState.parsedArgs);
3237 }, [toolCallState.parsedArgs]);
3338
39+ const isToggleable = ctxItems.length > 1;
40+ const isSingleItem = ctxItems.length === 1;
41+ const shouldShowContent = isToggleable ? open : false;
42+ const isClickable = isToggleable || isSingleItem;
43+
44+ function handleClick() {
45+ if (isToggleable) {
46+ setOpen((prev) => !prev);
47+ } else if (isSingleItem) {
48+ openContextItem(ctxItems[0], ideMessenger);
49+ }
50+ }
51+
52+ function renderIcon() {
53+ if (!Icon && !isToggleable) {
54+ return null;
55+ }
56+
57+ if (isToggleable) {
58+ const showChevron = isHovered || shouldShowContent;
59+ return showChevron ? (
60+ <ChevronRightIcon
61+ className={`text-description h-4 w-4 transition-transform duration-200 ease-in-out ${
62+ shouldShowContent ? "rotate-90" : "rotate-0"
63+ }`}
64+ />
65+ ) : (
66+ Icon && <Icon className="text-description h-4 w-4" />
67+ );
68+ }
69+
70+ return Icon ? <Icon className="text-description h-4 w-4" /> : null;
71+ }
72+
3473 return (
3574 <div className="flex flex-col pl-5 pr-2 pt-4">
3675 <div className="flex min-w-0 flex-row items-center justify-between gap-2">
3776 <div
38- 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"
39- onClick={() => setOpen((prev) => !prev)}
40- onMouseEnter={() => setIsHovered(true)}
41- onMouseLeave={() => setIsHovered(false)}
77+ 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 ${
78+ isClickable ? "cursor-pointer hover:brightness-125" : ""
79+ }`}
80+ onClick={isClickable ? handleClick : undefined}
81+ onMouseEnter={isToggleable ? () => setIsHovered(true) : undefined}
82+ onMouseLeave={isToggleable ? () => setIsHovered(false) : undefined}
4283 data-testid="context-items-peek"
4384 >
4485 <div className="flex h-4 w-4 flex-shrink-0 flex-col items-center justify-center">
45- {Icon && !isHovered && !open ? (
46- <Icon className={`text-description h-4 w-4`} />
47- ) : (
48- <ChevronRightIcon
49- className={`text-description h-4 w-4 transition-transform duration-200 ease-in-out ${
50- open ? "rotate-90" : "rotate-0"
51- }`}
52- />
53- )}
86+ {renderIcon()}
5487 </div>
5588 <ToolCallStatusMessage tool={tool} toolCallState={toolCallState} />
5689 </div>
57- {args.length > 0 ? (
90+ {args.length > 0 && (
5891 <ArgsToggleIcon
5992 isShowing={showingArgs}
6093 setIsShowing={setShowingArgs}
6194 toolCallId={toolCallState.toolCallId}
6295 />
63- ) : null}
64- </div>
65- <ArgsItems args={args} isShowing={showingArgs} />
66- <div
67- className={`mt-2 overflow-y-auto transition-all duration-300 ease-in-out ${
68- open ? "max-h-[50vh] opacity-100" : "max-h-0 opacity-0"
69- }`}
70- >
71- {ctxItems.length ? (
72- ctxItems.map((contextItem, idx) => (
73- <ContextItemsPeekItem key={idx} contextItem={contextItem} />
74- ))
75- ) : (
76- <div className="text-description pl-5 text-xs italic">
77- No tool call output
78- </div>
7996 )}
8097 </div>
98+
99+ <ArgsItems args={args} isShowing={showingArgs} />
100+
101+ {isToggleable && (
102+ <div
103+ className={`mt-2 overflow-y-auto transition-all duration-300 ease-in-out ${
104+ shouldShowContent ? "max-h-[50vh] opacity-100" : "max-h-0 opacity-0"
105+ }`}
106+ >
107+ {ctxItems.length > 0 ? (
108+ ctxItems.map((contextItem, idx) => (
109+ <ContextItemsPeekItem key={idx} contextItem={contextItem} />
110+ ))
111+ ) : (
112+ <div className="text-description pl-5 text-xs italic">
113+ No tool call output
114+ </div>
115+ )}
116+ </div>
117+ )}
81118 </div>
82119 );
83120 }