Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
feat(desktop-app): surface open-conversation gestures in the drawer instead of ejecting (minispec 04, #3)
Diego Zacarias69d518982367
diff --git a/desktop-app/ui/src/App.tsx b/desktop-app/ui/src/App.tsxindex 5a23d2616..0f20f0403 100644--- a/desktop-app/ui/src/App.tsx+++ b/desktop-app/ui/src/App.tsx@@ -436,6 +436,23 @@ export function App() {}}, [closeChatDrawer, openChatDrawer])+ // minispec 04 approach C: while the app embed is live, an "open conversation"+ // gesture (notification / approval) must surface the chat IN the drawer — open+ // the drawer and pass `keepNavItem` so the vm swaps the shared <ChatPage>+ // without ejecting to the full-screen chat route. App owns both the embed-live+ // signal and the drawer-open state, so the wrap lives here.+ const handleOpenNotificationInDrawer = React.useCallback(+ (...args: Parameters<typeof vm.handleOpenNotification>) => {+ const [notification, options] = args+ if (chatDrawerAvailableRef.current) {+ setChatDrawerOpen(true)+ return vm.handleOpenNotification(notification, { keepNavItem: true })+ }+ return vm.handleOpenNotification(notification, options)+ },+ [vm.handleOpenNotification]+ )+const closeChatLocalSearch = React.useCallback((restoreFocus = true) => {setChatLocalSearchOpen(false)setChatLocalSearchState({ query: '', currentMatch: null })@@ -1697,7 +1714,7 @@ export function App() {removeNotification: vm.removeNotification,resolveApprovalNotification: vm.resolveApprovalNotification,decideApproval: vm.decideApproval,- handleOpenNotification: vm.handleOpenNotification,+ handleOpenNotification: handleOpenNotificationInDrawer,handleApproveNotification: vm.handleApproveNotification,handleDenyNotification: vm.handleDenyNotification,handleRefreshPendingApprovals: vm.handleRefreshPendingApprovals,@@ -1709,7 +1726,7 @@ export function App() {vm.handleApproveNotification,vm.handleDecidePendingApproval,vm.handleDenyNotification,- vm.handleOpenNotification,+ handleOpenNotificationInDrawer,vm.handleRefreshPendingApprovals,vm.markNotificationsRead,vm.notificationActionById,diff --git a/desktop-app/ui/src/__tests__/App.chatDrawer.test.tsx b/desktop-app/ui/src/__tests__/App.chatDrawer.test.tsxindex 1b1317435..276bbe718 100644--- a/desktop-app/ui/src/__tests__/App.chatDrawer.test.tsx+++ b/desktop-app/ui/src/__tests__/App.chatDrawer.test.tsx@@ -2,6 +2,7 @@import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'import { act, cleanup, fireEvent, render, screen } from '@testing-library/react'import { DESKTOP_ROUTES } from '@constants/navigation'+import { useNotificationsContext } from '@contexts/NotificationsContext'import { useAppController } from '@hooks/useAppController'import { App } from '@/App'@@ -22,6 +23,9 @@ const sandboxUiPageHarness = vi.hoisted(() => ({}))const appHeaderHarness = vi.hoisted(() => ({props: null as null | { notificationTrayMode?: 'drawer' | 'overlay' },+ // Captured from context so tests can drive the "open conversation" gesture the+ // notification tray fires.+ openNotification: null as null | ((notification: unknown) => Promise<void>),}))vi.mock('@hooks/useAppController', () => ({ useAppController: vi.fn() }))@@ -29,6 +33,7 @@ vi.mock('@hooks/useAgentChatActionsValue', () => ({ useAgentChatActionsValue: ()vi.mock('@components/AppHeader', () => ({AppHeader: (props: NonNullable<typeof appHeaderHarness.props>) => {appHeaderHarness.props = props+ appHeaderHarness.openNotification = useNotificationsContext().handleOpenNotificationreturn null},}))@@ -80,6 +85,20 @@ function makeController(overrides: Partial<AppController> = {}): AppController {if (!options.keepNavItem) controller.navItem = DESKTOP_ROUTES.chat})+ // Faithful to the real openAgentConversationTarget: `keepNavItem` (passed by+ // App's drawer-aware wrapper) surfaces the chat WITHOUT flipping navItem;+ // otherwise it ejects to the full-screen chat route.+ const handleOpenNotification = vi.fn(+ (+ notification: { agentName?: string; chatId?: string },+ options: { keepNavItem?: boolean } = {}+ ) => {+ controller.selectedAgent = notification.agentName ?? controller.selectedAgent+ controller.activeChatId = notification.chatId ?? null+ if (!options.keepNavItem) controller.navItem = DESKTOP_ROUTES.chat+ return Promise.resolve()+ }+ )controller = {booting: false,initialExperienceLoading: false,@@ -122,6 +141,7 @@ function makeController(overrides: Partial<AppController> = {}): AppController {handleEnsureTeamContext: vi.fn(async () => false),getCurrentTeamId: vi.fn(() => 'team-a'),handleSelectChatAgent,+ handleOpenNotification,handleNavSelect,handleLogout: vi.fn(),pushToast: vi.fn(),@@ -145,6 +165,7 @@ describe('App chat drawer — reopen preserves the last-viewed chat', () => {sidebarHarness.props = nullsandboxUiPageHarness.props = nullappHeaderHarness.props = null+ appHeaderHarness.openNotification = nullcurrentController = makeController()vi.mocked(useAppController).mockImplementation(() => currentController)Object.defineProperty(window, 'clerum', {@@ -281,4 +302,50 @@ describe('App chat drawer — reopen preserves the last-viewed chat', () => {expect(screen.getByRole('button', { name: 'Open chats' }).textContent).toContain('Second chat')})+ // #3 — open-conversation gesture is drawer-aware (minispec 04 approach C). An+ // approval on a background chat, opened from the tray, must surface in the+ // drawer (navItem stays apps) instead of ejecting to the full-screen route.+ it('surfaces an open-conversation gesture in the drawer instead of ejecting', async () => {+ currentController = makeController({+ selectedAgent: 'alpha',+ activeChatId: 'chat-1',+ navItem: DESKTOP_ROUTES.chat,+ chatList: CHAT_LIST,+ } as Partial<AppController>)+ const { rerender } = render(<App />)++ // Launch from chat-1 → drawer open, app live, navItem apps.+ act(() => {+ sidebarHarness.props?.onOpenSandboxUiApp?.({+ appRef: 'ns/app',+ label: 'App',+ defaultPath: '/',+ })+ })+ expect(sandboxUiPageHarness.props?.chatDrawerOpen).toBe(true)+ expect(currentController.navItem).toBe(DESKTOP_ROUTES.apps)++ // Open the conversation the approval is on (chat-2, a background chat) via the+ // notification tray's gesture.+ await act(async () => {+ await appHeaderHarness.openNotification?.({+ id: 'n1',+ kind: 'agent_message',+ agentName: 'alpha',+ chatId: 'chat-2',+ } as unknown as Parameters<NonNullable<typeof appHeaderHarness.openNotification>>[0])+ })+ act(() => rerender(<App />))++ // Observable: the drawer now shows the approval's chat AND we did not eject+ // to the full-screen chat route.+ expect(currentController.navItem).toBe(DESKTOP_ROUTES.apps)+ expect(sandboxUiPageHarness.props?.chatDrawerOpen).toBe(true)+ expect(currentController.activeChatId).toBe('chat-2')+ expect(currentController.handleOpenNotification).toHaveBeenCalledWith(+ expect.objectContaining({ chatId: 'chat-2' }),+ { keepNavItem: true }+ )+ expect(screen.getByRole('button', { name: 'Open chats' }).textContent).toContain('Second chat')+ })})diff --git a/desktop-app/ui/src/hooks/__tests__/useAppController.chatDrawer.test.tsx b/desktop-app/ui/src/hooks/__tests__/useAppController.chatDrawer.test.tsxindex 0516d5592..0bf86ffdb 100644--- a/desktop-app/ui/src/hooks/__tests__/useAppController.chatDrawer.test.tsx+++ b/desktop-app/ui/src/hooks/__tests__/useAppController.chatDrawer.test.tsx@@ -164,4 +164,50 @@ describe('useAppController — chat drawer keepNavItem', () => {expect(app.result.current.selectedAgent).toBe('agent-x')expect(app.result.current.navItem).toBe(DESKTOP_ROUTES.chat)})++ it('opens a conversation notification in the drawer (keepNavItem) without ejecting to full-screen', async () => {+ // minispec 04 approach C — the real openAgentConversationTarget must honor+ // keepNavItem (App passes it while the app embed is live): surface the chat+ // without flipping navItem to the chat route.+ 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))++ // Land on `apps` with agent-x already selected (mirrors the live-embed state).+ act(() => {+ app.result.current.handleSelectChatAgent('agent-x', { chatId: 'chat-1', selectLatest: false })+ })+ await waitFor(() => expect(app.result.current.selectedAgent).toBe('agent-x'))+ act(() => {+ app.result.current.handleNavSelect(DESKTOP_ROUTES.apps)+ })+ await waitFor(() => expect(app.result.current.navItem).toBe(DESKTOP_ROUTES.apps))++ // Open the (approval's) conversation on a background chat, same team, same+ // agent, WITH keepNavItem — the gesture App fires while the embed is live.+ await act(async () => {+ await app.result.current.handleOpenNotification(+ {+ id: 'n1',+ kind: 'approval_required',+ agentName: 'agent-x',+ chatId: 'chat-2',+ teamId: 'team-1',+ text: 'Approval needed',+ timestamp: Date.now(),+ read: false,+ approval: { taskId: 't1', requestId: 'r1' },+ } as Parameters<typeof app.result.current.handleOpenNotification>[0],+ { keepNavItem: true }+ )+ })++ // Anti-eject: stayed on apps, and the drawer's displayed chat is the target.+ expect(app.result.current.navItem).toBe(DESKTOP_ROUTES.apps)+ expect(app.result.current.activeChatId).toBe('chat-2')+ await waitFor(() => expect(app.result.current.chatMessagesLoading).toBe(false))+ })})diff --git a/desktop-app/ui/src/hooks/useAppController.ts b/desktop-app/ui/src/hooks/useAppController.tsindex 0ca090858..d75535e58 100644--- a/desktop-app/ui/src/hooks/useAppController.ts+++ b/desktop-app/ui/src/hooks/useAppController.ts@@ -892,19 +892,39 @@ export function useAppController() {)const openAgentConversationTarget = useCallback(- async (target: AgentConversationNotificationTarget) => {+ async (+ target: AgentConversationNotificationTarget,+ options: { keepNavItem?: boolean } = {}+ ) => {const targetAgent = String(target.agentName || '').trim()if (!targetAgent) returnconst targetChatId = String(target.chatId || '').trim()const targetTeamId = String(target.teamId || '').trim()const activeTeamId = currentTeamIdRef.currentconst requiresTeamSwitch = Boolean(targetTeamId && targetTeamId !== activeTeamId)+ // minispec 04 approach C: when the app embed is live (App requests+ // `keepNavItem`) and no team switch is needed, surface the conversation IN+ // the drawer instead of ejecting to the full-screen chat route. A team+ // switch tears the embed down, so that case keeps the full-screen path.+ const stayInDrawer = Boolean(options.keepNavItem) && !requiresTeamSwitchtry {if (requiresTeamSwitch) {await ensureTeamContext({ teamId: targetTeamId })}+ if (stayInDrawer) {+ // handleSelectChatAgent(keepNavItem) sets the active chat without+ // flipping `navItem` (and imperatively switches for the same-agent+ // case); the drawer reconciler (approach A) syncs the switcher tab.+ handleSelectChatAgent(targetAgent, {+ selectLatest: false,+ keepNavItem: true,+ ...(targetChatId ? { chatId: targetChatId } : {}),+ })+ return+ }+// Same imperative-fast-path guard as handleSelectChatAgent: `switchToChat`// leaves no pending selection, so it only survives while the route (and// hence the agent-selection effect's deps) does not change. Opening a@@ -944,6 +964,7 @@ export function useAppController() {chat.switchToChat,ensureTeamContext,fullSetStatus,+ handleSelectChatAgent,nav.navItem,nav.selectedAgent,nav.setNavItem,@@ -1086,7 +1107,7 @@ export function useAppController() {// ─── Cross-domain: handleOpenNotification ───const handleOpenNotification = useCallback(- async (notification: AppNotification) => {+ async (notification: AppNotification, options: { keepNavItem?: boolean } = {}) => {notif.markNotificationRead(notification.id)if (notification.kind === 'workflow_completed') {await openWorkflowCompletionTarget(notification)@@ -1096,7 +1117,9 @@ export function useAppController() {await openSdkNotificationTarget(notification)return}- await openAgentConversationTarget(notification)+ // `keepNavItem` (App passes it when the app embed is live) only reaches the+ // agent-conversation surface — workflow/SDK targets navigate elsewhere.+ await openAgentConversationTarget(notification, options)},[notif.markNotificationRead,