# ---------------------------------------------------------------------------
# water — The production-ready agent harness framework for Python
# ---------------------------------------------------------------------------
# Subpackage layout:
#   water.core          – Flow, Task, ExecutionEngine, Context
#   water.storage       – StorageBackend, InMemory, SQLite, Redis, Postgres
#   water.resilience    – CircuitBreaker, RateLimiter, Cache, Checkpoint, DLQ
#   water.middleware     – Middleware, Hooks, Events
#   water.agents        – LLM tasks, Multi-agent, Approval, Human, Sandbox
#   water.integrations  – MCP, Chat, Streaming
#   water.observability – Telemetry, Dashboard
#   water.triggers      – WebhookTrigger, CronTrigger, QueueTrigger, Registry
#   water.server        – FlowServer (FastAPI)
#   water.utils         – Testing, Scheduler, Declarative, Secrets, CLI
# ---------------------------------------------------------------------------

# --- Core ---
from water.core import Flow, Task, create_task, ExecutionContext, SubFlow, compose_flows
from water.core.engine import FlowPausedError, FlowStoppedError
from water.core.replay import ReplayEngine, ReplayConfig, ReplayResult
from water.core.versioning import (
    FlowVersion,
    SchemaChange,
    CompatibilityChecker,
    SchemaRegistry,
    snapshot_flow_schemas,
)

# --- Storage ---
from water.storage import (
    StorageBackend,
    InMemoryStorage,
    SQLiteStorage,
    FlowSession,
    FlowStatus,
    TaskRun,
    RedisStorage,
    PostgresStorage,
)

# --- Resilience ---
from water.resilience import (
    CircuitBreaker,
    CircuitBreakerOpen,
    RateLimiter,
    get_rate_limiter,
    TaskCache,
    InMemoryCache,
    CheckpointBackend,
    InMemoryCheckpoint,
    DeadLetter,
    DeadLetterQueue,
    InMemoryDLQ,
    FlowCache,
    FlowCacheBackend,
    InMemoryFlowCache,
    CacheStats,
    ProviderRateLimiter,
    ProviderLimits,
    LimiterMetrics,
)

# --- Middleware & Lifecycle ---
from water.middleware import (
    Middleware,
    LoggingMiddleware,
    TransformMiddleware,
    HookManager,
    EventEmitter,
    FlowEvent,
    EventSubscription,
)

# --- Agents ---
from water.agents import (
    create_agent_task,
    LLMProvider,
    MockProvider,
    OpenAIProvider,
    AnthropicProvider,
    CustomProvider,
    AgentInput,
    AgentOutput,
    AgentRole,
    SharedContext,
    AgentOrchestrator,
    create_agent_team,
    RiskLevel,
    ApprovalPolicy,
    ApprovalRequest,
    ApprovalGate,
    ApprovalDenied,
    create_approval_task,
    create_human_task,
    HumanInputManager,
    HumanInputRequired,
    SandboxConfig,
    SandboxResult,
    SandboxBackend,
    InMemorySandbox,
    SubprocessSandbox,
    DockerSandbox,
    create_sandboxed_task,
    Tool,
    Toolkit,
    ToolResult,
    ToolExecutor,
    ContextManager,
    TokenCounter,
    TruncationStrategy,
    StreamChunk,
    StreamingProvider,
    MockStreamProvider,
    OpenAIStreamProvider,
    AnthropicStreamProvider,
    create_streaming_agent_task,
    FallbackChain,
    PromptTemplate,
    PromptLibrary,
    BatchProcessor,
    BatchResult,
    BatchItem,
    create_batch_task,
    PlannerAgent,
    TaskRegistry,
    ExecutionPlan,
    PlanStep,
    create_planner_task,
    create_agentic_task,
    SubAgentConfig,
    create_sub_agent_tool,
    MemoryLayer,
    MemoryEntry,
    MemoryBackend,
    InMemoryBackend as InMemoryMemoryBackend,
    FileBackend,
    MemoryManager,
    create_memory_tools,
    TFIDFScorer,
    SemanticToolSelector,
    create_tool_selector,
    Turn,
    ConversationState,
    ConversationManager,
    create_conversation_task,
    create_structured_task,
)

# --- Integrations ---
from water.integrations import (
    MCPServer,
    MCPClient,
    create_mcp_task,
    ChatAdapter,
    ChatBot,
    ChatMessage,
    FlowNotification,
    InMemoryAdapter,
    SlackAdapter,
    DiscordAdapter,
    TelegramAdapter,
    StreamEvent,
    StreamManager,
    StreamingFlow,
    add_streaming_routes,
    A2AServer,
    A2AClient,
    A2ATask,
    A2AMessage,
    AgentCard,
    AgentSkill,
    MessagePart,
    A2ATaskState,
    create_a2a_task,
)

# --- Plugins ---
from water.plugins import PluginRegistry, WaterPlugin, PluginType

# --- Bench ---
from water.bench import (
    BenchmarkCase,
    BenchmarkResult,
    Benchmark,
    BenchmarkRunner,
    BenchmarkReport,
    ToolUseBenchmark,
    InstructionBenchmark,
)

# --- Eval ---
from water.eval import (
    EvalSuite,
    EvalCase,
    Evaluator,
    ExactMatch,
    ContainsMatch,
    LLMJudge,
    SemanticSimilarity,
    EvalReport,
    EvalConfig,
    build_evaluators,
    build_cases,
)

# --- Guardrails ---
from water.guardrails import (
    Guardrail,
    GuardrailResult,
    GuardrailViolation,
    GuardrailChain,
    ContentFilter,
    SchemaGuardrail,
    CostGuardrail,
    TopicGuardrail,
    RetryWithFeedback,
    RetryContext,
)

# --- Observability ---
from water.observability import (
    FlowDashboard,
    TelemetryManager,
    is_otel_available,
    TraceCollector,
    TraceStore,
    Trace,
    TraceSpan,
    StructuredLogger,
    LogContext,
    LogExporter,
    CostTracker,
    CostSummary,
    TokenUsage,
    TaskCost,
    BudgetExceededError,
    auto_instrument,
    AutoInstrumentor,
    InstrumentationConfig,
    InstrumentationCollector,
    SpanRecord,
)

# --- Triggers ---
from water.triggers import (
    Trigger,
    TriggerEvent,
    WebhookTrigger,
    CronTrigger,
    QueueTrigger,
    TriggerRegistry,
)

# --- Server ---
from water.server import FlowServer

# --- Tasks (Standard Library) ---
from water.tasks import (
    http_request,
    json_transform,
    map_fields,
    filter_fields,
    file_read,
    file_write,
    webhook_task,
    delay,
    log_task,
    noop,
)

# --- Debug ---
from water.debug import FlowDebugger, Breakpoint, DebugStep

# --- Utils ---
from water.utils import (
    MockTask,
    FlowTestRunner,
    FlowScheduler,
    ScheduledJob,
    load_flow_from_dict,
    load_flow_from_yaml,
    load_flow_from_json,
    SecretValue,
    SecretsManager,
    EnvSecretsManager,
)

__all__ = [
    # Core
    "Flow",
    "Task",
    "create_task",
    "ExecutionContext",
    "SubFlow",
    "compose_flows",
    "FlowPausedError",
    "FlowStoppedError",
    "FlowVersion",
    "SchemaChange",
    "CompatibilityChecker",
    "SchemaRegistry",
    "snapshot_flow_schemas",
    "ReplayEngine",
    "ReplayConfig",
    "ReplayResult",
    # Storage
    "StorageBackend",
    "InMemoryStorage",
    "SQLiteStorage",
    "FlowSession",
    "FlowStatus",
    "TaskRun",
    "RedisStorage",
    "PostgresStorage",
    # Resilience
    "CircuitBreaker",
    "CircuitBreakerOpen",
    "RateLimiter",
    "get_rate_limiter",
    "TaskCache",
    "InMemoryCache",
    "CheckpointBackend",
    "InMemoryCheckpoint",
    "DeadLetter",
    "DeadLetterQueue",
    "InMemoryDLQ",
    "FlowCache",
    "FlowCacheBackend",
    "InMemoryFlowCache",
    "CacheStats",
    "ProviderRateLimiter",
    "ProviderLimits",
    "LimiterMetrics",
    # Middleware & Lifecycle
    "Middleware",
    "LoggingMiddleware",
    "TransformMiddleware",
    "HookManager",
    "EventEmitter",
    "FlowEvent",
    "EventSubscription",
    # Agents
    "create_agent_task",
    "LLMProvider",
    "MockProvider",
    "OpenAIProvider",
    "AnthropicProvider",
    "CustomProvider",
    "AgentInput",
    "AgentOutput",
    "AgentRole",
    "SharedContext",
    "AgentOrchestrator",
    "create_agent_team",
    "RiskLevel",
    "ApprovalPolicy",
    "ApprovalRequest",
    "ApprovalGate",
    "ApprovalDenied",
    "create_approval_task",
    "create_human_task",
    "HumanInputManager",
    "HumanInputRequired",
    "SandboxConfig",
    "SandboxResult",
    "SandboxBackend",
    "InMemorySandbox",
    "SubprocessSandbox",
    "DockerSandbox",
    "create_sandboxed_task",
    "Tool",
    "Toolkit",
    "ToolResult",
    "ToolExecutor",
    "ContextManager",
    "TokenCounter",
    "TruncationStrategy",
    "StreamChunk",
    "StreamingProvider",
    "MockStreamProvider",
    "OpenAIStreamProvider",
    "AnthropicStreamProvider",
    "create_streaming_agent_task",
    "FallbackChain",
    "PromptTemplate",
    "PromptLibrary",
    "BatchProcessor",
    "BatchResult",
    "BatchItem",
    "create_batch_task",
    "PlannerAgent",
    "TaskRegistry",
    "ExecutionPlan",
    "PlanStep",
    "create_planner_task",
    "create_agentic_task",
    "SubAgentConfig",
    "create_sub_agent_tool",
    "MemoryLayer",
    "MemoryEntry",
    "MemoryBackend",
    "InMemoryMemoryBackend",
    "FileBackend",
    "MemoryManager",
    "create_memory_tools",
    "TFIDFScorer",
    "SemanticToolSelector",
    "create_tool_selector",
    "Turn",
    "ConversationState",
    "ConversationManager",
    "create_conversation_task",
    "create_structured_task",
    # Integrations
    "MCPServer",
    "MCPClient",
    "create_mcp_task",
    "ChatAdapter",
    "ChatBot",
    "ChatMessage",
    "FlowNotification",
    "InMemoryAdapter",
    "SlackAdapter",
    "DiscordAdapter",
    "TelegramAdapter",
    "StreamEvent",
    "StreamManager",
    "StreamingFlow",
    "add_streaming_routes",
    # A2A Protocol
    "A2AServer",
    "A2AClient",
    "A2ATask",
    "A2AMessage",
    "AgentCard",
    "AgentSkill",
    "MessagePart",
    "A2ATaskState",
    "create_a2a_task",
    # Plugins
    "PluginRegistry",
    "WaterPlugin",
    "PluginType",
    # Bench
    "BenchmarkCase",
    "BenchmarkResult",
    "Benchmark",
    "BenchmarkRunner",
    "BenchmarkReport",
    "ToolUseBenchmark",
    "InstructionBenchmark",
    # Eval
    "EvalSuite",
    "EvalCase",
    "Evaluator",
    "ExactMatch",
    "ContainsMatch",
    "LLMJudge",
    "SemanticSimilarity",
    "EvalReport",
    "EvalConfig",
    "build_evaluators",
    "build_cases",
    # Guardrails
    "Guardrail",
    "GuardrailResult",
    "GuardrailViolation",
    "GuardrailChain",
    "ContentFilter",
    "SchemaGuardrail",
    "CostGuardrail",
    "TopicGuardrail",
    "RetryWithFeedback",
    "RetryContext",
    # Observability
    "FlowDashboard",
    "TelemetryManager",
    "is_otel_available",
    "TraceCollector",
    "TraceStore",
    "Trace",
    "TraceSpan",
    "StructuredLogger",
    "LogContext",
    "LogExporter",
    "CostTracker",
    "CostSummary",
    "TokenUsage",
    "TaskCost",
    "BudgetExceededError",
    "auto_instrument",
    "AutoInstrumentor",
    "InstrumentationConfig",
    "InstrumentationCollector",
    "SpanRecord",
    # Triggers
    "Trigger",
    "TriggerEvent",
    "WebhookTrigger",
    "CronTrigger",
    "QueueTrigger",
    "TriggerRegistry",
    # Server
    "FlowServer",
    # Utils
    "MockTask",
    "FlowTestRunner",
    "FlowScheduler",
    "ScheduledJob",
    "load_flow_from_dict",
    "load_flow_from_yaml",
    "load_flow_from_json",
    "SecretValue",
    "SecretsManager",
    "EnvSecretsManager",
    # Debug
    "FlowDebugger",
    "Breakpoint",
    "DebugStep",
    # Tasks (Standard Library)
    "http_request",
    "json_transform",
    "map_fields",
    "filter_fields",
    "file_read",
    "file_write",
    "webhook_task",
    "delay",
    "log_task",
    "noop",
]
