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