Skip to content

armgit / E2B

Public Imported from GitHub
0

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

fix merge conflict with main

0diva8e88de8465b
diff --cc packages/js-sdk/src/sandbox/filesystem/index.ts
index 68f8c3c4b,da61cdd18..e080a33e5
--- a/packages/js-sdk/src/sandbox/filesystem/index.ts
+++ b/packages/js-sdk/src/sandbox/filesystem/index.ts
@@@ -18,10 -18,14 +18,17 @@@ import { handleEnvdApiError, handleWatc
import { authenticationHeader, handleRpcError } from '../../envd/rpc'
import { EnvdApiClient } from '../../envd/api'
--import { FileType as FsFileType, Filesystem as FilesystemService } from '../../envd/filesystem/filesystem_pb'
++import {
++ FileType as FsFileType,
++ Filesystem as FilesystemService,
++} from '../../envd/filesystem/filesystem_pb'
-import { WatchHandle, FilesystemEvent } from './watchHandle'
+import { FilesystemEvent, WatchHandle } from './watchHandle'
+ import { compareVersions } from 'compare-versions'
+ import { TemplateError } from '../../errors'
+ import { ENVD_VERSION_RECURSIVE_WATCH } from '../../envd/versions'
+
/**
* Sandbox filesystem object information.
*/
@@@ -225,35 -229,12 +237,61 @@@ export class Filesystem
*
* @returns information about the written file
*/
- async write(path: string, data: string | ArrayBuffer | Blob | ReadableStream, opts?: FilesystemRequestOpts): Promise<EntryInfo>
- async write(files: WriteEntry[], opts?: FilesystemRequestOpts): Promise<EntryInfo[]>
+ async write(
+ path: string,
+ data: string | ArrayBuffer | Blob | ReadableStream,
+ opts?: FilesystemRequestOpts
- ): Promise<EntryInfo> {
- const blob = await new Response(data).blob()
++ ): Promise<EntryInfo>
++ async write(
++ files: WriteEntry[],
++ opts?: FilesystemRequestOpts
++ ): Promise<EntryInfo[]>
+ async write(
+ pathOrFiles: string | WriteEntry[],
- dataOrOpts?: string | ArrayBuffer | Blob | ReadableStream | FilesystemRequestOpts,
++ dataOrOpts?:
++ | string
++ | ArrayBuffer
++ | Blob
++ | ReadableStream
++ | FilesystemRequestOpts,
+ opts?: FilesystemRequestOpts
+ ): Promise<EntryInfo | EntryInfo[]> {
+ if (typeof pathOrFiles !== 'string' && !Array.isArray(pathOrFiles)) {
+ throw new Error('Path or files are required')
+ }
+
+ if (typeof pathOrFiles === 'string' && Array.isArray(dataOrOpts)) {
+ throw new Error(
+ 'Cannot specify both path and array of files. You have to specify either path and data for a single file or an array for multiple files.'
+ )
+ }
+
+ const { path, writeOpts, writeFiles } =
+ typeof pathOrFiles === 'string'
+ ? {
+ path: pathOrFiles,
+ writeOpts: opts as FilesystemRequestOpts,
- writeFiles: [{ data: dataOrOpts as string | ArrayBuffer | Blob | ReadableStream }],
++ writeFiles: [
++ {
++ data: dataOrOpts as
++ | string
++ | ArrayBuffer
++ | Blob
++ | ReadableStream,
++ },
++ ],
++ }
++ : {
++ path: undefined,
++ writeOpts: dataOrOpts as FilesystemRequestOpts,
++ writeFiles: pathOrFiles as WriteEntry[],
+ }
- : { path: undefined, writeOpts: dataOrOpts as FilesystemRequestOpts, writeFiles: pathOrFiles as WriteEntry[] }
+
+ if (writeFiles.length === 0) return [] as EntryInfo[]
+
- const blobs = await Promise.all(writeFiles.map((f) => new Response(f.data).blob()))
++ const blobs = await Promise.all(
++ writeFiles.map((f) => new Response(f.data).blob())
++ )
const res = await this.envdApi.api.POST('/files', {
params: {
@@@ -460,19 -441,24 +502,31 @@@
async watchDir(
path: string,
onEvent: (event: FilesystemEvent) => void | Promise<void>,
- opts?: WatchOpts
+ opts?: FilesystemRequestOpts & {
+ timeout?: number
+ onExit?: (err?: Error) => void | Promise<void>
+ }
): Promise<WatchHandle> {
- const requestTimeoutMs = opts?.requestTimeoutMs ?? this.connectionConfig.requestTimeoutMs
- if (opts?.recursive && this.envdApi.version && compareVersions(this.envdApi.version, ENVD_VERSION_RECURSIVE_WATCH) < 0) {
++ if (
++ opts?.recursive &&
++ this.envdApi.version &&
++ compareVersions(this.envdApi.version, ENVD_VERSION_RECURSIVE_WATCH) < 0
++ ) {
+ throw new TemplateError(
+ 'You need to update the template to use recursive watching. ' +
- 'You can do this by running `e2b template build` in the directory with the template.'
++ 'You can do this by running `e2b template build` in the directory with the template.'
+ )
+ }
+
+ const requestTimeoutMs =
+ opts?.requestTimeoutMs ?? this.connectionConfig.requestTimeoutMs
const controller = new AbortController()
const reqTimeout = requestTimeoutMs
? setTimeout(() => {
-- controller.abort()
-- }, requestTimeoutMs)
++ controller.abort()
++ }, requestTimeoutMs)
: undefined
const events = this.rpc.watchDir(
diff --cc packages/python-sdk/e2b/sandbox_async/filesystem/filesystem.py
index adef7a66f,f2d4f6076..998c1e945
--- a/packages/python-sdk/e2b/sandbox_async/filesystem/filesystem.py
+++ b/packages/python-sdk/e2b/sandbox_async/filesystem/filesystem.py
@@@ -1,10 -1,10 +1,11 @@@
+ import httpcore
+ import httpx
from io import TextIOBase
+ from packaging.version import Version
-from typing import IO, AsyncIterator, List, Literal, Optional, Union, overload
+from typing import AsyncIterator, IO, List, Literal, Optional, overload, Union
+from e2b.sandbox.filesystem.filesystem import WriteEntry
import e2b_connect as connect
- import httpcore
- import httpx
from e2b.connection_config import (
ConnectionConfig,
Username,