Skip to content

Commit 14613d0

Browse files
committed
Add gpt-5.1, shell and apply_patch tools
1 parent d2c4436 commit 14613d0

File tree

6 files changed

+314
-5
lines changed

6 files changed

+314
-5
lines changed

src/Models/Config.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ import MetaCodable
88
///
99
/// Reducing reasoning effort can result in faster responses and fewer tokens used on reasoning in a response.
1010
public enum Effort: String, CaseIterable, Equatable, Hashable, Codable, Sendable {
11-
case low
12-
case high
13-
case medium
14-
case minimal
11+
case none, minimal, low, medium, high
1512
}
1613

1714
/// A summary of the reasoning performed by the model.
@@ -149,6 +146,11 @@ public enum Order: String, Equatable, Hashable, Codable, Sendable {
149146
case desc
150147
}
151148

149+
public enum CacheRetention: String, Equatable, Hashable, Codable, Sendable {
150+
case `24h`
151+
case inMemory = "in_memory"
152+
}
153+
152154
public extension TextConfig.Format {
153155
/// JSON Schema response format. Used to generate structured JSON responses. Learn more about [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs).
154156
/// - Parameter schemable: A type conforming to `Schemable`, which provides the schema for the response format.

src/Models/Item.swift

Lines changed: 266 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,22 @@ import MetaCodable
7070
@CodedAs("local_shell_call_output")
7171
case localShellCallOutput(Item.LocalShellCallOutput)
7272

73+
/// A tool call representing a request to execute one or more shell commands.
74+
@CodedAs("shell_call")
75+
case shellCall(Item.ShellCall)
76+
77+
/// The streamed output items emitted by a function shell tool call.
78+
@CodedAs("shell_call_output")
79+
case shellCallOutput(Item.ShellCallOutput)
80+
81+
/// A tool call representing a request to create, delete, or update files using diff patches.
82+
@CodedAs("apply_patch_call")
83+
case applyPatchCall(Item.ApplyPatchCall)
84+
85+
/// The streamed output emitted by an apply patch tool call.
86+
@CodedAs("apply_patch_call_output")
87+
case applyPatchCallOutput(Item.ApplyPatchCallOutput)
88+
7389
/// A list of tools available on an MCP server.
7490
@CodedAs("mcp_list_tools")
7591
case mcpListTools(Item.MCPListTools)
@@ -226,6 +242,22 @@ import MetaCodable
226242
@CodedAs("local_shell_call")
227243
case localShellCall(Item.LocalShellCall)
228244

245+
/// A tool call representing a request to execute one or more shell commands.
246+
@CodedAs("shell_call")
247+
case shellCall(Item.ShellCall)
248+
249+
/// The streamed output items emitted by a function shell tool call.
250+
@CodedAs("shell_call_output")
251+
case shellCallOutput(Item.ShellCallOutput)
252+
253+
/// A tool call representing a request to create, delete, or update files using diff patches.
254+
@CodedAs("apply_patch_call")
255+
case applyPatchCall(Item.ApplyPatchCall)
256+
257+
/// The streamed output emitted by an apply patch tool call.
258+
@CodedAs("apply_patch_call_output")
259+
case applyPatchCallOutput(Item.ApplyPatchCallOutput)
260+
229261
/// An invocation of a tool on an MCP server.
230262
@CodedAs("mcp_call")
231263
case mcpToolCall(Item.MCPToolCall)
@@ -249,18 +281,22 @@ import MetaCodable
249281
/// A unique ID for this item.
250282
public var id: String {
251283
switch self {
284+
case let .shellCall(call): call.id
252285
case let .fileSearch(call): call.id
253286
case let .mcpToolCall(call): call.id
254287
case let .message(message): message.id
255288
case let .webSearchCall(call): call.id
289+
case let .applyPatchCall(call): call.id
256290
case let .mcpListTools(tools): tools.id
291+
case let .shellCallOutput(call): call.id
257292
case let .functionCall(call): call.callId
258293
case let .customToolCall(call): call.callId
259294
case let .localShellCall(call): call.callId
260295
case let .reasoning(reasoning): reasoning.id
261296
case let .imageGenerationCall(call): call.id
262297
case let .codeInterpreterCall(call): call.id
263298
case let .computerToolCall(call): call.callId
299+
case let .applyPatchCallOutput(call): call.id
264300
case let .mcpApprovalRequest(request): request.id
265301
case let .customToolCallOutput(call): call.callId
266302
}
@@ -1224,8 +1260,237 @@ import MetaCodable
12241260
}
12251261
}
12261262

1227-
case output(Output)
1263+
/// A tool call that executes one or more shell commands in a managed environment.
1264+
@Codable @CodingKeys(.snake_case) public struct ShellCall: Equatable, Hashable, Sendable {
1265+
/// The status of the function shell tool call.
1266+
public enum Status: String, CaseIterable, Equatable, Hashable, Codable, Sendable {
1267+
case completed, incomplete
1268+
case inProgress = "in_progress"
1269+
}
1270+
1271+
/// The shell commands and limits that describe how to run the tool call.
1272+
@Codable @CodingKeys(.snake_case) public struct Action: Equatable, Hashable, Sendable {
1273+
/// The shell commands to run.
1274+
public var commands: [String]
1275+
1276+
/// Optional maximum number of characters to return from each command.
1277+
public var maxOutputLength: UInt?
1278+
1279+
/// Optional timeout in milliseconds for the commands.
1280+
public var timeout: TimeInterval?
1281+
1282+
/// Creates a new action to run shell commands.
1283+
/// - Parameter commands: The shell commands to run.
1284+
/// - Parameter maxOutputLength: Optional maximum number of characters to return from each command.
1285+
/// - Parameter timeout: Optional timeout in milliseconds for the commands.
1286+
public init(commands: [String], maxOutputLength: UInt? = nil, timeout: TimeInterval? = nil) {
1287+
self.timeout = timeout
1288+
self.commands = commands
1289+
self.maxOutputLength = maxOutputLength
1290+
}
1291+
}
1292+
1293+
/// The unique ID of the function shell tool call.
1294+
public var id: String
1295+
1296+
/// The unique ID of the function shell tool call generated by the model.
1297+
public var callId: String
1298+
1299+
/// The status of the shell call.
1300+
public var status: Status
1301+
1302+
/// The ID of the entity that created this tool call.
1303+
public var createdBy: String?
1304+
1305+
/// The shell commands and limits that describe how to run the tool call.
1306+
public var action: Action
1307+
1308+
/// Creates a new function shell tool call.
1309+
/// - Parameter id: The unique ID of the function shell tool call.
1310+
/// - Parameter callId: The unique ID of the function shell tool call generated by the model.
1311+
/// - Parameter status: The status of the shell call.
1312+
/// - Parameter createdBy: The ID of the entity that created this tool call.
1313+
/// - Parameter action: The shell commands and limits that describe how to run the tool call.
1314+
public init(id: String, callId: String, status: Status, createdBy: String? = nil, action: Action) {
1315+
self.id = id
1316+
self.callId = callId
1317+
self.status = status
1318+
self.action = action
1319+
self.createdBy = createdBy
1320+
}
1321+
}
1322+
1323+
/// The output of a shell tool call.
1324+
@Codable @CodingKeys(.snake_case) public struct ShellCallOutput: Equatable, Hashable, Sendable {
1325+
/// The content of a shell call output.
1326+
@Codable @CodingKeys(.snake_case) public struct Output: Equatable, Hashable, Sendable {
1327+
@Codable @CodedAt("type") @CodingKeys(.snake_case) public enum Outcome: Equatable, Hashable, Sendable {
1328+
/// Indicates that the function shell call exceeded its configured time limit.
1329+
case timeout
1330+
1331+
/// Indicates that the shell commands finished and returned an exit code.
1332+
/// - Parameter exitCode: Exit code from the shell process.
1333+
case exit(exitCode: Int)
1334+
}
1335+
1336+
/// Represents either an exit outcome (with an exit code) or a timeout outcome for a shell call output chunk.
1337+
public var outcome: Outcome
1338+
1339+
/// The standard error output from the shell command.
1340+
public var stderr: String
1341+
1342+
/// The standard output from the shell command.
1343+
public var stdout: String
1344+
1345+
/// The ID of the entity that created this tool call.
1346+
public var createdBy: String?
1347+
1348+
/// Creates a new shell call output.
1349+
///
1350+
/// - Parameter outcome: Represents either an exit outcome (with an exit code) or a timeout outcome for a shell call output chunk.
1351+
/// - Parameter stderr: The standard error output from the shell command.
1352+
/// - Parameter stdout: The standard output from the shell command.
1353+
/// - Parameter createdBy: The ID of the entity that created this tool call.
1354+
public init(outcome: Outcome, stderr: String, stdout: String, createdBy: String? = nil) {
1355+
self.outcome = outcome
1356+
self.stderr = stderr
1357+
self.stdout = stdout
1358+
self.createdBy = createdBy
1359+
}
1360+
}
1361+
1362+
/// The unique ID of the shell call output.
1363+
public var id: String
1364+
1365+
/// The unique ID of the shell tool call generated by the model.
1366+
public var callId: String
1367+
1368+
/// The ID of the entity that created this tool call.
1369+
public var createdBy: String?
1370+
1371+
/// The maximum length of the shell command output.
1372+
///
1373+
/// This is generated by the model and should be passed back with the raw output.
1374+
public var maxOutputLength: UInt?
1375+
1376+
/// An array of shell call output contents
1377+
public var output: [Output]
1378+
1379+
/// Creates a new shell tool call output.
1380+
///
1381+
/// - Parameter id: The unique ID of the shell call output.
1382+
/// - Parameter callId: The unique ID of the shell tool call generated by the model.
1383+
/// - Parameter createdBy: The ID of the entity that created this tool call.
1384+
/// - Parameter maxOutputLength: The maximum length of the shell command output.
1385+
/// - Parameter output: An array of shell call output contents.
1386+
public init(id: String, callId: String, createdBy: String? = nil, maxOutputLength: UInt? = nil, output: [Output]) {
1387+
self.id = id
1388+
self.callId = callId
1389+
self.createdBy = createdBy
1390+
self.maxOutputLength = maxOutputLength
1391+
self.output = output
1392+
}
1393+
}
1394+
1395+
/// A tool call that applies file diffs by creating, deleting, or updating files.
1396+
@Codable @CodingKeys(.snake_case) public struct ApplyPatchCall: Equatable, Hashable, Sendable {
1397+
/// The status of the apply patch tool call.
1398+
public enum Status: String, CaseIterable, Equatable, Hashable, Codable, Sendable {
1399+
case completed
1400+
case inProgress = "in_progress"
1401+
}
1402+
1403+
@Codable @CodedAt("type") @CodingKeys(.snake_case) public enum Operation: Equatable, Hashable, Sendable {
1404+
/// Create a new file with the provided diff.
1405+
///
1406+
/// - Parameter path: Path of the file to create.
1407+
/// - Parameter diff: Diff to apply.
1408+
@CodedAs("create_file")
1409+
case create(path: String, diff: String)
1410+
1411+
/// Delete the specified file.
1412+
///
1413+
/// - Parameter path: Path of the file to delete.
1414+
@CodedAs("delete_file")
1415+
case delete
1416+
1417+
/// Update an existing file with the provided diff.
1418+
///
1419+
/// - Parameter path: Path of the file to update.
1420+
/// - Parameter diff: Diff to apply.
1421+
@CodedAs("update_file")
1422+
case update(path: String, diff: String)
1423+
}
1424+
1425+
/// The unique ID of the apply patch tool call.
1426+
public var id: String
1427+
1428+
/// The unique ID of the apply patch tool call generated by the model.
1429+
public var callId: String
1430+
1431+
/// The status of the apply patch tool call.
1432+
public var status: Status
1433+
1434+
/// The ID of the entity that created this tool call.
1435+
public var createdBy: String?
1436+
1437+
/// The operation to apply.
1438+
public var operation: Operation
1439+
1440+
/// Creates a new apply patch tool call.
1441+
/// - Parameter id: The unique ID of the apply patch tool call.
1442+
/// - Parameter callId: The unique ID of the apply patch tool call generated by the model.
1443+
/// - Parameter status: The status of the apply patch tool call.
1444+
/// - Parameter createdBy: The ID of the entity that created this tool call.
1445+
/// - Parameter operation: The operation to apply.
1446+
public init(id: String, callId: String, status: Status, createdBy: String? = nil, operation: Operation) {
1447+
self.id = id
1448+
self.callId = callId
1449+
self.status = status
1450+
self.createdBy = createdBy
1451+
self.operation = operation
1452+
}
1453+
}
1454+
1455+
/// The output emitted by an apply patch tool call.
1456+
@Codable @CodingKeys(.snake_case) public struct ApplyPatchCallOutput: Equatable, Hashable, Sendable {
1457+
/// The status of the apply patch tool call output.
1458+
public enum Status: String, CaseIterable, Equatable, Hashable, Codable, Sendable {
1459+
case completed, failed
1460+
}
1461+
1462+
/// The unique ID of the apply patch tool call output.
1463+
public var id: String
1464+
1465+
/// The unique ID of the apply patch tool call generated by the model.
1466+
public var callId: String
1467+
1468+
/// The status of the apply patch tool call.
1469+
public var status: Status
1470+
1471+
/// The ID of the entity that created this tool call output.
1472+
public var createdBy: String?
1473+
1474+
/// Optional textual output returned by the apply patch tool.
1475+
public var operation: String?
1476+
1477+
/// Creates a new apply patch tool call output.
1478+
/// - Parameter id: The unique ID of the apply patch tool call output.
1479+
/// - Parameter callId: The unique ID of the apply patch tool call generated by the model.
1480+
/// - Parameter status: The status of the apply patch tool call.
1481+
/// - Parameter createdBy: The ID of the entity that created this tool call output.
1482+
/// - Parameter operation: Optional textual output returned by the apply patch tool.
1483+
public init(id: String, callId: String, status: Status, createdBy: String? = nil, operation: String? = nil) {
1484+
self.id = id
1485+
self.callId = callId
1486+
self.status = status
1487+
self.createdBy = createdBy
1488+
self.operation = operation
1489+
}
1490+
}
1491+
12281492
case input(Input)
1493+
case output(Output)
12291494
}
12301495

12311496
// MARK: - Item.Input Creating helpers

src/Models/Model.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ public enum Model: Equatable, Hashable, Sendable {
1717
case gpt5Mini
1818
case gpt5Nano
1919
case gpt5Codex
20+
case gpt5CodexMini
21+
case gpt51
22+
case gpt51Mini
23+
case gpt51Codex
24+
case gpt51CodexMini
2025
case gpt4_5Preview
2126
case gpt4o
2227
case chatGPT4o
@@ -38,6 +43,10 @@ public enum Model: Equatable, Hashable, Sendable {
3843
case .gpt5Pro: "gpt-5-pro"
3944
case .gpt5Mini: "gpt-5-mini"
4045
case .gpt5Nano: "gpt-5-nano"
46+
case .gpt51: "gpt-5.1"
47+
case .gpt51Mini: "gpt-5.1-mini"
48+
case .gpt51Codex: "gpt-5.1-codex"
49+
case .gpt51CodexMini: "gpt-5.1-codex-mini"
4150
case .gpt4: "gpt-4"
4251
case .o3Pro: "o3-pro"
4352
case .o1Pro: "o1-pro"
@@ -49,6 +58,7 @@ public enum Model: Equatable, Hashable, Sendable {
4958
case .codexMini: "codex-mini"
5059
case let .other(value): value
5160
case .gpt5Codex: "gpt-5-codex"
61+
case .gpt5CodexMini: "gpt-5-codex-mini"
5262
case .gpt4oMini: "gpt-4o-mini"
5363
case .gpt4Turbo: "gpt-4o-turbo"
5464
case .gpt4_1Nano: "gpt-4.1-nano"
@@ -72,6 +82,7 @@ public enum Model: Equatable, Hashable, Sendable {
7282
case "gpt-4o": self = .gpt4o
7383
case "o1-pro": self = .o1Pro
7484
case "o3-pro": self = .o3Pro
85+
case "gpt-5.1": self = .gpt51
7586
case "o1-mini": self = .o1Mini
7687
case "o3-mini": self = .o3Mini
7788
case "o4-mini": self = .o4Mini
@@ -82,13 +93,17 @@ public enum Model: Equatable, Hashable, Sendable {
8293
case "codex-mini": self = .codexMini
8394
case "gpt-5-codex": self = .gpt5Codex
8495
case "gpt-4o-mini": self = .gpt4oMini
96+
case "gpt-5.1-mini": self = .gpt51Mini
8597
case "gpt-4o-turbo": self = .gpt4Turbo
8698
case "gpt-4.1-nano": self = .gpt4_1Nano
8799
case "gpt-4.1-mini": self = .gpt4_1Mini
100+
case "gpt-5.1-codex": self = .gpt51Codex
88101
case "gpt-3.5-turbo": self = .gpt3_5Turbo
89102
case "chatgpt-4o-latest": self = .chatGPT4o
90103
case "gpt-4.5-preview": self = .gpt4_5Preview
104+
case "gpt-5-codex-mini": self = .gpt5CodexMini
91105
case "o3-deep-research": self = .o3DeepResearch
106+
case "gpt-5.1-codex-mini": self = .gpt51CodexMini
92107
case "computer-use-preview": self = .computerUsePreview
93108
case "o4-mini-deep-research": self = .o4MiniDeepResearch
94109
default: self = .other(model)

0 commit comments

Comments
 (0)