"""Auto-generated by bindgen. Do not edit."""
# ruff: noqa: E501, F401, I001
# fmt: off

from __future__ import annotations

from dataclasses import dataclass
from typing import Any, ClassVar, Optional, TYPE_CHECKING, Union

from wasmtime.component import Variant as _WitVariant
from wasmtime.component import VariantCase as _WitVariantCase

from .conversation import ConversationManagerConfig
from .mcp import McpClientConfig
from .messages import ContentBlock, Message, PromptInput
from .models import ModelConfig, ModelParams
from .retry import RetryConfig
from .sessions import SessionManager, StorageError
from .streaming import AgentMetrics, AgentTrace, StreamEvent
from .tools import AgentAsToolConfig, ToolChoice, ToolSpec
from .vended import VendedPlugin, VendedTool


@dataclass(kw_only=True)
class ConcurrentOptions:
    """Concurrent-execution options."""
    max_concurrency: int | None


ToolExecutorStrategy = None | ConcurrentOptions
"""Strategy for executing tool calls emitted in a single assistant turn."""

AttributeValue = str | int | float | bool
"""Scalar attribute value attached to a trace."""

@dataclass(kw_only=True)
class TraceAttribute:
    """Key-value pair attached to every OpenTelemetry span the agent emits.
Distinct from `streaming.trace-metadata-entry`, which is string-only."""
    key: str
    value: AttributeValue


@dataclass(kw_only=True)
class TraceContext:
    """W3C Trace Context headers linking the agent's spans to a caller's trace."""
    traceparent: str
    tracestate: str | None


@dataclass(kw_only=True)
class AgentIdentity:
    """Display-level identity of the agent; all fields default to sensible values."""
    name: str | None
    id: str | None
    description: str | None


@dataclass(kw_only=True)
class AgentConfig:
    """Configuration passed to the `agent` constructor.
Invalid config surfaces on the first `generate` as `invalid-input`."""
    model: ModelConfig | None
    model_params: ModelParams | None
    messages: list[Message] | None
    system_prompt: PromptInput | None
    tools: list[ToolSpec] | None
    agent_tools: list[AgentAsToolConfig] | None
    vended_tools: list[VendedTool] | None
    vended_plugins: list[VendedPlugin] | None
    mcp_clients: list[McpClientConfig] | None
    identity: AgentIdentity | None
    tool_executor: ToolExecutorStrategy | None
    display_output: bool | None
    trace_attributes: list[TraceAttribute] | None
    trace_context: TraceContext | None
    session: SessionManager | None
    conversation_manager: ConversationManagerConfig | None
    retry: RetryConfig | None
    structured_output_schema: str | None
    app_state: str | None
    model_state: str | None


@dataclass(kw_only=True)
class InvokeArgs:
    """Arguments for `agent.generate`."""
    input: PromptInput
    tools: list[ToolSpec] | None
    tool_choice: ToolChoice | None
    structured_output_schema: str | None


@dataclass(kw_only=True)
class RespondArgs:
    """Payload supplied when resuming from a human-in-the-loop interrupt."""
    interrupt_id: str
    response: str


class AgentError:
    """Why an agent-resource call failed."""
    if TYPE_CHECKING:
        NoSessionConfigured: ClassVar[type["_AgentError_NoSessionConfigured"]]
        Storage: ClassVar[type["_AgentError_Storage"]]
        InvalidInput: ClassVar[type["_AgentError_InvalidInput"]]
        UnknownInterrupt: ClassVar[type["_AgentError_UnknownInterrupt"]]
        Internal: ClassVar[type["_AgentError_Internal"]]
        _CASES: ClassVar[dict[str, type]]
        @staticmethod
        def lift(raw: _WitVariant) -> "AgentError": ...

class _AgentError_NoSessionConfigured(_WitVariantCase, AgentError):
    """The agent was constructed without a session config."""
    tag = 'no-session-configured'
AgentError.NoSessionConfigured = _AgentError_NoSessionConfigured  # type: ignore[attr-defined]

class _AgentError_Storage(_WitVariantCase, AgentError):
    """The storage backend rejected the operation."""
    tag = 'storage'
AgentError.Storage = _AgentError_Storage  # type: ignore[attr-defined]

class _AgentError_InvalidInput(_WitVariantCase, AgentError):
    """Supplied payload did not match the expected shape."""
    tag = 'invalid-input'
AgentError.InvalidInput = _AgentError_InvalidInput  # type: ignore[attr-defined]

class _AgentError_UnknownInterrupt(_WitVariantCase, AgentError):
    """Supplied `interrupt-id` does not match any live interrupt."""
    tag = 'unknown-interrupt'
AgentError.UnknownInterrupt = _AgentError_UnknownInterrupt  # type: ignore[attr-defined]

class _AgentError_Internal(_WitVariantCase, AgentError):
    """Catch-all for internal failures."""
    tag = 'internal'
AgentError.Internal = _AgentError_Internal  # type: ignore[attr-defined]

AgentError._CASES = {  # type: ignore[attr-defined]
    'no-session-configured': AgentError.NoSessionConfigured,
    'storage': AgentError.Storage,
    'invalid-input': AgentError.InvalidInput,
    'unknown-interrupt': AgentError.UnknownInterrupt,
    'internal': AgentError.Internal,
}


def _AgentError_lift(raw: _WitVariant) -> AgentError:
    cls = AgentError._CASES.get(raw.tag)  # type: ignore[attr-defined]
    if cls is None:
        raise ValueError(f'unknown AgentError arm: {raw.tag!r}')
    return cls(raw.payload)
AgentError.lift = staticmethod(_AgentError_lift)  # type: ignore[attr-defined]

class Agent:
    """An agent instance. Persistent across `generate` calls."""
    # Wraps a wasmtime-py ResourceAny / ResourceHost handle.
    # The runtime sets ._handle to the underlying resource and
    # ._invoke to a callable that dispatches a method by WIT name.

    def __init__(self, handle: Any, invoke: Any = None) -> None:
        self._handle = handle
        self._invoke = invoke

    @staticmethod
    def new(config: AgentConfig, *, invoke: Any) -> Agent:
        return Agent(invoke('[constructor]agent', (config,)), invoke)

    def generate(self, args: InvokeArgs) -> Any:
        return self._invoke('[method]agent.generate', (self._handle, args,))

    def get_messages(self) -> list[Message]:
        return self._invoke('[method]agent.get-messages', (self._handle,))

    def set_messages(self, messages: list[Message]) -> Any:
        return self._invoke('[method]agent.set-messages', (self._handle, messages,))

    def get_app_state(self) -> str:
        return self._invoke('[method]agent.get-app-state', (self._handle,))

    def set_app_state(self, json: str) -> Any:
        return self._invoke('[method]agent.set-app-state', (self._handle, json,))

    def get_model_state(self) -> str:
        return self._invoke('[method]agent.get-model-state', (self._handle,))

    def set_model_state(self, json: str) -> Any:
        return self._invoke('[method]agent.set-model-state', (self._handle, json,))

    def get_traces(self) -> list[AgentTrace]:
        return self._invoke('[method]agent.get-traces', (self._handle,))

    def get_metrics(self) -> AgentMetrics:
        return self._invoke('[method]agent.get-metrics', (self._handle,))

    def save_session(self) -> Any:
        return self._invoke('[method]agent.save-session', (self._handle,))

    def list_snapshots(self) -> Any:
        return self._invoke('[method]agent.list-snapshots', (self._handle,))

    def delete_session(self) -> Any:
        return self._invoke('[method]agent.delete-session', (self._handle,))


class EventStream:
    """Pull-based stream of agent events; sync-WIT placeholder for `stream<stream-event>`."""
    # Wraps a wasmtime-py ResourceAny / ResourceHost handle.
    # The runtime sets ._handle to the underlying resource and
    # ._invoke to a callable that dispatches a method by WIT name.

    def __init__(self, handle: Any, invoke: Any = None) -> None:
        self._handle = handle
        self._invoke = invoke

    def read(self) -> StreamEvent | None:
        return self._invoke('[method]event-stream.read', (self._handle,))


class ResponseStream:
    """Handle to an in-flight `generate` invocation."""
    # Wraps a wasmtime-py ResourceAny / ResourceHost handle.
    # The runtime sets ._handle to the underlying resource and
    # ._invoke to a callable that dispatches a method by WIT name.

    def __init__(self, handle: Any, invoke: Any = None) -> None:
        self._handle = handle
        self._invoke = invoke

    def events(self) -> Any:
        return self._invoke('[method]response-stream.events', (self._handle,))

    def respond(self, args: RespondArgs) -> Any:
        return self._invoke('[method]response-stream.respond', (self._handle, args,))

    def cancel(self) -> None:
        return self._invoke('[method]response-stream.cancel', (self._handle,))
