edit mode state updates
This commit is contained in:
parent
f302682a5a
commit
e36bef8a16
24 changed files with 194 additions and 349 deletions
|
|
@ -2,8 +2,6 @@ import { CheckIcon, XMarkIcon } from "@heroicons/react/24/outline";
|
|||
import { ApplyState } from "core";
|
||||
import { useContext } from "react";
|
||||
import { IdeMessengerContext } from "../context/IdeMessenger";
|
||||
import { useAppSelector } from "../redux/hooks";
|
||||
import { selectIsSingleRangeEditOrInsertion } from "../redux/slices/sessionSlice";
|
||||
import { getMetaKeyLabel } from "../util";
|
||||
|
||||
export interface AcceptRejectAllButtonsProps {
|
||||
|
|
@ -18,7 +16,6 @@ export default function AcceptRejectAllButtons({
|
|||
onAcceptOrReject,
|
||||
}: AcceptRejectAllButtonsProps) {
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const isSingleRangeEdit = useAppSelector(selectIsSingleRangeEditOrInsertion);
|
||||
|
||||
async function handleAcceptOrReject(status: AcceptOrRejectOutcome) {
|
||||
for (const { filepath = "", streamId } of pendingApplyStates) {
|
||||
|
|
@ -41,15 +38,7 @@ export default function AcceptRejectAllButtons({
|
|||
data-testid="edit-reject-button"
|
||||
>
|
||||
<XMarkIcon className="mr-1 h-4 w-4 text-red-600" />
|
||||
{isSingleRangeEdit ? (
|
||||
<span>Reject ({getMetaKeyLabel()}⇧⌫)</span>
|
||||
) : (
|
||||
<>
|
||||
<span className="sm:hidden">Reject</span>
|
||||
<span className="max-sm:hidden md:hidden">Reject all</span>
|
||||
<span className="max-md:hidden">Reject all changes</span>
|
||||
</>
|
||||
)}
|
||||
<span>Reject ({getMetaKeyLabel()}⇧⌫)</span>
|
||||
</button>
|
||||
<button
|
||||
className="flex cursor-pointer items-center border-none bg-transparent px-2 py-1 text-xs text-gray-300 opacity-80 hover:opacity-100 hover:brightness-125"
|
||||
|
|
@ -57,15 +46,7 @@ export default function AcceptRejectAllButtons({
|
|||
data-testid="edit-accept-button"
|
||||
>
|
||||
<CheckIcon className="mr-1 h-4 w-4 text-green-600" />
|
||||
{isSingleRangeEdit ? (
|
||||
<span>Accept ({getMetaKeyLabel()}⇧⏎)</span>
|
||||
) : (
|
||||
<>
|
||||
<span className="sm:hidden">Accept</span>
|
||||
<span className="max-sm:hidden md:hidden">Accept all</span>
|
||||
<span className="max-md:hidden">Accept all changes</span>
|
||||
</>
|
||||
)}
|
||||
<span>Accept ({getMetaKeyLabel()}⇧⏎)</span>
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -6,13 +6,12 @@ import { AuthProvider } from "../context/Auth";
|
|||
import { LocalStorageProvider } from "../context/LocalStorage";
|
||||
import { useWebviewListener } from "../hooks/useWebviewListener";
|
||||
import { useAppDispatch, useAppSelector } from "../redux/hooks";
|
||||
import { focusEdit, setEditStatus } from "../redux/slices/editModeState";
|
||||
import {
|
||||
addCodeToEdit,
|
||||
newSession,
|
||||
selectIsInEditMode,
|
||||
setMode,
|
||||
} from "../redux/slices/sessionSlice";
|
||||
focusEdit,
|
||||
setEditStatus,
|
||||
} from "../redux/slices/editModeState";
|
||||
import { newSession, setMode } from "../redux/slices/sessionSlice";
|
||||
import { setShowDialog } from "../redux/slices/uiSlice";
|
||||
import { exitEditMode } from "../redux/thunks";
|
||||
import { loadLastSession, saveCurrentSession } from "../redux/thunks/session";
|
||||
|
|
@ -172,7 +171,7 @@ const Layout = () => {
|
|||
async (payload) => {
|
||||
dispatch(addCodeToEdit(payload));
|
||||
},
|
||||
[navigate],
|
||||
[],
|
||||
);
|
||||
|
||||
useWebviewListener(
|
||||
|
|
@ -183,11 +182,11 @@ const Layout = () => {
|
|||
[],
|
||||
);
|
||||
|
||||
const isInEditMode = useAppSelector(selectIsInEditMode);
|
||||
const mode = useAppSelector((store) => store.session.mode);
|
||||
useWebviewListener(
|
||||
"exitEditMode",
|
||||
async () => {
|
||||
if (!isInEditMode) {
|
||||
if (mode !== "edit") {
|
||||
return;
|
||||
}
|
||||
dispatch(
|
||||
|
|
@ -197,7 +196,7 @@ const Layout = () => {
|
|||
);
|
||||
dispatch(exitEditMode());
|
||||
},
|
||||
[isInEditMode],
|
||||
[mode],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
|
|
|
|||
|
|
@ -12,9 +12,9 @@ import { IdeMessengerContext } from "../../../context/IdeMessenger";
|
|||
import { useAppDispatch } from "../../../redux/hooks";
|
||||
import { setDialogMessage, setShowDialog } from "../../../redux/slices/uiSlice";
|
||||
import { updateSelectedModelByRole } from "../../../redux/thunks";
|
||||
import OllamaModelDownload from "../components/OllamaModelDownload";
|
||||
import { OllamaStatus } from "../components/OllamaStatus";
|
||||
import { useSubmitOnboarding } from "../hooks";
|
||||
import OllamaModelDownload from "./OllamaModelDownload";
|
||||
import { OllamaStatus } from "./OllamaStatus";
|
||||
|
||||
const OLLAMA_CHECK_INTERVAL_MS = 3000;
|
||||
|
||||
|
|
@ -5,8 +5,8 @@ import { getLocalStorage, setLocalStorage } from "../../../util/localStorage";
|
|||
import Alert from "../../gui/Alert";
|
||||
import { ReusableCard } from "../../ReusableCard";
|
||||
import { TabTitle } from "../components/OnboardingCardTabs";
|
||||
import OnboardingLocalTab from "../components/OnboardingLocalTab";
|
||||
import { useOnboardingCard } from "../hooks";
|
||||
import OnboardingLocalTab from "../tabs/OnboardingLocalTab";
|
||||
import MainTab from "./tabs/main";
|
||||
|
||||
export interface OnboardingCardState {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
export { default as Local } from "../components/OnboardingLocalTab";
|
||||
export { default as Best } from "./OnboardingBestTab";
|
||||
export { default as Local } from "./OnboardingLocalTab";
|
||||
export { default as Quickstart } from "./OnboardingQuickstartTab";
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ import { BarsArrowDownIcon, TrashIcon } from "@heroicons/react/24/outline";
|
|||
import { ChatHistoryItem } from "core";
|
||||
import { renderChatMessage } from "core/util/messageContent";
|
||||
import { useAppSelector } from "../../redux/hooks";
|
||||
import { selectIsInEditMode } from "../../redux/slices/sessionSlice";
|
||||
import FeedbackButtons from "../FeedbackButtons";
|
||||
import { CopyIconButton } from "../gui/CopyIconButton";
|
||||
import HeaderButtonWithToolTip from "../gui/HeaderButtonWithToolTip";
|
||||
|
|
@ -23,9 +22,9 @@ export default function ResponseActions({
|
|||
isTruncated,
|
||||
onDelete,
|
||||
}: ResponseActionsProps) {
|
||||
const isInEditMode = useAppSelector(selectIsInEditMode);
|
||||
const mode = useAppSelector((store) => store.session.mode);
|
||||
|
||||
if (isInEditMode) {
|
||||
if (mode === "edit") {
|
||||
return <EditActions index={index} item={item} />;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,10 +11,7 @@ import { IdeMessengerContext } from "../../../context/IdeMessenger";
|
|||
import { useIdeMessengerRequest } from "../../../hooks";
|
||||
import { useWebviewListener } from "../../../hooks/useWebviewListener";
|
||||
import { useAppSelector } from "../../../redux/hooks";
|
||||
import {
|
||||
selectApplyStateByStreamId,
|
||||
selectIsInEditMode,
|
||||
} from "../../../redux/slices/sessionSlice";
|
||||
import { selectApplyStateByStreamId } from "../../../redux/slices/sessionSlice";
|
||||
import { getFontSize } from "../../../util";
|
||||
import { isTerminalCodeBlock } from "../utils";
|
||||
import { ApplyActions } from "./ApplyActions";
|
||||
|
|
@ -74,10 +71,7 @@ export function StepContainerPreToolbar({
|
|||
disableManualApply,
|
||||
}: StepContainerPreToolbarProps) {
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const isInEditMode = useAppSelector(selectIsInEditMode);
|
||||
const [isExpanded, setIsExpanded] = useState(
|
||||
expanded ?? (isInEditMode ? false : true),
|
||||
);
|
||||
const [isExpanded, setIsExpanded] = useState(expanded ?? true);
|
||||
|
||||
const [relativeFilepathUri, setRelativeFilepathUri] = useState<string | null>(
|
||||
null,
|
||||
|
|
|
|||
|
|
@ -1,15 +1,12 @@
|
|||
import { useEffect } from "react";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { useAppSelector } from "../../redux/hooks";
|
||||
import { selectUseHub } from "../../redux/selectors";
|
||||
import { setDialogMessage, setShowDialog } from "../../redux/slices/uiSlice";
|
||||
import { OnboardingCard } from "../OnboardingCard";
|
||||
import { PlatformOnboardingCard } from "../OnboardingCard/platform/PlatformOnboardingCard";
|
||||
|
||||
function FreeTrialOverDialog() {
|
||||
const dispatch = useDispatch();
|
||||
const history = useAppSelector((store) => store.session.history);
|
||||
const usePlatform = useAppSelector(selectUseHub);
|
||||
|
||||
useEffect(() => {
|
||||
if (history.length === 0) {
|
||||
|
|
@ -20,11 +17,7 @@ function FreeTrialOverDialog() {
|
|||
|
||||
return (
|
||||
<div className="flex-1">
|
||||
{usePlatform ? (
|
||||
<PlatformOnboardingCard isDialog />
|
||||
) : (
|
||||
<OnboardingCard isDialog />
|
||||
)}
|
||||
<PlatformOnboardingCard isDialog />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ import { Lump } from "./Lump";
|
|||
import { TipTapEditor } from "./TipTapEditor";
|
||||
|
||||
interface ContinueInputBoxProps {
|
||||
isEditMode?: boolean;
|
||||
isLastUserInput: boolean;
|
||||
isMainInput?: boolean;
|
||||
onEnter: (
|
||||
|
|
@ -82,36 +81,41 @@ function ContinueInputBox(props: ContinueInputBoxProps) {
|
|||
const availableContextProviders = useAppSelector(
|
||||
(state) => state.config.config.contextProviders,
|
||||
);
|
||||
const mode = useAppSelector((store) => store.session.mode);
|
||||
const editModeState = useAppSelector((state) => state.editModeState);
|
||||
|
||||
const filteredSlashCommands = props.isEditMode ? [] : availableSlashCommands;
|
||||
const filteredSlashCommands = useMemo(() => {
|
||||
return mode === "edit" ? [] : availableSlashCommands;
|
||||
}, [mode, availableSlashCommands]);
|
||||
|
||||
const filteredContextProviders = useMemo(() => {
|
||||
if (!props.isEditMode) {
|
||||
return availableContextProviders ?? [];
|
||||
if (mode === "edit") {
|
||||
return (
|
||||
availableContextProviders?.filter(
|
||||
(provider) =>
|
||||
!EDIT_DISALLOWED_CONTEXT_PROVIDERS.includes(provider.title),
|
||||
) ?? []
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
availableContextProviders?.filter(
|
||||
(provider) =>
|
||||
!EDIT_DISALLOWED_CONTEXT_PROVIDERS.includes(provider.title),
|
||||
) ?? []
|
||||
);
|
||||
}, [availableContextProviders]);
|
||||
return availableContextProviders ?? [];
|
||||
}, [availableContextProviders, mode]);
|
||||
|
||||
const historyKey = props.isEditMode ? "edit" : "chat";
|
||||
const placeholder = props.isEditMode
|
||||
? "Describe changes, '#' to add files"
|
||||
: undefined;
|
||||
const historyKey = mode === "edit" ? "edit" : "chat";
|
||||
const placeholder =
|
||||
mode === "edit" ? "Describe changes, '#' to add files" : undefined;
|
||||
|
||||
const toolbarOptions: ToolbarOptions = props.isEditMode
|
||||
? {
|
||||
hideAddContext: false,
|
||||
hideImageUpload: false,
|
||||
hideUseCodebase: true,
|
||||
hideSelectModel: false,
|
||||
enterText: editModeState.editStatus === "accepting" ? "Retry" : "Edit",
|
||||
}
|
||||
: {};
|
||||
const toolbarOptions: ToolbarOptions =
|
||||
mode === "edit"
|
||||
? {
|
||||
hideAddContext: false,
|
||||
hideImageUpload: false,
|
||||
hideUseCodebase: true,
|
||||
hideSelectModel: false,
|
||||
enterText:
|
||||
editModeState.editStatus === "accepting" ? "Retry" : "Edit",
|
||||
}
|
||||
: {};
|
||||
|
||||
return (
|
||||
<div
|
||||
|
|
|
|||
|
|
@ -9,10 +9,6 @@ import {
|
|||
selectCurrentToolCallApplyState,
|
||||
} from "../../redux/selectors/selectCurrentToolCall";
|
||||
import { selectSelectedChatModel } from "../../redux/slices/configSlice";
|
||||
import {
|
||||
selectHasCodeToEdit,
|
||||
selectIsInEditMode,
|
||||
} from "../../redux/slices/sessionSlice";
|
||||
import { exitEditMode } from "../../redux/thunks";
|
||||
import { loadLastSession } from "../../redux/thunks/session";
|
||||
import {
|
||||
|
|
@ -52,17 +48,16 @@ function InputToolbar(props: InputToolbarProps) {
|
|||
const fileInputRef = useRef<HTMLInputElement | null>(null);
|
||||
const defaultModel = useAppSelector(selectSelectedChatModel);
|
||||
const useActiveFile = useAppSelector(selectUseActiveFile);
|
||||
const isInEditMode = useAppSelector(selectIsInEditMode);
|
||||
const hasCodeToEdit = useAppSelector(selectHasCodeToEdit);
|
||||
const mode = useAppSelector((store) => store.session.mode);
|
||||
const codeToEdit = useAppSelector((store) => store.editModeState.codeToEdit);
|
||||
const toolCallState = useAppSelector(selectCurrentToolCall);
|
||||
const isEditModeAndNoCodeToEdit = isInEditMode && !hasCodeToEdit;
|
||||
const currentToolCallApplyState = useAppSelector(
|
||||
selectCurrentToolCallApplyState,
|
||||
);
|
||||
|
||||
const isEnterDisabled =
|
||||
props.disabled ||
|
||||
isEditModeAndNoCodeToEdit ||
|
||||
(mode === "edit" && codeToEdit.length === 0) ||
|
||||
toolCallState?.status === "generated" ||
|
||||
(currentToolCallApplyState &&
|
||||
currentToolCallApplyState.status !== "closed");
|
||||
|
|
@ -158,7 +153,7 @@ function InputToolbar(props: InputToolbarProps) {
|
|||
fontSize: tinyFont,
|
||||
}}
|
||||
>
|
||||
{!props.toolbarOptions?.hideUseCodebase && !isInEditMode && (
|
||||
{!props.toolbarOptions?.hideUseCodebase && mode !== "edit" && (
|
||||
<div
|
||||
className={`${toolsSupported ? "md:flex" : "int:flex"} hover:underline" hidden transition-colors duration-200`}
|
||||
>
|
||||
|
|
@ -188,7 +183,7 @@ function InputToolbar(props: InputToolbarProps) {
|
|||
</div>
|
||||
)}
|
||||
|
||||
{isInEditMode && (
|
||||
{mode === "edit" && (
|
||||
<HoverItem
|
||||
className="hidden hover:underline sm:flex"
|
||||
onClick={async (e) => {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import useIsOSREnabled from "../../../hooks/useIsOSREnabled";
|
|||
import useUpdatingRef from "../../../hooks/useUpdatingRef";
|
||||
import { useAppDispatch, useAppSelector } from "../../../redux/hooks";
|
||||
import { selectSelectedChatModel } from "../../../redux/slices/configSlice";
|
||||
import { selectIsInEditMode } from "../../../redux/slices/sessionSlice";
|
||||
import InputToolbar, { ToolbarOptions } from "../InputToolbar";
|
||||
import { ComboBoxItem } from "../types";
|
||||
import { DragOverlay, InputBoxDiv } from "./components";
|
||||
|
|
@ -48,9 +47,9 @@ export function TipTapEditor(props: TipTapEditorProps) {
|
|||
|
||||
const defaultModel = useAppSelector(selectSelectedChatModel);
|
||||
const isStreaming = useAppSelector((state) => state.session.isStreaming);
|
||||
const isInEditMode = useAppSelector(selectIsInEditMode);
|
||||
const historyLength = useAppSelector((store) => store.session.history.length);
|
||||
|
||||
const mode = useAppSelector((store) => store.session.mode);
|
||||
const { editor, onEnterRef } = createEditorConfig({
|
||||
props,
|
||||
ideMessenger,
|
||||
|
|
@ -82,13 +81,13 @@ export function TipTapEditor(props: TipTapEditorProps) {
|
|||
}, [editor, props.placeholder, historyLength]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isInEditMode) {
|
||||
if (mode === "edit") {
|
||||
setShouldHideToolbar(false);
|
||||
}
|
||||
if (props.isMainInput) {
|
||||
editor?.commands.clearContent(true);
|
||||
}
|
||||
}, [editor, isInEditMode, props.isMainInput]);
|
||||
}, [editor, mode, props.isMainInput]);
|
||||
|
||||
const editorFocusedRef = useUpdatingRef(editor?.isFocused, [editor]);
|
||||
|
||||
|
|
@ -148,7 +147,7 @@ export function TipTapEditor(props: TipTapEditorProps) {
|
|||
|
||||
const handleBlur = useCallback(
|
||||
(e: React.FocusEvent) => {
|
||||
if (isInEditMode) {
|
||||
if (mode === "edit") {
|
||||
return;
|
||||
}
|
||||
// Check if the new focus target is within our InputBoxDiv
|
||||
|
|
@ -163,7 +162,7 @@ export function TipTapEditor(props: TipTapEditorProps) {
|
|||
setShouldHideToolbar(true);
|
||||
}, 100);
|
||||
},
|
||||
[isInEditMode, blurTimeout],
|
||||
[mode, blurTimeout],
|
||||
);
|
||||
|
||||
const handleFocus = useCallback(() => {
|
||||
|
|
|
|||
|
|
@ -3,10 +3,8 @@ import { InputModifiers } from "core";
|
|||
import { rifWithContentsToContextItem } from "core/commands/util";
|
||||
import { MutableRefObject } from "react";
|
||||
import { useWebviewListener } from "../../../hooks/useWebviewListener";
|
||||
import {
|
||||
clearCodeToEdit,
|
||||
setNewestToolbarPreviewForInput,
|
||||
} from "../../../redux/slices/sessionSlice";
|
||||
import { clearCodeToEdit } from "../../../redux/slices/editModeState";
|
||||
import { setNewestToolbarPreviewForInput } from "../../../redux/slices/sessionSlice";
|
||||
import { AppDispatch } from "../../../redux/store";
|
||||
import { loadSession, saveCurrentSession } from "../../../redux/thunks/session";
|
||||
import { CodeBlock, PromptBlock } from "./extensions";
|
||||
|
|
|
|||
|
|
@ -22,11 +22,7 @@ import useUpdatingRef from "../../../../hooks/useUpdatingRef";
|
|||
import { useAppSelector } from "../../../../redux/hooks";
|
||||
import { selectUseActiveFile } from "../../../../redux/selectors";
|
||||
import { selectSelectedChatModel } from "../../../../redux/slices/configSlice";
|
||||
import {
|
||||
addCodeToEdit,
|
||||
selectHasCodeToEdit,
|
||||
selectIsInEditMode,
|
||||
} from "../../../../redux/slices/sessionSlice";
|
||||
import { addCodeToEdit } from "../../../../redux/slices/editModeState";
|
||||
import { AppDispatch } from "../../../../redux/store";
|
||||
import { exitEditMode } from "../../../../redux/thunks";
|
||||
import { loadLastSession } from "../../../../redux/thunks/session";
|
||||
|
|
@ -87,15 +83,14 @@ export function createEditorConfig(options: {
|
|||
const isStreaming = useAppSelector((state) => state.session.isStreaming);
|
||||
const useActiveFile = useAppSelector(selectUseActiveFile);
|
||||
const historyLength = useAppSelector((store) => store.session.history.length);
|
||||
const isInEditMode = useAppSelector(selectIsInEditMode);
|
||||
const hasCodeToEdit = useAppSelector(selectHasCodeToEdit);
|
||||
const isEditModeAndNoCodeToEdit = isInEditMode && !hasCodeToEdit;
|
||||
const mode = useAppSelector((store) => store.session.mode);
|
||||
const modeRef = useUpdatingRef(mode);
|
||||
const codeToEdit = useAppSelector((store) => store.editModeState.codeToEdit);
|
||||
|
||||
const inSubmenuRef = useRef<string | undefined>(undefined);
|
||||
const inDropdownRef = useRef(false);
|
||||
const defaultModelRef = useUpdatingRef(defaultModel);
|
||||
const isStreamingRef = useUpdatingRef(isStreaming);
|
||||
const isInEditModeRef = useUpdatingRef(isInEditMode);
|
||||
const getSubmenuContextItemsRef = useUpdatingRef(getSubmenuContextItems);
|
||||
const availableContextProvidersRef = useUpdatingRef(
|
||||
props.availableContextProviders,
|
||||
|
|
@ -273,7 +268,7 @@ export function createEditorConfig(options: {
|
|||
return true;
|
||||
}
|
||||
|
||||
if (inDropdownRef.current || !isInEditModeRef.current) {
|
||||
if (inDropdownRef.current || modeRef.current !== "edit") {
|
||||
ideMessenger.post("focusEditor", undefined);
|
||||
return true;
|
||||
}
|
||||
|
|
@ -336,7 +331,7 @@ export function createEditorConfig(options: {
|
|||
inSubmenuRef,
|
||||
ideMessenger,
|
||||
),
|
||||
allow: () => isInEditModeRef.current,
|
||||
allow: () => modeRef.current !== "edit",
|
||||
command: async ({ editor, range, props }) => {
|
||||
editor.chain().focus().insertContentAt(range, "").run();
|
||||
const filepath = props.id;
|
||||
|
|
@ -389,7 +384,7 @@ export function createEditorConfig(options: {
|
|||
if (!editor) {
|
||||
return;
|
||||
}
|
||||
if (isStreaming || isEditModeAndNoCodeToEdit) {
|
||||
if (isStreaming || (codeToEdit.length === 0 && mode === "edit")) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -406,7 +401,7 @@ export function createEditorConfig(options: {
|
|||
|
||||
props.onEnter(json, modifiers, editor);
|
||||
},
|
||||
[props.onEnter, editor, props.isMainInput],
|
||||
[props.onEnter, editor, props.isMainInput, codeToEdit, mode],
|
||||
);
|
||||
|
||||
return { editor, onEnterRef };
|
||||
|
|
|
|||
|
|
@ -14,11 +14,7 @@ import { lightGray } from "..";
|
|||
import { useWebviewListener } from "../../hooks/useWebviewListener";
|
||||
import { useAppDispatch, useAppSelector } from "../../redux/hooks";
|
||||
import { selectSelectedChatModel } from "../../redux/slices/configSlice";
|
||||
import {
|
||||
cycleMode,
|
||||
selectCurrentMode,
|
||||
setMode,
|
||||
} from "../../redux/slices/sessionSlice";
|
||||
import { cycleMode, setMode } from "../../redux/slices/sessionSlice";
|
||||
import { exitEditMode } from "../../redux/thunks";
|
||||
import {
|
||||
loadLastSession,
|
||||
|
|
@ -40,7 +36,7 @@ const ShortcutText = styled.span`
|
|||
|
||||
function ModeSelect() {
|
||||
const dispatch = useAppDispatch();
|
||||
const mode = useAppSelector(selectCurrentMode);
|
||||
const mode = useAppSelector((store) => store.session.mode);
|
||||
const selectedModel = useAppSelector(selectSelectedChatModel);
|
||||
const currentSession = useAppSelector((state) => state.session);
|
||||
const [newSessionInitialized, setNewSessionInitialized] = useState(false);
|
||||
|
|
|
|||
|
|
@ -12,9 +12,6 @@ import { useAuth } from "../../context/Auth";
|
|||
import { IdeMessengerContext } from "../../context/IdeMessenger";
|
||||
import AddModelForm from "../../forms/AddModelForm";
|
||||
import { useAppDispatch, useAppSelector } from "../../redux/hooks";
|
||||
import {
|
||||
selectIsInEditMode,
|
||||
} from "../../redux/slices/sessionSlice";
|
||||
import { setDialogMessage, setShowDialog } from "../../redux/slices/uiSlice";
|
||||
import { updateSelectedModelByRole } from "../../redux/thunks";
|
||||
import { getMetaKeyLabel, isMetaEquivalentKeyPressed } from "../../util";
|
||||
|
|
@ -123,12 +120,12 @@ function ModelOption({
|
|||
function ModelSelect() {
|
||||
const dispatch = useAppDispatch();
|
||||
|
||||
const isInEditMode = useAppSelector(selectIsInEditMode);
|
||||
const mode = useAppSelector((store) => store.session.mode);
|
||||
const config = useAppSelector((state) => state.config.config);
|
||||
|
||||
let selectedModel = null;
|
||||
let allModels = null;
|
||||
if (isInEditMode) {
|
||||
if (mode === "edit") {
|
||||
allModels = config.modelsByRole.edit;
|
||||
selectedModel = config.selectedModelByRole.edit;
|
||||
}
|
||||
|
|
@ -158,14 +155,14 @@ function ModelSelect() {
|
|||
useEffect(() => {
|
||||
setOptions(
|
||||
allModels.map((model) => {
|
||||
return {
|
||||
value: model.title,
|
||||
title: modelSelectTitle(model),
|
||||
apiKey: model.apiKey,
|
||||
};
|
||||
}),
|
||||
return {
|
||||
value: model.title,
|
||||
title: modelSelectTitle(model),
|
||||
apiKey: model.apiKey,
|
||||
};
|
||||
}),
|
||||
);
|
||||
}, [isInEditMode, config]);
|
||||
}, [config]);
|
||||
|
||||
useEffect(() => {
|
||||
const handleKeyDown = (event: KeyboardEvent) => {
|
||||
|
|
@ -225,7 +222,7 @@ function ModelSelect() {
|
|||
dispatch(
|
||||
updateSelectedModelByRole({
|
||||
selectedProfile,
|
||||
role: isInEditMode ? "edit" : "chat",
|
||||
role: mode === "edit" ? "edit" : "chat",
|
||||
modelTitle: val,
|
||||
}),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ import { TabBar } from "../../components/TabBar/TabBar";
|
|||
import { IdeMessengerContext } from "../../context/IdeMessenger";
|
||||
import { useWebviewListener } from "../../hooks/useWebviewListener";
|
||||
import { useAppDispatch, useAppSelector } from "../../redux/hooks";
|
||||
import { selectUseHub } from "../../redux/selectors";
|
||||
import {
|
||||
selectCurrentToolCall,
|
||||
selectCurrentToolCallApplyState,
|
||||
|
|
@ -38,8 +37,6 @@ import { selectSelectedChatModel } from "../../redux/slices/configSlice";
|
|||
import { submitEdit } from "../../redux/slices/editModeState";
|
||||
import {
|
||||
newSession,
|
||||
selectIsInEditMode,
|
||||
selectIsSingleRangeEditOrInsertion,
|
||||
updateToolCallOutput,
|
||||
} from "../../redux/slices/sessionSlice";
|
||||
import {
|
||||
|
|
@ -56,7 +53,7 @@ import {
|
|||
FREE_TRIAL_LIMIT_REQUESTS,
|
||||
incrementFreeTrialCount,
|
||||
} from "../../util/freeTrial";
|
||||
import getMultifileEditPrompt from "../../util/getMultifileEditPrompt";
|
||||
|
||||
import { getLocalStorage, setLocalStorage } from "../../util/localStorage";
|
||||
import { EmptyChatBody } from "./EmptyChatBody";
|
||||
import { ExploreDialogWatcher } from "./ExploreDialogWatcher";
|
||||
|
|
@ -115,7 +112,7 @@ export function Chat() {
|
|||
const showChatScrollbar = useAppSelector(
|
||||
(state) => state.config.config.ui?.showChatScrollbar,
|
||||
);
|
||||
const codeToEdit = useAppSelector((state) => state.session.codeToEdit);
|
||||
const codeToEdit = useAppSelector((state) => state.editModeState.codeToEdit);
|
||||
const toolCallState = useAppSelector(selectCurrentToolCall);
|
||||
const applyStates = useAppSelector(
|
||||
(state) => state.session.codeBlockApplyStates.states,
|
||||
|
|
@ -124,12 +121,8 @@ export function Chat() {
|
|||
(state) => state.status === "done",
|
||||
);
|
||||
const hasPendingApplies = pendingApplyStates.length > 0;
|
||||
const isInEditMode = useAppSelector(selectIsInEditMode);
|
||||
const isSingleRangeEditOrInsertion = useAppSelector(
|
||||
selectIsSingleRangeEditOrInsertion,
|
||||
);
|
||||
const mode = useAppSelector((store) => store.session.mode);
|
||||
const lastSessionId = useAppSelector((state) => state.session.lastSessionId);
|
||||
const useHub = useAppSelector(selectUseHub);
|
||||
const hasDismissedExploreDialog = useAppSelector(
|
||||
(state) => state.ui.hasDismissedExploreDialog,
|
||||
);
|
||||
|
|
@ -206,18 +199,12 @@ export function Chat() {
|
|||
}
|
||||
}
|
||||
|
||||
if (isSingleRangeEditOrInsertion) {
|
||||
if (mode === "edit") {
|
||||
handleSingleRangeEditOrInsertion(editorState);
|
||||
return;
|
||||
}
|
||||
|
||||
const promptPreamble = isInEditMode
|
||||
? getMultifileEditPrompt(codeToEdit)
|
||||
: undefined;
|
||||
|
||||
dispatch(
|
||||
streamResponseThunk({ editorState, modifiers, promptPreamble, index }),
|
||||
);
|
||||
dispatch(streamResponseThunk({ editorState, modifiers, index }));
|
||||
|
||||
if (editorToClearOnSend) {
|
||||
editorToClearOnSend.commands.clearContent();
|
||||
|
|
@ -240,7 +227,7 @@ export function Chat() {
|
|||
history,
|
||||
selectedChatModel,
|
||||
streamResponse,
|
||||
isSingleRangeEditOrInsertion,
|
||||
mode,
|
||||
codeToEdit,
|
||||
toolCallState,
|
||||
],
|
||||
|
|
@ -314,8 +301,6 @@ export function Chat() {
|
|||
|
||||
useAutoScroll(stepsDivRef, history);
|
||||
|
||||
const showPageHeader = isInEditMode || useHub;
|
||||
|
||||
return (
|
||||
<>
|
||||
{widget}
|
||||
|
|
@ -324,7 +309,7 @@ export function Chat() {
|
|||
|
||||
<StepsDiv
|
||||
ref={stepsDivRef}
|
||||
className={`mt-3 overflow-y-scroll ${showPageHeader ? "" : "pt-[8px]"} ${showScrollbar ? "thin-scrollbar" : "no-scrollbar"} ${history.length > 0 ? "flex-1" : ""}`}
|
||||
className={`mt-3 overflow-y-scroll pt-[8px] ${showScrollbar ? "thin-scrollbar" : "no-scrollbar"} ${history.length > 0 ? "flex-1" : ""}`}
|
||||
>
|
||||
{highlights}
|
||||
{history.map((item, index: number) => (
|
||||
|
|
@ -342,14 +327,13 @@ export function Chat() {
|
|||
>
|
||||
{item.message.role === "user" ? (
|
||||
<>
|
||||
{isInEditMode && index === 0 && <CodeToEditCard />}
|
||||
{mode === "edit" && <CodeToEditCard />}
|
||||
<ContinueInputBox
|
||||
isEditMode={isInEditMode}
|
||||
onEnter={(editorState, modifiers) =>
|
||||
sendInput(editorState, modifiers, index)
|
||||
}
|
||||
isLastUserInput={isLastUserInput(index)}
|
||||
isMainInput={false}
|
||||
isMainInput={mode === "edit"}
|
||||
editorState={item.editorState}
|
||||
contextItems={item.contextItems}
|
||||
inputId={item.message.id}
|
||||
|
|
@ -421,18 +405,18 @@ export function Chat() {
|
|||
))}
|
||||
</StepsDiv>
|
||||
<div className={"relative"}>
|
||||
{isInEditMode && history.length === 0 && <CodeToEditCard />}
|
||||
|
||||
{isInEditMode && history.length > 0 ? null : (
|
||||
<ContinueInputBox
|
||||
isMainInput
|
||||
isEditMode={isInEditMode}
|
||||
isLastUserInput={false}
|
||||
onEnter={(editorState, modifiers, editor) =>
|
||||
sendInput(editorState, modifiers, undefined, editor)
|
||||
}
|
||||
inputId={MAIN_EDITOR_INPUT_ID}
|
||||
/>
|
||||
{mode === "edit" && history.length > 0 ? null : (
|
||||
<>
|
||||
{mode === "edit" && <CodeToEditCard />}
|
||||
<ContinueInputBox
|
||||
isMainInput
|
||||
isLastUserInput={false}
|
||||
onEnter={(editorState, modifiers, editor) =>
|
||||
sendInput(editorState, modifiers, undefined, editor)
|
||||
}
|
||||
inputId={MAIN_EDITOR_INPUT_ID}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
|
||||
<div
|
||||
|
|
@ -442,7 +426,7 @@ export function Chat() {
|
|||
>
|
||||
<div className="flex flex-row items-center justify-between pb-1 pl-0.5 pr-2">
|
||||
<div className="xs:inline hidden">
|
||||
{history.length === 0 && lastSessionId && !isInEditMode && (
|
||||
{history.length === 0 && lastSessionId && mode !== "edit" && (
|
||||
<div className="xs:inline hidden">
|
||||
<NewSessionButton
|
||||
onClick={async () => {
|
||||
|
|
@ -462,7 +446,7 @@ export function Chat() {
|
|||
</div>
|
||||
</div>
|
||||
|
||||
{hasPendingApplies && isSingleRangeEditOrInsertion && (
|
||||
{hasPendingApplies && (
|
||||
<AcceptRejectAllButtons
|
||||
pendingApplyStates={pendingApplyStates}
|
||||
onAcceptOrReject={async (outcome) => {
|
||||
|
|
@ -481,10 +465,7 @@ export function Chat() {
|
|||
{!hasDismissedExploreDialog && <ExploreDialogWatcher />}
|
||||
|
||||
{history.length === 0 && (
|
||||
<EmptyChatBody
|
||||
useHub={useHub}
|
||||
showOnboardingCard={onboardingCard.show}
|
||||
/>
|
||||
<EmptyChatBody showOnboardingCard={onboardingCard.show} />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -4,18 +4,15 @@ import { OnboardingCard } from "../../components/OnboardingCard";
|
|||
import { PlatformOnboardingCard } from "../../components/OnboardingCard/platform/PlatformOnboardingCard";
|
||||
|
||||
export interface EmptyChatBodyProps {
|
||||
useHub: boolean;
|
||||
showOnboardingCard?: boolean;
|
||||
}
|
||||
|
||||
export function EmptyChatBody({
|
||||
useHub,
|
||||
showOnboardingCard,
|
||||
}: EmptyChatBodyProps) {
|
||||
export function EmptyChatBody({ showOnboardingCard }: EmptyChatBodyProps) {
|
||||
if (showOnboardingCard) {
|
||||
return (
|
||||
<div className="mx-2 mt-6">
|
||||
{useHub ? (
|
||||
{true ? (
|
||||
// For now we are excluding local onboarding options other than ollama
|
||||
<PlatformOnboardingCard isDialog={false} />
|
||||
) : (
|
||||
<OnboardingCard isDialog={false} />
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ import { useAuth } from "../../context/Auth";
|
|||
import { IdeMessengerContext } from "../../context/IdeMessenger";
|
||||
import { selectSelectedProfile } from "../../redux/";
|
||||
import { useAppDispatch, useAppSelector } from "../../redux/hooks";
|
||||
import { selectUseHub } from "../../redux/selectors";
|
||||
import { selectSelectedChatModel } from "../../redux/slices/configSlice";
|
||||
import { setDialogMessage, setShowDialog } from "../../redux/slices/uiSlice";
|
||||
import { isLocalProfile } from "../../util";
|
||||
|
|
@ -36,7 +35,6 @@ const StreamErrorDialog = ({ error }: StreamErrorProps) => {
|
|||
const dispatch = useAppDispatch();
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const selectedModel = useAppSelector(selectSelectedChatModel);
|
||||
const hubEnabled = useAppSelector(selectUseHub);
|
||||
const selectedProfile = useAppSelector(selectSelectedProfile);
|
||||
const { session, refreshProfiles } = useAuth();
|
||||
|
||||
|
|
@ -180,17 +178,14 @@ const StreamErrorDialog = ({ error }: StreamErrorProps) => {
|
|||
if (statusCode === 401) {
|
||||
errorContent = (
|
||||
<div className="flex flex-col gap-2">
|
||||
{hubEnabled &&
|
||||
session &&
|
||||
selectedProfile &&
|
||||
!isLocalProfile(selectedProfile) && (
|
||||
<div className="flex flex-col gap-1">
|
||||
<span>{`If your hub secret values may have changed, refresh your assistants`}</span>
|
||||
<SecondaryButton onClick={handleRefreshProfiles}>
|
||||
Refresh assistant secrets
|
||||
</SecondaryButton>
|
||||
</div>
|
||||
)}
|
||||
{session && selectedProfile && !isLocalProfile(selectedProfile) && (
|
||||
<div className="flex flex-col gap-1">
|
||||
<span>{`If your hub secret values may have changed, refresh your assistants`}</span>
|
||||
<SecondaryButton onClick={handleRefreshProfiles}>
|
||||
Refresh assistant secrets
|
||||
</SecondaryButton>
|
||||
</div>
|
||||
)}
|
||||
<span>{`It's possible that your API key is invalid.`}</span>
|
||||
<div className="flex flex-row flex-wrap gap-2">
|
||||
{checkKeysButton}
|
||||
|
|
|
|||
|
|
@ -46,6 +46,3 @@ export const selectUseActiveFile = createSelector(
|
|||
[(state: RootState) => state.config.config.experimental?.defaultContext],
|
||||
(defaultContext) => defaultContext?.includes("activeFile" as any),
|
||||
);
|
||||
|
||||
export const selectUseHub = (state: RootState) =>
|
||||
state.config.config.usePlatform;
|
||||
|
|
|
|||
|
|
@ -1,15 +1,19 @@
|
|||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
import { EditStatus, MessageContent } from "core";
|
||||
import { CodeToEdit, EditStatus, MessageContent } from "core";
|
||||
|
||||
export interface EditModeState {
|
||||
codeToEdit: CodeToEdit[];
|
||||
editStatus: EditStatus;
|
||||
previousInputs: MessageContent[];
|
||||
fileAfterEdit?: string;
|
||||
enteredEditModeFromEditor: boolean;
|
||||
}
|
||||
|
||||
const initialState: EditModeState = {
|
||||
editStatus: "not-started",
|
||||
previousInputs: [],
|
||||
codeToEdit: [],
|
||||
enteredEditModeFromEditor: false,
|
||||
};
|
||||
|
||||
export const editModeStateSlice = createSlice({
|
||||
|
|
@ -69,6 +73,36 @@ export const editModeStateSlice = createSlice({
|
|||
state.editStatus = "done";
|
||||
state.previousInputs = [];
|
||||
},
|
||||
addCodeToEdit: (
|
||||
state,
|
||||
{ payload }: PayloadAction<CodeToEdit | CodeToEdit[]>,
|
||||
) => {
|
||||
const entries = Array.isArray(payload) ? payload : [payload];
|
||||
|
||||
const newEntries = entries.filter(
|
||||
(entry) =>
|
||||
!state.codeToEdit.some((existingEntry) =>
|
||||
isCodeToEditEqual(existingEntry, entry),
|
||||
),
|
||||
);
|
||||
|
||||
if (newEntries.length > 0) {
|
||||
state.codeToEdit.push(...newEntries);
|
||||
}
|
||||
},
|
||||
removeCodeToEdit: (state, { payload }: PayloadAction<CodeToEdit>) => {
|
||||
state.codeToEdit = state.codeToEdit.filter(
|
||||
(entry) => !isCodeToEditEqual(entry, payload),
|
||||
);
|
||||
},
|
||||
clearCodeToEdit: (state) => {
|
||||
state.codeToEdit = [];
|
||||
},
|
||||
},
|
||||
selectors: {
|
||||
selectHasCodeToEdit: (state) => {
|
||||
return state.codeToEdit.length > 0;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
|
|
@ -78,5 +112,41 @@ export const {
|
|||
setEditDone,
|
||||
submitEdit,
|
||||
focusEdit,
|
||||
clearCodeToEdit,
|
||||
addCodeToEdit,
|
||||
removeCodeToEdit,
|
||||
} = editModeStateSlice.actions;
|
||||
export default editModeStateSlice.reducer;
|
||||
|
||||
function isCodeToEditEqual(a: CodeToEdit, b: CodeToEdit) {
|
||||
if (a.filepath !== b.filepath || a.contents !== b.contents) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ("range" in a && "range" in b) {
|
||||
const rangeA = a.range;
|
||||
const rangeB = b.range;
|
||||
|
||||
return (
|
||||
rangeA.start.line === rangeB.start.line &&
|
||||
rangeA.end.line === rangeB.end.line
|
||||
);
|
||||
}
|
||||
|
||||
// If neither has a range, they are considered equal in this context
|
||||
return !("range" in a) && !("range" in b);
|
||||
}
|
||||
|
||||
export const { selectHasCodeToEdit } = editModeStateSlice.selectors;
|
||||
|
||||
// selectIsSingleRangeEditOrInsertion: (state) => {
|
||||
// if (state.mode !== "edit") {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// const isInsertion = state.codeToEdit.length === 0;
|
||||
// const selectIsSingleRangeEdit =
|
||||
// state.codeToEdit.length === 1 && "range" in state.codeToEdit[0];
|
||||
|
||||
// return selectIsSingleRangeEdit || isInsertion;
|
||||
// },
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import {
|
|||
ApplyState,
|
||||
ChatHistoryItem,
|
||||
ChatMessage,
|
||||
CodeToEdit,
|
||||
ContextItem,
|
||||
ContextItemWithId,
|
||||
FileSymbolMap,
|
||||
|
|
@ -44,7 +43,6 @@ type SessionState = {
|
|||
title: string;
|
||||
id: string;
|
||||
streamAborter: AbortController;
|
||||
codeToEdit: CodeToEdit[];
|
||||
curCheckpointIndex: number;
|
||||
mainEditorContentTrigger?: JSONContent | undefined;
|
||||
symbols: FileSymbolMap;
|
||||
|
|
@ -56,25 +54,6 @@ type SessionState = {
|
|||
newestToolbarPreviewForInput: Record<string, string>;
|
||||
};
|
||||
|
||||
function isCodeToEditEqual(a: CodeToEdit, b: CodeToEdit) {
|
||||
if (a.filepath !== b.filepath || a.contents !== b.contents) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ("range" in a && "range" in b) {
|
||||
const rangeA = a.range;
|
||||
const rangeB = b.range;
|
||||
|
||||
return (
|
||||
rangeA.start.line === rangeB.start.line &&
|
||||
rangeA.end.line === rangeB.end.line
|
||||
);
|
||||
}
|
||||
|
||||
// If neither has a range, they are considered equal in this context
|
||||
return !("range" in a) && !("range" in b);
|
||||
}
|
||||
|
||||
const initialState: SessionState = {
|
||||
allSessionMetadata: [],
|
||||
history: [],
|
||||
|
|
@ -83,7 +62,6 @@ const initialState: SessionState = {
|
|||
id: uuidv4(),
|
||||
curCheckpointIndex: 0,
|
||||
streamAborter: new AbortController(),
|
||||
codeToEdit: [],
|
||||
symbols: {},
|
||||
mode: "chat",
|
||||
codeBlockApplyStates: {
|
||||
|
|
@ -584,31 +562,7 @@ export const sessionSlice = createSlice({
|
|||
resetNextCodeBlockToApplyIndex: (state) => {
|
||||
state.codeBlockApplyStates.curIndex = 0;
|
||||
},
|
||||
addCodeToEdit: (
|
||||
state,
|
||||
{ payload }: PayloadAction<CodeToEdit | CodeToEdit[]>,
|
||||
) => {
|
||||
const entries = Array.isArray(payload) ? payload : [payload];
|
||||
|
||||
const newEntries = entries.filter(
|
||||
(entry) =>
|
||||
!state.codeToEdit.some((existingEntry) =>
|
||||
isCodeToEditEqual(existingEntry, entry),
|
||||
),
|
||||
);
|
||||
|
||||
if (newEntries.length > 0) {
|
||||
state.codeToEdit.push(...newEntries);
|
||||
}
|
||||
},
|
||||
removeCodeToEdit: (state, { payload }: PayloadAction<CodeToEdit>) => {
|
||||
state.codeToEdit = state.codeToEdit.filter(
|
||||
(entry) => !isCodeToEditEqual(entry, payload),
|
||||
);
|
||||
},
|
||||
clearCodeToEdit: (state) => {
|
||||
state.codeToEdit = [];
|
||||
},
|
||||
// TOOL CALL STATE
|
||||
setToolGenerated: (
|
||||
state,
|
||||
|
|
@ -724,26 +678,6 @@ export const sessionSlice = createSlice({
|
|||
const curHistoryItem = state.history.at(-1);
|
||||
return curHistoryItem?.isGatheringContext || false;
|
||||
},
|
||||
selectIsInEditMode: (state) => {
|
||||
return state.mode === "edit";
|
||||
},
|
||||
selectCurrentMode: (state) => {
|
||||
return state.mode;
|
||||
},
|
||||
selectIsSingleRangeEditOrInsertion: (state) => {
|
||||
if (state.mode !== "edit") {
|
||||
return false;
|
||||
}
|
||||
|
||||
const isInsertion = state.codeToEdit.length === 0;
|
||||
const selectIsSingleRangeEdit =
|
||||
state.codeToEdit.length === 1 && "range" in state.codeToEdit[0];
|
||||
|
||||
return selectIsSingleRangeEdit || isInsertion;
|
||||
},
|
||||
selectHasCodeToEdit: (state) => {
|
||||
return state.codeToEdit.length > 0;
|
||||
},
|
||||
},
|
||||
extraReducers: (builder) => {
|
||||
addPassthroughCases(builder, [streamResponseThunk]);
|
||||
|
|
@ -811,9 +745,6 @@ export const {
|
|||
resetNextCodeBlockToApplyIndex,
|
||||
updateApplyState,
|
||||
abortStream,
|
||||
clearCodeToEdit,
|
||||
addCodeToEdit,
|
||||
removeCodeToEdit,
|
||||
setToolCallCalling,
|
||||
cancelToolCall,
|
||||
errorToolCall,
|
||||
|
|
@ -829,12 +760,6 @@ export const {
|
|||
cycleMode,
|
||||
} = sessionSlice.actions;
|
||||
|
||||
export const {
|
||||
selectIsGatheringContext,
|
||||
selectIsInEditMode,
|
||||
selectCurrentMode,
|
||||
selectIsSingleRangeEditOrInsertion,
|
||||
selectHasCodeToEdit,
|
||||
} = sessionSlice.selectors;
|
||||
export const { selectIsGatheringContext } = sessionSlice.selectors;
|
||||
|
||||
export default sessionSlice.reducer;
|
||||
|
|
|
|||
|
|
@ -47,7 +47,6 @@ const saveSubsetFilters = [
|
|||
|
||||
// Persist edit mode in case closes in middle
|
||||
"mode",
|
||||
"codeToEdit",
|
||||
|
||||
// higher risk to persist
|
||||
// codeBlockApplyStates
|
||||
|
|
@ -55,7 +54,7 @@ const saveSubsetFilters = [
|
|||
// curCheckpointIndex
|
||||
]),
|
||||
// Don't persist any of the edit state for now
|
||||
createFilter("editModeState", []),
|
||||
createFilter("editModeState", ["codeToEdit"]),
|
||||
createFilter("config", ["defaultModelTitle"]),
|
||||
createFilter("ui", ["toolSettings", "toolGroupSettings"]),
|
||||
createFilter("indexing", []),
|
||||
|
|
|
|||
|
|
@ -1,24 +1,17 @@
|
|||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import {
|
||||
clearCodeToEdit,
|
||||
selectIsInEditMode,
|
||||
selectIsSingleRangeEditOrInsertion,
|
||||
setMainEditorContentTrigger,
|
||||
setMode,
|
||||
} from "../slices/sessionSlice";
|
||||
import { clearCodeToEdit, setEditDone } from "../slices/editModeState";
|
||||
import { setMainEditorContentTrigger, setMode } from "../slices/sessionSlice";
|
||||
import { ThunkApiType } from "../store";
|
||||
import { setEditDone } from "../slices/editModeState";
|
||||
|
||||
export const exitEditMode = createAsyncThunk<void, undefined, ThunkApiType>(
|
||||
"edit/complete",
|
||||
async (_, { dispatch, extra, getState }) => {
|
||||
const state = getState();
|
||||
const isInEditMode = selectIsInEditMode(state);
|
||||
const codeToEdit = state.session.codeToEdit;
|
||||
const isSingleRangeEditOrInsertion =
|
||||
selectIsSingleRangeEditOrInsertion(state);
|
||||
const codeToEdit = state.editModeState.codeToEdit;
|
||||
const enteredEditModeFromEditor =
|
||||
state.editModeState.enteredEditModeFromEditor;
|
||||
|
||||
if (!isInEditMode) {
|
||||
if (state.session.mode !== "edit") {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -35,7 +28,7 @@ export const exitEditMode = createAsyncThunk<void, undefined, ThunkApiType>(
|
|||
dispatch(setMainEditorContentTrigger(undefined));
|
||||
|
||||
extra.ideMessenger.post("edit/exit", {
|
||||
shouldFocusEditor: isSingleRangeEditOrInsertion,
|
||||
shouldFocusEditor: enteredEditModeFromEditor,
|
||||
});
|
||||
},
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,62 +0,0 @@
|
|||
import { CodeToEdit, IDE } from "core";
|
||||
import { findUriInDirs } from "core/util/uri";
|
||||
|
||||
export default function getMultifileEditPrompt(
|
||||
codeToEdit: CodeToEdit[],
|
||||
dirs?: string[],
|
||||
): string {
|
||||
const codeToEditStr = codeToEdit
|
||||
.map((code) => {
|
||||
const { relativePathOrBasename } = findUriInDirs(
|
||||
code.filepath,
|
||||
dirs ?? window.workspacePaths ?? [],
|
||||
);
|
||||
return `
|
||||
\`\`\` ${relativePathOrBasename}
|
||||
${code.contents}
|
||||
\`\`\`
|
||||
`;
|
||||
})
|
||||
.join("\n");
|
||||
|
||||
return `
|
||||
You are an AI assistant designed to help software engineers make multi-file edits in their codebase. Your task is to generate the necessary code changes for multiple files based on the engineer's request. Follow these guidelines:
|
||||
|
||||
1. Start with a brief introduction of the task you're about to perform. Do not start with any other preamble, such as "Certainly!"
|
||||
2. When providing instructions, if a user needs to interact with a CLI, walk them through each step
|
||||
2. Perform file edits in a logical, sequential ordering
|
||||
3. For each file edit, provide a brief explanation of the changes
|
||||
4. If the user submits a code block that contains a filename in the language specifier, always include the filename in any code block you generate based on that file. The filename should be on the same line as the language specifier in your code block.
|
||||
a. When creating new files, also inlcude the filname in the language specifier of the code block.
|
||||
6. After providing all file changes, include a brief, sequential overview of the most important 3-5 edits
|
||||
|
||||
Remember to be concise and focus on the code changes and their impact.
|
||||
|
||||
Here's an example of how your response should be structured:
|
||||
|
||||
<example>
|
||||
I'll make the following changes to implement feature X:
|
||||
|
||||
1. First, I'll modify file1.js to add a new function:
|
||||
\`\`\`javascript /path/to/file1.js
|
||||
// Entire content of file1.js or changes to be made
|
||||
\`\`\`
|
||||
|
||||
2. Next, let's create a new test file:
|
||||
\`\`\`javascript /path/to/file1.test.js
|
||||
# Entire content of file2.py or changes to be made
|
||||
\`\`\`
|
||||
|
||||
Summary:
|
||||
- [Sequential overview of the most important 3-5 edits]
|
||||
</example>
|
||||
|
||||
Here are the files to base your edits on:
|
||||
|
||||
<files>
|
||||
${codeToEditStr}
|
||||
</files>
|
||||
|
||||
Please provide the multi-file edit details based on the engineer's request below:
|
||||
`;
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue