Merge pull request #5718 from uinstinct/prompt-slug

feat: open prompt file or slug on edit click
This commit is contained in:
Dallin Romney 2025-05-19 12:59:33 -07:00 • committed by GitHub
commit 6fdd5375c6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 57 additions and 13 deletions

1
core/index.d.ts vendored
View file

@ -842,6 +842,7 @@ export interface SlashCommand {
description: string;
prompt?: string;
params?: { [key: string]: any };
promptFile?: string
run: (sdk: ContinueSDK) => AsyncGenerator<string | undefined>;
}

View file

@ -63,6 +63,7 @@ export function slashCommandFromPromptFileV1(
name,
description,
prompt,
promptFile: path,
run: async function* (context) {
const userInput = extractUserInput(context.input, name);
const [_, renderedPrompt] = await renderPromptFileV2(prompt, {

View file

@ -1,10 +1,12 @@
import { parseConfigYaml } from "@continuedev/config-yaml";
import {
BookmarkIcon as BookmarkOutline,
PencilIcon,
} from "@heroicons/react/24/outline";
import { BookmarkIcon as BookmarkSolid } from "@heroicons/react/24/solid";
import { SlashCommandDescription } from "core";
import { useContext } from "react";
import { useContext, useMemo } from "react";
import { useAuth } from "../../../../context/Auth";
import { IdeMessengerContext } from "../../../../context/IdeMessenger";
import { useBookmarkedSlashCommands } from "../../../../hooks/useBookmarkedSlashCommands";
import { useAppSelector } from "../../../../redux/hooks";
@ -13,8 +15,10 @@ import { useMainEditor } from "../../TipTapEditor";
import { useLump } from "../LumpContext";
import { ExploreBlocksButton } from "./ExploreBlocksButton";
type PromptWithSlug = SlashCommandDescription & { slug?: string };
interface PromptRowProps {
prompt: SlashCommandDescription;
prompt: PromptWithSlug;
isBookmarked: boolean;
setIsBookmarked: (isBookmarked: boolean) => void;
onEdit?: () => void;
@ -90,6 +94,7 @@ function PromptRow({
* Section that displays all available prompts with bookmarking functionality
*/
export function PromptsSection() {
const { selectedProfile } = useAuth();
const { isCommandBookmarked, toggleBookmark } = useBookmarkedSlashCommands();
const ideMessenger = useContext(IdeMessengerContext);
@ -97,19 +102,56 @@ export function PromptsSection() {
(state) => state.config.config.slashCommands ?? [],
);
const handleEdit = (_prompt: SlashCommandDescription) => {
ideMessenger.post("config/openProfile", {
profileId: undefined,
});
const handleEdit = (prompt: PromptWithSlug) => {
if (prompt.promptFile) {
ideMessenger.post("openFile", {
path: prompt.promptFile,
});
} else if (prompt.slug) {
void ideMessenger.request("controlPlane/openUrl", {
path: `${prompt.slug}/new-version`,
orgSlug: undefined,
});
} else {
ideMessenger.post("config/openProfile", {
profileId: undefined,
});
}
};
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;
});
const sortedCommands = useMemo(() => {
const promptsWithSlug: PromptWithSlug[] = structuredClone(slashCommands);
// get the slugs from rawYaml
if (selectedProfile?.rawYaml) {
const parsed = parseConfigYaml(selectedProfile.rawYaml);
const parsedPrompts = parsed.prompts ?? [];
let index = 0;
for (const prompt of promptsWithSlug) {
// skip for local prompt files
if (prompt.promptFile) continue;
const yamlPrompt = parsedPrompts[index];
if (yamlPrompt) {
if ("uses" in yamlPrompt) {
prompt.slug = yamlPrompt.uses;
} else {
prompt.slug =
`${selectedProfile?.fullSlug.ownerSlug}/${selectedProfile?.fullSlug.packageSlug}`;
}
}
index = index + 1;
}
}
return promptsWithSlug.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;
});
}, [slashCommands, isCommandBookmarked, selectedProfile]);
return (
<div className="flex flex-col">