diff --git a/.gitignore b/.gitignore index 763b96238..c2b943935 100644 --- a/.gitignore +++ b/.gitignore @@ -157,6 +157,7 @@ Icon? notes.md manual-testing-sandbox/.idea/** +manual-testing-sandbox/.continue/** extensions/intellij/.idea/** **/.idea/workspace.xml diff --git a/binary/package-lock.json b/binary/package-lock.json index c823d785e..5ce095e37 100644 --- a/binary/package-lock.json +++ b/binary/package-lock.json @@ -51,7 +51,7 @@ "@continuedev/config-yaml": "^1.0.63", "@continuedev/fetch": "^1.0.4", "@continuedev/llm-info": "^1.0.2", - "@continuedev/openai-adapters": "^1.0.10", + "@continuedev/openai-adapters": "^1.0.18", "@modelcontextprotocol/sdk": "^1.5.0", "@mozilla/readability": "^0.5.0", "@octokit/rest": "^20.1.1", diff --git a/core/commands/index.ts b/core/commands/index.ts index 72719d832..486eaccf2 100644 --- a/core/commands/index.ts +++ b/core/commands/index.ts @@ -10,6 +10,7 @@ export function slashFromCustomCommand( return { name: customCommand.name, description: customCommand.description ?? "", + prompt: customCommand.prompt, run: async function* ({ input, llm, history, ide, completionOptions }) { // Remove slash command prefix from input let userInput = input; diff --git a/core/commands/util.ts b/core/commands/util.ts index 1cd493fad..5a0ea32e4 100644 --- a/core/commands/util.ts +++ b/core/commands/util.ts @@ -1,6 +1,7 @@ +import { v4 as uuidv4 } from "uuid"; + import { ContextItemWithId, RangeInFileWithContents } from "../"; import { findUriInDirs, getUriPathBasename } from "../util/uri"; -import { v4 as uuidv4 } from "uuid"; export function rifWithContentsToContextItem( rif: RangeInFileWithContents, diff --git a/core/config/load.ts b/core/config/load.ts index 6597b86ae..4c98e7728 100644 --- a/core/config/load.ts +++ b/core/config/load.ts @@ -44,7 +44,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"; @@ -400,8 +399,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( @@ -633,11 +630,9 @@ async function finalToBrowserConfig( models: final.models.map(llmToSerializedModelDescription), systemMessage: final.systemMessage, completionOptions: final.completionOptions, - slashCommands: final.slashCommands?.map((s) => ({ - name: s.name, - description: s.description, - params: s.params, // TODO: is this why params aren't referenced properly by slash commands? - })), + slashCommands: final.slashCommands?.map( + ({ run, ...slashCommandDescription }) => slashCommandDescription, + ), contextProviders: final.contextProviders?.map((c) => c.description), disableIndexing: final.disableIndexing, disableSessionTitles: final.disableSessionTitles, diff --git a/core/config/profile/ControlPlaneProfileLoader.ts b/core/config/profile/ControlPlaneProfileLoader.ts index 8d12e771f..09a1846a4 100644 --- a/core/config/profile/ControlPlaneProfileLoader.ts +++ b/core/config/profile/ControlPlaneProfileLoader.ts @@ -2,6 +2,7 @@ import { ConfigJson } from "@continuedev/config-types"; import { ConfigResult } from "@continuedev/config-yaml"; import { ControlPlaneClient } from "../../control-plane/client.js"; +import { PRODUCTION_ENV } from "../../control-plane/env.js"; import { ContinueConfig, IDE, @@ -10,7 +11,6 @@ import { } from "../../index.js"; import { ProfileDescription } from "../ProfileLifecycleManager.js"; -import { PRODUCTION_ENV } from "../../control-plane/env.js"; import doLoadConfig from "./doLoadConfig.js"; import { IProfileLoader } from "./IProfileLoader.js"; diff --git a/core/config/profile/PlatformProfileLoader.ts b/core/config/profile/PlatformProfileLoader.ts index 49fd2d0c1..1eddedb6a 100644 --- a/core/config/profile/PlatformProfileLoader.ts +++ b/core/config/profile/PlatformProfileLoader.ts @@ -1,11 +1,10 @@ import { AssistantUnrolled, ConfigResult } from "@continuedev/config-yaml"; import { ControlPlaneClient } from "../../control-plane/client.js"; +import { getControlPlaneEnv } from "../../control-plane/env.js"; import { ContinueConfig, IDE, IdeSettings } from "../../index.js"; - import { ProfileDescription } from "../ProfileLifecycleManager.js"; -import { getControlPlaneEnv } from "../../control-plane/env.js"; import doLoadConfig from "./doLoadConfig.js"; import { IProfileLoader } from "./IProfileLoader.js"; diff --git a/core/config/profile/doLoadConfig.ts b/core/config/profile/doLoadConfig.ts index 53c35528d..28371a220 100644 --- a/core/config/profile/doLoadConfig.ts +++ b/core/config/profile/doLoadConfig.ts @@ -6,6 +6,7 @@ import { ConfigValidationError, ModelRole, } from "@continuedev/config-yaml"; + import { ContinueConfig, ContinueRcJson, @@ -31,6 +32,7 @@ import { loadContinueConfigFromJson } from "../load"; import { migrateJsonSharedConfig } from "../migrateSharedConfig"; import { rectifySelectedModelsFromGlobalContext } from "../selectedModels"; import { loadContinueConfigFromYaml } from "../yaml/loadYaml"; + import { PlatformConfigMetadata } from "./PlatformProfileLoader"; export default async function doLoadConfig( diff --git a/core/config/validation.ts b/core/config/validation.ts index d28bb7809..a3bc40099 100644 --- a/core/config/validation.ts +++ b/core/config/validation.ts @@ -1,4 +1,5 @@ import { ConfigValidationError } from "@continuedev/config-yaml"; + import { ModelDescription, SerializedContinueConfig } from "../"; import { Telemetry } from "../util/posthog"; diff --git a/core/config/yaml/loadYaml.ts b/core/config/yaml/loadYaml.ts index 32d016010..1ca54337b 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"; @@ -335,7 +334,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/index.d.ts b/core/index.d.ts index f73fec9ce..5de05fbf8 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -766,6 +766,7 @@ export interface ContinueSDK { export interface SlashCommand { name: string; description: string; + prompt?: string; params?: { [key: string]: any }; run: (sdk: ContinueSDK) => AsyncGenerator; } @@ -869,11 +870,7 @@ export interface ContextProviderWithParams { params: { [key: string]: any }; } -export interface SlashCommandDescription { - name: string; - description: string; - params?: { [key: string]: any }; -} +export type SlashCommandDescription = Omit; export interface CustomCommand { name: string; diff --git a/core/promptFiles/v1/slashCommandFromPromptFile.ts b/core/promptFiles/v1/slashCommandFromPromptFile.ts index b6cbd05fb..b9d4e88c8 100644 --- a/core/promptFiles/v1/slashCommandFromPromptFile.ts +++ b/core/promptFiles/v1/slashCommandFromPromptFile.ts @@ -53,16 +53,15 @@ 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, description, + prompt, run: async function* (context) { const originalSystemMessage = context.llm.systemMessage; context.llm.systemMessage = systemMessage; diff --git a/core/promptFiles/v2/parse.ts b/core/promptFiles/v2/parse.ts index 95e60230e..ec543cbdc 100644 --- a/core/promptFiles/v2/parse.ts +++ b/core/promptFiles/v2/parse.ts @@ -1,4 +1,5 @@ import * as YAML from "yaml"; + import { getLastNPathParts } from "../../util/uri"; export function extractName(preamble: { name?: string }, path: string): string { diff --git a/core/promptFiles/v2/parsePromptFileV1V2.ts b/core/promptFiles/v2/parsePromptFileV1V2.ts index 11e2b10be..a883c5e7b 100644 --- a/core/promptFiles/v2/parsePromptFileV1V2.ts +++ b/core/promptFiles/v2/parsePromptFileV1V2.ts @@ -1,4 +1,5 @@ import * as YAML from "yaml"; + import { getLastNPathParts } from "../../util/uri"; export function parsePromptFileV1V2(path: string, content: string) { diff --git a/core/promptFiles/v2/renderPromptFile.ts b/core/promptFiles/v2/renderPromptFile.ts index 4f6bb1534..1f08011a8 100644 --- a/core/promptFiles/v2/renderPromptFile.ts +++ b/core/promptFiles/v2/renderPromptFile.ts @@ -3,6 +3,7 @@ import { contextProviderClassFromName } from "../../context/providers"; import URLContextProvider from "../../context/providers/URLContextProvider"; import { resolveRelativePathInDir } from "../../util/ideUtils"; import { getUriPathBasename } from "../../util/uri"; + import { getPreambleAndBody } from "./parse"; async function resolveAttachment( diff --git a/core/protocol/core.ts b/core/protocol/core.ts index 09d5ba5a9..d0d12e2ec 100644 --- a/core/protocol/core.ts +++ b/core/protocol/core.ts @@ -1,11 +1,15 @@ -import { ConfigResult, ModelRole } from "@continuedev/config-yaml"; +import { + ConfigResult, + DevDataLogEvent, + ModelRole, +} from "@continuedev/config-yaml"; import { AutocompleteInput } from "../autocomplete/util/types"; import { ProfileDescription } from "../config/ConfigHandler"; import { OrganizationDescription } from "../config/ProfileLifecycleManager"; import { SharedConfigSchema } from "../config/sharedConfig"; +import { GlobalContextModelSelections } from "../util/GlobalContext"; -import { DevDataLogEvent } from "@continuedev/config-yaml"; import type { BrowserSerializedContinueConfig, ChatMessage, @@ -29,7 +33,6 @@ import type { SlashCommandDescription, ToolCall, } from "../"; -import { GlobalContextModelSelections } from "../util/GlobalContext"; export type OnboardingModes = "Local" | "Best" | "Custom" | "Quickstart"; 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/docs/docs/customize/deep-dives/prompt-files.md b/docs/docs/customize/deep-dives/prompt-files.md index f5c834c17..68995746f 100644 --- a/docs/docs/customize/deep-dives/prompt-files.md +++ b/docs/docs/customize/deep-dives/prompt-files.md @@ -2,11 +2,11 @@ title: Prompt files --- -Prompt files provide a convenient way to standardize common patterns and share a collection of LLM prompts with your team. They make it easy to build and use these prompts. +Prompt files allow you to build and use local prompts, and provide a convenient way to test and iterate on prompts before publishing them to the Hub. -On the [hub](../../hub/introduction.md), prompt files are stored within [prompt blocks](../../hub/blocks/block-types.md#prompts), which show up as [slash commands](../slash-commands.mdx) in Chat. Visit the hub to [explore prompts](https://hub.continue.dev/explore/prompts) or [create your own](https://hub.continue.dev/new?type=block&blockType=rules). - -Prompt files can also be stored within your project's root directory as `.prompt` files. See below. +:::info +Visit the Hub to [explore prompts](https://hub.continue.dev/explore/prompts) or [create your own](https://hub.continue.dev/new?type=block&blockType=prompts) +::: ## Quick start @@ -25,7 +25,7 @@ Attached is a summary of the current Ruby on Rails application, including the @G Now to use this prompt, you can highlight code and use cmd/ctrl + L to select it in the Continue sidebar. -Then, type "@", select "Prompt files", and choose the one called "Rails Project". You can now ask any question as usual and the LLM will have the information from your .prompt file. +Then, type / and choose the "Rails Project" prompt. You can now ask any question as usual and the LLM will have the information from your .prompt file. ## Format diff --git a/docs/docs/hub/blocks/block-types.md b/docs/docs/hub/blocks/block-types.md index 51ec97b10..9091184d4 100644 --- a/docs/docs/hub/blocks/block-types.md +++ b/docs/docs/hub/blocks/block-types.md @@ -43,8 +43,8 @@ Prompts blocks are pre-written, reusable prompts that can be referenced at any t Prompt blocks have the same syntax as [prompt files](../../customize/deep-dives/prompt-files.md). There are two important differences between prompt blocks and prompt files: -1. Prompt blocks are stored within `config.yaml` rather than `.continue/prompts` in project directory and -2. Prompt blocks only show up as slash commands in Chat, not under the `@Prompt Files` context provider +1. Currently, prompt blocks cannot use context providers +2. Prompt blocks are stored within `config.yaml` rather than `.continue/prompts` in project directory and The `config.yaml` spec for `prompts` can be found [here](../../yaml-reference.md#prompts). @@ -52,4 +52,4 @@ The `config.yaml` spec for `prompts` can be found [here](../../yaml-reference.md Data blocks allow you send your development data to custom destinations of your choice. Development data can be used for a variety of purposes, including analyzing usage, gathering insights, or fine-tuning models. You can read more about development data [here](../../customize/deep-dives/development-data.md). Explore data block examples [here](https://hub.continue.dev/explore/data). -Data destinations are configured in the[`data`](../../yaml-reference.md#data) section of `config.yaml`. \ No newline at end of file +Data destinations are configured in the [`data`](../../yaml-reference.md#data) section of `config.yaml`. diff --git a/gui/src/components/CodeToEditCard/AddFileCombobox.tsx b/gui/src/components/CodeToEditCard/AddFileCombobox.tsx index 07ab68a2c..9450ba480 100644 --- a/gui/src/components/CodeToEditCard/AddFileCombobox.tsx +++ b/gui/src/components/CodeToEditCard/AddFileCombobox.tsx @@ -1,9 +1,9 @@ -import { useState, useEffect, useRef } from "react"; -import { useSubmenuContextProviders } from "../../context/SubmenuContextProviders"; import { Combobox } from "@headlessui/react"; -import FileIcon from "../FileIcon"; -import { useAppSelector } from "../../redux/hooks"; import { ContextSubmenuItemWithProvider } from "core"; +import { useEffect, useRef, useState } from "react"; +import { useSubmenuContextProviders } from "../../context/SubmenuContextProviders"; +import { useAppSelector } from "../../redux/hooks"; +import FileIcon from "../FileIcon"; export interface AddFileComboboxProps { onSelect: (filepaths: string[]) => void | Promise; diff --git a/gui/src/components/ConversationStarters/ConversationStarterCard.tsx b/gui/src/components/ConversationStarters/ConversationStarterCard.tsx new file mode 100644 index 000000000..1542adadf --- /dev/null +++ b/gui/src/components/ConversationStarters/ConversationStarterCard.tsx @@ -0,0 +1,64 @@ +import { BookmarkIcon, ChatBubbleLeftIcon } from "@heroicons/react/24/outline"; +import { BookmarkIcon as BookmarkIconSolid } from "@heroicons/react/24/solid"; +import { SlashCommandDescription } from "core"; +import { useState } from "react"; +import { defaultBorderRadius, GhostButton, vscInputBackground } from ".."; + +interface ConversationStarterCardProps { + command: SlashCommandDescription; + onClick: (command: SlashCommandDescription) => void; + onBookmark: (command: SlashCommandDescription) => void; + isBookmarked: boolean; +} + +export function ConversationStarterCard({ + command, + onClick, + onBookmark, + isBookmarked = false, +}: ConversationStarterCardProps) { + const [isHovered, setIsHovered] = useState(false); + + return ( +
setIsHovered(true)} + onMouseLeave={() => setIsHovered(false)} + > +
+
+ +
+
onClick(command)} + className="flex flex-1 flex-col hover:cursor-pointer" + > +
{command.name}
+
{command.description}
+
+
+ { + e.stopPropagation(); + onBookmark(command); + }} + aria-label={ + isBookmarked ? "Remove bookmarked prompt" : "Bookmark prompt" + } + className={isHovered || isBookmarked ? "opacity-100" : "opacity-0"} + > + {isBookmarked ? ( + + ) : ( + + )} + +
+
+
+ ); +} diff --git a/gui/src/components/ConversationStarters/ConversationStarterCards.tsx b/gui/src/components/ConversationStarters/ConversationStarterCards.tsx new file mode 100644 index 000000000..921d47d6e --- /dev/null +++ b/gui/src/components/ConversationStarters/ConversationStarterCards.tsx @@ -0,0 +1,40 @@ +import { SlashCommandDescription } from "core"; +import { useAppDispatch } from "../../redux/hooks"; +import { setMainEditorContentTrigger } from "../../redux/slices/sessionSlice"; +import { getParagraphNodeFromString } from "../mainInput/utils"; +import { ConversationStarterCard } from "./ConversationStarterCard"; +import { useBookmarkedSlashCommands } from "./useBookmarkedSlashCommands"; + +const NUM_CARDS_TO_RENDER = 3; + +export function ConversationStarterCards() { + const dispatch = useAppDispatch(); + const { cmdsSortedByBookmark, bookmarkStatuses, toggleBookmark } = + useBookmarkedSlashCommands(); + + function onClick(command: SlashCommandDescription) { + if (command.prompt) { + dispatch( + setMainEditorContentTrigger(getParagraphNodeFromString(command.prompt)), + ); + } + } + + if (!cmdsSortedByBookmark || cmdsSortedByBookmark.length === 0) { + return null; + } + + return ( +
+ {cmdsSortedByBookmark.slice(0, NUM_CARDS_TO_RENDER).map((command, i) => ( + toggleBookmark(command)} + isBookmarked={bookmarkStatuses[command.name]} + /> + ))} +
+ ); +} diff --git a/gui/src/components/ConversationStarters/__tests__/utils.test.ts b/gui/src/components/ConversationStarters/__tests__/utils.test.ts new file mode 100644 index 000000000..3e7050985 --- /dev/null +++ b/gui/src/components/ConversationStarters/__tests__/utils.test.ts @@ -0,0 +1,45 @@ +import { SlashCommandDescription } from "core"; +import { sortCommandsByBookmarkStatus } from "../utils"; + +describe("sortCommandsByBookmarkStatus", () => { + const mockCommands: SlashCommandDescription[] = [ + { + name: "command1", + description: "First command", + prompt: "This is command 1", + }, + { + name: "command2", + description: "Second command", + prompt: "This is command 2", + }, + { + name: "command3", + description: "Third command", + prompt: "This is command 3", + }, + { + name: "command4", + description: "Fourth command", + prompt: "This is command 4", + }, + ]; + + it("should return commands in the same order when no bookmarks exist", () => { + const result = sortCommandsByBookmarkStatus(mockCommands, []); + expect(result).toEqual(mockCommands); + // Ensure it's a new array, not the original + expect(result).not.toBe(mockCommands); + }); + + it("should put bookmarked commands first", () => { + const bookmarkedCommands = ["command3", "command1"]; + const result = sortCommandsByBookmarkStatus( + mockCommands, + bookmarkedCommands, + ); + + expect(result[0].name).toBe("command1"); + expect(result[1].name).toBe("command3"); + }); +}); diff --git a/gui/src/components/ConversationStarters/index.ts b/gui/src/components/ConversationStarters/index.ts new file mode 100644 index 000000000..72b23e0b7 --- /dev/null +++ b/gui/src/components/ConversationStarters/index.ts @@ -0,0 +1 @@ +export * from "./ConversationStarterCards"; diff --git a/gui/src/components/ConversationStarters/useBookmarkedSlashCommands.ts b/gui/src/components/ConversationStarters/useBookmarkedSlashCommands.ts new file mode 100644 index 000000000..786ae379a --- /dev/null +++ b/gui/src/components/ConversationStarters/useBookmarkedSlashCommands.ts @@ -0,0 +1,69 @@ +import { SlashCommandDescription } from "core"; +import { usePostHog } from "posthog-js/react"; +import { useMemo } from "react"; +import { + bookmarkSlashCommand, + selectBookmarkedSlashCommands, + selectSelectedProfileId, + unbookmarkSlashCommand, +} from "../../redux"; +import { useAppDispatch, useAppSelector } from "../../redux/hooks"; +import { isDeprecatedCommandName, sortCommandsByBookmarkStatus } from "./utils"; + +export function useBookmarkedSlashCommands() { + const dispatch = useAppDispatch(); + const posthog = usePostHog(); + + const slashCommands = + useAppSelector((state) => state.config.config.slashCommands) ?? []; + const selectedProfileId = useAppSelector(selectSelectedProfileId); + const bookmarkedCommands = useAppSelector(selectBookmarkedSlashCommands); + + const filteredSlashCommands = slashCommands.filter(isDeprecatedCommandName); + + // Create a map of command names to bookmark status + const bookmarkStatuses = useMemo(() => { + const statuses: Record = {}; + if (selectedProfileId) { + filteredSlashCommands.forEach((command) => { + statuses[command.name] = bookmarkedCommands.includes(command.name); + }); + } + return statuses; + }, [filteredSlashCommands, bookmarkedCommands, selectedProfileId]); + + // Sort commands by bookmark status + const cmdsSortedByBookmark = useMemo( + () => + sortCommandsByBookmarkStatus(filteredSlashCommands, bookmarkedCommands), + [filteredSlashCommands, bookmarkedCommands], + ); + + const toggleBookmark = (command: SlashCommandDescription) => { + const isBookmarked = bookmarkStatuses[command.name]; + + posthog.capture("toggle_bookmarked_slash_command", { + isBookmarked, + }); + + if (isBookmarked) { + dispatch( + unbookmarkSlashCommand({ + commandName: command.name, + }), + ); + } else { + dispatch( + bookmarkSlashCommand({ + commandName: command.name, + }), + ); + } + }; + + return { + cmdsSortedByBookmark, + bookmarkStatuses, + toggleBookmark, + }; +} diff --git a/gui/src/components/ConversationStarters/utils.ts b/gui/src/components/ConversationStarters/utils.ts new file mode 100644 index 000000000..d37b45416 --- /dev/null +++ b/gui/src/components/ConversationStarters/utils.ts @@ -0,0 +1,49 @@ +import { SlashCommandDescription } from "core"; +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. + * + * Once these commands are no longer inserted during intermediary config loading, + * this function can be removed. + */ +export function isDeprecatedCommandName(command: SlashCommandDescription) { + const defaultCommands = isJetBrains() + ? defaultSlashCommandsJetBrains + : defaultSlashCommandsVscode; + + return !defaultCommands.find( + (defaultCommand) => defaultCommand.name === command.name, + ); +} + +/** + * Sorts commands with bookmarked ones first + * @param commands The list of commands to sort + * @param bookmarkedCommands An array of bookmarked command names + * @returns A new sorted array with bookmarked commands first + */ +export function sortCommandsByBookmarkStatus( + commands: SlashCommandDescription[], + bookmarkedCommands: string[], +): SlashCommandDescription[] { + return [...commands].sort((a, b) => { + const aIsBookmarked = bookmarkedCommands.includes(a.name); + const bIsBookmarked = bookmarkedCommands.includes(b.name); + + if (aIsBookmarked && !bIsBookmarked) return -1; + if (!aIsBookmarked && bIsBookmarked) return 1; + return 0; + }); +} diff --git a/gui/src/components/OnboardingCard/hooks/useSubmitOnboarding.ts b/gui/src/components/OnboardingCard/hooks/useSubmitOnboarding.ts index 93b24ea91..9e1bd8a9b 100644 --- a/gui/src/components/OnboardingCard/hooks/useSubmitOnboarding.ts +++ b/gui/src/components/OnboardingCard/hooks/useSubmitOnboarding.ts @@ -1,15 +1,13 @@ +import { OnboardingModes } from "core/protocol/core"; import { usePostHog } from "posthog-js/react"; import { useContext } from "react"; import { IdeMessengerContext } from "../../../context/IdeMessenger"; import { getLocalStorage, setLocalStorage } from "../../../util/localStorage"; -import { OnboardingModes } from "core/protocol/core"; -import { useTutorialCard } from "../../../hooks/useTutorialCard"; import { useOnboardingCard } from "./useOnboardingCard"; export function useSubmitOnboarding(mode: OnboardingModes, isDialog = false) { const posthog = usePostHog(); const ideMessenger = useContext(IdeMessengerContext); - const { openTutorialCard } = useTutorialCard(); const { close: closeOnboardingCard } = useOnboardingCard(); function submitOnboarding() { @@ -31,9 +29,6 @@ export function useSubmitOnboarding(mode: OnboardingModes, isDialog = false) { // Local state setLocalStorage("onboardingStatus", "Completed"); - // Show tutorial card - openTutorialCard(); - // Move to next step in onboarding ideMessenger.post("showTutorial", undefined); } diff --git a/gui/src/components/index.ts b/gui/src/components/index.ts index 04460f3b1..eb0632646 100644 --- a/gui/src/components/index.ts +++ b/gui/src/components/index.ts @@ -1,5 +1,5 @@ import styled from "styled-components"; -import { getFontSize, isJetBrains } from "../util"; +import { getFontSize } from "../util"; export const VSC_INPUT_BACKGROUND_VAR = "--vscode-input-background"; export const VSC_BACKGROUND_VAR = "--vscode-sideBar-background"; @@ -151,7 +151,7 @@ export const SecondaryButton = styled.button` `; export const GhostButton = styled.button` - padding: 10px 12px; + padding: 6px 8px; margin: 8px 0; border-radius: ${defaultBorderRadius}; diff --git a/gui/src/components/mainInput/InputToolbar.tsx b/gui/src/components/mainInput/InputToolbar.tsx index d948dc288..a1f9da282 100644 --- a/gui/src/components/mainInput/InputToolbar.tsx +++ b/gui/src/components/mainInput/InputToolbar.tsx @@ -75,7 +75,6 @@ export interface ToolbarOptions { interface InputToolbarProps { onEnter?: (modifiers: InputModifiers) => void; onAddContextItem?: () => void; - onAddSlashCommand?: () => void; onClick?: () => void; onImageFileSelected?: (file: File) => void; hidden?: boolean; diff --git a/gui/src/components/mainInput/MentionList.tsx b/gui/src/components/mainInput/MentionList.tsx index 98e798d12..66c2da16e 100644 --- a/gui/src/components/mainInput/MentionList.tsx +++ b/gui/src/components/mainInput/MentionList.tsx @@ -1,7 +1,7 @@ import { ArrowRightIcon, AtSymbolIcon, - BoltIcon, + ChatBubbleLeftIcon, PlusIcon, } from "@heroicons/react/24/outline"; import { Editor } from "@tiptap/react"; @@ -36,7 +36,8 @@ export function getIconFromDropdownItem( id: string | undefined, type: ComboBoxItemType, ) { - const typeIcon = type === "contextProvider" ? AtSymbolIcon : BoltIcon; + const typeIcon = + type === "contextProvider" ? AtSymbolIcon : ChatBubbleLeftIcon; return id ? (NAMED_ICONS[id] ?? typeIcon) : typeIcon; } @@ -454,7 +455,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 046da1021..06261d1b9 100644 --- a/gui/src/components/mainInput/TipTapEditor.tsx +++ b/gui/src/components/mainInput/TipTapEditor.tsx @@ -563,7 +563,7 @@ function TipTapEditor(props: TipTapEditorProps) { } return historyLength === 0 - ? "Ask anything, '@' to add context" + ? "Ask anything, '/' for prompts, '@' to add context" : "Ask a follow-up"; } @@ -994,7 +994,6 @@ function TipTapEditor(props: TipTapEditorProps) { activeKey={activeKey} hidden={shouldHideToolbar && !props.isMainInput} onAddContextItem={() => insertCharacterWithWhitespace("@")} - onAddSlashCommand={() => insertCharacterWithWhitespace("/")} onEnter={onEnterRef.current} onImageFileSelected={(file) => { handleImageFile(file).then((result) => { diff --git a/gui/src/components/mainInput/TutorialCard.tsx b/gui/src/components/mainInput/TutorialCard.tsx deleted file mode 100644 index c31c8f4a3..000000000 --- a/gui/src/components/mainInput/TutorialCard.tsx +++ /dev/null @@ -1,100 +0,0 @@ -import { - ArrowRightStartOnRectangleIcon, - BookOpenIcon, - ClipboardDocumentIcon, - Cog6ToothIcon, - PencilSquareIcon, - XMarkIcon, -} from "@heroicons/react/24/outline"; -import { useContext } from "react"; -import { lightGray } from ".."; -import { IdeMessengerContext } from "../../context/IdeMessenger"; -import { isJetBrains } from "../../util"; -import Shortcut from "../gui/Shortcut"; - -interface TutorialCardProps { - onClose: () => void; -} - -export function TutorialCard({ onClose }: TutorialCardProps) { - const ideMessenger = useContext(IdeMessengerContext); - const jetbrains = isJetBrains(); - - return ( -
-
-

-
- -
-
- -
    - {!jetbrains && ( -
  • - - - - ideMessenger.post("vscode/openMoveRightMarkdown", undefined) - } - > - Move Chat panel to the right - {" "} - for the cleanest experience - -
  • - )} -
  • -
    - -
    - - Highlight code and press meta I to quickly make - natural language edits - -
  • -
  • -
    - -
    - - Highlight code and press meta L to add it to - the chat window - -
  • -
  • -
    - -
    - - Click the gear icon in the upper right to configure Continue - -
  • -
  • -
    - -
    - - - ideMessenger.post("openUrl", "https://docs.continue.dev") - } - > - Read our documentation - {" "} - to learn more - -
  • -
-
- ); -} 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/components/mainInput/utils.ts b/gui/src/components/mainInput/utils.ts new file mode 100644 index 000000000..71565a429 --- /dev/null +++ b/gui/src/components/mainInput/utils.ts @@ -0,0 +1,18 @@ +import { JSONContent } from "@tiptap/core"; + +export function getParagraphNodeFromString(str: string): JSONContent { + return { + type: "doc", + content: [ + { + type: "paragraph", + content: [ + { + type: "text", + text: str, + }, + ], + }, + ], + }; +} diff --git a/gui/src/components/modelSelection/platform/AssistantSelect.tsx b/gui/src/components/modelSelection/platform/AssistantSelect.tsx index e64acb8f6..3bba921f8 100644 --- a/gui/src/components/modelSelection/platform/AssistantSelect.tsx +++ b/gui/src/components/modelSelection/platform/AssistantSelect.tsx @@ -4,8 +4,8 @@ import { ProfileDescription } from "core/config/ConfigHandler"; import { useContext, useEffect, useRef } from "react"; import { useAuth } from "../../../context/Auth"; import { IdeMessengerContext } from "../../../context/IdeMessenger"; +import { cycleProfile } from "../../../redux"; import { useAppDispatch } from "../../../redux/hooks"; -import { cycleProfile } from "../../../redux/thunks/profileAndOrg"; import { getFontSize, isMetaEquivalentKeyPressed } from "../../../util"; import PopoverTransition from "../../mainInput/InputToolbar/PopoverTransition"; import AssistantIcon from "./AssistantIcon"; diff --git a/gui/src/components/modelSelection/platform/AssistantSelectOptions.tsx b/gui/src/components/modelSelection/platform/AssistantSelectOptions.tsx index cd8d5cd5c..c7b9caa80 100644 --- a/gui/src/components/modelSelection/platform/AssistantSelectOptions.tsx +++ b/gui/src/components/modelSelection/platform/AssistantSelectOptions.tsx @@ -5,8 +5,8 @@ import { useNavigate } from "react-router-dom"; import { lightGray } from "../.."; import { useAuth } from "../../../context/Auth"; import { IdeMessengerContext } from "../../../context/IdeMessenger"; +import { selectProfileThunk } from "../../../redux"; import { useAppDispatch } from "../../../redux/hooks"; -import { selectProfileThunk } from "../../../redux/thunks/profileAndOrg"; import { getFontSize, getMetaKeyLabel, isLocalProfile } from "../../../util"; import { ROUTES } from "../../../util/navigation"; import AssistantIcon from "./AssistantIcon"; diff --git a/gui/src/context/Auth.tsx b/gui/src/context/Auth.tsx index 8ca1e5be0..a049e8adc 100644 --- a/gui/src/context/Auth.tsx +++ b/gui/src/context/Auth.tsx @@ -12,14 +12,11 @@ import React, { } from "react"; import ConfirmationDialog from "../components/dialogs/ConfirmationDialog"; import { useWebviewListener } from "../hooks/useWebviewListener"; +import { updateOrgsThunk, updateProfilesThunk } from "../redux"; +import { selectSelectedProfile } from "../redux/"; import { useAppDispatch, useAppSelector } from "../redux/hooks"; import { setLastControlServerBetaEnabledStatus } from "../redux/slices/miscSlice"; -import { selectSelectedProfile } from "../redux/slices/sessionSlice"; import { setDialogMessage, setShowDialog } from "../redux/slices/uiSlice"; -import { - updateOrgsThunk, - updateProfilesThunk, -} from "../redux/thunks/profileAndOrg"; import { IdeMessengerContext } from "./IdeMessenger"; interface AuthContextType { @@ -48,9 +45,9 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ ); // Orgs - const orgs = useAppSelector((store) => store.session.organizations); + const orgs = useAppSelector((store) => store.organizations.organizations); const selectedOrgId = useAppSelector( - (store) => store.session.selectedOrganizationId, + (store) => store.organizations.selectedOrganizationId, ); const selectedOrganization = useMemo(() => { if (!selectedOrgId) { @@ -60,7 +57,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ }, [orgs, selectedOrgId]); // Profiles - const profiles = useAppSelector((store) => store.session.availableProfiles); + const profiles = useAppSelector((store) => store.profiles.availableProfiles); const selectedProfile = useAppSelector(selectSelectedProfile); const login: AuthContextType["login"] = (useOnboarding: boolean) => { diff --git a/gui/src/hooks/useSetup.ts b/gui/src/hooks/useSetup.ts index 9d7f607b5..22a3ec324 100644 --- a/gui/src/hooks/useSetup.ts +++ b/gui/src/hooks/useSetup.ts @@ -4,6 +4,7 @@ import { IdeMessengerContext } from "../context/IdeMessenger"; import { ConfigResult } from "@continuedev/config-yaml"; import { BrowserSerializedContinueConfig } from "core"; +import { selectProfileThunk } from "../redux"; import { useAppDispatch, useAppSelector } from "../redux/hooks"; import { selectDefaultModel, @@ -16,7 +17,6 @@ import { setInactive, } from "../redux/slices/sessionSlice"; import { setTTSActive } from "../redux/slices/uiSlice"; -import { selectProfileThunk } from "../redux/thunks/profileAndOrg"; import { refreshSessionMetadata } from "../redux/thunks/session"; import { streamResponseThunk } from "../redux/thunks/streamResponse"; import { updateFileSymbolsFromHistory } from "../redux/thunks/updateFileSymbols"; diff --git a/gui/src/hooks/useTutorialCard.ts b/gui/src/hooks/useTutorialCard.ts deleted file mode 100644 index 0a8e7aee9..000000000 --- a/gui/src/hooks/useTutorialCard.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { useState } from "react"; -import { getLocalStorage, setLocalStorage } from "../util/localStorage"; -import { usePostHog } from "posthog-js/react"; - -export type UseTutorialCard = { - showTutorialCard: boolean; - closeTutorialCard: () => void; - openTutorialCard: () => void; -}; - -export function useTutorialCard(): UseTutorialCard { - const posthog = usePostHog(); - - const [showTutorialCard, setShowTutorialCard] = useState( - getLocalStorage("showTutorialCard") ?? true, - ); - - function closeTutorialCard() { - posthog.capture("closedTutorialCard"); - setLocalStorage("showTutorialCard", false); - setShowTutorialCard(false); - } - - function openTutorialCard() { - setLocalStorage("showTutorialCard", true); - setShowTutorialCard(true); - } - - return { showTutorialCard, closeTutorialCard, openTutorialCard }; -} - -export default UseTutorialCard; diff --git a/gui/src/pages/config/AccountManagement.tsx b/gui/src/pages/config/AccountManagement.tsx index 1b9dd80af..029718ed8 100644 --- a/gui/src/pages/config/AccountManagement.tsx +++ b/gui/src/pages/config/AccountManagement.tsx @@ -8,8 +8,8 @@ import { Fragment, useContext } from "react"; import AssistantIcon from "../../components/modelSelection/platform/AssistantIcon"; import { useAuth } from "../../context/Auth"; import { IdeMessengerContext } from "../../context/IdeMessenger"; +import { selectProfileThunk } from "../../redux"; import { useAppDispatch } from "../../redux/hooks"; -import { selectProfileThunk } from "../../redux/thunks/profileAndOrg"; import { ScopeSelect } from "./ScopeSelect"; export function AccountManagement({ hubEnabled }: { hubEnabled: boolean }) { 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/config/ScopeSelect.tsx b/gui/src/pages/config/ScopeSelect.tsx index 2d42483a0..51538d784 100644 --- a/gui/src/pages/config/ScopeSelect.tsx +++ b/gui/src/pages/config/ScopeSelect.tsx @@ -6,13 +6,13 @@ import { } from "@heroicons/react/24/outline"; import { useAuth } from "../../context/Auth"; import { useWebviewListener } from "../../hooks/useWebviewListener"; +import { selectOrgThunk } from "../../redux"; import { useAppDispatch, useAppSelector } from "../../redux/hooks"; -import { selectOrgThunk } from "../../redux/thunks/profileAndOrg"; export function ScopeSelect() { const { organizations, selectedOrganization } = useAuth(); const selectedOrgId = useAppSelector( - (state) => state.session.selectedOrganizationId, + (state) => state.organizations.selectedOrganizationId, ); const dispatch = useAppDispatch(); diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx index 16e13c278..cd2f72d24 100644 --- a/gui/src/pages/gui/Chat.tsx +++ b/gui/src/pages/gui/Chat.tsx @@ -22,7 +22,6 @@ import { import CodeToEditCard from "../../components/CodeToEditCard"; import FeedbackDialog from "../../components/dialogs/FeedbackDialog"; import FreeTrialOverDialog from "../../components/dialogs/FreeTrialOverDialog"; -import { ExploreHubCard } from "../../components/ExploreHubCard"; import { useFindWidget } from "../../components/find/FindWidget"; import TimelineItem from "../../components/gui/TimelineItem"; import ChatIndexingPeeks from "../../components/indexing/ChatIndexingPeeks"; @@ -30,19 +29,13 @@ import ContinueInputBox from "../../components/mainInput/ContinueInputBox"; import { NewSessionButton } from "../../components/mainInput/NewSessionButton"; import resolveEditorContent from "../../components/mainInput/resolveInput"; import ThinkingBlockPeek from "../../components/mainInput/ThinkingBlockPeek"; -import { TutorialCard } from "../../components/mainInput/TutorialCard"; import AssistantSelect from "../../components/modelSelection/platform/AssistantSelect"; -import { - OnboardingCard, - useOnboardingCard, -} from "../../components/OnboardingCard"; -import { PlatformOnboardingCard } from "../../components/OnboardingCard/platform/PlatformOnboardingCard"; +import { useOnboardingCard } from "../../components/OnboardingCard"; import PageHeader from "../../components/PageHeader"; import StepContainer from "../../components/StepContainer"; import AcceptRejectAllButtons from "../../components/StepContainer/AcceptRejectAllButtons"; import { TabBar } from "../../components/TabBar/TabBar"; import { IdeMessengerContext } from "../../context/IdeMessenger"; -import { useTutorialCard } from "../../hooks/useTutorialCard"; import { useWebviewListener } from "../../hooks/useWebviewListener"; import { useAppDispatch, useAppSelector } from "../../redux/hooks"; import { selectUseHub } from "../../redux/selectors"; @@ -78,6 +71,7 @@ import { import getMultifileEditPrompt from "../../util/getMultifileEditPrompt"; import { getLocalStorage, setLocalStorage } from "../../util/localStorage"; import ConfigErrorIndicator from "./ConfigError"; +import { EmptyChatBody } from "./EmptyChatBody"; import { ExploreDialogWatcher } from "./ExploreDialogWatcher"; import { ToolCallDiv } from "./ToolCallDiv"; import { ToolCallButtons } from "./ToolCallDiv/ToolCallButtonsDiv"; @@ -145,7 +139,6 @@ export function Chat() { const dispatch = useAppDispatch(); const ideMessenger = useContext(IdeMessengerContext); const onboardingCard = useOnboardingCard(); - const { showTutorialCard, closeTutorialCard } = useTutorialCard(); const showSessionTabs = useAppSelector( (store) => store.config.config.ui?.showSessionTabs, ); @@ -538,29 +531,10 @@ export function Chat() { {!hasDismissedExploreDialog && } {history.length === 0 && ( - <> - {onboardingCard.show && ( -
- {useHub ? ( - - ) : ( - - )} -
- )} - - {showTutorialCard !== false && !onboardingCard.show && ( -
- -
- )} - - {!onboardingCard.show && showTutorialCard === false && ( -
- -
- )} - + )} diff --git a/gui/src/pages/gui/EmptyChatBody.tsx b/gui/src/pages/gui/EmptyChatBody.tsx new file mode 100644 index 000000000..dce70cdd5 --- /dev/null +++ b/gui/src/pages/gui/EmptyChatBody.tsx @@ -0,0 +1,33 @@ +import { ConversationStarterCards } from "../../components/ConversationStarters"; +import { ExploreHubCard } from "../../components/ExploreHubCard"; +import { OnboardingCard } from "../../components/OnboardingCard"; +import { PlatformOnboardingCard } from "../../components/OnboardingCard/platform/PlatformOnboardingCard"; + +export interface EmptyChatBodyProps { + useHub: boolean; + showOnboardingCard?: boolean; +} + +export function EmptyChatBody({ + useHub, + showOnboardingCard, +}: EmptyChatBodyProps) { + if (showOnboardingCard) { + return ( +
+ {useHub ? ( + + ) : ( + + )} +
+ ); + } + + return ( +
+ + +
+ ); +} diff --git a/gui/src/pages/gui/StreamError.tsx b/gui/src/pages/gui/StreamError.tsx index c57f71422..389528cd0 100644 --- a/gui/src/pages/gui/StreamError.tsx +++ b/gui/src/pages/gui/StreamError.tsx @@ -6,10 +6,10 @@ import { DiscordIcon } from "../../components/svg/DiscordIcon"; import { GithubIcon } from "../../components/svg/GithubIcon"; import { useAuth } from "../../context/Auth"; import { IdeMessengerContext } from "../../context/IdeMessenger"; +import { selectSelectedProfile } from "../../redux/"; import { useAppDispatch, useAppSelector } from "../../redux/hooks"; import { selectUseHub } from "../../redux/selectors"; import { selectDefaultModel } from "../../redux/slices/configSlice"; -import { selectSelectedProfile } from "../../redux/slices/sessionSlice"; import { setDialogMessage, setShowDialog } from "../../redux/slices/uiSlice"; import { isLocalProfile } from "../../util"; import { providers } from "../AddNewModel/configs/providers"; diff --git a/gui/src/redux/index.ts b/gui/src/redux/index.ts new file mode 100644 index 000000000..0af19ed8d --- /dev/null +++ b/gui/src/redux/index.ts @@ -0,0 +1 @@ +export * from "./slices"; 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, }; diff --git a/gui/src/redux/slices/index.ts b/gui/src/redux/slices/index.ts new file mode 100644 index 000000000..644b24187 --- /dev/null +++ b/gui/src/redux/slices/index.ts @@ -0,0 +1,2 @@ +export * from "./organizations"; +export * from "./profiles"; diff --git a/gui/src/redux/slices/organizations/index.ts b/gui/src/redux/slices/organizations/index.ts new file mode 100644 index 000000000..22be336b5 --- /dev/null +++ b/gui/src/redux/slices/organizations/index.ts @@ -0,0 +1,2 @@ +export * from "./slice"; +export * from "./thunks"; diff --git a/gui/src/redux/slices/organizations/slice.ts b/gui/src/redux/slices/organizations/slice.ts new file mode 100644 index 000000000..b662d2435 --- /dev/null +++ b/gui/src/redux/slices/organizations/slice.ts @@ -0,0 +1,50 @@ +import { createSlice, PayloadAction } from "@reduxjs/toolkit"; +import { OrganizationDescription } from "core/config/ProfileLifecycleManager"; + +export interface OrganizationsState { + organizations: OrganizationDescription[]; + selectedOrganizationId: string | null; +} + +const initialState: OrganizationsState = { + organizations: [], + selectedOrganizationId: null, +}; + +export const organizationsSlice = createSlice({ + name: "organizations", + initialState, + reducers: { + setOrganizations: ( + state, + { payload }: PayloadAction, + ) => { + state.organizations = payload; + }, + setSelectedOrganizationId: ( + state, + { payload }: PayloadAction, + ) => { + state.selectedOrganizationId = payload; + }, + }, + selectors: { + selectOrganizations: (state) => state.organizations, + selectSelectedOrganizationId: (state) => state.selectedOrganizationId, + selectSelectedOrganization: (state) => + state.organizations.find( + (org) => org.id === state.selectedOrganizationId, + ) ?? null, + }, +}); + +export const { setOrganizations, setSelectedOrganizationId } = + organizationsSlice.actions; + +export const { + selectOrganizations, + selectSelectedOrganizationId, + selectSelectedOrganization, +} = organizationsSlice.selectors; + +export const { reducer: organizationsReducer } = organizationsSlice; diff --git a/gui/src/redux/slices/organizations/thunks.ts b/gui/src/redux/slices/organizations/thunks.ts new file mode 100644 index 000000000..85aeede0a --- /dev/null +++ b/gui/src/redux/slices/organizations/thunks.ts @@ -0,0 +1,47 @@ +import { createAsyncThunk } from "@reduxjs/toolkit"; +import { OrganizationDescription } from "core/config/ProfileLifecycleManager"; +import { ThunkApiType } from "../../store"; +import { setAvailableProfiles } from "../profiles/slice"; +import { setOrganizations, setSelectedOrganizationId } from "./slice"; + +export const selectOrgThunk = createAsyncThunk< + void, + string | null, + ThunkApiType +>("organizations/select", async (id, { dispatch, extra, getState }) => { + const state = getState(); + const initialId = state.organizations.selectedOrganizationId; + let newId = id; + + // If no orgs, force clear + if (state.organizations.organizations.length === 0) { + newId = null; + } else if (newId) { + // If new id doesn't match an existing org, clear it + if (!state.organizations.organizations.find((o) => o.id === newId)) { + newId = null; + } + } + // Unlike profiles, don't fallback to the first org, + // Fallback to Personal (org = null) + + if (initialId !== newId) { + dispatch(setAvailableProfiles(null)); + dispatch(setSelectedOrganizationId(newId)); + extra.ideMessenger.post("didChangeSelectedOrg", { + id: newId, + }); + } +}); + +export const updateOrgsThunk = createAsyncThunk< + void, + OrganizationDescription[], + ThunkApiType +>("organizations/update", async (orgs, { dispatch, getState }) => { + const state = getState(); + dispatch(setOrganizations(orgs)); + + // This will trigger reselection if needed + dispatch(selectOrgThunk(state.organizations.selectedOrganizationId)); +}); diff --git a/gui/src/redux/slices/profiles/index.ts b/gui/src/redux/slices/profiles/index.ts new file mode 100644 index 000000000..22be336b5 --- /dev/null +++ b/gui/src/redux/slices/profiles/index.ts @@ -0,0 +1,2 @@ +export * from "./slice"; +export * from "./thunks"; diff --git a/gui/src/redux/slices/profiles/slice.ts b/gui/src/redux/slices/profiles/slice.ts new file mode 100644 index 000000000..2d3386a5f --- /dev/null +++ b/gui/src/redux/slices/profiles/slice.ts @@ -0,0 +1,109 @@ +import { createSlice, PayloadAction } from "@reduxjs/toolkit"; +import { ProfileDescription } from "core/config/ConfigHandler"; +import { ensureProfilePreferences } from "./utils"; + +export interface PreferencesState { + bookmarksByName: string[]; +} + +export interface ProfilesState { + availableProfiles: ProfileDescription[] | null; + selectedProfileId: string | null; + preferencesByProfileId: Record; +} + +const initialState: ProfilesState = { + availableProfiles: null, + selectedProfileId: null, + preferencesByProfileId: {}, +}; + +export const profilesSlice = createSlice({ + name: "profiles", + initialState, + reducers: { + setSelectedProfile: (state, { payload }: PayloadAction) => { + state.selectedProfileId = payload; + + if (payload) { + ensureProfilePreferences(state, payload); + } + }, + setAvailableProfiles: ( + state, + { payload }: PayloadAction, + ) => { + state.availableProfiles = payload; + + if (payload) { + for (const profile of payload) { + ensureProfilePreferences(state, profile.id); + } + } + }, + bookmarkSlashCommand: ( + state, + action: PayloadAction<{ commandName: string }>, + ) => { + const { commandName } = action.payload; + const profileId = state.selectedProfileId; + + if (!profileId) return; + + const bookmarks = state.preferencesByProfileId[profileId].bookmarksByName; + if (!bookmarks.includes(commandName)) { + bookmarks.push(commandName); + } + }, + + unbookmarkSlashCommand: ( + state, + action: PayloadAction<{ commandName: string }>, + ) => { + const { commandName } = action.payload; + const profileId = state.selectedProfileId; + + if (!profileId) return; + + const preferences = state.preferencesByProfileId[profileId]; + preferences.bookmarksByName = preferences.bookmarksByName.filter( + (cmd) => cmd !== commandName, + ); + }, + }, + selectors: { + selectSelectedProfile: (state) => { + return ( + state.availableProfiles?.find( + (profile) => profile.id === state.selectedProfileId, + ) ?? null + ); + }, + + selectSelectedProfileId: (state) => state.selectedProfileId, + + selectBookmarkedSlashCommands: (state) => { + if (!state.selectedProfileId) return []; + const preferences = state.preferencesByProfileId[state.selectedProfileId]; + return preferences?.bookmarksByName || []; + }, + + selectPreferencesByProfileId: (state) => state.preferencesByProfileId, + }, +}); + +export const { + setAvailableProfiles, + setSelectedProfile, + bookmarkSlashCommand, + unbookmarkSlashCommand, +} = profilesSlice.actions; + +export const { + selectSelectedProfile, + selectSelectedProfileId, + selectBookmarkedSlashCommands, + selectPreferencesByProfileId, +} = profilesSlice.selectors; + +export const { reducer: profilesReducer } = profilesSlice; diff --git a/gui/src/redux/slices/profiles/thunks.ts b/gui/src/redux/slices/profiles/thunks.ts new file mode 100644 index 000000000..7ca109490 --- /dev/null +++ b/gui/src/redux/slices/profiles/thunks.ts @@ -0,0 +1,85 @@ +import { createAsyncThunk } from "@reduxjs/toolkit"; +import { ProfileDescription } from "core/config/ConfigHandler"; +import { ThunkApiType } from "../../store"; +import { setAvailableProfiles, setSelectedProfile } from "./slice"; + +export const selectProfileThunk = createAsyncThunk< + void, + string | null, + ThunkApiType +>("profiles/select", async (id, { dispatch, extra, getState }) => { + const state = getState(); + + if (state.profiles.availableProfiles === null) { + // Currently in loading state + return; + } + + const initialId = state.profiles.selectedProfileId; + + let newId = id; + + // If no profiles, force clear + if (state.profiles.availableProfiles.length === 0) { + newId = null; + } else { + // If new id doesn't match an existing profile, clear it + if (newId) { + if (!state.profiles.availableProfiles.find((p) => p.id === newId)) { + newId = null; + } + } + if (!newId) { + // At this point if null ID and there ARE profiles, + // Fallback to a profile, prioritizing the first in the list + newId = state.profiles.availableProfiles[0].id; + } + } + + // Only update if there's a change + if ((newId ?? null) !== (initialId ?? null)) { + dispatch(setSelectedProfile(newId)); + extra.ideMessenger.post("didChangeSelectedProfile", { + id: newId, + }); + } +}); + +export const cycleProfile = createAsyncThunk( + "profiles/cycle", + async (_, { dispatch, getState }) => { + const state = getState(); + + if (state.profiles.availableProfiles === null) { + return; + } + + const profileIds = state.profiles.availableProfiles.map( + (profile) => profile.id, + ); + // In case of no profiles just does nothing + if (profileIds.length === 0) { + return; + } + let nextId = profileIds[0]; + if (state.profiles.selectedProfileId) { + const curIndex = profileIds.indexOf(state.profiles.selectedProfileId); + const nextIndex = (curIndex + 1) % profileIds.length; + nextId = profileIds[nextIndex]; + } + await dispatch(selectProfileThunk(nextId)); + }, +); + +export const updateProfilesThunk = createAsyncThunk< + void, + { profiles: ProfileDescription[] | null; selectedProfileId: string | null }, + ThunkApiType +>("profiles/update", async (data, { dispatch, extra, getState }) => { + const { profiles, selectedProfileId } = data; + + dispatch(setAvailableProfiles(profiles)); + + // This will trigger reselection if needed + dispatch(selectProfileThunk(selectedProfileId)); +}); diff --git a/gui/src/redux/slices/profiles/utils.ts b/gui/src/redux/slices/profiles/utils.ts new file mode 100644 index 000000000..58da69942 --- /dev/null +++ b/gui/src/redux/slices/profiles/utils.ts @@ -0,0 +1,12 @@ +import { ProfilesState } from "./slice"; + +export function ensureProfilePreferences( + state: ProfilesState, + profileId: string, +) { + if (!state.preferencesByProfileId[profileId]) { + state.preferencesByProfileId[profileId] = { + bookmarksByName: [], + }; + } +} diff --git a/gui/src/redux/slices/sessionSlice.ts b/gui/src/redux/slices/sessionSlice.ts index c8ff93e88..2fde7aedd 100644 --- a/gui/src/redux/slices/sessionSlice.ts +++ b/gui/src/redux/slices/sessionSlice.ts @@ -21,8 +21,6 @@ import { ToolCallDelta, ToolCallState, } from "core"; -import { ProfileDescription } from "core/config/ConfigHandler"; -import { OrganizationDescription } from "core/config/ProfileLifecycleManager"; import { NEW_SESSION_TITLE } from "core/util/constants"; import { incrementalParseJson } from "core/util/incrementalParseJson"; import { renderChatMessage } from "core/util/messageContent"; @@ -45,11 +43,6 @@ type SessionState = { isStreaming: boolean; title: string; id: string; - /** null indicates loading state */ - availableProfiles: ProfileDescription[] | null; - selectedProfileId: string | null; - organizations: OrganizationDescription[]; - selectedOrganizationId: string | null; streamAborter: AbortController; codeToEdit: CodeToEdit[]; curCheckpointIndex: number; @@ -88,10 +81,6 @@ const initialState: SessionState = { isStreaming: false, title: NEW_SESSION_TITLE, id: uuidv4(), - selectedProfileId: null, - availableProfiles: null, - organizations: [], - selectedOrganizationId: "", curCheckpointIndex: 0, streamAborter: new AbortController(), codeToEdit: [], @@ -294,7 +283,6 @@ export const sessionSlice = createSlice({ state.streamAborter = new AbortController(); }, streamUpdate: (state, action: PayloadAction) => { - if (state.history.length) { function toolCallDeltaToState( toolCallDelta: ToolCallDelta, @@ -332,7 +320,7 @@ export const sessionSlice = createSlice({ id: uuidv4(), }, contextItems: [], - }) + }); continue; } @@ -554,30 +542,6 @@ export const sessionSlice = createSlice({ state.history[state.history.length - 1].contextItems = contextItems; }, - // Important: these reducers don't handle selected profile/organization fallback logic - // That is done in thunks - setSelectedProfile: (state, { payload }: PayloadAction) => { - state.selectedProfileId = payload; - }, - setAvailableProfiles: ( - state, - { payload }: PayloadAction, - ) => { - state.availableProfiles = payload; - }, - setOrganizations: ( - state, - { payload }: PayloadAction, - ) => { - state.organizations = payload; - }, - setSelectedOrganizationId: ( - state, - { payload }: PayloadAction, - ) => { - state.selectedOrganizationId = payload; - }, - /////////////// updateCurCheckpoint: ( state, @@ -690,15 +654,6 @@ export const sessionSlice = createSlice({ selectIsInEditMode: (state) => { return state.mode === "edit"; }, - selectSelectedProfile: (state) => { - // state.session.availableProfiles.find((p) => p.id === newId) ?? null, - - return ( - state.availableProfiles?.find( - (profile) => profile.id === state.selectedProfileId, - ) ?? null - ); - }, selectIsSingleRangeEditOrInsertion: (state) => { if (state.mode !== "edit") { return false; @@ -784,17 +739,11 @@ export const { updateSessionMetadata, deleteSessionMetadata, setNewestCodeblocksForInput, - - setAvailableProfiles, - setSelectedProfile, - setOrganizations, - setSelectedOrganizationId, } = sessionSlice.actions; export const { selectIsGatheringContext, selectIsInEditMode, - selectSelectedProfile, selectIsSingleRangeEditOrInsertion, selectHasCodeToEdit, } = sessionSlice.selectors; diff --git a/gui/src/redux/store.ts b/gui/src/redux/store.ts index 2cb7d2ded..d2addfacd 100644 --- a/gui/src/redux/store.ts +++ b/gui/src/redux/store.ts @@ -10,6 +10,7 @@ import { createFilter } from "redux-persist-transform-filter"; import autoMergeLevel2 from "redux-persist/lib/stateReconciler/autoMergeLevel2"; import storage from "redux-persist/lib/storage"; import { IdeMessenger, IIdeMessenger } from "../context/IdeMessenger"; +import { organizationsReducer, profilesReducer } from "./slices"; import configReducer from "./slices/configSlice"; import editModeStateReducer from "./slices/editModeState"; import indexingReducer from "./slices/indexingSlice"; @@ -31,13 +32,13 @@ const rootReducer = combineReducers({ config: configReducer, indexing: indexingReducer, tabs: tabsReducer, + profiles: profilesReducer, + organizations: organizationsReducer, }); const saveSubsetFilters = [ createFilter("session", [ "history", - "selectedOrganizationId", - "selectedProfile", "id", "lastSessionId", "title", @@ -61,6 +62,12 @@ const saveSubsetFilters = [ createFilter("ui", ["toolSettings", "toolGroupSettings", "useTools"]), createFilter("indexing", []), createFilter("tabs", ["tabs"]), + // Add this new filter for the profiles slice + createFilter("profiles", [ + "preferencesByProfileId", + "selectedOrganizationId", + "selectedProfileId", + ]), ]; const migrations: MigrationManifest = { diff --git a/gui/src/redux/thunks/profileAndOrg.ts b/gui/src/redux/thunks/profileAndOrg.ts deleted file mode 100644 index 0b378db66..000000000 --- a/gui/src/redux/thunks/profileAndOrg.ts +++ /dev/null @@ -1,133 +0,0 @@ -import { createAsyncThunk } from "@reduxjs/toolkit"; -import { ProfileDescription } from "core/config/ConfigHandler"; -import { OrganizationDescription } from "core/config/ProfileLifecycleManager"; -import { - setAvailableProfiles, - setOrganizations, - setSelectedOrganizationId, - setSelectedProfile, -} from "../slices/sessionSlice"; -import { ThunkApiType } from "../store"; - -export const selectProfileThunk = createAsyncThunk< - void, - string | null, - ThunkApiType ->("profiles/select", async (id, { dispatch, extra, getState }) => { - const state = getState(); - - if (state.session.availableProfiles === null) { - // Currently in loading state - return; - } - - const initialId = state.session.selectedProfileId; - - let newId = id; - - // If no profiles, force clear - if (state.session.availableProfiles.length === 0) { - newId = null; - } else { - // If new id doesn't match an existing profile, clear it - if (newId) { - if (!state.session.availableProfiles.find((p) => p.id === newId)) { - newId = null; - } - } - if (!newId) { - // At this point if null ID and there ARE profiles, - // Fallback to a profile, prioritizing the first in the list - newId = state.session.availableProfiles[0].id; - } - } - - // Only update if there's a change - if ((newId ?? null) !== (initialId ?? null)) { - dispatch(setSelectedProfile(newId)); - extra.ideMessenger.post("didChangeSelectedProfile", { - id: newId, - }); - } -}); - -export const cycleProfile = createAsyncThunk( - "profiles/cycle", - async (_, { dispatch, getState }) => { - const state = getState(); - - if (state.session.availableProfiles === null) { - return; - } - - const profileIds = state.session.availableProfiles.map( - (profile) => profile.id, - ); - // In case of no profiles just does nothing - if (profileIds.length === 0) { - return; - } - let nextId = profileIds[0]; - if (state.session.selectedProfileId) { - const curIndex = profileIds.indexOf(state.session.selectedProfileId); - const nextIndex = (curIndex + 1) % profileIds.length; - nextId = profileIds[nextIndex]; - } - await dispatch(selectProfileThunk(nextId)); - }, -); - -export const updateProfilesThunk = createAsyncThunk< - void, - { profiles: ProfileDescription[] | null; selectedProfileId: string | null }, - ThunkApiType ->("profiles/update", async (data, { dispatch, extra, getState }) => { - const { profiles, selectedProfileId } = data; - - dispatch(setAvailableProfiles(profiles)); - - // This will trigger reselection if needed - dispatch(selectProfileThunk(selectedProfileId)); -}); - -export const selectOrgThunk = createAsyncThunk< - void, - string | null, - ThunkApiType ->("session/selectOrg", async (id, { dispatch, extra, getState }) => { - const state = getState(); - const initialId = state.session.selectedOrganizationId; - let newId = id; - - // If no orgs, force clear - if (state.session.organizations.length === 0) { - newId = null; - } else if (newId) { - // If new id doesn't match an existing org, clear it - if (!state.session.organizations.find((o) => o.id === newId)) { - newId = null; - } - } - // Unlike profiles, don't fallback to the first org, - // Fallback to Personal (org = null) - - if (initialId !== newId) { - dispatch(setAvailableProfiles(null)); - dispatch(setSelectedOrganizationId(newId)); - extra.ideMessenger.post("didChangeSelectedOrg", { - id: newId, - }); - } -}); - -export const updateOrgsThunk = createAsyncThunk< - void, - OrganizationDescription[], - ThunkApiType ->("session/updateOrgs", async (orgs, { dispatch, getState }) => { - const state = getState(); - dispatch(setOrganizations(orgs)); - - // This will trigger reselection if needed - dispatch(selectOrgThunk(state.session.selectedOrganizationId)); -});