🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
✨ feat(settings): add auto-scroll option during AI response streaming
Inneiedec250cf31d
diff --git a/locales/en-US/setting.json b/locales/en-US/setting.jsonindex 03faf82af8e..7376803625d 100644--- a/locales/en-US/setting.json+++ b/locales/en-US/setting.json@@ -370,6 +370,8 @@"settingChat.compressThreshold.title": "History Message Length Compression Threshold","settingChat.enableAutoCreateTopic.desc": "Whether to automatically create a topic during the conversation, only effective in temporary topics","settingChat.enableAutoCreateTopic.title": "Auto Create Topic",+ "settingChat.enableAutoScrollOnStreaming.desc": "Override global setting for this assistant",+ "settingChat.enableAutoScrollOnStreaming.title": "Auto-scroll During AI Response","settingChat.enableCompressHistory.title": "Enable Automatic Summary of Chat History","settingChat.enableHistoryCount.alias": "Unlimited","settingChat.enableHistoryCount.limited": "Include only {{number}} conversation messages",@@ -385,6 +387,8 @@"settingChat.inputTemplate.title": "User Input Preprocessing","settingChat.submit": "Update Chat Preferences","settingChat.title": "Chat Settings",+ "settingChatAppearance.autoScrollOnStreaming.desc": "Automatically scroll to bottom when AI is generating response",+ "settingChatAppearance.autoScrollOnStreaming.title": "Auto-scroll During AI Response","settingChatAppearance.fontSize.desc": "Font size of messages","settingChatAppearance.fontSize.marks.normal": "Standard","settingChatAppearance.fontSize.title": "Font Size",diff --git a/locales/zh-CN/setting.json b/locales/zh-CN/setting.jsonindex 91f87d87131..0ef674bc93f 100644--- a/locales/zh-CN/setting.json+++ b/locales/zh-CN/setting.json@@ -370,6 +370,8 @@"settingChat.compressThreshold.title": "历史消息长度压缩阈值","settingChat.enableAutoCreateTopic.desc": "会话过程中是否自动创建话题,仅在临时话题中生效","settingChat.enableAutoCreateTopic.title": "自动创建话题",+ "settingChat.enableAutoScrollOnStreaming.desc": "覆盖此助手的全局设置",+ "settingChat.enableAutoScrollOnStreaming.title": "AI 回复时自动滚动","settingChat.enableCompressHistory.title": "开启历史消息自动总结","settingChat.enableHistoryCount.alias": "不限制","settingChat.enableHistoryCount.limited": "只包含 {{number}} 条会话消息",@@ -385,6 +387,8 @@"settingChat.inputTemplate.title": "用户输入预处理","settingChat.submit": "更新聊天偏好","settingChat.title": "聊天设置",+ "settingChatAppearance.autoScrollOnStreaming.desc": "当 AI 正在生成回复时,自动滚动到底部",+ "settingChatAppearance.autoScrollOnStreaming.title": "AI 回复时自动滚动","settingChatAppearance.fontSize.desc": "消息字体大小","settingChatAppearance.fontSize.marks.normal": "标准","settingChatAppearance.fontSize.title": "字体大小",diff --git a/packages/types/src/agent/chatConfig.ts b/packages/types/src/agent/chatConfig.tsindex 8a6ac4a8dc8..168eda17083 100644--- a/packages/types/src/agent/chatConfig.ts+++ b/packages/types/src/agent/chatConfig.ts@@ -99,6 +99,12 @@ export interface LobeAgentChatConfig {* @default 6000*/toolResultMaxLength?: number;++ /**+ * Whether to auto-scroll during AI streaming output+ * undefined = use global setting+ */+ enableAutoScrollOnStreaming?: boolean;}/* eslint-enable */@@ -116,6 +122,7 @@ export const AgentChatConfigSchema = z.object({effort: z.enum(['low', 'medium', 'high', 'max']).optional(),enableAdaptiveThinking: z.boolean().optional(),enableAutoCreateTopic: z.boolean().optional(),+ enableAutoScrollOnStreaming: z.boolean().optional(),enableCompressHistory: z.boolean().optional(),enableContextCompression: z.boolean().optional(),enableHistoryCount: z.boolean().optional(),diff --git a/packages/types/src/user/settings/general.ts b/packages/types/src/user/settings/general.tsindex 414882f7d04..8035d4b64bc 100644--- a/packages/types/src/user/settings/general.ts+++ b/packages/types/src/user/settings/general.ts@@ -9,6 +9,11 @@ export type ContextMenuMode = 'disabled' | 'default';export interface UserGeneralConfig {animationMode?: AnimationMode;contextMenuMode?: ContextMenuMode;+ /**+ * Whether to auto-scroll during AI streaming output+ * @default true+ */+ enableAutoScrollOnStreaming?: boolean;fontSize: number;highlighterTheme?: HighlighterProps['theme'];isDevMode: boolean;diff --git a/src/app/[variants]/(main)/agent/profile/features/AgentSettings/Content.tsx b/src/app/[variants]/(main)/agent/profile/features/AgentSettings/Content.tsxindex 5e583b2ecff..24cf56ebc15 100644--- a/src/app/[variants]/(main)/agent/profile/features/AgentSettings/Content.tsx+++ b/src/app/[variants]/(main)/agent/profile/features/AgentSettings/Content.tsx@@ -4,7 +4,7 @@ import { Avatar, Block, Flexbox, Icon, Text } from '@lobehub/ui';import { useTheme } from 'antd-style';import type { ItemType } from 'antd/es/menu/interface';import isEqual from 'fast-deep-equal';-import { BrainIcon, MessageSquareHeartIcon } from 'lucide-react';+import { BrainIcon, MessageSquareHeartIcon, MessagesSquareIcon } from 'lucide-react';import { memo, useMemo, useState } from 'react';import { useTranslation } from 'react-i18next';@@ -46,6 +46,11 @@ const Content = memo(() => {label: t('agentTab.opening'),}: null,+ {+ icon: <Icon icon={MessagesSquareIcon} />,+ key: ChatSettingsTabs.Chat,+ label: t('agentTab.chat'),+ },{icon: <Icon icon={BrainIcon} />,key: ChatSettingsTabs.Modal,diff --git a/src/features/AgentSetting/AgentChat/index.tsx b/src/features/AgentSetting/AgentChat/index.tsxindex 66fa27b9397..f640204f9b2 100644--- a/src/features/AgentSetting/AgentChat/index.tsx+++ b/src/features/AgentSetting/AgentChat/index.tsx@@ -60,6 +60,15 @@ const AgentChat = memo(() => {name: 'enableCompressHistory',valuePropName: 'checked',},+ {+ children: <Switch />,+ desc: t('settingChat.enableAutoScrollOnStreaming.desc'),+ label: t('settingChat.enableAutoScrollOnStreaming.title'),+ layout: 'horizontal',+ minWidth: undefined,+ name: 'enableAutoScrollOnStreaming',+ valuePropName: 'checked',+ },],title: t('settingChat.title'),};diff --git a/src/features/Conversation/ChatList/components/AutoScroll/DebugInspector.tsx b/src/features/Conversation/ChatList/components/AutoScroll/DebugInspector.tsxindex 1ba1a540fa5..52c915d17d4 100644--- a/src/features/Conversation/ChatList/components/AutoScroll/DebugInspector.tsx+++ b/src/features/Conversation/ChatList/components/AutoScroll/DebugInspector.tsx@@ -4,12 +4,7 @@ import { memo } from 'react';import { createPortal } from 'react-dom';import { messageStateSelectors, useConversationStore, virtuaListSelectors } from '../../../store';--/**- * 判断是否在底部的阈值(单位:px)- * 当距离底部小于等于此值时,认为在底部- */-export const AT_BOTTOM_THRESHOLD = 300;+import { AT_BOTTOM_THRESHOLD } from './const';/*** 是否开启调试面板diff --git a/src/features/Conversation/ChatList/components/AutoScroll/const.ts b/src/features/Conversation/ChatList/components/AutoScroll/const.tsnew file mode 100644index 00000000000..9513856d52a--- /dev/null+++ b/src/features/Conversation/ChatList/components/AutoScroll/const.ts@@ -0,0 +1,5 @@+/**+ * 判断是否在底部的阈值(单位:px)+ * 当距离底部小于等于此值时,认为在底部+ */+export const AT_BOTTOM_THRESHOLD = 100;diff --git a/src/features/Conversation/ChatList/components/AutoScroll/index.tsx b/src/features/Conversation/ChatList/components/AutoScroll/index.tsxindex 2540e866666..f5273cc4420 100644--- a/src/features/Conversation/ChatList/components/AutoScroll/index.tsx+++ b/src/features/Conversation/ChatList/components/AutoScroll/index.tsx@@ -8,6 +8,7 @@ import {useConversationStore,virtuaListSelectors,} from '../../../store';+import { useAutoScrollEnabled } from './useAutoScrollEnabled';/*** AutoScroll component - handles auto-scrolling logic during AI generation.@@ -22,8 +23,9 @@ const AutoScroll = memo(() => {const isGenerating = useConversationStore(messageStateSelectors.isAIGenerating);const scrollToBottom = useConversationStore((s) => s.scrollToBottom);const dbMessages = useConversationStore(dataSelectors.dbMessages);+ const isAutoScrollEnabled = useAutoScrollEnabled();- const shouldAutoScroll = atBottom && isGenerating && !isScrolling;+ const shouldAutoScroll = isAutoScrollEnabled && atBottom && isGenerating && !isScrolling;// 获取最后一条消息的 content 长度,用于监听流式输出const lastMessage = dbMessages.at(-1);diff --git a/src/features/Conversation/ChatList/components/AutoScroll/useAutoScrollEnabled.ts b/src/features/Conversation/ChatList/components/AutoScroll/useAutoScrollEnabled.tsnew file mode 100644index 00000000000..6b6d4c0e6ea--- /dev/null+++ b/src/features/Conversation/ChatList/components/AutoScroll/useAutoScrollEnabled.ts@@ -0,0 +1,27 @@+import { useAgentStore } from '@/store/agent';+import { chatConfigByIdSelectors } from '@/store/agent/selectors';+import { useUserStore } from '@/store/user';+import { userGeneralSettingsSelectors } from '@/store/user/slices/settings/selectors';++import { contextSelectors, useConversationStore } from '../../../store';++/**+ * Get the auto-scroll enabled state for current context+ * Priority: Agent setting > Global setting > Default value (true)+ */+export const useAutoScrollEnabled = (): boolean => {+ const agentId = useConversationStore(contextSelectors.agentId);++ const agentChatConfig = useAgentStore(chatConfigByIdSelectors.getChatConfigById(agentId));+ console.log('agentChatConfig', agentChatConfig);+ const agentSetting = agentChatConfig?.enableAutoScrollOnStreaming;++ const globalSetting = useUserStore(userGeneralSettingsSelectors.enableAutoScrollOnStreaming);++ // Agent setting takes priority if defined+ if (agentSetting !== undefined) {+ return agentSetting;+ }++ return globalSetting;+};diff --git a/src/features/Conversation/ChatList/components/BackBottom/index.tsx b/src/features/Conversation/ChatList/components/BackBottom/index.tsxindex 09c32947f1d..042d6286012 100644--- a/src/features/Conversation/ChatList/components/BackBottom/index.tsx+++ b/src/features/Conversation/ChatList/components/BackBottom/index.tsx@@ -4,7 +4,8 @@ import { ArrowDownIcon } from 'lucide-react';import { memo } from 'react';import { useTranslation } from 'react-i18next';-import { AT_BOTTOM_THRESHOLD, OPEN_DEV_INSPECTOR } from '../AutoScroll/DebugInspector';+import { OPEN_DEV_INSPECTOR } from '../AutoScroll/DebugInspector';+import { AT_BOTTOM_THRESHOLD } from '../AutoScroll/const';import { styles } from './style';export interface BackBottomProps {diff --git a/src/features/Conversation/ChatList/components/VirtualizedList.tsx b/src/features/Conversation/ChatList/components/VirtualizedList.tsxindex 47194d3d112..12ba0a02af4 100644--- a/src/features/Conversation/ChatList/components/VirtualizedList.tsx+++ b/src/features/Conversation/ChatList/components/VirtualizedList.tsx@@ -8,10 +8,8 @@ import WideScreenContainer from '../../../WideScreenContainer';import { dataSelectors, useConversationStore, virtuaListSelectors } from '../../store';import { useScrollToUserMessage } from '../hooks/useScrollToUserMessage';import AutoScroll from './AutoScroll';-import DebugInspector, {- AT_BOTTOM_THRESHOLD,- OPEN_DEV_INSPECTOR,-} from './AutoScroll/DebugInspector';+import DebugInspector, { OPEN_DEV_INSPECTOR } from './AutoScroll/DebugInspector';+import { AT_BOTTOM_THRESHOLD } from './AutoScroll/const';import BackBottom from './BackBottom';interface VirtualizedListProps {diff --git a/src/locales/default/setting.ts b/src/locales/default/setting.tsindex 2f7bfa65794..976d13352bb 100644--- a/src/locales/default/setting.ts+++ b/src/locales/default/setting.ts@@ -417,6 +417,8 @@ export default {'settingChat.enableAutoCreateTopic.desc':'Whether to automatically create a topic during the conversation, only effective in temporary topics','settingChat.enableAutoCreateTopic.title': 'Auto Create Topic',+ 'settingChat.enableAutoScrollOnStreaming.desc': 'Override global setting for this assistant',+ 'settingChat.enableAutoScrollOnStreaming.title': 'Auto-scroll During AI Response','settingChat.enableCompressHistory.title': 'Enable Automatic Summary of Chat History','settingChat.enableHistoryCount.alias': 'Unlimited','settingChat.enableHistoryCount.limited': 'Include only {{number}} conversation messages',@@ -434,6 +436,9 @@ export default {'settingChat.inputTemplate.title': 'User Input Preprocessing','settingChat.submit': 'Update Chat Preferences','settingChat.title': 'Chat Settings',+ 'settingChatAppearance.autoScrollOnStreaming.desc':+ 'Automatically scroll to bottom when AI is generating response',+ 'settingChatAppearance.autoScrollOnStreaming.title': 'Auto-scroll During AI Response','settingChatAppearance.fontSize.desc': 'Font size of messages','settingChatAppearance.fontSize.marks.normal': 'Standard','settingChatAppearance.fontSize.title': 'Font Size',@@ -654,7 +659,8 @@ When I am ___, I need ___---💡 Tip: The more specific your description, the better we can meet your needs`,- 'skillStore.wantMore.feedback.title': '[Skill Request] Summarize the skill you need in one sentence',+ 'skillStore.wantMore.feedback.title':+ '[Skill Request] Summarize the skill you need in one sentence','skillStore.wantMore.reachedEnd': "You've reached the end. Can't find what you need?",'startConversation': 'Start Conversation','storage.actions.export.button': 'Export',diff --git a/src/store/user/slices/settings/selectors/general.ts b/src/store/user/slices/settings/selectors/general.tsindex e04a33b7556..bd68df6b5e1 100644--- a/src/store/user/slices/settings/selectors/general.ts+++ b/src/store/user/slices/settings/selectors/general.ts@@ -18,11 +18,14 @@ const contextMenuMode = (s: UserStore) => {return isDesktop ? 'default' : 'disabled';};const telemetry = (s: UserStore) => generalConfig(s).telemetry;+const enableAutoScrollOnStreaming = (s: UserStore) =>+ generalConfig(s).enableAutoScrollOnStreaming ?? true;export const userGeneralSettingsSelectors = {animationMode,config: generalConfig,contextMenuMode,+ enableAutoScrollOnStreaming,fontSize,highlighterTheme,mermaidTheme,