diff --git a/components/ChatInput.test.mjs b/components/ChatInput.test.mjs index 6dd147b15..29cd5a20b 100644 --- a/components/ChatInput.test.mjs +++ b/components/ChatInput.test.mjs @@ -8,7 +8,7 @@ const jiti = createJiti(import.meta.url, { jsx: { runtime: "automatic" }, tsconfigPaths: true, }); -const { ChatInput, ModelErrorBanner } = await jiti.import("./ChatInput.tsx"); +const { ChatInput, ModelErrorBanner, filterModelOptions } = await jiti.import("./ChatInput.tsx"); test("renders the upstream model error", () => { const html = renderToStaticMarkup( @@ -64,4 +64,16 @@ test("renders goal, planning, and advisor indicators at the composer", () => { assert.match(html, /Ship the active goal bar/); assert.match(html, /(Planning in progress|chatInput\.planningInProgress)/); assert.match(html, /(Advisor enabled|chatInput\.advisorEnabled)/); +}); + +test("filters model options by display name, identifier, and provider", () => { + const options = [ + { provider: "OpenAI", modelId: "gpt-5.2", name: "GPT-5.2" }, + { provider: "Anthropic", modelId: "claude-sonnet-4-5", name: "Claude Sonnet 4.5" }, + ]; + + assert.deepEqual(filterModelOptions(options, "sonnet", "en"), [options[1]]); + assert.deepEqual(filterModelOptions(options, "5.2", "en"), [options[0]]); + assert.deepEqual(filterModelOptions(options, "OPENAI", "en"), [options[0]]); + assert.equal(filterModelOptions(options, " ", "en"), options); }); \ No newline at end of file diff --git a/components/ChatInput.tsx b/components/ChatInput.tsx index 410f0bec9..a0d5b0864 100644 --- a/components/ChatInput.tsx +++ b/components/ChatInput.tsx @@ -1,7 +1,7 @@ "use client"; import React, { useRef, useState, useCallback, useEffect, useImperativeHandle, forwardRef, memo, KeyboardEvent } from "react"; -import { ChevronDown, ListChecks, Sparkles, Target } from "lucide-react"; +import { ChevronDown, ListChecks, Search, Sparkles, Target } from "lucide-react"; import { getSubmitDuringRunBehavior } from "@/lib/composer-prefs"; import type { BuiltinSlashCommandResult, CompactResultInfo, QueuedMessages, SlashCommandInfo } from "@/hooks/useAgentSession"; import type { ActiveGoal, ActivePlan } from "@/lib/web-mode-state"; @@ -122,6 +122,16 @@ function compareModelOptions(collator: Intl.Collator, a: ModelOption, b: ModelOp || collator.compare(a.modelId, b.modelId); } +export function filterModelOptions(options: ModelOption[], query: string, locale: string): ModelOption[] { + const normalizedQuery = query.trim().toLocaleLowerCase(locale); + if (!normalizedQuery) return options; + return options.filter((option) => ( + option.name.toLocaleLowerCase(locale).includes(normalizedQuery) + || option.modelId.toLocaleLowerCase(locale).includes(normalizedQuery) + || option.provider.toLocaleLowerCase(locale).includes(normalizedQuery) + )); +} + const THINKING_LEVEL_DESC_KEYS: Record = { auto: "chatInput.thinkingAuto", off: "chatInput.thinkingOff", @@ -402,6 +412,7 @@ export const ChatInput = memo(forwardRef(function ChatIn const [modelDropdownOpen, setModelDropdownOpen] = useState(false); const [modelDropdownRect, setModelDropdownRect] = useState<{ top: number; left: number; width: number } | null>(null); const [thinkingDropdownOpen, setThinkingDropdownOpen] = useState(false); + const [modelSearchQuery, setModelSearchQuery] = useState(""); const [attachedImages, setAttachedImages] = useState(() => ( draftKey ? draftImagesToAttachedImages(getDraft(draftKey)?.images) : [] )); @@ -426,6 +437,7 @@ export const ChatInput = memo(forwardRef(function ChatIn const textareaRef = useRef(null); const dropdownRef = useRef(null); const modelDropdownPanelRef = useRef(null); + const modelSearchInputRef = useRef(null); const thinkingDropdownRef = useRef(null); const historyMenuRef = useRef(null); const fileInputRef = useRef(null); @@ -1318,16 +1330,21 @@ export const ChatInput = memo(forwardRef(function ChatIn })).sort((a, b) => compareModelOptions(modelCollator, a, b)); }, [modelList, modelNames, model?.provider, visibleModelKeys, modelCollator]); - // Group options by provider, preserving insertion order + const filteredModelOptions = React.useMemo( + () => filterModelOptions(modelOptions, modelSearchQuery, locale), + [locale, modelOptions, modelSearchQuery], + ); + + // Group options by provider, preserving insertion order. const modelsByProvider: { provider: string; options: ModelOption[] }[] = React.useMemo(() => { const groups: { provider: string; options: ModelOption[] }[] = []; - for (const opt of modelOptions) { + for (const opt of filteredModelOptions) { const group = groups.find((g) => g.provider === opt.provider); if (group) group.options.push(opt); else groups.push({ provider: opt.provider, options: [opt] }); } return groups; - }, [modelOptions]); + }, [filteredModelOptions]); const displayModelName = model ? (modelOptions.find((o) => o.modelId === model.modelId && o.provider === model.provider)?.name @@ -1374,6 +1391,14 @@ export const ChatInput = memo(forwardRef(function ChatIn if (isStreaming) setThinkingDropdownOpen(false); }, [isStreaming]); + useEffect(() => { + if (!modelDropdownOpen) { + setModelSearchQuery(""); + return; + } + requestAnimationFrame(() => modelSearchInputRef.current?.focus()); + }, [modelDropdownOpen]); + // Close dropdowns on outside click useEffect(() => { const handler = (e: MouseEvent) => { @@ -2101,11 +2126,44 @@ export const ChatInput = memo(forwardRef(function ChatIn bottom, ...panelPos, zIndex: 500, - overflow: "hidden", maxHeight: maxH, overflowY: "auto", + display: "flex", flexDirection: "column", + overflow: "hidden", maxHeight: maxH, }}> +
+
+
+
+
{modelsByProvider.length === 0 ? (
- {showModelsLoading ? t("chatInput.loadingModels") : t("chatInput.noAvailableModels")} + {modelSearchQuery.trim() ? t("chatInput.noMatchingModels") : showModelsLoading ? t("chatInput.loadingModels") : t("chatInput.noAvailableModels")}
) : modelsByProvider.map((group, gi) => (
@@ -2148,6 +2206,7 @@ export const ChatInput = memo(forwardRef(function ChatIn })}
))} +
); })()} diff --git a/lib/i18n/locales/en.json b/lib/i18n/locales/en.json index e7045ca51..abc86bf86 100644 --- a/lib/i18n/locales/en.json +++ b/lib/i18n/locales/en.json @@ -174,6 +174,7 @@ "chatInput.noAvailableModels": "No available models", "chatInput.noCommandsFound": "No extension, prompt, or skill commands found", "chatInput.noMatchingFiles": "No matching files", + "chatInput.noMatchingModels": "No matching models", "chatInput.noModels": "No models", "chatInput.placeholder": "Message… Type / for commands, @ for files", "chatInput.placeholderRunning": "Agent is running…", @@ -184,6 +185,7 @@ "chatInput.retrying": "Retrying ({attempt}/{maxAttempts})…", "chatInput.searching": "Searching…", "chatInput.searchingAllFiles": "searching all files…", + "chatInput.searchModels": "Search models…", "chatInput.selectModel": "Select model", "chatInput.send": "Send", "chatInput.shellLocal": "Shell · output stays local", diff --git a/lib/i18n/locales/ja.json b/lib/i18n/locales/ja.json index 2dcd8e61a..ac27e003a 100644 --- a/lib/i18n/locales/ja.json +++ b/lib/i18n/locales/ja.json @@ -174,6 +174,7 @@ "chatInput.noAvailableModels": "利用可能なモデルがありません", "chatInput.noCommandsFound": "拡張機能・プロンプト・スキルのコマンドが見つかりません", "chatInput.noMatchingFiles": "一致するファイルがありません", + "chatInput.noMatchingModels": "一致するモデルがありません", "chatInput.noModels": "モデルなし", "chatInput.placeholder": "メッセージ… / でコマンド、@ でファイル", "chatInput.placeholderRunning": "エージェント実行中…", @@ -184,6 +185,7 @@ "chatInput.retrying": "再試行中({attempt}/{maxAttempts})…", "chatInput.searching": "検索中…", "chatInput.searchingAllFiles": "全ファイルを検索中…", + "chatInput.searchModels": "モデルを検索…", "chatInput.selectModel": "モデルを選択", "chatInput.send": "送信", "chatInput.shellLocal": "シェル · 出力はローカルのみ", diff --git a/lib/i18n/locales/zh-CN.json b/lib/i18n/locales/zh-CN.json index a24976314..e322b5d88 100644 --- a/lib/i18n/locales/zh-CN.json +++ b/lib/i18n/locales/zh-CN.json @@ -174,6 +174,7 @@ "chatInput.noAvailableModels": "没有可用模型", "chatInput.noCommandsFound": "未找到扩展、提示词或技能命令", "chatInput.noMatchingFiles": "没有匹配的文件", + "chatInput.noMatchingModels": "没有匹配的模型", "chatInput.noModels": "无模型", "chatInput.placeholder": "输入消息… 输入 / 使用命令,@ 引用文件", "chatInput.placeholderRunning": "智能体运行中…", @@ -184,6 +185,7 @@ "chatInput.retrying": "重试中({attempt}/{maxAttempts})…", "chatInput.searching": "搜索中…", "chatInput.searchingAllFiles": "正在搜索所有文件…", + "chatInput.searchModels": "搜索模型…", "chatInput.selectModel": "选择模型", "chatInput.send": "发送", "chatInput.shellLocal": "Shell · 输出仅保留在本地",