refactor REMOTE_SLASH_COMMANDS

This commit is contained in:
Nate 2025-07-21 13:47:21 -07:00
parent e1668ad053
commit 2c106fc7c8
3 changed files with 54 additions and 47 deletions

View file

@ -56,17 +56,40 @@ export const SYSTEM_SLASH_COMMANDS: SystemCommand[] = [
},
];
// Remote mode specific commands
export const REMOTE_MODE_SLASH_COMMANDS: SlashCommand[] = [
{
name: "exit",
description: "Exit the remote environment",
category: "system",
},
];
/**
* Get all available slash commands including system commands and assistant prompts
*/
export function getAllSlashCommands(
assistant: AssistantConfig
assistant: AssistantConfig,
options: { isRemoteMode?: boolean; hasMultipleOrgs?: boolean } = {}
): SlashCommand[] {
const { isRemoteMode = false, hasMultipleOrgs = false } = options;
// In remote mode, only show the exit command
if (isRemoteMode) {
return REMOTE_MODE_SLASH_COMMANDS;
}
// Filter system commands based on requirements
const systemCommands = SYSTEM_SLASH_COMMANDS;
const systemCommands = SYSTEM_SLASH_COMMANDS.filter((cmd) => {
if (cmd.requiresMultipleOrgs && !hasMultipleOrgs) {
return false;
}
return true;
});
// Get assistant prompt commands
const assistantCommands: SlashCommand[] =
assistant.prompts?.map((prompt) => ({
assistant?.prompts?.map((prompt) => ({
name: prompt?.name || "",
description: prompt?.description || "",
category: "assistant" as const,
@ -82,10 +105,10 @@ export function getAssistantSlashCommands(
assistant: AssistantConfig
): SlashCommand[] {
return (
assistant.prompts?.map((prompt) => ({
assistant?.prompts?.map((prompt) => ({
name: prompt?.name || "",
description: prompt?.description || "",
category: "assistant" as const,
})) || []
);
}
}

View file

@ -1,8 +1,9 @@
import { type AssistantConfig } from "@continuedev/sdk";
import { Box, Text } from "ink";
import React, { useMemo } from "react";
import React, { useEffect, useMemo, useState } from "react";
import { getAllSlashCommands } from "../commands/commands.js";
import { hasMultipleOrganizations } from "../auth/workos.js";
interface SlashCommandUIProps {
assistant?: AssistantConfig;
@ -17,16 +18,21 @@ const SlashCommandUI: React.FC<SlashCommandUIProps> = ({
selectedIndex,
isRemoteMode = false,
}) => {
const [hasMultipleOrgs, setHasMultipleOrgs] = useState(false);
useEffect(() => {
if (!isRemoteMode) {
hasMultipleOrganizations().then(setHasMultipleOrgs);
}
}, [isRemoteMode]);
// Memoize the slash commands to prevent excessive re-renders
const allCommands = useMemo(() => {
// In remote mode, only show the exit command
if (isRemoteMode) {
return [{ name: "exit", description: "Exit the remote environment" }];
}
// In local mode, use the assistant's commands
if (assistant) {
return getAllSlashCommands(assistant);
if (assistant || isRemoteMode) {
return getAllSlashCommands(assistant || ({} as AssistantConfig), {
isRemoteMode,
hasMultipleOrgs,
});
}
// Fallback - basic commands without assistant
@ -35,7 +41,7 @@ const SlashCommandUI: React.FC<SlashCommandUIProps> = ({
{ name: "clear", description: "Clear the chat history" },
{ name: "exit", description: "Exit the chat" },
];
}, [isRemoteMode, assistant?.prompts]);
}, [isRemoteMode, assistant?.prompts, hasMultipleOrgs]);
// Filter commands based on the current filter
const filteredCommands = allCommands
@ -82,4 +88,4 @@ const SlashCommandUI: React.FC<SlashCommandUIProps> = ({
);
};
export default SlashCommandUI;
export default SlashCommandUI;

View file

@ -2,6 +2,7 @@ import { type AssistantConfig } from "@continuedev/sdk";
import { Box, Text, useApp, useInput } from "ink";
import React, { useEffect, useState } from "react";
import { hasMultipleOrganizations } from "../auth/workos.js";
import { getAllSlashCommands } from "../commands/commands.js";
import { InputHistory } from "../util/inputHistory.js";
import FileSearchUI from "./FileSearchUI.js";
import SlashCommandUI from "./SlashCommandUI.js";
@ -57,42 +58,19 @@ const UserInput: React.FC<UserInputProps> = ({
}, [isRemoteMode]);
const getSlashCommands = () => {
// In remote mode, only show the exit command
if (isRemoteMode) {
return [{ name: "exit", description: "Exit the remote environment" }];
if (assistant || isRemoteMode) {
return getAllSlashCommands(assistant || ({} as AssistantConfig), {
isRemoteMode,
hasMultipleOrgs,
});
}
const systemCommands = [
// Fallback - basic commands without assistant
return [
{ name: "help", description: "Show help message" },
{ name: "clear", description: "Clear the chat history" },
{ name: "exit", description: "Exit the chat" },
{ name: "login", description: "Authenticate with your account" },
{ name: "logout", description: "Sign out of your current session" },
{
name: "whoami",
description: "Check who you're currently logged in as",
},
{
name: "config",
description: "Switch configuration",
},
...(hasMultipleOrgs
? [
{
name: "org",
description: "Switch organization",
},
]
: []),
];
const assistantCommands =
assistant?.prompts?.map((prompt) => ({
name: prompt?.name || "",
description: prompt?.description || "",
})) || [];
return [...systemCommands, ...assistantCommands];
};
// Update slash command UI state based on input
@ -550,4 +528,4 @@ const UserInput: React.FC<UserInputProps> = ({
);
};
export default UserInput;
export default UserInput;