Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

Make the enabled-models picker a typeahead (#2451)

Joshua France25382c246852
diff --git a/plugins/admin/test/settings-lit.test.ts b/plugins/admin/test/settings-lit.test.ts
index 8fd34a2ee..15532cb77 100644
--- a/plugins/admin/test/settings-lit.test.ts
+++ b/plugins/admin/test/settings-lit.test.ts
@@ -34,10 +34,17 @@ test("model chips add and remove with stable keyed rendering", () => {
const dom = setup();
try {
dom.window.eval("settingsUI.load(" + JSON.stringify(models) + ',"org:test","webui-models")');
- const select = dom.window.document.getElementById("webui-models-add") as HTMLSelectElement;
- select.value = "b";
- select.dispatchEvent(new dom.window.Event("change"));
- dom.window.document.getElementById("webui-models-add-button")!.click();
+ const doc = dom.window.document;
+ const input = doc.getElementById("webui-models-add") as HTMLInputElement;
+ const options = () => [...doc.querySelectorAll("#webui-models-options option")].map((o) => o.textContent);
+ assert.deepEqual(options(), ["Alpha (a)", "Beta (b)"]);
+ input.value = "Bet";
+ input.dispatchEvent(new dom.window.Event("input"));
+ assert.equal((doc.getElementById("webui-models-add-button") as HTMLButtonElement).disabled, true);
+ input.value = "b";
+ input.dispatchEvent(new dom.window.Event("input"));
+ input.dispatchEvent(new dom.window.KeyboardEvent("keydown", { key: "Enter" }));
+ assert.deepEqual(options(), ["Alpha (a)"]);
assert.equal(dom.window.eval('settingsUI.collect("webui-models").ids.join()'), "b");
dom.window.document.querySelector<HTMLButtonElement>('[aria-label="Remove b"]')!.click();
assert.equal(dom.window.eval('settingsUI.states.get("webui-models").dirty'), false);
diff --git a/plugins/admin/ui/settings.ts b/plugins/admin/ui/settings.ts
index 078cf6153..0b46b6a85 100644
--- a/plugins/admin/ui/settings.ts
+++ b/plugins/admin/ui/settings.ts
@@ -150,6 +150,7 @@ function card(s: SettingsState) {
if (s.key === "branding") return brandingCard(s);
const ids: string[] = s.draft.ids || [];
const available = s.catalog.filter((m) => !ids.includes(m.id));
+ const canAdd = available.some((m) => m.id === s.selected);
return html`<section
class=${classMap({ card: true, "sv-models": true, hidden: !s.available, dirty: s.dirty })}
id="card-webui-models"
@@ -159,20 +160,23 @@ function card(s: SettingsState) {
<div class="model-add-row">
<div class="model-add-field">
<label for="webui-models-add">Add a model</label
- ><select
+ ><input
id="webui-models-add"
+ list="webui-models-options"
+ autocomplete="off"
+ placeholder="Search models…"
.value=${s.selected}
?disabled=${!available.length}
- @change=${(e: Event) => {
+ @input=${(e: Event) => {
s.selected = value(e);
s.render();
}}
- >
- <option value="">Choose a model…</option>
+ @keydown=${(e: KeyboardEvent) => e.key === "Enter" && canAdd && s.add()}
+ /><datalist id="webui-models-options">
${available.map((m) => html`<option value=${m.id}>${label(s, m.id)}</option>`)}
- </select>
+ </datalist>
</div>
- <button type="button" id="webui-models-add-button" ?disabled=${!s.selected} @click=${() => s.add()}>
+ <button type="button" id="webui-models-add-button" ?disabled=${!canAdd} @click=${() => s.add()}>
+ Add model
</button>
</div>