"""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, Optional, 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."""

    class NoSessionConfigured(_WitVariantCase):
        """The agent was constructed without a session config."""
        tag = 'no-session-configured'

    class Storage(_WitVariantCase):
        """The storage backend rejected the operation."""
        tag = 'storage'

    class InvalidInput(_WitVariantCase):
        """Supplied payload did not match the expected shape."""
        tag = 'invalid-input'

    class UnknownInterrupt(_WitVariantCase):
        """Supplied `interrupt-id` does not match any live interrupt."""
        tag = 'unknown-interrupt'

    class Internal(_WitVariantCase):
        """Catch-all for internal failures."""
        tag = 'internal'

    _CASES: dict[str, type] = {
        'no-session-configured': NoSessionConfigured,
        'storage': Storage,
        'invalid-input': InvalidInput,
        'unknown-interrupt': UnknownInterrupt,
        'internal': Internal,
    }

    @staticmethod
    def lift(raw: _WitVariant) -> AgentError:
        cls = AgentError._CASES.get(raw.tag)
        if cls is None:
            raise ValueError(f'unknown AgentError arm: {raw.tag!r}')
        return cls(raw.payload)

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,))
