Skip to content

armgit / E2B

Public Imported from GitHub
0

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

(Docs) Don't show playgrounds logs in browser console in prod

Vasek Mlejnsky6cc46a525d6e
diff --git a/apps/docs/src/components/Navigation.tsx b/apps/docs/src/components/Navigation.tsx
index e69c1be0a..7116704d9 100644
--- a/apps/docs/src/components/Navigation.tsx
+++ b/apps/docs/src/components/Navigation.tsx
@@ -150,6 +150,8 @@ function NavigationGroup({ group, className }) {
const isActiveGroup = activeGroupIndex(group, pathname) !== -1
+ console.log({ pathname, group, sections })
+
return (
<li className={clsx('relative mt-6', className)}>
<motion.h2
@@ -201,8 +203,22 @@ function NavigationGroup({ group, className }) {
mode="popLayout"
initial={false}
>
- {`/docs${link.href}` === pathname && sections.length > 0 && (
- <motion.ul
+ <ul>
+ {sections.map(section => (
+ <li key={section.id}>
+ {/* @ts-ignore */}
+ <NavLink
+ href={`${link.href}#${section.id}`}
+ tag={section.tag}
+ isAnchorLink
+ >
+ {section.title}
+ </NavLink>
+ </li>
+ ))}
+ </ul>
+ {/* {`/docs${link.href}` === pathname && sections.length > 0 && ( */}
+ {/* <motion.ul
role="list"
initial={{ opacity: 0 }}
animate={{
@@ -213,21 +229,8 @@ function NavigationGroup({ group, className }) {
opacity: 0,
transition: { duration: 0.15 },
}}
- >
- {sections.map(section => (
- <li key={section.id}>
- {/* @ts-ignore */}
- <NavLink
- href={`${link.href}#${section.id}`}
- tag={section.tag}
- isAnchorLink
- >
- {section.title}
- </NavLink>
- </li>
- ))}
- </motion.ul>
- )}
+ > */}
+ {/* </motion.ul> */}
</AnimatePresence>
</motion.li>
))}
diff --git a/apps/docs/src/utils/useSessions.tsx b/apps/docs/src/utils/useSessions.tsx
index 3463e9ed1..9d13bb191 100644
--- a/apps/docs/src/utils/useSessions.tsx
+++ b/apps/docs/src/utils/useSessions.tsx
@@ -3,14 +3,21 @@ import { create } from 'zustand'
import { LangShort } from '@/utils/consts'
function stdHandler({ line, timestamp, error }) {
+ if (process.env.NODE_ENV === 'production') return
+
const timestampHumanFriendly = new Date(timestamp / 1000000) // timestamp is in nanoseconds
.toISOString()
.split('T')[1] // only time, date is not relevant for debugging
.split('.')[0] // remove ms
- const emoji = error ? 'ERROR' : 'INFO'
+ const emoji = error ? '\x1B[31mERROR' : '\x1B[34mINFO'
console.log(`☁️ ${timestampHumanFriendly} ${emoji} ${line}`)
}
+function log(message?: any, ...optionalParams: any[]) {
+ if (process.env.NODE_ENV === 'production') return
+ else console.log(message, optionalParams)
+}
+
const envIds = {
js: 'Nodejs',
py: 'Python3',
@@ -32,15 +39,15 @@ export const useSessionsStore = create<SessionsStore>((set, get) => ({
return new Promise(async (resolve, reject) => {
const maybeExistingSession = get().sessions[lang]
if (maybeExistingSession?.session) {
- console.log(`${lang} session already ready`)
+ log(`${lang} session already ready`)
resolve(maybeExistingSession.session)
return
} else if (maybeExistingSession?.promise) {
- console.log(`${lang} session in progress, waiting...`)
+ log(`${lang} session in progress, waiting...`)
await maybeExistingSession.promise
resolve(maybeExistingSession.session)
} else {
- console.log(`${lang} session creating...`)
+ log(`${lang} session creating...`)
try {
const sessionP = Session.create({ id: envIds[lang], apiKey })
// set promise to store so that other calls to initSession will wait for this one to finish
@@ -54,7 +61,7 @@ export const useSessionsStore = create<SessionsStore>((set, get) => ({
},
}))
const newSession = await sessionP // await creation
- console.log(`${lang} session created, starting prep process...`)
+ log(`${lang} session created, starting prep process...`)
const proc = await newSession.process.start({
cmd: preps[lang],
onStdout: stdHandler,
@@ -62,7 +69,7 @@ export const useSessionsStore = create<SessionsStore>((set, get) => ({
rootdir: '/code',
})
await proc.finished // await prep process to finish
- console.log(`${lang} session created and started`)
+ log(`${lang} session created and started`)
// set session to store so it can be used instead of creating a new one
set(state => ({
sessions: {