diff --git a/gui/src/components/mainInput/icons.ts b/gui/src/components/mainInput/icons.ts index 62d69e65b..d8d04cc83 100644 --- a/gui/src/components/mainInput/icons.ts +++ b/gui/src/components/mainInput/icons.ts @@ -18,7 +18,6 @@ import { PlusIcon, SparklesIcon, TrashIcon, - WrenchScrewdriverIcon, } from "@heroicons/react/24/outline"; import { DiscordIcon } from "../svg/DiscordIcon"; import { GithubIcon } from "../svg/GithubIcon"; @@ -56,5 +55,4 @@ export const NAMED_ICONS: { [key: string]: any } = { "gitlab-mr": GitlabIcon, http: GlobeAltIcon, trash: TrashIcon, - toolCall: WrenchScrewdriverIcon, }; diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx index a965f9559..fb75d200c 100644 --- a/gui/src/pages/gui/Chat.tsx +++ b/gui/src/pages/gui/Chat.tsx @@ -319,7 +319,7 @@ export function Chat() { inputId={item.message.id} /> - ) : item.message.role === "tool" ? null : item.message.role === // /> // toolCallId={item.message.toolCallId} // contextItems={item.contextItems} // ); diff --git a/gui/src/pages/gui/ToolCallDiv/SimpleToolCallUI.tsx b/gui/src/pages/gui/ToolCallDiv/SimpleToolCallUI.tsx index 644638309..4a44a8ef3 100644 --- a/gui/src/pages/gui/ToolCallDiv/SimpleToolCallUI.tsx +++ b/gui/src/pages/gui/ToolCallDiv/SimpleToolCallUI.tsx @@ -1,5 +1,5 @@ import { ChevronRightIcon } from "@heroicons/react/24/outline"; -import { Tool, ToolCallState } from "core"; +import { ContextItemWithId, Tool, ToolCallState } from "core"; import { ComponentType, useContext, useMemo, useState } from "react"; import { ContextItemsPeekItem, @@ -7,28 +7,26 @@ import { } from "../../../components/mainInput/belowMainInput/ContextItemsPeek"; import { IdeMessengerContext } from "../../../context/IdeMessenger"; import { ArgsItems, ArgsToggleIcon } from "./ToolCallArgs"; -import { toolCallStateToContextItems } from "./toolCallStateToContextItem"; import { ToolCallStatusMessage } from "./ToolCallStatusMessage"; -import { ToolTruncateHistoryIcon } from "./ToolTruncateHistoryIcon"; interface SimpleToolCallUIProps { toolCallState: ToolCallState; tool: Tool | undefined; + contextItems: ContextItemWithId[]; icon?: ComponentType>; - historyIndex: number; } export function SimpleToolCallUI({ + contextItems, icon: Icon, toolCallState, tool, - historyIndex, }: SimpleToolCallUIProps) { const ideMessenger = useContext(IdeMessengerContext); - const shownContextItems = useMemo(() => { - const contextItems = toolCallStateToContextItems(toolCallState); - return contextItems.filter((item) => !item.hidden); - }, [toolCallState]); + + const ctxItems = useMemo(() => { + return contextItems?.filter((ctxItem) => !ctxItem.hidden) ?? []; + }, [contextItems]); const [open, setOpen] = useState(false); const [isHovered, setIsHovered] = useState(false); @@ -38,8 +36,8 @@ export function SimpleToolCallUI({ return Object.entries(toolCallState.parsedArgs); }, [toolCallState.parsedArgs]); - const isToggleable = shownContextItems.length > 1; - const isSingleItem = shownContextItems.length === 1; + const isToggleable = ctxItems.length > 1; + const isSingleItem = ctxItems.length === 1; const shouldShowContent = isToggleable ? open : false; const isClickable = isToggleable || isSingleItem; @@ -47,7 +45,7 @@ export function SimpleToolCallUI({ if (isToggleable) { setOpen((prev) => !prev); } else if (isSingleItem) { - openContextItem(shownContextItems[0], ideMessenger); + openContextItem(ctxItems[0], ideMessenger); } } @@ -73,7 +71,7 @@ export function SimpleToolCallUI({ } return ( -
+
-
- {!!toolCallState.output?.length && ( - - )} - {args.length > 0 ? ( - - ) : null} -
+ {args.length > 0 && ( + + )}
+ {isToggleable && ( @@ -110,8 +104,8 @@ export function SimpleToolCallUI({ shouldShowContent ? "max-h-[50vh] opacity-100" : "max-h-0 opacity-0" }`} > - {shownContextItems.length > 0 ? ( - shownContextItems.map((contextItem, idx) => ( + {ctxItems.length > 0 ? ( + ctxItems.map((contextItem, idx) => ( )) ) : ( diff --git a/gui/src/pages/gui/ToolCallDiv/ToolCall.tsx b/gui/src/pages/gui/ToolCallDiv/ToolCall.tsx index 956ef791b..dcfd186c7 100644 --- a/gui/src/pages/gui/ToolCallDiv/ToolCall.tsx +++ b/gui/src/pages/gui/ToolCallDiv/ToolCall.tsx @@ -2,14 +2,12 @@ import { Tool, ToolCallState } from "core"; import { useMemo, useState } from "react"; import { ArgsItems, ArgsToggleIcon } from "./ToolCallArgs"; import { ToolCallStatusMessage } from "./ToolCallStatusMessage"; -import { ToolTruncateHistoryIcon } from "./ToolTruncateHistoryIcon"; interface ToolCallDisplayProps { children: React.ReactNode; icon: React.ReactNode; tool: Tool | undefined; toolCallState: ToolCallState; - historyIndex: number; } export function ToolCallDisplay({ @@ -17,7 +15,6 @@ export function ToolCallDisplay({ toolCallState, children, icon, - historyIndex, }: ToolCallDisplayProps) { const [argsExpanded, setArgsExpanded] = useState(false); @@ -42,18 +39,13 @@ export function ToolCallDisplay({ toolCallState={toolCallState} />
-
- {!!toolCallState.output && ( - - )} - {!!args.length ? ( - - ) : null} -
+ {!!args.length ? ( + + ) : null}
{argsExpanded && !!args.length && ( diff --git a/gui/src/pages/gui/ToolCallDiv/ToolTruncateHistoryIcon.tsx b/gui/src/pages/gui/ToolCallDiv/ToolTruncateHistoryIcon.tsx deleted file mode 100644 index e4f0a1cc8..000000000 --- a/gui/src/pages/gui/ToolCallDiv/ToolTruncateHistoryIcon.tsx +++ /dev/null @@ -1,40 +0,0 @@ -import { BarsArrowUpIcon } from "@heroicons/react/24/outline"; -import { chatMessageIsEmpty } from "core/llm/messages"; -import { findLastIndex } from "core/util/findLast"; -import { useMemo } from "react"; -import { useMainEditor } from "../../../components/mainInput/TipTapEditor"; -import { ToolbarButtonWithTooltip } from "../../../components/StyledMarkdownPreview/StepContainerPreToolbar/ToolbarButtonWithTooltip"; -import { useAppDispatch, useAppSelector } from "../../../redux/hooks"; -import { truncateHistoryToMessage } from "../../../redux/slices/sessionSlice"; - -export function ToolTruncateHistoryIcon({ - historyIndex, -}: { - historyIndex: number; -}) { - const isStreaming = useAppSelector((state) => state.session.isStreaming); - const history = useAppSelector((state) => state.session.history); - const lastMessageIndex = useMemo(() => { - return findLastIndex(history, (item) => !chatMessageIsEmpty(item.message)); - }, [history]); - const dispatch = useAppDispatch(); - const { mainEditor } = useMainEditor(); - if (isStreaming || historyIndex === lastMessageIndex) { - return null; - } - return ( - { - dispatch( - truncateHistoryToMessage({ - index: historyIndex, - }), - ); - mainEditor?.commands.focus(); - }} - > - - - ); -} diff --git a/gui/src/pages/gui/ToolCallDiv/index.tsx b/gui/src/pages/gui/ToolCallDiv/index.tsx index 4141631bb..9f867356e 100644 --- a/gui/src/pages/gui/ToolCallDiv/index.tsx +++ b/gui/src/pages/gui/ToolCallDiv/index.tsx @@ -12,7 +12,12 @@ import { PencilIcon, XMarkIcon, } from "@heroicons/react/24/outline"; -import { ToolCallDelta, ToolCallState, ToolStatus } from "core"; +import { + ContextItemWithId, + ToolCallDelta, + ToolCallState, + ToolStatus, +} from "core"; import { BuiltInToolNames } from "core/tools/builtIn"; import { ComponentType, useMemo } from "react"; import { vscButtonBackground } from "../../../components"; @@ -25,6 +30,7 @@ import { ToolCallDisplay } from "./ToolCall"; interface ToolCallDivProps { toolCall: ToolCallDelta; toolCallState: ToolCallState; + output?: ContextItemWithId[]; historyIndex: number; } @@ -80,7 +86,7 @@ export function ToolCallDiv(props: ToolCallDivProps) { icon={ props.toolCallState.status === "generated" ? ArrowRightIcon : icon } - historyIndex={props.historyIndex} + contextItems={props.output ?? []} /> ); } @@ -90,7 +96,6 @@ export function ToolCallDiv(props: ToolCallDivProps) { icon={getStatusIcon(props.toolCallState.status)} tool={tool} toolCallState={props.toolCallState} - historyIndex={props.historyIndex} > , - ) => { - const { index } = payload; - - if (state.history.length && index < state.history.length) { - state.codeBlockApplyStates.curIndex = 0; - state.history = state.history.slice(0, index + 1).concat({ - message: { - id: uuidv4(), - role: "assistant", - content: "", // IMPORTANT - this is subsequently updated by response streaming - }, - contextItems: [], - }); - } - }, submitEditorAndInitAtIndex: ( state, { @@ -733,7 +711,6 @@ export const { addPromptCompletionPair, setActive, submitEditorAndInitAtIndex, - truncateHistoryToMessage, updateHistoryItemAtIndex, clearDanglingMessages, setMainEditorContentTrigger,