@@ -13,11 +13,9 @@ import { serverConfigQueryOptions } from "~/lib/serverReactQuery";
1313import { toastManager } from "~/components/ui/toast" ;
1414
1515import { SmeConversationDialog } from "./SmeConversationDialog" ;
16- import { SmeMessageBubble } from "./SmeMessageBubble " ;
16+ import { SmeMessageList } from "./SmeMessageList " ;
1717import { getSmeAuthMethodLabel , SME_PROVIDER_LABELS } from "./smeConversationConfig" ;
1818
19- const EMPTY_MESSAGES : SmeMessage [ ] = [ ] ;
20-
2119interface SmeChatWorkspaceProps {
2220 conversationId : string | null ;
2321 onToggleKnowledge : ( ) => void ;
@@ -36,17 +34,9 @@ export function SmeChatWorkspace({
3634 ( ) => conversations . find ( ( item ) => item . conversationId === conversationId ) ?? null ,
3735 [ conversationId , conversations ] ,
3836 ) ;
39- const messages = useSmeStore ( ( state ) =>
40- conversationId
41- ? ( state . messagesByConversation [ conversationId ] ?? EMPTY_MESSAGES )
42- : EMPTY_MESSAGES ,
43- ) ;
4437 const conversationError = useSmeStore ( ( state ) =>
4538 conversationId ? state . errorsByConversation [ conversationId ] : undefined ,
4639 ) ;
47- const streamingConversationId = useSmeStore ( ( state ) => state . streamingConversationId ) ;
48- const streamingMessageId = useSmeStore ( ( state ) => state . streamingMessageId ) ;
49- const streamingText = useSmeStore ( ( state ) => state . streamingText ) ;
5040 const addUserMessage = useSmeStore ( ( state ) => state . addUserMessage ) ;
5141 const clearStream = useSmeStore ( ( state ) => state . clearStream ) ;
5242 const setMessages = useSmeStore ( ( state ) => state . setMessages ) ;
@@ -55,7 +45,6 @@ export function SmeChatWorkspace({
5545 const [ sending , setSending ] = useState ( false ) ;
5646 const [ dialogOpen , setDialogOpen ] = useState ( false ) ;
5747 const [ bannerDismissed , setBannerDismissed ] = useState ( false ) ;
58- const messagesEndRef = useRef < HTMLDivElement > ( null ) ;
5948 const textareaRef = useRef < HTMLTextAreaElement > ( null ) ;
6049 const serverConfigQuery = useQuery ( serverConfigQueryOptions ( ) ) ;
6150 const validationQuery = useQuery ( {
@@ -96,10 +85,6 @@ export function SmeChatWorkspace({
9685 setBannerDismissed ( false ) ;
9786 } , [ conversationId ] ) ;
9887
99- useEffect ( ( ) => {
100- messagesEndRef . current ?. scrollIntoView ( { behavior : "smooth" } ) ;
101- } , [ messages , streamingText ] ) ;
102-
10388 useEffect ( ( ) => {
10489 const textarea = textareaRef . current ;
10590 if ( ! textarea ) return ;
@@ -116,7 +101,7 @@ export function SmeChatWorkspace({
116101 setInputText ( "" ) ;
117102 setSending ( true ) ;
118103 setConversationError ( conversationId , undefined ) ;
119- const previousMessages = messages ;
104+ const previousMessages = useSmeStore . getState ( ) . messagesByConversation [ conversationId ] ?? [ ] ;
120105
121106 addUserMessage ( conversationId , {
122107 messageId : `temp-${ Date . now ( ) } ` as SmeMessageId ,
@@ -174,7 +159,6 @@ export function SmeChatWorkspace({
174159 conversation ,
175160 conversationId ,
176161 inputText ,
177- messages ,
178162 providerOptions ,
179163 sendDisabled ,
180164 setConversationError ,
@@ -289,47 +273,7 @@ export function SmeChatWorkspace({
289273 ) : null }
290274 </ div >
291275
292- < div className = "flex-1 overflow-y-auto" >
293- < div className = "mx-auto max-w-3xl" >
294- { messages . map ( ( message ) => (
295- < SmeMessageBubble key = { message . messageId } message = { message } />
296- ) ) }
297- { streamingConversationId === conversationId && streamingText ? (
298- < SmeMessageBubble
299- message = {
300- {
301- messageId : ( streamingMessageId ?? "streaming" ) as SmeMessageId ,
302- conversationId : conversationId as SmeConversationId ,
303- role : "assistant" ,
304- text : streamingText ,
305- isStreaming : true ,
306- createdAt : new Date ( ) . toISOString ( ) ,
307- updatedAt : new Date ( ) . toISOString ( ) ,
308- } as SmeMessage
309- }
310- />
311- ) : null }
312- { sending && ! streamingText ? (
313- < div className = "flex items-center gap-4 px-4 py-5" >
314- < div className = "flex size-8 shrink-0 items-center justify-center rounded-lg bg-gradient-to-br from-primary/80 to-primary text-primary-foreground" >
315- < SparklesIcon className = "size-4" />
316- </ div >
317- < div className = "space-y-1" >
318- < p className = "text-xs font-medium text-muted-foreground" > SME Assistant</ p >
319- < div className = "flex items-center gap-1.5" >
320- < div className = "flex gap-1" >
321- < span className = "size-1.5 animate-bounce rounded-full bg-muted-foreground/50 [animation-delay:0ms]" />
322- < span className = "size-1.5 animate-bounce rounded-full bg-muted-foreground/50 [animation-delay:150ms]" />
323- < span className = "size-1.5 animate-bounce rounded-full bg-muted-foreground/50 [animation-delay:300ms]" />
324- </ div >
325- < span className = "text-xs text-muted-foreground" > Thinking...</ span >
326- </ div >
327- </ div >
328- </ div >
329- ) : null }
330- < div ref = { messagesEndRef } />
331- </ div >
332- </ div >
276+ < SmeMessageList conversationId = { conversationId } sending = { sending } />
333277
334278 < div className = "px-4 pb-4 pt-2" >
335279 < div className = "mx-auto max-w-3xl" >
0 commit comments