import { CheckIcon, ChevronDownIcon, InformationCircleIcon, } from "@heroicons/react/24/outline"; import { MessageModes } from "core"; import { modelSupportsTools } from "core/llm/autodetect"; import { useCallback, useEffect, useMemo } from "react"; import { useAppDispatch, useAppSelector } from "../../redux/hooks"; import { selectSelectedChatModel } from "../../redux/slices/configSlice"; import { setMode } from "../../redux/slices/sessionSlice"; import { getFontSize, getMetaKeyLabel } from "../../util"; import { ToolTip } from "../gui/Tooltip"; import { useMainEditor } from "../mainInput/TipTapEditor"; import { Listbox, ListboxButton, ListboxOption, ListboxOptions } from "../ui"; import { ModeIcon } from "./ModeIcon"; export function ModeSelect() { const dispatch = useAppDispatch(); const mode = useAppSelector((store) => store.session.mode); const selectedModel = useAppSelector(selectSelectedChatModel); const agentModeSupported = useMemo(() => { return selectedModel && modelSupportsTools(selectedModel); }, [selectedModel]); const { mainEditor } = useMainEditor(); const metaKeyLabel = useMemo(() => { return getMetaKeyLabel(); }, []); // Switch to chat mode if agent mode is selected but not supported useEffect(() => { if (!selectedModel) { return; } if (mode !== "chat" && !agentModeSupported) { dispatch(setMode("chat")); } }, [mode, agentModeSupported, dispatch, selectedModel]); const cycleMode = useCallback(() => { if (mode === "chat") { dispatch(setMode("plan")); } else if (mode === "plan") { dispatch(setMode("agent")); } else { dispatch(setMode("chat")); } // Only focus main editor if another one doesn't already have focus if (!document.activeElement?.classList?.contains("ProseMirror")) { mainEditor?.commands.focus(); } }, [mode, mainEditor]); const selectMode = useCallback( (newMode: MessageModes) => { if (newMode === mode) { return; } dispatch(setMode(newMode)); mainEditor?.commands.focus(); }, [mode, mainEditor], ); useEffect(() => { const handleKeyDown = (e: KeyboardEvent) => { if (e.key === "." && (e.metaKey || e.ctrlKey)) { e.preventDefault(); void cycleMode(); } }; document.addEventListener("keydown", handleKeyDown); return () => document.removeEventListener("keydown", handleKeyDown); }, [cycleMode]); return (
{mode === "chat" ? "Chat" : mode === "agent" ? "Agent" : "Plan"}
Chat All tools disabled {getMetaKeyLabel()}L
{mode === "chat" && }
Plan Read-only/MCP tools available
{agentModeSupported ? ( ) : ( (Not supported) )}
Agent All tools available
{agentModeSupported ? ( ) : ( (Not supported) )}
{`${metaKeyLabel} . for next mode`}
); }