Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

feat(desktop): add chat scroll-to-bottom control

Josué5aec0a3b0395
diff --git a/desktop-app/ui/src/components/agents/AgentWorkspace.tsx b/desktop-app/ui/src/components/agents/AgentWorkspace.tsx
index b1937ea9b..d4367d12c 100644
--- a/desktop-app/ui/src/components/agents/AgentWorkspace.tsx
+++ b/desktop-app/ui/src/components/agents/AgentWorkspace.tsx
@@ -1,5 +1,6 @@
import { useEffect, useMemo, useRef, useState } from 'react'
import type { RefObject } from 'react'
+import { useAgentChatActionsContext } from '@contexts/AgentChatActionsContext'
import { useChatListContext } from '@contexts/ChatListContext'
import { useMcpRuntimeContext } from '@contexts/McpRuntimeContext'
import { useNavigationContext } from '@contexts/NavigationContext'
@@ -76,8 +77,10 @@ export function AgentWorkspace({ mode = 'agents', scrollContainerRef }: AgentWor
const { sessionStateByChatId, activeChatId } = useChatListContext()
const activeSessionState = activeChatId ? sessionStateByChatId[activeChatId] : undefined
const { hostRuntimeStatus } = useMcpRuntimeContext()
+ const { scrollChatToBottom } = useAgentChatActionsContext()
const [chatScrollNavVisible, setChatScrollNavVisible] = useState(true)
+ const [showScrollToBottom, setShowScrollToBottom] = useState(false)
const [chatAgentRouteMenuOpen, setChatAgentRouteMenuOpen] = useState(false)
const chatAgentRouteMenuRef = useRef<HTMLSpanElement | null>(null)
@@ -497,7 +500,28 @@ export function AgentWorkspace({ mode = 'agents', scrollContainerRef }: AgentWor
<ComposerPanel inline />
</>
)}
- {isChatMode && <ChatThread />}
+ {isChatMode && (
+ <div className="chat-thread-container">
+ <ChatThread onScrollPositionChange={setShowScrollToBottom} />
+ {activeChatId && showScrollToBottom && (
+ <div className="chat-scroll-to-bottom">
+ <IconButton
+ className="chat-scroll-to-bottom-button"
+ color="neutral"
+ label="Scroll to latest messages"
+ onClick={scrollChatToBottom}
+ size="sm"
+ variant="solid"
+ >
+ <svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
+ <path d="M12 4v14" />
+ <path d="m6 12 6 6 6-6" />
+ </svg>
+ </IconButton>
+ </div>
+ )}
+ </div>
+ )}
{isChatMode && activeChatId && (
<div className="agent-chat-composer-dock">
{activeSessionState?.offlineMode || activeSessionState?.syncing ? (
diff --git a/desktop-app/ui/src/components/agents/ChatThread.tsx b/desktop-app/ui/src/components/agents/ChatThread.tsx
index 53e8b595e..701593e8f 100644
--- a/desktop-app/ui/src/components/agents/ChatThread.tsx
+++ b/desktop-app/ui/src/components/agents/ChatThread.tsx
@@ -26,7 +26,11 @@ import {
IconWorkflows,
} from '@components/SidebarNav/icons'
import { WorkflowRunArtifactActions } from '@components/WorkflowRunArtifactActions'
-import { AGENT_ERROR_CODE_LABELS, SESSION_PREVIEW_LIMIT } from '@constants/agents'
+import {
+ AGENT_ERROR_CODE_LABELS,
+ CHAT_NEAR_BOTTOM_THRESHOLD_PX,
+ SESSION_PREVIEW_LIMIT,
+} from '@constants/agents'
import { HTML_PREVIEW_INLINE_MAX_BYTES } from '@constants/htmlPreview'
import type { ChatMessageAttachment } from '../../../../src/types'
import {
@@ -49,8 +53,8 @@ import { NudgeArea } from './NudgeArea'
type ChatThreadProps = {
showAgentLabel?: boolean
+ onScrollPositionChange?: (isScrolledAwayFromBottom: boolean) => void
}
-
type RenderableChatMessage = AgentChatMessage & {
messageKey: string
}
@@ -211,7 +215,7 @@ function MessageAttachmentList({ attachments }: { attachments: ChatMessageAttach
)
}
-export function ChatThread({ showAgentLabel = false }: ChatThreadProps) {
+export function ChatThread({ showAgentLabel = false, onScrollPositionChange }: ChatThreadProps) {
const { selectedAgent, handleSelectChatAgent: onStartNewChat } = useNavigationContext()
const { decideApproval } = useNotificationsContext()
const {
@@ -252,6 +256,7 @@ export function ChatThread({ showAgentLabel = false }: ChatThreadProps) {
} | null>(null)
const dedicatedSessionsRef = useRef<HTMLDivElement | null>(null)
const sessionRenameInputRef = useRef<HTMLInputElement | null>(null)
+ const chatThreadRef = useRef<HTMLDivElement | null>(null)
const sessionRenameClosedRef = useRef(false)
const chatListRef = useRef(chatList)
const copyResetTimeoutRef = useRef<number | null>(null)
@@ -301,6 +306,24 @@ export function ChatThread({ showAgentLabel = false }: ChatThreadProps) {
chatListRef.current = chatList
}, [chatList])
+ useEffect(() => {
+ const chatThread = chatThreadRef.current
+ if (!chatThread || !activeChatId) {
+ onScrollPositionChange?.(false)
+ return
+ }
+
+ const updateScrollPosition = () => {
+ const distanceFromBottom =
+ chatThread.scrollHeight - chatThread.scrollTop - chatThread.clientHeight
+ onScrollPositionChange?.(distanceFromBottom > CHAT_NEAR_BOTTOM_THRESHOLD_PX)
+ }
+
+ updateScrollPosition()
+ chatThread.addEventListener('scroll', updateScrollPosition, { passive: true })
+ return () => chatThread.removeEventListener('scroll', updateScrollPosition)
+ }, [activeChatId, chatMessagesLoading, groupedWithKeys, onScrollPositionChange])
+
useEffect(() => {
if (renamingSessionId && sessionRenameInputRef.current) {
sessionRenameInputRef.current.focus()
@@ -514,6 +537,7 @@ export function ChatThread({ showAgentLabel = false }: ChatThreadProps) {
return (
<div
+ ref={chatThreadRef}
data-testid="message-list"
className={`chat-thread ${isDedicatedAgentView ? 'chat-thread-dedicated' : ''}`}
>
diff --git a/desktop-app/ui/src/components/agents/__tests__/chatThread.toolSteps.test.tsx b/desktop-app/ui/src/components/agents/__tests__/chatThread.toolSteps.test.tsx
index c6c3ebc79..f1b7619c3 100644
--- a/desktop-app/ui/src/components/agents/__tests__/chatThread.toolSteps.test.tsx
+++ b/desktop-app/ui/src/components/agents/__tests__/chatThread.toolSteps.test.tsx
@@ -10,7 +10,7 @@
*/
import type { ReactNode } from 'react'
import { afterEach, describe, expect, it, vi } from 'vitest'
-import { cleanup, render, screen } from '@testing-library/react'
+import { cleanup, fireEvent, render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import type { MessageToolStep } from '../../../../../src/types'
import type { AgentChatMessage, TaskProgress } from '../../../uiTypes'
@@ -246,6 +246,32 @@ describe('ChatThread tool-steps fallback (#582)', () => {
expect(threadStateValue.handleLoadOlderMessages).toHaveBeenCalledTimes(1)
})
+ it('reports when the reader is away from the bottom of the conversation', () => {
+ const onScrollPositionChange = vi.fn()
+ setThreadState([{ role: 'user', items: [userMsg] }])
+
+ render(<ChatThread onScrollPositionChange={onScrollPositionChange} />)
+
+ const chatThread = screen.getByTestId('message-list')
+ Object.defineProperties(chatThread, {
+ clientHeight: { configurable: true, value: 200 },
+ scrollHeight: { configurable: true, value: 800 },
+ scrollTop: { configurable: true, value: 0, writable: true },
+ })
+
+ fireEvent.scroll(chatThread)
+ expect(onScrollPositionChange).toHaveBeenLastCalledWith(true)
+
+ Object.defineProperty(chatThread, 'scrollTop', {
+ configurable: true,
+ value: 600,
+ writable: true,
+ })
+ fireEvent.scroll(chatThread)
+
+ expect(onScrollPositionChange).toHaveBeenLastCalledWith(false)
+ })
+
it('wraps long histories in virtualized message chunks', () => {
const groups = Array.from({ length: 10 }, (_, index) => {
const role = index % 2 === 0 ? ('user' as const) : ('assistant' as const)
diff --git a/desktop-app/ui/src/constants/agents.ts b/desktop-app/ui/src/constants/agents.ts
index 2e18dd08b..94b43ad69 100644
--- a/desktop-app/ui/src/constants/agents.ts
+++ b/desktop-app/ui/src/constants/agents.ts
@@ -1,5 +1,6 @@
export const MAX_VISIBLE_SESSIONS = 6
export const SESSION_PREVIEW_LIMIT = 9
+export const CHAT_NEAR_BOTTOM_THRESHOLD_PX = 120
export const AGENT_ERROR_CODE_LABELS: Record<string, string> = {
LLM_INSUFFICIENT_QUOTA: 'Out of Credits',
diff --git a/desktop-app/ui/src/contexts/AgentChatActionsContext/types.ts b/desktop-app/ui/src/contexts/AgentChatActionsContext/types.ts
index db9e68b63..fd9753c6e 100644
--- a/desktop-app/ui/src/contexts/AgentChatActionsContext/types.ts
+++ b/desktop-app/ui/src/contexts/AgentChatActionsContext/types.ts
@@ -8,6 +8,7 @@ import type { ComposerImageAttachment, ComposerReferenceAttachment } from '../..
*/
export interface AgentChatActionsContextValue {
chatEndRef: RefObject<HTMLDivElement | null>
+ scrollChatToBottom: () => void
handleCreateChat: () => Promise<void>
handleRenameChat: (chatId: string, newTitle: string) => Promise<void>
handleRenameChatForAgent: (agentRef: string, chatId: string, newTitle: string) => Promise<void>
diff --git a/desktop-app/ui/src/hooks/domain/useAgentChatController.ts b/desktop-app/ui/src/hooks/domain/useAgentChatController.ts
index 2fe14f469..e0d4993c8 100644
--- a/desktop-app/ui/src/hooks/domain/useAgentChatController.ts
+++ b/desktop-app/ui/src/hooks/domain/useAgentChatController.ts
@@ -2928,6 +2928,7 @@ export function useAgentChatController({
agentError,
failedAgentSend,
chatEndRef,
+ scrollChatToBottom,
activityByMessageId,
progressByMessageId,
groupedMessages,
diff --git a/desktop-app/ui/src/hooks/domain/useChatScroll.ts b/desktop-app/ui/src/hooks/domain/useChatScroll.ts
index 29da3ebef..cbe080b02 100644
--- a/desktop-app/ui/src/hooks/domain/useChatScroll.ts
+++ b/desktop-app/ui/src/hooks/domain/useChatScroll.ts
@@ -1,4 +1,5 @@
import { useCallback, useEffect, useRef } from 'react'
+import { CHAT_NEAR_BOTTOM_THRESHOLD_PX } from '@constants/agents'
import type { AgentChatMessage, TaskProgress } from '../../uiTypes'
/**
@@ -6,8 +7,6 @@ import type { AgentChatMessage, TaskProgress } from '../../uiTypes'
* treat the user as "following" the conversation and auto-scroll on new content.
* Beyond it, the user is reading history and we must NOT yank them down (B4-a).
*/
-const NEAR_BOTTOM_THRESHOLD_PX = 120
-
interface UseChatScrollParams {
selectedAgent: string | null
chatMessages: AgentChatMessage[]
@@ -125,7 +124,7 @@ export function useChatScroll({
while (node) {
const { scrollHeight, scrollTop, clientHeight } = node
if (scrollHeight > clientHeight) {
- return scrollHeight - scrollTop - clientHeight <= NEAR_BOTTOM_THRESHOLD_PX
+ return scrollHeight - scrollTop - clientHeight <= CHAT_NEAR_BOTTOM_THRESHOLD_PX
}
node = node.parentElement
}
diff --git a/desktop-app/ui/src/hooks/useAgentChatActionsValue.ts b/desktop-app/ui/src/hooks/useAgentChatActionsValue.ts
index 444eda876..29c93e92c 100644
--- a/desktop-app/ui/src/hooks/useAgentChatActionsValue.ts
+++ b/desktop-app/ui/src/hooks/useAgentChatActionsValue.ts
@@ -14,6 +14,7 @@ type AppVm = ReturnType<typeof useAppController>
*/
export function useAgentChatActionsValue(vm: AppVm): AgentChatActionsContextValue {
const chatEndRef = vm.chatEndRef
+ const scrollChatToBottom = useStableCallback(vm.scrollChatToBottom)
const handleCreateChat = useStableCallback(vm.handleCreateChat)
const handleRenameChat = useStableCallback(vm.handleRenameChat)
const handleRenameChatForAgent = useStableCallback(vm.handleRenameChatForAgent)
@@ -40,6 +41,7 @@ export function useAgentChatActionsValue(vm: AppVm): AgentChatActionsContextValu
return useMemo(
() => ({
chatEndRef,
+ scrollChatToBottom,
handleCreateChat,
handleRenameChat,
handleRenameChatForAgent,
@@ -57,6 +59,7 @@ export function useAgentChatActionsValue(vm: AppVm): AgentChatActionsContextValu
}),
[
chatEndRef,
+ scrollChatToBottom,
handleCreateChat,
handleRenameChat,
handleRenameChatForAgent,
diff --git a/desktop-app/ui/src/hooks/useAppController.ts b/desktop-app/ui/src/hooks/useAppController.ts
index ba52de0b1..bc3844b05 100644
--- a/desktop-app/ui/src/hooks/useAppController.ts
+++ b/desktop-app/ui/src/hooks/useAppController.ts
@@ -1221,6 +1221,7 @@ export function useAppController() {
agentError: chat.agentError,
failedAgentSend: chat.failedAgentSend,
chatEndRef: chat.chatEndRef,
+ scrollChatToBottom: chat.scrollChatToBottom,
activeMessages: chat.chatMessages,
activityByMessageId: chat.activityByMessageId,
progressByMessageId: chat.progressByMessageId,
diff --git a/desktop-app/ui/src/styles.css b/desktop-app/ui/src/styles.css
index 96c8a7c3b..66e433a67 100644
--- a/desktop-app/ui/src/styles.css
+++ b/desktop-app/ui/src/styles.css
@@ -4014,6 +4014,11 @@ h3 {
transform: rotate(90deg);
}
+.agent-workspace-shell .chat-thread-container {
+ flex: 1 1 auto;
+ min-height: 0;
+}
+
.agent-workspace-shell .chat-thread {
flex: 1 1 auto;
min-height: 0;
@@ -6042,7 +6047,13 @@ h3 {
color: var(--warning);
}
+.chat-thread-container {
+ position: relative;
+ min-height: 0;
+}
+
.chat-thread {
+ height: 100%;
min-height: 280px;
max-height: none;
overflow: auto;
@@ -6057,6 +6068,32 @@ h3 {
gap: var(--space-2-5);
}
+.chat-scroll-to-bottom {
+ position: absolute;
+ inset-inline: 0;
+ inset-block-end: var(--space-3);
+ z-index: var(--layer-chat-overlay);
+ display: grid;
+ place-items: center;
+ pointer-events: none;
+}
+
+.chat-scroll-to-bottom-button.ui-icon-button {
+ border-color: rgba(var(--edge-rgb), 0.58);
+ box-shadow: var(--shadow-soft);
+ pointer-events: auto;
+}
+
+.chat-scroll-to-bottom-button.ui-icon-button svg {
+ width: 18px;
+ height: 18px;
+ fill: none;
+ stroke: currentColor;
+ stroke-linecap: round;
+ stroke-linejoin: round;
+ stroke-width: 2;
+}
+
.chat-history-page-control {
display: flex;
justify-content: center;