diff --git a/extensions/vscode/src/quickEdit/QuickEditQuickPick.ts b/extensions/vscode/src/quickEdit/QuickEditQuickPick.ts index 59b7ad41f..877d94ad3 100644 --- a/extensions/vscode/src/quickEdit/QuickEditQuickPick.ts +++ b/extensions/vscode/src/quickEdit/QuickEditQuickPick.ts @@ -13,6 +13,7 @@ import { getModelQuickPickVal } from "./ModelSelectionQuickPick"; import { ConfigHandler } from "core/config/ConfigHandler"; // @ts-ignore import { getModelByRole } from "core/config/util"; +// @ts-ignore import MiniSearch from "minisearch"; /** diff --git a/gui/src/components/ButtonWithTooltip.tsx b/gui/src/components/ButtonWithTooltip.tsx index 005b82001..f692133a1 100644 --- a/gui/src/components/ButtonWithTooltip.tsx +++ b/gui/src/components/ButtonWithTooltip.tsx @@ -1,4 +1,4 @@ -import React, { useState } from "react"; +import React from "react"; import ReactDOM from "react-dom"; import { type PlacesType } from "react-tooltip"; import { HeaderButton } from "."; @@ -25,7 +25,6 @@ const ButtonWithTooltip = React.forwardRef< HTMLButtonElement, HeaderButtonWithTextProps >((props: HeaderButtonWithTextProps, ref) => { - const [hover, setHover] = useState(false); const id = uuidv4(); const tooltipPortalDiv = document.getElementById("tooltip-portal-div"); @@ -39,14 +38,6 @@ const ButtonWithTooltip = React.forwardRef< data-tooltip-id={tooltipId} inverted={props.inverted} disabled={props.disabled} - onMouseEnter={() => { - if (!props.disabled) { - setHover(true); - } - }} - onMouseLeave={() => { - setHover(false); - }} onClick={props.onClick} onKeyDown={props.onKeyDown} className={props.className} diff --git a/gui/src/components/gui/StepContainer.tsx b/gui/src/components/gui/StepContainer.tsx index 10a21fa0a..c4d0b2597 100644 --- a/gui/src/components/gui/StepContainer.tsx +++ b/gui/src/components/gui/StepContainer.tsx @@ -10,7 +10,7 @@ import { stripImages } from "core/llm/images"; import { useContext, useEffect, useState } from "react"; import { useSelector } from "react-redux"; import styled from "styled-components"; -import { defaultBorderRadius, vscBackground, vscInputBackground } from ".."; +import { vscBackground, vscInputBackground } from ".."; import { IdeMessengerContext } from "../../context/IdeMessenger"; import useUIConfig from "../../hooks/useUIConfig"; import { RootState } from "../../redux/store"; @@ -34,18 +34,15 @@ interface StepContainerProps { } const ContentDiv = styled.div<{ isUserInput: boolean; fontSize?: number }>` - padding: 4px 0px 8px 0px; + padding-top: 4px; background-color: ${(props) => props.isUserInput ? vscInputBackground : vscBackground}; font-size: ${(props) => props.fontSize || getFontSize()}px; - // border-radius: ${defaultBorderRadius}; overflow: hidden; `; function StepContainer(props: StepContainerProps) { - const [isHovered, setIsHovered] = useState(false); const active = useSelector((store: RootState) => store.state.active); - const history = useSelector((state: RootState) => state.state.history); const [truncatedEarly, setTruncatedEarly] = useState(false); const ideMessenger = useContext(IdeMessengerContext); const [feedback, setFeedback] = useState(undefined); @@ -53,6 +50,8 @@ function StepContainer(props: StepContainerProps) { const isUserInput = props.item.message.role === "user"; const uiConfig = useUIConfig(); + const shouldRenderActions = !props.isLast || (props.isLast && !active); + useEffect(() => { if (!active) { const content = stripImages(props.item.message.content).trim(); @@ -85,98 +84,72 @@ function StepContainer(props: StepContainerProps) { }; return ( -
{ - setIsHovered(true); - }} - onMouseLeave={() => { - setIsHovered(false); - }} - > -
- - {(props.isLast || isHovered || typeof feedback !== "undefined") && - !active && ( -
- {props.modelTitle && ( -
-
- {props.modelTitle} -
-
-
- )} - - {truncatedEarly && ( - - - - )} - - - - - - - {feedback === false || ( - - { - sendFeedback(true); - }} - /> - - )} - {feedback === true || ( - - { - sendFeedback(false); - }} - /> - - )} - - {props.index !== 1 && ( - - - - )} -
+ {props.index !== 1 && ( + + + )} -
+ + + + sendFeedback(true)} + > + + + + sendFeedback(false)} + > + + +
+ )}
); } diff --git a/gui/src/components/mainInput/ContextItemsPeek.tsx b/gui/src/components/mainInput/ContextItemsPeek.tsx index 5327719d2..38ec51b08 100644 --- a/gui/src/components/mainInput/ContextItemsPeek.tsx +++ b/gui/src/components/mainInput/ContextItemsPeek.tsx @@ -1,7 +1,7 @@ import { ChevronDownIcon, ChevronRightIcon } from "@heroicons/react/24/outline"; import { ContextItemWithId } from "core"; import { contextItemToRangeInFileWithContents } from "core/commands/util"; -import React, { useContext } from "react"; +import { useContext, useState } from "react"; import { lightGray, vscBackground } from ".."; import { IdeMessengerContext } from "../../context/IdeMessenger"; import { getFontSize } from "../../util"; @@ -9,15 +9,39 @@ import FileIcon from "../FileIcon"; import SafeImg from "../SafeImg"; import { INSTRUCTIONS_BASE_ITEM } from "core/context/providers/utils"; import { getIconFromDropdownItem } from "./MentionList"; +import styled from "styled-components"; interface ContextItemsPeekProps { contextItems?: ContextItemWithId[]; + isGatheringContext: boolean; } interface ContextItemsPeekItemProps { contextItem: ContextItemWithId; } +const AnimatedEllipsis = styled.span` + &::after { + content: "."; + animation: ellipsis 2.5s infinite; + display: inline-block; + width: 12px; + text-align: left; + } + + @keyframes ellipsis { + 0% { + content: "."; + } + 33% { + content: ".."; + } + 66% { + content: "..."; + } + } +`; + function ContextItemsPeekItem({ contextItem }: ContextItemsPeekItemProps) { const ideMessenger = useContext(IdeMessengerContext); @@ -116,53 +140,49 @@ function ContextItemsPeekItem({ contextItem }: ContextItemsPeekItemProps) { ); } -function ContextItemsPeek({ contextItems }: ContextItemsPeekProps) { - const [open, setOpen] = React.useState(false); +function ContextItemsPeek({ + contextItems, + isGatheringContext, +}: ContextItemsPeekProps) { + const [open, setOpen] = useState(false); const ctxItems = contextItems?.filter( (ctxItem) => !ctxItem.name.includes(INSTRUCTIONS_BASE_ITEM.name), ); - if (!ctxItems || ctxItems.length === 0) { + if ((!ctxItems || ctxItems.length === 0) && !isGatheringContext) { return null; } - const contextItemsText = `${ctxItems.length} context ${ - ctxItems.length > 1 ? "items" : "item" - }`; - return ( -
+
setOpen((prev) => !prev)} >
- - {contextItemsText} + + {isGatheringContext ? ( + <> + Gathering context + + + ) : ( + `${ctxItems.length} context ${ + ctxItems.length > 1 ? "items" : "item" + }` + )}
@@ -171,9 +191,10 @@ function ContextItemsPeek({ contextItems }: ContextItemsPeekProps) { open ? "max-h-[50vh] opacity-100" : "max-h-0 opacity-0" }`} > - {ctxItems.map((contextItem, idx) => ( - - ))} + {ctxItems && + ctxItems.map((contextItem, idx) => ( + + ))}
); diff --git a/gui/src/components/mainInput/ContinueInputBox.tsx b/gui/src/components/mainInput/ContinueInputBox.tsx index 574a945d0..9778a6de9 100644 --- a/gui/src/components/mainInput/ContinueInputBox.tsx +++ b/gui/src/components/mainInput/ContinueInputBox.tsx @@ -9,6 +9,16 @@ import { newSession, setMessageAtIndex } from "../../redux/slices/stateSlice"; import { RootState } from "../../redux/store"; import ContextItemsPeek from "./ContextItemsPeek"; import TipTapEditor from "./TipTapEditor"; +import { useState, useRef, useEffect } from "react"; + +interface ContinueInputBoxProps { + isLastUserInput: boolean; + isMainInput?: boolean; + onEnter: (editorState: JSONContent, modifiers: InputModifiers) => void; + editorState?: JSONContent; + contextItems?: ContextItemWithId[]; + hidden?: boolean; +} const gradient = keyframes` 0% { @@ -22,8 +32,6 @@ const gradient = keyframes` const GradientBorder = styled.div<{ borderRadius?: string; borderColor?: string; - isFirst: boolean; - isLast: boolean; loading: 0 | 1; }>` border-radius: ${(props) => props.borderRadius || "0"}; @@ -47,18 +55,8 @@ const GradientBorder = styled.div<{ display: flex; flex-direction: row; align-items: center; - margin-top: 8px; `; -interface ContinueInputBoxProps { - isLastUserInput: boolean; - isMainInput?: boolean; - onEnter: (editorState: JSONContent, modifiers: InputModifiers) => void; - editorState?: JSONContent; - contextItems?: ContextItemWithId[]; - hidden?: boolean; -} - function ContinueInputBox(props: ContinueInputBoxProps) { const dispatch = useDispatch(); @@ -67,6 +65,12 @@ function ContinueInputBox(props: ContinueInputBoxProps) { const availableContextProviders = useSelector( (store: RootState) => store.state.config.contextProviders, ); + const isGatheringContextStore = useSelector( + (store: RootState) => store.state.isGatheringContext, + ); + + const [isGatheringContext, setIsGatheringContext] = useState(false); + const timeoutRef = useRef(null); useWebviewListener( "newSessionWithPrompt", @@ -84,24 +88,31 @@ function ContinueInputBox(props: ContinueInputBoxProps) { [props.isMainInput], ); + console.log({ isGatheringContext, isGatheringContextStore }); + + useEffect(() => { + if (isGatheringContextStore && !isGatheringContext) { + // 500ms delay when going from false -> true to prevent flashing loading indicator + timeoutRef.current = setTimeout(() => setIsGatheringContext(true), 500); + } else { + // Update immediately otherwise (i.e. true -> false) + setIsGatheringContext(isGatheringContextStore); + } + + return () => { + if (timeoutRef.current) { + clearTimeout(timeoutRef.current); + } + }; + }, [isGatheringContextStore]); + return (
-
+
+ />
- +
); } diff --git a/gui/src/components/mainInput/InputToolbar.tsx b/gui/src/components/mainInput/InputToolbar.tsx index 57fff591f..99b08d481 100644 --- a/gui/src/components/mainInput/InputToolbar.tsx +++ b/gui/src/components/mainInput/InputToolbar.tsx @@ -59,11 +59,6 @@ const EnterButton = styled.div` border-radius: ${defaultBorderRadius}; color: ${vscForeground}; cursor: pointer; - - &:hover { - background-color: ${vscBadgeBackground}; - color: ${vscBadgeForeground}; - } `; interface InputToolbarProps { @@ -100,7 +95,7 @@ function InputToolbar(props: InputToolbarProps) { >
-
+
{supportsImages && ( <> - + { @@ -125,37 +120,22 @@ function InputToolbar(props: InputToolbarProps) { )} - + - - - -
-
+
{props.activeKey === "Alt" ? ( - + {`${getAltKeyLabel()}⏎ ${useActiveFile ? "No active file" : "Active file"}`} ) : ( props.onEnter({ useCodebase: true, diff --git a/gui/src/components/mainInput/resolveInput.ts b/gui/src/components/mainInput/resolveInput.ts index 7ede4a42d..f57c03f4a 100644 --- a/gui/src/components/mainInput/resolveInput.ts +++ b/gui/src/components/mainInput/resolveInput.ts @@ -207,4 +207,30 @@ function resolveParagraph(p: JSONContent): [string, MentionAttrs[], string] { return [text, contextItems, slashCommand]; } +export function hasSlashCommandOrContextProvider( + editorState: JSONContent, +): boolean { + if (!editorState.content) { + return false; + } + + for (const p of editorState.content) { + if (p.type === "paragraph" && p.content) { + for (const child of p.content) { + if (child.type === "slashcommand") { + return true; + } + if ( + child.type === "mention" && + child.attrs?.itemType === "contextProvider" + ) { + return true; + } + } + } + } + + return false; +} + export default resolveEditorContent; diff --git a/gui/src/components/markdown/CodeBlockToolbar.tsx b/gui/src/components/markdown/CodeBlockToolbar.tsx index 417d33dbb..510e70b2b 100644 --- a/gui/src/components/markdown/CodeBlockToolbar.tsx +++ b/gui/src/components/markdown/CodeBlockToolbar.tsx @@ -18,12 +18,7 @@ import { import { IdeMessengerContext } from "../../context/IdeMessenger"; import { useWebviewListener } from "../../hooks/useWebviewListener"; import { incrementNextCodeBlockToApplyIndex } from "../../redux/slices/uiStateSlice"; -import { - getAltKeyLabel, - getFontSize, - getMetaKeyLabel, - isJetBrains, -} from "../../util"; +import { getFontSize, getMetaKeyLabel, isJetBrains } from "../../util"; import FileIcon from "../FileIcon"; import ButtonWithTooltip from "../ButtonWithTooltip"; import { CopyButton as CopyButtonHeader } from "./CopyButton"; diff --git a/gui/src/components/markdown/CopyButton.tsx b/gui/src/components/markdown/CopyButton.tsx index 144b427f5..1b0a4fbbe 100644 --- a/gui/src/components/markdown/CopyButton.tsx +++ b/gui/src/components/markdown/CopyButton.tsx @@ -6,11 +6,17 @@ import ButtonWithTooltip from "../ButtonWithTooltip"; interface CopyButtonProps { text: string | (() => string); - color?: string; tabIndex?: number; + checkIconClassName?: string; + clipboardIconClassName?: string; } -export function CopyButton(props: CopyButtonProps) { +export function CopyButton({ + text, + tabIndex, + checkIconClassName = "h-4 w-4 text-green-400", + clipboardIconClassName = "h-4 w-4 text-gray-400", +}: CopyButtonProps) { const [copied, setCopied] = useState(false); const ideMessenger = useContext(IdeMessengerContext); @@ -18,15 +24,14 @@ export function CopyButton(props: CopyButtonProps) { return ( <> { - const text = - typeof props.text === "string" ? props.text : props.text(); + const textVal = typeof text === "string" ? text : text(); if (isJetBrains()) { - ideMessenger.request("copyText", { text }); + ideMessenger.request("copyText", { text: textVal }); } else { - navigator.clipboard.writeText(text); + navigator.clipboard.writeText(textVal); } setCopied(true); @@ -34,9 +39,9 @@ export function CopyButton(props: CopyButtonProps) { }} > {copied ? ( - + ) : ( - + )} diff --git a/gui/src/components/markdown/StyledMarkdownPreview.tsx b/gui/src/components/markdown/StyledMarkdownPreview.tsx index 53bed5d93..1e4be98db 100644 --- a/gui/src/components/markdown/StyledMarkdownPreview.tsx +++ b/gui/src/components/markdown/StyledMarkdownPreview.tsx @@ -29,8 +29,7 @@ const StyledMarkdown = styled.div<{ overflow-x: scroll; overflow-y: hidden; - padding: 6px; - margin: 0px; + padding: 6px 8px; } code { @@ -64,6 +63,14 @@ const StyledMarkdown = styled.div<{ ul { line-height: 1.5; } + + > *:first-child { + margin-top: 8px; + } + + > *:last-child { + margin-bottom: 0; + } `; interface StyledMarkdownPreviewProps { diff --git a/gui/src/components/markdown/SyntaxHighlightedPre.tsx b/gui/src/components/markdown/SyntaxHighlightedPre.tsx index 899a462ce..cee6f3f08 100644 --- a/gui/src/components/markdown/SyntaxHighlightedPre.tsx +++ b/gui/src/components/markdown/SyntaxHighlightedPre.tsx @@ -9,6 +9,7 @@ const StyledPre = styled.pre<{ theme: any }>` } margin-top: 0; + margin-bottom: 0; border-radius: 0 0 ${defaultBorderRadius} ${defaultBorderRadius} !important; ${(props) => diff --git a/gui/src/components/modelSelection/ModelSelect.tsx b/gui/src/components/modelSelection/ModelSelect.tsx index d5afd7382..553e440b3 100644 --- a/gui/src/components/modelSelection/ModelSelect.tsx +++ b/gui/src/components/modelSelection/ModelSelect.tsx @@ -318,7 +318,7 @@ function ModelSelect() { style={{ padding: 0 }} onClick={calculatePosition} > -
+
{modelSelectTitle(defaultModel) || "Select model"}{" "} diff --git a/gui/src/components/modelSelection/ModelSelectionListbox.tsx b/gui/src/components/modelSelection/ModelSelectionListbox.tsx index fcac2ce8b..451be0e16 100644 --- a/gui/src/components/modelSelection/ModelSelectionListbox.tsx +++ b/gui/src/components/modelSelection/ModelSelectionListbox.tsx @@ -141,11 +141,7 @@ function ModelSelectionListbox({ - `relative cursor-default select-none py-2 pl-10 pr-4 ${ - active ? "bg-amber-100 text-amber-900" : "text-gray-900" - }` - } + className="relative cursor-default select-none py-2 pl-10 pr-4 text-gray-900" value={option} > {({ selected }) => ( diff --git a/gui/src/hooks/useChatHandler.ts b/gui/src/hooks/useChatHandler.ts index 0de66bd44..9aff5dc79 100644 --- a/gui/src/hooks/useChatHandler.ts +++ b/gui/src/hooks/useChatHandler.ts @@ -17,7 +17,9 @@ import { getBasename, getRelativePath } from "core/util"; import { usePostHog } from "posthog-js/react"; import { useEffect, useRef } from "react"; import { useSelector } from "react-redux"; -import resolveEditorContent from "../components/mainInput/resolveInput"; +import resolveEditorContent, { + hasSlashCommandOrContextProvider, +} from "../components/mainInput/resolveInput"; import { IIdeMessenger } from "../context/IdeMessenger"; import { defaultModelSelector } from "../redux/selectors/modelSelectors"; import { @@ -27,6 +29,7 @@ import { initNewActiveMessage, resubmitAtIndex, setInactive, + setIsGatheringContext, setMessageAtIndex, streamUpdate, } from "../redux/slices/stateSlice"; @@ -52,6 +55,7 @@ function useChatHandler(dispatch: Dispatch, ideMessenger: IIdeMessenger) { const history = useSelector((store: RootState) => store.state.history); const active = useSelector((store: RootState) => store.state.active); const activeRef = useRef(active); + useEffect(() => { activeRef.current = active; }, [active]); @@ -182,6 +186,13 @@ function useChatHandler(dispatch: Dispatch, ideMessenger: IIdeMessenger) { // Reset current code block index dispatch(resetNextCodeBlockToApplyIndex()); + const shouldGatherContext = + modifiers.useCodebase || hasSlashCommandOrContextProvider(editorState); + + if (shouldGatherContext) { + dispatch(setIsGatheringContext(true)); + } + // Resolve context providers and construct new history const [selectedContextItems, selectedCode, content] = await resolveEditorContent( @@ -191,14 +202,17 @@ function useChatHandler(dispatch: Dispatch, ideMessenger: IIdeMessenger) { defaultContextProviders, ); + dispatch(setIsGatheringContext(false)); + // Automatically use currently open file if (!modifiers.noContext) { const usingFreeTrial = defaultModel?.provider === "free-trial"; const currentFilePath = await ideMessenger.ide.getCurrentFile(); if (typeof currentFilePath === "string") { - let currentFileContents = - await ideMessenger.ide.readFile(currentFilePath); + let currentFileContents = await ideMessenger.ide.readFile( + currentFilePath, + ); if (usingFreeTrial) { currentFileContents = currentFileContents .split("\n") @@ -219,18 +233,17 @@ function useChatHandler(dispatch: Dispatch, ideMessenger: IIdeMessenger) { }); } } + dispatch(addContextItems(contextItems)); const message: ChatMessage = { role: "user", content, }; + const historyItem: ChatHistoryItem = { message, contextItems: selectedContextItems, - // : typeof index === "number" - // ? history[index].contextItems - // : contextItems, editorState, }; diff --git a/gui/src/pages/gui.tsx b/gui/src/pages/gui.tsx index d1535f1ad..156c0b3b2 100644 --- a/gui/src/pages/gui.tsx +++ b/gui/src/pages/gui.tsx @@ -102,7 +102,6 @@ const StepsDiv = styled.div` .thread-message { margin: 8px 4px 0 4px; - padding-bottom: 8px; } `; diff --git a/gui/src/redux/slices/stateSlice.ts b/gui/src/redux/slices/stateSlice.ts index 82cad0542..f6c61970a 100644 --- a/gui/src/redux/slices/stateSlice.ts +++ b/gui/src/redux/slices/stateSlice.ts @@ -37,6 +37,7 @@ type State = { contextItems: ContextItemWithId[]; ttsActive: boolean; active: boolean; + isGatheringContext: boolean; config: BrowserSerializedContinueConfig; title: string; sessionId: string; @@ -50,6 +51,7 @@ const initialState: State = { contextItems: [], ttsActive: false, active: false, + isGatheringContext: false, config: { slashCommands: [ { @@ -113,6 +115,9 @@ export const stateSlice = createSlice({ setActive: (state) => { state.active = true; }, + setIsGatheringContext: (state, { payload }: PayloadAction) => { + state.isGatheringContext = payload; + }, clearLastResponse: (state) => { if (state.history.length < 2) { return; @@ -264,6 +269,7 @@ export const stateSlice = createSlice({ historyItem.contextItems.push(...payload.contextItems); }, setInactive: (state) => { + state.isGatheringContext = false; state.active = false; }, streamUpdate: (state, action: PayloadAction) => { @@ -453,5 +459,7 @@ export const { consumeMainEditorContent, setSelectedProfileId, deleteMessage, + setIsGatheringContext, } = stateSlice.actions; + export default stateSlice.reducer;