π OpenHands: AI-Driven Development
Add bytes support to FileStore write operations (#6019)
Robert Brennan510c1644dd71
diff --git a/openhands/runtime/impl/e2b/filestore.py b/openhands/runtime/impl/e2b/filestore.pyindex 86c6edae0c..640f884c2c 100644--- a/openhands/runtime/impl/e2b/filestore.py+++ b/openhands/runtime/impl/e2b/filestore.py@@ -5,7 +5,7 @@ class E2BFileStore(FileStore):def __init__(self, filesystem):self.filesystem = filesystem- def write(self, path: str, contents: str) -> None:+ def write(self, path: str, contents: str | bytes) -> None:self.filesystem.write(path, contents)def read(self, path: str) -> str:diff --git a/openhands/storage/files.py b/openhands/storage/files.pyindex 5a210eca80..d4f4104b3c 100644--- a/openhands/storage/files.py+++ b/openhands/storage/files.py@@ -3,7 +3,7 @@ from abc import abstractmethodclass FileStore:@abstractmethod- def write(self, path: str, contents: str) -> None:+ def write(self, path: str, contents: str | bytes) -> None:pass@abstractmethoddiff --git a/openhands/storage/memory.py b/openhands/storage/memory.pyindex b0b7f371b4..3574b875e7 100644--- a/openhands/storage/memory.py+++ b/openhands/storage/memory.py@@ -12,7 +12,9 @@ class InMemoryFileStore(FileStore):def __init__(self, files: dict[str, str] = IN_MEMORY_FILES):self.files = files- def write(self, path: str, contents: str) -> None:+ def write(self, path: str, contents: str | bytes) -> None:+ if isinstance(contents, bytes):+ contents = contents.decode('utf-8')self.files[path] = contentsdef read(self, path: str) -> str:diff --git a/openhands/storage/s3.py b/openhands/storage/s3.pyindex a9f1875379..b571d4288c 100644--- a/openhands/storage/s3.py+++ b/openhands/storage/s3.py@@ -15,8 +15,8 @@ class S3FileStore(FileStore):self.bucket = os.getenv('AWS_S3_BUCKET')self.client = Minio(endpoint, access_key, secret_key, secure=secure)- def write(self, path: str, contents: str) -> None:- as_bytes = contents.encode('utf-8')+ def write(self, path: str, contents: str | bytes) -> None:+ as_bytes = contents.encode('utf-8') if isinstance(contents, str) else contentsstream = io.BytesIO(as_bytes)try:self.client.put_object(self.bucket, path, stream, len(as_bytes))