Skip to main content

routa_core/
state.rs

1//! Shared application state for the axum server.
2
3use std::sync::Arc;
4
5use crate::acp::{
6    docker::{DockerDetector, DockerProcessManager},
7    AcpBinaryManager, AcpInstallationState, AcpManager, AcpPaths, AcpRuntimeManager,
8    AcpWarmupService,
9};
10use crate::db::Database;
11use crate::events::EventBus;
12use crate::sandbox::SandboxManager;
13use crate::skills::SkillRegistry;
14use crate::store::{
15    AcpSessionStore, AgentStore, ArtifactStore, CodebaseStore, ConversationStore, KanbanStore,
16    NoteStore, ScheduleStore, TaskStore, WorkspaceStore, WorktreeStore,
17};
18
19/// Docker state for managing Docker-based agent execution.
20#[derive(Default)]
21pub struct DockerState {
22    pub detector: DockerDetector,
23    pub process_manager: DockerProcessManager,
24}
25
26/// Shared state accessible by all API handlers.
27pub struct AppStateInner {
28    pub db: Database,
29    pub workspace_store: WorkspaceStore,
30    pub codebase_store: CodebaseStore,
31    pub worktree_store: WorktreeStore,
32    pub agent_store: AgentStore,
33    pub artifact_store: ArtifactStore,
34    pub task_store: TaskStore,
35    pub kanban_store: KanbanStore,
36    pub note_store: NoteStore,
37    pub schedule_store: ScheduleStore,
38    pub conversation_store: ConversationStore,
39    pub acp_session_store: AcpSessionStore,
40    pub skill_registry: SkillRegistry,
41    pub acp_manager: AcpManager,
42    pub event_bus: EventBus,
43    pub acp_paths: AcpPaths,
44    pub acp_binary_manager: AcpBinaryManager,
45    pub acp_installation_state: AcpInstallationState,
46    pub acp_runtime_manager: AcpRuntimeManager,
47    pub acp_warmup_service: AcpWarmupService,
48    pub docker_state: DockerState,
49    pub sandbox_manager: SandboxManager,
50}
51
52pub type AppState = Arc<AppStateInner>;
53
54impl AppStateInner {
55    pub fn new(db: Database) -> Self {
56        let acp_paths = AcpPaths::new();
57        let acp_binary_manager = AcpBinaryManager::new(acp_paths.clone());
58        let acp_installation_state = AcpInstallationState::new(acp_paths.clone());
59        let acp_runtime_manager = AcpRuntimeManager::new(acp_paths.clone());
60        let acp_warmup_service = AcpWarmupService::new(acp_paths.clone());
61        Self {
62            workspace_store: WorkspaceStore::new(db.clone()),
63            codebase_store: CodebaseStore::new(db.clone()),
64            worktree_store: WorktreeStore::new(db.clone()),
65            agent_store: AgentStore::new(db.clone()),
66            artifact_store: ArtifactStore::new(db.clone()),
67            task_store: TaskStore::new(db.clone()),
68            kanban_store: KanbanStore::new(db.clone()),
69            note_store: NoteStore::new(db.clone()),
70            schedule_store: ScheduleStore::new(db.clone()),
71            conversation_store: ConversationStore::new(db.clone()),
72            acp_session_store: AcpSessionStore::new(db.clone()),
73            skill_registry: SkillRegistry::new(),
74            acp_manager: AcpManager::new(),
75            event_bus: EventBus::new(),
76            db,
77            acp_paths,
78            acp_binary_manager,
79            acp_installation_state,
80            acp_runtime_manager,
81            acp_warmup_service,
82            docker_state: DockerState::default(),
83            sandbox_manager: SandboxManager::new(),
84        }
85    }
86}