1- import React , { Fragment , useEffect , useState , useCallback , useRef } from 'react' ;
1+ import React , { Fragment , useEffect , useState , useCallback } from 'react' ;
22import {
33 Chatbot ,
44 ChatbotContent ,
@@ -361,6 +361,11 @@ export function Chat({ preSelectedAgentId }: ChatProps = {}) {
361361 try {
362362 await loadSession ( selectedItem ) ;
363363 setIsDrawerOpen ( false ) ; // Close sidebar after selection
364+ // Always show warning when switching to a different session
365+ // User will manually dismiss it if not needed
366+ setHistoryWarning (
367+ 'Note: Some messages may not be displayed due to conversation history limitations.'
368+ ) ;
364369 } catch ( error ) {
365370 console . error ( 'Error loading session:' , error ) ;
366371 setAnnouncement ( 'Failed to load chat session' ) ;
@@ -382,6 +387,11 @@ export function Chat({ preSelectedAgentId }: ChatProps = {}) {
382387 setIsDrawerOpen ( false ) ;
383388 setIsSwitchWarningOpen ( false ) ;
384389 setPendingSessionSwitch ( null ) ;
390+ // Always show warning when switching to a different session
391+ // User will manually dismiss it if not needed
392+ setHistoryWarning (
393+ 'Note: Some messages may not be displayed due to conversation history limitations.'
394+ ) ;
385395 } catch ( error ) {
386396 console . error ( 'Error loading session:' , error ) ;
387397 setAnnouncement ( 'Failed to load chat session' ) ;
@@ -418,6 +428,8 @@ export function Chat({ preSelectedAgentId }: ChatProps = {}) {
418428 await fetchSessionsData ( selectedAgent ) ;
419429
420430 setIsDrawerOpen ( false ) ;
431+ // Clear warning for new chat
432+ setHistoryWarning ( null ) ;
421433 } catch ( error ) {
422434 console . error ( 'Error creating new session:' , error ) ;
423435 setAnnouncement ( 'Failed to create new chat session' ) ;
@@ -535,6 +547,11 @@ export function Chat({ preSelectedAgentId }: ChatProps = {}) {
535547 if ( ( ! sessionId || ! currentSessionExists ) && sessions . length > 0 ) {
536548 const firstSession = sessions [ 0 ] ; // Sessions should be ordered by updated_at desc (most recent first)
537549 await loadSession ( firstSession . id ) ;
550+ // Always show warning when loading a session
551+ // User will manually dismiss it if not needed
552+ setHistoryWarning (
553+ 'Note: Some messages may not be displayed due to conversation history limitations.'
554+ ) ;
538555 } else if ( sessions . length === 0 && agentId ) {
539556 // Create a new session if agent has no sessions
540557 try {
@@ -628,28 +645,6 @@ export function Chat({ preSelectedAgentId }: ChatProps = {}) {
628645 // eslint-disable-next-line react-hooks/exhaustive-deps
629646 } , [ selectedAgent ] ) ; // fetchSessionsData intentionally excluded to prevent infinite loop
630647
631- // Track when session changes to show warning only on session switch
632- const prevSessionIdRef = useRef < string | null > ( null ) ;
633-
634- // Show history warning only when switching to a different session with existing messages
635- useEffect ( ( ) => {
636- // Check if session ID actually changed
637- const sessionChanged = prevSessionIdRef . current !== sessionId ;
638- prevSessionIdRef . current = sessionId ;
639-
640- if ( sessionChanged ) {
641- // Only show warning if we have messages and a session ID
642- // Clear warning when no messages (new/empty session)
643- if ( chatMessages . length > 0 && sessionId ) {
644- setHistoryWarning (
645- 'Note: Some messages may not be displayed due to conversation history limitations.'
646- ) ;
647- } else {
648- setHistoryWarning ( null ) ;
649- }
650- }
651- } , [ chatMessages . length , sessionId ] ) ;
652-
653648 // Handle message sending
654649 const handleSendMessage = async ( message : string | number ) => {
655650 if ( typeof message === 'string' && message . trim ( ) && selectedAgent ) {
0 commit comments