1pub mod agent;
14pub mod chat_history;
15pub mod download;
16pub mod download_event_emitter;
17pub mod download_manager;
18pub mod download_state;
19pub mod event_emitter;
20pub mod gguf_parser;
21pub mod huggingface;
22pub mod llm_completion;
23pub mod mcp_dto;
24pub mod mcp_error;
25pub mod mcp_repository;
26pub mod model_catalog;
27pub mod model_registrar;
28pub mod model_repository;
29pub mod model_runtime;
30pub mod process_runner;
31pub mod server_health;
32pub mod server_log_sink;
33pub mod settings_repository;
34pub mod system_probe;
35pub mod tool_executor_filter;
36pub mod tool_support;
37pub mod voice;
38
39use std::sync::Arc;
40use thiserror::Error;
41
42pub use agent::{AgentError, AgentLoopPort, AgentRunOutput, ToolExecutorPort};
44pub use llm_completion::LlmCompletionPort;
46pub use tool_executor_filter::{EmptyToolExecutor, FilteredToolExecutor, TOOL_NOT_AVAILABLE_MSG};
48
49pub use chat_history::{ChatHistoryError, ChatHistoryRepository};
51pub use download::{QuantizationResolver, Resolution, ResolvedFile};
52pub use download_event_emitter::{AppEventBridge, DownloadEventEmitterPort, NoopDownloadEmitter};
53pub use download_manager::{DownloadManagerConfig, DownloadManagerPort, DownloadRequest};
54pub use download_state::DownloadStateRepositoryPort;
55pub use event_emitter::{AppEventEmitter, NoopEmitter};
56pub use gguf_parser::{
57 GgufCapabilities, GgufMetadata, GgufParseError, GgufParserPort, NoopGgufParser,
58};
59pub use huggingface::{
60 HfClientPort, HfFileInfo, HfPortError, HfQuantInfo, HfRepoInfo, HfSearchOptions, HfSearchResult,
61};
62pub use mcp_dto::{ResolutionAttempt, ResolutionStatus};
63pub use mcp_error::{McpErrorCategory, McpErrorInfo, McpServiceError};
64pub use mcp_repository::{McpRepositoryError, McpServerRepository};
65pub use model_catalog::{CatalogError, ModelCatalogPort, ModelLaunchSpec, ModelSummary};
66pub use model_registrar::{CompletedDownload, ModelRegistrarPort};
67pub use model_repository::ModelRepository;
68pub use model_runtime::{ModelRuntimeError, ModelRuntimePort, RunningTarget};
69pub use process_runner::{ProcessHandle, ProcessRunner, ServerConfig, ServerHealth};
70pub use server_health::ServerHealthStatus;
71pub use server_log_sink::ServerLogSinkPort;
72pub use settings_repository::SettingsRepository;
73pub use system_probe::{SystemProbeError, SystemProbePort, SystemProbeResult};
74pub use tool_support::{
75 ModelSource, ToolFormat, ToolSupportDetection, ToolSupportDetectionInput,
76 ToolSupportDetectorPort,
77};
78pub use voice::{
79 AudioDeviceDto, SttModelInfoDto, TtsModelInfoDto, VoiceInfoDto, VoiceModelsDto,
80 VoicePipelinePort, VoicePortError, VoiceStatusDto,
81};
82
83#[derive(Clone)]
100pub struct Repos {
101 pub models: Arc<dyn ModelRepository>,
103 pub settings: Arc<dyn SettingsRepository>,
105 pub mcp_servers: Arc<dyn McpServerRepository>,
107 pub chat_history: Arc<dyn ChatHistoryRepository>,
109}
110
111impl Repos {
112 pub fn new(
114 models: Arc<dyn ModelRepository>,
115 settings: Arc<dyn SettingsRepository>,
116 mcp_servers: Arc<dyn McpServerRepository>,
117 chat_history: Arc<dyn ChatHistoryRepository>,
118 ) -> Self {
119 Self {
120 models,
121 settings,
122 mcp_servers,
123 chat_history,
124 }
125 }
126}
127
128#[derive(Debug, Error)]
133pub enum RepositoryError {
134 #[error("Not found: {0}")]
136 NotFound(String),
137
138 #[error("Already exists: {0}")]
140 AlreadyExists(String),
141
142 #[error("Storage error: {0}")]
144 Storage(String),
145
146 #[error("Serialization error: {0}")]
148 Serialization(String),
149
150 #[error("Constraint violation: {0}")]
152 Constraint(String),
153}
154
155#[derive(Debug, Error)]
160pub enum ProcessError {
161 #[error("Failed to start: {0}")]
163 StartFailed(String),
164
165 #[error("Failed to stop: {0}")]
167 StopFailed(String),
168
169 #[error("Process not running: {0}")]
171 NotRunning(String),
172
173 #[error("Health check failed: {0}")]
175 HealthCheckFailed(String),
176
177 #[error("Configuration error: {0}")]
179 Configuration(String),
180
181 #[error("Resource exhaustion: {0}")]
183 ResourceExhausted(String),
184
185 #[error("Internal error: {0}")]
187 Internal(String),
188}
189
190#[derive(Debug, Error)]
196pub enum CoreError {
197 #[error(transparent)]
199 Repository(#[from] RepositoryError),
200
201 #[error(transparent)]
203 Process(#[from] ProcessError),
204
205 #[error(transparent)]
207 Settings(#[from] crate::settings::SettingsError),
208
209 #[error("Validation error: {0}")]
211 Validation(String),
212
213 #[error("Configuration error: {0}")]
215 Configuration(String),
216
217 #[error("External service error: {0}")]
219 ExternalService(String),
220
221 #[error("Internal error: {0}")]
223 Internal(String),
224}