Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Add highlight to code in pretty logs

Vasek Mlejnsky9e3fc20bbfd2
diff --git a/components/Editor/RightSidebar/Logs/LogEntry.tsx b/components/Editor/RightSidebar/Logs/LogEntry.tsx
index e988fc88c..b6836394a 100644
--- a/components/Editor/RightSidebar/Logs/LogEntry.tsx
+++ b/components/Editor/RightSidebar/Logs/LogEntry.tsx
@@ -1,7 +1,17 @@
-import { Log } from 'db/types'
-import { Code2, Package, TerminalSquare, Wrench } from 'lucide-react'
+import {
+ useEffect,
+} from 'react'
+import hljs from 'highlight.js'
+import {
+ Code2,
+ Package,
+ TerminalSquare,
+ Wrench,
+} from 'lucide-react'
import { ReactMarkdown } from 'react-markdown/lib/react-markdown'
+import { Log } from 'db/types'
+
function getToolIcon(toolName: string) {
switch (toolName) {
case 'InstallNPMDependencies':
@@ -20,12 +30,16 @@ export interface Props {
}
function LogEntry({ log }: Props) {
+ useEffect(function highlightCode() {
+ if (log.type === 'tool' && log.name === 'RunJavaScriptCode') {
+ hljs.highlightAll()
+ }
+ }, [log])
return (
<div className="
rounded-lg
p-3
border
- border-slate
">
{log.type === 'thought' &&
<div className="
diff --git a/components/Editor/RightSidebar/Logs/index.tsx b/components/Editor/RightSidebar/Logs/index.tsx
index 7920dc68c..c5f7713a0 100644
--- a/components/Editor/RightSidebar/Logs/index.tsx
+++ b/components/Editor/RightSidebar/Logs/index.tsx
@@ -90,10 +90,10 @@ function Logs({
p-4
">
{selectedTab === 0 && logs?.map((l, i, a) =>
- <Fragment key={i}>
+ <Fragment key={l.id}>
<LogEntry
log={l}
- key={i}
+ key={l.id}
/>
{i < a.length - 1 &&
<div className="flex items-center flex-col">