diff --git a/.github/workflows/preview.yaml b/.github/workflows/preview.yaml index bd5f4b7ac..945f8d84b 100644 --- a/.github/workflows/preview.yaml +++ b/.github/workflows/preview.yaml @@ -4,6 +4,13 @@ on: release: types: [prereleased] + workflow_dispatch: + inputs: + publish_build: + description: "Whether or not to publish the built extension to the VS Code marketplace" + required: true + default: false + jobs: check_release_name: runs-on: ubuntu-latest @@ -21,7 +28,7 @@ jobs: build: needs: check_release_name - if: needs.check_release_name.outputs.should_run == 'true' + if: needs.check_release_name.outputs.should_run == 'true' || github.event_name == 'workflow_dispatch' strategy: matrix: include: @@ -197,6 +204,7 @@ jobs: runs-on: ubuntu-latest needs: - build + if: github.event.inputs.publish_build == 'true' permissions: contents: write steps: diff --git a/core/autocomplete/snippets/getAllSnippets.ts b/core/autocomplete/snippets/getAllSnippets.ts index 198bf16c6..fc6538b41 100644 --- a/core/autocomplete/snippets/getAllSnippets.ts +++ b/core/autocomplete/snippets/getAllSnippets.ts @@ -90,7 +90,12 @@ const getClipboardSnippets = async ( const getDiffSnippets = async ( ide: IDE, ): Promise => { - const diff = await ide.getDiff(true); + let diff: string[] = []; + try { + diff = await ide.getDiff(true); + } catch (e) { + console.error("Error getting diff for autocomplete", e); + } return diff.map((item) => { return { diff --git a/core/config/ConfigHandler.ts b/core/config/ConfigHandler.ts index 4ad045d30..4638613b9 100644 --- a/core/config/ConfigHandler.ts +++ b/core/config/ConfigHandler.ts @@ -365,11 +365,11 @@ export class ConfigHandler { this.updateListeners.push(listener); } - async reloadConfig(additionalContextProviders: IContextProvider[] = []) { + async reloadConfig() { // TODO: this isn't right, there are two different senses in which you want to "reload" const { config, errors, configLoadInterrupted } = - await this.currentProfile.reloadConfig(additionalContextProviders); + await this.currentProfile.reloadConfig(this.additionalContextProviders); if (config) { this.inactiveProfiles.forEach((profile) => profile.clearConfig()); @@ -419,6 +419,6 @@ export class ConfigHandler { registerCustomContextProvider(contextProvider: IContextProvider) { this.additionalContextProviders.push(contextProvider); - void this.reloadConfig(this.additionalContextProviders); + void this.reloadConfig(); } } diff --git a/core/config/default.ts b/core/config/default.ts index 8662be678..23e709603 100644 --- a/core/config/default.ts +++ b/core/config/default.ts @@ -5,20 +5,6 @@ import { SlashCommandDescription, } from "../"; -export const DEFAULT_CHAT_MODEL_CONFIG: ModelDescription = { - model: "claude-3-5-sonnet-latest", - provider: "anthropic", - apiKey: "", - title: "Claude 3.5 Sonnet", -}; - -export const DEFAULT_AUTOCOMPLETE_MODEL_CONFIG: ModelDescription = { - title: "Codestral", - provider: "mistral", - model: "codestral-latest", - apiKey: "", -}; - export const FREE_TRIAL_MODELS: ModelDescription[] = [ { title: "Claude 3.5 Sonnet (Free Trial)", @@ -93,15 +79,13 @@ export const defaultSlashCommandsJetBrains = [ ]; export const defaultConfig: SerializedContinueConfig = { - models: [DEFAULT_CHAT_MODEL_CONFIG], - tabAutocompleteModel: DEFAULT_AUTOCOMPLETE_MODEL_CONFIG, + models: [], contextProviders: defaultContextProvidersVsCode, slashCommands: defaultSlashCommandsVscode, }; export const defaultConfigJetBrains: SerializedContinueConfig = { - models: [DEFAULT_CHAT_MODEL_CONFIG], - tabAutocompleteModel: DEFAULT_AUTOCOMPLETE_MODEL_CONFIG, + models: [], contextProviders: defaultContextProvidersJetBrains, slashCommands: defaultSlashCommandsJetBrains, }; diff --git a/core/llm/autodetect.ts b/core/llm/autodetect.ts index 8232f8288..ed1901641 100644 --- a/core/llm/autodetect.ts +++ b/core/llm/autodetect.ts @@ -1,4 +1,4 @@ -import { ModelCapability, TemplateType } from "../index.js"; +import { ChatMessage, ModelCapability, TemplateType } from "../index.js"; import { anthropicTemplateMessages, @@ -257,7 +257,10 @@ function autodetectTemplateFunction( const templateType = explicitTemplate ?? autodetectTemplateType(model); if (templateType) { - const mapping: Record = { + const mapping: Record< + TemplateType, + null | ((msg: ChatMessage[]) => string) + > = { llama2: llama2TemplateMessages, alpaca: templateAlpacaMessages, phi2: phi2TemplateMessages, diff --git a/core/llm/index.ts b/core/llm/index.ts index da1825407..4989f14fa 100644 --- a/core/llm/index.ts +++ b/core/llm/index.ts @@ -191,7 +191,8 @@ export abstract class BaseLLM implements ILLM { options.model, this.providerName, options.template, - ); + ) ?? + undefined; this.writeLog = options.writeLog; this.llmRequestHook = options.llmRequestHook; this.apiKey = options.apiKey; @@ -957,7 +958,9 @@ export abstract class BaseLLM implements ILLM { this.providerName, autodetectTemplateType(this.model), ); - return templateMessages(rendered); + if (templateMessages) { + return templateMessages(rendered); + } } return rendered; } diff --git a/core/promptFiles/v1/slashCommandFromPromptFile.ts b/core/promptFiles/v1/slashCommandFromPromptFile.ts index d89ee1082..b0dc0f881 100644 --- a/core/promptFiles/v1/slashCommandFromPromptFile.ts +++ b/core/promptFiles/v1/slashCommandFromPromptFile.ts @@ -25,15 +25,20 @@ async function renderPromptV1( ) { const helpers = getContextProviderHelpers(context); - // A few context providers that don't need to be in config.json to work in .prompt files - const diff = await context.ide.getDiff(true); - const currentFile = await context.ide.getCurrentFile(); const inputData: Record = { - diff: diff.join("\n"), input: userInput, }; - if (currentFile) { - inputData.currentFile = currentFile.path; + + // A few context providers that don't need to be in config.json to work in .prompt files + if (helpers?.find((helper) => helper[0] === "diff")) { + const diff = await context.ide.getDiff(true); + inputData.diff = diff.join("\n"); + } + if (helpers?.find((helper) => helper[0] === "currentFile")) { + const currentFile = await context.ide.getCurrentFile(); + if (currentFile) { + inputData.currentFile = currentFile.path; + } } return renderTemplatedString( diff --git a/docs/docs/customize/deep-dives/rules.md b/docs/docs/customize/deep-dives/rules.md index f53135b50..ae8347f29 100644 --- a/docs/docs/customize/deep-dives/rules.md +++ b/docs/docs/customize/deep-dives/rules.md @@ -12,7 +12,7 @@ You can create a project-specific system message by adding a `.continuerules` fi - If you want concise answers: ```title=.continuerules -Please provide concise answers. Do explain obvious concepts. You can assume that I am knowledgable about most programming topics. +Please provide concise answers. Don't explain obvious concepts. You can assume that I am knowledgable about most programming topics. ``` - If you want to ensure certain practices are followed, for example in React: diff --git a/extensions/vscode/config_schema.json b/extensions/vscode/config_schema.json index 827662dd2..d9dab076b 100644 --- a/extensions/vscode/config_schema.json +++ b/extensions/vscode/config_schema.json @@ -936,7 +936,8 @@ "gemini-1.5-flash-latest", "gemini-1.5-flash", "gemini-1.5-flash-8b", - "gemini-2.0-flash-exp" + "gemini-2.0-flash-exp", + "gemini-2.0-flash" ] } } diff --git a/extensions/vscode/package.json b/extensions/vscode/package.json index 5ef76d3dc..bb45a07be 100644 --- a/extensions/vscode/package.json +++ b/extensions/vscode/package.json @@ -580,7 +580,8 @@ { "type": "webview", "id": "continue.continueGUIView", - "name": "", + "name": "Continue", + "icon": "media/sidebar-icon.png", "visibility": "visible" } ] diff --git a/gui/src/components/Layout.tsx b/gui/src/components/Layout.tsx index 747c2ddab..94a9fb616 100644 --- a/gui/src/components/Layout.tsx +++ b/gui/src/components/Layout.tsx @@ -23,6 +23,7 @@ import { AuthProvider } from "../context/Auth"; import { exitEditMode } from "../redux/thunks"; import { loadLastSession, saveCurrentSession } from "../redux/thunks/session"; import { incrementFreeTrialCount } from "../util/freeTrial"; +import OSRContextMenu from "./OSRContextMenu"; const LayoutTopDiv = styled(CustomScrollbarDiv)` height: 100%; @@ -261,6 +262,7 @@ const Layout = () => { return ( +
{ + const ideMessenger = useContext(IdeMessengerContext); + const isOSREnabled = useIsOSREnabled(); + const platform = useRef(getPlatform()); + + const [position, setPosition] = useState(null); + const [canCopy, setCanCopy] = useState(false); + const [canCut, setCanCut] = useState(false); + const [canPaste, setCanPaste] = useState(false); + + const menuRef = React.useRef(null); + const selectedTextRef = useRef(null); + const selectedRangeRef = useRef(null); + + function onMenuItemClick( + event: React.MouseEvent, + ) { + event.preventDefault(); + + // restore selection + if (selectedRangeRef.current) { + const selection = window.getSelection(); + selection?.removeAllRanges(); + selection?.addRange(selectedRangeRef.current); + } + + // Hide menu + setPosition(null); + } + + useEffect(() => { + function leaveWindowHandler() { + setPosition(null); + } + function contextMenuHandler(event: MouseEvent) { + event.preventDefault(); + } + function clickHandler(event: MouseEvent) { + // If clicked outside of menu, close menu + if (!menuRef.current?.contains(event.target as Node)) { + setPosition(null); + } + + if (event.button === 2) { + // Prevent default context menu + event.preventDefault(); + + selectedRangeRef.current = null; + selectedTextRef.current = null; + + const selection = window.getSelection(); + let isClickWithinSelection = false; + if (selection && selection.rangeCount > 0) { + const range = selection.getRangeAt(0); + const selectedText = range.toString(); + selectedRangeRef.current = range.cloneRange(); + + if (selectedText.length > 0) { + if (selectedText) { + selectedTextRef.current = selectedText; + const rects = range.getClientRects(); + for (let i = 0; i < rects.length; i++) { + const rect = rects[i]; + if ( + event.clientX >= rect.left && + event.clientX <= rect.right && + event.clientY >= rect.top && + event.clientY <= rect.bottom + ) { + isClickWithinSelection = true; + break; + } + } + } + } + } + + // Check if right clicked on editable content (allows paste/cut) + let isEditable = false; + if ( + event.target && + "isContentEditable" in event.target && + typeof event.target.isContentEditable === "boolean" + ) { + isEditable = event.target.isContentEditable; + } + + setCanCopy(!!selectedTextRef.current && isClickWithinSelection); + setCanCut( + !!(isEditable && selectedTextRef.current && isClickWithinSelection), + ); + + // TODO only can paste if there is text in clipboard? + setCanPaste(isEditable); + // navigator.clipboard.readText().then((text) => { + // setCanPaste(text || null); + // }); + + // Open towards inside of window from click + const toRight = event.clientX > window.innerWidth / 2; + const toBottom = event.clientY > window.innerHeight / 2; + if (toRight) { + if (toBottom) { + setPosition({ + bottom: window.innerHeight - event.clientY, + right: window.innerWidth - event.clientX, + }); + } else { + setPosition({ + top: event.clientY, + right: window.innerWidth - event.clientX, + }); + } + } else { + if (toBottom) { + setPosition({ + bottom: window.innerHeight - event.clientY, + left: event.clientX, + }); + } else { + setPosition({ + top: event.clientY, + left: event.clientX, + }); + } + } + } + } + + setPosition(null); + if (isOSREnabled && platform.current !== "mac") { + document.addEventListener("mousedown", clickHandler); + document.addEventListener("mouseleave", leaveWindowHandler); + document.addEventListener("contextmenu", contextMenuHandler); + } + + return () => { + document.removeEventListener("mousedown", clickHandler); + document.removeEventListener("mouseleave", leaveWindowHandler); + document.removeEventListener("contextmenu", contextMenuHandler); + }; + }, [isOSREnabled]); + + if (platform.current === "mac" || !isOSREnabled || !position) { + return null; + } + return ( +
+ {canCopy && ( +
{ + onMenuItemClick(e); + document.execCommand("copy"); + }} + > + Copy +
+ )} + {canCut && ( +
{ + onMenuItemClick(e); + document.execCommand("cut"); + }} + > + Cut +
+ )} + {/* PASTING is currently broken, can't get the clipboard text */} + {/* {canPaste && ( +
{ + onMenuItemClick(e); + const clipboardText = await navigator.clipboard.readText(); + // const out = await navigator.clipboard.read(); + if (clipboardText) { + selectedRangeRef.current?.deleteContents(); + selectedRangeRef.current?.insertNode( + document.createTextNode(clipboardText), + ); + } + }} + > + Paste +
+ )} */} +
{ + onMenuItemClick(e); + ideMessenger.post("toggleDevTools", undefined); + }} + > + Open Dev Tools +
+
+ ); +}; + +export default OSRContextMenu; diff --git a/gui/src/components/OnboardingCard/OnboardingCard.tsx b/gui/src/components/OnboardingCard/OnboardingCard.tsx index eebbfb2bc..f48e2939d 100644 --- a/gui/src/components/OnboardingCard/OnboardingCard.tsx +++ b/gui/src/components/OnboardingCard/OnboardingCard.tsx @@ -5,6 +5,7 @@ import styled from "styled-components"; import { CloseButton, defaultBorderRadius, vscInputBackground } from "../"; import { getLocalStorage, setLocalStorage } from "../../util/localStorage"; import { useOnboardingCard } from "./hooks/useOnboardingCard"; +import { useAppSelector } from "../../redux/hooks"; const StyledCard = styled.div` margin: auto; @@ -26,6 +27,7 @@ interface OnboardingCardProps { export function OnboardingCard({ isDialog }: OnboardingCardProps) { const onboardingCard = useOnboardingCard(); + const config = useAppSelector((store) => store.config.config); function renderTabContent() { switch (onboardingCard.activeTab) { @@ -53,7 +55,7 @@ export function OnboardingCard({ isDialog }: OnboardingCardProps) { activeTab={onboardingCard.activeTab || "Best"} onTabClick={onboardingCard.setActiveTab} /> - {!isDialog && ( + {!isDialog && !!config.models.length && ( onboardingCard.close()}> diff --git a/gui/src/components/OnboardingCard/components/BestExperienceConfigForm.tsx b/gui/src/components/OnboardingCard/components/BestExperienceConfigForm.tsx index 86e7cd693..98f71cce2 100644 --- a/gui/src/components/OnboardingCard/components/BestExperienceConfigForm.tsx +++ b/gui/src/components/OnboardingCard/components/BestExperienceConfigForm.tsx @@ -1,5 +1,4 @@ import { CubeIcon } from "@heroicons/react/24/outline"; -import { DEFAULT_CHAT_MODEL_CONFIG } from "core/config/default"; import { FormEventHandler, useContext, useState } from "react"; import { useDispatch } from "react-redux"; import { Button, Input, InputSubtext, lightGray } from "../.."; @@ -57,9 +56,6 @@ function BestExperienceConfigForm({ apiKey: autocompleteApiKey, }; - ideMessenger.post("config/deleteModel", { - title: DEFAULT_CHAT_MODEL_CONFIG.title, - }); ideMessenger.post("config/addModel", { model: chatModelConfig }); ideMessenger.post("config/addModel", { model: repoMapConfig, diff --git a/gui/src/components/OnboardingCard/platform/PlatformOnboardingCard.tsx b/gui/src/components/OnboardingCard/platform/PlatformOnboardingCard.tsx index ede9295b3..51e951497 100644 --- a/gui/src/components/OnboardingCard/platform/PlatformOnboardingCard.tsx +++ b/gui/src/components/OnboardingCard/platform/PlatformOnboardingCard.tsx @@ -8,6 +8,7 @@ import { TabTitle } from "../components/OnboardingCardTabs"; import { useOnboardingCard } from "../hooks"; import OnboardingLocalTab from "../tabs/OnboardingLocalTab"; import MainTab from "./tabs/main"; +import { useAppSelector } from "../../../redux/hooks"; const StyledCard = styled.div` margin: auto; @@ -29,6 +30,7 @@ interface OnboardingCardProps { export function PlatformOnboardingCard({ isDialog }: OnboardingCardProps) { const onboardingCard = useOnboardingCard(); + const config = useAppSelector((store) => store.config.config); if (getLocalStorage("onboardingStatus") === undefined) { setLocalStorage("onboardingStatus", "Started"); @@ -38,7 +40,7 @@ export function PlatformOnboardingCard({ isDialog }: OnboardingCardProps) { return ( - {!isDialog && ( + {!isDialog && !!config.models.length && ( onboardingCard.close()}> diff --git a/gui/src/components/mainInput/handleMetaKeyIssues.ts b/gui/src/components/mainInput/handleMetaKeyIssues.ts index 14bf3f792..1adf5593a 100644 --- a/gui/src/components/mainInput/handleMetaKeyIssues.ts +++ b/gui/src/components/mainInput/handleMetaKeyIssues.ts @@ -3,7 +3,6 @@ import { KeyboardEvent } from "react"; import { getPlatform, isWebEnvironment } from "../../util"; const isWebEnv = isWebEnvironment(); -const platform = getPlatform(); /** * This handles various keypress issues when OSR is enabled @@ -14,6 +13,7 @@ export const handleJetBrainsOSRMetaKeyIssues = ( ) => { const selection = window.getSelection(); const alter = e.shiftKey ? "extend" : "move"; + const platform = getPlatform(); const handlers: Record void> = { Backspace: () => handleJetBrainsMetaBackspace(editor), @@ -108,6 +108,7 @@ export const handleJetBrainsMetaBackspace = (editor: Editor) => { } // For Linux/Windows, only delete the word to the left of the cursor + const platform = getPlatform(); if (platform !== "mac") { deleteSingleWord(editor); break; diff --git a/gui/src/pages/gui/StreamError.tsx b/gui/src/pages/gui/StreamError.tsx index ca3bc04bc..2a8465c30 100644 --- a/gui/src/pages/gui/StreamError.tsx +++ b/gui/src/pages/gui/StreamError.tsx @@ -51,7 +51,8 @@ const StreamErrorDialog = ({ error }: StreamErrorProps) => { typeof error["message"] === "string" ) { message = error["message"]; - const status = message?.split(" ")[0]; + const parts = message?.split(" ") ?? []; + const status = parts[0] === "HTTP" ? parts[1] : parts[0]; if (status) { const code = Number(status); if (!Number.isNaN(statusCode)) {