"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.""" from __future__ import annotations from .shellcallstatus import ShellCallStatus from functools import partial from openrouter.types import ( BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL, ) from openrouter.utils.unions import parse_open_union from pydantic import ConfigDict, model_serializer from pydantic.functional_validators import BeforeValidator from typing import Any, List, Literal, Union from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict TypeTimeout = Literal["timeout",] class OutcomeTimeoutTypedDict(TypedDict): type: TypeTimeout class OutcomeTimeout(BaseModel): type: TypeTimeout TypeExit = Literal["exit",] class OutcomeExitTypedDict(TypedDict): exit_code: int type: TypeExit class OutcomeExit(BaseModel): exit_code: int type: TypeExit OutcomeTypedDict = TypeAliasType( "OutcomeTypedDict", Union[OutcomeTimeoutTypedDict, OutcomeExitTypedDict] ) class UnknownOutcome(BaseModel): r"""A Outcome 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) _OUTCOME_VARIANTS: dict[str, Any] = { "exit": OutcomeExit, "timeout": OutcomeTimeout, } Outcome = Annotated[ Union[OutcomeExit, OutcomeTimeout, UnknownOutcome], BeforeValidator( partial( parse_open_union, disc_key="type", variants=_OUTCOME_VARIANTS, unknown_cls=UnknownOutcome, union_name="Outcome", ) ), ] class OutputShellCallOutputItemOutputTypedDict(TypedDict): outcome: OutcomeTypedDict stderr: str stdout: str class OutputShellCallOutputItemOutput(BaseModel): outcome: Outcome stderr: str stdout: str OutputShellCallOutputItemTypeShellCallOutput = Literal["shell_call_output",] class OutputShellCallOutputItemTypedDict(TypedDict): r"""A native `shell_call_output` item matching OpenAI's Responses API shape. Carries per-command stdout, stderr, and the exit/timeout outcome.""" call_id: str id: str output: List[OutputShellCallOutputItemOutputTypedDict] status: ShellCallStatus r"""Status of a shell call or its output.""" type: OutputShellCallOutputItemTypeShellCallOutput max_output_length: NotRequired[Nullable[int]] class OutputShellCallOutputItem(BaseModel): r"""A native `shell_call_output` item matching OpenAI's Responses API shape. Carries per-command stdout, stderr, and the exit/timeout outcome.""" call_id: str id: str output: List[OutputShellCallOutputItemOutput] status: ShellCallStatus r"""Status of a shell call or its output.""" type: OutputShellCallOutputItemTypeShellCallOutput max_output_length: OptionalNullable[int] = UNSET @model_serializer(mode="wrap") def serialize_model(self, handler): optional_fields = set(["max_output_length"]) nullable_fields = set(["max_output_length"]) 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