Skip to content

armgit / E2B

Public Imported from GitHub
0

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

uploadtree

Vasek Mlejnskyf7e099be4976
diff --git a/components/AgentLogFilesList.tsx b/components/AgentLogFilesList.tsx
index 8acb04951..754f00461 100644
--- a/components/AgentLogFilesList.tsx
+++ b/components/AgentLogFilesList.tsx
@@ -21,6 +21,7 @@ import {
import Spinner from 'components/Spinner'
import AgentLogFileContent from 'components/AgentLogFileContent'
import { useGetLogFile } from 'hooks/useGetLogFile'
+import Uploadtree from 'components/Uploadtree'
export interface Props {
logUploads: LiteLogUpload[]
@@ -191,6 +192,7 @@ function AgentLogFilesList({
classes={['flex pr-2 overflow-auto', 'bg-gray-900 flex pl-2']}
>
<div className="flex flex-col space-y-4 p-4 sm:p-6 lg:px-8 overflow-auto min-w-[320px]">
+ <Uploadtree logUploads={logUploads} />
{sortedLogUploads.map((logUpload, i) => (
<div
key={logUpload.id}
@@ -224,7 +226,7 @@ function AgentLogFilesList({
// This prevents hydration warning for timestamps rendered via SSR
suppressHydrationWarning
>
- Uploaded {logUpload.created_at.toLocaleString()}
+ Upload from {logUpload.created_at.toLocaleString()}
</span>
</div>
diff --git a/components/Uploadtree/NodeComponent.tsx b/components/Uploadtree/NodeComponent.tsx
new file mode 100644
index 000000000..2ed84a636
--- /dev/null
+++ b/components/Uploadtree/NodeComponent.tsx
@@ -0,0 +1,37 @@
+// Node is either a log upload or a dir.
+
+export interface Node {
+ id: string
+ name: string
+ children: Node[]
+}
+
+export interface Props {
+ node: Node
+}
+
+function NodeComponent({
+ node,
+}: Props) {
+
+ if (node.children.length === 0) {
+ // Leaft node
+ return (
+ <div>leaf</div>
+ )
+ }
+
+ return (
+ <div className="flex flex-col">
+ {node.name}
+
+ <div className="pl-2 flex flex-col">
+ {node.children.map(nodeChild => (
+ <NodeComponent key={nodeChild.id} node={nodeChild} />
+ ))}
+ </div>
+ </div>
+ )
+}
+
+export default NodeComponent
\ No newline at end of file
diff --git a/components/Uploadtree/index.tsx b/components/Uploadtree/index.tsx
new file mode 100644
index 000000000..fb864cd04
--- /dev/null
+++ b/components/Uploadtree/index.tsx
@@ -0,0 +1,84 @@
+import {
+ useEffect,
+ useMemo,
+ useState,
+} from 'react'
+import { LiteLogUpload } from 'utils/agentLogs'
+
+
+export interface Props {
+ logUploads: LiteLogUpload[]
+}
+
+function Uploadtree({
+ logUploads,
+}: Props) {
+ const [openNodes, setOpenNodes] = useState<string[]>([])
+
+ const sortedLogUploads = useMemo(() => {
+ return logUploads
+ // logUploads sorted by created_at - the newest first
+ .sort((a, b) => {
+ if (a.created_at > b.created_at) return -1
+ if (a.created_at < b.created_at) return 1
+ return 0
+ })
+ // Sort the log_files inside logUploads alphabtetical by relativePath
+ .map(logUpload => {
+ const sortedLogFiles = logUpload.log_files.sort((a, b) => {
+ if (a.relativePath > b.relativePath) return 1
+ if (a.relativePath < b.relativePath) return -1
+ return 0
+ })
+
+ return {
+ ...logUpload,
+ log_files: sortedLogFiles,
+ }
+ })
+ }, [logUploads])
+
+ useEffect(function uploadsToTree() {
+ const tree = sortedLogUploads.map(logUpload => {
+ const relativePaths = logUpload.log_files.map(logFile => logFile.relativePath)
+ const relativePathsSplit = relativePaths.map(relativePath => relativePath.split('/'))
+
+ const tree = relativePathsSplit.reduce((acc, relativePathSplit) => {
+ let currentAcc = acc
+
+ relativePathSplit.forEach((relativePathSplitPart, index) => {
+ if (currentAcc[relativePathSplitPart]) {
+ currentAcc = currentAcc[relativePathSplitPart]
+ } else {
+ currentAcc[relativePathSplitPart] = {}
+ currentAcc = currentAcc[relativePathSplitPart]
+ }
+
+ if (index === relativePathSplit.length - 1) {
+ currentAcc = {
+ ...currentAcc,
+ id: logUpload.id,
+ name: relativePathSplitPart,
+ children: [],
+ }
+ }
+ })
+
+ return acc
+ }, {} as any)
+
+
+ return tree
+ })
+
+ console.log('tree', tree)
+ }, [sortedLogUploads])
+
+ return (
+ <div className="flex flex-col items-start justify-start">
+ {/* <NodeComponent /> */}
+ </div>
+ )
+}
+
+export default Uploadtree
\ No newline at end of file