Skip to content

Commit 50c7400

Browse files
feat(ui): refine the mobile composer (#130308)
* feat(ui): refine the mobile composer * fix(ui): preserve mobile composer controls * fix(ui): keep mobile composer gates stable * perf(ui): lazy-load chat goal styles
1 parent 3fe6e58 commit 50c7400

22 files changed

Lines changed: 1209 additions & 345 deletions

‎ui/src/components/icons-tools.ts‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,6 @@ export const toolIcons = {
244244
d="M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49M14.084 14.158a3 3 0 0 1-4.242-4.242M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143M2 2l20 20"
245245
/>`,
246246
),
247-
moreHorizontal: strokeIcon(svg` <circle cx="12" cy="12" r="1.5" />
248-
<circle cx="6" cy="12" r="1.5" />
249-
<circle cx="18" cy="12" r="1.5" />`),
250247
arrowUpDown: strokeIcon(svg`<path d="M21 16l-4 4-4-4M17 20V4M3 8l4-4 4 4M7 4v16" />`),
251248
panelRightOpen: strokeIcon(svg` <rect x="3" y="3" width="18" height="18" rx="2" />
252249
<path d="M15 3v18M10 10l-3 2 3 2" />`),

‎ui/src/components/icons.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,12 @@ export const icons = {
301301
<circle cx="15" cy="18" r="1.1" fill="currentColor" stroke="none" />`),
302302
arrowDown: strokeIcon(svg`<path d="M12 5v14m7-7-7 7-7-7" />`),
303303
arrowUp: strokeIcon(svg`<path d="M12 19V5m-7 7 7-7 7 7" />`),
304+
audioLines: strokeIcon(svg`<path d="M2 10v3" />
305+
<path d="M6 6v11" />
306+
<path d="M10 3v18" />
307+
<path d="M14 8v7" />
308+
<path d="M18 5v13" />
309+
<path d="M22 10v3" />`),
304310
chevronUp: strokeIcon(svg`<path d="m18 15-6-6-6 6" />`),
305311
chevronsUpDown: strokeIcon(svg`<path d="m7 15 5 5 5-5" />
306312
<path d="m7 9 5-5 5 5" />`),
@@ -351,6 +357,9 @@ export const icons = {
351357
<path d="M13 6h8" />
352358
<path d="M13 12h8" />
353359
<path d="M13 18h8" />`),
360+
moreHorizontal: strokeIcon(svg` <circle cx="5" cy="12" r="1" />
361+
<circle cx="12" cy="12" r="1" />
362+
<circle cx="19" cy="12" r="1" />`),
354363
...toolIcons,
355364
} as const;
356365

‎ui/src/e2e/browser-dictation-status.e2e.test.ts‎

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -236,27 +236,9 @@ suite.define(() => {
236236
await installTalkBrowserFixtures(page);
237237
await page.goto(`${suite.server.baseUrl}chat`);
238238

239-
const microphone = page.getByRole("button", { name: "Start voice input" });
240-
const microphoneBox = await microphone.boundingBox();
241-
expect(microphoneBox).not.toBeNull();
242-
if (!microphoneBox) {
243-
throw new Error("expected microphone layout box");
244-
}
245-
await page.mouse.move(
246-
microphoneBox.x + microphoneBox.width / 2,
247-
microphoneBox.y + microphoneBox.height / 2,
248-
);
249-
await page.mouse.down();
250-
await page.waitForTimeout(350);
251-
await expect
252-
.poll(() => microphone.getAttribute("class"))
253-
.toContain("chat-send-btn--dictation-arming");
254-
await page.screenshot({
255-
animations: "allow",
256-
path: ".artifacts/control-ui-e2e/voice-controls/dictation-hold-ring.png",
257-
});
239+
const microphone = page.getByRole("button", { name: "Dictation" });
240+
await microphone.click();
258241
await gateway.waitForRequest("talk.session.create");
259-
await page.mouse.up();
260242

261243
const composer = page.locator(".agent-chat__input--dictating");
262244
const phase = composer.locator(".agent-chat__dictation-phase");
@@ -290,7 +272,7 @@ suite.define(() => {
290272
expect(box.x + box.width).toBeLessThanOrEqual(composerBox.x + composerBox.width);
291273
}
292274

293-
await page.keyboard.press("Escape");
275+
await stop.click();
294276
await expect.poll(() => microphone.isVisible()).toBe(true);
295277
},
296278
);

‎ui/src/e2e/browser-talk-start-stop.e2e.test.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ suite.define(() => {
5656
await microphoneSelect.selectOption("usb");
5757
await page.goto(`${suite.server.baseUrl}chat`);
5858
await page.setViewportSize({ width: 320, height: 720 });
59-
await page.getByRole("button", { name: "Start voice input" }).click();
59+
await page.getByRole("button", { name: "Tap to talk" }).click();
6060

6161
const createRequest = await gateway.waitForRequest("talk.client.create");
6262
expect(createRequest.params).toMatchObject({ sessionKey: "main" });
@@ -168,7 +168,7 @@ suite.define(() => {
168168

169169
await page.getByRole("button", { name: "Stop voice input" }).click();
170170
await expect
171-
.poll(() => page.getByRole("button", { name: "Start voice input" }).isVisible())
171+
.poll(() => page.getByRole("button", { name: "Tap to talk" }).isVisible())
172172
.toBe(true);
173173
await expect.poll(() => page.locator(".agent-chat__voice-activity").count()).toBe(0);
174174
await expect
@@ -191,7 +191,7 @@ suite.define(() => {
191191

192192
await gateway.deliverLatest({ setupComplete: {} });
193193
await expect
194-
.poll(() => page.getByRole("button", { name: "Start voice input" }).isVisible())
194+
.poll(() => page.getByRole("button", { name: "Tap to talk" }).isVisible())
195195
.toBe(true);
196196
console.info("[video-talk-e2e] ordinary_voice=start-stop-passed");
197197
});
@@ -1039,7 +1039,7 @@ suite.define(() => {
10391039

10401040
await page.setViewportSize({ width: 320, height: 720 });
10411041
await page.goto(`${suite.server.baseUrl}chat`);
1042-
await page.getByRole("button", { name: "Start voice input" }).click();
1042+
await page.getByRole("button", { name: "Tap to talk" }).click();
10431043
await gateway.waitForRequest("talk.client.create");
10441044

10451045
await expect
@@ -1049,7 +1049,7 @@ suite.define(() => {
10491049
.poll(() => gateway.getRequests("talk.session.close").then((requests) => requests.length))
10501050
.toBe(1);
10511051
await expect
1052-
.poll(() => page.getByRole("button", { name: "Start voice input" }).isVisible())
1052+
.poll(() => page.getByRole("button", { name: "Tap to talk" }).isVisible())
10531053
.toBe(true);
10541054
});
10551055
});

‎ui/src/e2e/chat-composer-redesign.e2e.test.ts‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ suite.define(() => {
224224
const settings = page.locator(".chat-header-session-menu__trigger");
225225
const splitView = page.getByRole("button", { name: "Open split view" });
226226
const voice = page.getByRole("button", { name: "Start voice input" });
227+
const mobileDictation = page.getByRole("button", { name: "Dictation" });
227228
const microphonePicker = page.getByRole("button", { name: "Microphone input" });
228229
const microphonePickerShell = page.locator(".chat-talk-input-picker");
229230
const captureMobileState = async (fileName: string) => {
@@ -632,20 +633,18 @@ suite.define(() => {
632633
await expect.poll(() => stop.count()).toBe(0);
633634

634635
await textarea.fill("");
635-
await expect
636-
.poll(() => page.getByRole("button", { name: "Start voice input" }).isVisible())
637-
.toBe(true);
638-
await expect.poll(() => emptySend.isVisible()).toBe(true);
639-
await expect.poll(() => emptySend.isDisabled()).toBe(true);
636+
await expect.poll(() => mobileDictation.isVisible()).toBe(true);
637+
const mobileTalk = page.getByRole("button", { name: "Tap to talk" });
638+
await expect.poll(() => mobileTalk.isVisible()).toBe(true);
640639
await captureMobileState("mobile-composer-idle.png");
641640
// Send holds its place with nothing to send: it goes unavailable rather
642641
// than disappearing, so the composer never looks like it lost the control
643642
// that commits a turn.
644643
await expect
645644
.poll(async () => {
646645
const [voiceRect, sendRect] = await Promise.all([
647-
voice.boundingBox(),
648-
emptySend.boundingBox(),
646+
mobileDictation.boundingBox(),
647+
mobileTalk.boundingBox(),
649648
]);
650649
return voiceRect && sendRect ? sendRect.x - (voiceRect.x + voiceRect.width) : null;
651650
})
@@ -683,7 +682,7 @@ suite.define(() => {
683682
mobileModelSettings.boundingBox(),
684683
settings.boundingBox(),
685684
contextUsage.boundingBox(),
686-
voice.boundingBox(),
685+
mobileDictation.boundingBox(),
687686
]);
688687
expect(mobileAttachBox).not.toBeNull();
689688
expect(mobileModelSettingsBox).not.toBeNull();
@@ -724,7 +723,7 @@ suite.define(() => {
724723
.poll(async () => {
725724
const [polledAttachBox, polledVoiceBox] = await Promise.all([
726725
attach.boundingBox(),
727-
voice.boundingBox(),
726+
mobileDictation.boundingBox(),
728727
]);
729728
if (!polledAttachBox || !polledVoiceBox) {
730729
return Number.POSITIVE_INFINITY;

‎ui/src/e2e/new-session-page.places.e2e.test.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,7 @@ suite.define(() => {
311311
}
312312
expect(mobileModelSettingsBox.width).toBeGreaterThanOrEqual(44);
313313
expect(mobileModelSettingsBox.height).toBeGreaterThanOrEqual(44);
314-
expect(mobileModelSettingsBox.x).toBeGreaterThan(
315-
mobileFooterBox.x + mobileFooterBox.width / 2,
316-
);
314+
expect(mobileModelSettingsBox.x).toBeGreaterThanOrEqual(mobileFooterBox.x);
317315
expect(mobileModelSettingsBox.x + mobileModelSettingsBox.width).toBeLessThanOrEqual(
318316
mobileFooterBox.x + mobileFooterBox.width,
319317
);

‎ui/src/e2e/new-session-page.workspace-memory.e2e.test.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ suite.define(() => {
126126
const footer = page.locator(".new-session-page__composer .agent-chat__composer-footer");
127127
const attach = page.getByRole("button", { name: "Add attachment" });
128128
const takePhoto = page.getByRole("menuitem", { name: "Take photo" });
129-
const draft = page.locator('.new-session-page__visibility--draft[aria-label="Draft"]');
129+
const draft = page.locator('.new-session-page__draft-toggle[aria-label^="Draft:"]');
130130
const incognito = page.getByRole("switch", { name: "Incognito" });
131131
const model = page.locator(".new-session-page__composer .chat-composer-model-control");
132132
await Promise.all([
@@ -178,13 +178,13 @@ suite.define(() => {
178178
const sameLine = Math.abs(nextCenter - previousCenter) <= previous.height / 2;
179179
return sameLine ? next.x > previous.x : nextCenter > previousCenter;
180180
};
181-
const sequence = [attachBox, draftBox, modelBox];
181+
const sequence = [attachBox, modelBox];
182182
for (let index = 1; index < sequence.length; index += 1) {
183183
expect(followsInReadingOrder(sequence[index - 1] ?? null, sequence[index] ?? null)).toBe(
184184
true,
185185
);
186186
}
187-
for (const control of [attachBox, draftBox, modelBox]) {
187+
for (const control of [attachBox, modelBox]) {
188188
expect(control?.x ?? 0).toBeGreaterThanOrEqual(footerBox?.x ?? 0);
189189
expect((control?.x ?? 0) + (control?.width ?? 0)).toBeLessThanOrEqual(
190190
(footerBox?.x ?? 0) + (footerBox?.width ?? 0),

‎ui/src/pages/chat/chat-composer-actions.test.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,13 +244,30 @@ describe("renderChatComposer controls", () => {
244244
expect(stopVoice.classList.contains("chat-send-btn--voice-live")).toBe(true);
245245
expect(stopVoice.classList.contains("chat-send-btn--stop")).toBe(false);
246246
expect(stopGeneration.classList.contains("chat-send-btn--stop")).toBe(true);
247+
expect(stopGeneration.closest(".chat-mobile-primary-action")).not.toBeNull();
247248
expect(container.querySelectorAll(".chat-send-btn--stop")).toHaveLength(1);
248249
stopVoice.click();
249250
stopGeneration.click();
250251
expect(onToggleRealtimeTalk).toHaveBeenCalledOnce();
251252
expect(onAbort).toHaveBeenCalledOnce();
252253
});
253254

255+
it("keeps mobile voice controls disabled while the composer is busy", () => {
256+
const { container } = renderComposer({
257+
sending: true,
258+
onToggleRealtimeTalk: vi.fn(),
259+
});
260+
261+
const mobileDictation = container.querySelector<HTMLButtonElement>(
262+
".chat-mobile-dictation-action .chat-send-btn--voice",
263+
);
264+
expect(mobileDictation?.disabled).toBe(true);
265+
expect(
266+
container.querySelector<HTMLButtonElement>(".chat-mobile-talk-action .chat-send-btn")
267+
?.disabled,
268+
).toBe(true);
269+
});
270+
254271
it("queues ordinary drafts offline but disables live voice", () => {
255272
const onSend = vi.fn();
256273
let view = renderComposer({ connected: false, draft: "queue this", onSend });

‎ui/src/pages/chat/chat-composer.test-support.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,15 @@ export function findComposerButton(container: Element, label: string): HTMLButto
4646

4747
export function findPrimaryButton(container: Element): HTMLButtonElement {
4848
const actions = container.querySelector(".agent-chat__composer-actions");
49-
const result = actions?.querySelector<HTMLButtonElement>(":scope > openclaw-tooltip > button");
49+
const result = actions?.querySelector<HTMLButtonElement>(
50+
":scope > .chat-desktop-primary-action > openclaw-tooltip > button",
51+
);
5052
if (!result) {
5153
throw new Error("expected one primary composer button");
5254
}
53-
expect(actions?.querySelectorAll(":scope > openclaw-tooltip > button")).toHaveLength(1);
55+
expect(
56+
actions?.querySelectorAll(":scope > .chat-desktop-primary-action > openclaw-tooltip > button"),
57+
).toHaveLength(1);
5458
return result;
5559
}
5660

‎ui/src/pages/chat/components/chat-composer-controls.ts‎

Lines changed: 63 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,42 @@ export function renderChatPrimaryActions(props: ChatRunControlsProps) {
475475
// the control shows whenever either route exists, and it always sits ahead of
476476
// the primary action rather than standing in for it.
477477
const voiceControl = props.dictation || props.onToggleVoice ? voiceButton : nothing;
478+
const mobileDictationControl = props.dictation
479+
? html`
480+
<span class="chat-mobile-dictation-action">
481+
${renderComposerVoiceButton({
482+
connected: props.connected,
483+
sending: props.sending,
484+
isBusy: props.isBusy,
485+
dictation: props.dictation,
486+
idleLabel: t("chat.composer.dictationCapability"),
487+
})}
488+
</span>
489+
`
490+
: nothing;
491+
const mobileTalkAction =
492+
!hasComposedContent && !props.dictation?.active && props.onToggleVoice
493+
? html`
494+
<openclaw-tooltip
495+
class="chat-mobile-talk-action"
496+
.content=${t("chat.composer.realtimeTalkCapability")}
497+
>
498+
<button
499+
class="chat-send-btn chat-send-btn--talk-mode"
500+
type="button"
501+
@pointerdown=${props.onPrimaryActionPointerDown}
502+
@click=${props.onToggleVoice}
503+
?disabled=${!props.connected || props.sending || props.isBusy}
504+
aria-label=${t("chat.composer.realtimeTalkCapability")}
505+
>
506+
${icons.audioLines}
507+
<span class="agent-chat__control-label"
508+
>${t("chat.composer.realtimeTalkCapability")}</span
509+
>
510+
</button>
511+
</openclaw-tooltip>
512+
`
513+
: nothing;
478514
// Send holds the trailing edge whatever the draft is. During an active run the
479515
// same slot shows stop while empty, then becomes the follow-up action as soon
480516
// as the operator composes content; two competing primary buttons never render.
@@ -512,6 +548,31 @@ export function renderChatPrimaryActions(props: ChatRunControlsProps) {
512548
props.onPrimaryActionPointerDown,
513549
)
514550
: nothing;
551+
const desktopPrimaryAction = props.dictation?.active
552+
? dictationSendAction
553+
: props.canAbort
554+
? hasComposedContent
555+
? sendAction
556+
: abortAction
557+
: sendAction;
558+
const mobilePrimaryAction = props.dictation?.active
559+
? dictationSendAction
560+
: hasComposedContent
561+
? sendAction
562+
: props.canAbort
563+
? abortAction
564+
: props.onToggleVoice
565+
? mobileTalkAction
566+
: sendAction;
567+
const primaryActions =
568+
mobilePrimaryAction === desktopPrimaryAction
569+
? html`<span class="chat-mobile-primary-action chat-desktop-primary-action"
570+
>${desktopPrimaryAction}</span
571+
>`
572+
: html`
573+
<span class="chat-mobile-primary-action">${mobilePrimaryAction}</span>
574+
<span class="chat-desktop-primary-action">${desktopPrimaryAction}</span>
575+
`;
515576
return html`
516577
${props.voiceActive && props.onToggleVoice
517578
? html`
@@ -574,17 +635,8 @@ export function renderChatPrimaryActions(props: ChatRunControlsProps) {
574635
</openclaw-tooltip>
575636
`
576637
: nothing}
577-
${abortAction}
638+
<span class="chat-mobile-primary-action chat-desktop-primary-action">${abortAction}</span>
578639
`
579-
: html`
580-
${voiceControl}
581-
${props.dictation?.active
582-
? dictationSendAction
583-
: props.canAbort
584-
? hasComposedContent
585-
? sendAction
586-
: abortAction
587-
: sendAction}
588-
`}
640+
: html` ${voiceControl} ${mobileDictationControl} ${primaryActions} `}
589641
`;
590642
}

0 commit comments

Comments
 (0)