"""sageLLM Backend Provider 抽象。

本包提供硬件后端抽象层：
- BackendProvider 接口定义
- Stream/Event/KVBlock 抽象
- CPU Backend 实现
- CUDA Backend 实现 (PyTorch)
- Ascend Backend 实现 (PyTorch-NPU)

能力描述符（DType, KernelKind, CapabilityDescriptor）已迁移至 sagellm-protocol。
请直接从 sagellm_protocol 导入这些类型。

Note: Engine implementations have been moved to sagellm-core.
      This package now focuses solely on hardware abstraction.
"""

from __future__ import annotations

from sagellm_protocol import CapabilityDescriptor, DType, KernelKind

from sagellm_backend.base import BackendProvider, Event, KVBlock, Stream
from sagellm_backend.providers.cpu import CPUBackendProvider, create_cpu_backend

# Optional PyTorch-based providers (lazy import)
try:
    from sagellm_backend.providers.pytorch_cuda import (
        PyTorchCUDABackendProvider,
        create_pytorch_cuda_backend,
    )

    _PYTORCH_CUDA_AVAILABLE = True
except ImportError:
    _PYTORCH_CUDA_AVAILABLE = False
    PyTorchCUDABackendProvider = None  # type: ignore
    create_pytorch_cuda_backend = None  # type: ignore

try:
    from sagellm_backend.providers.pytorch_ascend import (
        PyTorchAscendBackendProvider,
        create_pytorch_ascend_backend,
    )

    _PYTORCH_ASCEND_AVAILABLE = True
except ImportError:
    _PYTORCH_ASCEND_AVAILABLE = False
    PyTorchAscendBackendProvider = None  # type: ignore
    create_pytorch_ascend_backend = None  # type: ignore

__version__ = "0.3.0.9"

__all__ = [
    # Version
    "__version__",
    # Provider interface
    "BackendProvider",
    "Stream",
    "Event",
    "KVBlock",
    # Capability types (re-exported from protocol for convenience)
    "CapabilityDescriptor",
    "DType",
    "KernelKind",
    # CPU backend implementation
    "CPUBackendProvider",
    "create_cpu_backend",
    # PyTorch CUDA backend (optional)
    "PyTorchCUDABackendProvider",
    "create_pytorch_cuda_backend",
    # PyTorch Ascend backend (optional)
    "PyTorchAscendBackendProvider",
    "create_pytorch_ascend_backend",
]
