"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
# @generated-id: 8c8b08d853f6

from __future__ import annotations
from .agenthandoffdoneevent import AgentHandoffDoneEvent, AgentHandoffDoneEventTypedDict
from .agenthandoffstartedevent import (
    AgentHandoffStartedEvent,
    AgentHandoffStartedEventTypedDict,
)
from .functioncallevent import FunctionCallEvent, FunctionCallEventTypedDict
from .messageoutputevent import MessageOutputEvent, MessageOutputEventTypedDict
from .responsedoneevent import ResponseDoneEvent, ResponseDoneEventTypedDict
from .responseerrorevent import ResponseErrorEvent, ResponseErrorEventTypedDict
from .responsestartedevent import ResponseStartedEvent, ResponseStartedEventTypedDict
from .ssetypes import SSETypes
from .toolexecutiondeltaevent import (
    ToolExecutionDeltaEvent,
    ToolExecutionDeltaEventTypedDict,
)
from .toolexecutiondoneevent import (
    ToolExecutionDoneEvent,
    ToolExecutionDoneEventTypedDict,
)
from .toolexecutionstartedevent import (
    ToolExecutionStartedEvent,
    ToolExecutionStartedEventTypedDict,
)
from functools import partial
from mistralai.client.types import BaseModel
from mistralai.client.utils.unions import parse_open_union
from pydantic import ConfigDict
from pydantic.functional_validators import BeforeValidator
from typing import Any, Literal, Union
from typing_extensions import Annotated, TypeAliasType, TypedDict


ConversationEventsDataTypedDict = TypeAliasType(
    "ConversationEventsDataTypedDict",
    Union[
        ResponseStartedEventTypedDict,
        ResponseDoneEventTypedDict,
        ResponseErrorEventTypedDict,
        ToolExecutionDeltaEventTypedDict,
        ToolExecutionDoneEventTypedDict,
        AgentHandoffStartedEventTypedDict,
        AgentHandoffDoneEventTypedDict,
        ToolExecutionStartedEventTypedDict,
        MessageOutputEventTypedDict,
        FunctionCallEventTypedDict,
    ],
)


class UnknownConversationEventsData(BaseModel):
    r"""A ConversationEventsData variant the SDK doesn't recognize. Preserves the raw payload."""

    type: Literal["UNKNOWN"] = "UNKNOWN"
    raw: Any
    is_unknown: Literal[True] = True

    model_config = ConfigDict(frozen=True)


_CONVERSATION_EVENTS_DATA_VARIANTS: dict[str, Any] = {
    "agent.handoff.done": AgentHandoffDoneEvent,
    "agent.handoff.started": AgentHandoffStartedEvent,
    "conversation.response.done": ResponseDoneEvent,
    "conversation.response.error": ResponseErrorEvent,
    "conversation.response.started": ResponseStartedEvent,
    "function.call.delta": FunctionCallEvent,
    "message.output.delta": MessageOutputEvent,
    "tool.execution.delta": ToolExecutionDeltaEvent,
    "tool.execution.done": ToolExecutionDoneEvent,
    "tool.execution.started": ToolExecutionStartedEvent,
}


ConversationEventsData = Annotated[
    Union[
        AgentHandoffDoneEvent,
        AgentHandoffStartedEvent,
        ResponseDoneEvent,
        ResponseErrorEvent,
        ResponseStartedEvent,
        FunctionCallEvent,
        MessageOutputEvent,
        ToolExecutionDeltaEvent,
        ToolExecutionDoneEvent,
        ToolExecutionStartedEvent,
        UnknownConversationEventsData,
    ],
    BeforeValidator(
        partial(
            parse_open_union,
            disc_key="type",
            variants=_CONVERSATION_EVENTS_DATA_VARIANTS,
            unknown_cls=UnknownConversationEventsData,
            union_name="ConversationEventsData",
        )
    ),
]


class ConversationEventsTypedDict(TypedDict):
    event: SSETypes
    r"""Server side events sent when streaming a conversation response."""
    data: ConversationEventsDataTypedDict


class ConversationEvents(BaseModel):
    event: SSETypes
    r"""Server side events sent when streaming a conversation response."""

    data: ConversationEventsData
