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

from __future__ import annotations
from .codeinterpretertool import CodeInterpreterTool, CodeInterpreterToolTypedDict
from .completionargs import CompletionArgs, CompletionArgsTypedDict
from .conversationinputs import ConversationInputs, ConversationInputsTypedDict
from .customconnector import CustomConnector, CustomConnectorTypedDict
from .documentlibrarytool import DocumentLibraryTool, DocumentLibraryToolTypedDict
from .functiontool import FunctionTool, FunctionToolTypedDict
from .guardrailconfig import GuardrailConfig, GuardrailConfigTypedDict
from .imagegenerationtool import ImageGenerationTool, ImageGenerationToolTypedDict
from .metadatadict import MetadataDict, MetadataDictTypedDict
from .websearchpremiumtool import WebSearchPremiumTool, WebSearchPremiumToolTypedDict
from .websearchtool import WebSearchTool, WebSearchToolTypedDict
from mistralai.client.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from mistralai.client.utils import validate_const
import pydantic
from pydantic import Field, model_serializer
from pydantic.functional_validators import AfterValidator
from typing import List, Literal, Optional, Union
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict


ConversationStreamRequestHandoffExecution = Literal[
    "client",
    "server",
]


ConversationStreamRequestToolTypedDict = TypeAliasType(
    "ConversationStreamRequestToolTypedDict",
    Union[
        FunctionToolTypedDict,
        WebSearchToolTypedDict,
        WebSearchPremiumToolTypedDict,
        CodeInterpreterToolTypedDict,
        ImageGenerationToolTypedDict,
        DocumentLibraryToolTypedDict,
        CustomConnectorTypedDict,
    ],
)


ConversationStreamRequestTool = Annotated[
    Union[
        CodeInterpreterTool,
        CustomConnector,
        DocumentLibraryTool,
        FunctionTool,
        ImageGenerationTool,
        WebSearchTool,
        WebSearchPremiumTool,
    ],
    Field(discriminator="type"),
]


ConversationStreamRequestAgentVersionTypedDict = TypeAliasType(
    "ConversationStreamRequestAgentVersionTypedDict", Union[str, int]
)


ConversationStreamRequestAgentVersion = TypeAliasType(
    "ConversationStreamRequestAgentVersion", Union[str, int]
)


class ConversationStreamRequestTypedDict(TypedDict):
    inputs: ConversationInputsTypedDict
    stream: Literal[True]
    store: NotRequired[Nullable[bool]]
    handoff_execution: NotRequired[Nullable[ConversationStreamRequestHandoffExecution]]
    instructions: NotRequired[Nullable[str]]
    tools: NotRequired[Nullable[List[ConversationStreamRequestToolTypedDict]]]
    completion_args: NotRequired[Nullable[CompletionArgsTypedDict]]
    guardrails: NotRequired[Nullable[List[GuardrailConfigTypedDict]]]
    name: NotRequired[Nullable[str]]
    description: NotRequired[Nullable[str]]
    metadata: NotRequired[Nullable[MetadataDictTypedDict]]
    agent_id: NotRequired[Nullable[str]]
    agent_version: NotRequired[Nullable[ConversationStreamRequestAgentVersionTypedDict]]
    model: NotRequired[Nullable[str]]


class ConversationStreamRequest(BaseModel):
    inputs: ConversationInputs

    stream: Annotated[
        Annotated[Optional[Literal[True]], AfterValidator(validate_const(True))],
        pydantic.Field(alias="stream"),
    ] = True

    store: OptionalNullable[bool] = UNSET

    handoff_execution: OptionalNullable[ConversationStreamRequestHandoffExecution] = (
        UNSET
    )

    instructions: OptionalNullable[str] = UNSET

    tools: OptionalNullable[List[ConversationStreamRequestTool]] = UNSET

    completion_args: OptionalNullable[CompletionArgs] = UNSET

    guardrails: OptionalNullable[List[GuardrailConfig]] = UNSET

    name: OptionalNullable[str] = UNSET

    description: OptionalNullable[str] = UNSET

    metadata: OptionalNullable[MetadataDict] = UNSET

    agent_id: OptionalNullable[str] = UNSET

    agent_version: OptionalNullable[ConversationStreamRequestAgentVersion] = UNSET

    model: OptionalNullable[str] = UNSET

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "stream",
                "store",
                "handoff_execution",
                "instructions",
                "tools",
                "completion_args",
                "guardrails",
                "name",
                "description",
                "metadata",
                "agent_id",
                "agent_version",
                "model",
            ]
        )
        nullable_fields = set(
            [
                "store",
                "handoff_execution",
                "instructions",
                "tools",
                "completion_args",
                "guardrails",
                "name",
                "description",
                "metadata",
                "agent_id",
                "agent_version",
                "model",
            ]
        )
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k, serialized.get(n))
            is_nullable_and_explicitly_set = (
                k in nullable_fields
                and (self.__pydantic_fields_set__.intersection({n}))  # pylint: disable=no-member
            )

            if val != UNSET_SENTINEL:
                if (
                    val is not None
                    or k not in optional_fields
                    or is_nullable_and_explicitly_set
                ):
                    m[k] = val

        return m


try:
    ConversationStreamRequest.model_rebuild()
except NameError:
    pass
