Changesets · Branches · Tags · Compare
| Changeset | d22531502d6c125003967efe6f03d7f91bfd5e6ec640058efaeb8545794c6093 |
|---|---|
| Author | Patrick Erichsen <patrick.a.erichsen@gmail.com> · 2025-07-16 08:28 -07:00 |
| Committer | GitHub <noreply@github.com> · 2025-07-16 08:28 -07:00 |
| Parents | 4aa90a5da6be, f960a00a2c65 |
7 files changed
modified gui/src/pages/gui/ToolCallDiv/SimpleToolCallUI.tsx +0 −1
| @@ -89,7 +89,6 @@ | ||
| 89 | 89 | <ArgsToggleIcon |
| 90 | 90 | isShowing={showingArgs} |
| 91 | 91 | setIsShowing={setShowingArgs} |
| 92 | - toolCallId={toolCallState.toolCallId} | |
| 93 | 92 | /> |
| 94 | 93 | ) : null} |
| 95 | 94 | </div> |
deleted gui/src/pages/gui/ToolCallDiv/ToolCall.tsx +0 −66
| @@ -1,66 +0,0 @@ | ||
| 1 | -import { Tool, ToolCallState } from "core"; | |
| 2 | -import { useMemo, useState } from "react"; | |
| 3 | -import { ArgsItems, ArgsToggleIcon } from "./ToolCallArgs"; | |
| 4 | -import { ToolCallStatusMessage } from "./ToolCallStatusMessage"; | |
| 5 | -import { ToolTruncateHistoryIcon } from "./ToolTruncateHistoryIcon"; | |
| 6 | - | |
| 7 | -interface ToolCallDisplayProps { | |
| 8 | - children: React.ReactNode; | |
| 9 | - icon: React.ReactNode; | |
| 10 | - tool: Tool | undefined; | |
| 11 | - toolCallState: ToolCallState; | |
| 12 | - historyIndex: number; | |
| 13 | -} | |
| 14 | - | |
| 15 | -export function ToolCallDisplay({ | |
| 16 | - tool, | |
| 17 | - toolCallState, | |
| 18 | - children, | |
| 19 | - icon, | |
| 20 | - historyIndex, | |
| 21 | -}: ToolCallDisplayProps) { | |
| 22 | - const [argsExpanded, setArgsExpanded] = useState(false); | |
| 23 | - | |
| 24 | - const args: [string, any][] = useMemo(() => { | |
| 25 | - return Object.entries(toolCallState.parsedArgs); | |
| 26 | - }, [toolCallState.parsedArgs]); | |
| 27 | - | |
| 28 | - return ( | |
| 29 | - <> | |
| 30 | - <div className="flex flex-col justify-center p-4 pb-1"> | |
| 31 | - <div className="mb-2 flex flex-col"> | |
| 32 | - <div className="flex flex-row items-center justify-between gap-1.5"> | |
| 33 | - <div className="flex min-w-0 flex-row items-center gap-2"> | |
| 34 | - <div className="mt-[1px] h-4 w-4 flex-shrink-0 font-semibold"> | |
| 35 | - {icon} | |
| 36 | - </div> | |
| 37 | - {tool?.faviconUrl && ( | |
| 38 | - <img src={tool.faviconUrl} className="h-4 w-4 rounded-sm" /> | |
| 39 | - )} | |
| 40 | - <ToolCallStatusMessage | |
| 41 | - tool={tool} | |
| 42 | - toolCallState={toolCallState} | |
| 43 | - /> | |
| 44 | - </div> | |
| 45 | - <div className="flex flex-row items-center gap-1.5"> | |
| 46 | - {!!toolCallState.output && ( | |
| 47 | - <ToolTruncateHistoryIcon historyIndex={historyIndex} /> | |
| 48 | - )} | |
| 49 | - {!!args.length ? ( | |
| 50 | - <ArgsToggleIcon | |
| 51 | - isShowing={argsExpanded} | |
| 52 | - setIsShowing={setArgsExpanded} | |
| 53 | - toolCallId={toolCallState.toolCallId} | |
| 54 | - /> | |
| 55 | - ) : null} | |
| 56 | - </div> | |
| 57 | - </div> | |
| 58 | - {argsExpanded && !!args.length && ( | |
| 59 | - <ArgsItems args={args} isShowing={argsExpanded} /> | |
| 60 | - )} | |
| 61 | - </div> | |
| 62 | - <div>{children}</div> | |
| 63 | - </div> | |
| 64 | - </> | |
| 65 | - ); | |
| 66 | -} |
modified gui/src/pages/gui/ToolCallDiv/ToolCallArgs.tsx +0 −2
| @@ -4,13 +4,11 @@ | ||
| 4 | 4 | interface ArgsToggleIconProps { |
| 5 | 5 | isShowing: boolean; |
| 6 | 6 | setIsShowing: (val: boolean) => void; |
| 7 | - toolCallId: string; | |
| 8 | 7 | } |
| 9 | 8 | |
| 10 | 9 | export const ArgsToggleIcon = ({ |
| 11 | 10 | isShowing, |
| 12 | 11 | setIsShowing, |
| 13 | - toolCallId, | |
| 14 | 12 | }: ArgsToggleIconProps) => { |
| 15 | 13 | return ( |
| 16 | 14 | <ToolbarButtonWithTooltip |
added gui/src/pages/gui/ToolCallDiv/ToolCallDisplay.tsx +65 −0
| @@ -0,0 +1,65 @@ | ||
| 1 | +import { Tool, ToolCallState } from "core"; | |
| 2 | +import { useMemo, useState } from "react"; | |
| 3 | +import { ArgsItems, ArgsToggleIcon } from "./ToolCallArgs"; | |
| 4 | +import { ToolCallStatusMessage } from "./ToolCallStatusMessage"; | |
| 5 | +import { ToolTruncateHistoryIcon } from "./ToolTruncateHistoryIcon"; | |
| 6 | + | |
| 7 | +interface ToolCallDisplayProps { | |
| 8 | + children: React.ReactNode; | |
| 9 | + icon: React.ReactNode; | |
| 10 | + tool: Tool | undefined; | |
| 11 | + toolCallState: ToolCallState; | |
| 12 | + historyIndex: number; | |
| 13 | +} | |
| 14 | + | |
| 15 | +export function ToolCallDisplay({ | |
| 16 | + tool, | |
| 17 | + toolCallState, | |
| 18 | + children, | |
| 19 | + icon, | |
| 20 | + historyIndex, | |
| 21 | +}: ToolCallDisplayProps) { | |
| 22 | + const [argsExpanded, setArgsExpanded] = useState(false); | |
| 23 | + | |
| 24 | + const args: [string, any][] = useMemo(() => { | |
| 25 | + return Object.entries(toolCallState.parsedArgs); | |
| 26 | + }, [toolCallState.parsedArgs]); | |
| 27 | + | |
| 28 | + return ( | |
| 29 | + <> | |
| 30 | + <div className="flex flex-col justify-center"> | |
| 31 | + <div className="mb-2 flex flex-col"> | |
| 32 | + <div className="flex flex-row items-center justify-between gap-1.5"> | |
| 33 | + <div className="flex min-w-0 flex-row items-center gap-2"> | |
| 34 | + <div className="mt-[1px] h-4 w-4 flex-shrink-0 font-semibold"> | |
| 35 | + {icon} | |
| 36 | + </div> | |
| 37 | + {tool?.faviconUrl && ( | |
| 38 | + <img src={tool.faviconUrl} className="h-4 w-4 rounded-sm" /> | |
| 39 | + )} | |
| 40 | + <ToolCallStatusMessage | |
| 41 | + tool={tool} | |
| 42 | + toolCallState={toolCallState} | |
| 43 | + /> | |
| 44 | + </div> | |
| 45 | + <div className="flex flex-row items-center gap-1.5"> | |
| 46 | + {!!toolCallState.output && ( | |
| 47 | + <ToolTruncateHistoryIcon historyIndex={historyIndex} /> | |
| 48 | + )} | |
| 49 | + {!!args.length ? ( | |
| 50 | + <ArgsToggleIcon | |
| 51 | + isShowing={argsExpanded} | |
| 52 | + setIsShowing={setArgsExpanded} | |
| 53 | + /> | |
| 54 | + ) : null} | |
| 55 | + </div> | |
| 56 | + </div> | |
| 57 | + {argsExpanded && !!args.length && ( | |
| 58 | + <ArgsItems args={args} isShowing={argsExpanded} /> | |
| 59 | + )} | |
| 60 | + </div> | |
| 61 | + <div>{children}</div> | |
| 62 | + </div> | |
| 63 | + </> | |
| 64 | + ); | |
| 65 | +} |
modified gui/src/pages/gui/ToolCallDiv/ToolCallStatusMessage.tsx +1 −1
| @@ -53,7 +53,7 @@ | ||
| 53 | 53 | |
| 54 | 54 | return ( |
| 55 | 55 | <div |
| 56 | - className="text-description line-clamp-4 min-w-0 break-words" | |
| 56 | + className="text-description line-clamp-4 min-w-0 break-all" | |
| 57 | 57 | data-testid="tool-call-title" |
| 58 | 58 | > |
| 59 | 59 | {`Continue ${intro} ${message}`} |
modified gui/src/pages/gui/ToolCallDiv/index.tsx +2 −5
| @@ -6,7 +6,7 @@ | ||
| 6 | 6 | import FunctionSpecificToolCallDiv from "./FunctionSpecificToolCallDiv"; |
| 7 | 7 | import { GroupedToolCallHeader } from "./GroupedToolCallHeader"; |
| 8 | 8 | import { SimpleToolCallUI } from "./SimpleToolCallUI"; |
| 9 | -import { ToolCallDisplay } from "./ToolCall"; | |
| 9 | +import { ToolCallDisplay } from "./ToolCallDisplay"; | |
| 10 | 10 | import { getStatusIcon, toolCallIcons } from "./utils"; |
| 11 | 11 | |
| 12 | 12 | interface ToolCallDivProps { |
| @@ -103,10 +103,7 @@ | ||
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | return toolCallStates.map((toolCallState) => ( |
| 106 | - <div | |
| 107 | - className="border-border rounded-lg border p-3" | |
| 108 | - key={toolCallState.toolCallId} | |
| 109 | - > | |
| 106 | + <div className="p-4 pb-1" key={toolCallState.toolCallId}> | |
| 110 | 107 | {renderToolCall(toolCallState)} |
| 111 | 108 | </div> |
| 112 | 109 | )); |
modified gui/src/redux/thunks/streamResponseAfterToolCall.ts +21 −63
| @@ -2,80 +2,32 @@ | ||
| 2 | 2 | import { ChatMessage } from "core"; |
| 3 | 3 | import { renderContextItems } from "core/util/messageContent"; |
| 4 | 4 | import { |
| 5 | + ChatHistoryItemWithMessageId, | |
| 5 | 6 | resetNextCodeBlockToApplyIndex, |
| 6 | 7 | streamUpdate, |
| 7 | 8 | } from "../slices/sessionSlice"; |
| 8 | -import { AppThunkDispatch, RootState, ThunkApiType } from "../store"; | |
| 9 | +import { ThunkApiType } from "../store"; | |
| 9 | 10 | import { findToolCallById } from "../util"; |
| 10 | 11 | import { streamNormalInput } from "./streamNormalInput"; |
| 11 | 12 | import { streamThunkWrapper } from "./streamThunkWrapper"; |
| 12 | 13 | |
| 13 | -/** | |
| 14 | - * Finds the assistant message that contains the specified tool call. | |
| 15 | - */ | |
| 16 | -function findAssistantMessageWithToolCall( | |
| 17 | - history: RootState["session"]["history"], | |
| 18 | - toolCallId: string, | |
| 19 | -) { | |
| 20 | - return history.find( | |
| 21 | - (item) => | |
| 22 | - item.message.role === "assistant" && | |
| 23 | - item.toolCallStates?.some((tc) => tc.toolCallId === toolCallId), | |
| 24 | - ); | |
| 25 | -} | |
| 26 | - | |
| 27 | -/** | |
| 28 | - * Checks if all parallel tool calls in an assistant message are complete. | |
| 29 | - */ | |
| 30 | -function areAllToolCallsComplete( | |
| 31 | - toolCallStates: NonNullable< | |
| 32 | - ReturnType<typeof findAssistantMessageWithToolCall> | |
| 33 | - >["toolCallStates"], | |
| 34 | -): boolean { | |
| 35 | - if (!toolCallStates) return false; | |
| 36 | - | |
| 37 | - const completedToolCalls = toolCallStates.filter( | |
| 38 | - (tc) => tc.status === "done", | |
| 39 | - ); | |
| 40 | - | |
| 41 | - return completedToolCalls.length === toolCallStates.length; | |
| 42 | -} | |
| 43 | - | |
| 44 | 14 | /** |
| 45 | 15 | * Determines if we should continue streaming based on tool call completion status. |
| 46 | 16 | */ |
| 47 | -function shouldContinueStreaming( | |
| 48 | - assistantMessage: ReturnType<typeof findAssistantMessageWithToolCall>, | |
| 17 | +function areAllToolsDoneStreaming( | |
| 18 | + assistantMessage: ChatHistoryItemWithMessageId | undefined, | |
| 49 | 19 | ): boolean { |
| 20 | + // This might occur because of race conditions, if so, the tools are completed | |
| 50 | 21 | if (!assistantMessage?.toolCallStates) { |
| 51 | - return false; // No assistant message found - don't stream | |
| 52 | - } | |
| 53 | - | |
| 54 | - const totalToolCalls = assistantMessage.toolCallStates.length; | |
| 55 | - | |
| 56 | - // Single tool call - always continue streaming | |
| 57 | - if (totalToolCalls === 1) { | |
| 58 | 22 | return true; |
| 59 | 23 | } |
| 60 | 24 | |
| 61 | - // Multiple tool calls - only continue if all are complete | |
| 62 | - return areAllToolCallsComplete(assistantMessage.toolCallStates); | |
| 63 | -} | |
| 25 | + // Only continue if all tool calls are complete | |
| 26 | + const completedToolCalls = assistantMessage.toolCallStates.filter( | |
| 27 | + (tc) => tc.status === "done", | |
| 28 | + ); | |
| 64 | 29 | |
| 65 | -/** | |
| 66 | - * Creates and dispatches a tool message for the completed tool call. | |
| 67 | - */ | |
| 68 | -function createAndDispatchToolMessage( | |
| 69 | - dispatch: AppThunkDispatch, | |
| 70 | - toolCallId: string, | |
| 71 | - toolOutput: any[], | |
| 72 | -): void { | |
| 73 | - const newMessage: ChatMessage = { | |
| 74 | - role: "tool", | |
| 75 | - content: renderContextItems(toolOutput), | |
| 76 | - toolCallId, | |
| 77 | - }; | |
| 78 | - dispatch(streamUpdate([newMessage])); | |
| 30 | + return completedToolCalls.length === assistantMessage.toolCallStates.length; | |
| 79 | 31 | } |
| 80 | 32 | |
| 81 | 33 | export const streamResponseAfterToolCall = createAsyncThunk< |
| @@ -104,16 +56,22 @@ | ||
| 104 | 56 | await new Promise((resolve) => setTimeout(resolve, 0)); |
| 105 | 57 | |
| 106 | 58 | // Create and dispatch the tool message |
| 107 | - createAndDispatchToolMessage(dispatch, toolCallId, toolOutput); | |
| 59 | + const newMessage: ChatMessage = { | |
| 60 | + role: "tool", | |
| 61 | + content: renderContextItems(toolOutput), | |
| 62 | + toolCallId, | |
| 63 | + }; | |
| 64 | + dispatch(streamUpdate([newMessage])); | |
| 108 | 65 | |
| 109 | 66 | // Check if we should continue streaming based on tool call completion |
| 110 | 67 | const history = getState().session.history; |
| 111 | - const assistantMessage = findAssistantMessageWithToolCall( | |
| 112 | - history, | |
| 113 | - toolCallId, | |
| 68 | + const assistantMessage = history.find( | |
| 69 | + (item) => | |
| 70 | + item.message.role === "assistant" && | |
| 71 | + item.toolCallStates?.some((tc) => tc.toolCallId === toolCallId), | |
| 114 | 72 | ); |
| 115 | 73 | |
| 116 | - if (shouldContinueStreaming(assistantMessage)) { | |
| 74 | + if (areAllToolsDoneStreaming(assistantMessage)) { | |
| 117 | 75 | unwrapResult(await dispatch(streamNormalInput({}))); |
| 118 | 76 | } |
| 119 | 77 | }), |