Changesets · Branches · Tags · Compare
| Changeset | b0349aaa027a7542e6404a57f2dc8fb62cf77bfc347f530403a305f76319e08c |
|---|---|
| Author | Patrick Erichsen <patrick.a.erichsen@gmail.com> · 2025-05-25 19:55 -07:00 |
| Committer | GitHub <noreply@github.com> · 2025-05-25 19:55 -07:00 |
| Parents | f8a28b58727d, c4329554da83 |
46 files changed
modified core/index.d.ts +1 −1
| @@ -423,7 +423,7 @@ | ||
| 423 | 423 | completion: string; |
| 424 | 424 | } |
| 425 | 425 | |
| 426 | -export type MessageModes = "chat" | "edit" | "agent"; | |
| 426 | +export type MessageModes = "chat" | "agent"; | |
| 427 | 427 | |
| 428 | 428 | export type ToolStatus = |
| 429 | 429 | | "generating" |
modified gui/src/components/AcceptRejectDiffButtons.tsx +15 −28
| @@ -3,7 +3,7 @@ | ||
| 3 | 3 | import { useContext } from "react"; |
| 4 | 4 | import { IdeMessengerContext } from "../context/IdeMessenger"; |
| 5 | 5 | import { getMetaKeyLabel } from "../util"; |
| 6 | -import { useFontSize } from "./ui/font"; | |
| 6 | +import { ToolTip } from "./gui/Tooltip"; | |
| 7 | 7 | |
| 8 | 8 | export interface AcceptRejectAllButtonsProps { |
| 9 | 9 | applyStates: ApplyState[]; |
| @@ -21,8 +21,6 @@ | ||
| 21 | 21 | ); |
| 22 | 22 | const ideMessenger = useContext(IdeMessengerContext); |
| 23 | 23 | |
| 24 | - const tinyFont = useFontSize(-3); | |
| 25 | - | |
| 26 | 24 | async function handleAcceptOrReject(status: AcceptOrRejectOutcome) { |
| 27 | 25 | for (const { filepath = "", streamId } of pendingApplyStates) { |
| 28 | 26 | ideMessenger.post(status, { |
| @@ -36,54 +34,43 @@ | ||
| 36 | 34 | } |
| 37 | 35 | } |
| 38 | 36 | |
| 39 | - if (!pendingApplyStates.length) { | |
| 40 | - return null; | |
| 41 | - } | |
| 37 | + const rejectShortcut = `${getMetaKeyLabel()}⇧⌫`; | |
| 38 | + const acceptShortcut = `${getMetaKeyLabel()}⇧⏎`; | |
| 42 | 39 | |
| 43 | 40 | return ( |
| 44 | 41 | <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" | |
| 46 | 43 | data-testid="accept-reject-all-buttons" |
| 47 | 44 | > |
| 48 | 45 | <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" | |
| 50 | 47 | onClick={() => handleAcceptOrReject("rejectDiff")} |
| 51 | 48 | data-testid="edit-reject-button" |
| 49 | + data-tooltip-id="reject-shortcut" | |
| 50 | + data-tooltip-content={`Reject All (${rejectShortcut})`} | |
| 52 | 51 | > |
| 53 | 52 | <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" /> | |
| 55 | 54 | <span>Reject</span> |
| 56 | 55 | <span className="xs:inline-block hidden">All</span> |
| 57 | 56 | </div> |
| 58 | - | |
| 59 | - <span | |
| 60 | - className="xs:inline-block hidden text-gray-400" | |
| 61 | - style={{ | |
| 62 | - fontSize: tinyFont, | |
| 63 | - }} | |
| 64 | - > | |
| 65 | - ({getMetaKeyLabel()}⇧⌫) | |
| 66 | - </span> | |
| 67 | 57 | </button> |
| 58 | + <ToolTip id="reject-shortcut" /> | |
| 59 | + | |
| 68 | 60 | <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" | |
| 70 | 62 | onClick={() => handleAcceptOrReject("acceptDiff")} |
| 71 | 63 | data-testid="edit-accept-button" |
| 64 | + data-tooltip-id="accept-shortcut" | |
| 65 | + data-tooltip-content={`Accept All (${acceptShortcut})`} | |
| 72 | 66 | > |
| 73 | 67 | <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" /> | |
| 75 | 69 | <span>Accept</span> |
| 76 | 70 | <span className="xs:inline-block hidden">All</span> |
| 77 | 71 | </div> |
| 78 | - <span | |
| 79 | - className="xs:inline-block hidden text-gray-400" | |
| 80 | - style={{ | |
| 81 | - fontSize: tinyFont, | |
| 82 | - }} | |
| 83 | - > | |
| 84 | - ({getMetaKeyLabel()}⇧⏎) | |
| 85 | - </span> | |
| 86 | 72 | </button> |
| 73 | + <ToolTip id="accept-shortcut" /> | |
| 87 | 74 | </div> |
| 88 | 75 | ); |
| 89 | 76 | } |
modified gui/src/components/History/HistoryTableRow.tsx +2 −2
| @@ -6,7 +6,7 @@ | ||
| 6 | 6 | import { Input } from ".."; |
| 7 | 7 | import { IdeMessengerContext } from "../../context/IdeMessenger"; |
| 8 | 8 | import { useAppDispatch, useAppSelector } from "../../redux/hooks"; |
| 9 | -import { exitEditMode } from "../../redux/thunks/editMode"; | |
| 9 | +import { exitEdit } from "../../redux/thunks/edit"; | |
| 10 | 10 | import { |
| 11 | 11 | deleteSession, |
| 12 | 12 | getSession, |
| @@ -69,7 +69,7 @@ | ||
| 69 | 69 | data-testid={`history-row-${index}`} |
| 70 | 70 | className="hover:bg-vsc-editor-background relative box-border flex cursor-pointer overflow-hidden rounded-lg p-3" |
| 71 | 71 | onClick={async () => { |
| 72 | - await dispatch(exitEditMode({})); | |
| 72 | + await dispatch(exitEdit({})); | |
| 73 | 73 | if (sessionMetadata.sessionId !== currentSessionId) { |
| 74 | 74 | await dispatch( |
| 75 | 75 | loadSession({ |
modified gui/src/components/Layout.tsx +12 −12
| @@ -7,9 +7,9 @@ | ||
| 7 | 7 | import { LocalStorageProvider } from "../context/LocalStorage"; |
| 8 | 8 | import { useWebviewListener } from "../hooks/useWebviewListener"; |
| 9 | 9 | import { useAppDispatch, useAppSelector } from "../redux/hooks"; |
| 10 | -import { setCodeToEdit } from "../redux/slices/editModeState"; | |
| 10 | +import { setCodeToEdit } from "../redux/slices/editState"; | |
| 11 | 11 | import { setShowDialog } from "../redux/slices/uiSlice"; |
| 12 | -import { enterEditMode, exitEditMode } from "../redux/thunks/editMode"; | |
| 12 | +import { enterEdit, exitEdit } from "../redux/thunks/edit"; | |
| 13 | 13 | import { saveCurrentSession } from "../redux/thunks/session"; |
| 14 | 14 | import { fontSize, isMetaEquivalentKeyPressed } from "../util"; |
| 15 | 15 | import { incrementFreeTrialCount } from "../util/freeTrial"; |
| @@ -48,14 +48,14 @@ | ||
| 48 | 48 | const dialogMessage = useAppSelector((state) => state.ui.dialogMessage); |
| 49 | 49 | |
| 50 | 50 | const showDialog = useAppSelector((state) => state.ui.showDialog); |
| 51 | - const mode = useAppSelector((state) => state.session.mode); | |
| 51 | + const isInEdit = useAppSelector((store) => store.session.isInEdit); | |
| 52 | 52 | |
| 53 | 53 | useWebviewListener( |
| 54 | 54 | "newSession", |
| 55 | 55 | async () => { |
| 56 | 56 | navigate(ROUTES.HOME); |
| 57 | - if (mode === "edit") { | |
| 58 | - await dispatch(exitEditMode({})); | |
| 57 | + if (isInEdit) { | |
| 58 | + await dispatch(exitEdit({})); | |
| 59 | 59 | } else { |
| 60 | 60 | await dispatch( |
| 61 | 61 | saveCurrentSession({ |
| @@ -65,7 +65,7 @@ | ||
| 65 | 65 | ); |
| 66 | 66 | } |
| 67 | 67 | }, |
| 68 | - [mode], | |
| 68 | + [isInEdit], | |
| 69 | 69 | ); |
| 70 | 70 | |
| 71 | 71 | useWebviewListener( |
| @@ -81,9 +81,9 @@ | ||
| 81 | 81 | "focusContinueInputWithNewSession", |
| 82 | 82 | async () => { |
| 83 | 83 | navigate(ROUTES.HOME); |
| 84 | - if (mode === "edit") { | |
| 84 | + if (isInEdit) { | |
| 85 | 85 | await dispatch( |
| 86 | - exitEditMode({ | |
| 86 | + exitEdit({ | |
| 87 | 87 | openNewSession: true, |
| 88 | 88 | }), |
| 89 | 89 | ); |
| @@ -96,7 +96,7 @@ | ||
| 96 | 96 | ); |
| 97 | 97 | } |
| 98 | 98 | }, |
| 99 | - [location.pathname, mode], | |
| 99 | + [location.pathname, isInEdit], | |
| 100 | 100 | location.pathname === ROUTES.HOME, |
| 101 | 101 | ); |
| 102 | 102 | |
| @@ -148,7 +148,7 @@ | ||
| 148 | 148 | "focusEdit", |
| 149 | 149 | async () => { |
| 150 | 150 | await ideMessenger.request("edit/addCurrentSelection", undefined); |
| 151 | - await dispatch(enterEditMode({})); | |
| 151 | + await dispatch(enterEdit({ editorContent: mainEditor?.getJSON() })); | |
| 152 | 152 | mainEditor?.commands.focus(); |
| 153 | 153 | }, |
| 154 | 154 | [ideMessenger, mainEditor], |
| @@ -169,7 +169,7 @@ | ||
| 169 | 169 | useWebviewListener( |
| 170 | 170 | "exitEditMode", |
| 171 | 171 | async () => { |
| 172 | - await dispatch(exitEditMode({})); | |
| 172 | + await dispatch(exitEdit({})); | |
| 173 | 173 | }, |
| 174 | 174 | [], |
| 175 | 175 | ); |
| @@ -181,7 +181,7 @@ | ||
| 181 | 181 | if (selection) { |
| 182 | 182 | // Copy to clipboard |
| 183 | 183 | setTimeout(() => { |
| 184 | - navigator.clipboard.writeText(selection); | |
| 184 | + void navigator.clipboard.writeText(selection); | |
| 185 | 185 | }, 100); |
| 186 | 186 | } |
| 187 | 187 | } |
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 @@ | ||
| 83 | 83 | const availableContextProviders = useAppSelector( |
| 84 | 84 | (state) => state.config.config.contextProviders, |
| 85 | 85 | ); |
| 86 | - const mode = useAppSelector((store) => store.session.mode); | |
| 86 | + const isInEdit = useAppSelector((store) => store.session.isInEdit); | |
| 87 | 87 | const editModeState = useAppSelector((state) => state.editModeState); |
| 88 | 88 | |
| 89 | 89 | const filteredSlashCommands = useMemo(() => { |
| 90 | - return mode === "edit" ? [] : availableSlashCommands; | |
| 91 | - }, [mode, availableSlashCommands]); | |
| 90 | + return isInEdit ? [] : availableSlashCommands; | |
| 91 | + }, [isInEdit, availableSlashCommands]); | |
| 92 | 92 | |
| 93 | 93 | const filteredContextProviders = useMemo(() => { |
| 94 | - if (mode === "edit") { | |
| 94 | + if (isInEdit) { | |
| 95 | 95 | return ( |
| 96 | 96 | availableContextProviders?.filter( |
| 97 | 97 | (provider) => |
| @@ -101,22 +101,21 @@ | ||
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | return availableContextProviders ?? []; |
| 104 | - }, [availableContextProviders, mode]); | |
| 104 | + }, [availableContextProviders, isInEdit]); | |
| 105 | 105 | |
| 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; | |
| 108 | 108 | |
| 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 | + : {}; | |
| 120 | 119 | |
| 121 | 120 | const { appliedRules = [], contextItems = [] } = props; |
| 122 | 121 |
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 @@ | ||
| 10 | 10 | selectCurrentToolCallApplyState, |
| 11 | 11 | } from "../../redux/selectors/selectCurrentToolCall"; |
| 12 | 12 | import { selectSelectedChatModel } from "../../redux/slices/configSlice"; |
| 13 | -import { exitEditMode } from "../../redux/thunks/editMode"; | |
| 13 | +import { exitEdit } from "../../redux/thunks/edit"; | |
| 14 | 14 | import { |
| 15 | 15 | getAltKeyLabel, |
| 16 | 16 | getMetaKeyLabel, |
| @@ -18,7 +18,7 @@ | ||
| 18 | 18 | } from "../../util"; |
| 19 | 19 | import { ToolTip } from "../gui/Tooltip"; |
| 20 | 20 | import ModelSelect from "../modelSelection/ModelSelect"; |
| 21 | -import ModeSelect from "../modelSelection/ModeSelect"; | |
| 21 | +import { ModeSelect } from "../ModeSelect"; | |
| 22 | 22 | import { useFontSize } from "../ui/font"; |
| 23 | 23 | import { EnterButton } from "./InputToolbar/EnterButton"; |
| 24 | 24 | import HoverItem from "./InputToolbar/HoverItem"; |
| @@ -49,7 +49,7 @@ | ||
| 49 | 49 | const fileInputRef = useRef<HTMLInputElement | null>(null); |
| 50 | 50 | const defaultModel = useAppSelector(selectSelectedChatModel); |
| 51 | 51 | const useActiveFile = useAppSelector(selectUseActiveFile); |
| 52 | - const mode = useAppSelector((store) => store.session.mode); | |
| 52 | + const isInEdit = useAppSelector((store) => store.session.isInEdit); | |
| 53 | 53 | const codeToEdit = useAppSelector((store) => store.editModeState.codeToEdit); |
| 54 | 54 | const toolCallState = useAppSelector(selectCurrentToolCall); |
| 55 | 55 | const currentToolCallApplyState = useAppSelector( |
| @@ -58,7 +58,7 @@ | ||
| 58 | 58 | |
| 59 | 59 | const isEnterDisabled = |
| 60 | 60 | props.disabled || |
| 61 | - (mode === "edit" && codeToEdit.length === 0) || | |
| 61 | + (isInEdit && codeToEdit.length === 0) || | |
| 62 | 62 | toolCallState?.status === "generated" || |
| 63 | 63 | (currentToolCallApplyState && |
| 64 | 64 | currentToolCallApplyState.status !== "closed"); |
| @@ -87,19 +87,21 @@ | ||
| 87 | 87 | }} |
| 88 | 88 | > |
| 89 | 89 | <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 | + )} | |
| 96 | 98 | <HoverItem data-tooltip-id="model-select-tooltip" className="!p-0"> |
| 97 | 99 | <ModelSelect /> |
| 98 | 100 | <ToolTip id="model-select-tooltip" place="top"> |
| 99 | 101 | Select Model |
| 100 | 102 | </ToolTip> |
| 101 | 103 | </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"> | |
| 103 | 105 | {props.toolbarOptions?.hideImageUpload || |
| 104 | 106 | (supportsImages && ( |
| 105 | 107 | <> |
| @@ -149,12 +151,12 @@ | ||
| 149 | 151 | </div> |
| 150 | 152 | |
| 151 | 153 | <div |
| 152 | - className="flex items-center gap-2 whitespace-nowrap text-gray-400" | |
| 154 | + className="text-description flex items-center gap-2 whitespace-nowrap" | |
| 153 | 155 | style={{ |
| 154 | 156 | fontSize: tinyFont, |
| 155 | 157 | }} |
| 156 | 158 | > |
| 157 | - {!props.toolbarOptions?.hideUseCodebase && mode !== "edit" && ( | |
| 159 | + {!props.toolbarOptions?.hideUseCodebase && !isInEdit && ( | |
| 158 | 160 | <div |
| 159 | 161 | className={`${toolsSupported ? "md:flex" : "int:flex"} hover:underline" hidden transition-colors duration-200`} |
| 160 | 162 | > |
| @@ -184,16 +186,16 @@ | ||
| 184 | 186 | </div> |
| 185 | 187 | )} |
| 186 | 188 | |
| 187 | - {mode === "edit" && ( | |
| 189 | + {isInEdit && ( | |
| 188 | 190 | <HoverItem |
| 189 | 191 | className="hidden hover:underline sm:flex" |
| 190 | 192 | onClick={async () => { |
| 191 | - dispatch(exitEditMode({})); | |
| 193 | + void dispatch(exitEdit({})); | |
| 192 | 194 | ideMessenger.post("focusEditor", undefined); |
| 193 | 195 | }} |
| 194 | 196 | > |
| 195 | 197 | <span> |
| 196 | - <i>Esc</i> to exit | |
| 198 | + <i>Esc</i> to exit Edit | |
| 197 | 199 | </span> |
| 198 | 200 | </HoverItem> |
| 199 | 201 | )} |
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 @@ | ||
| 37 | 37 | |
| 38 | 38 | return ( |
| 39 | 39 | <LumpDiv> |
| 40 | - <div className="xs:px-2 mt-0.5 px-1"> | |
| 40 | + <div className="xs:px-2 px-1 py-0.5"> | |
| 41 | 41 | <LumpToolbar /> |
| 42 | 42 | |
| 43 | 43 | <ContentDiv |
modified gui/src/components/mainInput/TipTapEditor/MainEditorProvider.tsx +15 −12
| @@ -27,9 +27,15 @@ | ||
| 27 | 27 | onEnterRef: React.MutableRefObject<(modifiers: InputModifiers) => void>; |
| 28 | 28 | } |
| 29 | 29 | |
| 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); | |
| 33 | 39 | |
| 34 | 40 | /** |
| 35 | 41 | * Provider component that maintains a reference to the main editor |
| @@ -38,8 +44,10 @@ | ||
| 38 | 44 | children, |
| 39 | 45 | }) => { |
| 40 | 46 | 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); | |
| 43 | 51 | const onEnterRef = useRef<(modifiers: InputModifiers) => void>(() => {}); |
| 44 | 52 | const editorFocusedRef = useRef<boolean>(false); |
| 45 | 53 | const historyLength = useAppSelector((store) => store.session.history.length); |
| @@ -108,10 +116,5 @@ | ||
| 108 | 116 | /** |
| 109 | 117 | * Hook to access the main editor context |
| 110 | 118 | */ |
| 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 @@ | ||
| 42 | 42 | const mainEditorContext = useMainEditor(); |
| 43 | 43 | |
| 44 | 44 | const ideMessenger = useContext(IdeMessengerContext); |
| 45 | - | |
| 46 | 45 | const isOSREnabled = useIsOSREnabled(); |
| 47 | 46 | |
| 48 | 47 | const defaultModel = useAppSelector(selectSelectedChatModel); |
| 49 | 48 | const isStreaming = useAppSelector((state) => state.session.isStreaming); |
| 50 | 49 | const historyLength = useAppSelector((store) => store.session.history.length); |
| 50 | + const isInEdit = useAppSelector((store) => store.session.isInEdit); | |
| 51 | 51 | |
| 52 | - const mode = useAppSelector((store) => store.session.mode); | |
| 53 | 52 | const { editor, onEnterRef } = createEditorConfig({ |
| 54 | 53 | props, |
| 55 | 54 | ideMessenger, |
| @@ -87,10 +86,10 @@ | ||
| 87 | 86 | }, [editor, props.isMainInput]); |
| 88 | 87 | |
| 89 | 88 | useEffect(() => { |
| 90 | - if (mode === "edit") { | |
| 89 | + if (isInEdit) { | |
| 91 | 90 | setShouldHideToolbar(false); |
| 92 | 91 | } |
| 93 | - }, [mode]); | |
| 92 | + }, [isInEdit]); | |
| 94 | 93 | |
| 95 | 94 | const editorFocusedRef = useUpdatingRef(editor?.isFocused, [editor]); |
| 96 | 95 | |
| @@ -150,7 +149,7 @@ | ||
| 150 | 149 | |
| 151 | 150 | const handleBlur = useCallback( |
| 152 | 151 | (e: React.FocusEvent) => { |
| 153 | - if (mode === "edit") { | |
| 152 | + if (isInEdit) { | |
| 154 | 153 | return; |
| 155 | 154 | } |
| 156 | 155 | // Check if the new focus target is within our InputBoxDiv |
| @@ -165,7 +164,7 @@ | ||
| 165 | 164 | setShouldHideToolbar(true); |
| 166 | 165 | }, 100); |
| 167 | 166 | }, |
| 168 | - [mode, blurTimeout], | |
| 167 | + [isInEdit, blurTimeout], | |
| 169 | 168 | ); |
| 170 | 169 | |
| 171 | 170 | const handleFocus = useCallback(() => { |
| @@ -213,7 +212,7 @@ | ||
| 213 | 212 | } |
| 214 | 213 | setShowDragOverMsg(false); |
| 215 | 214 | let file = event.dataTransfer.files[0]; |
| 216 | - handleImageFile(ideMessenger, file).then((result) => { | |
| 215 | + void handleImageFile(ideMessenger, file).then((result) => { | |
| 217 | 216 | if (!editor) { |
| 218 | 217 | return; |
| 219 | 218 | } |
| @@ -245,7 +244,7 @@ | ||
| 245 | 244 | onAddContextItem={() => insertCharacterWithWhitespace("@")} |
| 246 | 245 | onEnter={onEnterRef.current} |
| 247 | 246 | onImageFileSelected={(file) => { |
| 248 | - handleImageFile(ideMessenger, file).then((result) => { | |
| 247 | + void handleImageFile(ideMessenger, file).then((result) => { | |
| 249 | 248 | if (!editor) { |
| 250 | 249 | return; |
| 251 | 250 | } |
modified gui/src/components/mainInput/TipTapEditor/useMainEditorWebviewListeners.ts +1 −1
| @@ -3,7 +3,7 @@ | ||
| 3 | 3 | import { rifWithContentsToContextItem } from "core/commands/util"; |
| 4 | 4 | import { MutableRefObject } from "react"; |
| 5 | 5 | import { useWebviewListener } from "../../../hooks/useWebviewListener"; |
| 6 | -import { clearCodeToEdit } from "../../../redux/slices/editModeState"; | |
| 6 | +import { clearCodeToEdit } from "../../../redux/slices/editState"; | |
| 7 | 7 | import { setNewestToolbarPreviewForInput } from "../../../redux/slices/sessionSlice"; |
| 8 | 8 | import { AppDispatch } from "../../../redux/store"; |
| 9 | 9 | import { loadSession, saveCurrentSession } from "../../../redux/thunks/session"; |
modified gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts +9 −9
| @@ -23,7 +23,7 @@ | ||
| 23 | 23 | import { selectUseActiveFile } from "../../../../redux/selectors"; |
| 24 | 24 | import { selectSelectedChatModel } from "../../../../redux/slices/configSlice"; |
| 25 | 25 | import { AppDispatch } from "../../../../redux/store"; |
| 26 | -import { exitEditMode } from "../../../../redux/thunks/editMode"; | |
| 26 | +import { exitEdit } from "../../../../redux/thunks/edit"; | |
| 27 | 27 | import { getFontSize, isJetBrains } from "../../../../util"; |
| 28 | 28 | import * as ContinueExtensions from "../extensions"; |
| 29 | 29 | import { TipTapEditorProps } from "../TipTapEditor"; |
| @@ -81,9 +81,9 @@ | ||
| 81 | 81 | const isStreaming = useAppSelector((state) => state.session.isStreaming); |
| 82 | 82 | const useActiveFile = useAppSelector(selectUseActiveFile); |
| 83 | 83 | const historyLength = useAppSelector((store) => store.session.history.length); |
| 84 | - const mode = useAppSelector((store) => store.session.mode); | |
| 85 | - const modeRef = useUpdatingRef(mode); | |
| 86 | 84 | const codeToEdit = useAppSelector((store) => store.editModeState.codeToEdit); |
| 85 | + const isInEdit = useAppSelector((store) => store.session.isInEdit); | |
| 86 | + const isInEditRef = useUpdatingRef(isInEdit); | |
| 87 | 87 | |
| 88 | 88 | const inSubmenuRef = useRef<string | undefined>(undefined); |
| 89 | 89 | const inDropdownRef = useRef(false); |
| @@ -157,7 +157,7 @@ | ||
| 157 | 157 | for (const item of items) { |
| 158 | 158 | const file = item.getAsFile(); |
| 159 | 159 | file && |
| 160 | - modelSupportsImages( | |
| 160 | + void modelSupportsImages( | |
| 161 | 161 | model.provider, |
| 162 | 162 | model.model, |
| 163 | 163 | model.title, |
| @@ -269,9 +269,9 @@ | ||
| 269 | 269 | return true; |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | - if (modeRef.current === "edit") { | |
| 273 | - dispatch( | |
| 274 | - exitEditMode({ | |
| 272 | + if (isInEditRef.current) { | |
| 273 | + void dispatch( | |
| 274 | + exitEdit({ | |
| 275 | 275 | openNewSession: false, |
| 276 | 276 | }), |
| 277 | 277 | ); |
| @@ -345,7 +345,7 @@ | ||
| 345 | 345 | if (!editor) { |
| 346 | 346 | return; |
| 347 | 347 | } |
| 348 | - if (isStreaming || (codeToEdit.length === 0 && mode === "edit")) { | |
| 348 | + if (isStreaming || (codeToEdit.length === 0 && isInEdit)) { | |
| 349 | 349 | return; |
| 350 | 350 | } |
| 351 | 351 | |
| @@ -362,7 +362,7 @@ | ||
| 362 | 362 | |
| 363 | 363 | props.onEnter(json, modifiers, editor); |
| 364 | 364 | }, |
| 365 | - [props.onEnter, editor, props.isMainInput, codeToEdit, mode], | |
| 365 | + [props.onEnter, editor, props.isMainInput, codeToEdit, isInEdit], | |
| 366 | 366 | ); |
| 367 | 367 | |
| 368 | 368 | 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 @@ | ||
| 6 | 6 | PlusIcon, |
| 7 | 7 | } from "@heroicons/react/24/outline"; |
| 8 | 8 | import { useContext, useEffect, useRef, useState } from "react"; |
| 9 | -import styled from "styled-components"; | |
| 10 | -import { defaultBorderRadius, lightGray } from ".."; | |
| 9 | +import { lightGray } from ".."; | |
| 11 | 10 | import { useAuth } from "../../context/Auth"; |
| 12 | 11 | import { IdeMessengerContext } from "../../context/IdeMessenger"; |
| 13 | 12 | import AddModelForm from "../../forms/AddModelForm"; |
| @@ -30,21 +29,6 @@ | ||
| 30 | 29 | apiKey?: string; |
| 31 | 30 | } |
| 32 | 31 | |
| 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 | - | |
| 48 | 32 | function modelSelectTitle(model: any): string { |
| 49 | 33 | if (model?.title) return model?.title; |
| 50 | 34 | if (model?.model !== undefined && model?.model.trim() !== "") { |
| @@ -120,12 +104,12 @@ | ||
| 120 | 104 | function ModelSelect() { |
| 121 | 105 | const dispatch = useAppDispatch(); |
| 122 | 106 | |
| 123 | - const mode = useAppSelector((store) => store.session.mode); | |
| 107 | + const isInEdit = useAppSelector((store) => store.session.isInEdit); | |
| 124 | 108 | const config = useAppSelector((state) => state.config.config); |
| 125 | 109 | |
| 126 | 110 | let selectedModel = null; |
| 127 | 111 | let allModels = null; |
| 128 | - if (mode === "edit") { | |
| 112 | + if (isInEdit) { | |
| 129 | 113 | allModels = config.modelsByRole.edit; |
| 130 | 114 | selectedModel = config.selectedModelByRole.edit; |
| 131 | 115 | } |
| @@ -226,7 +210,7 @@ | ||
| 226 | 210 | void dispatch( |
| 227 | 211 | updateSelectedModelByRole({ |
| 228 | 212 | selectedProfile, |
| 229 | - role: mode === "edit" ? "edit" : "chat", | |
| 213 | + role: isInEdit ? "edit" : "chat", | |
| 230 | 214 | modelTitle: val, |
| 231 | 215 | }), |
| 232 | 216 | ); |
| @@ -236,7 +220,7 @@ | ||
| 236 | 220 | <ListboxButton |
| 237 | 221 | data-testid="model-select-button" |
| 238 | 222 | ref={buttonRef} |
| 239 | - className="h-[18px] gap-1 border-none text-gray-400" | |
| 223 | + className="text-description h-[18px] gap-1 border-none" | |
| 240 | 224 | > |
| 241 | 225 | <span className="line-clamp-1 break-all hover:brightness-110"> |
| 242 | 226 | {modelSelectTitle(selectedModel) || "Select model"} |
modified gui/src/components/modelSelection/platform/AssistantSelect.tsx +8 −8
| @@ -126,7 +126,7 @@ | ||
| 126 | 126 | )} |
| 127 | 127 | {isLocalProfile(profile) ? ( |
| 128 | 128 | <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" | |
| 130 | 130 | onClick={(e) => { |
| 131 | 131 | e.stopPropagation(); |
| 132 | 132 | e.preventDefault(); |
| @@ -135,7 +135,7 @@ | ||
| 135 | 135 | /> |
| 136 | 136 | ) : ( |
| 137 | 137 | <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" | |
| 139 | 139 | onClick={(e) => { |
| 140 | 140 | e.stopPropagation(); |
| 141 | 141 | e.preventDefault(); |
| @@ -242,12 +242,12 @@ | ||
| 242 | 242 | return ( |
| 243 | 243 | <div |
| 244 | 244 | onClick={() => { |
| 245 | - ideMessenger.request("controlPlane/openUrl", { | |
| 245 | + void ideMessenger.request("controlPlane/openUrl", { | |
| 246 | 246 | path: "/new?type=assistant", |
| 247 | 247 | orgSlug: currentOrg?.slug, |
| 248 | 248 | }); |
| 249 | 249 | }} |
| 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" | |
| 251 | 251 | style={{ fontSize: smallFont }} |
| 252 | 252 | > |
| 253 | 253 | <PlusIcon className="h-3 w-3 flex-shrink-0 select-none" /> |
| @@ -266,7 +266,7 @@ | ||
| 266 | 266 | <ListboxButton |
| 267 | 267 | data-testid="assistant-select-button" |
| 268 | 268 | 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" | |
| 270 | 270 | style={{ fontSize: fontSize(-3) }} |
| 271 | 271 | > |
| 272 | 272 | <div className="flex flex-row items-center gap-1.5"> |
| @@ -301,7 +301,7 @@ | ||
| 301 | 301 | > |
| 302 | 302 | <ArrowPathIcon |
| 303 | 303 | className={cn( |
| 304 | - "text-lightgray h-2.5 w-2.5", | |
| 304 | + "text-description h-2.5 w-2.5", | |
| 305 | 305 | loading && "animate-spin-slow", |
| 306 | 306 | )} |
| 307 | 307 | /> |
| @@ -339,7 +339,7 @@ | ||
| 339 | 339 | onClick={session ? onNewAssistant : () => login(false)} |
| 340 | 340 | > |
| 341 | 341 | <div |
| 342 | - className="text-lightgray flex flex-row items-center gap-2" | |
| 342 | + className="text-description flex flex-row items-center gap-2" | |
| 343 | 343 | style={{ |
| 344 | 344 | fontSize: tinyFont, |
| 345 | 345 | }} |
| @@ -358,7 +358,7 @@ | ||
| 358 | 358 | /> |
| 359 | 359 | |
| 360 | 360 | <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" | |
| 362 | 362 | style={{ |
| 363 | 363 | fontSize: tinyFont, |
| 364 | 364 | }} |
modified gui/src/hooks/ParallelListeners.tsx +46 −34
| @@ -3,6 +3,7 @@ | ||
| 3 | 3 | |
| 4 | 4 | import { EDIT_MODE_STREAM_ID } from "core/edit/constants"; |
| 5 | 5 | import { FromCoreProtocol } from "core/protocol"; |
| 6 | +import { useMainEditor } from "../components/mainInput/TipTapEditor"; | |
| 6 | 7 | import { |
| 7 | 8 | initializeProfilePreferences, |
| 8 | 9 | setOrganizations, |
| @@ -15,7 +16,7 @@ | ||
| 15 | 16 | import { |
| 16 | 17 | setLastNonEditSessionEmpty, |
| 17 | 18 | updateEditStateApplyState, |
| 18 | -} from "../redux/slices/editModeState"; | |
| 19 | +} from "../redux/slices/editState"; | |
| 19 | 20 | import { updateIndexingStatus } from "../redux/slices/indexingSlice"; |
| 20 | 21 | import { |
| 21 | 22 | acceptToolCall, |
| @@ -23,7 +24,7 @@ | ||
| 23 | 24 | updateApplyState, |
| 24 | 25 | } from "../redux/slices/sessionSlice"; |
| 25 | 26 | import { setTTSActive } from "../redux/slices/uiSlice"; |
| 26 | -import { streamResponseAfterToolCall } from "../redux/thunks"; | |
| 27 | +import { exitEdit, streamResponseAfterToolCall } from "../redux/thunks"; | |
| 27 | 28 | import { cancelStream } from "../redux/thunks/cancelStream"; |
| 28 | 29 | import { refreshSessionMetadata } from "../redux/thunks/session"; |
| 29 | 30 | import { streamResponseThunk } from "../redux/thunks/streamResponse"; |
| @@ -40,12 +41,18 @@ | ||
| 40 | 41 | const dispatch = useAppDispatch(); |
| 41 | 42 | const ideMessenger = useContext(IdeMessengerContext); |
| 42 | 43 | const history = useAppSelector((store) => store.session.history); |
| 44 | + const isInEdit = useAppSelector((store) => store.session.isInEdit); | |
| 43 | 45 | |
| 44 | 46 | const selectedProfileId = useAppSelector( |
| 45 | 47 | (store) => store.profiles.selectedProfileId, |
| 46 | 48 | ); |
| 47 | 49 | |
| 48 | 50 | const hasDoneInitialConfigLoad = useRef(false); |
| 51 | + const currentToolCallApplyState = useAppSelector( | |
| 52 | + selectCurrentToolCallApplyState, | |
| 53 | + ); | |
| 54 | + | |
| 55 | + const { mainEditor } = useMainEditor(); | |
| 49 | 56 | |
| 50 | 57 | const handleConfigUpdate = useCallback( |
| 51 | 58 | async (isInitial: boolean, result: FromCoreProtocol["configUpdate"][0]) => { |
| @@ -99,18 +106,18 @@ | ||
| 99 | 106 | |
| 100 | 107 | // Load config from the IDE |
| 101 | 108 | useEffect(() => { |
| 102 | - initialLoadAuthAndConfig(true); | |
| 109 | + void initialLoadAuthAndConfig(true); | |
| 103 | 110 | const interval = setInterval(() => { |
| 104 | 111 | if (hasDoneInitialConfigLoad.current) { |
| 105 | 112 | // Init to run on initial config load |
| 106 | 113 | ideMessenger.post("docs/initStatuses", undefined); |
| 107 | - dispatch(updateFileSymbolsFromHistory()); | |
| 108 | - dispatch(refreshSessionMetadata({})); | |
| 114 | + void dispatch(updateFileSymbolsFromHistory()); | |
| 115 | + void dispatch(refreshSessionMetadata({})); | |
| 109 | 116 | |
| 110 | 117 | // This triggers sending pending status to the GUI for relevant docs indexes |
| 111 | 118 | clearInterval(interval); |
| 112 | 119 | } else { |
| 113 | - initialLoadAuthAndConfig(true); | |
| 120 | + void initialLoadAuthAndConfig(true); | |
| 114 | 121 | } |
| 115 | 122 | }, 2_000); |
| 116 | 123 | |
| @@ -132,39 +139,43 @@ | ||
| 132 | 139 | const sessionId = useAppSelector((state) => state.session.id); |
| 133 | 140 | useEffect(() => { |
| 134 | 141 | if (sessionId) { |
| 135 | - dispatch(updateFileSymbolsFromHistory()); | |
| 142 | + void dispatch(updateFileSymbolsFromHistory()); | |
| 136 | 143 | } |
| 137 | 144 | }, [sessionId]); |
| 138 | 145 | |
| 139 | 146 | // ON LOAD |
| 140 | 147 | useEffect(() => { |
| 141 | 148 | // Override persisted state |
| 142 | - dispatch(cancelStream()); | |
| 149 | + void dispatch(cancelStream()); | |
| 143 | 150 | |
| 144 | 151 | const jetbrains = isJetBrains(); |
| 145 | 152 | setDocumentStylesFromLocalStorage(jetbrains); |
| 146 | 153 | |
| 147 | 154 | if (jetbrains) { |
| 148 | 155 | // 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 | + }); | |
| 154 | 163 | |
| 155 | 164 | // 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 | + }); | |
| 168 | 179 | } |
| 169 | 180 | }, []); |
| 170 | 181 | |
| @@ -194,7 +205,7 @@ | ||
| 194 | 205 | ); |
| 195 | 206 | |
| 196 | 207 | useWebviewListener("setInactive", async () => { |
| 197 | - dispatch(cancelStream()); | |
| 208 | + void dispatch(cancelStream()); | |
| 198 | 209 | }); |
| 199 | 210 | |
| 200 | 211 | useWebviewListener("setTTSActive", async (status) => { |
| @@ -203,7 +214,7 @@ | ||
| 203 | 214 | |
| 204 | 215 | // TODO - remove? |
| 205 | 216 | useWebviewListener("submitMessage", async (data) => { |
| 206 | - dispatch( | |
| 217 | + void dispatch( | |
| 207 | 218 | streamResponseThunk({ |
| 208 | 219 | editorState: data.message, |
| 209 | 220 | modifiers: { useCodebase: false, noContext: true }, |
| @@ -224,14 +235,15 @@ | ||
| 224 | 235 | dispatch(updateIndexingStatus(data)); |
| 225 | 236 | }); |
| 226 | 237 | |
| 227 | - const currentToolCallApplyState = useAppSelector( | |
| 228 | - selectCurrentToolCallApplyState, | |
| 229 | - ); | |
| 230 | 238 | useWebviewListener( |
| 231 | 239 | "updateApplyState", |
| 232 | 240 | async (state) => { |
| 233 | 241 | if (state.streamId === EDIT_MODE_STREAM_ID) { |
| 234 | 242 | dispatch(updateEditStateApplyState(state)); |
| 243 | + | |
| 244 | + if (state.status === "closed") { | |
| 245 | + dispatch(exitEdit({})); | |
| 246 | + } | |
| 235 | 247 | } else { |
| 236 | 248 | // chat or agent |
| 237 | 249 | dispatch(updateApplyState(state)); |
| @@ -253,7 +265,7 @@ | ||
| 253 | 265 | }), |
| 254 | 266 | ); |
| 255 | 267 | // dispatch(setToolCallOutput([])); |
| 256 | - dispatch( | |
| 268 | + void dispatch( | |
| 257 | 269 | streamResponseAfterToolCall({ |
| 258 | 270 | toolCallId: currentToolCallApplyState.toolCallId!, |
| 259 | 271 | }), |
| @@ -264,12 +276,12 @@ | ||
| 264 | 276 | [currentToolCallApplyState, history], |
| 265 | 277 | ); |
| 266 | 278 | |
| 267 | - const mode = useAppSelector((store) => store.session.mode); | |
| 268 | 279 | useEffect(() => { |
| 269 | - if (mode !== "edit") { | |
| 280 | + if (!isInEdit) { | |
| 270 | 281 | dispatch(setLastNonEditSessionEmpty(history.length === 0)); |
| 271 | 282 | } |
| 272 | - }, [mode, history]); | |
| 283 | + }, [isInEdit, history]); | |
| 284 | + | |
| 273 | 285 | return <></>; |
| 274 | 286 | } |
| 275 | 287 |
modified gui/src/pages/gui/Chat.test.tsx +2 −2
| @@ -35,8 +35,8 @@ | ||
| 35 | 35 | ); |
| 36 | 36 | }); |
| 37 | 37 | |
| 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(); | |
| 40 | 40 | }); |
| 41 | 41 | |
| 42 | 42 | it.skip("should send a message and receive a response", async () => { |
modified gui/src/pages/gui/Chat.tsx +28 −36
| @@ -46,7 +46,7 @@ | ||
| 46 | 46 | } from "../../redux/slices/uiSlice"; |
| 47 | 47 | import { streamResponseThunk } from "../../redux/thunks"; |
| 48 | 48 | import { cancelStream } from "../../redux/thunks/cancelStream"; |
| 49 | -import { streamEditThunk } from "../../redux/thunks/editMode"; | |
| 49 | +import { streamEditThunk } from "../../redux/thunks/edit"; | |
| 50 | 50 | import { loadLastSession } from "../../redux/thunks/session"; |
| 51 | 51 | import { isJetBrains, isMetaEquivalentKeyPressed } from "../../util"; |
| 52 | 52 | import { |
| @@ -54,9 +54,6 @@ | ||
| 54 | 54 | incrementFreeTrialCount, |
| 55 | 55 | } from "../../util/freeTrial"; |
| 56 | 56 | |
| 57 | -import AcceptRejectDiffButtons from "../../components/AcceptRejectDiffButtons"; | |
| 58 | -import CodeToEditCard from "../../components/mainInput/CodeToEditCard"; | |
| 59 | -import EditModeDetails from "../../components/mainInput/EditModeDetails"; | |
| 60 | 57 | import { getLocalStorage, setLocalStorage } from "../../util/localStorage"; |
| 61 | 58 | import { EmptyChatBody } from "./EmptyChatBody"; |
| 62 | 59 | import { ExploreDialogWatcher } from "./ExploreDialogWatcher"; |
| @@ -121,9 +118,7 @@ | ||
| 121 | 118 | const codeToEdit = useAppSelector((state) => state.editModeState.codeToEdit); |
| 122 | 119 | const toolCallState = useAppSelector(selectCurrentToolCall); |
| 123 | 120 | 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); | |
| 127 | 122 | |
| 128 | 123 | const lastSessionId = useAppSelector((state) => state.session.lastSessionId); |
| 129 | 124 | const hasDismissedExploreDialog = useAppSelector( |
| @@ -185,15 +180,14 @@ | ||
| 185 | 180 | ); |
| 186 | 181 | } |
| 187 | 182 | |
| 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; | |
| 192 | 186 | if (!model) { |
| 193 | 187 | return; |
| 194 | 188 | } |
| 195 | 189 | |
| 196 | - if (mode === "edit" && codeToEdit.length === 0) { | |
| 190 | + if (isInEdit && codeToEdit.length === 0) { | |
| 197 | 191 | return; |
| 198 | 192 | } |
| 199 | 193 | |
| @@ -224,15 +218,15 @@ | ||
| 224 | 218 | } |
| 225 | 219 | } |
| 226 | 220 | |
| 227 | - if (mode === "edit") { | |
| 228 | - dispatch( | |
| 221 | + if (isInEdit) { | |
| 222 | + void dispatch( | |
| 229 | 223 | streamEditThunk({ |
| 230 | 224 | editorState, |
| 231 | 225 | codeToEdit, |
| 232 | 226 | }), |
| 233 | 227 | ); |
| 234 | 228 | } else { |
| 235 | - dispatch(streamResponseThunk({ editorState, modifiers, index })); | |
| 229 | + void dispatch(streamResponseThunk({ editorState, modifiers, index })); | |
| 236 | 230 | |
| 237 | 231 | if (editorToClearOnSend) { |
| 238 | 232 | editorToClearOnSend.commands.clearContent(); |
| @@ -252,7 +246,15 @@ | ||
| 252 | 246 | setLocalStorage("mainTextEntryCounter", 1); |
| 253 | 247 | } |
| 254 | 248 | }, |
| 255 | - [history, selectedModels, streamResponse, mode, codeToEdit, toolCallState], | |
| 249 | + [ | |
| 250 | + history, | |
| 251 | + selectedModels, | |
| 252 | + streamResponse, | |
| 253 | + mode, | |
| 254 | + isInEdit, | |
| 255 | + codeToEdit, | |
| 256 | + toolCallState, | |
| 257 | + ], | |
| 256 | 258 | ); |
| 257 | 259 | |
| 258 | 260 | useWebviewListener( |
| @@ -292,7 +294,7 @@ | ||
| 292 | 294 | |
| 293 | 295 | return ( |
| 294 | 296 | <> |
| 295 | - {!!showSessionTabs && mode !== "edit" && <TabBar ref={tabsRef} />} | |
| 297 | + {!!showSessionTabs && !isInEdit && <TabBar ref={tabsRef} />} | |
| 296 | 298 | {widget} |
| 297 | 299 | |
| 298 | 300 | <StepsDiv |
| @@ -381,24 +383,14 @@ | ||
| 381 | 383 | ))} |
| 382 | 384 | </StepsDiv> |
| 383 | 385 | <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 | + /> | |
| 402 | 394 | |
| 403 | 395 | <div |
| 404 | 396 | style={{ |
| @@ -407,7 +399,7 @@ | ||
| 407 | 399 | > |
| 408 | 400 | <div className="flex flex-row items-center justify-between pb-1 pl-0.5 pr-2"> |
| 409 | 401 | <div className="xs:inline hidden"> |
| 410 | - {history.length === 0 && lastSessionId && mode !== "edit" && ( | |
| 402 | + {history.length === 0 && lastSessionId && !isInEdit && ( | |
| 411 | 403 | <div className="xs:inline hidden"> |
| 412 | 404 | <NewSessionButton |
| 413 | 405 | 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 @@ | ||
| 47 | 47 | mainEditorContentTrigger?: JSONContent | undefined; |
| 48 | 48 | symbols: FileSymbolMap; |
| 49 | 49 | mode: MessageModes; |
| 50 | + isInEdit: boolean; | |
| 50 | 51 | codeBlockApplyStates: { |
| 51 | 52 | states: ApplyState[]; |
| 52 | 53 | curIndex: number; |
| @@ -63,6 +64,7 @@ | ||
| 63 | 64 | streamAborter: new AbortController(), |
| 64 | 65 | symbols: {}, |
| 65 | 66 | mode: "chat", |
| 67 | + isInEdit: false, | |
| 66 | 68 | codeBlockApplyStates: { |
| 67 | 69 | states: [], |
| 68 | 70 | curIndex: 0, |
| @@ -645,6 +647,9 @@ | ||
| 645 | 647 | setMode: (state, action: PayloadAction<MessageModes>) => { |
| 646 | 648 | state.mode = action.payload; |
| 647 | 649 | }, |
| 650 | + setIsInEdit: (state, action: PayloadAction<boolean>) => { | |
| 651 | + state.isInEdit = action.payload; | |
| 652 | + }, | |
| 648 | 653 | setNewestToolbarPreviewForInput: ( |
| 649 | 654 | state, |
| 650 | 655 | { |
| @@ -741,6 +746,7 @@ | ||
| 741 | 746 | updateSessionMetadata, |
| 742 | 747 | deleteSessionMetadata, |
| 743 | 748 | setNewestToolbarPreviewForInput, |
| 749 | + setIsInEdit, | |
| 744 | 750 | } = sessionSlice.actions; |
| 745 | 751 | |
| 746 | 752 | export const { selectIsGatheringContext } = sessionSlice.selectors; |
modified gui/src/redux/store.ts +1 −1
| @@ -17,7 +17,7 @@ | ||
| 17 | 17 | import { IdeMessenger, IIdeMessenger } from "../context/IdeMessenger"; |
| 18 | 18 | import { profilesReducer } from "./slices"; |
| 19 | 19 | import configReducer from "./slices/configSlice"; |
| 20 | -import editModeStateReducer from "./slices/editModeState"; | |
| 20 | +import editModeStateReducer from "./slices/editState"; | |
| 21 | 21 | import indexingReducer from "./slices/indexingSlice"; |
| 22 | 22 | import sessionReducer from "./slices/sessionSlice"; |
| 23 | 23 | 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"; |