@@ -93,22 +93,14 @@ const agentTransitions = useAgentTransitions();
9393const showScrollContainer = ref (true );
9494const chatContainerRef = ref <HTMLElement | null >(null );
9595const messagesRefs = ref <Array <HTMLElement | null >>([]);
96- const useWaitingForHeight = ref (false );
97-
9896/*
9997* Whenever user sends a message, it adds a bottom spacer, that takes the remaining height
10098* without last user and last agent message.
10199*
102100* On send message, happens the following logic:
103101* 1) showBottomSpacer is set to true
104- * 2) useWaitingForHeight is set to true and in 1000s set back to false
105- * Why do we do this?
106- * - When we want to read height of last user message, incremark shows text with some small delay
107- * - so when we read height of last user message, we actully getting height of the box without text ~18px
108- * - so for the initial period while useWaitingForHeight is true, we are waiting for real height to be bigger than 18px
109- * - and then we can read in normally, until new message is sent, then we need to wait again
110- * 3) updateSpacerHeight is called, which calculates the height for spacer based on scroll container height and messages height
111- * 4) Spacer moves text up
102+ * 2) updateSpacerHeight is called, which calculates the height for spacer based on scroll container height and messages height
103+ * 3) Spacer moves text up
112104*/
113105const showBottomSpacer = ref (false );
114106const spacerHeight = ref (0 );
@@ -197,20 +189,6 @@ function getScrollClientHeight() {
197189 return scrollContainer .value ?.container .scrollEl .clientHeight ?? scrollContainer .value ?.scrollParams .clientHeight ?? 0 ;
198190}
199191
200- async function waitForRealHeight(role : ' user' | ' assistant' ): Promise <number > {
201- const realHeightWeCanApprove = role === ' user' ? EMPTY_MESSAGE_HEIGHT : 0 ;
202- return new Promise ((resolve ) => {
203- const interval = setInterval (() => {
204- const height = role === ' user' ? getHeightOfLastUserMessage () : getHeightOfLastAgentMessage ();
205-
206- if (height > realHeightWeCanApprove ) {
207- clearInterval (interval );
208- resolve (height );
209- }
210- }, 50 );
211- });
212- }
213-
214192async function updateSpacerHeight() {
215193 if (! showBottomSpacer .value ) {
216194 return ;
@@ -222,8 +200,8 @@ async function updateSpacerHeight() {
222200 return ;
223201 }
224202
225- const lastUserMessageHeight = useWaitingForHeight . value ? await waitForRealHeight ( ' user ' ) : getHeightOfLastUserMessage ();
226- const lastAgentMessageHeight = useWaitingForHeight . value ? await waitForRealHeight ( ' assistant ' ) : getHeightOfLastAgentMessage ();
203+ const lastUserMessageHeight = getHeightOfLastUserMessage ();
204+ const lastAgentMessageHeight = getHeightOfLastAgentMessage ();
227205
228206 spacerHeight .value = Math .max (0 , clientHeight - (lastUserMessageHeight + MASK_HEIGHT + lastAgentMessageHeight ));
229207}
@@ -245,6 +223,14 @@ function scheduleSpacerHeightUpdate() {
245223 spacerUpdateQueued = false ;
246224 pendingSpacerUpdate = updateSpacerHeight ().finally (() => {
247225 pendingSpacerUpdate = null ;
226+
227+ // Auto-scroll to bottom if response generation is in progress
228+ if (agentStore .isResponseInProgress ) {
229+ nextTick (() => {
230+ scrollContainer .value ?.scrollToBottom ();
231+ });
232+ }
233+
248234 if (spacerUpdateQueued ) {
249235 scheduleSpacerHeightUpdate ();
250236 }
@@ -298,10 +284,6 @@ async function handleSendMessage() {
298284
299285 if (clientHeight ) {
300286 showBottomSpacer .value = true ;
301- useWaitingForHeight .value = true ;
302- setTimeout (() => {
303- useWaitingForHeight .value = false ;
304- }, 1000 );
305287 await updateSpacerHeight ();
306288 await nextTick ();
307289 scrollContainer .value ?.scrollToBottom ();
0 commit comments