diff --git a/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx b/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx index 375fd7ab8..f09ed1a9f 100644 --- a/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx +++ b/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx @@ -69,7 +69,6 @@ export default function StepContainerPreToolbar( props.expanded ?? (isInEditMode ? false : true), ); const [codeBlockContent, setCodeBlockContent] = useState(""); - const isStreaming = useAppSelector((state) => state.session.isStreaming); const nextCodeBlockIndex = useAppSelector( (state) => state.session.codeBlockApplyStates.curIndex, @@ -79,15 +78,6 @@ export default function StepContainerPreToolbar( selectApplyStateByStreamId(state, props.codeBlockStreamId), ); - // This handles an edge case when the last node in the markdown syntax tree is a codeblock. - // In this scenario, `isGeneratingCodeBlock` is never set to false since we determine if - // we are done generating based on whether the next node in the tree is not a codeblock. - // The tree parsing logic for Remark is defined on page load, so we can't access state - // during the actual tree parsing. - const isGeneratingCodeBlock = !isStreaming - ? false - : props.isGeneratingCodeBlock; - const isNextCodeBlock = nextCodeBlockIndex === props.codeBlockIndex; const hasFileExtension = /\.[0-9a-z]+$/i.test(props.relativeFilepath); @@ -196,7 +186,7 @@ export default function StepContainerPreToolbar(
- {isGeneratingCodeBlock ? ( + {props.isGeneratingCodeBlock ? ( { + return props.itemIndex && props.itemIndex === history.length - 1; + }, [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 }[]>( [], ); + useEffect(() => { if (props.singleCodeblockStreamId) { codeblockState.current = [ @@ -235,8 +245,7 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview( node.data = node.data || {}; node.data.hProperties = node.data.hProperties || {}; - node.data.hProperties["data-isgeneratingcodeblock"] = - lastCodeNode === node; + node.data.hProperties["data-islastcodeblock"] = lastCodeNode === node; node.data.hProperties["data-codeblockcontent"] = node.value; if (node.meta) { @@ -318,7 +327,9 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview( } const isGeneratingCodeBlock = - preChildProps["data-isgeneratingcodeblock"]; + preChildProps["data-islastcodeblock"] && + isLastItemRef.current && + !isStreamingRef.current; if (codeblockState.current[codeBlockIndex] === undefined) { codeblockState.current[codeBlockIndex] = { @@ -342,6 +353,7 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview( codeBlockStreamId={ codeblockState.current[codeBlockIndex].streamId } + expanded={props.expandCodeblocks} disableManualApply={props.disableManualApply} > diff --git a/gui/src/hooks/useSetup.ts b/gui/src/hooks/useSetup.ts index 25b1a7fc0..ded57ee08 100644 --- a/gui/src/hooks/useSetup.ts +++ b/gui/src/hooks/useSetup.ts @@ -3,7 +3,7 @@ import { VSC_THEME_COLOR_VARS } from "../components"; import { IdeMessengerContext } from "../context/IdeMessenger"; import { ConfigResult } from "@continuedev/config-yaml"; -import { BrowserSerializedContinueConfig, ContextItem } from "core"; +import { BrowserSerializedContinueConfig } from "core"; import { initializeProfilePreferencesThunk, selectProfileThunk, @@ -268,17 +268,17 @@ function useSetup() { state.streamId === activeToolStreamId[0] && state.status === "closed" ) { - const output: ContextItem = { - name: "Edit tool output", - content: "Completed edit", - description: "", - }; + // const output: ContextItem = { + // name: "Edit tool output", + // content: "Completed edit", + // description: "", + // }; dispatch(acceptToolCall()); - dispatch(setToolCallOutput([output])); + dispatch(setToolCallOutput([])); dispatch( streamResponseAfterToolCall({ toolCallId: activeToolStreamId[1], - toolOutput: [output], + toolOutput: [], }), ); } diff --git a/gui/src/pages/gui/ToolCallDiv/EditFile.tsx b/gui/src/pages/gui/ToolCallDiv/EditFile.tsx index 2ff34d489..80927e6e7 100644 --- a/gui/src/pages/gui/ToolCallDiv/EditFile.tsx +++ b/gui/src/pages/gui/ToolCallDiv/EditFile.tsx @@ -33,6 +33,7 @@ export function EditFile(props: EditToolCallProps) { source={src} disableManualApply={true} singleCodeblockStreamId={applyState?.streamId} + expandCodeblocks={false} /> {/* TODO better indicator of generation at bottom */} {/* {isStreaming && applyState?.status === "streaming" && ( diff --git a/gui/src/redux/thunks/callTool.ts b/gui/src/redux/thunks/callTool.ts index 41557cb40..bf15e7ae8 100644 --- a/gui/src/redux/thunks/callTool.ts +++ b/gui/src/redux/thunks/callTool.ts @@ -11,6 +11,7 @@ import { cancelToolCall, setCalling, setToolCallOutput, + updateApplyState, } from "../slices/sessionSlice"; import { ThunkApiType } from "../store"; import { streamResponseAfterToolCall } from "./streamResponseAfterToolCall"; @@ -61,6 +62,17 @@ export const callTool = createAsyncThunk( if (e instanceof Error) { errorMessage = e.message; } + if (state.session.activeToolStreamId?.[0]) { + dispatch( + updateApplyState({ + streamId: state.session.activeToolStreamId[0], + status: "closed", + toolCallId: toolCallState.toolCallId, + numDiffs: 0, + filepath: args.filepath, + }), + ); + } } } else { const result = await extra.ideMessenger.request("tools/call", { @@ -128,7 +140,7 @@ async function customGuiEditImpl( text: args.new_contents, curSelectedModelTitle: modelTitle, toolCallId, - filepath: firstUriMatch + filepath: firstUriMatch, }); if (apply.status === "error") { throw new Error(apply.error);