Elffuss BraidHub

kikocis/continue public

Merge pull request #5801 from continuedev/pe/remove-edit-mode

feat: remove edit as a mode
Changesetb0349aaa027a7542e6404a57f2dc8fb62cf77bfc347f530403a305f76319e08c
AuthorPatrick Erichsen <patrick.a.erichsen@gmail.com> · 2025-05-25 19:55 -07:00
CommitterGitHub <noreply@github.com> · 2025-05-25 19:55 -07:00
Parentsf8a28b58727d, c4329554da83

Browse the files at this changeset

46 files changed

modified core/index.d.ts +1 −1
@@ -423,7 +423,7 @@
423423 completion: string;
424424 }
425425
426-export type MessageModes = "chat" | "edit" | "agent";
426+export type MessageModes = "chat" | "agent";
427427
428428 export type ToolStatus =
429429 | "generating"
modified gui/src/components/AcceptRejectDiffButtons.tsx +15 −28
@@ -3,7 +3,7 @@
33 import { useContext } from "react";
44 import { IdeMessengerContext } from "../context/IdeMessenger";
55 import { getMetaKeyLabel } from "../util";
6-import { useFontSize } from "./ui/font";
6+import { ToolTip } from "./gui/Tooltip";
77
88 export interface AcceptRejectAllButtonsProps {
99 applyStates: ApplyState[];
@@ -21,8 +21,6 @@
2121 );
2222 const ideMessenger = useContext(IdeMessengerContext);
2323
24- const tinyFont = useFontSize(-3);
25-
2624 async function handleAcceptOrReject(status: AcceptOrRejectOutcome) {
2725 for (const { filepath = "", streamId } of pendingApplyStates) {
2826 ideMessenger.post(status, {
@@ -36,54 +34,43 @@
3634 }
3735 }
3836
39- if (!pendingApplyStates.length) {
40- return null;
41- }
37+ const rejectShortcut = `${getMetaKeyLabel()}⇧⌫`;
38+ const acceptShortcut = `${getMetaKeyLabel()}⇧⏎`;
4239
4340 return (
4441 <div
45- className="flex flex-row items-center justify-evenly gap-2 p-1 px-3"
42+ className="flex flex-row items-center justify-evenly gap-3 px-3"
4643 data-testid="accept-reject-all-buttons"
4744 >
4845 <button
49- className="flex cursor-pointer flex-row flex-wrap justify-center gap-1 border-none bg-transparent px-2 py-1 text-xs text-gray-300 opacity-80 hover:opacity-100 hover:brightness-125"
46+ className="text-foreground flex cursor-pointer flex-row flex-wrap justify-center gap-1 border-none bg-transparent p-0 text-xs opacity-80 hover:opacity-100 hover:brightness-125"
5047 onClick={() => handleAcceptOrReject("rejectDiff")}
5148 data-testid="edit-reject-button"
49+ data-tooltip-id="reject-shortcut"
50+ data-tooltip-content={`Reject All (${rejectShortcut})`}
5251 >
5352 <div className="flex flex-row items-center gap-1">
54- <XMarkIcon className="h-4 w-4 text-red-600" />
53+ <XMarkIcon className="text-error h-4 w-4" />
5554 <span>Reject</span>
5655 <span className="xs:inline-block hidden">All</span>
5756 </div>
58-
59- <span
60- className="xs:inline-block hidden text-gray-400"
61- style={{
62- fontSize: tinyFont,
63- }}
64- >
65- ({getMetaKeyLabel()}⇧⌫)
66- </span>
6757 </button>
58+ <ToolTip id="reject-shortcut" />
59+
6860 <button
69- className="flex cursor-pointer flex-row flex-wrap justify-center gap-1 border-none bg-transparent px-2 py-1 text-xs text-gray-300 opacity-80 hover:opacity-100 hover:brightness-125"
61+ className="text-foreground flex cursor-pointer flex-row flex-wrap justify-center gap-1 border-none bg-transparent p-0 text-xs opacity-80 hover:opacity-100 hover:brightness-125"
7062 onClick={() => handleAcceptOrReject("acceptDiff")}
7163 data-testid="edit-accept-button"
64+ data-tooltip-id="accept-shortcut"
65+ data-tooltip-content={`Accept All (${acceptShortcut})`}
7266 >
7367 <div className="flex flex-row items-center gap-1">
74- <CheckIcon className="h-4 w-4 text-green-600" />
68+ <CheckIcon className="text-success h-4 w-4" />
7569 <span>Accept</span>
7670 <span className="xs:inline-block hidden">All</span>
7771 </div>
78- <span
79- className="xs:inline-block hidden text-gray-400"
80- style={{
81- fontSize: tinyFont,
82- }}
83- >
84- ({getMetaKeyLabel()}⇧⏎)
85- </span>
8672 </button>
73+ <ToolTip id="accept-shortcut" />
8774 </div>
8875 );
8976 }
modified gui/src/components/History/HistoryTableRow.tsx +2 −2
@@ -6,7 +6,7 @@
66 import { Input } from "..";
77 import { IdeMessengerContext } from "../../context/IdeMessenger";
88 import { useAppDispatch, useAppSelector } from "../../redux/hooks";
9-import { exitEditMode } from "../../redux/thunks/editMode";
9+import { exitEdit } from "../../redux/thunks/edit";
1010 import {
1111 deleteSession,
1212 getSession,
@@ -69,7 +69,7 @@
6969 data-testid={`history-row-${index}`}
7070 className="hover:bg-vsc-editor-background relative box-border flex cursor-pointer overflow-hidden rounded-lg p-3"
7171 onClick={async () => {
72- await dispatch(exitEditMode({}));
72+ await dispatch(exitEdit({}));
7373 if (sessionMetadata.sessionId !== currentSessionId) {
7474 await dispatch(
7575 loadSession({
modified gui/src/components/Layout.tsx +12 −12
@@ -7,9 +7,9 @@
77 import { LocalStorageProvider } from "../context/LocalStorage";
88 import { useWebviewListener } from "../hooks/useWebviewListener";
99 import { useAppDispatch, useAppSelector } from "../redux/hooks";
10-import { setCodeToEdit } from "../redux/slices/editModeState";
10+import { setCodeToEdit } from "../redux/slices/editState";
1111 import { setShowDialog } from "../redux/slices/uiSlice";
12-import { enterEditMode, exitEditMode } from "../redux/thunks/editMode";
12+import { enterEdit, exitEdit } from "../redux/thunks/edit";
1313 import { saveCurrentSession } from "../redux/thunks/session";
1414 import { fontSize, isMetaEquivalentKeyPressed } from "../util";
1515 import { incrementFreeTrialCount } from "../util/freeTrial";
@@ -48,14 +48,14 @@
4848 const dialogMessage = useAppSelector((state) => state.ui.dialogMessage);
4949
5050 const showDialog = useAppSelector((state) => state.ui.showDialog);
51- const mode = useAppSelector((state) => state.session.mode);
51+ const isInEdit = useAppSelector((store) => store.session.isInEdit);
5252
5353 useWebviewListener(
5454 "newSession",
5555 async () => {
5656 navigate(ROUTES.HOME);
57- if (mode === "edit") {
58- await dispatch(exitEditMode({}));
57+ if (isInEdit) {
58+ await dispatch(exitEdit({}));
5959 } else {
6060 await dispatch(
6161 saveCurrentSession({
@@ -65,7 +65,7 @@
6565 );
6666 }
6767 },
68- [mode],
68+ [isInEdit],
6969 );
7070
7171 useWebviewListener(
@@ -81,9 +81,9 @@
8181 "focusContinueInputWithNewSession",
8282 async () => {
8383 navigate(ROUTES.HOME);
84- if (mode === "edit") {
84+ if (isInEdit) {
8585 await dispatch(
86- exitEditMode({
86+ exitEdit({
8787 openNewSession: true,
8888 }),
8989 );
@@ -96,7 +96,7 @@
9696 );
9797 }
9898 },
99- [location.pathname, mode],
99+ [location.pathname, isInEdit],
100100 location.pathname === ROUTES.HOME,
101101 );
102102
@@ -148,7 +148,7 @@
148148 "focusEdit",
149149 async () => {
150150 await ideMessenger.request("edit/addCurrentSelection", undefined);
151- await dispatch(enterEditMode({}));
151+ await dispatch(enterEdit({ editorContent: mainEditor?.getJSON() }));
152152 mainEditor?.commands.focus();
153153 },
154154 [ideMessenger, mainEditor],
@@ -169,7 +169,7 @@
169169 useWebviewListener(
170170 "exitEditMode",
171171 async () => {
172- await dispatch(exitEditMode({}));
172+ await dispatch(exitEdit({}));
173173 },
174174 [],
175175 );
@@ -181,7 +181,7 @@
181181 if (selection) {
182182 // Copy to clipboard
183183 setTimeout(() => {
184- navigator.clipboard.writeText(selection);
184+ void navigator.clipboard.writeText(selection);
185185 }, 100);
186186 }
187187 }
added gui/src/components/ModeSelect/ModeIcon.tsx +19 −0
@@ -0,0 +1,19 @@
1+import { ChatBubbleLeftIcon, SparklesIcon } from "@heroicons/react/24/outline";
2+import { MessageModes } from "core";
3+
4+interface ModeIconProps {
5+ mode: MessageModes;
6+ className?: string;
7+}
8+
9+export function ModeIcon({
10+ mode,
11+ className = "xs:h-3 xs:w-3 h-3 w-3",
12+}: ModeIconProps) {
13+ switch (mode) {
14+ case "agent":
15+ return <SparklesIcon className={className} />;
16+ case "chat":
17+ return <ChatBubbleLeftIcon className={className} />;
18+ }
19+}
added gui/src/components/ModeSelect/ModeSelect.tsx +123 −0
@@ -0,0 +1,123 @@
1+import { CheckIcon, ChevronDownIcon } from "@heroicons/react/24/outline";
2+import { MessageModes } from "core";
3+import { modelSupportsTools } from "core/llm/autodetect";
4+import { useCallback, useEffect, useMemo } from "react";
5+import { useAppDispatch, useAppSelector } from "../../redux/hooks";
6+import { selectSelectedChatModel } from "../../redux/slices/configSlice";
7+import { setMode } from "../../redux/slices/sessionSlice";
8+import { getFontSize, getMetaKeyLabel } from "../../util";
9+import { useMainEditor } from "../mainInput/TipTapEditor";
10+import {
11+ Listbox,
12+ ListboxButton,
13+ ListboxOption,
14+ ListboxOptions,
15+} from "../ui/Listbox";
16+import { ModeIcon } from "./ModeIcon";
17+
18+export function ModeSelect() {
19+ const dispatch = useAppDispatch();
20+ const mode = useAppSelector((store) => store.session.mode);
21+ const selectedModel = useAppSelector(selectSelectedChatModel);
22+ const agentModeSupported = useMemo(() => {
23+ return selectedModel && modelSupportsTools(selectedModel);
24+ }, [selectedModel]);
25+ const { mainEditor } = useMainEditor();
26+ const metaKeyLabel = useMemo(() => {
27+ return getMetaKeyLabel();
28+ }, []);
29+
30+ // Switch to chat mode if agent mode is selected but not supported
31+ useEffect(() => {
32+ if (!selectedModel) {
33+ return;
34+ }
35+ if (mode === "agent" && !agentModeSupported) {
36+ dispatch(setMode("chat"));
37+ }
38+ }, [mode, agentModeSupported, dispatch, selectedModel]);
39+
40+ const cycleMode = useCallback(() => {
41+ dispatch(setMode(mode === "chat" ? "agent" : "chat"));
42+ mainEditor?.commands.focus();
43+ }, [mode, mainEditor]);
44+
45+ const selectMode = useCallback(
46+ (newMode: MessageModes) => {
47+ if (newMode === mode) {
48+ return;
49+ }
50+
51+ dispatch(setMode(newMode));
52+
53+ mainEditor?.commands.focus();
54+ },
55+ [mode, mainEditor],
56+ );
57+
58+ useEffect(() => {
59+ const handleKeyDown = (e: KeyboardEvent) => {
60+ if (e.key === "." && (e.metaKey || e.ctrlKey)) {
61+ e.preventDefault();
62+ void cycleMode();
63+ }
64+ };
65+
66+ document.addEventListener("keydown", handleKeyDown);
67+ return () => document.removeEventListener("keydown", handleKeyDown);
68+ }, [cycleMode]);
69+
70+ return (
71+ <Listbox value={mode} onChange={selectMode}>
72+ <div className="relative">
73+ <ListboxButton
74+ data-testid="mode-select-button"
75+ className="xs:px-2 text-description-muted bg-table-oddRow gap-1 rounded-full border-none px-1.5 py-0.5 transition-colors duration-200 hover:brightness-110"
76+ >
77+ <ModeIcon mode={mode} />
78+ <span className="hidden sm:block">
79+ {mode.charAt(0).toUpperCase() + mode.slice(1)}
80+ </span>
81+ <ChevronDownIcon
82+ className="h-2 w-2 flex-shrink-0"
83+ aria-hidden="true"
84+ />
85+ </ListboxButton>
86+ <ListboxOptions className="min-w-32 max-w-48">
87+ <ListboxOption value="chat">
88+ <div className="flex flex-row items-center gap-1.5">
89+ <ModeIcon mode="chat" />
90+ <span className="">Chat</span>
91+ <span
92+ className={`text-description-muted text-[${getFontSize() - 3}px] mr-auto`}
93+ >
94+ {getMetaKeyLabel()}L
95+ </span>
96+ </div>
97+ {mode === "chat" && <CheckIcon className="ml-auto h-3 w-3" />}
98+ </ListboxOption>
99+
100+ <ListboxOption
101+ value="agent"
102+ disabled={!agentModeSupported}
103+ className={"gap-1"}
104+ >
105+ <div className="flex flex-row items-center gap-1.5">
106+ <ModeIcon mode="agent" />
107+ <span className="">Agent</span>
108+ </div>
109+ {agentModeSupported ? (
110+ mode === "agent" && <CheckIcon className="ml-auto h-3 w-3" />
111+ ) : (
112+ <span>(Not supported)</span>
113+ )}
114+ </ListboxOption>
115+
116+ <div className="text-description-muted px-2 py-1">
117+ {`${metaKeyLabel} . for next mode`}
118+ </div>
119+ </ListboxOptions>
120+ </div>
121+ </Listbox>
122+ );
123+}
added gui/src/components/ModeSelect/index.ts +1 −0
@@ -0,0 +1,1 @@
1+export * from "./ModeSelect";
deleted gui/src/components/mainInput/CodeToEditCard.tsx +0 −181
@@ -1,181 +0,0 @@
1-import { ChevronRightIcon, XMarkIcon } from "@heroicons/react/24/outline";
2-import { SetCodeToEditPayload } from "core";
3-import { getMarkdownLanguageTagForFile } from "core/util";
4-import { getUriPathBasename } from "core/util/uri";
5-import { useContext, useMemo, useState } from "react";
6-import { useDispatch } from "react-redux";
7-import styled from "styled-components";
8-import { IdeMessengerContext } from "../../context/IdeMessenger";
9-import { useAppSelector } from "../../redux/hooks";
10-import { clearCodeToEdit } from "../../redux/slices/editModeState";
11-import { getMetaKeyLabel } from "../../util";
12-import FileIcon from "../FileIcon";
13-import StyledMarkdownPreview from "../StyledMarkdownPreview";
14-import { useFontSize } from "../ui/font";
15-
16-const NoPaddingWrapper = styled.div`
17- > * {
18- margin: 0 !important;
19- padding: 0 !important;
20- }
21-
22- pre {
23- margin: 0 !important;
24- padding: 0px 0px 0px 10px !important;
25- }
26-`;
27-
28-interface CodeToEditItemProps {
29- code: SetCodeToEditPayload;
30-}
31-
32-function CodeToEditItem({ code }: CodeToEditItemProps) {
33- const dispatch = useDispatch();
34- const ideMessenger = useContext(IdeMessengerContext);
35- const [showCodeSnippet, setShowCodeSnippet] = useState(false);
36-
37- function onDelete() {
38- dispatch(clearCodeToEdit());
39- ideMessenger.post("edit/clearDecorations", undefined);
40- }
41-
42- const fileName = getUriPathBasename(code.filepath);
43-
44- let isInsertion = false;
45- let title = fileName;
46-
47- if ("range" in code) {
48- const start = code.range.start.line + 1;
49- const end = code.range.end.line + 1;
50-
51- isInsertion = start === end;
52-
53- title += isInsertion
54- ? ` - Inserting at line ${start}`
55- : ` (${start} - ${end})`;
56- }
57-
58- const source =
59- "```" +
60- getMarkdownLanguageTagForFile(code.filepath) +
61- "\n" +
62- code.contents +
63- "\n" +
64- "```";
65-
66- async function onClickFilename() {
67- if ("range" in code) {
68- await ideMessenger.ide.showLines(
69- code.filepath,
70- code.range.start.line,
71- code.range.end.line,
72- );
73- } else {
74- await ideMessenger.ide.openFile(code.filepath);
75- }
76- }
77-
78- const smallFont = useFontSize(-3);
79-
80- const iconClass =
81- "text-lightgray hover:bg-lightgray hover:text-vsc-foreground h-3.5 w-3.5 cursor-pointer rounded-sm p-0.5 hover:bg-opacity-20";
82-
83- return (
84- <div className="flex flex-col gap-1 py-0.5">
85- <div className="group flex flex-row items-center justify-start gap-1.5 px-1">
86- <span
87- className="hidden flex-shrink-0 pl-2 font-semibold text-gray-400 sm:flex"
88- style={{
89- fontSize: smallFont,
90- }}
91- >
92- Code to edit
93- </span>
94- {/* <CodeBracketIcon className="h-3 w-3 flex-shrink-0 text-gray-400 sm:hidden" /> */}
95- <div
96- className={`hover:bg-lightgray flex flex-1 cursor-pointer items-center justify-between rounded transition-colors hover:bg-opacity-20 ${showCodeSnippet && "bg-lightgray bg-opacity-20"}`}
97- onClick={() => {
98- if (!isInsertion) {
99- setShowCodeSnippet((showCodeSnippet) => !showCodeSnippet);
100- }
101- }}
102- >
103- <div className="flex items-center gap-0.5">
104- <FileIcon filename={code.filepath} height={"18px"} width={"18px"} />
105- <span
106- className="line-clamp-1 text-xs hover:underline"
107- onClick={(e) => {
108- e.stopPropagation();
109- void onClickFilename();
110- }}
111- >
112- {title}
113- </span>
114- </div>
115-
116- <div className="invisible flex items-center group-hover:visible">
117- <ChevronRightIcon
118- onClick={(e) => {
119- e.stopPropagation();
120- setShowCodeSnippet((val) => !val);
121- }}
122- className={`text-lightgray hover:bg-lightgray hover:text-vsc-foreground h-3.5 w-3.5 cursor-pointer rounded-sm p-0.5 hover:bg-opacity-20 ${showCodeSnippet ? "rotate-90" : ""} ${isInsertion ? "hidden" : ""}`}
123- />
124- <div className="flex items-center">
125- <XMarkIcon
126- onClick={(e) => {
127- e.stopPropagation();
128- void onDelete();
129- }}
130- className={iconClass}
131- />
132- </div>
133- </div>
134- </div>
135- </div>
136- {showCodeSnippet && (
137- <div className="!m-0 max-h-48 overflow-y-auto !p-0">
138- <NoPaddingWrapper>
139- <StyledMarkdownPreview source={source} />
140- </NoPaddingWrapper>
141- </div>
142- )}
143- </div>
144- );
145-}
146-
147-export default function CodeToEditCard() {
148- // Array from previous multi-file edit
149- const codeToEditArray = useAppSelector(
150- (state) => state.editModeState.codeToEdit,
151- );
152- const codeToEdit = useMemo(() => {
153- return codeToEditArray[0];
154- }, [codeToEditArray]);
155-
156- const metaKeyLabel = useMemo(() => {
157- return getMetaKeyLabel();
158- }, []);
159-
160- const tinyFont = useFontSize(-3);
161-
162- return (
163- <div className="bg-vsc-editor-background mx-3 flex flex-col rounded-t-lg py-1">
164- {codeToEdit ? (
165- <CodeToEditItem code={codeToEdit} />
166- ) : (
167- <>
168- <span
169- className="text-balance px-3 text-center font-semibold text-gray-400"
170- style={{
171- fontSize: tinyFont,
172- }}
173- >
174- {`To edit code, highlight it and press `}
175- <kbd>{metaKeyLabel}</kbd> <kbd>I</kbd>
176- </span>
177- </>
178- )}
179- </div>
180- );
181-}
modified gui/src/components/mainInput/ContinueInputBox.tsx +17 −18
@@ -83,15 +83,15 @@
8383 const availableContextProviders = useAppSelector(
8484 (state) => state.config.config.contextProviders,
8585 );
86- const mode = useAppSelector((store) => store.session.mode);
86+ const isInEdit = useAppSelector((store) => store.session.isInEdit);
8787 const editModeState = useAppSelector((state) => state.editModeState);
8888
8989 const filteredSlashCommands = useMemo(() => {
90- return mode === "edit" ? [] : availableSlashCommands;
91- }, [mode, availableSlashCommands]);
90+ return isInEdit ? [] : availableSlashCommands;
91+ }, [isInEdit, availableSlashCommands]);
9292
9393 const filteredContextProviders = useMemo(() => {
94- if (mode === "edit") {
94+ if (isInEdit) {
9595 return (
9696 availableContextProviders?.filter(
9797 (provider) =>
@@ -101,22 +101,21 @@
101101 }
102102
103103 return availableContextProviders ?? [];
104- }, [availableContextProviders, mode]);
104+ }, [availableContextProviders, isInEdit]);
105105
106- const historyKey = mode === "edit" ? "edit" : "chat";
107- const placeholder = mode === "edit" ? "Describe changes" : undefined;
106+ const historyKey = isInEdit ? "edit" : "chat";
107+ const placeholder = isInEdit ? "Edit selected code" : undefined;
108108
109- const toolbarOptions: ToolbarOptions =
110- mode === "edit"
111- ? {
112- hideAddContext: false,
113- hideImageUpload: false,
114- hideUseCodebase: true,
115- hideSelectModel: false,
116- enterText:
117- editModeState.applyState.status === "done" ? "Retry" : "Edit",
118- }
119- : {};
109+ const toolbarOptions: ToolbarOptions = isInEdit
110+ ? {
111+ hideAddContext: false,
112+ hideImageUpload: false,
113+ hideUseCodebase: true,
114+ hideSelectModel: false,
115+ enterText:
116+ editModeState.applyState.status === "done" ? "Retry" : "Edit",
117+ }
118+ : {};
120119
121120 const { appliedRules = [], contextItems = [] } = props;
122121
deleted gui/src/components/mainInput/EditModeDetails.tsx +0 −59
@@ -1,59 +0,0 @@
1-import { useContext } from "react";
2-import { IdeMessengerContext } from "../../context/IdeMessenger";
3-import { useAppDispatch, useAppSelector } from "../../redux/hooks";
4-import { exitEditMode } from "../../redux/thunks/editMode";
5-import AcceptRejectDiffButtons from "../AcceptRejectDiffButtons";
6-import { useMainEditor } from "./TipTapEditor";
7-
8-const EditModeDetails = () => {
9- const isStreaming = useAppSelector((store) => store.session.isStreaming);
10- const mode = useAppSelector((store) => store.session.mode);
11- const dispatch = useAppDispatch();
12- const editApplyState = useAppSelector(
13- (store) => store.editModeState.applyState,
14- );
15- const { mainEditor } = useMainEditor();
16- const ideMessenger = useContext(IdeMessengerContext);
17-
18- if (mode !== "edit") {
19- return null;
20- }
21- if (isStreaming) {
22- return null;
23- }
24- if (editApplyState.status === "done") {
25- const plural = editApplyState.numDiffs === 1 ? "" : "s";
26- return (
27- <>
28- <div className="flex flex-col items-center justify-center pb-1 pt-3 text-xs italic text-gray-400">
29- <span className="">{`${editApplyState.numDiffs} diff${plural} remaining`}</span>
30- </div>
31- <AcceptRejectDiffButtons
32- applyStates={[editApplyState]}
33- onAcceptOrReject={async (outcome) => {
34- if (outcome === "acceptDiff") {
35- await dispatch(exitEditMode({}));
36- ideMessenger.post("focusEditor", undefined);
37- } else {
38- mainEditor?.commands.focus();
39- }
40- }}
41- />
42- </>
43- );
44- }
45-
46- // Will only still show if not all accepted
47- if (editApplyState.status === "closed") {
48- return (
49- <div>
50- <span></span>
51- </div>
52- );
53- }
54-
55- // Not started/streaming
56- return null;
57-};
58-
59-export default EditModeDetails;
modified gui/src/components/mainInput/InputToolbar.tsx +18 −16
@@ -10,7 +10,7 @@
1010 selectCurrentToolCallApplyState,
1111 } from "../../redux/selectors/selectCurrentToolCall";
1212 import { selectSelectedChatModel } from "../../redux/slices/configSlice";
13-import { exitEditMode } from "../../redux/thunks/editMode";
13+import { exitEdit } from "../../redux/thunks/edit";
1414 import {
1515 getAltKeyLabel,
1616 getMetaKeyLabel,
@@ -18,7 +18,7 @@
1818 } from "../../util";
1919 import { ToolTip } from "../gui/Tooltip";
2020 import ModelSelect from "../modelSelection/ModelSelect";
21-import ModeSelect from "../modelSelection/ModeSelect";
21+import { ModeSelect } from "../ModeSelect";
2222 import { useFontSize } from "../ui/font";
2323 import { EnterButton } from "./InputToolbar/EnterButton";
2424 import HoverItem from "./InputToolbar/HoverItem";
@@ -49,7 +49,7 @@
4949 const fileInputRef = useRef<HTMLInputElement | null>(null);
5050 const defaultModel = useAppSelector(selectSelectedChatModel);
5151 const useActiveFile = useAppSelector(selectUseActiveFile);
52- const mode = useAppSelector((store) => store.session.mode);
52+ const isInEdit = useAppSelector((store) => store.session.isInEdit);
5353 const codeToEdit = useAppSelector((store) => store.editModeState.codeToEdit);
5454 const toolCallState = useAppSelector(selectCurrentToolCall);
5555 const currentToolCallApplyState = useAppSelector(
@@ -58,7 +58,7 @@
5858
5959 const isEnterDisabled =
6060 props.disabled ||
61- (mode === "edit" && codeToEdit.length === 0) ||
61+ (isInEdit && codeToEdit.length === 0) ||
6262 toolCallState?.status === "generated" ||
6363 (currentToolCallApplyState &&
6464 currentToolCallApplyState.status !== "closed");
@@ -87,19 +87,21 @@
8787 }}
8888 >
8989 <div className="xs:gap-1.5 flex flex-row items-center gap-1">
90- <HoverItem data-tooltip-id="mode-select-tooltip" className="!p-0">
91- <ModeSelect />
92- <ToolTip id="mode-select-tooltip" place="top">
93- Select Mode
94- </ToolTip>
95- </HoverItem>
90+ {!isInEdit && (
91+ <HoverItem data-tooltip-id="mode-select-tooltip" className="!p-0">
92+ <ModeSelect />
93+ <ToolTip id="mode-select-tooltip" place="top">
94+ Select Mode
95+ </ToolTip>
96+ </HoverItem>
97+ )}
9698 <HoverItem data-tooltip-id="model-select-tooltip" className="!p-0">
9799 <ModelSelect />
98100 <ToolTip id="model-select-tooltip" place="top">
99101 Select Model
100102 </ToolTip>
101103 </HoverItem>
102- <div className="xs:flex -mb-1 hidden items-center text-gray-400 transition-colors duration-200">
104+ <div className="xs:flex text-description -mb-1 hidden items-center transition-colors duration-200">
103105 {props.toolbarOptions?.hideImageUpload ||
104106 (supportsImages && (
105107 <>
@@ -149,12 +151,12 @@
149151 </div>
150152
151153 <div
152- className="flex items-center gap-2 whitespace-nowrap text-gray-400"
154+ className="text-description flex items-center gap-2 whitespace-nowrap"
153155 style={{
154156 fontSize: tinyFont,
155157 }}
156158 >
157- {!props.toolbarOptions?.hideUseCodebase && mode !== "edit" && (
159+ {!props.toolbarOptions?.hideUseCodebase && !isInEdit && (
158160 <div
159161 className={`${toolsSupported ? "md:flex" : "int:flex"} hover:underline" hidden transition-colors duration-200`}
160162 >
@@ -184,16 +186,16 @@
184186 </div>
185187 )}
186188
187- {mode === "edit" && (
189+ {isInEdit && (
188190 <HoverItem
189191 className="hidden hover:underline sm:flex"
190192 onClick={async () => {
191- dispatch(exitEditMode({}));
193+ void dispatch(exitEdit({}));
192194 ideMessenger.post("focusEditor", undefined);
193195 }}
194196 >
195197 <span>
196- <i>Esc</i> to exit
198+ <i>Esc</i> to exit Edit
197199 </span>
198200 </HoverItem>
199201 )}
deleted gui/src/components/mainInput/Lump/BlockSettingsTopToolbar.tsx +0 −206
@@ -1,206 +0,0 @@
1-import {
2- BookOpenIcon,
3- ChatBubbleLeftIcon,
4- ChevronLeftIcon,
5- CubeIcon,
6- EllipsisHorizontalIcon,
7- ExclamationTriangleIcon,
8- PencilIcon,
9- Squares2X2Icon,
10- WrenchScrewdriverIcon,
11-} from "@heroicons/react/24/outline";
12-import { ReactNode } from "react";
13-import { vscBadgeForeground } from "../..";
14-import { useAppSelector } from "../../../redux/hooks";
15-import { ToolTip } from "../../gui/Tooltip";
16-import AssistantSelect from "../../modelSelection/platform/AssistantSelect";
17-import { useFontSize } from "../../ui/font";
18-import HoverItem from "../InputToolbar/HoverItem";
19-import { useLump } from "./LumpContext";
20-import { ErrorsSectionTooltip } from "./sections/errors/ErrorsSectionTooltip";
21-import { McpSectionTooltip } from "./sections/mcp/MCPTooltip";
22-import { ToolsSectionTooltip } from "./sections/tool-policies/ToolPoliciesSectionTooltip";
23-
24-interface BlockSettingsToolbarIcon {
25- title: string;
26- tooltip: ReactNode;
27- icon: React.ComponentType<any>;
28- itemCount?: number;
29- onClick: () => void;
30- isSelected?: boolean;
31- className?: string;
32-}
33-
34-interface Section {
35- id: string;
36- title: string;
37- tooltip: ReactNode;
38- icon: React.ComponentType<any>;
39-}
40-
41-const sections: Section[] = [
42- { id: "models", title: "Models", tooltip: "Models", icon: CubeIcon },
43- { id: "rules", title: "Rules", tooltip: "Rules", icon: PencilIcon },
44- { id: "docs", title: "Docs", tooltip: "Docs", icon: BookOpenIcon },
45- {
46- id: "prompts",
47- title: "Prompts",
48- tooltip: "Prompts",
49- icon: ChatBubbleLeftIcon,
50- },
51- {
52- id: "tools",
53- title: "Tools",
54- tooltip: <ToolsSectionTooltip />,
55- icon: WrenchScrewdriverIcon,
56- },
57- {
58- id: "mcp",
59- title: "MCP",
60- tooltip: <McpSectionTooltip />,
61- icon: Squares2X2Icon,
62- },
63- {
64- id: "error",
65- title: "Errors",
66- tooltip: <ErrorsSectionTooltip />,
67- icon: ExclamationTriangleIcon,
68- },
69-];
70-
71-function BlockSettingsToolbarIcon(
72- props: BlockSettingsToolbarIcon & { sectionId?: string },
73-) {
74- const isErrorSection = props.sectionId === "error";
75-
76- const id = `block-settings-toolbar-icon-${props.sectionId}`;
77-
78- const fontSize = useFontSize(-3);
79- return (
80- <>
81- <HoverItem
82- px={0}
83- onClick={props.onClick}
84- data-testid={id}
85- data-tooltip-id={id}
86- >
87- <div
88- role="button"
89- tabIndex={0}
90- onKeyDown={(e) => {
91- if (e.key === "Enter" || e.key === " ") {
92- e.preventDefault();
93- props.onClick();
94- }
95- }}
96- className={`${
97- props.isSelected
98- ? isErrorSection
99- ? "bg-red-600"
100- : "bg-badge"
101- : undefined
102- } relative flex select-none items-center rounded-full px-[3px] transition-all duration-200 focus:outline-none focus-visible:ring-2 focus-visible:ring-blue-500/50 sm:px-1 ${props.className || ""}`}
103- >
104- <props.icon
105- className={`h-[13px] w-[13px] flex-shrink-0 hover:brightness-125 ${
106- isErrorSection ? "text-red-600" : ""
107- }`}
108- style={{
109- color: props.isSelected ? vscBadgeForeground : undefined,
110- }}
111- aria-hidden="true"
112- />
113- <div
114- style={{ fontSize }}
115- className={`overflow-hidden transition-all duration-200 ${
116- props.isSelected ? "ml-1 w-auto opacity-100" : "w-0 opacity-0"
117- }`}
118- >
119- <span
120- className="whitespace-nowrap"
121- style={{ color: vscBadgeForeground }}
122- >
123- {props.title}
124- </span>
125- </div>
126- </div>
127- </HoverItem>
128- <ToolTip delayShow={700} id={id}>
129- {props.tooltip}
130- </ToolTip>
131- </>
132- );
133-}
134-
135-export function BlockSettingsTopToolbar() {
136- const {
137- isToolbarExpanded,
138- toggleToolbar,
139- selectedSection,
140- setSelectedSection,
141- } = useLump();
142-
143- const configError = useAppSelector((store) => store.config.configError);
144-
145- const handleEllipsisClick = () => {
146- if (isToolbarExpanded) {
147- setSelectedSection(null);
148- }
149- toggleToolbar();
150- };
151-
152- const visibleSections = sections.filter(
153- (section) =>
154- section.id !== "error" ||
155- (section.id === "error" && configError && configError?.length > 0),
156- );
157-
158- return (
159- <div className="flex flex-1 items-center justify-between gap-2">
160- <div className="flex flex-row">
161- <div className="xs:flex hidden items-center justify-center text-gray-400">
162- <BlockSettingsToolbarIcon
163- className="-ml-1.5"
164- icon={isToolbarExpanded ? ChevronLeftIcon : EllipsisHorizontalIcon}
165- tooltip={isToolbarExpanded ? "Collapse Toolbar" : "Expand Toolbar"}
166- title=""
167- isSelected={false}
168- onClick={handleEllipsisClick}
169- />
170- <div
171- className={`${isToolbarExpanded ? "w-min" : "w-0"} flex overflow-hidden transition-all duration-200`}
172- >
173- <div className="flex">
174- {visibleSections.map((section) => (
175- <BlockSettingsToolbarIcon
176- key={section.id}
177- sectionId={section.id}
178- icon={section.icon}
179- tooltip={section.tooltip}
180- title={section.title}
181- isSelected={selectedSection === section.id}
182- onClick={() =>
183- setSelectedSection(
184- selectedSection === section.id ? null : section.id,
185- )
186- }
187- />
188- ))}
189- </div>
190- </div>
191- </div>
192- </div>
193- <div className="flex gap-0.5">
194- <HoverItem
195- data-tooltip-id="assistant-select-tooltip"
196- className="!m-0 !p-0"
197- >
198- <AssistantSelect />
199- <ToolTip id="assistant-select-tooltip" place="top">
200- Select Assistant
201- </ToolTip>
202- </HoverItem>
203- </div>
204- </div>
205- );
206-}
deleted gui/src/components/mainInput/Lump/LumpToolbar.tsx +0 −174
@@ -1,174 +0,0 @@
1-import { useContext, useEffect, useMemo } from "react";
2-import { useSelector } from "react-redux";
3-import styled from "styled-components";
4-import { AnimatedEllipsis } from "../..";
5-import { IdeMessengerContext } from "../../../context/IdeMessenger";
6-import { useAppDispatch, useAppSelector } from "../../../redux/hooks";
7-import { selectCurrentToolCall } from "../../../redux/selectors/selectCurrentToolCall";
8-import { callCurrentTool } from "../../../redux/thunks/callCurrentTool";
9-import { cancelCurrentToolCall } from "../../../redux/thunks/cancelCurrentToolCall";
10-import { cancelStream } from "../../../redux/thunks/cancelStream";
11-import {
12- getAltKeyLabel,
13- getFontSize,
14- getMetaKeyLabel,
15- isJetBrains,
16-} from "../../../util";
17-import { EnterButton } from "../InputToolbar/EnterButton";
18-import { BlockSettingsTopToolbar } from "./BlockSettingsTopToolbar";
19-
20-const Container = styled.div`
21- display: flex;
22- justify-content: space-between;
23- align-items: center;
24- width: 100%;
25-`;
26-
27-const StopButton = styled.div`
28- font-size: ${getFontSize() - 3}px;
29- padding: 2px;
30- padding-right: 4px;
31- cursor: pointer;
32-`;
33-
34-function GeneratingIndicator() {
35- return (
36- <div className="text-xs text-gray-400">
37- <span>Generating</span>
38- <AnimatedEllipsis />
39- </div>
40- );
41-}
42-
43-function ApplyingIndicator() {
44- return (
45- <div className="text-xs text-gray-400">
46- <span>Applying</span>
47- <AnimatedEllipsis />
48- </div>
49- );
50-}
51-
52-export function LumpToolbar() {
53- const dispatch = useAppDispatch();
54- const ideMessenger = useContext(IdeMessengerContext);
55- const ttsActive = useAppSelector((state) => state.ui.ttsActive);
56- const isStreaming = useAppSelector((state) => state.session.isStreaming);
57- const jetbrains = isJetBrains();
58- const applyStates = useAppSelector(
59- (store) => store.session.codeBlockApplyStates.states,
60- );
61- const isApplying = useMemo(() => {
62- return applyStates.find((state) => state.status === "streaming");
63- }, [applyStates]);
64-
65- const toolCallState = useSelector(selectCurrentToolCall);
66-
67- const handleKeyDown = (event: KeyboardEvent) => {
68- if (toolCallState?.status === "generated") {
69- const metaKey = event.metaKey || event.ctrlKey;
70- const altKey = event.altKey;
71-
72- if (metaKey && event.key === "Enter") {
73- event.preventDefault();
74- event.stopPropagation();
75- dispatch(callCurrentTool());
76- } else if ((jetbrains ? altKey : metaKey) && event.key === "Backspace") {
77- event.preventDefault();
78- event.stopPropagation();
79- dispatch(cancelCurrentToolCall());
80- }
81- }
82- };
83-
84- useEffect(() => {
85- document.addEventListener("keydown", handleKeyDown);
86- return () => {
87- document.removeEventListener("keydown", handleKeyDown);
88- };
89- }, [toolCallState]);
90-
91- if (ttsActive) {
92- return (
93- <Container>
94- <GeneratingIndicator />
95- <StopButton
96- className="text-gray-400"
97- onClick={() => {
98- ideMessenger.post("tts/kill", undefined);
99- }}
100- >
101- ■ Stop TTS
102- </StopButton>
103- </Container>
104- );
105- }
106-
107- if (isApplying) {
108- return (
109- <Container>
110- <ApplyingIndicator />
111- <StopButton
112- className="text-gray-400"
113- onClick={() => {
114- // Note that this will NOT stop generation but once apply is cancelled will show the Generating/cancel option
115- // Apply is prioritized because it can be more catastrophic
116- // Intentional to be more WYSIWYG for now
117- ideMessenger.post("cancelApply", undefined);
118- }}
119- >
120- {/* JetBrains overrides cmd+backspace, so we have to use another shortcut */}
121- {jetbrains ? getAltKeyLabel() : getMetaKeyLabel()} ⌫ Cancel
122- </StopButton>
123- </Container>
124- );
125- }
126-
127- if (isStreaming) {
128- return (
129- <Container>
130- <GeneratingIndicator />
131- <StopButton
132- className="text-gray-400"
133- onClick={() => {
134- dispatch(cancelStream());
135- }}
136- >
137- {/* JetBrains overrides cmd+backspace, so we have to use another shortcut */}
138- {jetbrains ? getAltKeyLabel() : getMetaKeyLabel()} ⌫ Cancel
139- </StopButton>
140- </Container>
141- );
142- }
143-
144- if (toolCallState?.status === "generated") {
145- return (
146- <Container>
147- <div className="flex flex-row items-center pb-0.5 pr-1 text-xs text-gray-400">
148- <span className="hidden sm:flex">Pending tool call</span>
149- </div>
150-
151- <div className="flex gap-2 pb-0.5">
152- <StopButton
153- className="text-gray-400"
154- onClick={() => dispatch(cancelCurrentToolCall())}
155- data-testid="reject-tool-call-button"
156- >
157- {/* JetBrains overrides cmd+backspace, so we have to use another shortcut */}
158- {jetbrains ? getAltKeyLabel() : getMetaKeyLabel()} ⌫ Cancel
159- </StopButton>
160- <EnterButton
161- isPrimary={true}
162- className="text-gray-400"
163- onClick={() => dispatch(callCurrentTool())}
164- data-testid="accept-tool-call-button"
165- >
166- {getMetaKeyLabel()} ⏎ Continue
167- </EnterButton>
168- </div>
169- </Container>
170- );
171- }
172-
173- return <BlockSettingsTopToolbar />;
174-}
added gui/src/components/mainInput/Lump/LumpToolbar/BlockSettingsTopToolbar.tsx +206 −0
@@ -0,0 +1,206 @@
1+import {
2+ BookOpenIcon,
3+ ChatBubbleLeftIcon,
4+ ChevronLeftIcon,
5+ CubeIcon,
6+ EllipsisHorizontalIcon,
7+ ExclamationTriangleIcon,
8+ PencilIcon,
9+ Squares2X2Icon,
10+ WrenchScrewdriverIcon,
11+} from "@heroicons/react/24/outline";
12+import { ReactNode } from "react";
13+import { vscBadgeForeground } from "../../..";
14+import { useAppSelector } from "../../../../redux/hooks";
15+import { ToolTip } from "../../../gui/Tooltip";
16+import AssistantSelect from "../../../modelSelection/platform/AssistantSelect";
17+import { useFontSize } from "../../../ui/font";
18+import HoverItem from "../../InputToolbar/HoverItem";
19+import { useLump } from "../LumpContext";
20+import { ErrorsSectionTooltip } from "../sections/errors/ErrorsSectionTooltip";
21+import { McpSectionTooltip } from "../sections/mcp/MCPTooltip";
22+import { ToolsSectionTooltip } from "../sections/tool-policies/ToolPoliciesSectionTooltip";
23+
24+interface BlockSettingsToolbarIcon {
25+ title: string;
26+ tooltip: ReactNode;
27+ icon: React.ComponentType<any>;
28+ itemCount?: number;
29+ onClick: () => void;
30+ isSelected?: boolean;
31+ className?: string;
32+}
33+
34+interface Section {
35+ id: string;
36+ title: string;
37+ tooltip: ReactNode;
38+ icon: React.ComponentType<any>;
39+}
40+
41+const sections: Section[] = [
42+ { id: "models", title: "Models", tooltip: "Models", icon: CubeIcon },
43+ { id: "rules", title: "Rules", tooltip: "Rules", icon: PencilIcon },
44+ { id: "docs", title: "Docs", tooltip: "Docs", icon: BookOpenIcon },
45+ {
46+ id: "prompts",
47+ title: "Prompts",
48+ tooltip: "Prompts",
49+ icon: ChatBubbleLeftIcon,
50+ },
51+ {
52+ id: "tools",
53+ title: "Tools",
54+ tooltip: <ToolsSectionTooltip />,
55+ icon: WrenchScrewdriverIcon,
56+ },
57+ {
58+ id: "mcp",
59+ title: "MCP",
60+ tooltip: <McpSectionTooltip />,
61+ icon: Squares2X2Icon,
62+ },
63+ {
64+ id: "error",
65+ title: "Errors",
66+ tooltip: <ErrorsSectionTooltip />,
67+ icon: ExclamationTriangleIcon,
68+ },
69+];
70+
71+function BlockSettingsToolbarIcon(
72+ props: BlockSettingsToolbarIcon & { sectionId?: string },
73+) {
74+ const isErrorSection = props.sectionId === "error";
75+
76+ const id = `block-settings-toolbar-icon-${props.sectionId}`;
77+
78+ const fontSize = useFontSize(-3);
79+ return (
80+ <>
81+ <HoverItem
82+ px={0}
83+ onClick={props.onClick}
84+ data-testid={id}
85+ data-tooltip-id={id}
86+ >
87+ <div
88+ role="button"
89+ tabIndex={0}
90+ onKeyDown={(e) => {
91+ if (e.key === "Enter" || e.key === " ") {
92+ e.preventDefault();
93+ props.onClick();
94+ }
95+ }}
96+ className={`${
97+ props.isSelected
98+ ? isErrorSection
99+ ? "bg-error"
100+ : "bg-badge"
101+ : undefined
102+ } relative flex select-none items-center rounded-full px-[3px] transition-all duration-200 focus:outline-none focus-visible:ring-2 focus-visible:ring-blue-500/50 sm:px-1 ${props.className || ""}`}
103+ >
104+ <props.icon
105+ className={`h-[13px] w-[13px] flex-shrink-0 hover:brightness-125 ${
106+ isErrorSection ? "text-error" : ""
107+ }`}
108+ style={{
109+ color: props.isSelected ? vscBadgeForeground : undefined,
110+ }}
111+ aria-hidden="true"
112+ />
113+ <div
114+ style={{ fontSize }}
115+ className={`overflow-hidden transition-all duration-200 ${
116+ props.isSelected ? "ml-1 w-auto opacity-100" : "w-0 opacity-0"
117+ }`}
118+ >
119+ <span
120+ className="whitespace-nowrap"
121+ style={{ color: vscBadgeForeground }}
122+ >
123+ {props.title}
124+ </span>
125+ </div>
126+ </div>
127+ </HoverItem>
128+ <ToolTip delayShow={700} id={id}>
129+ {props.tooltip}
130+ </ToolTip>
131+ </>
132+ );
133+}
134+
135+export function BlockSettingsTopToolbar() {
136+ const {
137+ isToolbarExpanded,
138+ toggleToolbar,
139+ selectedSection,
140+ setSelectedSection,
141+ } = useLump();
142+
143+ const configError = useAppSelector((store) => store.config.configError);
144+
145+ const handleEllipsisClick = () => {
146+ if (isToolbarExpanded) {
147+ setSelectedSection(null);
148+ }
149+ toggleToolbar();
150+ };
151+
152+ const visibleSections = sections.filter(
153+ (section) =>
154+ section.id !== "error" ||
155+ (section.id === "error" && configError && configError?.length > 0),
156+ );
157+
158+ return (
159+ <div className="flex flex-1 items-center justify-between gap-2">
160+ <div className="flex flex-row">
161+ <div className="xs:flex text-description hidden items-center justify-center">
162+ <BlockSettingsToolbarIcon
163+ className="-ml-1.5"
164+ icon={isToolbarExpanded ? ChevronLeftIcon : EllipsisHorizontalIcon}
165+ tooltip={isToolbarExpanded ? "Collapse Toolbar" : "Expand Toolbar"}
166+ title=""
167+ isSelected={false}
168+ onClick={handleEllipsisClick}
169+ />
170+ <div
171+ className={`${isToolbarExpanded ? "w-min" : "w-0"} flex overflow-hidden transition-all duration-200`}
172+ >
173+ <div className="flex">
174+ {visibleSections.map((section) => (
175+ <BlockSettingsToolbarIcon
176+ key={section.id}
177+ sectionId={section.id}
178+ icon={section.icon}
179+ tooltip={section.tooltip}
180+ title={section.title}
181+ isSelected={selectedSection === section.id}
182+ onClick={() =>
183+ setSelectedSection(
184+ selectedSection === section.id ? null : section.id,
185+ )
186+ }
187+ />
188+ ))}
189+ </div>
190+ </div>
191+ </div>
192+ </div>
193+ <div className="flex gap-0.5">
194+ <HoverItem
195+ data-tooltip-id="assistant-select-tooltip"
196+ className="!m-0 !p-0"
197+ >
198+ <AssistantSelect />
199+ <ToolTip id="assistant-select-tooltip" place="top">
200+ Select Assistant
201+ </ToolTip>
202+ </HoverItem>
203+ </div>
204+ </div>
205+ );
206+}
added gui/src/components/mainInput/Lump/LumpToolbar/EditOutcomeToolbar.tsx +34 −0
@@ -0,0 +1,34 @@
1+import { useContext } from "react";
2+import { IdeMessengerContext } from "../../../../context/IdeMessenger";
3+import { useAppDispatch, useAppSelector } from "../../../../redux/hooks";
4+import { exitEdit } from "../../../../redux/thunks/edit";
5+import AcceptRejectDiffButtons from "../../../AcceptRejectDiffButtons";
6+import { useMainEditor } from "../../TipTapEditor";
7+
8+export function EditOutcomeToolbar() {
9+ const dispatch = useAppDispatch();
10+ const editApplyState = useAppSelector(
11+ (store) => store.editModeState.applyState,
12+ );
13+ const { mainEditor } = useMainEditor();
14+ const ideMessenger = useContext(IdeMessengerContext);
15+
16+ return (
17+ <div className="text-description-muted flex items-center justify-between py-0.5 text-xs">
18+ <div className="bg-badge rounded px-1.5">
19+ <span>{`${editApplyState.numDiffs} diff${editApplyState.numDiffs !== 1 ? "s" : ""}`}</span>
20+ </div>
21+ <AcceptRejectDiffButtons
22+ applyStates={[editApplyState]}
23+ onAcceptOrReject={async (outcome) => {
24+ if (outcome === "acceptDiff") {
25+ await dispatch(exitEdit({}));
26+ ideMessenger.post("focusEditor", undefined);
27+ } else {
28+ mainEditor?.commands.focus();
29+ }
30+ }}
31+ />
32+ </div>
33+ );
34+}
added gui/src/components/mainInput/Lump/LumpToolbar/EditToolbar.tsx +38 −0
@@ -0,0 +1,38 @@
1+import { ArrowLeftIcon } from "@heroicons/react/24/outline";
2+import { useContext } from "react";
3+import { IdeMessengerContext } from "../../../../context/IdeMessenger";
4+import { useAppDispatch, useAppSelector } from "../../../../redux/hooks";
5+import { exitEdit } from "../../../../redux/thunks";
6+import { getEditFilenameAndRangeText } from "../../util";
7+
8+export function EditToolbar() {
9+ const dispatch = useAppDispatch();
10+ const ideMessenger = useContext(IdeMessengerContext);
11+ const mode = useAppSelector((state) => state.session.mode);
12+ const codeToEdit = useAppSelector(
13+ (state) => state.editModeState.codeToEdit[0],
14+ );
15+
16+ const handleBackClick = async () => {
17+ void dispatch(exitEdit({}));
18+ ideMessenger.post("focusEditor", undefined);
19+ };
20+
21+ return (
22+ <div className="text-description-muted flex items-center justify-between gap-3 text-xs">
23+ <span
24+ className="flex cursor-pointer items-center whitespace-nowrap hover:brightness-125"
25+ onClick={handleBackClick}
26+ >
27+ <ArrowLeftIcon className="mr-1 h-2.5 w-2.5" />
28+ Back to {mode.charAt(0).toUpperCase() + mode.slice(1)}
29+ </span>
30+ <span className="truncate">
31+ Editing{" "}
32+ <span className="italic">
33+ {getEditFilenameAndRangeText(codeToEdit)}
34+ </span>
35+ </span>
36+ </div>
37+ );
38+}
added gui/src/components/mainInput/Lump/LumpToolbar/GeneratingIndicator.tsx +14 −0
@@ -0,0 +1,14 @@
1+import { AnimatedEllipsis } from "../../..";
2+
3+export function GeneratingIndicator({
4+ text = "Generating",
5+}: {
6+ text?: string;
7+}) {
8+ return (
9+ <div className="text-description-muted text-xs">
10+ <span>{text}</span>
11+ <AnimatedEllipsis />
12+ </div>
13+ );
14+}
added gui/src/components/mainInput/Lump/LumpToolbar/IsApplyingToolbar.tsx +29 −0
@@ -0,0 +1,29 @@
1+import { useContext } from "react";
2+import { IdeMessengerContext } from "../../../../context/IdeMessenger";
3+import { getAltKeyLabel, getMetaKeyLabel } from "../../../../util";
4+import { Container, StopButton } from "./components";
5+import { GeneratingIndicator } from "./GeneratingIndicator";
6+
7+export const IsApplyingToolbar = () => {
8+ const ideMessenger = useContext(IdeMessengerContext);
9+
10+ const jetbrains = window.location.protocol === "jb-api:";
11+
12+ return (
13+ <Container>
14+ <GeneratingIndicator text="Applying" />
15+ <StopButton
16+ className="text-description"
17+ onClick={() => {
18+ // Note that this will NOT stop generation but once apply is cancelled will show the Generating/cancel option
19+ // Apply is prioritized because it can be more catastrophic
20+ // Intentional to be more WYSIWYG for now
21+ ideMessenger.post("cancelApply", undefined);
22+ }}
23+ >
24+ {/* JetBrains overrides cmd+backspace, so we have to use another shortcut */}
25+ {jetbrains ? getAltKeyLabel() : getMetaKeyLabel()} ⌫ Cancel
26+ </StopButton>
27+ </Container>
28+ );
29+};
added gui/src/components/mainInput/Lump/LumpToolbar/LumpToolbar.tsx +96 −0
@@ -0,0 +1,96 @@
1+import { useEffect } from "react";
2+import { useSelector } from "react-redux";
3+import { useAppDispatch, useAppSelector } from "../../../../redux/hooks";
4+import { selectCurrentToolCall } from "../../../../redux/selectors/selectCurrentToolCall";
5+import {
6+ callCurrentTool,
7+ cancelCurrentToolCall,
8+} from "../../../../redux/thunks";
9+import { isJetBrains } from "../../../../util";
10+import { BlockSettingsTopToolbar } from "./BlockSettingsTopToolbar";
11+import { EditOutcomeToolbar } from "./EditOutcomeToolbar";
12+import { EditToolbar } from "./EditToolbar";
13+import { IsApplyingToolbar } from "./IsApplyingToolbar";
14+import { PendingApplyStatesToolbar } from "./PendingApplyStatesToolbar";
15+import { PendingToolCallToolbar } from "./PendingToolCallToolbar";
16+import { StreamingToolbar } from "./StreamingToolbar";
17+import { TtsActiveToolbar } from "./TtsActiveToolbar";
18+
19+export function LumpToolbar() {
20+ const dispatch = useAppDispatch();
21+ const ttsActive = useAppSelector((state) => state.ui.ttsActive);
22+ const isStreaming = useAppSelector((state) => state.session.isStreaming);
23+ const isInEdit = useAppSelector((state) => state.session.isInEdit);
24+ const jetbrains = isJetBrains();
25+ const toolCallState = useSelector(selectCurrentToolCall);
26+ const editApplyState = useAppSelector(
27+ (state) => state.editModeState.applyState,
28+ );
29+ const applyStates = useAppSelector(
30+ (state) => state.session.codeBlockApplyStates.states,
31+ );
32+
33+ const pendingApplyStates = applyStates.filter(
34+ (state) => state.status === "done",
35+ );
36+
37+ const isApplying = applyStates.some((state) => state.status === "streaming");
38+
39+ useEffect(() => {
40+ if (toolCallState?.status !== "generated") {
41+ return;
42+ }
43+
44+ const handleKeyDown = (event: KeyboardEvent) => {
45+ const metaKey = event.metaKey || event.ctrlKey;
46+ const altKey = event.altKey;
47+
48+ if (metaKey && event.key === "Enter") {
49+ event.preventDefault();
50+ event.stopPropagation();
51+ void dispatch(callCurrentTool());
52+ } else if ((jetbrains ? altKey : metaKey) && event.key === "Backspace") {
53+ event.preventDefault();
54+ event.stopPropagation();
55+ void dispatch(cancelCurrentToolCall());
56+ }
57+ };
58+
59+ document.addEventListener("keydown", handleKeyDown);
60+ return () => {
61+ document.removeEventListener("keydown", handleKeyDown);
62+ };
63+ }, [toolCallState]);
64+
65+ if (isApplying) {
66+ return <IsApplyingToolbar />;
67+ }
68+
69+ if (isInEdit) {
70+ if (editApplyState.status === "done") {
71+ return <EditOutcomeToolbar />;
72+ }
73+
74+ return <EditToolbar />;
75+ }
76+
77+ if (ttsActive) {
78+ return <TtsActiveToolbar />;
79+ }
80+
81+ if (isStreaming) {
82+ return <StreamingToolbar />;
83+ }
84+
85+ if (toolCallState?.status === "generated") {
86+ return <PendingToolCallToolbar />;
87+ }
88+
89+ if (pendingApplyStates.length > 0) {
90+ return (
91+ <PendingApplyStatesToolbar pendingApplyStates={pendingApplyStates} />
92+ );
93+ }
94+
95+ return <BlockSettingsTopToolbar />;
96+}
added gui/src/components/mainInput/Lump/LumpToolbar/PendingApplyStatesToolbar.tsx +44 −0
@@ -0,0 +1,44 @@
1+import { ApplyState } from "core";
2+import { getUriPathBasename } from "core/util/uri";
3+import AcceptRejectDiffButtons from "../../../AcceptRejectDiffButtons";
4+import FileIcon from "../../../FileIcon";
5+
6+interface PendingApplyStatesToolbarProps {
7+ pendingApplyStates: ApplyState[];
8+}
9+
10+export function PendingApplyStatesToolbar({
11+ pendingApplyStates,
12+}: PendingApplyStatesToolbarProps) {
13+ // Group apply states by filepath
14+ const applyStatesByFilepath = pendingApplyStates.reduce(
15+ (acc, state) => {
16+ const filepath = state.filepath || ""; // Use empty string as fallback
17+ if (!acc[filepath]) {
18+ acc[filepath] = [];
19+ }
20+ acc[filepath].push(state);
21+ return acc;
22+ },
23+ {} as Record<string, ApplyState[]>,
24+ );
25+
26+ return (
27+ <div className="flex flex-col gap-2">
28+ {Object.entries(applyStatesByFilepath).map(([filepath, states]) => (
29+ <div key={filepath} className="flex justify-between gap-3">
30+ {filepath && (
31+ <span className="bg-badge flex items-center gap-1 rounded px-0.5">
32+ <FileIcon filename={filepath} height="18px" width="18px" />
33+ {getUriPathBasename(filepath)}
34+ </span>
35+ )}
36+ <AcceptRejectDiffButtons
37+ applyStates={states}
38+ onAcceptOrReject={async () => {}}
39+ />
40+ </div>
41+ ))}
42+ </div>
43+ );
44+}
added gui/src/components/mainInput/Lump/LumpToolbar/PendingToolCallToolbar.tsx +59 −0
@@ -0,0 +1,59 @@
1+import styled from "styled-components";
2+import { useAppDispatch } from "../../../../redux/hooks";
3+import {
4+ callCurrentTool,
5+ cancelCurrentToolCall,
6+} from "../../../../redux/thunks";
7+import {
8+ getAltKeyLabel,
9+ getFontSize,
10+ getMetaKeyLabel,
11+ isJetBrains,
12+} from "../../../../util";
13+import { EnterButton } from "../../InputToolbar/EnterButton";
14+
15+const Container = styled.div`
16+ display: flex;
17+ justify-content: space-between;
18+ align-items: center;
19+ width: 100%;
20+`;
21+
22+const StopButton = styled.div`
23+ font-size: ${getFontSize() - 3}px;
24+ padding: 2px;
25+ padding-right: 4px;
26+ cursor: pointer;
27+`;
28+
29+export function PendingToolCallToolbar() {
30+ const dispatch = useAppDispatch();
31+ const jetbrains = isJetBrains();
32+
33+ return (
34+ <Container>
35+ <div className="text-description flex flex-row items-center pb-0.5 pr-1 text-xs">
36+ <span className="hidden sm:flex">Pending tool call</span>
37+ </div>
38+
39+ <div className="flex gap-2 pb-0.5">
40+ <StopButton
41+ className="text-description"
42+ onClick={() => dispatch(cancelCurrentToolCall())}
43+ data-testid="reject-tool-call-button"
44+ >
45+ {/* JetBrains overrides cmd+backspace, so we have to use another shortcut */}
46+ {jetbrains ? getAltKeyLabel() : getMetaKeyLabel()} ⌫ Cancel
47+ </StopButton>
48+ <EnterButton
49+ isPrimary={true}
50+ className="text-description"
51+ onClick={() => dispatch(callCurrentTool())}
52+ data-testid="accept-tool-call-button"
53+ >
54+ {getMetaKeyLabel()} ⏎ Continue
55+ </EnterButton>
56+ </div>
57+ </Container>
58+ );
59+}
added gui/src/components/mainInput/Lump/LumpToolbar/StreamingToolbar.tsx +24 −0
@@ -0,0 +1,24 @@
1+import { useAppDispatch } from "../../../../redux/hooks";
2+import { cancelStream } from "../../../../redux/thunks";
3+import { getAltKeyLabel, getMetaKeyLabel, isJetBrains } from "../../../../util";
4+import { Container, StopButton } from "./components";
5+import { GeneratingIndicator } from "./GeneratingIndicator";
6+
7+export function StreamingToolbar() {
8+ const dispatch = useAppDispatch();
9+ const jetbrains = isJetBrains();
10+
11+ return (
12+ <Container>
13+ <GeneratingIndicator />
14+ <StopButton
15+ className="text-description"
16+ onClick={() => {
17+ void dispatch(cancelStream());
18+ }}
19+ >
20+ {jetbrains ? getAltKeyLabel() : getMetaKeyLabel()} ⌫ Cancel
21+ </StopButton>
22+ </Container>
23+ );
24+}
added gui/src/components/mainInput/Lump/LumpToolbar/TtsActiveToolbar.tsx +37 −0
@@ -0,0 +1,37 @@
1+import { useContext } from "react";
2+import styled from "styled-components";
3+import { IdeMessengerContext } from "../../../../context/IdeMessenger";
4+import { getFontSize } from "../../../../util";
5+import { GeneratingIndicator } from "./GeneratingIndicator";
6+
7+const Container = styled.div`
8+ display: flex;
9+ justify-content: space-between;
10+ align-items: center;
11+ width: 100%;
12+`;
13+
14+const StopButton = styled.div`
15+ font-size: ${getFontSize() - 3}px;
16+ padding: 2px;
17+ padding-right: 4px;
18+ cursor: pointer;
19+`;
20+
21+export function TtsActiveToolbar() {
22+ const ideMessenger = useContext(IdeMessengerContext);
23+
24+ return (
25+ <Container>
26+ <GeneratingIndicator />
27+ <StopButton
28+ className="text-description"
29+ onClick={() => {
30+ ideMessenger.post("tts/kill", undefined);
31+ }}
32+ >
33+ ■ Stop TTS
34+ </StopButton>
35+ </Container>
36+ );
37+}
added gui/src/components/mainInput/Lump/LumpToolbar/components.ts +18 −0
@@ -0,0 +1,18 @@
1+// TODO: Convert these to tailwind
2+
3+import styled from "styled-components";
4+import { getFontSize } from "../../../../util";
5+
6+export const Container = styled.div`
7+ display: flex;
8+ justify-content: space-between;
9+ align-items: center;
10+ width: 100%;
11+`;
12+
13+export const StopButton = styled.div`
14+ font-size: ${getFontSize() - 3}px;
15+ padding: 2px;
16+ padding-right: 4px;
17+ cursor: pointer;
18+`;
added gui/src/components/mainInput/Lump/LumpToolbar/index.ts +1 −0
@@ -0,0 +1,1 @@
1+export * from "./LumpToolbar";
modified gui/src/components/mainInput/Lump/index.tsx +1 −1
@@ -37,7 +37,7 @@
3737
3838 return (
3939 <LumpDiv>
40- <div className="xs:px-2 mt-0.5 px-1">
40+ <div className="xs:px-2 px-1 py-0.5">
4141 <LumpToolbar />
4242
4343 <ContentDiv
modified gui/src/components/mainInput/TipTapEditor/MainEditorProvider.tsx +15 −12
@@ -27,9 +27,15 @@
2727 onEnterRef: React.MutableRefObject<(modifiers: InputModifiers) => void>;
2828 }
2929
30-const MainEditorContext = createContext<MainEditorContextType | undefined>(
31- undefined,
32-);
30+const initialState: MainEditorContextType = {
31+ mainEditor: null,
32+ setMainEditor: () => {},
33+ inputId: null,
34+ setInputId: () => {},
35+ onEnterRef: { current: () => {} },
36+};
37+
38+const MainEditorContext = createContext<MainEditorContextType>(initialState);
3339
3440 /**
3541 * Provider component that maintains a reference to the main editor
@@ -38,8 +44,10 @@
3844 children,
3945 }) => {
4046 const dispatch = useAppDispatch();
41- const [mainEditor, setMainEditorInternal] = useState<Editor | null>(null);
42- const [inputId, setInputId] = useState<string | null>(null);
47+ const [mainEditor, setMainEditorInternal] = useState<Editor | null>(
48+ initialState.mainEditor,
49+ );
50+ const [inputId, setInputId] = useState<string | null>(initialState.inputId);
4351 const onEnterRef = useRef<(modifiers: InputModifiers) => void>(() => {});
4452 const editorFocusedRef = useRef<boolean>(false);
4553 const historyLength = useAppSelector((store) => store.session.history.length);
@@ -108,10 +116,5 @@
108116 /**
109117 * Hook to access the main editor context
110118 */
111-export const useMainEditor = (): MainEditorContextType => {
112- const context = useContext(MainEditorContext);
113- if (context === undefined) {
114- throw new Error("useMainEditor must be used within a MainEditorProvider");
115- }
116- return context;
117-};
119+export const useMainEditor = (): MainEditorContextType =>
120+ useContext(MainEditorContext);
modified gui/src/components/mainInput/TipTapEditor/TipTapEditor.tsx +7 −8
@@ -42,14 +42,13 @@
4242 const mainEditorContext = useMainEditor();
4343
4444 const ideMessenger = useContext(IdeMessengerContext);
45-
4645 const isOSREnabled = useIsOSREnabled();
4746
4847 const defaultModel = useAppSelector(selectSelectedChatModel);
4948 const isStreaming = useAppSelector((state) => state.session.isStreaming);
5049 const historyLength = useAppSelector((store) => store.session.history.length);
50+ const isInEdit = useAppSelector((store) => store.session.isInEdit);
5151
52- const mode = useAppSelector((store) => store.session.mode);
5352 const { editor, onEnterRef } = createEditorConfig({
5453 props,
5554 ideMessenger,
@@ -87,10 +86,10 @@
8786 }, [editor, props.isMainInput]);
8887
8988 useEffect(() => {
90- if (mode === "edit") {
89+ if (isInEdit) {
9190 setShouldHideToolbar(false);
9291 }
93- }, [mode]);
92+ }, [isInEdit]);
9493
9594 const editorFocusedRef = useUpdatingRef(editor?.isFocused, [editor]);
9695
@@ -150,7 +149,7 @@
150149
151150 const handleBlur = useCallback(
152151 (e: React.FocusEvent) => {
153- if (mode === "edit") {
152+ if (isInEdit) {
154153 return;
155154 }
156155 // Check if the new focus target is within our InputBoxDiv
@@ -165,7 +164,7 @@
165164 setShouldHideToolbar(true);
166165 }, 100);
167166 },
168- [mode, blurTimeout],
167+ [isInEdit, blurTimeout],
169168 );
170169
171170 const handleFocus = useCallback(() => {
@@ -213,7 +212,7 @@
213212 }
214213 setShowDragOverMsg(false);
215214 let file = event.dataTransfer.files[0];
216- handleImageFile(ideMessenger, file).then((result) => {
215+ void handleImageFile(ideMessenger, file).then((result) => {
217216 if (!editor) {
218217 return;
219218 }
@@ -245,7 +244,7 @@
245244 onAddContextItem={() => insertCharacterWithWhitespace("@")}
246245 onEnter={onEnterRef.current}
247246 onImageFileSelected={(file) => {
248- handleImageFile(ideMessenger, file).then((result) => {
247+ void handleImageFile(ideMessenger, file).then((result) => {
249248 if (!editor) {
250249 return;
251250 }
modified gui/src/components/mainInput/TipTapEditor/useMainEditorWebviewListeners.ts +1 −1
@@ -3,7 +3,7 @@
33 import { rifWithContentsToContextItem } from "core/commands/util";
44 import { MutableRefObject } from "react";
55 import { useWebviewListener } from "../../../hooks/useWebviewListener";
6-import { clearCodeToEdit } from "../../../redux/slices/editModeState";
6+import { clearCodeToEdit } from "../../../redux/slices/editState";
77 import { setNewestToolbarPreviewForInput } from "../../../redux/slices/sessionSlice";
88 import { AppDispatch } from "../../../redux/store";
99 import { loadSession, saveCurrentSession } from "../../../redux/thunks/session";
modified gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts +9 −9
@@ -23,7 +23,7 @@
2323 import { selectUseActiveFile } from "../../../../redux/selectors";
2424 import { selectSelectedChatModel } from "../../../../redux/slices/configSlice";
2525 import { AppDispatch } from "../../../../redux/store";
26-import { exitEditMode } from "../../../../redux/thunks/editMode";
26+import { exitEdit } from "../../../../redux/thunks/edit";
2727 import { getFontSize, isJetBrains } from "../../../../util";
2828 import * as ContinueExtensions from "../extensions";
2929 import { TipTapEditorProps } from "../TipTapEditor";
@@ -81,9 +81,9 @@
8181 const isStreaming = useAppSelector((state) => state.session.isStreaming);
8282 const useActiveFile = useAppSelector(selectUseActiveFile);
8383 const historyLength = useAppSelector((store) => store.session.history.length);
84- const mode = useAppSelector((store) => store.session.mode);
85- const modeRef = useUpdatingRef(mode);
8684 const codeToEdit = useAppSelector((store) => store.editModeState.codeToEdit);
85+ const isInEdit = useAppSelector((store) => store.session.isInEdit);
86+ const isInEditRef = useUpdatingRef(isInEdit);
8787
8888 const inSubmenuRef = useRef<string | undefined>(undefined);
8989 const inDropdownRef = useRef(false);
@@ -157,7 +157,7 @@
157157 for (const item of items) {
158158 const file = item.getAsFile();
159159 file &&
160- modelSupportsImages(
160+ void modelSupportsImages(
161161 model.provider,
162162 model.model,
163163 model.title,
@@ -269,9 +269,9 @@
269269 return true;
270270 }
271271
272- if (modeRef.current === "edit") {
273- dispatch(
274- exitEditMode({
272+ if (isInEditRef.current) {
273+ void dispatch(
274+ exitEdit({
275275 openNewSession: false,
276276 }),
277277 );
@@ -345,7 +345,7 @@
345345 if (!editor) {
346346 return;
347347 }
348- if (isStreaming || (codeToEdit.length === 0 && mode === "edit")) {
348+ if (isStreaming || (codeToEdit.length === 0 && isInEdit)) {
349349 return;
350350 }
351351
@@ -362,7 +362,7 @@
362362
363363 props.onEnter(json, modifiers, editor);
364364 },
365- [props.onEnter, editor, props.isMainInput, codeToEdit, mode],
365+ [props.onEnter, editor, props.isMainInput, codeToEdit, isInEdit],
366366 );
367367
368368 return { editor, onEnterRef };
added gui/src/components/mainInput/util/index.ts +20 −0
@@ -0,0 +1,20 @@
1+import { SetCodeToEditPayload } from "core";
2+import { getUriPathBasename } from "core/util/uri";
3+
4+export * from "./handleMetaKeyIssues";
5+
6+export function getEditFilenameAndRangeText(code: SetCodeToEditPayload) {
7+ const fileName = getUriPathBasename(code.filepath);
8+ let title = `${fileName}`;
9+
10+ if ("range" in code) {
11+ const start = code.range.start.line + 1;
12+ const end = code.range.end.line + 1;
13+ const isInsertion = start === end;
14+ title += isInsertion
15+ ? ` - Inserting at line ${start}`
16+ : ` (${start} - ${end})`;
17+ }
18+
19+ return title;
20+}
deleted gui/src/components/mainInput/util/inputModifiers.ts +0 −6
@@ -1,6 +0,0 @@
1-import { InputModifiers } from "core";
2-
3-export const defaultInputModifiers: InputModifiers = {
4- useCodebase: false,
5- noContext: true,
6-};
deleted gui/src/components/mainInput/utils.ts +0 −18
@@ -1,18 +0,0 @@
1-import { JSONContent } from "@tiptap/core";
2-
3-export function getParagraphNodeFromString(str: string): JSONContent {
4- return {
5- type: "doc",
6- content: [
7- {
8- type: "paragraph",
9- content: [
10- {
11- type: "text",
12- text: str,
13- },
14- ],
15- },
16- ],
17- };
18-}
deleted gui/src/components/modelSelection/ModeSelect.tsx +0 −201
@@ -1,201 +0,0 @@
1-// A dropdown menu for selecting between Chat, Edit, and Agent modes with keyboard shortcuts
2-import {
3- ChatBubbleLeftIcon,
4- CheckIcon,
5- ChevronDownIcon,
6- PencilIcon,
7- SparklesIcon,
8-} from "@heroicons/react/24/outline";
9-import { MessageModes } from "core";
10-import { modelSupportsTools } from "core/llm/autodetect";
11-import { useCallback, useEffect, useMemo } from "react";
12-import styled from "styled-components";
13-import { lightGray } from "..";
14-import { useAppDispatch, useAppSelector } from "../../redux/hooks";
15-import { selectSelectedChatModel } from "../../redux/slices/configSlice";
16-import { setMode } from "../../redux/slices/sessionSlice";
17-import { enterEditMode, exitEditMode } from "../../redux/thunks/editMode";
18-import { getFontSize, getMetaKeyLabel, isJetBrains } from "../../util";
19-import { useMainEditor } from "../mainInput/TipTapEditor";
20-import {
21- Listbox,
22- ListboxButton,
23- ListboxOption,
24- ListboxOptions,
25-} from "../ui/Listbox";
26-
27-const ShortcutText = styled.span`
28- color: ${lightGray};
29- font-size: ${getFontSize() - 3}px;
30- margin-right: auto;
31-`;
32-
33-function ModeSelect() {
34- const dispatch = useAppDispatch();
35- const mode = useAppSelector((store) => store.session.mode);
36- const selectedModel = useAppSelector(selectSelectedChatModel);
37- const agentModeSupported = useMemo(() => {
38- return selectedModel && modelSupportsTools(selectedModel);
39- }, [selectedModel]);
40- const { mainEditor } = useMainEditor();
41- const jetbrains = useMemo(() => {
42- return isJetBrains();
43- }, []);
44- const metaKeyLabel = useMemo(() => {
45- return getMetaKeyLabel();
46- }, []);
47-
48- const getModeIcon = (mode: MessageModes) => {
49- switch (mode) {
50- case "agent":
51- return <SparklesIcon className="xs:h-3 xs:w-3 h-3 w-3" />;
52- case "chat":
53- return <ChatBubbleLeftIcon className="xs:h-3 xs:w-3 h-3 w-3" />;
54- case "edit":
55- return <PencilIcon className="xs:h-3 xs:w-3 h-3 w-3" />;
56- }
57- };
58-
59- // Switch to chat mode if agent mode is selected but not supported
60- useEffect(() => {
61- if (!selectedModel) {
62- return;
63- }
64- if (mode === "agent" && !agentModeSupported) {
65- dispatch(setMode("chat"));
66- }
67- }, [mode, agentModeSupported, dispatch, selectedModel]);
68-
69- const cycleMode = useCallback(async () => {
70- const modes: MessageModes[] = jetbrains
71- ? ["chat", "agent"]
72- : ["chat", "agent", "edit"];
73- const currentIndex = modes.indexOf(mode);
74- const nextMode = modes[(currentIndex + 1) % modes.length];
75-
76- if (mode === "edit") {
77- await dispatch(
78- exitEditMode({
79- goToMode: nextMode,
80- }),
81- );
82- } else {
83- if (nextMode === "edit") {
84- await dispatch(
85- enterEditMode({
86- returnToMode: mode,
87- }),
88- );
89- } else {
90- dispatch(setMode(nextMode));
91- }
92- }
93- mainEditor?.commands.focus();
94- }, [jetbrains, mode, mainEditor]);
95-
96- const selectMode = useCallback(
97- async (newMode: MessageModes) => {
98- if (newMode === mode) {
99- return;
100- }
101- if (newMode === "edit") {
102- await dispatch(
103- enterEditMode({
104- returnToMode: mode,
105- }),
106- );
107- } else {
108- if (mode === "edit") {
109- await dispatch(
110- exitEditMode({
111- goToMode: newMode,
112- }),
113- );
114- } else {
115- dispatch(setMode(newMode));
116- }
117- }
118-
119- mainEditor?.commands.focus();
120- },
121- [mode, mainEditor],
122- );
123-
124- useEffect(() => {
125- const handleKeyDown = (e: KeyboardEvent) => {
126- if (e.key === "." && (e.metaKey || e.ctrlKey)) {
127- e.preventDefault();
128- void cycleMode();
129- }
130- };
131-
132- document.addEventListener("keydown", handleKeyDown);
133- return () => document.removeEventListener("keydown", handleKeyDown);
134- }, [cycleMode]);
135-
136- return (
137- <Listbox value={mode} onChange={selectMode}>
138- <div className="relative">
139- <ListboxButton
140- data-testid="mode-select-button"
141- className="xs:px-2 gap-1 border-none px-1.5 py-0.5 text-gray-400 transition-colors duration-200"
142- style={{
143- backgroundColor: `${lightGray}33`,
144- borderRadius: "9999px",
145- }}
146- >
147- {getModeIcon(mode)}
148- <span className="hidden sm:block">
149- {mode.charAt(0).toUpperCase() + mode.slice(1)}
150- </span>
151- <ChevronDownIcon
152- className="h-2 w-2 flex-shrink-0"
153- aria-hidden="true"
154- />
155- </ListboxButton>
156- <ListboxOptions className="min-w-32 max-w-48">
157- {!jetbrains && (
158- <ListboxOption value="edit">
159- <div className="flex flex-row items-center gap-1.5">
160- <PencilIcon className="h-3 w-3" />
161- <span className="">Edit</span>
162- <ShortcutText>{getMetaKeyLabel()}I</ShortcutText>
163- </div>
164- {mode === "edit" && <CheckIcon className="ml-auto h-3 w-3" />}
165- </ListboxOption>
166- )}
167- <ListboxOption value="chat">
168- <div className="flex flex-row items-center gap-1.5">
169- <ChatBubbleLeftIcon className="h-3 w-3" />
170- <span className="">Chat</span>
171- <ShortcutText>{getMetaKeyLabel()}L</ShortcutText>
172- </div>
173- {mode === "chat" && <CheckIcon className="ml-auto h-3 w-3" />}
174- </ListboxOption>
175-
176- <ListboxOption
177- value="agent"
178- disabled={!agentModeSupported}
179- className={"gap-1"}
180- >
181- <div className="flex flex-row items-center gap-1.5">
182- <SparklesIcon className="h-3 w-3" />
183- <span className="">Agent</span>
184- </div>
185- {agentModeSupported ? (
186- mode === "agent" && <CheckIcon className="ml-auto h-3 w-3" />
187- ) : (
188- <span>(Not supported)</span>
189- )}
190- </ListboxOption>
191-
192- <div className="text-lightgray px-2 py-1">
193- {`${metaKeyLabel} . for next mode`}
194- </div>
195- </ListboxOptions>
196- </div>
197- </Listbox>
198- );
199-}
200-
201-export default ModeSelect;
modified gui/src/components/modelSelection/ModelSelect.tsx +5 −21
@@ -6,8 +6,7 @@
66 PlusIcon,
77 } from "@heroicons/react/24/outline";
88 import { useContext, useEffect, useRef, useState } from "react";
9-import styled from "styled-components";
10-import { defaultBorderRadius, lightGray } from "..";
9+import { lightGray } from "..";
1110 import { useAuth } from "../../context/Auth";
1211 import { IdeMessengerContext } from "../../context/IdeMessenger";
1312 import AddModelForm from "../../forms/AddModelForm";
@@ -30,21 +29,6 @@
3029 apiKey?: string;
3130 }
3231
33-const IconBase = styled.div<{ $hovered: boolean }>`
34- width: 1.2em;
35- height: 1.2em;
36- cursor: pointer;
37- padding: 4px;
38- border-radius: ${defaultBorderRadius};
39- opacity: ${(props) => (props.$hovered ? 0.75 : 0)};
40- visibility: ${(props) => (props.$hovered ? "visible" : "hidden")};
41-
42- &:hover {
43- opacity: 1;
44- background-color: ${lightGray}33;
45- }
46-`;
47-
4832 function modelSelectTitle(model: any): string {
4933 if (model?.title) return model?.title;
5034 if (model?.model !== undefined && model?.model.trim() !== "") {
@@ -120,12 +104,12 @@
120104 function ModelSelect() {
121105 const dispatch = useAppDispatch();
122106
123- const mode = useAppSelector((store) => store.session.mode);
107+ const isInEdit = useAppSelector((store) => store.session.isInEdit);
124108 const config = useAppSelector((state) => state.config.config);
125109
126110 let selectedModel = null;
127111 let allModels = null;
128- if (mode === "edit") {
112+ if (isInEdit) {
129113 allModels = config.modelsByRole.edit;
130114 selectedModel = config.selectedModelByRole.edit;
131115 }
@@ -226,7 +210,7 @@
226210 void dispatch(
227211 updateSelectedModelByRole({
228212 selectedProfile,
229- role: mode === "edit" ? "edit" : "chat",
213+ role: isInEdit ? "edit" : "chat",
230214 modelTitle: val,
231215 }),
232216 );
@@ -236,7 +220,7 @@
236220 <ListboxButton
237221 data-testid="model-select-button"
238222 ref={buttonRef}
239- className="h-[18px] gap-1 border-none text-gray-400"
223+ className="text-description h-[18px] gap-1 border-none"
240224 >
241225 <span className="line-clamp-1 break-all hover:brightness-110">
242226 {modelSelectTitle(selectedModel) || "Select model"}
modified gui/src/components/modelSelection/platform/AssistantSelect.tsx +8 −8
@@ -126,7 +126,7 @@
126126 )}
127127 {isLocalProfile(profile) ? (
128128 <Cog6ToothIcon
129- className="text-lightgray h-3 w-3 flex-shrink-0 cursor-pointer"
129+ className="text-description h-3 w-3 flex-shrink-0 cursor-pointer"
130130 onClick={(e) => {
131131 e.stopPropagation();
132132 e.preventDefault();
@@ -135,7 +135,7 @@
135135 />
136136 ) : (
137137 <ArrowTopRightOnSquareIcon
138- className="text-lightgray h-3 w-3 flex-shrink-0 cursor-pointer"
138+ className="text-description h-3 w-3 flex-shrink-0 cursor-pointer"
139139 onClick={(e) => {
140140 e.stopPropagation();
141141 e.preventDefault();
@@ -242,12 +242,12 @@
242242 return (
243243 <div
244244 onClick={() => {
245- ideMessenger.request("controlPlane/openUrl", {
245+ void ideMessenger.request("controlPlane/openUrl", {
246246 path: "/new?type=assistant",
247247 orgSlug: currentOrg?.slug,
248248 });
249249 }}
250- className="flex cursor-pointer select-none items-center gap-1 text-gray-400"
250+ className="text-description flex cursor-pointer select-none items-center gap-1"
251251 style={{ fontSize: smallFont }}
252252 >
253253 <PlusIcon className="h-3 w-3 flex-shrink-0 select-none" />
@@ -266,7 +266,7 @@
266266 <ListboxButton
267267 data-testid="assistant-select-button"
268268 ref={buttonRef}
269- className="border-none bg-transparent text-gray-400 hover:brightness-125"
269+ className="text-description border-none bg-transparent hover:brightness-125"
270270 style={{ fontSize: fontSize(-3) }}
271271 >
272272 <div className="flex flex-row items-center gap-1.5">
@@ -301,7 +301,7 @@
301301 >
302302 <ArrowPathIcon
303303 className={cn(
304- "text-lightgray h-2.5 w-2.5",
304+ "text-description h-2.5 w-2.5",
305305 loading && "animate-spin-slow",
306306 )}
307307 />
@@ -339,7 +339,7 @@
339339 onClick={session ? onNewAssistant : () => login(false)}
340340 >
341341 <div
342- className="text-lightgray flex flex-row items-center gap-2"
342+ className="text-description flex flex-row items-center gap-2"
343343 style={{
344344 fontSize: tinyFont,
345345 }}
@@ -358,7 +358,7 @@
358358 />
359359
360360 <div
361- className="text-lightgray flex items-center justify-between px-2 py-1"
361+ className="text-description flex items-center justify-between px-2 py-1"
362362 style={{
363363 fontSize: tinyFont,
364364 }}
modified gui/src/hooks/ParallelListeners.tsx +46 −34
@@ -3,6 +3,7 @@
33
44 import { EDIT_MODE_STREAM_ID } from "core/edit/constants";
55 import { FromCoreProtocol } from "core/protocol";
6+import { useMainEditor } from "../components/mainInput/TipTapEditor";
67 import {
78 initializeProfilePreferences,
89 setOrganizations,
@@ -15,7 +16,7 @@
1516 import {
1617 setLastNonEditSessionEmpty,
1718 updateEditStateApplyState,
18-} from "../redux/slices/editModeState";
19+} from "../redux/slices/editState";
1920 import { updateIndexingStatus } from "../redux/slices/indexingSlice";
2021 import {
2122 acceptToolCall,
@@ -23,7 +24,7 @@
2324 updateApplyState,
2425 } from "../redux/slices/sessionSlice";
2526 import { setTTSActive } from "../redux/slices/uiSlice";
26-import { streamResponseAfterToolCall } from "../redux/thunks";
27+import { exitEdit, streamResponseAfterToolCall } from "../redux/thunks";
2728 import { cancelStream } from "../redux/thunks/cancelStream";
2829 import { refreshSessionMetadata } from "../redux/thunks/session";
2930 import { streamResponseThunk } from "../redux/thunks/streamResponse";
@@ -40,12 +41,18 @@
4041 const dispatch = useAppDispatch();
4142 const ideMessenger = useContext(IdeMessengerContext);
4243 const history = useAppSelector((store) => store.session.history);
44+ const isInEdit = useAppSelector((store) => store.session.isInEdit);
4345
4446 const selectedProfileId = useAppSelector(
4547 (store) => store.profiles.selectedProfileId,
4648 );
4749
4850 const hasDoneInitialConfigLoad = useRef(false);
51+ const currentToolCallApplyState = useAppSelector(
52+ selectCurrentToolCallApplyState,
53+ );
54+
55+ const { mainEditor } = useMainEditor();
4956
5057 const handleConfigUpdate = useCallback(
5158 async (isInitial: boolean, result: FromCoreProtocol["configUpdate"][0]) => {
@@ -99,18 +106,18 @@
99106
100107 // Load config from the IDE
101108 useEffect(() => {
102- initialLoadAuthAndConfig(true);
109+ void initialLoadAuthAndConfig(true);
103110 const interval = setInterval(() => {
104111 if (hasDoneInitialConfigLoad.current) {
105112 // Init to run on initial config load
106113 ideMessenger.post("docs/initStatuses", undefined);
107- dispatch(updateFileSymbolsFromHistory());
108- dispatch(refreshSessionMetadata({}));
114+ void dispatch(updateFileSymbolsFromHistory());
115+ void dispatch(refreshSessionMetadata({}));
109116
110117 // This triggers sending pending status to the GUI for relevant docs indexes
111118 clearInterval(interval);
112119 } else {
113- initialLoadAuthAndConfig(true);
120+ void initialLoadAuthAndConfig(true);
114121 }
115122 }, 2_000);
116123
@@ -132,39 +139,43 @@
132139 const sessionId = useAppSelector((state) => state.session.id);
133140 useEffect(() => {
134141 if (sessionId) {
135- dispatch(updateFileSymbolsFromHistory());
142+ void dispatch(updateFileSymbolsFromHistory());
136143 }
137144 }, [sessionId]);
138145
139146 // ON LOAD
140147 useEffect(() => {
141148 // Override persisted state
142- dispatch(cancelStream());
149+ void dispatch(cancelStream());
143150
144151 const jetbrains = isJetBrains();
145152 setDocumentStylesFromLocalStorage(jetbrains);
146153
147154 if (jetbrains) {
148155 // Save theme colors to local storage for immediate loading in JetBrains
149- ideMessenger.request("jetbrains/getColors", undefined).then((result) => {
150- if (result.status === "success") {
151- setDocumentStylesFromTheme(result.content);
152- }
153- });
156+ void ideMessenger
157+ .request("jetbrains/getColors", undefined)
158+ .then((result) => {
159+ if (result.status === "success") {
160+ setDocumentStylesFromTheme(result.content);
161+ }
162+ });
154163
155164 // Tell JetBrains the webview is ready
156- ideMessenger.request("jetbrains/onLoad", undefined).then((result) => {
157- if (result.status === "error") {
158- return;
159- }
160-
161- const msg = result.content;
162- (window as any).windowId = msg.windowId;
163- (window as any).serverUrl = msg.serverUrl;
164- (window as any).workspacePaths = msg.workspacePaths;
165- (window as any).vscMachineId = msg.vscMachineId;
166- (window as any).vscMediaUrl = msg.vscMediaUrl;
167- });
165+ void ideMessenger
166+ .request("jetbrains/onLoad", undefined)
167+ .then((result) => {
168+ if (result.status === "error") {
169+ return;
170+ }
171+
172+ const msg = result.content;
173+ (window as any).windowId = msg.windowId;
174+ (window as any).serverUrl = msg.serverUrl;
175+ (window as any).workspacePaths = msg.workspacePaths;
176+ (window as any).vscMachineId = msg.vscMachineId;
177+ (window as any).vscMediaUrl = msg.vscMediaUrl;
178+ });
168179 }
169180 }, []);
170181
@@ -194,7 +205,7 @@
194205 );
195206
196207 useWebviewListener("setInactive", async () => {
197- dispatch(cancelStream());
208+ void dispatch(cancelStream());
198209 });
199210
200211 useWebviewListener("setTTSActive", async (status) => {
@@ -203,7 +214,7 @@
203214
204215 // TODO - remove?
205216 useWebviewListener("submitMessage", async (data) => {
206- dispatch(
217+ void dispatch(
207218 streamResponseThunk({
208219 editorState: data.message,
209220 modifiers: { useCodebase: false, noContext: true },
@@ -224,14 +235,15 @@
224235 dispatch(updateIndexingStatus(data));
225236 });
226237
227- const currentToolCallApplyState = useAppSelector(
228- selectCurrentToolCallApplyState,
229- );
230238 useWebviewListener(
231239 "updateApplyState",
232240 async (state) => {
233241 if (state.streamId === EDIT_MODE_STREAM_ID) {
234242 dispatch(updateEditStateApplyState(state));
243+
244+ if (state.status === "closed") {
245+ dispatch(exitEdit({}));
246+ }
235247 } else {
236248 // chat or agent
237249 dispatch(updateApplyState(state));
@@ -253,7 +265,7 @@
253265 }),
254266 );
255267 // dispatch(setToolCallOutput([]));
256- dispatch(
268+ void dispatch(
257269 streamResponseAfterToolCall({
258270 toolCallId: currentToolCallApplyState.toolCallId!,
259271 }),
@@ -264,12 +276,12 @@
264276 [currentToolCallApplyState, history],
265277 );
266278
267- const mode = useAppSelector((store) => store.session.mode);
268279 useEffect(() => {
269- if (mode !== "edit") {
280+ if (!isInEdit) {
270281 dispatch(setLastNonEditSessionEmpty(history.length === 0));
271282 }
272- }, [mode, history]);
283+ }, [isInEdit, history]);
284+
273285 return <></>;
274286 }
275287
modified gui/src/pages/gui/Chat.test.tsx +2 −2
@@ -35,8 +35,8 @@
3535 );
3636 });
3737
38- // Check that it switched to Edit mode
39- expect(await screen.findByText("Edit")).toBeInTheDocument();
38+ // Check that it switched back to Chat mode
39+ expect(await screen.findByText("Chat")).toBeInTheDocument();
4040 });
4141
4242 it.skip("should send a message and receive a response", async () => {
modified gui/src/pages/gui/Chat.tsx +28 −36
@@ -46,7 +46,7 @@
4646 } from "../../redux/slices/uiSlice";
4747 import { streamResponseThunk } from "../../redux/thunks";
4848 import { cancelStream } from "../../redux/thunks/cancelStream";
49-import { streamEditThunk } from "../../redux/thunks/editMode";
49+import { streamEditThunk } from "../../redux/thunks/edit";
5050 import { loadLastSession } from "../../redux/thunks/session";
5151 import { isJetBrains, isMetaEquivalentKeyPressed } from "../../util";
5252 import {
@@ -54,9 +54,6 @@
5454 incrementFreeTrialCount,
5555 } from "../../util/freeTrial";
5656
57-import AcceptRejectDiffButtons from "../../components/AcceptRejectDiffButtons";
58-import CodeToEditCard from "../../components/mainInput/CodeToEditCard";
59-import EditModeDetails from "../../components/mainInput/EditModeDetails";
6057 import { getLocalStorage, setLocalStorage } from "../../util/localStorage";
6158 import { EmptyChatBody } from "./EmptyChatBody";
6259 import { ExploreDialogWatcher } from "./ExploreDialogWatcher";
@@ -121,9 +118,7 @@
121118 const codeToEdit = useAppSelector((state) => state.editModeState.codeToEdit);
122119 const toolCallState = useAppSelector(selectCurrentToolCall);
123120 const mode = useAppSelector((store) => store.session.mode);
124- const applyStates = useAppSelector(
125- (state) => state.session.codeBlockApplyStates.states,
126- );
121+ const isInEdit = useAppSelector((store) => store.session.isInEdit);
127122
128123 const lastSessionId = useAppSelector((state) => state.session.lastSessionId);
129124 const hasDismissedExploreDialog = useAppSelector(
@@ -185,15 +180,14 @@
185180 );
186181 }
187182
188- const model =
189- mode === "edit"
190- ? (selectedModels?.edit ?? selectedModels?.chat)
191- : selectedModels?.chat;
183+ const model = isInEdit
184+ ? (selectedModels?.edit ?? selectedModels?.chat)
185+ : selectedModels?.chat;
192186 if (!model) {
193187 return;
194188 }
195189
196- if (mode === "edit" && codeToEdit.length === 0) {
190+ if (isInEdit && codeToEdit.length === 0) {
197191 return;
198192 }
199193
@@ -224,15 +218,15 @@
224218 }
225219 }
226220
227- if (mode === "edit") {
228- dispatch(
221+ if (isInEdit) {
222+ void dispatch(
229223 streamEditThunk({
230224 editorState,
231225 codeToEdit,
232226 }),
233227 );
234228 } else {
235- dispatch(streamResponseThunk({ editorState, modifiers, index }));
229+ void dispatch(streamResponseThunk({ editorState, modifiers, index }));
236230
237231 if (editorToClearOnSend) {
238232 editorToClearOnSend.commands.clearContent();
@@ -252,7 +246,15 @@
252246 setLocalStorage("mainTextEntryCounter", 1);
253247 }
254248 },
255- [history, selectedModels, streamResponse, mode, codeToEdit, toolCallState],
249+ [
250+ history,
251+ selectedModels,
252+ streamResponse,
253+ mode,
254+ isInEdit,
255+ codeToEdit,
256+ toolCallState,
257+ ],
256258 );
257259
258260 useWebviewListener(
@@ -292,7 +294,7 @@
292294
293295 return (
294296 <>
295- {!!showSessionTabs && mode !== "edit" && <TabBar ref={tabsRef} />}
297+ {!!showSessionTabs && !isInEdit && <TabBar ref={tabsRef} />}
296298 {widget}
297299
298300 <StepsDiv
@@ -381,24 +383,14 @@
381383 ))}
382384 </StepsDiv>
383385 <div className={"relative"}>
384- <>
385- {!isStreaming && mode !== "edit" && (
386- <AcceptRejectDiffButtons
387- applyStates={applyStates}
388- onAcceptOrReject={async () => {}}
389- />
390- )}
391- {mode === "edit" && <CodeToEditCard />}
392- <ContinueInputBox
393- isMainInput
394- isLastUserInput={false}
395- onEnter={(editorState, modifiers, editor) =>
396- sendInput(editorState, modifiers, undefined, editor)
397- }
398- inputId={MAIN_EDITOR_INPUT_ID}
399- />
400- <EditModeDetails />
401- </>
386+ <ContinueInputBox
387+ isMainInput
388+ isLastUserInput={false}
389+ onEnter={(editorState, modifiers, editor) =>
390+ sendInput(editorState, modifiers, undefined, editor)
391+ }
392+ inputId={MAIN_EDITOR_INPUT_ID}
393+ />
402394
403395 <div
404396 style={{
@@ -407,7 +399,7 @@
407399 >
408400 <div className="flex flex-row items-center justify-between pb-1 pl-0.5 pr-2">
409401 <div className="xs:inline hidden">
410- {history.length === 0 && lastSessionId && mode !== "edit" && (
402+ {history.length === 0 && lastSessionId && !isInEdit && (
411403 <div className="xs:inline hidden">
412404 <NewSessionButton
413405 onClick={async () => {
deleted gui/src/redux/slices/editModeState.ts +0 −77
@@ -1,77 +0,0 @@
1-import { createSlice, PayloadAction } from "@reduxjs/toolkit";
2-import { ApplyState, SetCodeToEditPayload, MessageModes } from "core";
3-import { EDIT_MODE_STREAM_ID } from "core/edit/constants";
4-
5-export interface EditModeState {
6- // Array because of previous multi-file edit functionality
7- // Keeping array to not break persisted redux for now
8- codeToEdit: SetCodeToEditPayload[];
9- applyState: ApplyState;
10- returnToMode: MessageModes;
11- lastNonEditSessionWasEmpty: boolean;
12-}
13-
14-export const INITIAL_EDIT_APPLY_STATE: ApplyState = {
15- streamId: EDIT_MODE_STREAM_ID,
16- status: "not-started",
17-};
18-
19-const initialState: EditModeState = {
20- applyState: INITIAL_EDIT_APPLY_STATE,
21- codeToEdit: [],
22- returnToMode: "chat",
23- lastNonEditSessionWasEmpty: false,
24-};
25-
26-export const editModeStateSlice = createSlice({
27- name: "editModeState",
28- initialState,
29- reducers: {
30- setReturnToModeAfterEdit: (
31- state,
32- { payload }: PayloadAction<MessageModes>,
33- ) => {
34- state.returnToMode = payload;
35- },
36- updateEditStateApplyState: (
37- state,
38- { payload }: PayloadAction<ApplyState>,
39- ) => {
40- state.applyState = {
41- ...state.applyState,
42- ...payload,
43- };
44- },
45- setCodeToEdit: (
46- state,
47- {
48- payload,
49- }: PayloadAction<{
50- codeToEdit: SetCodeToEditPayload | SetCodeToEditPayload[];
51- }>,
52- ) => {
53- state.codeToEdit = Array.isArray(payload.codeToEdit)
54- ? payload.codeToEdit
55- : [payload.codeToEdit];
56- },
57- clearCodeToEdit: (state) => {
58- state.codeToEdit = [];
59- },
60- setLastNonEditSessionEmpty: (
61- state,
62- { payload }: PayloadAction<boolean>,
63- ) => {
64- state.lastNonEditSessionWasEmpty = payload;
65- },
66- },
67- selectors: {},
68-});
69-
70-export const {
71- setReturnToModeAfterEdit,
72- clearCodeToEdit,
73- setCodeToEdit,
74- updateEditStateApplyState,
75- setLastNonEditSessionEmpty,
76-} = editModeStateSlice.actions;
77-export default editModeStateSlice.reducer;
added gui/src/redux/slices/editState.ts +87 −0
@@ -0,0 +1,87 @@
1+import { createSlice, PayloadAction } from "@reduxjs/toolkit";
2+import { JSONContent } from "@tiptap/core";
3+import { ApplyState, MessageModes, SetCodeToEditPayload } from "core";
4+import { EDIT_MODE_STREAM_ID } from "core/edit/constants";
5+
6+export interface EditState {
7+ // Array because of previous multi-file edit functionality
8+ // Keeping array to not break persisted redux for now
9+ codeToEdit: SetCodeToEditPayload[];
10+ applyState: ApplyState;
11+ returnToMode: MessageModes;
12+ lastNonEditSessionWasEmpty: boolean;
13+ previousModeEditorContent: JSONContent | undefined;
14+}
15+
16+export const INITIAL_EDIT_APPLY_STATE: ApplyState = {
17+ streamId: EDIT_MODE_STREAM_ID,
18+ status: "not-started",
19+};
20+
21+const initialState: EditState = {
22+ applyState: INITIAL_EDIT_APPLY_STATE,
23+ codeToEdit: [],
24+ returnToMode: "chat",
25+ lastNonEditSessionWasEmpty: false,
26+ previousModeEditorContent: undefined,
27+};
28+
29+export const editStateSlice = createSlice({
30+ name: "editState",
31+ initialState,
32+ reducers: {
33+ setReturnToModeAfterEdit: (
34+ state,
35+ { payload }: PayloadAction<MessageModes>,
36+ ) => {
37+ state.returnToMode = payload;
38+ },
39+ updateEditStateApplyState: (
40+ state,
41+ { payload }: PayloadAction<ApplyState>,
42+ ) => {
43+ state.applyState = {
44+ ...state.applyState,
45+ ...payload,
46+ };
47+ },
48+ setCodeToEdit: (
49+ state,
50+ {
51+ payload,
52+ }: PayloadAction<{
53+ codeToEdit: SetCodeToEditPayload | SetCodeToEditPayload[];
54+ }>,
55+ ) => {
56+ state.codeToEdit = Array.isArray(payload.codeToEdit)
57+ ? payload.codeToEdit
58+ : [payload.codeToEdit];
59+ },
60+ clearCodeToEdit: (state) => {
61+ state.codeToEdit = [];
62+ },
63+ setLastNonEditSessionEmpty: (
64+ state,
65+ { payload }: PayloadAction<boolean>,
66+ ) => {
67+ state.lastNonEditSessionWasEmpty = payload;
68+ },
69+ setPreviousModeEditorContent: (
70+ state,
71+ { payload }: PayloadAction<JSONContent | undefined>,
72+ ) => {
73+ state.previousModeEditorContent = payload;
74+ },
75+ },
76+ selectors: {},
77+});
78+
79+export const {
80+ setReturnToModeAfterEdit,
81+ clearCodeToEdit,
82+ setCodeToEdit,
83+ updateEditStateApplyState,
84+ setLastNonEditSessionEmpty,
85+ setPreviousModeEditorContent,
86+} = editStateSlice.actions;
87+export default editStateSlice.reducer;
modified gui/src/redux/slices/sessionSlice.ts +6 −0
@@ -47,6 +47,7 @@
4747 mainEditorContentTrigger?: JSONContent | undefined;
4848 symbols: FileSymbolMap;
4949 mode: MessageModes;
50+ isInEdit: boolean;
5051 codeBlockApplyStates: {
5152 states: ApplyState[];
5253 curIndex: number;
@@ -63,6 +64,7 @@
6364 streamAborter: new AbortController(),
6465 symbols: {},
6566 mode: "chat",
67+ isInEdit: false,
6668 codeBlockApplyStates: {
6769 states: [],
6870 curIndex: 0,
@@ -645,6 +647,9 @@
645647 setMode: (state, action: PayloadAction<MessageModes>) => {
646648 state.mode = action.payload;
647649 },
650+ setIsInEdit: (state, action: PayloadAction<boolean>) => {
651+ state.isInEdit = action.payload;
652+ },
648653 setNewestToolbarPreviewForInput: (
649654 state,
650655 {
@@ -741,6 +746,7 @@
741746 updateSessionMetadata,
742747 deleteSessionMetadata,
743748 setNewestToolbarPreviewForInput,
749+ setIsInEdit,
744750 } = sessionSlice.actions;
745751
746752 export const { selectIsGatheringContext } = sessionSlice.selectors;
modified gui/src/redux/store.ts +1 −1
@@ -17,7 +17,7 @@
1717 import { IdeMessenger, IIdeMessenger } from "../context/IdeMessenger";
1818 import { profilesReducer } from "./slices";
1919 import configReducer from "./slices/configSlice";
20-import editModeStateReducer from "./slices/editModeState";
20+import editModeStateReducer from "./slices/editState";
2121 import indexingReducer from "./slices/indexingSlice";
2222 import sessionReducer from "./slices/sessionSlice";
2323 import tabsReducer from "./slices/tabsSlice";
added gui/src/redux/thunks/edit.ts +155 −0
@@ -0,0 +1,155 @@
1+import { createAsyncThunk } from "@reduxjs/toolkit";
2+import { JSONContent } from "@tiptap/core";
3+import {
4+ MessageModes,
5+ RangeInFileWithContents,
6+ SetCodeToEditPayload,
7+} from "core";
8+import { stripImages } from "core/util/messageContent";
9+import { resolveEditorContent } from "../../components/mainInput/TipTapEditor";
10+import {
11+ clearCodeToEdit,
12+ INITIAL_EDIT_APPLY_STATE,
13+ setPreviousModeEditorContent,
14+ setReturnToModeAfterEdit,
15+ updateEditStateApplyState,
16+} from "../slices/editState";
17+import {
18+ newSession,
19+ setActive,
20+ setIsInEdit,
21+ setMainEditorContentTrigger,
22+ setMode,
23+} from "../slices/sessionSlice";
24+import { ThunkApiType } from "../store";
25+import { loadLastSession, saveCurrentSession } from "./session";
26+import { streamThunkWrapper } from "./streamThunkWrapper";
27+
28+export const streamEditThunk = createAsyncThunk<
29+ void,
30+ {
31+ editorState: JSONContent;
32+ codeToEdit: SetCodeToEditPayload[];
33+ },
34+ ThunkApiType
35+>(
36+ "chat/streamResponse",
37+ async ({ editorState, codeToEdit }, { dispatch, extra }) => {
38+ await dispatch(
39+ streamThunkWrapper(async () => {
40+ dispatch(setActive());
41+ const [contextItems, __, userInstructions, _] =
42+ await resolveEditorContent({
43+ editorState,
44+ modifiers: {
45+ noContext: true,
46+ useCodebase: false,
47+ },
48+ ideMessenger: extra.ideMessenger,
49+ defaultContextProviders: [],
50+ availableSlashCommands: [],
51+ dispatch,
52+ });
53+
54+ const prompt = [
55+ ...contextItems.map((item) => item.content),
56+ stripImages(userInstructions),
57+ ].join("\n\n");
58+
59+ const response = await extra.ideMessenger.request("edit/sendPrompt", {
60+ prompt,
61+ range: codeToEdit[0] as RangeInFileWithContents,
62+ });
63+
64+ if (response.status === "error") {
65+ throw new Error(response.error);
66+ }
67+ }),
68+ );
69+ },
70+);
71+
72+export const exitEdit = createAsyncThunk<
73+ void,
74+ { goToMode?: MessageModes; openNewSession?: boolean },
75+ ThunkApiType
76+>(
77+ "edit/exit",
78+ async ({ goToMode, openNewSession }, { dispatch, extra, getState }) => {
79+ const state = getState();
80+ const codeToEdit = state.editModeState.codeToEdit;
81+ const isInEdit = state.session.isInEdit;
82+ const previousModeEditorContent =
83+ state.editModeState.previousModeEditorContent;
84+
85+ if (!isInEdit) {
86+ return;
87+ }
88+
89+ if (codeToEdit[0] && state.editModeState.applyState.numDiffs) {
90+ extra.ideMessenger.post("rejectDiff", {
91+ filepath: codeToEdit[0].filepath,
92+ });
93+ }
94+
95+ extra.ideMessenger.post("edit/clearDecorations", undefined);
96+
97+ dispatch(clearCodeToEdit());
98+ dispatch(updateEditStateApplyState(INITIAL_EDIT_APPLY_STATE));
99+ dispatch(setIsInEdit(false));
100+
101+ // Restore the previous editor content if available
102+ if (previousModeEditorContent) {
103+ dispatch(setMainEditorContentTrigger(previousModeEditorContent));
104+ dispatch(setPreviousModeEditorContent(undefined));
105+ }
106+
107+ if (openNewSession || state.editModeState.lastNonEditSessionWasEmpty) {
108+ dispatch(newSession());
109+ } else {
110+ await dispatch(
111+ loadLastSession({
112+ saveCurrentSession: false,
113+ }),
114+ );
115+ }
116+
117+ dispatch(setMode(goToMode ?? state.editModeState.returnToMode));
118+ },
119+);
120+
121+export const enterEdit = createAsyncThunk<
122+ void,
123+ { returnToMode?: MessageModes; editorContent?: JSONContent },
124+ ThunkApiType
125+>(
126+ "edit/enter",
127+ async ({ returnToMode, editorContent }, { dispatch, extra, getState }) => {
128+ const state = getState();
129+ const isInEdit = state.session.isInEdit;
130+
131+ if (isInEdit) {
132+ return;
133+ }
134+
135+ dispatch(setMainEditorContentTrigger({}));
136+ dispatch(setPreviousModeEditorContent(editorContent));
137+
138+ dispatch(setReturnToModeAfterEdit(returnToMode ?? state.session.mode));
139+ dispatch(updateEditStateApplyState(INITIAL_EDIT_APPLY_STATE));
140+
141+ await dispatch(
142+ saveCurrentSession({
143+ openNewSession: true,
144+ // Because this causes a lag before Edit is focused. TODO just have that happen in background
145+ generateTitle: false,
146+ }),
147+ );
148+
149+ dispatch(setIsInEdit(true));
150+
151+ if (!state.editModeState.codeToEdit[0]) {
152+ extra.ideMessenger.post("edit/addCurrentSelection", undefined);
153+ }
154+ },
155+);
deleted gui/src/redux/thunks/editMode.ts +0 −130
@@ -1,130 +0,0 @@
1-import { createAsyncThunk } from "@reduxjs/toolkit";
2-import { JSONContent } from "@tiptap/core";
3-import {
4- SetCodeToEditPayload,
5- MessageModes,
6- RangeInFileWithContents,
7-} from "core";
8-import { stripImages } from "core/util/messageContent";
9-import { resolveEditorContent } from "../../components/mainInput/TipTapEditor";
10-import {
11- clearCodeToEdit,
12- INITIAL_EDIT_APPLY_STATE,
13- setReturnToModeAfterEdit,
14- updateEditStateApplyState,
15-} from "../slices/editModeState";
16-import { newSession, setActive, setMode } from "../slices/sessionSlice";
17-import { ThunkApiType } from "../store";
18-import { loadLastSession, saveCurrentSession } from "./session";
19-import { streamThunkWrapper } from "./streamThunkWrapper";
20-
21-export const streamEditThunk = createAsyncThunk<
22- void,
23- {
24- editorState: JSONContent;
25- codeToEdit: SetCodeToEditPayload[];
26- },
27- ThunkApiType
28->(
29- "chat/streamResponse",
30- async ({ editorState, codeToEdit }, { dispatch, extra, getState }) => {
31- await dispatch(
32- streamThunkWrapper(async () => {
33- dispatch(setActive());
34- const [contextItems, __, userInstructions, _] =
35- await resolveEditorContent({
36- editorState,
37- modifiers: {
38- noContext: true,
39- useCodebase: false,
40- },
41- ideMessenger: extra.ideMessenger,
42- defaultContextProviders: [],
43- availableSlashCommands: [],
44- dispatch,
45- });
46-
47- const prompt = [
48- ...contextItems.map((item) => item.content),
49- stripImages(userInstructions),
50- ].join("\n\n");
51-
52- const response = await extra.ideMessenger.request("edit/sendPrompt", {
53- prompt,
54- range: codeToEdit[0] as RangeInFileWithContents,
55- });
56-
57- if (response.status === "error") {
58- throw new Error(response.error);
59- }
60- }),
61- );
62- },
63-);
64-
65-export const exitEditMode = createAsyncThunk<
66- void,
67- { goToMode?: MessageModes; openNewSession?: boolean },
68- ThunkApiType
69->(
70- "edit/exitMode",
71- async ({ goToMode, openNewSession }, { dispatch, extra, getState }) => {
72- const state = getState();
73- const codeToEdit = state.editModeState.codeToEdit;
74-
75- if (state.session.mode !== "edit") {
76- return;
77- }
78-
79- if (codeToEdit[0] && state.editModeState.applyState.numDiffs) {
80- extra.ideMessenger.post("rejectDiff", {
81- filepath: codeToEdit[0].filepath,
82- });
83- }
84-
85- extra.ideMessenger.post("edit/clearDecorations", undefined);
86-
87- dispatch(clearCodeToEdit());
88- dispatch(updateEditStateApplyState(INITIAL_EDIT_APPLY_STATE));
89-
90- if (openNewSession || state.editModeState.lastNonEditSessionWasEmpty) {
91- dispatch(newSession());
92- } else {
93- await dispatch(
94- loadLastSession({
95- saveCurrentSession: false,
96- }),
97- );
98- }
99-
100- dispatch(setMode(goToMode ?? state.editModeState.returnToMode));
101- },
102-);
103-
104-export const enterEditMode = createAsyncThunk<
105- void,
106- { returnToMode?: MessageModes },
107- ThunkApiType
108->("edit/enterMode", async ({ returnToMode }, { dispatch, extra, getState }) => {
109- const state = getState();
110-
111- if (state.session.mode === "edit") {
112- return;
113- }
114-
115- dispatch(setReturnToModeAfterEdit(returnToMode ?? state.session.mode));
116-
117- await dispatch(
118- saveCurrentSession({
119- openNewSession: true,
120- // Because this causes a lag before Edit mode is focused. TODO just have that happen in background
121- generateTitle: false,
122- }),
123- );
124- dispatch(updateEditStateApplyState(INITIAL_EDIT_APPLY_STATE));
125- dispatch(setMode("edit"));
126-
127- if (!state.editModeState.codeToEdit[0]) {
128- extra.ideMessenger.post("edit/addCurrentSelection", undefined);
129- }
130-});
modified gui/src/redux/thunks/index.ts +11 −7
@@ -1,7 +1,11 @@
1-export { gatherContext } from "./gatherContext";
2-export { resetStateForNewMessage } from "./resetStateForNewMessage";
3-export { streamNormalInput } from "./streamNormalInput";
4-export { streamResponseThunk } from "./streamResponse";
5-export { streamResponseAfterToolCall } from "./streamResponseAfterToolCall";
6-export { streamThunkWrapper } from "./streamThunkWrapper";
7-export { updateSelectedModelByRole } from "./updateSelectedModelByRole";
1+export * from "./callCurrentTool";
2+export * from "./cancelCurrentToolCall";
3+export * from "./cancelStream";
4+export * from "./edit";
5+export * from "./gatherContext";
6+export * from "./resetStateForNewMessage";
7+export * from "./streamNormalInput";
8+export * from "./streamResponse";
9+export * from "./streamResponseAfterToolCall";
10+export * from "./streamThunkWrapper";
11+export * from "./updateSelectedModelByRole";