DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.
Python ai-agentsai-tutorclawbotcli-tooldeepresearchinteractive-learninglearningmulti-agent-systemsrag
feat(chat): pick the conversation's reply language with /language
Bingxi Zhao (Frank)28f335c50de5
diff --git a/web/components/chat/home/ChatComposer.tsx b/web/components/chat/home/ChatComposer.tsxindex 10825911f..20d67d3e0 100644--- a/web/components/chat/home/ChatComposer.tsx+++ b/web/components/chat/home/ChatComposer.tsx@@ -257,6 +257,11 @@ export default memo(function ChatComposer({onPersonaSelectionChange,personaSelectorOpen,onPersonaSelectorOpenChange,+ replyLanguageOverride,+ replyLanguageOptions,+ replyLanguageDefaultLabel,+ replyLanguageDisabled,+ onReplyLanguageChange,resourceCatalog,resourceSelection,onResourceSelectionChange,@@ -384,13 +389,19 @@ export default memo(function ChatComposer({/*** Session-persona wiring (main chat only). When `onPersonaSelectionChange`* is provided, the toolbar shows a PersonaSelector chip and the composer- * accepts the `/persona` slash command. The quiz follow-up surface omits- * these and keeps its per-turn persona picker flow.+ * accepts `/persona`. The quiz follow-up surface omits these and keeps its+ * per-turn persona picker flow.*/personaSelection?: string;onPersonaSelectionChange?: (persona: string) => void;personaSelectorOpen?: boolean;onPersonaSelectorOpenChange?: (open: boolean) => void;+ /** Main chat's session-level reply language, selected via /language. */+ replyLanguageOverride?: string | null;+ replyLanguageOptions?: readonly { value: string; label: string }[];+ replyLanguageDefaultLabel?: string;+ replyLanguageDisabled?: boolean;+ onReplyLanguageChange?: (value: string) => void;/*** Skill / MCP narrowing for this conversation. Supplied together: the* catalog is what may be picked (already clipped to what the workspace@@ -1042,6 +1053,12 @@ export default memo(function ChatComposer({? () => onPersonaSelectorOpenChange(true): undefined}+ replyLanguageOverride={replyLanguageOverride}+ replyLanguageOptions={replyLanguageOptions}+ replyLanguageDefaultLabel={replyLanguageDefaultLabel}+ replyLanguageDisabled={replyLanguageDisabled}+ onReplyLanguageChange={onReplyLanguageChange}+ languagePickerBelow={!hasMessages}placeholder={inputPlaceholder}placeholderCompletion={inputPlaceholderCompletion}minHeight={hasMessages ? 28 : 64}diff --git a/web/components/chat/home/ComposerInput.tsx b/web/components/chat/home/ComposerInput.tsxindex cf1838995..e47d602d7 100644--- a/web/components/chat/home/ComposerInput.tsx+++ b/web/components/chat/home/ComposerInput.tsx@@ -5,6 +5,7 @@ import {memo,useCallback,useEffect,+ useId,useImperativeHandle,useMemo,useRef,@@ -12,7 +13,7 @@ import {type RefObject,} from "react";import { useTranslation } from "react-i18next";-import { Bot, Check, UserRound } from "lucide-react";+import { Bot, Check, Languages, UserRound } from "lucide-react";import ChatSpaceMenu, {type ChatSpaceSelectionCounts,} from "@/components/chat/space/ChatSpaceMenu";@@ -62,13 +63,17 @@ interface ComposerInputProps {onSelectPersonaPicker: () => void;onSelectMemoryPicker: () => void;/**- * Wires the `/persona` slash command. Typing "/" (then any prefix of- * "persona") at the start of an empty composer pops a command hint;- * selecting it clears the input and invokes this callback to open the- * session persona selector. Omitted on surfaces without session- * personas (e.g. the quiz follow-up), which disables the slash popup.+ * Opens the session persona selector from `/persona`. Surfaces without+ * session personas (e.g. quiz follow-up) omit this command.*/onOpenPersonaSelector?: () => void;+ /** Current conversation's reply-language choice. Null follows the account default. */+ replyLanguageOverride?: string | null;+ replyLanguageOptions?: readonly { value: string; label: string }[];+ replyLanguageDefaultLabel?: string;+ replyLanguageDisabled?: boolean;+ onReplyLanguageChange?: (value: string) => void;+ languagePickerBelow?: boolean;/*** Override the default placeholder. When unset, falls back to the* main chat ("How can I help you today?") / visualize defaults.@@ -119,20 +124,25 @@ export function atMentionQuery(value: string, cursorPos: number): string {return match ? match[2] : "";}-/**- * `/persona` slash-command detection (Codex-style: command position is the- * very start of the input, not mid-text like @ mentions). Active while the- * text before the cursor is "/" plus any prefix of "persona" — `/x` or a- * trailing space closes the popup.- */+type SlashCommand = "persona" | "language";++/** Slash commands only match at the start of the composer. */+export function matchingSlashCommands(+ value: string,+ cursorPos: number,+ enabled: readonly SlashCommand[] = ["persona", "language"],+): SlashCommand[] {+ const match = /^\/([a-z]*)$/i.exec(value.slice(0, cursorPos));+ if (!match) return [];+ const query = match[1].toLowerCase();+ return enabled.filter((command) => command.startsWith(query));+}+export function shouldOpenSlashPopup(value: string,cursorPos: number,): boolean {- const prefix = value.slice(0, cursorPos);- const match = /^\/([a-z]*)$/i.exec(prefix);- if (!match) return false;- return "persona".startsWith(match[1].toLowerCase());+ return matchingSlashCommands(value, cursorPos).length > 0;}export const ComposerInput = memo(@@ -163,6 +173,12 @@ export const ComposerInput = memo(onSelectPersonaPicker,onSelectMemoryPicker,onOpenPersonaSelector,+ replyLanguageOverride = null,+ replyLanguageOptions = [],+ replyLanguageDefaultLabel = "English",+ replyLanguageDisabled = false,+ onReplyLanguageChange,+ languagePickerBelow = false,placeholder,placeholderCompletion,minHeight = 28,@@ -173,8 +189,24 @@ export const ComposerInput = memo(const [input, setInput] = useState("");const [showAtPopup, setShowAtPopup] = useState(false);const [showSlashPopup, setShowSlashPopup] = useState(false);+ const [slashCommands, setSlashCommands] = useState<SlashCommand[]>([]);+ const [activeSlashIndex, setActiveSlashIndex] = useState(0);+ const [showLanguagePopup, setShowLanguagePopup] = useState(false);+ const [activeLanguageIndex, setActiveLanguageIndex] = useState(0);const [atQuery, setAtQuery] = useState("");- const slashEnabled = Boolean(onOpenPersonaSelector);+ const slashListId = useId();+ const languageListId = useId();+ const availableSlashCommands = useMemo<SlashCommand[]>(() => [+ ...(onOpenPersonaSelector ? ["persona" as const] : []),+ ...(onReplyLanguageChange && !replyLanguageDisabled ? ["language" as const] : []),+ ], [onOpenPersonaSelector, onReplyLanguageChange, replyLanguageDisabled]);+ const languageChoices = useMemo(() => [+ {+ value: "",+ label: `${t("Account default")} (${replyLanguageDefaultLabel})`,+ },+ ...replyLanguageOptions,+ ], [replyLanguageDefaultLabel, replyLanguageOptions, t]);// Main chat passes ``onSelectAgent`` → ``@`` picks a connected agent. Other// surfaces (quiz follow-up) omit it and keep the @ Space menu.const agentMentionMode = Boolean(onSelectAgent);@@ -230,6 +262,14 @@ export const ComposerInput = memo(useAutoSizedTextarea(textareaRef, input, { min: minHeight, max: 200 });+ const updateSlashPopup = useCallback((value: string, cursorPos: number) => {+ const matches = matchingSlashCommands(value, cursorPos, availableSlashCommands);+ setSlashCommands(matches);+ setActiveSlashIndex(0);+ setShowSlashPopup(matches.length > 0);+ setShowLanguagePopup(false);+ }, [availableSlashCommands]);+const handleInputChange = useCallback((e: React.ChangeEvent<HTMLTextAreaElement>) => {const value = e.target.value;@@ -239,11 +279,9 @@ export const ComposerInput = memo(const atOpen = shouldOpenAtPopup(value, cursorPos);setShowAtPopup(atOpen);setAtQuery(atOpen ? atMentionQuery(value, cursorPos) : "");- setShowSlashPopup(- slashEnabled && shouldOpenSlashPopup(value, cursorPos),- );+ updateSlashPopup(value, cursorPos);},- [setInputBoth, onInputChange, slashEnabled],+ [setInputBoth, onInputChange, updateSlashPopup],);const handleTextareaClick = useCallback(@@ -253,20 +291,34 @@ export const ComposerInput = memo(const atOpen = shouldOpenAtPopup(target.value, cursorPos);setShowAtPopup(atOpen);setAtQuery(atOpen ? atMentionQuery(target.value, cursorPos) : "");- setShowSlashPopup(- slashEnabled && shouldOpenSlashPopup(target.value, cursorPos),- );+ updateSlashPopup(target.value, cursorPos);},- [slashEnabled],+ [updateSlashPopup],);- const handleSelectSlashPersona = useCallback(() => {- // The slash text is a command, not message content — clear it.+ const handleSelectSlashCommand = useCallback((command: SlashCommand) => {+ // Command text is never part of the message sent to the model.setInputBoth("");onInputChange("");setShowSlashPopup(false);- onOpenPersonaSelector?.();- }, [setInputBoth, onInputChange, onOpenPersonaSelector]);+ setSlashCommands([]);+ if (command === "persona") {+ onOpenPersonaSelector?.();+ return;+ }+ const selectedIndex = languageChoices.findIndex(+ (choice) => choice.value === (replyLanguageOverride ?? ""),+ );+ setActiveLanguageIndex(Math.max(0, selectedIndex));+ setShowLanguagePopup(true);+ textareaRef.current?.focus();+ }, [setInputBoth, onInputChange, onOpenPersonaSelector, languageChoices, replyLanguageOverride, textareaRef]);++ const handleSelectReplyLanguage = useCallback((value: string) => {+ setShowLanguagePopup(false);+ onReplyLanguageChange?.(value);+ textareaRef.current?.focus();+ }, [onReplyLanguageChange, textareaRef]);const doSend = useCallback(() => {const content = inputRef.current.trim();@@ -279,6 +331,7 @@ export const ComposerInput = memo(onInputChange("");setShowAtPopup(false);setShowSlashPopup(false);+ setShowLanguagePopup(false);}, [canSendEmpty, onSend, setInputBoth, onInputChange]);const clearTrailingMention = useCallback(() => {@@ -299,16 +352,44 @@ export const ComposerInput = memo(const handleKeyDown = useCallback((e: React.KeyboardEvent<HTMLTextAreaElement>) => {- // With the slash popup open, Enter/Tab confirm the command instead- // of submitting "/persona" as a message.- if (- showSlashPopup &&- !isComposingRef.current &&- (e.key === "Enter" || e.key === "Tab")- ) {- e.preventDefault();- handleSelectSlashPersona();- return;+ if (showLanguagePopup && !isComposingRef.current) {+ if (e.key === "ArrowDown" || e.key === "ArrowUp") {+ e.preventDefault();+ setActiveLanguageIndex((index) =>+ (index + (e.key === "ArrowDown" ? 1 : -1) + languageChoices.length) % languageChoices.length,+ );+ return;+ }+ if (e.key === "Enter" || e.key === "Tab") {+ e.preventDefault();+ handleSelectReplyLanguage(languageChoices[activeLanguageIndex]?.value ?? "");+ return;+ }+ if (e.key === "Escape") {+ e.preventDefault();+ setShowLanguagePopup(false);+ return;+ }+ }+ if (showSlashPopup && !isComposingRef.current) {+ if (e.key === "ArrowDown" || e.key === "ArrowUp") {+ e.preventDefault();+ setActiveSlashIndex((index) =>+ (index + (e.key === "ArrowDown" ? 1 : -1) + slashCommands.length) % slashCommands.length,+ );+ return;+ }+ if (e.key === "Enter" || e.key === "Tab") {+ e.preventDefault();+ const command = slashCommands[activeSlashIndex];+ if (command) handleSelectSlashCommand(command);+ return;+ }+ if (e.key === "Escape") {+ e.preventDefault();+ setShowSlashPopup(false);+ return;+ }}// With the agent-mention popup open, Enter/Tab confirm the first match.if (@@ -341,13 +422,20 @@ export const ComposerInput = memo(} else if (e.key === "Escape") {setShowAtPopup(false);setShowSlashPopup(false);+ setShowLanguagePopup(false);}},[doSend,isStreaming,showSlashPopup,- handleSelectSlashPersona,+ slashCommands,+ activeSlashIndex,+ handleSelectSlashCommand,+ showLanguagePopup,+ languageChoices,+ activeLanguageIndex,+ handleSelectReplyLanguage,showAtPopup,agentMentionMode,filteredAgents,@@ -408,20 +496,31 @@ export const ComposerInput = memo(// re-open something else.const popupRef = useRef<HTMLDivElement>(null);const slashPopupRef = useRef<HTMLDivElement>(null);+ const languagePopupRef = useRef<HTMLDivElement>(null);+ const languageListRef = useRef<HTMLDivElement>(null);+ useEffect(() => {+ if (!showLanguagePopup) return;+ const option = languageListRef.current?.children[activeLanguageIndex];+ if (option && "scrollIntoView" in option) {+ option.scrollIntoView({ block: "nearest" });+ }+ }, [showLanguagePopup, activeLanguageIndex]);useEffect(() => {- if (!showAtPopup && !showSlashPopup) return;+ if (!showAtPopup && !showSlashPopup && !showLanguagePopup) return;const handler = (e: MouseEvent) => {const target = e.target as Node | null;if (!target) return;if (popupRef.current?.contains(target)) return;if (slashPopupRef.current?.contains(target)) return;+ if (languagePopupRef.current?.contains(target)) return;if (textareaRef.current?.contains(target)) return;setShowAtPopup(false);setShowSlashPopup(false);+ setShowLanguagePopup(false);};document.addEventListener("mousedown", handler);return () => document.removeEventListener("mousedown", handler);- }, [showAtPopup, showSlashPopup, textareaRef]);+ }, [showAtPopup, showSlashPopup, showLanguagePopup, textareaRef]);const basePlaceholder =placeholder ??@@ -521,31 +620,90 @@ export const ComposerInput = memo(className="absolute bottom-full left-0 z-[70] mb-2"><div+ id={slashListId}role="listbox"aria-label={t("Commands")}className="w-[300px] rounded-xl border border-[var(--border)] bg-[var(--popover)] py-1.5 shadow-lg backdrop-blur-md">- <button- type="button"- role="option"- aria-selected- onClick={handleSelectSlashPersona}- className="flex w-full items-center gap-2.5 bg-[var(--muted)]/60 px-3 py-2 text-left text-[12.5px] transition-colors"- >- <UserRound- size={14}- strokeWidth={1.7}- className="shrink-0 text-[var(--muted-foreground)]"- />- {/* Command syntax token — must not be localized. */}- {/* eslint-disable-next-line i18n/no-literal-ui-text */}- <span className="font-medium text-[var(--foreground)]">- /persona- </span>- <span className="min-w-0 truncate text-[var(--muted-foreground)]">- {t("Switch the persona for this chat session")}- </span>- </button>+ {slashCommands.map((command, index) => {+ const Icon = command === "persona" ? UserRound : Languages;+ return (+ <button+ key={command}+ id={`${slashListId}-option-${index}`}+ type="button"+ role="option"+ aria-selected={index === activeSlashIndex}+ onMouseEnter={() => setActiveSlashIndex(index)}+ onClick={() => handleSelectSlashCommand(command)}+ className={`flex w-full items-center gap-2.5 px-3 py-2 text-left text-[12.5px] transition-colors ${+ index === activeSlashIndex+ ? "bg-[var(--muted)]/60"+ : "hover:bg-[var(--muted)]/45"+ }`}+ >+ <Icon+ size={14}+ strokeWidth={1.7}+ className="shrink-0 text-[var(--muted-foreground)]"+ />+ {/* Command syntax tokens must not be localized. */}+ <span className="font-medium text-[var(--foreground)]">+ {command === "persona" ? "/persona" : "/language"}+ </span>+ <span className="min-w-0 truncate text-[var(--muted-foreground)]">+ {command === "persona"+ ? t("Switch the persona for this chat session")+ : t("Switch the reply language for this chat session")}+ </span>+ </button>+ );+ })}+ </div>+ </div>+ )}+ {showLanguagePopup && (+ <div+ ref={languagePopupRef}+ className={`absolute left-0 z-[70] ${+ languagePickerBelow ? "top-full mt-2" : "bottom-full mb-2"+ }`}+ >+ <div+ id={languageListId}+ role="listbox"+ aria-label={t("Reply language")}+ className="w-[300px] overflow-hidden rounded-xl border border-[var(--border)] bg-[var(--popover)] py-1.5 shadow-lg backdrop-blur-md"+ >+ <div className="px-3 pb-1 pt-1 text-[11px] font-medium uppercase tracking-[0.05em] text-[var(--muted-foreground)]">+ {t("Reply language")}+ </div>+ <div ref={languageListRef} className="max-h-[280px] overflow-y-auto">+ {languageChoices.map((choice, index) => {+ const selected = choice.value === (replyLanguageOverride ?? "");+ return (+ <button+ key={choice.value}+ id={`${languageListId}-option-${index}`}+ type="button"+ role="option"+ aria-selected={selected}+ onMouseEnter={() => setActiveLanguageIndex(index)}+ onClick={() => handleSelectReplyLanguage(choice.value)}+ className={`flex w-full items-center gap-2.5 px-3 py-1.5 text-left text-[12.5px] transition-colors ${+ index === activeLanguageIndex+ ? "bg-[var(--muted)]/60"+ : "hover:bg-[var(--muted)]/45"+ } ${index === 1 ? "border-t border-[var(--border)]" : ""}`}+ >+ <span className="min-w-0 flex-1 truncate text-[var(--foreground)]">+ {choice.label}+ </span>+ {selected && <Check size={14} strokeWidth={2} className="shrink-0 text-[var(--primary)]" />}+ </button>+ );+ })}+ </div></div></div>)}@@ -568,6 +726,13 @@ export const ComposerInput = memo(maxLength={32000}suppressHydrationWarningplaceholder={placeholderCompletion ? "" : basePlaceholder}+ aria-haspopup={showSlashPopup || showLanguagePopup ? "listbox" : undefined}+ aria-controls={showSlashPopup ? slashListId : showLanguagePopup ? languageListId : undefined}+ aria-activedescendant={showSlashPopup+ ? `${slashListId}-option-${activeSlashIndex}`+ : showLanguagePopup+ ? `${languageListId}-option-${activeLanguageIndex}`+ : undefined}// The overlay below replaces the native placeholder visually// (so a long hint can truncate instead of wrapping), but an// empty placeholder would otherwise leave the field with nodiff --git a/web/features/chat/components/ChatWorkspace.tsx b/web/features/chat/components/ChatWorkspace.tsxindex 8b7faef0a..7f6a9b3e8 100644--- a/web/features/chat/components/ChatWorkspace.tsx+++ b/web/features/chat/components/ChatWorkspace.tsx@@ -2506,27 +2506,6 @@ export default function ChatWorkspace({</span>) : null}</div>- <label className="flex shrink-0 items-center gap-1.5 text-[11px] text-[var(--muted-foreground)]">- <span className="hidden sm:inline">{t("Reply language")}</span>- <select- aria-label={t("Reply language")}- value={state.replyLanguageOverride ?? ""}- onChange={(event) => handleReplyLanguageChange(event.target.value)}- disabled={replyLanguageSavingKey === state.sessionKey || state.isStreaming}- className="max-w-[170px] rounded-lg border border-[var(--border)] bg-[var(--background)] px-2 py-1 text-[11px] text-[var(--foreground)] outline-none focus-visible:ring-2 focus-visible:ring-[var(--ring)] disabled:opacity-50"- >- <option value="">- {t("Account default")} ({RESPONSE_LANGUAGE_OPTIONS.find(- (option) => option.value === readStoredResponseLanguage(),- )?.label ?? "English"})- </option>- {RESPONSE_LANGUAGE_OPTIONS.map((option) => (- <option key={option.value} value={option.value}>- {option.label}- </option>- ))}- </select>- </label><div className="flex shrink-0 items-center gap-0.5"><HeaderActionButtononClick={() => setShowSaveModal(true)}@@ -2790,6 +2769,13 @@ export default function ChatWorkspace({onPersonaSelectionChange={setPersonaSelection}personaSelectorOpen={personaSelectorOpen}onPersonaSelectorOpenChange={setPersonaSelectorOpen}+ replyLanguageOverride={state.replyLanguageOverride}+ replyLanguageOptions={RESPONSE_LANGUAGE_OPTIONS}+ replyLanguageDefaultLabel={RESPONSE_LANGUAGE_OPTIONS.find(+ (option) => option.value === readStoredResponseLanguage(),+ )?.label ?? "English"}+ replyLanguageDisabled={replyLanguageSavingKey === state.sessionKey || state.isStreaming}+ onReplyLanguageChange={handleReplyLanguageChange}resourceCatalog={resourceCatalog}resourceSelection={state.resourceSelection}onResourceSelectionChange={setResourceSelection}diff --git a/web/locales/en/app.json b/web/locales/en/app.jsonindex 36c1b8ba2..c41c1e7a3 100644--- a/web/locales/en/app.json+++ b/web/locales/en/app.json@@ -4929,6 +4929,7 @@"Stop recording": "Stop recording","Commands": "Commands","Switch the persona for this chat session": "Switch the persona for this chat session",+ "Switch the reply language for this chat session": "Switch the reply language for this chat session","Search personas...": "Search personas...","No persona — the assistant's standard behavior": "No persona — the assistant's standard behavior","Preset": "Preset",diff --git a/web/locales/fr/app.json b/web/locales/fr/app.jsonindex dbf216eb4..2ccfb6d7f 100644--- a/web/locales/fr/app.json+++ b/web/locales/fr/app.json@@ -2491,6 +2491,7 @@"Identity": "Identité","e.g. Ada": "ex. Ada","Reply language": "Langue de réponse",+ "Switch the reply language for this chat session": "Changer la langue des réponses pour cette conversation","Auto (English)": "Auto (anglais)","What is this partner for?": "À quoi sert ce partenaire ?","Face": "Visage",@@ -4403,6 +4404,8 @@"No matching materials or contents.": "Aucun support ni contenu correspondant.","Fullscreen learning": "Apprentissage en plein écran","Exit learning mode": "Quitter le mode apprentissage",+ "Chat history": "Historique des conversations",+ "Question bank": "Banque de questions","Working on it…": "En cours…","Ask a follow-up": "Poser une question de suivi","Reading tools": "Outils de lecture",diff --git a/web/locales/uk/app.json b/web/locales/uk/app.jsonindex 4666eec6c..9b0abd769 100644--- a/web/locales/uk/app.json+++ b/web/locales/uk/app.json@@ -4946,6 +4946,7 @@"Stop recording": "Зупинити запис","Commands": "Команди","Switch the persona for this chat session": "Змінити персону для цього сеансу чату",+ "Switch the reply language for this chat session": "Змінити мову відповіді для цього чату","Search personas...": "Пошук персон...","No persona — the assistant's standard behavior": "Без персони — стандартна поведінка помічника","Preset": "Попереднє налаштування",diff --git a/web/locales/zh/app.json b/web/locales/zh/app.jsonindex 60ce317f2..ef141ea3d 100644--- a/web/locales/zh/app.json+++ b/web/locales/zh/app.json@@ -4929,6 +4929,7 @@"Stop recording": "停止录音","Commands": "命令","Switch the persona for this chat session": "切换当前对话的人格",+ "Switch the reply language for this chat session": "切换当前对话的回复语言","Search personas...": "搜索人格…","No persona — the assistant's standard behavior": "不使用人格 — 使用助手的默认行为","Preset": "预设",diff --git a/web/tests/composer-language-command.spec.tsx b/web/tests/composer-language-command.spec.tsxnew file mode 100644index 000000000..46c0f1709--- /dev/null+++ b/web/tests/composer-language-command.spec.tsx@@ -0,0 +1,162 @@+import { createRef } from "react";+import { fireEvent, render, screen, within } from "@testing-library/react";+import { expect, it, vi } from "vitest";++import { ComposerInput } from "@/components/chat/home/ComposerInput";++vi.mock("react-i18next", () => ({+ useTranslation: () => ({ t: (key: string) => key }),+}));++const languageOptions = [+ { value: "zh", label: "简体中文" },+ { value: "fr", label: "Français" },+];++function renderComposer({+ persona = true,+ language = true,+ disabled = false,+ override = null,+}: {+ persona?: boolean;+ language?: boolean;+ disabled?: boolean;+ override?: string | null;+} = {}) {+ const onSend = vi.fn();+ const onInputChange = vi.fn();+ const onOpenPersonaSelector = vi.fn();+ const onReplyLanguageChange = vi.fn();++ render(+ <ComposerInput+ textareaRef={createRef<HTMLTextAreaElement>()}+ isVisualizeMode={false}+ canSendEmpty={false}+ onSend={onSend}+ onInputChange={onInputChange}+ onPaste={vi.fn()}+ selectedCounts={{+ attachments: 0,+ knowledge: 0,+ chatHistory: 0,+ myAgents: 0,+ books: 0,+ reading: 0,+ notebooks: 0,+ questionBank: 0,+ persona: 0,+ memory: 0,+ }}+ knowledgeAvailable={false}+ personaAvailable={false}+ onSelectAttach={vi.fn()}+ onSelectNotebookPicker={vi.fn()}+ onSelectBookPicker={vi.fn()}+ onSelectHistoryPicker={vi.fn()}+ onSelectQuestionBankPicker={vi.fn()}+ onSelectPersonaPicker={vi.fn()}+ onSelectMemoryPicker={vi.fn()}+ onOpenPersonaSelector={persona ? onOpenPersonaSelector : undefined}+ replyLanguageOverride={override}+ replyLanguageOptions={languageOptions}+ replyLanguageDefaultLabel="English"+ replyLanguageDisabled={disabled}+ onReplyLanguageChange={language ? onReplyLanguageChange : undefined}+ />,+ );++ return {+ input: screen.getByRole("textbox") as HTMLTextAreaElement,+ onSend,+ onInputChange,+ onOpenPersonaSelector,+ onReplyLanguageChange,+ };+}++it("lists both slash commands and filters them by prefix", () => {+ const { input } = renderComposer();++ fireEvent.change(input, { target: { value: "/" } });+ expect(within(screen.getByRole("listbox", { name: "Commands" })).getAllByRole("option"))+ .toHaveLength(2);+ expect(screen.getByRole("option", { name: /\/persona/ })).toBeInTheDocument();+ expect(screen.getByRole("option", { name: /\/language/ })).toBeInTheDocument();++ fireEvent.change(input, { target: { value: "/lan" } });+ expect(screen.queryByRole("option", { name: /\/persona/ })).not.toBeInTheDocument();+ expect(screen.getByRole("option", { name: /\/language/ })).toBeInTheDocument();++ fireEvent.change(input, { target: { value: "/per" } });+ expect(screen.getByRole("option", { name: /\/persona/ })).toBeInTheDocument();+ expect(screen.queryByRole("option", { name: /\/language/ })).not.toBeInTheDocument();++ fireEvent.change(input, { target: { value: "Please /language" } });+ expect(screen.queryByRole("listbox", { name: "Commands" })).not.toBeInTheDocument();+});++it("uses arrow keys and Enter to open the language list without sending the command", () => {+ const { input, onSend, onInputChange, onOpenPersonaSelector, onReplyLanguageChange } =+ renderComposer();++ fireEvent.change(input, { target: { value: "/" } });+ fireEvent.keyDown(input, { key: "ArrowDown" });+ expect(screen.getByRole("option", { name: /\/language/ })).toHaveAttribute("aria-selected", "true");+ fireEvent.keyDown(input, { key: "Enter" });++ expect(input).toHaveValue("");+ expect(onInputChange).toHaveBeenLastCalledWith("");+ expect(onSend).not.toHaveBeenCalled();+ expect(onOpenPersonaSelector).not.toHaveBeenCalled();+ const choices = within(screen.getByRole("listbox", { name: "Reply language" }));+ expect(choices.getByRole("option", { name: "Account default (English)" })).toBeInTheDocument();+ expect(choices.getByRole("option", { name: "简体中文" })).toBeInTheDocument();+ expect(choices.getByRole("option", { name: "Français" })).toBeInTheDocument();++ fireEvent.click(choices.getByRole("option", { name: "Français" }));+ expect(onReplyLanguageChange).toHaveBeenCalledExactlyOnceWith("fr");+ expect(screen.queryByRole("listbox", { name: "Reply language" })).not.toBeInTheDocument();+ expect(onSend).not.toHaveBeenCalled();+});++it("selects the account default by keyboard and closes the menus with Escape", () => {+ const { input, onReplyLanguageChange, onSend } = renderComposer({ override: "zh" });++ fireEvent.change(input, { target: { value: "/language" } });+ fireEvent.keyDown(input, { key: "Enter" });+ const choices = within(screen.getByRole("listbox", { name: "Reply language" }));+ expect(choices.getByRole("option", { name: "简体中文" })).toHaveAttribute("aria-selected", "true");+ fireEvent.keyDown(input, { key: "ArrowUp" });+ fireEvent.keyDown(input, { key: "Enter" });+ expect(onReplyLanguageChange).toHaveBeenCalledExactlyOnceWith("");+ expect(onSend).not.toHaveBeenCalled();++ fireEvent.change(input, { target: { value: "/language" } });+ fireEvent.keyDown(input, { key: "Enter" });+ expect(screen.getByRole("listbox", { name: "Reply language" })).toBeInTheDocument();+ fireEvent.keyDown(input, { key: "Escape" });+ expect(screen.queryByRole("listbox", { name: "Reply language" })).not.toBeInTheDocument();+ expect(onReplyLanguageChange).toHaveBeenCalledTimes(1);++ fireEvent.change(input, { target: { value: "/" } });+ fireEvent.keyDown(input, { key: "Escape" });+ expect(screen.queryByRole("listbox", { name: "Commands" })).not.toBeInTheDocument();+});++it("keeps persona available while the reply-language command is disabled", () => {+ const { input, onOpenPersonaSelector, onReplyLanguageChange, onSend } =+ renderComposer({ disabled: true });++ fireEvent.change(input, { target: { value: "/" } });+ expect(screen.getByRole("option", { name: /\/persona/ })).toBeInTheDocument();+ expect(screen.queryByRole("option", { name: /\/language/ })).not.toBeInTheDocument();+ fireEvent.keyDown(input, { key: "Enter" });+ expect(onOpenPersonaSelector).toHaveBeenCalledOnce();+ expect(onReplyLanguageChange).not.toHaveBeenCalled();+ expect(onSend).not.toHaveBeenCalled();++ fireEvent.change(input, { target: { value: "/language" } });+ expect(screen.queryByRole("listbox", { name: "Commands" })).not.toBeInTheDocument();+});