From be88863c914d529959f599ba23f04c876f581181 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 14 Nov 2024 10:01:24 -0800 Subject: [PATCH 1/6] bunch of logs --- extensions/vscode/package-lock.json | 4 ++-- gui/src/redux/slices/stateSlice.ts | 28 ++++++++++++++++++++++++++++ gui/src/redux/slices/uiStateSlice.ts | 1 + 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index 3f4123969..24930d980 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "continue", - "version": "0.9.228", + "version": "0.9.229", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "continue", - "version": "0.9.228", + "version": "0.9.229", "license": "Apache-2.0", "dependencies": { "@electron/rebuild": "^3.2.10", diff --git a/gui/src/redux/slices/stateSlice.ts b/gui/src/redux/slices/stateSlice.ts index e3ce22eb6..f2cbe8dc9 100644 --- a/gui/src/redux/slices/stateSlice.ts +++ b/gui/src/redux/slices/stateSlice.ts @@ -83,6 +83,8 @@ export const stateSlice = createSlice({ state, { payload: config }: PayloadAction, ) => { + console.log("setConfig"); + const defaultModelTitle = config.models.find((model) => model.title === state.defaultModelTitle) ?.title || @@ -101,6 +103,8 @@ export const stateSlice = createSlice({ state, { payload }: PayloadAction, ) => { + console.log("addPromptCompletionPair"); + if (!state.history.length) { return; } @@ -139,11 +143,14 @@ export const stateSlice = createSlice({ contextItems: ChatHistoryItem["contextItems"]; }>, ) => { + console.log("setContextItemsAtIndex"); if (state.history[index]) { state.history[index].contextItems = contextItems; } }, addContextItems: (state, action: PayloadAction) => { + console.log("addContextItems"); + state.contextItems = state.contextItems.concat(action.payload); }, resubmitAtIndex: ( @@ -155,6 +162,8 @@ export const stateSlice = createSlice({ editorState: JSONContent; }>, ) => { + console.log("resubmitAtIndex"); + const historyItem = state.history[payload.index]; if (!historyItem) { return; @@ -188,6 +197,8 @@ export const stateSlice = createSlice({ editorState: JSONContent; }>, ) => { + console.log("initNewActiveMessage"); + state.history.push({ message: { role: "user", content: "", id: uuidv4() }, contextItems: state.contextItems, @@ -215,6 +226,7 @@ export const stateSlice = createSlice({ contextItems?: ContextItemWithId[]; }>, ) => { + console.log("setMessageAtIndex"); if (payload.index >= state.history.length) { state.history.push({ message: { ...payload.message, id: uuidv4() }, @@ -246,6 +258,8 @@ export const stateSlice = createSlice({ contextItems: ContextItemWithId[]; }>, ) => { + console.log("addContextItemsAtIndex"); + const historyItem = state.history[payload.index]; if (!historyItem) { return; @@ -257,6 +271,8 @@ export const stateSlice = createSlice({ state.active = false; }, streamUpdate: (state, action: PayloadAction) => { + console.log("streamUpdate"); + if (state.history.length) { state.history[state.history.length - 1].message.content += action.payload; @@ -267,6 +283,8 @@ export const stateSlice = createSlice({ { payload }: PayloadAction, ) => { if (payload) { + console.log("newSession"); + state.history = payload.history as any; state.title = payload.title; state.sessionId = payload.sessionId; @@ -285,6 +303,8 @@ export const stateSlice = createSlice({ payload, }: PayloadAction<{ ids: ContextItemId[]; index: number | undefined }>, ) => { + console.log("deleteContextWithIds"); + const getKey = (id: ContextItemId) => `${id.providerTitle}-${id.itemId}`; const ids = new Set(payload.ids.map(getKey)); @@ -304,6 +324,8 @@ export const stateSlice = createSlice({ payload, }: PayloadAction<{ rangeInFileWithContents: any; edit: boolean }>, ) => { + console.log("addHighlightedCode"); + let contextItems = [...state.contextItems].map((item) => { return { ...item, editing: false }; }); @@ -367,6 +389,8 @@ export const stateSlice = createSlice({ payload, }: PayloadAction<{ ids: ContextItemId[]; index: number | undefined }>, ) => { + console.log("setEditingAtIds"); + const ids = payload.ids.map((id) => id.itemId); if (typeof payload.index === "undefined") { @@ -403,6 +427,8 @@ export const stateSlice = createSlice({ state, { payload }: PayloadAction<{ title: string; force?: boolean }>, ) => { + console.log("setDefaultModel"); + const model = state.config.models.find( (model) => model.title === payload.title, ); @@ -413,6 +439,8 @@ export const stateSlice = createSlice({ }; }, setSelectedProfileId: (state, { payload }: PayloadAction) => { + console.log("setSelectedProfileId"); + return { ...state, selectedProfileId: payload, diff --git a/gui/src/redux/slices/uiStateSlice.ts b/gui/src/redux/slices/uiStateSlice.ts index 24c4fc194..385964881 100644 --- a/gui/src/redux/slices/uiStateSlice.ts +++ b/gui/src/redux/slices/uiStateSlice.ts @@ -58,6 +58,7 @@ export const uiStateSlice = createSlice({ state.nextCodeBlockToApplyIndex++; }, updateApplyState: (state, { payload }: PayloadAction) => { + console.log("updateApplyState"); const index = state.applyStates.findIndex( (applyState) => applyState.streamId === payload.streamId, ); From 9b529c99341db92c60a52cb7cd724288cacded2f Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 14 Nov 2024 12:12:51 -0800 Subject: [PATCH 2/6] remove state.contextItems - items per history item --- .../mainInput/CodeBlockComponent.tsx | 7 +- .../components/mainInput/ContextItemsPeek.tsx | 1 - .../components/mainInput/ContinueInputBox.tsx | 1 + gui/src/components/mainInput/TipTapEditor.tsx | 19 +-- gui/src/components/mainInput/resolveInput.ts | 2 + .../markdown/StyledMarkdownPreview.tsx | 8 +- gui/src/hooks/useChatHandler.ts | 46 ++++--- gui/src/hooks/useSetup.ts | 23 ++-- gui/src/pages/gui/Chat.tsx | 2 +- gui/src/redux/slices/stateSlice.ts | 129 +----------------- gui/src/redux/store.ts | 7 +- 11 files changed, 56 insertions(+), 189 deletions(-) diff --git a/gui/src/components/mainInput/CodeBlockComponent.tsx b/gui/src/components/mainInput/CodeBlockComponent.tsx index 217fcc293..5d62c6d91 100644 --- a/gui/src/components/mainInput/CodeBlockComponent.tsx +++ b/gui/src/components/mainInput/CodeBlockComponent.tsx @@ -12,12 +12,11 @@ export const CodeBlockComponent = ({ editor, updateAttributes, }: any) => { - const dispatch = useDispatch(); const item: ContextItemWithId = node.attrs.item; - const contextItems = useSelector( - (state: RootState) => state.state.contextItems, - ); + // const contextItems = useSelector( + // (state: RootState) => state.state.history[0]?.contextItems[0]?.id, + // ); return ( diff --git a/gui/src/components/mainInput/TipTapEditor.tsx b/gui/src/components/mainInput/TipTapEditor.tsx index c2646415e..3353d4462 100644 --- a/gui/src/components/mainInput/TipTapEditor.tsx +++ b/gui/src/components/mainInput/TipTapEditor.tsx @@ -159,6 +159,7 @@ interface TipTapEditorProps { placeholder?: string; header?: React.ReactNode; historyKey: string; + contextItems?: ContextItemWithId[]; } function TipTapEditor(props: TipTapEditorProps) { @@ -222,10 +223,6 @@ function TipTapEditor(props: TipTapEditorProps) { inDropdownRef.current = true; }; - const contextItems = useSelector( - (store: RootState) => store.state.contextItems, - ); - const defaultModel = useSelector(defaultModelSelector); const defaultModelRef = useUpdatingRef(defaultModel); @@ -495,19 +492,7 @@ function TipTapEditor(props: TipTapEditorProps) { content: props.editorState || mainEditorContent || "", onFocus: () => setIsEditorFocused(true), onBlur: () => setIsEditorFocused(false), - onUpdate: ({ editor, transaction }) => { - // If /edit is typed and no context items are selected, select the first - - if (contextItems.length > 0) { - return; - } - - const json = editor.getJSON(); - let codeBlock = json.content?.find((el) => el.type === "codeBlock"); - if (!codeBlock) { - return; - } - }, + // onUpdate editable: !active || props.isMainInput, }); diff --git a/gui/src/components/mainInput/resolveInput.ts b/gui/src/components/mainInput/resolveInput.ts index 64acba85a..27df6e4aa 100644 --- a/gui/src/components/mainInput/resolveInput.ts +++ b/gui/src/components/mainInput/resolveInput.ts @@ -30,6 +30,7 @@ async function resolveEditorContent( ideMessenger: IIdeMessenger, defaultContextProviders: DefaultContextProvider[], ): Promise<[ContextItemWithId[], RangeInFile[], MessageContent]> { + console.log("resolve editor content start"); let parts: MessagePart[] = []; let contextItemAttrs: MentionAttrs[] = []; const selectedCode: RangeInFile[] = []; @@ -171,6 +172,7 @@ async function resolveEditorContent( parts = [{ type: "text", text: lastPart }]; } } + console.log("resolve editor content end"); return [contextItems, selectedCode, parts]; } diff --git a/gui/src/components/markdown/StyledMarkdownPreview.tsx b/gui/src/components/markdown/StyledMarkdownPreview.tsx index a86a295c9..64bcecd04 100644 --- a/gui/src/components/markdown/StyledMarkdownPreview.tsx +++ b/gui/src/components/markdown/StyledMarkdownPreview.tsx @@ -15,12 +15,13 @@ import { getFontSize, isJetBrains } from "../../util"; import "./katex.css"; import "./markdown.css"; import { useSelector } from "react-redux"; -import { memoizedContextItemsSelector } from "../../redux/slices/stateSlice"; import { ctxItemToRifWithContents } from "core/commands/util"; import FilenameLink from "./FilenameLink"; import StepContainerPreToolbar from "./StepContainerPreToolbar"; import { SyntaxHighlightedPre } from "./SyntaxHighlightedPre"; import StepContainerPreActionButtons from "./StepContainerPreActionButtons"; +import { RootState } from "../../redux/store"; +import { ContextItemWithId } from "core"; const StyledMarkdown = styled.div<{ fontSize?: number; @@ -93,6 +94,7 @@ interface StyledMarkdownPreviewProps { className?: string; isRenderingInStepContainer?: boolean; // Currently only used to control the rendering of codeblocks scrollLocked?: boolean; + contextItems?: ContextItemWithId[]; } const HLJS_LANGUAGE_CLASSNAME_PREFIX = "language-"; @@ -152,8 +154,6 @@ function processCodeBlocks(tree: any) { const StyledMarkdownPreview = memo(function StyledMarkdownPreview( props: StyledMarkdownPreviewProps, ) { - const contextItems = useSelector(memoizedContextItemsSelector); - const [reactContent, setMarkdownSource] = useRemark({ remarkPlugins: [remarkMath, () => processCodeBlocks], rehypePlugins: [ @@ -236,7 +236,7 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview( code: ({ node, ...codeProps }) => { const content = getCodeChildrenContent(codeProps.children); - const ctxItem = contextItems.find((ctxItem) => + const ctxItem = props.contextItems?.find((ctxItem) => ctxItem.uri?.value.includes(content), ); diff --git a/gui/src/hooks/useChatHandler.ts b/gui/src/hooks/useChatHandler.ts index 2e35acc53..229c03ebc 100644 --- a/gui/src/hooks/useChatHandler.ts +++ b/gui/src/hooks/useChatHandler.ts @@ -23,7 +23,6 @@ import resolveEditorContent, { import { IIdeMessenger } from "../context/IdeMessenger"; import { defaultModelSelector } from "../redux/selectors/modelSelectors"; import { - addContextItems, addPromptCompletionPair, clearLastResponse, initNewActiveMessage, @@ -50,10 +49,6 @@ function useChatHandler(dispatch: Dispatch, ideMessenger: IIdeMessenger) { (store: RootState) => store.state.config.slashCommands || [], ); - const contextItems = useSelector( - (state: RootState) => state.state.contextItems, - ); - const history = useSelector((store: RootState) => store.state.history); const active = useSelector((store: RootState) => store.state.active); const activeRef = useRef(active); @@ -226,26 +221,33 @@ function useChatHandler(dispatch: Dispatch, ideMessenger: IIdeMessenger) { .slice(0, 1000) .join("\n"); } - selectedContextItems.unshift({ - content: `The following file is currently open. Don't reference it if it's not relevant to the user's message.\n\n\`\`\`${getRelativePath( - currentFile.path, - await ideMessenger.ide.getWorkspaceDirs(), - )}\n${currentFileContents}\n\`\`\``, - name: `Active file: ${getBasename(currentFile.path)}`, - description: currentFile.path, - id: { - itemId: currentFile.path, - providerTitle: "file", - }, - uri: { - type: "file", - value: currentFile.path, - }, - }); + if ( + !selectedContextItems.find( + (item) => item.uri?.value === currentFile.path, + ) + ) { + // don't add the file if it's already in the context items + selectedContextItems.unshift({ + content: `The following file is currently open. Don't reference it if it's not relevant to the user's message.\n\n\`\`\`${getRelativePath( + currentFile.path, + await ideMessenger.ide.getWorkspaceDirs(), + )}\n${currentFileContents}\n\`\`\``, + name: `Active file: ${getBasename(currentFile.path)}`, + description: currentFile.path, + id: { + itemId: currentFile.path, + providerTitle: "file", + }, + uri: { + type: "file", + value: currentFile.path, + }, + }); + } } } - dispatch(addContextItems(contextItems)); + // dispatch(addContextItems(contextItems)); const message: ChatMessage = { role: "user", diff --git a/gui/src/hooks/useSetup.ts b/gui/src/hooks/useSetup.ts index 2fed805da..c7f2a2598 100644 --- a/gui/src/hooks/useSetup.ts +++ b/gui/src/hooks/useSetup.ts @@ -21,7 +21,7 @@ import useChatHandler from "./useChatHandler"; import { useWebviewListener } from "./useWebviewListener"; function useSetup(dispatch: Dispatch) { - const [configLoaded, setConfigLoaded] = useState(false); + // const [configLoaded, setConfigLoaded] = useState(false); const ideMessenger = useContext(IdeMessengerContext); @@ -36,7 +36,7 @@ function useSetup(dispatch: Dispatch) { const { config, profileId } = result.content; dispatch(setConfig(config)); dispatch(setSelectedProfileId(profileId)); - setConfigLoaded(true); + // setConfigLoaded(true); setLocalStorage("disableIndexing", config.disableIndexing || false); // Perform any actions needed with the config @@ -49,16 +49,16 @@ function useSetup(dispatch: Dispatch) { // Load config from the IDE useEffect(() => { loadConfig(); - const interval = setInterval(() => { - if (configLoaded) { - clearInterval(interval); - return; - } - loadConfig(); - }, 2_000); + // const interval = setInterval(() => { + // if (configLoaded) { + // clearInterval(interval); + // return; + // } + // loadConfig(); + // }, 2_000); - return () => clearInterval(interval); - }, [configLoaded]); + // return () => clearInterval(interval); + }, []); useEffect(() => { // Override persisted state @@ -116,6 +116,7 @@ function useSetup(dispatch: Dispatch) { }, 1000); useWebviewListener("configUpdate", async () => { + console.log("config update"); await loadConfig(); if (!isJetBrains && !getLocalStorage("disableIndexing")) { diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx index 78bbcd262..6aaf38092 100644 --- a/gui/src/pages/gui/Chat.tsx +++ b/gui/src/pages/gui/Chat.tsx @@ -290,7 +290,7 @@ export function Chat() { setLocalStorage("mainTextEntryCounter", 1); } }, - [state.history, state.contextItems, defaultModel, state, streamResponse], + [state.history, defaultModel, state, streamResponse], ); useWebviewListener( diff --git a/gui/src/redux/slices/stateSlice.ts b/gui/src/redux/slices/stateSlice.ts index f2cbe8dc9..e1b22f8f7 100644 --- a/gui/src/redux/slices/stateSlice.ts +++ b/gui/src/redux/slices/stateSlice.ts @@ -15,16 +15,6 @@ import { createSelector } from "reselect"; import { v4 as uuidv4, v4 } from "uuid"; import { RootState } from "../store"; -export const memoizedContextItemsSelector = createSelector( - [(state: RootState) => state.state.history], - (history) => { - return history.reduce((acc, item) => { - acc.push(...item.contextItems); - return acc; - }, []); - }, -); - // We need this to handle reorderings (e.g. a mid-array deletion) of the messages array. // The proper fix is adding a UUID to all chat messages, but this is the temp workaround. type ChatHistoryItemWithMessageId = ChatHistoryItem & { @@ -33,7 +23,6 @@ type ChatHistoryItemWithMessageId = ChatHistoryItem & { type State = { history: ChatHistoryItemWithMessageId[]; - contextItems: ContextItemWithId[]; ttsActive: boolean; active: boolean; isGatheringContext: boolean; @@ -49,7 +38,6 @@ type State = { const initialState: State = { history: [], - contextItems: [], ttsActive: false, active: false, isGatheringContext: false, @@ -148,11 +136,6 @@ export const stateSlice = createSlice({ state.history[index].contextItems = contextItems; } }, - addContextItems: (state, action: PayloadAction) => { - console.log("addContextItems"); - - state.contextItems = state.contextItems.concat(action.payload); - }, resubmitAtIndex: ( state, { @@ -182,7 +165,6 @@ export const stateSlice = createSlice({ }); // https://github.com/continuedev/continue/pull/1021 - // state.contextItems = []; state.active = true; }, deleteMessage: (state, action: PayloadAction) => { @@ -201,7 +183,7 @@ export const stateSlice = createSlice({ state.history.push({ message: { role: "user", content: "", id: uuidv4() }, - contextItems: state.contextItems, + contextItems: [], editorState: payload.editorState, }); state.history.push({ @@ -212,8 +194,7 @@ export const stateSlice = createSlice({ }, contextItems: [], }); - // https://github.com/continuedev/continue/pull/1021 - // state.contextItems = []; + state.active = true; }, setMessageAtIndex: ( @@ -290,34 +271,12 @@ export const stateSlice = createSlice({ state.sessionId = payload.sessionId; } else { state.history = []; - state.contextItems = []; state.active = false; state.title = "New Session"; state.sessionId = v4(); state.isInMultifileEdit = false; } }, - deleteContextWithIds: ( - state, - { - payload, - }: PayloadAction<{ ids: ContextItemId[]; index: number | undefined }>, - ) => { - console.log("deleteContextWithIds"); - - const getKey = (id: ContextItemId) => `${id.providerTitle}-${id.itemId}`; - const ids = new Set(payload.ids.map(getKey)); - - if (payload.index === undefined) { - state.contextItems = state.contextItems.filter( - (item) => !ids.has(getKey(item.id)), - ); - } else { - state.history[payload.index].contextItems = state.history[ - payload.index - ].contextItems.filter((item) => !ids.has(getKey(item.id))); - } - }, addHighlightedCode: ( state, { @@ -325,47 +284,15 @@ export const stateSlice = createSlice({ }: PayloadAction<{ rangeInFileWithContents: any; edit: boolean }>, ) => { console.log("addHighlightedCode"); - - let contextItems = [...state.contextItems].map((item) => { + let contextItems = + state.history[state.history.length - 1].contextItems ?? []; + contextItems = contextItems.map((item) => { return { ...item, editing: false }; }); const base = payload.rangeInFileWithContents.filepath .split(/[\\/]/) .pop(); - // Merge if there is overlap - for (let i = 0; i < contextItems.length; i++) { - const item = contextItems[i]; - if (item.description === payload.rangeInFileWithContents.filepath) { - let newStart = payload.rangeInFileWithContents.range.start.line; - let newEnd = payload.rangeInFileWithContents.range.end.line; - let [oldStart, oldEnd] = item.name - .split("(")[1] - .split(")")[0] - .split("-") - .map((x: string) => parseInt(x) - 1); - if (newStart > oldEnd || newEnd < oldStart) { - continue; - } - const startLine = Math.min(newStart, oldStart); - const endLine = Math.max(newEnd, oldEnd); - - // const oldContents = item.content.split("\n"); - // const newContents = - // payload.rangeInFileWithContents.contents.split("\n"); - // const finalContents = []; - - contextItems[i] = { - ...item, - name: `${base} (${startLine + 1}-${endLine + 1})`, - content: payload.rangeInFileWithContents.contents, - editing: true, - editable: true, - }; - return { ...state, contextItems }; - } - } - const lineNums = `(${ payload.rangeInFileWithContents.range.start.line + 1 }-${payload.rangeInFileWithContents.range.end.line + 1})`; @@ -380,48 +307,7 @@ export const stateSlice = createSlice({ editing: true, editable: true, }); - - return { ...state, contextItems }; - }, - setEditingAtIds: ( - state, - { - payload, - }: PayloadAction<{ ids: ContextItemId[]; index: number | undefined }>, - ) => { - console.log("setEditingAtIds"); - - const ids = payload.ids.map((id) => id.itemId); - - if (typeof payload.index === "undefined") { - return { - ...state, - contextItems: state.contextItems.map((item) => { - return { - ...item, - editing: ids.includes(item.id.itemId), - }; - }), - }; - } else { - return { - ...state, - history: state.history.map((step, i) => { - if (i === payload.index) { - return { - ...step, - contextItems: step.contextItems.map((item) => { - return { - ...item, - editing: ids.includes(item.id.itemId), - }; - }), - }; - } - return step; - }), - }; - } + state.history[state.history.length - 1].contextItems = contextItems; }, setDefaultModel: ( state, @@ -454,15 +340,12 @@ export const stateSlice = createSlice({ export const { setContextItemsAtIndex, - addContextItems, addContextItemsAtIndex, setInactive, streamUpdate, newSession, - deleteContextWithIds, resubmitAtIndex, addHighlightedCode, - setEditingAtIds, setDefaultModel, setConfig, setConfigError, diff --git a/gui/src/redux/store.ts b/gui/src/redux/store.ts index a5d0313f4..221d275c9 100644 --- a/gui/src/redux/store.ts +++ b/gui/src/redux/store.ts @@ -40,12 +40,7 @@ const windowIDTransform = (windowID: string) => ); const saveSubsetFilters = [ - createFilter("state", [ - "history", - "contextItems", - "sessionId", - "defaultModelTitle", - ]), + createFilter("state", ["history", "sessionId", "defaultModelTitle"]), ]; const persistConfig = { From 00aaba64798ab33a2e4f2407b31fafe49ae62564 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 14 Nov 2024 12:25:33 -0800 Subject: [PATCH 3/6] pass contextItems around a bit more --- gui/src/components/gui/StepContainer.tsx | 1 + .../components/mainInput/CodeBlockComponent.tsx | 14 ++++++++------ .../components/markdown/CodeSnippetPreview.tsx | 1 + .../components/markdown/StyledMarkdownPreview.tsx | 15 ++++++++------- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/gui/src/components/gui/StepContainer.tsx b/gui/src/components/gui/StepContainer.tsx index 1eba7ee91..22523cfb2 100644 --- a/gui/src/components/gui/StepContainer.tsx +++ b/gui/src/components/gui/StepContainer.tsx @@ -105,6 +105,7 @@ function StepContainer(props: StepContainerProps) { )} diff --git a/gui/src/components/mainInput/CodeBlockComponent.tsx b/gui/src/components/mainInput/CodeBlockComponent.tsx index 5d62c6d91..80c1cec78 100644 --- a/gui/src/components/mainInput/CodeBlockComponent.tsx +++ b/gui/src/components/mainInput/CodeBlockComponent.tsx @@ -1,9 +1,9 @@ import { NodeViewWrapper } from "@tiptap/react"; import { ContextItemWithId } from "core"; -import { useDispatch, useSelector } from "react-redux"; import { vscBadgeBackground } from ".."; -import { RootState } from "../../redux/store"; import CodeSnippetPreview from "../markdown/CodeSnippetPreview"; +import { useSelector } from "react-redux"; +import { RootState } from "../../redux/store"; export const CodeBlockComponent = ({ node, @@ -13,15 +13,17 @@ export const CodeBlockComponent = ({ updateAttributes, }: any) => { const item: ContextItemWithId = node.attrs.item; + const contextItems = useSelector( + (store: RootState) => + store.state.history[store.state.history.length - 1].contextItems, + ); + const isFirstContextItem = item.id === contextItems[0].id; - // const contextItems = useSelector( - // (state: RootState) => state.state.history[0]?.contextItems[0]?.id, - // ); return ( diff --git a/gui/src/components/markdown/StyledMarkdownPreview.tsx b/gui/src/components/markdown/StyledMarkdownPreview.tsx index 64bcecd04..a3da04eb9 100644 --- a/gui/src/components/markdown/StyledMarkdownPreview.tsx +++ b/gui/src/components/markdown/StyledMarkdownPreview.tsx @@ -236,13 +236,14 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview( code: ({ node, ...codeProps }) => { const content = getCodeChildrenContent(codeProps.children); - const ctxItem = props.contextItems?.find((ctxItem) => - ctxItem.uri?.value.includes(content), - ); - - if (ctxItem) { - const rif = ctxItemToRifWithContents(ctxItem); - return ; + if (props.contextItems) { + const ctxItem = props.contextItems.find((ctxItem) => + ctxItem.uri?.value.includes(content), + ); + if (ctxItem) { + const rif = ctxItemToRifWithContents(ctxItem); + return ; + } } return {codeProps.children}; From e595235584629ed214139dc328818e168200ce32 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 14 Nov 2024 13:30:20 -0800 Subject: [PATCH 4/6] state.contextItems --- .../mainInput/CodeBlockComponent.tsx | 12 +++----- gui/src/hooks/useSetup.ts | 29 ++++++++++--------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/gui/src/components/mainInput/CodeBlockComponent.tsx b/gui/src/components/mainInput/CodeBlockComponent.tsx index 80c1cec78..1ece03733 100644 --- a/gui/src/components/mainInput/CodeBlockComponent.tsx +++ b/gui/src/components/mainInput/CodeBlockComponent.tsx @@ -5,19 +5,15 @@ import CodeSnippetPreview from "../markdown/CodeSnippetPreview"; import { useSelector } from "react-redux"; import { RootState } from "../../redux/store"; -export const CodeBlockComponent = ({ - node, - deleteNode, - selected, - editor, - updateAttributes, -}: any) => { +export const CodeBlockComponent = (props: any) => { + const { node, deleteNode, selected, editor, updateAttributes } = props; const item: ContextItemWithId = node.attrs.item; const contextItems = useSelector( (store: RootState) => store.state.history[store.state.history.length - 1].contextItems, ); - const isFirstContextItem = item.id === contextItems[0].id; + const isFirstContextItem = item.id === contextItems[0]?.id; + // const isFirstContextItem = false; return ( diff --git a/gui/src/hooks/useSetup.ts b/gui/src/hooks/useSetup.ts index c7f2a2598..9bdc4d713 100644 --- a/gui/src/hooks/useSetup.ts +++ b/gui/src/hooks/useSetup.ts @@ -1,5 +1,5 @@ import { Dispatch } from "@reduxjs/toolkit"; -import { useContext, useEffect, useState } from "react"; +import { useCallback, useContext, useEffect, useRef, useState } from "react"; import { useSelector } from "react-redux"; import { VSC_THEME_COLOR_VARS } from "../components"; import { IdeMessengerContext } from "../context/IdeMessenger"; @@ -14,7 +14,7 @@ import { } from "../redux/slices/stateSlice"; import { RootState } from "../redux/store"; -import { debounce } from "lodash"; +import { debounce, initial } from "lodash"; import { isJetBrains } from "../util"; import { getLocalStorage, setLocalStorage } from "../util/localStorage"; import useChatHandler from "./useChatHandler"; @@ -25,7 +25,8 @@ function useSetup(dispatch: Dispatch) { const ideMessenger = useContext(IdeMessengerContext); - const loadConfig = async () => { + const initialConfigLoad = useRef(false); + const loadConfig = useCallback(async () => { const result = await ideMessenger.request( "config/getSerializedProfileInfo", undefined, @@ -36,7 +37,7 @@ function useSetup(dispatch: Dispatch) { const { config, profileId } = result.content; dispatch(setConfig(config)); dispatch(setSelectedProfileId(profileId)); - // setConfigLoaded(true); + initialConfigLoad.current = true; setLocalStorage("disableIndexing", config.disableIndexing || false); // Perform any actions needed with the config @@ -44,21 +45,21 @@ function useSetup(dispatch: Dispatch) { setLocalStorage("fontSize", config.ui.fontSize); document.body.style.fontSize = `${config.ui.fontSize}px`; } - }; + }, [dispatch, ideMessenger, initialConfigLoad]); // Load config from the IDE useEffect(() => { loadConfig(); - // const interval = setInterval(() => { - // if (configLoaded) { - // clearInterval(interval); - // return; - // } - // loadConfig(); - // }, 2_000); + const interval = setInterval(() => { + if (initialConfigLoad.current) { + clearInterval(interval); + return; + } + loadConfig(); + }, 2_000); - // return () => clearInterval(interval); - }, []); + return () => clearInterval(interval); + }, [initialConfigLoad]); useEffect(() => { // Override persisted state From fbbee8980ae2583e06255f2642122f647abc9ffa Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 14 Nov 2024 14:27:55 -0800 Subject: [PATCH 5/6] files --- .../mainInput/CodeBlockComponent.tsx | 12 +++++------ .../components/mainInput/ContinueInputBox.tsx | 1 - gui/src/components/mainInput/TipTapEditor.tsx | 1 - gui/src/components/mainInput/resolveInput.ts | 2 -- .../markdown/StyledMarkdownPreview.tsx | 2 -- gui/src/hooks/useSetup.ts | 3 +-- gui/src/redux/slices/stateSlice.ts | 21 ------------------- 7 files changed, 7 insertions(+), 35 deletions(-) diff --git a/gui/src/components/mainInput/CodeBlockComponent.tsx b/gui/src/components/mainInput/CodeBlockComponent.tsx index 1ece03733..20d700c63 100644 --- a/gui/src/components/mainInput/CodeBlockComponent.tsx +++ b/gui/src/components/mainInput/CodeBlockComponent.tsx @@ -8,12 +8,12 @@ import { RootState } from "../../redux/store"; export const CodeBlockComponent = (props: any) => { const { node, deleteNode, selected, editor, updateAttributes } = props; const item: ContextItemWithId = node.attrs.item; - const contextItems = useSelector( - (store: RootState) => - store.state.history[store.state.history.length - 1].contextItems, - ); - const isFirstContextItem = item.id === contextItems[0]?.id; - // const isFirstContextItem = false; + // const contextItems = useSelector( + // (store: RootState) => + // store.state.history[store.state.history.length - 1].contextItems, + // ); + // const isFirstContextItem = item.id === contextItems[0]?.id; + const isFirstContextItem = false; return ( diff --git a/gui/src/components/mainInput/ContinueInputBox.tsx b/gui/src/components/mainInput/ContinueInputBox.tsx index d4aedf0b1..c98a69403 100644 --- a/gui/src/components/mainInput/ContinueInputBox.tsx +++ b/gui/src/components/mainInput/ContinueInputBox.tsx @@ -140,7 +140,6 @@ function ContinueInputBox(props: ContinueInputBoxProps) { availableContextProviders={availableContextProviders ?? []} availableSlashCommands={availableSlashCommands} historyKey="chat" - contextItems={props.contextItems} /> diff --git a/gui/src/components/mainInput/TipTapEditor.tsx b/gui/src/components/mainInput/TipTapEditor.tsx index 3353d4462..e3e0feb2e 100644 --- a/gui/src/components/mainInput/TipTapEditor.tsx +++ b/gui/src/components/mainInput/TipTapEditor.tsx @@ -159,7 +159,6 @@ interface TipTapEditorProps { placeholder?: string; header?: React.ReactNode; historyKey: string; - contextItems?: ContextItemWithId[]; } function TipTapEditor(props: TipTapEditorProps) { diff --git a/gui/src/components/mainInput/resolveInput.ts b/gui/src/components/mainInput/resolveInput.ts index 27df6e4aa..64acba85a 100644 --- a/gui/src/components/mainInput/resolveInput.ts +++ b/gui/src/components/mainInput/resolveInput.ts @@ -30,7 +30,6 @@ async function resolveEditorContent( ideMessenger: IIdeMessenger, defaultContextProviders: DefaultContextProvider[], ): Promise<[ContextItemWithId[], RangeInFile[], MessageContent]> { - console.log("resolve editor content start"); let parts: MessagePart[] = []; let contextItemAttrs: MentionAttrs[] = []; const selectedCode: RangeInFile[] = []; @@ -172,7 +171,6 @@ async function resolveEditorContent( parts = [{ type: "text", text: lastPart }]; } } - console.log("resolve editor content end"); return [contextItems, selectedCode, parts]; } diff --git a/gui/src/components/markdown/StyledMarkdownPreview.tsx b/gui/src/components/markdown/StyledMarkdownPreview.tsx index a3da04eb9..cd87cb2cd 100644 --- a/gui/src/components/markdown/StyledMarkdownPreview.tsx +++ b/gui/src/components/markdown/StyledMarkdownPreview.tsx @@ -14,13 +14,11 @@ import { import { getFontSize, isJetBrains } from "../../util"; import "./katex.css"; import "./markdown.css"; -import { useSelector } from "react-redux"; import { ctxItemToRifWithContents } from "core/commands/util"; import FilenameLink from "./FilenameLink"; import StepContainerPreToolbar from "./StepContainerPreToolbar"; import { SyntaxHighlightedPre } from "./SyntaxHighlightedPre"; import StepContainerPreActionButtons from "./StepContainerPreActionButtons"; -import { RootState } from "../../redux/store"; import { ContextItemWithId } from "core"; const StyledMarkdown = styled.div<{ diff --git a/gui/src/hooks/useSetup.ts b/gui/src/hooks/useSetup.ts index 9bdc4d713..effe838dc 100644 --- a/gui/src/hooks/useSetup.ts +++ b/gui/src/hooks/useSetup.ts @@ -59,7 +59,7 @@ function useSetup(dispatch: Dispatch) { }, 2_000); return () => clearInterval(interval); - }, [initialConfigLoad]); + }, [initialConfigLoad, loadConfig]); useEffect(() => { // Override persisted state @@ -117,7 +117,6 @@ function useSetup(dispatch: Dispatch) { }, 1000); useWebviewListener("configUpdate", async () => { - console.log("config update"); await loadConfig(); if (!isJetBrains && !getLocalStorage("disableIndexing")) { diff --git a/gui/src/redux/slices/stateSlice.ts b/gui/src/redux/slices/stateSlice.ts index e1b22f8f7..4222b4693 100644 --- a/gui/src/redux/slices/stateSlice.ts +++ b/gui/src/redux/slices/stateSlice.ts @@ -71,8 +71,6 @@ export const stateSlice = createSlice({ state, { payload: config }: PayloadAction, ) => { - console.log("setConfig"); - const defaultModelTitle = config.models.find((model) => model.title === state.defaultModelTitle) ?.title || @@ -91,8 +89,6 @@ export const stateSlice = createSlice({ state, { payload }: PayloadAction, ) => { - console.log("addPromptCompletionPair"); - if (!state.history.length) { return; } @@ -131,7 +127,6 @@ export const stateSlice = createSlice({ contextItems: ChatHistoryItem["contextItems"]; }>, ) => { - console.log("setContextItemsAtIndex"); if (state.history[index]) { state.history[index].contextItems = contextItems; } @@ -145,8 +140,6 @@ export const stateSlice = createSlice({ editorState: JSONContent; }>, ) => { - console.log("resubmitAtIndex"); - const historyItem = state.history[payload.index]; if (!historyItem) { return; @@ -179,8 +172,6 @@ export const stateSlice = createSlice({ editorState: JSONContent; }>, ) => { - console.log("initNewActiveMessage"); - state.history.push({ message: { role: "user", content: "", id: uuidv4() }, contextItems: [], @@ -207,7 +198,6 @@ export const stateSlice = createSlice({ contextItems?: ContextItemWithId[]; }>, ) => { - console.log("setMessageAtIndex"); if (payload.index >= state.history.length) { state.history.push({ message: { ...payload.message, id: uuidv4() }, @@ -239,8 +229,6 @@ export const stateSlice = createSlice({ contextItems: ContextItemWithId[]; }>, ) => { - console.log("addContextItemsAtIndex"); - const historyItem = state.history[payload.index]; if (!historyItem) { return; @@ -252,8 +240,6 @@ export const stateSlice = createSlice({ state.active = false; }, streamUpdate: (state, action: PayloadAction) => { - console.log("streamUpdate"); - if (state.history.length) { state.history[state.history.length - 1].message.content += action.payload; @@ -264,8 +250,6 @@ export const stateSlice = createSlice({ { payload }: PayloadAction, ) => { if (payload) { - console.log("newSession"); - state.history = payload.history as any; state.title = payload.title; state.sessionId = payload.sessionId; @@ -283,7 +267,6 @@ export const stateSlice = createSlice({ payload, }: PayloadAction<{ rangeInFileWithContents: any; edit: boolean }>, ) => { - console.log("addHighlightedCode"); let contextItems = state.history[state.history.length - 1].contextItems ?? []; contextItems = contextItems.map((item) => { @@ -313,8 +296,6 @@ export const stateSlice = createSlice({ state, { payload }: PayloadAction<{ title: string; force?: boolean }>, ) => { - console.log("setDefaultModel"); - const model = state.config.models.find( (model) => model.title === payload.title, ); @@ -325,8 +306,6 @@ export const stateSlice = createSlice({ }; }, setSelectedProfileId: (state, { payload }: PayloadAction) => { - console.log("setSelectedProfileId"); - return { ...state, selectedProfileId: payload, From ef715a8e4def60037776b55a9acaf2f1dcc4b736 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 14 Nov 2024 14:46:30 -0800 Subject: [PATCH 6/6] remove state.contextItems cleanup --- gui/src/hooks/useSetup.ts | 4 +--- gui/src/redux/slices/uiStateSlice.ts | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/gui/src/hooks/useSetup.ts b/gui/src/hooks/useSetup.ts index effe838dc..b96c48ed2 100644 --- a/gui/src/hooks/useSetup.ts +++ b/gui/src/hooks/useSetup.ts @@ -14,15 +14,13 @@ import { } from "../redux/slices/stateSlice"; import { RootState } from "../redux/store"; -import { debounce, initial } from "lodash"; +import { debounce } from "lodash"; import { isJetBrains } from "../util"; import { getLocalStorage, setLocalStorage } from "../util/localStorage"; import useChatHandler from "./useChatHandler"; import { useWebviewListener } from "./useWebviewListener"; function useSetup(dispatch: Dispatch) { - // const [configLoaded, setConfigLoaded] = useState(false); - const ideMessenger = useContext(IdeMessengerContext); const initialConfigLoad = useRef(false); diff --git a/gui/src/redux/slices/uiStateSlice.ts b/gui/src/redux/slices/uiStateSlice.ts index 385964881..24c4fc194 100644 --- a/gui/src/redux/slices/uiStateSlice.ts +++ b/gui/src/redux/slices/uiStateSlice.ts @@ -58,7 +58,6 @@ export const uiStateSlice = createSlice({ state.nextCodeBlockToApplyIndex++; }, updateApplyState: (state, { payload }: PayloadAction) => { - console.log("updateApplyState"); const index = state.applyStates.findIndex( (applyState) => applyState.streamId === payload.streamId, );