feat: move .prompts into slash cmd

This commit is contained in:
Patrick Erichsen 2025-03-20 16:58:29 -07:00
parent a73123e35c
commit 1d1f705f7d
14 changed files with 153 additions and 152 deletions

View file

@ -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(

View file

@ -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(

View file

@ -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<ContextItem[]> {
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<ContextSubmenuItem[]> {
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;

View file

@ -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,

View file

@ -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";

View file

@ -20,13 +20,13 @@ export function ConversationStarterCard({
backgroundColor: vscInputBackground,
}}
>
<div className="flex items-start p-3">
<div className="flex items-center px-3 py-2">
<div className="mr-3 flex-shrink-0">
<ChatBubbleLeftIcon className="h-5 w-5 text-gray-400" />
<ChatBubbleLeftIcon className="text-lightgray h-5 w-5" />
</div>
<div className="flex flex-col">
<div className="font-medium text-gray-200">{command.name}</div>
<div className="text-sm text-gray-400">{command.description}</div>
<div className="font-medium">{command.name}</div>
<div className="text-lightgray text-sm">{command.description}</div>
</div>
</div>
</div>

View file

@ -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) => (
<ConversationStarterCard command={command} onClick={onClick} />
));
function handleToggleExpand() {
setIsExpanded(!isExpanded);
}
if (!filteredSlashCommands || filteredSlashCommands.length === 0) {
return null;
}
return (
<div className="flex flex-col items-center">
<h4 className="mb-2 w-full max-w-md self-start">Prompts</h4>
<div className="w-full max-w-md">
{displayedCommands.map((command, i) => (
<ConversationStarterCard
key={command.name + i}
command={command}
onClick={onClick}
/>
))}
</div>
{hasMoreCommands && (
<p
onClick={handleToggleExpand}
className="text-lightgray cursor-pointer self-start text-xs hover:underline"
>
{isExpanded
? "Show less"
: `Show ${numFilteredSlashCommands - NUM_CARDS_TO_RENDER_COLLAPSED} more...`}
</p>
)}
</div>
);
}

View file

@ -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,
);
}

View file

@ -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) => {
) : (
<ItemDiv className="item">No results</ItemDiv>
)}
{/* </CustomScrollbarDiv> */}
</>
)}
</ItemsDiv>

View file

@ -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";
}

View file

@ -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<ComboBoxItem[]>,
@ -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);
}

View file

@ -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}
</ToolTip>
</div>
<Listbox value={selectedModel?.title ?? null} onChange={handleSelect}>
{({ open }) => (
<div className="relative">
<Listbox.Button
className={`border-vsc-input-border bg-vsc-background ${!!models.length ? "hover:bg-vsc-input-background cursor-pointer" : ""} text-vsc-foreground relative m-0 flex w-full items-center justify-between rounded-md border border-solid px-2 py-1 text-left`}
>
{models.length === 0 ? (
<span className="text-lightgray italic">{`No ${displayName} models${["Chat", "Apply", "Edit"].includes(displayName) ? ". Using chat model" : ""}`}</span>
) : (
{models.length === 0 ? (
<span className="text-lightgray">
{["Chat", "Apply", "Edit"].includes(displayName)
? "None (defaulting to Chat model)"
: "None"}
</span>
) : (
<Listbox value={selectedModel?.title ?? null} onChange={handleSelect}>
{({ open }) => (
<div className="relative">
<Listbox.Button className="border-vsc-input-border bg-vsc-background hover:bg-vsc-input-background text-vsc-foreground relative m-0 flex w-full cursor-pointer items-center justify-between rounded-md border border-solid px-2 py-1 text-left">
<span className="lines lines-1">
{selectedModel?.title ?? `Select ${displayName} model`}
</span>
)}
{models.length ? (
<div className="pointer-events-none flex items-center">
<ChevronUpDownIcon
className="h-3.5 w-3.5"
aria-hidden="true"
/>
</div>
) : null}
</Listbox.Button>
</Listbox.Button>
<Transition
as={Fragment}
show={open}
enter="transition ease-out duration-100"
enterFrom="transform opacity-0 scale-95"
enterTo="transform opacity-100 scale-100"
leave="transition ease-in duration-75"
leaveFrom="transform opacity-100 scale-100"
leaveTo="transform opacity-0 scale-95"
>
<Listbox.Options className="bg-vsc-background max-h-80vh absolute z-[800] mt-0.5 w-full overflow-y-scroll rounded-sm p-0">
{models.map((option, idx) => (
<Listbox.Option
key={idx}
value={option.title}
className={`text-vsc-foreground hover:text-list-active-foreground flex cursor-pointer flex-row items-center gap-3 px-2 py-1 ${option?.title === selectedModel?.title ? "bg-list-active" : "bg-vsc-input-background"}`}
>
<span className="lines lines-1 relative flex h-5 items-center justify-between gap-3 pr-2 text-xs">
{option.title}
</span>
</Listbox.Option>
))}
</Listbox.Options>
</Transition>
</div>
)}
</Listbox>
<Transition
as={Fragment}
show={open}
enter="transition ease-out duration-100"
enterFrom="transform opacity-0 scale-95"
enterTo="transform opacity-100 scale-100"
leave="transition ease-in duration-75"
leaveFrom="transform opacity-100 scale-100"
leaveTo="transform opacity-0 scale-95"
>
<Listbox.Options className="bg-vsc-background max-h-80vh absolute z-[800] mt-0.5 w-full overflow-y-scroll rounded-sm p-0">
{models.map((option, idx) => (
<Listbox.Option
key={idx}
value={option.title}
className={`text-vsc-foreground hover:text-list-active-foreground flex cursor-pointer flex-row items-center gap-3 px-2 py-1 ${option?.title === selectedModel?.title ? "bg-list-active" : "bg-vsc-input-background"}`}
>
<span className="lines lines-1 relative flex h-5 items-center justify-between gap-3 pr-2 text-xs">
{option.title}
</span>
</Listbox.Option>
))}
</Listbox.Options>
</Transition>
</div>
)}
</Listbox>
)}
</>
);
};

View file

@ -25,9 +25,9 @@ export function EmptyChatBody({
}
return (
<div className="mx-2 mt-6">
<ConversationStarterCards />
<div className="mx-2 mt-2">
<ExploreHubCard />
<ConversationStarterCards />
</div>
);
}

View file

@ -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,
};