Skip to content

Commit edcf197

Browse files
authored
improve: one channel picker and one model picker across the Control UI (#122964)
* fix(ui): unify channel pickers with icons Preserve channel values and mutation ownership across Automations, pairing, setup, and Workboard while sharing accessible picker rendering and artwork. * refactor(ui): unify model pickers Share provider-aware model selection across chat, new sessions, Automations, Agents, model defaults, Session Observer, Talk, and Memory while preserving owner-specific values and locks. * fix(ui): keep picker change callbacks value-only Keep the Web Awesome element private to model-picker custom-mode handling while preserving one-argument callbacks for every picker consumer. * fix(ui): satisfy model picker types Keep custom sentinel options within the shared model option shape and guard optional Memory placeholder translation keys. * refactor(ui): remove obsolete model option template import Drop the Lit import after Agents model options became pure shared-picker data. * fix(ui): satisfy picker lint gates Use explicit model option mapping, remove stale E2E locals, and keep the Cron behavior suite within its enforced line budget. * test(ui): target unified session model picker
1 parent 01b3ece commit edcf197

59 files changed

Lines changed: 1725 additions & 2246 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎ui/src/components/channel-icon.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { html } from "lit";
2+
import {
3+
pluginArtPath,
4+
pluginFallbackGradient,
5+
pluginMonogram,
6+
} from "../pages/plugins/presentation.ts";
7+
import "../styles/channels.css";
8+
9+
/** Bundled channel art reuses the plugin art set because channel ids match plugin slugs. */
10+
export function renderChannelIcon(
11+
channelId: string,
12+
label: string,
13+
variant: "tile" | "cover" | "picker",
14+
) {
15+
const artVariant = variant === "picker" ? "tile" : variant;
16+
const art = pluginArtPath(channelId);
17+
const [from, to] = art ? ["", ""] : pluginFallbackGradient(channelId);
18+
const style = `${variant === "picker" ? "--channels-art-size:24px;" : ""}${
19+
art ? "" : `--channels-art-a:${from};--channels-art-b:${to}`
20+
}`;
21+
return html`<span
22+
class=${`channels-${artVariant}${art ? "" : ` channels-${artVariant}--fallback`}`}
23+
style=${style}
24+
aria-hidden="true"
25+
>
26+
${art
27+
? html`<img src=${art} alt="" loading="lazy" decoding="async" />`
28+
: html`<span>${pluginMonogram(label)}</span>`}
29+
</span>`;
30+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/* @vitest-environment jsdom */
2+
import { render } from "lit";
3+
import { describe, expect, it, vi } from "vitest";
4+
import { renderChannelPicker } from "./channel-picker.ts";
5+
6+
describe("renderChannelPicker", () => {
7+
it("renders neutral and channel artwork while preserving a missing current channel", () => {
8+
const container = document.createElement("div");
9+
render(
10+
renderChannelPicker({
11+
label: "Channel",
12+
value: "retired-channel",
13+
options: [
14+
{ value: "last", label: "last", kind: "neutral" },
15+
{ value: "telegram", label: "Telegram" },
16+
],
17+
onChange: vi.fn(),
18+
}),
19+
container,
20+
);
21+
22+
expect(container.querySelector('wa-option[value="last"] [slot="start"]')).toBeNull();
23+
expect(container.querySelector('wa-option[value="telegram"] img')).not.toBeNull();
24+
expect(container.querySelector('wa-option[value="retired-channel"]')?.textContent).toContain(
25+
"retired-channel",
26+
);
27+
expect(
28+
container.querySelector('wa-option[value="retired-channel"] .channels-tile--fallback'),
29+
).not.toBeNull();
30+
});
31+
32+
it("honors disabled choices and reports enabled changes", () => {
33+
const container = document.createElement("div");
34+
const onChange = vi.fn();
35+
render(
36+
renderChannelPicker({
37+
label: "Channel",
38+
value: "telegram",
39+
options: [
40+
{ value: "telegram", label: "Telegram" },
41+
{ value: "disabled", label: "Disabled", disabled: true },
42+
],
43+
onChange,
44+
}),
45+
container,
46+
);
47+
48+
const picker = container.querySelector<HTMLElement & { value: string }>("wa-select");
49+
expect(container.querySelector('wa-option[value="disabled"]')?.hasAttribute("disabled")).toBe(
50+
true,
51+
);
52+
if (!picker) {
53+
return;
54+
}
55+
Object.defineProperty(picker, "value", { configurable: true, value: "disabled" });
56+
picker.dispatchEvent(new Event("change", { bubbles: true }));
57+
Reflect.deleteProperty(picker, "value");
58+
expect(onChange).not.toHaveBeenCalled();
59+
Object.defineProperty(picker, "value", { configurable: true, value: "telegram" });
60+
picker.dispatchEvent(new Event("change", { bubbles: true }));
61+
Reflect.deleteProperty(picker, "value");
62+
expect(onChange).toHaveBeenCalledWith("telegram");
63+
});
64+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { nothing } from "lit";
2+
import { renderChannelIcon } from "./channel-icon.ts";
3+
import { renderPicker, type PickerOption, type PickerParams } from "./select-picker.ts";
4+
5+
export type ChannelPickerOption = PickerOption & {
6+
/** Neutral choices such as "last" or "all" are routing policy, not transports. */
7+
kind?: "channel" | "neutral";
8+
};
9+
10+
export function renderChannelPicker(params: PickerParams<ChannelPickerOption>) {
11+
return renderPicker({
12+
...params,
13+
className: "channel-picker",
14+
renderLeading: (option) =>
15+
option.kind === "neutral" ? nothing : renderChannelIcon(option.value, option.label, "picker"),
16+
});
17+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/* @vitest-environment jsdom */
2+
import { render } from "lit";
3+
import { describe, expect, it, vi } from "vitest";
4+
import { renderModelPicker } from "./model-picker.ts";
5+
6+
describe("renderModelPicker", () => {
7+
it("renders provider details and caller sentinels while preserving an unknown current model", () => {
8+
const container = document.createElement("div");
9+
render(
10+
renderModelPicker({
11+
label: "Model",
12+
value: "legacy/model",
13+
options: [
14+
{ value: "", label: "Automatic" },
15+
{
16+
value: "openai/gpt-5.6-luna",
17+
label: "GPT-5.6 Luna",
18+
provider: "openai",
19+
detail: "Fast · 128k",
20+
disabled: true,
21+
},
22+
],
23+
onChange: vi.fn(),
24+
}),
25+
container,
26+
);
27+
28+
expect(container.querySelector('wa-option[value=""] [slot="start"]')).toBeNull();
29+
const openai = container.querySelector('wa-option[value="openai/gpt-5.6-luna"]');
30+
expect(openai?.querySelector('[data-provider-icon="codex"]')).not.toBeNull();
31+
expect(openai?.textContent).toContain("Fast · 128k");
32+
expect(openai?.hasAttribute("disabled")).toBe(true);
33+
expect(container.querySelector('wa-option[value="legacy/model"]')?.textContent).toContain(
34+
"legacy/model",
35+
);
36+
});
37+
38+
it("reveals free-form entry without leaking its internal option value", () => {
39+
const container = document.createElement("div");
40+
const onChange = vi.fn();
41+
render(
42+
renderModelPicker({
43+
label: "Model",
44+
value: "openai/gpt-5.6-luna",
45+
options: [
46+
{ value: "", label: "Default" },
47+
{ value: "openai/gpt-5.6-luna", label: "GPT-5.6 Luna", provider: "openai" },
48+
],
49+
custom: { label: "Custom model…", placeholder: "provider/model" },
50+
onChange,
51+
}),
52+
container,
53+
);
54+
55+
const customOption = Array.from(container.querySelectorAll("wa-option")).find(
56+
(option) => option.textContent?.trim() === "Custom model…",
57+
);
58+
const picker = container.querySelector<HTMLElement & { value: string }>("wa-select");
59+
const input = container.querySelector<HTMLInputElement>("input");
60+
expect(customOption).not.toBeNull();
61+
expect(input?.hidden).toBe(true);
62+
if (!customOption || !picker || !input) {
63+
return;
64+
}
65+
Object.defineProperty(picker, "value", {
66+
configurable: true,
67+
value: customOption.getAttribute("value"),
68+
});
69+
picker.dispatchEvent(new Event("change", { bubbles: true }));
70+
Reflect.deleteProperty(picker, "value");
71+
expect(input.hidden).toBe(false);
72+
73+
input.value = "vendor/model with spaces";
74+
input.dispatchEvent(new Event("input", { bubbles: true }));
75+
expect(onChange).toHaveBeenCalledWith("vendor/model with spaces");
76+
expect(onChange).not.toHaveBeenCalledWith(customOption.getAttribute("value"));
77+
});
78+
});

‎ui/src/components/model-picker.ts‎

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import { html, nothing } from "lit";
2+
import { renderProviderBrandIcon } from "./provider-icon.ts";
3+
import { renderPicker } from "./select-picker.ts";
4+
5+
export type ModelPickerOption = {
6+
value: string;
7+
label: string;
8+
provider?: string;
9+
detail?: string;
10+
disabled?: boolean;
11+
};
12+
13+
type ModelPickerParams = {
14+
id?: string;
15+
label: string;
16+
value: string;
17+
options: readonly ModelPickerOption[];
18+
disabled?: boolean;
19+
title?: string;
20+
className?: string;
21+
placement?: "top" | "bottom";
22+
custom?: {
23+
label: string;
24+
placeholder?: string;
25+
commit?: "input" | "change";
26+
id?: string;
27+
invalid?: boolean;
28+
describedBy?: string;
29+
};
30+
onChange: (value: string) => void;
31+
};
32+
33+
export function renderModelPicker(params: ModelPickerParams) {
34+
let customValue = "__openclaw_custom_model__";
35+
const values = new Set([params.value, ...params.options.map((option) => option.value)]);
36+
while (values.has(customValue)) {
37+
customValue += "_";
38+
}
39+
const currentIsKnown = params.options.some((option) => option.value === params.value);
40+
const options: Array<ModelPickerOption & { description?: string }> = [
41+
...params.options.map((option) => ({ ...option, description: option.detail })),
42+
...(params.custom ? [{ value: customValue, label: params.custom.label }] : []),
43+
];
44+
return html`
45+
<div class="model-picker">
46+
${renderPicker({
47+
id: params.id,
48+
label: params.label,
49+
value: params.value,
50+
options,
51+
disabled: params.disabled,
52+
title: params.title,
53+
placement: params.placement,
54+
className: `model-picker__select ${params.className ?? ""}`,
55+
renderLeading: (option) =>
56+
option.provider
57+
? renderProviderBrandIcon(option.provider, { className: "model-picker__provider-icon" })
58+
: nothing,
59+
onChange: params.onChange,
60+
onChangeTarget: (value, select) => {
61+
const wrapper = select.closest(".model-picker");
62+
const input = wrapper?.querySelector<HTMLInputElement>(".model-picker__custom");
63+
if (value === customValue && input) {
64+
input.hidden = false;
65+
queueMicrotask(() => input.focus());
66+
return;
67+
}
68+
if (input) {
69+
input.hidden = true;
70+
}
71+
params.onChange(value);
72+
},
73+
})}
74+
${params.custom
75+
? html`<input
76+
id=${params.custom.id ?? nothing}
77+
class="settings-input model-picker__custom"
78+
aria-label=${params.custom.label}
79+
aria-invalid=${params.custom.invalid ? "true" : "false"}
80+
aria-describedby=${params.custom.describedBy ?? nothing}
81+
placeholder=${params.custom.placeholder ?? ""}
82+
.value=${params.value}
83+
?hidden=${currentIsKnown}
84+
?disabled=${params.disabled}
85+
@input=${(event: InputEvent) => {
86+
if (params.custom?.commit !== "change") {
87+
params.onChange((event.currentTarget as HTMLInputElement).value);
88+
}
89+
}}
90+
@change=${(event: Event) => {
91+
if (params.custom?.commit === "change") {
92+
params.onChange((event.currentTarget as HTMLInputElement).value);
93+
}
94+
}}
95+
/>`
96+
: nothing}
97+
</div>
98+
`;
99+
}

‎ui/src/components/select-picker.ts‎

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { html, nothing } from "lit";
2+
import "./web-awesome-select.ts";
3+
4+
export type PickerOption = {
5+
value: string;
6+
label: string;
7+
description?: string;
8+
disabled?: boolean;
9+
};
10+
11+
export type PickerParams<Option extends PickerOption> = {
12+
id?: string;
13+
label: string;
14+
value: string | null;
15+
options: readonly Option[];
16+
disabled?: boolean;
17+
className?: string;
18+
title?: string;
19+
placement?: "top" | "bottom";
20+
onChange: (value: string) => void;
21+
onChangeTarget?: (value: string, select: HTMLElement) => void;
22+
renderLeading?: (option: Option) => unknown;
23+
};
24+
25+
export function renderPicker<Option extends PickerOption>(params: PickerParams<Option>) {
26+
const options =
27+
params.value === null ||
28+
params.value === "" ||
29+
params.options.some((option) => option.value === params.value)
30+
? params.options
31+
: [...params.options, { value: params.value, label: params.value } as Option];
32+
const leading = (option: Option | undefined) => {
33+
const content = option && params.renderLeading?.(option);
34+
return content === undefined || content === null || content === nothing
35+
? nothing
36+
: html`<span slot="start">${content}</span>`;
37+
};
38+
return html`
39+
<wa-select
40+
id=${params.id ?? nothing}
41+
class=${`settings-select picker-select ${params.className ?? ""}`}
42+
style="width:100%;min-width:0"
43+
title=${params.title ?? nothing}
44+
placement=${params.placement ?? nothing}
45+
.value=${params.value}
46+
?disabled=${params.disabled}
47+
@change=${(event: Event) => {
48+
const value = (event.currentTarget as HTMLElement & { value?: unknown }).value;
49+
const option = typeof value === "string" && options.find((entry) => entry.value === value);
50+
if (option && !option.disabled) {
51+
if (params.onChangeTarget) {
52+
params.onChangeTarget(value, event.currentTarget as HTMLElement);
53+
} else {
54+
params.onChange(value);
55+
}
56+
}
57+
}}
58+
>
59+
<span slot="label" class="settings-control__sr-label">${params.label}</span>
60+
${leading(options.find((option) => option.value === params.value))}
61+
${options.map(
62+
(option) => html`
63+
<wa-option
64+
class="picker-select__option"
65+
value=${option.value}
66+
.label=${option.label}
67+
?selected=${option.value === params.value}
68+
?disabled=${option.disabled}
69+
>
70+
${leading(option)}
71+
<span class="picker-select__copy">
72+
<span class="picker-select__label">${option.label}</span>
73+
${option.description
74+
? html`<span class="picker-select__description">${option.description}</span>`
75+
: nothing}
76+
</span>
77+
</wa-option>
78+
`,
79+
)}
80+
</wa-select>
81+
`;
82+
}

‎ui/src/components/web-awesome-migration.node.test.ts‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@ describe("Web Awesome control ownership", () => {
4040
).toEqual([]);
4141
expect(
4242
await matchingFiles(/<details\b[^>]*class=["'][^"']*(?:menu|select|popover|dropdown)/u),
43-
).toEqual([
44-
"pages/chat/components/chat-effort-picker.ts",
45-
"pages/chat/components/chat-model-picker.ts",
46-
]);
43+
).toEqual(["pages/chat/components/chat-effort-picker.ts"]);
4744
});
4845

4946
it("limits custom comboboxes to dynamic suggestion surfaces", async () => {
@@ -53,7 +50,6 @@ describe("Web Awesome control ownership", () => {
5350
"components/command-palette.ts",
5451
"pages/chat/components/chat-composer-skill-menu.ts",
5552
"pages/chat/components/chat-composer-slash-menu.ts",
56-
"pages/chat/components/chat-model-picker.ts",
5753
]);
5854
});
5955

0 commit comments

Comments
 (0)