feat: bookmark first 5 prompts by default
This commit is contained in:
parent
009e88bbe0
commit
0909ef938b
12 changed files with 199 additions and 143 deletions
4
extensions/vscode/package-lock.json
generated
4
extensions/vscode/package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "continue",
|
||||
"version": "1.1.13",
|
||||
"version": "1.1.14",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "continue",
|
||||
"version": "1.1.13",
|
||||
"version": "1.1.14",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@continuedev/fetch": "^1.0.3",
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
import { ChatBubbleLeftIcon } from "@heroicons/react/24/outline";
|
||||
import { SlashCommandDescription } from "core";
|
||||
import { useState } from "react";
|
||||
import { defaultBorderRadius, vscInputBackground } from "..";
|
||||
|
||||
interface ConversationStarterCardProps {
|
||||
command: SlashCommandDescription;
|
||||
|
|
@ -12,26 +10,20 @@ export function ConversationStarterCard({
|
|||
command,
|
||||
onClick,
|
||||
}: ConversationStarterCardProps) {
|
||||
const [isHovered, setIsHovered] = useState(false);
|
||||
|
||||
return (
|
||||
<div
|
||||
className="mb-2 w-full shadow-md hover:cursor-pointer hover:brightness-110"
|
||||
style={{
|
||||
borderRadius: defaultBorderRadius,
|
||||
backgroundColor: vscInputBackground,
|
||||
}}
|
||||
onMouseEnter={() => setIsHovered(true)}
|
||||
onMouseLeave={() => setIsHovered(false)}
|
||||
className="bg-vsc-input-background mb-2 w-full rounded-md shadow-md hover:cursor-pointer hover:brightness-110"
|
||||
onClick={() => onClick(command)}
|
||||
>
|
||||
<div className="flex px-3 py-1.5">
|
||||
<div className="mr-3 flex-shrink-0 self-start pt-0.5">
|
||||
<ChatBubbleLeftIcon className="text-lightgray h-5 w-5" />
|
||||
</div>
|
||||
<div className="flex flex-1 flex-col">
|
||||
<div className="flex flex-1 flex-col justify-center">
|
||||
<div className="text-xs font-medium">{command.name}</div>
|
||||
<div className="text-lightgray text-xs">{command.description}</div>
|
||||
{command.description && (
|
||||
<div className="text-lightgray text-xs">{command.description}</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,17 +1,28 @@
|
|||
import { SlashCommandDescription } from "core";
|
||||
import { useAppDispatch } from "../../redux/hooks";
|
||||
import { useState } from "react";
|
||||
import { useBookmarkedSlashCommands } from "../../hooks/useBookmarkedSlashCommands";
|
||||
import { useAppDispatch, useAppSelector } 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;
|
||||
const NUM_CARDS_TO_RENDER = 5;
|
||||
|
||||
export function ConversationStarterCards() {
|
||||
const dispatch = useAppDispatch();
|
||||
const { cmdsSortedByBookmark } = useBookmarkedSlashCommands();
|
||||
const [showAll, setShowAll] = useState(false);
|
||||
const { isCommandBookmarked } = useBookmarkedSlashCommands();
|
||||
const slashCommands = useAppSelector(
|
||||
(state) => state.config.config.slashCommands ?? [],
|
||||
);
|
||||
|
||||
const bookmarkedSlashCommands = slashCommands.filter((command) =>
|
||||
isCommandBookmarked(command.name),
|
||||
);
|
||||
|
||||
function onClick(command: SlashCommandDescription) {
|
||||
debugger;
|
||||
|
||||
if (command.prompt) {
|
||||
dispatch(
|
||||
setMainEditorContentTrigger(getParagraphNodeFromString(command.prompt)),
|
||||
|
|
@ -19,19 +30,35 @@ export function ConversationStarterCards() {
|
|||
}
|
||||
}
|
||||
|
||||
if (!cmdsSortedByBookmark || cmdsSortedByBookmark.length === 0) {
|
||||
if (bookmarkedSlashCommands.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const visibleCommands = showAll
|
||||
? bookmarkedSlashCommands
|
||||
: bookmarkedSlashCommands.slice(0, NUM_CARDS_TO_RENDER);
|
||||
|
||||
const remainingCount = bookmarkedSlashCommands.length - NUM_CARDS_TO_RENDER;
|
||||
|
||||
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}
|
||||
/>
|
||||
))}
|
||||
<div className="flex w-full max-w-full flex-col">
|
||||
<div className="lg:grid lg:grid-cols-3 lg:gap-4">
|
||||
{visibleCommands.map((command, i) => (
|
||||
<ConversationStarterCard
|
||||
key={command.name + i}
|
||||
command={command}
|
||||
onClick={onClick}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
{bookmarkedSlashCommands.length > NUM_CARDS_TO_RENDER && (
|
||||
<span
|
||||
className="text-lightgray mt-1 cursor-pointer text-xs hover:underline"
|
||||
onClick={() => setShowAll(!showAll)}
|
||||
>
|
||||
{showAll ? "Show less" : `Show ${remainingCount} more...`}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,69 +0,0 @@
|
|||
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,
|
||||
};
|
||||
}
|
||||
|
|
@ -3,8 +3,9 @@ import {
|
|||
PencilIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { BookmarkIcon as BookmarkSolid } from "@heroicons/react/24/solid";
|
||||
import { useBookmarkedSlashCommands } from "../../../../hooks/useBookmarkedSlashCommands";
|
||||
import { useAppSelector } from "../../../../redux/hooks";
|
||||
import { fontSize } from "../../../../util";
|
||||
import { useBookmarkedSlashCommands } from "../../../ConversationStarters/useBookmarkedSlashCommands";
|
||||
import { AddBlockButton } from "./AddBlockButton";
|
||||
|
||||
interface PromptRowProps {
|
||||
|
|
@ -54,22 +55,32 @@ function PromptRow({
|
|||
}
|
||||
|
||||
export function PromptsSection() {
|
||||
const { cmdsSortedByBookmark, bookmarkStatuses, toggleBookmark } =
|
||||
useBookmarkedSlashCommands();
|
||||
const { isCommandBookmarked, toggleBookmark } = useBookmarkedSlashCommands();
|
||||
const slashCommands = useAppSelector(
|
||||
(state) => state.config.config.slashCommands ?? [],
|
||||
);
|
||||
|
||||
const handleEdit = (prompt: any) => {
|
||||
// Handle edit action here
|
||||
console.log("Editing prompt:", prompt);
|
||||
};
|
||||
|
||||
const sortedCommands = [...slashCommands].sort((a, b) => {
|
||||
const aBookmarked = isCommandBookmarked(a.name);
|
||||
const bBookmarked = isCommandBookmarked(b.name);
|
||||
if (aBookmarked && !bBookmarked) return -1;
|
||||
if (!aBookmarked && bBookmarked) return 1;
|
||||
return 0;
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-1">
|
||||
{cmdsSortedByBookmark?.map((prompt, i) => (
|
||||
{sortedCommands.map((prompt) => (
|
||||
<PromptRow
|
||||
key={prompt.name}
|
||||
command={prompt.name}
|
||||
description={prompt.description}
|
||||
isBookmarked={bookmarkStatuses[prompt.name]}
|
||||
isBookmarked={isCommandBookmarked(prompt.name)}
|
||||
setIsBookmarked={() => toggleBookmark(prompt)}
|
||||
onEdit={() => handleEdit(prompt)}
|
||||
/>
|
||||
|
|
|
|||
45
gui/src/hooks/useBookmarkedSlashCommands.ts
Normal file
45
gui/src/hooks/useBookmarkedSlashCommands.ts
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import { SlashCommandDescription } from "core";
|
||||
import { usePostHog } from "posthog-js/react";
|
||||
import {
|
||||
bookmarkSlashCommand,
|
||||
selectBookmarkedSlashCommands,
|
||||
unbookmarkSlashCommand,
|
||||
} from "../redux";
|
||||
import { useAppDispatch, useAppSelector } from "../redux/hooks";
|
||||
|
||||
export function useBookmarkedSlashCommands() {
|
||||
const dispatch = useAppDispatch();
|
||||
const posthog = usePostHog();
|
||||
const bookmarkedCommands = useAppSelector(selectBookmarkedSlashCommands);
|
||||
|
||||
const isCommandBookmarked = (commandName: string): boolean => {
|
||||
return bookmarkedCommands.includes(commandName);
|
||||
};
|
||||
|
||||
const toggleBookmark = (command: SlashCommandDescription) => {
|
||||
const isBookmarked = isCommandBookmarked(command.name);
|
||||
|
||||
posthog.capture("toggle_bookmarked_slash_command", {
|
||||
isBookmarked,
|
||||
});
|
||||
|
||||
if (isBookmarked) {
|
||||
dispatch(
|
||||
unbookmarkSlashCommand({
|
||||
commandName: command.name,
|
||||
}),
|
||||
);
|
||||
} else {
|
||||
dispatch(
|
||||
bookmarkSlashCommand({
|
||||
commandName: command.name,
|
||||
}),
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
isCommandBookmarked,
|
||||
toggleBookmark,
|
||||
};
|
||||
}
|
||||
|
|
@ -4,7 +4,10 @@ import { IdeMessengerContext } from "../context/IdeMessenger";
|
|||
|
||||
import { ConfigResult } from "@continuedev/config-yaml";
|
||||
import { BrowserSerializedContinueConfig } from "core";
|
||||
import { selectProfileThunk } from "../redux";
|
||||
import {
|
||||
initializeProfilePreferencesThunk,
|
||||
selectProfileThunk,
|
||||
} from "../redux";
|
||||
import { useAppDispatch, useAppSelector } from "../redux/hooks";
|
||||
import {
|
||||
selectDefaultModel,
|
||||
|
|
@ -47,6 +50,10 @@ function useSetup() {
|
|||
dispatch(setConfigResult(configResult));
|
||||
dispatch(selectProfileThunk(profileId));
|
||||
|
||||
if (profileId) {
|
||||
dispatch(initializeProfilePreferencesThunk({ profileId }));
|
||||
}
|
||||
|
||||
// Perform any actions needed with the config
|
||||
if (configResult.config?.ui?.fontSize) {
|
||||
setLocalStorage("fontSize", configResult.config.ui.fontSize);
|
||||
|
|
|
|||
|
|
@ -427,7 +427,7 @@ export function Chat() {
|
|||
className="flex items-center gap-2"
|
||||
>
|
||||
<ArrowLeftIcon className="h-3 w-3" />
|
||||
Last Session
|
||||
<span className="text-xs">Last Session</span>
|
||||
</NewSessionButton>
|
||||
</div>
|
||||
)}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,15 @@
|
|||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
import { SlashCommandDescription } from "core";
|
||||
import { ProfileDescription } from "core/config/ConfigHandler";
|
||||
import { ensureProfilePreferences } from "./utils";
|
||||
|
||||
const DEFAULT_SLASH_COMMANDS_BOOKMARKS_COUNT = 5;
|
||||
|
||||
const INITIAL_PREFERENCES_STATE: PreferencesState = {
|
||||
bookmarkedSlashCommands: [],
|
||||
};
|
||||
|
||||
export interface PreferencesState {
|
||||
bookmarksByName: string[];
|
||||
bookmarkedSlashCommands: string[];
|
||||
}
|
||||
|
||||
export interface ProfilesState {
|
||||
|
|
@ -24,21 +30,42 @@ export const profilesSlice = createSlice({
|
|||
reducers: {
|
||||
setSelectedProfile: (state, { payload }: PayloadAction<string | null>) => {
|
||||
state.selectedProfileId = payload;
|
||||
|
||||
if (payload) {
|
||||
ensureProfilePreferences(state, payload);
|
||||
}
|
||||
},
|
||||
setAvailableProfiles: (
|
||||
state,
|
||||
{ payload }: PayloadAction<ProfileDescription[] | null>,
|
||||
) => {
|
||||
state.availableProfiles = payload;
|
||||
},
|
||||
initializeProfilePreferences: (
|
||||
state,
|
||||
action: PayloadAction<{
|
||||
profileId: string;
|
||||
defaultSlashCommands?: SlashCommandDescription[];
|
||||
}>,
|
||||
) => {
|
||||
const { profileId, defaultSlashCommands = [] } = action.payload;
|
||||
const defaultSlashCommandNames = defaultSlashCommands.map(
|
||||
(cmd) => cmd.name,
|
||||
);
|
||||
|
||||
if (payload) {
|
||||
for (const profile of payload) {
|
||||
ensureProfilePreferences(state, profile.id);
|
||||
}
|
||||
// First ensure all profile preferences are complete to handle
|
||||
// the case where a new preference has been added since last load
|
||||
Object.keys(state.preferencesByProfileId).forEach((pid) => {
|
||||
state.preferencesByProfileId[pid] = {
|
||||
...INITIAL_PREFERENCES_STATE,
|
||||
...state.preferencesByProfileId[pid],
|
||||
};
|
||||
});
|
||||
|
||||
// Then initialize preferences for the new profile if needed
|
||||
if (!state.preferencesByProfileId[profileId]) {
|
||||
state.preferencesByProfileId[profileId] = {
|
||||
bookmarkedSlashCommands: defaultSlashCommandNames.slice(
|
||||
0,
|
||||
DEFAULT_SLASH_COMMANDS_BOOKMARKS_COUNT,
|
||||
),
|
||||
};
|
||||
}
|
||||
},
|
||||
bookmarkSlashCommand: (
|
||||
|
|
@ -46,16 +73,15 @@ export const profilesSlice = createSlice({
|
|||
action: PayloadAction<{ commandName: string }>,
|
||||
) => {
|
||||
const { commandName } = action.payload;
|
||||
const profileId = state.selectedProfileId;
|
||||
const preferences =
|
||||
state.preferencesByProfileId[state.selectedProfileId ?? ""];
|
||||
|
||||
if (!profileId) return;
|
||||
if (!preferences) return;
|
||||
|
||||
const bookmarks = state.preferencesByProfileId[profileId].bookmarksByName;
|
||||
if (!bookmarks.includes(commandName)) {
|
||||
bookmarks.push(commandName);
|
||||
if (!preferences.bookmarkedSlashCommands.includes(commandName)) {
|
||||
preferences.bookmarkedSlashCommands.push(commandName);
|
||||
}
|
||||
},
|
||||
|
||||
unbookmarkSlashCommand: (
|
||||
state,
|
||||
action: PayloadAction<{ commandName: string }>,
|
||||
|
|
@ -66,9 +92,12 @@ export const profilesSlice = createSlice({
|
|||
if (!profileId) return;
|
||||
|
||||
const preferences = state.preferencesByProfileId[profileId];
|
||||
preferences.bookmarksByName = preferences.bookmarksByName.filter(
|
||||
(cmd) => cmd !== commandName,
|
||||
);
|
||||
if (!preferences) return;
|
||||
|
||||
preferences.bookmarkedSlashCommands =
|
||||
preferences.bookmarkedSlashCommands.filter(
|
||||
(cmd) => cmd !== commandName,
|
||||
);
|
||||
},
|
||||
},
|
||||
selectors: {
|
||||
|
|
@ -85,7 +114,7 @@ export const profilesSlice = createSlice({
|
|||
selectBookmarkedSlashCommands: (state) => {
|
||||
if (!state.selectedProfileId) return [];
|
||||
const preferences = state.preferencesByProfileId[state.selectedProfileId];
|
||||
return preferences?.bookmarksByName || [];
|
||||
return preferences?.bookmarkedSlashCommands || [];
|
||||
},
|
||||
|
||||
selectPreferencesByProfileId: (state) => state.preferencesByProfileId,
|
||||
|
|
@ -97,6 +126,7 @@ export const {
|
|||
setSelectedProfile,
|
||||
bookmarkSlashCommand,
|
||||
unbookmarkSlashCommand,
|
||||
initializeProfilePreferences,
|
||||
} = profilesSlice.actions;
|
||||
|
||||
export const {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,12 @@
|
|||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import { ProfileDescription } from "core/config/ConfigHandler";
|
||||
import { isDeprecatedCommandName } from "../../../components/ConversationStarters/utils";
|
||||
import { ThunkApiType } from "../../store";
|
||||
import { setAvailableProfiles, setSelectedProfile } from "./slice";
|
||||
import {
|
||||
initializeProfilePreferences,
|
||||
setAvailableProfiles,
|
||||
setSelectedProfile,
|
||||
} from "./slice";
|
||||
|
||||
export const selectProfileThunk = createAsyncThunk<
|
||||
void,
|
||||
|
|
@ -39,6 +44,7 @@ export const selectProfileThunk = createAsyncThunk<
|
|||
// Only update if there's a change
|
||||
if ((newId ?? null) !== (initialId ?? null)) {
|
||||
dispatch(setSelectedProfile(newId));
|
||||
|
||||
extra.ideMessenger.post("didChangeSelectedProfile", {
|
||||
id: newId,
|
||||
});
|
||||
|
|
@ -83,3 +89,26 @@ export const updateProfilesThunk = createAsyncThunk<
|
|||
// This will trigger reselection if needed
|
||||
dispatch(selectProfileThunk(selectedProfileId));
|
||||
});
|
||||
|
||||
export const initializeProfilePreferencesThunk = createAsyncThunk<
|
||||
void,
|
||||
{ profileId: string },
|
||||
ThunkApiType
|
||||
>(
|
||||
"profiles/initializeProfilePreferences",
|
||||
async (data, { getState, dispatch }) => {
|
||||
const { profileId } = data;
|
||||
const state = getState();
|
||||
|
||||
// Get slash commands from config
|
||||
const defaultSlashCommands =
|
||||
state.config.config.slashCommands.filter(isDeprecatedCommandName) ?? [];
|
||||
|
||||
dispatch(
|
||||
initializeProfilePreferences({
|
||||
defaultSlashCommands,
|
||||
profileId,
|
||||
}),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,12 +0,0 @@
|
|||
import { ProfilesState } from "./slice";
|
||||
|
||||
export function ensureProfilePreferences(
|
||||
state: ProfilesState,
|
||||
profileId: string,
|
||||
) {
|
||||
if (!state.preferencesByProfileId[profileId]) {
|
||||
state.preferencesByProfileId[profileId] = {
|
||||
bookmarksByName: [],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -62,12 +62,8 @@ const saveSubsetFilters = [
|
|||
createFilter("ui", ["toolSettings", "toolGroupSettings"]),
|
||||
createFilter("indexing", []),
|
||||
createFilter("tabs", ["tabs"]),
|
||||
// Add this new filter for the profiles slice
|
||||
createFilter("profiles", [
|
||||
"preferencesByProfileId",
|
||||
"selectedOrganizationId",
|
||||
"selectedProfileId",
|
||||
]),
|
||||
createFilter("organizations", ["selectedOrganizationId"]),
|
||||
createFilter("profiles", ["preferencesByProfileId", "selectedProfileId"]),
|
||||
];
|
||||
|
||||
const migrations: MigrationManifest = {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue