From 32161b6a52b0671ec19cac1a6b7a36ce48f13b40 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Tue, 18 Mar 2025 16:53:30 -0700 Subject: [PATCH 01/13] chore: remove tutorial card --- extensions/vscode/package-lock.json | 6 +- .../hooks/useSubmitOnboarding.ts | 7 +- gui/src/components/mainInput/TutorialCard.tsx | 100 ------------------ gui/src/hooks/useTutorialCard.ts | 32 ------ gui/src/pages/gui/Chat.tsx | 11 +- 5 files changed, 5 insertions(+), 151 deletions(-) delete mode 100644 gui/src/components/mainInput/TutorialCard.tsx delete mode 100644 gui/src/hooks/useTutorialCard.ts diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index a2492d0c8..f9b8bbf09 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "continue", - "version": "1.1.11", + "version": "1.1.12", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "continue", - "version": "1.1.11", + "version": "1.1.12", "license": "Apache-2.0", "dependencies": { "@continuedev/fetch": "^1.0.3", @@ -106,7 +106,7 @@ "@aws-sdk/client-sagemaker-runtime": "^3.758.0", "@aws-sdk/credential-providers": "^3.758.0", "@continuedev/config-types": "^1.0.13", - "@continuedev/config-yaml": "^1.0.60", + "@continuedev/config-yaml": "^1.0.63", "@continuedev/fetch": "^1.0.4", "@continuedev/llm-info": "^1.0.2", "@continuedev/openai-adapters": "^1.0.10", 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/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 ( -
-
-

-
- -
-
- - -
- ); -} 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/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx index 0c1b981bb..4458507f6 100644 --- a/gui/src/pages/gui/Chat.tsx +++ b/gui/src/pages/gui/Chat.tsx @@ -30,7 +30,6 @@ 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, @@ -42,7 +41,6 @@ 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"; @@ -145,7 +143,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, ); @@ -549,13 +546,7 @@ export function Chat() { )} - {showTutorialCard !== false && !onboardingCard.show && ( -
- -
- )} - - {!onboardingCard.show && showTutorialCard === false && ( + {!onboardingCard.show && (
From a73123e35ce29f1776b5afb456c9c67dc9495099 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Thu, 20 Mar 2025 14:45:57 -0700 Subject: [PATCH 02/13] feat: insert prompt into input on click --- .gitignore | 1 + core/commands/index.ts | 1 + core/commands/util.ts | 3 +- core/config/load.ts | 8 +-- .../profile/ControlPlaneProfileLoader.ts | 2 +- core/config/profile/PlatformProfileLoader.ts | 3 +- core/config/profile/doLoadConfig.ts | 2 + core/config/validation.ts | 1 + core/index.d.ts | 64 ++++++++++--------- .../v1/slashCommandFromPromptFile.ts | 1 + core/promptFiles/v2/parse.ts | 1 + core/promptFiles/v2/parsePromptFileV1V2.ts | 1 + core/promptFiles/v2/renderPromptFile.ts | 1 + core/protocol/core.ts | 9 ++- .../ConversationStarterCard.tsx | 34 ++++++++++ .../ConversationStarterCards.tsx | 27 ++++++++ .../components/ConversationStarters/index.ts | 1 + .../components/ConversationStarters/utils.ts | 18 ++++++ gui/src/components/mainInput/InputToolbar.tsx | 1 - gui/src/components/mainInput/TipTapEditor.tsx | 3 +- gui/src/components/mainInput/utils.ts | 18 ++++++ gui/src/pages/gui/Chat.tsx | 29 ++------- gui/src/pages/gui/EmptyChatBody.tsx | 33 ++++++++++ 23 files changed, 195 insertions(+), 67 deletions(-) create mode 100644 gui/src/components/ConversationStarters/ConversationStarterCard.tsx create mode 100644 gui/src/components/ConversationStarters/ConversationStarterCards.tsx create mode 100644 gui/src/components/ConversationStarters/index.ts create mode 100644 gui/src/components/ConversationStarters/utils.ts create mode 100644 gui/src/components/mainInput/utils.ts create mode 100644 gui/src/pages/gui/EmptyChatBody.tsx 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/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 cf2bcf5ac..d9c789404 100644 --- a/core/config/load.ts +++ b/core/config/load.ts @@ -667,11 +667,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 9182e3415..b4aae9b78 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 224b7b64e..e208d6db2 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, @@ -26,6 +27,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/index.d.ts b/core/index.d.ts index 4c21e326e..355fa333c 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -43,13 +43,13 @@ export interface IndexingProgressUpdate { desc: string; shouldClearIndexes?: boolean; status: - | "loading" - | "indexing" - | "done" - | "failed" - | "paused" - | "disabled" - | "cancelled"; + | "loading" + | "indexing" + | "done" + | "failed" + | "paused" + | "disabled" + | "cancelled"; debugInfo?: string; } @@ -164,7 +164,11 @@ export interface ILLM extends LLMOptions { } export interface ModelInstaller { - installModel(modelName: string, signal: AbortSignal, progressReporter?: (task: string, increment: number, total: number) => void): Promise; + installModel( + modelName: string, + signal: AbortSignal, + progressReporter?: (task: string, increment: number, total: number) => void, + ): Promise; } export type ContextProviderType = "normal" | "query" | "submenu"; @@ -312,7 +316,12 @@ export interface CompletionOptions extends BaseCompletionOptions { model: string; } -export type ChatMessageRole = "user" | "assistant" | "thinking" | "system" | "tool"; +export type ChatMessageRole = + | "user" + | "assistant" + | "thinking" + | "system" + | "tool"; export type TextMessagePart = { type: "text"; @@ -688,10 +697,10 @@ export interface IDE { getCurrentFile(): Promise< | undefined | { - isUntitled: boolean; - path: string; - contents: string; - } + isUntitled: boolean; + path: string; + contents: string; + } >; getLastFileSaveTimestamp?(): number; @@ -757,6 +766,7 @@ export interface ContinueSDK { export interface SlashCommand { name: string; description: string; + prompt?: string; params?: { [key: string]: any }; run: (sdk: ContinueSDK) => AsyncGenerator; } @@ -860,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; @@ -875,11 +881,11 @@ export interface CustomCommand { export interface Prediction { type: "content"; content: - | string - | { - type: "text"; - text: string; - }[]; + | string + | { + type: "text"; + text: string; + }[]; } export interface ToolExtras { @@ -1219,9 +1225,9 @@ export interface Config { embeddingsProvider?: EmbeddingsProviderDescription | ILLM; /** The model that Continue will use for tab autocompletions. */ tabAutocompleteModel?: - | CustomLLM - | ModelDescription - | (CustomLLM | ModelDescription)[]; + | CustomLLM + | ModelDescription + | (CustomLLM | ModelDescription)[]; /** Options for tab autocomplete */ tabAutocompleteOptions?: Partial; /** UI styles customization */ @@ -1313,9 +1319,9 @@ export type PackageDetailsSuccess = PackageDetails & { export type PackageDocsResult = { packageInfo: ParsedPackageInfo; } & ( - | { error: string; details?: never } - | { details: PackageDetailsSuccess; error?: never } - ); + | { error: string; details?: never } + | { details: PackageDetailsSuccess; error?: never } +); export interface TerminalOptions { reuseTerminal?: boolean; diff --git a/core/promptFiles/v1/slashCommandFromPromptFile.ts b/core/promptFiles/v1/slashCommandFromPromptFile.ts index b0dc0f881..833955d0d 100644 --- a/core/promptFiles/v1/slashCommandFromPromptFile.ts +++ b/core/promptFiles/v1/slashCommandFromPromptFile.ts @@ -63,6 +63,7 @@ export function slashCommandFromPromptFileV1( 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 138c7e9d3..d2d45d0fa 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, @@ -28,7 +32,6 @@ import type { SiteIndexingConfig, ToolCall, } from "../"; -import { GlobalContextModelSelections } from "../util/GlobalContext"; export type OnboardingModes = "Local" | "Best" | "Custom" | "Quickstart"; diff --git a/gui/src/components/ConversationStarters/ConversationStarterCard.tsx b/gui/src/components/ConversationStarters/ConversationStarterCard.tsx new file mode 100644 index 000000000..6714287c1 --- /dev/null +++ b/gui/src/components/ConversationStarters/ConversationStarterCard.tsx @@ -0,0 +1,34 @@ +import { ChatBubbleLeftIcon } from "@heroicons/react/24/outline"; +import { SlashCommandDescription } from "core"; +import { defaultBorderRadius, vscInputBackground } from ".."; + +interface ConversationStarterCardProps { + command: SlashCommandDescription; + onClick: (command: SlashCommandDescription) => void; +} + +export function ConversationStarterCard({ + command, + onClick, +}: ConversationStarterCardProps) { + return ( +
onClick(command)} + className="mb-2 w-full shadow-md hover:cursor-pointer hover:brightness-110" + style={{ + borderRadius: defaultBorderRadius, + backgroundColor: vscInputBackground, + }} + > +
+
+ +
+
+
{command.name}
+
{command.description}
+
+
+
+ ); +} diff --git a/gui/src/components/ConversationStarters/ConversationStarterCards.tsx b/gui/src/components/ConversationStarters/ConversationStarterCards.tsx new file mode 100644 index 000000000..f3dcda317 --- /dev/null +++ b/gui/src/components/ConversationStarters/ConversationStarterCards.tsx @@ -0,0 +1,27 @@ +import { SlashCommandDescription } from "core"; +import { useAppDispatch, useAppSelector } from "../../redux/hooks"; +import { setMainEditorContentTrigger } from "../../redux/slices/sessionSlice"; +import { getParagraphNodeFromString } from "../mainInput/utils"; +import { ConversationStarterCard } from "./ConversationStarterCard"; +import { isDeprecatedCommandName } from "./utils"; + +export function ConversationStarterCards() { + const dispatch = useAppDispatch(); + const slashCommands = useAppSelector( + (state) => state.config.config.slashCommands, + ); + + const filteredSlashCommands = slashCommands?.filter(isDeprecatedCommandName); + + function onClick(command: SlashCommandDescription) { + if (command.prompt) { + dispatch( + setMainEditorContentTrigger(getParagraphNodeFromString(command.prompt)), + ); + } + } + + return filteredSlashCommands?.map((command) => ( + + )); +} 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/utils.ts b/gui/src/components/ConversationStarters/utils.ts new file mode 100644 index 000000000..b1ca8859c --- /dev/null +++ b/gui/src/components/ConversationStarters/utils.ts @@ -0,0 +1,18 @@ +import { SlashCommandDescription } from "core"; + +const DEPRECATED_SLASH_COMMAND_NAMES = ["share", "cmd"]; + +/** + * 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. + * + * 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) { + return !DEPRECATED_SLASH_COMMAND_NAMES.includes(command.name); +} 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/TipTapEditor.tsx b/gui/src/components/mainInput/TipTapEditor.tsx index 7c1ace735..49dc3ce84 100644 --- a/gui/src/components/mainInput/TipTapEditor.tsx +++ b/gui/src/components/mainInput/TipTapEditor.tsx @@ -302,7 +302,7 @@ function TipTapEditor(props: TipTapEditorProps) { } // Ensure we're using the correct history key - chat for main input, edit for edit mode - const historyKey = props.historyKey === 'edit' ? 'edit' : 'chat'; + const historyKey = props.historyKey === "edit" ? "edit" : "chat"; const { prevRef, nextRef, addRef } = useInputHistory(historyKey); const editor: Editor | null = useEditor({ @@ -996,7 +996,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/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/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx index 4458507f6..973420cba 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"; @@ -31,11 +30,7 @@ import { NewSessionButton } from "../../components/mainInput/NewSessionButton"; import resolveEditorContent from "../../components/mainInput/resolveInput"; import ThinkingBlockPeek from "../../components/mainInput/ThinkingBlockPeek"; 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"; @@ -76,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"; @@ -535,23 +531,10 @@ export function Chat() { {!hasDismissedExploreDialog && } {history.length === 0 && ( - <> - {onboardingCard.show && ( -
- {useHub ? ( - - ) : ( - - )} -
- )} - - {!onboardingCard.show && ( -
- -
- )} - + )} diff --git a/gui/src/pages/gui/EmptyChatBody.tsx b/gui/src/pages/gui/EmptyChatBody.tsx new file mode 100644 index 000000000..a81143b8d --- /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 ( +
+ + +
+ ); +} From 1d1f705f7dfb1d517b90e03b82856e625f3f323e Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Thu, 20 Mar 2025 16:58:29 -0700 Subject: [PATCH 03/13] feat: move .prompts into slash cmd --- core/config/load.ts | 3 - core/config/yaml/loadYaml.ts | 2 - .../providers/PromptFilesContextProvider.ts | 57 ------------ .../v1/slashCommandFromPromptFile.ts | 10 +-- core/util/paths.ts | 2 +- .../ConversationStarterCard.tsx | 8 +- .../ConversationStarterCards.tsx | 53 ++++++++++-- .../components/ConversationStarters/utils.ts | 17 +++- gui/src/components/mainInput/MentionList.tsx | 6 +- gui/src/components/mainInput/TipTapEditor.tsx | 2 +- gui/src/components/mainInput/getSuggestion.ts | 53 +++++++----- gui/src/pages/config/ModelRoleSelector.tsx | 86 ++++++++++--------- gui/src/pages/gui/EmptyChatBody.tsx | 4 +- gui/src/redux/selectors/index.ts | 2 +- 14 files changed, 153 insertions(+), 152 deletions(-) delete mode 100644 core/context/providers/PromptFilesContextProvider.ts diff --git a/core/config/load.ts b/core/config/load.ts index d9c789404..0216894e1 100644 --- a/core/config/load.ts +++ b/core/config/load.ts @@ -45,7 +45,6 @@ import ContinueProxyContextProvider from "../context/providers/ContinueProxyCont import CustomContextProviderClass from "../context/providers/CustomContextProvider"; import FileContextProvider from "../context/providers/FileContextProvider"; import { contextProviderClassFromName } from "../context/providers/index"; -import PromptFilesContextProvider from "../context/providers/PromptFilesContextProvider"; import { useHub } from "../control-plane/env"; import { allEmbeddingsProviders } from "../indexing/allEmbeddingsProviders"; import { BaseLLM } from "../llm"; @@ -401,8 +400,6 @@ async function intermediateToFinalConfig( ...(!config.disableIndexing ? [new CodebaseContextProvider(codebaseContextParams)] : []), - // Add prompt files provider if enabled - ...(loadPromptFiles ? [new PromptFilesContextProvider({})] : []), ]; const DEFAULT_CONTEXT_PROVIDERS_TITLES = DEFAULT_CONTEXT_PROVIDERS.map( diff --git a/core/config/yaml/loadYaml.ts b/core/config/yaml/loadYaml.ts index a11e1ab44..ae1f13f58 100644 --- a/core/config/yaml/loadYaml.ts +++ b/core/config/yaml/loadYaml.ts @@ -28,7 +28,6 @@ import CodebaseContextProvider from "../../context/providers/CodebaseContextProv import DocsContextProvider from "../../context/providers/DocsContextProvider"; import FileContextProvider from "../../context/providers/FileContextProvider"; import { contextProviderClassFromName } from "../../context/providers/index"; -import PromptFilesContextProvider from "../../context/providers/PromptFilesContextProvider"; import { ControlPlaneClient } from "../../control-plane/client"; import { allEmbeddingsProviders } from "../../indexing/allEmbeddingsProviders"; import FreeTrial from "../../llm/llms/FreeTrial"; @@ -333,7 +332,6 @@ async function configYamlToContinueConfig( const DEFAULT_CONTEXT_PROVIDERS = [ new FileContextProvider({}), new CodebaseContextProvider(codebaseContextParams), - new PromptFilesContextProvider({}), ]; const DEFAULT_CONTEXT_PROVIDERS_TITLES = DEFAULT_CONTEXT_PROVIDERS.map( diff --git a/core/context/providers/PromptFilesContextProvider.ts b/core/context/providers/PromptFilesContextProvider.ts deleted file mode 100644 index c3b4381f4..000000000 --- a/core/context/providers/PromptFilesContextProvider.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { BaseContextProvider } from ".."; -import { - ContextItem, - ContextProviderDescription, - ContextProviderExtras, - ContextSubmenuItem, - LoadSubmenuItemsArgs, -} from "../../"; -import { getAllPromptFiles } from "../../promptFiles/v2/getPromptFiles"; -import { parsePreamble } from "../../promptFiles/v2/parse"; -import { renderPromptFileV2 } from "../../promptFiles/v2/renderPromptFile"; - -class PromptFilesContextProvider extends BaseContextProvider { - static description: ContextProviderDescription = { - title: "prompt-files", - displayTitle: "Prompt Files", - description: ".prompt files", - type: "submenu", - }; - - async getContextItems( - query: string, - extras: ContextProviderExtras, - ): Promise { - const rawContent = await extras.ide.readFile(query); - const preamble = parsePreamble(query, rawContent); - const [contextItems, body] = await renderPromptFileV2(rawContent, extras); - return [ - ...contextItems, - { - content: body, - name: preamble.name, - description: preamble.description, - }, - ]; - } - - async loadSubmenuItems( - args: LoadSubmenuItemsArgs, - ): Promise { - const promptFiles = await getAllPromptFiles( - args.ide, - args.config.experimental?.promptPath, - // Note, NOT checking v1 default folder here, deprecated for context provider - ); - return promptFiles.map((file) => { - const preamble = parsePreamble(file.path, file.content); - return { - id: file.path, - title: preamble.name, - description: preamble.description, - }; - }); - } -} - -export default PromptFilesContextProvider; diff --git a/core/promptFiles/v1/slashCommandFromPromptFile.ts b/core/promptFiles/v1/slashCommandFromPromptFile.ts index 833955d0d..f051dfe59 100644 --- a/core/promptFiles/v1/slashCommandFromPromptFile.ts +++ b/core/promptFiles/v1/slashCommandFromPromptFile.ts @@ -53,12 +53,10 @@ export function slashCommandFromPromptFileV1( path: string, content: string, ): SlashCommand | null { - const { name, description, systemMessage, prompt, version } = - parsePromptFileV1V2(path, content); - - if (version !== 1) { - return null; - } + const { name, description, systemMessage, prompt } = parsePromptFileV1V2( + path, + content, + ); return { name, diff --git a/core/util/paths.ts b/core/util/paths.ts index 3bc2ee3cf..0fa64d109 100644 --- a/core/util/paths.ts +++ b/core/util/paths.ts @@ -2,10 +2,10 @@ import * as fs from "fs"; import * as os from "os"; import * as path from "path"; +import { DevEventName } from "@continuedev/config-yaml"; import * as JSONC from "comment-json"; import dotenv from "dotenv"; -import { DevEventName } from "@continuedev/config-yaml"; import { IdeType, SerializedContinueConfig } from "../"; import { defaultConfig, defaultConfigJetBrains } from "../config/default"; import Types from "../config/types"; diff --git a/gui/src/components/ConversationStarters/ConversationStarterCard.tsx b/gui/src/components/ConversationStarters/ConversationStarterCard.tsx index 6714287c1..35a205481 100644 --- a/gui/src/components/ConversationStarters/ConversationStarterCard.tsx +++ b/gui/src/components/ConversationStarters/ConversationStarterCard.tsx @@ -20,13 +20,13 @@ export function ConversationStarterCard({ backgroundColor: vscInputBackground, }} > -
+
- +
-
{command.name}
-
{command.description}
+
{command.name}
+
{command.description}
diff --git a/gui/src/components/ConversationStarters/ConversationStarterCards.tsx b/gui/src/components/ConversationStarters/ConversationStarterCards.tsx index f3dcda317..69020dae5 100644 --- a/gui/src/components/ConversationStarters/ConversationStarterCards.tsx +++ b/gui/src/components/ConversationStarters/ConversationStarterCards.tsx @@ -1,18 +1,28 @@ import { SlashCommandDescription } from "core"; +import { useState } from "react"; import { useAppDispatch, useAppSelector } from "../../redux/hooks"; import { setMainEditorContentTrigger } from "../../redux/slices/sessionSlice"; import { getParagraphNodeFromString } from "../mainInput/utils"; import { ConversationStarterCard } from "./ConversationStarterCard"; import { isDeprecatedCommandName } from "./utils"; +const NUM_CARDS_TO_RENDER_COLLAPSED = 3; + export function ConversationStarterCards() { const dispatch = useAppDispatch(); - const slashCommands = useAppSelector( - (state) => state.config.config.slashCommands, - ); + const [isExpanded, setIsExpanded] = useState(false); + const slashCommands = + useAppSelector((state) => state.config.config.slashCommands) ?? []; const filteredSlashCommands = slashCommands?.filter(isDeprecatedCommandName); + const numFilteredSlashCommands = filteredSlashCommands.length; + const displayedCommands = isExpanded + ? filteredSlashCommands + : filteredSlashCommands.slice(0, NUM_CARDS_TO_RENDER_COLLAPSED); + const hasMoreCommands = + numFilteredSlashCommands > NUM_CARDS_TO_RENDER_COLLAPSED; + function onClick(command: SlashCommandDescription) { if (command.prompt) { dispatch( @@ -21,7 +31,38 @@ export function ConversationStarterCards() { } } - return filteredSlashCommands?.map((command) => ( - - )); + function handleToggleExpand() { + setIsExpanded(!isExpanded); + } + + if (!filteredSlashCommands || filteredSlashCommands.length === 0) { + return null; + } + + return ( +
+

Prompts

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

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

+ )} +
+ ); } diff --git a/gui/src/components/ConversationStarters/utils.ts b/gui/src/components/ConversationStarters/utils.ts index b1ca8859c..aab6cb414 100644 --- a/gui/src/components/ConversationStarters/utils.ts +++ b/gui/src/components/ConversationStarters/utils.ts @@ -1,12 +1,17 @@ import { SlashCommandDescription } from "core"; - -const DEPRECATED_SLASH_COMMAND_NAMES = ["share", "cmd"]; +import { + defaultSlashCommandsJetBrains, + defaultSlashCommandsVscode, +} from "core/config/default"; +import { isJetBrains } from "../../util"; /** * The commands filtered here are currently inserted into the slash commands array during * intermediary config loading, but once we get the actual prompts for an assistant, * they are overwritten. * + * Additionally, these default commands are all deprecated. + * * If we don't manually filter them out, then they are displayed in the UI * while the assistant is still loading. * @@ -14,5 +19,11 @@ const DEPRECATED_SLASH_COMMAND_NAMES = ["share", "cmd"]; * this function can be removed. */ export function isDeprecatedCommandName(command: SlashCommandDescription) { - return !DEPRECATED_SLASH_COMMAND_NAMES.includes(command.name); + const defaultCommands = isJetBrains() + ? defaultSlashCommandsJetBrains + : defaultSlashCommandsVscode; + + return !defaultCommands.find( + (defaultCommand) => defaultCommand.name === command.name, + ); } diff --git a/gui/src/components/mainInput/MentionList.tsx b/gui/src/components/mainInput/MentionList.tsx index 94324b75e..5ba1bcca4 100644 --- a/gui/src/components/mainInput/MentionList.tsx +++ b/gui/src/components/mainInput/MentionList.tsx @@ -3,9 +3,9 @@ import { ArrowUpOnSquareIcon, AtSymbolIcon, Bars3BottomLeftIcon, - BoltIcon, BookOpenIcon, BugAntIcon, + ChatBubbleLeftIcon, CircleStackIcon, CodeBracketIcon, CommandLineIcon, @@ -88,7 +88,8 @@ export function getIconFromDropdownItem( id: string | undefined, type: ComboBoxItemType, ) { - const typeIcon = type === "contextProvider" ? AtSymbolIcon : BoltIcon; + const typeIcon = + type === "contextProvider" ? AtSymbolIcon : ChatBubbleLeftIcon; return id ? (ICONS_FOR_DROPDOWN[id] ?? typeIcon) : typeIcon; } @@ -506,7 +507,6 @@ const MentionList = forwardRef((props: MentionListProps, ref) => { ) : ( No results )} - {/* */} )} diff --git a/gui/src/components/mainInput/TipTapEditor.tsx b/gui/src/components/mainInput/TipTapEditor.tsx index 49dc3ce84..3849ecd3f 100644 --- a/gui/src/components/mainInput/TipTapEditor.tsx +++ b/gui/src/components/mainInput/TipTapEditor.tsx @@ -565,7 +565,7 @@ function TipTapEditor(props: TipTapEditorProps) { } return historyLength === 0 - ? "Ask anything, '@' to add context" + ? "Ask anything, '/' for prompts, '@' to add context" : "Ask a follow-up"; } diff --git a/gui/src/components/mainInput/getSuggestion.ts b/gui/src/components/mainInput/getSuggestion.ts index ecc7b835e..ab107f146 100644 --- a/gui/src/components/mainInput/getSuggestion.ts +++ b/gui/src/components/mainInput/getSuggestion.ts @@ -8,8 +8,8 @@ import { MutableRefObject } from "react"; import tippy from "tippy.js"; import { IIdeMessenger } from "../../context/IdeMessenger"; import MentionList from "./MentionList"; -import { ComboBoxItem, ComboBoxItemType, ComboBoxSubAction } from "./types"; import { TIPPY_DIV_ID } from "./TipTapEditor"; +import { ComboBoxItem, ComboBoxItemType, ComboBoxSubAction } from "./types"; function getSuggestion( items: (props: { query: string }) => Promise, @@ -198,27 +198,18 @@ export function getSlashCommandDropdownOptions( ideMessenger: IIdeMessenger, ) { const items = async ({ query }: { query: string }) => { - const options = [ - ...availableSlashCommandsRef.current, - // { - // title: "Build a custom prompt", - // description: "Build a custom prompt", - // type: "action", - // id: "createPromptFile", - // label: "Create Prompt File", - // action: () => { - // ideMessenger.post("config/newPromptFile", undefined); - // }, - // name: "Create Prompt File", - // }, - ]; - return ( - options.filter((slashCommand) => { - const sc = slashCommand.title.substring(1).toLowerCase(); - const iv = query.toLowerCase(); - return sc.startsWith(iv); - }) || [] - ).map((provider) => ({ + const options = [...availableSlashCommandsRef.current]; + + const filteredCommands = + query.length > 0 + ? options.filter((slashCommand) => { + const sc = slashCommand.title.substring(1).toLowerCase(); + const iv = query.toLowerCase(); + return sc.startsWith(iv); + }) + : options; + + const commandItems = (filteredCommands || []).map((provider) => ({ name: provider.title, description: provider.description, id: provider.title, @@ -227,6 +218,24 @@ export function getSlashCommandDropdownOptions( type: (provider.type ?? "slashCommand") as ComboBoxItemType, action: provider.action, })); + + if (query.length === 0 && commandItems.length > 0) { + commandItems.push({ + title: "Explore prompts", + type: "action", + action: () => + ideMessenger.post( + "openUrl", + "https://hub.continue.dev/explore/prompts", + ), + description: "", + name: "", + id: "", + label: "", + }); + } + + return commandItems; }; return getSuggestion(items, undefined, onClose, onOpen); } diff --git a/gui/src/pages/config/ModelRoleSelector.tsx b/gui/src/pages/config/ModelRoleSelector.tsx index 163f86b76..d9d6196a7 100644 --- a/gui/src/pages/config/ModelRoleSelector.tsx +++ b/gui/src/pages/config/ModelRoleSelector.tsx @@ -1,12 +1,15 @@ -import { Fragment } from "react"; import { Listbox, Transition } from "@headlessui/react"; import { ChevronUpDownIcon, InformationCircleIcon, } from "@heroicons/react/24/outline"; import { type ModelDescription } from "core"; +import { Fragment } from "react"; import { ToolTip } from "../../components/gui/Tooltip"; +/** + * A component for selecting a model for a specific role + */ interface ModelRoleSelectorProps { models: ModelDescription[]; selectedModel: ModelDescription | null; @@ -38,56 +41,57 @@ const ModelRoleSelector = ({ {description} - - {({ open }) => ( -
- - {models.length === 0 ? ( - {`No ${displayName} models${["Chat", "Apply", "Edit"].includes(displayName) ? ". Using chat model" : ""}`} - ) : ( + + {models.length === 0 ? ( + + {["Chat", "Apply", "Edit"].includes(displayName) + ? "None (defaulting to Chat model)" + : "None"} + + ) : ( + + {({ open }) => ( +
+ {selectedModel?.title ?? `Select ${displayName} model`} - )} - {models.length ? (
- ) : null} -
+ - - - {models.map((option, idx) => ( - - - {option.title} - - - ))} - - -
- )} -
+ + + {models.map((option, idx) => ( + + + {option.title} + + + ))} + + +
+ )} +
+ )} ); }; diff --git a/gui/src/pages/gui/EmptyChatBody.tsx b/gui/src/pages/gui/EmptyChatBody.tsx index a81143b8d..dce70cdd5 100644 --- a/gui/src/pages/gui/EmptyChatBody.tsx +++ b/gui/src/pages/gui/EmptyChatBody.tsx @@ -25,9 +25,9 @@ export function EmptyChatBody({ } return ( -
- +
+
); } diff --git a/gui/src/redux/selectors/index.ts b/gui/src/redux/selectors/index.ts index 2097dbce8..3d46bf9ea 100644 --- a/gui/src/redux/selectors/index.ts +++ b/gui/src/redux/selectors/index.ts @@ -8,7 +8,7 @@ export const selectSlashCommandComboBoxInputs = createSelector( return ( slashCommands?.map((cmd) => { return { - title: `/${cmd.name}`, + title: `${cmd.name}`, description: cmd.description, type: "slashCommand" as ComboBoxItemType, }; From d3f4aeb4c676cc4d5e090fa2ea6e497f965a3acd Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Fri, 21 Mar 2025 11:04:04 -0700 Subject: [PATCH 04/13] feat: add bookmark logic --- extensions/vscode/src/VsCodeIde.ts | 2 +- .../ConversationStarterCard.tsx | 42 ++++++++++-- .../ConversationStarterCards.tsx | 43 +++++------- gui/src/components/index.ts | 4 +- .../platform/AssistantSelect.tsx | 2 +- .../platform/AssistantSelectOptions.tsx | 2 +- gui/src/context/Auth.tsx | 12 ++-- gui/src/hooks/useSetup.ts | 2 +- gui/src/pages/config/ScopeSelect.tsx | 4 +- gui/src/pages/config/index.tsx | 2 +- gui/src/pages/gui/StreamError.tsx | 2 +- gui/src/redux/slices/profiles/index.ts | 2 + gui/src/redux/slices/profiles/slice.ts | 59 +++++++++++++++++ .../profiles/thunks.ts} | 32 ++++----- gui/src/redux/slices/sessionSlice.ts | 66 ++++--------------- gui/src/redux/store.ts | 15 +++-- 16 files changed, 165 insertions(+), 126 deletions(-) create mode 100644 gui/src/redux/slices/profiles/index.ts create mode 100644 gui/src/redux/slices/profiles/slice.ts rename gui/src/redux/{thunks/profileAndOrg.ts => slices/profiles/thunks.ts} (76%) diff --git a/extensions/vscode/src/VsCodeIde.ts b/extensions/vscode/src/VsCodeIde.ts index 1aaa10283..c324edaf2 100644 --- a/extensions/vscode/src/VsCodeIde.ts +++ b/extensions/vscode/src/VsCodeIde.ts @@ -529,7 +529,7 @@ class VsCodeIde implements IDE { const tabArray = vscode.window.tabGroups.all[0].tabs; return tabArray - .filter((t) => t.isPinned) + .filter((t) => t.isBookmarked) .map((t) => (t.input as vscode.TabInputText).uri.toString()); } diff --git a/gui/src/components/ConversationStarters/ConversationStarterCard.tsx b/gui/src/components/ConversationStarters/ConversationStarterCard.tsx index 35a205481..1542adadf 100644 --- a/gui/src/components/ConversationStarters/ConversationStarterCard.tsx +++ b/gui/src/components/ConversationStarters/ConversationStarterCard.tsx @@ -1,33 +1,63 @@ -import { ChatBubbleLeftIcon } from "@heroicons/react/24/outline"; +import { BookmarkIcon, ChatBubbleLeftIcon } from "@heroicons/react/24/outline"; +import { BookmarkIcon as BookmarkIconSolid } from "@heroicons/react/24/solid"; import { SlashCommandDescription } from "core"; -import { defaultBorderRadius, vscInputBackground } from ".."; +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 (
onClick(command)} - className="mb-2 w-full shadow-md hover:cursor-pointer hover:brightness-110" + className="mb-2 w-full shadow-md hover:brightness-110" style={{ borderRadius: defaultBorderRadius, backgroundColor: vscInputBackground, }} + onMouseEnter={() => 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 index 69020dae5..8df9cd908 100644 --- a/gui/src/components/ConversationStarters/ConversationStarterCards.tsx +++ b/gui/src/components/ConversationStarters/ConversationStarterCards.tsx @@ -10,19 +10,13 @@ const NUM_CARDS_TO_RENDER_COLLAPSED = 3; export function ConversationStarterCards() { const dispatch = useAppDispatch(); - const [isExpanded, setIsExpanded] = useState(false); + const [bookmarkedCommands, setBookmarkedCommands] = useState([]); + const slashCommands = useAppSelector((state) => state.config.config.slashCommands) ?? []; const filteredSlashCommands = slashCommands?.filter(isDeprecatedCommandName); - const numFilteredSlashCommands = filteredSlashCommands.length; - const displayedCommands = isExpanded - ? filteredSlashCommands - : filteredSlashCommands.slice(0, NUM_CARDS_TO_RENDER_COLLAPSED); - const hasMoreCommands = - numFilteredSlashCommands > NUM_CARDS_TO_RENDER_COLLAPSED; - function onClick(command: SlashCommandDescription) { if (command.prompt) { dispatch( @@ -31,8 +25,14 @@ export function ConversationStarterCards() { } } - function handleToggleExpand() { - setIsExpanded(!isExpanded); + function handleBookmarkCommand(command: SlashCommandDescription) { + setBookmarkedCommands((prev) => { + if (prev.includes(command.name)) { + return prev.filter((name) => name !== command.name); + } else { + return [...prev, command.name]; + } + }); } if (!filteredSlashCommands || filteredSlashCommands.length === 0) { @@ -40,29 +40,18 @@ export function ConversationStarterCards() { } return ( -
-

Prompts

- -
- {displayedCommands.map((command, i) => ( +
+ {filteredSlashCommands + .slice(0, NUM_CARDS_TO_RENDER_COLLAPSED) + .map((command, i) => ( ))} -
- - {hasMoreCommands && ( -

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

- )}
); } 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/modelSelection/platform/AssistantSelect.tsx b/gui/src/components/modelSelection/platform/AssistantSelect.tsx index a4dde488d..4e1925ce4 100644 --- a/gui/src/components/modelSelection/platform/AssistantSelect.tsx +++ b/gui/src/components/modelSelection/platform/AssistantSelect.tsx @@ -5,7 +5,7 @@ import { useContext, useEffect, useRef } from "react"; import { useAuth } from "../../../context/Auth"; import { IdeMessengerContext } from "../../../context/IdeMessenger"; import { useAppDispatch } from "../../../redux/hooks"; -import { cycleProfile } from "../../../redux/thunks/profileAndOrg"; +import { cycleProfile } from "../../../redux/slices/profiles/thunks"; 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..de4db1422 100644 --- a/gui/src/components/modelSelection/platform/AssistantSelectOptions.tsx +++ b/gui/src/components/modelSelection/platform/AssistantSelectOptions.tsx @@ -6,7 +6,7 @@ import { lightGray } from "../.."; import { useAuth } from "../../../context/Auth"; import { IdeMessengerContext } from "../../../context/IdeMessenger"; import { useAppDispatch } from "../../../redux/hooks"; -import { selectProfileThunk } from "../../../redux/thunks/profileAndOrg"; +import { selectProfileThunk } from "../../../redux/slices/profiles/thunks"; 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 d4e6f7925..844ba1aa3 100644 --- a/gui/src/context/Auth.tsx +++ b/gui/src/context/Auth.tsx @@ -14,11 +14,11 @@ import ConfirmationDialog from "../components/dialogs/ConfirmationDialog"; import { useWebviewListener } from "../hooks/useWebviewListener"; import { useAppDispatch, useAppSelector } from "../redux/hooks"; import { setLastControlServerBetaEnabledStatus } from "../redux/slices/miscSlice"; -import { setDialogMessage, setShowDialog } from "../redux/slices/uiSlice"; import { updateOrgsThunk, updateProfilesThunk, -} from "../redux/thunks/profileAndOrg"; +} from "../redux/slices/profiles/thunks"; +import { setDialogMessage, setShowDialog } from "../redux/slices/uiSlice"; import { IdeMessengerContext } from "./IdeMessenger"; interface AuthContextType { @@ -47,9 +47,9 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ ); // Orgs - const orgs = useAppSelector((store) => store.session.organizations); + const orgs = useAppSelector((store) => store.profiles.organizations); const selectedOrgId = useAppSelector( - (store) => store.session.selectedOrganizationId, + (store) => store.profiles.selectedOrganizationId, ); const selectedOrganization = useMemo(() => { if (!selectedOrgId) { @@ -59,9 +59,9 @@ 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( - (store) => store.session.selectedProfile, + (store) => store.profiles.selectedProfile, ); const login: AuthContextType["login"] = (useOnboarding: boolean) => { diff --git a/gui/src/hooks/useSetup.ts b/gui/src/hooks/useSetup.ts index 9d7f607b5..c45c2323c 100644 --- a/gui/src/hooks/useSetup.ts +++ b/gui/src/hooks/useSetup.ts @@ -11,12 +11,12 @@ import { } from "../redux/slices/configSlice"; import { updateIndexingStatus } from "../redux/slices/indexingSlice"; import { updateDocsSuggestions } from "../redux/slices/miscSlice"; +import { selectProfileThunk } from "../redux/slices/profiles/thunks"; import { addContextItemsAtIndex, 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/pages/config/ScopeSelect.tsx b/gui/src/pages/config/ScopeSelect.tsx index 2d42483a0..3b001a421 100644 --- a/gui/src/pages/config/ScopeSelect.tsx +++ b/gui/src/pages/config/ScopeSelect.tsx @@ -7,12 +7,12 @@ import { import { useAuth } from "../../context/Auth"; import { useWebviewListener } from "../../hooks/useWebviewListener"; import { useAppDispatch, useAppSelector } from "../../redux/hooks"; -import { selectOrgThunk } from "../../redux/thunks/profileAndOrg"; +import { selectOrgThunk } from "../../redux/slices/profiles/thunks"; export function ScopeSelect() { const { organizations, selectedOrganization } = useAuth(); const selectedOrgId = useAppSelector( - (state) => state.session.selectedOrganizationId, + (state) => state.profiles.selectedOrganizationId, ); const dispatch = useAppDispatch(); diff --git a/gui/src/pages/config/index.tsx b/gui/src/pages/config/index.tsx index 3cf9b84a2..90530fa3a 100644 --- a/gui/src/pages/config/index.tsx +++ b/gui/src/pages/config/index.tsx @@ -29,7 +29,7 @@ import { setDefaultModel, updateConfig, } from "../../redux/slices/configSlice"; -import { selectProfileThunk } from "../../redux/thunks/profileAndOrg"; +import { selectProfileThunk } from "../../redux/slices/profiles/thunks"; import { getFontSize, isJetBrains } from "../../util"; import ModelRoleSelector from "./ModelRoleSelector"; import { ScopeSelect } from "./ScopeSelect"; diff --git a/gui/src/pages/gui/StreamError.tsx b/gui/src/pages/gui/StreamError.tsx index 7e372720c..b575ef0ec 100644 --- a/gui/src/pages/gui/StreamError.tsx +++ b/gui/src/pages/gui/StreamError.tsx @@ -22,7 +22,7 @@ const StreamErrorDialog = ({ error }: StreamErrorProps) => { const selectedModel = useAppSelector(selectDefaultModel); const hubEnabled = useAppSelector(selectUseHub); const selectedProfile = useAppSelector( - (store) => store.session.selectedProfile, + (store) => store.profiles.selectedProfile, ); const { session, refreshProfiles } = useAuth(); 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..b160c54b9 --- /dev/null +++ b/gui/src/redux/slices/profiles/slice.ts @@ -0,0 +1,59 @@ +import { createSlice, PayloadAction } from "@reduxjs/toolkit"; +import { ProfileDescription } from "core/config/ConfigHandler"; +import { OrganizationDescription } from "core/config/ProfileLifecycleManager"; + +interface ProfilesState { + availableProfiles: ProfileDescription[] | null; + selectedProfile: ProfileDescription | null; + organizations: OrganizationDescription[]; + selectedOrganizationId: string | null; +} + +const initialState: ProfilesState = { + availableProfiles: null, + selectedProfile: null, + organizations: [], + selectedOrganizationId: null, +}; + +export const profilesSlice = createSlice({ + name: "profiles", + initialState, + // Important: these reducers don't handle selected profile/organization fallback logic + // That is done in thunks + reducers: { + setSelectedProfile: ( + state, + { payload }: PayloadAction, + ) => { + state.selectedProfile = payload; + }, + setAvailableProfiles: ( + state, + { payload }: PayloadAction, + ) => { + state.availableProfiles = payload; + }, + setOrganizations: ( + state, + { payload }: PayloadAction, + ) => { + state.organizations = payload; + }, + setSelectedOrganizationId: ( + state, + { payload }: PayloadAction, + ) => { + state.selectedOrganizationId = payload; + }, + }, +}); + +export const { + setSelectedProfile, + setAvailableProfiles, + setOrganizations, + setSelectedOrganizationId, +} = profilesSlice.actions; + +export const profilesReducer = profilesSlice.reducer; diff --git a/gui/src/redux/thunks/profileAndOrg.ts b/gui/src/redux/slices/profiles/thunks.ts similarity index 76% rename from gui/src/redux/thunks/profileAndOrg.ts rename to gui/src/redux/slices/profiles/thunks.ts index 82a9602c0..f55d05f3c 100644 --- a/gui/src/redux/thunks/profileAndOrg.ts +++ b/gui/src/redux/slices/profiles/thunks.ts @@ -1,13 +1,13 @@ import { createAsyncThunk } from "@reduxjs/toolkit"; import { ProfileDescription } from "core/config/ConfigHandler"; import { OrganizationDescription } from "core/config/ProfileLifecycleManager"; +import { ThunkApiType } from "../../store"; import { setAvailableProfiles, setOrganizations, setSelectedOrganizationId, setSelectedProfile, -} from "../slices/sessionSlice"; -import { ThunkApiType } from "../store"; +} from "./slice"; export const selectProfileThunk = createAsyncThunk< void, @@ -16,29 +16,29 @@ export const selectProfileThunk = createAsyncThunk< >("profiles/select", async (id, { dispatch, extra, getState }) => { const state = getState(); - if (state.session.availableProfiles === null) { + if (state.profiles.availableProfiles === null) { // Currently in loading state return; } - const initialId = state.session.selectedProfile?.id; + const initialId = state.profiles.selectedProfile?.id; let newId = id; // If no profiles, force clear - if (state.session.availableProfiles.length === 0) { + if (state.profiles.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)) { + 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.session.availableProfiles[0].id; + newId = state.profiles.availableProfiles[0].id; } } @@ -46,7 +46,7 @@ export const selectProfileThunk = createAsyncThunk< if ((newId ?? null) !== (initialId ?? null)) { dispatch( setSelectedProfile( - state.session.availableProfiles.find((p) => p.id === newId) ?? null, + state.profiles.availableProfiles.find((p) => p.id === newId) ?? null, ), ); extra.ideMessenger.post("didChangeSelectedProfile", { @@ -60,11 +60,11 @@ export const cycleProfile = createAsyncThunk( async (_, { dispatch, getState }) => { const state = getState(); - if (state.session.availableProfiles === null) { + if (state.profiles.availableProfiles === null) { return; } - const profileIds = state.session.availableProfiles.map( + const profileIds = state.profiles.availableProfiles.map( (profile) => profile.id, ); // In case of no profiles just does nothing @@ -72,8 +72,8 @@ export const cycleProfile = createAsyncThunk( return; } let nextId = profileIds[0]; - if (state.session.selectedProfile) { - const curIndex = profileIds.indexOf(state.session.selectedProfile?.id); + if (state.profiles.selectedProfile) { + const curIndex = profileIds.indexOf(state.profiles.selectedProfile?.id); const nextIndex = (curIndex + 1) % profileIds.length; nextId = profileIds[nextIndex]; } @@ -100,15 +100,15 @@ export const selectOrgThunk = createAsyncThunk< ThunkApiType >("session/selectOrg", async (id, { dispatch, extra, getState }) => { const state = getState(); - const initialId = state.session.selectedOrganizationId; + const initialId = state.profiles.selectedOrganizationId; let newId = id; // If no orgs, force clear - if (state.session.organizations.length === 0) { + if (state.profiles.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)) { + if (!state.profiles.organizations.find((o) => o.id === newId)) { newId = null; } } @@ -133,5 +133,5 @@ export const updateOrgsThunk = createAsyncThunk< dispatch(setOrganizations(orgs)); // This will trigger reselection if needed - dispatch(selectOrgThunk(state.session.selectedOrganizationId)); + dispatch(selectOrgThunk(state.profiles.selectedOrganizationId)); }); diff --git a/gui/src/redux/slices/sessionSlice.ts b/gui/src/redux/slices/sessionSlice.ts index 04bb7ab19..33555660c 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; - selectedProfile: ProfileDescription | 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(), - selectedProfile: 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; } @@ -345,7 +333,7 @@ export const sessionSlice = createSlice({ !(!lastMessage.toolCalls?.length && !lastMessage.content) && // And there's a difference in tool call presence (lastMessage.toolCalls?.length ?? 0) !== - (message.toolCalls?.length ?? 0)) + (message.toolCalls?.length ?? 0)) ) { // Create a new message const historyItem: ChatHistoryItemWithMessageId = { @@ -495,9 +483,9 @@ export const sessionSlice = createSlice({ state.allSessionMetadata = state.allSessionMetadata.map((session) => session.sessionId === payload.sessionId ? { - ...session, - ...payload, - } + ...session, + ...payload, + } : session, ); if (payload.title && payload.sessionId === state.id) { @@ -532,8 +520,9 @@ export const sessionSlice = createSlice({ payload.rangeInFileWithContents.filepath, ); - const lineNums = `(${payload.rangeInFileWithContents.range.start.line + 1 - }-${payload.rangeInFileWithContents.range.end.line + 1})`; + const lineNums = `(${ + payload.rangeInFileWithContents.range.start.line + 1 + }-${payload.rangeInFileWithContents.range.end.line + 1})`; contextItems.push({ name: `${fileName} ${lineNums}`, @@ -553,34 +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.selectedProfile = payload; - }, - setAvailableProfiles: ( - state, - { payload }: PayloadAction, - ) => { - state.availableProfiles = payload; - }, - setOrganizations: ( - state, - { payload }: PayloadAction, - ) => { - state.organizations = payload; - }, - setSelectedOrganizationId: ( - state, - { payload }: PayloadAction, - ) => { - state.selectedOrganizationId = payload; - }, - /////////////// - updateCurCheckpoint: ( state, { payload }: PayloadAction<{ filepath: string; content: string }>, @@ -718,9 +679,9 @@ function addPassthroughCases( ) { thunks.forEach((thunk) => { builder - .addCase(thunk.fulfilled, (state, action) => { }) - .addCase(thunk.rejected, (state, action) => { }) - .addCase(thunk.pending, (state, action) => { }); + .addCase(thunk.fulfilled, (state, action) => {}) + .addCase(thunk.rejected, (state, action) => {}) + .addCase(thunk.pending, (state, action) => {}); }); } @@ -777,11 +738,6 @@ export const { updateSessionMetadata, deleteSessionMetadata, setNewestCodeblocksForInput, - - setAvailableProfiles, - setSelectedProfile, - setOrganizations, - setSelectedOrganizationId, } = sessionSlice.actions; export const { diff --git a/gui/src/redux/store.ts b/gui/src/redux/store.ts index fb3deec79..d7fea11c1 100644 --- a/gui/src/redux/store.ts +++ b/gui/src/redux/store.ts @@ -13,6 +13,7 @@ import configReducer from "./slices/configSlice"; import editModeStateReducer from "./slices/editModeState"; import indexingReducer from "./slices/indexingSlice"; import miscReducer from "./slices/miscSlice"; +import { profilesReducer } from "./slices/profiles"; import sessionReducer from "./slices/sessionSlice"; import tabsReducer from "./slices/tabsSlice"; import uiReducer from "./slices/uiSlice"; @@ -30,13 +31,12 @@ const rootReducer = combineReducers({ config: configReducer, indexing: indexingReducer, tabs: tabsReducer, + profiles: profilesReducer, }); const saveSubsetFilters = [ createFilter("session", [ "history", - "selectedOrganizationId", - "selectedProfile", "id", "lastSessionId", "title", @@ -45,10 +45,6 @@ const saveSubsetFilters = [ "mode", "codeToEdit", - // TODO consider removing persisted profiles/orgs - "availableProfiles", - "organizations", - // higher risk to persist // codeBlockApplyStates // symbols @@ -60,6 +56,13 @@ const saveSubsetFilters = [ createFilter("ui", ["toolSettings", "useTools"]), createFilter("indexing", []), createFilter("tabs", ["tabs"]), + createFilter("profiles", [ + // TODO consider removing persisted profiles/orgs + "availableProfiles", + "organizations", + "selectedOrganizationId", + "selectedProfile", + ]), ]; const migrations: MigrationManifest = { From 730ac56d5a15a6b2931330aeb849e2d260d2644a Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Fri, 21 Mar 2025 11:10:41 -0700 Subject: [PATCH 05/13] Revert "feat: add bookmark logic" This reverts commit d3f4aeb4c676cc4d5e090fa2ea6e497f965a3acd. --- extensions/vscode/src/VsCodeIde.ts | 2 +- .../ConversationStarterCard.tsx | 42 ++---------- .../ConversationStarterCards.tsx | 43 +++++++----- gui/src/components/index.ts | 4 +- .../platform/AssistantSelect.tsx | 2 +- .../platform/AssistantSelectOptions.tsx | 2 +- gui/src/context/Auth.tsx | 12 ++-- gui/src/hooks/useSetup.ts | 2 +- gui/src/pages/config/ScopeSelect.tsx | 4 +- gui/src/pages/config/index.tsx | 2 +- gui/src/pages/gui/StreamError.tsx | 2 +- gui/src/redux/slices/profiles/index.ts | 2 - gui/src/redux/slices/profiles/slice.ts | 59 ----------------- gui/src/redux/slices/sessionSlice.ts | 66 +++++++++++++++---- gui/src/redux/store.ts | 15 ++--- .../thunks.ts => thunks/profileAndOrg.ts} | 32 ++++----- 16 files changed, 126 insertions(+), 165 deletions(-) delete mode 100644 gui/src/redux/slices/profiles/index.ts delete mode 100644 gui/src/redux/slices/profiles/slice.ts rename gui/src/redux/{slices/profiles/thunks.ts => thunks/profileAndOrg.ts} (76%) diff --git a/extensions/vscode/src/VsCodeIde.ts b/extensions/vscode/src/VsCodeIde.ts index c324edaf2..1aaa10283 100644 --- a/extensions/vscode/src/VsCodeIde.ts +++ b/extensions/vscode/src/VsCodeIde.ts @@ -529,7 +529,7 @@ class VsCodeIde implements IDE { const tabArray = vscode.window.tabGroups.all[0].tabs; return tabArray - .filter((t) => t.isBookmarked) + .filter((t) => t.isPinned) .map((t) => (t.input as vscode.TabInputText).uri.toString()); } diff --git a/gui/src/components/ConversationStarters/ConversationStarterCard.tsx b/gui/src/components/ConversationStarters/ConversationStarterCard.tsx index 1542adadf..35a205481 100644 --- a/gui/src/components/ConversationStarters/ConversationStarterCard.tsx +++ b/gui/src/components/ConversationStarters/ConversationStarterCard.tsx @@ -1,63 +1,33 @@ -import { BookmarkIcon, ChatBubbleLeftIcon } from "@heroicons/react/24/outline"; -import { BookmarkIcon as BookmarkIconSolid } from "@heroicons/react/24/solid"; +import { ChatBubbleLeftIcon } from "@heroicons/react/24/outline"; import { SlashCommandDescription } from "core"; -import { useState } from "react"; -import { defaultBorderRadius, GhostButton, vscInputBackground } from ".."; +import { defaultBorderRadius, 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 (
onClick(command)} + className="mb-2 w-full shadow-md hover:cursor-pointer hover:brightness-110" style={{ borderRadius: defaultBorderRadius, backgroundColor: vscInputBackground, }} - onMouseEnter={() => 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 index 8df9cd908..69020dae5 100644 --- a/gui/src/components/ConversationStarters/ConversationStarterCards.tsx +++ b/gui/src/components/ConversationStarters/ConversationStarterCards.tsx @@ -10,13 +10,19 @@ const NUM_CARDS_TO_RENDER_COLLAPSED = 3; export function ConversationStarterCards() { const dispatch = useAppDispatch(); - const [bookmarkedCommands, setBookmarkedCommands] = useState([]); - + const [isExpanded, setIsExpanded] = useState(false); const slashCommands = useAppSelector((state) => state.config.config.slashCommands) ?? []; const filteredSlashCommands = slashCommands?.filter(isDeprecatedCommandName); + const numFilteredSlashCommands = filteredSlashCommands.length; + const displayedCommands = isExpanded + ? filteredSlashCommands + : filteredSlashCommands.slice(0, NUM_CARDS_TO_RENDER_COLLAPSED); + const hasMoreCommands = + numFilteredSlashCommands > NUM_CARDS_TO_RENDER_COLLAPSED; + function onClick(command: SlashCommandDescription) { if (command.prompt) { dispatch( @@ -25,14 +31,8 @@ export function ConversationStarterCards() { } } - function handleBookmarkCommand(command: SlashCommandDescription) { - setBookmarkedCommands((prev) => { - if (prev.includes(command.name)) { - return prev.filter((name) => name !== command.name); - } else { - return [...prev, command.name]; - } - }); + function handleToggleExpand() { + setIsExpanded(!isExpanded); } if (!filteredSlashCommands || filteredSlashCommands.length === 0) { @@ -40,18 +40,29 @@ export function ConversationStarterCards() { } return ( -
- {filteredSlashCommands - .slice(0, NUM_CARDS_TO_RENDER_COLLAPSED) - .map((command, i) => ( +
+

Prompts

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

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

+ )}
); } diff --git a/gui/src/components/index.ts b/gui/src/components/index.ts index eb0632646..04460f3b1 100644 --- a/gui/src/components/index.ts +++ b/gui/src/components/index.ts @@ -1,5 +1,5 @@ import styled from "styled-components"; -import { getFontSize } from "../util"; +import { getFontSize, isJetBrains } 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: 6px 8px; + padding: 10px 12px; margin: 8px 0; border-radius: ${defaultBorderRadius}; diff --git a/gui/src/components/modelSelection/platform/AssistantSelect.tsx b/gui/src/components/modelSelection/platform/AssistantSelect.tsx index 4e1925ce4..a4dde488d 100644 --- a/gui/src/components/modelSelection/platform/AssistantSelect.tsx +++ b/gui/src/components/modelSelection/platform/AssistantSelect.tsx @@ -5,7 +5,7 @@ import { useContext, useEffect, useRef } from "react"; import { useAuth } from "../../../context/Auth"; import { IdeMessengerContext } from "../../../context/IdeMessenger"; import { useAppDispatch } from "../../../redux/hooks"; -import { cycleProfile } from "../../../redux/slices/profiles/thunks"; +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 de4db1422..cd8d5cd5c 100644 --- a/gui/src/components/modelSelection/platform/AssistantSelectOptions.tsx +++ b/gui/src/components/modelSelection/platform/AssistantSelectOptions.tsx @@ -6,7 +6,7 @@ import { lightGray } from "../.."; import { useAuth } from "../../../context/Auth"; import { IdeMessengerContext } from "../../../context/IdeMessenger"; import { useAppDispatch } from "../../../redux/hooks"; -import { selectProfileThunk } from "../../../redux/slices/profiles/thunks"; +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 844ba1aa3..d4e6f7925 100644 --- a/gui/src/context/Auth.tsx +++ b/gui/src/context/Auth.tsx @@ -14,11 +14,11 @@ import ConfirmationDialog from "../components/dialogs/ConfirmationDialog"; import { useWebviewListener } from "../hooks/useWebviewListener"; import { useAppDispatch, useAppSelector } from "../redux/hooks"; import { setLastControlServerBetaEnabledStatus } from "../redux/slices/miscSlice"; +import { setDialogMessage, setShowDialog } from "../redux/slices/uiSlice"; import { updateOrgsThunk, updateProfilesThunk, -} from "../redux/slices/profiles/thunks"; -import { setDialogMessage, setShowDialog } from "../redux/slices/uiSlice"; +} from "../redux/thunks/profileAndOrg"; import { IdeMessengerContext } from "./IdeMessenger"; interface AuthContextType { @@ -47,9 +47,9 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ ); // Orgs - const orgs = useAppSelector((store) => store.profiles.organizations); + const orgs = useAppSelector((store) => store.session.organizations); const selectedOrgId = useAppSelector( - (store) => store.profiles.selectedOrganizationId, + (store) => store.session.selectedOrganizationId, ); const selectedOrganization = useMemo(() => { if (!selectedOrgId) { @@ -59,9 +59,9 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ }, [orgs, selectedOrgId]); // Profiles - const profiles = useAppSelector((store) => store.profiles.availableProfiles); + const profiles = useAppSelector((store) => store.session.availableProfiles); const selectedProfile = useAppSelector( - (store) => store.profiles.selectedProfile, + (store) => store.session.selectedProfile, ); const login: AuthContextType["login"] = (useOnboarding: boolean) => { diff --git a/gui/src/hooks/useSetup.ts b/gui/src/hooks/useSetup.ts index c45c2323c..9d7f607b5 100644 --- a/gui/src/hooks/useSetup.ts +++ b/gui/src/hooks/useSetup.ts @@ -11,12 +11,12 @@ import { } from "../redux/slices/configSlice"; import { updateIndexingStatus } from "../redux/slices/indexingSlice"; import { updateDocsSuggestions } from "../redux/slices/miscSlice"; -import { selectProfileThunk } from "../redux/slices/profiles/thunks"; import { addContextItemsAtIndex, 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/pages/config/ScopeSelect.tsx b/gui/src/pages/config/ScopeSelect.tsx index 3b001a421..2d42483a0 100644 --- a/gui/src/pages/config/ScopeSelect.tsx +++ b/gui/src/pages/config/ScopeSelect.tsx @@ -7,12 +7,12 @@ import { import { useAuth } from "../../context/Auth"; import { useWebviewListener } from "../../hooks/useWebviewListener"; import { useAppDispatch, useAppSelector } from "../../redux/hooks"; -import { selectOrgThunk } from "../../redux/slices/profiles/thunks"; +import { selectOrgThunk } from "../../redux/thunks/profileAndOrg"; export function ScopeSelect() { const { organizations, selectedOrganization } = useAuth(); const selectedOrgId = useAppSelector( - (state) => state.profiles.selectedOrganizationId, + (state) => state.session.selectedOrganizationId, ); const dispatch = useAppDispatch(); diff --git a/gui/src/pages/config/index.tsx b/gui/src/pages/config/index.tsx index 90530fa3a..3cf9b84a2 100644 --- a/gui/src/pages/config/index.tsx +++ b/gui/src/pages/config/index.tsx @@ -29,7 +29,7 @@ import { setDefaultModel, updateConfig, } from "../../redux/slices/configSlice"; -import { selectProfileThunk } from "../../redux/slices/profiles/thunks"; +import { selectProfileThunk } from "../../redux/thunks/profileAndOrg"; import { getFontSize, isJetBrains } from "../../util"; import ModelRoleSelector from "./ModelRoleSelector"; import { ScopeSelect } from "./ScopeSelect"; diff --git a/gui/src/pages/gui/StreamError.tsx b/gui/src/pages/gui/StreamError.tsx index b575ef0ec..7e372720c 100644 --- a/gui/src/pages/gui/StreamError.tsx +++ b/gui/src/pages/gui/StreamError.tsx @@ -22,7 +22,7 @@ const StreamErrorDialog = ({ error }: StreamErrorProps) => { const selectedModel = useAppSelector(selectDefaultModel); const hubEnabled = useAppSelector(selectUseHub); const selectedProfile = useAppSelector( - (store) => store.profiles.selectedProfile, + (store) => store.session.selectedProfile, ); const { session, refreshProfiles } = useAuth(); diff --git a/gui/src/redux/slices/profiles/index.ts b/gui/src/redux/slices/profiles/index.ts deleted file mode 100644 index 22be336b5..000000000 --- a/gui/src/redux/slices/profiles/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from "./slice"; -export * from "./thunks"; diff --git a/gui/src/redux/slices/profiles/slice.ts b/gui/src/redux/slices/profiles/slice.ts deleted file mode 100644 index b160c54b9..000000000 --- a/gui/src/redux/slices/profiles/slice.ts +++ /dev/null @@ -1,59 +0,0 @@ -import { createSlice, PayloadAction } from "@reduxjs/toolkit"; -import { ProfileDescription } from "core/config/ConfigHandler"; -import { OrganizationDescription } from "core/config/ProfileLifecycleManager"; - -interface ProfilesState { - availableProfiles: ProfileDescription[] | null; - selectedProfile: ProfileDescription | null; - organizations: OrganizationDescription[]; - selectedOrganizationId: string | null; -} - -const initialState: ProfilesState = { - availableProfiles: null, - selectedProfile: null, - organizations: [], - selectedOrganizationId: null, -}; - -export const profilesSlice = createSlice({ - name: "profiles", - initialState, - // Important: these reducers don't handle selected profile/organization fallback logic - // That is done in thunks - reducers: { - setSelectedProfile: ( - state, - { payload }: PayloadAction, - ) => { - state.selectedProfile = payload; - }, - setAvailableProfiles: ( - state, - { payload }: PayloadAction, - ) => { - state.availableProfiles = payload; - }, - setOrganizations: ( - state, - { payload }: PayloadAction, - ) => { - state.organizations = payload; - }, - setSelectedOrganizationId: ( - state, - { payload }: PayloadAction, - ) => { - state.selectedOrganizationId = payload; - }, - }, -}); - -export const { - setSelectedProfile, - setAvailableProfiles, - setOrganizations, - setSelectedOrganizationId, -} = profilesSlice.actions; - -export const profilesReducer = profilesSlice.reducer; diff --git a/gui/src/redux/slices/sessionSlice.ts b/gui/src/redux/slices/sessionSlice.ts index 33555660c..04bb7ab19 100644 --- a/gui/src/redux/slices/sessionSlice.ts +++ b/gui/src/redux/slices/sessionSlice.ts @@ -21,6 +21,8 @@ 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"; @@ -43,6 +45,11 @@ type SessionState = { isStreaming: boolean; title: string; id: string; + /** null indicates loading state */ + availableProfiles: ProfileDescription[] | null; + selectedProfile: ProfileDescription | null; + organizations: OrganizationDescription[]; + selectedOrganizationId: string | null; streamAborter: AbortController; codeToEdit: CodeToEdit[]; curCheckpointIndex: number; @@ -81,6 +88,10 @@ const initialState: SessionState = { isStreaming: false, title: NEW_SESSION_TITLE, id: uuidv4(), + selectedProfile: null, + availableProfiles: null, + organizations: [], + selectedOrganizationId: "", curCheckpointIndex: 0, streamAborter: new AbortController(), codeToEdit: [], @@ -283,6 +294,7 @@ export const sessionSlice = createSlice({ state.streamAborter = new AbortController(); }, streamUpdate: (state, action: PayloadAction) => { + if (state.history.length) { function toolCallDeltaToState( toolCallDelta: ToolCallDelta, @@ -320,7 +332,7 @@ export const sessionSlice = createSlice({ id: uuidv4(), }, contextItems: [], - }); + }) continue; } @@ -333,7 +345,7 @@ export const sessionSlice = createSlice({ !(!lastMessage.toolCalls?.length && !lastMessage.content) && // And there's a difference in tool call presence (lastMessage.toolCalls?.length ?? 0) !== - (message.toolCalls?.length ?? 0)) + (message.toolCalls?.length ?? 0)) ) { // Create a new message const historyItem: ChatHistoryItemWithMessageId = { @@ -483,9 +495,9 @@ export const sessionSlice = createSlice({ state.allSessionMetadata = state.allSessionMetadata.map((session) => session.sessionId === payload.sessionId ? { - ...session, - ...payload, - } + ...session, + ...payload, + } : session, ); if (payload.title && payload.sessionId === state.id) { @@ -520,9 +532,8 @@ export const sessionSlice = createSlice({ payload.rangeInFileWithContents.filepath, ); - const lineNums = `(${ - payload.rangeInFileWithContents.range.start.line + 1 - }-${payload.rangeInFileWithContents.range.end.line + 1})`; + const lineNums = `(${payload.rangeInFileWithContents.range.start.line + 1 + }-${payload.rangeInFileWithContents.range.end.line + 1})`; contextItems.push({ name: `${fileName} ${lineNums}`, @@ -542,6 +553,34 @@ 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.selectedProfile = payload; + }, + setAvailableProfiles: ( + state, + { payload }: PayloadAction, + ) => { + state.availableProfiles = payload; + }, + setOrganizations: ( + state, + { payload }: PayloadAction, + ) => { + state.organizations = payload; + }, + setSelectedOrganizationId: ( + state, + { payload }: PayloadAction, + ) => { + state.selectedOrganizationId = payload; + }, + /////////////// + updateCurCheckpoint: ( state, { payload }: PayloadAction<{ filepath: string; content: string }>, @@ -679,9 +718,9 @@ function addPassthroughCases( ) { thunks.forEach((thunk) => { builder - .addCase(thunk.fulfilled, (state, action) => {}) - .addCase(thunk.rejected, (state, action) => {}) - .addCase(thunk.pending, (state, action) => {}); + .addCase(thunk.fulfilled, (state, action) => { }) + .addCase(thunk.rejected, (state, action) => { }) + .addCase(thunk.pending, (state, action) => { }); }); } @@ -738,6 +777,11 @@ export const { updateSessionMetadata, deleteSessionMetadata, setNewestCodeblocksForInput, + + setAvailableProfiles, + setSelectedProfile, + setOrganizations, + setSelectedOrganizationId, } = sessionSlice.actions; export const { diff --git a/gui/src/redux/store.ts b/gui/src/redux/store.ts index d7fea11c1..fb3deec79 100644 --- a/gui/src/redux/store.ts +++ b/gui/src/redux/store.ts @@ -13,7 +13,6 @@ import configReducer from "./slices/configSlice"; import editModeStateReducer from "./slices/editModeState"; import indexingReducer from "./slices/indexingSlice"; import miscReducer from "./slices/miscSlice"; -import { profilesReducer } from "./slices/profiles"; import sessionReducer from "./slices/sessionSlice"; import tabsReducer from "./slices/tabsSlice"; import uiReducer from "./slices/uiSlice"; @@ -31,12 +30,13 @@ const rootReducer = combineReducers({ config: configReducer, indexing: indexingReducer, tabs: tabsReducer, - profiles: profilesReducer, }); const saveSubsetFilters = [ createFilter("session", [ "history", + "selectedOrganizationId", + "selectedProfile", "id", "lastSessionId", "title", @@ -45,6 +45,10 @@ const saveSubsetFilters = [ "mode", "codeToEdit", + // TODO consider removing persisted profiles/orgs + "availableProfiles", + "organizations", + // higher risk to persist // codeBlockApplyStates // symbols @@ -56,13 +60,6 @@ const saveSubsetFilters = [ createFilter("ui", ["toolSettings", "useTools"]), createFilter("indexing", []), createFilter("tabs", ["tabs"]), - createFilter("profiles", [ - // TODO consider removing persisted profiles/orgs - "availableProfiles", - "organizations", - "selectedOrganizationId", - "selectedProfile", - ]), ]; const migrations: MigrationManifest = { diff --git a/gui/src/redux/slices/profiles/thunks.ts b/gui/src/redux/thunks/profileAndOrg.ts similarity index 76% rename from gui/src/redux/slices/profiles/thunks.ts rename to gui/src/redux/thunks/profileAndOrg.ts index f55d05f3c..82a9602c0 100644 --- a/gui/src/redux/slices/profiles/thunks.ts +++ b/gui/src/redux/thunks/profileAndOrg.ts @@ -1,13 +1,13 @@ import { createAsyncThunk } from "@reduxjs/toolkit"; import { ProfileDescription } from "core/config/ConfigHandler"; import { OrganizationDescription } from "core/config/ProfileLifecycleManager"; -import { ThunkApiType } from "../../store"; import { setAvailableProfiles, setOrganizations, setSelectedOrganizationId, setSelectedProfile, -} from "./slice"; +} from "../slices/sessionSlice"; +import { ThunkApiType } from "../store"; export const selectProfileThunk = createAsyncThunk< void, @@ -16,29 +16,29 @@ export const selectProfileThunk = createAsyncThunk< >("profiles/select", async (id, { dispatch, extra, getState }) => { const state = getState(); - if (state.profiles.availableProfiles === null) { + if (state.session.availableProfiles === null) { // Currently in loading state return; } - const initialId = state.profiles.selectedProfile?.id; + const initialId = state.session.selectedProfile?.id; let newId = id; // If no profiles, force clear - if (state.profiles.availableProfiles.length === 0) { + if (state.session.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)) { + 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.profiles.availableProfiles[0].id; + newId = state.session.availableProfiles[0].id; } } @@ -46,7 +46,7 @@ export const selectProfileThunk = createAsyncThunk< if ((newId ?? null) !== (initialId ?? null)) { dispatch( setSelectedProfile( - state.profiles.availableProfiles.find((p) => p.id === newId) ?? null, + state.session.availableProfiles.find((p) => p.id === newId) ?? null, ), ); extra.ideMessenger.post("didChangeSelectedProfile", { @@ -60,11 +60,11 @@ export const cycleProfile = createAsyncThunk( async (_, { dispatch, getState }) => { const state = getState(); - if (state.profiles.availableProfiles === null) { + if (state.session.availableProfiles === null) { return; } - const profileIds = state.profiles.availableProfiles.map( + const profileIds = state.session.availableProfiles.map( (profile) => profile.id, ); // In case of no profiles just does nothing @@ -72,8 +72,8 @@ export const cycleProfile = createAsyncThunk( return; } let nextId = profileIds[0]; - if (state.profiles.selectedProfile) { - const curIndex = profileIds.indexOf(state.profiles.selectedProfile?.id); + if (state.session.selectedProfile) { + const curIndex = profileIds.indexOf(state.session.selectedProfile?.id); const nextIndex = (curIndex + 1) % profileIds.length; nextId = profileIds[nextIndex]; } @@ -100,15 +100,15 @@ export const selectOrgThunk = createAsyncThunk< ThunkApiType >("session/selectOrg", async (id, { dispatch, extra, getState }) => { const state = getState(); - const initialId = state.profiles.selectedOrganizationId; + const initialId = state.session.selectedOrganizationId; let newId = id; // If no orgs, force clear - if (state.profiles.organizations.length === 0) { + if (state.session.organizations.length === 0) { newId = null; } else if (newId) { // If new id doesn't match an existing org, clear it - if (!state.profiles.organizations.find((o) => o.id === newId)) { + if (!state.session.organizations.find((o) => o.id === newId)) { newId = null; } } @@ -133,5 +133,5 @@ export const updateOrgsThunk = createAsyncThunk< dispatch(setOrganizations(orgs)); // This will trigger reselection if needed - dispatch(selectOrgThunk(state.profiles.selectedOrganizationId)); + dispatch(selectOrgThunk(state.session.selectedOrganizationId)); }); From efff2d30181648b9dedc86313740a80353d5a899 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Fri, 21 Mar 2025 11:35:24 -0700 Subject: [PATCH 06/13] Revert "feat: add bookmark logic" This reverts commit d3f4aeb4c676cc4d5e090fa2ea6e497f965a3acd. --- .../ConversationStarterCard.tsx | 42 +++++++++++++++--- .../ConversationStarterCards.tsx | 43 +++++++------------ gui/src/components/index.ts | 4 +- 3 files changed, 54 insertions(+), 35 deletions(-) diff --git a/gui/src/components/ConversationStarters/ConversationStarterCard.tsx b/gui/src/components/ConversationStarters/ConversationStarterCard.tsx index 35a205481..1542adadf 100644 --- a/gui/src/components/ConversationStarters/ConversationStarterCard.tsx +++ b/gui/src/components/ConversationStarters/ConversationStarterCard.tsx @@ -1,33 +1,63 @@ -import { ChatBubbleLeftIcon } from "@heroicons/react/24/outline"; +import { BookmarkIcon, ChatBubbleLeftIcon } from "@heroicons/react/24/outline"; +import { BookmarkIcon as BookmarkIconSolid } from "@heroicons/react/24/solid"; import { SlashCommandDescription } from "core"; -import { defaultBorderRadius, vscInputBackground } from ".."; +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 (
onClick(command)} - className="mb-2 w-full shadow-md hover:cursor-pointer hover:brightness-110" + className="mb-2 w-full shadow-md hover:brightness-110" style={{ borderRadius: defaultBorderRadius, backgroundColor: vscInputBackground, }} + onMouseEnter={() => 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 index 69020dae5..8df9cd908 100644 --- a/gui/src/components/ConversationStarters/ConversationStarterCards.tsx +++ b/gui/src/components/ConversationStarters/ConversationStarterCards.tsx @@ -10,19 +10,13 @@ const NUM_CARDS_TO_RENDER_COLLAPSED = 3; export function ConversationStarterCards() { const dispatch = useAppDispatch(); - const [isExpanded, setIsExpanded] = useState(false); + const [bookmarkedCommands, setBookmarkedCommands] = useState([]); + const slashCommands = useAppSelector((state) => state.config.config.slashCommands) ?? []; const filteredSlashCommands = slashCommands?.filter(isDeprecatedCommandName); - const numFilteredSlashCommands = filteredSlashCommands.length; - const displayedCommands = isExpanded - ? filteredSlashCommands - : filteredSlashCommands.slice(0, NUM_CARDS_TO_RENDER_COLLAPSED); - const hasMoreCommands = - numFilteredSlashCommands > NUM_CARDS_TO_RENDER_COLLAPSED; - function onClick(command: SlashCommandDescription) { if (command.prompt) { dispatch( @@ -31,8 +25,14 @@ export function ConversationStarterCards() { } } - function handleToggleExpand() { - setIsExpanded(!isExpanded); + function handleBookmarkCommand(command: SlashCommandDescription) { + setBookmarkedCommands((prev) => { + if (prev.includes(command.name)) { + return prev.filter((name) => name !== command.name); + } else { + return [...prev, command.name]; + } + }); } if (!filteredSlashCommands || filteredSlashCommands.length === 0) { @@ -40,29 +40,18 @@ export function ConversationStarterCards() { } return ( -
-

Prompts

- -
- {displayedCommands.map((command, i) => ( +
+ {filteredSlashCommands + .slice(0, NUM_CARDS_TO_RENDER_COLLAPSED) + .map((command, i) => ( ))} -
- - {hasMoreCommands && ( -

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

- )}
); } 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}; From 9c2db6b9c7d7fd0a0164b3e2288a4135df759707 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Fri, 21 Mar 2025 12:36:21 -0700 Subject: [PATCH 07/13] feat: create profiles slice --- .../CodeToEditCard/AddFileCombobox.tsx | 8 +-- .../platform/AssistantSelect.tsx | 2 +- .../platform/AssistantSelectOptions.tsx | 2 +- gui/src/context/Auth.tsx | 5 +- gui/src/hooks/useSetup.ts | 2 +- gui/src/pages/config/AccountManagement.tsx | 2 +- gui/src/pages/config/ScopeSelect.tsx | 2 +- gui/src/redux/index.ts | 1 + gui/src/redux/slices/index.ts | 1 + gui/src/redux/slices/profiles/index.ts | 2 + gui/src/redux/slices/profiles/slice.ts | 65 +++++++++++++++++++ .../profiles/thunks.ts} | 4 +- gui/src/redux/store.ts | 2 + 13 files changed, 83 insertions(+), 15 deletions(-) create mode 100644 gui/src/redux/index.ts create mode 100644 gui/src/redux/slices/index.ts create mode 100644 gui/src/redux/slices/profiles/index.ts create mode 100644 gui/src/redux/slices/profiles/slice.ts rename gui/src/redux/{thunks/profileAndOrg.ts => slices/profiles/thunks.ts} (98%) 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/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..6baa3a308 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 { 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 { 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/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/ScopeSelect.tsx b/gui/src/pages/config/ScopeSelect.tsx index 2d42483a0..1efd465e8 100644 --- a/gui/src/pages/config/ScopeSelect.tsx +++ b/gui/src/pages/config/ScopeSelect.tsx @@ -6,8 +6,8 @@ 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(); 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/slices/index.ts b/gui/src/redux/slices/index.ts new file mode 100644 index 000000000..09303f508 --- /dev/null +++ b/gui/src/redux/slices/index.ts @@ -0,0 +1 @@ +export * from "./profiles"; 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..1f01ab6b6 --- /dev/null +++ b/gui/src/redux/slices/profiles/slice.ts @@ -0,0 +1,65 @@ +import { createSlice, PayloadAction } from "@reduxjs/toolkit"; +import { ProfileDescription } from "core/config/ConfigHandler"; +import { OrganizationDescription } from "core/config/ProfileLifecycleManager"; + +interface ProfilesState { + availableProfiles: ProfileDescription[] | null; + selectedProfileId: string | null; + organizations: OrganizationDescription[]; + selectedOrganizationId: string | null; +} + +const initialState: ProfilesState = { + availableProfiles: null, + selectedProfileId: null, + organizations: [], + selectedOrganizationId: null, +}; + +export const profilesSlice = createSlice({ + name: "profiles", + initialState, + reducers: { + 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; + }, + }, + selectors: { + selectSelectedProfile: (state) => { + return ( + state.availableProfiles?.find( + (profile) => profile.id === state.selectedProfileId, + ) ?? null + ); + }, + }, +}); + +export const { + setAvailableProfiles, + setSelectedProfile, + setOrganizations, + setSelectedOrganizationId, +} = profilesSlice.actions; + +export const { selectSelectedProfile } = profilesSlice.selectors; + +export const { reducer: profilesReducer } = profilesSlice; diff --git a/gui/src/redux/thunks/profileAndOrg.ts b/gui/src/redux/slices/profiles/thunks.ts similarity index 98% rename from gui/src/redux/thunks/profileAndOrg.ts rename to gui/src/redux/slices/profiles/thunks.ts index 0b378db66..580770476 100644 --- a/gui/src/redux/thunks/profileAndOrg.ts +++ b/gui/src/redux/slices/profiles/thunks.ts @@ -1,13 +1,13 @@ import { createAsyncThunk } from "@reduxjs/toolkit"; import { ProfileDescription } from "core/config/ConfigHandler"; import { OrganizationDescription } from "core/config/ProfileLifecycleManager"; +import { ThunkApiType } from "../../store"; import { setAvailableProfiles, setOrganizations, setSelectedOrganizationId, setSelectedProfile, -} from "../slices/sessionSlice"; -import { ThunkApiType } from "../store"; +} from "./slice"; export const selectProfileThunk = createAsyncThunk< void, diff --git a/gui/src/redux/store.ts b/gui/src/redux/store.ts index 0e7e5f805..601b41853 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 { profilesReducer } from "./redux"; import configReducer from "./slices/configSlice"; import editModeStateReducer from "./slices/editModeState"; import indexingReducer from "./slices/indexingSlice"; @@ -31,6 +32,7 @@ const rootReducer = combineReducers({ config: configReducer, indexing: indexingReducer, tabs: tabsReducer, + profiles: profilesReducer, }); const saveSubsetFilters = [ From b82d29c2df154a632c89d32c6847f5bf43b6564b Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Fri, 21 Mar 2025 15:11:57 -0700 Subject: [PATCH 08/13] feat: profiles slice --- binary/package-lock.json | 2 +- .../ConversationStarterCards.tsx | 47 ++++++++++---- gui/src/context/Auth.tsx | 8 +-- gui/src/pages/config/ScopeSelect.tsx | 2 +- gui/src/pages/gui/StreamError.tsx | 2 +- gui/src/redux/slices/profiles/slice.ts | 62 ++++++++++++++++++- gui/src/redux/slices/profiles/thunks.ts | 26 ++++---- gui/src/redux/slices/sessionSlice.ts | 53 +--------------- gui/src/redux/store.ts | 10 ++- 9 files changed, 124 insertions(+), 88 deletions(-) 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/gui/src/components/ConversationStarters/ConversationStarterCards.tsx b/gui/src/components/ConversationStarters/ConversationStarterCards.tsx index 8df9cd908..4176271ba 100644 --- a/gui/src/components/ConversationStarters/ConversationStarterCards.tsx +++ b/gui/src/components/ConversationStarters/ConversationStarterCards.tsx @@ -1,6 +1,11 @@ import { SlashCommandDescription } from "core"; -import { useState } from "react"; import { useAppDispatch, useAppSelector } from "../../redux/hooks"; +import { + bookmarkSlashCommand, + selectBookmarkedSlashCommands, + selectSelectedProfileId, + unbookmarkSlashCommand, +} from "../../redux/slices/profiles/slice"; import { setMainEditorContentTrigger } from "../../redux/slices/sessionSlice"; import { getParagraphNodeFromString } from "../mainInput/utils"; import { ConversationStarterCard } from "./ConversationStarterCard"; @@ -10,12 +15,23 @@ const NUM_CARDS_TO_RENDER_COLLAPSED = 3; export function ConversationStarterCards() { const dispatch = useAppDispatch(); - const [bookmarkedCommands, setBookmarkedCommands] = useState([]); const slashCommands = useAppSelector((state) => state.config.config.slashCommands) ?? []; - const filteredSlashCommands = slashCommands?.filter(isDeprecatedCommandName); + const selectedProfileId = useAppSelector(selectSelectedProfileId); + const bookmarkedCommands = useAppSelector(selectBookmarkedSlashCommands); + + const filteredSlashCommands = slashCommands.filter(isDeprecatedCommandName); + + const bookmarkStatuses: Record = {}; + if (selectedProfileId) { + filteredSlashCommands.forEach((command) => { + bookmarkStatuses[command.name] = bookmarkedCommands.includes( + command.name, + ); + }); + } function onClick(command: SlashCommandDescription) { if (command.prompt) { @@ -26,15 +42,22 @@ export function ConversationStarterCards() { } function handleBookmarkCommand(command: SlashCommandDescription) { - setBookmarkedCommands((prev) => { - if (prev.includes(command.name)) { - return prev.filter((name) => name !== command.name); - } else { - return [...prev, command.name]; - } - }); - } + const isBookmarked = bookmarkStatuses[command.name]; + if (isBookmarked) { + dispatch( + unbookmarkSlashCommand({ + commandName: command.name, + }), + ); + } else { + dispatch( + bookmarkSlashCommand({ + commandName: command.name, + }), + ); + } + } if (!filteredSlashCommands || filteredSlashCommands.length === 0) { return null; } @@ -49,7 +72,7 @@ export function ConversationStarterCards() { command={command} onClick={onClick} onBookmark={handleBookmarkCommand} - isBookmarked={bookmarkedCommands.includes(command.name)} + isBookmarked={bookmarkStatuses[command.name]} /> ))}
diff --git a/gui/src/context/Auth.tsx b/gui/src/context/Auth.tsx index 6baa3a308..ed0f7489c 100644 --- a/gui/src/context/Auth.tsx +++ b/gui/src/context/Auth.tsx @@ -13,9 +13,9 @@ import 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 { IdeMessengerContext } from "./IdeMessenger"; @@ -45,9 +45,9 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ ); // Orgs - const orgs = useAppSelector((store) => store.session.organizations); + const orgs = useAppSelector((store) => store.profiles.organizations); const selectedOrgId = useAppSelector( - (store) => store.session.selectedOrganizationId, + (store) => store.profiles.selectedOrganizationId, ); const selectedOrganization = useMemo(() => { if (!selectedOrgId) { @@ -57,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/pages/config/ScopeSelect.tsx b/gui/src/pages/config/ScopeSelect.tsx index 1efd465e8..2c23d73ce 100644 --- a/gui/src/pages/config/ScopeSelect.tsx +++ b/gui/src/pages/config/ScopeSelect.tsx @@ -12,7 +12,7 @@ import { useAppDispatch, useAppSelector } from "../../redux/hooks"; export function ScopeSelect() { const { organizations, selectedOrganization } = useAuth(); const selectedOrgId = useAppSelector( - (state) => state.session.selectedOrganizationId, + (state) => state.profiles.selectedOrganizationId, ); const dispatch = useAppDispatch(); 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/slices/profiles/slice.ts b/gui/src/redux/slices/profiles/slice.ts index 1f01ab6b6..c63a5c0ae 100644 --- a/gui/src/redux/slices/profiles/slice.ts +++ b/gui/src/redux/slices/profiles/slice.ts @@ -2,11 +2,16 @@ import { createSlice, PayloadAction } from "@reduxjs/toolkit"; import { ProfileDescription } from "core/config/ConfigHandler"; import { OrganizationDescription } from "core/config/ProfileLifecycleManager"; +interface PreferencesState { + bookmarksByName: string[]; +} + interface ProfilesState { availableProfiles: ProfileDescription[] | null; selectedProfileId: string | null; organizations: OrganizationDescription[]; selectedOrganizationId: string | null; + preferencesByProfileId: Record; } const initialState: ProfilesState = { @@ -14,6 +19,7 @@ const initialState: ProfilesState = { selectedProfileId: null, organizations: [], selectedOrganizationId: null, + preferencesByProfileId: {}, }; export const profilesSlice = createSlice({ @@ -41,6 +47,43 @@ export const profilesSlice = createSlice({ ) => { state.selectedOrganizationId = payload; }, + bookmarkSlashCommand: ( + state, + action: PayloadAction<{ commandName: string }>, + ) => { + const { commandName } = action.payload; + const profileId = state.selectedProfileId; + + if (!profileId) return; + + // Initialize preferences for this profile if needed + if (!state.preferencesByProfileId[profileId]) { + state.preferencesByProfileId[profileId] = { + bookmarksByName: [], + }; + } + + // Only add if not already bookmarked + 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 || !state.preferencesByProfileId[profileId]) return; + + const preferences = state.preferencesByProfileId[profileId]; + preferences.bookmarksByName = preferences.bookmarksByName.filter( + (cmd) => cmd !== commandName, + ); + }, }, selectors: { selectSelectedProfile: (state) => { @@ -50,6 +93,16 @@ export const profilesSlice = createSlice({ ) ?? null ); }, + + selectSelectedProfileId: (state) => state.selectedProfileId, + + selectBookmarkedSlashCommands: (state) => { + if (!state.selectedProfileId) return []; + const preferences = state.preferencesByProfileId[state.selectedProfileId]; + return preferences?.bookmarksByName || []; + }, + + selectPreferencesByProfileId: (state) => state.preferencesByProfileId, }, }); @@ -58,8 +111,15 @@ export const { setSelectedProfile, setOrganizations, setSelectedOrganizationId, + bookmarkSlashCommand, + unbookmarkSlashCommand, } = profilesSlice.actions; -export const { selectSelectedProfile } = profilesSlice.selectors; +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 index 580770476..5f0b04a02 100644 --- a/gui/src/redux/slices/profiles/thunks.ts +++ b/gui/src/redux/slices/profiles/thunks.ts @@ -16,29 +16,29 @@ export const selectProfileThunk = createAsyncThunk< >("profiles/select", async (id, { dispatch, extra, getState }) => { const state = getState(); - if (state.session.availableProfiles === null) { + if (state.profiles.availableProfiles === null) { // Currently in loading state return; } - const initialId = state.session.selectedProfileId; + const initialId = state.profiles.selectedProfileId; let newId = id; // If no profiles, force clear - if (state.session.availableProfiles.length === 0) { + if (state.profiles.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)) { + 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.session.availableProfiles[0].id; + newId = state.profiles.availableProfiles[0].id; } } @@ -56,11 +56,11 @@ export const cycleProfile = createAsyncThunk( async (_, { dispatch, getState }) => { const state = getState(); - if (state.session.availableProfiles === null) { + if (state.profiles.availableProfiles === null) { return; } - const profileIds = state.session.availableProfiles.map( + const profileIds = state.profiles.availableProfiles.map( (profile) => profile.id, ); // In case of no profiles just does nothing @@ -68,8 +68,8 @@ export const cycleProfile = createAsyncThunk( return; } let nextId = profileIds[0]; - if (state.session.selectedProfileId) { - const curIndex = profileIds.indexOf(state.session.selectedProfileId); + if (state.profiles.selectedProfileId) { + const curIndex = profileIds.indexOf(state.profiles.selectedProfileId); const nextIndex = (curIndex + 1) % profileIds.length; nextId = profileIds[nextIndex]; } @@ -96,15 +96,15 @@ export const selectOrgThunk = createAsyncThunk< ThunkApiType >("session/selectOrg", async (id, { dispatch, extra, getState }) => { const state = getState(); - const initialId = state.session.selectedOrganizationId; + const initialId = state.profiles.selectedOrganizationId; let newId = id; // If no orgs, force clear - if (state.session.organizations.length === 0) { + if (state.profiles.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)) { + if (!state.profiles.organizations.find((o) => o.id === newId)) { newId = null; } } @@ -129,5 +129,5 @@ export const updateOrgsThunk = createAsyncThunk< dispatch(setOrganizations(orgs)); // This will trigger reselection if needed - dispatch(selectOrgThunk(state.session.selectedOrganizationId)); + dispatch(selectOrgThunk(state.profiles.selectedOrganizationId)); }); 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 601b41853..40345f093 100644 --- a/gui/src/redux/store.ts +++ b/gui/src/redux/store.ts @@ -10,7 +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 { profilesReducer } from "./redux"; +import { profilesReducer } from "./slices"; import configReducer from "./slices/configSlice"; import editModeStateReducer from "./slices/editModeState"; import indexingReducer from "./slices/indexingSlice"; @@ -38,8 +38,6 @@ const rootReducer = combineReducers({ const saveSubsetFilters = [ createFilter("session", [ "history", - "selectedOrganizationId", - "selectedProfile", "id", "lastSessionId", "title", @@ -63,6 +61,12 @@ const saveSubsetFilters = [ createFilter("ui", ["toolSettings", "useTools"]), createFilter("indexing", []), createFilter("tabs", ["tabs"]), + // Add this new filter for the profiles slice + createFilter("profiles", [ + "preferencesByProfileId", + "selectedOrganizationId", + "selectedProfileId", + ]), ]; const migrations: MigrationManifest = { From 0819becfd98127a187cc84484dd59bb4348a1ec3 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Fri, 21 Mar 2025 15:27:46 -0700 Subject: [PATCH 09/13] feat: add tests --- .../ConversationStarterCards.tsx | 52 ++------------- .../__tests__/utils.test.ts | 45 +++++++++++++ .../useBookmarkedSlashCommands.ts | 64 +++++++++++++++++++ .../components/ConversationStarters/utils.ts | 20 ++++++ 4 files changed, 136 insertions(+), 45 deletions(-) create mode 100644 gui/src/components/ConversationStarters/__tests__/utils.test.ts create mode 100644 gui/src/components/ConversationStarters/useBookmarkedSlashCommands.ts diff --git a/gui/src/components/ConversationStarters/ConversationStarterCards.tsx b/gui/src/components/ConversationStarters/ConversationStarterCards.tsx index 4176271ba..f69d39974 100644 --- a/gui/src/components/ConversationStarters/ConversationStarterCards.tsx +++ b/gui/src/components/ConversationStarters/ConversationStarterCards.tsx @@ -1,37 +1,16 @@ import { SlashCommandDescription } from "core"; -import { useAppDispatch, useAppSelector } from "../../redux/hooks"; -import { - bookmarkSlashCommand, - selectBookmarkedSlashCommands, - selectSelectedProfileId, - unbookmarkSlashCommand, -} from "../../redux/slices/profiles/slice"; +import { useAppDispatch } from "../../redux/hooks"; import { setMainEditorContentTrigger } from "../../redux/slices/sessionSlice"; import { getParagraphNodeFromString } from "../mainInput/utils"; import { ConversationStarterCard } from "./ConversationStarterCard"; -import { isDeprecatedCommandName } from "./utils"; +import { useBookmarkedSlashCommands } from "./useBookmarkedSlashCommands"; const NUM_CARDS_TO_RENDER_COLLAPSED = 3; export function ConversationStarterCards() { const dispatch = useAppDispatch(); - - const slashCommands = - useAppSelector((state) => state.config.config.slashCommands) ?? []; - - const selectedProfileId = useAppSelector(selectSelectedProfileId); - const bookmarkedCommands = useAppSelector(selectBookmarkedSlashCommands); - - const filteredSlashCommands = slashCommands.filter(isDeprecatedCommandName); - - const bookmarkStatuses: Record = {}; - if (selectedProfileId) { - filteredSlashCommands.forEach((command) => { - bookmarkStatuses[command.name] = bookmarkedCommands.includes( - command.name, - ); - }); - } + const { cmdsSortedByBookmark, bookmarkStatuses, toggleBookmark } = + useBookmarkedSlashCommands(); function onClick(command: SlashCommandDescription) { if (command.prompt) { @@ -41,37 +20,20 @@ export function ConversationStarterCards() { } } - function handleBookmarkCommand(command: SlashCommandDescription) { - const isBookmarked = bookmarkStatuses[command.name]; - - if (isBookmarked) { - dispatch( - unbookmarkSlashCommand({ - commandName: command.name, - }), - ); - } else { - dispatch( - bookmarkSlashCommand({ - commandName: command.name, - }), - ); - } - } - if (!filteredSlashCommands || filteredSlashCommands.length === 0) { + if (!cmdsSortedByBookmark || cmdsSortedByBookmark.length === 0) { return null; } return (
- {filteredSlashCommands + {cmdsSortedByBookmark .slice(0, NUM_CARDS_TO_RENDER_COLLAPSED) .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/useBookmarkedSlashCommands.ts b/gui/src/components/ConversationStarters/useBookmarkedSlashCommands.ts new file mode 100644 index 000000000..732c2beb1 --- /dev/null +++ b/gui/src/components/ConversationStarters/useBookmarkedSlashCommands.ts @@ -0,0 +1,64 @@ +import { SlashCommandDescription } from "core"; +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 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], + ); + + // Function to toggle bookmark status + const toggleBookmark = (command: SlashCommandDescription) => { + const isBookmarked = bookmarkStatuses[command.name]; + + 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 index aab6cb414..d37b45416 100644 --- a/gui/src/components/ConversationStarters/utils.ts +++ b/gui/src/components/ConversationStarters/utils.ts @@ -27,3 +27,23 @@ export function isDeprecatedCommandName(command: SlashCommandDescription) { (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; + }); +} From d6ad3e2071ca1ee3f0b5cd4d8e93852a84fd138a Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Fri, 21 Mar 2025 15:42:05 -0700 Subject: [PATCH 10/13] feat: init profiles prefs --- .../ConversationStarterCards.tsx | 22 ++++++++-------- gui/src/redux/slices/profiles/slice.ts | 25 +++++++++++-------- gui/src/redux/slices/profiles/utils.ts | 12 +++++++++ 3 files changed, 36 insertions(+), 23 deletions(-) create mode 100644 gui/src/redux/slices/profiles/utils.ts diff --git a/gui/src/components/ConversationStarters/ConversationStarterCards.tsx b/gui/src/components/ConversationStarters/ConversationStarterCards.tsx index f69d39974..921d47d6e 100644 --- a/gui/src/components/ConversationStarters/ConversationStarterCards.tsx +++ b/gui/src/components/ConversationStarters/ConversationStarterCards.tsx @@ -5,7 +5,7 @@ import { getParagraphNodeFromString } from "../mainInput/utils"; import { ConversationStarterCard } from "./ConversationStarterCard"; import { useBookmarkedSlashCommands } from "./useBookmarkedSlashCommands"; -const NUM_CARDS_TO_RENDER_COLLAPSED = 3; +const NUM_CARDS_TO_RENDER = 3; export function ConversationStarterCards() { const dispatch = useAppDispatch(); @@ -26,17 +26,15 @@ export function ConversationStarterCards() { return (
- {cmdsSortedByBookmark - .slice(0, NUM_CARDS_TO_RENDER_COLLAPSED) - .map((command, i) => ( - toggleBookmark(command)} - isBookmarked={bookmarkStatuses[command.name]} - /> - ))} + {cmdsSortedByBookmark.slice(0, NUM_CARDS_TO_RENDER).map((command, i) => ( + toggleBookmark(command)} + isBookmarked={bookmarkStatuses[command.name]} + /> + ))}
); } diff --git a/gui/src/redux/slices/profiles/slice.ts b/gui/src/redux/slices/profiles/slice.ts index c63a5c0ae..85152e455 100644 --- a/gui/src/redux/slices/profiles/slice.ts +++ b/gui/src/redux/slices/profiles/slice.ts @@ -1,12 +1,13 @@ import { createSlice, PayloadAction } from "@reduxjs/toolkit"; import { ProfileDescription } from "core/config/ConfigHandler"; import { OrganizationDescription } from "core/config/ProfileLifecycleManager"; +import { ensureProfilePreferences } from "./utils"; -interface PreferencesState { +export interface PreferencesState { bookmarksByName: string[]; } -interface ProfilesState { +export interface ProfilesState { availableProfiles: ProfileDescription[] | null; selectedProfileId: string | null; organizations: OrganizationDescription[]; @@ -28,12 +29,22 @@ export const profilesSlice = createSlice({ 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); + } + } }, setOrganizations: ( state, @@ -56,14 +67,6 @@ export const profilesSlice = createSlice({ if (!profileId) return; - // Initialize preferences for this profile if needed - if (!state.preferencesByProfileId[profileId]) { - state.preferencesByProfileId[profileId] = { - bookmarksByName: [], - }; - } - - // Only add if not already bookmarked const bookmarks = state.preferencesByProfileId[profileId].bookmarksByName; if (!bookmarks.includes(commandName)) { bookmarks.push(commandName); @@ -77,7 +80,7 @@ export const profilesSlice = createSlice({ const { commandName } = action.payload; const profileId = state.selectedProfileId; - if (!profileId || !state.preferencesByProfileId[profileId]) return; + if (!profileId) return; const preferences = state.preferencesByProfileId[profileId]; preferences.bookmarksByName = preferences.bookmarksByName.filter( 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: [], + }; + } +} From 2f199ff9e08c37182738d2b3589a72220b138a70 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Fri, 21 Mar 2025 16:50:38 -0700 Subject: [PATCH 11/13] update docs --- docs/docs/customize/deep-dives/prompt-files.md | 10 +++++----- docs/docs/hub/blocks/block-types.md | 6 +++--- .../ConversationStarters/useBookmarkedSlashCommands.ts | 7 ++++++- 3 files changed, 14 insertions(+), 9 deletions(-) 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/ConversationStarters/useBookmarkedSlashCommands.ts b/gui/src/components/ConversationStarters/useBookmarkedSlashCommands.ts index 732c2beb1..786ae379a 100644 --- a/gui/src/components/ConversationStarters/useBookmarkedSlashCommands.ts +++ b/gui/src/components/ConversationStarters/useBookmarkedSlashCommands.ts @@ -1,4 +1,5 @@ import { SlashCommandDescription } from "core"; +import { usePostHog } from "posthog-js/react"; import { useMemo } from "react"; import { bookmarkSlashCommand, @@ -11,6 +12,7 @@ import { isDeprecatedCommandName, sortCommandsByBookmarkStatus } from "./utils"; export function useBookmarkedSlashCommands() { const dispatch = useAppDispatch(); + const posthog = usePostHog(); const slashCommands = useAppSelector((state) => state.config.config.slashCommands) ?? []; @@ -37,10 +39,13 @@ export function useBookmarkedSlashCommands() { [filteredSlashCommands, bookmarkedCommands], ); - // Function to toggle bookmark status const toggleBookmark = (command: SlashCommandDescription) => { const isBookmarked = bookmarkStatuses[command.name]; + posthog.capture("toggle_bookmarked_slash_command", { + isBookmarked, + }); + if (isBookmarked) { dispatch( unbookmarkSlashCommand({ From 71f85084f22333337a1e817e0502044771d66de4 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Fri, 21 Mar 2025 19:29:34 -0700 Subject: [PATCH 12/13] feat: create org slice --- gui/src/context/Auth.tsx | 4 +- gui/src/pages/config/ScopeSelect.tsx | 2 +- gui/src/redux/slices/index.ts | 1 + gui/src/redux/slices/organizations/index.ts | 2 + gui/src/redux/slices/organizations/slice.ts | 50 ++++++++++++++++++++ gui/src/redux/slices/organizations/thunks.ts | 47 ++++++++++++++++++ gui/src/redux/slices/profiles/slice.ts | 19 -------- gui/src/redux/slices/profiles/thunks.ts | 50 +------------------- gui/src/redux/store.ts | 3 +- 9 files changed, 106 insertions(+), 72 deletions(-) create mode 100644 gui/src/redux/slices/organizations/index.ts create mode 100644 gui/src/redux/slices/organizations/slice.ts create mode 100644 gui/src/redux/slices/organizations/thunks.ts diff --git a/gui/src/context/Auth.tsx b/gui/src/context/Auth.tsx index ed0f7489c..a049e8adc 100644 --- a/gui/src/context/Auth.tsx +++ b/gui/src/context/Auth.tsx @@ -45,9 +45,9 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ ); // Orgs - const orgs = useAppSelector((store) => store.profiles.organizations); + const orgs = useAppSelector((store) => store.organizations.organizations); const selectedOrgId = useAppSelector( - (store) => store.profiles.selectedOrganizationId, + (store) => store.organizations.selectedOrganizationId, ); const selectedOrganization = useMemo(() => { if (!selectedOrgId) { diff --git a/gui/src/pages/config/ScopeSelect.tsx b/gui/src/pages/config/ScopeSelect.tsx index 2c23d73ce..51538d784 100644 --- a/gui/src/pages/config/ScopeSelect.tsx +++ b/gui/src/pages/config/ScopeSelect.tsx @@ -12,7 +12,7 @@ import { useAppDispatch, useAppSelector } from "../../redux/hooks"; export function ScopeSelect() { const { organizations, selectedOrganization } = useAuth(); const selectedOrgId = useAppSelector( - (state) => state.profiles.selectedOrganizationId, + (state) => state.organizations.selectedOrganizationId, ); const dispatch = useAppDispatch(); diff --git a/gui/src/redux/slices/index.ts b/gui/src/redux/slices/index.ts index 09303f508..644b24187 100644 --- a/gui/src/redux/slices/index.ts +++ b/gui/src/redux/slices/index.ts @@ -1 +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/slice.ts b/gui/src/redux/slices/profiles/slice.ts index 85152e455..2d3386a5f 100644 --- a/gui/src/redux/slices/profiles/slice.ts +++ b/gui/src/redux/slices/profiles/slice.ts @@ -1,6 +1,5 @@ import { createSlice, PayloadAction } from "@reduxjs/toolkit"; import { ProfileDescription } from "core/config/ConfigHandler"; -import { OrganizationDescription } from "core/config/ProfileLifecycleManager"; import { ensureProfilePreferences } from "./utils"; export interface PreferencesState { @@ -10,16 +9,12 @@ export interface PreferencesState { export interface ProfilesState { availableProfiles: ProfileDescription[] | null; selectedProfileId: string | null; - organizations: OrganizationDescription[]; - selectedOrganizationId: string | null; preferencesByProfileId: Record; } const initialState: ProfilesState = { availableProfiles: null, selectedProfileId: null, - organizations: [], - selectedOrganizationId: null, preferencesByProfileId: {}, }; @@ -46,18 +41,6 @@ export const profilesSlice = createSlice({ } } }, - setOrganizations: ( - state, - { payload }: PayloadAction, - ) => { - state.organizations = payload; - }, - setSelectedOrganizationId: ( - state, - { payload }: PayloadAction, - ) => { - state.selectedOrganizationId = payload; - }, bookmarkSlashCommand: ( state, action: PayloadAction<{ commandName: string }>, @@ -112,8 +95,6 @@ export const profilesSlice = createSlice({ export const { setAvailableProfiles, setSelectedProfile, - setOrganizations, - setSelectedOrganizationId, bookmarkSlashCommand, unbookmarkSlashCommand, } = profilesSlice.actions; diff --git a/gui/src/redux/slices/profiles/thunks.ts b/gui/src/redux/slices/profiles/thunks.ts index 5f0b04a02..7ca109490 100644 --- a/gui/src/redux/slices/profiles/thunks.ts +++ b/gui/src/redux/slices/profiles/thunks.ts @@ -1,13 +1,7 @@ import { createAsyncThunk } from "@reduxjs/toolkit"; import { ProfileDescription } from "core/config/ConfigHandler"; -import { OrganizationDescription } from "core/config/ProfileLifecycleManager"; import { ThunkApiType } from "../../store"; -import { - setAvailableProfiles, - setOrganizations, - setSelectedOrganizationId, - setSelectedProfile, -} from "./slice"; +import { setAvailableProfiles, setSelectedProfile } from "./slice"; export const selectProfileThunk = createAsyncThunk< void, @@ -89,45 +83,3 @@ export const updateProfilesThunk = createAsyncThunk< // 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.profiles.selectedOrganizationId; - let newId = id; - - // If no orgs, force clear - if (state.profiles.organizations.length === 0) { - newId = null; - } else if (newId) { - // If new id doesn't match an existing org, clear it - if (!state.profiles.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.profiles.selectedOrganizationId)); -}); diff --git a/gui/src/redux/store.ts b/gui/src/redux/store.ts index 40345f093..dd8cf17a1 100644 --- a/gui/src/redux/store.ts +++ b/gui/src/redux/store.ts @@ -10,7 +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 { profilesReducer } from "./slices"; +import { organizationsReducer, profilesReducer } from "./slices"; import configReducer from "./slices/configSlice"; import editModeStateReducer from "./slices/editModeState"; import indexingReducer from "./slices/indexingSlice"; @@ -33,6 +33,7 @@ const rootReducer = combineReducers({ indexing: indexingReducer, tabs: tabsReducer, profiles: profilesReducer, + organizations: organizationsReducer, }); const saveSubsetFilters = [ From 4718c12c097dccb6c62175f56c43af885d0c4ebc Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Fri, 21 Mar 2025 19:31:50 -0700 Subject: [PATCH 13/13] Update MentionList.tsx --- gui/src/components/mainInput/MentionList.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/gui/src/components/mainInput/MentionList.tsx b/gui/src/components/mainInput/MentionList.tsx index 48582ce58..66c2da16e 100644 --- a/gui/src/components/mainInput/MentionList.tsx +++ b/gui/src/components/mainInput/MentionList.tsx @@ -1,6 +1,7 @@ import { ArrowRightIcon, AtSymbolIcon, + ChatBubbleLeftIcon, PlusIcon, } from "@heroicons/react/24/outline"; import { Editor } from "@tiptap/react";