event.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import datetime
  2. from dataclasses import dataclass
  3. from typing import TYPE_CHECKING, Optional
  4. if TYPE_CHECKING:
  5. from opendevin.events.serialization.event import EventSource
  6. @dataclass
  7. class Event:
  8. @property
  9. def message(self) -> str:
  10. if hasattr(self, '_message'):
  11. return self._message # type: ignore [attr-defined]
  12. return ''
  13. @property
  14. def id(self) -> int:
  15. if hasattr(self, '_id'):
  16. return self._id # type: ignore [attr-defined]
  17. return -1
  18. @property
  19. def timestamp(self) -> Optional[datetime.datetime]:
  20. if hasattr(self, '_timestamp'):
  21. return self._timestamp # type: ignore [attr-defined]
  22. return None
  23. @property
  24. def source(self) -> Optional['EventSource']:
  25. if hasattr(self, '_source'):
  26. return self._source # type: ignore [attr-defined]
  27. return None
  28. @property
  29. def cause(self) -> Optional[int]:
  30. if hasattr(self, '_cause'):
  31. return self._cause # type: ignore [attr-defined]
  32. return None