Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Fix logs disappearance [WIP]
Tomas Valenta6341ff9788ea
diff --git a/components/Editor/RightSidebar/Logs/LogStream.tsx b/components/Editor/RightSidebar/Logs/LogStream.tsxnew file mode 100644index 000000000..9563f2f38--- /dev/null+++ b/components/Editor/RightSidebar/Logs/LogStream.tsx@@ -0,0 +1,59 @@+import { Fragment, useEffect, useRef } from 'react'+import ReactMarkdown from 'react-markdown'++import ConnectionLine from 'components/Editor/ConnectionLine'+import { Log } from 'db/types'++import LogEntry from './LogEntry'++export interface Props {+ logs?: Log[]+ rawLogs?: string | null+}++function LogStream({ logs, rawLogs }: Props) {+ const ref = useRef<HTMLDivElement>(null)++ useEffect(function scrollLogs() {+ if (!ref.current) return+ ref.current.scrollIntoView({ behavior: 'smooth' })+ }, [logs])++ return (+ <div+ className="+ flex-1+ overflow-auto+ text-xs+ tracking-wide+ font-sans+ scroller+ whitespace-pre-wrap+ py-4+ flex+ flex-col+ px-2+ ">+ {rawLogs &&+ <ReactMarkdown>+ {rawLogs}+ </ReactMarkdown>+ }+ {logs && logs.map((l, i, a) =>+ <Fragment key={i}>+ <LogEntry+ log={l}+ />+ {i < a.length - 1 &&+ <div className="flex items-center flex-col">+ <ConnectionLine className="h-4" />+ </div>+ }+ </Fragment>+ )}+ <div ref={ref} />+ </div>+ )+}++export default LogStreamdiff --git a/components/Editor/RightSidebar/Logs/index.tsx b/components/Editor/RightSidebar/Logs/index.tsxindex caf9a2d02..ae0322a96 100644--- a/components/Editor/RightSidebar/Logs/index.tsx+++ b/components/Editor/RightSidebar/Logs/index.tsx@@ -1,28 +1,20 @@-import {- Fragment,- useEffect,- useRef,- useState,-} from 'react'+import { useState } from 'react'// import hljs from 'highlight.js'-import ReactMarkdown from 'react-markdown'+import { deployments } from '@prisma/client'import Text from 'components/Text'import { useTabs } from 'components/Tabs/useTabs'import Tabs from 'components/Tabs'import { Log } from 'db/types'-import ConnectionLine from 'components/Editor/ConnectionLine'-import LogEntry from './LogEntry'+import LogStream from './LogStream'export interface Props {- logs?: Log[]- logsRaw?: string+ deployment?: deployments}function Logs({- logs,- logsRaw,+ deployment,}: Props) {const [selectedTab, setSelectedTab] = useState(0)const [tabsProps] = useState({@@ -37,7 +29,7 @@ function Logs({},]})- const ref = useRef<HTMLDivElement>(null)+const tabsCss = useTabs(tabsProps)// useEffect(function highlightCode() {@@ -46,12 +38,6 @@ function Logs({// }// }, [logs, selectedTab])- useEffect(function scrollLogs() {- if (!ref.current) return- ref.current.scrollIntoView({ behavior: 'smooth' })- }, [logs])-- console.log(logs)return (<div className="@@ -87,44 +73,16 @@ function Logs({/>)}</div>-- <div- className="- flex-1- overflow-auto- text-xs- tracking-wide- font-sans- scroller- whitespace-pre-wrap- py-4- flex- flex-col- px-2- ">- {selectedTab === 0 && logs?.map((l, i, a) =>- <Fragment key={i}>- <LogEntry- log={l}- />- {i < a.length - 1 &&- <div className="flex items-center flex-col">- <ConnectionLine className="h-4" />- </div>- }- </Fragment>- )}- {selectedTab === 1 && (- <>- {logsRaw &&- <ReactMarkdown>- {logsRaw}- </ReactMarkdown>- }- </>- )}- <div ref={ref} />- </div>+ {selectedTab === 0 &&+ <LogStream+ logs={deployment?.logs as Log[] | undefined}+ />+ }+ {selectedTab === 1 &&+ <LogStream+ rawLogs={deployment?.logs_raw}+ />+ }</div>)}diff --git a/components/Editor/RightSidebar/index.tsx b/components/Editor/RightSidebar/index.tsxindex c294c108b..a4abb1107 100644--- a/components/Editor/RightSidebar/index.tsx+++ b/components/Editor/RightSidebar/index.tsx@@ -29,8 +29,6 @@ function RightSidebar({setDeployURL,}: Props) {const deployment = useLatestDeployment(project, route)- const logs = deployment?.logs as Log[] | undefined- const logsRaw = deployment?.logs_raw as string | undefineduseEffect(function updateURL() {setDeployURL(deployment?.url ? deployment.url : undefined)@@ -114,8 +112,7 @@ function RightSidebar({</div><Envs /><Logs- logs={logs}- logsRaw={logsRaw}+ deployment={deployment}/></Sidebar>)diff --git a/components/ItemList/Item.tsx b/components/ItemList/Item.tsxindex ab6b3e186..ce0f57223 100644--- a/components/ItemList/Item.tsx+++ b/components/ItemList/Item.tsx@@ -107,6 +107,7 @@ function Item({ item, deleteItem }: Props) {className="text-slate-300 transition-all group-hover:text-slate-400"size={Text.size.S3}text={item.created_at.toLocaleString()}+ suppressHydrationWarning/></div></div>diff --git a/components/Tabs/useTabs.ts b/components/Tabs/useTabs.tsindex c8b4697c1..c6e6907f2 100644--- a/components/Tabs/useTabs.ts+++ b/components/Tabs/useTabs.ts@@ -1,24 +1,17 @@-import {useState } from 'react'+import { useMemo, useState } from 'react'-// type Tab = { label: string; id: string; children: ReactNode }type Tab = { label: string; id: string; }export function useTabs({tabs,- // initialTabId,onChange,}: {tabs: Tab[];- // initialTabId: string;onChange?: (id: string) => void}) {const [selectedTabIndex, setSelectedTab] = useState(-1)- // const [selectedTabIndex, setSelectedTab] = useState(() => {- // const indexOfInitialTab = tabs.findIndex((tab) => tab.id === initialTabId)- // return indexOfInitialTab === -1 ? 0 : indexOfInitialTab- // })- return {+ return useMemo(() => ({tabProps: {tabs,selectedTabIndex,@@ -26,5 +19,5 @@ export function useTabs({setSelectedTab,},selectedTab: tabs[selectedTabIndex],- }+ }), [selectedTabIndex])}