Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
prebuild API ref routes and adapt component for nested ul elements
0div08daef2d4993
diff --git a/apps/web/package.json b/apps/web/package.jsonindex 446beead2..216079310 100644--- a/apps/web/package.json+++ b/apps/web/package.json@@ -4,6 +4,7 @@"private": true,"scripts": {"dev": "next dev",+ "prebuild": "node prebuild.js","build": "next build","start": "next start","lint": "next lint",diff --git a/apps/web/prebuild.js b/apps/web/prebuild.jsnew file mode 100644index 000000000..18dc759cc--- /dev/null+++ b/apps/web/prebuild.js@@ -0,0 +1,42 @@+const fs = require('fs')+const path = require('path')++function walkDir(dir, basePath = '') {+ const entries = fs.readdirSync(dir, { withFileTypes: true })++ return entries+ .map((entry) => {+ const relativePath = path.join(basePath, entry.name)++ if (entry.isDirectory()) {+ let route = { title: entry.name }+ const links = walkDir(path.join(dir, entry.name), relativePath)+ if (links.length > 0) {+ route.links = links+ } else {+ route.href = '/' + relativePath+ }+ return route+ }+ })+ .filter(Boolean)+}++function generateApiRefRoutes() {+ const apiRefPath = path.join(__dirname, './src/app/(docs)/docs/api-reference')++ if (!fs.existsSync(apiRefPath)) {+ return []+ }++ return walkDir(apiRefPath)+}++const apiRefRoutes = generateApiRefRoutes()++fs.writeFileSync(+ path.join(__dirname, './src/components/Navigation/apiRefRoutes.json'),+ JSON.stringify(apiRefRoutes, null, 2)+)++console.log('API reference routes generated successfully.')diff --git a/apps/web/src/components/Navigation/index.tsx b/apps/web/src/components/Navigation/index.tsxindex daab33929..7c202aa0e 100644--- a/apps/web/src/components/Navigation/index.tsx+++ b/apps/web/src/components/Navigation/index.tsx@@ -1,16 +1,16 @@'use client'-import { useRef } from 'react'-import Link from 'next/link'-import { usePathname } from 'next/navigation'import clsx from 'clsx'import { AnimatePresence, motion, useIsPresent } from 'framer-motion'+import Link from 'next/link'+import { usePathname } from 'next/navigation'+import { useRef } from 'react'+import { Auth } from '@/components/Auth'import { useIsInsideMobileNavigation } from '@/components/MobileNavigation'import { useSectionStore } from '@/components/SectionProvider'import { Tag } from '@/components/Tag'import { remToPx } from '@/lib/remToPx'-import { Auth } from '@/components/Auth'import { routes } from './routes'interface NavGroup {@@ -76,17 +76,14 @@ function NavLink({? 'text-zinc-900 dark:text-white': 'text-zinc-600 hover:text-zinc-900 dark:text-zinc-400 dark:hover:text-white',isFontMono ? 'font-mono text-xs' : '',- className,+ className)}><div className="flex items-center justify-start gap-1">{icon}{tag ? (<div className="flex items-center gap-2">- <Tag- variant="small"- color="emerald"- >+ <Tag variant="small" color="emerald">{tag}</Tag><span className={clsx('truncate', active ? 'text-white' : '')}>@@ -94,7 +91,9 @@ function NavLink({</span></div>) : (- <span className={clsx('truncate', active ? 'text-white' : '')}>{children}</span>+ <span className={clsx('truncate', active ? 'text-white' : '')}>+ {children}+ </span>)}</div></Link>@@ -103,19 +102,27 @@ function NavLink({function VisibleSectionHighlight({ group, pathname }) {const [sections, visibleSections] = useInitialValue(- [useSectionStore(s => s.sections), useSectionStore(s => s.visibleSections)],- useIsInsideMobileNavigation(),+ [+ useSectionStore((s) => s.sections),+ useSectionStore((s) => s.visibleSections),+ ],+ useIsInsideMobileNavigation())const isPresent = useIsPresent()const firstVisibleSectionIndex = Math.max(0,- [{ id: '_top' }, ...sections].findIndex(section => section.id === visibleSections[0]),+ [{ id: '_top' }, ...sections].findIndex(+ (section) => section.id === visibleSections[0]+ ))const itemHeight = remToPx(2)- const height = isPresent ? Math.max(1, visibleSections.length) * itemHeight : itemHeight+ const height = isPresent+ ? Math.max(1, visibleSections.length) * itemHeight+ : itemHeightconst activePageIndex = activeGroupIndex(group, pathname)- const top = activePageIndex * itemHeight + firstVisibleSectionIndex * itemHeight+ const top =+ activePageIndex * itemHeight + firstVisibleSectionIndex * itemHeightreturn (<motion.div@@ -129,7 +136,13 @@ function VisibleSectionHighlight({ group, pathname }) {)}-function ActivePageMarker({ group, pathname }: { group: NavGroup; pathname: string }) {+function ActivePageMarker({+ group,+ pathname,+}: {+ group: NavGroup+ pathname: string+}) {const itemHeight = remToPx(2)const offset = remToPx(0.25)const activePageIndex = activeGroupIndex(group, pathname)@@ -155,8 +168,8 @@ function NavigationGroup({ group, className }) {const initialPathname = usePathname()const [pathname, sections] = useInitialValue(- [initialPathname, useSectionStore(s => s.sections)],- isInsideMobileNavigation,+ [initialPathname, useSectionStore((s) => s.sections)],+ isInsideMobileNavigation)if (!pathname) {@@ -176,10 +189,7 @@ function NavigationGroup({ group, className }) {<div className="relative mt-3 pl-2"><AnimatePresence initial={!isInsideMobileNavigation}>{isActiveGroup && (- <VisibleSectionHighlight- group={group}- pathname={pathname}- />+ <VisibleSectionHighlight group={group} pathname={pathname} />)}</AnimatePresence><motion.div@@ -188,69 +198,95 @@ function NavigationGroup({ group, className }) {/><AnimatePresence initial={false}>{isActiveGroup && (- <ActivePageMarker- group={group}- pathname={pathname}- />+ <ActivePageMarker group={group} pathname={pathname} />)}</AnimatePresence>- <ul- role="list"- className="border-l border-transparent"- >- {group.links.map(link => (- <motion.li- key={link.href}- layout="position"- className="relative"- >+ <ul role="list" className="border-l border-transparent">+ {group.links.map((link) => (+ <motion.li key={link.href} layout="position" className="relative">{/* @ts-ignore */}- <NavLink- className="font-medium"- href={link.href}- active={- `/docs${link.href}` === pathname ||- // Special case for index (/)- (link.href == '/' && pathname == '/docs')- }- isFontMono={link.isFontMono}- icon={link.icon}- tag={link.tag}- >- {link.title}- </NavLink>- <AnimatePresence- mode="popLayout"- initial={false}- >- {`/docs${link.href}` === pathname && sections.length > 0 && (- <motion.ul- role="list"- initial={{ opacity: 0 }}- animate={{- opacity: 1,- transition: { delay: 0.1 },- }}- exit={{- opacity: 0,- transition: { duration: 0.15 },- }}- >- {sections.map(section => (- <li key={section.id}>- {/* @ts-ignore */}- <NavLink- href={`${link.href}#${section.id}`}- tag={section.tag}- icon={section.icon}- isAnchorLink- >- {section.title}- </NavLink>- </li>- ))}- </motion.ul>- )}+ {link.href ? (+ <NavLink+ className="font-medium"+ href={link.href}+ active={+ `/docs${link.href}` === pathname ||+ // Special case for index (/)+ (link.href == '/' && pathname == '/docs')+ }+ isFontMono={link.isFontMono}+ icon={link.icon}+ tag={link.tag}+ >+ {link.title}+ </NavLink>+ ) : (+ <span className="font-medium">{link.title}</span>+ )}+ <AnimatePresence mode="popLayout" initial={false}>+ {`/docs${link.href}` === pathname &&+ (sections.length > 0 || link.links) && (+ <motion.ul+ role="list"+ initial={{ opacity: 0 }}+ animate={{+ opacity: 1,+ transition: { delay: 0.1 },+ }}+ exit={{+ opacity: 0,+ transition: { duration: 0.15 },+ }}+ >+ {sections.map((section) => (+ <li key={section.id}>+ {/* @ts-ignore */}+ <NavLink+ href={`${link.href}#${section.id}`}+ tag={section.tag}+ icon={section.icon}+ isAnchorLink+ >+ {section.title}+ </NavLink>+ </li>+ ))}+ {link.links &&+ link.links.map((nestedLink) => (+ <li key={nestedLink.href}>+ <NavLink+ href={nestedLink.href}+ active={`/docs${nestedLink.href}` === pathname}+ isFontMono={nestedLink.isFontMono}+ icon={nestedLink.icon}+ tag={nestedLink.tag}+ >+ {nestedLink.title}+ </NavLink>+ {nestedLink.links && (+ <ul>+ {nestedLink.links.map((deepNestedLink) => (+ <li key={deepNestedLink.href}>+ <NavLink+ href={deepNestedLink.href}+ active={+ `/docs${deepNestedLink.href}` ===+ pathname+ }+ isFontMono={deepNestedLink.isFontMono}+ icon={deepNestedLink.icon}+ tag={deepNestedLink.tag}+ >+ {deepNestedLink.title}+ </NavLink>+ </li>+ ))}+ </ul>+ )}+ </li>+ ))}+ </motion.ul>+ )}</AnimatePresence></motion.li>))}@@ -260,7 +296,6 @@ function NavigationGroup({ group, className }) {)}-export function Navigation(props) {return (<nav {...props}>@@ -291,7 +326,7 @@ export function Navigation(props) {}function activeGroupIndex(group: NavGroup, pathname: string) {- return group.links.findIndex(link => {+ return group.links.findIndex((link) => {return link.href === pathname})}diff --git a/apps/web/src/components/Navigation/routes.tsx b/apps/web/src/components/Navigation/routes.tsxindex 4906b68d5..e540947e9 100644--- a/apps/web/src/components/Navigation/routes.tsx+++ b/apps/web/src/components/Navigation/routes.tsx@@ -1,5 +1,6 @@import {BarChart,+ BookOpen,Braces,ChevronRightSquare,Cog,@@ -24,258 +25,267 @@ import {Timer,Variable,Wrench,- BookOpen,} from 'lucide-react'-import Image from 'next/image'import logoNode from '@/images/logos/node.svg'import logoPython from '@/images/logos/python.svg'+import Image from 'next/image'++// @ts-ignore; generated by prebuild.ts+import apiRefRoutes from './apiRefRoutes.json'export const routes = [- {- title: 'Getting Started',- links: [- {- title: 'Installation',- href: '/docs',- },- {- title: 'helloWorld.[ts|js]',- href: '/docs/hello-world/js',- icon: <Image src={logoNode} width={20} height={20} alt="Python logo" />,- isFontMono: true,- },- {- title: 'hello_world.py',- href: '/docs/hello-world/py',- icon: <Image src={logoPython} width={20} height={20} alt="Python logo" />,- isFontMono: true,- },- {- title: 'Supported LLMs and AI frameworks',- href: '/docs/supported',- },- // {- // title: 'What\'s Code Interpreting?',- // href: '/code-interpreting',- // },- {- icon: <KeyRound strokeWidth={1} size={20} />,- title: 'API Key',- href: '/docs/getting-started/api-key',- },- {- icon: <DollarSign strokeWidth={1} size={20} />,- title: 'Pricing',- href: '/docs/pricing',- },- {- icon: <BarChart strokeWidth={1} size={20} />,- title: 'Track usage',- href: '/dashboard?tab=usage',- },- {- icon: <ShieldQuestion strokeWidth={1} size={20} />,- title: 'Getting help',- href: '/docs/getting-help',- },- ],- },- {- title: 'Guides',- links: [- {- icon: <BookOpen strokeWidth={1} size={20} />,- title: 'Guides and examples in cookbook',- href: 'https://github.com/e2b-dev/e2b-cookbook',- },- {- icon: <BookOpen strokeWidth={1} size={20} />,- title: '[SDK Beta] Migration',- href: '/docs/guide/beta-migration',- },- {- icon: <BookOpen strokeWidth={1} size={20} />,- title: '[SDK Beta] Runtimes in Code Interpreter',- href: '/docs/guide/beta-code-interpreter-language-runtimes',- },- // {- // icon: <Hammer strokeWidth={1} size={20} />,- // title: 'Guide: Code Interpreter with OpenAI models',- // href: '/guide/simple-gpt4-code-interpreter',- // },- // {- // icon: <Hammer strokeWidth={1} size={20} />,- // title: 'Guide: Secure Sandbox for Devin-like agent',- // href: '/guide/simple-gpt4-code-interpreter',- // },- // {- // icon: <Hammer strokeWidth={1} size={20} />,- // title: 'Guide: Generative UI with Next.js',- // href: '/guide/simple-gpt4-code-interpreter',- // },- // {- // icon: <Hammer strokeWidth={1} size={20} />,- // title: 'Guide: Upload and analyze CSV files with AI',- // href: '/guide/simple-gpt4-code-interpreter',- // },- // {- // icon: <Hammer strokeWidth={1} size={20} />,- // title: 'Guide: Customize sandbox compute (TODO: Move this away from guides?)',- // href: '/guide/simple-gpt4-code-interpreter',- // },- ],- },- {- title: 'E2B Code Interpreter',- links: [- {- title: 'Installation',- href: '/docs/code-interpreter/installation',- },- {- icon: <Terminal strokeWidth={1} size={20} />,- title: 'AI Code Execution',- href: '/docs/code-interpreter/execution',- },- // {- // icon: <Book strokeWidth={1} size={20} />,- // title: 'Streaming',- // href: '/code-interpreter/examples',- // },- // {- // icon: <Wrench strokeWidth={1} size={20} />,- // title: 'Supported languages',- // href: '/code-interpreter/template',- // },- // {- // icon: <Wrench strokeWidth={1} size={20} />,- // title: 'Preinstalled packages (customization)',- // href: '/code-interpreter/template',- // },- {- icon: <Wrench strokeWidth={1} size={20} />,- title: 'Customization',- href: '/docs/code-interpreter/template',- },- {- icon: <Cog strokeWidth={1} size={20} />,- title: 'Kernels',- href: '/docs/code-interpreter/kernels',- },- ],- },- {- title: 'E2B Sandbox',- links: [- {- title: 'Overview',- href: '/docs/sandbox/overview',- },- {- icon: <Cpu strokeWidth={1} size={20} />,- title: 'Compute',- href: '/docs/sandbox/compute',- },- {- icon: <PencilRuler strokeWidth={1} size={20} />,- title: 'Customization',- href: '/docs/sandbox/custom',- },- {- icon: <Variable strokeWidth={1} size={20} />,- title: 'Environment Variables',- href: '/docs/sandbox/api/envs',- },- {- icon: <FolderTree strokeWidth={1} size={20} />,- title: 'Filesystem',- href: '/docs/sandbox/api/filesystem',- },- {- icon: <ChevronRightSquare strokeWidth={1} size={20} />,- title: 'Process',- href: '/docs/sandbox/api/process',- },- {- icon: <Folder strokeWidth={1} size={20} />,- title: 'Working Directory',- href: '/docs/sandbox/api/cwd',- },- {- icon: <Link strokeWidth={1} size={20} />,- title: 'Sandbox URL',- href: '/docs/sandbox/api/url',- },- {- icon: <FileUp strokeWidth={1} size={20} />,- title: 'Upload Files',- href: '/docs/sandbox/api/upload',- },- {- icon: <FileDown strokeWidth={1} size={20} />,- title: 'Download Files',- href: '/docs/sandbox/api/download',- },- {- icon: <Timer strokeWidth={1} size={20} />,- title: 'Timeouts',- href: '/docs/sandbox/api/timeouts',- },- {- icon: <RefreshCw strokeWidth={1} size={20} />,- title: 'Connect to running sandbox',- href: '/docs/sandbox/api/reconnect',- },- {- icon: <Braces strokeWidth={1} size={20} />,- title: 'Sandbox metadata',- href: '/docs/sandbox/api/metadata',- },- ],- },- {- title: 'CLI',- links: [- {- icon: <Settings strokeWidth={1} size={20} />,- title: 'Installation',- href: '/docs/cli/installation',- },- {- icon: <TerminalSquare strokeWidth={1} size={20} />,- title: 'Commands',- href: '/docs/cli/commands',- },- ],- },- {- title: 'Custom Sandboxes',- links: [- {- title: 'Overview',- href: '/docs/sandbox/templates/overview',- },- {- icon: <File strokeWidth={1} size={20} />,- title: 'Template File',- href: '/docs/sandbox/templates/template-file',- },- {- icon: <PlaySquare strokeWidth={1} size={20} />,- title: 'Start Command',- href: '/docs/sandbox/templates/start-cmd',- },- {- icon: <Hammer strokeWidth={1} size={20} />,- title: 'Guide: Creating Custom Sandbox',- href: '/docs/guide/custom-sandbox',- },- {- icon: <HardDrive strokeWidth={1} size={20} />,- title: 'Connecting buckets to persist data',- href: '/docs/guide/connect-bucket',- },- ],- },+ ...[+ {+ title: 'Getting Started',+ links: [+ {+ title: 'Installation',+ href: '/docs',+ },+ {+ title: 'helloWorld.[ts|js]',+ href: '/docs/hello-world/js',+ icon: (+ <Image src={logoNode} width={20} height={20} alt="Python logo" />+ ),+ isFontMono: true,+ },+ {+ title: 'hello_world.py',+ href: '/docs/hello-world/py',+ icon: (+ <Image src={logoPython} width={20} height={20} alt="Python logo" />+ ),+ isFontMono: true,+ },+ {+ title: 'Supported LLMs and AI frameworks',+ href: '/docs/supported',+ },+ // {+ // title: 'What\'s Code Interpreting?',+ // href: '/code-interpreting',+ // },+ {+ icon: <KeyRound strokeWidth={1} size={20} />,+ title: 'API Key',+ href: '/docs/getting-started/api-key',+ },+ {+ icon: <DollarSign strokeWidth={1} size={20} />,+ title: 'Pricing',+ href: '/docs/pricing',+ },+ {+ icon: <BarChart strokeWidth={1} size={20} />,+ title: 'Track usage',+ href: '/dashboard?tab=usage',+ },+ {+ icon: <ShieldQuestion strokeWidth={1} size={20} />,+ title: 'Getting help',+ href: '/docs/getting-help',+ },+ ],+ },+ {+ title: 'Guides',+ links: [+ {+ icon: <BookOpen strokeWidth={1} size={20} />,+ title: 'Guides and examples in cookbook',+ href: 'https://github.com/e2b-dev/e2b-cookbook',+ },+ {+ icon: <BookOpen strokeWidth={1} size={20} />,+ title: '[SDK Beta] Migration',+ href: '/docs/guide/beta-migration',+ },+ {+ icon: <BookOpen strokeWidth={1} size={20} />,+ title: '[SDK Beta] Runtimes in Code Interpreter',+ href: '/docs/guide/beta-code-interpreter-language-runtimes',+ },+ // {+ // icon: <Hammer strokeWidth={1} size={20} />,+ // title: 'Guide: Code Interpreter with OpenAI models',+ // href: '/guide/simple-gpt4-code-interpreter',+ // },+ // {+ // icon: <Hammer strokeWidth={1} size={20} />,+ // title: 'Guide: Secure Sandbox for Devin-like agent',+ // href: '/guide/simple-gpt4-code-interpreter',+ // },+ // {+ // icon: <Hammer strokeWidth={1} size={20} />,+ // title: 'Guide: Generative UI with Next.js',+ // href: '/guide/simple-gpt4-code-interpreter',+ // },+ // {+ // icon: <Hammer strokeWidth={1} size={20} />,+ // title: 'Guide: Upload and analyze CSV files with AI',+ // href: '/guide/simple-gpt4-code-interpreter',+ // },+ // {+ // icon: <Hammer strokeWidth={1} size={20} />,+ // title: 'Guide: Customize sandbox compute (TODO: Move this away from guides?)',+ // href: '/guide/simple-gpt4-code-interpreter',+ // },+ ],+ },+ {+ title: 'E2B Code Interpreter',+ links: [+ {+ title: 'Installation',+ href: '/docs/code-interpreter/installation',+ },+ {+ icon: <Terminal strokeWidth={1} size={20} />,+ title: 'AI Code Execution',+ href: '/docs/code-interpreter/execution',+ },+ // {+ // icon: <Book strokeWidth={1} size={20} />,+ // title: 'Streaming',+ // href: '/code-interpreter/examples',+ // },+ // {+ // icon: <Wrench strokeWidth={1} size={20} />,+ // title: 'Supported languages',+ // href: '/code-interpreter/template',+ // },+ // {+ // icon: <Wrench strokeWidth={1} size={20} />,+ // title: 'Preinstalled packages (customization)',+ // href: '/code-interpreter/template',+ // },+ {+ icon: <Wrench strokeWidth={1} size={20} />,+ title: 'Customization',+ href: '/docs/code-interpreter/template',+ },+ {+ icon: <Cog strokeWidth={1} size={20} />,+ title: 'Kernels',+ href: '/docs/code-interpreter/kernels',+ },+ ],+ },+ {+ title: 'E2B Sandbox',+ links: [+ {+ title: 'Overview',+ href: '/docs/sandbox/overview',+ },+ {+ icon: <Cpu strokeWidth={1} size={20} />,+ title: 'Compute',+ href: '/docs/sandbox/compute',+ },+ {+ icon: <PencilRuler strokeWidth={1} size={20} />,+ title: 'Customization',+ href: '/docs/sandbox/custom',+ },+ {+ icon: <Variable strokeWidth={1} size={20} />,+ title: 'Environment Variables',+ href: '/docs/sandbox/api/envs',+ },+ {+ icon: <FolderTree strokeWidth={1} size={20} />,+ title: 'Filesystem',+ href: '/docs/sandbox/api/filesystem',+ },+ {+ icon: <ChevronRightSquare strokeWidth={1} size={20} />,+ title: 'Process',+ href: '/docs/sandbox/api/process',+ },+ {+ icon: <Folder strokeWidth={1} size={20} />,+ title: 'Working Directory',+ href: '/docs/sandbox/api/cwd',+ },+ {+ icon: <Link strokeWidth={1} size={20} />,+ title: 'Sandbox URL',+ href: '/docs/sandbox/api/url',+ },+ {+ icon: <FileUp strokeWidth={1} size={20} />,+ title: 'Upload Files',+ href: '/docs/sandbox/api/upload',+ },+ {+ icon: <FileDown strokeWidth={1} size={20} />,+ title: 'Download Files',+ href: '/docs/sandbox/api/download',+ },+ {+ icon: <Timer strokeWidth={1} size={20} />,+ title: 'Timeouts',+ href: '/docs/sandbox/api/timeouts',+ },+ {+ icon: <RefreshCw strokeWidth={1} size={20} />,+ title: 'Connect to running sandbox',+ href: '/docs/sandbox/api/reconnect',+ },+ {+ icon: <Braces strokeWidth={1} size={20} />,+ title: 'Sandbox metadata',+ href: '/docs/sandbox/api/metadata',+ },+ ],+ },+ {+ title: 'CLI',+ links: [+ {+ icon: <Settings strokeWidth={1} size={20} />,+ title: 'Installation',+ href: '/docs/cli/installation',+ },+ {+ icon: <TerminalSquare strokeWidth={1} size={20} />,+ title: 'Commands',+ href: '/docs/cli/commands',+ },+ ],+ },+ {+ title: 'Custom Sandboxes',+ links: [+ {+ title: 'Overview',+ href: '/docs/sandbox/templates/overview',+ },+ {+ icon: <File strokeWidth={1} size={20} />,+ title: 'Template File',+ href: '/docs/sandbox/templates/template-file',+ },+ {+ icon: <PlaySquare strokeWidth={1} size={20} />,+ title: 'Start Command',+ href: '/docs/sandbox/templates/start-cmd',+ },+ {+ icon: <Hammer strokeWidth={1} size={20} />,+ title: 'Guide: Creating Custom Sandbox',+ href: '/docs/guide/custom-sandbox',+ },+ {+ icon: <HardDrive strokeWidth={1} size={20} />,+ title: 'Connecting buckets to persist data',+ href: '/docs/guide/connect-bucket',+ },+ ],+ },+ ],+ ...apiRefRoutes,]