Merge pull request #4758 from continuedev/pe/conversation-starters
feat: conversation starters
This commit is contained in:
commit
ed6f001eb7
59 changed files with 783 additions and 543 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -157,6 +157,7 @@ Icon?
|
|||
notes.md
|
||||
|
||||
manual-testing-sandbox/.idea/**
|
||||
manual-testing-sandbox/.continue/**
|
||||
extensions/intellij/.idea/**
|
||||
|
||||
**/.idea/workspace.xml
|
||||
|
|
|
|||
2
binary/package-lock.json
generated
2
binary/package-lock.json
generated
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -44,7 +44,6 @@ import ContinueProxyContextProvider from "../context/providers/ContinueProxyCont
|
|||
import CustomContextProviderClass from "../context/providers/CustomContextProvider";
|
||||
import FileContextProvider from "../context/providers/FileContextProvider";
|
||||
import { contextProviderClassFromName } from "../context/providers/index";
|
||||
import PromptFilesContextProvider from "../context/providers/PromptFilesContextProvider";
|
||||
import { useHub } from "../control-plane/env";
|
||||
import { allEmbeddingsProviders } from "../indexing/allEmbeddingsProviders";
|
||||
import { BaseLLM } from "../llm";
|
||||
|
|
@ -400,8 +399,6 @@ async function intermediateToFinalConfig(
|
|||
...(!config.disableIndexing
|
||||
? [new CodebaseContextProvider(codebaseContextParams)]
|
||||
: []),
|
||||
// Add prompt files provider if enabled
|
||||
...(loadPromptFiles ? [new PromptFilesContextProvider({})] : []),
|
||||
];
|
||||
|
||||
const DEFAULT_CONTEXT_PROVIDERS_TITLES = DEFAULT_CONTEXT_PROVIDERS.map(
|
||||
|
|
@ -633,11 +630,9 @@ async function finalToBrowserConfig(
|
|||
models: final.models.map(llmToSerializedModelDescription),
|
||||
systemMessage: final.systemMessage,
|
||||
completionOptions: final.completionOptions,
|
||||
slashCommands: final.slashCommands?.map((s) => ({
|
||||
name: s.name,
|
||||
description: s.description,
|
||||
params: s.params, // TODO: is this why params aren't referenced properly by slash commands?
|
||||
})),
|
||||
slashCommands: final.slashCommands?.map(
|
||||
({ run, ...slashCommandDescription }) => slashCommandDescription,
|
||||
),
|
||||
contextProviders: final.contextProviders?.map((c) => c.description),
|
||||
disableIndexing: final.disableIndexing,
|
||||
disableSessionTitles: final.disableSessionTitles,
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import {
|
|||
ConfigValidationError,
|
||||
ModelRole,
|
||||
} from "@continuedev/config-yaml";
|
||||
|
||||
import {
|
||||
ContinueConfig,
|
||||
ContinueRcJson,
|
||||
|
|
@ -31,6 +32,7 @@ import { loadContinueConfigFromJson } from "../load";
|
|||
import { migrateJsonSharedConfig } from "../migrateSharedConfig";
|
||||
import { rectifySelectedModelsFromGlobalContext } from "../selectedModels";
|
||||
import { loadContinueConfigFromYaml } from "../yaml/loadYaml";
|
||||
|
||||
import { PlatformConfigMetadata } from "./PlatformProfileLoader";
|
||||
|
||||
export default async function doLoadConfig(
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { ConfigValidationError } from "@continuedev/config-yaml";
|
||||
|
||||
import { ModelDescription, SerializedContinueConfig } from "../";
|
||||
import { Telemetry } from "../util/posthog";
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ import CodebaseContextProvider from "../../context/providers/CodebaseContextProv
|
|||
import DocsContextProvider from "../../context/providers/DocsContextProvider";
|
||||
import FileContextProvider from "../../context/providers/FileContextProvider";
|
||||
import { contextProviderClassFromName } from "../../context/providers/index";
|
||||
import PromptFilesContextProvider from "../../context/providers/PromptFilesContextProvider";
|
||||
import { ControlPlaneClient } from "../../control-plane/client";
|
||||
import { allEmbeddingsProviders } from "../../indexing/allEmbeddingsProviders";
|
||||
import FreeTrial from "../../llm/llms/FreeTrial";
|
||||
|
|
@ -335,7 +334,6 @@ async function configYamlToContinueConfig(
|
|||
const DEFAULT_CONTEXT_PROVIDERS = [
|
||||
new FileContextProvider({}),
|
||||
new CodebaseContextProvider(codebaseContextParams),
|
||||
new PromptFilesContextProvider({}),
|
||||
];
|
||||
|
||||
const DEFAULT_CONTEXT_PROVIDERS_TITLES = DEFAULT_CONTEXT_PROVIDERS.map(
|
||||
|
|
|
|||
|
|
@ -1,57 +0,0 @@
|
|||
import { BaseContextProvider } from "..";
|
||||
import {
|
||||
ContextItem,
|
||||
ContextProviderDescription,
|
||||
ContextProviderExtras,
|
||||
ContextSubmenuItem,
|
||||
LoadSubmenuItemsArgs,
|
||||
} from "../../";
|
||||
import { getAllPromptFiles } from "../../promptFiles/v2/getPromptFiles";
|
||||
import { parsePreamble } from "../../promptFiles/v2/parse";
|
||||
import { renderPromptFileV2 } from "../../promptFiles/v2/renderPromptFile";
|
||||
|
||||
class PromptFilesContextProvider extends BaseContextProvider {
|
||||
static description: ContextProviderDescription = {
|
||||
title: "prompt-files",
|
||||
displayTitle: "Prompt Files",
|
||||
description: ".prompt files",
|
||||
type: "submenu",
|
||||
};
|
||||
|
||||
async getContextItems(
|
||||
query: string,
|
||||
extras: ContextProviderExtras,
|
||||
): Promise<ContextItem[]> {
|
||||
const rawContent = await extras.ide.readFile(query);
|
||||
const preamble = parsePreamble(query, rawContent);
|
||||
const [contextItems, body] = await renderPromptFileV2(rawContent, extras);
|
||||
return [
|
||||
...contextItems,
|
||||
{
|
||||
content: body,
|
||||
name: preamble.name,
|
||||
description: preamble.description,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
async loadSubmenuItems(
|
||||
args: LoadSubmenuItemsArgs,
|
||||
): Promise<ContextSubmenuItem[]> {
|
||||
const promptFiles = await getAllPromptFiles(
|
||||
args.ide,
|
||||
args.config.experimental?.promptPath,
|
||||
// Note, NOT checking v1 default folder here, deprecated for context provider
|
||||
);
|
||||
return promptFiles.map((file) => {
|
||||
const preamble = parsePreamble(file.path, file.content);
|
||||
return {
|
||||
id: file.path,
|
||||
title: preamble.name,
|
||||
description: preamble.description,
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default PromptFilesContextProvider;
|
||||
7
core/index.d.ts
vendored
7
core/index.d.ts
vendored
|
|
@ -766,6 +766,7 @@ export interface ContinueSDK {
|
|||
export interface SlashCommand {
|
||||
name: string;
|
||||
description: string;
|
||||
prompt?: string;
|
||||
params?: { [key: string]: any };
|
||||
run: (sdk: ContinueSDK) => AsyncGenerator<string | undefined>;
|
||||
}
|
||||
|
|
@ -869,11 +870,7 @@ export interface ContextProviderWithParams {
|
|||
params: { [key: string]: any };
|
||||
}
|
||||
|
||||
export interface SlashCommandDescription {
|
||||
name: string;
|
||||
description: string;
|
||||
params?: { [key: string]: any };
|
||||
}
|
||||
export type SlashCommandDescription = Omit<SlashCommand, "run">;
|
||||
|
||||
export interface CustomCommand {
|
||||
name: string;
|
||||
|
|
|
|||
|
|
@ -53,16 +53,15 @@ export function slashCommandFromPromptFileV1(
|
|||
path: string,
|
||||
content: string,
|
||||
): SlashCommand | null {
|
||||
const { name, description, systemMessage, prompt, version } =
|
||||
parsePromptFileV1V2(path, content);
|
||||
|
||||
if (version !== 1) {
|
||||
return null;
|
||||
}
|
||||
const { name, description, systemMessage, prompt } = parsePromptFileV1V2(
|
||||
path,
|
||||
content,
|
||||
);
|
||||
|
||||
return {
|
||||
name,
|
||||
description,
|
||||
prompt,
|
||||
run: async function* (context) {
|
||||
const originalSystemMessage = context.llm.systemMessage;
|
||||
context.llm.systemMessage = systemMessage;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import * as YAML from "yaml";
|
||||
|
||||
import { getLastNPathParts } from "../../util/uri";
|
||||
|
||||
export function extractName(preamble: { name?: string }, path: string): string {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import * as YAML from "yaml";
|
||||
|
||||
import { getLastNPathParts } from "../../util/uri";
|
||||
|
||||
export function parsePromptFileV1V2(path: string, content: string) {
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -1,11 +1,15 @@
|
|||
import { ConfigResult, ModelRole } from "@continuedev/config-yaml";
|
||||
import {
|
||||
ConfigResult,
|
||||
DevDataLogEvent,
|
||||
ModelRole,
|
||||
} from "@continuedev/config-yaml";
|
||||
|
||||
import { AutocompleteInput } from "../autocomplete/util/types";
|
||||
import { ProfileDescription } from "../config/ConfigHandler";
|
||||
import { OrganizationDescription } from "../config/ProfileLifecycleManager";
|
||||
import { SharedConfigSchema } from "../config/sharedConfig";
|
||||
import { GlobalContextModelSelections } from "../util/GlobalContext";
|
||||
|
||||
import { DevDataLogEvent } from "@continuedev/config-yaml";
|
||||
import type {
|
||||
BrowserSerializedContinueConfig,
|
||||
ChatMessage,
|
||||
|
|
@ -29,7 +33,6 @@ import type {
|
|||
SlashCommandDescription,
|
||||
ToolCall,
|
||||
} from "../";
|
||||
import { GlobalContextModelSelections } from "../util/GlobalContext";
|
||||
|
||||
export type OnboardingModes = "Local" | "Best" | "Custom" | "Quickstart";
|
||||
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
|
|
|
|||
|
|
@ -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 <kbd>cmd/ctrl</kbd> + <kbd>L</kbd> 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 <kbd>/</kbd> 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
|
||||
|
||||
|
|
|
|||
|
|
@ -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`.
|
||||
Data destinations are configured in the [`data`](../../yaml-reference.md#data) section of `config.yaml`.
|
||||
|
|
|
|||
|
|
@ -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<void>;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,64 @@
|
|||
import { BookmarkIcon, ChatBubbleLeftIcon } from "@heroicons/react/24/outline";
|
||||
import { BookmarkIcon as BookmarkIconSolid } from "@heroicons/react/24/solid";
|
||||
import { SlashCommandDescription } from "core";
|
||||
import { useState } from "react";
|
||||
import { defaultBorderRadius, GhostButton, vscInputBackground } from "..";
|
||||
|
||||
interface ConversationStarterCardProps {
|
||||
command: SlashCommandDescription;
|
||||
onClick: (command: SlashCommandDescription) => void;
|
||||
onBookmark: (command: SlashCommandDescription) => void;
|
||||
isBookmarked: boolean;
|
||||
}
|
||||
|
||||
export function ConversationStarterCard({
|
||||
command,
|
||||
onClick,
|
||||
onBookmark,
|
||||
isBookmarked = false,
|
||||
}: ConversationStarterCardProps) {
|
||||
const [isHovered, setIsHovered] = useState(false);
|
||||
|
||||
return (
|
||||
<div
|
||||
className="mb-2 w-full shadow-md hover:brightness-110"
|
||||
style={{
|
||||
borderRadius: defaultBorderRadius,
|
||||
backgroundColor: vscInputBackground,
|
||||
}}
|
||||
onMouseEnter={() => setIsHovered(true)}
|
||||
onMouseLeave={() => setIsHovered(false)}
|
||||
>
|
||||
<div className="flex items-center px-3 py-1.5">
|
||||
<div className="mr-3 flex-shrink-0">
|
||||
<ChatBubbleLeftIcon className="text-lightgray h-5 w-5" />
|
||||
</div>
|
||||
<div
|
||||
onClick={() => onClick(command)}
|
||||
className="flex flex-1 flex-col hover:cursor-pointer"
|
||||
>
|
||||
<div className="font-medium">{command.name}</div>
|
||||
<div className="text-lightgray text-sm">{command.description}</div>
|
||||
</div>
|
||||
<div className="flex items-center">
|
||||
<GhostButton
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onBookmark(command);
|
||||
}}
|
||||
aria-label={
|
||||
isBookmarked ? "Remove bookmarked prompt" : "Bookmark prompt"
|
||||
}
|
||||
className={isHovered || isBookmarked ? "opacity-100" : "opacity-0"}
|
||||
>
|
||||
{isBookmarked ? (
|
||||
<BookmarkIconSolid className="h-4 w-4" />
|
||||
) : (
|
||||
<BookmarkIcon className="h-4 w-4" />
|
||||
)}
|
||||
</GhostButton>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
import { SlashCommandDescription } from "core";
|
||||
import { useAppDispatch } from "../../redux/hooks";
|
||||
import { setMainEditorContentTrigger } from "../../redux/slices/sessionSlice";
|
||||
import { getParagraphNodeFromString } from "../mainInput/utils";
|
||||
import { ConversationStarterCard } from "./ConversationStarterCard";
|
||||
import { useBookmarkedSlashCommands } from "./useBookmarkedSlashCommands";
|
||||
|
||||
const NUM_CARDS_TO_RENDER = 3;
|
||||
|
||||
export function ConversationStarterCards() {
|
||||
const dispatch = useAppDispatch();
|
||||
const { cmdsSortedByBookmark, bookmarkStatuses, toggleBookmark } =
|
||||
useBookmarkedSlashCommands();
|
||||
|
||||
function onClick(command: SlashCommandDescription) {
|
||||
if (command.prompt) {
|
||||
dispatch(
|
||||
setMainEditorContentTrigger(getParagraphNodeFromString(command.prompt)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (!cmdsSortedByBookmark || cmdsSortedByBookmark.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex w-full max-w-full flex-col lg:grid lg:grid-cols-3 lg:gap-4">
|
||||
{cmdsSortedByBookmark.slice(0, NUM_CARDS_TO_RENDER).map((command, i) => (
|
||||
<ConversationStarterCard
|
||||
key={command.name + i}
|
||||
command={command}
|
||||
onClick={onClick}
|
||||
onBookmark={() => toggleBookmark(command)}
|
||||
isBookmarked={bookmarkStatuses[command.name]}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -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");
|
||||
});
|
||||
});
|
||||
1
gui/src/components/ConversationStarters/index.ts
Normal file
1
gui/src/components/ConversationStarters/index.ts
Normal file
|
|
@ -0,0 +1 @@
|
|||
export * from "./ConversationStarterCards";
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
import { SlashCommandDescription } from "core";
|
||||
import { usePostHog } from "posthog-js/react";
|
||||
import { useMemo } from "react";
|
||||
import {
|
||||
bookmarkSlashCommand,
|
||||
selectBookmarkedSlashCommands,
|
||||
selectSelectedProfileId,
|
||||
unbookmarkSlashCommand,
|
||||
} from "../../redux";
|
||||
import { useAppDispatch, useAppSelector } from "../../redux/hooks";
|
||||
import { isDeprecatedCommandName, sortCommandsByBookmarkStatus } from "./utils";
|
||||
|
||||
export function useBookmarkedSlashCommands() {
|
||||
const dispatch = useAppDispatch();
|
||||
const posthog = usePostHog();
|
||||
|
||||
const slashCommands =
|
||||
useAppSelector((state) => state.config.config.slashCommands) ?? [];
|
||||
const selectedProfileId = useAppSelector(selectSelectedProfileId);
|
||||
const bookmarkedCommands = useAppSelector(selectBookmarkedSlashCommands);
|
||||
|
||||
const filteredSlashCommands = slashCommands.filter(isDeprecatedCommandName);
|
||||
|
||||
// Create a map of command names to bookmark status
|
||||
const bookmarkStatuses = useMemo(() => {
|
||||
const statuses: Record<string, boolean> = {};
|
||||
if (selectedProfileId) {
|
||||
filteredSlashCommands.forEach((command) => {
|
||||
statuses[command.name] = bookmarkedCommands.includes(command.name);
|
||||
});
|
||||
}
|
||||
return statuses;
|
||||
}, [filteredSlashCommands, bookmarkedCommands, selectedProfileId]);
|
||||
|
||||
// Sort commands by bookmark status
|
||||
const cmdsSortedByBookmark = useMemo(
|
||||
() =>
|
||||
sortCommandsByBookmarkStatus(filteredSlashCommands, bookmarkedCommands),
|
||||
[filteredSlashCommands, bookmarkedCommands],
|
||||
);
|
||||
|
||||
const toggleBookmark = (command: SlashCommandDescription) => {
|
||||
const isBookmarked = bookmarkStatuses[command.name];
|
||||
|
||||
posthog.capture("toggle_bookmarked_slash_command", {
|
||||
isBookmarked,
|
||||
});
|
||||
|
||||
if (isBookmarked) {
|
||||
dispatch(
|
||||
unbookmarkSlashCommand({
|
||||
commandName: command.name,
|
||||
}),
|
||||
);
|
||||
} else {
|
||||
dispatch(
|
||||
bookmarkSlashCommand({
|
||||
commandName: command.name,
|
||||
}),
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
cmdsSortedByBookmark,
|
||||
bookmarkStatuses,
|
||||
toggleBookmark,
|
||||
};
|
||||
}
|
||||
49
gui/src/components/ConversationStarters/utils.ts
Normal file
49
gui/src/components/ConversationStarters/utils.ts
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
import { SlashCommandDescription } from "core";
|
||||
import {
|
||||
defaultSlashCommandsJetBrains,
|
||||
defaultSlashCommandsVscode,
|
||||
} from "core/config/default";
|
||||
import { isJetBrains } from "../../util";
|
||||
|
||||
/**
|
||||
* The commands filtered here are currently inserted into the slash commands array during
|
||||
* intermediary config loading, but once we get the actual prompts for an assistant,
|
||||
* they are overwritten.
|
||||
*
|
||||
* Additionally, these default commands are all deprecated.
|
||||
*
|
||||
* If we don't manually filter them out, then they are displayed in the UI
|
||||
* while the assistant is still loading.
|
||||
*
|
||||
* Once these commands are no longer inserted during intermediary config loading,
|
||||
* this function can be removed.
|
||||
*/
|
||||
export function isDeprecatedCommandName(command: SlashCommandDescription) {
|
||||
const defaultCommands = isJetBrains()
|
||||
? defaultSlashCommandsJetBrains
|
||||
: defaultSlashCommandsVscode;
|
||||
|
||||
return !defaultCommands.find(
|
||||
(defaultCommand) => defaultCommand.name === command.name,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts commands with bookmarked ones first
|
||||
* @param commands The list of commands to sort
|
||||
* @param bookmarkedCommands An array of bookmarked command names
|
||||
* @returns A new sorted array with bookmarked commands first
|
||||
*/
|
||||
export function sortCommandsByBookmarkStatus(
|
||||
commands: SlashCommandDescription[],
|
||||
bookmarkedCommands: string[],
|
||||
): SlashCommandDescription[] {
|
||||
return [...commands].sort((a, b) => {
|
||||
const aIsBookmarked = bookmarkedCommands.includes(a.name);
|
||||
const bIsBookmarked = bookmarkedCommands.includes(b.name);
|
||||
|
||||
if (aIsBookmarked && !bIsBookmarked) return -1;
|
||||
if (!aIsBookmarked && bIsBookmarked) return 1;
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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};
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import {
|
||||
ArrowRightIcon,
|
||||
AtSymbolIcon,
|
||||
BoltIcon,
|
||||
ChatBubbleLeftIcon,
|
||||
PlusIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { Editor } from "@tiptap/react";
|
||||
|
|
@ -36,7 +36,8 @@ export function getIconFromDropdownItem(
|
|||
id: string | undefined,
|
||||
type: ComboBoxItemType,
|
||||
) {
|
||||
const typeIcon = type === "contextProvider" ? AtSymbolIcon : BoltIcon;
|
||||
const typeIcon =
|
||||
type === "contextProvider" ? AtSymbolIcon : ChatBubbleLeftIcon;
|
||||
return id ? (NAMED_ICONS[id] ?? typeIcon) : typeIcon;
|
||||
}
|
||||
|
||||
|
|
@ -454,7 +455,6 @@ const MentionList = forwardRef((props: MentionListProps, ref) => {
|
|||
) : (
|
||||
<ItemDiv className="item">No results</ItemDiv>
|
||||
)}
|
||||
{/* </CustomScrollbarDiv> */}
|
||||
</>
|
||||
)}
|
||||
</ItemsDiv>
|
||||
|
|
|
|||
|
|
@ -563,7 +563,7 @@ function TipTapEditor(props: TipTapEditorProps) {
|
|||
}
|
||||
|
||||
return historyLength === 0
|
||||
? "Ask anything, '@' to add context"
|
||||
? "Ask anything, '/' for prompts, '@' to add context"
|
||||
: "Ask a follow-up";
|
||||
}
|
||||
|
||||
|
|
@ -994,7 +994,6 @@ function TipTapEditor(props: TipTapEditorProps) {
|
|||
activeKey={activeKey}
|
||||
hidden={shouldHideToolbar && !props.isMainInput}
|
||||
onAddContextItem={() => insertCharacterWithWhitespace("@")}
|
||||
onAddSlashCommand={() => insertCharacterWithWhitespace("/")}
|
||||
onEnter={onEnterRef.current}
|
||||
onImageFileSelected={(file) => {
|
||||
handleImageFile(file).then((result) => {
|
||||
|
|
|
|||
|
|
@ -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 (
|
||||
<div
|
||||
className="border-0.5 border-lightGray bg-vsc-background m-1 max-w-96 rounded-md border-solid px-3 py-3 sm:px-5"
|
||||
data-testid={`tutorial-card`}
|
||||
>
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="m-0 p-0"></h3>
|
||||
<div
|
||||
onClick={onClose}
|
||||
className="cursor-pointer items-center justify-center"
|
||||
>
|
||||
<XMarkIcon className="h-5 w-5" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ul className="space-y-4 pl-0" style={{ color: lightGray }}>
|
||||
{!jetbrains && (
|
||||
<li className="flex items-start">
|
||||
<ArrowRightStartOnRectangleIcon className="h-4 w-4 pr-3 align-middle" />
|
||||
<span>
|
||||
<span
|
||||
className="cursor-pointer underline"
|
||||
onClick={() =>
|
||||
ideMessenger.post("vscode/openMoveRightMarkdown", undefined)
|
||||
}
|
||||
>
|
||||
Move Chat panel to the right
|
||||
</span>{" "}
|
||||
for the cleanest experience
|
||||
</span>
|
||||
</li>
|
||||
)}
|
||||
<li className="flex items-start">
|
||||
<div>
|
||||
<PencilSquareIcon className="h-4 w-4 pr-3 align-middle" />
|
||||
</div>
|
||||
<span>
|
||||
Highlight code and press <Shortcut>meta I</Shortcut> to quickly make
|
||||
natural language edits
|
||||
</span>
|
||||
</li>
|
||||
<li className="flex items-start">
|
||||
<div>
|
||||
<ClipboardDocumentIcon className="h-4 w-4 pr-3 align-middle" />
|
||||
</div>
|
||||
<span>
|
||||
Highlight code and press <Shortcut>meta L</Shortcut> to add it to
|
||||
the chat window
|
||||
</span>
|
||||
</li>
|
||||
<li className="flex items-start">
|
||||
<div>
|
||||
<Cog6ToothIcon className="h-4 w-4 pr-3 align-middle" />
|
||||
</div>
|
||||
<span>
|
||||
Click the gear icon in the upper right to configure Continue
|
||||
</span>
|
||||
</li>
|
||||
<li className="flex items-start">
|
||||
<div>
|
||||
<BookOpenIcon className="h-4 w-4 pr-3 align-middle" />
|
||||
</div>
|
||||
<span>
|
||||
<a
|
||||
className="cursor-pointer text-inherit underline hover:text-inherit"
|
||||
onClick={() =>
|
||||
ideMessenger.post("openUrl", "https://docs.continue.dev")
|
||||
}
|
||||
>
|
||||
Read our documentation
|
||||
</a>{" "}
|
||||
to learn more
|
||||
</span>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -8,8 +8,8 @@ import { MutableRefObject } from "react";
|
|||
import tippy from "tippy.js";
|
||||
import { IIdeMessenger } from "../../context/IdeMessenger";
|
||||
import MentionList from "./MentionList";
|
||||
import { ComboBoxItem, ComboBoxItemType, ComboBoxSubAction } from "./types";
|
||||
import { TIPPY_DIV_ID } from "./TipTapEditor";
|
||||
import { ComboBoxItem, ComboBoxItemType, ComboBoxSubAction } from "./types";
|
||||
|
||||
function getSuggestion(
|
||||
items: (props: { query: string }) => Promise<ComboBoxItem[]>,
|
||||
|
|
@ -198,27 +198,18 @@ export function getSlashCommandDropdownOptions(
|
|||
ideMessenger: IIdeMessenger,
|
||||
) {
|
||||
const items = async ({ query }: { query: string }) => {
|
||||
const options = [
|
||||
...availableSlashCommandsRef.current,
|
||||
// {
|
||||
// title: "Build a custom prompt",
|
||||
// description: "Build a custom prompt",
|
||||
// type: "action",
|
||||
// id: "createPromptFile",
|
||||
// label: "Create Prompt File",
|
||||
// action: () => {
|
||||
// ideMessenger.post("config/newPromptFile", undefined);
|
||||
// },
|
||||
// name: "Create Prompt File",
|
||||
// },
|
||||
];
|
||||
return (
|
||||
options.filter((slashCommand) => {
|
||||
const sc = slashCommand.title.substring(1).toLowerCase();
|
||||
const iv = query.toLowerCase();
|
||||
return sc.startsWith(iv);
|
||||
}) || []
|
||||
).map((provider) => ({
|
||||
const options = [...availableSlashCommandsRef.current];
|
||||
|
||||
const filteredCommands =
|
||||
query.length > 0
|
||||
? options.filter((slashCommand) => {
|
||||
const sc = slashCommand.title.substring(1).toLowerCase();
|
||||
const iv = query.toLowerCase();
|
||||
return sc.startsWith(iv);
|
||||
})
|
||||
: options;
|
||||
|
||||
const commandItems = (filteredCommands || []).map((provider) => ({
|
||||
name: provider.title,
|
||||
description: provider.description,
|
||||
id: provider.title,
|
||||
|
|
@ -227,6 +218,24 @@ export function getSlashCommandDropdownOptions(
|
|||
type: (provider.type ?? "slashCommand") as ComboBoxItemType,
|
||||
action: provider.action,
|
||||
}));
|
||||
|
||||
if (query.length === 0 && commandItems.length > 0) {
|
||||
commandItems.push({
|
||||
title: "Explore prompts",
|
||||
type: "action",
|
||||
action: () =>
|
||||
ideMessenger.post(
|
||||
"openUrl",
|
||||
"https://hub.continue.dev/explore/prompts",
|
||||
),
|
||||
description: "",
|
||||
name: "",
|
||||
id: "",
|
||||
label: "",
|
||||
});
|
||||
}
|
||||
|
||||
return commandItems;
|
||||
};
|
||||
return getSuggestion(items, undefined, onClose, onOpen);
|
||||
}
|
||||
|
|
|
|||
18
gui/src/components/mainInput/utils.ts
Normal file
18
gui/src/components/mainInput/utils.ts
Normal file
|
|
@ -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,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
|
|
@ -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";
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
|
|
|
|||
|
|
@ -12,14 +12,11 @@ import React, {
|
|||
} from "react";
|
||||
import ConfirmationDialog from "../components/dialogs/ConfirmationDialog";
|
||||
import { useWebviewListener } from "../hooks/useWebviewListener";
|
||||
import { updateOrgsThunk, updateProfilesThunk } from "../redux";
|
||||
import { selectSelectedProfile } from "../redux/";
|
||||
import { useAppDispatch, useAppSelector } from "../redux/hooks";
|
||||
import { setLastControlServerBetaEnabledStatus } from "../redux/slices/miscSlice";
|
||||
import { selectSelectedProfile } from "../redux/slices/sessionSlice";
|
||||
import { setDialogMessage, setShowDialog } from "../redux/slices/uiSlice";
|
||||
import {
|
||||
updateOrgsThunk,
|
||||
updateProfilesThunk,
|
||||
} from "../redux/thunks/profileAndOrg";
|
||||
import { IdeMessengerContext } from "./IdeMessenger";
|
||||
|
||||
interface AuthContextType {
|
||||
|
|
@ -48,9 +45,9 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
|
|||
);
|
||||
|
||||
// Orgs
|
||||
const orgs = useAppSelector((store) => store.session.organizations);
|
||||
const orgs = useAppSelector((store) => store.organizations.organizations);
|
||||
const selectedOrgId = useAppSelector(
|
||||
(store) => store.session.selectedOrganizationId,
|
||||
(store) => store.organizations.selectedOrganizationId,
|
||||
);
|
||||
const selectedOrganization = useMemo(() => {
|
||||
if (!selectedOrgId) {
|
||||
|
|
@ -60,7 +57,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
|
|||
}, [orgs, selectedOrgId]);
|
||||
|
||||
// Profiles
|
||||
const profiles = useAppSelector((store) => store.session.availableProfiles);
|
||||
const profiles = useAppSelector((store) => store.profiles.availableProfiles);
|
||||
const selectedProfile = useAppSelector(selectSelectedProfile);
|
||||
|
||||
const login: AuthContextType["login"] = (useOnboarding: boolean) => {
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
|
|
|
|||
|
|
@ -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<boolean>(
|
||||
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;
|
||||
|
|
@ -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 }) {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,15 @@
|
|||
import { Fragment } from "react";
|
||||
import { Listbox, Transition } from "@headlessui/react";
|
||||
import {
|
||||
ChevronUpDownIcon,
|
||||
InformationCircleIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { type ModelDescription } from "core";
|
||||
import { Fragment } from "react";
|
||||
import { ToolTip } from "../../components/gui/Tooltip";
|
||||
|
||||
/**
|
||||
* A component for selecting a model for a specific role
|
||||
*/
|
||||
interface ModelRoleSelectorProps {
|
||||
models: ModelDescription[];
|
||||
selectedModel: ModelDescription | null;
|
||||
|
|
@ -38,56 +41,57 @@ const ModelRoleSelector = ({
|
|||
{description}
|
||||
</ToolTip>
|
||||
</div>
|
||||
<Listbox value={selectedModel?.title ?? null} onChange={handleSelect}>
|
||||
{({ open }) => (
|
||||
<div className="relative">
|
||||
<Listbox.Button
|
||||
className={`border-vsc-input-border bg-vsc-background ${!!models.length ? "hover:bg-vsc-input-background cursor-pointer" : ""} text-vsc-foreground relative m-0 flex w-full items-center justify-between rounded-md border border-solid px-2 py-1 text-left`}
|
||||
>
|
||||
{models.length === 0 ? (
|
||||
<span className="text-lightgray italic">{`No ${displayName} models${["Chat", "Apply", "Edit"].includes(displayName) ? ". Using chat model" : ""}`}</span>
|
||||
) : (
|
||||
|
||||
{models.length === 0 ? (
|
||||
<span className="text-lightgray">
|
||||
{["Chat", "Apply", "Edit"].includes(displayName)
|
||||
? "None (defaulting to Chat model)"
|
||||
: "None"}
|
||||
</span>
|
||||
) : (
|
||||
<Listbox value={selectedModel?.title ?? null} onChange={handleSelect}>
|
||||
{({ open }) => (
|
||||
<div className="relative">
|
||||
<Listbox.Button className="border-vsc-input-border bg-vsc-background hover:bg-vsc-input-background text-vsc-foreground relative m-0 flex w-full cursor-pointer items-center justify-between rounded-md border border-solid px-2 py-1 text-left">
|
||||
<span className="lines lines-1">
|
||||
{selectedModel?.title ?? `Select ${displayName} model`}
|
||||
</span>
|
||||
)}
|
||||
{models.length ? (
|
||||
<div className="pointer-events-none flex items-center">
|
||||
<ChevronUpDownIcon
|
||||
className="h-3.5 w-3.5"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
</div>
|
||||
) : null}
|
||||
</Listbox.Button>
|
||||
</Listbox.Button>
|
||||
|
||||
<Transition
|
||||
as={Fragment}
|
||||
show={open}
|
||||
enter="transition ease-out duration-100"
|
||||
enterFrom="transform opacity-0 scale-95"
|
||||
enterTo="transform opacity-100 scale-100"
|
||||
leave="transition ease-in duration-75"
|
||||
leaveFrom="transform opacity-100 scale-100"
|
||||
leaveTo="transform opacity-0 scale-95"
|
||||
>
|
||||
<Listbox.Options className="bg-vsc-background max-h-80vh absolute z-[800] mt-0.5 w-full overflow-y-scroll rounded-sm p-0">
|
||||
{models.map((option, idx) => (
|
||||
<Listbox.Option
|
||||
key={idx}
|
||||
value={option.title}
|
||||
className={`text-vsc-foreground hover:text-list-active-foreground flex cursor-pointer flex-row items-center gap-3 px-2 py-1 ${option?.title === selectedModel?.title ? "bg-list-active" : "bg-vsc-input-background"}`}
|
||||
>
|
||||
<span className="lines lines-1 relative flex h-5 items-center justify-between gap-3 pr-2 text-xs">
|
||||
{option.title}
|
||||
</span>
|
||||
</Listbox.Option>
|
||||
))}
|
||||
</Listbox.Options>
|
||||
</Transition>
|
||||
</div>
|
||||
)}
|
||||
</Listbox>
|
||||
<Transition
|
||||
as={Fragment}
|
||||
show={open}
|
||||
enter="transition ease-out duration-100"
|
||||
enterFrom="transform opacity-0 scale-95"
|
||||
enterTo="transform opacity-100 scale-100"
|
||||
leave="transition ease-in duration-75"
|
||||
leaveFrom="transform opacity-100 scale-100"
|
||||
leaveTo="transform opacity-0 scale-95"
|
||||
>
|
||||
<Listbox.Options className="bg-vsc-background max-h-80vh absolute z-[800] mt-0.5 w-full overflow-y-scroll rounded-sm p-0">
|
||||
{models.map((option, idx) => (
|
||||
<Listbox.Option
|
||||
key={idx}
|
||||
value={option.title}
|
||||
className={`text-vsc-foreground hover:text-list-active-foreground flex cursor-pointer flex-row items-center gap-3 px-2 py-1 ${option?.title === selectedModel?.title ? "bg-list-active" : "bg-vsc-input-background"}`}
|
||||
>
|
||||
<span className="lines lines-1 relative flex h-5 items-center justify-between gap-3 pr-2 text-xs">
|
||||
{option.title}
|
||||
</span>
|
||||
</Listbox.Option>
|
||||
))}
|
||||
</Listbox.Options>
|
||||
</Transition>
|
||||
</div>
|
||||
)}
|
||||
</Listbox>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@ import {
|
|||
} from "@heroicons/react/24/outline";
|
||||
import { useAuth } from "../../context/Auth";
|
||||
import { useWebviewListener } from "../../hooks/useWebviewListener";
|
||||
import { selectOrgThunk } from "../../redux";
|
||||
import { useAppDispatch, useAppSelector } from "../../redux/hooks";
|
||||
import { selectOrgThunk } from "../../redux/thunks/profileAndOrg";
|
||||
|
||||
export function ScopeSelect() {
|
||||
const { organizations, selectedOrganization } = useAuth();
|
||||
const selectedOrgId = useAppSelector(
|
||||
(state) => state.session.selectedOrganizationId,
|
||||
(state) => state.organizations.selectedOrganizationId,
|
||||
);
|
||||
const dispatch = useAppDispatch();
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ import {
|
|||
import CodeToEditCard from "../../components/CodeToEditCard";
|
||||
import FeedbackDialog from "../../components/dialogs/FeedbackDialog";
|
||||
import FreeTrialOverDialog from "../../components/dialogs/FreeTrialOverDialog";
|
||||
import { ExploreHubCard } from "../../components/ExploreHubCard";
|
||||
import { useFindWidget } from "../../components/find/FindWidget";
|
||||
import TimelineItem from "../../components/gui/TimelineItem";
|
||||
import ChatIndexingPeeks from "../../components/indexing/ChatIndexingPeeks";
|
||||
|
|
@ -30,19 +29,13 @@ import ContinueInputBox from "../../components/mainInput/ContinueInputBox";
|
|||
import { NewSessionButton } from "../../components/mainInput/NewSessionButton";
|
||||
import resolveEditorContent from "../../components/mainInput/resolveInput";
|
||||
import ThinkingBlockPeek from "../../components/mainInput/ThinkingBlockPeek";
|
||||
import { TutorialCard } from "../../components/mainInput/TutorialCard";
|
||||
import AssistantSelect from "../../components/modelSelection/platform/AssistantSelect";
|
||||
import {
|
||||
OnboardingCard,
|
||||
useOnboardingCard,
|
||||
} from "../../components/OnboardingCard";
|
||||
import { PlatformOnboardingCard } from "../../components/OnboardingCard/platform/PlatformOnboardingCard";
|
||||
import { useOnboardingCard } from "../../components/OnboardingCard";
|
||||
import PageHeader from "../../components/PageHeader";
|
||||
import StepContainer from "../../components/StepContainer";
|
||||
import AcceptRejectAllButtons from "../../components/StepContainer/AcceptRejectAllButtons";
|
||||
import { TabBar } from "../../components/TabBar/TabBar";
|
||||
import { IdeMessengerContext } from "../../context/IdeMessenger";
|
||||
import { useTutorialCard } from "../../hooks/useTutorialCard";
|
||||
import { useWebviewListener } from "../../hooks/useWebviewListener";
|
||||
import { useAppDispatch, useAppSelector } from "../../redux/hooks";
|
||||
import { selectUseHub } from "../../redux/selectors";
|
||||
|
|
@ -78,6 +71,7 @@ import {
|
|||
import getMultifileEditPrompt from "../../util/getMultifileEditPrompt";
|
||||
import { getLocalStorage, setLocalStorage } from "../../util/localStorage";
|
||||
import ConfigErrorIndicator from "./ConfigError";
|
||||
import { EmptyChatBody } from "./EmptyChatBody";
|
||||
import { ExploreDialogWatcher } from "./ExploreDialogWatcher";
|
||||
import { ToolCallDiv } from "./ToolCallDiv";
|
||||
import { ToolCallButtons } from "./ToolCallDiv/ToolCallButtonsDiv";
|
||||
|
|
@ -145,7 +139,6 @@ export function Chat() {
|
|||
const dispatch = useAppDispatch();
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const onboardingCard = useOnboardingCard();
|
||||
const { showTutorialCard, closeTutorialCard } = useTutorialCard();
|
||||
const showSessionTabs = useAppSelector(
|
||||
(store) => store.config.config.ui?.showSessionTabs,
|
||||
);
|
||||
|
|
@ -538,29 +531,10 @@ export function Chat() {
|
|||
{!hasDismissedExploreDialog && <ExploreDialogWatcher />}
|
||||
|
||||
{history.length === 0 && (
|
||||
<>
|
||||
{onboardingCard.show && (
|
||||
<div className="mx-2 mt-10">
|
||||
{useHub ? (
|
||||
<PlatformOnboardingCard isDialog={false} />
|
||||
) : (
|
||||
<OnboardingCard isDialog={false} />
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{showTutorialCard !== false && !onboardingCard.show && (
|
||||
<div className="flex w-full justify-center">
|
||||
<TutorialCard onClose={closeTutorialCard} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!onboardingCard.show && showTutorialCard === false && (
|
||||
<div className="mx-2 mt-10">
|
||||
<ExploreHubCard />
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
<EmptyChatBody
|
||||
useHub={useHub}
|
||||
showOnboardingCard={onboardingCard.show}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
33
gui/src/pages/gui/EmptyChatBody.tsx
Normal file
33
gui/src/pages/gui/EmptyChatBody.tsx
Normal file
|
|
@ -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 (
|
||||
<div className="mx-2 mt-6">
|
||||
{useHub ? (
|
||||
<PlatformOnboardingCard isDialog={false} />
|
||||
) : (
|
||||
<OnboardingCard isDialog={false} />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="mx-2 mt-2">
|
||||
<ExploreHubCard />
|
||||
<ConversationStarterCards />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -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";
|
||||
|
|
|
|||
1
gui/src/redux/index.ts
Normal file
1
gui/src/redux/index.ts
Normal file
|
|
@ -0,0 +1 @@
|
|||
export * from "./slices";
|
||||
|
|
@ -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,
|
||||
};
|
||||
|
|
|
|||
2
gui/src/redux/slices/index.ts
Normal file
2
gui/src/redux/slices/index.ts
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
export * from "./organizations";
|
||||
export * from "./profiles";
|
||||
2
gui/src/redux/slices/organizations/index.ts
Normal file
2
gui/src/redux/slices/organizations/index.ts
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
export * from "./slice";
|
||||
export * from "./thunks";
|
||||
50
gui/src/redux/slices/organizations/slice.ts
Normal file
50
gui/src/redux/slices/organizations/slice.ts
Normal file
|
|
@ -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<OrganizationDescription[]>,
|
||||
) => {
|
||||
state.organizations = payload;
|
||||
},
|
||||
setSelectedOrganizationId: (
|
||||
state,
|
||||
{ payload }: PayloadAction<string | null>,
|
||||
) => {
|
||||
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;
|
||||
47
gui/src/redux/slices/organizations/thunks.ts
Normal file
47
gui/src/redux/slices/organizations/thunks.ts
Normal file
|
|
@ -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));
|
||||
});
|
||||
2
gui/src/redux/slices/profiles/index.ts
Normal file
2
gui/src/redux/slices/profiles/index.ts
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
export * from "./slice";
|
||||
export * from "./thunks";
|
||||
109
gui/src/redux/slices/profiles/slice.ts
Normal file
109
gui/src/redux/slices/profiles/slice.ts
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
import { ProfileDescription } from "core/config/ConfigHandler";
|
||||
import { ensureProfilePreferences } from "./utils";
|
||||
|
||||
export interface PreferencesState {
|
||||
bookmarksByName: string[];
|
||||
}
|
||||
|
||||
export interface ProfilesState {
|
||||
availableProfiles: ProfileDescription[] | null;
|
||||
selectedProfileId: string | null;
|
||||
preferencesByProfileId: Record<string, PreferencesState>;
|
||||
}
|
||||
|
||||
const initialState: ProfilesState = {
|
||||
availableProfiles: null,
|
||||
selectedProfileId: null,
|
||||
preferencesByProfileId: {},
|
||||
};
|
||||
|
||||
export const profilesSlice = createSlice({
|
||||
name: "profiles",
|
||||
initialState,
|
||||
reducers: {
|
||||
setSelectedProfile: (state, { payload }: PayloadAction<string | null>) => {
|
||||
state.selectedProfileId = payload;
|
||||
|
||||
if (payload) {
|
||||
ensureProfilePreferences(state, payload);
|
||||
}
|
||||
},
|
||||
setAvailableProfiles: (
|
||||
state,
|
||||
{ payload }: PayloadAction<ProfileDescription[] | null>,
|
||||
) => {
|
||||
state.availableProfiles = payload;
|
||||
|
||||
if (payload) {
|
||||
for (const profile of payload) {
|
||||
ensureProfilePreferences(state, profile.id);
|
||||
}
|
||||
}
|
||||
},
|
||||
bookmarkSlashCommand: (
|
||||
state,
|
||||
action: PayloadAction<{ commandName: string }>,
|
||||
) => {
|
||||
const { commandName } = action.payload;
|
||||
const profileId = state.selectedProfileId;
|
||||
|
||||
if (!profileId) return;
|
||||
|
||||
const bookmarks = state.preferencesByProfileId[profileId].bookmarksByName;
|
||||
if (!bookmarks.includes(commandName)) {
|
||||
bookmarks.push(commandName);
|
||||
}
|
||||
},
|
||||
|
||||
unbookmarkSlashCommand: (
|
||||
state,
|
||||
action: PayloadAction<{ commandName: string }>,
|
||||
) => {
|
||||
const { commandName } = action.payload;
|
||||
const profileId = state.selectedProfileId;
|
||||
|
||||
if (!profileId) return;
|
||||
|
||||
const preferences = state.preferencesByProfileId[profileId];
|
||||
preferences.bookmarksByName = preferences.bookmarksByName.filter(
|
||||
(cmd) => cmd !== commandName,
|
||||
);
|
||||
},
|
||||
},
|
||||
selectors: {
|
||||
selectSelectedProfile: (state) => {
|
||||
return (
|
||||
state.availableProfiles?.find(
|
||||
(profile) => profile.id === state.selectedProfileId,
|
||||
) ?? null
|
||||
);
|
||||
},
|
||||
|
||||
selectSelectedProfileId: (state) => state.selectedProfileId,
|
||||
|
||||
selectBookmarkedSlashCommands: (state) => {
|
||||
if (!state.selectedProfileId) return [];
|
||||
const preferences = state.preferencesByProfileId[state.selectedProfileId];
|
||||
return preferences?.bookmarksByName || [];
|
||||
},
|
||||
|
||||
selectPreferencesByProfileId: (state) => state.preferencesByProfileId,
|
||||
},
|
||||
});
|
||||
|
||||
export const {
|
||||
setAvailableProfiles,
|
||||
setSelectedProfile,
|
||||
bookmarkSlashCommand,
|
||||
unbookmarkSlashCommand,
|
||||
} = profilesSlice.actions;
|
||||
|
||||
export const {
|
||||
selectSelectedProfile,
|
||||
selectSelectedProfileId,
|
||||
selectBookmarkedSlashCommands,
|
||||
selectPreferencesByProfileId,
|
||||
} = profilesSlice.selectors;
|
||||
|
||||
export const { reducer: profilesReducer } = profilesSlice;
|
||||
85
gui/src/redux/slices/profiles/thunks.ts
Normal file
85
gui/src/redux/slices/profiles/thunks.ts
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import { ProfileDescription } from "core/config/ConfigHandler";
|
||||
import { ThunkApiType } from "../../store";
|
||||
import { setAvailableProfiles, setSelectedProfile } from "./slice";
|
||||
|
||||
export const selectProfileThunk = createAsyncThunk<
|
||||
void,
|
||||
string | null,
|
||||
ThunkApiType
|
||||
>("profiles/select", async (id, { dispatch, extra, getState }) => {
|
||||
const state = getState();
|
||||
|
||||
if (state.profiles.availableProfiles === null) {
|
||||
// Currently in loading state
|
||||
return;
|
||||
}
|
||||
|
||||
const initialId = state.profiles.selectedProfileId;
|
||||
|
||||
let newId = id;
|
||||
|
||||
// If no profiles, force clear
|
||||
if (state.profiles.availableProfiles.length === 0) {
|
||||
newId = null;
|
||||
} else {
|
||||
// If new id doesn't match an existing profile, clear it
|
||||
if (newId) {
|
||||
if (!state.profiles.availableProfiles.find((p) => p.id === newId)) {
|
||||
newId = null;
|
||||
}
|
||||
}
|
||||
if (!newId) {
|
||||
// At this point if null ID and there ARE profiles,
|
||||
// Fallback to a profile, prioritizing the first in the list
|
||||
newId = state.profiles.availableProfiles[0].id;
|
||||
}
|
||||
}
|
||||
|
||||
// Only update if there's a change
|
||||
if ((newId ?? null) !== (initialId ?? null)) {
|
||||
dispatch(setSelectedProfile(newId));
|
||||
extra.ideMessenger.post("didChangeSelectedProfile", {
|
||||
id: newId,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
export const cycleProfile = createAsyncThunk<void, undefined, ThunkApiType>(
|
||||
"profiles/cycle",
|
||||
async (_, { dispatch, getState }) => {
|
||||
const state = getState();
|
||||
|
||||
if (state.profiles.availableProfiles === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
const profileIds = state.profiles.availableProfiles.map(
|
||||
(profile) => profile.id,
|
||||
);
|
||||
// In case of no profiles just does nothing
|
||||
if (profileIds.length === 0) {
|
||||
return;
|
||||
}
|
||||
let nextId = profileIds[0];
|
||||
if (state.profiles.selectedProfileId) {
|
||||
const curIndex = profileIds.indexOf(state.profiles.selectedProfileId);
|
||||
const nextIndex = (curIndex + 1) % profileIds.length;
|
||||
nextId = profileIds[nextIndex];
|
||||
}
|
||||
await dispatch(selectProfileThunk(nextId));
|
||||
},
|
||||
);
|
||||
|
||||
export const updateProfilesThunk = createAsyncThunk<
|
||||
void,
|
||||
{ profiles: ProfileDescription[] | null; selectedProfileId: string | null },
|
||||
ThunkApiType
|
||||
>("profiles/update", async (data, { dispatch, extra, getState }) => {
|
||||
const { profiles, selectedProfileId } = data;
|
||||
|
||||
dispatch(setAvailableProfiles(profiles));
|
||||
|
||||
// This will trigger reselection if needed
|
||||
dispatch(selectProfileThunk(selectedProfileId));
|
||||
});
|
||||
12
gui/src/redux/slices/profiles/utils.ts
Normal file
12
gui/src/redux/slices/profiles/utils.ts
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import { ProfilesState } from "./slice";
|
||||
|
||||
export function ensureProfilePreferences(
|
||||
state: ProfilesState,
|
||||
profileId: string,
|
||||
) {
|
||||
if (!state.preferencesByProfileId[profileId]) {
|
||||
state.preferencesByProfileId[profileId] = {
|
||||
bookmarksByName: [],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -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<ChatMessage[]>) => {
|
||||
|
||||
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<string | null>) => {
|
||||
state.selectedProfileId = payload;
|
||||
},
|
||||
setAvailableProfiles: (
|
||||
state,
|
||||
{ payload }: PayloadAction<ProfileDescription[] | null>,
|
||||
) => {
|
||||
state.availableProfiles = payload;
|
||||
},
|
||||
setOrganizations: (
|
||||
state,
|
||||
{ payload }: PayloadAction<OrganizationDescription[]>,
|
||||
) => {
|
||||
state.organizations = payload;
|
||||
},
|
||||
setSelectedOrganizationId: (
|
||||
state,
|
||||
{ payload }: PayloadAction<string | null>,
|
||||
) => {
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import { createFilter } from "redux-persist-transform-filter";
|
|||
import autoMergeLevel2 from "redux-persist/lib/stateReconciler/autoMergeLevel2";
|
||||
import storage from "redux-persist/lib/storage";
|
||||
import { IdeMessenger, IIdeMessenger } from "../context/IdeMessenger";
|
||||
import { organizationsReducer, profilesReducer } from "./slices";
|
||||
import configReducer from "./slices/configSlice";
|
||||
import editModeStateReducer from "./slices/editModeState";
|
||||
import indexingReducer from "./slices/indexingSlice";
|
||||
|
|
@ -31,13 +32,13 @@ const rootReducer = combineReducers({
|
|||
config: configReducer,
|
||||
indexing: indexingReducer,
|
||||
tabs: tabsReducer,
|
||||
profiles: profilesReducer,
|
||||
organizations: organizationsReducer,
|
||||
});
|
||||
|
||||
const saveSubsetFilters = [
|
||||
createFilter("session", [
|
||||
"history",
|
||||
"selectedOrganizationId",
|
||||
"selectedProfile",
|
||||
"id",
|
||||
"lastSessionId",
|
||||
"title",
|
||||
|
|
@ -61,6 +62,12 @@ const saveSubsetFilters = [
|
|||
createFilter("ui", ["toolSettings", "toolGroupSettings", "useTools"]),
|
||||
createFilter("indexing", []),
|
||||
createFilter("tabs", ["tabs"]),
|
||||
// Add this new filter for the profiles slice
|
||||
createFilter("profiles", [
|
||||
"preferencesByProfileId",
|
||||
"selectedOrganizationId",
|
||||
"selectedProfileId",
|
||||
]),
|
||||
];
|
||||
|
||||
const migrations: MigrationManifest = {
|
||||
|
|
|
|||
|
|
@ -1,133 +0,0 @@
|
|||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import { ProfileDescription } from "core/config/ConfigHandler";
|
||||
import { OrganizationDescription } from "core/config/ProfileLifecycleManager";
|
||||
import {
|
||||
setAvailableProfiles,
|
||||
setOrganizations,
|
||||
setSelectedOrganizationId,
|
||||
setSelectedProfile,
|
||||
} from "../slices/sessionSlice";
|
||||
import { ThunkApiType } from "../store";
|
||||
|
||||
export const selectProfileThunk = createAsyncThunk<
|
||||
void,
|
||||
string | null,
|
||||
ThunkApiType
|
||||
>("profiles/select", async (id, { dispatch, extra, getState }) => {
|
||||
const state = getState();
|
||||
|
||||
if (state.session.availableProfiles === null) {
|
||||
// Currently in loading state
|
||||
return;
|
||||
}
|
||||
|
||||
const initialId = state.session.selectedProfileId;
|
||||
|
||||
let newId = id;
|
||||
|
||||
// If no profiles, force clear
|
||||
if (state.session.availableProfiles.length === 0) {
|
||||
newId = null;
|
||||
} else {
|
||||
// If new id doesn't match an existing profile, clear it
|
||||
if (newId) {
|
||||
if (!state.session.availableProfiles.find((p) => p.id === newId)) {
|
||||
newId = null;
|
||||
}
|
||||
}
|
||||
if (!newId) {
|
||||
// At this point if null ID and there ARE profiles,
|
||||
// Fallback to a profile, prioritizing the first in the list
|
||||
newId = state.session.availableProfiles[0].id;
|
||||
}
|
||||
}
|
||||
|
||||
// Only update if there's a change
|
||||
if ((newId ?? null) !== (initialId ?? null)) {
|
||||
dispatch(setSelectedProfile(newId));
|
||||
extra.ideMessenger.post("didChangeSelectedProfile", {
|
||||
id: newId,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
export const cycleProfile = createAsyncThunk<void, undefined, ThunkApiType>(
|
||||
"profiles/cycle",
|
||||
async (_, { dispatch, getState }) => {
|
||||
const state = getState();
|
||||
|
||||
if (state.session.availableProfiles === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
const profileIds = state.session.availableProfiles.map(
|
||||
(profile) => profile.id,
|
||||
);
|
||||
// In case of no profiles just does nothing
|
||||
if (profileIds.length === 0) {
|
||||
return;
|
||||
}
|
||||
let nextId = profileIds[0];
|
||||
if (state.session.selectedProfileId) {
|
||||
const curIndex = profileIds.indexOf(state.session.selectedProfileId);
|
||||
const nextIndex = (curIndex + 1) % profileIds.length;
|
||||
nextId = profileIds[nextIndex];
|
||||
}
|
||||
await dispatch(selectProfileThunk(nextId));
|
||||
},
|
||||
);
|
||||
|
||||
export const updateProfilesThunk = createAsyncThunk<
|
||||
void,
|
||||
{ profiles: ProfileDescription[] | null; selectedProfileId: string | null },
|
||||
ThunkApiType
|
||||
>("profiles/update", async (data, { dispatch, extra, getState }) => {
|
||||
const { profiles, selectedProfileId } = data;
|
||||
|
||||
dispatch(setAvailableProfiles(profiles));
|
||||
|
||||
// This will trigger reselection if needed
|
||||
dispatch(selectProfileThunk(selectedProfileId));
|
||||
});
|
||||
|
||||
export const selectOrgThunk = createAsyncThunk<
|
||||
void,
|
||||
string | null,
|
||||
ThunkApiType
|
||||
>("session/selectOrg", async (id, { dispatch, extra, getState }) => {
|
||||
const state = getState();
|
||||
const initialId = state.session.selectedOrganizationId;
|
||||
let newId = id;
|
||||
|
||||
// If no orgs, force clear
|
||||
if (state.session.organizations.length === 0) {
|
||||
newId = null;
|
||||
} else if (newId) {
|
||||
// If new id doesn't match an existing org, clear it
|
||||
if (!state.session.organizations.find((o) => o.id === newId)) {
|
||||
newId = null;
|
||||
}
|
||||
}
|
||||
// Unlike profiles, don't fallback to the first org,
|
||||
// Fallback to Personal (org = null)
|
||||
|
||||
if (initialId !== newId) {
|
||||
dispatch(setAvailableProfiles(null));
|
||||
dispatch(setSelectedOrganizationId(newId));
|
||||
extra.ideMessenger.post("didChangeSelectedOrg", {
|
||||
id: newId,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
export const updateOrgsThunk = createAsyncThunk<
|
||||
void,
|
||||
OrganizationDescription[],
|
||||
ThunkApiType
|
||||
>("session/updateOrgs", async (orgs, { dispatch, getState }) => {
|
||||
const state = getState();
|
||||
dispatch(setOrganizations(orgs));
|
||||
|
||||
// This will trigger reselection if needed
|
||||
dispatch(selectOrgThunk(state.session.selectedOrganizationId));
|
||||
});
|
||||
Loading…
Add table
Reference in a new issue