Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Handle logs in wrong format
Tomas Valenta5f4b09645d67
diff --git a/components/AgentPromptLogDetail.tsx b/components/AgentPromptLogDetail.tsxindex a465fe187..9c5706f49 100644--- a/components/AgentPromptLogDetail.tsx+++ b/components/AgentPromptLogDetail.tsx@@ -4,8 +4,23 @@ import {AssistantPromptLog,} from 'utils/agentLogs'import dynamic from 'next/dynamic'+import { useMemo } from 'react'const ReactJson = dynamic(import('react-json-view'), { ssr: false })+function handleJSONQuotes(content: string) {+ try {+ return JSON.parse(content)+ } catch (err) {+ console.log('JSON parse error', err, content)+ }++ try {+ return JSON.parse(content.replace(/"/g, '\\"').replace(/'/g, '"'))+ } catch (err) {+ console.log('JSON parse error', err, content)+ }+}+export interface Props {log?: SystemPromptLog | UserPromptLog | AssistantPromptLog}@@ -13,6 +28,10 @@ export interface Props {function AgentPrompLogDetail({log,}: Props) {+ const parsedLog = useMemo(() => {+ return log ? handleJSONQuotes(log.content) : undefined+ }, [log])+return (<div className="overflow-auto p-2 h-full bg-[#1F2437] rounded-md flex flex-col space-y-4 border border-gray-800 min-w-[550px]">{log && (@@ -27,19 +46,28 @@ function AgentPrompLogDetail({{log.role !== 'assistant' ? (<p className="text-sm text-gray-200 w-full prose whitespace-pre-wrap max-w-full">{log.content}</p>) : (- <ReactJson- src={JSON.parse(log.content)}- name={null}- style={{- background: 'transparent'- }}- displayObjectSize={false}- quotesOnKeys={false}- sortKeys={true}- displayDataTypes={false}- theme="ocean"- enableClipboard={false}- />+ <>+ {!parsedLog &&+ <div>+ Unexpected JSON format. Please reach out to the e2b team.+ </div>+ }+ {parsedLog &&+ <ReactJson+ src={parsedLog}+ name={null}+ style={{+ background: 'transparent'+ }}+ displayObjectSize={false}+ quotesOnKeys={false}+ sortKeys={true}+ displayDataTypes={false}+ theme="ocean"+ enableClipboard={false}+ />+ }+ </>)}</div>