feat: better slash command UI
This commit is contained in:
parent
dccb31106a
commit
c62cbdc21e
1 changed files with 35 additions and 38 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
|
import { type AssistantConfig } from "@continuedev/sdk";
|
||||||
import { Box, Text } from "ink";
|
import { Box, Text } from "ink";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { type AssistantConfig } from "@continuedev/sdk";
|
|
||||||
|
|
||||||
interface SlashCommandUIProps {
|
interface SlashCommandUIProps {
|
||||||
assistant: AssistantConfig;
|
assistant: AssistantConfig;
|
||||||
|
|
@ -26,28 +26,43 @@ const SlashCommandUI: React.FC<SlashCommandUIProps> = ({
|
||||||
const systemCommands: SlashCommand[] = [
|
const systemCommands: SlashCommand[] = [
|
||||||
{ name: "help", description: "Show help message", category: "system" },
|
{ name: "help", description: "Show help message", category: "system" },
|
||||||
{ name: "exit", description: "Exit the chat", category: "system" },
|
{ name: "exit", description: "Exit the chat", category: "system" },
|
||||||
{ name: "login", description: "Authenticate with your account", category: "system" },
|
{
|
||||||
{ name: "logout", description: "Sign out of your current session", category: "system" },
|
name: "login",
|
||||||
{ name: "whoami", description: "Check who you're currently logged in as", category: "system" },
|
description: "Authenticate with your account",
|
||||||
{ name: "models", description: "List available AI models", category: "system" },
|
category: "system",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "logout",
|
||||||
|
description: "Sign out of your current session",
|
||||||
|
category: "system",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "whoami",
|
||||||
|
description: "Check who you're currently logged in as",
|
||||||
|
category: "system",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "models",
|
||||||
|
description: "List available AI models",
|
||||||
|
category: "system",
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const assistantCommands: SlashCommand[] = assistant.prompts?.map(
|
const assistantCommands: SlashCommand[] =
|
||||||
(prompt) => ({
|
assistant.prompts?.map((prompt) => ({
|
||||||
name: prompt?.name || "",
|
name: prompt?.name || "",
|
||||||
description: prompt?.description || "",
|
description: prompt?.description || "",
|
||||||
category: "assistant" as const,
|
category: "assistant" as const,
|
||||||
})
|
})) || [];
|
||||||
) || [];
|
|
||||||
|
|
||||||
return [...systemCommands, ...assistantCommands];
|
return [...systemCommands, ...assistantCommands];
|
||||||
};
|
};
|
||||||
|
|
||||||
const allCommands = getSlashCommands();
|
const allCommands = getSlashCommands();
|
||||||
|
|
||||||
// Filter commands based on the current filter
|
// Filter commands based on the current filter
|
||||||
const filteredCommands = allCommands.filter(
|
const filteredCommands = allCommands.filter((cmd) =>
|
||||||
(cmd) => cmd.name.toLowerCase().includes(filter.toLowerCase())
|
cmd.name.toLowerCase().includes(filter.toLowerCase())
|
||||||
);
|
);
|
||||||
|
|
||||||
if (filteredCommands.length === 0) {
|
if (filteredCommands.length === 0) {
|
||||||
|
|
@ -65,39 +80,21 @@ const SlashCommandUI: React.FC<SlashCommandUIProps> = ({
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box paddingX={1} marginX={1} marginBottom={1} flexDirection="column">
|
||||||
borderStyle="round"
|
|
||||||
borderColor="gray"
|
|
||||||
paddingX={1}
|
|
||||||
marginX={1}
|
|
||||||
marginBottom={1}
|
|
||||||
flexDirection="column"
|
|
||||||
>
|
|
||||||
<Box marginBottom={1}>
|
|
||||||
<Text color="gray" bold>
|
|
||||||
Slash Commands
|
|
||||||
</Text>
|
|
||||||
</Box>
|
|
||||||
|
|
||||||
{filteredCommands.map((command, index) => {
|
{filteredCommands.map((command, index) => {
|
||||||
const isSelected = index === selectedIndex;
|
const isSelected = index === selectedIndex;
|
||||||
const categoryColor = command.category === "system" ? "cyan" : "yellow";
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box key={command.name} marginBottom={index === filteredCommands.length - 1 ? 0 : 1}>
|
<Box key={command.name}>
|
||||||
<Text
|
<Text color="white" bold={isSelected}>
|
||||||
color={isSelected ? "black" : "white"}
|
{" "}
|
||||||
backgroundColor={isSelected ? "white" : undefined}
|
<Text color="green">/{command.name}</Text>
|
||||||
bold={isSelected}
|
|
||||||
>
|
|
||||||
{isSelected ? "▶ " : " "}
|
|
||||||
<Text color={categoryColor}>/{command.name}</Text>
|
|
||||||
<Text color="gray"> - {command.description}</Text>
|
<Text color="gray"> - {command.description}</Text>
|
||||||
</Text>
|
</Text>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|
||||||
<Box marginTop={1}>
|
<Box marginTop={1}>
|
||||||
<Text color="gray" dimColor>
|
<Text color="gray" dimColor>
|
||||||
Use ↑/↓ to navigate, Enter to select, Tab to complete
|
Use ↑/↓ to navigate, Enter to select, Tab to complete
|
||||||
|
|
@ -107,4 +104,4 @@ const SlashCommandUI: React.FC<SlashCommandUIProps> = ({
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default SlashCommandUI;
|
export default SlashCommandUI;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue