Skip to content

armgit / E2B

Public Imported from GitHub
0

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

Fix links to files and file id in query

Tomas Valentae3dea92b2535
diff --git a/components/AgentLogFilesList.tsx b/components/AgentLogFilesList.tsx
index addf12427..6445502d6 100644
--- a/components/AgentLogFilesList.tsx
+++ b/components/AgentLogFilesList.tsx
@@ -33,11 +33,16 @@ function AgentLogFilesList({
}: Props) {
const [isUploading, setIsUploading] = useState(false)
const [openedLogUploads, setOpeneLogUploads] = useState<string[]>([])
- const [selectedLogFile, setSelectedLogFile] = useState<Omit<log_files, 'project_id' | 'type' | 'size' | 'log_upload_id' | 'content' | 'last_modified'> & { content: AgentPromptLogs | AgentNextActionLog }>()
const router = useRouter()
const fileInput = useRef<HTMLInputElement>(null)
const uploadFiles = useUploadLogs(defaultProjectID)
+ const selectedLogFile = useMemo<undefined | Omit<log_files, 'project_id' | 'type' | 'size' | 'log_upload_id' | 'content' | 'last_modified'> & { content: AgentPromptLogs | AgentNextActionLog }>(() => {
+ const id = router.query.logFileID || router.query.logfileid
+ if (!id) return
+ return logUploads.flatMap(logUpload => logUpload.log_files).find(f => f.id === id)
+ }, [router.query, logUploads])
+
const sortedLogUploads = useMemo(() => logUploads
// logUploads sorted by created_at - the newest first
.sort((a, b) => {
@@ -103,16 +108,6 @@ function AgentLogFilesList({
}
}
- function logFileURL(logFileID: string) {
- // Create URL like so /?logFileID=123 and also pass any existing queries in the router.
- const query = {
- ...router.query,
- logFileID,
- selectedLog: '0',
- }
- return `/?${new URLSearchParams(query).toString()}`
- }
-
return (
<main className="overflow-hidden flex flex-col max-h-full flex-1">
<input
@@ -199,7 +194,6 @@ function AgentLogFilesList({
<div className="flex flex-col space-y-3 border-l border-gray-800 pl-2 ml-[11px] flex-1">
<UploadTree
logUpload={logUpload}
- onFileSelect={setSelectedLogFile}
/>
</div>
)}
diff --git a/components/Filesystem/File.tsx b/components/Filesystem/File.tsx
index 616909dff..e9deccec4 100644
--- a/components/Filesystem/File.tsx
+++ b/components/Filesystem/File.tsx
@@ -5,6 +5,7 @@ import {
} from 'lucide-react'
import clsx from 'clsx'
import path from 'path-browserify'
+import Link from 'next/link'
import {
FileProps,
@@ -64,28 +65,32 @@ function File({
}
return (
- <div
- className={clsx(
- 'px-1',
- 'rounded',
- 'cursor-pointer',
- 'text-gray-300',
- 'flex',
- 'items-center',
- 'space-x-1',
- 'hover:bg-gray-700/80',
- { 'bg-gray-700': isSelected },
- { 'bg-transparent': !isSelected }
- )}
+ <Link
+ prefetch={false}
+ href={metadata['href']}
+ className={
+ clsx(
+ 'px-1',
+ 'rounded',
+ 'cursor-pointer',
+ 'text-gray-300',
+ 'flex',
+ 'items-center',
+ 'space-x-1',
+ 'hover:bg-gray-700/80',
+ { 'bg-gray-700': isSelected },
+ { 'bg-transparent': !isSelected }
+ )}
onClick={handleOnClick}
+ shallow
>
{icon}
- <span
+ < span
className='truncate text-gray-400'
>
{name}
- </span>
- </div>
+ </span >
+ </Link >
)
}
diff --git a/components/Filesystem/index.tsx b/components/Filesystem/index.tsx
index 2dd9f38f2..f42ad9fcb 100644
--- a/components/Filesystem/index.tsx
+++ b/components/Filesystem/index.tsx
@@ -15,6 +15,7 @@ import FilesystemPrimitive, {
import Dir from './Dir'
import File from './File'
+
export interface FileInfo {
isDir: boolean
name: string
@@ -26,7 +27,7 @@ export interface Props {
rootPath: string
ignore?: string[]
onFiletreeClick?: (path: string, type: NodeType) => void
- fetchContent: (dirpath: string) => FileInfo[]
+ fetchContent: (dirpath: string) => (FileInfo & { id?: string })[]
}
function Filesystem({
@@ -40,7 +41,19 @@ function Filesystem({
const fetchDirContent = useCallback(async (dirpath: string) => {
const files = fetchContent(dirpath)
- const ns = files.map(f => (f.isDir ? new DirNode({ name: f.name }) : new FileNode({ name: f.name })))
+ const ns = files.map(f => (f.isDir
+ ? new DirNode({ name: f.name })
+ : new FileNode({
+ name: f.name, metadata: {
+ href: {
+ pathname: '/',
+ query: {
+ view: 'logs',
+ logFileID: f.id,
+ }
+ }
+ }
+ })))
fs.add(dirpath, ns, ignore)
}, [
diff --git a/components/Uploadtree/index.tsx b/components/Uploadtree/index.tsx
index 00e0a8de7..45600f98b 100644
--- a/components/Uploadtree/index.tsx
+++ b/components/Uploadtree/index.tsx
@@ -4,19 +4,18 @@ import path from 'path-browserify'
import Filesystem, { FileInfo } from 'components/Filesystem'
import { AgentNextActionLog, AgentPromptLogs, LiteLogUpload } from 'utils/agentLogs'
import { FiletreeProvider } from 'hooks/useFiletree'
-import { NodeType } from 'filesystem'
import { log_files } from 'db/prisma'
export interface Props {
logUpload: LiteLogUpload
- onFileSelect: (file: Omit<log_files, 'project_id' | 'type' | 'size' | 'log_upload_id' | 'content' | 'last_modified'> & { content: AgentPromptLogs | AgentNextActionLog }) => void
+ onFileSelect?: (file: Omit<log_files, 'project_id' | 'type' | 'size' | 'log_upload_id' | 'content' | 'last_modified'> & { content: AgentPromptLogs | AgentNextActionLog }) => void
}
function UploadTree({
logUpload,
onFileSelect,
}: Props) {
- const fetchLogDirContent = useCallback<(dirpath: string) => FileInfo[]>(dirpath => {
+ const fetchLogDirContent = useCallback<(dirpath: string) => (FileInfo & { id?: string })[]>(dirpath => {
const currentDir = dirpath.slice(1)
const childFiles = logUpload
.log_files
@@ -48,6 +47,7 @@ function UploadTree({
...childFiles.map(f => ({
name: f.filename,
isDir: false,
+ id: f.id,
})),
...Array.from(childDirs).map(dir => ({
name: dir,
@@ -61,16 +61,16 @@ function UploadTree({
<div className="flex flex-col items-start justify-start">
<FiletreeProvider>
<Filesystem
- onFiletreeClick={(path, type) => {
- console.log('select file', path, type)
- const pathWithoutLeadingSlash = path.slice(1)
- if (type === NodeType.File) {
- const file = logUpload.log_files.find(f => f.relativePath === pathWithoutLeadingSlash)
- if (file) {
- onFileSelect(file)
- }
- }
- }}
+ // onFiletreeClick={(path, type) => {
+ // console.log('select file', path, type)
+ // const pathWithoutLeadingSlash = path.slice(1)
+ // if (type === NodeType.File) {
+ // const file = logUpload.log_files.find(f => f.relativePath === pathWithoutLeadingSlash)
+ // if (file) {
+ // onFileSelect(file)
+ // }
+ // }
+ // }}
rootPath='/'
fetchContent={fetchLogDirContent}
/>