Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
feat(desktop-app): mount chat drawer beside the live app on the apps route (Fase 1)
Diego Zacarias941967409f8d
diff --git a/desktop-app/ui/src/App.tsx b/desktop-app/ui/src/App.tsxindex df521d4b0..9058e8bc4 100644--- a/desktop-app/ui/src/App.tsx+++ b/desktop-app/ui/src/App.tsx@@ -11,6 +11,7 @@ import {} from '@contexts/index'import { AppHeader } from '@components/AppHeader'import { BootSplash } from '@components/BootSplash'+import { ChatDrawer } from '@components/ChatDrawer'import { ChatLocalSearch } from '@components/ChatLocalSearch'import { ChatViewWorkspace } from '@components/ChatViewWorkspace'import { CommandPalette } from '@components/CommandPalette'@@ -255,6 +256,8 @@ export function App() {const [headerShellOverlayOpen, setHeaderShellOverlayOpen] = React.useState(false)const [headerNotificationTrayOpen, setHeaderNotificationTrayOpen] = React.useState(false)const [notificationDrawerReady, setNotificationDrawerReady] = React.useState(false)+ const [chatDrawerOpen, setChatDrawerOpen] = React.useState(false)+ const [chatDrawerReady, setChatDrawerReady] = React.useState(false)const [availableSandboxUiApps, setAvailableSandboxUiApps] = React.useState<ActiveSandboxUiApp[]>([])@@ -268,6 +271,11 @@ export function App() {createChatViewTabsState('chat-tab-1'))const chatViewTabsRef = React.useRef(chatViewTabs)+ const chatDrawerRef = React.useRef<HTMLElement | null>(null)+ // Mirrors `chatDrawerVisible` so the chat-tab handlers (which run from stable+ // callbacks) can tell whether a reveal should target the in-app drawer or the+ // full-screen chat route without re-binding on every render.+ const chatDrawerVisibleRef = React.useRef(false)const [composerFocusRequestId, setComposerFocusRequestId] = React.useState(0)const [globalSearchFocusRequestId, setGlobalSearchFocusRequestId] = React.useState(0)const [notificationOpenRequestId, setNotificationOpenRequestId] = React.useState(0)@@ -308,7 +316,21 @@ export function App() {}, [])const revealChatViewTab = React.useCallback(- (tab: ChatViewTab) => {+ (tab: ChatViewTab, inDrawer = chatDrawerVisibleRef.current) => {+ if (inDrawer) {+ // Swap the shared <ChatPage>'s conversation in place, keeping the live+ // app mounted and the `apps` route active. A blank tab with no agent+ // simply shows the empty composer — there is nothing to navigate to.+ if (tab.agentRef) {+ vm.handleSelectChatAgent(+ tab.agentRef,+ tab.chatId+ ? { chatId: tab.chatId, title: tab.title, selectLatest: false, keepNavItem: true }+ : { selectLatest: false, keepNavItem: true }+ )+ }+ return+ }leaveSandboxForChat()if (tab.agentRef) {vm.handleSelectChatAgent(@@ -353,6 +375,26 @@ export function App() {setComposerFocusRequestId(value => value + 1)}, [nextChatTabId, revealChatViewTab, vm.selectedAgent])+ const openChatDrawer = React.useCallback(() => {+ setChatDrawerOpen(true)+ // The ref still reads `false` until the next render commits the open state,+ // so reveal explicitly in-drawer to swap the shared <ChatPage> in place.+ revealChatViewTab(activeChatViewTab(chatViewTabsRef.current), true)+ setComposerFocusRequestId(value => value + 1)+ }, [revealChatViewTab])++ const closeChatDrawer = React.useCallback(() => {+ setChatDrawerOpen(false)+ }, [])++ const toggleChatDrawer = React.useCallback(() => {+ if (chatDrawerVisibleRef.current) {+ closeChatDrawer()+ } else {+ openChatDrawer()+ }+ }, [closeChatDrawer, openChatDrawer])+const closeChatLocalSearch = React.useCallback((restoreFocus = true) => {setChatLocalSearchOpen(false)setChatLocalSearchState({ query: '', currentMatch: null })@@ -391,7 +433,13 @@ export function App() {}): focusBlankChatViewTab(chatViewTabsRef.current, nextChatTabId(), agentName)setChatViewTabs(next)- vm.handleSelectChatAgent(agentName, options)+ // While the drawer is visible, agent selection (sidebar picker, ChatPage's+ // auto-select) must swap the drawer's chat in place instead of navigating+ // to the full-screen chat route and tearing the live app down.+ vm.handleSelectChatAgent(+ agentName,+ chatDrawerVisibleRef.current ? { ...options, keepNavItem: true } : options+ )},[nextChatTabId, vm.handleSelectChatAgent])@@ -401,6 +449,12 @@ export function App() {(vm.navItem === DESKTOP_ROUTES.chat && Boolean(vm.selectedAgent))const notificationTrayUsesDrawer = Boolean(activeSandboxUiApp)const appNotificationDrawerOpen = notificationTrayUsesDrawer && headerNotificationTrayOpen+ // The chat drawer coexists with the live app only on the `apps` route. It is+ // an orthogonal boolean axis over the shared `chatViewTabs`/<ChatPage> — never+ // a second tab store, never a foreground/background precedence module.+ const chatDrawerAvailable = vm.navItem === DESKTOP_ROUTES.apps && Boolean(activeSandboxUiApp)+ const chatDrawerVisible = chatDrawerAvailable && chatDrawerOpen+ chatDrawerVisibleRef.current = chatDrawerVisibleconst activeConversationOrigin = React.useMemo<SandboxUiConversationOrigin | null>(() => {if (vm.navItem !== DESKTOP_ROUTES.chat || !vm.selectedAgent || !vm.activeChatId) {return null@@ -644,9 +698,16 @@ export function App() {setNotificationDrawerReady(false)}, [activeSandboxUiApp?.appRef, headerNotificationTrayOpen])+ // Re-arm the chat drawer's anti-flash gate whenever it (re)opens or the app+ // changes, so its DOM is revealed only after the embed finishes shrinking.+ React.useEffect(() => {+ setChatDrawerReady(false)+ }, [activeSandboxUiApp?.appRef, chatDrawerVisible])+const handleSandboxUiBoundsApplied = React.useCallback(() => {if (appNotificationDrawerOpen) setNotificationDrawerReady(true)- }, [appNotificationDrawerOpen])+ if (chatDrawerVisible) setChatDrawerReady(true)+ }, [appNotificationDrawerOpen, chatDrawerVisible])const launchSandboxUiApp = React.useCallback((app: ActiveSandboxUiApp, conversationOrigin: SandboxUiConversationOrigin | null) => {@@ -1094,6 +1155,7 @@ export function App() {setCommandPaletteOpen(false)setCommandPaletteReturnToSandbox(false)setSettingsShortcutsRequestId(0)+ setChatDrawerOpen(false)}, [vm.authenticatedPrincipalIdentity])const desktopCommandContext = React.useMemo(@@ -1322,7 +1384,7 @@ export function App() {const sandboxUiBoundsRefreshKey = `${sidebarCollapsed ? 'collapsed' : 'expanded'}:${appNotificationDrawerOpen ? 'notification-drawer-open' : 'notification-drawer-closed'- }`+ }:${chatDrawerVisible ? 'chat-drawer-open' : 'chat-drawer-closed'}`const pendingSandboxUiConfirmation =findPendingSandboxUiDeepLinkAwaitingConfirmation(@@ -1818,7 +1880,7 @@ export function App() {appNotificationDrawerOpen? ' content-panel--app-notification-drawer-open': ''- }`}+ }${chatDrawerVisible ? ' content-panel--chat-drawer-open' : ''}`}><AppHeadersearchFocusRequestId={globalSearchFocusRequestId}@@ -1868,28 +1930,47 @@ export function App() {)}{vm.navItem === DESKTOP_ROUTES.plugins && <WorkflowsPage />}{vm.navItem === DESKTOP_ROUTES.apps && (- <SandboxUiPage- boundsRefreshKey={sandboxUiBoundsRefreshKey}- actionRequest={sandboxActionRequest}- conversationOrigin={sandboxUiConversationOrigin}- currentTeamId={vm.currentTeamId}- headerShellOverlayOpen={- headerShellOverlayOpen || commandPaletteOpen- }- sidebarShellOverlayOpen={sidebarSettingsMenuOpen}- toastShellOverlayOpen={vm.toasts.length > 0}- shortcutApp={activeSandboxUiApp}- shortcutOpenRequestId={sandboxUiShortcutOpenRequestId}- localSearchRequestId={sandboxLocalSearchRequestId}- onBackToConversation={handleSandboxUiBackToConversation}- onEmbeddedAppOpening={handleSandboxUiOpening}- onEmbeddedAppMounted={handleSandboxUiMounted}- onEmbeddedAppBack={handleSandboxUiClosed}- onEmbeddedAppRemoved={handleSandboxUiRemoved}- onEmbedBoundsApplied={handleSandboxUiBoundsApplied}- onNotify={vm.pushToast}- onShortcutOpenResult={handleSandboxUiShortcutOpenResult}- />+ <>+ <SandboxUiPage+ boundsRefreshKey={sandboxUiBoundsRefreshKey}+ actionRequest={sandboxActionRequest}+ conversationOrigin={sandboxUiConversationOrigin}+ currentTeamId={vm.currentTeamId}+ headerShellOverlayOpen={+ headerShellOverlayOpen || commandPaletteOpen+ }+ sidebarShellOverlayOpen={sidebarSettingsMenuOpen}+ toastShellOverlayOpen={vm.toasts.length > 0}+ shortcutApp={activeSandboxUiApp}+ shortcutOpenRequestId={sandboxUiShortcutOpenRequestId}+ localSearchRequestId={sandboxLocalSearchRequestId}+ chatDrawerOpen={chatDrawerVisible}+ onToggleChatDrawer={toggleChatDrawer}+ onBackToConversation={handleSandboxUiBackToConversation}+ onEmbeddedAppOpening={handleSandboxUiOpening}+ onEmbeddedAppMounted={handleSandboxUiMounted}+ onEmbeddedAppBack={handleSandboxUiClosed}+ onEmbeddedAppRemoved={handleSandboxUiRemoved}+ onEmbedBoundsApplied={handleSandboxUiBoundsApplied}+ onNotify={vm.pushToast}+ onShortcutOpenResult={handleSandboxUiShortcutOpenResult}+ />+ {chatDrawerVisible && (+ <ChatDrawer+ header={+ <span className="chat-drawer__title">+ {activeChatViewTab(chatViewTabs).title}+ </span>+ }+ onNewChat={handleNewChatViewTab}+ onClose={closeChatDrawer}+ containerRef={chatDrawerRef}+ ready={chatDrawerReady}+ >+ <ChatPage scrollContainerRef={chatDrawerRef} />+ </ChatDrawer>+ )}+ </>)}{vm.navItem === DESKTOP_ROUTES.settings && (<SettingsPagediff --git a/desktop-app/ui/src/components/ChatDrawer/ChatDrawer.test.tsx b/desktop-app/ui/src/components/ChatDrawer/ChatDrawer.test.tsxnew file mode 100644index 000000000..a66035649--- /dev/null+++ b/desktop-app/ui/src/components/ChatDrawer/ChatDrawer.test.tsx@@ -0,0 +1,77 @@+// @vitest-environment jsdom+import { createRef } from 'react'+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'+import { cleanup, fireEvent, render, screen } from '@testing-library/react'+import { readFileSync } from 'node:fs'+import path from 'node:path'+import { ChatDrawer } from '.'++beforeEach(() => {+ const style = document.createElement('style')+ style.dataset.testStyles = 'chat-drawer'+ style.textContent = `${readFileSync(+ path.join(process.cwd(), 'ui', 'src', 'styles', 'tokens.css'),+ 'utf8'+ )}+${readFileSync(path.join(process.cwd(), 'ui', 'src', 'styles.css'), 'utf8')}`+ document.head.append(style)+})++afterEach(() => {+ cleanup()+ document.querySelector('[data-test-styles="chat-drawer"]')?.remove()+})++function renderDrawer(props: Partial<React.ComponentProps<typeof ChatDrawer>> = {}) {+ const onNewChat = props.onNewChat ?? vi.fn()+ const onClose = props.onClose ?? vi.fn()+ const containerRef = props.containerRef ?? createRef<HTMLElement>()+ const utils = render(+ <ChatDrawer+ header={props.header ?? <span className="chat-drawer__title">Drawer chat</span>}+ onNewChat={onNewChat}+ onClose={onClose}+ containerRef={containerRef}+ ready={props.ready ?? true}+ >+ <div data-testid="drawer-chat-page">chat page</div>+ </ChatDrawer>+ )+ return { ...utils, onNewChat, onClose }+}++describe('ChatDrawer', () => {+ it('renders the header slot, the embedded chat page, and its actions', () => {+ renderDrawer()+ expect(screen.getByText('Drawer chat')).toBeTruthy()+ expect(screen.getByTestId('drawer-chat-page')).toBeTruthy()+ expect(screen.getByRole('button', { name: 'New chat' })).toBeTruthy()+ expect(screen.getByRole('button', { name: 'Close chat drawer' })).toBeTruthy()+ })++ it('wires the new-chat and close actions', () => {+ const { onNewChat, onClose } = renderDrawer()+ fireEvent.click(screen.getByRole('button', { name: 'New chat' }))+ fireEvent.click(screen.getByRole('button', { name: 'Close chat drawer' }))+ expect(onNewChat).toHaveBeenCalledTimes(1)+ expect(onClose).toHaveBeenCalledTimes(1)+ })++ it('stays hidden and inert until the embed acknowledges its shrunk bounds', () => {+ const { container } = renderDrawer({ ready: false })+ const drawer = container.querySelector('.chat-drawer') as HTMLElement+ expect(drawer.getAttribute('data-ready')).toBe('false')+ expect(drawer.classList.contains('is-ready')).toBe(false)+ expect(getComputedStyle(drawer).opacity).toBe('0')+ expect(getComputedStyle(drawer).pointerEvents).toBe('none')+ })++ it('reveals once ready', () => {+ const { container } = renderDrawer({ ready: true })+ const drawer = container.querySelector('.chat-drawer') as HTMLElement+ expect(drawer.getAttribute('data-ready')).toBe('true')+ expect(drawer.classList.contains('is-ready')).toBe(true)+ expect(getComputedStyle(drawer).opacity).toBe('1')+ expect(getComputedStyle(drawer).pointerEvents).toBe('auto')+ })+})diff --git a/desktop-app/ui/src/components/ChatDrawer/index.tsx b/desktop-app/ui/src/components/ChatDrawer/index.tsxnew file mode 100644index 000000000..e32aaacb2--- /dev/null+++ b/desktop-app/ui/src/components/ChatDrawer/index.tsx@@ -0,0 +1,58 @@+import { IconButton } from '@components/Common'+import { IconClose, IconNewChat } from '@components/SidebarNav/icons'+import type { ChatDrawerProps } from './types'++/**+ * Cursor-style chat drawer that coexists with the live sandbox-ui embed on the+ * `apps` route. It is a `position: fixed` right column; the embed slot is+ * shrunk with `padding-right` so the native WebContentsView never overlaps it.+ *+ * The drawer mounts a single <ChatPage> (passed as children) driven by the same+ * global `chatViewTabs` state as the full-screen chat route — no duplicated tab+ * state and no duplicated streams.+ */+export function ChatDrawer({+ header,+ onNewChat,+ onClose,+ containerRef,+ ready,+ children,+}: ChatDrawerProps) {+ return (+ <aside+ className={`chat-drawer${ready ? ' is-ready' : ''}`}+ aria-label="Chat"+ data-ready={ready ? 'true' : 'false'}+ >+ <header className="chat-drawer__header">+ <div className="chat-drawer__header-main">{header}</div>+ <div className="chat-drawer__header-actions">+ <IconButton+ color="neutral"+ variant="ghost"+ size="sm"+ label="New chat"+ title="New chat"+ onClick={onNewChat}+ >+ <IconNewChat />+ </IconButton>+ <IconButton+ color="neutral"+ variant="ghost"+ size="sm"+ label="Close chat drawer"+ title="Close chat drawer"+ onClick={onClose}+ >+ <IconClose />+ </IconButton>+ </div>+ </header>+ <div className="chat-drawer__surface" ref={containerRef as React.RefObject<HTMLDivElement>}>+ {children}+ </div>+ </aside>+ )+}diff --git a/desktop-app/ui/src/components/ChatDrawer/types.ts b/desktop-app/ui/src/components/ChatDrawer/types.tsnew file mode 100644index 000000000..6bed6bfa5--- /dev/null+++ b/desktop-app/ui/src/components/ChatDrawer/types.ts@@ -0,0 +1,20 @@+import type { ReactNode, RefObject } from 'react'++export type ChatDrawerProps = {+ /**+ * Header content that names the visible conversation. Phase 1 passes a plain+ * title; Phase 2 replaces it with the open-chats switcher select.+ */+ header: ReactNode+ onNewChat: () => void+ onClose: () => void+ /** Scroll container the embedded <ChatPage> anchors to. */+ containerRef: RefObject<HTMLElement | null>+ /**+ * When false the drawer stays mounted but visually hidden until the native+ * embed has finished shrinking, mirroring the notification drawer's+ * bounds-ack anti-flash gate.+ */+ ready: boolean+ children: ReactNode+}diff --git a/desktop-app/ui/src/hooks/__tests__/useAppController.chatDrawer.test.tsx b/desktop-app/ui/src/hooks/__tests__/useAppController.chatDrawer.test.tsxnew file mode 100644index 000000000..b1503aa16--- /dev/null+++ b/desktop-app/ui/src/hooks/__tests__/useAppController.chatDrawer.test.tsx@@ -0,0 +1,87 @@+// @vitest-environment jsdom+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'+import { act, waitFor } from '@testing-library/react'+import { DESKTOP_ROUTES } from '@constants/navigation'+import {+ installAppControllerClerum,+ renderAppController,+} from '../domain/__tests__/__fixtures__/appControllerHarness'+import { uninstallMockClerum } from '../domain/__tests__/__fixtures__/mockClerum'++;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true++/**+ * The chat drawer coexists with the live app on the `apps` route. Selecting a+ * chat for the drawer must swap the shared <ChatPage>'s conversation WITHOUT+ * navigating to the full-screen chat route (which would tear down the embed).+ * `keepNavItem` is the single seam that breaks the XOR coupling — these pins+ * fail against the parent commit, where the option does not exist and+ * `handleSelectChatAgent` always flips `navItem` to `chat`.+ */+describe('useAppController — chat drawer keepNavItem', () => {+ let unmount: (() => void) | null = null++ beforeEach(() => {+ vi.clearAllMocks()+ })++ afterEach(() => {+ unmount?.()+ unmount = null+ vi.restoreAllMocks()+ uninstallMockClerum()+ })++ it('keeps the apps route when selecting a chat with keepNavItem', async () => {+ installAppControllerClerum({ agentNames: ['agent-x'] })+ const app = renderAppController()+ unmount = app.unmount++ await waitFor(() => expect(app.result.current.isAuthenticated).toBe(true))+ await waitFor(() => expect(app.result.current.initialExperienceLoading).toBe(false))++ act(() => {+ app.result.current.handleNavSelect(DESKTOP_ROUTES.apps)+ })+ expect(app.result.current.navItem).toBe(DESKTOP_ROUTES.apps)++ act(() => {+ app.result.current.handleSelectChatAgent('agent-x', {+ chatId: 'chat-1',+ title: 'Drawer chat',+ selectLatest: false,+ keepNavItem: true,+ })+ })++ // The chat controller now targets the requested agent/chat, but the route+ // stays on `apps` so the live embed survives.+ expect(app.result.current.selectedAgent).toBe('agent-x')+ expect(app.result.current.navItem).toBe(DESKTOP_ROUTES.apps)+ })++ it('navigates to the full-screen chat route without keepNavItem', async () => {+ installAppControllerClerum({ agentNames: ['agent-x'] })+ const app = renderAppController()+ unmount = app.unmount++ await waitFor(() => expect(app.result.current.isAuthenticated).toBe(true))+ await waitFor(() => expect(app.result.current.initialExperienceLoading).toBe(false))++ act(() => {+ app.result.current.handleNavSelect(DESKTOP_ROUTES.apps)+ })+ expect(app.result.current.navItem).toBe(DESKTOP_ROUTES.apps)++ act(() => {+ app.result.current.handleSelectChatAgent('agent-x', {+ chatId: 'chat-1',+ title: 'Full screen chat',+ selectLatest: false,+ })+ })++ expect(app.result.current.selectedAgent).toBe('agent-x')+ expect(app.result.current.navItem).toBe(DESKTOP_ROUTES.chat)+ })+})diff --git a/desktop-app/ui/src/hooks/useAppController.ts b/desktop-app/ui/src/hooks/useAppController.tsindex ffd601908..87b65f81e 100644--- a/desktop-app/ui/src/hooks/useAppController.ts+++ b/desktop-app/ui/src/hooks/useAppController.ts@@ -782,7 +782,17 @@ export function useAppController() {const handleSelectChatAgent = useCallback((agentName: string,- options: { selectLatest?: boolean; chatId?: string; isRemote?: boolean; title?: string } = {}+ options: {+ selectLatest?: boolean+ chatId?: string+ isRemote?: boolean+ title?: string+ // When true, drive the chat controller (pending selection + selectedAgent)+ // WITHOUT flipping `navItem` to the chat route. The chat-drawer coexists+ // with the live app on the `apps` route and needs to swap the shared+ // <ChatPage>'s conversation in place, so it must not navigate away.+ keepNavItem?: boolean+ } = {}) => {if (!agentName) returnconst targetChatId = String(options.chatId || '').trim()@@ -825,7 +835,7 @@ export function useAppController() {}nav.setSelectedAgentRoute('details')nav.setSelectedAgent(agentName)- nav.setNavItem(DESKTOP_ROUTES.chat)+ if (!options.keepNavItem) nav.setNavItem(DESKTOP_ROUTES.chat)},[chat.clearActiveChat,diff --git a/desktop-app/ui/src/pages/SandboxUiPage.tsx b/desktop-app/ui/src/pages/SandboxUiPage.tsxindex 349caa429..05dedb8b9 100644--- a/desktop-app/ui/src/pages/SandboxUiPage.tsx+++ b/desktop-app/ui/src/pages/SandboxUiPage.tsx@@ -159,6 +159,8 @@ export function SandboxUiPage({shortcutApp = null,shortcutOpenRequestId = 0,localSearchRequestId = 0,+ chatDrawerOpen = false,+ onToggleChatDrawer,onBackToConversation,onEmbeddedAppOpening,onEmbeddedAppMounted,@@ -574,6 +576,21 @@ export function SandboxUiPage({<IconClose /><span>Back to apps</span></Button>+ {launch.kind === 'mounted' && onToggleChatDrawer && (+ <Button+ color="neutral"+ variant={chatDrawerOpen ? 'solid' : 'soft'}+ size="sm"+ className="sandbox-ui-chat-drawer-btn"+ aria-label="Toggle chat drawer"+ aria-pressed={chatDrawerOpen}+ title="Toggle chat drawer"+ onClick={onToggleChatDrawer}+ >+ <IconChat />+ <span>Chat</span>+ </Button>+ )}{launch.kind === 'mounted' && (<><Buttondiff --git a/desktop-app/ui/src/pages/SandboxUiPage.types.ts b/desktop-app/ui/src/pages/SandboxUiPage.types.tsindex 15958eee5..7cee6f576 100644--- a/desktop-app/ui/src/pages/SandboxUiPage.types.ts+++ b/desktop-app/ui/src/pages/SandboxUiPage.types.ts@@ -29,6 +29,8 @@ export type SandboxUiPageProps = {shortcutApp?: ActiveSandboxUiApp | nullshortcutOpenRequestId?: numberlocalSearchRequestId?: number+ chatDrawerOpen?: boolean+ onToggleChatDrawer?: () => voidonBackToConversation?: () => void | Promise<void>onEmbeddedAppOpening?: (app: ActiveSandboxUiApp) => voidonEmbeddedAppMounted?: () => voiddiff --git a/desktop-app/ui/src/pages/__tests__/SandboxUiPage.test.tsx b/desktop-app/ui/src/pages/__tests__/SandboxUiPage.test.tsxindex 2fcd97dec..e2708d8d5 100644--- a/desktop-app/ui/src/pages/__tests__/SandboxUiPage.test.tsx+++ b/desktop-app/ui/src/pages/__tests__/SandboxUiPage.test.tsx@@ -185,6 +185,60 @@ describe('SandboxUiPage', () => {expect(screen.getAllByRole('button', { name: /^Back to / })).toHaveLength(1)})+ it('exposes a chat-drawer toggle in the mounted header that reflects and drives drawer state', async () => {+ sandboxUi.listApps.mockResolvedValueOnce({+ apps: [+ {+ appRef: 'sandbox-recipes/sales-crm',+ title: "Andy's Sales CRM",+ defaultPath: '/',+ ready: true,+ phase: 'active',+ updatedAt: null,+ },+ ],+ })+ sandboxUi.open.mockResolvedValueOnce(undefined)+ const onToggleChatDrawer = vi.fn()++ const view = render(+ <SandboxUiPage chatDrawerOpen={false} onToggleChatDrawer={onToggleChatDrawer} />+ )+ fireEvent.click(await screen.findByRole('button', { name: "Open Andy's Sales CRM" }))++ const toggle = await screen.findByRole('button', { name: 'Toggle chat drawer' })+ expect(toggle.getAttribute('aria-pressed')).toBe('false')++ fireEvent.click(toggle)+ expect(onToggleChatDrawer).toHaveBeenCalledTimes(1)++ view.rerender(<SandboxUiPage chatDrawerOpen={true} onToggleChatDrawer={onToggleChatDrawer} />)+ expect(+ screen.getByRole('button', { name: 'Toggle chat drawer' }).getAttribute('aria-pressed')+ ).toBe('true')+ })++ it('omits the chat-drawer toggle when no toggle handler is provided', async () => {+ sandboxUi.listApps.mockResolvedValueOnce({+ apps: [+ {+ appRef: 'sandbox-recipes/sales-crm',+ title: "Andy's Sales CRM",+ defaultPath: '/',+ ready: true,+ phase: 'active',+ updatedAt: null,+ },+ ],+ })+ sandboxUi.open.mockResolvedValueOnce(undefined)++ render(<SandboxUiPage />)+ fireEvent.click(await screen.findByRole('button', { name: "Open Andy's Sales CRM" }))+ await screen.findByRole('button', { name: 'Back to apps' })+ expect(screen.queryByRole('button', { name: 'Toggle chat drawer' })).toBeNull()+ })+it('routes controlled refresh and back requests through mounted-app owners', async () => {sandboxUi.listApps.mockResolvedValue({apps: [diff --git a/desktop-app/ui/src/styles.css b/desktop-app/ui/src/styles.cssindex 978b81286..72da5c7da 100644--- a/desktop-app/ui/src/styles.css+++ b/desktop-app/ui/src/styles.css@@ -12536,6 +12536,81 @@ pre {padding-left: var(--space-4);}+/* Chat drawer — Cursor-style chat column beside the live app embed. Reuses the+ notification drawer's rect-shrink gutter (padding-right on the embed slot's+ page) so the native WebContentsView shrinks to sit left of the drawer instead+ of painting over it. */+.content-panel.content-panel--chat-drawer-open > .page:has(.sandbox-ui-mounted-header) {+ padding-right: var(--app-header-utilities-width);+}++.content-panel.content-panel--chat-drawer-open .sandbox-ui-mounted-header {+ padding-right: 0;+}++.chat-drawer {+ position: fixed;+ top: calc(var(--space-4) + 36px + var(--space-2));+ right: var(--space-4);+ bottom: var(--space-4);+ width: var(--app-notification-drawer-width);+ z-index: var(--layer-chat-overlay);+ display: flex;+ flex-direction: column;+ min-height: 0;+ border: 1px solid rgba(var(--edge-rgb), 0.32);+ border-radius: var(--radius-md);+ background: var(--panel);+ box-shadow: var(--shadow-hard);+ overflow: hidden;+ /* Anti-flash: reveal only after the embed acknowledges its shrunk bounds,+ mirroring the notification drawer's bounds-ack gate. */+ opacity: 0;+ pointer-events: none;+}++.chat-drawer.is-ready {+ opacity: 1;+ pointer-events: auto;+}++.chat-drawer__header {+ display: flex;+ align-items: center;+ gap: var(--space-2);+ padding: var(--space-2) var(--space-2) var(--space-2) var(--space-3);+ border-bottom: 1px solid rgba(var(--edge-rgb), 0.24);+ flex: 0 0 auto;+}++.chat-drawer__header-main {+ flex: 1 1 auto;+ min-width: 0;+}++.chat-drawer__header-actions {+ display: inline-flex;+ align-items: center;+ gap: var(--space-1);+ flex: 0 0 auto;+}++.chat-drawer__title {+ display: block;+ font-weight: var(--font-weight-semibold);+ white-space: nowrap;+ overflow: hidden;+ text-overflow: ellipsis;+}++.chat-drawer__surface {+ flex: 1 1 auto;+ min-height: 0;+ overflow-y: auto;+ display: flex;+ flex-direction: column;+}+@media (min-width: 901px) and (max-width: 1220px) {.content-panel {--app-header-utilities-width: calc(