plugin.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. booking_supported: bool = True
  16. @classmethod
  17. def get_plugin_info(cls) -> Dict[str, str]:
  18. """
  19. @brief Gets plugin static metadata information.
  20. """
  21. return {
  22. "name": cls.name or cls.__name__,
  23. "version": cls.version,
  24. "description": cls.description,
  25. }
  26. @abstractmethod
  27. def set_config(self, config: PluginConfig):
  28. """
  29. @brief Sets API configuration.
  30. @param config PluginConfig configuration object
  31. """
  32. pass
  33. @abstractmethod
  34. def set_log(self, logger: Callable[[str], None]) -> None:
  35. """
  36. @brief Sets logging function. Must not raise exceptions.
  37. """
  38. pass
  39. @abstractmethod
  40. def create_session(self) -> None:
  41. """
  42. @brief Creates a new session. Raises exception on failure.
  43. """
  44. pass
  45. @abstractmethod
  46. def query(self, apt_type: AppointmentType) -> QueryResult:
  47. """
  48. @brief Queries available appointment slots. Raises exception on failure.
  49. @return QueryResult object containing query results
  50. """
  51. pass
  52. @abstractmethod
  53. def book(self, slot_info: QueryResult, user_inputs) -> BookResult:
  54. """
  55. @brief Executes booking attempt. Raises exception on failure.
  56. @param slot_info QueryResult slot information
  57. @param user_inputs User inputs for the booking
  58. @return BookResult object representing booking result
  59. """
  60. pass
  61. @abstractmethod
  62. def keep_alive(self):
  63. """
  64. @brief Keeps session alive. Must not raise exceptions.
  65. """
  66. pass
  67. @abstractmethod
  68. def health_check(self) -> bool:
  69. """
  70. @brief Performs health check to test API service status. Must not raise exceptions.
  71. @return True if healthy, False if issues exist
  72. """
  73. pass
  74. @abstractmethod
  75. def cleanup(self) -> None:
  76. """
  77. @brief Cleans up resources held by the plugin instance.
  78. """
  79. pass
  80. def get_plugin_status(self) -> PluginStatus:
  81. """
  82. @brief Gets snapshot of plugin instance runtime status.
  83. @return PluginStatus
  84. """
  85. return PluginStatus()