diff --git a/src/commands/commands.ts b/src/commands/commands.ts index 918bb631a..611ba216e 100644 --- a/src/commands/commands.ts +++ b/src/commands/commands.ts @@ -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, })) || [] ); -} +} \ No newline at end of file diff --git a/src/ui/SlashCommandUI.tsx b/src/ui/SlashCommandUI.tsx index ba86ed476..5a720b0df 100644 --- a/src/ui/SlashCommandUI.tsx +++ b/src/ui/SlashCommandUI.tsx @@ -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 = ({ 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 = ({ { 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 = ({ ); }; -export default SlashCommandUI; +export default SlashCommandUI; \ No newline at end of file diff --git a/src/ui/UserInput.tsx b/src/ui/UserInput.tsx index 5f8a6806b..da999681f 100644 --- a/src/ui/UserInput.tsx +++ b/src/ui/UserInput.tsx @@ -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 = ({ }, [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 = ({ ); }; -export default UserInput; +export default UserInput; \ No newline at end of file