openrustclaw-core 1.4.3

Core types, traits, and error handling for OpenRustClaw
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
//! Configuration structs for OpenRustClaw.
//!
//! Maps to `config/default.toml` and environment variable overrides.
//! Uses the `config` crate for layered configuration loading.

use serde::{Deserialize, Serialize};
use std::path::PathBuf;

/// Root configuration for the entire OpenRustClaw system.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AppConfig {
    pub gateway: GatewayConfig,
    pub database: DatabaseConfig,
    pub providers: ProvidersConfig,
    #[serde(default)]
    pub external_backends: ExternalBackendsConfig,
    pub memory: MemoryConfig,
    pub session_routing: SessionRoutingConfig,
    pub scheduler: SchedulerConfig,
    pub security: SecurityConfig,
    pub sidecar: SidecarConfig,
    pub observability: ObservabilityConfig,
    pub channels: ChannelsConfig,
    pub voice: VoiceConfig,
    pub skills: Option<SkillsConfig>,
}

/// Session-routing policy configuration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SessionRoutingConfig {
    #[serde(default = "default_direct_strategy")]
    pub direct_strategy: String,
    #[serde(default = "default_group_strategy")]
    pub group_strategy: String,
    #[serde(default = "default_thread_overrides_channel")]
    pub thread_overrides_channel: bool,
    #[serde(default = "default_pairing_approval_required")]
    pub pairing_approval_required: bool,
    #[serde(default = "default_group_activation_mode")]
    pub default_group_activation: String,
    #[serde(default = "default_send_mode")]
    pub default_send_mode: String,
    #[serde(default = "default_chunk_chars")]
    pub default_chunk_chars: usize,
    #[serde(default)]
    pub default_chunk_delay_ms: u64,
}

fn default_direct_strategy() -> String {
    "shared_main".to_string()
}

fn default_group_strategy() -> String {
    "isolated".to_string()
}

fn default_thread_overrides_channel() -> bool {
    true
}

fn default_pairing_approval_required() -> bool {
    false
}

fn default_group_activation_mode() -> String {
    "mention".to_string()
}

fn default_send_mode() -> String {
    "blocks".to_string()
}

fn default_chunk_chars() -> usize {
    1600
}

fn default_true() -> bool {
    true
}

/// Gateway (WebSocket server) configuration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GatewayConfig {
    #[serde(default = "default_gateway_network_mode")]
    pub network_mode: String,
    pub host: String,
    pub port: u16,
    pub allowed_origins: Vec<String>,
}

fn default_gateway_network_mode() -> String {
    "loopback".to_string()
}

/// Database configuration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DatabaseConfig {
    pub url: String,
    pub wal_mode: bool,
    pub max_connections: u32,
}

/// Provider configuration container.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProvidersConfig {
    pub default_provider: String,
    pub fallback_chain: Vec<String>,
    #[serde(default)]
    pub control_plane_provider: Option<String>,
    #[serde(default)]
    pub control_plane_fallback_chain: Vec<String>,
    pub anthropic: AnthropicConfig,
    pub openai: OpenAiConfig,
    pub openrouter: OpenRouterConfig,
    pub ollama: OllamaConfig,
    #[serde(default)]
    pub gemini: GeminiConfig,
}

/// Anthropic provider configuration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AnthropicConfig {
    pub model: String,
    #[serde(default)]
    pub api_key_env: Option<String>,
    pub api_version: String,
    pub strict_tools: bool,
    pub streaming_tool_deltas: bool,
}

/// OpenAI provider configuration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OpenAiConfig {
    pub model: String,
    #[serde(default = "default_codex_model")]
    pub codex_model: String,
    #[serde(default)]
    pub api_key_env: Option<String>,
    pub use_responses_api: bool,
    pub strict_tools: bool,
}

fn default_codex_model() -> String {
    "gpt-5.3-codex".to_string()
}

/// OpenRouter provider configuration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OpenRouterConfig {
    pub model: String,
    #[serde(default)]
    pub api_key_env: Option<String>,
    pub route_strategy: String,
}

/// Ollama (local model) configuration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OllamaConfig {
    pub base_url: String,
    pub model: String,
}

/// Gemini provider configuration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GeminiConfig {
    pub model: String,
    #[serde(default)]
    pub api_key_env: Option<String>,
    #[serde(default)]
    pub base_url: Option<String>,
}

impl Default for GeminiConfig {
    fn default() -> Self {
        Self {
            model: "gemini-1.5-pro".to_string(),
            api_key_env: Some("GEMINI_API_KEY".to_string()),
            base_url: None,
        }
    }
}

/// Governance policy for optional external execution backends.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct ExternalBackendsConfig {
    #[serde(default = "default_allowed_external_backends")]
    pub allowed_backends: Vec<String>,
    #[serde(default = "default_true")]
    pub allow_local_cli_wrappers: bool,
    #[serde(default)]
    pub allow_cloud_agent_execution: bool,
    #[serde(default = "default_external_backend_audit_log_path")]
    pub audit_log_path: String,
    #[serde(default = "default_external_backend_env_allowlist")]
    pub command_env_allowlist: Vec<String>,
}

fn default_allowed_external_backends() -> Vec<String> {
    vec!["agent_browser_cli".to_string()]
}

fn default_external_backend_audit_log_path() -> String {
    ".claw/control/external-backends-audit.jsonl".to_string()
}

fn default_external_backend_env_allowlist() -> Vec<String> {
    vec![
        "PATH".to_string(),
        "HOME".to_string(),
        "USER".to_string(),
        "USERNAME".to_string(),
        "TMPDIR".to_string(),
        "TMP".to_string(),
        "TEMP".to_string(),
        "LANG".to_string(),
        "LC_ALL".to_string(),
        "SSL_CERT_FILE".to_string(),
        "SSL_CERT_DIR".to_string(),
        "XDG_RUNTIME_DIR".to_string(),
        "XDG_CACHE_HOME".to_string(),
        "XDG_CONFIG_HOME".to_string(),
    ]
}

/// Memory system configuration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MemoryConfig {
    pub core_memory_max_tokens: usize,
    pub core_memory_max_entries: usize,
    pub embedding_concurrency: usize,
    pub dedupe_cosine_threshold: f32,
    pub decay_half_life_days: f64,
    pub ttl: MemoryTtlConfig,
    pub consolidation: ConsolidationConfig,
}

/// Memory TTL (time-to-live) configuration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MemoryTtlConfig {
    /// Days until episodic memories expire (0 = never).
    pub episodic_days: u64,
    /// Days until semantic memories expire (0 = never).
    pub semantic_days: u64,
    /// Days until procedural memories expire (0 = never).
    pub procedural_days: u64,
}

/// Memory consolidation configuration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ConsolidationConfig {
    pub enabled: bool,
    pub threshold_entries: usize,
    pub schedule_interval_hours: u64,
}

/// Scheduler configuration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SchedulerConfig {
    pub poll_interval_ms: u64,
    pub lease_duration_secs: u64,
    pub max_retries: u32,
    pub base_retry_delay_secs: u64,
    pub max_retry_delay_secs: u64,
}

/// Security configuration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SecurityConfig {
    pub require_auth: bool,
    pub origin_validation: bool,
    #[serde(default)]
    pub control_api_token_env: Option<String>,
    #[serde(default)]
    pub trusted_proxy_token_env: Option<String>,
    pub prompt_injection_defense: bool,
    pub skill_signature_required: bool,
    pub skill_verifying_key: Option<String>,
}

/// Python sidecar configuration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SidecarConfig {
    pub grpc_port: u16,
    pub python_path: String,
    #[serde(default)]
    pub role: SidecarRole,
    pub auto_start: bool,
    pub restart_on_crash: bool,
}

impl SidecarConfig {
    pub fn supports_compat_dispatch(&self) -> bool {
        matches!(self.role, SidecarRole::Compatibility)
    }

    pub fn supports_experimental_lane(&self) -> bool {
        matches!(self.role, SidecarRole::Experimental)
    }

    pub fn is_disabled(&self) -> bool {
        matches!(self.role, SidecarRole::Disabled)
    }
}

/// The allowed role of the optional Python sidecar.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(rename_all = "snake_case")]
pub enum SidecarRole {
    /// Optional bounded compatibility bridge for legacy workflow execution only.
    #[default]
    Compatibility,
    /// Experimental LangGraph lane for prototyping and evaluation only.
    Experimental,
    /// Fully disabled; the sidecar should not be started or used for dispatch.
    Disabled,
}

/// Observability configuration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ObservabilityConfig {
    pub langsmith_enabled: bool,
    pub tracing_enabled: bool,
    pub metrics_enabled: bool,
    pub metrics_port: u16,
}

/// Voice runtime configuration.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct VoiceConfig {
    #[serde(default)]
    pub enabled: bool,
    #[serde(default)]
    pub wake_word: VoiceWakeWordConfig,
    #[serde(default)]
    pub stt: VoiceSttRuntimeConfig,
    #[serde(default)]
    pub tts: VoiceTtsRuntimeConfig,
    #[serde(default)]
    pub talk_mode: VoiceTalkModeRuntimeConfig,
}

/// Wake-word configuration for voice flows.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VoiceWakeWordConfig {
    #[serde(default = "default_true")]
    pub enabled: bool,
    #[serde(default)]
    pub model_path: Option<String>,
    #[serde(default = "default_wake_word_sensitivity")]
    pub sensitivity: f32,
}

impl Default for VoiceWakeWordConfig {
    fn default() -> Self {
        Self {
            enabled: true,
            model_path: None,
            sensitivity: default_wake_word_sensitivity(),
        }
    }
}

fn default_wake_word_sensitivity() -> f32 {
    0.7
}

/// Speech-to-text runtime configuration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VoiceSttRuntimeConfig {
    #[serde(default = "default_voice_stt_provider")]
    pub provider: String,
    #[serde(default = "default_voice_stt_model")]
    pub model: String,
    #[serde(default = "default_voice_language")]
    pub language: String,
    #[serde(default)]
    pub api_base_url: Option<String>,
    #[serde(default)]
    pub api_key_env: Option<String>,
    #[serde(default)]
    pub prompt: Option<String>,
    #[serde(default)]
    pub transcribe_inbound_notes: bool,
    #[serde(default)]
    pub download_dir: Option<String>,
    #[serde(default = "default_voice_max_audio_bytes")]
    pub max_audio_bytes: usize,
    #[serde(default = "default_voice_timeout_secs")]
    pub timeout_secs: u64,
}

impl Default for VoiceSttRuntimeConfig {
    fn default() -> Self {
        Self {
            provider: default_voice_stt_provider(),
            model: default_voice_stt_model(),
            language: default_voice_language(),
            api_base_url: None,
            api_key_env: None,
            prompt: None,
            transcribe_inbound_notes: false,
            download_dir: None,
            max_audio_bytes: default_voice_max_audio_bytes(),
            timeout_secs: default_voice_timeout_secs(),
        }
    }
}

fn default_voice_stt_provider() -> String {
    "openai".to_string()
}

fn default_voice_stt_model() -> String {
    "whisper-1".to_string()
}

fn default_voice_language() -> String {
    "auto".to_string()
}

fn default_voice_max_audio_bytes() -> usize {
    25 * 1024 * 1024
}

fn default_voice_timeout_secs() -> u64 {
    60
}

/// Text-to-speech runtime configuration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VoiceTtsRuntimeConfig {
    #[serde(default = "default_voice_tts_provider")]
    pub provider: String,
    #[serde(default = "default_voice_tts_model")]
    pub model: String,
    #[serde(default = "default_voice_tts_voice")]
    pub voice: String,
    #[serde(default)]
    pub api_base_url: Option<String>,
    #[serde(default)]
    pub api_key_env: Option<String>,
}

impl Default for VoiceTtsRuntimeConfig {
    fn default() -> Self {
        Self {
            provider: default_voice_tts_provider(),
            model: default_voice_tts_model(),
            voice: default_voice_tts_voice(),
            api_base_url: None,
            api_key_env: None,
        }
    }
}

fn default_voice_tts_provider() -> String {
    "openai".to_string()
}

fn default_voice_tts_model() -> String {
    "tts-1".to_string()
}

fn default_voice_tts_voice() -> String {
    "alloy".to_string()
}

/// Continuous talk-mode configuration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VoiceTalkModeRuntimeConfig {
    #[serde(default = "default_true")]
    pub enabled: bool,
    #[serde(default = "default_talk_timeout_secs")]
    pub timeout_secs: u64,
}

impl Default for VoiceTalkModeRuntimeConfig {
    fn default() -> Self {
        Self {
            enabled: true,
            timeout_secs: default_talk_timeout_secs(),
        }
    }
}

fn default_talk_timeout_secs() -> u64 {
    30
}

/// Channel runtime resilience configuration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ChannelRuntimeConfig {
    #[serde(default = "default_true")]
    pub health_monitor_enabled: bool,
    #[serde(default = "default_channel_probe_interval_secs")]
    pub probe_interval_secs: u64,
    #[serde(default)]
    pub auto_restart_on_failure: bool,
    #[serde(default = "default_channel_failure_threshold")]
    pub failure_threshold: usize,
}

impl Default for ChannelRuntimeConfig {
    fn default() -> Self {
        Self {
            health_monitor_enabled: true,
            probe_interval_secs: default_channel_probe_interval_secs(),
            auto_restart_on_failure: false,
            failure_threshold: default_channel_failure_threshold(),
        }
    }
}

fn default_channel_probe_interval_secs() -> u64 {
    300
}

fn default_channel_failure_threshold() -> usize {
    3
}

/// Channel integrations configuration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ChannelsConfig {
    #[serde(default)]
    pub runtime: ChannelRuntimeConfig,
    pub telegram: TelegramConfig,
    pub discord: DiscordConfig,
    pub slack: SlackConfig,
    pub whatsapp: WhatsAppConfig,
    pub teams: TeamsConfig,
    pub mattermost: MattermostConfig,
    pub google_chat: GoogleChatConfig,
    pub google_meet: GoogleMeetConfig,
    pub gmail_pubsub: GmailPubSubConfig,
    pub signal: SignalConfig,
    pub matrix: MatrixConfig,
    pub x: XConfig,
    pub twilio: TwilioConfig,
    pub meta: MetaConfig,
    pub imessage: IMessageConfig,
    pub line: LineConfig,
    pub viber: ViberConfig,
    pub wechat: WeChatConfig,
}

/// Mattermost bot / slash-command configuration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MattermostConfig {
    pub enabled: bool,
    /// Mattermost server base URL (e.g. "<https://chat.example.com>")
    pub server_url: String,
    /// Personal access token or bot token for REST API calls
    pub bot_token: String,
    /// Webhook path for incoming slash commands / outgoing webhooks
    pub webhook_path: String,
    /// Optional shared token used to validate incoming slash-command / webhook payloads
    pub webhook_token: Option<String>,
    /// Optional bot username used for mention detection
    pub bot_username: Option<String>,
    /// Allowed Mattermost user IDs or usernames
    pub allowlist: Vec<String>,
    /// Allowed Mattermost channel IDs (empty = all)
    pub allowed_channels: Vec<String>,
    /// Rate limit for outgoing REST API requests per second
    pub rate_limit_requests_per_second: u32,
}

/// Skills/Plugins configuration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SkillsConfig {
    /// ClawHub registry URL
    pub registry_url: Option<String>,
    /// Auto-update skills on startup
    pub auto_update: Option<bool>,
    /// Additional skill directories
    pub skill_dirs: Option<Vec<String>>,
}

/// Telegram bot configuration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TelegramConfig {
    pub enabled: bool,
    pub token: String,
    #[serde(default)]
    pub api_base_url: Option<String>,
    pub mode: TelegramMode,
    pub webhook_url: Option<String>,
    pub webhook_port: Option<u16>,
    pub allowed_users: Vec<String>,
    pub rate_limit_per_second: u32,
}

/// Telegram connection mode.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum TelegramMode {
    Polling,
    Webhook,
}

/// Discord bot configuration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DiscordConfig {
    pub enabled: bool,
    pub token: String,
    pub application_id: String,
    #[serde(default)]
    pub interaction_public_key: Option<String>,
    #[serde(default)]
    pub api_base_url: Option<String>,
    #[serde(default)]
    pub attachment_download_dir: Option<String>,
    pub rate_limit_requests_per_second: u32,
    pub allowed_guilds: Vec<String>,
    pub allowed_channels: Vec<String>,
    pub dm_enabled: bool,
}

/// Slack app configuration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SlackConfig {
    pub enabled: bool,
    pub token: String,
    #[serde(default)]
    pub api_base_url: Option<String>,
    pub app_token: Option<String>,
    pub signing_secret: Option<String>,
    pub mode: SlackMode,
    pub socket_mode: bool,
    pub rate_limit_requests_per_second: u32,
    pub allowed_workspaces: Vec<String>,
    pub app_home_enabled: bool,
}

/// Slack connection mode.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum SlackMode {
    Http,
    SocketMode,
}

/// WhatsApp Web configuration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WhatsAppConfig {
    pub enabled: bool,
    /// Path to store session credentials
    pub session_path: String,
    /// Use pairing code instead of QR code
    pub pairing_mode: bool,
    /// Allowed phone numbers for DMs (empty = all allowed)
    pub allowlist: Vec<String>,
    /// Optional webhook URL for notifications
    pub webhook_url: Option<String>,
    /// Path to the Baileys bridge script
    pub bridge_path: String,
    /// Rate limit for outgoing messages per second
    pub rate_limit_per_second: u32,
    /// Maximum reconnection attempts
    pub max_reconnect_attempts: u32,
    /// Initial reconnection delay in seconds (increases with backoff)
    pub reconnect_delay_secs: u64,
}

/// Microsoft Teams bot configuration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TeamsConfig {
    pub enabled: bool,
    /// Microsoft App ID (from Azure Bot registration)
    pub app_id: String,
    /// Microsoft App Password (client secret)
    pub app_password: String,
    /// Tenant ID for single-tenant apps (None for multi-tenant)
    pub tenant_id: Option<String>,
    /// Webhook path for incoming messages
    pub webhook_path: String,
    /// List of allowed user emails or AAD object IDs
    pub allowlist: Vec<String>,
    /// Group policy for mentions
    pub group_policy: TeamsGroupPolicy,
    /// Rate limit for sending messages
    pub rate_limit_requests_per_second: u32,
    /// Enable Adaptive Cards support
    pub adaptive_cards_enabled: bool,
    /// Optional local download root for inbound Teams attachments
    #[serde(default)]
    pub attachment_download_dir: Option<String>,
}

/// Group policy for Microsoft Teams mentions.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum TeamsGroupPolicy {
    /// Bot responds only when @mentioned
    Mention,
    /// Bot responds to all messages in the channel
    Open,
}

/// Google Chat bot configuration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GoogleChatConfig {
    pub enabled: bool,
    /// Path to service account JSON key file
    pub service_account_key: String,
    /// Google Cloud project ID
    pub project_id: String,
    /// Webhook URL for receiving messages (if using HTTP push)
    pub webhook_url: Option<String>,
    /// Pub/Sub subscription name (if using Pub/Sub)
    pub pubsub_subscription: Option<String>,
    /// List of allowed user emails or Google Workspace user IDs
    pub allowlist: Vec<String>,
    /// List of allowed space IDs (empty = all spaces)
    pub allowed_spaces: Vec<String>,
    /// Rate limit for sending messages
    pub rate_limit_requests_per_second: u32,
    /// Enable Card-based responses
    pub cards_enabled: bool,
    /// Optional local download root for inbound Google Chat attachments
    #[serde(default)]
    pub attachment_download_dir: Option<String>,
    /// Response mode for the bot
    pub response_mode: GoogleChatResponseMode,
}

/// Response mode for Google Chat bot.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum GoogleChatResponseMode {
    /// Bot responds only when @mentioned
    Mention,
    /// Bot responds to all messages in the space
    Open,
    /// Bot only responds to slash commands
    SlashCommands,
}

/// Google Meet integration configuration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GoogleMeetConfig {
    pub enabled: bool,
    /// Path to service account JSON key file, or `token:<value>`, or `env:VAR`
    pub service_account_key_path: String,
    /// Delegated Google Workspace user email for Meet API access
    pub delegated_user_email: String,
    /// Webhook path for Google Workspace Events / Pub/Sub push delivery
    pub webhook_path: String,
    /// Optional space allowlist (empty = all spaces)
    pub allowed_spaces: Vec<String>,
    /// Rate limit for Meet API requests per second
    pub rate_limit_requests_per_second: u32,
    /// Optional override for the Google Meet API base URL
    pub api_base_url: Option<String>,
    /// Optional override for the Google OAuth token URL
    pub oauth_token_url: Option<String>,
    /// Additional OAuth scopes to request beyond the built-in Meet defaults
    pub additional_scopes: Vec<String>,
    /// Whether transcript events should hydrate transcript entries eagerly
    pub hydrate_transcript_events: bool,
}

/// Gmail Pub/Sub configuration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GmailPubSubConfig {
    pub enabled: bool,
    /// Google Cloud project ID
    pub project_id: String,
    /// Pub/Sub subscription name
    pub subscription_name: String,
    /// Optional fully qualified Pub/Sub topic name for Gmail watch notifications
    pub topic_name: Option<String>,
    /// Path to service account JSON key file
    pub service_account_key_path: String,
    /// Gmail user email address
    pub user_email: String,
    /// Label filters (e.g., ["INBOX", "UNREAD"])
    pub label_filters: Vec<String>,
    /// Optional query filter (e.g., "from:github.com")
    pub query_filter: Option<String>,
    /// Enable auto-reply functionality
    pub auto_reply: bool,
    /// Maximum number of history records to fetch per notification
    pub max_history_fetch: u32,
    /// Rate limit for Gmail API requests per second
    pub rate_limit_requests_per_second: u32,
    /// Optional override for the Gmail API base URL
    pub api_base_url: Option<String>,
    /// Optional override for the Google OAuth token URL
    pub oauth_token_url: Option<String>,
}

/// Signal messenger configuration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SignalConfig {
    pub enabled: bool,
    /// Bot's phone number (E.164 format, e.g., +1234567890)
    pub phone_number: String,
    /// Path to signal-cli data directory
    pub data_dir: PathBuf,
    /// Allowed phone numbers (empty = allow all)
    pub allowlist: Vec<String>,
    /// Allowed group IDs (empty = allow all)
    pub allowed_groups: Vec<String>,
    /// Path to signal-cli binary (None = use system PATH)
    pub signal_cli_path: Option<PathBuf>,
    /// Use native libsignal-client instead of signal-cli
    pub use_libsignal: bool,
    /// Rate limit for outgoing messages per minute
    pub rate_limit_per_minute: u32,
    /// Require allowlist for security
    pub require_allowlist: bool,
}

/// Matrix protocol configuration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MatrixConfig {
    pub enabled: bool,
    /// Matrix homeserver URL (e.g., "<https://matrix.org>")
    pub homeserver: String,
    /// Matrix user ID (e.g., "@bot:matrix.org")
    pub user_id: String,
    /// Access token for authentication (preferred over password)
    pub access_token: Option<String>,
    /// Password for authentication (if access_token not provided)
    pub password: Option<String>,
    /// Device ID for the session
    pub device_id: Option<String>,
    /// Directory to store Matrix client data (encryption keys, sync tokens)
    pub data_dir: String,
    /// List of allowed MXIDs (empty = allow all)
    pub allowlist: Vec<String>,
    /// List of allowed room IDs (empty = allow all)
    pub room_allowlist: Vec<String>,
    /// Automatically join rooms when invited
    pub auto_join_rooms: bool,
    /// Enable end-to-end encryption
    pub enable_encryption: bool,
    /// Rate limit for sending messages per second
    pub rate_limit_per_second: u32,
}

/// X (Twitter) API v2 configuration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct XConfig {
    pub enabled: bool,
    /// Bearer token for X API v2
    pub bearer_token: String,
    /// API key (for user context endpoints)
    pub api_key: String,
    /// API secret (for user context endpoints)
    pub api_secret: String,
    /// Access token (for user context endpoints)
    pub access_token: String,
    /// Access token secret (for user context endpoints)
    pub access_token_secret: String,
    /// Bot user ID (numeric string)
    pub bot_user_id: String,
    /// List of allowed usernames (without @, empty = all allowed)
    pub allowlist: Vec<String>,
    /// Respond to mentions
    pub respond_to_mentions: bool,
    /// Respond to DMs
    pub respond_to_dms: bool,
    /// Maximum tweet length (default: 280)
    pub max_tweet_length: usize,
    /// Polling interval for mentions in seconds
    pub mention_poll_interval_secs: u64,
    /// Polling interval for DMs in seconds
    pub dm_poll_interval_secs: u64,
    /// Rate limit for sending tweets per minute
    pub rate_limit_per_minute: u32,
}

/// Twilio SMS/MMS configuration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TwilioConfig {
    pub enabled: bool,
    /// Twilio Account SID
    pub account_sid: String,
    /// Twilio Auth Token
    pub auth_token: String,
    /// Twilio phone number (E.164 format, e.g., +1234567890)
    pub phone_number: String,
    /// Optional webhook URL for receiving messages
    pub webhook_url: Option<String>,
    /// List of allowed phone numbers (empty = all allowed)
    pub allowlist: Vec<String>,
    /// Maximum message length (default 1600, Twilio's limit)
    pub max_message_length: usize,
    /// Enable MMS support
    pub enable_mms: bool,
    /// Rate limit for sending messages per second
    pub rate_limit_per_second: u32,
}

/// LINE Messaging API configuration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LineConfig {
    pub enabled: bool,
    /// LINE Channel Access Token
    pub channel_access_token: String,
    /// LINE Channel Secret (for webhook signature verification)
    pub channel_secret: String,
    /// Webhook path for receiving events
    pub webhook_path: String,
    /// List of allowed user IDs (empty = all allowed)
    pub allowlist: Vec<String>,
    /// Rate limit for sending messages per second (default: 1000)
    pub rate_limit_per_second: u32,
    /// Enable rich menu support
    pub enable_rich_menu: bool,
    /// Enable quick replies
    pub enable_quick_replies: bool,
}

/// Viber Bot API configuration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ViberConfig {
    pub enabled: bool,
    /// Viber Bot Authentication Token
    pub auth_token: String,
    /// Webhook URL for receiving callbacks (optional)
    pub webhook_url: Option<String>,
    /// Webhook path for receiving callbacks
    pub webhook_path: String,
    /// List of allowed user IDs (empty = all allowed)
    pub allowlist: Vec<String>,
    /// Rate limit for sending messages per minute (default: 300)
    pub rate_limit_per_minute: u32,
    /// Allow broadcast messages (admin only)
    pub allow_broadcast: bool,
    /// Welcome message for new conversations
    pub welcome_message: Option<String>,
    /// Enable keyboard support
    pub enable_keyboards: bool,
}

/// WeChat configuration (supports both Work and Official Accounts).
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WeChatConfig {
    pub enabled: bool,
    /// App type: "work" for WeChat Work, "official_account" for Official Accounts
    pub app_type: String,
    // WeChat Work fields
    /// WeChat Work Corp ID
    pub corp_id: String,
    /// WeChat Work Corp Secret
    pub corp_secret: String,
    /// WeChat Work Agent ID
    pub agent_id: String,
    // Official Account fields
    /// WeChat Official Account App ID
    pub app_id: String,
    /// WeChat Official Account App Secret
    pub app_secret: String,
    /// Token for webhook signature verification (Official Accounts)
    pub token: String,
    /// Encoding AES key for message encryption (optional)
    pub encoding_aes_key: Option<String>,
    /// Webhook path for receiving messages
    pub webhook_path: String,
    /// List of allowed user IDs (empty = all allowed)
    pub allowlist: Vec<String>,
    /// Rate limit for API requests per second (default: 20)
    pub rate_limit_per_second: u32,
    /// Enable message encryption
    pub enable_encryption: bool,
}

/// Meta (Messenger & Instagram) configuration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MetaConfig {
    pub enabled: bool,
    /// Meta App ID
    pub app_id: String,
    /// Meta App Secret
    pub app_secret: String,
    /// Page Access Token for Messenger
    pub page_access_token: String,
    /// Webhook verify token
    pub verify_token: String,
    /// Webhook path for receiving messages
    pub webhook_path: String,
    /// Facebook Page ID
    pub page_id: String,
    /// Instagram Account ID (optional, for Instagram Direct)
    pub instagram_account_id: Option<String>,
    /// List of allowed sender IDs (empty = all allowed)
    pub allowlist: Vec<String>,
    /// Respond to Messenger messages
    pub respond_to_messenger: bool,
    /// Respond to Instagram Direct messages
    pub respond_to_instagram: bool,
    /// Show typing indicator while processing
    pub show_typing_indicator: bool,
    /// Rate limit for sending messages per second
    pub rate_limit_per_second: u32,
}

/// iMessage configuration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct IMessageConfig {
    pub enabled: bool,
    /// Bridge mode for iMessage integration
    pub bridge_mode: IMessageBridgeMode,
    /// List of allowed phone numbers or Apple IDs (empty = all allowed)
    pub allowlist: Vec<String>,
    /// Enable tapback/reaction support
    pub enable_tapbacks: bool,
    /// Enable typing indicator support
    pub enable_typing_indicator: bool,
}

/// Bridge mode for iMessage integration.
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case", tag = "mode")]
pub enum IMessageBridgeMode {
    /// BlueBubbles server (works remotely)
    #[serde(rename = "bluebubbles", alias = "blue_bubbles")]
    BlueBubbles {
        /// BlueBubbles server URL
        server_url: String,
        /// BlueBubbles API password
        password: String,
    },
    /// Direct macOS AppleScript (local only, requires macOS)
    #[default]
    #[serde(rename = "macos_direct", alias = "mac_o_s_direct")]
    MacOSDirect,
    /// macOS Messages.app private API (advanced)
    PrivateApi,
}

impl AppConfig {
    /// Load configuration from default.toml, then overlay environment variables.
    ///
    /// Environment variables use the prefix `OPENRUSTCLAW_` with `__` as separator.
    /// Example: `OPENRUSTCLAW_GATEWAY__PORT=8080`
    pub fn load() -> Result<Self, config::ConfigError> {
        let config = config::Config::builder()
            .add_source(config::File::with_name("config/default").required(false))
            .add_source(
                config::Environment::with_prefix("OPENRUSTCLAW")
                    .separator("__")
                    .try_parsing(true),
            )
            .build()?;

        config.try_deserialize()
    }

    /// Load from a specific config file path.
    pub fn load_from(path: &str) -> Result<Self, config::ConfigError> {
        let config = config::Config::builder()
            .add_source(config::File::with_name(path))
            .add_source(
                config::Environment::with_prefix("OPENRUSTCLAW")
                    .separator("__")
                    .try_parsing(true),
            )
            .build()?;

        config.try_deserialize()
    }
}

impl Default for AppConfig {
    fn default() -> Self {
        Self {
            gateway: GatewayConfig {
                network_mode: default_gateway_network_mode(),
                host: "127.0.0.1".to_string(),
                port: 18789,
                allowed_origins: vec![
                    "http://localhost:3000".to_string(),
                    "http://127.0.0.1:3000".to_string(),
                ],
            },
            database: DatabaseConfig {
                url: "sqlite://data/openrustclaw.db".to_string(),
                wal_mode: true,
                max_connections: 10,
            },
            providers: ProvidersConfig {
                default_provider: "anthropic".to_string(),
                fallback_chain: vec![
                    "anthropic".to_string(),
                    "openai".to_string(),
                    "openrouter".to_string(),
                ],
                control_plane_provider: Some("openrouter".to_string()),
                control_plane_fallback_chain: vec!["ollama".to_string(), "anthropic".to_string()],
                anthropic: AnthropicConfig {
                    model: "claude-sonnet-4-20250514".to_string(),
                    api_key_env: None,
                    api_version: "2023-06-01".to_string(),
                    strict_tools: true,
                    streaming_tool_deltas: true,
                },
                openai: OpenAiConfig {
                    model: "gpt-4o".to_string(),
                    codex_model: default_codex_model(),
                    api_key_env: None,
                    use_responses_api: true,
                    strict_tools: true,
                },
                openrouter: OpenRouterConfig {
                    model: "anthropic/claude-sonnet-4".to_string(),
                    api_key_env: None,
                    route_strategy: "quality".to_string(),
                },
                ollama: OllamaConfig {
                    base_url: "http://localhost:11434".to_string(),
                    model: "llama3.1".to_string(),
                },
                gemini: GeminiConfig::default(),
            },
            external_backends: ExternalBackendsConfig {
                allowed_backends: default_allowed_external_backends(),
                allow_local_cli_wrappers: true,
                allow_cloud_agent_execution: false,
                audit_log_path: default_external_backend_audit_log_path(),
                command_env_allowlist: default_external_backend_env_allowlist(),
            },
            memory: MemoryConfig {
                core_memory_max_tokens: 500,
                core_memory_max_entries: 20,
                embedding_concurrency: 4,
                dedupe_cosine_threshold: 0.92,
                decay_half_life_days: 30.0,
                ttl: MemoryTtlConfig {
                    episodic_days: 90,
                    semantic_days: 0,
                    procedural_days: 0,
                },
                consolidation: ConsolidationConfig {
                    enabled: true,
                    threshold_entries: 1000,
                    schedule_interval_hours: 24,
                },
            },
            session_routing: SessionRoutingConfig {
                direct_strategy: "shared_main".to_string(),
                group_strategy: "isolated".to_string(),
                thread_overrides_channel: true,
                pairing_approval_required: false,
                default_group_activation: "mention".to_string(),
                default_send_mode: "blocks".to_string(),
                default_chunk_chars: 1600,
                default_chunk_delay_ms: 250,
            },
            scheduler: SchedulerConfig {
                poll_interval_ms: 1000,
                lease_duration_secs: 60,
                max_retries: 3,
                base_retry_delay_secs: 5,
                max_retry_delay_secs: 300,
            },
            security: SecurityConfig {
                require_auth: true,
                origin_validation: true,
                control_api_token_env: None,
                trusted_proxy_token_env: None,
                prompt_injection_defense: true,
                skill_signature_required: false,
                skill_verifying_key: None,
            },
            sidecar: SidecarConfig {
                grpc_port: 50051,
                python_path: "python3".to_string(),
                role: SidecarRole::Compatibility,
                auto_start: false,
                restart_on_crash: true,
            },
            observability: ObservabilityConfig {
                langsmith_enabled: false,
                tracing_enabled: true,
                metrics_enabled: true,
                metrics_port: 9090,
            },
            voice: VoiceConfig::default(),
            channels: ChannelsConfig {
                runtime: ChannelRuntimeConfig::default(),
                telegram: TelegramConfig {
                    enabled: false,
                    token: String::new(),
                    api_base_url: None,
                    mode: TelegramMode::Polling,
                    webhook_url: None,
                    webhook_port: None,
                    allowed_users: Vec::new(),
                    rate_limit_per_second: 30,
                },
                discord: DiscordConfig {
                    enabled: false,
                    token: String::new(),
                    application_id: String::new(),
                    interaction_public_key: None,
                    api_base_url: None,
                    attachment_download_dir: None,
                    rate_limit_requests_per_second: 5,
                    allowed_guilds: Vec::new(),
                    allowed_channels: Vec::new(),
                    dm_enabled: true,
                },
                slack: SlackConfig {
                    enabled: false,
                    token: String::new(),
                    api_base_url: None,
                    app_token: None,
                    signing_secret: None,
                    mode: SlackMode::SocketMode,
                    socket_mode: true,
                    rate_limit_requests_per_second: 10,
                    allowed_workspaces: Vec::new(),
                    app_home_enabled: true,
                },
                whatsapp: WhatsAppConfig {
                    enabled: false,
                    session_path: "./data/whatsapp-session".to_string(),
                    pairing_mode: false,
                    allowlist: Vec::new(),
                    webhook_url: None,
                    bridge_path: "./crates/channels/baileys-bridge/index.js".to_string(),
                    rate_limit_per_second: 10,
                    max_reconnect_attempts: 10,
                    reconnect_delay_secs: 5,
                },
                teams: TeamsConfig {
                    enabled: false,
                    app_id: String::new(),
                    app_password: String::new(),
                    tenant_id: None,
                    webhook_path: "/webhooks/teams".to_string(),
                    allowlist: Vec::new(),
                    group_policy: TeamsGroupPolicy::Mention,
                    rate_limit_requests_per_second: 10,
                    adaptive_cards_enabled: true,
                    attachment_download_dir: None,
                },
                mattermost: MattermostConfig {
                    enabled: false,
                    server_url: String::new(),
                    bot_token: String::new(),
                    webhook_path: "/webhooks/mattermost".to_string(),
                    webhook_token: None,
                    bot_username: None,
                    allowlist: Vec::new(),
                    allowed_channels: Vec::new(),
                    rate_limit_requests_per_second: 10,
                },
                google_chat: GoogleChatConfig {
                    enabled: false,
                    service_account_key: String::new(),
                    project_id: String::new(),
                    webhook_url: None,
                    pubsub_subscription: None,
                    allowlist: Vec::new(),
                    allowed_spaces: Vec::new(),
                    rate_limit_requests_per_second: 10,
                    cards_enabled: true,
                    attachment_download_dir: None,
                    response_mode: GoogleChatResponseMode::Mention,
                },
                google_meet: GoogleMeetConfig {
                    enabled: false,
                    service_account_key_path: String::new(),
                    delegated_user_email: String::new(),
                    webhook_path: "/webhooks/google-meet/events".to_string(),
                    allowed_spaces: Vec::new(),
                    rate_limit_requests_per_second: 5,
                    api_base_url: None,
                    oauth_token_url: None,
                    additional_scopes: Vec::new(),
                    hydrate_transcript_events: true,
                },
                gmail_pubsub: GmailPubSubConfig {
                    enabled: false,
                    project_id: String::new(),
                    subscription_name: String::new(),
                    topic_name: None,
                    service_account_key_path: String::new(),
                    user_email: String::new(),
                    label_filters: vec!["INBOX".to_string(), "UNREAD".to_string()],
                    query_filter: None,
                    auto_reply: false,
                    max_history_fetch: 100,
                    rate_limit_requests_per_second: 10,
                    api_base_url: None,
                    oauth_token_url: None,
                },
                signal: SignalConfig {
                    enabled: false,
                    phone_number: String::new(),
                    data_dir: std::path::PathBuf::from("./data/signal"),
                    allowlist: Vec::new(),
                    allowed_groups: Vec::new(),
                    signal_cli_path: None,
                    use_libsignal: false,
                    rate_limit_per_minute: 20,
                    require_allowlist: true,
                },
                matrix: MatrixConfig {
                    enabled: false,
                    homeserver: String::new(),
                    user_id: String::new(),
                    access_token: None,
                    password: None,
                    device_id: None,
                    data_dir: "./data/matrix".to_string(),
                    allowlist: Vec::new(),
                    room_allowlist: Vec::new(),
                    auto_join_rooms: true,
                    enable_encryption: true,
                    rate_limit_per_second: 10,
                },
                x: XConfig {
                    enabled: false,
                    bearer_token: String::new(),
                    api_key: String::new(),
                    api_secret: String::new(),
                    access_token: String::new(),
                    access_token_secret: String::new(),
                    bot_user_id: String::new(),
                    allowlist: Vec::new(),
                    respond_to_mentions: true,
                    respond_to_dms: true,
                    max_tweet_length: 280,
                    mention_poll_interval_secs: 60,
                    dm_poll_interval_secs: 120,
                    rate_limit_per_minute: 10,
                },
                twilio: TwilioConfig {
                    enabled: false,
                    account_sid: String::new(),
                    auth_token: String::new(),
                    phone_number: String::new(),
                    webhook_url: None,
                    allowlist: Vec::new(),
                    max_message_length: 1600,
                    enable_mms: true,
                    rate_limit_per_second: 10,
                },
                meta: MetaConfig {
                    enabled: false,
                    app_id: String::new(),
                    app_secret: String::new(),
                    page_access_token: String::new(),
                    verify_token: String::new(),
                    webhook_path: "/webhooks/meta".to_string(),
                    page_id: String::new(),
                    instagram_account_id: None,
                    allowlist: Vec::new(),
                    respond_to_messenger: true,
                    respond_to_instagram: true,
                    show_typing_indicator: true,
                    rate_limit_per_second: 10,
                },
                imessage: IMessageConfig {
                    enabled: false,
                    bridge_mode: IMessageBridgeMode::MacOSDirect,
                    allowlist: Vec::new(),
                    enable_tapbacks: true,
                    enable_typing_indicator: false,
                },
                line: LineConfig {
                    enabled: false,
                    channel_access_token: String::new(),
                    channel_secret: String::new(),
                    webhook_path: "/webhook/line".to_string(),
                    allowlist: Vec::new(),
                    rate_limit_per_second: 1000,
                    enable_rich_menu: true,
                    enable_quick_replies: true,
                },
                viber: ViberConfig {
                    enabled: false,
                    auth_token: String::new(),
                    webhook_url: None,
                    webhook_path: "/webhook/viber".to_string(),
                    allowlist: Vec::new(),
                    rate_limit_per_minute: 300,
                    allow_broadcast: false,
                    welcome_message: None,
                    enable_keyboards: true,
                },
                wechat: WeChatConfig {
                    enabled: false,
                    app_type: "work".to_string(),
                    corp_id: String::new(),
                    corp_secret: String::new(),
                    agent_id: String::new(),
                    app_id: String::new(),
                    app_secret: String::new(),
                    token: String::new(),
                    encoding_aes_key: None,
                    webhook_path: "/webhook/wechat".to_string(),
                    allowlist: Vec::new(),
                    rate_limit_per_second: 20,
                    enable_encryption: false,
                },
            },
            skills: None,
        }
    }
}