4
4
*/
5
5
import { AlertCircle , Camera , Loader2 } from 'lucide-react' ;
6
6
import { Button } from '@renderer/components/ui/button' ;
7
+ import { GUIAgentError , ErrorStatusEnum } from '@ui-tars/shared/types' ;
7
8
8
9
export const HumanTextMessage = ( { text } : { text : string } ) => {
9
10
return (
@@ -27,13 +28,46 @@ export const ScreenshotMessage = ({ onClick }: ScreenshotMessageProps) => {
27
28
} ;
28
29
29
30
export const ErrorMessage = ( { text } : { text : string } ) => {
31
+ let parsedError : GUIAgentError | null = null ;
32
+ try {
33
+ const parsed = JSON . parse ( text ) ;
34
+ if ( parsed && typeof parsed === 'object' && 'code' in parsed ) {
35
+ parsedError = parsed as GUIAgentError ;
36
+ }
37
+ } catch {
38
+ // ignore
39
+ }
40
+
30
41
return (
31
42
< div className = "flex flex-col gap-2 my-4 p-4 bg-red-500/10 border border-red-500/20 rounded-lg" >
32
43
< div className = "flex items-center gap-2" >
33
44
< AlertCircle className = "w-5 h-5 text-red-500 shrink-0" />
34
- < span className = "font-medium text-red-500" > Error</ span >
45
+ < span className = "font-medium text-red-500" >
46
+ { parsedError
47
+ ? ErrorStatusEnum [ parsedError . code ] || 'UNKNOWN_ERROR'
48
+ : 'Error' }
49
+ </ span >
35
50
</ div >
36
- < div className = "text-sm text-red-500/90 break-all" > { text } </ div >
51
+ { parsedError ? (
52
+ < div className = "flex flex-col gap-1" >
53
+ < div className = "text-sm text-red-500/90 font-medium" >
54
+ { parsedError . message }
55
+ </ div >
56
+ { parsedError . stack ? (
57
+ < div className = "text-xs text-red-500/70 font-mono mt-2" >
58
+ { parsedError . stack }
59
+ </ div >
60
+ ) : (
61
+ parsedError . detail && (
62
+ < div className = "text-xs text-red-500/70 font-mono mt-2" >
63
+ { parsedError . detail }
64
+ </ div >
65
+ )
66
+ ) }
67
+ </ div >
68
+ ) : (
69
+ < div className = "text-sm text-red-500/90 break-all" > { text } </ div >
70
+ ) }
37
71
</ div >
38
72
) ;
39
73
} ;
0 commit comments