@@ -18,7 +18,7 @@ import {
1818 Textarea
1919} from '@internal/components' ;
2020import { useChat } from 'ai/react' ;
21- import { Bot , Clock , Send , User } from 'lucide-react' ;
21+ import { Bot , Clock , Lightbulb , Send , User , Wrench } from 'lucide-react' ;
2222import { useSearchParams } from 'next/navigation' ;
2323import { useEffect , useRef , useState } from 'react' ;
2424import ReactMarkdown from 'react-markdown' ;
@@ -159,44 +159,66 @@ export function ChatsUI({ connections }: { connections: DbConnection[] }) {
159159 </ div >
160160 ) }
161161 { messages . map ( ( message ) => (
162- < div
163- key = { message . id }
164- className = { `flex gap-3 ${ message . role === 'assistant' ? 'flex-row' : 'flex-row-reverse' } ` }
165- >
166- < Avatar >
167- < AvatarFallback >
168- { message . role === 'assistant' ? < Bot className = "h-6 w-6" /> : < User className = "h-6 w-6" /> }
169- </ AvatarFallback >
170- </ Avatar >
171- < div
172- className = { `max-w-[80%] rounded-lg px-4 py-2 ${
173- message . role === 'assistant' ? 'bg-secondary' : 'bg-primary text-primary-foreground ml-auto'
174- } `}
175- >
176- < ReactMarkdown
177- components = { {
178- p : ( { children } ) => < p className = "mb-2 text-sm last:mb-0" > { children } </ p > ,
179- ul : ( { children } ) => < ul className = "mb-2 list-inside list-disc text-sm" > { children } </ ul > ,
180- ol : ( { children } ) => < ol className = "mb-2 list-inside list-decimal text-sm" > { children } </ ol > ,
181- li : ( { children } ) => < li className = "mb-1" > { children } </ li > ,
182- h1 : ( { children } ) => < h1 className = "mb-2 text-xl font-bold" > { children } </ h1 > ,
183- h2 : ( { children } ) => < h2 className = "mb-2 text-lg font-semibold" > { children } </ h2 > ,
184- h3 : ( { children } ) => < h3 className = "mb-2 text-base font-medium" > { children } </ h3 > ,
185- code : ( { children } ) => (
186- < code className = "rounded bg-black px-1 py-0.5 font-mono text-sm text-white" > { children } </ code >
187- )
188- } }
162+ < div key = { message . id } className = "space-y-4" >
163+ { message . parts . map ( ( part , index ) => (
164+ < div
165+ key = { `${ message . id } -${ index } ` }
166+ className = { `flex gap-3 ${ message . role === 'assistant' ? 'flex-row' : 'flex-row-reverse' } ` }
189167 >
190- { message . content }
191- </ ReactMarkdown >
192- { message . toolInvocations &&
193- message . toolInvocations . map ( ( tool , index ) => (
194- < div key = { index } className = "text-muted-foreground mt-2 text-xs" >
195- < Clock className = "mr-1 inline-block h-4 w-4" />
196- Tool called: { tool . toolName }
197- </ div >
198- ) ) }
199- </ div >
168+ < Avatar >
169+ < AvatarFallback >
170+ { part . type === 'text' && message . role === 'user' ? (
171+ < User className = "h-6 w-6" />
172+ ) : part . type === 'text' ? (
173+ < Bot className = "h-6 w-6" />
174+ ) : part . type === 'tool-invocation' ? (
175+ < Wrench className = "h-6 w-6" />
176+ ) : part . type === 'reasoning' ? (
177+ < Lightbulb className = "h-6 w-6" />
178+ ) : null }
179+ </ AvatarFallback >
180+ </ Avatar >
181+
182+ < div
183+ className = { `max-w-[80%] rounded-lg px-4 py-2 ${
184+ message . role === 'assistant' ? 'bg-secondary' : 'bg-primary text-primary-foreground ml-auto'
185+ } `}
186+ >
187+ { part . type === 'text' ? (
188+ < ReactMarkdown
189+ components = { {
190+ p : ( { children } ) => < p className = "mb-2 text-sm last:mb-0" > { children } </ p > ,
191+ ul : ( { children } ) => < ul className = "mb-2 list-inside list-disc text-sm" > { children } </ ul > ,
192+ ol : ( { children } ) => (
193+ < ol className = "mb-2 list-inside list-decimal text-sm" > { children } </ ol >
194+ ) ,
195+ li : ( { children } ) => < li className = "mb-1" > { children } </ li > ,
196+ h1 : ( { children } ) => < h1 className = "mb-2 text-xl font-bold" > { children } </ h1 > ,
197+ h2 : ( { children } ) => < h2 className = "mb-2 text-lg font-semibold" > { children } </ h2 > ,
198+ h3 : ( { children } ) => < h3 className = "mb-2 text-base font-medium" > { children } </ h3 > ,
199+ code : ( { children } ) => (
200+ < code className = "rounded bg-black px-1 py-0.5 font-mono text-sm text-white" >
201+ { children }
202+ </ code >
203+ )
204+ } }
205+ >
206+ { message . content }
207+ </ ReactMarkdown >
208+ ) : part . type === 'tool-invocation' ? (
209+ < div className = "text-muted-foreground mt-1 text-xs" >
210+ < Clock className = "mr-1 inline-block h-4 w-4" />
211+ Tool called: { part . toolInvocation . toolName }
212+ </ div >
213+ ) : part . type === 'reasoning' ? (
214+ < div className = "text-muted-foreground mt-1 text-xs" >
215+ < Clock className = "mr-1 inline-block h-4 w-4" />
216+ { part . type }
217+ </ div >
218+ ) : null }
219+ </ div >
220+ </ div >
221+ ) ) }
200222 </ div >
201223 ) ) }
202224 { isLoading && (
0 commit comments