web: filter the chat model picker

Add a search field that narrows models by name, id or provider in place, keeps
focus while typing, and reports when nothing matches.
This commit is contained in:
2026-10-20 15:04:10 +01:00
parent 1480591a34
commit 9f29f387ba
5 changed files with 85 additions and 17 deletions
+1
View File
@@ -392,6 +392,7 @@
/* Model picker: a bounded list of the current harness's models. */
.chat-model-panel { width: min(480px, 100%); max-height: calc(100dvh - 48px); }
.chat-model-helper { margin: 0; font-size: 12px; }
.chat-model-search { width: 100%; min-height: 38px; }
.chat-model-loading { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 13px; }
.chat-model-error { margin: 0; color: var(--bad); font-size: 12px; }
.chat-model-empty { margin: 0; font-size: 13px; }
+1
View File
@@ -193,6 +193,7 @@ const state = {
chatModelsFor: "",
chatModelsLoading: false,
chatModelsError: "",
chatModelQuery: "",
chatModelBusy: false,
// The last time each destination's data arrived (manual refresh or a socket
// push); the list's Refresh button shows it on hover.
+14
View File
@@ -871,6 +871,20 @@ export function isChatSessionUnseen(session, { activeId = null, seen = null, ope
}
/**
* Narrow a model list by a case-insensitive substring over its display name,
* model id and provider. A blank query returns the whole list in its existing
* (server) order; the picker never re-sorts.
*/
export function filterChatModels(models, query) {
const list = (models ?? []).filter((model) => model && (model.id || model.name));
const needle = str(query).trim().toLowerCase();
if (needle === "") return list;
return list.filter((model) =>
`${str(model.name)}\u0000${str(model.id)}\u0000${str(model.provider)}`.toLowerCase().includes(needle),
);
}
// ---------------------------------------------------------------------------
// Session narrowing and grouping (ChatListFilter.kt)
// ---------------------------------------------------------------------------
+55 -17
View File
@@ -112,6 +112,7 @@ import {
emptyChatSeen,
encodeChatOverrides,
encodeChatSeen,
filterChatModels,
filterSessions,
groupSessionsByDirectory,
hideChatOverride,
@@ -2570,6 +2571,7 @@ function openChatModelPicker(session) {
state.chatModelsError = "";
state.chatModelsFor = "";
state.chatModels = [];
state.chatModelQuery = "";
state.chatModelsLoading = true;
renderContent();
loadChatModels(session.id);
@@ -2579,6 +2581,7 @@ function closeChatModelPicker() {
state.chatModelPicker = null;
state.chatModelsError = "";
state.chatModelsLoading = false;
state.chatModelQuery = "";
renderContent();
}
@@ -2659,28 +2662,63 @@ function renderChatModelDialog(session) {
} else if ((state.chatModels ?? []).length === 0) {
panel.append(h("p", { class: "chat-model-empty muted", text: "No models are available for this chat." }));
} else {
const list = h("div", { class: "chat-model-list", role: "listbox", "aria-label": "Available models" });
const search = h("input", {
id: "chatModelSearch",
class: "chat-model-search",
type: "search",
placeholder: "Search models",
"aria-label": "Search models",
"aria-controls": "chatModelList",
autocomplete: "off",
spellcheck: "false",
value: state.chatModelQuery,
});
panel.append(search);
const list = h("div", {
id: "chatModelList",
class: "chat-model-list",
role: "listbox",
"aria-label": "Available models",
});
const noMatch = h("p", { class: "chat-model-empty muted", hidden: true });
const currentProvider = String(session.model_provider ?? "");
const currentModel = String(session.model ?? "");
for (const model of state.chatModels) {
const selected =
model.id === currentModel && (currentProvider === "" || model.provider === currentProvider);
const option = h("button", {
class: `ghost chat-model-option${selected ? " selected" : ""}`,
type: "button",
role: "option",
"aria-selected": selected ? "true" : "false",
disabled: state.chatModelBusy,
onclick: () => selectChatModel(session, model),
});
option.append(h("span", { class: "chat-model-option-name", text: model.name || model.id }));
option.append(h("span", { class: "chat-model-option-provider muted", text: model.provider }));
if (selected) option.append(h("span", { class: "chat-model-check", text: "\u2713" }));
list.append(option);
const renderOptions = (query) => {
const models = filterChatModels(state.chatModels, query);
list.replaceChildren();
for (const model of models) {
const selected =
model.id === currentModel && (currentProvider === "" || model.provider === currentProvider);
const option = h("button", {
class: `ghost chat-model-option${selected ? " selected" : ""}`,
type: "button",
role: "option",
"aria-selected": selected ? "true" : "false",
disabled: state.chatModelBusy,
onclick: () => selectChatModel(session, model),
});
option.append(h("span", { class: "chat-model-option-name", text: model.name || model.id }));
option.append(h("span", { class: "chat-model-option-provider muted", text: model.provider }));
if (selected) option.append(h("span", { class: "chat-model-check", text: "\u2713" }));
list.append(option);
}
const needle = String(query ?? "").trim();
noMatch.hidden = models.length > 0;
noMatch.textContent = needle === "" ? "" : `No models match "${needle}".`;
};
search.addEventListener("input", (event) => {
state.chatModelQuery = event.target.value;
renderOptions(event.target.value);
list.scrollTop = 0;
});
renderOptions(state.chatModelQuery);
panel.append(list, noMatch);
if (typeof requestAnimationFrame === "function") {
requestAnimationFrame(() => search.focus());
}
panel.append(list);
if (typeof requestAnimationFrame === "function") {
requestAnimationFrame(() => {
if (String(state.chatModelQuery ?? "").trim() !== "") return;
const selected = list.querySelector(".chat-model-option.selected");
if (!selected) return;
const top = selected.offsetTop - list.clientHeight / 2 + selected.offsetHeight / 2;
+14
View File
@@ -111,6 +111,7 @@ import {
deltaPartId,
directoryChoices,
directoryLabel,
filterChatModels,
homeDirectoryFor,
abbreviateHome,
dismissChatNotice,
@@ -572,6 +573,19 @@ test("groupSessionsByDirectory groups in first-occurrence order and labels a bla
assert.equal(directoryLabel("/a"), "/a");
});
test("filterChatModels matches name, id or provider case-insensitively", () => {
const models = [
{ id: "deepseek-v4.1-flash", provider: "opencode-go", name: "DeepSeek V4.1 Flash" },
{ id: "gpt-6-luna", provider: "openai", name: "GPT-6 Luna" },
{ id: "beam-free", provider: "opencode-go", name: "Beam Free" },
];
assert.deepEqual(filterChatModels(models, "").map((m) => m.id), models.map((m) => m.id));
assert.deepEqual(filterChatModels(models, "LUNA").map((m) => m.id), ["gpt-6-luna"]);
assert.deepEqual(filterChatModels(models, "deepseek").map((m) => m.id), ["deepseek-v4.1-flash"]);
assert.deepEqual(filterChatModels(models, "opencode-go").map((m) => m.id), ["deepseek-v4.1-flash", "beam-free"]);
assert.deepEqual(filterChatModels(models, "nothing"), []);
});
test("directory labels abbreviate the user's home to ~", () => {
const home = homeDirectoryFor(["/Users/alan/repos/pipelines", "/Users/alan/notes"]);
assert.equal(home, "/Users/alan");