File size: 1,282 Bytes
4a2ab42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from abc import ABC, abstractmethod
from dataclasses import dataclass
from typing import Any


@dataclass
class PluginMetadata:
    name: str
    version: str
    namespace: str
    author: str
    description: str
    dependencies: dict[str, str]  # name: version_constraint
    capabilities: list[str]  # ['fraud_detection', 'ui_component']
    security_level: str  # 'official', 'verified', 'community', 'custom'
    api_version: str


@dataclass
class PluginContext:
    config: dict[str, Any]
    services: dict[str, Any]  # Map of service accessors

    def get_service(self, name: str) -> Any:
        return self.services.get(name)


class PluginInterface(ABC):
    """
    Base interface for all plugins.
    """

    @property
    @abstractmethod
    def metadata(self) -> PluginMetadata:
        pass

    @abstractmethod
    async def initialize(self, context: PluginContext) -> bool:
        """Initialize with injected dependencies"""

    @abstractmethod
    async def execute(self, *args, **kwargs) -> Any:
        """Main execution method"""

    @abstractmethod
    async def cleanup(self) -> None:
        """Cleanup resources"""

    @abstractmethod
    def validate_config(self, config: dict[str, Any]) -> list[str]:
        """Validate plugin configuration"""