From 1d1f705f7dfb1d517b90e03b82856e625f3f323e Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Thu, 20 Mar 2025 16:58:29 -0700 Subject: [PATCH] feat: move .prompts into slash cmd --- core/config/load.ts | 3 - core/config/yaml/loadYaml.ts | 2 - .../providers/PromptFilesContextProvider.ts | 57 ------------ .../v1/slashCommandFromPromptFile.ts | 10 +-- core/util/paths.ts | 2 +- .../ConversationStarterCard.tsx | 8 +- .../ConversationStarterCards.tsx | 53 ++++++++++-- .../components/ConversationStarters/utils.ts | 17 +++- gui/src/components/mainInput/MentionList.tsx | 6 +- gui/src/components/mainInput/TipTapEditor.tsx | 2 +- gui/src/components/mainInput/getSuggestion.ts | 53 +++++++----- gui/src/pages/config/ModelRoleSelector.tsx | 86 ++++++++++--------- gui/src/pages/gui/EmptyChatBody.tsx | 4 +- gui/src/redux/selectors/index.ts | 2 +- 14 files changed, 153 insertions(+), 152 deletions(-) delete mode 100644 core/context/providers/PromptFilesContextProvider.ts diff --git a/core/config/load.ts b/core/config/load.ts index d9c789404..0216894e1 100644 --- a/core/config/load.ts +++ b/core/config/load.ts @@ -45,7 +45,6 @@ import ContinueProxyContextProvider from "../context/providers/ContinueProxyCont import CustomContextProviderClass from "../context/providers/CustomContextProvider"; import FileContextProvider from "../context/providers/FileContextProvider"; import { contextProviderClassFromName } from "../context/providers/index"; -import PromptFilesContextProvider from "../context/providers/PromptFilesContextProvider"; import { useHub } from "../control-plane/env"; import { allEmbeddingsProviders } from "../indexing/allEmbeddingsProviders"; import { BaseLLM } from "../llm"; @@ -401,8 +400,6 @@ async function intermediateToFinalConfig( ...(!config.disableIndexing ? [new CodebaseContextProvider(codebaseContextParams)] : []), - // Add prompt files provider if enabled - ...(loadPromptFiles ? [new PromptFilesContextProvider({})] : []), ]; const DEFAULT_CONTEXT_PROVIDERS_TITLES = DEFAULT_CONTEXT_PROVIDERS.map( diff --git a/core/config/yaml/loadYaml.ts b/core/config/yaml/loadYaml.ts index a11e1ab44..ae1f13f58 100644 --- a/core/config/yaml/loadYaml.ts +++ b/core/config/yaml/loadYaml.ts @@ -28,7 +28,6 @@ import CodebaseContextProvider from "../../context/providers/CodebaseContextProv import DocsContextProvider from "../../context/providers/DocsContextProvider"; import FileContextProvider from "../../context/providers/FileContextProvider"; import { contextProviderClassFromName } from "../../context/providers/index"; -import PromptFilesContextProvider from "../../context/providers/PromptFilesContextProvider"; import { ControlPlaneClient } from "../../control-plane/client"; import { allEmbeddingsProviders } from "../../indexing/allEmbeddingsProviders"; import FreeTrial from "../../llm/llms/FreeTrial"; @@ -333,7 +332,6 @@ async function configYamlToContinueConfig( const DEFAULT_CONTEXT_PROVIDERS = [ new FileContextProvider({}), new CodebaseContextProvider(codebaseContextParams), - new PromptFilesContextProvider({}), ]; const DEFAULT_CONTEXT_PROVIDERS_TITLES = DEFAULT_CONTEXT_PROVIDERS.map( diff --git a/core/context/providers/PromptFilesContextProvider.ts b/core/context/providers/PromptFilesContextProvider.ts deleted file mode 100644 index c3b4381f4..000000000 --- a/core/context/providers/PromptFilesContextProvider.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { BaseContextProvider } from ".."; -import { - ContextItem, - ContextProviderDescription, - ContextProviderExtras, - ContextSubmenuItem, - LoadSubmenuItemsArgs, -} from "../../"; -import { getAllPromptFiles } from "../../promptFiles/v2/getPromptFiles"; -import { parsePreamble } from "../../promptFiles/v2/parse"; -import { renderPromptFileV2 } from "../../promptFiles/v2/renderPromptFile"; - -class PromptFilesContextProvider extends BaseContextProvider { - static description: ContextProviderDescription = { - title: "prompt-files", - displayTitle: "Prompt Files", - description: ".prompt files", - type: "submenu", - }; - - async getContextItems( - query: string, - extras: ContextProviderExtras, - ): Promise { - const rawContent = await extras.ide.readFile(query); - const preamble = parsePreamble(query, rawContent); - const [contextItems, body] = await renderPromptFileV2(rawContent, extras); - return [ - ...contextItems, - { - content: body, - name: preamble.name, - description: preamble.description, - }, - ]; - } - - async loadSubmenuItems( - args: LoadSubmenuItemsArgs, - ): Promise { - const promptFiles = await getAllPromptFiles( - args.ide, - args.config.experimental?.promptPath, - // Note, NOT checking v1 default folder here, deprecated for context provider - ); - return promptFiles.map((file) => { - const preamble = parsePreamble(file.path, file.content); - return { - id: file.path, - title: preamble.name, - description: preamble.description, - }; - }); - } -} - -export default PromptFilesContextProvider; diff --git a/core/promptFiles/v1/slashCommandFromPromptFile.ts b/core/promptFiles/v1/slashCommandFromPromptFile.ts index 833955d0d..f051dfe59 100644 --- a/core/promptFiles/v1/slashCommandFromPromptFile.ts +++ b/core/promptFiles/v1/slashCommandFromPromptFile.ts @@ -53,12 +53,10 @@ export function slashCommandFromPromptFileV1( path: string, content: string, ): SlashCommand | null { - const { name, description, systemMessage, prompt, version } = - parsePromptFileV1V2(path, content); - - if (version !== 1) { - return null; - } + const { name, description, systemMessage, prompt } = parsePromptFileV1V2( + path, + content, + ); return { name, diff --git a/core/util/paths.ts b/core/util/paths.ts index 3bc2ee3cf..0fa64d109 100644 --- a/core/util/paths.ts +++ b/core/util/paths.ts @@ -2,10 +2,10 @@ import * as fs from "fs"; import * as os from "os"; import * as path from "path"; +import { DevEventName } from "@continuedev/config-yaml"; import * as JSONC from "comment-json"; import dotenv from "dotenv"; -import { DevEventName } from "@continuedev/config-yaml"; import { IdeType, SerializedContinueConfig } from "../"; import { defaultConfig, defaultConfigJetBrains } from "../config/default"; import Types from "../config/types"; diff --git a/gui/src/components/ConversationStarters/ConversationStarterCard.tsx b/gui/src/components/ConversationStarters/ConversationStarterCard.tsx index 6714287c1..35a205481 100644 --- a/gui/src/components/ConversationStarters/ConversationStarterCard.tsx +++ b/gui/src/components/ConversationStarters/ConversationStarterCard.tsx @@ -20,13 +20,13 @@ export function ConversationStarterCard({ backgroundColor: vscInputBackground, }} > -
+
- +
-
{command.name}
-
{command.description}
+
{command.name}
+
{command.description}
diff --git a/gui/src/components/ConversationStarters/ConversationStarterCards.tsx b/gui/src/components/ConversationStarters/ConversationStarterCards.tsx index f3dcda317..69020dae5 100644 --- a/gui/src/components/ConversationStarters/ConversationStarterCards.tsx +++ b/gui/src/components/ConversationStarters/ConversationStarterCards.tsx @@ -1,18 +1,28 @@ import { SlashCommandDescription } from "core"; +import { useState } from "react"; import { useAppDispatch, useAppSelector } from "../../redux/hooks"; import { setMainEditorContentTrigger } from "../../redux/slices/sessionSlice"; import { getParagraphNodeFromString } from "../mainInput/utils"; import { ConversationStarterCard } from "./ConversationStarterCard"; import { isDeprecatedCommandName } from "./utils"; +const NUM_CARDS_TO_RENDER_COLLAPSED = 3; + export function ConversationStarterCards() { const dispatch = useAppDispatch(); - const slashCommands = useAppSelector( - (state) => state.config.config.slashCommands, - ); + const [isExpanded, setIsExpanded] = useState(false); + const slashCommands = + useAppSelector((state) => state.config.config.slashCommands) ?? []; const filteredSlashCommands = slashCommands?.filter(isDeprecatedCommandName); + const numFilteredSlashCommands = filteredSlashCommands.length; + const displayedCommands = isExpanded + ? filteredSlashCommands + : filteredSlashCommands.slice(0, NUM_CARDS_TO_RENDER_COLLAPSED); + const hasMoreCommands = + numFilteredSlashCommands > NUM_CARDS_TO_RENDER_COLLAPSED; + function onClick(command: SlashCommandDescription) { if (command.prompt) { dispatch( @@ -21,7 +31,38 @@ export function ConversationStarterCards() { } } - return filteredSlashCommands?.map((command) => ( - - )); + function handleToggleExpand() { + setIsExpanded(!isExpanded); + } + + if (!filteredSlashCommands || filteredSlashCommands.length === 0) { + return null; + } + + return ( +
+

Prompts

+ +
+ {displayedCommands.map((command, i) => ( + + ))} +
+ + {hasMoreCommands && ( +

+ {isExpanded + ? "Show less" + : `Show ${numFilteredSlashCommands - NUM_CARDS_TO_RENDER_COLLAPSED} more...`} +

+ )} +
+ ); } diff --git a/gui/src/components/ConversationStarters/utils.ts b/gui/src/components/ConversationStarters/utils.ts index b1ca8859c..aab6cb414 100644 --- a/gui/src/components/ConversationStarters/utils.ts +++ b/gui/src/components/ConversationStarters/utils.ts @@ -1,12 +1,17 @@ import { SlashCommandDescription } from "core"; - -const DEPRECATED_SLASH_COMMAND_NAMES = ["share", "cmd"]; +import { + defaultSlashCommandsJetBrains, + defaultSlashCommandsVscode, +} from "core/config/default"; +import { isJetBrains } from "../../util"; /** * The commands filtered here are currently inserted into the slash commands array during * intermediary config loading, but once we get the actual prompts for an assistant, * they are overwritten. * + * Additionally, these default commands are all deprecated. + * * If we don't manually filter them out, then they are displayed in the UI * while the assistant is still loading. * @@ -14,5 +19,11 @@ const DEPRECATED_SLASH_COMMAND_NAMES = ["share", "cmd"]; * this function can be removed. */ export function isDeprecatedCommandName(command: SlashCommandDescription) { - return !DEPRECATED_SLASH_COMMAND_NAMES.includes(command.name); + const defaultCommands = isJetBrains() + ? defaultSlashCommandsJetBrains + : defaultSlashCommandsVscode; + + return !defaultCommands.find( + (defaultCommand) => defaultCommand.name === command.name, + ); } diff --git a/gui/src/components/mainInput/MentionList.tsx b/gui/src/components/mainInput/MentionList.tsx index 94324b75e..5ba1bcca4 100644 --- a/gui/src/components/mainInput/MentionList.tsx +++ b/gui/src/components/mainInput/MentionList.tsx @@ -3,9 +3,9 @@ import { ArrowUpOnSquareIcon, AtSymbolIcon, Bars3BottomLeftIcon, - BoltIcon, BookOpenIcon, BugAntIcon, + ChatBubbleLeftIcon, CircleStackIcon, CodeBracketIcon, CommandLineIcon, @@ -88,7 +88,8 @@ export function getIconFromDropdownItem( id: string | undefined, type: ComboBoxItemType, ) { - const typeIcon = type === "contextProvider" ? AtSymbolIcon : BoltIcon; + const typeIcon = + type === "contextProvider" ? AtSymbolIcon : ChatBubbleLeftIcon; return id ? (ICONS_FOR_DROPDOWN[id] ?? typeIcon) : typeIcon; } @@ -506,7 +507,6 @@ const MentionList = forwardRef((props: MentionListProps, ref) => { ) : ( No results )} - {/* */} )} diff --git a/gui/src/components/mainInput/TipTapEditor.tsx b/gui/src/components/mainInput/TipTapEditor.tsx index 49dc3ce84..3849ecd3f 100644 --- a/gui/src/components/mainInput/TipTapEditor.tsx +++ b/gui/src/components/mainInput/TipTapEditor.tsx @@ -565,7 +565,7 @@ function TipTapEditor(props: TipTapEditorProps) { } return historyLength === 0 - ? "Ask anything, '@' to add context" + ? "Ask anything, '/' for prompts, '@' to add context" : "Ask a follow-up"; } diff --git a/gui/src/components/mainInput/getSuggestion.ts b/gui/src/components/mainInput/getSuggestion.ts index ecc7b835e..ab107f146 100644 --- a/gui/src/components/mainInput/getSuggestion.ts +++ b/gui/src/components/mainInput/getSuggestion.ts @@ -8,8 +8,8 @@ import { MutableRefObject } from "react"; import tippy from "tippy.js"; import { IIdeMessenger } from "../../context/IdeMessenger"; import MentionList from "./MentionList"; -import { ComboBoxItem, ComboBoxItemType, ComboBoxSubAction } from "./types"; import { TIPPY_DIV_ID } from "./TipTapEditor"; +import { ComboBoxItem, ComboBoxItemType, ComboBoxSubAction } from "./types"; function getSuggestion( items: (props: { query: string }) => Promise, @@ -198,27 +198,18 @@ export function getSlashCommandDropdownOptions( ideMessenger: IIdeMessenger, ) { const items = async ({ query }: { query: string }) => { - const options = [ - ...availableSlashCommandsRef.current, - // { - // title: "Build a custom prompt", - // description: "Build a custom prompt", - // type: "action", - // id: "createPromptFile", - // label: "Create Prompt File", - // action: () => { - // ideMessenger.post("config/newPromptFile", undefined); - // }, - // name: "Create Prompt File", - // }, - ]; - return ( - options.filter((slashCommand) => { - const sc = slashCommand.title.substring(1).toLowerCase(); - const iv = query.toLowerCase(); - return sc.startsWith(iv); - }) || [] - ).map((provider) => ({ + const options = [...availableSlashCommandsRef.current]; + + const filteredCommands = + query.length > 0 + ? options.filter((slashCommand) => { + const sc = slashCommand.title.substring(1).toLowerCase(); + const iv = query.toLowerCase(); + return sc.startsWith(iv); + }) + : options; + + const commandItems = (filteredCommands || []).map((provider) => ({ name: provider.title, description: provider.description, id: provider.title, @@ -227,6 +218,24 @@ export function getSlashCommandDropdownOptions( type: (provider.type ?? "slashCommand") as ComboBoxItemType, action: provider.action, })); + + if (query.length === 0 && commandItems.length > 0) { + commandItems.push({ + title: "Explore prompts", + type: "action", + action: () => + ideMessenger.post( + "openUrl", + "https://hub.continue.dev/explore/prompts", + ), + description: "", + name: "", + id: "", + label: "", + }); + } + + return commandItems; }; return getSuggestion(items, undefined, onClose, onOpen); } diff --git a/gui/src/pages/config/ModelRoleSelector.tsx b/gui/src/pages/config/ModelRoleSelector.tsx index 163f86b76..d9d6196a7 100644 --- a/gui/src/pages/config/ModelRoleSelector.tsx +++ b/gui/src/pages/config/ModelRoleSelector.tsx @@ -1,12 +1,15 @@ -import { Fragment } from "react"; import { Listbox, Transition } from "@headlessui/react"; import { ChevronUpDownIcon, InformationCircleIcon, } from "@heroicons/react/24/outline"; import { type ModelDescription } from "core"; +import { Fragment } from "react"; import { ToolTip } from "../../components/gui/Tooltip"; +/** + * A component for selecting a model for a specific role + */ interface ModelRoleSelectorProps { models: ModelDescription[]; selectedModel: ModelDescription | null; @@ -38,56 +41,57 @@ const ModelRoleSelector = ({ {description} - - {({ open }) => ( -
- - {models.length === 0 ? ( - {`No ${displayName} models${["Chat", "Apply", "Edit"].includes(displayName) ? ". Using chat model" : ""}`} - ) : ( + + {models.length === 0 ? ( + + {["Chat", "Apply", "Edit"].includes(displayName) + ? "None (defaulting to Chat model)" + : "None"} + + ) : ( + + {({ open }) => ( +
+ {selectedModel?.title ?? `Select ${displayName} model`} - )} - {models.length ? (
- ) : null} -
+ - - - {models.map((option, idx) => ( - - - {option.title} - - - ))} - - -
- )} -
+ + + {models.map((option, idx) => ( + + + {option.title} + + + ))} + + +
+ )} +
+ )} ); }; diff --git a/gui/src/pages/gui/EmptyChatBody.tsx b/gui/src/pages/gui/EmptyChatBody.tsx index a81143b8d..dce70cdd5 100644 --- a/gui/src/pages/gui/EmptyChatBody.tsx +++ b/gui/src/pages/gui/EmptyChatBody.tsx @@ -25,9 +25,9 @@ export function EmptyChatBody({ } return ( -
- +
+
); } diff --git a/gui/src/redux/selectors/index.ts b/gui/src/redux/selectors/index.ts index 2097dbce8..3d46bf9ea 100644 --- a/gui/src/redux/selectors/index.ts +++ b/gui/src/redux/selectors/index.ts @@ -8,7 +8,7 @@ export const selectSlashCommandComboBoxInputs = createSelector( return ( slashCommands?.map((cmd) => { return { - title: `/${cmd.name}`, + title: `${cmd.name}`, description: cmd.description, type: "slashCommand" as ComboBoxItemType, };