|
|
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] |