plugin.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. # plugin.py
  2. from typing import Callable, List, Dict
  3. from abc import ABC, abstractmethod
  4. from core_types import PluginConfig, AppointmentType, QueryResult, BookResult, PluginStatus
  5. # ================== Interface Class ==================
  6. class IPlugin(ABC):
  7. """
  8. @brief Plugin API interface class
  9. Defines core operations for visa automation plugins, including configuration, session management,
  10. querying, booking, health checks, and resource cleanup. All concrete plugin implementations must inherit from this interface.
  11. """
  12. name: str = ""
  13. version: str = "1.0.0"
  14. description: str = ""
  15. @classmethod
  16. def get_plugin_info(cls) -> Dict[str, str]:
  17. """
  18. @brief Gets plugin static metadata information.
  19. """
  20. return {
  21. "name": cls.name or cls.__name__,
  22. "version": cls.version,
  23. "description": cls.description,
  24. }
  25. @abstractmethod
  26. def set_config(self, config: PluginConfig):
  27. """
  28. @brief Sets API configuration.
  29. @param config PluginConfig configuration object
  30. """
  31. pass
  32. @abstractmethod
  33. def set_log(self, logger: Callable[[str], None]) -> None:
  34. """
  35. @brief Sets logging function. Must not raise exceptions.
  36. """
  37. pass
  38. @abstractmethod
  39. def create_session(self) -> None:
  40. """
  41. @brief Creates a new session. Raises exception on failure.
  42. """
  43. pass
  44. @abstractmethod
  45. def query(self, apt_type: AppointmentType) -> QueryResult:
  46. """
  47. @brief Queries available appointment slots. Raises exception on failure.
  48. @return QueryResult object containing query results
  49. """
  50. pass
  51. @abstractmethod
  52. def book(self, slot_info: QueryResult, user_inputs) -> BookResult:
  53. """
  54. @brief Executes booking attempt. Raises exception on failure.
  55. @param slot_info QueryResult slot information
  56. @param user_inputs User inputs for the booking
  57. @return BookResult object representing booking result
  58. """
  59. pass
  60. @abstractmethod
  61. def keep_alive(self):
  62. """
  63. @brief Keeps session alive. Must not raise exceptions.
  64. """
  65. pass
  66. @abstractmethod
  67. def health_check(self) -> bool:
  68. """
  69. @brief Performs health check to test API service status. Must not raise exceptions.
  70. @return True if healthy, False if issues exist
  71. """
  72. pass
  73. @abstractmethod
  74. def cleanup(self) -> None:
  75. """
  76. @brief Cleans up resources held by the plugin instance.
  77. """
  78. pass
  79. def get_plugin_status(self) -> PluginStatus:
  80. """
  81. @brief Gets snapshot of plugin instance runtime status.
  82. @return PluginStatus
  83. """
  84. return PluginStatus()