Przeglądaj źródła

remove sandbox abstract class (#3337)

* remove sandbox abstract class

* remove cancellable stream
Yufan Song 1 rok temu
rodzic
commit
99ac91f6ad

+ 0 - 3
opendevin/core/schema/__init__.py

@@ -2,13 +2,10 @@ from .action import ActionType
 from .agent import AgentState
 from .agent import AgentState
 from .config import ConfigType
 from .config import ConfigType
 from .observation import ObservationType
 from .observation import ObservationType
-from .stream import CancellableStream, StreamMixin
 
 
 __all__ = [
 __all__ = [
     'ActionType',
     'ActionType',
     'ObservationType',
     'ObservationType',
     'ConfigType',
     'ConfigType',
     'AgentState',
     'AgentState',
-    'CancellableStream',
-    'StreamMixin',
 ]
 ]

+ 0 - 27
opendevin/core/schema/stream.py

@@ -1,27 +0,0 @@
-from abc import ABC, abstractmethod
-from typing import Union
-
-
-class StreamMixin:
-    def __init__(self, generator):
-        self.generator = generator
-        self.closed = False
-
-    def __iter__(self):
-        return self
-
-    def __next__(self):
-        if self.closed:
-            raise StopIteration
-        else:
-            return next(self.generator)
-
-
-class CancellableStream(StreamMixin, ABC):
-    @abstractmethod
-    def close(self):
-        pass
-
-    @abstractmethod
-    def exit_code(self) -> Union[int, None]:
-        pass

+ 0 - 1
opendevin/runtime/__init__.py

@@ -1,5 +1,4 @@
 from .e2b.sandbox import E2BBox
 from .e2b.sandbox import E2BBox
-from .sandbox import Sandbox
 
 
 
 
 def get_runtime_cls(name: str):
 def get_runtime_cls(name: str):

+ 1 - 2
opendevin/runtime/e2b/runtime.py

@@ -10,7 +10,6 @@ from opendevin.events.observation import (
     Observation,
     Observation,
 )
 )
 from opendevin.events.stream import EventStream
 from opendevin.events.stream import EventStream
-from opendevin.runtime import Sandbox
 from opendevin.runtime.plugins import PluginRequirement
 from opendevin.runtime.plugins import PluginRequirement
 from opendevin.runtime.runtime import Runtime
 from opendevin.runtime.runtime import Runtime
 
 
@@ -26,7 +25,7 @@ class E2BRuntime(Runtime):
         event_stream: EventStream,
         event_stream: EventStream,
         sid: str = 'default',
         sid: str = 'default',
         plugins: list[PluginRequirement] | None = None,
         plugins: list[PluginRequirement] | None = None,
-        sandbox: Sandbox | None = None,
+        sandbox: E2BSandbox | None = None,
     ):
     ):
         super().__init__(config, event_stream, sid, plugins)
         super().__init__(config, event_stream, sid, plugins)
         if sandbox is None:
         if sandbox is None:

+ 8 - 7
opendevin/runtime/e2b/sandbox.py

@@ -1,5 +1,6 @@
 import os
 import os
 import tarfile
 import tarfile
+import copy
 from glob import glob
 from glob import glob
 
 
 from e2b import Sandbox as E2BSandbox
 from e2b import Sandbox as E2BSandbox
@@ -9,13 +10,12 @@ from e2b.sandbox.exception import (
 
 
 from opendevin.core.config import SandboxConfig
 from opendevin.core.config import SandboxConfig
 from opendevin.core.logger import opendevin_logger as logger
 from opendevin.core.logger import opendevin_logger as logger
-from opendevin.core.schema import CancellableStream
-from opendevin.runtime.sandbox import Sandbox
 
 
-
-class E2BBox(Sandbox):
+class E2BBox:
     closed = False
     closed = False
     _cwd: str = '/home/user'
     _cwd: str = '/home/user'
+    _env: dict[str, str] = {}
+    is_initial_session: bool = True
 
 
     def __init__(
     def __init__(
         self,
         self,
@@ -23,7 +23,8 @@ class E2BBox(Sandbox):
         e2b_api_key: str,
         e2b_api_key: str,
         template: str = 'open-devin',
         template: str = 'open-devin',
     ):
     ):
-        super().__init__(config)
+        self.config = copy.deepcopy(config)
+        self.initialize_plugins: bool = config.initialize_plugins
         self.sandbox = E2BSandbox(
         self.sandbox = E2BSandbox(
             api_key=e2b_api_key,
             api_key=e2b_api_key,
             template=template,
             template=template,
@@ -62,8 +63,8 @@ class E2BBox(Sandbox):
         return tar_filename
         return tar_filename
 
 
     def execute(
     def execute(
-        self, cmd: str, stream: bool = False, timeout: int | None = None
-    ) -> tuple[int, str | CancellableStream]:
+        self, cmd: str, timeout: int | None = None
+    ) -> tuple[int, str]:
         timeout = timeout if timeout is not None else self.config.timeout
         timeout = timeout if timeout is not None else self.config.timeout
         process = self.sandbox.process.start(cmd, env_vars=self._env)
         process = self.sandbox.process.start(cmd, env_vars=self._env)
         try:
         try:

+ 0 - 32
opendevin/runtime/sandbox.py

@@ -1,32 +0,0 @@
-import copy
-from abc import ABC, abstractmethod
-
-from opendevin.core.config import SandboxConfig
-from opendevin.core.schema import CancellableStream
-
-
-class Sandbox(ABC):
-    _env: dict[str, str] = {}
-    is_initial_session: bool = True
-
-    def __init__(self, config: SandboxConfig):
-        self.config = copy.deepcopy(config)
-        self.initialize_plugins: bool = config.initialize_plugins
-
-    @abstractmethod
-    def execute(
-        self, cmd: str, stream: bool = False, timeout: int | None = None
-    ) -> tuple[int, str | CancellableStream]:
-        pass
-
-    @abstractmethod
-    def close(self):
-        pass
-
-    @abstractmethod
-    def copy_to(self, host_src: str, sandbox_dest: str, recursive: bool = False):
-        pass
-
-    @abstractmethod
-    def get_working_directory(self):
-        pass