Skip to content

Your lightweight open-source personal agent.

fix(webui): adapt chat toolbar to available width (#5760)

chengyongruf611c880f991
diff --git a/webui/src/components/thread/ThreadHeader.tsx b/webui/src/components/thread/ThreadHeader.tsx
index ba1cf4dab..18f13f565 100644
--- a/webui/src/components/thread/ThreadHeader.tsx
+++ b/webui/src/components/thread/ThreadHeader.tsx
@@ -13,6 +13,12 @@ import {
import { cn } from "@/lib/utils";
import type { SessionHandle } from "@/lib/types";
+const controlsClassName = cn(
+ "pointer-events-auto flex items-center gap-0.5 rounded-compact bg-background p-px empty:hidden",
+ "[&_button]:h-7 [&_button]:w-7 [&_button>svg]:h-3.5 [&_button>svg]:w-3.5",
+ "forced-colors:bg-[Canvas] forced-colors:outline forced-colors:outline-1 forced-colors:outline-[ButtonText]",
+);
+
interface ThreadHeaderProps {
title: string;
handle?: SessionHandle | null;
@@ -56,11 +62,18 @@ export function ThreadHeader({
<div
data-testid="thread-header"
className={cn(
- "relative z-30 flex items-center justify-between gap-3 px-3 py-1",
+ "pointer-events-none inset-x-0 top-0 z-30 flex shrink-0 items-center justify-between gap-3 px-3 py-1",
+ "[position:var(--thread-header-position,absolute)]",
minimal && "h-11",
)}
>
- <div className="relative flex min-w-0 items-center gap-2">
+ <div
+ className={cn(
+ controlsClassName,
+ "relative min-w-0",
+ hideSidebarToggleForHostChrome && (minimal || hideTitle) && !handle && "lg:hidden",
+ )}
+ >
{!hideSidebarToggle ? (
<Button
variant="ghost"
@@ -91,7 +104,7 @@ export function ThreadHeader({
) : null}
</div>
- <div className="ml-auto flex shrink-0 items-center gap-1">
+ <div className={cn(controlsClassName, "ml-auto shrink-0")}>
{sessionInfoAction}
{promptNavigatorAction}
{actions}
@@ -151,10 +164,6 @@ export function ThreadHeader({
/>
) : null}
</div>
-
- {!minimal ? (
- <div aria-hidden className="pointer-events-none absolute inset-x-0 top-full h-4" />
- ) : null}
</div>
);
}
diff --git a/webui/src/components/thread/ThreadShell.tsx b/webui/src/components/thread/ThreadShell.tsx
index a5b6739fd..3604df192 100644
--- a/webui/src/components/thread/ThreadShell.tsx
+++ b/webui/src/components/thread/ThreadShell.tsx
@@ -55,6 +55,7 @@ import type {
} from "@/lib/types";
import { projectWebuiThreadMessages } from "@/lib/thread-display-compat";
import { ThreadMessageCache } from "@/lib/thread-message-cache";
+import { cn } from "@/lib/utils";
import { useClient } from "@/providers/ClientProvider";
type MessageShape = Pick<UIMessage, "role" | "kind" | "content" | "isStreaming" | "turnId">;
@@ -1693,7 +1694,10 @@ export function ThreadShell({
return (
<section ref={shellRef} className="relative flex min-h-0 flex-1 overflow-hidden">
- <div className="relative flex min-w-0 flex-1 flex-col overflow-hidden">
+ <div className={cn(
+ "relative flex min-w-0 flex-1 flex-col overflow-hidden",
+ headerPortalTarget === undefined && !hideHeader && "thread-workspace",
+ )}>
{hideHeaderTitle && inlineHandle && !temporary && session?.handle ? (
<div
aria-label={`Session @${session.handle.name}`}
diff --git a/webui/src/components/thread/ThreadViewport.tsx b/webui/src/components/thread/ThreadViewport.tsx
index 73d4f2e5b..b62b05f3b 100644
--- a/webui/src/components/thread/ThreadViewport.tsx
+++ b/webui/src/components/thread/ThreadViewport.tsx
@@ -64,6 +64,7 @@ interface ThreadViewportProps {
}
const NEAR_BOTTOM_PX = 48;
+const PROMPT_TOP_INSET_PX = 48;
const HISTORY_PREFETCH_MIN_PX = 160;
const HISTORY_PREFETCH_MAX_PX = 480;
const DEFAULT_SCROLL_BUTTON_BOTTOM_PX = 192;
@@ -83,6 +84,11 @@ interface HistoryScrollAnchor {
const THREAD_DISPLAY_UNIT_SELECTOR = "[data-thread-display-unit]";
+function promptTopInset(scroller: HTMLElement): number {
+ const padding = Number.parseFloat(getComputedStyle(scroller).paddingTop);
+ return Number.isFinite(padding) ? padding : PROMPT_TOP_INSET_PX;
+}
+
function historyPrefetchDistance(scroller: HTMLElement): number {
return Math.min(
HISTORY_PREFETCH_MAX_PX,
@@ -297,7 +303,7 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
promptTop: prompt
? Math.min(
maxScrollTop,
- Math.max(0, promptTop(scrollEl, prompt) - 16),
+ Math.max(0, promptTop(scrollEl, prompt) - promptTopInset(scrollEl)),
)
: null,
};
@@ -477,7 +483,7 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
threadMotionRef.current?.navigateHistoryTo(
Math.min(
maxScrollTop,
- Math.max(0, promptTop(scrollEl, prompt) - 16),
+ Math.max(0, promptTop(scrollEl, prompt) - promptTopInset(scrollEl)),
),
);
return true;
@@ -871,7 +877,7 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
data-testid="thread-message-region"
className={cn(
"thread-message-viewport thread-viewport-scrollbar row-start-1 flex min-h-0 min-w-0 flex-col",
- "scroll-auto justify-start overflow-x-hidden px-3 pb-0 pt-3 sm:px-4",
+ "scroll-auto justify-start overflow-x-hidden px-3 pb-0 pt-[var(--thread-prompt-inset,3rem)] sm:px-4",
"[overflow-anchor:none] [scrollbar-width:none]",
"[&::-webkit-scrollbar]:hidden",
hasVerticalOverflow ? "overflow-y-auto" : "overflow-hidden",
@@ -968,11 +974,6 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
{!hasMessages ? <div ref={bottomRef} aria-hidden className="h-px" /> : null}
</div>
- <div
- aria-hidden
- className="pointer-events-none absolute inset-x-0 top-0 h-3 bg-gradient-to-b from-background to-transparent"
- />
-
{hasMessages ? (
<PromptRail
messages={visibleMessages}
diff --git a/webui/src/components/workbench/PaneWorkbench.tsx b/webui/src/components/workbench/PaneWorkbench.tsx
index 51f5ade47..d976b8893 100644
--- a/webui/src/components/workbench/PaneWorkbench.tsx
+++ b/webui/src/components/workbench/PaneWorkbench.tsx
@@ -685,11 +685,15 @@ export function PaneWorkbench({
return (
<section
aria-label={t("workbench.aria", { defaultValue: "Conversation workbench" })}
- className="flex h-full min-h-0 flex-col overflow-hidden bg-background"
+ className={cn(
+ "thread-workspace relative flex h-full min-h-0 flex-col overflow-hidden bg-background",
+ chrome && displayedPanes.length > 1
+ && "[--thread-header-position:relative] [--thread-prompt-inset:1rem]",
+ )}
>
<TooltipProvider>
{chrome ? (
- <header className="shrink-0 bg-background">
+ <header className="pointer-events-none inset-x-0 top-0 z-30 shrink-0 [position:var(--thread-header-position,absolute)]">
<div
ref={setHeaderPortalTarget}
data-testid="workbench-header-host"
diff --git a/webui/src/globals.css b/webui/src/globals.css
index 3b633c7ac..dccf1d491 100644
--- a/webui/src/globals.css
+++ b/webui/src/globals.css
@@ -604,6 +604,17 @@
}
}
+ .thread-workspace {
+ container: thread-workspace / inline-size;
+ }
+ /* Keep room for the 49.5rem message column and controls in the side margin. */
+ @container thread-workspace (max-width: 72rem) {
+ .thread-workspace > * {
+ --thread-header-position: relative;
+ --thread-prompt-inset: 1rem;
+ }
+ }
+
.workbench-pane {
transform-origin: top left;
}
diff --git a/webui/src/tests/thread-viewport.test.tsx b/webui/src/tests/thread-viewport.test.tsx
index d6139cbc6..093a43ebf 100644
--- a/webui/src/tests/thread-viewport.test.tsx
+++ b/webui/src/tests/thread-viewport.test.tsx
@@ -279,7 +279,6 @@ describe("ThreadViewport", () => {
expect(messageRegion).toHaveClass("justify-start");
expect(messageRegion).not.toHaveClass("justify-end");
expect(messageRegion).toHaveClass("thread-message-viewport");
- expect(messageRegion).toHaveClass("pt-3");
expect(messageRegion).toHaveClass("pb-0");
expect(messageRegion.className).not.toContain("5rem");
});
@@ -573,7 +572,7 @@ describe("ThreadViewport", () => {
});
await flushAnimationFrame();
- expect(jumpTo).toHaveBeenCalledWith(1404);
+ expect(jumpTo).toHaveBeenCalledWith(1372);
});
it("drives the camera from a message commit when canonical replay replaces the prompt DOM id", async () => {
@@ -1681,7 +1680,7 @@ describe("ThreadViewport", () => {
fireEvent.click(targetPrompt);
- expect(navigateTo).toHaveBeenCalledWith(1064);
+ expect(navigateTo).toHaveBeenCalledWith(1032);
});
it("renders markdown in prompt rail previews", async () => {
@@ -1855,14 +1854,29 @@ describe("ThreadViewport", () => {
expect(markers).toHaveLength(count);
markers.forEach((marker, index) => {
fireEvent.click(marker);
- expect(navigateTo).toHaveBeenLastCalledWith(Math.max(0, index * 40 - 16));
+ expect(navigateTo).toHaveBeenLastCalledWith(Math.max(0, index * 40 - 48));
});
} else {
expect(markers.length).toBeGreaterThan(1);
expect(markers.length).toBeLessThan(count);
}
fireEvent.click(markers[markers.length - 1]);
- expect(navigateTo).toHaveBeenLastCalledWith((count - 1) * 40 - 16);
+ expect(navigateTo).toHaveBeenLastCalledWith(Math.max(0, (count - 1) * 40 - 48));
+ });
+
+ it("keeps prompt jumps aligned when the header changes between a row and an overlay", async () => {
+ const navigateTo = vi.spyOn(ThreadCameraController.prototype, "navigateTo")
+ .mockReturnValue("started");
+ const { scroller } = await renderPromptRailViewport();
+ const marker = screen.getByRole("button", { name: "Jump to prompt: message 1" });
+
+ scroller.style.paddingTop = "16px";
+ fireEvent.click(marker);
+ expect(navigateTo).toHaveBeenLastCalledWith(344);
+
+ scroller.style.paddingTop = "48px";
+ fireEvent.click(marker);
+ expect(navigateTo).toHaveBeenLastCalledWith(312);
});
it("buckets dense prompt rails without rendering every prompt as a marker", async () => {
@@ -1913,7 +1927,7 @@ describe("ThreadViewport", () => {
fireEvent.click(promptMarkers[promptMarkers.length - 1]);
- expect(navigateTo).toHaveBeenCalledWith(8894);
+ expect(navigateTo).toHaveBeenCalledWith(8862);
});
it("expands the window start to avoid cutting an agent activity cluster", () => {