1use crate::auth::{AuthPluginRegistry, ProviderRegistry};
2use crate::catalog::CatalogConfig;
3use crate::config::LlmConfigProvider;
4use crate::error::Result;
5use crate::model_registry::ModelRegistry;
6use std::sync::Arc;
7
8pub mod conversation;
9pub mod domain;
10pub mod system_context;
11pub mod validation;
12
13pub use conversation::{Message, MessageData, MessageGraph};
14pub use steer_workspace::EnvironmentInfo;
15pub use system_context::SystemContext;
16
17#[derive(Clone)]
18pub struct AppConfig {
19 pub llm_config_provider: LlmConfigProvider,
20 pub model_registry: Arc<ModelRegistry>,
21 pub provider_registry: Arc<ProviderRegistry>,
22}
23
24impl AppConfig {
25 pub fn from_auth_storage(auth_storage: Arc<dyn crate::auth::AuthStorage>) -> Result<Self> {
26 Self::from_auth_storage_with_catalog(auth_storage, CatalogConfig::default())
27 }
28
29 pub fn from_auth_storage_with_catalog(
30 auth_storage: Arc<dyn crate::auth::AuthStorage>,
31 catalog_config: CatalogConfig,
32 ) -> Result<Self> {
33 let llm_config_provider = LlmConfigProvider::new(auth_storage)?;
34 let model_registry = Arc::new(ModelRegistry::load(&catalog_config.catalog_paths)?);
35 let provider_registry = Arc::new(ProviderRegistry::load(&catalog_config.catalog_paths)?);
36
37 Ok(Self {
38 llm_config_provider,
39 model_registry,
40 provider_registry,
41 })
42 }
43
44 #[cfg(not(test))]
45 pub fn new() -> Result<Self> {
46 let auth_storage = Arc::new(crate::auth::DefaultAuthStorage::new()?);
47 Self::from_auth_storage(auth_storage)
48 }
49}
50
51impl Default for AppConfig {
52 fn default() -> Self {
54 let storage = Arc::new(crate::test_utils::InMemoryAuthStorage::new());
55 Self::from_auth_storage(storage.clone()).unwrap_or_else(|error| {
56 let catalog_config = crate::catalog::CatalogConfig::default();
57 let (model_registry, provider_registry) =
58 crate::catalog::load_registries(&catalog_config).unwrap_or_else(|fallback_error| {
59 tracing::error!(
60 error = %fallback_error,
61 "AppConfig::default failed to load registries; using empty defaults"
62 );
63 (
64 Arc::new(
65 crate::model_registry::ModelRegistry::load(&[]).unwrap_or_else(
66 |fallback_error| {
67 tracing::error!(
68 error = %fallback_error,
69 "Failed to load built-in model registry; using empty registry"
70 );
71 crate::model_registry::ModelRegistry::empty()
72 },
73 ),
74 ),
75 Arc::new(
76 ProviderRegistry::load(&[]).unwrap_or_else(|fallback_error| {
77 tracing::error!(
78 error = %fallback_error,
79 "Failed to load built-in provider registry; using empty registry"
80 );
81 ProviderRegistry::empty()
82 }),
83 ),
84 )
85 });
86 let llm_config_provider = match LlmConfigProvider::new(storage) {
87 Ok(provider) => provider,
88 Err(fallback_error) => {
89 tracing::error!(
90 error = %fallback_error,
91 "Failed to initialize LLM config provider; using fallback provider"
92 );
93 LlmConfigProvider::new_with_plugins(
94 Arc::new(crate::test_utils::InMemoryAuthStorage::new()),
95 Arc::new(AuthPluginRegistry::new()),
96 )
97 }
98 };
99
100 tracing::error!(
101 error = %error,
102 "AppConfig::default failed to load; using fallback defaults"
103 );
104
105 Self {
106 llm_config_provider,
107 model_registry,
108 provider_registry,
109 }
110 })
111 }
112}