mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
remove sandbox abstract class (#3337)
* remove sandbox abstract class * remove cancellable stream
This commit is contained in:
parent
9757f362bf
commit
99ac91f6ad
@ -2,13 +2,10 @@ from .action import ActionType
|
||||
from .agent import AgentState
|
||||
from .config import ConfigType
|
||||
from .observation import ObservationType
|
||||
from .stream import CancellableStream, StreamMixin
|
||||
|
||||
__all__ = [
|
||||
'ActionType',
|
||||
'ObservationType',
|
||||
'ConfigType',
|
||||
'AgentState',
|
||||
'CancellableStream',
|
||||
'StreamMixin',
|
||||
]
|
||||
|
||||
@ -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
|
||||
@ -1,5 +1,4 @@
|
||||
from .e2b.sandbox import E2BBox
|
||||
from .sandbox import Sandbox
|
||||
|
||||
|
||||
def get_runtime_cls(name: str):
|
||||
|
||||
@ -10,7 +10,6 @@ from opendevin.events.observation import (
|
||||
Observation,
|
||||
)
|
||||
from opendevin.events.stream import EventStream
|
||||
from opendevin.runtime import Sandbox
|
||||
from opendevin.runtime.plugins import PluginRequirement
|
||||
from opendevin.runtime.runtime import Runtime
|
||||
|
||||
@ -26,7 +25,7 @@ class E2BRuntime(Runtime):
|
||||
event_stream: EventStream,
|
||||
sid: str = 'default',
|
||||
plugins: list[PluginRequirement] | None = None,
|
||||
sandbox: Sandbox | None = None,
|
||||
sandbox: E2BSandbox | None = None,
|
||||
):
|
||||
super().__init__(config, event_stream, sid, plugins)
|
||||
if sandbox is None:
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import os
|
||||
import tarfile
|
||||
import copy
|
||||
from glob import glob
|
||||
|
||||
from e2b import Sandbox as E2BSandbox
|
||||
@ -9,13 +10,12 @@ from e2b.sandbox.exception import (
|
||||
|
||||
from opendevin.core.config import SandboxConfig
|
||||
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
|
||||
_cwd: str = '/home/user'
|
||||
_env: dict[str, str] = {}
|
||||
is_initial_session: bool = True
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@ -23,7 +23,8 @@ class E2BBox(Sandbox):
|
||||
e2b_api_key: str,
|
||||
template: str = 'open-devin',
|
||||
):
|
||||
super().__init__(config)
|
||||
self.config = copy.deepcopy(config)
|
||||
self.initialize_plugins: bool = config.initialize_plugins
|
||||
self.sandbox = E2BSandbox(
|
||||
api_key=e2b_api_key,
|
||||
template=template,
|
||||
@ -62,8 +63,8 @@ class E2BBox(Sandbox):
|
||||
return tar_filename
|
||||
|
||||
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
|
||||
process = self.sandbox.process.start(cmd, env_vars=self._env)
|
||||
try:
|
||||
|
||||
@ -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
|
||||
Loading…
x
Reference in New Issue
Block a user