Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Create separate components from different types of logs
Vasek Mlejnsky17429b2418ed
diff --git a/components/Editor/RightSidebar/Logs/LogEntry.tsx b/components/Editor/RightSidebar/Logs/LogEntry.tsxindex 03d352a46..ae56a02ca 100644--- a/components/Editor/RightSidebar/Logs/LogEntry.tsx+++ b/components/Editor/RightSidebar/Logs/LogEntry.tsx@@ -1,27 +1,7 @@-import {- Code2,- Package,- TerminalSquare,- Wrench,- Loader,-} from 'lucide-react'-import ReactMarkdown from 'react-markdown'+import { Log, LogType } from 'db/types'-import { Log } from 'db/types'---function getToolIcon(toolName: string) {- switch (toolName) {- case 'InstallNPMDependencies':- return <Package size="16px" />- case 'RunJavaScriptCode':- return <Code2 size="16px" />- case 'CurlJavaScriptServer':- return <TerminalSquare size="16px" />- default:- return <Wrench size="16px" />- }-}+import Thought from './Thought'+import Tool from './Tool'export interface Props {log: Log@@ -35,66 +15,14 @@ function LogEntry({ log }: Props) {border">{log.type === 'thought' &&- <div className="- italic- text-slate-400- ">- <ReactMarkdown>- {log.content}- </ReactMarkdown>- </div>+ <Thought+ log={log}+ />}- {log.type === 'tool' &&- <>- <div className="- flex- justify-between- items-center- ">- <div className="- flex- items-center- space-x-2- ">- {getToolIcon(log.tool_name)}- <div className="font-medium">- {log.tool_name}- </div>- </div>- {log.tool_output === undefined &&- <Loader size="16px" className="text-slate-400 animate-spin" />- }- </div>- {log.tool_input.trim() &&- <div className="- pt-2- "- >- {(log.tool_name === 'RunJavaScriptCode' || log.tool_name === 'InstallNPMDependencies') &&- <pre>- {log.tool_input.trim()}- </pre>- }- {log.tool_name !== 'RunJavaScriptCode' && log.tool_name !== 'InstallNPMDependencies' &&- <ReactMarkdown>- {log.tool_input}- </ReactMarkdown>- }- </div>- }- {log.tool_output?.trim() &&- <div className="- border-t- mt-2- pt-2- "- >- <ReactMarkdown>- {log.tool_output}- </ReactMarkdown>- </div>- }- </>+ {log.type === LogType.Tool &&+ <Tool+ log={log}+ />}</div>)diff --git a/components/Editor/RightSidebar/Logs/Thought.tsx b/components/Editor/RightSidebar/Logs/Thought.tsxnew file mode 100644index 000000000..f9b0e6e9e--- /dev/null+++ b/components/Editor/RightSidebar/Logs/Thought.tsx@@ -0,0 +1,24 @@+import { ThoughtLog } from 'db/types'++import ReactMarkdown from 'react-markdown'++export interface Props {+ log: ThoughtLog+}++function Thought({+ log,+}: Props) {+ return (+ <div className="+ italic+ text-slate-400+ ">+ <ReactMarkdown>+ {log.content}+ </ReactMarkdown>+ </div>+ )+}++export default Thought\ No newline at end of filediff --git a/components/Editor/RightSidebar/Logs/Tool/Base.tsx b/components/Editor/RightSidebar/Logs/Tool/Base.tsxnew file mode 100644index 000000000..6be6ad6fe--- /dev/null+++ b/components/Editor/RightSidebar/Logs/Tool/Base.tsx@@ -0,0 +1,64 @@+import { ReactNode } from 'react'+import {+ Loader,+} from 'lucide-react'+import ReactMarkdown from 'react-markdown'++import { ToolLog, LogType } from 'db/types'++export interface Props {+ log: ToolLog+ icon: ReactNode+ body: ReactNode+}++function BaseTool({+ icon,+ log,+ body,+}: Props) {+ if (log.type !== LogType.Tool) throw new Error(`'${log.type}': This component supports only logs of type '${log.type}'`)++ return (+ <div>+ <div className="+ flex+ justify-between+ items-center+ ">+ <div className="+ flex+ items-center+ space-x-2+ ">+ {icon}+ <div className="font-medium">+ {log.tool_name}+ </div>+ </div>+ {log.tool_output === undefined &&+ <Loader+ className="text-slate-400 animate-spin"+ size="16px"+ />+ }+ </div>++ {body}++ {log.tool_output?.trim() &&+ <div className="+ border-t+ mt-2+ pt-2+ ">+ <ReactMarkdown>+ {log.tool_output}+ </ReactMarkdown>+ </div>+ }+ </div>+ )+}++export default BaseTool\ No newline at end of filediff --git a/components/Editor/RightSidebar/Logs/Tool/CurlServer.tsx b/components/Editor/RightSidebar/Logs/Tool/CurlServer.tsxnew file mode 100644index 000000000..4b7ceaa55--- /dev/null+++ b/components/Editor/RightSidebar/Logs/Tool/CurlServer.tsx@@ -0,0 +1,44 @@+import {+ ReactNode+} from 'react'+import {+ TerminalSquare,+} from 'lucide-react'++import { ToolName, ToolLog } from 'db/types'++import Base from './Base'+++export interface Props {+ log: ToolLog+}++function CurlServer({+ log,+}: Props) {+ if (log.tool_name !== ToolName.CurlJavaScriptServer) throw new Error(`'${log.tool_name}': This component supports only logs for '${ToolName.CurlJavaScriptServer}' tool`)++ let body: ReactNode = null+ if (log.tool_input.trim()) {+ body = (+ <div className="+ pt-2+ ">+ <pre>+ {log.tool_input.trim()}+ </pre>+ </div>+ )+ }++ return (+ <Base+ log={log}+ icon={<TerminalSquare size="16px" />}+ body={body}+ />+ )+}++export default CurlServer\ No newline at end of filediff --git a/components/Editor/RightSidebar/Logs/Tool/InstallNPMDeps.tsx b/components/Editor/RightSidebar/Logs/Tool/InstallNPMDeps.tsxnew file mode 100644index 000000000..bfe671b0a--- /dev/null+++ b/components/Editor/RightSidebar/Logs/Tool/InstallNPMDeps.tsx@@ -0,0 +1,44 @@+import {+ ReactNode+} from 'react'+import {+ Package,+} from 'lucide-react'++import { ToolName, ToolLog } from 'db/types'++import Base from './Base'+++export interface Props {+ log: ToolLog+}++function InstallNPMDeps({+ log,+}: Props) {+ if (log.tool_name !== ToolName.InstallNPMDependencies) throw new Error(`'${log.tool_name}': This component supports only logs for '${ToolName.InstallNPMDependencies}' tool`)++ let body: ReactNode = null+ if (log.tool_input.trim()) {+ body = (+ <div className="+ pt-2+ ">+ <pre>+ {log.tool_input.trim()}+ </pre>+ </div>+ )+ }++ return (+ <Base+ log={log}+ icon={<Package size="16px" />}+ body={body}+ />+ )+}++export default InstallNPMDeps\ No newline at end of filediff --git a/components/Editor/RightSidebar/Logs/Tool/RunCode.tsx b/components/Editor/RightSidebar/Logs/Tool/RunCode.tsxnew file mode 100644index 000000000..acda4eea6--- /dev/null+++ b/components/Editor/RightSidebar/Logs/Tool/RunCode.tsx@@ -0,0 +1,44 @@+import {+ ReactNode+} from 'react'+import {+ Code2,+} from 'lucide-react'++import { ToolName, ToolLog } from 'db/types'++import Base from './Base'+++export interface Props {+ log: ToolLog+}++function RunCode({+ log,+}: Props) {+ if (log.tool_name !== ToolName.RunJavaScriptCode) throw new Error(`'${log.tool_name}': This component supports only logs for '${ToolName.RunJavaScriptCode}' tool`)++ let body: ReactNode = null+ if (log.tool_input.trim()) {+ body = (+ <div className="+ pt-2+ ">+ <pre>+ {log.tool_input.trim()}+ </pre>+ </div>+ )+ }++ return (+ <Base+ log={log}+ icon={<Code2 size="16px" />}+ body={body}+ />+ )+}++export default RunCode\ No newline at end of filediff --git a/components/Editor/RightSidebar/Logs/Tool/index.tsx b/components/Editor/RightSidebar/Logs/Tool/index.tsxnew file mode 100644index 000000000..955f981d5--- /dev/null+++ b/components/Editor/RightSidebar/Logs/Tool/index.tsx@@ -0,0 +1,26 @@+import { ToolLog, ToolName } from 'db/types'++import CurlServer from './CurlServer'+import InstallNPMDeps from './InstallNPMDeps'+import RunCode from './RunCode'++export interface Props {+ log: ToolLog+}++function Tool({+ log+}: Props) {+ switch (log.tool_name) {+ case ToolName.CurlJavaScriptServer:+ return <CurlServer log={log} />+ case ToolName.InstallNPMDependencies:+ return <InstallNPMDeps log={log} />+ case ToolName.RunJavaScriptCode:+ return <RunCode log={log} />+ default:+ throw new Error(`'${log.tool_name}': Unknown tool log`)+ }+}++export default Tool\ No newline at end of filediff --git a/components/Editor/RightSidebar/Logs/Tools/RunCode/index.tsx b/components/Editor/RightSidebar/Logs/Tools/RunCode/index.tsxdeleted file mode 100644index 349185888..000000000--- a/components/Editor/RightSidebar/Logs/Tools/RunCode/index.tsx+++ /dev/null@@ -1,17 +0,0 @@-import { ToolName, ToolLog } from 'db/types'--export interface Props {- log: ToolLog-}--function RunCode({- log,-}: Props) {- if (log.tool_name !== ToolName.RunJavaScriptCode) throw new Error(`'${log.tool_name}': This component supports only logs for 'RunJavaScriptCode' tool`)-- return (-- )-}--export default RunCode\ No newline at end of filediff --git a/components/Editor/RightSidebar/Logs/index.tsx b/components/Editor/RightSidebar/Logs/index.tsxindex caf9a2d02..831cf253f 100644--- a/components/Editor/RightSidebar/Logs/index.tsx+++ b/components/Editor/RightSidebar/Logs/index.tsx@@ -51,8 +51,6 @@ function Logs({ref.current.scrollIntoView({ behavior: 'smooth' })}, [logs])- console.log(logs)-return (<div className="max-w-full