@@ -8,7 +8,8 @@ import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'
88import { github } from "react-syntax-highlighter/dist/esm/styles/hljs"
99import { Badge } from "@/components/ui/badge"
1010import { Button } from "@/components/ui/button"
11- import { formatCodeBlock , preprocessCodeInAnswer } from "@/lib/utils"
11+ import { decodeProcessedAnswer , formatCodeBlock , preprocessCodeInAnswer } from "@/lib/utils"
12+ import { AIAnswer } from "@/lib/types" ;
1213
1314interface AnswerDisplayProps {
1415 answer : string
@@ -20,9 +21,26 @@ interface AnswerDisplayProps {
2021 onRetry ?: ( ) => void
2122}
2223
23- export default function AnswerDisplay ( {
24- answer,
25- language,
24+
25+ // Decode any encoded code blocks
26+ const processContent = ( content : string ) => {
27+ return decodeProcessedAnswer ( content ) ;
28+ }
29+
30+ // Process the answer to decode Base64 encoded blocks
31+ const getProcessedContent = ( displayAnswer : string | AIAnswer , language : string ) => {
32+ if ( typeof displayAnswer === "string" ) {
33+ return processContent ( displayAnswer ) ;
34+ } else if ( displayAnswer && displayAnswer . answer ) {
35+ const content = displayAnswer . answer [ language ] || displayAnswer . answer . en || "" ;
36+ return processContent ( content ) ;
37+ }
38+ return "" ;
39+ }
40+
41+ export default function AnswerDisplay ( {
42+ answer,
43+ language,
2644 isStreaming = false ,
2745 parsedAnswer,
2846 onClose,
@@ -51,8 +69,11 @@ export default function AnswerDisplay({
5169 )
5270 }
5371
72+
73+
5474 // Use parsed answer if available, otherwise fall back to the original answer
55- const displayAnswer = parsedAnswer ? preprocessCodeInAnswer ( parsedAnswer ) : answer
75+ let displayAnswer = parsedAnswer ? preprocessCodeInAnswer ( parsedAnswer ) : answer
76+
5677
5778 // If we're getting string data but couldn't parse it
5879 if ( typeof displayAnswer === "string" ) {
@@ -93,13 +114,13 @@ export default function AnswerDisplay({
93114 code ( { node, className, children, ...props } : any ) {
94115 const match = / l a n g u a g e - ( \w + ) / . exec ( className || '' )
95116 const inline = ! match
96-
117+
97118 if ( ! inline ) {
98- // Format code using our utility function
119+ // Format code using our utility function
99120 const { code, language : detectedLanguage } = formatCodeBlock ( String ( children ) ) ;
100121 // Use either the detected language or the one from className
101122 const langToUse = match ? match [ 1 ] : detectedLanguage ;
102-
123+
103124 return (
104125 < SyntaxHighlighter
105126 style = { github }
@@ -130,8 +151,7 @@ export default function AnswerDisplay({
130151 )
131152 }
132153
133- const answerContent = typeof displayAnswer === "string" ?
134- displayAnswer : displayAnswer . answer ?. [ language ] || displayAnswer . answer ?. en || displayAnswer
154+ const answerContent = getProcessedContent ( displayAnswer , language ) ;
135155
136156 return (
137157 < Card className = "mb-6 shadow-sm border border-gray-200 dark:border-gray-800 bg-white dark:bg-[#2c2c2e] rounded-xl" >
@@ -166,13 +186,13 @@ export default function AnswerDisplay({
166186 code ( { node, className, children, ...props } : any ) {
167187 const match = / l a n g u a g e - ( \w + ) / . exec ( className || '' )
168188 const inline = ! match
169-
189+
170190 if ( ! inline ) {
171- // Format code using our utility function
191+ // Format code using our utility function
172192 const { code, language : detectedLanguage } = formatCodeBlock ( String ( children ) ) ;
173193 // Use either the detected language or the one from className
174194 const langToUse = match ? match [ 1 ] : detectedLanguage ;
175-
195+
176196 return (
177197 < SyntaxHighlighter
178198 style = { github }
0 commit comments