|  | 
| 1 |  | -import React, { useEffect, useRef, useState } from "react"; | 
|  | 1 | +import React, { useEffect, useRef } from "react"; | 
| 2 | 2 | import Dialog from "@material-ui/core/Dialog"; | 
| 3 | 3 | import { DialogContent, DialogTitle, makeStyles } from "@material-ui/core"; | 
| 4 | 4 | import { useAiBot } from "../hooks"; | 
| 5 |  | -import rehypeRaw from "rehype-raw"; | 
| 6 |  | -import remarkGfm from "remark-gfm"; | 
| 7 |  | -import ReactMarkdown from "react-markdown"; | 
| 8 | 5 | import IconButton from "@material-ui/core/IconButton"; | 
| 9 | 6 | import CloseIcon from "@material-ui/icons/Close"; | 
| 10 |  | -import { disallowedHtmlTagsForMarkdown } from "../utils"; | 
| 11 | 7 | import { DebugLogs } from "../DebugLogs/DebugLogs"; | 
| 12 |  | -import { DebugMessage } from "../../../types/api/entities/bot"; | 
|  | 8 | +import { createMessageFragment } from "../utils"; | 
| 13 | 9 | 
 | 
| 14 | 10 | const useStyles = makeStyles( | 
| 15 | 11 |   (theme) => ({ | 
| 16 | 12 |     dialogStyle: { | 
| 17 | 13 |       top: '5%!important', | 
| 18 | 14 |       right: '10%!important', | 
| 19 | 15 |       left: 'unset!important', | 
| 20 |  | -      height: 'fit-content', | 
| 21 |  | -      width: 'fit-content', | 
|  | 16 | +      height: '80vh', | 
|  | 17 | +      width: '80vw', | 
| 22 | 18 |     }, | 
| 23 | 19 |     paper: { | 
| 24 | 20 |       width: '80vw', | 
| 25 |  | -      height: '70vh', | 
|  | 21 | +      height: '80vh', | 
| 26 | 22 |       opacity: '.5', | 
| 27 | 23 |       transition: '.2s ease', | 
| 28 | 24 |       '&:hover': { | 
| @@ -58,17 +54,19 @@ export const DebugConsole = (props: DebugConsoleProps) => { | 
| 58 | 54 | 
 | 
| 59 | 55 |   useEffect(() => { | 
| 60 | 56 |     if (containerRef.current && debugMessages?.length && threadId && !debugMessagesLoading && isOpen) { | 
| 61 |  | -      let code: HTMLElement = containerRef.current.getElementsByTagName('code')?.[0]; | 
|  | 57 | +      let code = containerRef.current.getElementsByTagName('code')?.[0]; | 
|  | 58 | +      if (!code) { | 
|  | 59 | +        code = document.createElement('code'); | 
|  | 60 | +        containerRef.current.appendChild(code); | 
|  | 61 | +      } | 
|  | 62 | + | 
| 62 | 63 |       if (code.hasChildNodes()) { | 
| 63 |  | -        code.appendChild(document.createTextNode(`[${debugMessages[debugMessages.length - 1].created_at}]: ${debugMessages[debugMessages.length - 1].content}\n`)) | 
|  | 64 | +        const lastMessage = debugMessages[debugMessages.length - 1]; | 
|  | 65 | +        const fragment = createMessageFragment([lastMessage]); | 
|  | 66 | +        code.appendChild(fragment); | 
| 64 | 67 |       } else { | 
| 65 |  | -        debugMessages.forEach((item) => { | 
| 66 |  | -          code.appendChild(document.createTextNode(`[${item.created_at}]: ${item.content}\n`)) | 
| 67 |  | -        }) | 
| 68 |  | -        const container = document.getElementById(`logs-container-${threadId}`); | 
| 69 |  | -        if (container) { | 
| 70 |  | -          container.appendChild(code) | 
| 71 |  | -        } | 
|  | 68 | +        const fragment = createMessageFragment(debugMessages); | 
|  | 69 | +        code.appendChild(fragment); | 
| 72 | 70 |       } | 
| 73 | 71 |     } | 
| 74 | 72 |   }, [debugMessages, isOpen, threadId, debugMessagesLoading]); | 
|  | 
0 commit comments