Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat: responsive agent window (#21638)

ecmadao82e471dfdbd7
diff --git a/frontend/src/modules/agent/components/AgentChat.test.tsx b/frontend/src/modules/agent/components/AgentChat.test.tsx
index 48ca0a709e..0f12c47e43 100644
--- a/frontend/src/modules/agent/components/AgentChat.test.tsx
+++ b/frontend/src/modules/agent/components/AgentChat.test.tsx
@@ -93,7 +93,6 @@ beforeEach(async () => {
const initialState = createAgentStore().getState();
useAgentStore.setState({
visible: initialState.visible,
- position: initialState.position,
size: initialState.size,
sidebarWidth: initialState.sidebarWidth,
minimized: initialState.minimized,
diff --git a/frontend/src/modules/agent/components/AgentInput.test.tsx b/frontend/src/modules/agent/components/AgentInput.test.tsx
index 0d27d69aa6..05980bf202 100644
--- a/frontend/src/modules/agent/components/AgentInput.test.tsx
+++ b/frontend/src/modules/agent/components/AgentInput.test.tsx
@@ -269,6 +269,21 @@ afterEach(() => {
});
describe("AgentInput", () => {
+ test("uses a growing textarea without a row cap", () => {
+ const { container, render, unmount } = renderIntoContainer(<AgentInput />);
+
+ render();
+
+ const textarea = container.querySelector(
+ 'textarea[aria-label="agent.input-placeholder"]'
+ );
+ expect(textarea).toBeInstanceOf(HTMLTextAreaElement);
+ expect(textarea?.className).toContain("min-h-9");
+ expect(textarea?.className).not.toContain("max-h-");
+
+ unmount();
+ });
+
test("shows the send and newline keyboard hint only in the empty input placeholder", () => {
const view = renderIntoContainer(<AgentInput />);
view.render();
@@ -1334,23 +1349,18 @@ describe("AgentInput", () => {
unmount();
});
- test("uses the same single-line height for the textarea and send button", () => {
+ test("uses a one-line textarea starting size beside the send button", () => {
const { container, render, unmount } = renderIntoContainer(<AgentInput />);
render();
const row = container.querySelector("[data-agent-input-row]");
expect(row?.className).toContain("items-end");
- expect(container.querySelector("textarea")?.className).toContain(
- "h-9"
- );
- expect(container.querySelector("textarea")?.className).toContain(
- "min-h-9"
- );
- expect(container.querySelector("textarea")?.className).toContain(
- "max-h-[134px]"
- );
- expect(container.querySelector("textarea")?.className).toContain("block");
+ const textarea = container.querySelector("textarea");
+ expect(textarea).toBeInstanceOf(HTMLTextAreaElement);
+ expect(textarea?.className).toContain("h-9");
+ expect(textarea?.className).toContain("min-h-9");
+ expect(textarea?.className).not.toContain("max-h-");
expect(container.querySelector("[data-agent-send]")?.className).toContain(
"h-9"
);
@@ -1358,53 +1368,44 @@ describe("AgentInput", () => {
unmount();
});
- test("sizes from CSS min/max heights and enables scrolling only at max height", () => {
+ test("keeps pasted line breaks in the textarea", () => {
const { container, render, unmount } = renderIntoContainer(<AgentInput />);
render();
- const textarea = container.querySelector("textarea");
- expect(textarea).toBeInstanceOf(HTMLTextAreaElement);
-
- const element = textarea as HTMLTextAreaElement;
- let scrollHeight = 32;
- Object.defineProperty(element, "scrollHeight", {
- configurable: true,
- get: () => scrollHeight,
- });
- Object.defineProperty(element, "offsetHeight", {
- configurable: true,
- get: () => 34,
- });
- Object.defineProperty(element, "clientHeight", {
- configurable: true,
- get: () => 32,
- });
- const getComputedStyleSpy = vi
- .spyOn(window, "getComputedStyle")
- .mockReturnValue({
- minHeight: "34px",
- maxHeight: "134px",
- } as CSSStyleDeclaration);
+ const textarea = container.querySelector("textarea") as HTMLTextAreaElement;
act(() => {
- setTextareaValue(element, "hello");
- element.dispatchEvent(new Event("input", { bubbles: true }));
+ setTextareaValue(textarea, "first line\nsecond line");
+ textarea.dispatchEvent(new Event("input", { bubbles: true }));
});
- expect(element.style.height).toBe("34px");
- expect(element.style.overflowY).toBe("hidden");
+ expect(textarea.value).toContain("\n");
+ unmount();
+ });
- scrollHeight = 200;
+ test("grows without a maximum height", () => {
+ const { container, render, unmount } = renderIntoContainer(<AgentInput />);
- act(() => {
- setTextareaValue(element, "a\nb\nc\nd\ne\nf\ng");
- element.dispatchEvent(new Event("input", { bubbles: true }));
+ render();
+
+ const textarea = container.querySelector("textarea") as HTMLTextAreaElement;
+ Object.defineProperties(textarea, {
+ clientHeight: { configurable: true, value: 32 },
+ offsetHeight: { configurable: true, value: 34 },
+ scrollHeight: { configurable: true, value: 200 },
});
+ const getComputedStyleSpy = vi
+ .spyOn(window, "getComputedStyle")
+ .mockReturnValue({ minHeight: "34px" } as CSSStyleDeclaration);
- expect(element.style.height).toBe("134px");
- expect(element.style.overflowY).toBe("auto");
+ act(() => {
+ setTextareaValue(textarea, "a\nb\nc\nd\ne\nf\ng");
+ textarea.dispatchEvent(new Event("input", { bubbles: true }));
+ });
+ expect(textarea.style.height).toBe("202px");
+ expect(textarea.style.overflowY).toBe("hidden");
getComputedStyleSpy.mockRestore();
unmount();
});
diff --git a/frontend/src/modules/agent/components/AgentInput.tsx b/frontend/src/modules/agent/components/AgentInput.tsx
index 5ed798a636..f8b714fb1a 100644
--- a/frontend/src/modules/agent/components/AgentInput.tsx
+++ b/frontend/src/modules/agent/components/AgentInput.tsx
@@ -555,7 +555,6 @@ export function AgentInput() {
});
}, [input, selectionStart, selectionEnd]);
- // Auto-resize textarea
const autoResize = useCallback(() => {
const el = textareaRef.current;
if (!el) return;
@@ -565,14 +564,11 @@ export function AgentInput() {
const styles = window.getComputedStyle(el);
const minHeight =
Number.parseFloat(styles.minHeight) || el.getBoundingClientRect().height;
- const maxHeight =
- Number.parseFloat(styles.maxHeight) || Number.POSITIVE_INFINITY;
const borderHeight = el.offsetHeight - el.clientHeight;
- const contentHeight = el.scrollHeight + borderHeight;
- const nextHeight = Math.max(minHeight, Math.min(contentHeight, maxHeight));
+ const nextHeight = Math.max(minHeight, el.scrollHeight + borderHeight);
el.style.height = `${nextHeight}px`;
- el.style.overflowY = contentHeight > maxHeight ? "auto" : "hidden";
+ el.style.overflowY = "hidden";
}, []);
useEffect(() => {
@@ -1180,7 +1176,6 @@ export function AgentInput() {
[blockWhenAIIsNotConfigured, startChatRun]
);
- // Textarea keydown handler
const handleTextareaKeydown = useCallback(
(event: React.KeyboardEvent<HTMLTextAreaElement>) => {
if (showMention) {
@@ -1356,7 +1351,7 @@ export function AgentInput() {
ref={textareaRef}
value={input}
rows={1}
- className="block h-9 min-h-9 max-h-[134px] w-full resize-none overflow-y-hidden rounded-xs border px-3 py-1.5 text-sm leading-5 outline-none focus:ring-1 focus:ring-accent disabled:opacity-50"
+ className="block h-9 min-h-9 w-full resize-none overflow-y-hidden rounded-xs border px-3 py-1.5 text-sm leading-5 outline-none focus:ring-1 focus:ring-accent disabled:opacity-50"
aria-label={inputPlaceholder}
disabled={isCurrentChatRunning || isAIConfigurationBlocked}
onChange={(e) => {
diff --git a/frontend/src/modules/agent/components/AgentWindow.test.tsx b/frontend/src/modules/agent/components/AgentWindow.test.tsx
index 9ed8355083..1168b002bb 100644
--- a/frontend/src/modules/agent/components/AgentWindow.test.tsx
+++ b/frontend/src/modules/agent/components/AgentWindow.test.tsx
@@ -118,6 +118,8 @@ beforeEach(async () => {
}
);
vi.stubGlobal("PointerEvent", MouseEvent);
+ vi.stubGlobal("innerWidth", 1600);
+ vi.stubGlobal("innerHeight", 1000);
Object.defineProperty(window, "matchMedia", {
configurable: true,
writable: true,
@@ -135,7 +137,6 @@ beforeEach(async () => {
const initialState = createAgentStore().getState();
useAgentStore.setState({
visible: initialState.visible,
- position: initialState.position,
size: initialState.size,
sidebarWidth: initialState.sidebarWidth,
minimized: initialState.minimized,
@@ -150,8 +151,7 @@ beforeEach(async () => {
useAgentStore.setState({
visible: true,
minimized: false,
- position: { x: 100, y: 120 },
- size: { width: 500, height: 450 },
+ size: { width: 1200, height: 450 },
sidebarWidth: 200,
});
@@ -181,6 +181,279 @@ afterEach(() => {
});
describe("AgentWindow", () => {
+ test("uses the compact rail below the roomy agent-window width", () => {
+ useAgentStore.setState({ size: { width: 700, height: 450 } });
+
+ const { render, unmount } = renderIntoContainer(<AgentWindow />);
+ render();
+
+ expect(
+ document.body.querySelector("[data-agent-compact-rail]")
+ ).toBeInstanceOf(HTMLElement);
+ expect(
+ document.body.querySelector("[data-agent-chat-sidebar]")
+ ).toBeNull();
+
+ unmount();
+ });
+
+ test("does not render a sidebar resize handle in compact view", () => {
+ useAgentStore.setState({ size: { width: 700, height: 450 } });
+
+ const { render, unmount } = renderIntoContainer(<AgentWindow />);
+ render();
+
+ expect(
+ document.body.querySelector("[data-agent-sidebar-resize]")
+ ).toBeNull();
+
+ unmount();
+ });
+
+ test("keeps the compact rail at the 480px agent-window boundary", () => {
+ useAgentStore.setState({ size: { width: 480, height: 450 } });
+
+ const { render, unmount } = renderIntoContainer(<AgentWindow />);
+ render();
+
+ try {
+ expect(
+ document.body.querySelector("[data-agent-compact-rail]")
+ ).toBeInstanceOf(HTMLElement);
+ expect(
+ document.body.querySelector("[data-agent-mobile-chat-list]")
+ ).toBeNull();
+ } finally {
+ unmount();
+ }
+ });
+
+ test("keeps the full chat sidebar when the agent window has room for it", () => {
+ useAgentStore.setState({ size: { width: 750, height: 450 } });
+
+ const { render, unmount } = renderIntoContainer(<AgentWindow />);
+ render();
+
+ expect(
+ document.body.querySelector("[data-agent-chat-sidebar]")
+ ).toBeInstanceOf(HTMLElement);
+ expect(
+ document.body.querySelector("[data-agent-compact-rail]")
+ ).toBeNull();
+
+ unmount();
+ });
+
+ test("renders the compact drawer outside the clipped rail panel", async () => {
+ useAgentStore.setState({ size: { width: 700, height: 450 } });
+
+ const { render, unmount } = renderIntoContainer(<AgentWindow />);
+ render();
+
+ const listButton = document.body.querySelector(
+ 'button[aria-label="agent.chat-list-label"]'
+ ) as HTMLButtonElement;
+ await act(async () => {
+ listButton.click();
+ await Promise.resolve();
+ });
+
+ const drawer = document.body.querySelector(
+ "[data-agent-compact-drawer]"
+ );
+ const body = document.body.querySelector("[data-agent-window-body]");
+ expect(drawer?.parentElement).toBe(body);
+ expect(
+ document.body.querySelector("[data-agent-compact-rail]")
+ ).toBeInstanceOf(HTMLElement);
+
+ unmount();
+ });
+
+ test("layers the compact drawer above the chat panel and composer", async () => {
+ useAgentStore.setState({ size: { width: 700, height: 450 } });
+
+ const { render, unmount } = renderIntoContainer(<AgentWindow />);
+ render();
+
+ const listButton = document.body.querySelector(
+ 'button[aria-label="agent.chat-list-label"]'
+ ) as HTMLButtonElement;
+ await act(async () => {
+ listButton.click();
+ await Promise.resolve();
+ });
+
+ try {
+ const body = document.body.querySelector("[data-agent-window-body]");
+ const panels = document.body.querySelector("[data-agent-chat-panels]");
+ const drawer = document.body.querySelector(
+ "[data-agent-compact-drawer]"
+ );
+ const overlay = document.body.querySelector(
+ "[data-agent-compact-overlay]"
+ );
+ const input = document.body.querySelector('[data-testid="agent-input"]');
+
+ expect(panels?.parentElement).toBe(body);
+ expect(panels?.contains(input)).toBe(true);
+ expect(panels?.className).toContain("relative");
+ expect(panels?.className).toContain("z-0");
+ expect(overlay?.parentElement).toBe(body);
+ expect(overlay?.className).toContain("absolute");
+ expect(overlay?.className).toContain("inset-0");
+ expect(overlay?.className).toContain("z-1");
+ expect(drawer?.parentElement).toBe(body);
+ expect(drawer?.className).toContain("z-2");
+ } finally {
+ unmount();
+ }
+ });
+
+ test("opens the mobile agent directly in its current conversation", async () => {
+ useAgentStore.setState({
+ visible: false,
+ minimized: false,
+ size: { width: 479, height: 450 },
+ });
+
+ const { render, unmount } = renderIntoContainer(<AgentWindow />);
+ render();
+
+ try {
+ await act(async () => {
+ useAgentStore.getState().open();
+ await Promise.resolve();
+ });
+
+ expect(
+ document.body.querySelector("[data-agent-mobile-conversation]")
+ ).toBeInstanceOf(HTMLDivElement);
+ expect(
+ document.body.querySelector("[data-agent-mobile-chat-list]")
+ ).toBeNull();
+ expect(
+ document.body.querySelector("[data-agent-compact-rail]")
+ ).toBeNull();
+
+ const back = document.body.querySelector(
+ '[aria-label="agent.chat-list-label"]'
+ ) as HTMLButtonElement;
+ act(() => back.click());
+ expect(
+ document.body.querySelector("[data-agent-mobile-chat-list]")
+ ).toBeInstanceOf(HTMLDivElement);
+ } finally {
+ unmount();
+ }
+ });
+
+ test("keeps rename out of the mobile chat list", () => {
+ useAgentStore.setState({ size: { width: 479, height: 450 } });
+ const chatId = useAgentStore.getState().currentChatId!;
+
+ const { render, unmount } = renderIntoContainer(<AgentWindow />);
+ render();
+
+ const back = document.body.querySelector(
+ '[aria-label="agent.chat-list-label"]'
+ ) as HTMLButtonElement;
+ act(() => back.click());
+
+ const row = document.body.querySelector(
+ `[data-agent-chat-row="${chatId}"] button`
+ ) as HTMLButtonElement;
+ act(() => row.click());
+
+ expect(
+ document.body.querySelector("[data-agent-inline-rename-input]")
+ ).toBeNull();
+ expect(
+ document.body.querySelector("[data-agent-mobile-conversation]")
+ ).toBeInstanceOf(HTMLDivElement);
+
+ unmount();
+ });
+
+ test("restores and deletes archived chats from the mobile archive view", () => {
+ useAgentStore.setState({ size: { width: 479, height: 450 } });
+ const store = useAgentStore.getState();
+ const restoredChat = store.createChat({
+ title: "Restore me",
+ archived: true,
+ select: false,
+ });
+ const deletedChat = store.createChat({
+ title: "Delete me",
+ archived: true,
+ select: false,
+ });
+
+ const { render, unmount } = renderIntoContainer(<AgentWindow />);
+ render();
+
+ const back = document.body.querySelector(
+ '[aria-label="agent.chat-list-label"]'
+ ) as HTMLButtonElement;
+ act(() => back.click());
+
+ const archiveButton = document.body.querySelector(
+ '[aria-label="agent.archived-only-chats"]'
+ ) as HTMLButtonElement;
+ act(() => archiveButton.click());
+
+ const restoreButton = document.body.querySelector(
+ `[data-agent-chat-row="${restoredChat.id}"] [data-agent-unarchive-chat]`
+ ) as HTMLButtonElement;
+ act(() => restoreButton.click());
+ expect(useAgentStore.getState().getChat(restoredChat.id)?.archived).toBe(
+ false
+ );
+
+ const deleteButton = document.body.querySelector(
+ `[data-agent-chat-row="${deletedChat.id}"] [data-agent-delete-chat]`
+ ) as HTMLButtonElement;
+ act(() => deleteButton.click());
+ const confirmButton = Array.from(
+ document.body.querySelectorAll("button")
+ ).find((button) => button.textContent === "common.confirm");
+ act(() => confirmButton?.click());
+ expect(useAgentStore.getState().getChat(deletedChat.id)).toBeNull();
+
+ unmount();
+ });
+
+ test("opens the compact chat list before renaming the selected chat", async () => {
+ useAgentStore.setState({ size: { width: 700, height: 450 } });
+ const chatId = useAgentStore.getState().currentChatId!;
+
+ const { render, unmount } = renderIntoContainer(<AgentWindow />);
+ render();
+
+ const listButton = document.body.querySelector(
+ 'button[aria-label="agent.chat-list-label"]'
+ ) as HTMLButtonElement;
+ await act(async () => {
+ listButton.click();
+ await Promise.resolve();
+ });
+
+ const selectedChat = document.body.querySelector(
+ `[data-agent-chat-row="${chatId}"] button`
+ ) as HTMLButtonElement;
+ expect(selectedChat).toBeInstanceOf(HTMLButtonElement);
+ await act(async () => {
+ selectedChat.click();
+ await Promise.resolve();
+ });
+
+ expect(
+ document.body.querySelector("[data-agent-inline-rename-input]")
+ ).toBeInstanceOf(HTMLInputElement);
+
+ unmount();
+ });
+
test("binds the initial empty chat when opened under a project", () => {
const chatId = useAgentStore.getState().currentChatId!;
expect(useAgentStore.getState().getChat(chatId)?.context).toBeUndefined();
@@ -306,6 +579,92 @@ describe("AgentWindow", () => {
unmount();
});
+ test("hides new-chat actions from the archived full sidebar", async () => {
+ useAgentStore.setState({ size: { width: 750, height: 450 } });
+ useAgentStore.getState().createChat({
+ title: "Archived analytics",
+ context: "projects/analytics",
+ archived: true,
+ select: false,
+ });
+
+ const { render, unmount } = renderIntoContainer(<AgentWindow />);
+ render();
+
+ const moreButton = document.body.querySelector(
+ "[aria-label='common.more']"
+ ) as HTMLButtonElement;
+ act(() => {
+ moreButton.dispatchEvent(
+ new MouseEvent("click", { bubbles: true, cancelable: true })
+ );
+ });
+
+ const archivedModeButton = document.body.querySelector(
+ "[data-agent-chat-list-mode]"
+ ) as HTMLDivElement;
+ await act(async () => {
+ archivedModeButton.dispatchEvent(
+ new MouseEvent("click", { bubbles: true, cancelable: true })
+ );
+ await Promise.resolve();
+ });
+
+ try {
+ const actions = document.body.querySelector(
+ "[data-agent-chat-sidebar-actions]"
+ );
+ expect(
+ actions?.querySelector("[aria-label='agent.new-chat']")
+ ).toBeNull();
+ expect(
+ actions?.querySelector("[aria-label='common.more']")
+ ).toBeInstanceOf(HTMLButtonElement);
+ expect(
+ document.body.querySelector(
+ '[data-agent-new-chat-for-context="projects/analytics"]'
+ )
+ ).toBeNull();
+ } finally {
+ unmount();
+ }
+ });
+
+ test("hides the compact rail new-chat action while viewing archived chats", async () => {
+ useAgentStore.setState({ size: { width: 700, height: 450 } });
+ useAgentStore.getState().createChat({
+ title: "Archived analytics",
+ context: "projects/analytics",
+ archived: true,
+ select: false,
+ });
+
+ const { render, unmount } = renderIntoContainer(<AgentWindow />);
+ render();
+
+ const archiveButton = document.body.querySelector(
+ "[data-agent-compact-rail] [aria-label='agent.archived-only-chats']"
+ ) as HTMLButtonElement;
+ await act(async () => {
+ archiveButton.click();
+ await Promise.resolve();
+ });
+
+ try {
+ const rail = document.body.querySelector("[data-agent-compact-rail]");
+ expect(
+ rail?.querySelector("[aria-label='agent.new-chat']")
+ ).toBeNull();
+ expect(
+ document.body.querySelector(
+ '[data-agent-new-chat-for-context="projects/analytics"]'
+ )
+ ).toBeNull();
+ } finally {
+ unmount();
+ }
+ });
+
test("hydrates uncached project chat contexts before rendering their labels", async () => {
mocks.projectsByName = {};
mocks.batchFetchProjects.mockImplementation(async () => {
@@ -734,7 +1093,7 @@ describe("AgentWindow", () => {
unmount();
});
- test("commits drag position only on pointerup", () => {
+ test("anchors the window at the bottom right without a drag affordance", () => {
const { render, unmount } = renderIntoContainer(<AgentWindow />);
render();
@@ -742,21 +1101,23 @@ describe("AgentWindow", () => {
const windowEl = document.body.querySelector(
"[data-agent-window]"
) as HTMLDivElement | null;
- const header = windowEl?.querySelector(
- ".cursor-move"
+ const header = document.body.querySelector(
+ "[data-agent-window-header]"
) as HTMLDivElement | null;
expect(windowEl).toBeInstanceOf(HTMLDivElement);
expect(header).toBeInstanceOf(HTMLDivElement);
-
- Object.defineProperty(windowEl, "offsetWidth", {
- configurable: true,
- get: () => 500,
- });
- Object.defineProperty(windowEl, "offsetHeight", {
- configurable: true,
- get: () => 450,
- });
+ expect(windowEl?.style.right).toBe("16px");
+ expect(windowEl?.style.bottom).toBe("16px");
+ expect(windowEl?.style.left).toBe("");
+ expect(windowEl?.style.top).toBe("");
+ expect(header?.className).not.toContain("cursor-move");
+ expect(
+ Array.from(
+ document.body.querySelectorAll("[data-agent-window-resize-zone]"),
+ (zone) => zone.getAttribute("data-agent-window-resize-zone")
+ )
+ ).toEqual(["n", "w", "nw"]);
act(() => {
header?.dispatchEvent(
@@ -774,13 +1135,6 @@ describe("AgentWindow", () => {
clientY: 190,
})
);
- });
-
- expect(windowEl?.style.left).toBe("130px");
- expect(windowEl?.style.top).toBe("160px");
- expect(useAgentStore.getState().position).toEqual({ x: 100, y: 120 });
-
- act(() => {
document.dispatchEvent(
new PointerEvent("pointerup", {
bubbles: true,
@@ -790,8 +1144,12 @@ describe("AgentWindow", () => {
);
});
- expect(useAgentStore.getState().position).toEqual({ x: 130, y: 160 });
+ expect(windowEl?.style.right).toBe("16px");
+ expect(windowEl?.style.bottom).toBe("16px");
+ expect(windowEl?.style.left).toBe("");
+ expect(windowEl?.style.top).toBe("");
unmount();
});
+
});
diff --git a/frontend/src/modules/agent/components/AgentWindow.tsx b/frontend/src/modules/agent/components/AgentWindow.tsx
index e8597afd8a..c4fe362fd8 100644
--- a/frontend/src/modules/agent/components/AgentWindow.tsx
+++ b/frontend/src/modules/agent/components/AgentWindow.tsx
@@ -1,8 +1,10 @@
import {
Archive,
Building2,
+ ChevronLeft,
EllipsisVertical,
FolderKanban,
+ MessageSquare,
Plus,
Trash2,
Undo2,
@@ -79,17 +81,22 @@ import {
resizeWindowBounds,
} from "./window-resize";
-const resizeZoneClasses: Record<ResizeDirection, string> = {
+type AnchoredResizeDirection = Extract<ResizeDirection, "n" | "w" | "nw">;
+
+const resizeZoneClasses: Record<AnchoredResizeDirection, string> = {
n: "left-[12px] top-[-6px] h-[6px] w-[calc(100%-24px)] cursor-n-resize",
- s: "bottom-[-6px] left-[12px] h-[6px] w-[calc(100%-24px)] cursor-s-resize",
- e: "right-[-6px] top-[12px] h-[calc(100%-24px)] w-[6px] cursor-e-resize",
w: "left-[-6px] top-[12px] h-[calc(100%-24px)] w-[6px] cursor-w-resize",
- ne: "right-[-6px] top-[-6px] size-[12px] cursor-ne-resize",
nw: "left-[-6px] top-[-6px] size-[12px] cursor-nw-resize",
- se: "bottom-[-6px] right-[-6px] size-[12px] cursor-se-resize",
- sw: "bottom-[-6px] left-[-6px] size-[12px] cursor-sw-resize",
};
+// The default 750px agent window leaves a useful reading column beside the
+// persistent chat sidebar. Keep the compact rail for genuinely constrained
+// desktop widths, rather than applying a browser-level breakpoint.
+const COMPACT_WINDOW_MAX_WIDTH = 719;
+// Compact remains viable down to the 460px minimum agent-window width. Reserve
+// the single-pane mobile flow for genuinely phone-sized agent windows.
+const MOBILE_WINDOW_MAX_WIDTH = 479;
+
interface AgentChatGroup {
context?: string;
chats: AgentChatRecord[];
@@ -129,7 +136,6 @@ export function AgentWindow() {
const visible = useAgentStore((s) => s.visible);
const minimized = useAgentStore((s) => s.minimized);
- const position = useAgentStore((s) => s.position);
const size = useAgentStore((s) => s.size);
const sidebarWidth = useAgentStore((s) => s.sidebarWidth);
const orderedChats = useAgentStore(selectOrderedChats);
@@ -147,6 +153,7 @@ export function AgentWindow() {
}, [hasRunningChat, workspace?.name]);
const windowRef = useRef<HTMLDivElement>(null);
+ const bodyRef = useRef<HTMLDivElement>(null);
const renameInputRef = useRef<HTMLInputElement>(null);
const [viewportSize, setViewportSize] = useState({
@@ -160,6 +167,12 @@ export function AgentWindow() {
const viewportResizeFrameRef = useRef(0);
const [showArchivedOnly, setShowArchivedOnly] = useState(false);
+ const [compactPanel, setCompactPanel] = useState<"chats" | "archived" | null>(
+ null
+ );
+ const [mobileScreen, setMobileScreen] = useState<
+ "chats" | "conversation" | "archived"
+ >("chats");
const [isRenamingCurrentChat, setIsRenamingCurrentChat] = useState(false);
const [
isDeleteAllArchivedChatsDialogOpen,
@@ -167,21 +180,18 @@ export function AgentWindow() {
] = useState(false);
const [renamingTitle, setRenamingTitle] = useState("");
- // Refs for drag/resize intermediate values (avoid re-renders)
- const isDraggingRef = useRef(false);
- const dragOffsetRef = useRef({ x: 0, y: 0 });
- const dragPositionRef = useRef<{ x: number; y: number } | null>(null);
+ // Refs for resize intermediate values (avoid re-renders)
const isResizingRef = useRef(false);
const resizeStartRef = useRef<{
x: number;
y: number;
bounds: ResizeBounds;
- direction: ResizeDirection;
+ direction: AnchoredResizeDirection;
}>({
x: 0,
y: 0,
bounds: { x: 0, y: 0, width: 0, height: 0 },
- direction: "se",
+ direction: "nw",
});
const resizeObserverRef = useRef<ResizeObserver | null>(null);
@@ -229,46 +239,13 @@ export function AgentWindow() {
[clampWidth, clampHeight]
);
- const getDisplayPosition = useCallback(
- (x: number, y: number, displaySize?: { width: number; height: number }) => {
- const sz = displaySize ?? getDisplaySize(size.width, size.height);
- const maxX = Math.max(
- WINDOW_MARGIN,
- viewportSize.width - sz.width - WINDOW_MARGIN
- );
- const maxY = Math.max(
- WINDOW_MARGIN,
- viewportSize.height - sz.height - WINDOW_MARGIN
- );
- return {
- x: Math.min(maxX, Math.max(WINDOW_MARGIN, Math.round(x))),
- y: Math.min(maxY, Math.max(WINDOW_MARGIN, Math.round(y))),
- };
- },
- [
- getDisplaySize,
- size.width,
- size.height,
- viewportSize.width,
- viewportSize.height,
- ]
+ const displaySize = useMemo(
+ () => getDisplaySize(size.width, size.height),
+ [getDisplaySize, size.height, size.width]
);
- const displayWindowState = useMemo(() => {
- const sz = getDisplaySize(size.width, size.height);
- const pos = getDisplayPosition(position.x, position.y, sz);
- return { position: pos, size: sz };
- }, [
- getDisplaySize,
- getDisplayPosition,
- size.width,
- size.height,
- position.x,
- position.y,
- ]);
-
const clampSidebarWidth = useCallback(
- (width: number, windowWidth = displayWindowState.size.width) => {
+ (width: number, windowWidth = displaySize.width) => {
const maxSW = Math.max(
MIN_SIDEBAR_WIDTH,
windowWidth - MIN_MAIN_PANEL_WIDTH
@@ -276,7 +253,7 @@ export function AgentWindow() {
const minSW = Math.min(MIN_SIDEBAR_WIDTH, maxSW);
return Math.min(maxSW, Math.max(minSW, Math.round(width)));
},
- [displayWindowState.size.width]
+ [displaySize.width]
);
const clampedSidebarWidth = useMemo(
@@ -285,21 +262,24 @@ export function AgentWindow() {
);
const windowStyle: React.CSSProperties = {
- left: `${displayWindowState.position.x}px`,
- top: `${displayWindowState.position.y}px`,
- width: `${displayWindowState.size.width}px`,
- height: `${displayWindowState.size.height}px`,
+ right: `${WINDOW_MARGIN}px`,
+ bottom: `${WINDOW_MARGIN}px`,
+ width: `${displaySize.width}px`,
+ height: `${displaySize.height}px`,
};
const maxSidebarWidth = Math.max(
MIN_SIDEBAR_WIDTH,
- displayWindowState.size.width - MIN_MAIN_PANEL_WIDTH
+ displaySize.width - MIN_MAIN_PANEL_WIDTH
);
const minSidebarWidth = Math.min(MIN_SIDEBAR_WIDTH, maxSidebarWidth);
const minMainPanelWidth = Math.min(
MIN_MAIN_PANEL_WIDTH,
- Math.max(1, displayWindowState.size.width - minSidebarWidth)
+ Math.max(1, displaySize.width - minSidebarWidth)
);
+ const isMobileWindow = displaySize.width <= MOBILE_WINDOW_MAX_WIDTH;
+ const isCompactWindow =
+ displaySize.width <= COMPACT_WINDOW_MAX_WIDTH && !isMobileWindow;
// --- Derived chat data ---
@@ -349,17 +329,10 @@ export function AgentWindow() {
});
}, [batchFetchProjects, missingProjectContexts, visible]);
- const syncStoreToDisplayState = useCallback(() => {
+ const syncStoreToDisplaySize = useCallback(() => {
const store = useAgentStore.getState();
- store.setSize(
- displayWindowState.size.width,
- displayWindowState.size.height
- );
- store.setPosition(
- displayWindowState.position.x,
- displayWindowState.position.y
- );
- }, [displayWindowState]);
+ store.setSize(displaySize.width, displaySize.height);
+ }, [displaySize]);
// --- Chat helpers ---
@@ -660,108 +633,36 @@ export function AgentWindow() {
ensureCurrentChatMatchesDisplayedMode();
}, [showArchivedOnly]);
- // --- Drag handlers ---
- // All drag/resize handlers manipulate DOM directly during movement
- // and only commit to the Zustand store on pointerup, avoiding per-frame
- // immer drafts + React re-renders.
-
const sidebarPanelRef = useRef<PanelImperativeHandle | null>(null);
- const dragCleanupRef = useRef<(() => void) | null>(null);
const resizeCleanupRef = useRef<(() => void) | null>(null);
- // Cleanup drag/resize listeners on unmount
+ // Cleanup resize listeners on unmount.
useEffect(() => {
return () => {
- dragCleanupRef.current?.();
resizeCleanupRef.current?.();
};
}, []);
- const startDrag = useCallback(
- (event: React.PointerEvent<HTMLDivElement>) => {
- if (event.button !== 0) return;
- if (
- event.target instanceof HTMLElement &&
- event.target.closest("[data-agent-window-action]")
- ) {
- return;
- }
- event.preventDefault();
- syncStoreToDisplayState();
- isDraggingRef.current = true;
- const store = useAgentStore.getState();
- dragOffsetRef.current = {
- x: event.clientX - store.position.x,
- y: event.clientY - store.position.y,
- };
- dragPositionRef.current = {
- x: store.position.x,
- y: store.position.y,
- };
-
- const onDrag = (e: PointerEvent) => {
- if (!isDraggingRef.current || !windowRef.current) return;
- const el = windowRef.current;
- const vw = window.innerWidth;
- const vh = window.innerHeight;
- const w = el.offsetWidth;
- const h = el.offsetHeight;
- const maxX = Math.max(WINDOW_MARGIN, vw - w - WINDOW_MARGIN);
- const maxY = Math.max(WINDOW_MARGIN, vh - h - WINDOW_MARGIN);
- const x = Math.min(
- maxX,
- Math.max(WINDOW_MARGIN, e.clientX - dragOffsetRef.current.x)
- );
- const y = Math.min(
- maxY,
- Math.max(WINDOW_MARGIN, e.clientY - dragOffsetRef.current.y)
- );
- el.style.left = `${x}px`;
- el.style.top = `${y}px`;
- dragPositionRef.current = { x, y };
- };
-
- const stopDrag = () => {
- isDraggingRef.current = false;
- document.removeEventListener("pointermove", onDrag);
- document.removeEventListener("pointerup", stopDrag);
- document.removeEventListener("pointercancel", stopDrag);
- dragCleanupRef.current = null;
- if (dragPositionRef.current) {
- useAgentStore
- .getState()
- .setPosition(dragPositionRef.current.x, dragPositionRef.current.y);
- }
- dragPositionRef.current = null;
- useAgentStore.getState().saveWindowState();
- };
-
- document.addEventListener("pointermove", onDrag);
- document.addEventListener("pointerup", stopDrag);
- document.addEventListener("pointercancel", stopDrag);
- dragCleanupRef.current = stopDrag;
- },
- [syncStoreToDisplayState]
- );
-
// --- Resize handlers ---
const startResize = useCallback(
- (direction: ResizeDirection, event: React.PointerEvent<HTMLDivElement>) => {
+ (
+ direction: AnchoredResizeDirection,
+ event: React.PointerEvent<HTMLDivElement>
+ ) => {
if (!canResizeWindow || event.button !== 0) return;
event.preventDefault();
event.stopPropagation();
- syncStoreToDisplayState();
+ syncStoreToDisplaySize();
isResizingRef.current = true;
- const store = useAgentStore.getState();
resizeStartRef.current = {
x: event.clientX,
y: event.clientY,
bounds: {
- x: store.position.x,
- y: store.position.y,
- width: store.size.width,
- height: store.size.height,
+ x: window.innerWidth - displaySize.width - WINDOW_MARGIN,
+ y: window.innerHeight - displaySize.height - WINDOW_MARGIN,
+ width: displaySize.width,
+ height: displaySize.height,
},
direction,
};
@@ -782,13 +683,9 @@ export function AgentWindow() {
margin: WINDOW_MARGIN,
},
});
- el.style.left = `${nextBounds.x}px`;
- el.style.top = `${nextBounds.y}px`;
el.style.width = `${nextBounds.width}px`;
el.style.height = `${nextBounds.height}px`;
- const store = useAgentStore.getState();
- store.setSize(nextBounds.width, nextBounds.height);
- store.setPosition(nextBounds.x, nextBounds.y);
+ useAgentStore.getState().setSize(nextBounds.width, nextBounds.height);
};
const stopResize = () => {
@@ -805,7 +702,7 @@ export function AgentWindow() {
document.addEventListener("pointercancel", stopResize);
resizeCleanupRef.current = stopResize;
},
- [canResizeWindow, syncStoreToDisplayState]
+ [canResizeWindow, displaySize, syncStoreToDisplaySize]
);
// --- Viewport resize ---
@@ -878,22 +775,6 @@ export function AgentWindow() {
const clH = Math.min(maxH, Math.max(minH, Math.round(height)));
state.size.width = clW;
state.size.height = clH;
- const maxX = Math.max(
- WINDOW_MARGIN,
- viewportSize.width - clW - WINDOW_MARGIN
- );
- const maxY = Math.max(
- WINDOW_MARGIN,
- viewportSize.height - clH - WINDOW_MARGIN
- );
- state.position.x = Math.min(
- maxX,
- Math.max(WINDOW_MARGIN, Math.round(state.position.x))
- );
- state.position.y = Math.min(
- maxY,
- Math.max(WINDOW_MARGIN, Math.round(state.position.y))
- );
});
useAgentStore.getState().saveWindowState();
});
@@ -906,8 +787,9 @@ export function AgentWindow() {
// --- Sync sidebar width when window width changes ---
useEffect(() => {
+ if (isCompactWindow) return;
const store = useAgentStore.getState();
- const windowWidth = displayWindowState.size.width;
+ const windowWidth = displaySize.width;
const maxSW = Math.max(
MIN_SIDEBAR_WIDTH,
windowWidth - MIN_MAIN_PANEL_WIDTH
@@ -923,15 +805,24 @@ export function AgentWindow() {
});
store.saveWindowState();
}
- }, [displayWindowState.size.width]);
+ }, [displaySize.width, isCompactWindow]);
useEffect(() => {
+ if (isCompactWindow) return;
const panel = sidebarPanelRef.current;
if (!panel) return;
if (Math.round(panel.getSize().inPixels) !== clampedSidebarWidth) {
panel.resize(clampedSidebarWidth);
}
- }, [clampedSidebarWidth]);
+ }, [clampedSidebarWidth, isCompactWindow]);
+
+ useEffect(() => {
+ if (!isCompactWindow) setCompactPanel(null);
+ }, [isCompactWindow]);
+
+ useLayoutEffect(() => {
+ if (visible && isMobileWindow) setMobileScreen("conversation");
+ }, [isMobileWindow, visible]);
const saveSidebarWidth = useCallback(() => {
const width = sidebarPanelRef.current?.getSize().inPixels;
@@ -971,6 +862,92 @@ export function AgentWindow() {
};
}, [currentChatId, getOrFetchSettingByName, visible]);
+ const openMobileChatList = useCallback(() => {
+ setShowArchivedOnly(false);
+ setMobileScreen("chats");
+ }, []);
+
+ const openMobileArchivedChats = useCallback(() => {
+ setShowArchivedOnly(true);
+ setMobileScreen("archived");
+ }, []);
+
+ const createMobileChat = useCallback(
+ (context?: string) => {
+ if (context) {
+ createChatForContext(context);
+ } else {
+ createChat();
+ }
+ setMobileScreen("conversation");
+ },
+ [createChat, createChatForContext]
+ );
+
+ const selectMobileChat = useCallback(
+ (chatId: string) => {
+ if (!useAgentStore.getState().canSelectChat(chatId)) return;
+ cancelRenameCurrentChat();
+ useAgentStore.getState().setCurrentChat(chatId);
+ setMobileScreen("conversation");
+ },
+ [cancelRenameCurrentChat]
+ );
+
+ const renderCompactRail = (overlay = false) => (
+ <nav
+ className={cn(
+ "flex flex-col items-center gap-y-2 border-r border-block-border bg-control-bg py-3",
+ overlay ? "absolute inset-y-0 left-0 z-3 w-12" : "size-full"
+ )}
+ data-agent-compact-rail
+ aria-label={t("agent.chat-list-label")}
+ >
+ <AgentTooltip content={t("agent.chat-list-label")}>
+ <Button
+ appearance="secondary"
+ size="xs"
+ className="text-control-light hover:bg-control-bg-hover"
+ aria-label={t("agent.chat-list-label")}
+ onClick={() => {
+ setShowArchivedOnly(false);
+ setCompactPanel("chats");
+ }}
+ >
+ <MessageSquare className="size-3.5" aria-hidden="true" />
+ </Button>
+ </AgentTooltip>
+ {!showArchivedOnly && (
+ <AgentTooltip content={t("agent.new-chat")}>
+ <Button
+ appearance="secondary"
+ size="xs"
+ className="text-control-light hover:bg-control-bg-hover"
+ aria-label={t("agent.new-chat")}
+ disabled={isChatCreationDisabled}
+ onClick={createChat}
+ >
+ <Plus className="size-3.5" aria-hidden="true" />
+ </Button>
+ </AgentTooltip>
+ )}
+ <AgentTooltip content={t("agent.archived-only-chats")}>
+ <Button
+ appearance="secondary"
+ size="xs"
+ className="text-control-light hover:bg-control-bg-hover"
+ aria-label={t("agent.archived-only-chats")}
+ onClick={() => {
+ setShowArchivedOnly(true);
+ setCompactPanel("archived");
+ }}
+ >
+ <Archive className="size-3.5" aria-hidden="true" />
+ </Button>
+ </AgentTooltip>
+ </nav>
+ );
+
// --- Render ---
if (!visible) return null;
@@ -1040,15 +1017,83 @@ export function AgentWindow() {
{/* Header */}
<div
data-agent-window-header
- className="flex cursor-move select-none items-center justify-between border-b bg-control-bg px-3 py-2 [touch-action:none]"
- onPointerDown={startDrag}
+ className="flex select-none items-center justify-between border-b bg-control-bg px-3 py-2"
>
<div className="flex min-w-0 items-center gap-x-2">
+ {isMobileWindow && mobileScreen === "conversation" && (
+ <Button
+ appearance="secondary"
+ size="xs"
+ data-agent-window-action
+ className="-ml-1 text-control-light hover:bg-control-bg-hover"
+ aria-label={t("agent.chat-list-label")}
+ onClick={(event) => {
+ event.stopPropagation();
+ openMobileChatList();
+ }}
+ >
+ <ChevronLeft className="size-4" aria-hidden="true" />
+ </Button>
+ )}
+ {isMobileWindow && mobileScreen === "archived" && (
+ <Button
+ appearance="secondary"
+ size="xs"
+ data-agent-window-action
+ className="-ml-1 text-control-light hover:bg-control-bg-hover"
+ aria-label={t("agent.chat-list-label")}
+ onClick={(event) => {
+ event.stopPropagation();
+ openMobileChatList();
+ }}
+ >
+ <ChevronLeft className="size-4" aria-hidden="true" />
+ </Button>
+ )}
<span className="truncate text-sm font-medium">
- {t("agent.assistant-title")}
+ {isMobileWindow && mobileScreen === "chats"
+ ? t("agent.chat-list-label")
+ : isMobileWindow && mobileScreen === "archived"
+ ? t("agent.archived-only-chats")
+ : t("agent.assistant-title")}
</span>
</div>
<div className="flex items-center gap-x-1">
+ {isMobileWindow && mobileScreen === "chats" && (
+ <>
+ <AgentTooltip content={t("agent.archived-only-chats")}>
+ <Button
+ appearance="secondary"
+ size="xs"
+ data-agent-window-action
+ className="text-control-light hover:bg-control-bg-hover"
+ aria-label={t("agent.archived-only-chats")}
+ onClick={(event) => {
+ event.stopPropagation();
+ openMobileArchivedChats();
+ }}
+ >
+ <Archive className="size-3.5" aria-hidden="true" />
+ </Button>
+ </AgentTooltip>
+ <AgentTooltip content={t("agent.new-chat")}>
+ <Button
+ appearance="secondary"
+ size="xs"
+ data-agent-window-action
+ className="text-control-light hover:bg-control-bg-hover"
+ aria-label={t("agent.new-chat")}
+ disabled={isChatCreationDisabled}
+ onClick={(event) => {
+ event.stopPropagation();
+ createMobileChat();
+ }}
+ >
+ <Plus className="size-3.5" aria-hidden="true" />
+ </Button>
+ </AgentTooltip>
+ </>
+ )}
<Button
appearance="secondary"
size="xs"
@@ -1079,117 +1124,25 @@ export function AgentWindow() {
</div>
{/* Body */}
- <PanelGroup
- orientation="horizontal"
- className="min-h-0 flex-1 bg-background"
- onLayoutChanged={(_, meta) => {
- if (meta.isUserInteraction) saveSidebarWidth();
- }}
+ <div
+ ref={bodyRef}
+ className="relative min-h-0 flex-1"
+ data-agent-window-body
>
- {/* Sidebar */}
- <Panel
- id="agent-chat-sidebar"
- panelRef={sidebarPanelRef}
- defaultSize={clampedSidebarWidth}
- minSize={minSidebarWidth}
- maxSize={maxSidebarWidth}
- groupResizeBehavior="preserve-pixel-size"
- >
- <aside className="flex size-full flex-col bg-control-bg">
- {/* Sidebar header */}
- <div className="border-b border-block-border px-3 py-3">
- <div className="flex items-center justify-between gap-x-2">
- <div>
- <h2 className="text-xs font-semibold uppercase tracking-wide text-control-light">
- {t("agent.chat-list-label")}
- </h2>
- </div>
- <div
- className="flex items-center gap-x-1"
- data-agent-chat-sidebar-actions
- >
- <AgentTooltip content={t("agent.new-chat")}>
- <Button
- appearance="secondary"
- size="xs"
- className="px-1 text-control-light hover:bg-control-bg-hover"
- aria-label={t("agent.new-chat")}
- disabled={isChatCreationDisabled}
- onClick={createChat}
- >
- <Plus className="size-3.5" aria-hidden="true" />
- </Button>
- </AgentTooltip>
- <AgentDropdownMenu>
- <AgentTooltip content={t("common.more")}>
- <AgentDropdownMenuTrigger
- className="inline-flex size-6 items-center justify-center rounded-xs text-control-light outline-hidden hover:bg-control-bg-hover focus-visible:ring-2 focus-visible:ring-accent disabled:pointer-events-none disabled:opacity-50"
- aria-label={t("common.more")}
- onClick={(event) => event.stopPropagation()}
- >
- <EllipsisVertical
- className="size-3.5"
- aria-hidden="true"
- />
- </AgentDropdownMenuTrigger>
- </AgentTooltip>
- <AgentDropdownMenuContent>
- {showArchivedOnly ? (
- <>
- <AgentDropdownMenuItem
- data-agent-unarchive-all-chats
- disabled={isUnarchiveAllDisabled}
- onClick={(event) => {
- event.stopPropagation();
- unarchiveAllChats();
- }}
- >
- {t("agent.unarchive-all-chats")}
- </AgentDropdownMenuItem>
- <AgentDropdownMenuItem
- data-agent-delete-all-chats
- className="text-error data-highlighted:bg-error/10"
- disabled={isDeleteAllDisabled}
- onClick={(event) => {
- event.stopPropagation();
- setIsDeleteAllArchivedChatsDialogOpen(true);
- }}
- >
- {t("agent.delete-all-chats")}
- </AgentDropdownMenuItem>
- </>
- ) : (
- <AgentDropdownMenuItem
- data-agent-archive-all-chats
- disabled={isArchiveAllDisabled}
- onClick={(event) => {
- event.stopPropagation();
- archiveAllChats();
- }}
- >
- {t("agent.archive-all-chats")}
- </AgentDropdownMenuItem>
- )}
- <AgentDropdownMenuSeparator />
- <AgentDropdownMenuItem
- data-agent-chat-list-mode
- onClick={(event) => {
- event.stopPropagation();
- toggleChatListMode();
- }}
- >
- {showArchivedOnly
- ? t("agent.active-only-chats")
- : t("agent.archived-only-chats")}
- </AgentDropdownMenuItem>
- </AgentDropdownMenuContent>
- </AgentDropdownMenu>
- </div>
- </div>
+ {isMobileWindow ? (
+ mobileScreen === "conversation" ? (
+ <div
+ className="flex size-full flex-col bg-background"
+ data-agent-mobile-conversation
+ >
+ <AgentChat className="min-h-0 flex-1" />
+ <AgentInput />
</div>
-
- {/* Chat list */}
- <div className="min-h-0 flex-1 overflow-y-auto">
+ ) : (
+ <div
+ className="size-full overflow-y-auto bg-control-bg"
+ data-agent-mobile-chat-list
+ >
<div className="flex flex-col" data-agent-chat-list>
{displayedChatGroups.map((group) => (
<div
@@ -1214,7 +1167,7 @@ export function AgentWindow() {
{t("agent.other-chats")}
</span>
)}
- {group.context && (
+ {group.context && !showArchivedOnly && (
<AgentTooltip
content={`${t("agent.new-chat")}: ${getContextLabel(group.context)}`}
>
@@ -1225,9 +1178,7 @@ export function AgentWindow() {
aria-label={`${t("agent.new-chat")}: ${getContextLabel(group.context)}`}
data-agent-new-chat-for-context={group.context}
disabled={isChatCreationDisabled}
- onClick={() =>
- createChatForContext(group.context!)
- }
+ onClick={() => createMobileChat(group.context)}
>
<Plus className="size-3.5" aria-hidden="true" />
</Button>
@@ -1237,123 +1188,440 @@ export function AgentWindow() {
{group.chats.map((chat) => (
<div
key={chat.id}
- className={`group w-full rounded-xs px-3 py-2 text-left text-sm transition-colors ${
+ className={cn(
+ "flex items-center gap-x-2 px-3 py-2 text-sm",
chat.id === currentChatId
? "bg-accent/10 text-accent"
- : "text-control hover:bg-control-bg-hover"
- }`}
+ : "text-control"
+ )}
data-agent-chat-row={chat.id}
>
- {chat.id === currentChatId &&
- isRenamingCurrentChat ? (
- <Input
- ref={renameInputRef}
- value={renamingTitle}
- onChange={(e) => setRenamingTitle(e.target.value)}
- className="h-7 text-sm"
- placeholder={t("agent.rename-chat-placeholder")}
- data-agent-inline-rename-input
- onBlur={commitRenameCurrentChat}
- onKeyDown={onRenameKeydown}
- />
- ) : (
- <div className="flex items-center gap-x-2">
- <Button
- appearance="secondary"
- size="md"
- type="button"
- className="h-auto min-w-0 flex-1 flex-col items-start p-0 text-left whitespace-normal hover:bg-transparent disabled:cursor-not-allowed disabled:opacity-60"
- disabled={
- !useAgentStore
- .getState()
- .canSelectChat(chat.id)
- }
- aria-current={
- chat.id === currentChatId ? "true" : undefined
- }
- onClick={() => handleChatRowClick(chat.id)}
+ <Button
+ appearance="secondary"
+ size="md"
+ type="button"
+ className="h-auto min-w-0 flex-1 justify-start p-0 text-left hover:bg-transparent"
+ disabled={
+ !useAgentStore.getState().canSelectChat(chat.id)
+ }
+ aria-current={
+ chat.id === currentChatId ? "true" : undefined
+ }
+ onClick={() => selectMobileChat(chat.id)}
+ >
+ <span className="truncate font-medium">
+ {getChatLabel(chat)}
+ </span>
+ </Button>
+ {chat.archived ? (
+ <>
+ <SidebarIconButton
+ tooltip={t("agent.unarchive-chat")}
+ ariaLabel={t("agent.unarchive-chat")}
+ dataAttr="data-agent-unarchive-chat"
+ onClick={() => unarchiveChat(chat.id)}
>
- <div
- className="w-full truncate font-medium"
- data-agent-chat-title
- >
- {getChatLabel(chat)}
- </div>
- </Button>
- <div className="pointer-events-none flex shrink-0 items-center gap-x-2 opacity-0 transition-opacity group-hover:pointer-events-auto group-hover:opacity-100 group-focus-within:pointer-events-auto group-focus-within:opacity-100">
- {chat.archived ? (
- <>
- <SidebarIconButton
- tooltip={t("agent.unarchive-chat")}
- ariaLabel={t("agent.unarchive-chat")}
- dataAttr="data-agent-unarchive-chat"
- onClick={() => unarchiveChat(chat.id)}
+ <Undo2
+ className="size-3.5"
+ aria-hidden="true"
+ />
+ </SidebarIconButton>
+ <ConfirmDialog
+ message={t("agent.delete-chat-confirmation")}
+ onConfirm={() => deleteChat(chat.id)}
+ triggerLabel={t("agent.delete-chat")}
+ triggerDataAttr="data-agent-delete-chat"
+ triggerVariant="icon"
+ >
+ <Trash2
+ className="size-3.5"
+ aria-hidden="true"
+ />
+ </ConfirmDialog>
+ </>
+ ) : (
+ <SidebarIconButton
+ tooltip={t("agent.archive-chat")}
+ ariaLabel={t("agent.archive-chat")}
+ dataAttr="data-agent-archive-chat"
+ onClick={() => archiveChat(chat.id)}
+ >
+ <Archive
+ className="size-3.5"
+ aria-hidden="true"
+ />
+ </SidebarIconButton>
+ )}
+ </div>
+ ))}
+ </div>
+ ))}
+ </div>
+ </div>
+ )
+ ) : (
+ <PanelGroup
+ orientation="horizontal"
+ className="relative z-0 size-full bg-background"
+ data-agent-chat-panels
+ onLayoutChanged={(_, meta) => {
+ if (!isCompactWindow && meta.isUserInteraction)
+ saveSidebarWidth();
+ }}
+ >
+ {/* Sidebar */}
+ <Panel
+ key={isCompactWindow ? "compact" : "roomy"}
+ id="agent-chat-sidebar"
+ panelRef={sidebarPanelRef}
+ defaultSize={isCompactWindow ? 48 : clampedSidebarWidth}
+ minSize={isCompactWindow ? 48 : minSidebarWidth}
+ maxSize={isCompactWindow ? 48 : maxSidebarWidth}
+ groupResizeBehavior="preserve-pixel-size"
+ className="relative"
+ >
+ {isCompactWindow && !compactPanel ? (
+ renderCompactRail()
+ ) : (
+ <EscapePanelClip
+ target={
+ isCompactWindow && compactPanel ? bodyRef.current : null
+ }
+ >
+ <aside
+ className={cn(
+ "flex size-full flex-col bg-control-bg",
+ isCompactWindow &&
+ "absolute inset-y-0 left-12 z-2 w-80 shadow-lg"
+ )}
+ data-agent-chat-sidebar={
+ isCompactWindow ? undefined : true
+ }
+ data-agent-compact-drawer={
+ isCompactWindow ? true : undefined
+ }
+ >
+ {/* Sidebar header */}
+ <div className="border-b border-block-border px-3 py-3">
+ <div className="flex items-center justify-between gap-x-2">
+ <h2 className="text-xs font-semibold uppercase tracking-wide text-control-light">
+ {showArchivedOnly
+ ? t("agent.archived-only-chats")
+ : t("agent.chat-list-label")}
+ </h2>
+ {isCompactWindow ? (
+ <Button
+ appearance="secondary"
+ size="xs"
+ className="text-control-light hover:bg-control-bg-hover"
+ aria-label={t("agent.close")}
+ onClick={() => setCompactPanel(null)}
+ >
+ &#10005;
+ </Button>
+ ) : (
+ <div
+ className="flex items-center gap-x-1"
+ data-agent-chat-sidebar-actions
+ >
+ {!showArchivedOnly && (
+ <AgentTooltip content={t("agent.new-chat")}>
+ <Button
+ appearance="secondary"
+ size="xs"
+ className="px-1 text-control-light hover:bg-control-bg-hover"
+ aria-label={t("agent.new-chat")}
+ disabled={isChatCreationDisabled}
+ onClick={createChat}
+ >
+ <Plus
+ className="size-3.5"
+ aria-hidden="true"
+ />
+ </Button>
+ </AgentTooltip>
+ )}
+ <AgentDropdownMenu>
+ <AgentTooltip content={t("common.more")}>
+ <AgentDropdownMenuTrigger
+ className="inline-flex size-6 items-center justify-center rounded-xs text-control-light outline-hidden hover:bg-control-bg-hover focus-visible:ring-2 focus-visible:ring-accent disabled:pointer-events-none disabled:opacity-50"
+ aria-label={t("common.more")}
+ onClick={(event) => event.stopPropagation()}
+ >
+ <EllipsisVertical
+ className="size-3.5"
+ aria-hidden="true"
+ />
+ </AgentDropdownMenuTrigger>
+ </AgentTooltip>
+ <AgentDropdownMenuContent>
+ {showArchivedOnly ? (
+ <>
+ <AgentDropdownMenuItem
+ data-agent-unarchive-all-chats
+ disabled={isUnarchiveAllDisabled}
+ onClick={(event) => {
+ event.stopPropagation();
+ unarchiveAllChats();
+ }}
+ >
+ {t("agent.unarchive-all-chats")}
+ </AgentDropdownMenuItem>
+ <AgentDropdownMenuItem
+ data-agent-delete-all-chats
+ className="text-error data-highlighted:bg-error/10"
+ disabled={isDeleteAllDisabled}
+ onClick={(event) => {
+ event.stopPropagation();
+ setIsDeleteAllArchivedChatsDialogOpen(
+ true
+ );
+ }}
+ >
+ {t("agent.delete-all-chats")}
+ </AgentDropdownMenuItem>
+ </>
+ ) : (
+ <AgentDropdownMenuItem
+ data-agent-archive-all-chats
+ disabled={isArchiveAllDisabled}
+ onClick={(event) => {
+ event.stopPropagation();
+ archiveAllChats();
+ }}
>
- <Undo2
- className="size-3.5"
- aria-hidden="true"
- />
- </SidebarIconButton>
- <ConfirmDialog
- message={t(
- "agent.delete-chat-confirmation"
- )}
- onConfirm={() => deleteChat(chat.id)}
- triggerLabel={t("agent.delete-chat")}
- triggerDataAttr="data-agent-delete-chat"
- triggerVariant="icon"
+ {t("agent.archive-all-chats")}
+ </AgentDropdownMenuItem>
+ )}
+ <AgentDropdownMenuSeparator />
+ <AgentDropdownMenuItem
+ data-agent-chat-list-mode
+ onClick={(event) => {
+ event.stopPropagation();
+ toggleChatListMode();
+ }}
+ >
+ {showArchivedOnly
+ ? t("agent.active-only-chats")
+ : t("agent.archived-only-chats")}
+ </AgentDropdownMenuItem>
+ </AgentDropdownMenuContent>
+ </AgentDropdownMenu>
+ </div>
+ )}
+ </div>
+ </div>
+
+ {/* Chat list */}
+ <div className="min-h-0 flex-1 overflow-y-auto">
+ <div className="flex flex-col" data-agent-chat-list>
+ {displayedChatGroups.map((group) => (
+ <div
+ key={group.context ?? "unscoped"}
+ className="flex flex-col"
+ data-agent-chat-group={
+ group.context ?? "unscoped"
+ }
+ >
+ <div className="flex min-w-0 items-center justify-between gap-x-2 px-3 pt-3 pb-1 text-xs font-medium text-control-light">
+ {group.context ? (
+ <div className="flex min-w-0 items-center gap-x-1.5">
+ {group.context.startsWith(
+ projectNamePrefix
+ ) ? (
+ <FolderKanban className="size-3.5 shrink-0" />
+ ) : (
+ <Building2 className="size-3.5 shrink-0" />
+ )}
+ <span className="truncate">
+ {getContextLabel(group.context)}
+ </span>
+ </div>
+ ) : (
+ <span className="truncate">
+ {t("agent.other-chats")}
+ </span>
+ )}
+ {group.context && !showArchivedOnly && (
+ <AgentTooltip
+ content={`${t("agent.new-chat")}: ${getContextLabel(group.context)}`}
+ >
+ <Button
+ appearance="secondary"
+ size="xs"
+ className="shrink-0 px-1 text-control-light hover:bg-control-bg-hover"
+ aria-label={`${t("agent.new-chat")}: ${getContextLabel(group.context)}`}
+ data-agent-new-chat-for-context={
+ group.context
+ }
+ disabled={isChatCreationDisabled}
+ onClick={() =>
+ createChatForContext(group.context!)
+ }
>
- <Trash2
+ <Plus
className="size-3.5"
aria-hidden="true"
/>
- </ConfirmDialog>
- </>
- ) : (
- <SidebarIconButton
- tooltip={t("agent.archive-chat")}
- ariaLabel={t("agent.archive-chat")}
- dataAttr="data-agent-archive-chat"
- onClick={() => archiveChat(chat.id)}
- >
- <Archive
- className="size-3.5"
- aria-hidden="true"
- />
- </SidebarIconButton>
+ </Button>
+ </AgentTooltip>
)}
</div>
+ {group.chats.map((chat) => (
+ <div
+ key={chat.id}
+ className={`group w-full rounded-xs px-3 py-2 text-left text-sm transition-colors ${
+ chat.id === currentChatId
+ ? "bg-accent/10 text-accent"
+ : "text-control hover:bg-control-bg-hover"
+ }`}
+ data-agent-chat-row={chat.id}
+ >
+ {chat.id === currentChatId &&
+ isRenamingCurrentChat ? (
+ <Input
+ ref={renameInputRef}
+ value={renamingTitle}
+ onChange={(e) =>
+ setRenamingTitle(e.target.value)
+ }
+ className="h-7 text-sm"
+ placeholder={t(
+ "agent.rename-chat-placeholder"
+ )}
+ data-agent-inline-rename-input
+ onBlur={commitRenameCurrentChat}
+ onKeyDown={onRenameKeydown}
+ />
+ ) : (
+ <div className="flex items-center gap-x-2">
+ <Button
+ appearance="secondary"
+ size="md"
+ type="button"
+ className="h-auto min-w-0 flex-1 flex-col items-start p-0 text-left whitespace-normal hover:bg-transparent disabled:cursor-not-allowed disabled:opacity-60"
+ disabled={
+ !useAgentStore
+ .getState()
+ .canSelectChat(chat.id)
+ }
+ aria-current={
+ chat.id === currentChatId
+ ? "true"
+ : undefined
+ }
+ onClick={() =>
+ handleChatRowClick(chat.id)
+ }
+ >
+ <div
+ className="w-full truncate font-medium"
+ data-agent-chat-title
+ >
+ {getChatLabel(chat)}
+ </div>
+ </Button>
+ <div className="pointer-events-none flex shrink-0 items-center gap-x-2 opacity-0 transition-opacity group-hover:pointer-events-auto group-hover:opacity-100 group-focus-within:pointer-events-auto group-focus-within:opacity-100">
+ {chat.archived ? (
+ <>
+ <SidebarIconButton
+ tooltip={t(
+ "agent.unarchive-chat"
+ )}
+ ariaLabel={t(
+ "agent.unarchive-chat"
+ )}
+ dataAttr="data-agent-unarchive-chat"
+ onClick={() =>
+ unarchiveChat(chat.id)
+ }
+ >
+ <Undo2
+ className="size-3.5"
+ aria-hidden="true"
+ />
+ </SidebarIconButton>
+ <ConfirmDialog
+ message={t(
+ "agent.delete-chat-confirmation"
+ )}
+ onConfirm={() =>
+ deleteChat(chat.id)
+ }
+ triggerLabel={t(
+ "agent.delete-chat"
+ )}
+ triggerDataAttr="data-agent-delete-chat"
+ triggerVariant="icon"
+ >
+ <Trash2
+ className="size-3.5"
+ aria-hidden="true"
+ />
+ </ConfirmDialog>
+ </>
+ ) : (
+ <SidebarIconButton
+ tooltip={t("agent.archive-chat")}
+ ariaLabel={t("agent.archive-chat")}
+ dataAttr="data-agent-archive-chat"
+ onClick={() => archiveChat(chat.id)}
+ >
+ <Archive
+ className="size-3.5"
+ aria-hidden="true"
+ />
+ </SidebarIconButton>
+ )}
+ </div>
+ </div>
+ )}
+ </div>
+ ))}
</div>
- )}
+ ))}
</div>
- ))}
- </div>
- ))}
- </div>
- </div>
- </aside>
- </Panel>
+ </div>
+ </aside>
+ </EscapePanelClip>
+ )}
+ </Panel>
+
+ {!isCompactWindow && (
+ <PanelResizeHandle
+ data-agent-sidebar-resize
+ className="group relative w-1 shrink-0 cursor-ew-resize bg-control-bg transition-colors hover:bg-accent/10"
+ >
+ <span className="pointer-events-none absolute inset-y-0 left-1/2 w-px -translate-x-1/2 bg-transparent transition-colors group-hover:bg-accent" />
+ </PanelResizeHandle>
+ )}
- {/* Sidebar resize handle */}
- <PanelResizeHandle
- data-agent-sidebar-resize
- className="group relative w-1 shrink-0 cursor-ew-resize bg-control-bg transition-colors hover:bg-accent/10"
- >
- <span className="pointer-events-none absolute inset-y-0 left-1/2 w-px -translate-x-1/2 bg-transparent transition-colors group-hover:bg-accent" />
- </PanelResizeHandle>
-
- {/* Main panel */}
- <Panel id="agent-chat-main" minSize={minMainPanelWidth}>
- <div className="flex size-full min-w-0 flex-col">
- <AgentChat className="min-h-0 flex-1" />
- <AgentInput />
- </div>
- </Panel>
- </PanelGroup>
+ {/* Main panel */}
+ <Panel id="agent-chat-main" minSize={minMainPanelWidth}>
+ <div className="relative flex size-full min-w-0 flex-col">
+ <AgentChat className="min-h-0 flex-1" />
+ <AgentInput />
+ </div>
+ </Panel>
+ </PanelGroup>
+ )}
+ {isCompactWindow && compactPanel && (
+ <Button
+ type="button"
+ appearance="secondary"
+ size="xs"
+ aria-label={t("agent.close")}
+ className="absolute inset-0 z-1 h-auto rounded-none bg-overlay/50 hover:bg-overlay/50"
+ data-agent-compact-overlay
+ onClick={() => setCompactPanel(null)}
+ />
+ )}
+ {isCompactWindow && compactPanel && renderCompactRail(true)}
+ </div>
</div>
{canResizeWindow &&
- (Object.keys(resizeZoneClasses) as ResizeDirection[]).map(
+ (Object.keys(resizeZoneClasses) as AnchoredResizeDirection[]).map(
(direction) => (
<div
key={direction}
@@ -1372,6 +1640,16 @@ export function AgentWindow() {
);
}
+function EscapePanelClip({
+ children,
+ target,
+}: Readonly<{
+ children: ReactNode;
+ target: HTMLElement | null;
+}>) {
+ return target ? createPortal(children, target) : children;
+}
+
// --- Confirmation Dialog ---
function ConfirmDialog({
diff --git a/frontend/src/modules/agent/store/agent.test.ts b/frontend/src/modules/agent/store/agent.test.ts
index 532636cfdf..53f487b124 100644
--- a/frontend/src/modules/agent/store/agent.test.ts
+++ b/frontend/src/modules/agent/store/agent.test.ts
@@ -117,21 +117,23 @@ describe("useAgentStore (Zustand)", () => {
);
});
- test("keeps agent window layout in the current workspace cache", () => {
+ test("keeps agent window size and sidebar width in the current workspace cache", () => {
const store = createAgentStore();
s(store).setWorkspaceName("workspaces/alpha");
- s(store).setPosition(320, 240);
+ s(store).setSize(680, 500);
+ s(store).setSidebarWidth(240);
s(store).saveWindowState();
expect(
localStorage.getItem(getAgentWindowKey("workspaces/alpha"))
- ).toContain('"x":320');
+ ).toContain('"width":680');
s(store).setWorkspaceName("workspaces/beta");
- expect(s(store).position).not.toEqual({ x: 320, y: 240 });
+ expect(s(store).size).not.toEqual({ width: 680, height: 500 });
s(store).setWorkspaceName("workspaces/alpha");
- expect(s(store).position).toEqual({ x: 320, y: 240 });
+ expect(s(store).size).toEqual({ width: 680, height: 500 });
+ expect(s(store).sidebarWidth).toBe(240);
});
test("migrates unscoped legacy chats to the first workspace context", () => {
@@ -462,13 +464,12 @@ describe("useAgentStore (Zustand)", () => {
expect(s(store).chats).toHaveLength(1);
});
- test("uses larger bottom-right window defaults when no saved window state exists", () => {
+ test("uses the default window size when no saved window state exists", () => {
setViewportSize(1440, 900);
const store = createAgentStore();
expect(s(store).size).toEqual({ width: 750, height: 521 });
- expect(s(store).position).toEqual({ x: 674, y: 363 });
expect(s(store).sidebarWidth).toBe(200);
});
@@ -478,7 +479,6 @@ describe("useAgentStore (Zustand)", () => {
const store = createAgentStore();
expect(s(store).size).toEqual({ width: 398, height: 400 });
- expect(s(store).position).toEqual({ x: 16, y: 34 });
});
test("moves outdated stored windows to the current default layout", () => {
@@ -496,7 +496,6 @@ describe("useAgentStore (Zustand)", () => {
const store = createAgentStore();
s(store).setWorkspaceName("workspaces/acme");
- expect(s(store).position).toEqual({ x: 674, y: 363 });
expect(s(store).size).toEqual({ width: 750, height: 521 });
expect(s(store).sidebarWidth).toBe(280);
expect(
@@ -504,7 +503,7 @@ describe("useAgentStore (Zustand)", () => {
).toContain(`"layoutVersion":${AGENT_WINDOW_LAYOUT_VERSION}`);
});
- test("loads persisted window state from the current layout version", () => {
+ test("loads persisted window size and sidebar while dropping legacy position", () => {
localStorage.setItem(
AGENT_WINDOW_KEY,
JSON.stringify({
@@ -520,67 +519,33 @@ describe("useAgentStore (Zustand)", () => {
s(store).loadWindowState();
expect(s(store).sidebarWidth).toBe(280);
- expect(s(store).position).toEqual({ x: 120, y: 240 });
expect(s(store).size).toEqual({ width: 480, height: 640 });
expect(
- localStorage.getItem(getAgentWindowKey("workspaces/acme"))
- ).toContain('"width":480');
- expect(
- localStorage.getItem(getAgentWindowKey("workspaces/acme"))
- ).toContain('"sidebarWidth":280');
+ JSON.parse(
+ localStorage.getItem(getAgentWindowKey("workspaces/acme")) ?? "{}"
+ )
+ ).toEqual({
+ layoutVersion: AGENT_WINDOW_LAYOUT_VERSION,
+ size: { width: 480, height: 640 },
+ sidebarWidth: 280,
+ });
expect(
localStorage.getItem(getAgentStateKey("workspaces/acme"))
).not.toBeNull();
});
- test("keeps persisted position when opening the agent", () => {
- setViewportSize(1440, 900);
- localStorage.setItem(
- AGENT_WINDOW_KEY,
- JSON.stringify({
- layoutVersion: AGENT_WINDOW_LAYOUT_VERSION,
- position: { x: 120, y: 140 },
- size: { width: 480, height: 540 },
- sidebarWidth: 200,
- })
- );
-
- const store = createAgentStore();
- s(store).setWorkspaceName("workspaces/acme");
-
- s(store).toggle();
-
- expect(s(store).visible).toBe(true);
- expect(s(store).position).toEqual({ x: 120, y: 140 });
- });
-
- test("keeps current position when opening the agent", () => {
+ test("keeps current window size when opening the agent", () => {
setViewportSize(1440, 900);
const store = createAgentStore();
s(store).setSize(788, 625);
- s(store).setPosition(320, 180);
s(store).toggle();
expect(s(store).visible).toBe(true);
- expect(s(store).position).toEqual({ x: 320, y: 180 });
expect(s(store).size).toEqual({ width: 788, height: 625 });
});
- test("clamps opening position using the rendered minimum size on wider viewports", () => {
- setViewportSize(1440, 900);
- const store = createAgentStore();
-
- s(store).setSize(398, 388);
- s(store).setPosition(700, 500);
-
- s(store).toggle();
-
- expect(s(store).visible).toBe(true);
- expect(s(store).position).toEqual({ x: 700, y: 484 });
- });
-
test("normalizes stale running chats on load", () => {
localStorage.setItem(
getAgentStateKey("workspaces/acme"),
diff --git a/frontend/src/modules/agent/store/agent.ts b/frontend/src/modules/agent/store/agent.ts
index a62cd0a808..8636cd1af2 100644
--- a/frontend/src/modules/agent/store/agent.ts
+++ b/frontend/src/modules/agent/store/agent.ts
@@ -14,10 +14,7 @@ import type {
Message,
ToolCall,
} from "../logic/types";
-import {
- clampAgentWindowPosition,
- getDefaultAgentWindowState,
-} from "../window";
+import { getDefaultAgentWindowState } from "../window";
export const AGENT_STATE_KEY = "bb-agent-state-v2";
export const AGENT_WINDOW_KEY = "bb-agent-window";
@@ -373,7 +370,6 @@ const normalizePersistedState = (raw: unknown): PersistedAgentState => {
export interface AgentState {
// Window state
visible: boolean;
- position: { x: number; y: number };
size: { width: number; height: number };
sidebarWidth: number;
minimized: boolean;
@@ -393,7 +389,6 @@ export interface AgentState {
toggle: () => void;
minimize: () => void;
restore: () => void;
- setPosition: (x: number, y: number) => void;
setSize: (width: number, height: number) => void;
setSidebarWidth: (width: number) => void;
@@ -582,7 +577,6 @@ const getSafeStorage = (): Storage | null => {
const getInitialWindowState = () => {
if (typeof window === "undefined") {
return {
- position: { x: 0, y: 0 },
size: { width: 480, height: 540 },
sidebarWidth: 200,
};
@@ -777,7 +771,6 @@ export const createAgentStore = () => {
return {
// Window state
visible: false,
- position: initialWindowState.position,
size: initialWindowState.size,
sidebarWidth: initialWindowState.sidebarWidth,
minimized: false,
@@ -797,30 +790,12 @@ export const createAgentStore = () => {
set((state) => {
state.visible = true;
state.minimized = false;
- if (typeof window !== "undefined") {
- state.position = clampAgentWindowPosition(
- window.innerWidth,
- window.innerHeight,
- state.size.width,
- state.size.height,
- state.position
- );
- }
}),
toggle: () =>
set((state) => {
state.visible = !state.visible;
if (state.visible) {
state.minimized = false;
- if (typeof window !== "undefined") {
- state.position = clampAgentWindowPosition(
- window.innerWidth,
- window.innerHeight,
- state.size.width,
- state.size.height,
- state.position
- );
- }
}
}),
minimize: () =>
@@ -831,10 +806,6 @@ export const createAgentStore = () => {
set((state) => {
state.minimized = false;
}),
- setPosition: (x, y) =>
- set((state) => {
- state.position = { x, y };
- }),
setSize: (width, height) =>
set((state) => {
state.size = { width, height };
@@ -1483,7 +1454,6 @@ export const createAgentStore = () => {
key,
JSON.stringify({
layoutVersion: AGENT_WINDOW_LAYOUT_VERSION,
- position: state.position,
size: state.size,
sidebarWidth: state.sidebarWidth,
})
@@ -1502,7 +1472,6 @@ export const createAgentStore = () => {
if (!saved) {
const defaultWindowState = getInitialWindowState();
set((draft) => {
- draft.position = defaultWindowState.position;
draft.size = defaultWindowState.size;
draft.sidebarWidth = defaultWindowState.sidebarWidth;
});
@@ -1511,24 +1480,15 @@ export const createAgentStore = () => {
try {
const state = JSON.parse(saved) as {
layoutVersion?: number;
- position?: { x?: number; y?: number };
+ position?: unknown;
size?: { width?: number; height?: number };
sidebarWidth?: number;
};
const isCurrentLayout =
state.layoutVersion === AGENT_WINDOW_LAYOUT_VERSION;
+ const hasLegacyPosition = state.position !== undefined;
const defaultWindowState = getInitialWindowState();
set((draft) => {
- if (
- isCurrentLayout &&
- typeof state.position?.x === "number" &&
- typeof state.position?.y === "number"
- ) {
- draft.position = {
- x: state.position.x,
- y: state.position.y,
- };
- }
if (
isCurrentLayout &&
typeof state.size?.width === "number" &&
@@ -1539,14 +1499,17 @@ export const createAgentStore = () => {
height: state.size.height,
};
} else if (!isCurrentLayout) {
- draft.position = defaultWindowState.position;
draft.size = defaultWindowState.size;
}
if (typeof state.sidebarWidth === "number") {
draft.sidebarWidth = state.sidebarWidth;
}
});
- if (!isCurrentLayout || !storage?.getItem(key)) {
+ if (
+ !isCurrentLayout ||
+ !storage?.getItem(key) ||
+ hasLegacyPosition
+ ) {
get().saveWindowState();
}
} catch {
@@ -1593,7 +1556,7 @@ export const createAgentStore = () => {
// Auto-persist on state changes
// Auto-persist only the chat state slice (not UI/window state).
// Uses a serialization check to avoid redundant writes during
- // drag/resize operations that only change position/size.
+ // layout-only changes such as resizing.
const lastSerializedByWorkspace = new Map<string, string>();
store.subscribe((state) => {
const storage = getSafeStorage();
diff --git a/frontend/src/modules/agent/window.ts b/frontend/src/modules/agent/window.ts
index 9f4cb98e72..0919e52540 100644
--- a/frontend/src/modules/agent/window.ts
+++ b/frontend/src/modules/agent/window.ts
@@ -26,57 +26,6 @@ const clampDefaultDimension = (
);
};
-const clampDisplayDimension = (
- size: number,
- viewportSize: number,
- preferredMin: number
-) => {
- const max = Math.max(1, viewportSize - WINDOW_MARGIN * 2);
- const min = Math.min(preferredMin, max);
- return Math.min(max, Math.max(min, Math.round(size)));
-};
-
-export const getCenteredAgentWindowPosition = (
- viewportWidth: number,
- viewportHeight: number,
- windowWidth: number,
- windowHeight: number
-) => {
- const width = clampDisplayDimension(windowWidth, viewportWidth, MIN_WIDTH);
- const height = clampDisplayDimension(
- windowHeight,
- viewportHeight,
- MIN_HEIGHT
- );
-
- return {
- x: Math.max(WINDOW_MARGIN, Math.round((viewportWidth - width) / 2)),
- y: Math.max(WINDOW_MARGIN, Math.round((viewportHeight - height) / 2)),
- };
-};
-
-export const clampAgentWindowPosition = (
- viewportWidth: number,
- viewportHeight: number,
- windowWidth: number,
- windowHeight: number,
- position: { x: number; y: number }
-) => {
- const width = clampDisplayDimension(windowWidth, viewportWidth, MIN_WIDTH);
- const height = clampDisplayDimension(
- windowHeight,
- viewportHeight,
- MIN_HEIGHT
- );
- const maxX = Math.max(WINDOW_MARGIN, viewportWidth - width - WINDOW_MARGIN);
- const maxY = Math.max(WINDOW_MARGIN, viewportHeight - height - WINDOW_MARGIN);
-
- return {
- x: Math.min(maxX, Math.max(WINDOW_MARGIN, Math.round(position.x))),
- y: Math.min(maxY, Math.max(WINDOW_MARGIN, Math.round(position.y))),
- };
-};
-
export const getDefaultAgentWindowState = (
viewportWidth: number,
viewportHeight: number
@@ -97,16 +46,6 @@ export const getDefaultAgentWindowState = (
);
return {
- position: clampAgentWindowPosition(
- viewportWidth,
- viewportHeight,
- width,
- height,
- {
- x: viewportWidth - width - WINDOW_MARGIN,
- y: viewportHeight - height - WINDOW_MARGIN,
- }
- ),
size: {
width,
height,