MCPcopy Create free account
hub / github.com/GCWing/BitFun / initialize

Function initialize

src/apps/server/src/bootstrap.rs:33–233  ·  view source on GitHub ↗

Initialize all core services and return the shared server state. The optional `workspace` path, when provided, is opened automatically.

(workspace: Option<String>)

Source from the content-addressed store, hash-verified

31///
32/// The optional `workspace` path, when provided, is opened automatically.
33pub async fn initialize(workspace: Option<String>) -> anyhow::Result<Arc<ServerAppState>> {
34 log::info!("Initializing BitFun server core services");
35
36 // 1. Global config
37 config::initialize_global_config().await?;
38 let config_service = config::get_global_config_service().await?;
39
40 // Initialize the global I18nService so server-mode bot/remote-connect
41 // consumers observe the same runtime locale lifecycle as Desktop.
42 if let Err(e) =
43 bitfun_core::service::i18n::initialize_global_i18n_service(Some(config_service.clone()))
44 .await
45 {
46 log::warn!(
47 "Failed to initialize global I18nService in server mode: {}",
48 e
49 );
50 }
51
52 // 2. AI client factory
53 AIClientFactory::initialize_global().await?;
54 let ai_client_factory = AIClientFactory::get_global().await?;
55
56 // 3. Agentic system
57 let path_manager = try_get_path_manager_arc()?;
58
59 let event_queue = Arc::new(events::EventQueue::new(Default::default()));
60 let event_router = Arc::new(events::EventRouter::new());
61
62 let persistence_manager = Arc::new(persistence::PersistenceManager::new(path_manager.clone())?);
63
64 let context_store = Arc::new(session::SessionContextStore::new());
65 let context_compressor = Arc::new(session::ContextCompressor::new(Default::default()));
66
67 let session_manager = Arc::new(session::SessionManager::new(
68 context_store,
69 persistence_manager,
70 Default::default(),
71 ));
72
73 let tool_registry = tools::registry::get_global_tool_registry();
74 let tool_state_manager = Arc::new(tools::pipeline::ToolStateManager::new(event_queue.clone()));
75
76 let tool_pipeline = Arc::new(tools::pipeline::ToolPipeline::new(
77 tool_registry.clone(),
78 tool_state_manager,
79 None,
80 ));
81
82 let stream_processor = Arc::new(execution::StreamProcessor::new(event_queue.clone()));
83 let round_executor = Arc::new(execution::RoundExecutor::new(
84 stream_processor,
85 event_queue.clone(),
86 tool_pipeline.clone(),
87 ));
88
89 let execution_engine = Arc::new(execution::ExecutionEngine::new(
90 round_executor,

Callers 1

initialize_global_configFunction · 0.50

Tested by

no test coverage detected