From b1ed13f19a6c9c50b84e8014a0d446490e392c83 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 24 Apr 2025 17:15:54 -0700 Subject: [PATCH 1/4] WIP: invert apply toolcall state approach --- core/index.d.ts | 6 ++- gui/src/hooks/useSetup.ts | 49 +++++++++---------- .../redux/selectors/selectCurrentToolCall.ts | 17 +++++++ gui/src/redux/slices/sessionSlice.ts | 24 --------- gui/src/redux/thunks/callCurrentTool.ts | 5 +- gui/src/util/clientTools/callClientTool.ts | 2 +- gui/src/util/clientTools/editImpl.ts | 8 +-- 7 files changed, 55 insertions(+), 56 deletions(-) diff --git a/core/index.d.ts b/core/index.d.ts index 877f308ae..b1e78f70c 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -1,4 +1,8 @@ -import { DataDestination, ModelRole, PromptTemplates } from "@continuedev/config-yaml"; +import { + DataDestination, + ModelRole, + PromptTemplates, +} from "@continuedev/config-yaml"; import Parser from "web-tree-sitter"; import { LLMConfigurationStatuses } from "./llm/constants"; import { GetGhTokenArgs } from "./protocol/ide"; diff --git a/gui/src/hooks/useSetup.ts b/gui/src/hooks/useSetup.ts index 6f9b8c7ac..98ba3c5cf 100644 --- a/gui/src/hooks/useSetup.ts +++ b/gui/src/hooks/useSetup.ts @@ -10,6 +10,7 @@ import { setSelectedProfile, } from "../redux"; import { useAppDispatch, useAppSelector } from "../redux/hooks"; +import { selectCurrentToolCallApplyState } from "../redux/selectors/selectCurrentToolCall"; import { selectSelectedChatModel, setConfigResult, @@ -252,41 +253,39 @@ function useSetup() { dispatch(updateIndexingStatus(data)); }); - const activeToolStreamId = useAppSelector( - (store) => store.session.activeToolStreamId, + const currentToolCallApplyState = useAppSelector( + selectCurrentToolCallApplyState, ); useWebviewListener( "updateApplyState", async (state) => { dispatch(updateApplyState(state)); - const lastHistoryMsg = history.at(-1); - const [streamId, toolCallId] = activeToolStreamId ?? []; + + // Handle apply status updates that are associated with current tool call if ( - toolCallId && state.status === "closed" && - lastHistoryMsg?.toolCallState?.toolCallId === toolCallId + currentToolCallApplyState && + currentToolCallApplyState.streamId === state.streamId ) { - if (state.streamId === streamId) { - // const output: ContextItem = { - // name: "Edit tool output", - // content: "Completed edit", - // description: "", - // }; - dispatch( - acceptToolCall({ - toolCallId, - }), - ); - // dispatch(setToolCallOutput([])); - dispatch( - streamResponseAfterToolCall({ - toolCallId, - }), - ); - } + // const output: ContextItem = { + // name: "Edit tool output", + // content: "Completed edit", + // description: "", + // }; + dispatch( + acceptToolCall({ + toolCallId: currentToolCallApplyState.toolCallId!, + }), + ); + // dispatch(setToolCallOutput([])); + dispatch( + streamResponseAfterToolCall({ + toolCallId: currentToolCallApplyState.toolCallId!, + }), + ); } }, - [activeToolStreamId, history], + [currentToolCallApplyState, history], ); } diff --git a/gui/src/redux/selectors/selectCurrentToolCall.ts b/gui/src/redux/selectors/selectCurrentToolCall.ts index eb0bf669b..56c3a6cc1 100644 --- a/gui/src/redux/selectors/selectCurrentToolCall.ts +++ b/gui/src/redux/selectors/selectCurrentToolCall.ts @@ -8,3 +8,20 @@ export const selectCurrentToolCall = createSelector( return findCurrentToolCall(history); }, ); + +export const selectCurrentToolCallApplyState = createSelector( + [ + (store: RootState) => store.session.history, + (store: RootState) => store.session.codeBlockApplyStates, + ], + (history, applyStates) => { + const currentToolCall = findCurrentToolCall(history); + if (!currentToolCall) { + return undefined; + } + return applyStates.states.find( + (state) => + state.toolCallId && state.toolCallId === currentToolCall.toolCallId, + ); + }, +); diff --git a/gui/src/redux/slices/sessionSlice.ts b/gui/src/redux/slices/sessionSlice.ts index 002b809db..50b34d485 100644 --- a/gui/src/redux/slices/sessionSlice.ts +++ b/gui/src/redux/slices/sessionSlice.ts @@ -21,7 +21,6 @@ import { ToolCallDelta, ToolCallState, } from "core"; -import { BuiltInToolNames } from "core/tools/builtIn"; import { NEW_SESSION_TITLE } from "core/util/constants"; import { incrementalParseJson } from "core/util/incrementalParseJson"; import { renderChatMessage } from "core/util/messageContent"; @@ -54,7 +53,6 @@ type SessionState = { states: ApplyState[]; curIndex: number; }; - activeToolStreamId?: [string, string]; newestToolbarPreviewForInput: Record; }; @@ -368,19 +366,6 @@ export const sessionSlice = createSlice({ ); } - if ( - toolCallDelta.id && - toolCallDelta.function?.name === - BuiltInToolNames.EditExistingFile - ) { - const streamId = uuidv4(); - state.codeBlockApplyStates.states.push({ - streamId, - toolCallId: toolCallDelta.id, - status: "streaming", - }); - state.activeToolStreamId = [streamId, toolCallDelta.id]; - } historyItem.toolCallState = toolCallDeltaToState(toolCallDelta); } state.history.push(historyItem); @@ -660,9 +645,6 @@ export const sessionSlice = createSlice({ toolCallId: string; }>, ) => { - if (action.payload.toolCallId === state.activeToolStreamId?.[1]) { - state.activeToolStreamId = undefined; - } const toolCallState = findToolCall( state.history, action.payload.toolCallId, @@ -677,9 +659,6 @@ export const sessionSlice = createSlice({ toolCallId: string; }>, ) => { - if (action.payload.toolCallId === state.activeToolStreamId?.[1]) { - state.activeToolStreamId = undefined; - } const toolCallState = findToolCall( state.history, action.payload.toolCallId, @@ -694,9 +673,6 @@ export const sessionSlice = createSlice({ toolCallId: string; }>, ) => { - if (action.payload.toolCallId === state.activeToolStreamId?.[1]) { - state.activeToolStreamId = undefined; - } const toolCallState = findToolCall( state.history, action.payload.toolCallId, diff --git a/gui/src/redux/thunks/callCurrentTool.ts b/gui/src/redux/thunks/callCurrentTool.ts index 61795de96..4f6eba622 100644 --- a/gui/src/redux/thunks/callCurrentTool.ts +++ b/gui/src/redux/thunks/callCurrentTool.ts @@ -63,7 +63,10 @@ export const callCurrentTool = createAsyncThunk( } = await callClientTool(toolCallState.toolCall, { dispatch, ideMessenger: extra.ideMessenger, - activeToolStreamId: state.session.activeToolStreamId?.[0], + streamId: state.session.codeBlockApplyStates.states.find( + (state) => + state.toolCallId && state.toolCallId === toolCallState.toolCallId, + )?.streamId, }); output = clientToolOuput; errorMessage = clientToolError; diff --git a/gui/src/util/clientTools/callClientTool.ts b/gui/src/util/clientTools/callClientTool.ts index 6d451fe7e..56665f03f 100644 --- a/gui/src/util/clientTools/callClientTool.ts +++ b/gui/src/util/clientTools/callClientTool.ts @@ -7,7 +7,7 @@ import { editToolImpl } from "./editImpl"; export interface ClientToolExtras { dispatch: AppThunkDispatch; ideMessenger: IIdeMessenger; - activeToolStreamId?: string; + streamId?: string; } export interface ClientToolOutput { diff --git a/gui/src/util/clientTools/editImpl.ts b/gui/src/util/clientTools/editImpl.ts index 2a6d3e1d4..592c410d8 100644 --- a/gui/src/util/clientTools/editImpl.ts +++ b/gui/src/util/clientTools/editImpl.ts @@ -7,7 +7,7 @@ export const editToolImpl: ClientToolImpl = async ( toolCallId, extras, ) => { - if (!extras.activeToolStreamId) { + if (!extras.streamId) { throw new Error("Invalid apply state"); } const firstUriMatch = await resolveRelativePathInDir( @@ -18,7 +18,7 @@ export const editToolImpl: ClientToolImpl = async ( throw new Error(`${args.filepath} does not exist`); } const apply = await extras.ideMessenger.request("applyToFile", { - streamId: extras.activeToolStreamId, + streamId: extras.streamId, text: args.new_contents, toolCallId, filepath: firstUriMatch, @@ -26,10 +26,10 @@ export const editToolImpl: ClientToolImpl = async ( if (apply.status === "error") { throw new Error(apply.error); } - if (extras.activeToolStreamId) { + if (extras.streamId) { extras.dispatch( updateApplyState({ - streamId: extras.activeToolStreamId, + streamId: extras.streamId, status: "closed", toolCallId, numDiffs: 0, From 275e116d9c2f028f3c812d2b5b935f7be9ac27df Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 24 Apr 2025 18:21:22 -0700 Subject: [PATCH 2/4] WIP: edit tool fixes --- core/index.d.ts | 1 + .../StepContainerPreToolbar/ApplyActions.tsx | 18 ++++++--- .../StepContainerPreToolbar/index.tsx | 7 +++- .../StyledMarkdownPreview/index.tsx | 16 ++++---- gui/src/components/mainInput/InputToolbar.tsx | 11 ++++-- gui/src/pages/gui/Chat.tsx | 5 ++- gui/src/pages/gui/ToolCallDiv/CreateFile.tsx | 2 + gui/src/pages/gui/ToolCallDiv/EditFile.tsx | 37 ++++++++++++++----- .../FunctionSpecificToolCallDiv.tsx | 4 ++ gui/src/pages/gui/ToolCallDiv/index.tsx | 2 + gui/src/redux/slices/sessionSlice.ts | 12 +++++- gui/src/util/clientTools/editImpl.ts | 2 +- 12 files changed, 86 insertions(+), 31 deletions(-) diff --git a/core/index.d.ts b/core/index.d.ts index b1e78f70c..9fa0245b5 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -1216,6 +1216,7 @@ export type EditStatus = | "done"; export type ApplyStateStatus = + | "not-started" // Apply state created but not necessarily streaming | "streaming" // Changes are being applied to the file | "done" // All changes have been applied, awaiting user to accept/reject | "closed"; // All changes have been applied. Note that for new files, we immediately set the status to "closed" diff --git a/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/ApplyActions.tsx b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/ApplyActions.tsx index 0c1c8c7d0..76d51476d 100644 --- a/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/ApplyActions.tsx +++ b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/ApplyActions.tsx @@ -47,7 +47,18 @@ export function ApplyActions(props: ApplyActionsProps) { ); + console.log(props.applyState); + switch (props.applyState ? props.applyState.status : null) { + case "not-started": + return ( +
+ + Pending + + +
+ ); case "streaming": return (
@@ -84,8 +95,8 @@ export function ApplyActions(props: ApplyActionsProps) {
); case "closed": - if (!hasRejected && props.applyState?.numDiffs === 0) { - if (showApplied) { + if (isSuccessful) { + if (showApplied || props.disableManualApply) { return ( Applied @@ -93,9 +104,6 @@ export function ApplyActions(props: ApplyActionsProps) { ); } - if (props.disableManualApply) { - return null; - } return applyButton("Reapply"); } default: diff --git a/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.tsx b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.tsx index 202d87972..8625c1b62 100644 --- a/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.tsx +++ b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.tsx @@ -217,7 +217,12 @@ export function StepContainerPreToolbar({ }); } } - + console.log( + isLoadingFileExists, + fileExists, + relativeFilepath, + isGeneratingCodeBlock, + ); const renderActionButtons = () => { if (isTerminalCodeBlock(language, codeBlockContent)) { return ; diff --git a/gui/src/components/StyledMarkdownPreview/index.tsx b/gui/src/components/StyledMarkdownPreview/index.tsx index 1cab75874..913f7d753 100644 --- a/gui/src/components/StyledMarkdownPreview/index.tsx +++ b/gui/src/components/StyledMarkdownPreview/index.tsx @@ -126,7 +126,7 @@ interface StyledMarkdownPreviewProps { itemIndex?: number; useParentBackgroundColor?: boolean; disableManualApply?: boolean; - singleCodeblockStreamId?: string; + forceStreamId?: string; expandCodeblocks?: boolean; } @@ -195,7 +195,7 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview( const pastFileInfoRef = useUpdatingRef(pastFileInfo); const isLastItem = useMemo(() => { - return props.itemIndex && props.itemIndex === history.length - 1; + return props.itemIndex === history.length - 1; }, [history.length, props.itemIndex]); const isLastItemRef = useUpdatingRef(isLastItem); @@ -207,15 +207,15 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview( ); useEffect(() => { - if (props.singleCodeblockStreamId) { + if (props.forceStreamId) { codeblockState.current = [ { - streamId: props.singleCodeblockStreamId, + streamId: props.forceStreamId, isGenerating: false, }, ]; } - }, [props.singleCodeblockStreamId]); + }, [props.forceStreamId]); const [reactContent, setMarkdownSource] = useRemark({ remarkPlugins: [ @@ -317,7 +317,7 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview( if (codeblockState.current[codeBlockIndex] === undefined) { codeblockState.current[codeBlockIndex] = { - streamId: uuidv4(), + streamId: props.forceStreamId ?? uuidv4(), isGenerating: isGeneratingCodeBlock, }; } else { @@ -325,6 +325,8 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview( isGeneratingCodeBlock; } + console.log(props.forceStreamId); + return ( store.session.activeToolStreamId, + const currentToolCallApplyState = useAppSelector( + selectCurrentToolCallApplyState, ); const isEnterDisabled = props.disabled || isEditModeAndNoCodeToEdit || toolCallState?.status === "generated" || - !!activeToolCallStreamId; + currentToolCallApplyState?.status !== "closed"; const toolsSupported = defaultModel && modelSupportsTools(defaultModel); diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx index 284f4f8cc..32caeb2fc 100644 --- a/gui/src/pages/gui/Chat.tsx +++ b/gui/src/pages/gui/Chat.tsx @@ -339,8 +339,8 @@ export function Chat() { inputId={item.message.id} /> - ) : item.message.role === "tool" ? null : // /> // toolCallId={item.message.toolCallId} // contextItems={item.contextItems} // // toolCallId={item.message.toolCallId} // contextItems={item.contextItems} // @@ -351,6 +351,7 @@ export function Chat() { toolCallState={item.toolCallState!} toolCall={toolCall} output={history[index + 1]?.contextItems} + historyIndex={index} /> ); diff --git a/gui/src/pages/gui/ToolCallDiv/CreateFile.tsx b/gui/src/pages/gui/ToolCallDiv/CreateFile.tsx index 7e50b7305..a3e81355b 100644 --- a/gui/src/pages/gui/ToolCallDiv/CreateFile.tsx +++ b/gui/src/pages/gui/ToolCallDiv/CreateFile.tsx @@ -4,6 +4,7 @@ import StyledMarkdownPreview from "../../../components/StyledMarkdownPreview"; interface CreateFileToolCallProps { relativeFilepath: string; fileContents: string; + historyIndex: number; } export function CreateFile(props: CreateFileToolCallProps) { @@ -14,6 +15,7 @@ export function CreateFile(props: CreateFileToolCallProps) { isRenderingInStepContainer disableManualApply source={src} + itemIndex={props.historyIndex} /> ) : null; } diff --git a/gui/src/pages/gui/ToolCallDiv/EditFile.tsx b/gui/src/pages/gui/ToolCallDiv/EditFile.tsx index 304dcb4c7..0ed988497 100644 --- a/gui/src/pages/gui/ToolCallDiv/EditFile.tsx +++ b/gui/src/pages/gui/ToolCallDiv/EditFile.tsx @@ -1,39 +1,56 @@ import { getMarkdownLanguageTagForFile } from "core/util"; -import { useMemo } from "react"; +import { useEffect } from "react"; +import { v4 as uuidv4 } from "uuid"; import AcceptRejectAllButtons from "../../../components/AcceptRejectAllButtons"; import StyledMarkdownPreview from "../../../components/StyledMarkdownPreview"; -import { useAppSelector } from "../../../redux/hooks"; +import { useAppDispatch, useAppSelector } from "../../../redux/hooks"; +import { + selectApplyStateByToolCallId, + updateApplyState, +} from "../../../redux/slices/sessionSlice"; type EditToolCallProps = { relativeFilePath: string; newContents: string; toolCallId?: string; + historyIndex: number; }; export function EditFile(props: EditToolCallProps) { const src = `\`\`\`${getMarkdownLanguageTagForFile(props.relativeFilePath ?? "test.txt")} ${props.relativeFilePath}\n${props.newContents ?? ""}\n\`\`\``; + const dispatch = useAppDispatch(); const isStreaming = useAppSelector((state) => state.session.isStreaming); - const states = useAppSelector((store) => store.session.codeBlockApplyStates); - - const applyState = useMemo(() => { - return states.states.find( - (state) => state.toolCallId && state.toolCallId === props.toolCallId, - ); - }, [states, props.toolCallId]); + const applyState = useAppSelector((state) => + selectApplyStateByToolCallId(state, props.toolCallId), + ); + useEffect(() => { + if (!applyState) { + dispatch( + updateApplyState({ + streamId: uuidv4(), + toolCallId: props.toolCallId, + status: "not-started", + }), + ); + } + }, [applyState, props.toolCallId]); if (!props.relativeFilePath) { return null; } + console.log("APPLY STATE", applyState); + return ( <> {/* TODO better indicator of generation at bottom */} {/* {isStreaming && applyState?.status === "streaming" && ( diff --git a/gui/src/pages/gui/ToolCallDiv/FunctionSpecificToolCallDiv.tsx b/gui/src/pages/gui/ToolCallDiv/FunctionSpecificToolCallDiv.tsx index d9906794e..88bf4a76f 100644 --- a/gui/src/pages/gui/ToolCallDiv/FunctionSpecificToolCallDiv.tsx +++ b/gui/src/pages/gui/ToolCallDiv/FunctionSpecificToolCallDiv.tsx @@ -7,9 +7,11 @@ import { RunTerminalCommand } from "./RunTerminalCommand"; function FunctionSpecificToolCallDiv({ toolCall, toolCallState, + historyIndex, }: { toolCall: ToolCallDelta; toolCallState: ToolCallState; + historyIndex: number; }) { const args = toolCallState.parsedArgs; @@ -19,6 +21,7 @@ function FunctionSpecificToolCallDiv({ ); case BuiltInToolNames.EditExistingFile: @@ -27,6 +30,7 @@ function FunctionSpecificToolCallDiv({ relativeFilePath={args.filepath} newContents={args.new_contents} toolCallId={toolCall.id} + historyIndex={historyIndex} /> ); case BuiltInToolNames.RunTerminalCommand: diff --git a/gui/src/pages/gui/ToolCallDiv/index.tsx b/gui/src/pages/gui/ToolCallDiv/index.tsx index 19bb13c02..5fd016d45 100644 --- a/gui/src/pages/gui/ToolCallDiv/index.tsx +++ b/gui/src/pages/gui/ToolCallDiv/index.tsx @@ -31,6 +31,7 @@ interface ToolCallDivProps { toolCall: ToolCallDelta; toolCallState: ToolCallState; output?: ContextItemWithId[]; + historyIndex: number; } const toolCallIcons: Record = { @@ -100,6 +101,7 @@ export function ToolCallDiv(props: ToolCallDivProps) { ); diff --git a/gui/src/redux/slices/sessionSlice.ts b/gui/src/redux/slices/sessionSlice.ts index 50b34d485..3b3d65c32 100644 --- a/gui/src/redux/slices/sessionSlice.ts +++ b/gui/src/redux/slices/sessionSlice.ts @@ -355,7 +355,7 @@ export const sessionSlice = createSlice({ if ( !( toolCallDelta.id && - toolCallDelta.function?.arguments && + toolCallDelta.function?.arguments !== undefined && toolCallDelta.function?.name && toolCallDelta.type ) @@ -782,6 +782,16 @@ export const selectApplyStateByStreamId = createSelector( }, ); +export const selectApplyStateByToolCallId = createSelector( + [ + (state: RootState) => state.session.codeBlockApplyStates.states, + (state: RootState, toolCallId?: string) => toolCallId, + ], + (states, toolCallId) => { + return states.find((state) => state.toolCallId === toolCallId); + }, +); + export const { updateFileSymbols, setContextItemsAtIndex, diff --git a/gui/src/util/clientTools/editImpl.ts b/gui/src/util/clientTools/editImpl.ts index 592c410d8..0d1ac4445 100644 --- a/gui/src/util/clientTools/editImpl.ts +++ b/gui/src/util/clientTools/editImpl.ts @@ -30,7 +30,7 @@ export const editToolImpl: ClientToolImpl = async ( extras.dispatch( updateApplyState({ streamId: extras.streamId, - status: "closed", + status: "done", toolCallId, numDiffs: 0, filepath: args.filepath, From d68deaf6fc9dff33ddfe016263397bb0f9b93739 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 24 Apr 2025 21:16:05 -0700 Subject: [PATCH 3/4] fix edit tool --- extensions/vscode/package-lock.json | 4 +- .../StepContainerPreToolbar/ApplyActions.tsx | 3 -- .../GeneratingCodeLoader.tsx | 6 ++- .../StepContainerPreToolbar/index.tsx | 35 ++++++++-------- .../StyledMarkdownPreview/index.tsx | 42 +++++-------------- .../components/mainInput/Lump/LumpToolbar.tsx | 4 +- gui/src/pages/gui/Chat.tsx | 17 +++++++- gui/src/pages/gui/ToolCallDiv/EditFile.tsx | 2 - gui/src/redux/thunks/callCurrentTool.ts | 1 + gui/src/util/clientTools/callClientTool.ts | 3 +- gui/src/util/clientTools/editImpl.ts | 13 +----- 11 files changed, 57 insertions(+), 73 deletions(-) diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index 7cf0b9dd7..22390e25e 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "continue", - "version": "1.1.24", + "version": "1.1.26", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "continue", - "version": "1.1.24", + "version": "1.1.26", "license": "Apache-2.0", "dependencies": { "@continuedev/fetch": "^1.0.3", diff --git a/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/ApplyActions.tsx b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/ApplyActions.tsx index 76d51476d..17bbc5802 100644 --- a/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/ApplyActions.tsx +++ b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/ApplyActions.tsx @@ -47,15 +47,12 @@ export function ApplyActions(props: ApplyActionsProps) { ); - console.log(props.applyState); - switch (props.applyState ? props.applyState.status : null) { case "not-started": return (
Pending -
); diff --git a/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/GeneratingCodeLoader.tsx b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/GeneratingCodeLoader.tsx index b730b30e5..28e13e5b3 100644 --- a/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/GeneratingCodeLoader.tsx +++ b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/GeneratingCodeLoader.tsx @@ -3,22 +3,24 @@ import Spinner from "../../gui/Spinner"; export interface GeneratingCodeLoaderProps { showLineCount: boolean; codeBlockContent: string; + isPending: boolean; } export function GeneratingCodeLoader({ showLineCount, codeBlockContent, + isPending, }: GeneratingCodeLoaderProps) { const numLinesCodeBlock = codeBlockContent.split("\n").length; const linesGeneratedText = numLinesCodeBlock === 1 ? `1 line generated` - : `${numLinesCodeBlock} lines generated`; + : `${numLinesCodeBlock} lines ${isPending ? "pending" : "generated"}`; return ( {showLineCount ? linesGeneratedText : "Generating"} - + {!isPending && } ); } diff --git a/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.tsx b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.tsx index 8625c1b62..c56ba099c 100644 --- a/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.tsx +++ b/gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.tsx @@ -52,7 +52,7 @@ export interface StepContainerPreToolbarProps { codeBlockContent: string; language: string | null; relativeFilepath?: string; - isGeneratingCodeBlock: boolean; + isFinalCodeblock: boolean; codeBlockIndex: number; // To track which codeblock we are applying codeBlockStreamId: string; range?: string; @@ -65,7 +65,7 @@ export function StepContainerPreToolbar({ codeBlockContent, language, relativeFilepath, - isGeneratingCodeBlock, + isFinalCodeblock, codeBlockIndex, codeBlockStreamId, range, @@ -115,6 +115,9 @@ export function StepContainerPreToolbar({ const hasFileExtension = relativeFilepath && /\.[0-9a-z]+$/i.test(relativeFilepath); + const isStreaming = useAppSelector((store) => store.session.isStreaming); + const isGeneratingCodeBlock = isFinalCodeblock && isStreaming; + // If we are creating a file, we already render that in the button // so we don't want to dispaly it twice here const displayFilepath = relativeFilepath ?? appliedFileUri; @@ -217,12 +220,7 @@ export function StepContainerPreToolbar({ }); } } - console.log( - isLoadingFileExists, - fileExists, - relativeFilepath, - isGeneratingCodeBlock, - ); + const renderActionButtons = () => { if (isTerminalCodeBlock(language, codeBlockContent)) { return ; @@ -277,20 +275,23 @@ export function StepContainerPreToolbar({
- {isGeneratingCodeBlock ? ( + {!isGeneratingCodeBlock && ( +
+ + +
+ )} + + {isGeneratingCodeBlock || applyState?.status === "not-started" ? ( ) : ( - <> -
- - -
- - {renderActionButtons()} - + renderActionButtons() )}
diff --git a/gui/src/components/StyledMarkdownPreview/index.tsx b/gui/src/components/StyledMarkdownPreview/index.tsx index 913f7d753..36700cf46 100644 --- a/gui/src/components/StyledMarkdownPreview/index.tsx +++ b/gui/src/components/StyledMarkdownPreview/index.tsx @@ -199,23 +199,12 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview( }, [history.length, props.itemIndex]); const isLastItemRef = useUpdatingRef(isLastItem); - const isStreaming = useAppSelector((store) => store.session.isStreaming); - const isStreamingRef = useUpdatingRef(isStreaming); - - const codeblockState = useRef<{ streamId: string; isGenerating: boolean }[]>( - [], - ); - + const codeblockStreamIds = useRef([]); useEffect(() => { if (props.forceStreamId) { - codeblockState.current = [ - { - streamId: props.forceStreamId, - isGenerating: false, - }, - ]; + codeblockStreamIds.current = [props.forceStreamId]; } - }, [props.forceStreamId]); + }, [props.forceStreamId, codeblockStreamIds]); const [reactContent, setMarkdownSource] = useRemark({ remarkPlugins: [ @@ -310,34 +299,23 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview( const language = getLanguageFromClassName(className); - const isGeneratingCodeBlock = - preChildProps["data-islastcodeblock"] && - isLastItemRef.current && - isStreamingRef.current; + const isFinalCodeblock = + preChildProps["data-islastcodeblock"] && isLastItemRef.current; - if (codeblockState.current[codeBlockIndex] === undefined) { - codeblockState.current[codeBlockIndex] = { - streamId: props.forceStreamId ?? uuidv4(), - isGenerating: isGeneratingCodeBlock, - }; - } else { - codeblockState.current[codeBlockIndex].isGenerating = - isGeneratingCodeBlock; + if (codeblockStreamIds.current[codeBlockIndex] === undefined) { + codeblockStreamIds.current[codeBlockIndex] = + props.forceStreamId ?? uuidv4(); } - console.log(props.forceStreamId); - return ( diff --git a/gui/src/components/mainInput/Lump/LumpToolbar.tsx b/gui/src/components/mainInput/Lump/LumpToolbar.tsx index f2e0d8c6f..70425436a 100644 --- a/gui/src/components/mainInput/Lump/LumpToolbar.tsx +++ b/gui/src/components/mainInput/Lump/LumpToolbar.tsx @@ -101,7 +101,9 @@ export function LumpToolbar() { if (toolCallState?.status === "generated") { return ( - +
+ Pending tool call +
( (state) => state.toolCallId && state.toolCallId === toolCallState.toolCallId, )?.streamId, + getState, }); output = clientToolOuput; errorMessage = clientToolError; diff --git a/gui/src/util/clientTools/callClientTool.ts b/gui/src/util/clientTools/callClientTool.ts index 56665f03f..65f11fbf6 100644 --- a/gui/src/util/clientTools/callClientTool.ts +++ b/gui/src/util/clientTools/callClientTool.ts @@ -1,10 +1,11 @@ import { ContextItem, ToolCall } from "core"; import { BuiltInToolNames } from "core/tools/builtIn"; import { IIdeMessenger } from "../../context/IdeMessenger"; -import { AppThunkDispatch } from "../../redux/store"; +import { AppThunkDispatch, RootState } from "../../redux/store"; import { editToolImpl } from "./editImpl"; export interface ClientToolExtras { + getState: () => RootState; dispatch: AppThunkDispatch; ideMessenger: IIdeMessenger; streamId?: string; diff --git a/gui/src/util/clientTools/editImpl.ts b/gui/src/util/clientTools/editImpl.ts index 0d1ac4445..06574bf56 100644 --- a/gui/src/util/clientTools/editImpl.ts +++ b/gui/src/util/clientTools/editImpl.ts @@ -1,5 +1,4 @@ import { resolveRelativePathInDir } from "core/util/ideUtils"; -import { updateApplyState } from "../../redux/slices/sessionSlice"; import { ClientToolImpl } from "./callClientTool"; export const editToolImpl: ClientToolImpl = async ( @@ -26,17 +25,7 @@ export const editToolImpl: ClientToolImpl = async ( if (apply.status === "error") { throw new Error(apply.error); } - if (extras.streamId) { - extras.dispatch( - updateApplyState({ - streamId: extras.streamId, - status: "done", - toolCallId, - numDiffs: 0, - filepath: args.filepath, - }), - ); - } + return { respondImmediately: false, output: undefined, // No immediate output. From 8cc98773d4ec6378570363232e8b3f30a18e7b71 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Fri, 25 Apr 2025 16:16:38 -0700 Subject: [PATCH 4/4] fix enter button disabled --- gui/src/components/mainInput/InputToolbar.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gui/src/components/mainInput/InputToolbar.tsx b/gui/src/components/mainInput/InputToolbar.tsx index 7ab85d2b2..abde8ce18 100644 --- a/gui/src/components/mainInput/InputToolbar.tsx +++ b/gui/src/components/mainInput/InputToolbar.tsx @@ -64,7 +64,8 @@ function InputToolbar(props: InputToolbarProps) { props.disabled || isEditModeAndNoCodeToEdit || toolCallState?.status === "generated" || - currentToolCallApplyState?.status !== "closed"; + (currentToolCallApplyState && + currentToolCallApplyState.status !== "closed"); const toolsSupported = defaultModel && modelSupportsTools(defaultModel);