🙌 OpenHands: AI-Driven Development
fix(command-menu): list Model Router and Agent Context; show Ctrl+K off Apple (#18027)
Engel Nyst760e954da65b
diff --git a/__tests__/components/features/command-menu/command-menu-items.test.tsx b/__tests__/components/features/command-menu/command-menu-items.test.tsxindex 355601651b..bff3cb1f61 100644--- a/__tests__/components/features/command-menu/command-menu-items.test.tsx+++ b/__tests__/components/features/command-menu/command-menu-items.test.tsx@@ -1,6 +1,7 @@import { afterEach, describe, expect, it, vi } from "vitest";import { createCommandMenuItems } from "#/components/features/command-menu/command-menu-items";+import { OSS_NAV_ITEMS } from "#/constants/settings-nav";/*** The automation entry's title, description, and keywords are the interface@@ -46,13 +47,27 @@ describe("the command menu settings group", () => {"settings","agent-settings","llm-settings",+ "meta-llm-settings","condenser-settings",+ "agent-context-settings","verification-settings","app-settings","secrets-settings",]);});+ it("offers an entry for every page the settings nav lists", () => {+ // Act+ const routes = createCommandMenuItems({ toggleSidebar: vi.fn() }).map(+ (item) => item.to,+ );++ // Assert+ expect(routes).toEqual(+ expect.arrayContaining(OSS_NAV_ITEMS.map((navItem) => navItem.to)),+ );+ });+it("keeps only Settings and Application when locked to a Cloud host", () => {// Arrangevi.stubEnv("VITE_LOCK_TO_CLOUD", "https://app.all-hands.dev");diff --git a/__tests__/components/features/command-menu/command-menu.test.tsx b/__tests__/components/features/command-menu/command-menu.test.tsxindex 26cc0f304a..bec21b7f48 100644--- a/__tests__/components/features/command-menu/command-menu.test.tsx+++ b/__tests__/components/features/command-menu/command-menu.test.tsx@@ -1,7 +1,13 @@-import { act, fireEvent, screen, waitFor } from "@testing-library/react";+import {+ act,+ fireEvent,+ screen,+ waitFor,+ within,+} from "@testing-library/react";import userEvent from "@testing-library/user-event";import { renderToStaticMarkup } from "react-dom/server";-import { describe, it, expect, beforeEach, vi } from "vitest";+import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";import {CommandMenu,CommandMenuTrigger,@@ -41,6 +47,16 @@ const AUTOMATIONS_TITLE_KEY = getInterfaceCopy().commandMenuTitle;const NEW_CHAT_TITLE_KEY = "COMMAND_MENU$NEW_CHAT_TITLE";const SECRETS_TITLE_KEY = "COMMAND_MENU$SECRETS_SETTINGS_TITLE";const TOGGLE_SIDEBAR_TITLE_KEY = "COMMAND_MENU$TOGGLE_SIDEBAR_TITLE";+const APPLE_SHORTCUT_KEY = "COMMAND_MENU$SHORTCUT";+const CTRL_SHORTCUT_KEY = "COMMAND_MENU$SHORTCUT_CTRL";+const MAC_USER_AGENT =+ "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36";+const IPHONE_USER_AGENT =+ "Mozilla/5.0 (iPhone; CPU iPhone OS 18_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.0 Mobile/15E148 Safari/604.1";+const LINUX_USER_AGENT =+ "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36";+const WINDOWS_USER_AGENT =+ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36";const SEARCH_INPUT_ID = "command-menu-search";const RESULTS_LISTBOX_ID = "command-menu-results";const NEW_CHAT_OPTION_ID = "command-menu-option-new-chat";@@ -191,6 +207,28 @@ describe("CommandMenu", () => {});});+ it.each([+ ["meta_llm", COMMAND_MENU_ROUTE.metaLlmSettings],+ ["agent_context", COMMAND_MENU_ROUTE.agentContextSettings],+ ])(+ "finds the %s settings page and opens it",+ async (searchTerm, expectedRoute) => {+ useCommandMenuStore.getState().open();+ const { navigate } = renderCommandMenu();++ await userEvent.type(+ screen.getByRole("combobox", { name: SEARCH_LABEL_KEY }),+ searchTerm,+ );+ await userEvent.keyboard("{Enter}");++ expect(navigate).toHaveBeenCalledWith(expectedRoute);+ await waitFor(() => {+ expect(screen.queryByTestId("command-menu")).not.toBeInTheDocument();+ });+ },+ );+it("supports arrow-key navigation and enter selection", async () => {useCommandMenuStore.getState().open();const { navigate } = renderCommandMenu();@@ -364,7 +402,7 @@ describe("CommandMenu", () => {name: SEARCH_LABEL_KEY,});expect(reopenedInput).toHaveValue("");- expect(screen.getAllByRole("option")).toHaveLength(12);+ expect(screen.getAllByRole("option")).toHaveLength(14);expect(screen.getAllByRole("option")[0]).toHaveAttribute("aria-selected","true",@@ -467,6 +505,46 @@ describe("CommandMenu", () => {});});+describe("the command menu shortcut hint", () => {+ afterEach(() => {+ vi.restoreAllMocks();+ });++ it.each([+ ["macOS", MAC_USER_AGENT, APPLE_SHORTCUT_KEY],+ ["iOS", IPHONE_USER_AGENT, APPLE_SHORTCUT_KEY],+ ["Linux", LINUX_USER_AGENT, CTRL_SHORTCUT_KEY],+ ["Windows", WINDOWS_USER_AGENT, CTRL_SHORTCUT_KEY],+ ])(+ "on %s reads the same in the sidebar trigger and the menu header",+ (_platform, userAgent, expectedShortcutKey) => {+ // Arrange+ vi.spyOn(window.navigator, "userAgent", "get").mockReturnValue(userAgent);+ useCommandMenuStore.getState().open();++ // Act+ renderWithProviders(+ <>+ <CommandMenuTrigger collapsed={false} />+ <CommandMenu />+ </>,+ );++ // Assert+ expect(+ within(screen.getByRole("button", { name: OPEN_LABEL_KEY })).getByText(+ expectedShortcutKey,+ ),+ ).toBeInTheDocument();+ expect(+ within(screen.getByTestId("command-menu")).getByText(+ expectedShortcutKey,+ ),+ ).toBeInTheDocument();+ },+ );+});+describe("CommandMenuTrigger", () => {it("opens the command menu from the sidebar trigger", async () => {renderWithProviders(diff --git a/src/components/features/command-menu/command-menu-items.tsx b/src/components/features/command-menu/command-menu-items.tsxindex 3328a6f100..ab6dea1c4b 100644--- a/src/components/features/command-menu/command-menu-items.tsx+++ b/src/components/features/command-menu/command-menu-items.tsx@@ -1,11 +1,13 @@import React from "react";import {Bot,+ Brain,Home,Keyboard,KeyRound,ListTodo,PanelsTopLeft,+ Route,Search,Settings,ShieldCheck,@@ -21,6 +23,7 @@ import {} from "#/manifests/automation-interface";import { getLockedCloudHost } from "#/api/agent-server-config";import { LOCKED_CLOUD_SETTINGS_NAV_PATH } from "#/constants/settings-nav";+import { isApplePlatform } from "#/utils/utils";const ICON_SIZE = 18;@@ -32,7 +35,9 @@ export const COMMAND_MENU_ROUTE = {settings: "/settings",agentSettings: "/settings/agents",llmSettings: "/settings/llm",+ metaLlmSettings: "/settings/meta-llm",condenserSettings: "/settings/condenser",+ agentContextSettings: "/settings/agent-context",verificationSettings: "/settings/verification",appSettings: "/settings/app",secretsSettings: "/settings/secrets",@@ -47,7 +52,9 @@ export type CommandMenuItemId =| "settings"| "agent-settings"| "llm-settings"+ | "meta-llm-settings"| "condenser-settings"+ | "agent-context-settings"| "verification-settings"| "app-settings"| "secrets-settings"@@ -82,6 +89,16 @@ export function commandMenuItemCopy(return key === undefined ? "" : translate(key);}+/**+ * The open-menu shortcut as the platform spells it: ⌘K on Apple platforms,+ * Ctrl+K elsewhere. The key handler accepts either modifier everywhere.+ */+export function getCommandMenuShortcutKey(): I18nKey {+ return isApplePlatform()+ ? I18nKey.COMMAND_MENU$SHORTCUT+ : I18nKey.COMMAND_MENU$SHORTCUT_CTRL;+}+export const COMMAND_MENU_GROUP_LABELS: Record<CommandMenuGroupId, I18nKey> = {navigation: I18nKey.COMMAND_MENU$GROUP_NAVIGATION,settings: I18nKey.COMMAND_MENU$GROUP_SETTINGS,@@ -169,6 +186,15 @@ export const createCommandMenuItems = ({icon: <Search size={ICON_SIZE} />,to: COMMAND_MENU_ROUTE.llmSettings,},+ {+ id: "meta-llm-settings",+ group: "settings",+ titleKey: I18nKey.SETTINGS$NAV_META_LLM,+ descriptionKey: I18nKey.SETTINGS$PAGE_META_LLM_SUBLINE,+ keywordsKey: I18nKey.COMMAND_MENU$META_LLM_SETTINGS_KEYWORDS,+ icon: <Route size={ICON_SIZE} />,+ to: COMMAND_MENU_ROUTE.metaLlmSettings,+ },{id: "condenser-settings",group: "settings",@@ -178,6 +204,15 @@ export const createCommandMenuItems = ({icon: <ListTodo size={ICON_SIZE} />,to: COMMAND_MENU_ROUTE.condenserSettings,},+ {+ id: "agent-context-settings",+ group: "settings",+ titleKey: I18nKey.SETTINGS$NAV_AGENT_CONTEXT,+ descriptionKey: I18nKey.SETTINGS$PAGE_AGENT_CONTEXT_SUBLINE,+ keywordsKey: I18nKey.COMMAND_MENU$AGENT_CONTEXT_SETTINGS_KEYWORDS,+ icon: <Brain size={ICON_SIZE} />,+ to: COMMAND_MENU_ROUTE.agentContextSettings,+ },{id: "verification-settings",group: "settings",diff --git a/src/components/features/command-menu/command-menu-trigger.tsx b/src/components/features/command-menu/command-menu-trigger.tsxindex 3f04841781..c64c675c24 100644--- a/src/components/features/command-menu/command-menu-trigger.tsx+++ b/src/components/features/command-menu/command-menu-trigger.tsx@@ -11,6 +11,7 @@ import {sidebarNavLabelClassName,sidebarNavRowClassName,} from "#/components/features/sidebar/sidebar-layout";+import { getCommandMenuShortcutKey } from "./command-menu-items";interface CommandMenuTriggerProps {collapsed: boolean;@@ -63,7 +64,7 @@ export function CommandMenuTrigger({ collapsed }: CommandMenuTriggerProps) {</span>{!collapsed ? (<kbd className="rounded-md border border-border bg-black/20 px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-[0.12em] text-text-dim">- {t(I18nKey.COMMAND_MENU$SHORTCUT)}+ {t(getCommandMenuShortcutKey())}</kbd>) : null}</button>diff --git a/src/components/features/command-menu/command-menu.tsx b/src/components/features/command-menu/command-menu.tsxindex 3be7f6cc9e..cfa175df4f 100644--- a/src/components/features/command-menu/command-menu.tsx+++ b/src/components/features/command-menu/command-menu.tsx@@ -14,6 +14,7 @@ import {type CommandMenuItemDefinition,commandMenuItemCopy,createCommandMenuItems,+ getCommandMenuShortcutKey,} from "./command-menu-items";const COMMAND_MENU_SEARCH_INPUT_ID = "command-menu-search";@@ -241,7 +242,7 @@ export function CommandMenu() {</button>) : null}<kbd className="hidden rounded-md border border-border bg-black/25 px-2 py-1 text-[11px] font-semibold uppercase tracking-[0.18em] text-text-dim sm:inline-flex">- {t(I18nKey.COMMAND_MENU$SHORTCUT)}+ {t(getCommandMenuShortcutKey())}</kbd></div>diff --git a/src/i18n/translation.json b/src/i18n/translation.jsonindex 002d4a977d..f1e2e4de8e 100644--- a/src/i18n/translation.json+++ b/src/i18n/translation.json@@ -36889,6 +36889,23 @@"zh-CN": "⌘K","zh-TW": "⌘K"},+ "COMMAND_MENU$SHORTCUT_CTRL": {+ "ar": "Ctrl+K",+ "ca": "Ctrl+K",+ "de": "Strg+K",+ "en": "Ctrl+K",+ "es": "Ctrl+K",+ "fr": "Ctrl+K",+ "it": "Ctrl+K",+ "ja": "Ctrl+K",+ "ko-KR": "Ctrl+K",+ "no": "Ctrl+K",+ "pt": "Ctrl+K",+ "tr": "Ctrl+K",+ "uk": "Ctrl+K",+ "zh-CN": "Ctrl+K",+ "zh-TW": "Ctrl+K"+ },"COMMAND_MENU$GROUP_NAVIGATION": {"ar": "Navigation","ca": "Navigation",@@ -37331,6 +37348,23 @@"zh-CN": "llm model provider api key profile inference","zh-TW": "llm model provider api key profile inference"},+ "COMMAND_MENU$META_LLM_SETTINGS_KEYWORDS": {+ "ar": "model router meta llm routing profile موجه النماذج توجيه ملف",+ "ca": "model router meta llm routing profile encaminador models encaminament perfil",+ "de": "model router meta llm routing profile modell-router weiterleitung profil",+ "en": "model router meta llm routing profile",+ "es": "model router meta llm routing profile enrutador modelos enrutamiento perfil",+ "fr": "model router meta llm routing profile routeur modèles routage profil",+ "it": "model router meta llm routing profile router modelli instradamento profilo",+ "ja": "model router meta llm routing profile モデル ルーター ルーティング プロファイル",+ "ko-KR": "model router meta llm routing profile 모델 라우터 라우팅 프로필",+ "no": "model router meta llm routing profile modellruter ruting profil",+ "pt": "model router meta llm routing profile roteador modelos roteamento perfil",+ "tr": "model router meta llm routing profile model yönlendirici yönlendirme profil",+ "uk": "model router meta llm routing profile маршрутизатор моделей маршрутизація профіль",+ "zh-CN": "model router meta llm routing profile 模型 路由器 路由 配置文件",+ "zh-TW": "model router meta llm routing profile 模型 路由器 路由 設定檔"+ },"COMMAND_MENU$CONDENSER_SETTINGS_TITLE": {"ar": "Condenser settings","ca": "Condenser settings",@@ -37382,6 +37416,23 @@"zh-CN": "condenser context memory summary","zh-TW": "condenser context memory summary"},+ "COMMAND_MENU$AGENT_CONTEXT_SETTINGS_KEYWORDS": {+ "ar": "agent context memory notes recall سياق الوكيل ذاكرة ملاحظات تذكر",+ "ca": "agent context memory notes recall context agent memòria notes record",+ "de": "agent context memory notes recall agentenkontext gedächtnis notizen erinnerung",+ "en": "agent context memory notes recall",+ "es": "agent context memory notes recall contexto agente memoria notas recordar",+ "fr": "agent context memory notes recall contexte agent mémoire notes rappel",+ "it": "agent context memory notes recall contesto agente memoria appunti ricordare",+ "ja": "agent context memory notes recall エージェント コンテキスト メモリ メモ 記憶",+ "ko-KR": "agent context memory notes recall 에이전트 컨텍스트 메모리 메모 기억",+ "no": "agent context memory notes recall agentkontekst minne notater huske",+ "pt": "agent context memory notes recall contexto agente memória notas lembrar",+ "tr": "agent context memory notes recall ajan bağlam bellek notlar hatırlama",+ "uk": "agent context memory notes recall контекст агента пам'ять нотатки згадування",+ "zh-CN": "agent context memory notes recall 代理 上下文 记忆 笔记 回忆",+ "zh-TW": "agent context memory notes recall 代理 上下文 記憶 筆記 回憶"+ },"COMMAND_MENU$VERIFICATION_SETTINGS_TITLE": {"ar": "Verification settings","ca": "Verification settings",diff --git a/src/utils/utils.ts b/src/utils/utils.tsindex e9c0cb2b04..23bb300cb9 100644--- a/src/utils/utils.ts+++ b/src/utils/utils.ts@@ -72,6 +72,15 @@ export const isMobileUserAgent = (): boolean =>navigator.userAgent,);+/**+ * Detect an Apple platform (macOS, iOS, iPadOS), whose keyboard shortcuts use+ * ⌘ where other platforms use Ctrl. iPadOS Safari reports a Mac user agent,+ * which this matches too.+ */+export const isApplePlatform = (): boolean =>+ typeof navigator !== "undefined" &&+ /Macintosh|Mac OS X|iPhone|iPad|iPod/.test(navigator.userAgent);+/*** Detect if the user is on a mobile device.* Touch support alone is not sufficient — touchscreen laptops have touch