codexwire-protocol 0.1.0

Generated serde types for the OpenAI Codex app-server JSON-RPC protocol
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
// @generated by scripts/gen-codex-protocol from
// schema/ (codex 0.167.0). Do not edit.

use alloc::collections::BTreeMap;

use serde::{Deserialize, Serialize, de::DeserializeOwned};
use serde_json::Value;

/// The Codex version this schema came from (`codex --version`).
pub const CODEX_VERSION: &str = "0.167.0";

/// A client request: its method name and response type.
pub trait Request: Serialize {
    const METHOD: &'static str;
    type Response: DeserializeOwned;
}

/// A server notification: its method name.
pub trait Notification: DeserializeOwned {
    const METHOD: &'static str;
}

/// A server-to-client request: its method name and response type.
pub trait ServerRequest: DeserializeOwned {
    const METHOD: &'static str;
    type Response: Serialize;
}

impl Request for InitializeParams {
    const METHOD: &'static str = "initialize";
    type Response = InitializeResponse;
}
impl Request for ThreadStartParams {
    const METHOD: &'static str = "thread/start";
    type Response = ThreadStartResponse;
}
impl Request for ThreadResumeParams {
    const METHOD: &'static str = "thread/resume";
    type Response = ThreadResumeResponse;
}
impl Request for TurnStartParams {
    const METHOD: &'static str = "turn/start";
    type Response = TurnStartResponse;
}
impl Request for TurnInterruptParams {
    const METHOD: &'static str = "turn/interrupt";
    type Response = TurnInterruptResponse;
}
impl Notification for ErrorNotification {
    const METHOD: &'static str = "error";
}
impl Notification for ThreadStartedNotification {
    const METHOD: &'static str = "thread/started";
}
impl Notification for TurnStartedNotification {
    const METHOD: &'static str = "turn/started";
}
impl Notification for TurnCompletedNotification {
    const METHOD: &'static str = "turn/completed";
}
impl Notification for ItemStartedNotification {
    const METHOD: &'static str = "item/started";
}
impl Notification for ItemCompletedNotification {
    const METHOD: &'static str = "item/completed";
}
impl Notification for AgentMessageDeltaNotification {
    const METHOD: &'static str = "item/agentMessage/delta";
}
impl Notification for ThreadTokenUsageUpdatedNotification {
    const METHOD: &'static str = "thread/tokenUsage/updated";
}
impl Notification for AccountRateLimitsUpdatedNotification {
    const METHOD: &'static str = "account/rateLimits/updated";
}
impl ServerRequest for CommandExecutionRequestApprovalParams {
    const METHOD: &'static str = "item/commandExecution/requestApproval";
    type Response = CommandExecutionRequestApprovalResponse;
}
impl ServerRequest for FileChangeRequestApprovalParams {
    const METHOD: &'static str = "item/fileChange/requestApproval";
    type Response = FileChangeRequestApprovalResponse;
}
impl ServerRequest for McpServerElicitationRequestParams {
    const METHOD: &'static str = "mcpServer/elicitation/request";
    type Response = McpServerElicitationRequestResponse;
}

/// A path that is guaranteed to be absolute and normalized (though it is not guaranteed to be canonicalized or exist on the filesystem).
///
/// IMPORTANT: When deserializing an `AbsolutePathBuf`, a base path must be set using \[AbsolutePathBufGuard::new\]. If no base path is set, the deserialization will fail unless the path being deserialized is already absolute.
pub type AbsolutePathBuf = String;

/// Sparse rolling rate-limit update.
///
/// Clients should merge available values into the most recent `account/rateLimits/read` response or refetch that snapshot. Nullable account metadata may be unavailable in a rolling update and does not clear a previously observed value.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct AccountRateLimitsUpdatedNotification {
    #[serde(rename = "rateLimits")]
    pub rate_limits: RateLimitSnapshot,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct AddPatchChangeKind {}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum AgentMessageDelivery {
    #[serde(rename = "async")]
    Async,
    /// A value this Codex version doesn't know, or a known one whose body didn't decode.
    #[serde(untagged)]
    Unknown(Value),
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct AgentMessageDeltaNotification {
    pub delta: String,
    #[serde(rename = "itemId")]
    pub item_id: String,
    #[serde(rename = "threadId")]
    pub thread_id: String,
    #[serde(rename = "turnId")]
    pub turn_id: String,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct AgentMessageThreadItem {
    /// Unix timestamp in milliseconds when the item completed, if recorded.
    #[serde(rename = "completedAtMs")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub completed_at_ms: Option<i64>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub delivery: Option<AgentMessageDelivery>,
    pub id: String,
    #[serde(rename = "memoryCitation")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub memory_citation: Option<MemoryCitation>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub phase: Option<MessagePhase>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub questions: Option<Vec<AsyncUserInputQuestion>>,
    /// Unix timestamp in milliseconds when the item started, if recorded.
    #[serde(rename = "startedAtMs")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub started_at_ms: Option<i64>,
    pub text: String,
}

pub type AgentPath = String;

/// Configures who approval requests are routed to for review. Examples include sandbox escapes, blocked network access, MCP approval prompts, and ARC escalations. Defaults to `user`. `auto_review` uses a carefully prompted subagent to gather relevant context and apply a risk-based decision framework before approving or denying the request. The legacy value `guardian_subagent` is accepted for compatibility.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum ApprovalsReviewer {
    #[serde(rename = "user")]
    User,
    #[serde(rename = "auto_review")]
    AutoReview,
    #[serde(rename = "guardian_subagent")]
    GuardianSubagent,
    /// A value this Codex version doesn't know, or a known one whose body didn't decode.
    #[serde(untagged)]
    Unknown(Value),
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum AskForApproval {
    #[serde(rename = "untrusted")]
    Untrusted,
    #[serde(rename = "on-request")]
    OnRequest,
    #[serde(rename = "never")]
    Never,
    #[serde(rename = "granular")]
    Granular(AskForApprovalGranular),
    /// A value this Codex version doesn't know, or a known one whose body didn't decode.
    #[serde(untagged)]
    Unknown(Value),
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct AskForApprovalGranular {
    pub mcp_elicitations: bool,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub request_permissions: Option<bool>,
    pub rules: bool,
    pub sandbox_approval: bool,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub skill_approval: Option<bool>,
}

pub type AsyncUserInputQuestion = Value;

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct AudioUserInput {
    #[serde(rename = "fileId")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub file_id: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub url: Option<String>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct ClientInfo {
    pub name: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub title: Option<String>,
    pub version: String,
}

/// This translation layer make sure that we expose codex error code in camel case.
///
/// When an upstream HTTP status is available (for example, from the Responses API or a provider), it is forwarded in `httpStatusCode` on the relevant `codexErrorInfo` variant.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum CodexErrorInfo {
    #[serde(rename = "contextWindowExceeded")]
    ContextWindowExceeded,
    #[serde(rename = "sessionBudgetExceeded")]
    SessionBudgetExceeded,
    #[serde(rename = "usageLimitExceeded")]
    UsageLimitExceeded,
    #[serde(rename = "rateLimitExceeded")]
    RateLimitExceeded,
    #[serde(rename = "flexUnavailable")]
    FlexUnavailable,
    #[serde(rename = "serverOverloaded")]
    ServerOverloaded,
    #[serde(rename = "modelNotFound")]
    ModelNotFound,
    #[serde(rename = "policyCapacityUnavailable")]
    PolicyCapacityUnavailable,
    #[serde(rename = "cyberPolicy")]
    CyberPolicy,
    #[serde(rename = "misalignmentPolicyViolation")]
    MisalignmentPolicyViolation,
    #[serde(rename = "tooManyDenials")]
    TooManyDenials,
    #[serde(rename = "internalServerError")]
    InternalServerError,
    #[serde(rename = "unauthorized")]
    Unauthorized,
    #[serde(rename = "badRequest")]
    BadRequest,
    #[serde(rename = "threadRollbackFailed")]
    ThreadRollbackFailed,
    #[serde(rename = "sandboxError")]
    SandboxError,
    #[serde(rename = "other")]
    Other,
    #[serde(rename = "httpConnectionFailed")]
    HttpConnectionFailed(CodexErrorInfoHttpConnectionFailed),
    /// Failed to connect to the response SSE stream.
    #[serde(rename = "responseStreamConnectionFailed")]
    ResponseStreamConnectionFailed(CodexErrorInfoResponseStreamConnectionFailed),
    /// The response SSE stream disconnected in the middle of a turn before completion.
    #[serde(rename = "responseStreamDisconnected")]
    ResponseStreamDisconnected(CodexErrorInfoResponseStreamDisconnected),
    /// Reached the retry limit for responses.
    #[serde(rename = "responseTooManyFailedAttempts")]
    ResponseTooManyFailedAttempts(CodexErrorInfoResponseTooManyFailedAttempts),
    /// Returned when `turn/start` or `turn/steer` is submitted while the current active turn cannot accept same-turn steering, for example `/review` or manual `/compact`.
    #[serde(rename = "activeTurnNotSteerable")]
    ActiveTurnNotSteerable(CodexErrorInfoActiveTurnNotSteerable),
    /// A value this Codex version doesn't know, or a known one whose body didn't decode.
    #[serde(untagged)]
    Unknown(Value),
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct CodexErrorInfoActiveTurnNotSteerable {
    #[serde(rename = "turnKind")]
    pub turn_kind: NonSteerableTurnKind,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct CodexErrorInfoHttpConnectionFailed {
    #[serde(rename = "httpStatusCode")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub http_status_code: Option<u64>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct CodexErrorInfoResponseStreamConnectionFailed {
    #[serde(rename = "httpStatusCode")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub http_status_code: Option<u64>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct CodexErrorInfoResponseStreamDisconnected {
    #[serde(rename = "httpStatusCode")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub http_status_code: Option<u64>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct CodexErrorInfoResponseTooManyFailedAttempts {
    #[serde(rename = "httpStatusCode")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub http_status_code: Option<u64>,
}

pub type CollabAgentState = Value;

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum CollabAgentTool {
    #[serde(rename = "spawnAgent")]
    SpawnAgent,
    #[serde(rename = "sendInput")]
    SendInput,
    #[serde(rename = "resumeAgent")]
    ResumeAgent,
    #[serde(rename = "wait")]
    Wait,
    #[serde(rename = "closeAgent")]
    CloseAgent,
    #[serde(rename = "sendMessage")]
    SendMessage,
    #[serde(rename = "followupTask")]
    FollowupTask,
    #[serde(rename = "interruptAgent")]
    InterruptAgent,
    #[serde(rename = "listAgents")]
    ListAgents,
    /// A value this Codex version doesn't know, or a known one whose body didn't decode.
    #[serde(untagged)]
    Unknown(Value),
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum CollabAgentToolCallStatus {
    #[serde(rename = "inProgress")]
    InProgress,
    #[serde(rename = "completed")]
    Completed,
    #[serde(rename = "failed")]
    Failed,
    #[serde(rename = "interrupted")]
    Interrupted,
    /// A value this Codex version doesn't know, or a known one whose body didn't decode.
    #[serde(untagged)]
    Unknown(Value),
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct CollabAgentToolCallThreadItem {
    /// Last known status of the target agents, when available.
    #[serde(rename = "agentsStates")]
    pub agents_states: BTreeMap<String, CollabAgentState>,
    /// Unix timestamp in milliseconds when the item completed, if recorded.
    #[serde(rename = "completedAtMs")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub completed_at_ms: Option<i64>,
    /// Unique identifier for this collab tool call.
    pub id: String,
    /// Model requested for the spawned agent, when applicable.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub model: Option<String>,
    /// Prompt text sent as part of the collab tool call, when available.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub prompt: Option<String>,
    /// Reasoning effort requested for the spawned agent, when applicable.
    #[serde(rename = "reasoningEffort")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub reasoning_effort: Option<ReasoningEffort>,
    /// Thread ID of the receiving agent, when applicable. In case of spawn operation, this corresponds to the newly spawned agent.
    #[serde(rename = "receiverThreadIds")]
    pub receiver_thread_ids: Vec<String>,
    /// Thread ID of the agent issuing the collab request.
    #[serde(rename = "senderThreadId")]
    pub sender_thread_id: String,
    /// Unix timestamp in milliseconds when the item started, if recorded.
    #[serde(rename = "startedAtMs")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub started_at_ms: Option<i64>,
    /// Current status of the collab tool call.
    pub status: CollabAgentToolCallStatus,
    /// Name of the collab tool that was invoked.
    pub tool: CollabAgentTool,
}

/// Collaboration mode for a Codex session.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct CollaborationMode {
    pub mode: ModeKind,
    pub settings: Settings,
}

pub type CommandAction = Value;

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum CommandExecutionApprovalDecision {
    /// User approved the command.
    #[serde(rename = "accept")]
    Accept,
    /// User approved the command and future prompts in the same session-scoped approval cache should run without prompting.
    #[serde(rename = "acceptForSession")]
    AcceptForSession,
    /// User approved the command, and wants to apply the proposed execpolicy amendment so future matching commands can run without prompting.
    #[serde(rename = "acceptWithExecpolicyAmendment")]
    AcceptWithExecpolicyAmendment(CommandExecutionApprovalDecisionAcceptWithExecpolicyAmendment),
    /// User chose a persistent network policy rule (allow/deny) for this host.
    #[serde(rename = "applyNetworkPolicyAmendment")]
    ApplyNetworkPolicyAmendment(CommandExecutionApprovalDecisionApplyNetworkPolicyAmendment),
    /// User denied the command. The agent will continue the turn.
    #[serde(rename = "decline")]
    Decline,
    /// User denied the command. The turn will also be immediately interrupted.
    #[serde(rename = "cancel")]
    Cancel,
    /// A value this Codex version doesn't know, or a known one whose body didn't decode.
    #[serde(untagged)]
    Unknown(Value),
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct CommandExecutionApprovalDecisionAcceptWithExecpolicyAmendment {
    pub execpolicy_amendment: Vec<String>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct CommandExecutionApprovalDecisionApplyNetworkPolicyAmendment {
    pub network_policy_amendment: NetworkPolicyAmendment,
}

/// Distinguishes a command approval from input sent to an existing terminal.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum CommandExecutionApprovalKind {
    #[serde(rename = "command")]
    Command,
    #[serde(rename = "writeStdin")]
    WriteStdin,
    /// A managed checkpoint requiring a fresh human decision. Only `accept`, `decline`, and `cancel` are valid. Requires the `requiredHumanApproval` initialize capability. This prompt does not itself start a command execution item.
    #[serde(rename = "humanCommand")]
    HumanCommand,
    /// A value this Codex version doesn't know, or a known one whose body didn't decode.
    #[serde(untagged)]
    Unknown(Value),
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct CommandExecutionRequestApprovalParams {
    /// Unique identifier for this specific approval callback.
    ///
    /// For regular shell/unified_exec approvals, this is null.
    ///
    /// For zsh-exec-bridge subcommand approvals, multiple callbacks can belong to one parent `itemId`, so `approvalId` is a distinct opaque callback id (a UUID) used to disambiguate routing. Stdin approvals also use a distinct callback id; inspect `kind` to distinguish them.
    #[serde(rename = "approvalId")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub approval_id: Option<String>,
    /// The command to be executed.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub command: Option<String>,
    /// Best-effort parsed command actions for friendly display.
    #[serde(rename = "commandActions")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub command_actions: Option<Vec<CommandAction>>,
    /// The command's working directory.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub cwd: Option<LegacyAppPathString>,
    /// Environment in which the command will run.
    #[serde(rename = "environmentId")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub environment_id: Option<String>,
    #[serde(rename = "itemId")]
    pub item_id: String,
    /// Kind of action under review. Defaults to `command` for older servers.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub kind: Option<CommandExecutionApprovalKind>,
    /// Optional context for a managed-network approval prompt.
    #[serde(rename = "networkApprovalContext")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub network_approval_context: Option<NetworkApprovalContext>,
    /// Optional proposed execpolicy amendment to allow similar commands without prompting.
    #[serde(rename = "proposedExecpolicyAmendment")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub proposed_execpolicy_amendment: Option<Vec<String>>,
    /// Optional proposed network policy amendments (allow/deny host) for future requests.
    #[serde(rename = "proposedNetworkPolicyAmendments")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub proposed_network_policy_amendments: Option<Vec<NetworkPolicyAmendment>>,
    /// Optional explanatory reason (e.g. request for network access).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub reason: Option<String>,
    /// Unix timestamp (in milliseconds) when this approval request started.
    #[serde(rename = "startedAtMs")]
    pub started_at_ms: i64,
    #[serde(rename = "threadId")]
    pub thread_id: String,
    #[serde(rename = "turnId")]
    pub turn_id: String,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct CommandExecutionRequestApprovalResponse {
    pub decision: CommandExecutionApprovalDecision,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum CommandExecutionSource {
    #[serde(rename = "agent")]
    Agent,
    #[serde(rename = "userShell")]
    UserShell,
    #[serde(rename = "unifiedExecStartup")]
    UnifiedExecStartup,
    #[serde(rename = "unifiedExecInteraction")]
    UnifiedExecInteraction,
    /// A value this Codex version doesn't know, or a known one whose body didn't decode.
    #[serde(untagged)]
    Unknown(Value),
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum CommandExecutionStatus {
    #[serde(rename = "inProgress")]
    InProgress,
    #[serde(rename = "completed")]
    Completed,
    #[serde(rename = "failed")]
    Failed,
    #[serde(rename = "declined")]
    Declined,
    /// A value this Codex version doesn't know, or a known one whose body didn't decode.
    #[serde(untagged)]
    Unknown(Value),
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct CommandExecutionThreadItem {
    /// The command's output, aggregated from stdout and stderr.
    #[serde(rename = "aggregatedOutput")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub aggregated_output: Option<String>,
    /// The command to be executed.
    pub command: String,
    /// A best-effort parsing of the command to understand the action(s) it will perform. This returns a list of CommandAction objects because a single shell command may be composed of many commands piped together.
    #[serde(rename = "commandActions")]
    pub command_actions: Vec<CommandAction>,
    /// Unix timestamp in milliseconds when the item completed, if recorded.
    #[serde(rename = "completedAtMs")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub completed_at_ms: Option<i64>,
    /// The command's working directory.
    pub cwd: LegacyAppPathString,
    /// The duration of the command execution in milliseconds.
    #[serde(rename = "durationMs")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub duration_ms: Option<i64>,
    /// The command's exit code.
    #[serde(rename = "exitCode")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub exit_code: Option<i64>,
    pub id: String,
    /// Trusted first-party plugin id when this command resolves to one plugin script.
    #[serde(rename = "pluginId")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub plugin_id: Option<String>,
    /// Identifier for the underlying PTY process (when available).
    #[serde(rename = "processId")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub process_id: Option<String>,
    /// Safe plugin-relative path when this command resolves to one plugin script.
    #[serde(rename = "scriptPath")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub script_path: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub source: Option<CommandExecutionSource>,
    /// Unix timestamp in milliseconds when the item started, if recorded.
    #[serde(rename = "startedAtMs")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub started_at_ms: Option<i64>,
    pub status: CommandExecutionStatus,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct ContextCompactionThreadItem {
    /// Unix timestamp in milliseconds when the item completed, if recorded.
    #[serde(rename = "completedAtMs")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub completed_at_ms: Option<i64>,
    pub id: String,
    /// Unix timestamp in milliseconds when the item started, if recorded.
    #[serde(rename = "startedAtMs")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub started_at_ms: Option<i64>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct CreditsSnapshot {
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub balance: Option<String>,
    #[serde(rename = "hasCredits")]
    pub has_credits: bool,
    pub unlimited: bool,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct DeletePatchChangeKind {}

pub type DynamicToolCallOutputContentItem = Value;

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum DynamicToolCallStatus {
    #[serde(rename = "inProgress")]
    InProgress,
    #[serde(rename = "completed")]
    Completed,
    #[serde(rename = "failed")]
    Failed,
    /// A value this Codex version doesn't know, or a known one whose body didn't decode.
    #[serde(untagged)]
    Unknown(Value),
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct DynamicToolCallThreadItem {
    pub arguments: Value,
    /// Unix timestamp in milliseconds when the item completed, if recorded.
    #[serde(rename = "completedAtMs")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub completed_at_ms: Option<i64>,
    #[serde(rename = "contentItems")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub content_items: Option<Vec<DynamicToolCallOutputContentItem>>,
    /// The duration of the dynamic tool call in milliseconds.
    #[serde(rename = "durationMs")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub duration_ms: Option<i64>,
    pub id: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub namespace: Option<String>,
    /// Unix timestamp in milliseconds when the item started, if recorded.
    #[serde(rename = "startedAtMs")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub started_at_ms: Option<i64>,
    pub status: DynamicToolCallStatus,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub success: Option<bool>,
    pub tool: String,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct EnteredReviewModeThreadItem {
    /// Unix timestamp in milliseconds when the item completed, if recorded.
    #[serde(rename = "completedAtMs")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub completed_at_ms: Option<i64>,
    pub id: String,
    pub review: String,
    /// Unix timestamp in milliseconds when the item started, if recorded.
    #[serde(rename = "startedAtMs")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub started_at_ms: Option<i64>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ErrorNotification {
    pub error: TurnError,
    #[serde(rename = "threadId")]
    pub thread_id: String,
    #[serde(rename = "turnId")]
    pub turn_id: String,
    #[serde(rename = "willRetry")]
    pub will_retry: bool,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct ExitedReviewModeThreadItem {
    /// Unix timestamp in milliseconds when the item completed, if recorded.
    #[serde(rename = "completedAtMs")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub completed_at_ms: Option<i64>,
    pub id: String,
    pub review: String,
    /// Unix timestamp in milliseconds when the item started, if recorded.
    #[serde(rename = "startedAtMs")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub started_at_ms: Option<i64>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum FileChangeApprovalDecision {
    /// User approved the file changes.
    #[serde(rename = "accept")]
    Accept,
    /// User approved the file changes and future changes to the same files should run without prompting.
    #[serde(rename = "acceptForSession")]
    AcceptForSession,
    /// User denied the file changes. The agent will continue the turn.
    #[serde(rename = "decline")]
    Decline,
    /// User denied the file changes. The turn will also be immediately interrupted.
    #[serde(rename = "cancel")]
    Cancel,
    /// A value this Codex version doesn't know, or a known one whose body didn't decode.
    #[serde(untagged)]
    Unknown(Value),
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct FileChangeRequestApprovalParams {
    /// \[UNSTABLE\] When set, the agent is asking the user to allow writes under this root for the remainder of the session (unclear if this is honored today).
    #[serde(rename = "grantRoot")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub grant_root: Option<String>,
    #[serde(rename = "itemId")]
    pub item_id: String,
    /// Optional explanatory reason (e.g. request for extra write access).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub reason: Option<String>,
    /// Unix timestamp (in milliseconds) when this approval request started.
    #[serde(rename = "startedAtMs")]
    pub started_at_ms: i64,
    #[serde(rename = "threadId")]
    pub thread_id: String,
    #[serde(rename = "turnId")]
    pub turn_id: String,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct FileChangeRequestApprovalResponse {
    pub decision: FileChangeApprovalDecision,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct FileChangeThreadItem {
    pub changes: Vec<FileUpdateChange>,
    /// Unix timestamp in milliseconds when the item completed, if recorded.
    #[serde(rename = "completedAtMs")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub completed_at_ms: Option<i64>,
    pub id: String,
    /// Unix timestamp in milliseconds when the item started, if recorded.
    #[serde(rename = "startedAtMs")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub started_at_ms: Option<i64>,
    pub status: PatchApplyStatus,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct FileUpdateChange {
    pub diff: String,
    pub kind: PatchChangeKind,
    pub path: String,
}

pub type FunctionCallOutputBody = Value;

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct FunctionCallOutputThreadItem {
    /// Unix timestamp in milliseconds when the item completed, if recorded.
    #[serde(rename = "completedAtMs")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub completed_at_ms: Option<i64>,
    pub id: String,
    pub name: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub namespace: Option<String>,
    pub output: FunctionCallOutputBody,
    /// Unix timestamp in milliseconds when the item started, if recorded.
    #[serde(rename = "startedAtMs")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub started_at_ms: Option<i64>,
}

pub type GitInfo = Value;

pub type HookPromptFragment = Value;

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct HookPromptThreadItem {
    /// Unix timestamp in milliseconds when the item completed, if recorded.
    #[serde(rename = "completedAtMs")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub completed_at_ms: Option<i64>,
    pub fragments: Vec<HookPromptFragment>,
    pub id: String,
    /// Unix timestamp in milliseconds when the item started, if recorded.
    #[serde(rename = "startedAtMs")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub started_at_ms: Option<i64>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum ImageDetail {
    #[serde(rename = "auto")]
    Auto,
    #[serde(rename = "low")]
    Low,
    #[serde(rename = "high")]
    High,
    #[serde(rename = "original")]
    Original,
    /// A value this Codex version doesn't know, or a known one whose body didn't decode.
    #[serde(untagged)]
    Unknown(Value),
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(tag = "type")]
pub enum ImageGenerationFailure {
    #[serde(rename = "usageLimitExceeded")]
    UsageLimitExceeded(UsageLimitExceededImageGenerationFailure),
    /// A value this Codex version doesn't know, or a known one whose body didn't decode.
    #[serde(untagged)]
    Unknown(Value),
}

/// A local image file successfully read for this exact image-generation request.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct ImageGenerationInputImage {
    pub path: AbsolutePathBuf,
    /// Lowercase SHA-256 of the file bytes read before image normalization.
    pub sha256: String,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct ImageGenerationThreadItem {
    /// Unix timestamp in milliseconds when the item completed, if recorded.
    #[serde(rename = "completedAtMs")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub completed_at_ms: Option<i64>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub failure: Option<ImageGenerationFailure>,
    #[serde(rename = "fileId")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub file_id: Option<String>,
    /// Image generation identifier for the generated image, when provided by the image backend.
    #[serde(rename = "generationId")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub generation_id: Option<String>,
    pub id: String,
    /// Observed local inputs for a completed generation, absent on older items.
    #[serde(rename = "inputImages")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub input_images: Option<Vec<ImageGenerationInputImage>>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub result: Option<String>,
    #[serde(rename = "revisedPrompt")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub revised_prompt: Option<String>,
    #[serde(rename = "savedPath")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub saved_path: Option<AbsolutePathBuf>,
    /// Unix timestamp in milliseconds when the item started, if recorded.
    #[serde(rename = "startedAtMs")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub started_at_ms: Option<i64>,
    pub status: String,
    #[serde(rename = "transparentBackground")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub transparent_background: Option<bool>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct ImageUserInput {
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub detail: Option<ImageDetail>,
    #[serde(rename = "fileId")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub file_id: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub url: Option<String>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct ImageViewThreadItem {
    /// Unix timestamp in milliseconds when the item completed, if recorded.
    #[serde(rename = "completedAtMs")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub completed_at_ms: Option<i64>,
    pub id: String,
    pub path: LegacyAppPathString,
    /// Unix timestamp in milliseconds when the item started, if recorded.
    #[serde(rename = "startedAtMs")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub started_at_ms: Option<i64>,
}

/// Client-declared capabilities negotiated during initialize.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct InitializeCapabilities {
    /// Opt into receiving experimental API methods and fields.
    #[serde(rename = "experimentalApi")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub experimental_api: Option<bool>,
    /// Use explicit gateway OAuth login instead of automatic browser authorization. Applies to this app-server's gateway runtime; later connections cannot undo it.
    #[serde(rename = "explicitGatewayOauth")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub explicit_gateway_oauth: Option<bool>,
    /// MCP extension settings declared by the app-server client.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub extensions: Option<BTreeMap<String, Value>>,
    /// Legacy opt-in for the `openai/form` MCP extension.
    ///
    /// New clients should declare `openai/form` in [`Self::extensions`].
    #[serde(rename = "mcpServerOpenaiFormElicitation")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub mcp_server_openai_form_elicitation: Option<bool>,
    /// Exact notification method names that should be suppressed for this connection (for example `thread/started`).
    #[serde(rename = "optOutNotificationMethods")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub opt_out_notification_methods: Option<Vec<String>>,
    /// Opt into `attestation/generate` requests for upstream `x-oai-attestation`.
    #[serde(rename = "requestAttestation")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub request_attestation: Option<bool>,
    /// Present `humanCommand` approvals to a person and return only a one-time decision. Requires `experimentalApi`. Pending requests can be replayed to compatible clients.
    #[serde(rename = "requiredHumanApproval")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub required_human_approval: Option<bool>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct InitializeParams {
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub capabilities: Option<InitializeCapabilities>,
    #[serde(rename = "clientInfo")]
    pub client_info: ClientInfo,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct InitializeResponse {
    /// Absolute path to the server's $CODEX_HOME directory.
    #[serde(rename = "codexHome")]
    pub codex_home: AbsolutePathBuf,
    /// Platform family for the running app-server target, for example `"unix"` or `"windows"`.
    #[serde(rename = "platformFamily")]
    pub platform_family: String,
    /// Operating system for the running app-server target, for example `"macos"`, `"linux"`, or `"windows"`.
    #[serde(rename = "platformOs")]
    pub platform_os: String,
    #[serde(rename = "userAgent")]
    pub user_agent: String,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ItemCompletedNotification {
    /// Unix timestamp (in milliseconds) when this item lifecycle completed.
    #[serde(rename = "completedAtMs")]
    pub completed_at_ms: i64,
    pub item: ThreadItem,
    #[serde(rename = "threadId")]
    pub thread_id: String,
    #[serde(rename = "turnId")]
    pub turn_id: String,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ItemStartedNotification {
    pub item: ThreadItem,
    /// Unix timestamp (in milliseconds) when this item lifecycle started.
    #[serde(rename = "startedAtMs")]
    pub started_at_ms: i64,
    #[serde(rename = "threadId")]
    pub thread_id: String,
    #[serde(rename = "turnId")]
    pub turn_id: String,
}

pub type LegacyAppPathString = String;

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct LocalAudioUserInput {
    pub path: String,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct LocalImageUserInput {
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub detail: Option<ImageDetail>,
    pub path: String,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum McpAppDisplayMode {
    #[serde(rename = "inline")]
    Inline,
    #[serde(rename = "fullscreen")]
    Fullscreen,
    /// A value this Codex version doesn't know, or a known one whose body didn't decode.
    #[serde(untagged)]
    Unknown(Value),
}

/// UI resource and display preference for model invocations, captured from the tool descriptor.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct McpAppUi {
    #[serde(rename = "preferredModelDisplayMode")]
    pub preferred_model_display_mode: McpAppDisplayMode,
    #[serde(rename = "resourceUri")]
    pub resource_uri: String,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum McpServerElicitationAction {
    #[serde(rename = "accept")]
    Accept,
    #[serde(rename = "decline")]
    Decline,
    #[serde(rename = "cancel")]
    Cancel,
    /// A value this Codex version doesn't know, or a known one whose body didn't decode.
    #[serde(untagged)]
    Unknown(Value),
}

pub type McpServerElicitationRequestParams = Value;

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct McpServerElicitationRequestResponse {
    /// Optional client metadata for form-mode action handling.
    #[serde(rename = "_meta")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub meta: Option<Value>,
    pub action: McpServerElicitationAction,
    /// Structured user input for accepted elicitations, mirroring RMCP `CreateElicitationResult`.
    ///
    /// This is nullable because decline/cancel responses have no content.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub content: Option<Value>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct McpToolCallAppContext {
    #[serde(rename = "actionName")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub action_name: Option<String>,
    #[serde(rename = "appName")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub app_name: Option<String>,
    #[serde(rename = "connectorId")]
    pub connector_id: String,
    #[serde(rename = "linkId")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub link_id: Option<String>,
    #[serde(rename = "resourceUri")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub resource_uri: Option<String>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct McpToolCallError {
    pub message: String,
}

pub type McpToolCallResult = Value;

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum McpToolCallStatus {
    #[serde(rename = "inProgress")]
    InProgress,
    #[serde(rename = "completed")]
    Completed,
    #[serde(rename = "failed")]
    Failed,
    /// A value this Codex version doesn't know, or a known one whose body didn't decode.
    #[serde(untagged)]
    Unknown(Value),
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct McpToolCallThreadItem {
    #[serde(rename = "appContext")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub app_context: Option<McpToolCallAppContext>,
    pub arguments: Value,
    /// Unix timestamp in milliseconds when the item completed, if recorded.
    #[serde(rename = "completedAtMs")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub completed_at_ms: Option<i64>,
    /// The duration of the MCP tool call in milliseconds.
    #[serde(rename = "durationMs")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub duration_ms: Option<i64>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub error: Option<McpToolCallError>,
    pub id: String,
    /// Legacy compatibility field; prefer `mcpAppUi.resourceUri` when available.
    #[serde(rename = "mcpAppResourceUri")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub mcp_app_resource_uri: Option<String>,
    /// Presentation captured from the invoked descriptor; absent in older history.
    #[serde(rename = "mcpAppUi")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub mcp_app_ui: Option<McpAppUi>,
    #[serde(rename = "pluginId")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub plugin_id: Option<String>,
    #[serde(rename = "readOnlyHint")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub read_only_hint: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub result: Option<McpToolCallResult>,
    pub server: String,
    /// Unix timestamp in milliseconds when the item started, if recorded.
    #[serde(rename = "startedAtMs")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub started_at_ms: Option<i64>,
    pub status: McpToolCallStatus,
    pub tool: String,
}

pub type MemoryCitation = Value;

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct MentionUserInput {
    pub name: String,
    pub path: String,
}

/// Classifies assistant text as commentary, a partial answer, or a terminal answer.
///
/// Providers do not emit this consistently, so callers must treat `None` as "phase unknown" and keep compatibility behavior for legacy models.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum MessagePhase {
    /// Mid-turn assistant text (for example preamble/progress narration).
    ///
    /// Additional tool calls or assistant output may follow before turn completion.
    #[serde(rename = "commentary")]
    Commentary,
    /// Stable answer text that may be followed by more assistant output or tools.
    #[serde(rename = "partial_answer")]
    PartialAnswer,
    /// The assistant's declared terminal answer text for the current turn.
    #[serde(rename = "final_answer")]
    FinalAnswer,
    /// A value this Codex version doesn't know, or a known one whose body didn't decode.
    #[serde(untagged)]
    Unknown(Value),
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct MisalignmentErrorDetails {
    /// A substantive localized explanation is required before offering continuation.
    #[serde(rename = "detailedExplanation")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub detailed_explanation: Option<String>,
    /// Open-ended classification; clients must accept categories added by Responses.
    #[serde(rename = "errorType")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub error_type: Option<String>,
    /// Opaque server-issued block target. Presence alone does not enable target-based continuation.
    #[serde(rename = "reviewTarget")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub review_target: Option<String>,
    /// Instruction to submit as the next turn's user input if continuation is confirmed.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub steer: Option<MisalignmentSteer>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct MisalignmentSteer {
    pub message: String,
}

/// Initial collaboration mode to use when the TUI starts.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum ModeKind {
    #[serde(rename = "plan")]
    Plan,
    #[serde(rename = "default")]
    Default,
    /// A value this Codex version doesn't know, or a known one whose body didn't decode.
    #[serde(untagged)]
    Unknown(Value),
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct NetworkApprovalContext {
    pub host: String,
    pub protocol: NetworkApprovalProtocol,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum NetworkApprovalProtocol {
    #[serde(rename = "http")]
    Http,
    #[serde(rename = "https")]
    Https,
    #[serde(rename = "socks5Tcp")]
    Socks5Tcp,
    #[serde(rename = "socks5Udp")]
    Socks5Udp,
    /// A value this Codex version doesn't know, or a known one whose body didn't decode.
    #[serde(untagged)]
    Unknown(Value),
}

pub type NetworkPolicyAmendment = Value;

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum NonSteerableTurnKind {
    #[serde(rename = "review")]
    Review,
    #[serde(rename = "compact")]
    Compact,
    /// A value this Codex version doesn't know, or a known one whose body didn't decode.
    #[serde(untagged)]
    Unknown(Value),
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum PatchApplyStatus {
    #[serde(rename = "inProgress")]
    InProgress,
    #[serde(rename = "completed")]
    Completed,
    #[serde(rename = "failed")]
    Failed,
    #[serde(rename = "declined")]
    Declined,
    /// A value this Codex version doesn't know, or a known one whose body didn't decode.
    #[serde(untagged)]
    Unknown(Value),
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(tag = "type")]
pub enum PatchChangeKind {
    #[serde(rename = "add")]
    Add(AddPatchChangeKind),
    #[serde(rename = "delete")]
    Delete(DeletePatchChangeKind),
    #[serde(rename = "update")]
    Update(UpdatePatchChangeKind),
    /// A value this Codex version doesn't know, or a known one whose body didn't decode.
    #[serde(untagged)]
    Unknown(Value),
}

/// Deprecated: `friendly` and `pragmatic` no longer select a style.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum Personality {
    #[serde(rename = "none")]
    None,
    #[serde(rename = "friendly")]
    Friendly,
    #[serde(rename = "pragmatic")]
    Pragmatic,
    /// A value this Codex version doesn't know, or a known one whose body didn't decode.
    #[serde(untagged)]
    Unknown(Value),
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct PlanThreadItem {
    /// Unix timestamp in milliseconds when the item completed, if recorded.
    #[serde(rename = "completedAtMs")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub completed_at_ms: Option<i64>,
    pub id: String,
    /// Unix timestamp in milliseconds when the item started, if recorded.
    #[serde(rename = "startedAtMs")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub started_at_ms: Option<i64>,
    pub text: String,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum PlanType {
    #[serde(rename = "free")]
    Free,
    #[serde(rename = "go")]
    Go,
    #[serde(rename = "plus")]
    Plus,
    #[serde(rename = "pro")]
    Pro,
    #[serde(rename = "prolite")]
    Prolite,
    #[serde(rename = "promax")]
    Promax,
    #[serde(rename = "team")]
    Team,
    #[serde(rename = "self_serve_business_prolite")]
    SelfServeBusinessProlite,
    #[serde(rename = "self_serve_business_usage_based")]
    SelfServeBusinessUsageBased,
    #[serde(rename = "business")]
    Business,
    #[serde(rename = "ent26")]
    Ent26,
    #[serde(rename = "enterprise_cbp_automation")]
    EnterpriseCbpAutomation,
    #[serde(rename = "enterprise_cbp_usage_based")]
    EnterpriseCbpUsageBased,
    #[serde(rename = "enterprise")]
    Enterprise,
    #[serde(rename = "edu")]
    Edu,
    #[serde(rename = "edu_plus")]
    EduPlus,
    #[serde(rename = "edu_pro")]
    EduPro,
    #[serde(rename = "sci")]
    Sci,
    #[serde(rename = "sci_plus")]
    SciPlus,
    #[serde(rename = "unknown")]
    Unknown,
    /// A value this Codex version doesn't know, or a known one whose body didn't decode.
    #[serde(untagged)]
    UnknownValue(Value),
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum RateLimitReachedType {
    #[serde(rename = "rate_limit_reached")]
    RateLimitReached,
    #[serde(rename = "workspace_owner_credits_depleted")]
    WorkspaceOwnerCreditsDepleted,
    #[serde(rename = "workspace_member_credits_depleted")]
    WorkspaceMemberCreditsDepleted,
    #[serde(rename = "workspace_owner_usage_limit_reached")]
    WorkspaceOwnerUsageLimitReached,
    #[serde(rename = "workspace_member_usage_limit_reached")]
    WorkspaceMemberUsageLimitReached,
    /// A value this Codex version doesn't know, or a known one whose body didn't decode.
    #[serde(untagged)]
    Unknown(Value),
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct RateLimitSnapshot {
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub credits: Option<CreditsSnapshot>,
    #[serde(rename = "individualLimit")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub individual_limit: Option<SpendControlLimitSnapshot>,
    #[serde(rename = "limitId")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub limit_id: Option<String>,
    #[serde(rename = "limitName")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub limit_name: Option<String>,
    /// Normal model whose display name and reasoning options describe this quota alias.
    #[serde(rename = "normalModelSlug")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub normal_model_slug: Option<String>,
    #[serde(rename = "planType")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub plan_type: Option<PlanType>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub primary: Option<RateLimitWindow>,
    #[serde(rename = "rateLimitReachedType")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub rate_limit_reached_type: Option<RateLimitReachedType>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub secondary: Option<RateLimitWindow>,
    /// Backend-reported spend-control state. `None` is unavailable, not a sparse-update recovery.
    #[serde(rename = "spendControlReached")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub spend_control_reached: Option<bool>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct RateLimitWindow {
    #[serde(rename = "resetsAt")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub resets_at: Option<i64>,
    #[serde(rename = "usedPercent")]
    pub used_percent: i64,
    #[serde(rename = "windowDurationMins")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub window_duration_mins: Option<i64>,
}

/// A non-empty reasoning effort value advertised by the model.
pub type ReasoningEffort = String;

/// A summary of the reasoning performed by the model. This can be useful for debugging and understanding the model's reasoning process. See <https://platform.openai.com/docs/guides/reasoning?api-mode=responses#reasoning-summaries>
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum ReasoningSummary {
    #[serde(rename = "auto")]
    Auto,
    #[serde(rename = "concise")]
    Concise,
    #[serde(rename = "detailed")]
    Detailed,
    /// Option to disable reasoning summaries.
    #[serde(rename = "none")]
    None,
    /// A value this Codex version doesn't know, or a known one whose body didn't decode.
    #[serde(untagged)]
    Unknown(Value),
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct ReasoningThreadItem {
    /// Unix timestamp in milliseconds when the item completed, if recorded.
    #[serde(rename = "completedAtMs")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub completed_at_ms: Option<i64>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub content: Option<Vec<String>>,
    pub id: String,
    /// Unix timestamp in milliseconds when the item started, if recorded.
    #[serde(rename = "startedAtMs")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub started_at_ms: Option<i64>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub summary: Option<Vec<String>>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum SandboxMode {
    #[serde(rename = "read-only")]
    ReadOnly,
    #[serde(rename = "workspace-write")]
    WorkspaceWrite,
    #[serde(rename = "danger-full-access")]
    DangerFullAccess,
    /// A value this Codex version doesn't know, or a known one whose body didn't decode.
    #[serde(untagged)]
    Unknown(Value),
}

pub type SandboxPolicy = Value;

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum SessionSource {
    #[serde(rename = "cli")]
    Cli,
    #[serde(rename = "vscode")]
    Vscode,
    #[serde(rename = "exec")]
    Exec,
    #[serde(rename = "appServer")]
    AppServer,
    #[serde(rename = "unknown")]
    Unknown,
    #[serde(rename = "custom")]
    Custom(String),
    #[serde(rename = "subAgent")]
    SubAgent(SubAgentSource),
    /// A value this Codex version doesn't know, or a known one whose body didn't decode.
    #[serde(untagged)]
    UnknownValue(Value),
}

/// Settings for a collaboration mode.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct Settings {
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub developer_instructions: Option<String>,
    pub model: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub reasoning_effort: Option<ReasoningEffort>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct SkillUserInput {
    pub name: String,
    pub path: String,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct SleepThreadItem {
    /// Unix timestamp in milliseconds when the item completed, if recorded.
    #[serde(rename = "completedAtMs")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub completed_at_ms: Option<i64>,
    #[serde(rename = "durationMs")]
    pub duration_ms: u64,
    pub id: String,
    /// Unix timestamp in milliseconds when the item started, if recorded.
    #[serde(rename = "startedAtMs")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub started_at_ms: Option<i64>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct SpendControlLimitSnapshot {
    pub limit: String,
    #[serde(rename = "remainingPercent")]
    pub remaining_percent: i64,
    #[serde(rename = "resetsAt")]
    pub resets_at: i64,
    pub used: String,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum SubAgentActivityKind {
    #[serde(rename = "started")]
    Started,
    #[serde(rename = "interacted")]
    Interacted,
    #[serde(rename = "interrupted")]
    Interrupted,
    #[serde(rename = "completed")]
    Completed,
    /// A value this Codex version doesn't know, or a known one whose body didn't decode.
    #[serde(untagged)]
    Unknown(Value),
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct SubAgentActivityThreadItem {
    #[serde(rename = "agentPath")]
    pub agent_path: String,
    #[serde(rename = "agentThreadId")]
    pub agent_thread_id: String,
    /// Unix timestamp in milliseconds when the item completed, if recorded.
    #[serde(rename = "completedAtMs")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub completed_at_ms: Option<i64>,
    pub id: String,
    pub kind: SubAgentActivityKind,
    /// Resolved model at sub-agent creation; absent from older records and other activities.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub model: Option<String>,
    /// Resolved reasoning effort at sub-agent creation, when known.
    #[serde(rename = "reasoningEffort")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub reasoning_effort: Option<ReasoningEffort>,
    /// Unix timestamp in milliseconds when the item started, if recorded.
    #[serde(rename = "startedAtMs")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub started_at_ms: Option<i64>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum SubAgentSource {
    #[serde(rename = "review")]
    Review,
    #[serde(rename = "compact")]
    Compact,
    #[serde(rename = "memory_consolidation")]
    MemoryConsolidation,
    #[serde(rename = "thread_spawn")]
    ThreadSpawn(SubAgentSourceThreadSpawn),
    #[serde(rename = "other")]
    Other(String),
    /// A value this Codex version doesn't know, or a known one whose body didn't decode.
    #[serde(untagged)]
    Unknown(Value),
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct SubAgentSourceThreadSpawn {
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub agent_nickname: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub agent_path: Option<AgentPath>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub agent_role: Option<String>,
    pub depth: i64,
    pub parent_thread_id: ThreadId,
}

pub type TextElement = Value;

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct TextUserInput {
    pub text: String,
    /// UI-defined spans within `text` used to render or persist special elements.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub text_elements: Option<Vec<TextElement>>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Thread {
    /// Optional random unique nickname assigned to an AgentControl-spawned sub-agent.
    #[serde(rename = "agentNickname")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub agent_nickname: Option<String>,
    /// Optional role (agent_role) assigned to an AgentControl-spawned sub-agent.
    #[serde(rename = "agentRole")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub agent_role: Option<String>,
    /// Version of the CLI that created the thread.
    #[serde(rename = "cliVersion")]
    pub cli_version: String,
    /// Unix timestamp (in seconds) when the thread was created.
    #[serde(rename = "createdAt")]
    pub created_at: i64,
    /// Working directory captured for the thread.
    pub cwd: AbsolutePathBuf,
    /// Whether the thread is ephemeral and should not be materialized on disk.
    pub ephemeral: bool,
    /// Source thread id when this thread was created by forking another thread.
    #[serde(rename = "forkedFromId")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub forked_from_id: Option<String>,
    /// Optional Git metadata captured when the thread was created.
    #[serde(rename = "gitInfo")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub git_info: Option<GitInfo>,
    /// Persisted thread history contract selected when this thread was created.
    #[serde(rename = "historyMode")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub history_mode: Option<ThreadHistoryMode>,
    /// Identifier for this thread. Codex-generated thread IDs are UUIDv7.
    pub id: String,
    /// Current configured model when loaded, otherwise the latest persisted model. Null when unavailable. This is not per-turn execution telemetry.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub model: Option<String>,
    /// Model provider used for this thread (for example, 'openai').
    #[serde(rename = "modelProvider")]
    pub model_provider: String,
    /// Optional user-facing thread title.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    /// Originator recorded when the thread was created, independent of its current client or executor. Null when the recorded originator is unavailable.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub originator: Option<String>,
    /// The ID of the parent thread. This will only be set if this thread is a subagent.
    #[serde(rename = "parentThreadId")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub parent_thread_id: Option<String>,
    /// \[UNSTABLE\] Path to the thread on disk.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub path: Option<String>,
    /// Usually the first user message in the thread, if available.
    pub preview: String,
    /// Canonical project assignment owned by app-server, if any.
    #[serde(rename = "projectId")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub project_id: Option<String>,
    /// Current configured reasoning effort when loaded, otherwise the latest persisted effort. Null when unset or unavailable. This is not per-turn execution telemetry.
    #[serde(rename = "reasoningEffort")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub reasoning_effort: Option<ReasoningEffort>,
    /// Unix timestamp (in seconds) used for thread recency ordering.
    #[serde(rename = "recencyAt")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub recency_at: Option<i64>,
    /// The independently persisted section selected for this thread, if any.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub section: Option<ThreadSection>,
    /// Unix timestamp in seconds when the thread entered its current section.
    #[serde(rename = "sectionEnteredAt")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub section_entered_at: Option<i64>,
    /// Session id shared by threads that belong to the same session tree.
    #[serde(rename = "sessionId")]
    pub session_id: String,
    /// Origin of the thread (CLI, VSCode, codex exec, codex app-server, etc.).
    pub source: SessionSource,
    /// Current runtime status for the thread.
    pub status: ThreadStatus,
    /// Optional analytics source classification for this thread.
    #[serde(rename = "threadSource")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub thread_source: Option<ThreadSource>,
    /// Only populated on `thread/resume`, `thread/fork`, and `thread/read` (when `includeTurns` is true) responses. For all other responses and notifications returning a Thread, the turns field will be an empty list.
    pub turns: Vec<Turn>,
    /// Unix timestamp (in seconds) when the thread was last updated.
    #[serde(rename = "updatedAt")]
    pub updated_at: i64,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum ThreadHistoryMode {
    #[serde(rename = "legacy")]
    Legacy,
    #[serde(rename = "paginated")]
    Paginated,
    /// A value this Codex version doesn't know, or a known one whose body didn't decode.
    #[serde(untagged)]
    Unknown(Value),
}

pub type ThreadId = String;

/// A thread item and its recorded lifecycle times. The payload stays flat on the wire.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(tag = "type")]
pub enum ThreadItem {
    #[serde(rename = "userMessage")]
    UserMessage(UserMessageThreadItem),
    #[serde(rename = "hookPrompt")]
    HookPrompt(HookPromptThreadItem),
    #[serde(rename = "agentMessage")]
    AgentMessage(AgentMessageThreadItem),
    #[serde(rename = "functionCallOutput")]
    FunctionCallOutput(FunctionCallOutputThreadItem),
    /// EXPERIMENTAL - proposed plan item content. The completed plan item is authoritative and may not match the concatenation of `PlanDelta` text.
    #[serde(rename = "plan")]
    Plan(PlanThreadItem),
    #[serde(rename = "reasoning")]
    Reasoning(ReasoningThreadItem),
    #[serde(rename = "commandExecution")]
    CommandExecution(CommandExecutionThreadItem),
    #[serde(rename = "fileChange")]
    FileChange(FileChangeThreadItem),
    #[serde(rename = "mcpToolCall")]
    McpToolCall(McpToolCallThreadItem),
    #[serde(rename = "dynamicToolCall")]
    DynamicToolCall(DynamicToolCallThreadItem),
    #[serde(rename = "collabAgentToolCall")]
    CollabAgentToolCall(CollabAgentToolCallThreadItem),
    #[serde(rename = "subAgentActivity")]
    SubAgentActivity(SubAgentActivityThreadItem),
    #[serde(rename = "webSearch")]
    WebSearch(WebSearchThreadItem),
    #[serde(rename = "imageView")]
    ImageView(ImageViewThreadItem),
    /// Display item emitted by the interruptible `clock.sleep` tool.
    #[serde(rename = "sleep")]
    Sleep(SleepThreadItem),
    /// Either inline generated-image data or its durable attachment-store identity.
    ///
    /// `File` must remain first so rollouts written during the migration, which contain both an empty `result` and a `fileId`, retain the file reference when deserialized.
    #[serde(rename = "imageGeneration")]
    ImageGeneration(ImageGenerationThreadItem),
    #[serde(rename = "enteredReviewMode")]
    EnteredReviewMode(EnteredReviewModeThreadItem),
    #[serde(rename = "exitedReviewMode")]
    ExitedReviewMode(ExitedReviewModeThreadItem),
    #[serde(rename = "contextCompaction")]
    ContextCompaction(ContextCompactionThreadItem),
    /// A value this Codex version doesn't know, or a known one whose body didn't decode.
    #[serde(untagged)]
    Unknown(Value),
}

/// There are three ways to resume a thread: 1. By thread_id: load the thread from disk by thread_id and resume it. 2. By history: instantiate the thread from memory and resume it. 3. By path: load the thread from disk by path and resume it.
///
/// For non-running threads, the precedence is: history > non-empty path > thread_id. If using history or a non-empty path for a non-running thread, the thread_id param will be ignored.
///
/// If thread_id identifies a running thread, app-server rejoins that thread and treats a non-empty path as a consistency check against the active rollout path. Empty string path values are treated as absent.
///
/// Prefer using thread_id whenever possible.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct ThreadResumeParams {
    #[serde(rename = "approvalPolicy")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub approval_policy: Option<AskForApproval>,
    /// Override where approval requests are routed for review on this thread and subsequent turns.
    #[serde(rename = "approvalsReviewer")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub approvals_reviewer: Option<ApprovalsReviewer>,
    #[serde(rename = "baseInstructions")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub base_instructions: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub config: Option<BTreeMap<String, Value>>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub cwd: Option<String>,
    #[serde(rename = "developerInstructions")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub developer_instructions: Option<String>,
    /// When true, return only thread metadata and live-resume state without populating `thread.turns`. This is useful when the client plans to call `thread/turns/list` immediately after resuming. Full-history hydration is deprecated for paginated threads; use this with `thread/turns/list` and `thread/items/list` instead.
    #[serde(rename = "excludeTurns")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub exclude_turns: Option<bool>,
    /// Configuration overrides for the resumed thread, if any.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub model: Option<String>,
    #[serde(rename = "modelProvider")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub model_provider: Option<String>,
    /// @deprecated `friendly` and `pragmatic` no longer select a style. Changing this does not rewrite the thread's existing instructions.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub personality: Option<Personality>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub sandbox: Option<SandboxMode>,
    #[serde(rename = "serviceTier")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub service_tier: Option<String>,
    #[serde(rename = "threadId")]
    pub thread_id: String,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ThreadResumeResponse {
    #[serde(rename = "approvalPolicy")]
    pub approval_policy: AskForApproval,
    /// Reviewer currently used for approval requests on this thread.
    #[serde(rename = "approvalsReviewer")]
    pub approvals_reviewer: ApprovalsReviewer,
    /// Effective collaboration mode. Absent when resuming from an older server.
    #[serde(rename = "collaborationMode")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub collaboration_mode: Option<CollaborationMode>,
    pub cwd: AbsolutePathBuf,
    /// Saved list of disabled plugin IDs. Does not yet filter plugin capabilities.
    #[serde(rename = "disabledPluginIds")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub disabled_plugin_ids: Option<Vec<String>>,
    /// Environment-native paths to instruction source files currently loaded for this thread.
    #[serde(rename = "instructionSources")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub instruction_sources: Option<Vec<LegacyAppPathString>>,
    /// Opaque cursor for hydrating paginated items backwards.
    ///
    /// Pass this as `cursor` to `thread/items/list` with `sortDirection: "desc"`. The first page includes the item identified by the cursor.
    #[serde(rename = "itemsBackwardsCursor")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub items_backwards_cursor: Option<String>,
    pub model: String,
    #[serde(rename = "modelProvider")]
    pub model_provider: String,
    #[serde(rename = "reasoningEffort")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub reasoning_effort: Option<ReasoningEffort>,
    /// Legacy sandbox policy retained for compatibility. Experimental clients should prefer `activePermissionProfile` for profile provenance.
    pub sandbox: SandboxPolicy,
    #[serde(rename = "serviceTier")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub service_tier: Option<String>,
    pub thread: Thread,
    /// Opaque cursor for hydrating paginated turns backwards.
    ///
    /// Pass this as `cursor` to `thread/turns/list` with `sortDirection: "desc"`. The first page includes the turn identified by the cursor.
    #[serde(rename = "turnsBackwardsCursor")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub turns_backwards_cursor: Option<String>,
}

/// An independently persisted, user-visible thread section.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct ThreadSection {
    /// Optional appearance synchronized across clients.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub appearance: Option<ThreadSectionAppearance>,
    /// Opaque UUIDv7 identity that remains stable when the section is renamed.
    pub id: String,
    /// The current user-visible section name.
    pub name: String,
}

/// Extensible visual presentation for a custom thread section.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct ThreadSectionAppearance {
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub color: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub icon: Option<String>,
}

pub type ThreadSource = String;

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct ThreadStartParams {
    #[serde(rename = "approvalPolicy")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub approval_policy: Option<AskForApproval>,
    /// Override where approval requests are routed for review on this thread and subsequent turns.
    #[serde(rename = "approvalsReviewer")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub approvals_reviewer: Option<ApprovalsReviewer>,
    #[serde(rename = "baseInstructions")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub base_instructions: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub config: Option<BTreeMap<String, Value>>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub cwd: Option<String>,
    #[serde(rename = "developerInstructions")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub developer_instructions: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub ephemeral: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub model: Option<String>,
    #[serde(rename = "modelProvider")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub model_provider: Option<String>,
    /// @deprecated `friendly` and `pragmatic` no longer select a style.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub personality: Option<Personality>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub sandbox: Option<SandboxMode>,
    #[serde(rename = "serviceName")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub service_name: Option<String>,
    #[serde(rename = "serviceTier")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub service_tier: Option<String>,
    #[serde(rename = "sessionStartSource")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub session_start_source: Option<ThreadStartSource>,
    /// Optional client-supplied analytics source classification for this thread.
    #[serde(rename = "threadSource")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub thread_source: Option<ThreadSource>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ThreadStartResponse {
    #[serde(rename = "approvalPolicy")]
    pub approval_policy: AskForApproval,
    /// Reviewer currently used for approval requests on this thread.
    #[serde(rename = "approvalsReviewer")]
    pub approvals_reviewer: ApprovalsReviewer,
    pub cwd: AbsolutePathBuf,
    /// Saved list of disabled plugin IDs. Does not yet filter plugin capabilities.
    #[serde(rename = "disabledPluginIds")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub disabled_plugin_ids: Option<Vec<String>>,
    /// Environment-native paths to instruction source files currently loaded for this thread.
    #[serde(rename = "instructionSources")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub instruction_sources: Option<Vec<LegacyAppPathString>>,
    pub model: String,
    #[serde(rename = "modelProvider")]
    pub model_provider: String,
    #[serde(rename = "reasoningEffort")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub reasoning_effort: Option<ReasoningEffort>,
    /// Legacy sandbox policy retained for compatibility. Experimental clients should prefer `activePermissionProfile` for profile provenance.
    pub sandbox: SandboxPolicy,
    #[serde(rename = "serviceTier")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub service_tier: Option<String>,
    pub thread: Thread,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum ThreadStartSource {
    #[serde(rename = "startup")]
    Startup,
    #[serde(rename = "clear")]
    Clear,
    /// A value this Codex version doesn't know, or a known one whose body didn't decode.
    #[serde(untagged)]
    Unknown(Value),
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ThreadStartedNotification {
    pub thread: Thread,
}

pub type ThreadStatus = Value;

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ThreadTokenUsage {
    pub last: TokenUsageBreakdown,
    #[serde(rename = "modelContextWindow")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub model_context_window: Option<i64>,
    pub total: TokenUsageBreakdown,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ThreadTokenUsageUpdatedNotification {
    #[serde(rename = "threadId")]
    pub thread_id: String,
    #[serde(rename = "tokenUsage")]
    pub token_usage: ThreadTokenUsage,
    #[serde(rename = "turnId")]
    pub turn_id: String,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct TokenUsageBreakdown {
    #[serde(rename = "cacheWriteInputTokens")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub cache_write_input_tokens: Option<i64>,
    #[serde(rename = "cachedInputTokens")]
    pub cached_input_tokens: i64,
    #[serde(rename = "inputTokens")]
    pub input_tokens: i64,
    #[serde(rename = "outputTokens")]
    pub output_tokens: i64,
    #[serde(rename = "reasoningOutputTokens")]
    pub reasoning_output_tokens: i64,
    #[serde(rename = "totalTokens")]
    pub total_tokens: i64,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Turn {
    /// Unix timestamp (in seconds) when the turn completed.
    #[serde(rename = "completedAt")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub completed_at: Option<i64>,
    /// Duration between turn start and completion in milliseconds, if known.
    #[serde(rename = "durationMs")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub duration_ms: Option<i64>,
    /// Error associated with a failed or interrupted turn.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub error: Option<TurnError>,
    /// Identifier for this turn. Codex-generated turn IDs are UUIDv7.
    pub id: String,
    /// Thread items currently included in this turn payload.
    pub items: Vec<ThreadItem>,
    /// Describes how much of `items` has been loaded for this turn.
    #[serde(rename = "itemsView")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub items_view: Option<TurnItemsView>,
    /// ID of the first turn in the chain of work that led to this turn. Pass this as `rootTurnId` when starting work on behalf of this turn. May be null in older history or a `review/start` response.
    #[serde(rename = "rootTurnId")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub root_turn_id: Option<String>,
    /// Unix timestamp (in seconds) when the turn started.
    #[serde(rename = "startedAt")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub started_at: Option<i64>,
    pub status: TurnStatus,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct TurnCompletedNotification {
    #[serde(rename = "threadId")]
    pub thread_id: String,
    pub turn: Turn,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct TurnError {
    #[serde(rename = "additionalDetails")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub additional_details: Option<String>,
    #[serde(rename = "codexErrorInfo")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub codex_error_info: Option<CodexErrorInfo>,
    pub message: String,
    /// Optional public explanation and continuation instruction for a misalignment block.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub misalignment: Option<MisalignmentErrorDetails>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct TurnInterruptParams {
    #[serde(rename = "threadId")]
    pub thread_id: String,
    #[serde(rename = "turnId")]
    pub turn_id: String,
}

pub type TurnInterruptResponse = BTreeMap<String, Value>;

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum TurnItemsView {
    /// `items` was not loaded for this turn. The field is intentionally empty.
    #[serde(rename = "notLoaded")]
    NotLoaded,
    /// `items` contains only a display summary for this turn.
    #[serde(rename = "summary")]
    Summary,
    /// `items` contains every ThreadItem available from persisted app-server history for this turn.
    #[serde(rename = "full")]
    Full,
    /// A value this Codex version doesn't know, or a known one whose body didn't decode.
    #[serde(untagged)]
    Unknown(Value),
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct TurnStartParams {
    /// Override the approval policy for this turn and subsequent turns.
    #[serde(rename = "approvalPolicy")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub approval_policy: Option<AskForApproval>,
    /// Override where approval requests are routed for review on this turn and subsequent turns.
    #[serde(rename = "approvalsReviewer")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub approvals_reviewer: Option<ApprovalsReviewer>,
    #[serde(rename = "clientUserMessageId")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub client_user_message_id: Option<String>,
    /// Override the working directory for this turn and subsequent turns.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub cwd: Option<String>,
    /// Replace this thread's disabled plugin IDs. Omitted/null preserves the list; \[\] clears it.
    #[serde(rename = "disabledPluginIds")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub disabled_plugin_ids: Option<Vec<String>>,
    /// Override the reasoning effort for this turn and subsequent turns.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub effort: Option<ReasoningEffort>,
    pub input: Vec<UserInput>,
    /// Override the model for this turn and subsequent turns.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub model: Option<String>,
    /// Optional JSON Schema used to constrain the final assistant message for this turn.
    #[serde(rename = "outputSchema")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub output_schema: Option<Value>,
    /// ID of the turn that caused this new turn to start.
    ///
    /// Set this when starting work on behalf of another turn, such as delegated work in a different thread. Leave unset for work started directly by the user. Ignored when this request adds input to an active turn.
    #[serde(rename = "parentTurnId")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub parent_turn_id: Option<String>,
    /// @deprecated `friendly` and `pragmatic` no longer select a style. Changing this does not rewrite the thread's existing instructions.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub personality: Option<Personality>,
    /// ID of the first turn in the chain of work that led to this new turn.
    ///
    /// When setting `parentTurnId`, set this to the parent turn's `rootTurnId` when known. This keeps descendant work attributed to the original turn. If omitted, the new turn becomes its own root. Ignored when this request adds input to an active turn.
    #[serde(rename = "rootTurnId")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub root_turn_id: Option<String>,
    /// Override the sandbox policy for this turn and subsequent turns.
    #[serde(rename = "sandboxPolicy")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub sandbox_policy: Option<SandboxPolicy>,
    /// Override the service tier for this turn and subsequent turns.
    #[serde(rename = "serviceTier")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub service_tier: Option<String>,
    /// Override the service tier only when this request starts a new turn. Use "default" for standard speed. Omitted or null inherits the thread's tier. Does not change the thread's tier or a turn being steered.
    #[serde(rename = "serviceTierForTurn")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub service_tier_for_turn: Option<String>,
    /// Override the reasoning summary for this turn and subsequent turns.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub summary: Option<ReasoningSummary>,
    #[serde(rename = "threadId")]
    pub thread_id: String,
    #[serde(rename = "toolOutput")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub tool_output: Option<TurnToolOutput>,
    /// Optional source classification for the caller that starts this turn. Ignored when this request steers an already-active turn.
    #[serde(rename = "turnTrigger")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub turn_trigger: Option<String>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct TurnStartResponse {
    pub turn: Turn,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct TurnStartedNotification {
    #[serde(rename = "threadId")]
    pub thread_id: String,
    pub turn: Turn,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum TurnStatus {
    #[serde(rename = "completed")]
    Completed,
    #[serde(rename = "interrupted")]
    Interrupted,
    #[serde(rename = "failed")]
    Failed,
    #[serde(rename = "inProgress")]
    InProgress,
    /// A value this Codex version doesn't know, or a known one whose body didn't decode.
    #[serde(untagged)]
    Unknown(Value),
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct TurnToolOutput {
    pub name: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub namespace: Option<String>,
    pub output: FunctionCallOutputBody,
    /// Requests retention of this output in the thread's model history.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub retain: Option<bool>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct UpdatePatchChangeKind {
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub move_path: Option<String>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct UsageLimitExceededImageGenerationFailure {
    #[serde(rename = "limitId")]
    pub limit_id: String,
    #[serde(rename = "resetsAt")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub resets_at: Option<i64>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(tag = "type")]
pub enum UserInput {
    #[serde(rename = "text")]
    Text(TextUserInput),
    #[serde(rename = "image")]
    Image(ImageUserInput),
    #[serde(rename = "localImage")]
    LocalImage(LocalImageUserInput),
    #[serde(rename = "audio")]
    Audio(AudioUserInput),
    #[serde(rename = "localAudio")]
    LocalAudio(LocalAudioUserInput),
    #[serde(rename = "skill")]
    Skill(SkillUserInput),
    #[serde(rename = "mention")]
    Mention(MentionUserInput),
    /// A value this Codex version doesn't know, or a known one whose body didn't decode.
    #[serde(untagged)]
    Unknown(Value),
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct UserMessageThreadItem {
    #[serde(rename = "clientId")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub client_id: Option<String>,
    /// Unix timestamp in milliseconds when the item completed, if recorded.
    #[serde(rename = "completedAtMs")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub completed_at_ms: Option<i64>,
    pub content: Vec<UserInput>,
    pub id: String,
    /// Unix timestamp in milliseconds when the item started, if recorded.
    #[serde(rename = "startedAtMs")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub started_at_ms: Option<i64>,
}

pub type WebSearchAction = Value;

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct WebSearchThreadItem {
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub action: Option<WebSearchAction>,
    /// Unix timestamp in milliseconds when the item completed, if recorded.
    #[serde(rename = "completedAtMs")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub completed_at_ms: Option<i64>,
    pub id: String,
    pub query: String,
    /// Structured search results returned out-of-band by standalone web search.
    ///
    /// These stay as opaque JSON at the extension/app-server boundary so new result fields and result types can pass through without a Codex release.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub results: Option<Vec<Value>>,
    /// Unix timestamp in milliseconds when the item started, if recorded.
    #[serde(rename = "startedAtMs")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub started_at_ms: Option<i64>,
}