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
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
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
// Generated by scripts/protocol-gen-swift.ts — do not edit by hand
import Foundation

public let GATEWAY_PROTOCOL_VERSION = 3

public enum ErrorCode: String, Codable, Sendable {
    case notLinked = "NOT_LINKED"
    case notPaired = "NOT_PAIRED"
    case agentTimeout = "AGENT_TIMEOUT"
    case invalidRequest = "INVALID_REQUEST"
    case unavailable = "UNAVAILABLE"
}

public struct ConnectParams: Codable, Sendable {
    public let minprotocol: Int
    public let maxprotocol: Int
    public let client: [String: AnyCodable]
    public let caps: [String]?
    public let commands: [String]?
    public let permissions: [String: AnyCodable]?
    public let pathenv: String?
    public let role: String?
    public let scopes: [String]?
    public let device: [String: AnyCodable]?
    public let auth: [String: AnyCodable]?
    public let locale: String?
    public let useragent: String?

    public init(
        minprotocol: Int,
        maxprotocol: Int,
        client: [String: AnyCodable],
        caps: [String]?,
        commands: [String]?,
        permissions: [String: AnyCodable]?,
        pathenv: String?,
        role: String?,
        scopes: [String]?,
        device: [String: AnyCodable]?,
        auth: [String: AnyCodable]?,
        locale: String?,
        useragent: String?
    ) {
        self.minprotocol = minprotocol
        self.maxprotocol = maxprotocol
        self.client = client
        self.caps = caps
        self.commands = commands
        self.permissions = permissions
        self.pathenv = pathenv
        self.role = role
        self.scopes = scopes
        self.device = device
        self.auth = auth
        self.locale = locale
        self.useragent = useragent
    }
    private enum CodingKeys: String, CodingKey {
        case minprotocol = "minProtocol"
        case maxprotocol = "maxProtocol"
        case client
        case caps
        case commands
        case permissions
        case pathenv = "pathEnv"
        case role
        case scopes
        case device
        case auth
        case locale
        case useragent = "userAgent"
    }
}

public struct HelloOk: Codable, Sendable {
    public let type: String
    public let _protocol: Int
    public let server: [String: AnyCodable]
    public let features: [String: AnyCodable]
    public let snapshot: Snapshot
    public let canvashosturl: String?
    public let auth: [String: AnyCodable]?
    public let policy: [String: AnyCodable]

    public init(
        type: String,
        _protocol: Int,
        server: [String: AnyCodable],
        features: [String: AnyCodable],
        snapshot: Snapshot,
        canvashosturl: String?,
        auth: [String: AnyCodable]?,
        policy: [String: AnyCodable]
    ) {
        self.type = type
        self._protocol = _protocol
        self.server = server
        self.features = features
        self.snapshot = snapshot
        self.canvashosturl = canvashosturl
        self.auth = auth
        self.policy = policy
    }
    private enum CodingKeys: String, CodingKey {
        case type
        case _protocol = "protocol"
        case server
        case features
        case snapshot
        case canvashosturl = "canvasHostUrl"
        case auth
        case policy
    }
}

public struct RequestFrame: Codable, Sendable {
    public let type: String
    public let id: String
    public let method: String
    public let params: AnyCodable?

    public init(
        type: String,
        id: String,
        method: String,
        params: AnyCodable?
    ) {
        self.type = type
        self.id = id
        self.method = method
        self.params = params
    }
    private enum CodingKeys: String, CodingKey {
        case type
        case id
        case method
        case params
    }
}

public struct ResponseFrame: Codable, Sendable {
    public let type: String
    public let id: String
    public let ok: Bool
    public let payload: AnyCodable?
    public let error: [String: AnyCodable]?

    public init(
        type: String,
        id: String,
        ok: Bool,
        payload: AnyCodable?,
        error: [String: AnyCodable]?
    ) {
        self.type = type
        self.id = id
        self.ok = ok
        self.payload = payload
        self.error = error
    }
    private enum CodingKeys: String, CodingKey {
        case type
        case id
        case ok
        case payload
        case error
    }
}

public struct EventFrame: Codable, Sendable {
    public let type: String
    public let event: String
    public let payload: AnyCodable?
    public let seq: Int?
    public let stateversion: [String: AnyCodable]?

    public init(
        type: String,
        event: String,
        payload: AnyCodable?,
        seq: Int?,
        stateversion: [String: AnyCodable]?
    ) {
        self.type = type
        self.event = event
        self.payload = payload
        self.seq = seq
        self.stateversion = stateversion
    }
    private enum CodingKeys: String, CodingKey {
        case type
        case event
        case payload
        case seq
        case stateversion = "stateVersion"
    }
}

public struct PresenceEntry: Codable, Sendable {
    public let host: String?
    public let ip: String?
    public let version: String?
    public let platform: String?
    public let devicefamily: String?
    public let modelidentifier: String?
    public let mode: String?
    public let lastinputseconds: Int?
    public let reason: String?
    public let tags: [String]?
    public let text: String?
    public let ts: Int
    public let deviceid: String?
    public let roles: [String]?
    public let scopes: [String]?
    public let instanceid: String?

    public init(
        host: String?,
        ip: String?,
        version: String?,
        platform: String?,
        devicefamily: String?,
        modelidentifier: String?,
        mode: String?,
        lastinputseconds: Int?,
        reason: String?,
        tags: [String]?,
        text: String?,
        ts: Int,
        deviceid: String?,
        roles: [String]?,
        scopes: [String]?,
        instanceid: String?
    ) {
        self.host = host
        self.ip = ip
        self.version = version
        self.platform = platform
        self.devicefamily = devicefamily
        self.modelidentifier = modelidentifier
        self.mode = mode
        self.lastinputseconds = lastinputseconds
        self.reason = reason
        self.tags = tags
        self.text = text
        self.ts = ts
        self.deviceid = deviceid
        self.roles = roles
        self.scopes = scopes
        self.instanceid = instanceid
    }
    private enum CodingKeys: String, CodingKey {
        case host
        case ip
        case version
        case platform
        case devicefamily = "deviceFamily"
        case modelidentifier = "modelIdentifier"
        case mode
        case lastinputseconds = "lastInputSeconds"
        case reason
        case tags
        case text
        case ts
        case deviceid = "deviceId"
        case roles
        case scopes
        case instanceid = "instanceId"
    }
}

public struct StateVersion: Codable, Sendable {
    public let presence: Int
    public let health: Int

    public init(
        presence: Int,
        health: Int
    ) {
        self.presence = presence
        self.health = health
    }
    private enum CodingKeys: String, CodingKey {
        case presence
        case health
    }
}

public struct Snapshot: Codable, Sendable {
    public let presence: [PresenceEntry]
    public let health: AnyCodable
    public let stateversion: StateVersion
    public let uptimems: Int
    public let configpath: String?
    public let statedir: String?
    public let sessiondefaults: [String: AnyCodable]?

    public init(
        presence: [PresenceEntry],
        health: AnyCodable,
        stateversion: StateVersion,
        uptimems: Int,
        configpath: String?,
        statedir: String?,
        sessiondefaults: [String: AnyCodable]?
    ) {
        self.presence = presence
        self.health = health
        self.stateversion = stateversion
        self.uptimems = uptimems
        self.configpath = configpath
        self.statedir = statedir
        self.sessiondefaults = sessiondefaults
    }
    private enum CodingKeys: String, CodingKey {
        case presence
        case health
        case stateversion = "stateVersion"
        case uptimems = "uptimeMs"
        case configpath = "configPath"
        case statedir = "stateDir"
        case sessiondefaults = "sessionDefaults"
    }
}

public struct ErrorShape: Codable, Sendable {
    public let code: String
    public let message: String
    public let details: AnyCodable?
    public let retryable: Bool?
    public let retryafterms: Int?

    public init(
        code: String,
        message: String,
        details: AnyCodable?,
        retryable: Bool?,
        retryafterms: Int?
    ) {
        self.code = code
        self.message = message
        self.details = details
        self.retryable = retryable
        self.retryafterms = retryafterms
    }
    private enum CodingKeys: String, CodingKey {
        case code
        case message
        case details
        case retryable
        case retryafterms = "retryAfterMs"
    }
}

public struct AgentEvent: Codable, Sendable {
    public let runid: String
    public let seq: Int
    public let stream: String
    public let ts: Int
    public let data: [String: AnyCodable]

    public init(
        runid: String,
        seq: Int,
        stream: String,
        ts: Int,
        data: [String: AnyCodable]
    ) {
        self.runid = runid
        self.seq = seq
        self.stream = stream
        self.ts = ts
        self.data = data
    }
    private enum CodingKeys: String, CodingKey {
        case runid = "runId"
        case seq
        case stream
        case ts
        case data
    }
}

public struct SendParams: Codable, Sendable {
    public let to: String
    public let message: String
    public let mediaurl: String?
    public let mediaurls: [String]?
    public let gifplayback: Bool?
    public let channel: String?
    public let accountid: String?
    public let sessionkey: String?
    public let idempotencykey: String

    public init(
        to: String,
        message: String,
        mediaurl: String?,
        mediaurls: [String]?,
        gifplayback: Bool?,
        channel: String?,
        accountid: String?,
        sessionkey: String?,
        idempotencykey: String
    ) {
        self.to = to
        self.message = message
        self.mediaurl = mediaurl
        self.mediaurls = mediaurls
        self.gifplayback = gifplayback
        self.channel = channel
        self.accountid = accountid
        self.sessionkey = sessionkey
        self.idempotencykey = idempotencykey
    }
    private enum CodingKeys: String, CodingKey {
        case to
        case message
        case mediaurl = "mediaUrl"
        case mediaurls = "mediaUrls"
        case gifplayback = "gifPlayback"
        case channel
        case accountid = "accountId"
        case sessionkey = "sessionKey"
        case idempotencykey = "idempotencyKey"
    }
}

public struct PollParams: Codable, Sendable {
    public let to: String
    public let question: String
    public let options: [String]
    public let maxselections: Int?
    public let durationhours: Int?
    public let channel: String?
    public let accountid: String?
    public let idempotencykey: String

    public init(
        to: String,
        question: String,
        options: [String],
        maxselections: Int?,
        durationhours: Int?,
        channel: String?,
        accountid: String?,
        idempotencykey: String
    ) {
        self.to = to
        self.question = question
        self.options = options
        self.maxselections = maxselections
        self.durationhours = durationhours
        self.channel = channel
        self.accountid = accountid
        self.idempotencykey = idempotencykey
    }
    private enum CodingKeys: String, CodingKey {
        case to
        case question
        case options
        case maxselections = "maxSelections"
        case durationhours = "durationHours"
        case channel
        case accountid = "accountId"
        case idempotencykey = "idempotencyKey"
    }
}

public struct AgentParams: Codable, Sendable {
    public let message: String
    public let agentid: String?
    public let to: String?
    public let replyto: String?
    public let sessionid: String?
    public let sessionkey: String?
    public let thinking: String?
    public let deliver: Bool?
    public let attachments: [AnyCodable]?
    public let channel: String?
    public let replychannel: String?
    public let accountid: String?
    public let replyaccountid: String?
    public let threadid: String?
    public let groupid: String?
    public let groupchannel: String?
    public let groupspace: String?
    public let timeout: Int?
    public let lane: String?
    public let extrasystemprompt: String?
    public let idempotencykey: String
    public let label: String?
    public let spawnedby: String?

    public init(
        message: String,
        agentid: String?,
        to: String?,
        replyto: String?,
        sessionid: String?,
        sessionkey: String?,
        thinking: String?,
        deliver: Bool?,
        attachments: [AnyCodable]?,
        channel: String?,
        replychannel: String?,
        accountid: String?,
        replyaccountid: String?,
        threadid: String?,
        groupid: String?,
        groupchannel: String?,
        groupspace: String?,
        timeout: Int?,
        lane: String?,
        extrasystemprompt: String?,
        idempotencykey: String,
        label: String?,
        spawnedby: String?
    ) {
        self.message = message
        self.agentid = agentid
        self.to = to
        self.replyto = replyto
        self.sessionid = sessionid
        self.sessionkey = sessionkey
        self.thinking = thinking
        self.deliver = deliver
        self.attachments = attachments
        self.channel = channel
        self.replychannel = replychannel
        self.accountid = accountid
        self.replyaccountid = replyaccountid
        self.threadid = threadid
        self.groupid = groupid
        self.groupchannel = groupchannel
        self.groupspace = groupspace
        self.timeout = timeout
        self.lane = lane
        self.extrasystemprompt = extrasystemprompt
        self.idempotencykey = idempotencykey
        self.label = label
        self.spawnedby = spawnedby
    }
    private enum CodingKeys: String, CodingKey {
        case message
        case agentid = "agentId"
        case to
        case replyto = "replyTo"
        case sessionid = "sessionId"
        case sessionkey = "sessionKey"
        case thinking
        case deliver
        case attachments
        case channel
        case replychannel = "replyChannel"
        case accountid = "accountId"
        case replyaccountid = "replyAccountId"
        case threadid = "threadId"
        case groupid = "groupId"
        case groupchannel = "groupChannel"
        case groupspace = "groupSpace"
        case timeout
        case lane
        case extrasystemprompt = "extraSystemPrompt"
        case idempotencykey = "idempotencyKey"
        case label
        case spawnedby = "spawnedBy"
    }
}

public struct AgentIdentityParams: Codable, Sendable {
    public let agentid: String?
    public let sessionkey: String?

    public init(
        agentid: String?,
        sessionkey: String?
    ) {
        self.agentid = agentid
        self.sessionkey = sessionkey
    }
    private enum CodingKeys: String, CodingKey {
        case agentid = "agentId"
        case sessionkey = "sessionKey"
    }
}

public struct AgentIdentityResult: Codable, Sendable {
    public let agentid: String
    public let name: String?
    public let avatar: String?

    public init(
        agentid: String,
        name: String?,
        avatar: String?
    ) {
        self.agentid = agentid
        self.name = name
        self.avatar = avatar
    }
    private enum CodingKeys: String, CodingKey {
        case agentid = "agentId"
        case name
        case avatar
    }
}

public struct AgentWaitParams: Codable, Sendable {
    public let runid: String
    public let timeoutms: Int?

    public init(
        runid: String,
        timeoutms: Int?
    ) {
        self.runid = runid
        self.timeoutms = timeoutms
    }
    private enum CodingKeys: String, CodingKey {
        case runid = "runId"
        case timeoutms = "timeoutMs"
    }
}

public struct WakeParams: Codable, Sendable {
    public let mode: AnyCodable
    public let text: String

    public init(
        mode: AnyCodable,
        text: String
    ) {
        self.mode = mode
        self.text = text
    }
    private enum CodingKeys: String, CodingKey {
        case mode
        case text
    }
}

public struct NodePairRequestParams: Codable, Sendable {
    public let nodeid: String
    public let displayname: String?
    public let platform: String?
    public let version: String?
    public let coreversion: String?
    public let uiversion: String?
    public let devicefamily: String?
    public let modelidentifier: String?
    public let caps: [String]?
    public let commands: [String]?
    public let remoteip: String?
    public let silent: Bool?

    public init(
        nodeid: String,
        displayname: String?,
        platform: String?,
        version: String?,
        coreversion: String?,
        uiversion: String?,
        devicefamily: String?,
        modelidentifier: String?,
        caps: [String]?,
        commands: [String]?,
        remoteip: String?,
        silent: Bool?
    ) {
        self.nodeid = nodeid
        self.displayname = displayname
        self.platform = platform
        self.version = version
        self.coreversion = coreversion
        self.uiversion = uiversion
        self.devicefamily = devicefamily
        self.modelidentifier = modelidentifier
        self.caps = caps
        self.commands = commands
        self.remoteip = remoteip
        self.silent = silent
    }
    private enum CodingKeys: String, CodingKey {
        case nodeid = "nodeId"
        case displayname = "displayName"
        case platform
        case version
        case coreversion = "coreVersion"
        case uiversion = "uiVersion"
        case devicefamily = "deviceFamily"
        case modelidentifier = "modelIdentifier"
        case caps
        case commands
        case remoteip = "remoteIp"
        case silent
    }
}

public struct NodePairListParams: Codable, Sendable {
}

public struct NodePairApproveParams: Codable, Sendable {
    public let requestid: String

    public init(
        requestid: String
    ) {
        self.requestid = requestid
    }
    private enum CodingKeys: String, CodingKey {
        case requestid = "requestId"
    }
}

public struct NodePairRejectParams: Codable, Sendable {
    public let requestid: String

    public init(
        requestid: String
    ) {
        self.requestid = requestid
    }
    private enum CodingKeys: String, CodingKey {
        case requestid = "requestId"
    }
}

public struct NodePairVerifyParams: Codable, Sendable {
    public let nodeid: String
    public let token: String

    public init(
        nodeid: String,
        token: String
    ) {
        self.nodeid = nodeid
        self.token = token
    }
    private enum CodingKeys: String, CodingKey {
        case nodeid = "nodeId"
        case token
    }
}

public struct NodeRenameParams: Codable, Sendable {
    public let nodeid: String
    public let displayname: String

    public init(
        nodeid: String,
        displayname: String
    ) {
        self.nodeid = nodeid
        self.displayname = displayname
    }
    private enum CodingKeys: String, CodingKey {
        case nodeid = "nodeId"
        case displayname = "displayName"
    }
}

public struct NodeListParams: Codable, Sendable {
}

public struct NodeDescribeParams: Codable, Sendable {
    public let nodeid: String

    public init(
        nodeid: String
    ) {
        self.nodeid = nodeid
    }
    private enum CodingKeys: String, CodingKey {
        case nodeid = "nodeId"
    }
}

public struct NodeInvokeParams: Codable, Sendable {
    public let nodeid: String
    public let command: String
    public let params: AnyCodable?
    public let timeoutms: Int?
    public let idempotencykey: String

    public init(
        nodeid: String,
        command: String,
        params: AnyCodable?,
        timeoutms: Int?,
        idempotencykey: String
    ) {
        self.nodeid = nodeid
        self.command = command
        self.params = params
        self.timeoutms = timeoutms
        self.idempotencykey = idempotencykey
    }
    private enum CodingKeys: String, CodingKey {
        case nodeid = "nodeId"
        case command
        case params
        case timeoutms = "timeoutMs"
        case idempotencykey = "idempotencyKey"
    }
}

public struct NodeInvokeResultParams: Codable, Sendable {
    public let id: String
    public let nodeid: String
    public let ok: Bool
    public let payload: AnyCodable?
    public let payloadjson: String?
    public let error: [String: AnyCodable]?

    public init(
        id: String,
        nodeid: String,
        ok: Bool,
        payload: AnyCodable?,
        payloadjson: String?,
        error: [String: AnyCodable]?
    ) {
        self.id = id
        self.nodeid = nodeid
        self.ok = ok
        self.payload = payload
        self.payloadjson = payloadjson
        self.error = error
    }
    private enum CodingKeys: String, CodingKey {
        case id
        case nodeid = "nodeId"
        case ok
        case payload
        case payloadjson = "payloadJSON"
        case error
    }
}

public struct NodeEventParams: Codable, Sendable {
    public let event: String
    public let payload: AnyCodable?
    public let payloadjson: String?

    public init(
        event: String,
        payload: AnyCodable?,
        payloadjson: String?
    ) {
        self.event = event
        self.payload = payload
        self.payloadjson = payloadjson
    }
    private enum CodingKeys: String, CodingKey {
        case event
        case payload
        case payloadjson = "payloadJSON"
    }
}

public struct NodeInvokeRequestEvent: Codable, Sendable {
    public let id: String
    public let nodeid: String
    public let command: String
    public let paramsjson: String?
    public let timeoutms: Int?
    public let idempotencykey: String?

    public init(
        id: String,
        nodeid: String,
        command: String,
        paramsjson: String?,
        timeoutms: Int?,
        idempotencykey: String?
    ) {
        self.id = id
        self.nodeid = nodeid
        self.command = command
        self.paramsjson = paramsjson
        self.timeoutms = timeoutms
        self.idempotencykey = idempotencykey
    }
    private enum CodingKeys: String, CodingKey {
        case id
        case nodeid = "nodeId"
        case command
        case paramsjson = "paramsJSON"
        case timeoutms = "timeoutMs"
        case idempotencykey = "idempotencyKey"
    }
}

public struct SessionsListParams: Codable, Sendable {
    public let limit: Int?
    public let activeminutes: Int?
    public let includeglobal: Bool?
    public let includeunknown: Bool?
    public let includederivedtitles: Bool?
    public let includelastmessage: Bool?
    public let label: String?
    public let spawnedby: String?
    public let agentid: String?
    public let search: String?

    public init(
        limit: Int?,
        activeminutes: Int?,
        includeglobal: Bool?,
        includeunknown: Bool?,
        includederivedtitles: Bool?,
        includelastmessage: Bool?,
        label: String?,
        spawnedby: String?,
        agentid: String?,
        search: String?
    ) {
        self.limit = limit
        self.activeminutes = activeminutes
        self.includeglobal = includeglobal
        self.includeunknown = includeunknown
        self.includederivedtitles = includederivedtitles
        self.includelastmessage = includelastmessage
        self.label = label
        self.spawnedby = spawnedby
        self.agentid = agentid
        self.search = search
    }
    private enum CodingKeys: String, CodingKey {
        case limit
        case activeminutes = "activeMinutes"
        case includeglobal = "includeGlobal"
        case includeunknown = "includeUnknown"
        case includederivedtitles = "includeDerivedTitles"
        case includelastmessage = "includeLastMessage"
        case label
        case spawnedby = "spawnedBy"
        case agentid = "agentId"
        case search
    }
}

public struct SessionsPreviewParams: Codable, Sendable {
    public let keys: [String]
    public let limit: Int?
    public let maxchars: Int?

    public init(
        keys: [String],
        limit: Int?,
        maxchars: Int?
    ) {
        self.keys = keys
        self.limit = limit
        self.maxchars = maxchars
    }
    private enum CodingKeys: String, CodingKey {
        case keys
        case limit
        case maxchars = "maxChars"
    }
}

public struct SessionsResolveParams: Codable, Sendable {
    public let key: String?
    public let sessionid: String?
    public let label: String?
    public let agentid: String?
    public let spawnedby: String?
    public let includeglobal: Bool?
    public let includeunknown: Bool?

    public init(
        key: String?,
        sessionid: String?,
        label: String?,
        agentid: String?,
        spawnedby: String?,
        includeglobal: Bool?,
        includeunknown: Bool?
    ) {
        self.key = key
        self.sessionid = sessionid
        self.label = label
        self.agentid = agentid
        self.spawnedby = spawnedby
        self.includeglobal = includeglobal
        self.includeunknown = includeunknown
    }
    private enum CodingKeys: String, CodingKey {
        case key
        case sessionid = "sessionId"
        case label
        case agentid = "agentId"
        case spawnedby = "spawnedBy"
        case includeglobal = "includeGlobal"
        case includeunknown = "includeUnknown"
    }
}

public struct SessionsPatchParams: Codable, Sendable {
    public let key: String
    public let label: AnyCodable?
    public let thinkinglevel: AnyCodable?
    public let verboselevel: AnyCodable?
    public let reasoninglevel: AnyCodable?
    public let responseusage: AnyCodable?
    public let elevatedlevel: AnyCodable?
    public let exechost: AnyCodable?
    public let execsecurity: AnyCodable?
    public let execask: AnyCodable?
    public let execnode: AnyCodable?
    public let model: AnyCodable?
    public let spawnedby: AnyCodable?
    public let sendpolicy: AnyCodable?
    public let groupactivation: AnyCodable?

    public init(
        key: String,
        label: AnyCodable?,
        thinkinglevel: AnyCodable?,
        verboselevel: AnyCodable?,
        reasoninglevel: AnyCodable?,
        responseusage: AnyCodable?,
        elevatedlevel: AnyCodable?,
        exechost: AnyCodable?,
        execsecurity: AnyCodable?,
        execask: AnyCodable?,
        execnode: AnyCodable?,
        model: AnyCodable?,
        spawnedby: AnyCodable?,
        sendpolicy: AnyCodable?,
        groupactivation: AnyCodable?
    ) {
        self.key = key
        self.label = label
        self.thinkinglevel = thinkinglevel
        self.verboselevel = verboselevel
        self.reasoninglevel = reasoninglevel
        self.responseusage = responseusage
        self.elevatedlevel = elevatedlevel
        self.exechost = exechost
        self.execsecurity = execsecurity
        self.execask = execask
        self.execnode = execnode
        self.model = model
        self.spawnedby = spawnedby
        self.sendpolicy = sendpolicy
        self.groupactivation = groupactivation
    }
    private enum CodingKeys: String, CodingKey {
        case key
        case label
        case thinkinglevel = "thinkingLevel"
        case verboselevel = "verboseLevel"
        case reasoninglevel = "reasoningLevel"
        case responseusage = "responseUsage"
        case elevatedlevel = "elevatedLevel"
        case exechost = "execHost"
        case execsecurity = "execSecurity"
        case execask = "execAsk"
        case execnode = "execNode"
        case model
        case spawnedby = "spawnedBy"
        case sendpolicy = "sendPolicy"
        case groupactivation = "groupActivation"
    }
}

public struct SessionsResetParams: Codable, Sendable {
    public let key: String

    public init(
        key: String
    ) {
        self.key = key
    }
    private enum CodingKeys: String, CodingKey {
        case key
    }
}

public struct SessionsDeleteParams: Codable, Sendable {
    public let key: String
    public let deletetranscript: Bool?

    public init(
        key: String,
        deletetranscript: Bool?
    ) {
        self.key = key
        self.deletetranscript = deletetranscript
    }
    private enum CodingKeys: String, CodingKey {
        case key
        case deletetranscript = "deleteTranscript"
    }
}

public struct SessionsCompactParams: Codable, Sendable {
    public let key: String
    public let maxlines: Int?

    public init(
        key: String,
        maxlines: Int?
    ) {
        self.key = key
        self.maxlines = maxlines
    }
    private enum CodingKeys: String, CodingKey {
        case key
        case maxlines = "maxLines"
    }
}

public struct ConfigGetParams: Codable, Sendable {
}

public struct ConfigSetParams: Codable, Sendable {
    public let raw: String
    public let basehash: String?

    public init(
        raw: String,
        basehash: String?
    ) {
        self.raw = raw
        self.basehash = basehash
    }
    private enum CodingKeys: String, CodingKey {
        case raw
        case basehash = "baseHash"
    }
}

public struct ConfigApplyParams: Codable, Sendable {
    public let raw: String
    public let basehash: String?
    public let sessionkey: String?
    public let note: String?
    public let restartdelayms: Int?

    public init(
        raw: String,
        basehash: String?,
        sessionkey: String?,
        note: String?,
        restartdelayms: Int?
    ) {
        self.raw = raw
        self.basehash = basehash
        self.sessionkey = sessionkey
        self.note = note
        self.restartdelayms = restartdelayms
    }
    private enum CodingKeys: String, CodingKey {
        case raw
        case basehash = "baseHash"
        case sessionkey = "sessionKey"
        case note
        case restartdelayms = "restartDelayMs"
    }
}

public struct ConfigPatchParams: Codable, Sendable {
    public let raw: String
    public let basehash: String?
    public let sessionkey: String?
    public let note: String?
    public let restartdelayms: Int?

    public init(
        raw: String,
        basehash: String?,
        sessionkey: String?,
        note: String?,
        restartdelayms: Int?
    ) {
        self.raw = raw
        self.basehash = basehash
        self.sessionkey = sessionkey
        self.note = note
        self.restartdelayms = restartdelayms
    }
    private enum CodingKeys: String, CodingKey {
        case raw
        case basehash = "baseHash"
        case sessionkey = "sessionKey"
        case note
        case restartdelayms = "restartDelayMs"
    }
}

public struct ConfigSchemaParams: Codable, Sendable {
}

public struct ConfigSchemaResponse: Codable, Sendable {
    public let schema: AnyCodable
    public let uihints: [String: AnyCodable]
    public let version: String
    public let generatedat: String

    public init(
        schema: AnyCodable,
        uihints: [String: AnyCodable],
        version: String,
        generatedat: String
    ) {
        self.schema = schema
        self.uihints = uihints
        self.version = version
        self.generatedat = generatedat
    }
    private enum CodingKeys: String, CodingKey {
        case schema
        case uihints = "uiHints"
        case version
        case generatedat = "generatedAt"
    }
}

public struct WizardStartParams: Codable, Sendable {
    public let mode: AnyCodable?
    public let workspace: String?

    public init(
        mode: AnyCodable?,
        workspace: String?
    ) {
        self.mode = mode
        self.workspace = workspace
    }
    private enum CodingKeys: String, CodingKey {
        case mode
        case workspace
    }
}

public struct WizardNextParams: Codable, Sendable {
    public let sessionid: String
    public let answer: [String: AnyCodable]?

    public init(
        sessionid: String,
        answer: [String: AnyCodable]?
    ) {
        self.sessionid = sessionid
        self.answer = answer
    }
    private enum CodingKeys: String, CodingKey {
        case sessionid = "sessionId"
        case answer
    }
}

public struct WizardCancelParams: Codable, Sendable {
    public let sessionid: String

    public init(
        sessionid: String
    ) {
        self.sessionid = sessionid
    }
    private enum CodingKeys: String, CodingKey {
        case sessionid = "sessionId"
    }
}

public struct WizardStatusParams: Codable, Sendable {
    public let sessionid: String

    public init(
        sessionid: String
    ) {
        self.sessionid = sessionid
    }
    private enum CodingKeys: String, CodingKey {
        case sessionid = "sessionId"
    }
}

public struct WizardStep: Codable, Sendable {
    public let id: String
    public let type: AnyCodable
    public let title: String?
    public let message: String?
    public let options: [[String: AnyCodable]]?
    public let initialvalue: AnyCodable?
    public let placeholder: String?
    public let sensitive: Bool?
    public let executor: AnyCodable?

    public init(
        id: String,
        type: AnyCodable,
        title: String?,
        message: String?,
        options: [[String: AnyCodable]]?,
        initialvalue: AnyCodable?,
        placeholder: String?,
        sensitive: Bool?,
        executor: AnyCodable?
    ) {
        self.id = id
        self.type = type
        self.title = title
        self.message = message
        self.options = options
        self.initialvalue = initialvalue
        self.placeholder = placeholder
        self.sensitive = sensitive
        self.executor = executor
    }
    private enum CodingKeys: String, CodingKey {
        case id
        case type
        case title
        case message
        case options
        case initialvalue = "initialValue"
        case placeholder
        case sensitive
        case executor
    }
}

public struct WizardNextResult: Codable, Sendable {
    public let done: Bool
    public let step: [String: AnyCodable]?
    public let status: AnyCodable?
    public let error: String?

    public init(
        done: Bool,
        step: [String: AnyCodable]?,
        status: AnyCodable?,
        error: String?
    ) {
        self.done = done
        self.step = step
        self.status = status
        self.error = error
    }
    private enum CodingKeys: String, CodingKey {
        case done
        case step
        case status
        case error
    }
}

public struct WizardStartResult: Codable, Sendable {
    public let sessionid: String
    public let done: Bool
    public let step: [String: AnyCodable]?
    public let status: AnyCodable?
    public let error: String?

    public init(
        sessionid: String,
        done: Bool,
        step: [String: AnyCodable]?,
        status: AnyCodable?,
        error: String?
    ) {
        self.sessionid = sessionid
        self.done = done
        self.step = step
        self.status = status
        self.error = error
    }
    private enum CodingKeys: String, CodingKey {
        case sessionid = "sessionId"
        case done
        case step
        case status
        case error
    }
}

public struct WizardStatusResult: Codable, Sendable {
    public let status: AnyCodable
    public let error: String?

    public init(
        status: AnyCodable,
        error: String?
    ) {
        self.status = status
        self.error = error
    }
    private enum CodingKeys: String, CodingKey {
        case status
        case error
    }
}

public struct TalkModeParams: Codable, Sendable {
    public let enabled: Bool
    public let phase: String?

    public init(
        enabled: Bool,
        phase: String?
    ) {
        self.enabled = enabled
        self.phase = phase
    }
    private enum CodingKeys: String, CodingKey {
        case enabled
        case phase
    }
}

public struct ChannelsStatusParams: Codable, Sendable {
    public let probe: Bool?
    public let timeoutms: Int?

    public init(
        probe: Bool?,
        timeoutms: Int?
    ) {
        self.probe = probe
        self.timeoutms = timeoutms
    }
    private enum CodingKeys: String, CodingKey {
        case probe
        case timeoutms = "timeoutMs"
    }
}

public struct ChannelsStatusResult: Codable, Sendable {
    public let ts: Int
    public let channelorder: [String]
    public let channellabels: [String: AnyCodable]
    public let channeldetaillabels: [String: AnyCodable]?
    public let channelsystemimages: [String: AnyCodable]?
    public let channelmeta: [[String: AnyCodable]]?
    public let channels: [String: AnyCodable]
    public let channelaccounts: [String: AnyCodable]
    public let channeldefaultaccountid: [String: AnyCodable]

    public init(
        ts: Int,
        channelorder: [String],
        channellabels: [String: AnyCodable],
        channeldetaillabels: [String: AnyCodable]?,
        channelsystemimages: [String: AnyCodable]?,
        channelmeta: [[String: AnyCodable]]?,
        channels: [String: AnyCodable],
        channelaccounts: [String: AnyCodable],
        channeldefaultaccountid: [String: AnyCodable]
    ) {
        self.ts = ts
        self.channelorder = channelorder
        self.channellabels = channellabels
        self.channeldetaillabels = channeldetaillabels
        self.channelsystemimages = channelsystemimages
        self.channelmeta = channelmeta
        self.channels = channels
        self.channelaccounts = channelaccounts
        self.channeldefaultaccountid = channeldefaultaccountid
    }
    private enum CodingKeys: String, CodingKey {
        case ts
        case channelorder = "channelOrder"
        case channellabels = "channelLabels"
        case channeldetaillabels = "channelDetailLabels"
        case channelsystemimages = "channelSystemImages"
        case channelmeta = "channelMeta"
        case channels
        case channelaccounts = "channelAccounts"
        case channeldefaultaccountid = "channelDefaultAccountId"
    }
}

public struct ChannelsLogoutParams: Codable, Sendable {
    public let channel: String
    public let accountid: String?

    public init(
        channel: String,
        accountid: String?
    ) {
        self.channel = channel
        self.accountid = accountid
    }
    private enum CodingKeys: String, CodingKey {
        case channel
        case accountid = "accountId"
    }
}

public struct WebLoginStartParams: Codable, Sendable {
    public let force: Bool?
    public let timeoutms: Int?
    public let verbose: Bool?
    public let accountid: String?

    public init(
        force: Bool?,
        timeoutms: Int?,
        verbose: Bool?,
        accountid: String?
    ) {
        self.force = force
        self.timeoutms = timeoutms
        self.verbose = verbose
        self.accountid = accountid
    }
    private enum CodingKeys: String, CodingKey {
        case force
        case timeoutms = "timeoutMs"
        case verbose
        case accountid = "accountId"
    }
}

public struct WebLoginWaitParams: Codable, Sendable {
    public let timeoutms: Int?
    public let accountid: String?

    public init(
        timeoutms: Int?,
        accountid: String?
    ) {
        self.timeoutms = timeoutms
        self.accountid = accountid
    }
    private enum CodingKeys: String, CodingKey {
        case timeoutms = "timeoutMs"
        case accountid = "accountId"
    }
}

public struct AgentSummary: Codable, Sendable {
    public let id: String
    public let name: String?
    public let identity: [String: AnyCodable]?

    public init(
        id: String,
        name: String?,
        identity: [String: AnyCodable]?
    ) {
        self.id = id
        self.name = name
        self.identity = identity
    }
    private enum CodingKeys: String, CodingKey {
        case id
        case name
        case identity
    }
}

public struct AgentsListParams: Codable, Sendable {
}

public struct AgentsListResult: Codable, Sendable {
    public let defaultid: String
    public let mainkey: String
    public let scope: AnyCodable
    public let agents: [AgentSummary]

    public init(
        defaultid: String,
        mainkey: String,
        scope: AnyCodable,
        agents: [AgentSummary]
    ) {
        self.defaultid = defaultid
        self.mainkey = mainkey
        self.scope = scope
        self.agents = agents
    }
    private enum CodingKeys: String, CodingKey {
        case defaultid = "defaultId"
        case mainkey = "mainKey"
        case scope
        case agents
    }
}

public struct ModelChoice: Codable, Sendable {
    public let id: String
    public let name: String
    public let provider: String
    public let contextwindow: Int?
    public let reasoning: Bool?

    public init(
        id: String,
        name: String,
        provider: String,
        contextwindow: Int?,
        reasoning: Bool?
    ) {
        self.id = id
        self.name = name
        self.provider = provider
        self.contextwindow = contextwindow
        self.reasoning = reasoning
    }
    private enum CodingKeys: String, CodingKey {
        case id
        case name
        case provider
        case contextwindow = "contextWindow"
        case reasoning
    }
}

public struct ModelsListParams: Codable, Sendable {
}

public struct ModelsListResult: Codable, Sendable {
    public let models: [ModelChoice]

    public init(
        models: [ModelChoice]
    ) {
        self.models = models
    }
    private enum CodingKeys: String, CodingKey {
        case models
    }
}

public struct SkillsStatusParams: Codable, Sendable {
}

public struct SkillsBinsParams: Codable, Sendable {
}

public struct SkillsBinsResult: Codable, Sendable {
    public let bins: [String]

    public init(
        bins: [String]
    ) {
        self.bins = bins
    }
    private enum CodingKeys: String, CodingKey {
        case bins
    }
}

public struct SkillsInstallParams: Codable, Sendable {
    public let name: String
    public let installid: String
    public let timeoutms: Int?

    public init(
        name: String,
        installid: String,
        timeoutms: Int?
    ) {
        self.name = name
        self.installid = installid
        self.timeoutms = timeoutms
    }
    private enum CodingKeys: String, CodingKey {
        case name
        case installid = "installId"
        case timeoutms = "timeoutMs"
    }
}

public struct SkillsUpdateParams: Codable, Sendable {
    public let skillkey: String
    public let enabled: Bool?
    public let apikey: String?
    public let env: [String: AnyCodable]?

    public init(
        skillkey: String,
        enabled: Bool?,
        apikey: String?,
        env: [String: AnyCodable]?
    ) {
        self.skillkey = skillkey
        self.enabled = enabled
        self.apikey = apikey
        self.env = env
    }
    private enum CodingKeys: String, CodingKey {
        case skillkey = "skillKey"
        case enabled
        case apikey = "apiKey"
        case env
    }
}

public struct CronJob: Codable, Sendable {
    public let id: String
    public let agentid: String?
    public let name: String
    public let description: String?
    public let enabled: Bool
    public let deleteafterrun: Bool?
    public let createdatms: Int
    public let updatedatms: Int
    public let schedule: AnyCodable
    public let sessiontarget: AnyCodable
    public let wakemode: AnyCodable
    public let payload: AnyCodable
    public let isolation: [String: AnyCodable]?
    public let state: [String: AnyCodable]

    public init(
        id: String,
        agentid: String?,
        name: String,
        description: String?,
        enabled: Bool,
        deleteafterrun: Bool?,
        createdatms: Int,
        updatedatms: Int,
        schedule: AnyCodable,
        sessiontarget: AnyCodable,
        wakemode: AnyCodable,
        payload: AnyCodable,
        isolation: [String: AnyCodable]?,
        state: [String: AnyCodable]
    ) {
        self.id = id
        self.agentid = agentid
        self.name = name
        self.description = description
        self.enabled = enabled
        self.deleteafterrun = deleteafterrun
        self.createdatms = createdatms
        self.updatedatms = updatedatms
        self.schedule = schedule
        self.sessiontarget = sessiontarget
        self.wakemode = wakemode
        self.payload = payload
        self.isolation = isolation
        self.state = state
    }
    private enum CodingKeys: String, CodingKey {
        case id
        case agentid = "agentId"
        case name
        case description
        case enabled
        case deleteafterrun = "deleteAfterRun"
        case createdatms = "createdAtMs"
        case updatedatms = "updatedAtMs"
        case schedule
        case sessiontarget = "sessionTarget"
        case wakemode = "wakeMode"
        case payload
        case isolation
        case state
    }
}

public struct CronListParams: Codable, Sendable {
    public let includedisabled: Bool?

    public init(
        includedisabled: Bool?
    ) {
        self.includedisabled = includedisabled
    }
    private enum CodingKeys: String, CodingKey {
        case includedisabled = "includeDisabled"
    }
}

public struct CronStatusParams: Codable, Sendable {
}

public struct CronAddParams: Codable, Sendable {
    public let name: String
    public let agentid: AnyCodable?
    public let description: String?
    public let enabled: Bool?
    public let deleteafterrun: Bool?
    public let schedule: AnyCodable
    public let sessiontarget: AnyCodable
    public let wakemode: AnyCodable
    public let payload: AnyCodable
    public let isolation: [String: AnyCodable]?

    public init(
        name: String,
        agentid: AnyCodable?,
        description: String?,
        enabled: Bool?,
        deleteafterrun: Bool?,
        schedule: AnyCodable,
        sessiontarget: AnyCodable,
        wakemode: AnyCodable,
        payload: AnyCodable,
        isolation: [String: AnyCodable]?
    ) {
        self.name = name
        self.agentid = agentid
        self.description = description
        self.enabled = enabled
        self.deleteafterrun = deleteafterrun
        self.schedule = schedule
        self.sessiontarget = sessiontarget
        self.wakemode = wakemode
        self.payload = payload
        self.isolation = isolation
    }
    private enum CodingKeys: String, CodingKey {
        case name
        case agentid = "agentId"
        case description
        case enabled
        case deleteafterrun = "deleteAfterRun"
        case schedule
        case sessiontarget = "sessionTarget"
        case wakemode = "wakeMode"
        case payload
        case isolation
    }
}

public struct CronRunLogEntry: Codable, Sendable {
    public let ts: Int
    public let jobid: String
    public let action: String
    public let status: AnyCodable?
    public let error: String?
    public let summary: String?
    public let runatms: Int?
    public let durationms: Int?
    public let nextrunatms: Int?

    public init(
        ts: Int,
        jobid: String,
        action: String,
        status: AnyCodable?,
        error: String?,
        summary: String?,
        runatms: Int?,
        durationms: Int?,
        nextrunatms: Int?
    ) {
        self.ts = ts
        self.jobid = jobid
        self.action = action
        self.status = status
        self.error = error
        self.summary = summary
        self.runatms = runatms
        self.durationms = durationms
        self.nextrunatms = nextrunatms
    }
    private enum CodingKeys: String, CodingKey {
        case ts
        case jobid = "jobId"
        case action
        case status
        case error
        case summary
        case runatms = "runAtMs"
        case durationms = "durationMs"
        case nextrunatms = "nextRunAtMs"
    }
}

public struct LogsTailParams: Codable, Sendable {
    public let cursor: Int?
    public let limit: Int?
    public let maxbytes: Int?

    public init(
        cursor: Int?,
        limit: Int?,
        maxbytes: Int?
    ) {
        self.cursor = cursor
        self.limit = limit
        self.maxbytes = maxbytes
    }
    private enum CodingKeys: String, CodingKey {
        case cursor
        case limit
        case maxbytes = "maxBytes"
    }
}

public struct LogsTailResult: Codable, Sendable {
    public let file: String
    public let cursor: Int
    public let size: Int
    public let lines: [String]
    public let truncated: Bool?
    public let reset: Bool?

    public init(
        file: String,
        cursor: Int,
        size: Int,
        lines: [String],
        truncated: Bool?,
        reset: Bool?
    ) {
        self.file = file
        self.cursor = cursor
        self.size = size
        self.lines = lines
        self.truncated = truncated
        self.reset = reset
    }
    private enum CodingKeys: String, CodingKey {
        case file
        case cursor
        case size
        case lines
        case truncated
        case reset
    }
}

public struct ExecApprovalsGetParams: Codable, Sendable {
}

public struct ExecApprovalsSetParams: Codable, Sendable {
    public let file: [String: AnyCodable]
    public let basehash: String?

    public init(
        file: [String: AnyCodable],
        basehash: String?
    ) {
        self.file = file
        self.basehash = basehash
    }
    private enum CodingKeys: String, CodingKey {
        case file
        case basehash = "baseHash"
    }
}

public struct ExecApprovalsNodeGetParams: Codable, Sendable {
    public let nodeid: String

    public init(
        nodeid: String
    ) {
        self.nodeid = nodeid
    }
    private enum CodingKeys: String, CodingKey {
        case nodeid = "nodeId"
    }
}

public struct ExecApprovalsNodeSetParams: Codable, Sendable {
    public let nodeid: String
    public let file: [String: AnyCodable]
    public let basehash: String?

    public init(
        nodeid: String,
        file: [String: AnyCodable],
        basehash: String?
    ) {
        self.nodeid = nodeid
        self.file = file
        self.basehash = basehash
    }
    private enum CodingKeys: String, CodingKey {
        case nodeid = "nodeId"
        case file
        case basehash = "baseHash"
    }
}

public struct ExecApprovalsSnapshot: Codable, Sendable {
    public let path: String
    public let exists: Bool
    public let hash: String
    public let file: [String: AnyCodable]

    public init(
        path: String,
        exists: Bool,
        hash: String,
        file: [String: AnyCodable]
    ) {
        self.path = path
        self.exists = exists
        self.hash = hash
        self.file = file
    }
    private enum CodingKeys: String, CodingKey {
        case path
        case exists
        case hash
        case file
    }
}

public struct ExecApprovalRequestParams: Codable, Sendable {
    public let id: String?
    public let command: String
    public let cwd: AnyCodable?
    public let host: AnyCodable?
    public let security: AnyCodable?
    public let ask: AnyCodable?
    public let agentid: AnyCodable?
    public let resolvedpath: AnyCodable?
    public let sessionkey: AnyCodable?
    public let timeoutms: Int?

    public init(
        id: String?,
        command: String,
        cwd: AnyCodable?,
        host: AnyCodable?,
        security: AnyCodable?,
        ask: AnyCodable?,
        agentid: AnyCodable?,
        resolvedpath: AnyCodable?,
        sessionkey: AnyCodable?,
        timeoutms: Int?
    ) {
        self.id = id
        self.command = command
        self.cwd = cwd
        self.host = host
        self.security = security
        self.ask = ask
        self.agentid = agentid
        self.resolvedpath = resolvedpath
        self.sessionkey = sessionkey
        self.timeoutms = timeoutms
    }
    private enum CodingKeys: String, CodingKey {
        case id
        case command
        case cwd
        case host
        case security
        case ask
        case agentid = "agentId"
        case resolvedpath = "resolvedPath"
        case sessionkey = "sessionKey"
        case timeoutms = "timeoutMs"
    }
}

public struct ExecApprovalResolveParams: Codable, Sendable {
    public let id: String
    public let decision: String

    public init(
        id: String,
        decision: String
    ) {
        self.id = id
        self.decision = decision
    }
    private enum CodingKeys: String, CodingKey {
        case id
        case decision
    }
}

public struct DevicePairListParams: Codable, Sendable {
}

public struct DevicePairApproveParams: Codable, Sendable {
    public let requestid: String

    public init(
        requestid: String
    ) {
        self.requestid = requestid
    }
    private enum CodingKeys: String, CodingKey {
        case requestid = "requestId"
    }
}

public struct DevicePairRejectParams: Codable, Sendable {
    public let requestid: String

    public init(
        requestid: String
    ) {
        self.requestid = requestid
    }
    private enum CodingKeys: String, CodingKey {
        case requestid = "requestId"
    }
}

public struct DeviceTokenRotateParams: Codable, Sendable {
    public let deviceid: String
    public let role: String
    public let scopes: [String]?

    public init(
        deviceid: String,
        role: String,
        scopes: [String]?
    ) {
        self.deviceid = deviceid
        self.role = role
        self.scopes = scopes
    }
    private enum CodingKeys: String, CodingKey {
        case deviceid = "deviceId"
        case role
        case scopes
    }
}

public struct DeviceTokenRevokeParams: Codable, Sendable {
    public let deviceid: String
    public let role: String

    public init(
        deviceid: String,
        role: String
    ) {
        self.deviceid = deviceid
        self.role = role
    }
    private enum CodingKeys: String, CodingKey {
        case deviceid = "deviceId"
        case role
    }
}

public struct DevicePairRequestedEvent: Codable, Sendable {
    public let requestid: String
    public let deviceid: String
    public let publickey: String
    public let displayname: String?
    public let platform: String?
    public let clientid: String?
    public let clientmode: String?
    public let role: String?
    public let roles: [String]?
    public let scopes: [String]?
    public let remoteip: String?
    public let silent: Bool?
    public let isrepair: Bool?
    public let ts: Int

    public init(
        requestid: String,
        deviceid: String,
        publickey: String,
        displayname: String?,
        platform: String?,
        clientid: String?,
        clientmode: String?,
        role: String?,
        roles: [String]?,
        scopes: [String]?,
        remoteip: String?,
        silent: Bool?,
        isrepair: Bool?,
        ts: Int
    ) {
        self.requestid = requestid
        self.deviceid = deviceid
        self.publickey = publickey
        self.displayname = displayname
        self.platform = platform
        self.clientid = clientid
        self.clientmode = clientmode
        self.role = role
        self.roles = roles
        self.scopes = scopes
        self.remoteip = remoteip
        self.silent = silent
        self.isrepair = isrepair
        self.ts = ts
    }
    private enum CodingKeys: String, CodingKey {
        case requestid = "requestId"
        case deviceid = "deviceId"
        case publickey = "publicKey"
        case displayname = "displayName"
        case platform
        case clientid = "clientId"
        case clientmode = "clientMode"
        case role
        case roles
        case scopes
        case remoteip = "remoteIp"
        case silent
        case isrepair = "isRepair"
        case ts
    }
}

public struct DevicePairResolvedEvent: Codable, Sendable {
    public let requestid: String
    public let deviceid: String
    public let decision: String
    public let ts: Int

    public init(
        requestid: String,
        deviceid: String,
        decision: String,
        ts: Int
    ) {
        self.requestid = requestid
        self.deviceid = deviceid
        self.decision = decision
        self.ts = ts
    }
    private enum CodingKeys: String, CodingKey {
        case requestid = "requestId"
        case deviceid = "deviceId"
        case decision
        case ts
    }
}

public struct ChatHistoryParams: Codable, Sendable {
    public let sessionkey: String
    public let limit: Int?

    public init(
        sessionkey: String,
        limit: Int?
    ) {
        self.sessionkey = sessionkey
        self.limit = limit
    }
    private enum CodingKeys: String, CodingKey {
        case sessionkey = "sessionKey"
        case limit
    }
}

public struct ChatSendParams: Codable, Sendable {
    public let sessionkey: String
    public let message: String
    public let thinking: String?
    public let deliver: Bool?
    public let attachments: [AnyCodable]?
    public let timeoutms: Int?
    public let idempotencykey: String

    public init(
        sessionkey: String,
        message: String,
        thinking: String?,
        deliver: Bool?,
        attachments: [AnyCodable]?,
        timeoutms: Int?,
        idempotencykey: String
    ) {
        self.sessionkey = sessionkey
        self.message = message
        self.thinking = thinking
        self.deliver = deliver
        self.attachments = attachments
        self.timeoutms = timeoutms
        self.idempotencykey = idempotencykey
    }
    private enum CodingKeys: String, CodingKey {
        case sessionkey = "sessionKey"
        case message
        case thinking
        case deliver
        case attachments
        case timeoutms = "timeoutMs"
        case idempotencykey = "idempotencyKey"
    }
}

public struct ChatAbortParams: Codable, Sendable {
    public let sessionkey: String
    public let runid: String?

    public init(
        sessionkey: String,
        runid: String?
    ) {
        self.sessionkey = sessionkey
        self.runid = runid
    }
    private enum CodingKeys: String, CodingKey {
        case sessionkey = "sessionKey"
        case runid = "runId"
    }
}

public struct ChatInjectParams: Codable, Sendable {
    public let sessionkey: String
    public let message: String
    public let label: String?

    public init(
        sessionkey: String,
        message: String,
        label: String?
    ) {
        self.sessionkey = sessionkey
        self.message = message
        self.label = label
    }
    private enum CodingKeys: String, CodingKey {
        case sessionkey = "sessionKey"
        case message
        case label
    }
}

public struct ChatEvent: Codable, Sendable {
    public let runid: String
    public let sessionkey: String
    public let seq: Int
    public let state: AnyCodable
    public let message: AnyCodable?
    public let errormessage: String?
    public let usage: AnyCodable?
    public let stopreason: String?

    public init(
        runid: String,
        sessionkey: String,
        seq: Int,
        state: AnyCodable,
        message: AnyCodable?,
        errormessage: String?,
        usage: AnyCodable?,
        stopreason: String?
    ) {
        self.runid = runid
        self.sessionkey = sessionkey
        self.seq = seq
        self.state = state
        self.message = message
        self.errormessage = errormessage
        self.usage = usage
        self.stopreason = stopreason
    }
    private enum CodingKeys: String, CodingKey {
        case runid = "runId"
        case sessionkey = "sessionKey"
        case seq
        case state
        case message
        case errormessage = "errorMessage"
        case usage
        case stopreason = "stopReason"
    }
}

public struct UpdateRunParams: Codable, Sendable {
    public let sessionkey: String?
    public let note: String?
    public let restartdelayms: Int?
    public let timeoutms: Int?

    public init(
        sessionkey: String?,
        note: String?,
        restartdelayms: Int?,
        timeoutms: Int?
    ) {
        self.sessionkey = sessionkey
        self.note = note
        self.restartdelayms = restartdelayms
        self.timeoutms = timeoutms
    }
    private enum CodingKeys: String, CodingKey {
        case sessionkey = "sessionKey"
        case note
        case restartdelayms = "restartDelayMs"
        case timeoutms = "timeoutMs"
    }
}

public struct TickEvent: Codable, Sendable {
    public let ts: Int

    public init(
        ts: Int
    ) {
        self.ts = ts
    }
    private enum CodingKeys: String, CodingKey {
        case ts
    }
}

public struct ShutdownEvent: Codable, Sendable {
    public let reason: String
    public let restartexpectedms: Int?

    public init(
        reason: String,
        restartexpectedms: Int?
    ) {
        self.reason = reason
        self.restartexpectedms = restartexpectedms
    }
    private enum CodingKeys: String, CodingKey {
        case reason
        case restartexpectedms = "restartExpectedMs"
    }
}

public enum GatewayFrame: Codable, Sendable {
    case req(RequestFrame)
    case res(ResponseFrame)
    case event(EventFrame)
    case unknown(type: String, raw: [String: AnyCodable])

    private enum CodingKeys: String, CodingKey {
        case type
    }

    public init(from decoder: Decoder) throws {
        let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
        let type = try typeContainer.decode(String.self, forKey: .type)
        switch type {
        case "req":
            self = .req(try RequestFrame(from: decoder))
        case "res":
            self = .res(try ResponseFrame(from: decoder))
        case "event":
            self = .event(try EventFrame(from: decoder))
        default:
            let container = try decoder.singleValueContainer()
            let raw = try container.decode([String: AnyCodable].self)
            self = .unknown(type: type, raw: raw)
        }
    }

    public func encode(to encoder: Encoder) throws {
        switch self {
        case .req(let v): try v.encode(to: encoder)
        case .res(let v): try v.encode(to: encoder)
        case .event(let v): try v.encode(to: encoder)
        case .unknown(_, let raw):
            var container = encoder.singleValueContainer()
            try container.encode(raw)
        }
    }

}