diff --git a/core/index.d.ts b/core/index.d.ts index 81ddd2039..06fbd7275 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -195,10 +195,12 @@ export interface CustomContextProvider { description?: string; renderInlineAs?: string; type?: ContextProviderType; + getContextItems( query: string, extras: ContextProviderExtras, ): Promise; + loadSubmenuItems?: ( args: LoadSubmenuItemsArgs, ) => Promise; @@ -275,10 +277,12 @@ export interface Range { start: Position; end: Position; } + export interface Position { line: number; character: number; } + export interface FileEdit { filepath: string; range: Range; @@ -479,6 +483,7 @@ export interface LLMOptions { // IBM watsonx Options deploymentId?: string; } + type RequireAtLeastOne = Pick< T, Exclude @@ -535,6 +540,7 @@ export class Thread { } export type IdeType = "vscode" | "jetbrains"; + export interface IdeInfo { ideType: IdeType; name: string; @@ -570,42 +576,68 @@ export interface IdeSettings { export interface IDE { getIdeInfo(): Promise; + getIdeSettings(): Promise; + getDiff(includeUnstaged: boolean): Promise; + getClipboardContent(): Promise<{ text: string; copiedAt: string }>; + isTelemetryEnabled(): Promise; + getUniqueId(): Promise; + getTerminalContents(): Promise; + getDebugLocals(threadIndex: number): Promise; + getTopLevelCallStackSources( threadIndex: number, stackDepth: number, ): Promise; + getAvailableThreads(): Promise; + listFolders(): Promise; + getWorkspaceDirs(): Promise; + getWorkspaceConfigs(): Promise; + fileExists(filepath: string): Promise; + writeFile(path: string, contents: string): Promise; + showVirtualFile(title: string, contents: string): Promise; + getContinueDir(): Promise; + openFile(path: string): Promise; + openUrl(url: string): Promise; + runCommand(command: string): Promise; + saveFile(filepath: string): Promise; + readFile(filepath: string): Promise; + readRangeInFile(filepath: string, range: Range): Promise; + showLines( filepath: string, startLine: number, endLine: number, ): Promise; + showDiff( filepath: string, newContents: string, stepIndex: number, ): Promise; + getOpenFiles(): Promise; + getCurrentFile(): Promise< | undefined | { @@ -614,21 +646,33 @@ export interface IDE { contents: string; } >; + getPinnedFiles(): Promise; + getSearchResults(query: string): Promise; + subprocess(command: string, cwd?: string): Promise<[string, string]>; + getProblems(filepath?: string | undefined): Promise; + getBranch(dir: string): Promise; + getTags(artifactId: string): Promise; + getRepoName(dir: string): Promise; + showToast( type: ToastType, message: string, ...otherParams: any[] ): Promise; + getGitRootPath(dir: string): Promise; + listDir(dir: string): Promise<[string, FileType][]>; + getLastModified(files: string[]): Promise<{ [path: string]: number }>; + getGitHubAuthToken(args: GetGhTokenArgs): Promise; // LSP @@ -636,6 +680,7 @@ export interface IDE { // Callbacks onDidChangeActiveTextEditor(callback: (filepath: string) => void): void; + pathSep(): Promise; } @@ -1035,6 +1080,7 @@ export interface EmbeddingsProvider { id: string; providerName: EmbeddingsProviderName; maxChunkSize: number; + embed(chunks: string[]): Promise; } @@ -1053,6 +1099,7 @@ export interface RerankerDescription { export interface Reranker { name: string; + rerank(query: string, chunks: Chunk[]): Promise; } diff --git a/gui/src/components/CodeToEditCard/CodeToEditCard.tsx b/gui/src/components/CodeToEditCard/CodeToEditCard.tsx index 04c55e8cc..cac18f4e1 100644 --- a/gui/src/components/CodeToEditCard/CodeToEditCard.tsx +++ b/gui/src/components/CodeToEditCard/CodeToEditCard.tsx @@ -73,13 +73,15 @@ export default function CodeToEditCard() { ))} ) : ( -
setShowAddFileCombobox(true)} - > - - Add a file to get started -
+ !showAddFileCombobox && ( +
setShowAddFileCombobox(true)} + > + + Add a file to get started +
+ ) )} {showAddFileCombobox && ( diff --git a/gui/src/components/PageHeader.tsx b/gui/src/components/PageHeader.tsx new file mode 100644 index 000000000..a0de733d0 --- /dev/null +++ b/gui/src/components/PageHeader.tsx @@ -0,0 +1,20 @@ +import { ArrowLeftIcon } from "@heroicons/react/24/outline"; + +export interface PageHeaderProps { + onClick: () => void; + title: string; +} + +export default function PageHeader({ onClick, title }: PageHeaderProps) { + return ( +
+
+ + {title} +
+
+ ); +} diff --git a/gui/src/components/StepContainer/AcceptRejectAllButtons.tsx b/gui/src/components/StepContainer/AcceptRejectAllButtons.tsx index 7fbbf07c6..472a3d3f7 100644 --- a/gui/src/components/StepContainer/AcceptRejectAllButtons.tsx +++ b/gui/src/components/StepContainer/AcceptRejectAllButtons.tsx @@ -8,9 +8,11 @@ import { selectIsSingleRangeEditOrInsertion } from "../../redux/slices/sessionSl export interface AcceptRejectAllButtonsProps { pendingApplyStates: ApplyState[]; - onAcceptOrReject?: () => void; + onAcceptOrReject?: (outcome: AcceptOrRejectOutcome) => void; } +export type AcceptOrRejectOutcome = "acceptDiff" | "rejectDiff"; + export default function AcceptRejectAllButtons({ pendingApplyStates, onAcceptOrReject, @@ -18,7 +20,7 @@ export default function AcceptRejectAllButtons({ const ideMessenger = useContext(IdeMessengerContext); const isSingleRangeEdit = useAppSelector(selectIsSingleRangeEditOrInsertion); - async function handleAcceptOrReject(status: "acceptDiff" | "rejectDiff") { + async function handleAcceptOrReject(status: AcceptOrRejectOutcome) { for (const { filepath, streamId } of pendingApplyStates) { ideMessenger.post(status, { filepath, @@ -27,9 +29,10 @@ export default function AcceptRejectAllButtons({ } if (onAcceptOrReject) { - onAcceptOrReject(); + onAcceptOrReject(status); } } + return (
)} + {isInEditMode && ( + { + loadLastSession().catch((e) => + console.error(`Failed to load last session: ${e}`), + ); + + dispatch(exitEditMode()); + }} + > + + Esc to exit + + + )} + { if (props.onEnter) { diff --git a/gui/src/components/markdown/StepContainerPreToolbar/ApplyActions.tsx b/gui/src/components/markdown/StepContainerPreToolbar/ApplyActions.tsx index 42ee8e048..321fe2633 100644 --- a/gui/src/components/markdown/StepContainerPreToolbar/ApplyActions.tsx +++ b/gui/src/components/markdown/StepContainerPreToolbar/ApplyActions.tsx @@ -3,7 +3,7 @@ import { ApplyState } from "core"; import { useState } from "react"; import { lightGray, vscForeground } from "../.."; import { getMetaKeyLabel } from "../../../util"; -import Spinner from "./Spinner"; +import Spinner from "../../gui/Spinner"; import { ToolbarButtonWithTooltip } from "./ToolbarButtonWithTooltip"; interface ApplyActionsProps { diff --git a/gui/src/components/markdown/StepContainerPreToolbar/GeneratingCodeLoader.tsx b/gui/src/components/markdown/StepContainerPreToolbar/GeneratingCodeLoader.tsx index 2b256929f..c430c8d62 100644 --- a/gui/src/components/markdown/StepContainerPreToolbar/GeneratingCodeLoader.tsx +++ b/gui/src/components/markdown/StepContainerPreToolbar/GeneratingCodeLoader.tsx @@ -1,4 +1,4 @@ -import Spinner from "./Spinner"; +import Spinner from "../../gui/Spinner"; export interface GeneratingCodeLoaderProps { showLineCount: boolean; diff --git a/gui/src/pages/More/More.tsx b/gui/src/pages/More/More.tsx index 5f97f9b31..347220084 100644 --- a/gui/src/pages/More/More.tsx +++ b/gui/src/pages/More/More.tsx @@ -16,6 +16,7 @@ import useHistory from "../../hooks/useHistory"; import MoreHelpRow from "./MoreHelpRow"; import IndexingProgress from "./IndexingProgress"; import DocsIndexingStatuses from "../../components/indexing/DocsIndexingStatuses"; +import PageHeader from "../../components/PageHeader"; function MorePage() { useNavigationListener(); @@ -26,20 +27,7 @@ function MorePage() { return (
-
-
navigate("/")} - > - - Chat -
-
+ navigate("/")} title="Chat" />
diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx index 258a92013..325f60dff 100644 --- a/gui/src/pages/gui/Chat.tsx +++ b/gui/src/pages/gui/Chat.tsx @@ -70,6 +70,8 @@ import resolveEditorContent from "../../components/mainInput/resolveInput"; import AcceptRejectAllButtons from "../../components/StepContainer/AcceptRejectAllButtons"; import CodeToEditCard from "../../components/CodeToEditCard"; import { exitEditMode } from "../../redux/thunks/exitEditMode"; +import PageHeader from "../../components/PageHeader"; +import Spinner from "../../components/gui/Spinner"; const StopButton = styled.div` background-color: ${vscBackground}; @@ -135,7 +137,7 @@ export function Chat() { const { showTutorialCard, closeTutorialCard } = useTutorialCard(); const defaultModel = useAppSelector(selectDefaultModel); const ttsActive = useAppSelector((state) => state.ui.ttsActive); - const active = useAppSelector((state) => state.session.isStreaming); + const isStreaming = useAppSelector((state) => state.session.isStreaming); const [stepsOpen, setStepsOpen] = useState<(boolean | undefined)[]>([]); const mainTextInputRef = useRef(null); const stepsDivRef = useRef(null); @@ -181,13 +183,9 @@ export function Chat() { setIsAtBottom(true); }, [stepsDivRef, setIsAtBottom]); - const returnToLastSessionButtonText = isInEditMode - ? "Back to Chat" - : "Last Session"; - useEffect(() => { - if (active) snapToBottom(); - }, [active, snapToBottom]); + if (isStreaming) snapToBottom(); + }, [isStreaming, snapToBottom]); // useEffect(() => { // setTimeout(() => { @@ -211,7 +209,7 @@ export function Chat() { return () => { window.removeEventListener("keydown", listener); }; - }, [active]); + }, [isStreaming]); const handleScroll = () => { // Temporary fix to account for additional height when code blocks are added @@ -338,6 +336,21 @@ export function Chat() { return ( <> + {isInEditMode && ( + { + loadLastSession().catch((e) => + console.error(`Failed to load last session: ${e}`), + ); + + if (isInEditMode) { + dispatch(exitEditMode()); + } + }} + /> + )} + {widget} @@ -448,7 +461,7 @@ export function Chat() { ■ Stop TTS )} - {active && ( + {isStreaming && ( { dispatch(setInactive()); @@ -475,49 +488,40 @@ export function Chat() {
-
- {history.length === 0 && - getLastSessionId() && - !hasPendingApplies ? ( -
- { - loadLastSession().catch((e) => - console.error(`Failed to load last session: ${e}`), - ); - - if (isInEditMode) { - dispatch(exitEditMode()); - } - }} - className="flex items-center gap-2" - > - - {returnToLastSessionButtonText} - -
- ) : null} -
+ {history.length === 0 && getLastSessionId() && !isInEditMode && ( + + loadLastSession().catch((e) => + console.error(`Failed to load last session: ${e}`), + ) + } + className="xs:inline flex hidden items-center gap-2" + > + + Last Session + + )}
{hasPendingApplies && isSingleRangeEditOrInsertion && ( { - loadLastSession().catch((e) => - console.error(`Failed to load last session: ${e}`), - ); + onAcceptOrReject={(outcome) => { + if (outcome === "acceptDiff") { + loadLastSession().catch((e) => + console.error(`Failed to load last session: ${e}`), + ); - dispatch(exitEditMode()); + dispatch(exitEditMode()); + } }} /> )} - {history.length === 0 && ( <> {onboardingCard.show && ( diff --git a/gui/src/pages/gui/ToolCallDiv/ToolCallButtonsDiv.tsx b/gui/src/pages/gui/ToolCallDiv/ToolCallButtonsDiv.tsx index 291e15e74..9d4528f33 100644 --- a/gui/src/pages/gui/ToolCallDiv/ToolCallButtonsDiv.tsx +++ b/gui/src/pages/gui/ToolCallDiv/ToolCallButtonsDiv.tsx @@ -6,7 +6,7 @@ import { vscButtonBackground, vscButtonForeground, } from "../../../components"; -import Spinner from "../../../components/markdown/StepContainerPreToolbar/Spinner"; +import Spinner from "../../../components/gui/Spinner"; import { selectCurrentToolCall } from "../../../redux/selectors/selectCurrentToolCall"; import { callTool } from "../../../redux/thunks/callTool"; import { cancelTool } from "../../../redux/thunks/cancelTool"; diff --git a/gui/src/pages/gui/ToolCallDiv/index.tsx b/gui/src/pages/gui/ToolCallDiv/index.tsx index e1745c459..6ca16bf87 100644 --- a/gui/src/pages/gui/ToolCallDiv/index.tsx +++ b/gui/src/pages/gui/ToolCallDiv/index.tsx @@ -5,7 +5,7 @@ import { } from "@heroicons/react/24/outline"; import { ToolCall, ToolCallState, ToolStatus } from "core"; import { vscButtonBackground } from "../../../components"; -import Spinner from "../../../components/markdown/StepContainerPreToolbar/Spinner"; +import Spinner from "../../../components/gui/Spinner"; import FunctionSpecificToolCallDiv from "./FunctionSpecificToolCallDiv"; import { ThreadDiv } from "./ThreadDiv"; diff --git a/gui/src/pages/history/HistoryHeader.tsx b/gui/src/pages/history/HistoryHeader.tsx deleted file mode 100644 index 4dbdf90bb..000000000 --- a/gui/src/pages/history/HistoryHeader.tsx +++ /dev/null @@ -1,45 +0,0 @@ -import { ArrowLeftIcon } from "@heroicons/react/24/outline"; -import { useNavigate } from "react-router-dom"; -import { lightGray, vscBackground } from "../../components"; -import { useNavigationListener } from "../../hooks/useNavigationListener"; -import { getFontSize } from "../../util"; - -export const HistoryHeader = () => { - useNavigationListener(); - const navigate = useNavigate(); - - return ( -
-
-
navigate("/")} - > - - Chat -
-
- {/* {workspacePaths && workspacePaths.length > 0 && ( - setFilteringByWorkspace((prev) => !prev)} - title={`Show only sessions from ${lastPartOfPath( - workspacePaths[workspacePaths.length - 1] - )}/`} - /> - )} */} -
- ); -}; diff --git a/gui/src/pages/history/index.tsx b/gui/src/pages/history/index.tsx index 6d31c60bc..54b6cea0a 100644 --- a/gui/src/pages/history/index.tsx +++ b/gui/src/pages/history/index.tsx @@ -1,11 +1,14 @@ +import { useNavigate } from "react-router-dom"; import { History } from "../../components/History"; +import PageHeader from "../../components/PageHeader"; import { getFontSize } from "../../util"; -import { HistoryHeader } from "./HistoryHeader"; export default function HistoryPage() { + const navigate = useNavigate(); + return (
- + navigate("/")} title="Chat" />
); diff --git a/gui/src/redux/thunks/exitEditMode.ts b/gui/src/redux/thunks/exitEditMode.ts index 9faba123a..ad3503696 100644 --- a/gui/src/redux/thunks/exitEditMode.ts +++ b/gui/src/redux/thunks/exitEditMode.ts @@ -13,6 +13,7 @@ export const exitEditMode = createAsyncThunk( async (_, { dispatch, extra, getState }) => { const state = getState(); const isInEditMode = selectIsInEditMode(state); + const codeToEdit = state.session.codeToEdit; const isSingleRangeEditOrInsertion = selectIsSingleRangeEditOrInsertion(state); @@ -21,6 +22,13 @@ export const exitEditMode = createAsyncThunk( } dispatch(setMode("chat")); + + for (const code of codeToEdit) { + extra.ideMessenger.post("rejectDiff", { + filepath: code.filepath, + }); + } + dispatch(clearCodeToEdit()); dispatch(setEditDone());