diff --git a/core/commands/slash/cmd.ts b/core/commands/slash/built-in-legacy/cmd.ts similarity index 91% rename from core/commands/slash/cmd.ts rename to core/commands/slash/built-in-legacy/cmd.ts index 7b93d2fa3..5cd96e365 100644 --- a/core/commands/slash/cmd.ts +++ b/core/commands/slash/built-in-legacy/cmd.ts @@ -1,6 +1,6 @@ -import { streamLines } from "../../diff/util.js"; -import { SlashCommand } from "../../index.js"; -import { removeQuotesAndEscapes } from "../../util/index.js"; +import { streamLines } from "../../../diff/util.js"; +import { SlashCommand } from "../../../index.js"; +import { removeQuotesAndEscapes } from "../../../util/index.js"; function commandIsPotentiallyDangerous(command: string) { return ( diff --git a/core/commands/slash/commit.ts b/core/commands/slash/built-in-legacy/commit.ts similarity index 89% rename from core/commands/slash/commit.ts rename to core/commands/slash/built-in-legacy/commit.ts index 55499b583..1f7e71343 100644 --- a/core/commands/slash/commit.ts +++ b/core/commands/slash/built-in-legacy/commit.ts @@ -1,5 +1,5 @@ -import { SlashCommand } from "../../index.js"; -import { renderChatMessage } from "../../util/messageContent.js"; +import { SlashCommand } from "../../../index.js"; +import { renderChatMessage } from "../../../util/messageContent.js"; const CommitMessageCommand: SlashCommand = { name: "commit", diff --git a/core/commands/slash/draftIssue.ts b/core/commands/slash/built-in-legacy/draftIssue.ts similarity index 91% rename from core/commands/slash/draftIssue.ts rename to core/commands/slash/built-in-legacy/draftIssue.ts index fba5d4cd3..9a1c5bdf9 100644 --- a/core/commands/slash/draftIssue.ts +++ b/core/commands/slash/built-in-legacy/draftIssue.ts @@ -1,6 +1,6 @@ -import { ChatMessage, SlashCommand } from "../../index.js"; -import { removeQuotesAndEscapes } from "../../util/index.js"; -import { renderChatMessage } from "../../util/messageContent.js"; +import { ChatMessage, SlashCommand } from "../../../index.js"; +import { removeQuotesAndEscapes } from "../../../util/index.js"; +import { renderChatMessage } from "../../../util/messageContent.js"; const PROMPT = ( input: string, diff --git a/core/commands/slash/http.ts b/core/commands/slash/built-in-legacy/http.ts similarity index 87% rename from core/commands/slash/http.ts rename to core/commands/slash/built-in-legacy/http.ts index e92c7c3f1..3141dcc11 100644 --- a/core/commands/slash/http.ts +++ b/core/commands/slash/built-in-legacy/http.ts @@ -1,6 +1,6 @@ import { streamResponse } from "@continuedev/fetch"; -import { SlashCommand } from "../../index.js"; -import { removeQuotesAndEscapes } from "../../util/index.js"; +import { SlashCommand } from "../../../index.js"; +import { removeQuotesAndEscapes } from "../../../util/index.js"; const HttpSlashCommand: SlashCommand = { name: "http", diff --git a/core/commands/slash/built-in-legacy/index.ts b/core/commands/slash/built-in-legacy/index.ts new file mode 100644 index 000000000..3e57f67a6 --- /dev/null +++ b/core/commands/slash/built-in-legacy/index.ts @@ -0,0 +1,37 @@ +import { + SlashCommand, + SlashCommandDescription, + SlashCommandWithSource, +} from "../../.."; +import GenerateTerminalCommand from "./cmd"; +import CommitMessageCommand from "./commit"; +import DraftIssueCommand from "./draftIssue"; +import HttpSlashCommand from "./http"; +import OnboardSlashCommand from "./onboard"; +import ReviewMessageCommand from "./review"; +import ShareSlashCommand from "./share"; + +const LegacyBuiltInSlashCommands: SlashCommand[] = [ + DraftIssueCommand, + ShareSlashCommand, + GenerateTerminalCommand, + HttpSlashCommand, + CommitMessageCommand, + ReviewMessageCommand, + OnboardSlashCommand, +]; + +export function getLegacyBuiltInSlashCommandFromDescription( + desc: SlashCommandDescription, +): SlashCommandWithSource | undefined { + const cmd = LegacyBuiltInSlashCommands.find((cmd) => cmd.name === desc.name); + if (!cmd) { + return undefined; + } + return { + ...cmd, + params: desc.params, + description: desc.description ?? cmd.description, + source: "built-in-legacy", + }; +} diff --git a/core/commands/slash/onboard.ts b/core/commands/slash/built-in-legacy/onboard.ts similarity index 96% rename from core/commands/slash/onboard.ts rename to core/commands/slash/built-in-legacy/onboard.ts index 545b75cc2..969ebc0c4 100644 --- a/core/commands/slash/onboard.ts +++ b/core/commands/slash/built-in-legacy/onboard.ts @@ -1,17 +1,17 @@ import ignore from "ignore"; -import type { FileType, IDE, SlashCommand } from "../.."; +import type { FileType, IDE, SlashCommand } from "../../.."; import { DEFAULT_IGNORE, getGlobalContinueIgArray, gitIgArrayFromFile, -} from "../../indexing/ignore"; -import { renderChatMessage } from "../../util/messageContent"; +} from "../../../indexing/ignore"; +import { renderChatMessage } from "../../../util/messageContent"; import { findUriInDirs, getUriPathBasename, joinPathsToUri, -} from "../../util/uri"; +} from "../../../util/uri"; const LANGUAGE_DEP_MGMT_FILENAMES = [ "package.json", // JavaScript (Node.js) diff --git a/core/commands/slash/review.ts b/core/commands/slash/built-in-legacy/review.ts similarity index 93% rename from core/commands/slash/review.ts rename to core/commands/slash/built-in-legacy/review.ts index 6190f5499..37c280b34 100644 --- a/core/commands/slash/review.ts +++ b/core/commands/slash/built-in-legacy/review.ts @@ -1,5 +1,5 @@ -import { ChatMessage, SlashCommand } from "../../index.js"; -import { renderChatMessage } from "../../util/messageContent.js"; +import { ChatMessage, SlashCommand } from "../../../index.js"; +import { renderChatMessage } from "../../../util/messageContent.js"; const prompt = ` Review the following code, focusing on Readability, Maintainability, Code Smells, Speed, and Memory Performance. Provide feedback with these guidelines: diff --git a/core/commands/slash/share.ts b/core/commands/slash/built-in-legacy/share.ts similarity index 92% rename from core/commands/slash/share.ts rename to core/commands/slash/built-in-legacy/share.ts index 01d5bea96..daddf8dff 100644 --- a/core/commands/slash/share.ts +++ b/core/commands/slash/built-in-legacy/share.ts @@ -3,10 +3,10 @@ import { homedir } from "node:os"; import { fileURLToPath, pathToFileURL } from "node:url"; import path from "path"; -import { languageForFilepath } from "../../autocomplete/constants/AutocompleteLanguageInfo.js"; -import { SlashCommand } from "../../index.js"; -import { renderChatMessage } from "../../util/messageContent.js"; -import { getContinueGlobalPath } from "../../util/paths.js"; +import { languageForFilepath } from "../../../autocomplete/constants/AutocompleteLanguageInfo.js"; +import { SlashCommand } from "../../../index.js"; +import { renderChatMessage } from "../../../util/messageContent.js"; +import { getContinueGlobalPath } from "../../../util/paths.js"; // If useful elsewhere, helper funcs should move to core/util/index.ts or similar function getOffsetDatetime(date: Date): Date { diff --git a/core/commands/index.ts b/core/commands/slash/customSlashCommand.ts similarity index 62% rename from core/commands/index.ts rename to core/commands/slash/customSlashCommand.ts index d87a3536f..29fb1144d 100644 --- a/core/commands/index.ts +++ b/core/commands/slash/customSlashCommand.ts @@ -1,14 +1,12 @@ -import { CustomCommand, SlashCommand, SlashCommandDescription } from "../"; -import { renderTemplatedString } from "../promptFiles/v1/renderTemplatedString"; -import { replaceSlashCommandWithPromptInChatHistory } from "../promptFiles/v1/updateChatHistory"; -import { renderPromptFileV2 } from "../promptFiles/v2/renderPromptFile"; -import { renderChatMessage } from "../util/messageContent"; +import { CustomCommand, SlashCommandWithSource } from "../.."; +import { renderTemplatedString } from "../../promptFiles/v1/renderTemplatedString"; +import { replaceSlashCommandWithPromptInChatHistory } from "../../promptFiles/v1/updateChatHistory"; +import { renderPromptFileV2 } from "../../promptFiles/v2/renderPromptFile"; +import { renderChatMessage } from "../../util/messageContent"; -import SlashCommands from "./slash"; - -export function slashFromCustomCommand( +export function convertCustomCommandToSlashCommand( customCommand: CustomCommand, -): SlashCommand { +): SlashCommandWithSource { const commandName = customCommand.name.startsWith("/") ? customCommand.name.substring(1) : customCommand.name; @@ -16,6 +14,7 @@ export function slashFromCustomCommand( name: commandName, description: customCommand.description ?? "", prompt: customCommand.prompt, + source: "json-custom-command", run: async function* ({ input, llm, @@ -45,8 +44,8 @@ export function slashFromCustomCommand( selectedCode, fetch, fullInput: input, - embeddingsProvider: config.modelsByRole.embed[0], - reranker: config.modelsByRole.rerank[0], + embeddingsProvider: config.selectedModelByRole.embed, + reranker: config.selectedModelByRole.rerank, }, ); @@ -72,17 +71,3 @@ export function slashFromCustomCommand( }, }; } - -export function slashCommandFromDescription( - desc: SlashCommandDescription, -): SlashCommand | undefined { - const cmd = SlashCommands.find((cmd) => cmd.name === desc.name); - if (!cmd) { - return undefined; - } - return { - ...cmd, - params: desc.params, - description: desc.description ?? cmd.description, - }; -} diff --git a/core/commands/slash/index.ts b/core/commands/slash/index.ts deleted file mode 100644 index 18008e251..000000000 --- a/core/commands/slash/index.ts +++ /dev/null @@ -1,17 +0,0 @@ -import GenerateTerminalCommand from "./cmd"; -import CommitMessageCommand from "./commit"; -import DraftIssueCommand from "./draftIssue"; -import HttpSlashCommand from "./http"; -import OnboardSlashCommand from "./onboard"; -import ReviewMessageCommand from "./review"; -import ShareSlashCommand from "./share"; - -export default [ - DraftIssueCommand, - ShareSlashCommand, - GenerateTerminalCommand, - HttpSlashCommand, - CommitMessageCommand, - ReviewMessageCommand, - OnboardSlashCommand, -]; diff --git a/core/commands/slash/mcp.ts b/core/commands/slash/mcpSlashCommand.ts similarity index 94% rename from core/commands/slash/mcp.ts rename to core/commands/slash/mcpSlashCommand.ts index 89af5c5c2..c97b3b383 100644 --- a/core/commands/slash/mcp.ts +++ b/core/commands/slash/mcpSlashCommand.ts @@ -1,17 +1,18 @@ import { Client } from "@modelcontextprotocol/sdk/client/index.js"; import { PromptMessage } from "@modelcontextprotocol/sdk/types.js"; -import { ChatMessage, SlashCommand } from "../../index.js"; +import { ChatMessage, SlashCommandWithSource } from "../../index.js"; import { renderChatMessage } from "../../util/messageContent.js"; export function constructMcpSlashCommand( client: Client, name: string, description?: string, args?: string[], -): SlashCommand { +): SlashCommandWithSource { return { name, description: description ?? "MCP Prompt", + source: "mcp-prompt", params: {}, run: async function* (context) { const argsObject: { [key: string]: string } = {}; diff --git a/core/promptFiles/v1/slashCommandFromPromptFile.ts b/core/commands/slash/promptFileSlashCommand.ts similarity index 80% rename from core/promptFiles/v1/slashCommandFromPromptFile.ts rename to core/commands/slash/promptFileSlashCommand.ts index 8e1478648..7c037b2cf 100644 --- a/core/promptFiles/v1/slashCommandFromPromptFile.ts +++ b/core/commands/slash/promptFileSlashCommand.ts @@ -1,13 +1,13 @@ -import { ContinueSDK, SlashCommand } from "../.."; +import { ContinueSDK, SlashCommandWithSource } from "../.."; import { getDiffsFromCache } from "../../autocomplete/snippets/gitDiffCache"; +import { parsePromptFileV1V2 } from "../../promptFiles/v2/parsePromptFileV1V2"; +import { renderPromptFileV2 } from "../../promptFiles/v2/renderPromptFile"; import { renderChatMessage } from "../../util/messageContent"; import { getLastNPathParts } from "../../util/uri"; -import { parsePromptFileV1V2 } from "../v2/parsePromptFileV1V2"; -import { renderPromptFileV2 } from "../v2/renderPromptFile"; -import { getContextProviderHelpers } from "./getContextProviderHelpers"; -import { renderTemplatedString } from "./renderTemplatedString"; -import { replaceSlashCommandWithPromptInChatHistory } from "./updateChatHistory"; +import { getContextProviderHelpers } from "../../promptFiles/v1/getContextProviderHelpers"; +import { renderTemplatedString } from "../../promptFiles/v1/renderTemplatedString"; +import { replaceSlashCommandWithPromptInChatHistory } from "../../promptFiles/v1/updateChatHistory"; export function extractName(preamble: { name?: string }, path: string): string { return preamble.name ?? getLastNPathParts(path, 1).split(".prompt")[0]; @@ -47,7 +47,7 @@ async function renderPromptV1( export function slashCommandFromPromptFileV1( path: string, content: string, -): SlashCommand | null { +): SlashCommandWithSource | null { const { name, description, systemMessage, prompt } = parsePromptFileV1V2( path, content, @@ -57,6 +57,7 @@ export function slashCommandFromPromptFileV1( name, description, prompt, + source: ".prompt-file", promptFile: path, run: async function* (context) { const [_, renderedPrompt] = await renderPromptFileV2(prompt, { diff --git a/core/config/load.ts b/core/config/load.ts index fe0c4de61..79bb66e6a 100644 --- a/core/config/load.ts +++ b/core/config/load.ts @@ -32,10 +32,9 @@ import { SerializedContinueConfig, SlashCommand, } from ".."; -import { - slashCommandFromDescription, - slashFromCustomCommand, -} from "../commands/index"; +import { getLegacyBuiltInSlashCommandFromDescription } from "../commands/slash/built-in-legacy"; +import { convertCustomCommandToSlashCommand } from "../commands/slash/customSlashCommand"; +import { slashCommandFromPromptFileV1 } from "../commands/slash/promptFileSlashCommand"; import { MCPManagerSingleton } from "../context/mcp/MCPManagerSingleton"; import CodebaseContextProvider from "../context/providers/CodebaseContextProvider"; import ContinueProxyContextProvider from "../context/providers/ContinueProxyContextProvider"; @@ -48,7 +47,6 @@ import { LLMClasses, llmFromDescription } from "../llm/llms"; import CustomLLMClass from "../llm/llms/CustomLLM"; import { LLMReranker } from "../llm/llms/llm"; import TransformersJsEmbeddingsProvider from "../llm/llms/TransformersJsEmbeddingsProvider"; -import { slashCommandFromPromptFileV1 } from "../promptFiles/v1/slashCommandFromPromptFile"; import { getAllPromptFiles } from "../promptFiles/v2/getPromptFiles"; import { copyOf } from "../util"; import { GlobalContext } from "../util/GlobalContext"; @@ -176,13 +174,13 @@ async function serializedToIntermediateConfig( // DEPRECATED - load custom slash commands const slashCommands: SlashCommand[] = []; for (const command of initial.slashCommands || []) { - const newCommand = slashCommandFromDescription(command); + const newCommand = getLegacyBuiltInSlashCommandFromDescription(command); if (newCommand) { slashCommands.push(newCommand); } } for (const command of initial.customCommands || []) { - slashCommands.push(slashFromCustomCommand(command)); + slashCommands.push(convertCustomCommandToSlashCommand(command)); } // DEPRECATED - load slash commands from v1 prompt files @@ -529,7 +527,7 @@ async function intermediateToFinalConfig({ contextProviders, tools: [...baseToolDefinitions], mcpServerStatuses: [], - slashCommands: config.slashCommands ?? [], + slashCommands: [], modelsByRole: { chat: models, edit: models, @@ -551,6 +549,17 @@ async function intermediateToFinalConfig({ rules: [], }; + for (const cmd of config.slashCommands ?? []) { + if ("source" in cmd) { + continueConfig.slashCommands.push(cmd); + } else { + continueConfig.slashCommands.push({ + ...cmd, + source: "config-ts-slash-command", + }); + } + } + if (config.systemMessage) { continueConfig.rules.unshift({ rule: config.systemMessage, @@ -651,9 +660,7 @@ async function finalToBrowserConfig( return { allowAnonymousTelemetry: final.allowAnonymousTelemetry, completionOptions: final.completionOptions, - slashCommands: final.slashCommands?.map( - ({ run, ...slashCommandDescription }) => slashCommandDescription, - ), + slashCommands: final.slashCommands?.map(({ run, ...rest }) => rest), contextProviders: final.contextProviders?.map((c) => c.description), disableIndexing: final.disableIndexing, disableSessionTitles: final.disableSessionTitles, diff --git a/core/config/profile/doLoadConfig.ts b/core/config/profile/doLoadConfig.ts index 7685546c9..90369b57a 100644 --- a/core/config/profile/doLoadConfig.ts +++ b/core/config/profile/doLoadConfig.ts @@ -18,7 +18,7 @@ import { SerializedContinueConfig, Tool, } from "../../"; -import { constructMcpSlashCommand } from "../../commands/slash/mcp"; +import { constructMcpSlashCommand } from "../../commands/slash/mcpSlashCommand"; import { MCPManagerSingleton } from "../../context/mcp/MCPManagerSingleton"; import MCPContextProvider from "../../context/providers/MCPContextProvider"; import RulesContextProvider from "../../context/providers/RulesContextProvider"; diff --git a/core/config/yaml/loadYaml.ts b/core/config/yaml/loadYaml.ts index 0c6436c38..539e18ad1 100644 --- a/core/config/yaml/loadYaml.ts +++ b/core/config/yaml/loadYaml.ts @@ -25,7 +25,7 @@ import { ILLMLogger, RuleWithSource, } from "../.."; -import { slashFromCustomCommand } from "../../commands"; +import { slashCommandFromPromptFileV1 } from "../../commands/slash/promptFileSlashCommand"; import { MCPManagerSingleton } from "../../context/mcp/MCPManagerSingleton"; import CodebaseContextProvider from "../../context/providers/CodebaseContextProvider"; import DocsContextProvider from "../../context/providers/DocsContextProvider"; @@ -33,11 +33,11 @@ import FileContextProvider from "../../context/providers/FileContextProvider"; import { contextProviderClassFromName } from "../../context/providers/index"; import { ControlPlaneClient } from "../../control-plane/client"; import TransformersJsEmbeddingsProvider from "../../llm/llms/TransformersJsEmbeddingsProvider"; -import { slashCommandFromPromptFileV1 } from "../../promptFiles/v1/slashCommandFromPromptFile"; import { getAllPromptFiles } from "../../promptFiles/v2/getPromptFiles"; import { GlobalContext } from "../../util/GlobalContext"; import { modifyAnyConfigWithSharedConfig } from "../sharedConfig"; +import { convertCustomCommandToSlashCommand } from "../../commands/slash/customSlashCommand"; import { getControlPlaneEnvSync } from "../../control-plane/env"; import { baseToolDefinitions } from "../../tools"; import { getCleanUriPath } from "../../util/uri"; @@ -286,7 +286,7 @@ async function configYamlToContinueConfig(options: { config.prompts?.forEach((prompt) => { try { - const slashCommand = slashFromCustomCommand(prompt); + const slashCommand = convertCustomCommandToSlashCommand(prompt); continueConfig.slashCommands?.push(slashCommand); } catch (e) { localErrors.push({ diff --git a/core/index.d.ts b/core/index.d.ts index 047c468d8..d3c96f8de 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -836,15 +836,38 @@ export interface ContinueSDK { abortController: AbortController; } -export interface SlashCommand { +/* Be careful changing SlashCommand or SlashCommandDescription, config.ts can break */ +export interface SlashCommandDescription { name: string; description: string; prompt?: string; params?: { [key: string]: any }; - promptFile?: string; +} + +export interface SlashCommand extends SlashCommandDescription { run: (sdk: ContinueSDK) => AsyncGenerator; } +export type SlashCommandSource = + | "built-in-legacy" + | "built-in" + | "json-custom-command" + | "config-ts-slash-command" + | "yaml-prompt-block" + | "mcp-prompt" + | ".prompt-file" + | "invokable-rule"; + +export interface SlashCommandDescWithSource extends SlashCommandDescription { + source: SlashCommandSource; + promptFile?: string; +} + +export interface SlashCommandWithSource extends SlashCommand { + source: SlashCommandSource; + promptFile?: string; +} + // Config export type StepName = @@ -945,8 +968,6 @@ export interface ContextProviderWithParams { params: { [key: string]: any }; } -export type SlashCommandDescription = Omit; - export interface CustomCommand { name: string; prompt: string; @@ -1442,7 +1463,7 @@ export interface Config { /** Request options that will be applied to all models and context providers */ requestOptions?: RequestOptions; /** The list of slash commands that will be available in the sidebar */ - slashCommands?: SlashCommand[]; + slashCommands?: (SlashCommand | SlashCommandWithSource)[]; /** Each entry in this array will originally be a ContextProviderWithParams, the same object from your config.json, but you may add CustomContextProviders. * A CustomContextProvider requires you only to define a title and getContextItems function. When you type '@title ', Continue will call `getContextItems(query)`. */ @@ -1479,7 +1500,7 @@ export interface ContinueConfig { // systemMessage?: string; completionOptions?: BaseCompletionOptions; requestOptions?: RequestOptions; - slashCommands: SlashCommand[]; + slashCommands: SlashCommandWithSource[]; contextProviders: IContextProvider[]; disableSessionTitles?: boolean; disableIndexing?: boolean; @@ -1502,7 +1523,7 @@ export interface BrowserSerializedContinueConfig { // systemMessage?: string; completionOptions?: BaseCompletionOptions; requestOptions?: RequestOptions; - slashCommands: SlashCommandDescription[]; + slashCommands: SlashCommandDescWithSource[]; contextProviders: ContextProviderDescription[]; disableIndexing?: boolean; disableSessionTitles?: boolean; diff --git a/core/protocol/core.ts b/core/protocol/core.ts index dfc0d87d6..22e0c0717 100644 --- a/core/protocol/core.ts +++ b/core/protocol/core.ts @@ -29,7 +29,7 @@ import { Session, SessionMetadata, SiteIndexingConfig, - SlashCommandDescription, + SlashCommandDescWithSource, StreamDiffLinesPayload, ToolCall, } from "../"; @@ -141,7 +141,7 @@ export type ToCoreFromIdeOrWebviewProtocol = { completionOptions: LLMFullCompletionOptions; title: string; legacySlashCommandData?: { - command: SlashCommandDescription; + command: SlashCommandDescWithSource; input: string; contextItems: ContextItemWithId[]; historyIndex: number; diff --git a/gui/src/components/ConversationStarters/ConversationStarterCard.tsx b/gui/src/components/ConversationStarters/ConversationStarterCard.tsx index 29ff81833..64705d99b 100644 --- a/gui/src/components/ConversationStarters/ConversationStarterCard.tsx +++ b/gui/src/components/ConversationStarters/ConversationStarterCard.tsx @@ -1,9 +1,9 @@ import { ChatBubbleLeftIcon } from "@heroicons/react/24/outline"; -import { SlashCommandDescription } from "core"; +import { SlashCommandDescWithSource } from "core"; interface ConversationStarterCardProps { - command: SlashCommandDescription; - onClick: (command: SlashCommandDescription) => void; + command: SlashCommandDescWithSource; + onClick: (command: SlashCommandDescWithSource) => void; } export function ConversationStarterCard({ diff --git a/gui/src/components/ConversationStarters/ConversationStarterCards.tsx b/gui/src/components/ConversationStarters/ConversationStarterCards.tsx index 776c0721b..ce7907a67 100644 --- a/gui/src/components/ConversationStarters/ConversationStarterCards.tsx +++ b/gui/src/components/ConversationStarters/ConversationStarterCards.tsx @@ -1,4 +1,4 @@ -import { SlashCommandDescription } from "core"; +import { SlashCommandDescWithSource } from "core"; import { useState } from "react"; import { useBookmarkedSlashCommands } from "../../hooks/useBookmarkedSlashCommands"; import { useAppDispatch, useAppSelector } from "../../redux/hooks"; @@ -23,7 +23,7 @@ export function ConversationStarterCards() { isCommandBookmarked(command.name), ); - function onClick(command: SlashCommandDescription) { + function onClick(command: SlashCommandDescWithSource) { mainEditor?.commands.insertPrompt(command); } diff --git a/gui/src/components/ConversationStarters/__tests__/utils.test.ts b/gui/src/components/ConversationStarters/__tests__/utils.test.ts index 3e7050985..047606ba9 100644 --- a/gui/src/components/ConversationStarters/__tests__/utils.test.ts +++ b/gui/src/components/ConversationStarters/__tests__/utils.test.ts @@ -1,27 +1,31 @@ -import { SlashCommandDescription } from "core"; +import { SlashCommandDescWithSource } from "core"; import { sortCommandsByBookmarkStatus } from "../utils"; describe("sortCommandsByBookmarkStatus", () => { - const mockCommands: SlashCommandDescription[] = [ + const mockCommands: SlashCommandDescWithSource[] = [ { name: "command1", description: "First command", prompt: "This is command 1", + source: "built-in", }, { name: "command2", description: "Second command", prompt: "This is command 2", + source: "built-in", }, { name: "command3", description: "Third command", prompt: "This is command 3", + source: "built-in", }, { name: "command4", description: "Fourth command", prompt: "This is command 4", + source: "built-in", }, ]; diff --git a/gui/src/components/ConversationStarters/utils.ts b/gui/src/components/ConversationStarters/utils.ts index 1f9ef09ae..e10b79237 100644 --- a/gui/src/components/ConversationStarters/utils.ts +++ b/gui/src/components/ConversationStarters/utils.ts @@ -1,4 +1,4 @@ -import { SlashCommandDescription } from "core"; +import { SlashCommandDescWithSource } from "core"; import {} from "core/config/default"; /** @@ -8,9 +8,9 @@ import {} from "core/config/default"; * @returns A new sorted array with bookmarked commands first */ export function sortCommandsByBookmarkStatus( - commands: SlashCommandDescription[], + commands: SlashCommandDescWithSource[], bookmarkedCommands: string[], -): SlashCommandDescription[] { +): SlashCommandDescWithSource[] { return [...commands].sort((a, b) => { const aIsBookmarked = bookmarkedCommands.includes(a.name); const bIsBookmarked = bookmarkedCommands.includes(b.name); diff --git a/gui/src/components/mainInput/Lump/sections/PromptsSection.tsx b/gui/src/components/mainInput/Lump/sections/PromptsSection.tsx index d7fd74eee..52e6a5d6f 100644 --- a/gui/src/components/mainInput/Lump/sections/PromptsSection.tsx +++ b/gui/src/components/mainInput/Lump/sections/PromptsSection.tsx @@ -4,7 +4,7 @@ import { PencilIcon, } from "@heroicons/react/24/outline"; import { BookmarkIcon as BookmarkSolid } from "@heroicons/react/24/solid"; -import { SlashCommandDescription } from "core"; +import { SlashCommandDescWithSource } from "core"; import { useContext, useMemo } from "react"; import { useAuth } from "../../../../context/Auth"; import { IdeMessengerContext } from "../../../../context/IdeMessenger"; @@ -15,7 +15,7 @@ import { useMainEditor } from "../../TipTapEditor"; import { useLump } from "../LumpContext"; import { ExploreBlocksButton } from "./ExploreBlocksButton"; -type PromptWithSlug = SlashCommandDescription & { slug?: string }; +type PromptWithSlug = SlashCommandDescWithSource & { slug?: string }; interface PromptRowProps { prompt: PromptWithSlug; diff --git a/gui/src/components/mainInput/TipTapEditor/extensions/Prompt/PromptBlock.ts b/gui/src/components/mainInput/TipTapEditor/extensions/Prompt/PromptBlock.ts index 8f5c27780..839182303 100644 --- a/gui/src/components/mainInput/TipTapEditor/extensions/Prompt/PromptBlock.ts +++ b/gui/src/components/mainInput/TipTapEditor/extensions/Prompt/PromptBlock.ts @@ -1,7 +1,7 @@ import { mergeAttributes, Node } from "@tiptap/core"; import { Node as ProseMirrorNode } from "@tiptap/pm/model"; import { ReactNodeViewRenderer } from "@tiptap/react"; -import { ContextItemWithId, SlashCommandDescription } from "core"; +import { ContextItemWithId, SlashCommandDescWithSource } from "core"; import { MAIN_EDITOR_INPUT_ID } from "../../../../../pages/gui/Chat"; import { PromptBlockPreview } from "./PromptBlockPreview"; @@ -20,7 +20,7 @@ declare module "@tiptap/core" { /** * Insert a prompt block into the editor */ - insertPrompt: (item: SlashCommandDescription) => ReturnType; + insertPrompt: (item: SlashCommandDescWithSource) => ReturnType; /** * Clear all prompt blocks from the editor @@ -76,7 +76,7 @@ export const PromptBlock = Node.create({ addCommands() { return { insertPrompt: - (prompt: SlashCommandDescription) => + (prompt: SlashCommandDescWithSource) => ({ chain }) => { const item: ContextItemWithId = { content: prompt.prompt ?? "", diff --git a/gui/src/components/mainInput/TipTapEditor/utils/resolveEditorContent.ts b/gui/src/components/mainInput/TipTapEditor/utils/resolveEditorContent.ts index 958ea2331..25b251ff1 100644 --- a/gui/src/components/mainInput/TipTapEditor/utils/resolveEditorContent.ts +++ b/gui/src/components/mainInput/TipTapEditor/utils/resolveEditorContent.ts @@ -10,7 +10,7 @@ import { MessageContent, MessagePart, RangeInFile, - SlashCommandDescription, + SlashCommandDescWithSource, TextMessagePart, } from "core"; import { ctxItemToRifWithContents } from "core/commands/util"; @@ -32,7 +32,7 @@ interface ResolveEditorContentInput { modifiers: InputModifiers; ideMessenger: IIdeMessenger; defaultContextProviders: DefaultContextProvider[]; - availableSlashCommands: SlashCommandDescription[]; + availableSlashCommands: SlashCommandDescWithSource[]; dispatch: Dispatch; } @@ -42,7 +42,7 @@ type ResolveEditorContentOutput = [ MessageContent, ( | { - command: SlashCommandDescription; + command: SlashCommandDescWithSource; input: string; } | undefined @@ -184,9 +184,9 @@ function processEditorContent(editorState: JSONContent) { */ function processSlashCommand( slashCommandName: string | undefined, - availableSlashCommands: SlashCommandDescription[], + availableSlashCommands: SlashCommandDescWithSource[], parts: MessagePart[], -): { command: SlashCommandDescription; input: string } | undefined { +): { command: SlashCommandDescWithSource; input: string } | undefined { if (!slashCommandName) return; const command = availableSlashCommands.find( diff --git a/gui/src/hooks/useBookmarkedSlashCommands.ts b/gui/src/hooks/useBookmarkedSlashCommands.ts index dcd58f9f7..0301c6cc6 100644 --- a/gui/src/hooks/useBookmarkedSlashCommands.ts +++ b/gui/src/hooks/useBookmarkedSlashCommands.ts @@ -1,4 +1,4 @@ -import { SlashCommandDescription } from "core"; +import { SlashCommandDescWithSource } from "core"; import { usePostHog } from "posthog-js/react"; import { useAppDispatch, useAppSelector } from "../redux/hooks"; @@ -17,7 +17,7 @@ export function useBookmarkedSlashCommands() { return bookmarkedCommands.includes(commandName); }; - const toggleBookmark = (command: SlashCommandDescription) => { + const toggleBookmark = (command: SlashCommandDescWithSource) => { const isBookmarked = isCommandBookmarked(command.name); posthog.capture("toggle_bookmarked_slash_command", { diff --git a/gui/src/redux/slices/configSlice.ts b/gui/src/redux/slices/configSlice.ts index b26d596c8..e59f730d0 100644 --- a/gui/src/redux/slices/configSlice.ts +++ b/gui/src/redux/slices/configSlice.ts @@ -9,16 +9,7 @@ export type ConfigState = { }; export const EMPTY_CONFIG: BrowserSerializedContinueConfig = { - slashCommands: [ - { - name: "share", - description: "Export the current chat session to markdown", - }, - { - name: "cmd", - description: "Generate a shell command", - }, - ], + slashCommands: [], contextProviders: [], tools: [], mcpServerStatuses: [], diff --git a/gui/src/redux/slices/profilesSlice.ts b/gui/src/redux/slices/profilesSlice.ts index 6f3144736..16d0498ae 100644 --- a/gui/src/redux/slices/profilesSlice.ts +++ b/gui/src/redux/slices/profilesSlice.ts @@ -1,5 +1,5 @@ import { createSlice, PayloadAction } from "@reduxjs/toolkit"; -import { SlashCommandDescription } from "core"; +import { SlashCommandDescWithSource } from "core"; import { SerializedOrgWithProfiles } from "core/config/ProfileLifecycleManager"; const DEFAULT_SLASH_COMMANDS_BOOKMARKS_COUNT = 5; @@ -81,7 +81,7 @@ export const profilesSlice = createSlice({ state, action: PayloadAction<{ profileId: string; - defaultSlashCommands?: SlashCommandDescription[]; + defaultSlashCommands?: SlashCommandDescWithSource[]; }>, ) => { const { profileId, defaultSlashCommands = [] } = action.payload; diff --git a/gui/src/redux/thunks/gatherContext.ts b/gui/src/redux/thunks/gatherContext.ts index 8b72b5f88..a17a05813 100644 --- a/gui/src/redux/thunks/gatherContext.ts +++ b/gui/src/redux/thunks/gatherContext.ts @@ -17,7 +17,7 @@ export const gatherContext = createAsyncThunk< selectedContextItems: ContextItemWithId[]; selectedCode: RangeInFile[]; content: MessageContent; - slashCommandWithInput: + legacyCommandWithInput: | { command: SlashCommandDescription; input: string; @@ -50,7 +50,7 @@ export const gatherContext = createAsyncThunk< } // Resolve context providers and construct new history - let [selectedContextItems, selectedCode, content, slashCommandWithInput] = + let [selectedContextItems, selectedCode, content, legacyCommandWithInput] = await resolveEditorContent({ editorState, modifiers, @@ -118,7 +118,7 @@ export const gatherContext = createAsyncThunk< selectedContextItems, selectedCode, content, - slashCommandWithInput, + legacyCommandWithInput, }; }, ); diff --git a/gui/src/redux/thunks/streamResponse.ts b/gui/src/redux/thunks/streamResponse.ts index caeded723..7f90de52a 100644 --- a/gui/src/redux/thunks/streamResponse.ts +++ b/gui/src/redux/thunks/streamResponse.ts @@ -60,7 +60,7 @@ export const streamResponseThunk = createAsyncThunk< selectedContextItems, selectedCode, content, - slashCommandWithInput, + legacyCommandWithInput, } = unwrapResult(result); // symbols for both context items AND selected codeblocks @@ -133,9 +133,9 @@ export const streamResponseThunk = createAsyncThunk< }); posthog.capture("userInput", {}); - if (slashCommandWithInput) { + if (legacyCommandWithInput) { posthog.capture("step run", { - step_name: slashCommandWithInput.command.name, + step_name: legacyCommandWithInput.command.name, params: {}, }); } @@ -144,12 +144,12 @@ export const streamResponseThunk = createAsyncThunk< await dispatch( streamNormalInput({ messages, - legacySlashCommandData: slashCommandWithInput + legacySlashCommandData: legacyCommandWithInput ? { - command: slashCommandWithInput.command, + command: legacyCommandWithInput.command, contextItems: selectedContextItems, historyIndex: inputIndex, - input: slashCommandWithInput.input, + input: legacyCommandWithInput.input, selectedCode, } : undefined,