Skip to content

#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere

Improve UI of Stirling Agent (#8385)

James Bruntond9dbfe22c7ab
diff --git a/frontend/editor/public/locales/en-US/translation.toml b/frontend/editor/public/locales/en-US/translation.toml
index ef55dc295c..53b10ddd01 100644
--- a/frontend/editor/public/locales/en-US/translation.toml
+++ b/frontend/editor/public/locales/en-US/translation.toml
@@ -1939,9 +1939,6 @@ wrapUp = "That's the admin tour! You've seen the enterprise features that make S
admin = "Admin"
title = "User Control Settings"
-[agents]
-stirling_name = "Stirling"
-
[alphabetOptions]
arabic = "Arabic"
chinese = "Chinese (Simplified)"
@@ -3219,17 +3216,16 @@ text = "To make these permissions unchangeable, use the Add Password tool to set
[chat.actions]
copy = "Copy message"
-[chat.fab]
-close = "Close chat"
-open = "Open Stirling AI assistant"
+[chat.dock]
+collapse = "Collapse chat"
+placeholder = "Ask Stirling Agent"
+title = "Stirling Agent"
[chat.header]
-agentMenu = "Stirling agent options"
clearChat = "Clear chat"
[chat.input]
disclaimer = "AI can make mistakes. Be sure to verify the output before sharing."
-placeholder = "What do you want to do?"
send = "Send message"
[chat.progress]
@@ -3260,9 +3256,7 @@ convertMany = "Convert these documents to PDF"
convertOne = "Convert this document to PDF"
heading = "Get started"
mergeMany = "Merge these {{count}} documents into 1"
-moreFiles = "+{{count}} more"
openFromComputer = "Open from computer"
-removeFile = "Remove {{name}}"
splitOne = "Split this document"
[chat.responses]
diff --git a/frontend/editor/src/core/components/chat/ChatFAB.tsx b/frontend/editor/src/core/components/chat/ChatFAB.tsx
deleted file mode 100644
index 5488213693..0000000000
--- a/frontend/editor/src/core/components/chat/ChatFAB.tsx
+++ /dev/null
@@ -1,8 +0,0 @@
-/**
- * Core stub for the floating action button chat widget.
- * The real implementation lives in proprietary/components/chat/ChatFAB.tsx
- * and shadows this via the @app/* alias cascade in proprietary builds.
- */
-export function ChatFAB() {
- return null;
-}
diff --git a/frontend/editor/src/core/components/chat/ChatPanel.tsx b/frontend/editor/src/core/components/chat/ChatPanel.tsx
deleted file mode 100644
index 0d85c23fcc..0000000000
--- a/frontend/editor/src/core/components/chat/ChatPanel.tsx
+++ /dev/null
@@ -1,14 +0,0 @@
-/**
- * Core stub for the chat panel.
- * The real implementation lives in proprietary/components/chat/ChatPanel.tsx
- * and shadows this via the @app/* alias cascade in proprietary builds.
- */
-
-export interface ChatPanelProps {
- onBack: () => void;
- backLabel: string;
-}
-
-export function ChatPanel(_props: ChatPanelProps) {
- return null;
-}
diff --git a/frontend/editor/src/core/components/chat/SidebarChat.tsx b/frontend/editor/src/core/components/chat/SidebarChat.tsx
new file mode 100644
index 0000000000..3d30ee589c
--- /dev/null
+++ b/frontend/editor/src/core/components/chat/SidebarChat.tsx
@@ -0,0 +1,7 @@
+/**
+ * AI agent docked at the foot of the file sidebar. Renders nothing here; builds
+ * that ship the agent shadow this module.
+ */
+export function SidebarChat() {
+ return null;
+}
diff --git a/frontend/editor/src/core/components/layout/Workbench.tsx b/frontend/editor/src/core/components/layout/Workbench.tsx
index 33fff48876..94dd3f50a0 100644
--- a/frontend/editor/src/core/components/layout/Workbench.tsx
+++ b/frontend/editor/src/core/components/layout/Workbench.tsx
@@ -25,7 +25,6 @@ import { useTitleBarStrip } from "@app/contexts/TitleBarStripContext";
import WorkbenchFloatingSearch from "@app/components/shared/WorkbenchFloatingSearch";
import LandingPage from "@app/components/shared/LandingPage";
import DismissAllErrorsButton from "@app/components/shared/DismissAllErrorsButton";
-import { ChatFAB } from "@app/components/chat/ChatFAB";
import { NotificationBell } from "@app/components/notifications/NotificationBell";
// Workbench panels are loaded on demand. Viewer pulls in pdfjs-dist and the
@@ -270,9 +269,6 @@ export default function Workbench() {
{/* Dismiss All Errors Button */}
<DismissAllErrorsButton />
- {/* Floating AI chat button + panel */}
- {currentView !== "myFiles" && currentView !== "signing" && <ChatFAB />}
-
{/* Main content area */}
<Box
className={`flex-1 min-h-0 z-10 ${currentView === "pageEditor" ? "relative flex flex-col" : `relative ${styles.workbenchScrollable}`}`}
diff --git a/frontend/editor/src/core/components/shared/FileSidebar.css b/frontend/editor/src/core/components/shared/FileSidebar.css
index 2fa20b3970..74c3bcb322 100644
--- a/frontend/editor/src/core/components/shared/FileSidebar.css
+++ b/frontend/editor/src/core/components/shared/FileSidebar.css
@@ -18,11 +18,12 @@
gap: var(--nav-gutter);
}
+/* Its minimum is the header and action rows, so a row below that grows
+ squeezes only the file list and never overlaps them. */
.file-sidebar-inner {
display: flex;
flex-direction: column;
flex: 1;
- min-height: 0;
gap: 0.5rem;
}
@@ -106,7 +107,9 @@
flex-shrink: 0;
}
.file-sidebar-files-box {
- flex: 1;
+ /* A length basis, not flex: 1's 0%, which intrinsic sizing reads as the
+ content height and would put the whole list into the column's minimum. */
+ flex: 1 1 0;
min-height: 0;
display: flex;
flex-direction: column;
diff --git a/frontend/editor/src/core/components/shared/FileSidebar.tsx b/frontend/editor/src/core/components/shared/FileSidebar.tsx
index 41f6b996e2..d735d725e1 100644
--- a/frontend/editor/src/core/components/shared/FileSidebar.tsx
+++ b/frontend/editor/src/core/components/shared/FileSidebar.tsx
@@ -50,6 +50,7 @@ import { DeleteFilesDialog } from "@app/components/filesPage/DeleteFilesDialog";
import { RenameFileDialog } from "@app/components/shared/RenameFileDialog";
import { duplicateStoredFile } from "@app/utils/duplicateFile";
import { SidebarChecklistSlot } from "@app/components/shared/SidebarChecklistSlot";
+import { SidebarChat } from "@app/components/chat/SidebarChat";
import {
deleteServerFile,
type DeleteScope,
@@ -1226,6 +1227,8 @@ const FileSidebar = forwardRef<HTMLDivElement, FileSidebarProps>(
credits={credits}
onOpenPlan={openPlan ?? undefined}
/>
+
+ {currentWorkbench !== "myFiles" && <SidebarChat />}
</div>
);
},
diff --git a/frontend/editor/src/core/styles/zIndex.ts b/frontend/editor/src/core/styles/zIndex.ts
index 1e673c7035..fb4ee8c9d6 100644
--- a/frontend/editor/src/core/styles/zIndex.ts
+++ b/frontend/editor/src/core/styles/zIndex.ts
@@ -14,9 +14,6 @@ export const Z_INDEX_OVER_SETTINGS_MODAL = 1500;
export const Z_INDEX_FILE_MANAGER_MODAL = 1200;
-// Chat FAB overlay — sits above normal app chrome (fullscreen surface: 1000)
-// but below all modals (automate: 1100, file manager: 1200, config: 1400).
-export const Z_INDEX_CHAT_FAB_OVERLAY = 1050;
export const Z_INDEX_OVER_FILE_MANAGER_MODAL = 1300;
export const Z_INDEX_AUTOMATE_MODAL = 1100;
diff --git a/frontend/editor/src/core/tests/stubbed/sidebar-chat.spec.ts b/frontend/editor/src/core/tests/stubbed/sidebar-chat.spec.ts
new file mode 100644
index 0000000000..b59e40e856
--- /dev/null
+++ b/frontend/editor/src/core/tests/stubbed/sidebar-chat.spec.ts
@@ -0,0 +1,153 @@
+import { test, expect } from "@app/tests/helpers/stub-test-base";
+import type { Locator, Page, Route } from "@playwright/test";
+
+/** The AI agent docked at the foot of the file sidebar, and how it opens and closes. */
+
+test.use({ autoGoto: false });
+
+async function openEditorWithAi(page: Page): Promise<Locator> {
+ await page.route("**/api/v1/config/app-config", (route: Route) =>
+ route.fulfill({
+ json: {
+ enableLogin: false,
+ isAdmin: false,
+ enableAnalytics: false,
+ languages: ["en_US"],
+ defaultLocale: "en-US",
+ aiEngineEnabled: true,
+ },
+ }),
+ );
+ await page.goto("/editor", { waitUntil: "domcontentloaded" });
+ const dock = page.getByRole("region", { name: "Stirling Agent" });
+ await expect(dock).toBeVisible();
+ return dock;
+}
+
+async function dockHeight(dock: Locator): Promise<number> {
+ const box = await dock.boundingBox();
+ return box?.height ?? 0;
+}
+
+/** Waits out the expand/collapse transition so heights compare settled values. */
+async function settledHeight(dock: Locator): Promise<number> {
+ let previous = -1;
+ let current = await dockHeight(dock);
+ while (current !== previous) {
+ previous = current;
+ await dock.page().waitForTimeout(120);
+ current = await dockHeight(dock);
+ }
+ return current;
+}
+
+test("sits collapsed as just the composer", async ({ page }) => {
+ const dock = await openEditorWithAi(page);
+ await expect(dock).toHaveAttribute("data-state", "collapsed");
+ await expect(
+ dock.getByRole("textbox", { name: "Ask Stirling Agent" }),
+ ).toBeVisible();
+ await expect(dock.getByRole("button", { name: "Collapse chat" })).toHaveCount(
+ 0,
+ );
+ // The collapsed conversation stays mounted but hidden from the a11y tree.
+ await expect(
+ dock.getByRole("button", { name: "Open from computer" }),
+ ).toHaveCount(0);
+
+ await dock.getByRole("textbox", { name: "Ask Stirling Agent" }).click();
+ await expect(
+ dock.getByRole("button", { name: "Open from computer" }),
+ ).toBeVisible();
+});
+
+test("opens when the composer is focused and closes only from the chevron", async ({
+ page,
+}) => {
+ const dock = await openEditorWithAi(page);
+ const collapsed = await settledHeight(dock);
+
+ await dock.getByRole("textbox", { name: "Ask Stirling Agent" }).click();
+ await expect(dock).toHaveAttribute("data-state", "expanded");
+ expect(await settledHeight(dock)).toBeGreaterThan(collapsed + 100);
+
+ await page
+ .locator('[data-tour="workbench"]')
+ .click({ position: { x: 40, y: 200 } });
+ await expect(dock).toHaveAttribute("data-state", "expanded");
+
+ await dock.getByRole("button", { name: "Collapse chat" }).click();
+ await expect(dock).toHaveAttribute("data-state", "collapsed");
+ expect(await settledHeight(dock)).toBe(collapsed);
+
+ await dock.getByRole("textbox", { name: "Ask Stirling Agent" }).click();
+ await expect(dock).toHaveAttribute("data-state", "expanded");
+});
+
+test("rules the header once messages scroll beneath it", async ({ page }) => {
+ const answer = Array.from({ length: 40 }, (_, i) => `Line ${i + 1}`).join(
+ "\n\n",
+ );
+ await page.route("**/api/v1/ai/orchestrate/stream", (route: Route) =>
+ route.fulfill({
+ headers: { "content-type": "text/event-stream" },
+ body: `event: result\ndata: ${JSON.stringify({ outcome: "answer", answer })}\n\n`,
+ }),
+ );
+ const dock = await openEditorWithAi(page);
+ const header = dock.locator(".file-sidebar-section-header");
+ await expect(header).not.toHaveAttribute("data-scrolled");
+
+ const composer = dock.getByRole("textbox", { name: "Ask Stirling Agent" });
+ await composer.click();
+ await composer.fill("List forty lines");
+ await composer.press("Enter");
+ await expect(dock.getByText("Line 40")).toBeVisible();
+ await expect(header).toHaveAttribute("data-scrolled");
+
+ await dock.getByRole("button", { name: "Collapse chat" }).click();
+ await expect(header).not.toHaveAttribute("data-scrolled");
+});
+
+test("accepts typing while the agent is thinking but holds the send", async ({
+ page,
+}) => {
+ let releaseReply = () => {};
+ const replyReleased = new Promise<void>((resolve) => {
+ releaseReply = resolve;
+ });
+ let requests = 0;
+ await page.route("**/api/v1/ai/orchestrate/stream", async (route: Route) => {
+ requests += 1;
+ await replyReleased;
+ await route.fulfill({
+ headers: { "content-type": "text/event-stream" },
+ body: `event: result\ndata: ${JSON.stringify({ outcome: "answer", answer: "Done." })}\n\n`,
+ });
+ });
+ const dock = await openEditorWithAi(page);
+ const composer = dock.getByRole("textbox", { name: "Ask Stirling Agent" });
+ const send = dock.getByRole("button", { name: "Send message" });
+ await composer.click();
+ await composer.fill("First");
+ await composer.press("Enter");
+
+ await composer.fill("Second");
+ await expect(composer).toHaveValue("Second");
+ await expect(send).toBeDisabled();
+ await composer.press("Enter");
+ await expect(composer).toHaveValue("Second");
+
+ releaseReply();
+ await expect(dock.getByText("Done.")).toBeVisible();
+ await expect(send).toBeEnabled();
+ expect(requests).toBe(1);
+});
+
+test("is absent when the AI engine is off", async ({ page }) => {
+ await page.goto("/editor", { waitUntil: "domcontentloaded" });
+ await expect(page.locator('[data-sidebar="file-sidebar"]')).toBeVisible();
+ await expect(
+ page.getByRole("region", { name: "Stirling Agent" }),
+ ).toHaveCount(0);
+});
diff --git a/frontend/editor/src/core/ui/ChatFABButton.css b/frontend/editor/src/core/ui/ChatFABButton.css
deleted file mode 100644
index b68713aa1f..0000000000
--- a/frontend/editor/src/core/ui/ChatFABButton.css
+++ /dev/null
@@ -1,143 +0,0 @@
-.chat-fab-btn {
- display: flex;
- align-items: center;
- justify-content: center;
- width: 56px;
- height: 56px;
- border-radius: 16px;
- border: 1px solid var(--c-btn-secondary-border);
- background: var(--c-btn-secondary);
- cursor: pointer;
- box-shadow: var(--shadow-md);
- transition:
- transform 180ms cubic-bezier(0.32, 0.72, 0, 1),
- box-shadow 180ms ease;
- position: relative;
- outline-offset: 3px;
- flex-shrink: 0;
-}
-
-.chat-fab-btn:hover {
- transform: scale(1.09);
- box-shadow: var(--shadow-lg);
-}
-
-.chat-fab-btn:active {
- transform: scale(0.96);
- transition-duration: 90ms;
-}
-
-/* Animated logo paths when the agent is actively working */
-.chat-fab-btn--loading svg path:first-child {
- animation: chat-fab-logo-right 2s ease-in-out infinite;
-}
-
-.chat-fab-btn--loading svg path:last-child {
- animation: chat-fab-logo-left 2s ease-in-out infinite;
-}
-
-@keyframes chat-fab-logo-right {
- 0%,
- 100% {
- transform: translate(0, 0);
- opacity: 0.5;
- }
- 25% {
- transform: translate(-1px, -5px);
- opacity: 0.45;
- }
- 50% {
- transform: translate(-6px, 0);
- opacity: 0.9;
- }
- 75% {
- transform: translate(-1px, 5px);
- opacity: 0.55;
- }
-}
-
-@keyframes chat-fab-logo-left {
- 0%,
- 100% {
- transform: translate(0, 0);
- opacity: 1;
- }
- 25% {
- transform: translate(1px, 5px);
- opacity: 0.85;
- }
- 50% {
- transform: translate(6px, 0);
- opacity: 0.5;
- }
- 75% {
- transform: translate(1px, -5px);
- opacity: 0.85;
- }
-}
-
-/* Green pulse dot when the agent is actively working */
-.chat-fab-btn__pulse {
- position: absolute;
- top: 9px;
- right: 9px;
- width: 8px;
- height: 8px;
- border-radius: 50%;
- background: var(--c-success);
- animation: chat-fab-pulse 1.5s ease-in-out infinite;
-}
-
-@keyframes chat-fab-pulse {
- 0%,
- 100% {
- transform: scale(1);
- opacity: 1;
- }
- 50% {
- transform: scale(1.35);
- opacity: 0.65;
- }
-}
-
-/* Tick badge shown when there's an unread result */
-.chat-fab-btn__tick {
- position: absolute;
- top: 9px;
- right: 9px;
- width: 16px;
- height: 16px;
- border-radius: 50%;
- background: var(--c-success);
- display: flex;
- align-items: center;
- justify-content: center;
- animation: chat-fab-tick-in 220ms cubic-bezier(0.32, 0.72, 0, 1) both;
-}
-
-@keyframes chat-fab-tick-in {
- from {
- transform: scale(0);
- opacity: 0;
- }
- to {
- transform: scale(1);
- opacity: 1;
- }
-}
-
-@media (prefers-reduced-motion: reduce) {
- .chat-fab-btn {
- transition: none;
- }
- .chat-fab-btn__pulse {
- animation: none;
- }
- .chat-fab-btn--loading svg path:first-child,
- .chat-fab-btn--loading svg path:last-child {
- animation: none;
- }
- .chat-fab-btn__tick {
- animation: none;
- }
-}
diff --git a/frontend/editor/src/core/ui/ChatFABButton.stories.tsx b/frontend/editor/src/core/ui/ChatFABButton.stories.tsx
deleted file mode 100644
index 5e85738b57..0000000000
--- a/frontend/editor/src/core/ui/ChatFABButton.stories.tsx
+++ /dev/null
@@ -1,37 +0,0 @@
-import type { Meta, StoryObj } from "@storybook/react-vite";
-import { ChatFABButton } from "@app/ui/ChatFABButton";
-
-const meta: Meta<typeof ChatFABButton> = {
- title: "Editor/ChatFAB/ChatFABButton",
- component: ChatFABButton,
- parameters: { layout: "centered" },
- argTypes: {
- loading: { control: "boolean" },
- showTick: { control: "boolean" },
- onClick: { action: "clicked" },
- },
-};
-export default meta;
-type Story = StoryObj<typeof ChatFABButton>;
-
-/** Default idle state — no agent running, no unread result. */
-export const Default: Story = {};
-
-/** Agent is actively working — the logo paths animate and a green pulse dot appears. */
-export const Loading: Story = {
- args: { loading: true },
-};
-
-/** Agent finished while the panel was closed — tick badge pops in to signal an unread result. */
-export const Tick: Story = {
- args: { showTick: true },
-};
-
-/**
- * If loading restarts while a tick is already showing, the pulse dot is
- * suppressed in favour of the tick until the user opens the panel.
- * In practice this transition is handled by the parent via `hasUnviewedResult`.
- */
-export const TickWhileLoading: Story = {
- args: { loading: true, showTick: true },
-};
diff --git a/frontend/editor/src/core/ui/ChatFABButton.tsx b/frontend/editor/src/core/ui/ChatFABButton.tsx
deleted file mode 100644
index f1de1b88e8..0000000000
--- a/frontend/editor/src/core/ui/ChatFABButton.tsx
+++ /dev/null
@@ -1,56 +0,0 @@
-import type { ButtonHTMLAttributes } from "react";
-import { Icon } from "@app/ui/Icon";
-import { useTranslation } from "react-i18next";
-import { BrandMark } from "@app/components/shared/BrandMark";
-import "@app/ui/ChatFABButton.css";
-
-export interface ChatFABButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
- /** Green pulse dot — agent is working. */
- loading?: boolean;
- /** Green tick badge — unread result waiting. */
- showTick?: boolean;
-}
-
-export function ChatFABButton({
- loading = false,
- showTick = false,
- className,
- ...rest
-}: ChatFABButtonProps) {
- const { t } = useTranslation();
- const classes = [
- "chat-fab-btn",
- loading ? "chat-fab-btn--loading" : "",
- showTick ? "chat-fab-btn--tick" : "",
- className ?? "",
- ]
- .filter(Boolean)
- .join(" ");
-
- return (
- <button
- type="button"
- className={classes}
- aria-label={t("portal.assistant.open", "Open assistant")}
- {...rest}
- >
- {/* Decorative: the button itself carries the accessible name. */}
- <span aria-hidden="true" style={{ display: "inline-flex" }}>
- <BrandMark height="1.875rem" />
- </span>
- {loading && !showTick && (
- <span className="chat-fab-btn__pulse" aria-hidden="true" />
- )}
- {showTick && (
- <span className="chat-fab-btn__tick" aria-hidden="true">
- <Icon
- name="check"
- size={10}
- strokeWidth={2.5}
- style={{ color: "white" }}
- />
- </span>
- )}
- </button>
- );
-}
diff --git a/frontend/editor/src/core/ui/ChatFABWindow.css b/frontend/editor/src/core/ui/ChatFABWindow.css
deleted file mode 100644
index 6f281d8252..0000000000
--- a/frontend/editor/src/core/ui/ChatFABWindow.css
+++ /dev/null
@@ -1,43 +0,0 @@
-.chat-fab-window {
- position: relative;
- display: flex;
- flex-direction: column;
- width: 100%;
- height: 100%;
- /* Use Mantine variables in the editor; fall back to shared tokens in storybook */
- background: var(--mantine-color-body, var(--c-surface));
- border-radius: 16px;
- border: 1px solid var(--c-border-subtle, var(--c-border));
- box-shadow:
- 0 8px 32px rgba(0, 0, 0, 0.14),
- 0 2px 8px rgba(0, 0, 0, 0.06);
- overflow: hidden;
-
- /* Closed state: collapsed toward bottom-right origin */
- opacity: 0;
- transform: scale(0.9);
- pointer-events: none;
- transform-origin: bottom right;
- transition:
- opacity 200ms ease,
- transform 220ms cubic-bezier(0.32, 0.72, 0, 1);
-}
-
-.chat-fab-window--open {
- opacity: 1;
- transform: scale(1);
- pointer-events: auto;
-}
-
-[data-mantine-color-scheme="dark"] .chat-fab-window,
-[data-theme="dark"] .chat-fab-window {
- box-shadow:
- 0 8px 32px rgba(0, 0, 0, 0.38),
- 0 2px 8px rgba(0, 0, 0, 0.22);
-}
-
-@media (prefers-reduced-motion: reduce) {
- .chat-fab-window {
- transition: opacity 100ms ease;
- }
-}
diff --git a/frontend/editor/src/core/ui/ChatFABWindow.stories.tsx b/frontend/editor/src/core/ui/ChatFABWindow.stories.tsx
deleted file mode 100644
index 33b855c8d8..0000000000
--- a/frontend/editor/src/core/ui/ChatFABWindow.stories.tsx
+++ /dev/null
@@ -1,145 +0,0 @@
-import type { Meta, StoryObj } from "@storybook/react-vite";
-import { useState } from "react";
-import { ChatFABWindow } from "@app/ui/ChatFABWindow";
-
-const DEMO_MESSAGES = [
- {
- id: 1,
- role: "user" as const,
- text: "Merge the three contracts and redact all SSNs",
- },
- {
- id: 2,
- role: "assistant" as const,
- text: "I'll merge the PDFs first, then run redaction on the combined document. Starting now…",
- },
- { id: 3, role: "user" as const, text: "Great, also add a watermark" },
-];
-
-function MockChat() {
- return (
- <div
- style={{
- display: "flex",
- flexDirection: "column",
- height: "100%",
- fontFamily: "system-ui, sans-serif",
- }}
- >
- <div
- style={{
- padding: "14px 16px 10px",
- borderBottom: "1px solid var(--c-border)",
- fontSize: 14,
- fontWeight: 600,
- }}
- >
- Stirling
- </div>
- <div
- style={{
- flex: 1,
- overflowY: "auto",
- padding: "12px 16px",
- display: "flex",
- flexDirection: "column",
- gap: 10,
- }}
- >
- {DEMO_MESSAGES.map((m) => (
- <div
- key={m.id}
- style={{
- alignSelf: m.role === "user" ? "flex-end" : "flex-start",
- maxWidth: "80%",
- background:
- m.role === "user"
- ? "var(--c-accent-solid)"
- : "var(--c-surface-sunken)",
- color: m.role === "user" ? "#fff" : "inherit",
- borderRadius: 10,
- padding: "8px 12px",
- fontSize: 13,
- }}
- >
- {m.text}
- </div>
- ))}
- </div>
- <div
- style={{
- padding: "10px 12px 14px",
- borderTop: "1px solid var(--c-border)",
- }}
- >
- <div
- style={{
- background: "var(--c-surface-sunken)",
- borderRadius: 10,
- padding: "8px 12px",
- fontSize: 13,
- color: "var(--c-text-subtle)",
- }}
- >
- What do you want to do?
- </div>
- </div>
- </div>
- );
-}
-
-const meta: Meta<typeof ChatFABWindow> = {
- title: "Editor/ChatFAB/ChatFABWindow",
- component: ChatFABWindow,
- parameters: { layout: "centered" },
- decorators: [
- (S) => (
- <div style={{ width: 390, height: 520 }}>
- <S />
- </div>
- ),
- ],
- argTypes: {
- open: { control: "boolean" },
- },
-};
-export default meta;
-type Story = StoryObj<typeof ChatFABWindow>;
-
-export const Closed: Story = {
- args: { open: false, children: <MockChat /> },
-};
-
-export const Open: Story = {
- args: { open: true, children: <MockChat /> },
-};
-
-export const Toggle: Story = {
- render: () => {
- const [open, setOpen] = useState(false);
- return (
- <div style={{ width: 390, height: 520, position: "relative" }}>
- <ChatFABWindow open={open}>
- <MockChat />
- </ChatFABWindow>
- <button
- type="button"
- onClick={() => setOpen((v) => !v)}
- style={{
- position: "absolute",
- bottom: -48,
- right: 0,
- background: "var(--c-accent-solid)",
- color: "#fff",
- border: "none",
- borderRadius: 8,
- padding: "8px 16px",
- cursor: "pointer",
- }}
- >
- {open ? "Close panel" : "Open panel"}
- </button>
- </div>
- );
- },
-};
diff --git a/frontend/editor/src/core/ui/ChatFABWindow.tsx b/frontend/editor/src/core/ui/ChatFABWindow.tsx
deleted file mode 100644
index 84231b4e9d..0000000000
--- a/frontend/editor/src/core/ui/ChatFABWindow.tsx
+++ /dev/null
@@ -1,49 +0,0 @@
-import type { CSSProperties, MouseEventHandler, ReactNode } from "react";
-import "@app/ui/ChatFABWindow.css";
-
-export interface ChatFABWindowProps {
- /** Whether the window is in its expanded/visible state. Controls the CSS transition. */
- open: boolean;
- children: ReactNode;
- className?: string;
- style?: CSSProperties;
- onDoubleClick?: MouseEventHandler<HTMLDivElement>;
-}
-
-/**
- * Visual frame for the floating chat panel.
- *
- * Renders a card shell (rounded corners, shadow, border) that animates in and
- * out via CSS transitions. The caller controls open/closed state; this component
- * owns only the appearance and animation — no drag logic, no context.
- */
-export function ChatFABWindow({
- open,
- children,
- className,
- style,
- onDoubleClick,
-}: ChatFABWindowProps) {
- const classes = [
- "chat-fab-window",
- open ? "chat-fab-window--open" : "",
- className ?? "",
- ]
- .filter(Boolean)
- .join(" ");
-
- return (
- // The closed panel stays mounted so it can animate, so `inert` is what keeps
- // its controls out of the tab order while aria-hidden keeps them off the
- // accessibility tree.
- <div
- className={classes}
- style={style}
- aria-hidden={!open}
- inert={!open}
- onDoubleClick={onDoubleClick}
- >
- {children}
- </div>
- );
-}
diff --git a/frontend/editor/src/portal/components/ChatFABWidget.stories.tsx b/frontend/editor/src/portal/components/ChatFABWidget.stories.tsx
deleted file mode 100644
index e7d2584915..0000000000
--- a/frontend/editor/src/portal/components/ChatFABWidget.stories.tsx
+++ /dev/null
@@ -1,359 +0,0 @@
-import type { Meta, StoryObj } from "@storybook/react-vite";
-import { useRef, useState } from "react";
-import { Button } from "@app/ui/Button";
-import { ChatFABButton } from "@app/ui/ChatFABButton";
-import { ChatFABWindow } from "@app/ui/ChatFABWindow";
-
-/**
- * Full ChatFAB widget demo — composed from ChatFABButton + ChatFABWindow.
- *
- * This story simulates the open/close interaction as it looks in the editor
- * without needing the full editor context. The real implementation wires
- * these same components to ChatContext and react-rnd for dragging.
- */
-
-interface MockMessage {
- id: number;
- role: "user" | "assistant";
- text: string;
-}
-
-const INITIAL_MESSAGES: MockMessage[] = [
- {
- id: 1,
- role: "user",
- text: "Merge the three contracts and redact all SSNs",
- },
- {
- id: 2,
- role: "assistant",
- text: "I'll merge the PDFs first, then run automatic PII redaction on the combined document.",
- },
-];
-
-function MockChatContent({
- messages,
- onClose,
-}: {
- messages: MockMessage[];
- onClose: () => void;
-}) {
- return (
- <div
- style={{
- display: "flex",
- flexDirection: "column",
- height: "100%",
- fontFamily: "system-ui, sans-serif",
- fontSize: 14,
- }}
- >
- {/* Header — acts as drag handle in the real implementation */}
- <div
- style={{
- display: "flex",
- alignItems: "center",
- justifyContent: "space-between",
- padding: "14px 16px 10px",
- borderBottom: "1px solid var(--c-border)",
- flexShrink: 0,
- }}
- >
- <span style={{ fontWeight: 600 }}>Stirling</span>
- <Button
- variant="tertiary"
- shape="circle"
- onClick={onClose}
- aria-label="Close chat"
- style={{ color: "var(--c-text-subtle)" }}
- >
- ✕
- </Button>
- </div>
-
- {/* Messages */}
- <div
- style={{
- flex: 1,
- overflowY: "auto",
- padding: "12px 16px",
- display: "flex",
- flexDirection: "column",
- gap: 10,
- }}
- >
- {messages.map((m) => (
- <div
- key={m.id}
- style={{
- alignSelf: m.role === "user" ? "flex-end" : "flex-start",
- maxWidth: "82%",
- background:
- m.role === "user"
- ? "var(--c-accent-solid)"
- : "var(--c-surface-sunken)",
- color: m.role === "user" ? "#fff" : "inherit",
- borderRadius: 10,
- padding: "8px 12px",
- fontSize: 13,
- lineHeight: 1.5,
- }}
- >
- {m.text}
- </div>
- ))}
- </div>
-
- {/* Input */}
- <div
- style={{
- padding: "10px 12px 14px",
- borderTop: "1px solid var(--c-border)",
- flexShrink: 0,
- }}
- >
- <div
- style={{
- background: "var(--c-surface-sunken)",
- borderRadius: 10,
- padding: "8px 12px",
- fontSize: 13,
- color: "var(--c-text-subtle)",
- }}
- >
- What do you want to do?
- </div>
- </div>
- </div>
- );
-}
-
-function ChatFABWidgetDemo({
- startOpen = false,
- agentLoading = false,
- showTick = false,
-}: {
- startOpen?: boolean;
- agentLoading?: boolean;
- showTick?: boolean;
-}) {
- const [open, setOpen] = useState(startOpen);
- const [hasUnviewedResult, setHasUnviewedResult] = useState(showTick);
- const messages = INITIAL_MESSAGES;
-
- return (
- /* Simulates the workbench overlay container */
- <div
- style={{
- position: "relative",
- width: "100%",
- height: "100%",
- overflow: "hidden",
- background: "var(--c-bg)",
- }}
- >
- {/* FAB button */}
- <ChatFABButton
- loading={agentLoading}
- showTick={hasUnviewedResult && !agentLoading}
- tabIndex={open ? -1 : 0}
- onClick={() => {
- setOpen(true);
- setHasUnviewedResult(false);
- }}
- aria-label="Open Stirling AI assistant"
- aria-expanded={open}
- style={{
- position: "absolute",
- right: 16,
- bottom: 16,
- padding: 0,
- opacity: open ? 0 : 1,
- transform: open ? "scale(0.78)" : "scale(1)",
- transition:
- "opacity 160ms ease, transform 180ms cubic-bezier(0.32, 0.72, 0, 1)",
- pointerEvents: open ? "none" : "auto",
- }}
- />
-
- {/* Chat panel */}
- <div
- style={{
- position: "absolute",
- right: 16,
- bottom: 16,
- width: 390,
- height: 520,
- }}
- >
- <ChatFABWindow open={open}>
- <MockChatContent messages={messages} onClose={() => setOpen(false)} />
- </ChatFABWindow>
- </div>
- </div>
- );
-}
-
-type FlowStep = "idle" | "loading" | "tick" | "open";
-
-function ChatFABFullFlowDemo() {
- const [step, setStep] = useState<FlowStep>("idle");
- const [open, setOpen] = useState(false);
- const [isLoading, setIsLoading] = useState(false);
- const [hasUnviewedResult, setHasUnviewedResult] = useState(false);
- const isOpenRef = useRef(open);
- isOpenRef.current = open;
-
- // Simulate agent finishing while FAB is closed → show tick
- const simulateAgentRun = () => {
- setStep("loading");
- setIsLoading(true);
- setTimeout(() => {
- setIsLoading(false);
- if (!isOpenRef.current) setHasUnviewedResult(true);
- setStep("tick");
- }, 2500);
- };
-
- const handleOpen = () => {
- setOpen(true);
- setHasUnviewedResult(false);
- setStep("open");
- };
-
- const handleClose = () => {
- setOpen(false);
- setStep("idle");
- };
-
- return (
- <div style={{ position: "relative", width: "100%", height: "100%" }}>
- {/* Step guide */}
- <div
- style={{
- position: "absolute",
- top: 16,
- left: 16,
- zIndex: 10,
- fontFamily: "system-ui, sans-serif",
- fontSize: 13,
- display: "flex",
- flexDirection: "column",
- gap: 8,
- }}
- >
- {(["idle", "loading", "tick", "open"] as FlowStep[]).map((s) => (
- <div
- key={s}
- style={{
- padding: "4px 10px",
- borderRadius: 6,
- background:
- step === s
- ? "var(--c-accent-solid)"
- : "var(--c-surface-sunken)",
- color: step === s ? "#fff" : "inherit",
- fontWeight: step === s ? 600 : 400,
- }}
- >
- {s === "idle" && "① Idle — plain icon"}
- {s === "loading" && "② Loading — animated logo + pulse"}
- {s === "tick" && "③ Unread result — tick badge"}
- {s === "open" && "④ Viewed — tick cleared"}
- </div>
- ))}
- <Button
- accent="success"
- size="sm"
- onClick={simulateAgentRun}
- disabled={isLoading || open}
- style={{ marginTop: 4 }}
- >
- Simulate agent run
- </Button>
- </div>
-
- {/* FAB button */}
- <ChatFABButton
- loading={isLoading}
- showTick={hasUnviewedResult && !isLoading}
- onClick={handleOpen}
- aria-label="Open Stirling AI assistant"
- style={{
- position: "absolute",
- right: 16,
- bottom: 16,
- padding: 0,
- opacity: open ? 0 : 1,
- transform: open ? "scale(0.78)" : "scale(1)",
- transition:
- "opacity 160ms ease, transform 180ms cubic-bezier(0.32, 0.72, 0, 1)",
- pointerEvents: open ? "none" : "auto",
- }}
- />
-
- {/* Chat panel */}
- <div
- style={{
- position: "absolute",
- right: 16,
- bottom: 16,
- width: 390,
- height: 520,
- }}
- >
- <ChatFABWindow open={open}>
- <MockChatContent messages={INITIAL_MESSAGES} onClose={handleClose} />
- </ChatFABWindow>
- </div>
- </div>
- );
-}
-
-const meta: Meta = {
- title: "Editor/ChatFAB/ChatFABWidget",
- parameters: { layout: "fullscreen" },
- decorators: [
- (S) => (
- <div style={{ minHeight: "100vh", position: "relative" }}>
- <S />
- </div>
- ),
- ],
-};
-export default meta;
-type Story = StoryObj;
-
-export const Closed: Story = {
- render: () => <ChatFABWidgetDemo startOpen={false} />,
-};
-
-export const Open: Story = {
- render: () => <ChatFABWidgetDemo startOpen={true} />,
-};
-
-/** FAB closed while the agent is running — animated logo + green pulse dot. */
-export const LoadingWhileClosed: Story = {
- render: () => <ChatFABWidgetDemo startOpen={false} agentLoading={true} />,
-};
-
-export const LoadingWhileOpen: Story = {
- render: () => <ChatFABWidgetDemo startOpen={true} agentLoading={true} />,
-};
-
-/**
- * Agent finished while the panel was closed.
- * The tick badge signals an unread result; clicking the FAB clears it.
- */
-export const UnreadResult: Story = {
- render: () => <ChatFABWidgetDemo startOpen={false} showTick={true} />,
-};
-
-/**
- * Interactive walkthrough of the full notification state machine:
- * idle → loading (animated logo) → tick badge (unread) → open (tick clears) → idle.
- * Use the "Simulate agent run" button to trigger the transition.
- */
-export const FullFlow: Story = {
- render: () => <ChatFABFullFlowDemo />,
-};
diff --git a/frontend/editor/src/proprietary/components/chat/ChatFAB.css b/frontend/editor/src/proprietary/components/chat/ChatFAB.css
deleted file mode 100644
index 01e713429a..0000000000
--- a/frontend/editor/src/proprietary/components/chat/ChatFAB.css
+++ /dev/null
@@ -1,68 +0,0 @@
-/* Overlay layer ─────────────────────────────────────────────────────────── */
-
-.chat-fab-overlay {
- position: absolute;
- inset: 0;
- pointer-events: none;
- overflow: hidden;
-}
-
-/* Bounds element — inset by FAB_GAP_PX, used as react-rnd drag+resize limit ── */
-
-.chat-fab-bounds {
- position: absolute;
- inset: 16px;
- pointer-events: none;
-}
-
-/* FAB trigger button ─────────────────────────────────────────────────────── */
-
-.chat-fab-trigger {
- position: absolute;
- right: 16px;
- bottom: 16px;
- pointer-events: auto;
- opacity: 1;
- /* Include box-shadow so the ChatFABButton hover shadow still animates */
- transition:
- opacity 160ms ease,
- transform 180ms cubic-bezier(0.32, 0.72, 0, 1),
- box-shadow 180ms ease;
-}
-
-@media (prefers-reduced-motion: reduce) {
- .chat-fab-trigger {
- transition: none;
- }
-}
-
-.chat-fab-trigger--hidden {
- opacity: 0;
- transform: scale(0.78);
- pointer-events: none;
-}
-
-/* Panel layout ───────────────────────────────────────────────────────────── */
-
-/* ChatPanel fills remaining height when inside the FAB window */
-.chat-fab-panel-rnd .chat-panel--embedded {
- flex: 1;
- height: auto;
- min-height: 0;
-}
-
-/* Header is the drag handle — grab cursor on background areas */
-.chat-fab-panel-rnd .chat-panel__header {
- cursor: grab;
- user-select: none;
-}
-
-.chat-fab-panel-rnd .chat-panel__header:active {
- cursor: grabbing;
-}
-
-/* Buttons inside the header keep their pointer cursor */
-.chat-fab-panel-rnd .chat-panel__header button,
-.chat-fab-panel-rnd .chat-panel__header [role="button"] {
- cursor: pointer;
-}
diff --git a/frontend/editor/src/proprietary/components/chat/ChatFAB.tsx b/frontend/editor/src/proprietary/components/chat/ChatFAB.tsx
deleted file mode 100644
index f1fce8fa45..0000000000
--- a/frontend/editor/src/proprietary/components/chat/ChatFAB.tsx
+++ /dev/null
@@ -1,269 +0,0 @@
-import {
- useEffect,
- useLayoutEffect,
- useRef,
- useState,
- useCallback,
-} from "react";
-import {
- createTheme,
- MantineProvider,
- Popover,
- useMantineColorScheme,
-} from "@mantine/core";
-import { Rnd } from "react-rnd";
-import { useTranslation } from "react-i18next";
-import { ChatFABButton } from "@app/ui/ChatFABButton";
-import { ChatFABWindow } from "@app/ui/ChatFABWindow";
-import { ChatPanel } from "@app/components/chat/ChatPanel";
-import { useChat } from "@app/components/chat/ChatContext";
-import { useAiEngineEnabled } from "@app/hooks/useAiEngineEnabled";
-import { useChatAccess } from "@app/hooks/useChatAccess";
-import { Z_INDEX_CHAT_FAB_OVERLAY } from "@app/styles/zIndex";
-import {
- PANEL_WIDTH_PX,
- PANEL_HEIGHT_PX,
- PANEL_MIN_WIDTH_PX,
- PANEL_MIN_HEIGHT_PX,
- RESET_MS,
- RESET_TRANSITION,
- RESIZE_HANDLES,
- clampToOverlay,
- defaultPanelPos,
-} from "@app/components/chat/chatFabLayout";
-import "@app/components/chat/ChatFAB.css";
-
-// Raise Mantine popup z-index so Menu/Popover portals appear above the FAB overlay.
-const FAB_PANEL_THEME = createTheme({
- components: {
- Popover: Popover.extend({
- defaultProps: { zIndex: Z_INDEX_CHAT_FAB_OVERLAY + 300 },
- }),
- },
-});
-
-export function ChatFAB() {
- const { t } = useTranslation();
- // Intentionally separate from useChat().isOpen — the FAB tracks its own
- // open state so it doesn't interact with the right-rail chat panel.
- const [isOpen, setIsOpen] = useState(false);
- const [hasUnviewedResult, setHasUnviewedResult] = useState(false);
- const { isLoading } = useChat();
- // Desktop sources this from the SaaS backend (cloud kill switch); web reads it
- // from the local app-config. Either way the AI engine drives FAB visibility.
- const enabled = useAiEngineEnabled();
- const requestChatAccess = useChatAccess();
-
- // Scope the panel's nested MantineProvider to this ref; unscoped it writes
- // its color scheme onto <html> and overrides the whole app's theme.
- const panelThemeRootRef = useRef<HTMLDivElement>(null);
- const { colorScheme } = useMantineColorScheme();
- const panelColorScheme = colorScheme === "dark" ? "dark" : "light";
-
- // Detect loading → done transition. If the FAB is closed when the agent
- // finishes, show the tick badge until the user opens the panel.
- const isOpenRef = useRef(isOpen);
- isOpenRef.current = isOpen;
- // Initialize to false, not isLoading: if loading is already in-flight at
- // mount we never showed the spinner, so we shouldn't show the tick on completion.
- const prevIsLoadingRef = useRef(false);
- useEffect(() => {
- const wasLoading = prevIsLoadingRef.current;
- prevIsLoadingRef.current = isLoading;
- if (wasLoading && !isLoading && !isOpenRef.current) {
- setHasUnviewedResult(true);
- }
- }, [isLoading]);
-
- const overlayRef = useRef<HTMLDivElement>(null);
- // Separate bounds element inset by FAB_GAP_PX — react-rnd enforces this
- // during both drag and resize, keeping the panel off the overlay edges.
- const [boundsEl, setBoundsEl] = useState<HTMLDivElement | null>(null);
- const boundsRef = useCallback(
- (el: HTMLDivElement | null) => setBoundsEl(el),
- [],
- );
- const [rndPos, setRndPos] = useState<{ x: number; y: number } | null>(null);
- const [rndSize, setRndSize] = useState({
- width: PANEL_WIDTH_PX,
- height: PANEL_HEIGHT_PX,
- });
- const [isAnimatingReset, setIsAnimatingReset] = useState(false);
- const resetTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
-
- // Anchored = at default home; re-homes on overlay resize. Drag/resize breaks anchor; double-click restores it.
- const [isAnchored, setIsAnchored] = useState(true);
-
- // Mirror the latest position/size/anchor into refs so the ResizeObserver below —
- // set up once — always reads current values without re-subscribing on every drag/resize.
- const rndPosRef = useRef(rndPos);
- rndPosRef.current = rndPos;
- const rndSizeRef = useRef(rndSize);
- rndSizeRef.current = rndSize;
- const isAnchoredRef = useRef(isAnchored);
- isAnchoredRef.current = isAnchored;
-
- const getDefaultPos = () => {
- const el = overlayRef.current;
- if (!el) return null;
- return defaultPanelPos(el.offsetWidth, el.offsetHeight);
- };
-
- useLayoutEffect(() => {
- // The overlay only mounts once the AI engine is enabled (config can load
- // after first render), so re-measure when that flips true rather than only
- // on initial mount, otherwise the default position never gets computed.
- if (!enabled) return;
- const pos = getDefaultPos();
- if (pos) setRndPos(pos);
- }, [enabled]);
- // ResizeObserver keeps position valid when the overlay changes size (e.g. window resize, sidebar toggle).
- useEffect(() => {
- if (!enabled) return;
- const el = overlayRef.current;
- if (!el) return;
- const observer = new ResizeObserver(() => {
- const pos = rndPosRef.current;
- if (!pos) return;
- const base = isAnchoredRef.current
- ? defaultPanelPos(el.offsetWidth, el.offsetHeight)
- : pos;
- const next = clampToOverlay(
- base,
- rndSizeRef.current,
- el.offsetWidth,
- el.offsetHeight,
- );
- if (next.x !== pos.x || next.y !== pos.y) setRndPos(next);
- });
- observer.observe(el);
- return () => observer.disconnect();
- }, [enabled]);
-
- // Clear the reset timer on unmount to avoid state updates on dead components.
- // Also ensure body user-select is restored if we unmount mid-resize.
- useEffect(() => {
- return () => {
- if (resetTimerRef.current !== null) clearTimeout(resetTimerRef.current);
- document.body.style.removeProperty("user-select");
- document.body.style.removeProperty("-webkit-user-select");
- };
- }, []);
-
- const cancelResetAnimation = () => {
- if (resetTimerRef.current !== null) {
- clearTimeout(resetTimerRef.current);
- resetTimerRef.current = null;
- }
- setIsAnimatingReset(false);
- };
-
- const handleHeaderDoubleClick = (e: React.MouseEvent<HTMLDivElement>) => {
- const target = e.target as HTMLElement;
- if (target.closest(".chat-panel__header") && !target.closest("button")) {
- const pos = getDefaultPos();
- if (!pos) return;
- if (resetTimerRef.current !== null) clearTimeout(resetTimerRef.current);
- setIsAnimatingReset(true);
- setRndPos(pos);
- setRndSize({ width: PANEL_WIDTH_PX, height: PANEL_HEIGHT_PX });
- // Back at the default home — re-enable corner-hugging on resize.
- setIsAnchored(true);
- resetTimerRef.current = setTimeout(() => {
- setIsAnimatingReset(false);
- resetTimerRef.current = null;
- }, RESET_MS + 60);
- }
- };
-
- if (!enabled) return null;
-
- return (
- <div
- ref={overlayRef}
- className="chat-fab-overlay"
- style={{ zIndex: Z_INDEX_CHAT_FAB_OVERLAY }}
- >
- {/* Inset boundary element — react-rnd uses this to constrain drag+resize */}
- <div ref={boundsRef} className="chat-fab-bounds" />
- {/* Trigger button — fades out while panel is open */}
- <ChatFABButton
- className={`chat-fab-trigger${isOpen ? " chat-fab-trigger--hidden" : ""}`}
- onClick={() => {
- if (!requestChatAccess()) return;
- // Fallback: ensure a position exists before opening, in case the
- // layout effect measured before the overlay was laid out.
- if (rndPos === null) {
- const pos = getDefaultPos();
- if (pos) setRndPos(pos);
- }
- setIsOpen(true);
- setHasUnviewedResult(false);
- }}
- aria-label={t("chat.fab.open", "Open Stirling AI assistant")}
- aria-expanded={isOpen}
- loading={isLoading}
- showTick={hasUnviewedResult && !isLoading}
- />
-
- {/* Draggable / resizable panel */}
- {rndPos !== null && boundsEl !== null && (
- <Rnd
- className="chat-fab-panel-rnd"
- position={rndPos}
- size={rndSize}
- minWidth={PANEL_MIN_WIDTH_PX}
- minHeight={PANEL_MIN_HEIGHT_PX}
- bounds={boundsEl}
- enableResizing={true}
- // Drag from the header; cancel keeps buttons inside it clickable
- dragHandleClassName="chat-panel__header"
- cancel="button, [role='button']"
- onDragStart={cancelResetAnimation}
- onDragStop={(_e, d) => {
- setRndPos({ x: d.x, y: d.y });
- // A bare click on the header fires drag start/stop without movement;
- // only break the anchor when the panel actually moved.
- if (rndPos && (d.x !== rndPos.x || d.y !== rndPos.y)) {
- setIsAnchored(false);
- }
- }}
- onResizeStart={() => {
- cancelResetAnimation();
- document.body.style.setProperty("user-select", "none");
- document.body.style.setProperty("-webkit-user-select", "none");
- }}
- onResizeStop={(_e, _dir, ref, _delta, pos) => {
- document.body.style.removeProperty("user-select");
- document.body.style.removeProperty("-webkit-user-select");
- setRndSize({ width: ref.offsetWidth, height: ref.offsetHeight });
- setRndPos(pos);
- setIsAnchored(false);
- }}
- // Invisible strips centred on the border — cursor change is the affordance.
- // zIndex: 1 lifts them above ChatFABWindow's stacking context.
- resizeHandleStyles={RESIZE_HANDLES}
- style={{
- pointerEvents: isOpen ? "auto" : "none",
- transition: isAnimatingReset ? RESET_TRANSITION : undefined,
- }}
- >
- <ChatFABWindow open={isOpen} onDoubleClick={handleHeaderDoubleClick}>
- <MantineProvider
- theme={FAB_PANEL_THEME}
- getRootElement={() => panelThemeRootRef.current ?? undefined}
- forceColorScheme={panelColorScheme}
- >
- <div ref={panelThemeRootRef} style={{ display: "contents" }}>
- <ChatPanel
- onBack={() => setIsOpen(false)}
- backLabel={t("chat.fab.close", "Close chat")}
- />
- </div>
- </MantineProvider>
- </ChatFABWindow>
- </Rnd>
- )}
- </div>
- );
-}
diff --git a/frontend/editor/src/proprietary/components/chat/ChatPanel.css b/frontend/editor/src/proprietary/components/chat/ChatPanel.css
index dab05057a6..f680656011 100644
--- a/frontend/editor/src/proprietary/components/chat/ChatPanel.css
+++ b/frontend/editor/src/proprietary/components/chat/ChatPanel.css
@@ -1,155 +1,11 @@
+/* The conversation between the dock's header and its composer. It is what
+ gives way as the dock collapses, so it clips instead of pushing the composer. */
.chat-panel {
display: flex;
flex-direction: column;
- /* Clip + allow shrink so tall welcome content squeezes the scrollable
- quick-actions block instead of pushing the composer off-screen. */
- overflow: hidden;
+ flex: 1 1 0;
min-height: 0;
- /* Match the right-rail toolbar background so dark-mode doesn't show a
- lighter card behind the chat, and so the agent-card → pill morph
- doesn't flash a different colour mid-transition. */
- background: var(--c-bg-raised);
-}
-
-.chat-panel--embedded {
- height: 100%;
- width: 100%;
-}
-
-/* Top header: agent pill + close. */
-.chat-panel__header {
- display: flex;
- align-items: center;
- gap: 0.5rem;
- padding: 1rem 1rem 0.75rem;
- flex-shrink: 0;
-}
-
-.chat-panel__agent-pill {
- display: inline-flex;
- gap: 0.5rem;
- flex: 1;
- min-width: 0;
- padding: 0.4rem 0.75rem 0.4rem 0.4rem;
- border: 1px solid var(--c-border-subtle);
- border-radius: 9999px;
- background: var(--mantine-color-body);
- cursor: pointer;
- transition:
- background 120ms ease-out,
- border-color 120ms ease-out;
-}
-
-.chat-fab-window--open .chat-panel__agent-pill {
- view-transition-name: stirling-agent;
-}
-
-/* Match the active-tool morph timing for a consistent rail feel. */
-::view-transition-group(stirling-agent),
-::view-transition-old(stirling-agent),
-::view-transition-new(stirling-agent) {
- animation-duration: 220ms;
- animation-timing-function: cubic-bezier(0.32, 0.72, 0, 1);
-}
-
-.chat-panel__agent-pill:hover {
- background: var(--mantine-color-default-hover);
-}
-
-.chat-panel__agent-pill-icon {
- display: inline-flex;
- align-items: center;
- justify-content: center;
- width: 1.75rem;
- height: 1.75rem;
- border-radius: 9999px;
- background: var(--mantine-color-blue-light);
- color: var(--c-accent-text);
- flex-shrink: 0;
- position: relative;
-}
-
-/* Running / in-progress status dot, anchored to the agent pill icon. */
-.agent-status-dot {
- position: absolute;
- bottom: 0;
- right: 0;
- width: 8px;
- height: 8px;
- border-radius: 50%;
- background: var(--mantine-color-blue-5);
- border: 1.5px solid var(--mantine-color-body);
- animation: agent-dot-pulse 2.4s ease-in-out infinite;
- pointer-events: none;
-}
-
-@keyframes agent-dot-pulse {
- 0%,
- 100% {
- opacity: 1;
- }
- 50% {
- opacity: 0.45;
- }
-}
-
-@media (prefers-reduced-motion: reduce) {
- .agent-status-dot {
- animation: none;
- }
-}
-
-.chat-panel__agent-pill--loading {
- border-color: color-mix(
- in srgb,
- var(--mantine-color-blue-5) 60%,
- var(--c-border-subtle)
- );
-}
-
-[data-mantine-color-scheme="dark"] .chat-panel__agent-pill--loading {
- border-color: color-mix(
- in srgb,
- var(--mantine-color-blue-4) 55%,
- var(--c-border-subtle)
- );
-}
-
-/* Dark-mode: let the pill blend into the rail. Just a thin border, no fill —
- so it doesn't read as a clashing lighter card on the dark toolbar. */
-[data-mantine-color-scheme="dark"] .chat-panel__agent-pill {
- background: transparent;
- border-color: var(--c-border-subtle);
-}
-
-/* The default tertiary accent is blue — use the surface text colour instead so
- the pill label and close icon don't look like interactive links. Overrides
- the Mantine button colour var the shared Button sets inline. */
-.chat-panel__header .sui-btn--tertiary {
- --button-color: var(--c-text) !important;
-}
-
-[data-mantine-color-scheme="dark"] .chat-panel__agent-pill:hover {
- background: rgba(255, 255, 255, 0.04);
-}
-
-[data-mantine-color-scheme="dark"] .chat-panel__agent-pill-icon {
- background: color-mix(
- in srgb,
- var(--mantine-color-blue-filled) 18%,
- transparent
- );
- color: var(--c-accent-text);
-}
-
-/* Same treatment for the input pill and quick-action cards. */
-[data-mantine-color-scheme="dark"] .chat-panel-input {
- background: transparent;
- box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
-}
-
-[data-mantine-color-scheme="dark"] .chat-panel-input:focus-within {
- box-shadow: 0 8px 22px color-mix(in srgb, var(--c-btn-solid) 18%, transparent);
+ overflow: hidden;
}
[data-mantine-color-scheme="dark"] .chat-quick-action {
@@ -161,16 +17,6 @@
border-color: var(--c-border-subtle);
}
-.chat-panel__agent-pill-label {
- font-size: 0.95rem;
- font-weight: 600;
- flex: 1;
- text-align: left;
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
-}
-
.chat-panel-messages {
flex: 1;
min-height: 0;
@@ -191,8 +37,8 @@
display: flex;
flex-direction: column;
gap: 0.5rem;
- padding: 0.75rem 0.75rem 0.25rem;
- /* When the panel is short, this block (file pills + actions) shrinks and
+ padding: 0.5rem 0 0.25rem;
+ /* When the panel is short, this block shrinks and
scrolls internally instead of pushing the composer off-screen — the input
must always stay pinned and visible at the bottom. */
flex-shrink: 1;
@@ -207,76 +53,6 @@
margin-bottom: 0.1rem;
}
-/* File pills shown above the quick actions when files are loaded. */
-.chat-file-pills {
- display: flex;
- flex-wrap: wrap;
- gap: 0.35rem;
- align-items: center;
-}
-
-.chat-file-pill {
- display: inline-flex;
- align-items: center;
- gap: 0.3rem;
- max-width: 11rem;
- padding: 0.2rem 0.35rem 0.2rem 0.45rem;
- border: 1px solid var(--mantine-color-blue-light);
- border-radius: 9999px;
- background: var(--mantine-color-blue-light);
- color: var(--c-accent-text);
- font-size: 0.8rem;
- font-weight: 500;
- line-height: 1.1;
-}
-
-.chat-file-pill__icon {
- flex-shrink: 0;
-}
-
-.chat-file-pill__label {
- flex: 1;
- min-width: 0;
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
-}
-
-.chat-file-pill__remove {
- display: inline-flex;
- align-items: center;
- justify-content: center;
- width: 1rem;
- height: 1rem;
- padding: 0;
- border: none;
- border-radius: 9999px;
- background: transparent;
- color: inherit;
- cursor: pointer;
- opacity: 0.7;
- transition:
- background 120ms ease-out,
- opacity 120ms ease-out;
-}
-
-.chat-file-pill__remove:hover {
- background: var(--mantine-color-default-hover);
- opacity: 1;
-}
-
-.chat-file-pill--more {
- background: transparent;
- border: 1px dashed var(--c-border-subtle);
- color: var(--c-text-subtle);
- cursor: pointer;
- padding: 0.2rem 0.55rem;
-}
-
-.chat-file-pill--more:hover {
- background: var(--mantine-color-default-hover);
-}
-
.chat-quick-action {
display: block;
width: 100%;
@@ -314,47 +90,52 @@
text-align: left;
}
-/* Input area: send button on the left, textarea fills the rest — one compact
- row so the composer stays short when the welcome screen is fully populated. */
.chat-panel-input {
display: flex;
- flex-direction: row;
align-items: center;
- gap: 0.5rem;
- padding: 0.7rem 0.8rem;
- margin: 0.75rem 0.75rem 1rem;
- border: none;
- border-radius: 1.1rem;
- background: var(--mantine-color-body);
+ gap: 0.375rem;
flex-shrink: 0;
- box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
- transition: box-shadow 160ms ease-out;
+ padding: 0.25rem 0.25rem 0.25rem 0.75rem;
+ border: 1px solid var(--c-border-subtle);
+ border-radius: 0.875rem;
+ background: var(--c-input-bg);
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
+ transition:
+ border-color 160ms ease-out,
+ box-shadow 160ms ease-out;
}
.chat-panel-input:focus-within {
- box-shadow: 0 6px 18px color-mix(in srgb, var(--c-btn-solid) 12%, transparent);
+ border-color: var(--c-border);
+ box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
}
-/* Kill the Mantine Textarea's own border/outline — the wrapper owns the chrome. */
+/* The wrapper owns the chrome, so the Mantine field's own is cleared. */
.chat-panel-input__field,
.chat-panel-input__field:focus,
.chat-panel-input__field:focus-visible {
- font-size: 1.05rem;
- padding: 0.15rem 0 !important;
+ font-size: 0.95rem;
+ /* One line plus padding matches the 30px send button. Mantine's input
+ min-height is taller, which left the text sitting high in the row. */
+ line-height: 1.375rem;
+ min-height: 0 !important;
+ padding: 0.25rem 0.125rem !important;
background: transparent !important;
border: none !important;
outline: none !important;
box-shadow: none !important;
}
-/* Textarea grows to fill the row; the send button keeps its size on the left. */
.chat-panel-input__textarea {
flex: 1;
min-width: 0;
}
-.chat-panel-input__send {
+.chat-panel-input .mantine-ActionIcon-root {
flex-shrink: 0;
+ align-self: flex-end;
+ /* Concentric with the composer's corner: its 0.875rem radius less the 0.25rem inset. */
+ --ai-radius: 0.625rem;
}
/* AI disclaimer. Two presentations share one base:
@@ -375,8 +156,8 @@
/* Welcome-screen banner: a little grey box just under the header. */
.chat-panel-disclaimer--banner {
- margin: 0.35rem 0.75rem 0;
- padding: 0.6rem 0.75rem;
+ margin: 0.25rem 0 0;
+ padding: 0.5rem 0.625rem;
border: 1px solid var(--c-border-subtle);
border-radius: 0.65rem;
background: var(--mantine-color-gray-light);
@@ -386,10 +167,11 @@
/* Compact line above the composer once the conversation has started. */
.chat-panel-disclaimer--inline {
- justify-content: center;
- padding: 0.1rem 1.25rem 0;
+ /* Inset to line up with the composer's text below. */
+ padding: 0.25rem 0.9375rem 0;
font-size: 0.7rem;
line-height: 1.3;
+ text-wrap: pretty;
}
/* Message layout */
@@ -509,24 +291,6 @@
padding: 0.2rem 0.5rem 0.35rem;
}
-[data-mantine-color-scheme="dark"] .chat-panel__header .sui-panelhdr__icon,
-.chat-panel__header .sui-panelhdr__icon {
- background: transparent;
- border: none;
-}
-
-.chat-panel__header .chat-panel__header-mark {
- width: auto;
- height: 26px;
-}
-
-/* The wordmark is an inline lockup, so in the label's line box it sits on the
- text baseline, above the mark's centre. */
-.chat-panel__header .sui-panelhdr__label {
- display: flex;
- align-items: center;
-}
-
.chat-progress-live__logo {
display: inline-flex;
align-items: center;
@@ -539,7 +303,6 @@
.chat-progress-live__label {
flex: 1;
min-width: 0;
- text-align: center;
font-size: 0.875rem;
line-height: 1.35;
background: linear-gradient(
diff --git a/frontend/editor/src/proprietary/components/chat/ChatPanel.tsx b/frontend/editor/src/proprietary/components/chat/ChatPanel.tsx
index 29a9b4287d..391e53d187 100644
--- a/frontend/editor/src/proprietary/components/chat/ChatPanel.tsx
+++ b/frontend/editor/src/proprietary/components/chat/ChatPanel.tsx
@@ -2,15 +2,18 @@ import {
useMemo,
useRef,
useEffect,
+ useLayoutEffect,
useState,
+ type FocusEvent,
type KeyboardEvent,
type ReactNode,
+ type RefCallback,
} from "react";
+import { useMergedRef } from "@mantine/hooks";
import { renderMarkdown } from "@app/components/viewer/nonpdf/MarkdownRenderer";
import { TFunction } from "i18next";
import { useTranslation } from "react-i18next";
import {
- Box,
Collapse,
Group,
Paper,
@@ -33,9 +36,6 @@ import {
import { formatRelativeTime } from "@app/utils/timeUtils";
import { useTranslatedToolCatalog } from "@app/data/useTranslatedToolRegistry";
import { StirlingLogoAnimated } from "@app/components/agents/StirlingLogoAnimated";
-import { BrandMark } from "@app/components/shared/BrandMark";
-import { Logo } from "@app/ui/Logo";
-import { PanelHeader } from "@app/ui/PanelHeader";
import { ChatQuickActions } from "@app/components/chat/ChatQuickActions";
import "@app/components/chat/ChatPanel.css";
@@ -299,6 +299,24 @@ function CompletedProgressLogDropdown({
);
}
+/**
+ * Narrows wrapped text to its longest line. Text that wraps keeps the full width
+ * on offer, so a shorter last line would leave a gap down the bubble's right side.
+ */
+function useShrinkWrap(content: string) {
+ const ref = useRef<HTMLParagraphElement>(null);
+ useLayoutEffect(() => {
+ const el = ref.current;
+ if (!el) return;
+ el.style.width = "";
+ const range = document.createRange();
+ range.selectNodeContents(el);
+ const { width } = range.getBoundingClientRect();
+ if (width > 0) el.style.width = `${Math.ceil(width)}px`;
+ }, [content]);
+ return ref;
+}
+
function ChatMessageBubble({
role,
content,
@@ -319,6 +337,7 @@ function ChatMessageBubble({
t: TranslateFn;
}) {
const [copied, setCopied] = useState(false);
+ const userTextRef = useShrinkWrap(content);
function handleCopy() {
void navigator.clipboard.writeText(content).then(() => {
@@ -349,8 +368,17 @@ function ChatMessageBubble({
return (
<div className="chat-message chat-message-user">
<div className="chat-message-user__inner">
- <Paper className="chat-bubble chat-bubble-user" p="xs" radius="md">
- <Text size="sm" style={{ whiteSpace: "pre-wrap" }}>
+ <Paper
+ className="chat-bubble chat-bubble-user"
+ px="sm"
+ py="xs"
+ radius="md"
+ >
+ <Text
+ ref={userTextRef}
+ size="sm"
+ style={{ whiteSpace: "pre-wrap" }}
+ >
{content}
</Text>
</Paper>
@@ -382,33 +410,43 @@ function ChatMessageBubble({
}
export interface ChatPanelProps {
- /** Called when the user closes the chat to return to the tool list. */
- onBack: () => void;
- /** Accessible label for the close button. */
- backLabel: string;
+ /** False keeps only the composer on screen; the conversation stays mounted but inert. */
+ expanded: boolean;
+ /** Sits above the conversation and is hidden with it. */
+ header: ReactNode;
+ /** Attached to the message list's scroller, for a header above it to track its scroll. */
+ messagesRef: RefCallback<HTMLDivElement>;
+ onComposerFocus: (event: FocusEvent<HTMLTextAreaElement>) => void;
}
-export function ChatPanel({ onBack, backLabel }: ChatPanelProps) {
+/** The conversation and its composer, laid out to sit under a header in a flex column. */
+export function ChatPanel({
+ expanded,
+ header,
+ messagesRef,
+ onComposerFocus,
+}: ChatPanelProps) {
const { t } = useTranslation();
- const { messages, isLoading, progressLog, sendMessage, clearChat } =
- useChat();
+ const { messages, isLoading, progressLog, sendMessage } = useChat();
const resolveToolName = useToolNameResolver();
const resolveToolIcon = useToolIconResolver();
const [input, setInput] = useState("");
const scrollRef = useRef<HTMLDivElement>(null);
- const inputRef = useRef<HTMLTextAreaElement>(null);
+ const viewportRef = useMergedRef(scrollRef, messagesRef);
// Tracks whether the user manually scrolled away from the bottom.
// A ref (not state) so scroll events don't cause re-renders.
const userScrolledUp = useRef(false);
- // Jump to the bottom on first render so existing conversations open at the
- // most recent message rather than the top.
+ // Open at the most recent message rather than wherever a collapsed, zero-height
+ // viewport left the scroll position.
useEffect(() => {
+ if (!expanded) return;
+ userScrolledUp.current = false;
requestAnimationFrame(() => {
const el = scrollRef.current;
if (el) el.scrollTop = el.scrollHeight;
});
- }, []);
+ }, [expanded]);
// Attach a passive scroll listener to track whether the user has scrolled
// away from the bottom (breaks auto-scroll) or returned to it (re-latches).
@@ -440,10 +478,6 @@ export function ChatPanel({ onBack, backLabel }: ChatPanelProps) {
}
}, [messages, progressLog]);
- useEffect(() => {
- inputRef.current?.focus();
- }, []);
-
const handleSend = (override?: string) => {
const text = (override ?? input).trim();
if (!text || isLoading) return;
@@ -465,104 +499,75 @@ export function ChatPanel({ onBack, backLabel }: ChatPanelProps) {
);
return (
- <Box className="chat-panel chat-panel--embedded">
- <PanelHeader
- icon={<BrandMark height="26px" className="chat-panel__header-mark" />}
- title={
- <Logo
- variant="textOnly"
- textHeight="17px"
- alt={t("agents.stirling_name", "Stirling")}
- />
- }
- loading={isLoading}
- className="chat-panel__header"
- barClassName="chat-panel__agent-pill-vt"
- menuLabel={t("chat.header.agentMenu", "Stirling agent options")}
- menuItems={[
- {
- key: "clear-chat",
- icon: <Icon name="trash" size={18} />,
- label: t("chat.header.clearChat", "Clear chat"),
- onClick: clearChat,
- disabled: messages.length === 0 && !isLoading,
- },
- ]}
- onClose={onBack}
- closeLabel={backLabel}
- />
-
- {showQuickActions && (
- <div className="chat-panel-disclaimer chat-panel-disclaimer--banner">
- <Icon name="info" size={18} className="chat-panel-disclaimer__icon" />
- <span>{disclaimerText}</span>
- </div>
- )}
-
- <ScrollArea className="chat-panel-messages" viewportRef={scrollRef}>
- <Stack
- gap="sm"
- px="md"
- pt="sm"
- className="chat-panel-messages__content"
- >
- {messages.map((msg) => (
- <ChatMessageBubble
- key={msg.id}
- role={msg.role}
- content={msg.content}
- timestamp={msg.timestamp}
- progressLog={msg.progressLog}
- durationMs={msg.durationMs}
- resolveToolName={resolveToolName}
- resolveToolIcon={resolveToolIcon}
- t={t}
+ <>
+ <div className="chat-panel" aria-hidden={!expanded} inert={!expanded}>
+ {header}
+ {showQuickActions && (
+ <div className="chat-panel-disclaimer chat-panel-disclaimer--banner">
+ <Icon
+ name="info"
+ size={18}
+ className="chat-panel-disclaimer__icon"
/>
- ))}
- {isLoading && (
- <div className="chat-message chat-message-assistant">
- <ProgressLogDisplay
- progressLog={progressLog}
- t={t}
+ <span>{disclaimerText}</span>
+ </div>
+ )}
+
+ <ScrollArea className="chat-panel-messages" viewportRef={viewportRef}>
+ <Stack
+ gap="sm"
+ px="xs"
+ pt="sm"
+ className="chat-panel-messages__content"
+ >
+ {messages.map((msg) => (
+ <ChatMessageBubble
+ key={msg.id}
+ role={msg.role}
+ content={msg.content}
+ timestamp={msg.timestamp}
+ progressLog={msg.progressLog}
+ durationMs={msg.durationMs}
resolveToolName={resolveToolName}
resolveToolIcon={resolveToolIcon}
+ t={t}
/>
- </div>
- )}
- </Stack>
- </ScrollArea>
-
- {showQuickActions && (
- <ChatQuickActions
- heading={t("chat.quickActions.heading", "Get started")}
- onAction={(text) => handleSend(text)}
- />
- )}
+ ))}
+ {isLoading && (
+ <div className="chat-message chat-message-assistant">
+ <ProgressLogDisplay
+ progressLog={progressLog}
+ t={t}
+ resolveToolName={resolveToolName}
+ resolveToolIcon={resolveToolIcon}
+ />
+ </div>
+ )}
+ </Stack>
+ </ScrollArea>
+
+ {showQuickActions && (
+ <ChatQuickActions
+ heading={t("chat.quickActions.heading", "Get started")}
+ onAction={(text) => handleSend(text)}
+ />
+ )}
- {!showQuickActions && (
- <div className="chat-panel-disclaimer chat-panel-disclaimer--inline">
- <Icon name="info" size={13} className="chat-panel-disclaimer__icon" />
- <span>{disclaimerText}</span>
- </div>
- )}
+ {!showQuickActions && (
+ <div className="chat-panel-disclaimer chat-panel-disclaimer--inline">
+ <span>{disclaimerText}</span>
+ </div>
+ )}
+ </div>
<div className="chat-panel-input">
- <ActionIcon
- className="chat-panel-input__send"
- size="sm"
- onClick={() => handleSend()}
- disabled={!input.trim() || isLoading}
- aria-label={t("chat.input.send", "Send message")}
- >
- <Icon name="arrow-up" size={16} />
- </ActionIcon>
<Textarea
- ref={inputRef}
- placeholder={t("chat.input.placeholder", "What do you want to do?")}
+ placeholder={t("chat.dock.placeholder", "Ask Stirling Agent")}
+ aria-label={t("chat.dock.placeholder", "Ask Stirling Agent")}
value={input}
onChange={(e) => setInput(e.currentTarget.value)}
onKeyDown={handleKeyDown}
- disabled={isLoading}
+ onFocus={onComposerFocus}
autosize
minRows={1}
maxRows={4}
@@ -572,7 +577,16 @@ export function ChatPanel({ onBack, backLabel }: ChatPanelProps) {
input: "chat-panel-input__field",
}}
/>
+ <ActionIcon
+ size="sm"
+ loading={isLoading}
+ onClick={() => handleSend()}
+ disabled={!input.trim() || isLoading}
+ aria-label={t("chat.input.send", "Send message")}
+ >
+ <Icon name="arrow-up" size={16} />
+ </ActionIcon>
</div>
- </Box>
+ </>
);
}
diff --git a/frontend/editor/src/proprietary/components/chat/ChatQuickActions.tsx b/frontend/editor/src/proprietary/components/chat/ChatQuickActions.tsx
index edf25620a1..f4ee7509ca 100644
--- a/frontend/editor/src/proprietary/components/chat/ChatQuickActions.tsx
+++ b/frontend/editor/src/proprietary/components/chat/ChatQuickActions.tsx
@@ -2,15 +2,12 @@ import { useMemo } from "react";
import { useTranslation } from "react-i18next";
import { Box, Stack, Text } from "@mantine/core";
import { Button } from "@app/ui/Button";
-import { ActionIcon } from "@app/ui/ActionIcon";
import { Icon } from "@app/ui/Icon";
-import { useAllFiles, useFileActions } from "@app/contexts/FileContext";
+import { useAllFiles } from "@app/contexts/FileContext";
import { useFilesModalContext } from "@app/contexts/FilesModalContext";
import { detectFileExtension, isPdfFile } from "@app/utils/fileUtils";
import type { StirlingFileStub } from "@app/types/fileContext";
-const MAX_FILE_PILLS = 3;
-
interface QuickAction {
key: string;
icon: React.ReactNode;
@@ -58,55 +55,6 @@ function QuickActionCard({ action }: { action: QuickAction }) {
);
}
-function WorkbenchFilePills({
- stubs,
- onOpenFilesModal,
- onRemove,
- moreLabel,
- removeLabel,
-}: {
- stubs: StirlingFileStub[];
- onOpenFilesModal: () => void;
- onRemove: (id: StirlingFileStub["id"]) => void;
- moreLabel: (count: number) => string;
- removeLabel: (name: string) => string;
-}) {
- const visible = stubs.slice(0, MAX_FILE_PILLS);
- const overflow = Math.max(0, stubs.length - visible.length);
- return (
- <div className="chat-file-pills">
- {visible.map((stub) => (
- <span key={stub.id} className="chat-file-pill">
- <Icon name="file" size={14} className="chat-file-pill__icon" />
- <span className="chat-file-pill__label" title={stub.name}>
- {stub.name}
- </span>
- <ActionIcon
- type="button"
- variant="tertiary"
- className="chat-file-pill__remove"
- onClick={() => onRemove(stub.id)}
- aria-label={removeLabel(stub.name)}
- >
- <Icon name="x" size={12} />
- </ActionIcon>
- </span>
- ))}
- {overflow > 0 && (
- <Button
- type="button"
- variant="tertiary"
- hover={false}
- className="chat-file-pill chat-file-pill--more"
- onClick={onOpenFilesModal}
- >
- {moreLabel(overflow)}
- </Button>
- )}
- </div>
- );
-}
-
interface WorkbenchSummary {
fileCount: number;
pdfCount: number;
@@ -155,7 +103,6 @@ export interface ChatQuickActionsProps {
export function ChatQuickActions({ heading, onAction }: ChatQuickActionsProps) {
const { t } = useTranslation();
const { fileStubs } = useAllFiles();
- const { actions: fileActions } = useFileActions();
const { openFilesModal } = useFilesModalContext();
const summary = useMemo(() => summariseWorkbench(fileStubs), [fileStubs]);
@@ -256,25 +203,6 @@ export function ChatQuickActions({ heading, onAction }: ChatQuickActionsProps) {
return (
<div className="chat-panel__quick-actions">
- {summary.fileCount > 0 && (
- <WorkbenchFilePills
- stubs={fileStubs}
- onOpenFilesModal={() => openFilesModal()}
- onRemove={(id) => fileActions.removeFiles([id])}
- moreLabel={(count) =>
- t("chat.quickActions.moreFiles", {
- count,
- defaultValue: "+{{count}} more",
- })
- }
- removeLabel={(name) =>
- t("chat.quickActions.removeFile", {
- name,
- defaultValue: "Remove {{name}}",
- })
- }
- />
- )}
<Text className="chat-panel__quick-actions-label">{heading}</Text>
<Stack gap="xs">
{actions.map((action) => (
diff --git a/frontend/editor/src/proprietary/components/chat/SidebarChat.css b/frontend/editor/src/proprietary/components/chat/SidebarChat.css
new file mode 100644
index 0000000000..7ab00b7434
--- /dev/null
+++ b/frontend/editor/src/proprietary/components/chat/SidebarChat.css
@@ -0,0 +1,40 @@
+/* A row of the file sidebar's column. It grows by flex-grow against the rows
+ above, which transitions smoothly where a height to or from auto cannot; at
+ grow 0 its basis of 0 leaves it at its minimum, the composer alone. */
+.chat-dock {
+ display: flex;
+ flex-direction: column;
+ flex: 0 1 0;
+ gap: var(--nav-gutter);
+ border-top: 1px solid var(--c-border-subtle);
+ transition: flex-grow 280ms cubic-bezier(0.32, 0.72, 0, 1);
+}
+
+.chat-dock:not([data-state="collapsed"]) {
+ flex-grow: 1;
+}
+
+.chat-dock .chat-panel {
+ transition: opacity 180ms ease-out;
+}
+
+.chat-dock[data-state="collapsed"] .chat-panel {
+ opacity: 0;
+}
+
+/* Ruled above by the dock and below once messages scroll, so it pads evenly to
+ sit centred between the two, unlike the library header it otherwise matches. */
+.chat-dock .chat-panel > .file-sidebar-section-header {
+ padding-block: 0.25rem;
+}
+
+.chat-dock__title {
+ flex: 1;
+}
+
+@media (prefers-reduced-motion: reduce) {
+ .chat-dock,
+ .chat-dock .chat-panel {
+ transition: none;
+ }
+}
diff --git a/frontend/editor/src/proprietary/components/chat/SidebarChat.tsx b/frontend/editor/src/proprietary/components/chat/SidebarChat.tsx
new file mode 100644
index 0000000000..72e44b0aed
--- /dev/null
+++ b/frontend/editor/src/proprietary/components/chat/SidebarChat.tsx
@@ -0,0 +1,94 @@
+import { useRef, useState, type FocusEvent } from "react";
+import { useTranslation } from "react-i18next";
+import { ActionIcon } from "@app/ui/ActionIcon";
+import { Icon } from "@app/ui/Icon";
+import { ChatPanel } from "@app/components/chat/ChatPanel";
+import { useChat } from "@app/components/chat/ChatContext";
+import { useAiEngineEnabled } from "@app/hooks/useAiEngineEnabled";
+import { useChatAccess } from "@app/hooks/useChatAccess";
+import { useIsScrolled } from "@app/hooks/useIsScrolled";
+// Its header reuses the file sidebar's section header, so the two sections match.
+import "@app/components/shared/FileSidebar.css";
+import "@app/components/chat/SidebarChat.css";
+
+export function SidebarChat() {
+ return useAiEngineEnabled() ? <ChatDock /> : null;
+}
+
+function ChatDock() {
+ const { t } = useTranslation();
+ const { messages, isLoading, clearChat } = useChat();
+ const requestChatAccess = useChatAccess();
+ const [expanded, setExpanded] = useState(false);
+ const dockRef = useRef<HTMLElement>(null);
+ const { scrolled, scrollRef: messagesRef } = useIsScrolled();
+
+ const handleComposerFocus = (event: FocusEvent<HTMLTextAreaElement>) => {
+ if (expanded) return;
+ if (!requestChatAccess()) {
+ event.currentTarget.blur();
+ return;
+ }
+ setExpanded(true);
+ };
+
+ const handleCollapse = () => {
+ setExpanded(false);
+ // WebKit keeps focus on the composer through a button click, and a composer
+ // that is already focused never fires the focus that reopens the dock.
+ const active = document.activeElement;
+ if (active instanceof HTMLElement && dockRef.current?.contains(active)) {
+ active.blur();
+ }
+ };
+
+ const title = t("chat.dock.title", "Stirling Agent");
+ const collapseLabel = t("chat.dock.collapse", "Collapse chat");
+
+ const header = (
+ <div
+ className="file-sidebar-section-header"
+ data-scrolled={(expanded && scrolled) || undefined}
+ >
+ <span className="file-sidebar-section-label chat-dock__title">
+ {title}
+ </span>
+ {(messages.length > 0 || isLoading) && (
+ <ActionIcon
+ variant="quiet"
+ className="file-sidebar-section-btn"
+ onClick={clearChat}
+ aria-label={t("chat.header.clearChat", "Clear chat")}
+ title={t("chat.header.clearChat", "Clear chat")}
+ >
+ <Icon name="trash" size="1rem" />
+ </ActionIcon>
+ )}
+ <ActionIcon
+ variant="quiet"
+ className="file-sidebar-section-btn"
+ onClick={handleCollapse}
+ aria-label={collapseLabel}
+ title={collapseLabel}
+ >
+ <Icon name="chevron-down" size="1rem" />
+ </ActionIcon>
+ </div>
+ );
+
+ return (
+ <section
+ ref={dockRef}
+ className="chat-dock"
+ data-state={expanded ? "expanded" : "collapsed"}
+ aria-label={title}
+ >
+ <ChatPanel
+ expanded={expanded}
+ header={header}
+ messagesRef={messagesRef}
+ onComposerFocus={handleComposerFocus}
+ />
+ </section>
+ );
+}
diff --git a/frontend/editor/src/proprietary/components/chat/chatFabLayout.ts b/frontend/editor/src/proprietary/components/chat/chatFabLayout.ts
deleted file mode 100644
index db2fd76d63..0000000000
--- a/frontend/editor/src/proprietary/components/chat/chatFabLayout.ts
+++ /dev/null
@@ -1,52 +0,0 @@
-// Pure layout/geometry for the draggable ChatFAB panel. Kept free of React so
-// the constants and clamping math stay readable and unit-testable; ChatFAB.tsx
-// owns the stateful wiring (refs, effects, the ResizeObserver) that consumes them.
-
-export const PANEL_WIDTH_PX = 390;
-export const PANEL_HEIGHT_PX = 520;
-export const PANEL_MIN_WIDTH_PX = 300;
-export const PANEL_MIN_HEIGHT_PX = 380;
-export const FAB_GAP_PX = 16;
-const FAB_BOTTOM_OFFSET_PX = FAB_GAP_PX;
-
-export const RESET_MS = 380;
-const RESET_EASING = "cubic-bezier(0.32, 0.72, 0, 1)";
-export const RESET_TRANSITION = `transform ${RESET_MS}ms ${RESET_EASING}, width ${RESET_MS}ms ${RESET_EASING}, height ${RESET_MS}ms ${RESET_EASING}`;
-
-// Handle strips straddle the border; zIndex:1 lifts them above ChatFABWindow's transform stacking context.
-export const RESIZE_HANDLES = {
- top: { top: -3, left: 14, right: 14, height: 6, zIndex: 1 },
- bottom: { bottom: -3, left: 14, right: 14, height: 6, zIndex: 1 },
- left: { left: -3, top: 14, bottom: 14, width: 6, zIndex: 1 },
- right: { right: -3, top: 14, bottom: 14, width: 6, zIndex: 1 },
- topLeft: { top: -4, left: -4, width: 14, height: 14, zIndex: 1 },
- topRight: { top: -4, right: -4, width: 14, height: 14, zIndex: 1 },
- bottomLeft: { bottom: -4, left: -4, width: 14, height: 14, zIndex: 1 },
- bottomRight: { bottom: -4, right: -4, width: 14, height: 14, zIndex: 1 },
-};
-
-// Default resting position: bottom-right of the overlay, inset by the gap.
-export function defaultPanelPos(
- overlayWidth: number,
- overlayHeight: number,
-): { x: number; y: number } {
- return {
- x: overlayWidth - PANEL_WIDTH_PX - FAB_GAP_PX,
- y: overlayHeight - PANEL_HEIGHT_PX - FAB_BOTTOM_OFFSET_PX,
- };
-}
-
-// Clamps pos to [gap, max] on each axis; pins to top-left gap when the overlay is too small so the header stays reachable.
-export function clampToOverlay(
- pos: { x: number; y: number },
- size: { width: number; height: number },
- overlayWidth: number,
- overlayHeight: number,
-): { x: number; y: number } {
- const maxX = overlayWidth - size.width - FAB_GAP_PX;
- const maxY = overlayHeight - size.height - FAB_GAP_PX;
- return {
- x: Math.max(FAB_GAP_PX, Math.min(pos.x, maxX)),
- y: Math.max(FAB_GAP_PX, Math.min(pos.y, maxY)),
- };
-}
diff --git a/frontend/editor/src/saas/components/SignupRequiredBootstrap.test.tsx b/frontend/editor/src/saas/components/SignupRequiredBootstrap.test.tsx
index cb650ce0bd..60b058e7ae 100644
--- a/frontend/editor/src/saas/components/SignupRequiredBootstrap.test.tsx
+++ b/frontend/editor/src/saas/components/SignupRequiredBootstrap.test.tsx
@@ -5,11 +5,12 @@ import {
screen,
waitFor,
} from "@testing-library/react";
+import type { FocusEvent } from "react";
import { MantineProvider } from "@mantine/core";
import { MemoryRouter, useLocation } from "react-router-dom";
import { beforeEach, describe, expect, it, vi } from "vitest";
import SignupRequiredBootstrap from "@app/components/SignupRequiredBootstrap";
-import { ChatFAB } from "@app/components/chat/ChatFAB";
+import { SidebarChat } from "@app/components/chat/SidebarChat";
import { useToolRunComplete } from "@app/hooks/useToolRunComplete";
import { useProcessingFolderCreation } from "@app/hooks/useProcessingFolderCreation";
import { QuickNavRailHost } from "@app/components/shared/quickNav/QuickNavRailHost";
@@ -30,9 +31,15 @@ vi.mock("@app/contexts/QuickNavHostContext", () => ({
}));
vi.mock("@app/ui/Icon", () => ({ Icon: () => null }));
vi.mock("@app/components/chat/ChatContext", () => ({
- useChat: () => ({ isLoading: false }),
+ useChat: () => ({ messages: [], isLoading: false, clearChat: () => {} }),
+}));
+vi.mock("@app/components/chat/ChatPanel", () => ({
+ ChatPanel: ({
+ onComposerFocus,
+ }: {
+ onComposerFocus: (event: FocusEvent<HTMLTextAreaElement>) => void;
+ }) => <textarea aria-label="Ask Stirling Agent" onFocus={onComposerFocus} />,
}));
-vi.mock("@app/components/chat/ChatPanel", () => ({ ChatPanel: () => null }));
vi.mock("@app/components/policies/ProcessingFolderSetupFlow", () => ({
ProcessingFolderSetupFlow: () => <div>Processing folder wizard</div>,
}));
@@ -88,7 +95,7 @@ function renderPrompt(withRail = false, withChat = false, withActions = false) {
<MantineProvider>
<SignupRequiredBootstrap />
{withRail && <QuickNavRailHost />}
- {withChat && <ChatFAB />}
+ {withChat && <SidebarChat />}
{withActions && <GuestActions />}
<Destination />
</MantineProvider>
@@ -125,12 +132,15 @@ describe("guest signup prompt", () => {
it("opens signup instead of the assistant for guests without navigating", async () => {
renderPrompt(false, true);
- const assistant = screen.getByRole("button", {
- name: "Open Stirling AI assistant",
+ const composer = screen.getByRole("textbox", {
+ name: "Ask Stirling Agent",
});
- fireEvent.click(assistant);
+ act(() => composer.focus());
expect(await screen.findByRole("dialog")).toBeInTheDocument();
- expect(assistant).toHaveAttribute("aria-expanded", "false");
+ expect(composer).not.toHaveFocus();
+ expect(
+ screen.getByRole("region", { name: "Stirling Agent" }),
+ ).toHaveAttribute("data-state", "collapsed");
expect(screen.getByTestId("destination")).toHaveTextContent(
"/editor?tool=compress",
);
@@ -139,11 +149,12 @@ describe("guest signup prompt", () => {
it("opens the assistant without a signup prompt for registered users", () => {
auth.isAnonymous = false;
renderPrompt(false, true);
- const assistant = screen.getByRole("button", {
- name: "Open Stirling AI assistant",
- });
- fireEvent.click(assistant);
- expect(assistant).toHaveAttribute("aria-expanded", "true");
+ act(() =>
+ screen.getByRole("textbox", { name: "Ask Stirling Agent" }).focus(),
+ );
+ expect(
+ screen.getByRole("region", { name: "Stirling Agent" }),
+ ).toHaveAttribute("data-state", "expanded");
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
});