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

from __future__ import annotations

from typing import Dict, List, Union, Optional
from typing_extensions import Literal

from .._models import BaseModel

__all__ = ["Response", "MCPServerErrors"]


class MCPServerErrors(BaseModel):
    """Error details for a single MCP server failure."""

    message: str
    """Human-readable error message."""

    code: Optional[str] = None
    """Machine-readable error code."""

    recommendation: Optional[str] = None
    """Suggested action for the user."""


class Response(BaseModel):
    """Responses API response with Dedalus extensions."""

    id: str
    """Unique identifier for this Response"""

    created_at: float
    """Unix timestamp (in seconds) when this Response was created"""

    model: str
    """The model used for this response"""

    output: List["JSONObjectInput"]
    """Array of content items generated by the model"""

    status: Literal["completed", "failed", "in_progress", "cancelled", "queued", "incomplete"]
    """The status of the response generation"""

    background: Optional[bool] = None
    """Whether the request was run in the background"""

    completed_at: Optional[float] = None
    """Unix timestamp (in seconds) when the response was completed"""

    conversation: Optional["JSONObjectInput"] = None
    """Conversation this response belongs to (requires BYOK)"""

    error: Optional["JSONObjectInput"] = None
    """Error details if status is 'failed'"""

    frequency_penalty: Optional[float] = None
    """Frequency penalty used for this response"""

    incomplete_details: Optional[Dict[str, str]] = None
    """
    Details about why the response is incomplete (e.g., max_output_tokens,
    content_filter)
    """

    instructions: Union[str, List["JSONObjectInput"], None] = None
    """System/developer instructions used"""

    max_output_tokens: Optional[int] = None
    """Maximum output tokens allowed for this response"""

    max_tool_calls: Optional[int] = None
    """Maximum tool calls allowed for this response"""

    mcp_server_errors: Optional[Dict[str, MCPServerErrors]] = None
    """MCP server failures keyed by server name."""

    mcp_tool_results: Optional[List["MCPToolResult"]] = None
    """Results of MCP tool executions including inputs, outputs, and timing."""

    metadata: Optional[Dict[str, str]] = None
    """Key-value pairs attached to this response (requires BYOK)"""

    object: Optional[Literal["response"]] = None
    """The object type, always 'response'"""

    output_text: Optional[str] = None
    """
    Aggregated text output from all output_text items (SDK-only convenience
    property)
    """

    parallel_tool_calls: Optional[bool] = None
    """Whether parallel tool calls were enabled"""

    presence_penalty: Optional[float] = None
    """Presence penalty used for this response"""

    previous_response_id: Optional[str] = None
    """Previous response ID referenced, if any"""

    prompt_cache_key: Optional[str] = None
    """Prompt cache key used for this response"""

    reasoning: Optional["JSONObjectInput"] = None
    """Reasoning configuration and outputs"""

    safety_identifier: Optional[str] = None
    """Safety identifier used for this response"""

    service_tier: Optional[str] = None
    """Service tier used for this response"""

    store: Optional[bool] = None
    """Whether the response was stored for later retrieval"""

    temperature: Optional[float] = None
    """Temperature parameter used"""

    text: Optional["JSONObjectInput"] = None
    """Text configuration used for this response"""

    tool_choice: Union[str, "JSONObjectInput", None] = None
    """Tool choice configuration used"""

    tools: Optional[List["JSONObjectInput"]] = None
    """Tools that were available to the model"""

    tools_executed: Optional[List[str]] = None
    """List of tool names that were executed server-side (e.g., MCP tools)."""

    top_logprobs: Optional[int] = None
    """Number of logprob tokens returned per position"""

    top_p: Optional[float] = None
    """Top-p parameter used"""

    truncation: Optional[str] = None
    """Truncation strategy applied when context exceeded limits"""

    usage: Optional["JSONObjectInput"] = None
    """Token usage statistics for the response"""


from .shared.mcp_tool_result import MCPToolResult
from .shared.json_object_input import JSONObjectInput
