Merge pull request #9 from continuedev/clear
feat: add /clear command to clear chat history
This commit is contained in:
commit
d8e1dd9230
3 changed files with 21 additions and 0 deletions
|
|
@ -14,6 +14,7 @@ export function handleSlashCommands(
|
|||
output?: string;
|
||||
exit?: boolean;
|
||||
newInput?: string;
|
||||
clear?: boolean;
|
||||
} | null {
|
||||
if (input.startsWith("/")) {
|
||||
const [command, ...args] = input.slice(1).split(" ");
|
||||
|
|
@ -22,6 +23,7 @@ export function handleSlashCommands(
|
|||
const helpMessage = [
|
||||
"Available commands:",
|
||||
"/help - Show this help message",
|
||||
"/clear - Clear the chat history",
|
||||
"/exit - Exit the chat",
|
||||
"/login - Authenticate with your account",
|
||||
"/logout - Sign out of your current session",
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ const SlashCommandUI: React.FC<SlashCommandUIProps> = ({
|
|||
const getSlashCommands = (): SlashCommand[] => {
|
||||
const systemCommands: SlashCommand[] = [
|
||||
{ name: "help", description: "Show help message", category: "system" },
|
||||
{ name: "clear", description: "Clear the chat history", category: "system" },
|
||||
{ name: "exit", description: "Exit the chat", category: "system" },
|
||||
{
|
||||
name: "login",
|
||||
|
|
|
|||
|
|
@ -66,6 +66,24 @@ const TUIChat: React.FC<TUIChatProps> = ({
|
|||
return;
|
||||
}
|
||||
|
||||
if (commandResult.clear) {
|
||||
// Clear chat history but keep system message
|
||||
const systemMessage = chatHistory.find(msg => msg.role === "system");
|
||||
const newHistory = systemMessage ? [systemMessage] : [];
|
||||
setChatHistory(newHistory);
|
||||
setMessages([]);
|
||||
|
||||
// Add command output to messages
|
||||
if (commandResult.output) {
|
||||
setMessages([{
|
||||
role: "system",
|
||||
content: commandResult.output!,
|
||||
messageType: "system",
|
||||
}]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Add command output to messages
|
||||
if (commandResult.output) {
|
||||
setMessages((prev) => [
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue