# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from __future__ import annotations

from typing import Dict, Union, Iterable
from datetime import datetime
from typing_extensions import Literal, Required, Annotated, TypeAlias, TypedDict

from .._utils import PropertyInfo
from .shared_params.chunk_extra_info_schema import ChunkExtraInfoSchema
from .shared_params.result_schema_generation import ResultSchemaGeneration
from .shared_params.string_extra_info_schema import StringExtraInfoSchema
from .evaluation_datasets.flexible_chunk_param import FlexibleChunkParam
from .evaluation_datasets.flexible_message_param import FlexibleMessageParam

__all__ = [
    "ApplicationTestCaseOutputBatchParams",
    "Item",
    "ItemOutput",
    "ItemOutputResultSchemaFlexible",
    "ItemOutputResultSchemaFlexibleGenerationExtraInfo",
    "ItemTraceSpan",
]


class ApplicationTestCaseOutputBatchParams(TypedDict, total=False):
    items: Required[Iterable[Item]]


ItemOutputResultSchemaFlexibleGenerationExtraInfo: TypeAlias = Union[ChunkExtraInfoSchema, StringExtraInfoSchema]


class ItemOutputResultSchemaFlexible(TypedDict, total=False):
    generation_output: Required[
        Union[
            str,
            float,
            Iterable[FlexibleChunkParam],
            Iterable[FlexibleMessageParam],
            Iterable[object],
            Dict[
                str,
                Union[
                    str, float, Iterable[FlexibleChunkParam], Iterable[FlexibleMessageParam], Iterable[object], object
                ],
            ],
            object,
        ]
    ]

    generation_extra_info: ItemOutputResultSchemaFlexibleGenerationExtraInfo


ItemOutput: TypeAlias = Union[ResultSchemaGeneration, ItemOutputResultSchemaFlexible]


class ItemTraceSpan(TypedDict, total=False):
    node_id: Required[str]
    """Identifier for the node that emitted this trace span."""

    operation_input: Required[
        Dict[
            str,
            Union[str, float, Iterable[FlexibleChunkParam], Iterable[FlexibleMessageParam], Iterable[object], object],
        ]
    ]
    """The JSON representation of the input that this step received."""

    operation_output: Required[
        Dict[
            str,
            Union[str, float, Iterable[FlexibleChunkParam], Iterable[FlexibleMessageParam], Iterable[object], object],
        ]
    ]
    """The JSON representation of the output that this step emitted."""

    start_timestamp: Required[Annotated[Union[str, datetime], PropertyInfo(format="iso8601")]]
    """The start time of the step."""

    duration_ms: int
    """The duration of the operation step in milliseconds."""

    operation_expected: Dict[
        str, Union[str, float, Iterable[FlexibleChunkParam], Iterable[FlexibleMessageParam], Iterable[object], object]
    ]
    """The JSON representation of the expected output for this step"""

    operation_metadata: object
    """The JSON representation of the metadata insights emitted during execution.

    This can differ based on different types of operations.
    """

    operation_status: Literal["SUCCESS", "ERROR"]
    """Enum representing the status of an operation."""

    operation_type: Literal["COMPLETION", "RERANKING", "RETRIEVAL", "CUSTOM"]
    """Enum representing the type of operation performed."""


class Item(TypedDict, total=False):
    account_id: Required[str]
    """The ID of the account that owns the given entity."""

    application_variant_id: Required[str]

    evaluation_dataset_version_num: Required[int]

    output: Required[ItemOutput]

    test_case_id: Required[str]

    application_interaction_id: str

    metrics: Dict[str, float]

    trace_spans: Iterable[ItemTraceSpan]
    """List of trace spans associated with the application's execution.

    These spans provide insight into the individual steps taken by nodes involved in
    generating the output.
    """
