mirror of
https://github.com/All-Hands-AI/OpenHands.git
synced 2026-04-29 03:00:45 -04:00
* deprecating recall action * fix integration tests * fix integration tests * refractor runtime to use async * remove search memory * rename .initialize to .ainit * draft of runtime image building (separate from img agnostic) * refractor runtime build into separate file and add unit tests for it * fix image agnostic tests * move `split_bash_commands` into a separate util file * fix bash pexcept parsing for env * refractor add_env_var from sandbox to runtime; add test runtime for env var, remove it from sandbox; * remove unclear comment * capture broader error * make `add_env_var` handle multiple export at the same time * add multi env var test * fix tests with new config * make runtime tests a separate ci to avoid full disk * Update Runtime README with architecture diagram and detailed explanations * update test * remove dependency of global config in sandbox test * fix sandbox typo * runtime tests does not need ghcr build now * remove download runtime img * remove dependency of global config in sandbox test * fix sandbox typo * try to free disk before running the tests * Update opendevin/runtime/client/README.md Co-authored-by: Yufan Song <33971064+yufansong@users.noreply.github.com> * Update opendevin/runtime/client/README.md Co-authored-by: Yufan Song <33971064+yufansong@users.noreply.github.com> * Update opendevin/runtime/client/README.md Co-authored-by: Yufan Song <33971064+yufansong@users.noreply.github.com> * try to reduce code duplication * Update opendevin/runtime/client/README.md Co-authored-by: Yufan Song <33971064+yufansong@users.noreply.github.com> * Update opendevin/runtime/client/README.md Co-authored-by: Yufan Song <33971064+yufansong@users.noreply.github.com> * Update opendevin/runtime/client/README.md Co-authored-by: Yufan Song <33971064+yufansong@users.noreply.github.com> * Update opendevin/runtime/client/README.md Co-authored-by: Yufan Song <33971064+yufansong@users.noreply.github.com> * Update opendevin/runtime/client/README.md Co-authored-by: Yufan Song <33971064+yufansong@users.noreply.github.com> * cleanup before setup * temporarily remove this enable lint test since env var are now handled by runtime * linter --------- Co-authored-by: OpenDevin <opendevin@all-hands.dev> Co-authored-by: Yufan Song <33971064+yufansong@users.noreply.github.com>
55 lines
2.1 KiB
Python
55 lines
2.1 KiB
Python
from opendevin.core.config import SandboxConfig
|
|
from opendevin.events.action import (
|
|
FileReadAction,
|
|
FileWriteAction,
|
|
)
|
|
from opendevin.events.observation import (
|
|
ErrorObservation,
|
|
FileReadObservation,
|
|
FileWriteObservation,
|
|
Observation,
|
|
)
|
|
from opendevin.events.stream import EventStream
|
|
from opendevin.runtime import Sandbox
|
|
from opendevin.runtime.server.files import insert_lines, read_lines
|
|
from opendevin.runtime.server.runtime import ServerRuntime
|
|
|
|
from .filestore import E2BFileStore
|
|
from .sandbox import E2BSandbox
|
|
|
|
|
|
class E2BRuntime(ServerRuntime):
|
|
def __init__(
|
|
self,
|
|
sandbox_config: SandboxConfig,
|
|
event_stream: EventStream,
|
|
sid: str = 'default',
|
|
sandbox: Sandbox | None = None,
|
|
):
|
|
super().__init__(sandbox_config, event_stream, sid, sandbox)
|
|
if not isinstance(self.sandbox, E2BSandbox):
|
|
raise ValueError('E2BRuntime requires an E2BSandbox')
|
|
self.file_store = E2BFileStore(self.sandbox.filesystem)
|
|
|
|
async def read(self, action: FileReadAction) -> Observation:
|
|
content = self.file_store.read(action.path)
|
|
lines = read_lines(content.split('\n'), action.start, action.end)
|
|
code_view = ''.join(lines)
|
|
return FileReadObservation(code_view, path=action.path)
|
|
|
|
async def write(self, action: FileWriteAction) -> Observation:
|
|
if action.start == 0 and action.end == -1:
|
|
self.file_store.write(action.path, action.content)
|
|
return FileWriteObservation(content='', path=action.path)
|
|
files = self.file_store.list(action.path)
|
|
if action.path in files:
|
|
all_lines = self.file_store.read(action.path).split('\n')
|
|
new_file = insert_lines(
|
|
action.content.split('\n'), all_lines, action.start, action.end
|
|
)
|
|
self.file_store.write(action.path, ''.join(new_file))
|
|
return FileWriteObservation('', path=action.path)
|
|
else:
|
|
# FIXME: we should create a new file here
|
|
return ErrorObservation(f'File not found: {action.path}')
|