"""Internal type stubs for the compiled AutoAgents bridge module."""

from __future__ import annotations

from typing import AsyncIterator, Awaitable, Callable, Optional, Sequence, Union

from autoagents_py.types import (
    AgentRunResult,
    ChatMessagePayload,
    ExecutorOutput,
    JsonObject,
    JsonValue,
    LLMChatResponse,
    TaskPayload,
)


class LLMBuilder:
    def __init__(self, backend: str) -> None: ...
    def api_key(self, key: str) -> LLMBuilder: ...
    def base_url(self, url: str) -> LLMBuilder: ...
    def model(self, model: str) -> LLMBuilder: ...
    def max_tokens(self, max_tokens: int) -> LLMBuilder: ...
    def temperature(self, temperature: float) -> LLMBuilder: ...
    def top_p(self, top_p: float) -> LLMBuilder: ...
    def top_k(self, top_k: int) -> LLMBuilder: ...
    def timeout_seconds(self, secs: int) -> LLMBuilder: ...
    def reasoning(self, enable: bool) -> LLMBuilder: ...
    def reasoning_effort(self, effort: str) -> LLMBuilder: ...
    def reasoning_budget_tokens(self, tokens: int) -> LLMBuilder: ...
    def normalize_response(self, value: bool) -> LLMBuilder: ...
    def enable_parallel_tool_use(self, value: bool) -> LLMBuilder: ...
    def api_version(self, value: str) -> LLMBuilder: ...
    def deployment_id(self, value: str) -> LLMBuilder: ...
    def extra_body_json(self, json_body: str) -> LLMBuilder: ...
    def build(self) -> LLMProvider: ...


class LLMProvider:
    def __repr__(self) -> str: ...


class ExecutionLLM:
    def __repr__(self) -> str: ...
    async def chat(
        self,
        messages: Union[str, ChatMessagePayload, Sequence[ChatMessagePayload]],
        schema: Optional[Union[str, JsonObject]] = None,
    ) -> LLMChatResponse: ...
    async def chat_with_struct(
        self,
        messages: Union[str, ChatMessagePayload, Sequence[ChatMessagePayload]],
        schema: Union[str, JsonObject],
    ) -> LLMChatResponse: ...
    async def chat_with_tools(
        self,
        messages: Union[str, ChatMessagePayload, Sequence[ChatMessagePayload]],
        tools: Sequence[Tool],
        schema: Optional[Union[str, JsonObject]] = None,
    ) -> LLMChatResponse: ...
    async def chat_with_tools_struct(
        self,
        messages: Union[str, ChatMessagePayload, Sequence[ChatMessagePayload]],
        tools: Sequence[Tool],
        schema: Union[str, JsonObject],
    ) -> LLMChatResponse: ...
    async def chat_with_web_search(self, input: str) -> LLMChatResponse: ...
    async def chat_stream(
        self,
        messages: Union[str, ChatMessagePayload, Sequence[ChatMessagePayload]],
        schema: Optional[Union[str, JsonObject]] = None,
    ) -> AsyncIterator[str]: ...
    async def chat_stream_struct(
        self,
        messages: Union[str, ChatMessagePayload, Sequence[ChatMessagePayload]],
        tools: Optional[Sequence[Tool]] = None,
        schema: Optional[Union[str, JsonObject]] = None,
    ) -> AsyncIterator[JsonObject]: ...
    async def chat_stream_with_tools(
        self,
        messages: Union[str, ChatMessagePayload, Sequence[ChatMessagePayload]],
        tools: Sequence[Tool],
        schema: Optional[Union[str, JsonObject]] = None,
    ) -> AsyncIterator[JsonObject]: ...


class ExecutionMemory:
    def __repr__(self) -> str: ...
    def is_configured(self) -> bool: ...
    async def recall(self, query: str, limit: Optional[int] = None) -> list[ChatMessagePayload]: ...
    async def remember(self, message: Union[str, ChatMessagePayload]) -> None: ...
    async def clear(self) -> None: ...
    async def size(self) -> int: ...


class MemoryProvider:
    def __repr__(self) -> str: ...

def memory_provider_from_impl(memory: object) -> MemoryProvider: ...
def sliding_window_memory(window_size: int) -> MemoryProvider: ...


def pipeline_cache_layer(
    provider: LLMProvider,
    ttl_seconds: Optional[int] = None,
) -> LLMProvider: ...
def pipeline_retry_layer(
    provider: LLMProvider,
    max_attempts: Optional[int] = None,
    initial_backoff_ms: Optional[int] = None,
    max_backoff_ms: Optional[int] = None,
    jitter: Optional[bool] = None,
) -> LLMProvider: ...
def pipeline_python_layer(provider: LLMProvider, layer: object) -> LLMProvider: ...


class Tool:
    def __init__(
        self,
        name: str,
        description: str,
        schema_json: str,
        callable: Union[
            Callable[[JsonObject], object],
            Callable[[JsonObject], Awaitable[object]],
        ],
    ) -> None: ...
    def __repr__(self) -> str: ...


class AgentBuilder:
    def __init__(self, agent: object) -> None: ...
    def llm(self, provider: LLMProvider) -> AgentBuilder: ...
    def memory(self, mem: MemoryProvider) -> AgentBuilder: ...
    def runtime(self, rt: Runtime) -> AgentBuilder: ...
    def subscribe(self, topic: str) -> AgentBuilder: ...
    async def build(self) -> AgentHandle: ...
    async def build_actor(self) -> ActorAgentHandle: ...


class AgentHandle:
    def __repr__(self) -> str: ...
    async def run(self, task: Union[str, TaskPayload]) -> AgentRunResult: ...
    def event_stream(self) -> EventStream: ...
    async def run_stream(self, task: Union[str, TaskPayload]) -> RunStream: ...


class ActorAgentHandle:
    def __repr__(self) -> str: ...
    async def send(self, prompt: str) -> None: ...


class RunStream:
    def __aiter__(self) -> RunStream: ...
    async def __anext__(self) -> ExecutorOutput: ...


class EventStream:
    def __aiter__(self) -> EventStream: ...
    async def __anext__(self) -> JsonObject: ...


class Topic:
    def __init__(self, name: str) -> None: ...
    @property
    def name(self) -> str: ...
    def __repr__(self) -> str: ...


class Runtime:
    def __init__(self) -> None: ...
    async def publish(self, topic: Topic, task: str) -> None: ...
    async def event_stream(self) -> EventStream: ...


class Environment:
    def __init__(self) -> None: ...
    def register_runtime(self, runtime: Runtime) -> None: ...
    def run(self) -> None: ...
    def event_stream(self) -> EventStream: ...
