Changesets · Branches · Tags · Compare
| Changeset | c9f65f59bfedfc3af81595836ee7f9f98ad54943136d76a1f6c51d77024cdb99 |
|---|---|
| Author | Patrick Erichsen <patrick.a.erichsen@gmail.com> · 2025-06-30 14:27 -07:00 |
| Committer | GitHub <noreply@github.com> · 2025-06-30 14:27 -07:00 |
| Parents | 331f3efaf2d8, 86933b774919 |
2 files changed
modified gui/src/components/mainInput/belowMainInput/ContextItemsPeek.tsx +29 −23
| @@ -4,7 +4,10 @@ | ||
| 4 | 4 | import { getUriPathBasename } from "core/util/uri"; |
| 5 | 5 | import { ComponentType, useContext, useMemo } from "react"; |
| 6 | 6 | import { AnimatedEllipsis } from "../.."; |
| 7 | -import { IdeMessengerContext } from "../../../context/IdeMessenger"; | |
| 7 | +import { | |
| 8 | + IdeMessengerContext, | |
| 9 | + IIdeMessenger, | |
| 10 | +} from "../../../context/IdeMessenger"; | |
| 8 | 11 | import { useAppSelector } from "../../../redux/hooks"; |
| 9 | 12 | import { selectIsGatheringContext } from "../../../redux/slices/sessionSlice"; |
| 10 | 13 | import FileIcon from "../../FileIcon"; |
| @@ -24,33 +27,36 @@ | ||
| 24 | 27 | contextItem: ContextItemWithId; |
| 25 | 28 | } |
| 26 | 29 | |
| 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 | + | |
| 27 | 54 | export function ContextItemsPeekItem({ |
| 28 | 55 | contextItem, |
| 29 | 56 | }: ContextItemsPeekItemProps) { |
| 30 | 57 | const ideMessenger = useContext(IdeMessengerContext); |
| 31 | 58 | const isUrl = contextItem.uri?.type === "url"; |
| 32 | 59 | |
| 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 | - | |
| 54 | 60 | function getContextItemIcon() { |
| 55 | 61 | const dimensions = "18px"; |
| 56 | 62 | |
| @@ -116,7 +122,7 @@ | ||
| 116 | 122 | |
| 117 | 123 | return ( |
| 118 | 124 | <div |
| 119 | - onClick={openContextItem} | |
| 125 | + onClick={() => openContextItem(contextItem, ideMessenger)} | |
| 120 | 126 | 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" |
| 121 | 127 | data-testid="context-items-peek-item" |
| 122 | 128 | > |
modified gui/src/pages/gui/ToolCallDiv/SimpleToolCallUI.tsx +70 −33
| @@ -1,7 +1,11 @@ | ||
| 1 | 1 | import { ChevronRightIcon } from "@heroicons/react/24/outline"; |
| 2 | 2 | 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"; | |
| 5 | 9 | import { ArgsItems, ArgsToggleIcon } from "./ToolCallArgs"; |
| 6 | 10 | import { ToolCallStatusMessage } from "./ToolCallStatusMessage"; |
| 7 | 11 | |
| @@ -18,66 +22,99 @@ | ||
| 18 | 22 | toolCallState, |
| 19 | 23 | tool, |
| 20 | 24 | }: SimpleToolCallUIProps) { |
| 25 | + const ideMessenger = useContext(IdeMessengerContext); | |
| 26 | + | |
| 21 | 27 | const ctxItems = useMemo(() => { |
| 22 | 28 | return contextItems?.filter((ctxItem) => !ctxItem.hidden) ?? []; |
| 23 | 29 | }, [contextItems]); |
| 24 | 30 | |
| 25 | 31 | const [open, setOpen] = useState(false); |
| 26 | 32 | const [isHovered, setIsHovered] = useState(false); |
| 27 | - | |
| 28 | 33 | const [showingArgs, setShowingArgs] = useState(false); |
| 29 | 34 | |
| 30 | 35 | const args: [string, any][] = useMemo(() => { |
| 31 | 36 | return Object.entries(toolCallState.parsedArgs); |
| 32 | 37 | }, [toolCallState.parsedArgs]); |
| 33 | 38 | |
| 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 | + | |
| 34 | 73 | return ( |
| 35 | 74 | <div className="flex flex-col pl-5 pr-2 pt-4"> |
| 36 | 75 | <div className="flex min-w-0 flex-row items-center justify-between gap-2"> |
| 37 | 76 | <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} | |
| 42 | 83 | data-testid="context-items-peek" |
| 43 | 84 | > |
| 44 | 85 | <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()} | |
| 54 | 87 | </div> |
| 55 | 88 | <ToolCallStatusMessage tool={tool} toolCallState={toolCallState} /> |
| 56 | 89 | </div> |
| 57 | - {args.length > 0 ? ( | |
| 90 | + {args.length > 0 && ( | |
| 58 | 91 | <ArgsToggleIcon |
| 59 | 92 | isShowing={showingArgs} |
| 60 | 93 | setIsShowing={setShowingArgs} |
| 61 | 94 | toolCallId={toolCallState.toolCallId} |
| 62 | 95 | /> |
| 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> | |
| 79 | 96 | )} |
| 80 | 97 | </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 | + )} | |
| 81 | 118 | </div> |
| 82 | 119 | ); |
| 83 | 120 | } |