files.py 993 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. from dataclasses import dataclass
  2. from typing import ClassVar
  3. from openhands.core.schema import ActionType
  4. from openhands.events.action.action import Action, ActionSecurityRisk
  5. @dataclass
  6. class FileReadAction(Action):
  7. """Reads a file from a given path.
  8. Can be set to read specific lines using start and end
  9. Default lines 0:-1 (whole file)
  10. """
  11. path: str
  12. start: int = 0
  13. end: int = -1
  14. thought: str = ''
  15. action: str = ActionType.READ
  16. runnable: ClassVar[bool] = True
  17. security_risk: ActionSecurityRisk | None = None
  18. @property
  19. def message(self) -> str:
  20. return f'Reading file: {self.path}'
  21. @dataclass
  22. class FileWriteAction(Action):
  23. path: str
  24. content: str
  25. start: int = 0
  26. end: int = -1
  27. thought: str = ''
  28. action: str = ActionType.WRITE
  29. runnable: ClassVar[bool] = True
  30. security_risk: ActionSecurityRisk | None = None
  31. @property
  32. def message(self) -> str:
  33. return f'Writing file: {self.path}'