main
  1# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
  2
  3from typing import Dict, List, Union, Optional
  4from typing_extensions import Literal, Annotated, TypeAlias
  5
  6from ..._utils import PropertyInfo
  7from ..._models import BaseModel
  8from .response_output_message import ResponseOutputMessage
  9from .response_computer_tool_call import ResponseComputerToolCall
 10from .response_input_message_item import ResponseInputMessageItem
 11from .response_function_web_search import ResponseFunctionWebSearch
 12from .response_apply_patch_tool_call import ResponseApplyPatchToolCall
 13from .response_file_search_tool_call import ResponseFileSearchToolCall
 14from .response_function_tool_call_item import ResponseFunctionToolCallItem
 15from .response_function_shell_tool_call import ResponseFunctionShellToolCall
 16from .response_code_interpreter_tool_call import ResponseCodeInterpreterToolCall
 17from .response_apply_patch_tool_call_output import ResponseApplyPatchToolCallOutput
 18from .response_computer_tool_call_output_item import ResponseComputerToolCallOutputItem
 19from .response_function_tool_call_output_item import ResponseFunctionToolCallOutputItem
 20from .response_function_shell_tool_call_output import ResponseFunctionShellToolCallOutput
 21
 22__all__ = [
 23    "ResponseItem",
 24    "ImageGenerationCall",
 25    "LocalShellCall",
 26    "LocalShellCallAction",
 27    "LocalShellCallOutput",
 28    "McpListTools",
 29    "McpListToolsTool",
 30    "McpApprovalRequest",
 31    "McpApprovalResponse",
 32    "McpCall",
 33]
 34
 35
 36class ImageGenerationCall(BaseModel):
 37    id: str
 38    """The unique ID of the image generation call."""
 39
 40    result: Optional[str] = None
 41    """The generated image encoded in base64."""
 42
 43    status: Literal["in_progress", "completed", "generating", "failed"]
 44    """The status of the image generation call."""
 45
 46    type: Literal["image_generation_call"]
 47    """The type of the image generation call. Always `image_generation_call`."""
 48
 49
 50class LocalShellCallAction(BaseModel):
 51    command: List[str]
 52    """The command to run."""
 53
 54    env: Dict[str, str]
 55    """Environment variables to set for the command."""
 56
 57    type: Literal["exec"]
 58    """The type of the local shell action. Always `exec`."""
 59
 60    timeout_ms: Optional[int] = None
 61    """Optional timeout in milliseconds for the command."""
 62
 63    user: Optional[str] = None
 64    """Optional user to run the command as."""
 65
 66    working_directory: Optional[str] = None
 67    """Optional working directory to run the command in."""
 68
 69
 70class LocalShellCall(BaseModel):
 71    id: str
 72    """The unique ID of the local shell call."""
 73
 74    action: LocalShellCallAction
 75    """Execute a shell command on the server."""
 76
 77    call_id: str
 78    """The unique ID of the local shell tool call generated by the model."""
 79
 80    status: Literal["in_progress", "completed", "incomplete"]
 81    """The status of the local shell call."""
 82
 83    type: Literal["local_shell_call"]
 84    """The type of the local shell call. Always `local_shell_call`."""
 85
 86
 87class LocalShellCallOutput(BaseModel):
 88    id: str
 89    """The unique ID of the local shell tool call generated by the model."""
 90
 91    output: str
 92    """A JSON string of the output of the local shell tool call."""
 93
 94    type: Literal["local_shell_call_output"]
 95    """The type of the local shell tool call output. Always `local_shell_call_output`."""
 96
 97    status: Optional[Literal["in_progress", "completed", "incomplete"]] = None
 98    """The status of the item. One of `in_progress`, `completed`, or `incomplete`."""
 99
100
101class McpListToolsTool(BaseModel):
102    input_schema: object
103    """The JSON schema describing the tool's input."""
104
105    name: str
106    """The name of the tool."""
107
108    annotations: Optional[object] = None
109    """Additional annotations about the tool."""
110
111    description: Optional[str] = None
112    """The description of the tool."""
113
114
115class McpListTools(BaseModel):
116    id: str
117    """The unique ID of the list."""
118
119    server_label: str
120    """The label of the MCP server."""
121
122    tools: List[McpListToolsTool]
123    """The tools available on the server."""
124
125    type: Literal["mcp_list_tools"]
126    """The type of the item. Always `mcp_list_tools`."""
127
128    error: Optional[str] = None
129    """Error message if the server could not list tools."""
130
131
132class McpApprovalRequest(BaseModel):
133    id: str
134    """The unique ID of the approval request."""
135
136    arguments: str
137    """A JSON string of arguments for the tool."""
138
139    name: str
140    """The name of the tool to run."""
141
142    server_label: str
143    """The label of the MCP server making the request."""
144
145    type: Literal["mcp_approval_request"]
146    """The type of the item. Always `mcp_approval_request`."""
147
148
149class McpApprovalResponse(BaseModel):
150    id: str
151    """The unique ID of the approval response"""
152
153    approval_request_id: str
154    """The ID of the approval request being answered."""
155
156    approve: bool
157    """Whether the request was approved."""
158
159    type: Literal["mcp_approval_response"]
160    """The type of the item. Always `mcp_approval_response`."""
161
162    reason: Optional[str] = None
163    """Optional reason for the decision."""
164
165
166class McpCall(BaseModel):
167    id: str
168    """The unique ID of the tool call."""
169
170    arguments: str
171    """A JSON string of the arguments passed to the tool."""
172
173    name: str
174    """The name of the tool that was run."""
175
176    server_label: str
177    """The label of the MCP server running the tool."""
178
179    type: Literal["mcp_call"]
180    """The type of the item. Always `mcp_call`."""
181
182    approval_request_id: Optional[str] = None
183    """
184    Unique identifier for the MCP tool call approval request. Include this value in
185    a subsequent `mcp_approval_response` input to approve or reject the
186    corresponding tool call.
187    """
188
189    error: Optional[str] = None
190    """The error from the tool call, if any."""
191
192    output: Optional[str] = None
193    """The output from the tool call."""
194
195    status: Optional[Literal["in_progress", "completed", "incomplete", "calling", "failed"]] = None
196    """The status of the tool call.
197
198    One of `in_progress`, `completed`, `incomplete`, `calling`, or `failed`.
199    """
200
201
202ResponseItem: TypeAlias = Annotated[
203    Union[
204        ResponseInputMessageItem,
205        ResponseOutputMessage,
206        ResponseFileSearchToolCall,
207        ResponseComputerToolCall,
208        ResponseComputerToolCallOutputItem,
209        ResponseFunctionWebSearch,
210        ResponseFunctionToolCallItem,
211        ResponseFunctionToolCallOutputItem,
212        ImageGenerationCall,
213        ResponseCodeInterpreterToolCall,
214        LocalShellCall,
215        LocalShellCallOutput,
216        ResponseFunctionShellToolCall,
217        ResponseFunctionShellToolCallOutput,
218        ResponseApplyPatchToolCall,
219        ResponseApplyPatchToolCallOutput,
220        McpListTools,
221        McpApprovalRequest,
222        McpApprovalResponse,
223        McpCall,
224    ],
225    PropertyInfo(discriminator="type"),
226]