Backup-bdg/OpenHands
0
1from dataclasses import dataclass2from typing import ClassVar3 4from openhands.core.schema import ActionType5from openhands.events.action.action import (6 Action,7 ActionConfirmationStatus,8 ActionSecurityRisk,9)10 11 12@dataclass13class CmdRunAction(Action):14 command: (15 str # When `command` is empty, it will be used to print the current tmux window16 )17 is_input: bool = False # if True, the command is an input to the running process18 thought: str = ''19 blocking: bool = False # if True, the command will be run in a blocking manner, but a timeout must be set through _set_hard_timeout20 is_static: bool = False # if True, runs the command in a separate process21 cwd: str | None = None # current working directory, only used if is_static is True22 hidden: bool = False23 action: str = ActionType.RUN24 runnable: ClassVar[bool] = True25 confirmation_state: ActionConfirmationStatus = ActionConfirmationStatus.CONFIRMED26 security_risk: ActionSecurityRisk | None = None27 28 @property29 def message(self) -> str:30 return f'Running command: {self.command}'31 32 def __str__(self) -> str:33 ret = f'**CmdRunAction (source={self.source}, is_input={self.is_input})**\n'34 if self.thought:35 ret += f'THOUGHT: {self.thought}\n'36 ret += f'COMMAND:\n{self.command}'37 return ret38 39 40@dataclass41class IPythonRunCellAction(Action):42 code: str43 thought: str = ''44 include_extra: bool = (45 True # whether to include CWD & Python interpreter in the output46 )47 action: str = ActionType.RUN_IPYTHON48 runnable: ClassVar[bool] = True49 confirmation_state: ActionConfirmationStatus = ActionConfirmationStatus.CONFIRMED50 security_risk: ActionSecurityRisk | None = None51 kernel_init_code: str = '' # code to run in the kernel (if the kernel is restarted)52 53 def __str__(self) -> str:54 ret = '**IPythonRunCellAction**\n'55 if self.thought:56 ret += f'THOUGHT: {self.thought}\n'57 ret += f'CODE:\n{self.code}'58 return ret59 60 @property61 def message(self) -> str:62 return f'Running Python code interactively: {self.code}'63 