mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
refactor(action_execution_client): rename function and add property (#7913)
This commit is contained in:
parent
45f572f268
commit
f1f7dca009
@ -94,9 +94,13 @@ class ActionExecutionClient(Runtime):
|
||||
git_provider_tokens,
|
||||
)
|
||||
|
||||
@abstractmethod
|
||||
def _get_action_execution_server_host(self) -> str:
|
||||
pass
|
||||
@property
|
||||
def action_execution_server_url(self) -> str:
|
||||
raise NotImplementedError("Action execution server URL is not implemented")
|
||||
|
||||
@property
|
||||
def runtime_initialized(self) -> bool:
|
||||
return self._runtime_initialized
|
||||
|
||||
@retry(
|
||||
retry=retry_if_exception(_is_retryable_error),
|
||||
@ -127,7 +131,7 @@ class ActionExecutionClient(Runtime):
|
||||
def check_if_alive(self) -> None:
|
||||
response = self._send_action_server_request(
|
||||
'GET',
|
||||
f'{self._get_action_execution_server_host()}/alive',
|
||||
f'{self.action_execution_server_url}/alive',
|
||||
timeout=5,
|
||||
)
|
||||
assert response.is_closed
|
||||
@ -145,7 +149,7 @@ class ActionExecutionClient(Runtime):
|
||||
|
||||
response = self._send_action_server_request(
|
||||
'POST',
|
||||
f'{self._get_action_execution_server_host()}/list_files',
|
||||
f'{self.action_execution_server_url}/list_files',
|
||||
json=data,
|
||||
timeout=10,
|
||||
)
|
||||
@ -163,7 +167,7 @@ class ActionExecutionClient(Runtime):
|
||||
params = {'path': path}
|
||||
with self.session.stream(
|
||||
'GET',
|
||||
f'{self._get_action_execution_server_host()}/download_files',
|
||||
f'{self.action_execution_server_url}/download_files',
|
||||
params=params,
|
||||
timeout=30,
|
||||
) as response:
|
||||
@ -207,7 +211,7 @@ class ActionExecutionClient(Runtime):
|
||||
|
||||
response = self._send_action_server_request(
|
||||
'POST',
|
||||
f'{self._get_action_execution_server_host()}/upload_file',
|
||||
f'{self.action_execution_server_url}/upload_file',
|
||||
files=upload_data,
|
||||
params=params,
|
||||
timeout=300,
|
||||
@ -224,12 +228,12 @@ class ActionExecutionClient(Runtime):
|
||||
)
|
||||
|
||||
def get_vscode_token(self) -> str:
|
||||
if self.vscode_enabled and self._runtime_initialized:
|
||||
if self.vscode_enabled and self.runtime_initialized:
|
||||
if self._vscode_token is not None: # cached value
|
||||
return self._vscode_token
|
||||
response = self._send_action_server_request(
|
||||
'GET',
|
||||
f'{self._get_action_execution_server_host()}/vscode/connection_token',
|
||||
f'{self.action_execution_server_url}/vscode/connection_token',
|
||||
timeout=10,
|
||||
)
|
||||
response_json = response.json()
|
||||
@ -288,7 +292,7 @@ class ActionExecutionClient(Runtime):
|
||||
}
|
||||
response = self._send_action_server_request(
|
||||
'POST',
|
||||
f'{self._get_action_execution_server_host()}/execute_action',
|
||||
f'{self.action_execution_server_url}/execute_action',
|
||||
json=execution_action_body,
|
||||
# wait a few more seconds to get the timeout error from client side
|
||||
timeout=action.timeout + 5,
|
||||
|
||||
@ -127,7 +127,8 @@ class DaytonaRuntime(ActionExecutionClient):
|
||||
]
|
||||
return f'https://{port}-{self.workspace.id}.{node_domain}'
|
||||
|
||||
def _get_action_execution_server_host(self) -> str:
|
||||
@property
|
||||
def action_execution_server_url(self) -> str:
|
||||
return self.api_url
|
||||
|
||||
def _start_action_execution_server(self) -> None:
|
||||
|
||||
@ -86,7 +86,6 @@ class DockerRuntime(ActionExecutionClient):
|
||||
)
|
||||
|
||||
self.config = config
|
||||
self._runtime_initialized: bool = False
|
||||
self.status_callback = status_callback
|
||||
|
||||
self._host_port = -1
|
||||
@ -133,7 +132,8 @@ class DockerRuntime(ActionExecutionClient):
|
||||
f'Installing extra user-provided dependencies in the runtime image: {self.config.sandbox.runtime_extra_deps}',
|
||||
)
|
||||
|
||||
def _get_action_execution_server_host(self):
|
||||
@property
|
||||
def action_execution_server_url(self):
|
||||
return self.api_url
|
||||
|
||||
async def connect(self):
|
||||
|
||||
@ -174,7 +174,8 @@ class LocalRuntime(ActionExecutionClient):
|
||||
headless_mode,
|
||||
)
|
||||
|
||||
def _get_action_execution_server_host(self):
|
||||
@property
|
||||
def action_execution_server_url(self):
|
||||
return self.api_url
|
||||
|
||||
async def connect(self):
|
||||
@ -292,7 +293,7 @@ class LocalRuntime(ActionExecutionClient):
|
||||
|
||||
async def execute_action(self, action: Action) -> Observation:
|
||||
"""Execute an action by sending it to the server."""
|
||||
if not self._runtime_initialized:
|
||||
if not self.runtime_initialized:
|
||||
raise AgentRuntimeDisconnectedError('Runtime not initialized')
|
||||
|
||||
if self.server_process is None or self.server_process.poll() is not None:
|
||||
|
||||
@ -146,7 +146,8 @@ class ModalRuntime(ActionExecutionClient):
|
||||
self.send_status_message(' ')
|
||||
self._runtime_initialized = True
|
||||
|
||||
def _get_action_execution_server_host(self):
|
||||
@property
|
||||
def action_execution_server_url(self):
|
||||
return self.api_url
|
||||
|
||||
@tenacity.retry(
|
||||
|
||||
@ -93,7 +93,8 @@ class RemoteRuntime(ActionExecutionClient):
|
||||
message = f'[runtime session_id={self.sid} runtime_id={self.runtime_id or "unknown"}] {message}'
|
||||
getattr(logger, level)(message, stacklevel=2)
|
||||
|
||||
def _get_action_execution_server_host(self):
|
||||
@property
|
||||
def action_execution_server_url(self):
|
||||
return self.runtime_url
|
||||
|
||||
async def connect(self):
|
||||
|
||||
@ -56,7 +56,8 @@ class RunloopRuntime(ActionExecutionClient):
|
||||
# Buffer for container logs
|
||||
self._vscode_url: str | None = None
|
||||
|
||||
def _get_action_execution_server_host(self):
|
||||
@property
|
||||
def action_execution_server_url(self):
|
||||
return self.api_url
|
||||
|
||||
@tenacity.retry(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user