File size: 1,652 Bytes
070c020
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
54
55
56
57
58
59
60
from abc import ABC, abstractmethod
from typing import Dict, Any, Optional
from pydantic import BaseModel
import logging
from datetime import datetime

class LatticeComponent(ABC):
    """Base class for all Lattice components"""
    
    def __init__(self, config: Optional[Dict[str, Any]] = None):
        self.config = config or {}
        self.logger = logging.getLogger(f"lattice.{self.__class__.__name__}")
        self._initialized = False
    
    @abstractmethod
    async def initialize(self) -> None:
        """Initialize the component"""
        self._initialized = True
    
    @abstractmethod
    async def validate_config(self) -> bool:
        """Validate component configuration"""
        pass
    
    def ensure_initialized(self):
        """Ensure component is initialized"""
        if not self._initialized:
            raise RuntimeError(f"{self.__class__.__name__} not initialized")

class LatticeError(Exception):
    """Base class for Lattice errors"""
    pass

class ConfigurationError(LatticeError):
    """Configuration related errors"""
    pass

class ExecutionError(LatticeError):
    """Execution related errors"""
    pass

class BaseRequest(BaseModel):
    """Base class for all requests"""
    request_id: Optional[str]
    timestamp: Optional[datetime]

class BaseResponse(BaseModel):
    """Base class for all responses"""
    request_id: Optional[str]
    timestamp: datetime
    status: str
    error: Optional[str]

class ComponentMetadata(BaseModel):
    """Component metadata"""
    name: str
    version: str
    description: Optional[str]
    capabilities: Dict[str, Any]
    dependencies: Dict[str, str]