1
1
import React , { useEffect , useState } from "react" ;
2
- import { Accordion , AccordionContent , AccordionItem , AccordionTrigger } from "@/components/ui/accordion" ;
3
2
import { Badge } from "@/components/ui/badge" ;
4
3
import { PreviewMessage , UIMessage } from "./ChatMessages" ;
5
4
import ReactMarkdown from "react-markdown" ;
@@ -148,15 +147,6 @@ const ThinkingMessage = () => {
148
147
) ;
149
148
} ;
150
149
151
- // Helper to render JSON content with syntax highlighting
152
- const renderJson = ( obj : unknown ) => {
153
- return (
154
- < pre className = "max-h-[300px] overflow-auto whitespace-pre-wrap rounded-md bg-muted p-4 font-mono text-sm" >
155
- { JSON . stringify ( obj , null , 2 ) }
156
- </ pre >
157
- ) ;
158
- } ;
159
-
160
150
// Markdown content renderer component
161
151
const MarkdownContent : React . FC < { content : string } > = ( { content } ) => {
162
152
return (
@@ -227,22 +217,6 @@ const MarkdownContent: React.FC<{ content: string }> = ({ content }) => {
227
217
) ;
228
218
} ;
229
219
230
- // Helper function to ensure image content is properly formatted
231
- const formatImageSource = ( content : string ) : string => {
232
- // If already a data URI, use as is
233
- if ( content . startsWith ( "data:image/" ) ) {
234
- return content ;
235
- }
236
-
237
- // If it looks like base64 data without a prefix, add a PNG prefix
238
- if ( / ^ [ A - Z a - z 0 - 9 + / = ] + $ / . test ( content . substring ( 0 , 20 ) ) ) {
239
- return `data:image/png;base64,${ content } ` ;
240
- }
241
-
242
- // Otherwise assume it's a URL
243
- return content ;
244
- } ;
245
-
246
220
// Component to render display objects
247
221
const DisplayObjectRenderer : React . FC < { object : DisplayObject ; isInSourceView ?: boolean } > = ( {
248
222
object,
@@ -266,9 +240,9 @@ const DisplayObjectRenderer: React.FC<{ object: DisplayObject; isInSourceView?:
266
240
src = { hasImagePrefix ? object . content : `data:image/png;base64,${ object . content } ` }
267
241
alt = { object . caption || "Image" }
268
242
className = "h-auto max-w-full"
269
- onError = { e => {
270
- // Fallback chain: try JPEG if PNG fails
271
- const target = e . target as HTMLImageElement ;
243
+ onError = { event => {
244
+ // Correctly typed event parameter
245
+ const target = event . target as HTMLImageElement ;
272
246
if ( ! hasImagePrefix && target . src . includes ( "image/png" ) ) {
273
247
target . src = `data:image/jpeg;base64,${ object . content } ` ;
274
248
}
@@ -283,35 +257,8 @@ const DisplayObjectRenderer: React.FC<{ object: DisplayObject; isInSourceView?:
283
257
return null ;
284
258
} ;
285
259
286
- // Helper function to detect image format from base64
287
- const detectImageFormat = ( base64String : string ) : string => {
288
- // Check the first few bytes of the base64 to determine image format
289
- // See: https://en.wikipedia.org/wiki/List_of_file_signatures
290
- try {
291
- if ( ! base64String || base64String . length < 10 ) return "png" ;
292
-
293
- // Decode the first few bytes of the base64 string
294
- const firstBytes = atob ( base64String . substring ( 0 , 20 ) ) ;
295
-
296
- // Check for common image signatures
297
- if ( firstBytes . startsWith ( "\xFF\xD8\xFF" ) ) return "jpeg" ;
298
- if ( firstBytes . startsWith ( "\x89PNG\r\n\x1A\n" ) ) return "png" ;
299
- if ( firstBytes . startsWith ( "GIF87a" ) || firstBytes . startsWith ( "GIF89a" ) ) return "gif" ;
300
- if ( firstBytes . startsWith ( "RIFF" ) && firstBytes . substring ( 8 , 12 ) === "WEBP" ) return "webp" ;
301
-
302
- // Default to PNG if signature not recognized
303
- return "png" ;
304
- } catch ( e ) {
305
- // If any error in detection, default to PNG
306
- return "png" ;
307
- }
308
- } ;
309
-
310
260
// Component to render sources as tags with dropdown content
311
- const SourcesRenderer : React . FC < { sources : SourceObject [ ] ; displayObjects ?: DisplayObject [ ] } > = ( {
312
- sources,
313
- displayObjects = [ ] ,
314
- } ) => {
261
+ const SourcesRenderer : React . FC < { sources : SourceObject [ ] } > = ( { sources } ) => {
315
262
const [ selectedSource , setSelectedSource ] = useState < string | null > ( null ) ;
316
263
const [ animation , setAnimation ] = useState < "open" | "close" | null > ( null ) ;
317
264
const [ visibleContent , setVisibleContent ] = useState < string | null > ( null ) ;
@@ -470,7 +417,7 @@ export function AgentPreviewMessage({ message }: AgentMessageProps) {
470
417
{ /* Render sources if available */ }
471
418
{ sources && sources . length > 0 && (
472
419
< div className = "mt-4 border-t border-border pt-3" >
473
- < SourcesRenderer sources = { sources } displayObjects = { displayObjects } />
420
+ < SourcesRenderer sources = { sources } />
474
421
</ div >
475
422
) }
476
423
</ div >
0 commit comments