roboticus_api/api/
state.rs1use std::sync::Arc;
12use tokio::sync::RwLock;
13
14use roboticus_agent::approvals::ApprovalManager;
15use roboticus_agent::capability::CapabilityRegistry;
16use roboticus_agent::policy::PolicyEngine;
17use roboticus_agent::retrieval::MemoryRetriever;
18use roboticus_agent::subagents::SubagentRegistry;
19use roboticus_agent::tools::ToolRegistry;
20use roboticus_channels::router::ChannelRouter;
21use roboticus_core::RoboticusConfig;
22use roboticus_db::Database;
23use roboticus_llm::LlmService;
24use roboticus_llm::semantic_classifier::SemanticClassifier;
25use roboticus_plugin_sdk::registry::PluginRegistry;
26use roboticus_wallet::WalletService;
27
28pub trait HasCore {
30 fn db(&self) -> &Database;
31 fn config(&self) -> &Arc<RwLock<RoboticusConfig>>;
32 fn hmac_secret(&self) -> &[u8];
33}
34
35pub trait HasInference {
37 fn llm(&self) -> &Arc<RwLock<LlmService>>;
38 fn semantic_classifier(&self) -> &Arc<SemanticClassifier>;
39}
40
41pub trait HasAgent {
43 fn tools(&self) -> &Arc<ToolRegistry>;
44 fn capabilities(&self) -> &Arc<CapabilityRegistry>;
45 fn policy_engine(&self) -> &Arc<PolicyEngine>;
46 fn approvals(&self) -> &Arc<ApprovalManager>;
47 fn registry(&self) -> &Arc<SubagentRegistry>;
48 fn plugins(&self) -> &Arc<PluginRegistry>;
49}
50
51pub trait HasMemory {
53 fn retriever(&self) -> &Arc<MemoryRetriever>;
54 fn ann_index(&self) -> &roboticus_db::ann::AnnIndex;
55}
56
57pub trait HasChannels {
59 fn channel_router(&self) -> &Arc<ChannelRouter>;
60}
61
62pub trait HasWallet {
64 fn wallet(&self) -> &Arc<WalletService>;
65}
66
67use super::routes::AppState;
70
71impl HasCore for AppState {
72 fn db(&self) -> &roboticus_db::Database {
73 &self.db
74 }
75 fn config(&self) -> &Arc<RwLock<roboticus_core::RoboticusConfig>> {
76 &self.config
77 }
78 fn hmac_secret(&self) -> &[u8] {
79 &self.hmac_secret
80 }
81}
82
83impl HasInference for AppState {
84 fn llm(&self) -> &Arc<RwLock<roboticus_llm::LlmService>> {
85 &self.llm
86 }
87 fn semantic_classifier(&self) -> &Arc<roboticus_llm::semantic_classifier::SemanticClassifier> {
88 &self.semantic_classifier
89 }
90}
91
92impl HasAgent for AppState {
93 fn tools(&self) -> &Arc<roboticus_agent::tools::ToolRegistry> {
94 &self.tools
95 }
96 fn capabilities(&self) -> &Arc<roboticus_agent::capability::CapabilityRegistry> {
97 &self.capabilities
98 }
99 fn policy_engine(&self) -> &Arc<roboticus_agent::policy::PolicyEngine> {
100 &self.policy_engine
101 }
102 fn approvals(&self) -> &Arc<roboticus_agent::approvals::ApprovalManager> {
103 &self.approvals
104 }
105 fn registry(&self) -> &Arc<roboticus_agent::subagents::SubagentRegistry> {
106 &self.registry
107 }
108 fn plugins(&self) -> &Arc<roboticus_plugin_sdk::registry::PluginRegistry> {
109 &self.plugins
110 }
111}
112
113impl HasMemory for AppState {
114 fn retriever(&self) -> &Arc<roboticus_agent::retrieval::MemoryRetriever> {
115 &self.retriever
116 }
117 fn ann_index(&self) -> &roboticus_db::ann::AnnIndex {
118 &self.ann_index
119 }
120}
121
122impl HasChannels for AppState {
123 fn channel_router(&self) -> &Arc<roboticus_channels::router::ChannelRouter> {
124 &self.channel_router
125 }
126}
127
128impl HasWallet for AppState {
129 fn wallet(&self) -> &Arc<roboticus_wallet::WalletService> {
130 &self.wallet
131 }
132}