"""
AgentBase SDK - Deploy. Observe. Heal.

Usage:
    import agentbase_sdk as ab

    ab.init(api_key="ab_live_...", agent_name="my-agent")
    ab.instrument_openai()

    with ab.trace("my-task") as t:
        result = my_agent.run(input)
        t.set_output(result)
"""

from agentbase_sdk.client import AgentBaseClient
from agentbase_sdk.tracer import Tracer, trace, span
from agentbase_sdk.instruments import (
    instrument_langchain,
    instrument_crewai,
    instrument_openai,
    instrument_anthropic,
)
from agentbase_sdk.decorators import observe, heal

__version__ = "0.1.0"
__all__ = [
    "init", "trace", "span", "observe", "heal",
    "instrument_langchain", "instrument_crewai",
    "instrument_openai", "instrument_anthropic",
    "get_client", "shutdown",
]

_client = None


def init(
    api_key=None,
    agent_name=None,
    endpoint="https://api.agentbase.dev",
    auto_heal=True,
    environment="production",
    debug=False,
    batch_size=50,
    flush_interval=2.0,
):
    """Initialize the AgentBase SDK."""
    global _client
    _client = AgentBaseClient(
        api_key=api_key,
        agent_name=agent_name,
        endpoint=endpoint,
        auto_heal=auto_heal,
        environment=environment,
        debug=debug,
        batch_size=batch_size,
        flush_interval=flush_interval,
    )
    _client.start()
    return _client


def get_client():
    if _client is None:
        raise RuntimeError("AgentBase SDK not initialized. Call agentbase_sdk.init() first.")
    return _client


def shutdown():
    global _client
    if _client:
        _client.shutdown()
        _client = None
